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

feat: DEVREL-22 Added global fields handler #110

Closed
Closed
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
36 changes: 36 additions & 0 deletions src/stack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,42 @@ class Stack {
const options = { params: {uid : variant_uid}, action: 'getVariantById' };
return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
}

/**
* This API allows you to retrieve data of a single global field of a stack using the {@link https://www.contentstack.com/docs/developers/apis/content-management-api#get-single-global-field| Global Field API} requests. This method returns a Promise object.
* @param {string} uid of the desired global field
* @param {Object} params Optional parameters for the GET call
* @return {Object} A promise object which will be resolved with global field details.
*/
getGlobalField(uid: string, params = {}): Promise<{ [key: string]: GenericObjectType }> {
if (!uid) {
return Promise.reject(new Error("uid is required"));
}
const options = { uid, params, action: "getGlobalField" };
return this._connection
.sendToParent("stackQuery", options)
.then(onData)
.catch(onError);
}

/**
* This API allows you to retrieve data of all global fields of a stack using the {@link https://www.contentstack.com/docs/developers/apis/content-management-api#get-all-global-fields| Global Fields API} requests. This method returns a Promise object.
* @param {Object} query Query for the GET call
* @param {Object} params Optional parameters for the GET call
* @return {Object} A promise object which will be resolved with global field details.
*/
getGlobalFields(
query = {},
params: { [key: string]: GenericObjectType } = {}
): Promise<{ [key: string]: GenericObjectType }> {
const optionParams = params;
optionParams.query = query;
const options = { params: optionParams, action: "getGlobalFields" };
return this._connection
.sendToParent("stackQuery", options)
.then(onData)
.catch(onError);
}
}

export default Stack;
Loading