payload 3.89.0-internal.4b0e9b6 → 3.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/collections/operations/update.js +5 -5
  2. package/dist/collections/operations/update.js.map +1 -1
  3. package/dist/index.bundled.d.ts +49 -29
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/queues/config/collection.d.ts.map +1 -1
  9. package/dist/queues/config/collection.js +6 -0
  10. package/dist/queues/config/collection.js.map +1 -1
  11. package/dist/queues/config/types/index.d.ts +2 -0
  12. package/dist/queues/config/types/index.d.ts.map +1 -1
  13. package/dist/queues/config/types/index.js.map +1 -1
  14. package/dist/queues/endpoints/handleSchedules.d.ts.map +1 -1
  15. package/dist/queues/endpoints/handleSchedules.js +2 -1
  16. package/dist/queues/endpoints/handleSchedules.js.map +1 -1
  17. package/dist/queues/endpoints/run.d.ts.map +1 -1
  18. package/dist/queues/endpoints/run.js +2 -1
  19. package/dist/queues/endpoints/run.js.map +1 -1
  20. package/dist/uploads/getFileContentRequirement.d.ts +9 -0
  21. package/dist/uploads/getFileContentRequirement.d.ts.map +1 -0
  22. package/dist/uploads/getFileContentRequirement.js +24 -0
  23. package/dist/uploads/getFileContentRequirement.js.map +1 -0
  24. package/dist/uploads/getFileContentRequirement.spec.js +95 -0
  25. package/dist/uploads/getFileContentRequirement.spec.js.map +1 -0
  26. package/dist/uploads/getFileFromClientUpload.d.ts +20 -0
  27. package/dist/uploads/getFileFromClientUpload.d.ts.map +1 -0
  28. package/dist/uploads/getFileFromClientUpload.js +199 -0
  29. package/dist/uploads/getFileFromClientUpload.js.map +1 -0
  30. package/dist/uploads/getFileFromClientUpload.spec.js +590 -0
  31. package/dist/uploads/getFileFromClientUpload.spec.js.map +1 -0
  32. package/dist/uploads/unlinkClientUploadTempFile.d.ts +20 -0
  33. package/dist/uploads/unlinkClientUploadTempFile.d.ts.map +1 -0
  34. package/dist/uploads/unlinkClientUploadTempFile.js +30 -0
  35. package/dist/uploads/unlinkClientUploadTempFile.js.map +1 -0
  36. package/dist/uploads/unlinkTempFiles.d.ts.map +1 -1
  37. package/dist/uploads/unlinkTempFiles.js +10 -2
  38. package/dist/uploads/unlinkTempFiles.js.map +1 -1
  39. package/dist/uploads/unlinkTempFiles.spec.js +217 -0
  40. package/dist/uploads/unlinkTempFiles.spec.js.map +1 -0
  41. package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
  42. package/dist/utilities/addDataAndFileToRequest.js +7 -46
  43. package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
  44. package/dist/utilities/addDataAndFileToRequest.spec.js +131 -1
  45. package/dist/utilities/addDataAndFileToRequest.spec.js.map +1 -1
  46. package/dist/utilities/wrapInternalEndpoints.d.ts.map +1 -1
  47. package/dist/utilities/wrapInternalEndpoints.js +10 -3
  48. package/dist/utilities/wrapInternalEndpoints.js.map +1 -1
  49. package/dist/utilities/wrapInternalEndpoints.spec.js +124 -0
  50. package/dist/utilities/wrapInternalEndpoints.spec.js.map +1 -0
  51. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/queues/config/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,O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,GAAG,CACA;IACE,KAAK,EAAE,KAAK,CAAA;IACZ,GAAG,CAAC,EAAE,KAAK,CAAA;IACX,MAAM,EAAE,OAAO,CAAA;CAChB,GACD;IACE,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,SAAS,CAAA;CAClB,GACD;IACE,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,GAAG,CAAC,EAAE,KAAK,CAAA;IACX;;OAEG;IACH,MAAM,EAAE,SAAS,CAAA;CAClB,CACJ,KACE,YAAY,CAAC,IAAI,CAAC,CAAA;AAEvB,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;;;;;;;;;;;;;;;OAkBG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE;QACN;;;;WAIG;QACH,aAAa,CAAC,EAAE,eAAe,CAAA;QAC/B;;;;;;;;;WASG;QACH,cAAc,CAAC,EAAE,gBAAgB,CAAA;KAClC,CAAA;IACD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;CACd,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queues/config/types/index.ts"],"sourcesContent":["import type { CollectionConfig, Job } from '../../../index.js'\nimport type { MaybePromise, Payload, PayloadRequest, Sort } from '../../../types/index.js'\nimport type { RunJobsSilent } from '../../localAPI.js'\nimport type { RunJobsArgs } from '../../operations/runJobs/index.js'\nimport type { JobStats } from '../global.js'\nimport type { TaskConfig } from './taskTypes.js'\nimport type { WorkflowConfig } from './workflowTypes.js'\n\nexport type AutorunCronConfig = {\n /**\n * If you want to autoRUn jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n /**\n * The cron schedule for the job.\n * @default '* * * * *' (every minute).\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron?: string\n /**\n * By default, the autorun will attempt to schedule jobs for tasks and workflows that have a `schedule` property, given\n * the queue name is the same.\n *\n * Set this to `true` to disable the scheduling of jobs automatically.\n *\n * @default false\n */\n disableScheduling?: boolean\n /**\n * The limit for the job. This can be overridden by the user. Defaults to 10.\n */\n limit?: number\n /**\n * The queue name for the job.\n *\n * @default 'default'\n */\n queue?: string\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n}\n\nexport type RunJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type RunJobAccess = (args: RunJobAccessArgs) => MaybePromise<boolean>\n\nexport type QueueJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type CancelJobAccessArgs = {\n req: PayloadRequest\n}\nexport type CancelJobAccess = (args: CancelJobAccessArgs) => MaybePromise<boolean>\nexport type QueueJobAccess = (args: QueueJobAccessArgs) => MaybePromise<boolean>\n\nexport type SanitizedJobsConfig = {\n /**\n * If set to `true`, the job system is enabled and a payload-jobs collection exists.\n * This property is automatically set during sanitization.\n */\n enabled?: boolean\n /**\n * If set to `true`, at least one task or workflow has scheduling enabled.\n * This property is automatically set during sanitization.\n */\n scheduling?: boolean\n /**\n * If set to `true`, a payload-job-stats global exists.\n * This property is automatically set during sanitization.\n */\n stats?: boolean\n} & JobsConfig\nexport type JobsConfig = {\n /**\n * Specify access control to determine who can interact with jobs.\n */\n access?: {\n /**\n * By default, all logged-in users can cancel jobs.\n */\n cancel?: CancelJobAccess\n /**\n * By default, all logged-in users can queue jobs.\n */\n queue?: QueueJobAccess\n /**\n * By default, all logged-in users can run jobs.\n */\n run?: RunJobAccess\n }\n /** Adds information about the parent job to the task log. This is useful for debugging and tracking the flow of tasks.\n *\n * In 4.0, this will default to `true`.\n *\n * @default false\n */\n addParentToTaskLog?: boolean\n /**\n * Allows you to configure cron jobs that automatically run queued jobs\n * at specified intervals. Note that this does not _queue_ new jobs - only\n * _runs_ jobs that are already in the specified queue.\n *\n * @remark this property should not be used on serverless platforms like Vercel\n */\n autoRun?: ((payload: Payload) => MaybePromise<AutorunCronConfig[]>) | AutorunCronConfig[]\n /**\n * Determine whether or not to delete a job after it has successfully completed.\n */\n deleteJobOnComplete?: boolean\n /**\n * Specify depth for retrieving jobs from the queue.\n * This should be as low as possible in order for job retrieval\n * to be as efficient as possible. Setting it to anything higher than\n * 0 will drastically affect performance, as less efficient database\n * queries will be used.\n *\n * @default 0\n * @deprecated - this will be removed in 4.0\n */\n depth?: number\n /**\n * Enable concurrency controls for workflows and tasks.\n * When enabled, adds a `concurrencyKey` field to the jobs collection schema.\n * This allows workflows and tasks to use the `concurrency` option to prevent race conditions.\n *\n * **Important:** Enabling this may require a database migration depending on your database adapter,\n * as it adds a new indexed field to the jobs collection schema.\n *\n * @default false\n * @todo In 4.0, this will default to `true`.\n */\n enableConcurrencyControl?: boolean\n /**\n * Override any settings on the default Jobs collection. Accepts the default collection and allows you to return\n * a new collection.\n */\n jobsCollectionOverrides?: (args: { defaultJobsCollection: CollectionConfig }) => CollectionConfig\n /**\n * Adjust the job processing order using a Payload sort string. This can be set globally or per queue.\n *\n * FIFO would equal `createdAt` and LIFO would equal `-createdAt`.\n *\n * @default all jobs for all queues will be executed in FIFO order.\n */\n processingOrder?:\n | ((args: RunJobsArgs) => Promise<Sort> | Sort)\n | {\n default?: Sort\n queues: {\n [queue: string]: Sort\n }\n }\n | Sort\n /**\n * By default, the job system uses direct database calls for optimal performance.\n * If you added custom hooks to your jobs collection, you can set this to true to\n * use the standard Payload API for all job operations. This is discouraged, as it will\n * drastically affect performance.\n *\n * @default false\n * @deprecated - this will be removed in 4.0\n */\n runHooks?: boolean\n /**\n * A function that will be executed before Payload picks up jobs which are configured by the `jobs.autorun` function.\n * If this function returns true, jobs will be queried and picked up. If it returns false, jobs will not be run.\n * @default undefined - if this function is not defined, jobs will be run - as if () => true was passed.\n * @param payload\n * @returns boolean\n */\n shouldAutoRun?: (payload: Payload) => MaybePromise<boolean>\n /**\n * Define all possible tasks here\n */\n tasks?: TaskConfig<any>[]\n /**\n * Define all the workflows here. Workflows orchestrate the flow of multiple tasks.\n */\n workflows?: WorkflowConfig<any>[]\n}\n\nexport type Queueable = {\n scheduleConfig: ScheduleConfig\n taskConfig?: TaskConfig\n // If not set, queue it immediately\n waitUntil?: Date\n workflowConfig?: WorkflowConfig\n}\n\nexport type BeforeScheduleFn = (args: {\n defaultBeforeSchedule: BeforeScheduleFn\n /**\n * payload-job-stats global data\n */\n jobStats: JobStats\n queueable: Queueable\n req: PayloadRequest\n}) => MaybePromise<{\n input?: object\n shouldSchedule: boolean\n waitUntil?: Date\n}>\n\nexport type AfterScheduleFn = (\n args: {\n defaultAfterSchedule: AfterScheduleFn\n /**\n * payload-job-stats global data. If the global does not exist, it will be null.\n */\n jobStats: JobStats | null\n queueable: Queueable\n req: PayloadRequest\n } & (\n | {\n error: Error\n job?: never\n status: 'error'\n }\n | {\n error?: never\n job: Job\n status: 'success'\n }\n | {\n error?: never\n job?: never\n /**\n * If the beforeSchedule hook returned `shouldSchedule: false`, this will be called with status `skipped`.\n */\n status: 'skipped'\n }\n ),\n) => MaybePromise<void>\n\nexport type ScheduleConfig = {\n /**\n * The cron for scheduling the job.\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron: string\n hooks?: {\n /**\n * Functions that will be executed after the job has been successfully scheduled.\n *\n * @default By default, global update?? Unless global update should happen before\n */\n afterSchedule?: AfterScheduleFn\n /**\n * Functions that will be executed before the job is scheduled.\n * You can use this to control whether or not the job should be scheduled, or what input\n * data should be passed to the job.\n *\n * @default By default, this has one function that returns { shouldSchedule: true } if the following conditions are met:\n * - There currently is no job of the same type in the specified queue that is currently running\n * - There currently is no job of the same type in the specified queue that is scheduled to run in the future\n * - There currently is no job of the same type in the specified queue that failed previously but can be retried\n */\n beforeSchedule?: BeforeScheduleFn\n }\n /**\n * Queue to which the scheduled job will be added.\n */\n queue: string\n}\n"],"names":[],"mappings":"AAsQA,WA4CC"}
1
+ {"version":3,"sources":["../../../../src/queues/config/types/index.ts"],"sourcesContent":["import type { CollectionConfig, Job } from '../../../index.js'\nimport type { MaybePromise, Payload, PayloadRequest, Sort } from '../../../types/index.js'\nimport type { RunJobsSilent } from '../../localAPI.js'\nimport type { RunJobsArgs } from '../../operations/runJobs/index.js'\nimport type { JobStats } from '../global.js'\nimport type { TaskConfig } from './taskTypes.js'\nimport type { WorkflowConfig } from './workflowTypes.js'\n\nexport type AutorunCronConfig = {\n /**\n * If you want to autoRUn jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n /**\n * The cron schedule for the job.\n * @default '* * * * *' (every minute).\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron?: string\n /**\n * By default, the autorun will attempt to schedule jobs for tasks and workflows that have a `schedule` property, given\n * the queue name is the same.\n *\n * Set this to `true` to disable the scheduling of jobs automatically.\n *\n * @default false\n */\n disableScheduling?: boolean\n /**\n * The limit for the job. This can be overridden by the user. Defaults to 10.\n */\n limit?: number\n /**\n * The queue name for the job.\n *\n * @default 'default'\n */\n queue?: string\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n}\n\nexport type RunJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type RunJobAccess = (args: RunJobAccessArgs) => MaybePromise<boolean>\n\nexport type QueueJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type CancelJobAccessArgs = {\n req: PayloadRequest\n}\nexport type CancelJobAccess = (args: CancelJobAccessArgs) => MaybePromise<boolean>\nexport type QueueJobAccess = (args: QueueJobAccessArgs) => MaybePromise<boolean>\n\nexport type SanitizedJobsConfig = {\n /**\n * If set to `true`, the job system is enabled and a payload-jobs collection exists.\n * This property is automatically set during sanitization.\n */\n enabled?: boolean\n /**\n * If set to `true`, at least one task or workflow has scheduling enabled.\n * This property is automatically set during sanitization.\n */\n scheduling?: boolean\n /**\n * If set to `true`, a payload-job-stats global exists.\n * This property is automatically set during sanitization.\n */\n stats?: boolean\n} & JobsConfig\nexport type JobsConfig = {\n /**\n * Specify access control to determine who can interact with jobs.\n */\n access?: {\n /**\n * By default, all logged-in users can cancel jobs.\n */\n cancel?: CancelJobAccess\n /**\n * By default, all logged-in users can queue jobs.\n */\n queue?: QueueJobAccess\n /**\n * By default, all logged-in users can run jobs.\n */\n run?: RunJobAccess\n }\n /** Adds information about the parent job to the task log. This is useful for debugging and tracking the flow of tasks.\n *\n * In 4.0, this will default to `true`.\n *\n * @default false\n */\n addParentToTaskLog?: boolean\n /**\n * Allows you to configure cron jobs that automatically run queued jobs\n * at specified intervals. Note that this does not _queue_ new jobs - only\n * _runs_ jobs that are already in the specified queue.\n *\n * @remark this property should not be used on serverless platforms like Vercel\n */\n autoRun?: ((payload: Payload) => MaybePromise<AutorunCronConfig[]>) | AutorunCronConfig[]\n /**\n * Determine whether or not to delete a job after it has successfully completed.\n */\n deleteJobOnComplete?: boolean\n /**\n * Specify depth for retrieving jobs from the queue.\n * This should be as low as possible in order for job retrieval\n * to be as efficient as possible. Setting it to anything higher than\n * 0 will drastically affect performance, as less efficient database\n * queries will be used.\n *\n * @default 0\n * @deprecated - this will be removed in 4.0\n */\n depth?: number\n /**\n * Enable concurrency controls for workflows and tasks.\n * When enabled, adds a `concurrencyKey` field to the jobs collection schema.\n * This allows workflows and tasks to use the `concurrency` option to prevent race conditions.\n *\n * **Important:** Enabling this may require a database migration depending on your database adapter,\n * as it adds a new indexed field to the jobs collection schema.\n *\n * @default false\n * @todo In 4.0, this will default to `true`.\n */\n enableConcurrencyControl?: boolean\n /**\n * Override any settings on the default Jobs collection. Accepts the default collection and allows you to return\n * a new collection.\n *\n * @experimental\n */\n jobsCollectionOverrides?: (args: { defaultJobsCollection: CollectionConfig }) => CollectionConfig\n /**\n * Adjust the job processing order using a Payload sort string. This can be set globally or per queue.\n *\n * FIFO would equal `createdAt` and LIFO would equal `-createdAt`.\n *\n * @default all jobs for all queues will be executed in FIFO order.\n */\n processingOrder?:\n | ((args: RunJobsArgs) => Promise<Sort> | Sort)\n | {\n default?: Sort\n queues: {\n [queue: string]: Sort\n }\n }\n | Sort\n /**\n * By default, the job system uses direct database calls for optimal performance.\n * If you added custom hooks to your jobs collection, you can set this to true to\n * use the standard Payload API for all job operations. This is discouraged, as it will\n * drastically affect performance.\n *\n * @default false\n * @deprecated - this will be removed in 4.0\n */\n runHooks?: boolean\n /**\n * A function that will be executed before Payload picks up jobs which are configured by the `jobs.autorun` function.\n * If this function returns true, jobs will be queried and picked up. If it returns false, jobs will not be run.\n * @default undefined - if this function is not defined, jobs will be run - as if () => true was passed.\n * @param payload\n * @returns boolean\n */\n shouldAutoRun?: (payload: Payload) => MaybePromise<boolean>\n /**\n * Define all possible tasks here\n */\n tasks?: TaskConfig<any>[]\n /**\n * Define all the workflows here. Workflows orchestrate the flow of multiple tasks.\n */\n workflows?: WorkflowConfig<any>[]\n}\n\nexport type Queueable = {\n scheduleConfig: ScheduleConfig\n taskConfig?: TaskConfig\n // If not set, queue it immediately\n waitUntil?: Date\n workflowConfig?: WorkflowConfig\n}\n\nexport type BeforeScheduleFn = (args: {\n defaultBeforeSchedule: BeforeScheduleFn\n /**\n * payload-job-stats global data\n */\n jobStats: JobStats\n queueable: Queueable\n req: PayloadRequest\n}) => MaybePromise<{\n input?: object\n shouldSchedule: boolean\n waitUntil?: Date\n}>\n\nexport type AfterScheduleFn = (\n args: {\n defaultAfterSchedule: AfterScheduleFn\n /**\n * payload-job-stats global data. If the global does not exist, it will be null.\n */\n jobStats: JobStats | null\n queueable: Queueable\n req: PayloadRequest\n } & (\n | {\n error: Error\n job?: never\n status: 'error'\n }\n | {\n error?: never\n job: Job\n status: 'success'\n }\n | {\n error?: never\n job?: never\n /**\n * If the beforeSchedule hook returned `shouldSchedule: false`, this will be called with status `skipped`.\n */\n status: 'skipped'\n }\n ),\n) => MaybePromise<void>\n\nexport type ScheduleConfig = {\n /**\n * The cron for scheduling the job.\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron: string\n hooks?: {\n /**\n * Functions that will be executed after the job has been successfully scheduled.\n *\n * @default By default, global update?? Unless global update should happen before\n */\n afterSchedule?: AfterScheduleFn\n /**\n * Functions that will be executed before the job is scheduled.\n * You can use this to control whether or not the job should be scheduled, or what input\n * data should be passed to the job.\n *\n * @default By default, this has one function that returns { shouldSchedule: true } if the following conditions are met:\n * - There currently is no job of the same type in the specified queue that is currently running\n * - There currently is no job of the same type in the specified queue that is scheduled to run in the future\n * - There currently is no job of the same type in the specified queue that failed previously but can be retried\n */\n beforeSchedule?: BeforeScheduleFn\n }\n /**\n * Queue to which the scheduled job will be added.\n */\n queue: string\n}\n"],"names":[],"mappings":"AAwQA,WA4CC"}
@@ -1 +1 @@
1
- {"version":3,"file":"handleSchedules.d.ts","sourceRoot":"","sources":["../../../src/queues/endpoints/handleSchedules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAKrD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,EAAE,QA8DzC,CAAA"}
1
+ {"version":3,"file":"handleSchedules.d.ts","sourceRoot":"","sources":["../../../src/queues/endpoints/handleSchedules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAMrD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,EAAE,QA8DzC,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { defaultAccess } from '../../auth/defaultAccess.js';
1
2
  import { handleSchedules } from '../operations/handleSchedules/index.js';
2
3
  import { configHasJobs } from './run.js';
3
4
  /**
@@ -14,7 +15,7 @@ import { configHasJobs } from './run.js';
14
15
  status: 200
15
16
  });
16
17
  }
17
- const accessFn = jobsConfig.access?.run ?? (()=>true);
18
+ const accessFn = jobsConfig.access?.run ?? defaultAccess;
18
19
  const hasAccess = await accessFn({
19
20
  req
20
21
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/endpoints/handleSchedules.ts"],"sourcesContent":["import type { Endpoint } from '../../config/types.js'\n\nimport { handleSchedules } from '../operations/handleSchedules/index.js'\nimport { configHasJobs } from './run.js'\n\n/**\n * GET /api/payload-jobs/handle-schedules endpoint\n *\n * This endpoint is GET instead of POST to allow it to be used in a Vercel Cron.\n */\nexport const handleSchedulesJobsEndpoint: Endpoint = {\n handler: async (req) => {\n const jobsConfig = req.payload.config.jobs\n\n if (!configHasJobs(jobsConfig)) {\n return Response.json(\n {\n message: 'No jobs to schedule.',\n },\n { status: 200 },\n )\n }\n\n const accessFn = jobsConfig.access?.run ?? (() => true)\n\n const hasAccess = await accessFn({ req })\n\n if (!hasAccess) {\n return Response.json(\n {\n message: req.i18n.t('error:unauthorized'),\n },\n { status: 401 },\n )\n }\n\n if (!jobsConfig.scheduling) {\n // There is no reason to call the handleSchedules endpoint if the stats global is not enabled (= no schedules defined)\n return Response.json(\n {\n message:\n 'Cannot handle schedules because no tasks or workflows with schedules are defined.',\n },\n { status: 500 },\n )\n }\n\n const { allQueues, queue } = req.query as {\n allQueues?: 'false' | 'true'\n queue?: string\n }\n\n const runAllQueues = allQueues && !(typeof allQueues === 'string' && allQueues === 'false')\n\n const { errored, queued, skipped } = await handleSchedules({\n allQueues: runAllQueues,\n queue,\n req,\n })\n\n return Response.json(\n {\n errored,\n message: req.i18n.t('general:success'),\n queued,\n skipped,\n },\n { status: 200 },\n )\n },\n method: 'get',\n path: '/handle-schedules',\n}\n"],"names":["handleSchedules","configHasJobs","handleSchedulesJobsEndpoint","handler","req","jobsConfig","payload","config","jobs","Response","json","message","status","accessFn","access","run","hasAccess","i18n","t","scheduling","allQueues","queue","query","runAllQueues","errored","queued","skipped","method","path"],"mappings":"AAEA,SAASA,eAAe,QAAQ,yCAAwC;AACxE,SAASC,aAAa,QAAQ,WAAU;AAExC;;;;CAIC,GACD,OAAO,MAAMC,8BAAwC;IACnDC,SAAS,OAAOC;QACd,MAAMC,aAAaD,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI;QAE1C,IAAI,CAACP,cAAcI,aAAa;YAC9B,OAAOI,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAMC,WAAWR,WAAWS,MAAM,EAAEC,OAAQ,CAAA,IAAM,IAAG;QAErD,MAAMC,YAAY,MAAMH,SAAS;YAAET;QAAI;QAEvC,IAAI,CAACY,WAAW;YACd,OAAOP,SAASC,IAAI,CAClB;gBACEC,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACtB,GACA;gBAAEN,QAAQ;YAAI;QAElB;QAEA,IAAI,CAACP,WAAWc,UAAU,EAAE;YAC1B,sHAAsH;YACtH,OAAOV,SAASC,IAAI,CAClB;gBACEC,SACE;YACJ,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAM,EAAEQ,SAAS,EAAEC,KAAK,EAAE,GAAGjB,IAAIkB,KAAK;QAKtC,MAAMC,eAAeH,aAAa,CAAE,CAAA,OAAOA,cAAc,YAAYA,cAAc,OAAM;QAEzF,MAAM,EAAEI,OAAO,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAM1B,gBAAgB;YACzDoB,WAAWG;YACXF;YACAjB;QACF;QAEA,OAAOK,SAASC,IAAI,CAClB;YACEc;YACAb,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACpBO;YACAC;QACF,GACA;YAAEd,QAAQ;QAAI;IAElB;IACAe,QAAQ;IACRC,MAAM;AACR,EAAC"}
1
+ {"version":3,"sources":["../../../src/queues/endpoints/handleSchedules.ts"],"sourcesContent":["import type { Endpoint } from '../../config/types.js'\n\nimport { defaultAccess } from '../../auth/defaultAccess.js'\nimport { handleSchedules } from '../operations/handleSchedules/index.js'\nimport { configHasJobs } from './run.js'\n\n/**\n * GET /api/payload-jobs/handle-schedules endpoint\n *\n * This endpoint is GET instead of POST to allow it to be used in a Vercel Cron.\n */\nexport const handleSchedulesJobsEndpoint: Endpoint = {\n handler: async (req) => {\n const jobsConfig = req.payload.config.jobs\n\n if (!configHasJobs(jobsConfig)) {\n return Response.json(\n {\n message: 'No jobs to schedule.',\n },\n { status: 200 },\n )\n }\n\n const accessFn = jobsConfig.access?.run ?? defaultAccess\n\n const hasAccess = await accessFn({ req })\n\n if (!hasAccess) {\n return Response.json(\n {\n message: req.i18n.t('error:unauthorized'),\n },\n { status: 401 },\n )\n }\n\n if (!jobsConfig.scheduling) {\n // There is no reason to call the handleSchedules endpoint if the stats global is not enabled (= no schedules defined)\n return Response.json(\n {\n message:\n 'Cannot handle schedules because no tasks or workflows with schedules are defined.',\n },\n { status: 500 },\n )\n }\n\n const { allQueues, queue } = req.query as {\n allQueues?: 'false' | 'true'\n queue?: string\n }\n\n const runAllQueues = allQueues && !(typeof allQueues === 'string' && allQueues === 'false')\n\n const { errored, queued, skipped } = await handleSchedules({\n allQueues: runAllQueues,\n queue,\n req,\n })\n\n return Response.json(\n {\n errored,\n message: req.i18n.t('general:success'),\n queued,\n skipped,\n },\n { status: 200 },\n )\n },\n method: 'get',\n path: '/handle-schedules',\n}\n"],"names":["defaultAccess","handleSchedules","configHasJobs","handleSchedulesJobsEndpoint","handler","req","jobsConfig","payload","config","jobs","Response","json","message","status","accessFn","access","run","hasAccess","i18n","t","scheduling","allQueues","queue","query","runAllQueues","errored","queued","skipped","method","path"],"mappings":"AAEA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,eAAe,QAAQ,yCAAwC;AACxE,SAASC,aAAa,QAAQ,WAAU;AAExC;;;;CAIC,GACD,OAAO,MAAMC,8BAAwC;IACnDC,SAAS,OAAOC;QACd,MAAMC,aAAaD,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI;QAE1C,IAAI,CAACP,cAAcI,aAAa;YAC9B,OAAOI,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAMC,WAAWR,WAAWS,MAAM,EAAEC,OAAOhB;QAE3C,MAAMiB,YAAY,MAAMH,SAAS;YAAET;QAAI;QAEvC,IAAI,CAACY,WAAW;YACd,OAAOP,SAASC,IAAI,CAClB;gBACEC,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACtB,GACA;gBAAEN,QAAQ;YAAI;QAElB;QAEA,IAAI,CAACP,WAAWc,UAAU,EAAE;YAC1B,sHAAsH;YACtH,OAAOV,SAASC,IAAI,CAClB;gBACEC,SACE;YACJ,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAM,EAAEQ,SAAS,EAAEC,KAAK,EAAE,GAAGjB,IAAIkB,KAAK;QAKtC,MAAMC,eAAeH,aAAa,CAAE,CAAA,OAAOA,cAAc,YAAYA,cAAc,OAAM;QAEzF,MAAM,EAAEI,OAAO,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAM1B,gBAAgB;YACzDoB,WAAWG;YACXF;YACAjB;QACF;QAEA,OAAOK,SAASC,IAAI,CAClB;YACEc;YACAb,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACpBO;YACAC;QACF,GACA;YAAEd,QAAQ;QAAI;IAElB;IACAe,QAAQ;IACRC,MAAM;AACR,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/queues/endpoints/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAInE;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAmG7B,CAAA;AAED,eAAO,MAAM,aAAa,eAAgB,mBAAmB,KAAG,OAE/D,CAAA"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/queues/endpoints/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAKnE;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAmG7B,CAAA;AAED,eAAO,MAAM,aAAa,eAAgB,mBAAmB,KAAG,OAE/D,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { defaultAccess } from '../../auth/defaultAccess.js';
1
2
  import { runJobs } from '../operations/runJobs/index.js';
2
3
  /**
3
4
  * /api/payload-jobs/run endpoint
@@ -13,7 +14,7 @@ import { runJobs } from '../operations/runJobs/index.js';
13
14
  status: 200
14
15
  });
15
16
  }
16
- const accessFn = jobsConfig.access?.run ?? (()=>true);
17
+ const accessFn = jobsConfig.access?.run ?? defaultAccess;
17
18
  const hasAccess = await accessFn({
18
19
  req
19
20
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/endpoints/run.ts"],"sourcesContent":["import type { Endpoint } from '../../config/types.js'\nimport type { SanitizedJobsConfig } from '../config/types/index.js'\n\nimport { runJobs, type RunJobsArgs } from '../operations/runJobs/index.js'\n\n/**\n * /api/payload-jobs/run endpoint\n *\n * This endpoint is GET instead of POST to allow it to be used in a Vercel Cron.\n */\nexport const runJobsEndpoint: Endpoint = {\n handler: async (req) => {\n const jobsConfig = req.payload.config.jobs\n\n if (!configHasJobs(jobsConfig)) {\n return Response.json(\n {\n message: 'No jobs to run.',\n },\n { status: 200 },\n )\n }\n\n const accessFn = jobsConfig.access?.run ?? (() => true)\n\n const hasAccess = await accessFn({ req })\n\n if (!hasAccess) {\n return Response.json(\n {\n message: req.i18n.t('error:unauthorized'),\n },\n { status: 401 },\n )\n }\n\n const {\n allQueues,\n disableScheduling: disableSchedulingParam,\n limit,\n queue,\n silent: silentParam,\n } = req.query as {\n allQueues?: 'false' | 'true'\n disableScheduling?: 'false' | 'true'\n limit?: number\n queue?: string\n silent?: string\n }\n\n const silent = silentParam === 'true'\n\n const shouldHandleSchedules = disableSchedulingParam !== 'true'\n\n const runAllQueues = allQueues && !(typeof allQueues === 'string' && allQueues === 'false')\n\n if (shouldHandleSchedules && jobsConfig.scheduling) {\n // If should handle schedules and schedules are defined\n await req.payload.jobs.handleSchedules({ allQueues: runAllQueues, queue, req })\n }\n\n const runJobsArgs: RunJobsArgs = {\n queue,\n req,\n // Access is validated above, so it's safe to override here\n allQueues: runAllQueues,\n overrideAccess: true,\n silent,\n }\n\n const parsedLimit = Number(limit)\n if (!isNaN(parsedLimit)) {\n runJobsArgs.limit = parsedLimit\n }\n\n let noJobsRemaining = false\n let remainingJobsFromQueried = 0\n try {\n const result = await runJobs(runJobsArgs)\n noJobsRemaining = !!result.noJobsRemaining\n remainingJobsFromQueried = result.remainingJobsFromQueried\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: 'There was an error running jobs:',\n queue: runJobsArgs.queue,\n })\n\n return Response.json(\n {\n message: req.i18n.t('error:unknown'),\n noJobsRemaining: true,\n remainingJobsFromQueried,\n },\n { status: 500 },\n )\n }\n\n return Response.json(\n {\n message: req.i18n.t('general:success'),\n noJobsRemaining,\n remainingJobsFromQueried,\n },\n { status: 200 },\n )\n },\n method: 'get',\n path: '/run',\n}\n\nexport const configHasJobs = (jobsConfig: SanitizedJobsConfig): boolean => {\n return Boolean(jobsConfig.tasks?.length || jobsConfig.workflows?.length)\n}\n"],"names":["runJobs","runJobsEndpoint","handler","req","jobsConfig","payload","config","jobs","configHasJobs","Response","json","message","status","accessFn","access","run","hasAccess","i18n","t","allQueues","disableScheduling","disableSchedulingParam","limit","queue","silent","silentParam","query","shouldHandleSchedules","runAllQueues","scheduling","handleSchedules","runJobsArgs","overrideAccess","parsedLimit","Number","isNaN","noJobsRemaining","remainingJobsFromQueried","result","err","logger","error","msg","method","path","Boolean","tasks","length","workflows"],"mappings":"AAGA,SAASA,OAAO,QAA0B,iCAAgC;AAE1E;;;;CAIC,GACD,OAAO,MAAMC,kBAA4B;IACvCC,SAAS,OAAOC;QACd,MAAMC,aAAaD,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI;QAE1C,IAAI,CAACC,cAAcJ,aAAa;YAC9B,OAAOK,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAMC,WAAWT,WAAWU,MAAM,EAAEC,OAAQ,CAAA,IAAM,IAAG;QAErD,MAAMC,YAAY,MAAMH,SAAS;YAAEV;QAAI;QAEvC,IAAI,CAACa,WAAW;YACd,OAAOP,SAASC,IAAI,CAClB;gBACEC,SAASR,IAAIc,IAAI,CAACC,CAAC,CAAC;YACtB,GACA;gBAAEN,QAAQ;YAAI;QAElB;QAEA,MAAM,EACJO,SAAS,EACTC,mBAAmBC,sBAAsB,EACzCC,KAAK,EACLC,KAAK,EACLC,QAAQC,WAAW,EACpB,GAAGtB,IAAIuB,KAAK;QAQb,MAAMF,SAASC,gBAAgB;QAE/B,MAAME,wBAAwBN,2BAA2B;QAEzD,MAAMO,eAAeT,aAAa,CAAE,CAAA,OAAOA,cAAc,YAAYA,cAAc,OAAM;QAEzF,IAAIQ,yBAAyBvB,WAAWyB,UAAU,EAAE;YAClD,uDAAuD;YACvD,MAAM1B,IAAIE,OAAO,CAACE,IAAI,CAACuB,eAAe,CAAC;gBAAEX,WAAWS;gBAAcL;gBAAOpB;YAAI;QAC/E;QAEA,MAAM4B,cAA2B;YAC/BR;YACApB;YACA,2DAA2D;YAC3DgB,WAAWS;YACXI,gBAAgB;YAChBR;QACF;QAEA,MAAMS,cAAcC,OAAOZ;QAC3B,IAAI,CAACa,MAAMF,cAAc;YACvBF,YAAYT,KAAK,GAAGW;QACtB;QAEA,IAAIG,kBAAkB;QACtB,IAAIC,2BAA2B;QAC/B,IAAI;YACF,MAAMC,SAAS,MAAMtC,QAAQ+B;YAC7BK,kBAAkB,CAAC,CAACE,OAAOF,eAAe;YAC1CC,2BAA2BC,OAAOD,wBAAwB;QAC5D,EAAE,OAAOE,KAAK;YACZpC,IAAIE,OAAO,CAACmC,MAAM,CAACC,KAAK,CAAC;gBACvBF;gBACAG,KAAK;gBACLnB,OAAOQ,YAAYR,KAAK;YAC1B;YAEA,OAAOd,SAASC,IAAI,CAClB;gBACEC,SAASR,IAAIc,IAAI,CAACC,CAAC,CAAC;gBACpBkB,iBAAiB;gBACjBC;YACF,GACA;gBAAEzB,QAAQ;YAAI;QAElB;QAEA,OAAOH,SAASC,IAAI,CAClB;YACEC,SAASR,IAAIc,IAAI,CAACC,CAAC,CAAC;YACpBkB;YACAC;QACF,GACA;YAAEzB,QAAQ;QAAI;IAElB;IACA+B,QAAQ;IACRC,MAAM;AACR,EAAC;AAED,OAAO,MAAMpC,gBAAgB,CAACJ;IAC5B,OAAOyC,QAAQzC,WAAW0C,KAAK,EAAEC,UAAU3C,WAAW4C,SAAS,EAAED;AACnE,EAAC"}
1
+ {"version":3,"sources":["../../../src/queues/endpoints/run.ts"],"sourcesContent":["import type { Endpoint } from '../../config/types.js'\nimport type { SanitizedJobsConfig } from '../config/types/index.js'\n\nimport { defaultAccess } from '../../auth/defaultAccess.js'\nimport { runJobs, type RunJobsArgs } from '../operations/runJobs/index.js'\n\n/**\n * /api/payload-jobs/run endpoint\n *\n * This endpoint is GET instead of POST to allow it to be used in a Vercel Cron.\n */\nexport const runJobsEndpoint: Endpoint = {\n handler: async (req) => {\n const jobsConfig = req.payload.config.jobs\n\n if (!configHasJobs(jobsConfig)) {\n return Response.json(\n {\n message: 'No jobs to run.',\n },\n { status: 200 },\n )\n }\n\n const accessFn = jobsConfig.access?.run ?? defaultAccess\n\n const hasAccess = await accessFn({ req })\n\n if (!hasAccess) {\n return Response.json(\n {\n message: req.i18n.t('error:unauthorized'),\n },\n { status: 401 },\n )\n }\n\n const {\n allQueues,\n disableScheduling: disableSchedulingParam,\n limit,\n queue,\n silent: silentParam,\n } = req.query as {\n allQueues?: 'false' | 'true'\n disableScheduling?: 'false' | 'true'\n limit?: number\n queue?: string\n silent?: string\n }\n\n const silent = silentParam === 'true'\n\n const shouldHandleSchedules = disableSchedulingParam !== 'true'\n\n const runAllQueues = allQueues && !(typeof allQueues === 'string' && allQueues === 'false')\n\n if (shouldHandleSchedules && jobsConfig.scheduling) {\n // If should handle schedules and schedules are defined\n await req.payload.jobs.handleSchedules({ allQueues: runAllQueues, queue, req })\n }\n\n const runJobsArgs: RunJobsArgs = {\n queue,\n req,\n // Access is validated above, so it's safe to override here\n allQueues: runAllQueues,\n overrideAccess: true,\n silent,\n }\n\n const parsedLimit = Number(limit)\n if (!isNaN(parsedLimit)) {\n runJobsArgs.limit = parsedLimit\n }\n\n let noJobsRemaining = false\n let remainingJobsFromQueried = 0\n try {\n const result = await runJobs(runJobsArgs)\n noJobsRemaining = !!result.noJobsRemaining\n remainingJobsFromQueried = result.remainingJobsFromQueried\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: 'There was an error running jobs:',\n queue: runJobsArgs.queue,\n })\n\n return Response.json(\n {\n message: req.i18n.t('error:unknown'),\n noJobsRemaining: true,\n remainingJobsFromQueried,\n },\n { status: 500 },\n )\n }\n\n return Response.json(\n {\n message: req.i18n.t('general:success'),\n noJobsRemaining,\n remainingJobsFromQueried,\n },\n { status: 200 },\n )\n },\n method: 'get',\n path: '/run',\n}\n\nexport const configHasJobs = (jobsConfig: SanitizedJobsConfig): boolean => {\n return Boolean(jobsConfig.tasks?.length || jobsConfig.workflows?.length)\n}\n"],"names":["defaultAccess","runJobs","runJobsEndpoint","handler","req","jobsConfig","payload","config","jobs","configHasJobs","Response","json","message","status","accessFn","access","run","hasAccess","i18n","t","allQueues","disableScheduling","disableSchedulingParam","limit","queue","silent","silentParam","query","shouldHandleSchedules","runAllQueues","scheduling","handleSchedules","runJobsArgs","overrideAccess","parsedLimit","Number","isNaN","noJobsRemaining","remainingJobsFromQueried","result","err","logger","error","msg","method","path","Boolean","tasks","length","workflows"],"mappings":"AAGA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,OAAO,QAA0B,iCAAgC;AAE1E;;;;CAIC,GACD,OAAO,MAAMC,kBAA4B;IACvCC,SAAS,OAAOC;QACd,MAAMC,aAAaD,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI;QAE1C,IAAI,CAACC,cAAcJ,aAAa;YAC9B,OAAOK,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAMC,WAAWT,WAAWU,MAAM,EAAEC,OAAOhB;QAE3C,MAAMiB,YAAY,MAAMH,SAAS;YAAEV;QAAI;QAEvC,IAAI,CAACa,WAAW;YACd,OAAOP,SAASC,IAAI,CAClB;gBACEC,SAASR,IAAIc,IAAI,CAACC,CAAC,CAAC;YACtB,GACA;gBAAEN,QAAQ;YAAI;QAElB;QAEA,MAAM,EACJO,SAAS,EACTC,mBAAmBC,sBAAsB,EACzCC,KAAK,EACLC,KAAK,EACLC,QAAQC,WAAW,EACpB,GAAGtB,IAAIuB,KAAK;QAQb,MAAMF,SAASC,gBAAgB;QAE/B,MAAME,wBAAwBN,2BAA2B;QAEzD,MAAMO,eAAeT,aAAa,CAAE,CAAA,OAAOA,cAAc,YAAYA,cAAc,OAAM;QAEzF,IAAIQ,yBAAyBvB,WAAWyB,UAAU,EAAE;YAClD,uDAAuD;YACvD,MAAM1B,IAAIE,OAAO,CAACE,IAAI,CAACuB,eAAe,CAAC;gBAAEX,WAAWS;gBAAcL;gBAAOpB;YAAI;QAC/E;QAEA,MAAM4B,cAA2B;YAC/BR;YACApB;YACA,2DAA2D;YAC3DgB,WAAWS;YACXI,gBAAgB;YAChBR;QACF;QAEA,MAAMS,cAAcC,OAAOZ;QAC3B,IAAI,CAACa,MAAMF,cAAc;YACvBF,YAAYT,KAAK,GAAGW;QACtB;QAEA,IAAIG,kBAAkB;QACtB,IAAIC,2BAA2B;QAC/B,IAAI;YACF,MAAMC,SAAS,MAAMtC,QAAQ+B;YAC7BK,kBAAkB,CAAC,CAACE,OAAOF,eAAe;YAC1CC,2BAA2BC,OAAOD,wBAAwB;QAC5D,EAAE,OAAOE,KAAK;YACZpC,IAAIE,OAAO,CAACmC,MAAM,CAACC,KAAK,CAAC;gBACvBF;gBACAG,KAAK;gBACLnB,OAAOQ,YAAYR,KAAK;YAC1B;YAEA,OAAOd,SAASC,IAAI,CAClB;gBACEC,SAASR,IAAIc,IAAI,CAACC,CAAC,CAAC;gBACpBkB,iBAAiB;gBACjBC;YACF,GACA;gBAAEzB,QAAQ;YAAI;QAElB;QAEA,OAAOH,SAASC,IAAI,CAClB;YACEC,SAASR,IAAIc,IAAI,CAACC,CAAC,CAAC;YACpBkB;YACAC;QACF,GACA;YAAEzB,QAAQ;QAAI;IAElB;IACA+B,QAAQ;IACRC,MAAM;AACR,EAAC;AAED,OAAO,MAAMpC,gBAAgB,CAACJ;IAC5B,OAAOyC,QAAQzC,WAAW0C,KAAK,EAAEC,UAAU3C,WAAW4C,SAAS,EAAED;AACnE,EAAC"}
@@ -0,0 +1,9 @@
1
+ import type { SanitizedUploadConfig } from './types.js';
2
+ export declare const HEADER_PROBE_BYTE_LENGTH: number;
3
+ export type FileContentRequirement = 'full' | 'header' | 'none';
4
+ export declare function getFileContentRequirement({ hasSizeEdits, mimeType, uploadConfig, }: {
5
+ hasSizeEdits?: boolean;
6
+ mimeType: string;
7
+ uploadConfig: SanitizedUploadConfig;
8
+ }): FileContentRequirement;
9
+ //# sourceMappingURL=getFileContentRequirement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFileContentRequirement.d.ts","sourceRoot":"","sources":["../../src/uploads/getFileContentRequirement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAMvD,eAAO,MAAM,wBAAwB,QAAc,CAAA;AAEnD,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE/D,wBAAgB,yBAAyB,CAAC,EACxC,YAAY,EACZ,QAAQ,EACR,YAAY,GACb,EAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,qBAAqB,CAAA;CACpC,GAAG,sBAAsB,CAgCzB"}
@@ -0,0 +1,24 @@
1
+ import { canResizeImage } from './canResizeImage.js';
2
+ import { isAnimatedImage } from './isAnimatedImage.js';
3
+ import { isImage } from './isImage.js';
4
+ export const HEADER_PROBE_BYTE_LENGTH = 1024 * 1024;
5
+ export function getFileContentRequirement({ hasSizeEdits, mimeType, uploadConfig }) {
6
+ if (!uploadConfig.disableLocalStorage) {
7
+ return 'full';
8
+ }
9
+ const hasMimeTypeAllowList = !uploadConfig.allowRestrictedFileTypes && Array.isArray(uploadConfig.mimeTypes) && uploadConfig.mimeTypes.length > 0;
10
+ if (hasMimeTypeAllowList) {
11
+ return 'full';
12
+ }
13
+ const isResizableImage = canResizeImage(mimeType);
14
+ const hasConfiguredAdjustments = Boolean(uploadConfig.resizeOptions || uploadConfig.formatOptions || uploadConfig.trimOptions || uploadConfig.constructorOptions || Array.isArray(uploadConfig.imageSizes) && uploadConfig.imageSizes.length > 0);
15
+ if (hasSizeEdits || isResizableImage && hasConfiguredAdjustments || isAnimatedImage(mimeType)) {
16
+ return 'full';
17
+ }
18
+ if (isResizableImage || isImage(mimeType)) {
19
+ return 'header';
20
+ }
21
+ return 'none';
22
+ }
23
+
24
+ //# sourceMappingURL=getFileContentRequirement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/uploads/getFileContentRequirement.ts"],"sourcesContent":["import type { SanitizedUploadConfig } from './types.js'\n\nimport { canResizeImage } from './canResizeImage.js'\nimport { isAnimatedImage } from './isAnimatedImage.js'\nimport { isImage } from './isImage.js'\n\nexport const HEADER_PROBE_BYTE_LENGTH = 1024 * 1024\n\nexport type FileContentRequirement = 'full' | 'header' | 'none'\n\nexport function getFileContentRequirement({\n hasSizeEdits,\n mimeType,\n uploadConfig,\n}: {\n hasSizeEdits?: boolean\n mimeType: string\n uploadConfig: SanitizedUploadConfig\n}): FileContentRequirement {\n if (!uploadConfig.disableLocalStorage) {\n return 'full'\n }\n\n const hasMimeTypeAllowList =\n !uploadConfig.allowRestrictedFileTypes &&\n Array.isArray(uploadConfig.mimeTypes) &&\n uploadConfig.mimeTypes.length > 0\n\n if (hasMimeTypeAllowList) {\n return 'full'\n }\n\n const isResizableImage = canResizeImage(mimeType)\n const hasConfiguredAdjustments = Boolean(\n uploadConfig.resizeOptions ||\n uploadConfig.formatOptions ||\n uploadConfig.trimOptions ||\n uploadConfig.constructorOptions ||\n (Array.isArray(uploadConfig.imageSizes) && uploadConfig.imageSizes.length > 0),\n )\n\n if (hasSizeEdits || (isResizableImage && hasConfiguredAdjustments) || isAnimatedImage(mimeType)) {\n return 'full'\n }\n\n if (isResizableImage || isImage(mimeType)) {\n return 'header'\n }\n\n return 'none'\n}\n"],"names":["canResizeImage","isAnimatedImage","isImage","HEADER_PROBE_BYTE_LENGTH","getFileContentRequirement","hasSizeEdits","mimeType","uploadConfig","disableLocalStorage","hasMimeTypeAllowList","allowRestrictedFileTypes","Array","isArray","mimeTypes","length","isResizableImage","hasConfiguredAdjustments","Boolean","resizeOptions","formatOptions","trimOptions","constructorOptions","imageSizes"],"mappings":"AAEA,SAASA,cAAc,QAAQ,sBAAqB;AACpD,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,OAAO,QAAQ,eAAc;AAEtC,OAAO,MAAMC,2BAA2B,OAAO,KAAI;AAInD,OAAO,SAASC,0BAA0B,EACxCC,YAAY,EACZC,QAAQ,EACRC,YAAY,EAKb;IACC,IAAI,CAACA,aAAaC,mBAAmB,EAAE;QACrC,OAAO;IACT;IAEA,MAAMC,uBACJ,CAACF,aAAaG,wBAAwB,IACtCC,MAAMC,OAAO,CAACL,aAAaM,SAAS,KACpCN,aAAaM,SAAS,CAACC,MAAM,GAAG;IAElC,IAAIL,sBAAsB;QACxB,OAAO;IACT;IAEA,MAAMM,mBAAmBf,eAAeM;IACxC,MAAMU,2BAA2BC,QAC/BV,aAAaW,aAAa,IACxBX,aAAaY,aAAa,IAC1BZ,aAAaa,WAAW,IACxBb,aAAac,kBAAkB,IAC9BV,MAAMC,OAAO,CAACL,aAAae,UAAU,KAAKf,aAAae,UAAU,CAACR,MAAM,GAAG;IAGhF,IAAIT,gBAAiBU,oBAAoBC,4BAA6Bf,gBAAgBK,WAAW;QAC/F,OAAO;IACT;IAEA,IAAIS,oBAAoBb,QAAQI,WAAW;QACzC,OAAO;IACT;IAEA,OAAO;AACT"}
@@ -0,0 +1,95 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { getFileContentRequirement } from './getFileContentRequirement.js';
3
+ describe('getFileContentRequirement', ()=>{
4
+ it.each([
5
+ {
6
+ expected: 'full',
7
+ mimeType: 'video/mp4',
8
+ upload: {
9
+ disableLocalStorage: false
10
+ }
11
+ },
12
+ {
13
+ expected: 'full',
14
+ mimeType: 'video/mp4',
15
+ upload: {
16
+ disableLocalStorage: true,
17
+ mimeTypes: [
18
+ 'video/*'
19
+ ]
20
+ }
21
+ },
22
+ {
23
+ expected: 'none',
24
+ mimeType: 'video/mp4',
25
+ upload: {
26
+ disableLocalStorage: true
27
+ }
28
+ },
29
+ {
30
+ expected: 'header',
31
+ mimeType: 'image/png',
32
+ upload: {
33
+ disableLocalStorage: true
34
+ }
35
+ },
36
+ {
37
+ expected: 'full',
38
+ mimeType: 'image/png',
39
+ upload: {
40
+ disableLocalStorage: true,
41
+ resizeOptions: {
42
+ width: 100
43
+ }
44
+ }
45
+ },
46
+ {
47
+ expected: 'full',
48
+ mimeType: 'image/png',
49
+ upload: {
50
+ disableLocalStorage: true,
51
+ imageSizes: [
52
+ {
53
+ name: 'thumb',
54
+ width: 100
55
+ }
56
+ ]
57
+ }
58
+ },
59
+ {
60
+ expected: 'full',
61
+ mimeType: 'image/gif',
62
+ upload: {
63
+ disableLocalStorage: true
64
+ }
65
+ }
66
+ ])('returns $expected for $mimeType and $upload', ({ expected, mimeType, upload })=>{
67
+ expect(getFileContentRequirement({
68
+ mimeType,
69
+ uploadConfig: upload
70
+ })).toBe(expected);
71
+ });
72
+ it('requires full content when the request includes crop or size edits', ()=>{
73
+ expect(getFileContentRequirement({
74
+ hasSizeEdits: true,
75
+ mimeType: 'image/png',
76
+ uploadConfig: {
77
+ disableLocalStorage: true
78
+ }
79
+ })).toBe('full');
80
+ });
81
+ it('returns none for a restricted-type-allowed non-image when mimeTypes validation is bypassed', ()=>{
82
+ expect(getFileContentRequirement({
83
+ mimeType: 'video/mp4',
84
+ uploadConfig: {
85
+ allowRestrictedFileTypes: true,
86
+ disableLocalStorage: true,
87
+ mimeTypes: [
88
+ 'video/*'
89
+ ]
90
+ }
91
+ })).toBe('none');
92
+ });
93
+ });
94
+
95
+ //# sourceMappingURL=getFileContentRequirement.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/uploads/getFileContentRequirement.spec.ts"],"sourcesContent":["import type { SanitizedUploadConfig } from './types.js'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { getFileContentRequirement } from './getFileContentRequirement.js'\n\ndescribe('getFileContentRequirement', () => {\n it.each([\n { expected: 'full', mimeType: 'video/mp4', upload: { disableLocalStorage: false } },\n {\n expected: 'full',\n mimeType: 'video/mp4',\n upload: { disableLocalStorage: true, mimeTypes: ['video/*'] },\n },\n { expected: 'none', mimeType: 'video/mp4', upload: { disableLocalStorage: true } },\n { expected: 'header', mimeType: 'image/png', upload: { disableLocalStorage: true } },\n {\n expected: 'full',\n mimeType: 'image/png',\n upload: { disableLocalStorage: true, resizeOptions: { width: 100 } },\n },\n {\n expected: 'full',\n mimeType: 'image/png',\n upload: { disableLocalStorage: true, imageSizes: [{ name: 'thumb', width: 100 }] },\n },\n { expected: 'full', mimeType: 'image/gif', upload: { disableLocalStorage: true } },\n ])('returns $expected for $mimeType and $upload', ({ expected, mimeType, upload }) => {\n expect(\n getFileContentRequirement({\n mimeType,\n uploadConfig: upload as SanitizedUploadConfig,\n }),\n ).toBe(expected)\n })\n\n it('requires full content when the request includes crop or size edits', () => {\n expect(\n getFileContentRequirement({\n hasSizeEdits: true,\n mimeType: 'image/png',\n uploadConfig: { disableLocalStorage: true } as SanitizedUploadConfig,\n }),\n ).toBe('full')\n })\n\n it('returns none for a restricted-type-allowed non-image when mimeTypes validation is bypassed', () => {\n expect(\n getFileContentRequirement({\n mimeType: 'video/mp4',\n uploadConfig: {\n allowRestrictedFileTypes: true,\n disableLocalStorage: true,\n mimeTypes: ['video/*'],\n } as SanitizedUploadConfig,\n }),\n ).toBe('none')\n })\n})\n"],"names":["describe","expect","it","getFileContentRequirement","each","expected","mimeType","upload","disableLocalStorage","mimeTypes","resizeOptions","width","imageSizes","name","uploadConfig","toBe","hasSizeEdits","allowRestrictedFileTypes"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1EH,SAAS,6BAA6B;IACpCE,GAAGE,IAAI,CAAC;QACN;YAAEC,UAAU;YAAQC,UAAU;YAAaC,QAAQ;gBAAEC,qBAAqB;YAAM;QAAE;QAClF;YACEH,UAAU;YACVC,UAAU;YACVC,QAAQ;gBAAEC,qBAAqB;gBAAMC,WAAW;oBAAC;iBAAU;YAAC;QAC9D;QACA;YAAEJ,UAAU;YAAQC,UAAU;YAAaC,QAAQ;gBAAEC,qBAAqB;YAAK;QAAE;QACjF;YAAEH,UAAU;YAAUC,UAAU;YAAaC,QAAQ;gBAAEC,qBAAqB;YAAK;QAAE;QACnF;YACEH,UAAU;YACVC,UAAU;YACVC,QAAQ;gBAAEC,qBAAqB;gBAAME,eAAe;oBAAEC,OAAO;gBAAI;YAAE;QACrE;QACA;YACEN,UAAU;YACVC,UAAU;YACVC,QAAQ;gBAAEC,qBAAqB;gBAAMI,YAAY;oBAAC;wBAAEC,MAAM;wBAASF,OAAO;oBAAI;iBAAE;YAAC;QACnF;QACA;YAAEN,UAAU;YAAQC,UAAU;YAAaC,QAAQ;gBAAEC,qBAAqB;YAAK;QAAE;KAClF,EAAE,+CAA+C,CAAC,EAAEH,QAAQ,EAAEC,QAAQ,EAAEC,MAAM,EAAE;QAC/EN,OACEE,0BAA0B;YACxBG;YACAQ,cAAcP;QAChB,IACAQ,IAAI,CAACV;IACT;IAEAH,GAAG,sEAAsE;QACvED,OACEE,0BAA0B;YACxBa,cAAc;YACdV,UAAU;YACVQ,cAAc;gBAAEN,qBAAqB;YAAK;QAC5C,IACAO,IAAI,CAAC;IACT;IAEAb,GAAG,8FAA8F;QAC/FD,OACEE,0BAA0B;YACxBG,UAAU;YACVQ,cAAc;gBACZG,0BAA0B;gBAC1BT,qBAAqB;gBACrBC,WAAW;oBAAC;iBAAU;YACxB;QACF,IACAM,IAAI,CAAC;IACT;AACF"}
@@ -0,0 +1,20 @@
1
+ import type { PayloadRequest } from '../types/index.js';
2
+ export type ClientUploadData = {
3
+ clientUploadContext?: unknown;
4
+ collectionSlug: string;
5
+ filename: string;
6
+ mimeType: string;
7
+ size: number;
8
+ };
9
+ /**
10
+ * `req.context` key `unlinkClientUploadTempFile` reads to find a materializer-created temp file
11
+ * once `req.file` is gone - plugin-cloud-storage's afterChange hook clears `req.file` after
12
+ * uploading generated image sizes, before cleanup runs, so tracking it only on `req.file`
13
+ * would leak the temp file.
14
+ */
15
+ export declare const CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY = "payloadClientUploadTempFilePath";
16
+ export declare function getFileFromClientUpload({ file, req, }: {
17
+ file: ClientUploadData;
18
+ req: PayloadRequest;
19
+ }): Promise<NonNullable<PayloadRequest['file']>>;
20
+ //# sourceMappingURL=getFileFromClientUpload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFileFromClientUpload.d.ts","sourceRoot":"","sources":["../../src/uploads/getFileFromClientUpload.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAQvD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,wCAAwC,oCAAoC,CAAA;AAEzF,wBAAsB,uBAAuB,CAAC,EAC5C,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,gBAAgB,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAgD/C"}
@@ -0,0 +1,199 @@
1
+ import { randomUUID } from 'crypto';
2
+ import fs from 'fs';
3
+ import { mkdir, rm, writeFile } from 'fs/promises';
4
+ import os from 'os';
5
+ import path from 'path';
6
+ import { Readable } from 'stream';
7
+ import { pipeline } from 'stream/promises';
8
+ import { APIError } from '../errors/APIError.js';
9
+ import { isolateObjectProperty } from '../utilities/isolateObjectProperty.js';
10
+ import { getFileContentRequirement, HEADER_PROBE_BYTE_LENGTH } from './getFileContentRequirement.js';
11
+ import { getImageSize } from './getImageSize.js';
12
+ /**
13
+ * `req.context` key `unlinkClientUploadTempFile` reads to find a materializer-created temp file
14
+ * once `req.file` is gone - plugin-cloud-storage's afterChange hook clears `req.file` after
15
+ * uploading generated image sizes, before cleanup runs, so tracking it only on `req.file`
16
+ * would leak the temp file.
17
+ */ export const CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY = 'payloadClientUploadTempFilePath';
18
+ export async function getFileFromClientUpload({ file, req }) {
19
+ const uploadConfig = req.payload.collections[file.collectionSlug]?.config.upload;
20
+ if (!uploadConfig || !uploadConfig.handlers) {
21
+ throw new APIError(`uploadConfig.handlers is not present for ${file.collectionSlug}`);
22
+ }
23
+ const contentRequirement = file.clientUploadContext ? getFileContentRequirement({
24
+ hasSizeEdits: requestHasSizeEdits(req),
25
+ mimeType: file.mimeType,
26
+ uploadConfig
27
+ }) : 'full';
28
+ if (contentRequirement === 'none') {
29
+ return {
30
+ name: file.filename,
31
+ clientUploadContext: file.clientUploadContext,
32
+ data: Buffer.alloc(0),
33
+ mimetype: file.mimeType,
34
+ size: file.size
35
+ };
36
+ }
37
+ if (contentRequirement === 'header') {
38
+ const headerFile = await fetchHeaderOnly({
39
+ file,
40
+ req,
41
+ uploadConfig
42
+ });
43
+ if (headerFile) {
44
+ return headerFile;
45
+ }
46
+ }
47
+ const response = await fetchUploadResponse({
48
+ file,
49
+ req,
50
+ uploadConfig
51
+ });
52
+ const tempFilePath = await streamResponseToTempFile({
53
+ req,
54
+ response
55
+ });
56
+ if (!req.context) {
57
+ req.context = {};
58
+ }
59
+ req.context[CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY] = tempFilePath;
60
+ return {
61
+ name: file.filename,
62
+ clientUploadContext: file.clientUploadContext,
63
+ data: Buffer.alloc(0),
64
+ mimetype: response.headers.get('Content-Type') || file.mimeType,
65
+ size: file.size,
66
+ tempFilePath
67
+ };
68
+ }
69
+ /**
70
+ * Only crop and explicit pixel edits require the original bytes - a focal-point-only
71
+ * change re-derives from data already on the document, not the incoming upload.
72
+ */ function requestHasSizeEdits(req) {
73
+ const uploadEdits = req.query?.uploadEdits && typeof req.query.uploadEdits === 'object' ? req.query.uploadEdits : undefined;
74
+ return Boolean(uploadEdits?.crop || uploadEdits?.heightInPixels || uploadEdits?.widthInPixels);
75
+ }
76
+ /**
77
+ * Runs every configured handler and returns the last one that responds, following a single
78
+ * redirect if that response is one - matching the pre-existing v3 handler contract exactly
79
+ * (v3 always ran every handler; only v4 stops at the first response, via an unrelated PR).
80
+ */ async function fetchUploadResponse({ file, req, uploadConfig }) {
81
+ let response = null;
82
+ let error;
83
+ for (const handler of uploadConfig.handlers){
84
+ try {
85
+ const result = await handler(req, {
86
+ doc: null,
87
+ params: {
88
+ clientUploadContext: file.clientUploadContext,
89
+ collection: file.collectionSlug,
90
+ filename: file.filename
91
+ }
92
+ });
93
+ if (result) {
94
+ response = result;
95
+ }
96
+ // If we couldn't get the file from that handler, save the error and try other.
97
+ } catch (err) {
98
+ error = err;
99
+ }
100
+ }
101
+ if (!response) {
102
+ if (error) {
103
+ req.payload.logger.error(error);
104
+ }
105
+ throw new APIError('Expected response from the upload handler.');
106
+ }
107
+ if (response.status >= 300 && response.status < 400) {
108
+ const redirectUrl = response.headers.get('Location');
109
+ if (redirectUrl) {
110
+ // Forward the Range header (if any) so a redirect from the header-probe path still
111
+ // fetches only the bounded slice, instead of the whole object, from the redirect target.
112
+ const rangeHeader = req.headers.get('Range');
113
+ response = rangeHeader ? await fetch(redirectUrl, {
114
+ headers: {
115
+ Range: rangeHeader
116
+ }
117
+ }) : await fetch(redirectUrl);
118
+ }
119
+ }
120
+ return response;
121
+ }
122
+ /**
123
+ * Requests a bounded byte range from the handlers and probes it for image dimensions, without
124
+ * ever reading past `HEADER_PROBE_BYTE_LENGTH`. Returns `null` when the bounded bytes cannot be
125
+ * probed, so the caller falls back to a full streamed fetch.
126
+ */ async function fetchHeaderOnly({ file, req, uploadConfig }) {
127
+ const rangedHeaders = new Headers(req.headers);
128
+ rangedHeaders.set('Range', `bytes=0-${HEADER_PROBE_BYTE_LENGTH - 1}`);
129
+ const scopedReq = isolateObjectProperty(req, 'headers');
130
+ scopedReq.headers = rangedHeaders;
131
+ const response = await fetchUploadResponse({
132
+ file,
133
+ req: scopedReq,
134
+ uploadConfig
135
+ });
136
+ if (!response.body) {
137
+ return null;
138
+ }
139
+ const reader = response.body.getReader();
140
+ const chunks = [];
141
+ let bytesRead = 0;
142
+ try {
143
+ while(bytesRead < HEADER_PROBE_BYTE_LENGTH){
144
+ const { done, value } = await reader.read();
145
+ if (done || !value) {
146
+ break;
147
+ }
148
+ const remaining = HEADER_PROBE_BYTE_LENGTH - bytesRead;
149
+ const chunk = value.length > remaining ? value.slice(0, remaining) : value;
150
+ chunks.push(chunk);
151
+ bytesRead += chunk.length;
152
+ }
153
+ } finally{
154
+ await reader.cancel().catch(()=>undefined);
155
+ }
156
+ const probedFile = {
157
+ name: file.filename,
158
+ clientUploadContext: file.clientUploadContext,
159
+ data: Buffer.concat(chunks),
160
+ mimetype: response.headers.get('Content-Type') || file.mimeType,
161
+ size: file.size
162
+ };
163
+ try {
164
+ await getImageSize({
165
+ file: probedFile,
166
+ sharp: req.payload.config.sharp
167
+ });
168
+ } catch {
169
+ return null;
170
+ }
171
+ return probedFile;
172
+ }
173
+ /**
174
+ * Streams the full response body straight to disk so a cloud object of unbounded size never
175
+ * becomes a single in-memory Buffer.
176
+ */ async function streamResponseToTempFile({ req, response }) {
177
+ const tempFileDir = req.payload.config.upload?.tempFileDir || os.tmpdir();
178
+ await mkdir(tempFileDir, {
179
+ recursive: true
180
+ });
181
+ const tempFilePath = path.join(tempFileDir, `payload-client-upload-${randomUUID()}`);
182
+ // A null body is a legitimate zero-byte file (the Fetch API allows a Response to omit a
183
+ // body entirely), not a failure - `response.arrayBuffer()` tolerated this the same way.
184
+ if (!response.body) {
185
+ await writeFile(tempFilePath, Buffer.alloc(0));
186
+ return tempFilePath;
187
+ }
188
+ try {
189
+ await pipeline(Readable.fromWeb(response.body), fs.createWriteStream(tempFilePath));
190
+ } catch (error) {
191
+ await rm(tempFilePath, {
192
+ force: true
193
+ });
194
+ throw error;
195
+ }
196
+ return tempFilePath;
197
+ }
198
+
199
+ //# sourceMappingURL=getFileFromClientUpload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/uploads/getFileFromClientUpload.ts"],"sourcesContent":["import { randomUUID } from 'crypto'\nimport fs from 'fs'\nimport { mkdir, rm, writeFile } from 'fs/promises'\nimport os from 'os'\nimport path from 'path'\nimport { Readable } from 'stream'\nimport { pipeline } from 'stream/promises'\n\nimport type { PayloadRequest } from '../types/index.js'\nimport type { SanitizedUploadConfig, UploadEdits } from './types.js'\n\nimport { APIError } from '../errors/APIError.js'\nimport { isolateObjectProperty } from '../utilities/isolateObjectProperty.js'\nimport { getFileContentRequirement, HEADER_PROBE_BYTE_LENGTH } from './getFileContentRequirement.js'\nimport { getImageSize } from './getImageSize.js'\n\nexport type ClientUploadData = {\n clientUploadContext?: unknown\n collectionSlug: string\n filename: string\n mimeType: string\n size: number\n}\n\n/**\n * `req.context` key `unlinkClientUploadTempFile` reads to find a materializer-created temp file\n * once `req.file` is gone - plugin-cloud-storage's afterChange hook clears `req.file` after\n * uploading generated image sizes, before cleanup runs, so tracking it only on `req.file`\n * would leak the temp file.\n */\nexport const CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY = 'payloadClientUploadTempFilePath'\n\nexport async function getFileFromClientUpload({\n file,\n req,\n}: {\n file: ClientUploadData\n req: PayloadRequest\n}): Promise<NonNullable<PayloadRequest['file']>> {\n const uploadConfig = req.payload.collections[file.collectionSlug]?.config.upload\n\n if (!uploadConfig || !uploadConfig.handlers) {\n throw new APIError(`uploadConfig.handlers is not present for ${file.collectionSlug}`)\n }\n\n const contentRequirement = file.clientUploadContext\n ? getFileContentRequirement({\n hasSizeEdits: requestHasSizeEdits(req),\n mimeType: file.mimeType,\n uploadConfig,\n })\n : 'full'\n\n if (contentRequirement === 'none') {\n return {\n name: file.filename,\n clientUploadContext: file.clientUploadContext,\n data: Buffer.alloc(0),\n mimetype: file.mimeType,\n size: file.size,\n }\n }\n\n if (contentRequirement === 'header') {\n const headerFile = await fetchHeaderOnly({ file, req, uploadConfig })\n if (headerFile) {\n return headerFile\n }\n }\n\n const response = await fetchUploadResponse({ file, req, uploadConfig })\n const tempFilePath = await streamResponseToTempFile({ req, response })\n\n if (!req.context) {\n req.context = {}\n }\n req.context[CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY] = tempFilePath\n\n return {\n name: file.filename,\n clientUploadContext: file.clientUploadContext,\n data: Buffer.alloc(0),\n mimetype: response.headers.get('Content-Type') || file.mimeType,\n size: file.size,\n tempFilePath,\n }\n}\n\n/**\n * Only crop and explicit pixel edits require the original bytes - a focal-point-only\n * change re-derives from data already on the document, not the incoming upload.\n */\nfunction requestHasSizeEdits(req: PayloadRequest): boolean {\n const uploadEdits =\n req.query?.uploadEdits && typeof req.query.uploadEdits === 'object'\n ? (req.query.uploadEdits as UploadEdits)\n : undefined\n\n return Boolean(uploadEdits?.crop || uploadEdits?.heightInPixels || uploadEdits?.widthInPixels)\n}\n\n/**\n * Runs every configured handler and returns the last one that responds, following a single\n * redirect if that response is one - matching the pre-existing v3 handler contract exactly\n * (v3 always ran every handler; only v4 stops at the first response, via an unrelated PR).\n */\nasync function fetchUploadResponse({\n file,\n req,\n uploadConfig,\n}: {\n file: ClientUploadData\n req: PayloadRequest\n uploadConfig: SanitizedUploadConfig\n}): Promise<Response> {\n let response: null | Response = null\n let error: unknown\n\n for (const handler of uploadConfig.handlers!) {\n try {\n const result = await handler(req, {\n doc: null!,\n params: {\n clientUploadContext: file.clientUploadContext,\n collection: file.collectionSlug,\n filename: file.filename,\n },\n })\n\n if (result) {\n response = result\n }\n // If we couldn't get the file from that handler, save the error and try other.\n } catch (err) {\n error = err\n }\n }\n\n if (!response) {\n if (error) {\n req.payload.logger.error(error)\n }\n\n throw new APIError('Expected response from the upload handler.')\n }\n\n if (response.status >= 300 && response.status < 400) {\n const redirectUrl = response.headers.get('Location')\n if (redirectUrl) {\n // Forward the Range header (if any) so a redirect from the header-probe path still\n // fetches only the bounded slice, instead of the whole object, from the redirect target.\n const rangeHeader = req.headers.get('Range')\n response = rangeHeader\n ? await fetch(redirectUrl, { headers: { Range: rangeHeader } })\n : await fetch(redirectUrl)\n }\n }\n\n return response\n}\n\n/**\n * Requests a bounded byte range from the handlers and probes it for image dimensions, without\n * ever reading past `HEADER_PROBE_BYTE_LENGTH`. Returns `null` when the bounded bytes cannot be\n * probed, so the caller falls back to a full streamed fetch.\n */\nasync function fetchHeaderOnly({\n file,\n req,\n uploadConfig,\n}: {\n file: ClientUploadData\n req: PayloadRequest\n uploadConfig: SanitizedUploadConfig\n}): Promise<NonNullable<PayloadRequest['file']> | null> {\n const rangedHeaders = new Headers(req.headers)\n rangedHeaders.set('Range', `bytes=0-${HEADER_PROBE_BYTE_LENGTH - 1}`)\n\n const scopedReq = isolateObjectProperty(req, 'headers')\n scopedReq.headers = rangedHeaders\n\n const response = await fetchUploadResponse({ file, req: scopedReq, uploadConfig })\n\n if (!response.body) {\n return null\n }\n\n const reader = response.body.getReader()\n const chunks: Uint8Array[] = []\n let bytesRead = 0\n\n try {\n while (bytesRead < HEADER_PROBE_BYTE_LENGTH) {\n const { done, value } = await reader.read()\n if (done || !value) {\n break\n }\n\n const remaining = HEADER_PROBE_BYTE_LENGTH - bytesRead\n const chunk = value.length > remaining ? value.slice(0, remaining) : value\n\n chunks.push(chunk)\n bytesRead += chunk.length\n }\n } finally {\n await reader.cancel().catch(() => undefined)\n }\n\n const probedFile = {\n name: file.filename,\n clientUploadContext: file.clientUploadContext,\n data: Buffer.concat(chunks),\n mimetype: response.headers.get('Content-Type') || file.mimeType,\n size: file.size,\n }\n\n try {\n await getImageSize({ file: probedFile, sharp: req.payload.config.sharp })\n } catch {\n return null\n }\n\n return probedFile\n}\n\n/**\n * Streams the full response body straight to disk so a cloud object of unbounded size never\n * becomes a single in-memory Buffer.\n */\nasync function streamResponseToTempFile({\n req,\n response,\n}: {\n req: PayloadRequest\n response: Response\n}): Promise<string> {\n const tempFileDir = req.payload.config.upload?.tempFileDir || os.tmpdir()\n await mkdir(tempFileDir, { recursive: true })\n const tempFilePath = path.join(tempFileDir, `payload-client-upload-${randomUUID()}`)\n\n // A null body is a legitimate zero-byte file (the Fetch API allows a Response to omit a\n // body entirely), not a failure - `response.arrayBuffer()` tolerated this the same way.\n if (!response.body) {\n await writeFile(tempFilePath, Buffer.alloc(0))\n return tempFilePath\n }\n\n try {\n await pipeline(\n Readable.fromWeb(response.body as ReadableStream<Uint8Array>),\n fs.createWriteStream(tempFilePath),\n )\n } catch (error) {\n await rm(tempFilePath, { force: true })\n throw error\n }\n\n return tempFilePath\n}\n"],"names":["randomUUID","fs","mkdir","rm","writeFile","os","path","Readable","pipeline","APIError","isolateObjectProperty","getFileContentRequirement","HEADER_PROBE_BYTE_LENGTH","getImageSize","CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY","getFileFromClientUpload","file","req","uploadConfig","payload","collections","collectionSlug","config","upload","handlers","contentRequirement","clientUploadContext","hasSizeEdits","requestHasSizeEdits","mimeType","name","filename","data","Buffer","alloc","mimetype","size","headerFile","fetchHeaderOnly","response","fetchUploadResponse","tempFilePath","streamResponseToTempFile","context","headers","get","uploadEdits","query","undefined","Boolean","crop","heightInPixels","widthInPixels","error","handler","result","doc","params","collection","err","logger","status","redirectUrl","rangeHeader","fetch","Range","rangedHeaders","Headers","set","scopedReq","body","reader","getReader","chunks","bytesRead","done","value","read","remaining","chunk","length","slice","push","cancel","catch","probedFile","concat","sharp","tempFileDir","tmpdir","recursive","join","fromWeb","createWriteStream","force"],"mappings":"AAAA,SAASA,UAAU,QAAQ,SAAQ;AACnC,OAAOC,QAAQ,KAAI;AACnB,SAASC,KAAK,EAAEC,EAAE,EAAEC,SAAS,QAAQ,cAAa;AAClD,OAAOC,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,QAAQ,QAAQ,SAAQ;AACjC,SAASC,QAAQ,QAAQ,kBAAiB;AAK1C,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,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