@payloadcms/storage-azure 3.91.0-internal.c1569dc → 4.0.0-beta.1

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 (58) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +7 -16
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +33 -8
  5. package/dist/adapter.js.map +1 -1
  6. package/dist/client/AzureClientUploadHandler.d.ts +4 -8
  7. package/dist/client/AzureClientUploadHandler.d.ts.map +1 -1
  8. package/dist/client/AzureClientUploadHandler.js +2 -12
  9. package/dist/client/AzureClientUploadHandler.js.map +1 -1
  10. package/dist/client/handleAzureUpload.d.ts +2 -14
  11. package/dist/client/handleAzureUpload.d.ts.map +1 -1
  12. package/dist/client/handleAzureUpload.js +15 -59
  13. package/dist/client/handleAzureUpload.js.map +1 -1
  14. package/dist/copyFile.d.ts +11 -0
  15. package/dist/copyFile.d.ts.map +1 -0
  16. package/dist/copyFile.js +52 -0
  17. package/dist/copyFile.js.map +1 -0
  18. package/dist/generateUploadInstructions.d.ts +12 -0
  19. package/dist/generateUploadInstructions.d.ts.map +1 -0
  20. package/dist/generateUploadInstructions.js +57 -0
  21. package/dist/generateUploadInstructions.js.map +1 -0
  22. package/dist/getFile.d.ts +4 -3
  23. package/dist/getFile.d.ts.map +1 -1
  24. package/dist/getFile.js +18 -16
  25. package/dist/getFile.js.map +1 -1
  26. package/dist/index.d.ts +11 -33
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +74 -79
  29. package/dist/index.js.map +1 -1
  30. package/dist/isClientUploadAllowed.d.ts +5 -2
  31. package/dist/isClientUploadAllowed.d.ts.map +1 -1
  32. package/dist/isClientUploadAllowed.js +1 -1
  33. package/dist/isClientUploadAllowed.js.map +1 -1
  34. package/package.json +6 -6
  35. package/dist/adapter.spec.d.ts +0 -2
  36. package/dist/adapter.spec.d.ts.map +0 -1
  37. package/dist/adapter.spec.js +0 -15
  38. package/dist/adapter.spec.js.map +0 -1
  39. package/dist/client/handleAzureUpload.spec.d.ts +0 -2
  40. package/dist/client/handleAzureUpload.spec.d.ts.map +0 -1
  41. package/dist/client/handleAzureUpload.spec.js +0 -214
  42. package/dist/client/handleAzureUpload.spec.js.map +0 -1
  43. package/dist/generateSignedURL.d.ts +0 -14
  44. package/dist/generateSignedURL.d.ts.map +0 -1
  45. package/dist/generateSignedURL.js +0 -63
  46. package/dist/generateSignedURL.js.map +0 -1
  47. package/dist/generateSignedURL.spec.d.ts +0 -2
  48. package/dist/generateSignedURL.spec.d.ts.map +0 -1
  49. package/dist/generateSignedURL.spec.js +0 -65
  50. package/dist/generateSignedURL.spec.js.map +0 -1
  51. package/dist/index.containerAccess.spec.d.ts +0 -2
  52. package/dist/index.containerAccess.spec.d.ts.map +0 -1
  53. package/dist/index.containerAccess.spec.js +0 -78
  54. package/dist/index.containerAccess.spec.js.map +0 -1
  55. package/dist/index.spec.d.ts +0 -2
  56. package/dist/index.spec.d.ts.map +0 -1
  57. package/dist/index.spec.js +0 -44
  58. package/dist/index.spec.js.map +0 -1
package/dist/getFile.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RestError } from '@azure/storage-blob';
2
- import { getStorageFilePath } from '@payloadcms/plugin-cloud-storage/utilities';
3
- import { getRangeRequestInfo, isXmlMimeType, UPLOAD_CONTENT_SECURITY_POLICY } from 'payload/internal';
2
+ import { buildStoragePathData, getFilePrefix as getDocPrefix } from '@payloadcms/plugin-cloud-storage/utilities';
3
+ import { getRangeRequestInfo, isXmlMimeType, uploadContentSecurityPolicy } from 'payload/internal';
4
4
  const isNodeReadableStream = (body)=>{
5
5
  return typeof body === 'object' && body !== null && 'pipe' in body && typeof body.pipe === 'function' && 'destroy' in body && typeof body.destroy === 'function';
6
6
  };
@@ -13,7 +13,8 @@ const abortRequestAndDestroyStream = ({ abortController, blob })=>{
13
13
  blob.readableStreamBody.destroy();
14
14
  }
15
15
  };
