Skip to content

Commit

Permalink
Added support for nested global fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil-lakshman committed Dec 16, 2024
1 parent 0e5105b commit 15dbab3
Show file tree
Hide file tree
Showing 8 changed files with 627 additions and 122 deletions.
3 changes: 2 additions & 1 deletion lib/stack/globalField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ export function GlobalField (http, data = {}) {
* .then((globalField) => console.log(globalField))
*
*/
this.import = async function (data, params = {}) {
this.import = async function (data, params = {}, headers = {}) {
try {
this.stackHeaders = { ...this.stackHeaders, ...headers };
const response = await upload({
http: http,
urlPath: `${this.urlPath}/import`,
Expand Down
25 changes: 21 additions & 4 deletions lib/stack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,29 @@ export function Stack (http, data) {
*
* client.stack({ api_key: 'api_key'}).globalField('globalField_uid').fetch()
* .then((globalField) => console.log(globalField))
*
* client.stack({ api_key: 'api_key'}).globalField('globalField_uid', { api_version: '3.2' }).fetch()
* .then((globalField) => console.log(globalField))
*
* client.stack({ api_key: 'api_key'}).globalField({ api_version: '3.2' }).fetch()
* .then((globalField) => console.log(globalField))
*/
this.globalField = (globalFieldUid = null) => {
const data = { stackHeaders: this.stackHeaders }
if (globalFieldUid) {
data.global_field = { uid: globalFieldUid }
this.globalField = (globalFieldUidOrOptions = null, options = {}) => {
let data = {
stackHeaders: this.stackHeaders,
};
if (typeof globalFieldUidOrOptions === 'object' && globalFieldUidOrOptions !== null) {
options = globalFieldUidOrOptions;
} else if (globalFieldUidOrOptions) {
data.global_field = { uid: globalFieldUidOrOptions };
}

if (options?.api_version) {
data.api_version = options.api_version;
http.defaults.headers.api_version = data.api_version;
http.httpClientParams.headers.api_version = data.api_version;
}

return new GlobalField(http, data)
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.18.4",
"version": "1.19.0",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down
Loading

0 comments on commit 15dbab3

Please sign in to comment.