Skip to content

Commit 084ac43

Browse files
Merge pull request #111 from contentstack/feat/DEVREL-22-add-global-fields-handler-main
feat: DEVREL-22 Added global fields handler
2 parents 7e27dee + 23bbdc3 commit 084ac43

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/app-sdk",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"types": "dist/src/index.d.ts",
55
"description": "The Contentstack App SDK allows you to customize your Contentstack applications.",
66
"main": "dist/index.js",

src/stack/index.ts

+37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ContentType from './api/content-type/index';
33
import { onData, onError } from "../utils/utils";
44
import { BranchDetail, GetAllStacksOptions, StackAdditionalData, StackDetail, StackSearchQuery } from '../types/stack.types';
55
import { IManagementTokenDetails } from '../types';
6+
import { GenericObjectType } from "../types/common.types";
67

78

89
/**
@@ -272,6 +273,42 @@ class Stack {
272273
getCurrentBranch(): BranchDetail | null {
273274
return this._currentBranch;
274275
}
276+
277+
/**
278+
* 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.
279+
* @param {string} uid of the desired global field
280+
* @param {Object} params Optional parameters for the GET call
281+
* @return {Object} A promise object which will be resolved with global field details.
282+
*/
283+
getGlobalField(uid: string, params = {}): Promise<{ [key: string]: GenericObjectType }> {
284+
if (!uid) {
285+
return Promise.reject(new Error("uid is required"));
286+
}
287+
const options = { uid, params, action: "getGlobalField" };
288+
return this._connection
289+
.sendToParent("stackQuery", options)
290+
.then(onData)
291+
.catch(onError);
292+
}
293+
294+
/**
295+
* 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.
296+
* @param {Object} query Query for the GET call
297+
* @param {Object} params Optional parameters for the GET call
298+
* @return {Object} A promise object which will be resolved with global field details.
299+
*/
300+
getGlobalFields(
301+
query = {},
302+
params: { [key: string]: GenericObjectType } = {}
303+
): Promise<{ [key: string]: GenericObjectType }> {
304+
const optionParams = params;
305+
optionParams.query = query;
306+
const options = { params: optionParams, action: "getGlobalFields" };
307+
return this._connection
308+
.sendToParent("stackQuery", options)
309+
.then(onData)
310+
.catch(onError);
311+
}
275312
}
276313

277314
export default Stack;

0 commit comments

Comments
 (0)