strapi-plugin-bulk-updater 1.5.8 → 1.5.10

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.
@@ -5608,8 +5608,14 @@ function buildDeepPopulate(attributes, allComponents, depth = 0) {
5608
5608
  }
5609
5609
  } else if (def.type === "dynamiczone") {
5610
5610
  populate[key] = true;
5611
- } else if (def.type === "relation" || def.type === "media") {
5612
- populate[key] = true;
5611
+ } else if (def.type === "relation") {
5612
+ populate[key] = {
5613
+ fields: ["documentId", "name", "title", "slug", "username", "email"]
5614
+ };
5615
+ } else if (def.type === "media") {
5616
+ populate[key] = {
5617
+ fields: ["url", "name", "mime"]
5618
+ };
5613
5619
  }
5614
5620
  }
5615
5621
  return Object.keys(populate).length > 0 ? populate : void 0;
@@ -6174,12 +6180,6 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6174
6180
  });
6175
6181
  continue;
6176
6182
  }
6177
- const updateArgs = {
6178
- documentId: resolvedDocId,
6179
- data: mergedPayload
6180
- };
6181
- if (effectiveLocale) updateArgs.locale = effectiveLocale;
6182
- await strapi.documents(uid).update(updateArgs);
6183
6183
  let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6184
6184
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6185
6185
  try {
@@ -6196,7 +6196,9 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6196
6196
  } catch {
6197
6197
  }
6198
6198
  }
6199
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
6199
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
6200
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
6201
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
6200
6202
  const { hadPublishedVersion } = resolveRecordPublicationStatus(
6201
6203
  inspectionExisting,
6202
6204
  pubRecord,
@@ -6210,6 +6212,12 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6210
6212
  publishStrategy,
6211
6213
  unreviewedConsent: options.unreviewedConsent
6212
6214
  });
6215
+ const updateArgs = {
6216
+ documentId: resolvedDocId,
6217
+ data: mergedPayload
6218
+ };
6219
+ if (effectiveLocale) updateArgs.locale = effectiveLocale;
6220
+ await strapi.documents(uid).update(updateArgs);
6213
6221
  if (shouldPublish) {
6214
6222
  try {
6215
6223
  const pubArgs = { documentId: resolvedDocId };
@@ -6257,12 +6265,6 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6257
6265
  mergedPayload[key] = deepMergeComponent(existing[key], payload[key]);
6258
6266
  }
6259
6267
  }
6260
- const updateArgs = {
6261
- documentId: resolvedDocId,
6262
- data: mergedPayload
6263
- };
6264
- if (effectiveLocale) updateArgs.locale = effectiveLocale;
6265
- await strapi.documents(uid).update(updateArgs);
6266
6268
  let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6267
6269
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6268
6270
  try {
@@ -6279,7 +6281,9 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6279
6281
  } catch {
6280
6282
  }
6281
6283
  }
6282
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
6284
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
6285
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
6286
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
6283
6287
  const { hadPublishedVersion } = resolveRecordPublicationStatus(
6284
6288
  inspectionExisting,
6285
6289
  pubRecord,
@@ -6293,6 +6297,12 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6293
6297
  publishStrategy,
6294
6298
  unreviewedConsent: options.unreviewedConsent
6295
6299
  });
6300
+ const updateArgs = {
6301
+ documentId: resolvedDocId,
6302
+ data: mergedPayload
6303
+ };
6304
+ if (effectiveLocale) updateArgs.locale = effectiveLocale;
6305
+ await strapi.documents(uid).update(updateArgs);
6296
6306
  if (shouldPublish) {
6297
6307
  try {
6298
6308
  const pubArgs = { documentId: resolvedDocId };
@@ -6382,12 +6392,6 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6382
6392
  mergedPayload[key] = deepMergeComponent(existing[key], payload[key]);
6383
6393
  }
6384
6394
  }
6385
- const updateArgs = {
6386
- documentId: resolvedDocId,
6387
- data: mergedPayload
6388
- };
6389
- if (effectiveLocale) updateArgs.locale = effectiveLocale;
6390
- await strapi.documents(uid).update(updateArgs);
6391
6395
  let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6392
6396
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6393
6397
  try {
@@ -6404,7 +6408,9 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6404
6408
  } catch {
6405
6409
  }
6406
6410
  }
6407
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
6411
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
6412
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
6413
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
6408
6414
  const { hadPublishedVersion } = resolveRecordPublicationStatus(
6409
6415
  inspectionExisting,
6410
6416
  pubRecord,
@@ -6418,6 +6424,12 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6418
6424
  publishStrategy,
6419
6425
  unreviewedConsent: options.unreviewedConsent
6420
6426
  });
