diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ede8288f..bf64ecec 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -5,4 +5,4 @@ .github/workflows/policy-scan.yml @contentstack/security-admin -.github/workflows/issues-jira.yml @contentstack/security-admin +.github/workflows/issues-jira.yml @contentstack/security-admin \ No newline at end of file diff --git a/__test__/entry.test.ts b/__test__/entry.test.ts index 2548935d..dfd3bc27 100644 --- a/__test__/entry.test.ts +++ b/__test__/entry.test.ts @@ -223,7 +223,7 @@ describe("Entry", () => { dataWithoutEntry.entry = {}; entry = new Entry(dataWithoutEntry, connection as any, emitter); expect(() => entry.getField("invaliduid")).toThrowError( - "The data is unsaved. Save the data before requesting the field." + "Invalid uid, Field not found" ); }); diff --git a/package-lock.json b/package-lock.json index 6506f14c..be2739b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/app-sdk", - "version": "2.3.3", + "version": "2.3.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/app-sdk", - "version": "2.3.3", + "version": "2.3.5", "license": "MIT", "dependencies": { "axios": "^1.7.9", @@ -1762,10 +1762,11 @@ } }, "node_modules/@istanbuljs/load-nyc-config/node_modules/js-yaml": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", - "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.2.tgz", + "integrity": "sha512-PMSmkqxr106Xa156c2M265Z+FTrPl+oxd/rgOQy2tijQeK5TxQ43psO1ZCwhVOSdnn+RzkzlRz/eY4BgJBYVpg==", "dev": true, + "license": "MIT", "dependencies": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -8903,10 +8904,11 @@ "dev": true }, "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", + "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==", "dev": true, + "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, @@ -9785,10 +9787,11 @@ "dev": true }, "node_modules/node-forge": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", - "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.3.tgz", + "integrity": "sha512-rLvcdSyRCyouf6jcOIPe/BgwG/d7hKjzMKOas33/pHEr6gbq18IK9zV7DiPvzsz0oBJPme6qr6H6kGZuI9/DZg==", "dev": true, + "license": "(BSD-3-Clause OR GPL-2.0)", "engines": { "node": ">= 6.13.0" } diff --git a/package.json b/package.json index 3af26daa..4fe5f301 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/app-sdk", - "version": "2.3.3", + "version": "2.3.5", "types": "dist/src/index.d.ts", "description": "The Contentstack App SDK allows you to customize your Contentstack applications.", "main": "dist/index.js", diff --git a/src/entry.ts b/src/entry.ts index 14ecd768..d56c45ba 100755 --- a/src/entry.ts +++ b/src/entry.ts @@ -154,14 +154,6 @@ class Entry { : this._data; let schema: Schema[0] = this.content_type.schema; - const isDataEmpty = Object.keys(value).length === 0; - - if (isDataEmpty) { - throw new Error( - "The data is unsaved. Save the data before requesting the field." - ); - } - try { let skipNext = false; let skipNextTwo = false; diff --git a/src/stack/index.ts b/src/stack/index.ts index 6535d214..a66d2ec6 100755 --- a/src/stack/index.ts +++ b/src/stack/index.ts @@ -113,10 +113,15 @@ class Stack { * Gets the results of the search based on user query * @param queries Array of key value pair of query parameters * @param apiKey API key of the stack + * @param config Optional configuration. Only pass this if you need to query a specific branch using `{ branch: 'branch-name' }. If not provided, queries the default branch.` * @returns Result of the query */ - search(queries: StackSearchQuery, apiKey: string | null = this._data.api_key) { - const options = { params: queries, api_key: apiKey, action: "search" }; + search(queries: StackSearchQuery, apiKey: string | null = this._data.api_key, config: { [key: string]: any } = {}) { + const { branch } = config; + const options: any = { params: queries, api_key: apiKey, action: "search" }; + if (branch) { + options.headers = { branch }; + } return this._connection .sendToParent("stackQuery", options) .then(onData) diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index 82637c77..9c19fc44 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -16,15 +16,11 @@ import { axiosToFetchResponse, fetchToAxiosConfig } from "./utils"; export const dispatchAdapter = (postRobot: typeof PostRobot) => ( - config: AxiosRequestConfig, - context?: { installationUID: string; extensionUID: string } + config: AxiosRequestConfig ) => { return new Promise((resolve, reject) => { postRobot - .sendToParent("apiAdapter", { - data: config, - extension: context, - }) + .sendToParent("apiAdapter", config) .then((event: unknown) => { const { data: response } = event as { data: AxiosResponse }; @@ -63,14 +59,12 @@ export const dispatchAdapter = */ export const dispatchApiRequest = async ( url: string, - options?: RequestInit, - context?: { installationUID: string; extensionUID: string } + options?: RequestInit ): Promise => { try { const config = fetchToAxiosConfig(url, options); const axiosResponse = (await dispatchAdapter(PostRobot)( - config, - context + config )) as AxiosResponse; return axiosToFetchResponse(axiosResponse);