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 #109

Closed
wants to merge 3 commits into from
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
38 changes: 37 additions & 1 deletion src/stack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,42 @@ class Stack {
getCurrentBranch(): BranchDetail | null {
return this._currentBranch;
}

/**
* 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 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]: any }> {
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]: any } = {}
): Promise<{ [key: string]: any }> {
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;
export default Stack;