@payloadcms/storage-azure 4.0.0-internal.bc5cf8c → 4.0.0-internal.bf4bcce

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 (49) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +29 -10
  3. package/dist/adapter.d.ts +1 -1
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +35 -14
  6. package/dist/adapter.js.map +1 -1
  7. package/dist/client/AzureClientUploadHandler.d.ts +3 -4
  8. package/dist/client/AzureClientUploadHandler.d.ts.map +1 -1
  9. package/dist/client/AzureClientUploadHandler.js +3 -35
  10. package/dist/client/AzureClientUploadHandler.js.map +1 -1
  11. package/dist/client/handleAzureUpload.d.ts +7 -0
  12. package/dist/client/handleAzureUpload.d.ts.map +1 -0
  13. package/dist/client/handleAzureUpload.js +23 -0
  14. package/dist/client/handleAzureUpload.js.map +1 -0
  15. package/dist/copyFile.d.ts +11 -0
  16. package/dist/copyFile.d.ts.map +1 -0
  17. package/dist/copyFile.js +52 -0
  18. package/dist/copyFile.js.map +1 -0
  19. package/dist/deleteFile.d.ts +2 -5
  20. package/dist/deleteFile.d.ts.map +1 -1
  21. package/dist/deleteFile.js +2 -9
  22. package/dist/deleteFile.js.map +1 -1
  23. package/dist/generateURL.js +3 -3
  24. package/dist/generateURL.js.map +1 -1
  25. package/dist/generateUploadInstructions.d.ts +12 -0
  26. package/dist/generateUploadInstructions.d.ts.map +1 -0
  27. package/dist/generateUploadInstructions.js +57 -0
  28. package/dist/generateUploadInstructions.js.map +1 -0
  29. package/dist/getFile.d.ts +5 -4
  30. package/dist/getFile.d.ts.map +1 -1
  31. package/dist/getFile.js +17 -19
  32. package/dist/getFile.js.map +1 -1
  33. package/dist/index.d.ts +30 -18
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +25 -22
  36. package/dist/index.js.map +1 -1
  37. package/dist/isClientUploadAllowed.d.ts +6 -0
  38. package/dist/isClientUploadAllowed.d.ts.map +1 -0
  39. package/dist/isClientUploadAllowed.js +3 -0
  40. package/dist/isClientUploadAllowed.js.map +1 -0
  41. package/dist/uploadFile.d.ts +2 -5
  42. package/dist/uploadFile.d.ts.map +1 -1
  43. package/dist/uploadFile.js +2 -9
  44. package/dist/uploadFile.js.map +1 -1
  45. package/package.json +5 -5
  46. package/dist/generateSignedURL.d.ts +0 -14
  47. package/dist/generateSignedURL.d.ts.map +0 -1
  48. package/dist/generateSignedURL.js +0 -47
  49. package/dist/generateSignedURL.js.map +0 -1
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018-2025 Payload CMS, Inc. <info@payloadcms.com>
3
+ Copyright (c) 2018-2026 Payload CMS, LLC <info@payloadcms.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -14,7 +14,23 @@ pnpm add @payloadcms/storage-azure
14
14
 
15
15
  - Configure the `collections` object to specify which collections should use the Azure Blob Storage adapter. The slug _must_ match one of your existing collection slugs.
16
16
  - When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
17
- - When deploying to Vercel, server uploads are limited with 4.5MB. Set `clientUploads` to `true` to do uploads directly on the client. You must allow CORS PUT method to your website.
17
+ - When deploying to Vercel, server uploads are limited to 4.5MB. Set `clientUploads` to `true` to use upload instructions and send files directly to Azure.
18
+
19
+ ### Client uploads and CORS
20
+
21
+ Client uploads (`clientUploads: true`) use the Azure Blob SDK, which splits large files into blocks and therefore avoids the ~5GB limit of a single upload request. Because the SDK sends `x-ms-*` headers, the browser issues a CORS preflight, so your storage account's CORS rules must allow the `OPTIONS` and `PUT` methods **and** the required headers.
22
+
23
+ Configure a CORS rule on the Blob service (Storage account → **Resource sharing (CORS)**):
24
+
25
+ | Field | Value |
26
+ | --------------- | -------------------------------------------------------- |
27
+ | Allowed origins | Your site origin (e.g. `https://example.com`) |
28
+ | Allowed methods | `GET,PUT,OPTIONS` (add `HEAD` if reading in-browser) |
29
+ | Allowed headers | `*` (or at minimum `x-ms-*,content-type,content-length`) |
30
+ | Exposed headers | `*` |
31
+ | Max age | `3600` |
32
+
33
+ > If you previously configured CORS for the older single-`PUT` upload flow, broaden `Allowed headers` to include the `x-ms-*` headers when upgrading.
18
34
 
