Skip to content

DX | 13-01-2025 | Release #240

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 20 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0e5105b
Merge pull request #226 from contentstack/staging
cs-raj Dec 5, 2024
2411594
fix: customBackOff fix
Dec 12, 2024
3fba7cf
add items to bulk operation and corresponding tests
harshithad0703 Dec 13, 2024
d96c4ac
implementation, api and unit test case for fetch by job status
harshithad0703 Dec 17, 2024
bec711e
Merge pull request #229 from contentstack/feat/dx-1591-bulk-operation…
harshithad0703 Dec 17, 2024
ee7f925
Merge pull request #233 from contentstack/feat/dx-1592-fetch-job-status
harshithad0703 Dec 17, 2024
de267b4
update items implementation,api and unit test cases and types support
harshithad0703 Dec 20, 2024
5079d20
move items from release implementation, unit & api test cases, types …
harshithad0703 Dec 20, 2024
aa9e1d5
removed console log
harshithad0703 Dec 21, 2024
c5a6170
Merge pull request #235 from contentstack/feat/dx-1594-update-move-items
harshithad0703 Dec 21, 2024
21854fc
Merge pull request #228 from contentstack/fix/DX-1409
netrajpatel Jan 6, 2025
23b262f
updated doc changes
harshithad0703 Jan 8, 2025
97247f5
updated add and delete items implementation according to release v2
harshithad0703 Jan 8, 2025
ea0fd04
added unit and api test cases
harshithad0703 Jan 8, 2025
22c3d07
added types support for add and delete
harshithad0703 Jan 8, 2025
d445bad
Merge pull request #236 from contentstack/feat/dx-1595-add-delete-items
harshithad0703 Jan 8, 2025
f73f540
Merge pull request #237 from contentstack/development
harshithad0703 Jan 9, 2025
9bdc7d3
Merge pull request #238 from contentstack/feat/release-2.0
harshithad0703 Jan 9, 2025
1c4a4b9
version bump to 1.19.0
harshithad0703 Jan 9, 2025
481b4c3
Merge pull request #239 from contentstack/fix/version-bump-1.19.0
harshithad0703 Jan 9, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog

