From 89a7820c90a079e75690202e6a069bbd266e607e Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Fri, 16 May 2025 19:42:00 +0530 Subject: [PATCH 1/6] Update addSettings Method to Support Generic Stack Settings Update --- lib/stack/index.js | 4 +- test/sanity-check/api/stack-test.js | 106 ++++++++++++++++++++++++++-- 2 files changed, 102 insertions(+), 8 deletions(-) diff --git a/lib/stack/index.js b/lib/stack/index.js index 3ced19ee..dde92b32 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -631,9 +631,9 @@ export function Stack (http, data) { * .then((settings) => console.log(settings)) * */ - this.addSettings = async (stackVariables = {}) => { + this.addSettings = async (variables = {}) => { try { - const response = await http.post(`${this.urlPath}/settings`, { stack_settings: { stack_variables: stackVariables } }, + const response = await http.post(`${this.urlPath}/settings`, { stack_settings: variables }, { headers: { ...cloneDeep(this.stackHeaders) } }) diff --git a/test/sanity-check/api/stack-test.js b/test/sanity-check/api/stack-test.js index 76082f43..7eeb7478 100644 --- a/test/sanity-check/api/stack-test.js +++ b/test/sanity-check/api/stack-test.js @@ -91,15 +91,109 @@ describe('Stack api Test', () => { .catch(done) }) - it('should add stack settings', done => { + it('should set stack_variables correctly', done => { + const variables = { + stack_variables: { + enforce_unique_urls: true, + sys_rte_allowed_tags: "style,figure,script", + sys_rte_skip_format_on_paste: "GD:font-size", + samplevariable: "too" + } + }; + client.stack({ api_key: stacks.api_key }) - .addSettings({ samplevariable: 'too' }) + .addSettings(variables) .then((response) => { - expect(response.stack_variables.samplevariable).to.be.equal('too', 'samplevariable must set to \'too\' ') - done() + const vars = response.stack_variables; + expect(vars.enforce_unique_urls).to.equal(true); + expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script"); + expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size"); + expect(vars.samplevariable).to.equal("too"); + done(); }) - .catch(done) - }) + .catch(done); + }); + + it('should set rte settings correctly', done => { + const variables = { + rte: { + cs_breakline_on_enter: true, + cs_only_breakline: true + } + }; + + client.stack({ api_key: stacks.api_key }) + .addSettings(variables) + .then((response) => { + const rte = response.rte; + expect(rte.cs_breakline_on_enter).to.equal(true); + expect(rte.cs_only_breakline).to.equal(true); + done(); + }) + .catch(done); + }); + + it('should set live_preview settings correctly', done => { + const variables = { + live_preview: { + enabled: true, + "default-env": "", + "default-url": "https://preview.example.com" + } + }; + + client.stack({ api_key: stacks.api_key }) + .addSettings(variables) + .then((response) => { + const preview = response.live_preview; + expect(preview.enabled).to.equal(true); + expect(preview["default-env"]).to.equal(""); + expect(preview["default-url"]).to.equal("https://preview.example.com"); + done(); + }) + .catch(done); + }); + + it('should add stack settings', done => { + const variables = { + stack_variables: { + enforce_unique_urls: true, + sys_rte_allowed_tags: "style,figure,script", + sys_rte_skip_format_on_paste: "GD:font-size", + samplevariable: "too" + }, + rte: { + cs_breakline_on_enter: true, + cs_only_breakline: true + }, + live_preview: { + enabled: true, + "default-env": "", + "default-url": "https://preview.example.com" + } + }; + + client.stack({ api_key: stacks.api_key }) + .addSettings(variables) .then((response) => { + const vars = response.stack_variables; + expect(vars.enforce_unique_urls).to.equal(true, 'enforce_unique_urls must be true'); + expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script", 'sys_rte_allowed_tags must match'); + expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size", 'sys_rte_skip_format_on_paste must match'); + expect(vars.samplevariable).to.equal("too", 'samplevariable must be "too"'); + + const rte = response.rte; + expect(rte.cs_breakline_on_enter).to.equal(true, 'cs_breakline_on_enter must be true'); + expect(rte.cs_only_breakline).to.equal(true, 'cs_only_breakline must be true'); + + const preview = response.live_preview; + expect(preview.enabled).to.equal(true, 'live_preview.enabled must be true'); + expect(preview["default-env"]).to.equal("", 'default-env must match'); + expect(preview["default-url"]).to.equal("https://preview.example.com", 'default-url must match'); + + done(); + }) + .catch(done); +}); it('should reset stack settings', done => { client.stack({ api_key: stacks.api_key }) From 0595d041ba69eb183a1b420655695ad358630e68 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Fri, 16 May 2025 19:42:35 +0530 Subject: [PATCH 2/6] update changeLog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 726e69b2..17e08076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [v1.21.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.2) (2025-05-19) - Enhancement - Added preview token generation. + - Update addSettings Method to Support Generic Stack Settings Update ## [v1.21.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.1) (2025-05-12) - Fix From ffd2c7f08183d66dd7f73736e627e549ac448481 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 19 May 2025 10:23:51 +0530 Subject: [PATCH 3/6] chore: update version to 1.21.3 and enhance changelog with addSettings method update --- CHANGELOG.md | 5 ++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e08076..b638938a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ # Changelog +## [v1.21.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.3) (2025-05-26) + - Enhancement + - Update addSettings Method to Support Generic Stack Settings Update + ## [v1.21.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.2) (2025-05-19) - Enhancement - Added preview token generation. - - Update addSettings Method to Support Generic Stack Settings Update ## [v1.21.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.1) (2025-05-12) - Fix diff --git a/package-lock.json b/package-lock.json index 82a6b51d..32aa93f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/management", - "version": "1.21.2", + "version": "1.21.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.21.2", + "version": "1.21.3", "license": "MIT", "dependencies": { "assert": "^2.1.0", diff --git a/package.json b/package.json index 0dba89bc..ad3a4082 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.21.2", + "version": "1.21.3", "description": "The Content Management API is used to manage the content of your Contentstack account", "main": "./dist/node/contentstack-management.js", "browser": "./dist/web/contentstack-management.js", From d88c29c047d4608c14c7c9d845d6136bedf7a157 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 19 May 2025 12:08:59 +0530 Subject: [PATCH 4/6] fix: enhance addSettings method to handle stack variables and live preview settings --- lib/stack/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/stack/index.js b/lib/stack/index.js index dde92b32..1a155902 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -631,12 +631,19 @@ export function Stack (http, data) { * .then((settings) => console.log(settings)) * */ - this.addSettings = async (variables = {}) => { + this.addSettings = async (stackVariables = {}) => { try { - const response = await http.post(`${this.urlPath}/settings`, { stack_settings: variables }, - { headers: { - ...cloneDeep(this.stackHeaders) - } }) + const payloadBody = ( + 'stack_variables' in stackVariables || + 'live_preview' in stackVariables || + 'rte' in stackVariables + ) + ? { stack_settings: stackVariables } + : { stack_settings: { stack_variables: stackVariables } } + + const response = await http.post(`${this.urlPath}/settings`, payloadBody, { headers: { + ...cloneDeep(this.stackHeaders) + } }) if (response.data) { return response.data.stack_settings } else { From f0bcbb80f58ad74ff49cd34bde34125e88332c2a Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 19 May 2025 12:09:20 +0530 Subject: [PATCH 5/6] fix: fix lint issues --- test/sanity-check/api/stack-test.js | 136 +++++++++++++++------------- 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/test/sanity-check/api/stack-test.js b/test/sanity-check/api/stack-test.js index 7eeb7478..ce52ec83 100644 --- a/test/sanity-check/api/stack-test.js +++ b/test/sanity-check/api/stack-test.js @@ -95,24 +95,24 @@ describe('Stack api Test', () => { const variables = { stack_variables: { enforce_unique_urls: true, - sys_rte_allowed_tags: "style,figure,script", - sys_rte_skip_format_on_paste: "GD:font-size", - samplevariable: "too" + sys_rte_allowed_tags: 'style,figure,script', + sys_rte_skip_format_on_paste: 'GD:font-size', + samplevariable: 'too' } - }; + } client.stack({ api_key: stacks.api_key }) .addSettings(variables) .then((response) => { - const vars = response.stack_variables; - expect(vars.enforce_unique_urls).to.equal(true); - expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script"); - expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size"); - expect(vars.samplevariable).to.equal("too"); - done(); + const vars = response.stack_variables + expect(vars.enforce_unique_urls).to.equal(true) + expect(vars.sys_rte_allowed_tags).to.equal('style,figure,script') + expect(vars.sys_rte_skip_format_on_paste).to.equal('GD:font-size') + expect(vars.samplevariable).to.equal('too') + done() }) - .catch(done); - }); + .catch(done) + }) it('should set rte settings correctly', done => { const variables = { @@ -120,80 +120,90 @@ describe('Stack api Test', () => { cs_breakline_on_enter: true, cs_only_breakline: true } - }; + } client.stack({ api_key: stacks.api_key }) .addSettings(variables) .then((response) => { - const rte = response.rte; - expect(rte.cs_breakline_on_enter).to.equal(true); - expect(rte.cs_only_breakline).to.equal(true); - done(); + const rte = response.rte + expect(rte.cs_breakline_on_enter).to.equal(true) + expect(rte.cs_only_breakline).to.equal(true) + done() }) - .catch(done); - }); + .catch(done) + }) it('should set live_preview settings correctly', done => { const variables = { live_preview: { enabled: true, - "default-env": "", - "default-url": "https://preview.example.com" + 'default-env': '', + 'default-url': 'https://preview.example.com' } - }; + } client.stack({ api_key: stacks.api_key }) .addSettings(variables) .then((response) => { - const preview = response.live_preview; - expect(preview.enabled).to.equal(true); - expect(preview["default-env"]).to.equal(""); - expect(preview["default-url"]).to.equal("https://preview.example.com"); - done(); + const preview = response.live_preview + expect(preview.enabled).to.equal(true) + expect(preview['default-env']).to.equal('') + expect(preview['default-url']).to.equal('https://preview.example.com') + done() }) - .catch(done); - }); + .catch(done) + }) + + it('should add simple stack variable', done => { + client.stack({ api_key: stacks.api_key }) + .addSettings({ samplevariable: 'too' }) + .then((response) => { + expect(response.stack_variables.samplevariable).to.be.equal('too', 'samplevariable must set to \'too\' ') + done() + }) + .catch(done) + }) it('should add stack settings', done => { - const variables = { - stack_variables: { - enforce_unique_urls: true, - sys_rte_allowed_tags: "style,figure,script", - sys_rte_skip_format_on_paste: "GD:font-size", - samplevariable: "too" - }, - rte: { - cs_breakline_on_enter: true, - cs_only_breakline: true - }, - live_preview: { - enabled: true, - "default-env": "", - "default-url": "https://preview.example.com" + const variables = { + stack_variables: { + enforce_unique_urls: true, + sys_rte_allowed_tags: 'style,figure,script', + sys_rte_skip_format_on_paste: 'GD:font-size', + samplevariable: 'too' + }, + rte: { + cs_breakline_on_enter: true, + cs_only_breakline: true + }, + live_preview: { + enabled: true, + 'default-env': '', + 'default-url': 'https://preview.example.com' + } } - }; - client.stack({ api_key: stacks.api_key }) - .addSettings(variables) .then((response) => { - const vars = response.stack_variables; - expect(vars.enforce_unique_urls).to.equal(true, 'enforce_unique_urls must be true'); - expect(vars.sys_rte_allowed_tags).to.equal("style,figure,script", 'sys_rte_allowed_tags must match'); - expect(vars.sys_rte_skip_format_on_paste).to.equal("GD:font-size", 'sys_rte_skip_format_on_paste must match'); - expect(vars.samplevariable).to.equal("too", 'samplevariable must be "too"'); + client.stack({ api_key: stacks.api_key }) + .addSettings(variables).then((response) => { + const vars = response.stack_variables + expect(vars.enforce_unique_urls).to.equal(true, 'enforce_unique_urls must be true') + expect(vars.sys_rte_allowed_tags).to.equal('style,figure,script', 'sys_rte_allowed_tags must match') + expect(vars.sys_rte_skip_format_on_paste).to.equal('GD:font-size', 'sys_rte_skip_format_on_paste must match') + expect(vars.samplevariable).to.equal('too', 'samplevariable must be "too"') - const rte = response.rte; - expect(rte.cs_breakline_on_enter).to.equal(true, 'cs_breakline_on_enter must be true'); - expect(rte.cs_only_breakline).to.equal(true, 'cs_only_breakline must be true'); + const rte = response.rte + expect(rte.cs_breakline_on_enter).to.equal(true, 'cs_breakline_on_enter must be true') + expect(rte.cs_only_breakline).to.equal(true, 'cs_only_breakline must be true') - const preview = response.live_preview; - expect(preview.enabled).to.equal(true, 'live_preview.enabled must be true'); - expect(preview["default-env"]).to.equal("", 'default-env must match'); - expect(preview["default-url"]).to.equal("https://preview.example.com", 'default-url must match'); + const preview = response.live_preview + expect(preview.enabled).to.equal(true, 'live_preview.enabled must be true') + expect(preview['default-env']).to.equal('', 'default-env must match') + expect(preview['default-url']).to.equal('https://preview.example.com', 'default-url must match') - done(); - }) - .catch(done); -}); + done() + }) + .catch(done) + }) it('should reset stack settings', done => { client.stack({ api_key: stacks.api_key }) From 4c275057500fb5e985f692cfbf133c6f29037103 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 19 May 2025 12:15:55 +0530 Subject: [PATCH 6/6] fix: add stack-test.js to fileignoreconfig with checksum --- .talismanrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.talismanrc b/.talismanrc index 41223457..9131959e 100644 --- a/.talismanrc +++ b/.talismanrc @@ -6,4 +6,6 @@ fileignoreconfig: checksum: 9d0340f9359927d477fe8ab4650642c068c592be63fb817651d866849e0dbbc2 - filename: .husky/pre-commit checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193 +- filename: test/sanity-check/api/stack-test.js + checksum: 198d5cf7ead33b079249dc3ecdee61a9c57453e93f1073ed0341400983e5aa53 version: "" \ No newline at end of file