@jini-ai/http-kit 0.3.8 → 0.4.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 (60) hide show
  1. package/CHANGELOG.md +177 -0
  2. package/README.md +71 -98
  3. package/dist/adapter.d.ts +21 -6
  4. package/dist/adapter.js +47 -17
  5. package/dist/api-security-middleware.d.ts +27 -17
  6. package/dist/api-security-middleware.js +27 -36
  7. package/dist/compat.d.ts +12 -17
  8. package/dist/compat.js +4 -12
  9. package/dist/db-ops.d.ts +3 -3
  10. package/dist/db-ops.js +3 -3
  11. package/dist/delegated-tools.d.ts +9 -78
  12. package/dist/delegated-tools.js +27 -95
  13. package/dist/index.d.ts +21 -70
  14. package/dist/index.js +12 -32
  15. package/dist/local-daemon-request.d.ts +18 -8
  16. package/dist/local-daemon-request.js +23 -32
  17. package/dist/memory.d.ts +1 -1
  18. package/dist/middleware.d.ts +20 -0
  19. package/dist/middleware.js +21 -0
  20. package/dist/observability.d.ts +29 -0
  21. package/dist/observability.js +22 -0
  22. package/dist/origin.d.ts +8 -6
  23. package/dist/origin.js +8 -5
  24. package/dist/pack-http.d.ts +12 -8
  25. package/dist/pack-http.js +3 -3
  26. package/dist/rate-limit.d.ts +97 -0
  27. package/dist/rate-limit.js +94 -0
  28. package/dist/raw-sse.d.ts +7 -2
  29. package/dist/raw-sse.js +6 -7
  30. package/dist/read-only-tools.d.ts +67 -0
  31. package/dist/read-only-tools.js +59 -0
  32. package/dist/remote-run-events.js +1 -1
  33. package/dist/request.d.ts +8 -2
  34. package/dist/request.js +4 -4
  35. package/dist/response.d.ts +16 -4
  36. package/dist/response.js +7 -5
  37. package/dist/route-registration-guard.d.ts +13 -5
  38. package/dist/route-registration-guard.js +6 -6
  39. package/dist/sse.d.ts +25 -9
  40. package/dist/sse.js +10 -10
  41. package/dist/tool-catalog.d.ts +3 -3
  42. package/dist/types.d.ts +52 -15
  43. package/dist/types.js +2 -2
  44. package/dist/verified-origin/configured-origin.d.ts +37 -0
  45. package/dist/verified-origin/configured-origin.js +112 -0
  46. package/dist/verified-origin/index.d.ts +7 -0
  47. package/dist/verified-origin/index.js +6 -0
  48. package/dist/verified-origin/origin.d.ts +65 -0
  49. package/dist/verified-origin/origin.js +151 -0
  50. package/dist/verified-origin/ports.d.ts +40 -0
  51. package/dist/verified-origin/ports.js +2 -0
  52. package/dist/verified-origin/repo.memory.d.ts +34 -0
  53. package/dist/verified-origin/repo.memory.js +34 -0
  54. package/dist/verified-origin/site-path.d.ts +113 -0
  55. package/dist/verified-origin/site-path.js +179 -0
  56. package/dist/verified-origin/types.d.ts +33 -0
  57. package/dist/verified-origin/types.js +23 -0
  58. package/dist/verified-origin.d.ts +2 -0
  59. package/dist/verified-origin.js +2 -0
  60. package/package.json +52 -11
