@payloadcms/plugin-import-export 4.0.0-canary.7 → 4.0.0-canary.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImportPreview/index.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAkC,MAAM,OAAO,CAAA;AAStD,OAAO,aAAa,CAAA;AAIpB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EA2mBjC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImportPreview/index.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAkC,MAAM,OAAO,CAAA;AAStD,OAAO,aAAa,CAAA;AAoBpB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EA2mBjC,CAAA"}
@@ -8,6 +8,20 @@ import React, { useState, useTransition } from 'react';
8
8
  import { DEFAULT_PREVIEW_LIMIT, PREVIEW_LIMIT_OPTIONS } from '../../constants.js';
9
9
  import './index.css';
10
10
  const baseClass = 'import-preview';
11
+ /**
12
+ * Browser-native ArrayBuffer → base64. Avoids Node's `Buffer`, which is not
13
+ * available in the browser under bundlers that don't polyfill it (e.g. Vite),
14
+ * unlike Next's webpack build. Chunked to stay under `String.fromCharCode`'s
15
+ * argument-count limit for large files.
16
+ */ const arrayBufferToBase64 = (arrayBuffer)=>{
17
+ const bytes = new Uint8Array(arrayBuffer);
18
+ const chunkSize = 0x8000;
19
+ let binary = '';
20
+ for(let i = 0; i < bytes.length; i += chunkSize){
21
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
22
+ }
23
+ return btoa(binary);
24
+ };
11
25
  export const ImportPreview = ()=>{
12
26
  const [isPending, startTransition] = useTransition();
13
27
  const { config, config: { routes } } = useConfig();
@@ -86,7 +100,7 @@ export const ImportPreview = ()=>{
86
100
  if (fileField?.value && fileField.value instanceof File) {
87
101
  // File is being uploaded, read its contents
88
102
  const arrayBuffer = await fileField.value.arrayBuffer();
89
- const base64 = Buffer.from(arrayBuffer).toString('base64');
103
+ const base64 = arrayBufferToBase64(arrayBuffer);
90
104
  fileData = base64;
91
105
  } else if (url) {
92
106
  // File has been saved, fetch from URL
@@ -97,7 +111,7 @@ export const ImportPreview = ()=>{
97
111
  throw new Error('Failed to fetch file');
98
112
  }
99
113
  const arrayBuffer = await response.arrayBuffer();
100
- const base64 = Buffer.from(arrayBuffer).toString('base64');
114
+ const base64 = arrayBufferToBase64(arrayBuffer);
101
115
  fileData = base64;
102
116
  }
103
117
  if (!fileData) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/ImportPreview/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Column, PaginatedDocs } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Pagination,\n PerPage,\n Table,\n Translation,\n useConfig,\n useDebouncedEffect,\n useDocumentInfo,\n useField,\n useFormFields,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatDocTitle } from '@payloadcms/ui/shared'\nimport { fieldAffectsData, getObjectDotNotation } from 'payload/shared'\nimport React, { useState, useTransition } from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\nimport type { ImportPreviewResponse } from '../../types.js'\n\nimport { DEFAULT_PREVIEW_LIMIT, PREVIEW_LIMIT_OPTIONS } from '../../constants.js'\nimport './index.css'\n\nconst baseClass = 'import-preview'\n\nexport const ImportPreview: React.FC = () => {\n const [isPending, startTransition] = useTransition()\n const {\n config,\n config: { routes },\n } = useConfig()\n const { collectionSlug } = useDocumentInfo()\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n const { value: targetCollectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { value: importMode } = useField<string>({ path: 'importMode' })\n const { value: matchField } = useField<string>({ path: 'matchField' })\n const { value: filename } = useField<string>({ path: 'filename' })\n const { value: url } = useField<string>({ path: 'url' })\n const { value: mimeType } = useField<string>({ path: 'mimeType' })\n const { value: status } = useField<string>({ path: 'status' })\n const { value: summary } = useField<any>({ path: 'summary' })\n\n // Access the file field directly from form fields\n const fileField = useFormFields(([fields]) => fields?.file || null)\n\n const [dataToRender, setDataToRender] = useState<Record<string, unknown>[]>([])\n const [columns, setColumns] = useState<Column[]>([])\n const [totalDocs, setTotalDocs] = useState<number>(0)\n const [error, setError] = useState<null | string>(null)\n\n // Preview pagination state\n const [previewPage, setPreviewPage] = useState(1)\n const [previewLimit, setPreviewLimit] = useState(DEFAULT_PREVIEW_LIMIT)\n const [paginationData, setPaginationData] = useState<null | Pick<\n PaginatedDocs,\n 'hasNextPage' | 'hasPrevPage' | 'limit' | 'nextPage' | 'page' | 'prevPage' | 'totalPages'\n >>(null)\n\n const collectionConfig = React.useMemo(\n () => config.collections.find((c) => c.slug === targetCollectionSlug),\n [targetCollectionSlug, config.collections],\n )\n\n useDebouncedEffect(\n () => {\n if (!collectionSlug || !targetCollectionSlug) {\n return\n }\n\n if (!targetCollectionSlug || (!url && !fileField?.value)) {\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n return\n }\n\n if (!collectionConfig) {\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n return\n }\n\n const abortController = new AbortController()\n\n const processFileData = async () => {\n setError(null)\n\n try {\n // Determine format from file\n let format: 'csv' | 'json' = 'json'\n if (fileField?.value && fileField.value instanceof File) {\n const file = fileField.value\n format = file.type === 'text/csv' || file.name?.endsWith('.csv') ? 'csv' : 'json'\n } else if (mimeType === 'text/csv' || filename?.endsWith('.csv')) {\n format = 'csv'\n }\n\n // Get file data as base64\n let fileData: string | undefined\n\n if (fileField?.value && fileField.value instanceof File) {\n // File is being uploaded, read its contents\n const arrayBuffer = await fileField.value.arrayBuffer()\n const base64 = Buffer.from(arrayBuffer).toString('base64')\n fileData = base64\n } else if (url) {\n // File has been saved, fetch from URL\n const response = await fetch(url, { signal: abortController.signal })\n if (!response.ok) {\n throw new Error('Failed to fetch file')\n }\n const arrayBuffer = await response.arrayBuffer()\n const base64 = Buffer.from(arrayBuffer).toString('base64')\n fileData = base64\n }\n\n if (!fileData) {\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n return\n }\n\n // Fetch transformed data from the server\n const res = await fetch(`${routes.api}/${collectionSlug}/preview-data`, {\n body: JSON.stringify({\n collectionSlug: targetCollectionSlug,\n fileData,\n format,\n previewLimit,\n previewPage,\n }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n signal: abortController.signal,\n })\n\n if (!res.ok) {\n throw new Error('Failed to process file')\n }\n\n const {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n page: responsePage,\n totalDocs: serverTotalDocs,\n totalPages,\n }: ImportPreviewResponse = await res.json()\n\n setTotalDocs(serverTotalDocs)\n setPaginationData({\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n nextPage: responsePage + 1,\n page: responsePage,\n prevPage: responsePage - 1,\n totalPages,\n })\n\n if (!Array.isArray(docs) || docs.length === 0) {\n setDataToRender([])\n setColumns([])\n return\n }\n\n // Build columns from collection fields without traverseFields\n const buildColumnsFromFields = (\n fields: ClientField[],\n parentPath = '',\n parentLabel = '',\n ): Column[] => {\n const cols: Column[] = []\n\n fields.forEach((field) => {\n if (!fieldAffectsData(field) || field.admin?.disabled) {\n return\n }\n\n // Build the field path\n const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name\n\n // Get the field label\n let label = field.name\n if ('label' in field && field.label) {\n label = getTranslation(field.label, i18n)\n }\n\n // Add parent label prefix if in a group\n if (parentLabel) {\n label = `${parentLabel} > ${label}`\n }\n\n // Skip if this field doesn't exist in any document\n const hasData = docs.some((doc) => {\n const value = getObjectDotNotation(doc, fieldPath)\n return value !== undefined && value !== null\n })\n\n if (!hasData && field.type !== 'relationship') {\n return\n }\n\n cols.push({\n accessor: fieldPath,\n active: true,\n field,\n Heading: label,\n renderedCells: docs.map((doc) => {\n const value = getObjectDotNotation(doc, fieldPath)\n\n if (value === undefined || value === null) {\n return null\n }\n\n // Format based on field type\n if (field.type === 'relationship' || field.type === 'upload') {\n // Handle relationships\n if (typeof value === 'object' && !Array.isArray(value)) {\n // Single relationship\n const relationTo = Array.isArray(field.relationTo)\n ? (value as any).relationTo\n : field.relationTo\n\n const relatedConfig = config.collections.find((c) => c.slug === relationTo)\n if (relatedConfig && relatedConfig.admin?.useAsTitle) {\n const titleValue = (value as any)[relatedConfig.admin.useAsTitle]\n if (titleValue) {\n return formatDocTitle({\n collectionConfig: relatedConfig,\n data: value as any,\n dateFormat: config.admin.dateFormat,\n i18n,\n })\n }\n }\n\n // Fallback to ID\n const id = (value as any).id || value\n return `${getTranslation(relatedConfig?.labels?.singular || relationTo, i18n)}: ${id}`\n } else if (Array.isArray(value)) {\n // Multiple relationships\n return value\n .map((item) => {\n if (typeof item === 'object') {\n const relationTo = Array.isArray(field.relationTo)\n ? item.relationTo\n : field.relationTo\n const relatedConfig = config.collections.find(\n (c) => c.slug === relationTo,\n )\n\n if (relatedConfig && relatedConfig.admin?.useAsTitle) {\n const titleValue = item[relatedConfig.admin.useAsTitle]\n if (titleValue) {\n return formatDocTitle({\n collectionConfig: relatedConfig,\n data: item,\n dateFormat: config.admin.dateFormat,\n i18n,\n })\n }\n }\n\n return item.id || item\n }\n return item\n })\n .join(', ')\n }\n\n // Just an ID\n return String(value)\n } else if (field.type === 'date') {\n // Display date as string to avoid wrong locale/timezone conversion\n return String(value)\n } else if (field.type === 'checkbox') {\n return value ? '✓' : '✗'\n } else if (field.type === 'select' || field.type === 'radio') {\n // Show the label for select/radio options\n const option = field.options?.find((opt) => {\n if (typeof opt === 'string') {\n return opt === value\n }\n return opt.value === value\n })\n\n if (option && typeof option === 'object') {\n return getTranslation(option.label, i18n)\n }\n return String(value)\n } else if (field.type === 'number') {\n return String(value)\n } else if (Array.isArray(value)) {\n // Handle arrays\n if (field.type === 'blocks') {\n return value.map((block: any) => `${block.blockType || 'Block'}`).join(', ')\n }\n return `[${value.length} items]`\n } else if (typeof value === 'object') {\n // Handle objects\n if (field.type === 'group') {\n return '{...}'\n }\n return JSON.stringify(value)\n }\n\n return String(value)\n }),\n })\n\n // For groups, add nested fields with parent label\n if (field.type === 'group' && 'fields' in field) {\n const groupLabel =\n 'label' in field && field.label ? getTranslation(field.label, i18n) : field.name\n\n const nestedCols = buildColumnsFromFields(\n field.fields,\n fieldPath,\n parentLabel ? `${parentLabel} > ${groupLabel}` : groupLabel,\n )\n cols.push(...nestedCols)\n }\n\n // For tabs, process the fields within\n if ('tabs' in field && Array.isArray(field.tabs)) {\n field.tabs.forEach((tab) => {\n if ('name' in tab && tab.name) {\n // Named tab\n const tabPath = parentPath ? `${parentPath}.${tab.name}` : tab.name\n const tabLabel =\n 'label' in tab && tab.label ? getTranslation(tab.label, i18n) : tab.name\n\n const tabCols = buildColumnsFromFields(\n tab.fields,\n tabPath,\n parentLabel ? `${parentLabel} > ${tabLabel}` : tabLabel,\n )\n cols.push(...tabCols)\n } else {\n // Unnamed tab - fields go directly under parent\n const tabLabel =\n 'label' in tab && tab.label ? getTranslation(tab.label, i18n) : ''\n\n const tabCols = buildColumnsFromFields(\n tab.fields,\n parentPath,\n tabLabel && typeof tabLabel === 'string' && parentLabel\n ? `${parentLabel} > ${tabLabel}`\n : typeof tabLabel === 'string'\n ? tabLabel\n : parentLabel,\n )\n cols.push(...tabCols)\n }\n })\n }\n })\n\n return cols\n }\n\n const fieldColumns = buildColumnsFromFields(collectionConfig.fields)\n\n const existingAccessors = new Set(fieldColumns.map((column) => column.accessor))\n\n // Discover all fields from document data to determine column order\n // Respect the order fields appear in the data (e.g., CSV column order)\n const dataFieldOrder: string[] = []\n const dataFieldsSet = new Set<string>()\n\n // Collect all fields from all docs to get comprehensive field list\n docs.forEach((doc) => {\n Object.keys(doc).forEach((key) => {\n if (!dataFieldsSet.has(key) && doc[key] !== undefined && doc[key] !== null) {\n dataFieldsSet.add(key)\n dataFieldOrder.push(key)\n }\n })\n })\n\n // Helper to create a column for a field\n const createColumnForField = (fieldName: string): Column => ({\n accessor: fieldName,\n active: true,\n field: { name: fieldName } as ClientField,\n Heading: getTranslation(fieldName, i18n),\n renderedCells: docs.map((doc) => {\n const value = doc[fieldName]\n if (value === undefined || value === null) {\n return null\n }\n\n return String(value)\n }),\n })\n\n // Build columns respecting data order for fields not in config\n // For fields in config, use their natural order from fieldColumns\n const finalColumns: Column[] = []\n const addedAccessors = new Set<string>()\n\n // Process fields in the order they appear in the data\n dataFieldOrder.forEach((fieldName) => {\n if (existingAccessors.has(fieldName)) {\n // This field is from the collection config\n const configColumn = fieldColumns.find((col) => col.accessor === fieldName)\n if (configColumn && !addedAccessors.has(fieldName)) {\n finalColumns.push(configColumn)\n addedAccessors.add(fieldName)\n }\n } else {\n // This is an additional field (system field or extra data field)\n if (!addedAccessors.has(fieldName)) {\n finalColumns.push(createColumnForField(fieldName))\n addedAccessors.add(fieldName)\n }\n }\n })\n\n // Add any remaining config fields that weren't in the data\n fieldColumns.forEach((col) => {\n if (!addedAccessors.has(col.accessor)) {\n finalColumns.push(col)\n addedAccessors.add(col.accessor)\n }\n })\n\n setColumns(finalColumns)\n setDataToRender(docs)\n } catch (err) {\n console.error('Error processing file data:', err)\n setError(err instanceof Error ? err.message : 'Failed to load preview')\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n }\n }\n\n startTransition(async () => await processFileData())\n\n return () => {\n if (!abortController.signal.aborted) {\n abortController.abort('Component unmounted')\n }\n }\n },\n [\n collectionSlug,\n targetCollectionSlug,\n url,\n filename,\n mimeType,\n fileField?.value,\n collectionConfig,\n config,\n i18n,\n previewLimit,\n previewPage,\n routes.api,\n ],\n 500,\n )\n\n // If import has been processed, show results instead of preview\n if (status !== 'pending' && summary) {\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:importResults\" t={t} />\n </h3>\n </div>\n <div className={`${baseClass}__results`}>\n <p>\n <strong>Status:</strong> {status}\n </p>\n <p>\n <strong>Imported:</strong> {summary.imported || 0}\n </p>\n <p>\n <strong>Updated:</strong> {summary.updated || 0}\n </p>\n <p>\n <strong>Total:</strong> {summary.total || 0}\n </p>\n {summary.issues > 0 && (\n <p>\n <strong>Issues:</strong> {summary.issues}\n </p>\n )}\n {summary.issueDetails && summary.issueDetails.length > 0 && (\n <div style={{ marginTop: '1rem' }}>\n <strong>Issue Details:</strong>\n <ul style={{ marginTop: '0.5rem' }}>\n {summary.issueDetails.slice(0, 10).map((issue: any, index: number) => (\n <li key={index}>\n Row {issue.row}: {issue.error}\n </li>\n ))}\n {summary.issueDetails.length > 10 && (\n <li>... and {summary.issueDetails.length - 10} more issues</li>\n )}\n </ul>\n </div>\n )}\n </div>\n </div>\n )\n }\n\n if (!targetCollectionSlug) {\n return (\n <div className={baseClass}>\n <p style={{ opacity: 0.6 }}>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:collectionRequired\" t={t} />\n </p>\n </div>\n )\n }\n\n if (error) {\n return (\n <div className={baseClass}>\n <p style={{ color: 'red' }}>\n <Translation i18nKey=\"general:error\" t={t} />: {error}\n </p>\n </div>\n )\n }\n\n if (!url && !fileField?.value) {\n return (\n <div className={baseClass}>\n <p style={{ opacity: 0.6 }}>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:uploadFileToSeePreview\" t={t} />\n </p>\n </div>\n )\n }\n\n const handlePageChange = (page: number) => {\n setPreviewPage(page)\n }\n\n const handlePerPageChange = (newLimit: number) => {\n setPreviewLimit(newLimit)\n setPreviewPage(1)\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n <Translation i18nKey=\"version:preview\" t={t} />\n </h3>\n {totalDocs > 0 && !isPending && (\n <div className={`${baseClass}__info`}>\n <span className={`${baseClass}__import-count`}>\n <Translation\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n i18nKey=\"plugin-import-export:documentsToImport\"\n t={t}\n variables={{\n count: totalDocs,\n }}\n />\n </span>\n {' | '}\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:mode\" t={t} />: {importMode || 'create'}\n {importMode !== 'create' && (\n <>\n {' | '}\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:matchBy\" t={t} />: {matchField || 'id'}\n </>\n )}\n </div>\n )}\n </div>\n {isPending && !dataToRender.length && (\n <div className={`${baseClass}__loading`}>\n <Translation i18nKey=\"general:loading\" t={t} />\n </div>\n )}\n {dataToRender.length > 0 && <Table columns={columns} data={dataToRender} />}\n {!isPending && dataToRender.length === 0 && targetCollectionSlug && (\n <p>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:noDataToPreview\" t={t} />\n </p>\n )}\n {paginationData && totalDocs > 0 && (\n <div className={`${baseClass}__pagination`}>\n {paginationData.totalPages > 1 && (\n <Pagination\n hasNextPage={paginationData.hasNextPage}\n hasPrevPage={paginationData.hasPrevPage}\n nextPage={paginationData.nextPage ?? undefined}\n numberOfNeighbors={1}\n onChange={handlePageChange}\n page={paginationData.page}\n prevPage={paginationData.prevPage ?? undefined}\n totalPages={paginationData.totalPages}\n />\n )}\n <span className={`${baseClass}__page-info`}>\n <Translation\n // @ts-expect-error - plugin translations not typed\n i18nKey=\"plugin-import-export:previewPageInfo\"\n t={t}\n variables={{\n end: Math.min((paginationData.page ?? 1) * previewLimit, totalDocs),\n start: ((paginationData.page ?? 1) - 1) * previewLimit + 1,\n total: totalDocs,\n }}\n />\n </span>\n <PerPage\n handleChange={handlePerPageChange}\n limit={previewLimit}\n limits={PREVIEW_LIMIT_OPTIONS}\n />\n </div>\n )}\n </div>\n )\n}\n"],"names":["getTranslation","Pagination","PerPage","Table","Translation","useConfig","useDebouncedEffect","useDocumentInfo","useField","useFormFields","useTranslation","formatDocTitle","fieldAffectsData","getObjectDotNotation","React","useState","useTransition","DEFAULT_PREVIEW_LIMIT","PREVIEW_LIMIT_OPTIONS","baseClass","ImportPreview","isPending","startTransition","config","routes","collectionSlug","i18n","t","value","targetCollectionSlug","path","importMode","matchField","filename","url","mimeType","status","summary","fileField","fields","file","dataToRender","setDataToRender","columns","setColumns","totalDocs","setTotalDocs","error","setError","previewPage","setPreviewPage","previewLimit","setPreviewLimit","paginationData","setPaginationData","collectionConfig","useMemo","collections","find","c","slug","abortController","AbortController","processFileData","format","File","type","name","endsWith","fileData","arrayBuffer","base64","Buffer","from","toString","response","fetch","signal","ok","Error","res","api","body","JSON","stringify","credentials","headers","method","docs","hasNextPage","hasPrevPage","limit","responseLimit","page","responsePage","serverTotalDocs","totalPages","json","nextPage","prevPage","Array","isArray","length","buildColumnsFromFields","parentPath","parentLabel","cols","forEach","field","admin","disabled","fieldPath","label","hasData","some","doc","undefined","push","accessor","active","Heading","renderedCells","map","relationTo","relatedConfig","useAsTitle","titleValue","data","dateFormat","id","labels","singular","item","join","String","option","options","opt","block","blockType","groupLabel","nestedCols","tabs","tab","tabPath","tabLabel","tabCols","fieldColumns","existingAccessors","Set","column","dataFieldOrder","dataFieldsSet","Object","keys","key","has","add","createColumnForField","fieldName","finalColumns","addedAccessors","configColumn","col","err","console","message","aborted","abort","div","className","h3","i18nKey","p","strong","imported","updated","total","issues","issueDetails","style","marginTop","ul","slice","issue","index","li","row","opacity","color","handlePageChange","handlePerPageChange","newLimit","span","variables","count","numberOfNeighbors","onChange","end","Math","min","start","handleChange","limits"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,UAAU,EACVC,OAAO,EACPC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,kBAAkB,EAClBC,eAAe,EACfC,QAAQ,EACRC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aAAa6D,MAAM,kBAChC,KAACmE;gBAAIC,WAAW,GAAGvJ,UAAU,SAAS,CAAC;0BACrC,cAAA,KAACf;oBAAYwK,SAAQ;oBAAkBjJ,GAAGA;;;YAG7Cc,aAAa6D,MAAM,GAAG,mBAAK,KAACnG;gBAAMwC,SAASA;gBAASoF,MAAMtF;;YAC1D,CAACpB,aAAaoB,aAAa6D,MAAM,KAAK,KAAKzE,sCAC1C,KAACgJ;0BAEC,cAAA,KAACzK;oBAAYwK,SAAQ;oBAAuCjJ,GAAGA;;;YAGlE0B,kBAAkBR,YAAY,mBAC7B,MAAC4H;gBAAIC,WAAW,GAAGvJ,UAAU,YAAY,CAAC;;oBACvCkC,eAAe2C,UAAU,GAAG,mBAC3B,KAAC/F;wBACCwF,aAAapC,eAAeoC,WAAW;wBACvCC,aAAarC,eAAeqC,WAAW;wBACvCQ,UAAU7C,eAAe6C,QAAQ,IAAIkB;wBACrCgF,mBAAmB;wBACnBC,UAAUP;wBACVjG,MAAMxC,eAAewC,IAAI;wBACzBM,UAAU9C,eAAe8C,QAAQ,IAAIiB;wBACrCpB,YAAY3C,eAAe2C,UAAU;;kCAGzC,KAACiG;wBAAKvB,WAAW,GAAGvJ,UAAU,WAAW,CAAC;kCACxC,cAAA,KAACf;4BACC,mDAAmD;4BACnDwK,SAAQ;4BACRjJ,GAAGA;4BACHuK,WAAW;gCACTI,KAAKC,KAAKC,GAAG,CAAC,AAACnJ,CAAAA,eAAewC,IAAI,IAAI,CAAA,IAAK1C,cAAcN;gCACzD4J,OAAO,AAAC,CAAA,AAACpJ,CAAAA,eAAewC,IAAI,IAAI,CAAA,IAAK,CAAA,IAAK1C,eAAe;gCACzD8H,OAAOpI;4BACT;;;kCAGJ,KAAC3C;wBACCwM,cAAcX;wBACdpG,OAAOxC;wBACPwJ,QAAQzL;;;;;;AAMpB,EAAC"}
1
+ {"version":3,"sources":["../../../src/components/ImportPreview/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Column, PaginatedDocs } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Pagination,\n PerPage,\n Table,\n Translation,\n useConfig,\n useDebouncedEffect,\n useDocumentInfo,\n useField,\n useFormFields,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatDocTitle } from '@payloadcms/ui/shared'\nimport { fieldAffectsData, getObjectDotNotation } from 'payload/shared'\nimport React, { useState, useTransition } from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\nimport type { ImportPreviewResponse } from '../../types.js'\n\nimport { DEFAULT_PREVIEW_LIMIT, PREVIEW_LIMIT_OPTIONS } from '../../constants.js'\nimport './index.css'\n\nconst baseClass = 'import-preview'\n\n/**\n * Browser-native ArrayBuffer → base64. Avoids Node's `Buffer`, which is not\n * available in the browser under bundlers that don't polyfill it (e.g. Vite),\n * unlike Next's webpack build. Chunked to stay under `String.fromCharCode`'s\n * argument-count limit for large files.\n */\nconst arrayBufferToBase64 = (arrayBuffer: ArrayBuffer): string => {\n const bytes = new Uint8Array(arrayBuffer)\n const chunkSize = 0x8000\n let binary = ''\n for (let i = 0; i < bytes.length; i += chunkSize) {\n binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize))\n }\n return btoa(binary)\n}\n\nexport const ImportPreview: React.FC = () => {\n const [isPending, startTransition] = useTransition()\n const {\n config,\n config: { routes },\n } = useConfig()\n const { collectionSlug } = useDocumentInfo()\n const { i18n, t } = useTranslation<\n PluginImportExportTranslations,\n PluginImportExportTranslationKeys\n >()\n\n const { value: targetCollectionSlug } = useField<string>({ path: 'collectionSlug' })\n const { value: importMode } = useField<string>({ path: 'importMode' })\n const { value: matchField } = useField<string>({ path: 'matchField' })\n const { value: filename } = useField<string>({ path: 'filename' })\n const { value: url } = useField<string>({ path: 'url' })\n const { value: mimeType } = useField<string>({ path: 'mimeType' })\n const { value: status } = useField<string>({ path: 'status' })\n const { value: summary } = useField<any>({ path: 'summary' })\n\n // Access the file field directly from form fields\n const fileField = useFormFields(([fields]) => fields?.file || null)\n\n const [dataToRender, setDataToRender] = useState<Record<string, unknown>[]>([])\n const [columns, setColumns] = useState<Column[]>([])\n const [totalDocs, setTotalDocs] = useState<number>(0)\n const [error, setError] = useState<null | string>(null)\n\n // Preview pagination state\n const [previewPage, setPreviewPage] = useState(1)\n const [previewLimit, setPreviewLimit] = useState(DEFAULT_PREVIEW_LIMIT)\n const [paginationData, setPaginationData] = useState<null | Pick<\n PaginatedDocs,\n 'hasNextPage' | 'hasPrevPage' | 'limit' | 'nextPage' | 'page' | 'prevPage' | 'totalPages'\n >>(null)\n\n const collectionConfig = React.useMemo(\n () => config.collections.find((c) => c.slug === targetCollectionSlug),\n [targetCollectionSlug, config.collections],\n )\n\n useDebouncedEffect(\n () => {\n if (!collectionSlug || !targetCollectionSlug) {\n return\n }\n\n if (!targetCollectionSlug || (!url && !fileField?.value)) {\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n return\n }\n\n if (!collectionConfig) {\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n return\n }\n\n const abortController = new AbortController()\n\n const processFileData = async () => {\n setError(null)\n\n try {\n // Determine format from file\n let format: 'csv' | 'json' = 'json'\n if (fileField?.value && fileField.value instanceof File) {\n const file = fileField.value\n format = file.type === 'text/csv' || file.name?.endsWith('.csv') ? 'csv' : 'json'\n } else if (mimeType === 'text/csv' || filename?.endsWith('.csv')) {\n format = 'csv'\n }\n\n // Get file data as base64\n let fileData: string | undefined\n\n if (fileField?.value && fileField.value instanceof File) {\n // File is being uploaded, read its contents\n const arrayBuffer = await fileField.value.arrayBuffer()\n const base64 = arrayBufferToBase64(arrayBuffer)\n fileData = base64\n } else if (url) {\n // File has been saved, fetch from URL\n const response = await fetch(url, { signal: abortController.signal })\n if (!response.ok) {\n throw new Error('Failed to fetch file')\n }\n const arrayBuffer = await response.arrayBuffer()\n const base64 = arrayBufferToBase64(arrayBuffer)\n fileData = base64\n }\n\n if (!fileData) {\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n return\n }\n\n // Fetch transformed data from the server\n const res = await fetch(`${routes.api}/${collectionSlug}/preview-data`, {\n body: JSON.stringify({\n collectionSlug: targetCollectionSlug,\n fileData,\n format,\n previewLimit,\n previewPage,\n }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n signal: abortController.signal,\n })\n\n if (!res.ok) {\n throw new Error('Failed to process file')\n }\n\n const {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n page: responsePage,\n totalDocs: serverTotalDocs,\n totalPages,\n }: ImportPreviewResponse = await res.json()\n\n setTotalDocs(serverTotalDocs)\n setPaginationData({\n hasNextPage,\n hasPrevPage,\n limit: responseLimit,\n nextPage: responsePage + 1,\n page: responsePage,\n prevPage: responsePage - 1,\n totalPages,\n })\n\n if (!Array.isArray(docs) || docs.length === 0) {\n setDataToRender([])\n setColumns([])\n return\n }\n\n // Build columns from collection fields without traverseFields\n const buildColumnsFromFields = (\n fields: ClientField[],\n parentPath = '',\n parentLabel = '',\n ): Column[] => {\n const cols: Column[] = []\n\n fields.forEach((field) => {\n if (!fieldAffectsData(field) || field.admin?.disabled) {\n return\n }\n\n // Build the field path\n const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name\n\n // Get the field label\n let label = field.name\n if ('label' in field && field.label) {\n label = getTranslation(field.label, i18n)\n }\n\n // Add parent label prefix if in a group\n if (parentLabel) {\n label = `${parentLabel} > ${label}`\n }\n\n // Skip if this field doesn't exist in any document\n const hasData = docs.some((doc) => {\n const value = getObjectDotNotation(doc, fieldPath)\n return value !== undefined && value !== null\n })\n\n if (!hasData && field.type !== 'relationship') {\n return\n }\n\n cols.push({\n accessor: fieldPath,\n active: true,\n field,\n Heading: label,\n renderedCells: docs.map((doc) => {\n const value = getObjectDotNotation(doc, fieldPath)\n\n if (value === undefined || value === null) {\n return null\n }\n\n // Format based on field type\n if (field.type === 'relationship' || field.type === 'upload') {\n // Handle relationships\n if (typeof value === 'object' && !Array.isArray(value)) {\n // Single relationship\n const relationTo = Array.isArray(field.relationTo)\n ? (value as any).relationTo\n : field.relationTo\n\n const relatedConfig = config.collections.find((c) => c.slug === relationTo)\n if (relatedConfig && relatedConfig.admin?.useAsTitle) {\n const titleValue = (value as any)[relatedConfig.admin.useAsTitle]\n if (titleValue) {\n return formatDocTitle({\n collectionConfig: relatedConfig,\n data: value as any,\n dateFormat: config.admin.dateFormat,\n i18n,\n })\n }\n }\n\n // Fallback to ID\n const id = (value as any).id || value\n return `${getTranslation(relatedConfig?.labels?.singular || relationTo, i18n)}: ${id}`\n } else if (Array.isArray(value)) {\n // Multiple relationships\n return value\n .map((item) => {\n if (typeof item === 'object') {\n const relationTo = Array.isArray(field.relationTo)\n ? item.relationTo\n : field.relationTo\n const relatedConfig = config.collections.find(\n (c) => c.slug === relationTo,\n )\n\n if (relatedConfig && relatedConfig.admin?.useAsTitle) {\n const titleValue = item[relatedConfig.admin.useAsTitle]\n if (titleValue) {\n return formatDocTitle({\n collectionConfig: relatedConfig,\n data: item,\n dateFormat: config.admin.dateFormat,\n i18n,\n })\n }\n }\n\n return item.id || item\n }\n return item\n })\n .join(', ')\n }\n\n // Just an ID\n return String(value)\n } else if (field.type === 'date') {\n // Display date as string to avoid wrong locale/timezone conversion\n return String(value)\n } else if (field.type === 'checkbox') {\n return value ? '✓' : '✗'\n } else if (field.type === 'select' || field.type === 'radio') {\n // Show the label for select/radio options\n const option = field.options?.find((opt) => {\n if (typeof opt === 'string') {\n return opt === value\n }\n return opt.value === value\n })\n\n if (option && typeof option === 'object') {\n return getTranslation(option.label, i18n)\n }\n return String(value)\n } else if (field.type === 'number') {\n return String(value)\n } else if (Array.isArray(value)) {\n // Handle arrays\n if (field.type === 'blocks') {\n return value.map((block: any) => `${block.blockType || 'Block'}`).join(', ')\n }\n return `[${value.length} items]`\n } else if (typeof value === 'object') {\n // Handle objects\n if (field.type === 'group') {\n return '{...}'\n }\n return JSON.stringify(value)\n }\n\n return String(value)\n }),\n })\n\n // For groups, add nested fields with parent label\n if (field.type === 'group' && 'fields' in field) {\n const groupLabel =\n 'label' in field && field.label ? getTranslation(field.label, i18n) : field.name\n\n const nestedCols = buildColumnsFromFields(\n field.fields,\n fieldPath,\n parentLabel ? `${parentLabel} > ${groupLabel}` : groupLabel,\n )\n cols.push(...nestedCols)\n }\n\n // For tabs, process the fields within\n if ('tabs' in field && Array.isArray(field.tabs)) {\n field.tabs.forEach((tab) => {\n if ('name' in tab && tab.name) {\n // Named tab\n const tabPath = parentPath ? `${parentPath}.${tab.name}` : tab.name\n const tabLabel =\n 'label' in tab && tab.label ? getTranslation(tab.label, i18n) : tab.name\n\n const tabCols = buildColumnsFromFields(\n tab.fields,\n tabPath,\n parentLabel ? `${parentLabel} > ${tabLabel}` : tabLabel,\n )\n cols.push(...tabCols)\n } else {\n // Unnamed tab - fields go directly under parent\n const tabLabel =\n 'label' in tab && tab.label ? getTranslation(tab.label, i18n) : ''\n\n const tabCols = buildColumnsFromFields(\n tab.fields,\n parentPath,\n tabLabel && typeof tabLabel === 'string' && parentLabel\n ? `${parentLabel} > ${tabLabel}`\n : typeof tabLabel === 'string'\n ? tabLabel\n : parentLabel,\n )\n cols.push(...tabCols)\n }\n })\n }\n })\n\n return cols\n }\n\n const fieldColumns = buildColumnsFromFields(collectionConfig.fields)\n\n const existingAccessors = new Set(fieldColumns.map((column) => column.accessor))\n\n // Discover all fields from document data to determine column order\n // Respect the order fields appear in the data (e.g., CSV column order)\n const dataFieldOrder: string[] = []\n const dataFieldsSet = new Set<string>()\n\n // Collect all fields from all docs to get comprehensive field list\n docs.forEach((doc) => {\n Object.keys(doc).forEach((key) => {\n if (!dataFieldsSet.has(key) && doc[key] !== undefined && doc[key] !== null) {\n dataFieldsSet.add(key)\n dataFieldOrder.push(key)\n }\n })\n })\n\n // Helper to create a column for a field\n const createColumnForField = (fieldName: string): Column => ({\n accessor: fieldName,\n active: true,\n field: { name: fieldName } as ClientField,\n Heading: getTranslation(fieldName, i18n),\n renderedCells: docs.map((doc) => {\n const value = doc[fieldName]\n if (value === undefined || value === null) {\n return null\n }\n\n return String(value)\n }),\n })\n\n // Build columns respecting data order for fields not in config\n // For fields in config, use their natural order from fieldColumns\n const finalColumns: Column[] = []\n const addedAccessors = new Set<string>()\n\n // Process fields in the order they appear in the data\n dataFieldOrder.forEach((fieldName) => {\n if (existingAccessors.has(fieldName)) {\n // This field is from the collection config\n const configColumn = fieldColumns.find((col) => col.accessor === fieldName)\n if (configColumn && !addedAccessors.has(fieldName)) {\n finalColumns.push(configColumn)\n addedAccessors.add(fieldName)\n }\n } else {\n // This is an additional field (system field or extra data field)\n if (!addedAccessors.has(fieldName)) {\n finalColumns.push(createColumnForField(fieldName))\n addedAccessors.add(fieldName)\n }\n }\n })\n\n // Add any remaining config fields that weren't in the data\n fieldColumns.forEach((col) => {\n if (!addedAccessors.has(col.accessor)) {\n finalColumns.push(col)\n addedAccessors.add(col.accessor)\n }\n })\n\n setColumns(finalColumns)\n setDataToRender(docs)\n } catch (err) {\n console.error('Error processing file data:', err)\n setError(err instanceof Error ? err.message : 'Failed to load preview')\n setDataToRender([])\n setColumns([])\n setTotalDocs(0)\n setPaginationData(null)\n }\n }\n\n startTransition(async () => await processFileData())\n\n return () => {\n if (!abortController.signal.aborted) {\n abortController.abort('Component unmounted')\n }\n }\n },\n [\n collectionSlug,\n targetCollectionSlug,\n url,\n filename,\n mimeType,\n fileField?.value,\n collectionConfig,\n config,\n i18n,\n previewLimit,\n previewPage,\n routes.api,\n ],\n 500,\n )\n\n // If import has been processed, show results instead of preview\n if (status !== 'pending' && summary) {\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:importResults\" t={t} />\n </h3>\n </div>\n <div className={`${baseClass}__results`}>\n <p>\n <strong>Status:</strong> {status}\n </p>\n <p>\n <strong>Imported:</strong> {summary.imported || 0}\n </p>\n <p>\n <strong>Updated:</strong> {summary.updated || 0}\n </p>\n <p>\n <strong>Total:</strong> {summary.total || 0}\n </p>\n {summary.issues > 0 && (\n <p>\n <strong>Issues:</strong> {summary.issues}\n </p>\n )}\n {summary.issueDetails && summary.issueDetails.length > 0 && (\n <div style={{ marginTop: '1rem' }}>\n <strong>Issue Details:</strong>\n <ul style={{ marginTop: '0.5rem' }}>\n {summary.issueDetails.slice(0, 10).map((issue: any, index: number) => (\n <li key={index}>\n Row {issue.row}: {issue.error}\n </li>\n ))}\n {summary.issueDetails.length > 10 && (\n <li>... and {summary.issueDetails.length - 10} more issues</li>\n )}\n </ul>\n </div>\n )}\n </div>\n </div>\n )\n }\n\n if (!targetCollectionSlug) {\n return (\n <div className={baseClass}>\n <p style={{ opacity: 0.6 }}>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:collectionRequired\" t={t} />\n </p>\n </div>\n )\n }\n\n if (error) {\n return (\n <div className={baseClass}>\n <p style={{ color: 'red' }}>\n <Translation i18nKey=\"general:error\" t={t} />: {error}\n </p>\n </div>\n )\n }\n\n if (!url && !fileField?.value) {\n return (\n <div className={baseClass}>\n <p style={{ opacity: 0.6 }}>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:uploadFileToSeePreview\" t={t} />\n </p>\n </div>\n )\n }\n\n const handlePageChange = (page: number) => {\n setPreviewPage(page)\n }\n\n const handlePerPageChange = (newLimit: number) => {\n setPreviewLimit(newLimit)\n setPreviewPage(1)\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <h3>\n <Translation i18nKey=\"version:preview\" t={t} />\n </h3>\n {totalDocs > 0 && !isPending && (\n <div className={`${baseClass}__info`}>\n <span className={`${baseClass}__import-count`}>\n <Translation\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n i18nKey=\"plugin-import-export:documentsToImport\"\n t={t}\n variables={{\n count: totalDocs,\n }}\n />\n </span>\n {' | '}\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:mode\" t={t} />: {importMode || 'create'}\n {importMode !== 'create' && (\n <>\n {' | '}\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:matchBy\" t={t} />: {matchField || 'id'}\n </>\n )}\n </div>\n )}\n </div>\n {isPending && !dataToRender.length && (\n <div className={`${baseClass}__loading`}>\n <Translation i18nKey=\"general:loading\" t={t} />\n </div>\n )}\n {dataToRender.length > 0 && <Table columns={columns} data={dataToRender} />}\n {!isPending && dataToRender.length === 0 && targetCollectionSlug && (\n <p>\n {/* @ts-expect-error - translations are not typed in plugins */}\n <Translation i18nKey=\"plugin-import-export:noDataToPreview\" t={t} />\n </p>\n )}\n {paginationData && totalDocs > 0 && (\n <div className={`${baseClass}__pagination`}>\n {paginationData.totalPages > 1 && (\n <Pagination\n hasNextPage={paginationData.hasNextPage}\n hasPrevPage={paginationData.hasPrevPage}\n nextPage={paginationData.nextPage ?? undefined}\n numberOfNeighbors={1}\n onChange={handlePageChange}\n page={paginationData.page}\n prevPage={paginationData.prevPage ?? undefined}\n totalPages={paginationData.totalPages}\n />\n )}\n <span className={`${baseClass}__page-info`}>\n <Translation\n // @ts-expect-error - plugin translations not typed\n i18nKey=\"plugin-import-export:previewPageInfo\"\n t={t}\n variables={{\n end: Math.min((paginationData.page ?? 1) * previewLimit, totalDocs),\n start: ((paginationData.page ?? 1) - 1) * previewLimit + 1,\n total: totalDocs,\n }}\n />\n </span>\n <PerPage\n handleChange={handlePerPageChange}\n limit={previewLimit}\n limits={PREVIEW_LIMIT_OPTIONS}\n />\n </div>\n )}\n </div>\n )\n}\n"],"names":["getTranslation","Pagination","PerPage","Table","Translation","useConfig","useDebouncedEffect","useDocumentInfo","useField","useFormFields","useTranslation","formatDocTitle","fieldAffectsData","getObjectDotNotation","React","useState","useTransition","DEFAULT_PREVIEW_LIMIT","PREVIEW_LIMIT_OPTIONS","baseClass","arrayBufferToBase64","arrayBuffer","bytes","Uint8Array","chunkSize","binary","i","length","String","fromCharCode","subarray","btoa","ImportPreview","isPending","startTransition","config","routes","collectionSlug","i18n","t","value","targetCollectionSlug","path","importMode","matchField","filename","url","mimeType","status","summary","fileField","fields","file","dataToRender","setDataToRender","columns","setColumns","totalDocs","setTotalDocs","error","setError","previewPage","setPreviewPage","previewLimit","setPreviewLimit","paginationData","setPaginationData","collectionConfig","useMemo","collections","find","c","slug","abortController","AbortController","processFileData","format","File","type","name","endsWith","fileData","base64","response","fetch","signal","ok","Error","res","api","body","JSON","stringify","credentials","headers","method","docs","hasNextPage","hasPrevPage","limit","responseLimit","page","responsePage","serverTotalDocs","totalPages","json","nextPage","prevPage","Array","isArray","buildColumnsFromFields","parentPath","parentLabel","cols","forEach","field","admin","disabled","fieldPath","label","hasData","some","doc","undefined","push","accessor","active","Heading","renderedCells","map","relationTo","relatedConfig","useAsTitle","titleValue","data","dateFormat","id","labels","singular","item","join","option","options","opt","block","blockType","groupLabel","nestedCols","tabs","tab","tabPath","tabLabel","tabCols","fieldColumns","existingAccessors","Set","column","dataFieldOrder","dataFieldsSet","Object","keys","key","has","add","createColumnForField","fieldName","finalColumns","addedAccessors","configColumn","col","err","console","message","aborted","abort","div","className","h3","i18nKey","p","strong","imported","updated","total","issues","issueDetails","style","marginTop","ul","slice","issue","index","li","row","opacity","color","handlePageChange","handlePerPageChange","newLimit","span","variables","count","numberOfNeighbors","onChange","end","Math","min","start","handleChange","limits"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,UAAU,EACVC,OAAO,EACPC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,kBAAkB,EAClBC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,gBAAgB,EAAEC,oBAAoB,Q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EAAC"}
@@ -2,7 +2,7 @@
2
2
  * Export-specific batch processor for processing documents in batches during export.
3
3
  * Uses the generic batch processing utilities from useBatchProcessor.
4
4
  */
5
- import type { PayloadRequest, SelectType, Sort, TypedUser, Where } from 'payload';
5
+ import type { PayloadRequest, SelectType, Sort, User, Where } from 'payload';
6
6
  import type { ExportAfterHook, ExportBeforeHook } from '../types.js';
7
7
  import { type BatchProcessorOptions } from '../utilities/useBatchProcessor.js';
8
8
  /**
@@ -24,7 +24,7 @@ export interface ExportFindArgs {
24
24
  page?: number;
25
25
  select?: SelectType;
26
26
  sort?: Sort;
27
- user?: TypedUser;
27
+ user?: User;
28
28
  where?: Where;
29
29
  }
30
30
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"batchProcessor.d.ts","sourceRoot":"","sources":["../../src/export/batchProcessor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEjF,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEpE,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAE9E;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,qBAAqB;IACxE,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,OAAO,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,OAAO,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,IAAI,CAAC,EAAE,SAAS,CAAA;I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IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,GAAG,EAAE,cAAc,CAAA;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,YAAY,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,2BAAgC;sBA6NnD,IAAI,kBACjB,oBAAoB,CAAC,IAAI,CAAC,KACzC,OAAO,CAAC,MAAM,EAAE,CAAC;oBA7MS,IAAI,kBACf,oBAAoB,CAAC,IAAI,CAAC,KACzC,OAAO,CAAC,YAAY,CAAC;mBA0GK,IAAI,kBACf,oBAAoB,CAAC,IAAI,CAAC,KACzC,cAAc,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE,CAAC;EAwJ1E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/batchProcessor.ts"],"sourcesContent":["/**\n * Export-specific batch processor for processing documents in batches during export.\n * Uses the generic batch processing utilities from useBatchProcessor.\n */\nimport type { PayloadRequest, SelectType, Sort, TypedUser, Where } from 'payload'\n\nimport type { ExportAfterHook, ExportBeforeHook } from '../types.js'\n\nimport { type BatchProcessorOptions } from '../utilities/useBatchProcessor.js'\n\n/**\n * Export-specific batch processor options\n */\nexport interface ExportBatchProcessorOptions extends BatchProcessorOptions {\n debug?: boolean\n}\n\n/**\n * Find arguments for querying documents during export\n */\nexport interface ExportFindArgs {\n collection: string\n depth: number\n draft: boolean\n limit: number\n locale?: string\n overrideAccess: boolean\n page?: number\n select?: SelectType\n sort?: Sort\n user?: TypedUser\n where?: Where\n}\n\n/**\n * Options for processing an export operation\n */\nexport interface ExportProcessOptions<TDoc = unknown> {\n /**\n * The slug of the collection to export\n */\n collectionSlug: string\n /**\n * Arguments to pass to payload.find()\n */\n findArgs: ExportFindArgs\n /**\n * The export format - affects column tracking for CSV\n */\n format: 'csv' | 'json'\n /** Lifecycle hooks for this export operation */\n hooks?: {\n after?: ExportAfterHook\n before?: ExportBeforeHook\n }\n /**\n * Maximum number of documents to export\n */\n maxDocs: number\n /**\n * The Payload request object\n */\n req: PayloadRequest\n /**\n * Starting page for pagination (default: 1)\n */\n startPage?: number\n /** Total number of docs available (used to compute totalBatches for hooks) */\n totalDocs?: number\n /**\n * Transform function to apply to each document\n */\n transformDoc: (doc: TDoc) => Record<string, unknown>\n}\n\n/**\n * Result from processing an export operation\n */\nexport interface ExportResult {\n /**\n * Discovered column names (for CSV exports)\n */\n columns: string[]\n /**\n * Transformed documents ready for output\n */\n docs: Record<string, unknown>[]\n /**\n * Total number of documents fetched\n */\n fetchedCount: number\n}\n\n/**\n * Creates an export batch processor with the specified options.\n *\n * @param options - Configuration options for the batch processor\n * @returns An object containing the processExport method\n *\n * @example\n * ```ts\n * const processor = createExportBatchProcessor({ batchSize: 100, debug: true })\n *\n * const result = await processor.processExport({\n * collectionSlug: 'posts',\n * findArgs: { collection: 'posts', depth: 1, draft: false, limit: 100, overrideAccess: false },\n * format: 'csv',\n * maxDocs: 1000,\n * req,\n * transformDoc: (doc) => flattenObject({ data: doc }),\n * })\n * ```\n */\nexport function createExportBatchProcessor(options: ExportBatchProcessorOptions = {}) {\n const batchSize = options.batchSize ?? 100\n const debug = options.debug ?? false\n\n const computeTotalBatches = (totalDocs: number | undefined, maxDocs: number): number => {\n const effectiveDocs =\n totalDocs !== undefined\n ? Math.min(totalDocs, maxDocs === Number.POSITIVE_INFINITY ? totalDocs : maxDocs)\n : 0\n return effectiveDocs > 0 ? Math.ceil(effectiveDocs / batchSize) : 1\n }\n\n /**\n * Process an export operation by fetching and transforming documents in batches.\n *\n * @param processOptions - Options for the export operation\n * @returns The export result containing transformed documents and column info\n */\n const processExport = async <TDoc>(\n processOptions: ExportProcessOptions<TDoc>,\n ): Promise<ExportResult> => {\n const {\n findArgs,\n format,\n hooks,\n maxDocs,\n req,\n startPage = 1,\n totalDocs,\n transformDoc,\n } = processOptions\n\n const totalBatches = computeTotalBatches(totalDocs, maxDocs)\n\n const docs: Record<string, unknown>[] = []\n const columnsSet = new Set<string>()\n const columns: string[] = []\n\n let currentPage = startPage\n let fetched = 0\n let hasNextPage = true\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await req.payload.find({\n ...findArgs,\n limit: Math.min(batchSize, remaining),\n page: currentPage,\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Processing export batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n const batchNumber = currentPage - startPage + 1\n const originalDocs = result.docs as Record<string, unknown>[]\n const batchData = result.docs.map((doc) => transformDoc(doc as TDoc))\n\n const dataToWrite =\n hooks?.before && batchData.length > 0\n ? await hooks.before({\n batchNumber,\n data: batchData,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n : batchData\n\n for (const row of dataToWrite) {\n docs.push(row)\n\n if (format === 'csv') {\n for (const key of Object.keys(row)) {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n }\n }\n }\n\n if (hooks?.after && dataToWrite.length > 0) {\n await hooks.after({\n batchNumber,\n data: dataToWrite,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage++\n }\n\n return { columns, docs, fetchedCount: fetched }\n }\n\n /**\n * Async generator for streaming export - yields batches instead of collecting all.\n * Useful for streaming exports where you want to process batches as they're fetched.\n *\n * @param processOptions - Options for the export operation\n * @yields Batch results containing transformed documents and discovered columns\n *\n * @example\n * ```ts\n * const processor = createExportBatchProcessor({ batchSize: 100 })\n *\n * for await (const batch of processor.streamExport({ ... })) {\n * // Process each batch as it's yielded\n * console.log(`Got ${batch.docs.length} documents`)\n * }\n * ```\n */\n async function* streamExport<TDoc>(\n processOptions: ExportProcessOptions<TDoc>,\n ): AsyncGenerator<{ columns: string[]; docs: Record<string, unknown>[] }> {\n const {\n findArgs,\n format,\n hooks,\n maxDocs,\n req,\n startPage = 1,\n totalDocs,\n transformDoc,\n } = processOptions\n\n const totalBatches = computeTotalBatches(totalDocs, maxDocs)\n\n const columnsSet = new Set<string>()\n const columns: string[] = []\n\n let currentPage = startPage\n let fetched = 0\n let hasNextPage = true\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await req.payload.find({\n ...findArgs,\n limit: Math.min(batchSize, remaining),\n page: currentPage,\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Streaming export batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n const batchNumber = currentPage - startPage + 1\n const originalDocs = result.docs as Record<string, unknown>[]\n const batchData = result.docs.map((doc) => transformDoc(doc as TDoc))\n\n const dataToWrite =\n hooks?.before && batchData.length > 0\n ? await hooks.before({\n batchNumber,\n data: batchData,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n : batchData\n\n for (const row of dataToWrite) {\n if (format === 'csv') {\n for (const key of Object.keys(row)) {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n }\n }\n }\n\n yield { columns: [...columns], docs: dataToWrite }\n\n if (hooks?.after && dataToWrite.length > 0) {\n await hooks.after({\n batchNumber,\n data: dataToWrite,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage++\n }\n }\n\n /**\n * Discover all columns from the dataset by scanning through all batches.\n * Useful for CSV exports where you need to know all columns before streaming.\n *\n * @param processOptions - Options for the export operation\n * @returns Array of discovered column names\n */\n const discoverColumns = async <TDoc>(\n processOptions: ExportProcessOptions<TDoc>,\n ): Promise<string[]> => {\n const { findArgs, maxDocs, req, startPage = 1, transformDoc } = processOptions\n\n const columnsSet = new Set<string>()\n const columns: string[] = []\n\n let currentPage = startPage\n let fetched = 0\n let hasNextPage = true\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await req.payload.find({\n ...findArgs,\n limit: Math.min(batchSize, remaining),\n page: currentPage,\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Scanning columns from batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n for (const doc of result.docs) {\n const transformedDoc = transformDoc(doc as TDoc)\n\n for (const key of Object.keys(transformedDoc)) {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n }\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage++\n }\n\n if (debug) {\n req.payload.logger.debug(`Discovered ${columns.length} columns`)\n }\n\n return columns\n }\n\n return {\n discoverColumns,\n processExport,\n streamExport,\n }\n}\n"],"names":["createExportBatchProcessor","options","batchSize","debug","computeTotalBatches","totalDocs","maxDocs","effectiveDocs","undefined","Math","min","Number","POSITIVE_INFINITY","ceil","processExport","processOptions","findArgs","format","hooks","req","startPage","transformDoc","totalBatches","docs","columnsSet","Set","columns","currentPage","fetched","hasNextPage","remaining","max","result","payload","find","limit","page","logger","length","batchNumber","originalDocs","batchData","map","doc","dataToWrite","before","data","originalData","row","push","key","Object","keys","has","add","after","fetchedCount","streamExport","discoverColumns","transformedDoc"],"mappings":"AAAA;;;CAGC,GA0FD;;;;;;;;;;;;;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;QACA5C;QACA2C;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/export/batchProcessor.ts"],"sourcesContent":["/**\n * Export-specific batch processor for processing documents in batches during export.\n * Uses the generic batch processing utilities from useBatchProcessor.\n */\nimport type { PayloadRequest, SelectType, Sort, User, Where } from 'payload'\n\nimport type { ExportAfterHook, ExportBeforeHook } from '../types.js'\n\nimport { type BatchProcessorOptions } from '../utilities/useBatchProcessor.js'\n\n/**\n * Export-specific batch processor options\n */\nexport interface ExportBatchProcessorOptions extends BatchProcessorOptions {\n debug?: boolean\n}\n\n/**\n * Find arguments for querying documents during export\n */\nexport interface ExportFindArgs {\n collection: string\n depth: number\n draft: boolean\n limit: number\n locale?: string\n overrideAccess: boolean\n page?: number\n select?: SelectType\n sort?: Sort\n user?: User\n where?: Where\n}\n\n/**\n * Options for processing an export operation\n */\nexport interface ExportProcessOptions<TDoc = unknown> {\n /**\n * The slug of the collection to export\n */\n collectionSlug: string\n /**\n * Arguments to pass to payload.find()\n */\n findArgs: ExportFindArgs\n /**\n * The export format - affects column tracking for CSV\n */\n format: 'csv' | 'json'\n /** Lifecycle hooks for this export operation */\n hooks?: {\n after?: ExportAfterHook\n before?: ExportBeforeHook\n }\n /**\n * Maximum number of documents to export\n */\n maxDocs: number\n /**\n * The Payload request object\n */\n req: PayloadRequest\n /**\n * Starting page for pagination (default: 1)\n */\n startPage?: number\n /** Total number of docs available (used to compute totalBatches for hooks) */\n totalDocs?: number\n /**\n * Transform function to apply to each document\n */\n transformDoc: (doc: TDoc) => Record<string, unknown>\n}\n\n/**\n * Result from processing an export operation\n */\nexport interface ExportResult {\n /**\n * Discovered column names (for CSV exports)\n */\n columns: string[]\n /**\n * Transformed documents ready for output\n */\n docs: Record<string, unknown>[]\n /**\n * Total number of documents fetched\n */\n fetchedCount: number\n}\n\n/**\n * Creates an export batch processor with the specified options.\n *\n * @param options - Configuration options for the batch processor\n * @returns An object containing the processExport method\n *\n * @example\n * ```ts\n * const processor = createExportBatchProcessor({ batchSize: 100, debug: true })\n *\n * const result = await processor.processExport({\n * collectionSlug: 'posts',\n * findArgs: { collection: 'posts', depth: 1, draft: false, limit: 100, overrideAccess: false },\n * format: 'csv',\n * maxDocs: 1000,\n * req,\n * transformDoc: (doc) => flattenObject({ data: doc }),\n * })\n * ```\n */\nexport function createExportBatchProcessor(options: ExportBatchProcessorOptions = {}) {\n const batchSize = options.batchSize ?? 100\n const debug = options.debug ?? false\n\n const computeTotalBatches = (totalDocs: number | undefined, maxDocs: number): number => {\n const effectiveDocs =\n totalDocs !== undefined\n ? Math.min(totalDocs, maxDocs === Number.POSITIVE_INFINITY ? totalDocs : maxDocs)\n : 0\n return effectiveDocs > 0 ? Math.ceil(effectiveDocs / batchSize) : 1\n }\n\n /**\n * Process an export operation by fetching and transforming documents in batches.\n *\n * @param processOptions - Options for the export operation\n * @returns The export result containing transformed documents and column info\n */\n const processExport = async <TDoc>(\n processOptions: ExportProcessOptions<TDoc>,\n ): Promise<ExportResult> => {\n const {\n findArgs,\n format,\n hooks,\n maxDocs,\n req,\n startPage = 1,\n totalDocs,\n transformDoc,\n } = processOptions\n\n const totalBatches = computeTotalBatches(totalDocs, maxDocs)\n\n const docs: Record<string, unknown>[] = []\n const columnsSet = new Set<string>()\n const columns: string[] = []\n\n let currentPage = startPage\n let fetched = 0\n let hasNextPage = true\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await req.payload.find({\n ...findArgs,\n limit: Math.min(batchSize, remaining),\n page: currentPage,\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Processing export batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n const batchNumber = currentPage - startPage + 1\n const originalDocs = result.docs as Record<string, unknown>[]\n const batchData = result.docs.map((doc) => transformDoc(doc as TDoc))\n\n const dataToWrite =\n hooks?.before && batchData.length > 0\n ? await hooks.before({\n batchNumber,\n data: batchData,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n : batchData\n\n for (const row of dataToWrite) {\n docs.push(row)\n\n if (format === 'csv') {\n for (const key of Object.keys(row)) {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n }\n }\n }\n\n if (hooks?.after && dataToWrite.length > 0) {\n await hooks.after({\n batchNumber,\n data: dataToWrite,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage++\n }\n\n return { columns, docs, fetchedCount: fetched }\n }\n\n /**\n * Async generator for streaming export - yields batches instead of collecting all.\n * Useful for streaming exports where you want to process batches as they're fetched.\n *\n * @param processOptions - Options for the export operation\n * @yields Batch results containing transformed documents and discovered columns\n *\n * @example\n * ```ts\n * const processor = createExportBatchProcessor({ batchSize: 100 })\n *\n * for await (const batch of processor.streamExport({ ... })) {\n * // Process each batch as it's yielded\n * console.log(`Got ${batch.docs.length} documents`)\n * }\n * ```\n */\n async function* streamExport<TDoc>(\n processOptions: ExportProcessOptions<TDoc>,\n ): AsyncGenerator<{ columns: string[]; docs: Record<string, unknown>[] }> {\n const {\n findArgs,\n format,\n hooks,\n maxDocs,\n req,\n startPage = 1,\n totalDocs,\n transformDoc,\n } = processOptions\n\n const totalBatches = computeTotalBatches(totalDocs, maxDocs)\n\n const columnsSet = new Set<string>()\n const columns: string[] = []\n\n let currentPage = startPage\n let fetched = 0\n let hasNextPage = true\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await req.payload.find({\n ...findArgs,\n limit: Math.min(batchSize, remaining),\n page: currentPage,\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Streaming export batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n const batchNumber = currentPage - startPage + 1\n const originalDocs = result.docs as Record<string, unknown>[]\n const batchData = result.docs.map((doc) => transformDoc(doc as TDoc))\n\n const dataToWrite =\n hooks?.before && batchData.length > 0\n ? await hooks.before({\n batchNumber,\n data: batchData,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n : batchData\n\n for (const row of dataToWrite) {\n if (format === 'csv') {\n for (const key of Object.keys(row)) {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n }\n }\n }\n\n yield { columns: [...columns], docs: dataToWrite }\n\n if (hooks?.after && dataToWrite.length > 0) {\n await hooks.after({\n batchNumber,\n data: dataToWrite,\n format,\n originalData: originalDocs,\n req,\n totalBatches,\n })\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage++\n }\n }\n\n /**\n * Discover all columns from the dataset by scanning through all batches.\n * Useful for CSV exports where you need to know all columns before streaming.\n *\n * @param processOptions - Options for the export operation\n * @returns Array of discovered column names\n */\n const discoverColumns = async <TDoc>(\n processOptions: ExportProcessOptions<TDoc>,\n ): Promise<string[]> => {\n const { findArgs, maxDocs, req, startPage = 1, transformDoc } = processOptions\n\n const columnsSet = new Set<string>()\n const columns: string[] = []\n\n let currentPage = startPage\n let fetched = 0\n let hasNextPage = true\n\n while (hasNextPage) {\n const remaining = Math.max(0, maxDocs - fetched)\n\n if (remaining === 0) {\n break\n }\n\n const result = await req.payload.find({\n ...findArgs,\n limit: Math.min(batchSize, remaining),\n page: currentPage,\n })\n\n if (debug) {\n req.payload.logger.debug(\n `Scanning columns from batch ${currentPage} with ${result.docs.length} documents`,\n )\n }\n\n for (const doc of result.docs) {\n const transformedDoc = transformDoc(doc as TDoc)\n\n for (const key of Object.keys(transformedDoc)) {\n if (!columnsSet.has(key)) {\n columnsSet.add(key)\n columns.push(key)\n }\n }\n }\n\n fetched += result.docs.length\n hasNextPage = result.hasNextPage && fetched < maxDocs\n currentPage++\n }\n\n if (debug) {\n req.payload.logger.debug(`Discovered ${columns.length} columns`)\n }\n\n return columns\n }\n\n return {\n discoverColumns,\n processExport,\n streamExport,\n }\n}\n"],"names":["createExportBatchProcessor","options","batchSize","debug","computeTotalBatches","totalDocs","maxDocs","effectiveDocs","undefined","Math","min","Number","POSITIVE_INFINITY","ceil","processExport","processOptions","findArgs","format","hooks","req","startPage","transformDoc","totalBatches","docs","columnsSet","Set","columns","currentPage","fetched","hasNextPage","remaining","max","result","payload","find","limit","page","logger","length","batchNumber","originalDocs","batchData","map","doc","dataToWrite","before","data","originalData","row","push","key","Object","keys","has","add","after","fetchedCount","streamExport","discoverColumns","transformedDoc"],"mappings":"AAAA;;;CAGC,GA0FD;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASA,2BAA2BC,UAAuC,CAAC,CAAC;IAClF,MAAMC,YAAYD,QAAQC,SAAS,IAAI;IACvC,MAAMC,QAAQF,QAAQE,KAAK,IAAI;IAE/B,MAAMC,sBAAsB,CAACC,WAA+BC;QAC1D,MAAMC,gBACJF,cAAcG,YACVC,KAAKC,GAAG,CAACL,WAAWC,YAAYK,OAAOC,iBAAiB,GAAGP,YAAYC,WACvE;QACN,OAAOC,gBAAgB,IAAIE,KAAKI,IAAI,CAACN,gBAAgBL,aAAa;IACpE;IAEA;;;;;GAKC,GACD,MAAMY,gBAAgB,OACpBC;QAEA,MAAM,EACJC,QAAQ,EACRC,MAAM,EACNC,KAAK,EACLZ,OAAO,EACPa,GAAG,EACHC,YAAY,CAAC,EACbf,SAAS,EACTgB,YAAY,EACb,GAAGN;QAEJ,MAAMO,eAAelB,oBAAoBC,WAAWC;QAEpD,MAAMiB,OAAkC,EAAE;QAC1C,MAAMC,aAAa,IAAIC;QACvB,MAAMC,UAAoB,EAAE;QAE5B,IAAIC,cAAcP;QAClB,IAAIQ,UAAU;QACd,IAAIC,cAAc;QAElB,MAAOA,YAAa;YAClB,MAAMC,YAAYrB,KAAKsB,GAAG,CAAC,GAAGzB,UAAUsB;YAExC,IAAIE,cAAc,GAAG;gBACnB;YACF;YAEA,MAAME,SAAS,MAAMb,IAAIc,OAAO,CAACC,IAAI,CAAC;gBACpC,GAAGlB,QAAQ;gBACXmB,OAAO1B,KA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BACfxB,QAAQuB,IAAI,CAACC;oBACf;gBACF;YACF;YAEAtB,WAAWI,OAAOT,IAAI,CAACe,MAAM;YAC7BT,cAAcG,OAAOH,WAAW,IAAID,UAAUtB;YAC9CqB;QACF;QAEA,IAAIxB,OAAO;YACTgB,IAAIc,OAAO,CAACI,MAAM,CAAClC,KAAK,CAAC,CAAC,WAAW,EAAEuB,QAAQY,MAAM,CAAC,QAAQ,CAAC;QACjE;QAEA,OAAOZ;IACT;IAEA,OAAO;QACLgC;QACA5C;QACA2C;IACF;AACF"}
@@ -26,8 +26,8 @@ export type Export = {
26
26
  name: string;
27
27
  page?: number;
28
28
  sort?: Sort;
29
- userCollection: string;
30
- userID: number | string;
29
+ userCollection?: string;
30
+ userID?: number | string;
31
31
  where?: Where;
32
32
  };
33
33
  export type CreateExportArgs = {
@@ -1 +1 @@
1
- {"version":3,"file":"createExport.d.ts","sourceRoot":"","sources":["../../src/export/createExport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAa,KAAK,EAAE,MAAM,SAAS,CAAA;AAgBrE,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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AM,GAAG,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,YAAY,GAAU,MAAM,gBAAgB,kCAgmBxD,CAAA"}
@@ -39,7 +39,7 @@ export const createExport = async (args)=>{
39
39
  });
40
40
  }
41
41
  if (!user && req.user) {
42
- user = req?.user?.id ? req.user : req?.user?.user;
42
+ user = req.user;
43
43
  }
44
44
  if (!user) {
45
45
  throw new APIError('User authentication is required to create exports.');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/export/createExport.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-objects */\nimport type { PayloadRequest, Sort, TypedUser, 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: TypedUser | undefined\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n overrideAccess: true,\n })) as TypedUser\n }\n\n if (!user && req.user) {\n user = req?.user?.id ? req.user : req?.user?.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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,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 { 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,QAAQ,EACRC,QAAQC,eAAe,EACvBC,gBAAgB,EAChBC,MAAM,EACNC,MAAM,EACNC,OAAOC,aAAa,EACpBC,QAAQ,EACRC,QAAQC,eAAe,EACvBC,IAAI,EACJC,GAAG,EACHC,IAAI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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"}
@@ -91,8 +91,8 @@ export const getExportCollection = ({ collectionSlugs, config, exportConfig, plu
91
91
  exportCollection: collectionConfig.slug,
92
92
  maxLimit,
93
93
  req,
94
- userCollection: user?.collection || user?.user?.collection,
95
- userID: user?.id || user?.user?.id
94
+ userCollection: user?.collection,
95
+ userID: user?.id
96
96
  });
97
97
  });
98
98
  afterChange.push(async ({ collection: collectionConfig, doc, operation, req })=>{
@@ -129,8 +129,8 @@ export const getExportCollection = ({ collectionSlugs, config, exportConfig, plu
129
129
  maxLimit,
130
130
  page: doc.page,
131
131
  sort: doc.sort,
132
- userCollection: user?.collection || user?.user?.collection,
133
- userID: user?.id || user?.user?.id,
132
+ userCollection: user?.collection,
133
+ userID: user?.id,
134
134
  where: doc.where
135
135
  };
136
136
  await req.payload.jobs.queue({
@@ -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 || user?.user?.collection,\n userID: user?.id || user?.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 || user?.user?.collection,\n userID: user?.id || user?.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,kBAAmD,EAAE;IAC3D,MAAMC,cAA2C,EAAE;IAEnD,MAAMC,kBAAkBJ,cAAcI,mBAAmB;IACzD,MAAMC,cAAcL,cAAcK,eAAe;IACjD,MAAMC,SAASN,cAAcM;IAE7B,MAAMC,aAA+B;QACnCC,MAAM;QACN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IM,IAAI;YACdT,gBAAgBR,MAAMvC,cAAcuC,MAAMA,MAAMvC;YAChDgD,QAAQT,MAAMU,MAAMV,MAAMA,MAAMU;YAChCQ,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 { 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,kBAAmD,EAAE;IAC3D,MAAMC,cAA2C,EAAE;IAEnD,MAAMC,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;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"}
@@ -28,8 +28,8 @@ export const handleDownload = async (req, debug = false)=>{
28
28
  });
29
29
  }
30
30
  const { user } = req;
31
- body.data.userID = user?.id || user?.user?.id;
32
- body.data.userCollection = user?.collection || user?.user?.collection;
31
+ body.data.userID = user?.id;
32
+ body.data.userCollection = user?.collection;
33
33
  const res = await createExport({
34
34
  ...body.data,
35
35
  debug,
@@ -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 || user?.user?.id\n body.data.userCollection = user?.collection || user?.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,YAAY;YACnCD,OAAO,MAAMF,IAAIG,IAAI;QACvB;QAEA,IAAI,CAACD,QAAQ,CAACA,KAAKE,IAAI,EAAE;YACvB,MAAM,IAAIR,SAAS;QACrB;QAEA,MAAM,EAAES,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,IAAItB,SACR,CAAC,eAAe,EAAEU,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;QAEjBE,KAAKE,IAAI,CAACmB,MAAM,GAAGD,MAAME,MAAMF,MAAMA,MAAME;QAC3CtB,KAAKE,IAAI,CAACqB,cAAc,GAAGH,MAAMI,cAAcJ,MAAMA,MAAMI;QAE3D,MAAMC,MAAM,MAAM7B,aAAa;YAC7B,GAAGI,KAAKE,IAAI;YACZH;YACA2B,UAAU;YACVhB;YACAZ;YACAsB,MAAMtB,IAAIsB,IAAI;QAChB;QAEA,OAAOK;IACT,EAAE,OAAOE,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
+ {"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,YAAY;YACnCD,OAAO,MAAMF,IAAIG,IAAI;QACvB;QAEA,IAAI,CAACD,QAAQ,CAACA,KAAKE,IAAI,EAAE;YACvB,MAAM,IAAIR,SAAS;QACrB;QAEA,MAAM,EAAES,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,IAAItB,SACR,CAAC,eAAe,EAAEU,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;QAEjBE,KAAKE,IAAI,CAACmB,MAAM,GAAGD,MAAME;QACzBtB,KAAKE,IAAI,CAACqB,cAAc,GAAGH,MAAMI;QAEjC,MAAMC,MAAM,MAAM7B,aAAa;YAC7B,GAAGI,KAAKE,IAAI;YACZH;YACA2B,UAAU;YACVhB;YACAZ;YACAsB,MAAMtB,IAAIsB,IAAI;QAChB;QAEA,OAAOK;IACT,EAAE,OAAOE,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,4 +1,4 @@
1
- import type { PayloadRequest, TypedUser } from 'payload';
1
+ import type { PayloadRequest, User } from 'payload';
2
2
  import type { ImportAfterHook, ImportBeforeHook, ImportResult } from '../types.js';
3
3
  import type { ImportMode } from './createImport.js';
4
4
  import { type BatchError } from '../utilities/useBatchProcessor.js';
@@ -50,7 +50,7 @@ export interface ImportProcessOptions {
50
50
  req: PayloadRequest;
51
51
  /** Total number of batches (pre-computed for hook args) */
52
52
  totalBatches?: number;
53
- user?: TypedUser;
53
+ user?: User;
54
54
  }
55
55
  export declare function createImportBatchProcessor(options?: ImportBatchProcessorOptions): {
56
56
  processImport: (processOptions: ImportProcessOptions) => Promise<ImportResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"batchProcessor.d.ts","sourceRoot":"","sources":["../../src/import/batchProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EACL,KAAK,UAAU,EAIhB,MAAM,mCAAmC,CAAA;AAE1C;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,CAAA;IAC1B,UAAU,EAAE,KAAK,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC,KAAK,EAAE,MAAM,CAAA;QACb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CAAA;IACrB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ;AA4hBD,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,2BAAgC;oCAMrC,oBAAoB,KAAG,OAAO,CAAC,YAAY,CAAC;EAgH1F"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/import/batchProcessor.ts"],"sourcesContent":["import type { PayloadRequest, TypedUser } from 'payload'\n\nimport { isolateObjectProperty } from 'payload'\n\nimport type { ImportAfterHook, ImportBeforeHook, ImportResult } from '../types.js'\nimport type { ImportMode } from './createImport.js'\n\nimport {\n type BatchError,\n categorizeError,\n createBatches,\n extractErrorMessage,\n} from '../utilities/useBatchProcessor.js'\n\n/**\n * Import-specific batch processor options\n */\nexport interface ImportBatchProcessorOptions {\n batchSize?: number\n defaultVersionStatus?: 'draft' | 'published'\n}\n\n/**\n * Import-specific error type extending the generic BatchError\n */\nexport interface ImportError extends BatchError<Record<string, unknown>> {\n documentData: Record<string, unknown>\n field?: string\n fieldLabel?: string\n rowNumber: number // 1-indexed for user clarity\n}\n\n/**\n * Result from processing a single import batch\n */\nexport interface ImportBatchResult {\n failed: Array<ImportError>\n successful: Array<{\n document: Record<string, unknown>\n index: number\n operation?: 'created' | 'updated'\n result: Record<string, unknown>\n }>\n}\n\n/**\n * Options for processing an import operation\n */\nexport interface ImportProcessOptions {\n collectionSlug: string\n docs: Record<string, unknown>[]\n /** Export format — passed through to hook args */\n format?: 'csv' | 'json'\n /** Lifecycle hooks for this import operation */\n hooks?: {\n after?: ImportAfterHook\n before?: ImportBeforeHook\n }\n importMode: ImportMode\n matchField?: string\n /** Raw parsed rows before unflattening — used as originalData in hooks */\n originalDocs?: Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches (pre-computed for hook args) */\n totalBatches?: number\n user?: TypedUser\n}\n\n/**\n * Separates multi-locale data from a document for sequential locale updates.\n *\n * When a field has locale-keyed values (e.g., { title: { en: 'Hello', es: 'Hola' } }),\n * this extracts the default locale's data for initial create/update, and stores\n * remaining locales for subsequent update calls.\n *\n * @returns\n * - flatData: Document with default locale values extracted (for initial operation)\n * - hasMultiLocale: Whether any multi-locale fields were found\n * - localeUpdates: Map of locale -> field data for follow-up updates\n */\nfunction extractMultiLocaleData(\n data: Record<string, unknown>,\n configuredLocales?: string[],\n defaultLocale?: string,\n): {\n flatData: Record<string, unknown>\n hasMultiLocale: boolean\n localeUpdates: Record<string, Record<string, unknown>>\n} {\n const flatData: Record<string, unknown> = {}\n const localeUpdates: Record<string, Record<string, unknown>> = {}\n let hasMultiLocale = false\n\n if (!configuredLocales || configuredLocales.length === 0) {\n return { flatData: { ...data }, hasMultiLocale: false, localeUpdates: {} }\n }\n\n const localeSet = new Set(configuredLocales)\n\n for (const [key, value] of Object.entries(data)) {\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n const valueObj = value as Record<string, unknown>\n const localeKeys = Object.keys(valueObj).filter((k) => localeSet.has(k))\n\n if (localeKeys.length > 0) {\n hasMultiLocale = true\n const baseLocale =\n defaultLocale && localeKeys.includes(defaultLocale) ? defaultLocale : localeKeys[0]\n if (baseLocale) {\n flatData[key] = valueObj[baseLocale]\n for (const locale of localeKeys) {\n if (locale !== baseLocale) {\n if (!localeUpdates[locale]) {\n localeUpdates[locale] = {}\n }\n localeUpdates[locale][key] = valueObj[locale]\n }\n }\n }\n } else {\n flatData[key] = value\n }\n } else {\n flatData[key] = value\n }\n }\n\n return { flatData, hasMultiLocale, localeUpdates }\n}\n\ntype ProcessImportBatchOptions = {\n batch: Record<string, unknown>[]\n batchIndex: number\n collectionSlug: string\n importMode: ImportMode\n matchField: string | undefined\n options: { batchSize: number; defaultVersionStatus: 'draft' | 'published' }\n req: PayloadRequest\n user?: TypedUser\n}\n\n/**\n * Processes a batch of documents for import based on the import mode.\n *\n * For each document in the batch:\n * - create: Creates a new document (removes any existing ID)\n * - update: Finds existing document by matchField and updates it\n * - upsert: Updates if found, creates if not found\n *\n * Handles versioned collections, multi-locale data, and MongoDB ObjectID validation.\n * Continues processing remaining documents even if individual imports fail.\n */\nasync function processImportBatch({\n batch,\n batchIndex,\n collectionSlug,\n importMode,\n matchField,\n options,\n req: reqFromArgs,\n user,\n}: ProcessImportBatchOptions): Promise<ImportBatchResult> {\n const result: ImportBatchResult = {\n failed: [],\n successful: [],\n }\n // Create a request proxy that isolates the transactionID property, then clear it.\n // This is critical because if a nested operation fails (e.g., Forbidden due to access control),\n // Payload's error handling calls killTransaction(req), which would kill the parent's transaction\n // if we shared the same transaction. By isolating and clearing transactionID, each nested\n // operation either uses no transaction or starts its own, independent of the parent.\n const req = isolateObjectProperty(reqFromArgs, 'transactionID')\n req.transactionID = undefined\n\n const collectionEntry = req.payload.collections[collectionSlug]\n\n const collectionConfig = collectionEntry?.config\n const collectionHasVersions = Boolean(collectionConfig?.versions)\n const hasCustomIdField = Boolean(collectionEntry?.customIDType)\n\n const configuredLocales = req.payload.config.localization\n ? req.payload.config.localization.localeCodes\n : undefined\n\n const defaultLocale = req.payload.config.localization\n ? req.payload.config.localization.defaultLocale\n : undefined\n\n const startingRowNumber = batchIndex * options.batchSize\n\n for (let i = 0; i < batch.length; i++) {\n const document = batch[i]\n if (!document) {\n continue\n }\n const rowNumber = startingRowNumber + i + 1\n\n try {\n let savedDocument: Record<string, unknown> | undefined\n let existingDocResult: { docs: Array<Record<string, unknown>> } | undefined\n\n if (importMode === 'create') {\n const createData = { ...document }\n if (!hasCustomIdField) {\n delete createData.id\n }\n\n let draftOption: boolean | undefined\n if (collectionHasVersions) {\n const statusValue = createData._status || options.defaultVersionStatus\n const isPublished = statusValue !== 'draft'\n draftOption = !isPublished\n createData._status = statusValue\n\n if (req.payload.config.debug) {\n req.payload.logger.info({\n _status: createData._status,\n isPublished,\n msg: 'Status handling in create',\n willSetDraft: draftOption,\n })\n }\n }\n\n if (req.payload.config.debug && 'title' in createData) {\n req.payload.logger.info({\n msg: 'Creating document',\n title: createData.title,\n titleIsNull: createData.title === null,\n titleType: typeof createData.title,\n })\n }\n\n // Check if we have multi-locale data and extract it\n const { flatData, hasMultiLocale, localeUpdates } = extractMultiLocaleData(\n createData,\n configuredLocales,\n defaultLocale,\n )\n\n if (hasMultiLocale) {\n // Create with default locale data\n const defaultLocaleReq = defaultLocale ? { ...req, locale: defaultLocale } : req\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: flatData,\n draft: draftOption,\n overrideAccess: false,\n req: defaultLocaleReq,\n user,\n })\n\n if (savedDocument && Object.keys(localeUpdates).length > 0) {\n for (const [locale, localeData] of Object.entries(localeUpdates)) {\n try {\n await req.payload.update({\n id: savedDocument.id as number | string,\n collection: collectionSlug,\n data: localeData,\n draft: collectionHasVersions ? false : undefined,\n overrideAccess: false,\n req: { ...req, locale },\n user,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `Failed to update locale ${locale} for document ${String(savedDocument.id)}`,\n })\n }\n }\n }\n } else {\n // No multi-locale data, create normally\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: createData,\n draft: draftOption,\n overrideAccess: false,\n req,\n user,\n })\n }\n } else if (importMode === 'update' || importMode === 'upsert') {\n const matchValue = document[matchField || 'id']\n if (!matchValue) {\n throw new Error(`Match field \"${matchField || 'id'}\" not found in document`)\n }\n\n // Special handling for ID field with MongoDB\n // If matching by 'id' and it's not a valid ObjectID format, handle specially\n const isMatchingById = (matchField || 'id') === 'id'\n\n // Check if it's a valid MongoDB ObjectID format (24 hex chars)\n // Note: matchValue could be string, number, or ObjectID object\n let matchValueStr: string\n if (typeof matchValue === 'object' && matchValue !== null) {\n matchValueStr = JSON.stringify(matchValue)\n } else if (typeof matchValue === 'string') {\n matchValueStr = matchValue\n } else if (typeof matchValue === 'number') {\n matchValueStr = matchValue.toString()\n } else {\n // For other types, use JSON.stringify\n matchValueStr = JSON.stringify(matchValue)\n }\n const isValidObjectIdFormat = /^[0-9a-f]{24}$/i.test(matchValueStr)\n\n try {\n existingDocResult = await req.payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1,\n overrideAccess: false,\n req,\n user,\n where: {\n [matchField || 'id']: {\n equals: matchValue,\n },\n },\n })\n } catch (error) {\n // MongoDB may throw for invalid ObjectID format - handle gracefully for upsert\n if (isMatchingById && importMode === 'upsert' && !isValidObjectIdFormat) {\n existingDocResult = { docs: [] }\n } else if (isMatchingById && importMode === 'update' && !isValidObjectIdFormat) {\n throw new Error(`Invalid ID format for update: ${matchValueStr}`)\n } else {\n throw error\n }\n }\n\n if (existingDocResult.docs.length > 0) {\n const existingDoc = existingDocResult.docs[0]\n if (!existingDoc) {\n throw new Error(`Document not found`)\n }\n\n // Debug: log what we found\n if (req.payload.config.debug) {\n req.payload.logger.info({\n existingId: existingDoc.id,\n existingStatus: existingDoc._status,\n existingTitle: existingDoc.title,\n incomingDocument: document,\n mode: importMode,\n msg: 'Found existing document for update',\n })\n }\n\n const updateData = { ...document }\n // Remove ID and internal fields from update data\n delete updateData.id\n delete updateData._id\n delete updateData.createdAt\n delete updateData.updatedAt\n\n // Check if we have multi-locale data and extract it\n const { flatData, hasMultiLocale, localeUpdates } = extractMultiLocaleData(\n updateData,\n configuredLocales,\n defaultLocale,\n )\n\n if (req.payload.config.debug) {\n req.payload.logger.info({\n existingId: existingDoc.id,\n hasMultiLocale,\n mode: importMode,\n msg: 'Updating document in upsert/update mode',\n updateData: Object.keys(hasMultiLocale ? flatData : updateData).reduce(\n (acc, key) => {\n const val = (hasMultiLocale ? flatData : updateData)[key]\n acc[key] =\n typeof val === 'string' && val.length > 50 ? val.substring(0, 50) + '...' : val\n return acc\n },\n {} as Record<string, unknown>,\n ),\n })\n }\n\n if (hasMultiLocale) {\n // Update with default locale data\n const defaultLocaleReq = defaultLocale ? { ...req, locale: defaultLocale } : req\n savedDocument = await req.payload.update({\n id: existingDoc.id as number | string,\n collection: collectionSlug,\n data: flatData,\n depth: 0,\n // Don't specify draft - this creates a new draft for versioned collections\n overrideAccess: false,\n req: defaultLocaleReq,\n user,\n })\n\n if (savedDocument && Object.keys(localeUpdates).length > 0) {\n for (const [locale, localeData] of Object.entries(localeUpdates)) {\n try {\n await req.payload.update({\n id: existingDoc.id as number | string,\n collection: collectionSlug,\n data: localeData,\n depth: 0,\n overrideAccess: false,\n req: { ...req, locale },\n user,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `Failed to update locale ${locale} for document ${String(existingDoc.id)}`,\n })\n }\n }\n }\n } else {\n // No multi-locale data, update normally\n try {\n // Extra debug: log before update\n if (req.payload.config.debug) {\n req.payload.logger.info({\n existingId: existingDoc.id,\n existingTitle: existingDoc.title,\n msg: 'About to update document',\n newData: updateData,\n })\n }\n\n // Update the document - don't specify draft to let Payload handle versions properly\n // This will create a new draft version for collections with versions enabled\n savedDocument = await req.payload.update({\n id: existingDoc.id as number | string,\n collection: collectionSlug,\n data: updateData,\n depth: 0,\n // Don't specify draft - this creates a new draft for versioned collections\n overrideAccess: false,\n req,\n user,\n })\n\n if (req.payload.config.debug && savedDocument) {\n req.payload.logger.info({\n id: savedDocument.id,\n msg: 'Update completed',\n status: savedDocument._status,\n title: savedDocument.title,\n })\n }\n } catch (updateError) {\n req.payload.logger.error({\n id: existingDoc.id,\n err: updateError,\n msg: 'Update failed',\n })\n throw updateError\n }\n }\n } else if (importMode === 'upsert') {\n // Create new in upsert mode\n if (req.payload.config.debug) {\n req.payload.logger.info({\n document,\n matchField: matchField || 'id',\n matchValue: document[matchField || 'id'],\n msg: 'No existing document found, creating new in upsert mode',\n })\n }\n\n const createData = { ...document }\n if (!hasCustomIdField) {\n delete createData.id\n }\n\n // Only handle _status for versioned collections\n let draftOption: boolean | undefined\n if (collectionHasVersions) {\n // Use defaultVersionStatus from config if _status not provided\n const statusValue = createData._status || options.defaultVersionStatus\n const isPublished = statusValue !== 'draft'\n draftOption = !isPublished\n createData._status = statusValue\n }\n\n // Check if we have multi-locale data and extract it\n const { flatData, hasMultiLocale, localeUpdates } = extractMultiLocaleData(\n createData,\n configuredLocales,\n defaultLocale,\n )\n\n if (hasMultiLocale) {\n // Create with default locale data\n const defaultLocaleReq = defaultLocale ? { ...req, locale: defaultLocale } : req\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: flatData,\n draft: draftOption,\n overrideAccess: false,\n req: defaultLocaleReq,\n user,\n })\n\n if (savedDocument && Object.keys(localeUpdates).length > 0) {\n for (const [locale, localeData] of Object.entries(localeUpdates)) {\n try {\n await req.payload.update({\n id: savedDocument.id as number | string,\n collection: collectionSlug,\n data: localeData,\n draft: collectionHasVersions ? false : undefined,\n overrideAccess: false,\n req: { ...req, locale },\n user,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `Failed to update locale ${locale} for document ${String(savedDocument.id)}`,\n })\n }\n }\n }\n } else {\n // No multi-locale data, create normally\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: createData,\n draft: draftOption,\n overrideAccess: false,\n req,\n user,\n })\n }\n } else {\n // Update mode but document not found\n let matchValueDisplay: string\n if (typeof matchValue === 'object' && matchValue !== null) {\n matchValueDisplay = JSON.stringify(matchValue)\n } else if (typeof matchValue === 'string') {\n matchValueDisplay = matchValue\n } else if (typeof matchValue === 'number') {\n matchValueDisplay = matchValue.toString()\n } else {\n // For other types, use JSON.stringify to avoid [object Object]\n matchValueDisplay = JSON.stringify(matchValue)\n }\n throw new Error(`Document with ${matchField || 'id'}=\"${matchValueDisplay}\" not found`)\n }\n } else {\n throw new Error(`Unknown import mode: ${String(importMode)}`)\n }\n\n if (savedDocument) {\n // Determine operation type for proper counting\n let operation: 'created' | 'updated' | undefined\n if (importMode === 'create') {\n operation = 'created'\n } else if (importMode === 'update') {\n operation = 'updated'\n } else if (importMode === 'upsert') {\n if (existingDocResult && existingDocResult.docs.length > 0) {\n operation = 'updated'\n } else {\n operation = 'created'\n }\n }\n\n result.successful.push({\n document,\n index: rowNumber - 1, // Store as 0-indexed\n operation,\n result: savedDocument,\n })\n }\n } catch (error) {\n const importError: ImportError = {\n type: categorizeError(error),\n documentData: document || {},\n error: extractErrorMessage(error),\n item: document || {},\n itemIndex: rowNumber - 1,\n rowNumber,\n }\n\n // Try to extract field information from validation errors\n if (error && typeof error === 'object' && 'data' in error) {\n const errorData = error as { data?: { errors?: Array<{ path?: string }> } }\n if (errorData.data?.errors && Array.isArray(errorData.data.errors)) {\n const firstError = errorData.data.errors[0]\n if (firstError?.path) {\n importError.field = firstError.path\n }\n }\n }\n\n result.failed.push(importError)\n // Always continue processing all rows\n }\n }\n\n return result\n}\n\nexport function createImportBatchProcessor(options: ImportBatchProcessorOptions = {}) {\n const processorOptions = {\n batchSize: options.batchSize ?? 100,\n defaultVersionStatus: options.defaultVersionStatus ?? 'published',\n }\n\n const processImport = async (processOptions: ImportProcessOptions): Promise<ImportResult> => {\n const {\n collectionSlug,\n docs: documents,\n format = 'csv',\n hooks,\n importMode,\n matchField,\n originalDocs: originalDocs,\n req,\n totalBatches: totalBatchesFromOptions,\n user,\n } = processOptions\n const batches = createBatches(documents, processorOptions.batchSize)\n const totalBatches = totalBatchesFromOptions ?? batches.length\n\n const result: ImportResult = {\n errors: [],\n imported: 0,\n total: documents.length,\n updated: 0,\n }\n\n for (let i = 0; i < batches.length; i++) {\n const currentBatch = batches[i]\n if (!currentBatch) {\n continue\n }\n\n const batchNumber = i + 1\n const batchStart = i * processorOptions.batchSize\n const originalBatch = originalDocs\n ? originalDocs.slice(batchStart, batchStart + currentBatch.length)\n : currentBatch\n\n const batchToProcess: Record<string, unknown>[] =\n hooks?.before && currentBatch.length > 0\n ? ((await hooks.before({\n batchNumber,\n data: currentBatch as Parameters<ImportBeforeHook>[0]['data'],\n format,\n originalData: originalBatch,\n req,\n totalBatches,\n })) as Record<string, unknown>[])\n : currentBatch\n\n const batchResult = await processImportBatch({\n batch: batchToProcess,\n batchIndex: i,\n collectionSlug,\n importMode,\n matchField,\n options: processorOptions,\n req,\n user,\n })\n\n let batchImported = 0\n let batchUpdated = 0\n for (const success of batchResult.successful) {\n if (success.operation === 'created') {\n result.imported++\n batchImported++\n } else if (success.operation === 'updated') {\n result.updated++\n batchUpdated++\n } else {\n // Fallback\n if (importMode === 'create') {\n result.imported++\n batchImported++\n } else {\n result.updated++\n batchUpdated++\n }\n }\n }\n\n for (const error of batchResult.failed) {\n result.errors.push({\n doc: error.documentData,\n error: error.error,\n index: error.rowNumber - 1, // Convert back to 0-indexed\n })\n }\n\n if (hooks?.after) {\n const batchHookResult: ImportResult = {\n errors:\n batchResult.failed.length > 0 ? result.errors.slice(-batchResult.failed.length) : [],\n imported: batchImported,\n total: batchToProcess.length,\n updated: batchUpdated,\n }\n await hooks.after({\n batchNumber,\n format,\n originalData: originalBatch,\n req,\n result: batchHookResult,\n totalBatches,\n })\n }\n }\n\n return result\n }\n\n return {\n processImport,\n }\n}\n"],"names":["isolateObjectProperty","categorizeError","createBatches","extractErrorMessage","extractMultiLocaleData","data","configuredLocales","defaultLocale","flatData","localeUpdates","hasMultiLocale","length","localeSet","Set","key","value","Object","entries","Array","isArray","valueObj","localeKeys","keys","filter","k","has","baseLocale","includes","locale","processImportBatch","batch","batchIndex","collectionSlug","importMode","matchField","options","req","reqFromArgs","user","result","failed","successful","transactionID","undefined","collectionEntry","payload","collections","collectionConfig","config","collectionHasVersions","Boolean","versions","hasCustomIdField","customIDType","localization","localeCodes","startingRowNumber","batchSize","i","document","rowNumber","savedDocument","existingDocResult","createData","id","draftOption","statusValue","_status","defaultVersionStatus","isPublished","debug","logger","info","msg","willSetDraft","title","titleIsNull","titleType","defaultLocaleReq","create","collection","draft","overrideAccess","localeData","update","error","err","String","matchValue","Error","isMatchingById","matchValueStr","JSON","stringify","toString","isValidObjectIdFormat","test","find","depth","limit","where","equals","docs","existingDoc","existingId","existingStatus","existingTitle","incomingDocument","mode","updateData","_id","createdAt","updatedAt","reduce","acc","val","substring","newData","status","updateError","matchValueDisplay","operation","push","index","importError","type","documentData","item","itemIndex","errorData","errors","firstError","path","field","createImportBatchProcessor","processorOptions","processImport","processOptions","documents","format","hooks","originalDocs","totalBatches","totalBatchesFromOptions","batches","imported","total","updated","currentBatch","batchNumber","batchStart","originalBatch","slice","batchToProcess","before","originalData","batchResult","batchImported","batchUpdated","success","doc","after","batchHookResult"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,UAAS;AAK/C,SAEEC,eAAe,EACfC,aAAa,EACbC,mBAAmB,QACd,oCAAmC;AAwD1C;;;;;;;;;;;CAWC,GACD,SAASC,uBACPC,IAA6B,EAC7BC,iBAA4B,EAC5BC,aAAsB;IAMtB,MAAMC,WAAoC,CAAC;IAC3C,MAAMC,gBAAyD,CAAC;IAChE,IAAIC,iBAAiB;IAErB,IAAI,CAACJ,qBAAqBA,kBAAkBK,MAAM,KAAK,GAAG;QACxD,OAAO;YAAEH,UAAU;gBAAE,GAAGH,IAAI;YAAC;YAAGK,gBAAgB;YAAOD,eAAe,CAAC;QAAE;IAC3E;IAEA,MAAMG,YAAY,IAAIC,IAAIP;IAE1B,KAAK,MAAM,CAACQ,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACZ,MAAO;QAC/C,IAAIU,SAAS,OAAOA,UAAU,YAAY,CAACG,MAAMC,OAAO,CAACJ,QAAQ;YAC/D,MAAMK,WAAWL;YACjB,MAAMM,aAAaL,OAAOM,IAAI,CAACF,UAAUG,MAAM,CAAC,CAACC,IAAMZ,UAAUa,GAAG,CAACD;YAErE,IAAIH,WAAWV,MAAM,GAAG,GAAG;gBACzBD,iBAAiB;gBACjB,MAAMgB,aACJnB,iBAAiBc,WAAWM,QAAQ,CAACpB,iBAAiBA,gBAAgBc,UAAU,CAAC,EAAE;gBACrF,IAAIK,YAAY;oBACdlB,QAAQ,CAACM,IAAI,GAAGM,QAAQ,CAACM,WAAW;oBACpC,KAAK,MAAME,UAAUP,WAAY;wBAC/B,IAAIO,WAAWF,YAAY;4BACzB,IAAI,CAACjB,aAAa,CAACmB,OAAO,EAAE;gCAC1BnB,aAAa,CAACmB,OAAO,GAAG,CAAC;4BAC3B;4BACAnB,aAAa,CAACmB,OAAO,CAACd,IAAI,GAAGM,QA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;gBACF,OAAO;oBACL,WAAW;oBACX,IAAI7H,eAAe,UAAU;wBAC3BM,OAAO0G,QAAQ;wBACfY;oBACF,OAAO;wBACLtH,OAAO4G,OAAO;wBACdW;oBACF;gBACF;YACF;YAEA,KAAK,MAAMzE,SAASuE,YAAYpH,MAAM,CAAE;gBACtCD,OAAO2F,MAAM,CAACR,IAAI,CAAC;oBACjBsC,KAAK3E,MAAMyC,YAAY;oBACvBzC,OAAOA,MAAMA,KAAK;oBAClBsC,OAAOtC,MAAMzB,SAAS,GAAG;gBAC3B;YACF;YAEA,IAAIgF,OAAOqB,OAAO;gBAChB,MAAMC,kBAAgC;oBACpChC,QACE0B,YAAYpH,MAAM,CAAC7B,MAAM,GAAG,IAAI4B,OAAO2F,MAAM,CAACsB,KAAK,CAAC,CAACI,YAAYpH,MAAM,CAAC7B,MAAM,IAAI,EAAE;oBACtFsI,UAAUY;oBACVX,OAAOO,eAAe9I,MAAM;oBAC5BwI,SAASW;gBACX;gBACA,MAAMlB,MAAMqB,KAAK,CAAC;oBAChBZ;oBACAV;oBACAgB,cAAcJ;oBACdnH;oBACAG,QAAQ2H;oBACRpB;gBACF;YACF;QACF;QAEA,OAAOvG;IACT;IAEA,OAAO;QACLiG;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/import/batchProcessor.ts"],"sourcesContent":["import type { PayloadRequest, User } from 'payload'\n\nimport { isolateObjectProperty } from 'payload'\n\nimport type { ImportAfterHook, ImportBeforeHook, ImportResult } from '../types.js'\nimport type { ImportMode } from './createImport.js'\n\nimport {\n type BatchError,\n categorizeError,\n createBatches,\n extractErrorMessage,\n} from '../utilities/useBatchProcessor.js'\n\n/**\n * Import-specific batch processor options\n */\nexport interface ImportBatchProcessorOptions {\n batchSize?: number\n defaultVersionStatus?: 'draft' | 'published'\n}\n\n/**\n * Import-specific error type extending the generic BatchError\n */\nexport interface ImportError extends BatchError<Record<string, unknown>> {\n documentData: Record<string, unknown>\n field?: string\n fieldLabel?: string\n rowNumber: number // 1-indexed for user clarity\n}\n\n/**\n * Result from processing a single import batch\n */\nexport interface ImportBatchResult {\n failed: Array<ImportError>\n successful: Array<{\n document: Record<string, unknown>\n index: number\n operation?: 'created' | 'updated'\n result: Record<string, unknown>\n }>\n}\n\n/**\n * Options for processing an import operation\n */\nexport interface ImportProcessOptions {\n collectionSlug: string\n docs: Record<string, unknown>[]\n /** Export format — passed through to hook args */\n format?: 'csv' | 'json'\n /** Lifecycle hooks for this import operation */\n hooks?: {\n after?: ImportAfterHook\n before?: ImportBeforeHook\n }\n importMode: ImportMode\n matchField?: string\n /** Raw parsed rows before unflattening — used as originalData in hooks */\n originalDocs?: Record<string, unknown>[]\n req: PayloadRequest\n /** Total number of batches (pre-computed for hook args) */\n totalBatches?: number\n user?: User\n}\n\n/**\n * Separates multi-locale data from a document for sequential locale updates.\n *\n * When a field has locale-keyed values (e.g., { title: { en: 'Hello', es: 'Hola' } }),\n * this extracts the default locale's data for initial create/update, and stores\n * remaining locales for subsequent update calls.\n *\n * @returns\n * - flatData: Document with default locale values extracted (for initial operation)\n * - hasMultiLocale: Whether any multi-locale fields were found\n * - localeUpdates: Map of locale -> field data for follow-up updates\n */\nfunction extractMultiLocaleData(\n data: Record<string, unknown>,\n configuredLocales?: string[],\n defaultLocale?: string,\n): {\n flatData: Record<string, unknown>\n hasMultiLocale: boolean\n localeUpdates: Record<string, Record<string, unknown>>\n} {\n const flatData: Record<string, unknown> = {}\n const localeUpdates: Record<string, Record<string, unknown>> = {}\n let hasMultiLocale = false\n\n if (!configuredLocales || configuredLocales.length === 0) {\n return { flatData: { ...data }, hasMultiLocale: false, localeUpdates: {} }\n }\n\n const localeSet = new Set(configuredLocales)\n\n for (const [key, value] of Object.entries(data)) {\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n const valueObj = value as Record<string, unknown>\n const localeKeys = Object.keys(valueObj).filter((k) => localeSet.has(k))\n\n if (localeKeys.length > 0) {\n hasMultiLocale = true\n const baseLocale =\n defaultLocale && localeKeys.includes(defaultLocale) ? defaultLocale : localeKeys[0]\n if (baseLocale) {\n flatData[key] = valueObj[baseLocale]\n for (const locale of localeKeys) {\n if (locale !== baseLocale) {\n if (!localeUpdates[locale]) {\n localeUpdates[locale] = {}\n }\n localeUpdates[locale][key] = valueObj[locale]\n }\n }\n }\n } else {\n flatData[key] = value\n }\n } else {\n flatData[key] = value\n }\n }\n\n return { flatData, hasMultiLocale, localeUpdates }\n}\n\ntype ProcessImportBatchOptions = {\n batch: Record<string, unknown>[]\n batchIndex: number\n collectionSlug: string\n importMode: ImportMode\n matchField: string | undefined\n options: { batchSize: number; defaultVersionStatus: 'draft' | 'published' }\n req: PayloadRequest\n user?: User\n}\n\n/**\n * Processes a batch of documents for import based on the import mode.\n *\n * For each document in the batch:\n * - create: Creates a new document (removes any existing ID)\n * - update: Finds existing document by matchField and updates it\n * - upsert: Updates if found, creates if not found\n *\n * Handles versioned collections, multi-locale data, and MongoDB ObjectID validation.\n * Continues processing remaining documents even if individual imports fail.\n */\nasync function processImportBatch({\n batch,\n batchIndex,\n collectionSlug,\n importMode,\n matchField,\n options,\n req: reqFromArgs,\n user,\n}: ProcessImportBatchOptions): Promise<ImportBatchResult> {\n const result: ImportBatchResult = {\n failed: [],\n successful: [],\n }\n // Create a request proxy that isolates the transactionID property, then clear it.\n // This is critical because if a nested operation fails (e.g., Forbidden due to access control),\n // Payload's error handling calls killTransaction(req), which would kill the parent's transaction\n // if we shared the same transaction. By isolating and clearing transactionID, each nested\n // operation either uses no transaction or starts its own, independent of the parent.\n const req = isolateObjectProperty(reqFromArgs, 'transactionID')\n req.transactionID = undefined\n\n const collectionEntry = req.payload.collections[collectionSlug]\n\n const collectionConfig = collectionEntry?.config\n const collectionHasVersions = Boolean(collectionConfig?.versions)\n const hasCustomIdField = Boolean(collectionEntry?.customIDType)\n\n const configuredLocales = req.payload.config.localization\n ? req.payload.config.localization.localeCodes\n : undefined\n\n const defaultLocale = req.payload.config.localization\n ? req.payload.config.localization.defaultLocale\n : undefined\n\n const startingRowNumber = batchIndex * options.batchSize\n\n for (let i = 0; i < batch.length; i++) {\n const document = batch[i]\n if (!document) {\n continue\n }\n const rowNumber = startingRowNumber + i + 1\n\n try {\n let savedDocument: Record<string, unknown> | undefined\n let existingDocResult: { docs: Array<Record<string, unknown>> } | undefined\n\n if (importMode === 'create') {\n const createData = { ...document }\n if (!hasCustomIdField) {\n delete createData.id\n }\n\n let draftOption: boolean | undefined\n if (collectionHasVersions) {\n const statusValue = createData._status || options.defaultVersionStatus\n const isPublished = statusValue !== 'draft'\n draftOption = !isPublished\n createData._status = statusValue\n\n if (req.payload.config.debug) {\n req.payload.logger.info({\n _status: createData._status,\n isPublished,\n msg: 'Status handling in create',\n willSetDraft: draftOption,\n })\n }\n }\n\n if (req.payload.config.debug && 'title' in createData) {\n req.payload.logger.info({\n msg: 'Creating document',\n title: createData.title,\n titleIsNull: createData.title === null,\n titleType: typeof createData.title,\n })\n }\n\n // Check if we have multi-locale data and extract it\n const { flatData, hasMultiLocale, localeUpdates } = extractMultiLocaleData(\n createData,\n configuredLocales,\n defaultLocale,\n )\n\n if (hasMultiLocale) {\n // Create with default locale data\n const defaultLocaleReq = defaultLocale ? { ...req, locale: defaultLocale } : req\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: flatData,\n draft: draftOption,\n overrideAccess: false,\n req: defaultLocaleReq,\n user,\n })\n\n if (savedDocument && Object.keys(localeUpdates).length > 0) {\n for (const [locale, localeData] of Object.entries(localeUpdates)) {\n try {\n await req.payload.update({\n id: savedDocument.id as number | string,\n collection: collectionSlug,\n data: localeData,\n draft: collectionHasVersions ? false : undefined,\n overrideAccess: false,\n req: { ...req, locale },\n user,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `Failed to update locale ${locale} for document ${String(savedDocument.id)}`,\n })\n }\n }\n }\n } else {\n // No multi-locale data, create normally\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: createData,\n draft: draftOption,\n overrideAccess: false,\n req,\n user,\n })\n }\n } else if (importMode === 'update' || importMode === 'upsert') {\n const matchValue = document[matchField || 'id']\n if (!matchValue) {\n throw new Error(`Match field \"${matchField || 'id'}\" not found in document`)\n }\n\n // Special handling for ID field with MongoDB\n // If matching by 'id' and it's not a valid ObjectID format, handle specially\n const isMatchingById = (matchField || 'id') === 'id'\n\n // Check if it's a valid MongoDB ObjectID format (24 hex chars)\n // Note: matchValue could be string, number, or ObjectID object\n let matchValueStr: string\n if (typeof matchValue === 'object' && matchValue !== null) {\n matchValueStr = JSON.stringify(matchValue)\n } else if (typeof matchValue === 'string') {\n matchValueStr = matchValue\n } else if (typeof matchValue === 'number') {\n matchValueStr = matchValue.toString()\n } else {\n // For other types, use JSON.stringify\n matchValueStr = JSON.stringify(matchValue)\n }\n const isValidObjectIdFormat = /^[0-9a-f]{24}$/i.test(matchValueStr)\n\n try {\n existingDocResult = await req.payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: 1,\n overrideAccess: false,\n req,\n user,\n where: {\n [matchField || 'id']: {\n equals: matchValue,\n },\n },\n })\n } catch (error) {\n // MongoDB may throw for invalid ObjectID format - handle gracefully for upsert\n if (isMatchingById && importMode === 'upsert' && !isValidObjectIdFormat) {\n existingDocResult = { docs: [] }\n } else if (isMatchingById && importMode === 'update' && !isValidObjectIdFormat) {\n throw new Error(`Invalid ID format for update: ${matchValueStr}`)\n } else {\n throw error\n }\n }\n\n if (existingDocResult.docs.length > 0) {\n const existingDoc = existingDocResult.docs[0]\n if (!existingDoc) {\n throw new Error(`Document not found`)\n }\n\n // Debug: log what we found\n if (req.payload.config.debug) {\n req.payload.logger.info({\n existingId: existingDoc.id,\n existingStatus: existingDoc._status,\n existingTitle: existingDoc.title,\n incomingDocument: document,\n mode: importMode,\n msg: 'Found existing document for update',\n })\n }\n\n const updateData = { ...document }\n // Remove ID and internal fields from update data\n delete updateData.id\n delete updateData._id\n delete updateData.createdAt\n delete updateData.updatedAt\n\n // Check if we have multi-locale data and extract it\n const { flatData, hasMultiLocale, localeUpdates } = extractMultiLocaleData(\n updateData,\n configuredLocales,\n defaultLocale,\n )\n\n if (req.payload.config.debug) {\n req.payload.logger.info({\n existingId: existingDoc.id,\n hasMultiLocale,\n mode: importMode,\n msg: 'Updating document in upsert/update mode',\n updateData: Object.keys(hasMultiLocale ? flatData : updateData).reduce(\n (acc, key) => {\n const val = (hasMultiLocale ? flatData : updateData)[key]\n acc[key] =\n typeof val === 'string' && val.length > 50 ? val.substring(0, 50) + '...' : val\n return acc\n },\n {} as Record<string, unknown>,\n ),\n })\n }\n\n if (hasMultiLocale) {\n // Update with default locale data\n const defaultLocaleReq = defaultLocale ? { ...req, locale: defaultLocale } : req\n savedDocument = await req.payload.update({\n id: existingDoc.id as number | string,\n collection: collectionSlug,\n data: flatData,\n depth: 0,\n // Don't specify draft - this creates a new draft for versioned collections\n overrideAccess: false,\n req: defaultLocaleReq,\n user,\n })\n\n if (savedDocument && Object.keys(localeUpdates).length > 0) {\n for (const [locale, localeData] of Object.entries(localeUpdates)) {\n try {\n await req.payload.update({\n id: existingDoc.id as number | string,\n collection: collectionSlug,\n data: localeData,\n depth: 0,\n overrideAccess: false,\n req: { ...req, locale },\n user,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `Failed to update locale ${locale} for document ${String(existingDoc.id)}`,\n })\n }\n }\n }\n } else {\n // No multi-locale data, update normally\n try {\n // Extra debug: log before update\n if (req.payload.config.debug) {\n req.payload.logger.info({\n existingId: existingDoc.id,\n existingTitle: existingDoc.title,\n msg: 'About to update document',\n newData: updateData,\n })\n }\n\n // Update the document - don't specify draft to let Payload handle versions properly\n // This will create a new draft version for collections with versions enabled\n savedDocument = await req.payload.update({\n id: existingDoc.id as number | string,\n collection: collectionSlug,\n data: updateData,\n depth: 0,\n // Don't specify draft - this creates a new draft for versioned collections\n overrideAccess: false,\n req,\n user,\n })\n\n if (req.payload.config.debug && savedDocument) {\n req.payload.logger.info({\n id: savedDocument.id,\n msg: 'Update completed',\n status: savedDocument._status,\n title: savedDocument.title,\n })\n }\n } catch (updateError) {\n req.payload.logger.error({\n id: existingDoc.id,\n err: updateError,\n msg: 'Update failed',\n })\n throw updateError\n }\n }\n } else if (importMode === 'upsert') {\n // Create new in upsert mode\n if (req.payload.config.debug) {\n req.payload.logger.info({\n document,\n matchField: matchField || 'id',\n matchValue: document[matchField || 'id'],\n msg: 'No existing document found, creating new in upsert mode',\n })\n }\n\n const createData = { ...document }\n if (!hasCustomIdField) {\n delete createData.id\n }\n\n // Only handle _status for versioned collections\n let draftOption: boolean | undefined\n if (collectionHasVersions) {\n // Use defaultVersionStatus from config if _status not provided\n const statusValue = createData._status || options.defaultVersionStatus\n const isPublished = statusValue !== 'draft'\n draftOption = !isPublished\n createData._status = statusValue\n }\n\n // Check if we have multi-locale data and extract it\n const { flatData, hasMultiLocale, localeUpdates } = extractMultiLocaleData(\n createData,\n configuredLocales,\n defaultLocale,\n )\n\n if (hasMultiLocale) {\n // Create with default locale data\n const defaultLocaleReq = defaultLocale ? { ...req, locale: defaultLocale } : req\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: flatData,\n draft: draftOption,\n overrideAccess: false,\n req: defaultLocaleReq,\n user,\n })\n\n if (savedDocument && Object.keys(localeUpdates).length > 0) {\n for (const [locale, localeData] of Object.entries(localeUpdates)) {\n try {\n await req.payload.update({\n id: savedDocument.id as number | string,\n collection: collectionSlug,\n data: localeData,\n draft: collectionHasVersions ? false : undefined,\n overrideAccess: false,\n req: { ...req, locale },\n user,\n })\n } catch (error) {\n req.payload.logger.error({\n err: error,\n msg: `Failed to update locale ${locale} for document ${String(savedDocument.id)}`,\n })\n }\n }\n }\n } else {\n // No multi-locale data, create normally\n savedDocument = await req.payload.create({\n collection: collectionSlug,\n data: createData,\n draft: draftOption,\n overrideAccess: false,\n req,\n user,\n })\n }\n } else {\n // Update mode but document not found\n let matchValueDisplay: string\n if (typeof matchValue === 'object' && matchValue !== null) {\n matchValueDisplay = JSON.stringify(matchValue)\n } else if (typeof matchValue === 'string') {\n matchValueDisplay = matchValue\n } else if (typeof matchValue === 'number') {\n matchValueDisplay = matchValue.toString()\n } else {\n // For other types, use JSON.stringify to avoid [object Object]\n matchValueDisplay = JSON.stringify(matchValue)\n }\n throw new Error(`Document with ${matchField || 'id'}=\"${matchValueDisplay}\" not found`)\n }\n } else {\n throw new Error(`Unknown import mode: ${String(importMode)}`)\n }\n\n if (savedDocument) {\n // Determine operation type for proper counting\n let operation: 'created' | 'updated' | undefined\n if (importMode === 'create') {\n operation = 'created'\n } else if (importMode === 'update') {\n operation = 'updated'\n } else if (importMode === 'upsert') {\n if (existingDocResult && existingDocResult.docs.length > 0) {\n operation = 'updated'\n } else {\n operation = 'created'\n }\n }\n\n result.successful.push({\n document,\n index: rowNumber - 1, // Store as 0-indexed\n operation,\n result: savedDocument,\n })\n }\n } catch (error) {\n const importError: ImportError = {\n type: categorizeError(error),\n documentData: document || {},\n error: extractErrorMessage(error),\n item: document || {},\n itemIndex: rowNumber - 1,\n rowNumber,\n }\n\n // Try to extract field information from validation errors\n if (error && typeof error === 'object' && 'data' in error) {\n const errorData = error as { data?: { errors?: Array<{ path?: string }> } }\n if (errorData.data?.errors && Array.isArray(errorData.data.errors)) {\n const firstError = errorData.data.errors[0]\n if (firstError?.path) {\n importError.field = firstError.path\n }\n }\n }\n\n result.failed.push(importError)\n // Always continue processing all rows\n }\n }\n\n return result\n}\n\nexport function createImportBatchProcessor(options: ImportBatchProcessorOptions = {}) {\n const processorOptions = {\n batchSize: options.batchSize ?? 100,\n defaultVersionStatus: options.defaultVersionStatus ?? 'published',\n }\n\n const processImport = async (processOptions: ImportProcessOptions): Promise<ImportResult> => {\n const {\n collectionSlug,\n docs: documents,\n format = 'csv',\n hooks,\n importMode,\n matchField,\n originalDocs: originalDocs,\n req,\n totalBatches: totalBatchesFromOptions,\n user,\n } = processOptions\n const batches = createBatches(documents, processorOptions.batchSize)\n const totalBatches = totalBatchesFromOptions ?? batches.length\n\n const result: ImportResult = {\n errors: [],\n imported: 0,\n total: documents.length,\n updated: 0,\n }\n\n for (let i = 0; i < batches.length; i++) {\n const currentBatch = batches[i]\n if (!currentBatch) {\n continue\n }\n\n const batchNumber = i + 1\n const batchStart = i * processorOptions.batchSize\n const originalBatch = originalDocs\n ? originalDocs.slice(batchStart, batchStart + currentBatch.length)\n : currentBatch\n\n const batchToProcess: Record<string, unknown>[] =\n hooks?.before && currentBatch.length > 0\n ? ((await hooks.before({\n batchNumber,\n data: currentBatch as Parameters<ImportBeforeHook>[0]['data'],\n format,\n originalData: originalBatch,\n req,\n totalBatches,\n })) as Record<string, unknown>[])\n : currentBatch\n\n const batchResult = await processImportBatch({\n batch: batchToProcess,\n batchIndex: i,\n collectionSlug,\n importMode,\n matchField,\n options: processorOptions,\n req,\n user,\n })\n\n let batchImported = 0\n let batchUpdated = 0\n for (const success of batchResult.successful) {\n if (success.operation === 'created') {\n result.imported++\n batchImported++\n } else if (success.operation === 'updated') {\n result.updated++\n batchUpdated++\n } else {\n // Fallback\n if (importMode === 'create') {\n result.imported++\n batchImported++\n } else {\n result.updated++\n batchUpdated++\n }\n }\n }\n\n for (const error of batchResult.failed) {\n result.errors.push({\n doc: error.documentData,\n error: error.error,\n index: error.rowNumber - 1, // Convert back to 0-indexed\n })\n }\n\n if (hooks?.after) {\n const batchHookResult: ImportResult = {\n errors:\n batchResult.failed.length > 0 ? result.errors.slice(-batchResult.failed.length) : [],\n imported: batchImported,\n total: batchToProcess.length,\n updated: batchUpdated,\n }\n await hooks.after({\n batchNumber,\n format,\n originalData: originalBatch,\n req,\n result: batchHookResult,\n totalBatches,\n })\n }\n }\n\n return result\n }\n\n return {\n processImport,\n }\n}\n"],"names":["isolateObjectProperty","categorizeError","createBatches","extractErrorMessage","extractMultiLocaleData","data","configuredLocales","defaultLocale","flatData","localeUpdates","hasMultiLocale","length","localeSet","Set","key","value","Object","entries","Array","isArray","valueObj","localeKeys","keys","filter","k","has","baseLocale","includes","locale","processImportBatch","batch","batchIndex","collectionSlug","importMode","matchField","options","req","reqFromArgs","user","result","failed","successful","transactionID","undefined","collectionEntry","payload","collections","collectionConfig","config","collectionHasVersions","Boolean","versions","hasCustomIdField","customIDType","localization","localeCodes","startingRowNumber","batchSize","i","document","rowNumber","savedDocument","existingDocResult","createData","id","draftOption","statusValue","_status","defaultVersionStatus","isPublished","debug","logger","info","msg","willSetDraft","title","titleIsNull","titleType","defaultLocaleReq","create","collection","draft","overrideAccess","localeData","update","error","err","String","matchValue","Error","isMatchingById","matchValueStr","JSON","stringify","toString","isValidObjectIdFormat","test","find","depth","limit","where","equals","docs","existingDoc","existingId","existingStatus","existingTitle","incomingDocument","mode","updateData","_id","createdAt","updatedAt","reduce","acc","val","substring","newData","status","updateError","matchValueDisplay","operation","push","index","importError","type","documentData","item","itemIndex","errorData","errors","firstError","path","field","createImportBatchProcessor","processorOptions","processImport","processOptions","documents","format","hooks","originalDocs","totalBatches","totalBatchesFromOptions","batches","imported","total","updated","currentBatch","batchNumber","batchStart","originalBatch","slice","batchToProcess","before","originalData","batchResult","batchImported","batchUpdated","success","doc","after","batchHookResult"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,UAAS;AAK/C,SAEEC,eAAe,EACfC,aAAa,EACbC,mBAAmB,QACd,oCAAmC;AAwD1C;;;;;;;;;;;CAWC,GACD,SAASC,uBACPC,IAA6B,EAC7BC,iBAA4B,EAC5BC,aAAsB;IAMtB,MAAMC,WAAoC,CAAC;IAC3C,MAAMC,gBAAyD,CAAC;IAChE,IAAIC,iBAAiB;IAErB,IAAI,CAACJ,qBAAqBA,kBAAkBK,MAAM,KAAK,GAAG;QACxD,OAAO;YAAEH,UAAU;gBAAE,GAAGH,IAAI;YAAC;YAAGK,gBAAgB;YAAOD,eAAe,CAAC;QAAE;IAC3E;IAEA,MAAMG,YAAY,IAAIC,IAAIP;IAE1B,KAAK,MAAM,CAACQ,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACZ,MAAO;QAC/C,IAAIU,SAAS,OAAOA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Y,CAuLzC,CAAA"}
1
+ {"version":3,"file":"createImport.d.ts","sourceRoot":"","sources":["../../src/import/createImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAQ,MAAM,SAAS,CAAA;AAInD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAU/C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAEvD,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,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IACD,MAAM,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;IAC5C,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,MAAM,CAAA;AAEV,eAAO,MAAM,YAAY,GAAU,0IAahC,gBAAgB,KAAG,OAAO,CAAC,YAAY,CAuLzC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/import/createImport.ts"],"sourcesContent":["import type { PayloadRequest, TypedUser } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { ImportResult } from '../types.js'\n\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { getImportFieldFunctions } from '../utilities/getImportFieldFunctions.js'\nimport { parseCSV } from '../utilities/parseCSV.js'\nimport { parseJSON } from '../utilities/parseJSON.js'\nimport { removeDisabledFields } from '../utilities/removeDisabledFields.js'\nimport { unflattenObject } from '../utilities/unflattenObject.js'\nimport { createImportBatchProcessor } from './batchProcessor.js'\n\nexport type ImportMode = 'create' | 'update' | 'upsert'\n\nexport type Import = {\n /**\n * Number of documents to process in each batch during import\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enabled debug logging\n */\n debug?: boolean\n file?: {\n data: Buffer\n mimetype: string\n name: string\n }\n format: 'csv' | 'json'\n id?: number | string\n /**\n * Import mode: create, update or upset\n */\n importMode: ImportMode\n matchField?: string\n /**\n * Maximum number of documents that can be imported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n userCollection?: string\n userID?: number | string\n}\n\nexport type CreateImportArgs = {\n defaultVersionStatus?: 'draft' | 'published'\n req: PayloadRequest\n} & Import\n\nexport const createImport = async ({\n batchSize = 100,\n collectionSlug,\n debug = false,\n defaultVersionStatus = 'published',\n file,\n format,\n importMode = 'create',\n matchField = 'id',\n maxLimit,\n req,\n userCollection,\n userID,\n}: CreateImportArgs): Promise<ImportResult> => {\n let user: TypedUser | undefined\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n req,\n })) as TypedUser\n }\n\n if (!user) {\n throw new APIError('User is required for import operations', 401, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n collectionSlug,\n format,\n importMode,\n matchField,\n msg: 'Starting import process with args:',\n transactionID: req.transactionID, // Log transaction ID to verify we're in same transaction\n })\n }\n\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n\n if (!file || !file?.data) {\n throw new APIError('No file data provided for import', 400, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n fileName: file.name,\n fileSize: file.data.length,\n mimeType: file.mimetype,\n msg: 'File info',\n })\n }\n\n const collectionConfig = req.payload.config.collections.find(\n ({ slug }) => slug === collectionSlug,\n )\n\n if (!collectionConfig) {\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n throw new APIError(`Collection with slug ${collectionSlug} not found`, 400, null, true)\n }\n\n // Get disabled fields configuration\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const importHooks = collectionConfig.custom?.['plugin-import-export']?.importHooks\n\n // Get beforeImport functions for field transformations\n const importFieldHooks = getImportFieldFunctions({\n fields: collectionConfig.flattenedFields || [],\n })\n\n // Parse the file data\n let originalDocs: Record<string, unknown>[] | undefined\n let documents: Record<string, unknown>[]\n if (format === 'csv') {\n const rawData = await parseCSV({\n data: file.data,\n req,\n })\n\n originalDocs = rawData\n documents = rawData\n\n // Unflatten CSV data\n documents = documents\n .map((doc) => {\n const unflattened = unflattenObject({\n data: doc,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n importFieldHooks,\n req,\n })\n return unflattened ?? {}\n })\n .filter((doc) => doc && Object.keys(doc).length > 0)\n\n if (debug) {\n req.payload.logger.debug({\n documentCount: documents.length,\n msg: 'After unflattening CSV',\n rawDataCount: rawData.length,\n })\n }\n } else {\n const parsedDocs = parseJSON({ data: file.data, req })\n originalDocs = parsedDocs\n // Apply field-level import hooks for JSON format\n documents = parsedDocs.map((doc) =>\n applyFieldHooks({\n type: 'beforeImport',\n data: doc,\n fieldHooks: importFieldHooks,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n operation: 'import',\n req,\n }),\n )\n }\n\n if (debug) {\n req.payload.logger.debug({\n msg: `Parsed ${documents.length} documents from ${format} file`,\n })\n if (documents.length > 0) {\n req.payload.logger.debug({\n doc: documents[0],\n msg: 'First document sample:',\n })\n }\n }\n\n // Enforce maxLimit before processing to save memory/time\n if (typeof maxLimit === 'number' && maxLimit > 0 && documents.length > maxLimit) {\n throw new APIError(\n `Import file contains ${documents.length} documents but limit is ${maxLimit}`,\n 400,\n null,\n true,\n )\n }\n\n // Remove disabled fields from all documents\n if (disabledFields.length > 0) {\n documents = documents.map((doc) => removeDisabledFields(doc, disabledFields))\n }\n\n if (debug) {\n req.payload.logger.debug({\n batchSize,\n documentCount: documents.length,\n msg: 'Processing import in batches',\n })\n }\n\n // Create batch processor\n const processor = createImportBatchProcessor({\n batchSize,\n defaultVersionStatus,\n })\n\n const totalBatches = documents.length > 0 ? Math.ceil(documents.length / batchSize) : 1\n\n // Process import with batch processor\n const result = await processor.processImport({\n collectionSlug,\n docs: documents,\n format,\n hooks: importHooks,\n importMode,\n matchField,\n originalDocs,\n req,\n totalBatches,\n user,\n })\n\n if (debug) {\n req.payload.logger.info({\n errors: result.errors.length,\n imported: result.imported,\n msg: 'Import completed',\n total: result.total,\n updated: result.updated,\n })\n }\n\n return result\n}\n"],"names":["APIError","applyFieldHooks","getImportFieldFunctions","parseCSV","parseJSON","removeDisabledFields","unflattenObject","createImportBatchProcessor","createImport","batchSize","collectionSlug","debug","defaultVersionStatus","file","format","importMode","matchField","maxLimit","req","userCollection","userID","user","payload","findByID","id","collection","logger","msg","transactionID","data","fileName","name","fileSize","length","mimeType","mimetype","collectionConfig","config","collections","find","slug","disabledFields","admin","custom","importHooks","importFieldHooks","fields","flattenedFields","originalDocs","documents","rawData","map","doc","unflattened","filter","Object","keys","documentCount","rawDataCount","parsedDocs","type","fieldHooks","operation","processor","totalBatches","Math","ceil","result","processImport","docs","hooks","info","errors","imported","total","updated"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,eAAe,QAA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BC,QAAQL,OAAOK,MAAM,CAACvC,MAAM;YAC5BwC,UAAUN,OAAOM,QAAQ;YACzB9C,KAAK;YACL+C,OAAOP,OAAOO,KAAK;YACnBC,SAASR,OAAOQ,OAAO;QACzB;IACF;IAEA,OAAOR;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/import/createImport.ts"],"sourcesContent":["import type { PayloadRequest, User } from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { ImportResult } from '../types.js'\n\nimport { applyFieldHooks } from '../utilities/applyFieldHooks.js'\nimport { getImportFieldFunctions } from '../utilities/getImportFieldFunctions.js'\nimport { parseCSV } from '../utilities/parseCSV.js'\nimport { parseJSON } from '../utilities/parseJSON.js'\nimport { removeDisabledFields } from '../utilities/removeDisabledFields.js'\nimport { unflattenObject } from '../utilities/unflattenObject.js'\nimport { createImportBatchProcessor } from './batchProcessor.js'\n\nexport type ImportMode = 'create' | 'update' | 'upsert'\n\nexport type Import = {\n /**\n * Number of documents to process in each batch during import\n * @default 100\n */\n batchSize?: number\n collectionSlug: string\n /**\n * If true, enabled debug logging\n */\n debug?: boolean\n file?: {\n data: Buffer\n mimetype: string\n name: string\n }\n format: 'csv' | 'json'\n id?: number | string\n /**\n * Import mode: create, update or upset\n */\n importMode: ImportMode\n matchField?: string\n /**\n * Maximum number of documents that can be imported in a single operation.\n * This value has already been resolved from the plugin config.\n */\n maxLimit?: number\n name: string\n userCollection?: string\n userID?: number | string\n}\n\nexport type CreateImportArgs = {\n defaultVersionStatus?: 'draft' | 'published'\n req: PayloadRequest\n} & Import\n\nexport const createImport = async ({\n batchSize = 100,\n collectionSlug,\n debug = false,\n defaultVersionStatus = 'published',\n file,\n format,\n importMode = 'create',\n matchField = 'id',\n maxLimit,\n req,\n userCollection,\n userID,\n}: CreateImportArgs): Promise<ImportResult> => {\n let user: undefined | User\n\n if (userCollection && userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: userCollection,\n req,\n })) as User\n }\n\n if (!user) {\n throw new APIError('User is required for import operations', 401, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n collectionSlug,\n format,\n importMode,\n matchField,\n msg: 'Starting import process with args:',\n transactionID: req.transactionID, // Log transaction ID to verify we're in same transaction\n })\n }\n\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n\n if (!file || !file?.data) {\n throw new APIError('No file data provided for import', 400, null, true)\n }\n\n if (debug) {\n req.payload.logger.debug({\n fileName: file.name,\n fileSize: file.data.length,\n mimeType: file.mimetype,\n msg: 'File info',\n })\n }\n\n const collectionConfig = req.payload.config.collections.find(\n ({ slug }) => slug === collectionSlug,\n )\n\n if (!collectionConfig) {\n if (!collectionSlug) {\n throw new APIError('Collection slug is required', 400, null, true)\n }\n throw new APIError(`Collection with slug ${collectionSlug} not found`, 400, null, true)\n }\n\n // Get disabled fields configuration\n const disabledFields =\n collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []\n\n const importHooks = collectionConfig.custom?.['plugin-import-export']?.importHooks\n\n // Get beforeImport functions for field transformations\n const importFieldHooks = getImportFieldFunctions({\n fields: collectionConfig.flattenedFields || [],\n })\n\n // Parse the file data\n let originalDocs: Record<string, unknown>[] | undefined\n let documents: Record<string, unknown>[]\n if (format === 'csv') {\n const rawData = await parseCSV({\n data: file.data,\n req,\n })\n\n originalDocs = rawData\n documents = rawData\n\n // Unflatten CSV data\n documents = documents\n .map((doc) => {\n const unflattened = unflattenObject({\n data: doc,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n importFieldHooks,\n req,\n })\n return unflattened ?? {}\n })\n .filter((doc) => doc && Object.keys(doc).length > 0)\n\n if (debug) {\n req.payload.logger.debug({\n documentCount: documents.length,\n msg: 'After unflattening CSV',\n rawDataCount: rawData.length,\n })\n }\n } else {\n const parsedDocs = parseJSON({ data: file.data, req })\n originalDocs = parsedDocs\n // Apply field-level import hooks for JSON format\n documents = parsedDocs.map((doc) =>\n applyFieldHooks({\n type: 'beforeImport',\n data: doc,\n fieldHooks: importFieldHooks,\n fields: collectionConfig.flattenedFields ?? [],\n format,\n operation: 'import',\n req,\n }),\n )\n }\n\n if (debug) {\n req.payload.logger.debug({\n msg: `Parsed ${documents.length} documents from ${format} file`,\n })\n if (documents.length > 0) {\n req.payload.logger.debug({\n doc: documents[0],\n msg: 'First document sample:',\n })\n }\n }\n\n // Enforce maxLimit before processing to save memory/time\n if (typeof maxLimit === 'number' && maxLimit > 0 && documents.length > maxLimit) {\n throw new APIError(\n `Import file contains ${documents.length} documents but limit is ${maxLimit}`,\n 400,\n null,\n true,\n )\n }\n\n // Remove disabled fields from all documents\n if (disabledFields.length > 0) {\n documents = documents.map((doc) => removeDisabledFields(doc, disabledFields))\n }\n\n if (debug) {\n req.payload.logger.debug({\n batchSize,\n documentCount: documents.length,\n msg: 'Processing import in batches',\n })\n }\n\n // Create batch processor\n const processor = createImportBatchProcessor({\n batchSize,\n defaultVersionStatus,\n })\n\n const totalBatches = documents.length > 0 ? Math.ceil(documents.length / batchSize) : 1\n\n // Process import with batch processor\n const result = await processor.processImport({\n collectionSlug,\n docs: documents,\n format,\n hooks: importHooks,\n importMode,\n matchField,\n originalDocs,\n req,\n totalBatches,\n user,\n })\n\n if (debug) {\n req.payload.logger.info({\n errors: result.errors.length,\n imported: result.imported,\n msg: 'Import completed',\n total: result.total,\n updated: result.updated,\n })\n }\n\n return result\n}\n"],"names":["APIError","applyFieldHooks","getImportFieldFunctions","parseCSV","parseJSON","removeDisabledFields","unflattenObject","createImportBatchProcessor","createImport","batchSize","collectionSlug","debug","defaultVersionStatus","file","format","importMode","matchField","maxLimit","req","userCollection","userID","user","payload","findByID","id","collection","logger","msg","transactionID","data","fileName","name","fileSize","length","mimeType","mimetype","collectionConfig","config","collections","find","slug","disabledFields","admin","custom","importHooks","importFieldHooks","fields","flattenedFields","originalDocs","documents","rawData","map","doc","unflattened","filter","Object","keys","documentCount","rawDataCount","parsedDocs","type","fieldHooks","operation","processor","totalBatches","Math","ceil","result","processImport","docs","hooks","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B,MAAM,GAAGxB,aAAa;IAEtF,sCAAsC;IACtC,MAAM0D,SAAS,MAAMJ,UAAUK,aAAa,CAAC;QAC3C1D;QACA2D,MAAMpB;QACNnC;QACAwD,OAAO1B;QACP7B;QACAC;QACAgC;QACA9B;QACA8C;QACA3C;IACF;IAEA,IAAIV,OAAO;QACTO,IAAII,OAAO,CAACI,MAAM,CAAC6C,IAAI,CAAC;YACtBC,QAAQL,OAAOK,MAAM,CAACvC,MAAM;YAC5BwC,UAAUN,OAAOM,QAAQ;YACzB9C,KAAK;YACL+C,OAAOP,OAAOO,KAAK;YACnBC,SAASR,OAAOQ,OAAO;QACzB;IACF;IAEA,OAAOR;AACT,EAAC"}
@@ -121,8 +121,8 @@ export const getImportCollection = ({ collectionSlugs, importConfig, pluginConfi
121
121
  matchField: doc.matchField,
122
122
  maxLimit,
123
123
  req,
124
- userCollection: req?.user?.collection || req?.user?.user?.collection,
125
- userID: req?.user?.id || req?.user?.user?.id
124
+ userCollection: req?.user?.collection,
125
+ userID: req?.user?.id
126
126
  });
127
127
  // Determine status
128
128
  let status;
@@ -283,8 +283,8 @@ export const getImportCollection = ({ collectionSlugs, importConfig, pluginConfi
283
283
  importCollection: collectionConfig.slug,
284
284
  importId: doc.id,
285
285
  maxLimit,
286
- userCollection: req.user?.collection || req?.user?.user?.collection,
287
- userID: req?.user?.id || req?.user?.user?.id
286
+ userCollection: req.user?.collection,
287
+ userID: req?.user?.id
288
288
  };
289
289
  await req.payload.jobs.queue({
290
290
  input,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/import/getImportCollection.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig } from 'payload'\n\nimport { FileRetrievalError } from 'payload'\n\nimport type { ImportConfig, ImportExportPluginConfig } from '../types.js'\nimport type { ImportTaskInput } from './getCreateImportCollectionTask.js'\n\nimport { getFileFromDoc } from '../utilities/getFileFromDoc.js'\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { createImport } from './createImport.js'\nimport { getFields } from './getFields.js'\nimport { handlePreview } from './handlePreview.js'\n\nconst FALLBACK_BATCH_SIZE = 100\nconst FALLBACK_VERSION_STATUS = 'published'\n\nexport const getImportCollection = ({\n collectionSlugs,\n importConfig,\n pluginConfig,\n}: {\n /**\n * Collection slugs that this import collection supports.\n */\n collectionSlugs: string[]\n importConfig?: ImportConfig\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const afterChange: CollectionAfterChangeHook[] = []\n\n const collection: CollectionConfig = {\n slug: 'imports',\n access: {\n update: () => false,\n },\n admin: {\n components: {\n edit: {\n SaveButton: '@payloadcms/plugin-import-export/rsc#ImportSaveButton',\n },\n },\n custom: {\n 'plugin-import-export': {\n collectionSlugs,\n },\n },\n disableCopyToLocale: true,\n group: false,\n useAsTitle: 'filename',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: handlePreview,\n method: 'post',\n path: '/preview-data',\n },\n ],\n fields: getFields({ collectionSlugs }),\n hooks: {\n afterChange,\n },\n lockDocuments: false,\n upload: {\n filesRequiredOnCreate: true,\n hideFileInputOnCreate: false,\n hideRemoveFile: true,\n mimeTypes: ['text/csv', 'application/json'],\n },\n }\n\n afterChange.push(async ({ collection: collectionConfig, doc, operation, req }) => {\n if (operation !== 'create' || doc.status !== 'pending') {\n return doc\n }\n\n const targetCollection = req.payload.collections[doc.collectionSlug]\n const targetPluginConfig = targetCollection?.config.custom?.['plugin-import-export']\n\n const disableJobsQueue =\n targetPluginConfig?.importDisableJobsQueue ?? importConfig?.disableJobsQueue ?? false\n\n const debug = pluginConfig.debug || false\n\n if (debug) {\n req.payload.logger.info({\n collectionSlug: doc.collectionSlug,\n disableJobsQueue,\n docId: doc.id,\n msg: '[Import Sync Hook] Starting',\n transactionID: req.transactionID,\n })\n }\n\n if (!disableJobsQueue) {\n return doc\n }\n\n try {\n // Get file data from the uploaded document\n // First try req.file which is available during the same request (especially important for cloud storage)\n // Fall back to getFileFromDoc for cases where req.file isn't available\n let fileData: Buffer\n let fileMimetype: string\n\n if (req.file?.data) {\n fileData = req.file.data\n fileMimetype = req.file.mimetype || doc.mimeType\n\n if (!fileMimetype) {\n throw new FileRetrievalError(\n req.t,\n `Unable to determine mimetype for file: ${doc.filename}`,\n )\n }\n } else {\n const fileFromDoc = await getFileFromDoc({\n collectionConfig,\n doc: {\n filename: doc.filename,\n mimeType: doc.mimeType,\n url: doc.url,\n },\n req,\n })\n fileData = fileFromDoc.data\n fileMimetype = fileFromDoc.mimetype\n }\n\n const maxLimit = await resolveLimit({\n limit: targetPluginConfig?.importLimit,\n req,\n })\n const defaultVersionStatus =\n targetPluginConfig?.defaultVersionStatus ??\n importConfig?.defaultVersionStatus ??\n pluginConfig.defaultVersionStatus ??\n FALLBACK_VERSION_STATUS\n const batchSize =\n targetPluginConfig?.importBatchSize ??\n importConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n const result = await createImport({\n id: doc.id,\n name: doc.filename || 'import',\n batchSize,\n collectionSlug: doc.collectionSlug,\n debug,\n defaultVersionStatus,\n file: {\n name: doc.filename,\n data: fileData,\n mimetype: fileMimetype,\n },\n format: fileMimetype === 'text/csv' ? 'csv' : 'json',\n importMode: doc.importMode || 'create',\n matchField: doc.matchField,\n maxLimit,\n req,\n userCollection: req?.user?.collection || req?.user?.user?.collection,\n userID: req?.user?.id || req?.user?.user?.id,\n })\n\n // Determine status\n let status: 'completed' | 'failed' | 'partial'\n if (result.errors.length === 0) {\n status = 'completed'\n } else if (result.imported + result.updated === 0) {\n status = 'failed'\n } else {\n status = 'partial'\n }\n\n const summary = {\n imported: result.imported,\n issueDetails:\n result.errors.length > 0\n ? result.errors.map((e) => ({\n data: e.doc,\n error: e.error,\n row: e.index + 1,\n }))\n : undefined,\n issues: result.errors.length,\n total: result.total,\n updated: result.updated,\n }\n\n // Try to update the document with results\n try {\n await req.payload.update({\n id: doc.id,\n collection: collectionConfig.slug,\n data: {\n status,\n summary,\n },\n overrideAccess: true,\n req,\n })\n } catch (updateErr) {\n // Update may fail if document not yet committed\n if (debug) {\n req.payload.logger.error({\n err: updateErr,\n msg: `Failed to update import document ${doc.id} with results`,\n })\n }\n }\n\n // Return updated doc for immediate response\n return {\n ...doc,\n status,\n summary,\n }\n } catch (err) {\n const summary = {\n imported: 0,\n issueDetails: [\n {\n data: {},\n error: err instanceof Error ? err.message : String(err),\n row: 0,\n },\n ],\n issues: 1,\n total: 0,\n updated: 0,\n }\n\n if (debug) {\n req.payload.logger.error({\n docId: doc.id,\n err,\n msg: '[Import Sync Hook] Import processing failed, attempting to update status',\n transactionID: req.transactionID,\n })\n }\n\n // Try to update document with error status\n try {\n if (debug) {\n req.payload.logger.info({\n collectionSlug: collectionConfig.slug,\n docId: doc.id,\n msg: '[Import Sync Hook] About to update document with failed status',\n })\n }\n await req.payload.update({\n id: doc.id,\n collection: collectionConfig.slug,\n data: {\n status: 'failed',\n summary,\n },\n overrideAccess: true,\n req,\n })\n if (debug) {\n req.payload.logger.info({\n docId: doc.id,\n msg: '[Import Sync Hook] Successfully updated document with failed status',\n })\n }\n } catch (updateErr) {\n // Update may fail if document not yet committed, log but continue\n // ALWAYS log this error to help debug Postgres issues\n req.payload.logger.error({\n err: updateErr,\n msg: `[Import Sync Hook] Failed to update import document ${doc.id} with error status`,\n transactionID: req.transactionID,\n })\n }\n\n if (debug) {\n req.payload.logger.info({\n docId: doc.id,\n msg: '[Import Sync Hook] Returning failed doc',\n status: 'failed',\n })\n }\n\n // Return error status for immediate response\n return {\n ...doc,\n status: 'failed',\n summary,\n }\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\n const disableJobsQueue =\n targetPluginConfig?.importDisableJobsQueue ?? importConfig?.disableJobsQueue ?? false\n\n if (pluginConfig.debug) {\n req.payload.logger.info({\n collectionSlug: doc.collectionSlug,\n disableJobsQueue,\n docId: doc.id,\n docStatus: doc.status,\n msg: '[Import Job Hook] Checking if should queue job',\n transactionID: req.transactionID,\n })\n }\n\n if (disableJobsQueue) {\n if (pluginConfig.debug) {\n req.payload.logger.info({\n docId: doc.id,\n msg: '[Import Job Hook] Skipping job queue (sync mode)',\n })\n }\n return\n }\n\n try {\n // Resolve maxLimit ahead of time since it may involve async config resolution\n const maxLimit = await resolveLimit({\n limit: targetPluginConfig?.importLimit,\n req,\n })\n const defaultVersionStatus =\n targetPluginConfig?.defaultVersionStatus ??\n importConfig?.defaultVersionStatus ??\n pluginConfig.defaultVersionStatus ??\n FALLBACK_VERSION_STATUS\n const batchSize =\n targetPluginConfig?.importBatchSize ??\n importConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n const input: ImportTaskInput = {\n batchSize,\n debug: pluginConfig.debug,\n defaultVersionStatus,\n importCollection: collectionConfig.slug,\n importId: doc.id,\n maxLimit,\n userCollection: req.user?.collection || req?.user?.user?.collection,\n userID: req?.user?.id || req?.user?.user?.id,\n }\n\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionImport',\n })\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `Failed to queue import job for document ${doc.id}`,\n })\n }\n })\n\n return collection\n}\n"],"names":["FileRetrievalError","getFileFromDoc","resolveLimit","createImport","getFields","handlePreview","FALLBACK_BATCH_SIZE","FALLBACK_VERSION_STATUS","getImportCollection","collectionSlugs","importConfig","pluginConfig","afterChange","collection","slug","access","update","admin","components","edit","SaveButton","custom","disableCopyToLocale","group","useAsTitle","disableDuplicate","endpoints","handler","method","path","fields","hooks","lockDocuments","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","mimeTypes","push","collectionConfig","doc","operation","req","status","targetCollection","payload","collections","collectionSlug","targetPluginConfig","config","disableJobsQueue","importDisableJobsQueue","debug","logger","info","docId","id","msg","transactionID","fileData","fileMimetype","file","data","mimetype","mimeType","t","filename","fileFromDoc","url","maxLimit","limit","importLimit","defaultVersionStatus","batchSize","importBatchSize","result","name","format","importMode","matchField","userCollection","user","userID","errors","length","imported","updated","summary","issueDetails","map","e","error","row","index","undefined","issues","total","overrideAccess","updateErr","err","Error","message","String","docStatus","input","importCollection","importId","jobs","queue","task"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ,UAAS;AAK5C,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,aAAa,QAAQ,qBAAoB;AAElD,MAAMC,sBAAsB;AAC5B,MAAMC,0BAA0B;AAEhC,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,eAAe,EACfC,YAAY,EACZC,YAAY,EAQb;IACC,MAAMC,cAA2C,EAAE;IAEnD,MAAMC,aAA+B;QACnCC,MAAM;QACNC,QAAQ;YACNC,QAAQ,IAAM;QAChB;QACAC,OAAO;YACLC,YAAY;gBACVC,MAAM;oBACJC,YAAY;gBACd;YACF;YACAC,QAAQ;gBACN,wBAAwB;oBACtBZ;gBACF;YACF;YACAa,qBAAqB;YACrBC,OAAO;YACPC,YAAY;QACd;QACAC,kBAAkB;QAClBC,WAAW;YACT;gBACEC,SAAStB;gBACTuB,QAAQ;gBACRC,MAAM;YACR;SACD;QACDC,QAAQ1B,UAAU;YAAEK;QAAgB;QACpCsB,OAAO;YACLnB;QACF;QACAoB,eAAe;QACfC,QAAQ;YACNC,uBAAuB;YACvBC,uBAAuB;YACvBC,gBAAgB;YAChBC,WAAW;gBAAC;gBAAY;aAAmB;QAC7C;IACF;IAEAzB,YAAY0B,IAAI,CAAC,OAAO,EAAEzB,YAAY0B,gBAAgB,EAAEC,GAAG,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC3E,IAAID,cAAc,YAAYD,IAAIG,MAAM,KAAK,WAAW;YACtD,OAAOH;QACT;QAEA,MAAMI,mBAA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IAAIG,OAAO,CAACQ,MAAM,CAACC,IAAI,CAAC;oBACtBC,OAAOf,IAAIgB,EAAE;oBACbC,KAAK;gBACP;YACF;YACA;QACF;QAEA,IAAI;YACF,8EAA8E;YAC9E,MAAMY,WAAW,MAAMnE,aAAa;gBAClCoE,OAAOtB,oBAAoBuB;gBAC3B7B;YACF;YACA,MAAM8B,uBACJxB,oBAAoBwB,wBACpB9D,cAAc8D,wBACd7D,aAAa6D,oBAAoB,IACjCjE;YACF,MAAMkE,YACJzB,oBAAoB0B,mBACpBhE,cAAc+D,aACd9D,aAAa8D,SAAS,IACtBnE;YAEF,MAAMkG,QAAyB;gBAC7B/B;gBACArB,OAAOzC,aAAayC,KAAK;gBACzBoB;gBACAiC,kBAAkBlE,iBAAiBzB,IAAI;gBACvC4F,UAAUlE,IAAIgB,EAAE;gBAChBa;gBACAW,gBAAgBtC,IAAIuC,IAAI,EAAEpE,cAAc6B,KAAKuC,MAAMA,MAAMpE;gBACzDqE,QAAQxC,KAAKuC,MAAMzB,MAAMd,KAAKuC,MAAMA,MAAMzB;YAC5C;YAEA,MAAMd,IAAIG,OAAO,CAAC8D,IAAI,CAACC,KAAK,CAAC;gBAC3BJ;gBACAK,MAAM;YACR;QACF,EAAE,OAAOV,KAAK;YACZzD,IAAIG,OAAO,CAACQ,MAAM,CAACsC,KAAK,CAAC;gBACvBQ;gBACA1C,KAAK,CAAC,wCAAwC,EAAEjB,IAAIgB,EAAE,EAAE;YAC1D;QACF;IACF;IAEA,OAAO3C;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/import/getImportCollection.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig } from 'payload'\n\nimport { FileRetrievalError } from 'payload'\n\nimport type { ImportConfig, ImportExportPluginConfig } from '../types.js'\nimport type { ImportTaskInput } from './getCreateImportCollectionTask.js'\n\nimport { getFileFromDoc } from '../utilities/getFileFromDoc.js'\nimport { resolveLimit } from '../utilities/resolveLimit.js'\nimport { createImport } from './createImport.js'\nimport { getFields } from './getFields.js'\nimport { handlePreview } from './handlePreview.js'\n\nconst FALLBACK_BATCH_SIZE = 100\nconst FALLBACK_VERSION_STATUS = 'published'\n\nexport const getImportCollection = ({\n collectionSlugs,\n importConfig,\n pluginConfig,\n}: {\n /**\n * Collection slugs that this import collection supports.\n */\n collectionSlugs: string[]\n importConfig?: ImportConfig\n pluginConfig: ImportExportPluginConfig\n}): CollectionConfig => {\n const afterChange: CollectionAfterChangeHook[] = []\n\n const collection: CollectionConfig = {\n slug: 'imports',\n access: {\n update: () => false,\n },\n admin: {\n components: {\n edit: {\n SaveButton: '@payloadcms/plugin-import-export/rsc#ImportSaveButton',\n },\n },\n custom: {\n 'plugin-import-export': {\n collectionSlugs,\n },\n },\n disableCopyToLocale: true,\n group: false,\n useAsTitle: 'filename',\n },\n disableDuplicate: true,\n endpoints: [\n {\n handler: handlePreview,\n method: 'post',\n path: '/preview-data',\n },\n ],\n fields: getFields({ collectionSlugs }),\n hooks: {\n afterChange,\n },\n lockDocuments: false,\n upload: {\n filesRequiredOnCreate: true,\n hideFileInputOnCreate: false,\n hideRemoveFile: true,\n mimeTypes: ['text/csv', 'application/json'],\n },\n }\n\n afterChange.push(async ({ collection: collectionConfig, doc, operation, req }) => {\n if (operation !== 'create' || doc.status !== 'pending') {\n return doc\n }\n\n const targetCollection = req.payload.collections[doc.collectionSlug]\n const targetPluginConfig = targetCollection?.config.custom?.['plugin-import-export']\n\n const disableJobsQueue =\n targetPluginConfig?.importDisableJobsQueue ?? importConfig?.disableJobsQueue ?? false\n\n const debug = pluginConfig.debug || false\n\n if (debug) {\n req.payload.logger.info({\n collectionSlug: doc.collectionSlug,\n disableJobsQueue,\n docId: doc.id,\n msg: '[Import Sync Hook] Starting',\n transactionID: req.transactionID,\n })\n }\n\n if (!disableJobsQueue) {\n return doc\n }\n\n try {\n // Get file data from the uploaded document\n // First try req.file which is available during the same request (especially important for cloud storage)\n // Fall back to getFileFromDoc for cases where req.file isn't available\n let fileData: Buffer\n let fileMimetype: string\n\n if (req.file?.data) {\n fileData = req.file.data\n fileMimetype = req.file.mimetype || doc.mimeType\n\n if (!fileMimetype) {\n throw new FileRetrievalError(\n req.t,\n `Unable to determine mimetype for file: ${doc.filename}`,\n )\n }\n } else {\n const fileFromDoc = await getFileFromDoc({\n collectionConfig,\n doc: {\n filename: doc.filename,\n mimeType: doc.mimeType,\n url: doc.url,\n },\n req,\n })\n fileData = fileFromDoc.data\n fileMimetype = fileFromDoc.mimetype\n }\n\n const maxLimit = await resolveLimit({\n limit: targetPluginConfig?.importLimit,\n req,\n })\n const defaultVersionStatus =\n targetPluginConfig?.defaultVersionStatus ??\n importConfig?.defaultVersionStatus ??\n pluginConfig.defaultVersionStatus ??\n FALLBACK_VERSION_STATUS\n const batchSize =\n targetPluginConfig?.importBatchSize ??\n importConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n const result = await createImport({\n id: doc.id,\n name: doc.filename || 'import',\n batchSize,\n collectionSlug: doc.collectionSlug,\n debug,\n defaultVersionStatus,\n file: {\n name: doc.filename,\n data: fileData,\n mimetype: fileMimetype,\n },\n format: fileMimetype === 'text/csv' ? 'csv' : 'json',\n importMode: doc.importMode || 'create',\n matchField: doc.matchField,\n maxLimit,\n req,\n userCollection: req?.user?.collection,\n userID: req?.user?.id,\n })\n\n // Determine status\n let status: 'completed' | 'failed' | 'partial'\n if (result.errors.length === 0) {\n status = 'completed'\n } else if (result.imported + result.updated === 0) {\n status = 'failed'\n } else {\n status = 'partial'\n }\n\n const summary = {\n imported: result.imported,\n issueDetails:\n result.errors.length > 0\n ? result.errors.map((e) => ({\n data: e.doc,\n error: e.error,\n row: e.index + 1,\n }))\n : undefined,\n issues: result.errors.length,\n total: result.total,\n updated: result.updated,\n }\n\n // Try to update the document with results\n try {\n await req.payload.update({\n id: doc.id,\n collection: collectionConfig.slug,\n data: {\n status,\n summary,\n },\n overrideAccess: true,\n req,\n })\n } catch (updateErr) {\n // Update may fail if document not yet committed\n if (debug) {\n req.payload.logger.error({\n err: updateErr,\n msg: `Failed to update import document ${doc.id} with results`,\n })\n }\n }\n\n // Return updated doc for immediate response\n return {\n ...doc,\n status,\n summary,\n }\n } catch (err) {\n const summary = {\n imported: 0,\n issueDetails: [\n {\n data: {},\n error: err instanceof Error ? err.message : String(err),\n row: 0,\n },\n ],\n issues: 1,\n total: 0,\n updated: 0,\n }\n\n if (debug) {\n req.payload.logger.error({\n docId: doc.id,\n err,\n msg: '[Import Sync Hook] Import processing failed, attempting to update status',\n transactionID: req.transactionID,\n })\n }\n\n // Try to update document with error status\n try {\n if (debug) {\n req.payload.logger.info({\n collectionSlug: collectionConfig.slug,\n docId: doc.id,\n msg: '[Import Sync Hook] About to update document with failed status',\n })\n }\n await req.payload.update({\n id: doc.id,\n collection: collectionConfig.slug,\n data: {\n status: 'failed',\n summary,\n },\n overrideAccess: true,\n req,\n })\n if (debug) {\n req.payload.logger.info({\n docId: doc.id,\n msg: '[Import Sync Hook] Successfully updated document with failed status',\n })\n }\n } catch (updateErr) {\n // Update may fail if document not yet committed, log but continue\n // ALWAYS log this error to help debug Postgres issues\n req.payload.logger.error({\n err: updateErr,\n msg: `[Import Sync Hook] Failed to update import document ${doc.id} with error status`,\n transactionID: req.transactionID,\n })\n }\n\n if (debug) {\n req.payload.logger.info({\n docId: doc.id,\n msg: '[Import Sync Hook] Returning failed doc',\n status: 'failed',\n })\n }\n\n // Return error status for immediate response\n return {\n ...doc,\n status: 'failed',\n summary,\n }\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\n const disableJobsQueue =\n targetPluginConfig?.importDisableJobsQueue ?? importConfig?.disableJobsQueue ?? false\n\n if (pluginConfig.debug) {\n req.payload.logger.info({\n collectionSlug: doc.collectionSlug,\n disableJobsQueue,\n docId: doc.id,\n docStatus: doc.status,\n msg: '[Import Job Hook] Checking if should queue job',\n transactionID: req.transactionID,\n })\n }\n\n if (disableJobsQueue) {\n if (pluginConfig.debug) {\n req.payload.logger.info({\n docId: doc.id,\n msg: '[Import Job Hook] Skipping job queue (sync mode)',\n })\n }\n return\n }\n\n try {\n // Resolve maxLimit ahead of time since it may involve async config resolution\n const maxLimit = await resolveLimit({\n limit: targetPluginConfig?.importLimit,\n req,\n })\n const defaultVersionStatus =\n targetPluginConfig?.defaultVersionStatus ??\n importConfig?.defaultVersionStatus ??\n pluginConfig.defaultVersionStatus ??\n FALLBACK_VERSION_STATUS\n const batchSize =\n targetPluginConfig?.importBatchSize ??\n importConfig?.batchSize ??\n pluginConfig.batchSize ??\n FALLBACK_BATCH_SIZE\n\n const input: ImportTaskInput = {\n batchSize,\n debug: pluginConfig.debug,\n defaultVersionStatus,\n importCollection: collectionConfig.slug,\n importId: doc.id,\n maxLimit,\n userCollection: req.user?.collection,\n userID: req?.user?.id,\n }\n\n await req.payload.jobs.queue({\n input,\n task: 'createCollectionImport',\n })\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `Failed to queue import job for document ${doc.id}`,\n })\n }\n })\n\n return collection\n}\n"],"names":["FileRetrievalError","getFileFromDoc","resolveLimit","createImport","getFields","handlePreview","FALLBACK_BATCH_SIZE","FALLBACK_VERSION_STATUS","getImportCollection","collectionSlugs","importConfig","pluginConfig","afterChange","collection","slug","access","update","admin","components","edit","SaveButton","custom","disableCopyToLocale","group","useAsTitle","disableDuplicate","endpoints","handler","method","path","fields","hooks","lockDocuments","upload","filesRequiredOnCreate","hideFileInputOnCreate","hideRemoveFile","mimeTypes","push","collectionConfig","doc","operation","req","status","targetCollection","payload","collections","collectionSlug","targetPluginConfig","config","disableJobsQueue","importDisableJobsQueue","debug","logger","info","docId","id","msg","transactionID","fileData","fileMimetype","file","data","mimetype","mimeType","t","filename","fileFromDoc","url","maxLimit","limit","importLimit","defaultVersionStatus","batchSize","importBatchSize","result","name","format","importMode","matchField","userCollection","user","userID","errors","length","imported","updated","summary","issueDetails","map","e","error","row","index","undefined","issues","total","overrideAccess","updateErr","err","Error","message","String","docStatus","input","importCollection","importId","jobs","queue","task"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ,UAAS;AAK5C,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,aAAa,QAAQ,qBAAoB;AAElD,MAAMC,sBAAsB;AAC5B,MAAMC,0BAA0B;AAEhC,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,eAAe,EACfC,YAAY,EACZC,YAAY,EAQb;IACC,MAAMC,cAA2C,EAAE;IAEnD,MAAMC,aAA+B;QACnCC,MAAM;QACNC,QAAQ;YACNC,QAAQ,IAAM;QAChB;QACAC,OAAO;YACLC,YAAY;gBACVC,MAAM;oBACJC,YAAY;gBACd;YACF;YACAC,QAAQ;gBACN,wBAAwB;oBACtBZ;gBACF;YACF;YACAa,qBAAqB;YACrBC,OAAO;YACPC,YAAY;QACd;QACAC,kBAAkB;QAClBC,WAAW;YACT;gBACEC,SAAStB;gBACTuB,QAAQ;gBACRC,MAAM;YACR;SACD;QACDC,QAAQ1B,UAAU;YAAEK;QAAgB;QACpCsB,OAAO;YACLnB;QACF;QACAoB,eAAe;QACfC,QAAQ;YACNC,uBAAuB;YACvBC,uBAAuB;YACvBC,gBAAgB;YAChBC,WAAW;gBAAC;gBAAY;aAAmB;QAC7C;IACF;IAEAzB,YAAY0B,IAAI,CAAC,OAAO,EAAEzB,YAAY0B,gBAAgB,EAAEC,GAAG,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC3E,IAAID,cAAc,YAAYD,IAAIG,MAAM,KAAK,WAAW;YACtD,OAAOH;QACT;QAEA,MAAMI,mBAAmBF,IAAIG,OAAO,CAACC,WAAW,CAACN,IAAIO,cAAc,CAA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I;YACF,8EAA8E;YAC9E,MAAMY,WAAW,MAAMnE,aAAa;gBAClCoE,OAAOtB,oBAAoBuB;gBAC3B7B;YACF;YACA,MAAM8B,uBACJxB,oBAAoBwB,wBACpB9D,cAAc8D,wBACd7D,aAAa6D,oBAAoB,IACjCjE;YACF,MAAMkE,YACJzB,oBAAoB0B,mBACpBhE,cAAc+D,aACd9D,aAAa8D,SAAS,IACtBnE;YAEF,MAAMkG,QAAyB;gBAC7B/B;gBACArB,OAAOzC,aAAayC,KAAK;gBACzBoB;gBACAiC,kBAAkBlE,iBAAiBzB,IAAI;gBACvC4F,UAAUlE,IAAIgB,EAAE;gBAChBa;gBACAW,gBAAgBtC,IAAIuC,IAAI,EAAEpE;gBAC1BqE,QAAQxC,KAAKuC,MAAMzB;YACrB;YAEA,MAAMd,IAAIG,OAAO,CAAC8D,IAAI,CAACC,KAAK,CAAC;gBAC3BJ;gBACAK,MAAM;YACR;QACF,EAAE,OAAOV,KAAK;YACZzD,IAAIG,OAAO,CAACQ,MAAM,CAACsC,KAAK,CAAC;gBACvBQ;gBACA1C,KAAK,CAAC,wCAAwC,EAAEjB,IAAIgB,EAAE,EAAE;YAC1D;QACF;IACF;IAEA,OAAO3C;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-import-export",
3
- "version": "4.0.0-canary.7",
3
+ "version": "4.0.0-canary.8",
4
4
  "description": "Import-Export plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -64,17 +64,17 @@
64
64
  "csv-parse": "5.6.0",
65
65
  "csv-stringify": "6.5.2",
66
66
  "qs-esm": "8.0.1",
67
- "@payloadcms/translations": "4.0.0-canary.7",
68
- "@payloadcms/ui": "4.0.0-canary.7"
67
+ "@payloadcms/translations": "4.0.0-canary.8",
68
+ "@payloadcms/ui": "4.0.0-canary.8"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@payloadcms/eslint-config": "3.28.0",
72
- "@payloadcms/ui": "4.0.0-canary.7",
73
- "payload": "4.0.0-canary.7"
72
+ "@payloadcms/ui": "4.0.0-canary.8",
73
+ "payload": "4.0.0-canary.8"
74
74
  },
75
75
  "peerDependencies": {
76
- "@payloadcms/ui": "4.0.0-canary.7",
77
- "payload": "4.0.0-canary.7"
76
+ "@payloadcms/ui": "4.0.0-canary.8",
77
+ "payload": "4.0.0-canary.8"
78
78
  },
79
79
  "homepage:": "https://payloadcms.com",
80
80
  "scripts": {