@flipstream/sdk 0.12.0 → 0.13.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.
- package/CHANGELOG.md +21 -0
- package/README.md +84 -14
- package/dist/api/backend.d.ts +11 -3
- package/dist/api/backend.js +26 -6
- package/dist/api/backend.js.map +1 -1
- package/dist/api/me.js +2 -1
- package/dist/api/me.js.map +1 -1
- package/dist/api/wallet.js +4 -1
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +7 -7
- package/dist/api/workspaces.js +7 -7
- package/dist/auth/discovery.js +5 -2
- package/dist/auth/discovery.js.map +1 -1
- package/dist/core/call.d.ts +10 -1
- package/dist/core/call.js +9 -4
- package/dist/core/call.js.map +1 -1
- package/dist/core/identify.d.ts +59 -14
- package/dist/core/identify.js +54 -20
- package/dist/core/identify.js.map +1 -1
- package/dist/core/invalid.d.ts +5 -2
- package/dist/core/invalid.js +10 -4
- package/dist/core/invalid.js.map +1 -1
- package/dist/core/read.d.ts +9 -0
- package/dist/core/read.js +14 -5
- package/dist/core/read.js.map +1 -1
- package/dist/core/result.d.ts +9 -5
- package/dist/core/result.js.map +1 -1
- package/dist/core/shared.d.ts +39 -0
- package/dist/core/shared.js +177 -0
- package/dist/core/shared.js.map +1 -0
- package/dist/core/signal.d.ts +12 -0
- package/dist/core/signal.js +25 -0
- package/dist/core/signal.js.map +1 -0
- package/dist/flipstream.d.ts +87 -3
- package/dist/flipstream.js +197 -82
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/node/clientSecret.js +2 -1
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/loopback.d.ts +5 -2
- package/dist/node/loopback.js +28 -3
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.js +13 -6
- package/dist/node/session.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/admin.md +56 -1
- package/docs/node-sign-in.md +3 -1
- package/package.json +1 -1
package/dist/core/call.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/core/call.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/core/call.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,cAAc,EAAgD,MAAM,aAAa,CAAA;AAC1F,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAgC,MAAM,YAAY,CAAA;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AA4B3C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAI,SAAoB,EAAE,IAAiB,EAAE,MAAoB,EAAE,OAAqB,EAAE,QAAmC;IACrJ,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI,IAAI,OAAO,EAAE,OAAO,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IAC7F,mGAAmG;IACnG,gGAAgG;IAChG,kGAAkG;IAClG,iGAAiG;IACjG,kGAAkG;IAClG,gGAAgG;IAChG,2FAA2F;IAC3F,gBAAgB;IAChB,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,UAAU,GAAG,YAAY;QAAE,OAAO,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IACjG,6FAA6F;IAC7F,gGAAgG;IAChG,mBAAmB;IACnB,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC5C,8FAA8F;IAC9F,yFAAyF;IACzF,MAAM,IAAI,GAAG,IAAI,eAAe,EA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AAG,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAA;AACxG,CAAC;AAED,8FAA8F;AAC9F,0BAA0B;AAC1B,MAAM,QAAQ,GAAG,CAAC,KAAe,EAAqB,EAAE,CACtD,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAA;AAEnF,qHAAqH;AACrH,SAAS,KAAK,CAAC,EAAU,EAAE,MAAmB;IAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,wFAAwF;QACxF,uFAAuF;QACvF,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,OAAO,EAAE,CAAA;QACpC,MAAM,IAAI,GAAG,GAAS,EAAE;YACtB,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YACzC,OAAO,EAAE,CAAA;QACX,CAAC,CAAA;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAClC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,KAAe,EAAoD,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA"}
|
package/dist/core/identify.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ServiceName } from './transport.js';
|
|
1
2
|
/** An app's or an agent's name and version, as a product token: `name/version`. */
|
|
2
3
|
export interface Product {
|
|
3
4
|
readonly name: string;
|
|
@@ -30,24 +31,29 @@ export interface Trace {
|
|
|
30
31
|
export declare function traceFor(callerTraceparent: unknown): Trace;
|
|
31
32
|
/** The traceparent of one attempt: the call's trace, with a parent-id of its own. */
|
|
32
33
|
export declare function traceparent(trace: Trace): string;
|
|
33
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* What a request says about who sent it: the header that names the products, `User-Agent` in Node
|
|
36
|
+
* and `Flipstream-Client` in a browser, its value, the baggage, and the caller's values in them.
|
|
37
|
+
*/
|
|
34
38
|
export interface Sender {
|
|
35
|
-
readonly
|
|
39
|
+
readonly header: 'user-agent' | 'flipstream-client';
|
|
40
|
+
readonly products: string;
|
|
36
41
|
readonly baggage: string | undefined;
|
|
37
42
|
/** Each of which must never hold the access token. */
|
|
38
43
|
readonly values: readonly string[];
|
|
39
44
|
}
|
|
40
45
|
/**
|
|
41
|
-
* A signed-in call's:
|
|
42
|
-
* `
|
|
43
|
-
* agent or a conversation: no empty
|
|
46
|
+
* A signed-in call's: `<app>/<version> flipstream-sdk/<version>`, with ` node/<version>` in Node, as
|
|
47
|
+
* `User-Agent` there and as `Flipstream-Client` in a browser; and `baggage` with OpenTelemetry's
|
|
48
|
+
* GenAI names, each value percent-encoded, only when there is an agent or a conversation: no empty
|
|
49
|
+
* header.
|
|
44
50
|
*/
|
|
45
|
-
export declare function callerSender(identity: Identity, conversationId: string | undefined,
|
|
51
|
+
export declare function callerSender(identity: Identity, conversationId: string | undefined, runtime: Identifying): Sender;
|
|
46
52
|
/**
|
|
47
|
-
* Health's, signed out (D535): `
|
|
48
|
-
* for no token, so nothing could check a caller's value there, and a probe gains little from one.
|
|
53
|
+
* Health's, signed out (D535): `flipstream-sdk/<version>`, with ` node/<version>` in Node, alone. It
|
|
54
|
+
* asks for no token, so nothing could check a caller's value there, and a probe gains little from one.
|
|
49
55
|
*/
|
|
50
|
-
export declare function sdkSender(
|
|
56
|
+
export declare function sdkSender(runtime: Identifying): Sender;
|
|
51
57
|
/**
|
|
52
58
|
* Whether a caller's `value` holds the access token (#199): contains it, for a token of real
|
|
53
59
|
* length; equals it, for a shorter one, which as a substring turns up in ordinary values ('abc' in
|
|
@@ -55,9 +61,48 @@ export declare function sdkSender(nodeVersion: string): Sender;
|
|
|
55
61
|
*/
|
|
56
62
|
export declare function valueHolds(value: string, token: string): boolean;
|
|
57
63
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
* Where the SDK runs, for what its requests say about who sent them (#192, #196): Node, a browser
|
|
65
|
+
* (a page, with its CORS), or another runtime, which sends none of it.
|
|
66
|
+
*/
|
|
67
|
+
export type Runtime = {
|
|
68
|
+
readonly kind: 'node';
|
|
69
|
+
readonly version: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'browser';
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: 'other';
|
|
74
|
+
};
|
|
75
|
+
/** A runtime whose requests say who sent them. */
|
|
76
|
+
export type Identifying = Exclude<Runtime, {
|
|
77
|
+
readonly kind: 'other';
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Node, or a runtime that says it is Node's (Bun, Deno with Node's compatibility), with no
|
|
81
|
+
* `window`: its version. Otherwise a browser, when a page's `document` is defined (a page,
|
|
82
|
+
* Electron's renderer, a jsdom test): there a cross-origin request's custom headers are
|
|
83
|
+
* preflighted, so they go only where CORS allows them (#196). Anything else (Deno 1.x, which has a
|
|
84
|
+
* `window` but no `document`, a Worker, an edge function, React Native, a bundler's stand-in
|
|
85
|
+
* `process` with no versions) is `other`, and sends none, as before #196 (#378's code review, 3).
|
|
86
|
+
*/
|
|
87
|
+
export declare function runtimeOf(): Runtime;
|
|
88
|
+
/**
|
|
89
|
+
* Which hosts a request says who sent it to, in Node and in a browser: the whole policy, in one
|
|
90
|
+
* table (#378's code review, 7). Switching a host on for a browser is its line here, and its row in
|
|
91
|
+
* test/query/identify-browser.test.mjs, once its CORS allows `Flipstream-Client`, `traceparent` and
|
|
92
|
+
* `baggage`: a browser refuses every call to a host whose CORS doesn't, and the SDK can't tell that
|
|
93
|
+
* refusal from a network failure (`unavailable`).
|
|
94
|
+
* - query: in a browser too, since query-planner#41 (6100c0e, deployed 18 Nov 2026).
|
|
95
|
+
* - admin and wallet: Node only, until pulse-admin's and pulse-wallet's CORS allows them (Douwe's).
|
|
96
|
+
* - api: the public gateway, which the SDK doesn't call yet.
|
|
97
|
+
* - auth: never, where sign-in sends none (#192).
|
|
98
|
+
*/
|
|
99
|
+
export declare const IDENTIFIED: Readonly<Record<ServiceName, {
|
|
100
|
+
readonly node: boolean;
|
|
101
|
+
readonly browser: boolean;
|
|
102
|
+
}>>;
|
|
103
|
+
/**
|
|
104
|
+
* Whether a request to `service` says who sent it, by `IDENTIFIED`. In a browser, only at its
|
|
105
|
+
* deployed origin (`atDeployedOrigin`): a custom host (a proxy, staging, a local planner) gets none,
|
|
106
|
+
* as before #196, since nothing says its CORS allows them (#378's code review, 1).
|
|
62
107
|
*/
|
|
63
|
-
export declare function
|
|
108
|
+
export declare function identifies(runtime: Identifying, service: ServiceName, atDeployedOrigin: boolean): boolean;
|
package/dist/core/identify.js
CHANGED
|
@@ -68,29 +68,34 @@ function randomHex(bytes, zero) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
* A signed-in call's:
|
|
72
|
-
* `
|
|
73
|
-
* agent or a conversation: no empty
|
|
71
|
+
* A signed-in call's: `<app>/<version> flipstream-sdk/<version>`, with ` node/<version>` in Node, as
|
|
72
|
+
* `User-Agent` there and as `Flipstream-Client` in a browser; and `baggage` with OpenTelemetry's
|
|
73
|
+
* GenAI names, each value percent-encoded, only when there is an agent or a conversation: no empty
|
|
74
|
+
* header.
|
|
74
75
|
*/
|
|
75
|
-
export function callerSender(identity, conversationId,
|
|
76
|
+
export function callerSender(identity, conversationId, runtime) {
|
|
76
77
|
const { app, agent } = identity;
|
|
77
78
|
const members = [];
|
|
78
79
|
if (agent !== undefined)
|
|
79
80
|
members.push(`gen_ai.agent.name=${encodeURIComponent(agent.name)}`, `gen_ai.agent.version=${encodeURIComponent(agent.version)}`);
|
|
80
81
|
if (conversationId !== undefined)
|
|
81
82
|
members.push(`gen_ai.conversation.id=${encodeURIComponent(conversationId)}`);
|
|
83
|
+
const sdk = sdkSender(runtime);
|
|
82
84
|
return {
|
|
83
|
-
|
|
85
|
+
header: sdk.header,
|
|
86
|
+
products: `${app.name}/${app.version} ${sdk.products}`,
|
|
84
87
|
baggage: members.length > 0 ? members.join(',') : undefined,
|
|
85
88
|
values: [app.name, app.version, ...(agent === undefined ? [] : [agent.name, agent.version]), ...(conversationId === undefined ? [] : [conversationId])],
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
|
-
* Health's, signed out (D535): `
|
|
90
|
-
* for no token, so nothing could check a caller's value there, and a probe gains little from one.
|
|
92
|
+
* Health's, signed out (D535): `flipstream-sdk/<version>`, with ` node/<version>` in Node, alone. It
|
|
93
|
+
* asks for no token, so nothing could check a caller's value there, and a probe gains little from one.
|
|
91
94
|
*/
|
|
92
|
-
export function sdkSender(
|
|
93
|
-
return
|
|
95
|
+
export function sdkSender(runtime) {
|
|
96
|
+
return runtime.kind === 'node'
|
|
97
|
+
? { header: 'user-agent', products: `flipstream-sdk/${version} node/${runtime.version}`, baggage: undefined, values: [] }
|
|
98
|
+
: { header: 'flipstream-client', products: `flipstream-sdk/${version}`, baggage: undefined, values: [] };
|
|
94
99
|
}
|
|
95
100
|
/**
|
|
96
101
|
* The shortest token looked for inside a value. A real access token, a JWT, runs to hundreds of
|
|
@@ -106,17 +111,46 @@ export function valueHolds(value, token) {
|
|
|
106
111
|
return token.length >= TOKEN_SEARCHED_FROM ? value.includes(token) : value === token;
|
|
107
112
|
}
|
|
108
113
|
/**
|
|
109
|
-
* Node
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
114
|
+
* Node, or a runtime that says it is Node's (Bun, Deno with Node's compatibility), with no
|
|
115
|
+
* `window`: its version. Otherwise a browser, when a page's `document` is defined (a page,
|
|
116
|
+
* Electron's renderer, a jsdom test): there a cross-origin request's custom headers are
|
|
117
|
+
* preflighted, so they go only where CORS allows them (#196). Anything else (Deno 1.x, which has a
|
|
118
|
+
* `window` but no `document`, a Worker, an edge function, React Native, a bundler's stand-in
|
|
119
|
+
* `process` with no versions) is `other`, and sends none, as before #196 (#378's code review, 3).
|
|
113
120
|
*/
|
|
114
|
-
export function
|
|
115
|
-
if (typeof window
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
export function runtimeOf() {
|
|
122
|
+
if (typeof window === 'undefined' && typeof process !== 'undefined') {
|
|
123
|
+
const versions = process.versions;
|
|
124
|
+
const node = isRecord(versions) ? versions['node'] : undefined;
|
|
125
|
+
if (typeof node === 'string' && PRODUCT_TOKEN.test(node))
|
|
126
|
+
return { kind: 'node', version: node };
|
|
127
|
+
}
|
|
128
|
+
return typeof document !== 'undefined' ? { kind: 'browser' } : { kind: 'other' };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Which hosts a request says who sent it to, in Node and in a browser: the whole policy, in one
|
|
132
|
+
* table (#378's code review, 7). Switching a host on for a browser is its line here, and its row in
|
|
133
|
+
* test/query/identify-browser.test.mjs, once its CORS allows `Flipstream-Client`, `traceparent` and
|
|
134
|
+
* `baggage`: a browser refuses every call to a host whose CORS doesn't, and the SDK can't tell that
|
|
135
|
+
* refusal from a network failure (`unavailable`).
|
|
136
|
+
* - query: in a browser too, since query-planner#41 (6100c0e, deployed 18 Nov 2026).
|
|
137
|
+
* - admin and wallet: Node only, until pulse-admin's and pulse-wallet's CORS allows them (Douwe's).
|
|
138
|
+
* - api: the public gateway, which the SDK doesn't call yet.
|
|
139
|
+
* - auth: never, where sign-in sends none (#192).
|
|
140
|
+
*/
|
|
141
|
+
export const IDENTIFIED = {
|
|
142
|
+
query: { node: true, browser: true },
|
|
143
|
+
admin: { node: true, browser: false },
|
|
144
|
+
wallet: { node: true, browser: false },
|
|
145
|
+
api: { node: true, browser: false },
|
|
146
|
+
auth: { node: false, browser: false },
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Whether a request to `service` says who sent it, by `IDENTIFIED`. In a browser, only at its
|
|
150
|
+
* deployed origin (`atDeployedOrigin`): a custom host (a proxy, staging, a local planner) gets none,
|
|
151
|
+
* as before #196, since nothing says its CORS allows them (#378's code review, 1).
|
|
152
|
+
*/
|
|
153
|
+
export function identifies(runtime, service, atDeployedOrigin) {
|
|
154
|
+
return runtime.kind === 'node' ? IDENTIFIED[service].node : IDENTIFIED[service].browser && atDeployedOrigin;
|
|
121
155
|
}
|
|
122
156
|
//# sourceMappingURL=identify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../src/core/identify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../src/core/identify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAyB3C,sGAAsG;AACtG,MAAM,aAAa,GAAG,qCAAqC,CAAA;AAC3D,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAClD,qEAAqE;AACrE,MAAM,WAAW,GAAG,kDAAkD,CAAA;AACtE,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AACpC,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAErC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA8C,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AAE5H;;;GAGG;AACH,SAAS,OAAO,CAAC,MAAc,EAAE,IAAY;IAC3C,OAAO,IAAI,SAAS,CAAC,qBAAqB,MAAM,YAAY,IAAI,+BAA+B,CAAC,CAAA;AAClG,CAAC;AAED,MAAM,YAAY,GAAG,8EAA8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O,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAClF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAyF;IAC9G,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IACpC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE;IACrC,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE;IACtC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE;IACnC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;CACtC,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAoB,EAAE,OAAoB,EAAE,gBAAyB;IAC9F,OAAO,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAA;AAC7G,CAAC"}
|
package/dist/core/invalid.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { ApiResult } from './result.js';
|
|
1
|
+
import type { ApiError, ApiResult } from './result.js';
|
|
2
2
|
/** `invalid` with `status`, a status the SDK knows, or with none when it's undefined. */
|
|
3
|
-
export declare function invalidWith(issues: string, status: number | undefined):
|
|
3
|
+
export declare function invalidWith(issues: string, status: number | undefined): {
|
|
4
|
+
readonly ok: false;
|
|
5
|
+
readonly error: ApiError;
|
|
6
|
+
};
|
|
4
7
|
/** `invalid`, found by a check of an answer whose route answers 200 by its backend's own code. */
|
|
5
8
|
export declare const invalidAnswer: (issues: string) => ApiResult<never>;
|
|
6
9
|
/** `invalid`, found by a check of an answer whose route's success status isn't known: a create's. */
|
package/dist/core/invalid.js
CHANGED
|
@@ -3,13 +3,19 @@
|
|
|
3
3
|
* asked for, another organisation's, a page that leaks, or an id that can't name the next path. It
|
|
4
4
|
* has one shape wherever it's found, and `issues` names a place or a rule, never an id or a value.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* (#368's decision log dropped carrying one, since that would change
|
|
8
|
-
* success status the route answers by its backend's own code: 200
|
|
9
|
-
* for the
|
|
6
|
+
* On our own backends' routes its `status` is assumed, never observed. A read takes any 2xx as ok,
|
|
7
|
+
* and its data carries no status (#368's decision log dropped carrying one, since that would change
|
|
8
|
+
* every read's shape). So it's the success status the route answers by its backend's own code: 200
|
|
9
|
+
* for every GET the SDK sends to pulse-admin, pulse-auth and pulse-wallet, and for the two PUTs, whose
|
|
10
|
+
* pulse-admin routes declare it at dff6bf9b
|
|
10
11
|
* (adapters/connection/ingress/fastapi/__init__.py:423 and adapters/event_log/ingress/fastapi/__init__.py:164).
|
|
11
12
|
* Where a route's success status isn't known, there's none: the two creates, POST /clients and POST
|
|
12
13
|
* /event-logs, which come from a generic router with no recording of their answer.
|
|
14
|
+
*
|
|
15
|
+
* An authorisation server is any one the app names, so nothing in our code says how it answers: the
|
|
16
|
+
* RFC 8414 metadata discover() reads and the OpenID configuration a session reads take the 2xx
|
|
17
|
+
* call() heard instead (its `answered`), through invalidWith. A credentialed failure keeps its own
|
|
18
|
+
* status (clientSecret.ts's vouchedFor). #385 would take the observed status for every check.
|
|
13
19
|
*/
|
|
14
20
|
/** `invalid` with `status`, a status the SDK knows, or with none when it's undefined. */
|
|
15
21
|
export function invalidWith(issues, status) {
|
package/dist/core/invalid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalid.js","sourceRoot":"","sources":["../../src/core/invalid.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"invalid.js","sourceRoot":"","sources":["../../src/core/invalid.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,yFAAyF;AACzF,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,MAA0B;IACpE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;AACvH,CAAC;AAED,kGAAkG;AAClG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAoB,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAE3F,qGAAqG;AACrG,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAoB,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA"}
|
package/dist/core/read.d.ts
CHANGED
|
@@ -4,6 +4,15 @@ import type { ServiceName, TransportResult } from './transport.js';
|
|
|
4
4
|
type NoAnswer = Exclude<TransportResult, {
|
|
5
5
|
readonly kind: 'response';
|
|
6
6
|
}>;
|
|
7
|
+
/** readJson's issue for a 2xx whose body isn't JSON: a proxy's or a portal's page, never the host's answer. */
|
|
8
|
+
export declare const NOT_JSON = "the body is not JSON";
|
|
9
|
+
/**
|
|
10
|
+
* `value`, a 2xx's JSON, read by `schema`: the data, or `invalid` with the response's `status`.
|
|
11
|
+
* readJson's own last step, and the one a scope's shared read takes for each call (#377's code
|
|
12
|
+
* review, 10), so both give one shape, status and issue text. Zod's issues name paths and expected
|
|
13
|
+
* types, never the body's values.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readParsed<T>(value: unknown, schema: z.ZodType<T>, status: number): ApiResult<T>;
|
|
7
16
|
/** Why a transport has no answer to read. */
|
|
8
17
|
export declare function noAnswer(sent: NoAnswer): ApiError;
|
|
9
18
|
/**
|
package/dist/core/read.js
CHANGED
|
@@ -5,6 +5,18 @@ import { classifyStatus } from './result.js';
|
|
|
5
5
|
// compile here until it's mapped. Checked as an own key, because an app's own transport may be
|
|
6
6
|
// plain JavaScript and give any (#199).
|
|
7
7
|
const FROM_TRANSPORT = { destination: true, identification: true };
|
|
8
|
+
/** readJson's issue for a 2xx whose body isn't JSON: a proxy's or a portal's page, never the host's answer. */
|
|
9
|
+
export const NOT_JSON = 'the body is not JSON';
|
|
10
|
+
/**
|
|
11
|
+
* `value`, a 2xx's JSON, read by `schema`: the data, or `invalid` with the response's `status`.
|
|
12
|
+
* readJson's own last step, and the one a scope's shared read takes for each call (#377's code
|
|
13
|
+
* review, 10), so both give one shape, status and issue text. Zod's issues name paths and expected
|
|
14
|
+
* types, never the body's values.
|
|
15
|
+
*/
|
|
16
|
+
export function readParsed(value, schema, status) {
|
|
17
|
+
const parsed = schema.safeParse(value);
|
|
18
|
+
return parsed.success ? { ok: true, data: parsed.data } : failed({ kind: 'invalid', issues: z.prettifyError(parsed.error), status });
|
|
19
|
+
}
|
|
8
20
|
/** Why a transport has no answer to read. */
|
|
9
21
|
export function noAnswer(sent) {
|
|
10
22
|
switch (sent.kind) {
|
|
@@ -53,11 +65,8 @@ export async function readJson(sent, schema, signal, service, keepsNoText = fals
|
|
|
53
65
|
}
|
|
54
66
|
const json = parseJson(body.text);
|
|
55
67
|
if (!json.ok)
|
|
56
|
-
return failed(keepsNoText ? { kind: 'invalid', issues:
|
|
57
|
-
|
|
58
|
-
if (!parsed.success)
|
|
59
|
-
return failed({ kind: 'invalid', issues: z.prettifyError(parsed.error), status });
|
|
60
|
-
return { ok: true, data: parsed.data };
|
|
68
|
+
return failed(keepsNoText ? { kind: 'invalid', issues: NOT_JSON, status } : { kind: 'invalid', issues: NOT_JSON, status, text: body.text });
|
|
69
|
+
return readParsed(json.value, schema, status);
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
72
|
* The whole body as text, or why there is none: the caller aborted, or it broke off. A
|
package/dist/core/read.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAiC,MAAM,aAAa,CAAA;AAM3E,8FAA8F;AAC9F,+FAA+F;AAC/F,wCAAwC;AACxC,MAAM,cAAc,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAoD,CAAA;AAEpH,6CAA6C;AAC7C,MAAM,UAAU,QAAQ,CAAC,IAAc;IACrC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;YACvB,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;QAClG,CAAC;QACD,KAAK,aAAa;YAChB,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;QAChC,KAAK,WAAW;YACd,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;QAC9B,KAAK,SAAS;YACZ,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;QAC5B,KAAK,UAAU;YACb,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAA;QAChD,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,SAAS,GAAU,IAAI,CAAA;YAC7B,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,CAAC,SAA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CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,CAAA;IACjF,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;AACH,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,KAAe,EAAoD,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA"}
|
package/dist/core/result.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import type { PlannerErrorCode } from '../spec/query-planner/types.gen.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* What every call returns: its data, or one failure with one meaning (D412). `trace_id` is the W3C
|
|
4
4
|
* trace-id the call's requests carried (#251), so a person can find them in Logs: there when a
|
|
5
|
-
* request carrying it went out, on either arm, and absent when nothing was sent.
|
|
5
|
+
* request carrying it went out, on either arm, and absent when nothing was sent. In a scope (#376),
|
|
6
|
+
* a shared read goes out under a trace of its own, and a call it answered names that trace: the
|
|
7
|
+
* read's whose failure is the answer, else the call's own, else the first shared read it asked for.
|
|
6
8
|
*/
|
|
7
9
|
export type ApiResult<T> = {
|
|
8
10
|
readonly ok: true;
|
|
@@ -62,10 +64,12 @@ export type ApiError = Answered
|
|
|
62
64
|
* Outside the contract: reported, never shown as empty. `status` is set on a failure from an
|
|
63
65
|
* answer whose status the SDK knows. When the answer's own status or shape is outside the
|
|
64
66
|
* contract, or a read after pause's or resume's write failed, it's the response's. When a check
|
|
65
|
-
* after the read found it (#368),
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* after the read found it (#368), on an authorisation server's answer (discover()'s metadata, a
|
|
68
|
+
* session's OpenID configuration) it's the 2xx that server answered, since any server can be
|
|
69
|
+
* named there. On Flipstream's own routes it's the success status that route answers by its
|
|
70
|
+
* backend's own code, 200 for every read and both PUTs, assumed from a 2xx and never observed
|
|
71
|
+
* until #385. A create's answer has none, since its route's success status isn't known. `text` is
|
|
72
|
+
* its body, when a 2xx body is not JSON.
|
|
69
73
|
*/
|
|
70
74
|
| {
|
|
71
75
|
readonly kind: 'invalid';
|
package/dist/core/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AA6HA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,kBAAkB,CAAA;IACxD,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,SAAS,CAAA;IACpD,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,cAAc,CAAA;IACzC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,WAAW,CAAA;IACtC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,WAAW,CAAA;IACtC,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,UAAU,CAAA;IACvD,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;QAAE,OAAO,aAAa,CAAA;IAC5E,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,UAAU,CAAA;IACrD,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AAyBD,+FAA+F;AAC/F,6EAA6E;AAC7E,MAAM,eAAe,GAA+D;IAClF,WAAW,EAAE,gGAAgG;IAC7G,cAAc,EAAE,mFAAmF;IACnG,IAAI,EAAE,uCAA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K,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,aAAa,MAAM,GAAG,CAAC,CAAA;QACpG,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,8FAA8F;QAC9F,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAA;IAClD,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,UAAU,OAAO,CAAI,MAAoB;IAC7C,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;IACnE,OAAO,MAAM,CAAC,IAAI,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CallSpec } from './call.js';
|
|
2
|
+
import type { Deadline } from './deadline.js';
|
|
3
|
+
import { type ApiResult } from './result.js';
|
|
4
|
+
/** How a spec is shared in a scope (`CallSpec.shared`): its key, with its endpoint's, names one read. */
|
|
5
|
+
export interface SharedRule {
|
|
6
|
+
/** The path the read asks for, as the seam builds it, so no request is built to name it. */
|
|
7
|
+
readonly key: string;
|
|
8
|
+
}
|
|
9
|
+
/** One call waiting on a shared read: its own deadline, its caller's signal, and its own end (#349). */
|
|
10
|
+
export interface Waiter {
|
|
11
|
+
readonly deadline: Deadline;
|
|
12
|
+
readonly signal: AbortSignal | undefined;
|
|
13
|
+
readonly end: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* How a shared read is sent: `spec`, its answer read as JSON and left unchecked, under `deadlineMs`,
|
|
17
|
+
* its starter's, and ended by `end`, never by one call's signal. `answered` hears the 2xx's status.
|
|
18
|
+
* Its `origin` is what the scope hands each call it answers: the read's own trace, in the client.
|
|
19
|
+
*/
|
|
20
|
+
export type StartRead<O> = (spec: CallSpec<unknown>, deadlineMs: number, end: AbortSignal, answered: (status: number) => void) => {
|
|
21
|
+
readonly answer: Promise<ApiResult<unknown>>;
|
|
22
|
+
readonly origin: O;
|
|
23
|
+
};
|
|
24
|
+
/** What a call heard from a shared read: its result, and the read that answered it, when one did. */
|
|
25
|
+
export interface Heard<T, O> {
|
|
26
|
+
readonly result: ApiResult<T>;
|
|
27
|
+
readonly origin: O | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** A scope's shared reads. */
|
|
30
|
+
export interface SharedReads<O> {
|
|
31
|
+
/** True until the scope closes; then every call reads its own, as outside a scope. */
|
|
32
|
+
readonly isOpen: () => boolean;
|
|
33
|
+
/** `spec`'s answer for `waiter`, from the one read the scope makes of it, started with `start` when none is kept. */
|
|
34
|
+
read<T>(spec: CallSpec<T>, rule: SharedRule, waiter: Waiter, start: StartRead<O>): Promise<Heard<T, O>>;
|
|
35
|
+
/** Closes the scope: ends every shared read still in flight, and answers once each has settled. */
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/** The reads of one scope, empty and open. */
|
|
39
|
+
export declare function sharedReads<O>(): SharedReads<O>;
|