Skip to content

Commit 2a877cd

Browse files
Merge pull request #305 from contentstack/fix/global-fields
Fix/global fields
2 parents 2264ba5 + 52b49fc commit 2a877cd

File tree

6 files changed

+44
-22
lines changed

6 files changed

+44
-22
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
## [v1.19.6](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.6) (2025-03-31)
3+
## [v1.19.6](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.6) (2025-03-24)
44
- Enhancement
5+
- Added stack headers in global fields response
56
- Added buffer upload in assets
67

78
## [v1.19.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.5) (2025-03-17)

lib/stack/globalField/index.js

+33-13
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ export function GlobalField (http, data = {}) {
5555
if (this.apiVersion) {
5656
delete this.stackHeaders.api_version
5757
}
58-
if (response.data) {
59-
return response.data
58+
const data = response.data
59+
if (data) {
60+
if (this.stackHeaders) {
61+
data.stackHeaders = this.stackHeaders
62+
}
63+
return data
6064
} else {
6165
throw error(response)
6266
}
@@ -105,8 +109,12 @@ export function GlobalField (http, data = {}) {
105109
headers: { ...cloneDeep(this.stackHeaders) }
106110
}
107111
const response = await http.put(`${this.urlPath}`, config, headers)
108-
if (response.data) {
109-
return response.data
112+
const data = response.data
113+
if (data) {
114+
if (this.stackHeaders) {
115+
data.stackHeaders = this.stackHeaders
116+
}
117+
return data
110118
} else {
111119
throw error(response)
112120
}
@@ -146,8 +154,12 @@ export function GlobalField (http, data = {}) {
146154
if (this.apiVersion) {
147155
delete this.stackHeaders.api_version
148156
}
149-
if (response.data) {
150-
return response.data
157+
const data = response.data
158+
if (data) {
159+
if (this.stackHeaders) {
160+
data.stackHeaders = this.stackHeaders
161+
}
162+
return data
151163
} else {
152164
throw error(response)
153165
}
@@ -183,8 +195,12 @@ export function GlobalField (http, data = {}) {
183195
}
184196
}
185197
const response = await http.get(this.urlPath, headers)
186-
if (response.data) {
187-
return response.data
198+
const data = response.data
199+
if (data) {
200+
if (this.stackHeaders) {
201+
data.stackHeaders = this.stackHeaders
202+
}
203+
return data
188204
} else {
189205
throw error(response)
190206
}
@@ -214,7 +230,7 @@ export function GlobalField (http, data = {}) {
214230
* client.stack().globalField().create({ global_field })
215231
* .then((globalField) => console.log(globalField))
216232
*/
217-
this.create = async (data) => {
233+
this.create = async (payload) => {
218234
try {
219235
if (this.apiVersion) {
220236
this.stackHeaders.api_version = this.apiVersion
@@ -224,11 +240,15 @@ export function GlobalField (http, data = {}) {
224240
...cloneDeep(this.stackHeaders)
225241
}
226242
}
227-
const response = await http.post(`${this.urlPath}`, data, headers)
228-
if (response.data) {
229-
return response.data
243+
const response = await http.post(`${this.urlPath}`, payload, headers)
244+
const data = response.data
245+
if (data) {
246+
if (this.stackHeaders) {
247+
data.stackHeaders = this.stackHeaders
248+
}
249+
return data
230250
} else {
231-
return error(response)
251+
throw error(response)
232252
}
233253
} catch (err) {
234254
return error(err)

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.19.5",
3+
"version": "1.19.6",
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",

types/stack/globalField/index.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export interface GlobalField extends SystemFields, SystemFunction<GlobalField> {
88

99
export interface GlobalFields extends Queryable<GlobalField, {global_field: GlobalFieldData}> {
1010
import(data: {global_field: string}, params?: any): Promise<GlobalField>
11-
(globalFieldUidOrOptions: string | { api_version?: string }, options?: { api_version?: string }): GlobalField;
1211
}
1312

1413
export interface GlobalFieldData extends AnyProperty {

types/stack/index.d.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ export interface Stack extends SystemFields {
6161
contentType(): ContentTypes
6262
contentType(uid: string): ContentType
6363

64-
globalField(): GlobalFields
65-
globalField({}): GlobalFields
66-
globalField(uid: string): GlobalField
67-
globalField(uid: string, option: object): GlobalField
64+
globalField(): GlobalFields;
65+
globalField(uid: string, option?: object): GlobalField;
66+
globalField(options: { api_version: string }): GlobalFields;
67+
globalField(uidOrOptions?: string | { api_version: string }, option?: object): GlobalFields | GlobalField;
68+
69+
6870

6971
asset(): Assets
7072
asset(uid: string): Asset

0 commit comments

Comments
 (0)