@contentstack/cli-variants 1.1.1 → 1.1.3

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.
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -133,7 +143,7 @@ class VariantEntries extends variant_api_adapter_1.default {
133
143
  const ctConfig = this.config.modules['content-types'];
134
144
  const contentType = JSON.parse((0, fs_1.readFileSync)((0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), (0, cli_utilities_1.sanitizePath)(ctConfig.dirName), `${(0, cli_utilities_1.sanitizePath)(content_type)}.json`), 'utf8'));
135
145
  const variantEntryBasePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.entriesDirPath), (0, cli_utilities_1.sanitizePath)(content_type), (0, cli_utilities_1.sanitizePath)(locale), (0, cli_utilities_1.sanitizePath)(variantEntry.dirName), (0, cli_utilities_1.sanitizePath)(entry_uid));
136
- const fs = new cli_utilities_1.FsUtility({ basePath: variantEntryBasePath });
146
+ const fs = new cli_utilities_1.FsUtility({ basePath: variantEntryBasePath, createDirIfNotExist: false });
137
147
  for (const _ in fs.indexFileContent) {
138
148
  try {
139
149
  const variantEntries = (yield fs.readChunkFiles.next());
@@ -176,12 +186,12 @@ class VariantEntries extends variant_api_adapter_1.default {
176
186
  const start = Date.now();
177
187
  for (let [, variantEntry] of (0, entries_1.default)(batch)) {
178
188
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }) => {
179
- log(this.config, `Created entry variant: '${variantUid}' of entry uid ${entryUid}`, 'info');
189
+ log(this.config, `Created entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`, 'info');
180
190
  };
181
191
  const onReject = ({ error, apiData, log }) => {
182
192
  const { entryUid, variantUid } = apiData;
183
193
  this.failedVariantEntries.set(variantUid, apiData);
184
- log(this.config, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
194
+ log(this.config, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`, 'error');
185
195
  log(this.config, error, 'error');
186
196
  };
187
197
  // NOTE Find new variant Id by old Id
@@ -352,10 +362,10 @@ class VariantEntries extends variant_api_adapter_1.default {
352
362
  return;
353
363
  }
354
364
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }) => {
355
- log(this.config, `Entry variant: '${variantUid}' of entry uid ${entryUid} published successfully!`, 'info');
365
+ log(this.config, `Entry variant: '${variantUid}' of entry '${entryUid}' published on locales '${locales.join(',')}'`, 'info');
356
366
  };
357
367
  const onReject = ({ error, apiData: { entryUid, variantUid }, log }) => {
358
- log(this.config, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
368
+ log(this.config, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid} on locales '${locales.join(',')}'`, 'error');
359
369
  log(this.config, (0, utils_1.formatError)(error), 'error');
360
370
  };
361
371
  const { environments, locales } = this.serializePublishEntries(variantEntry);
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -162,7 +162,7 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
162
162
  try {
163
163
  this.apiClient.headers({ api_version: undefined });
164
164
  const res = yield this.apiClient.put(endpoint, { entry: input });
165
- const data = this.handleVariantAPIRes(res);
165
+ const data = yield this.handleVariantAPIRes(res);
166
166
  if (res.status >= 200 && res.status < 300) {
167
167
  onSuccess(data);
168
168
  }
@@ -188,16 +188,16 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
188
188
  const { reject, resolve, log, variantUid } = apiParams;
189
189
  const { entry_uid, content_type_uid } = options;
190
190
  let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
191
- const onSuccess = (response) => resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log });
191
+ const onSuccess = (response) => resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log });
192
192
  const onReject = (error) => reject({
193
193
  error,
194
- apiData: { entryUid: entry_uid, variantUid },
194
+ apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales },
195
195
  log,
196
196
  });
197
197
  try {
198
198
  this.apiClient.headers({ api_version: 3.2 });
199
199
  const res = yield this.apiClient.post(endpoint, input);
200
- const data = this.handleVariantAPIRes(res);
200
+ const data = yield this.handleVariantAPIRes(res);
201
201
  if (res.status >= 200 && res.status < 300) {
202
202
  onSuccess(data);
203
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-variants",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Variants plugin",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,21 +18,21 @@
18
18
  "license": "MIT",
19
19
  "devDependencies": {
20
20
  "@contentstack/cli-dev-dependencies": "^1.2.4",
21
- "@oclif/test": "^2.5.6",
22
- "@types/chai": "^4.3.14",
23
- "@types/node": "^20.12.7",
24
- "chai": "^4.4.1",
25
- "mocha": "^10.4.0",
21
+ "@oclif/test": "^4.1.0",
22
+ "@types/chai": "^4.3.20",
23
+ "@types/node": "^20.17.6",
24
+ "chai": "^4.5.0",
25
+ "mocha": "^10.8.2",
26
26
  "nyc": "^15.1.0",
27
- "sinon": "^17.0.1",
27
+ "sinon": "^19.0.2",
28
28
  "ts-node": "^10.9.2",
29
- "tslib": "^2.6.2",
30
- "typescript": "^5.4.2"
29
+ "tslib": "^2.8.1",
30
+ "typescript": "^5.6.3"
31
31
  },
32
32
  "dependencies": {
33
33
  "@contentstack/cli-utilities": "^1.8.0",
34
34
  "lodash": "^4.17.21",
35
35
  "mkdirp": "^1.0.4",
36
- "winston": "^3.7.2"
36
+ "winston": "^3.17.0"
37
37
  }
38
38
  }
@@ -54,16 +54,9 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
54
54
  },
