@voltro/api-client 0.85.0 → 0.87.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.
@@ -1,6 +1,6 @@
1
1
  # Third-Party Notices — @voltro/api-client
2
2
 
3
- This package depends on the open-source software listed below. Each is the
3
+ This package uses the open-source software listed below. Each is the
4
4
  property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/api-client itself, which is proprietary (see LICENSE).
@@ -0,0 +1,108 @@
1
+ //#region src/apiRoleEndpoints.ts
2
+ var e = (e, t) => {
3
+ if (!e || typeof e != "object" || Array.isArray(e) || ![Object.prototype, null].includes(Object.getPrototypeOf(e))) throw Error("Invalid role endpoint object");
4
+ let n = Object.create(null);
5
+ for (let r of Reflect.ownKeys(e)) {
6
+ let i = Object.getOwnPropertyDescriptor(e, r);
7
+ if (typeof r != "string" || !t.includes(r) || !i.enumerable || !("value" in i)) throw Error("Invalid role endpoint field");
8
+ n[r] = i.value;
9
+ }
10
+ return n;
11
+ }, t = (e, t, n = !1) => {
12
+ if (!Array.isArray(e) || e.length < +!n || e.length > t || Reflect.ownKeys(e).length !== e.length + 1) throw Error("Invalid role endpoint list");
13
+ let r = [];
14
+ for (let t = 0; t < e.length; t++) {
15
+ let n = Object.getOwnPropertyDescriptor(e, String(t));
16
+ if (!n?.enumerable || !("value" in n)) throw Error("Invalid role endpoint list item");
17
+ r.push(n.value);
18
+ }
19
+ return r;
20
+ }, n = /^(?:[A-Za-z][A-Za-z0-9_-]*\.)*[A-Za-z][A-Za-z0-9_-]*$/, r = /^(?:[A-Za-z_][A-Za-z0-9_-]*\.)*[A-Za-z_][A-Za-z0-9_-]*$/, i = [
21
+ "rpc",
22
+ "subscriptions",
23
+ "events",
24
+ "presence",
25
+ "workflows",
26
+ "schedules",
27
+ "directors",
28
+ "drainers",
29
+ "reapers",
30
+ "retention",
31
+ "rest",
32
+ "webhooks",
33
+ "inspect",
34
+ "cdc"
35
+ ], a = (r) => {
36
+ let a = e(r, [
37
+ "version",
38
+ "transport",
39
+ "roles"
40
+ ]);
41
+ if (a.version !== 1 || a.transport !== "compose-nginx" && a.transport !== "kubernetes-nginx") throw Error("Unknown role endpoint protocol");
42
+ let o = /* @__PURE__ */ new Set(), s = t(a.roles, 32, !0).map((r) => {
43
+ let a = e(r, [
44
+ "role",
45
+ "routes",
46
+ "workloads",
47
+ "httpPath",
48
+ "webSocketPath"
49
+ ]), s = a.role;
50
+ if (typeof s != "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(s) || o.has(s)) throw Error("Invalid or duplicate endpoint role");
51
+ o.add(s);
52
+ let c = t(a.workloads, 14).map((e) => {
53
+ if (typeof e != "string" || !i.includes(e)) throw Error("Unknown endpoint workload");
54
+ return e;
55
+ });
56
+ if (new Set(c).size !== c.length) throw Error("Duplicate endpoint workload");
57
+ let l = a.routes === null ? null : t(a.routes, 128).map((e) => {
58
+ if (typeof e != "string" || e.length > 191 || !n.test(e.endsWith(".*") ? e.slice(0, -2) : e)) throw Error("Invalid endpoint tag filter");
59
+ return e;
60
+ });
61
+ if (l && new Set(l).size !== l.length) throw Error("Duplicate endpoint tag filter");
62
+ let u = "/_voltro/roles/" + s;
63
+ if (a.webSocketPath !== u + "/ws" || a.httpPath !== (c.includes("rpc") ? u + "/rpc" : null)) throw Error("Role endpoints must use canonical same-origin paths");
64
+ return Object.freeze({
65
+ role: s,
66
+ routes: l && Object.freeze(l),
67
+ workloads: Object.freeze(c),
68
+ httpPath: a.httpPath,
69
+ webSocketPath: a.webSocketPath
70
+ });
71
+ });
72
+ return Object.freeze({
73
+ version: 1,
74
+ transport: a.transport,
75
+ roles: Object.freeze(s)
76
+ });
77
+ }, o = (e, t, n) => {
78
+ if (t.length > 191 || !r.test(t) || ![
79
+ "rpc",
80
+ "subscriptions",
81
+ "events"
82
+ ].includes(n)) throw Error("Invalid role endpoint request");
83
+ let i, a = -1, o = !1;
84
+ for (let r of e.roles) {
85
+ if (!r.workloads.includes(n)) continue;
86
+ let e = r.routes === null ? 0 : Math.max(-1, ...r.routes.map((e) => e.endsWith(".*") ? t.startsWith(e.slice(0, -1)) ? e.length : -1 : e === t ? 1024 + e.length : -1));
87
+ e > a ? (i = r, a = e, o = !1) : e >= 0 && e === a && (o = !0);
88
+ }
89
+ if (!i || o) throw Error(o ? "Ambiguous role endpoint" : "No role endpoint owns this tag and workload");
90
+ return i;
91
+ }, s = (e) => {
92
+ if (!/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/.test(e)) throw Error("Invalid role proxy API name");
93
+ return `/_voltro/role-api/api-${e}/ws`;
94
+ }, c = (e, t, n) => {
95
+ if (!/^[a-z][a-z0-9-]{0,63}$/.test(t.role) || !["http", "websocket"].includes(n)) throw Error("Invalid role transport");
96
+ let r = new URL(e);
97
+ if (![
98
+ "http:",
99
+ "https:",
100
+ "ws:",
101
+ "wss:"
102
+ ].includes(r.protocol) || r.username || r.password) throw Error("Invalid role endpoint origin");
103
+ let i = n === "http" ? t.httpPath : t.webSocketPath;
104
+ if (!i || i !== "/_voltro/roles/" + t.role + (n === "http" ? "/rpc" : "/ws")) throw Error("Missing or noncanonical role transport");
105
+ return r.protocol = n === "http" ? r.protocol === "https:" || r.protocol === "wss:" ? "https:" : "http:" : r.protocol === "https:" || r.protocol === "wss:" ? "wss:" : "ws:", r.pathname = (/^\/_voltro\/role-api\/api-[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}\/ws$/.test(r.pathname) ? r.pathname.slice(0, -3) : "") + i, r.search = "", r.hash = "", r.toString();
106
+ };
107
+ //#endregion
108
+ export { c as apiRoleEndpointUrl, s as apiRoleProxyBasePath, a as captureApiRoleEndpoints, o as selectApiRoleEndpoint };
package/dist/client.js ADDED
@@ -0,0 +1,68 @@
1
+ import { splitTag as e } from "./manifest.js";
2
+ import { makeRestCore as t } from "./rest.js";
3
+ import { openLiveQueries as n } from "./live.js";
4
+ import { apiRoleEndpointUrl as r, captureApiRoleEndpoints as i, selectApiRoleEndpoint as a } from "./apiRoleEndpoints.js";
5
+ //#region src/client.ts
6
+ var o = (t) => {
7
+ let n = {};
8
+ for (let r of t.manifest.projections) {
9
+ let i = Object.assign((e, n) => t.call(r.tag, e, n), {
10
+ pages: (e, n) => t.pages(r.tag, e, n),
11
+ subscribe: (e) => t.subscribe(r.tag, e),
12
+ tag: r.tag
13
+ }), { namespace: a, method: o } = e(r.tag);
14
+ if (a === void 0) {
15
+ n[o] = i;
16
+ continue;
17
+ }
18
+ let s = n[a] ?? {};
19
+ s[o] = i, n[a] = s;
20
+ }
21
+ return n;
22
+ }, s = (e, t, n, r) => ({ async *[Symbol.asyncIterator]() {
23
+ let i;
24
+ for (;;) {
25
+ let a = await e(i === void 0 ? n : {
26
+ ...typeof n == "object" && n ? n : {},
27
+ [t]: i
28
+ }, r);
29
+ if (yield a.value, a.nextCursor === void 0) return;
30
+ i = a.nextCursor;
31
+ }
32
+ } }), c = (e, o = {}) => {
33
+ let c = t(e.manifest, e.errors, o), l = e.manifest.profile.cursorParam, u = o.roleEndpoints === void 0 ? void 0 : i(o.roleEndpoints);
34
+ if (u && o.subscriptions?.wsUrl !== void 0) throw Error("Role endpoints and a fixed subscription URL are mutually exclusive");
35
+ let d = /* @__PURE__ */ new Map(), f = !1, p = (t) => {
36
+ if (f) throw Error("API client is closed");
37
+ let i = u && a(u, t, "subscriptions"), s = i?.role ?? "default", l = d.get(s);
38
+ return l || (l = n(e.manifest, e.errors, c.baseUrl, {
39
+ token: o.token,
40
+ tenant: o.tenant,
41
+ headers: o.headers,
42
+ ...o.subscriptions ?? {},
43
+ ...i ? { wsUrl: r(c.baseUrl, i, "websocket") } : {}
44
+ }), d.set(s, l)), l;
45
+ };
46
+ return {
47
+ manifest: e.manifest,
48
+ errors: e.errors,
49
+ call: async (e, t = {}, n) => (await c.call(e, t, n)).value,
50
+ callRaw: (e, t = {}, n) => c.call(e, t, n),
51
+ pages: (e, t = {}, n) => s((t, n) => c.call(e, t, n), l, t, n),
52
+ subscribe: (e, t = {}) => {
53
+ let n = p(e);
54
+ return { [Symbol.asyncIterator]: () => {
55
+ if (f) throw Error("API client is closed");
56
+ return n.subscribe(e, t)[Symbol.asyncIterator]();
57
+ } };
58
+ },
59
+ close: async () => {
60
+ f = !0, await Promise.all([...d.values()].map((e) => e.close())), d.clear();
61
+ }
62
+ };
63
+ }, l = (e, t = {}) => {
64
+ let n = c(e, t);
65
+ return Object.assign(o(n), n);
66
+ };
67
+ //#endregion
68
+ export { o as buildNamespaces, l as createClient, c as createPromiseClient, s as pagesOf };
package/dist/errors.js ADDED
@@ -0,0 +1,77 @@
1
+ //#region src/errors.ts
2
+ var e = class extends Error {
3
+ status;
4
+ requestId;
5
+ constructor(e, t = {}, n) {
6
+ super(e, n), this.status = t.status, this.requestId = t.requestId;
7
+ }
8
+ get name() {
9
+ return this._tag;
10
+ }
11
+ }, t = class extends e {
12
+ _tag = "TransportError";
13
+ tag;
14
+ reason;
15
+ constructor(e) {
16
+ super(e.message, { requestId: e.requestId }, e.cause === void 0 ? void 0 : { cause: e.cause }), this.tag = e.tag, this.reason = e.reason;
17
+ }
18
+ }, n = class extends e {
19
+ _tag = "ApiHttpError";
20
+ tag;
21
+ status;
22
+ errorTag;
23
+ detail;
24
+ body;
25
+ constructor(e) {
26
+ super(`${e.tag}: ${e.status}${e.errorTag === void 0 ? "" : ` ${e.errorTag}`}${e.detail === void 0 ? "" : ` — ${e.detail}`}`, {
27
+ status: e.status,
28
+ requestId: e.requestId
29
+ }), this.tag = e.tag, this.status = e.status, this.errorTag = e.errorTag, this.detail = e.detail, this.body = e.body;
30
+ }
31
+ }, r = class extends e {
32
+ _tag = "RateLimitedError";
33
+ tag;
34
+ retryAfterMs;
35
+ limit;
36
+ remaining;
37
+ resetAtMs;
38
+ constructor(e) {
39
+ super(`${e.tag}: rate limited — retry after ${e.retryAfterMs} ms`, {
40
+ status: 429,
41
+ requestId: e.requestId
42
+ }), this.tag = e.tag, this.retryAfterMs = e.retryAfterMs, this.limit = e.limit, this.remaining = e.remaining, this.resetAtMs = e.resetAtMs;
43
+ }
44
+ }, i = class extends e {
45
+ _tag = "ProfileMismatchError";
46
+ expected;
47
+ actual;
48
+ constructor(e) {
49
+ super(`the API speaks the '${e.actual}' profile; this client was generated for '${e.expected}' — regenerate it`), this.expected = e.expected, this.actual = e.actual;
50
+ }
51
+ }, a = class extends e {
52
+ _tag = "InputEncodeError";
53
+ tag;
54
+ constructor(e) {
55
+ super(`${e.tag}: ${e.message}`), this.tag = e.tag;
56
+ }
57
+ }, o = class extends e {
58
+ _tag;
59
+ detail;
60
+ constructor(e, t, n = {}) {
61
+ super(n.detail ?? `${e}${Object.keys(t).length > 0 ? ` ${JSON.stringify(t)}` : ""}`, n), this._tag = e, this.detail = n.detail;
62
+ }
63
+ toJSON() {
64
+ let e = { _tag: this._tag };
65
+ for (let [t, n] of Object.entries(this)) t !== "status" && t !== "requestId" && t !== "detail" && t !== "_tag" && (e[t] = n);
66
+ return e;
67
+ }
68
+ }, s = (e) => {
69
+ class t extends o {
70
+ constructor(t = {}, n = {}) {
71
+ super(e, t, n), Object.assign(this, t);
72
+ }
73
+ }
74
+ return Object.defineProperty(t, "name", { value: e }), t;
75
+ };
76
+ //#endregion
77
+ export { e as ApiClientError, n as ApiHttpError, o as DeclaredError, a as InputEncodeError, i as ProfileMismatchError, r as RateLimitedError, t as TransportError, s as defineError };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare interface ApiClientConfig extends RestClientConfig {
8
8
  /** The socket the live queries ride — derived from `baseUrl` by default,
9
9
  * opened on the first `subscribe`. */
10
10
  readonly subscriptions?: LiveQueriesConfig | undefined;
11
+ /** Captured role-endpoints.json; live subscriptions use a separate socket per role. */
12
+ readonly roleEndpoints?: unknown;
11
13
  }
12
14
 
13
15
  /** The base of every error the client raises: a `_tag`, the HTTP `status`
@@ -44,6 +46,27 @@ export declare class ApiHttpError extends ApiClientError {
44
46
  });
45
47
  }
46
48
 
49
+ export declare interface ApiRoleEndpoint {
50
+ readonly role: string;
51
+ readonly routes: ReadonlyArray<string> | null;
52
+ readonly workloads: ReadonlyArray<string>;
53
+ readonly httpPath: string | null;
54
+ readonly webSocketPath: string;
55
+ }
56
+
57
+ export declare interface ApiRoleEndpoints {
58
+ readonly version: 1;
59
+ readonly transport: 'compose-nginx' | 'kubernetes-nginx';
60
+ readonly roles: ReadonlyArray<ApiRoleEndpoint>;
61
+ }
62
+
63
+ export declare const apiRoleEndpointUrl: (baseUrl: string, endpoint: ApiRoleEndpoint, transport: "http" | "websocket") => string;
64
+
65
+ /** Reserved web proxy base; the API name isolates identical role names. */
66
+ export declare const apiRoleProxyBasePath: (apiName: string) => string;
67
+
68
+ export declare type ApiRoleRpcWorkload = 'rpc' | 'subscriptions' | 'events';
69
+
47
70
  /**
48
71
  * Apply a patch to `prev`: `add`/`replace` set the id's row, `mergeCells`
49
72
  * folds columns into it, and null order preserves the previous ID sequence.
@@ -79,6 +102,8 @@ export declare interface CallResult<A = unknown> {
79
102
  readonly fromCache: boolean;
80
103
  }
81
104
 
105
+ export declare const captureApiRoleEndpoints: (value: unknown) => ApiRoleEndpoints;
106
+
82
107
  export declare interface ClientManifest {
83
108
  /** The generated package's name and version — the `User-Agent` line. */
84
109
  readonly name?: string;
@@ -135,6 +160,9 @@ export declare interface ClientProjection {
135
160
  /** The typed errors the projection answers with, by tag, and the status
136
161
  * each is answered with. */
137
162
  readonly errorStatus?: Readonly<Record<string, number>>;
163
+ /** Other documented statuses for the same typed error; the primary mapping
164
+ * above remains stable. Response decoding uses the actual HTTP response. */
165
+ readonly additionalErrorStatuses?: Readonly<Record<string, ReadonlyArray<number>>>;
138
166
  /** Whether the output carries the profile's cursor field — the route can
139
167
  * answer with a next page. */
140
168
  readonly paginates: boolean;
@@ -436,6 +464,10 @@ export declare type RowPatchOp = {
436
464
  /** The codec options of the rpc socket: the schema's own date forms, no renaming. */
437
465
  export declare const rpcCodec: (models: Readonly<Record<string, WireType>>) => WireCodecOptions;
438
466
 
467
+ /** Exact tags outrank namespace filters; deeper namespaces outrank broader ones.
468
+ * Equal specificity is an ambiguity, never an implicit failover/credential hop. */
469
+ export declare const selectApiRoleEndpoint: (endpoints: ApiRoleEndpoints, tag: string, workload: ApiRoleRpcWorkload) => ApiRoleEndpoint;
470
+
439
471
  /** `teams.getById` → `{ namespace: 'teams', method: 'getById' }`; a tag
440
472
  * without a dot lives at the root. The tag prefix is the namespace, like the
441
473
  * OpenAPI tag group. */
@@ -514,8 +546,12 @@ export declare interface WireProcedure {
514
546
  readonly errors?: Readonly<Record<string, WireType>> | undefined;
515
547
  }
516
548
 
517
- export declare type WireType = {
549
+ export declare type WireType =
550
+ /** Native source may retain the actual byte transformation's encoded form.
551
+ * Ordinary TypeScript wire generation and string values are unchanged. */
552
+ {
518
553
  readonly kind: 'string';
554
+ readonly byteEncoding?: 'base64';
519
555
  } | {
520
556
  readonly kind: 'number';
521
557
  } | {