diff --git a/package-lock.json b/package-lock.json index d6c3105a71..776c3e9797 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23493,7 +23493,7 @@ "version": "1.12.0", "license": "MIT", "dependencies": { - "@contentstack/cli-audit": "~1.3.1", + "@contentstack/cli-audit": "~1.3.2", "@contentstack/cli-auth": "~1.3.17", "@contentstack/cli-cm-bootstrap": "~1.7.1", "@contentstack/cli-cm-branches": "~1.0.19", @@ -23558,7 +23558,7 @@ }, "packages/contentstack-audit": { "name": "@contentstack/cli-audit", - "version": "1.3.1", + "version": "1.3.2", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.16", diff --git a/packages/contentstack-audit/package.json b/packages/contentstack-audit/package.json index 1412682711..202e4c6d65 100644 --- a/packages/contentstack-audit/package.json +++ b/packages/contentstack-audit/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-audit", - "version": "1.3.1", + "version": "1.3.2", "description": "Contentstack audit plugin", "author": "Contentstack CLI", "homepage": "https://github.com/contentstack/cli", @@ -19,7 +19,7 @@ ], "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@oclif/plugin-help": "^5", "@oclif/plugin-plugins": "^4.1.9", "chalk": "^4.1.2", diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index 1a9ec7db80..b1794a4247 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -60,7 +60,11 @@ export abstract class AuditBaseCommand extends BaseCommand { const { uid, data_type } = field; + if (!Object(entry).hasOwnProperty(uid)) { + return; + } + switch (data_type) { case 'global_field': entry[uid] = this.fixGlobalFieldReferences( @@ -474,7 +482,6 @@ export default class Entries { break; } } - // NOTE Reference field entry[uid] = this.fixMissingReferences( [...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], @@ -623,19 +630,21 @@ export default class Entries { return this.fixJsonRteMissingReferences([...tree, { index, type: child?.type, uid: child?.uid }], field, child); }) as EntryJsonRTEFieldDataType[]; } else { - entry.children = entry.children - .map((child) => { - const refExist = this.jsonRefCheck(tree, field, child); + if (entry?.children) { + entry.children = entry.children + .map((child) => { + const refExist = this.jsonRefCheck(tree, field, child); - if (!refExist) return null; + if (!refExist) return null; - if (isEmpty(child.children)) { - child = this.fixJsonRteMissingReferences(tree, field, child) as EntryJsonRTEFieldDataType; - } + if (!isEmpty(child.children)) { + child = this.fixJsonRteMissingReferences(tree, field, child) as EntryJsonRTEFieldDataType; + } - return child; - }) - .filter((val) => val) as EntryJsonRTEFieldDataType[]; + return child; + }) + .filter((val) => val) as EntryJsonRTEFieldDataType[]; + } } return entry; diff --git a/packages/contentstack-auth/package.json b/packages/contentstack-auth/package.json index ef27bae5b7..4af4afb1c6 100644 --- a/packages/contentstack-auth/package.json +++ b/packages/contentstack-auth/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "chalk": "^4.0.0", "debug": "^4.1.1", "inquirer": "8.2.4", diff --git a/packages/contentstack-bootstrap/package.json b/packages/contentstack-bootstrap/package.json index 5d7767b8f5..9b07d8bb3b 100644 --- a/packages/contentstack-bootstrap/package.json +++ b/packages/contentstack-bootstrap/package.json @@ -19,7 +19,7 @@ "dependencies": { "@contentstack/cli-cm-seed": "~1.7.0", "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "inquirer": "8.2.4", "mkdirp": "^1.0.4", "tar": "^6.1.13" diff --git a/packages/contentstack-branches/package.json b/packages/contentstack-branches/package.json index c085e73c4b..f9fe694229 100644 --- a/packages/contentstack-branches/package.json +++ b/packages/contentstack-branches/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@oclif/core": "^2.9.3", "async": "^3.2.4", "big-json": "^3.2.0", diff --git a/packages/contentstack-bulk-publish/package.json b/packages/contentstack-bulk-publish/package.json index 11175711f6..924108631c 100644 --- a/packages/contentstack-bulk-publish/package.json +++ b/packages/contentstack-bulk-publish/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "bluebird": "^3.7.2", "chalk": "^4.1.2", "dotenv": "^16.1.4", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 7db139c301..e0d7614279 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -8,7 +8,7 @@ "@contentstack/cli-cm-export": "~1.10.2", "@contentstack/cli-cm-import": "~1.12.2", "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@colors/colors": "^1.5.0", "async": "^3.2.4", "chalk": "^4.1.0", diff --git a/packages/contentstack-command/package.json b/packages/contentstack-command/package.json index c4150ff6ca..716ba3e8ac 100644 --- a/packages/contentstack-command/package.json +++ b/packages/contentstack-command/package.json @@ -17,7 +17,7 @@ "format": "eslint src/**/*.ts --fix" }, "dependencies": { - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "contentstack": "^3.10.1" }, "devDependencies": { diff --git a/packages/contentstack-config/README.md b/packages/contentstack-config/README.md index 11dfabf3ac..f9fd176b04 100644 --- a/packages/contentstack-config/README.md +++ b/packages/contentstack-config/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-config/1.5.0 darwin-arm64 node-v20.8.0 +@contentstack/cli-config/1.5.1 darwin-arm64 node-v20.8.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-config/package.json b/packages/contentstack-config/package.json index fa72150a28..0ebe6c6737 100644 --- a/packages/contentstack-config/package.json +++ b/packages/contentstack-config/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-config", "description": "Contentstack CLI plugin for configuration", - "version": "1.5.0", + "version": "1.5.1", "author": "Contentstack", "scripts": { "build": "npm run clean && npm run compile", @@ -22,7 +22,7 @@ }, "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "chalk": "^4.0.0", "debug": "^4.1.1", "inquirer": "8.2.4", diff --git a/packages/contentstack-config/src/commands/config/set/early-access-header.ts b/packages/contentstack-config/src/commands/config/set/early-access-header.ts index eb5f2f9b06..f63d40c9ee 100644 --- a/packages/contentstack-config/src/commands/config/set/early-access-header.ts +++ b/packages/contentstack-config/src/commands/config/set/early-access-header.ts @@ -20,10 +20,10 @@ export default class SetEarlyAccessHeaderCommand extends Command { flags: { header: earlyAccessHeader, 'header-alias': earlyAccessHeaderAlias }, } = await this.parse(SetEarlyAccessHeaderCommand); if (!earlyAccessHeaderAlias) { - earlyAccessHeaderAlias = await interactive.askEarlyAccessHeaderAlias(); + earlyAccessHeaderAlias = (await interactive.askEarlyAccessHeaderAlias())?.trim(); } if (!earlyAccessHeader) { - earlyAccessHeader = await interactive.askEarlyAccessHeaderValue(); + earlyAccessHeader = (await interactive.askEarlyAccessHeaderValue())?.trim(); } configHandler.set(`earlyAccessHeaders.${earlyAccessHeaderAlias}`, earlyAccessHeader); cliux.success( diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index e7c0e21de2..1fae8312a8 100644 --- a/packages/contentstack-export-to-csv/package.json +++ b/packages/contentstack-export-to-csv/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "chalk": "^4.1.0", "fast-csv": "^4.3.6", "inquirer": "8.2.4", diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index 23b84d85bf..5c2874f7be 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@oclif/core": "^2.9.3", "async": "^3.2.4", "big-json": "^3.2.0", @@ -98,4 +98,4 @@ } }, "repository": "https://github.com/contentstack/cli" -} +} \ No newline at end of file diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index a5435bf7ab..6da5117134 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@contentstack/management": "~1.13.0", "@oclif/core": "^2.9.3", "axios": "^1.6.0", diff --git a/packages/contentstack-launch/package.json b/packages/contentstack-launch/package.json index a885e441a8..76389cf34a 100755 --- a/packages/contentstack-launch/package.json +++ b/packages/contentstack-launch/package.json @@ -19,7 +19,7 @@ "dependencies": { "@apollo/client": "^3.7.9", "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@oclif/core": "^2.9.3", "@oclif/plugin-help": "^5", "@oclif/plugin-plugins": "^4.1.9", @@ -105,4 +105,4 @@ "launch:deployments": "LNCH-DPLMNT" } } -} +} \ No newline at end of file diff --git a/packages/contentstack-migrate-rte/package.json b/packages/contentstack-migrate-rte/package.json index ea0b71e591..c0e4cf86b1 100644 --- a/packages/contentstack-migrate-rte/package.json +++ b/packages/contentstack-migrate-rte/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@contentstack/json-rte-serializer": "~2.0.4", "collapse-whitespace": "^1.1.7", "chalk": "^4.1.2", diff --git a/packages/contentstack-migration/package.json b/packages/contentstack-migration/package.json index d5dfe6add3..fcb26548c8 100644 --- a/packages/contentstack-migration/package.json +++ b/packages/contentstack-migration/package.json @@ -5,7 +5,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "async": "^3.2.4", "callsites": "^3.1.0", "cardinal": "^2.1.1", diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index ba9b796186..5ebadf20a8 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -7,7 +7,7 @@ "dependencies": { "@contentstack/cli-cm-import": "~1.12.2", "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "inquirer": "8.2.4", "mkdirp": "^1.0.4", "tar": "^6.1.13", diff --git a/packages/contentstack-utilities/package.json b/packages/contentstack-utilities/package.json index bbb5373429..691f2a40ec 100644 --- a/packages/contentstack-utilities/package.json +++ b/packages/contentstack-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-utilities", - "version": "1.5.9", + "version": "1.5.10", "description": "Utilities for contentstack projects", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -83,4 +83,4 @@ "tslib": "^1.13.0", "typescript": "^4.9.3" } -} +} \ No newline at end of file diff --git a/packages/contentstack-utilities/src/http-client/client.ts b/packages/contentstack-utilities/src/http-client/client.ts index 7db8321b52..323cfd97d1 100644 --- a/packages/contentstack-utilities/src/http-client/client.ts +++ b/packages/contentstack-utilities/src/http-client/client.ts @@ -4,6 +4,9 @@ import { HttpResponse } from './http-response'; import configStore from '../config-handler'; import authHandler from '../auth-handler'; +type HttpClientOptions = { + disableEarlyAccessHeaders?: boolean; +}; export class HttpClient implements IHttpClient { /** * The request configuration. @@ -15,6 +18,8 @@ export class HttpClient implements IHttpClient { */ private readonly axiosInstance: AxiosInstance; + private disableEarlyAccessHeaders: boolean; + /** * The payload format for a JSON or form-url-encoded request. */ @@ -23,9 +28,10 @@ export class HttpClient implements IHttpClient { /** * Createa new pending HTTP request instance. */ - constructor(request: AxiosRequestConfig = {}) { + constructor(request: AxiosRequestConfig = {}, options: HttpClientOptions = {}) { this.request = request; this.axiosInstance = Axios.create(); + this.disableEarlyAccessHeaders = options.disableEarlyAccessHeaders || false; // Sets payload format as json by default this.asJson(); @@ -351,24 +357,53 @@ export class HttpClient implements IHttpClient { */ async createAndSendRequest(method: HttpMethod, url: string): Promise { let counter = 0; - this.axiosInstance.interceptors.response.use(null, async error => { + this.axiosInstance.interceptors.response.use(null, async (error) => { const { message, response } = error; if (response?.data?.error_message?.includes('access token is invalid or expired')) { const token = await this.refreshToken(); this.headers({ ...this.request.headers, authorization: token.authorization }); - return await this.axiosInstance({ url, method, withCredentials: true, ...this.request, data: this.prepareRequestPayload(), }) + return await this.axiosInstance({ + url, + method, + withCredentials: true, + ...this.request, + data: this.prepareRequestPayload(), + }); } // Retry while Network timeout or Network Error - if (!(message.includes('timeout') || message.includes('Network Error') || message.includes('getaddrinfo ENOTFOUND'))) { + if ( + !(message.includes('timeout') || message.includes('Network Error') || message.includes('getaddrinfo ENOTFOUND')) + ) { return Promise.reject(error); } if (counter < 1) { counter++; - return await this.axiosInstance({ url, method, withCredentials: true, ...this.request, data: this.prepareRequestPayload(), }) + return await this.axiosInstance({ + url, + method, + withCredentials: true, + ...this.request, + data: this.prepareRequestPayload(), + }); } return Promise.reject(error); }); - return await this.axiosInstance({ url, method, withCredentials: true, ...this.request, data: this.prepareRequestPayload(), }) + + if (!this.disableEarlyAccessHeaders) { + // Add early access header by default + const earlyAccessHeaders = configStore.get(`earlyAccessHeaders`); + if (earlyAccessHeaders && Object.keys(earlyAccessHeaders).length > 0) { + this.headers({ 'x-header-ea': Object.values(earlyAccessHeaders).join(',') }); + } + } + + return await this.axiosInstance({ + url, + method, + withCredentials: true, + ...this.request, + data: this.prepareRequestPayload(), + }); } /** @@ -383,8 +418,9 @@ export class HttpClient implements IHttpClient { if (authorisationType === 'BASIC') { return Promise.reject('Your session is timed out, please login to proceed'); } else if (authorisationType === 'OAUTH') { - return authHandler.compareOAuthExpiry(true) - .then(() => Promise.resolve({ authorization: `Bearer ${configStore.get('oauthAccessToken')}`, })) + return authHandler + .compareOAuthExpiry(true) + .then(() => Promise.resolve({ authorization: `Bearer ${configStore.get('oauthAccessToken')}` })) .catch((error) => Promise.reject(error)); } else { return Promise.reject('You do not have permissions to perform this action, please login to proceed'); diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index 6f2def36ed..ff09a87ddd 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli/1.12.0 darwin-arm64 node-v20.8.0 +@contentstack/cli/1.12.1 darwin-arm64 node-v20.8.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index e55eb1af53..0deadcc227 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli", "description": "Command-line tool (CLI) to interact with Contentstack", - "version": "1.12.0", + "version": "1.12.1", "author": "Contentstack", "bin": { "csdx": "./bin/run" @@ -22,7 +22,7 @@ "prepack": "pnpm compile && oclif manifest && oclif readme" }, "dependencies": { - "@contentstack/cli-audit": "~1.3.1", + "@contentstack/cli-audit": "~1.3.2", "@contentstack/cli-auth": "~1.3.17", "@contentstack/cli-cm-bootstrap": "~1.7.1", "@contentstack/cli-cm-branches": "~1.0.19", @@ -34,10 +34,10 @@ "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.0", "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-config": "~1.5.0", + "@contentstack/cli-config": "~1.5.1", "@contentstack/cli-launch": "~1.0.15", "@contentstack/cli-migration": "~1.4.2", - "@contentstack/cli-utilities": "~1.5.9", + "@contentstack/cli-utilities": "~1.5.10", "@contentstack/management": "~1.13.0", "@oclif/core": "^2.9.3", "@oclif/plugin-help": "^5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c9ca9965b..0b8d7ccdba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,7 +10,7 @@ importers: packages/contentstack: specifiers: - '@contentstack/cli-audit': ~1.3.1 + '@contentstack/cli-audit': ~1.3.2 '@contentstack/cli-auth': ~1.3.17 '@contentstack/cli-cm-bootstrap': ~1.7.1 '@contentstack/cli-cm-branches': ~1.0.19