55
55
  };
56
56
  super(Object.assign(omit(config, ['helpers']), conf));
57
- this.entriesMapperPath = resolve(
58
- sanitizePath(config.backupDir),
59
- 'mapper',
60
- 'entries',
61
- );
57
+ this.entriesMapperPath = resolve(sanitizePath(config.backupDir), 'mapper', 'entries');
62
58
  this.personalizeConfig = this.config.modules.personalize;
63
- this.entriesDirPath = resolve(
64
- sanitizePath(config.backupDir),
65
- sanitizePath(config.modules.entries.dirName),
66
- );
59
+ this.entriesDirPath = resolve(sanitizePath(config.backupDir), sanitizePath(config.modules.entries.dirName));
67
60
  this.failedVariantPath = resolve(sanitizePath(this.entriesMapperPath), 'failed-entry-variants.json');
68
61
  this.failedVariantEntries = new Map();
69
62
  }
@@ -169,7 +162,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
169
162
  sanitizePath(variantEntry.dirName),
170
163
  sanitizePath(entry_uid),
171
164
  );
172
- const fs = new FsUtility({ basePath: variantEntryBasePath });
165
+ const fs = new FsUtility({ basePath: variantEntryBasePath, createDirIfNotExist: false });
173
166
 
174
167
  for (const _ in fs.indexFileContent) {
175
168
  try {
@@ -217,13 +210,21 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
217
210
 
218
211
  for (let [, variantEntry] of entries(batch)) {
219
212
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }: any) => {
220
- log(this.config, `Created entry variant: '${variantUid}' of entry uid ${entryUid}`, 'info');
213
+ log(
214
+ this.config,
215
+ `Created entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`,
216
+ 'info',
217
+ );
221
218
  };
222
219
 
223
220
  const onReject = ({ error, apiData, log }: any) => {
224
221
  const { entryUid, variantUid } = apiData;
225
222
  this.failedVariantEntries.set(variantUid, apiData);
226
- log(this.config, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
223
+ log(
224
+ this.config,
225
+ `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`,
226
+ 'error',
227
+ );
227
228
  log(this.config, error, 'error');
228
229
  };
229
230
  // NOTE Find new variant Id by old Id
@@ -440,10 +441,18 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
440
441
  }
441
442
 
442
443
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }: any) => {
443
- log(this.config, `Entry variant: '${variantUid}' of entry uid ${entryUid} published successfully!`, 'info');
444
+ log(
445
+ this.config,
446
+ `Entry variant: '${variantUid}' of entry '${entryUid}' published on locales '${locales.join(',')}'`,
447
+ 'info',
448
+ );
444
449
  };
445
450
  const onReject = ({ error, apiData: { entryUid, variantUid }, log }: any) => {
446
- log(this.config, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
451
+ log(
452
+ this.config,
453
+ `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid} on locales '${locales.join(',')}'`,
454
+ 'error',
455
+ );
447
456
  log(this.config, formatError(error), 'error');
448
457
  };
449
458
 
@@ -54,7 +54,7 @@ export type PublishVariantEntryDto = {
54
54
  uid: string;
55
55
  version?: number;
56
56
  }[];
57
- }
57
+ };
58
58
  locale: string;
59
59
  version?: number;
60
- } & AnyProperty;
60
+ } & AnyProperty;
@@ -197,7 +197,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
197
197
  try {
198
198
  this.apiClient.headers({ api_version: undefined });
199
199
  const res = await this.apiClient.put<VariantEntryStruct>(endpoint, { entry: input });
200
- const data = this.handleVariantAPIRes(res);
200
+ const data = await this.handleVariantAPIRes(res);
201
201
 
202
202
  if (res.status >= 200 && res.status < 300) {
203
203
  onSuccess(data);
@@ -226,18 +226,19 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
226
226
  const { entry_uid, content_type_uid } = options;
227
227
  let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
228
228
 
229
- const onSuccess = (response: any) => resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log });
229
+ const onSuccess = (response: any) =>
230
+ resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log });
230
231
  const onReject = (error: any) =>
231
232
  reject({
232
233
  error,
233
- apiData: { entryUid: entry_uid, variantUid },
234
+ apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales },
234
235
  log,
235
236
  });
236
237
 
237
238
  try {
238
239
  this.apiClient.headers({ api_version: 3.2 });
239
240
  const res = await this.apiClient.post<any>(endpoint, input);
240
- const data = this.handleVariantAPIRes(res);
241
+ const data = await this.handleVariantAPIRes(res);
241
242
 
242
243
  if (res.status >= 200 && res.status < 300) {
243
244
  onSuccess(data);