@contentstack/cli-cm-seed 1.4.12 → 1.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,6 +22,7 @@ USAGE
22
22
  $ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
23
23
 
24
24
  FLAGS
25
+ -a, --alias=<value> Alias of the management token
25
26
  -k, --stack-api-key=<value> Provide stack api key to seed content to
26
27
  -n, --stack-name=<value> Name of a new stack that needs to be created.
27
28
  -o, --org=<value> Provide Organization UID to create a new stack
@@ -56,6 +57,7 @@ USAGE
56
57
  $ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
57
58
 
58
59
  FLAGS
60
+ -a, --alias=<value> Alias of the management token
59
61
  -k, --stack-api-key=<value> Provide stack api key to seed content to
60
62
  -n, --stack-name=<value> Name of a new stack that needs to be created.
61
63
  -o, --org=<value> Provide Organization UID to create a new stack
@@ -7,8 +7,9 @@ class SeedCommand extends cli_command_1.Command {
7
7
  async run() {
8
8
  try {
9
9
  const { flags: seedFlags } = await this.parse(SeedCommand);
10
- if (!(0, cli_utilities_1.isAuthenticated)()) {
11
- this.error('You need to login, first. See: auth:login --help', {
10
+ const managementTokenAlias = seedFlags.alias;
11
+ if (!(0, cli_utilities_1.isAuthenticated)() && !managementTokenAlias) {
12
+ this.error('You need to login or provide an alias for the management token. See: auth:login --help', {
12
13
  exit: 2,
13
14
  suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
14
15
  });
@@ -24,7 +25,13 @@ class SeedCommand extends cli_command_1.Command {
24
25
  fetchLimit: seedFlags['fetch-limit'],
25
26
  skipStackConfirmation: seedFlags['yes'],
26
27
  isAuthenticated: (0, cli_utilities_1.isAuthenticated)(),
28
+ alias: managementTokenAlias,
27
29
  };
30
+ const listOfTokens = cli_utilities_1.configHandler.get('tokens');
31
+ if (managementTokenAlias && listOfTokens[managementTokenAlias]) {
32
+ options.managementToken = listOfTokens[managementTokenAlias].token;
33
+ options.stackUid = listOfTokens[managementTokenAlias].apiKey;
34
+ }
28
35
  const seeder = new seed_1.default(options);
29
36
  const result = await seeder.run();
30
37
  return result;
@@ -101,5 +108,9 @@ SeedCommand.flags = {
101
108
  exclusive: ['org', 'name'],
102
109
  parse: (0, cli_utilities_1.printFlagDeprecation)(['s', 'stack'], ['-k', 'stack-api-key']),
103
110
  }),
111
+ alias: cli_utilities_1.flags.string({
112
+ char: 'a',
113
+ description: 'Alias of the management token',
114
+ }),
104
115
  };
105
116
  SeedCommand.aliases = ['cm:seed'];
@@ -26,7 +26,7 @@ export default class ContentstackClient {
26
26
  private mapOrganization;
27
27
  getStack(stackUID: string): Promise<Stack>;
28
28
  getStacks(org_uid: string, skip?: number, stacks?: Stack[]): Promise<Stack[]>;
29
- getContentTypeCount(api_key: string): Promise<number>;
29
+ getContentTypeCount(api_key: string, managementToken?: string): Promise<number>;
30
30
  createStack(options: CreateStackOptions): Promise<Stack>;
31
31
  private buildError;
32
32
  }
@@ -98,10 +98,14 @@ class ContentstackClient {
98
98
  throw this.buildError(error);
99
99
  }
100
100
  }
101
- async getContentTypeCount(api_key) {
101
+ async getContentTypeCount(api_key, managementToken) {
102
102
  try {
103
103
  const client = await this.instance;
104
- const response = await client.stack({ api_key: api_key }).contentType().query({ include_count: true }).find();
104
+ const response = await client
105
+ .stack({ api_key: api_key, management_token: managementToken })
106
+ .contentType()
107
+ .query({ include_count: true })
108
+ .find();
105
109
  return response.count;
106
110
  }
107
111
  catch (error) {
@@ -5,5 +5,6 @@ export interface ImporterOptions {
5
5
  cmaHost: string;
6
6
  cdaHost: string;
7
7
  isAuthenticated: boolean;
8
+ alias?: string;
8
9
  }
9
10
  export declare function run(options: ImporterOptions): Promise<void>;
@@ -7,7 +7,10 @@ const cli_cm_import_1 = require("@contentstack/cli-cm-import");
7
7
  const STACK_FOLDER = 'stack';
8
8
  async function run(options) {
9
9
  const importPath = path.resolve(options.tmpPath, STACK_FOLDER);
10
+ const args = options.alias
11
+ ? ['-k', options.api_key, '-d', importPath, '--alias', options.alias]
12
+ : ['-k', options.api_key, '-d', importPath];
10
13
  process.chdir(options.tmpPath);
11
- await cli_cm_import_1.default.run(['-k', options.api_key, '-d', importPath]);
14
+ await cli_cm_import_1.default.run(args);
12
15
  }
13
16
  exports.run = run;
@@ -12,6 +12,8 @@ export interface ContentModelSeederOptions {
12
12
  fetchLimit: string | undefined;
13
13
  skipStackConfirmation: string | undefined;
14
14
  isAuthenticated: boolean | false;
15
+ managementToken?: string | undefined;
16
+ alias?: string | undefined;
15
17
  }
16
18
  export default class ContentModelSeeder {
17
19
  options: ContentModelSeederOptions;
@@ -21,6 +23,7 @@ export default class ContentModelSeeder {
21
23
  private readonly _options;
22
24
  private ghUsername;
23
25
  private ghRepo;
26
+ managementToken?: string | undefined;
24
27
  get ghPath(): string;
25
28
  constructor(options: ContentModelSeederOptions);
26
29
  run(): Promise<{
package/lib/seed/index.js CHANGED
@@ -25,6 +25,7 @@ class ContentModelSeeder {
25
25
  this.ghUsername = gh.username || DEFAULT_OWNER;
26
26
  this.ghRepo = gh.repo;
27
27
  const limit = Number(this.options.fetchLimit);
28
+ this.managementToken = options.managementToken;
28
29
  this.csClient = new client_1.default(options.cmaHost, limit);
29
30
  this.ghClient = new client_2.default(this.ghUsername, DEFAULT_STACK_PATTERN);
30
31
  }
@@ -43,7 +44,7 @@ class ContentModelSeeder {
43
44
  }
44
45
  }
45
46
  const tmpPath = await this.downloadRelease();
46
- cli_utilities_1.cliux.print(`Importing into '${stackResponse.name}'.`);
47
+ cli_utilities_1.cliux.print(`Importing into ${this.managementToken ? 'your stack' : `'${stackResponse.name}'`}.`);
47
48
  await importer.run({
48
49
  api_key: api_key,
49
50
  cdaHost: this.options.cdaHost,
@@ -51,6 +52,7 @@ class ContentModelSeeder {
51
52
  master_locale: exports.ENGLISH_LOCALE,
52
53
  tmpPath: tmpPath,
53
54
  isAuthenticated: this.options.isAuthenticated,
55
+ alias: this.options.alias,
54
56
  });
55
57
  return { api_key };
56
58
  }
@@ -69,15 +71,26 @@ class ContentModelSeeder {
69
71
  throw error;
70
72
  }
71
73
  if (repoExists === false) {
72
- cli_utilities_1.cliux.error(repoResponseData.status === 403 ? repoResponseData.statusMessage : `Could not find GitHub repository '${this.ghPath}'.`);
74
+ cli_utilities_1.cliux.error(repoResponseData.status === 403
75
+ ? repoResponseData.statusMessage
76
+ : `Could not find GitHub repository '${this.ghPath}'.`);
73
77
  if (this.parent)
74
78
  this.parent.exit(1);
75
79
  }
76
80
  else {
77
81
  let organizationResponse;
78
82
  let stackResponse;
79
- if (this.options.stackUid) {
80
- const stack = await this.csClient.getStack(this.options.stackUid);
83
+ let stack;
84
+ if (this.options.stackUid && this.options.managementToken) {
85
+ stackResponse = {
86
+ isNew: false,
87
+ name: 'your stack',
88
+ uid: this.options.stackUid,
89
+ api_key: this.options.stackUid,
90
+ };
91
+ }
92
+ else if (this.options.stackUid) {
93
+ stack = await this.csClient.getStack(this.options.stackUid);
81
94
  stackResponse = {
82
95
  isNew: false,
83
96
  name: stack.name,
@@ -114,7 +127,8 @@ class ContentModelSeeder {
114
127
  return newStack.api_key;
115
128
  }
116
129
  async shouldProceed(api_key) {
117
- const count = await this.csClient.getContentTypeCount(api_key);
130
+ let count;
131
+ count = await this.csClient.getContentTypeCount(api_key, this.managementToken);
118
132
  if (count > 0 && this._options.skipStackConfirmation !== 'yes') {
119
133
  const proceed = await (0, interactive_1.inquireProceed)();
120
134
  if (!proceed) {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.12",
2
+ "version": "1.4.13",
3
3
  "commands": {
4
4
  "cm:stacks:seed": {
5
5
  "id": "cm:stacks:seed",
@@ -89,6 +89,13 @@
89
89
  "org",
90
90
  "name"
91
91
  ]
92
+ },
93
+ "alias": {
94
+ "name": "alias",
95
+ "type": "option",
96
+ "char": "a",
97
+ "description": "Alias of the management token",
98
+ "multiple": false
92
99
  }
93
100
  },
94
101
  "args": {}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-seed",
3
3
  "description": "create a Stack from existing content types, entries, assets, etc.",
4
- "version": "1.4.12",
4
+ "version": "1.4.13",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-cm-import": "^1.6.0",
9
- "@contentstack/cli-command": "^1.2.10",
10
- "@contentstack/cli-utilities": "^1.5.0",
8
+ "@contentstack/cli-cm-import": "^1.7.0",
9
+ "@contentstack/cli-command": "^1.2.11",
10
+ "@contentstack/cli-utilities": "^1.5.1",
11
11
  "axios": "1.3.4",
12
12
  "inquirer": "8.2.4",
13
13
  "mkdirp": "^1.0.4",
@@ -73,4 +73,4 @@
73
73
  "version": "oclif readme && git add README.md",
74
74
  "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
75
75
  }
76
- }
76
+ }