@contentstack/cli-variants 1.3.2 → 1.3.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.
- package/lib/import/variant-entries.js +11 -10
- package/lib/utils/personalization-api-adapter.js +12 -12
- package/lib/utils/variant-api-adapter.js +14 -32
- package/package.json +2 -2
- package/src/import/variant-entries.ts +13 -14
- package/src/utils/personalization-api-adapter.ts +12 -12
- package/src/utils/variant-api-adapter.ts +55 -49
|
@@ -91,6 +91,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
91
91
|
*/
|
|
92
92
|
import() {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
var _a, _b, _c;
|
|
94
95
|
const filePath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'data-for-variant-entry.json');
|
|
95
96
|
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
97
|
cli_utilities_1.log.debug(`Checking for variant entry data file: ${filePath}`, this.config.context);
|
|
@@ -130,10 +131,10 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
130
131
|
this.assetUidMapper = (utils_1.fsUtil.readFile(assetUidMapperPath, true) || {});
|
|
131
132
|
this.assetUrlMapper = (utils_1.fsUtil.readFile(assetUrlMapperPath, true) || {});
|
|
132
133
|
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);
|
|
134
|
+
cli_utilities_1.log.debug(`Loaded dependency data - Entries: ${(_a = Object.keys(this.entriesUidMapper)) === null || _a === void 0 ? void 0 : _a.length}, Assets: ${(_b = Object.keys(this.assetUidMapper)) === null || _b === void 0 ? void 0 : _b.length}, Taxonomies: ${(_c = Object.keys(this.taxonomies)) === null || _c === void 0 ? void 0 : _c.length}`, this.config.context);
|
|
134
135
|
// set the token
|
|
135
136
|
yield this.variantInstance.init();
|
|
136
|
-
cli_utilities_1.log.info(`Processing ${entriesForVariants.length} entries for variant import`, this.config.context);
|
|
137
|
+
cli_utilities_1.log.info(`Processing ${entriesForVariants === null || entriesForVariants === void 0 ? void 0 : entriesForVariants.length} entries for variant import`, this.config.context);
|
|
137
138
|
for (const entriesForVariant of entriesForVariants) {
|
|
138
139
|
yield this.importVariantEntries(entriesForVariant);
|
|
139
140
|
}
|
|
@@ -149,7 +150,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
149
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
151
|
const variantEntry = this.config.modules.variantEntry;
|
|
151
152
|
const { content_type, locale, entry_uid } = entriesForVariant;
|
|
152
|
-
cli_utilities_1.log.
|
|
153
|
+
cli_utilities_1.log.info(`Importing variant entries for: ${content_type}/${locale}/${entry_uid}`, this.config.context);
|
|
153
154
|
const ctConfig = this.config.modules['content-types'];
|
|
154
155
|
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'));
|
|
155
156
|
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));
|
|
@@ -159,7 +160,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
159
160
|
try {
|
|
160
161
|
const variantEntries = (yield fs.readChunkFiles.next());
|
|
161
162
|
if (variantEntries === null || variantEntries === void 0 ? void 0 : variantEntries.length) {
|
|
162
|
-
cli_utilities_1.log.
|
|
163
|
+
cli_utilities_1.log.info(`Processing batch of ${variantEntries.length} variant entries`, this.config.context);
|
|
163
164
|
yield this.handleConcurrency(contentType, variantEntries, entriesForVariant);
|
|
164
165
|
}
|
|
165
166
|
}
|
|
@@ -192,12 +193,12 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
192
193
|
const batches = (0, chunk_1.default)(variantEntries, variantEntryConfig.apiConcurrency || 5);
|
|
193
194
|
if ((0, isEmpty_1.default)(batches))
|
|
194
195
|
return;
|
|
195
|
-
cli_utilities_1.log.debug(`Starting concurrent processing for ${variantEntries.length} variant entries`, this.config.context);
|
|
196
|
+
cli_utilities_1.log.debug(`Starting concurrent processing for ${variantEntries === null || variantEntries === void 0 ? void 0 : variantEntries.length} variant entries`, this.config.context);
|
|
196
197
|
for (const [, batch] of (0, entries_1.default)(batches)) {
|
|
197
198
|
batchNo += 1;
|
|
198
199
|
const allPromise = [];
|
|
199
200
|
const start = Date.now();
|
|
200
|
-
cli_utilities_1.log.debug(`Processing batch ${batchNo}/${batches.length} with ${batch.length} variant entries`, this.config.context);
|
|
201
|
+
cli_utilities_1.log.debug(`Processing batch ${batchNo}/${batches === null || batches === void 0 ? void 0 : batches.length} with ${batch === null || batch === void 0 ? void 0 : batch.length} variant entries`, this.config.context);
|
|
201
202
|
for (let [, variantEntry] of (0, entries_1.default)(batch)) {
|
|
202
203
|
const onSuccess = ({ response, apiData: { entryUid, variantUid } }) => {
|
|
203
204
|
cli_utilities_1.log.info(`Created entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`, this.config.context);
|
|
@@ -357,7 +358,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
357
358
|
}
|
|
358
359
|
};
|
|
359
360
|
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);
|
|
361
|
+
cli_utilities_1.log.debug(`Found ${pathsToUpdate === null || pathsToUpdate === void 0 ? void 0 : pathsToUpdate.length} file field paths to update`, this.config.context);
|
|
361
362
|
pathsToUpdate.forEach((path) => setValue(variantEntry, path.split('.')));
|
|
362
363
|
}
|
|
363
364
|
/**
|
|
@@ -382,11 +383,11 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
382
383
|
continue;
|
|
383
384
|
}
|
|
384
385
|
if (this.failedVariantEntries.has(variantEntryUID)) {
|
|
385
|
-
cli_utilities_1.log.
|
|
386
|
+
cli_utilities_1.log.info(`Variant UID not found. Skipping entry variant publish for ${variantEntryUID}`, this.config.context);
|
|
386
387
|
continue;
|
|
387
388
|
}
|
|
388
389
|
if ((_a = this.environments) === null || _a === void 0 ? void 0 : _a.length) {
|
|
389
|
-
cli_utilities_1.log.
|
|
390
|
+
cli_utilities_1.log.info('No environment found! Skipping entry variant publishing...', this.config.context);
|
|
390
391
|
return;
|
|
391
392
|
}
|
|
392
393
|
const onSuccess = ({ response, apiData: { entryUid, variantUid } }) => {
|
|
@@ -397,7 +398,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
397
398
|
};
|
|
398
399
|
const { environments, locales } = this.serializePublishEntries(variantEntry);
|
|
399
400
|
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.
|
|
401
|
+
cli_utilities_1.log.info(`Skipping publish for variant ${newVariantUid} - no environments or locales`, this.config.context);
|
|
401
402
|
continue;
|
|
402
403
|
}
|
|
403
404
|
cli_utilities_1.log.debug(`Publishing variant ${newVariantUid} to environments: ${environments.join(', ')}, locales: ${locales.join(', ')}`, this.config.context);
|
|
@@ -85,7 +85,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
85
85
|
cli_utilities_1.log.debug(`Creating project: ${project.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
86
86
|
const data = yield this.apiClient.post('/projects', project);
|
|
87
87
|
const result = (yield this.handleVariantAPIRes(data));
|
|
88
|
-
cli_utilities_1.log.
|
|
88
|
+
cli_utilities_1.log.info(`Project created successfully: ${result === null || result === void 0 ? void 0 : result.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
89
89
|
return result;
|
|
90
90
|
});
|
|
91
91
|
}
|
|
@@ -104,7 +104,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
104
104
|
cli_utilities_1.log.debug(`Creating attribute: ${attribute.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
105
105
|
const data = yield this.apiClient.post('/attributes', attribute);
|
|
106
106
|
const result = (yield this.handleVariantAPIRes(data));
|
|
107
|
-
cli_utilities_1.log.
|
|
107
|
+
cli_utilities_1.log.info(`Attribute created successfully: ${(result === null || result === void 0 ? void 0 : result.name) || (result === null || result === void 0 ? void 0 : result.uid)}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
108
108
|
return result;
|
|
109
109
|
});
|
|
110
110
|
}
|
|
@@ -143,7 +143,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
143
143
|
}
|
|
144
144
|
const data = yield this.apiClient.get(getExperiencesVersionsEndPoint);
|
|
145
145
|
const result = (yield this.handleVariantAPIRes(data));
|
|
146
|
-
cli_utilities_1.log.
|
|
146
|
+
cli_utilities_1.log.info(`Experience versions fetched successfully for: ${experienceUid}`, (_f = this.exportConfig) === null || _f === void 0 ? void 0 : _f.context);
|
|
147
147
|
return result;
|
|
148
148
|
});
|
|
149
149
|
}
|
|
@@ -154,7 +154,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
154
154
|
const createExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`;
|
|
155
155
|
const data = yield this.apiClient.post(createExperiencesVersionsEndPoint, input);
|
|
156
156
|
const result = (yield this.handleVariantAPIRes(data));
|
|
157
|
-
cli_utilities_1.log.
|
|
157
|
+
cli_utilities_1.log.info(`Experience version created successfully for: ${experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
158
158
|
return result;
|
|
159
159
|
});
|
|
160
160
|
}
|
|
@@ -187,7 +187,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
187
187
|
.queryParams({ experience_uid: input.experienceUid })
|
|
188
188
|
.get(getVariantGroupEndPoint);
|
|
189
189
|
const result = (yield this.handleVariantAPIRes(data));
|
|
190
|
-
cli_utilities_1.log.debug(`Variant group fetched successfully for experience: ${input.experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
190
|
+
cli_utilities_1.log.debug(`Variant group fetched successfully for experience: ${input === null || input === void 0 ? void 0 : input.experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
191
191
|
return result;
|
|
192
192
|
}
|
|
193
193
|
else {
|
|
@@ -203,7 +203,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
203
203
|
const updateVariantGroupEndPoint = `/variant_groups/${input.uid}`;
|
|
204
204
|
const data = yield this.cmaAPIClient.put(updateVariantGroupEndPoint, input);
|
|
205
205
|
const result = (yield this.handleVariantAPIRes(data));
|
|
206
|
-
cli_utilities_1.log.debug(`Variant group updated successfully: ${input.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
206
|
+
cli_utilities_1.log.debug(`Variant group updated successfully: ${input === null || input === void 0 ? void 0 : input.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
207
207
|
return result;
|
|
208
208
|
}
|
|
209
209
|
else {
|
|
@@ -227,7 +227,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
227
227
|
cli_utilities_1.log.debug(`Creating event: ${event.key}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
228
228
|
const data = yield this.apiClient.post('/events', event);
|
|
229
229
|
const result = (yield this.handleVariantAPIRes(data));
|
|
230
|
-
cli_utilities_1.log.
|
|
230
|
+
cli_utilities_1.log.info(`Event created successfully: ${result === null || result === void 0 ? void 0 : result.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
231
231
|
return result;
|
|
232
232
|
});
|
|
233
233
|
}
|
|
@@ -247,7 +247,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
247
247
|
cli_utilities_1.log.debug('Fetching attributes from personalization API', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
248
248
|
const data = yield this.apiClient.get('/attributes');
|
|
249
249
|
const result = (yield this.handleVariantAPIRes(data));
|
|
250
|
-
cli_utilities_1.log.
|
|
250
|
+
cli_utilities_1.log.info(`Fetched ${(result === null || result === void 0 ? void 0 : result.length) || 0} attributes`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
251
251
|
return result;
|
|
252
252
|
});
|
|
253
253
|
}
|
|
@@ -265,7 +265,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
265
265
|
cli_utilities_1.log.debug(`Creating audience: ${audience.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
266
266
|
const data = yield this.apiClient.post('/audiences', audience);
|
|
267
267
|
const result = (yield this.handleVariantAPIRes(data));
|
|
268
|
-
cli_utilities_1.log.
|
|
268
|
+
cli_utilities_1.log.info(`Audience created successfully: ${(result === null || result === void 0 ? void 0 : result.name) || (result === null || result === void 0 ? void 0 : result.uid)}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
269
269
|
return result;
|
|
270
270
|
});
|
|
271
271
|
}
|
|
@@ -283,7 +283,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
283
283
|
cli_utilities_1.log.debug(`Creating experience: ${experience.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
284
284
|
const data = yield this.apiClient.post('/experiences', experience);
|
|
285
285
|
const result = (yield this.handleVariantAPIRes(data));
|
|
286
|
-
cli_utilities_1.log.
|
|
286
|
+
cli_utilities_1.log.info(`Experience created successfully: ${(result === null || result === void 0 ? void 0 : result.name) || (result === null || result === void 0 ? void 0 : result.uid)}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
287
287
|
return result;
|
|
288
288
|
});
|
|
289
289
|
}
|
|
@@ -299,7 +299,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
299
299
|
const updateCTInExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
|
|
300
300
|
const data = yield this.apiClient.post(updateCTInExpEndPoint, experience);
|
|
301
301
|
const result = (yield this.handleVariantAPIRes(data));
|
|
302
|
-
cli_utilities_1.log.
|
|
302
|
+
cli_utilities_1.log.info(`Content types updated successfully in experience: ${experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
303
303
|
return result;
|
|
304
304
|
});
|
|
305
305
|
}
|
|
@@ -315,7 +315,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
|
|
|
315
315
|
const getCTFromExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
|
|
316
316
|
const data = yield this.apiClient.get(getCTFromExpEndPoint);
|
|
317
317
|
const result = (yield this.handleVariantAPIRes(data));
|
|
318
|
-
cli_utilities_1.log.
|
|
318
|
+
cli_utilities_1.log.info(`Content types fetched successfully from experience: ${experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
319
319
|
return result;
|
|
320
320
|
});
|
|
321
321
|
}
|
|
@@ -40,7 +40,7 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
|
|
|
40
40
|
}
|
|
41
41
|
init() {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
var _a, _b, _c, _d
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
44
|
cli_utilities_1.log.debug('Initializing VariantHttpClient...', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
45
45
|
yield cli_utilities_1.authenticationHandler.getAuthDetails();
|
|
46
46
|
const token = cli_utilities_1.authenticationHandler.accessToken;
|
|
@@ -53,7 +53,6 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
|
|
|
53
53
|
cli_utilities_1.log.debug('Setting authtoken header', (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
|
|
54
54
|
this.apiClient.headers({ authtoken: token });
|
|
55
55
|
}
|
|
56
|
-
cli_utilities_1.log.debug('VariantHttpClient initialization completed', (_e = this.exportConfig) === null || _e === void 0 ? void 0 : _e.context);
|
|
57
56
|
});
|
|
58
57
|
}
|
|
59
58
|
variantEntry(options) {
|
|
@@ -171,28 +170,24 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
|
|
|
171
170
|
createVariantEntry(input, options, apiParams) {
|
|
172
171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
172
|
var _a, _b;
|
|
174
|
-
const { reject, resolve, variantUid
|
|
173
|
+
const { reject, resolve, variantUid } = apiParams;
|
|
175
174
|
const variantConfig = this.config.modules.variantEntry;
|
|
176
175
|
const { locale = variantConfig.query.locale || 'en-us', variant_id, entry_uid, content_type_uid } = options;
|
|
177
|
-
log.debug(`Creating variant entry for content type: ${content_type_uid}, entry: ${entry_uid}, variant: ${variant_id}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
176
|
+
cli_utilities_1.log.debug(`Creating variant entry for content type: ${content_type_uid}, entry: ${entry_uid}, variant: ${variant_id}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
178
177
|
let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/variants/${variant_id}?locale=${locale}`;
|
|
179
178
|
const query = this.constructQuery((0, omit_1.default)(variantConfig.query, ['locale']));
|
|
180
179
|
if (query) {
|
|
181
180
|
endpoint = endpoint.concat(query);
|
|
182
181
|
}
|
|
183
|
-
log.debug(`Making API call to: ${endpoint}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
182
|
+
cli_utilities_1.log.debug(`Making API call to: ${endpoint}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
184
183
|
const onSuccess = (response) => {
|
|
185
|
-
|
|
186
|
-
log.debug(`Variant entry created successfully: ${variantUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
187
|
-
resolve({ response, apiData: { variantUid, entryUid: entry_uid }, log });
|
|
184
|
+
resolve({ response, apiData: { variantUid, entryUid: entry_uid }, log: cli_utilities_1.log });
|
|
188
185
|
};
|
|
189
186
|
const onReject = (error) => {
|
|
190
|
-
var _a;
|
|
191
|
-
log.debug(`Failed to create variant entry: ${variantUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
192
187
|
reject({
|
|
193
188
|
error,
|
|
194
189
|
apiData: { variantUid, entryUid: entry_uid },
|
|
195
|
-
log,
|
|
190
|
+
log: cli_utilities_1.log,
|
|
196
191
|
});
|
|
197
192
|
};
|
|
198
193
|
try {
|
|
@@ -222,23 +217,23 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
|
|
|
222
217
|
publishVariantEntry(input, options, apiParams) {
|
|
223
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
224
219
|
var _a, _b;
|
|
225
|
-
const { reject, resolve,
|
|
220
|
+
const { reject, resolve, variantUid } = apiParams;
|
|
226
221
|
const { entry_uid, content_type_uid } = options;
|
|
227
|
-
log.debug(`Publishing variant entry for content type: ${content_type_uid}, entry: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
222
|
+
cli_utilities_1.log.debug(`Publishing variant entry for content type: ${content_type_uid}, entry: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
228
223
|
let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
|
|
229
|
-
log.debug(`Making API call to: ${endpoint}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
224
|
+
cli_utilities_1.log.debug(`Making API call to: ${endpoint}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
230
225
|
const onSuccess = (response) => {
|
|
231
226
|
var _a;
|
|
232
|
-
log.debug(`Variant entry published successfully: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
233
|
-
resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log });
|
|
227
|
+
cli_utilities_1.log.debug(`Variant entry published successfully: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
228
|
+
resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log: cli_utilities_1.log });
|
|
234
229
|
};
|
|
235
230
|
const onReject = (error) => {
|
|
236
231
|
var _a;
|
|
237
|
-
log.debug(`Failed to publish variant entry: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
232
|
+
cli_utilities_1.log.debug(`Failed to publish variant entry: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
238
233
|
reject({
|
|
239
234
|
error,
|
|
240
235
|
apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales },
|
|
241
|
-
log,
|
|
236
|
+
log: cli_utilities_1.log,
|
|
242
237
|
});
|
|
243
238
|
};
|
|
244
239
|
try {
|
|
@@ -275,9 +270,7 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
|
|
|
275
270
|
cli_utilities_1.log.debug(`API request failed with status: ${status}`, (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
|
|
276
271
|
// Refresh the access token if the response status is 401
|
|
277
272
|
yield cli_utilities_1.authenticationHandler.refreshAccessToken(res);
|
|
278
|
-
const errorMsg = (data === null || data === void 0 ? void 0 : data.errors)
|
|
279
|
-
? (0, error_helper_1.formatErrors)(data.errors)
|
|
280
|
-
: (data === null || data === void 0 ? void 0 : data.error_message) || (data === null || data === void 0 ? void 0 : data.message) || data;
|
|
273
|
+
const errorMsg = (data === null || data === void 0 ? void 0 : data.errors) ? (0, error_helper_1.formatErrors)(data.errors) : (data === null || data === void 0 ? void 0 : data.error_message) || (data === null || data === void 0 ? void 0 : data.message) || data;
|
|
281
274
|
cli_utilities_1.log.debug(`API error: ${errorMsg}`, (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
|
|
282
275
|
throw errorMsg;
|
|
283
276
|
});
|
|
@@ -287,38 +280,27 @@ exports.VariantHttpClient = VariantHttpClient;
|
|
|
287
280
|
class VariantManagementSDK extends adapter_helper_1.AdapterHelper {
|
|
288
281
|
init() {
|
|
289
282
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
var _a, _b;
|
|
291
|
-
cli_utilities_1.log.debug('Initializing VariantManagementSDK...', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
292
283
|
this.apiClient = yield (0, cli_utilities_1.managementSDKClient)(this.config);
|
|
293
|
-
cli_utilities_1.log.debug('VariantManagementSDK initialized successfully', (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
|
|
294
284
|
});
|
|
295
285
|
}
|
|
296
286
|
variantEntry(options) {
|
|
297
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
-
var _a;
|
|
299
|
-
cli_utilities_1.log.debug('VariantEntry method called (SDK placeholder implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
300
288
|
// TODO SDK implementation
|
|
301
289
|
return { entry: {} };
|
|
302
290
|
});
|
|
303
291
|
}
|
|
304
292
|
variantEntries(options) {
|
|
305
293
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
var _a;
|
|
307
|
-
cli_utilities_1.log.debug('VariantEntries method called (SDK placeholder implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
308
294
|
// TODO SDK implementation
|
|
309
295
|
return { entries: [{}] };
|
|
310
296
|
});
|
|
311
297
|
}
|
|
312
298
|
createVariantEntry(input, options, apiParams) {
|
|
313
|
-
var _a;
|
|
314
|
-
cli_utilities_1.log.debug('CreateVariantEntry method called (SDK placeholder implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
315
299
|
// FIXME placeholder
|
|
316
300
|
return Promise.resolve({});
|
|
317
301
|
}
|
|
318
302
|
handleVariantAPIRes(res) {
|
|
319
303
|
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
-
var _a;
|
|
321
|
-
cli_utilities_1.log.debug('HandleVariantAPIRes method called (SDK implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
|
|
322
304
|
return res.data;
|
|
323
305
|
});
|
|
324
306
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-variants",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Variants plugin",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"typescript": "^5.8.3"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@contentstack/cli-utilities": "~1.14.
|
|
30
|
+
"@contentstack/cli-utilities": "~1.14.1",
|
|
31
31
|
"@oclif/core": "^4.3.0",
|
|
32
32
|
"@oclif/plugin-help": "^6.2.28",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
@@ -140,16 +140,15 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
140
140
|
this.environments = (fsUtil.readFile(envPath, true) || {}) as Record<string, any>;
|
|
141
141
|
|
|
142
142
|
log.debug(
|
|
143
|
-
`Loaded dependency data - Entries: ${Object.keys(this.entriesUidMapper)
|
|
144
|
-
Object.keys(this.assetUidMapper)
|
|
145
|
-
}, Taxonomies: ${Object.keys(this.taxonomies)
|
|
143
|
+
`Loaded dependency data - Entries: ${Object.keys(this.entriesUidMapper)?.length}, Assets: ${
|
|
144
|
+
Object.keys(this.assetUidMapper)?.length
|
|
145
|
+
}, Taxonomies: ${Object.keys(this.taxonomies)?.length}`,
|
|
146
146
|
this.config.context,
|
|
147
147
|
);
|
|
148
148
|
|
|
149
149
|
// set the token
|
|
150
150
|
await this.variantInstance.init();
|
|
151
|
-
|
|
152
|
-
log.info(`Processing ${entriesForVariants.length} entries for variant import`, this.config.context);
|
|
151
|
+
log.info(`Processing ${entriesForVariants?.length} entries for variant import`, this.config.context);
|
|
153
152
|
for (const entriesForVariant of entriesForVariants) {
|
|
154
153
|
await this.importVariantEntries(entriesForVariant);
|
|
155
154
|
}
|
|
@@ -166,7 +165,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
166
165
|
const variantEntry = this.config.modules.variantEntry;
|
|
167
166
|
const { content_type, locale, entry_uid } = entriesForVariant;
|
|
168
167
|
|
|
169
|
-
log.
|
|
168
|
+
log.info(`Importing variant entries for: ${content_type}/${locale}/${entry_uid}`, this.config.context);
|
|
170
169
|
|
|
171
170
|
const ctConfig = this.config.modules['content-types'];
|
|
172
171
|
const contentType: ContentTypeStruct = JSON.parse(
|
|
@@ -195,7 +194,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
195
194
|
try {
|
|
196
195
|
const variantEntries = (await fs.readChunkFiles.next()) as VariantEntryStruct[];
|
|
197
196
|
if (variantEntries?.length) {
|
|
198
|
-
log.
|
|
197
|
+
log.info(`Processing batch of ${variantEntries.length} variant entries`, this.config.context);
|
|
199
198
|
await this.handleConcurrency(contentType, variantEntries, entriesForVariant);
|
|
200
199
|
}
|
|
201
200
|
} catch (error) {
|
|
@@ -234,7 +233,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
234
233
|
const batches = chunk(variantEntries, variantEntryConfig.apiConcurrency || 5);
|
|
235
234
|
if (isEmpty(batches)) return;
|
|
236
235
|
|
|
237
|
-
log.debug(`Starting concurrent processing for ${variantEntries
|
|
236
|
+
log.debug(`Starting concurrent processing for ${variantEntries?.length} variant entries`, this.config.context);
|
|
238
237
|
|
|
239
238
|
for (const [, batch] of entries(batches)) {
|
|
240
239
|
batchNo += 1;
|
|
@@ -242,7 +241,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
242
241
|
const start = Date.now();
|
|
243
242
|
|
|
244
243
|
log.debug(
|
|
245
|
-
`Processing batch ${batchNo}/${batches
|
|
244
|
+
`Processing batch ${batchNo}/${batches?.length} with ${batch?.length} variant entries`,
|
|
246
245
|
this.config.context,
|
|
247
246
|
);
|
|
248
247
|
|
|
@@ -302,7 +301,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
302
301
|
}
|
|
303
302
|
|
|
304
303
|
// NOTE Handle the API response here
|
|
305
|
-
log.debug(`Waiting for ${allPromise.length} variant entry creation promises to complete`, this.config.context);
|
|
304
|
+
log.debug(`Waiting for ${allPromise.length} variant entry creation promises to complete`, this.config.context);
|
|
306
305
|
await Promise.allSettled(allPromise);
|
|
307
306
|
log.debug(`Batch ${batchNo} creation completed`, this.config.context);
|
|
308
307
|
|
|
@@ -455,7 +454,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
455
454
|
?.filter((ref: any) => ref._content_type_uid === 'sys_assets')
|
|
456
455
|
.map((ref: any) => ref.path) || [];
|
|
457
456
|
|
|
458
|
-
log.debug(`Found ${pathsToUpdate
|
|
457
|
+
log.debug(`Found ${pathsToUpdate?.length} file field paths to update`, this.config.context);
|
|
459
458
|
pathsToUpdate.forEach((path: string) => setValue(variantEntry, path.split('.')));
|
|
460
459
|
}
|
|
461
460
|
|
|
@@ -485,12 +484,12 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
485
484
|
}
|
|
486
485
|
|
|
487
486
|
if (this.failedVariantEntries.has(variantEntryUID)) {
|
|
488
|
-
log.
|
|
487
|
+
log.info(`Variant UID not found. Skipping entry variant publish for ${variantEntryUID}`, this.config.context);
|
|
489
488
|
continue;
|
|
490
489
|
}
|
|
491
490
|
|
|
492
491
|
if (this.environments?.length) {
|
|
493
|
-
log.
|
|
492
|
+
log.info('No environment found! Skipping entry variant publishing...', this.config.context);
|
|
494
493
|
return;
|
|
495
494
|
}
|
|
496
495
|
|
|
@@ -510,7 +509,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
|
|
|
510
509
|
|
|
511
510
|
const { environments, locales } = this.serializePublishEntries(variantEntry);
|
|
512
511
|
if (environments?.length === 0 || locales?.length === 0) {
|
|
513
|
-
log.
|
|
512
|
+
log.info(`Skipping publish for variant ${newVariantUid} - no environments or locales`, this.config.context);
|
|
514
513
|
continue;
|
|
515
514
|
}
|
|
516
515
|
|
|
@@ -84,7 +84,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
84
84
|
log.debug(`Creating project: ${project.name}`, this.exportConfig?.context );
|
|
85
85
|
const data = await this.apiClient.post<ProjectStruct>('/projects', project);
|
|
86
86
|
const result = (await this.handleVariantAPIRes(data)) as ProjectStruct;
|
|
87
|
-
log.
|
|
87
|
+
log.info(`Project created successfully: ${result?.uid}`, this.exportConfig?.context );
|
|
88
88
|
return result;
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -101,7 +101,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
101
101
|
log.debug(`Creating attribute: ${attribute.name}`, this.exportConfig?.context );
|
|
102
102
|
const data = await this.apiClient.post<AttributeStruct>('/attributes', attribute);
|
|
103
103
|
const result = (await this.handleVariantAPIRes(data)) as AttributeStruct;
|
|
104
|
-
log.
|
|
104
|
+
log.info(`Attribute created successfully: ${result?.name || result?.uid}`, this.exportConfig?.context );
|
|
105
105
|
return result;
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -134,7 +134,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
134
134
|
}
|
|
135
135
|
const data = await this.apiClient.get(getExperiencesVersionsEndPoint);
|
|
136
136
|
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct;
|
|
137
|
-
log.
|
|
137
|
+
log.info(`Experience versions fetched successfully for: ${experienceUid}`, this.exportConfig?.context );
|
|
138
138
|
return result;
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -146,7 +146,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
146
146
|
const createExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`;
|
|
147
147
|
const data = await this.apiClient.post(createExperiencesVersionsEndPoint, input);
|
|
148
148
|
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct;
|
|
149
|
-
log.
|
|
149
|
+
log.info(`Experience version created successfully for: ${experienceUid}`, this.exportConfig?.context );
|
|
150
150
|
return result;
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -176,7 +176,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
176
176
|
.queryParams({ experience_uid: input.experienceUid })
|
|
177
177
|
.get(getVariantGroupEndPoint);
|
|
178
178
|
const result = (await this.handleVariantAPIRes(data)) as VariantGroupStruct;
|
|
179
|
-
log.debug(`Variant group fetched successfully for experience: ${input
|
|
179
|
+
log.debug(`Variant group fetched successfully for experience: ${input?.experienceUid}`, this.exportConfig?.context );
|
|
180
180
|
return result;
|
|
181
181
|
} else {
|
|
182
182
|
log.debug('CMA API client not available for variant group fetch', this.exportConfig?.context );
|
|
@@ -189,7 +189,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
189
189
|
const updateVariantGroupEndPoint = `/variant_groups/${input.uid}`;
|
|
190
190
|
const data = await this.cmaAPIClient.put(updateVariantGroupEndPoint, input);
|
|
191
191
|
const result = (await this.handleVariantAPIRes(data)) as VariantGroup;
|
|
192
|
-
log.debug(`Variant group updated successfully: ${input
|
|
192
|
+
log.debug(`Variant group updated successfully: ${input?.uid}`, this.exportConfig?.context );
|
|
193
193
|
return result;
|
|
194
194
|
} else {
|
|
195
195
|
log.debug('CMA API client not available for variant group update', this.exportConfig?.context );
|
|
@@ -208,7 +208,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
208
208
|
log.debug(`Creating event: ${event.key}`, this.exportConfig?.context );
|
|
209
209
|
const data = await this.apiClient.post<EventStruct>('/events', event);
|
|
210
210
|
const result = (await this.handleVariantAPIRes(data)) as EventStruct;
|
|
211
|
-
log.
|
|
211
|
+
log.info(`Event created successfully: ${result?.uid}`, this.exportConfig?.context );
|
|
212
212
|
return result;
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -224,7 +224,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
224
224
|
log.debug('Fetching attributes from personalization API', this.exportConfig?.context );
|
|
225
225
|
const data = await this.apiClient.get<AttributeStruct>('/attributes');
|
|
226
226
|
const result = (await this.handleVariantAPIRes(data)) as AttributeStruct[];
|
|
227
|
-
log.
|
|
227
|
+
log.info(`Fetched ${result?.length || 0} attributes`, this.exportConfig?.context );
|
|
228
228
|
return result;
|
|
229
229
|
}
|
|
230
230
|
|
|
@@ -240,7 +240,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
240
240
|
log.debug(`Creating audience: ${audience.name}`, this.exportConfig?.context );
|
|
241
241
|
const data = await this.apiClient.post<AudienceStruct>('/audiences', audience);
|
|
242
242
|
const result = (await this.handleVariantAPIRes(data)) as AudienceStruct;
|
|
243
|
-
log.
|
|
243
|
+
log.info(`Audience created successfully: ${result?.name || result?.uid}`, this.exportConfig?.context );
|
|
244
244
|
return result;
|
|
245
245
|
}
|
|
246
246
|
|
|
@@ -256,7 +256,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
256
256
|
log.debug(`Creating experience: ${experience.name}`, this.exportConfig?.context );
|
|
257
257
|
const data = await this.apiClient.post<ExperienceStruct>('/experiences', experience);
|
|
258
258
|
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct;
|
|
259
|
-
log.
|
|
259
|
+
log.info(`Experience created successfully: ${result?.name || result?.uid}`, this.exportConfig?.context );
|
|
260
260
|
return result;
|
|
261
261
|
}
|
|
262
262
|
|
|
@@ -273,7 +273,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
273
273
|
const updateCTInExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
|
|
274
274
|
const data = await this.apiClient.post<CMSExperienceStruct>(updateCTInExpEndPoint, experience);
|
|
275
275
|
const result = (await this.handleVariantAPIRes(data)) as CMSExperienceStruct;
|
|
276
|
-
log.
|
|
276
|
+
log.info(`Content types updated successfully in experience: ${experienceUid}`, this.exportConfig?.context );
|
|
277
277
|
return result;
|
|
278
278
|
}
|
|
279
279
|
|
|
@@ -287,7 +287,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
|
|
|
287
287
|
const getCTFromExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
|
|
288
288
|
const data = await this.apiClient.get<CMSExperienceStruct>(getCTFromExpEndPoint);
|
|
289
289
|
const result = (await this.handleVariantAPIRes(data)) as CMSExperienceStruct;
|
|
290
|
-
log.
|
|
290
|
+
log.info(`Content types fetched successfully from experience: ${experienceUid}`, this.exportConfig?.context );
|
|
291
291
|
return result;
|
|
292
292
|
}
|
|
293
293
|
|
|
@@ -39,23 +39,24 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
39
39
|
super(config, options);
|
|
40
40
|
this.baseURL = config.baseURL?.includes('http') ? `${config.baseURL}/v3` : `https://${config.baseURL}/v3`;
|
|
41
41
|
this.apiClient.baseUrl(this.baseURL);
|
|
42
|
-
log.debug(`VariantHttpClient initialized with base URL: ${this.baseURL}`, this.exportConfig?.context
|
|
42
|
+
log.debug(`VariantHttpClient initialized with base URL: ${this.baseURL}`, this.exportConfig?.context);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async init(): Promise<void> {
|
|
46
|
-
log.debug('Initializing VariantHttpClient...', this.exportConfig?.context
|
|
46
|
+
log.debug('Initializing VariantHttpClient...', this.exportConfig?.context);
|
|
47
47
|
await authenticationHandler.getAuthDetails();
|
|
48
48
|
const token = authenticationHandler.accessToken;
|
|
49
|
-
log.debug(
|
|
50
|
-
|
|
49
|
+
log.debug(
|
|
50
|
+
`Authentication type: ${authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`,
|
|
51
|
+
this.exportConfig?.context,
|
|
52
|
+
);
|
|
51
53
|
if (authenticationHandler.isOauthEnabled) {
|
|
52
|
-
log.debug('Setting OAuth authorization header', this.exportConfig?.context
|
|
54
|
+
log.debug('Setting OAuth authorization header', this.exportConfig?.context);
|
|
53
55
|
this.apiClient.headers({ authorization: token });
|
|
54
56
|
} else {
|
|
55
|
-
log.debug('Setting authtoken header', this.exportConfig?.context
|
|
57
|
+
log.debug('Setting authtoken header', this.exportConfig?.context);
|
|
56
58
|
this.apiClient.headers({ authtoken: token });
|
|
57
59
|
}
|
|
58
|
-
log.debug('VariantHttpClient initialization completed', this.exportConfig?.context );
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
async variantEntry(options: VariantOptions) {
|
|
@@ -96,22 +97,28 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
96
97
|
include_publish_details = variantConfig.query.include_publish_details || true,
|
|
97
98
|
} = options;
|
|
98
99
|
|
|
99
|
-
log.debug(
|
|
100
|
-
|
|
100
|
+
log.debug(
|
|
101
|
+
`Fetching variant entries for content type: ${content_type_uid}, entry: ${entry_uid}, locale: ${locale}`,
|
|
102
|
+
this.exportConfig?.context,
|
|
103
|
+
);
|
|
104
|
+
log.debug(
|
|
105
|
+
`Query parameters - skip: ${skip}, limit: ${limit}, include_variant: ${include_variant}, include_count: ${include_count}, include_publish_details: ${include_publish_details}`,
|
|
106
|
+
this.exportConfig?.context,
|
|
107
|
+
);
|
|
101
108
|
|
|
102
109
|
if (variantConfig.serveMockData && callback) {
|
|
103
|
-
log.debug('Using mock data for variant entries', this.exportConfig?.context
|
|
110
|
+
log.debug('Using mock data for variant entries', this.exportConfig?.context);
|
|
104
111
|
let data = [] as Record<string, any>[];
|
|
105
112
|
|
|
106
113
|
if (existsSync(variantConfig.mockDataPath)) {
|
|
107
|
-
log.debug(`Loading mock data from: ${variantConfig.mockDataPath}`, this.exportConfig?.context
|
|
114
|
+
log.debug(`Loading mock data from: ${variantConfig.mockDataPath}`, this.exportConfig?.context);
|
|
108
115
|
data = require(variantConfig.mockDataPath) as Record<string, any>[];
|
|
109
116
|
}
|
|
110
117
|
callback(data);
|
|
111
118
|
return;
|
|
112
119
|
}
|
|
113
120
|
if (!locale) {
|
|
114
|
-
log.debug('No locale provided, skipping variant entries fetch', this.exportConfig?.context
|
|
121
|
+
log.debug('No locale provided, skipping variant entries fetch', this.exportConfig?.context);
|
|
115
122
|
return;
|
|
116
123
|
}
|
|
117
124
|
|
|
@@ -153,19 +160,22 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
153
160
|
endpoint = endpoint.concat(query);
|
|
154
161
|
}
|
|
155
162
|
|
|
156
|
-
log.debug(`Making API call to: ${endpoint}`, this.exportConfig?.context
|
|
163
|
+
log.debug(`Making API call to: ${endpoint}`, this.exportConfig?.context);
|
|
157
164
|
const data = await this.apiClient.get(endpoint);
|
|
158
165
|
const response = (await this.handleVariantAPIRes(data)) as { entries: VariantEntryStruct[]; count: number };
|
|
159
|
-
|
|
166
|
+
|
|
160
167
|
if (response?.entries?.length) {
|
|
161
|
-
log.debug(
|
|
168
|
+
log.debug(
|
|
169
|
+
`Received ${response.entries?.length} variant entries out of total ${response.count}`,
|
|
170
|
+
this.exportConfig?.context,
|
|
171
|
+
);
|
|
162
172
|
}
|
|
163
173
|
|
|
164
174
|
if (callback) {
|
|
165
|
-
log.debug('Executing callback with variant entries', this.exportConfig?.context
|
|
175
|
+
log.debug('Executing callback with variant entries', this.exportConfig?.context);
|
|
166
176
|
callback(response.entries);
|
|
167
177
|
} else {
|
|
168
|
-
log.debug('Adding variant entries to collection', this.exportConfig?.context
|
|
178
|
+
log.debug('Adding variant entries to collection', this.exportConfig?.context);
|
|
169
179
|
entries = entries.concat(response.entries);
|
|
170
180
|
}
|
|
171
181
|
|
|
@@ -206,12 +216,15 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
206
216
|
options: CreateVariantEntryOptions,
|
|
207
217
|
apiParams: Record<string, any>,
|
|
208
218
|
): Promise<VariantEntryStruct | string | void> {
|
|
209
|
-
const { reject, resolve, variantUid
|
|
219
|
+
const { reject, resolve, variantUid } = apiParams;
|
|
210
220
|
const variantConfig = (this.config as ImportConfig).modules.variantEntry;
|
|
211
221
|
const { locale = variantConfig.query.locale || 'en-us', variant_id, entry_uid, content_type_uid } = options;
|
|
212
|
-
|
|
213
|
-
log.debug(
|
|
214
|
-
|
|
222
|
+
|
|
223
|
+
log.debug(
|
|
224
|
+
`Creating variant entry for content type: ${content_type_uid}, entry: ${entry_uid}, variant: ${variant_id}`,
|
|
225
|
+
this.exportConfig?.context,
|
|
226
|
+
);
|
|
227
|
+
|
|
215
228
|
let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/variants/${variant_id}?locale=${locale}`;
|
|
216
229
|
|
|
217
230
|
const query = this.constructQuery(omit(variantConfig.query, ['locale']));
|
|
@@ -220,14 +233,12 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
220
233
|
endpoint = endpoint.concat(query);
|
|
221
234
|
}
|
|
222
235
|
|
|
223
|
-
log.debug(`Making API call to: ${endpoint}`, this.exportConfig?.context
|
|
236
|
+
log.debug(`Making API call to: ${endpoint}`, this.exportConfig?.context);
|
|
224
237
|
|
|
225
238
|
const onSuccess = (response: any) => {
|
|
226
|
-
log.debug(`Variant entry created successfully: ${variantUid}`, this.exportConfig?.context );
|
|
227
239
|
resolve({ response, apiData: { variantUid, entryUid: entry_uid }, log });
|
|
228
240
|
};
|
|
229
241
|
const onReject = (error: any) => {
|
|
230
|
-
log.debug(`Failed to create variant entry: ${variantUid}`, this.exportConfig?.context );
|
|
231
242
|
reject({
|
|
232
243
|
error,
|
|
233
244
|
apiData: { variantUid, entryUid: entry_uid },
|
|
@@ -263,14 +274,17 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
263
274
|
options: PublishVariantEntryOptions,
|
|
264
275
|
apiParams: Record<string, any>,
|
|
265
276
|
) {
|
|
266
|
-
const { reject, resolve,
|
|
277
|
+
const { reject, resolve, variantUid } = apiParams;
|
|
267
278
|
const { entry_uid, content_type_uid } = options;
|
|
268
|
-
|
|
269
|
-
log.debug(
|
|
270
|
-
|
|
279
|
+
|
|
280
|
+
log.debug(
|
|
281
|
+
`Publishing variant entry for content type: ${content_type_uid}, entry: ${entry_uid}`,
|
|
282
|
+
this.exportConfig?.context,
|
|
283
|
+
);
|
|
284
|
+
|
|
271
285
|
let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
|
|
272
286
|
|
|
273
|
-
log.debug(`Making API call to: ${endpoint}`, this.exportConfig?.context
|
|
287
|
+
log.debug(`Making API call to: ${endpoint}`, this.exportConfig?.context);
|
|
274
288
|
|
|
275
289
|
const onSuccess = (response: any) => {
|
|
276
290
|
log.debug(`Variant entry published successfully: ${entry_uid}`, this.exportConfig?.context );
|
|
@@ -310,22 +324,20 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
310
324
|
res: APIResponse,
|
|
311
325
|
): Promise<VariantEntryStruct | { entries: VariantEntryStruct[]; count: number } | string | any> {
|
|
312
326
|
const { status, data } = res;
|
|
313
|
-
log.debug(`API response status: ${status}`, this.exportConfig?.context
|
|
327
|
+
log.debug(`API response status: ${status}`, this.exportConfig?.context);
|
|
314
328
|
|
|
315
329
|
if (status >= 200 && status < 300) {
|
|
316
|
-
log.debug('API request successful', this.exportConfig?.context
|
|
330
|
+
log.debug('API request successful', this.exportConfig?.context);
|
|
317
331
|
return data;
|
|
318
332
|
}
|
|
319
333
|
|
|
320
|
-
log.debug(`API request failed with status: ${status}`, this.exportConfig?.context
|
|
334
|
+
log.debug(`API request failed with status: ${status}`, this.exportConfig?.context);
|
|
321
335
|
// Refresh the access token if the response status is 401
|
|
322
336
|
await authenticationHandler.refreshAccessToken(res);
|
|
323
337
|
|
|
324
|
-
const errorMsg = data?.errors
|
|
325
|
-
? formatErrors(data.errors)
|
|
326
|
-
: data?.error_message || data?.message || data;
|
|
338
|
+
const errorMsg = data?.errors ? formatErrors(data.errors) : data?.error_message || data?.message || data;
|
|
327
339
|
|
|
328
|
-
log.debug(`API error: ${errorMsg}`, this.exportConfig?.context
|
|
340
|
+
log.debug(`API error: ${errorMsg}`, this.exportConfig?.context);
|
|
329
341
|
throw errorMsg;
|
|
330
342
|
}
|
|
331
343
|
}
|
|
@@ -338,19 +350,15 @@ export class VariantManagementSDK<T>
|
|
|
338
350
|
public exportConfig?: any;
|
|
339
351
|
|
|
340
352
|
async init(): Promise<void> {
|
|
341
|
-
log.debug('Initializing VariantManagementSDK...', this.exportConfig?.context );
|
|
342
353
|
this.apiClient = await managementSDKClient(this.config);
|
|
343
|
-
log.debug('VariantManagementSDK initialized successfully', this.exportConfig?.context );
|
|
344
354
|
}
|
|
345
355
|
|
|
346
356
|
async variantEntry(options: VariantOptions) {
|
|
347
|
-
log.debug('VariantEntry method called (SDK placeholder implementation)', this.exportConfig?.context );
|
|
348
357
|
// TODO SDK implementation
|
|
349
358
|
return { entry: {} };
|
|
350
359
|
}
|
|
351
360
|
|
|
352
361
|
async variantEntries(options: VariantsOption) {
|
|
353
|
-
log.debug('VariantEntries method called (SDK placeholder implementation)', this.exportConfig?.context );
|
|
354
362
|
// TODO SDK implementation
|
|
355
363
|
return { entries: [{}] };
|
|
356
364
|
}
|
|
@@ -360,7 +368,6 @@ export class VariantManagementSDK<T>
|
|
|
360
368
|
options: CreateVariantEntryOptions,
|
|
361
369
|
apiParams: Record<string, any>,
|
|
362
370
|
): Promise<VariantEntryStruct | string | void> {
|
|
363
|
-
log.debug('CreateVariantEntry method called (SDK placeholder implementation)', this.exportConfig?.context );
|
|
364
371
|
// FIXME placeholder
|
|
365
372
|
return Promise.resolve({} as VariantEntryStruct);
|
|
366
373
|
}
|
|
@@ -368,16 +375,15 @@ export class VariantManagementSDK<T>
|
|
|
368
375
|
async handleVariantAPIRes(
|
|
369
376
|
res: APIResponse,
|
|
370
377
|
): Promise<VariantEntryStruct | { entries: VariantEntryStruct[]; count: number } | string> {
|
|
371
|
-
log.debug('HandleVariantAPIRes method called (SDK implementation)', this.exportConfig?.context );
|
|
372
378
|
return res.data;
|
|
373
379
|
}
|
|
374
380
|
|
|
375
381
|
constructQuery(query: Record<string, any>): string | void {
|
|
376
|
-
log.debug('ConstructQuery method called (SDK placeholder implementation)', this.exportConfig?.context
|
|
382
|
+
log.debug('ConstructQuery method called (SDK placeholder implementation)', this.exportConfig?.context);
|
|
377
383
|
}
|
|
378
384
|
|
|
379
385
|
async delay(ms: number): Promise<void> {
|
|
380
|
-
log.debug(`Delay method called for ${ms}ms (SDK placeholder implementation)`, this.exportConfig?.context
|
|
386
|
+
log.debug(`Delay method called for ${ms}ms (SDK placeholder implementation)`, this.exportConfig?.context);
|
|
381
387
|
}
|
|
382
388
|
}
|
|
383
389
|
|
|
@@ -392,20 +398,20 @@ export class VariantAdapter<T> {
|
|
|
392
398
|
config: APIConfig & AdapterType<T, (APIConfig & AnyProperty) | ContentstackConfig>,
|
|
393
399
|
options?: HttpClientOptions,
|
|
394
400
|
) {
|
|
395
|
-
log.debug('Initializing VariantAdapter...', this.exportConfig?.context
|
|
396
|
-
|
|
401
|
+
log.debug('Initializing VariantAdapter...', this.exportConfig?.context);
|
|
402
|
+
|
|
397
403
|
if (config.httpClient) {
|
|
398
|
-
log.debug('Using HTTP client variant instance', this.exportConfig?.context
|
|
404
|
+
log.debug('Using HTTP client variant instance', this.exportConfig?.context);
|
|
399
405
|
const { httpClient, Adapter, ...restConfig } = config;
|
|
400
406
|
this.variantInstance = new Adapter(restConfig, options);
|
|
401
407
|
} else {
|
|
402
|
-
log.debug('Using SDK variant instance', this.exportConfig?.context
|
|
408
|
+
log.debug('Using SDK variant instance', this.exportConfig?.context);
|
|
403
409
|
const { Adapter, ...restConfig } = config;
|
|
404
410
|
this.variantInstance = new Adapter(restConfig);
|
|
405
411
|
}
|
|
406
412
|
|
|
407
413
|
this.messages = messages;
|
|
408
|
-
log.debug('VariantAdapter initialized successfully', this.exportConfig?.context
|
|
414
|
+
log.debug('VariantAdapter initialized successfully', this.exportConfig?.context);
|
|
409
415
|
}
|
|
410
416
|
}
|
|
411
417
|
|