Skip to content

Commit c6c2d8a

Browse files
authored
Merge pull request #2110 from contentstack/fix/DX-3525
fix: variant entries creation issue
2 parents ed6221c + 02b7255 commit c6c2d8a

9 files changed

Lines changed: 108 additions & 119 deletions

File tree

.github/workflows/secrets-scan.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

CODEOWNERS

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
* @contentstack/security-admin
1+
* @contentstack/devex-pr-reviewers
2+
3+
.github/workflows/sca-scan.yml @contentstack/security-admin
4+
5+
.github/workflows/codeql-anaylsis.yml @contentstack/security-admin
6+
7+
**/.snyk @contentstack/security-admin
8+
9+
.github/workflows/policy-scan.yml @contentstack/security-admin
10+
11+
.github/workflows/issues-jira.yml @contentstack/security-admin

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@contentstack/cli-command": "~1.6.1",
1010
"@contentstack/cli-utilities": "~1.14.1",
1111
"@contentstack/management": "~1.22.0",
12-
"@contentstack/cli-variants": "~1.3.1",
12+
"@contentstack/cli-variants": "~1.3.3",
1313
"@oclif/core": "^4.3.0",
1414
"big-json": "^3.2.0",
1515
"bluebird": "^3.7.2",

packages/contentstack-import/src/import/module-importer.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ModuleImporter {
8686
}
8787

