@rotorsoft/act-http 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +12 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/@types/api/actor.d.ts +20 -0
  4. package/dist/@types/api/actor.d.ts.map +1 -0
  5. package/dist/@types/api/errors.d.ts +73 -0
  6. package/dist/@types/api/errors.d.ts.map +1 -0
  7. package/dist/@types/api/idempotency.d.ts +36 -0
  8. package/dist/@types/api/idempotency.d.ts.map +1 -0
  9. package/dist/@types/api/index.d.ts +39 -0
  10. package/dist/@types/api/index.d.ts.map +1 -0
  11. package/dist/@types/receiver/start.d.ts +1 -1
  12. package/dist/@types/sse/apply-patch.d.ts +3 -3
  13. package/dist/@types/sse/broadcast.d.ts +6 -6
  14. package/dist/@types/sse/broadcast.d.ts.map +1 -1
  15. package/dist/@types/sse/presence.d.ts +7 -7
  16. package/dist/@types/sse/presence.d.ts.map +1 -1
  17. package/dist/@types/webhook/classify.d.ts +6 -6
  18. package/dist/@types/webhook/classify.d.ts.map +1 -1
  19. package/dist/@types/webhook/index.d.ts +1 -1
  20. package/dist/@types/webhook/index.d.ts.map +1 -1
  21. package/dist/@types/webhook/sign.d.ts +1 -1
  22. package/dist/@types/webhook/sign.d.ts.map +1 -1
  23. package/dist/api/index.cjs +85 -0
  24. package/dist/api/index.cjs.map +1 -0
  25. package/dist/api/index.js +62 -0
  26. package/dist/api/index.js.map +1 -0
  27. package/dist/{chunk-NOIXOF2I.js → chunk-4CGAUB5H.js} +13 -13
  28. package/dist/chunk-4CGAUB5H.js.map +1 -0
  29. package/dist/{chunk-F7VWYZ37.js → chunk-K4HAOBRF.js} +4 -4
  30. package/dist/{chunk-F7VWYZ37.js.map → chunk-K4HAOBRF.js.map} +1 -1
  31. package/dist/receiver/express/index.cjs +14 -14
  32. package/dist/receiver/express/index.cjs.map +1 -1
  33. package/dist/receiver/express/index.js +3 -3
  34. package/dist/receiver/express/index.js.map +1 -1
  35. package/dist/receiver/fastify/index.cjs +12 -12
  36. package/dist/receiver/fastify/index.cjs.map +1 -1
  37. package/dist/receiver/fastify/index.js +1 -1
  38. package/dist/receiver/hono/index.cjs +14 -14
  39. package/dist/receiver/hono/index.cjs.map +1 -1
  40. package/dist/receiver/hono/index.js +2 -2
  41. package/dist/receiver/index.cjs +19 -2746
  42. package/dist/receiver/index.cjs.map +1 -1
  43. package/dist/receiver/index.js +5 -2077
  44. package/dist/receiver/index.js.map +1 -1
  45. package/dist/receiver/trpc/index.cjs +12 -12
  46. package/dist/receiver/trpc/index.cjs.map +1 -1
  47. package/dist/receiver/trpc/index.js +1 -1
  48. package/dist/sse/index.cjs +21 -21
  49. package/dist/sse/index.cjs.map +1 -1
  50. package/dist/sse/index.js +24 -24
  51. package/dist/sse/index.js.map +1 -1
  52. package/dist/webhook/index.cjs +14 -34
  53. package/dist/webhook/index.cjs.map +1 -1
  54. package/dist/webhook/index.js +14 -32
  55. package/dist/webhook/index.js.map +1 -1
  56. package/package.json +34 -12
  57. package/dist/chunk-NOIXOF2I.js.map +0 -1
  58. package/dist/dist-NWMJQI4E.js +0 -647
  59. package/dist/dist-NWMJQI4E.js.map +0 -1
package/README.md CHANGED
@@ -31,6 +31,7 @@ Three independent subpath exports:
31
31
  | `@rotorsoft/act-http/receiver/express` | `webhookMiddleware` — Express middleware adapter. |
32
32
  | `@rotorsoft/act-http/receiver/fastify` | `webhookMiddleware` — Fastify `preHandler` adapter. |
33
33
  | `@rotorsoft/act-http/receiver/hono` | `webhookMiddleware` — Hono middleware adapter. |
34
+ | `@rotorsoft/act-http/api` | `ActorExtractor` type, `ApiError` + `ERROR_MAP` + `toApiError` envelope mapping, `withIdempotency` wrapper. Shared utilities for the auto-generated API surfaces (`/trpc`, `/hono`, `/openapi` subpaths, landing under issues #843/#844/#845). |
34
35
 
35
36
  ## Quick start
36
37
 
@@ -188,6 +189,17 @@ Each framework adapter exports a single function `webhookMiddleware(options)` th
188
189
  | `/receiver/fastify` | `request.idempotency` | `reply.status(...).send({ error: reason })` |
189
190
  | `/receiver/hono` | `c.get("idempotency")` (typed via `Variables`) | `c.json({ error: reason }, status)` |
190
191
 
192
+ ### `/api` subpath
193
+
194
+ Shared utilities consumed by every transport in the auto-generated API umbrella (act-http-api epic #835). Three concerns surfaced once, not per-transport:
195
+
196
+ - **`ActorExtractor`** — type alias `(request: unknown) => Actor | Promise<Actor>`. The host-supplied closure resolving an `Actor` from an incoming request. Required on every transport (`trpc(app, { actor })`, `hono(app, { actor })`). Auth (JWT, session, API key) stays in the host; the package only asks for this function.
197
+ - **`ApiError`** — uniform envelope `{ error, detail?, code? }` shipped over the wire by every transport. Hosts get the same shape from REST, tRPC, and OpenAPI.
198
+ - **`ERROR_MAP`** — `as const` table mapping framework error types to `{ status, code }`. `ValidationError → 422 / VALIDATION`, `InvariantError → 409 / INVARIANT`, `ConcurrencyError → 412 / CONCURRENCY`, `StreamClosedError → 410 / STREAM_CLOSED`, `NonRetryableError → 400 / NON_RETRYABLE`.
199
+ - **`toApiError(err) → { status, body }`** — the single mapping helper every transport calls in its error boundary. Known framework errors map per `ERROR_MAP`; everything else surfaces as 500 / `INTERNAL` (with `detail` only when the throw was an `Error` — thrown strings or objects don't leak payloads).
200
+ - **`withIdempotency(store, key, handler)`** — wraps an action handler in an `Idempotency-Key` claim. Reuses `@rotorsoft/act-ops/idempotency` — same contract `@rotorsoft/act-http/receiver` already speaks, so one `IdempotencyStore` covers both halves of the "Act over the wire" surface. Returns `{ deduped: false, result }` on fresh claim, `{ deduped: true }` on duplicate (handler is not called).
201
+ - **Types**: `IdempotencyResult<T>`, `ErrorMapEntry`.
202
+
191
203
  ### `/sse` subpath
192
204
 
193
205
  - **`BroadcastChannel<S>`** — server-side broadcast manager with per-stream subscriber sets and an LRU state cache.