@payloadcms/payload-cloud 3.0.0-canary.ab70b75 → 3.0.0-canary.bda91d8
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 +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/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 +4 -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/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"}
|
|
@@ -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.bda91d8",
|
|
4
4
|
"description": "The official Payload Cloud plugin",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -30,16 +30,16 @@
|
|
|
30
30
|
"amazon-cognito-identity-js": "^6.1.2",
|
|
31
31
|
"nodemailer": "6.9.10",
|
|
32
32
|
"resend": "^0.17.2",
|
|
33
|
-
"@payloadcms/email-nodemailer": "3.0.0-canary.
|
|
33
|
+
"@payloadcms/email-nodemailer": "3.0.0-canary.bda91d8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/jest": "29.5.12",
|
|
37
37
|
"@types/nodemailer": "6.4.14",
|
|
38
38
|
"ts-jest": "^29.1.0",
|
|
39
|
-
"payload": "3.0.0-canary.
|
|
39
|
+
"payload": "3.0.0-canary.bda91d8"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"payload": "3.0.0-canary.
|
|
42
|
+
"payload": "3.0.0-canary.bda91d8"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"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"}
|