@karmaniverous/smoz 0.1.2
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/LICENSE +28 -0
- package/README.md +66 -0
- package/dist/cjs/index.js +706 -0
- package/dist/cjs/serverless-plugin.js +43 -0
- package/dist/index.d.ts +422 -0
- package/dist/mjs/index.js +690 -0
- package/dist/mjs/serverless-plugin.js +41 -0
- package/dist/serverless-plugin.d.ts +6 -0
- package/package.json +190 -0
- package/templates/.check/eslint.minimal.config.ts +41 -0
- package/templates/.check/eslint.templates.config.ts +60 -0
- package/templates/.check/tsconfig.eslintconfig.json +6 -0
- package/templates/.check/tsconfig.minimal.json +14 -0
- package/templates/.manifests/package.minimal.json +19 -0
- package/templates/.manifests/package.project.json +23 -0
- package/templates/minimal/app/config/app.config.ts +50 -0
- package/templates/minimal/app/config/openapi.ts +45 -0
- package/templates/minimal/app/functions/rest/hello/get/handler.ts +18 -0
- package/templates/minimal/app/functions/rest/hello/get/lambda.ts +28 -0
- package/templates/minimal/app/functions/rest/hello/get/openapi.ts +23 -0
- package/templates/minimal/serverless.ts +34 -0
- package/templates/minimal/tsconfig.json +25 -0
- package/templates/minimal/types/registers.d.ts +11 -0
- package/templates/project/.prettierrc.json +3 -0
- package/templates/project/README.md +85 -0
- package/templates/project/eslint.config.ts +47 -0
- package/templates/project/tsconfig.base.json +21 -0
- package/templates/project/tsconfig.json +16 -0
- package/templates/project/typedoc.json +14 -0
- package/templates/project/vitest.config.ts +8 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_child_process = require('node:child_process');
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
|
|
6
|
+
/* REQUIREMENTS ADDRESSED
|
|
7
|
+
* - Provide a lightweight Serverless Framework plugin that ensures registers are fresh
|
|
8
|
+
* by running `smoz register` before package/deploy.
|
|
9
|
+
* - Keep it simple: spawn Node to run the packaged CJS CLI, inherit stdio, and fail fast.
|
|
10
|
+
*
|
|
11
|
+
* Notes:
|
|
12
|
+
* - This file is bundled to dist/cjs/serverless-plugin.js and exported via the "./serverless-plugin" subpath.
|
|
13
|
+
* - Serverless v4 loads CJS plugins via `require`; exporting a default class allows
|
|
14
|
+
* rollup to wrap it for CJS while preserving the ESM entry for completeness.
|
|
15
|
+
*/
|
|
16
|
+
const runRegister = () => {
|
|
17
|
+
// Resolve the packaged CLI entry relative to the compiled CJS plugin:
|
|
18
|
+
// dist/cjs/serverless-plugin.js -> ../cli/index.cjs
|
|
19
|
+
const cliPath = path.resolve(__dirname, '../cli/index.cjs');
|
|
20
|
+
const res = node_child_process.spawnSync(process.execPath, [cliPath, 'register'], {
|
|
21
|
+
stdio: 'inherit',
|
|
22
|
+
shell: false,
|
|
23
|
+
});
|
|
24
|
+
const code = typeof res.status === 'number' ? String(res.status) : 'unknown';
|
|
25
|
+
if (res.status !== 0)
|
|
26
|
+
throw new Error(`smoz register failed (exit code ${code})`);
|
|
27
|
+
};
|
|
28
|
+
// Minimal Serverless v4 plugin: register hooks that run before package/deploy.
|
|
29
|
+
class SmozRegisterPlugin {
|
|
30
|
+
hooks;
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
constructor(_serverless, _options) {
|
|
33
|
+
this.hooks = {
|
|
34
|
+
// Package lifecycle
|
|
35
|
+
'before:package:initialize': runRegister,
|
|
36
|
+
// Deploy lifecycles where functions/artifacts can be (re)built
|
|
37
|
+
'before:deploy:function:initialize': runRegister,
|
|
38
|
+
'before:deploy:deploy': runRegister,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = SmozRegisterPlugin;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { AWS } from '@serverless/typescript';
|
|
2
|
+
import { z, ZodObject, ZodRawShape } from 'zod';
|
|
3
|
+
import { ZodOpenApiPathsObject, ZodOpenApiPathItemObject } from 'zod-openapi';
|
|
4
|
+
import { buildStageArtifacts } from '@/src/core/buildStageArtifacts';
|
|
5
|
+
import { EnvSchemaNode as EnvSchemaNode$1 } from '@/src/core/defineAppConfig';
|
|
6
|
+
import { serverlessConfigSchema, AppServerlessConfig } from '@/src/core/serverlessConfig';
|
|
7
|
+
import { ZodObj } from '@/src/core/types';
|
|
8
|
+
import { AppHttpConfig as AppHttpConfig$1 } from '@/src/http/middleware/httpStackCustomization';
|
|
9
|
+
import { MethodKey as MethodKey$1, FunctionConfig } from '@/src/types/FunctionConfig';
|
|
10
|
+
import { HttpContext as HttpContext$1 } from '@/src/types/HttpContext';
|
|
11
|
+
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, ALBEvent, SQSEvent, SNSEvent, S3Event, DynamoDBStreamEvent, KinesisStreamEvent, EventBridgeEvent, CloudWatchLogsEvent, SESEvent, CloudFrontRequestEvent, FirehoseTransformationEvent, CognitoUserPoolTriggerEvent, Context } from 'aws-lambda';
|
|
12
|
+
import { stagesFactory } from '@/src/serverless/stagesFactory';
|
|
13
|
+
import { SecurityContextHttpEventMap as SecurityContextHttpEventMap$1 } from '@/src/types/SecurityContextHttpEventMap';
|
|
14
|
+
import { BaseEventTypeMap } from '@/src/core/baseEventTypeMapSchema';
|
|
15
|
+
import { EnvAttached } from '@/src/core/defineFunctionConfig';
|
|
16
|
+
import { Handler as Handler$1 } from '@/src/types/Handler';
|
|
17
|
+
import { MiddlewareObj } from '@middy/core';
|
|
18
|
+
import httpContentNegotiation from '@middy/http-content-negotiation';
|
|
19
|
+
import httpCors from '@middy/http-cors';
|
|
20
|
+
import httpErrorHandler from '@middy/http-error-handler';
|
|
21
|
+
import httpHeaderNormalizer from '@middy/http-header-normalizer';
|
|
22
|
+
import httpJsonBodyParser from '@middy/http-json-body-parser';
|
|
23
|
+
import { HttpTransform, PhasedArrays } from '@/src/http/middleware/transformUtils';
|
|
24
|
+
import { ConsoleLogger as ConsoleLogger$1 } from '@/src/types/Loggable';
|
|
25
|
+
import { DeepOverride } from '@/src/types/DeepOverride';
|
|
26
|
+
import { PropFromUnion } from '@/src/types/PropFromUnion';
|
|
27
|
+
|
|
28
|
+
interface AppInit<GlobalParamsSchema extends ZodObj, StageParamsSchema extends ZodObj, EventTypeMapSchema extends ZodObj> {
|
|
29
|
+
appRootAbs: string;
|
|
30
|
+
globalParamsSchema: GlobalParamsSchema;
|
|
31
|
+
stageParamsSchema: StageParamsSchema;
|
|
32
|
+
eventTypeMapSchema?: EventTypeMapSchema;
|
|
33
|
+
/** Accept raw serverless config; App will parse it internally. */
|
|
34
|
+
serverless: z.input<typeof serverlessConfigSchema>;
|
|
35
|
+
global: {
|
|
36
|
+
params: z.infer<GlobalParamsSchema>;
|
|
37
|
+
envKeys: readonly (keyof z.infer<GlobalParamsSchema>)[];
|
|
38
|
+
};
|
|
39
|
+
stage: {
|
|
40
|
+
/** Accept raw stage param objects; App will parse with (global.partial + stage) */
|
|
41
|
+
params: Record<string, Record<string, unknown>>;
|
|
42
|
+
envKeys: readonly (keyof z.infer<StageParamsSchema>)[];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* HTTP tokens to treat as HTTP at runtime (widenable).
|
|
46
|
+
* Defaults to ['rest', 'http'].
|
|
47
|
+
*/
|
|
48
|
+
httpEventTypeTokens?: readonly (keyof z.infer<EventTypeMapSchema>)[];
|
|
49
|
+
/**
|
|
50
|
+
* Optional app-level HTTP middleware customization (defaults & profiles).
|
|
51
|
+
*/
|
|
52
|
+
http?: AppHttpConfig$1;
|
|
53
|
+
/** Optional defaults applied to every function (merged per registration). */
|
|
54
|
+
functionDefaults?: {
|
|
55
|
+
fnEnvKeys?: readonly string[];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Application class. *
|
|
60
|
+
* @typeParam GlobalParamsSchema - Zod object schema for global parameters
|
|
61
|
+
* @typeParam StageParamsSchema - Zod object schema for per‑stage parameters
|
|
62
|
+
* @typeParam EventTypeMapSchema - Zod object schema mapping event tokens to runtime types
|
|
63
|
+
*/ declare class App<GlobalParamsSchema extends ZodObj, StageParamsSchema extends ZodObj, EventTypeMapSchema extends ZodObj> {
|
|
64
|
+
/** Helper alias for stage artifacts type */
|
|
65
|
+
private static readonly _stageArtifactsType;
|
|
66
|
+
readonly appRootAbs: string;
|
|
67
|
+
readonly globalParamsSchema: GlobalParamsSchema;
|
|
68
|
+
readonly stageParamsSchema: StageParamsSchema;
|
|
69
|
+
readonly eventTypeMapSchema: EventTypeMapSchema;
|
|
70
|
+
readonly serverless: AppServerlessConfig;
|
|
71
|
+
readonly global: EnvSchemaNode$1<GlobalParamsSchema>;
|
|
72
|
+
readonly stage: EnvSchemaNode$1<StageParamsSchema>;
|
|
73
|
+
readonly stages: ReturnType<typeof buildStageArtifacts>['stages'];
|
|
74
|
+
readonly environment: ReturnType<typeof buildStageArtifacts>['environment'];
|
|
75
|
+
readonly buildFnEnv: ReturnType<typeof buildStageArtifacts>['buildFnEnv'];
|
|
76
|
+
readonly http: AppHttpConfig$1;
|
|
77
|
+
readonly httpEventTypeTokens: readonly string[];
|
|
78
|
+
private readonly registry;
|
|
79
|
+
private constructor(); /**
|
|
80
|
+
* Ergonomic constructor for schema‑first inference.
|
|
81
|
+
*
|
|
82
|
+
* @param init - initialization object (schemas, serverless defaults, params/envKeys)
|
|
83
|
+
* @returns a new App instance
|
|
84
|
+
*/
|
|
85
|
+
static create<GlobalParamsSchema extends ZodObj, StageParamsSchema extends ZodObj, EventTypeMapSchema extends ZodObj>(init: AppInit<GlobalParamsSchema, StageParamsSchema, EventTypeMapSchema>): App<GlobalParamsSchema, StageParamsSchema, EventTypeMapSchema>;
|
|
86
|
+
/**
|
|
87
|
+
* Register a function (HTTP or non‑HTTP).
|
|
88
|
+
*
|
|
89
|
+
* @typeParam EventType - A key from your eventTypeMapSchema (e.g., 'rest' | 'http' | 'sqs' | 'step')
|
|
90
|
+
* @typeParam EventSchema - Optional Zod schema validated BEFORE the handler (refines event shape)
|
|
91
|
+
* @typeParam ResponseSchema - Optional Zod schema validated AFTER the handler (refines response shape)
|
|
92
|
+
* @param options - per‑function configuration (method/basePath/httpContexts for HTTP; serverless extras for non‑HTTP)
|
|
93
|
+
* @returns a per‑function API: { handler(business), openapi(baseOperation), serverless(extras) }
|
|
94
|
+
*/
|
|
95
|
+
defineFunction<EventType extends Extract<keyof z.infer<EventTypeMapSchema>, string>, EventSchema extends z.ZodType | undefined, ResponseSchema extends z.ZodType | undefined>(options: {
|
|
96
|
+
functionName?: string;
|
|
97
|
+
eventType: EventType;
|
|
98
|
+
method?: MethodKey$1;
|
|
99
|
+
basePath?: string;
|
|
100
|
+
httpContexts?: readonly HttpContext$1[];
|
|
101
|
+
contentType?: string;
|
|
102
|
+
eventSchema?: EventSchema;
|
|
103
|
+
responseSchema?: ResponseSchema;
|
|
104
|
+
fnEnvKeys?: readonly (keyof (z.infer<GlobalParamsSchema> & z.infer<StageParamsSchema>))[];
|
|
105
|
+
callerModuleUrl: string;
|
|
106
|
+
endpointsRootAbs: string;
|
|
107
|
+
}): any;
|
|
108
|
+
/**
|
|
109
|
+
* Aggregate Serverless function definitions across the registry.
|
|
110
|
+
*
|
|
111
|
+
* @returns An AWS['functions'] object suitable for serverless.ts
|
|
112
|
+
*/
|
|
113
|
+
buildAllServerlessFunctions(): AWS['functions'];
|
|
114
|
+
/**
|
|
115
|
+
* Aggregate OpenAPI path items across the registry.
|
|
116
|
+
*
|
|
117
|
+
* @returns ZodOpenApiPathsObject to be embedded in a full OpenAPI document
|
|
118
|
+
*/
|
|
119
|
+
buildAllOpenApiPaths(): ZodOpenApiPathsObject;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* baseEventTypeMapSchema
|
|
124
|
+
* - Schema-first companion to BaseEventTypeMap.
|
|
125
|
+
* - Ensures z.infer<typeof baseEventTypeMapSchema> === BaseEventTypeMap.
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* Consumers typically extend this schema when creating an App to add
|
|
129
|
+
* project‑local event tokens (e.g., 'step').
|
|
130
|
+
* Only tokens listed in the app’s `httpEventTypeTokens` are treated as HTTP at runtime.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
declare const baseEventTypeMapSchema: z.ZodObject<{
|
|
134
|
+
rest: z.ZodCustom<APIGatewayProxyEvent, APIGatewayProxyEvent>;
|
|
135
|
+
http: z.ZodCustom<APIGatewayProxyEventV2, APIGatewayProxyEventV2>;
|
|
136
|
+
alb: z.ZodCustom<ALBEvent, ALBEvent>;
|
|
137
|
+
sqs: z.ZodCustom<SQSEvent, SQSEvent>;
|
|
138
|
+
sns: z.ZodCustom<SNSEvent, SNSEvent>;
|
|
139
|
+
s3: z.ZodCustom<S3Event, S3Event>;
|
|
140
|
+
dynamodb: z.ZodCustom<DynamoDBStreamEvent, DynamoDBStreamEvent>;
|
|
141
|
+
kinesis: z.ZodCustom<KinesisStreamEvent, KinesisStreamEvent>;
|
|
142
|
+
eventbridge: z.ZodCustom<EventBridgeEvent<string, unknown>, EventBridgeEvent<string, unknown>>;
|
|
143
|
+
'cloudwatch-logs': z.ZodCustom<CloudWatchLogsEvent, CloudWatchLogsEvent>;
|
|
144
|
+
ses: z.ZodCustom<SESEvent, SESEvent>;
|
|
145
|
+
cloudfront: z.ZodCustom<CloudFrontRequestEvent, CloudFrontRequestEvent>;
|
|
146
|
+
firehose: z.ZodCustom<FirehoseTransformationEvent, FirehoseTransformationEvent>;
|
|
147
|
+
'cognito-userpool': z.ZodCustom<CognitoUserPoolTriggerEvent, CognitoUserPoolTriggerEvent>;
|
|
148
|
+
}, z.core.$strip>;
|
|
149
|
+
|
|
150
|
+
/** Base: envKeys tied to a Zod schema’s inferred keys. */
|
|
151
|
+
/**
|
|
152
|
+
* Bind a list of environment keys to a schema’s inferred key space.
|
|
153
|
+
*
|
|
154
|
+
* @typeParam Schema - Zod object schema
|
|
155
|
+
* @remarks Used to express “these keys are allowed to be exposed from this schema”.
|
|
156
|
+
*/
|
|
157
|
+
interface EnvKeysNode<Schema extends ZodObject<ZodRawShape>> {
|
|
158
|
+
envKeys: readonly (keyof z.infer<Schema>)[];
|
|
159
|
+
}
|
|
160
|
+
/** For wrapper input: schema + envKeys. */
|
|
161
|
+
interface EnvSchemaNode<Schema extends ZodObject<ZodRawShape>> extends EnvKeysNode<Schema> {
|
|
162
|
+
paramsSchema: Schema;
|
|
163
|
+
}
|
|
164
|
+
/** Wrapper input: no glue; both global and stage sides. */
|
|
165
|
+
/**
|
|
166
|
+
* Environment configuration bounds for an application.
|
|
167
|
+
*
|
|
168
|
+
* @typeParam GlobalParamsSchema - Global params schema
|
|
169
|
+
* @typeParam StageParamsSchema - Per‑stage params schema
|
|
170
|
+
*/
|
|
171
|
+
interface GlobalEnvConfig<GlobalParamsSchema extends ZodObject<ZodRawShape>, StageParamsSchema extends ZodObject<ZodRawShape>> {
|
|
172
|
+
global: EnvSchemaNode<GlobalParamsSchema>;
|
|
173
|
+
stage: EnvSchemaNode<StageParamsSchema>;
|
|
174
|
+
}
|
|
175
|
+
/** Authoring input — global: concrete params + envKeys. */
|
|
176
|
+
/**
|
|
177
|
+
* Concrete global configuration for authoring (params + env exposure).
|
|
178
|
+
*
|
|
179
|
+
* @typeParam GlobalParamsSchema - Global params schema
|
|
180
|
+
* @remarks The App keeps this typed and uses it to generate provider.environment.
|
|
181
|
+
*/
|
|
182
|
+
interface GlobalParamsNode<GlobalParamsSchema extends ZodObject<ZodRawShape>> extends EnvKeysNode<GlobalParamsSchema> {
|
|
183
|
+
params: z.infer<GlobalParamsSchema>;
|
|
184
|
+
}
|
|
185
|
+
/** Authoring input — stage: per-stage params + envKeys. */
|
|
186
|
+
/**
|
|
187
|
+
* Concrete per‑stage configuration for authoring (params + env exposure).
|
|
188
|
+
*
|
|
189
|
+
* @typeParam StageParamsSchema - Per‑stage params schema
|
|
190
|
+
* @remarks The App composes stage with global (global.partial().extend(stage)).
|
|
191
|
+
*/
|
|
192
|
+
interface StageParamsNode<StageParamsSchema extends ZodObject<ZodRawShape>> extends EnvKeysNode<StageParamsSchema> {
|
|
193
|
+
params: Record<string, z.infer<StageParamsSchema>>;
|
|
194
|
+
}
|
|
195
|
+
/** Authoring input for unified app config (serverless + env). */
|
|
196
|
+
/**
|
|
197
|
+
* Authoring input for a complete, unified app configuration.
|
|
198
|
+
*
|
|
199
|
+
* @typeParam GlobalParamsSchema - Global params schema
|
|
200
|
+
* @typeParam StageParamsSchema - Per‑stage params schema
|
|
201
|
+
* @remarks Use with {@link defineAppConfig}.
|
|
202
|
+
*/
|
|
203
|
+
interface DefineAppConfigInput<GlobalParamsSchema extends ZodObject<ZodRawShape>, StageParamsSchema extends ZodObject<ZodRawShape>> {
|
|
204
|
+
serverless: {
|
|
205
|
+
defaultHandlerFileName: string;
|
|
206
|
+
defaultHandlerFileExport: string;
|
|
207
|
+
httpContextEventMap: SecurityContextHttpEventMap$1;
|
|
208
|
+
};
|
|
209
|
+
global: GlobalParamsNode<GlobalParamsSchema>;
|
|
210
|
+
stage: StageParamsNode<StageParamsSchema>;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Output of {@link defineAppConfig}.
|
|
214
|
+
*
|
|
215
|
+
* Carries serverless defaults, stage artifacts, and typed env nodes suitable
|
|
216
|
+
* for passing directly to SMOZ wrappers.
|
|
217
|
+
*/
|
|
218
|
+
interface DefineAppConfigOutput<GlobalParamsSchema extends ZodObject<ZodRawShape>, StageParamsSchema extends ZodObject<ZodRawShape>> extends GlobalEnvConfig<GlobalParamsSchema, StageParamsSchema> {
|
|
219
|
+
serverless: DefineAppConfigInput<GlobalParamsSchema, StageParamsSchema>['serverless'];
|
|
220
|
+
stages: ReturnType<typeof stagesFactory>['stages'];
|
|
221
|
+
environment: ReturnType<typeof stagesFactory>['environment'];
|
|
222
|
+
buildFnEnv: ReturnType<typeof stagesFactory>['buildFnEnv'];
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Define a complete application configuration from schemas and authoring input.
|
|
226
|
+
*
|
|
227
|
+
* @typeParam GlobalParamsSchema - Global params schema
|
|
228
|
+
* @typeParam StageParamsSchema - Per‑stage params schema
|
|
229
|
+
* @param globalParamsSchema - schema for global params
|
|
230
|
+
* @param stageParamsSchema - schema for stage params
|
|
231
|
+
* @param input - serverless defaults and concrete params + env exposure
|
|
232
|
+
* @returns Typed configuration nodes and stage artifacts
|
|
233
|
+
* * @throws Error if envKeys include keys not present in their corresponding schema
|
|
234
|
+
*/
|
|
235
|
+
declare function defineAppConfig<GlobalParamsSchema extends ZodObject<ZodRawShape>, StageParamsSchema extends ZodObject<ZodRawShape>>(globalParamsSchema: GlobalParamsSchema, stageParamsSchema: StageParamsSchema, input: DefineAppConfigInput<GlobalParamsSchema, StageParamsSchema>): DefineAppConfigOutput<GlobalParamsSchema, StageParamsSchema>;
|
|
236
|
+
|
|
237
|
+
/** Classify the security context from either API Gateway event version. */
|
|
238
|
+
/**
|
|
239
|
+
* Detect security context from API Gateway v1/v2 events.
|
|
240
|
+
*
|
|
241
|
+
* @param evt - unknown event
|
|
242
|
+
* @returns 'my' when authorized (Cognito/JWT/IAM), 'private' when API key present, else 'public'
|
|
243
|
+
*/
|
|
244
|
+
declare const detectSecurityContext: (evt: unknown) => HttpContext$1;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Wrap a business handler with SMOZ runtime. *
|
|
248
|
+
* - HTTP event tokens receive the full Middy pipeline (validation, shaping, CORS, etc.)
|
|
249
|
+
* - Non‑HTTP tokens bypass Middy and call the business function directly.
|
|
250
|
+
*
|
|
251
|
+
* @typeParam GlobalParamsSchema - global params schema type
|
|
252
|
+
* @typeParam StageParamsSchema - stage params schema type
|
|
253
|
+
* @typeParam EventTypeMap - event token → runtime type map
|
|
254
|
+
* @typeParam EventType - a key of EventTypeMap
|
|
255
|
+
* @typeParam EventSchema - optional Zod schema for event (validated before handler)
|
|
256
|
+
* @typeParam ResponseSchema - optional Zod schema for response (validated after handler)
|
|
257
|
+
* @param functionConfig - per‑function configuration (branded with env nodes)
|
|
258
|
+
* @param business - the business handler implementation
|
|
259
|
+
* @param opts - optional runtime overrides (e.g., widen HTTP tokens)
|
|
260
|
+
* @returns a Lambda‑compatible handler function
|
|
261
|
+
*/
|
|
262
|
+
declare function wrapHandler<GlobalParamsSchema extends ZodObject<ZodRawShape>, StageParamsSchema extends ZodObject<ZodRawShape>, EventTypeMap extends BaseEventTypeMap, EventType extends keyof EventTypeMap, EventSchema extends z.ZodType | undefined, ResponseSchema extends z.ZodType | undefined>(functionConfig: FunctionConfig<EventSchema, ResponseSchema, z.infer<GlobalParamsSchema>, z.infer<StageParamsSchema>, EventTypeMap, EventType> & EnvAttached<GlobalParamsSchema, StageParamsSchema>, business: Handler$1<EventSchema, ResponseSchema, EventTypeMap[EventType]>, opts?: {
|
|
263
|
+
httpEventTypeTokens?: readonly string[];
|
|
264
|
+
httpConfig?: AppHttpConfig$1;
|
|
265
|
+
}): (event: unknown, context: Context) => Promise<any>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* HTTP customization types and aliases.
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
type ApiMiddleware$1 = MiddlewareObj<APIGatewayProxyEvent, Context>;
|
|
272
|
+
type HttpStackOptions = {
|
|
273
|
+
contentType?: string;
|
|
274
|
+
logger?: ConsoleLogger$1;
|
|
275
|
+
contentNegotiation?: Parameters<typeof httpContentNegotiation>[0];
|
|
276
|
+
cors?: Parameters<typeof httpCors>[0];
|
|
277
|
+
errorHandler?: Parameters<typeof httpErrorHandler>[0];
|
|
278
|
+
serializer?: {
|
|
279
|
+
json?: {
|
|
280
|
+
label?: string;
|
|
281
|
+
stringify?: (value: unknown) => string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
jsonBodyParser?: Parameters<typeof httpJsonBodyParser>[0];
|
|
285
|
+
headerNormalizer?: Parameters<typeof httpHeaderNormalizer>[0];
|
|
286
|
+
};
|
|
287
|
+
type Extend = {
|
|
288
|
+
before?: ApiMiddleware$1[];
|
|
289
|
+
after?: ApiMiddleware$1[];
|
|
290
|
+
onError?: ApiMiddleware$1[];
|
|
291
|
+
};
|
|
292
|
+
type HttpProfile = HttpStackOptions & {
|
|
293
|
+
extend?: Extend;
|
|
294
|
+
transform?: HttpTransform;
|
|
295
|
+
};
|
|
296
|
+
type AppHttpConfig = {
|
|
297
|
+
defaults?: HttpStackOptions & {
|
|
298
|
+
extend?: Extend;
|
|
299
|
+
transform?: HttpTransform;
|
|
300
|
+
};
|
|
301
|
+
profiles?: Record<string, HttpProfile>;
|
|
302
|
+
};
|
|
303
|
+
type FunctionHttpConfig = {
|
|
304
|
+
profile?: string;
|
|
305
|
+
options?: Partial<HttpStackOptions>;
|
|
306
|
+
extend?: Extend;
|
|
307
|
+
transform?: HttpTransform;
|
|
308
|
+
replace?: {
|
|
309
|
+
stack: MiddlewareObj | PhasedArrays;
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
type M = ApiMiddleware$1;
|
|
314
|
+
declare const buildDefaultPhases: (args: {
|
|
315
|
+
contentType: string;
|
|
316
|
+
logger: ConsoleLogger$1;
|
|
317
|
+
opts?: HttpStackOptions;
|
|
318
|
+
eventSchema?: z.ZodType | undefined;
|
|
319
|
+
responseSchema?: z.ZodType | undefined;
|
|
320
|
+
}) => {
|
|
321
|
+
before: M[];
|
|
322
|
+
after: M[];
|
|
323
|
+
onError: M[];
|
|
324
|
+
};
|
|
325
|
+
/** Public helper: build default phases suitable for replace scenarios. */
|
|
326
|
+
type BuildSafeDefaultsArgs = Parameters<typeof buildDefaultPhases>[0];
|
|
327
|
+
declare const buildSafeDefaults: (args: BuildSafeDefaultsArgs) => {
|
|
328
|
+
before: M[];
|
|
329
|
+
after: M[];
|
|
330
|
+
onError: M[];
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Transform helpers for HTTP middleware stacks.
|
|
335
|
+
*
|
|
336
|
+
* - Steps are identified by a non-enumerable __id property on MiddlewareObj.
|
|
337
|
+
* - Utilities operate on arrays immutably and return new arrays.
|
|
338
|
+
* * Requirements addressed:
|
|
339
|
+
* - insertBefore, insertAfter, replaceStep, removeStep, findIndex, getId
|
|
340
|
+
*/
|
|
341
|
+
|
|
342
|
+
type ApiMiddleware = MiddlewareObj<APIGatewayProxyEvent, Context>;
|
|
343
|
+
type StepId = 'head' | 'header-normalizer' | 'event-normalizer' | 'content-negotiation' | 'json-body-parser' | 'zod-before' | 'head-finalize' | 'zod-after' | 'error-expose' | 'error-handler' | 'cors' | 'preferred-media' | 'shape' | 'serializer';
|
|
344
|
+
/** Attach a non-enumerable __id to a middleware step. */
|
|
345
|
+
declare const tagStep: (mw: ApiMiddleware, id: StepId) => ApiMiddleware;
|
|
346
|
+
/** Retrieve a step's id, if present. */
|
|
347
|
+
declare const getId: (mw: ApiMiddleware) => StepId | undefined;
|
|
348
|
+
/** Find index of a step by id. */
|
|
349
|
+
declare const findIndex: (list: ApiMiddleware[], id: StepId) => number;
|
|
350
|
+
/** Insert a step before the step with given id. */
|
|
351
|
+
declare const insertBefore: (list: ApiMiddleware[], id: StepId, mw: ApiMiddleware) => ApiMiddleware[];
|
|
352
|
+
/** Insert a step after the step with given id. */
|
|
353
|
+
declare const insertAfter: (list: ApiMiddleware[], id: StepId, mw: ApiMiddleware) => ApiMiddleware[];
|
|
354
|
+
/** Replace a step with given id. */
|
|
355
|
+
declare const replaceStep: (list: ApiMiddleware[], id: StepId, mw: ApiMiddleware) => ApiMiddleware[];
|
|
356
|
+
/** Remove a step with given id. */
|
|
357
|
+
declare const removeStep: (list: ApiMiddleware[], id: StepId) => ApiMiddleware[];
|
|
358
|
+
|
|
359
|
+
/** HTTP methods supported from zod-openapi's PathItem shape (excluding helper 'id'). */
|
|
360
|
+
type MethodKey = keyof Omit<ZodOpenApiPathItemObject, 'id'>;
|
|
361
|
+
|
|
362
|
+
/** Event type after applying deep schema overrides. */
|
|
363
|
+
/**
|
|
364
|
+
* Compute the event type as seen by a business handler after Zod overrides.
|
|
365
|
+
*/
|
|
366
|
+
type ShapedEvent<EventSchema extends z.ZodType | undefined, EventType> = EventSchema extends z.ZodType ? DeepOverride<EventType, z.infer<EventSchema>> : EventType;
|
|
367
|
+
/** Handler options shared across invocation modes. */
|
|
368
|
+
type HandlerOptions = {
|
|
369
|
+
env: Record<string, unknown>;
|
|
370
|
+
/** Present only for HTTP calls; omitted for SQS/Step/etc. */
|
|
371
|
+
securityContext?: unknown;
|
|
372
|
+
/** REQUIRED and must satisfy ConsoleLogger. */
|
|
373
|
+
logger: ConsoleLogger$1;
|
|
374
|
+
};
|
|
375
|
+
/** Business handler: returns raw payloads; wrapping layers handle HTTP shaping when applicable. */
|
|
376
|
+
/**
|
|
377
|
+
* Business handler signature used by SMOZ.
|
|
378
|
+
*
|
|
379
|
+
* @returns the raw payload; the wrapper applies HTTP shaping when applicable.
|
|
380
|
+
*/
|
|
381
|
+
type Handler<EventSchema extends z.ZodType | undefined, ResponseSchema extends z.ZodType | undefined, EventType> = (event: ShapedEvent<EventSchema, EventType>, context: Context, options: HandlerOptions) => Promise<ResponseSchema extends z.ZodType ? z.infer<ResponseSchema> : unknown>;
|
|
382
|
+
|
|
383
|
+
/** Security context classification used throughout the handlers. */
|
|
384
|
+
/**
|
|
385
|
+
* HTTP security context tokens.
|
|
386
|
+
*/
|
|
387
|
+
type HttpContext = 'my' | 'private' | 'public';
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* REQUIREMENTS ADDRESSED
|
|
391
|
+
* - Provide a minimal generic Lambda event shape that is compatible with
|
|
392
|
+
* common authoring patterns. Zod schemas will refine this via deep override.
|
|
393
|
+
*
|
|
394
|
+
* @remarks
|
|
395
|
+
* Used for internal/non‑HTTP flows when a narrow event type is not desirable.
|
|
396
|
+
*/
|
|
397
|
+
type LambdaEvent = Record<string, unknown>;
|
|
398
|
+
|
|
399
|
+
type ConsoleLogger = Pick<Console, 'debug' | 'error' | 'info' | 'log'>;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Opaque Serverless event fragments keyed by security context.
|
|
403
|
+
*
|
|
404
|
+
* @remarks
|
|
405
|
+
* Shape is intentionally platform‑specific; used by the App to decorate
|
|
406
|
+
* generated HTTP events based on 'my' | 'private' | 'public' contexts.
|
|
407
|
+
*/
|
|
408
|
+
type SecurityContextHttpEventMap = Record<HttpContext$1, Partial<PropFromUnion<PropFromUnion<PropFromUnion<AWS['functions'], string>['events'], number>, 'http'>>>;
|
|
409
|
+
|
|
410
|
+
/** Normalize a path to POSIX separators. */
|
|
411
|
+
declare const toPosixPath: (p: string) => string;
|
|
412
|
+
/**
|
|
413
|
+
* Resolve a directory path relative to the current module URL and normalize it.
|
|
414
|
+
*
|
|
415
|
+
* @param metaUrl - typically import.meta.url
|
|
416
|
+
* @param levelsUp - how many directory levels to ascend (default: 1)
|
|
417
|
+
* @returns absolute, POSIX-normalized directory path
|
|
418
|
+
*/
|
|
419
|
+
declare const dirFromHere: (metaUrl: string, levelsUp?: number) => string;
|
|
420
|
+
|
|
421
|
+
export { App, baseEventTypeMapSchema, buildSafeDefaults, defineAppConfig, detectSecurityContext, dirFromHere, findIndex, getId, insertAfter, insertBefore, removeStep, replaceStep, tagStep, toPosixPath, wrapHandler };
|
|
422
|
+
export type { AppHttpConfig, AppInit, ConsoleLogger, DefineAppConfigInput, DefineAppConfigOutput, EnvKeysNode, EnvSchemaNode, FunctionHttpConfig, GlobalEnvConfig, GlobalParamsNode, Handler, HandlerOptions, HttpContext, HttpProfile, HttpStackOptions, LambdaEvent, MethodKey, SecurityContextHttpEventMap, ShapedEvent, StageParamsNode };
|