@payloadcms/plugin-import-export 4.0.0-internal.43ccea7 → 4.0.0-internal.44ac9c8

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.
Files changed (146) hide show
  1. package/dist/components/CollectionField/index.d.ts +3 -2
  2. package/dist/components/CollectionField/index.d.ts.map +1 -1
  3. package/dist/components/CollectionField/index.js.map +1 -1
  4. package/dist/components/ExportListMenuItem/index.d.ts.map +1 -1
  5. package/dist/components/ExportListMenuItem/index.js +14 -12
  6. package/dist/components/ExportListMenuItem/index.js.map +1 -1
  7. package/dist/components/ExportPreview/index.d.ts.map +1 -1
  8. package/dist/components/ExportPreview/index.js +11 -1
  9. package/dist/components/ExportPreview/index.js.map +1 -1
  10. package/dist/components/FieldsToExport/index.d.ts +3 -2
  11. package/dist/components/FieldsToExport/index.d.ts.map +1 -1
  12. package/dist/components/FieldsToExport/index.js.map +1 -1
  13. package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -1
  14. package/dist/components/FormatField/index.d.ts +3 -2
  15. package/dist/components/FormatField/index.d.ts.map +1 -1
  16. package/dist/components/FormatField/index.js.map +1 -1
  17. package/dist/components/ImportListMenuItem/index.d.ts.map +1 -1
  18. package/dist/components/ImportListMenuItem/index.js +14 -12
  19. package/dist/components/ImportListMenuItem/index.js.map +1 -1
  20. package/dist/components/ImportPreview/index.d.ts.map +1 -1
  21. package/dist/components/ImportPreview/index.js +17 -1
  22. package/dist/components/ImportPreview/index.js.map +1 -1
  23. package/dist/components/LimitField/index.d.ts +3 -2
  24. package/dist/components/LimitField/index.d.ts.map +1 -1
  25. package/dist/components/LimitField/index.js.map +1 -1
  26. package/dist/components/LocaleField/index.d.ts +3 -2
  27. package/dist/components/LocaleField/index.d.ts.map +1 -1
  28. package/dist/components/LocaleField/index.js.map +1 -1
  29. package/dist/components/Page/index.d.ts +3 -2
  30. package/dist/components/Page/index.d.ts.map +1 -1
  31. package/dist/components/Page/index.js.map +1 -1
  32. package/dist/components/SortBy/index.d.ts +3 -2
  33. package/dist/components/SortBy/index.d.ts.map +1 -1
  34. package/dist/components/SortBy/index.js.map +1 -1
  35. package/dist/components/SortOrder/index.d.ts +3 -2
  36. package/dist/components/SortOrder/index.d.ts.map +1 -1
  37. package/dist/components/SortOrder/index.js.map +1 -1
  38. package/dist/export/batchProcessor.d.ts +2 -1
  39. package/dist/export/batchProcessor.d.ts.map +1 -1
  40. package/dist/export/batchProcessor.js +6 -2
  41. package/dist/export/batchProcessor.js.map +1 -1
  42. package/dist/export/createExport.d.ts +2 -0
  43. package/dist/export/createExport.d.ts.map +1 -1
  44. package/dist/export/createExport.js +6 -1
  45. package/dist/export/createExport.js.map +1 -1
  46. package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
  47. package/dist/export/getCreateExportCollectionTask.js +11 -0
  48. package/dist/export/getCreateExportCollectionTask.js.map +1 -1
  49. package/dist/export/getExportCollection.d.ts.map +1 -1
  50. package/dist/export/getExportCollection.js +5 -0
  51. package/dist/export/getExportCollection.js.map +1 -1
  52. package/dist/export/getFields.d.ts.map +1 -1
  53. package/dist/export/handleDownload.d.ts.map +1 -1
  54. package/dist/export/handleDownload.js +7 -3
  55. package/dist/export/handleDownload.js.map +1 -1
  56. package/dist/export/handlePreview.d.ts.map +1 -1
  57. package/dist/export/handlePreview.js +24 -5
  58. package/dist/export/handlePreview.js.map +1 -1
  59. package/dist/exports/types.d.ts +1 -1
  60. package/dist/exports/types.d.ts.map +1 -1
  61. package/dist/exports/types.js.map +1 -1
  62. package/dist/import/batchProcessor.d.ts +2 -1
  63. package/dist/import/batchProcessor.d.ts.map +1 -1
  64. package/dist/import/batchProcessor.js +15 -8
  65. package/dist/import/batchProcessor.js.map +1 -1
  66. package/dist/import/createImport.d.ts +3 -2
  67. package/dist/import/createImport.d.ts.map +1 -1
  68. package/dist/import/createImport.js +8 -1
  69. package/dist/import/createImport.js.map +1 -1
  70. package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
  71. package/dist/import/getCreateImportCollectionTask.js +5 -2
  72. package/dist/import/getCreateImportCollectionTask.js.map +1 -1
  73. package/dist/import/getFields.d.ts.map +1 -1
  74. package/dist/import/getImportCollection.d.ts.map +1 -1
  75. package/dist/import/getImportCollection.js +2 -0
  76. package/dist/import/getImportCollection.js.map +1 -1
  77. package/dist/import/handlePreview.d.ts.map +1 -1
  78. package/dist/import/handlePreview.js +5 -1
  79. package/dist/import/handlePreview.js.map +1 -1
  80. package/dist/translations/languages/en.d.ts.map +1 -1
  81. package/dist/types.d.ts +17 -1
  82. package/dist/types.d.ts.map +1 -1
  83. package/dist/types.js.map +1 -1
  84. package/dist/utilities/applyFieldHooks.d.ts.map +1 -1
  85. package/dist/utilities/buildDisabledFieldRegex.d.ts.map +1 -1
  86. package/dist/utilities/collectDisabledFieldPaths.d.ts.map +1 -1
  87. package/dist/utilities/fieldToRegex.d.ts.map +1 -1
  88. package/dist/utilities/flattenObject.d.ts.map +1 -1
  89. package/dist/utilities/flattenedFields.d.ts.map +1 -1
  90. package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
  91. package/dist/utilities/getFileFromDoc.d.ts.map +1 -1
  92. package/dist/utilities/getFileFromDoc.js +3 -3
  93. package/dist/utilities/getFileFromDoc.js.map +1 -1
  94. package/dist/utilities/getFlattenedFieldKeys.d.ts.map +1 -1
  95. package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
  96. package/dist/utilities/getPluginCollections.d.ts.map +1 -1
  97. package/dist/utilities/getSchemaColumns.d.ts.map +1 -1
  98. package/dist/utilities/getSelect.d.ts.map +1 -1
  99. package/dist/utilities/getSelect.js +11 -3
  100. package/dist/utilities/getSelect.js.map +1 -1
  101. package/dist/utilities/getSubmittedFormValues.d.ts +12 -0
  102. package/dist/utilities/getSubmittedFormValues.d.ts.map +1 -0
  103. package/dist/utilities/getSubmittedFormValues.js +24 -0
  104. package/dist/utilities/getSubmittedFormValues.js.map +1 -0
  105. package/dist/utilities/isPlainObject.d.ts.map +1 -1
  106. package/dist/utilities/parseCSV.d.ts.map +1 -1
  107. package/dist/utilities/parseJSON.d.ts.map +1 -1
  108. package/dist/utilities/polymorphicRel.d.ts.map +1 -1
  109. package/dist/utilities/processRichTextField.d.ts.map +1 -1
  110. package/dist/utilities/removeDisabledFields.d.ts.map +1 -1
  111. package/dist/utilities/setNestedValue.d.ts +2 -1
  112. package/dist/utilities/setNestedValue.d.ts.map +1 -1
  113. package/dist/utilities/setNestedValue.js +65 -34
  114. package/dist/utilities/setNestedValue.js.map +1 -1
  115. package/dist/utilities/sortHelpers.d.ts +1 -1
  116. package/dist/utilities/sortHelpers.d.ts.map +1 -1
  117. package/dist/utilities/unflattenObject.d.ts.map +1 -1
  118. package/dist/utilities/unflattenPostProcess.d.ts.map +1 -1
  119. package/dist/utilities/validateLimitValue.d.ts.map +1 -1
  120. package/package.json +8 -8
  121. package/dist/components/FieldsToExport/reduceFields.spec.js +0 -239
  122. package/dist/components/FieldsToExport/reduceFields.spec.js.map +0 -1
  123. package/dist/utilities/applyFieldHooks.spec.js +0 -205
  124. package/dist/utilities/applyFieldHooks.spec.js.map +0 -1
  125. package/dist/utilities/buildDisabledFieldRegex.spec.js +0 -64
  126. package/dist/utilities/buildDisabledFieldRegex.spec.js.map +0 -1
  127. package/dist/utilities/fieldToRegex.spec.js +0 -151
  128. package/dist/utilities/fieldToRegex.spec.js.map +0 -1
  129. package/dist/utilities/filterToSelectedFields.spec.js +0 -204
  130. package/dist/utilities/filterToSelectedFields.spec.js.map +0 -1
  131. package/dist/utilities/flattenObject.spec.js +0 -158
  132. package/dist/utilities/flattenObject.spec.js.map +0 -1
  133. package/dist/utilities/getExportFieldFunctions.spec.js +0 -50
  134. package/dist/utilities/getExportFieldFunctions.spec.js.map +0 -1
  135. package/dist/utilities/getImportFieldFunctions.spec.js +0 -167
  136. package/dist/utilities/getImportFieldFunctions.spec.js.map +0 -1
  137. package/dist/utilities/getSchemaColumns.spec.js +0 -157
  138. package/dist/utilities/getSchemaColumns.spec.js.map +0 -1
  139. package/dist/utilities/parseCSV.spec.js +0 -195
  140. package/dist/utilities/parseCSV.spec.js.map +0 -1
  141. package/dist/utilities/processRichTextField.spec.js +0 -308
  142. package/dist/utilities/processRichTextField.spec.js.map +0 -1
  143. package/dist/utilities/siblingDoc.spec.js +0 -278
  144. package/dist/utilities/siblingDoc.spec.js.map +0 -1
  145. package/dist/utilities/unflattenObject.spec.js +0 -819
  146. package/dist/utilities/unflattenObject.spec.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAQ,KAAK,EAAE,MAAM,SAAS,CAAA;AAgBhE,MAAM,MAAM,MAAM,GAAG;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,KAAK,CAAA;IACrB,gBAAgB,EAAE,MAAM,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CA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EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,SAAS,CAAA;IACpB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,YAAY,SAAgB,gBAAgB,kCAsmBxD,CAAA"}
@@ -11,7 +11,7 @@ import { getSelect } from '../utilities/getSelect.js';
11
11
  import { validateLimitValue } from '../utilities/validateLimitValue.js';
12
12
  import { createExportBatchProcessor } from './batchProcessor.js';
