@payloadcms/storage-azure 3.0.0-alpha.65 → 3.0.0-alpha.67
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 +51 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
# Azure Storage
|
|
1
|
+
# Azure Blob Storage for Payload
|
|
2
|
+
|
|
3
|
+
This package provides a simple way to use [Azure Blob Storage](https://azure.microsoft.com/en-us/products/storage/blobs) with Payload.
|
|
4
|
+
|
|
5
|
+
**NOTE:** This package removes the need to use `@payloadcms/plugin-cloud-storage` as was needed in Payload 2.x.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @payloadcms/storage-azure
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
- Configure the `collections` object to specify which collections should use the Vercel Blob adapter. The slug _must_ match one of your existing collection slugs.
|
|
16
|
+
- When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { azureStorage } from '@payloadcms/storage-azure'
|
|
20
|
+
import { Media } from './collections/Media'
|
|
21
|
+
import { MediaWithPrefix } from './collections/MediaWithPrefix'
|
|
22
|
+
|
|
23
|
+
export default buildConfig({
|
|
24
|
+
collections: [Media, MediaWithPrefix],
|
|
25
|
+
plugins: [
|
|
26
|
+
azureStorage({
|
|
27
|
+
collections: {
|
|
28
|
+
[mediaSlug]: true,
|
|
29
|
+
[mediaWithPrefixSlug]: {
|
|
30
|
+
prefix,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
|
|
34
|
+
baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
|
|
35
|
+
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
|
|
36
|
+
containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Configuration Options
|
|
43
|
+
|
|
44
|
+
| Option | Description | Default |
|
|
45
|
+
| ---------------------- | ------------------------------------------------------------------------ | ------- |
|
|
46
|
+
| `enabled` | Whether or not to enable the plugin | `true` |
|
|
47
|
+
| `collections` | Collections to apply the Azure Blob adapter to | |
|
|
48
|
+
| `allowContainerCreate` | Whether or not to allow the container to be created if it does not exist | `false` |
|
|
49
|
+
| `baseURL` | Base URL for the Azure Blob storage account | |
|
|
50
|
+
| `connectionString` | Azure Blob storage connection string | |
|
|
51
|
+
| `containerName` | Azure Blob storage container name | |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
2
|
import type { Plugin } from 'payload/config';
|
|
3
3
|
export type AzureStorageOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether or not to allow the container to be created if it does not exist
|
|
6
|
+
*
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
4
9
|
allowContainerCreate: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Base URL for the Azure Blob storage account
|
|
12
|
+
*/
|
|
5
13
|
baseURL: string;
|
|
6
14
|
/**
|
|
7
15
|
* Collection options to apply the Azure Blob adapter to.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAUpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,oBAAoB,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAUpD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAE7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAEtE;;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,kBA4CxB,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { BlobServiceClient } from '@azure/storage-blob'\nimport { cloudStorage } 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'\n\nexport type AzureStorageOptions = {\n allowContainerCreate: boolean\n baseURL: string\n /**\n * Collection options to apply the Azure Blob adapter to.\n */\n collections: Record<string, 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 cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction azureStorageInternal({\n allowContainerCreate,\n baseURL,\n connectionString,\n containerName,\n}: AzureStorageOptions): Adapter {\n let storageClient: ContainerClient | null = null\n const getStorageClient = () => {\n if (storageClient) return storageClient\n\n const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString)\n storageClient = blobServiceClient.getContainerClient(containerName)\n return storageClient\n }\n\n const createContainerIfNotExists = () => {\n void getStorageClient().createIfNotExists({ access: 'blob' })\n }\n\n return ({ collection, prefix }): GeneratedAdapter => {\n return {\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"],"names":["BlobServiceClient","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","azureStorage","azureStorageOptions","incomingConfig","enabled","adapter","azureStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","allowContainerCreate","baseURL","connectionString","containerName","storageClient","getStorageClient","blobServiceClient","fromConnectionString","getContainerClient","createContainerIfNotExists","createIfNotExists","access","prefix","generateURL","handleDelete","handleUpload","staticHandler","onInit"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { BlobServiceClient } from '@azure/storage-blob'\nimport { cloudStorage } 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'\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: Record<string, 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 cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction azureStorageInternal({\n allowContainerCreate,\n baseURL,\n connectionString,\n containerName,\n}: AzureStorageOptions): Adapter {\n let storageClient: ContainerClient | null = null\n const getStorageClient = () => {\n if (storageClient) return storageClient\n\n const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString)\n storageClient = blobServiceClient.getContainerClient(containerName)\n return storageClient\n }\n\n const createContainerIfNotExists = () => {\n void getStorageClient().createIfNotExists({ access: 'blob' })\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"],"names":["BlobServiceClient","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","azureStorage","azureStorageOptions","incomingConfig","enabled","adapter","azureStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","allowContainerCreate","baseURL","connectionString","containerName","storageClient","getStorageClient","blobServiceClient","fromConnectionString","getContainerClient","createContainerIfNotExists","createIfNotExists","access","prefix","name","generateURL","handleDelete","handleUpload","staticHandler","onInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,SAASA,iBAAiB,QAAQ,sBAAqB;AACvD,SAASC,YAAY,QAAQ,mCAAkC;AAE/D,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AAwC/C,OAAO,MAAMC,eACX,CAACC,sBACD,CAACC;QACC,IAAID,oBAAoBE,OAAO,KAAK,OAAO;YACzC,OAAOD;QACT;QAEA,MAAME,UAAUC,qBAAqBJ;QAErC,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFP,oBAAoBQ,WAAW,EAC/BC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMU,SAAS;YACb,GAAGZ,cAAc;YACjBO,aAAa,AAACP,CAAAA,eAAeO,WAAW,IAAI,EAAE,AAAD,EAAGM,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACV,sBAAsB,CAACU,WAAWJ,IAAI,CAAC,EAAE;oBAC5C,OAAOI;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,OAAOvB,aAAa;YAClBc,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAAST,qBAAqB,EAC5Bc,oBAAoB,EACpBC,OAAO,EACPC,gBAAgB,EAChBC,aAAa,EACO;IACpB,IAAIC,gBAAwC;IAC5C,MAAMC,mBAAmB;QACvB,IAAID,eAAe,OAAOA;QAE1B,MAAME,oBAAoB/B,kBAAkBgC,oBAAoB,CAACL;QACjEE,gBAAgBE,kBAAkBE,kBAAkB,CAACL;QACrD,OAAOC;IACT;IAEA,MAAMK,6BAA6B;QACjC,KAAKJ,mBAAmBK,iBAAiB,CAAC;YAAEC,QAAQ;QAAO;IAC7D;IAEA,OAAO,CAAC,EAAEd,UAAU,EAAEe,MAAM,EAAE;QAC5B,OAAO;YACLC,MAAM;YACNC,aAAarC,eAAe;gBAAEwB;gBAASE;YAAc;YACrDY,cAAcrC,gBAAgB;gBAAEmB;gBAAYQ;YAAiB;YAC7DW,cAAcrC,gBAAgB;gBAC5BkB;gBACAQ;gBACAO;YACF;YACAK,eAAerC,WAAW;gBAAEiB;gBAAYQ;YAAiB;YACzD,GAAIL,wBAAwB;gBAAEkB,QAAQT;YAA2B,CAAC;QACpE;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-azure",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.67",
|
|
4
4
|
"description": "Payload storage adapter for Azure Blob Storage",
|
|
5
|
+
"homepage": "https://payloadcms.com",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/payloadcms/payload.git",
|
|
8
9
|
"directory": "packages/storage-azure"
|
|
9
10
|
},
|
|
10
11
|
"license": "MIT",
|
|
11
|
-
"homepage": "https://payloadcms.com",
|
|
12
12
|
"author": "Payload CMS, Inc.",
|
|
13
|
-
"main": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
13
|
"type": "module",
|
|
16
14
|
"exports": {
|
|
17
15
|
".": {
|
|
@@ -20,30 +18,32 @@
|
|
|
20
18
|
"types": "./dist/index.d.ts"
|
|
21
19
|
}
|
|
22
20
|
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
23
26
|
"dependencies": {
|
|
24
27
|
"@azure/abort-controller": "^1.1.0",
|
|
25
28
|
"@azure/storage-blob": "^12.11.0",
|
|
26
29
|
"range-parser": "^1.2.1",
|
|
27
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-alpha.
|
|
30
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-alpha.67"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@types/range-parser": "^1.2.7",
|
|
31
|
-
"payload": "3.0.0-alpha.
|
|
34
|
+
"payload": "3.0.0-alpha.67"
|
|
32
35
|
},
|
|
33
36
|
"peerDependencies": {
|
|
34
|
-
"payload": "3.0.0-alpha.
|
|
37
|
+
"payload": "3.0.0-alpha.67"
|
|
35
38
|
},
|
|
36
39
|
"engines": {
|
|
37
40
|
"node": ">=18.20.2"
|
|
38
41
|
},
|
|
39
|
-
"files": [
|
|
40
|
-
"dist"
|
|
41
|
-
],
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "pnpm build:swc && pnpm build:types",
|
|
44
|
+
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
44
45
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
45
46
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
46
|
-
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
47
47
|
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
48
48
|
}
|
|
49
49
|
}
|