Skip to content

Commit 15dbab3

Browse files
Added support for nested global fields
1 parent 0e5105b commit 15dbab3

File tree

8 files changed

+627
-122
lines changed

8 files changed

+627
-122
lines changed

lib/stack/globalField/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ export function GlobalField (http, data = {}) {
119119
* .then((globalField) => console.log(globalField))
120120
*
121121
*/
122-
this.import = async function (data, params = {}) {
122+
this.import = async function (data, params = {}, headers = {}) {
123123
try {
124+
this.stackHeaders = { ...this.stackHeaders, ...headers };
124125
const response = await upload({
125126
http: http,
126127
urlPath: `${this.urlPath}/import`,

lib/stack/index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,29 @@ export function Stack (http, data) {
159159
*
160160
* client.stack({ api_key: 'api_key'}).globalField('globalField_uid').fetch()
161161
* .then((globalField) => console.log(globalField))
162+
*
163+
* client.stack({ api_key: 'api_key'}).globalField('globalField_uid', { api_version: '3.2' }).fetch()
164+
* .then((globalField) => console.log(globalField))
165+
*
166+
* client.stack({ api_key: 'api_key'}).globalField({ api_version: '3.2' }).fetch()
167+
* .then((globalField) => console.log(globalField))
162168
*/
163-
this.globalField = (globalFieldUid = null) => {
164-
const data = { stackHeaders: this.stackHeaders }
165-
if (globalFieldUid) {
166-
data.global_field = { uid: globalFieldUid }
169+
this.globalField = (globalFieldUidOrOptions = null, options = {}) => {
170+
let data = {
171+
stackHeaders: this.stackHeaders,
172+
};
173+
if (typeof globalFieldUidOrOptions === 'object' && globalFieldUidOrOptions !== null) {
174+
options = globalFieldUidOrOptions;
175+
} else if (globalFieldUidOrOptions) {
176+
data.global_field = { uid: globalFieldUidOrOptions };
177+
}
178+
179+
if (options?.api_version) {
180+
data.api_version = options.api_version;
181+
http.defaults.headers.api_version = data.api_version;
182+
http.httpClientParams.headers.api_version = data.api_version;
167183
}
184+
168185
return new GlobalField(http, data)
169186
}
170187

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.18.4",
3+
"version": "1.19.0",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",

0 commit comments

Comments
 (0)