19
35
  ```ts
20
36
  import { azureStorage } from '@payloadcms/storage-azure'
@@ -42,12 +58,15 @@ export default buildConfig({
42
58
 
43
59
  ### Configuration Options
44
60
 
45
- | Option | Description | Default |
46
- | ---------------------- | ------------------------------------------------------------------------ | ------- |
47
- | `enabled` | Whether or not to enable the plugin | `true` |
48
- | `collections` | Collections to apply the Azure Blob adapter to | |
49
- | `allowContainerCreate` | Whether or not to allow the container to be created if it does not exist | `false` |
50
- | `baseURL` | Base URL for the Azure Blob storage account | |
51
- | `connectionString` | Azure Blob storage connection string | |
52
- | `containerName` | Azure Blob storage container name | |
53
- | `clientUploads` | Do uploads directly on the client to bypass limits on Vercel. | |
61
+ | Option | Description | Default |
62
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
63
+ | `enabled` | Whether or not to enable the plugin | `true` |
64
+ | `collections` | Collections to apply the Azure Blob adapter to | |
65
+ | `allowContainerCreate` | Whether or not to allow the container to be created if it does not exist | `false` |
66
+ | `containerAccess` | Public access level for a container the plugin creates. `'private'` (default) serves blobs only through Payload's access-controlled route; `'blob'` / `'container'` expose them to anonymous clients directly from Azure. Has no effect on containers that already exist. | `'private'` |
67
+ | `baseURL` | Base URL for the Azure Blob storage account | |
68
+ | `connectionString` | Azure Blob storage connection string | |
69
+ | `containerName` | Azure Blob storage container name | |
70
+ | `clientUploads` | Upload directly to Azure instead of through Payload. | |
71
+
72
+ > **Breaking change (private by default):** When `allowContainerCreate: true`, the plugin now creates containers with **private** access. Previously it created them with public `blob` access. If you relied on files being served directly from the anonymous Azure blob URL (typically alongside `disablePayloadAccessControl: true`), set `containerAccess: 'blob'` to restore the old behaviour. This only affects **newly created** containers — existing containers keep their current access level, so you must flip their ACL manually if needed.
package/dist/adapter.d.ts CHANGED
@@ -5,7 +5,7 @@ interface CreateAzureAdapterArgs {
5
5
  baseURL: string;
6
6
  clientUploads?: ClientUploadsConfig;
7
7
  containerName: string;
8
- createContainerIfNotExists: () => void;
8
+ createContainerIfNotExists: () => Promise<void> | void;
9
9
  getStorageClient: () => ContainerClient;
10
10
  useCompositePrefixes?: boolean;
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EAEpB,MAAM,wCAAwC,CAAA;AAO/C,UAAU,sBAAsB;IAC9B,oBAAoB,EAAE,OAAO,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,aAAa,EAAE,MAAM,CAAA;IACrB,0BAA0B,EAAE,MAAM,IAAI,CAAA;IACtC,gBAAgB,EAAE,MAAM,eAAe,CAAA;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,wBAAgB,kBAAkB,CAAC,EACjC,oBAAoB,EACpB,OAAO,EACP,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,gBAAgB,EAChB,oBAA4B,GAC7B,EAAE,sBAAsB,GAAG,OAAO,CAyDlC"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EAGpB,MAAM,wCAAwC,CAAA;AAU/C,UAAU,sBAAsB;IAC9B,oBAAoB,EAAE,OAAO,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,aAAa,EAAE,MAAM,CAAA;IACrB,0BAA0B,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACtD,gBAAgB,EAAE,MAAM,eAAe,CAAA;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,wBAAgB,kBAAkB,CAAC,EACjC,oBAAoB,EACpB,OAAO,EACP,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,gBAAgB,EAChB,oBAA4B,GAC7B,EAAE,sBAAsB,GAAG,OAAO,CAmElC"}
package/dist/adapter.js CHANGED
@@ -1,11 +1,25 @@
1
+ import { copyAzureFile } from './copyFile.js';
1
2
  import { deleteFile } from './deleteFile.js';
3
+ import { generateUploadInstructions } from './generateUploadInstructions.js';
2
4
  import { generateURL } from './generateURL.js';
3
5
  import { getFile } from './getFile.js';
6
+ import { isClientUploadAllowed } from './isClientUploadAllowed.js';
4
7
  import { uploadFile } from './uploadFile.js';
5
8
  export function createAzureAdapter({ allowContainerCreate, baseURL, clientUploads, containerName, createContainerIfNotExists, getStorageClient, useCompositePrefixes = false }) {
9
+ const deleteStoredFile = ({ storageFilePath })=>deleteFile({
10
+ client: getStorageClient(),
11
+ storageFilePath
12
+ });
6
13
  return ({ collection, prefix = '' })=>({
7
14
  name: 'azure',
8
- clientUploads,
15
+ supportsTempFiles: true,
16
+ copyFile: ({ from, req, to })=>copyAzureFile({
17
+ client: getStorageClient(),
18
+ from,
19
+ req,
20
+ to
21
+ }),
22
+ deleteFile: deleteStoredFile,
9
23
  generateURL: ({ filename, prefix: urlPrefix = '' })=>generateURL({
10
24
  baseURL,
11
25
  collectionPrefix: prefix,
@@ -14,35 +28,42 @@ export function createAzureAdapter({ allowContainerCreate, baseURL, clientUpload
14
28
  prefix: urlPrefix,
15
29
  useCompositePrefixes
16
30
  }),
17
- handleDelete: ({ doc: { prefix: docPrefix = '' }, filename })=>deleteFile({
18
- client: getStorageClient(),
31
+ uploadInstructions: {
32
+ adminHandler: {
33
+ path: '@payloadcms/storage-azure/client#AzureClientUploadHandler'
34
+ },
35
+ enabled: Boolean(clientUploads) && isClientUploadAllowed(collection),
36
+ generate: generateUploadInstructions({
37
+ access: typeof clientUploads === 'object' ? clientUploads.access : undefined,
19
38
  collectionPrefix: prefix,
20
- docPrefix,
21
- filename,
39
+ containerName,
40
+ getStorageClient,
22
41
  useCompositePrefixes
23
42
  }),
24
- handleUpload: async ({ data, file })=>{
43
+ requiresUploadReceipt: true,
44
+ useInAdmin: true
45
+ },
46
+ handleDelete: deleteStoredFile,
47
+ handleUpload: async ({ data, file, storageFilePath })=>{
25
48
  await uploadFile({
26
49
  buffer: file.buffer,
27
50
  client: getStorageClient(),
28
- collectionPrefix: prefix,
29
- docPrefix: data.prefix,
30
- filename: file.filename,
31
51
  mimeType: file.mimeType,
32
- tempFilePath: file.tempFilePath,
33
- useCompositePrefixes
52
+ storageFilePath,
53
+ tempFilePath: file.tempFilePath
34
54
  });
35
55
  return data;
36
56
  },
37
- staticHandler: (req, { headers, params: { clientUploadContext, filename, prefix: prefixQueryParam } })=>getFile({
57
+ staticHandler: (req, { doc, headers, params: { filename, operation, uploadReference } })=>getFile({
38
58
  client: getStorageClient(),
39
- clientUploadContext,
40
59
  collection,
41
60
  collectionPrefix: prefix,
61
+ doc,
42
62
  filename,
43
63
  incomingHeaders: headers,
44
- prefixQueryParam,
64
+ operation,
45
65
  req,
66
+ uploadReference,
46
67
  useCompositePrefixes
47
68
  }),
48
69
  ...allowContainerCreate && {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type {\n Adapter,\n ClientUploadsConfig,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\n\nimport { deleteFile } from './deleteFile.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateAzureAdapterArgs {\n allowContainerCreate: boolean\n baseURL: string\n clientUploads?: ClientUploadsConfig\n containerName: string\n createContainerIfNotExists: () => void\n getStorageClient: () => ContainerClient\n useCompositePrefixes?: boolean\n}\n\nexport function createAzureAdapter({\n allowContainerCreate,\n baseURL,\n clientUploads,\n containerName,\n createContainerIfNotExists,\n getStorageClient,\n useCompositePrefixes = false,\n}: CreateAzureAdapterArgs): Adapter {\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'azure',\n clientUploads,\n\n generateURL: ({ filename, prefix: urlPrefix = '' }) =>\n generateURL({\n baseURL,\n collectionPrefix: prefix,\n containerName,\n filename,\n prefix: urlPrefix,\n useCompositePrefixes,\n }),\n\n handleDelete: ({ doc: { prefix: docPrefix = '' }, filename }) =>\n deleteFile({\n client: getStorageClient(),\n collectionPrefix: prefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n }),\n\n handleUpload: async ({ data, file }) => {\n await uploadFile({\n buffer: file.buffer,\n client: getStorageClient(),\n collectionPrefix: prefix,\n docPrefix: data.prefix,\n filename: file.filename,\n mimeType: file.mimeType,\n tempFilePath: file.tempFilePath,\n useCompositePrefixes,\n })\n\n return data\n },\n\n staticHandler: (\n req,\n { headers, params: { clientUploadContext, filename, prefix: prefixQueryParam } },\n ) =>\n getFile({\n client: getStorageClient(),\n clientUploadContext,\n collection,\n collectionPrefix: prefix,\n filename,\n incomingHeaders: headers,\n prefixQueryParam,\n req,\n useCompositePrefixes,\n }),\n\n ...(allowContainerCreate && { onInit: createContainerIfNotExists }),\n })\n}\n"],"names":["deleteFile","generateURL","getFile","uploadFile","createAzureAdapter","allowContainerCreate","baseURL","clientUploads","containerName","createContainerIfNotExists","getStorageClient","useCompositePrefixes","collection","prefix","name","filename","urlPrefix","collectionPrefix","handleDelete","doc","docPrefix","client","handleUpload","data","file","buffer","mimeType","tempFilePath","staticHandler","req","headers","params","clientUploadContext","prefixQueryParam","incomingHeaders","on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N,wBAAwB;gBAAE8B,QAAQ1B;YAA2B,CAAC;QACpE,CAAA;AACF"}
1
+ {"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type {\n Adapter,\n ClientUploadsConfig,\n DeleteFile,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\n\nimport { copyAzureFile } from './copyFile.js'\nimport { deleteFile } from './deleteFile.js'\nimport { generateUploadInstructions } from './generateUploadInstructions.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { isClientUploadAllowed } from './isClientUploadAllowed.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateAzureAdapterArgs {\n allowContainerCreate: boolean\n baseURL: string\n clientUploads?: ClientUploadsConfig\n containerName: string\n createContainerIfNotExists: () => Promise<void> | void\n getStorageClient: () => ContainerClient\n useCompositePrefixes?: boolean\n}\n\nexport function createAzureAdapter({\n allowContainerCreate,\n baseURL,\n clientUploads,\n containerName,\n createContainerIfNotExists,\n getStorageClient,\n useCompositePrefixes = false,\n}: CreateAzureAdapterArgs): Adapter {\n const deleteStoredFile: DeleteFile = ({ storageFilePath }) =>\n deleteFile({ client: getStorageClient(), storageFilePath })\n\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'azure',\n supportsTempFiles: true,\n\n copyFile: ({ from, req, to }) => copyAzureFile({ client: getStorageClient(), from, req, to }),\n deleteFile: deleteStoredFile,\n\n generateURL: ({ filename, prefix: urlPrefix = '' }) =>\n generateURL({\n baseURL,\n collectionPrefix: prefix,\n containerName,\n filename,\n prefix: urlPrefix,\n useCompositePrefixes,\n }),\n\n uploadInstructions: {\n adminHandler: {\n path: '@payloadcms/storage-azure/client#AzureClientUploadHandler',\n },\n enabled: Boolean(clientUploads) && isClientUploadAllowed(collection),\n generate: generateUploadInstructions({\n access: typeof clientUploads === 'object' ? clientUploads.access : undefined,\n collectionPrefix: prefix,\n containerName,\n getStorageClient,\n useCompositePrefixes,\n }),\n requiresUploadReceipt: true,\n useInAdmin: true,\n },\n\n handleDelete: deleteStoredFile,\n\n handleUpload: async ({ data, file, storageFilePath }) => {\n await uploadFile({\n buffer: file.buffer,\n client: getStorageClient(),\n mimeType: file.mimeType,\n storageFilePath,\n tempFilePath: file.tempFilePath,\n })\n\n return data\n },\n\n staticHandler: (req, { doc, headers, params: { filename, operation, uploadReference } }) =>\n getFile({\n client: getStorageClient(),\n collection,\n collectionPrefix: prefix,\n doc,\n filename,\n incomingHeaders: headers,\n operation,\n req,\n uploadReference,\n useCompositePrefixes,\n }),\n\n ...(allowContainerCreate && { onInit: createContainerIfNotExists }),\n })\n}\n"],"names":["copyAzureFile","deleteFile","generateUploadInstructions","generateURL","getFile","isClientUploadAllowed","uploadFile","createAzureAdapter","allowContainerCreate","baseURL","clientUploads","containerName","createContainerIfNotExists","getStorageClient","useCompositePrefixes","deleteStoredFile","storageFilePath","client","collection","prefix","name","supportsTempFiles","copyFile","from","req","to","filename","urlPrefix","collectionPrefix","uploadInstructions","adminHandler","path","enabled","Boolean","generate","access","undefined","requiresUploadReceipt","useInAdmin","handleDelete","handleUpload","data","file","buffer","mimeType","tempFilePath","staticHandler","doc","headers","params","operation","uploadReference","incomingHeaders","onInit"],"mappings":"AAQA,SAASA,aAAa,QAAQ,gBAAe;AAC7C,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,UAAU,QAAQ,kBAAiB;AAY5C,OAAO,SAASC,mBAAmB,EACjCC,oBAAoB,EACpBC,OAAO,EACPC,aAAa,EACbC,aAAa,EACbC,0BAA0B,EAC1BC,gBAAgB,EAChBC,uBAAuB,KAAK,EACL;IACvB,MAAMC,mBAA+B,CAAC,EAAEC,eAAe,EAAE,GACvDf,WAAW;YAAEgB,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B,CAAC;QACpE,CAAA;AACF"}
@@ -1,9 +1,8 @@
1
- export declare const AzureClientUploadHandler: ({ children, collectionSlug, enabled, extra, prefix, serverHandlerPath, }: {
1
+ export declare const AzureClientUploadHandler: ({ children, collectionSlug, endpointPath, prefix, props, }: {
2
2
  children: import("react").ReactNode;
3
3
  collectionSlug: import("payload").UploadCollectionSlug;
4
- enabled?: boolean;
5
- extra: Record<string, unknown>;
4
+ endpointPath?: `/${string}`;
6
5
  prefix?: string;
7
- serverHandlerPath: `/${string}`;
6
+ props: Record<string, unknown>;
8
7
  }) => import("react").JSX.Element;
9
8
  //# sourceMappingURL=AzureClientUploadHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AzureClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/AzureClientUploadHandler.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBAAwB;;;;;;;iCAqDnC,CAAA"}
1
+ {"version":3,"file":"AzureClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/AzureClientUploadHandler.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB;;;;;;iCAGnC,CAAA"}
@@ -1,41 +1,9 @@
1
1
  'use client';
2
2
  import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client';
3
- import { formatAdminURL } from 'payload/shared';
3
+ import { handleAzureUpload } from './handleAzureUpload.js';
4
4
  export const AzureClientUploadHandler = createClientUploadHandler({
5
- handler: async ({ apiRoute, collectionSlug, docPrefix, file, serverHandlerPath, serverURL, updateFilename })=>{
6
- const endpointRoute = formatAdminURL({
7
- apiRoute,
8
- path: serverHandlerPath,
9
- serverURL
10
- });
11
- const response = await fetch(endpointRoute, {
12
- body: JSON.stringify({
13
- collectionSlug,
14
- docPrefix,
15
- filename: file.name,
16
- mimeType: file.type
17
- }),
18
- credentials: 'include',
19
- method: 'POST'
20
- });
21
- const { docPrefix: sanitizedDocPrefix, filename: sanitizedFilename, url } = await response.json();
22
- if (sanitizedFilename && sanitizedFilename !== file.name) {
23
- updateFilename(sanitizedFilename);
24
- }
25
- await fetch(url, {
26
- body: file,
27
- headers: {
28
- 'Content-Length': file.size.toString(),
29
- 'Content-Type': file.type,
30
- // Required for azure
31
- 'x-ms-blob-type': 'BlockBlob'
32
- },
33
- method: 'PUT'
34
- });
35
- return {
36
- prefix: sanitizedDocPrefix
37
- };
38
- }
5
+ name: 'uploadToAzure',
6
+ handler: handleAzureUpload
39
7
  });
40
8
 
41
9
  //# sourceMappingURL=AzureClientUploadHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/client/AzureClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\nimport { formatAdminURL } from 'payload/shared'\n\nexport const AzureClientUploadHandler = createClientUploadHandler({\n handler: async ({\n apiRoute,\n collectionSlug,\n docPrefix,\n file,\n serverHandlerPath,\n serverURL,\n updateFilename,\n }) => {\n const endpointRoute = formatAdminURL({\n apiRoute,\n path: serverHandlerPath,\n serverURL,\n })\n const response = await fetch(endpointRoute, {\n body: JSON.stringify({\n collectionSlug,\n docPrefix,\n filename: file.name,\n mimeType: file.type,\n }),\n credentials: 'include',\n method: 'POST',\n })\n\n const {\n docPrefix: sanitizedDocPrefix,\n filename: sanitizedFilename,\n url,\n } = (await response.json()) as {\n docPrefix: string\n filename?: string\n url: string\n }\n\n if (sanitizedFilename && sanitizedFilename !== file.name) {\n updateFilename(sanitizedFilename)\n }\n\n await fetch(url, {\n body: file,\n headers: {\n 'Content-Length': file.size.toString(),\n 'Content-Type': file.type,\n // Required for azure\n 'x-ms-blob-type': 'BlockBlob',\n },\n method: 'PUT',\n })\n\n return { prefix: sanitizedDocPrefix }\n },\n})\n"],"names":["createClientUploadHandler","formatAdminURL","AzureClientUploadHandler","handler","apiRoute","collectionSlug","docPrefix","file","serverHandlerPath","serverURL","updateFilename","endpointRoute","path","response","fetch","body","JSON","stringify","filename","name","mimeType","type","credentials","method","sanitizedDocPrefix","sanitizedFilename","url","json","headers","size","toString","prefix"],"mappings":"AAAA;AACA,SAASA,yBAAyB,QAAQ,0CAAyC;AACnF,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,OAAO,MAAMC,2BAA2BF,0BAA0B;IAChEG,SAAS,OAAO,EACdC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,IAAI,EACJC,iBAAiB,EACjBC,SAAS,EACTC,cAAc,EACf;QACC,MAAMC,gBAAgBV,eAAe;YACnCG;YACAQ,MAAMJ;YACNC;QACF;QACA,MAAMI,WAAW,MAAMC,MAAMH,eAAe;YAC1CI,MAAMC,KAAKC,SAAS,CAAC;gBACnBZ;gBACAC;gBACAY,UAAUX,KAAKY,IAAI;gBACnBC,UAAUb,KAAKc,IAAI;YACrB;YACAC,aAAa;YACbC,QAAQ;QACV;QAEA,MAAM,EACJjB,WAAWkB,kBAAkB,EAC7BN,UAAUO,iBAAiB,EAC3BC,GAAG,EACJ,GAAI,MAAMb,SAASc,IAAI;QAMxB,IAAIF,qBAAqBA,sBAAsBlB,KAAKY,IAAI,EAAE;YACxDT,eAAee;QACjB;QAEA,MAAMX,MAAMY,KAAK;YACfX,MAAMR;YACNqB,SAAS;gBACP,kBAAkBrB,KAAKsB,IAAI,CAACC,QAAQ;gBACpC,gBAAgBvB,KAAKc,IAAI;gBACzB,qBAAqB;gBACrB,kBAAkB;YACpB;YACAE,QAAQ;QACV;QAEA,OAAO;YAAEQ,QAAQP;QAAmB;IACtC;AACF,GAAE"}
1
+ {"version":3,"sources":["../../src/client/AzureClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\n\nimport { handleAzureUpload } from './handleAzureUpload.js'\n\nexport const AzureClientUploadHandler = createClientUploadHandler({\n name: 'uploadToAzure',\n handler: handleAzureUpload,\n})\n"],"names":["createClientUploadHandler","handleAzureUpload","AzureClientUploadHandler","name","handler"],"mappings":"AAAA;AACA,SAASA,yBAAyB,QAAQ,0CAAyC;AAEnF,SAASC,iBAAiB,QAAQ,yBAAwB;AAE1D,OAAO,MAAMC,2BAA2BF,0BAA0B;IAChEG,MAAM;IACNC,SAASH;AACX,GAAE"}
@@ -0,0 +1,7 @@
1
+ type HandleAzureUploadArgs = {
2
+ data?: unknown;
3
+ file: File;
4
+ };
5
+ export declare const handleAzureUpload: ({ data, file }: HandleAzureUploadArgs) => Promise<void>;
6
+ export {};
7
+ //# sourceMappingURL=handleAzureUpload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleAzureUpload.d.ts","sourceRoot":"","sources":["../../src/client/handleAzureUpload.ts"],"names":[],"mappings":"AASA,KAAK,qBAAqB,GAAG;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,eAAO,MAAM,iBAAiB,mBAA0B,qBAAqB,KAAG,OAAO,CAAC,IAAI,CAc3F,CAAA"}
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+ // Balances upload parallelism against browser memory: `blockSize * concurrency`
3
+ // bytes are buffered in flight. The SDK uses a single Put Blob for small files
4
+ // and switches to Put Block + Put Block List above its single-shot threshold,
5
+ // lifting the ~5 GB single-request ceiling to Azure's block-blob maximum.
6
+ const BLOCK_SIZE = 64 * 1024 * 1024;
7
+ const CONCURRENCY = 4;
8
+ export const handleAzureUpload = async ({ data, file })=>{
9
+ const { url } = data;
10
+ // Loaded on demand so @azure/storage-blob is only pulled into the client bundle
11
+ // when a client upload actually runs, rather than for every Azure adapter user.
12
+ const { BlockBlobClient } = await import('@azure/storage-blob');
13
+ const blockBlobClient = new BlockBlobClient(url);
14
+ await blockBlobClient.uploadData(file, {
15
+ blobHTTPHeaders: {
16
+ blobContentType: file.type
17
+ },
18
+ blockSize: BLOCK_SIZE,
19
+ concurrency: CONCURRENCY
20
+ });
21
+ };
22
+
23
+ //# sourceMappingURL=handleAzureUpload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/handleAzureUpload.ts"],"sourcesContent":["'use client'\n\n// Balances upload parallelism against browser memory: `blockSize * concurrency`\n// bytes are buffered in flight. The SDK uses a single Put Blob for small files\n// and switches to Put Block + Put Block List above its single-shot threshold,\n// lifting the ~5 GB single-request ceiling to Azure's block-blob maximum.\nconst BLOCK_SIZE = 64 * 1024 * 1024\nconst CONCURRENCY = 4\n\ntype HandleAzureUploadArgs = {\n data?: unknown\n file: File\n}\n\nexport const handleAzureUpload = async ({ data, file }: HandleAzureUploadArgs): Promise<void> => {\n const { url } = data as { url: string }\n\n // Loaded on demand so @azure/storage-blob is only pulled into the client bundle\n // when a client upload actually runs, rather than for every Azure adapter user.\n const { BlockBlobClient } = await import('@azure/storage-blob')\n\n const blockBlobClient = new BlockBlobClient(url)\n\n await blockBlobClient.uploadData(file, {\n blobHTTPHeaders: { blobContentType: file.type },\n blockSize: BLOCK_SIZE,\n concurrency: CONCURRENCY,\n })\n}\n"],"names":["BLOCK_SIZE","CONCURRENCY","handleAzureUpload","data","file","url","BlockBlobClient","blockBlobClient","uploadData","blobHTTPHeaders","blobContentType","type","blockSize","concurrency"],"mappings":"AAAA;AAEA,gFAAgF;AAChF,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,MAAMA,aAAa,KAAK,OAAO;AAC/B,MAAMC,cAAc;AAOpB,OAAO,MAAMC,oBAAoB,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAyB;IAC3E,MAAM,EAAEC,GAAG,EAAE,GAAGF;IAEhB,gFAAgF;IAChF,gFAAgF;IAChF,MAAM,EAAEG,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC;IAEzC,MAAMC,kBAAkB,IAAID,gBAAgBD;IAE5C,MAAME,gBAAgBC,UAAU,CAACJ,MAAM;QACrCK,iBAAiB;YAAEC,iBAAiBN,KAAKO,IAAI;QAAC;QAC9CC,WAAWZ;QACXa,aAAaZ;IACf;AACF,EAAC"}
@@ -0,0 +1,11 @@
1
+ import type { ContainerClient } from '@azure/storage-blob';
2
+ import type { PayloadRequest } from 'payload';
3
+ type Args = {
4
+ client: ContainerClient;
5
+ from: string;
6
+ req?: PayloadRequest;
7
+ to: string;
8
+ };
9
+ export declare const copyAzureFile: ({ client, from, req, to }: Args) => Promise<void>;
10
+ export {};
11
+ //# sourceMappingURL=copyFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyFile.d.ts","sourceRoot":"","sources":["../src/copyFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,KAAK,IAAI,GAAG;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,cAAc,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvF,eAAO,MAAM,aAAa,8BAAqC,IAAI,KAAG,OAAO,CAAC,IAAI,CAqDjF,CAAA"}
@@ -0,0 +1,52 @@
1
+ export const copyAzureFile = async ({ client, from, req, to })=>{
2
+ if (from === to) {
3
+ throw new Error('Storage copy requires different source and destination keys');
4
+ }
5
+ const source = client.getBlockBlobClient(from);
6
+ const destination = client.getBlockBlobClient(to);
7
+ const properties = await source.getProperties();
8
+ const { tags } = await source.getTags();
9
+ const download = await source.download();
10
+ if (!download.readableStreamBody) {
11
+ throw new Error(`Azure storage source is not readable: ${from}`);
12
+ }
13
+ const uploaded = await destination.uploadStream(download.readableStreamBody, 4 * 1024 * 1024, 4, {
14
+ blobHTTPHeaders: {
15
+ blobCacheControl: properties.cacheControl,
16
+ blobContentDisposition: properties.contentDisposition,
17
+ blobContentEncoding: properties.contentEncoding,
18
+ blobContentLanguage: properties.contentLanguage,
19
+ blobContentType: properties.contentType
20
+ },
21
+ conditions: {
22
+ ifNoneMatch: '*'
23
+ },
24
+ metadata: properties.metadata,
25
+ tags
26
+ });
27
+ try {
28
+ const copied = await destination.getProperties();
29
+ if (copied.contentLength !== properties.contentLength) {
30
+ throw new Error(`Copied Azure object is not readable at its expected length: ${to}`);
31
+ }
32
+ } catch (err) {
33
+ try {
34
+ if (!uploaded.etag) {
35
+ throw new Error('Azure copy did not return an ETag for safe cleanup');
36
+ }
37
+ await destination.deleteIfExists({
38
+ conditions: {
39
+ ifMatch: uploaded.etag
40
+ }
41
+ });
42
+ } catch (cleanupError) {
43
+ req?.payload.logger.error({
44
+ err: cleanupError,
45
+ msg: `Failed to remove unsuccessful Azure copy at ${client.containerName}/${to}`
46
+ });
47
+ }
48
+ throw err;
49
+ }
50
+ };
51
+
52
+ //# sourceMappingURL=copyFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/copyFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { Readable } from 'node:stream'\nimport type { PayloadRequest } from 'payload'\n\ntype Args = { client: ContainerClient; from: string; req?: PayloadRequest; to: string }\n\nexport const copyAzureFile = async ({ client, from, req, to }: Args): Promise<void> => {\n if (from === to) {\n throw new Error('Storage copy requires different source and destination keys')\n }\n\n const source = client.getBlockBlobClient(from)\n const destination = client.getBlockBlobClient(to)\n const properties = await source.getProperties()\n const { tags } = await source.getTags()\n const download = await source.download()\n\n if (!download.readableStreamBody) {\n throw new Error(`Azure storage source is not readable: ${from}`)\n }\n\n const uploaded = await destination.uploadStream(\n download.readableStreamBody as Readable,\n 4 * 1024 * 1024,\n 4,\n {\n blobHTTPHeaders: {\n blobCacheControl: properties.cacheControl,\n blobContentDisposition: properties.contentDisposition,\n blobContentEncoding: properties.contentEncoding,\n blobContentLanguage: properties.contentLanguage,\n blobContentType: properties.contentType,\n },\n conditions: { ifNoneMatch: '*' },\n metadata: properties.metadata,\n tags,\n },\n )\n\n try {\n const copied = await destination.getProperties()\n\n if (copied.contentLength !== properties.contentLength) {\n throw new Error(`Copied Azure object is not readable at its expected length: ${to}`)\n }\n } catch (err) {\n try {\n if (!uploaded.etag) {\n throw new Error('Azure copy did not return an ETag for safe cleanup')\n }\n await destination.deleteIfExists({ conditions: { ifMatch: uploaded.etag } })\n } catch (cleanupError) {\n req?.payload.logger.error({\n err: cleanupError,\n msg: `Failed to remove unsuccessful Azure copy at ${client.containerName}/${to}`,\n })\n }\n throw err\n }\n}\n"],"names":["copyAzureFile","client","from","req","to","Error","source","getBlockBlobClient","destination","properties","getProperties","tags","getTags","download","readableStreamBody","uploaded","uploadStream","blobHTTPHeaders","blobCacheControl","cacheControl","blobContentDisposition","contentDisposition","blobContentEncoding","contentEncoding","blobContentLanguage","contentLanguage","blobContentType","contentType","conditions","ifNoneMatch","metadata","copied","contentLength","err","etag","deleteIfExists","ifMatch","cleanupError","payload","logger","error","msg","containerName"],"mappings":"AAMA,OAAO,MAAMA,gBAAgB,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAEC,EAAE,EAAQ;IACjE,IAAIF,SAASE,IAAI;QACf,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,SAASL,OAAOM,kBAAkB,CAACL;IACzC,MAAMM,cAAcP,OAAOM,kBAAkB,CAACH;IAC9C,MAAMK,aAAa,MAAMH,OAAOI,aAAa;IAC7C,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAML,OAAOM,OAAO;IACrC,MAAMC,WAAW,MAAMP,OAAOO,QAAQ;IAEtC,IAAI,CAACA,SAASC,kBAAkB,EAAE;QAChC,MAAM,IAAIT,MAAM,CAAC,sCAAsC,EAAEH,MAAM;IACjE;IAEA,MAAMa,WAAW,MAAMP,YAAYQ,YAAY,CAC7CH,SAASC,kBAAkB,EAC3B,IAAI,OAAO,MACX,GACA;QACEG,iBAAiB;YACfC,kBAAkBT,WAAWU,YAAY;YACzCC,wBAAwBX,WAAWY,kBAAkB;YACrDC,qBAAqBb,WAAWc,eAAe;YAC/CC,qBAAqBf,WAAWgB,eAAe;YAC/CC,iBAAiBjB,WAAWkB,WAAW;QACzC;QACAC,YAAY;YAAEC,aAAa;QAAI;QAC/BC,UAAUrB,WAAWqB,QAAQ;QAC7BnB;IACF;IAGF,IAAI;QACF,MAAMoB,SAAS,MAAMvB,YAAYE,aAAa;QAE9C,IAAIqB,OAAOC,aAAa,KAAKvB,WAAWuB,aAAa,EAAE;YACrD,MAAM,IAAI3B,MAAM,CAAC,4DAA4D,EAAED,IAAI;QACrF;IACF,EAAE,OAAO6B,KAAK;QACZ,IAAI;YACF,IAAI,CAAClB,SAASmB,IAAI,EAAE;gBAClB,MAAM,IAAI7B,MAAM;YAClB;YACA,MAAMG,YAAY2B,cAAc,CAAC;gBAAEP,YAAY;oBAAEQ,SAASrB,SAASmB,IAAI;gBAAC;YAAE;QAC5E,EAAE,OAAOG,cAAc;YACrBlC,KAAKmC,QAAQC,OAAOC,MAAM;gBACxBP,KAAKI;gBACLI,KAAK,CAAC,4CAA4C,EAAExC,OAAOyC,aAAa,CAAC,CAAC,EAAEtC,IAAI;YAClF;QACF;QACA,MAAM6B;IACR;AACF,EAAC"}
@@ -1,11 +1,8 @@
1
1
  import type { ContainerClient } from '@azure/storage-blob';
2
2
  interface DeleteArgs {
3
3
  client: ContainerClient;
4
- collectionPrefix?: string;
5
- docPrefix: string;
6
- filename: string;
7
- useCompositePrefixes?: boolean;
4
+ storageFilePath: string;
8
5
  }
9
- export declare function deleteFile({ client, collectionPrefix, docPrefix, filename, useCompositePrefixes, }: DeleteArgs): Promise<void>;
6
+ export declare function deleteFile({ client, storageFilePath }: DeleteArgs): Promise<void>;
10
7
  export {};
11
8
  //# sourceMappingURL=deleteFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteFile.d.ts","sourceRoot":"","sources":["../src/deleteFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAI1D,UAAU,UAAU;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,gBAAqB,EACrB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAW5B"}
1
+ {"version":3,"file":"deleteFile.d.ts","sourceRoot":"","sources":["../src/deleteFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1D,UAAU,UAAU;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,wBAAsB,UAAU,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAIvF"}
@@ -1,12 +1,5 @@
1
- import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
2
- export async function deleteFile({ client, collectionPrefix = '', docPrefix, filename, useCompositePrefixes = false }) {
3
- const { fileKey } = getFileKey({
4
- collectionPrefix,
5
- docPrefix,
6
- filename,
7
- useCompositePrefixes
8
- });
9
- const blockBlobClient = client.getBlockBlobClient(fileKey);
1
+ export async function deleteFile({ client, storageFilePath }) {
2
+ const blockBlobClient = client.getBlockBlobClient(storageFilePath);
10
3
  await blockBlobClient.deleteIfExists();
11
4
  }
12
5
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\n\nimport { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\n\ninterface DeleteArgs {\n client: ContainerClient\n collectionPrefix?: string\n docPrefix: string\n filename: string\n useCompositePrefixes?: boolean\n}\n\nexport async function deleteFile({\n client,\n collectionPrefix = '',\n docPrefix,\n filename,\n useCompositePrefixes = false,\n}: DeleteArgs): Promise<void> {\n const { fileKey } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n const blockBlobClient = client.getBlockBlobClient(fileKey)\n\n await blockBlobClient.deleteIfExists()\n}\n"],"names":["getFileKey","deleteFile","client","collectionPrefix","docPrefix","filename","useCompositePrefixes","fileKey","blockBlobClient","getBlockBlobClient","deleteIfExists"],"mappings":"AAEA,SAASA,UAAU,QAAQ,6CAA4C;AAUvE,OAAO,eAAeC,WAAW,EAC/BC,MAAM,EACNC,mBAAmB,EAAE,EACrBC,SAAS,EACTC,QAAQ,EACRC,uBAAuB,KAAK,EACjB;IACX,MAAM,EAAEC,OAAO,EAAE,GAAGP,WAAW;QAC7BG;QACAC;QACAC;QACAC;IACF;IAEA,MAAME,kBAAkBN,OAAOO,kBAAkB,CAACF;IAElD,MAAMC,gBAAgBE,cAAc;AACtC"}
1
+ {"version":3,"sources":["../src/deleteFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\n\ninterface DeleteArgs {\n client: ContainerClient\n storageFilePath: string\n}\n\nexport async function deleteFile({ client, storageFilePath }: DeleteArgs): Promise<void> {\n const blockBlobClient = client.getBlockBlobClient(storageFilePath)\n\n await blockBlobClient.deleteIfExists()\n}\n"],"names":["deleteFile","client","storageFilePath","blockBlobClient","getBlockBlobClient","deleteIfExists"],"mappings":"AAOA,OAAO,eAAeA,WAAW,EAAEC,MAAM,EAAEC,eAAe,EAAc;IACtE,MAAMC,kBAAkBF,OAAOG,kBAAkB,CAACF;IAElD,MAAMC,gBAAgBE,cAAc;AACtC"}
@@ -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"}
@@ -0,0 +1,12 @@
1
+ import type { ContainerClient } from '@azure/storage-blob';
2
+ import type { GenerateUploadInstructions, UploadInstructionsAccess } from 'payload';
3
+ interface Args {
4
+ access?: UploadInstructionsAccess;
5
+ collectionPrefix: string;
6
+ containerName: string;
7
+ getStorageClient: () => ContainerClient;
8
+ useCompositePrefixes?: boolean;
9
+ }
10
+ export declare const generateUploadInstructions: ({ access, collectionPrefix, containerName, getStorageClient, useCompositePrefixes, }: Args) => GenerateUploadInstructions;
11
+ export {};
12
+ //# sourceMappingURL=generateUploadInstructions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateUploadInstructions.d.ts","sourceRoot":"","sources":["../src/generateUploadInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,qBAAqB,CAAA;AACtF,OAAO,KAAK,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AASnF,UAAU,IAAI;IACZ,MAAM,CAAC,EAAE,wBAAwB,CAAA;IACjC,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,MAAM,eAAe,CAAA;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,eAAO,MAAM,0BAA0B,yFAMpC,IAAI,KAAG,0BA8DT,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { BlobSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob';
2
+ import { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities';
3
+ import { APIError, Forbidden } from 'payload';
4
+ import { assertClientUploadAllowed } from 'payload/internal';
5
+ import { isClientUploadAllowed } from './isClientUploadAllowed.js';
6
+ export const generateUploadInstructions = ({ access, collectionPrefix, containerName, getStorageClient, useCompositePrefixes = false })=>{
7
+ return async ({ collectionSlug, docPrefix, filename, filesize, mimeType, overrideAccess, req })=>{
8
+ if (!overrideAccess && (access ? !await access({
9
+ collectionSlug,
10
+ req
11
+ }) : !req.user)) {
12
+ throw new Forbidden(req.t);
13
+ }
14
+ const collection = req.payload.collections[collectionSlug]?.config;
15
+ if (!isClientUploadAllowed(collection)) {
16
+ throw new APIError('Azure client uploads require allowRestrictedFileTypes to be enabled.', 400);
17
+ }
18
+ assertClientUploadAllowed({
19
+ collection,
20
+ filename,
21
+ mimeType
22
+ });
23
+ const { sanitizedFilename, storageFilePath, uploadReference } = await resolveSignedURLKey({
24
+ collectionPrefix,
25
+ collectionSlug,
26
+ docPrefix,
27
+ filename,
28
+ req,
29
+ useCompositePrefixes
30
+ });
31
+ const blobClient = getStorageClient().getBlobClient(storageFilePath);
32
+ const sasToken = generateBlobSASQueryParameters({
33
+ blobName: storageFilePath,
34
+ containerName,
35
+ contentType: mimeType,
36
+ expiresOn: new Date(Date.now() + 3 * 60 * 60 * 1000),
37
+ permissions: BlobSASPermissions.parse('c'),
38
+ startsOn: new Date(),
39
+ version: '2026-04-06'
40
+ }, getStorageClient().credential);
41
+ return {
42
+ name: 'uploadToAzure',
43
+ type: 'dispatch',
44
+ data: {
45
+ url: `${blobClient.url}?${sasToken.toString()}`
46
+ },
47
+ file: {
48
+ filename: sanitizedFilename,
49
+ mimeType,
50
+ size: filesize,
51
+ uploadReference
52
+ }
53
+ };
54
+ };
55
+ };
56
+
57
+ //# sourceMappingURL=generateUploadInstructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generateUploadInstructions.ts"],"sourcesContent":["import type { ContainerClient, StorageSharedKeyCredential } from '@azure/storage-blob'\nimport type { GenerateUploadInstructions, UploadInstructionsAccess } from 'payload'\n\nimport { BlobSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob'\nimport { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { APIError, Forbidden } from 'payload'\nimport { assertClientUploadAllowed } from 'payload/internal'\n\nimport { isClientUploadAllowed } from './isClientUploadAllowed.js'\n\ninterface Args {\n access?: UploadInstructionsAccess\n collectionPrefix: string\n containerName: string\n getStorageClient: () => ContainerClient\n useCompositePrefixes?: boolean\n}\n\nexport const generateUploadInstructions = ({\n access,\n collectionPrefix,\n containerName,\n getStorageClient,\n useCompositePrefixes = false,\n}: Args): GenerateUploadInstructions => {\n return async ({\n collectionSlug,\n docPrefix,\n filename,\n filesize,\n mimeType,\n overrideAccess,\n req,\n }) => {\n if (!overrideAccess && (access ? !(await access({ collectionSlug, req })) : !req.user)) {\n throw new Forbidden(req.t)\n }\n\n const collection = req.payload.collections[collectionSlug]?.config\n if (!isClientUploadAllowed(collection)) {\n throw new APIError(\n 'Azure client uploads require allowRestrictedFileTypes to be enabled.',\n 400,\n )\n }\n\n assertClientUploadAllowed({ collection, filename, mimeType })\n\n const { sanitizedFilename, storageFilePath, uploadReference } = await resolveSignedURLKey({\n collectionPrefix,\n collectionSlug,\n docPrefix,\n filename,\n req,\n useCompositePrefixes,\n })\n\n const blobClient = getStorageClient().getBlobClient(storageFilePath)\n\n const sasToken = generateBlobSASQueryParameters(\n {\n blobName: storageFilePath,\n containerName,\n contentType: mimeType,\n expiresOn: new Date(Date.now() + 3 * 60 * 60 * 1000),\n permissions: BlobSASPermissions.parse('c'),\n startsOn: new Date(),\n version: '2026-04-06',\n },\n getStorageClient().credential as StorageSharedKeyCredential,\n )\n\n return {\n name: 'uploadToAzure',\n type: 'dispatch',\n data: {\n url: `${blobClient.url}?${sasToken.toString()}`,\n },\n file: {\n filename: sanitizedFilename,\n mimeType,\n size: filesize,\n uploadReference,\n },\n }\n }\n}\n"],"names":["BlobSASPermissions","generateBlobSASQueryParameters","resolveSignedURLKey","APIError","Forbidden","assertClientUploadAllowed","isClientUploadAllowed","generateUploadInstructions","access","collectionPrefix","containerName","getStorageClient","useCompositePrefixes","collectionSlug","docPrefix","filename","filesize","mimeType","overrideAccess","req","user","t","collection","payload","collections","config","sanitizedFilename","storageFilePath","uploadReference","blobClient","getBlobClient","sasToken","blobName","contentType","expiresOn","Date","now","permissions","parse","startsOn","version","credential","name","type","data","url","toString","file","size"],"mappings":"AAGA,SAASA,kBAAkB,EAAEC,8BAA8B,QAAQ,sBAAqB;AACxF,SAASC,mBAAmB,QAAQ,6CAA4C;AAChF,SAASC,QAAQ,EAAEC,SAAS,QAAQ,UAAS;AAC7C,SAASC,yBAAyB,QAAQ,mBAAkB;AAE5D,SAASC,qBAAqB,QAAQ,6BAA4B;AAUlE,OAAO,MAAMC,6BAA6B,CAAC,EACzCC,MAAM,EACNC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,EAChBC,uBAAuB,KAAK,EACvB;IACL,OAAO,OAAO,EACZC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,cAAc,EACdC,GAAG,EACJ;QACC,IAAI,CAACD,kBAAmBV,CAAAA,SAAS,CAAE,MAAMA,OAAO;YAAEK;YAAgBM;QAAI,KAAM,CAACA,IAAIC,IAAI,AAAD,GAAI;YACtF,MAAM,IAAIhB,UAAUe,IAAIE,CAAC;QAC3B;QAEA,MAAMC,aAAaH,IAAII,OAAO,CAACC,WAAW,CAACX,eAAe,EAAEY;QAC5D,IAAI,CAACnB,sBAAsBgB,aAAa;YACtC,MAAM,IAAInB,SACR,wEACA;QAEJ;QAEAE,0BAA0B;YAAEiB;YAAYP;YAAUE;QAAS;QAE3D,MAAM,EAAES,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAE,GAAG,MAAM1B,oBAAoB;YACxFO;YACAI;YACAC;YACAC;YACAI;YACAP;QACF;QAEA,MAAMiB,aAAalB,mBAAmBmB,aAAa,CAACH;QAEpD,MAAMI,WAAW9B,+BACf;YACE+B,UAAUL;YACVjB;YACAuB,aAAahB;YACbiB,WAAW,IAAIC,KAAKA,KAAKC,GAAG,KAAK,IAAI,KAAK,KAAK;YAC/CC,aAAarC,mBAAmBsC,KAAK,CAAC;YACtCC,UAAU,IAAIJ;YACdK,SAAS;QACX,GACA7B,mBAAmB8B,UAAU;QAG/B,OAAO;YACLC,MAAM;YACNC,MAAM;YACNC,MAAM;gBACJC,KAAK,GAAGhB,WAAWgB,GAAG,CAAC,CAAC,EAAEd,SAASe,QAAQ,IAAI;YACjD;YACAC,MAAM;gBACJhC,UAAUW;gBACVT;gBACA+B,MAAMhC;gBACNY;YACF;QACF;IACF;AACF,EAAC"}
package/dist/getFile.d.ts CHANGED
@@ -1,16 +1,17 @@
1
1
  import type { ContainerClient } from '@azure/storage-blob';
2
- import type { CollectionConfig, PayloadRequest } from 'payload';
2
+ import type { CollectionConfig, FileHandlerOperation, PayloadRequest, TypeWithID } from 'payload';
3
3
  interface GetFileArgs {
4
4
  client: ContainerClient;
5
- clientUploadContext?: unknown;
6
5
  collection: CollectionConfig;
7
6
  collectionPrefix?: string;
7
+ doc?: TypeWithID;
8
8
  filename: string;
9
9
  incomingHeaders?: Headers;
10
- prefixQueryParam?: string;
10
+ operation?: FileHandlerOperation;
11
11
  req: PayloadRequest;
12
+ uploadReference?: unknown;
12
13
  useCompositePrefixes?: boolean;
13
14
  }
14
- export declare function getFile({ client, clientUploadContext, collection, collectionPrefix, filename, incomingHeaders, prefixQueryParam, req, useCompositePrefixes, }: GetFileArgs): Promise<Response>;
15
+ export declare function getFile({ client, collection, collectionPrefix, doc, filename, incomingHeaders, operation, req, uploadReference, useCompositePrefixes, }: GetFileArgs): Promise<Response>;
15
16
  export {};
16
17
  //# 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,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAUjG,UAAU,WAAW;IACnB,MAAM,EAAE,eAAe,CAAA;IACvB,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,SAAS,CAAC,EAAE,oBAAoB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAgCD,wBAAsB,OAAO,CAAC,EAC5B,MAAM,EACN,UAAU,EACV,gBAAqB,EACrB,GAAG,EACH,QAAQ,EACR,eAAe,EACf,SAAkB,EAClB,GAAG,EACH,eAAe,EACf,oBAA4B,GAC7B,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsHjC"}
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 { 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 = '', filename, incomingHeaders, prefixQueryParam, 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();
@@ -27,20 +28,21 @@ export async function getFile({ client, clientUploadContext, collection, collect
27
28
  }
28
29
  try {
29
30
  const docPrefix = await getDocPrefix({
30
- clientUploadContext,
31
31
  collection,
32
+ collectionPrefix,
33
+ doc,
32
34
  filename,
33
- prefixQueryParam,
34
- req
35
+ req,
36
+ uploadReference,
37
+ useCompositePrefixes
35
38
  });
36
- const { fileKey } = getFileKey({
39
+ const { storageFilePath } = buildStoragePathData({
37
40
  collectionPrefix,
38
41
  docPrefix,
39
42
  filename,
40
43
  useCompositePrefixes
41
44
  });
42
- const blockBlobClient = client.getBlockBlobClient(fileKey);
43
- // Get file size for range validation
45
+ const blockBlobClient = client.getBlockBlobClient(storageFilePath);
44
46
  const properties = await blockBlobClient.getProperties();
45
47
  const fileSize = properties.contentLength;
46
48
  if (!fileSize) {
@@ -48,8 +50,7 @@ export async function getFile({ client, clientUploadContext, collection, collect
48
50
  status: 500
49
51
  });
50
52
  }
51
- // Handle range request
52
- const rangeHeader = req.headers.get('range');
53
+ const rangeHeader = isTransformSource ? null : req.headers.get('range');
53
54
  const rangeResult = getRangeRequestInfo({
54
55
  fileSize,
55
56
  rangeHeader
@@ -60,33 +61,30 @@ export async function getFile({ client, clientUploadContext, collection, collect
60
61
  status: rangeResult.status
61
62
  });
62
63
  }
63
- // Download with range if partial
64
64
  blob = rangeResult.type === 'partial' ? await blockBlobClient.download(rangeResult.rangeStart, rangeResult.rangeEnd - rangeResult.rangeStart + 1, {
65
65
  abortSignal: abortController.signal
66
66
  }) : await blockBlobClient.download(0, undefined, {
67
67
  abortSignal: abortController.signal
68
68
  });
69
69
  let headers = new Headers(incomingHeaders);
70
- // Add range-related headers from the result
71
70
  for (const [key, value] of Object.entries(rangeResult.headers)){
72
71
  headers.append(key, value);
73
72
  }
74
- // Add Azure-specific headers
75
73
  headers.append('Content-Type', String(properties.contentType));
76
74
  if (properties.etag) {
77
75
  headers.append('ETag', String(properties.etag));
78
76
  }
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'");
77
+ // Apply a restrictive policy to XML-family responses served through Payload.
78
+ if (isXmlMimeType(properties.contentType)) {
79
+ headers.append('Content-Security-Policy', uploadContentSecurityPolicy);
82
80
  }
83
81
  const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
84
- 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') {
85
83
  headers = collection.upload.modifyResponseHeaders({
86
84
  headers
87
85
  }) || headers;
88
86
  }
89
- if (etagFromHeaders && etagFromHeaders === properties.etag) {
87
+ if (!isTransformSource && etagFromHeaders && etagFromHeaders === properties.etag) {
90
88
  return new Response(null, {
91
89
  headers,
92
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 } 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,SA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AEnB;YAAQ,MAAMA;QACpE;QAEA,IAAIiB,mBAAmBA,oBAAoBxB,WAAWuB,IAAI,EAAE;YAC1D,OAAO,IAAInB,SAAS,MAAM;gBACxBG;gBACAF,QAAQ;YACV;QACF;QAEA,IAAI,CAAC3B,KAAKE,kBAAkB,IAAI,CAACR,qBAAqBM,KAAKE,kBAAkB,GAAG;YAC9E,OAAO,IAAIwB,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;QAEA,MAAMsB,SAASjD,KAAKE,kBAAkB;QACtC+C,OAAOC,EAAE,CAAC,SAAS,CAACC;YAClBxC,IAAIyC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBACvBH;gBACAI,KAAK;YACP;YACAzD,6BAA6B;gBAAEC;gBAAiBC;YAAK;QACvD;QAEAc,WAAW;QACX,OAAO,IAAIY,SAASuB,QAAQ;YAAEpB;YAASF,QAAQI,YAAYJ,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, 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,oBAAoBJ,cAAc;IACxC,IAAIV,OAA+Ce;IACnD,IAAIC,WAAW;IAEf,MAAMjB,kBAAkB,IAAIkB;IAC5B,IAAIN,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,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
@@ -8,16 +8,6 @@ export type AzureStorageOptions = {
8
8
  * @default false
9
9
  */
10
10
  allowContainerCreate: boolean;
11
- /**
12
- * When enabled, fields (like the prefix field) will always be inserted into
13
- * the collection schema regardless of whether the plugin is enabled. This
14
- * ensures a consistent schema across all environments.
15
- *
16
- * This will be enabled by default in Payload v4.
17
- *
18
- * @default false
19
- */
20
- alwaysInsertFields?: boolean;
21
11
  /**
22
12
  * Base URL for the Azure Blob storage account
23
13
  */
@@ -30,7 +20,13 @@ export type AzureStorageOptions = {
30
20
  */
31
21
  clientCacheKey?: string;
32
22
  /**
33
- * 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.
24
+ *
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`).
34
30
  */
