@payloadcms/payload-cloud 3.0.0-canary.ab70b75 → 3.0.0-canary.b8c9483
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/LICENSE.md +2 -2
- package/README.md +4 -4
- package/dist/staticHandler.d.ts.map +1 -1
- package/dist/staticHandler.js +4 -19
- package/dist/staticHandler.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/getStorageClient.d.ts +1 -1
- package/dist/utilities/getStorageClient.d.ts.map +1 -1
- package/dist/utilities/getStorageClient.js +26 -2
- package/dist/utilities/getStorageClient.js.map +1 -1
- package/package.json +12 -4
- package/dist/utilities/refreshSession.d.ts +0 -11
- package/dist/utilities/refreshSession.d.ts.map +0 -1
- package/dist/utilities/refreshSession.js +0 -30
- package/dist/utilities/refreshSession.js.map +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-
|
|
3
|
+
Copyright (c) 2018-2024 Payload CMS, Inc. <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
|
@@ -21,11 +21,11 @@ Add the plugin to your Payload config
|
|
|
21
21
|
`yarn add @payloadcms/payload-cloud`
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
import {
|
|
24
|
+
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'
|
|
25
25
|
import { buildConfig } from 'payload'
|
|
26
26
|
|
|
27
27
|
export default buildConfig({
|
|
28
|
-
plugins: [
|
|
28
|
+
plugins: [payloadCloudPlugin()],
|
|
29
29
|
// rest of config
|
|
30
30
|
})
|
|
31
31
|
```
|
|
@@ -41,7 +41,7 @@ After configuring, ensure that the `from` email address is from a domain you hav
|
|
|
41
41
|
If you wish to opt-out of any Payload cloud features, the plugin also accepts options to do so.
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
|
-
|
|
44
|
+
payloadCloudPlugin({
|
|
45
45
|
storage: false, // Disable file storage
|
|
46
46
|
email: false, // Disable email delivery
|
|
47
47
|
uploadCaching: false, // Disable upload caching
|
|
@@ -53,7 +53,7 @@ payloadCloud({
|
|
|
53
53
|
If you wish to configure upload caching on a per-collection basis, you can do so by passing in a keyed object of collection names. By default, all collections will be cached for 24 hours (86400 seconds). The cache is invalidated when an item is updated or deleted.
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
-
|
|
56
|
+
payloadCloudPlugin({
|
|
57
57
|
uploadCaching: {
|
|
58
58
|
maxAge: 604800, // Override default maxAge for all collections
|
|
59
59
|
collection1Slug: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAA2B,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAA2B,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAKvF,UAAU,IAAI;IACZ,cAAc,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAA;IAC/C,UAAU,EAAE,gBAAgB,CAAA;CAC7B;AAWD,eAAO,MAAM,gBAAgB,mCAAoC,IAAI,KAAG,aAoDvE,CAAA"}
|
package/dist/staticHandler.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createKey } from './utilities/createKey.js';
|
|
2
2
|
import { getStorageClient } from './utilities/getStorageClient.js';
|
|
3
|
-
import { refreshSession } from './utilities/refreshSession.js';
|
|
4
3
|
// Convert a stream into a promise that resolves with a Buffer
|
|
5
4
|
const streamToBuffer = async (readableStream)=>{
|
|
6
5
|
const chunks = [];
|
|
@@ -29,24 +28,10 @@ export const getStaticHandler = ({ cachingOptions, collection })=>{
|
|
|
29
28
|
filename: params.filename,
|
|
30
29
|
identityID
|
|
31
30
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Key
|
|
37
|
-
});
|
|
38
|
-
} catch (err) {
|
|
39
|
-
if (err.code === 'ExpiredToken' || err.Code === 'ExpiredToken') {
|
|
40
|
-
await refreshSession();
|
|
41
|
-
const { storageClient: newStorageClient } = await getStorageClient();
|
|
42
|
-
object = await newStorageClient.getObject({
|
|
43
|
-
Bucket: process.env.PAYLOAD_CLOUD_BUCKET,
|
|
44
|
-
Key
|
|
45
|
-
});
|
|
46
|
-
} else {
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
31
|
+
const object = await storageClient.getObject({
|
|
32
|
+
Bucket: process.env.PAYLOAD_CLOUD_BUCKET,
|
|
33
|
+
Key
|
|
34
|
+
});
|
|
50
35
|
if (!object.Body) {
|
|
51
36
|
return new Response(null, {
|
|
52
37
|
status: 404,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { CollectionCachingConfig, PluginOptions, StaticHandler } from './types.js'\n\nimport { createKey } from './utilities/createKey.js'\nimport { getStorageClient } from './utilities/getStorageClient.js'\
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { CollectionCachingConfig, PluginOptions, StaticHandler } from './types.js'\n\nimport { createKey } from './utilities/createKey.js'\nimport { getStorageClient } from './utilities/getStorageClient.js'\n\ninterface Args {\n cachingOptions?: PluginOptions['uploadCaching']\n collection: CollectionConfig\n}\n\n// Convert a stream into a promise that resolves with a Buffer\nconst streamToBuffer = async (readableStream) => {\n const chunks = []\n for await (const chunk of readableStream) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks)\n}\n\nexport const getStaticHandler = ({ cachingOptions, collection }: Args): StaticHandler => {\n let maxAge = 86400 // 24 hours default\n let collCacheConfig: CollectionCachingConfig | undefined\n if (cachingOptions !== false) {\n // Set custom maxAge for all collections\n maxAge = cachingOptions?.maxAge || maxAge\n collCacheConfig = cachingOptions?.collections?.[collection.slug] || {}\n }\n\n // Set maxAge using collection-specific override\n maxAge = collCacheConfig?.maxAge || maxAge\n\n const cachingEnabled =\n cachingOptions !== false &&\n !!process.env.PAYLOAD_CLOUD_CACHE_KEY &&\n collCacheConfig?.enabled !== false\n\n return async (req, { params }) => {\n try {\n const { identityID, storageClient } = await getStorageClient()\n\n const Key = createKey({\n collection: collection.slug,\n filename: params.filename,\n identityID,\n })\n\n const object = await storageClient.getObject({\n Bucket: process.env.PAYLOAD_CLOUD_BUCKET,\n Key,\n })\n\n if (!object.Body) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const bodyBuffer = await streamToBuffer(object.Body)\n\n return new Response(bodyBuffer, {\n headers: new Headers({\n 'Content-Length': String(object.ContentLength),\n 'Content-Type': object.ContentType,\n ...(cachingEnabled && { 'Cache-Control': `public, max-age=${maxAge}` }),\n ETag: object.ETag,\n }),\n status: 200,\n })\n } catch (err: unknown) {\n req.payload.logger.error({ err, msg: 'Error getting file from cloud storage' })\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["createKey","getStorageClient","streamToBuffer","readableStream","chunks","chunk","push","Buffer","from","concat","getStaticHandler","cachingOptions","collection","maxAge","collCacheConfig","collections","slug","cachingEnabled","process","env","PAYLOAD_CLOUD_CACHE_KEY","enabled","req","params","identityID","storageClient","Key","filename","object","getObject","Bucket","PAYLOAD_CLOUD_BUCKET","Body","Response","status","statusText","bodyBuffer","headers","Headers","String","ContentLength","ContentType","ETag","err","payload","logger","error","msg"],"mappings":"AAIA,SAASA,SAAS,QAAQ,2BAA0B;AACpD,SAASC,gBAAgB,QAAQ,kCAAiC;AAOlE,8DAA8D;AAC9D,MAAMC,iBAAiB,OAAOC;IAC5B,MAAMC,SAAS,EAAE;IACjB,WAAW,MAAMC,SAASF,eAAgB;QACxCC,OAAOE,IAAI,CAAC,OAAOD,UAAU,WAAWE,OAAOC,IAAI,CAACH,SAASA;IAC/D;IACA,OAAOE,OAAOE,MAAM,CAACL;AACvB;AAEA,OAAO,MAAMM,mBAAmB,CAAC,EAAEC,cAAc,EAAEC,UAAU,EAAQ;IACnE,IAAIC,SAAS,MAAM,mBAAmB;;IACtC,IAAIC;IACJ,IAAIH,mBAAmB,OAAO;QAC5B,wCAAwC;QACxCE,SAASF,gBAAgBE,UAAUA;QACnCC,kBAAkBH,gBAAgBI,aAAa,CAACH,WAAWI,IAAI,CAAC,IAAI,CAAC;IACvE;IAEA,gDAAgD;IAChDH,SAASC,iBAAiBD,UAAUA;IAEpC,MAAMI,iBACJN,mBAAmB,SACnB,CAAC,CAACO,QAAQC,GAAG,CAACC,uBAAuB,IACrCN,iBAAiBO,YAAY;IAE/B,OAAO,OAAOC,KAAK,EAAEC,MAAM,EAAE;QAC3B,IAAI;YACF,MAAM,EAAEC,UAAU,EAAEC,aAAa,EAAE,GAAG,MAAMxB;YAE5C,MAAMyB,MAAM1B,UAAU;gBACpBY,YAAYA,WAAWI,IAAI;gBAC3BW,UAAUJ,OAAOI,QAAQ;gBACzBH;YACF;YAEA,MAAMI,SAAS,MAAMH,cAAcI,SAAS,CAAC;gBAC3CC,QAAQZ,QAAQC,GAAG,CAACY,oBAAoB;gBACxCL;YACF;YAEA,IAAI,CAACE,OAAOI,IAAI,EAAE;gBAChB,OAAO,IAAIC,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAY;YACnE;YAEA,MAAMC,aAAa,MAAMlC,eAAe0B,OAAOI,IAAI;YAEnD,OAAO,IAAIC,SAASG,YAAY;gBAC9BC,SAAS,IAAIC,QAAQ;oBACnB,kBAAkBC,OAAOX,OAAOY,aAAa;oBAC7C,gBAAgBZ,OAAOa,WAAW;oBAClC,GAAIxB,kBAAkB;wBAAE,iBAAiB,CAAC,gBAAgB,EAAEJ,OAAO,CAAC;oBAAC,CAAC;oBACtE6B,MAAMd,OAAOc,IAAI;gBACnB;gBACAR,QAAQ;YACV;QACF,EAAE,OAAOS,KAAc;YACrBrB,IAAIsB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBAAEH;gBAAKI,KAAK;YAAwC;YAC7E,OAAO,IAAId,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig, Config, FileData, PayloadRequest, TypeWithID } from 'payload';
|
|
1
|
+
import type { CollectionConfig, Config, FileData, PayloadRequest, TypeWithID, UploadCollectionSlug } from 'payload';
|
|
2
2
|
export interface File {
|
|
3
3
|
buffer: Buffer;
|
|
4
4
|
filename: string;
|
|
@@ -81,7 +81,7 @@ export interface PluginOptions {
|
|
|
81
81
|
/**
|
|
82
82
|
* Caching configuration per-collection
|
|
83
83
|
*/
|
|
84
|
-
collections?: Record<
|
|
84
|
+
collections?: Partial<Record<UploadCollectionSlug, CollectionCachingConfig>>;
|
|
85
85
|
/** Caching in seconds override for all collections
|
|
86
86
|
* @default 86400 (24 hours)
|
|
87
87
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,MAAM,EACN,QAAQ,EACR,cAAc,EACd,UAAU,EACV,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAEhB,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE;IAChC,UAAU,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,GAAG,CAAA;IACT,IAAI,EAAE,IAAI,CAAA;IACV,GAAG,EAAE,cAAc,CAAA;CACpB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE1B,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE;IAChC,UAAU,EAAE,gBAAgB,CAAA;IAC5B,GAAG,EAAE,QAAQ,GAAG,UAAU,GAAG,cAAc,CAAA;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE1B,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE;IAC/B,UAAU,EAAE,gBAAgB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;AAE9B,MAAM,MAAM,aAAa,GAAG,CAC1B,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE;IAAE,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,KACvD,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAA;AAExD,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,EAAE,MAAM,CAAA;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,KAAK,CAAC,EACF;QACE,kBAAkB,EAAE,MAAM,CAAA;QAC1B,eAAe,EAAE,MAAM,CAAA;QACvB,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,GACD,KAAK,CAAA;IAET;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAA;IAEf;;;;;;;;;;;;;;;;;OAiBG;IAEH,aAAa,CAAC,EACV;QACE;;WAEG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,CAAC,CAAA;QAC5E;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,GACD,KAAK,CAAA;CACV;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n FileData,\n PayloadRequest,\n TypeWithID,\n UploadCollectionSlug,\n} from 'payload'\n\nexport interface File {\n buffer: Buffer\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n}\n\nexport type HandleUpload = (args: {\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequest\n}) => Promise<void> | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: FileData & TypeWithID & TypeWithPrefix\n filename: string\n req: PayloadRequest\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequest,\n args: { params: { collection: string; filename: string } },\n) => Promise<Response> | Promise<void> | Response | void\n\nexport interface PayloadCloudEmailOptions {\n apiKey: string\n config: Config\n defaultDomain: string\n defaultFromAddress?: string\n defaultFromName?: string\n skipVerify?: boolean\n}\n\nexport interface PluginOptions {\n /** Payload Cloud Email\n * @default true\n */\n email?:\n | {\n defaultFromAddress: string\n defaultFromName: string\n skipVerify?: boolean\n }\n | false\n\n /**\n * Payload Cloud API endpoint\n *\n * @internal Endpoint override for developement\n */\n endpoint?: string\n\n /** Payload Cloud Storage\n * @default true\n */\n storage?: false\n\n /**\n * Upload caching. Defaults to 24 hours for all collections.\n *\n * Optionally configure caching per collection\n *\n * ```ts\n * {\n * collSlug1: {\n * maxAge: 3600 // Custom value in seconds\n * },\n * collSlug2: {\n * enabled: false // Disable caching for this collection\n * }\n * }\n * ```\n *\n * @default true\n */\n\n uploadCaching?:\n | {\n /**\n * Caching configuration per-collection\n */\n collections?: Partial<Record<UploadCollectionSlug, CollectionCachingConfig>>\n /** Caching in seconds override for all collections\n * @default 86400 (24 hours)\n */\n maxAge?: number\n }\n | false\n}\n\nexport type CollectionCachingConfig = {\n /**\n * Enable/disable caching for this collection\n *\n * @default true\n */\n enabled?: boolean\n /** Caching in seconds override for this collection\n * @default 86400 (24 hours)\n */\n maxAge?: number\n}\n"],"names":[],"mappings":"AAgHA,WAWC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageClient.d.ts","sourceRoot":"","sources":["../../src/utilities/getStorageClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getStorageClient.d.ts","sourceRoot":"","sources":["../../src/utilities/getStorageClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAKzC,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,GAAG,CAAC,EAAE,CAAA;CACtB,CAAC,CAAA;AAMF,eAAO,MAAM,gBAAgB,EAAE,gBAwC9B,CAAA"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity';
|
|
2
|
+
import * as AWS from '@aws-sdk/client-s3';
|
|
3
|
+
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
|
|
4
|
+
import { authAsCognitoUser } from './authAsCognitoUser.js';
|
|
5
|
+
let storageClient = null;
|
|
6
|
+
let session = null;
|
|
7
|
+
let identityID;
|
|
2
8
|
export const getStorageClient = async ()=>{
|
|
3
9
|
if (storageClient && session?.isValid()) {
|
|
4
10
|
return {
|
|
@@ -6,7 +12,25 @@ export const getStorageClient = async ()=>{
|
|
|
6
12
|
storageClient
|
|
7
13
|
};
|
|
8
14
|
}
|
|
9
|
-
await
|
|
15
|
+
session = await authAsCognitoUser(process.env.PAYLOAD_CLOUD_PROJECT_ID, process.env.PAYLOAD_CLOUD_COGNITO_PASSWORD);
|
|
16
|
+
const cognitoIdentity = new CognitoIdentityClient({
|
|
17
|
+
credentials: fromCognitoIdentityPool({
|
|
18
|
+
clientConfig: {
|
|
19
|
+
region: 'us-east-1'
|
|
20
|
+
},
|
|
21
|
+
identityPoolId: process.env.PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID,
|
|
22
|
+
logins: {
|
|
23
|
+
[`cognito-idp.us-east-1.amazonaws.com/${process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_ID}`]: session.getIdToken().getJwtToken()
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
const credentials = await cognitoIdentity.config.credentials();
|
|
28
|
+
// @ts-expect-error - Incorrect AWS types
|
|
29
|
+
identityID = credentials.identityId;
|
|
30
|
+
storageClient = new AWS.S3({
|
|
31
|
+
credentials,
|
|
32
|
+
region: process.env.PAYLOAD_CLOUD_BUCKET_REGION
|
|
33
|
+
});
|
|
10
34
|
return {
|
|
11
35
|
identityID,
|
|
12
36
|
storageClient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getStorageClient.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\n\nexport type GetStorageClient = () => Promise<{\n identityID: string\n storageClient: AWS.S3\n}>\n\
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getStorageClient.ts"],"sourcesContent":["import type { CognitoUserSession } from 'amazon-cognito-identity-js'\n\nimport { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity'\nimport * as AWS from '@aws-sdk/client-s3'\nimport { fromCognitoIdentityPool } from '@aws-sdk/credential-providers'\n\nimport { authAsCognitoUser } from './authAsCognitoUser.js'\n\nexport type GetStorageClient = () => Promise<{\n identityID: string\n storageClient: AWS.S3\n}>\n\nlet storageClient: AWS.S3 | null = null\nlet session: CognitoUserSession | null = null\nlet identityID: string\n\nexport const getStorageClient: GetStorageClient = async () => {\n if (storageClient && session?.isValid()) {\n return {\n identityID,\n storageClient,\n }\n }\n\n session = await authAsCognitoUser(\n process.env.PAYLOAD_CLOUD_PROJECT_ID,\n process.env.PAYLOAD_CLOUD_COGNITO_PASSWORD,\n )\n\n const cognitoIdentity = new CognitoIdentityClient({\n credentials: fromCognitoIdentityPool({\n clientConfig: {\n region: 'us-east-1',\n },\n identityPoolId: process.env.PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID,\n logins: {\n [`cognito-idp.us-east-1.amazonaws.com/${process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_ID}`]:\n session.getIdToken().getJwtToken(),\n },\n }),\n })\n\n const credentials = await cognitoIdentity.config.credentials()\n\n // @ts-expect-error - Incorrect AWS types\n identityID = credentials.identityId\n\n storageClient = new AWS.S3({\n credentials,\n region: process.env.PAYLOAD_CLOUD_BUCKET_REGION,\n })\n\n return {\n identityID,\n storageClient,\n }\n}\n"],"names":["CognitoIdentityClient","AWS","fromCognitoIdentityPool","authAsCognitoUser","storageClient","session","identityID","getStorageClient","isValid","process","env","PAYLOAD_CLOUD_PROJECT_ID","PAYLOAD_CLOUD_COGNITO_PASSWORD","cognitoIdentity","credentials","clientConfig","region","identityPoolId","PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID","logins","PAYLOAD_CLOUD_COGNITO_USER_POOL_ID","getIdToken","getJwtToken","config","identityId","S3","PAYLOAD_CLOUD_BUCKET_REGION"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,mCAAkC;AACxE,YAAYC,SAAS,qBAAoB;AACzC,SAASC,uBAAuB,QAAQ,gCAA+B;AAEvE,SAASC,iBAAiB,QAAQ,yBAAwB;AAO1D,IAAIC,gBAA+B;AACnC,IAAIC,UAAqC;AACzC,IAAIC;AAEJ,OAAO,MAAMC,mBAAqC;IAChD,IAAIH,iBAAiBC,SAASG,WAAW;QACvC,OAAO;YACLF;YACAF;QACF;IACF;IAEAC,UAAU,MAAMF,kBACdM,QAAQC,GAAG,CAACC,wBAAwB,EACpCF,QAAQC,GAAG,CAACE,8BAA8B;IAG5C,MAAMC,kBAAkB,IAAIb,sBAAsB;QAChDc,aAAaZ,wBAAwB;YACnCa,cAAc;gBACZC,QAAQ;YACV;YACAC,gBAAgBR,QAAQC,GAAG,CAACQ,sCAAsC;YAClEC,QAAQ;gBACN,CAAC,CAAC,oCAAoC,EAAEV,QAAQC,GAAG,CAACU,kCAAkC,CAAC,CAAC,CAAC,EACvFf,QAAQgB,UAAU,GAAGC,WAAW;YACpC;QACF;IACF;IAEA,MAAMR,cAAc,MAAMD,gBAAgBU,MAAM,CAACT,WAAW;IAE5D,yCAAyC;IACzCR,aAAaQ,YAAYU,UAAU;IAEnCpB,gBAAgB,IAAIH,IAAIwB,EAAE,CAAC;QACzBX;QACAE,QAAQP,QAAQC,GAAG,CAACgB,2BAA2B;IACjD;IAEA,OAAO;QACLpB;QACAF;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/payload-cloud",
|
|
3
|
-
"version": "3.0.0-canary.
|
|
3
|
+
"version": "3.0.0-canary.b8c9483",
|
|
4
4
|
"description": "The official Payload Cloud plugin",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
"directory": "packages/payload-cloud"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
+
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
13
|
+
"maintainers": [
|
|
14
|
+
{
|
|
15
|
+
"name": "Payload",
|
|
16
|
+
"email": "info@payloadcms.com",
|
|
17
|
+
"url": "https://payloadcms.com"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
12
20
|
"type": "module",
|
|
13
21
|
"exports": {
|
|
14
22
|
".": {
|
|
@@ -30,16 +38,16 @@
|
|
|
30
38
|
"amazon-cognito-identity-js": "^6.1.2",
|
|
31
39
|
"nodemailer": "6.9.10",
|
|
32
40
|
"resend": "^0.17.2",
|
|
33
|
-
"@payloadcms/email-nodemailer": "3.0.0-canary.
|
|
41
|
+
"@payloadcms/email-nodemailer": "3.0.0-canary.b8c9483"
|
|
34
42
|
},
|
|
35
43
|
"devDependencies": {
|
|
36
44
|
"@types/jest": "29.5.12",
|
|
37
45
|
"@types/nodemailer": "6.4.14",
|
|
38
46
|
"ts-jest": "^29.1.0",
|
|
39
|
-
"payload": "3.0.0-canary.
|
|
47
|
+
"payload": "3.0.0-canary.b8c9483"
|
|
40
48
|
},
|
|
41
49
|
"peerDependencies": {
|
|
42
|
-
"payload": "3.0.0-canary.
|
|
50
|
+
"payload": "3.0.0-canary.b8c9483"
|
|
43
51
|
},
|
|
44
52
|
"scripts": {
|
|
45
53
|
"build": "pnpm build:types && pnpm build:swc",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { CognitoUserSession } from 'amazon-cognito-identity-js';
|
|
2
|
-
import * as AWS from '@aws-sdk/client-s3';
|
|
3
|
-
export type GetStorageClient = () => Promise<{
|
|
4
|
-
identityID: string;
|
|
5
|
-
storageClient: AWS.S3;
|
|
6
|
-
}>;
|
|
7
|
-
export declare let storageClient: AWS.S3 | null;
|
|
8
|
-
export declare let session: CognitoUserSession | null;
|
|
9
|
-
export declare let identityID: string;
|
|
10
|
-
export declare const refreshSession: () => Promise<void>;
|
|
11
|
-
//# sourceMappingURL=refreshSession.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"refreshSession.d.ts","sourceRoot":"","sources":["../../src/utilities/refreshSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAGpE,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAKzC,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,GAAG,CAAC,EAAE,CAAA;CACtB,CAAC,CAAA;AAEF,eAAO,IAAI,aAAa,EAAE,GAAG,CAAC,EAAE,GAAG,IAAW,CAAA;AAC9C,eAAO,IAAI,OAAO,EAAE,kBAAkB,GAAG,IAAW,CAAA;AACpD,eAAO,IAAI,UAAU,EAAE,MAAM,CAAA;AAE7B,eAAO,MAAM,cAAc,qBA4B1B,CAAA"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity';
|
|
2
|
-
import * as AWS from '@aws-sdk/client-s3';
|
|
3
|
-
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
|
|
4
|
-
import { authAsCognitoUser } from './authAsCognitoUser.js';
|
|
5
|
-
export let storageClient = null;
|
|
6
|
-
export let session = null;
|
|
7
|
-
export let identityID;
|
|
8
|
-
export const refreshSession = async ()=>{
|
|
9
|
-
session = await authAsCognitoUser(process.env.PAYLOAD_CLOUD_PROJECT_ID, process.env.PAYLOAD_CLOUD_COGNITO_PASSWORD);
|
|
10
|
-
const cognitoIdentity = new CognitoIdentityClient({
|
|
11
|
-
credentials: fromCognitoIdentityPool({
|
|
12
|
-
clientConfig: {
|
|
13
|
-
region: 'us-east-1'
|
|
14
|
-
},
|
|
15
|
-
identityPoolId: process.env.PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID,
|
|
16
|
-
logins: {
|
|
17
|
-
[`cognito-idp.us-east-1.amazonaws.com/${process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_ID}`]: session.getIdToken().getJwtToken()
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
});
|
|
21
|
-
const credentials = await cognitoIdentity.config.credentials();
|
|
22
|
-
// @ts-expect-error - Incorrect AWS types
|
|
23
|
-
identityID = credentials.identityId;
|
|
24
|
-
storageClient = new AWS.S3({
|
|
25
|
-
credentials,
|
|
26
|
-
region: process.env.PAYLOAD_CLOUD_BUCKET_REGION
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=refreshSession.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/refreshSession.ts"],"sourcesContent":["import type { CognitoUserSession } from 'amazon-cognito-identity-js'\n\nimport { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity'\nimport * as AWS from '@aws-sdk/client-s3'\nimport { fromCognitoIdentityPool } from '@aws-sdk/credential-providers'\n\nimport { authAsCognitoUser } from './authAsCognitoUser.js'\n\nexport type GetStorageClient = () => Promise<{\n identityID: string\n storageClient: AWS.S3\n}>\n\nexport let storageClient: AWS.S3 | null = null\nexport let session: CognitoUserSession | null = null\nexport let identityID: string\n\nexport const refreshSession = async () => {\n session = await authAsCognitoUser(\n process.env.PAYLOAD_CLOUD_PROJECT_ID,\n process.env.PAYLOAD_CLOUD_COGNITO_PASSWORD,\n )\n\n const cognitoIdentity = new CognitoIdentityClient({\n credentials: fromCognitoIdentityPool({\n clientConfig: {\n region: 'us-east-1',\n },\n identityPoolId: process.env.PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID,\n logins: {\n [`cognito-idp.us-east-1.amazonaws.com/${process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_ID}`]:\n session.getIdToken().getJwtToken(),\n },\n }),\n })\n\n const credentials = await cognitoIdentity.config.credentials()\n\n // @ts-expect-error - Incorrect AWS types\n identityID = credentials.identityId\n\n storageClient = new AWS.S3({\n credentials,\n region: process.env.PAYLOAD_CLOUD_BUCKET_REGION,\n })\n}\n"],"names":["CognitoIdentityClient","AWS","fromCognitoIdentityPool","authAsCognitoUser","storageClient","session","identityID","refreshSession","process","env","PAYLOAD_CLOUD_PROJECT_ID","PAYLOAD_CLOUD_COGNITO_PASSWORD","cognitoIdentity","credentials","clientConfig","region","identityPoolId","PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID","logins","PAYLOAD_CLOUD_COGNITO_USER_POOL_ID","getIdToken","getJwtToken","config","identityId","S3","PAYLOAD_CLOUD_BUCKET_REGION"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,mCAAkC;AACxE,YAAYC,SAAS,qBAAoB;AACzC,SAASC,uBAAuB,QAAQ,gCAA+B;AAEvE,SAASC,iBAAiB,QAAQ,yBAAwB;AAO1D,OAAO,IAAIC,gBAA+B,KAAI;AAC9C,OAAO,IAAIC,UAAqC,KAAI;AACpD,OAAO,IAAIC,WAAkB;AAE7B,OAAO,MAAMC,iBAAiB;IAC5BF,UAAU,MAAMF,kBACdK,QAAQC,GAAG,CAACC,wBAAwB,EACpCF,QAAQC,GAAG,CAACE,8BAA8B;IAG5C,MAAMC,kBAAkB,IAAIZ,sBAAsB;QAChDa,aAAaX,wBAAwB;YACnCY,cAAc;gBACZC,QAAQ;YACV;YACAC,gBAAgBR,QAAQC,GAAG,CAACQ,sCAAsC;YAClEC,QAAQ;gBACN,CAAC,CAAC,oCAAoC,EAAEV,QAAQC,GAAG,CAACU,kCAAkC,CAAC,CAAC,CAAC,EACvFd,QAAQe,UAAU,GAAGC,WAAW;YACpC;QACF;IACF;IAEA,MAAMR,cAAc,MAAMD,gBAAgBU,MAAM,CAACT,WAAW;IAE5D,yCAAyC;IACzCP,aAAaO,YAAYU,UAAU;IAEnCnB,gBAAgB,IAAIH,IAAIuB,EAAE,CAAC;QACzBX;QACAE,QAAQP,QAAQC,GAAG,CAACgB,2BAA2B;IACjD;AACF,EAAC"}
|