@contentstack/cli-variants 1.2.2 → 1.3.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/lib/export/attributes.js +27 -10
- package/lib/export/audiences.js +28 -10
- package/lib/export/events.js +28 -10
- package/lib/export/experiences.js +48 -13
- package/lib/export/projects.js +24 -6
- package/lib/export/variant-entries.js +25 -4
- package/lib/import/attribute.d.ts +2 -3
- package/lib/import/attribute.js +16 -8
- package/lib/import/audiences.d.ts +2 -3
- package/lib/import/audiences.js +21 -8
- package/lib/import/events.d.ts +3 -4
- package/lib/import/events.js +16 -9
- package/lib/import/experiences.d.ts +2 -3
- package/lib/import/experiences.js +60 -17
- package/lib/import/project.d.ts +2 -3
- package/lib/import/project.js +11 -6
- package/lib/import/variant-entries.js +62 -25
- package/lib/types/export-config.d.ts +2 -1
- package/lib/types/utils.d.ts +11 -0
- package/lib/utils/attributes-helper.js +17 -1
- package/lib/utils/audiences-helper.js +37 -6
- package/lib/utils/events-helper.js +17 -4
- package/lib/utils/personalization-api-adapter.d.ts +2 -1
- package/lib/utils/personalization-api-adapter.js +119 -27
- package/lib/utils/variant-api-adapter.d.ts +4 -1
- package/lib/utils/variant-api-adapter.js +91 -17
- package/package.json +5 -2
- package/src/export/attributes.ts +34 -10
- package/src/export/audiences.ts +35 -7
- package/src/export/events.ts +35 -7
- package/src/export/experiences.ts +74 -24
- package/src/export/projects.ts +31 -7
- package/src/export/variant-entries.ts +47 -12
- package/src/import/attribute.ts +22 -9
- package/src/import/audiences.ts +28 -10
- package/src/import/events.ts +21 -10
- package/src/import/experiences.ts +74 -20
- package/src/import/project.ts +22 -8
- package/src/import/variant-entries.ts +116 -40
- package/src/types/export-config.ts +2 -1
- package/src/types/utils.ts +12 -0
- package/src/utils/attributes-helper.ts +21 -2
- package/src/utils/audiences-helper.ts +41 -1
- package/src/utils/events-helper.ts +19 -1
- package/src/utils/personalization-api-adapter.ts +95 -19
- package/src/utils/variant-api-adapter.ts +79 -8
|
@@ -77,6 +77,9 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
77
77
|
this.entriesDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.backupDir), (0, cli_utilities_1.sanitizePath)(config.modules.entries.dirName));
|
|
78
78
|
this.failedVariantPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'failed-entry-variants.json');
|
|
79
79
|
this.failedVariantEntries = new Map();
|
|
80
|
+
if (this.config && this.config.context) {
|
|
81
|
+
this.config.context.module = 'variant-entries';
|
|
82
|
+
}
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
85
|
* This TypeScript function asynchronously imports backupDir from a JSON file and processes the entries
|
|
@@ -90,17 +93,20 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
90
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
94
|
const filePath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'data-for-variant-entry.json');
|
|
92
95
|
const variantIdPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.experiences.dirName), 'variants-uid-mapping.json');
|
|
96
|
+
cli_utilities_1.log.debug(`Checking for variant entry data file: ${filePath}`, this.config.context);
|
|
93
97
|
if (!(0, fs_1.existsSync)(filePath)) {
|
|
94
|
-
|
|
98
|
+
cli_utilities_1.log.warn(`Variant entry data file not found at path: ${filePath}, skipping import`, this.config.context);
|
|
95
99
|
return;
|
|
96
100
|
}
|
|
101
|
+
cli_utilities_1.log.debug(`Checking for variant ID mapping file: ${variantIdPath}`, this.config.context);
|
|
97
102
|
if (!(0, fs_1.existsSync)(variantIdPath)) {
|
|
98
|
-
|
|
103
|
+
cli_utilities_1.log.error('Variant UID mapping file not found', this.config.context);
|
|
99
104
|
return;
|
|
100
105
|
}
|
|
101
106
|
const entriesForVariants = utils_1.fsUtil.readFile(filePath, true);
|
|
107
|
+
cli_utilities_1.log.debug(`Loaded ${(entriesForVariants === null || entriesForVariants === void 0 ? void 0 : entriesForVariants.length) || 0} entries for variant processing`, this.config.context);
|
|
102
108
|
if ((0, isEmpty_1.default)(entriesForVariants)) {
|
|
103
|
-
|
|
109
|
+
cli_utilities_1.log.warn('No entries found for variant import', this.config.context);
|
|
104
110
|
return;
|
|
105
111
|
}
|
|
106
112
|
const entriesUidMapperPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'uid-mapping.json');
|
|
@@ -109,10 +115,11 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
109
115
|
const taxonomiesPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.config.modules.taxonomies.dirName), 'terms', 'success.json');
|
|
110
116
|
const marketplaceAppMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', 'marketplace_apps', 'uid-mapping.json');
|
|
111
117
|
const envPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'environments', 'environments.json');
|
|
118
|
+
cli_utilities_1.log.debug('Loading variant ID mapping and dependency data', this.config.context);
|
|
112
119
|
// NOTE Read and store list of variant IDs
|
|
113
120
|
this.variantIdList = (utils_1.fsUtil.readFile(variantIdPath, true) || {});
|
|
114
121
|
if ((0, isEmpty_1.default)(this.variantIdList)) {
|
|
115
|
-
|
|
122
|
+
cli_utilities_1.log.warn('Empty variant UID data found', this.config.context);
|
|
116
123
|
return;
|
|
117
124
|
}
|
|
118
125
|
// NOTE entry relational data lookup dependencies.
|
|
@@ -123,12 +130,14 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
123
130
|
this.assetUidMapper = (utils_1.fsUtil.readFile(assetUidMapperPath, true) || {});
|
|
124
131
|
this.assetUrlMapper = (utils_1.fsUtil.readFile(assetUrlMapperPath, true) || {});
|
|
125
132
|
this.environments = (utils_1.fsUtil.readFile(envPath, true) || {});
|
|
133
|
+
cli_utilities_1.log.debug(`Loaded dependency data - Entries: ${Object.keys(this.entriesUidMapper).length}, Assets: ${Object.keys(this.assetUidMapper).length}, Taxonomies: ${Object.keys(this.taxonomies).length}`, this.config.context);
|
|
126
134
|
// set the token
|
|
127
135
|
yield this.variantInstance.init();
|
|
136
|
+
cli_utilities_1.log.info(`Processing ${entriesForVariants.length} entries for variant import`, this.config.context);
|
|
128
137
|
for (const entriesForVariant of entriesForVariants) {
|
|
129
138
|
yield this.importVariantEntries(entriesForVariant);
|
|
130
139
|
}
|
|
131
|
-
|
|
140
|
+
cli_utilities_1.log.success('All variant entries have been imported and published successfully', this.config.context);
|
|
132
141
|
});
|
|
133
142
|
}
|
|
134
143
|
/**
|
|
@@ -140,19 +149,22 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
140
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
150
|
const variantEntry = this.config.modules.variantEntry;
|
|
142
151
|
const { content_type, locale, entry_uid } = entriesForVariant;
|
|
152
|
+
cli_utilities_1.log.debug(`Importing variant entries for: ${content_type}/${locale}/${entry_uid}`, this.config.context);
|
|
143
153
|
const ctConfig = this.config.modules['content-types'];
|
|
144
154
|
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'));
|
|
145
155
|
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));
|
|
156
|
+
cli_utilities_1.log.debug(`Processing variant entries from: ${variantEntryBasePath}`, this.config.context);
|
|
146
157
|
const fs = new cli_utilities_1.FsUtility({ basePath: variantEntryBasePath, createDirIfNotExist: false });
|
|
147
158
|
for (const _ in fs.indexFileContent) {
|
|
148
159
|
try {
|
|
149
160
|
const variantEntries = (yield fs.readChunkFiles.next());
|
|
150
161
|
if (variantEntries === null || variantEntries === void 0 ? void 0 : variantEntries.length) {
|
|
162
|
+
cli_utilities_1.log.debug(`Processing batch of ${variantEntries.length} variant entries`, this.config.context);
|
|
151
163
|
yield this.handleConcurrency(contentType, variantEntries, entriesForVariant);
|
|
152
164
|
}
|
|
153
165
|
}
|
|
154
166
|
catch (error) {
|
|
155
|
-
(0,
|
|
167
|
+
(0, cli_utilities_1.handleAndLogError)(error, this.config.context, `Failed to process variant entries for ${content_type}/${locale}/${entry_uid}`);
|
|
156
168
|
}
|
|
157
169
|
}
|
|
158
170
|
});
|
|
@@ -180,27 +192,30 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
180
192
|
const batches = (0, chunk_1.default)(variantEntries, variantEntryConfig.apiConcurrency || 5);
|
|
181
193
|
if ((0, isEmpty_1.default)(batches))
|
|
182
194
|
return;
|
|
195
|
+
cli_utilities_1.log.debug(`Starting concurrent processing for ${variantEntries.length} variant entries`, this.config.context);
|
|
183
196
|
for (const [, batch] of (0, entries_1.default)(batches)) {
|
|
184
197
|
batchNo += 1;
|
|
185
198
|
const allPromise = [];
|
|
186
199
|
const start = Date.now();
|
|
200
|
+
cli_utilities_1.log.debug(`Processing batch ${batchNo}/${batches.length} with ${batch.length} variant entries`, this.config.context);
|
|
187
201
|
for (let [, variantEntry] of (0, entries_1.default)(batch)) {
|
|
188
|
-
const onSuccess = ({ response, apiData: { entryUid, variantUid }
|
|
189
|
-
log(
|
|
202
|
+
const onSuccess = ({ response, apiData: { entryUid, variantUid } }) => {
|
|
203
|
+
cli_utilities_1.log.info(`Created entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`, this.config.context);
|
|
190
204
|
};
|
|
191
|
-
const onReject = ({ error, apiData
|
|
205
|
+
const onReject = ({ error, apiData }) => {
|
|
192
206
|
const { entryUid, variantUid } = apiData;
|
|
193
207
|
this.failedVariantEntries.set(variantUid, apiData);
|
|
194
|
-
|
|
195
|
-
log(this.config, error, 'error');
|
|
208
|
+
(0, cli_utilities_1.handleAndLogError)(error, this.config.context, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`);
|
|
196
209
|
};
|
|
197
210
|
// NOTE Find new variant Id by old Id
|
|
198
211
|
const variantId = this.variantIdList[variantEntry._variant._uid];
|
|
212
|
+
cli_utilities_1.log.debug(`Looking up variant ID for ${variantEntry._variant._uid}: ${variantId ? 'found' : 'not found'}`, this.config.context);
|
|
199
213
|
// NOTE Replace all the relation data UID's
|
|
200
214
|
variantEntry = this.handleVariantEntryRelationalData(contentType, variantEntry);
|
|
201
215
|
const changeSet = this.serializeChangeSet(variantEntry);
|
|
202
216
|
const createVariantReq = Object.assign({ _variant: variantEntry._variant }, changeSet);
|
|
203
217
|
if (variantId) {
|
|
218
|
+
cli_utilities_1.log.debug(`Creating variant entry for variant ID: ${variantId}`, this.config.context);
|
|
204
219
|
const promise = this.variantInstance.createVariantEntry(createVariantReq, {
|
|
205
220
|
locale,
|
|
206
221
|
entry_uid: entryUid,
|
|
@@ -210,22 +225,25 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
210
225
|
reject: onReject.bind(this),
|
|
211
226
|
resolve: onSuccess.bind(this),
|
|
212
227
|
variantUid: variantId,
|
|
213
|
-
log: utils_1.log,
|
|
214
228
|
});
|
|
215
229
|
allPromise.push(promise);
|
|
216
230
|
}
|
|
217
231
|
else {
|
|
218
|
-
|
|
232
|
+
cli_utilities_1.log.error(`Variant ID not found for ${variantEntry._variant._uid}`, this.config.context);
|
|
219
233
|
}
|
|
220
234
|
}
|
|
221
235
|
// NOTE Handle the API response here
|
|
236
|
+
cli_utilities_1.log.debug(`Waiting for ${allPromise.length} variant entry creation promises to complete`, this.config.context);
|
|
222
237
|
yield Promise.allSettled(allPromise);
|
|
238
|
+
cli_utilities_1.log.debug(`Batch ${batchNo} creation completed`, this.config.context);
|
|
223
239
|
// NOTE publish all the entries
|
|
224
240
|
yield this.publishVariantEntries(batch, entryUid, content_type);
|
|
225
241
|
const end = Date.now();
|
|
226
242
|
const exeTime = end - start;
|
|
243
|
+
cli_utilities_1.log.debug(`Batch ${batchNo} completed in ${exeTime}ms`, this.config.context);
|
|
227
244
|
this.variantInstance.delay(1000 - exeTime);
|
|
228
245
|
}
|
|
246
|
+
cli_utilities_1.log.debug(`Writing failed variant entries to: ${this.failedVariantPath}`, this.config.context);
|
|
229
247
|
utils_1.fsUtil.writeFile(this.failedVariantPath, this.failedVariantEntries);
|
|
230
248
|
});
|
|
231
249
|
}
|
|
@@ -263,21 +281,25 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
263
281
|
* `config.helpers`.
|
|
264
282
|
*/
|
|
265
283
|
handleVariantEntryRelationalData(contentType, variantEntry) {
|
|
284
|
+
cli_utilities_1.log.debug(`Processing relational data for variant entry: ${variantEntry.uid}`, this.config.context);
|
|
266
285
|
if (this.config.helpers) {
|
|
267
286
|
const { lookUpTerms, lookupAssets, lookupExtension, lookupEntries, restoreJsonRteEntryRefs } = this.config.helpers;
|
|
268
287
|
// FIXME Not sure why do we even need lookupExtension in entries [Ref taken from entries import]
|
|
269
288
|
// Feel free to remove this flow if it's not valid
|
|
270
289
|
// NOTE Find and replace extension's UID
|
|
271
290
|
if (lookupExtension) {
|
|
291
|
+
cli_utilities_1.log.debug('Processing extension lookups for variant entry', this.config.context);
|
|
272
292
|
lookupExtension(this.config, contentType.schema, this.config.preserveStackVersion, this.installedExtensions);
|
|
273
293
|
}
|
|
274
294
|
// NOTE Find and replace RTE Ref UIDs
|
|
295
|
+
cli_utilities_1.log.debug('Processing RTE reference lookups for variant entry', this.config.context);
|
|
275
296
|
variantEntry = restoreJsonRteEntryRefs(variantEntry, variantEntry, contentType.schema, {
|
|
276
297
|
uidMapper: this.entriesUidMapper,
|
|
277
298
|
mappedAssetUids: this.assetUidMapper,
|
|
278
299
|
mappedAssetUrls: this.assetUrlMapper,
|
|
279
300
|
});
|
|
280
301
|
// NOTE Find and replace Entry Ref UIDs
|
|
302
|
+
cli_utilities_1.log.debug('Processing entry reference lookups for variant entry', this.config.context);
|
|
281
303
|
variantEntry = lookupEntries({
|
|
282
304
|
entry: variantEntry,
|
|
283
305
|
content_type: contentType,
|
|
@@ -285,10 +307,13 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
285
307
|
// NOTE: will remove term if term doesn't exists in taxonomy
|
|
286
308
|
// FIXME: Validate if taxonomy support available for variant entries,
|
|
287
309
|
// if not, feel free to remove this lookup flow.
|
|
310
|
+
cli_utilities_1.log.debug('Processing taxonomy term lookups for variant entry', this.config.context);
|
|
288
311
|
lookUpTerms(contentType.schema, variantEntry, this.taxonomies, this.config);
|
|
289
312
|
// update file fields of entry variants to support lookup asset logic
|
|
313
|
+
cli_utilities_1.log.debug('Updating file fields for variant entry', this.config.context);
|
|
290
314
|
this.updateFileFields(variantEntry);
|
|
291
315
|
// NOTE Find and replace asset's UID
|
|
316
|
+
cli_utilities_1.log.debug('Processing asset lookups for variant entry', this.config.context);
|
|
292
317
|
variantEntry = lookupAssets({
|
|
293
318
|
entry: variantEntry,
|
|
294
319
|
content_type: contentType,
|
|
@@ -303,6 +328,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
303
328
|
*/
|
|
304
329
|
updateFileFields(variantEntry) {
|
|
305
330
|
var _a, _b;
|
|
331
|
+
cli_utilities_1.log.debug(`Updating file fields for variant entry: ${variantEntry.uid}`, this.config.context);
|
|
306
332
|
const setValue = (currentObj, keys) => {
|
|
307
333
|
if (!currentObj || keys.length === 0)
|
|
308
334
|
return;
|
|
@@ -331,6 +357,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
331
357
|
}
|
|
332
358
|
};
|
|
333
359
|
const pathsToUpdate = ((_b = (_a = variantEntry === null || variantEntry === void 0 ? void 0 : variantEntry._metadata) === null || _a === void 0 ? void 0 : _a.references) === null || _b === void 0 ? void 0 : _b.filter((ref) => ref._content_type_uid === 'sys_assets').map((ref) => ref.path)) || [];
|
|
360
|
+
cli_utilities_1.log.debug(`Found ${pathsToUpdate.length} file field paths to update`, this.config.context);
|
|
334
361
|
pathsToUpdate.forEach((path) => setValue(variantEntry, path.split('.')));
|
|
335
362
|
}
|
|
336
363
|
/**
|
|
@@ -344,34 +371,36 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
344
371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
345
372
|
var _a;
|
|
346
373
|
const allPromise = [];
|
|
347
|
-
|
|
374
|
+
cli_utilities_1.log.info(`Publishing variant entries for entry uid '${entryUid}' of Content Type '${content_type}'`, this.config.context);
|
|
375
|
+
cli_utilities_1.log.debug(`Processing ${batch.length} variant entries for publishing`, this.config.context);
|
|
348
376
|
for (let [, variantEntry] of (0, entries_1.default)(batch)) {
|
|
349
377
|
const variantEntryUID = variantEntry.uid;
|
|
350
378
|
const oldVariantUid = variantEntry._variant._uid || '';
|
|
351
379
|
const newVariantUid = this.variantIdList[oldVariantUid];
|
|
352
380
|
if (!newVariantUid) {
|
|
353
|
-
|
|
381
|
+
cli_utilities_1.log.debug('Variant ID not found', this.config.context);
|
|
354
382
|
continue;
|
|
355
383
|
}
|
|
356
384
|
if (this.failedVariantEntries.has(variantEntryUID)) {
|
|
357
|
-
|
|
385
|
+
cli_utilities_1.log.debug(`Variant UID not found. Skipping entry variant publish for ${variantEntryUID}`, this.config.context);
|
|
358
386
|
continue;
|
|
359
387
|
}
|
|
360
388
|
if ((_a = this.environments) === null || _a === void 0 ? void 0 : _a.length) {
|
|
361
|
-
|
|
389
|
+
cli_utilities_1.log.debug('No environment found! Skipping entry variant publishing...', this.config.context);
|
|
362
390
|
return;
|
|
363
391
|
}
|
|
364
|
-
const onSuccess = ({ response, apiData: { entryUid, variantUid }
|
|
365
|
-
log(
|
|
392
|
+
const onSuccess = ({ response, apiData: { entryUid, variantUid } }) => {
|
|
393
|
+
cli_utilities_1.log.info(`Entry variant: '${variantUid}' of entry '${entryUid}' published on locales '${locales.join(',')}'`, this.config.context);
|
|
366
394
|
};
|
|
367
|
-
const onReject = ({ error, apiData: { entryUid, variantUid }
|
|
368
|
-
|
|
369
|
-
log(this.config, (0, utils_1.formatError)(error), 'error');
|
|
395
|
+
const onReject = ({ error, apiData: { entryUid, variantUid } }) => {
|
|
396
|
+
(0, cli_utilities_1.handleAndLogError)(error, this.config.context, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid} on locales '${locales.join(',')}'`);
|
|
370
397
|
};
|
|
371
398
|
const { environments, locales } = this.serializePublishEntries(variantEntry);
|
|
372
399
|
if ((environments === null || environments === void 0 ? void 0 : environments.length) === 0 || (locales === null || locales === void 0 ? void 0 : locales.length) === 0) {
|
|
400
|
+
cli_utilities_1.log.debug(`Skipping publish for variant ${newVariantUid} - no environments or locales`, this.config.context);
|
|
373
401
|
continue;
|
|
374
402
|
}
|
|
403
|
+
cli_utilities_1.log.debug(`Publishing variant ${newVariantUid} to environments: ${environments.join(', ')}, locales: ${locales.join(', ')}`, this.config.context);
|
|
375
404
|
const publishReq = {
|
|
376
405
|
entry: {
|
|
377
406
|
environments,
|
|
@@ -386,13 +415,13 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
386
415
|
}, {
|
|
387
416
|
reject: onReject.bind(this),
|
|
388
417
|
resolve: onSuccess.bind(this),
|
|
389
|
-
log:
|
|
418
|
+
log: cli_utilities_1.log,
|
|
390
419
|
variantUid: newVariantUid,
|
|
391
420
|
});
|
|
392
421
|
allPromise.push(promise);
|
|
393
422
|
}
|
|
394
423
|
yield Promise.allSettled(allPromise);
|
|
395
|
-
|
|
424
|
+
cli_utilities_1.log.info(`Published variant entries for entry uid '${entryUid}' of Content Type '${content_type}'`, this.config.context);
|
|
396
425
|
});
|
|
397
426
|
}
|
|
398
427
|
/**
|
|
@@ -401,12 +430,19 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
401
430
|
* @returns An object containing the serialized publish entries.
|
|
402
431
|
*/
|
|
403
432
|
serializePublishEntries(variantEntry) {
|
|
404
|
-
var _a;
|
|
433
|
+
var _a, _b;
|
|
434
|
+
cli_utilities_1.log.debug(`Serializing publish entries for variant: ${variantEntry.uid}`, this.config.context);
|
|
405
435
|
const requestObject = {
|
|
406
436
|
environments: [],
|
|
407
437
|
locales: [],
|
|
408
438
|
};
|
|
409
439
|
if (variantEntry.publish_details && ((_a = variantEntry.publish_details) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
440
|
+
cli_utilities_1.log.debug(`Processing ${variantEntry.publish_details.length} publish details`, this.config.context);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
cli_utilities_1.log.debug('No publish details found for variant entry', this.config.context);
|
|
444
|
+
}
|
|
445
|
+
if (variantEntry.publish_details && ((_b = variantEntry.publish_details) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
410
446
|
(0, forEach_1.default)(variantEntry.publish_details, (pubObject) => {
|
|
411
447
|
if (this.environments.hasOwnProperty(pubObject.environment) &&
|
|
412
448
|
(0, indexOf_1.default)(requestObject.environments, this.environments[pubObject.environment].name) === -1) {
|
|
@@ -417,6 +453,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
417
453
|
}
|
|
418
454
|
});
|
|
419
455
|
}
|
|
456
|
+
cli_utilities_1.log.debug(`Serialized publish data - environments: ${requestObject.environments.length}, locales: ${requestObject.locales.length}`, this.config.context);
|
|
420
457
|
return requestObject;
|
|
421
458
|
}
|
|
422
459
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* because it will create a circular dependency and cause the prepack/build command to fail.
|
|
4
4
|
* Therefore, we are duplicating the following types from the export.
|
|
5
5
|
*/
|
|
6
|
-
import { AnyProperty } from './utils';
|
|
6
|
+
import { AnyProperty, Context } from './utils';
|
|
7
7
|
export type Modules = 'stack' | 'assets' | 'locales' | 'environments' | 'extensions' | 'webhooks' | 'global-fields' | 'entries' | 'content-types' | 'custom-roles' | 'workflows' | 'labels' | 'marketplace-apps' | 'taxonomies' | 'personalize';
|
|
8
8
|
export type branch = {
|
|
9
9
|
uid: string;
|
|
@@ -13,6 +13,7 @@ export type masterLocale = {
|
|
|
13
13
|
code: string;
|
|
14
14
|
};
|
|
15
15
|
export interface DefaultConfig {
|
|
16
|
+
context: Context;
|
|
16
17
|
contentVersion: number;
|
|
17
18
|
versioning: boolean;
|
|
18
19
|
host: string;
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -5,3 +5,14 @@ export interface LogType {
|
|
|
5
5
|
(message: any): void;
|
|
6
6
|
(config: any, message: any, type: 'info' | 'error' | 'success'): void;
|
|
7
7
|
}
|
|
8
|
+
export interface Context {
|
|
9
|
+
command: string;
|
|
10
|
+
module: string;
|
|
11
|
+
userId: string | undefined;
|
|
12
|
+
email: string | undefined;
|
|
13
|
+
sessionId: string | undefined;
|
|
14
|
+
clientId?: string | undefined;
|
|
15
|
+
apiKey: string;
|
|
16
|
+
orgId: string;
|
|
17
|
+
authMethod?: string;
|
|
18
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.lookUpAttributes = void 0;
|
|
4
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
5
|
/**
|
|
5
6
|
* function to either modify the UID or eliminate it if the attribute is not created in the target project
|
|
6
7
|
* @param attributeRules
|
|
@@ -9,29 +10,44 @@ exports.lookUpAttributes = void 0;
|
|
|
9
10
|
*/
|
|
10
11
|
const lookUpAttributes = (attributeRules, attributesUid) => {
|
|
11
12
|
var _a;
|
|
13
|
+
cli_utilities_1.log.debug(`Looking up attributes in ${(attributeRules === null || attributeRules === void 0 ? void 0 : attributeRules.length) || 0} rules`);
|
|
14
|
+
cli_utilities_1.log.debug(`Available attribute mappings: ${Object.keys(attributesUid).length}`);
|
|
12
15
|
for (let index = 0; index < (attributeRules === null || attributeRules === void 0 ? void 0 : attributeRules.length); index++) {
|
|
13
16
|
const rule = attributeRules[index];
|
|
17
|
+
cli_utilities_1.log.debug(`Processing rule ${index + 1}/${attributeRules.length} of type: ${rule['__type']}`);
|
|
14
18
|
if (rule['__type'] === 'Rule') {
|
|
15
19
|
// Check if attribute reference exists in attributesUid
|
|
16
20
|
const attributeRef = (_a = rule.attribute) === null || _a === void 0 ? void 0 : _a.ref;
|
|
17
21
|
const attributeType = rule.attribute['__type'];
|
|
22
|
+
cli_utilities_1.log.debug(`Rule attribute type: ${attributeType}, reference: ${attributeRef}`);
|
|
18
23
|
// check if type is CustomAttributeReference
|
|
19
24
|
if (attributeType === 'CustomAttributeReference') {
|
|
20
25
|
if (attributeRef && attributesUid.hasOwnProperty(attributeRef) && attributesUid[attributeRef]) {
|
|
21
|
-
|
|
26
|
+
const newAttributeRef = attributesUid[attributeRef];
|
|
27
|
+
cli_utilities_1.log.debug(`Mapping attribute reference: ${attributeRef} -> ${newAttributeRef}`);
|
|
28
|
+
rule.attribute.ref = newAttributeRef;
|
|
22
29
|
}
|
|
23
30
|
else {
|
|
31
|
+
cli_utilities_1.log.warn(`Attribute reference not found in mapping: ${attributeRef}. Removing rule.`);
|
|
24
32
|
// Remove the rule if the attribute reference is not found
|
|
25
33
|
attributeRules.splice(index, 1);
|
|
26
34
|
--index;
|
|
27
35
|
}
|
|
28
36
|
}
|
|
37
|
+
else {
|
|
38
|
+
cli_utilities_1.log.debug(`Skipping non-custom attribute reference: ${attributeType}`);
|
|
39
|
+
}
|
|
29
40
|
}
|
|
30
41
|
else if (rule['__type'] === 'RuleCombination' && Array.isArray(rule.rules)) {
|
|
42
|
+
cli_utilities_1.log.debug(`Processing nested rule combination with ${rule.rules.length} sub-rules`);
|
|
31
43
|
// Recursively look up attributes in nested rule combinations
|
|
32
44
|
(0, exports.lookUpAttributes)(rule.rules, attributesUid);
|
|
33
45
|
}
|
|
46
|
+
else {
|
|
47
|
+
cli_utilities_1.log.debug(`Skipping rule of type: ${rule['__type']}`);
|
|
48
|
+
}
|
|
34
49
|
}
|
|
50
|
+
cli_utilities_1.log.debug(`Attribute lookup completed. Final rule count: ${attributeRules.length}`);
|
|
35
51
|
return attributeRules;
|
|
36
52
|
};
|
|
37
53
|
exports.lookUpAttributes = lookUpAttributes;
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.lookUpAudiences = void 0;
|
|
4
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
5
|
/**
|
|
5
6
|
* function for substituting an old audience UID with a new one or deleting the audience information if it does not exist
|
|
6
7
|
* @param audiences - {audiences} list of audience
|
|
7
8
|
* @param audiencesUid - {audiencesUid} audiences mapper data in format {<old-uid>: <new-uid>}
|
|
8
9
|
*/
|
|
9
10
|
function updateAudiences(audiences, audiencesUid) {
|
|
11
|
+
cli_utilities_1.log.debug(`Updating ${audiences.length} audiences`);
|
|
10
12
|
for (let audienceIndex = audiences.length - 1; audienceIndex >= 0; audienceIndex--) {
|
|
11
13
|
const audienceUid = audiences[audienceIndex];
|
|
12
14
|
if (audiencesUid.hasOwnProperty(audienceUid) && audiencesUid[audienceUid]) {
|
|
13
|
-
|
|
15
|
+
const newAudienceUid = audiencesUid[audienceUid];
|
|
16
|
+
cli_utilities_1.log.debug(`Mapping audience: ${audienceUid} -> ${newAudienceUid}`);
|
|
17
|
+
audiences[audienceIndex] = newAudienceUid;
|
|
14
18
|
}
|
|
15
19
|
else {
|
|
20
|
+
cli_utilities_1.log.warn(`Audience not found in mapping: ${audienceUid}. Removing from list.`);
|
|
16
21
|
audiences.splice(audienceIndex, 1);
|
|
17
22
|
}
|
|
18
23
|
}
|
|
24
|
+
cli_utilities_1.log.debug(`Updated audiences count: ${audiences.length}`);
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* function to either modify the UID or eliminate it if the audience is not created in the target project
|
|
@@ -24,37 +30,62 @@ function updateAudiences(audiences, audiencesUid) {
|
|
|
24
30
|
* @returns
|
|
25
31
|
*/
|
|
26
32
|
const lookUpAudiences = (experience, audiencesUid) => {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
33
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
34
|
+
cli_utilities_1.log.debug('Starting audience lookup for experience');
|
|
35
|
+
cli_utilities_1.log.debug(`Available audience mappings: ${(_a = Object.keys(audiencesUid)) === null || _a === void 0 ? void 0 : _a.length}`);
|
|
28
36
|
// Update experience variations
|
|
29
|
-
if ((
|
|
37
|
+
if ((_b = experience === null || experience === void 0 ? void 0 : experience.variations) === null || _b === void 0 ? void 0 : _b.length) {
|
|
38
|
+
cli_utilities_1.log.debug(`Processing ${experience.variations.length} experience variations`);
|
|
30
39
|
for (let index = experience.variations.length - 1; index >= 0; index--) {
|
|
31
40
|
const expVariations = experience.variations[index];
|
|
32
|
-
|
|
41
|
+
cli_utilities_1.log.debug(`Processing variation ${index + 1}/${experience.variations.length} of type: ${expVariations['__type']}`);
|
|
42
|
+
if (expVariations['__type'] === 'AudienceBasedVariation' && ((_c = expVariations === null || expVariations === void 0 ? void 0 : expVariations.audiences) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
43
|
+
cli_utilities_1.log.debug(`Found ${expVariations.audiences.length} audiences in AudienceBasedVariation`);
|
|
33
44
|
updateAudiences(expVariations.audiences, audiencesUid);
|
|
34
45
|
if (!expVariations.audiences.length) {
|
|
46
|
+
cli_utilities_1.log.warn('No audiences remaining after mapping. Removing variation.');
|
|
35
47
|
experience.variations.splice(index, 1);
|
|
36
48
|
}
|
|
37
49
|
}
|
|
50
|
+
else {
|
|
51
|
+
cli_utilities_1.log.debug(`Skipping variation of type: ${expVariations['__type']}`);
|
|
52
|
+
}
|
|
38
53
|
}
|
|
39
54
|
}
|
|
40
55
|
else if (experience.variants) {
|
|
56
|
+
cli_utilities_1.log.debug(`Processing ${experience.variants.length} experience variants`);
|
|
41
57
|
for (let index = experience.variants.length - 1; index >= 0; index--) {
|
|
42
58
|
const expVariations = experience.variants[index];
|
|
43
|
-
|
|
59
|
+
cli_utilities_1.log.debug(`Processing variant ${index + 1}/${experience.variants.length} of type: ${expVariations['__type']}`);
|
|
60
|
+
if (expVariations['__type'] === 'SegmentedVariant' && ((_d = expVariations === null || expVariations === void 0 ? void 0 : expVariations.audiences) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
61
|
+
cli_utilities_1.log.debug(`Found ${expVariations.audiences.length} audiences in SegmentedVariant`);
|
|
44
62
|
updateAudiences(expVariations.audiences, audiencesUid);
|
|
45
63
|
if (!expVariations.audiences.length) {
|
|
64
|
+
cli_utilities_1.log.warn('No audiences remaining after mapping. Removing variant.');
|
|
46
65
|
experience.variants.splice(index, 1);
|
|
47
66
|
}
|
|
48
67
|
}
|
|
68
|
+
else {
|
|
69
|
+
cli_utilities_1.log.debug(`Skipping variant of type: ${expVariations['__type']}`);
|
|
70
|
+
}
|
|
49
71
|
}
|
|
50
72
|
}
|
|
51
|
-
|
|
73
|
+
else {
|
|
74
|
+
cli_utilities_1.log.debug('No variations or variants found in experience');
|
|
75
|
+
}
|
|
76
|
+
if (((_e = experience === null || experience === void 0 ? void 0 : experience.targeting) === null || _e === void 0 ? void 0 : _e.hasOwnProperty('audience')) && ((_h = (_g = (_f = experience === null || experience === void 0 ? void 0 : experience.targeting) === null || _f === void 0 ? void 0 : _f.audience) === null || _g === void 0 ? void 0 : _g.audiences) === null || _h === void 0 ? void 0 : _h.length)) {
|
|
77
|
+
cli_utilities_1.log.debug(`Processing ${experience.targeting.audience.audiences.length} targeting audiences`);
|
|
52
78
|
// Update targeting audiences
|
|
53
79
|
updateAudiences(experience.targeting.audience.audiences, audiencesUid);
|
|
54
80
|
if (!experience.targeting.audience.audiences.length) {
|
|
81
|
+
cli_utilities_1.log.warn('No targeting audiences remaining after mapping. Removing targeting.');
|
|
55
82
|
experience.targeting = {};
|
|
56
83
|
}
|
|
57
84
|
}
|
|
85
|
+
else {
|
|
86
|
+
cli_utilities_1.log.debug('No targeting audiences found in experience');
|
|
87
|
+
}
|
|
88
|
+
cli_utilities_1.log.debug('Audience lookup completed for experience');
|
|
58
89
|
return experience;
|
|
59
90
|
};
|
|
60
91
|
exports.lookUpAudiences = lookUpAudiences;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.lookUpEvents = void 0;
|
|
4
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
5
|
/**
|
|
5
6
|
* function to either modify the UID or eliminate it if the event is not created in the target project
|
|
6
7
|
* @param experience - experience object
|
|
@@ -8,20 +9,32 @@ exports.lookUpEvents = void 0;
|
|
|
8
9
|
* @returns
|
|
9
10
|
*/
|
|
10
11
|
const lookUpEvents = (experience, eventsUid) => {
|
|
11
|
-
var _a, _b;
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
cli_utilities_1.log.debug('Starting event lookup for experience');
|
|
14
|
+
cli_utilities_1.log.debug(`Available event mappings: ${(_a = Object.keys(eventsUid)) === null || _a === void 0 ? void 0 : _a.length}`);
|
|
12
15
|
// Update events uid in experience metrics
|
|
13
|
-
if ((
|
|
14
|
-
|
|
16
|
+
if ((_b = experience === null || experience === void 0 ? void 0 : experience.metrics) === null || _b === void 0 ? void 0 : _b.length) {
|
|
17
|
+
cli_utilities_1.log.debug(`Processing ${experience.metrics.length} experience metrics`);
|
|
18
|
+
for (let metricIndex = ((_c = experience === null || experience === void 0 ? void 0 : experience.metrics) === null || _c === void 0 ? void 0 : _c.length) - 1; metricIndex >= 0; metricIndex--) {
|
|
15
19
|
const metric = experience === null || experience === void 0 ? void 0 : experience.metrics[metricIndex];
|
|
16
20
|
const eventUid = metric.event;
|
|
21
|
+
cli_utilities_1.log.debug(`Processing metric ${metricIndex + 1}/${experience.metrics.length} with event: ${eventUid}`);
|
|
17
22
|
if (eventsUid.hasOwnProperty(eventUid) && eventsUid[eventUid]) {
|
|
18
|
-
|
|
23
|
+
const newEventUid = eventsUid[eventUid];
|
|
24
|
+
cli_utilities_1.log.debug(`Mapping event: ${eventUid} -> ${newEventUid}`);
|
|
25
|
+
experience.metrics[metricIndex].event = newEventUid;
|
|
19
26
|
}
|
|
20
27
|
else {
|
|
28
|
+
cli_utilities_1.log.warn(`Event not found in mapping: ${eventUid}. Removing metric.`);
|
|
21
29
|
experience === null || experience === void 0 ? void 0 : experience.metrics.splice(metricIndex, 1);
|
|
22
30
|
}
|
|
23
31
|
}
|
|
32
|
+
cli_utilities_1.log.debug(`Final metrics count: ${experience.metrics.length}`);
|
|
24
33
|
}
|
|
34
|
+
else {
|
|
35
|
+
cli_utilities_1.log.debug('No metrics found in experience');
|
|
36
|
+
}
|
|
37
|
+
cli_utilities_1.log.debug('Event lookup completed for experience');
|
|
25
38
|
return experience;
|
|
26
39
|
};
|
|
27
40
|
exports.lookUpEvents = lookUpEvents;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AdapterHelper } from './adapter-helper';
|
|
2
2
|
import { HttpClient } from '@contentstack/cli-utilities';
|
|
3
|
-
import { ProjectStruct, Personalization, GetProjectsParams, CreateProjectInput, CreateAttributeInput, APIConfig, GetVariantGroupInput, EventStruct, AudienceStruct, AttributeStruct, CreateAudienceInput, CreateEventInput, CreateExperienceInput, ExperienceStruct, UpdateExperienceInput, CMSExperienceStruct, VariantAPIRes, APIResponse, VariantGroupStruct, VariantGroup, CreateExperienceVersionInput } from '../types';
|
|
3
|
+
import { ProjectStruct, Personalization, GetProjectsParams, CreateProjectInput, CreateAttributeInput, APIConfig, GetVariantGroupInput, EventStruct, AudienceStruct, AttributeStruct, CreateAudienceInput, CreateEventInput, CreateExperienceInput, ExperienceStruct, UpdateExperienceInput, CMSExperienceStruct, VariantAPIRes, APIResponse, VariantGroupStruct, VariantGroup, CreateExperienceVersionInput, ExportConfig } from '../types';
|
|
4
4
|
export declare class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> implements Personalization<T> {
|
|
5
|
+
exportConfig?: ExportConfig;
|
|
5
6
|
constructor(options: APIConfig);
|
|
6
7
|
init(): Promise<void>;
|
|
7
8
|
projects(options: GetProjectsParams): Promise<ProjectStruct[]>;
|