strapi-plugin-bulk-updater 1.6.5 → 1.6.6

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.
@@ -339,6 +339,137 @@ const contentTypes = {
339
339
  schema: auditLog
340
340
  }
341
341
  };
342
+ const CRASH_GUARD_SYMBOL = Symbol.for("strapi-plugin-bulk-updater.undiciCrashGuardInstalled");
343
+ let activeBulkOperations = 0;
344
+ function getActiveBulkOperationCount() {
345
+ return activeBulkOperations;
346
+ }
347
+ async function trackActiveBulkOperation(fn) {
348
+ activeBulkOperations++;
349
+ try {
350
+ return await fn();
351
+ } finally {
352
+ activeBulkOperations = Math.max(0, activeBulkOperations - 1);
353
+ }
354
+ }
355
+ function getBatchConcurrency(strapi) {
356
+ const DEFAULT_CONCURRENCY = 5;
357
+ const MIN_CONCURRENCY = 1;
358
+ const MAX_CONCURRENCY = 10;
359
+ try {
360
+ const configured = strapi?.config?.get?.("plugin::bulk-updater.batchConcurrency");
361
+ if (configured !== void 0 && configured !== null && configured !== "") {
362
+ const parsed = Number(configured);
363
+ if (Number.isFinite(parsed) && parsed >= MIN_CONCURRENCY) {
364
+ return Math.min(MAX_CONCURRENCY, Math.floor(parsed));
365
+ }
366
+ }
367
+ } catch {
368
+ }
369
+ return DEFAULT_CONCURRENCY;
370
+ }
371
+ function sanitizeSensitiveErrorText(text) {
372
+ if (!text || typeof text !== "string") return "";
373
+ return text.replace(/Bearer\s+[A-Za-z0-9\-._~+/]+=*/gi, "Bearer [REDACTED]").replace(/Basic\s+[A-Za-z0-9+/=]+/gi, "Basic [REDACTED]").replace(/(authorization|api[_-]?key|token|secret|password)\s*[:=]\s*[^\s,;'"}\]]+/gi, "$1=[REDACTED]").replace(/([?&](?:token|key|api_key|apikey|secret|password|auth)=)[^&\s]+/gi, "$1[REDACTED]");
374
+ }
375
+ function isFetchFailedError(err) {
376
+ if (!err) return false;
377
+ const visited = /* @__PURE__ */ new Set();
378
+ let current = err;
379
+ while (current && typeof current === "object" && !visited.has(current)) {
380
+ visited.add(current);
381
+ const msg = typeof current.message === "string" ? current.message : "";
382
+ const code = typeof current.code === "string" ? current.code : "";
383
+ const stack = typeof current.stack === "string" ? current.stack : "";
384
+ if (/fetch failed/i.test(msg) || code.startsWith("UND_ERR_") || stack.includes("node:internal/deps/undici")) {
385
+ return true;
386
+ }
387
+ if (Array.isArray(current.errors)) {
388
+ for (const sub of current.errors) {
389
+ if (isFetchFailedError(sub)) return true;
390
+ }
391
+ }
392
+ current = current.cause;
393
+ }
394
+ return false;
395
+ }
396
+ function formatErrorWithCause(err, fallback = "Unknown error") {
397
+ if (!err) return fallback;
398
+ if (typeof err === "string") return sanitizeSensitiveErrorText(err) || fallback;
399
+ const primaryMsg = typeof err.message === "string" && err.message.trim() && err.message !== "[object Object]" ? err.message.trim() : fallback;
400
+ const causeParts = [];
401
+ const visited = /* @__PURE__ */ new Set([err]);
402
+ let current = err.cause;
403
+ while (current && !visited.has(current) && causeParts.length < 4) {
404
+ visited.add(current);
405
+ if (typeof current === "string") {
406
+ if (current.trim()) causeParts.push(current.trim());
407
+ break;
408
+ }
409
+ if (typeof current === "object") {
410
+ const code = typeof current.code === "string" ? current.code.trim() : "";
411
+ const msg = typeof current.message === "string" ? current.message.trim() : "";
412
+ const addr = typeof current.address === "string" ? current.address.trim() : "";
413
+ const port = current.port !== void 0 && current.port !== null ? String(current.port) : "";
414
+ const endpoint = addr ? port ? `${addr}:${port}` : addr : "";
415
+ const pieces = [];
416
+ if (code) pieces.push(code);
417
+ if (msg && msg !== code) pieces.push(msg);
418
+ if (endpoint && !msg.includes(endpoint)) pieces.push(endpoint);
419
+ if (pieces.length > 0) {
420
+ causeParts.push(pieces.join(" - "));
421
+ } else if (Array.isArray(current.errors) && current.errors.length > 0) {
422
+ const subMsgs = current.errors.slice(0, 2).map((e) => {
423
+ const subCode = e?.code ? `${e.code}: ` : "";
424
+ return `${subCode}${e?.message || ""}`.trim();
425
+ }).filter(Boolean);
426
+ if (subMsgs.length > 0) {
427
+ causeParts.push(subMsgs.join("; "));
428
+ }
429
+ }
430
+ current = current.cause;
431
+ } else {
432
+ break;
433
+ }
434
+ }
435
+ let formatted = primaryMsg;
436
+ if (causeParts.length > 0) {
437
+ formatted = `${primaryMsg} (${causeParts.join(" -> ")})`;
438
+ }
439
+ if (isFetchFailedError(err) && !formatted.toLowerCase().includes("webhook")) {
440
+ formatted += " — downstream webhook or lifecycle HTTP request failed";
441
+ }
442
+ return sanitizeSensitiveErrorText(formatted);
443
+ }
444
+ function installUndiciCrashGuard(strapi) {
445
+ const globalObj = globalThis;
446
+ if (globalObj[CRASH_GUARD_SYMBOL]) {
447
+ return globalObj[CRASH_GUARD_SYMBOL];
448
+ }
449
+ const handler = (reason) => {
450
+ if (!isFetchFailedError(reason)) {
451
+ return;
452
+ }
453
+ const formatted = formatErrorWithCause(reason, "fetch failed");
454
+ const inBulk = activeBulkOperations > 0;
455
+ const contextNote = inBulk ? `during active bulk/CSV operation (${activeBulkOperations} active)` : "outside active bulk operation";
456
+ const logMsg = `[bulk-updater] Prevented server crash from unhandled undici fetch rejection ${contextNote}: ${formatted}. Check Strapi Settings > Webhooks or custom lifecycle hooks for unreachable/slow endpoints.`;
457
+ if (strapi?.log?.error) {
458
+ strapi.log.error(logMsg);
459
+ } else {
460
+ console.error(logMsg);
461
+ }
462
+ };
463
+ process.on("unhandledRejection", handler);
464
+ const uninstall = () => {
465
+ process.removeListener("unhandledRejection", handler);
466
+ if (globalObj[CRASH_GUARD_SYMBOL] === uninstall) {
467
+ delete globalObj[CRASH_GUARD_SYMBOL];
468
+ }
469
+ };
470
+ globalObj[CRASH_GUARD_SYMBOL] = uninstall;
471
+ return uninstall;
472
+ }
342
473
  const bulkUpdaterController = ({ strapi }) => ({
343
474
  async getModels(ctx) {
344
475
  try {
@@ -414,8 +545,10 @@ const bulkUpdaterController = ({ strapi }) => ({
414
545
  const result = await service.batchUpdate(ctx.request.body || {}, currentUser);
415
546
  ctx.body = result;
416
547
  } catch (err) {
417
- ctx.status = 400;
418
- ctx.body = { success: false, error: err.message };
548
+ const formatted = formatErrorWithCause(err, "Batch update failed");
549
+ strapi.log?.error?.(`[bulk-updater] POST /batch-update error: ${formatted}`);
550
+ ctx.status = isFetchFailedError(err) ? 502 : 400;
551
+ ctx.body = { success: false, error: formatted };
419
552
  }
420
553
  },
421
554
  async batchPublish(ctx) {
@@ -425,8 +558,10 @@ const bulkUpdaterController = ({ strapi }) => ({
425
558
  const result = await service.batchPublish(ctx.request.body || {}, currentUser);
426
559
  ctx.body = result;
427
560
  } catch (err) {
428
- ctx.status = 400;
429
- ctx.body = { success: false, error: err.message };
561
+ const formatted = formatErrorWithCause(err, "Batch publish failed");
562
+ strapi.log?.error?.(`[bulk-updater] POST /batch-publish error: ${formatted}`);
563
+ ctx.status = isFetchFailedError(err) ? 502 : 400;
564
+ ctx.body = { success: false, error: formatted };
430
565
  }
431
566
  },
432
567
  async previewBatch(ctx) {
@@ -458,8 +593,10 @@ const bulkUpdaterController = ({ strapi }) => ({
458
593
  const result = await service.approveBatch(batchId, currentUser, { executeImmediately });
459
594
  ctx.body = result;
460
595
  } catch (err) {
461
- ctx.status = 400;
462
- ctx.body = { success: false, error: err.message };
596
+ const formatted = formatErrorWithCause(err, "Batch approval failed");
597
+ strapi.log?.error?.(`[bulk-updater] POST /batches/${ctx.params?.batchId}/approve error: ${formatted}`);
598
+ ctx.status = isFetchFailedError(err) ? 502 : 400;
599
+ ctx.body = { success: false, error: formatted };
463
600
  }
464
601
  },
465
602
  async rejectBatch(ctx) {
@@ -483,8 +620,10 @@ const bulkUpdaterController = ({ strapi }) => ({
483
620
  const result = await service.executeNow(batchId, currentUser);
484
621
  ctx.body = result;
485
622
  } catch (err) {
486
- ctx.status = 400;
487
- ctx.body = { success: false, error: err.message };
623
+ const formatted = formatErrorWithCause(err, "Batch execution failed");
624
+ strapi.log?.error?.(`[bulk-updater] POST /batches/${ctx.params?.batchId}/execute-now error: ${formatted}`);
625
+ ctx.status = isFetchFailedError(err) ? 502 : 400;
626
+ ctx.body = { success: false, error: formatted };
488
627
  }
489
628
  },
490
629
  async getBatchStatus(ctx) {
@@ -770,8 +909,10 @@ const csvController = ({ strapi }) => ({
770
909
  });
771
910
  ctx.body = result;
772
911
  } catch (err) {
773
- ctx.status = 500;
774
- ctx.body = { success: false, error: err.message };
912
+ const formatted = formatErrorWithCause(err, "CSV import failed");
913
+ strapi.log?.error?.(`[bulk-updater] POST /csv/import error: ${formatted}`);
914
+ ctx.status = isFetchFailedError(err) ? 502 : 500;
915
+ ctx.body = { success: false, error: formatted };
775
916
  }
776
917
  },
777
918
  async importChunk(ctx) {
@@ -802,8 +943,10 @@ const csvController = ({ strapi }) => ({
802
943
  });
803
944
  ctx.body = result;
804
945
  } catch (err) {
805
- ctx.status = 500;
806
- ctx.body = { success: false, error: err.message };
946
+ const formatted = formatErrorWithCause(err, "CSV chunk import failed");
947
+ strapi.log?.error?.(`[bulk-updater] POST /csv/import-chunk error: ${formatted}`);
948
+ ctx.status = isFetchFailedError(err) ? 502 : 500;
949
+ ctx.body = { success: false, error: formatted };
807
950
  }
808
951
  },
809
952
  async validatePreflight(ctx) {
@@ -856,8 +999,10 @@ const csvController = ({ strapi }) => ({
856
999
  });
857
1000
  ctx.body = result;
858
1001
  } catch (err) {
859
- ctx.status = 500;
860
- ctx.body = { success: false, error: err.message };
1002
+ const formatted = formatErrorWithCause(err, "CSV batch submission failed");
1003
+ strapi.log?.error?.(`[bulk-updater] POST /csv/submit-batch error: ${formatted}`);
1004
+ ctx.status = isFetchFailedError(err) ? 502 : 500;
1005
+ ctx.body = { success: false, error: formatted };
861
1006
  }
862
1007
  }
863
1008
  });
@@ -5515,7 +5660,9 @@ async function resolveAndMaybePublishTarget({
5515
5660
  if (isLocalized) pubArgs.locale = candLocale;
5516
5661
  await strapi.documents(target.uid).publish(pubArgs);
5517
5662
  } catch (publishErr) {
5518
- strapi.log.warn(`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}:`, publishErr);
5663
+ strapi.log.warn(
5664
+ `[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
5665
+ );
5519
5666
  }
5520
5667
  }
5521
5668
  invalidateCollectionCache(target.uid);
@@ -5746,562 +5893,594 @@ async function executeBatchInternal(strapi, {
5746
5893
  results: []
5747
5894
  };
5748
5895
  batchJobsMap.set(batchId, jobState);
5749
- let regexObj = null;
5750
- if (effectiveEditMode !== "grid" && isRegex && regexPattern) {
5751
- regexObj = new RegExp(regexPattern, "g");
5752
- }
5753
- const CHUNK_SIZE = 25;
5754
- const publishedCounterparts = /* @__PURE__ */ new Map();
5755
- const uidsWithDraftAndPublish = /* @__PURE__ */ new Set();
5756
- const docIdsByUid = /* @__PURE__ */ new Map();
5757
- for (const target of targets) {
5758
- if (target.uid && target.documentId) {
5759
- const ct = strapi.contentTypes[target.uid];
5760
- if (ct?.options?.draftAndPublish) {
5761
- uidsWithDraftAndPublish.add(target.uid);
5762
- if (!docIdsByUid.has(target.uid)) {
5763
- docIdsByUid.set(target.uid, []);
5896
+ return await trackActiveBulkOperation(async () => {
5897
+ try {
5898
+ let regexObj = null;
5899
+ if (effectiveEditMode !== "grid" && isRegex && regexPattern) {
5900
+ regexObj = new RegExp(regexPattern, "g");
5901
+ }
5902
+ const CHUNK_SIZE = getBatchConcurrency(strapi);
5903
+ const publishedCounterparts = /* @__PURE__ */ new Map();
5904
+ const uidsWithDraftAndPublish = /* @__PURE__ */ new Set();
5905
+ const docIdsByUid = /* @__PURE__ */ new Map();
5906
+ for (const target of targets) {
5907
+ if (target.uid && target.documentId) {
5908
+ const ct = strapi.contentTypes[target.uid];
5909
+ if (ct?.options?.draftAndPublish) {
5910
+ uidsWithDraftAndPublish.add(target.uid);
5911
+ if (!docIdsByUid.has(target.uid)) {
5912
+ docIdsByUid.set(target.uid, []);
5913
+ }
5914
+ docIdsByUid.get(target.uid).push(target.documentId);
5915
+ }
5764
5916
  }
5765
- docIdsByUid.get(target.uid).push(target.documentId);
5766
5917
  }
5767
- }
5768
- }
5769
- for (const colUid of uidsWithDraftAndPublish) {
5770
- const docIds = docIdsByUid.get(colUid) || [];
5771
- if (docIds.length > 0) {
5772
- try {
5773
- const pubDocs = await strapi.documents(colUid).findMany({
5774
- status: "published",
5775
- filters: { documentId: { $in: docIds } },
5776
- fields: ["documentId", "updatedAt", "publishedAt", "locale"],
5777
- limit: Math.max(docIds.length, 100)
5778
- });
5779
- for (const pub of pubDocs || []) {
5780
- if (pub?.documentId) {
5781
- publishedCounterparts.set(`${colUid}@@@${pub.documentId}`, pub);
5782
- if (pub.locale) {
5783
- publishedCounterparts.set(`${colUid}@@@${pub.documentId}@@@${pub.locale}`, pub);
5918
+ for (const colUid of uidsWithDraftAndPublish) {
5919
+ const docIds = docIdsByUid.get(colUid) || [];
5920
+ if (docIds.length > 0) {
5921
+ try {
5922
+ const pubDocs = await strapi.documents(colUid).findMany({
5923
+ status: "published",
5924
+ filters: { documentId: { $in: docIds } },
5925
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
5926
+ limit: Math.max(docIds.length, 100)
5927
+ });
5928
+ for (const pub of pubDocs || []) {
5929
+ if (pub?.documentId) {
5930
+ publishedCounterparts.set(`${colUid}@@@${pub.documentId}`, pub);
5931
+ if (pub.locale) {
5932
+ publishedCounterparts.set(`${colUid}@@@${pub.documentId}@@@${pub.locale}`, pub);
5933
+ }
5934
+ }
5784
5935
  }
5936
+ } catch {
5785
5937
  }
5786
5938
  }
5787
- } catch {
5788
5939
  }
5789
- }
5790
- }
5791
- const documentLoader = /* @__PURE__ */ new Map();
5792
- const getDocumentDeduplicated = (uid, documentId) => {
5793
- const loaderKey = `${uid}@@@${documentId}`;
5794
- if (!documentLoader.has(loaderKey)) {
5795
- const ct = strapi.contentTypes[uid];
5796
- const populateDef = ct?.attributes ? buildDeepPopulate(ct.attributes, strapi.components) : void 0;
5797
- documentLoader.set(
5798
- loaderKey,
5799
- strapi.documents(uid).findOne({
5800
- documentId,
5801
- ...populateDef ? { populate: populateDef } : { populate: "*" }
5802
- })
5803
- );
5804
- }
5805
- return documentLoader.get(loaderKey);
5806
- };
5807
- for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
5808
- const chunk = targets.slice(i, i + CHUNK_SIZE);
5809
- const chunkPromises = chunk.map(async (target) => {
5810
- const contentType = strapi.contentTypes[target.uid];
5811
- const displayName = contentType?.info?.displayName || target.uid;
5812
- try {
5813
- if (effectiveEditMode === "grid") {
5814
- return await executeGridTargetUpdate({
5815
- strapi,
5816
- target,
5817
- attribute,
5818
- contentType,
5819
- displayName,
5820
- publishedCounterparts,
5821
- publishOnApproval: Boolean(publishOnApproval),
5822
- publishStrategy,
5823
- unreviewedConsent: Boolean(unreviewedConsent),
5824
- currentUser
5825
- });
5940
+ const documentLoader = /* @__PURE__ */ new Map();
5941
+ const getDocumentDeduplicated = (uid, documentId) => {
5942
+ const loaderKey = `${uid}@@@${documentId}`;
5943
+ if (!documentLoader.has(loaderKey)) {
5944
+ const ct = strapi.contentTypes[uid];
5945
+ const populateDef = ct?.attributes ? buildDeepPopulate(ct.attributes, strapi.components) : void 0;
5946
+ documentLoader.set(
5947
+ loaderKey,
5948
+ strapi.documents(uid).findOne({
5949
+ documentId,
5950
+ ...populateDef ? { populate: populateDef } : { populate: "*" }
5951
+ })
5952
+ );
5826
5953
  }
5827
- const currentEntry = await getDocumentDeduplicated(target.uid, target.documentId);
5828
- const entryLabel = currentEntry?.name || currentEntry?.title || currentEntry?.email || `Entry #${target.documentId}`;
5829
- const parsed = parseDynamicZonePath(attribute);
5830
- const isNested = attribute.includes(".") || attribute.includes("[");
5831
- const isComponentNested = isNested && isDeepComponentField(contentType, strapi.components, attribute);
5832
- const parts = isNested ? parsed.cleanPath.split(".") : [];
5833
- const rootKey = parsed.rootKey;
5834
- const targetComponentUid = target.targetComponentUid || parsed.targetComponentUid;
5835
- const targetIndexes = target.dynamicZoneIndexes;
5836
- const attrDef = contentType?.attributes?.[attribute];
5837
- const hasAttribute = Boolean(attrDef) || isComponentNested;
5838
- if (hasAttribute) {
5839
- if (isComponentNested) {
5840
- const populateOption = buildDeepPopulate(contentType.attributes, strapi.components);
5841
- const findOneArgs = { documentId: target.documentId };
5842
- if (populateOption) {
5843
- findOneArgs.populate = populateOption;
5954
+ return documentLoader.get(loaderKey);
5955
+ };
5956
+ for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
5957
+ const chunk = targets.slice(i, i + CHUNK_SIZE);
5958
+ const chunkPromises = chunk.map(async (target) => {
5959
+ const contentType = strapi.contentTypes[target.uid];
5960
+ const displayName = contentType?.info?.displayName || target.uid;
5961
+ try {
5962
+ if (effectiveEditMode === "grid") {
5963
+ return await executeGridTargetUpdate({
5964
+ strapi,
5965
+ target,
5966
+ attribute,
5967
+ contentType,
5968
+ displayName,
5969
+ publishedCounterparts,
5970
+ publishOnApproval: Boolean(publishOnApproval),
5971
+ publishStrategy,
5972
+ unreviewedConsent: Boolean(unreviewedConsent),
5973
+ currentUser
5974
+ });
5844
5975
  }
5845
- const currentEntryWithPopulate = await strapi.documents(target.uid).findOne(findOneArgs);
5846
- const isRootDz = contentType?.attributes?.[rootKey]?.type === "dynamiczone";
5847
- const existingRoot = currentEntryWithPopulate?.[rootKey] || (isRootDz ? [] : {});
5848
- let affectedMatches = [];
5849
- if (isRootDz && Array.isArray(existingRoot)) {
5850
- affectedMatches = getAllNestedValues({ [rootKey]: existingRoot }, attribute);
5851
- if (targetIndexes && targetIndexes.length > 0) {
5852
- affectedMatches = affectedMatches.filter((m) => targetIndexes.includes(m.index));
5853
- }
5854
- if (targetComponentUid) {
5855
- affectedMatches = affectedMatches.filter((m) => m.componentUid === targetComponentUid);
5976
+ const currentEntry = await getDocumentDeduplicated(target.uid, target.documentId);
5977
+ const entryLabel = currentEntry?.name || currentEntry?.title || currentEntry?.email || `Entry #${target.documentId}`;
5978
+ const parsed = parseDynamicZonePath(attribute);
5979
+ const isNested = attribute.includes(".") || attribute.includes("[");
5980
+ const isComponentNested = isNested && isDeepComponentField(contentType, strapi.components, attribute);
5981
+ const parts = isNested ? parsed.cleanPath.split(".") : [];
5982
+ const rootKey = parsed.rootKey;
5983
+ const targetComponentUid = target.targetComponentUid || parsed.targetComponentUid;
5984
+ const targetIndexes = target.dynamicZoneIndexes;
5985
+ const attrDef = contentType?.attributes?.[attribute];
5986
+ const hasAttribute = Boolean(attrDef) || isComponentNested;
5987
+ if (hasAttribute) {
5988
+ if (isComponentNested) {
5989
+ const populateOption = buildDeepPopulate(contentType.attributes, strapi.components);
5990
+ const findOneArgs = { documentId: target.documentId };
5991
+ if (populateOption) {
5992
+ findOneArgs.populate = populateOption;
5993
+ }
5994
+ const currentEntryWithPopulate = await strapi.documents(target.uid).findOne(findOneArgs);
5995
+ const isRootDz = contentType?.attributes?.[rootKey]?.type === "dynamiczone";
5996
+ const existingRoot = currentEntryWithPopulate?.[rootKey] || (isRootDz ? [] : {});
5997
+ let affectedMatches = [];
5998
+ if (isRootDz && Array.isArray(existingRoot)) {
5999
+ affectedMatches = getAllNestedValues({ [rootKey]: existingRoot }, attribute);
6000
+ if (targetIndexes && targetIndexes.length > 0) {
6001
+ affectedMatches = affectedMatches.filter((m) => targetIndexes.includes(m.index));
6002
+ }
6003
+ if (targetComponentUid) {
6004
+ affectedMatches = affectedMatches.filter((m) => m.componentUid === targetComponentUid);
6005
+ }
6006
+ }
6007
+ const currentVal2 = isRootDz ? affectedMatches.length > 0 ? affectedMatches.map((m) => m.value).join(", ") : getDeepProperty(existingRoot, parts.slice(1).join(".")) : getDeepProperty(existingRoot, parts.slice(1).join("."));
6008
+ let newValue2 = value;
6009
+ if (regexObj && typeof currentVal2 === "string") {
6010
+ newValue2 = currentVal2.replace(regexObj, value);
6011
+ }
6012
+ const updatedRoot = setDeepProperty(existingRoot, parts.slice(1), newValue2, {
6013
+ targetIndexes,
6014
+ targetComponentUid
6015
+ });
6016
+ const isDraftAndPublishComp = Boolean(contentType?.options?.draftAndPublish);
6017
+ const candLocaleComp = target.locale || currentEntry?.locale;
6018
+ let pubRecordComp = candLocaleComp && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleComp}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
6019
+ if (!pubRecordComp && isDraftAndPublishComp && target.documentId) {
6020
+ try {
6021
+ const singlePub = await strapi.documents(target.uid).findMany({
6022
+ status: "published",
6023
+ filters: { documentId: target.documentId },
6024
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6025
+ limit: 1
6026
+ });
6027
+ if (singlePub && singlePub.length > 0) {
6028
+ pubRecordComp = singlePub[0];
6029
+ publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordComp);
6030
+ }
6031
+ } catch {
6032
+ }
6033
+ }
6034
+ const inspectionTargetComp = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6035
+ const { hadPublishedVersion: hadPubComp } = resolveRecordPublicationStatus(
6036
+ inspectionTargetComp,
6037
+ pubRecordComp,
6038
+ isDraftAndPublishComp
6039
+ );
6040
+ const isEditingComp = isRowInEditingStage$1(inspectionTargetComp) || isRowInEditingStage$1(target);
6041
+ const shouldPublishComp = evaluateShouldPublish({
6042
+ isDraftAndPublish: isDraftAndPublishComp,
6043
+ hadPublishedVersion: hadPubComp,
6044
+ isEditing: isEditingComp,
6045
+ publishOnApproval: Boolean(publishOnApproval),
6046
+ publishStrategy,
6047
+ unreviewedConsent
6048
+ });
6049
+ const proposedEntityComp = deepMergeEntities(currentEntryWithPopulate || currentEntry, { [rootKey]: updatedRoot });
6050
+ const valResultComp = await validateEntityQuotas(strapi, target.uid, proposedEntityComp);
6051
+ if (!valResultComp.isValid) {
6052
+ return {
6053
+ uid: target.uid,
6054
+ collectionName: displayName,
6055
+ documentId: target.documentId,
6056
+ label: entryLabel,
6057
+ attribute,
6058
+ oldValue: currentVal2 ?? null,
6059
+ newValue: newValue2,
6060
+ status: "error",
6061
+ message: valResultComp.errorMessage
6062
+ };
6063
+ }
6064
+ const updateArgsComp = {
6065
+ documentId: target.documentId,
6066
+ data: {
6067
+ [rootKey]: updatedRoot
6068
+ }
6069
+ };
6070
+ if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
6071
+ updateArgsComp.locale = candLocaleComp;
6072
+ }
6073
+ await strapi.documents(target.uid).update(updateArgsComp);
6074
+ if (shouldPublishComp) {
6075
+ try {
6076
+ const pubArgs = {
6077
+ documentId: target.documentId
6078
+ };
6079
+ if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
6080
+ pubArgs.locale = candLocaleComp;
6081
+ }
6082
+ await strapi.documents(target.uid).publish(pubArgs);
6083
+ } catch (publishErr) {
6084
+ strapi.log.warn(
6085
+ `[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
6086
+ );
6087
+ }
6088
+ }
6089
+ invalidateCollectionCache(target.uid);
6090
+ await recordContentHistoryVersion(strapi, {
6091
+ uid: target.uid,
6092
+ documentId: target.documentId,
6093
+ userId: currentUser?.id,
6094
+ statusOverride: shouldPublishComp ? "published" : isDraftAndPublishComp ? hadPubComp ? "modified" : "draft" : void 0
6095
+ });
6096
+ const dzDiffs = isRootDz && affectedMatches.length > 0 ? affectedMatches.map((m) => ({
6097
+ index: m.index,
6098
+ componentUid: m.componentUid,
6099
+ componentName: m.componentName,
6100
+ attribute: `${rootKey}[#${m.index} ${m.componentName}].${parts.slice(1).join(".")}`,
6101
+ oldValue: m.value,
6102
+ newValue: regexObj && typeof m.value === "string" ? m.value.replace(regexObj, value) : value
6103
+ })) : [];
6104
+ return {
6105
+ uid: target.uid,
6106
+ collectionName: displayName,
6107
+ documentId: target.documentId,
6108
+ label: entryLabel,
6109
+ attribute,
6110
+ oldValue: currentVal2 ?? null,
6111
+ newValue: newValue2,
6112
+ status: "updated",
6113
+ message: isRootDz ? `Successfully updated ${affectedMatches.length} dynamic zone item(s) in ${attribute}` : `Successfully updated nested field ${attribute}`,
6114
+ dynamicZoneDiffs: dzDiffs
6115
+ };
5856
6116
  }
5857
- }
5858
- const currentVal2 = isRootDz ? affectedMatches.length > 0 ? affectedMatches.map((m) => m.value).join(", ") : getDeepProperty(existingRoot, parts.slice(1).join(".")) : getDeepProperty(existingRoot, parts.slice(1).join("."));
5859
- let newValue2 = value;
5860
- if (regexObj && typeof currentVal2 === "string") {
5861
- newValue2 = currentVal2.replace(regexObj, value);
5862
- }
5863
- const updatedRoot = setDeepProperty(existingRoot, parts.slice(1), newValue2, {
5864
- targetIndexes,
5865
- targetComponentUid
5866
- });
5867
- const isDraftAndPublishComp = Boolean(contentType?.options?.draftAndPublish);
5868
- const candLocaleComp = target.locale || currentEntry?.locale;
5869
- let pubRecordComp = candLocaleComp && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleComp}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
5870
- if (!pubRecordComp && isDraftAndPublishComp && target.documentId) {
5871
- try {
5872
- const singlePub = await strapi.documents(target.uid).findMany({
5873
- status: "published",
5874
- filters: { documentId: target.documentId },
5875
- fields: ["documentId", "updatedAt", "publishedAt", "locale"],
5876
- limit: 1
6117
+ if (attrDef.type === "relation") {
6118
+ const isMulti = attrDef.relation === "oneToMany" || attrDef.relation === "manyToMany";
6119
+ const currentEntryWithPopulate = await strapi.documents(target.uid).findOne({
6120
+ documentId: target.documentId,
6121
+ populate: [attribute]
5877
6122
  });
5878
- if (singlePub && singlePub.length > 0) {
5879
- pubRecordComp = singlePub[0];
5880
- publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordComp);
6123
+ const currentRel = currentEntryWithPopulate?.[attribute];
6124
+ let oldDocIds = [];
6125
+ let oldDisplay = "";
6126
+ if (isMulti && Array.isArray(currentRel)) {
6127
+ oldDocIds = currentRel.map((r) => r.documentId).filter(Boolean);
6128
+ oldDisplay = currentRel.map((r) => r.name || r.title || r.email || r.documentId).join(", ") || "(empty)";
6129
+ } else if (currentRel) {
6130
+ oldDocIds = currentRel.documentId ? [currentRel.documentId] : [];
6131
+ oldDisplay = currentRel.name || currentRel.title || currentRel.email || currentRel.documentId || "(empty)";
6132
+ } else {
6133
+ oldDisplay = "(unlinked / none)";
5881
6134
  }
5882
- } catch {
6135
+ let mode = "set";
6136
+ let targetDocIds = [];
6137
+ let newDisplay = "";
6138
+ if (value === "__clear__" || value === "") {
6139
+ mode = "clear";
6140
+ newDisplay = "(cleared / unlinked)";
6141
+ } else {
6142
+ try {
6143
+ const parsed2 = JSON.parse(value);
6144
+ if (parsed2 && typeof parsed2 === "object" && parsed2.mode) {
6145
+ mode = parsed2.mode;
6146
+ targetDocIds = Array.isArray(parsed2.documentIds) ? parsed2.documentIds : parsed2.documentId ? [parsed2.documentId] : [];
6147
+ newDisplay = parsed2.label || targetDocIds.join(", ") || `[${mode}]`;
6148
+ } else if (Array.isArray(parsed2)) {
6149
+ targetDocIds = parsed2;
6150
+ newDisplay = targetDocIds.join(", ");
6151
+ } else {
6152
+ targetDocIds = [value];
6153
+ newDisplay = value;
6154
+ }
6155
+ } catch {
6156
+ targetDocIds = [value];
6157
+ newDisplay = value;
6158
+ }
6159
+ }
6160
+ let relationPayload;
6161
+ if (mode === "clear") {
6162
+ relationPayload = isMulti ? { set: [] } : null;
6163
+ } else if (mode === "set") {
6164
+ relationPayload = isMulti ? { set: targetDocIds } : targetDocIds[0] || null;
6165
+ } else if (mode === "connect") {
6166
+ relationPayload = { connect: targetDocIds };
6167
+ } else if (mode === "disconnect") {
6168
+ relationPayload = { disconnect: targetDocIds };
6169
+ }
6170
+ const isDraftAndPublishRel = Boolean(contentType?.options?.draftAndPublish);
6171
+ const candLocaleRel = target.locale || currentEntry?.locale;
6172
+ let pubRecordRel = candLocaleRel && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleRel}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
6173
+ if (!pubRecordRel && isDraftAndPublishRel && target.documentId) {
6174
+ try {
6175
+ const singlePub = await strapi.documents(target.uid).findMany({
6176
+ status: "published",
6177
+ filters: { documentId: target.documentId },
6178
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6179
+ limit: 1
6180
+ });
6181
+ if (singlePub && singlePub.length > 0) {
6182
+ pubRecordRel = singlePub[0];
6183
+ publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordRel);
6184
+ }
6185
+ } catch {
6186
+ }
6187
+ }
6188
+ const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6189
+ const { hadPublishedVersion: hadPubRel } = resolveRecordPublicationStatus(
6190
+ inspectionTargetRel,
6191
+ pubRecordRel,
6192
+ isDraftAndPublishRel
6193
+ );
6194
+ const isEditingRel = isRowInEditingStage$1(inspectionTargetRel) || isRowInEditingStage$1(target);
6195
+ const shouldPublishRel = evaluateShouldPublish({
6196
+ isDraftAndPublish: isDraftAndPublishRel,
6197
+ hadPublishedVersion: hadPubRel,
6198
+ isEditing: isEditingRel,
6199
+ publishOnApproval: Boolean(publishOnApproval),
6200
+ publishStrategy,
6201
+ unreviewedConsent
6202
+ });
6203
+ const proposedEntityRel = deepMergeEntities(currentEntry, { [attribute]: relationPayload });
6204
+ const valResultRel = await validateEntityQuotas(strapi, target.uid, proposedEntityRel);
6205
+ if (!valResultRel.isValid) {
6206
+ return {
6207
+ uid: target.uid,
6208
+ collectionName: displayName,
6209
+ documentId: target.documentId,
6210
+ label: entryLabel,
6211
+ attribute,
6212
+ oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
6213
+ newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
6214
+ status: "error",
6215
+ message: valResultRel.errorMessage
6216
+ };
6217
+ }
6218
+ const updateArgsRel = {
6219
+ documentId: target.documentId,
6220
+ data: {
6221
+ [attribute]: relationPayload
6222
+ }
6223
+ };
6224
+ if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
6225
+ updateArgsRel.locale = candLocaleRel;
6226
+ }
6227
+ await strapi.documents(target.uid).update(updateArgsRel);
6228
+ if (shouldPublishRel) {
6229
+ try {
6230
+ const pubArgs = {
6231
+ documentId: target.documentId
6232
+ };
6233
+ if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
6234
+ pubArgs.locale = candLocaleRel;
6235
+ }
6236
+ await strapi.documents(target.uid).publish(pubArgs);
6237
+ } catch (publishErr) {
6238
+ strapi.log.warn(
6239
+ `[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
6240
+ );
6241
+ }
6242
+ }
6243
+ invalidateCollectionCache(target.uid);
6244
+ if (attrDef.target) {
6245
+ invalidateCollectionCache(attrDef.target);
6246
+ }
6247
+ await recordContentHistoryVersion(strapi, {
6248
+ uid: target.uid,
6249
+ documentId: target.documentId,
6250
+ userId: currentUser?.id,
6251
+ statusOverride: shouldPublishRel ? "published" : isDraftAndPublishRel ? hadPubRel ? "modified" : "draft" : void 0
6252
+ });
6253
+ return {
6254
+ uid: target.uid,
6255
+ collectionName: displayName,
6256
+ documentId: target.documentId,
6257
+ label: entryLabel,
6258
+ attribute,
6259
+ oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
6260
+ newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
6261
+ status: "updated",
6262
+ message: `Successfully updated relation "${attribute}"`
6263
+ };
5883
6264
  }
5884
- }
5885
- const inspectionTargetComp = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
5886
- const { hadPublishedVersion: hadPubComp } = resolveRecordPublicationStatus(
5887
- inspectionTargetComp,
5888
- pubRecordComp,
5889
- isDraftAndPublishComp
5890
- );
5891
- const isEditingComp = isRowInEditingStage$1(inspectionTargetComp) || isRowInEditingStage$1(target);
5892
- const shouldPublishComp = evaluateShouldPublish({
5893
- isDraftAndPublish: isDraftAndPublishComp,
5894
- hadPublishedVersion: hadPubComp,
5895
- isEditing: isEditingComp,
5896
- publishOnApproval: Boolean(publishOnApproval),
5897
- publishStrategy,
5898
- unreviewedConsent
5899
- });
5900
- const proposedEntityComp = deepMergeEntities(currentEntryWithPopulate || currentEntry, { [rootKey]: updatedRoot });
5901
- const valResultComp = await validateEntityQuotas(strapi, target.uid, proposedEntityComp);
5902
- if (!valResultComp.isValid) {
6265
+ let newValue = value;
6266
+ const currentVal = currentEntry?.[attribute];
6267
+ if (regexObj && typeof currentVal === "string") {
6268
+ newValue = currentVal.replace(regexObj, value);
6269
+ }
6270
+ const isDraftAndPublishScalar = Boolean(contentType?.options?.draftAndPublish);
6271
+ const candLocaleScalar = target.locale || currentEntry?.locale;
6272
+ let pubRecordScalar = candLocaleScalar && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleScalar}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
6273
+ if (!pubRecordScalar && isDraftAndPublishScalar && target.documentId) {
6274
+ try {
6275
+ const singlePub = await strapi.documents(target.uid).findMany({
6276
+ status: "published",
6277
+ filters: { documentId: target.documentId },
6278
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6279
+ limit: 1
6280
+ });
6281
+ if (singlePub && singlePub.length > 0) {
6282
+ pubRecordScalar = singlePub[0];
6283
+ publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordScalar);
6284
+ }
6285
+ } catch {
6286
+ }
6287
+ }
6288
+ const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6289
+ const { hadPublishedVersion: hadPubScalar } = resolveRecordPublicationStatus(
6290
+ inspectionTargetScalar,
6291
+ pubRecordScalar,
6292
+ isDraftAndPublishScalar
6293
+ );
6294
+ const isEditingScalar = isRowInEditingStage$1(inspectionTargetScalar) || isRowInEditingStage$1(target);
6295
+ const shouldPublishScalar = evaluateShouldPublish({
6296
+ isDraftAndPublish: isDraftAndPublishScalar,
6297
+ hadPublishedVersion: hadPubScalar,
6298
+ isEditing: isEditingScalar,
6299
+ publishOnApproval: Boolean(publishOnApproval),
6300
+ publishStrategy,
6301
+ unreviewedConsent
6302
+ });
6303
+ const proposedEntityScalar = deepMergeEntities(currentEntry, { [attribute]: newValue });
6304
+ const valResultScalar = await validateEntityQuotas(strapi, target.uid, proposedEntityScalar);
6305
+ if (!valResultScalar.isValid) {
6306
+ return {
6307
+ uid: target.uid,
6308
+ collectionName: displayName,
6309
+ documentId: target.documentId,
6310
+ label: entryLabel,
6311
+ attribute,
6312
+ oldValue: currentVal ?? null,
6313
+ newValue,
6314
+ status: "error",
6315
+ message: valResultScalar.errorMessage
6316
+ };
6317
+ }
6318
+ const updateArgsScalar = {
6319
+ documentId: target.documentId,
6320
+ data: {
6321
+ [attribute]: newValue
6322
+ }
6323
+ };
6324
+ if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
6325
+ updateArgsScalar.locale = candLocaleScalar;
6326
+ }
6327
+ await strapi.documents(target.uid).update(updateArgsScalar);
6328
+ if (shouldPublishScalar) {
6329
+ try {
6330
+ const pubArgs = {
6331
+ documentId: target.documentId
6332
+ };
6333
+ if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
6334
+ pubArgs.locale = candLocaleScalar;
6335
+ }
6336
+ await strapi.documents(target.uid).publish(pubArgs);
6337
+ } catch (publishErr) {
6338
+ strapi.log.warn(
6339
+ `[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
6340
+ );
6341
+ }
6342
+ }
6343
+ await recordContentHistoryVersion(strapi, {
6344
+ uid: target.uid,
6345
+ documentId: target.documentId,
6346
+ userId: currentUser?.id,
6347
+ statusOverride: shouldPublishScalar ? "published" : isDraftAndPublishScalar ? hadPubScalar ? "modified" : "draft" : void 0
6348
+ });
5903
6349
  return {
5904
6350
  uid: target.uid,
5905
6351
  collectionName: displayName,
5906
6352
  documentId: target.documentId,
5907
6353
  label: entryLabel,
5908
6354
  attribute,
5909
- oldValue: currentVal2 ?? null,
5910
- newValue: newValue2,
5911
- status: "error",
5912
- message: valResultComp.errorMessage
6355
+ oldValue: currentVal ?? null,
6356
+ newValue,
6357
+ status: "updated",
6358
+ message: `Successfully updated ${attribute}`
6359
+ };
6360
+ } else {
6361
+ return {
6362
+ uid: target.uid,
6363
+ collectionName: displayName,
6364
+ documentId: target.documentId,
6365
+ label: entryLabel,
6366
+ attribute,
6367
+ status: "skipped",
6368
+ message: `Skipped: Attribute "${attribute}" does not exist in schema for ${displayName}`
5913
6369
  };
5914
6370
  }
5915
- const updateArgsComp = {
5916
- documentId: target.documentId,
5917
- data: {
5918
- [rootKey]: updatedRoot
5919
- }
5920
- };
5921
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
5922
- updateArgsComp.locale = candLocaleComp;
5923
- }
5924
- await strapi.documents(target.uid).update(updateArgsComp);
5925
- if (shouldPublishComp) {
5926
- try {
5927
- const pubArgs = {
5928
- documentId: target.documentId
5929
- };
5930
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
5931
- pubArgs.locale = candLocaleComp;
5932
- }
5933
- await strapi.documents(target.uid).publish(pubArgs);
5934
- } catch (publishErr) {
5935
- strapi.log.warn(`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}:`, publishErr);
5936
- }
6371
+ } catch (updateErr) {
6372
+ const formattedErr = formatErrorWithCause(updateErr, "Failed to update record");
6373
+ if (isFetchFailedError(updateErr)) {
6374
+ strapi.log?.error?.(
6375
+ `[bulk-updater] Network/webhook fetch error during batch ${batchId} update of ${target.uid}/${target.documentId}: ${formattedErr}`
6376
+ );
5937
6377
  }
5938
- invalidateCollectionCache(target.uid);
5939
- await recordContentHistoryVersion(strapi, {
5940
- uid: target.uid,
5941
- documentId: target.documentId,
5942
- userId: currentUser?.id,
5943
- statusOverride: shouldPublishComp ? "published" : isDraftAndPublishComp ? hadPubComp ? "modified" : "draft" : void 0
5944
- });
5945
- const dzDiffs = isRootDz && affectedMatches.length > 0 ? affectedMatches.map((m) => ({
5946
- index: m.index,
5947
- componentUid: m.componentUid,
5948
- componentName: m.componentName,
5949
- attribute: `${rootKey}[#${m.index} ${m.componentName}].${parts.slice(1).join(".")}`,
5950
- oldValue: m.value,
5951
- newValue: regexObj && typeof m.value === "string" ? m.value.replace(regexObj, value) : value
5952
- })) : [];
5953
6378
  return {
5954
6379
  uid: target.uid,
5955
6380
  collectionName: displayName,
5956
6381
  documentId: target.documentId,
5957
- label: entryLabel,
6382
+ label: `Entry #${target.documentId}`,
5958
6383
  attribute,
5959
- oldValue: currentVal2 ?? null,
5960
- newValue: newValue2,
5961
- status: "updated",
5962
- message: isRootDz ? `Successfully updated ${affectedMatches.length} dynamic zone item(s) in ${attribute}` : `Successfully updated nested field ${attribute}`,
5963
- dynamicZoneDiffs: dzDiffs
6384
+ status: "error",
6385
+ message: formattedErr
5964
6386
  };
5965
6387
  }
5966
- if (attrDef.type === "relation") {
5967
- const isMulti = attrDef.relation === "oneToMany" || attrDef.relation === "manyToMany";
5968
- const currentEntryWithPopulate = await strapi.documents(target.uid).findOne({
5969
- documentId: target.documentId,
5970
- populate: [attribute]
6388
+ });
6389
+ const chunkResults = await Promise.all(chunkPromises);
6390
+ for (const res of chunkResults) {
6391
+ if (res.status === "updated") updatedCount++;
6392
+ else if (res.status === "skipped") skippedCount++;
6393
+ results.push(res);
6394
+ }
6395
+ jobState.processedCount = results.length;
6396
+ jobState.updatedCount = updatedCount;
6397
+ jobState.skippedCount = skippedCount;
6398
+ jobState.failedCount = results.filter((r) => r.status === "error").length;
6399
+ if (i + CHUNK_SIZE < targets.length) {
6400
+ await new Promise((resolve) => setImmediate(resolve));
6401
+ }
6402
+ }
6403
+ const affectedUids = new Set(targets.map((t) => t.uid));
6404
+ affectedUids.forEach((uid) => {
6405
+ invalidateCollectionCache(uid);
6406
+ });
6407
+ const failedCount = results.filter((r) => r.status === "error").length;
6408
+ jobState.failedCount = failedCount;
6409
+ jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
6410
+ jobState.isLive = updatedCount > 0;
6411
+ jobState.status = failedCount === 0 && updatedCount > 0 ? "successful" : failedCount > 0 && updatedCount > 0 ? "partial_failure" : failedCount > 0 ? "failed" : "successful";
6412
+ jobState.results = results.map((r) => ({
6413
+ ...r,
6414
+ isLive: r.status === "updated"
6415
+ }));
6416
+ const flattenedDiffs = [];
6417
+ for (const r of results) {
6418
+ if (effectiveEditMode === "grid") {
6419
+ flattenedDiffs.push(r);
6420
+ } else if (r.dynamicZoneDiffs && r.dynamicZoneDiffs.length > 0) {
6421
+ for (const dz of r.dynamicZoneDiffs) {
6422
+ flattenedDiffs.push({
6423
+ uid: r.uid,
6424
+ collectionName: r.collectionName,
6425
+ documentId: r.documentId,
6426
+ label: `${r.label} [Block #${dz.index} (${dz.componentName})]`,
6427
+ attribute: dz.attribute,
6428
+ oldValue: dz.oldValue,
6429
+ newValue: dz.newValue,
6430
+ status: "updated",
6431
+ message: `Updated ${dz.attribute}`
5971
6432
  });
5972
- const currentRel = currentEntryWithPopulate?.[attribute];
5973
- let oldDocIds = [];
5974
- let oldDisplay = "";
5975
- if (isMulti && Array.isArray(currentRel)) {
5976
- oldDocIds = currentRel.map((r) => r.documentId).filter(Boolean);
5977
- oldDisplay = currentRel.map((r) => r.name || r.title || r.email || r.documentId).join(", ") || "(empty)";
5978
- } else if (currentRel) {
5979
- oldDocIds = currentRel.documentId ? [currentRel.documentId] : [];
5980
- oldDisplay = currentRel.name || currentRel.title || currentRel.email || currentRel.documentId || "(empty)";
5981
- } else {
5982
- oldDisplay = "(unlinked / none)";
5983
- }
5984
- let mode = "set";
5985
- let targetDocIds = [];
5986
- let newDisplay = "";
5987
- if (value === "__clear__" || value === "") {
5988
- mode = "clear";
5989
- newDisplay = "(cleared / unlinked)";
5990
- } else {
5991
- try {
5992
- const parsed2 = JSON.parse(value);
5993
- if (parsed2 && typeof parsed2 === "object" && parsed2.mode) {
5994
- mode = parsed2.mode;
5995
- targetDocIds = Array.isArray(parsed2.documentIds) ? parsed2.documentIds : parsed2.documentId ? [parsed2.documentId] : [];
5996
- newDisplay = parsed2.label || targetDocIds.join(", ") || `[${mode}]`;
5997
- } else if (Array.isArray(parsed2)) {
5998
- targetDocIds = parsed2;
5999
- newDisplay = targetDocIds.join(", ");
6000
- } else {
6001
- targetDocIds = [value];
6002
- newDisplay = value;
6003
- }
6004
- } catch {
6005
- targetDocIds = [value];
6006
- newDisplay = value;
6007
- }
6008
- }
6009
- let relationPayload;
6010
- if (mode === "clear") {
6011
- relationPayload = isMulti ? { set: [] } : null;
6012
- } else if (mode === "set") {
6013
- relationPayload = isMulti ? { set: targetDocIds } : targetDocIds[0] || null;
6014
- } else if (mode === "connect") {
6015
- relationPayload = { connect: targetDocIds };
6016
- } else if (mode === "disconnect") {
6017
- relationPayload = { disconnect: targetDocIds };
6018
- }
6019
- const isDraftAndPublishRel = Boolean(contentType?.options?.draftAndPublish);
6020
- const candLocaleRel = target.locale || currentEntry?.locale;
6021
- let pubRecordRel = candLocaleRel && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleRel}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
6022
- if (!pubRecordRel && isDraftAndPublishRel && target.documentId) {
6023
- try {
6024
- const singlePub = await strapi.documents(target.uid).findMany({
6025
- status: "published",
6026
- filters: { documentId: target.documentId },
6027
- fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6028
- limit: 1
6029
- });
6030
- if (singlePub && singlePub.length > 0) {
6031
- pubRecordRel = singlePub[0];
6032
- publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordRel);
6033
- }
6034
- } catch {
6035
- }
6036
- }
6037
- const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6038
- const { hadPublishedVersion: hadPubRel } = resolveRecordPublicationStatus(
6039
- inspectionTargetRel,
6040
- pubRecordRel,
6041
- isDraftAndPublishRel
6042
- );
6043
- const isEditingRel = isRowInEditingStage$1(inspectionTargetRel) || isRowInEditingStage$1(target);
6044
- const shouldPublishRel = evaluateShouldPublish({
6045
- isDraftAndPublish: isDraftAndPublishRel,
6046
- hadPublishedVersion: hadPubRel,
6047
- isEditing: isEditingRel,
6048
- publishOnApproval: Boolean(publishOnApproval),
6049
- publishStrategy,
6050
- unreviewedConsent
6051
- });
6052
- const proposedEntityRel = deepMergeEntities(currentEntry, { [attribute]: relationPayload });
6053
- const valResultRel = await validateEntityQuotas(strapi, target.uid, proposedEntityRel);
6054
- if (!valResultRel.isValid) {
6055
- return {
6056
- uid: target.uid,
6057
- collectionName: displayName,
6058
- documentId: target.documentId,
6059
- label: entryLabel,
6060
- attribute,
6061
- oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
6062
- newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
6063
- status: "error",
6064
- message: valResultRel.errorMessage
6065
- };
6066
- }
6067
- const updateArgsRel = {
6068
- documentId: target.documentId,
6069
- data: {
6070
- [attribute]: relationPayload
6071
- }
6072
- };
6073
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
6074
- updateArgsRel.locale = candLocaleRel;
6075
- }
6076
- await strapi.documents(target.uid).update(updateArgsRel);
6077
- if (shouldPublishRel) {
6078
- try {
6079
- const pubArgs = {
6080
- documentId: target.documentId
6081
- };
6082
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
6083
- pubArgs.locale = candLocaleRel;
6084
- }
6085
- await strapi.documents(target.uid).publish(pubArgs);
6086
- } catch (publishErr) {
6087
- strapi.log.warn(`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}:`, publishErr);
6088
- }
6089
- }
6090
- invalidateCollectionCache(target.uid);
6091
- if (attrDef.target) {
6092
- invalidateCollectionCache(attrDef.target);
6093
- }
6094
- await recordContentHistoryVersion(strapi, {
6095
- uid: target.uid,
6096
- documentId: target.documentId,
6097
- userId: currentUser?.id,
6098
- statusOverride: shouldPublishRel ? "published" : isDraftAndPublishRel ? hadPubRel ? "modified" : "draft" : void 0
6099
- });
6100
- return {
6101
- uid: target.uid,
6102
- collectionName: displayName,
6103
- documentId: target.documentId,
6104
- label: entryLabel,
6105
- attribute,
6106
- oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
6107
- newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
6108
- status: "updated",
6109
- message: `Successfully updated relation "${attribute}"`
6110
- };
6111
- }
6112
- let newValue = value;
6113
- const currentVal = currentEntry?.[attribute];
6114
- if (regexObj && typeof currentVal === "string") {
6115
- newValue = currentVal.replace(regexObj, value);
6116
- }
6117
- const isDraftAndPublishScalar = Boolean(contentType?.options?.draftAndPublish);
6118
- const candLocaleScalar = target.locale || currentEntry?.locale;
6119
- let pubRecordScalar = candLocaleScalar && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleScalar}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
6120
- if (!pubRecordScalar && isDraftAndPublishScalar && target.documentId) {
6121
- try {
6122
- const singlePub = await strapi.documents(target.uid).findMany({
6123
- status: "published",
6124
- filters: { documentId: target.documentId },
6125
- fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6126
- limit: 1
6127
- });
6128
- if (singlePub && singlePub.length > 0) {
6129
- pubRecordScalar = singlePub[0];
6130
- publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordScalar);
6131
- }
6132
- } catch {
6133
- }
6134
- }
6135
- const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6136
- const { hadPublishedVersion: hadPubScalar } = resolveRecordPublicationStatus(
6137
- inspectionTargetScalar,
6138
- pubRecordScalar,
6139
- isDraftAndPublishScalar
6140
- );
6141
- const isEditingScalar = isRowInEditingStage$1(inspectionTargetScalar) || isRowInEditingStage$1(target);
6142
- const shouldPublishScalar = evaluateShouldPublish({
6143
- isDraftAndPublish: isDraftAndPublishScalar,
6144
- hadPublishedVersion: hadPubScalar,
6145
- isEditing: isEditingScalar,
6146
- publishOnApproval: Boolean(publishOnApproval),
6147
- publishStrategy,
6148
- unreviewedConsent
6149
- });
6150
- const proposedEntityScalar = deepMergeEntities(currentEntry, { [attribute]: newValue });
6151
- const valResultScalar = await validateEntityQuotas(strapi, target.uid, proposedEntityScalar);
6152
- if (!valResultScalar.isValid) {
6153
- return {
6154
- uid: target.uid,
6155
- collectionName: displayName,
6156
- documentId: target.documentId,
6157
- label: entryLabel,
6158
- attribute,
6159
- oldValue: currentVal ?? null,
6160
- newValue,
6161
- status: "error",
6162
- message: valResultScalar.errorMessage
6163
- };
6164
- }
6165
- const updateArgsScalar = {
6166
- documentId: target.documentId,
6167
- data: {
6168
- [attribute]: newValue
6169
- }
6170
- };
6171
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
6172
- updateArgsScalar.locale = candLocaleScalar;
6173
6433
  }
6174
- await strapi.documents(target.uid).update(updateArgsScalar);
6175
- if (shouldPublishScalar) {
6176
- try {
6177
- const pubArgs = {
6178
- documentId: target.documentId
6179
- };
6180
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
6181
- pubArgs.locale = candLocaleScalar;
6182
- }
6183
- await strapi.documents(target.uid).publish(pubArgs);
6184
- } catch (publishErr) {
6185
- strapi.log.warn(`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}:`, publishErr);
6186
- }
6187
- }
6188
- await recordContentHistoryVersion(strapi, {
6189
- uid: target.uid,
6190
- documentId: target.documentId,
6191
- userId: currentUser?.id,
6192
- statusOverride: shouldPublishScalar ? "published" : isDraftAndPublishScalar ? hadPubScalar ? "modified" : "draft" : void 0
6193
- });
6194
- return {
6195
- uid: target.uid,
6196
- collectionName: displayName,
6197
- documentId: target.documentId,
6198
- label: entryLabel,
6199
- attribute,
6200
- oldValue: currentVal ?? null,
6201
- newValue,
6202
- status: "updated",
6203
- message: `Successfully updated ${attribute}`
6204
- };
6205
6434
  } else {
6206
- return {
6207
- uid: target.uid,
6208
- collectionName: displayName,
6209
- documentId: target.documentId,
6210
- label: entryLabel,
6211
- attribute,
6212
- status: "skipped",
6213
- message: `Skipped: Attribute "${attribute}" does not exist in schema for ${displayName}`
6214
- };
6435
+ flattenedDiffs.push(r);
6215
6436
  }
6216
- } catch (updateErr) {
6217
- return {
6218
- uid: target.uid,
6219
- collectionName: displayName,
6220
- documentId: target.documentId,
6221
- label: `Entry #${target.documentId}`,
6222
- attribute,
6223
- status: "error",
6224
- message: updateErr.message
6225
- };
6226
6437
  }
6227
- });
6228
- const chunkResults = await Promise.all(chunkPromises);
6229
- for (const res of chunkResults) {
6230
- if (res.status === "updated") updatedCount++;
6231
- else if (res.status === "skipped") skippedCount++;
6232
- results.push(res);
6233
- }
6234
- jobState.processedCount = results.length;
6235
- jobState.updatedCount = updatedCount;
6236
- jobState.skippedCount = skippedCount;
6237
- jobState.failedCount = results.filter((r) => r.status === "error").length;
6238
- }
6239
- const affectedUids = new Set(targets.map((t) => t.uid));
6240
- affectedUids.forEach((uid) => {
6241
- invalidateCollectionCache(uid);
6242
- });
6243
- const failedCount = results.filter((r) => r.status === "error").length;
6244
- jobState.failedCount = failedCount;
6245
- jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
6246
- jobState.isLive = updatedCount > 0;
6247
- jobState.status = failedCount === 0 && updatedCount > 0 ? "successful" : failedCount > 0 && updatedCount > 0 ? "partial_failure" : failedCount > 0 ? "failed" : "successful";
6248
- jobState.results = results.map((r) => ({
6249
- ...r,
6250
- isLive: r.status === "updated"
6251
- }));
6252
- const flattenedDiffs = [];
6253
- for (const r of results) {
6254
- if (effectiveEditMode === "grid") {
6255
- flattenedDiffs.push(r);
6256
- } else if (r.dynamicZoneDiffs && r.dynamicZoneDiffs.length > 0) {
6257
- for (const dz of r.dynamicZoneDiffs) {
6258
- flattenedDiffs.push({
6259
- uid: r.uid,
6260
- collectionName: r.collectionName,
6261
- documentId: r.documentId,
6262
- label: `${r.label} [Block #${dz.index} (${dz.componentName})]`,
6263
- attribute: dz.attribute,
6264
- oldValue: dz.oldValue,
6265
- newValue: dz.newValue,
6266
- status: "updated",
6267
- message: `Updated ${dz.attribute}`
6268
- });
6438
+ const batchSummary = {
6439
+ batchId,
6440
+ attribute,
6441
+ value: effectiveSummaryVal,
6442
+ editMode: effectiveEditMode,
6443
+ updatedCount,
6444
+ skippedCount,
6445
+ totalTargets: targets.length,
6446
+ publishOnApproval,
6447
+ publishStrategy,
6448
+ unreviewedConsent
6449
+ };
6450
+ try {
6451
+ await strapi.plugin("bulk-updater").service("audit").recordBatch(
6452
+ batchSummary,
6453
+ flattenedDiffs,
6454
+ currentUser
6455
+ );
6456
+ } catch (auditErr) {
6457
+ strapi.log?.warn?.(
6458
+ `[bulk-updater] Non-fatal audit logging failure for batch ${batchId}: ${formatErrorWithCause(auditErr)}`
6459
+ );
6269
6460
  }
6270
- } else {
6271
- flattenedDiffs.push(r);
6461
+ return {
6462
+ success: true,
6463
+ batchId,
6464
+ attribute,
6465
+ value: effectiveSummaryVal,
6466
+ editMode: effectiveEditMode,
6467
+ updatedCount,
6468
+ skippedCount,
6469
+ failedCount,
6470
+ totalTargets: targets.length,
6471
+ isLive: jobState.isLive,
6472
+ status: jobState.status,
6473
+ results
6474
+ };
6475
+ } catch (fatalErr) {
6476
+ const formattedFatal = formatErrorWithCause(fatalErr, "Batch execution failed");
6477
+ jobState.status = "failed";
6478
+ jobState.error = formattedFatal;
6479
+ jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
6480
+ strapi.log?.error?.(`[bulk-updater] Batch ${batchId} aborted with error: ${formattedFatal}`);
6481
+ throw fatalErr;
6272
6482
  }
6273
- }
6274
- const batchSummary = {
6275
- batchId,
6276
- attribute,
6277
- value: effectiveSummaryVal,
6278
- editMode: effectiveEditMode,
6279
- updatedCount,
6280
- skippedCount,
6281
- totalTargets: targets.length,
6282
- publishOnApproval,
6283
- publishStrategy,
6284
- unreviewedConsent
6285
- };
6286
- await strapi.plugin("bulk-updater").service("audit").recordBatch(
6287
- batchSummary,
6288
- flattenedDiffs,
6289
- currentUser
6290
- );
6291
- return {
6292
- success: true,
6293
- batchId,
6294
- attribute,
6295
- value: effectiveSummaryVal,
6296
- editMode: effectiveEditMode,
6297
- updatedCount,
6298
- skippedCount,
6299
- failedCount,
6300
- totalTargets: targets.length,
6301
- isLive: jobState.isLive,
6302
- status: jobState.status,
6303
- results
6304
- };
6483
+ });
6305
6484
  }
