From 96b056d4902586c9e37686b07d6db8ebec112638 Mon Sep 17 00:00:00 2001 From: MaitriGurey1 Date: Mon, 30 Sep 2024 10:59:05 +0530 Subject: [PATCH 1/7] fix: added branch in headers --- src/stack/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/stack/index.ts b/src/stack/index.ts index d4d07113..6857c6dd 100755 --- a/src/stack/index.ts +++ b/src/stack/index.ts @@ -144,10 +144,18 @@ class Stack { * @param {Object} params Optional parameters for the GET call * @return {Object} A promise object which will be resolved with details of the content type. */ - getContentTypes(query = {}, params: { [key: string]: any } = {}): Promise<{ [key: string]: any }> { + getContentTypes(branch?: string, query = {}, params: { [key: string]: any } = {}): Promise<{ [key: string]: any }> { const optionParams = params; optionParams.query = query; - const options = { params: optionParams, action: 'getContentTypes' }; + + const options: any = { + params: optionParams, + action: 'getContentTypes', + }; + + if (branch) { + options.headers = { branch }; + } return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError); } From 7742398215f41b25e0e921774ea64e15a18b4a1a Mon Sep 17 00:00:00 2001 From: MaitriGurey1 Date: Mon, 30 Sep 2024 11:02:21 +0530 Subject: [PATCH 2/7] fix: test case --- __test__/stack.test.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/__test__/stack.test.ts b/__test__/stack.test.ts index c025698a..e58c2187 100644 --- a/__test__/stack.test.ts +++ b/__test__/stack.test.ts @@ -188,18 +188,21 @@ describe("Stack", () => { }); it("getContentTypes", (done) => { - let params: { [key: string]: any } = { sample: "parameter" }; - let query = { sample: "query" }; - stack.getContentTypes(query, params).then((data) => { - params.query = query; + const params: { [key: string]: any } = { sample: "parameter" }; + const query = { sample: "query" }; + const branch = "sampleBranch"; + + stack.getContentTypes(branch, query, params).then((data) => { expect(data).toEqual({}); - expect(connection.sendToParent).toHaveBeenCalledWith( - "stackQuery", - { params, action: "getContentTypes" } - ); + expect(connection.sendToParent).toHaveBeenCalledWith("stackQuery", { + params: { ...params, query }, + action: "getContentTypes", + ...(branch && { headers: { branch } }), + }); done(); }); }); + it("getContentTypes error case", async () => { let newStack = new Stack( From d598b9c7cafca3ab60dcad371b5870326c3ec33c Mon Sep 17 00:00:00 2001 From: MaitriGurey1 Date: Mon, 30 Sep 2024 11:53:49 +0530 Subject: [PATCH 3/7] fix: PR feedback --- src/stack/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stack/index.ts b/src/stack/index.ts index 6857c6dd..af2f06b9 100755 --- a/src/stack/index.ts +++ b/src/stack/index.ts @@ -144,8 +144,8 @@ class Stack { * @param {Object} params Optional parameters for the GET call * @return {Object} A promise object which will be resolved with details of the content type. */ - getContentTypes(branch?: string, query = {}, params: { [key: string]: any } = {}): Promise<{ [key: string]: any }> { - const optionParams = params; + getContentTypes(query = {}, params: { [key: string]: any } = {}): Promise<{ [key: string]: any }> { + const { branch, ... optionParams } = params; optionParams.query = query; const options: any = { From fcb9cfd112b65ea744ca2242baf15edfd7c699c6 Mon Sep 17 00:00:00 2001 From: MaitriGurey1 Date: Mon, 30 Sep 2024 11:57:07 +0530 Subject: [PATCH 4/7] update: test case --- __test__/stack.test.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/__test__/stack.test.ts b/__test__/stack.test.ts index e58c2187..8682544e 100644 --- a/__test__/stack.test.ts +++ b/__test__/stack.test.ts @@ -187,22 +187,24 @@ describe("Stack", () => { ); }); - it("getContentTypes", (done) => { - const params: { [key: string]: any } = { sample: "parameter" }; - const query = { sample: "query" }; - const branch = "sampleBranch"; + it("getContentTypes", (done) => { + let params: { [key: string]: any } = { sample: "parameter", branch: "sampleBranch" }; + let query = { sample: "query" }; + let expectedParams = { sample: "parameter", query }; - stack.getContentTypes(branch, query, params).then((data) => { + stack.getContentTypes(query, params).then((data) => { expect(data).toEqual({}); - expect(connection.sendToParent).toHaveBeenCalledWith("stackQuery", { - params: { ...params, query }, - action: "getContentTypes", - ...(branch && { headers: { branch } }), - }); + expect(connection.sendToParent).toHaveBeenCalledWith( + "stackQuery", + { + params: expectedParams, + action: "getContentTypes", + headers: { branch: "sampleBranch" } + } + ); done(); }); - }); - + }); it("getContentTypes error case", async () => { let newStack = new Stack( From 7c15c2da22059c3a4153193c355ada9bc2091bfe Mon Sep 17 00:00:00 2001 From: MaitriGurey1 Date: Mon, 30 Sep 2024 12:00:57 +0530 Subject: [PATCH 5/7] chore: updated package version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2e03c593..be0063fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/app-sdk", - "version": "2.0.3", + "version": "2.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@contentstack/app-sdk", - "version": "2.0.3", + "version": "2.0.4", "license": "MIT", "dependencies": { "loader-utils": "^3.2.1", diff --git a/package.json b/package.json index 9dbbe4a7..74479603 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/app-sdk", - "version": "2.0.3", + "version": "2.0.4", "types": "dist/src/index.d.ts", "description": "The Contentstack App SDK allows you to customize your Contentstack applications.", "main": "dist/index.js", From e7b2e1aa2a03fab1596bd1ac482c62447dcfbf1d Mon Sep 17 00:00:00 2001 From: MaitriGurey1 Date: Mon, 30 Sep 2024 12:36:49 +0530 Subject: [PATCH 6/7] fix: removed extra spaces --- __test__/stack.test.ts | 2 +- src/stack/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__test__/stack.test.ts b/__test__/stack.test.ts index 8682544e..d390fb24 100644 --- a/__test__/stack.test.ts +++ b/__test__/stack.test.ts @@ -187,7 +187,7 @@ describe("Stack", () => { ); }); - it("getContentTypes", (done) => { + it("getContentTypes", (done) => { let params: { [key: string]: any } = { sample: "parameter", branch: "sampleBranch" }; let query = { sample: "query" }; let expectedParams = { sample: "parameter", query }; diff --git a/src/stack/index.ts b/src/stack/index.ts index af2f06b9..ec7b9213 100755 --- a/src/stack/index.ts +++ b/src/stack/index.ts @@ -145,7 +145,7 @@ class Stack { * @return {Object} A promise object which will be resolved with details of the content type. */ getContentTypes(query = {}, params: { [key: string]: any } = {}): Promise<{ [key: string]: any }> { - const { branch, ... optionParams } = params; + const {branch, ... optionParams} = params; optionParams.query = query; const options: any = { From 32dfe2a299a62903555f0fc27e589f6d0ad15f48 Mon Sep 17 00:00:00 2001 From: MaitriGurey1 Date: Mon, 30 Sep 2024 12:43:20 +0530 Subject: [PATCH 7/7] fix: removed extra spaces --- src/stack/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stack/index.ts b/src/stack/index.ts index ec7b9213..6535d214 100755 --- a/src/stack/index.ts +++ b/src/stack/index.ts @@ -145,7 +145,7 @@ class Stack { * @return {Object} A promise object which will be resolved with details of the content type. */ getContentTypes(query = {}, params: { [key: string]: any } = {}): Promise<{ [key: string]: any }> { - const {branch, ... optionParams} = params; + const {branch, ...optionParams} = params; optionParams.query = query; const options: any = {