6427
+ const updateArgs = {
6428
+ documentId: resolvedDocId,
6429
+ data: mergedPayload
6430
+ };
6431
+ if (effectiveLocale) updateArgs.locale = effectiveLocale;
6432
+ await strapi.documents(uid).update(updateArgs);
6421
6433
  if (shouldPublish) {
6422
6434
  try {
6423
6435
  const pubArgs = { documentId: resolvedDocId };
@@ -6696,7 +6708,7 @@ const csvService = ({ strapi }) => ({
6696
6708
  lines.push(fields.map((f) => escapeCsvValue(f.key)).join(","));
6697
6709
  let totalExported = 0;
6698
6710
  const maxLimit = options.limit && options.limit > 0 ? options.limit : Infinity;
6699
- const CHUNK_SIZE = 1e3;
6711
+ const BATCH_SIZE = 200;
6700
6712
  if (ct.kind === "singleType") {
6701
6713
  const findFirstArgs = {};
6702
6714
  if (deepPopulate) {
@@ -6711,15 +6723,18 @@ const csvService = ({ strapi }) => ({
6711
6723
  } else {
6712
6724
  let currentPage = 1;
6713
6725
  let hasMore = true;
6726
+ const sortClause = ct.attributes?.createdAt ? { createdAt: "desc" } : ct.attributes?.id ? { id: "desc" } : void 0;
6714
6727
  while (hasMore && totalExported < maxLimit) {
6715
6728
  const remaining = maxLimit - totalExported;
6716
- const currentBatchLimit = Math.min(CHUNK_SIZE, remaining);
6729
+ const currentBatchLimit = Math.min(BATCH_SIZE, remaining);
6717
6730
  const findPageArgs = {
6718
6731
  filters: Object.keys(filters).length > 0 ? filters : void 0,
6719
6732
  page: currentPage,
6720
- pageSize: currentBatchLimit,
6721
- sort: { createdAt: "desc" }
6733
+ pageSize: currentBatchLimit
6722
6734
  };
6735
+ if (sortClause) {
6736
+ findPageArgs.sort = sortClause;
6737
+ }
6723
6738
  if (deepPopulate) {
6724
6739
  findPageArgs.populate = deepPopulate;
6725
6740
  }
@@ -6742,6 +6757,7 @@ const csvService = ({ strapi }) => ({
6742
6757
  } else {
6743
6758
  currentPage++;
6744
6759
  }
6760
+ await new Promise((resolve) => setImmediate(resolve));
6745
6761
  }
6746
6762
  }
6747
6763
  const csvContent = "\uFEFF" + lines.join("\r\n") + "\r\n";
@@ -6834,10 +6850,23 @@ const csvService = ({ strapi }) => ({
6834
6850
  filters: { documentId: { $in: docIds } },
6835
6851
  limit: docIds.length
6836
6852
  });
6853
+ let pubSet = /* @__PURE__ */ new Set();
6854
+ if (Boolean(ct.options?.draftAndPublish)) {
6855
+ try {
6856
+ const pubDocs = await strapi.documents(uid).findMany({
6857
+ status: "published",
6858
+ filters: { documentId: { $in: docIds } },
6859
+ fields: ["documentId"],
6860
+ limit: docIds.length
6861
+ });
6862
+ pubSet = new Set((pubDocs || []).map((p) => String(p.documentId)));
6863
+ } catch {
6864
+ }
6865
+ }
6837
6866
  for (const entry of entries || []) {
6838
6867
  const titleOrName = entry.title || entry.name || entry.subject || entry.email || `Entry #${entry.documentId}`;
6839
6868
  const identifier = entry.slug || entry.email || entry.username || entry.documentId;
6840
- const isPublished = Boolean(entry.publishedAt);
6869
+ const isPublished = Boolean(entry.publishedAt) || pubSet.has(String(entry.documentId));
6841
6870
  const row = [
6842
6871
  uid,
6843
6872
  displayName,
@@ -7052,6 +7081,27 @@ const csvService = ({ strapi }) => ({
7052
7081
  };
7053
7082
  const errors2 = [];
7054
7083
  const warnings = [];
7084
+ const docIdsInPreflight = rows.map((r) => extractDocId(r)).filter(Boolean);
7085
+ const publishedCounterparts = /* @__PURE__ */ new Map();
7086
+ if (isDraftAndPublish && docIdsInPreflight.length > 0) {
7087
+ try {
7088
+ const pubDocs = await strapi.documents(uid).findMany({
7089
+ status: "published",
7090
+ filters: { documentId: { $in: docIdsInPreflight } },
7091
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
7092
+ limit: Math.max(docIdsInPreflight.length, 100)
7093
+ });
7094
+ for (const pub of pubDocs || []) {
7095
+ if (pub?.documentId) {
7096
+ publishedCounterparts.set(String(pub.documentId), pub);
7097
+ if (pub.locale) {
7098
+ publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
7099
+ }
7100
+ }
7101
+ }
7102
+ } catch {
7103
+ }
7104
+ }
7055
7105
  for (let i = 0; i < rows.length; i++) {
7056
7106
  const rowNumber = i + 2;
7057
7107
  const row = rows[i];
@@ -7066,14 +7116,16 @@ const csvService = ({ strapi }) => ({
7066
7116
  }
7067
7117
  if (existing && isDraftAndPublish) {
7068
7118
  lifecycleStats.totalChecked++;
7069
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
7119
+ const pubRecord = effectiveLocale && publishedCounterparts.get(`${docId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(docId));
7120
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
7121
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
7122
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
7070
7123
  const { status: preStatus, hadPublishedVersion } = resolveRecordPublicationStatus(
7071
7124
  inspectionExisting,
7072
- void 0,
7125
+ pubRecord,
7073
7126
  isDraftAndPublish
7074
7127
  );
7075
- const isApproved = !isEditing && hadPublishedVersion;
7076
- if (isApproved) {
7128
+ if (!isEditing && preStatus === "published") {
7077
7129
  lifecycleStats.published++;
7078
7130
  } else if (preStatus === "modified" || hadPublishedVersion && isEditing) {
7079
7131
  lifecycleStats.modified++;