@jini-ai/http-kit 0.3.8 → 0.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +71 -98
  3. package/dist/adapter.d.ts +13 -5
  4. package/dist/adapter.js +17 -15
  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 +140 -59
  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 +15 -13
  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 +6 -0
  47. package/dist/verified-origin/index.js +5 -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/types.d.ts +33 -0
  55. package/dist/verified-origin/types.js +23 -0
  56. package/dist/verified-origin.d.ts +2 -0
  57. package/dist/verified-origin.js +2 -0
  58. package/package.json +36 -9
@@ -0,0 +1,40 @@
1
+ type UUID = string;
2
+ import type { VerifiedOrigin } from "./types.js";
3
+ export interface VerifiedOriginRequestContext {
4
+ workspaceId: UUID;
5
+ siteId?: UUID;
6
+ locale?: string;
7
+ }
8
+ export interface RedirectTargetContext {
9
+ workspaceId: UUID;
10
+ siteId?: UUID;
11
+ originKey?: string;
12
+ }
13
+ export interface EgressTargetContext {
14
+ workspaceId: UUID;
15
+ siteId?: UUID;
16
+ }
17
+ export interface OriginRegistryPort {
18
+ canonicalOrigin(ctx: VerifiedOriginRequestContext): Promise<VerifiedOrigin>;
19
+ isAllowedRedirectTarget(required: {
20
+ context: RedirectTargetContext;
21
+ url: string;
22
+ }): Promise<boolean>;
23
+ isAllowedEgressTarget(required: {
24
+ context: EgressTargetContext;
25
+ url: string;
26
+ }): Promise<boolean>;
27
+ }
28
+ export interface OriginSettingRepoPort {
29
+ findByWorkspaceId(required: {
30
+ workspaceId: UUID;
31
+ }): Promise<VerifiedOrigin | null>;
32
+ findRedirectAllowlist(required: {
33
+ workspaceId: UUID;
34
+ }): Promise<string[]>;
35
+ findEgressAllowlist(required: {
36
+ workspaceId: UUID;
37
+ }): Promise<string[]>;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1,34 @@
1
+ type UUID = string;
2
+ import type { OriginSettingRepoPort } from "./ports.js";
3
+ import { type VerifiedOrigin } from "./types.js";
4
+ export interface OriginSettingSeed {
5
+ workspaceId: UUID;
6
+ origin: VerifiedOrigin;
7
+ /** Exact-match hosts trusted for cross-origin redirects; independent of third-party egress. */
8
+ redirectAllowlist?: string[];
9
+ /** Exact-match hosts trusted for third-party egress; redirect permission alone does not grant it. */
10
+ egressAllowlist?: string[];
11
+ }
12
+ /** Seeded read adapter that returns copies of origins and lists to protect stored trust.
13
+ * Reads are O(1) for an origin, O(k) for an allowlist; construction is O(total seed host bytes).
14
+ * @example new InMemoryOriginSettingRepo({ seeds: [{ workspaceId, origin }] });
15
+ */
16
+ export declare class InMemoryOriginSettingRepo implements OriginSettingRepoPort {
17
+ private readonly origins;
18
+ private readonly redirectAllowlists;
19
+ private readonly egressAllowlists;
20
+ constructor({ seeds }: {
21
+ seeds: readonly OriginSettingSeed[];
22
+ });
23
+ findByWorkspaceId({ workspaceId }: {
24
+ workspaceId: UUID;
25
+ }): Promise<VerifiedOrigin | null>;
26
+ findRedirectAllowlist({ workspaceId }: {
27
+ workspaceId: UUID;
28
+ }): Promise<string[]>;
29
+ findEgressAllowlist({ workspaceId }: {
30
+ workspaceId: UUID;
31
+ }): Promise<string[]>;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=repo.memory.d.ts.map
@@ -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,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.0",
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": "node",
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",
@@ -39,16 +69,13 @@
39
69
  },
40
70
  "dependencies": {
41
71
  "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"
72
+ "@jini-ai/core": "0.4.0",
73
+ "@jini-ai/protocol": "0.4.0",
74
+ "@jini-ai/platform": "0.5.0"
47
75
  },
48
76
  "devDependencies": {
49
77
  "@types/express": "^4.17.21",
50
- "@vitest/coverage-v8": "^2.1.9",
51
- "@jini-ai/chat": "0.3.11"
78
+ "@vitest/coverage-v8": "^2.1.9"
52
79
  },
53
80
  "scripts": {
54
81
  "build": "tsc -p tsconfig.json",