## [v1.19.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.0) (2025-01-13)
- Feature
- Release 2.0 feature
## [v1.18.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.4) (2024-11-22)
- Enhancement
- Added support for response headers.
Expand Down
2 changes: 1 addition & 1 deletion lib/core/concurrency-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export function ConcurrencyQueue ({ axios, config }) {
} else {
return Promise.reject(responseHandler(error))
}
} else if (response.status === 429 || (response.status === 401 && this.config.refreshToken)) {
} else if ((response.status === 401 && this.config.refreshToken)) {
retryErrorType = `Error with status: ${response.status}`
networkError++

Expand Down
103 changes: 103 additions & 0 deletions lib/stack/bulkOperation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,109 @@ export function BulkOperation (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/bulk`

/**
* The addItems request allows you to add multiple items to a release in bulk.
* @memberof BulkOperation
* @func addItems
* @returns {Promise<Object>} Response Object.
* @param {Object} params.data - The data containing the items to be added to the release.
* @param {String} [params.bulk_version] - The bulk version.
* @example
* const itemsData = {
* items: [
* {
* uid: '{{entry_uid}}',
* content_type: '{{content_type_uid}}'
* }
* ]
* }
* client.stack({ api_key: 'api_key'}).bulkOperation().addItems({ data: itemsData })
* .then((response) => { console.log(response) })
*/
this.addItems = async ({ data, bulk_version = "" }) => {
this.urlPath = `/bulk/release/items`;
const headers = {
headers: {
...cloneDeep(this.stackHeaders),
},
};
if (bulk_version) headers.headers.bulk_version = bulk_version;
try {
const response = await http.post(this.urlPath, data, headers);
if (response.data) {
return response.data;
}
} catch (error) {
console.error(error);
}
};

/**
* The updateItems request allows you to update multiple items in a release in bulk.
* @memberof BulkOperation
* @func updateItems
* @returns {Promise<Object>} Response Object.
* @param {Object} params.data - The data containing the items to be updated in the release.
* @param {String} [params.bulk_version] - The bulk version.
* @example
* const itemsData = {
* items: [
* {
* uid: '{{entry_uid}}',
* content_type: '{{content_type_uid}}'
* }
* ]
* }
* client.stack({ api_key: 'api_key'}).bulkOperation().updateItems({ data: itemsData })
* .then((response) => { console.log(response) })
*/
this.updateItems = async ({ data, bulk_version = "" }) => {
this.urlPath = `/bulk/release/update_items`;
const headers = {
headers: {
...cloneDeep(this.stackHeaders),
},
};
if (bulk_version) headers.headers.bulk_version = bulk_version;
try {
const response = await http.put(this.urlPath, data, headers);
if (response.data) {
return response.data;
}
} catch (error) {
console.error(error);
}
};

/**
* The jobStatus request allows you to check the status of a bulk job.
* @memberof BulkOperation
* @func jobStatus
* @returns {Promise<Object>} Response Object.
* @param {String} params.job_id - The ID of the job.
* @param {String} [params.bulk_version] - The bulk version.
* @example
* client.stack({ api_key: 'api_key'}).bulkOperation().jobStatus({ job_id: 'job_id' })
* .then((response) => { console.log(response) })
*/
this.jobStatus = async ({ job_id, bulk_version = "" }) => {
this.urlPath = `/bulk/jobs/${job_id}`;
const headers = {
headers: {
...cloneDeep(this.stackHeaders),
},
};
if (bulk_version) headers.headers.bulk_version = bulk_version;
try {
const response = await http.get(this.urlPath, headers);
if (response.data) {
return response.data;
}
} catch (error) {
console.error(error);
}
};

/**
* The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time.
* @memberof BulkOperation
Expand Down
73 changes: 67 additions & 6 deletions lib/stack/release/items/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,36 @@ export function ReleaseItem (http, data = {}) {
* client.stack({ api_key: 'api_key'}).release('release_uid').delete({items})
* .then((response) => console.log(response.notice))
*/
this.delete = async (items) => {
this.delete = async (params) => {
let param = {}
if (items === undefined) {
if (params.items === undefined && params.item === undefined) {
param = {all: true}
params.items = []
}
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) },
data: {
...cloneDeep(items)
...cloneDeep(params)
},
params: {
...cloneDeep(param)
}
} || {}

if (params.release_version) {
headers.headers['release_version'] = params.release_version;
}

if (params.item) {
this.urlPath = `releases/${data.releaseUid}/item`
headers.data['item'] = params.item
} else
headers.data['items'] = params.items

const response = await http.delete(this.urlPath, headers)
if (response.data) {
return new Release(http, { ...response.data, stackHeaders: data.stackHeaders })
return response.data
} else {
throw error(response)
}
Expand Down Expand Up @@ -129,9 +140,18 @@ export function ReleaseItem (http, data = {}) {
...cloneDeep(this.stackHeaders)
}
} || {}

if (param.release_version) {
headers.headers['release_version'] = param.release_version;
}
if (param.item) {
this.urlPath = `releases/${data.releaseUid}/item`
param['item'] = param.item
} else
param['items'] = param.items

try {
const response = await http.post(param.item ? `releases/${data.releaseUid}/item` : this.urlPath, param, headers)
const response = await http.post(this.urlPath, param, headers)
if (response.data) {
if (response.data) {
return new Release(http, { ...response.data, stackHeaders: data.stackHeaders })
Expand Down Expand Up @@ -166,7 +186,10 @@ export function ReleaseItem (http, data = {}) {
...cloneDeep(param)
}
} || {}

if (param.release_version) {
headers.headers['release_version'] = param.release_version;
delete headers.params.release_version;
}
const response = await http.get(this.urlPath, headers)
if (response.data) {
return new ContentstackCollection(response, http, this.stackHeaders, ReleaseItemCollection)
Expand All @@ -177,6 +200,44 @@ export function ReleaseItem (http, data = {}) {
error(err)
}
}

/**
* The move request allows you to move multiple items within a release.
* @memberof ReleaseItem
* @func move
* @returns {Promise<Object>} Response Object.
* @param {Object} params.param - The data containing the items to be moved within the release.
* @param {String} [params.release_version] - The release version.
* @example
* const moveData = {
* items: [
* {
* uid: '{{entry_uid}}',
* content_type: '{{content_type_uid}}'
* }
* ]
* }
* client.stack({ api_key: 'api_key'}).release('release_uid').item().move({ param: moveData, release_version: '1.0' })
* .then((response) => { console.log(response) })
*/
this.move = async ({ param, release_version = '' }) => {
const headers = {
headers: {
...cloneDeep(this.stackHeaders)
}
} || {}
if (release_version) {
headers.headers['release_version'] = release_version;
}
try {
const response = await http.put(`${this.urlPath}/move`, param, headers)
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}
}
return this
}
Expand Down
Loading
Loading