@payloadcms/storage-vercel-blob 4.0.0-canary.34 → 4.0.0-canary.36

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
@@ -14,16 +14,6 @@ export type VercelBlobStorageOptions = {
14
14
  * @default false
15
15
  */
16
16
  addRandomSuffix?: boolean;
17
- /**
18
- * When enabled, fields (like the prefix field) will always be inserted into
19
- * the collection schema regardless of whether the plugin is enabled. This
20
- * ensures a consistent schema across all environments.
21
- *
22
- * This will be enabled by default in Payload v4.
23
- *
24
- * @default false
25
- */
26
- alwaysInsertFields?: boolean;
27
17
  /**
28
18
  * Cache-Control max-age in seconds
29
19
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAW3E,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IAEjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IAEnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAE7F;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAEzB;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AASD,KAAK,wBAAwB,GAAG,CAAC,qBAAqB,EAAE,wBAAwB,KAAK,cAAc,CAAA;AAEnG,eAAO,MAAM,iBAAiB,EAAE,wBA4G/B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAW3E,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IAEjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IAEnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAE7F;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAEzB;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AASD,KAAK,wBAAwB,GAAG,CAAC,qBAAqB,EAAE,wBAAwB,KAAK,cAAc,CAAA;AAEnG,eAAO,MAAM,iBAAiB,EAAE,wBAwG/B,CAAA"}
package/dist/index.js CHANGED
@@ -26,22 +26,18 @@ export const vercelBlobStorage = (options)=>{
26
26
  const baseUrl = process.env.STORAGE_VERCEL_BLOB_BASE_URL || `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`;
27
27
  // If the plugin is disabled or no token is provided, do not enable the plugin
28
28
  if (isPluginDisabled) {
29
- if (options.alwaysInsertFields) {
30
- const collectionsWithoutAdapter = Object.entries(options.collections).reduce((acc, [slug, collOptions])=>({
31
- ...acc,
32
- [slug]: {
33
- ...collOptions === true ? {} : collOptions,
34
- adapter: null
35
- }
36
- }), {});
37
- return cloudStoragePlugin({
38
- alwaysInsertFields: true,
39
- collections: collectionsWithoutAdapter,
40
- enabled: false,
41
- useCompositePrefixes: options.useCompositePrefixes
42
- })(incomingConfig);
43
- }
44
- return incomingConfig;
29
+ const collectionsWithoutAdapter = Object.entries(options.collections).reduce((acc, [slug, collOptions])=>({
30
+ ...acc,
31
+ [slug]: {
32
+ ...collOptions === true ? {} : collOptions,
33
+ adapter: null
34
+ }
35
+ }), {});
36
+ return cloudStoragePlugin({
37
+ collections: collectionsWithoutAdapter,
38
+ enabled: false,
39
+ useCompositePrefixes: options.useCompositePrefixes
40
+ })(incomingConfig);
45
41
  }
46
42
  const adapter = createVercelBlobAdapter({
47
43
  access: optionsWithDefaults.access ?? 'public',
@@ -81,7 +77,6 @@ export const vercelBlobStorage = (options)=>{
81
77
  })
82
78
  };
83
79
  return cloudStoragePlugin({
84
- alwaysInsertFields: options.alwaysInsertFields,
85
80
  collections: collectionsWithAdapter,
86
81
  useCompositePrefixes: options.useCompositePrefixes
87
82
  })(config);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { createVercelBlobAdapter } from './adapter.js'\nimport {\n getCollectionSources,\n type InternalVercelBlobStorageAdapter,\n vercelBlobStorageMetadata,\n} from './getCollectionSources.js'\n\nexport type VercelBlobStorageOptions = {\n /**\n * Access control level. Currently, only 'public' is supported.\n * Vercel plans on adding support for private blobs in the future.\n *\n * @default 'public'\n */\n access?: 'public'\n\n /**\n * Add a random suffix to the uploaded file name in Vercel Blob storage\n *\n * @default false\n */\n addRandomSuffix?: boolean\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 * Cache-Control max-age in seconds\n *\n * @default 365 * 24 * 60 * 60 // (1 Year)\n */\n cacheControlMaxAge?: number\n\n /**\n * Upload directly to Vercel Blob instead of through Payload.\n */\n clientUploads?: ClientUploadsConfig\n\n /**\n * Collections to apply the Vercel Blob adapter to\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Vercel Blob storage read/write token\n *\n * Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel\n *\n * If unset, the plugin will be disabled and will fallback to local storage\n */\n token: string | undefined\n\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\nconst defaultUploadOptions: Partial<VercelBlobStorageOptions> = {\n access: 'public',\n addRandomSuffix: false,\n cacheControlMaxAge: 60 * 60 * 24 * 365, // 1 year\n enabled: true,\n}\n\ntype VercelBlobStorageFactory = (vercelBlobStorageOpts: VercelBlobStorageOptions) => StorageAdapter\n\nexport const vercelBlobStorage: VercelBlobStorageFactory = (\n options: VercelBlobStorageOptions,\n): StorageAdapter => {\n const storeId = options.token?.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]?.toLowerCase()\n const isPluginDisabled = options.enabled === false || !options.token\n const storageAdapter: InternalVercelBlobStorageAdapter = {\n name: 'vercel-blob',\n collections: Object.keys(options.collections),\n init: (incomingConfig: Config): Config => {\n // Don't throw if the plugin is disabled\n if (!storeId && !isPluginDisabled) {\n throw new Error(\n 'Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.',\n )\n }\n\n const optionsWithDefaults = {\n ...defaultUploadOptions,\n ...options,\n }\n\n // support overriding the base URL for emulator https://github.com/payloadcms/vercel-blob-emulator\n const baseUrl =\n process.env.STORAGE_VERCEL_BLOB_BASE_URL ||\n `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`\n\n // If the plugin is disabled or no token is provided, do not enable the plugin\n if (isPluginDisabled) {\n if (options.alwaysInsertFields) {\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] =\n Object.entries(options.collections).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: { ...(collOptions === true ? {} : collOptions), adapter: null },\n }),\n {} as Record<string, CollectionOptions>,\n )\n return cloudStoragePlugin({\n alwaysInsertFields: true,\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: options.useCompositePrefixes,\n })(incomingConfig)\n }\n return incomingConfig\n }\n\n const adapter = createVercelBlobAdapter({\n access: optionsWithDefaults.access ?? 'public',\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n baseUrl,\n cacheControlMaxAge: optionsWithDefaults.cacheControlMaxAge ?? 60 * 60 * 24 * 365,\n clientUploads: optionsWithDefaults.clientUploads,\n collectionSources: getCollectionSources({\n currentAdapter: storageAdapter,\n storageAdapters: incomingConfig.storage,\n }),\n token: options.token!,\n useCompositePrefixes: options.useCompositePrefixes,\n })\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\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: options.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: options.useCompositePrefixes,\n })(config)\n },\n [vercelBlobStorageMetadata]: {\n collections: options.collections,\n enabled: !isPluginDisabled,\n storeId,\n useCompositePrefixes: Boolean(options.useCompositePrefixes),\n },\n }\n\n return storageAdapter\n}\n"],"names":["cloudStoragePlugin","createVercelBlobAdapter","getCollectionSources","vercelBlobStorageMetadata","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","storeId","token","match","toLowerCase","isPluginDisabled","storageAdapter","name","collections","Object","keys","init","incomingConfig","Error","optionsWithDefaults","baseUrl","process","env","STORAGE_VERCEL_BLOB_BASE_URL","alwaysInsertFields","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","clientUploads","collectionSources","currentAdapter","storageAdapters","storage","collectionsWithAdapter","config","map","collection","upload","disableLocalStorage","Boolean"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,uBAAuB,QAAQ,eAAc;AACtD,SACEC,oBAAoB,EAEpBC,yBAAyB,QACpB,4BAA2B;AA8ElC,MAAMC,uBAA0D;IAC9DC,QAAQ;IACRC,iBAAiB;IACjBC,oBAAoB,KAAK,K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type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { createVercelBlobAdapter } from './adapter.js'\nimport {\n getCollectionSources,\n type InternalVercelBlobStorageAdapter,\n vercelBlobStorageMetadata,\n} from './getCollectionSources.js'\n\nexport type VercelBlobStorageOptions = {\n /**\n * Access control level. Currently, only 'public' is supported.\n * Vercel plans on adding support for private blobs in the future.\n *\n * @default 'public'\n */\n access?: 'public'\n\n /**\n * Add a random suffix to the uploaded file name in Vercel Blob storage\n *\n * @default false\n */\n addRandomSuffix?: boolean\n\n /**\n * Cache-Control max-age in seconds\n *\n * @default 365 * 24 * 60 * 60 // (1 Year)\n */\n cacheControlMaxAge?: number\n\n /**\n * Upload directly to Vercel Blob instead of through Payload.\n */\n clientUploads?: ClientUploadsConfig\n\n /**\n * Collections to apply the Vercel Blob adapter to\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Vercel Blob storage read/write token\n *\n * Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel\n *\n * If unset, the plugin will be disabled and will fallback to local storage\n */\n token: string | undefined\n\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\nconst defaultUploadOptions: Partial<VercelBlobStorageOptions> = {\n access: 'public',\n addRandomSuffix: false,\n cacheControlMaxAge: 60 * 60 * 24 * 365, // 1 year\n enabled: true,\n}\n\ntype VercelBlobStorageFactory = (vercelBlobStorageOpts: VercelBlobStorageOptions) => StorageAdapter\n\nexport const vercelBlobStorage: VercelBlobStorageFactory = (\n options: VercelBlobStorageOptions,\n): StorageAdapter => {\n const storeId = options.token?.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]?.toLowerCase()\n const isPluginDisabled = options.enabled === false || !options.token\n const storageAdapter: InternalVercelBlobStorageAdapter = {\n name: 'vercel-blob',\n collections: Object.keys(options.collections),\n init: (incomingConfig: Config): Config => {\n // Don't throw if the plugin is disabled\n if (!storeId && !isPluginDisabled) {\n throw new Error(\n 'Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.',\n )\n }\n\n const optionsWithDefaults = {\n ...defaultUploadOptions,\n ...options,\n }\n\n // support overriding the base URL for emulator https://github.com/payloadcms/vercel-blob-emulator\n const baseUrl =\n process.env.STORAGE_VERCEL_BLOB_BASE_URL ||\n `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`\n\n // If the plugin is disabled or no token is provided, do not enable the plugin\n if (isPluginDisabled) {\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: { ...(collOptions === true ? {} : collOptions), adapter: null },\n }),\n {} as Record<string, CollectionOptions>,\n )\n return cloudStoragePlugin({\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: options.useCompositePrefixes,\n })(incomingConfig)\n }\n\n const adapter = createVercelBlobAdapter({\n access: optionsWithDefaults.access ?? 'public',\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n baseUrl,\n cacheControlMaxAge: optionsWithDefaults.cacheControlMaxAge ?? 60 * 60 * 24 * 365,\n clientUploads: optionsWithDefaults.clientUploads,\n collectionSources: getCollectionSources({\n currentAdapter: storageAdapter,\n storageAdapters: incomingConfig.storage,\n }),\n token: options.token!,\n useCompositePrefixes: options.useCompositePrefixes,\n })\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\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: options.useCompositePrefixes,\n })(config)\n },\n [vercelBlobStorageMetadata]: {\n collections: options.collections,\n enabled: !isPluginDisabled,\n storeId,\n useCompositePrefixes: Boolean(options.useCompositePrefixes),\n },\n }\n\n return storageAdapter\n}\n"],"names":["cloudStoragePlugin","createVercelBlobAdapter","getCollectionSources","vercelBlobStorageMetadata","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","storeId","token","match","toLowerCase","isPluginDisabled","storageAdapter","name","collections","Object","keys","init","incomingConfig","Error","optionsWithDefaults","baseUrl","process","env","STORAGE_VERCEL_BLOB_BASE_URL","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","clientUploads","collectionSources","currentAdapter","storageAdapters","storage","collectionsWithAdapter","config","map","collection","upload","disableLocalStorage","Boolean"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,uBAAuB,QAAQ,eAAc;AACtD,SACEC,oBAAoB,EAEpBC,yBAAyB,QACpB,4BAA2B;AAmElC,MAAMC,uBAA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ary.34",
3
+ "version": "4.0.0-canary.36",
4
4
  "description": "Payload storage adapter for Vercel Blob Storage",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -38,13 +38,13 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@vercel/blob": "2.3.1",
41
- "@payloadcms/plugin-cloud-storage": "4.0.0-canary.34"
41
+ "@payloadcms/plugin-cloud-storage": "4.0.0-canary.36"
42
42
  },