6306
6485
  async function executePublishBatchInternal(strapi, {
6307
6486
  selectedEntries = [],
@@ -6355,120 +6534,146 @@ async function executePublishBatchInternal(strapi, {
6355
6534
  results: []
6356
6535
  };
6357
6536
  batchJobsMap.set(batchId, jobState);
6358
- const targets = Array.from(targetsMap.values());
6359
- const CHUNK_SIZE = 25;
6360
- for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
6361
- const chunk = targets.slice(i, i + CHUNK_SIZE);
6362
- const chunkPromises = chunk.map(async (target) => {
6363
- try {
6364
- const contentType = strapi.contentTypes[target.uid];
6365
- const displayName = contentType?.info?.displayName || target.uid;
6366
- const isDraftAndPublish = Boolean(contentType?.options?.draftAndPublish);
6367
- let existingDoc = null;
6368
- try {
6369
- existingDoc = await strapi.documents(target.uid).findOne({
6370
- documentId: target.documentId
6371
- });
6372
- } catch {
6373
- existingDoc = null;
6374
- }
6375
- const entryLabel = existingDoc?.name || existingDoc?.title || existingDoc?.label || existingDoc?.documentId || `Entry #${target.documentId}`;
6376
- if (!isDraftAndPublish) {
6377
- return {
6378
- uid: target.uid,
6379
- collectionName: displayName,
6380
- documentId: target.documentId,
6381
- label: entryLabel,
6382
- attribute: "(publish)",
6383
- status: "skipped",
6384
- message: `Skipped: Draft & Publish is disabled for collection ${displayName}`
6385
- };
6386
- }
6387
- const isAlreadyPublished = Boolean(existingDoc?.publishedAt);
6388
- await strapi.documents(target.uid).publish({
6389
- documentId: target.documentId
6390
- });
6391
- invalidateCollectionCache(target.uid);
6392
- await recordContentHistoryVersion(strapi, {
6393
- uid: target.uid,
6394
- documentId: target.documentId,
6395
- userId: currentUser?.id,
6396
- statusOverride: "published"
6537
+ return await trackActiveBulkOperation(async () => {
6538
+ try {
6539
+ const targets = Array.from(targetsMap.values());
6540
+ const CHUNK_SIZE = getBatchConcurrency(strapi);
6541
+ for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
6542
+ const chunk = targets.slice(i, i + CHUNK_SIZE);
6543
+ const chunkPromises = chunk.map(async (target) => {
6544
+ try {
6545
+ const contentType = strapi.contentTypes[target.uid];
6546
+ const displayName = contentType?.info?.displayName || target.uid;
6547
+ const isDraftAndPublish = Boolean(contentType?.options?.draftAndPublish);
6548
+ let existingDoc = null;
6549
+ try {
6550
+ existingDoc = await strapi.documents(target.uid).findOne({
6551
+ documentId: target.documentId
6552
+ });
6553
+ } catch {
6554
+ existingDoc = null;
6555
+ }
6556
+ const entryLabel = existingDoc?.name || existingDoc?.title || existingDoc?.label || existingDoc?.documentId || `Entry #${target.documentId}`;
6557
+ if (!isDraftAndPublish) {
6558
+ return {
6559
+ uid: target.uid,
6560
+ collectionName: displayName,
6561
+ documentId: target.documentId,
6562
+ label: entryLabel,
6563
+ attribute: "(publish)",
6564
+ status: "skipped",
6565
+ message: `Skipped: Draft & Publish is disabled for collection ${displayName}`
6566
+ };
6567
+ }
6568
+ const isAlreadyPublished = Boolean(existingDoc?.publishedAt);
6569
+ await strapi.documents(target.uid).publish({
6570
+ documentId: target.documentId
6571
+ });
6572
+ invalidateCollectionCache(target.uid);
6573
+ await recordContentHistoryVersion(strapi, {
6574
+ uid: target.uid,
6575
+ documentId: target.documentId,
6576
+ userId: currentUser?.id,
6577
+ statusOverride: "published"
6578
+ });
6579
+ return {
6580
+ uid: target.uid,
6581
+ collectionName: displayName,
6582
+ documentId: target.documentId,
6583
+ label: entryLabel,
6584
+ attribute: "(publish)",
6585
+ oldValue: isAlreadyPublished ? "published" : "draft",
6586
+ newValue: "published",
6587
+ status: "updated",
6588
+ message: isAlreadyPublished ? "Re-published latest version live" : "Successfully published to live"
6589
+ };
6590
+ } catch (pubErr) {
6591
+ const formattedPubErr = formatErrorWithCause(pubErr, "Failed to publish entry");
6592
+ if (isFetchFailedError(pubErr)) {
6593
+ strapi.log?.error?.(
6594
+ `[bulk-updater] Network/webhook fetch error during batch publish ${batchId} of ${target.uid}/${target.documentId}: ${formattedPubErr}`
6595
+ );
6596
+ }
6597
+ return {
6598
+ uid: target.uid,
6599
+ collectionName: strapi.contentTypes[target.uid]?.info?.displayName || target.uid,
6600
+ documentId: target.documentId,
6601
+ label: `Entry #${target.documentId}`,
6602
+ attribute: "(publish)",
6603
+ status: "error",
6604
+ message: formattedPubErr
6605
+ };
6606
+ }
6397
6607
  });
6398
- return {
6399
- uid: target.uid,
6400
- collectionName: displayName,
6401
- documentId: target.documentId,
6402
- label: entryLabel,
6403
- attribute: "(publish)",
6404
- oldValue: isAlreadyPublished ? "published" : "draft",
6405
- newValue: "published",
6406
- status: "updated",
6407
- message: isAlreadyPublished ? "Re-published latest version live" : "Successfully published to live"
6408
- };
6409
- } catch (pubErr) {
6410
- return {
6411
- uid: target.uid,
6412
- collectionName: strapi.contentTypes[target.uid]?.info?.displayName || target.uid,
6413
- documentId: target.documentId,
6414
- label: `Entry #${target.documentId}`,
6415
- attribute: "(publish)",
6416
- status: "error",
6417
- message: pubErr.message || "Failed to publish entry"
6418
- };
6608
+ const chunkResults = await Promise.all(chunkPromises);
6609
+ for (const res of chunkResults) {
6610
+ if (res.status === "updated") publishedCount++;
6611
+ else if (res.status === "skipped") skippedCount++;
6612
+ results.push(res);
6613
+ }
6614
+ jobState.processedCount = results.length;
6615
+ jobState.updatedCount = publishedCount;
6616
+ jobState.skippedCount = skippedCount;
6617
+ jobState.failedCount = results.filter((r) => r.status === "error").length;
6618
+ if (i + CHUNK_SIZE < targets.length) {
6619
+ await new Promise((resolve) => setImmediate(resolve));
6620
+ }
6621
+ }
6622
+ const affectedUids = new Set(targets.map((t) => t.uid));
6623
+ affectedUids.forEach((uid) => {
6624
+ invalidateCollectionCache(uid);
6625
+ });
6626
+ const failedCount = results.filter((r) => r.status === "error").length;
6627
+ jobState.failedCount = failedCount;
6628
+ jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
6629
+ jobState.isLive = publishedCount > 0;
6630
+ jobState.status = failedCount === 0 && publishedCount > 0 ? "successful" : failedCount > 0 && publishedCount > 0 ? "partial_failure" : failedCount > 0 ? "failed" : "successful";
6631
+ jobState.results = results.map((r) => ({
6632
+ ...r,
6633
+ isLive: r.status === "updated"
6634
+ }));
6635
+ const batchSummary = {
6636
+ batchId,
6637
+ attribute: "(publish)",
6638
+ value: "published",
6639
+ updatedCount: publishedCount,
6640
+ skippedCount,
6641
+ totalTargets: targetsMap.size,
6642
+ publishOnApproval: true,
6643
+ unreviewedConsent
6644
+ };
6645
+ try {
6646
+ await strapi.plugin("bulk-updater").service("audit").recordBatch(
6647
+ batchSummary,
6648
+ results,
6649
+ currentUser
6650
+ );
6651
+ } catch (auditErr) {
6652
+ strapi.log?.warn?.(
6653
+ `[bulk-updater] Non-fatal audit logging failure for publish batch ${batchId}: ${formatErrorWithCause(auditErr)}`
6654
+ );
6419
6655
  }
6420
- });
6421
- const chunkResults = await Promise.all(chunkPromises);
6422
- for (const res of chunkResults) {
6423
- if (res.status === "updated") publishedCount++;
6424
- else if (res.status === "skipped") skippedCount++;
6425
- results.push(res);
6426
- }
6427
- jobState.processedCount = results.length;
6428
- jobState.updatedCount = publishedCount;
6429
- jobState.skippedCount = skippedCount;
6430
- jobState.failedCount = results.filter((r) => r.status === "error").length;
6431
- }
6432
- const affectedUids = new Set(targets.map((t) => t.uid));
6433
- affectedUids.forEach((uid) => {
6434
- invalidateCollectionCache(uid);
6656
+ return {
6657
+ success: true,
6658
+ batchId,
6659
+ publishedCount,
6660
+ updatedCount: publishedCount,
6661
+ skippedCount,
6662
+ failedCount,
6663
+ totalTargets: targetsMap.size,
6664
+ isLive: publishedCount > 0,
6665
+ status: jobState.status,
6666
+ results
6667
+ };
6668
+ } catch (fatalErr) {
6669
+ const formattedFatal = formatErrorWithCause(fatalErr, "Batch publish failed");
6670
+ jobState.status = "failed";
6671
+ jobState.error = formattedFatal;
6672
+ jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
6673
+ strapi.log?.error?.(`[bulk-updater] Publish batch ${batchId} aborted with error: ${formattedFatal}`);
6674
+ throw fatalErr;
6675
+ }
6435
6676
  });
6436
- const failedCount = results.filter((r) => r.status === "error").length;
6437
- jobState.failedCount = failedCount;
6438
- jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
6439
- jobState.isLive = publishedCount > 0;
6440
- jobState.status = failedCount === 0 && publishedCount > 0 ? "successful" : failedCount > 0 && publishedCount > 0 ? "partial_failure" : failedCount > 0 ? "failed" : "successful";
6441
- jobState.results = results.map((r) => ({
6442
- ...r,
6443
- isLive: r.status === "updated"
6444
- }));
6445
- const batchSummary = {
6446
- batchId,
6447
- attribute: "(publish)",
6448
- value: "published",
6449
- updatedCount: publishedCount,
6450
- skippedCount,
6451
- totalTargets: targetsMap.size,
6452
- publishOnApproval: true,
6453
- unreviewedConsent
6454
- };
6455
- await strapi.plugin("bulk-updater").service("audit").recordBatch(
6456
- batchSummary,
6457
- results,
6458
- currentUser
6459
- );
6460
- return {
6461
- success: true,
6462
- batchId,
6463
- publishedCount,
6464
- updatedCount: publishedCount,
6465
- skippedCount,
6466
- failedCount,
6467
- totalTargets: targetsMap.size,
6468
- isLive: publishedCount > 0,
6469
- status: jobState.status,
6470
- results
6471
- };
6472
6677
  }
6473
6678
  async function executeBatchByPayload(strapi, batch, currentUser) {
6474
6679
  if (batch.payload?.action === "csv_import") {
@@ -9686,6 +9891,9 @@ function extractDetailedErrorMessage(err) {
9686
9891
  if (err.details?.message) {
9687
9892
  return err.details.message;
9688
9893
  }
9894
+ if (isFetchFailedError(err) || err.cause) {
9895
+ return formatErrorWithCause(err, "Error processing row");
9896
+ }
9689
9897
  if (err.message && err.message !== "[object Object]") {
9690
9898
  return err.message;
9691
9899
  }
@@ -9966,7 +10174,9 @@ async function executeUpdateMutation(strapi, ct, uid, existing, row, rowNumber,
9966
10174
  if (effectiveLocale) pubArgs.locale = effectiveLocale;
9967
10175
  await strapi.documents(uid).publish(pubArgs);
9968
10176
  } catch (pubErr) {
9969
- strapi.log.warn(`[bulk-updater] Auto-publish failed for ${resolvedDocId}:`, pubErr);
10177
+ strapi.log.warn(
10178
+ `[bulk-updater] Auto-publish failed for ${uid}/${resolvedDocId}: ${formatErrorWithCause(pubErr)}`
10179
+ );
9970
10180
  }
9971
10181
  }
9972
10182
  try {
@@ -10084,7 +10294,9 @@ async function executeCreateMutation(strapi, ct, uid, docId, row, rowNumber, opt
10084
10294
  if (effectiveLocale) pubArgs.locale = effectiveLocale;
10085
10295
  await strapi.documents(uid).publish(pubArgs);
10086
10296
  } catch (pubErr) {
10087
- strapi.log.warn(`[bulk-updater] Auto-publish failed for ${newDocId}:`, pubErr);
10297
+ strapi.log.warn(
10298
+ `[bulk-updater] Auto-publish failed for ${uid}/${newDocId}: ${formatErrorWithCause(pubErr)}`
10299
+ );
10088
10300
  }
10089
10301
  }
10090
10302
  try {
@@ -10115,177 +10327,121 @@ async function executeCreateMutation(strapi, ct, uid, docId, row, rowNumber, opt
10115
10327
  }
10116
10328
  }
10117
10329
  async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
10118
- ct.attributes || {};
10119
- const { mode = "auto", publish = true, publishStrategy = "safe", user, originalHeaders } = options;
10120
- const isDraftAndPublish = Boolean(ct.options?.draftAndPublish);
10121
- const docIdsInChunk = rows.map((r) => extractDocId(r)).filter(Boolean);
10122
- const publishedCounterparts = /* @__PURE__ */ new Map();
10123
- if (isDraftAndPublish && docIdsInChunk.length > 0) {
10124
- try {
10125
- const pubDocs = await strapi.documents(uid).findMany({
10126
- status: "published",
10127
- filters: { documentId: { $in: docIdsInChunk } },
10128
- fields: ["documentId", "updatedAt", "publishedAt", "locale"],
10129
- limit: Math.max(docIdsInChunk.length, 100)
10130
- });
10131
- for (const pub of pubDocs || []) {
10132
- if (pub?.documentId) {
10133
- publishedCounterparts.set(String(pub.documentId), pub);
10134
- if (pub.locale) {
10135
- publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
10330
+ return await trackActiveBulkOperation(async () => {
10331
+ const attrs = ct.attributes || {};
10332
+ const { mode = "auto", publish = true, publishStrategy = "safe", user, originalHeaders } = options;
10333
+ const isDraftAndPublish = Boolean(ct.options?.draftAndPublish);
10334
+ const docIdsInChunk = rows.map((r) => extractDocId(r)).filter(Boolean);
10335
+ const publishedCounterparts = /* @__PURE__ */ new Map();
10336
+ if (isDraftAndPublish && docIdsInChunk.length > 0) {
10337
+ try {
10338
+ const pubDocs = await strapi.documents(uid).findMany({
10339
+ status: "published",
10340
+ filters: { documentId: { $in: docIdsInChunk } },
10341
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
10342
+ limit: Math.max(docIdsInChunk.length, 100)
10343
+ });
10344
+ for (const pub of pubDocs || []) {
10345
+ if (pub?.documentId) {
10346
+ publishedCounterparts.set(String(pub.documentId), pub);
10347
+ if (pub.locale) {
10348
+ publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
10349
+ }
10136
10350
  }
10137
10351
  }
10352
+ } catch {
10138
10353
  }
10139
- } catch {
10140
10354
  }
10141
- }
10142
- const stats = {
10143
- total: rows.length,
10144
- created: 0,
10145
- updated: 0,
10146
- skipped: 0,
10147
- failed: 0,
10148
- newWithoutDocId: 0,
10149
- errors: [],
10150
- failedRows: [],
10151
- diffs: []
10152
- };
10153
- const batchModeInfo = detectCsvBatchExportMode(rows);
10154
- if (batchModeInfo.error) {
10355
+ const stats = {
10356
+ total: rows.length,
10357
+ created: 0,
10358
+ updated: 0,
10359
+ skipped: 0,
10360
+ failed: 0,
10361
+ newWithoutDocId: 0,
10362
+ errors: [],
10363
+ failedRows: [],
10364
+ diffs: []
10365
+ };
10366
+ const batchModeInfo = detectCsvBatchExportMode(rows);
10367
+ if (batchModeInfo.error) {
10368
+ for (let i = 0; i < rows.length; i++) {
10369
+ const rowNumber = startRowNumber + i;
10370
+ const row = rows[i];
10371
+ const docId = extractDocId(row);
10372
+ stats.skipped++;
10373
+ if (stats.failed !== void 0) stats.failed++;
10374
+ recordFailedCsvRow(
10375
+ stats,
10376
+ rowNumber,
10377
+ row,
10378
+ batchModeInfo.error,
10379
+ docId || void 0,
10380
+ originalHeaders
10381
+ );
10382
+ stats.diffs.push({
10383
+ uid,
10384
+ collectionName: ct.info?.displayName || uid,
10385
+ documentId: docId || `(Row #${rowNumber})`,
10386
+ label: `Row #${rowNumber}`,
10387
+ attribute: "__bulk_updater_metadata",
10388
+ oldValue: null,
10389
+ newValue: null,
10390
+ status: "error",
10391
+ message: batchModeInfo.error
10392
+ });
10393
+ }
10394
+ return stats;
10395
+ }
10396
+ const rowOptions = {
10397
+ ...options,
10398
+ expectedExportMode: batchModeInfo.mode
10399
+ };
10155
10400
  for (let i = 0; i < rows.length; i++) {
10156
10401
  const rowNumber = startRowNumber + i;
10157
10402
  const row = rows[i];
10158
- const docId = extractDocId(row);
10159
- stats.skipped++;
10160
- if (stats.failed !== void 0) stats.failed++;
10161
- recordFailedCsvRow(
10162
- stats,
10163
- rowNumber,
10164
- row,
10165
- batchModeInfo.error,
10166
- docId || void 0,
10167
- originalHeaders
10168
- );
10169
- stats.diffs.push({
10170
- uid,
10171
- collectionName: ct.info?.displayName || uid,
10172
- documentId: docId || `(Row #${rowNumber})`,
10173
- label: `Row #${rowNumber}`,
10174
- attribute: "__bulk_updater_metadata",
10175
- oldValue: null,
10176
- newValue: null,
10177
- status: "error",
10178
- message: batchModeInfo.error
10179
- });
10180
- }
10181
- return stats;
10182
- }
10183
- const rowOptions = {
10184
- ...options,
10185
- expectedExportMode: batchModeInfo.mode
10186
- };
10187
- for (let i = 0; i < rows.length; i++) {
10188
- const rowNumber = startRowNumber + i;
10189
- const row = rows[i];
10190
- let docId = extractDocId(row);
10191
- const rowLocale = extractLocale(row);
10192
- const effectiveLocale = getEffectiveLocale(ct, rowLocale);
10193
- const isEditing = isRowInEditingStage(row);
10194
- if (ct.kind === "singleType" && !docId) {
10195
- try {
10196
- const findSingleArgs = {};
10197
- if (effectiveLocale) findSingleArgs.locale = effectiveLocale;
10198
- const singleDoc = await strapi.documents(uid).findFirst(findSingleArgs);
10199
- if (singleDoc?.documentId) {
10200
- docId = singleDoc.documentId;
10403
+ let docId = extractDocId(row);
10404
+ const rowLocale = extractLocale(row);
10405
+ const effectiveLocale = getEffectiveLocale(ct, rowLocale);
10406
+ const isEditing = isRowInEditingStage(row);
10407
+ if (ct.kind === "singleType" && !docId) {
10408
+ try {
10409
+ const findSingleArgs = {};
10410
+ if (effectiveLocale) findSingleArgs.locale = effectiveLocale;
10411
+ const singleDoc = await strapi.documents(uid).findFirst(findSingleArgs);
10412
+ if (singleDoc?.documentId) {
10413
+ docId = singleDoc.documentId;
10414
+ }
10415
+ } catch {
10201
10416
  }
10202
- } catch {
10203
10417
  }
10204
- }
10205
- try {
10206
- if (mode === "update") {
10207
- if (!docId) {
10208
- stats.skipped++;
10209
- recordFailedCsvRow(
10210
- stats,
10211
- rowNumber,
10212
- row,
10213
- "Missing or invalid documentId for Update mode. (Tip: Use Smart Auto-Detect mode to auto-add entries without document IDs).",
10214
- void 0,
10215
- originalHeaders
10216
- );
10217
- continue;
10218
- }
10219
- const existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
10220
- if (!existing) {
10221
- stats.skipped++;
10222
- recordFailedCsvRow(
10223
- stats,
10224
- rowNumber,
10225
- row,
10226
- `Document with ID "${docId}" not found in database.`,
10227
- docId,
10228
- originalHeaders
10229
- );
10230
- continue;
10231
- }
10232
- await executeUpdateMutation(
10233
- strapi,
10234
- ct,
10235
- uid,
10236
- existing,
10237
- row,
10238
- rowNumber,
10239
- rowOptions,
10240
- effectiveLocale,
10241
- isEditing,
10242
- isDraftAndPublish,
10243
- publishedCounterparts,
10244
- stats,
10245
- "Updated"
10246
- );
10247
- } else if (mode === "create_or_override") {
10248
- let existing = null;
10249
- if (docId) {
10250
- existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
10251
- }
10252
- if (existing) {
10253
- await executeUpdateMutation(
10254
- strapi,
10255
- ct,
10256
- uid,
10257
- existing,
10258
- row,
10259
- rowNumber,
10260
- rowOptions,
10261
- effectiveLocale,
10262
- isEditing,
10263
- isDraftAndPublish,
10264
- publishedCounterparts,
10265
- stats,
10266
- "Overridden"
10267
- );
10268
- } else {
10269
- await executeCreateMutation(
10270
- strapi,
10271
- ct,
10272
- uid,
10273
- docId,
10274
- row,
10275
- rowNumber,
10276
- rowOptions,
10277
- effectiveLocale,
10278
- isEditing,
10279
- isDraftAndPublish,
10280
- stats
10281
- );
10282
- }
10283
- } else {
10284
- let existing = null;
10285
- if (docId) {
10286
- existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
10287
- }
10288
- if (existing) {
10418
+ try {
10419
+ if (mode === "update") {
10420
+ if (!docId) {
10421
+ stats.skipped++;
10422
+ recordFailedCsvRow(
10423
+ stats,
10424
+ rowNumber,
10425
+ row,
10426
+ "Missing or invalid documentId for Update mode. (Tip: Use Smart Auto-Detect mode to auto-add entries without document IDs).",
10427
+ void 0,
10428
+ originalHeaders
10429
+ );
10430
+ continue;
10431
+ }
10432
+ const existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
10433
+ if (!existing) {
10434
+ stats.skipped++;
10435
+ recordFailedCsvRow(
10436
+ stats,
10437
+ rowNumber,
10438
+ row,
10439
+ `Document with ID "${docId}" not found in database.`,
10440
+ docId,
10441
+ originalHeaders
10442
+ );
10443
+ continue;
10444
+ }
10289
10445
  await executeUpdateMutation(
10290
10446
  strapi,
10291
10447
  ct,
@@ -10301,48 +10457,114 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
10301
10457
  stats,
10302
10458
  "Updated"
10303
10459
  );
10460
+ } else if (mode === "create_or_override") {
10461
+ let existing = null;
10462
+ if (docId) {
10463
+ existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
10464
+ }
10465
+ if (existing) {
10466
+ await executeUpdateMutation(
10467
+ strapi,
10468
+ ct,
10469
+ uid,
10470
+ existing,
10471
+ row,
10472
+ rowNumber,
10473
+ rowOptions,
10474
+ effectiveLocale,
10475
+ isEditing,
10476
+ isDraftAndPublish,
10477
+ publishedCounterparts,
10478
+ stats,
10479
+ "Overridden"
10480
+ );
10481
+ } else {
10482
+ await executeCreateMutation(
10483
+ strapi,
10484
+ ct,
10485
+ uid,
10486
+ docId,
10487
+ row,
10488
+ rowNumber,
10489
+ rowOptions,
10490
+ effectiveLocale,
10491
+ isEditing,
10492
+ isDraftAndPublish,
10493
+ stats
10494
+ );
10495
+ }
10304
10496
  } else {
10305
- await executeCreateMutation(
10306
- strapi,
10307
- ct,
10308
- uid,
10309
- docId,
10310
- row,
10311
- rowNumber,
10312
- rowOptions,
10313
- effectiveLocale,
10314
- isEditing,
10315
- isDraftAndPublish,
10316
- stats
10497
+ let existing = null;
10498
+ if (docId) {
10499
+ existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
10500
+ }
10501
+ if (existing) {
10502
+ await executeUpdateMutation(
10503
+ strapi,
10504
+ ct,
10505
+ uid,
10506
+ existing,
10507
+ row,
10508
+ rowNumber,
10509
+ rowOptions,
10510
+ effectiveLocale,
10511
+ isEditing,
10512
+ isDraftAndPublish,
10513
+ publishedCounterparts,
10514
+ stats,
10515
+ "Updated"
10516
+ );
10517
+ } else {
10518
+ await executeCreateMutation(
10519
+ strapi,
10520
+ ct,
10521
+ uid,
10522
+ docId,
10523
+ row,
10524
+ rowNumber,
10525
+ rowOptions,
10526
+ effectiveLocale,
10527
+ isEditing,
10528
+ isDraftAndPublish,
10529
+ stats
10530
+ );
10531
+ }
10532
+ }
10533
+ } catch (err) {
10534
+ stats.skipped++;
10535
+ if (stats.failed !== void 0) stats.failed++;
10536
+ const errMsg = sanitizeUserErrorMessage(extractDetailedErrorMessage(err));
10537
+ if (isFetchFailedError(err)) {
10538
+ strapi.log?.error?.(
10539
+ `[bulk-updater] Network/webhook fetch error during CSV import row ${rowNumber} (${uid}/${docId || "new"}): ${errMsg}`
10317
10540
  );
10318
10541
  }
10542
+ recordFailedCsvRow(
10543
+ stats,
10544
+ rowNumber,
10545
+ row,
10546
+ errMsg,
10547
+ docId || void 0,
10548
+ originalHeaders
10549
+ );
10550
+ stats.diffs.push({
10551
+ uid,
10552
+ collectionName: ct.info?.displayName || uid,
10553
+ documentId: docId || `(Row #${rowNumber})`,
10554
+ label: `Row #${rowNumber}`,
10555
+ attribute: "(record)",
10556
+ oldValue: null,
10557
+ newValue: null,
10558
+ status: "error",
10559
+ message: `Failed to process row ${rowNumber}: ${errMsg}`
10560
+ });
10561
+ }
10562
+ if (i > 0 && i % 10 === 0) {
10563
+ await new Promise((resolve) => setImmediate(resolve));
10319
10564
  }
10320
- } catch (err) {
10321
- stats.skipped++;
10322
- if (stats.failed !== void 0) stats.failed++;
10323
- const errMsg = sanitizeUserErrorMessage(extractDetailedErrorMessage(err));
10324
- recordFailedCsvRow(
10325
- stats,
10326
- rowNumber,
10327
- row,
10328
- errMsg,
10329
- docId || void 0,
10330
- originalHeaders
10331
- );
10332
- stats.diffs.push({
10333
- uid,
10334
- collectionName: ct.info?.displayName || uid,
10335
- documentId: docId || `(Row #${rowNumber})`,
10336
- label: `Row #${rowNumber}`,
10337
- attribute: "(record)",
10338
- oldValue: null,
10339
- newValue: null,
10340
- status: "error",
10341
- message: `Failed to process row ${rowNumber}: ${errMsg}`
10342
- });
10343
10565
  }
10344
- }
10345
- return stats;
10566
+ return stats;
10567
+ });
10346
10568
  }
10347
10569
  async function recordCsvAuditLog(strapi, ct, uid, batchId, stats, user, publishOnApproval, publishStrategy, unreviewedConsent) {
10348
10570
  if (stats.updated === 0 && stats.created === 0) return;
@@ -11792,6 +12014,7 @@ const index = {
11792
12014
  });
11793
12015
  },
11794
12016
  bootstrap({ strapi }) {
12017
+ installUndiciCrashGuard(strapi);
11795
12018
  strapi.server.use(async (ctx, next) => {
11796
12019
  try {
11797
12020
  await next();
@@ -11814,6 +12037,9 @@ const index = {
11814
12037
  }
11815
12038
  });
11816
12039
  strapi.documents.use(async (context, next) => {
12040
+ if (typeof context.uid === "string" && context.uid.startsWith("plugin::bulk-updater.")) {
12041
+ return await next();
12042
+ }
11817
12043
  const params = context.params;
11818
12044
  if (["create", "update"].includes(context.action)) {
11819
12045
  const data = params?.data;
@@ -11996,9 +12222,14 @@ exports.extractHeadingsFromRichText = extractHeadingsFromRichText;
11996
12222
  exports.extractMetadataFromRow = extractMetadataFromRow;
11997
12223
  exports.extractRowFlattenedMetadata = extractRowFlattenedMetadata;
11998
12224
  exports.formatErrorCsvFilename = formatErrorCsvFilename;
12225
+ exports.formatErrorWithCause = formatErrorWithCause;
12226
+ exports.getActiveBulkOperationCount = getActiveBulkOperationCount;
11999
12227
  exports.getAllNestedValues = getAllNestedValues;
12228
+ exports.getBatchConcurrency = getBatchConcurrency;
12000
12229
  exports.getDeepProp = getDeepProp;
12001
12230
  exports.inspectRowMetadataMode = inspectRowMetadataMode;
12231
+ exports.installUndiciCrashGuard = installUndiciCrashGuard;
12232
+ exports.isFetchFailedError = isFetchFailedError;
12002
12233
  exports.isPlainObject = isPlainObject;
12003
12234
  exports.isValidDocumentId = isValidDocumentId;
12004
12235
  exports.normalizeExportMode = normalizeExportMode;
@@ -12016,12 +12247,14 @@ exports.resolveErrorColumnName = resolveErrorColumnName;
12016
12247
  exports.resolveMediaIds = resolveMediaIds;
12017
12248
  exports.resolveRelationPayload = resolveRelationPayload;
12018
12249
  exports.resolveTargetObjectField = resolveTargetObjectField;
12250
+ exports.sanitizeSensitiveErrorText = sanitizeSensitiveErrorText;
12019
12251
  exports.sanitizeUserErrorMessage = sanitizeUserErrorMessage;
12020
12252
  exports.serializeDocumentsToCsv = serializeDocumentsToCsv;
12021
12253
  exports.serializeFieldValue = serializeFieldValue;
12022
12254
  exports.serializePlannedCell = serializePlannedCell;
12023
12255
  exports.setDeepProp = setDeepProp;
12024
12256
  exports.sortAuditRecordsDesc = sortAuditRecordsDesc;
12257
+ exports.trackActiveBulkOperation = trackActiveBulkOperation;
12025
12258
  exports.validateEntityQuotas = validateEntityQuotas;
12026
12259
  exports.validateRecordSchemaConstraints = validateRecordSchemaConstraints;
12027
12260
  exports.verifyDocumentIntegrity = verifyDocumentIntegrity;