@karmaniverous/smoz 0.2.9 → 0.2.11

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 CHANGED
@@ -1,28 +1,28 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2025, Jason Williscroft
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Jason Williscroft
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,81 +1,82 @@
1
- <div align="center">
2
-
3
- # SMOZ
4
-
5
- [Serverless](https://www.serverless.com/) · [Middy](https://middy.js.org/) · [OpenAPI 3.1](https://spec.openapis.org/oas/latest.html) · [Zod](https://zod.dev/)
6
-
7
- [![npm version](https://img.shields.io/npm/v/@karmaniverous/smoz.svg)](https://www.npmjs.com/package/@karmaniverous/smoz)
8
- ![Node Current](https://img.shields.io/node/v/@karmaniverous/smoz)
9
- [![docs](https://img.shields.io/badge/docs-website-blue)](https://docs.karmanivero.us/smoz)
10
- [![changelog](https://img.shields.io/badge/changelog-latest-blue.svg)](https://github.com/karmaniverous/smoz/tree/main/CHANGELOG.md)
11
- [![license](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://github.com/karmaniverous/smoz/tree/main/LICENSE.md)
12
-
13
- </div>
14
-
15
- SMOZ is a small, pragmatic toolkit for authoring AWS Lambda handlers with [Middy] and [Zod], then aggregating Serverless functions and hand‑crafted OpenAPI 3.1 paths from a single, schema‑first application definition.
16
-
17
- - Keep prod code testable and framework‑agnostic
18
- - HTTP middleware with validation, shaping, errors, CORS, negotiation, and HEAD
19
- - Non‑HTTP flows stay lean (no middleware overhead)
20
-
21
- ## Quick start (from zero)
22
-
23
- From an empty directory:
24
-
25
- ```bash
26
- npx @karmaniverous/smoz init -i
27
- npx smoz dev -p 3000
28
- ```
29
-
30
- - The first command scaffolds a new app and installs dependencies (including a local `smoz` bin).
31
- - The second command starts the inline local backend and keeps registers + OpenAPI fresh.
32
- - Open http://localhost:3000/openapi in your browser.
33
-
34
- Prefer `serverless‑offline`?
35
-
36
- ```bash
37
- npx smoz dev -l offline -p 3000
38
- ```
39
-
40
- Add your first endpoint (avoid clashing with the template’s hello):
41
-
42
- ```bash
43
- npx smoz add rest/foo/get
44
- ```
45
-
46
- ## Quick links
47
-
48
- - [Overview](https://docs.karmanivero.us/smoz/documents/Overview.html)
49
- - [Why smoz?](https://docs.karmanivero.us/smoz/documents/Why_smoz_.html)
50
- - [Getting started](https://docs.karmanivero.us/smoz/documents/Getting_started.html)
51
- - [10-minute tour](https://docs.karmanivero.us/smoz/documents/10%E2%80%91minute_tour.html)
52
- - [HTTP Middleware](https://docs.karmanivero.us/smoz/documents/HTTP_middleware.html)
53
- - [Recipes](https://docs.karmanivero.us/smoz/documents/Recipes.html)
54
- - [SQS function](https://docs.karmanivero.us/smoz/documents/Recipes.SQS_function.html)
55
- - [Contexts + Cognito authorizer](https://docs.karmanivero.us/smoz/documents/Recipes.Contexts_+_Cognito_authorizer.html) - [Custom middleware insertion](https://docs.karmanivero.us/smoz/documents/Recipes.Custom_middleware_insertion.html)
56
- - [Per‑function env](<https://docs.karmanivero.us/smoz/documents/Recipes.Per%E2%80%91function_env_(fnEnvKeys).html>)
57
- - [Observability](<https://docs.karmanivero.us/smoz/documents/Recipes.Observability_(requestId_header).html>)
58
- - [Troubleshooting](https://docs.karmanivero.us/smoz/documents/Recipes.Troubleshooting.html)
59
- - [Templates](https://docs.karmanivero.us/smoz/documents/Templates.html)
60
- - [CLI](https://docs.karmanivero.us/smoz/documents/CLI.html)
61
- - [Contributing](https://docs.karmanivero.us/smoz/documents/Contributing.html)
62
-
63
- ## Install
64
-
65
- ```bash
66
- npm i @karmaniverous/smoz zod zod-openapi
67
- ```
68
-
69
- ## Dev tooling (recommended):
70
-
71
- ```bash
72
- npm i -D typescript typescript-eslint eslint prettier typedoc
73
- ```
74
-
75
- ## Docs and reference
76
-
77
- - [Docs site](https://docs.karmanivero.us/smoz)
78
- - [Changelog](https://github.com/karmaniverous/smoz/tree/main/CHANGELOG.md)
79
- - [License](https://github.com/karmaniverous/smoz/tree/main/LICENSE.md)
80
- - [Middy](https://middy.js.org/)
81
- - [Zod](https://zod.dev/)
1
+ <div align="center">
2
+
3
+ # SMOZ
4
+
5
+ [Serverless](https://www.serverless.com/) · [Middy](https://middy.js.org/) · [OpenAPI 3.1](https://spec.openapis.org/oas/latest.html) · [Zod](https://zod.dev/)
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@karmaniverous/smoz.svg)](https://www.npmjs.com/package/@karmaniverous/smoz)
8
+ ![Node Current](https://img.shields.io/node/v/@karmaniverous/smoz)
9
+ [![docs](https://img.shields.io/badge/docs-website-blue)](https://docs.karmanivero.us/smoz)
10
+ [![changelog](https://img.shields.io/badge/changelog-latest-blue.svg)](https://github.com/karmaniverous/smoz/tree/main/CHANGELOG.md)
11
+ [![license](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://github.com/karmaniverous/smoz/tree/main/LICENSE.md)
12
+
13
+ </div>
14
+
15
+ SMOZ is a small, pragmatic toolkit for authoring AWS Lambda handlers with [Middy] and [Zod], then aggregating Serverless functions and hand‑crafted OpenAPI 3.1 paths from a single, schema‑first application definition.
16
+
17
+ - Keep prod code testable and framework‑agnostic
18
+ - HTTP middleware with validation, shaping, errors, CORS, negotiation, and HEAD
19
+ - Non‑HTTP flows stay lean (no middleware overhead)
20
+
21
+ ## Quick start (from zero)
22
+
23
+ From an empty directory:
24
+
25
+ ```bash
26
+ npx @karmaniverous/smoz init -i
27
+ npx smoz dev -p 3000
28
+ ```
29
+
30
+ - The first command scaffolds a new app and installs dependencies (including a local `smoz` bin).
31
+ - The second command starts the inline local backend and keeps registers + OpenAPI fresh.
32
+ - Open http://localhost:3000/openapi in your browser.
33
+
34
+ Prefer `serverless‑offline`?
35
+
36
+ ```bash
37
+ npx smoz dev -l offline -p 3000
38
+ ```
39
+
40
+ Add your first endpoint (avoid clashing with the template’s hello):
41
+
42
+ ```bash
43
+ npx smoz add rest/foo/get
44
+ ```
45
+
46
+ ## Quick links
47
+
48
+ - [Overview](./docs-src/overview.md)
49
+ - [Why smoz?](./docs-src/why-smoz.md)
50
+ - [Getting started](./docs-src/getting-started.md)
51
+ - [10-minute tour](./docs-src/tour-10-minutes.md)
52
+ - [HTTP Middleware](https://docs.karmanivero.us/smoz/documents/HTTP_middleware.html)
53
+ - [Recipes](./docs-src/recipes/index.md)
54
+ - [SQS function](./docs-src/recipes/sqs.md)
55
+ - [Step Functions function](./docs-src/recipes/step.md)
56
+ - [Contexts + Cognito authorizer](./docs-src/recipes/contexts-auth.md) - [Custom middleware insertion](./docs-src/recipes/custom-middleware.md)
57
+ - [Per‑function env](./docs-src/recipes/per-function-env.md)
58
+ - [Observability](./docs-src/recipes/observability.md)
59
+ - [Troubleshooting](./docs-src/recipes/troubleshooting.md)
60
+ - [Templates](./docs-src/templates.md)
61
+ - [CLI](./docs-src/cli.md)
62
+ - [Contributing](./CONTRIBUTING.md)
63
+
64
+ ## Install
65
+
66
+ ```bash
67
+ npm i @karmaniverous/smoz zod zod-openapi
68
+ ```
69
+
70
+ ## Dev tooling (recommended):
71
+
72
+ ```bash
73
+ npm i -D typescript typescript-eslint eslint prettier typedoc
74
+ ```
75
+
76
+ ## Docs and reference
77
+
78
+ - [Docs site](https://docs.karmanivero.us/smoz)
79
+ - [Changelog](./CHANGELOG.md)
80
+ - [License](LICENSE)
81
+ - [Middy](https://middy.js.org/)
82
+ - [Zod](https://zod.dev/)
package/dist/cjs/index.js CHANGED
@@ -30,12 +30,23 @@ const baseEventTypeMapSchema = zod.z.object({
30
30
  firehose: zod.z.custom(),
31
31
  // eslint-disable-next-line @typescript-eslint/no-deprecated -- Upstream AWS types mark this as deprecated; we retain the token for compatibility with existing apps.
32
32
  'cognito-userpool': zod.z.custom(),
33
+ /**
34
+ * Step Functions → Lambda (Service Integration: Lambda Invoke)
35
+ *
36
+ * When Step Functions invokes Lambda via the AWS SDK integration
37
+ * (e.g., "arn:aws:states:::lambda:invoke"), the event received by the
38
+ * Lambda handler is an object that wraps the original input under a
39
+ * "Payload" key. The Payload is already parsed JSON.
40
+ *
41
+ * Notes:
42
+ * - We accept additional keys (e.g., StatusCode/ExecutedVersion in some
43
+ * patterns) via passthrough.
44
+ * - For the common “request/response” integration where Step Functions
45
+ * passes state directly, apps can still treat the event via their
46
+ * own app-local event map if needed.
47
+ */
48
+ step: zod.z.object({ Payload: zod.z.unknown().optional() }).catchall(zod.z.unknown()),
33
49
  });
34
- // Notes:
35
- // - This list intentionally includes widely used, generic AWS events.
36
- // - Apps can extend the schema with custom or specialized tokens:
37
- // const EventMap = baseEventTypeMapSchema.extend({ step: z.custom<MyStepEvent>() })
38
- // - Only tokens listed in your App's httpEventTypeTokens are treated as HTTP by the runtime.
39
50
 
40
51
  /**
41
52
  * Stage artifacts factory.
@@ -1043,10 +1054,10 @@ const buildAllServerlessFunctions = (registry, serverless, buildFnEnv) => {
1043
1054
  /**
1044
1055
  * App (schema‑first)
1045
1056
  *
1057
+ * Overloads on create() preserve strong inference when eventTypeMapSchema is omitted.
1046
1058
  * Central orchestrator for a SMOZ application. You provide:
1047
1059
  * - Global/stage parameter schemas and env exposure keys
1048
- * - Serverless defaults (handler filename/export and context map)
1049
- * - Event‑type map schema (extendable: e.g., add 'step')
1060
+ * - Serverless defaults (handler filename/export and context map) * - Event‑type map schema (extendable: e.g., add 'step')
1050
1061
  *
1051
1062
  * The instance:
1052
1063
  * - Validates configuration
@@ -1130,6 +1141,7 @@ const buildAllServerlessFunctions = (registry, serverless, buildFnEnv) => {
1130
1141
  * @param init - initialization object (schemas, serverless defaults, params/envKeys)
1131
1142
  * @returns a new App instance
1132
1143
  */
1144
+ // Implementation (must come after overload signatures)
1133
1145
  static create(init) {
1134
1146
  return new App(init);
1135
1147
  }
@@ -1137,9 +1149,7 @@ const buildAllServerlessFunctions = (registry, serverless, buildFnEnv) => {
1137
1149
  * Register a function (HTTP or non‑HTTP).
1138
1150
  *
1139
1151
  * @typeParam EventType - A key from your eventTypeMapSchema (e.g., 'rest' | 'http' | 'sqs' | 'step')
1140
- * @typeParam EventSchema - Optional Zod schema validated BEFORE the handler (refines event shape)
1141
- * @typeParam ResponseSchema - Optional Zod schema validated AFTER the handler (refines response shape)
1142
- * @param options - per‑function configuration (method/basePath/httpContexts for HTTP; serverless extras for non‑HTTP)
1152
+ * @typeParam EventSchema - Optional Zod schema validated BEFORE the handler (refines event shape) * @typeParam ResponseSchema - Optional Zod schema validated AFTER the handler (refines response shape) * @param options - per‑function configuration (method/basePath/httpContexts for HTTP; serverless extras for non‑HTTP)
1143
1153
  * @returns a per‑function API: { handler(business), openapi(baseOperation), serverless(extras) }
1144
1154
  */
1145
1155
  defineFunction(options) {