Skip to content

Commit

Permalink
Merge pull request #111 from contentstack/feat/DEVREL-22-add-global-f…
Browse files Browse the repository at this point in the history
…ields-handler-main

feat: DEVREL-22 Added global fields handler
  • Loading branch information
praveen-mohan-cs authored Jul 12, 2024
2 parents 7e27dee + 23bbdc3 commit 084ac43
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/app-sdk",
"version": "2.0.1",
"version": "2.0.2",
"types": "dist/src/index.d.ts",
"description": "The Contentstack App SDK allows you to customize your Contentstack applications.",
"main": "dist/index.js",
Expand Down
37 changes: 37 additions & 0 deletions src/stack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ContentType from './api/content-type/index';
import { onData, onError } from "../utils/utils";
import { BranchDetail, GetAllStacksOptions, StackAdditionalData, StackDetail, StackSearchQuery } from '../types/stack.types';
import { IManagementTokenDetails } from '../types';
import { GenericObjectType } from "../types/common.types";


/**
Expand Down Expand Up @@ -272,6 +273,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 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;

0 comments on commit 084ac43

Please sign in to comment.