@invokta/gateway 0.0.0-stage → 0.10.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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +274 -2
  3. package/dist/access.d.ts +14 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/access.js +30 -0
  6. package/dist/access.js.map +1 -0
  7. package/dist/authentication.d.ts +49 -0
  8. package/dist/authentication.d.ts.map +1 -0
  9. package/dist/authentication.js +92 -0
  10. package/dist/authentication.js.map +1 -0
  11. package/dist/discovery.d.ts +81 -0
  12. package/dist/discovery.d.ts.map +1 -0
  13. package/dist/discovery.js +471 -0
  14. package/dist/discovery.js.map +1 -0
  15. package/dist/engine-upstream.d.ts +34 -0
  16. package/dist/engine-upstream.d.ts.map +1 -0
  17. package/dist/engine-upstream.js +110 -0
  18. package/dist/engine-upstream.js.map +1 -0
  19. package/dist/gateway.d.ts +32 -0
  20. package/dist/gateway.d.ts.map +1 -0
  21. package/dist/gateway.js +208 -0
  22. package/dist/gateway.js.map +1 -0
  23. package/dist/index.d.ts +10 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +8 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/json-schema-contract.d.ts +37 -0
  28. package/dist/json-schema-contract.d.ts.map +1 -0
  29. package/dist/json-schema-contract.js +131 -0
  30. package/dist/json-schema-contract.js.map +1 -0
  31. package/dist/mcp-upstream.d.ts +121 -0
  32. package/dist/mcp-upstream.d.ts.map +1 -0
  33. package/dist/mcp-upstream.js +401 -0
  34. package/dist/mcp-upstream.js.map +1 -0
  35. package/dist/patterns.d.ts +19 -0
  36. package/dist/patterns.d.ts.map +1 -0
  37. package/dist/patterns.js +57 -0
  38. package/dist/patterns.js.map +1 -0
  39. package/dist/search-index.d.ts +24 -0
  40. package/dist/search-index.d.ts.map +1 -0
  41. package/dist/search-index.js +102 -0
  42. package/dist/search-index.js.map +1 -0
  43. package/dist/types.d.ts +120 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +2 -0
  46. package/dist/types.js.map +1 -0
  47. package/dist/upstream-registry.d.ts +5 -0
  48. package/dist/upstream-registry.d.ts.map +1 -0
  49. package/dist/upstream-registry.js +21 -0
  50. package/dist/upstream-registry.js.map +1 -0
  51. package/package.json +39 -4
