@dench.com/cli 3.11.34-staging.773 → 3.11.35-staging.803
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/crm.ts +24 -2
- package/package.json +1 -1
package/crm.ts
CHANGED
|
@@ -532,17 +532,31 @@ export function countResultStatuses(results: unknown[]): {
|
|
|
532
532
|
created: number;
|
|
533
533
|
alreadyExisted: number;
|
|
534
534
|
updated: number;
|
|
535
|
+
errors: number;
|
|
535
536
|
} {
|
|
536
537
|
let created = 0;
|
|
537
538
|
let alreadyExisted = 0;
|
|
538
539
|
let updated = 0;
|
|
540
|
+
let errors = 0;
|
|
539
541
|
for (const result of results) {
|
|
540
542
|
const status = isJsonRecord(result) ? result.status : undefined;
|
|
541
543
|
if (status === "already_existed") alreadyExisted += 1;
|
|
542
544
|
else if (status === "updated") updated += 1;
|
|
545
|
+
else if (status === "error") errors += 1;
|
|
543
546
|
else created += 1;
|
|
544
547
|
}
|
|
545
|
-
return { created, alreadyExisted, updated };
|
|
548
|
+
return { created, alreadyExisted, updated, errors };
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** "Row N: reason" for every row `batch.apply` skipped (DEN-349). */
|
|
552
|
+
export function importRowErrors(results: unknown[]): string[] {
|
|
553
|
+
return results.flatMap((result) =>
|
|
554
|
+
isJsonRecord(result) &&
|
|
555
|
+
result.status === "error" &&
|
|
556
|
+
typeof result.error === "string"
|
|
557
|
+
? [result.error]
|
|
558
|
+
: [],
|
|
559
|
+
);
|
|
546
560
|
}
|
|
547
561
|
|
|
548
562
|
function parseUpdateManyRows(items: unknown[]): Array<{
|
|
@@ -672,6 +686,7 @@ export async function applyBatchOpsInChunks(
|
|
|
672
686
|
allowUnknown = false,
|
|
673
687
|
onConflict?: CrmOnConflictPolicy,
|
|
674
688
|
withReferences = false,
|
|
689
|
+
collectRowErrors = false,
|
|
675
690
|
): Promise<{
|
|
676
691
|
chunks: number;
|
|
677
692
|
results: unknown[];
|
|
@@ -689,6 +704,7 @@ export async function applyBatchOpsInChunks(
|
|
|
689
704
|
...(chunkKey ? { idempotencyKey: chunkKey } : {}),
|
|
690
705
|
...(allowUnknown ? { allowUnknown: true } : {}),
|
|
691
706
|
...(onConflict ? { onConflict } : {}),
|
|
707
|
+
...(collectRowErrors ? { collectRowErrors: true } : {}),
|
|
692
708
|
})) as
|
|
693
709
|
| { results?: unknown[]; references?: WorkspaceReference[] }
|
|
694
710
|
| null
|
|
@@ -3893,21 +3909,27 @@ async function runImportCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
3893
3909
|
}));
|
|
3894
3910
|
// batch.apply matches the selected CRM field when supplied; otherwise
|
|
3895
3911
|
// seedKey protects exact reruns. The shared helper handles chunking.
|
|
3912
|
+
// A bad row is reported by its row number and skipped; the good rows are
|
|
3913
|
+
// still created (DEN-349).
|
|
3896
3914
|
const { results } = await applyBatchOpsInChunks(
|
|
3897
3915
|
ctx,
|
|
3898
3916
|
ops,
|
|
3899
3917
|
undefined,
|
|
3900
3918
|
false,
|
|
3901
3919
|
onConflict,
|
|
3920
|
+
false,
|
|
3921
|
+
true,
|
|
3902
3922
|
);
|
|
3903
3923
|
const counts = countResultStatuses(results);
|
|
3924
|
+
const rowErrors = importRowErrors(results);
|
|
3904
3925
|
out(ctx, {
|
|
3905
3926
|
objectName,
|
|
3906
3927
|
sourceRowsParsed: rows.length,
|
|
3907
3928
|
imported: counts.created,
|
|
3908
3929
|
skipped: counts.alreadyExisted,
|
|
3909
3930
|
updated: counts.updated,
|
|
3910
|
-
errors:
|
|
3931
|
+
errors: counts.errors,
|
|
3932
|
+
...(rowErrors.length > 0 ? { rowErrors } : {}),
|
|
3911
3933
|
onConflict,
|
|
3912
3934
|
...(dedupeColumn ? { dedupeKey: dedupeColumn } : {}),
|
|
3913
3935
|
});
|