@contentstack/cli-cm-bulk-publish 1.3.8 → 1.3.9

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
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
18
18
  $ csdx COMMAND
19
19
  running command...
20
20
  $ csdx (--version)
21
- @contentstack/cli-cm-bulk-publish/1.3.8 linux-x64 node-v16.20.0
21
+ @contentstack/cli-cm-bulk-publish/1.3.9 linux-x64 node-v18.16.1
22
22
  $ csdx --help [COMMAND]
23
23
  USAGE
24
24
  $ csdx COMMAND
@@ -70,6 +70,7 @@ FLAGS
70
70
  -a, --alias=<value> Alias(name) for the management token
71
71
  -c, --config=<value> Path to the config file
72
72
  -e, --environments=<value>... Environments where assets will be published
73
+ -k, --stack-api-key=<value> Stack api key to be used
73
74
  -l, --locales=<value>... Locales to where assets will be published
74
75
  -y, --yes Agree to process the command with the current configuration
75
76
  --api-version=<value> API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].
@@ -124,6 +125,12 @@ EXAMPLES
124
125
  Using --source-env
125
126
 
126
127
  $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]
128
+
129
+
130
+
131
+ Using --stack-api-key flag
132
+
133
+ $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY]
127
134
  ```
128
135
 
129
136
  _See code: [src/commands/cm/assets/publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js)_
@@ -134,22 +141,23 @@ Unpublish assets from given environment
134
141
 
135
142
  ```
136
143
  USAGE
137
- $ csdx cm:assets:unpublish [-a <value>] [-e <value>] [-c <value>] [-y] [--locale <value>] [--branch <value>]
138
- [--retry-failed <value>] [--bulk-unpublish <value>] [--api-version <value>] [--delivery-token <value>]
144
+ $ csdx cm:assets:unpublish [-a <value>] [-k <value>] [-e <value>] [-c <value>] [-y] [--locale <value>] [--branch
145
+ <value>] [--retry-failed <value>] [--bulk-unpublish <value>] [--api-version <value>] [--delivery-token <value>]
139
146
 
140
147
  FLAGS
141
- -a, --alias=<value> Alias(name) for the management token
142
- -c, --config=<value> Path to the config file
143
- -e, --environment=<value> Source Environment
144
- -y, --yes Agree to process the command with the current configuration
145
- --api-version=<value> API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].
146
- --branch=<value> [default: main] Specify the branch to fetch the content (by default the main branch is
147
- selected)
148
- --bulk-unpublish=<value> [default: true] By default this flag is set as true. It indicates that contentstack's
149
- bulkpublish API will be used to unpublish the assets
150
- --delivery-token=<value> Delivery Token for source environment
151
- --locale=<value> Locale filter
152
- --retry-failed=<value> Retry unpublishing failed assets from the logfile
148
+ -a, --alias=<value> Alias(name) for the management token
149
+ -c, --config=<value> Path to the config file
150
+ -e, --environment=<value> Source Environment
151
+ -k, --stack-api-key=<value> Stack api key to be used
152
+ -y, --yes Agree to process the command with the current configuration
153
+ --api-version=<value> API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].
154
+ --branch=<value> [default: main] Specify the branch to fetch the content (by default the main branch is
155
+ selected)
156
+ --bulk-unpublish=<value> [default: true] By default this flag is set as true. It indicates that contentstack's
157
+ bulkpublish API will be used to unpublish the assets
158
+ --delivery-token=<value> Delivery Token for source environment
159
+ --locale=<value> Locale filter
160
+ --retry-failed=<value> Retry unpublishing failed assets from the logfile
153
161
 
154
162
  DESCRIPTION
155
163
  Unpublish assets from given environment
@@ -184,6 +192,12 @@ EXAMPLES
184
192
  Using --branch flag
185
193
 
186
194
  $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]