@@ -0,0 +1,120 @@
1
+ import type { CapabilityAnnotations, CapabilityDeprecation, CapabilityErrorMap, EngineSchema, ExecutionContext, Principal } from "@invokta/core";
2
+ import type { JsonObject } from "./json-schema-contract.js";
3
+ /** Where a gateway capability is executed. */
4
+ export type GatewayUpstreamKind = "engine" | "mcp";
5
+ /** One published gateway capability and the upstream operation behind it. */
6
+ export interface GatewayUpstreamRoute {
7
+ /** The capability ID the gateway publishes. */
8
+ readonly capabilityId: string;
9
+ /** The configured upstream name. */
10
+ readonly upstream: string;
11
+ readonly kind: GatewayUpstreamKind;
12
+ /** The upstream capability ID, or the MCP tool name. */
13
+ readonly upstreamCapabilityId: string;
14
+ /**
15
+ * Whether the operation is trusted to be read-only: an engine upstream's
16
+ * `readOnly` annotation, or an MCP tool the operator vouched for with
17
+ * `trustAnnotations` or `readOnlyTools`. An MCP server's own hint alone
18
+ * never makes this `true`.
19
+ */
20
+ readonly readOnly: boolean;
21
+ }
22
+ /** A gateway route together with the name of the rule that governs it. */
23
+ export interface GatewayRoute extends GatewayUpstreamRoute {
24
+ /** The rule `name`, `rules[<index>]` when unnamed, or `default`. */
25
+ readonly rule: string;
26
+ }
27
+ /**
28
+ * A configured upstream. Create one with `engineUpstream` or `mcpUpstream`;
29
+ * the gateway only accepts values produced by those functions.
30
+ */
31
+ export interface GatewayUpstream {
32
+ readonly name: string;
33
+ readonly kind: GatewayUpstreamKind;
34
+ readonly routes: ReadonlyArray<GatewayUpstreamRoute>;
35
+ }
36
+ /** Arguments of a gateway access function. */
37
+ export interface GatewayAccessArgs {
38
+ readonly principal: Principal | null;
39
+ /**
40
+ * The input after the gateway's validation: the configured JSON Schema
41
+ * validator's, or only the structural check when validation is delegated
42
+ * to the upstream.
43
+ */
44
+ readonly input: JsonObject;
45
+ readonly context: ExecutionContext;
46
+ readonly route: GatewayUpstreamRoute;
47
+ }
48
+ export type GatewayAccessFunction = (args: GatewayAccessArgs) => boolean | Promise<boolean>;
49
+ /**
50
+ * The access a rule grants. `public` and `authenticated` keep their core
51
+ * meaning, `deny` refuses every caller, and a function allows only when it
52
+ * returns exactly `true`.
53
+ */
54
+ export type GatewayAccess = "public" | "authenticated" | "deny" | GatewayAccessFunction;
55
+ export interface GatewayRule {
56
+ /** A stable name reported in routes and decisions. */
57
+ readonly name?: string;
58
+ /**
59
+ * Gateway capability IDs this rule governs: an exact ID, a `prefix.*`
60
+ * pattern matching IDs that start with `prefix.`, or `*` for every ID.
61
+ */
62
+ readonly match: string | ReadonlyArray<string>;
63
+ readonly access: GatewayAccess;
64
+ /**
65
+ * Who sees the governed capabilities in listings and search. Defaults to
66
+ * the access itself for `public`, `authenticated`, `deny`, and
67
+ * `requireScopes`, and to every authenticated caller for other functions,
68
+ * which may depend on input a listing does not have. It receives the
69
+ * capability's route, so one rule can show reads and writes to different
70
+ * callers. It must be synchronous. Visibility never grants access.
71
+ */
72
+ readonly visible?: (principal: Principal | null, route: GatewayUpstreamRoute) => boolean;
73
+ }
74
+ /**
75
+ * The visibility option of `@invokta/mcp` and `@invokta/http`: whether one
76
+ * capability is listed for, and callable by, the authenticated principal.
77
+ */
78
+ export type GatewayVisibility = (args: {
79
+ readonly principal: Principal | null;
80
+ readonly capabilityId: string;
81
+ }) => boolean;
82
+ /** One authorization decision, free of input, output, and credentials. */
83
+ export interface GatewayDecision {
84
+ readonly requestId: string;
85
+ readonly capabilityId: string;
86
+ readonly upstream: string;
87
+ readonly rule: string;
88
+ /** `failed` means the access function threw and access was denied. */
89
+ readonly outcome: "allowed" | "denied" | "failed";
90
+ readonly principalId?: string;
91
+ }
92
+ export interface GatewayOptions {
93
+ readonly upstreams: ReadonlyArray<GatewayUpstream>;
94
+ /** Evaluated in order; the first rule matching a capability governs it. */
95
+ readonly rules?: ReadonlyArray<GatewayRule>;
96
+ /** Access for capabilities no rule matches. Defaults to `deny`. */
97
+ readonly defaultAccess?: GatewayAccess;
98
+ /** Receives every decision. Failures and returned promises are ignored. */
99
+ readonly onDecision?: (decision: GatewayDecision) => void | Promise<void>;
100
+ }
101
+ /**
102
+ * The upstream half of a gateway capability: everything except the access
103
+ * rule, which the gateway attaches from its policy.
104
+ */
105
+ export interface GatewayUpstreamCapability {
106
+ readonly route: GatewayUpstreamRoute;
107
+ readonly title?: string;
108
+ readonly description: string;
109
+ readonly input: EngineSchema<JsonObject>;
110
+ readonly output: EngineSchema<JsonObject>;
111
+ readonly timeoutMs?: number;
112
+ readonly annotations?: CapabilityAnnotations;
113
+ readonly deprecated?: CapabilityDeprecation;
114
+ readonly errors?: CapabilityErrorMap;
115
+ readonly run: (args: {
116
+ readonly input: JsonObject;
117
+ readonly context: ExecutionContext;
118
+ }) => Promise<JsonObject>;
119
+ }
120
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACV,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,8CAA8C;AAC9C,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEnD,6EAA6E;AAC7E,MAAM,WAAW,oBAAoB;IACnC,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,oCAAoC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC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AC;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IAC7C,QAAQ,CAAC,UAAU,CAAC,EAAE,qBAAqB,CAAC;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE;QACnB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;QAC3B,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;KACpC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CAC3B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { GatewayUpstream, GatewayUpstreamCapability, GatewayUpstreamKind } from "./types.js";
2
+ /** Freezes an upstream and records its capabilities for `createGateway`. */
3
+ export declare function registerUpstream(name: string, kind: GatewayUpstreamKind, capabilities: ReadonlyArray<GatewayUpstreamCapability>, extra?: Readonly<Record<string, unknown>>): GatewayUpstream;
4
+ export declare function upstreamCapabilities(upstream: unknown): ReadonlyArray<GatewayUpstreamCapability>;
5
+ //# sourceMappingURL=upstream-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream-registry.d.ts","sourceRoot":"","sources":["../src/upstream-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAOpB,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,mBAAmB,EACzB,YAAY,EAAE,aAAa,CAAC,yBAAyB,CAAC,EACtD,KAAK,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAC5C,eAAe,CAUjB;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,GAChB,aAAa,CAAC,yBAAyB,CAAC,CAQ1C"}
@@ -0,0 +1,21 @@
1
+ const registered = new WeakMap();
2
+ /** Freezes an upstream and records its capabilities for `createGateway`. */
3
+ export function registerUpstream(name, kind, capabilities, extra = {}) {
4
+ const frozenCapabilities = Object.freeze([...capabilities]);
5
+ const upstream = Object.freeze({
6
+ name,
7
+ kind,
8
+ routes: Object.freeze(frozenCapabilities.map(({ route }) => route)),
9
+ ...extra,
10
+ });
11
+ registered.set(upstream, frozenCapabilities);
12
+ return upstream;
13
+ }
14
+ export function upstreamCapabilities(upstream) {
15
+ const capabilities = registered.get(upstream);
16
+ if (capabilities === undefined) {
17
+ throw new TypeError("Gateway upstreams must be created by engineUpstream or mcpUpstream.");
18
+ }
19
+ return capabilities;
20
+ }
21
+ //# sourceMappingURL=upstream-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream-registry.js","sourceRoot":"","sources":["../src/upstream-registry.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,GAAG,IAAI,OAAO,EAG3B,CAAC;AAEJ,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,IAAyB,EACzB,YAAsD,EACtD,KAAK,GAAsC,EAAE;IAE7C,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI;QACJ,IAAI;QACJ,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QACnE,GAAG,KAAK;KACT,CAAC,CAAC;IACH,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;IAC7C,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,QAAiB;IAEjB,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,QAA2B,CAAC,CAAC;IACjE,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CACjB,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@invokta/gateway",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.10.0",
4
+ "description": "Gateway capabilities that serve several Action Engines and MCP servers behind one authenticated, policy-enforcing engine.",
5
+ "author": "Vini Lana <vini@aicoders.academy>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/vinilana/invokta.git",
10
+ "directory": "packages/gateway"
11
+ },
12
+ "homepage": "https://docs.invokta.dev/reference/gateway/",
13
+ "bugs": {
14
+ "url": "https://github.com/vinilana/invokta/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "type": "module",
20
+ "sideEffects": false,
21
+ "engines": {
22
+ "node": ">=22.20.0"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -b --pretty false",
36
+ "prepack": "npm run --silent build"
37
+ },
38
+ "dependencies": {
39
+ "@invokta/core": "0.10.0"
40
+ }
41
+ }