43
43
  "devDependencies": {
44
- "payload": "4.0.0-canary.34"
44
+ "payload": "4.0.0-canary.36"
45
45
  },
46
46
  "peerDependencies": {
47
- "payload": "4.0.0-canary.34"
47
+ "payload": "4.0.0-canary.36"
48
48
  },
49
49
  "engines": {
50
50
  "node": ">=24.15.0"
@@ -1,124 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- const mocks = vi.hoisted(()=>({
3
- generateClientToken: vi.fn(async ()=>'client-token'),
4
- // Resolves the stored location of an owning document, so it matches the requested key.
5
- buildStoragePathData: vi.fn(()=>({
6
- storageFilePath: 'reference.png',
7
- sanitizedCollectionPrefix: '',
8
- sanitizedDocPrefix: '',
9
- sanitizedFilename: 'reference.png'
10
- })),
11
- buildUploadStoragePathData: vi.fn(()=>({
12
- storageFilePath: 'reference.png',
13
- sanitizedCollectionPrefix: '',
14
- sanitizedDocPrefix: '',
15
- sanitizedFilename: 'reference.png'
16
- })),
17
- isStoragePathWithinCollectionPrefix: vi.fn(()=>true),
18
- resolveSignedURLKey: vi.fn(async ()=>({
19
- storageFilePath: 'reference-1.png',
20
- sanitizedDocPrefix: '',
21
- sanitizedFilename: 'reference-1.png',
22
- uploadReference: {
23
- prefix: '',
24
- signedReceipt: 'upload-receipt'
25
- }
26
- }))
27
- }));
28
- vi.mock('@payloadcms/plugin-cloud-storage/utilities', ()=>({
29
- buildStoragePathData: mocks.buildStoragePathData,
30
- buildUploadStoragePathData: mocks.buildUploadStoragePathData,
31
- isStoragePathWithinCollectionPrefix: mocks.isStoragePathWithinCollectionPrefix,
32
- resolveSignedURLKey: mocks.resolveSignedURLKey
33
- }));
34
- vi.mock('@vercel/blob/client', ()=>({
35
- generateClientTokenFromReadWriteToken: mocks.generateClientToken
36
- }));
37
- import { createVercelBlobAdapter } from './adapter.js';
38
- const generateInstructions = async ({ hasOwner })=>{
39
- const adapter = createVercelBlobAdapter({
40
- access: 'public',
41
- baseUrl: 'https://example.com',
42
- cacheControlMaxAge: 60,
43
- clientUploads: true,
44
- collectionSources: [
45
- {
46
- collectionPrefix: '',
47
- collectionSlug: 'media',
48
- useCompositePrefixes: false
49
- }
50
- ],
51
- token: 'read-write-token'
52
- });
53
- const generatedAdapter = adapter({
54
- collection: {
55
- slug: 'media'
56
- },
57
- prefix: ''
58
- });
59
- const req = {
60
- payload: {
61
- collections: {
62
- media: {
63
- config: {
64
- access: {
65
- update: async ()=>true
66
- },
67
- upload: true
68
- }
69
- }
70
- },
71
- find: vi.fn(async ()=>({
72
- docs: hasOwner ? [
73
- {
74
- filename: 'reference.png',
75
- id: 1
76
- }
77
- ] : []
78
- })),
79
- secret: 'secret'
80
- },
81
- t: vi.fn()
82
- };
83
- return generatedAdapter.uploadInstructions?.generate({
84
- collectionSlug: 'media',
85
- filename: 'reference.png',
86
- filesize: 100,
87
- mimeType: 'image/png',
88
- overrideAccess: true,
89
- req
90
- });
91
- };
92
- describe('createVercelBlobAdapter', ()=>{
93
- beforeEach(()=>{
94
- vi.clearAllMocks();
95
- });
96
- it('should disable overwrite when no document owns the requested key', async ()=>{
97
- const instructions = await generateInstructions({
98
- hasOwner: false
99
- });
100
- const tokenOptions = mocks.generateClientToken.mock.calls[0][0];
101
- expect(instructions).toMatchObject({
102
- data: {
103
- pathname: 'reference-1.png'
104
- }
105
- });
106
- expect(tokenOptions).not.toHaveProperty('allowOverwrite');
107
- });
108
- it('should allow an authorized owner to update the requested key', async ()=>{
109
- const instructions = await generateInstructions({
110
- hasOwner: true
111
- });
112
- expect(instructions).toMatchObject({
113
- data: {
114
- pathname: 'reference.png'
115
- }
116
- });
117
- expect(mocks.generateClientToken).toHaveBeenCalledWith(expect.objectContaining({
118
- allowOverwrite: true,
119
- pathname: 'reference.png'
120
- }));
121
- });
122
- });
123
-
124
- //# sourceMappingURL=adapter.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/adapter.spec.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { beforeEach, describe, expect, it, vi } from 'vitest'\n\nconst mocks = vi.hoisted(() => ({\n generateClientToken: vi.fn(async () => 'client-token'),\n // Resolves the stored location of an owning document, so it matches the requested key.\n buildStoragePathData: vi.fn(() => ({\n storageFilePath: 'reference.png',\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'reference.png',\n })),\n buildUploadStoragePathData: vi.fn(() => ({\n storageFilePath: 'reference.png',\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'reference.png',\n })),\n isStoragePathWithinCollectionPrefix: vi.fn(() => true),\n resolveSignedURLKey: vi.fn(async () => ({\n storageFilePath: 'reference-1.png',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'reference-1.png',\n uploadReference: { prefix: '', signedReceipt: 'upload-receipt' },\n })),\n}))\n\nvi.mock('@payloadcms/plugin-cloud-storage/utilities', () => ({\n buildStoragePathData: mocks.buildStoragePathData,\n buildUploadStoragePathData: mocks.buildUploadStoragePathData,\n isStoragePathWithinCollectionPrefix: mocks.isStoragePathWithinCollectionPrefix,\n resolveSignedURLKey: mocks.resolveSignedURLKey,\n}))\n\nvi.mock('@vercel/blob/client', () => ({\n generateClientTokenFromReadWriteToken: mocks.generateClientToken,\n}))\n\nimport { createVercelBlobAdapter } from './adapter.js'\n\nconst generateInstructions = async ({ hasOwner }: { hasOwner: boolean }) => {\n const adapter = createVercelBlobAdapter({\n access: 'public',\n baseUrl: 'https://example.com',\n cacheControlMaxAge: 60,\n clientUploads: true,\n collectionSources: [\n { collectionPrefix: '', collectionSlug: 'media', useCompositePrefixes: false },\n ],\n token: 'read-write-token',\n })\n const generatedAdapter = adapter({\n collection: { slug: 'media' },\n prefix: '',\n } as never)\n const req = {\n payload: {\n collections: {\n media: { config: { access: { update: async () => true }, upload: true } },\n },\n find: vi.fn(async () => ({\n docs: hasOwner ? [{ filename: 'reference.png', id: 1 }] : [],\n })),\n secret: 'secret',\n },\n t: vi.fn(),\n } as unknown as PayloadRequest\n\n return generatedAdapter.uploadInstructions?.generate({\n collectionSlug: 'media',\n filename: 'reference.png',\n filesize: 100,\n mimeType: 'image/png',\n overrideAccess: true,\n req,\n })\n}\n\ndescribe('createVercelBlobAdapter', () => {\n beforeEach(() => {\n vi.clearAllMocks()\n })\n\n it('should disable overwrite when no document owns the requested key', async () => {\n const instructions = await generateInstructions({ hasOwner: false })\n const tokenOptions = mocks.generateClientToken.mock.calls[0]![0]\n\n expect(instructions).toMatchObject({ data: { pathname: 'reference-1.png' } })\n expect(tokenOptions).not.toHaveProperty('allowOverwrite')\n })\n\n it('should allow an authorized owner to update the requested key', async () => {\n const instructions = await generateInstructions({ hasOwner: true })\n\n expect(instructions).toMatchObject({ data: { pathname: 'reference.png' } })\n expect(mocks.generateClientToken).toHaveBeenCalledWith(\n expect.objectContaining({ allowOverwrite: true, pathname: 'reference.png' }),\n )\n })\n})\n"],"names":["beforeEach","describe","expect","it","vi","mocks","hoisted","generateClientToken","fn","buildStoragePathData","storageFilePath","sanitizedCollectionPrefix","sanitizedDocPrefix","sanitizedFilename","buildUploadStoragePathData","isStoragePathWithinCollectionPrefix","resolveSignedURLKey","uploadReference","prefix","signedReceipt","mock","generateClientTokenFromReadWriteToken","createVercelBlobAdapter","generateInstructions","hasOwner","adapter","access","baseUrl","cacheControlMaxAge","clientUploads","collectionSources","collectionPrefix","collectionSlug","useCompositePrefixes","token","generatedAdapter","collection","slug","req","payload","collections","media","config","update","upload","find","docs","filename","id","secret","t","uploadInstructions","generate","filesize","mimeType","overrideAccess","clearAllMocks","instructions","tokenOptions","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BAAgB,CAAC;YAAEC,gBAAgB;YAAML,UAAU;QAAgB;IAE9E;AACF"}
@@ -1,92 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import { authorizeClientOverwrite } from './authorizeFileOverwrite.js';
3
- const owner = (id)=>({
4
- filename: 'image.png',
5
- id,
6
- prefix: 'shared'
7
- });
8
- const collectionSources = [
9
- {
10
- collectionPrefix: '',
11
- collectionSlug: 'media',
12
- useCompositePrefixes: false
13
- },
14
- {
15
- collectionPrefix: '',
16
- collectionSlug: 'protected',
17
- useCompositePrefixes: false
18
- }
19
- ];
20
- const createRequest = ({ mediaOwner = true, protectedOwner = false } = {})=>({
21
- payload: {
22
- collections: {
23
- media: {
24
- config: {
25
- access: {
26
- update: async ()=>true
27
- },
28
- upload: true
29
- }
30
- },
31
- protected: {
32
- config: {
33
- access: {
34
- update: async ()=>false
35
- },
36
- upload: true
37
- }
38
- }
39
- },
40
- find: vi.fn(async ({ collection })=>({
41
- docs: collection === 'media' ? mediaOwner ? [
42
- owner(1)
43
- ] : [] : protectedOwner ? [
44
- owner(2)
45
- ] : []
46
- }))
47
- },
48
- t: vi.fn()
49
- });
50
- describe('authorizeClientOverwrite', ()=>{
51
- it('allows an update when the requested collection is the only owner', async ()=>{
52
- await expect(authorizeClientOverwrite({
53
- collectionSources,
54
- requestedStorageFilePath: 'shared/image.png',
55
- requestedFilename: 'image.png',
56
- req: createRequest(),
57
- requestedCollectionSlug: 'media',
58
- collectionPrefix: ''
59
- })).resolves.toBe(true);
60
- });
61
- it('rejects an update when another collection owns the same key', async ()=>{
62
- await expect(authorizeClientOverwrite({
63
- collectionSources,
64
- requestedStorageFilePath: 'shared/image.png',
65
- requestedFilename: 'image.png',
66
- req: createRequest({
67
- mediaOwner: false,
68
- protectedOwner: true
69
- }),
70
- requestedCollectionSlug: 'media',
71
- collectionPrefix: ''
72
- })).rejects.toMatchObject({
73
- status: 403
74
- });
75
- });
76
- it('rejects an update when multiple collections own the same key', async ()=>{
77
- await expect(authorizeClientOverwrite({
78
- collectionSources,
79
- requestedStorageFilePath: 'shared/image.png',
80
- requestedFilename: 'image.png',
81
- req: createRequest({
82
- protectedOwner: true
83
- }),
84
- requestedCollectionSlug: 'media',
85
- collectionPrefix: ''
86
- })).rejects.toMatchObject({
87
- status: 403
88
- });
89
- });
90
- });
91
-
92
- //# sourceMappingURL=authorizeFileOverwrite.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/authorizeFileOverwrite.spec.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { authorizeClientOverwrite } from './authorizeFileOverwrite.js'\n\nconst owner = (id: number) => ({ filename: 'image.png', id, prefix: 'shared' })\nconst collectionSources = [\n { collectionPrefix: '', collectionSlug: 'media', useCompositePrefixes: false },\n { collectionPrefix: '', collectionSlug: 'protected', useCompositePrefixes: false },\n]\n\nconst createRequest = ({\n mediaOwner = true,\n protectedOwner = false,\n}: {\n mediaOwner?: boolean\n protectedOwner?: boolean\n} = {}) =>\n ({\n payload: {\n collections: {\n media: {\n config: { access: { update: async () => true }, upload: true },\n },\n protected: {\n config: { access: { update: async () => false }, upload: true },\n },\n },\n find: vi.fn(async ({ collection }: { collection: string }) => ({\n docs:\n collection === 'media'\n ? mediaOwner\n ? [owner(1)]\n : []\n : protectedOwner\n ? [owner(2)]\n : [],\n })),\n },\n t: vi.fn(),\n }) as unknown as PayloadRequest\n\ndescribe('authorizeClientOverwrite', () => {\n it('allows an update when the requested collection is the only owner', async () => {\n await expect(\n authorizeClientOverwrite({\n collectionSources,\n requestedStorageFilePath: 'shared/image.png',\n requestedFilename: 'image.png',\n req: createRequest(),\n requestedCollectionSlug: 'media',\n collectionPrefix: '',\n }),\n ).resolves.toBe(true)\n })\n\n it('rejects an update when another collection owns the same key', async () => {\n await expect(\n authorizeClientOverwrite({\n collectionSources,\n requestedStorageFilePath: 'shared/image.png',\n requestedFilename: 'image.png',\n req: createRequest({ mediaOwner: false, protectedOwner: true }),\n requestedCollectionSlug: 'media',\n collectionPrefix: '',\n }),\n ).rejects.toMatchObject({ status: 403 })\n })\n\n it('rejects an update when multiple collections own the same key', async () => {\n await expect(\n authorizeClientOverwrite({\n collectionSources,\n requestedStorageFilePath: 'shared/image.png',\n requestedFilename: 'image.png',\n req: createRequest({ protectedOwner: true }),\n requestedCollectionSlug: 'media',\n collectionPrefix: '',\n }),\n ).rejects.toMatchObject({ status: 403 })\n })\n})\n"],"names":["describe","expect","it","vi","authorizeClientOverwrite","owner","id","filename","prefix","collectionSources","collectionPrefix","collectionSlug","useCompositePrefixes","createRequest","mediaOwner","protectedOwner","payload","collections","media","config","access","update","upload","protected","find","fn","collection","docs","t","requestedStorageFilePath","requestedFilename","req","requestedCollectionSlug","resolves","toBe","rejects","toMatchObject","status"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,SAASC,wBAAwB,QAAQ,8BAA6B;AAEtE,MAAMC,QAAQ,CAACC,KAAgB,CAAA;QAAEC,UAAU;QAAaD;QAAIE,QAAQ;IAAS,CAAA;AAC7E,MAAMC,oBAAoB;IACxB;QAAEC,kBAAkB;QAAIC,gBAAgB;QAASC,sBAAsB;IAAM;IAC7E;QAAEF,kBAAkB;QAAIC,gBAAgB;QAAaC,sBAAsB;IAAM;CAClF;AAED,MAAMC,gBAAgB,CAAC,EACrBC,aAAa,IAAI,EACjBC,iBAAiB,KAAK,EAIvB,GAAG,CAAC,CAAC,GACH,CAAA;QACCC,SAAS;YACPC,aAAa;gBACXC,OAAO;oBACLC,QAAQ;wBAAEC,QAAQ;4BAAEC,QAAQ,UAAY;wBAAK;wBAAGC,QAAQ;oBAAK;gBAC/D;gBACAC,WAAW;oBACTJ,QAAQ;wBAAEC,QAAQ;4BAAEC,QAAQ,UAAY;wBAAM;wBAAGC,QAAQ;oBAAK;gBAChE;YACF;YACAE,MAAMrB,GAAGsB,EAAE,CAAC,OAAO,EAAEC,UAAU,EAA0B,GAAM,CAAA;oBAC7DC,MACED,eAAe,UACXZ,aACE;wBAACT,MAAM;qBAAG,GACV,EAAE,GACJU,iBACE;wBAACV,MAAM;qBAAG,GACV,EAAE;gBACZ,CAAA;QACF;QACAuB,GAAGzB,GAAGsB,EAAE;IACV,CAAA;AAEFzB,SAAS,4BAA4B;IACnCE,GAAG,oEAAoE;QACrE,MAAMD,OACJG,yBAAyB;YACvBK;YACAoB,0BAA0B;YAC1BC,mBAAmB;YACnBC,KAAKlB;YACLmB,yBAAyB;YACzBtB,kBAAkB;QACpB,IACAuB,QAAQ,CAACC,IAAI,CAAC;IAClB;IAEAhC,GAAG,+DAA+D;QAChE,MAAMD,OACJG,yBAAyB;YACvBK;YACAoB,0BAA0B;YAC1BC,mBAAmB;YACnBC,KAAKlB,cAAc;gBAAEC,YAAY;gBAAOC,gBAAgB;YAAK;YAC7DiB,yBAAyB;YACzBtB,kBAAkB;QACpB,IACAyB,OAAO,CAACC,aAAa,CAAC;YAAEC,QAAQ;QAAI;IACxC;IAEAnC,GAAG,gEAAgE;QACjE,MAAMD,OACJG,yBAAyB;YACvBK;YACAoB,0BAA0B;YAC1BC,mBAAmB;YACnBC,KAAKlB,cAAc;gBAAEE,gBAAgB;YAAK;YAC1CiB,yBAAyB;YACzBtB,kBAAkB;QACpB,IACAyB,OAAO,CAACC,aAAa,CAAC;YAAEC,QAAQ;QAAI;IACxC;AACF"}
@@ -1,67 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getCollectionSources } from './getCollectionSources.js';
3
- import { vercelBlobStorage } from './index.js';
4
- describe('getCollectionSources', ()=>{
5
- it('includes collections from adapter instances that share a store', ()=>{
6
- const mediaAdapter = vercelBlobStorage({
7
- collections: {
8
- media: true
9
- },
10
- token: 'vercel_blob_rw_shared_abc123'
11
- });
12
- const protectedAdapter = vercelBlobStorage({
13
- collections: {
14
- protected: {
15
- prefix: 'assets'
16
- }
17
- },
18
- token: 'vercel_blob_rw_shared_def456',
19
- useCompositePrefixes: true
20
- });
21
- const otherStoreAdapter = vercelBlobStorage({
22
- collections: {
23
- archive: true
24
- },
25
- token: 'vercel_blob_rw_other_abc123'
26
- });
27
- expect(getCollectionSources({
28
- currentAdapter: mediaAdapter,
29
- storageAdapters: [
30
- mediaAdapter,
31
- protectedAdapter,
32
- otherStoreAdapter
33
- ]
34
- })).toEqual([
35
- {
36
- collectionPrefix: '',
37
- collectionSlug: 'media',
38
- useCompositePrefixes: false
39
- },
40
- {
41
- collectionPrefix: 'assets',
42
- collectionSlug: 'protected',
43
- useCompositePrefixes: true
44
- }
45
- ]);
46
- });
47
- it('includes the current adapter when config storage is unavailable', ()=>{
48
- const adapter = vercelBlobStorage({
49
- collections: {
50
- media: true
51
- },
52
- token: 'vercel_blob_rw_shared_abc123'
53
- });
54
- expect(getCollectionSources({
55
- currentAdapter: adapter,
56
- storageAdapters: undefined
57
- })).toEqual([
58
- {
59
- collectionPrefix: '',
60
- collectionSlug: 'media',
61
- useCompositePrefixes: false
62
- }
63
- ]);
64
- });
65
- });
66
-
67
- //# sourceMappingURL=getCollectionSources.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/getCollectionSources.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport {\n getCollectionSources,\n type InternalVercelBlobStorageAdapter,\n} from './getCollectionSources.js'\nimport { vercelBlobStorage } from './index.js'\n\ndescribe('getCollectionSources', () => {\n it('includes collections from adapter instances that share a store', () => {\n const mediaAdapter = vercelBlobStorage({\n collections: { media: true },\n token: 'vercel_blob_rw_shared_abc123',\n }) as InternalVercelBlobStorageAdapter\n const protectedAdapter = vercelBlobStorage({\n collections: { protected: { prefix: 'assets' } },\n token: 'vercel_blob_rw_shared_def456',\n useCompositePrefixes: true,\n }) as InternalVercelBlobStorageAdapter\n const otherStoreAdapter = vercelBlobStorage({\n collections: { archive: true },\n token: 'vercel_blob_rw_other_abc123',\n })\n\n expect(\n getCollectionSources({\n currentAdapter: mediaAdapter,\n storageAdapters: [mediaAdapter, protectedAdapter, otherStoreAdapter],\n }),\n ).toEqual([\n { collectionPrefix: '', collectionSlug: 'media', useCompositePrefixes: false },\n { collectionPrefix: 'assets', collectionSlug: 'protected', useCompositePrefixes: true },\n ])\n })\n\n it('includes the current adapter when config storage is unavailable', () => {\n const adapter = vercelBlobStorage({\n collections: { media: true },\n token: 'vercel_blob_rw_shared_abc123',\n }) as InternalVercelBlobStorageAdapter\n\n expect(getCollectionSources({ currentAdapter: adapter, storageAdapters: undefined })).toEqual([\n { collectionPrefix: '', collectionSlug: 'media', useCompositePrefixes: false },\n ])\n })\n})\n"],"names":["describe","expect","it","getCollectionSources","vercelBlobStorage","mediaAdapter","collections","media","token","protectedAdapter","protected","prefix","useCompositePrefixes","otherStoreAdapter","archive","currentAdapter","storageAdapters","toEqual","collectionPrefix","collectionSlug","adapter","undefined"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SACEC,oBAAoB,QAEf,4BAA2B;AAClC,SAASC,iBAAiB,QAAQ,aAAY;AAE9CJ,SAAS,wBAAwB;IAC/BE,GAAG,kEAAkE;QACnE,MAAMG,eAAeD,kBAAkB;YACrCE,aAAa;gBAAEC,OAAO;YAAK;YAC3BC,OAAO;QACT;QACA,MAAMC,mBAAmBL,kBAAkB;YACzCE,aAAa;gBAAEI,WAAW;oBAAEC,QAAQ;gBAAS;YAAE;YAC/CH,OAAO;YACPI,sBAAsB;QACxB;QACA,MAAMC,oBAAoBT,kBAAkB;YAC1CE,aAAa;gBAAEQ,SAAS;YAAK;YAC7BN,OAAO;QACT;QAEAP,OACEE,qBAAqB;YACnBY,gBAAgBV;YAChBW,iBAAiB;gBAACX;gBAAcI;gBAAkBI;aAAkB;QACtE,IACAI,OAAO,CAAC;YACR;gBAAEC,kBAAkB;gBAAIC,gBAAgB;gBAASP,sBAAsB;YAAM;YAC7E;gBAAEM,kBAAkB;gBAAUC,gBAAgB;gBAAaP,sBAAsB;YAAK;SACvF;IACH;IAEAV,GAAG,mEAAmE;QACpE,MAAMkB,UAAUhB,kBAAkB;YAChCE,aAAa;gBAAEC,OAAO;YAAK;YAC3BC,OAAO;QACT;QAEAP,OAAOE,qBAAqB;YAAEY,gBAAgBK;YAASJ,iBAAiBK;QAAU,IAAIJ,OAAO,CAAC;YAC5F;gBAAEC,kBAAkB;gBAAIC,gBAAgB;gBAASP,sBAAsB;YAAM;SAC9E;IACH;AACF"}
@@ -1,71 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import { head } from '@vercel/blob';
3
- vi.mock('@vercel/blob', async (importOriginal)=>({
4
- ...await importOriginal(),
5
- head: vi.fn(async ()=>({
6
- contentDisposition: 'inline',
7
- contentType: 'image/png',
8
- size: 4,
9
- uploadedAt: new Date('2026-01-01')
10
- }))
11
- }));
12
- afterEach(()=>{
13
- vi.unstubAllGlobals();
14
- vi.clearAllMocks();
15
- });
16
- import { createVercelBlobAdapter } from './adapter.js';
17
- describe('static handler document locations', ()=>{
18
- it('should read the checked document without another lookup', async ()=>{
19
- const fetchMock = vi.fn(async ()=>new Response('file'));
20
- vi.stubGlobal('fetch', fetchMock);
21
- const adapter = createVercelBlobAdapter({
22
- access: 'public',
23
- baseUrl: 'https://example.com',
24
- cacheControlMaxAge: 60,
25
- token: 'token'
26
- });
27
- const find = vi.fn(async ()=>({
28
- docs: [
29
- {
30
- prefix: 'database'
31
- }
32
- ]
33
- }));
34
- const generatedAdapter = adapter({
35
- collection: {
36
- fields: [],
37
- slug: 'media',
38
- upload: {}
39
- },
40
- prefix: 'media'
41
- });
42
- const doc = {
43
- id: 'authorized',
44
- prefix: 'legacy'
45
- };
46
- const response = await generatedAdapter.staticHandler({
47
- headers: new Headers(),
48
- payload: {
49
- find,
50
- logger: {
51
- error: vi.fn()
52
- }
53
- }
54
- }, {
55
- doc,
56
- params: {
57
- collection: 'media',
58
- filename: 'original.png'
59
- }
60
- });
61
- expect(response.status).toBe(200);
62
- expect(await response.text()).toBe('file');
63
- expect(head).toHaveBeenCalledWith(`https://example.com/legacy/original.png`, {
64
- token: 'token'
65
- });
66
- expect(fetchMock).toHaveBeenCalledWith(`https://example.com/legacy/original.png?2026-01-01T00:00:00.000Z`, expect.any(Object));
67
- expect(find).not.toHaveBeenCalled();
68
- });
69
- });
70
-
71
- //# sourceMappingURL=staticHandler.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/staticHandler.spec.ts"],"sourcesContent":["import { afterEach, describe, expect, it, vi } from 'vitest'\n\nimport { head } from '@vercel/blob'\n\nvi.mock('@vercel/blob', async (importOriginal) => ({\n ...(await importOriginal<typeof import('@vercel/blob')>()),\n head: vi.fn(async () => ({\n contentDisposition: 'inline',\n contentType: 'image/png',\n size: 4,\n uploadedAt: new Date('2026-01-01'),\n })),\n}))\n\nafterEach(() => {\n vi.unstubAllGlobals()\n vi.clearAllMocks()\n})\n\nimport { createVercelBlobAdapter } from './adapter.js'\n\ndescribe('static handler document locations', () => {\n it('should read the checked document without another lookup', async () => {\n const fetchMock = vi.fn(async () => new Response('file'))\n\n vi.stubGlobal('fetch', fetchMock)\n const adapter = createVercelBlobAdapter({\n access: 'public',\n baseUrl: 'https://example.com',\n cacheControlMaxAge: 60,\n token: 'token',\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(head).toHaveBeenCalledWith(`https://example.com/legacy/original.png`, { token: 'token' })\n expect(fetchMock).toHaveBeenCalledWith(\n `https://example.com/legacy/original.png?2026-01-01T00:00:00.000Z`,\n expect.any(Object),\n )\n expect(find).not.toHaveBeenCalled()\n })\n})\n"],"names":["afterEach","describe","expect","it","vi","head","mock","importOriginal","fn","contentDisposition","contentType","size","uploadedAt","Date","unstubAllGlobals","clearAllMocks","createVercelBlobAdapter","fetchMock","Response","stubGlobal","adapter","access","baseUrl","cacheControlMaxAge","token","find","docs","prefix","generatedAdapter","collection","fields","slug","upload","doc","id","response","staticHandler","headers","Headers","payload","logger","error","params","filename","status","toBe","text","toHaveBeenCalledWith","any","Object","not","toHaveBeenCalled"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAE5D,SAASC,IAAI,QAAQ,eAAc;AAEnCD,GAAGE,IAAI,CAAC,gBAAgB,OAAOC,iBAAoB,CAAA;QACjD,GAAI,MAAMA,gBAA+C;QACzDF,MAAMD,GAAGI,EAAE,CAAC,UAAa,CAAA;gBACvBC,oBAAoB;gBACpBC,aAAa;gBACbC,MAAM;gBACNC,YAAY,IAAIC,KAAK;YACvB,CAAA;IACF,CAAA;AAEAb,UAAU;IACRI,GAAGU,gBAAgB;IACnBV,GAAGW,aAAa;AAClB;AAEA,SAASC,uBAAuB,QAAQ,eAAc;AAEtDf,SAAS,qCAAqC;IAC5CE,GAAG,2DAA2D;QAC5D,MAAMc,YAAYb,GAAGI,EAAE,CAAC,UAAY,IAAIU,SAAS;QAEjDd,GAAGe,UAAU,CAAC,SAASF;QACvB,MAAMG,UAAUJ,wBAAwB;YACtCK,QAAQ;YACRC,SAAS;YACTC,oBAAoB;YACpBC,OAAO;QACT;QACA,MAAMC,OAAOrB,GAAGI,EAAE,CAAC,UAAa,CAAA;gBAAEkB,MAAM;oBAAC;wBAAEC,QAAQ;oBAAW;iBAAE;YAAC,CAAA;QACjE,MAAMC,mBAAmBR,QAAQ;YAC/BS,YAAY;gBACVC,QAAQ,EAAE;gBACVC,MAAM;gBACNC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