35
31
  clientUploads?: ClientUploadsConfig;
36
32
  /**
@@ -41,6 +37,21 @@ export type AzureStorageOptions = {
41
37
  * Azure Blob storage connection string
42
38
  */
43
39
  connectionString: string;
40
+ /**
41
+ * Public access level applied to a container that the plugin creates via
42
+ * `allowContainerCreate`. Has no effect on containers that already exist.
43
+ *
44
+ * - `'private'` (default): no anonymous access. Blobs are reachable only
45
+ * through Payload's access-controlled file route.
46
+ * - `'blob'`: unauthenticated clients can read any blob directly from Azure.
47
+ * - `'container'`: unauthenticated clients can read and list blobs directly.
48
+ *
49
+ * Only choose `'blob'` or `'container'` if you deliberately want files served
50
+ * publicly from Azure, bypassing Payload read access control.
51
+ *
52
+ * @default 'private'
53
+ */
54
+ containerAccess?: 'blob' | 'container' | 'private';
44
55
  /**
45
56
  * Azure Blob storage container name
46
57
  */
@@ -53,14 +64,15 @@ export type AzureStorageOptions = {
53
64
  enabled?: boolean;
54
65
  /**
55
66
  * When true, the collection-level prefix and document-level prefix are combined
56
- * (compositional). When false (default), document prefix overrides collection
57
- * prefix entirely.
67
+ * (compositional). When false (default), a document prefix already within the
68
+ * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.
69
+ * Existing files retain their stored prefixes for reads, URLs, and cleanup.
58
70
  *
59
- * Example:
60
- * - collection prefix: `collection-prefix/`
61
- * - document prefix: `document-prefix/`
62
- * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`
63
- * - resulting prefix with useCompositePrefixes=false: `document-prefix/`
71
+ * Example with a document prefix already contained by the collection prefix:
72
+ * - collection prefix: `uploads/`
73
+ * - document prefix: `uploads/documents/`
74
+ * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`
75
+ * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`
64
76
  *
65
77
  * @default false
66
78
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAO3E,OAAO,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAEtF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAE7B;;;;;;;;OAQG;IACH,kBAAk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AAW,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,7 +1,5 @@
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
3
  import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js';
6
4
  export const azureStorage = (azureStorageOptions)=>({
7
5
  name: 'azure',
@@ -12,30 +10,36 @@ export const azureStorage = (azureStorageOptions)=>({
12
10
  containerName: azureStorageOptions.containerName
13
11
  });
14
12
  const isPluginDisabled = azureStorageOptions.enabled === false;
15
- initClientUploads({
16
- clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',
17
- collections: azureStorageOptions.collections,
18
- config: incomingConfig,
19
- enabled: !isPluginDisabled && Boolean(azureStorageOptions.clientUploads),
20
- serverHandler: getGenerateSignedURLHandler({
21
- access: typeof azureStorageOptions.clientUploads === 'object' ? azureStorageOptions.clientUploads.access : undefined,
22
- collections: azureStorageOptions.collections,
23
- containerName: azureStorageOptions.containerName,
24
- getStorageClient,
25
- useCompositePrefixes: azureStorageOptions.useCompositePrefixes
26
- }),
27
- serverHandlerPath: '/storage-azure-generate-signed-url'
28
- });
29
13
  if (isPluginDisabled) {
30
- return incomingConfig;
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);
31
28
  }
32
- const createContainerIfNotExists = ()=>{
33
- void getStorageClientFunc({
29
+ const createContainerIfNotExists = async ()=>{
30
+ const containerClient = getStorageClientFunc({
34
31
  connectionString: azureStorageOptions.connectionString,
35
32
  containerName: azureStorageOptions.containerName
36
- }).createIfNotExists({
37
- access: 'blob'
38
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
+ }
39
43
  };
40
44
  const adapter = createAzureAdapter({
41
45
  allowContainerCreate: azureStorageOptions.allowContainerCreate,
@@ -71,7 +75,6 @@ export const azureStorage = (azureStorageOptions)=>({
71
75
  })
72
76
  };
73
77
  return cloudStoragePlugin({
74
- alwaysInsertFields: azureStorageOptions.alwaysInsertFields,
75
78
  collections: collectionsWithAdapter,
76
79
  useCompositePrefixes: azureStorageOptions.useCompositePrefixes
77
80
  })(config);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\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 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 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 * 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 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 initClientUploads({\n clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',\n collections: azureStorageOptions.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(azureStorageOptions.clientUploads),\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})\n\nexport { getStorageClientFunc as getStorageClient }\n"],"names":["cloudStoragePlugin","initClientUploads","createAzureAdapter","getGenerateSignedURLHandler","getStorageClient","getStorageClientFunc","azureStorage","azureStorageOptions","name","collections","Object","keys","init","incomingConfig","connectionString","containerName","isPluginDisabled","enabled","clientHandler","config","Boolean","clientUploads","serverHandler","access","undefined","useCompositePrefixes","serverHandlerPath","createContainerIfNotExists","createIfNotExists","adapter","allowContainerCreate","baseURL","collectionsWithAdapter","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;AA8EtF,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;YAEzDhB,kBAAkB;gBAChBiB,eAAe;gBACfT,aAAaF,oBAAoBE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AAE;wBAC5C,OAAOG;oBACT;oBAEA,OAAO;wBACL,GAAGA,UAAU;wBACbC,QAAQ;4BACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;4BAClEC,qBAAqB;wBACvB;oBACF;gBACF;YACF;YAEA,OAAOzC,mBAAmB;gBACxB0C,oBAAoBnC,oBAAoBmC,kBAAkB;gBAC1DjC,aAAauB;gBACbP,sBAAsBlB,oBAAoBkB,oBAAoB;YAChE,GAAGN;QACL;IACF,CAAA,EAAE;AAEF,SAASd,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;4BAAGC,SAAS;wBAAK;oBACxE,CAAA,GACA,CAAC;gBAGH,OAAOtB,mBAAmB;oBACxBO,aAAaS;oBACbD,SAAS;oBACTQ,sBAAsBlB,oBAAoBkB,oBAAoB;gBAChE,GAAGZ;YACL;YAEA,MAAMa,6BAA6B;gBACjC,MAAMC,kBAAkBtB,qBAAqB;oBAC3CS,kBAAkBP,oBAAoBO,gBAAgB;oBACtDC,eAAeR,oBAAoBQ,aAAa;gBAClD;gBAEA,qEAAqE;gBACrE,MAAMa,kBAAkBr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@
1
+ export declare const isClientUploadAllowed: (collection?: {
2
+ upload?: {
3
+ allowRestrictedFileTypes?: boolean;
4
+ } | boolean;
5
+ }) => boolean;
6
+ //# sourceMappingURL=isClientUploadAllowed.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
1
+ export const isClientUploadAllowed = (collection)=>Boolean(collection && typeof collection.upload === 'object' && collection.upload.allowRestrictedFileTypes);
2
+
3
+ //# sourceMappingURL=isClientUploadAllowed.js.map
@@ -0,0 +1 @@
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"}
@@ -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": "4.0.0-internal.bc5cf8c",
3
+ "version": "4.0.0-internal.bf4bcce",
4
4
  "description": "Payload storage adapter for Azure Blob Storage",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -38,14 +38,14 @@
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": "4.0.0-internal.bc5cf8c"
41
+ "@azure/storage-blob": "^12.33.0",
42
+ "@payloadcms/plugin-cloud-storage": "4.0.0-internal.bf4bcce"
43
43
  },
44
44
  "devDependencies": {
45
- "payload": "4.0.0-internal.bc5cf8c"
45
+ "payload": "4.0.0-internal.bf4bcce"
46
46
  },
47
47
  "peerDependencies": {
48
- "payload": "4.0.0-internal.bc5cf8c"
48
+ "payload": "4.0.0-internal.bf4bcce"
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=24.15.0"
@@ -1,14 +0,0 @@
1
- import type { ContainerClient } from '@azure/storage-blob';
2
- import type { ClientUploadsAccess } from '@payloadcms/plugin-cloud-storage/types';
3
- import type { PayloadHandler } from 'payload';
4
- import type { AzureStorageOptions } from './index.js';
5
- interface Args {
6
- access?: ClientUploadsAccess;
7
- collections: AzureStorageOptions['collections'];
8
- containerName: string;
9
- getStorageClient: () => ContainerClient;
10
- useCompositePrefixes?: boolean;
11
- }
12
- export declare const getGenerateSignedURLHandler: ({ access, collections, containerName, getStorageClient, useCompositePrefixes, }: Args) => PayloadHandler;
13
- export {};
14
- //# sourceMappingURL=generateSignedURL.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateSignedURL.d.ts","sourceRoot":"","sources":["../src/generateSignedURL.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,qBAAqB,CAAA;AACtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,UAAU,IAAI;IACZ,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,WAAW,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAA;IAC/C,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,MAAM,eAAe,CAAA;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAID,eAAO,MAAM,2BAA2B,GAAI,iFAMzC,IAAI,KAAG,cAsDT,CAAA"}
@@ -1,47 +0,0 @@
1
- import { BlobSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob';
2
- import { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities';
3
- import { APIError, Forbidden } from 'payload';
4
- const defaultAccess = ({ req })=>!!req.user;
5
- export const getGenerateSignedURLHandler = ({ access = defaultAccess, collections, containerName, getStorageClient, useCompositePrefixes = false })=>{
6
- return async (req)=>{
7
- if (!req.json) {
8
- throw new APIError('Unreachable');
9
- }
10
- const { collectionSlug, docPrefix, filename, mimeType } = await req.json();
11
- const collectionStorageConfig = collections[collectionSlug];
12
- if (!collectionStorageConfig) {
13
- throw new APIError(`Collection ${collectionSlug} was not found in Azure storage options`);
14
- }
15
- const collectionPrefix = typeof collectionStorageConfig === 'object' && collectionStorageConfig.prefix || '';
16
- if (!await access({
17
- collectionSlug,
18
- req
19
- })) {
20
- throw new Forbidden();
21
- }
22
- const { fileKey, sanitizedDocPrefix, sanitizedFilename } = await resolveSignedURLKey({
23
- collectionPrefix,
24
- collectionSlug,
25
- docPrefix,
26
- filename,
27
- req,
28
- useCompositePrefixes
29
- });
30
- const blobClient = getStorageClient().getBlobClient(fileKey);
31
- const sasToken = generateBlobSASQueryParameters({
32
- blobName: fileKey,
33
- containerName,
34
- contentType: mimeType,
35
- expiresOn: new Date(Date.now() + 30 * 60 * 1000),
36
- permissions: BlobSASPermissions.parse('w'),
37
- startsOn: new Date()
38
- }, getStorageClient().credential);
39
- return Response.json({
40
- docPrefix: sanitizedDocPrefix,
41
- filename: sanitizedFilename,
42
- url: `${blobClient.url}?${sasToken.toString()}`
43
- });
44
- };
45
- };
46
-
47
- //# sourceMappingURL=generateSignedURL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generateSignedURL.ts"],"sourcesContent":["import type { ContainerClient, StorageSharedKeyCredential } from '@azure/storage-blob'\nimport type { ClientUploadsAccess } from '@payloadcms/plugin-cloud-storage/types'\nimport type { PayloadHandler } from 'payload'\n\nimport { BlobSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob'\nimport { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { APIError, Forbidden } from 'payload'\n\nimport type { AzureStorageOptions } from './index.js'\n\ninterface Args {\n access?: ClientUploadsAccess\n collections: AzureStorageOptions['collections']\n containerName: string\n getStorageClient: () => ContainerClient\n useCompositePrefixes?: boolean\n}\n\nconst defaultAccess: Args['access'] = ({ req }) => !!req.user\n\nexport const getGenerateSignedURLHandler = ({\n access = defaultAccess,\n collections,\n containerName,\n getStorageClient,\n useCompositePrefixes = false,\n}: Args): PayloadHandler => {\n return async (req) => {\n if (!req.json) {\n throw new APIError('Unreachable')\n }\n\n const { collectionSlug, docPrefix, filename, mimeType } = (await req.json()) as {\n collectionSlug: string\n docPrefix?: string\n filename: string\n mimeType: string\n }\n\n const collectionStorageConfig = collections[collectionSlug]\n if (!collectionStorageConfig) {\n throw new APIError(`Collection ${collectionSlug} was not found in Azure storage options`)\n }\n\n const collectionPrefix =\n (typeof collectionStorageConfig === 'object' && collectionStorageConfig.prefix) || ''\n\n if (!(await access({ collectionSlug, req }))) {\n throw new Forbidden()\n }\n\n const { fileKey, sanitizedDocPrefix, sanitizedFilename } = await resolveSignedURLKey({\n collectionPrefix,\n collectionSlug,\n docPrefix,\n filename,\n req,\n useCompositePrefixes,\n })\n\n const blobClient = getStorageClient().getBlobClient(fileKey)\n\n const sasToken = generateBlobSASQueryParameters(\n {\n blobName: fileKey,\n containerName,\n contentType: mimeType,\n expiresOn: new Date(Date.now() + 30 * 60 * 1000),\n permissions: BlobSASPermissions.parse('w'),\n startsOn: new Date(),\n },\n getStorageClient().credential as StorageSharedKeyCredential,\n )\n\n return Response.json({\n docPrefix: sanitizedDocPrefix,\n filename: sanitizedFilename,\n url: `${blobClient.url}?${sasToken.toString()}`,\n })\n }\n}\n"],"names":["BlobSASPermissions","generateBlobSASQueryParameters","resolveSignedURLKey","APIError","Forbidden","defaultAccess","req","user","getGenerateSignedURLHandler","access","collections","containerName","getStorageClient","useCompositePrefixes","json","collectionSlug","docPrefix","filename","mimeType","collectionStorageConfig","collectionPrefix","prefix","fileKey","sanitizedDocPrefix","sanitizedFilename","blobClient","getBlobClient","sasToken","blobName","contentType","expiresOn","Date","now","permissions","parse","startsOn","credential","Response","url","toString"],"mappings":"AAIA,SAASA,kBAAkB,EAAEC,8BAA8B,QAAQ,s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