@payloadcms/storage-azure 3.89.0-internal.95c9cba → 3.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +12 -9
  2. package/dist/adapter.d.ts +1 -1
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +10 -14
  5. package/dist/adapter.js.map +1 -1
  6. package/dist/adapter.spec.d.ts +2 -0
  7. package/dist/adapter.spec.d.ts.map +1 -0
  8. package/dist/adapter.spec.js +15 -0
  9. package/dist/adapter.spec.js.map +1 -0
  10. package/dist/client/handleAzureUpload.d.ts +2 -3
  11. package/dist/client/handleAzureUpload.d.ts.map +1 -1
  12. package/dist/client/handleAzureUpload.js +11 -3
  13. package/dist/client/handleAzureUpload.js.map +1 -1
  14. package/dist/client/handleAzureUpload.spec.js +34 -7
  15. package/dist/client/handleAzureUpload.spec.js.map +1 -1
  16. package/dist/deleteFile.d.ts +2 -5
  17. package/dist/deleteFile.d.ts.map +1 -1
  18. package/dist/deleteFile.js +2 -9
  19. package/dist/deleteFile.js.map +1 -1
  20. package/dist/generateSignedURL.d.ts.map +1 -1
  21. package/dist/generateSignedURL.js +19 -3
  22. package/dist/generateSignedURL.js.map +1 -1
  23. package/dist/generateSignedURL.spec.d.ts +2 -0
  24. package/dist/generateSignedURL.spec.d.ts.map +1 -0
  25. package/dist/generateSignedURL.spec.js +65 -0
  26. package/dist/generateSignedURL.spec.js.map +1 -0
  27. package/dist/generateURL.js +3 -3
  28. package/dist/generateURL.js.map +1 -1
  29. package/dist/getFile.d.ts +3 -3
  30. package/dist/getFile.d.ts.map +1 -1
  31. package/dist/getFile.js +10 -14
  32. package/dist/getFile.js.map +1 -1
  33. package/dist/index.containerAccess.spec.d.ts +2 -0
  34. package/dist/index.containerAccess.spec.d.ts.map +1 -0
  35. package/dist/index.containerAccess.spec.js +78 -0
  36. package/dist/index.containerAccess.spec.js.map +1 -0
  37. package/dist/index.d.ts +23 -7
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +14 -5
  40. package/dist/index.js.map +1 -1
  41. package/dist/index.spec.d.ts +2 -0
  42. package/dist/index.spec.d.ts.map +1 -0
  43. package/dist/index.spec.js +44 -0
  44. package/dist/index.spec.js.map +1 -0
  45. package/dist/isClientUploadAllowed.d.ts +3 -0
  46. package/dist/isClientUploadAllowed.d.ts.map +1 -0
  47. package/dist/isClientUploadAllowed.js +3 -0
  48. package/dist/isClientUploadAllowed.js.map +1 -0
  49. package/dist/uploadFile.d.ts +2 -5
  50. package/dist/uploadFile.d.ts.map +1 -1
  51. package/dist/uploadFile.js +2 -9
  52. package/dist/uploadFile.js.map +1 -1
  53. package/package.json +4 -4
