Skip to content

Merge pull request #348 from contentstack/master #353

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 11 commits into from
May 19, 2025
Merged
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: 1 addition & 1 deletion sanity-report-dev11.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let tagUsers =
failedTests > 0 ? `<@${user1}> <@${user2}> <@${user3}> <@${user4}>` : "";

const slackMessage = {
text: `Dev11, SDK-CMA Sanity\n*Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s\n*Failed Tests:* ${failedTests}\n<${reportUrl}|View Report>\n${tagUsers}`,
text: `Dev11, SDK-JS-CMA Sanity\n*Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s\n*Failed Tests:* ${failedTests}\n<${reportUrl}|View Report>\n${tagUsers}`,
};

const app = new App({
Expand Down
10 changes: 9 additions & 1 deletion sanity-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ console.log(`Failed Tests: ${failedTests}`)
console.log(`Pending Tests: ${pendingTests}`)
console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`)

const host = process.env.HOST || ''
let region = 'NA'

const match = host.match(/^([^-]+(?:-[^-]+)*)-api/)
if (match && match[1]) {
region = match[1].toUpperCase()
}

const slackMessage = `
*JavaScript CMA Report*
*JavaScript CMA Report - ${region}*
• Total Suites: *${totalSuites}*
• Total Tests: *${totalTests}*
• Passed Tests: *${passedTests}*
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