Skip to content

Commit 0e0f9f0

Browse files
committed
Merge branch 'development' into fix/DX-2370
2 parents d4a538c + 2a3fb9d commit 0e0f9f0

File tree

28 files changed

+2855
-340
lines changed

28 files changed

+2855
-340
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ tsconfig.json
6767
.next
6868
.dccache
6969
dist
70-
jsdocs
70+
jsdocs
71+
.early.coverage

.husky/pre-commit

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
#!/usr/bin/env sh
2-
# Pre-commit hook to run Snyk and Talisman scans, completing both before deciding to commit
2+
# Pre-commit hook to run lint, Snyk and Talisman scans, completing all before deciding to commit
33

44
# Function to check if a command exists
55
command_exists() {
66
command -v "$1" >/dev/null 2>&1
77
}
88

9+
# Allow bypassing the hook with an environment variable
10+
if [ "$SKIP_HOOK" = "1" ]; then
11+
echo "Skipping lint, Snyk and Talisman scans (SKIP_HOOK=1)."
12+
exit 0
13+
fi
14+
15+
# Run ESLint check first
16+
echo "Running ESLint check..."
17+
npm run lint
18+
lint_exit_code=$?
19+
20+
if [ $lint_exit_code -ne 0 ]; then
21+
echo "ESLint check failed. Please fix the linting issues and try again."
22+
echo "You can run 'npm run format' to auto-fix most issues."
23+
exit 1
24+
fi
25+
26+
echo "ESLint check passed."
27+
928
# Check if Snyk is installed
1029
if ! command_exists snyk; then
1130
echo "Error: Snyk is not installed. Please install it and try again."
@@ -18,12 +37,6 @@ if ! command_exists talisman; then
1837
exit 1
1938
fi
2039

21-
# Allow bypassing the hook with an environment variable
22-
if [ "$SKIP_HOOK" = "1" ]; then
23-
echo "Skipping Snyk and Talisman scans (SKIP_HOOK=1)."
24-
exit 0
25-
fi
26-
2740
# Initialize variables to track scan results
2841
snyk_failed=false
2942
talisman_failed=false
@@ -63,7 +76,7 @@ if [ "$snyk_failed" = true ] || [ "$talisman_failed" = true ]; then
6376
exit 1
6477
fi
6578

66-
# If both scans pass, allow the commit
67-
echo "All scans passed. Proceeding with commit.cd ."
79+
# If all checks pass, allow the commit
80+
echo "All checks passed (ESLint, Snyk, Talisman). Proceeding with commit."
6881
rm -f snyk_output.log talisman_output.log
6982
exit 0

.talismanrc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ fileignoreconfig:
99
ignore_detectors:
1010
- filecontent
1111
- filename: package-lock.json
12-
checksum: 2f7e068e1479bf9a9acbba8ec797caa5cfbce0b435acb3b714e023aa44467e72
12+
checksum: a184b5573183d051dc4f75af776a6b152e272eceef7b56fd3e1c80d88b392a58
1313
- filename: .husky/pre-commit
14-
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
15-
version: "1.0"
14+
checksum: 52a664f536cf5d1be0bea19cb6031ca6e8107b45b6314fe7d47b7fad7d800632
15+
- filename: test/sanity-check/api/user-test.js
16+
checksum: 6bb8251aad584e09f4d963a913bd0007e5f6e089357a44c3fb1529e3fda5509d
17+
- filename: lib/stack/asset/index.js
18+
checksum: b3358310e9cb2fb493d70890b7219db71e2202360be764465d505ef71907eefe
19+
- filename: test/sanity-check/api/previewToken-test.js
20+
checksum: 9a42e079b7c71f76932896a0d2390d86ac626678ab20d36821dcf962820a886c
21+
- filename: lib/stack/deliveryToken/index.js
22+
checksum: 51ae00f07f4cc75c1cd832b311c2e2482f04a8467a0139da6013ceb88fbdda2f
23+
- filename: lib/stack/deliveryToken/previewToken/index.js
24+
checksum: b506f33bffdd20dfc701f964370707f5d7b28a2c05c70665f0edb7b3c53c165b
25+
version: "1.0"

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
# Changelog
2+
3+
## [v1.23.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.24.0) (2025-07-28)
4+
- Fix
5+
- Add asset types support in bulk operations
6+
7+
## [v1.23.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.23.0) (2025-07-28)
8+
- Feature
9+
- Added new getReferences method to Asset class for retrieving asset references
10+
- Added comprehensive test coverage for Asset getReferences method across all test suites
11+
- Dependency updates
12+
13+
## [v1.22.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.22.0) (2025-07-07)
14+
- Enhancement
15+
- AWS-AU Region support added
16+
- Fix
17+
- Fixed branch header conflits
18+
## [v1.21.7](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.7) (2025-06-30)
19+
- Fix
20+
- Fixed Request-URI Too Large error
21+
22+
## [v1.21.6](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.6) (2025-06-11)
23+
- Fix
24+
- Revert Retry Logic modification on x-ratelimit-remaining Header
25+
26+
## [v1.21.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.5) (2025-06-09)
27+
- Enhancement
28+
- Preview token support added
29+
30+
## [v1.21.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.4) (2025-06-02)
31+
- Enhancement
32+
- Retry Logic modification on x-ratelimit-remaining Header
33+
234
## [v1.21.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.3) (2025-05-26)
335
- Enhancement
436
- Update addSettings Method to Support Generic Stack Settings Update