@@ -1,12 +1,12 @@
1
- import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
1
+ import { buildStoragePathData } from '@payloadcms/plugin-cloud-storage/utilities';
2
2
  export function generateURL({ baseURL, collectionPrefix = '', containerName, filename, prefix, useCompositePrefixes = false }) {
3
- const { fileKey } = getFileKey({
3
+ const { storageFilePath } = buildStoragePathData({
4
4
  collectionPrefix,
5
5
  docPrefix: prefix,
6
6
  filename,
7
7
  useCompositePrefixes
8
8
  });
9
- return `${baseURL}/${containerName}/${fileKey}`;
9
+ return `${baseURL}/${containerName}/${storageFilePath}`;
10
10
  }
11
11
 
12
12
  //# sourceMappingURL=generateURL.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\n\ninterface GenerateURLArgs {\n baseURL: string\n collectionPrefix?: string\n containerName: string\n filename: string\n prefix: string\n useCompositePrefixes?: boolean\n}\n\nexport function generateURL({\n baseURL,\n collectionPrefix = '',\n containerName,\n filename,\n prefix,\n useCompositePrefixes = false,\n}: GenerateURLArgs): string {\n const { fileKey } = getFileKey({\n collectionPrefix,\n docPrefix: prefix,\n filename,\n useCompositePrefixes,\n })\n\n return `${baseURL}/${containerName}/${fileKey}`\n}\n"],"names":["getFileKey","generateURL","baseURL","collectionPrefix","containerName","filename","prefix","useCompositePrefixes","fileKey","docPrefix"],"mappings":"AAAA,SAASA,UAAU,QAAQ,6CAA4C;AAWvE,OAAO,SAASC,YAAY,EAC1BC,OAAO,EACPC,mBAAmB,EAAE,EACrBC,aAAa,EACbC,QAAQ,EACRC,MAAM,EACNC,uBAAuB,KAAK,EACZ;IAChB,MAAM,EAAEC,OAAO,EAAE,GAAGR,WAAW;QAC7BG;QACAM,WAAWH;QACXD;QACAE;IACF;IAEA,OAAO,GAAGL,QAAQ,CAAC,EAAEE,cAAc,CAAC,EAAEI,SAAS;AACjD"}
1
+ {"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import { buildStoragePathData } from '@payloadcms/plugin-cloud-storage/utilities'\n\ninterface GenerateURLArgs {\n baseURL: string\n collectionPrefix?: string\n containerName: string\n filename: string\n prefix: string\n useCompositePrefixes?: boolean\n}\n\nexport function generateURL({\n baseURL,\n collectionPrefix = '',\n containerName,\n filename,\n prefix,\n useCompositePrefixes = false,\n}: GenerateURLArgs): string {\n const { storageFilePath } = buildStoragePathData({\n collectionPrefix,\n docPrefix: prefix,\n filename,\n useCompositePrefixes,\n })\n\n return `${baseURL}/${containerName}/${storageFilePath}`\n}\n"],"names":["buildStoragePathData","generateURL","baseURL","collectionPrefix","containerName","filename","prefix","useCompositePrefixes","storageFilePath","docPrefix"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,6CAA4C;AAWjF,OAAO,SAASC,YAAY,EAC1BC,OAAO,EACPC,mBAAmB,EAAE,EACrBC,aAAa,EACbC,QAAQ,EACRC,MAAM,EACNC,uBAAuB,KAAK,EACZ;IAChB,MAAM,EAAEC,eAAe,EAAE,GAAGR,qBAAqB;QAC/CG;QACAM,WAAWH;QACXD;QACAE;IACF;IAEA,OAAO,GAAGL,QAAQ,CAAC,EAAEE,cAAc,CAAC,EAAEI,iBAAiB;AACzD"}
package/dist/getFile.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import type { ContainerClient } from '@azure/storage-blob';
2
- import type { CollectionConfig, PayloadRequest } from 'payload';
2
+ import type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload';
3
3
  interface GetFileArgs {
4
4
  client: ContainerClient;
5
5
  clientUploadContext?: unknown;
6
6
  collection: CollectionConfig;
7
7
  collectionPrefix?: string;
8
+ doc?: TypeWithID;
8
9
  filename: string;
9
10
  incomingHeaders?: Headers;
10
- prefixQueryParam?: string;
11
11
  req: PayloadRequest;
12
12
  useCompositePrefixes?: boolean;
13
13
  }
14
- export declare function getFile({ client, clientUploadContext, collection, collectionPrefix, filename, incomingHeaders, prefixQueryParam, req, useCompositePrefixes, }: GetFileArgs): Promise<Response>;
14
+ export declare function getFile({ client, clientUploadContext, collection, collectionPrefix, doc, filename, incomingHeaders, req, useCompositePrefixes, }: GetFileArgs): Promise<Response>;
15
15
  export {};
16
16
  //# sourceMappingURL=getFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../src/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAU/D,UAAU,WAAW;IACnB,MAAM,EAAE,eAAe,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAgCD,wBAAsB,OAAO,CAAC,EAC5B,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,gBAAqB,EACrB,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,GAAG,EACH,oBAA4B,GAC7B,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuHjC"}
1
+ {"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../src/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAW3E,UAAU,WAAW;IACnB,MAAM,EAAE,eAAe,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE,UAAU,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAgCD,wBAAsB,OAAO,CAAC,EAC5B,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,gBAAqB,EACrB,GAAG,EACH,QAAQ,EACR,eAAe,EACf,GAAG,EACH,oBAA4B,GAC7B,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkHjC"}
package/dist/getFile.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RestError } from '@azure/storage-blob';
2
- import { getFilePrefix as getDocPrefix, getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
3
- import { getRangeRequestInfo } from 'payload/internal';
2
+ import { getStorageFilePath } from '@payloadcms/plugin-cloud-storage/utilities';
3
+ import { getRangeRequestInfo, isXmlMimeType, UPLOAD_CONTENT_SECURITY_POLICY } 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,7 @@ const abortRequestAndDestroyStream = ({ abortController, blob })=>{
13
13
  blob.readableStreamBody.destroy();
14
14
  }
15
15
  };
16
- export async function getFile({ client, clientUploadContext, collection, collectionPrefix = '', filename, incomingHeaders, prefixQueryParam, req, useCompositePrefixes = false }) {
16
+ export async function getFile({ client, clientUploadContext, collection, collectionPrefix = '', doc, filename, incomingHeaders, req, useCompositePrefixes = false }) {
17
17
  let blob = undefined;
18
18
  let streamed = false;
19
19
  const abortController = new AbortController();
@@ -26,20 +26,16 @@ export async function getFile({ client, clientUploadContext, collection, collect
26
26
  });
27
27
  }
28
28
  try {
29
- const docPrefix = await getDocPrefix({
29
+ const filePath = await getStorageFilePath({
30
30
  clientUploadContext,
31
31
  collection,
32
- filename,
33
- prefixQueryParam,
34
- req
35
- });
36
- const { fileKey } = getFileKey({
37
32
  collectionPrefix,
38
- docPrefix,
33
+ doc,
39
34
  filename,
35
+ req,
40
36
  useCompositePrefixes
41
37
  });
42
- const blockBlobClient = client.getBlockBlobClient(fileKey);
38
+ const blockBlobClient = client.getBlockBlobClient(filePath);
43
39
  // Get file size for range validation
44
40
  const properties = await blockBlobClient.getProperties();
45
41
  const fileSize = properties.contentLength;
@@ -76,9 +72,9 @@ export async function getFile({ client, clientUploadContext, collection, collect
76
72
  if (properties.etag) {
77
73
  headers.append('ETag', String(properties.etag));
78
74
  }
79
- // Add Content-Security-Policy header for SVG files to prevent executable code
80
- if (properties.contentType === 'image/svg+xml') {
81
- headers.append('Content-Security-Policy', "script-src 'none'");
75
+ // Add Content-Security-Policy header for XML-family files
76
+ if (isXmlMimeType(properties.contentType)) {
77
+ headers.append('Content-Security-Policy', UPLOAD_CONTENT_SECURITY_POLICY);
82
78
  }
83
79
  const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
84
80
  if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type { BlobDownloadResponseParsed, ContainerClient } from '@azure/storage-blob'\nimport type { CollectionConfig, PayloadRequest } from 'payload'\nimport type { Readable } from 'stream'\n\nimport { RestError } from '@azure/storage-blob'\nimport {\n getFilePrefix as getDocPrefix,\n getFileKey,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { getRangeRequestInfo } from 'payload/internal'\n\ninterface GetFileArgs {\n client: ContainerClient\n clientUploadContext?: unknown\n collection: CollectionConfig\n collectionPrefix?: string\n filename: string\n incomingHeaders?: Headers\n prefixQueryParam?: string\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 filename,\n incomingHeaders,\n prefixQueryParam,\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 docPrefix = await getDocPrefix({\n clientUploadContext,\n collection,\n filename,\n prefixQueryParam,\n req,\n })\n\n const { fileKey } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n const blockBlobClient = client.getBlockBlobClient(fileKey)\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 SVG files to prevent executable code\n if (properties.contentType === 'image/svg+xml') {\n headers.append('Content-Security-Policy', \"script-src 'none'\")\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","getFilePrefix","getDocPrefix","getFileKey","getRangeRequestInfo","isNodeReadableStream","body","pipe","destroy","abortRequestAndDestroyStream","abortController","blob","abort","readableStreamBody","getFile","client","clientUploadContext","collection","collectionPrefix","filename","incomingHeaders","prefixQueryParam","req","useCompositePrefixes","undefined","streamed","AbortController","signal","addEventListener","docPrefix","fileKey","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,iBAAiBC,YAAY,EAC7BC,UAAU,QACL,6CAA4C;AACnD,SAASC,mBAAmB,QAAQ,mBAAkB;AActD,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,QAAQ,EACRC,eAAe,EACfC,gBAAgB,EAChBC,GAAG,EACHC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,MAAM;QAAC;IACpE,EAAE,OAAOwB,KAAc;QACrB,IAAIA,eAAe9D,aAAa8D,IAAIK,UAAU,KAAK,KAAK;YACtD,OAAO,IAAI9B,SAAS,MAAM;gBAAEC,QAAQ;gBAAK8B,YAAY;YAAY;QACnE;QACA9C,IAAIyC,OAAO,CAACC,MAAM,CAACC,KAAK,CAACH;QACzB,OAAO,IAAIzB,SAAS,yBAAyB;YAAEC,QAAQ;QAAI;IAC7D,SAAU;QACR,IAAI,CAACb,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, 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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AQ;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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.containerAccess.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.containerAccess.spec.d.ts","sourceRoot":"","sources":["../src/index.containerAccess.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,78 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ // Inspect the access level the adapter passes when it provisions a container.
3
+ const { createIfNotExists } = vi.hoisted(()=>({
4
+ createIfNotExists: vi.fn()
5
+ }));
6
+ // Capture the closure index.ts hands to the adapter (normally run via onInit).
7
+ const captured = vi.hoisted(()=>({
8
+ createContainerIfNotExists: undefined
9
+ }));
10
+ vi.mock('./utils/getStorageClient.js', ()=>({
11
+ getStorageClient: ()=>({
12
+ createIfNotExists
13
+ })
14
+ }));
15
+ vi.mock('./adapter.js', ()=>({
16
+ createAzureAdapter: (args)=>{
17
+ captured.createContainerIfNotExists = args.createContainerIfNotExists;
18
+ return ()=>({
19
+ name: 'azure'
20
+ });
21
+ }
22
+ }));
23
+ vi.mock('@payloadcms/plugin-cloud-storage', ()=>({
24
+ cloudStoragePlugin: ()=>(config)=>config
25
+ }));
26
+ const { azureStorage } = await import('./index.js');
27
+ const runContainerCreate = (containerAccess)=>{
28
+ createIfNotExists.mockClear();
29
+ azureStorage({
30
+ allowContainerCreate: true,
31
+ baseURL: 'https://account.blob.core.windows.net',
32
+ collections: {
33
+ media: true
34
+ },
35
+ connectionString: 'UseDevelopmentStorage=true',
36
+ containerAccess,
37
+ containerName: 'media'
38
+ })({
39
+ collections: []
40
+ });
41
+ captured.createContainerIfNotExists?.();
42
+ return createIfNotExists.mock.calls[0]?.[0];
43
+ };
44
+ describe('azureStorage container creation', ()=>{
45
+ it('should not create the container with anonymous public blob access by default', ()=>{
46
+ const options = runContainerCreate();
47
+ expect(createIfNotExists).toHaveBeenCalledTimes(1);
48
+ // No access level == private. Any public value would bypass Payload's
49
+ // access-controlled route, so the default must stay private.
50
+ expect(options?.access).toBeUndefined();
51
+ });
52
+ it('should create a private container when containerAccess is private', ()=>{
53
+ const options = runContainerCreate('private');
54
+ expect(options?.access).toBeUndefined();
55
+ });
56
+ it('should apply public access only when explicitly opted in', ()=>{
57
+ expect(runContainerCreate('blob')?.access).toBe('blob');
58
+ expect(runContainerCreate('container')?.access).toBe('container');
59
+ });
60
+ it('should surface a creation failure as an awaitable rejection, not a swallowed promise', async ()=>{
61
+ createIfNotExists.mockClear();
62
+ createIfNotExists.mockRejectedValueOnce(new Error('AuthorizationFailure: public access is not permitted on this storage account'));
63
+ azureStorage({
64
+ allowContainerCreate: true,
65
+ baseURL: 'https://account.blob.core.windows.net',
66
+ collections: {
67
+ media: true
68
+ },
69
+ connectionString: 'UseDevelopmentStorage=true',
70
+ containerName: 'media'
71
+ })({
72
+ collections: []
73
+ });
74
+ await expect(captured.createContainerIfNotExists?.()).rejects.toThrow('AuthorizationFailure');
75
+ });
76
+ });
77
+
78
+ //# sourceMappingURL=index.containerAccess.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.containerAccess.spec.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport { describe, expect, it, vi } from 'vitest'\n\n// Inspect the access level the adapter passes when it provisions a container.\nconst { createIfNotExists } = vi.hoisted(() => ({ createIfNotExists: vi.fn() }))\n\n// Capture the closure index.ts hands to the adapter (normally run via onInit).\nconst captured = vi.hoisted(\n () => ({ createContainerIfNotExists: undefined }) as { createContainerIfNotExists?: () => void },\n)\n\nvi.mock('./utils/getStorageClient.js', () => ({\n getStorageClient: () => ({ createIfNotExists }),\n}))\n\nvi.mock('./adapter.js', () => ({\n createAzureAdapter: (args: { createContainerIfNotExists: () => void }) => {\n captured.createContainerIfNotExists = args.createContainerIfNotExists\n return () => ({ name: 'azure' })\n },\n}))\n\nvi.mock('@payloadcms/plugin-cloud-storage', () => ({\n cloudStoragePlugin: () => (config: Config) => config,\n}))\n\nconst { azureStorage } = await import('./index.js')\n\nconst runContainerCreate = (\n containerAccess?: 'blob' | 'container' | 'private',\n): { access?: string } | undefined => {\n createIfNotExists.mockClear()\n\n azureStorage({\n allowContainerCreate: true,\n baseURL: 'https://account.blob.core.windows.net',\n collections: { media: true },\n connectionString: 'UseDevelopmentStorage=true',\n containerAccess,\n containerName: 'media',\n })({ collections: [] } as unknown as Config)\n\n captured.createContainerIfNotExists?.()\n\n return createIfNotExists.mock.calls[0]?.[0] as { access?: string } | undefined\n}\n\ndescribe('azureStorage container creation', () => {\n it('should not create the container with anonymous public blob access by default', () => {\n const options = runContainerCreate()\n\n expect(createIfNotExists).toHaveBeenCalledTimes(1)\n // No access level == private. Any public value would bypass Payload's\n // access-controlled route, so the default must stay private.\n expect(options?.access).toBeUndefined()\n })\n\n it('should create a private container when containerAccess is private', () => {\n const options = runContainerCreate('private')\n\n expect(options?.access).toBeUndefined()\n })\n\n it('should apply public access only when explicitly opted in', () => {\n expect(runContainerCreate('blob')?.access).toBe('blob')\n expect(runContainerCreate('container')?.access).toBe('container')\n })\n\n it('should surface a creation failure as an awaitable rejection, not a swallowed promise', async () => {\n createIfNotExists.mockClear()\n createIfNotExists.mockRejectedValueOnce(\n new Error('AuthorizationFailure: public access is not permitted on this storage account'),\n )\n\n azureStorage({\n allowContainerCreate: true,\n baseURL: 'https://account.blob.core.windows.net',\n collections: { media: true },\n connectionString: 'UseDevelopmentStorage=true',\n containerName: 'media',\n })({ collections: [] } as unknown as Config)\n\n await expect(captured.createContainerIfNotExists?.()).rejects.toThrow('AuthorizationFailure')\n })\n})\n"],"names":["describe","expect","it","vi","createIfNotExists","hoisted","fn","captured","createContainerIfNotExists","undefined","mock","getStorageClient","createAzureAdapter","args","name","cloudStoragePlugin","config","azureStorage","runContainerCreate","containerAccess","mockClear","allowContainerCreate","baseURL","collections","media","connectionString","containerName","calls","options","toHaveBeenCalledTimes","access","toBeUndefined","toBe","mockRejectedValueOnce","Error","rejects","toThrow"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,8EAA8E;AAC9E,MAAM,EAAEC,iBAAiB,EAAE,GAAGD,GAAGE,OAAO,CAAC,IAAO,CAAA;QAAED,mBAAmBD,GAAGG,EAAE;IAAG,CAAA;AAE7E,+EAA+E;AAC/E,MAAMC,WAAWJ,GAAGE,OAAO,CACzB,IAAO,CAAA;QAAEG,4BAA4BC;IAAU,CAAA;AAGjDN,GAAGO,IAAI,CAAC,+BAA+B,IAAO,CAAA;QAC5CC,kBAAkB,IAAO,CAAA;gBAAEP;YAAkB,CAAA;IAC/C,CAAA;AAEAD,GAAGO,IAAI,CAAC,gBAAgB,IAAO,CAAA;QAC7BE,oBAAoB,CAACC;YACnBN,SAASC,0BAA0B,GAAGK,KAAKL,0BAA0B;YACrE,OAAO,IAAO,CAAA;oBAAEM,MAAM;gBAAQ,CAAA;QAChC;IACF,CAAA;AAEAX,G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
59
  * Azure Blob storage connection string
60
60
  */
61
61
  connectionString: string;
62
+ /**
63
+ * Public access level applied to a container that the plugin creates via
64
+ * `allowContainerCreate`. Has no effect on containers that already exist.
65
+ *
66
+ * - `'private'` (default): no anonymous access. Blobs are reachable only
67
+ * through Payload's access-controlled file route.
68
+ * - `'blob'`: unauthenticated clients can read any blob directly from Azure.
69
+ * - `'container'`: unauthenticated clients can read and list blobs directly.
70
+ *
71
+ * Only choose `'blob'` or `'container'` if you deliberately want files served
72
+ * publicly from Azure, bypassing Payload read access control.
73
+ *
74
+ * @default 'private'
75
+ */
76
+ containerAccess?: 'blob' | 'container' | 'private';
62
77
  /**
63
78
  * Azure Blob storage container name
64
79
  */
@@ -71,14 +86,15 @@ export type AzureStorageOptions = {
71
86
  enabled?: boolean;
72
87
  /**
73
88
  * When true, the collection-level prefix and document-level prefix are combined
74
- * (compositional). When false (default), document prefix overrides collection
75
- * prefix entirely.
89
+ * (compositional). When false (default), a document prefix already within the
90
+ * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.
91
+ * Existing files retain their stored prefixes for reads, URLs, and cleanup.
76
92
  *
77
- * Example:
78
- * - collection prefix: `collection-prefix/`
79
- * - document prefix: `document-prefix/`
80
- * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`
81
- * - resulting prefix with useCompositePrefixes=false: `document-prefix/`
93
+ * Example with a document prefix already contained by the collection prefix:
94
+ * - collection prefix: `uploads/`
95
+ * - document prefix: `uploads/documents/`
96
+ * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`
97
+ * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`
82
98
  *
83
99
  * @default false
84
100
  */
@@ -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,oBAA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ud-storage';
2
2
  import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
3
3
  import { createAzureAdapter } from './adapter.js';
4
4
  import { getGenerateSignedURLHandler } from './generateSignedURL.js';
5
+ import { isAzureClientUploadAllowed } from './isClientUploadAllowed.js';
5
6
  import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js';
6
7
  export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
7
8
  const getStorageClient = ()=>getStorageClientFunc({
@@ -9,9 +10,10 @@ export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
9
10
  containerName: azureStorageOptions.containerName
10
11
  });
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))));
12
14
  initClientUploads({
13
15
  clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',
14
- collections: azureStorageOptions.collections,
16
+ collections: clientUploadCollections,
15
17
  config: incomingConfig,
16
18
  enabled: !isPluginDisabled && Boolean(azureStorageOptions.clientUploads),
17
19
  extraClientHandlerProps: ()=>({
@@ -29,13 +31,20 @@ export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
29
31
  if (isPluginDisabled) {
30
32
  return incomingConfig;
31
33
  }
32
- const createContainerIfNotExists = ()=>{
33
- void getStorageClientFunc({
34
+ const createContainerIfNotExists = async ()=>{
35
+ const containerClient = getStorageClientFunc({
34
36
  connectionString: azureStorageOptions.connectionString,
35
37
  containerName: azureStorageOptions.containerName
36
- }).createIfNotExists({
37
- access: 'blob'
38
38
  });
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
+ }
39
48
  };
40
49
  const adapter = createAzureAdapter({
41
50
  allowContainerCreate: azureStorageOptions.allowContainerCreate,
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 { 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 * 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), document prefix overrides collection\n * prefix entirely.\n *\n * Example:\n * - collection prefix: `collection-prefix/`\n * - document prefix: `document-prefix/`\n * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`\n * - resulting prefix with useCompositePrefixes=false: `document-prefix/`\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 initClientUploads({\n clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',\n collections: azureStorageOptions.collections,\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 = () => {\n void getStorageClientFunc({\n connectionString: azureStorageOptions.connectionString,\n containerName: azureStorageOptions.containerName,\n }).createIfNotExists({\n access: 'blob',\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","getStorageClient","getStorageClientFunc","azureStorage","azureStorageOptions","incomingConfig","connectionString","containerName","isPluginDisabled","enabled","clientHandler","collections","config","Boolean","clientUploads","extraClientHandlerProps","chunkLargeFiles","serverHandler","access","undefined","useCompositePrefixes","serverHandlerPath","createContainerIfNotExists","createIfNotExists","adapter","allowContainerCreate","baseURL","collectionsWithAdapter","Object","entries","reduce","acc","slug","collOptions","map","collection","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,oBAAoBC,oBAAoB,QAAQ,8BAA6B;AAmGtF,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;QAEzDX,kBAAkB;YAChBY,eAAe;YACfC,aAAaP,oBAAoBO,WAAW;YAC5CC,QAAQP;YACRI,SAAS,CAACD,oBAAoBK,QAAQT,oBAAoBU,aAAa;YACvEC,yBAAyB,IAAO,CAAA;oBAC9BC,iBACE,OAAOZ,oBAAoBU,aAAa,KAAK,WACzCD,QAAQT,oBAAoBU,aAAa,CAACE,eAAe,IACzD;gBACR,CAAA;YACAC,eAAejB,4BAA4B;gBACzCkB,QACE,OAAOd,oBAAoBU,aAAa,KAAK,WACzCV,oBAAoBU,aAAa,CAACI,MAAM,GACxCC;gBACNR,aAAaP,oBAAoBO,WAAW;gBAC5CJ,eAAeH,oBAAoBG,aAAa;gBAChDN;gBACAmB,sBAAsBhB,oBAAoBgB,oBAAoB;YAChE;YACAC,mBAAmB;QACrB;QAEA,IAAIb,kBAAkB;YACpB,OAAOH;QACT;QAEA,MAAMiB,6BAA6B;YACjC,KAAKpB,qBAAqB;gBACxBI,kBAAkBF,oBAAoBE,gBAAgB;gBACtDC,eAAeH,oBAAoBG,aAAa;YAClD,GAAGgB,iBAAiB,CAAC;gBACnBL,QAAQ;YACV;QACF;QAEA,MAAMM,UAAUzB,mBAAmB;YACjC0B,sBAAsBrB,oBAAoBqB,oBAAoB;YAC9DC,SAAStB,oBAAoBsB,OAAO;YACpCZ,eAAeV,oBAAoBU,aAAa;YAChDP,eAAeH,oBAAoBG,aAAa;YAChDe;YACArB;YACAmB,sBAAsBhB,oBAAoBgB,oBAAoB;QAChE;QAEA,+CAA+C;QAC/C,MAAMO,yBAAmEC,OAAOC,OAAO,CACrFzB,oBAAoBO,WAAW,EAC/BmB,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMZ,SAAS;YACb,GAAGP,cAAc;YACjBM,aAAa,AAACN,CAAAA,eAAeM,WAAW,IAAI,EAAE,AAAD,EAAGuB,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACR,sBAAsB,CAACQ,WAAWH,IAAI,CAAC,EAAE;oBAC5C,OAAOG;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOxC,mBAAmB;YACxByC,oBAAoBlC,oBAAoBkC,kBAAkB;YAC1D3B,aAAagB;YACbP,sBAAsBhB,oBAAoBgB,oBAAoB;QAChE,GAAGR;IACL,EAAC;AAEH,SAASV,wBAAwBD,gBAAgB,GAAE"}
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,KAAKA;QAK3EnB,kBAAkB;YAChBsB,eAAe;YACfL,aAAaJ;YACbU,QAAQf;YACRI,SAAS,CAACD,oBAAoBa,QAAQjB,oBAAoBkB,aAAa;YACvEC,yBAAyB,IAA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,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { azureStorage } from './index.js';
3
+ const createConfig = ()=>({
4
+ collections: [
5
+ {
6
+ slug: 'media',
7
+ fields: [],
8
+ upload: true
9
+ },
10
+ {
11
+ slug: 'direct-media',
12
+ fields: [],
13
+ upload: {
14
+ allowRestrictedFileTypes: true
15
+ }
16
+ }
17
+ ],
18
+ secret: 'test-secret'
19
+ });
20
+ describe('azureStorage client uploads', ()=>{
21
+ it('should register direct uploads only for explicit opt-out collections', ()=>{
22
+ const config = azureStorage({
23
+ allowContainerCreate: false,
24
+ baseURL: 'https://account.blob.core.windows.net',
25
+ clientUploads: true,
26
+ collections: {
27
+ 'direct-media': true,
28
+ media: true
29
+ },
30
+ connectionString: 'UseDevelopmentStorage=true',
31
+ containerName: 'media'
32
+ })(createConfig());
33
+ const providers = config.admin?.components?.providers ?? [];
34
+ const providerCollections = providers.map((provider)=>{
35
+ const clientProps = provider.clientProps;
36
+ return typeof clientProps?.collectionSlug === 'string' ? clientProps.collectionSlug : undefined;
37
+ }).filter(Boolean);
38
+ expect(providerCollections).toEqual([
39
+ 'direct-media'
40
+ ]);
41
+ });
42
+ });
43
+
44
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.spec.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { azureStorage } from './index.js'\n\nconst createConfig = (): Config =>\n ({\n collections: [\n {\n slug: 'media',\n fields: [],\n upload: true,\n },\n {\n slug: 'direct-media',\n fields: [],\n upload: { allowRestrictedFileTypes: true },\n },\n ],\n secret: 'test-secret',\n }) as unknown as Config\n\ndescribe('azureStorage client uploads', () => {\n it('should register direct uploads only for explicit opt-out collections', () => {\n const config = azureStorage({\n allowContainerCreate: false,\n baseURL: 'https://account.blob.core.windows.net',\n clientUploads: true,\n collections: {\n 'direct-media': true,\n media: true,\n },\n connectionString: 'UseDevelopmentStorage=true',\n containerName: 'media',\n })(createConfig()) as Config\n\n const providers = config.admin?.components?.providers ?? []\n const providerCollections = providers\n .map((provider) => {\n const clientProps = (provider as { clientProps?: { collectionSlug?: unknown } }).clientProps\n return typeof clientProps?.collectionSlug === 'string'\n ? clientProps.collectionSlug\n : undefined\n })\n .filter(Boolean)\n\n expect(providerCollections).toEqual(['direct-media'])\n })\n})\n"],"names":["describe","expect","it","azureStorage","createConfig","collections","slug","fields","upload","allowRestrictedFileTypes","secret","config","allowContainerCreate","baseURL","clientUploads","media","connectionString","containerName","providers","admin","components","providerCollections","map","provider","clientProps","collectionSlug","undefined","filter","Boolean","toEqual"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,YAAY,QAAQ,aAAY;AAEzC,MAAMC,eAAe,IAClB,CAAA;QACCC,aAAa;YACX;gBACEC,MAAM;gBACNC,QAAQ,EAAE;gBACVC,QAAQ;YACV;YACA;gBACEF,MAAM;gBACNC,QAAQ,EAAE;gBACVC,QAAQ;oBAAEC,0BAA0B;gBAAK;YAC3C;SACD;QACDC,QAAQ;IACV,CAAA;AAEFV,SAAS,+BAA+B;IACtCE,GAAG,wEAAwE;QACzE,MAAMS,SAASR,aAAa;YAC1BS,sBAAsB;YACtBC,SAAS;YACTC,eAAe;YACfT,aAAa;gBACX,gBAAgB;gBAChBU,OAAO;YACT;YACAC,kBAAkB;YAClBC,eAAe;QACjB,GAAGb;QAEH,MAAMc,YAAYP,OAAOQ,KAAK,EAAEC,YAAYF,aAAa,EAAE;QAC3D,MAAMG,sBAAsBH,UACzBI,GAAG,CAAC,CAACC;YACJ,MAAMC,cAAc,AAACD,SAA4DC,WAAW;YAC5F,OAAO,OAAOA,aAAaC,mBAAmB,WAC1CD,YAAYC,cAAc,GAC1BC;QACN,GACCC,MAAM,CAACC;QAEV3B,OAAOoB,qBAAqBQ,OAAO,CAAC;YAAC;SAAe;IACtD;AACF"}
@@ -0,0 +1,3 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ export declare const isAzureClientUploadAllowed: (collection: CollectionConfig | undefined) => boolean;
3
+ //# sourceMappingURL=isClientUploadAllowed.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export const isAzureClientUploadAllowed = (collection)=>Boolean(collection?.upload && typeof collection.upload === 'object' && collection.upload.allowRestrictedFileTypes === true);
2
+
3
+ //# sourceMappingURL=isClientUploadAllowed.js.map
@@ -0,0 +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"}
@@ -2,13 +2,10 @@ import type { ContainerClient } from '@azure/storage-blob';
2
2
  interface UploadArgs {
3
3
  buffer: Buffer;
4
4
  client: ContainerClient;
5
- collectionPrefix?: string;
6
- docPrefix?: string;
7
- filename: string;
8
5
  mimeType: string;
6
+ storageFilePath: string;
9
7
  tempFilePath?: string;
10
- useCompositePrefixes?: boolean;
11
8
  }
12
- export declare function uploadFile({ buffer, client, collectionPrefix, docPrefix, filename, mimeType, tempFilePath, useCompositePrefixes, }: UploadArgs): Promise<void>;
9
+ export declare function uploadFile({ buffer, client, mimeType, storageFilePath, tempFilePath, }: UploadArgs): Promise<void>;
13
10
  export {};
14
11
  //# sourceMappingURL=uploadFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAO1D,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,eAAe,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAID,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,MAAM,EACN,gBAAqB,EACrB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,oBAA4B,GAC7B,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA0B5B"}
1
+ {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAM1D,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,eAAe,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAID,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,MAAM,EACN,QAAQ,EACR,eAAe,EACf,YAAY,GACb,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAmB5B"}
@@ -1,17 +1,10 @@
1
1
  import { AbortController } from '@azure/abort-controller';
2
- import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
3
2
  import fs from 'fs';
4
3
  import { Readable } from 'stream';
5
4
  const multipartThreshold = 1024 * 1024 * 50 // 50MB
6
5
  ;
7
- export async function uploadFile({ buffer, client, collectionPrefix = '', docPrefix, filename, mimeType, tempFilePath, useCompositePrefixes = false }) {
8
- const { fileKey } = getFileKey({
9
- collectionPrefix,
10
- docPrefix,
11
- filename,
12
- useCompositePrefixes
13
- });
14
- const blockBlobClient = client.getBlockBlobClient(fileKey);
6
+ export async function uploadFile({ buffer, client, mimeType, storageFilePath, tempFilePath }) {
7
+ const blockBlobClient = client.getBlockBlobClient(storageFilePath);
15
8
  // when there are no temp files, or the upload is less than the threshold size, do not stream files
16
9
  if (!tempFilePath && buffer.length > 0 && buffer.length < multipartThreshold) {
17
10
  await blockBlobClient.upload(buffer, buffer.byteLength, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\n\nimport { AbortController } from '@azure/abort-controller'\nimport { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport fs from 'fs'\nimport { Readable } from 'stream'\n\ninterface UploadArgs {\n buffer: Buffer\n client: ContainerClient\n collectionPrefix?: string\n docPrefix?: string\n filename: string\n mimeType: string\n tempFilePath?: string\n useCompositePrefixes?: boolean\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\n\nexport async function uploadFile({\n buffer,\n client,\n collectionPrefix = '',\n docPrefix,\n filename,\n mimeType,\n tempFilePath,\n useCompositePrefixes = false,\n}: UploadArgs): Promise<void> {\n const { fileKey } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n const blockBlobClient = client.getBlockBlobClient(fileKey)\n\n // when there are no temp files, or the upload is less than the threshold size, do not stream files\n if (!tempFilePath && buffer.length > 0 && buffer.length < multipartThreshold) {\n await blockBlobClient.upload(buffer, buffer.byteLength, {\n blobHTTPHeaders: { blobContentType: mimeType },\n })\n return\n }\n\n const fileBufferOrStream: Readable = tempFilePath\n ? fs.createReadStream(tempFilePath)\n : Readable.from(buffer)\n\n await blockBlobClient.uploadStream(fileBufferOrStream, 4 * 1024 * 1024, 4, {\n abortSignal: AbortController.timeout(30 * 60 * 1000),\n blobHTTPHeaders: { blobContentType: mimeType },\n })\n}\n"],"names":["AbortController","getFileKey","fs","Readable","multipartThreshold","uploadFile","buffer","client","collectionPrefix","docPrefix","filename","mimeType","tempFilePath","useCompositePrefixes","fileKey","blockBlobClient","getBlockBlobClient","length","upload","byteLength","blobHTTPHeaders","blobContentType","fileBufferOrStream","createReadStream","from","uploadStream","abortSignal","timeout"],"mappings":"AAEA,SAASA,eAAe,QAAQ,0BAAyB;AACzD,SAASC,UAAU,QAAQ,6CAA4C;AACvE,OAAOC,QAAQ,KAAI;AACnB,SAASC,QAAQ,QAAQ,SAAQ;AAajC,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AAEnD,OAAO,eAAeC,WAAW,EAC/BC,MAAM,EACNC,MAAM,EACNC,mBAAmB,EAAE,EACrBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,YAAY,EACZC,uBAAuB,KAAK,EACjB;IACX,MAAM,EAAEC,OAAO,EAAE,GAAGb,WAAW;QAC7BO;QACAC;QACAC;QACAG;IACF;IAEA,MAAME,kBAAkBR,OAAOS,kBAAkB,CAACF;IAElD,mGAAmG;IACnG,IAAI,CAACF,gBAAgBN,OAAOW,MAAM,GAAG,KAAKX,OAAOW,MAAM,GAAGb,oBAAoB;QAC5E,MAAMW,gBAAgBG,MAAM,CAACZ,QAAQA,OAAOa,UAAU,EAAE;YACtDC,iBAAiB;gBAAEC,iBAAiBV;YAAS;QAC/C;QACA;IACF;IAEA,MAAMW,qBAA+BV,eACjCV,GAAGqB,gBAAgB,CAACX,gBACpBT,SAASqB,IAAI,CAAClB;IAElB,MAAMS,gBAAgBU,YAAY,CAACH,oBAAoB,IAAI,OAAO,MAAM,GAAG;QACzEI,aAAa1B,gBAAgB2B,OAAO,CAAC,KAAK,KAAK;QAC/CP,iBAAiB;YAAEC,iBAAiBV;QAAS;IAC/C;AACF"}
1
+ {"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\n\nimport { AbortController } from '@azure/abort-controller'\nimport fs from 'fs'\nimport { Readable } from 'stream'\n\ninterface UploadArgs {\n buffer: Buffer\n client: ContainerClient\n mimeType: string\n storageFilePath: string\n tempFilePath?: string\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\n\nexport async function uploadFile({\n buffer,\n client,\n mimeType,\n storageFilePath,\n tempFilePath,\n}: UploadArgs): Promise<void> {\n const blockBlobClient = client.getBlockBlobClient(storageFilePath)\n\n // when there are no temp files, or the upload is less than the threshold size, do not stream files\n if (!tempFilePath && buffer.length > 0 && buffer.length < multipartThreshold) {\n await blockBlobClient.upload(buffer, buffer.byteLength, {\n blobHTTPHeaders: { blobContentType: mimeType },\n })\n return\n }\n\n const fileBufferOrStream: Readable = tempFilePath\n ? fs.createReadStream(tempFilePath)\n : Readable.from(buffer)\n\n await blockBlobClient.uploadStream(fileBufferOrStream, 4 * 1024 * 1024, 4, {\n abortSignal: AbortController.timeout(30 * 60 * 1000),\n blobHTTPHeaders: { blobContentType: mimeType },\n })\n}\n"],"names":["AbortController","fs","Readable","multipartThreshold","uploadFile","buffer","client","mimeType","storageFilePath","tempFilePath","blockBlobClient","getBlockBlobClient","length","upload","byteLength","blobHTTPHeaders","blobContentType","fileBufferOrStream","createReadStream","from","uploadStream","abortSignal","timeout"],"mappings":"AAEA,SAASA,eAAe,QAAQ,0BAAyB;AACzD,OAAOC,QAAQ,KAAI;AACnB,SAASC,QAAQ,QAAQ,SAAQ;AAUjC,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AAEnD,OAAO,eAAeC,WAAW,EAC/BC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,eAAe,EACfC,YAAY,EACD;IACX,MAAMC,kBAAkBJ,OAAOK,kBAAkB,CAACH;IAElD,mGAAmG;IACnG,IAAI,CAACC,gBAAgBJ,OAAOO,MAAM,GAAG,KAAKP,OAAOO,MAAM,GAAGT,oBAAoB;QAC5E,MAAMO,gBAAgBG,MAAM,CAACR,QAAQA,OAAOS,UAAU,EAAE;YACtDC,iBAAiB;gBAAEC,iBAAiBT;YAAS;QAC/C;QACA;IACF;IAEA,MAAMU,qBAA+BR,eACjCR,GAAGiB,gBAAgB,CAACT,gBACpBP,SAASiB,IAAI,CAACd;IAElB,MAAMK,gBAAgBU,YAAY,CAACH,oBAAoB,IAAI,OAAO,MAAM,GAAG;QACzEI,aAAarB,gBAAgBsB,OAAO,CAAC,KAAK,KAAK;QAC/CP,iBAAiB;YAAEC,iBAAiBT;QAAS;IAC/C;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-azure",
3
- "version": "3.89.0-internal.95c9cba",
3
+ "version": "3.90.0",
4
4
  "description": "Payload storage adapter for Azure Blob Storage",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -39,13 +39,13 @@
39
39
  "dependencies": {
40
40
  "@azure/abort-controller": "^1.1.0",
41
41
  "@azure/storage-blob": "^12.11.0",
42
- "@payloadcms/plugin-cloud-storage": "3.89.0-internal.95c9cba"
42
+ "@payloadcms/plugin-cloud-storage": "3.90.0"
43
43
  },
44
44
  "devDependencies": {
45
- "payload": "3.89.0-internal.95c9cba"
45
+ "payload": "3.90.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "payload": "3.89.0-internal.95c9cba"
48
+ "payload": "3.90.0"
49
49
  },
50
50
  "engines": {
51
51
  "node": "^18.20.2 || >=20.9.0"