From f17f78e4b3071a166cacce293b2179d3541b3805 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:26:17 +0530 Subject: [PATCH] Added support for returning response headers --- CHANGELOG.md | 6 ++++++ lib/contentstackCollection.js | 6 ++++++ lib/entity.js | 16 +++++++++++----- package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30e7d449..43227268 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog +## [v1.18.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.4) (2024-11-22) + - Enhancement + - Added support for response headers. +## [v1.18.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.3) (2024-11-8) + - Fix + - Fixed incorrect input type for bulk delete operation ## [v1.18.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.2) (2024-10-3) - Fix - Variants testcases Added diff --git a/lib/contentstackCollection.js b/lib/contentstackCollection.js index 7be70a01..b03fd7be 100644 --- a/lib/contentstackCollection.js +++ b/lib/contentstackCollection.js @@ -7,6 +7,12 @@ export default class ContentstackCollection { if (stackHeaders) { data.stackHeaders = stackHeaders } + if (http?.httpClientParams?.headers?.includeResHeaders === true) { + data.stackHeaders = { + ...data.stackHeaders, + responseHeaders: response.headers, + }; + } if (wrapperCollection) { this.items = wrapperCollection(http, data) } diff --git a/lib/entity.js b/lib/entity.js index d56d4d39..a1d55a23 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -84,7 +84,7 @@ export const create = ({ http, params }) => { try { const response = await http.post(this.urlPath, data, headers) if (response.data) { - return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid)) + return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http)) } else { if (response.status >= 200 && response.status < 300) { return { @@ -152,7 +152,7 @@ export const update = (http, type, params = {}) => { } }) if (response.data) { - return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid)) + return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http)) } else { throw error(response) } @@ -211,7 +211,7 @@ export const fetch = (http, type, params = {}) => { response.data[type]['content_type'] = response.data['content_type'] response.data[type]['schema'] = response.data['schema'] } - return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid)) + return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http)) } else { throw error(response) } @@ -242,7 +242,7 @@ export const fetchAll = (http, wrapperCollection, params = {}) => { } } -export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid) { +export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid, http) { const data = response.data || {} if (stackHeaders) { data.stackHeaders = stackHeaders @@ -253,6 +253,12 @@ export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid) if (taxonomy_uid) { data.taxonomy_uid = taxonomy_uid } + if (http?.httpClientParams?.headers?.includeResHeaders === true) { + data.stackHeaders = { + ...data.stackHeaders, + responseHeaders: response.headers, + }; + } return data } @@ -300,7 +306,7 @@ export const move = (http, type, force = false, params = {}) => { } const response = await http.put(`${this.urlPath}/move`, updateData, headers) if (response.data) { - return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid)) + return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http)) } else { throw error(response) } diff --git a/package-lock.json b/package-lock.json index ce227ee8..f869f821 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/management", - "version": "1.18.3", + "version": "1.18.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.18.3", + "version": "1.18.4", "license": "MIT", "dependencies": { "axios": "^1.7.4", diff --git a/package.json b/package.json index 27b1efd1..9c9e1e7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.18.3", + "version": "1.18.4", "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",