lib/contentstack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import httpClient from './core/contentstackHTTPClient.js'
1010
const regionHostMap = {
1111
NA: 'api.contentstack.io',
1212
EU: 'eu-api.contentstack.com',
13+
AU: 'au-api.contentstack.com',
1314
AZURE_NA: 'azure-na-api.contentstack.com',
1415
AZURE_EU: 'azure-eu-api.contentstack.com',
1516
GCP_NA: 'gcp-na-api.contentstack.com',

lib/core/concurrency-queue.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export function ConcurrencyQueue ({ axios, config }) {
229229
if (!this.config.retryOnError || networkError > this.config.retryLimit) {
230230
return Promise.reject(responseHandler(error))
231231
}
232+
// Check rate limit remaining header before retrying
232233

233234
// Error handling
234235
const wait = this.config.retryDelay

lib/entity.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,20 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me
8585
}
8686
}
8787

88-
export const create = ({ http, params = {}, createWithPreviewToken = false }) => {
88+
export const create = ({ http, params }) => {
8989
return async function (data, param) {
9090
this.stackHeaders = {
9191
...this.stackHeaders
9292
}
93-
const queryParams = {
94-
...(createWithPreviewToken ? { create_with_preview_token: true } : {}),
95-
...cloneDeep(param) // user param can override default
96-
}
93+
9794
const headers = {
9895
headers: {
9996
...cloneDeep(params),
10097
...cloneDeep(this.stackHeaders)
10198
},
102-
params: queryParams
99+
params: {
100+
...cloneDeep(param)
101+
}
103102
} || {}
104103

105104
try {
@@ -158,11 +157,6 @@ export const update = (http, type, params = {}) => {
158157
delete json.updated_at
159158
delete json.updated_by
160159

161-
// If param has data for this entity type, merge it with the json object
162-
if (param && param[type]) {
163-
Object.assign(json, param[type])
164-
}
165-
166160
if (type) {
167161
updateData[type] = json
168162
if (type === 'entry') updateData[type] = cleanAssets(updateData[type])
@@ -319,7 +313,6 @@ export const move = (http, type, force = false, params = {}) => {
319313
try {
320314
let updateData = {}
321315
const json = cloneDeep(this)
322-
delete json.parent_uid
323316
if (type) {
324317
updateData[type] = json
325318
} else {
@@ -334,7 +327,7 @@ export const move = (http, type, force = false, params = {}) => {
334327
if (force === true) {
335328
headers.params.force = true
336329
}
337-
const response = await http.put(`${this.urlPath}/move`, updateData, headers)
330+
const response = await http.put(`${this.urlPath}/move`, param, headers)
338331
if (response.data) {
339332
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
340333
} else {

lib/stack/asset/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,35 @@ export function Asset (http, data = {}) {
152152
*
153153
*/
154154
this.unpublish = unpublish(http, 'asset')
155+
156+
/**
157+
* @description The References function will get all the references for the asset.
158+
* @memberof Asset
159+
* @func references
160+
* @returns {Promise<Array>} Array of references.
161+
* @param {Object} param - Query parameters
162+
* @example
163+
* client.stack({ api_key: 'api_key'}).asset('uid').getReferences({ include_publish_details: true })
164+
* .then((references) => console.log(references))
165+
*/
166+
this.getReferences = async function (param = {}) {
167+
try {
168+
const headers = {
169+
headers: { ...cloneDeep(this.stackHeaders) },
170+
params: {
171+
...cloneDeep(param)
172+
}
173+
} || {}
174+
const response = await http.get(this.urlPath + '/references', headers)
175+
if (response.data) {
176+
return response.data
177+
} else {
178+
throw error(response)
179+
}
180+
} catch (err) {
181+
throw error(err)
182+
}
183+
}
155184
} else {
156185
/**
157186
* @description The Folder allows to fetch and create folders in assets.

lib/stack/deliveryToken/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cloneDeep from 'lodash/cloneDeep'
22
import { create, update, deleteEntity, fetch, query } from '../../entity'
3+
import { PreviewToken } from './previewToken'
34

45
/**
56
* Delivery tokens provide read-only access to the associated environments. Read more about <a href='https://www.contentstack.com/docs/developers/create-tokens/about-delivery-tokens'>DeliveryToken</a>.
@@ -59,6 +60,22 @@ export function DeliveryToken (http, data = {}) {
5960
*
6061
*/
6162
this.fetch = fetch(http, 'token')
63+
64+
/**
65+
* @description The Create a PreviewToken call creates a new previewToken in a particular stack of your Contentstack account.
66+
* @memberof DeliveryToken
67+
* @func previewToken
68+
* @returns {PreviewToken} Instance of PreviewToken.
69+
* @example
70+
* import * as contentstack from '@contentstack/management'
71+
* const client = contentstack.client()
72+
* const deliveryToken = client.stack({ api_key: 'api_key'}).deliveryToken('delivery_token_uid')
73+
* const previewToken = deliveryToken.previewToken()
74+
* console.log(previewToken)
75+
*/
76+
this.previewToken = () => {
77+
return new PreviewToken(http, { stackHeaders: this.stackHeaders, token: { uid: this.uid } })
78+
}
6279
} else {
6380
/**
6481
* @description The Create a DeliveryToken call creates a new deliveryToken in a particular stack of your Contentstack account.
@@ -84,7 +101,7 @@ export function DeliveryToken (http, data = {}) {
84101
* client.stack().deliveryToken().create({ token })
85102
* .then((deliveryToken) => console.log(deliveryToken))
86103
*/
87-
this.create = create({ http: http, createWithPreviewToken: true })
104+
this.create = create({ http: http })
88105

89106
/**
90107
* @description The ‘Get all deliveryToken’ request returns comprehensive information about all deliveryToken created in a stack.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import cloneDeep from 'lodash/cloneDeep'
2+
import { create, deleteEntity } from '../../../entity'
3+
4+
/**
5+
* Preview tokens provide read-only access to the associated environments. Read more about <a href='https://www.contentstack.com/docs/developers/create-tokens/about-preview-tokens'>PreviewToken</a>.
6+
* @namespace PreviewToken
7+
*/
8+
export function PreviewToken (http, data = {}) {
9+
this.stackHeaders = data.stackHeaders
10+
if (data.token) {
11+
Object.assign(this, cloneDeep(data.token))
12+
this.urlPath = `/stacks/delivery_tokens/${this.uid}/preview_token`
13+
14+
/**
15+
* @description The Delete PreviewToken call is used to delete an existing PreviewToken permanently from your Stack.
16+
* @memberof PreviewToken
17+
* @func delete
18+
* @returns {Object} Response Object.
19+
* @example
20+
* import * as contentstack from '@contentstack/management'
21+
* const client = contentstack.client()
22+
*
23+
* client.stack({ api_key: 'api_key'}).deliveryToken('delivery_token_uid').previewToken().delete()
24+
* .then((response) => console.log(response.notice))
25+
*/
26+
this.delete = deleteEntity(http)
27+
28+
/**
29+
* @description The Create a PreviewToken call creates a new previewToken in a particular stack of your Contentstack account.
30+
* @memberof PreviewToken
31+
* @func create
32+
* @returns {Promise<PreviewToken.PreviewToken>} Promise for PreviewToken instance
33+
*
34+
* @example
35+
* import * as contentstack from '@contentstack/management'
36+
* const client = contentstack.client()
37+
* client.stack().deliveryToken('delivery_token_uid').previewToken().create()
38+
* .then((previewToken) => console.log(previewToken))
39+
*/
40+
this.create = create({ http: http })
41+
}
42+
}
43+
44+
export function PreviewTokenCollection (http, data) {
45+
const obj = cloneDeep(data.tokens) || []
46+
const previewTokenCollection = obj.map((userdata) => {
47+
return new PreviewToken(http, { token: userdata, stackHeaders: data.stackHeaders })
48+
})
49+
return previewTokenCollection
50+
}

0 commit comments

Comments
 (0)