fix(payload-cloud): add ts strict mode and fix a couple of wrong runtime behaviors (#10570)

This commit is contained in:
Germán Jabloñski
2025-01-14 13:14:37 -03:00
committed by GitHub
parent 31ae27b67d
commit 16ad7a671f
7 changed files with 28 additions and 6 deletions

View File

@@ -7,7 +7,7 @@ type NodemailerAdapter = ReturnType<typeof nodemailerAdapter>
export const payloadCloudEmail = async ( export const payloadCloudEmail = async (
args: PayloadCloudEmailOptions, args: PayloadCloudEmailOptions,
): Promise<NodemailerAdapter> | undefined => { ): Promise<NodemailerAdapter | undefined> => {
if (process.env.PAYLOAD_CLOUD !== 'true' || !args) { if (process.env.PAYLOAD_CLOUD !== 'true' || !args) {
return undefined return undefined
} }

View File

@@ -17,8 +17,10 @@ export const getAfterDeleteHook = ({
const { identityID, storageClient } = await getStorageClient() const { identityID, storageClient } = await getStorageClient()
const filesToDelete: string[] = [ const filesToDelete: string[] = [
doc.filename, doc.filename || '',
...Object.values(doc?.sizes || []).map((resizedFileData) => resizedFileData?.filename), ...Object.values(doc?.sizes || [])
.map((resizedFileData) => resizedFileData.filename)
.filter((filename): filename is string => filename !== null),
] ]
const promises = filesToDelete.map(async (filename) => { const promises = filesToDelete.map(async (filename) => {

View File

@@ -128,7 +128,7 @@ export const payloadCloudPlugin =
return config return config
} }
const oldAutoRunCopy = config.jobs.autoRun const oldAutoRunCopy = config.jobs.autoRun ?? []
const newAutoRun = async (payload: Payload) => { const newAutoRun = async (payload: Payload) => {
const instance = generateRandomString() const instance = generateRandomString()

View File

@@ -11,7 +11,7 @@ interface Args {
} }
// Convert a stream into a promise that resolves with a Buffer // Convert a stream into a promise that resolves with a Buffer
const streamToBuffer = async (readableStream) => { const streamToBuffer = async (readableStream: any) => {
const chunks = [] const chunks = []
for await (const chunk of readableStream) { for await (const chunk of readableStream) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk) chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
@@ -52,7 +52,7 @@ export const getStaticHandler = ({ cachingOptions, collection }: Args): StaticHa
Key: key, Key: key,
}) })
if (!object.Body) { if (!object.Body || !object.ContentType || !object.ETag) {
return new Response(null, { status: 404, statusText: 'Not Found' }) return new Response(null, { status: 404, statusText: 'Not Found' })
} }

View File

@@ -13,6 +13,13 @@ export const authAsCognitoUser = async (
return sessionAndToken return sessionAndToken
} }
if (!process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_CLIENT_ID) {
throw new Error('PAYLOAD_CLOUD_COGNITO_USER_POOL_CLIENT_ID is required')
}
if (!process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_ID) {
throw new Error('PAYLOAD_CLOUD_COGNITO_USER_POOL_ID is required')
}
const userPool = new CognitoUserPool({ const userPool = new CognitoUserPool({
ClientId: process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_CLIENT_ID, ClientId: process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_CLIENT_ID,
UserPoolId: process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_ID, UserPoolId: process.env.PAYLOAD_CLOUD_COGNITO_USER_POOL_ID,

View File

@@ -23,6 +23,16 @@ export const getStorageClient: GetStorageClient = async () => {
} }
} }
if (!process.env.PAYLOAD_CLOUD_PROJECT_ID) {
throw new Error('PAYLOAD_CLOUD_PROJECT_ID is required')
}
if (!process.env.PAYLOAD_CLOUD_COGNITO_PASSWORD) {
throw new Error('PAYLOAD_CLOUD_COGNITO_PASSWORD is required')
}
if (!process.env.PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID) {
throw new Error('PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID is required')
}
session = await authAsCognitoUser( session = await authAsCognitoUser(
process.env.PAYLOAD_CLOUD_PROJECT_ID, process.env.PAYLOAD_CLOUD_PROJECT_ID,
process.env.PAYLOAD_CLOUD_COGNITO_PASSWORD, process.env.PAYLOAD_CLOUD_COGNITO_PASSWORD,

View File

@@ -1,4 +1,7 @@
{ {
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": {
"strict": true
},
"references": [{ "path": "../payload" }] "references": [{ "path": "../payload" }]
} }