8888
async import() {
89-
log.info(`Starting to import content version ${this.importConfig.contentVersion}`);
89+
log.info(`Starting to import content version ${this.importConfig.contentVersion}`, this.importConfig.context);
9090

9191
// checks for single module or all modules
9292
if (this.importConfig.singleModuleImport) {
@@ -96,7 +96,7 @@ class ModuleImporter {
9696
}
9797

9898
async importByModuleByName(moduleName: Modules) {
99-
log.info(`Starting import of ${moduleName} module`);
99+
log.info(`Starting import of ${moduleName} module`, this.importConfig.context);
100100
// import the modules by name
101101
// calls the module runner which inturn calls the module itself
102102
// NOTE: Implement a mechanism to determine whether module is new or old
@@ -122,7 +122,10 @@ class ModuleImporter {
122122
// use the algorithm to determine the parallel and sequential execution of modules
123123
for (let moduleName of this.importConfig.modules.types) {
124124
if (this.importConfig.globalModules.includes(moduleName) && this.importConfig['exclude-global-modules']) {
125-
log.warn(`Skipping the import of the global module '${moduleName}', as it already exists in the stack.`);
125+
log.warn(
126+
`Skipping the import of the global module '${moduleName}', as it already exists in the stack.`,
127+
this.importConfig.context,
128+
);
126129
continue;
127130
}
128131
await this.importByModuleByName(moduleName);
@@ -178,9 +181,9 @@ class ModuleImporter {
178181
});
179182
}
180183
args.push('--modules', 'field-rules');
181-
log.info('Starting audit process');
184+
log.info('Starting audit process', this.importConfig.context);
182185
const result = await AuditFix.run(args);
183-
log.info('Audit process completed');
186+
log.info('Audit process completed', this.importConfig.context);
184187

185188
if (result) {
186189
const { hasFix, config } = result;
@@ -206,7 +209,7 @@ class ModuleImporter {
206209

207210
return true;
208211
} catch (error) {
209-
log.error(`Audit failed with following error. ${error}`);
212+
log.error(`Audit failed with following error. ${error}`, this.importConfig.context);
210213
}
211214
}
212215
}

packages/contentstack-variants/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-variants",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Variants plugin",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

packages/contentstack-variants/src/import/variant-entries.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,15 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
140140
this.environments = (fsUtil.readFile(envPath, true) || {}) as Record<string, any>;
141141

142142
log.debug(
143-
`Loaded dependency data - Entries: ${Object.keys(this.entriesUidMapper).length}, Assets: ${
144-
Object.keys(this.assetUidMapper).length
145-
}, Taxonomies: ${Object.keys(this.taxonomies).length}`,
143+
`Loaded dependency data - Entries: ${Object.keys(this.entriesUidMapper)?.length}, Assets: ${
144+
Object.keys(this.assetUidMapper)?.length
145+
}, Taxonomies: ${Object.keys(this.taxonomies)?.length}`,
146146
this.config.context,
147147
);
148148

149149
// set the token
150150
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);
153152
for (const entriesForVariant of entriesForVariants) {
154153
await this.importVariantEntries(entriesForVariant);
155154
}
@@ -166,7 +165,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
166165
const variantEntry = this.config.modules.variantEntry;
167166
const { content_type, locale, entry_uid } = entriesForVariant;
168167

169-
log.debug(`Importing variant entries for: ${content_type}/${locale}/${entry_uid}`, this.config.context);
168+
log.info(`Importing variant entries for: ${content_type}/${locale}/${entry_uid}`, this.config.context);
170169

171170
const ctConfig = this.config.modules['content-types'];
172171
const contentType: ContentTypeStruct = JSON.parse(
@@ -188,14 +187,14 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
188187
sanitizePath(entry_uid),
189188
);
190189

191-
log.debug(`Processing variant entries from: ${variantEntryBasePath}`, this.config.context);
190+
log.info(`Processing variant entries from: ${variantEntryBasePath}`, this.config.context);
192191
const fs = new FsUtility({ basePath: variantEntryBasePath, createDirIfNotExist: false });
193192

194193
for (const _ in fs.indexFileContent) {
195194
try {
196195
const variantEntries = (await fs.readChunkFiles.next()) as VariantEntryStruct[];
197196
if (variantEntries?.length) {
198-
log.debug(`Processing batch of ${variantEntries.length} variant entries`, this.config.context);
197+
log.info(`Processing batch of ${variantEntries.length} variant entries`, this.config.context);
199198
await this.handleConcurrency(contentType, variantEntries, entriesForVariant);
200199
}
201200
} catch (error) {
@@ -234,15 +233,15 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
234233
const batches = chunk(variantEntries, variantEntryConfig.apiConcurrency || 5);
235234
if (isEmpty(batches)) return;
236235

237-
log.debug(`Starting concurrent processing for ${variantEntries.length} variant entries`, this.config.context);
236+
log.debug(`Starting concurrent processing for ${variantEntries?.length} variant entries`, this.config.context);
238237

239238
for (const [, batch] of entries(batches)) {
240239
batchNo += 1;
241240
const allPromise = [];
242241
const start = Date.now();
243242

244243
log.debug(
245-
`Processing batch ${batchNo}/${batches.length} with ${batch.length} variant entries`,
244+
`Processing batch ${batchNo}/${batches?.length} with ${batch?.length} variant entries`,
246245
this.config.context,
247246
);
248247

@@ -279,7 +278,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
279278
};
280279

281280
if (variantId) {
282-
log.debug(`Creating variant entry for variant ID: ${variantId}`, this.config.context);
281+
log.info(`Creating variant entry for variant ID: ${variantId}`, this.config.context);
283282
const promise = this.variantInstance.createVariantEntry(
284283
createVariantReq,
285284
{
@@ -302,7 +301,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
302301
}
303302

304303
// 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);
306305
await Promise.allSettled(allPromise);
307306
log.debug(`Batch ${batchNo} creation completed`, this.config.context);
308307

@@ -421,7 +420,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
421420
* @param variantEntry - The entry variant to update.
422421
*/
423422
updateFileFields(variantEntry: VariantEntryStruct) {
424-
log.debug(`Updating file fields for variant entry: ${variantEntry.uid}`, this.config.context);
423+
log.info(`Updating file fields for variant entry: ${variantEntry.uid}`, this.config.context);
425424

426425
const setValue = (currentObj: VariantEntryStruct, keys: string[]) => {
427426
if (!currentObj || keys.length === 0) return;
@@ -455,7 +454,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
455454
?.filter((ref: any) => ref._content_type_uid === 'sys_assets')
456455
.map((ref: any) => ref.path) || [];
457456

458-
log.debug(`Found ${pathsToUpdate.length} file field paths to update`, this.config.context);
457+
log.debug(`Found ${pathsToUpdate?.length} file field paths to update`, this.config.context);
459458
pathsToUpdate.forEach((path: string) => setValue(variantEntry, path.split('.')));
460459
}
461460

@@ -485,12 +484,12 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
485484
}
486485

487486
if (this.failedVariantEntries.has(variantEntryUID)) {
488-
log.debug(`Variant UID not found. Skipping entry variant publish for ${variantEntryUID}`, this.config.context);
487+
log.info(`Variant UID not found. Skipping entry variant publish for ${variantEntryUID}`, this.config.context);
489488
continue;
490489
}
491490

492491
if (this.environments?.length) {
493-
log.debug('No environment found! Skipping entry variant publishing...', this.config.context);
492+
log.info('No environment found! Skipping entry variant publishing...', this.config.context);
494493
return;
495494
}
496495

@@ -510,7 +509,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
510509

511510
const { environments, locales } = this.serializePublishEntries(variantEntry);
512511
if (environments?.length === 0 || locales?.length === 0) {
513-
log.debug(`Skipping publish for variant ${newVariantUid} - no environments or locales`, this.config.context);
512+
log.info(`Skipping publish for variant ${newVariantUid} - no environments or locales`, this.config.context);
514513
continue;
515514
}
516515

packages/contentstack-variants/src/utils/personalization-api-adapter.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
8484
log.debug(`Creating project: ${project.name}`, this.exportConfig?.context );
8585
const data = await this.apiClient.post<ProjectStruct>('/projects', project);
8686
const result = (await this.handleVariantAPIRes(data)) as ProjectStruct;
87-
log.debug(`Project created successfully: ${result.uid}`, this.exportConfig?.context );
87+
log.info(`Project created successfully: ${result?.uid}`, this.exportConfig?.context );
8888
return result;
8989
}
9090

@@ -101,7 +101,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
101101
log.debug(`Creating attribute: ${attribute.name}`, this.exportConfig?.context );
102102
const data = await this.apiClient.post<AttributeStruct>('/attributes', attribute);
103103
const result = (await this.handleVariantAPIRes(data)) as AttributeStruct;
104-
log.debug(`Attribute created successfully: ${result.uid}`, this.exportConfig?.context );
104+
log.info(`Attribute created successfully: ${result?.uid}`, this.exportConfig?.context );
105105
return result;
106106
}
107107

@@ -110,7 +110,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
110110
const getExperiencesEndPoint = `/experiences`;
111111
const data = await this.apiClient.get(getExperiencesEndPoint);
112112
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct[];
113-
log.debug(`Fetched ${result?.length || 0} experiences`, this.exportConfig?.context );
113+
log.info(`Fetched ${result?.length || 0} experiences`, this.exportConfig?.context );
114114
return result;
115115
}
116116

@@ -122,7 +122,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
122122
}
123123
const data = await this.apiClient.get(getExperiencesEndPoint);
124124
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct;
125-
log.debug(`Experience fetched successfully: ${result?.uid}`, this.exportConfig?.context );
125+
log.info(`Experience fetched successfully: ${result?.uid}`, this.exportConfig?.context );
126126
return result;
127127
}
128128

