@payloadcms/storage-s3 4.0.0-canary.35 → 4.0.0-canary.37

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.
package/dist/index.d.ts CHANGED
@@ -7,16 +7,6 @@ export type S3StorageOptions = {
7
7
  * Access control list for uploaded files.
8
8
  */
9
9
  acl?: 'private' | 'public-read';
10
- /**
11
- * When enabled, fields (like the prefix field) will always be inserted into
12
- * the collection schema regardless of whether the plugin is enabled. This
13
- * ensures a consistent schema across all environments.
14
- *
15
- * This will be enabled by default in Payload v4.
16
- *
17
- * @default false
18
- */
19
- alwaysInsertFields?: boolean;
20
10
  /**
21
11
  * Bucket name to upload files to.
22
12
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAK3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAIzD,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAE/B;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;;OAIG;IAEH,MAAM,EAAE,MAAM,CAAA;IAEd;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAClB,MAAM,CACJ,oBAAoB,EAClB,CAAC;QACC,eAAe,CAAC,EAAE,qBAAqB,CAAA;KACxC,GAAG,IAAI,CAAC,iBAAiB,E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AM,EAAE,cAAc,CAAA;IAEtB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAA;IACvC;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,gBAAgB,GAAG,CAAC,aAAa,EAAE,gBAAgB,KAAK,cAAc,CAAA;AAe3E,eAAO,MAAM,SAAS,EAAE,gBA8GtB,CAAA"}
package/dist/index.js CHANGED
@@ -29,24 +29,20 @@ export const s3Storage = (s3StorageOptions)=>({
29
29
  return s3Clients.get(cacheKey);
30
30
  };
31
31
  if (isPluginDisabled) {
32
- // If alwaysInsertFields is true, still call cloudStoragePlugin to insert fields
33
- if (s3StorageOptions.alwaysInsertFields) {
34
- // Build collections with adapter: null since plugin is disabled
35
- const collectionsWithoutAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
36
- ...acc,
37
- [slug]: {
38
- ...collOptions === true ? {} : collOptions,
39
- adapter: null
40
- }
41
- }), {});
42
- return cloudStoragePlugin({
43
- alwaysInsertFields: true,
44
- collections: collectionsWithoutAdapter,
45
- enabled: false,
46
- useCompositePrefixes: s3StorageOptions.useCompositePrefixes
47
- })(incomingConfig);
48
- }
49
- return incomingConfig;
32
+ // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are
33
+ // inserted into the schema, keeping it consistent across environments.
34
+ const collectionsWithoutAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
35
+ ...acc,
36
+ [slug]: {
37
+ ...collOptions === true ? {} : collOptions,
38
+ adapter: null
39
+ }
40
+ }), {});
41
+ return cloudStoragePlugin({
42
+ collections: collectionsWithoutAdapter,
43
+ enabled: false,
44
+ useCompositePrefixes: s3StorageOptions.useCompositePrefixes
45
+ })(incomingConfig);
50
46
  }
51
47
  // Determine signedDownloads for this collection
52
48
  const resolveSignedDownloads = (slug)=>{
@@ -90,7 +86,6 @@ export const s3Storage = (s3StorageOptions)=>({
90
86
  })
91
87
  };
92
88
  return cloudStoragePlugin({
93
- alwaysInsertFields: s3StorageOptions.alwaysInsertFields,
94
89
  collections: collectionsWithAdapter,
95
90
  useCompositePrefixes: s3StorageOptions.useCompositePrefixes
96
91
  })(config);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { S3ClientConfig } from '@aws-sdk/client-s3'\nimport type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { NodeHttpHandlerOptions } from '@smithy/node-http-handler'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { S3 } from '@aws-sdk/client-s3'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport type { SignedDownloadsConfig } from './getFile.js'\n\nimport { createS3Adapter } from './adapter.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n acl?: 'private' | 'public-read'\n\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\n /**\n * Bucket name to upload files to.\n *\n * Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).\n */\n\n bucket: string\n\n /**\n * Optional cache key to identify the S3 storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `s3:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Upload directly to S3 instead of through Payload. You must allow CORS PUT requests from your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<\n Record<\n UploadCollectionSlug,\n | ({\n signedDownloads?: SignedDownloadsConfig\n } & Omit<CollectionOptions, 'adapter'>)\n | true\n >\n >\n /**\n * AWS S3 client configuration. Highly dependent on your AWS setup.\n *\n * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)\n */\n config: S3ClientConfig\n\n /**\n * Whether or not to disable local storage\n *\n * @default true\n */\n disableLocalStorage?: boolean\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Use pre-signed URLs for files downloading. Can be overriden per-collection.\n */\n signedDownloads?: SignedDownloadsConfig\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), a document prefix already within the\n * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.\n * Existing files retain their stored prefixes for reads, URLs, and cleanup.\n *\n * Example with a document prefix already contained by the collection prefix:\n * - collection prefix: `uploads/`\n * - document prefix: `uploads/documents/`\n * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`\n * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype S3StorageFactory = (storageS3Args: S3StorageOptions) => StorageAdapter\n\nconst s3Clients = new Map<string, S3>()\n\nconst defaultRequestHandlerOpts: NodeHttpHandlerOptions = {\n httpAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n httpsAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n}\n\nexport const s3Storage: S3StorageFactory = (\n s3StorageOptions: S3StorageOptions,\n): StorageAdapter => ({\n name: 's3',\n collections: Object.keys(s3StorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`\n\n const isPluginDisabled = s3StorageOptions.enabled === false\n\n const getStorageClient: () => S3 = () => {\n if (s3Clients.has(cacheKey)) {\n return s3Clients.get(cacheKey)!\n }\n\n s3Clients.set(\n cacheKey,\n new S3({\n requestHandler: defaultRequestHandlerOpts,\n ...(s3StorageOptions.config ?? {}),\n }),\n )\n\n return s3Clients.get(cacheKey)!\n }\n\n if (isPluginDisabled) {\n // If alwaysInsertFields is true, still call cloudStoragePlugin to insert fields\n if (s3StorageOptions.alwaysInsertFields) {\n // Build collections with adapter: null since plugin is disabled\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: null,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n alwaysInsertFields: true,\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\n\n return incomingConfig\n }\n\n // Determine signedDownloads for this collection\n const resolveSignedDownloads = (slug: string): SignedDownloadsConfig => {\n const collectionStorageConfig = s3StorageOptions.collections[slug]\n\n let signedDownloads: null | SignedDownloadsConfig =\n typeof collectionStorageConfig === 'object'\n ? (collectionStorageConfig.signedDownloads ?? false)\n : null\n\n if (signedDownloads === null) {\n signedDownloads = s3StorageOptions.signedDownloads ?? false\n }\n\n return signedDownloads\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: createS3Adapter({\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n clientUploads: s3StorageOptions.clientUploads,\n config: s3StorageOptions.config,\n getStorageClient,\n signedDownloads: resolveSignedDownloads(slug),\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n alwaysInsertFields: s3StorageOptions.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["S3","cloudStoragePlugin","createS3Adapter","s3Clients","Map","defaultRequestHandlerOpts","httpAgent","keepAlive","maxSockets","httpsAgent","s3Storage","s3StorageOptions","name","collections","Object","keys","init","incomingConfig","cacheKey","clientCacheKey","bucket","isPluginDisabled","enabled","getStorageClient","has","get","set","requestHandler","config","alwaysInsertFields","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","resolveSignedDownloads","collectionStorageConfig","signedDownloads","collectionsWithAdapter","acl","clientUploads","map","collection","upload","disableLocalStorage"],"mappings":"AASA,SAASA,EAAE,QAAQ,qBAAoB;AACvC,SAASC,kBAAkB,QAAQ,mCAAkC;AAIrE,SAASC,eAAe,QAAQ,eAAc;AA8F9C,MAAMC,YAAY,IAAIC;AAEtB,MAAMC,4BAAoD;IACxDC,WAAW;QACTC,WAAW;QACXC,YAAY;IACd;IACAC,YAAY;QACVF,WAAW;QACXC,YAAY;IACd;AACF;AAEA,OAAO,MAAME,YAA8B,CACzCC,mBACoB,CAAA;QACpBC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACJ,iBAAiBE,WAAW;QACrDG,MAAM,CAACC;YACL,MAAMC,WAAWP,iBAAiBQ,cAAc,IAAI,CAAC,GAAG,EAAER,iBAAiBS,MAAM,EAAE;YAEnF,MAAMC,mBAAmBV,iBAAiBW,OAAO,KAAK;YAEtD,MAAMC,mBAA6B;gBACjC,IAAIpB,UAAUqB,GAAG,CAACN,WAAW;oBAC3B,OAAOf,UAAUsB,GAAG,CAACP;gBAC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AAiB+B,GAAG;4BACzBtB,QAAQT,iBAAiBS,MAAM;4BAC/BuB,eAAehC,iBAAiBgC,aAAa;4BAC7Cf,QAAQjB,iBAAiBiB,MAAM;4BAC/BL;4BACAiB,iBAAiBF,uBAAuBJ;4BACxCG,sBAAsB1B,iBAAiB0B,oBAAoB;wBAC7D;oBACF;gBACF,CAAA,GACA,CAAC;YAGH,gFAAgF;YAChF,MAAMT,SAAS;gBACb,GAAGX,cAAc;gBACjBJ,aAAa,AAACI,CAAAA,eAAeJ,WAAW,IAAI,EAAE,AAAD,EAAG+B,GAAG,CAAC,CAACC;oBACnD,IAAI,CAACJ,sBAAsB,CAACI,WAAWX,IAAI,CAAC,EAAE;wBAC5C,OAAOW;oBACT;oBAEA,OAAO;wBACL,GAAGA,UAAU;wBACbC,QAAQ;4BACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;4BAClEC,qBAAqB;wBACvB;oBACF;gBACF;YACF;YAEA,OAAO9C,mBAAmB;gBACxB4B,oBAAoBlB,iBAAiBkB,kBAAkB;gBACvDhB,aAAa4B;gBACbJ,sBAAsB1B,iBAAiB0B,oBAAoB;YAC7D,GAAGT;QACL;IACF,CAAA,EAAE"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { S3ClientConfig } from '@aws-sdk/client-s3'\nimport type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { NodeHttpHandlerOptions } from '@smithy/node-http-handler'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { S3 } from '@aws-sdk/client-s3'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport type { SignedDownloadsConfig } from './getFile.js'\n\nimport { createS3Adapter } from './adapter.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n acl?: 'private' | 'public-read'\n\n /**\n * Bucket name to upload files to.\n *\n * Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).\n */\n\n bucket: string\n\n /**\n * Optional cache key to identify the S3 storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `s3:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Upload directly to S3 instead of through Payload. You must allow CORS PUT requests from your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<\n Record<\n UploadCollectionSlug,\n | ({\n signedDownloads?: SignedDownloadsConfig\n } & Omit<CollectionOptions, 'adapter'>)\n | true\n >\n >\n /**\n * AWS S3 client configuration. Highly dependent on your AWS setup.\n *\n * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)\n */\n config: S3ClientConfig\n\n /**\n * Whether or not to disable local storage\n *\n * @default true\n */\n disableLocalStorage?: boolean\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Use pre-signed URLs for files downloading. Can be overriden per-collection.\n */\n signedDownloads?: SignedDownloadsConfig\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), a document prefix already within the\n * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.\n * Existing files retain their stored prefixes for reads, URLs, and cleanup.\n *\n * Example with a document prefix already contained by the collection prefix:\n * - collection prefix: `uploads/`\n * - document prefix: `uploads/documents/`\n * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`\n * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype S3StorageFactory = (storageS3Args: S3StorageOptions) => StorageAdapter\n\nconst s3Clients = new Map<string, S3>()\n\nconst defaultRequestHandlerOpts: NodeHttpHandlerOptions = {\n httpAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n httpsAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n}\n\nexport const s3Storage: S3StorageFactory = (\n s3StorageOptions: S3StorageOptions,\n): StorageAdapter => ({\n name: 's3',\n collections: Object.keys(s3StorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`\n\n const isPluginDisabled = s3StorageOptions.enabled === false\n\n const getStorageClient: () => S3 = () => {\n if (s3Clients.has(cacheKey)) {\n return s3Clients.get(cacheKey)!\n }\n\n s3Clients.set(\n cacheKey,\n new S3({\n requestHandler: defaultRequestHandlerOpts,\n ...(s3StorageOptions.config ?? {}),\n }),\n )\n\n return s3Clients.get(cacheKey)!\n }\n\n if (isPluginDisabled) {\n // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are\n // inserted into the schema, keeping it consistent across environments.\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: null,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\n\n // Determine signedDownloads for this collection\n const resolveSignedDownloads = (slug: string): SignedDownloadsConfig => {\n const collectionStorageConfig = s3StorageOptions.collections[slug]\n\n let signedDownloads: null | SignedDownloadsConfig =\n typeof collectionStorageConfig === 'object'\n ? (collectionStorageConfig.signedDownloads ?? false)\n : null\n\n if (signedDownloads === null) {\n signedDownloads = s3StorageOptions.signedDownloads ?? false\n }\n\n return signedDownloads\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: createS3Adapter({\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n clientUploads: s3StorageOptions.clientUploads,\n config: s3StorageOptions.config,\n getStorageClient,\n signedDownloads: resolveSignedDownloads(slug),\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n collections: collectionsWithAdapter,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["S3","cloudStoragePlugin","createS3Adapter","s3Clients","Map","defaultRequestHandlerOpts","httpAgent","keepAlive","maxSockets","httpsAgent","s3Storage","s3StorageOptions","name","collections","Object","keys","init","incomingConfig","cacheKey","clientCacheKey","bucket","isPluginDisabled","enabled","getStorageClient","has","get","set","requestHandler","config","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","resolveSignedDownloads","collectionStorageConfig","signedDownloads","collectionsWithAdapter","acl","clientUploads","map","collection","upload","disableLocalStorage"],"mappings":"AASA,SAASA,EAAE,QAAQ,qBAAoB;AACvC,SAASC,kBAAkB,QAAQ,mCAAkC;AAIrE,SAASC,eAAe,QAAQ,eAAc;AAmF9C,MAAMC,YAAY,IAAIC;AAEtB,MAAMC,4BAAoD;IACxDC,WAAW;QACTC,WAAW;QACXC,YAAY;IACd;IACAC,YAAY;QACVF,WAAW;QACXC,YAAY;IACd;AACF;AAEA,OAAO,MAAME,YAA8B,CACzCC,mBACoB,CAAA;QACpBC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACJ,iBAAiBE,WAAW;QACrDG,MAAM,CAACC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Y,GAAM,CAAA;oBAC7B,GAAGF,GAAG;oBACN,CAACC,KAAK,EAAE;wBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;wBAC3CC,SAASjC,gBAAgB;4BACvBuC,KAAK9B,iBAAiB8B,GAAG;4BACzBrB,QAAQT,iBAAiBS,MAAM;4BAC/BsB,eAAe/B,iBAAiB+B,aAAa;4BAC7Cd,QAAQjB,iBAAiBiB,MAAM;4BAC/BL;4BACAgB,iBAAiBF,uBAAuBJ;4BACxCG,sBAAsBzB,iBAAiByB,oBAAoB;wBAC7D;oBACF;gBACF,CAAA,GACA,CAAC;YAGH,gFAAgF;YAChF,MAAMR,SAAS;gBACb,GAAGX,cAAc;gBACjBJ,aAAa,AAACI,CAAAA,eAAeJ,WAAW,IAAI,EAAE,AAAD,EAAG8B,GAAG,CAAC,CAACC;oBACnD,IAAI,CAACJ,sBAAsB,CAACI,WAAWX,IAAI,CAAC,EAAE;wBAC5C,OAAOW;oBACT;oBAEA,OAAO;wBACL,GAAGA,UAAU;wBACbC,QAAQ;4BACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;4BAClEC,qBAAqB;wBACvB;oBACF;gBACF;YACF;YAEA,OAAO7C,mBAAmB;gBACxBY,aAAa2B;gBACbJ,sBAAsBzB,iBAAiByB,oBAAoB;YAC7D,GAAGR;QACL;IACF,CAAA,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-s3",
3
- "version": "4.0.0-canary.35",
3
+ "version": "4.0.0-canary.37",
4
4
  "description": "Payload storage adapter for Amazon S3",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -35,14 +35,14 @@
35
35
  "@aws-sdk/client-s3": "^3.614.0",
36
36
  "@aws-sdk/lib-storage": "^3.614.0",
37
37
  "@aws-sdk/s3-request-presigner": "^3.614.0",
38
- "@payloadcms/plugin-cloud-storage": "4.0.0-canary.35"
38
+ "@payloadcms/plugin-cloud-storage": "4.0.0-canary.37"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@smithy/node-http-handler": "4.0.3",
42
- "payload": "4.0.0-canary.35"
42
+ "payload": "4.0.0-canary.37"
43
43
  },
44
44
  "peerDependencies": {
45
- "payload": "4.0.0-canary.35"
45
+ "payload": "4.0.0-canary.37"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=24.15.0"
@@ -1,72 +0,0 @@
1
- import { Readable } from 'node:stream';
2
- import { describe, expect, it, vi } from 'vitest';
3
- import { createS3Adapter } from './adapter.js';
4
- describe('static handler document locations', ()=>{
5
- it('should read the checked document without another lookup', async ()=>{
6
- const headObject = vi.fn(async ()=>({
7
- ContentLength: 4,
8
- ContentType: 'image/png'
9
- }));
10
- const getObject = vi.fn(async ()=>({
11
- Body: Readable.from([
12
- 'file'
13
- ])
14
- }));
15
- const adapter = createS3Adapter({
16
- bucket: 'bucket',
17
- config: {},
18
- getStorageClient: ()=>({
19
- getObject,
20
- headObject
21
- }),
22
- signedDownloads: false
23
- });
24
- const find = vi.fn(async ()=>({
25
- docs: [
26
- {
27
- prefix: 'database'
28
- }
29
- ]
30
- }));
31
- const generatedAdapter = adapter({
32
- collection: {
33
- fields: [],
34
- slug: 'media',
35
- upload: {}
36
- },
37
- prefix: 'media'
38
- });
39
- const doc = {
40
- id: 'authorized',
41
- prefix: 'legacy'
42
- };
43
- const response = await generatedAdapter.staticHandler({
44
- headers: new Headers(),
45
- payload: {
46
- find,
47
- logger: {
48
- error: vi.fn()
49
- }
50
- }
51
- }, {
52
- doc,
53
- params: {
54
- collection: 'media',
55
- filename: 'original.png'
56
- }
57
- });
58
- expect(response.status).toBe(200);
59
- expect(await response.text()).toBe('file');
60
- expect(headObject).toHaveBeenCalledWith({
61
- Bucket: 'bucket',
62
- Key: 'legacy/original.png'
63
- });
64
- expect(getObject).toHaveBeenCalledWith(expect.objectContaining({
65
- Bucket: 'bucket',
66
- Key: 'legacy/original.png'
67
- }), expect.any(Object));
68
- expect(find).not.toHaveBeenCalled();
69
- });
70
- });
71
-
72
- //# sourceMappingURL=staticHandler.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/staticHandler.spec.ts"],"sourcesContent":["import { Readable } from 'node:stream'\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { createS3Adapter } from './adapter.js'\n\ndescribe('static handler document locations', () => {\n it('should read the checked document without another lookup', async () => {\n const headObject = vi.fn(async () => ({ ContentLength: 4, ContentType: 'image/png' }))\n const getObject = vi.fn(async () => ({ Body: Readable.from(['file']) }))\n const adapter = createS3Adapter({\n bucket: 'bucket',\n config: {},\n getStorageClient: () => ({ getObject, headObject }) as never,\n signedDownloads: false,\n })\n const find = vi.fn(async () => ({ docs: [{ prefix: 'database' }] }))\n const generatedAdapter = adapter({\n collection: {\n fields: [],\n slug: 'media',\n upload: {},\n },\n prefix: 'media',\n })\n const doc = {\n id: 'authorized',\n prefix: 'legacy',\n }\n const response = await generatedAdapter.staticHandler(\n {\n headers: new Headers(),\n payload: { find, logger: { error: vi.fn() } },\n } as never,\n {\n doc,\n params: { collection: 'media', filename: 'original.png' },\n },\n )\n\n expect(response.status).toBe(200)\n expect(await response.text()).toBe('file')\n expect(headObject).toHaveBeenCalledWith({ Bucket: 'bucket', Key: 'legacy/original.png' })\n expect(getObject).toHaveBeenCalledWith(\n expect.objectContaining({ Bucket: 'bucket', Key: 'legacy/original.png' }),\n expect.any(Object),\n )\n expect(find).not.toHaveBeenCalled()\n })\n})\n"],"names":["Readable","describe","expect","it","vi","createS3Adapter","headObject","fn","ContentLength","ContentType","getObject","Body","from","adapter","bucket","config","getStorageClient","signedDownloads","find","docs","prefix","generatedAdapter","collection","fields","slug","upload","doc","id","response","staticHandler","headers","Headers","payload","logger","error","params","filename","status","toBe","text","toHaveBeenCalledWith","Bucket","Key","objectContaining","any","Object","not","toHaveBeenCalled"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAa;AACtC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