Skip to content

Fix/global fields #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

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

## [v1.19.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.5) (2025-03-17)
Expand Down
46 changes: 33 additions & 13 deletions lib/stack/globalField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
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.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",
Expand Down
1 change: 0 additions & 1 deletion types/stack/globalField/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface GlobalField extends SystemFields, SystemFunction<GlobalField> {

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

export interface GlobalFieldData extends AnyProperty {
Expand Down
10 changes: 6 additions & 4 deletions types/stack/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading