@contentstack/cli-cm-import 1.12.0 → 1.12.2

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.12.0 linux-x64 node-v18.18.2
50
+ @contentstack/cli-cm-import/1.12.2 linux-x64 node-v18.19.0
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -82,6 +82,7 @@ FLAGS
82
82
  --import-webhook-status=<option> [default: disable] [optional] Webhook state
83
83
  <options: disable|current>
84
84
  --replace-existing Replaces the existing module in the target stack.
85
+ --skip-app-recreation [optional] Skip private apps recreation if already exist
85
86
  --skip-existing Skips the module exists warning messages.
86
87
 
87
88
  DESCRIPTION
@@ -129,6 +130,7 @@ FLAGS
129
130
  --import-webhook-status=<option> [default: disable] [optional] Webhook state
130
131
  <options: disable|current>
131
132
  --replace-existing Replaces the existing module in the target stack.
133
+ --skip-app-recreation [optional] Skip private apps recreation if already exist
132
134
  --skip-existing Skips the module exists warning messages.
133
135
 
134
136
  DESCRIPTION
@@ -4,7 +4,6 @@ const tslib_1 = require("tslib");
4
4
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
5
5
  const cli_command_1 = require("@contentstack/cli-command");
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
- const log_1 = require("../../../utils/log");
8
7
  const import_1 = require("../../../import");
9
8
  const utils_1 = require("../../../utils");
10
9
  class ImportCommand extends cli_command_1.Command {
@@ -26,7 +25,6 @@ class ImportCommand extends cli_command_1.Command {
26
25
  (0, utils_1.log)(importConfig, `The log has been stored at '${node_path_1.default.join(importConfig.backupDir, 'logs', 'import')}'`, 'success');
27
26
  }
28
27
  catch (error) {
29
- (0, log_1.trace)(error, 'error', true);
30
28
  (0, utils_1.log)({ data: backupDir }, `Failed to import stack content - ${(0, utils_1.formatError)(error)}`, 'error');
31
29
  (0, utils_1.log)({ data: backupDir }, `The log has been stored at ${{ data: backupDir } ? node_path_1.default.join(backupDir || __dirname, 'logs', 'import') : node_path_1.default.join(__dirname, 'logs')}`, 'info');
32
30
  }
@@ -110,6 +108,9 @@ ImportCommand.flags = {
110
108
  required: false,
111
109
  description: '[optional] Override marketplace prompts',
112
110
  }),
