@contentstack/cli-cm-import 1.7.1 → 1.8.0

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
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import/1.7.1 linux-x64 node-v18.17.0
50
+ @contentstack/cli-cm-import/1.8.0 linux-x64 node-v18.17.1
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -377,6 +377,8 @@ const config = {
377
377
  'content-types',
378
378
  'webhooks',
379
379
  'custom-roles',
380
+ 'workflows',
381
+ 'entries',
380
382
  ],
381
383
  rateLimit: 5,
382
384
  preserveStackVersion: false,
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
5
  const utils_1 = require("../utils");
5
6
  const modules_1 = tslib_1.__importDefault(require("./modules"));
6
7
  const modules_js_1 = tslib_1.__importDefault(require("./modules-js"));
@@ -17,6 +18,20 @@ class ModuleImporter {
17
18
  if (this.importConfig.branchName) {
18
19
  await (0, utils_1.validateBranch)(this.stackAPIClient, this.importConfig, this.importConfig.branchName);
19
20
  }
21
+ // Temporarily adding this api call to verify management token has read and write permissions
22
+ // TODO: CS-40354 - CLI | import rewrite | Migrate HTTP call to SDK call once fix is ready from SDK side
23
+ const httpClient = new cli_utilities_1.HttpClient({
24
+ headers: { api_key: this.importConfig.apiKey, authorization: this.importConfig.management_token },
25
+ });
26
+ const { data } = await httpClient.post('https://api.contentstack.io/v3/locales', {
27
+ locale: {
28
+ name: 'English',
29
+ code: 'en-us',
30
+ },
31
+ });
32
+ if (data.error_code === 161) {
33
+ throw new Error(data.error_message);
34
+ }
20
35
  if (!this.importConfig.master_locale) {
21
36
  let masterLocalResponse = await (0, utils_1.masterLocalDetails)(this.stackAPIClient);
22
37
  this.importConfig['master_locale'] = { code: masterLocalResponse.code };
@@ -3,7 +3,7 @@ import { ImportConfig, ModuleClassParams } from '../../types';
3
3
  export type AdditionalKeys = {
4
4
  backupDir: string;
5
5
  };
6
- export type ApiModuleType = 'create-assets' | 'replace-assets' | 'publish-assets' | 'create-assets-folder' | 'create-extensions' | 'create-locale' | 'update-locale' | 'create-gfs' | 'create-cts' | 'update-cts' | 'update-gfs' | 'create-environments' | 'create-labels' | 'update-labels' | 'create-webhooks' | 'create-workflows' | 'create-custom-role';
6
+ export type ApiModuleType = 'create-assets' | 'replace-assets' | 'publish-assets' | 'create-assets-folder' | 'create-extensions' | 'create-locale' | 'update-locale' | 'create-gfs' | 'create-cts' | 'update-cts' | 'update-gfs' | 'create-environments' | 'create-labels' | 'update-labels' | 'create-webhooks' | 'create-workflows' | 'create-custom-role' | 'create-entries' | 'update-entries' | 'publish-entries' | 'delete-entries';
7
7
  export type ApiOptions = {
8
8
  uid?: string;
9
9
  url?: string;
@@ -105,10 +105,11 @@ class BaseClass {
105
105
  * @return {Promise} Promise<void>
106
106
  */
107
107
  makeAPICall(apiOptions, isLastRequest = false) {
108
+ var _a, _b;
108
109
  if (apiOptions.serializeData instanceof Function) {
109
110
  apiOptions = apiOptions.serializeData(apiOptions);
110
111
  }
111
- const { uid, entity, reject, resolve, apiData, additionalInfo, includeParamOnCompletion } = apiOptions;
112
+ const { uid, entity, reject, resolve, apiData, additionalInfo = {}, includeParamOnCompletion } = apiOptions;
112
113
  const onSuccess = (response) => resolve({
113
114
  response,
114
115
  isLastRequest,
@@ -168,6 +169,9 @@ class BaseClass {
168
169
  case 'create-cts':
169
170
  return this.stack.contentType().create(apiData).then(onSuccess).catch(onReject);
170
171
  case 'update-cts':
172
+ if (additionalInfo.skip) {
173
+ return Promise.resolve(onSuccess(apiData));
174
+ }
171
175
  return apiData.update().then(onSuccess).catch(onReject);
172
176
  case 'update-gfs':
173
177
  return apiData.update().then(onSuccess).catch(onReject);
@@ -210,6 +214,32 @@ class BaseClass {
210
214
  .create({ role: apiData })
211
215
  .then(onSuccess)
212
216
  .catch(onReject);
217
+ case 'create-entries':
218
+ return this.stack
219
+ .contentType(additionalInfo.cTUid)
220
+ .entry()
221
+ .create({ entry: apiData }, { locale: additionalInfo.locale })
222
+ .then(onSuccess)
223
+ .catch(onReject);
224
+ case 'update-entries':
225
+ return apiData.update({ locale: additionalInfo.locale }).then(onSuccess).catch(onReject);
226
+ case 'publish-entries':
227
+ if (additionalInfo.skip) {
228
+ return Promise.resolve(onSuccess(apiData));
229
+ }
230
+ return this.stack
231
+ .contentType(additionalInfo.cTUid)
232
+ .entry(additionalInfo.entryUid)
233
+ .publish({ publishDetails: apiData, locale: additionalInfo.locale })
234
+ .then(onSuccess)
235
+ .catch(onReject);
236
+ case 'delete-entries':
237
+ return this.stack
238
+ .contentType(apiData.cTUid)
239
+ .entry(apiData.entryUid)
240
+ .delete({ locale: (_b = (_a = this.importConfig) === null || _a === void 0 ? void 0 : _a.master_locale) === null || _b === void 0 ? void 0 : _b.code })
241
+ .then(onSuccess)
242
+ .catch(onReject);
213
243
  default:
214
244
  return Promise.resolve();
215
245
  }
@@ -150,7 +150,7 @@ class ContentTypesImport extends base_class_1.default {
150
150
  (0, utils_1.log)(this.importConfig, `Updated the global field ${uid} with content type references`, 'info');
151
151
  };
152
152
  const onReject = ({ error, apiData: { uid } = undefined }) => {
153
- (0, utils_1.log)(this.importConfig, `failed to update the global field ${uid} ${(0, utils_1.formatError)(error)}`, 'error');
153
+ (0, utils_1.log)(this.importConfig, `failed to update the global field '${uid}' ${(0, utils_1.formatError)(error)}`, 'error');
154
154
  };
155
155
  return await this.makeConcurrentCall({
156
156
  processName: 'Update pending global fields',
@@ -0,0 +1,93 @@
1
+ /*!
2
+ * Contentstack Import
3
+ * Copyright (c) 2019 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ModuleClassParams } from '../../types';
7
+ import BaseClass, { ApiOptions } from './base-class';
8
+ export default class EntriesImport extends BaseClass {
9
+ private assetUidMapperPath;
10
+ private assetUidMapper;
11
+ private assetUrlMapper;
12
+ private assetUrlMapperPath;
13
+ private entriesMapperPath;
14
+ private envPath;
15
+ private entriesUIDMapperPath;
16
+ private uniqueUidMapperPath;
17
+ private modifiedCTsPath;
18
+ private marketplaceAppMapperPath;
19
+ private entriesConfig;
20
+ private cTsPath;
21
+ private localesPath;
22
+ private importConcurrency;
23
+ private entriesPath;
24
+ private cTs;
25
+ private modifiedCTs;
26
+ private refCTs;
27
+ private jsonRteCTs;
28
+ private jsonRteCTsWithRef;
29
+ private jsonRteEntries;
30
+ private installedExtensions;
31
+ private createdEntries;
32
+ private failedEntries;
33
+ private locales;
34
+ private entriesUidMapper;
35
+ private envs;
36
+ private autoCreatedEntries;
37
+ constructor({ importConfig, stackAPIClient }: ModuleClassParams);
38
+ start(): Promise<any>;
39
+ disableMandatoryCTReferences(): Promise<void>;
40
+ /**
41
+ * @method serializeUpdateCTs
42
+ * @param {ApiOptions} apiOptions ApiOptions
43
+ * @returns {ApiOptions} ApiOptions
44
+ */
45
+ serializeUpdateCTs(apiOptions: ApiOptions): ApiOptions;
46
+ populateEntryCreatePayload(): {
47
+ cTUid: string;
48
+ locale: string;
49
+ }[];
50
+ createEntries({ cTUid, locale }: {
51
+ cTUid: string;
52
+ locale: string;
53
+ }): Promise<void>;
54
+ /**
55
+ * @method serializeEntries
56
+ * @param {ApiOptions} apiOptions ApiOptions
57
+ * @returns {ApiOptions} ApiOptions
58
+ */
59
+ serializeEntries(apiOptions: ApiOptions): ApiOptions;
60
+ populateEntryUpdatePayload(): {
61
+ cTUid: string;
62
+ locale: string;
63
+ }[];
64
+ updateEntriesWithReferences({ cTUid, locale }: {
65
+ cTUid: string;
66
+ locale: string;
67
+ }): Promise<void>;
68
+ /**
69
+ * @method serializeUpdateEntries
70
+ * @param {ApiOptions} apiOptions ApiOptions
71
+ * @returns {ApiOptions} ApiOptions
72
+ */
73
+ serializeUpdateEntries(apiOptions: ApiOptions): ApiOptions;
74
+ enableMandatoryCTReferences(): Promise<void>;
75
+ /**
76
+ * @method serializeUpdateCTsWithRef
77
+ * @param {ApiOptions} apiOptions ApiOptions
78
+ * @returns {ApiOptions} ApiOptions
79
+ */
80
+ serializeUpdateCTsWithRef(apiOptions: ApiOptions): ApiOptions;
81
+ removeAutoCreatedEntries(): Promise<void>;
82
+ updateFieldRules(): Promise<void>;
83
+ publishEntries({ cTUid, locale }: {
84
+ cTUid: string;
85
+ locale: string;
86
+ }): Promise<void>;
87
+ /**
88
+ * @method serializeEntries
89
+ * @param {ApiOptions} apiOptions ApiOptions
90
+ * @returns {ApiOptions} ApiOptions
91
+ */
92
+ serializePublishEntries(apiOptions: ApiOptions): ApiOptions;
93
+ }