Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## [v1.21.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.2) (2025-05-19)
- Enhancement
- Added preview token generation.

## [v1.21.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.1) (2025-05-12)
- Fix
Expand Down
10 changes: 6 additions & 4 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,21 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me
}
}

export const create = ({ http, params }) => {
export const create = ({ http, params = {}, createWithPreviewToken = false }) => {
return async function (data, param) {
this.stackHeaders = {
...this.stackHeaders
}
const queryParams = {
...(createWithPreviewToken ? { create_with_preview_token: true } : {}),
...cloneDeep(param) // user param can override default
}
const headers = {
headers: {
...cloneDeep(params),
...cloneDeep(this.stackHeaders)
},
params: {
...cloneDeep(param)
}
params: queryParams
} || {}

try {
Expand Down
2 changes: 1 addition & 1 deletion lib/stack/deliveryToken/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function DeliveryToken (http, data = {}) {
* client.stack().deliveryToken().create({ token })
* .then((deliveryToken) => console.log(deliveryToken))
*/
this.create = create({ http: http })
this.create = create({ http: http, createWithPreviewToken: true })

/**
* @description The ‘Get all deliveryToken’ request returns comprehensive information about all deliveryToken created in a stack.
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.1",
"version": "1.21.2",
"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
2 changes: 2 additions & 0 deletions test/sanity-check/api/deliveryToken-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Delivery Token api Test', () => {
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
expect(token.preview_token).to.be.not.equal(null)
done()
})
.catch(done)
Expand All @@ -39,6 +40,7 @@ describe('Delivery Token api Test', () => {
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
expect(token.preview_token).to.be.not.equal(null)
done()
})
.catch(done)
Expand Down
Loading