@aws-lambda-powertools/parser
Version:
The parser package for the Powertools for AWS Lambda (TypeScript) library.
165 lines (164 loc) • 5.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppSyncEventsSubscribeSchema = exports.AppSyncEventsPublishSchema = exports.AppSyncEventsInfoSchema = exports.AppSyncEventsRequestSchema = exports.AppSyncOidcIdentity = exports.AppSyncLambdaAuthIdentity = exports.AppSyncIamIdentity = exports.AppSyncCognitoIdentity = exports.AppSyncEventsBaseSchema = void 0;
const zod_1 = require("zod");
const appsync_shared_js_1 = require("./appsync-shared.js");
Object.defineProperty(exports, "AppSyncCognitoIdentity", { enumerable: true, get: function () { return appsync_shared_js_1.AppSyncCognitoIdentity; } });
Object.defineProperty(exports, "AppSyncIamIdentity", { enumerable: true, get: function () { return appsync_shared_js_1.AppSyncIamIdentity; } });
Object.defineProperty(exports, "AppSyncOidcIdentity", { enumerable: true, get: function () { return appsync_shared_js_1.AppSyncOidcIdentity; } });
/**
* A zod schema for the AppSync Events `identity` object when using an AWS Lambda Authorizer.
*/
const AppSyncLambdaAuthIdentity = zod_1.z.object({
handlerContext: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
});
exports.AppSyncLambdaAuthIdentity = AppSyncLambdaAuthIdentity;
/**
* A zod schema for AppSync Events request object.
*
* This schema is used when extending subscribe and publish events.
*/
const AppSyncEventsRequestSchema = zod_1.z.object({
headers: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
domainName: zod_1.z.string().nullable(),
});
exports.AppSyncEventsRequestSchema = AppSyncEventsRequestSchema;
/**
* A zod schema for AppSync Events info object.
*
* This schema is used when extending subscribe and publish events.
*/
const AppSyncEventsInfoSchema = zod_1.z.object({
channel: zod_1.z.object({
path: zod_1.z.string(),
segments: zod_1.z.array(zod_1.z.string()),
}),
channelNamespace: zod_1.z.object({
name: zod_1.z.string(),
}),
operation: zod_1.z.union([zod_1.z.literal('PUBLISH'), zod_1.z.literal('SUBSCRIBE')]),
});
exports.AppSyncEventsInfoSchema = AppSyncEventsInfoSchema;
/**
* A zod schema for AppSync Events base events.
*
* This schema is used as a base for both publish and subscribe events.
*/
const AppSyncEventsBaseSchema = zod_1.z.object({
identity: zod_1.z.union([
zod_1.z.null(),
appsync_shared_js_1.AppSyncCognitoIdentity,
appsync_shared_js_1.AppSyncIamIdentity,
AppSyncLambdaAuthIdentity,
appsync_shared_js_1.AppSyncOidcIdentity,
]),
result: zod_1.z.null(),
request: AppSyncEventsRequestSchema,
info: AppSyncEventsInfoSchema,
error: zod_1.z.null(),
prev: zod_1.z.null(),
stash: zod_1.z.object({}),
outErrors: zod_1.z.array(zod_1.z.unknown()),
events: zod_1.z.null(),
});
exports.AppSyncEventsBaseSchema = AppSyncEventsBaseSchema;
/**
* A zod schema for AppSync Events publish events.
*
* @example
* ```json
* {
* "identity": null,
* "result": null,
* "request": {
* "headers": {
* "header1": "value1",
* },
* "domainName": "example.com"
* },
* "info": {
* "channel": {
* "path": "/default/foo",
* "segments": ["default", "foo"]
* },
* "channelNamespace": {
* "name": "default"
* },
* "operation": "PUBLISH"
* },
* "error": null,
* "prev": null,
* "stash": {},
* "outErrors": [],
* "events": [
* {
* "payload": {
* "key": "value"
* },
* "id": "12345"
* },
* {
* "payload": {
* "key2": "value2"
* },
* "id": "67890"
* }
* ]
* }
* ```
*
* @see {@link AppSyncEventsPublishEvent | `AppSyncEventsPublishEvent`}
*/
const AppSyncEventsPublishSchema = AppSyncEventsBaseSchema.extend({
info: AppSyncEventsInfoSchema.extend({
operation: zod_1.z.literal('PUBLISH'),
}),
events: zod_1.z
.array(zod_1.z.object({
payload: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
id: zod_1.z.string(),
}))
.min(1),
});
exports.AppSyncEventsPublishSchema = AppSyncEventsPublishSchema;
/**
* A zod schema for AppSync Events subscribe events.
*
* @example
* ```json
* {
* "identity": null,
* "result": null,
* "request": {
* "headers": {
* "header1": "value1",
* },
* "domainName": "example.com"
* },
* "info": {
* "channel": {
* "path": "/default/foo",
* "segments": ["default", "foo"]
* },
* "channelNamespace": {
* "name": "default"
* },
* "operation": "SUBSCRIBE"
* },
* "error": null,
* "prev": null,
* "stash": {},
* "outErrors": [],
* "events": null,
* }
* ```
*
* @see {@link AppSyncEventsSubscribeEvent | `AppSyncEventsSubscribeEvent`}
*/
const AppSyncEventsSubscribeSchema = AppSyncEventsBaseSchema.extend({
info: AppSyncEventsInfoSchema.extend({
operation: zod_1.z.literal('SUBSCRIBE'),
}),
events: zod_1.z.null(),
});
exports.AppSyncEventsSubscribeSchema = AppSyncEventsSubscribeSchema;