13
13
  export const createExport = async (args)=>{
14
- const { id, name: nameArg, batchSize = 100, collectionSlug, debug = false, download, drafts: draftsFromInput, exportCollection, fields, format, limit: incomingLimit, maxLimit, locale: localeFromInput, page, req, sort, userCollection, userID, where: whereFromInput = {} } = args;
14
+ const { id, name: nameArg, batchSize = 100, collectionSlug, debug = false, download, drafts: draftsFromInput, exportCollection, exportDoc, fields, format, limit: incomingLimit, maxLimit, locale: localeFromInput, page, req, sort, userCollection, userID, where: whereFromInput = {} } = args;
15
15
  const { locale: localeFromReq, payload } = req;
16
16
  if (debug) {
17
17
  req.payload.logger.debug({
@@ -242,6 +242,7 @@ export const createExport = async (args)=>{
242
242
  batchRowsToWrite = await exportHooks.before({
243
243
  batchNumber: streamBatchNumber,
244
244
  data: batchRows,
245
+ exportDoc,
245
246
  format,
246
247
  originalData: originalDocs,
247
248
  req,
@@ -291,6 +292,7 @@ export const createExport = async (args)=>{
291
292
  await exportHooks.after({
292
293
  batchNumber: streamBatchNumber,
293
294
  data: batchRowsToWrite,
295
+ exportDoc,
294
296
  format,
295
297
  originalData: originalDocs,
296
298
  req,
@@ -314,6 +316,7 @@ export const createExport = async (args)=>{
314
316
  batchRowsToWrite = await exportHooks.before({
315
317
  batchNumber: streamBatchNumber,
316
318
  data: batchRows,
319
+ exportDoc,
317
320
  format,
318
321
  originalData: originalDocs,
319
322
  req,
@@ -331,6 +334,7 @@ export const createExport = async (args)=>{
331
334
  await exportHooks.after({
332
335
  batchNumber: streamBatchNumber,
333
336
  data: batchRowsToWrite,
337
+ exportDoc,
334
338
  format,
335
339
  originalData: originalDocs,
336
340
  req,
@@ -393,6 +397,7 @@ export const createExport = async (args)=>{
393
397
  if (!accessDenied) {
394
398
  exportResult = await processor.processExport({
395
399
  collectionSlug,
400
+ exportDoc,
396
401
  findArgs: findArgs,
397
402
  format,
398
403
  hooks: exportHooks,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, User, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { buildDisabledFieldRegex } from '../utilities/buildDisabledFieldRegex.js'\nimport { flattenObject } from '../utilities/flattenObject.js'\nimport { getExportFieldFunctions } from '../utilities/getExportFieldFunctions.js'\nimport { getFilename } from '../utilities/getFilename.js'\nimport { getSchemaColumns, mergeColumns } from '../utilities/getSchemaColumns.js'\nimport { getSelect } from '../utilities/getSelect.js'\nimport { validateLimitValue } from '../utilities/validateLimitValue.js'\nimport { createExportBatchProcessor, type ExportFindArgs } from './batchProcessor.js'\n\nexport type Export = {\n /**\n * Number of documents to process in each batch during export\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n limit?: number\n locale?: string\n /**\n * Maximum number of documents that can be exported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n page?: number\n sort?: Sort\n userCollection?: string\n userID?: number | string\n where?: Where\n}\n\nexport type CreateExportArgs = {\n /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n req: PayloadRequest\n} & Export\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n id,\n name: nameArg,\n batchSize = 100,\n collectionSlug,\n debug = false,\n download,\n drafts: draftsFromInput,\n exportCollection,\n fields,\n format,\n limit: incomingLimit,\n maxLimit,\n locale: localeFromInput,\n page,\n req,\n sort,\n userCollection,\n userID,\n where: whereFromInput = {},\n } = args\n const { locale: localeFromReq, payload } = req\n\n if (debug) {\n req.payload.logger.debug({\n msg: '[createExport] Starting export process',\n exportDocId: id,\n exportName: nameArg,\n collectionSlug,\n exportCollection,\n draft: draftsFromInput,\n fields,\n format,\n })\n }\n\n const locale = localeFromInput ?? localeFromReq\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found.`)\n }\n\n let user: undefined | User\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n overrideAccess: true,\n })) as User\n }\n\n if (!user && req.user) {\n user = req.user\n }\n\n if (!user) {\n throw new APIError('User authentication is required to create exports.')\n }\n\n const draft = draftsFromInput === 'yes'\n const hasVersions = Boolean(collectionConfig.versions)\n\n // Only filter by _status for versioned collections\n const publishedWhere: Where = hasVersions ? { _status: { equals: 'published' } } : {}\n\n const where: Where = {\n and: [whereFromInput, draft ? {} : publishedWhere],\n }\n\n const baseName = nameArg ?? getFilename()\n const name = `${baseName}-${collectionSlug}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.debug({ isCSV, locale, msg: 'Export configuration:', name })\n }\n\n // Determine maximum export documents:\n // 1. If maxLimit is defined, it sets the absolute ceiling\n // 2. User's limit is applied but clamped to maxLimit if it exceeds it\n let maxExportDocuments: number | undefined\n\n if (typeof maxLimit === 'number' && maxLimit > 0) {\n if (typeof incomingLimit === 'number' && incomingLimit > 0) {\n // User provided a limit - clamp it to maxLimit\n maxExportDocuments = Math.min(incomingLimit, maxLimit)\n } else {\n // No user limit - use maxLimit as the ceiling\n maxExportDocuments = maxLimit\n }\n } else {\n // No maxLimit - use user's limit if provided\n maxExportDocuments =\n typeof incomingLimit === 'number' && incomingLimit > 0 ? incomingLimit : undefined\n }\n\n // Try to count documents - if access is denied, treat as 0 documents\n let totalDocs = 0\n let accessDenied = false\n try {\n const countResult = await payload.count({\n collection: collectionSlug,\n user,\n locale,\n overrideAccess: false,\n })\n totalDocs = countResult.totalDocs\n } catch (error) {\n // Access denied - user can't read from this collection\n // We'll create an empty export file\n accessDenied = true\n if (debug) {\n req.payload.logger.debug({\n collectionSlug,\n msg: 'Access denied for collection, creating empty export',\n })\n }\n }\n\n const totalPages = Math.max(1, Math.ceil(totalDocs / batchSize))\n const requestedPage = page || 1\n const adjustedPage = requestedPage > totalPages ? 1 : requestedPage\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft,\n limit: batchSize,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.debug({ findArgs, msg: 'Find arguments:' })\n }\n\n const exportFieldHooks = getExportFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n const exportHooks = collectionConfig.custom?.['plugin-import-export']?.exportHooks\n\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const disabledMatchers = disabledFields.map(buildDisabledFieldRegex)\n\n const filterDisabledCSV = (row: Record<string, unknown>): Record<string, unknown> => {\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(row)) {\n const isDisabled = disabledMatchers.some((matcher) => matcher.test(key))\n if (!isDisabled) {\n filtered[key] = value\n }\n }\n\n return filtered\n }\n\n const filterDisabledJSON = (doc: unknown, parentPath = ''): unknown => {\n if (Array.isArray(doc)) {\n return doc.map((item) => filterDisabledJSON(item, parentPath))\n }\n\n if (typeof doc !== 'object' || doc === null) {\n return doc\n }\n\n const filtered: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(doc as Record<string, unknown>)) {\n const currentPath = parentPath ? `${parentPath}.${key}` : key\n\n // Only remove if this exact path is disabled\n const isDisabled = disabledFields.includes(currentPath)\n\n if (!isDisabled) {\n filtered[key] = filterDisabledJSON(value, currentPath)\n }\n }\n\n return filtered\n }\n\n if (download) {\n const limitErrorMsg = validateLimitValue(incomingLimit, req.t)\n if (limitErrorMsg) {\n throw new APIError(limitErrorMsg)\n }\n\n // Get schema-based columns first (provides base ordering and handles empty exports)\n let schemaColumns: string[] = []\n if (isCSV) {\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n if (debug) {\n req.payload.logger.debug({\n columnCount: schemaColumns.length,\n msg: 'Schema-based column inference complete',\n })\n }\n }\n\n // allColumns will be finalized after first batch (schema + data columns merged)\n let allColumns: string[] = []\n let columnsFinalized = false\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let currentBatchPage = adjustedPage\n let fetched = 0\n const maxDocs =\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY\n\n const effectiveStreamDocs =\n typeof maxExportDocuments === 'number' ? Math.min(totalDocs, maxExportDocuments) : totalDocs\n const totalBatches = effectiveStreamDocs > 0 ? Math.ceil(effectiveStreamDocs / batchSize) : 1\n let streamBatchNumber = 0\n\n const stream = new Readable({\n async read() {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n if (!isCSV) {\n // If first batch with no remaining, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n const result = await payload.find({\n ...findArgs,\n page: currentBatchPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Streaming batch ${currentBatchPage} with ${result.docs.length} docs`,\n )\n }\n\n if (result.docs.length === 0) {\n // Close JSON array properly if JSON\n if (!isCSV) {\n // If first batch with no docs, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n streamBatchNumber++\n\n if (isCSV) {\n // --- CSV Streaming ---\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(\n flattenObject({\n data: doc as Record<string, unknown>,\n fields,\n format,\n exportFieldHooks,\n req,\n }),\n ),\n )\n\n const originalDocs = result.docs as Record<string, unknown>[]\n let batchRowsToWrite = batchRows\n if (exportHooks?.before && batchRows.length > 0) {\n batchRowsToWrite = await exportHooks.before({\n batchNumber: streamBatchNumber,\n data: batchRows,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n // On first batch, discover additional columns from data and merge with schema\n if (!columnsFinalized) {\n const dataColumns: string[] = []\n const seenCols = new Set<string>()\n for (const row of batchRowsToWrite) {\n for (const key of Object.keys(row)) {\n if (!seenCols.has(key)) {\n seenCols.add(key)\n dataColumns.push(key)\n }\n }\n }\n // Merge schema columns with data-discovered columns.\n // When a before hook is active and rows exist, restrict to columns actually present\n // in the data so that the hook can remove fields by not returning them.\n const mergedColumns = mergeColumns(schemaColumns, dataColumns)\n allColumns =\n Boolean(exportHooks?.before) && batchRowsToWrite.length > 0\n ? mergedColumns.filter((col) => dataColumns.includes(col))\n : mergedColumns\n columnsFinalized = true\n\n if (debug) {\n req.payload.logger.debug({\n dataColumnsCount: dataColumns.length,\n finalColumnsCount: allColumns.length,\n msg: 'Merged schema and data columns',\n })\n }\n }\n\n const paddedRows = batchRowsToWrite.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of allColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n const csvString = stringify(paddedRows, {\n bom: isFirstBatch,\n header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n\n if (exportHooks?.after && batchRowsToWrite.length > 0) {\n await exportHooks.after({\n batchNumber: streamBatchNumber,\n data: batchRowsToWrite,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n } else {\n // --- JSON Streaming ---\n const batchRows = result.docs.map(\n (doc) =>\n filterDisabledJSON(\n applyFieldHooks({\n data: doc as Record<string, unknown>,\n fieldHooks: exportFieldHooks,\n fields: collectionConfig.flattenedFields,\n format,\n operation: 'export',\n req,\n type: 'beforeExport',\n }),\n ) as Record<string, unknown>,\n )\n\n const originalDocs = result.docs as Record<string, unknown>[]\n let batchRowsToWrite = batchRows\n if (exportHooks?.before && batchRows.length > 0) {\n batchRowsToWrite = await exportHooks.before({\n batchNumber: streamBatchNumber,\n data: batchRows,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n // Convert each filtered/flattened row into JSON string\n const batchJSON = batchRowsToWrite.map((row) => JSON.stringify(row)).join(',')\n\n if (isFirstBatch) {\n this.push(encoder.encode('[' + batchJSON))\n } else {\n this.push(encoder.encode(',' + batchJSON))\n }\n\n if (exportHooks?.after && batchRowsToWrite.length > 0) {\n await exportHooks.after({\n batchNumber: streamBatchNumber,\n data: batchRowsToWrite,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n }\n\n fetched += result.docs.length\n isFirstBatch = false\n currentBatchPage += 1\n\n if (!result.hasNextPage || fetched >= maxDocs) {\n if (debug) {\n req.payload.logger.debug('Stream complete - no more pages')\n }\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(Readable.toWeb(stream) as ReadableStream, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n },\n })\n }\n\n // Non-download path (buffered export)\n if (debug) {\n req.payload.logger.debug('Starting file generation')\n }\n\n // Create export batch processor\n const processor = createExportBatchProcessor({ batchSize, debug })\n\n // Transform function based on format\n const transformDoc = (doc: unknown) =>\n isCSV\n ? filterDisabledCSV(\n flattenObject({\n data: doc as Record<string, unknown>,\n fields,\n format,\n exportFieldHooks,\n req,\n }),\n )\n : (filterDisabledJSON(\n applyFieldHooks({\n data: doc as Record<string, unknown>,\n fieldHooks: exportFieldHooks,\n fields: collectionConfig.flattenedFields,\n format,\n operation: 'export',\n req,\n type: 'beforeExport',\n }),\n ) as Record<string, unknown>)\n\n // Skip fetching if access was denied - we'll create an empty export\n let exportResult = {\n columns: [] as string[],\n docs: [] as Record<string, unknown>[],\n fetchedCount: 0,\n }\n\n if (!accessDenied) {\n exportResult = await processor.processExport({\n collectionSlug,\n findArgs: findArgs as ExportFindArgs,\n format,\n hooks: exportHooks,\n maxDocs:\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY,\n req,\n startPage: adjustedPage,\n totalDocs,\n transformDoc,\n })\n }\n\n const { columns: dataColumns, docs: rows } = exportResult\n const outputData: string[] = []\n\n // Prepare final output\n if (isCSV) {\n // Get schema-based columns for consistent ordering\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n const schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n // Merge schema columns with data-discovered columns\n // Schema provides ordering, data provides additional columns (e.g., array indices > 0)\n // When a before hook is active and rows exist, restrict to columns actually present in the data\n // so that the hook can remove fields by not returning them\n const mergedColumns = mergeColumns(schemaColumns, dataColumns)\n const finalColumns =\n Boolean(exportHooks?.before) && rows.length > 0\n ? mergedColumns.filter((col) => dataColumns.includes(col))\n : mergedColumns\n\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of finalColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n // Always output CSV with header, even if empty\n outputData.push(\n stringify(paddedRows, {\n bom: true,\n header: true,\n columns: finalColumns,\n }),\n )\n } else {\n // JSON format\n outputData.push(rows.map((doc) => JSON.stringify(doc)).join(',\\n'))\n }\n\n // Ensure we always have valid content for the file\n // For JSON, empty exports produce \"[]\"\n // For CSV, if completely empty (no columns, no rows), produce at least a newline to ensure file creation\n const content = format === 'json' ? `[${outputData.join(',')}]` : outputData.join('')\n const buffer = Buffer.from(content.length > 0 ? content : '\\n')\n if (debug) {\n req.payload.logger.debug(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.debug('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.debug({\n msg: '[createExport] Updating export document with file',\n exportDocId: id,\n exportCollection,\n fileName: name,\n fileSize: buffer.length,\n mimeType: isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n })\n }\n try {\n await req.payload.update({\n id,\n collection: exportCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n size: buffer.length,\n },\n // Override access only here so that we can be sure the export collection itself is updated as expected\n overrideAccess: true,\n req,\n })\n } catch (error) {\n const errorDetails =\n error instanceof Error\n ? {\n message: error.message,\n name: error.name,\n stack: error.stack,\n // @ts-expect-error - data might exist on Payload errors\n data: error.data,\n }\n : error\n req.payload.logger.error({\n msg: '[createExport] Failed to update export document with file',\n err: errorDetails,\n exportDocId: id,\n exportCollection,\n fileName: name,\n })\n throw error\n }\n }\n if (debug) {\n req.payload.logger.debug('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","applyFieldHooks","buildDisabledFieldRegex","flattenObject","getExportFieldFunctions","getFilename","getSchemaColumns","mergeColumns","getSelect","validateLimitValue","createExportBatchProcessor","createExport","args","id","name","nameArg","batchSize","collectionSlug","debug","download","drafts","draftsFromInput","exportCollection","fields","format","limit","incomingLimit","maxLimit","locale","localeFromInput","page","req","sort","userCollection","userID","where","whereFromInput","localeFromReq","payload","logger","msg","exportDocId","exportName","draft","collectionConfig","config","collections","find","slug","user","findByID","collection","overrideAccess","hasVersions","Boolean","versions","publishedWhere","_status","equals","and","baseName","isCSV","select","Array","isArray","length","undefined","maxExportDocuments","Math","min","totalDocs","accessDenied","countResult","count","error","totalPages","max","ceil","requestedPage","adjustedPage","findArgs","depth","exportFieldHooks","flattenedFields","exportHooks","custom","disabledFields","admin","disabledMatchers","map","filterDisabledCSV","row","filtered","key","value","Object","entries","isDisabled","some","matcher","test","filterDisabledJSON","doc","parentPath","item","currentPath","includes","limitErrorMsg","t","schemaColumns","localeCodes","localization","columnCount","allColumns","columnsFinalized","encoder","TextEncoder","isFirstBatch","currentBatchPage","fetched","maxDocs","Number","POSITIVE_INFINITY","effectiveStreamDocs","totalBatches","streamBatchNumber","stream","read","remaining","push","encode","result","docs","batchRows","data","originalDocs","batchRowsToWrite","before","batchNumber","originalData","dataColumns","seenCols","Set","keys","has","add","mergedColumns","filter","col","dataColumnsCount","finalColumnsCount","paddedRows","fullRow","csvString","bom","header","columns","after","fieldHooks","operation","type","batchJSON","JSON","join","hasNextPage","Response","toWeb","headers","processor","transformDoc","exportResult","fetchedCount","processExport","hooks","startPage","rows","outputData","finalColumns","content","buffer","Buffer","from","file","mimetype","size","fileName","fileSize","mimeType","update","errorDetails","Error","message","stack","err"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAEjC,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,gBAAgB,EAAEC,YAAY,QAAQ,mCAAkC;AACjF,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,0BAA0B,QAA6B,sBAAqB;AA0CrF,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,EAAE,EACFC,MAAMC,OAAO,EACbC,YAAY,GAAG,EACfC,cAAc,EACdC,QAAQ,KAAK,EACbC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B;YAC9C2H,MAAML,OAAOlH,MAAM;QACrB;IACF,OAAO;QACL,IAAI/C,OAAO;YACTa,IAAIO,OAAO,CAACC,MAAM,CAACrB,KAAK,CAAC;gBACvBsB,KAAK;gBACLC,aAAa5B;gBACbS;gBACAmK,UAAU3K;gBACV4K,UAAUP,OAAOlH,MAAM;gBACvB0H,UAAU9H,QAAQ,4BAA4B;YAChD;QACF;QACA,IAAI;YACF,MAAM9B,IAAIO,OAAO,CAACsJ,MAAM,CAAC;gBACvB/K;gBACAsC,YAAY7B;gBACZgH,MAAM,CAAC;gBACPgD,MAAM;oBACJxK;oBACAwH,MAAM6C;oBACNI,UAAU1H,QAAQ,4BAA4B;oBAC9C2H,MAAML,OAAOlH,MAAM;gBACrB;gBACA,uGAAuG;gBACvGb,gBAAgB;gBAChBrB;YACF;QACF,EAAE,OAAO2C,OAAO;YACd,MAAMmH,eACJnH,iBAAiBoH,QACb;gBACEC,SAASrH,MAAMqH,OAAO;gBACtBjL,MAAM4D,MAAM5D,IAAI;gBAChBkL,OAAOtH,MAAMsH,KAAK;gBAClB,wDAAwD;gBACxD1D,MAAM5D,MAAM4D,IAAI;YAClB,IACA5D;YACN3C,IAAIO,OAAO,CAACC,MAAM,CAACmC,KAAK,CAAC;gBACvBlC,KAAK;gBACLyJ,KAAKJ;gBACLpJ,aAAa5B;gBACbS;gBACAmK,UAAU3K;YACZ;YACA,MAAM4D;QACR;IACF;IACA,IAAIxD,OAAO;QACTa,IAAIO,OAAO,CAACC,MAAM,CAACrB,KAAK,CAAC;IAC3B;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, User, Where } from 'payload'\n\nimport { stringify } from 'csv-stringify/sync'\nimport { APIError } from 'payload'\nimport { Readable } from 'stream'\n\nimport type { ExportDoc } from '../types.js'\n\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { buildDisabledFieldRegex } from '../utilities/buildDisabledFieldRegex.js'\nimport { flattenObject } from '../utilities/flattenObject.js'\nimport { getExportFieldFunctions } from '../utilities/getExportFieldFunctions.js'\nimport { getFilename } from '../utilities/getFilename.js'\nimport { getSchemaColumns, mergeColumns } from '../utilities/getSchemaColumns.js'\nimport { getSelect } from '../utilities/getSelect.js'\nimport { validateLimitValue } from '../utilities/validateLimitValue.js'\nimport { createExportBatchProcessor, type ExportFindArgs } from './batchProcessor.js'\n\nexport type Export = {\n /**\n * Number of documents to process in each batch during export\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enables debug logging\n */\n debug?: boolean\n drafts?: 'no' | 'yes'\n exportCollection: string\n fields?: string[]\n format: 'csv' | 'json'\n globals?: string[]\n id: number | string\n limit?: number\n locale?: string\n /**\n * Maximum number of documents that can be exported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n page?: number\n sort?: Sort\n userCollection?: string\n userID?: number | string\n where?: Where\n}\n\nexport type CreateExportArgs = {\n /**\n * If true, stream the file instead of saving it\n */\n download?: boolean\n exportDoc: ExportDoc\n req: PayloadRequest\n} & Export\n\nexport const createExport = async (args: CreateExportArgs) => {\n const {\n id,\n name: nameArg,\n batchSize = 100,\n collectionSlug,\n debug = false,\n download,\n drafts: draftsFromInput,\n exportCollection,\n exportDoc,\n fields,\n format,\n limit: incomingLimit,\n maxLimit,\n locale: localeFromInput,\n page,\n req,\n sort,\n userCollection,\n userID,\n where: whereFromInput = {},\n } = args\n const { locale: localeFromReq, payload } = req\n\n if (debug) {\n req.payload.logger.debug({\n msg: '[createExport] Starting export process',\n exportDocId: id,\n exportName: nameArg,\n collectionSlug,\n exportCollection,\n draft: draftsFromInput,\n fields,\n format,\n })\n }\n\n const locale = localeFromInput ?? localeFromReq\n const collectionConfig = payload.config.collections.find(({ slug }) => slug === collectionSlug)\n\n if (!collectionConfig) {\n throw new APIError(`Collection with slug ${collectionSlug} not found.`)\n }\n\n let user: undefined | User\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n overrideAccess: true,\n })) as User\n }\n\n if (!user && req.user) {\n user = req.user\n }\n\n if (!user) {\n throw new APIError('User authentication is required to create exports.')\n }\n\n const draft = draftsFromInput === 'yes'\n const hasVersions = Boolean(collectionConfig.versions)\n\n // Only filter by _status for versioned collections\n const publishedWhere: Where = hasVersions ? { _status: { equals: 'published' } } : {}\n\n const where: Where = {\n and: [whereFromInput, draft ? {} : publishedWhere],\n }\n\n const baseName = nameArg ?? getFilename()\n const name = `${baseName}-${collectionSlug}.${format}`\n const isCSV = format === 'csv'\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n if (debug) {\n req.payload.logger.debug({ isCSV, locale, msg: 'Export configuration:', name })\n }\n\n // Determine maximum export documents:\n // 1. If maxLimit is defined, it sets the absolute ceiling\n // 2. User's limit is applied but clamped to maxLimit if it exceeds it\n let maxExportDocuments: number | undefined\n\n if (typeof maxLimit === 'number' && maxLimit > 0) {\n if (typeof incomingLimit === 'number' && incomingLimit > 0) {\n // User provided a limit - clamp it to maxLimit\n maxExportDocuments = Math.min(incomingLimit, maxLimit)\n } else {\n // No user limit - use maxLimit as the ceiling\n maxExportDocuments = maxLimit\n }\n } else {\n // No maxLimit - use user's limit if provided\n maxExportDocuments =\n typeof incomingLimit === 'number' && incomingLimit > 0 ? incomingLimit : undefined\n }\n\n // Try to count documents - if access is denied, treat as 0 documents\n let totalDocs = 0\n let accessDenied = false\n try {\n const countResult = await payload.count({\n collection: collectionSlug,\n user,\n locale,\n overrideAccess: false,\n })\n totalDocs = countResult.totalDocs\n } catch (error) {\n // Access denied - user can't read from this collection\n // We'll create an empty export file\n accessDenied = true\n if (debug) {\n req.payload.logger.debug({\n collectionSlug,\n msg: 'Access denied for collection, creating empty export',\n })\n }\n }\n\n const totalPages = Math.max(1, Math.ceil(totalDocs / batchSize))\n const requestedPage = page || 1\n const adjustedPage = requestedPage > totalPages ? 1 : requestedPage\n\n const findArgs = {\n collection: collectionSlug,\n depth: 1,\n draft,\n limit: batchSize,\n locale,\n overrideAccess: false,\n page: 0,\n select,\n sort,\n user,\n where,\n }\n\n if (debug) {\n req.payload.logger.debug({ findArgs, msg: 'Find arguments:' })\n }\n\n const exportFieldHooks = getExportFieldFunctions({\n fields: collectionConfig.flattenedFields,\n })\n\n const exportHooks = collectionConfig.custom?.['plugin-import-export']?.exportHooks\n\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const disabledMatchers = disabledFields.map(buildDisabledFieldRegex)\n\n const filterDisabledCSV = (row: Record<string, unknown>): Record<string, unknown> => {\n const filtered: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(row)) {\n const isDisabled = disabledMatchers.some((matcher) => matcher.test(key))\n if (!isDisabled) {\n filtered[key] = value\n }\n }\n\n return filtered\n }\n\n const filterDisabledJSON = (doc: unknown, parentPath = ''): unknown => {\n if (Array.isArray(doc)) {\n return doc.map((item) => filterDisabledJSON(item, parentPath))\n }\n\n if (typeof doc !== 'object' || doc === null) {\n return doc\n }\n\n const filtered: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(doc as Record<string, unknown>)) {\n const currentPath = parentPath ? `${parentPath}.${key}` : key\n\n // Only remove if this exact path is disabled\n const isDisabled = disabledFields.includes(currentPath)\n\n if (!isDisabled) {\n filtered[key] = filterDisabledJSON(value, currentPath)\n }\n }\n\n return filtered\n }\n\n if (download) {\n const limitErrorMsg = validateLimitValue(incomingLimit, req.t)\n if (limitErrorMsg) {\n throw new APIError(limitErrorMsg)\n }\n\n // Get schema-based columns first (provides base ordering and handles empty exports)\n let schemaColumns: string[] = []\n if (isCSV) {\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n if (debug) {\n req.payload.logger.debug({\n columnCount: schemaColumns.length,\n msg: 'Schema-based column inference complete',\n })\n }\n }\n\n // allColumns will be finalized after first batch (schema + data columns merged)\n let allColumns: string[] = []\n let columnsFinalized = false\n\n const encoder = new TextEncoder()\n let isFirstBatch = true\n let currentBatchPage = adjustedPage\n let fetched = 0\n const maxDocs =\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY\n\n const effectiveStreamDocs =\n typeof maxExportDocuments === 'number' ? Math.min(totalDocs, maxExportDocuments) : totalDocs\n const totalBatches = effectiveStreamDocs > 0 ? Math.ceil(effectiveStreamDocs / batchSize) : 1\n let streamBatchNumber = 0\n\n const stream = new Readable({\n async read() {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n if (!isCSV) {\n // If first batch with no remaining, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n const result = await payload.find({\n ...findArgs,\n page: currentBatchPage,\n limit: Math.min(batchSize, remaining),\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Streaming batch ${currentBatchPage} with ${result.docs.length} docs`,\n )\n }\n\n if (result.docs.length === 0) {\n // Close JSON array properly if JSON\n if (!isCSV) {\n // If first batch with no docs, output empty array; otherwise just close\n this.push(encoder.encode(isFirstBatch ? '[]' : ']'))\n }\n this.push(null)\n return\n }\n\n streamBatchNumber++\n\n if (isCSV) {\n // --- CSV Streaming ---\n const batchRows = result.docs.map((doc) =>\n filterDisabledCSV(\n flattenObject({\n data: doc as Record<string, unknown>,\n fields,\n format,\n exportFieldHooks,\n req,\n }),\n ),\n )\n\n const originalDocs = result.docs as Record<string, unknown>[]\n let batchRowsToWrite = batchRows\n if (exportHooks?.before && batchRows.length > 0) {\n batchRowsToWrite = await exportHooks.before({\n batchNumber: streamBatchNumber,\n data: batchRows,\n exportDoc,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n // On first batch, discover additional columns from data and merge with schema\n if (!columnsFinalized) {\n const dataColumns: string[] = []\n const seenCols = new Set<string>()\n for (const row of batchRowsToWrite) {\n for (const key of Object.keys(row)) {\n if (!seenCols.has(key)) {\n seenCols.add(key)\n dataColumns.push(key)\n }\n }\n }\n // Merge schema columns with data-discovered columns.\n // When a before hook is active and rows exist, restrict to columns actually present\n // in the data so that the hook can remove fields by not returning them.\n const mergedColumns = mergeColumns(schemaColumns, dataColumns)\n allColumns =\n Boolean(exportHooks?.before) && batchRowsToWrite.length > 0\n ? mergedColumns.filter((col) => dataColumns.includes(col))\n : mergedColumns\n columnsFinalized = true\n\n if (debug) {\n req.payload.logger.debug({\n dataColumnsCount: dataColumns.length,\n finalColumnsCount: allColumns.length,\n msg: 'Merged schema and data columns',\n })\n }\n }\n\n const paddedRows = batchRowsToWrite.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of allColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n const csvString = stringify(paddedRows, {\n bom: isFirstBatch,\n header: isFirstBatch,\n columns: allColumns,\n })\n\n this.push(encoder.encode(csvString))\n\n if (exportHooks?.after && batchRowsToWrite.length > 0) {\n await exportHooks.after({\n batchNumber: streamBatchNumber,\n data: batchRowsToWrite,\n exportDoc,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n } else {\n // --- JSON Streaming ---\n const batchRows = result.docs.map(\n (doc) =>\n filterDisabledJSON(\n applyFieldHooks({\n data: doc as Record<string, unknown>,\n fieldHooks: exportFieldHooks,\n fields: collectionConfig.flattenedFields,\n format,\n operation: 'export',\n req,\n type: 'beforeExport',\n }),\n ) as Record<string, unknown>,\n )\n\n const originalDocs = result.docs as Record<string, unknown>[]\n let batchRowsToWrite = batchRows\n if (exportHooks?.before && batchRows.length > 0) {\n batchRowsToWrite = await exportHooks.before({\n batchNumber: streamBatchNumber,\n data: batchRows,\n exportDoc,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n // Convert each filtered/flattened row into JSON string\n const batchJSON = batchRowsToWrite.map((row) => JSON.stringify(row)).join(',')\n\n if (isFirstBatch) {\n this.push(encoder.encode('[' + batchJSON))\n } else {\n this.push(encoder.encode(',' + batchJSON))\n }\n\n if (exportHooks?.after && batchRowsToWrite.length > 0) {\n await exportHooks.after({\n batchNumber: streamBatchNumber,\n data: batchRowsToWrite,\n exportDoc,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n }\n\n fetched += result.docs.length\n isFirstBatch = false\n currentBatchPage += 1\n\n if (!result.hasNextPage || fetched >= maxDocs) {\n if (debug) {\n req.payload.logger.debug('Stream complete - no more pages')\n }\n if (!isCSV) {\n this.push(encoder.encode(']'))\n }\n this.push(null) // End the stream\n }\n },\n })\n\n return new Response(Readable.toWeb(stream) as ReadableStream, {\n headers: {\n 'Content-Disposition': `attachment; filename=\"${name}\"`,\n 'Content-Type': isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n },\n })\n }\n\n // Non-download path (buffered export)\n if (debug) {\n req.payload.logger.debug('Starting file generation')\n }\n\n // Create export batch processor\n const processor = createExportBatchProcessor({ batchSize, debug })\n\n // Transform function based on format\n const transformDoc = (doc: unknown) =>\n isCSV\n ? filterDisabledCSV(\n flattenObject({\n data: doc as Record<string, unknown>,\n fields,\n format,\n exportFieldHooks,\n req,\n }),\n )\n : (filterDisabledJSON(\n applyFieldHooks({\n data: doc as Record<string, unknown>,\n fieldHooks: exportFieldHooks,\n fields: collectionConfig.flattenedFields,\n format,\n operation: 'export',\n req,\n type: 'beforeExport',\n }),\n ) as Record<string, unknown>)\n\n // Skip fetching if access was denied - we'll create an empty export\n let exportResult = {\n columns: [] as string[],\n docs: [] as Record<string, unknown>[],\n fetchedCount: 0,\n }\n\n if (!accessDenied) {\n exportResult = await processor.processExport({\n collectionSlug,\n exportDoc,\n findArgs: findArgs as ExportFindArgs,\n format,\n hooks: exportHooks,\n maxDocs:\n typeof maxExportDocuments === 'number' ? maxExportDocuments : Number.POSITIVE_INFINITY,\n req,\n startPage: adjustedPage,\n totalDocs,\n transformDoc,\n })\n }\n\n const { columns: dataColumns, docs: rows } = exportResult\n const outputData: string[] = []\n\n // Prepare final output\n if (isCSV) {\n // Get schema-based columns for consistent ordering\n const localeCodes =\n locale === 'all' && payload.config.localization\n ? payload.config.localization.localeCodes\n : undefined\n\n const schemaColumns = getSchemaColumns({\n collectionConfig,\n disabledFields,\n fields,\n locale,\n localeCodes,\n })\n\n // Merge schema columns with data-discovered columns\n // Schema provides ordering, data provides additional columns (e.g., array indices > 0)\n // When a before hook is active and rows exist, restrict to columns actually present in the data\n // so that the hook can remove fields by not returning them\n const mergedColumns = mergeColumns(schemaColumns, dataColumns)\n const finalColumns =\n Boolean(exportHooks?.before) && rows.length > 0\n ? mergedColumns.filter((col) => dataColumns.includes(col))\n : mergedColumns\n\n const paddedRows = rows.map((row) => {\n const fullRow: Record<string, unknown> = {}\n for (const col of finalColumns) {\n fullRow[col] = row[col] ?? ''\n }\n return fullRow\n })\n\n // Always output CSV with header, even if empty\n outputData.push(\n stringify(paddedRows, {\n bom: true,\n header: true,\n columns: finalColumns,\n }),\n )\n } else {\n // JSON format\n outputData.push(rows.map((doc) => JSON.stringify(doc)).join(',\\n'))\n }\n\n // Ensure we always have valid content for the file\n // For JSON, empty exports produce \"[]\"\n // For CSV, if completely empty (no columns, no rows), produce at least a newline to ensure file creation\n const content = format === 'json' ? `[${outputData.join(',')}]` : outputData.join('')\n const buffer = Buffer.from(content.length > 0 ? content : '\\n')\n if (debug) {\n req.payload.logger.debug(`${format} file generation complete`)\n }\n\n if (!id) {\n if (debug) {\n req.payload.logger.debug('Creating new export file')\n }\n req.file = {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n size: buffer.length,\n }\n } else {\n if (debug) {\n req.payload.logger.debug({\n msg: '[createExport] Updating export document with file',\n exportDocId: id,\n exportCollection,\n fileName: name,\n fileSize: buffer.length,\n mimeType: isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n })\n }\n try {\n await req.payload.update({\n id,\n collection: exportCollection,\n data: {},\n file: {\n name,\n data: buffer,\n mimetype: isCSV ? 'text/csv; charset=utf-8' : 'application/json',\n size: buffer.length,\n },\n // Override access only here so that we can be sure the export collection itself is updated as expected\n overrideAccess: true,\n req,\n })\n } catch (error) {\n const errorDetails =\n error instanceof Error\n ? {\n message: error.message,\n name: error.name,\n stack: error.stack,\n // @ts-expect-error - data might exist on Payload errors\n data: error.data,\n }\n : error\n req.payload.logger.error({\n msg: '[createExport] Failed to update export document with file',\n err: errorDetails,\n exportDocId: id,\n exportCollection,\n fileName: name,\n })\n throw error\n }\n }\n if (debug) {\n req.payload.logger.debug('Export process completed successfully')\n }\n}\n"],"names":["stringify","APIError","Readable","applyFieldHooks","buildDisabledFieldRegex","flattenObject","getExportFieldFunctions","getFilename","getSchemaColumns","mergeColumns","getSelect","validateLimitValue","createExportBatchProcessor","createExport","args","id","name","nameArg","batchSize","collectionSlug","debug","download","drafts","draftsFromInput","exportCollection","exportDoc","fields","format","limit","incomingLimit","maxLimit","locale","localeFromInput","page","req","sort","userCollection","userID","where","whereFromInput","localeFromReq","payload","logger","msg","exportDocId","exportName","draft","collectionConfig","config","collections","find","slug","user","findByID","collection","overrideAccess","hasVersions","Boolean","versions","publishedWhere","_status","equals","and","baseName","isCSV","select","Array","isArray","length","undefined","maxExportDocuments","Math","min","totalDocs","accessDenied","countResult","count","error","totalPages","max","ceil","requestedPage","adjustedPage","findArgs","depth","exportFieldHooks","flattenedFields","exportHooks","custom","disabledFields","admin","disabledMatchers","map","filterDisabledCSV","row","filtered","key","value","Object","entries","isDisabled","some","matcher","test","filterDisabledJSON","doc","parentPath","item","currentPath","includes","limitErrorMsg","t","schemaColumns","localeCodes","localization","columnCount","allColumns","columnsFinalized","encoder","TextEncoder","isFirstBatch","currentBatchPage","fetched","maxDocs","Number","POSITIVE_INFINITY","effectiveStreamDocs","totalBatches","streamBatchNumber","stream","read","remaining","push","encode","result","docs","batchRows","data","originalDocs","batchRowsToWrite","before","batchNumber","originalData","dataColumns","seenCols","Set","keys","has","add","mergedColumns","filter","col","dataColumnsCount","finalColumnsCount","paddedRows","fullRow","csvString","bom","header","columns","after","fieldHooks","operation","type","batchJSON","JSON","join","hasNextPage","Response","toWeb","headers","processor","transformDoc","exportResult","fetchedCount","processExport","hooks","startPage","rows","outputData","finalColumns","content","buffer","Buffer","from","file","mimetype","size","fileName","fileSize","mimeType","update","errorDetails","Error","message","stack","err"],"mappings":"AAAA,6CAA6C,GAG7C,SAASA,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,QAAQ,QAAQ,UAAS;AAClC,SAASC,QAAQ,QAAQ,SAAQ;AAIjC,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,gBAAgB,EAAEC,YAAY,QAAQ,mCAAkC;AACjF,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,0BAA0B,QAA6B,sBAAqB;AA2CrF,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EACJC,EAAE,EACFC,MAAMC,OAAO,EACbC,YAAY,GAAG,EACfC,cAAc,EACdC,QAAQ,KAAK,EACbC,QAAQ,EACRC,QAAQC,eAAe,EACvBC,gBAAgB,EAChBC,SAAS,EACTC,MAAM,EACNC,MAAM,EACNC,OAAOC,aAAa,EACpBC,QAAQ,EACRC,QAAQC,eAAe,EACvBC,IAAI,EACJC,GAAG,EACHC,IAAI,EACJC,cAAc,EACdC,MAAM,EACNC,OAAOC,iBAAiB,CAAC,CAAC,EAC3B,GAAGzB;IACJ,MAAM,EAAEiB,QAAQS,aAAa,EAAEC,OAAO,EAAE,GAAGP;IAE3C,IAAId,OAAO;QACTc,IAAIO,OAAO,CAACC,MAAM,CAACtB,KAAK,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Y9B;gBACZiH,MAAM,CAAC;gBACPgD,MAAM;oBACJzK;oBACAyH,MAAM6C;oBACNI,UAAU1H,QAAQ,4BAA4B;oBAC9C2H,MAAML,OAAOlH,MAAM;gBACrB;gBACA,uGAAuG;gBACvGb,gBAAgB;gBAChBrB;YACF;QACF,EAAE,OAAO2C,OAAO;YACd,MAAMmH,eACJnH,iBAAiBoH,QACb;gBACEC,SAASrH,MAAMqH,OAAO;gBACtBlL,MAAM6D,MAAM7D,IAAI;gBAChBmL,OAAOtH,MAAMsH,KAAK;gBAClB,wDAAwD;gBACxD1D,MAAM5D,MAAM4D,IAAI;YAClB,IACA5D;YACN3C,IAAIO,OAAO,CAACC,MAAM,CAACmC,KAAK,CAAC;gBACvBlC,KAAK;gBACLyJ,KAAKJ;gBACLpJ,aAAa7B;gBACbS;gBACAoK,UAAU5K;YACZ;YACA,MAAM6D;QACR;IACF;IACA,IAAIzD,OAAO;QACTc,IAAIO,OAAO,CAACC,MAAM,CAACtB,KAAK,CAAC;IAC3B;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,UAAU,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAI/C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAAA;AAmGV,eAAO,MAAM,6BAA6B,GACxC,QAAQ,MAAM,KACb,UAAU,CAAC;IACZ,KAAK,EAAE,cAAc,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACf,CAuBA,CAAA"}
1
+ {"version":3,"file":"getCreateExportCollectionTask.d.ts","sourceRoot":"","sources":["../../src/export/getCreateExportCollectionTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,UAAU,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAI/C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAAA;AAmGV,eAAO,MAAM,6BAA6B,WAChC,MAAM,KACb,UAAU,CAAC;IACZ,KAAK,EAAE,cAAc,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACf,CAoCA,CAAA"}
@@ -115,8 +115,19 @@ export const getCreateCollectionExportTask = (config)=>{
115
115
  output: {}
116
116
  };
117
117
  }
118
+ // The job input omits custom fields, so read the export document once for the hooks.
119
+ const exportDoc = await req.payload.findByID({
120
+ id: input.id,
121
+ collection: input.exportCollection,
122
+ overrideAccess: true,
123
+ req
124
+ });
125
+ if (!exportDoc) {
126
+ throw new Error(`Export document not found: ${input.id}`);
127
+ }
118
128
  await createExport({
119
129
  ...input,
130
+ exportDoc,
120
131
  req
121
132
  });
122
133
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, Field, TaskConfig } from 'payload'\n\nimport type { Export } from './createExport.js'\n\nimport { createExport } from './createExport.js'\n\n/**\n * Export input type for job queue serialization.\n * When exports are queued as jobs, the user must be serialized as an ID string or number\n * along with the collection name so it can be rehydrated when the job runs.\n */\nexport type ExportJobInput = {\n user: number | string\n userCollection: string\n} & Export\n\n/**\n * Creates a minimal inputSchema for the job queue task.\n */\nconst getJobInputSchema = (config: Config): Field[] => {\n const allCollectionSlugs = config.collections?.map((c) => c.slug) || []\n\n const collectionOptions = allCollectionSlugs.map((slug) => {\n const collectionConfig = config.collections?.find((c) => c.slug === slug)\n return {\n label: collectionConfig?.labels?.singular || slug,\n value: slug,\n }\n })\n\n return [\n {\n name: 'id',\n type: 'text',\n required: true,\n },\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n {\n name: 'batchSize',\n type: 'number',\n },\n {\n name: 'collectionSlug',\n type: 'select',\n options: collectionOptions,\n required: true,\n },\n {\n name: 'drafts',\n type: 'select',\n options: [\n { label: 'Yes', value: 'yes' },\n { label: 'No', value: 'no' },\n ],\n },\n {\n name: 'exportCollection',\n type: 'text',\n required: true,\n },\n {\n name: 'fields',\n type: 'text',\n hasMany: true,\n },\n {\n name: 'format',\n type: 'select',\n options: [\n { label: 'CSV', value: 'csv' },\n { label: 'JSON', value: 'json' },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n },\n {\n name: 'locale',\n type: 'text',\n },\n {\n name: 'maxLimit',\n type: 'number',\n },\n {\n name: 'page',\n type: 'number',\n },\n {\n name: 'sort',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'userID',\n type: 'text',\n },\n {\n name: 'where',\n type: 'json',\n },\n ]\n}\n\nexport const getCreateCollectionExportTask = (\n config: Config,\n): TaskConfig<{\n input: ExportJobInput\n output: object\n}> => {\n const inputSchema = getJobInputSchema(config)\n\n return {\n slug: 'createCollectionExport',\n handler: async ({ input, req }) => {\n if (!input) {\n req.payload.logger.error('No input provided to createCollectionExport task')\n\n return { output: {} }\n }\n\n await createExport({\n ...input,\n req,\n })\n\n return {\n output: {},\n }\n },\n inputSchema,\n }\n}\n"],"names":["createExport","getJobInputSchema","config","allCollectionSlugs","collections","map","c","slug","collectionOptions","collectionConfig","find","label","labels","singular","value","name","type","required","options","hasMany","getCreateCollectionExportTask","inputSchema","handler","input","req","payload","logger","error","output"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAYhD;;CAEC,GACD,MAAMC,oBAAoB,CAACC;IACzB,MAAMC,qBAAqBD,OAAOE,WAAW,EAAEC,IAAI,CAACC,IAAMA,EAAEC,IAAI,KAAK,EAAE;IA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gBACVC,IAAIC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBAEzB,OAAO;oBAAEC,QAAQ,CAAC;gBAAE;YACtB;YAEA,MAAM5B,aAAa;gBACjB,GAAGuB,KAAK;gBACRC;YACF;YAEA,OAAO;gBACLI,QAAQ,CAAC;YACX;QACF;QACAP;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/export/getCreateExportCollectionTask.ts"],"sourcesContent":["import type { Config, Field, TaskConfig } from 'payload'\n\nimport type { Export } from './createExport.js'\n\nimport { createExport } from './createExport.js'\n\n/**\n * Export input type for job queue serialization.\n * When exports are queued as jobs, the user must be serialized as an ID string or number\n * along with the collection name so it can be rehydrated when the job runs.\n */\nexport type ExportJobInput = {\n user: number | string\n userCollection: string\n} & Export\n\n/**\n * Creates a minimal inputSchema for the job queue task.\n */\nconst getJobInputSchema = (config: Config): Field[] => {\n const allCollectionSlugs = config.collections?.map((c) => c.slug) || []\n\n const collectionOptions = allCollectionSlugs.map((slug) => {\n const collectionConfig = config.collections?.find((c) => c.slug === slug)\n return {\n label: collectionConfig?.labels?.singular || slug,\n value: slug,\n }\n })\n\n return [\n {\n name: 'id',\n type: 'text',\n required: true,\n },\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n {\n name: 'batchSize',\n type: 'number',\n },\n {\n name: 'collectionSlug',\n type: 'select',\n options: collectionOptions,\n required: true,\n },\n {\n name: 'drafts',\n type: 'select',\n options: [\n { label: 'Yes', value: 'yes' },\n { label: 'No', value: 'no' },\n ],\n },\n {\n name: 'exportCollection',\n type: 'text',\n required: true,\n },\n {\n name: 'fields',\n type: 'text',\n hasMany: true,\n },\n {\n name: 'format',\n type: 'select',\n options: [\n { label: 'CSV', value: 'csv' },\n { label: 'JSON', value: 'json' },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n },\n {\n name: 'locale',\n type: 'text',\n },\n {\n name: 'maxLimit',\n type: 'number',\n },\n {\n name: 'page',\n type: 'number',\n },\n {\n name: 'sort',\n type: 'text',\n },\n {\n name: 'userCollection',\n type: 'text',\n },\n {\n name: 'userID',\n type: 'text',\n },\n {\n name: 'where',\n type: 'json',\n },\n ]\n}\n\nexport const getCreateCollectionExportTask = (\n config: Config,\n): TaskConfig<{\n input: ExportJobInput\n output: object\n}> => {\n const inputSchema = getJobInputSchema(config)\n\n return {\n slug: 'createCollectionExport',\n handler: async ({ input, req }) => {\n if (!input) {\n req.payload.logger.error('No input provided to createCollectionExport task')\n\n return { output: {} }\n }\n\n // The job input omits custom fields, so read the export document once for the hooks.\n const exportDoc = await req.payload.findByID({\n id: input.id,\n collection: input.exportCollection,\n overrideAccess: true,\n req,\n })\n\n if (!exportDoc) {\n throw new Error(`Export document not found: ${input.id}`)\n }\n\n await createExport({\n ...input,\n exportDoc,\n req,\n })\n\n return {\n output: {},\n }\n },\n inputSchema,\n }\n}\n"],"names":["createExport","getJobInputSchema","config","allCollectionSlugs","collections","map","c","slug","collectionOptions","collectionConfig","find","label","labels","singular","value","name","type","required","options","hasMany","getCreateCollectionExportTask","inputSchema","handler","input","req","payload","logger","error","output","exportDoc","findByID","id","collection","exportCollection","overrideAccess","Error"],"mappings":"AAIA,SAASA,YAAY,QAAQ,oBAAmB;AAYhD;;CAEC,GACD,MAAMC,oBAAoB,CAACC;IACzB,MAAMC,qBAAqBD,OAAOE,WAAW,EAAEC,IAAI,CAACC,IAAMA,EAAEC,IAAI,KAAK,EAAE;IAEvE,MAAMC,oBAAoBL,mBAAmBE,GAAG,CAAC,CAACE;QAChD,MAAME,mBAAmBP,OAAOE,WAAW,EAAEM,KAAK,CAACJ,IAAMA,EAAEC,IAAI,KAAKA;QACpE,OAAO;YACLI,OAAOF,kBAAkBG,QAAQC,YAAYN;YAC7CO,OAAOP;QACT;IACF;IAEA,OAAO;QACL;YACEQ,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;Q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EAAE,EAAE;YAC1D;YAEA,MAAM/B,aAAa;gBACjB,GAAGuB,KAAK;gBACRM;gBACAL;YACF;YAEA,OAAO;gBACLI,QAAQ,CAAC;YACX;QACF;QACAP;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../../src/export/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAS,MAAM,aAAa,CAAA;AAWhF,eAAO,MAAM,mBAAmB,GAAI,0DAKjC;IACD;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBA8JH,CAAA"}
1
+ {"version":3,"file":"getExportCollection.d.ts","sourceRoot":"","sources":["../../src/export/getExportCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAS,MAAM,aAAa,CAAA;AAYhF,eAAO,MAAM,mBAAmB,6DAK7B;IACD;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,YAAY,EAAE,wBAAwB,CAAA;CACvC,KAAG,gBAgKH,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { getSubmittedFormValues } from '../utilities/getSubmittedFormValues.js';
1
2
  import { resolveLimit } from '../utilities/resolveLimit.js';
2
3
  import { createExport } from './createExport.js';
3
4
  import { getFields } from './getFields.js';
@@ -89,6 +90,9 @@ export const getExportCollection = ({ collectionSlugs, config, exportConfig, plu
89
90
  batchSize,
90
91
  debug,
91
92
  exportCollection: collectionConfig.slug,
93
+ exportDoc: getSubmittedFormValues({
94
+ formData: exportData
95
+ }),
92
96
  maxLimit,
93
97
  req,
94
98
  userCollection: user?.collection,
@@ -135,6 +139,7 @@ export const getExportCollection = ({ collectionSlugs, config, exportConfig, plu
135
139
  };
136
140
  await req.payload.jobs.queue({
137
141
  input,
142
+ overrideAccess: true,
138
143
  task: 'createCollectionExport'
139
144
  });
140
145
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/getExportCollection.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport type { ExportConfig, ImportExportPluginConfig, Limit } from '../types.js'\nimport type { Export } from './createExport.js'\n\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\nimport { handleDownload } from './handleDownload.js'\nimport { handlePreview } from './handlePreview.js'\n\nconst FALLBACK_BATCH_SIZE = 100\n\nexport const getExportCollection = ({\n collectionSlugs,\n config,\n exportConfig,\n pluginConfig,\n}: {\n /**\n * Collection slugs that this export collection supports.\n */\n collectionSlugs: string[]\n config: Config\n exportConfig?: ExportConfig\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const beforeOperation: CollectionBeforeOperationHook[] = []\n const afterChange: CollectionAfterChangeHook[] = []\n\n const disableDownload = exportConfig?.disableDownload ?? false\n const disableSave = exportConfig?.disableSave ?? false\n const format = exportConfig?.format\n\n const collection: CollectionConfig = {\n slug: 'exports',\n access: {\n update: () => false,\n },\n admin: {\n components: {\n edit: {\n SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton',\n },\n },\n custom: {\n disableDownload,\n disableSave,\n format,\n 'plugin-import-export': {\n collectionSlugs,\n },\n },\n disableCopyToLocale: true,\n group: false,\n useAsTitle: 'name',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: (req) => handleDownload(req, pluginConfig.debug),\n method: 'post',\n path: '/download',\n },\n {\n handler: handlePreview,\n method: 'post',\n path: '/export-preview',\n },\n ],\n fields: getFields({ collectionSlugs, config, format }),\n hooks: {\n afterChange,\n beforeOperation,\n },\n lockDocuments: false,\n upload: {\n filesRequiredOnCreate: false,\n hideFileInputOnCreate: true,\n hideRemoveFile: true,\n },\n }\n\n // Synchronous export hook - runs when target collection has disableJobsQueue enabled\n beforeOperation.push(async ({ args, collection: collectionConfig, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const exportData = args.data as Export\n const targetCollection = req.payload.collections[exportData.collectionSlug]\n const targetPluginConfig = targetCollection?.config.custom?.['plugin-import-export']\n\n // Check if this target collection should use sync mode\n // Fall back to exportConfig (for custom collections with overrideCollection)\n const disableJobsQueue =\n targetPluginConfig?.exportDisableJobsQueue ?? exportConfig?.disableJobsQueue ?? false\n if (!disableJobsQueue) {\n return\n }\n\n const { user } = req\n const debug = pluginConfig.debug\n\n const exportLimitConfig: Limit | undefined = targetPluginConfig?.exportLimit\n const maxLimit = await resolveLimit({\n limit: exportLimitConfig,\n req,\n })\n\n const batchSize =\n targetPluginConfig?.exportBatchSize ??\n exportConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n await createExport({\n ...exportData,\n batchSize,\n debug,\n exportCollection: collectionConfig.slug,\n maxLimit,\n req,\n userCollection: user?.collection,\n userID: user?.id,\n })\n })\n\n afterChange.push(async ({ collection: collectionConfig, doc, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const targetCollection = req.payload.collections[doc.collectionSlug]\n const targetPluginConfig = targetCollection?.config.custom?.['plugin-import-export']\n const disableJobsQueue =\n targetPluginConfig?.exportDisableJobsQueue ?? exportConfig?.disableJobsQueue ?? false\n if (disableJobsQueue) {\n return\n }\n\n const { user } = req\n\n // Get max limit from the target collection's config\n // For job-based exports, we resolve the limit now since function limits\n // cannot be serialized. This means dynamic limits are resolved at queue time.\n const exportLimitConfig: Limit | undefined = targetPluginConfig?.exportLimit\n const maxLimit = await resolveLimit({\n limit: exportLimitConfig,\n req,\n })\n\n const batchSize =\n targetPluginConfig?.exportBatchSize ??\n exportConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n const input: Export = {\n id: doc.id,\n name: doc.name,\n batchSize,\n collectionSlug: doc.collectionSlug,\n drafts: doc.drafts,\n exportCollection: collectionConfig.slug,\n fields: doc.fields,\n format: doc.format,\n limit: doc.limit,\n locale: doc.locale,\n maxLimit,\n page: doc.page,\n sort: doc.sort,\n userCollection: user?.collection,\n userID: user?.id,\n where: doc.where,\n }\n\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionExport',\n })\n })\n\n return collection\n}\n"],"names":["resolveLimit","createExport","getFields","handleDownload","handlePreview","FALLBACK_BATCH_SIZE","getExportCollection","collectionSlugs","config","exportConfig","pluginConfig","beforeOperation","afterChange","disableDownload","disableSave","format","collection","slug","access","update","admin","components","edit","SaveButton","custom","disableCopyToLocale","group","useAsTitle","disableDuplicate","endpoints","handler","req","debug","method","path","fields","hooks","lockDocuments","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","push","args","collectionConfig","operation","exportData","data","targetCollection","payload","collections","collectionSlug","targetPluginConfig","disableJobsQueue","exportDisableJobsQueue","user","exportLimitConfig","exportLimit","maxLimit","limit","batchSize","exportBatchSize","exportCollection","userCollection","userID","id","doc","input","name","drafts","locale","page","sort","where","jobs","queue","task"],"mappings":"AAUA,SAASA,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,aAAa,QAAQ,qBAAoB;AAElD,MAAMC,sBAAsB;AAE5B,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,eAAe,EACfC,MAAM,EACNC,YAAY,EACZC,YAAY,EASb;IACC,MAAMC,kBAA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B,QAAQmD,IAAInD,MAAM;YAClB4C,OAAOO,IAAIP,KAAK;YAChBW,QAAQJ,IAAII,MAAM;YAClBZ;YACAa,MAAML,IAAIK,IAAI;YACdC,MAAMN,IAAIM,IAAI;YACdT,gBAAgBR,MAAMvC;YACtBgD,QAAQT,MAAMU;YACdQ,OAAOP,IAAIO,KAAK;QAClB;QAEA,MAAM1C,IAAIkB,OAAO,CAACyB,IAAI,CAACC,KAAK,CAAC;YAC3BR;YACAS,MAAM;QACR;IACF;IAEA,OAAO5D;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/export/getExportCollection.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n Config,\n} from 'payload'\n\nimport type { ExportConfig, ImportExportPluginConfig, Limit } from '../types.js'\nimport type { Export } from './createExport.js'\n\nimport { getSubmittedFormValues } from '../utilities/getSubmittedFormValues.js'\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { createExport } from './createExport.js'\nimport { getFields } from './getFields.js'\nimport { handleDownload } from './handleDownload.js'\nimport { handlePreview } from './handlePreview.js'\n\nconst FALLBACK_BATCH_SIZE = 100\n\nexport const getExportCollection = ({\n collectionSlugs,\n config,\n exportConfig,\n pluginConfig,\n}: {\n /**\n * Collection slugs that this export collection supports.\n */\n collectionSlugs: string[]\n config: Config\n exportConfig?: ExportConfig\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const beforeOperation: CollectionBeforeOperationHook[] = []\n const afterChange: CollectionAfterChangeHook[] = []\n\n const disableDownload = exportConfig?.disableDownload ?? false\n const disableSave = exportConfig?.disableSave ?? false\n const format = exportConfig?.format\n\n const collection: CollectionConfig = {\n slug: 'exports',\n access: {\n update: () => false,\n },\n admin: {\n components: {\n edit: {\n SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton',\n },\n },\n custom: {\n disableDownload,\n disableSave,\n format,\n 'plugin-import-export': {\n collectionSlugs,\n },\n },\n disableCopyToLocale: true,\n group: false,\n useAsTitle: 'name',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: (req) => handleDownload(req, pluginConfig.debug),\n method: 'post',\n path: '/download',\n },\n {\n handler: handlePreview,\n method: 'post',\n path: '/export-preview',\n },\n ],\n fields: getFields({ collectionSlugs, config, format }),\n hooks: {\n afterChange,\n beforeOperation,\n },\n lockDocuments: false,\n upload: {\n filesRequiredOnCreate: false,\n hideFileInputOnCreate: true,\n hideRemoveFile: true,\n },\n }\n\n // Synchronous export hook - runs when target collection has disableJobsQueue enabled\n beforeOperation.push(async ({ args, collection: collectionConfig, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const exportData = args.data as Export\n const targetCollection = req.payload.collections[exportData.collectionSlug]\n const targetPluginConfig = targetCollection?.config.custom?.['plugin-import-export']\n\n // Check if this target collection should use sync mode\n // Fall back to exportConfig (for custom collections with overrideCollection)\n const disableJobsQueue =\n targetPluginConfig?.exportDisableJobsQueue ?? exportConfig?.disableJobsQueue ?? false\n if (!disableJobsQueue) {\n return\n }\n\n const { user } = req\n const debug = pluginConfig.debug\n\n const exportLimitConfig: Limit | undefined = targetPluginConfig?.exportLimit\n const maxLimit = await resolveLimit({\n limit: exportLimitConfig,\n req,\n })\n\n const batchSize =\n targetPluginConfig?.exportBatchSize ??\n exportConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n await createExport({\n ...exportData,\n batchSize,\n debug,\n exportCollection: collectionConfig.slug,\n exportDoc: getSubmittedFormValues({ formData: exportData }),\n maxLimit,\n req,\n userCollection: user?.collection,\n userID: user?.id,\n })\n })\n\n afterChange.push(async ({ collection: collectionConfig, doc, operation, req }) => {\n if (operation !== 'create') {\n return\n }\n\n const targetCollection = req.payload.collections[doc.collectionSlug]\n const targetPluginConfig = targetCollection?.config.custom?.['plugin-import-export']\n const disableJobsQueue =\n targetPluginConfig?.exportDisableJobsQueue ?? exportConfig?.disableJobsQueue ?? false\n if (disableJobsQueue) {\n return\n }\n\n const { user } = req\n\n // Get max limit from the target collection's config\n // For job-based exports, we resolve the limit now since function limits\n // cannot be serialized. This means dynamic limits are resolved at queue time.\n const exportLimitConfig: Limit | undefined = targetPluginConfig?.exportLimit\n const maxLimit = await resolveLimit({\n limit: exportLimitConfig,\n req,\n })\n\n const batchSize =\n targetPluginConfig?.exportBatchSize ??\n exportConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n const input: Export = {\n id: doc.id,\n name: doc.name,\n batchSize,\n collectionSlug: doc.collectionSlug,\n drafts: doc.drafts,\n exportCollection: collectionConfig.slug,\n fields: doc.fields,\n format: doc.format,\n limit: doc.limit,\n locale: doc.locale,\n maxLimit,\n page: doc.page,\n sort: doc.sort,\n userCollection: user?.collection,\n userID: user?.id,\n where: doc.where,\n }\n\n await req.payload.jobs.queue({\n input,\n overrideAccess: true,\n task: 'createCollectionExport',\n })\n })\n\n return collection\n}\n"],"names":["getSubmittedFormValues","resolveLimit","createExport","getFields","handleDownload","handlePreview","FALLBACK_BATCH_SIZE","getExportCollection","collectionSlugs","config","exportConfig","pluginConfig","beforeOperation","afterChange","disableDownload","disableSave","format","collection","slug","access","update","admin","components","edit","SaveButton","custom","disableCopyToLocale","group","useAsTitle","disableDuplicate","endpoints","handler","req","debug","method","path","fields","hooks","lockDocuments","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","push","args","collectionConfig","operation","exportData","data","targetCollection","payload","collections","collectionSlug","targetPluginConfig","disableJobsQueue","exportDisableJobsQueue","user","exportLimitConfig","exportLimit","maxLimit","limit","batchSize","exportBatchSize","exportCollection","exportDoc","formData","userCollection","userID","id","doc","input","name","drafts","locale","page","sort","where","jobs","queue","overrideAccess","task"],"mappings":"AAUA,SAASA,sBAAsB,QAAQ,yCAAwC;AAC/E,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC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mD,aACdlD,aAAakD,SAAS,IACtBvD;QAEF,MAAMgE,QAAgB;YACpBF,IAAIC,IAAID,EAAE;YACVG,MAAMF,IAAIE,IAAI;YACdV;YACAT,gBAAgBiB,IAAIjB,cAAc;YAClCoB,QAAQH,IAAIG,MAAM;YAClBT,kBAAkBlB,iBAAiB3B,IAAI;YACvCkB,QAAQiC,IAAIjC,MAAM;YAClBpB,QAAQqD,IAAIrD,MAAM;YAClB4C,OAAOS,IAAIT,KAAK;YAChBa,QAAQJ,IAAII,MAAM;YAClBd;YACAe,MAAML,IAAIK,IAAI;YACdC,MAAMN,IAAIM,IAAI;YACdT,gBAAgBV,MAAMvC;YACtBkD,QAAQX,MAAMY;YACdQ,OAAOP,IAAIO,KAAK;QAClB;QAEA,MAAM5C,IAAIkB,OAAO,CAAC2B,IAAI,CAACC,KAAK,CAAC;YAC3BR;YACAS,gBAAgB;YAChBC,MAAM;QACR;IACF;IAEA,OAAO/D;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAA+B,MAAM,SAAS,CAAA;AAKzE,KAAK,gBAAgB,GAAG;IACtB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,SAAS,gBAAgB,KAAG,KAAK,EA6Q1D,CAAA"}
1
+ {"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAA+B,MAAM,SAAS,CAAA;AAKzE,KAAK,gBAAgB,GAAG;IACtB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,SAAS,YAAa,gBAAgB,KAAG,KAAK,EA6Q1D,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"handleDownload.d.ts","sourceRoot":"","sources":["../../src/export/handleDownload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7C,eAAO,MAAM,cAAc,GAAU,KAAK,cAAc,EAAE,eAAa,sBA2DtE,CAAA"}
1
+ {"version":3,"file":"handleDownload.d.ts","sourceRoot":"","sources":["../../src/export/handleDownload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAU7C,eAAO,MAAM,cAAc,QAAe,cAAc,uCA6DvD,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { APIError } from 'payload';
2
+ import { getSubmittedFormValues } from '../utilities/getSubmittedFormValues.js';
2
3
  import { resolveLimit } from '../utilities/resolveLimit.js';
3
4
  import { createExport } from './createExport.js';
4
5
  export const handleDownload = async (req, debug = false)=>{
@@ -28,15 +29,18 @@ export const handleDownload = async (req, debug = false)=>{
28
29
  });
29
30
  }
30
31
  const { user } = req;
31
- body.data.userID = user?.id;
32
- body.data.userCollection = user?.collection;
32
+ const exportDoc = getSubmittedFormValues({
33
+ formData: body.data
34
+ });
33
35
  const res = await createExport({
34
36
  ...body.data,
35
37
  debug,
36
38
  download: true,
39
+ exportDoc,
37
40
  maxLimit,
38
41
  req,
39
- user: req.user
42
+ userCollection: user?.collection,
43
+ userID: user?.id
40
44
  });
41
45
  return res;
42
46
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/handleDownload.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { createExport } from './createExport.js'\n\nexport const handleDownload = async (req: PayloadRequest, debug = false) => {\n try {\n let body\n\n if (typeof req?.json === 'function') {\n body = await req.json()\n }\n\n if (!body || !body.data) {\n throw new APIError('Request data is required.')\n }\n\n const { collectionSlug, format } = body.data || {}\n\n req.payload.logger.info(`Download request received ${collectionSlug}`)\n\n const targetCollection = req.payload.collections[collectionSlug]\n let maxLimit: number | undefined\n\n if (targetCollection) {\n const adminPluginConfig = targetCollection.config.admin?.custom?.['plugin-import-export']\n const pluginConfig = targetCollection.config.custom?.['plugin-import-export']\n\n const forcedFormat = adminPluginConfig?.exportFormat\n if (forcedFormat && format && format !== forcedFormat) {\n throw new APIError(\n `Export format '${format}' is not supported for collection '${collectionSlug}'. Only '${forcedFormat}' format is allowed.`,\n )\n }\n\n // Resolve max limit from the collection config\n maxLimit = await resolveLimit({\n limit: pluginConfig?.exportLimit,\n req,\n })\n }\n\n const { user } = req\n\n body.data.userID = user?.id\n body.data.userCollection = user?.collection\n\n const res = await createExport({\n ...body.data,\n debug,\n download: true,\n maxLimit,\n req,\n user: req.user,\n })\n\n return res as Response\n } catch (err) {\n // Return JSON for front-end toast\n return new Response(\n JSON.stringify({ errors: [{ message: (err as Error).message || 'Something went wrong' }] }),\n { headers: { 'Content-Type': 'application/json' }, status: 400 },\n )\n }\n}\n"],"names":["APIError","resolveLimit","createExport","handleDownload","req","debug","body","json","data","collectionSlug","format","payload","logger","info","targetCollection","collections","maxLimit","adminPluginConfig","config","admin","custom","pluginConfig","forcedFormat","exportFormat","limit","exportLimit","user","userID","id","userCollection","collection","res","download","err","Response","JSON","stringify","errors","message","headers","status"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,iBAAiB,OAAOC,KAAqBC,QAAQ,KAAK;IACrE,IAAI;QACF,IAAIC;QAEJ,IAAI,OAAOF,KAAKG,SAAS,YA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BAAuB;aAAE;QAAC,IACzF;YAAEC,SAAS;gBAAE,gBAAgB;YAAmB;YAAGC,QAAQ;QAAI;IAEnE;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/export/handleDownload.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { ExportDoc } from '../types.js'\n\nimport { getSubmittedFormValues } from '../utilities/getSubmittedFormValues.js'\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { createExport } from './createExport.js'\n\nexport const handleDownload = async (req: PayloadRequest, debug = false) => {\n try {\n let body\n\n if (typeof req?.json === 'function') {\n body = await req.json()\n }\n\n if (!body || !body.data) {\n throw new APIError('Request data is required.')\n }\n\n const { collectionSlug, format } = body.data || {}\n\n req.payload.logger.info(`Download request received ${collectionSlug}`)\n\n const targetCollection = req.payload.collections[collectionSlug]\n let maxLimit: number | undefined\n\n if (targetCollection) {\n const adminPluginConfig = targetCollection.config.admin?.custom?.['plugin-import-export']\n const pluginConfig = targetCollection.config.custom?.['plugin-import-export']\n\n const forcedFormat = adminPluginConfig?.exportFormat\n if (forcedFormat && format && format !== forcedFormat) {\n throw new APIError(\n `Export format '${format}' is not supported for collection '${collectionSlug}'. Only '${forcedFormat}' format is allowed.`,\n )\n }\n\n // Resolve max limit from the collection config\n maxLimit = await resolveLimit({\n limit: pluginConfig?.exportLimit,\n req,\n })\n }\n\n const { user } = req\n const exportDoc = getSubmittedFormValues({\n formData: body.data as Record<string, unknown>,\n }) as ExportDoc\n\n const res = await createExport({\n ...body.data,\n debug,\n download: true,\n exportDoc,\n maxLimit,\n req,\n userCollection: user?.collection,\n userID: user?.id,\n })\n\n return res as Response\n } catch (err) {\n // Return JSON for front-end toast\n return new Response(\n JSON.stringify({ errors: [{ message: (err as Error).message || 'Something went wrong' }] }),\n { headers: { 'Content-Type': 'application/json' }, status: 400 },\n )\n }\n}\n"],"names":["APIError","getSubmittedFormValues","resolveLimit","createExport","handleDownload","req","debug","body","json","data","collectionSlug","format","payload","logger","info","targetCollection","collections","maxLimit","adminPluginConfig","config","admin","custom","pluginConfig","forcedFormat","exportFormat","limit","exportLimit","user","exportDoc","formData","res","download","userCollection","collection","userID","id","err","Response","JSON","stringify","errors","message","headers","status"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,sBAAsB,QAAQ,yCAAwC;AAC/E,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,iBAAiB,OAAOC,KAAqBC,QAAQ,KAAK;IACrE,IAAI;QACF,IAAIC;QAEJ,IAAI,OAAOF,KAAKG,SAAS,YAAY;YACnCD,OAAO,MAAMF,IAAIG,IAAI;QACvB;QAEA,IAAI,CAACD,QAAQ,CAACA,KAAKE,IAAI,EAAE;YACvB,MAAM,IAAIT,SAAS;QACrB;QAEA,MAAM,EAAEU,cAAc,EAAEC,MAAM,EAAE,GAAGJ,KAAKE,IAAI,IAAI,CAAC;QAEjDJ,IAAIO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,0BAA0B,EAAEJ,gBAAgB;QAErE,MAAMK,mBAAmBV,IAAIO,OAAO,CAACI,WAAW,CAACN,eAAe;QAChE,IAAIO;QAEJ,IAAIF,kBAAkB;YACpB,MAAMG,oBAAoBH,iBAAiBI,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,uBAAuB;YACzF,MAAMC,eAAeP,iBAAiBI,MAAM,CAACE,MAAM,EAAE,CAAC,uBAAuB;YAE7E,MAAME,eAAeL,mBAAmBM;YACxC,IAAID,gBAAgBZ,UAAUA,WAAWY,cAAc;gBACrD,MAAM,IAAIvB,SACR,CAAC,eAAe,EAAEW,OAAO,mCAAmC,EAAED,eAAe,SAAS,EAAEa,aAAa,oBAAoB,CAAC;YAE9H;YAEA,+CAA+C;YAC/CN,WAAW,MAAMf,aAAa;gBAC5BuB,OAAOH,cAAcI;gBACrBrB;YACF;QACF;QAEA,MAAM,EAAEsB,IAAI,EAAE,GAAGtB;QACjB,MAAMuB,YAAY3B,uBAAuB;YACvC4B,UAAUtB,KAAKE,IAAI;QACrB;QAEA,MAAMqB,MAAM,MAAM3B,aAAa;YAC7B,GAAGI,KAAKE,IAAI;YACZH;YACAyB,UAAU;YACVH;YACAX;YACAZ;YACA2B,gBAAgBL,MAAMM;YACtBC,QAAQP,MAAMQ;QAChB;QAEA,OAAOL;IACT,EAAE,OAAOM,KAAK;QACZ,kCAAkC;QAClC,OAAO,IAAIC,SACTC,KAAKC,SAAS,CAAC;YAAEC,QAAQ;gBAAC;oBAAEC,SAAS,AAACL,IAAcK,OAAO,IAAI;gBAAuB;aAAE;QAAC,IACzF;YAAEC,SAAS;gBAAE,gBAAgB;YAAmB;YAAGC,QAAQ;QAAI;IAEnE;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/export/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,SAAS,CAAA;AA2C1D,eAAO,MAAM,aAAa,GAAU,KAAK,cAAc,KAAG,OAAO,CAAC,QAAQ,CAuQzE,CAAA"}
1
+ {"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/export/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,SAAS,CAAA;AAqD1D,eAAO,MAAM,aAAa,QAAe,cAAc,KAAG,OAAO,CAAC,QAAQ,CA2RzE,CAAA"}
@@ -7,16 +7,18 @@ import { getExportFieldFunctions } from '../utilities/getExportFieldFunctions.js
7
7
  import { getFlattenedFieldKeys } from '../utilities/getFlattenedFieldKeys.js';
8
8
  import { getSchemaColumns, mergeColumns } from '../utilities/getSchemaColumns.js';
9
9
  import { getSelect } from '../utilities/getSelect.js';
10
+ import { getSubmittedFormValues } from '../utilities/getSubmittedFormValues.js';
10
11
  import { removeDisabledFields } from '../utilities/removeDisabledFields.js';
11
12
  import { resolveLimit } from '../utilities/resolveLimit.js';
12
13
  import { setNestedValue } from '../utilities/setNestedValue.js';
13
- const applyExportBeforeHook = async (hook, data, originalDocs, format, req)=>{
14
+ const applyExportBeforeHook = async ({ data, exportDoc, format, hook, originalDocs, req })=>{
14
15
  if (!hook || data.length === 0) {
15
16
  return data;
16
17
  }
17
18
  return hook({
18
19
  batchNumber: 1,
19
20
  data,
21
+ exportDoc,
20
22
  format,
21
23
  originalData: originalDocs,
22
24
  req,
@@ -25,10 +27,13 @@ const applyExportBeforeHook = async (hook, data, originalDocs, format, req)=>{
25
27
  };
26
28
  export const handlePreview = async (req)=>{
27
29
  await addDataAndFileToRequest(req);
28
- const { collectionSlug, draft: draftFromReq, fields, limit: exportLimit, locale, previewLimit: rawPreviewLimit = DEFAULT_PREVIEW_LIMIT, previewPage: rawPreviewPage = 1, sort, where: whereFromReq = {} } = req.data;
30
+ const { collectionSlug, draft: draftFromReq, fields, formData, limit: exportLimit, locale, previewLimit: rawPreviewLimit = DEFAULT_PREVIEW_LIMIT, previewPage: rawPreviewPage = 1, sort, where: whereFromReq = {} } = req.data;
29
31
  // Validate and clamp pagination values to safe bounds
30
32
  const previewLimit = Math.max(MIN_PREVIEW_LIMIT, Math.min(rawPreviewLimit, MAX_PREVIEW_LIMIT));
31
33
  const previewPage = Math.max(MIN_PREVIEW_PAGE, rawPreviewPage);
34
+ const exportDoc = getSubmittedFormValues({
35
+ formData: formData ?? {}
36
+ });
32
37
  const targetCollection = req.payload.collections[collectionSlug];
33
38
  if (!targetCollection) {
34
39
  return Response.json({
@@ -154,7 +159,14 @@ export const handlePreview = async (req)=>{
154
159
  format: 'csv',
155
160
  req
156
161
  }));
157
- transformed = await applyExportBeforeHook(exportHooks?.before, transformed, docs, 'csv', req);
162
+ transformed = await applyExportBeforeHook({
163
+ data: transformed,
164
+ exportDoc,
165
+ format: 'csv',
166
+ hook: exportHooks?.before,
167
+ originalDocs: docs,
168
+ req
169
+ });
158
170
  if (schemaColumns && transformed.length > 0) {
159
171
  const dataColumns = [];
160
172
  const seenCols = new Set();
@@ -199,13 +211,20 @@ export const handlePreview = async (req)=>{
199
211
  const trimmed = {};
200
212
  for (const key of fields){
201
213
  const value = getObjectDotNotation(output, key);
202
- setNestedValue(trimmed, key, value ?? null);
214
+ setNestedValue(trimmed, key, value ?? null, output);
203
215
  }
204
216
  output = trimmed;
205
217
  }
206
218
  return output;
207
219
  });
208
- transformed = await applyExportBeforeHook(exportHooks?.before, transformed, docs, 'json', req);
220
+ transformed = await applyExportBeforeHook({
221
+ data: transformed,
222
+ exportDoc,
223
+ format: 'json',
224
+ hook: exportHooks?.before,
225
+ originalDocs: docs,
226
+ req
227
+ });
209
228
  }
210
229
  const hasNextPage = previewPage < previewTotalPages;
211
230
  const hasPrevPage = previewPage > 1;