diff --git a/CHANGELOG.md b/CHANGELOG.md index 08500cf7..a704c532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [v1.19.6](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.6) (2025-03-24) + - Fix + - Added stack headers in global fields response ## [v1.19.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.5) (2025-03-17) - Fix - Added AuditLog in the stack class diff --git a/README.md b/README.md index 9ae2fe35..921f2a1b 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset }) - [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api) ### The MIT License (MIT) -Copyright © 2012-2024 [Contentstack](https://www.contentstack.com/). All Rights Reserved +Copyright © 2012-2025 [Contentstack](https://www.contentstack.com/). All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/lib/stack/globalField/index.js b/lib/stack/globalField/index.js index 682902ff..3f36cc82 100644 --- a/lib/stack/globalField/index.js +++ b/lib/stack/globalField/index.js @@ -55,8 +55,12 @@ export function GlobalField (http, data = {}) { if (this.apiVersion) { delete this.stackHeaders.api_version } - if (response.data) { - return response.data + const data = response.data + if (data) { + if (this.stackHeaders) { + data.stackHeaders = this.stackHeaders + } + return data } else { throw error(response) } @@ -105,8 +109,12 @@ export function GlobalField (http, data = {}) { headers: { ...cloneDeep(this.stackHeaders) } } const response = await http.put(`${this.urlPath}`, config, headers) - if (response.data) { - return response.data + const data = response.data + if (data) { + if (this.stackHeaders) { + data.stackHeaders = this.stackHeaders + } + return data } else { throw error(response) } @@ -146,8 +154,12 @@ export function GlobalField (http, data = {}) { if (this.apiVersion) { delete this.stackHeaders.api_version } - if (response.data) { - return response.data + const data = response.data + if (data) { + if (this.stackHeaders) { + data.stackHeaders = this.stackHeaders + } + return data } else { throw error(response) } @@ -183,8 +195,12 @@ export function GlobalField (http, data = {}) { } } const response = await http.get(this.urlPath, headers) - if (response.data) { - return response.data + const data = response.data + if (data) { + if (this.stackHeaders) { + data.stackHeaders = this.stackHeaders + } + return data } else { throw error(response) } @@ -214,7 +230,7 @@ export function GlobalField (http, data = {}) { * client.stack().globalField().create({ global_field }) * .then((globalField) => console.log(globalField)) */ - this.create = async (data) => { + this.create = async (payload) => { try { if (this.apiVersion) { this.stackHeaders.api_version = this.apiVersion @@ -224,11 +240,15 @@ export function GlobalField (http, data = {}) { ...cloneDeep(this.stackHeaders) } } - const response = await http.post(`${this.urlPath}`, data, headers) - if (response.data) { - return response.data + const response = await http.post(`${this.urlPath}`, payload, headers) + const data = response.data + if (data) { + if (this.stackHeaders) { + data.stackHeaders = this.stackHeaders + } + return data } else { - return error(response) + throw error(response) } } catch (err) { return error(err) diff --git a/package-lock.json b/package-lock.json index 4f66bd64..a7aea494 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/management", - "version": "1.19.5", + "version": "1.19.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.19.5", + "version": "1.19.6", "license": "MIT", "dependencies": { "axios": "^1.8.2", diff --git a/package.json b/package.json index 691d9447..a60e84eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.19.5", + "version": "1.19.6", "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", diff --git a/types/stack/globalField/index.d.ts b/types/stack/globalField/index.d.ts index c3c0bb36..70a4ab8b 100644 --- a/types/stack/globalField/index.d.ts +++ b/types/stack/globalField/index.d.ts @@ -8,7 +8,6 @@ export interface GlobalField extends SystemFields, SystemFunction { export interface GlobalFields extends Queryable { import(data: {global_field: string}, params?: any): Promise - (globalFieldUidOrOptions: string | { api_version?: string }, options?: { api_version?: string }): GlobalField; } export interface GlobalFieldData extends AnyProperty { diff --git a/types/stack/index.d.ts b/types/stack/index.d.ts index 2ee9d273..f0344b38 100644 --- a/types/stack/index.d.ts +++ b/types/stack/index.d.ts @@ -61,10 +61,12 @@ export interface Stack extends SystemFields { contentType(): ContentTypes contentType(uid: string): ContentType - globalField(): GlobalFields - globalField({}): GlobalFields - globalField(uid: string): GlobalField - globalField(uid: string, option: object): GlobalField + globalField(): GlobalFields; + globalField(uid: string, option?: object): GlobalField; + globalField(options: { api_version: string }): GlobalFields; + globalField(uidOrOptions?: string | { api_version: string }, option?: object): GlobalFields | GlobalField; + + asset(): Assets asset(uid: string): Asset