@payloadcms/plugin-cloud-storage 4.0.0-canary.32 → 4.0.0-canary.34

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 (75) hide show
  1. package/README.md +2 -0
  2. package/dist/exports/client.d.ts +1 -1
  3. package/dist/exports/client.d.ts.map +1 -1
  4. package/dist/exports/client.js +1 -1
  5. package/dist/exports/client.js.map +1 -1
  6. package/dist/exports/utilities.d.ts +1 -1
  7. package/dist/exports/utilities.d.ts.map +1 -1
  8. package/dist/exports/utilities.js +1 -1
  9. package/dist/exports/utilities.js.map +1 -1
  10. package/dist/fields/getFields.d.ts.map +1 -1
  11. package/dist/fields/getFields.js +25 -1
  12. package/dist/fields/getFields.js.map +1 -1
  13. package/dist/hooks/afterChange.d.ts +3 -1
  14. package/dist/hooks/afterChange.d.ts.map +1 -1
  15. package/dist/hooks/afterChange.js +51 -8
  16. package/dist/hooks/afterChange.js.map +1 -1
  17. package/dist/hooks/afterChange.spec.js +95 -0
  18. package/dist/hooks/afterChange.spec.js.map +1 -0
  19. package/dist/hooks/afterDelete.d.ts +3 -1
  20. package/dist/hooks/afterDelete.d.ts.map +1 -1
  21. package/dist/hooks/afterDelete.js +16 -2
  22. package/dist/hooks/afterDelete.js.map +1 -1
  23. package/dist/hooks/afterRead.d.ts.map +1 -1
  24. package/dist/hooks/afterRead.js +15 -2
  25. package/dist/hooks/afterRead.js.map +1 -1
  26. package/dist/hooks/beforeChange.d.ts.map +1 -1
  27. package/dist/hooks/beforeChange.js +12 -1
  28. package/dist/hooks/beforeChange.js.map +1 -1
  29. package/dist/hooks/normalizeUploadPrefix.d.ts +11 -0
  30. package/dist/hooks/normalizeUploadPrefix.d.ts.map +1 -0
  31. package/dist/hooks/normalizeUploadPrefix.js +42 -0
  32. package/dist/hooks/normalizeUploadPrefix.js.map +1 -0
  33. package/dist/hooks/normalizeUploadPrefix.spec.js +154 -0
  34. package/dist/hooks/normalizeUploadPrefix.spec.js.map +1 -0
  35. package/dist/plugin.d.ts.map +1 -1
  36. package/dist/plugin.js +14 -6
  37. package/dist/plugin.js.map +1 -1
  38. package/dist/plugin.spec.js +166 -0
  39. package/dist/plugin.spec.js.map +1 -0
  40. package/dist/types.d.ts +19 -1
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/types.js.map +1 -1
  43. package/dist/utilities/buildPrefixWithObjectKey.d.ts +8 -0
  44. package/dist/utilities/buildPrefixWithObjectKey.d.ts.map +1 -0
  45. package/dist/utilities/buildPrefixWithObjectKey.js +13 -0
  46. package/dist/utilities/buildPrefixWithObjectKey.js.map +1 -0
  47. package/dist/utilities/buildStoragePathData.d.ts +49 -0
  48. package/dist/utilities/buildStoragePathData.d.ts.map +1 -0
  49. package/dist/utilities/buildStoragePathData.js +67 -0
  50. package/dist/utilities/buildStoragePathData.js.map +1 -0
  51. package/dist/utilities/buildStoragePathData.spec.js +241 -0
  52. package/dist/utilities/buildStoragePathData.spec.js.map +1 -0
  53. package/dist/utilities/getFilePrefix.d.ts +18 -10
  54. package/dist/utilities/getFilePrefix.d.ts.map +1 -1
  55. package/dist/utilities/getFilePrefix.js +69 -29
  56. package/dist/utilities/getFilePrefix.js.map +1 -1
  57. package/dist/utilities/getFilePrefix.spec.js +174 -31
  58. package/dist/utilities/getFilePrefix.spec.js.map +1 -1
  59. package/dist/utilities/resolveSignedURLKey.d.ts +12 -1
  60. package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
  61. package/dist/utilities/resolveSignedURLKey.js +42 -8
  62. package/dist/utilities/resolveSignedURLKey.js.map +1 -1
  63. package/dist/utilities/resolveSignedURLKey.spec.js +74 -0
  64. package/dist/utilities/resolveSignedURLKey.spec.js.map +1 -0
  65. package/dist/utilities/sanitizePrefix.d.ts +1 -9
  66. package/dist/utilities/sanitizePrefix.d.ts.map +1 -1
  67. package/dist/utilities/sanitizePrefix.js +1 -21
  68. package/dist/utilities/sanitizePrefix.js.map +1 -1
  69. package/package.json +4 -4
  70. package/dist/utilities/getFileKey.d.ts +0 -22
  71. package/dist/utilities/getFileKey.d.ts.map +0 -1
  72. package/dist/utilities/getFileKey.js +0 -23
  73. package/dist/utilities/getFileKey.js.map +0 -1
  74. package/dist/utilities/getFileKey.spec.js +0 -174
  75. package/dist/utilities/getFileKey.spec.js.map +0 -1
package/dist/types.d.ts CHANGED
@@ -10,11 +10,25 @@ export interface File {
10
10
  export type ClientUploadsConfig = {
11
11
  access?: UploadInstructionsAccess;
12
12
  } | boolean;
13
+ /**
14
+ * Reference to a client-uploaded object, returned by an upload handler and
15
+ * submitted with the document. Always carries the signed receipt; `prefix`
16
+ * locates the stored object.
17
+ */
18
+ export type UploadReference = {
19
+ _objectKey?: string;
20
+ prefix: string;
21
+ signedReceipt: `${string}.${string}`;
22
+ };
13
23
  export type HandleUpload = (args: {
14
24
  collection: CollectionConfig;
15
25
  data: any;
16
26
  file: File;
17
27
  req: PayloadRequest;
28
+ /**
29
+ * Pre-resolved storage path (`_objectKey` folded in, contained beneath the collection prefix).
30
+ */
31
+ storageFilePath: string;
18
32
  }) => Partial<FileData & TypeWithID> | Promise<Partial<FileData & TypeWithID>> | Promise<void> | void;
19
33
  export interface TypeWithPrefix {
20
34
  prefix?: string;
@@ -24,6 +38,10 @@ export type HandleDelete = (args: {
24
38
  doc: FileData & TypeWithID & TypeWithPrefix;
25
39
  filename: string;
26
40
  req: PayloadRequest;
41
+ /**
42
+ * Pre-resolved storage path of the object to delete.
43
+ */
44
+ storageFilePath: string;
27
45
  }) => Promise<void> | void;
28
46
  export type GenerateURL = (args: {
29
47
  collection: CollectionConfig;
@@ -53,7 +71,7 @@ export interface GeneratedAdapter {
53
71
  handleDelete: HandleDelete;
54
72
  handleUpload: HandleUpload;
55
73
  name: string;
56
- onInit?: () => void;
74
+ onInit?: () => Promise<void> | void;
57
75
  staticHandler: StaticHandler;
58
76
  /** Generates upload instructions when supported. */
59
77
  uploadInstructions?: {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.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AoB,CAAC,EAAE,OAAO,CAAA;CAC/B"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n FileData,\n ImageSize,\n PayloadHandler,\n PayloadRequest,\n TypeWithID,\n UploadCollectionSlug,\n UploadInstructionsAccess,\n UploadInstructionsCapability,\n} from 'payload'\n\nexport interface File {\n buffer: Buffer\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n uploadReference?: unknown\n}\n\nexport type ClientUploadsConfig = { access?: UploadInstructionsAccess } | boolean\n\nexport type HandleUpload = (args: {\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequest\n}) =>\n | Partial<FileData & TypeWithID>\n | Promise<Partial<FileData & TypeWithID>>\n | Promise<void>\n | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: FileData & TypeWithID & TypeWithPrefix\n filename: string\n req: PayloadRequest\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n data: any\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequest,\n args: {\n doc?: TypeWithID\n headers?: Headers\n params: { collection: string; filename: string; prefix?: string; uploadReference?: unknown }\n },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n /**\n * Additional fields to be injected into the base collection and image sizes\n */\n fields?: Field[]\n /**\n * Generates the public URL for a file\n */\n generateURL?: GenerateURL\n handleDelete: HandleDelete\n handleUpload: HandleUpload\n name: string\n onInit?: () => void\n staticHandler: StaticHandler\n /** Generates upload instructions when supported. */\n uploadInstructions?: {\n adminHandler?: {\n path: string\n props?: Record<string, unknown>\n }\n enabled: boolean\n endpoint?: {\n handler: PayloadHandler\n path: `/${string}`\n }\n } & UploadInstructionsCapability\n}\n\nexport type Adapter = (args: { collection: CollectionConfig; prefix?: string }) => GeneratedAdapter\n\nexport type AllowList = Array<{\n hostname: string\n pathname?: string\n port?: string\n protocol?: 'http' | 'https'\n search?: string\n}>\n\nexport type GenerateFileURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n size?: ImageSize\n}) => Promise<string> | string\n\nexport interface CollectionOptions {\n adapter: Adapter | null\n disableLocalStorage?: boolean\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport interface PluginOptions {\n /**\n * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n collections: Partial<Record<UploadCollectionSlug, CollectionOptions>>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * When true (compositional prefixes), the stored `prefix` field is only the\n * document-level segment; the collection prefix comes from plugin options and\n * must not be pre-filled as the field default.\n *\n * Set by storage adapters that support compositional prefixes (e.g. S3, Azure, R2, Vercel Blob, GCS).\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n"],"names":[],"mappings":"AAmHA,WA4BC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n FileData,\n ImageSize,\n PayloadHandler,\n PayloadRequest,\n TypeWithID,\n UploadCollectionSlug,\n UploadInstructionsAccess,\n UploadInstructionsCapability,\n} from 'payload'\n\nexport interface File {\n buffer: Buffer\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n uploadReference?: unknown\n}\n\nexport type ClientUploadsConfig = { access?: UploadInstructionsAccess } | boolean\n\n/**\n * Reference to a client-uploaded object, returned by an upload handler and\n * submitted with the document. Always carries the signed receipt; `prefix`\n * locates the stored object.\n */\nexport type UploadReference = {\n _objectKey?: string\n prefix: string\n signedReceipt: `${string}.${string}`\n}\n\nexport type HandleUpload = (args: {\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequest\n /**\n * Pre-resolved storage path (`_objectKey` folded in, contained beneath the collection prefix).\n */\n storageFilePath: string\n}) =>\n | Partial<FileData & TypeWithID>\n | Promise<Partial<FileData & TypeWithID>>\n | Promise<void>\n | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: FileData & TypeWithID & TypeWithPrefix\n filename: string\n req: PayloadRequest\n /**\n * Pre-resolved storage path of the object to delete.\n */\n storageFilePath: string\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n data: any\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequest,\n args: {\n doc?: TypeWithID\n headers?: Headers\n params: { collection: string; filename: string; prefix?: string; uploadReference?: unknown }\n },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n /**\n * Additional fields to be injected into the base collection and image sizes\n */\n fields?: Field[]\n /**\n * Generates the public URL for a file\n */\n generateURL?: GenerateURL\n handleDelete: HandleDelete\n handleUpload: HandleUpload\n name: string\n onInit?: () => Promise<void> | void\n staticHandler: StaticHandler\n /** Generates upload instructions when supported. */\n uploadInstructions?: {\n adminHandler?: {\n path: string\n props?: Record<string, unknown>\n }\n enabled: boolean\n endpoint?: {\n handler: PayloadHandler\n path: `/${string}`\n }\n } & UploadInstructionsCapability\n}\n\nexport type Adapter = (args: { collection: CollectionConfig; prefix?: string }) => GeneratedAdapter\n\nexport type AllowList = Array<{\n hostname: string\n pathname?: string\n port?: string\n protocol?: 'http' | 'https'\n search?: string\n}>\n\nexport type GenerateFileURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n size?: ImageSize\n}) => Promise<string> | string\n\nexport interface CollectionOptions {\n adapter: Adapter | null\n disableLocalStorage?: boolean\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport interface PluginOptions {\n /**\n * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n collections: Partial<Record<UploadCollectionSlug, CollectionOptions>>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * When true (compositional prefixes), the stored `prefix` field is only the\n * document-level segment; the collection prefix comes from plugin options and\n * must not be pre-filled as the field default.\n *\n * Set by storage adapters that support compositional prefixes (e.g. S3, Azure, R2, Vercel Blob, GCS).\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n"],"names":[],"mappings":"AAsIA,WA4BC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.
3
+ */
4
+ export declare const buildPrefixWithObjectKey: ({ objectKey, prefix, }: {
5
+ objectKey?: string;
6
+ prefix?: string;
7
+ }) => string;
8
+ //# sourceMappingURL=buildPrefixWithObjectKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildPrefixWithObjectKey.d.ts","sourceRoot":"","sources":["../../src/utilities/buildPrefixWithObjectKey.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,wBAAwB,2BAGlC;IACD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAG,MASH,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { sanitizePrefix } from './sanitizePrefix.js';
2
+ /**
3
+ * Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.
4
+ */ export const buildPrefixWithObjectKey = ({ objectKey, prefix })=>{
5
+ const safePrefix = sanitizePrefix(prefix ?? '');
6
+ const safeObjectKey = sanitizePrefix(objectKey ?? '');
7
+ if (safePrefix && safeObjectKey) {
8
+ return `${safePrefix}/${safeObjectKey}`;
9
+ }
10
+ return safePrefix || safeObjectKey;
11
+ };
12
+
13
+ //# sourceMappingURL=buildPrefixWithObjectKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/buildPrefixWithObjectKey.ts"],"sourcesContent":["import { sanitizePrefix } from './sanitizePrefix.js'\n\n/**\n * Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.\n */\nexport const buildPrefixWithObjectKey = ({\n objectKey,\n prefix,\n}: {\n objectKey?: string\n prefix?: string\n}): string => {\n const safePrefix = sanitizePrefix(prefix ?? '')\n const safeObjectKey = sanitizePrefix(objectKey ?? '')\n\n if (safePrefix && safeObjectKey) {\n return `${safePrefix}/${safeObjectKey}`\n }\n\n return safePrefix || safeObjectKey\n}\n"],"names":["sanitizePrefix","buildPrefixWithObjectKey","objectKey","prefix","safePrefix","safeObjectKey"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD;;CAEC,GACD,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,SAAS,EACTC,MAAM,EAIP;IACC,MAAMC,aAAaJ,eAAeG,UAAU;IAC5C,MAAME,gBAAgBL,eAAeE,aAAa;IAElD,IAAIE,cAAcC,eAAe;QAC/B,OAAO,GAAGD,WAAW,CAAC,EAAEC,eAAe;IACzC;IAEA,OAAOD,cAAcC;AACvB,EAAC"}
@@ -0,0 +1,49 @@
1
+ type BuildFilePathDataArgs = {
2
+ collectionPrefix?: string;
3
+ docPrefix?: string;
4
+ filename: string;
5
+ useCompositePrefixes?: boolean;
6
+ };
7
+ type BuildFilePathDataResult = {
8
+ sanitizedCollectionPrefix: string;
9
+ sanitizedDocPrefix: string;
10
+ sanitizedFilename: string;
11
+ /**
12
+ * The full path to the file within the storage backend.
13
+ */
14
+ storageFilePath: string;
15
+ };
16
+ export declare function isStoragePathWithinCollectionPrefix({ collectionPrefix, docPrefix, }: {
17
+ collectionPrefix?: string;
18
+ docPrefix: string;
19
+ }): boolean;
20
+ /**
21
+ * Resolves where a new upload must be stored, without needing a filename.
22
+ *
23
+ * In non-composite mode (useCompositePrefixes: false), docPrefix is treated as a complete prefix
24
+ * when it is already within collectionPrefix and is otherwise nested beneath collectionPrefix.
25
+ * In composite mode (useCompositePrefixes: true), the collection prefix is joined when the key is
26
+ * built, so the persisted document prefix stays relative to it.
27
+ *
28
+ * Prefix-only callers (such as the upload prefix hooks) use this directly; use
29
+ * {@link buildUploadStoragePathData} when a full object key is needed.
30
+ */
31
+ export declare function buildUploadPrefix({ collectionPrefix, docPrefix, useCompositePrefixes, }: Omit<BuildFilePathDataArgs, 'filename'>): {
32
+ sanitizedCollectionPrefix: string;
33
+ sanitizedDocPrefix: string;
34
+ uploadPrefix: string;
35
+ };
36
+ /**
37
+ * Resolves a new upload destination beneath the configured collection prefix.
38
+ * Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.
39
+ */
40
+ export declare function buildUploadStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes, }: BuildFilePathDataArgs): BuildFilePathDataResult;
41
+ /**
42
+ * Resolves the exact location represented by persisted upload metadata.
43
+ * Non-composite document prefixes historically override the collection prefix;
44
+ * keep that behavior for reads, URLs, and cleanup of pre-upgrade files.
45
+ * New writes must use buildUploadStoragePathData instead.
46
+ */
47
+ export declare function buildStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes, }: BuildFilePathDataArgs): BuildFilePathDataResult;
48
+ export {};
49
+ //# sourceMappingURL=buildStoragePathData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildStoragePathData.d.ts","sourceRoot":"","sources":["../../src/utilities/buildStoragePathData.ts"],"names":[],"mappings":"AAKA,KAAK,qBAAqB,GAAG;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC7B,yBAAyB,EAAE,MAAM,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,wBAAgB,mCAAmC,CAAC,EAClD,gBAAgB,EAChB,SAAS,GACV,EAAE;IACD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,OAAO,CAQV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,SAAS,EACT,oBAA4B,GAC7B,EAAE,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,GAAG;IAC3C,yBAAyB,EAAE,MAAM,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;CACrB,CAiBA;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,qBAAqB,GAAG,uBAAuB,CAkBjD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,qBAAqB,GAAG,uBAAuB,CAcjD"}
@@ -0,0 +1,67 @@
1
+ import path from 'path';
2
+ import { sanitizeFilename } from 'payload/shared';
3
+ import { sanitizePrefix } from './sanitizePrefix.js';
4
+ export function isStoragePathWithinCollectionPrefix({ collectionPrefix, docPrefix }) {
5
+ const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '');
6
+ return !safeCollectionPrefix || docPrefix === safeCollectionPrefix || docPrefix.startsWith(`${safeCollectionPrefix}/`);
7
+ }
8
+ /**
9
+ * Resolves where a new upload must be stored, without needing a filename.
10
+ *
11
+ * In non-composite mode (useCompositePrefixes: false), docPrefix is treated as a complete prefix
12
+ * when it is already within collectionPrefix and is otherwise nested beneath collectionPrefix.
13
+ * In composite mode (useCompositePrefixes: true), the collection prefix is joined when the key is
14
+ * built, so the persisted document prefix stays relative to it.
15
+ *
16
+ * Prefix-only callers (such as the upload prefix hooks) use this directly; use
17
+ * {@link buildUploadStoragePathData} when a full object key is needed.
18
+ */ export function buildUploadPrefix({ collectionPrefix, docPrefix, useCompositePrefixes = false }) {
19
+ const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '');
20
+ const safeDocPrefix = sanitizePrefix(docPrefix || '');
21
+ const uploadPrefix = safeDocPrefix && !isStoragePathWithinCollectionPrefix({
22
+ collectionPrefix: safeCollectionPrefix,
23
+ docPrefix: safeDocPrefix
24
+ }) ? path.posix.join(safeCollectionPrefix, safeDocPrefix) : safeDocPrefix || safeCollectionPrefix;
25
+ return {
26
+ sanitizedCollectionPrefix: safeCollectionPrefix,
27
+ sanitizedDocPrefix: !useCompositePrefixes && safeDocPrefix ? uploadPrefix : safeDocPrefix,
28
+ uploadPrefix
29
+ };
30
+ }
31
+ /**
32
+ * Resolves a new upload destination beneath the configured collection prefix.
33
+ * Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.
34
+ */ export function buildUploadStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes = false }) {
35
+ const { sanitizedCollectionPrefix, sanitizedDocPrefix, uploadPrefix } = buildUploadPrefix({
36
+ collectionPrefix,
37
+ docPrefix,
38
+ useCompositePrefixes
39
+ });
40
+ const safeFilename = sanitizeFilename(filename);
41
+ const storageFilePath = useCompositePrefixes ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, safeFilename) : path.posix.join(uploadPrefix, safeFilename);
42
+ return {
43
+ sanitizedCollectionPrefix,
44
+ sanitizedDocPrefix,
45
+ sanitizedFilename: safeFilename,
46
+ storageFilePath
47
+ };
48
+ }
49
+ /**
50
+ * Resolves the exact location represented by persisted upload metadata.
51
+ * Non-composite document prefixes historically override the collection prefix;
52
+ * keep that behavior for reads, URLs, and cleanup of pre-upgrade files.
53
+ * New writes must use buildUploadStoragePathData instead.
54
+ */ export function buildStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes = false }) {
55
+ const sanitizedCollectionPrefix = sanitizePrefix(collectionPrefix || '');
56
+ const sanitizedDocPrefix = sanitizePrefix(docPrefix || '');
57
+ const sanitizedFilename = sanitizeFilename(filename);
58
+ const storageFilePath = useCompositePrefixes ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, sanitizedFilename) : path.posix.join(sanitizedDocPrefix || sanitizedCollectionPrefix, sanitizedFilename);
59
+ return {
60
+ sanitizedCollectionPrefix,
61
+ sanitizedDocPrefix,
62
+ sanitizedFilename,
63
+ storageFilePath
64
+ };
65
+ }
66
+
67
+ //# sourceMappingURL=buildStoragePathData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/buildStoragePathData.ts"],"sourcesContent":["import path from 'path'\nimport { sanitizeFilename } from 'payload/shared'\n\nimport { sanitizePrefix } from './sanitizePrefix.js'\n\ntype BuildFilePathDataArgs = {\n collectionPrefix?: string\n docPrefix?: string\n filename: string\n useCompositePrefixes?: boolean\n}\n\ntype BuildFilePathDataResult = {\n sanitizedCollectionPrefix: string\n sanitizedDocPrefix: string\n sanitizedFilename: string\n /**\n * The full path to the file within the storage backend.\n */\n storageFilePath: string\n}\n\nexport function isStoragePathWithinCollectionPrefix({\n collectionPrefix,\n docPrefix,\n}: {\n collectionPrefix?: string\n docPrefix: string\n}): boolean {\n const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '')\n\n return (\n !safeCollectionPrefix ||\n docPrefix === safeCollectionPrefix ||\n docPrefix.startsWith(`${safeCollectionPrefix}/`)\n )\n}\n\n/**\n * Resolves where a new upload must be stored, without needing a filename.\n *\n * In non-composite mode (useCompositePrefixes: false), docPrefix is treated as a complete prefix\n * when it is already within collectionPrefix and is otherwise nested beneath collectionPrefix.\n * In composite mode (useCompositePrefixes: true), the collection prefix is joined when the key is\n * built, so the persisted document prefix stays relative to it.\n *\n * Prefix-only callers (such as the upload prefix hooks) use this directly; use\n * {@link buildUploadStoragePathData} when a full object key is needed.\n */\nexport function buildUploadPrefix({\n collectionPrefix,\n docPrefix,\n useCompositePrefixes = false,\n}: Omit<BuildFilePathDataArgs, 'filename'>): {\n sanitizedCollectionPrefix: string\n sanitizedDocPrefix: string\n uploadPrefix: string\n} {\n const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '')\n const safeDocPrefix = sanitizePrefix(docPrefix || '')\n const uploadPrefix =\n safeDocPrefix &&\n !isStoragePathWithinCollectionPrefix({\n collectionPrefix: safeCollectionPrefix,\n docPrefix: safeDocPrefix,\n })\n ? path.posix.join(safeCollectionPrefix, safeDocPrefix)\n : safeDocPrefix || safeCollectionPrefix\n\n return {\n sanitizedCollectionPrefix: safeCollectionPrefix,\n sanitizedDocPrefix: !useCompositePrefixes && safeDocPrefix ? uploadPrefix : safeDocPrefix,\n uploadPrefix,\n }\n}\n\n/**\n * Resolves a new upload destination beneath the configured collection prefix.\n * Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.\n */\nexport function buildUploadStoragePathData({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes = false,\n}: BuildFilePathDataArgs): BuildFilePathDataResult {\n const { sanitizedCollectionPrefix, sanitizedDocPrefix, uploadPrefix } = buildUploadPrefix({\n collectionPrefix,\n docPrefix,\n useCompositePrefixes,\n })\n const safeFilename = sanitizeFilename(filename)\n\n const storageFilePath = useCompositePrefixes\n ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, safeFilename)\n : path.posix.join(uploadPrefix, safeFilename)\n\n return {\n sanitizedCollectionPrefix,\n sanitizedDocPrefix,\n sanitizedFilename: safeFilename,\n storageFilePath,\n }\n}\n\n/**\n * Resolves the exact location represented by persisted upload metadata.\n * Non-composite document prefixes historically override the collection prefix;\n * keep that behavior for reads, URLs, and cleanup of pre-upgrade files.\n * New writes must use buildUploadStoragePathData instead.\n */\nexport function buildStoragePathData({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes = false,\n}: BuildFilePathDataArgs): BuildFilePathDataResult {\n const sanitizedCollectionPrefix = sanitizePrefix(collectionPrefix || '')\n const sanitizedDocPrefix = sanitizePrefix(docPrefix || '')\n const sanitizedFilename = sanitizeFilename(filename)\n const storageFilePath = useCompositePrefixes\n ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, sanitizedFilename)\n : path.posix.join(sanitizedDocPrefix || sanitizedCollectionPrefix, sanitizedFilename)\n\n return {\n sanitizedCollectionPrefix,\n sanitizedDocPrefix,\n sanitizedFilename,\n storageFilePath,\n }\n}\n"],"names":["path","sanitizeFilename","sanitizePrefix","isStoragePathWithinCollectionPrefix","collectionPrefix","docPrefix","safeCollectionPrefix","startsWith","buildUploadPrefix","useCompositePrefixes","safeDocPrefix","uploadPrefix","posix","join","sanitizedCollectionPrefix","sanitizedDocPrefix","buildUploadStoragePathData","filename","safeFilename","storageFilePath","sanitizedFilename","buildStoragePathData"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AACvB,SAASC,gBAAgB,QAAQ,iBAAgB;AAEjD,SAASC,cAAc,QAAQ,sBAAqB;AAmBpD,OAAO,SAASC,oCAAoC,EAClDC,gBAAgB,EAChBC,SAAS,EAIV;IACC,MAAMC,uBAAuBJ,eAAeE,oBAAoB;IAEhE,OACE,CAACE,wBACDD,cAAcC,wBACdD,UAAUE,UAAU,CAAC,GAAGD,qBAAqB,CAAC,CAAC;AAEnD;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASE,kBAAkB,EAChCJ,gBAAgB,EAChBC,SAAS,EACTI,uBAAuB,KAAK,EACY;IAKxC,MAAMH,uBAAuBJ,eAAeE,oBAAoB;IAChE,MAAMM,gBAAgBR,eAAeG,aAAa;IAClD,MAAMM,eACJD,iBACA,CAACP,oCAAoC;QACnCC,kBAAkBE;QAClBD,WAAWK;IACb,KACIV,KAAKY,KAAK,CAACC,IAAI,CAACP,sBAAsBI,iBACtCA,iBAAiBJ;IAEvB,OAAO;QACLQ,2BAA2BR;QAC3BS,oBAAoB,CAACN,wBAAwBC,gBAAgBC,eAAeD;QAC5EC;IACF;AACF;AAEA;;;CAGC,GACD,OAAO,SAASK,2BAA2B,EACzCZ,gBAAgB,EAChBC,SAAS,EACTY,QAAQ,EACRR,uBAAuB,KAAK,EACN;IACtB,MAAM,EAAEK,yBAAyB,EAAEC,kBAAkB,EAAEJ,YAAY,EAAE,GAAGH,kBAAkB;QACxFJ;QACAC;QACAI;IACF;IACA,MAAMS,eAAejB,iBAAiBgB;IAEtC,MAAME,kBAAkBV,uBACpBT,KAAKY,KAAK,CAACC,IAAI,CAACC,2BAA2BC,oBAAoBG,gBAC/DlB,KAAKY,KAAK,CAACC,IAAI,CAACF,cAAcO;IAElC,OAAO;QACLJ;QACAC;QACAK,mBAAmBF;QACnBC;IACF;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASE,qBAAqB,EACnCjB,gBAAgB,EAChBC,SAAS,EACTY,QAAQ,EACRR,uBAAuB,KAAK,EACN;IACtB,MAAMK,4BAA4BZ,eAAeE,oBAAoB;IACrE,MAAMW,qBAAqBb,eAAeG,aAAa;IACvD,MAAMe,oBAAoBnB,iBAAiBgB;IAC3C,MAAME,kBAAkBV,uBACpBT,KAAKY,KAAK,CAACC,IAAI,CAACC,2BAA2BC,oBAAoBK,qBAC/DpB,KAAKY,KAAK,CAACC,IAAI,CAACE,sBAAsBD,2BAA2BM;IAErE,OAAO;QACLN;QACAC;QACAK;QACAD;IACF;AACF"}
@@ -0,0 +1,241 @@
1
+ import { buildStoragePathData, buildUploadStoragePathData, isStoragePathWithinCollectionPrefix } from './buildStoragePathData.js';
2
+ import { describe, expect, it } from 'vitest';
3
+ describe('buildFileKey', ()=>{
4
+ describe('non-composite mode (useCompositePrefixes: false)', ()=>{
5
+ it('should preserve the key of a legacy document outside the collection prefix', ()=>{
6
+ const result = buildStoragePathData({
7
+ collectionPrefix: 'media/',
8
+ docPrefix: 'media-archive',
9
+ filename: 'test.png',
10
+ useCompositePrefixes: false
11
+ });
12
+ expect(result).toEqual({
13
+ sanitizedCollectionPrefix: 'media',
14
+ sanitizedDocPrefix: 'media-archive',
15
+ sanitizedFilename: 'test.png',
16
+ storageFilePath: 'media-archive/test.png'
17
+ });
18
+ });
19
+ it('should fallback to collectionPrefix when docPrefix is empty', ()=>{
20
+ const result = buildStoragePathData({
21
+ collectionPrefix: 'collection',
22
+ docPrefix: '',
23
+ filename: 'test.png',
24
+ useCompositePrefixes: false
25
+ });
26
+ expect(result).toEqual({
27
+ sanitizedCollectionPrefix: 'collection',
28
+ sanitizedDocPrefix: '',
29
+ sanitizedFilename: 'test.png',
30
+ storageFilePath: 'collection/test.png'
31
+ });
32
+ });
33
+ it('should fallback to collectionPrefix when docPrefix is undefined', ()=>{
34
+ const result = buildStoragePathData({
35
+ collectionPrefix: 'collection',
36
+ filename: 'test.png',
37
+ useCompositePrefixes: false
38
+ });
39
+ expect(result).toEqual({
40
+ sanitizedCollectionPrefix: 'collection',
41
+ sanitizedDocPrefix: '',
42
+ sanitizedFilename: 'test.png',
43
+ storageFilePath: 'collection/test.png'
44
+ });
45
+ });
46
+ it('should return only filename when both prefixes are empty', ()=>{
47
+ const result = buildStoragePathData({
48
+ filename: 'test.png',
49
+ useCompositePrefixes: false
50
+ });
51
+ expect(result).toEqual({
52
+ sanitizedCollectionPrefix: '',
53
+ sanitizedDocPrefix: '',
54
+ sanitizedFilename: 'test.png',
55
+ storageFilePath: 'test.png'
56
+ });
57
+ });
58
+ });
59
+ describe('composite mode (useCompositePrefixes: true)', ()=>{
60
+ it('should combine collectionPrefix and docPrefix', ()=>{
61
+ const result = buildStoragePathData({
62
+ collectionPrefix: 'collection',
63
+ docPrefix: 'document',
64
+ filename: 'test.png',
65
+ useCompositePrefixes: true
66
+ });
67
+ expect(result).toEqual({
68
+ sanitizedCollectionPrefix: 'collection',
69
+ sanitizedDocPrefix: 'document',
70
+ sanitizedFilename: 'test.png',
71
+ storageFilePath: 'collection/document/test.png'
72
+ });
73
+ });
74
+ it('should work with only collectionPrefix', ()=>{
75
+ const result = buildStoragePathData({
76
+ collectionPrefix: 'collection',
77
+ filename: 'test.png',
78
+ useCompositePrefixes: true
79
+ });
80
+ expect(result).toEqual({
81
+ sanitizedCollectionPrefix: 'collection',
82
+ sanitizedDocPrefix: '',
83
+ sanitizedFilename: 'test.png',
84
+ storageFilePath: 'collection/test.png'
85
+ });
86
+ });
87
+ it('should work with only docPrefix', ()=>{
88
+ const result = buildStoragePathData({
89
+ docPrefix: 'document',
90
+ filename: 'test.png',
91
+ useCompositePrefixes: true
92
+ });
93
+ expect(result).toEqual({
94
+ sanitizedCollectionPrefix: '',
95
+ sanitizedDocPrefix: 'document',
96
+ sanitizedFilename: 'test.png',
97
+ storageFilePath: 'document/test.png'
98
+ });
99
+ });
100
+ it('should return only filename when both prefixes are empty', ()=>{
101
+ const result = buildStoragePathData({
102
+ filename: 'test.png',
103
+ useCompositePrefixes: true
104
+ });
105
+ expect(result).toEqual({
106
+ sanitizedCollectionPrefix: '',
107
+ sanitizedDocPrefix: '',
108
+ sanitizedFilename: 'test.png',
109
+ storageFilePath: 'test.png'
110
+ });
111
+ });
112
+ });
113
+ describe('collection prefix boundaries', ()=>{
114
+ it('should accept a file key within a slash-terminated collection prefix', ()=>{
115
+ expect(isStoragePathWithinCollectionPrefix({
116
+ collectionPrefix: 'media/',
117
+ docPrefix: 'media/documents/test.png'
118
+ })).toBe(true);
119
+ });
120
+ });
121
+ describe('sanitization', ()=>{
122
+ it.each([
123
+ './media/./images',
124
+ 'media\\images',
125
+ '/media//images'
126
+ ])('should canonicalize equivalent prefix paths', (docPrefix)=>{
127
+ const result = buildStoragePathData({
128
+ docPrefix,
129
+ filename: 'test.png'
130
+ });
131
+ expect(result).toEqual({
132
+ sanitizedCollectionPrefix: '',
133
+ sanitizedDocPrefix: 'media/images',
134
+ sanitizedFilename: 'test.png',
135
+ storageFilePath: 'media/images/test.png'
136
+ });
137
+ });
138
+ it('should remove path traversal segments from collectionPrefix', ()=>{
139
+ const result = buildStoragePathData({
140
+ collectionPrefix: '../../../etc',
141
+ filename: 'test.png',
142
+ useCompositePrefixes: false
143
+ });
144
+ expect(result).toEqual({
145
+ sanitizedCollectionPrefix: 'etc',
146
+ sanitizedDocPrefix: '',
147
+ sanitizedFilename: 'test.png',
148
+ storageFilePath: 'etc/test.png'
149
+ });
150
+ expect(result.storageFilePath).not.toContain('..');
151
+ });
152
+ it('should remove path traversal segments from docPrefix', ()=>{
153
+ const result = buildStoragePathData({
154
+ docPrefix: 'a/../../outside',
155
+ filename: 'test.png',
156
+ useCompositePrefixes: false
157
+ });
158
+ expect(result).toEqual({
159
+ sanitizedCollectionPrefix: '',
160
+ sanitizedDocPrefix: 'a/outside',
161
+ sanitizedFilename: 'test.png',
162
+ storageFilePath: 'a/outside/test.png'
163
+ });
164
+ expect(result.storageFilePath).not.toContain('..');
165
+ });
166
+ it('should remove control characters from prefixes', ()=>{
167
+ const result = buildStoragePathData({
168
+ collectionPrefix: 'test\x00\x1fprefix',
169
+ filename: 'test.png',
170
+ useCompositePrefixes: false
171
+ });
172
+ expect(result).toEqual({
173
+ sanitizedCollectionPrefix: 'testprefix',
174
+ sanitizedDocPrefix: '',
175
+ sanitizedFilename: 'test.png',
176
+ storageFilePath: 'testprefix/test.png'
177
+ });
178
+ expect(result.storageFilePath).not.toMatch(/[\x00-\x1f]/);
179
+ });
180
+ it('should normalize both prefixes after removing control characters in composite mode', ()=>{
181
+ const result = buildStoragePathData({
182
+ collectionPrefix: '.\x00./collection',
183
+ docPrefix: '.\x00./doc',
184
+ filename: 'test.png',
185
+ useCompositePrefixes: true
186
+ });
187
+ expect(result).toEqual({
188
+ sanitizedCollectionPrefix: 'collection',
189
+ sanitizedDocPrefix: 'doc',
190
+ sanitizedFilename: 'test.png',
191
+ storageFilePath: 'collection/doc/test.png'
192
+ });
193
+ expect(result.storageFilePath).not.toContain('..');
194
+ });
195
+ });
196
+ });
197
+ describe('buildUploadStoragePathData', ()=>{
198
+ it.each([
199
+ [
200
+ 'invoices',
201
+ false,
202
+ 'media/invoices/file.png',
203
+ 'media/invoices'
204
+ ],
205
+ [
206
+ 'media/invoices',
207
+ false,
208
+ 'media/invoices/file.png',
209
+ 'media/invoices'
210
+ ],
211
+ [
212
+ '',
213
+ false,
214
+ 'media/file.png',
215
+ ''
216
+ ],
217
+ [
218
+ 'invoices',
219
+ true,
220
+ 'media/invoices/file.png',
221
+ 'invoices'
222
+ ]
223
+ ])('should persist a readable destination for %s (composite %s)', (docPrefix, useCompositePrefixes, fileKey, storedPrefix)=>{
224
+ const result = buildUploadStoragePathData({
225
+ collectionPrefix: 'media',
226
+ docPrefix,
227
+ filename: 'file.png',
228
+ useCompositePrefixes
229
+ });
230
+ expect(result.storageFilePath).toBe(fileKey);
231
+ expect(result.sanitizedDocPrefix).toBe(storedPrefix);
232
+ expect(buildStoragePathData({
233
+ collectionPrefix: 'media',
234
+ docPrefix: result.sanitizedDocPrefix,
235
+ filename: 'file.png',
236
+ useCompositePrefixes
237
+ }).storageFilePath).toBe(fileKey);
238
+ });
239
+ });
240
+
241
+ //# sourceMappingURL=buildStoragePathData.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/buildStoragePathData.spec.ts"],"sourcesContent":["import {\n buildStoragePathData,\n buildUploadStoragePathData,\n isStoragePathWithinCollectionPrefix,\n} from './buildStoragePathData.js'\nimport { describe, expect, it } from 'vitest'\n\ndescribe('buildFileKey', () => {\n describe('non-composite mode (useCompositePrefixes: false)', () => {\n it('should preserve the key of a legacy document outside the collection prefix', () => {\n const result = buildStoragePathData({\n collectionPrefix: 'media/',\n docPrefix: 'media-archive',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'media',\n sanitizedDocPrefix: 'media-archive',\n sanitizedFilename: 'test.png',\n storageFilePath: 'media-archive/test.png',\n })\n })\n\n it('should fallback to collectionPrefix when docPrefix is empty', () => {\n const result = buildStoragePathData({\n collectionPrefix: 'collection',\n docPrefix: '',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n storageFilePath: 'collection/test.png',\n })\n })\n\n it('should fallback to collectionPrefix when docPrefix is undefined', () => {\n const result = buildStoragePathData({\n collectionPrefix: 'collection',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n storageFilePath: 'collection/test.png',\n })\n })\n\n it('should return only filename when both prefixes are empty', () => {\n const result = buildStoragePathData({\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n storageFilePath: 'test.png',\n })\n })\n })\n\n describe('composite mode (useCompositePrefixes: true)', () => {\n it('should combine collectionPrefix and docPrefix', () => {\n const result = buildStoragePathData({\n collectionPrefix: 'collection',\n docPrefix: 'document',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: 'document',\n sanitizedFilename: 'test.png',\n storageFilePath: 'collection/document/test.png',\n })\n })\n\n it('should work with only collectionPrefix', () => {\n const result = buildStoragePathData({\n collectionPrefix: 'collection',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n storageFilePath: 'collection/test.png',\n })\n })\n\n it('should work with only docPrefix', () => {\n const result = buildStoragePathData({\n docPrefix: 'document',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: 'document',\n sanitizedFilename: 'test.png',\n storageFilePath: 'document/test.png',\n })\n })\n\n it('should return only filename when both prefixes are empty', () => {\n const result = buildStoragePathData({\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n storageFilePath: 'test.png',\n })\n })\n })\n\n describe('collection prefix boundaries', () => {\n it('should accept a file key within a slash-terminated collection prefix', () => {\n expect(\n isStoragePathWithinCollectionPrefix({\n collectionPrefix: 'media/',\n docPrefix: 'media/documents/test.png',\n }),\n ).toBe(true)\n })\n })\n\n describe('sanitization', () => {\n it.each(['./media/./images', 'media\\\\images', '/media//images'])(\n 'should canonicalize equivalent prefix paths',\n (docPrefix) => {\n const result = buildStoragePathData({ docPrefix, filename: 'test.png' })\n\n expect(result).toEqual({\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: 'media/images',\n sanitizedFilename: 'test.png',\n storageFilePath: 'media/images/test.png',\n })\n },\n )\n\n it('should remove path traversal segments from collectionPrefix', () => {\n const result = buildStoragePathData({\n collectionPrefix: '../../../etc',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'etc',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n storageFilePath: 'etc/test.png',\n })\n expect(result.storageFilePath).not.toContain('..')\n })\n\n it('should remove path traversal segments from docPrefix', () => {\n const result = buildStoragePathData({\n docPrefix: 'a/../../outside',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: 'a/outside',\n sanitizedFilename: 'test.png',\n storageFilePath: 'a/outside/test.png',\n })\n expect(result.storageFilePath).not.toContain('..')\n })\n\n it('should remove control characters from prefixes', () => {\n const result = buildStoragePathData({\n collectionPrefix: 'test\\x00\\x1fprefix',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'testprefix',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n storageFilePath: 'testprefix/test.png',\n })\n expect(result.storageFilePath).not.toMatch(/[\\x00-\\x1f]/)\n })\n\n it('should normalize both prefixes after removing control characters in composite mode', () => {\n const result = buildStoragePathData({\n collectionPrefix: '.\\x00./collection',\n docPrefix: '.\\x00./doc',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: 'doc',\n sanitizedFilename: 'test.png',\n storageFilePath: 'collection/doc/test.png',\n })\n expect(result.storageFilePath).not.toContain('..')\n })\n })\n})\n\ndescribe('buildUploadStoragePathData', () => {\n it.each([\n ['invoices', false, 'media/invoices/file.png', 'media/invoices'],\n ['media/invoices', false, 'media/invoices/file.png', 'media/invoices'],\n ['', false, 'media/file.png', ''],\n ['invoices', true, 'media/invoices/file.png', 'invoices'],\n ] as const)(\n 'should persist a readable destination for %s (composite %s)',\n (docPrefix, useCompositePrefixes, fileKey, storedPrefix) => {\n const result = buildUploadStoragePathData({\n collectionPrefix: 'media',\n docPrefix,\n filename: 'file.png',\n useCompositePrefixes,\n })\n\n expect(result.storageFilePath).toBe(fileKey)\n expect(result.sanitizedDocPrefix).toBe(storedPrefix)\n expect(\n buildStoragePathData({\n collectionPrefix: 'media',\n docPrefix: result.sanitizedDocPrefix,\n filename: 'file.png',\n useCompositePrefixes,\n }).storageFilePath,\n ).toBe(fileKey)\n },\n )\n})\n"],"names":["buildStoragePathData","buildUploadStoragePathData","isStoragePathWithinCollectionPrefix","describe","expect","it","result","collectionPrefix","docPrefix","filename","useCompositePrefixes","toEqual","sanitizedCollectionPrefix","sanitizedDocPrefix","sanitizedFilename","storageFilePath","toBe","each","not","toContain","toMatch","fileKey","storedPrefix"],"mappings":"AAAA,SACEA,oBAAoB,EACpBC,0BAA0B,EAC1BC,mCAAmC,QAC9B,4BAA2B;AAClC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7CF,SAAS,gBAAgB;IACvBA,SAAS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ACM;QACvClB,OACEJ,qBAAqB;YACnBO,kBAAkB;YAClBC,WAAWF,OAAOO,kBAAkB;YACpCJ,UAAU;YACVC;QACF,GAAGK,eAAe,EAClBC,IAAI,CAACK;IACT;AAEJ"}
@@ -1,20 +1,28 @@
1
- import type { CollectionConfig, PayloadRequest } from 'payload';
1
+ import type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload';
2
2
  /**
3
- * Resolves the file prefix from the highest-priority available source and
4
- * always returns a sanitized value.
3
+ * Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).
5
4
  *
6
- * Resolution order:
7
- * 1. `prefixQueryParam`
8
- * 2. `uploadReference.prefix`
9
- * 3. Stored document `prefix` from the database
10
- *
11
- * Resolved values are passed through `sanitizePrefix`.
5
+ * An already-authorized `doc` wins outright. Otherwise an `uploadReference` is used (its
6
+ * `prefix` re-contained with {@link buildUploadStoragePathData}, since it hasn't been verified against
7
+ * a signed receipt by every adapter). Otherwise the document is resolved with
8
+ * `overrideAccess: false`, any query-param prefix only narrows that lookup, and `_objectKey`
9
+ * is read from the resolved document via `showHiddenFields`.
12
10
  */
