@contentstack/cli-cm-import 1.32.3 → 1.33.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 +1 -1
- package/lib/config/index.d.ts +1 -0
- package/lib/config/index.js +8 -0
- package/lib/import/modules/base-class.d.ts +1 -1
- package/lib/import/modules/base-class.js +7 -0
- package/lib/import/modules/publishing-rules.d.ts +33 -0
- package/lib/import/modules/publishing-rules.js +208 -0
- package/lib/types/default-config.d.ts +5 -0
- package/lib/types/index.d.ts +6 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +4 -1
- package/lib/utils/publishing-rules-helper.d.ts +11 -0
- package/lib/utils/publishing-rules-helper.js +33 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
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.
|
|
50
|
+
@contentstack/cli-cm-import/1.33.0 linux-x64 node-v22.22.2
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
package/lib/config/index.d.ts
CHANGED
package/lib/config/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PUBLISHING_RULES_APPROVERS_SKIP_MSG = void 0;
|
|
3
4
|
const config = {
|
|
4
5
|
versioning: false,
|
|
5
6
|
// use below hosts for eu region
|
|
@@ -41,6 +42,7 @@ const config = {
|
|
|
41
42
|
'personalize',
|
|
42
43
|
'custom-roles',
|
|
43
44
|
'workflows',
|
|
45
|
+
'publishing-rules',
|
|
44
46
|
'entries',
|
|
45
47
|
'variant-entries',
|
|
46
48
|
'labels',
|
|
@@ -88,6 +90,11 @@ const config = {
|
|
|
88
90
|
fileName: 'workflows.json',
|
|
89
91
|
invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
|
|
90
92
|
},
|
|
93
|
+
'publishing-rules': {
|
|
94
|
+
dirName: 'workflows',
|
|
95
|
+
fileName: 'publishing-rules.json',
|
|
96
|
+
invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
|
|
97
|
+
},
|
|
91
98
|
assets: {
|
|
92
99
|
dirName: 'assets',
|
|
93
100
|
assetBatchLimit: 1,
|
|
@@ -455,4 +462,5 @@ const config = {
|
|
|
455
462
|
globalModules: ['webhooks'],
|
|
456
463
|
entriesPublish: true,
|
|
457
464
|
};
|
|
465
|
+
exports.PUBLISHING_RULES_APPROVERS_SKIP_MSG = 'Skipping import of publish rule approver(s) (roles/users); reconfigure approvers on the target stack.';
|
|
458
466
|
exports.default = config;
|
|
@@ -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' | 'update-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' | 'create-taxonomies' | 'create-terms' | 'import-taxonomy';
|
|
6
|
+
export type ApiModuleType = 'create-assets' | 'replace-assets' | 'publish-assets' | 'create-assets-folder' | 'create-extensions' | 'update-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' | 'create-taxonomies' | 'create-terms' | 'import-taxonomy' | 'create-publishing-rule';
|
|
7
7
|
export type ApiOptions = {
|
|
8
8
|
uid?: string;
|
|
9
9
|
url?: string;
|
|
@@ -244,6 +244,13 @@ class BaseClass {
|
|
|
244
244
|
.create({ workflow: apiData })
|
|
245
245
|
.then(onSuccess)
|
|
246
246
|
.catch(onReject);
|
|
247
|
+
case 'create-publishing-rule':
|
|
248
|
+
return this.stack
|
|
249
|
+
.workflow()
|
|
250
|
+
.publishRule()
|
|
251
|
+
.create({ publishing_rule: (0, omit_1.default)(apiData, ['uid']) })
|
|
252
|
+
.then(onSuccess)
|
|
253
|
+
.catch(onReject);
|
|
247
254
|
case 'create-custom-role':
|
|
248
255
|
return this.stack
|
|
249
256
|
.role()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BaseClass, { ApiOptions } from './base-class';
|
|
2
|
+
import { ModuleClassParams } from '../../types';
|
|
3
|
+
export default class ImportPublishingRules extends BaseClass {
|
|
4
|
+
private readonly mapperDirPath;
|
|
5
|
+
private readonly publishingRulesFolderPath;
|
|
6
|
+
private readonly publishingRulesUidMapperPath;
|
|
7
|
+
private readonly createdPublishingRulesPath;
|
|
8
|
+
private readonly failedPublishingRulesPath;
|
|
9
|
+
private readonly publishingRulesConfig;
|
|
10
|
+
private publishingRules;
|
|
11
|
+
private publishingRulesUidMapper;
|
|
12
|
+
private readonly createdPublishingRules;
|
|
13
|
+
private readonly failedPublishingRules;
|
|
14
|
+
private envUidMapper;
|
|
15
|
+
private workflowUidMapper;
|
|
16
|
+
private readonly stageUidMapper;
|
|
17
|
+
constructor({ importConfig, stackAPIClient }: ModuleClassParams);
|
|
18
|
+
private static collectOldStageUidToName;
|
|
19
|
+
/**
|
|
20
|
+
* Returns `{ noSuccessMsg: true }` if any rule failed, so the import command skips the generic stack success line.
|
|
21
|
+
*/
|
|
22
|
+
start(): Promise<{
|
|
23
|
+
noSuccessMsg: true;
|
|
24
|
+
} | void>;
|
|
25
|
+
private readUidMappingFile;
|
|
26
|
+
private readMapper;
|
|
27
|
+
private importPublishingRules;
|
|
28
|
+
private mergeFetchedWorkflowStages;
|
|
29
|
+
private buildStageUidMapper;
|
|
30
|
+
private stripApprovers;
|
|
31
|
+
private remapReference;
|
|
32
|
+
serializePublishingRules(apiOptions: ApiOptions): ApiOptions;
|
|
33
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
|
+
const values_1 = tslib_1.__importDefault(require("lodash/values"));
|
|
6
|
+
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
9
|
+
const config_1 = require("../../config");
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
12
|
+
class ImportPublishingRules extends base_class_1.default {
|
|
13
|
+
constructor({ importConfig, stackAPIClient }) {
|
|
14
|
+
super({ importConfig, stackAPIClient });
|
|
15
|
+
this.stageUidMapper = {};
|
|
16
|
+
this.importConfig.context.module = 'publishing-rules';
|
|
17
|
+
this.publishingRulesConfig = importConfig.modules['publishing-rules'];
|
|
18
|
+
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'publishing-rules');
|
|
19
|
+
this.publishingRulesFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.publishingRulesConfig.dirName);
|
|
20
|
+
this.publishingRulesUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
|
|
21
|
+
this.createdPublishingRulesPath = (0, node_path_1.join)(this.mapperDirPath, 'success.json');
|
|
22
|
+
this.failedPublishingRulesPath = (0, node_path_1.join)(this.mapperDirPath, 'fails.json');
|
|
23
|
+
this.publishingRules = {};
|
|
24
|
+
this.publishingRulesUidMapper = {};
|
|
25
|
+
this.createdPublishingRules = [];
|
|
26
|
+
this.failedPublishingRules = [];
|
|
27
|
+
this.envUidMapper = {};
|
|
28
|
+
this.workflowUidMapper = {};
|
|
29
|
+
}
|
|
30
|
+
static collectOldStageUidToName(exportedWorkflows) {
|
|
31
|
+
var _a;
|
|
32
|
+
const map = {};
|
|
33
|
+
for (const workflow of Object.values(exportedWorkflows)) {
|
|
34
|
+
for (const stage of (_a = workflow.workflow_stages) !== null && _a !== void 0 ? _a : []) {
|
|
35
|
+
if (stage.uid && stage.name) {
|
|
36
|
+
map[stage.uid] = stage.name;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return map;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns `{ noSuccessMsg: true }` if any rule failed, so the import command skips the generic stack success line.
|
|
44
|
+
*/
|
|
45
|
+
async start() {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
const rulesFilePath = (0, node_path_1.join)(this.publishingRulesFolderPath, this.publishingRulesConfig.fileName);
|
|
48
|
+
if (!utils_1.fileHelper.fileExistsSync(rulesFilePath)) {
|
|
49
|
+
cli_utilities_1.log.info(`No Publishing Rules found - '${rulesFilePath}'`, this.importConfig.context);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.publishingRules = (_a = utils_1.fsUtil.readFile(rulesFilePath, true)) !== null && _a !== void 0 ? _a : {};
|
|
53
|
+
if ((0, isEmpty_1.default)(this.publishingRules)) {
|
|
54
|
+
cli_utilities_1.log.info('No Publishing Rules found', this.importConfig.context);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
58
|
+
this.publishingRulesUidMapper = this.readUidMappingFile(this.publishingRulesUidMapperPath);
|
|
59
|
+
this.envUidMapper = this.readMapper('environments');
|
|
60
|
+
this.workflowUidMapper = this.readMapper('workflows');
|
|
61
|
+
await this.buildStageUidMapper();
|
|
62
|
+
await this.importPublishingRules();
|
|
63
|
+
if ((_b = this.createdPublishingRules) === null || _b === void 0 ? void 0 : _b.length) {
|
|
64
|
+
utils_1.fsUtil.writeFile(this.createdPublishingRulesPath, this.createdPublishingRules);
|
|
65
|
+
}
|
|
66
|
+
if ((_c = this.failedPublishingRules) === null || _c === void 0 ? void 0 : _c.length) {
|
|
67
|
+
utils_1.fsUtil.writeFile(this.failedPublishingRulesPath, this.failedPublishingRules);
|
|
68
|
+
}
|
|
69
|
+
const successCount = this.createdPublishingRules.length;
|
|
70
|
+
const failCount = this.failedPublishingRules.length;
|
|
71
|
+
if (failCount > 0 && successCount === 0) {
|
|
72
|
+
cli_utilities_1.log.error(`Publishing rules import failed! ${failCount} rule(s) could not be imported. Check '${this.failedPublishingRulesPath}' for details.`, this.importConfig.context);
|
|
73
|
+
}
|
|
74
|
+
else if (failCount > 0) {
|
|
75
|
+
cli_utilities_1.log.warn(`Publishing rules import completed with errors. Imported: ${successCount}, Failed: ${failCount}. Check '${this.failedPublishingRulesPath}' for details.`, this.importConfig.context);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
cli_utilities_1.log.success('Publishing rules have been imported successfully!', this.importConfig.context);
|
|
79
|
+
}
|
|
80
|
+
if (failCount > 0) {
|
|
81
|
+
return { noSuccessMsg: true };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
readUidMappingFile(path) {
|
|
85
|
+
var _a;
|
|
86
|
+
return utils_1.fileHelper.fileExistsSync(path) ? (_a = utils_1.fsUtil.readFile(path, true)) !== null && _a !== void 0 ? _a : {} : {};
|
|
87
|
+
}
|
|
88
|
+
readMapper(moduleDir) {
|
|
89
|
+
const p = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', moduleDir, 'uid-mapping.json');
|
|
90
|
+
return this.readUidMappingFile(p);
|
|
91
|
+
}
|
|
92
|
+
async importPublishingRules() {
|
|
93
|
+
const apiContent = (0, values_1.default)(this.publishingRules);
|
|
94
|
+
cli_utilities_1.log.debug(`Importing ${apiContent.length} publishing rule(s)`, this.importConfig.context);
|
|
95
|
+
const onSuccess = ({ response, apiData }) => {
|
|
96
|
+
const { uid } = apiData;
|
|
97
|
+
this.createdPublishingRules.push(response);
|
|
98
|
+
this.publishingRulesUidMapper[uid] = response.uid;
|
|
99
|
+
cli_utilities_1.log.success(`Publishing rule imported successfully (${uid} → ${response.uid})`, this.importConfig.context);
|
|
100
|
+
utils_1.fsUtil.writeFile(this.publishingRulesUidMapperPath, this.publishingRulesUidMapper);
|
|
101
|
+
};
|
|
102
|
+
const onReject = ({ error, apiData }) => {
|
|
103
|
+
const uid = apiData.uid;
|
|
104
|
+
const parsed = (0, utils_1.parseErrorPayload)(error);
|
|
105
|
+
if ((0, utils_1.isDuplicatePublishingRuleError)(parsed, error)) {
|
|
106
|
+
cli_utilities_1.log.info(`Publishing rule '${uid}' already exists`, this.importConfig.context);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.failedPublishingRules.push(apiData);
|
|
110
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { publishingRuleUid: uid }), `Publishing rule '${uid}' failed to import`);
|
|
111
|
+
};
|
|
112
|
+
await this.makeConcurrentCall({
|
|
113
|
+
apiContent,
|
|
114
|
+
processName: 'import publishing rules',
|
|
115
|
+
apiParams: {
|
|
116
|
+
serializeData: this.serializePublishingRules.bind(this),
|
|
117
|
+
reject: onReject,
|
|
118
|
+
resolve: onSuccess,
|
|
119
|
+
entity: 'create-publishing-rule',
|
|
120
|
+
includeParamOnCompletion: true,
|
|
121
|
+
},
|
|
122
|
+
concurrencyLimit: this.importConfig.fetchConcurrency || 1,
|
|
123
|
+
}, undefined, false);
|
|
124
|
+
}
|
|
125
|
+
mergeFetchedWorkflowStages(workflow, oldStageUidToName) {
|
|
126
|
+
var _a;
|
|
127
|
+
for (const newStage of (_a = workflow.workflow_stages) !== null && _a !== void 0 ? _a : []) {
|
|
128
|
+
const oldUid = Object.keys(oldStageUidToName).find((u) => oldStageUidToName[u] === newStage.name);
|
|
129
|
+
if (oldUid && newStage.uid) {
|
|
130
|
+
this.stageUidMapper[oldUid] = newStage.uid;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async buildStageUidMapper() {
|
|
135
|
+
const wf = this.importConfig.modules.workflows;
|
|
136
|
+
const workflowsFilePath = (0, node_path_1.join)(this.importConfig.backupDir, wf.dirName, wf.fileName);
|
|
137
|
+
if (!utils_1.fileHelper.fileExistsSync(workflowsFilePath)) {
|
|
138
|
+
cli_utilities_1.log.debug('No exported workflows file; stage UID mapping skipped', this.importConfig.context);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const exportedWorkflows = utils_1.fsUtil.readFile(workflowsFilePath, true);
|
|
142
|
+
if (!exportedWorkflows)
|
|
143
|
+
return;
|
|
144
|
+
const oldStageUidToName = ImportPublishingRules.collectOldStageUidToName(exportedWorkflows);
|
|
145
|
+
for (const newWorkflowUid of Object.values(this.workflowUidMapper)) {
|
|
146
|
+
try {
|
|
147
|
+
const workflow = await this.stack.workflow(newWorkflowUid).fetch();
|
|
148
|
+
this.mergeFetchedWorkflowStages(workflow, oldStageUidToName);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
cli_utilities_1.log.debug(`Stage mapping: could not fetch workflow '${newWorkflowUid}'`, this.importConfig.context);
|
|
152
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
cli_utilities_1.log.debug(`Stage UID mapper: ${Object.keys(this.stageUidMapper).length} entr(y/ies)`, this.importConfig.context);
|
|
156
|
+
}
|
|
157
|
+
stripApprovers(rule) {
|
|
158
|
+
if (rule.approvers == null)
|
|
159
|
+
return;
|
|
160
|
+
const a = rule.approvers;
|
|
161
|
+
const hadContent = (Array.isArray(a.roles) && a.roles.length > 0) || (Array.isArray(a.users) && a.users.length > 0);
|
|
162
|
+
if (hadContent) {
|
|
163
|
+
cli_utilities_1.log.info(chalk_1.default.yellow(config_1.PUBLISHING_RULES_APPROVERS_SKIP_MSG), this.importConfig.context);
|
|
164
|
+
}
|
|
165
|
+
rule.approvers = { roles: [], users: [] };
|
|
166
|
+
}
|
|
167
|
+
remapReference(rule, field, mapper) {
|
|
168
|
+
const current = rule[field];
|
|
169
|
+
if (!current)
|
|
170
|
+
return;
|
|
171
|
+
const mapped = mapper[current];
|
|
172
|
+
if (mapped) {
|
|
173
|
+
rule[field] = mapped;
|
|
174
|
+
cli_utilities_1.log.debug(`${field} UID remapped`, this.importConfig.context);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
cli_utilities_1.log.debug(`No ${field} mapping for ${current}; leaving as-is`, this.importConfig.context);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
serializePublishingRules(apiOptions) {
|
|
181
|
+
const rule = apiOptions.apiData;
|
|
182
|
+
const ruleUid = rule.uid;
|
|
183
|
+
if (ruleUid in this.publishingRulesUidMapper) {
|
|
184
|
+
cli_utilities_1.log.info(`Publishing rule '${ruleUid}' already exists. Skipping it to avoid duplicates!`, this.importConfig.context);
|
|
185
|
+
apiOptions.entity = undefined;
|
|
186
|
+
return apiOptions;
|
|
187
|
+
}
|
|
188
|
+
const oldUid = ruleUid;
|
|
189
|
+
delete rule.uid;
|
|
190
|
+
this.stripApprovers(rule);
|
|
191
|
+
this.remapReference(rule, 'workflow', this.workflowUidMapper);
|
|
192
|
+
this.remapReference(rule, 'environment', this.envUidMapper);
|
|
193
|
+
if (rule.workflow_stage) {
|
|
194
|
+
const stage = rule.workflow_stage;
|
|
195
|
+
const mappedStage = this.stageUidMapper[stage];
|
|
196
|
+
if (mappedStage) {
|
|
197
|
+
rule.workflow_stage = mappedStage;
|
|
198
|
+
cli_utilities_1.log.debug('workflow_stage UID remapped', this.importConfig.context);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
cli_utilities_1.log.debug(`No workflow_stage mapping for ${stage}; leaving as-is`, this.importConfig.context);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
apiOptions.apiData = Object.assign(Object.assign({}, rule), { uid: oldUid });
|
|
205
|
+
return apiOptions;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.default = ImportPublishingRules;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface User {
|
|
|
26
26
|
email: string;
|
|
27
27
|
authtoken: string;
|
|
28
28
|
}
|
|
29
|
-
export type Modules = 'stack' | 'assets' | 'locales' | 'environments' | 'extensions' | 'webhooks' | 'global-fields' | 'entries' | 'content-types' | 'custom-roles' | 'workflows' | 'labels' | 'marketplace-apps' | 'taxonomies' | 'personalize' | 'variant-entries' | 'composable-studio';
|
|
29
|
+
export type Modules = 'stack' | 'assets' | 'locales' | 'environments' | 'extensions' | 'webhooks' | 'global-fields' | 'entries' | 'content-types' | 'custom-roles' | 'workflows' | 'publishing-rules' | 'labels' | 'marketplace-apps' | 'taxonomies' | 'personalize' | 'variant-entries' | 'composable-studio';
|
|
30
30
|
export type ModuleClassParams = {
|
|
31
31
|
stackAPIClient: ReturnType<ContentstackClient['stack']>;
|
|
32
32
|
importConfig: ImportConfig;
|
|
@@ -61,6 +61,11 @@ export interface WorkflowConfig {
|
|
|
61
61
|
fileName: string;
|
|
62
62
|
invalidKeys: string[];
|
|
63
63
|
}
|
|
64
|
+
export interface PublishingRulesConfig {
|
|
65
|
+
dirName: string;
|
|
66
|
+
fileName: string;
|
|
67
|
+
invalidKeys: string[];
|
|
68
|
+
}
|
|
64
69
|
export interface CustomRoleConfig {
|
|
65
70
|
dirName: string;
|
|
66
71
|
fileName: string;
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -14,3 +14,4 @@ export { lookupEntries, removeUidsFromJsonRteFields, removeEntryRefsFromJSONRTE,
|
|
|
14
14
|
export * from './common-helper';
|
|
15
15
|
export * from './log';
|
|
16
16
|
export { lookUpTaxonomy, lookUpTerms } from './taxonomies-helper';
|
|
17
|
+
export { parseErrorPayload, isDuplicatePublishingRuleError } from './publishing-rules-helper';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = exports.executeImportPathLogic = exports.updateImportConfigWithResolvedPath = exports.resolveImportPath = exports.selectBranchFromDirectory = exports.setupBranchConfig = void 0;
|
|
3
|
+
exports.isDuplicatePublishingRuleError = exports.parseErrorPayload = exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = exports.executeImportPathLogic = exports.updateImportConfigWithResolvedPath = exports.resolveImportPath = exports.selectBranchFromDirectory = exports.setupBranchConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var setup_branch_1 = require("./setup-branch");
|
|
6
6
|
Object.defineProperty(exports, "setupBranchConfig", { enumerable: true, get: function () { return setup_branch_1.setupBranchConfig; } });
|
|
@@ -48,3 +48,6 @@ tslib_1.__exportStar(require("./log"), exports);
|
|
|
48
48
|
var taxonomies_helper_1 = require("./taxonomies-helper");
|
|
49
49
|
Object.defineProperty(exports, "lookUpTaxonomy", { enumerable: true, get: function () { return taxonomies_helper_1.lookUpTaxonomy; } });
|
|
50
50
|
Object.defineProperty(exports, "lookUpTerms", { enumerable: true, get: function () { return taxonomies_helper_1.lookUpTerms; } });
|
|
51
|
+
var publishing_rules_helper_1 = require("./publishing-rules-helper");
|
|
52
|
+
Object.defineProperty(exports, "parseErrorPayload", { enumerable: true, get: function () { return publishing_rules_helper_1.parseErrorPayload; } });
|
|
53
|
+
Object.defineProperty(exports, "isDuplicatePublishingRuleError", { enumerable: true, get: function () { return publishing_rules_helper_1.isDuplicatePublishingRuleError; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for publishing rules import (API error shape, duplicate detection).
|
|
3
|
+
*/
|
|
4
|
+
export declare function parseErrorPayload(error: unknown): {
|
|
5
|
+
errors?: Record<string, unknown>;
|
|
6
|
+
error_message?: string;
|
|
7
|
+
} | null;
|
|
8
|
+
export declare function isDuplicatePublishingRuleError(parsed: {
|
|
9
|
+
errors?: Record<string, unknown>;
|
|
10
|
+
error_message?: string;
|
|
11
|
+
} | null, raw: unknown): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Helpers for publishing rules import (API error shape, duplicate detection).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isDuplicatePublishingRuleError = exports.parseErrorPayload = void 0;
|
|
7
|
+
function parseErrorPayload(error) {
|
|
8
|
+
if (!error || typeof error !== 'object')
|
|
9
|
+
return null;
|
|
10
|
+
const e = error;
|
|
11
|
+
if (e.errors)
|
|
12
|
+
return e;
|
|
13
|
+
if (e.message && typeof e.message === 'string') {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(e.message);
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
exports.parseErrorPayload = parseErrorPayload;
|
|
24
|
+
function isDuplicatePublishingRuleError(parsed, raw) {
|
|
25
|
+
var _a;
|
|
26
|
+
const errors = (_a = parsed === null || parsed === void 0 ? void 0 : parsed.errors) !== null && _a !== void 0 ? _a : raw === null || raw === void 0 ? void 0 : raw.errors;
|
|
27
|
+
if ((errors === null || errors === void 0 ? void 0 : errors.name) || (errors === null || errors === void 0 ? void 0 : errors['publishing_rule.name']) || (errors === null || errors === void 0 ? void 0 : errors['publish_rule.name'])) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const msg = parsed === null || parsed === void 0 ? void 0 : parsed.error_message;
|
|
31
|
+
return typeof msg === 'string' && /already exists|duplicate/i.test(msg);
|
|
32
|
+
}
|
|
33
|
+
exports.isDuplicatePublishingRuleError = isDuplicatePublishingRuleError;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.33.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@contentstack/cli-audit": "~1.19.3",
|
|
9
9
|
"@contentstack/cli-command": "~1.8.2",
|
|
10
10
|
"@contentstack/cli-utilities": "~1.18.3",
|
|
11
|
-
"@contentstack/cli-variants": "~1.
|
|
11
|
+
"@contentstack/cli-variants": "~1.5.0",
|
|
12
12
|
"@oclif/core": "^4.10.5",
|
|
13
13
|
"big-json": "^3.2.0",
|
|
14
14
|
"bluebird": "^3.7.2",
|
|
@@ -89,4 +89,4 @@
|
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
"repository": "https://github.com/contentstack/cli"
|
|
92
|
-
}
|
|
92
|
+
}
|