195
+
196
+
197
+
198
+ Using --stack-api-key flag
199
+
200
+ $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]
187
201
  ```
188
202
 
189
203
  _See code: [src/commands/cm/assets/unpublish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/assets/unpublish.js)_
@@ -282,6 +296,7 @@ FLAGS
282
296
  -a, --alias=<value> Alias(name) for the management token
283
297
  -c, --config=<value> Path to the config file
284
298
  -e, --environments=<value>... Environments where assets will be published
299
+ -k, --stack-api-key=<value> Stack api key to be used
285
300
  -l, --locales=<value>... Locales to where assets will be published
286
301
  -y, --yes Agree to process the command with the current configuration
287
302
  --api-version=<value> API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].
@@ -336,6 +351,12 @@ EXAMPLES
336
351
  Using --source-env
337
352
 
338
353
  $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]
354
+
355
+
356
+
357
+ Using --stack-api-key flag
358
+
359
+ $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY]
339
360
  ```
340
361
 
341
362
  ## `csdx cm:bulk-publish:clear`
@@ -402,23 +423,24 @@ USAGE
402
423
  [-y] [--branch <value>] [--onlyAssets] [--onlyEntries]
403
424
 
404
425
  FLAGS
405
- -B, --branch=<value> [default: main] Specify the branch to fetch the content (by default the main branch is
406
- selected)
407
- -a, --alias=<value> Alias(name) for the management token
408
- -c, --config=<value> Path to the config file
409
- -y, --yes Agree to process the command with the current configuration
410
- --api-version=<value> API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].
411
- --bulk-publish=<value> [default: true] This flag is set to true by default. It indicates that contentstack's
412
- bulkpublish API will be used to publish the entries
413
- --content-type=<value>... The Contenttypes from which entries will be published
414
- --delivery-token=<value> Delivery token for source environment
415
- --environments=<value>... Destination Environments
416
- --locales=<value> Source locale
417
- --onlyAssets Unpublish only assets
418
- --onlyEntries Unpublish only entries
419
- --retry-failed=<value> (optional) Retry publishing failed entries from the logfile (this flag overrides all other
420
- flags)
421
- --source-env=<value> Source Env
426
+ -B, --branch=<value> [default: main] Specify the branch to fetch the content (by default the main branch is
427
+ selected)
428
+ -a, --alias=<value> Alias(name) for the management token
429
+ -c, --config=<value> Path to the config file
430
+ -k, --stack-api-key=<value> Stack api key to be used
431
+ -y, --yes Agree to process the command with the current configuration
432
+ --api-version=<value> API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].
433
+ --bulk-publish=<value> [default: true] This flag is set to true by default. It indicates that contentstack's
434
+ bulkpublish API will be used to publish the entries
435
+ --content-type=<value>... The Contenttypes from which entries will be published
436
+ --delivery-token=<value> Delivery token for source environment
437
+ --environments=<value>... Destination Environments
438
+ --locales=<value> Source locale
439
+ --onlyAssets Unpublish only assets
440
+ --onlyEntries Unpublish only entries
441
+ --retry-failed=<value> (optional) Retry publishing failed entries from the logfile (this flag overrides all
442
+ other flags)
443
+ --source-env=<value> Source Env
422
444
 
423
445
  DESCRIPTION
424
446
  Publish entries and assets from one environment to other environments
@@ -457,6 +479,12 @@ EXAMPLES
457
479
  Using --branch flag
458
480
 
459
481
  $ csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]