13
- export declare function getFilePrefix({ collection, filename, prefixQueryParam, req, uploadReference, }: {
11
+ export declare function getFilePrefix({ collection, collectionPrefix, doc, filename, prefixQueryParam, req, uploadReference, useCompositePrefixes, }: {
14
12
  collection: CollectionConfig;
13
+ collectionPrefix?: string;
14
+ doc?: {
15
+ _objectKey?: string;
16
+ prefix?: string;
17
+ } & TypeWithID;
15
18
  filename: string;
19
+ /**
20
+ * Only narrows the access-controlled fallback lookup below; never trusted or
21
+ * returned directly. Prefer passing the access-checked document as `doc` instead.
22
+ */
16
23
  prefixQueryParam?: string;
17
24
  req: PayloadRequest;
18
25
  uploadReference?: unknown;
26
+ useCompositePrefixes?: boolean;
19
27
  }): Promise<string>;
20
28
  //# sourceMappingURL=getFilePrefix.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/getFilePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAgB,MAAM,SAAS,CAAA;AAI7E;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CAAC,EAClC,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,GAAG,EACH,eAAe,GAChB,EAAE;IACD,UAAU,EAAE,gBAAgB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,GAAG,OAAO,CAAC,MAAM,CAAC,CAoClB"}
1
+ {"version":3,"file":"getFilePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/getFilePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAA;AAMzF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,UAAU,EACV,gBAAgB,EAChB,GAAG,EACH,QAAQ,EACR,gBAAgB,EAChB,GAAG,EACH,eAAe,EACf,oBAA4B,GAC7B,EAAE;IACD,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU,CAAA;IAC3D,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,CAqElB"}