From 6c6a4e218bf20292963cc24b23394d03b7a166df Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 21 Jan 2025 19:32:49 +0100 Subject: [PATCH 1/2] improv(parser): export APIGatewayEventRequestContextSchema --- packages/parser/src/schemas/apigw.ts | 10 ++++++---- packages/parser/src/schemas/index.ts | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/parser/src/schemas/apigw.ts b/packages/parser/src/schemas/apigw.ts index 8e7e3d1d7c..606bc736b5 100644 --- a/packages/parser/src/schemas/apigw.ts +++ b/packages/parser/src/schemas/apigw.ts @@ -43,18 +43,19 @@ const APIGatewayEventIdentity = z.object({ * * @see {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference} */ -const APIGatewayEventRequestContext = z +const APIGatewayEventRequestContextSchema = z .object({ accountId: z.string(), apiId: z.string(), deploymentId: z.string().nullish(), authorizer: z - .union([ + .discriminatedUnion('integrationLatency', [ z.object({ integrationLatency: z.number(), principalId: z.string(), }), z.object({ + integrationLatency: z.NEVER, claims: z.record(z.string(), z.any()), scopes: APIGatewayStringArray.optional(), }), @@ -161,7 +162,7 @@ const APIGatewayProxyEventSchema = z.object({ multiValueQueryStringParameters: z.record(APIGatewayStringArray).nullable(), pathParameters: APIGatewayRecord.nullish(), stageVariables: APIGatewayRecord.nullish(), - requestContext: APIGatewayEventRequestContext, + requestContext: APIGatewayEventRequestContextSchema, body: z.string().nullable(), isBase64Encoded: z.boolean(), }); @@ -232,7 +233,7 @@ const APIGatewayRequestAuthorizerEventSchema = z.object({ multiValueQueryStringParameters: z.record(APIGatewayStringArray), pathParameters: APIGatewayRecord, stageVariables: APIGatewayRecord, - requestContext: APIGatewayEventRequestContext, + requestContext: APIGatewayEventRequestContextSchema, domainName: z.string().optional(), deploymentId: z.string().optional(), apiId: z.string().optional(), @@ -262,4 +263,5 @@ export { APIGatewayProxyEventSchema, APIGatewayRequestAuthorizerEventSchema, APIGatewayTokenAuthorizerEventSchema, + APIGatewayEventRequestContextSchema, }; diff --git a/packages/parser/src/schemas/index.ts b/packages/parser/src/schemas/index.ts index 7c92729ad2..266a1251fb 100644 --- a/packages/parser/src/schemas/index.ts +++ b/packages/parser/src/schemas/index.ts @@ -3,6 +3,7 @@ export { APIGatewayProxyEventSchema, APIGatewayRequestAuthorizerEventSchema, APIGatewayTokenAuthorizerEventSchema, + APIGatewayEventRequestContextSchema, } from './apigw.js'; export { AppSyncResolverSchema, From eb9c540c5f54ae660e90ba80da579a21fac31991 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 21 Jan 2025 19:33:58 +0100 Subject: [PATCH 2/2] chore: remove discriminated union --- packages/parser/src/schemas/apigw.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/parser/src/schemas/apigw.ts b/packages/parser/src/schemas/apigw.ts index 606bc736b5..991cd88bcb 100644 --- a/packages/parser/src/schemas/apigw.ts +++ b/packages/parser/src/schemas/apigw.ts @@ -49,13 +49,12 @@ const APIGatewayEventRequestContextSchema = z apiId: z.string(), deploymentId: z.string().nullish(), authorizer: z - .discriminatedUnion('integrationLatency', [ + .union([ z.object({ integrationLatency: z.number(), principalId: z.string(), }), z.object({ - integrationLatency: z.NEVER, claims: z.record(z.string(), z.any()), scopes: APIGatewayStringArray.optional(), }),