@rotorsoft/act-http 1.3.0 → 1.4.0
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/README.md +48 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/hono/index.d.ts +109 -0
- package/dist/@types/hono/index.d.ts.map +1 -0
- package/dist/hono/index.cjs +192 -0
- package/dist/hono/index.cjs.map +1 -0
- package/dist/hono/index.js +116 -0
- package/dist/hono/index.js.map +1 -0
- package/package.json +9 -3
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Act, Actor, Schema, Schemas } from "@rotorsoft/act";
|
|
2
|
+
import type { IdempotencyStore } from "@rotorsoft/act-ops/idempotency";
|
|
3
|
+
import type { Context, MiddlewareHandler } from "hono";
|
|
4
|
+
import { Hono } from "hono";
|
|
5
|
+
import { type ActorExtractor } from "../api/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Hono context variables this subpath contributes. The generic on
|
|
8
|
+
* the returned middleware threads it through so routes downstream
|
|
9
|
+
* of {@link authenticated} see `c.get("actor")` typed without a
|
|
10
|
+
* manual cast.
|
|
11
|
+
*/
|
|
12
|
+
export type ActMiddlewareVariables = {
|
|
13
|
+
actor: Actor;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Per-call options for {@link hono}. The host supplies the four
|
|
17
|
+
* seams the package can't make decisions on:
|
|
18
|
+
*
|
|
19
|
+
* - `actor` — auth resolver. Receives the Hono context, returns the
|
|
20
|
+
* `Actor` that flows onto `c.get("actor")` for every generated
|
|
21
|
+
* route (via an internal {@link authenticated}).
|
|
22
|
+
* - `stream` — stream-id resolver. Receives the action name, the
|
|
23
|
+
* validated body, and the Hono context; returns the target
|
|
24
|
+
* stream. Singleton aggregates return a constant; per-tenant
|
|
25
|
+
* aggregates pull from headers, path, or body.
|
|
26
|
+
* - `expectedVersion` (optional) — optimistic-concurrency resolver.
|
|
27
|
+
* Hosts typically read it from an `If-Match` header on the
|
|
28
|
+
* request, or from the client's last-known snapshot. Returning
|
|
29
|
+
* `undefined` skips the check for that call — handy when only
|
|
30
|
+
* some actions are concurrency-sensitive.
|
|
31
|
+
* - `idempotency` (optional) — when set, the route honors
|
|
32
|
+
* `Idempotency-Key` via {@link withIdempotency}. The host
|
|
33
|
+
* supplies the `IdempotencyStore`; `keyFrom` defaults to reading
|
|
34
|
+
* the `Idempotency-Key` header. On a duplicate claim, the route
|
|
35
|
+
* responds `409 Conflict` — the contract intentionally doesn't
|
|
36
|
+
* cache the original handler's result, matching the
|
|
37
|
+
* receiver-side "ack the duplicate" semantics.
|
|
38
|
+
* - `basePath` (optional, default `"/api"`) — Hono basePath the
|
|
39
|
+
* routes mount under.
|
|
40
|
+
*/
|
|
41
|
+
export type HonoOptions = {
|
|
42
|
+
readonly actor: ActorExtractor;
|
|
43
|
+
readonly stream: (action_name: string, input: unknown, c: Context) => string | Promise<string>;
|
|
44
|
+
readonly expectedVersion?: (action_name: string, input: unknown, c: Context) => number | undefined | Promise<number | undefined>;
|
|
45
|
+
readonly idempotency?: {
|
|
46
|
+
readonly store: IdempotencyStore;
|
|
47
|
+
readonly keyFrom?: (c: Context) => string | undefined;
|
|
48
|
+
};
|
|
49
|
+
readonly basePath?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Build a Hono middleware that runs an {@link ActorExtractor} once
|
|
53
|
+
* per call and stashes the resolved {@link Actor} under
|
|
54
|
+
* `c.set("actor", ...)` so downstream routes can read it via
|
|
55
|
+
* `c.get("actor")`. The generator at {@link hono} uses this
|
|
56
|
+
* internally; it's also exported so hosts that want to compose
|
|
57
|
+
* their own route chain (logging, tracing, custom auth flavors)
|
|
58
|
+
* can wire it directly:
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { Hono } from "hono";
|
|
62
|
+
* import { authenticated, type ActMiddlewareVariables } from "@rotorsoft/act-http/hono";
|
|
63
|
+
*
|
|
64
|
+
* const api = new Hono<{ Variables: ActMiddlewareVariables }>();
|
|
65
|
+
* api.use("*", authenticated((c) => resolveUserFromJwt(c)));
|
|
66
|
+
* api.get("/me", (c) => c.json(c.get("actor"))); // typed
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* Errors thrown by the extractor surface as `401 Unauthorized` with
|
|
70
|
+
* the shared {@link ApiError} envelope.
|
|
71
|
+
*/
|
|
72
|
+
export declare function authenticated(extractor: ActorExtractor): MiddlewareHandler<{
|
|
73
|
+
Variables: ActMiddlewareVariables;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Build a typed Hono REST surface from a built `Act` instance.
|
|
77
|
+
*
|
|
78
|
+
* Walks `app.registry.actions` once and emits one
|
|
79
|
+
* `POST /actions/<actionName>` per action under the configured
|
|
80
|
+
* `basePath` (default `/api`). Each route:
|
|
81
|
+
*
|
|
82
|
+
* 1. Runs the internal {@link authenticated} middleware —
|
|
83
|
+
* `options.actor` resolves the {@link Actor} once and stashes
|
|
84
|
+
* it under `c.get("actor")`.
|
|
85
|
+
* 2. Validates the JSON body against the action's Zod schema via
|
|
86
|
+
* `@hono/zod-validator`. Failures short-circuit with `422`.
|
|
87
|
+
* 3. Resolves the target stream via
|
|
88
|
+
* `options.stream(name, input, c)`.
|
|
89
|
+
* 4. (Optionally) resolves `expectedVersion` for optimistic
|
|
90
|
+
* concurrency.
|
|
91
|
+
* 5. (Optionally) claims the `Idempotency-Key` via
|
|
92
|
+
* {@link withIdempotency} — responds `409` on duplicate.
|
|
93
|
+
* 6. Calls
|
|
94
|
+
* `app.do(name, { stream, actor, expectedVersion? }, input)`.
|
|
95
|
+
* 7. Maps any thrown framework error onto the shared
|
|
96
|
+
* {@link ApiError} envelope via {@link toApiError}, returning
|
|
97
|
+
* the conventional HTTP status (`409` / `412` for concurrency,
|
|
98
|
+
* `422` for validation, `400` for non-retryable, etc.).
|
|
99
|
+
*
|
|
100
|
+
* @param app A built `Act` orchestrator.
|
|
101
|
+
* @param options Auth, stream, expected-version, idempotency, and
|
|
102
|
+
* base-path seams.
|
|
103
|
+
* @returns A Hono app covering every registered action under
|
|
104
|
+
* `<basePath>/actions/<name>`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function hono(app: Act<Schemas, Schemas, Schemas, Record<string, Schema>>, options: HonoOptions): Hono<{
|
|
107
|
+
Variables: ActMiddlewareVariables;
|
|
108
|
+
}>;
|
|
109
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hono/index.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,iBAAiB,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,CACf,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,OAAO,EACd,CAAC,EAAE,OAAO,KACP,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,eAAe,CAAC,EAAE,CACzB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,OAAO,EACd,CAAC,EAAE,OAAO,KACP,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACtD,QAAQ,CAAC,WAAW,CAAC,EAAE;QACrB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;QACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;KACvD,CAAC;IACF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,cAAc,GACxB,iBAAiB,CAAC;IAAE,SAAS,EAAE,sBAAsB,CAAA;CAAE,CAAC,CAe1D;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,IAAI,CAClB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC3D,OAAO,EAAE,WAAW,GACnB,IAAI,CAAC;IAAE,SAAS,EAAE,sBAAsB,CAAA;CAAE,CAAC,CAyE7C"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/hono/index.ts
|
|
21
|
+
var hono_exports = {};
|
|
22
|
+
__export(hono_exports, {
|
|
23
|
+
authenticated: () => authenticated,
|
|
24
|
+
hono: () => hono
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(hono_exports);
|
|
27
|
+
|
|
28
|
+
// ../../node_modules/.pnpm/@hono+zod-validator@0.8.0_hono@4.12.23_zod@4.4.3/node_modules/@hono/zod-validator/dist/index.js
|
|
29
|
+
var import_validator = require("hono/validator");
|
|
30
|
+
function zValidatorFunction(target, schema, hook, options) {
|
|
31
|
+
return (0, import_validator.validator)(target, async (value, c) => {
|
|
32
|
+
let validatorValue = value;
|
|
33
|
+
if (target === "header" && "_def" in schema || target === "header" && "_zod" in schema) {
|
|
34
|
+
const schemaKeys = Object.keys("in" in schema ? schema.in.shape : schema.shape);
|
|
35
|
+
const caseInsensitiveKeymap = Object.fromEntries(schemaKeys.map((key) => [key.toLowerCase(), key]));
|
|
36
|
+
validatorValue = Object.fromEntries(Object.entries(value).map(([key, value$1]) => [caseInsensitiveKeymap[key] || key, value$1]));
|
|
37
|
+
}
|
|
38
|
+
const result = options && options.validationFunction ? await options.validationFunction(schema, validatorValue) : await schema.safeParseAsync(validatorValue);
|
|
39
|
+
if (hook) {
|
|
40
|
+
const hookResult = await hook({
|
|
41
|
+
data: validatorValue,
|
|
42
|
+
...result,
|
|
43
|
+
target
|
|
44
|
+
}, c);
|
|
45
|
+
if (hookResult) {
|
|
46
|
+
if (hookResult instanceof Response) return hookResult;
|
|
47
|
+
if ("response" in hookResult) return hookResult.response;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!result.success) return c.json(result, 400);
|
|
51
|
+
return result.data;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
var zValidator = zValidatorFunction;
|
|
55
|
+
|
|
56
|
+
// src/hono/index.ts
|
|
57
|
+
var import_hono = require("hono");
|
|
58
|
+
|
|
59
|
+
// src/api/errors.ts
|
|
60
|
+
var import_act = require("@rotorsoft/act");
|
|
61
|
+
var ERROR_MAP = {
|
|
62
|
+
ValidationError: { status: 422, code: "VALIDATION" },
|
|
63
|
+
InvariantError: { status: 409, code: "INVARIANT" },
|
|
64
|
+
ConcurrencyError: { status: 412, code: "CONCURRENCY" },
|
|
65
|
+
StreamClosedError: { status: 410, code: "STREAM_CLOSED" },
|
|
66
|
+
NonRetryableError: { status: 400, code: "NON_RETRYABLE" }
|
|
67
|
+
};
|
|
68
|
+
var lookup_known = (err) => {
|
|
69
|
+
if (err instanceof import_act.ValidationError) return { name: "ValidationError" };
|
|
70
|
+
if (err instanceof import_act.InvariantError) return { name: "InvariantError" };
|
|
71
|
+
if (err instanceof import_act.ConcurrencyError) return { name: "ConcurrencyError" };
|
|
72
|
+
if (err instanceof import_act.StreamClosedError) return { name: "StreamClosedError" };
|
|
73
|
+
if (err instanceof import_act.NonRetryableError) return { name: "NonRetryableError" };
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
function toApiError(err) {
|
|
77
|
+
const known = lookup_known(err);
|
|
78
|
+
if (known) {
|
|
79
|
+
const entry = ERROR_MAP[known.name];
|
|
80
|
+
return {
|
|
81
|
+
status: entry.status,
|
|
82
|
+
body: {
|
|
83
|
+
error: known.name,
|
|
84
|
+
detail: err.message,
|
|
85
|
+
code: entry.code
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (err instanceof Error) {
|
|
90
|
+
return {
|
|
91
|
+
status: 500,
|
|
92
|
+
body: { error: "InternalError", detail: err.message, code: "INTERNAL" }
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
status: 500,
|
|
97
|
+
body: { error: "InternalError", code: "INTERNAL" }
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/api/idempotency.ts
|
|
102
|
+
async function withIdempotency(store, key, handler) {
|
|
103
|
+
const fresh = await store.claim(key);
|
|
104
|
+
if (!fresh) {
|
|
105
|
+
return { deduped: true };
|
|
106
|
+
}
|
|
107
|
+
return { deduped: false, result: await handler() };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/hono/index.ts
|
|
111
|
+
function authenticated(extractor) {
|
|
112
|
+
return async (c, next) => {
|
|
113
|
+
try {
|
|
114
|
+
const actor = await extractor(c);
|
|
115
|
+
c.set("actor", actor);
|
|
116
|
+
await next();
|
|
117
|
+
} catch (err) {
|
|
118
|
+
const body = {
|
|
119
|
+
error: "Unauthorized",
|
|
120
|
+
detail: err instanceof Error ? err.message : void 0,
|
|
121
|
+
code: "UNAUTHORIZED"
|
|
122
|
+
};
|
|
123
|
+
return c.json(body, 401);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
var default_key_from = (c) => c.req.header("idempotency-key");
|
|
128
|
+
function hono(app, options) {
|
|
129
|
+
const base_path = options.basePath ?? "/api";
|
|
130
|
+
const api = new import_hono.Hono().basePath(
|
|
131
|
+
base_path
|
|
132
|
+
);
|
|
133
|
+
api.use("*", authenticated(options.actor));
|
|
134
|
+
const key_from = options.idempotency?.keyFrom ?? default_key_from;
|
|
135
|
+
for (const [action_name, state] of Object.entries(app.registry.actions)) {
|
|
136
|
+
const schema = state.actions[action_name];
|
|
137
|
+
api.post(
|
|
138
|
+
`/actions/${action_name}`,
|
|
139
|
+
zValidator("json", schema),
|
|
140
|
+
async (c) => {
|
|
141
|
+
try {
|
|
142
|
+
const input = c.req.valid("json");
|
|
143
|
+
const actor = c.get("actor");
|
|
144
|
+
const stream = await options.stream(action_name, input, c);
|
|
145
|
+
const expected_version = options.expectedVersion ? await options.expectedVersion(action_name, input, c) : void 0;
|
|
146
|
+
const target = expected_version === void 0 ? { stream, actor } : { stream, actor, expectedVersion: expected_version };
|
|
147
|
+
if (options.idempotency) {
|
|
148
|
+
const key = key_from(c);
|
|
149
|
+
if (!key) {
|
|
150
|
+
const body = {
|
|
151
|
+
error: "BadRequest",
|
|
152
|
+
detail: "Idempotency-Key required",
|
|
153
|
+
code: "BAD_REQUEST"
|
|
154
|
+
};
|
|
155
|
+
return c.json(body, 400);
|
|
156
|
+
}
|
|
157
|
+
const outcome = await withIdempotency(
|
|
158
|
+
options.idempotency.store,
|
|
159
|
+
key,
|
|
160
|
+
() => app.do(action_name, target, input)
|
|
161
|
+
);
|
|
162
|
+
if (outcome.deduped) {
|
|
163
|
+
const body = {
|
|
164
|
+
error: "Conflict",
|
|
165
|
+
detail: "Idempotency-Key already used; original result not cached",
|
|
166
|
+
code: "CONFLICT"
|
|
167
|
+
};
|
|
168
|
+
return c.json(body, 409);
|
|
169
|
+
}
|
|
170
|
+
return c.json(outcome.result);
|
|
171
|
+
}
|
|
172
|
+
const snapshots = await app.do(
|
|
173
|
+
action_name,
|
|
174
|
+
target,
|
|
175
|
+
input
|
|
176
|
+
);
|
|
177
|
+
return c.json(snapshots);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
const { status, body } = toApiError(err);
|
|
180
|
+
return c.json(body, status);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return api;
|
|
186
|
+
}
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
authenticated,
|
|
190
|
+
hono
|
|
191
|
+
});
|
|
192
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/index.ts","../../../../node_modules/.pnpm/@hono+zod-validator@0.8.0_hono@4.12.23_zod@4.4.3/node_modules/@hono/zod-validator/src/index.ts","../../src/api/errors.ts","../../src/api/idempotency.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * @module act-http/hono\n *\n * Hono subpath for the auto-generated API epic (#835). Walks the\n * registry of a built `Act` once at function call and emits a Hono\n * app with one `POST /actions/<name>` route per registered action,\n * Zod-validated bodies, and the shared error envelope.\n *\n * Usage:\n *\n * ```ts\n * import { hono } from \"@rotorsoft/act-http/hono\";\n *\n * const api = hono(app, {\n * actor: (c) => ({ id: c.req.header(\"x-user-id\")!, name: \"...\" }),\n * stream: (action, input, c) => `tenant-${c.req.header(\"x-tenant\")}`,\n * });\n *\n * // Mounts at /api by default — pass `basePath` to override.\n * // POST /api/actions/OpenTicket body: { title } → 200 Snapshot[] | 4xx ApiError\n * ```\n *\n * The route shape matches the flat tRPC sibling at\n * `@rotorsoft/act-http/trpc`: one endpoint per action, no\n * state-name tier. Action names are unique across the registry —\n * the framework enforces no duplicates — so an extra namespace\n * level would be overhead. Queries live in a follow-up; this\n * slice is mutations only.\n *\n * **Actor lives on the context.** The generator wires an internal\n * middleware that runs the host's\n * {@link HonoOptions.actor | actor extractor} once per call and\n * stashes the resolved {@link Actor} under `c.get(\"actor\")`. Every\n * generated route reads from there — auth resolves at one seam,\n * downstream middleware (logging, tracing) sees the same actor.\n * The middleware factory is also exported as {@link authenticated}\n * for hosts that want to compose it into their own Hono chain\n * alongside hand-written routes.\n *\n * Composes the shared utilities at `@rotorsoft/act-http/api`:\n * {@link ActorExtractor} for the auth seam, {@link toApiError} for\n * the uniform error → status / code mapping, {@link withIdempotency}\n * for `Idempotency-Key` dedup. Three transports (tRPC, this one,\n * OpenAPI) ride the same utilities so a client speaking two of\n * them never sees two shapes for the same framework error.\n */\nimport { zValidator } from \"@hono/zod-validator\";\nimport type { Act, Actor, Schema, Schemas } from \"@rotorsoft/act\";\nimport type { IdempotencyStore } from \"@rotorsoft/act-ops/idempotency\";\nimport type { Context, MiddlewareHandler } from \"hono\";\nimport { Hono } from \"hono\";\nimport {\n type ActorExtractor,\n type ApiError,\n toApiError,\n withIdempotency,\n} from \"../api/index.js\";\n\n/**\n * Hono context variables this subpath contributes. The generic on\n * the returned middleware threads it through so routes downstream\n * of {@link authenticated} see `c.get(\"actor\")` typed without a\n * manual cast.\n */\nexport type ActMiddlewareVariables = {\n actor: Actor;\n};\n\n/**\n * Per-call options for {@link hono}. The host supplies the four\n * seams the package can't make decisions on:\n *\n * - `actor` — auth resolver. Receives the Hono context, returns the\n * `Actor` that flows onto `c.get(\"actor\")` for every generated\n * route (via an internal {@link authenticated}).\n * - `stream` — stream-id resolver. Receives the action name, the\n * validated body, and the Hono context; returns the target\n * stream. Singleton aggregates return a constant; per-tenant\n * aggregates pull from headers, path, or body.\n * - `expectedVersion` (optional) — optimistic-concurrency resolver.\n * Hosts typically read it from an `If-Match` header on the\n * request, or from the client's last-known snapshot. Returning\n * `undefined` skips the check for that call — handy when only\n * some actions are concurrency-sensitive.\n * - `idempotency` (optional) — when set, the route honors\n * `Idempotency-Key` via {@link withIdempotency}. The host\n * supplies the `IdempotencyStore`; `keyFrom` defaults to reading\n * the `Idempotency-Key` header. On a duplicate claim, the route\n * responds `409 Conflict` — the contract intentionally doesn't\n * cache the original handler's result, matching the\n * receiver-side \"ack the duplicate\" semantics.\n * - `basePath` (optional, default `\"/api\"`) — Hono basePath the\n * routes mount under.\n */\nexport type HonoOptions = {\n readonly actor: ActorExtractor;\n readonly stream: (\n action_name: string,\n input: unknown,\n c: Context\n ) => string | Promise<string>;\n readonly expectedVersion?: (\n action_name: string,\n input: unknown,\n c: Context\n ) => number | undefined | Promise<number | undefined>;\n readonly idempotency?: {\n readonly store: IdempotencyStore;\n readonly keyFrom?: (c: Context) => string | undefined;\n };\n readonly basePath?: string;\n};\n\n/**\n * Build a Hono middleware that runs an {@link ActorExtractor} once\n * per call and stashes the resolved {@link Actor} under\n * `c.set(\"actor\", ...)` so downstream routes can read it via\n * `c.get(\"actor\")`. The generator at {@link hono} uses this\n * internally; it's also exported so hosts that want to compose\n * their own route chain (logging, tracing, custom auth flavors)\n * can wire it directly:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { authenticated, type ActMiddlewareVariables } from \"@rotorsoft/act-http/hono\";\n *\n * const api = new Hono<{ Variables: ActMiddlewareVariables }>();\n * api.use(\"*\", authenticated((c) => resolveUserFromJwt(c)));\n * api.get(\"/me\", (c) => c.json(c.get(\"actor\"))); // typed\n * ```\n *\n * Errors thrown by the extractor surface as `401 Unauthorized` with\n * the shared {@link ApiError} envelope.\n */\nexport function authenticated(\n extractor: ActorExtractor\n): MiddlewareHandler<{ Variables: ActMiddlewareVariables }> {\n return async (c, next) => {\n try {\n const actor = await extractor(c);\n c.set(\"actor\", actor);\n await next();\n } catch (err) {\n const body: ApiError = {\n error: \"Unauthorized\",\n detail: err instanceof Error ? err.message : undefined,\n code: \"UNAUTHORIZED\",\n };\n return c.json(body, 401);\n }\n };\n}\n\nconst default_key_from = (c: Context): string | undefined =>\n c.req.header(\"idempotency-key\");\n\n/**\n * Build a typed Hono REST surface from a built `Act` instance.\n *\n * Walks `app.registry.actions` once and emits one\n * `POST /actions/<actionName>` per action under the configured\n * `basePath` (default `/api`). Each route:\n *\n * 1. Runs the internal {@link authenticated} middleware —\n * `options.actor` resolves the {@link Actor} once and stashes\n * it under `c.get(\"actor\")`.\n * 2. Validates the JSON body against the action's Zod schema via\n * `@hono/zod-validator`. Failures short-circuit with `422`.\n * 3. Resolves the target stream via\n * `options.stream(name, input, c)`.\n * 4. (Optionally) resolves `expectedVersion` for optimistic\n * concurrency.\n * 5. (Optionally) claims the `Idempotency-Key` via\n * {@link withIdempotency} — responds `409` on duplicate.\n * 6. Calls\n * `app.do(name, { stream, actor, expectedVersion? }, input)`.\n * 7. Maps any thrown framework error onto the shared\n * {@link ApiError} envelope via {@link toApiError}, returning\n * the conventional HTTP status (`409` / `412` for concurrency,\n * `422` for validation, `400` for non-retryable, etc.).\n *\n * @param app A built `Act` orchestrator.\n * @param options Auth, stream, expected-version, idempotency, and\n * base-path seams.\n * @returns A Hono app covering every registered action under\n * `<basePath>/actions/<name>`.\n */\nexport function hono(\n app: Act<Schemas, Schemas, Schemas, Record<string, Schema>>,\n options: HonoOptions\n): Hono<{ Variables: ActMiddlewareVariables }> {\n const base_path = options.basePath ?? \"/api\";\n const api = new Hono<{ Variables: ActMiddlewareVariables }>().basePath(\n base_path\n );\n api.use(\"*\", authenticated(options.actor));\n\n const key_from = options.idempotency?.keyFrom ?? default_key_from;\n\n for (const [action_name, state] of Object.entries(app.registry.actions)) {\n const schema = state.actions[action_name] as Schema;\n api.post(\n `/actions/${action_name}`,\n zValidator(\"json\", schema as never),\n async (c) => {\n try {\n const input = c.req.valid(\"json\" as never) as unknown;\n const actor = c.get(\"actor\");\n const stream = await options.stream(action_name, input, c);\n const expected_version = options.expectedVersion\n ? await options.expectedVersion(action_name, input, c)\n : undefined;\n const target =\n expected_version === undefined\n ? { stream, actor }\n : { stream, actor, expectedVersion: expected_version };\n\n if (options.idempotency) {\n const key = key_from(c);\n if (!key) {\n const body: ApiError = {\n error: \"BadRequest\",\n detail: \"Idempotency-Key required\",\n code: \"BAD_REQUEST\",\n };\n return c.json(body, 400);\n }\n const outcome = await withIdempotency(\n options.idempotency.store,\n key,\n () =>\n app.do(action_name as never, target as never, input as never)\n );\n if (outcome.deduped) {\n const body: ApiError = {\n error: \"Conflict\",\n detail:\n \"Idempotency-Key already used; original result not cached\",\n code: \"CONFLICT\",\n };\n return c.json(body, 409);\n }\n return c.json(outcome.result);\n }\n\n const snapshots = await app.do(\n action_name as never,\n target as never,\n input as never\n );\n return c.json(snapshots);\n } catch (err) {\n const { status, body } = toApiError(err);\n // Hono types narrow `status` to its known status-number union;\n // `toApiError` returns a numeric status from a closed set that\n // matches but TypeScript can't prove it through the union.\n return c.json(body, status as 400 | 409 | 410 | 412 | 422 | 500);\n }\n }\n );\n }\n\n return api;\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Context, Env, Input, MiddlewareHandler, TypedResponse, ValidationTargets } from 'hono'\nimport { validator } from 'hono/validator'\nimport type * as v3 from 'zod/v3'\nimport type { ZodSafeParseResult as v4ZodSafeParseResult } from 'zod/v4'\nimport type * as v4 from 'zod/v4/core'\nimport type { InferInput } from './utils'\n\ntype ZodSchema = v3.ZodType | v4.$ZodType\ntype ZodError<T extends ZodSchema> = T extends v4.$ZodType\n ? v4.$ZodError<v4.output<T>>\n : v3.ZodError\ntype ZodSafeParseResult<T, T2, T3 extends ZodSchema> = T3 extends v4.$ZodType\n ? v4ZodSafeParseResult<T>\n : v3.SafeParseReturnType<T, T2>\ntype zInput<T> = T extends v3.ZodType ? v3.input<T> : T extends v4.$ZodType ? v4.input<T> : never\ntype zOutput<T> = T extends v3.ZodType ? v3.output<T> : T extends v4.$ZodType ? v4.output<T> : never\ntype zInfer<T> = T extends v3.ZodType ? v3.infer<T> : T extends v4.$ZodType ? v4.infer<T> : never\n\n// Failure variant of `safeParseAsync`'s return value.\n// Mirrors the runtime body returned by `c.json(result, 400)` on validation failure.\ntype ZodValidatorFailureBody<T extends ZodSchema> = T extends v4.$ZodType\n ? Extract<v4ZodSafeParseResult<v4.output<T>>, { success: false }>\n : T extends v3.ZodType\n ? Extract<v3.SafeParseReturnType<v3.input<T>, v3.output<T>>, { success: false }>\n : never\n\ntype ZodValidatorFailureResponse<T extends ZodSchema> = Response &\n TypedResponse<ZodValidatorFailureBody<T>, 400, 'json'>\n\nexport type Hook<\n T,\n E extends Env,\n P extends string,\n Target extends keyof ValidationTargets = keyof ValidationTargets,\n O = {},\n Schema extends ZodSchema = any,\n> = (\n result: ({ success: true; data: T } | { success: false; error: ZodError<Schema>; data: T }) & {\n target: Target\n },\n c: Context<E, P>\n) => Response | void | TypedResponse<O> | Promise<Response | void | TypedResponse<O>>\n\ntype HasUndefined<T> = undefined extends T ? true : false\n\ntype ExtractValidationResponse<VF> = VF extends (value: any, c: any) => infer R\n ? R extends Promise<infer PR>\n ? PR extends TypedResponse<infer T, infer S, infer F>\n ? Response & TypedResponse<T, S, F>\n : PR extends Response\n ? PR\n : PR extends undefined\n ? never\n : never\n : R extends TypedResponse<infer T, infer S, infer F>\n ? Response & TypedResponse<T, S, F>\n : R extends Response\n ? R\n : R extends undefined\n ? never\n : never\n : never\n\ntype ValidationFunctionOption<T extends ZodSchema, Target extends keyof ValidationTargets> = {\n validationFunction: (\n schema: T,\n value: ValidationTargets[Target]\n ) => ZodSafeParseResult<any, any, T> | Promise<ZodSafeParseResult<any, any, T>>\n}\n\ntype DefaultInput<Target extends keyof ValidationTargets, In, Out> = {\n in: HasUndefined<In> extends true\n ? {\n [K in Target]?: [In] extends [ValidationTargets[K]] ? In : InferInput<In, K>\n }\n : {\n [K in Target]: [In] extends [ValidationTargets[K]] ? In : InferInput<In, K>\n }\n out: { [K in Target]: Out }\n}\n\n// without hook (with or without options)\nfunction zValidatorFunction<\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n E extends Env,\n P extends string,\n In = zInput<T>,\n Out = zOutput<T>,\n I extends Input = DefaultInput<Target, In, Out>,\n V extends I = I,\n>(\n target: Target,\n schema: T,\n hook?: undefined,\n options?: ValidationFunctionOption<T, Target>\n): MiddlewareHandler<E, P, V, ZodValidatorFailureResponse<T>>\n\n// with hook and options\nfunction zValidatorFunction<\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n E extends Env,\n P extends string,\n HookFn extends Hook<InferredValue, E, P, Target, {}, T>,\n In = zInput<T>,\n Out = zOutput<T>,\n I extends Input = DefaultInput<Target, In, Out>,\n V extends I = I,\n InferredValue = zInfer<T>,\n>(\n target: Target,\n schema: T,\n hook?: HookFn,\n options?: ValidationFunctionOption<T, Target>\n): MiddlewareHandler<E, P, V, ExtractValidationResponse<HookFn>>\n\n// implementation\nfunction zValidatorFunction<\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n E extends Env,\n P extends string,\n HookFn extends Hook<InferredValue, E, P, Target, {}, T>,\n In = zInput<T>,\n Out = zOutput<T>,\n I extends Input = DefaultInput<Target, In, Out>,\n V extends I = I,\n InferredValue = zInfer<T>,\n>(\n target: Target,\n schema: T,\n hook?: HookFn,\n options?: ValidationFunctionOption<T, Target>\n):\n | MiddlewareHandler<E, P, V, ZodValidatorFailureResponse<T>>\n | MiddlewareHandler<E, P, V, ExtractValidationResponse<HookFn>> {\n // @ts-expect-error not typed well\n return validator(target, async (value: ValidationTargets[Target], c) => {\n let validatorValue = value\n\n // in case where our `target` === `header`, Hono parses all of the headers into lowercase.\n // this might not match the Zod schema, so we want to make sure that we account for that when parsing the schema.\n if ((target === 'header' && '_def' in schema) || (target === 'header' && '_zod' in schema)) {\n // create an object that maps lowercase schema keys to lowercase\n // @ts-expect-error the schema is a Zod Schema\n const schemaKeys = Object.keys('in' in schema ? schema.in.shape : schema.shape)\n const caseInsensitiveKeymap = Object.fromEntries(\n schemaKeys.map((key) => [key.toLowerCase(), key])\n )\n\n validatorValue = Object.fromEntries(\n Object.entries(value).map(([key, value]) => [caseInsensitiveKeymap[key] || key, value])\n )\n }\n\n const result =\n options && options.validationFunction\n ? await options.validationFunction(schema, validatorValue)\n : // @ts-expect-error z4.$ZodType has safeParseAsync\n await schema.safeParseAsync(validatorValue)\n\n if (hook) {\n const hookResult = await hook({ data: validatorValue, ...result, target }, c)\n if (hookResult) {\n if (hookResult instanceof Response) {\n return hookResult\n }\n\n if ('response' in hookResult) {\n return hookResult.response\n }\n }\n }\n\n if (!result.success) {\n return c.json(result, 400)\n }\n\n return result.data as zInfer<T>\n })\n}\n\nexport const zValidator: typeof zValidatorFunction = zValidatorFunction\n","import {\n ConcurrencyError,\n InvariantError,\n NonRetryableError,\n StreamClosedError,\n ValidationError,\n} from \"@rotorsoft/act\";\n\n/**\n * Uniform error envelope shipped over the wire by every act-http\n * transport. Hosts get the same shape from REST, tRPC, and OpenAPI —\n * a client that talks to two transports doesn't have to invent two\n * error parsers.\n *\n * - `error` — the framework error name (`\"ValidationError\"`,\n * `\"InvariantError\"`, …). Stable identifier, safe to switch on.\n * - `detail` — the framework's message text. Human-readable; not\n * parsed by clients.\n * - `code` — a machine-readable status code from {@link ERROR_MAP}\n * for clients that prefer enum-style branching over name strings.\n */\nexport type ApiError = {\n error: string;\n detail?: string;\n code?: string;\n};\n\n/**\n * Status + code pair for one known framework error.\n */\nexport type ErrorMapEntry = {\n status: number;\n code: string;\n};\n\n/**\n * The single table that maps framework error types to HTTP status\n * codes and machine-readable codes. One table, three consumers\n * (Hono, tRPC, OpenAPI) — cross-transport consistency by\n * construction.\n *\n * Operators wanting different mappings wrap the generated transport\n * rather than mutating this — the consistency is the load-bearing\n * property, not the specific status codes.\n */\nexport const ERROR_MAP = {\n ValidationError: { status: 422, code: \"VALIDATION\" },\n InvariantError: { status: 409, code: \"INVARIANT\" },\n ConcurrencyError: { status: 412, code: \"CONCURRENCY\" },\n StreamClosedError: { status: 410, code: \"STREAM_CLOSED\" },\n NonRetryableError: { status: 400, code: \"NON_RETRYABLE\" },\n} as const satisfies Record<string, ErrorMapEntry>;\n\nconst lookup_known = (\n err: unknown\n): { name: keyof typeof ERROR_MAP } | null => {\n if (err instanceof ValidationError) return { name: \"ValidationError\" };\n if (err instanceof InvariantError) return { name: \"InvariantError\" };\n if (err instanceof ConcurrencyError) return { name: \"ConcurrencyError\" };\n if (err instanceof StreamClosedError) return { name: \"StreamClosedError\" };\n if (err instanceof NonRetryableError) return { name: \"NonRetryableError\" };\n return null;\n};\n\n/**\n * Translate an unknown thrown value into the canonical\n * {@link ApiError} envelope plus HTTP status. Each transport's error\n * boundary calls this once and forwards the result to the wire.\n *\n * Known framework errors map per {@link ERROR_MAP}. Everything else\n * surfaces as a 500 with `code: \"INTERNAL\"`; the `detail` field is\n * populated when the throw was an `Error` instance, omitted\n * otherwise (a thrown string or object doesn't get to leak its\n * payload to the client).\n */\nexport function toApiError(err: unknown): { status: number; body: ApiError } {\n const known = lookup_known(err);\n if (known) {\n const entry = ERROR_MAP[known.name];\n return {\n status: entry.status,\n body: {\n error: known.name,\n detail: (err as Error).message,\n code: entry.code,\n },\n };\n }\n if (err instanceof Error) {\n return {\n status: 500,\n body: { error: \"InternalError\", detail: err.message, code: \"INTERNAL\" },\n };\n }\n return {\n status: 500,\n body: { error: \"InternalError\", code: \"INTERNAL\" },\n };\n}\n","import type { IdempotencyStore } from \"@rotorsoft/act-ops/idempotency\";\n\n/**\n * Result of a {@link withIdempotency} call.\n *\n * - `{ deduped: false, result }` — the claim was fresh; the handler\n * ran and produced `result`.\n * - `{ deduped: true }` — the claim was already taken; the handler\n * was *not* invoked. The caller decides how to respond (typically\n * a 2xx with no body, matching the receiver-side convention).\n *\n * Note: the contract does not cache the previous response. A\n * duplicate call returns the deduped marker only — replaying the\n * original handler's output would require a response-caching\n * adapter, which is out of scope here. The receiver-side convention\n * (and the convention the generated transports follow) is \"ack the\n * duplicate; do nothing else.\"\n */\nexport type IdempotencyResult<T> =\n | { deduped: false; result: T }\n | { deduped: true };\n\n/**\n * Wrap an action handler so the framework honors `Idempotency-Key`\n * dedup. Acquires the key via {@link IdempotencyStore.claim}, runs\n * the handler exactly when the claim was fresh, and skips the\n * handler entirely on a duplicate.\n *\n * Reuses the contract `@rotorsoft/act-ops/idempotency` already\n * defines for the receiver-side `Idempotency-Key` story. A single\n * `IdempotencyStore` implementation covers both halves of the \"Act\n * over the wire\" surface — receiver and generated API.\n */\nexport async function withIdempotency<T>(\n store: IdempotencyStore,\n key: string,\n handler: () => Promise<T>\n): Promise<IdempotencyResult<T>> {\n const fresh = await store.claim(key);\n if (!fresh) {\n return { deduped: true };\n }\n return { deduped: false, result: await handler() };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;ACuHA,SAAS,mBAYP,QACA,QACA,MACA,SAGgE;AAEhE,aAAO,4BAAU,QAAQ,OAAO,OAAkC,MAAM;AACtE,QAAI,iBAAiB;AAIrB,QAAK,WAAW,YAAY,UAAU,UAAY,WAAW,YAAY,UAAU,QAAS;AAG1F,YAAM,aAAa,OAAO,KAAK,QAAQ,SAAS,OAAO,GAAG,QAAQ,OAAO,KAAA;AACzE,YAAM,wBAAwB,OAAO,YACnC,WAAW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AAAA,YAC1B;AAAA,YACA;AAAA,YACA;AAAA,UACF;AACA,iBAAO,EAAE,KAAK,SAAS;AAAA,QACzB,SAAS,KAAK;AACZ,gBAAM,EAAE,QAAQ,KAAK,IAAI,WAAW,GAAG;AAIvC,iBAAO,EAAE,KAAK,MAAM,MAA2C;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":["value","zValidator: typeof zValidatorFunction"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toApiError,
|
|
3
|
+
withIdempotency
|
|
4
|
+
} from "../chunk-Z6FVXDDU.js";
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/.pnpm/@hono+zod-validator@0.8.0_hono@4.12.23_zod@4.4.3/node_modules/@hono/zod-validator/dist/index.js
|
|
7
|
+
import { validator } from "hono/validator";
|
|
8
|
+
function zValidatorFunction(target, schema, hook, options) {
|
|
9
|
+
return validator(target, async (value, c) => {
|
|
10
|
+
let validatorValue = value;
|
|
11
|
+
if (target === "header" && "_def" in schema || target === "header" && "_zod" in schema) {
|
|
12
|
+
const schemaKeys = Object.keys("in" in schema ? schema.in.shape : schema.shape);
|
|
13
|
+
const caseInsensitiveKeymap = Object.fromEntries(schemaKeys.map((key) => [key.toLowerCase(), key]));
|
|
14
|
+
validatorValue = Object.fromEntries(Object.entries(value).map(([key, value$1]) => [caseInsensitiveKeymap[key] || key, value$1]));
|
|
15
|
+
}
|
|
16
|
+
const result = options && options.validationFunction ? await options.validationFunction(schema, validatorValue) : await schema.safeParseAsync(validatorValue);
|
|
17
|
+
if (hook) {
|
|
18
|
+
const hookResult = await hook({
|
|
19
|
+
data: validatorValue,
|
|
20
|
+
...result,
|
|
21
|
+
target
|
|
22
|
+
}, c);
|
|
23
|
+
if (hookResult) {
|
|
24
|
+
if (hookResult instanceof Response) return hookResult;
|
|
25
|
+
if ("response" in hookResult) return hookResult.response;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!result.success) return c.json(result, 400);
|
|
29
|
+
return result.data;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var zValidator = zValidatorFunction;
|
|
33
|
+
|
|
34
|
+
// src/hono/index.ts
|
|
35
|
+
import { Hono } from "hono";
|
|
36
|
+
function authenticated(extractor) {
|
|
37
|
+
return async (c, next) => {
|
|
38
|
+
try {
|
|
39
|
+
const actor = await extractor(c);
|
|
40
|
+
c.set("actor", actor);
|
|
41
|
+
await next();
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const body = {
|
|
44
|
+
error: "Unauthorized",
|
|
45
|
+
detail: err instanceof Error ? err.message : void 0,
|
|
46
|
+
code: "UNAUTHORIZED"
|
|
47
|
+
};
|
|
48
|
+
return c.json(body, 401);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var default_key_from = (c) => c.req.header("idempotency-key");
|
|
53
|
+
function hono(app, options) {
|
|
54
|
+
const base_path = options.basePath ?? "/api";
|
|
55
|
+
const api = new Hono().basePath(
|
|
56
|
+
base_path
|
|
57
|
+
);
|
|
58
|
+
api.use("*", authenticated(options.actor));
|
|
59
|
+
const key_from = options.idempotency?.keyFrom ?? default_key_from;
|
|
60
|
+
for (const [action_name, state] of Object.entries(app.registry.actions)) {
|
|
61
|
+
const schema = state.actions[action_name];
|
|
62
|
+
api.post(
|
|
63
|
+
`/actions/${action_name}`,
|
|
64
|
+
zValidator("json", schema),
|
|
65
|
+
async (c) => {
|
|
66
|
+
try {
|
|
67
|
+
const input = c.req.valid("json");
|
|
68
|
+
const actor = c.get("actor");
|
|
69
|
+
const stream = await options.stream(action_name, input, c);
|
|
70
|
+
const expected_version = options.expectedVersion ? await options.expectedVersion(action_name, input, c) : void 0;
|
|
71
|
+
const target = expected_version === void 0 ? { stream, actor } : { stream, actor, expectedVersion: expected_version };
|
|
72
|
+
if (options.idempotency) {
|
|
73
|
+
const key = key_from(c);
|
|
74
|
+
if (!key) {
|
|
75
|
+
const body = {
|
|
76
|
+
error: "BadRequest",
|
|
77
|
+
detail: "Idempotency-Key required",
|
|
78
|
+
code: "BAD_REQUEST"
|
|
79
|
+
};
|
|
80
|
+
return c.json(body, 400);
|
|
81
|
+
}
|
|
82
|
+
const outcome = await withIdempotency(
|
|
83
|
+
options.idempotency.store,
|
|
84
|
+
key,
|
|
85
|
+
() => app.do(action_name, target, input)
|
|
86
|
+
);
|
|
87
|
+
if (outcome.deduped) {
|
|
88
|
+
const body = {
|
|
89
|
+
error: "Conflict",
|
|
90
|
+
detail: "Idempotency-Key already used; original result not cached",
|
|
91
|
+
code: "CONFLICT"
|
|
92
|
+
};
|
|
93
|
+
return c.json(body, 409);
|
|
94
|
+
}
|
|
95
|
+
return c.json(outcome.result);
|
|
96
|
+
}
|
|
97
|
+
const snapshots = await app.do(
|
|
98
|
+
action_name,
|
|
99
|
+
target,
|
|
100
|
+
input
|
|
101
|
+
);
|
|
102
|
+
return c.json(snapshots);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
const { status, body } = toApiError(err);
|
|
105
|
+
return c.json(body, status);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return api;
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
authenticated,
|
|
114
|
+
hono
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../node_modules/.pnpm/@hono+zod-validator@0.8.0_hono@4.12.23_zod@4.4.3/node_modules/@hono/zod-validator/src/index.ts","../../src/hono/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Context, Env, Input, MiddlewareHandler, TypedResponse, ValidationTargets } from 'hono'\nimport { validator } from 'hono/validator'\nimport type * as v3 from 'zod/v3'\nimport type { ZodSafeParseResult as v4ZodSafeParseResult } from 'zod/v4'\nimport type * as v4 from 'zod/v4/core'\nimport type { InferInput } from './utils'\n\ntype ZodSchema = v3.ZodType | v4.$ZodType\ntype ZodError<T extends ZodSchema> = T extends v4.$ZodType\n ? v4.$ZodError<v4.output<T>>\n : v3.ZodError\ntype ZodSafeParseResult<T, T2, T3 extends ZodSchema> = T3 extends v4.$ZodType\n ? v4ZodSafeParseResult<T>\n : v3.SafeParseReturnType<T, T2>\ntype zInput<T> = T extends v3.ZodType ? v3.input<T> : T extends v4.$ZodType ? v4.input<T> : never\ntype zOutput<T> = T extends v3.ZodType ? v3.output<T> : T extends v4.$ZodType ? v4.output<T> : never\ntype zInfer<T> = T extends v3.ZodType ? v3.infer<T> : T extends v4.$ZodType ? v4.infer<T> : never\n\n// Failure variant of `safeParseAsync`'s return value.\n// Mirrors the runtime body returned by `c.json(result, 400)` on validation failure.\ntype ZodValidatorFailureBody<T extends ZodSchema> = T extends v4.$ZodType\n ? Extract<v4ZodSafeParseResult<v4.output<T>>, { success: false }>\n : T extends v3.ZodType\n ? Extract<v3.SafeParseReturnType<v3.input<T>, v3.output<T>>, { success: false }>\n : never\n\ntype ZodValidatorFailureResponse<T extends ZodSchema> = Response &\n TypedResponse<ZodValidatorFailureBody<T>, 400, 'json'>\n\nexport type Hook<\n T,\n E extends Env,\n P extends string,\n Target extends keyof ValidationTargets = keyof ValidationTargets,\n O = {},\n Schema extends ZodSchema = any,\n> = (\n result: ({ success: true; data: T } | { success: false; error: ZodError<Schema>; data: T }) & {\n target: Target\n },\n c: Context<E, P>\n) => Response | void | TypedResponse<O> | Promise<Response | void | TypedResponse<O>>\n\ntype HasUndefined<T> = undefined extends T ? true : false\n\ntype ExtractValidationResponse<VF> = VF extends (value: any, c: any) => infer R\n ? R extends Promise<infer PR>\n ? PR extends TypedResponse<infer T, infer S, infer F>\n ? Response & TypedResponse<T, S, F>\n : PR extends Response\n ? PR\n : PR extends undefined\n ? never\n : never\n : R extends TypedResponse<infer T, infer S, infer F>\n ? Response & TypedResponse<T, S, F>\n : R extends Response\n ? R\n : R extends undefined\n ? never\n : never\n : never\n\ntype ValidationFunctionOption<T extends ZodSchema, Target extends keyof ValidationTargets> = {\n validationFunction: (\n schema: T,\n value: ValidationTargets[Target]\n ) => ZodSafeParseResult<any, any, T> | Promise<ZodSafeParseResult<any, any, T>>\n}\n\ntype DefaultInput<Target extends keyof ValidationTargets, In, Out> = {\n in: HasUndefined<In> extends true\n ? {\n [K in Target]?: [In] extends [ValidationTargets[K]] ? In : InferInput<In, K>\n }\n : {\n [K in Target]: [In] extends [ValidationTargets[K]] ? In : InferInput<In, K>\n }\n out: { [K in Target]: Out }\n}\n\n// without hook (with or without options)\nfunction zValidatorFunction<\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n E extends Env,\n P extends string,\n In = zInput<T>,\n Out = zOutput<T>,\n I extends Input = DefaultInput<Target, In, Out>,\n V extends I = I,\n>(\n target: Target,\n schema: T,\n hook?: undefined,\n options?: ValidationFunctionOption<T, Target>\n): MiddlewareHandler<E, P, V, ZodValidatorFailureResponse<T>>\n\n// with hook and options\nfunction zValidatorFunction<\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n E extends Env,\n P extends string,\n HookFn extends Hook<InferredValue, E, P, Target, {}, T>,\n In = zInput<T>,\n Out = zOutput<T>,\n I extends Input = DefaultInput<Target, In, Out>,\n V extends I = I,\n InferredValue = zInfer<T>,\n>(\n target: Target,\n schema: T,\n hook?: HookFn,\n options?: ValidationFunctionOption<T, Target>\n): MiddlewareHandler<E, P, V, ExtractValidationResponse<HookFn>>\n\n// implementation\nfunction zValidatorFunction<\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n E extends Env,\n P extends string,\n HookFn extends Hook<InferredValue, E, P, Target, {}, T>,\n In = zInput<T>,\n Out = zOutput<T>,\n I extends Input = DefaultInput<Target, In, Out>,\n V extends I = I,\n InferredValue = zInfer<T>,\n>(\n target: Target,\n schema: T,\n hook?: HookFn,\n options?: ValidationFunctionOption<T, Target>\n):\n | MiddlewareHandler<E, P, V, ZodValidatorFailureResponse<T>>\n | MiddlewareHandler<E, P, V, ExtractValidationResponse<HookFn>> {\n // @ts-expect-error not typed well\n return validator(target, async (value: ValidationTargets[Target], c) => {\n let validatorValue = value\n\n // in case where our `target` === `header`, Hono parses all of the headers into lowercase.\n // this might not match the Zod schema, so we want to make sure that we account for that when parsing the schema.\n if ((target === 'header' && '_def' in schema) || (target === 'header' && '_zod' in schema)) {\n // create an object that maps lowercase schema keys to lowercase\n // @ts-expect-error the schema is a Zod Schema\n const schemaKeys = Object.keys('in' in schema ? schema.in.shape : schema.shape)\n const caseInsensitiveKeymap = Object.fromEntries(\n schemaKeys.map((key) => [key.toLowerCase(), key])\n )\n\n validatorValue = Object.fromEntries(\n Object.entries(value).map(([key, value]) => [caseInsensitiveKeymap[key] || key, value])\n )\n }\n\n const result =\n options && options.validationFunction\n ? await options.validationFunction(schema, validatorValue)\n : // @ts-expect-error z4.$ZodType has safeParseAsync\n await schema.safeParseAsync(validatorValue)\n\n if (hook) {\n const hookResult = await hook({ data: validatorValue, ...result, target }, c)\n if (hookResult) {\n if (hookResult instanceof Response) {\n return hookResult\n }\n\n if ('response' in hookResult) {\n return hookResult.response\n }\n }\n }\n\n if (!result.success) {\n return c.json(result, 400)\n }\n\n return result.data as zInfer<T>\n })\n}\n\nexport const zValidator: typeof zValidatorFunction = zValidatorFunction\n","/**\n * @packageDocumentation\n * @module act-http/hono\n *\n * Hono subpath for the auto-generated API epic (#835). Walks the\n * registry of a built `Act` once at function call and emits a Hono\n * app with one `POST /actions/<name>` route per registered action,\n * Zod-validated bodies, and the shared error envelope.\n *\n * Usage:\n *\n * ```ts\n * import { hono } from \"@rotorsoft/act-http/hono\";\n *\n * const api = hono(app, {\n * actor: (c) => ({ id: c.req.header(\"x-user-id\")!, name: \"...\" }),\n * stream: (action, input, c) => `tenant-${c.req.header(\"x-tenant\")}`,\n * });\n *\n * // Mounts at /api by default — pass `basePath` to override.\n * // POST /api/actions/OpenTicket body: { title } → 200 Snapshot[] | 4xx ApiError\n * ```\n *\n * The route shape matches the flat tRPC sibling at\n * `@rotorsoft/act-http/trpc`: one endpoint per action, no\n * state-name tier. Action names are unique across the registry —\n * the framework enforces no duplicates — so an extra namespace\n * level would be overhead. Queries live in a follow-up; this\n * slice is mutations only.\n *\n * **Actor lives on the context.** The generator wires an internal\n * middleware that runs the host's\n * {@link HonoOptions.actor | actor extractor} once per call and\n * stashes the resolved {@link Actor} under `c.get(\"actor\")`. Every\n * generated route reads from there — auth resolves at one seam,\n * downstream middleware (logging, tracing) sees the same actor.\n * The middleware factory is also exported as {@link authenticated}\n * for hosts that want to compose it into their own Hono chain\n * alongside hand-written routes.\n *\n * Composes the shared utilities at `@rotorsoft/act-http/api`:\n * {@link ActorExtractor} for the auth seam, {@link toApiError} for\n * the uniform error → status / code mapping, {@link withIdempotency}\n * for `Idempotency-Key` dedup. Three transports (tRPC, this one,\n * OpenAPI) ride the same utilities so a client speaking two of\n * them never sees two shapes for the same framework error.\n */\nimport { zValidator } from \"@hono/zod-validator\";\nimport type { Act, Actor, Schema, Schemas } from \"@rotorsoft/act\";\nimport type { IdempotencyStore } from \"@rotorsoft/act-ops/idempotency\";\nimport type { Context, MiddlewareHandler } from \"hono\";\nimport { Hono } from \"hono\";\nimport {\n type ActorExtractor,\n type ApiError,\n toApiError,\n withIdempotency,\n} from \"../api/index.js\";\n\n/**\n * Hono context variables this subpath contributes. The generic on\n * the returned middleware threads it through so routes downstream\n * of {@link authenticated} see `c.get(\"actor\")` typed without a\n * manual cast.\n */\nexport type ActMiddlewareVariables = {\n actor: Actor;\n};\n\n/**\n * Per-call options for {@link hono}. The host supplies the four\n * seams the package can't make decisions on:\n *\n * - `actor` — auth resolver. Receives the Hono context, returns the\n * `Actor` that flows onto `c.get(\"actor\")` for every generated\n * route (via an internal {@link authenticated}).\n * - `stream` — stream-id resolver. Receives the action name, the\n * validated body, and the Hono context; returns the target\n * stream. Singleton aggregates return a constant; per-tenant\n * aggregates pull from headers, path, or body.\n * - `expectedVersion` (optional) — optimistic-concurrency resolver.\n * Hosts typically read it from an `If-Match` header on the\n * request, or from the client's last-known snapshot. Returning\n * `undefined` skips the check for that call — handy when only\n * some actions are concurrency-sensitive.\n * - `idempotency` (optional) — when set, the route honors\n * `Idempotency-Key` via {@link withIdempotency}. The host\n * supplies the `IdempotencyStore`; `keyFrom` defaults to reading\n * the `Idempotency-Key` header. On a duplicate claim, the route\n * responds `409 Conflict` — the contract intentionally doesn't\n * cache the original handler's result, matching the\n * receiver-side \"ack the duplicate\" semantics.\n * - `basePath` (optional, default `\"/api\"`) — Hono basePath the\n * routes mount under.\n */\nexport type HonoOptions = {\n readonly actor: ActorExtractor;\n readonly stream: (\n action_name: string,\n input: unknown,\n c: Context\n ) => string | Promise<string>;\n readonly expectedVersion?: (\n action_name: string,\n input: unknown,\n c: Context\n ) => number | undefined | Promise<number | undefined>;\n readonly idempotency?: {\n readonly store: IdempotencyStore;\n readonly keyFrom?: (c: Context) => string | undefined;\n };\n readonly basePath?: string;\n};\n\n/**\n * Build a Hono middleware that runs an {@link ActorExtractor} once\n * per call and stashes the resolved {@link Actor} under\n * `c.set(\"actor\", ...)` so downstream routes can read it via\n * `c.get(\"actor\")`. The generator at {@link hono} uses this\n * internally; it's also exported so hosts that want to compose\n * their own route chain (logging, tracing, custom auth flavors)\n * can wire it directly:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { authenticated, type ActMiddlewareVariables } from \"@rotorsoft/act-http/hono\";\n *\n * const api = new Hono<{ Variables: ActMiddlewareVariables }>();\n * api.use(\"*\", authenticated((c) => resolveUserFromJwt(c)));\n * api.get(\"/me\", (c) => c.json(c.get(\"actor\"))); // typed\n * ```\n *\n * Errors thrown by the extractor surface as `401 Unauthorized` with\n * the shared {@link ApiError} envelope.\n */\nexport function authenticated(\n extractor: ActorExtractor\n): MiddlewareHandler<{ Variables: ActMiddlewareVariables }> {\n return async (c, next) => {\n try {\n const actor = await extractor(c);\n c.set(\"actor\", actor);\n await next();\n } catch (err) {\n const body: ApiError = {\n error: \"Unauthorized\",\n detail: err instanceof Error ? err.message : undefined,\n code: \"UNAUTHORIZED\",\n };\n return c.json(body, 401);\n }\n };\n}\n\nconst default_key_from = (c: Context): string | undefined =>\n c.req.header(\"idempotency-key\");\n\n/**\n * Build a typed Hono REST surface from a built `Act` instance.\n *\n * Walks `app.registry.actions` once and emits one\n * `POST /actions/<actionName>` per action under the configured\n * `basePath` (default `/api`). Each route:\n *\n * 1. Runs the internal {@link authenticated} middleware —\n * `options.actor` resolves the {@link Actor} once and stashes\n * it under `c.get(\"actor\")`.\n * 2. Validates the JSON body against the action's Zod schema via\n * `@hono/zod-validator`. Failures short-circuit with `422`.\n * 3. Resolves the target stream via\n * `options.stream(name, input, c)`.\n * 4. (Optionally) resolves `expectedVersion` for optimistic\n * concurrency.\n * 5. (Optionally) claims the `Idempotency-Key` via\n * {@link withIdempotency} — responds `409` on duplicate.\n * 6. Calls\n * `app.do(name, { stream, actor, expectedVersion? }, input)`.\n * 7. Maps any thrown framework error onto the shared\n * {@link ApiError} envelope via {@link toApiError}, returning\n * the conventional HTTP status (`409` / `412` for concurrency,\n * `422` for validation, `400` for non-retryable, etc.).\n *\n * @param app A built `Act` orchestrator.\n * @param options Auth, stream, expected-version, idempotency, and\n * base-path seams.\n * @returns A Hono app covering every registered action under\n * `<basePath>/actions/<name>`.\n */\nexport function hono(\n app: Act<Schemas, Schemas, Schemas, Record<string, Schema>>,\n options: HonoOptions\n): Hono<{ Variables: ActMiddlewareVariables }> {\n const base_path = options.basePath ?? \"/api\";\n const api = new Hono<{ Variables: ActMiddlewareVariables }>().basePath(\n base_path\n );\n api.use(\"*\", authenticated(options.actor));\n\n const key_from = options.idempotency?.keyFrom ?? default_key_from;\n\n for (const [action_name, state] of Object.entries(app.registry.actions)) {\n const schema = state.actions[action_name] as Schema;\n api.post(\n `/actions/${action_name}`,\n zValidator(\"json\", schema as never),\n async (c) => {\n try {\n const input = c.req.valid(\"json\" as never) as unknown;\n const actor = c.get(\"actor\");\n const stream = await options.stream(action_name, input, c);\n const expected_version = options.expectedVersion\n ? await options.expectedVersion(action_name, input, c)\n : undefined;\n const target =\n expected_version === undefined\n ? { stream, actor }\n : { stream, actor, expectedVersion: expected_version };\n\n if (options.idempotency) {\n const key = key_from(c);\n if (!key) {\n const body: ApiError = {\n error: \"BadRequest\",\n detail: \"Idempotency-Key required\",\n code: \"BAD_REQUEST\",\n };\n return c.json(body, 400);\n }\n const outcome = await withIdempotency(\n options.idempotency.store,\n key,\n () =>\n app.do(action_name as never, target as never, input as never)\n );\n if (outcome.deduped) {\n const body: ApiError = {\n error: \"Conflict\",\n detail:\n \"Idempotency-Key already used; original result not cached\",\n code: \"CONFLICT\",\n };\n return c.json(body, 409);\n }\n return c.json(outcome.result);\n }\n\n const snapshots = await app.do(\n action_name as never,\n target as never,\n input as never\n );\n return c.json(snapshots);\n } catch (err) {\n const { status, body } = toApiError(err);\n // Hono types narrow `status` to its known status-number union;\n // `toApiError` returns a numeric status from a closed set that\n // matches but TypeScript can't prove it through the union.\n return c.json(body, status as 400 | 409 | 410 | 412 | 422 | 500);\n }\n }\n );\n }\n\n return api;\n}\n"],"mappings":";;;;;;;AAuHA,SAAS,mBAYP,QACA,QACA,MACA,SAGgE;AAEhE,SAAO,UAAU,QAAQ,OAAO,OAAkC,MAAM;AACtE,QAAI,iBAAiB;AAIrB,QAAK,WAAW,YAAY,UAAU,UAAY,WAAW,YAAY,UAAU,QAAS;AAG1F,YAAM,aAAa,OAAO,KAAK,QAAQ,SAAS,OAAO,GAAG,QAAQ,OAAO,KAAA;AACzE,YAAM,wBAAwB,OAAO,YACnC,WAAW,IAAA,CAAK,QAAQ,CAAC,IAAI,YAAA,GAAe,GAAA,CAAI,CAAC;AAGnD,uBAAiB,OAAO,YACtB,OAAO,QAAQ,KAAA,EAAO,IAAA,CAAK,CAAC,KAAKA,OAAAA,MAAW,CAAC,sBAAsB,GAAA,KAAQ,KAAKA,OAAAA,CAAM,CAAC;;AAI3F,UAAM,SACJ,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
|
2
2
|
"name": "@rotorsoft/act-http",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "HTTP integrations for act apps — webhooks and SSE",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"typescript",
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
"import": "./dist/api/index.js",
|
|
32
32
|
"require": "./dist/api/index.cjs"
|
|
33
33
|
},
|
|
34
|
+
"./hono": {
|
|
35
|
+
"types": "./dist/@types/hono/index.d.ts",
|
|
36
|
+
"import": "./dist/hono/index.js",
|
|
37
|
+
"require": "./dist/hono/index.cjs"
|
|
38
|
+
},
|
|
34
39
|
"./receiver": {
|
|
35
40
|
"types": "./dist/@types/receiver/index.d.ts",
|
|
36
41
|
"import": "./dist/receiver/index.js",
|
|
@@ -80,11 +85,11 @@
|
|
|
80
85
|
"access": "public"
|
|
81
86
|
},
|
|
82
87
|
"peerDependencies": {
|
|
83
|
-
"@trpc/server": ">=11.17.0",
|
|
84
88
|
"@hono/node-server": "^2.0.4",
|
|
89
|
+
"@trpc/server": ">=11.17.0",
|
|
85
90
|
"express": "^5.2.1",
|
|
86
91
|
"fastify": "^5.8.5",
|
|
87
|
-
"hono": "^4.12.
|
|
92
|
+
"hono": "^4.12.24",
|
|
88
93
|
"@rotorsoft/act": "^1.10.2",
|
|
89
94
|
"@rotorsoft/act-ops": "^0.2.1"
|
|
90
95
|
},
|
|
@@ -113,6 +118,7 @@
|
|
|
113
118
|
},
|
|
114
119
|
"devDependencies": {
|
|
115
120
|
"@hono/node-server": "^2.0.4",
|
|
121
|
+
"@hono/zod-validator": "^0.8.0",
|
|
116
122
|
"@trpc/server": "^11.17.0",
|
|
117
123
|
"@types/express": "^5.0.6",
|
|
118
124
|
"express": "^5.2.1",
|