From 0eac4540e446fc4d2a207fa844743e29d96dfcd5 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 15 Dec 2023 14:40:35 +0530 Subject: [PATCH 01/39] added preview token as required in env file --- .../src/bootstrap/github/client.ts | 2 +- .../contentstack-bootstrap/src/bootstrap/utils.ts | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/contentstack-bootstrap/src/bootstrap/github/client.ts b/packages/contentstack-bootstrap/src/bootstrap/github/client.ts index d2c6fc8160..bf300bc045 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/github/client.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/github/client.ts @@ -1,7 +1,7 @@ import { Stream } from 'stream'; import * as zlib from 'zlib'; import * as tar from 'tar'; -import * as mkdirp from 'mkdirp'; +const mkdirp = require('mkdirp') import { HttpRequestConfig, HttpClient } from '@contentstack/cli-utilities'; import GithubError from './github-error'; diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index 4ee10a9588..6cff39c1ba 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -10,6 +10,7 @@ interface EnviornmentVariables { deliveryToken: string; environment: string; livePreviewEnabled?: boolean; + preview_token: string } /** @@ -56,13 +57,14 @@ export const setupEnvironments = async ( }; if (!managementToken) { try { - const tokenResult = await managementAPIClient.stack({ api_key }).deliveryToken().create(body); + const tokenResult = await managementAPIClient.stack({ api_key }).deliveryToken().create(body,{"create_with_preview_token":true}); if (tokenResult.token) { const environmentVariables: EnviornmentVariables = { api_key, deliveryToken: tokenResult.token, environment: environment.name, livePreviewEnabled, + preview_token: tokenResult.preview_token }; await envFileHandler( appConfig.appConfigKey || '', @@ -139,7 +141,7 @@ const envFileHandler = async ( environmentVariables.api_key }\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken - }\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ + }\nREACT_APP_CONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token}\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ customHost ? '\nREACT_APP_CONTENTSTACK_API_HOST=' + customHost : '' }${ !isUSRegion && !customHost ? '\nREACT_APP_CONTENTSTACK_REGION=' + region.name : '' @@ -152,7 +154,7 @@ const envFileHandler = async ( filePath = path.join(clonedDirectory, fileName); content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken - }\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${ + }\nCONTENTSTACK_LIVE_PREVIEW=${environmentVariables.preview_token}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${ customHost ? customHost : managementAPIHost }${ !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' @@ -163,7 +165,7 @@ const envFileHandler = async ( case 'gatsby-starter': fileName = `.env.${environmentVariables.environment}`; filePath = path.join(clonedDirectory, fileName); - content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${managementAPIHost}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`; + content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${managementAPIHost}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`; result = await writeEnvFile(content, filePath); break; case 'angular': @@ -171,7 +173,7 @@ const envFileHandler = async ( environmentVariables.environment === 'production' ? true : false }, \n\tconfig : { \n\t\tapi_key: '${environmentVariables.api_key}', \n\t\tdelivery_token: '${ environmentVariables.deliveryToken - }', \n\t\tenvironment: '${environmentVariables.environment}'${ + }',\npreview_token:'${environmentVariables.preview_token}', \n\t\tenvironment: '${environmentVariables.environment}'${ !isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : '' } \n\t } \n };`; fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`; @@ -181,7 +183,7 @@ const envFileHandler = async ( case 'angular-starter': content = `export const environment = { \n\tproduction: true \n}; \nexport const Config = { \n\tapi_key: '${ environmentVariables.api_key - }', \n\tdelivery_token: '${environmentVariables.deliveryToken}', \n\tenvironment: '${ + }', \n\tdelivery_token: '${environmentVariables.deliveryToken}',\n\tpreview_token: '${environmentVariables.preview_token}',\n\tenvironment: '${ environmentVariables.environment }'${!isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : ''},\n\tapi_host: '${ customHost ? customHost : managementAPIHost From 646072b71106bc9479b768013d1beac5774b4617 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 18 Dec 2023 16:02:59 +0530 Subject: [PATCH 02/39] added preview host --- .../src/bootstrap/utils.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index 6cff39c1ba..d77e0f7227 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -55,16 +55,15 @@ export const setupEnvironments = async ( ], }, }; - if (!managementToken) { try { - const tokenResult = await managementAPIClient.stack({ api_key }).deliveryToken().create(body,{"create_with_preview_token":true}); + const tokenResult = !managementToken? await managementAPIClient.stack({ api_key }).deliveryToken().create(body,livePreviewEnabled?{"create_with_preview_token":true}:{}) :{}; if (tokenResult.token) { const environmentVariables: EnviornmentVariables = { api_key, - deliveryToken: tokenResult.token, + deliveryToken: tokenResult.token??'', environment: environment.name, livePreviewEnabled, - preview_token: tokenResult.preview_token + preview_token: tokenResult.preview_token??'' }; await envFileHandler( appConfig.appConfigKey || '', @@ -80,7 +79,6 @@ export const setupEnvironments = async ( console.log('error', error); cliux.print(messageHandler.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV', environment.name)); } - } } else { cliux.print('No environments name found for the environment'); } @@ -125,11 +123,13 @@ const envFileHandler = async ( let filePath; let fileName; let customHost; + let previewHost:string; const regionName = region && region.name && region.name.toLowerCase(); - const managementAPIHost = region.cma && region.cma.substring('8'); + previewHost = region.cda().replace('cdn','rest-preview'); const isUSRegion = regionName === 'us' || regionName === 'na'; if (regionName !== 'eu' && !isUSRegion) { - customHost = region.cma && region.cma.substring('8'); + customHost = region.cda && region.cda.substring('8'); + customHost = customHost.replace('cdn','rest-preview') } const production = environmentVariables.environment === 'production' ? true : false; switch (appConfigKey) { @@ -141,9 +141,7 @@ const envFileHandler = async ( environmentVariables.api_key }\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken - }\nREACT_APP_CONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token}\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ - customHost ? '\nREACT_APP_CONTENTSTACK_API_HOST=' + customHost : '' - }${ + }\n${livePreviewEnabled?`\nREACT_APP_CONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token}\nREACT_APP_CONTENTSTACK_PREVIEW_HOST=${customHost??previewHost}\n`:''}\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${ !isUSRegion && !customHost ? '\nREACT_APP_CONTENTSTACK_REGION=' + region.name : '' }\nSKIP_PREFLIGHT_CHECK=true\nREACT_APP_CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`; result = await writeEnvFile(content, filePath); From 5d0811080a1981731c0539066ae239068d9c5db8 Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Tue, 19 Dec 2023 13:02:20 +0530 Subject: [PATCH 03/39] lock file update --- packages/contentstack/README.md | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index ddb48aeb3b..6f2def36ed 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -2958,14 +2958,14 @@ _See code: [@contentstack/cli-config](https://github.com/contentstack/cli/blob/m ## `csdx config:get:ea-header` -Display early access headers +Display Early Access Program headers ``` USAGE $ csdx config:get:ea-header DESCRIPTION - Display early access headers + Display Early Access Program headers ALIASES $ csdx config:get:ea-header @@ -2976,14 +2976,14 @@ EXAMPLES ## `csdx config:get:early-access-header` -Display early access headers +Display Early Access Program headers ``` USAGE $ csdx config:get:early-access-header DESCRIPTION - Display early access headers + Display Early Access Program headers ALIASES $ csdx config:get:ea-header @@ -3036,7 +3036,7 @@ _See code: [@contentstack/cli-config](https://github.com/contentstack/cli/blob/m ## `csdx config:remove:ea-header` -Remove early access header +Remove Early Access Program header ``` USAGE @@ -3047,7 +3047,7 @@ FLAGS --header-alias= Early access header alias DESCRIPTION - Remove early access header + Remove Early Access Program header ALIASES $ csdx config:remove:ea-header @@ -3060,7 +3060,7 @@ EXAMPLES ## `csdx config:remove:early-access-header` -Remove early access header +Remove Early Access Program header ``` USAGE @@ -3071,7 +3071,7 @@ FLAGS --header-alias= Early access header alias DESCRIPTION - Remove early access header + Remove Early Access Program header ALIASES $ csdx config:remove:ea-header @@ -3109,7 +3109,7 @@ _See code: [@contentstack/cli-config](https://github.com/contentstack/cli/blob/m ## `csdx config:set:ea-header` -Set early access header +Set Early Access Program header ``` USAGE @@ -3117,10 +3117,10 @@ USAGE FLAGS --header= Early access header value - --header-alias= Alias for the header + --header-alias= Early access header alias DESCRIPTION - Set early access header + Set Early Access Program header ALIASES $ csdx config:set:ea-header @@ -3133,7 +3133,7 @@ EXAMPLES ## `csdx config:set:early-access-header` -Set early access header +Set Early Access Program header ``` USAGE @@ -3141,10 +3141,10 @@ USAGE FLAGS --header= Early access header value - --header-alias= Alias for the header + --header-alias= Early access header alias DESCRIPTION - Set early access header + Set Early Access Program header ALIASES $ csdx config:set:ea-header @@ -3213,7 +3213,7 @@ DESCRIPTION Display help for csdx. ``` -_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.20/src/commands/help.ts)_ +_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.14/src/commands/help.ts)_ ## `csdx launch` @@ -3258,7 +3258,7 @@ EXAMPLES $ csdx launch --config --type --name= --environment= --branch= --build-command= --framework=