Skip to content

Commit 235aab1

Browse files
committed
Merge branch 'development' into feat/DX-3471
2 parents e3c54b1 + ac661f6 commit 235aab1

14 files changed

Lines changed: 516 additions & 335 deletions

File tree

.talismanrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: d67682476d9f5fa60e18a0107050b25f109fa888a5c7f1640bb676a1a4453327
3+
checksum: 60cf06e944b51a620589f6785874c0c771e6e12a01cb561ec60fc92bfddf70ee
44
- filename: pnpm-lock.yaml
55
checksum: bee7058cd14780ac1a012ca95dccb89e62918f0e1bc9ea0d13d4c58d284e21e0
66
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
@@ -57,4 +57,8 @@ fileignoreconfig:
5757
checksum: f93aa9b0c964608b60c88d4c72ff33840b58ec900297c4bae1f4ea365aa51048
5858
- filename: packages/contentstack-auth/test/utils/mfa-handler.test.ts
5959
checksum: b067f93cf0185d794e8419cc41e8fac96ed790dea8fc48dc083ee242ccacbd4d
60-
version: "1.0"
60+
- filename: packages/contentstack-utilities/src/logger/logger.ts
61+
checksum: 76429bc87e279624b386f00e7eb3f4ec25621ace7056289f812b9a076d6e184e
62+
- filename: packages/contentstack-import/src/import/modules/entries.ts
63+
checksum: 2fd4e8ecf75e077632a6408d09997f0921d2a3508f9f2cb8f47fe79a28592300
64+
version: "1.0"

package-lock.json

