Skip to content
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

Merge staging to main #941

Merged
merged 164 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
b99f10d
fix: handled ui_locations and different schema types
abhinav-from-contentstack Jun 14, 2023
41f81fa
fix: updated versions
abhinav-from-contentstack Jun 14, 2023
cfcac2e
Merge branch 'development' into feat/CS-39167
abhinav-from-contentstack Jun 27, 2023
a00b963
extensions export & import rewrite
aman19K Jul 4, 2023
25e5bd6
fix: handle already exists extension
aman19K Jul 5, 2023
b83b471
Merge branch 'export-import-rewrite' into feat/extensions-rewrite
aman19K Jul 5, 2023
6dc2ed8
fix: extension issue
aman19K Jul 5, 2023
85ac0d1
changed code to remove branch dependency
akashbhosale97 Jul 6, 2023
1b662de
fix: extension integration test
aman19K Jul 6, 2023
fd4efd9
Merge branch 'export-import-rewrite' into feat/CS-39752
aman19K Jul 6, 2023
c297bbe
used http client to validate management token and error handling
akashbhosale97 Jul 6, 2023
292e08e
refactor: extension export & import
aman19K Jul 6, 2023
99ff0e2
fix: extension import
aman19K Jul 6, 2023
6e2588d
Merge pull request #880 from contentstack/feat/CS-39752
shafeeqd959 Jul 6, 2023
e43168e
removed branch dependency for management token
akashbhosale97 Jul 7, 2023
6f2278e
Merge branch 'development' into fix/remove-branch-dependency
shafeeqd959 Jul 7, 2023
1488083
Merge branch 'development' into CS-39867-fix/remove-branch-dependency
akashbhosale97 Jul 7, 2023
f63e0ff
Merge branch 'development' into CS-39867-fix/remove-branch-dependency
akashbhosale97 Jul 7, 2023
ba25a9f
Merge branch 'export-import-rewrite' of github.com:contentstack/cli i…
Jul 7, 2023
5614d9e
enabled new modules use
Jul 7, 2023
2b3f05b
fix(bulk-publish): added oauth and basic auth support for entry modif…
Jul 7, 2023
d22fd83
fix: doc updated
Jul 7, 2023
7549924
marketplace app export & import rewrite
aman19K Jul 7, 2023
ec6f0ca
fix: marketplace bug
aman19K Jul 10, 2023
7023eba
refactor: removed duplicate method
aman19K Jul 10, 2023
8cc72bb
fix
aman19K Jul 10, 2023
346029b
Merge branch 'development' into CS-39867-fix/remove-branch-dependency
netrajpatel Jul 10, 2023
92457ff
Merge branch 'development' into feat/CS-38496
netrajpatel Jul 10, 2023
2ccf3bb
removed validation for delivery token
akashbhosale97 Jul 10, 2023
2fba0a5
Merge branch 'development' into feat/CS-39167
abhinav-from-contentstack Jul 10, 2023
1050f86
fix: corrected function call
abhinav-from-contentstack Jul 10, 2023
fab2a4c
Merge branch 'development' into feat/CS-38496
netrajpatel Jul 10, 2023
ef0934a
Merge pull request #894 from contentstack/feat/CS-39754
shafeeqd959 Jul 10, 2023
650cfb5
Merge branch 'development' into CS-39867-fix/remove-branch-dependency
akashbhosale97 Jul 10, 2023
74dbcc7
feat(bulk-publish): added support for basic and oauth auth
Jul 10, 2023
5bbbcad
Merge branch 'development' into CS-39867-fix/remove-branch-dependency
akashbhosale97 Jul 11, 2023
ecc5959
Merge branch 'development' of github.com:contentstack/cli into export…
Jul 11, 2023
20cb916
Merge branch 'export-import-rewrite' of github.com:contentstack/cli i…
Jul 11, 2023
044a42d
environment export & import rewrite
aman19K Jul 11, 2023
ae755e3
Merge branch 'development' into feat/CS-38496
netrajpatel Jul 11, 2023
53b9e56
Merge branch 'development' into CS-39867-fix/remove-branch-dependency
netrajpatel Jul 11, 2023
deba099
feat(bulk-publish): added oauth support for unpublished entries cmd
Jul 11, 2023
3080644
feat(bulk-publish): added oauth support for entries published cmd
Jul 11, 2023
218f58e
added changes for alias flag
akashbhosale97 Jul 11, 2023
d7b8b70
content type and global fields
Jul 12, 2023
6554be6
fix: enviornment import, export integration
aman19K Jul 12, 2023
96338fe
Merge branch 'export-import-rewrite' into feat/CS-39750
aman19K Jul 12, 2023
2cedc5d
fix: log message
aman19K Jul 12, 2023
a10a0b5
feat(bulk-publish): added oauth support for unpublish cmd
Jul 12, 2023
8810de9
feat(bulk-publish): added oauth support for update and publish cmd
Jul 12, 2023
3eeed33
feat(bulk-publish): added oauth support for configure cmd
Jul 12, 2023
f893a57
refactor: removed unused fsutility instance
aman19K Jul 12, 2023
08aaa9e
add management alias support for seed command
akashbhosale97 Jul 12, 2023
8a2c7c9
fix: filehelper issue
aman19K Jul 12, 2023
481f1a1
add changes to support management token alias
akashbhosale97 Jul 13, 2023
f9bd10c
changes to get management token value
akashbhosale97 Jul 13, 2023
06b3263
Merge pull request #906 from contentstack/feat/CS-39750
shafeeqd959 Jul 13, 2023
22482e8
error message changed
akashbhosale97 Jul 13, 2023
9d545f6
Merge branch 'CS-38606/add-mgmt-token-support' into CS-38607-add-mgmt…
akashbhosale97 Jul 13, 2023
d08bc2e
Merge pull request #910 from contentstack/CS-38607-add-mgmt-token-sup…
akashbhosale97 Jul 13, 2023
581c537
readme update
akashbhosale97 Jul 13, 2023
5d6247e
remove bootstrap code
akashbhosale97 Jul 13, 2023
cca2add
Merge pull request #886 from contentstack/CS-39867-fix/remove-branch-…
akashbhosale97 Jul 13, 2023
273504b
label export & import rewrite
aman19K Jul 13, 2023
5d8c6c2
Merge branch 'feat/CS-38499' into feat/bulk_publish_oauth
Jul 13, 2023
e7671c0
Merge branch 'feat/CS-38496' into feat/bulk_publish_oauth
Jul 13, 2023
184f49d
Merge branch 'feat/CS-38500' into feat/bulk_publish_oauth
Jul 13, 2023
f9c60d6
Merge branch 'feat/CS-38501' into feat/bulk_publish_oauth
Jul 13, 2023
e809880
Merge branch 'feat/CS-38502' into feat/bulk_publish_oauth
Jul 13, 2023
c9504ed
Merge branch 'feat/CS-38503' into feat/bulk_publish_oauth
Jul 13, 2023
32a4b89
Merge branch 'feat/CS-38505' into feat/bulk_publish_oauth
Jul 13, 2023
75e8d1b
removed delivery token execution if using alias
akashbhosale97 Jul 14, 2023
e7b98b0
Merge branch 'development' into CS-38606/add-mgmt-token-support
akashbhosale97 Jul 14, 2023
2c0d40a
fix(bulk-publish): fixed config issue with stacks publish cmd
Jul 14, 2023
0529548
++ content type and global field rewrite
Jul 14, 2023
e12c741
merged changes
Jul 14, 2023
7b5dbd1
Merge pull request #911 from contentstack/feat/CS-39981
aman19K Jul 17, 2023
e4e7e16
webhook export & import rewrite
aman19K Jul 17, 2023
b33483d
fix: file or directory exists or not check
aman19K Jul 17, 2023
230e18e
feat(bulk-publish): added oauth support for stacks unpublish cmd
Jul 17, 2023
038b8d2
backup dir flag path not working fix
akashbhosale97 Jul 17, 2023
4302f7c
Merge pull request #923 from contentstack/feat/39983
shafeeqd959 Jul 18, 2023
5d6d55b
fixed bugs
Jul 18, 2023
7d8f5d0
env uncommented
Jul 18, 2023
c8eb4dd
merged with latest changes
Jul 18, 2023
c5dffe4
added types
Jul 18, 2023
30e15fd
Merge branch 'development' into feat/CS-38496
netrajpatel Jul 18, 2023
5793e37
changed @oclif/core version to fix github workflow
akashbhosale97 Jul 18, 2023
174a4d7
changed @oclif/core version to fix github workflow
akashbhosale97 Jul 18, 2023
2833833
Merge branch 'development' into feat/CS-39167
abhinav-from-contentstack Jul 18, 2023
dd888c8
fix: @oclif/core version updated to fix vulnerabilities
antonyagustine Jul 18, 2023
9eefbe5
Merge branch 'CS-40193-fix-backup-dir-flag' of https://github.com/con…
antonyagustine Jul 18, 2023
f52ee8f
Package lock file updated
antonyagustine Jul 18, 2023
50e3534
fix(auth): added message config for otp channel
Jul 18, 2023
52f7bf3
fix: updated version according to current development branch
abhinav-from-contentstack Jul 18, 2023
807077a
fix: updated lock files and READMEs
abhinav-from-contentstack Jul 18, 2023
9709f73
Merge branch 'development' into CS-38607-add-mgmt-token-support
netrajpatel Jul 19, 2023
ce58ff7
Merge pull request #925 from contentstack/CS-40193-fix-backup-dir-flag
netrajpatel Jul 19, 2023
c1852b5
Merge branch 'development' into CS-38607-add-mgmt-token-support
akashbhosale97 Jul 19, 2023
42693cc
version bump
akashbhosale97 Jul 19, 2023
b010dfe
rewrite custom role export & import and fix app mapper issue
aman19K Jul 19, 2023
305e52a
version bump
akashbhosale97 Jul 19, 2023
0c773c4
Merge pull request #930 from contentstack/feat/CS-39980
shafeeqd959 Jul 19, 2023
3e2ca09
merged latest changes
Jul 19, 2023
518c932
fix pagination
Jul 19, 2023
8eedfe8
Merge pull request #909 from contentstack/CS-38607-add-mgmt-token-sup…
akashbhosale97 Jul 19, 2023
e5ba576
Merge branch 'development' into fix/CS-40139
Jul 19, 2023
3d6db90
Merge branch 'development' into feat/CS-38508
Jul 19, 2023
e50ae47
Merge branch 'development' into feat/CS-38496
Jul 19, 2023
cdc4a47
Merge remote-tracking branch 'origin/feat/CS-38496' into feat/CS-38496
Jul 19, 2023
6502b55
Merge pull request #931 from contentstack/feat/CS-39759
aman19K Jul 19, 2023
4518a33
Merge branch 'development' of https://github.com/contentstack/cli int…
akashbhosale97 Jul 19, 2023
309a8a0
added changes for bootstrap after merging development into this
akashbhosale97 Jul 19, 2023
f146dea
added missing management token
akashbhosale97 Jul 19, 2023
989dabd
Merge branch 'development' into feat/CS-39167
abhinav-from-contentstack Jul 19, 2023
639d18d
Merge pull request #929 from contentstack/feat/CS-39167
abhinav-from-contentstack Jul 19, 2023
8a8da37
Merge branch 'development' of https://github.com/contentstack/cli int…
akashbhosale97 Jul 19, 2023
04862a1
Merge pull request #914 from contentstack/CS-38606/add-mgmt-token-sup…
akashbhosale97 Jul 19, 2023
94172e6
fix: downgraded @contentstack/management to 1.8.0
abhinav-from-contentstack Jul 19, 2023
0bb7448
fix: management sdk issue
aman19K Jul 19, 2023
732cf4b
fix: updated lock files
abhinav-from-contentstack Jul 19, 2023
7340bd7
Merge branch 'development' into fix/CS-40294
abhinav-from-contentstack Jul 19, 2023
f0fb541
updated version
aman19K Jul 19, 2023
3f95665
Merge pull request #932 from contentstack/fix/management-sdk-issue
shafeeqd959 Jul 20, 2023
be52a19
Merge staging to development
aman19K Jul 20, 2023
2332ec4
Merge pull request #933 from contentstack/fix/CS-40294
abhinav-from-contentstack Jul 20, 2023
8728057
Merge branch 'development' into fix/merge-staging-development
aman19K Jul 20, 2023
6090225
Merge pull request #934 from contentstack/fix/merge-staging-development
shafeeqd959 Jul 20, 2023
5049f35
Merge branch 'development' into export-import-rewrite
aman19K Jul 20, 2023
739d790
updated lock file
aman19K Jul 20, 2023
f4025ee
Merge branch 'feat/CS-38496' into feat/bulk_publish_oauth
Jul 20, 2023
f69f937
Merge branch 'feat/CS-38507' into feat/bulk_publish_oauth
Jul 20, 2023
b71d954
Merge branch 'feat/CS-38508' into feat/bulk_publish_oauth
Jul 20, 2023
f549dbd
Merge branch 'development' into feat/bulk_publish_oauth
Jul 20, 2023
6f03905
version bump
aman19K Jul 20, 2023
e633835
disable new module structure
aman19K Jul 20, 2023
e5dff3c
enable new structure
aman19K Jul 20, 2023
9c811f4
refactor: environment & extension
aman19K Jul 21, 2023
fe121b3
fix: marketplace management token issue
aman19K Jul 21, 2023
21f56e4
fix: app export management token issue
aman19K Jul 21, 2023
154861d
mangement sdk version bump 1.8.0 -> 1.10.0
aman19K Jul 24, 2023
63c4a66
Merge pull request #935 from contentstack/feat/bulk_publish_oauth
aman19K Jul 24, 2023
29c3487
Merge branch 'development' into fix/CS-40139
aman19K Jul 24, 2023
540e874
Merge pull request #928 from contentstack/fix/CS-40139
aman19K Jul 24, 2023
775932c
disable new file structure
aman19K Jul 24, 2023
6239386
revert: backup dir flag path changes
aman19K Jul 24, 2023
e328a5e
Merge branch 'development' into refactor/CS-40254
aman19K Jul 24, 2023
75e1ce8
Merge pull request #938 from contentstack/refactor/CS-40254
aman19K Jul 24, 2023
4f239ef
Merge branch 'staging' into development
aman19K Jul 24, 2023
62e704e
Merge branch 'staging' into feat/merge-staging-dev
aman19K Jul 24, 2023
13e7721
Merge pull request #939 from contentstack/feat/merge-staging-dev
shafeeqd959 Jul 24, 2023
f459869
Merge pull request #940 from contentstack/development
aman19K Jul 24, 2023
54585df
Merge branch 'main' into staging_main_merge
aman19K Jul 25, 2023
98b4dd1
fix: remove secret scan file
aman19K Jul 25, 2023
ea5710c
Merge branch 'development' into fix/remove-secret-scan
aman19K Jul 25, 2023
6b26e8a
Merge pull request #942 from contentstack/fix/remove-secret-scan
aman19K Jul 25, 2023
8e84e1d
Merge branch 'staging' into fix/remove-secret-scan-merge
aman19K Jul 25, 2023
d17b388
Merge pull request #945 from contentstack/fix/remove-secret-scan-merge
aman19K Jul 25, 2023
14ef6db
Merge branch 'staging' into staging_main_merge
aman19K Jul 25, 2023
36e659e
Merge pull request #946 from contentstack/staging_main_merge
aman19K Jul 25, 2023
39d42b9
revert: backup dir changes
aman19K Jul 25, 2023
b846abc
Merge pull request #947 from contentstack/fix/backup-dir-revert
aman19K Jul 25, 2023
6f32844
fix: management sdk version ^1.10.0 -> ~1.10.0
aman19K Jul 25, 2023
2fd2d8a
Merge pull request #949 from contentstack/fix/management-sdk-version
shafeeqd959 Jul 25, 2023
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
11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

