Skip to content
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

Fix/1694 global fields #300

Draft
wants to merge 7 commits into
base: development
Choose a base branch
from
Draft
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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