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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 726e69b2..b638938a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # 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. diff --git a/lib/stack/index.js b/lib/stack/index.js index 3ced19ee..1a155902 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -633,10 +633,17 @@ export function Stack (http, data) { */ this.addSettings = async (stackVariables = {}) => { try { - const response = await http.post(`${this.urlPath}/settings`, { stack_settings: { stack_variables: stackVariables } }, - { 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 { 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", diff --git a/test/sanity-check/api/stack-test.js b/test/sanity-check/api/stack-test.js index 76082f43..ce52ec83 100644 --- a/test/sanity-check/api/stack-test.js +++ b/test/sanity-check/api/stack-test.js @@ -91,7 +91,70 @@ 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(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() + }) + .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 simple stack variable', done => { client.stack({ api_key: stacks.api_key }) .addSettings({ samplevariable: 'too' }) .then((response) => { @@ -101,6 +164,47 @@ describe('Stack api Test', () => { .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 }) .resetSettings()