21,095 changes: 19,555 additions & 1,540 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-auth/1.3.11 darwin-x64 node-v18.12.1
@contentstack/cli-auth/1.3.12 darwin-arm64 node-v18.16.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-auth/messages/index.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_OTP": "Please select OTP channel",
"CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS": "Enter your email address",
"CLI_AUTH_LOGIN_ENTER_PASSWORD": "Enter your password",
"CLI_AUTH_LOGIN_SUCCESS": "Successfully logged in!!",
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-auth",
"description": "Contentstack CLI plugin for authentication activities",
"version": "1.3.11",
"version": "1.3.12",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -22,8 +22,8 @@
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
},
"dependencies": {
"@contentstack/cli-command": "^1.2.10",
"@contentstack/cli-utilities": "^1.5.0",
"@contentstack/cli-command": "^1.2.11",
"@contentstack/cli-utilities": "^1.5.1",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
76 changes: 14 additions & 62 deletions packages/contentstack-auth/src/commands/auth/tokens/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { Command } from '@contentstack/cli-command';
import {
logger,
cliux,
CLIError,
configHandler,
printFlagDeprecation,
flags,
managementSDKClient,
FlagInput,
HttpClient,
messageHandler,
} from '@contentstack/cli-utilities';
import { askTokenType } from '../../../utils/interactive';
import { tokenValidation } from '../../../utils';

export default class TokensAddCommand extends Command {
static description = 'Adds management/delivery tokens to your session to use it with other CLI commands';

Expand Down Expand Up @@ -130,39 +128,6 @@ export default class TokensAddCommand extends Command {
token = await cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ENTER_TOKEN', name: 'token' });
}

const managementAPIClient = await managementSDKClient({ host: this.cmaHost });

let doBranchesExistInPlan: boolean = false;

if (isManagement && apiKey && token) {
await managementAPIClient
.stack({ api_key: apiKey, management_token: token })
.branch()
.query()
.find()
.then(() => (doBranchesExistInPlan = true))
.catch((err) => {
if (err.errorCode && err.errorMessage && branch) {
throw new Error(err.errorMessage);
}
});
} else {
if (!apiKey) {
throw new Error('Api key is required');
}
if (!token) {
throw new Error('Token is required');
}
}

if (doBranchesExistInPlan && !branch) {
branch = await cliux.inquire({
type: 'input',
message: 'CLI_AUTH_ENTER_BRANCH',
name: 'branch',
});
}

if (isDelivery && !environment) {
environment = await cliux.inquire({
type: 'input',
Expand All @@ -171,31 +136,18 @@ export default class TokensAddCommand extends Command {
});
}

let tokenValidationResult;

if (type === 'delivery') {
branch = branch || 'main';
tokenValidationResult = await tokenValidation.validateDeliveryToken(
this.deliveryAPIClient,
apiKey,
token,
environment,
this.region.name,
this.cdaHost,
branch,
);
} else if (type === 'management') {
tokenValidationResult = await tokenValidation.validateManagementToken(
managementAPIClient,
apiKey,
token,
doBranchesExistInPlan ? branch : null,
);
}
if (!tokenValidationResult.valid) {
throw new CLIError(tokenValidationResult.message);
}
if (type === 'management') {
// FIXME - Once the SDK refresh token issue is resolved, need to revert this back to SDK call
const httpClient = new HttpClient({ headers: { api_key: apiKey, authorization: token } });

const response = (await httpClient.get(`https://${this.cmaHost}/v3/environments?limit=1`)).data;

if (response?.error_code === 105) {
throw new Error(messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN'));
} else if (response?.error_message) {
throw new Error(response.error_message);
}
}
if (isManagement) {
configHandler.set(`${configKeyTokens}.${alias}`, { token, apiKey, type });
} else {
Expand All @@ -210,7 +162,7 @@ export default class TokensAddCommand extends Command {
} catch (error) {
logger.error('token add error', error.message);
cliux.print('CLI_AUTH_TOKENS_ADD_FAILED', { color: 'yellow' });
cliux.print(error.message.message ? error.message.message : error.message, { color: 'red' });
cliux.error(error.message.message ? error.message.message : error.message);
}
}
}
103 changes: 1 addition & 102 deletions packages/contentstack-auth/src/utils/tokens-validation.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,5 @@
import { messageHandler, logger } from '@contentstack/cli-utilities';

/**
* Validate delivery token
* @param contentStackClient
* @param apiKey
* @param deliveryToken
* @param environment
* @param region
* @returns
*/
export const validateDeliveryToken = async (
contentStackClient: any,
apiKey: string,
deliveryToken: string,
environment: string,
region: string,
host: string,
branch: string,
): Promise<any> => {
let result: { valid: boolean; message: string };
try {
const regionMap = {
EU: 'eu',
NA: 'us',
AZURE_NA: 'azure-na',
AZURE_EU: 'azure-eu',
};

const stack = contentStackClient.Stack({
api_key: apiKey,
delivery_token: deliveryToken,
environment,
region: regionMap[region],
host,
branch,
});

const parsedHost = host.replace(/^https?:\/\//, '');
stack.setHost(parsedHost);
const deliveryTokenResult = await stack.getContentTypes({ limit: 1 });

logger.debug('delivery token validation result', deliveryTokenResult);
if (deliveryTokenResult?.content_types) {
result = { valid: true, message: deliveryTokenResult };
} else {
result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_DELIVERY_TOKEN') };
}
} catch (error) {
logger.debug('validate delivery token error', error);
if (error.error_code === 109) {
result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') };
} else if (error.error_code === 141) {
result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME') };
} else if (error?.error_code) {
throw new Error(error?.error_message);
} else {
result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_DELIVERY_TOKEN') };
}
}
return result;
};

/**
* Validate environment
* @param contentStackClient
Expand All @@ -75,7 +14,7 @@ export const validateEnvironment = async (
): Promise<any> => {
let result: { valid: boolean; message: string };
try {
const validationResult = await contentStackClient.stack({ api_key: apiKey }).environment(environment).fetch();
const validationResult = await contentStackClient.Stack({ api_key: apiKey }).environment(environment).fetch();
logger.debug('environment validation result', validationResult);
if (validationResult.name === environment) {
result = { valid: true, message: validationResult };
Expand All @@ -89,46 +28,6 @@ export const validateEnvironment = async (
return result;
};

/**
* Validate management token
* @param contentStackClient
* @param apiKey
* @param managementToken
* @returns { valid: boolean; message: any }
* Note: Fetching one content type using the management token to check whether it is valid or not
*/
export const validateManagementToken = async (
contentStackClient: any,
apiKey: string,
managementToken: string,
branch: string,
): Promise<any> => {
let result: { valid: boolean; message: string };
try {
const validationResuslt = await contentStackClient.axiosInstance.get('/content_types?limit=1&include_branch=true', {
headers: { api_key: apiKey, authorization: managementToken, branch },
});

logger.debug('Management validation result', validationResuslt);
if (validationResuslt.status === 200) {
result = { valid: true, message: validationResuslt };
} else {
result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN') };
}
} catch (error) {
logger.error('Failed to validate management token', error);
if (error.response && error.response.status === 401) {
result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN') };
}
if (error?.response?.data) {
throw new Error(error.response.data?.error_message);
} else {
result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') };
}
}
return result;
};

/**
* Validate API key
* @param contentStackClient
Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.4.12 darwin-x64 node-v18.12.1
@contentstack/cli-cm-bootstrap/1.4.13 darwin-arm64 node-v18.16.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -45,9 +45,10 @@ Bootstrap contentstack apps
```
USAGE
$ csdx cm:bootstrap [--app-name <value>] [--project-dir <value>] [-k <value> | --org <value> | -n <value>] [-y
<value>]
<value>] [-a <value>]

FLAGS
-a, --alias=<value> Alias of the management token
-k, --stack-api-key=<value> Provide stack API key to seed content
-n, --stack-name=<value> Name of a new stack that will be created.
-y, --yes=<value> [Optional] Skip stack confirmation
Expand Down
10 changes: 5 additions & 5 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.4.12",
"version": "1.4.13",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -17,9 +17,9 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "^1.4.12",
"@contentstack/cli-command": "^1.2.10",
"@contentstack/cli-utilities": "^1.5.0",
"@contentstack/cli-cm-seed": "^1.4.13",
"@contentstack/cli-command": "^1.2.11",
"@contentstack/cli-utilities": "^1.5.1",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.1.13"
Expand Down Expand Up @@ -73,4 +73,4 @@
}
},
"repository": "contentstack/cli"
}
}
23 changes: 15 additions & 8 deletions packages/contentstack-bootstrap/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface SeedParams {
org?: string;
stackName?: string;
yes?: string;
managementTokenAlias?: string | undefined;
managementToken?: string | undefined;
}

/**
Expand Down Expand Up @@ -62,7 +64,7 @@ export default class Bootstrap {
}

async run(): Promise<any> {
cliux.loader(messageHandler.parse('CLI_BOOTSTRAP_START_CLONE_APP'))
cliux.loader(messageHandler.parse('CLI_BOOTSTRAP_START_CLONE_APP'));

try {
await this.ghClient.getLatest(this.cloneDirectory);
Expand All @@ -79,35 +81,40 @@ export default class Bootstrap {

// seed plugin start
try {
const cmd = ['--repo', this.appConfig.stack]
const cmd = ['--repo', this.appConfig.stack];
if (this.options.seedParams.stackAPIKey) {
cmd.push('--stack-api-key', this.options.seedParams.stackAPIKey)
cmd.push('--stack-api-key', this.options.seedParams.stackAPIKey);
}
if (this.options.seedParams.org) {
cmd.push('--org', this.options.seedParams.org)
cmd.push('--org', this.options.seedParams.org);
}
if (this.options.seedParams.stackName) {
cmd.push('-n', this.options.seedParams.stackName)
cmd.push('-n', this.options.seedParams.stackName);
}
if (this.options.seedParams.yes) {
cmd.push('-y', this.options.seedParams.yes);
}
if (this.options.seedParams.managementTokenAlias) {
cmd.push('--alias', this.options.seedParams.managementTokenAlias);
}

const result = await ContentStackSeed.run(cmd);
if ( result && result.api_key) {
if (result && result.api_key) {
await setupEnvironments(
this.managementAPIClient,
result.api_key,
this.appConfig,
this.cloneDirectory,
this.region,
this.options.livePreviewEnabled as boolean,
this.options.seedParams.managementToken as string,
);
} else {
throw new Error(messageHandler.parse('CLI_BOOTSTRAP_NO_API_KEY_FOUND'));
}
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_SUCCESS'))
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_SUCCESS'));
} catch (error) {
cliux.error(messageHandler.parse('CLI_BOOTSTRAP_STACK_CREATION_FAILED', this.appConfig.stack))
cliux.error(messageHandler.parse('CLI_BOOTSTRAP_STACK_CREATION_FAILED', this.appConfig.stack));
}
}
}
Loading