Lines changed: 180 additions & 180 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-import/src/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ const config: DefaultConfig = {
436436
getEncryptionKeyMaxRetry: 3,
437437
// useBackedupDir: '',
438438
// backupConcurrency: 10,
439-
onlyTSModules: ['taxonomies', 'personalize', 'variant-entries'],
439+
onlyTSModules: ['taxonomies', 'personalize', 'variant-entries', 'stack'],
440440
auditConfig: {
441441
noLog: false, // Skip logs printing on terminal
442442
skipConfirm: true, // Skip confirmation if any

packages/contentstack-import/src/import/modules/content-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default class ContentTypesImport extends BaseClass {
114114
log.debug('Created content types mapper directory', this.importConfig.context);
115115

116116
this.installedExtensions = (
117-
((await fsUtil.readFile(this.marketplaceAppMapperPath)) as any) || { extension_uid: {} }
117+
(fsUtil.readFile(this.marketplaceAppMapperPath) as any) || { extension_uid: {} }
118118
).extension_uid;
119119
log.debug(
120120
`Loaded ${Object.keys(this.installedExtensions)?.length} installed extensions`,

packages/contentstack-import/src/import/modules/entries.ts

Lines changed: 212 additions & 88 deletions
Large diffs are not rendered by default.

packages/contentstack-import/src/utils/asset-helper.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const uploadAssetHelper = function (config: ImportConfig, req: any, fsPat
2222
return new Bluebird(function (resolve, reject) {
2323
try {
2424
log.debug(`Starting asset upload helper for path: ${fsPath}`);
25-
25+
2626
managementSDKClient(config)
2727
.then((APIClient: ContentstackClient) => {
2828
validate(req);
@@ -34,13 +34,13 @@ export const uploadAssetHelper = function (config: ImportConfig, req: any, fsPat
3434
}
3535

3636
log.debug(`Uploading asset (attempt ${RETRY}/${MAX_RETRY_LIMIT}): ${fsPath}`);
37-
37+
3838
req.upload = fsPath;
3939
const stackAPIClient = APIClient.stack({
4040
api_key: config.target_stack,
4141
management_token: config.management_token,
4242
});
43-
43+
4444
stackAPIClient
4545
.asset()
4646
.create(req)
@@ -81,9 +81,9 @@ export const lookupAssets = function (
8181
) {
8282
throw new Error('Invalid inputs for lookupAssets!');
8383
}
84-
84+
8585
log.debug(`Starting asset lookup for entry: ${data.entry?.uid}, content type: ${data.content_type?.uid}`);
86-
86+
8787
let parent: string[] = [];
8888
let assetUids: string[] = [];
8989
let assetUrls: string[] = [];
@@ -138,7 +138,9 @@ export const lookupAssets = function (
138138
findAssetIdsFromJsonCustomFields(data.entry, data.content_type.schema);
139139
} else if (schema[i].data_type === 'json' && schema[i].field_metadata.extension) {
140140
if (installedExtensions && installedExtensions[schema[i].extension_uid]) {
141-
log.debug(`Mapping extension UID: ${schema[i].extension_uid} to ${installedExtensions[schema[i].extension_uid]}`);
141+
log.debug(
142+
`Mapping extension UID: ${schema[i].extension_uid} to ${installedExtensions[schema[i].extension_uid]}`,
143+
);
142144
schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
143145
}
144146
}
@@ -267,9 +269,9 @@ export const lookupAssets = function (
267269
updateFileFields(data.entry, data, null, mappedAssetUids, matchedUids, unmatchedUids, mappedAssetUrls);
268270
assetUids = _.uniq(assetUids);
269271
assetUrls = _.uniq(assetUrls);
270-
272+
271273
log.debug(`Found ${assetUids.length} unique asset UIDs and ${assetUrls.length} unique asset URLs`);
272-
274+
273275
let entry = JSON.stringify(data.entry);
274276

275277
assetUrls.forEach(function (assetUrl: any) {
@@ -310,7 +312,7 @@ export const lookupAssets = function (
310312
}
311313

312314
if (unmatchedUids.length) {
313-
log.warn(`Found ${unmatchedUids.length} unmatched asset UIDs`);
315+
log.debug(`Found ${unmatchedUids.length} unmatched asset UIDs`);
314316
let unmatchedAssetUids = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
315317
unmatchedAssetUids = unmatchedAssetUids || {};
316318
if (unmatchedAssetUids.hasOwnProperty(data.content_type.uid)) {
@@ -324,7 +326,7 @@ export const lookupAssets = function (
324326
}
325327

326328
if (unmatchedUrls.length) {
327-
log.warn(`Found ${unmatchedUrls.length} unmatched asset URLs`);
329+
log.debug(`Found ${unmatchedUrls.length} unmatched asset URLs`);
328330
let unmatchedAssetUrls = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
329331
unmatchedAssetUrls = unmatchedAssetUrls || {};
330332
if (unmatchedAssetUrls.hasOwnProperty(data.content_type.uid)) {

packages/contentstack-import/src/utils/content-type-helper.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const schemaTemplate = {
5454

5555
export const suppressSchemaReference = function (schema: any, flag: any) {
5656
log.debug('Starting schema reference suppression process');
57-
57+
5858
for (var i in schema) {
5959
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
6060
log.debug(`Processing ${schema[i].data_type} field: ${schema[i].uid}`);
@@ -95,7 +95,7 @@ export const suppressSchemaReference = function (schema: any, flag: any) {
9595
}
9696
}
9797
}
98-
98+
9999
log.debug('Schema reference suppression completed');
100100
};
101101

@@ -105,7 +105,7 @@ export const removeReferenceFields = async function (
105105
stackAPIClient: any,
106106
): Promise<boolean | void> {
107107
log.debug('Starting reference field removal process');
108-
108+
109109
if (schema?.length) {
110110
for (let i = 0; i < schema.length; i++) {
111111
if (schema[i].data_type === 'group') {
@@ -119,11 +119,11 @@ export const removeReferenceFields = async function (
119119
} else if (schema[i].data_type === 'reference') {
120120
log.debug(`Processing reference field: ${schema[i].uid}`);
121121
flag.supressed = true;
122-
122+
123123
// Check if content-type exists
124124
// If exists, then no change should be required.
125125
let isContentTypeError = false;
126-
126+
127127
for (let j = 0; j < schema[i].reference_to.length; j++) {
128128
try {
129129
log.debug(`Checking if content type exists: ${schema[i].reference_to[j]}`);
@@ -132,16 +132,15 @@ export const removeReferenceFields = async function (
132132
} catch (error) {
133133
// Else warn and modify the schema object.
134134
isContentTypeError = true;
135-
log.warn(`Content type does not exist: ${schema[i].reference_to[j]}`);
136-
console.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
135+
log.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
137136
}
138137
}
139-
138+
140139
if (isContentTypeError) {
141140
log.debug(`Removing reference field due to missing content types: ${schema[i].uid}`);
142141
schema.splice(i, 1);
143142
--i;
144-
143+
145144
if (schema.length < 1) {
146145
log.debug('Adding dummy field to prevent empty schema');
147146
schema.push({
@@ -197,45 +196,45 @@ export const removeReferenceFields = async function (
197196
}
198197
}
199198
}
200-
199+
201200
log.debug('Reference field removal process completed');
202201
};
203202

204203
export const updateFieldRules = function (contentType: any) {
205204
log.debug(`Starting field rules update for content type: ${contentType.uid}`);
206-
205+
207206
const fieldDataTypeMap: { [key: string]: string } = {};
208207
for (let i = 0; i < contentType.schema.length; i++) {
209208
const field = contentType.schema[i];
210209
fieldDataTypeMap[field.uid] = field.data_type;
211210
}
212-
211+
213212
log.debug(`Created field data type mapping for ${Object.keys(fieldDataTypeMap).length} fields`);
214-
213+
215214
const fieldRules = [...contentType.field_rules];
216215
let len = fieldRules.length;
217216
let removedRules = 0;
218-
217+
219218
// Looping backwards as we need to delete elements as we move.
220219
for (let i = len - 1; i >= 0; i--) {
221220
const conditions = fieldRules[i].conditions;
222221
let isReference = false;
223-
222+
224223
for (let j = 0; j < conditions.length; j++) {
225224
const field = conditions[j].operand_field;
226225
if (fieldDataTypeMap[field] === 'reference') {
227226
log.debug(`Found reference field in rule condition: ${field}`);
228227
isReference = true;
229228
}
230229
}
231-
230+
232231
if (isReference) {
233232
log.debug(`Removing field rule with reference condition`);
234233
fieldRules.splice(i, 1);
235234
removedRules++;
236235
}
237236
}
238-
237+
239238
log.debug(`Field rules update completed. Removed ${removedRules} rules with reference conditions`);
240239
return fieldRules;
241240
};

packages/contentstack-import/src/utils/entries-helper.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const lookupEntries = function (
2121
uidMapperPath: string,
2222
) {
2323
log.debug(`Starting entry lookup for entry: ${data.entry?.uid}, content type: ${data.content_type?.uid}`);
24-
24+
2525
let parent: string[] = [];
2626
let uids: string[] = [];
2727
let unmapped: string[] = [];
@@ -162,7 +162,7 @@ export const lookupEntries = function (
162162

163163
function findEntryIdsFromJsonRte(entry: any, ctSchema: any = []) {
164164
log.debug('Processing JSON RTE fields for entry references');
165-
165+
166166
for (const element of ctSchema) {
167167
switch (element.data_type) {
168168
case 'blocks': {
@@ -211,9 +211,9 @@ export const lookupEntries = function (
211211
log.debug('Processing new reference field format');
212212
findUidsInNewRefFields(data.entry, uids);
213213
}
214-
214+
215215
uids = _.flattenDeep(uids);
216-
216+
217217
// if no references are found, return
218218
if (uids.length === 0) {
219219
log.debug('No entry references found');
@@ -222,9 +222,9 @@ export const lookupEntries = function (
222222

223223
uids = _.uniq(uids);
224224
log.debug(`Found ${uids.length} unique entry references`);
225-
225+
226226
let entry = JSON.stringify(data.entry);
227-
227+
228228
uids?.forEach(function (uid: any) {
229229
if (mappedUids.hasOwnProperty(uid)) {
230230
const sanitizedUid = escapeRegExp(uid);
@@ -243,7 +243,7 @@ export const lookupEntries = function (
243243
});
244244

245245
if (unmapped.length > 0) {
246-
log.warn(`Found ${unmapped.length} unmapped entry references`);
246+
log.debug(`Found ${unmapped.length} unmapped entry references`);
247247
let unmappedUids = fileHelper.readFileSync(path.join(uidMapperPath, 'unmapped-uids.json'));
248248
unmappedUids = unmappedUids || {};
249249
if (unmappedUids.hasOwnProperty(data.content_type.uid)) {
@@ -299,7 +299,7 @@ export const removeUidsFromJsonRteFields = (
299299
ctSchema: Record<string, any>[] = [],
300300
): Record<string, any> => {
301301
log.debug('Removing UIDs from JSON RTE fields');
302-
302+
303303
for (const element of ctSchema) {
304304
switch (element.data_type) {
305305
case 'blocks': {
@@ -332,7 +332,7 @@ export const removeUidsFromJsonRteFields = (
332332
case 'json': {
333333
if (entry[element.uid] && element?.field_metadata?.rich_text_type) {
334334
log.debug(`Processing JSON RTE field for UID removal: ${element.uid}`);
335-
335+
336336
if (element.multiple) {
337337
entry[element.uid] = entry[element.uid].map((jsonRteData: any) => {
338338
delete jsonRteData.uid; // remove uid
@@ -363,7 +363,7 @@ export const removeUidsFromJsonRteFields = (
363363
}
364364
}
365365
}
366-
366+
367367
log.debug('Completed removing UIDs from JSON RTE fields');
368368
return entry;
369369
};

packages/contentstack-import/src/utils/extension-helper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const lookupExtension = function (
7676
log.debug(`Mapping global field reference: ${global_fields_key_value} -> ${mappedValue}`);
7777
schema[i].reference_to = global_fields_data[global_fields_key_value];
7878
} else {
79-
log.warn(`No mapping found for global field: ${global_fields_key_value}`);
79+
log.debug(`No mapping found for global field: ${global_fields_key_value}`);
8080
}
8181
} else if (schema[i].hasOwnProperty('extension_uid')) {
8282
log.debug(`Processing field with extension UID: ${schema[i].uid}`);
@@ -93,7 +93,7 @@ export const lookupExtension = function (
9393
log.debug(`Using installed extension mapping: ${schema[i].extension_uid}`);
9494
schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
9595
} else {
96-
log.warn(`No mapping found for extension: ${extension_key_value}`);
96+
log.debug(`No mapping found for extension: ${extension_key_value}`);
9797
}
9898
}
9999
} else if (schema[i].data_type === 'json' && schema[i].hasOwnProperty('plugins') && schema[i].plugins.length > 0) {
@@ -116,7 +116,7 @@ export const lookupExtension = function (
116116
log.debug(`Mapping marketplace app extension: ${extension_key_value} -> ${mappedMarketplaceExt}`);
117117
newPluginUidsArray.push(marketPlaceAppsData.extension_uid[extension_key_value]);
118118
} else {
119-
log.warn(`No mapping found for plugin extension: ${extension_key_value}`);
119+
log.debug(`No mapping found for plugin extension: ${extension_key_value}`);
120120
}
121121
});
122122

packages/contentstack-utilities/src/helpers.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const formatError = function (error: any) {
175175
}
176176

177177
// Append detailed error information if available
178-
if (parsedError.errors && Object.keys(parsedError.errors).length > 0) {
178+
if (parsedError.errors && typeof parsedError.errors === 'object' && Object.keys(parsedError.errors).length > 0) {
179179
const entityNames: { [key: string]: string } = {
180180
authorization: 'Authentication',
181181
api_key: 'Stack API key',
@@ -184,11 +184,15 @@ export const formatError = function (error: any) {
184184
access_token: 'Delivery Token',
185185
};
186186

187-
message +=
188-
' ' +
189-
Object.entries(parsedError.errors)
190-
.map(([key, value]) => `${entityNames[key] || key} ${value}`)
191-
.join(' ');
187+
const errorList = Object.entries(parsedError.errors)
188+
.map(([field, errors]) => {
189+
const errorArray = Array.isArray(errors) ? errors : [errors];
190+
const fieldName = entityNames[field] || field;
191+
return ` • ${fieldName}: ${errorArray.join(', ')}`;
192+
})
193+
.join('\n');
194+
195+
message += `\n\nAPI Errors:\n${errorList}`;
192196
}
193197

194198
return message;

0 commit comments

Comments
 (0)