@@ -134,7 +134,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
134134
}
135135
const data = await this.apiClient.get(getExperiencesVersionsEndPoint);
136136
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct;
137-
log.debug(`Experience versions fetched successfully for: ${experienceUid}`, this.exportConfig?.context );
137+
log.info(`Experience versions fetched successfully for: ${experienceUid}`, this.exportConfig?.context );
138138
return result;
139139
}
140140

@@ -146,7 +146,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
146146
const createExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`;
147147
const data = await this.apiClient.post(createExperiencesVersionsEndPoint, input);
148148
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct;
149-
log.debug(`Experience version created successfully for: ${experienceUid}`, this.exportConfig?.context );
149+
log.info(`Experience version created successfully for: ${experienceUid}`, this.exportConfig?.context );
150150
return result;
151151
}
152152

@@ -176,7 +176,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
176176
.queryParams({ experience_uid: input.experienceUid })
177177
.get(getVariantGroupEndPoint);
178178
const result = (await this.handleVariantAPIRes(data)) as VariantGroupStruct;
179-
log.debug(`Variant group fetched successfully for experience: ${input.experienceUid}`, this.exportConfig?.context );
179+
log.debug(`Variant group fetched successfully for experience: ${input?.experienceUid}`, this.exportConfig?.context );
180180
return result;
181181
} else {
182182
log.debug('CMA API client not available for variant group fetch', this.exportConfig?.context );
@@ -208,23 +208,23 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
208208
log.debug(`Creating event: ${event.key}`, this.exportConfig?.context );
209209
const data = await this.apiClient.post<EventStruct>('/events', event);
210210
const result = (await this.handleVariantAPIRes(data)) as EventStruct;
211-
log.debug(`Event created successfully: ${result.uid}`, this.exportConfig?.context );
211+
log.info(`Event created successfully: ${result?.uid}`, this.exportConfig?.context );
212212
return result;
213213
}
214214

215215
async getAudiences(): Promise<AudienceStruct[] | void> {
216216
log.debug('Fetching audiences from personalization API', this.exportConfig?.context );
217217
const data = await this.apiClient.get<AudienceStruct>('/audiences');
218218
const result = (await this.handleVariantAPIRes(data)) as AudienceStruct[];
219-
log.debug(`Fetched ${result?.length || 0} audiences`, this.exportConfig?.context );
219+
log.info(`Fetched ${result?.length || 0} audiences`, this.exportConfig?.context );
220220
return result;
221221
}
222222

223223
async getAttributes(): Promise<AttributeStruct[] | void> {
224224
log.debug('Fetching attributes from personalization API', this.exportConfig?.context );
225225
const data = await this.apiClient.get<AttributeStruct>('/attributes');
226226
const result = (await this.handleVariantAPIRes(data)) as AttributeStruct[];
227-
log.debug(`Fetched ${result?.length || 0} attributes`, this.exportConfig?.context );
227+
log.info(`Fetched ${result?.length || 0} attributes`, this.exportConfig?.context );
228228
return result;
229229
}
230230

@@ -240,7 +240,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
240240
log.debug(`Creating audience: ${audience.name}`, this.exportConfig?.context );
241241
const data = await this.apiClient.post<AudienceStruct>('/audiences', audience);
242242
const result = (await this.handleVariantAPIRes(data)) as AudienceStruct;
243-
log.debug(`Audience created successfully: ${result.uid}`, this.exportConfig?.context );
243+
log.info(`Audience created successfully: ${result?.uid}`, this.exportConfig?.context );
244244
return result;
245245
}
246246

@@ -256,7 +256,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
256256
log.debug(`Creating experience: ${experience.name}`, this.exportConfig?.context );
257257
const data = await this.apiClient.post<ExperienceStruct>('/experiences', experience);
258258
const result = (await this.handleVariantAPIRes(data)) as ExperienceStruct;
259-
log.debug(`Experience created successfully: ${result.uid}`, this.exportConfig?.context );
259+
log.info(`Experience created successfully: ${result?.uid}`, this.exportConfig?.context );
260260
return result;
261261
}
262262

@@ -273,7 +273,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
273273
const updateCTInExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
274274
const data = await this.apiClient.post<CMSExperienceStruct>(updateCTInExpEndPoint, experience);
275275
const result = (await this.handleVariantAPIRes(data)) as CMSExperienceStruct;
276-
log.debug(`Content types updated successfully in experience: ${experienceUid}`, this.exportConfig?.context );
276+
log.info(`Content types updated successfully in experience: ${experienceUid}`, this.exportConfig?.context );
277277
return result;
278278
}
279279

@@ -287,7 +287,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
287287
const getCTFromExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
288288
const data = await this.apiClient.get<CMSExperienceStruct>(getCTFromExpEndPoint);
289289
const result = (await this.handleVariantAPIRes(data)) as CMSExperienceStruct;
290-
log.debug(`Content types fetched successfully from experience: ${experienceUid}`, this.exportConfig?.context );
290+
log.info(`Content types fetched successfully from experience: ${experienceUid}`, this.exportConfig?.context );
291291
return result;
292292
}
293293

0 commit comments

Comments
 (0)