Skip to content

Fix/dx 2972 add settings #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ fileignoreconfig:
checksum: 9d0340f9359927d477fe8ab4650642c068c592be63fb817651d866849e0dbbc2
- filename: .husky/pre-commit
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
- filename: test/sanity-check/api/stack-test.js
checksum: 198d5cf7ead33b079249dc3ecdee61a9c57453e93f1073ed0341400983e5aa53
version: ""
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 11 additions & 4 deletions lib/stack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
106 changes: 105 additions & 1 deletion test/sanity-check/api/stack-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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()
Expand Down
Loading