111
+ 'skip-app-recreation': cli_utilities_1.flags.boolean({
112
+ description: '[optional] Skip private apps recreation if already exist',
113
+ }),
113
114
  'replace-existing': cli_utilities_1.flags.boolean({
114
115
  required: false,
115
116
  description: 'Replaces the existing module in the target stack.',
@@ -63,7 +63,7 @@ export default class EntriesImport extends BaseClass {
63
63
  cTUid: string;
64
64
  locale: string;
65
65
  }): Promise<void>;
66
- replaceEntriesHandler({ apiParams, element: entry, isLastRequest, }: {
66
+ replaceEntriesHandler({ apiParams, element: entry }: {
67
67
  apiParams: ApiOptions;
68
68
  element: Record<string, string>;
69
69
  isLastRequest: boolean;
@@ -39,6 +39,7 @@ class EntriesImport extends base_class_1.default {
39
39
  this.failedEntries = [];
40
40
  }
41
41
  async start() {
42
+ var _a;
42
43
  try {
43
44
  this.cTs = utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json'));
44
45
  if (!this.cTs || (0, lodash_1.isEmpty)(this.cTs)) {
@@ -68,7 +69,7 @@ class EntriesImport extends base_class_1.default {
68
69
  }
69
70
  await utils_1.fileHelper.writeLargeFile(path.join(this.entriesMapperPath, 'uid-mapping.json'), this.entriesUidMapper); // TBD: manages mapper in one file, should find an alternative
70
71
  utils_1.fsUtil.writeFile(path.join(this.entriesMapperPath, 'failed-entries.json'), this.failedEntries);
71
- if (this.autoCreatedEntries.length > 0) {
72
+ if (((_a = this.autoCreatedEntries) === null || _a === void 0 ? void 0 : _a.length) > 0) {
72
73
  (0, utils_1.log)(this.importConfig, 'Removing entries from master language which got created by default', 'info');
73
74
  await this.removeAutoCreatedEntries().catch((error) => {
74
75
  (0, utils_1.log)(this.importConfig, `Error while removing auto created entries in master locale ${(0, utils_1.formatError)(error)}`, 'error');
@@ -409,7 +410,7 @@ class EntriesImport extends base_class_1.default {
409
410
  }
410
411
  }
411
412
  }
412
- async replaceEntriesHandler({ apiParams, element: entry, isLastRequest, }) {
413
+ async replaceEntriesHandler({ apiParams, element: entry }) {
413
414
  const { additionalInfo: { cTUid, locale } = {} } = apiParams;
414
415
  return new Promise(async (resolve, reject) => {
415
416
  const { items: [entryInStack] = [] } = (await this.stack
@@ -538,6 +539,7 @@ class EntriesImport extends base_class_1.default {
538
539
  if (this.jsonRteCTs.indexOf(cTUid) > -1) {
539
540
  // the entries stored in eSuccessFilePath, have the same uids as the entries from source data
540
541
  entry = (0, utils_1.restoreJsonRteEntryRefs)(entry, sourceEntry, contentType.schema, {
542
+ uidMapper: this.entriesUidMapper,
541
543
  mappedAssetUids: this.assetUidMapper,
542
544
  mappedAssetUrls: this.assetUrlMapper,
543
545
  });
@@ -618,6 +620,7 @@ class EntriesImport extends base_class_1.default {
618
620
  });
619
621
  }
620
622
  async updateFieldRules() {
623
+ var _a, _b, _c;
621
624
  let cTsWithFieldRules = utils_1.fsUtil.readFile(path.join(this.cTsPath + '/field_rules_uid.json'));
622
625
  if (!cTsWithFieldRules || (cTsWithFieldRules === null || cTsWithFieldRules === void 0 ? void 0 : cTsWithFieldRules.length) === 0) {
623
626
  return;
@@ -627,13 +630,13 @@ class EntriesImport extends base_class_1.default {
627
630
  const contentType = (0, lodash_1.find)(cTs, { uid: cTUid });
628
631
  if (contentType.field_rules) {
629
632
  const fieldDatatypeMap = {};
630
- for (let i = 0; i < contentType.schema.length; i++) {
633
+ for (let i = 0; i < ((_a = contentType.schema) === null || _a === void 0 ? void 0 : _a.length); i++) {
631
634
  const field = contentType.schema[i].uid;
632
635
  fieldDatatypeMap[field] = contentType.schema[i].data_type;
633
636
  }
634
- let fieldRuleLength = contentType.field_rules.length;
637
+ let fieldRuleLength = (_b = contentType.field_rules) === null || _b === void 0 ? void 0 : _b.length;
635
638
  for (let k = 0; k < fieldRuleLength; k++) {
636
- let fieldRuleConditionLength = contentType.field_rules[k].conditions.length;
639
+ let fieldRuleConditionLength = (_c = contentType.field_rules[k].conditions) === null || _c === void 0 ? void 0 : _c.length;
637
640
  for (let i = 0; i < fieldRuleConditionLength; i++) {
638
641
  if (fieldDatatypeMap[contentType.field_rules[k].conditions[i].operand_field] === 'reference') {
639
642
  let fieldRulesValue = contentType.field_rules[k].conditions[i].value;
@@ -723,13 +726,14 @@ class EntriesImport extends base_class_1.default {
723
726
  * @returns {ApiOptions} ApiOptions
724
727
  */
725
728
  serializePublishEntries(apiOptions) {
729
+ var _a;
726
730
  let { apiData: entry, additionalInfo } = apiOptions;
727
731
  const requestObject = {
728
732
  environments: [],
729
733
  locales: [],
730
734
  entryUid: this.entriesUidMapper[entry.uid],
731
735
  };
732
- if (entry.publish_details && entry.publish_details.length > 0) {
736
+ if (entry.publish_details && ((_a = entry.publish_details) === null || _a === void 0 ? void 0 : _a.length) > 0) {
733
737
  (0, lodash_1.forEach)(entry.publish_details, (pubObject) => {
734
738
  if (this.envs.hasOwnProperty(pubObject.environment) &&
735
739
  (0, lodash_1.indexOf)(requestObject.environments, this.envs[pubObject.environment].name) === -1) {
@@ -1,18 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
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
+ };
2
25
  var _a;
3
26
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
5
- const cli_utilities_1 = require("@contentstack/cli-utilities");
6
- const node_path_1 = require("node:path");
7
- const modules_js_1 = tslib_1.__importDefault(require("../modules-js"));
8
27
  async function startModuleImport(modulePayload) {
9
- var _a;
10
- // Todo: Remove below code when auto detect mechanism implemented for old and new module
11
- if (modulePayload.moduleName === 'assets' &&
12
- !new cli_utilities_1.FsUtility({ basePath: (0, node_path_1.join)((_a = modulePayload.importConfig) === null || _a === void 0 ? void 0 : _a.backupDir, 'assets') }).isNewFsStructure) {
13
- return (0, modules_js_1.default)(modulePayload);
14
- }
15
- const { default: ModuleRunner } = await (_a = `./${modulePayload.moduleName}`, Promise.resolve().then(() => tslib_1.__importStar(require(_a))));
28
+ const { default: ModuleRunner } = await (_a = `./${modulePayload.moduleName}`, Promise.resolve().then(() => __importStar(require(_a))));
16
29
  const moduleRunner = new ModuleRunner(modulePayload);
17
30
  return moduleRunner.start();
18
31
  }
@@ -1,43 +1,113 @@
1
- import { NodeCrypto, ContentstackClient } from '@contentstack/cli-utilities';
2
- import BaseClass from './base-class';
3
- import { ModuleClassParams } from '../../types';
4
- export default class ImportMarketplaceApps extends BaseClass {
1
+ import { NodeCrypto, ContentstackMarketplaceClient } from '@contentstack/cli-utilities';
2
+ import { ModuleClassParams, ImportConfig, Installation, Manifest } from '../../types';
3
+ export default class ImportMarketplaceApps {
4
+ importConfig: ImportConfig;
5
5
  private mapperDirPath;
6
6
  private marketPlaceFolderPath;
7
7
  private marketPlaceUidMapperPath;
8
8
  private marketPlaceAppConfig;
9
9
  private marketplaceApps;
10
- private httpClient;
11
10
  private appNameMapping;
12
11
  private appUidMapping;
13
12
  private installationUidMapping;
14
13
  private installedApps;
15
14
  private appOriginalName;
16
15
  developerHubBaseUrl: string;
17
- sdkClient: ContentstackClient;
18
16
  nodeCrypto: NodeCrypto;
19
- appSdkAxiosInstance: any;
20
- constructor({ importConfig, stackAPIClient }: ModuleClassParams);
17
+ appSdk: ContentstackMarketplaceClient;
18
+ constructor({ importConfig }: ModuleClassParams);
21
19
  /**
22
- * @method start
23
- * @returns {Promise<void>} Promise<void>
20
+ * This function starts the process of importing marketplace apps.
21
+ * @returns The function `start()` returns a `Promise<void>`.
24
22
  */
25
23
  start(): Promise<void>;
26
- setHttpClient(): Promise<void>;
27
24
  /**
28
- * @method startInstallation
29
- * @returns {Promise<void>}
25
+ * The function `importMarketplaceApps` installs marketplace apps, handles private app creation,
26
+ * validates app installation, and generates a UID mapper.
27
+ */
28
+ importMarketplaceApps(): Promise<void>;
29
+ /**
30
+ * The function `generateUidMapper` generates a mapping of extension UIDs from old metadata to new
31
+ * metadata based on the installed and marketplace apps.
32
+ * @returns The function `generateUidMapper` returns a Promise that resolves to a `Record<string,
33
+ * unknown>`.
30
34
  */
31
- startInstallation(): Promise<void>;
32
35
  generateUidMapper(): Promise<Record<string, unknown>>;
36
+ /**
37
+ * The function `getAndValidateEncryptionKey` retrieves and validates an encryption key, with the
38
+ * option to retry a specified number of times.
39
+ * @param {string} defaultValue - The defaultValue parameter is a string that represents the default
40
+ * encryption key value to use if no valid encryption key is found in the marketplaceApps
41
+ * configuration.
42
+ * @param [retry=1] - The `retry` parameter is an optional parameter that specifies the number of
43
+ * times the function should retry getting and validating the encryption key if it fails. The default
44
+ * value is 1, meaning that if the function fails to get and validate the encryption key on the first
45
+ * attempt, it will not retry.
46
+ * @returns The function `getAndValidateEncryptionKey` returns a Promise that resolves to the
47
+ * encryption key.
48
+ */
33
49
  getAndValidateEncryptionKey(defaultValue: string, retry?: number): Promise<any>;
34
50
  /**
35
- * @method handleAllPrivateAppsCreationProcess
36
- * @returns {Promise<void>}
51
+ * The function `handleAllPrivateAppsCreationProcess` handles the creation process for all private
52
+ * apps in a developer hub, including checking for existing apps, getting confirmation from the user,
53
+ * and creating the apps if necessary.
54
+ * @returns a Promise that resolves to void.
37
55
  */
38
56
  handleAllPrivateAppsCreationProcess(): Promise<void>;
39
- createPrivateApps(app: any, uidCleaned?: boolean, appSuffix?: number): Promise<any>;
40
- updateManifestUILocations(locations: any, type?: string, appSuffix?: number): Promise<any[]>;
57
+ /**
58
+ * The function checks if a private app exists in the developer hub.
59
+ * @param {App} app - The `app` parameter is an object representing an application. It likely has
60
+ * properties such as `uid` which is a unique identifier for the app.
61
+ * @returns a boolean value. It returns true if the installation object is not empty, and false if
62
+ * the installation object is empty.
63
+ */
64
+ isPrivateAppExistInDeveloperHub(app: Installation): Promise<boolean>;
65
+ /**
66
+ * The function creates a private app in a marketplace, with an optional suffix for the app name and
67
+ * an option to update the UI location.
68
+ * @param {Manifest} app - The `app` parameter is an object that represents the manifest of the app
69
+ * being created. It contains various properties such as `name`, `ui_location`, and `uid`.
70
+ * @param [appSuffix=1] - The appSuffix parameter is an optional parameter that specifies a suffix to
71
+ * be added to the app's UI location. It is used when updating the UI location of the app.
72
+ * @param [updateUiLocation=false] - A boolean value indicating whether to update the UI location of
73
+ * the app.
74
+ * @returns the result of the `appCreationCallback` function, which takes in the `app`, `response`,
75
+ * and `appSuffix` as arguments.
76
+ */
77
+ createPrivateApp(app: Manifest, appSuffix?: number, updateUiLocation?: boolean): Promise<any>;
78
+ /**
79
+ * The function installs an app from a marketplace onto a target stack.
80
+ * @param {ImportConfig} config - The `config` parameter is an object that contains the configuration
81
+ * for the installation. It likely includes information such as the target stack UID and other
82
+ * relevant details.
83
+ * @param {string} [appManifestUid] - The `appManifestUid` parameter is the unique identifier of the
84
+ * app manifest. It is used to specify which app to install from the marketplace.
85
+ * @returns a Promise that resolves to an object.
86
+ */
87
+ installApp(config: ImportConfig, appManifestUid?: string): Promise<any>;
88
+ /**
89
+ * The function updates the names of locations in a manifest UI based on a given app suffix.
90
+ * @param {any} locations - An array of objects representing different locations in a manifest file.
91
+ * Each object has a "meta" property which is an array of objects representing metadata for that
92
+ * location.
93
+ * @param [appSuffix=1] - The `appSuffix` parameter is an optional parameter that specifies a suffix
94
+ * to be added to the app name. It is set to 1 by default.
95
+ * @returns The function `updateManifestUILocations` returns an updated array of `locations`.
96
+ */
97
+ updateManifestUILocations(locations: any, appSuffix?: number): any[];
98
+ /**
99
+ * The function `appCreationCallback` handles the creation of a new app and handles any conflicts or
100
+ * errors that may occur during the process.
101
+ * @param {any} app - The `app` parameter is an object representing the app that is being created. It
102
+ * contains various properties such as `uid` (unique identifier), `name`, and other app-specific
103
+ * details.
104
+ * @param {any} response - The `response` parameter is an object that contains the response received
105
+ * from an API call. It may have properties such as `statusText` and `message`.
106
+ * @param {number} appSuffix - The `appSuffix` parameter is a number that is used to generate a
107
+ * unique suffix for the app name in case of a name conflict. It is incremented each time a name
108
+ * conflict occurs to ensure that the new app name is unique.
109
+ * @returns a Promise.
110
+ */
41
111
  appCreationCallback(app: any, response: any, appSuffix: number): Promise<any>;
42
112
  /**
43
113
  * @method installApps
@@ -48,8 +118,10 @@ export default class ImportMarketplaceApps extends BaseClass {
48
118
  */
49
119
  installApps(app: any): Promise<void>;
50
120
  /**
51
- * @method updateAppsConfig
52
- * @returns {Promise<void>}
121
+ * The `updateAppsConfig` function updates the configuration and server configuration of an app in a
122
+ * marketplace.
123
+ * @param {Installation} app - The `app` parameter is an object that represents an installation of an
124
+ * app. It contains the following properties:
53
125
  */
54
- updateAppsConfig(app: any): Promise<void>;
126
+ updateAppsConfig(app: Installation): Promise<void>;
55
127
  }