@geekmidas/constructs 9.5.0 → 9.6.1
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/CHANGELOG.md +69 -0
- package/dist/Endpoint-ZtG0zVz1.d.mts.map +1 -1
- package/dist/{Queue-I5NfFV0V.d.mts → Queue-Bg6WzavN.d.mts} +26 -3
- package/dist/Queue-Bg6WzavN.d.mts.map +1 -0
- package/dist/{Queue-915lgS2D.mjs → Queue-Cvv-QluM.mjs} +6 -3
- package/dist/Queue-Cvv-QluM.mjs.map +1 -0
- package/dist/{Queue-HbdYCQ-X.cjs → Queue-Di2a2N-b.cjs} +6 -3
- package/dist/Queue-Di2a2N-b.cjs.map +1 -0
- package/dist/{Queue-XQNGO6_-.d.cts → Queue-GJexVGOh.d.cts} +26 -3
- package/dist/Queue-GJexVGOh.d.cts.map +1 -0
- package/dist/adaptors/aws.cjs +4 -2
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +3 -2
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +3 -2
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +4 -2
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/testing.d.cts +1 -1
- package/dist/adaptors/testing.d.mts +1 -1
- package/dist/queue/index.cjs +24 -4
- package/dist/queue/index.cjs.map +1 -1
- package/dist/queue/index.d.cts +20 -3
- package/dist/queue/index.d.cts.map +1 -1
- package/dist/queue/index.d.mts +20 -3
- package/dist/queue/index.d.mts.map +1 -1
- package/dist/queue/index.mjs +24 -4
- package/dist/queue/index.mjs.map +1 -1
- package/package.json +22 -22
- package/src/queue/AWSLambdaQueueAdaptor.ts +5 -1
- package/src/queue/Queue.ts +16 -0
- package/src/queue/QueueBuilder.ts +36 -3
- package/src/queue/__tests__/AWSLambdaQueueAdaptor.spec.ts +65 -0
- package/src/queue/__tests__/QueueBuilder.spec.ts +19 -0
- package/dist/Queue-915lgS2D.mjs.map +0 -1
- package/dist/Queue-HbdYCQ-X.cjs.map +0 -1
- package/dist/Queue-I5NfFV0V.d.mts.map +0 -1
- package/dist/Queue-XQNGO6_-.d.cts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.mjs","names":["envParser: EnvironmentParser<{}>","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction\n\t\t>","options: AmazonApiGatewayEndpointOptions","body: string | undefined | null","isBase64Encoded: boolean | undefined","contentType: string | undefined","e: TEvent","event: Event<TEvent, TInput, TServices, TLogger, TSession>","db: any","metadata","output","trx: any","result","lambdaResponse: AmazonApiGatewayEndpointHandlerResponse","baseHeaders: Record<string, string> | undefined","setCookieHeaders: string[]","ctx: any","event: TEvent","context: Context","queryParams: Record<string, string | string[] | undefined> | null","parts: string[]","e: APIGatewayProxyEvent","mergedParams: Record<string, string | string[]>","data: APIGatewayProxyEvent","context: Context","envParser: EnvironmentParser<{}>","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>","options: AmazonApiGatewayEndpointOptions","e: APIGatewayProxyEventV2","event: APIGatewayProxyEventV2","context: Context","envParser: EnvironmentParser<{}>","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>","options: AmazonApiGatewayEndpointOptions","envParser: EnvironmentParser<{}>","queue: Queue<TName, TMessage, TServices, TLogger>","value: string","record: SQSRecord","event: SQSEvent","context: Context","batchItemFailures: { itemIdentifier: string }[]","records: QueueRecord<TMessage>[]","envParser: EnvironmentParser<{}>","subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>","events: any[]","event: SQSEvent | SNSEvent","record: SNSEventRecord","record: SQSRecord","value: string","event: any","event: SubscriberEvent<TServices, TLogger>","event: unknown","context: Context"],"sources":["../../src/endpoints/AmazonApiGatewayEndpointAdaptor.ts","../../src/endpoints/parseQueryParams.ts","../../src/endpoints/AmazonApiGatewayV1EndpointAdaptor.ts","../../src/endpoints/AmazonApiGatewayV2EndpointAdaptor.ts","../../src/queue/AWSLambdaQueueAdaptor.ts","../../src/subscribers/AWSLambdaSubscriberAdaptor.ts"],"sourcesContent":["import type { AuditableAction, AuditStorage } from '@geekmidas/audit';\nimport { withRlsContext } from '@geekmidas/db/rls';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type {\n\tAPIGatewayProxyEvent,\n\tAPIGatewayProxyEventV2,\n\tContext,\n} from 'aws-lambda';\nimport type { Telemetry } from '../telemetry';\nimport type { HttpMethod } from '../types';\nimport { Endpoint, type EndpointSchemas, ResponseBuilder } from './Endpoint';\n\n/**\n * Telescope integration for request recording.\n * Uses Middy middleware pattern for compatibility with existing telescope package.\n */\nexport interface TelescopeIntegration {\n\tmiddleware: MiddlewareObj<any, any, Error, Context>;\n}\n\nimport {\n\tForbiddenError,\n\tUnprocessableEntityError,\n\twrapError,\n} from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type {\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport { publishConstructEvents } from '../publisher';\nimport type { MappedAudit } from './audit';\nimport type { CookieFn, HeaderFn } from './Endpoint';\nimport {\n\tcreateAuditContext,\n\texecuteWithAuditTransaction,\n} from './processAudits';\n\n// Helper function to publish events\n\n/**\n * Options for Amazon API Gateway endpoint adaptors\n */\nexport interface AmazonApiGatewayEndpointOptions {\n\t/**\n\t * Telescope integration for request recording and monitoring.\n\t *\n\t * @example\n\t * ```typescript\n\t * import { telescopeMiddleware } from '@geekmidas/telescope/lambda';\n\t *\n\t * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n\t * telescope: { middleware: telescopeMiddleware(telescope) },\n\t * });\n\t * ```\n\t */\n\ttelescope?: TelescopeIntegration;\n\n\t/**\n\t * Telemetry integration for distributed tracing.\n\t * Works with any OpenTelemetry-compatible backend.\n\t *\n\t * @example\n\t * ```typescript\n\t * import { OTelTelemetry } from '@geekmidas/telescope/instrumentation';\n\t *\n\t * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n\t * telemetry: new OTelTelemetry(),\n\t * });\n\t * ```\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport abstract class AmazonApiGatewayEndpoint<\n\tTHandler extends\n\t\t| AmazonApiGatewayV1EndpointHandler\n\t\t| AmazonApiGatewayV2EndpointHandler,\n\tTEvent extends HandlerEvent<THandler>,\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tprotected options: AmazonApiGatewayEndpointOptions;\n\n\tconstructor(\n\t\tprotected envParser: EnvironmentParser<{}>,\n\t\tprotected readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction\n\t\t>,\n\t\toptions: AmazonApiGatewayEndpointOptions = {},\n\t) {\n\t\tthis.options = options;\n\t}\n\n\tprivate error(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\t(req.event.logger || this.endpoint.logger).error(\n\t\t\t\t\treq.error || {},\n\t\t\t\t\t'Error processing request',\n\t\t\t\t);\n\t\t\t\tconst wrappedError = wrapError(req.error);\n\n\t\t\t\t// Set the response with the proper status code from the HttpError\n\t\t\t\treq.response = {\n\t\t\t\t\tstatusCode: wrappedError.statusCode,\n\t\t\t\t\tbody: wrappedError.body,\n\t\t\t\t};\n\t\t\t},\n\t\t};\n\t}\n\tabstract getInput(e: TEvent): GetInputResponse;\n\n\t/**\n\t * Decodes the raw body from an API Gateway event.\n\t * Uses Content-Type to decide parsing strategy (like Express/Fastify/Hono):\n\t * - `application/json` (or missing) → JSON.parse the decoded string\n\t * - Anything else → return decoded string as-is, let the schema handle it\n\t *\n\t * Defaults to JSON when no Content-Type is provided for backwards compatibility.\n\t */\n\tstatic decodeBody(\n\t\tbody: string | undefined | null,\n\t\tisBase64Encoded: boolean | undefined,\n\t\tcontentType: string | undefined,\n\t): any {\n\t\tif (!body) return undefined;\n\n\t\tconst raw = isBase64Encoded\n\t\t\t? Buffer.from(body, 'base64').toString('utf-8')\n\t\t\t: body;\n\n\t\tconst isJson =\n\t\t\t!contentType || contentType.toLowerCase().includes('application/json');\n\t\tif (isJson) {\n\t\t\treturn JSON.parse(raw);\n\t\t}\n\n\t\treturn raw;\n\t}\n\n\tprotected getCookies(e: TEvent): CookieFn {\n\t\tconst headers = e.headers as Record<string, string>;\n\t\treturn Endpoint.createCookies(headers?.cookie);\n\t}\n\n\tprivate input(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst { body, query, params } = this.getInput(req.event);\n\t\t\t\t\tconst headers = req.event.headers as Record<string, string>;\n\t\t\t\t\tconst header = Endpoint.createHeaders(headers);\n\t\t\t\t\tconst cookie = this.getCookies(req.event);\n\n\t\t\t\t\tObject.assign(req.event, {\n\t\t\t\t\t\tbody: await this.endpoint.parseInput(body, 'body'),\n\t\t\t\t\t\tquery: await this.endpoint.parseInput(query, 'query'),\n\t\t\t\t\t\tparams: await this.endpoint.parseInput(params, 'params'),\n\t\t\t\t\t\theader,\n\t\t\t\t\t\tcookie,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Convert validation errors to 422 Unprocessable Entity\n\t\t\t\t\tif (error && typeof error === 'object' && Array.isArray(error)) {\n\t\t\t\t\t\tthrow new UnprocessableEntityError('Validation failed', error);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tabstract getLoggerContext(data: TEvent, context: Context): LoggerContext;\n\n\tprivate logger(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\treq.event.logger = this.endpoint.logger.child({\n\t\t\t\t\troute: this.endpoint.route,\n\t\t\t\t\thost: req.event.headers?.host,\n\t\t\t\t\tmethod: this.endpoint.method,\n\t\t\t\t\t...this.getLoggerContext(req.event, req.context),\n\t\t\t\t}) as TLogger;\n\t\t\t},\n\t\t};\n\t}\n\tprivate services(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst _logger = req.event.logger as TLogger;\n\t\t\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\t\t\tServiceRecord<TServices>\n\t\t\t\t>(this.envParser);\n\n\t\t\t\tconst services = await serviceDiscovery.register(\n\t\t\t\t\tthis.endpoint.services,\n\t\t\t\t);\n\n\t\t\t\treq.event.services = services;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate authorize(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst logger = req.event.logger as TLogger;\n\t\t\t\tconst services = req.event.services;\n\t\t\t\tconst header = req.event.header;\n\t\t\t\tconst cookie = req.event.cookie;\n\t\t\t\tconst session = req.event.session as TSession;\n\n\t\t\t\tconst isAuthorized = await this.endpoint.authorize({\n\t\t\t\t\theader,\n\t\t\t\t\tcookie,\n\t\t\t\t\tservices,\n\t\t\t\t\tlogger,\n\t\t\t\t\tsession,\n\t\t\t\t\t...((req.event as any).db !== undefined && {\n\t\t\t\t\t\tdb: (req.event as any).db,\n\t\t\t\t\t}),\n\t\t\t\t\tbody: (req.event as any).body,\n\t\t\t\t\tquery: (req.event as any).query,\n\t\t\t\t\tparams: (req.event as any).params,\n\t\t\t\t} as any);\n\n\t\t\t\tif (!isAuthorized) {\n\t\t\t\t\tlogger.warn('Forbidden access attempt');\n\t\t\t\t\tthrow new ForbiddenError(\n\t\t\t\t\t\t'Forbidden access to the endpoint',\n\t\t\t\t\t\t'You do not have permission to access this resource.',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate database(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tif (!this.endpoint.databaseService) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst _logger = req.event.logger as TLogger;\n\t\t\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\t\t\tServiceRecord<TServices>\n\t\t\t\t>(this.envParser);\n\n\t\t\t\tconst db = await serviceDiscovery\n\t\t\t\t\t.register([this.endpoint.databaseService])\n\t\t\t\t\t.then(\n\t\t\t\t\t\t(s) =>\n\t\t\t\t\t\t\ts[this.endpoint.databaseService?.serviceName as keyof typeof s],\n\t\t\t\t\t);\n\n\t\t\t\t(req.event as any).db = db;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate session(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst logger = req.event.logger as TLogger;\n\t\t\t\tconst services = req.event.services;\n\t\t\t\tconst db = (req.event as any).db;\n\t\t\t\treq.event.session = (await this.endpoint.getSession({\n\t\t\t\t\tlogger,\n\t\t\t\t\tservices,\n\t\t\t\t\theader: req.event.header,\n\t\t\t\t\tcookie: req.event.cookie,\n\t\t\t\t\t...(db !== undefined && { db }),\n\t\t\t\t} as any)) as TSession;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate events(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tafter: async (req) => {\n\t\t\t\tconst event = req.event;\n\t\t\t\tconst response = (event as any)\n\t\t\t\t\t.__response as InferStandardSchema<TOutSchema>;\n\t\t\t\tconst statusCode = req.response?.statusCode ?? this.endpoint.status;\n\n\t\t\t\t// Only publish events on successful responses (2xx status codes)\n\t\t\t\t// Note: Audits are processed inside the handler's transaction\n\t\t\t\tif (Endpoint.isSuccessStatus(statusCode)) {\n\t\t\t\t\tconst logger = event.logger as TLogger;\n\t\t\t\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\t\t\t\tServiceRecord<TServices>\n\t\t\t\t\t>(this.envParser);\n\n\t\t\t\t\t// Publish events\n\t\t\t\t\tawait publishConstructEvents(\n\t\t\t\t\t\tthis.endpoint,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t\tserviceDiscovery,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async _handler(\n\t\tevent: Event<TEvent, TInput, TServices, TLogger, TSession>,\n\t) {\n\t\tconst input = this.endpoint.refineInput(event);\n\t\tconst logger = event.logger as TLogger;\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\tServiceRecord<TServices>\n\t\t>(this.envParser);\n\n\t\t// Create audit context if audit storage is configured\n\t\tconst auditContext = await createAuditContext(\n\t\t\tthis.endpoint,\n\t\t\tserviceDiscovery,\n\t\t\tlogger,\n\t\t\t{\n\t\t\t\tsession: event.session,\n\t\t\t\theader: event.header,\n\t\t\t\tcookie: event.cookie,\n\t\t\t\tservices: event.services as Record<string, unknown>,\n\t\t\t},\n\t\t);\n\n\t\t// Warn if declarative audits are configured but no audit storage\n\t\tconst audits = this.endpoint.audits as MappedAudit<\n\t\t\tTAuditAction,\n\t\t\tTOutSchema\n\t\t>[];\n\t\tif (!auditContext && audits?.length) {\n\t\t\tlogger.warn('No auditor storage service available');\n\t\t}\n\n\t\t// Get pre-resolved database from middleware\n\t\tconst rawDb = (event as any).db;\n\n\t\t// Extract RLS context if configured and not bypassed\n\t\tconst rlsActive =\n\t\t\tthis.endpoint.rlsConfig &&\n\t\t\t!this.endpoint.rlsBypass &&\n\t\t\trawDb !== undefined;\n\t\tconst rlsContext = rlsActive\n\t\t\t? await this.endpoint.rlsConfig?.extractor({\n\t\t\t\t\tservices: event.services as ServiceRecord<TServices>,\n\t\t\t\t\tsession: event.session,\n\t\t\t\t\theader: event.header,\n\t\t\t\t\tcookie: event.cookie,\n\t\t\t\t\tlogger,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\t// Execute handler with automatic audit transaction support\n\t\tconst result = await executeWithAuditTransaction(\n\t\t\tauditContext,\n\t\t\tasync (auditor) => {\n\t\t\t\t// Use audit transaction as db only if the storage uses the same database service\n\t\t\t\tconst sameDatabase =\n\t\t\t\t\tauditContext?.storage?.databaseServiceName &&\n\t\t\t\t\tauditContext.storage.databaseServiceName ===\n\t\t\t\t\t\tthis.endpoint.databaseService?.serviceName;\n\t\t\t\tconst baseDb = sameDatabase\n\t\t\t\t\t? (auditor?.getTransaction?.() ?? rawDb)\n\t\t\t\t\t: rawDb;\n\n\t\t\t\t// Helper to execute handler with given db\n\t\t\t\tconst executeHandler = async (db: any) => {\n\t\t\t\t\tconst responseBuilder = new ResponseBuilder();\n\t\t\t\t\tconst response = await this.endpoint.handler(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\theader: event.header,\n\t\t\t\t\t\t\tcookie: event.cookie,\n\t\t\t\t\t\t\tlogger: event.logger,\n\t\t\t\t\t\t\tservices: event.services,\n\t\t\t\t\t\t\tsession: event.session,\n\t\t\t\t\t\t\tauditor,\n\t\t\t\t\t\t\tdb,\n\t\t\t\t\t\t\t...input,\n\t\t\t\t\t\t} as any,\n\t\t\t\t\t\tresponseBuilder,\n\t\t\t\t\t);\n\n\t\t\t\t\t// Check if response has metadata\n\t\t\t\t\tlet data = response;\n\t\t\t\t\tlet metadata = responseBuilder.getMetadata();\n\n\t\t\t\t\tif (Endpoint.hasMetadata(response)) {\n\t\t\t\t\t\tdata = response.data;\n\t\t\t\t\t\tmetadata = response.metadata;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst output = this.endpoint.outputSchema\n\t\t\t\t\t\t? await this.endpoint.parseOutput(data)\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\treturn { output, metadata, responseBuilder };\n\t\t\t\t};\n\n\t\t\t\t// If RLS is active, wrap handler with RLS context\n\t\t\t\tif (rlsActive && rlsContext && baseDb) {\n\t\t\t\t\treturn withRlsContext(\n\t\t\t\t\t\tbaseDb,\n\t\t\t\t\t\trlsContext,\n\t\t\t\t\t\tasync (trx: any) => executeHandler(trx),\n\t\t\t\t\t\t{ prefix: this.endpoint.rlsConfig?.prefix },\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn executeHandler(baseDb);\n\t\t\t},\n\t\t\t// Process declarative audits after handler (inside transaction)\n\t\t\tasync (result, auditor) => {\n\t\t\t\tif (!audits?.length) return;\n\n\t\t\t\tfor (const audit of audits) {\n\t\t\t\t\tif (audit.when && !audit.when(result.output as any)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst payload = audit.payload(result.output as any);\n\t\t\t\t\tconst entityId = audit.entityId?.(result.output as any);\n\t\t\t\t\tauditor.audit(audit.type as any, payload as any, {\n\t\t\t\t\t\ttable: audit.table,\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\t// Pass rawDb so storage can reuse existing transactions\n\t\t\t{ db: rawDb },\n\t\t);\n\n\t\tconst { output, metadata } = result;\n\t\tconst isJsonResponse = this.endpoint.responseType === 'application/json';\n\t\tconst body =\n\t\t\toutput === undefined\n\t\t\t\t? undefined\n\t\t\t\t: isJsonResponse\n\t\t\t\t\t? JSON.stringify(output)\n\t\t\t\t\t: typeof output === 'string'\n\t\t\t\t\t\t? output\n\t\t\t\t\t\t: String(output);\n\n\t\t// Store response for middleware access\n\t\t(event as any).__response = output;\n\n\t\t// Build response with metadata\n\t\tconst lambdaResponse: AmazonApiGatewayEndpointHandlerResponse = {\n\t\t\tstatusCode: metadata.status ?? this.endpoint.status,\n\t\t\tbody,\n\t\t};\n\n\t\t// Compose headers. For non-JSON responseType, emit a default\n\t\t// Content-Type header which metadata.headers (r.header()) can override.\n\t\tconst baseHeaders: Record<string, string> | undefined = isJsonResponse\n\t\t\t? undefined\n\t\t\t: { 'content-type': this.endpoint.responseType };\n\n\t\tif (\n\t\t\tbaseHeaders ||\n\t\t\t(metadata.headers && Object.keys(metadata.headers).length > 0)\n\t\t) {\n\t\t\tlambdaResponse.headers = {\n\t\t\t\t...(baseHeaders ?? {}),\n\t\t\t\t...(metadata.headers ?? {}),\n\t\t\t};\n\t\t}\n\n\t\t// Format cookies as Set-Cookie headers\n\t\tif (metadata.cookies && metadata.cookies.size > 0) {\n\t\t\tconst setCookieHeaders: string[] = [];\n\t\t\tfor (const [name, { value, options }] of metadata.cookies) {\n\t\t\t\tsetCookieHeaders.push(\n\t\t\t\t\tEndpoint.formatCookieHeader(name, value, options),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (setCookieHeaders.length > 0) {\n\t\t\t\tlambdaResponse.multiValueHeaders = {\n\t\t\t\t\t...lambdaResponse.multiValueHeaders,\n\t\t\t\t\t'Set-Cookie': setCookieHeaders,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn lambdaResponse;\n\t}\n\n\t/**\n\t * Convert Telemetry interface to Middy middleware\n\t */\n\tprivate telemetry(): Middleware<TEvent, TInput, TServices, TLogger> | null {\n\t\tif (!this.options.telemetry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst telemetry = this.options.telemetry;\n\t\tlet ctx: any;\n\n\t\treturn {\n\t\t\tbefore: (request) => {\n\t\t\t\tctx = telemetry.onRequestStart({\n\t\t\t\t\tevent: request.event,\n\t\t\t\t\tcontext: request.context,\n\t\t\t\t});\n\t\t\t},\n\t\t\tafter: (request) => {\n\t\t\t\tif (ctx) {\n\t\t\t\t\ttelemetry.onRequestEnd(ctx, {\n\t\t\t\t\t\tstatusCode: request.response?.statusCode ?? 200,\n\t\t\t\t\t\tbody: request.response?.body,\n\t\t\t\t\t\theaders: request.response?.headers,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\tonError: (request) => {\n\t\t\t\tif (ctx && request.error) {\n\t\t\t\t\ttelemetry.onRequestError(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\trequest.error instanceof Error\n\t\t\t\t\t\t\t? request.error\n\t\t\t\t\t\t\t: new Error(String(request.error)),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tget handler() {\n\t\tconst handler = this._handler.bind(this);\n\t\tlet chain = middy(handler)\n\t\t\t.use(this.logger())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services())\n\t\t\t.use(this.input())\n\t\t\t.use(this.database())\n\t\t\t.use(this.session())\n\t\t\t.use(this.authorize())\n\t\t\t.use(this.events());\n\n\t\t// Add telemetry middleware if configured (runs early for span creation)\n\t\tconst telemetryMiddleware = this.telemetry();\n\t\tif (telemetryMiddleware) {\n\t\t\tchain = chain.use(telemetryMiddleware);\n\t\t}\n\n\t\t// Add Telescope middleware if configured (runs first/last in chain)\n\t\tif (this.options.telescope?.middleware) {\n\t\t\tchain = chain.use(this.options.telescope.middleware);\n\t\t}\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: TEvent, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.endpoint.logger.child({ requestId }) as TLogger;\n\n\t\t\t// Cast event to any since Middy middlewares enrich the event with\n\t\t\t// services, logger, session, etc. during the middleware chain execution\n\t\t\treturn runWithRequestContext({ logger, requestId, startTime }, () =>\n\t\t\t\tchain(event as unknown as Parameters<typeof chain>[0], context),\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as THandler;\n\t}\n}\n\nexport type Event<\n\tTEvent extends APIGatewayProxyEvent | APIGatewayProxyEventV2,\n\tTInput extends EndpointSchemas = {},\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n> = {\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\theader: HeaderFn;\n\tcookie: CookieFn;\n\tsession: TSession;\n} & TEvent &\n\tInferComposableStandardSchema<TInput>;\n\ntype Middleware<\n\tTEvent extends APIGatewayProxyEvent | APIGatewayProxyEventV2,\n\tTInput extends EndpointSchemas = {},\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n> = MiddlewareObj<Event<TEvent, TInput, TServices, TLogger, TSession>>;\n\nexport type AmazonApiGatewayEndpointHandlerResponse = {\n\tstatusCode: number;\n\tbody: string | undefined;\n\theaders?: Record<string, string>;\n\tmultiValueHeaders?: Record<string, string[]>;\n};\n\nexport type LoggerContext = {\n\tfn: {\n\t\tname: string;\n\t\tversion: string;\n\t};\n\treq: {\n\t\tid: string | undefined;\n\t\tawsRequestId: string;\n\t\tpath: string;\n\t\tip: string | undefined;\n\t\tuserAgent: string | undefined;\n\t};\n};\n\nexport type GetInputResponse = {\n\tbody: any;\n\tquery: any;\n\tparams: any;\n};\n\nexport type AmazonApiGatewayV1EndpointHandler = (\n\tevent: APIGatewayProxyEvent,\n\tcontext: Context,\n) => Promise<AmazonApiGatewayEndpointHandlerResponse>;\n\nexport type AmazonApiGatewayV2EndpointHandler = (\n\tevent: APIGatewayProxyEventV2,\n\tcontext: Context,\n) => Promise<AmazonApiGatewayEndpointHandlerResponse>;\n\nexport type HandlerEvent<T extends Function> = T extends (\n\tevent: infer E,\n\tcontext: Context,\n) => any\n\t? E\n\t: never;\n","import qs from 'qs';\n\n/**\n * Parse query parameters from a flat object into a nested structure\n * Uses qs bracket notation for standard interoperability\n *\n * @example\n * parseQueryParams({ 'tags[]': ['a', 'b'], 'filter[name]': 'john' })\n * // Returns: { tags: ['a', 'b'], filter: { name: 'john' } }\n */\nexport function parseQueryParams(\n\tqueryParams: Record<string, string | string[] | undefined> | null,\n): Record<string, any> {\n\tif (!queryParams) {\n\t\treturn {};\n\t}\n\n\t// Reconstruct a query string from the flat object so qs can parse bracket notation\n\tconst parts: string[] = [];\n\tfor (const [key, value] of Object.entries(queryParams)) {\n\t\tif (value === undefined) continue;\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tparts.push(`${encodeURIComponent(key)}=${encodeURIComponent(v)}`);\n\t\t\t}\n\t\t} else {\n\t\t\tparts.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);\n\t\t}\n\t}\n\n\treturn qs.parse(parts.join('&')) as Record<string, any>;\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { APIGatewayProxyEvent, Context } from 'aws-lambda';\nimport type { HttpMethod } from '../types';\nimport {\n\tAmazonApiGatewayEndpoint,\n\ttype AmazonApiGatewayEndpointOptions,\n\ttype AmazonApiGatewayV1EndpointHandler,\n\ttype GetInputResponse,\n\ttype LoggerContext,\n} from './AmazonApiGatewayEndpointAdaptor';\nimport type { Endpoint, EndpointSchemas } from './Endpoint';\nimport { parseQueryParams } from './parseQueryParams';\n\nexport class AmazonApiGatewayV1Endpoint<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n> extends AmazonApiGatewayEndpoint<\n\tAmazonApiGatewayV1EndpointHandler,\n\tAPIGatewayProxyEvent,\n\tTRoute,\n\tTMethod,\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTSession,\n\tTEventPublisher\n> {\n\toverride getInput(e: APIGatewayProxyEvent): GetInputResponse {\n\t\t// For arrays, AWS API Gateway V1 provides multiValueQueryStringParameters\n\t\tconst multiValueParams = e.multiValueQueryStringParameters || {};\n\t\tconst singleValueParams = e.queryStringParameters || {};\n\n\t\t// Merge single and multi-value parameters\n\t\tconst mergedParams: Record<string, string | string[]> = {};\n\n\t\t// Add single value parameters\n\t\tfor (const [key, value] of Object.entries(singleValueParams)) {\n\t\t\tif (value !== undefined) {\n\t\t\t\tmergedParams[key] = value;\n\t\t\t}\n\t\t}\n\n\t\t// Override with multi-value parameters where applicable\n\t\tfor (const [key, values] of Object.entries(multiValueParams)) {\n\t\t\tif (values && values.length > 1) {\n\t\t\t\tmergedParams[key] = values;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tbody: AmazonApiGatewayEndpoint.decodeBody(\n\t\t\t\te.body,\n\t\t\t\te.isBase64Encoded,\n\t\t\t\te.headers?.['Content-Type'] ?? e.headers?.['content-type'],\n\t\t\t),\n\t\t\tquery: parseQueryParams(mergedParams),\n\t\t\tparams: e.pathParameters || {},\n\t\t};\n\t}\n\toverride getLoggerContext(\n\t\tdata: APIGatewayProxyEvent,\n\t\tcontext: Context,\n\t): LoggerContext {\n\t\treturn {\n\t\t\tfn: {\n\t\t\t\tname: context.functionName,\n\t\t\t\tversion: context.functionVersion,\n\t\t\t},\n\t\t\treq: {\n\t\t\t\tid: data.requestContext.requestId,\n\t\t\t\tawsRequestId: context.awsRequestId,\n\t\t\t\tip: data.requestContext.identity.sourceIp,\n\t\t\t\tuserAgent: data.requestContext.identity.userAgent || undefined,\n\t\t\t\tpath: data.requestContext.path,\n\t\t\t},\n\t\t};\n\t}\n\tconstructor(\n\t\tprotected override envParser: EnvironmentParser<{}>,\n\t\tprotected override readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>,\n\t\toptions: AmazonApiGatewayEndpointOptions = {},\n\t) {\n\t\tsuper(envParser, endpoint, options);\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { APIGatewayProxyEventV2, Context } from 'aws-lambda';\nimport qs from 'qs';\nimport type { HttpMethod } from '../types';\nimport {\n\tAmazonApiGatewayEndpoint,\n\ttype AmazonApiGatewayEndpointOptions,\n\ttype AmazonApiGatewayV2EndpointHandler,\n\ttype GetInputResponse,\n\ttype LoggerContext,\n} from './AmazonApiGatewayEndpointAdaptor';\nimport type { CookieFn, Endpoint, EndpointSchemas } from './Endpoint';\nimport { createApiGatewayCookies } from './lazyAccessors';\n\nexport class AmazonApiGatewayV2Endpoint<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n> extends AmazonApiGatewayEndpoint<\n\tAmazonApiGatewayV2EndpointHandler,\n\tAPIGatewayProxyEventV2,\n\tTRoute,\n\tTMethod,\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTSession,\n\tTEventPublisher\n> {\n\toverride getCookies(e: APIGatewayProxyEventV2): CookieFn {\n\t\treturn createApiGatewayCookies(\n\t\t\te.cookies,\n\t\t\t(e.headers as Record<string, string>)?.cookie,\n\t\t);\n\t}\n\n\toverride getInput(e: APIGatewayProxyEventV2): GetInputResponse {\n\t\tconst raw = AmazonApiGatewayEndpoint.decodeBody(\n\t\t\te.body,\n\t\t\te.isBase64Encoded,\n\t\t\te.headers?.['content-type'],\n\t\t);\n\n\t\treturn {\n\t\t\tbody: raw,\n\t\t\tquery: qs.parse(e.rawQueryString) as Record<string, any>,\n\t\t\tparams: e.pathParameters || {},\n\t\t};\n\t}\n\toverride getLoggerContext(\n\t\tevent: APIGatewayProxyEventV2,\n\t\tcontext: Context,\n\t): LoggerContext {\n\t\treturn {\n\t\t\tfn: {\n\t\t\t\tname: context.functionName,\n\t\t\t\tversion: context.functionVersion,\n\t\t\t},\n\t\t\treq: {\n\t\t\t\tid: event.requestContext.requestId,\n\t\t\t\tawsRequestId: context.awsRequestId,\n\t\t\t\tip: event.requestContext.http.sourceIp,\n\t\t\t\tuserAgent: event.requestContext.http.userAgent || undefined,\n\t\t\t\tpath: event.requestContext.http.path,\n\t\t\t},\n\t\t};\n\t}\n\tconstructor(\n\t\tprotected override envParser: EnvironmentParser<{}>,\n\t\tprotected override readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>,\n\t\toptions: AmazonApiGatewayEndpointOptions = {},\n\t) {\n\t\tsuper(envParser, endpoint, options);\n\t}\n}\n\n// Re-export options type for convenience\nexport type { AmazonApiGatewayEndpointOptions };\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type {\n\tContext,\n\tHandler,\n\tSQSBatchResponse,\n\tSQSEvent,\n\tSQSRecord,\n} from 'aws-lambda';\nimport { isQueueResult, type Queue, type QueueRecord } from './Queue';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\n/**\n * Runs a {@link Queue} worker as an AWS Lambda backed by an SQS event-source\n * mapping. Unlike a subscriber, a queue drains *every* record (no type filter):\n * each record body (`{ type, payload }`, as written by the SQS publisher) is\n * unwrapped to its `payload`, validated against the queue's `messageSchema`, and\n * the whole batch is handed to the handler as `messages`.\n *\n * Uses SQS partial-batch responses: a record that fails to parse or validate\n * is returned in `batchItemFailures`, so SQS retries only it. After that, the\n * handler decides: returning a {@link QueueResult} retries only the records it\n * names, and throwing retries every record in the batch.\n */\nexport class AWSLambdaQueue<\n\tTName extends string = string,\n\tTMessage extends StandardSchemaV1 = StandardSchemaV1,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> {\n\tprivate _services?: ServiceRecord<TServices>;\n\n\tconstructor(\n\t\tprivate readonly envParser: EnvironmentParser<{}>,\n\t\treadonly queue: Queue<TName, TMessage, TServices, TLogger>,\n\t) {}\n\n\tget logger(): TLogger {\n\t\treturn this.queue.logger;\n\t}\n\n\tprivate async getServices(): Promise<ServiceRecord<TServices>> {\n\t\tif (this._services) {\n\t\t\treturn this._services;\n\t\t}\n\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance(this.envParser);\n\n\t\tthis._services =\n\t\t\tthis.queue.services.length > 0\n\t\t\t\t? ((await serviceDiscovery.register(\n\t\t\t\t\t\tthis.queue.services,\n\t\t\t\t\t)) as ServiceRecord<TServices>)\n\t\t\t\t: ({} as ServiceRecord<TServices>);\n\n\t\treturn this._services;\n\t}\n\n\tprivate safeJsonParse(value: string): unknown {\n\t\ttry {\n\t\t\treturn JSON.parse(value);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Unwrap the queue payload from an SQS record. The SQS publisher writes\n\t * `{ type, payload }`; a payload-only body is also accepted as-is.\n\t */\n\tprivate extractPayload(record: SQSRecord): unknown {\n\t\tconst body = this.safeJsonParse(record.body);\n\t\tif (body && typeof body === 'object' && 'payload' in body) {\n\t\t\treturn (body as { payload: unknown }).payload;\n\t\t}\n\t\treturn body ?? record.body;\n\t}\n\n\tprivate async _handler(\n\t\tevent: SQSEvent,\n\t\tcontext: Context,\n\t): Promise<SQSBatchResponse> {\n\t\tconst logger = this.queue.logger.child({\n\t\t\tqueue: {\n\t\t\t\tname: this.queue.name,\n\t\t\t\tfn: context.functionName,\n\t\t\t},\n\t\t\treq: { id: context.awsRequestId },\n\t\t}) as TLogger;\n\n\t\tconst services = await this.getServices();\n\t\tconst schema = this.queue.messageSchema;\n\n\t\tconst batchItemFailures: { itemIdentifier: string }[] = [];\n\t\tconst records: QueueRecord<TMessage>[] = [];\n\n\t\tfor (const record of event.Records) {\n\t\t\ttry {\n\t\t\t\tconst payload = this.extractPayload(record);\n\t\t\t\tconst validation = await schema['~standard'].validate(payload);\n\t\t\t\tif (validation.issues) {\n\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t{ issues: validation.issues, messageId: record.messageId },\n\t\t\t\t\t\t'Queue message failed validation',\n\t\t\t\t\t);\n\t\t\t\t\tbatchItemFailures.push({ itemIdentifier: record.messageId });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\trecords.push({\n\t\t\t\t\tid: record.messageId,\n\t\t\t\t\tmessage: validation.value as InferStandardSchema<TMessage>,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\n\t\t\t\t\t{ error, messageId: record.messageId },\n\t\t\t\t\t'Failed to parse SQS record',\n\t\t\t\t);\n\t\t\t\tbatchItemFailures.push({ itemIdentifier: record.messageId });\n\t\t\t}\n\t\t}\n\n\t\tif (records.length === 0) {\n\t\t\treturn { batchItemFailures };\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await this.queue.handler({\n\t\t\t\tmessages: records.map((r) => r.message),\n\t\t\t\trecords,\n\t\t\t\tservices,\n\t\t\t\tlogger,\n\t\t\t});\n\n\t\t\tif (isQueueResult(result)) {\n\t\t\t\tconst handed = new Set(records.map((r) => r.id));\n\t\t\t\tconst unknown = result.failed.filter((id) => !handed.has(id));\n\t\t\t\tif (unknown.length > 0) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t{ unknown },\n\t\t\t\t\t\t'Queue handler reported records not in its batch',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tfor (const id of result.failed) {\n\t\t\t\t\tif (handed.has(id)) {\n\t\t\t\t\t\tbatchItemFailures.push({ itemIdentifier: id });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error(wrapError(error), 'Queue handler failed; retrying batch');\n\t\t\t// Handler processes the batch atomically — fail the whole batch so SQS\n\t\t\t// retries every (valid) record.\n\t\t\tfor (const record of event.Records) {\n\t\t\t\tif (\n\t\t\t\t\t!batchItemFailures.some((f) => f.itemIdentifier === record.messageId)\n\t\t\t\t) {\n\t\t\t\t\tbatchItemFailures.push({ itemIdentifier: record.messageId });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { batchItemFailures };\n\t}\n\n\tget handler(): AWSLambdaHandler<SQSEvent, SQSBatchResponse> {\n\t\tconst handler = this._handler.bind(this);\n\n\t\treturn (async (event: SQSEvent, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.queue.logger.child({ requestId }) as TLogger;\n\n\t\t\treturn runWithRequestContext({ logger, requestId, startTime }, () =>\n\t\t\t\thandler(event, context),\n\t\t\t);\n\t\t}) as unknown as AWSLambdaHandler<SQSEvent, SQSBatchResponse>;\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type {\n\tContext,\n\tHandler,\n\tSNSEvent,\n\tSNSEventRecord,\n\tSQSEvent,\n\tSQSRecord,\n} from 'aws-lambda';\nimport type { Subscriber } from './Subscriber';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\ntype SubscriberEvent<TServices extends Service[], TLogger extends Logger> = {\n\tevents: any[];\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n};\n\ntype Middleware<\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined,\n> = MiddlewareObj<\n\tSubscriberEvent<TServices, TLogger>,\n\tInferStandardSchema<TOutSchema>,\n\tError,\n\tContext\n>;\n\nexport class AWSLambdaSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTSubscribedEvents extends any[] = [],\n> {\n\tprivate _logger!: TLogger;\n\tprivate _services!: ServiceRecord<TServices>;\n\n\tconstructor(\n\t\tprivate envParser: EnvironmentParser<{}>,\n\t\treadonly subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>,\n\t) {\n\t\tthis._logger = subscriber.logger;\n\t}\n\n\tget logger(): TLogger {\n\t\treturn this._logger;\n\t}\n\n\tprivate async getServices(): Promise<ServiceRecord<TServices>> {\n\t\tif (this._services) {\n\t\t\treturn this._services;\n\t\t}\n\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance(this.envParser);\n\n\t\tif (this.subscriber.services.length > 0) {\n\t\t\tconst registered = await serviceDiscovery.register(\n\t\t\t\tthis.subscriber.services,\n\t\t\t);\n\t\t\tthis._services = registered as ServiceRecord<TServices>;\n\t\t} else {\n\t\t\tthis._services = {} as ServiceRecord<TServices>;\n\t\t}\n\n\t\treturn this._services;\n\t}\n\n\tprivate error(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\tconst logger = req.event?.logger || this.subscriber.logger;\n\t\t\t\tlogger.error(req.error || {}, 'Error processing subscriber');\n\n\t\t\t\t// Re-throw the wrapped error to let Lambda handle it\n\t\t\t\tthrow wrapError(req.error);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loggerMiddleware(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\tthis._logger = this.subscriber.logger.child({\n\t\t\t\t\tsubscriber: {\n\t\t\t\t\t\tname: req.context.functionName,\n\t\t\t\t\t\tversion: req.context.functionVersion,\n\t\t\t\t\t\tmemory: req.context.memoryLimitInMB,\n\t\t\t\t\t},\n\t\t\t\t\treq: {\n\t\t\t\t\t\tid: req.context.awsRequestId,\n\t\t\t\t\t},\n\t\t\t\t}) as TLogger;\n\n\t\t\t\treq.event.logger = this._logger;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate services(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.services = await this.getServices();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate parseEvents(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst { logger, ...e } = req.event;\n\t\t\t\tconst rawEvent = e as any as SQSEvent | SNSEvent;\n\n\t\t\t\tlogger.info({\n\t\t\t\t\trawEvent,\n\t\t\t\t});\n\n\t\t\t\t// Parse events based on the event type\n\t\t\t\tconst events: any[] = [];\n\n\t\t\t\tif ('Records' in rawEvent) {\n\t\t\t\t\tif (this.isSQSEvent(rawEvent)) {\n\t\t\t\t\t\t// SQS Event\n\t\t\t\t\t\tfor (const record of rawEvent.Records) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst event = this.parseSQSRecord(record);\n\t\t\t\t\t\t\t\tif (this.shouldIncludeEvent(event)) {\n\t\t\t\t\t\t\t\t\tevents.push(event);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t\t{ error, record },\n\t\t\t\t\t\t\t\t\t'Failed to parse SQS record',\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (this.isSNSEvent(rawEvent)) {\n\t\t\t\t\t\t// SNS Event\n\t\t\t\t\t\tfor (const record of rawEvent.Records) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst event = this.parseSNSRecord(record);\n\t\t\t\t\t\t\t\tif (this.shouldIncludeEvent(event)) {\n\t\t\t\t\t\t\t\t\tevents.push(event);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t\t{ error, record },\n\t\t\t\t\t\t\t\t\t'Failed to parse SNS record',\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t(req.event as any).events = events;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate isSQSEvent(event: SQSEvent | SNSEvent): event is SQSEvent {\n\t\tconst firstRecord = event.Records[0];\n\t\treturn (\n\t\t\t'Records' in event &&\n\t\t\tevent.Records.length > 0 &&\n\t\t\tfirstRecord !== undefined &&\n\t\t\t'eventSource' in firstRecord &&\n\t\t\tfirstRecord.eventSource === 'aws:sqs'\n\t\t);\n\t}\n\n\tprivate isSNSEvent(event: SQSEvent | SNSEvent): event is SNSEvent {\n\t\tconst firstRecord = event.Records[0];\n\t\treturn (\n\t\t\t'Records' in event &&\n\t\t\tevent.Records.length > 0 &&\n\t\t\tfirstRecord !== undefined &&\n\t\t\t'EventSource' in firstRecord &&\n\t\t\tfirstRecord.EventSource === 'aws:sns'\n\t\t);\n\t}\n\n\tprivate parseSNSRecord(record: SNSEventRecord): any {\n\t\tconst message = this.safeJsonParse(record.Sns.Message);\n\t\tconst messageType = record.Sns.MessageAttributes?.type?.Value;\n\n\t\t// Not JSON — wrap raw string with type from MessageAttributes if available\n\t\tif (message === null) {\n\t\t\treturn messageType\n\t\t\t\t? { type: messageType, payload: record.Sns.Message }\n\t\t\t\t: record.Sns.Message;\n\t\t}\n\n\t\t// Resolve type from MessageAttributes (preferred) or message body\n\t\tconst resolvedType = messageType ?? message.type;\n\n\t\tif (message.type) {\n\t\t\treturn message; // Full event format: { type, payload }\n\t\t}\n\n\t\t// Payload-only format: type is in MessageAttributes\n\t\treturn resolvedType ? { type: resolvedType, payload: message } : message;\n\t}\n\n\tprivate parseSQSRecord(record: SQSRecord): any {\n\t\tconst body = this.safeJsonParse(record.body);\n\n\t\t// Not JSON — return raw body as-is\n\t\tif (body === null) {\n\t\t\treturn record.body;\n\t\t}\n\n\t\t// Check if this is an SNS message wrapped in SQS\n\t\tif (body.Type === 'Notification' && body.Message) {\n\t\t\tconst snsMessage = this.safeJsonParse(body.Message);\n\t\t\tconst messageType = body.MessageAttributes?.type?.Value;\n\n\t\t\t// SNS Message not JSON — wrap with type from MessageAttributes if available\n\t\t\tif (snsMessage === null) {\n\t\t\t\treturn messageType\n\t\t\t\t\t? { type: messageType, payload: body.Message }\n\t\t\t\t\t: body.Message;\n\t\t\t}\n\n\t\t\tif (snsMessage.type) {\n\t\t\t\treturn snsMessage; // Full event format: { type, payload }\n\t\t\t}\n\n\t\t\t// Payload-only format: type is in MessageAttributes\n\t\t\tconst resolvedType = messageType ?? snsMessage.type;\n\t\t\treturn resolvedType\n\t\t\t\t? { type: resolvedType, payload: snsMessage }\n\t\t\t\t: snsMessage;\n\t\t}\n\n\t\t// Direct SQS message\n\t\treturn body;\n\t}\n\n\tprivate safeJsonParse(value: string): any | null {\n\t\ttry {\n\t\t\treturn JSON.parse(value);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate shouldIncludeEvent(event: any): boolean {\n\t\t// No event type (raw string/non-object) — always include\n\t\tif (typeof event !== 'object' || !event?.type) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// No filter configured — accept all\n\t\tif (!this.subscriber.subscribedEvents) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn this.subscriber.subscribedEvents.includes(event.type as any);\n\t}\n\n\tprivate async _handler(event: SubscriberEvent<TServices, TLogger>) {\n\t\t// If no events after filtering, return early\n\t\tif (event.events.length === 0) {\n\t\t\tthis.logger.info('No subscribed events to process');\n\t\t\treturn {\n\t\t\t\tbatchItemFailures: [],\n\t\t\t};\n\t\t}\n\n\t\t// Execute the subscriber with the parsed context\n\t\tconst result = await this.subscriber.handler({\n\t\t\tevents: event.events,\n\t\t\tservices: event.services,\n\t\t\tlogger: event.logger,\n\t\t});\n\n\t\t// Parse output if schema is provided\n\t\tif (this.subscriber.outputSchema && result) {\n\t\t\tconst validationResult =\n\t\t\t\tawait this.subscriber.outputSchema['~standard'].validate(result);\n\n\t\t\tif (validationResult.issues) {\n\t\t\t\tthis.logger.error(\n\t\t\t\t\t{ issues: validationResult.issues },\n\t\t\t\t\t'Subscriber output validation failed',\n\t\t\t\t);\n\t\t\t\tthrow new Error('Subscriber output validation failed');\n\t\t\t}\n\n\t\t\treturn validationResult.value;\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tget handler(): AWSLambdaHandler {\n\t\tconst handler = this._handler.bind(this);\n\n\t\t// Apply middleware in order\n\t\tconst chain = middy(handler)\n\t\t\t.use(this.loggerMiddleware())\n\t\t\t.use(this.parseEvents())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services());\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: unknown, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.subscriber.logger.child({\n\t\t\t\trequestId,\n\t\t\t}) as TLogger;\n\n\t\t\treturn runWithRequestContext({ logger, requestId, startTime }, () =>\n\t\t\t\tchain(event as Parameters<typeof chain>[0], context),\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as AWSLambdaHandler;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmFA,IAAsB,2BAAtB,MAoBE;CACD,AAAU;CAEV,YACWA,WACSC,UAcnBC,UAA2C,CAAE,GAC5C;EAhBS;EACS;AAgBnB,OAAK,UAAU;CACf;CAED,AAAQ,QAAwD;AAC/D,SAAO,EACN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,CAAE,EACrB;EACD;EAGD,MAAM,SAAS,MAAM,KAAK,WAAW,QAAQ;GAC5C,QAAQ,MAAM;GACd,UAAU,MAAM;GAChB,QAAQ,MAAM;EACd,EAAC;AAGF,MAAI,KAAK,WAAW,gBAAgB,QAAQ;GAC3C,MAAM,mBACL,MAAM,KAAK,WAAW,aAAa,aAAa,SAAS,OAAO;AAEjE,OAAI,iBAAiB,QAAQ;AAC5B,SAAK,OAAO,MACX,EAAE,QAAQ,iBAAiB,OAAQ,GACnC,sCACA;AACD,UAAM,IAAI,MAAM;GAChB;AAED,UAAO,iBAAiB;EACxB;AAED,SAAO;CACP;CAED,IAAI,UAA4B;EAC/B,MAAM,UAAU,KAAK,SAAS,KAAK,KAAK;EAGxC,MAAM,QAAQ,MAAM,QAAQ,CAC1B,IAAI,KAAK,kBAAkB,CAAC,CAC5B,IAAI,KAAK,aAAa,CAAC,CACvB,IAAI,KAAK,OAAO,CAAC,CACjB,IAAI,KAAK,UAAU,CAAC;EAGtB,MAAM,iBAAiB,OAAOC,OAAgBC,YAAqB;GAClE,MAAM,YAAY,KAAK,KAAK;GAC5B,MAAM,YAAY,QAAQ;GAC1B,MAAM,SAAS,KAAK,WAAW,OAAO,MAAM,EAC3C,UACA,EAAC;AAEF,UAAO,sBAAsB;IAAE;IAAQ;IAAW;GAAW,GAAE,MAC9D,MAAM,OAAsC,QAAQ,CACpD;EACD;AAED,SAAO;CACP;AACD"}
|
|
1
|
+
{"version":3,"file":"aws.mjs","names":["envParser: EnvironmentParser<{}>","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction\n\t\t>","options: AmazonApiGatewayEndpointOptions","body: string | undefined | null","isBase64Encoded: boolean | undefined","contentType: string | undefined","e: TEvent","event: Event<TEvent, TInput, TServices, TLogger, TSession>","db: any","metadata","output","trx: any","result","lambdaResponse: AmazonApiGatewayEndpointHandlerResponse","baseHeaders: Record<string, string> | undefined","setCookieHeaders: string[]","ctx: any","event: TEvent","context: Context","queryParams: Record<string, string | string[] | undefined> | null","parts: string[]","e: APIGatewayProxyEvent","mergedParams: Record<string, string | string[]>","data: APIGatewayProxyEvent","context: Context","envParser: EnvironmentParser<{}>","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>","options: AmazonApiGatewayEndpointOptions","e: APIGatewayProxyEventV2","event: APIGatewayProxyEventV2","context: Context","envParser: EnvironmentParser<{}>","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>","options: AmazonApiGatewayEndpointOptions","envParser: EnvironmentParser<{}>","queue: Queue<TName, TMessage, TServices, TLogger>","value: string","record: SQSRecord","event: SQSEvent","context: Context","batchItemFailures: { itemIdentifier: string }[]","records: QueueRecord<TMessage>[]","envParser: EnvironmentParser<{}>","subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>","events: any[]","event: SQSEvent | SNSEvent","record: SNSEventRecord","record: SQSRecord","value: string","event: any","event: SubscriberEvent<TServices, TLogger>","event: unknown","context: Context"],"sources":["../../src/endpoints/AmazonApiGatewayEndpointAdaptor.ts","../../src/endpoints/parseQueryParams.ts","../../src/endpoints/AmazonApiGatewayV1EndpointAdaptor.ts","../../src/endpoints/AmazonApiGatewayV2EndpointAdaptor.ts","../../src/queue/AWSLambdaQueueAdaptor.ts","../../src/subscribers/AWSLambdaSubscriberAdaptor.ts"],"sourcesContent":["import type { AuditableAction, AuditStorage } from '@geekmidas/audit';\nimport { withRlsContext } from '@geekmidas/db/rls';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type {\n\tAPIGatewayProxyEvent,\n\tAPIGatewayProxyEventV2,\n\tContext,\n} from 'aws-lambda';\nimport type { Telemetry } from '../telemetry';\nimport type { HttpMethod } from '../types';\nimport { Endpoint, type EndpointSchemas, ResponseBuilder } from './Endpoint';\n\n/**\n * Telescope integration for request recording.\n * Uses Middy middleware pattern for compatibility with existing telescope package.\n */\nexport interface TelescopeIntegration {\n\tmiddleware: MiddlewareObj<any, any, Error, Context>;\n}\n\nimport {\n\tForbiddenError,\n\tUnprocessableEntityError,\n\twrapError,\n} from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type {\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport { publishConstructEvents } from '../publisher';\nimport type { MappedAudit } from './audit';\nimport type { CookieFn, HeaderFn } from './Endpoint';\nimport {\n\tcreateAuditContext,\n\texecuteWithAuditTransaction,\n} from './processAudits';\n\n// Helper function to publish events\n\n/**\n * Options for Amazon API Gateway endpoint adaptors\n */\nexport interface AmazonApiGatewayEndpointOptions {\n\t/**\n\t * Telescope integration for request recording and monitoring.\n\t *\n\t * @example\n\t * ```typescript\n\t * import { telescopeMiddleware } from '@geekmidas/telescope/lambda';\n\t *\n\t * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n\t * telescope: { middleware: telescopeMiddleware(telescope) },\n\t * });\n\t * ```\n\t */\n\ttelescope?: TelescopeIntegration;\n\n\t/**\n\t * Telemetry integration for distributed tracing.\n\t * Works with any OpenTelemetry-compatible backend.\n\t *\n\t * @example\n\t * ```typescript\n\t * import { OTelTelemetry } from '@geekmidas/telescope/instrumentation';\n\t *\n\t * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n\t * telemetry: new OTelTelemetry(),\n\t * });\n\t * ```\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport abstract class AmazonApiGatewayEndpoint<\n\tTHandler extends\n\t\t| AmazonApiGatewayV1EndpointHandler\n\t\t| AmazonApiGatewayV2EndpointHandler,\n\tTEvent extends HandlerEvent<THandler>,\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tprotected options: AmazonApiGatewayEndpointOptions;\n\n\tconstructor(\n\t\tprotected envParser: EnvironmentParser<{}>,\n\t\tprotected readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction\n\t\t>,\n\t\toptions: AmazonApiGatewayEndpointOptions = {},\n\t) {\n\t\tthis.options = options;\n\t}\n\n\tprivate error(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\t(req.event.logger || this.endpoint.logger).error(\n\t\t\t\t\treq.error || {},\n\t\t\t\t\t'Error processing request',\n\t\t\t\t);\n\t\t\t\tconst wrappedError = wrapError(req.error);\n\n\t\t\t\t// Set the response with the proper status code from the HttpError\n\t\t\t\treq.response = {\n\t\t\t\t\tstatusCode: wrappedError.statusCode,\n\t\t\t\t\tbody: wrappedError.body,\n\t\t\t\t};\n\t\t\t},\n\t\t};\n\t}\n\tabstract getInput(e: TEvent): GetInputResponse;\n\n\t/**\n\t * Decodes the raw body from an API Gateway event.\n\t * Uses Content-Type to decide parsing strategy (like Express/Fastify/Hono):\n\t * - `application/json` (or missing) → JSON.parse the decoded string\n\t * - Anything else → return decoded string as-is, let the schema handle it\n\t *\n\t * Defaults to JSON when no Content-Type is provided for backwards compatibility.\n\t */\n\tstatic decodeBody(\n\t\tbody: string | undefined | null,\n\t\tisBase64Encoded: boolean | undefined,\n\t\tcontentType: string | undefined,\n\t): any {\n\t\tif (!body) return undefined;\n\n\t\tconst raw = isBase64Encoded\n\t\t\t? Buffer.from(body, 'base64').toString('utf-8')\n\t\t\t: body;\n\n\t\tconst isJson =\n\t\t\t!contentType || contentType.toLowerCase().includes('application/json');\n\t\tif (isJson) {\n\t\t\treturn JSON.parse(raw);\n\t\t}\n\n\t\treturn raw;\n\t}\n\n\tprotected getCookies(e: TEvent): CookieFn {\n\t\tconst headers = e.headers as Record<string, string>;\n\t\treturn Endpoint.createCookies(headers?.cookie);\n\t}\n\n\tprivate input(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst { body, query, params } = this.getInput(req.event);\n\t\t\t\t\tconst headers = req.event.headers as Record<string, string>;\n\t\t\t\t\tconst header = Endpoint.createHeaders(headers);\n\t\t\t\t\tconst cookie = this.getCookies(req.event);\n\n\t\t\t\t\tObject.assign(req.event, {\n\t\t\t\t\t\tbody: await this.endpoint.parseInput(body, 'body'),\n\t\t\t\t\t\tquery: await this.endpoint.parseInput(query, 'query'),\n\t\t\t\t\t\tparams: await this.endpoint.parseInput(params, 'params'),\n\t\t\t\t\t\theader,\n\t\t\t\t\t\tcookie,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Convert validation errors to 422 Unprocessable Entity\n\t\t\t\t\tif (error && typeof error === 'object' && Array.isArray(error)) {\n\t\t\t\t\t\tthrow new UnprocessableEntityError('Validation failed', error);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tabstract getLoggerContext(data: TEvent, context: Context): LoggerContext;\n\n\tprivate logger(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\treq.event.logger = this.endpoint.logger.child({\n\t\t\t\t\troute: this.endpoint.route,\n\t\t\t\t\thost: req.event.headers?.host,\n\t\t\t\t\tmethod: this.endpoint.method,\n\t\t\t\t\t...this.getLoggerContext(req.event, req.context),\n\t\t\t\t}) as TLogger;\n\t\t\t},\n\t\t};\n\t}\n\tprivate services(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst _logger = req.event.logger as TLogger;\n\t\t\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\t\t\tServiceRecord<TServices>\n\t\t\t\t>(this.envParser);\n\n\t\t\t\tconst services = await serviceDiscovery.register(\n\t\t\t\t\tthis.endpoint.services,\n\t\t\t\t);\n\n\t\t\t\treq.event.services = services;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate authorize(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst logger = req.event.logger as TLogger;\n\t\t\t\tconst services = req.event.services;\n\t\t\t\tconst header = req.event.header;\n\t\t\t\tconst cookie = req.event.cookie;\n\t\t\t\tconst session = req.event.session as TSession;\n\n\t\t\t\tconst isAuthorized = await this.endpoint.authorize({\n\t\t\t\t\theader,\n\t\t\t\t\tcookie,\n\t\t\t\t\tservices,\n\t\t\t\t\tlogger,\n\t\t\t\t\tsession,\n\t\t\t\t\t...((req.event as any).db !== undefined && {\n\t\t\t\t\t\tdb: (req.event as any).db,\n\t\t\t\t\t}),\n\t\t\t\t\tbody: (req.event as any).body,\n\t\t\t\t\tquery: (req.event as any).query,\n\t\t\t\t\tparams: (req.event as any).params,\n\t\t\t\t} as any);\n\n\t\t\t\tif (!isAuthorized) {\n\t\t\t\t\tlogger.warn('Forbidden access attempt');\n\t\t\t\t\tthrow new ForbiddenError(\n\t\t\t\t\t\t'Forbidden access to the endpoint',\n\t\t\t\t\t\t'You do not have permission to access this resource.',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate database(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tif (!this.endpoint.databaseService) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst _logger = req.event.logger as TLogger;\n\t\t\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\t\t\tServiceRecord<TServices>\n\t\t\t\t>(this.envParser);\n\n\t\t\t\tconst db = await serviceDiscovery\n\t\t\t\t\t.register([this.endpoint.databaseService])\n\t\t\t\t\t.then(\n\t\t\t\t\t\t(s) =>\n\t\t\t\t\t\t\ts[this.endpoint.databaseService?.serviceName as keyof typeof s],\n\t\t\t\t\t);\n\n\t\t\t\t(req.event as any).db = db;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate session(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst logger = req.event.logger as TLogger;\n\t\t\t\tconst services = req.event.services;\n\t\t\t\tconst db = (req.event as any).db;\n\t\t\t\treq.event.session = (await this.endpoint.getSession({\n\t\t\t\t\tlogger,\n\t\t\t\t\tservices,\n\t\t\t\t\theader: req.event.header,\n\t\t\t\t\tcookie: req.event.cookie,\n\t\t\t\t\t...(db !== undefined && { db }),\n\t\t\t\t} as any)) as TSession;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate events(): Middleware<TEvent, TInput, TServices, TLogger> {\n\t\treturn {\n\t\t\tafter: async (req) => {\n\t\t\t\tconst event = req.event;\n\t\t\t\tconst response = (event as any)\n\t\t\t\t\t.__response as InferStandardSchema<TOutSchema>;\n\t\t\t\tconst statusCode = req.response?.statusCode ?? this.endpoint.status;\n\n\t\t\t\t// Only publish events on successful responses (2xx status codes)\n\t\t\t\t// Note: Audits are processed inside the handler's transaction\n\t\t\t\tif (Endpoint.isSuccessStatus(statusCode)) {\n\t\t\t\t\tconst logger = event.logger as TLogger;\n\t\t\t\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\t\t\t\tServiceRecord<TServices>\n\t\t\t\t\t>(this.envParser);\n\n\t\t\t\t\t// Publish events\n\t\t\t\t\tawait publishConstructEvents(\n\t\t\t\t\t\tthis.endpoint,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t\tserviceDiscovery,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async _handler(\n\t\tevent: Event<TEvent, TInput, TServices, TLogger, TSession>,\n\t) {\n\t\tconst input = this.endpoint.refineInput(event);\n\t\tconst logger = event.logger as TLogger;\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance<\n\t\t\tServiceRecord<TServices>\n\t\t>(this.envParser);\n\n\t\t// Create audit context if audit storage is configured\n\t\tconst auditContext = await createAuditContext(\n\t\t\tthis.endpoint,\n\t\t\tserviceDiscovery,\n\t\t\tlogger,\n\t\t\t{\n\t\t\t\tsession: event.session,\n\t\t\t\theader: event.header,\n\t\t\t\tcookie: event.cookie,\n\t\t\t\tservices: event.services as Record<string, unknown>,\n\t\t\t},\n\t\t);\n\n\t\t// Warn if declarative audits are configured but no audit storage\n\t\tconst audits = this.endpoint.audits as MappedAudit<\n\t\t\tTAuditAction,\n\t\t\tTOutSchema\n\t\t>[];\n\t\tif (!auditContext && audits?.length) {\n\t\t\tlogger.warn('No auditor storage service available');\n\t\t}\n\n\t\t// Get pre-resolved database from middleware\n\t\tconst rawDb = (event as any).db;\n\n\t\t// Extract RLS context if configured and not bypassed\n\t\tconst rlsActive =\n\t\t\tthis.endpoint.rlsConfig &&\n\t\t\t!this.endpoint.rlsBypass &&\n\t\t\trawDb !== undefined;\n\t\tconst rlsContext = rlsActive\n\t\t\t? await this.endpoint.rlsConfig?.extractor({\n\t\t\t\t\tservices: event.services as ServiceRecord<TServices>,\n\t\t\t\t\tsession: event.session,\n\t\t\t\t\theader: event.header,\n\t\t\t\t\tcookie: event.cookie,\n\t\t\t\t\tlogger,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\t// Execute handler with automatic audit transaction support\n\t\tconst result = await executeWithAuditTransaction(\n\t\t\tauditContext,\n\t\t\tasync (auditor) => {\n\t\t\t\t// Use audit transaction as db only if the storage uses the same database service\n\t\t\t\tconst sameDatabase =\n\t\t\t\t\tauditContext?.storage?.databaseServiceName &&\n\t\t\t\t\tauditContext.storage.databaseServiceName ===\n\t\t\t\t\t\tthis.endpoint.databaseService?.serviceName;\n\t\t\t\tconst baseDb = sameDatabase\n\t\t\t\t\t? (auditor?.getTransaction?.() ?? rawDb)\n\t\t\t\t\t: rawDb;\n\n\t\t\t\t// Helper to execute handler with given db\n\t\t\t\tconst executeHandler = async (db: any) => {\n\t\t\t\t\tconst responseBuilder = new ResponseBuilder();\n\t\t\t\t\tconst response = await this.endpoint.handler(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\theader: event.header,\n\t\t\t\t\t\t\tcookie: event.cookie,\n\t\t\t\t\t\t\tlogger: event.logger,\n\t\t\t\t\t\t\tservices: event.services,\n\t\t\t\t\t\t\tsession: event.session,\n\t\t\t\t\t\t\tauditor,\n\t\t\t\t\t\t\tdb,\n\t\t\t\t\t\t\t...input,\n\t\t\t\t\t\t} as any,\n\t\t\t\t\t\tresponseBuilder,\n\t\t\t\t\t);\n\n\t\t\t\t\t// Check if response has metadata\n\t\t\t\t\tlet data = response;\n\t\t\t\t\tlet metadata = responseBuilder.getMetadata();\n\n\t\t\t\t\tif (Endpoint.hasMetadata(response)) {\n\t\t\t\t\t\tdata = response.data;\n\t\t\t\t\t\tmetadata = response.metadata;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst output = this.endpoint.outputSchema\n\t\t\t\t\t\t? await this.endpoint.parseOutput(data)\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\treturn { output, metadata, responseBuilder };\n\t\t\t\t};\n\n\t\t\t\t// If RLS is active, wrap handler with RLS context\n\t\t\t\tif (rlsActive && rlsContext && baseDb) {\n\t\t\t\t\treturn withRlsContext(\n\t\t\t\t\t\tbaseDb,\n\t\t\t\t\t\trlsContext,\n\t\t\t\t\t\tasync (trx: any) => executeHandler(trx),\n\t\t\t\t\t\t{ prefix: this.endpoint.rlsConfig?.prefix },\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn executeHandler(baseDb);\n\t\t\t},\n\t\t\t// Process declarative audits after handler (inside transaction)\n\t\t\tasync (result, auditor) => {\n\t\t\t\tif (!audits?.length) return;\n\n\t\t\t\tfor (const audit of audits) {\n\t\t\t\t\tif (audit.when && !audit.when(result.output as any)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst payload = audit.payload(result.output as any);\n\t\t\t\t\tconst entityId = audit.entityId?.(result.output as any);\n\t\t\t\t\tauditor.audit(audit.type as any, payload as any, {\n\t\t\t\t\t\ttable: audit.table,\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\t// Pass rawDb so storage can reuse existing transactions\n\t\t\t{ db: rawDb },\n\t\t);\n\n\t\tconst { output, metadata } = result;\n\t\tconst isJsonResponse = this.endpoint.responseType === 'application/json';\n\t\tconst body =\n\t\t\toutput === undefined\n\t\t\t\t? undefined\n\t\t\t\t: isJsonResponse\n\t\t\t\t\t? JSON.stringify(output)\n\t\t\t\t\t: typeof output === 'string'\n\t\t\t\t\t\t? output\n\t\t\t\t\t\t: String(output);\n\n\t\t// Store response for middleware access\n\t\t(event as any).__response = output;\n\n\t\t// Build response with metadata\n\t\tconst lambdaResponse: AmazonApiGatewayEndpointHandlerResponse = {\n\t\t\tstatusCode: metadata.status ?? this.endpoint.status,\n\t\t\tbody,\n\t\t};\n\n\t\t// Compose headers. For non-JSON responseType, emit a default\n\t\t// Content-Type header which metadata.headers (r.header()) can override.\n\t\tconst baseHeaders: Record<string, string> | undefined = isJsonResponse\n\t\t\t? undefined\n\t\t\t: { 'content-type': this.endpoint.responseType };\n\n\t\tif (\n\t\t\tbaseHeaders ||\n\t\t\t(metadata.headers && Object.keys(metadata.headers).length > 0)\n\t\t) {\n\t\t\tlambdaResponse.headers = {\n\t\t\t\t...(baseHeaders ?? {}),\n\t\t\t\t...(metadata.headers ?? {}),\n\t\t\t};\n\t\t}\n\n\t\t// Format cookies as Set-Cookie headers\n\t\tif (metadata.cookies && metadata.cookies.size > 0) {\n\t\t\tconst setCookieHeaders: string[] = [];\n\t\t\tfor (const [name, { value, options }] of metadata.cookies) {\n\t\t\t\tsetCookieHeaders.push(\n\t\t\t\t\tEndpoint.formatCookieHeader(name, value, options),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (setCookieHeaders.length > 0) {\n\t\t\t\tlambdaResponse.multiValueHeaders = {\n\t\t\t\t\t...lambdaResponse.multiValueHeaders,\n\t\t\t\t\t'Set-Cookie': setCookieHeaders,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn lambdaResponse;\n\t}\n\n\t/**\n\t * Convert Telemetry interface to Middy middleware\n\t */\n\tprivate telemetry(): Middleware<TEvent, TInput, TServices, TLogger> | null {\n\t\tif (!this.options.telemetry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst telemetry = this.options.telemetry;\n\t\tlet ctx: any;\n\n\t\treturn {\n\t\t\tbefore: (request) => {\n\t\t\t\tctx = telemetry.onRequestStart({\n\t\t\t\t\tevent: request.event,\n\t\t\t\t\tcontext: request.context,\n\t\t\t\t});\n\t\t\t},\n\t\t\tafter: (request) => {\n\t\t\t\tif (ctx) {\n\t\t\t\t\ttelemetry.onRequestEnd(ctx, {\n\t\t\t\t\t\tstatusCode: request.response?.statusCode ?? 200,\n\t\t\t\t\t\tbody: request.response?.body,\n\t\t\t\t\t\theaders: request.response?.headers,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\tonError: (request) => {\n\t\t\t\tif (ctx && request.error) {\n\t\t\t\t\ttelemetry.onRequestError(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\trequest.error instanceof Error\n\t\t\t\t\t\t\t? request.error\n\t\t\t\t\t\t\t: new Error(String(request.error)),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tget handler() {\n\t\tconst handler = this._handler.bind(this);\n\t\tlet chain = middy(handler)\n\t\t\t.use(this.logger())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services())\n\t\t\t.use(this.input())\n\t\t\t.use(this.database())\n\t\t\t.use(this.session())\n\t\t\t.use(this.authorize())\n\t\t\t.use(this.events());\n\n\t\t// Add telemetry middleware if configured (runs early for span creation)\n\t\tconst telemetryMiddleware = this.telemetry();\n\t\tif (telemetryMiddleware) {\n\t\t\tchain = chain.use(telemetryMiddleware);\n\t\t}\n\n\t\t// Add Telescope middleware if configured (runs first/last in chain)\n\t\tif (this.options.telescope?.middleware) {\n\t\t\tchain = chain.use(this.options.telescope.middleware);\n\t\t}\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: TEvent, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.endpoint.logger.child({ requestId }) as TLogger;\n\n\t\t\t// Cast event to any since Middy middlewares enrich the event with\n\t\t\t// services, logger, session, etc. during the middleware chain execution\n\t\t\treturn runWithRequestContext({ logger, requestId, startTime }, () =>\n\t\t\t\tchain(event as unknown as Parameters<typeof chain>[0], context),\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as THandler;\n\t}\n}\n\nexport type Event<\n\tTEvent extends APIGatewayProxyEvent | APIGatewayProxyEventV2,\n\tTInput extends EndpointSchemas = {},\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n> = {\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n\theader: HeaderFn;\n\tcookie: CookieFn;\n\tsession: TSession;\n} & TEvent &\n\tInferComposableStandardSchema<TInput>;\n\ntype Middleware<\n\tTEvent extends APIGatewayProxyEvent | APIGatewayProxyEventV2,\n\tTInput extends EndpointSchemas = {},\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n> = MiddlewareObj<Event<TEvent, TInput, TServices, TLogger, TSession>>;\n\nexport type AmazonApiGatewayEndpointHandlerResponse = {\n\tstatusCode: number;\n\tbody: string | undefined;\n\theaders?: Record<string, string>;\n\tmultiValueHeaders?: Record<string, string[]>;\n};\n\nexport type LoggerContext = {\n\tfn: {\n\t\tname: string;\n\t\tversion: string;\n\t};\n\treq: {\n\t\tid: string | undefined;\n\t\tawsRequestId: string;\n\t\tpath: string;\n\t\tip: string | undefined;\n\t\tuserAgent: string | undefined;\n\t};\n};\n\nexport type GetInputResponse = {\n\tbody: any;\n\tquery: any;\n\tparams: any;\n};\n\nexport type AmazonApiGatewayV1EndpointHandler = (\n\tevent: APIGatewayProxyEvent,\n\tcontext: Context,\n) => Promise<AmazonApiGatewayEndpointHandlerResponse>;\n\nexport type AmazonApiGatewayV2EndpointHandler = (\n\tevent: APIGatewayProxyEventV2,\n\tcontext: Context,\n) => Promise<AmazonApiGatewayEndpointHandlerResponse>;\n\nexport type HandlerEvent<T extends Function> = T extends (\n\tevent: infer E,\n\tcontext: Context,\n) => any\n\t? E\n\t: never;\n","import qs from 'qs';\n\n/**\n * Parse query parameters from a flat object into a nested structure\n * Uses qs bracket notation for standard interoperability\n *\n * @example\n * parseQueryParams({ 'tags[]': ['a', 'b'], 'filter[name]': 'john' })\n * // Returns: { tags: ['a', 'b'], filter: { name: 'john' } }\n */\nexport function parseQueryParams(\n\tqueryParams: Record<string, string | string[] | undefined> | null,\n): Record<string, any> {\n\tif (!queryParams) {\n\t\treturn {};\n\t}\n\n\t// Reconstruct a query string from the flat object so qs can parse bracket notation\n\tconst parts: string[] = [];\n\tfor (const [key, value] of Object.entries(queryParams)) {\n\t\tif (value === undefined) continue;\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tparts.push(`${encodeURIComponent(key)}=${encodeURIComponent(v)}`);\n\t\t\t}\n\t\t} else {\n\t\t\tparts.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);\n\t\t}\n\t}\n\n\treturn qs.parse(parts.join('&')) as Record<string, any>;\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { APIGatewayProxyEvent, Context } from 'aws-lambda';\nimport type { HttpMethod } from '../types';\nimport {\n\tAmazonApiGatewayEndpoint,\n\ttype AmazonApiGatewayEndpointOptions,\n\ttype AmazonApiGatewayV1EndpointHandler,\n\ttype GetInputResponse,\n\ttype LoggerContext,\n} from './AmazonApiGatewayEndpointAdaptor';\nimport type { Endpoint, EndpointSchemas } from './Endpoint';\nimport { parseQueryParams } from './parseQueryParams';\n\nexport class AmazonApiGatewayV1Endpoint<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n> extends AmazonApiGatewayEndpoint<\n\tAmazonApiGatewayV1EndpointHandler,\n\tAPIGatewayProxyEvent,\n\tTRoute,\n\tTMethod,\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTSession,\n\tTEventPublisher\n> {\n\toverride getInput(e: APIGatewayProxyEvent): GetInputResponse {\n\t\t// For arrays, AWS API Gateway V1 provides multiValueQueryStringParameters\n\t\tconst multiValueParams = e.multiValueQueryStringParameters || {};\n\t\tconst singleValueParams = e.queryStringParameters || {};\n\n\t\t// Merge single and multi-value parameters\n\t\tconst mergedParams: Record<string, string | string[]> = {};\n\n\t\t// Add single value parameters\n\t\tfor (const [key, value] of Object.entries(singleValueParams)) {\n\t\t\tif (value !== undefined) {\n\t\t\t\tmergedParams[key] = value;\n\t\t\t}\n\t\t}\n\n\t\t// Override with multi-value parameters where applicable\n\t\tfor (const [key, values] of Object.entries(multiValueParams)) {\n\t\t\tif (values && values.length > 1) {\n\t\t\t\tmergedParams[key] = values;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tbody: AmazonApiGatewayEndpoint.decodeBody(\n\t\t\t\te.body,\n\t\t\t\te.isBase64Encoded,\n\t\t\t\te.headers?.['Content-Type'] ?? e.headers?.['content-type'],\n\t\t\t),\n\t\t\tquery: parseQueryParams(mergedParams),\n\t\t\tparams: e.pathParameters || {},\n\t\t};\n\t}\n\toverride getLoggerContext(\n\t\tdata: APIGatewayProxyEvent,\n\t\tcontext: Context,\n\t): LoggerContext {\n\t\treturn {\n\t\t\tfn: {\n\t\t\t\tname: context.functionName,\n\t\t\t\tversion: context.functionVersion,\n\t\t\t},\n\t\t\treq: {\n\t\t\t\tid: data.requestContext.requestId,\n\t\t\t\tawsRequestId: context.awsRequestId,\n\t\t\t\tip: data.requestContext.identity.sourceIp,\n\t\t\t\tuserAgent: data.requestContext.identity.userAgent || undefined,\n\t\t\t\tpath: data.requestContext.path,\n\t\t\t},\n\t\t};\n\t}\n\tconstructor(\n\t\tprotected override envParser: EnvironmentParser<{}>,\n\t\tprotected override readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>,\n\t\toptions: AmazonApiGatewayEndpointOptions = {},\n\t) {\n\t\tsuper(envParser, endpoint, options);\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { APIGatewayProxyEventV2, Context } from 'aws-lambda';\nimport qs from 'qs';\nimport type { HttpMethod } from '../types';\nimport {\n\tAmazonApiGatewayEndpoint,\n\ttype AmazonApiGatewayEndpointOptions,\n\ttype AmazonApiGatewayV2EndpointHandler,\n\ttype GetInputResponse,\n\ttype LoggerContext,\n} from './AmazonApiGatewayEndpointAdaptor';\nimport type { CookieFn, Endpoint, EndpointSchemas } from './Endpoint';\nimport { createApiGatewayCookies } from './lazyAccessors';\n\nexport class AmazonApiGatewayV2Endpoint<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n> extends AmazonApiGatewayEndpoint<\n\tAmazonApiGatewayV2EndpointHandler,\n\tAPIGatewayProxyEventV2,\n\tTRoute,\n\tTMethod,\n\tTInput,\n\tTOutSchema,\n\tTServices,\n\tTLogger,\n\tTSession,\n\tTEventPublisher\n> {\n\toverride getCookies(e: APIGatewayProxyEventV2): CookieFn {\n\t\treturn createApiGatewayCookies(\n\t\t\te.cookies,\n\t\t\t(e.headers as Record<string, string>)?.cookie,\n\t\t);\n\t}\n\n\toverride getInput(e: APIGatewayProxyEventV2): GetInputResponse {\n\t\tconst raw = AmazonApiGatewayEndpoint.decodeBody(\n\t\t\te.body,\n\t\t\te.isBase64Encoded,\n\t\t\te.headers?.['content-type'],\n\t\t);\n\n\t\treturn {\n\t\t\tbody: raw,\n\t\t\tquery: qs.parse(e.rawQueryString) as Record<string, any>,\n\t\t\tparams: e.pathParameters || {},\n\t\t};\n\t}\n\toverride getLoggerContext(\n\t\tevent: APIGatewayProxyEventV2,\n\t\tcontext: Context,\n\t): LoggerContext {\n\t\treturn {\n\t\t\tfn: {\n\t\t\t\tname: context.functionName,\n\t\t\t\tversion: context.functionVersion,\n\t\t\t},\n\t\t\treq: {\n\t\t\t\tid: event.requestContext.requestId,\n\t\t\t\tawsRequestId: context.awsRequestId,\n\t\t\t\tip: event.requestContext.http.sourceIp,\n\t\t\t\tuserAgent: event.requestContext.http.userAgent || undefined,\n\t\t\t\tpath: event.requestContext.http.path,\n\t\t\t},\n\t\t};\n\t}\n\tconstructor(\n\t\tprotected override envParser: EnvironmentParser<{}>,\n\t\tprotected override readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher\n\t\t>,\n\t\toptions: AmazonApiGatewayEndpointOptions = {},\n\t) {\n\t\tsuper(envParser, endpoint, options);\n\t}\n}\n\n// Re-export options type for convenience\nexport type { AmazonApiGatewayEndpointOptions };\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type {\n\tContext,\n\tHandler,\n\tSQSBatchResponse,\n\tSQSEvent,\n\tSQSRecord,\n} from 'aws-lambda';\nimport { isQueueResult, type Queue, type QueueRecord } from './Queue';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\n/**\n * Runs a {@link Queue} worker as an AWS Lambda backed by an SQS event-source\n * mapping. Unlike a subscriber, a queue drains *every* record (no type filter):\n * each record body (`{ type, payload }`, as written by the SQS publisher) is\n * unwrapped to its `payload`, validated against the queue's `messageSchema`, and\n * the whole batch is handed to the handler as `messages`.\n *\n * Uses SQS partial-batch responses: a record that fails to parse or validate\n * is returned in `batchItemFailures`, so SQS retries only it. After that, the\n * handler decides: returning a {@link QueueResult} retries only the records it\n * names, and throwing retries every record in the batch.\n */\nexport class AWSLambdaQueue<\n\tTName extends string = string,\n\tTMessage extends StandardSchemaV1 = StandardSchemaV1,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> {\n\tprivate _services?: ServiceRecord<TServices>;\n\n\tconstructor(\n\t\tprivate readonly envParser: EnvironmentParser<{}>,\n\t\treadonly queue: Queue<TName, TMessage, TServices, TLogger>,\n\t) {}\n\n\tget logger(): TLogger {\n\t\treturn this.queue.logger;\n\t}\n\n\tprivate async getServices(): Promise<ServiceRecord<TServices>> {\n\t\tif (this._services) {\n\t\t\treturn this._services;\n\t\t}\n\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance(this.envParser);\n\n\t\tthis._services =\n\t\t\tthis.queue.services.length > 0\n\t\t\t\t? ((await serviceDiscovery.register(\n\t\t\t\t\t\tthis.queue.services,\n\t\t\t\t\t)) as ServiceRecord<TServices>)\n\t\t\t\t: ({} as ServiceRecord<TServices>);\n\n\t\treturn this._services;\n\t}\n\n\tprivate safeJsonParse(value: string): unknown {\n\t\ttry {\n\t\t\treturn JSON.parse(value);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Unwrap the queue payload from an SQS record. The SQS publisher writes\n\t * `{ type, payload }`; a payload-only body is also accepted as-is. A queue\n\t * built with `.envelope(false)` is never unwrapped: its body is the message.\n\t */\n\tprivate extractPayload(record: SQSRecord): unknown {\n\t\tconst body = this.safeJsonParse(record.body);\n\t\tif (!this.queue.envelope) {\n\t\t\treturn body ?? record.body;\n\t\t}\n\t\tif (body && typeof body === 'object' && 'payload' in body) {\n\t\t\treturn (body as { payload: unknown }).payload;\n\t\t}\n\t\treturn body ?? record.body;\n\t}\n\n\tprivate async _handler(\n\t\tevent: SQSEvent,\n\t\tcontext: Context,\n\t): Promise<SQSBatchResponse> {\n\t\tconst logger = this.queue.logger.child({\n\t\t\tqueue: {\n\t\t\t\tname: this.queue.name,\n\t\t\t\tfn: context.functionName,\n\t\t\t},\n\t\t\treq: { id: context.awsRequestId },\n\t\t}) as TLogger;\n\n\t\tconst services = await this.getServices();\n\t\tconst schema = this.queue.messageSchema;\n\n\t\tconst batchItemFailures: { itemIdentifier: string }[] = [];\n\t\tconst records: QueueRecord<TMessage>[] = [];\n\n\t\tfor (const record of event.Records) {\n\t\t\ttry {\n\t\t\t\tconst payload = this.extractPayload(record);\n\t\t\t\tconst validation = await schema['~standard'].validate(payload);\n\t\t\t\tif (validation.issues) {\n\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t{ issues: validation.issues, messageId: record.messageId },\n\t\t\t\t\t\t'Queue message failed validation',\n\t\t\t\t\t);\n\t\t\t\t\tbatchItemFailures.push({ itemIdentifier: record.messageId });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\trecords.push({\n\t\t\t\t\tid: record.messageId,\n\t\t\t\t\tmessage: validation.value as InferStandardSchema<TMessage>,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\n\t\t\t\t\t{ error, messageId: record.messageId },\n\t\t\t\t\t'Failed to parse SQS record',\n\t\t\t\t);\n\t\t\t\tbatchItemFailures.push({ itemIdentifier: record.messageId });\n\t\t\t}\n\t\t}\n\n\t\tif (records.length === 0) {\n\t\t\treturn { batchItemFailures };\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await this.queue.handler({\n\t\t\t\tmessages: records.map((r) => r.message),\n\t\t\t\trecords,\n\t\t\t\tservices,\n\t\t\t\tlogger,\n\t\t\t});\n\n\t\t\tif (isQueueResult(result)) {\n\t\t\t\tconst handed = new Set(records.map((r) => r.id));\n\t\t\t\tconst unknown = result.failed.filter((id) => !handed.has(id));\n\t\t\t\tif (unknown.length > 0) {\n\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t{ unknown },\n\t\t\t\t\t\t'Queue handler reported records not in its batch',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tfor (const id of result.failed) {\n\t\t\t\t\tif (handed.has(id)) {\n\t\t\t\t\t\tbatchItemFailures.push({ itemIdentifier: id });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error(wrapError(error), 'Queue handler failed; retrying batch');\n\t\t\t// Handler processes the batch atomically — fail the whole batch so SQS\n\t\t\t// retries every (valid) record.\n\t\t\tfor (const record of event.Records) {\n\t\t\t\tif (\n\t\t\t\t\t!batchItemFailures.some((f) => f.itemIdentifier === record.messageId)\n\t\t\t\t) {\n\t\t\t\t\tbatchItemFailures.push({ itemIdentifier: record.messageId });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { batchItemFailures };\n\t}\n\n\tget handler(): AWSLambdaHandler<SQSEvent, SQSBatchResponse> {\n\t\tconst handler = this._handler.bind(this);\n\n\t\treturn (async (event: SQSEvent, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.queue.logger.child({ requestId }) as TLogger;\n\n\t\t\treturn runWithRequestContext({ logger, requestId, startTime }, () =>\n\t\t\t\thandler(event, context),\n\t\t\t);\n\t\t}) as unknown as AWSLambdaHandler<SQSEvent, SQSBatchResponse>;\n\t}\n}\n","import type { EnvironmentParser } from '@geekmidas/envkit';\nimport { wrapError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';\nimport middy, { type MiddlewareObj } from '@middy/core';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type {\n\tContext,\n\tHandler,\n\tSNSEvent,\n\tSNSEventRecord,\n\tSQSEvent,\n\tSQSRecord,\n} from 'aws-lambda';\nimport type { Subscriber } from './Subscriber';\n\nexport type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<\n\tTEvent,\n\tTResult\n>;\n\ntype SubscriberEvent<TServices extends Service[], TLogger extends Logger> = {\n\tevents: any[];\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n};\n\ntype Middleware<\n\tTServices extends Service[],\n\tTLogger extends Logger,\n\tTOutSchema extends StandardSchemaV1 | undefined,\n> = MiddlewareObj<\n\tSubscriberEvent<TServices, TLogger>,\n\tInferStandardSchema<TOutSchema>,\n\tError,\n\tContext\n>;\n\nexport class AWSLambdaSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTSubscribedEvents extends any[] = [],\n> {\n\tprivate _logger!: TLogger;\n\tprivate _services!: ServiceRecord<TServices>;\n\n\tconstructor(\n\t\tprivate envParser: EnvironmentParser<{}>,\n\t\treadonly subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>,\n\t) {\n\t\tthis._logger = subscriber.logger;\n\t}\n\n\tget logger(): TLogger {\n\t\treturn this._logger;\n\t}\n\n\tprivate async getServices(): Promise<ServiceRecord<TServices>> {\n\t\tif (this._services) {\n\t\t\treturn this._services;\n\t\t}\n\n\t\tconst serviceDiscovery = ServiceDiscovery.getInstance(this.envParser);\n\n\t\tif (this.subscriber.services.length > 0) {\n\t\t\tconst registered = await serviceDiscovery.register(\n\t\t\t\tthis.subscriber.services,\n\t\t\t);\n\t\t\tthis._services = registered as ServiceRecord<TServices>;\n\t\t} else {\n\t\t\tthis._services = {} as ServiceRecord<TServices>;\n\t\t}\n\n\t\treturn this._services;\n\t}\n\n\tprivate error(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tonError: (req) => {\n\t\t\t\tconst logger = req.event?.logger || this.subscriber.logger;\n\t\t\t\tlogger.error(req.error || {}, 'Error processing subscriber');\n\n\t\t\t\t// Re-throw the wrapped error to let Lambda handle it\n\t\t\t\tthrow wrapError(req.error);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loggerMiddleware(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tbefore: (req) => {\n\t\t\t\tthis._logger = this.subscriber.logger.child({\n\t\t\t\t\tsubscriber: {\n\t\t\t\t\t\tname: req.context.functionName,\n\t\t\t\t\t\tversion: req.context.functionVersion,\n\t\t\t\t\t\tmemory: req.context.memoryLimitInMB,\n\t\t\t\t\t},\n\t\t\t\t\treq: {\n\t\t\t\t\t\tid: req.context.awsRequestId,\n\t\t\t\t\t},\n\t\t\t\t}) as TLogger;\n\n\t\t\t\treq.event.logger = this._logger;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate services(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\treq.event.services = await this.getServices();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate parseEvents(): Middleware<TServices, TLogger, OutSchema> {\n\t\treturn {\n\t\t\tbefore: async (req) => {\n\t\t\t\tconst { logger, ...e } = req.event;\n\t\t\t\tconst rawEvent = e as any as SQSEvent | SNSEvent;\n\n\t\t\t\tlogger.info({\n\t\t\t\t\trawEvent,\n\t\t\t\t});\n\n\t\t\t\t// Parse events based on the event type\n\t\t\t\tconst events: any[] = [];\n\n\t\t\t\tif ('Records' in rawEvent) {\n\t\t\t\t\tif (this.isSQSEvent(rawEvent)) {\n\t\t\t\t\t\t// SQS Event\n\t\t\t\t\t\tfor (const record of rawEvent.Records) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst event = this.parseSQSRecord(record);\n\t\t\t\t\t\t\t\tif (this.shouldIncludeEvent(event)) {\n\t\t\t\t\t\t\t\t\tevents.push(event);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t\t{ error, record },\n\t\t\t\t\t\t\t\t\t'Failed to parse SQS record',\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (this.isSNSEvent(rawEvent)) {\n\t\t\t\t\t\t// SNS Event\n\t\t\t\t\t\tfor (const record of rawEvent.Records) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst event = this.parseSNSRecord(record);\n\t\t\t\t\t\t\t\tif (this.shouldIncludeEvent(event)) {\n\t\t\t\t\t\t\t\t\tevents.push(event);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t\t{ error, record },\n\t\t\t\t\t\t\t\t\t'Failed to parse SNS record',\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t(req.event as any).events = events;\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate isSQSEvent(event: SQSEvent | SNSEvent): event is SQSEvent {\n\t\tconst firstRecord = event.Records[0];\n\t\treturn (\n\t\t\t'Records' in event &&\n\t\t\tevent.Records.length > 0 &&\n\t\t\tfirstRecord !== undefined &&\n\t\t\t'eventSource' in firstRecord &&\n\t\t\tfirstRecord.eventSource === 'aws:sqs'\n\t\t);\n\t}\n\n\tprivate isSNSEvent(event: SQSEvent | SNSEvent): event is SNSEvent {\n\t\tconst firstRecord = event.Records[0];\n\t\treturn (\n\t\t\t'Records' in event &&\n\t\t\tevent.Records.length > 0 &&\n\t\t\tfirstRecord !== undefined &&\n\t\t\t'EventSource' in firstRecord &&\n\t\t\tfirstRecord.EventSource === 'aws:sns'\n\t\t);\n\t}\n\n\tprivate parseSNSRecord(record: SNSEventRecord): any {\n\t\tconst message = this.safeJsonParse(record.Sns.Message);\n\t\tconst messageType = record.Sns.MessageAttributes?.type?.Value;\n\n\t\t// Not JSON — wrap raw string with type from MessageAttributes if available\n\t\tif (message === null) {\n\t\t\treturn messageType\n\t\t\t\t? { type: messageType, payload: record.Sns.Message }\n\t\t\t\t: record.Sns.Message;\n\t\t}\n\n\t\t// Resolve type from MessageAttributes (preferred) or message body\n\t\tconst resolvedType = messageType ?? message.type;\n\n\t\tif (message.type) {\n\t\t\treturn message; // Full event format: { type, payload }\n\t\t}\n\n\t\t// Payload-only format: type is in MessageAttributes\n\t\treturn resolvedType ? { type: resolvedType, payload: message } : message;\n\t}\n\n\tprivate parseSQSRecord(record: SQSRecord): any {\n\t\tconst body = this.safeJsonParse(record.body);\n\n\t\t// Not JSON — return raw body as-is\n\t\tif (body === null) {\n\t\t\treturn record.body;\n\t\t}\n\n\t\t// Check if this is an SNS message wrapped in SQS\n\t\tif (body.Type === 'Notification' && body.Message) {\n\t\t\tconst snsMessage = this.safeJsonParse(body.Message);\n\t\t\tconst messageType = body.MessageAttributes?.type?.Value;\n\n\t\t\t// SNS Message not JSON — wrap with type from MessageAttributes if available\n\t\t\tif (snsMessage === null) {\n\t\t\t\treturn messageType\n\t\t\t\t\t? { type: messageType, payload: body.Message }\n\t\t\t\t\t: body.Message;\n\t\t\t}\n\n\t\t\tif (snsMessage.type) {\n\t\t\t\treturn snsMessage; // Full event format: { type, payload }\n\t\t\t}\n\n\t\t\t// Payload-only format: type is in MessageAttributes\n\t\t\tconst resolvedType = messageType ?? snsMessage.type;\n\t\t\treturn resolvedType\n\t\t\t\t? { type: resolvedType, payload: snsMessage }\n\t\t\t\t: snsMessage;\n\t\t}\n\n\t\t// Direct SQS message\n\t\treturn body;\n\t}\n\n\tprivate safeJsonParse(value: string): any | null {\n\t\ttry {\n\t\t\treturn JSON.parse(value);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate shouldIncludeEvent(event: any): boolean {\n\t\t// No event type (raw string/non-object) — always include\n\t\tif (typeof event !== 'object' || !event?.type) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// No filter configured — accept all\n\t\tif (!this.subscriber.subscribedEvents) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn this.subscriber.subscribedEvents.includes(event.type as any);\n\t}\n\n\tprivate async _handler(event: SubscriberEvent<TServices, TLogger>) {\n\t\t// If no events after filtering, return early\n\t\tif (event.events.length === 0) {\n\t\t\tthis.logger.info('No subscribed events to process');\n\t\t\treturn {\n\t\t\t\tbatchItemFailures: [],\n\t\t\t};\n\t\t}\n\n\t\t// Execute the subscriber with the parsed context\n\t\tconst result = await this.subscriber.handler({\n\t\t\tevents: event.events,\n\t\t\tservices: event.services,\n\t\t\tlogger: event.logger,\n\t\t});\n\n\t\t// Parse output if schema is provided\n\t\tif (this.subscriber.outputSchema && result) {\n\t\t\tconst validationResult =\n\t\t\t\tawait this.subscriber.outputSchema['~standard'].validate(result);\n\n\t\t\tif (validationResult.issues) {\n\t\t\t\tthis.logger.error(\n\t\t\t\t\t{ issues: validationResult.issues },\n\t\t\t\t\t'Subscriber output validation failed',\n\t\t\t\t);\n\t\t\t\tthrow new Error('Subscriber output validation failed');\n\t\t\t}\n\n\t\t\treturn validationResult.value;\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tget handler(): AWSLambdaHandler {\n\t\tconst handler = this._handler.bind(this);\n\n\t\t// Apply middleware in order\n\t\tconst chain = middy(handler)\n\t\t\t.use(this.loggerMiddleware())\n\t\t\t.use(this.parseEvents())\n\t\t\t.use(this.error())\n\t\t\t.use(this.services());\n\n\t\t// Wrap entire Middy chain in request context for service access\n\t\tconst wrappedHandler = async (event: unknown, context: Context) => {\n\t\t\tconst startTime = Date.now();\n\t\t\tconst requestId = context.awsRequestId;\n\t\t\tconst logger = this.subscriber.logger.child({\n\t\t\t\trequestId,\n\t\t\t}) as TLogger;\n\n\t\t\treturn runWithRequestContext({ logger, requestId, startTime }, () =>\n\t\t\t\tchain(event as Parameters<typeof chain>[0], context),\n\t\t\t);\n\t\t};\n\n\t\treturn wrappedHandler as unknown as AWSLambdaHandler;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmFA,IAAsB,2BAAtB,MAoBE;CACD,AAAU;CAEV,YACWA,WACSC,UAcnBC,UAA2C,CAAE,GAC5C;EAhBS;EACS;AAgBnB,OAAK,UAAU;CACf;CAED,AAAQ,QAAwD;AAC/D,SAAO,EACN,SAAS,CAAC,QAAQ;AACjB,IAAC,IAAI,MAAM,UAAU,KAAK,SAAS,QAAQ,MAC1C,IAAI,SAAS,CAAE,GACf,2BACA;GACD,MAAM,eAAe,UAAU,IAAI,MAAM;AAGzC,OAAI,WAAW;IACd,YAAY,aAAa;IACzB,MAAM,aAAa;GACnB;EACD,EACD;CACD;;;;;;;;;CAWD,OAAO,WACNC,MACAC,iBACAC,aACM;AACN,OAAK,KAAM;EAEX,MAAM,MAAM,kBACT,OAAO,KAAK,MAAM,SAAS,CAAC,SAAS,QAAQ,GAC7C;EAEH,MAAM,UACJ,eAAe,YAAY,aAAa,CAAC,SAAS,mBAAmB;AACvE,MAAI,OACH,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B;AAED,SAAO;CACP;CAED,IAAI,UAA4B;EAC/B,MAAM,UAAU,KAAK,SAAS,KAAK,KAAK;EAGxC,MAAM,QAAQ,MAAM,QAAQ,CAC1B,IAAI,KAAK,kBAAkB,CAAC,CAC5B,IAAI,KAAK,aAAa,CAAC,CACvB,IAAI,KAAK,OAAO,CAAC,CACjB,IAAI,KAAK,UAAU,CAAC;EAGtB,MAAM,iBAAiB,OAAOC,OAAgBC,YAAqB;GAClE,MAAM,YAAY,KAAK,KAAK;GAC5B,MAAM,YAAY,QAAQ;GAC1B,MAAM,SAAS,KAAK,WAAW,OAAO,MAAM,EAC3C,UACA,EAAC;AAEF,UAAO,sBAAsB;IAAE;IAAQ;IAAW;GAAW,GAAE,MAC9D,MAAM,OAAsC,QAAQ,CACpD;EACD;AAED,SAAO;CACP;AACD"}
|
|
@@ -2,7 +2,7 @@ import "../Construct-BEh2DSMe.cjs";
|
|
|
2
2
|
import { Function } from "../index-XJKTxGx7.cjs";
|
|
3
3
|
import { HttpMethod } from "../types-BdAaYDvd.cjs";
|
|
4
4
|
import { Endpoint, EndpointSchemas } from "../Endpoint-DIQblT3d.cjs";
|
|
5
|
-
import { Queue, QueueRecord } from "../Queue-
|
|
5
|
+
import { Queue, QueueRecord } from "../Queue-GJexVGOh.cjs";
|
|
6
6
|
import { Subscriber } from "../Subscriber-YwPpHrBc.cjs";
|
|
7
7
|
import { EventPublisher, ExtractPublisherMessage } from "@geekmidas/events";
|
|
8
8
|
import { Logger } from "@geekmidas/logger";
|
|
@@ -2,7 +2,7 @@ import "../Construct-qnOnQTcP.mjs";
|
|
|
2
2
|
import { Function } from "../index-CbhtERFB.mjs";
|
|
3
3
|
import { HttpMethod } from "../types-X37z95fN.mjs";
|
|
4
4
|
import { Endpoint, EndpointSchemas } from "../Endpoint-ZtG0zVz1.mjs";
|
|
5
|
-
import { Queue, QueueRecord } from "../Queue-
|
|
5
|
+
import { Queue, QueueRecord } from "../Queue-Bg6WzavN.mjs";
|
|
6
6
|
import { Subscriber } from "../Subscriber-Bjil86Ub.mjs";
|
|
7
7
|
import { Service, ServiceDiscovery, ServiceRecord } from "@geekmidas/services";
|
|
8
8
|
import { AuditStorage, AuditableAction, Auditor } from "@geekmidas/audit";
|
package/dist/queue/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_Construct = require('../Construct-Cf_0pAvo.cjs');
|
|
2
2
|
const require_clone = require('../clone-BQnYiRgm.cjs');
|
|
3
|
-
const require_Queue = require('../Queue-
|
|
3
|
+
const require_Queue = require('../Queue-Di2a2N-b.cjs');
|
|
4
4
|
const __geekmidas_logger_console = require_Construct.__toESM(require("@geekmidas/logger/console"));
|
|
5
5
|
|
|
6
6
|
//#region src/queue/QueueBuilder.ts
|
|
@@ -16,6 +16,8 @@ var QueueBuilder = class {
|
|
|
16
16
|
_timeout = 3e4;
|
|
17
17
|
_batchSize;
|
|
18
18
|
_fifo;
|
|
19
|
+
_envelope = true;
|
|
20
|
+
_groupId;
|
|
19
21
|
_services = [];
|
|
20
22
|
_logger = __geekmidas_logger_console.DEFAULT_LOGGER;
|
|
21
23
|
/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */
|
|
@@ -29,9 +31,27 @@ var QueueBuilder = class {
|
|
|
29
31
|
batchSize(batchSize) {
|
|
30
32
|
return require_clone.cloneWith(this, { _batchSize: batchSize });
|
|
31
33
|
}
|
|
32
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Mark the queue as FIFO (deployed). Pass `{ groupId }` to give each message
|
|
36
|
+
* its message group, which the queue's publisher then sends: a FIFO queue
|
|
37
|
+
* refuses a message without one. Messages in one group keep their order.
|
|
38
|
+
*/
|
|
33
39
|
fifo(fifo = true) {
|
|
34
|
-
return require_clone.cloneWith(this, { _fifo: fifo });
|
|
40
|
+
if (typeof fifo === "boolean") return require_clone.cloneWith(this, { _fifo: fifo });
|
|
41
|
+
return require_clone.cloneWith(this, {
|
|
42
|
+
_fifo: true,
|
|
43
|
+
_groupId: fifo.groupId
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether messages arrive in the `{ type, payload }` envelope the queue's
|
|
48
|
+
* publisher writes. Pass `false` for a queue fed by something else — an IoT
|
|
49
|
+
* rule, a webhook forwarder — whose bodies are the message as they stand: a
|
|
50
|
+
* body is then never unwrapped, even one that has a `payload` field of its
|
|
51
|
+
* own, and one that is not JSON is the message as a string.
|
|
52
|
+
*/
|
|
53
|
+
envelope(envelope = true) {
|
|
54
|
+
return require_clone.cloneWith(this, { _envelope: envelope });
|
|
35
55
|
}
|
|
36
56
|
services(services) {
|
|
37
57
|
return require_clone.cloneWith(this, { _services: [...this._services, ...services] });
|
|
@@ -46,7 +66,7 @@ var QueueBuilder = class {
|
|
|
46
66
|
handle(fn) {
|
|
47
67
|
if (!this._name) throw new Error("Queue requires a name — call .queue(name) before .handle().");
|
|
48
68
|
if (!this._messageSchema) throw new Error("Queue requires a message schema — call .message(schema) before .handle().");
|
|
49
|
-
const queue = new require_Queue.Queue(this._name, fn, this._messageSchema, this._timeout, this._services, this._logger, this._batchSize, this._fifo);
|
|
69
|
+
const queue = new require_Queue.Queue(this._name, fn, this._messageSchema, this._timeout, this._services, this._logger, this._batchSize, this._fifo, this._envelope, this._groupId);
|
|
50
70
|
return queue;
|
|
51
71
|
}
|
|
52
72
|
};
|
package/dist/queue/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["DEFAULT_LOGGER","name: T","timeout: number","batchSize: number","services: T","logger: T","schema: T","fn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>","Queue"],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { cloneWith } from '../clone';\nimport { Queue, type QueueHandler } from './Queue';\n\n/**\n * Builds a {@link Queue} worker — `q.queue('orders').services([db]).message(schema).handle(fn)`.\n * Services are an array (sniffed for required env vars); `message` is the typed\n * job payload; `handle` is the single consumer. The queue name is captured as a\n * literal so `queue.publisher` is typed to `{ type: '<name>', payload }`.\n */\nexport class QueueBuilder<\n\tTName extends string = string,\n\tTMessage extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> {\n\tprivate _name?: string;\n\tprivate _messageSchema?: TMessage;\n\tprivate _timeout = 30000;\n\tprivate _batchSize?: number;\n\tprivate _fifo?: boolean;\n\tprivate _services: TServices = [] as Service[] as TServices;\n\tprivate _logger: TLogger = DEFAULT_LOGGER as TLogger;\n\n\t/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */\n\tqueue<T extends string>(\n\t\tname: T,\n\t): QueueBuilder<T, TMessage, TServices, TLogger> {\n\t\treturn cloneWith(this, { _name: name }) as unknown as QueueBuilder<\n\t\t\tT,\n\t\t\tTMessage,\n\t\t\tTServices,\n\t\t\tTLogger\n\t\t>;\n\t}\n\n\ttimeout(timeout: number): this {\n\t\treturn cloneWith(this, { _timeout: timeout });\n\t}\n\n\t/** SQS event-source batch size (deployed). */\n\tbatchSize(batchSize: number): this {\n\t\treturn cloneWith(this, { _batchSize: batchSize });\n\t}\n\n\t
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["DEFAULT_LOGGER","name: T","timeout: number","batchSize: number","fifo:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t\tgroupId: (\n\t\t\t\t\t\tmessage: TMessage extends StandardSchemaV1\n\t\t\t\t\t\t\t? InferStandardSchema<TMessage>\n\t\t\t\t\t\t\t: never,\n\t\t\t\t\t) => string;\n\t\t\t }","services: T","logger: T","schema: T","fn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>","Queue"],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { cloneWith } from '../clone';\nimport { Queue, type QueueHandler } from './Queue';\n\n/**\n * Builds a {@link Queue} worker — `q.queue('orders').services([db]).message(schema).handle(fn)`.\n * Services are an array (sniffed for required env vars); `message` is the typed\n * job payload; `handle` is the single consumer. The queue name is captured as a\n * literal so `queue.publisher` is typed to `{ type: '<name>', payload }`.\n */\nexport class QueueBuilder<\n\tTName extends string = string,\n\tTMessage extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> {\n\tprivate _name?: string;\n\tprivate _messageSchema?: TMessage;\n\tprivate _timeout = 30000;\n\tprivate _batchSize?: number;\n\tprivate _fifo?: boolean;\n\tprivate _envelope = true;\n\tprivate _groupId?: (message: any) => string;\n\tprivate _services: TServices = [] as Service[] as TServices;\n\tprivate _logger: TLogger = DEFAULT_LOGGER as TLogger;\n\n\t/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */\n\tqueue<T extends string>(\n\t\tname: T,\n\t): QueueBuilder<T, TMessage, TServices, TLogger> {\n\t\treturn cloneWith(this, { _name: name }) as unknown as QueueBuilder<\n\t\t\tT,\n\t\t\tTMessage,\n\t\t\tTServices,\n\t\t\tTLogger\n\t\t>;\n\t}\n\n\ttimeout(timeout: number): this {\n\t\treturn cloneWith(this, { _timeout: timeout });\n\t}\n\n\t/** SQS event-source batch size (deployed). */\n\tbatchSize(batchSize: number): this {\n\t\treturn cloneWith(this, { _batchSize: batchSize });\n\t}\n\n\t/**\n\t * Mark the queue as FIFO (deployed). Pass `{ groupId }` to give each message\n\t * its message group, which the queue's publisher then sends: a FIFO queue\n\t * refuses a message without one. Messages in one group keep their order.\n\t */\n\tfifo(\n\t\tfifo:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t\tgroupId: (\n\t\t\t\t\t\tmessage: TMessage extends StandardSchemaV1\n\t\t\t\t\t\t\t? InferStandardSchema<TMessage>\n\t\t\t\t\t\t\t: never,\n\t\t\t\t\t) => string;\n\t\t\t } = true,\n\t): this {\n\t\tif (typeof fifo === 'boolean') {\n\t\t\treturn cloneWith(this, { _fifo: fifo });\n\t\t}\n\t\treturn cloneWith(this, { _fifo: true, _groupId: fifo.groupId });\n\t}\n\n\t/**\n\t * Whether messages arrive in the `{ type, payload }` envelope the queue's\n\t * publisher writes. Pass `false` for a queue fed by something else — an IoT\n\t * rule, a webhook forwarder — whose bodies are the message as they stand: a\n\t * body is then never unwrapped, even one that has a `payload` field of its\n\t * own, and one that is not JSON is the message as a string.\n\t */\n\tenvelope(envelope = true): this {\n\t\treturn cloneWith(this, { _envelope: envelope });\n\t}\n\n\tservices<T extends Service[]>(\n\t\tservices: T,\n\t): QueueBuilder<TName, TMessage, [...TServices, ...T], TLogger> {\n\t\treturn cloneWith(this, {\n\t\t\t_services: [...this._services, ...services] as unknown as TServices,\n\t\t}) as unknown as QueueBuilder<\n\t\t\tTName,\n\t\t\tTMessage,\n\t\t\t[...TServices, ...T],\n\t\t\tTLogger\n\t\t>;\n\t}\n\n\tlogger<T extends Logger>(\n\t\tlogger: T,\n\t): QueueBuilder<TName, TMessage, TServices, T> {\n\t\treturn cloneWith(this, {\n\t\t\t_logger: logger as unknown as TLogger,\n\t\t}) as unknown as QueueBuilder<TName, TMessage, TServices, T>;\n\t}\n\n\t/** The typed message (job) payload the queue carries. */\n\tmessage<T extends StandardSchemaV1>(\n\t\tschema: T,\n\t): QueueBuilder<TName, T, TServices, TLogger> {\n\t\treturn cloneWith(this, {\n\t\t\t_messageSchema: schema as unknown as TMessage,\n\t\t}) as unknown as QueueBuilder<TName, T, TServices, TLogger>;\n\t}\n\n\thandle(\n\t\tfn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>,\n\t): Queue<TName, NonNullable<TMessage>, TServices, TLogger> {\n\t\tif (!this._name) {\n\t\t\tthrow new Error(\n\t\t\t\t'Queue requires a name — call .queue(name) before .handle().',\n\t\t\t);\n\t\t}\n\t\tif (!this._messageSchema) {\n\t\t\tthrow new Error(\n\t\t\t\t'Queue requires a message schema — call .message(schema) before .handle().',\n\t\t\t);\n\t\t}\n\n\t\tconst queue = new Queue<TName, NonNullable<TMessage>, TServices, TLogger>(\n\t\t\tthis._name as TName,\n\t\t\tfn,\n\t\t\tthis._messageSchema as NonNullable<TMessage>,\n\t\t\tthis._timeout,\n\t\t\tthis._services,\n\t\t\tthis._logger,\n\t\t\tthis._batchSize,\n\t\t\tthis._fifo,\n\t\t\tthis._envelope,\n\t\t\tthis._groupId,\n\t\t);\n\n\t\t// No reset. `.handle()` reads this builder and leaves it alone, so a\n\t\t// configured base keeps its configuration for every construct built\n\t\t// from it. The reset that used to be here wiped the base on first use.\n\n\t\treturn queue;\n\t}\n}\n","export {\n\tisQueueResult,\n\tQueue,\n\ttype QueueContext,\n\ttype QueueHandler,\n\ttype QueueMessage,\n\ttype QueueRecord,\n\ttype QueueResult,\n} from './Queue';\n\nimport { QueueBuilder } from './QueueBuilder';\n\nexport { QueueBuilder } from './QueueBuilder';\n\nexport const q = new QueueBuilder();\n"],"mappings":";;;;;;;;;;;;AAcA,IAAa,eAAb,MAKE;CACD,AAAQ;CACR,AAAQ;CACR,AAAQ,WAAW;CACnB,AAAQ;CACR,AAAQ;CACR,AAAQ,YAAY;CACpB,AAAQ;CACR,AAAQ,YAAuB,CAAE;CACjC,AAAQ,UAAmBA;;CAG3B,MACCC,MACgD;AAChD,SAAO,wBAAU,MAAM,EAAE,OAAO,KAAM,EAAC;CAMvC;CAED,QAAQC,SAAuB;AAC9B,SAAO,wBAAU,MAAM,EAAE,UAAU,QAAS,EAAC;CAC7C;;CAGD,UAAUC,WAAyB;AAClC,SAAO,wBAAU,MAAM,EAAE,YAAY,UAAW,EAAC;CACjD;;;;;;CAOD,KACCC,OAQO,MACA;AACP,aAAW,SAAS,UACnB,QAAO,wBAAU,MAAM,EAAE,OAAO,KAAM,EAAC;AAExC,SAAO,wBAAU,MAAM;GAAE,OAAO;GAAM,UAAU,KAAK;EAAS,EAAC;CAC/D;;;;;;;;CASD,SAAS,WAAW,MAAY;AAC/B,SAAO,wBAAU,MAAM,EAAE,WAAW,SAAU,EAAC;CAC/C;CAED,SACCC,UAC+D;AAC/D,SAAO,wBAAU,MAAM,EACtB,WAAW,CAAC,GAAG,KAAK,WAAW,GAAG,QAAS,EAC3C,EAAC;CAMF;CAED,OACCC,QAC8C;AAC9C,SAAO,wBAAU,MAAM,EACtB,SAAS,OACT,EAAC;CACF;;CAGD,QACCC,QAC6C;AAC7C,SAAO,wBAAU,MAAM,EACtB,gBAAgB,OAChB,EAAC;CACF;CAED,OACCC,IAC0D;AAC1D,OAAK,KAAK,MACT,OAAM,IAAI,MACT;AAGF,OAAK,KAAK,eACT,OAAM,IAAI,MACT;EAIF,MAAM,QAAQ,IAAIC,oBACjB,KAAK,OACL,IACA,KAAK,gBACL,KAAK,UACL,KAAK,WACL,KAAK,SACL,KAAK,YACL,KAAK,OACL,KAAK,WACL,KAAK;AAON,SAAO;CACP;AACD;;;;ACrID,MAAa,IAAI,IAAI"}
|
package/dist/queue/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "../Construct-BEh2DSMe.cjs";
|
|
2
|
-
import { Queue, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult } from "../Queue-
|
|
2
|
+
import { Queue, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult } from "../Queue-GJexVGOh.cjs";
|
|
3
3
|
import * as _geekmidas_logger8 from "@geekmidas/logger";
|
|
4
4
|
import { Logger } from "@geekmidas/logger";
|
|
5
|
+
import { InferStandardSchema } from "@geekmidas/schema";
|
|
5
6
|
import { Service } from "@geekmidas/services";
|
|
6
7
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
7
8
|
|
|
@@ -19,6 +20,8 @@ declare class QueueBuilder<TName extends string = string, TMessage extends Stand
|
|
|
19
20
|
private _timeout;
|
|
20
21
|
private _batchSize?;
|
|
21
22
|
private _fifo?;
|
|
23
|
+
private _envelope;
|
|
24
|
+
private _groupId?;
|
|
22
25
|
private _services;
|
|
23
26
|
private _logger;
|
|
24
27
|
/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */
|
|
@@ -26,8 +29,22 @@ declare class QueueBuilder<TName extends string = string, TMessage extends Stand
|
|
|
26
29
|
timeout(timeout: number): this;
|
|
27
30
|
/** SQS event-source batch size (deployed). */
|
|
28
31
|
batchSize(batchSize: number): this;
|
|
29
|
-
/**
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Mark the queue as FIFO (deployed). Pass `{ groupId }` to give each message
|
|
34
|
+
* its message group, which the queue's publisher then sends: a FIFO queue
|
|
35
|
+
* refuses a message without one. Messages in one group keep their order.
|
|
36
|
+
*/
|
|
37
|
+
fifo(fifo?: boolean | {
|
|
38
|
+
groupId: (message: TMessage extends StandardSchemaV1 ? InferStandardSchema<TMessage> : never) => string;
|
|
39
|
+
}): this;
|
|
40
|
+
/**
|
|
41
|
+
* Whether messages arrive in the `{ type, payload }` envelope the queue's
|
|
42
|
+
* publisher writes. Pass `false` for a queue fed by something else — an IoT
|
|
43
|
+
* rule, a webhook forwarder — whose bodies are the message as they stand: a
|
|
44
|
+
* body is then never unwrapped, even one that has a `payload` field of its
|
|
45
|
+
* own, and one that is not JSON is the message as a string.
|
|
46
|
+
*/
|
|
47
|
+
envelope(envelope?: boolean): this;
|
|
31
48
|
services<T extends Service[]>(services: T): QueueBuilder<TName, TMessage, [...TServices, ...T], TLogger>;
|
|
32
49
|
logger<T extends Logger>(logger: T): QueueBuilder<TName, TMessage, TServices, T>;
|
|
33
50
|
/** The typed message (job) payload the queue carries. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;AAcA;;AAEkB,cAFL,YAEK,CAAA,cAAA,MAAA,GAAA,MAAA,EAAA,iBAAA,gBAAA,GAAA,SAAA,GAAA,SAAA,EAAA,kBACC,OADD,EAAA,GAAA,EAAA,EAAA,gBAED,MAFC,GAEQ,MAFR,CAAA,CAAA;EAAgB,QACf,KAAA;EAAO,QACT,cAAA;EAAM,QAAG,QAAA;EAAM,QAcxB,UAAA;EAAC,QACQ,KAAA;EAAC,QAAE,SAAA;EAAQ,QAAE,QAAA;EAAS,QAAE,SAAA;EAAO,QAA5C,OAAA;EAAY;EA4BO,KAAS,CAAA,UAAA,MAAA,CAAA,CAAA,IAAA,EA7BxB,CA6BwB,CAAA,EA5B5B,YA4B4B,CA5Bf,CA4Be,EA5BZ,QA4BY,EA5BF,SA4BE,EA5BS,OA4BT,CAAA;EAAgB,OACnB,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAQ;EAAT,SAsBR,CAAA,SAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAO;;;;;EAE0B,IAAG,CAAA,IAAxC,CAAwC,EAAA,OAAA,GAAA;IAApD,OAAA,EAAA,CAAA,OAAA,EAzBW,QAyBX,SAzB4B,gBAyB5B,GAxBK,mBAwBL,CAxByB,QAwBzB,CAAA,GAAA,KAAA,EAAA,GAAA,MAAA;EAAY,CAAA,CAAA,EAWE,IAAA;EAAM;;;;;;;EASW,QACzB,CAAA,QAAA,CAAA,EAAA,OAAA,CAAA,EAAA,IAAA;EAAC,QACM,CAAA,UAxBG,OAwBH,EAAA,CAAA,CAAA,QAAA,EAvBL,CAuBK,CAAA,EAtBb,YAsBa,CAtBA,KAsBA,EAtBO,QAsBP,EAAA,CAAA,GAtBqB,SAsBrB,EAAA,GAtBmC,CAsBnC,CAAA,EAtBuC,OAsBvC,CAAA;EAAK,MAAE,CAAA,UAXN,MAWM,CAAA,CAAA,MAAA,EAVd,CAUc,CAAA,EATpB,YASoB,CATP,KASO,EATA,QASA,EATU,SASV,EATqB,CASrB,CAAA;EAAC;EAAW,OAAE,CAAA,UAFnB,gBAEmB,CAAA,CAAA,MAAA,EAD5B,CAC4B,CAAA,EAAlC,YAAkC,CAArB,KAAqB,EAAd,CAAc,EAAX,SAAW,EAAA,OAAA,CAAA;EAAO,MAAzC,CAAA,EAAA,EAOE,YAPF,CAOe,WAPf,CAO2B,QAP3B,CAAA,EAOsC,SAPtC,EAOiD,OAPjD,CAAA,CAAA,EAQA,KARA,CAQM,KARN,EAQa,WARb,CAQyB,QARzB,CAAA,EAQoC,SARpC,EAQ+C,OAR/C,CAAA;;;;;cC9FS,GAAC,oCAAqB,kBAAA,CAArB,MAAA"}
|
package/dist/queue/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "../Construct-qnOnQTcP.mjs";
|
|
2
|
-
import { Queue, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult } from "../Queue-
|
|
2
|
+
import { Queue, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult } from "../Queue-Bg6WzavN.mjs";
|
|
3
3
|
import { Service } from "@geekmidas/services";
|
|
4
4
|
import { Logger as Logger$1 } from "@geekmidas/logger";
|
|
5
|
+
import { InferStandardSchema } from "@geekmidas/schema";
|
|
5
6
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
7
|
|
|
7
8
|
//#region src/queue/QueueBuilder.d.ts
|
|
@@ -18,6 +19,8 @@ declare class QueueBuilder<TName extends string = string, TMessage extends Stand
|
|
|
18
19
|
private _timeout;
|
|
19
20
|
private _batchSize?;
|
|
20
21
|
private _fifo?;
|
|
22
|
+
private _envelope;
|
|
23
|
+
private _groupId?;
|
|
21
24
|
private _services;
|
|
22
25
|
private _logger;
|
|
23
26
|
/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */
|
|
@@ -25,8 +28,22 @@ declare class QueueBuilder<TName extends string = string, TMessage extends Stand
|
|
|
25
28
|
timeout(timeout: number): this;
|
|
26
29
|
/** SQS event-source batch size (deployed). */
|
|
27
30
|
batchSize(batchSize: number): this;
|
|
28
|
-
/**
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Mark the queue as FIFO (deployed). Pass `{ groupId }` to give each message
|
|
33
|
+
* its message group, which the queue's publisher then sends: a FIFO queue
|
|
34
|
+
* refuses a message without one. Messages in one group keep their order.
|
|
35
|
+
*/
|
|
36
|
+
fifo(fifo?: boolean | {
|
|
37
|
+
groupId: (message: TMessage extends StandardSchemaV1 ? InferStandardSchema<TMessage> : never) => string;
|
|
38
|
+
}): this;
|
|
39
|
+
/**
|
|
40
|
+
* Whether messages arrive in the `{ type, payload }` envelope the queue's
|
|
41
|
+
* publisher writes. Pass `false` for a queue fed by something else — an IoT
|
|
42
|
+
* rule, a webhook forwarder — whose bodies are the message as they stand: a
|
|
43
|
+
* body is then never unwrapped, even one that has a `payload` field of its
|
|
44
|
+
* own, and one that is not JSON is the message as a string.
|
|
45
|
+
*/
|
|
46
|
+
envelope(envelope?: boolean): this;
|
|
30
47
|
services<T extends Service[]>(services: T): QueueBuilder<TName, TMessage, [...TServices, ...T], TLogger>;
|
|
31
48
|
logger<T extends Logger$1>(logger: T): QueueBuilder<TName, TMessage, TServices, T>;
|
|
32
49
|
/** The typed message (job) payload the queue carries. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;AAcA;;;AAGmB,cAHN,YAGM,CAAA,cAAA,MAAA,GA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AA,CAAA,MAAA,EADM,CACN,CAAA,EAAA,YAAA,CAAa,KAAb,EAAoB,CAApB,EAAuB,SAAvB,EAAkC,OAAlC,CAAA;EAAY,MAOe,CAAA,EAAA,EAAzB,YAAyB,CAAZ,WAAY,CAAA,QAAA,CAAA,EAAW,SAAX,EAAsB,OAAtB,CAAA,CAAA,EAC3B,KAD2B,CACrB,KADqB,EACd,WADc,CACF,QADE,CAAA,EACS,SADT,EACoB,OADpB,CAAA;;;;;cCrGlB,GAAC,oCAAA"}
|
package/dist/queue/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../Construct-D5LZBFhb.mjs";
|
|
2
2
|
import { cloneWith } from "../clone-BWIwx6vL.mjs";
|
|
3
|
-
import { Queue, isQueueResult } from "../Queue-
|
|
3
|
+
import { Queue, isQueueResult } from "../Queue-Cvv-QluM.mjs";
|
|
4
4
|
import { DEFAULT_LOGGER } from "@geekmidas/logger/console";
|
|
5
5
|
|
|
6
6
|
//#region src/queue/QueueBuilder.ts
|
|
@@ -16,6 +16,8 @@ var QueueBuilder = class {
|
|
|
16
16
|
_timeout = 3e4;
|
|
17
17
|
_batchSize;
|
|
18
18
|
_fifo;
|
|
19
|
+
_envelope = true;
|
|
20
|
+
_groupId;
|
|
19
21
|
_services = [];
|
|
20
22
|
_logger = DEFAULT_LOGGER;
|
|
21
23
|
/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */
|
|
@@ -29,9 +31,27 @@ var QueueBuilder = class {
|
|
|
29
31
|
batchSize(batchSize) {
|
|
30
32
|
return cloneWith(this, { _batchSize: batchSize });
|
|
31
33
|
}
|
|
32
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Mark the queue as FIFO (deployed). Pass `{ groupId }` to give each message
|
|
36
|
+
* its message group, which the queue's publisher then sends: a FIFO queue
|
|
37
|
+
* refuses a message without one. Messages in one group keep their order.
|
|
38
|
+
*/
|
|
33
39
|
fifo(fifo = true) {
|
|
34
|
-
return cloneWith(this, { _fifo: fifo });
|
|
40
|
+
if (typeof fifo === "boolean") return cloneWith(this, { _fifo: fifo });
|
|
41
|
+
return cloneWith(this, {
|
|
42
|
+
_fifo: true,
|
|
43
|
+
_groupId: fifo.groupId
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether messages arrive in the `{ type, payload }` envelope the queue's
|
|
48
|
+
* publisher writes. Pass `false` for a queue fed by something else — an IoT
|
|
49
|
+
* rule, a webhook forwarder — whose bodies are the message as they stand: a
|
|
50
|
+
* body is then never unwrapped, even one that has a `payload` field of its
|
|
51
|
+
* own, and one that is not JSON is the message as a string.
|
|
52
|
+
*/
|
|
53
|
+
envelope(envelope = true) {
|
|
54
|
+
return cloneWith(this, { _envelope: envelope });
|
|
35
55
|
}
|
|
36
56
|
services(services) {
|
|
37
57
|
return cloneWith(this, { _services: [...this._services, ...services] });
|
|
@@ -46,7 +66,7 @@ var QueueBuilder = class {
|
|
|
46
66
|
handle(fn) {
|
|
47
67
|
if (!this._name) throw new Error("Queue requires a name — call .queue(name) before .handle().");
|
|
48
68
|
if (!this._messageSchema) throw new Error("Queue requires a message schema — call .message(schema) before .handle().");
|
|
49
|
-
const queue = new Queue(this._name, fn, this._messageSchema, this._timeout, this._services, this._logger, this._batchSize, this._fifo);
|
|
69
|
+
const queue = new Queue(this._name, fn, this._messageSchema, this._timeout, this._services, this._logger, this._batchSize, this._fifo, this._envelope, this._groupId);
|
|
50
70
|
return queue;
|
|
51
71
|
}
|
|
52
72
|
};
|