@@ -0,0 +1,34 @@
1
+ import { createVerifiedOrigin } from "./types.js";
2
+ /** Seeded read adapter that returns copies of origins and lists to protect stored trust.
3
+ * Reads are O(1) for an origin, O(k) for an allowlist; construction is O(total seed host bytes).
4
+ * @example new InMemoryOriginSettingRepo({ seeds: [{ workspaceId, origin }] });
5
+ */
6
+ export class InMemoryOriginSettingRepo {
7
+ origins;
8
+ redirectAllowlists;
9
+ egressAllowlists;
10
+ constructor({ seeds }) {
11
+ this.origins = new Map();
12
+ this.redirectAllowlists = new Map();
13
+ this.egressAllowlists = new Map();
14
+ for (const seed of seeds) {
15
+ this.origins.set(seed.workspaceId, createVerifiedOrigin(seed.origin));
16
+ this.redirectAllowlists.set(seed.workspaceId, normalizeHostList(seed.redirectAllowlist));
17
+ this.egressAllowlists.set(seed.workspaceId, normalizeHostList(seed.egressAllowlist));
18
+ }
19
+ }
20
+ async findByWorkspaceId({ workspaceId }) {
21
+ const origin = this.origins.get(workspaceId);
22
+ return origin ? { ...origin } : null;
23
+ }
24
+ async findRedirectAllowlist({ workspaceId }) {
25
+ return [...(this.redirectAllowlists.get(workspaceId) ?? [])];
26
+ }
27
+ async findEgressAllowlist({ workspaceId }) {
28
+ return [...(this.egressAllowlists.get(workspaceId) ?? [])];
29
+ }
30
+ }
31
+ function normalizeHostList(hosts) {
32
+ return (hosts ?? []).map((host) => host.trim().toLowerCase());
33
+ }
34
+ //# sourceMappingURL=repo.memory.js.map
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @file Shared site-path checks: decoded, dot-resolved segments and origin tracking.
3
+ *
4
+ * Why the rule is not `path.startsWith("/admin")`:
5
+ * - `/administer-survey` is ordinary site content and must keep working, so the comparison is per
6
+ * SEGMENT, not per prefix.
7
+ * - `/%61dmin` is compared AFTER one percent-decode, not on the raw bytes. Express (which routes on
8
+ * the raw path) and browsers (which do not decode `%61` in a path) do NOT treat it as `/admin`; a
9
+ * proxy or server that decodes before routing does. Refusing it is deliberate over-refusal — the
10
+ * safe direction for a rule whose job is to keep public redirects and fetches off the admin
11
+ * surface.
12
+ * - `/ADMIN` reaches the same Express mount (Express matches paths case-insensitively by default),
13
+ * so the comparison is case-folded.
14
+ * - `/blog/../admin` is `/admin` by the time a browser issues the request, so dot segments are
15
+ * resolved first.
16
+ *
17
+ */
18
+ /** {@link checkSitePathname}'s verdict. Every arm is a refusal except `ok`. */
19
+ export type SitePathCheck = {
20
+ kind: "ok";
21
+ }
22
+ /** `decodeURIComponent` threw — a stray or truncated `%` sequence. */
23
+ | {
24
+ kind: "malformed-encoding";
25
+ }
26
+ /** Decodes to a backslash (a `/` to URL parsers) or a C0/C1 control character (CR/LF splitting). */
27
+ | {
28
+ kind: "disallowed-character";
29
+ } | {
30
+ kind: "reserved";
31
+ surface: string;
32
+ };
33
+ /** {@link checkSiteRelativeTarget}'s verdict — {@link SitePathCheck} plus the two structural arms
34
+ * that only apply when the input is still a raw, unparsed reference. */
35
+ export type SiteRelativeTargetCheck = SitePathCheck
36
+ /** `new URL()` could not parse it at all. */
37
+ | {
38
+ kind: "unparseable";
39
+ }
40
+ /** Parses, but resolves to a DIFFERENT host — e.g. `/\evil.example`, which starts with a single
41
+ * slash yet is `//evil.example` to a URL parser, so a `startsWith("//")` test never sees it. */
42
+ | {
43
+ kind: "off-origin";
44
+ };
45
+ /**
46
+ * Whether `value` contains a C0 or C1 control character.
47
+ *
48
+ * CR/LF in a request target is HTTP request splitting and in a `Location` header is response
49
+ * splitting; NUL and friends are path-truncation tricks.
50
+ *
51
+ * @param required.value - Any string, already decoded or not.
52
+ * @returns `true` if any code unit is in `U+0000`–`U+001F` or `U+007F`–`U+009F`.
53
+ * @complexity O(n) in the string length.
54
+ * @example hasControlCharacter({ value: "/ok" }, {}); // => false
55
+ */
56
+ export declare function hasControlCharacter({ value }: {
57
+ value: string;
58
+ }, _optional?: Record<string, never>): boolean;
59
+ /**
60
+ * Classify an already-parsed URL's pathname against the admin application's URL space.
61
+ *
62
+ * Takes the {@link URL} itself, not a bare pathname string, so this cannot be handed a raw,
63
+ * unparsed reference by accident: a string has no way to prove it went through `new URL()` first,
64
+ * and this rule's whole design (see the module doc) depends on comparing the DECODED, dot-resolved
65
+ * form a URL parser would actually produce. A caller that only has a raw string — a stored redirect
66
+ * target, anything from user input — must go through {@link checkSiteRelativeTarget} instead, which
67
+ * parses it (and rejects what doesn't parse) before this check ever runs.
68
+ *
69
+ * PRECONDITION: the caller has already established that `url` is on the site's own origin. This
70
+ * function reads only `pathname`, so `new URL("//admin", base)` (host `admin`, pathname `/`)
71
+ * returns `ok`. It deliberately does not compare origins itself: `platform/routing` cannot use
72
+ * `features/origin`'s normalizer, and a string `URL.origin` comparison is wrong for redirect
73
+ * candidates (`https://site./admin`). Callers: `checkSiteRelativeTarget` (probe-origin check),
74
+ * `site-inspection`'s `resolveWithinOrigin`, and `features/redirects/reserved-destination.ts` (the
75
+ * origin oracle's `isSameOrigin`).
76
+ *
77
+ * @param required.url - An already-parsed `URL`; only `url.pathname` is read.
78
+ * @param required.reservedSegments - First segments reserved by the host, stored case-folded.
79
+ * @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
80
+ * @complexity O(n) in the pathname length.
81
+ * @example checkSitePathname({ url: new URL("/administer-survey", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
82
+ * @example checkSitePathname({ url: new URL("/%61dmin/settings", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "reserved", surface: "admin" }
83
+ */
84
+ export declare function checkSitePathname({ url, reservedSegments }: {
85
+ url: URL;
86
+ reservedSegments: ReadonlySet<string>;
87
+ }, _optional?: Record<string, never>): SitePathCheck;
88
+ /**
89
+ * Classify a raw, site-relative reference (a stored redirect target, a caller-supplied path)
90
+ * against the admin application's URL space, including the structural check that it is site-
91
+ * relative at all.
92
+ *
93
+ * The structural pass runs FIRST and matters on its own: `/\evil.example` begins with exactly one
94
+ * slash, so a `startsWith("//")` or scheme test calls it site-relative, while `new URL()` — and
95
+ * every browser following a `Location` — reads the backslash as a separator and lands on
96
+ * `evil.example`. Resolving against a probe origin and asserting the origin TRACKED that base is a
97
+ * structural answer to that instead of a pattern someone has to keep correct — done against two
98
+ * different bases so the probe origin itself is not a nameable way to pass (see
99
+ * {@link PROBE_ORIGIN}).
100
+ *
101
+ * @param required.raw - The untrusted reference, expected to be site-relative.
102
+ * @param required.reservedSegments - First segments reserved by the host, stored case-folded.
103
+ * @returns `{ kind: "ok" }` when it stays on this site and names ordinary content; otherwise the
104
+ * arm naming the refusal.
105
+ * @complexity O(n) in the reference length.
106
+ * @example checkSiteRelativeTarget({ raw: "/new", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
107
+ * @example checkSiteRelativeTarget({ raw: "/\\evil.example", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "off-origin" }
108
+ */
109
+ export declare function checkSiteRelativeTarget({ raw, reservedSegments }: {
110
+ raw: string;
111
+ reservedSegments: ReadonlySet<string>;
112
+ }, _optional?: Record<string, never>): SiteRelativeTargetCheck;
113
+ //# sourceMappingURL=site-path.d.ts.map
@@ -0,0 +1,179 @@
1
+ /**
2
+ * @file Shared site-path checks: decoded, dot-resolved segments and origin tracking.
3
+ *
4
+ * Why the rule is not `path.startsWith("/admin")`:
5
+ * - `/administer-survey` is ordinary site content and must keep working, so the comparison is per
6
+ * SEGMENT, not per prefix.
7
+ * - `/%61dmin` is compared AFTER one percent-decode, not on the raw bytes. Express (which routes on
8
+ * the raw path) and browsers (which do not decode `%61` in a path) do NOT treat it as `/admin`; a
9
+ * proxy or server that decodes before routing does. Refusing it is deliberate over-refusal — the
10
+ * safe direction for a rule whose job is to keep public redirects and fetches off the admin
11
+ * surface.
12
+ * - `/ADMIN` reaches the same Express mount (Express matches paths case-insensitively by default),
13
+ * so the comparison is case-folded.
14
+ * - `/blog/../admin` is `/admin` by the time a browser issues the request, so dot segments are
15
+ * resolved first.
16
+ *
17
+ */
18
+ /**
19
+ * Two hosts this deployment can never actually reach, used only so `new URL()` has a base to
20
+ * resolve a site-relative reference against. `.invalid` is reserved by RFC 2606 precisely for this.
21
+ *
22
+ * There are TWO because one base is NAMEABLE (t85 independent review, 2026-09-16). With a single
23
+ * base, `//reserved-path-probe.invalid/x` resolves to that very origin, so "did the origin survive"
24
+ * answered yes for a reference that leaves the site — reachable as `/store/buy`'s `returnTo`, which
25
+ * sent `Location: //reserved-path-probe.invalid/x`. Requiring the resolved origin to TRACK whichever
26
+ * base it was given leaves no origin an input can name, which is a structural answer rather than a
27
+ * denylist of the sentinel's spellings (the same reasoning as the probe itself — see
28
+ * {@link checkSiteRelativeTarget}). Both are bare origins, so a reference resolves to the same
29
+ * pathname against either.
30
+ */
31
+ const PROBE_ORIGIN = "http://reserved-path-probe.invalid";
32
+ const SECOND_PROBE_ORIGIN = "http://reserved-path-probe-2.invalid";
33
+ /**
34
+ * Whether `value` contains a C0 or C1 control character.
35
+ *
36
+ * CR/LF in a request target is HTTP request splitting and in a `Location` header is response
37
+ * splitting; NUL and friends are path-truncation tricks.
38
+ *
39
+ * @param required.value - Any string, already decoded or not.
40
+ * @returns `true` if any code unit is in `U+0000`–`U+001F` or `U+007F`–`U+009F`.
41
+ * @complexity O(n) in the string length.
42
+ * @example hasControlCharacter({ value: "/ok" }, {}); // => false
43
+ */
44
+ export function hasControlCharacter({ value }, _optional = {}) {
45
+ for (let index = 0; index < value.length; index += 1) {
46
+ const code = value.charCodeAt(index);
47
+ if (code <= 0x1f || (code >= 0x7f && code <= 0x9f))
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ /**
53
+ * Resolve `.` and `..` segments, RFC 3986 §5.2.4 style, on an already-decoded path.
54
+ *
55
+ * Done by hand rather than with a second `new URL()` pass because a decoded path can contain a
56
+ * literal `?` or `#` (from `%3F`/`%23`), and the URL parser would treat those as a query/fragment
57
+ * delimiter and TRUNCATE the path — turning `/x#/../admin` into `/x` and losing the very segment
58
+ * this check exists to find. A browser does no such thing: it never decodes `%23` before splitting
59
+ * the path, so the truncation would be a false negative, not a match for real behavior.
60
+ *
61
+ * Empty segments are dropped, so `//admin` collapses to `/admin`. That is deliberately stricter
62
+ * than a URL parser (which preserves `//`); over-matching here only ever refuses more.
63
+ *
64
+ * @param path - A decoded path, expected to start with `/`.
65
+ * @returns The path with dot segments removed, always starting with `/`.
66
+ * @complexity O(n) in the path length.
67
+ * @example resolveDotSegments("/blog/../admin"); // => "/admin"
68
+ */
69
+ function resolveDotSegments(path) {
70
+ const out = [];
71
+ for (const segment of path.split("/")) {
72
+ if (segment === "" || segment === ".")
73
+ continue;
74
+ if (segment === "..") {
75
+ out.pop();
76
+ continue;
77
+ }
78
+ out.push(segment);
79
+ }
80
+ return `/${out.join("/")}`;
81
+ }
82
+ /**
83
+ * The actual per-segment rule, on a pathname string that is guaranteed to have come from a real
84
+ * `URL` (see {@link checkSitePathname}, this function's only caller). Kept private: a bare
85
+ * string carries no proof it was ever parsed — the query/fragment stripping, dot-segment removal
86
+ * relative to a real origin, etc. are exactly what `new URL()` already did before that caller
87
+ * reaches this. Do not export this directly.
88
+ *
89
+ * Order is load-bearing: decode ONCE, then resolve dot segments, then compare the first segment
90
+ * case-folded. Decoding first is what catches `/%61dmin` (over-refusal for Express and browsers, a
91
+ * real match for a decoding proxy — see the module doc); resolving dot segments after the decode is
92
+ * what catches `/blog/%2e%2e/admin`. Exactly one decode pass models one decoding intermediary:
93
+ * `/%2561dmin` would need two, so it stays allowed.
94
+ *
95
+ * @param pathname - An already-parsed `URL`'s `.pathname` (no query, no fragment).
96
+ * @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
97
+ * @complexity O(n) in the pathname length.
98
+ */
99
+ function checkDecodedSitePathname(pathname, reservedSegments) {
100
+ let decoded;
101
+ try {
102
+ decoded = decodeURIComponent(pathname);
103
+ }
104
+ catch {
105
+ return { kind: "malformed-encoding" };
106
+ }
107
+ if (decoded.includes("\\") || hasControlCharacter({ value: decoded }, {}))
108
+ return { kind: "disallowed-character" };
109
+ const first = (resolveDotSegments(decoded).split("/")[1] ?? "").toLowerCase();
110
+ if (reservedSegments.has(first))
111
+ return { kind: "reserved", surface: first };
112
+ return { kind: "ok" };
113
+ }
114
+ /**
115
+ * Classify an already-parsed URL's pathname against the admin application's URL space.
116
+ *
117
+ * Takes the {@link URL} itself, not a bare pathname string, so this cannot be handed a raw,
118
+ * unparsed reference by accident: a string has no way to prove it went through `new URL()` first,
119
+ * and this rule's whole design (see the module doc) depends on comparing the DECODED, dot-resolved
120
+ * form a URL parser would actually produce. A caller that only has a raw string — a stored redirect
121
+ * target, anything from user input — must go through {@link checkSiteRelativeTarget} instead, which
122
+ * parses it (and rejects what doesn't parse) before this check ever runs.
123
+ *
124
+ * PRECONDITION: the caller has already established that `url` is on the site's own origin. This
125
+ * function reads only `pathname`, so `new URL("//admin", base)` (host `admin`, pathname `/`)
126
+ * returns `ok`. It deliberately does not compare origins itself: `platform/routing` cannot use
127
+ * `features/origin`'s normalizer, and a string `URL.origin` comparison is wrong for redirect
128
+ * candidates (`https://site./admin`). Callers: `checkSiteRelativeTarget` (probe-origin check),
129
+ * `site-inspection`'s `resolveWithinOrigin`, and `features/redirects/reserved-destination.ts` (the
130
+ * origin oracle's `isSameOrigin`).
131
+ *
132
+ * @param required.url - An already-parsed `URL`; only `url.pathname` is read.
133
+ * @param required.reservedSegments - First segments reserved by the host, stored case-folded.
134
+ * @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
135
+ * @complexity O(n) in the pathname length.
136
+ * @example checkSitePathname({ url: new URL("/administer-survey", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
137
+ * @example checkSitePathname({ url: new URL("/%61dmin/settings", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "reserved", surface: "admin" }
138
+ */
139
+ export function checkSitePathname({ url, reservedSegments }, _optional = {}) {
140
+ return checkDecodedSitePathname(url.pathname, reservedSegments);
141
+ }
142
+ /**
143
+ * Classify a raw, site-relative reference (a stored redirect target, a caller-supplied path)
144
+ * against the admin application's URL space, including the structural check that it is site-
145
+ * relative at all.
146
+ *
147
+ * The structural pass runs FIRST and matters on its own: `/\evil.example` begins with exactly one
148
+ * slash, so a `startsWith("//")` or scheme test calls it site-relative, while `new URL()` — and
149
+ * every browser following a `Location` — reads the backslash as a separator and lands on
150
+ * `evil.example`. Resolving against a probe origin and asserting the origin TRACKED that base is a
151
+ * structural answer to that instead of a pattern someone has to keep correct — done against two
152
+ * different bases so the probe origin itself is not a nameable way to pass (see
153
+ * {@link PROBE_ORIGIN}).
154
+ *
155
+ * @param required.raw - The untrusted reference, expected to be site-relative.
156
+ * @param required.reservedSegments - First segments reserved by the host, stored case-folded.
157
+ * @returns `{ kind: "ok" }` when it stays on this site and names ordinary content; otherwise the
158
+ * arm naming the refusal.
159
+ * @complexity O(n) in the reference length.
160
+ * @example checkSiteRelativeTarget({ raw: "/new", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
161
+ * @example checkSiteRelativeTarget({ raw: "/\\evil.example", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "off-origin" }
162
+ */
163
+ export function checkSiteRelativeTarget({ raw, reservedSegments }, _optional = {}) {
164
+ if (hasControlCharacter({ value: raw }, {}))
165
+ return { kind: "disallowed-character" };
166
+ let parsed;
167
+ let reparsed;
168
+ try {
169
+ parsed = new URL(raw, PROBE_ORIGIN);
170
+ reparsed = new URL(raw, SECOND_PROBE_ORIGIN);
171
+ }
172
+ catch {
173
+ return { kind: "unparseable" };
174
+ }
175
+ if (parsed.origin !== PROBE_ORIGIN || reparsed.origin !== SECOND_PROBE_ORIGIN)
176
+ return { kind: "off-origin" };
177
+ return checkSitePathname({ url: parsed, reservedSegments }, {});
178
+ }
179
+ //# sourceMappingURL=site-path.js.map
@@ -0,0 +1,33 @@
1
+ type ISODateTime = string;
2
+ /** Canonical links, redirect checks and egress decisions must use stored trust evidence,
3
+ * never the raw request Host/:authority, which is attacker-controlled. */
4
+ export type OriginScheme = "https" | "http";
5
+ export type OriginSource = "workspace-setting" | "dev-capability";
6
+ /** Stored trust evidence. Public origins use HTTPS; HTTP is limited to explicit development capabilities. */
7
+ export interface VerifiedOrigin {
8
+ scheme: OriginScheme;
9
+ host: string;
10
+ port?: number;
11
+ basePath?: string;
12
+ verifiedAt: ISODateTime;
13
+ source: OriginSource;
14
+ }
15
+ export declare class InsecureOriginSourceError extends Error {
16
+ constructor({ message }: {
17
+ message: string;
18
+ });
19
+ }
20
+ /** Missing trust evidence is a hard precondition failure. Callers must fail closed rather than
21
+ * guessing an origin from the request or another unverified value. */
22
+ export declare class OriginNotVerifiedError extends Error {
23
+ constructor({ message }: {
24
+ message: string;
25
+ });
26
+ }
27
+ /** Copy stored evidence, rejecting an HTTP public origin with InsecureOriginSourceError.
28
+ * @complexity O(1) time and space; pure, with no ownership or reachability probe.
29
+ * @example createVerifiedOrigin({ scheme: "https", host: "example.com", verifiedAt, source: "workspace-setting" });
30
+ */
31
+ export declare function createVerifiedOrigin(input: VerifiedOrigin): VerifiedOrigin;
32
+ export {};
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,23 @@
1
+ export class InsecureOriginSourceError extends Error {
2
+ constructor({ message }) { super(message); }
3
+ }
4
+ /** Missing trust evidence is a hard precondition failure. Callers must fail closed rather than
5
+ * guessing an origin from the request or another unverified value. */
6
+ export class OriginNotVerifiedError extends Error {
7
+ constructor({ message }) { super(message); }
8
+ }
9
+ /** Copy stored evidence, rejecting an HTTP public origin with InsecureOriginSourceError.
10
+ * @complexity O(1) time and space; pure, with no ownership or reachability probe.
11
+ * @example createVerifiedOrigin({ scheme: "https", host: "example.com", verifiedAt, source: "workspace-setting" });
12
+ */
13
+ export function createVerifiedOrigin(input) {
14
+ // Repositories and other adapters must construct evidence through this function; an object
15
+ // literal can bypass the scheme/source invariant even though it satisfies the structural type.
16
+ if (input.scheme === "http" && input.source !== "dev-capability") {
17
+ throw new InsecureOriginSourceError({
18
+ message: `origin scheme 'http' is only legal for source 'dev-capability' (got source '${input.source}')`
19
+ });
20
+ }
21
+ return { ...input };
22
+ }
23
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,2 @@
1
+ export * from "./verified-origin/index.js";
2
+ //# sourceMappingURL=verified-origin.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "./verified-origin/index.js";
2
+ //# sourceMappingURL=verified-origin.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jini-ai/http-kit",
3
- "version": "0.3.8",
4
- "description": "Composable Express route packs and JSON-route transport for a @jini-ai/core daemon composition: request parsing, response serialization, same-origin guard, and a route-pack registrar.",
3
+ "version": "0.4.1",
4
+ "description": "Generic Express transport primitives, request parsing, response serialization, origin guards and route-pack mounting.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -11,6 +11,13 @@
11
11
  "jini": {
12
12
  "domain": "server",
13
13
  "kind": "transport",
14
+ "entries": {
15
+ ".": "node",
16
+ "./rate-limit": "node",
17
+ "./middleware": "node",
18
+ "./verified-origin": "universal",
19
+ "./observability": "node"
20
+ },
14
21
  "runtime": "node"
15
22
  },
16
23
  "type": "module",
@@ -22,10 +29,33 @@
22
29
  "types": "./dist/index.d.ts",
23
30
  "import": "./dist/index.js",
24
31
  "default": "./dist/index.js"
32
+ },
33
+ "./rate-limit": {
34
+ "types": "./dist/rate-limit.d.ts",
35
+ "import": "./dist/rate-limit.js",
36
+ "default": "./dist/rate-limit.js"
37
+ },
38
+ "./middleware": {
39
+ "types": "./dist/middleware.d.ts",
40
+ "import": "./dist/middleware.js",
41
+ "default": "./dist/middleware.js"
42
+ },
43
+ "./verified-origin": {
44
+ "types": "./dist/verified-origin.d.ts",
45
+ "import": "./dist/verified-origin.js",
46
+ "default": "./dist/verified-origin.js"
47
+ },
48
+ "./observability": {
49
+ "types": "./dist/observability.d.ts",
50
+ "import": "./dist/observability.js",
51
+ "default": "./dist/observability.js"
25
52
  }
26
53
  },
