@payloadcms/storage-azure 3.25.0-canary.f62445f → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/client/AzureClientUploadHandler.d.ts +8 -0
- package/dist/client/AzureClientUploadHandler.d.ts.map +1 -0
- package/dist/client/AzureClientUploadHandler.js +28 -0
- package/dist/client/AzureClientUploadHandler.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +3 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/generateSignedURL.d.ts +13 -0
- package/dist/generateSignedURL.d.ts.map +1 -0
- package/dist/generateSignedURL.js +38 -0
- package/dist/generateSignedURL.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -6
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ 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
18
|
|
|
18
19
|
```ts
|
|
19
20
|
import { azureStorage } from '@payloadcms/storage-azure'
|
|
@@ -49,3 +50,4 @@ export default buildConfig({
|
|
|
49
50
|
| `baseURL` | Base URL for the Azure Blob storage account | |
|
|
50
51
|
| `connectionString` | Azure Blob storage connection string | |
|
|
51
52
|
| `containerName` | Azure Blob storage container name | |
|
|
53
|
+
| `clientUploads` | Do uploads directly on the client to bypass limits on Vercel. | |
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const AzureClientUploadHandler: ({ children, collectionSlug, enabled, extra, serverHandlerPath, }: {
|
|
2
|
+
children: import("react").ReactNode;
|
|
3
|
+
collectionSlug: import("packages/payload/src/index.js").UploadCollectionSlug;
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
extra: Record<string, unknown>;
|
|
6
|
+
serverHandlerPath: string;
|
|
7
|
+
}) => import("react").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=AzureClientUploadHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AzureClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/AzureClientUploadHandler.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB;;;;;;aAsB/B,OAAI,aAGR,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client';
|
|
3
|
+
export const AzureClientUploadHandler = createClientUploadHandler({
|
|
4
|
+
handler: async ({ apiRoute, collectionSlug, file, serverHandlerPath, serverURL })=>{
|
|
5
|
+
const response = await fetch(`${serverURL}${apiRoute}${serverHandlerPath}`, {
|
|
6
|
+
body: JSON.stringify({
|
|
7
|
+
collectionSlug,
|
|
8
|
+
filename: file.name,
|
|
9
|
+
mimeType: file.type
|
|
10
|
+
}),
|
|
11
|
+
credentials: 'include',
|
|
12
|
+
method: 'POST'
|
|
13
|
+
});
|
|
14
|
+
const { url } = await response.json();
|
|
15
|
+
await fetch(url, {
|
|
16
|
+
body: file,
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Length': file.size.toString(),
|
|
19
|
+
'Content-Type': file.type,
|
|
20
|
+
// Required for azure
|
|
21
|
+
'x-ms-blob-type': 'BlockBlob'
|
|
22
|
+
},
|
|
23
|
+
method: 'PUT'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=AzureClientUploadHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/AzureClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\n\nexport const AzureClientUploadHandler = createClientUploadHandler({\n handler: async ({ apiRoute, collectionSlug, file, serverHandlerPath, serverURL }) => {\n const response = await fetch(`${serverURL}${apiRoute}${serverHandlerPath}`, {\n body: JSON.stringify({\n collectionSlug,\n filename: file.name,\n mimeType: file.type,\n }),\n credentials: 'include',\n method: 'POST',\n })\n\n const { url } = await response.json()\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})\n"],"names":["createClientUploadHandler","AzureClientUploadHandler","handler","apiRoute","collectionSlug","file","serverHandlerPath","serverURL","response","fetch","body","JSON","stringify","filename","name","mimeType","type","credentials","method","url","json","headers","size","toString"],"mappings":"AAAA;AACA,SAASA,yBAAyB,QAAQ,0CAAyC;AAEnF,OAAO,MAAMC,2BAA2BD,0BAA0B;IAChEE,SAAS,OAAO,EAAEC,QAAQ,EAAEC,cAAc,EAAEC,IAAI,EAAEC,iBAAiB,EAAEC,SAAS,EAAE;QAC9E,MAAMC,WAAW,MAAMC,MAAM,GAAGF,YAAYJ,WAAWG,mBAAmB,EAAE;YAC1EI,MAAMC,KAAKC,SAAS,CAAC;gBACnBR;gBACAS,UAAUR,KAAKS,IAAI;gBACnBC,UAAUV,KAAKW,IAAI;YACrB;YACAC,aAAa;YACbC,QAAQ;QACV;QAEA,MAAM,EAAEC,GAAG,EAAE,GAAG,MAAMX,SAASY,IAAI;QAEnC,MAAMX,MAAMU,KAAK;YACfT,MAAML;YACNgB,SAAS;gBACP,kBAAkBhB,KAAKiB,IAAI,CAACC,QAAQ;gBACpC,gBAAgBlB,KAAKW,IAAI;gBACzB,qBAAqB;gBACrB,kBAAkB;YACpB;YACAE,QAAQ;QACV;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { AzureClientUploadHandler } from '../client/AzureClientUploadHandler.js'\n"],"names":["AzureClientUploadHandler"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,wCAAuC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
11
|
+
export declare const getGenerateSignedURLHandler: ({ access, collections, containerName, getStorageClient, }: Args) => PayloadHandler;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=generateSignedURL.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;CACxC;AAID,eAAO,MAAM,2BAA2B,8DAKrC,IAAI,KAAG,cAqCT,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BlobSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { APIError, Forbidden } from 'payload';
|
|
4
|
+
const defaultAccess = ({ req })=>!!req.user;
|
|
5
|
+
export const getGenerateSignedURLHandler = ({ access = defaultAccess, collections, containerName, getStorageClient })=>{
|
|
6
|
+
return async (req)=>{
|
|
7
|
+
if (!req.json) {
|
|
8
|
+
throw new APIError('Unreachable');
|
|
9
|
+
}
|
|
10
|
+
const { collectionSlug, filename, mimeType } = await req.json();
|
|
11
|
+
const collectionS3Config = collections[collectionSlug];
|
|
12
|
+
if (!collectionS3Config) {
|
|
13
|
+
throw new APIError(`Collection ${collectionSlug} was not found in S3 options`);
|
|
14
|
+
}
|
|
15
|
+
const prefix = typeof collectionS3Config === 'object' && collectionS3Config.prefix || '';
|
|
16
|
+
if (!await access({
|
|
17
|
+
collectionSlug,
|
|
18
|
+
req
|
|
19
|
+
})) {
|
|
20
|
+
throw new Forbidden();
|
|
21
|
+
}
|
|
22
|
+
const fileKey = path.posix.join(prefix, filename);
|
|
23
|
+
const blobClient = getStorageClient().getBlobClient(fileKey);
|
|
24
|
+
const sasToken = generateBlobSASQueryParameters({
|
|
25
|
+
blobName: fileKey,
|
|
26
|
+
containerName,
|
|
27
|
+
contentType: mimeType,
|
|
28
|
+
expiresOn: new Date(Date.now() + 30 * 60 * 1000),
|
|
29
|
+
permissions: BlobSASPermissions.parse('w'),
|
|
30
|
+
startsOn: new Date()
|
|
31
|
+
}, getStorageClient().credential);
|
|
32
|
+
return Response.json({
|
|
33
|
+
url: `${blobClient.url}?${sasToken.toString()}`
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=generateSignedURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 path from 'path'\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}\n\nconst defaultAccess: Args['access'] = ({ req }) => !!req.user\n\nexport const getGenerateSignedURLHandler = ({\n access = defaultAccess,\n collections,\n containerName,\n getStorageClient,\n}: Args): PayloadHandler => {\n return async (req) => {\n if (!req.json) {\n throw new APIError('Unreachable')\n }\n\n const { collectionSlug, filename, mimeType } = await req.json()\n\n const collectionS3Config = collections[collectionSlug]\n if (!collectionS3Config) {\n throw new APIError(`Collection ${collectionSlug} was not found in S3 options`)\n }\n\n const prefix = (typeof collectionS3Config === 'object' && collectionS3Config.prefix) || ''\n\n if (!(await access({ collectionSlug, req }))) {\n throw new Forbidden()\n }\n\n const fileKey = path.posix.join(prefix, filename)\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({ url: `${blobClient.url}?${sasToken.toString()}` })\n }\n}\n"],"names":["BlobSASPermissions","generateBlobSASQueryParameters","path","APIError","Forbidden","defaultAccess","req","user","getGenerateSignedURLHandler","access","collections","containerName","getStorageClient","json","collectionSlug","filename","mimeType","collectionS3Config","prefix","fileKey","posix","join","blobClient","getBlobClient","sasToken","blobName","contentType","expiresOn","Date","now","permissions","parse","startsOn","credential","Response","url","toString"],"mappings":"AAIA,SAASA,kBAAkB,EAAEC,8BAA8B,QAAQ,sBAAqB;AACxF,OAAOC,UAAU,OAAM;AACvB,SAASC,QAAQ,EAAEC,SAAS,QAAQ,UAAS;AAW7C,MAAMC,gBAAgC,CAAC,EAAEC,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;AAE7D,OAAO,MAAMC,8BAA8B,CAAC,EAC1CC,SAASJ,aAAa,EACtBK,WAAW,EACXC,aAAa,EACbC,gBAAgB,EACX;IACL,OAAO,OAAON;QACZ,IAAI,CAACA,IAAIO,IAAI,EAAE;YACb,MAAM,IAAIV,SAAS;QACrB;QAEA,MAAM,EAAEW,cAAc,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAG,MAAMV,IAAIO,IAAI;QAE7D,MAAMI,qBAAqBP,WAAW,CAACI,eAAe;QACtD,IAAI,CAACG,oBAAoB;YACvB,MAAM,IAAId,SAAS,CAAC,WAAW,EAAEW,eAAe,4BAA4B,CAAC;QAC/E;QAEA,MAAMI,SAAS,AAAC,OAAOD,uBAAuB,YAAYA,mBAAmBC,MAAM,IAAK;QAExF,IAAI,CAAE,MAAMT,OAAO;YAAEK;YAAgBR;QAAI,IAAK;YAC5C,MAAM,IAAIF;QACZ;QAEA,MAAMe,UAAUjB,KAAKkB,KAAK,CAACC,IAAI,CAACH,QAAQH;QAExC,MAAMO,aAAaV,mBAAmBW,aAAa,CAACJ;QAEpD,MAAMK,WAAWvB,+BACf;YACEwB,UAAUN;YACVR;YACAe,aAAaV;YACbW,WAAW,IAAIC,KAAKA,KAAKC,GAAG,KAAK,KAAK,KAAK;YAC3CC,aAAa9B,mBAAmB+B,KAAK,CAAC;YACtCC,UAAU,IAAIJ;QAChB,GACAhB,mBAAmBqB,UAAU;QAG/B,OAAOC,SAASrB,IAAI,CAAC;YAAEsB,KAAK,GAAGb,WAAWa,GAAG,CAAC,CAAC,EAAEX,SAASY,QAAQ,IAAI;QAAC;IACzE;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
1
|
+
import type { ClientUploadsConfig, CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
2
|
import type { Plugin, UploadCollectionSlug } from 'payload';
|
|
3
3
|
import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js';
|
|
4
4
|
export type AzureStorageOptions = {
|
|
@@ -12,6 +12,10 @@ export type AzureStorageOptions = {
|
|
|
12
12
|
* Base URL for the Azure Blob storage account
|
|
13
13
|
*/
|
|
14
14
|
baseURL: string;
|
|
15
|
+
/**
|
|
16
|
+
* Do uploads directly on the client to bypass limits on Vercel. You must allow CORS PUT method to your website.
|
|
17
|
+
*/
|
|
18
|
+
clientUploads?: ClientUploadsConfig;
|
|
15
19
|
/**
|
|
16
20
|
* Collection options to apply the Azure Blob adapter to.
|
|
17
21
|
*/
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,mBAAmB,EAEnB,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAUnE,OAAO,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAEtF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAE7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IAEnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAE7F;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,KAAK,MAAM,CAAA;AAE3E,eAAO,MAAM,YAAY,EAAE,kBAmExB,CAAA;AA4BH,OAAO,EAAE,oBAAoB,IAAI,gBAAgB,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
2
|
+
import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
3
|
+
import { getGenerateSignedURLHandler } from './generateSignedURL.js';
|
|
2
4
|
import { getGenerateURL } from './generateURL.js';
|
|
3
5
|
import { getHandleDelete } from './handleDelete.js';
|
|
4
6
|
import { getHandleUpload } from './handleUpload.js';
|
|
@@ -8,7 +10,24 @@ export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
|
|
|
8
10
|
if (azureStorageOptions.enabled === false) {
|
|
9
11
|
return incomingConfig;
|
|
10
12
|
}
|
|
11
|
-
const
|
|
13
|
+
const getStorageClient = ()=>getStorageClientFunc({
|
|
14
|
+
connectionString: azureStorageOptions.connectionString,
|
|
15
|
+
containerName: azureStorageOptions.containerName
|
|
16
|
+
});
|
|
17
|
+
initClientUploads({
|
|
18
|
+
clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',
|
|
19
|
+
collections: azureStorageOptions.collections,
|
|
20
|
+
config: incomingConfig,
|
|
21
|
+
enabled: !!azureStorageOptions.clientUploads,
|
|
22
|
+
serverHandler: getGenerateSignedURLHandler({
|
|
23
|
+
access: typeof azureStorageOptions.clientUploads === 'object' ? azureStorageOptions.clientUploads.access : undefined,
|
|
24
|
+
collections: azureStorageOptions.collections,
|
|
25
|
+
containerName: azureStorageOptions.containerName,
|
|
26
|
+
getStorageClient
|
|
27
|
+
}),
|
|
28
|
+
serverHandlerPath: '/storage-azure-generate-signed-url'
|
|
29
|
+
});
|
|
30
|
+
const adapter = azureStorageInternal(getStorageClient, azureStorageOptions);
|
|
12
31
|
// Add adapter to each collection option object
|
|
13
32
|
const collectionsWithAdapter = Object.entries(azureStorageOptions.collections).reduce((acc, [slug, collOptions])=>({
|
|
14
33
|
...acc,
|
|
@@ -37,7 +56,7 @@ export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
|
|
|
37
56
|
collections: collectionsWithAdapter
|
|
38
57
|
})(config);
|
|
39
58
|
};
|
|
40
|
-
function azureStorageInternal({ allowContainerCreate, baseURL, connectionString, containerName }) {
|
|
59
|
+
function azureStorageInternal(getStorageClient, { allowContainerCreate, baseURL, connectionString, containerName }) {
|
|
41
60
|
const createContainerIfNotExists = ()=>{
|
|
42
61
|
void getStorageClientFunc({
|
|
43
62
|
connectionString,
|
|
@@ -46,10 +65,6 @@ function azureStorageInternal({ allowContainerCreate, baseURL, connectionString,
|
|
|
46
65
|
access: 'blob'
|
|
47
66
|
});
|
|
48
67
|
};
|
|
49
|
-
const getStorageClient = ()=>getStorageClientFunc({
|
|
50
|
-
connectionString,
|
|
51
|
-
containerName
|
|
52
|
-
});
|
|
53
68
|
return ({ collection, prefix })=>{
|
|
54
69
|
return {
|
|
55
70
|
name: 'azure',
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.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 * 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\ntype AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin\n\nexport const azureStorage: AzureStoragePlugin =\n (azureStorageOptions: AzureStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (azureStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = azureStorageInternal(azureStorageOptions)\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 })(config)\n }\n\nfunction azureStorageInternal(
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type {\n Adapter,\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport { getGenerateSignedURLHandler } from './generateSignedURL.js'\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.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 * 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\ntype AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin\n\nexport const azureStorage: AzureStoragePlugin =\n (azureStorageOptions: AzureStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (azureStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const getStorageClient = () =>\n getStorageClientFunc({\n connectionString: azureStorageOptions.connectionString,\n containerName: azureStorageOptions.containerName,\n })\n\n initClientUploads({\n clientHandler: '@payloadcms/storage-azure/client#AzureClientUploadHandler',\n collections: azureStorageOptions.collections,\n config: incomingConfig,\n enabled: !!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 }),\n serverHandlerPath: '/storage-azure-generate-signed-url',\n })\n\n const adapter = azureStorageInternal(getStorageClient, azureStorageOptions)\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 })(config)\n }\n\nfunction azureStorageInternal(\n getStorageClient: () => ContainerClient,\n { allowContainerCreate, baseURL, connectionString, containerName }: AzureStorageOptions,\n): Adapter {\n const createContainerIfNotExists = () => {\n void getStorageClientFunc({ connectionString, containerName }).createIfNotExists({\n access: 'blob',\n })\n }\n\n return ({ collection, prefix }): GeneratedAdapter => {\n return {\n name: 'azure',\n generateURL: getGenerateURL({ baseURL, containerName }),\n handleDelete: getHandleDelete({ collection, getStorageClient }),\n handleUpload: getHandleUpload({\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ collection, getStorageClient }),\n ...(allowContainerCreate && { onInit: createContainerIfNotExists }),\n }\n }\n}\n\nexport { getStorageClientFunc as getStorageClient }\n"],"names":["cloudStoragePlugin","initClientUploads","getGenerateSignedURLHandler","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","getStorageClient","getStorageClientFunc","azureStorage","azureStorageOptions","incomingConfig","enabled","connectionString","containerName","clientHandler","collections","config","clientUploads","serverHandler","access","undefined","serverHandlerPath","adapter","azureStorageInternal","collectionsWithAdapter","Object","entries","reduce","acc","slug","collOptions","map","collection","upload","disableLocalStorage","allowContainerCreate","baseURL","createContainerIfNotExists","createIfNotExists","prefix","name","generateURL","handleDelete","handleUpload","staticHandler","onInit"],"mappings":"AAUA,SAASA,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAE9E,SAASC,2BAA2B,QAAQ,yBAAwB;AACpE,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,oBAAoBC,oBAAoB,QAAQ,8BAA6B;AA6CtF,OAAO,MAAMC,eACX,CAACC,sBACD,CAACC;QACC,IAAID,oBAAoBE,OAAO,KAAK,OAAO;YACzC,OAAOD;QACT;QAEA,MAAMJ,mBAAmB,IACvBC,qBAAqB;gBACnBK,kBAAkBH,oBAAoBG,gBAAgB;gBACtDC,eAAeJ,oBAAoBI,aAAa;YAClD;QAEFb,kBAAkB;YAChBc,eAAe;YACfC,aAAaN,oBAAoBM,WAAW;YAC5CC,QAAQN;YACRC,SAAS,CAAC,CAACF,oBAAoBQ,aAAa;YAC5CC,eAAejB,4BAA4B;gBACzCkB,QACE,OAAOV,oBAAoBQ,aAAa,KAAK,WACzCR,oBAAoBQ,aAAa,CAACE,MAAM,GACxCC;gBACNL,aAAaN,oBAAoBM,WAAW;gBAC5CF,eAAeJ,oBAAoBI,aAAa;gBAChDP;YACF;YACAe,mBAAmB;QACrB;QAEA,MAAMC,UAAUC,qBAAqBjB,kBAAkBG;QAEvD,+CAA+C;QAC/C,MAAMe,yBAAmEC,OAAOC,OAAO,CACrFjB,oBAAoBM,WAAW,EAC/BY,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CR;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMN,SAAS;YACb,GAAGN,cAAc;YACjBK,aAAa,AAACL,CAAAA,eAAeK,WAAW,IAAI,EAAE,AAAD,EAAGgB,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACR,sBAAsB,CAACQ,WAAWH,IAAI,CAAC,EAAE;oBAC5C,OAAOG;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOnC,mBAAmB;YACxBgB,aAAaS;QACf,GAAGR;IACL,EAAC;AAEH,SAASO,qBACPjB,gBAAuC,EACvC,EAAE6B,oBAAoB,EAAEC,OAAO,EAAExB,gBAAgB,EAAEC,aAAa,EAAuB;IAEvF,MAAMwB,6BAA6B;QACjC,KAAK9B,qBAAqB;YAAEK;YAAkBC;QAAc,GAAGyB,iBAAiB,CAAC;YAC/EnB,QAAQ;QACV;IACF;IAEA,OAAO,CAAC,EAAEa,UAAU,EAAEO,MAAM,EAAE;QAC5B,OAAO;YACLC,MAAM;YACNC,aAAavC,eAAe;gBAAEkC;gBAASvB;YAAc;YACrD6B,cAAcvC,gBAAgB;gBAAE6B;gBAAY1B;YAAiB;YAC7DqC,cAAcvC,gBAAgB;gBAC5B4B;gBACA1B;gBACAiC;YACF;YACAK,eAAevC,WAAW;gBAAE2B;gBAAY1B;YAAiB;YACzD,GAAI6B,wBAAwB;gBAAEU,QAAQR;YAA2B,CAAC;QACpE;IACF;AACF;AAEA,SAAS9B,wBAAwBD,gBAAgB,GAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-azure",
|
|
3
|
-
"version": "3.25.0
|
|
3
|
+
"version": "3.25.0",
|
|
4
4
|
"description": "Payload storage adapter for Azure Blob Storage",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"import": "./dist/index.js",
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./client": {
|
|
28
|
+
"import": "./dist/exports/client.js",
|
|
29
|
+
"types": "./dist/exports/client.d.ts",
|
|
30
|
+
"default": "./dist/exports/client.js"
|
|
26
31
|
}
|
|
27
32
|
},
|
|
28
33
|
"main": "./dist/index.js",
|
|
@@ -34,14 +39,14 @@
|
|
|
34
39
|
"@azure/abort-controller": "^1.1.0",
|
|
35
40
|
"@azure/storage-blob": "^12.11.0",
|
|
36
41
|
"range-parser": "^1.2.1",
|
|
37
|
-
"@payloadcms/plugin-cloud-storage": "3.25.0
|
|
42
|
+
"@payloadcms/plugin-cloud-storage": "3.25.0"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
45
|
"@types/range-parser": "^1.2.7",
|
|
41
|
-
"payload": "3.25.0
|
|
46
|
+
"payload": "3.25.0"
|
|
42
47
|
},
|
|
43
48
|
"peerDependencies": {
|
|
44
|
-
"payload": "3.25.0
|
|
49
|
+
"payload": "3.25.0"
|
|
45
50
|
},
|
|
46
51
|
"engines": {
|
|
47
52
|
"node": "^18.20.2 || >=20.9.0"
|