Skip to content

Commit 1d01896

Browse files
Merge pull request #354 from contentstack/fix/dx-2972-addSettings
Fix/dx 2972 add settings
2 parents 6dcb6ac + 4c27505 commit 1d01896

File tree

6 files changed

+125
-8
lines changed

6 files changed

+125
-8
lines changed

.talismanrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ fileignoreconfig:
66
checksum: 9d0340f9359927d477fe8ab4650642c068c592be63fb817651d866849e0dbbc2
77
- filename: .husky/pre-commit
88
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
9+
- filename: test/sanity-check/api/stack-test.js
10+
checksum: 198d5cf7ead33b079249dc3ecdee61a9c57453e93f1073ed0341400983e5aa53
911
version: ""

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## [v1.21.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.3) (2025-05-26)
3+
- Enhancement
4+
- Update addSettings Method to Support Generic Stack Settings Update
5+
26
## [v1.21.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.2) (2025-05-19)
37
- Enhancement
48
- Added preview token generation.

lib/stack/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,17 @@ export function Stack (http, data) {
633633
*/
634634
this.addSettings = async (stackVariables = {}) => {
635635
try {
636-
const response = await http.post(`${this.urlPath}/settings`, { stack_settings: { stack_variables: stackVariables } },
637-
{ headers: {
638-
...cloneDeep(this.stackHeaders)
639-
} })
636+
const payloadBody = (
637+
'stack_variables' in stackVariables ||
638+
'live_preview' in stackVariables ||
639+
'rte' in stackVariables
640+
)
641+
? { stack_settings: stackVariables }
642+
: { stack_settings: { stack_variables: stackVariables } }
643+
644+
const response = await http.post(`${this.urlPath}/settings`, payloadBody, { headers: {
645+
...cloneDeep(this.stackHeaders)
646+
} })
640647
if (response.data) {
641648
return response.data.stack_settings
642649
} else {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.21.2",
3+
"version": "1.21.3",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",

test/sanity-check/api/stack-test.js

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,70 @@ describe('Stack api Test', () => {
9191
.catch(done)
9292
})
9393

94-
it('should add stack settings', done => {
94+
it('should set stack_variables correctly', done => {
95+
const variables = {
96+
stack_variables: {
97+
enforce_unique_urls: true,
98+
sys_rte_allowed_tags: 'style,figure,script',
99+
sys_rte_skip_format_on_paste: 'GD:font-size',
100+
samplevariable: 'too'
101+
}
102+
}
103+
104+
client.stack({ api_key: stacks.api_key })
105+
.addSettings(variables)
106+
.then((response) => {
107+
const vars = response.stack_variables
108+
expect(vars.enforce_unique_urls).to.equal(true)
109+
expect(vars.sys_rte_allowed_tags).to.equal('style,figure,script')
110+
expect(vars.sys_rte_skip_format_on_paste).to.equal('GD:font-size')
111+
expect(vars.samplevariable).to.equal('too')
112+
done()
113+
})
114+
.catch(done)
115+
})
116+
117+
it('should set rte settings correctly', done => {
118+
const variables = {
119+
rte: {
120+
cs_breakline_on_enter: true,
121+
cs_only_breakline: true
122+
}
123+
}
124+
125+
client.stack({ api_key: stacks.api_key })
126+
.addSettings(variables)
127+
.then((response) => {
128+
const rte = response.rte
129+
expect(rte.cs_breakline_on_enter).to.equal(true)
130+
expect(rte.cs_only_breakline).to.equal(true)
131+
done()
132+
})
133+
.catch(done)
134+
})
135+
136+
it('should set live_preview settings correctly', done => {
137+
const variables = {
138+
live_preview: {
139+
enabled: true,
140+
'default-env': '',
141+
'default-url': 'https://preview.example.com'
142+
}
143+
}
144+
145+
client.stack({ api_key: stacks.api_key })
146+
.addSettings(variables)
147+
.then((response) => {
148+
const preview = response.live_preview
149+
expect(preview.enabled).to.equal(true)
150+
expect(preview['default-env']).to.equal('')
151+
expect(preview['default-url']).to.equal('https://preview.example.com')
152+
done()
153+
})
154+
.catch(done)
155+
})
156+
157+
it('should add simple stack variable', done => {
95158
client.stack({ api_key: stacks.api_key })
96159
.addSettings({ samplevariable: 'too' })
97160
.then((response) => {
@@ -101,6 +164,47 @@ describe('Stack api Test', () => {
101164
.catch(done)
102165
})
103166

167+
it('should add stack settings', done => {
168+
const variables = {
169+
stack_variables: {
170+
enforce_unique_urls: true,
171+
sys_rte_allowed_tags: 'style,figure,script',
172+
sys_rte_skip_format_on_paste: 'GD:font-size',
173+
samplevariable: 'too'
174+
},
175+
rte: {
176+
cs_breakline_on_enter: true,
177+
cs_only_breakline: true
178+
},
179+
live_preview: {
180+
enabled: true,
181+
'default-env': '',
182+
'default-url': 'https://preview.example.com'
183+
}
184+
}
185+
186+
client.stack({ api_key: stacks.api_key })
187+
.addSettings(variables).then((response) => {
188+
const vars = response.stack_variables
189+
expect(vars.enforce_unique_urls).to.equal(true, 'enforce_unique_urls must be true')
190+
expect(vars.sys_rte_allowed_tags).to.equal('style,figure,script', 'sys_rte_allowed_tags must match')
191+
expect(vars.sys_rte_skip_format_on_paste).to.equal('GD:font-size', 'sys_rte_skip_format_on_paste must match')
192+
expect(vars.samplevariable).to.equal('too', 'samplevariable must be "too"')
193+
194+
const rte = response.rte
195+
expect(rte.cs_breakline_on_enter).to.equal(true, 'cs_breakline_on_enter must be true')
196+
expect(rte.cs_only_breakline).to.equal(true, 'cs_only_breakline must be true')
197+
198+
const preview = response.live_preview
199+
expect(preview.enabled).to.equal(true, 'live_preview.enabled must be true')
200+
expect(preview['default-env']).to.equal('', 'default-env must match')
201+
expect(preview['default-url']).to.equal('https://preview.example.com', 'default-url must match')
202+
203+
done()
204+
})
205+
.catch(done)
206+
})
207+
104208
it('should reset stack settings', done => {
105209
client.stack({ api_key: stacks.api_key })
106210
.resetSettings()

0 commit comments

Comments
 (0)