482
+
483
+
484
+
485
+ Using --stack-api-key flag
486
+
487
+ $ csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]
460
488
  ```
461
489
 
462
490
  _See code: [src/commands/cm/bulk-publish/cross-publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/cross-publish.js)_
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.8",
2
+ "version": "1.3.9",
3
3
  "commands": {
4
4
  "cm:assets:publish": {
5
5
  "id": "cm:assets:publish",
@@ -28,7 +28,10 @@
28
28
  "csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]",
29
29
  "",
30
30
  "Using --source-env",
31
- "csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]"
31
+ "csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]",
32
+ "",
33
+ "Using --stack-api-key flag",
34
+ "csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY]"
32
35
  ],
33
36
  "flags": {
34
37
  "alias": {
@@ -38,6 +41,14 @@
38
41
  "description": "Alias(name) for the management token",
39
42
  "multiple": false
40
43
  },
44
+ "stack-api-key": {
45
+ "name": "stack-api-key",
46
+ "type": "option",
47
+ "char": "k",
48
+ "description": "Stack api key to be used",
49
+ "required": false,
50
+ "multiple": false
51
+ },
41
52
  "retry-failed": {
42
53
  "name": "retry-failed",
43
54
  "type": "option",
@@ -173,7 +184,10 @@
173
184
  "csdx cm:assets:unpublish --retry-failed [LOG FILE NAME]",
174
185
  "",
175
186
  "Using --branch flag",
176
- "csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]"
187
+ "csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]",
188
+ "",
189
+ "Using --stack-api-key flag",
190
+ "csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]"
177
191
  ],
178
192
  "flags": {
179
193
  "alias": {
@@ -183,6 +197,14 @@
183
197
  "description": "Alias(name) for the management token",
184
198
  "multiple": false
185
199
  },
200
+ "stack-api-key": {
201
+ "name": "stack-api-key",
202
+ "type": "option",
203
+ "char": "k",
204
+ "description": "Stack api key to be used",
205
+ "required": false,
206
+ "multiple": false
207
+ },
186
208
  "environment": {
187
209
  "name": "environment",
188
210
  "type": "option",
@@ -268,7 +290,11 @@
268
290
  "csdx cm:bulk-publish:cross-publish -r [LOG FILE NAME]",
269
291
  "",
270
292
  "Using --branch flag",
271
- "csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]"
293
+ "csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]",
294
+ "",
295
+ "Using --stack-api-key flag",
296
+ "csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]",
297
+ ""
272
298
  ],
273
299
  "flags": {
274
300
  "alias": {
@@ -278,6 +304,14 @@
278
304
  "description": "Alias(name) for the management token",
279
305
  "multiple": false
280
306
  },
307
+ "stack-api-key": {
308
+ "name": "stack-api-key",
309
+ "type": "option",
310
+ "char": "k",
311
+ "description": "Stack api key to be used",
312
+ "required": false,
313
+ "multiple": false
314
+ },
281
315
  "retryFailed": {
282
316
  "name": "retryFailed",
283
317
  "type": "option",
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-bulk-publish",
3
3
  "description": "Contentstack CLI plugin for bulk publish actions",
4
- "version": "1.3.8",
4
+ "version": "1.3.9",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.2.9",
9
- "@contentstack/cli-utilities": "^1.4.5",
8
+ "@contentstack/cli-command": "^1.2.10",
9
+ "@contentstack/cli-utilities": "^1.5.0",
10
10
  "bluebird": "^3.7.2",
11
11
  "chalk": "^4.1.2",
12
+ "dotenv": "^16.1.4",
12
13
  "inquirer": "8.2.4",
13
14
  "lodash": "^4.17.15",
15
+ "mkdirp": "^1.0.4",
14
16
  "nock": "^13.0.2",
15
17
  "winston": "^3.7.2"
16
18
  },
@@ -92,7 +94,7 @@
92
94
  "scripts": {
93
95
  "postpack": "rm -f oclif.manifest.json",
94
96
  "prepack": "oclif manifest && oclif readme",
95
- "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
97
+ "test:unit": "nyc mocha --forbid-only \"test/unit/**/*.test.js\"",
96
98
  "posttest": "eslint .",
97
99
  "version": "oclif readme && git add README.md",
98
100
  "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
@@ -1,5 +1,5 @@
1
1
  const { Command } = require('@contentstack/cli-command');
2
- const { printFlagDeprecation, flags } = require('@contentstack/cli-utilities');
2
+ const { printFlagDeprecation, flags, isAuthenticated } = require('@contentstack/cli-utilities');
3
3
  const { start: startPublish } = require('../../../producer/publish-assets');
4
4
  const { start: startCrossPublish } = require('../../../producer/cross-publish');
5
5
  const store = require('../../../util/store.js');
@@ -30,33 +30,39 @@ class AssetsPublishCommand extends Command {
30
30
  if (this.validate(updatedFlags)) {
31
31
  let stack;
32
32
  if (!updatedFlags.retryFailed) {
33
- if (!updatedFlags.alias) {
34
- updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
33
+ config = {
34
+ host: this.cmaHost,
35
+ cda: this.cdaHost,
36
+ branch: assetsFlags.branch,
37
+ };
38
+ if (updatedFlags.alias) {
39
+ // Validate management token alias.
40
+ try {
41
+ this.getToken(updatedFlags.alias);
42
+ config.alias = updatedFlags.alias;
43
+ } catch (error) {
44
+ this.error(
45
+ `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`,
46
+ { exit: 2 },
47
+ );
48
+ }
49
+ } else if (updatedFlags['stack-api-key']) {
50
+ config.stackApiKey = updatedFlags['stack-api-key'];
51
+ } else {
52
+ this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 });
35
53
  }
36
54
  updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true;
37
55
  if (updatedFlags.folderUid === undefined) {
38
56
  // set default value for folderUid
39
57
  updatedFlags.folderUid = 'cs_root';
40
58
  }
41
- // Validate management token alias.
42
- try {
43
- this.getToken(updatedFlags.alias);
44
- } catch (error) {
45
- this.error(
46
- `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`,
47
- { exit: 2 },
48
- );
49
- }
50
- config = {
51
- alias: updatedFlags.alias,
52
- host: this.cmaHost,
53
- cda: this.cdaHost,
54
- branch: assetsFlags.branch,
55
- };
56
59
  stack = await getStack(config);
57
60
  }
58
61
  if (await this.confirmFlags(updatedFlags)) {
59
62
  try {
63
+ if (process.env.NODE_ENV === 'test') {
64
+ return;
65
+ }
60
66
  const publishFunction = async (func) => {
61
67
  if (!updatedFlags.retryFailed) {
62
68
  try {
@@ -153,6 +159,11 @@ AssetsPublishCommand.flags = {
153
159
  char: 'a',
154
160
  description: 'Alias(name) for the management token',
155
161
  }),
162
+ 'stack-api-key': flags.string({
163
+ char: 'k',
164
+ description: 'Stack api key to be used',
165
+ required: false,
166
+ }),
156
167
  'retry-failed': flags.string({
157
168
  description: 'Retry publishing failed assets from the logfile (optional, will override all other flags)',
158
169
  }),
@@ -238,6 +249,9 @@ AssetsPublishCommand.examples = [
238
249
  '',
239
250
  'Using --source-env',
240
251
  'csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]',
252
+ '',
253
+ 'Using --stack-api-key flag',
254
+ 'csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY]',
241
255
  ];
242
256
 
243
257
  AssetsPublishCommand.aliases = ['cm:bulk-publish:assets'];
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-console */
2
2
  /* eslint-disable node/no-extraneous-require */
3
3
  const { Command } = require('@contentstack/cli-command');
4
- const { cliux, flags } = require('@contentstack/cli-utilities');
4
+ const { cliux, flags, isAuthenticated } = require('@contentstack/cli-utilities');
5
5
  const { start } = require('../../../producer/unpublish');
6
6
  const store = require('../../../util/store.js');
7
7
  const configKey = 'Unpublish';
@@ -33,28 +33,31 @@ class UnpublishCommand extends Command {
33
33
  if (this.validate(updatedFlags)) {
34
34
  let stack;
35
35
  if (!updatedFlags.retryFailed) {
36
- if (!updatedFlags.alias) {
37
- updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
38
- }
39
- if (!updatedFlags.deliveryToken) {
40
- updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
41
- }
42
- updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true;
43
- // Validate management token alias.
44
- try {
45
- this.getToken(updatedFlags.alias);
46
- } catch (error) {
47
- this.error(
48
- `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add --alias ${updatedFlags.alias}'`,
49
- { exit: 2 },
50
- );
51
- }
52
36
  config = {
53
- alias: updatedFlags.alias,
54
37
  host: this.cmaHost,
55
38
  cda: this.cdaHost,
56
39
  branch: unpublishFlags.branch,
57
40
  };