27
54
  "files": [
28
55
  "dist",
56
+ "README.md",
57
+ "CHANGELOG.md",
58
+ "LICENSE",
29
59
  "!dist/**/*.test.js",
30
60
  "!dist/**/*.test.d.ts",
31
61
  "!dist/**/*.test.js.map",
@@ -37,18 +67,29 @@
37
67
  "access": "public",
38
68
  "registry": "https://registry.npmjs.org"
39
69
  },
40
- "dependencies": {
41
- "express": "^4.21.0",
42
- "@jini-ai/core": "0.3.1",
43
- "@jini-ai/protocol": "0.3.1",
44
- "@jini-ai/platform": "0.3.0",
45
- "@jini-ai/daemon": "0.3.8",
46
- "@jini-ai/agent-runtime": "0.3.10"
47
- },
48
70
  "devDependencies": {
49
71
  "@types/express": "^4.17.21",
50
72
  "@vitest/coverage-v8": "^2.1.9",
51
- "@jini-ai/chat": "0.3.11"
73
+ "express": "^4.21.0",
74
+ "@jini-ai/core": "0.4.2",
75
+ "@jini-ai/protocol": "0.4.2",
76
+ "@jini-ai/platform": "0.5.2"
77
+ },
78
+ "dependencies": {
79
+ "@jini-ai/core": "^0.4.2",
80
+ "@jini-ai/protocol": "^0.4.2"
81
+ },
82
+ "peerDependencies": {
83
+ "@jini-ai/platform": "^0.5.1",
84
+ "express": "^4.21.0"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "@jini-ai/platform": {
88
+ "optional": true
89
+ },
90
+ "express": {
91
+ "optional": true
92
+ }
52
93
  },
53
94
  "scripts": {
54
95
  "build": "tsc -p tsconfig.json",