16
- export async function getFile({ client, clientUploadContext, collection, collectionPrefix = '', doc, filename, incomingHeaders, req, useCompositePrefixes = false }) {
16
+ export async function getFile({ client, collection, collectionPrefix = '', doc, filename, incomingHeaders, operation = 'read', req, uploadReference, useCompositePrefixes = false }) {
17
+ const isTransformSource = operation === 'transform';
17
18
  let blob = undefined;
18
19
  let streamed = false;
19
20
  const abortController = new AbortController();
@@ -26,17 +27,22 @@ export async function getFile({ client, clientUploadContext, collection, collect
26
27
  });
27
28
  }
28
29
  try {
29
- const filePath = await getStorageFilePath({
30
- clientUploadContext,
30
+ const docPrefix = await getDocPrefix({
31
31
  collection,
32
32
  collectionPrefix,
33
33
  doc,
34
34
  filename,
35
35
  req,
36
+ uploadReference,
36
37
  useCompositePrefixes
37
38
  });
38
- const blockBlobClient = client.getBlockBlobClient(filePath);
39
- // Get file size for range validation
39
+ const { storageFilePath } = buildStoragePathData({
40
+ collectionPrefix,
41
+ docPrefix,
42
+ filename,
43
+ useCompositePrefixes
44
+ });
45
+ const blockBlobClient = client.getBlockBlobClient(storageFilePath);
40
46
  const properties = await blockBlobClient.getProperties();
41
47
  const fileSize = properties.contentLength;
42
48
  if (!fileSize) {
@@ -44,8 +50,7 @@ export async function getFile({ client, clientUploadContext, collection, collect
44
50
  status: 500
45
51
  });
46
52
  }
47
- // Handle range request
48
- const rangeHeader = req.headers.get('range');
53
+ const rangeHeader = isTransformSource ? null : req.headers.get('range');
49
54
  const rangeResult = getRangeRequestInfo({
50
55
  fileSize,
51
56
  rangeHeader
@@ -56,33 +61,30 @@ export async function getFile({ client, clientUploadContext, collection, collect
56
61
  status: rangeResult.status
57
62
  });
58
63
  }
59
- // Download with range if partial
60
64
  blob = rangeResult.type === 'partial' ? await blockBlobClient.download(rangeResult.rangeStart, rangeResult.rangeEnd - rangeResult.rangeStart + 1, {
61
65
  abortSignal: abortController.signal
62
66
  }) : await blockBlobClient.download(0, undefined, {
63
67
  abortSignal: abortController.signal
64
68
  });
65
69
  let headers = new Headers(incomingHeaders);
66
- // Add range-related headers from the result
67
70
  for (const [key, value] of Object.entries(rangeResult.headers)){
68
71
  headers.append(key, value);
69
72
  }
70
- // Add Azure-specific headers
71
73
  headers.append('Content-Type', String(properties.contentType));
72
74
  if (properties.etag) {
73
75
  headers.append('ETag', String(properties.etag));
74
76
  }
75
- // Add Content-Security-Policy header for XML-family files
77
+ // Apply a restrictive policy to XML-family responses served through Payload.
76
78
  if (isXmlMimeType(properties.contentType)) {
77
- headers.append('Content-Security-Policy', UPLOAD_CONTENT_SECURITY_POLICY);
79
+ headers.append('Content-Security-Policy', uploadContentSecurityPolicy);
78
80
  }
79
81
  const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
80
- if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
82
+ if (!isTransformSource && collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
81
83
  headers = collection.upload.modifyResponseHeaders({
82
84
  headers
83
85
  }) || headers;
84
86
  }
85
- if (etagFromHeaders && etagFromHeaders === properties.etag) {
87
+ if (!isTransformSource && etagFromHeaders && etagFromHeaders === properties.etag) {
86
88
  return new Response(null, {
87
89
  headers,
88
90
  status: 304
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type { BlobDownloadResponseParsed, ContainerClient } from '@azure/storage-blob'\nimport type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload'\nimport type { Readable } from 'stream'\n\nimport { RestError } from '@azure/storage-blob'\nimport { getStorageFilePath } from '@payloadcms/plugin-cloud-storage/utilities'\nimport {\n getRangeRequestInfo,\n isXmlMimeType,\n UPLOAD_CONTENT_SECURITY_POLICY,\n} from 'payload/internal'\n\ninterface GetFileArgs {\n client: ContainerClient\n clientUploadContext?: unknown\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: TypeWithID\n filename: string\n incomingHeaders?: Headers\n req: PayloadRequest\n useCompositePrefixes?: boolean\n}\n\nconst isNodeReadableStream = (\n body: BlobDownloadResponseParsed['readableStreamBody'],\n): body is Readable => {\n return (\n typeof body === 'object' &&\n body !== null &&\n 'pipe' in body &&\n typeof body.pipe === 'function' &&\n 'destroy' in body &&\n typeof body.destroy === 'function'\n )\n}\n\nconst abortRequestAndDestroyStream = ({\n abortController,\n blob,\n}: {\n abortController: AbortController\n blob?: BlobDownloadResponseParsed\n}) => {\n try {\n abortController.abort()\n } catch {\n /* noop */\n }\n if (blob?.readableStreamBody && isNodeReadableStream(blob.readableStreamBody)) {\n blob.readableStreamBody.destroy()\n }\n}\n\nexport async function getFile({\n client,\n clientUploadContext,\n collection,\n collectionPrefix = '',\n doc,\n filename,\n incomingHeaders,\n req,\n useCompositePrefixes = false,\n}: GetFileArgs): Promise<Response> {\n let blob: BlobDownloadResponseParsed | undefined = undefined\n let streamed = false\n\n const abortController = new AbortController()\n if (req.signal) {\n req.signal.addEventListener('abort', () => {\n abortRequestAndDestroyStream({ abortController, blob })\n })\n }\n\n try {\n const filePath = await getStorageFilePath({\n clientUploadContext,\n collection,\n collectionPrefix,\n doc,\n filename,\n req,\n useCompositePrefixes,\n })\n\n const blockBlobClient = client.getBlockBlobClient(filePath)\n\n // Get file size for range validation\n const properties = await blockBlobClient.getProperties()\n const fileSize = properties.contentLength\n\n if (!fileSize) {\n return new Response('Internal Server Error', { status: 500 })\n }\n\n // Handle range request\n const rangeHeader = req.headers.get('range')\n const rangeResult = getRangeRequestInfo({ fileSize, rangeHeader })\n\n if (rangeResult.type === 'invalid') {\n return new Response(null, {\n headers: new Headers(rangeResult.headers),\n status: rangeResult.status,\n })\n }\n\n // Download with range if partial\n blob =\n rangeResult.type === 'partial'\n ? await blockBlobClient.download(\n rangeResult.rangeStart,\n rangeResult.rangeEnd - rangeResult.rangeStart + 1,\n { abortSignal: abortController.signal },\n )\n : await blockBlobClient.download(0, undefined, { abortSignal: abortController.signal })\n\n let headers = new Headers(incomingHeaders)\n\n // Add range-related headers from the result\n for (const [key, value] of Object.entries(rangeResult.headers)) {\n headers.append(key, value)\n }\n\n // Add Azure-specific headers\n headers.append('Content-Type', String(properties.contentType))\n if (properties.etag) {\n headers.append('ETag', String(properties.etag))\n }\n\n // Add Content-Security-Policy header for XML-family files\n if (isXmlMimeType(properties.contentType)) {\n headers.append('Content-Security-Policy', UPLOAD_CONTENT_SECURITY_POLICY)\n }\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n\n if (\n collection.upload &&\n typeof collection.upload === 'object' &&\n typeof collection.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collection.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (etagFromHeaders && etagFromHeaders === properties.etag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n if (!blob.readableStreamBody || !isNodeReadableStream(blob.readableStreamBody)) {\n return new Response('Internal Server Error', { status: 500 })\n }\n\n const stream = blob.readableStreamBody\n stream.on('error', (err: Error) => {\n req.payload.logger.error({\n err,\n msg: 'Error while streaming Azure blob (aborting)',\n })\n abortRequestAndDestroyStream({ abortController, blob })\n })\n\n streamed = true\n return new Response(stream, { headers, status: rangeResult.status })\n } catch (err: unknown) {\n if (err instanceof RestError && err.statusCode === 404) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n } finally {\n if (!streamed) {\n abortRequestAndDestroyStream({ abortController, blob })\n }\n }\n}\n"],"names":["RestError","getStorageFilePath","getRangeRequestInfo","isXmlMimeType","UPLOAD_CONTENT_SECURITY_POLICY","isNodeReadableStream","body","pipe","destroy","abortRequestAndDestroyStream","abortController","blob","abort","readableStreamBody","getFile","client","clientUploadContext","collection","collectionPrefix","doc","filename","incomingHeaders","req","useCompositePrefixes","undefined","streamed","AbortController","signal","addEventListener","filePath","blockBlobClient","getBlockBlobClient","properties","getProperties","fileSize","contentLength","Response","status","rangeHeader","headers","get","rangeResult","type","Headers","download","rangeStart","rangeEnd","abortSignal","key","value","Object","entries","append","String","contentType","etag","etagFromHeaders","upload","modifyResponseHeaders","stream","on","err","payload","logger","error","msg","statusCode","statusText"],"mappings":"AAIA,SAASA,SAAS,QAAQ,sBAAqB;AAC/C,SAASC,kBAAkB,QAAQ,6CAA4C;AAC/E,SACEC,mBAAmB,EACnBC,aAAa,EACbC,8BAA8B,QACzB,mBAAkB;AAczB,MAAMC,uBAAuB,CAC3BC;IAEA,OACE,OAAOA,SAAS,YAChBA,SAAS,QACT,UAAUA,QACV,OAAOA,KAAKC,IAAI,KAAK,cACrB,aAAaD,QACb,OAAOA,KAAKE,OAAO,KAAK;AAE5B;AAEA,MAAMC,+BAA+B,CAAC,EACpCC,eAAe,EACfC,IAAI,EAIL;IACC,IAAI;QACFD,gBAAgBE,KAAK;IACvB,EAAE,OAAM;IACN,QAAQ,GACV;IACA,IAAID,MAAME,sBAAsBR,qBAAqBM,KAAKE,kBAAkB,GAAG;QAC7EF,KAAKE,kBAAkB,CAACL,OAAO;IACjC;AACF;AAEA,OAAO,eAAeM,QAAQ,EAC5BC,MAAM,EACNC,mBAAmB,EACnBC,UAAU,EACVC,mBAAmB,EAAE,EACrBC,GAAG,EACHC,QAAQ,EACRC,eAAe,EACfC,GAAG,EACHC,uBAAuB,KAAK,EAChB;IACZ,IAAIZ,OAA+Ca;IACnD,IAAIC,WAAW;IAEf,MAAMf,kBAAkB,IAAIgB;IAC5B,IAAIJ,IAAIK,MAAM,EAAE;QACdL,IAAIK,MAAM,CAACC,gBAAgB,CAAC,SAAS;YACnCnB,6BAA6B;gBAAEC;gBAAiBC;YAAK;QACvD;IACF;IAEA,IAAI;QACF,MAAMkB,WAAW,MAAM5B,mBAAmB;YACxCe;YACAC;YACAC;YACAC;YACAC;YACAE;YACAC;QACF;QAEA,MAAMO,kBAAkBf,OAAOgB,kBAAkB,CAACF;QAElD,qCAAqC;QACrC,MAAMG,aAAa,MAAMF,gBAAgBG,aAAa;QACtD,MAAMC,WAAWF,WAAWG,aAAa;QAEzC,IAAI,CAACD,UAAU;YACb,OAAO,I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,OAAOxC,WAAWwC,MAAM,CAACC,qBAAqB,KAAK,YACnD;YACAnB,UAAUtB,WAAWwC,MAAM,CAACC,qBAAqB,CAAC;gBAAEnB;YAAQ,MAAMA;QACpE;QAEA,IAAIiB,mBAAmBA,oBAAoBxB,WAAWuB,IAAI,EAAE;YAC1D,OAAO,IAAInB,SAAS,MAAM;gBACxBG;gBACAF,QAAQ;YACV;QACF;QAEA,IAAI,CAAC1B,KAAKE,kBAAkB,IAAI,CAACR,qBAAqBM,KAAKE,kBAAkB,GAAG;YAC9E,OAAO,IAAIuB,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;QAEA,MAAMsB,SAAShD,KAAKE,kBAAkB;QACtC8C,OAAOC,EAAE,CAAC,SAAS,CAACC;YAClBvC,IAAIwC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBACvBH;gBACAI,KAAK;YACP;YACAxD,6BAA6B;gBAAEC;gBAAiBC;YAAK;QACvD;QAEAc,WAAW;QACX,OAAO,IAAIW,SAASuB,QAAQ;YAAEpB;YAASF,QAAQI,YAAYJ,MAAM;QAAC;IACpE,EAAE,OAAOwB,KAAc;QACrB,IAAIA,eAAe7D,aAAa6D,IAAIK,UAAU,KAAK,KAAK;YACtD,OAAO,IAAI9B,SAAS,MAAM;gBAAEC,QAAQ;gBAAK8B,YAAY;YAAY;QACnE;QACA7C,IAAIwC,OAAO,CAACC,MAAM,CAACC,KAAK,CAACH;QACzB,OAAO,IAAIzB,SAAS,yBAAyB;YAAEC,QAAQ;QAAI;IAC7D,SAAU;QACR,IAAI,CAACZ,UAAU;YACbhB,6BAA6B;gBAAEC;gBAAiBC;YAAK;QACvD;IACF;AACF"}
1
+ {"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type { BlobDownloadResponseParsed, ContainerClient } from '@azure/storage-blob'\nimport type { CollectionConfig, FileHandlerOperation, PayloadRequest, TypeWithID } from 'payload'\nimport type { Readable } from 'stream'\n\nimport { RestError } from '@azure/storage-blob'\nimport {\n buildStoragePathData,\n getFilePrefix as getDocPrefix,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { getRangeRequestInfo, isXmlMimeType, uploadContentSecurityPolicy } from 'payload/internal'\n\ninterface GetFileArgs {\n client: ContainerClient\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: TypeWithID\n filename: string\n incomingHeaders?: Headers\n operation?: FileHandlerOperation\n req: PayloadRequest\n uploadReference?: unknown\n useCompositePrefixes?: boolean\n}\n\nconst isNodeReadableStream = (\n body: BlobDownloadResponseParsed['readableStreamBody'],\n): body is Readable => {\n return (\n typeof body === 'object' &&\n body !== null &&\n 'pipe' in body &&\n typeof body.pipe === 'function' &&\n 'destroy' in body &&\n typeof body.destroy === 'function'\n )\n}\n\nconst abortRequestAndDestroyStream = ({\n abortController,\n blob,\n}: {\n abortController: AbortController\n blob?: BlobDownloadResponseParsed\n}) => {\n try {\n abortController.abort()\n } catch {\n /* noop */\n }\n if (blob?.readableStreamBody && isNodeReadableStream(blob.readableStreamBody)) {\n blob.readableStreamBody.destroy()\n }\n}\n\nexport async function getFile({\n client,\n collection,\n collectionPrefix = '',\n doc,\n filename,\n incomingHeaders,\n operation = 'read',\n req,\n uploadReference,\n useCompositePrefixes = false,\n}: GetFileArgs): Promise<Response> {\n const isTransformSource = operation === 'transform'\n let blob: BlobDownloadResponseParsed | undefined = undefined\n let streamed = false\n\n const abortController = new AbortController()\n if (req.signal) {\n req.signal.addEventListener('abort', () => {\n abortRequestAndDestroyStream({ abortController, blob })\n })\n }\n\n try {\n const docPrefix = await getDocPrefix({\n collection,\n collectionPrefix,\n doc,\n filename,\n req,\n uploadReference,\n useCompositePrefixes,\n })\n\n const { storageFilePath } = buildStoragePathData({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n const blockBlobClient = client.getBlockBlobClient(storageFilePath)\n\n const properties = await blockBlobClient.getProperties()\n const fileSize = properties.contentLength\n\n if (!fileSize) {\n return new Response('Internal Server Error', { status: 500 })\n }\n\n const rangeHeader = isTransformSource ? null : req.headers.get('range')\n const rangeResult = getRangeRequestInfo({ fileSize, rangeHeader })\n\n if (rangeResult.type === 'invalid') {\n return new Response(null, {\n headers: new Headers(rangeResult.headers),\n status: rangeResult.status,\n })\n }\n\n blob =\n rangeResult.type === 'partial'\n ? await blockBlobClient.download(\n rangeResult.rangeStart,\n rangeResult.rangeEnd - rangeResult.rangeStart + 1,\n { abortSignal: abortController.signal },\n )\n : await blockBlobClient.download(0, undefined, { abortSignal: abortController.signal })\n\n let headers = new Headers(incomingHeaders)\n\n for (const [key, value] of Object.entries(rangeResult.headers)) {\n headers.append(key, value)\n }\n\n headers.append('Content-Type', String(properties.contentType))\n if (properties.etag) {\n headers.append('ETag', String(properties.etag))\n }\n\n // Apply a restrictive policy to XML-family responses served through Payload.\n if (isXmlMimeType(properties.contentType)) {\n headers.append('Content-Security-Policy', uploadContentSecurityPolicy)\n }\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n\n if (\n !isTransformSource &&\n collection.upload &&\n typeof collection.upload === 'object' &&\n typeof collection.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collection.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (!isTransformSource && etagFromHeaders && etagFromHeaders === properties.etag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n if (!blob.readableStreamBody || !isNodeReadableStream(blob.readableStreamBody)) {\n return new Response('Internal Server Error', { status: 500 })\n }\n\n const stream = blob.readableStreamBody\n stream.on('error', (err: Error) => {\n req.payload.logger.error({\n err,\n msg: 'Error while streaming Azure blob (aborting)',\n })\n abortRequestAndDestroyStream({ abortController, blob })\n })\n\n streamed = true\n return new Response(stream, { headers, status: rangeResult.status })\n } catch (err: unknown) {\n if (err instanceof RestError && err.statusCode === 404) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n } finally {\n if (!streamed) {\n abortRequestAndDestroyStream({ abortController, blob })\n }\n }\n}\n"],"names":["RestError","buildStoragePathData","getFilePrefix","getDocPrefix","getRangeRequestInfo","isXmlMimeType","uploadContentSecurityPolicy","isNodeReadableStream","body","pipe","destroy","abortRequestAndDestroyStream","abortController","blob","abort","readableStreamBody","getFile","client","collection","collectionPrefix","doc","filename","incomingHeaders","operation","req","uploadReference","useCompositePrefixes","isTransformSource","undefined","streamed","AbortController","signal","addEventListener","docPrefix","storageFilePath","blockBlobClient","getBlockBlobClient","properties","getProperties","fileSize","contentLength","Response","status","rangeHeader","headers","get","rangeResult","type","Headers","download","rangeStart","rangeEnd","abortSignal","key","value","Object","entries","append","String","contentType","etag","etagFromHeaders","upload","modifyResponseHeaders","stream","on","err","payload","logger","error","msg","statusCode","statusText"],"mappings":"AAIA,SAASA,SAAS,QAAQ,sBAAqB;AAC/C,SACEC,oBAAoB,EACpBC,iBAAiBC,YAAY,QACxB,6CAA4C;AACnD,SAASC,mBAAmB,EAAEC,aAAa,EAAEC,2BAA2B,QAAQ,mBAAkB;AAelG,MAAMC,uBAAuB,CAC3BC;IAEA,OACE,OAAOA,SAAS,YAChBA,SAAS,QACT,UAAUA,QACV,OAAOA,KAAKC,IAAI,KAAK,cACrB,aAAaD,QACb,OAAOA,KAAKE,OAAO,KAAK;AAE5B;AAEA,MAAMC,+BAA+B,CAAC,EACpCC,eAAe,EACfC,IAAI,EAIL;IACC,IAAI;QACFD,gBAAgBE,KAAK;IACvB,EAAE,OAAM;IACN,QAAQ,GACV;IACA,IAAID,MAAME,sBAAsBR,qBAAqBM,KAAKE,kBAAkB,GAAG;QAC7EF,KAAKE,kBAAkB,CAACL,OAAO;IACjC;AACF;AAEA,OAAO,eAAeM,QAAQ,EAC5BC,MAAM,EACNC,UAAU,EACVC,mBAAmB,EAAE,EACrBC,GAAG,EACHC,QAAQ,EACRC,eAAe,EACfC,YAAY,MAAM,EAClBC,GAAG,EACHC,eAAe,EACfC,uBAAuB,KAAK,EAChB;IACZ,MAAMC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;IACpE,EAAE,OAAOwB,KAAc;QACrB,IAAIA,eAAelE,aAAakE,IAAIK,UAAU,KAAK,KAAK;YACtD,OAAO,IAAI9B,SAAS,MAAM;gBAAEC,QAAQ;gBAAK8B,YAAY;YAAY;QACnE;QACAhD,IAAI2C,OAAO,CAACC,MAAM,CAACC,KAAK,CAACH;QACzB,OAAO,IAAIzB,SAAS,yBAAyB;YAAEC,QAAQ;QAAI;IAC7D,SAAU;QACR,IAAI,CAACb,UAAU;YACblB,6BAA6B;gBAAEC;gBAAiBC;YAAK;QACvD;IACF;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,17 +1,6 @@
1
- import type { ClientUploadsAccess, CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
2
- import type { Plugin, UploadCollectionSlug } from 'payload';
1
+ import type { ClientUploadsConfig, CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
2
+ import type { StorageAdapter, UploadCollectionSlug } from 'payload';
3
3
  import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js';
4
- export type AzureClientUploadsConfig = {
5
- access?: ClientUploadsAccess;
6
- /**
7
- * Upload large files in blocks via the Azure Blob SDK, lifting the ~5GB
8
- * single-request limit. Requires broader CORS on the storage account
9
- * (the `OPTIONS`/`PUT` methods and `x-ms-*` headers).
10
- *
11
- * @default false
12
- */
13
- chunkLargeFiles?: boolean;
14
- } | boolean;
15
4
  export type AzureStorageOptions = {
16
5
  /**
17
6
  * Whether or not to allow the container to be created if it does not exist
@@ -19,16 +8,6 @@ export type AzureStorageOptions = {
19
8
  * @default false
20
9
  */
21
10
  allowContainerCreate: boolean;
22
- /**
23
- * When enabled, fields (like the prefix field) will always be inserted into
24
- * the collection schema regardless of whether the plugin is enabled. This
25
- * ensures a consistent schema across all environments.
26
- *
27
- * This will be enabled by default in Payload v4.
28
- *
29
- * @default false
30
- */
31
- alwaysInsertFields?: boolean;
32
11
  /**
33
12
  * Base URL for the Azure Blob storage account
34
13
  */
@@ -41,16 +20,15 @@ export type AzureStorageOptions = {
41
20
  */
42
21
  clientCacheKey?: string;
43
22
  /**
44
- * Do uploads directly on the client to bypass limits on Vercel. You must allow CORS PUT method to your website.
23
+ * Do uploads directly on the client to bypass limits on Vercel.
45
24
  *
46
- * Set `chunkLargeFiles: true` to upload through the Azure Blob SDK, which splits
47
- * large files into blocks and lifts the ~5GB single-request limit. The SDK sends
48
- * additional `x-ms-*` headers, so your storage account's CORS rules must allow the
49
- * `OPTIONS` and `PUT` methods and those headers (allowed headers `*`, or at minimum
50
- * `x-ms-*,content-type,content-length`). Left off, uploads use a single request
51
- * (the default) and are capped at ~5GB.
25
+ * Client uploads use the Azure Blob SDK, which splits large files into blocks
26
+ * (avoiding the ~5GB limit of a single upload request). The SDK sends `x-ms-*`
27
+ * headers, so the browser issues a CORS preflight: your storage account's CORS
28
+ * rules must allow the `OPTIONS` and `PUT` methods and the required headers
29
+ * (allowed headers `*`, or at minimum `x-ms-*,content-type,content-length`).
52
30
  */
53
- clientUploads?: AzureClientUploadsConfig;
31
+ clientUploads?: ClientUploadsConfig;
54
32
  /**
55
33
  * Collection options to apply the Azure Blob adapter to.
56
34
  */
@@ -100,7 +78,7 @@ export type AzureStorageOptions = {
100
78
  */
101
79
  useCompositePrefixes?: boolean;
102
80
  };
103
- type AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin;
104
- export declare const azureStorage: AzureStoragePlugin;
81
+ type AzureStorageFactory = (azureStorageArgs: AzureStorageOptions) => StorageAdapter;
82
+ export declare const azureStorage: AzureStorageFactory;
105
83
  export { getStorageClientFunc as getStorageClient };
106
84
  //# sourceMappingURL=index.d.ts.map
@@ -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,MAAM,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA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iB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAK3E,OAAO,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAEtF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAE7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;;;;OAQG;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;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;;;;;;;;;;;;OAaG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAA;IAElD;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,mBAAmB,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,KAAK,cAAc,CAAA;AAEpF,eAAO,MAAM,YAAY,EAAE,mBAiGzB,CAAA;AAEF,OAAO,EAAE,oBAAoB,IAAI,gBAAgB,EAAE,CAAA"}
package/dist/index.js CHANGED
@@ -1,90 +1,85 @@
1
1
  import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
2
- import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
3
2
  import { createAzureAdapter } from './adapter.js';
4
- import { getGenerateSignedURLHandler } from './generateSignedURL.js';
5
- import { isAzureClientUploadAllowed } from './isClientUploadAllowed.js';
6
3
  import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js';
7
- export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
8
- const getStorageClient = ()=>getStorageClientFunc({
9
- connectionString: azureStorageOptions.connectionString,
10
- containerName: azureStorageOptions.containerName
11
- });
12
- const isPluginDisabled = azureStorageOptions.enabled === false;
13
- const clientUploadCollections = Object.fromEntries(Object.entries(azureStorageOptions.collections).filter(([slug])=>isAzureClientUploadAllowed(incomingConfig.collections?.find((collection)=>collection.slug === slug))));
14
- initClientUploads({
15
- clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',
16
- collections: clientUploadCollections,
17
- config: incomingConfig,
18
- enabled: !isPluginDisabled && Boolean(azureStorageOptions.clientUploads),
19
- extraClientHandlerProps: ()=>({
20
- chunkLargeFiles: typeof azureStorageOptions.clientUploads === 'object' ? Boolean(azureStorageOptions.clientUploads.chunkLargeFiles) : false
21
- }),
22
- serverHandler: getGenerateSignedURLHandler({
23
- access: typeof azureStorageOptions.clientUploads === 'object' ? azureStorageOptions.clientUploads.access : undefined,
24
- collections: azureStorageOptions.collections,
4
+ export const azureStorage = (azureStorageOptions)=>({
5
+ name: 'azure',
6
+ collections: Object.keys(azureStorageOptions.collections),
7
+ init: (incomingConfig)=>{
8
+ const getStorageClient = ()=>getStorageClientFunc({
9
+ connectionString: azureStorageOptions.connectionString,
10
+ containerName: azureStorageOptions.containerName
11
+ });
12
+ const isPluginDisabled = azureStorageOptions.enabled === false;
13
+ if (isPluginDisabled) {
14
+ // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are
15
+ // inserted into the schema, keeping it consistent across environments.
16
+ const collectionsWithoutAdapter = Object.entries(azureStorageOptions.collections).reduce((acc, [slug, collOptions])=>({
17
+ ...acc,
18
+ [slug]: {
19
+ ...collOptions === true ? {} : collOptions,
20
+ adapter: null
21
+ }
22
+ }), {});
23
+ return cloudStoragePlugin({
24
+ collections: collectionsWithoutAdapter,
25
+ enabled: false,
26
+ useCompositePrefixes: azureStorageOptions.useCompositePrefixes
27
+ })(incomingConfig);
28
+ }
29
+ const createContainerIfNotExists = async ()=>{
30
+ const containerClient = getStorageClientFunc({
31
+ connectionString: azureStorageOptions.connectionString,
32
+ containerName: azureStorageOptions.containerName
33
+ });
34
+ // Private by default; public access is opt-in via `containerAccess`.
35
+ const containerAccess = azureStorageOptions.containerAccess ?? 'private';
36
+ if (containerAccess === 'private') {
37
+ await containerClient.createIfNotExists();
38
+ } else {
39
+ await containerClient.createIfNotExists({
40
+ access: containerAccess
41
+ });
42
+ }
43
+ };
44
+ const adapter = createAzureAdapter({
45
+ allowContainerCreate: azureStorageOptions.allowContainerCreate,
46
+ baseURL: azureStorageOptions.baseURL,
47
+ clientUploads: azureStorageOptions.clientUploads,
25
48
  containerName: azureStorageOptions.containerName,
49
+ createContainerIfNotExists,
26
50
  getStorageClient,
27
51
  useCompositePrefixes: azureStorageOptions.useCompositePrefixes
28
- }),
29
- serverHandlerPath: '/storage-azure-generate-signed-url'
30
- });
31
- if (isPluginDisabled) {
32
- return incomingConfig;
33
- }
34
- const createContainerIfNotExists = async ()=>{
35
- const containerClient = getStorageClientFunc({
36
- connectionString: azureStorageOptions.connectionString,
37
- containerName: azureStorageOptions.containerName
38
52
  });
39
- // Private by default; public access is opt-in via `containerAccess`.
40
- const containerAccess = azureStorageOptions.containerAccess ?? 'private';
41
- if (containerAccess === 'private') {
42
- await containerClient.createIfNotExists();
43
- } else {
44
- await containerClient.createIfNotExists({
45
- access: containerAccess
46
- });
47
- }
48
- };
49
- const adapter = createAzureAdapter({
50
- allowContainerCreate: azureStorageOptions.allowContainerCreate,
51
- baseURL: azureStorageOptions.baseURL,
52
- clientUploads: azureStorageOptions.clientUploads,
53
- containerName: azureStorageOptions.containerName,
54
- createContainerIfNotExists,
55
- getStorageClient,
56
- useCompositePrefixes: azureStorageOptions.useCompositePrefixes
57
- });
58
- // Add adapter to each collection option object
59
- const collectionsWithAdapter = Object.entries(azureStorageOptions.collections).reduce((acc, [slug, collOptions])=>({
60
- ...acc,
61
- [slug]: {
62
- ...collOptions === true ? {} : collOptions,
63
- adapter
64
- }
65
- }), {});
66
- // Set disableLocalStorage: true for collections specified in the plugin options
67
- const config = {
68
- ...incomingConfig,
69
- collections: (incomingConfig.collections || []).map((collection)=>{
70
- if (!collectionsWithAdapter[collection.slug]) {
71
- return collection;
72
- }
73
- return {
74
- ...collection,
75
- upload: {
76
- ...typeof collection.upload === 'object' ? collection.upload : {},
77
- disableLocalStorage: true
53
+ // Add adapter to each collection option object
54
+ const collectionsWithAdapter = Object.entries(azureStorageOptions.collections).reduce((acc, [slug, collOptions])=>({
55
+ ...acc,
56
+ [slug]: {
57
+ ...collOptions === true ? {} : collOptions,
58
+ adapter
78
59
  }
79
- };
80
- })
81
- };
82
- return cloudStoragePlugin({
83
- alwaysInsertFields: azureStorageOptions.alwaysInsertFields,
84
- collections: collectionsWithAdapter,
85
- useCompositePrefixes: azureStorageOptions.useCompositePrefixes
86
- })(config);
87
- };
60
+ }), {});
61
+ // Set disableLocalStorage: true for collections specified in the plugin options
62
+ const config = {
63
+ ...incomingConfig,
64
+ collections: (incomingConfig.collections || []).map((collection)=>{
65
+ if (!collectionsWithAdapter[collection.slug]) {
66
+ return collection;
67
+ }
68
+ return {
69
+ ...collection,
70
+ upload: {
71
+ ...typeof collection.upload === 'object' ? collection.upload : {},
72
+ disableLocalStorage: true
73
+ }
74
+ };
75
+ })
76
+ };
77
+ return cloudStoragePlugin({
78
+ collections: collectionsWithAdapter,
79
+ useCompositePrefixes: azureStorageOptions.useCompositePrefixes
80
+ })(config);
81
+ }
82
+ });
88
83
  export { getStorageClientFunc as getStorageClient };
89
84
 
90
85
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsAccess,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport { createAzureAdapter } from './adapter.js'\nimport { getGenerateSignedURLHandler } from './generateSignedURL.js'\nimport { isAzureClientUploadAllowed } from './isClientUploadAllowed.js'\nimport { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js'\n\nexport type AzureClientUploadsConfig =\n | {\n access?: ClientUploadsAccess\n /**\n * Upload large files in blocks via the Azure Blob SDK, lifting the ~5GB\n * single-request limit. Requires broader CORS on the storage account\n * (the `OPTIONS`/`PUT` methods and `x-ms-*` headers).\n *\n * @default false\n */\n chunkLargeFiles?: boolean\n }\n | boolean\n\nexport type AzureStorageOptions = {\n /**\n * Whether or not to allow the container to be created if it does not exist\n *\n * @default false\n */\n allowContainerCreate: 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 * Base URL for the Azure Blob storage account\n */\n baseURL: string\n\n /**\n * Optional cache key to identify the Azure Blob storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `azure:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Do uploads directly on the client to bypass limits on Vercel. You must allow CORS PUT method to your website.\n *\n * Set `chunkLargeFiles: true` to upload through the Azure Blob SDK, which splits\n * large files into blocks and lifts the ~5GB single-request limit. The SDK sends\n * additional `x-ms-*` headers, so your storage account's CORS rules must allow the\n * `OPTIONS` and `PUT` methods and those headers (allowed headers `*`, or at minimum\n * `x-ms-*,content-type,content-length`). Left off, uploads use a single request\n * (the default) and are capped at ~5GB.\n */\n clientUploads?: AzureClientUploadsConfig\n\n /**\n * Collection options to apply the Azure Blob adapter to.\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n\n /**\n * Azure Blob storage connection string\n */\n connectionString: string\n\n /**\n * Public access level applied to a container that the plugin creates via\n * `allowContainerCreate`. Has no effect on containers that already exist.\n *\n * - `'private'` (default): no anonymous access. Blobs are reachable only\n * through Payload's access-controlled file route.\n * - `'blob'`: unauthenticated clients can read any blob directly from Azure.\n * - `'container'`: unauthenticated clients can read and list blobs directly.\n *\n * Only choose `'blob'` or `'container'` if you deliberately want files served\n * publicly from Azure, bypassing Payload read access control.\n *\n * @default 'private'\n */\n containerAccess?: 'blob' | 'container' | 'private'\n\n /**\n * Azure Blob storage container name\n */\n containerName: string\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\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 AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin\n\nexport const azureStorage: AzureStoragePlugin =\n (azureStorageOptions: AzureStorageOptions) =>\n (incomingConfig: Config): Config => {\n const getStorageClient = () =>\n getStorageClientFunc({\n connectionString: azureStorageOptions.connectionString,\n containerName: azureStorageOptions.containerName,\n })\n\n const isPluginDisabled = azureStorageOptions.enabled === false\n\n const clientUploadCollections = Object.fromEntries(\n Object.entries(azureStorageOptions.collections).filter(([slug]) =>\n isAzureClientUploadAllowed(\n incomingConfig.collections?.find((collection) => collection.slug === slug),\n ),\n ),\n )\n\n initClientUploads({\n clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',\n collections: clientUploadCollections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(azureStorageOptions.clientUploads),\n extraClientHandlerProps: () => ({\n chunkLargeFiles:\n typeof azureStorageOptions.clientUploads === 'object'\n ? Boolean(azureStorageOptions.clientUploads.chunkLargeFiles)\n : false,\n }),\n serverHandler: getGenerateSignedURLHandler({\n access:\n typeof azureStorageOptions.clientUploads === 'object'\n ? azureStorageOptions.clientUploads.access\n : undefined,\n collections: azureStorageOptions.collections,\n containerName: azureStorageOptions.containerName,\n getStorageClient,\n useCompositePrefixes: azureStorageOptions.useCompositePrefixes,\n }),\n serverHandlerPath: '/storage-azure-generate-signed-url',\n })\n\n if (isPluginDisabled) {\n return incomingConfig\n }\n\n const createContainerIfNotExists = async (): Promise<void> => {\n const containerClient = getStorageClientFunc({\n connectionString: azureStorageOptions.connectionString,\n containerName: azureStorageOptions.containerName,\n })\n\n // Private by default; public access is opt-in via `containerAccess`.\n const containerAccess = azureStorageOptions.containerAccess ?? 'private'\n\n if (containerAccess === 'private') {\n await containerClient.createIfNotExists()\n } else {\n await containerClient.createIfNotExists({ access: containerAccess })\n }\n }\n\n const adapter = createAzureAdapter({\n allowContainerCreate: azureStorageOptions.allowContainerCreate,\n baseURL: azureStorageOptions.baseURL,\n clientUploads: azureStorageOptions.clientUploads,\n containerName: azureStorageOptions.containerName,\n createContainerIfNotExists,\n getStorageClient,\n useCompositePrefixes: azureStorageOptions.useCompositePrefixes,\n })\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n azureStorageOptions.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: azureStorageOptions.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: azureStorageOptions.useCompositePrefixes,\n })(config)\n }\n\nexport { getStorageClientFunc as getStorageClient }\n"],"names":["cloudStoragePlugin","initClientUploads","createAzureAdapter","getGenerateSignedURLHandler","isAzureClientUploadAllowed","getStorageClient","getStorageClientFunc","azureStorage","azureStorageOptions","incomingConfig","connectionString","containerName","isPluginDisabled","enabled","clientUploadCollections","Object","fromEntries","entries","collections","filter","slug","find","collection","clientHandler","config","Boolean","clientUploads","extraClientHandlerProps","chunkLargeFiles","serverHandler","access","undefined","useCompositePrefixes","serverHandlerPath","createContainerIfNotExists","containerClient","containerAccess","createIfNotExists","adapter","allowContainerCreate","baseURL","collectionsWithAdapter","reduce","acc","collOptions","map","upload","disableLocalStorage","alwaysInsertFields"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAE9E,SAASC,kBAAkB,QAAQ,eAAc;AACjD,SAASC,2BAA2B,QAAQ,yBAAwB;AACpE,SAASC,0BAA0B,QAAQ,6BAA4B;AACvE,SAASC,oBAAoBC,oBAAoB,QAAQ,8BAA6B;AAoHtF,OAAO,MAAMC,eACX,CAACC,sBACD,CAACC;QACC,MAAMJ,mBAAmB,IACvBC,qBAAqB;gBACnBI,kBAAkBF,oBAAoBE,gBAAgB;gBACtDC,eAAeH,oBAAoBG,aAAa;YAClD;QAEF,MAAMC,mBAAmBJ,oBAAoBK,OAAO,KAAK;QAEzD,MAAMC,0BAA0BC,OAAOC,WAAW,CAChDD,OAAOE,OAAO,CAACT,oBAAoBU,WAAW,EAAEC,MAAM,CAAC,CAAC,CAACC,KAAK,GAC5DhB,2BACEK,eAAeS,WAAW,EAAEG,KAAK,CAACC,aAAeA,WAAWF,IAAI,KAA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AAM,CAAA;gBAC7B,GAAGD,GAAG;gBACN,CAACvB,KAAK,EAAE;oBACN,GAAIwB,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CN;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMd,SAAS;YACb,GAAGf,cAAc;YACjBS,aAAa,AAACT,CAAAA,eAAeS,WAAW,IAAI,EAAE,AAAD,EAAG2B,GAAG,CAAC,CAACvB;gBACnD,IAAI,CAACmB,sBAAsB,CAACnB,WAAWF,IAAI,CAAC,EAAE;oBAC5C,OAAOE;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbwB,QAAQ;wBACN,GAAI,OAAOxB,WAAWwB,MAAM,KAAK,WAAWxB,WAAWwB,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAO/C,mBAAmB;YACxBgD,oBAAoBxC,oBAAoBwC,kBAAkB;YAC1D9B,aAAauB;YACbT,sBAAsBxB,oBAAoBwB,oBAAoB;QAChE,GAAGR;IACL,EAAC;AAEH,SAASlB,wBAAwBD,gBAAgB,GAAE"}
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 { createAzureAdapter } from './adapter.js'\nimport { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js'\n\nexport type AzureStorageOptions = {\n /**\n * Whether or not to allow the container to be created if it does not exist\n *\n * @default false\n */\n allowContainerCreate: boolean\n\n /**\n * Base URL for the Azure Blob storage account\n */\n baseURL: string\n\n /**\n * Optional cache key to identify the Azure Blob storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `azure:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Do uploads directly on the client to bypass limits on Vercel.\n *\n * Client uploads use the Azure Blob SDK, which splits large files into blocks\n * (avoiding the ~5GB limit of a single upload request). The SDK sends `x-ms-*`\n * headers, so the browser issues a CORS preflight: your storage account's CORS\n * rules must allow the `OPTIONS` and `PUT` methods and the required headers\n * (allowed headers `*`, or at minimum `x-ms-*,content-type,content-length`).\n */\n clientUploads?: ClientUploadsConfig\n\n /**\n * Collection options to apply the Azure Blob adapter to.\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n\n /**\n * Azure Blob storage connection string\n */\n connectionString: string\n\n /**\n * Public access level applied to a container that the plugin creates via\n * `allowContainerCreate`. Has no effect on containers that already exist.\n *\n * - `'private'` (default): no anonymous access. Blobs are reachable only\n * through Payload's access-controlled file route.\n * - `'blob'`: unauthenticated clients can read any blob directly from Azure.\n * - `'container'`: unauthenticated clients can read and list blobs directly.\n *\n * Only choose `'blob'` or `'container'` if you deliberately want files served\n * publicly from Azure, bypassing Payload read access control.\n *\n * @default 'private'\n */\n containerAccess?: 'blob' | 'container' | 'private'\n\n /**\n * Azure Blob storage container name\n */\n containerName: string\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\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 AzureStorageFactory = (azureStorageArgs: AzureStorageOptions) => StorageAdapter\n\nexport const azureStorage: AzureStorageFactory = (\n azureStorageOptions: AzureStorageOptions,\n): StorageAdapter => ({\n name: 'azure',\n collections: Object.keys(azureStorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const getStorageClient = () =>\n getStorageClientFunc({\n connectionString: azureStorageOptions.connectionString,\n containerName: azureStorageOptions.containerName,\n })\n\n const isPluginDisabled = azureStorageOptions.enabled === false\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 azureStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: { ...(collOptions === true ? {} : collOptions), adapter: null },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: azureStorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\n\n const createContainerIfNotExists = async (): Promise<void> => {\n const containerClient = getStorageClientFunc({\n connectionString: azureStorageOptions.connectionString,\n containerName: azureStorageOptions.containerName,\n })\n\n // Private by default; public access is opt-in via `containerAccess`.\n const containerAccess = azureStorageOptions.containerAccess ?? 'private'\n\n if (containerAccess === 'private') {\n await containerClient.createIfNotExists()\n } else {\n await containerClient.createIfNotExists({ access: containerAccess })\n }\n }\n\n const adapter = createAzureAdapter({\n allowContainerCreate: azureStorageOptions.allowContainerCreate,\n baseURL: azureStorageOptions.baseURL,\n clientUploads: azureStorageOptions.clientUploads,\n containerName: azureStorageOptions.containerName,\n createContainerIfNotExists,\n getStorageClient,\n useCompositePrefixes: azureStorageOptions.useCompositePrefixes,\n })\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n azureStorageOptions.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: azureStorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n\nexport { getStorageClientFunc as getStorageClient }\n"],"names":["cloudStoragePlugin","createAzureAdapter","getStorageClient","getStorageClientFunc","azureStorage","azureStorageOptions","name","collections","Object","keys","init","incomingConfig","connectionString","containerName","isPluginDisabled","enabled","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","createContainerIfNotExists","containerClient","containerAccess","createIfNotExists","access","allowContainerCreate","baseURL","clientUploads","collectionsWithAdapter","config","map","collection","upload","disableLocalStorage"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,kBAAkB,QAAQ,eAAc;AACjD,SAASC,oBAAoBC,oBAAoB,QAAQ,8BAA6B;AA0FtF,OAAO,MAAMC,eAAoC,CAC/CC,sBACoB,CAAA;QACpBC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACJ,oBAAoBE,WAAW;QACxDG,MAAM,CAACC;YACL,MAAMT,mBAAmB,IACvBC,qBAAqB;oBACnBS,kBAAkBP,oBAAoBO,gBAAgB;oBACtDC,eAAeR,oBAAoBQ,aAAa;gBAClD;YAEF,MAAMC,mBAAmBT,oBAAoBU,OAAO,KAAK;YAEzD,IAAID,kBAAkB;gBACpB,+EAA+E;gBAC/E,uEAAuE;gBACvE,MAAME,4BAAsER,OAAOS,OAAO,CACxFZ,oBAAoBE,WAAW,EAC/BW,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;wBAC7B,GAAGF,GAAG;wBACN,CAACC,KAAK,EAAE;4BAAE,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;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A,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,OAAOrC,mBAAmB;gBACxBO,aAAayB;gBACbT,sBAAsBlB,oBAAoBkB,oBAAoB;YAChE,GAAGU;QACL;IACF,CAAA,EAAE;AAEF,SAAS9B,wBAAwBD,gBAAgB,GAAE"}
@@ -1,3 +1,6 @@
1
- import type { CollectionConfig } from 'payload';
2
- export declare const isAzureClientUploadAllowed: (collection: CollectionConfig | undefined) => boolean;
1
+ export declare const isClientUploadAllowed: (collection?: {
2
+ upload?: {
3
+ allowRestrictedFileTypes?: boolean;
4
+ } | boolean;
5
+ }) => boolean;
3
6
  //# sourceMappingURL=isClientUploadAllowed.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"isClientUploadAllowed.d.ts","sourceRoot":"","sources":["../src/isClientUploadAllowed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,eAAO,MAAM,0BAA0B,eAAgB,gBAAgB,GAAG,SAAS,KAAG,OAKnF,CAAA"}
1
+ {"version":3,"file":"isClientUploadAllowed.d.ts","sourceRoot":"","sources":["../src/isClientUploadAllowed.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,gBAAiB;IACjD,MAAM,CAAC,EAAE;QAAE,wBAAwB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAA;CAC1D,KAAG,OAKD,CAAA"}
@@ -1,3 +1,3 @@
1
- export const isAzureClientUploadAllowed = (collection)=>Boolean(collection?.upload && typeof collection.upload === 'object' && collection.upload.allowRestrictedFileTypes === true);
1
+ export const isClientUploadAllowed = (collection)=>Boolean(collection && typeof collection.upload === 'object' && collection.upload.allowRestrictedFileTypes);
2
2
 
3
3
  //# sourceMappingURL=isClientUploadAllowed.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/isClientUploadAllowed.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nexport const isAzureClientUploadAllowed = (collection: CollectionConfig | undefined): boolean =>\n Boolean(\n collection?.upload &&\n typeof collection.upload === 'object' &&\n collection.upload.allowRestrictedFileTypes === true,\n )\n"],"names":["isAzureClientUploadAllowed","collection","Boolean","upload","allowRestrictedFileTypes"],"mappings":"AAEA,OAAO,MAAMA,6BAA6B,CAACC,aACzCC,QACED,YAAYE,UACV,OAAOF,WAAWE,MAAM,KAAK,YAC7BF,WAAWE,MAAM,CAACC,wBAAwB,KAAK,MAClD"}
1
+ {"version":3,"sources":["../src/isClientUploadAllowed.ts"],"sourcesContent":["export const isClientUploadAllowed = (collection?: {\n upload?: { allowRestrictedFileTypes?: boolean } | boolean\n}): boolean =>\n Boolean(\n collection &&\n typeof collection.upload === 'object' &&\n collection.upload.allowRestrictedFileTypes,\n )\n"],"names":["isClientUploadAllowed","collection","Boolean","upload","allowRestrictedFileTypes"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC,aAGpCC,QACED,cACE,OAAOA,WAAWE,MAAM,KAAK,YAC7BF,WAAWE,MAAM,CAACC,wBAAwB,EAC7C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-azure",
3
- "version": "3.91.0-internal.c1569dc",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Payload storage adapter for Azure Blob Storage",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -38,17 +38,17 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@azure/abort-controller": "^1.1.0",
41
- "@azure/storage-blob": "^12.11.0",
42
- "@payloadcms/plugin-cloud-storage": "3.91.0-internal.c1569dc"
41
+ "@azure/storage-blob": "^12.33.0",
42
+ "@payloadcms/plugin-cloud-storage": "4.0.0-beta.1"
43
43
  },
44
44
  "devDependencies": {
45
- "payload": "3.91.0-internal.c1569dc"
45
+ "payload": "4.0.0-beta.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "payload": "3.91.0-internal.c1569dc"
48
+ "payload": "4.0.0-beta.1"
49
49
  },
50
50
  "engines": {
51
- "node": "^18.20.2 || >=20.9.0"
51
+ "node": ">=24.15.0"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "pnpm build:types && pnpm build:swc",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=adapter.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter.spec.d.ts","sourceRoot":"","sources":["../src/adapter.spec.ts"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { generateURL } from './generateURL.js';
3
- describe('Azure storage adapter', ()=>{
4
- it('should generate the pre-upgrade public URL for a legacy upload', ()=>{
5
- expect(generateURL({
6
- baseURL: 'https://storage.example.test',
7
- collectionPrefix: 'docprefix-collection',
8
- containerName: 'uploads',
9
- filename: 'legacy.png',
10
- prefix: 'legacy-invoices'
11
- })).toBe('https://storage.example.test/uploads/legacy-invoices/legacy.png');
12
- });
13
- });
14
-
15
- //# sourceMappingURL=adapter.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/adapter.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { generateURL } from './generateURL.js'\n\ndescribe('Azure storage adapter', () => {\n it('should generate the pre-upgrade public URL for a legacy upload', () => {\n expect(\n generateURL({\n baseURL: 'https://storage.example.test',\n collectionPrefix: 'docprefix-collection',\n containerName: 'uploads',\n filename: 'legacy.png',\n prefix: 'legacy-invoices',\n }),\n ).toBe('https://storage.example.test/uploads/legacy-invoices/legacy.png')\n })\n})\n"],"names":["describe","expect","it","generateURL","baseURL","collectionPrefix","containerName","filename","prefix","toBe"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,WAAW,QAAQ,mBAAkB;AAE9CH,SAAS,yBAAyB;IAChCE,GAAG,kEAAkE;QACnED,OACEE,YAAY;YACVC,SAAS;YACTC,kBAAkB;YAClBC,eAAe;YACfC,UAAU;YACVC,QAAQ;QACV,IACAC,IAAI,CAAC;IACT;AACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=handleAzureUpload.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handleAzureUpload.spec.d.ts","sourceRoot":"","sources":["../../src/client/handleAzureUpload.spec.ts"],"names":[],"mappings":""}