41
+ if (updatedFlags.alias) {
42
+ // Validate management token alias.
43
+ try {
44
+ this.getToken(updatedFlags.alias);
45
+ config.alias = updatedFlags.alias;
46
+ } catch (error) {
47
+ this.error(
48
+ `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`,
49
+ { exit: 2 },
50
+ );
51
+ }
52
+ } else if (updatedFlags['stack-api-key']) {
53
+ config.stackApiKey = updatedFlags['stack-api-key'];
54
+ } else {
55
+ this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 });
56
+ }
57
+ if (!updatedFlags.deliveryToken) {
58
+ updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
59
+ }
60
+ updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true;
58
61
  stack = await getStack(config);
59
62
  }
60
63
  if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) {
@@ -63,6 +66,9 @@ class UnpublishCommand extends Command {
63
66
 
64
67
  if (await this.confirmFlags(updatedFlags)) {
65
68
  try {
69
+ if (process.env.NODE_ENV === 'test') {
70
+ return;
71
+ }
66
72
  if (!updatedFlags.retryFailed) {
67
73
  await start(updatedFlags, stack, config);
68
74
  } else {
@@ -130,6 +136,11 @@ UnpublishCommand.flags = {
130
136
  char: 'a',
131
137
  description: 'Alias(name) for the management token',
132
138
  }),
139
+ 'stack-api-key': flags.string({
140
+ char: 'k',
141
+ description: 'Stack api key to be used',
142
+ required: false,
143
+ }),
133
144
  environment: flags.string({
134
145
  char: 'e',
135
146
  description: 'Source Environment',
@@ -179,6 +190,9 @@ UnpublishCommand.examples = [
179
190
  '',
180
191
  'Using --branch flag',
181
192
  'csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]',
193
+ '',
194
+ 'Using --stack-api-key flag',
195
+ 'csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]',
182
196
  ];
183
197
 
184
198
  module.exports = UnpublishCommand;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable node/no-extraneous-require */
2
2
  const { Command } = require('@contentstack/cli-command');
3
- const { cliux, printFlagDeprecation, flags } = require('@contentstack/cli-utilities');
3
+ const { cliux, printFlagDeprecation, flags, isAuthenticated } = require('@contentstack/cli-utilities');
4
4
  const { start } = require('../../../producer/cross-publish');
5
5
  const store = require('../../../util/store.js');
6
6
  const configKey = 'cross_env_publish';
@@ -22,28 +22,31 @@ class CrossPublishCommand extends Command {
22
22
  if (this.validate(updatedFlags)) {
23
23
  let stack;
24
24
  if (!updatedFlags.retryFailed) {
25
- if (!updatedFlags.alias) {
26
- updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
27
- }
28
- if (!updatedFlags.deliveryToken) {
29
- updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
30
- }
31
- updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true;
32
- // Validate management token alias.
33
- try {
34
- this.getToken(updatedFlags.alias);
35
- } catch (error) {
36
- this.error(
37
- `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`,
38
- { exit: 2 },
39
- );
40
- }
41
25
  config = {
42
- alias: updatedFlags.alias,
43
26
  host: this.cmaHost,
44
27
  cda: this.cdaHost,
45
28
  branch: crossPublishFlags.branch,
46
29
  };
30
+ if (updatedFlags.alias) {
31
+ try {
32
+ this.getToken(updatedFlags.alias);
33
+ config.alias = updatedFlags.alias;
34
+ } catch (error) {
35
+ this.error(
36
+ `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`,
37
+ { exit: 2 },
38
+ );
39
+ }
40
+ } else if (updatedFlags['stack-api-key']) {
41
+ config.stackApiKey = updatedFlags['stack-api-key'];
42
+ } else {
43
+ this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 });
44
+ }
45
+ if (!updatedFlags.deliveryToken) {
46
+ updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
47
+ }
48
+ updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true;
49
+
47
50
  stack = await getStack(config);
48
51
  }
49
52
 
@@ -53,6 +56,9 @@ class CrossPublishCommand extends Command {
53
56
 
54
57
  if (await this.confirmFlags(updatedFlags)) {
55
58
  try {
59
+ if (process.env.NODE_ENV === 'test') {
60
+ return;
61
+ }
56
62
  if (!updatedFlags.retryFailed) {
57
63
  await start(updatedFlags, stack, config);
58
64
  } else {
@@ -162,6 +168,11 @@ But, if retryFailed flag is set, then only a logfile is required
162
168
 
163
169
  CrossPublishCommand.flags = {
164
170
  alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }),
171
+ 'stack-api-key': flags.string({
172
+ char: 'k',
173
+ description: 'Stack api key to be used',
174
+ required: false,
175
+ }),
165
176
  retryFailed: flags.string({
166
177
  char: 'r',
167
178
  description: '(optional) Retry publishing failed entries from the logfile (this flag overrides all other flags)',
@@ -263,6 +274,10 @@ CrossPublishCommand.examples = [
263
274
  '',
264
275
  'Using --branch flag',
265
276
  'csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]',
277
+ '',
278
+ 'Using --stack-api-key flag',
279
+ 'csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]',
280
+ '',
266
281
  ];
267
282
 
268
283
  CrossPublishCommand.usage = `cm:bulk-publish:cross-publish [-a <value>] [--retry-failed <value>] [--bulk-publish <value>] [--content-type <value>] [--locales <value>] [--source-env <value>] [--environments <value>] [--delivery-token <value>] [-c <value>] [-y] [--branch <value>] [--onlyAssets] [--onlyEntries]`;
@@ -60,6 +60,9 @@ class PublishEntriesCommand extends Command {
60
60
  }
61
61
  if (await this.confirmFlags(updatedFlags)) {
62
62
  try {
63
+ if (process.env.NODE_ENV === 'test') {
64
+ return;
65
+ }
63
66
  const publishFunction = async (func) => {
64
67
  // eslint-disable-next-line no-negated-condition
65
68
  if (!updatedFlags.retryFailed) {
@@ -65,6 +65,9 @@ class UnpublishCommand extends Command {
65
65
 
66
66
  if (await this.confirmFlags(updatedFlags)) {
67
67
  try {
68
+ if (process.env.NODE_ENV === 'test') {
69
+ return;
70
+ }
68
71
  if (!updatedFlags.retryFailed) {
69
72
  await start(updatedFlags, stack, config);
70
73
  } else {
@@ -143,7 +143,12 @@ async function getSyncEntries(
143
143
  ) {
144
144
  return new Promise(async (resolve, reject) => {
145
145
  try {
146
- const tokenDetails = command.getToken(config.alias);
146
+ let tokenDetails;
147
+ if (config.stackApiKey) {
148
+ tokenDetails = { apiKey: config.stackApiKey };
149
+ } else {
150
+ tokenDetails = command.getToken(config.alias);
151
+ }
147
152
  const queryParamsObj = {};
148
153
  const pairs = queryParams.split('&').filter((e) => e !== null && e !== '' && e !== undefined);
149
154
  for (let i in pairs) {
@@ -158,7 +158,12 @@ async function getSyncEntries(
158
158
  ) {
159
159
  return new Promise(async (resolve, reject) => {
160
160
  try {
161
- const tokenDetails = command.getToken(config.alias);
161
+ let tokenDetails;
162
+ if (config.stackApiKey) {
163
+ tokenDetails = { apiKey: config.stackApiKey };
164
+ } else {
165
+ tokenDetails = command.getToken(config.alias);
166
+ }
162
167
  const queryParamsObj = {};
163
168
  const pairs = queryParams.split('&');
164
169
  for (let i in pairs) {
@@ -1,11 +1,26 @@
1
- const { managementSDKClient } = require('@contentstack/cli-utilities');
1
+ const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
2
2
  const { Command } = require('@contentstack/cli-command');
3
3
  const command = new Command();
4
4
 
5
5
  async function getStack(data) {
6
- const tokenDetails = command.getToken(data.alias);
7
- const managementClient = await managementSDKClient({ host: data.host, branchName: data.branch });
8
- const stack = managementClient.stack({ api_key: tokenDetails.apiKey, management_token: tokenDetails.token });
6
+ const options = {
7
+ host: data.host,
8
+ branchName: data.branch,
9
+ };
10
+ const stackOptions = {};
11
+ if (data.alias) {
12
+ const tokenDetails = command.getToken(data.alias);
13
+ options.management_token = tokenDetails.token;
14
+ stackOptions.management_token = tokenDetails.token;
15
+ stackOptions.api_key = tokenDetails.apiKey;
16
+ } else if (data.stackApiKey) {
17
+ if (!isAuthenticated()) {
18
+ throw new Error('Please login to proceed further. Or use `--alias` instead of `--stack-api-key` to proceed without logging in.')
19
+ }
20
+ stackOptions.api_key = data.stackApiKey;
21
+ }
22
+ const managementClient = await managementSDKClient(options);
23
+ const stack = managementClient.stack(stackOptions);
9
24
  stack.alias = data.alias;
10
25
  stack.host = data.host;
11
26
  return stack;