@flipstream/sdk 0.11.0 → 0.12.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 +48 -0
- package/README.md +97 -412
- package/dist/api/backend.d.ts +10 -0
- package/dist/api/backend.js +24 -4
- package/dist/api/backend.js.map +1 -1
- package/dist/api/credentials.js +4 -4
- package/dist/api/credentials.js.map +1 -1
- package/dist/api/datasets.d.ts +82 -14
- package/dist/api/datasets.js +193 -57
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/log.d.ts +25 -20
- package/dist/api/log.js +63 -48
- package/dist/api/log.js.map +1 -1
- package/dist/api/me.js +7 -4
- package/dist/api/me.js.map +1 -1
- package/dist/api/members.d.ts +34 -1
- package/dist/api/members.js +67 -27
- package/dist/api/members.js.map +1 -1
- package/dist/api/wallet.d.ts +8 -5
- package/dist/api/wallet.js +36 -24
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +28 -7
- package/dist/api/workspaces.js +46 -16
- package/dist/api/workspaces.js.map +1 -1
- package/dist/auth/discovery.d.ts +19 -6
- package/dist/auth/discovery.js +25 -4
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.d.ts +18 -14
- package/dist/auth/signIn.js +29 -22
- package/dist/auth/signIn.js.map +1 -1
- package/dist/core/call.d.ts +4 -1
- package/dist/core/call.js +26 -6
- package/dist/core/call.js.map +1 -1
- package/dist/core/deadline.d.ts +30 -0
- package/dist/core/deadline.js +51 -0
- package/dist/core/deadline.js.map +1 -0
- package/dist/core/invalid.d.ts +7 -0
- package/dist/core/invalid.js +22 -0
- package/dist/core/invalid.js.map +1 -0
- package/dist/core/names.d.ts +13 -2
- package/dist/core/names.js +11 -2
- package/dist/core/names.js.map +1 -1
- package/dist/core/notFound.d.ts +8 -0
- package/dist/core/notFound.js +8 -0
- package/dist/core/notFound.js.map +1 -0
- package/dist/core/result.d.ts +17 -12
- package/dist/core/result.js +5 -5
- package/dist/core/result.js.map +1 -1
- package/dist/core/retry.d.ts +5 -2
- package/dist/core/retry.js +6 -3
- package/dist/core/retry.js.map +1 -1
- package/dist/core/scope.d.ts +20 -0
- package/dist/core/scope.js +54 -0
- package/dist/core/scope.js.map +1 -0
- package/dist/flipstream.d.ts +136 -69
- package/dist/flipstream.js +67 -45
- package/dist/flipstream.js.map +1 -1
- package/dist/node/clientSecret.js +5 -5
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/headless.d.ts +14 -6
- package/dist/node/headless.js +8 -6
- package/dist/node/headless.js.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.js +26 -14
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +3 -3
- package/dist/node/keychainStore.d.ts +10 -7
- package/dist/node/keychainStore.js +44 -23
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/loopback.d.ts +8 -1
- package/dist/node/loopback.js +19 -2
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +17 -9
- package/dist/node/session.js +55 -44
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +35 -2
- package/dist/node/store.js +56 -12
- package/dist/node/store.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/admin.md +503 -0
- package/docs/node-sign-in.md +60 -38
- package/package.json +1 -1
package/dist/auth/signIn.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
|
+
import { wallClock } from '../core/deadline.js';
|
|
4
|
+
import { serverProblem } from './discovery.js';
|
|
3
5
|
import { challengeOf, randomValue } from './pkce.js';
|
|
4
6
|
import { tokenCall } from './tokenEndpoint.js';
|
|
5
7
|
import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
|
|
6
8
|
const nonEmpty = (value) => typeof value === 'string' && value !== '';
|
|
7
9
|
/**
|
|
8
10
|
* The URL to send the person to, and what finishing will need. Rejects with a TypeError, before
|
|
9
|
-
* anything is made, when the client ID is missing or empty, the redirect URI isn't absolute,
|
|
10
|
-
*
|
|
11
|
+
* anything is made, when the client ID is missing or empty, the redirect URI isn't absolute, the
|
|
12
|
+
* scopes are empty or one holds a space, or `server` isn't discover()'s answer in its snake_case
|
|
13
|
+
* names, naming the field it lacks: from TypeScript, none of these compiles. Always S256;
|
|
11
14
|
* no `resource` is sent, since the hosts share one audience.
|
|
12
15
|
*/
|
|
13
16
|
export async function startSignIn(request) {
|
|
@@ -19,10 +22,13 @@ export async function startSignIn(request) {
|
|
|
19
22
|
if (!Array.isArray(scopes) || scopes.length === 0 || !scopes.every((scope) => nonEmpty(scope) && !/\s/.test(scope))) {
|
|
20
23
|
throw new TypeError('startSignIn: scopes must be one or more scope names, none with a space');
|
|
21
24
|
}
|
|
25
|
+
const problem = serverProblem(server);
|
|
26
|
+
if (problem !== null)
|
|
27
|
+
throw new TypeError(`startSignIn: ${problem}: pass discover()'s answer, in its snake_case names (D569)`);
|
|
22
28
|
const state = randomValue(32);
|
|
23
29
|
const verifier = randomValue(64);
|
|
24
30
|
const scope = scopes.join(' ');
|
|
25
|
-
const url = new URL(server.
|
|
31
|
+
const url = new URL(server.authorization_endpoint);
|
|
26
32
|
url.searchParams.set('response_type', 'code');
|
|
27
33
|
url.searchParams.set('client_id', clientId);
|
|
28
34
|
url.searchParams.set('redirect_uri', redirectUri);
|
|
@@ -35,12 +41,12 @@ export async function startSignIn(request) {
|
|
|
35
41
|
pending: {
|
|
36
42
|
state,
|
|
37
43
|
verifier,
|
|
38
|
-
clientId,
|
|
39
|
-
redirectUri,
|
|
44
|
+
client_id: clientId,
|
|
45
|
+
redirect_uri: redirectUri,
|
|
40
46
|
scope,
|
|
41
47
|
issuer: server.issuer,
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
token_endpoint: server.token_endpoint,
|
|
49
|
+
authorization_response_iss_parameter_supported: server.authorization_response_iss_parameter_supported,
|
|
44
50
|
},
|
|
45
51
|
};
|
|
46
52
|
}
|
|
@@ -54,7 +60,7 @@ export function readCallback(callbackUrl, pending) {
|
|
|
54
60
|
return { kind: 'wrong_state' };
|
|
55
61
|
const iss = params.get('iss');
|
|
56
62
|
// Compared as strings, as RFC 9207 §2.4 says: the issuer exactly as its metadata names it.
|
|
57
|
-
if (iss === null ? pending.
|
|
63
|
+
if (iss === null ? pending.authorization_response_iss_parameter_supported : iss !== pending.issuer)
|
|
58
64
|
return { kind: 'wrong_issuer' };
|
|
59
65
|
const error = params.get('error');
|
|
60
66
|
if (error !== null) {
|
|
@@ -68,23 +74,24 @@ const zPending = z
|
|
|
68
74
|
.object({
|
|
69
75
|
state: z.string().min(1),
|
|
70
76
|
verifier: z.string().min(43).max(128),
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
client_id: z.string().min(1),
|
|
78
|
+
redirect_uri: z.string().min(1),
|
|
73
79
|
scope: z.string().min(1),
|
|
74
80
|
issuer: z.string().min(1),
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
token_endpoint: z.string(),
|
|
82
|
+
authorization_response_iss_parameter_supported: z.boolean(),
|
|
77
83
|
})
|
|
78
84
|
// A pending from storage may have been edited. Its token endpoint is held to the issuer's rule:
|
|
79
85
|
// https for an https issuer; for an http one on this machine, its own origin, which `finishSignIn`
|
|
80
86
|
// then sends to only with `allowLocalhostHttp` (#164).
|
|
81
|
-
.refine((pending) => endpointProblem(pending.issuer, [pending.
|
|
87
|
+
.refine((pending) => endpointProblem(pending.issuer, [pending.token_endpoint]) === null);
|
|
82
88
|
/** A pending sign-in as `startSignIn` makes one, checked: it comes back from the app's storage. */
|
|
83
89
|
export const isPendingSignIn = (value) => zPending.safeParse(value).success;
|
|
84
90
|
/**
|
|
85
91
|
* Finishes a sign-in: the redirect is read (`readCallback`), and only then is its code exchanged
|
|
86
92
|
* for tokens, once (`tokenCall`). A `pending` that isn't one (from
|
|
87
|
-
* storage the app couldn't read back
|
|
93
|
+
* storage the app couldn't read back, or one an earlier version made, in camelCase) is `refused`,
|
|
94
|
+
* with nothing sent. A public client's: an app
|
|
88
95
|
* with a server signs in as a confidential client with `@flipstream/sdk/node`'s `finishSignIn`.
|
|
89
96
|
*/
|
|
90
97
|
export function finishSignIn(callbackUrl, pending, options = {}) {
|
|
@@ -99,7 +106,7 @@ export async function exchangeCode(callbackUrl, pending, options, authorization)
|
|
|
99
106
|
// Refused with nothing sent, each for its own reason (#199): what it refuses is as before.
|
|
100
107
|
if (!isPendingSignIn(pending))
|
|
101
108
|
return { ok: false, error: { kind: 'refused', reason: 'pending' } };
|
|
102
|
-
if (!isSignInUrl(pending.
|
|
109
|
+
if (!isSignInUrl(pending.token_endpoint, options.allowLocalhostHttp))
|
|
103
110
|
return { ok: false, error: { kind: 'refused', reason: 'destination' } };
|
|
104
111
|
if (!URL.canParse(callbackUrl))
|
|
105
112
|
return { ok: false, error: { kind: 'refused', reason: 'callback' } };
|
|
@@ -109,23 +116,23 @@ export async function exchangeCode(callbackUrl, pending, options, authorization)
|
|
|
109
116
|
const form = {
|
|
110
117
|
grant_type: 'authorization_code',
|
|
111
118
|
code: callback.code,
|
|
112
|
-
redirect_uri: pending.
|
|
113
|
-
client_id: pending.
|
|
119
|
+
redirect_uri: pending.redirect_uri,
|
|
120
|
+
client_id: pending.client_id,
|
|
114
121
|
code_verifier: pending.verifier,
|
|
115
122
|
};
|
|
116
123
|
// Before the request, so the expiry is never later than the server's own.
|
|
117
|
-
const sentAt =
|
|
118
|
-
const answer = await call(authTransport(options), tokenCall('auth.token', pending.
|
|
124
|
+
const sentAt = wallClock();
|
|
125
|
+
const answer = await call(authTransport(options), tokenCall('auth.token', pending.token_endpoint, form, 30_000, authorization), options.signal);
|
|
119
126
|
if (!answer.ok)
|
|
120
127
|
return answer;
|
|
121
128
|
const { access_token, expires_in, refresh_token, scope } = answer.data;
|
|
122
129
|
return {
|
|
123
130
|
ok: true,
|
|
124
131
|
data: {
|
|
125
|
-
|
|
132
|
+
access_token,
|
|
126
133
|
// pulse-auth sends "" for "no refresh token" (its model's default): that is none, not a token.
|
|
127
|
-
...(nonEmpty(refresh_token) ? {
|
|
128
|
-
...(expires_in === undefined ? {} : {
|
|
134
|
+
...(nonEmpty(refresh_token) ? { refresh_token } : {}),
|
|
135
|
+
...(expires_in === undefined ? {} : { expires_at: sentAt + expires_in * 1000 }),
|
|
129
136
|
// RFC 6749 §5.1: a server leaves `scope` out when it granted what was asked. pulse-auth
|
|
130
137
|
// always leaves it out.
|
|
131
138
|
scope: scope ?? pending.scope,
|
package/dist/auth/signIn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,OAAO,EAAE,aAAa,EAAmB,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAwB,MAAM,gBAAgB,CAAA;AAsElG,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAA;AAE/F;;;;;;GAMG;AACH,MAAM,CAAC,KA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AK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAA;IACnE,MAAM,IAAI,GAAG;QACX,UAAU,EAAE,oBAAoB;QAChC,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,QAAQ;KAChC,CAAA;IACD,0EAA0E;IAC1E,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IAC/I,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAA;IACtE,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ,YAAY;YACZ,+FAA+F;YAC/F,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrD,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC;YAC/E,wFAAwF;YACxF,wBAAwB;YACxB,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK;SAC9B;KACF,CAAA;AACH,CAAC"}
|
package/dist/core/call.d.ts
CHANGED
|
@@ -19,5 +19,8 @@ export interface CallSpec<T> extends Omit<ApiRequest, 'signal'> {
|
|
|
19
19
|
* One call: attempts under its rule, every attempt, wait and read under one signal that joins the
|
|
20
20
|
* caller's with the deadline. Whichever fires first decides the answer, `timeout` or `aborted`
|
|
21
21
|
* (#15), never mixed. The call ends when it fires, whatever the transport does with the signal.
|
|
22
|
+
* `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
|
|
23
|
+
* does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
|
|
24
|
+
* the caller's, so a caller's signal gets one listener a request, as before, and never one more.
|
|
22
25
|
*/
|
|
23
|
-
export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal): Promise<ApiResult<T>>;
|
|
26
|
+
export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal, callEnd?: AbortSignal): Promise<ApiResult<T>>;
|
package/dist/core/call.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { readJson } from './read.js';
|
|
2
|
+
import { deadlineIn, MAX_TIMER_MS } from './deadline.js';
|
|
2
3
|
import { classifyStatus } from './result.js';
|
|
3
4
|
import { decide, parseRetryAfterMs } from './retry.js';
|
|
4
5
|
/**
|
|
5
6
|
* One call: attempts under its rule, every attempt, wait and read under one signal that joins the
|
|
6
7
|
* caller's with the deadline. Whichever fires first decides the answer, `timeout` or `aborted`
|
|
7
8
|
* (#15), never mixed. The call ends when it fires, whatever the transport does with the signal.
|
|
9
|
+
* `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
|
|
10
|
+
* does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
|
|
11
|
+
* the caller's, so a caller's signal gets one listener a request, as before, and never one more.
|
|
8
12
|
*/
|
|
9
|
-
export async function call(transport, spec, signal) {
|
|
10
|
-
if (signal?.aborted === true)
|
|
13
|
+
export async function call(transport, spec, signal, callEnd) {
|
|
14
|
+
if (signal?.aborted === true || callEnd?.aborted === true)
|
|
11
15
|
return failed({ kind: 'aborted' });
|
|
12
|
-
|
|
16
|
+
// A call with no time for it is over before it starts: nothing is sent, as nothing is for a caller
|
|
17
|
+
// that has already aborted (#339). No time is what a deadline's passed() calls it (#337): under
|
|
18
|
+
// 1 ms, or not a number. A caller that checked its own deadline a moment before may still hand on
|
|
19
|
+
// under 1 ms, the time left read again. It's read off the value handed, as passed() reads it the
|
|
20
|
+
// moment the deadline is set: a microsecond later, a deadline of 1 ms already reads passed, and a
|
|
21
|
+
// call given 1 ms would never go out. A deadline past what a timer holds would fire after 1 ms,
|
|
22
|
+
// so it's none either; the public `deadlineMs` is refused before it gets here (#340's code
|
|
23
|
+
// review, 1-3).
|
|
24
|
+
if (!(spec.deadlineMs >= 1) || spec.deadlineMs > MAX_TIMER_MS)
|
|
25
|
+
return failed({ kind: 'timeout' });
|
|
26
|
+
// On the monotonic clock, as the timer below is, so whether a wait fits is read as the timer
|
|
27
|
+
// counts: a wall clock stepped back would start waits past it, one stepped forward refuse waits
|
|
28
|
+
// that fit (#333).
|
|
29
|
+
const deadline = deadlineIn(spec.deadlineMs);
|
|
13
30
|
// Owned here, strongly: the timer and the caller's listener each hold `stop`, so the deadline
|
|
14
31
|
// reaches every attempt, however weakly a transport or its fetch keeps the signal (#57).
|
|
15
32
|
const stop = new AbortController();
|
|
@@ -17,6 +34,8 @@ export async function call(transport, spec, signal) {
|
|
|
17
34
|
const timer = setTimeout(() => stop.abort(timedOut), spec.deadlineMs);
|
|
18
35
|
const onAbort = () => stop.abort(signal?.reason);
|
|
19
36
|
signal?.addEventListener('abort', onAbort, { once: true });
|
|
37
|
+
const onEnd = () => stop.abort(callEnd?.reason);
|
|
38
|
+
callEnd?.addEventListener('abort', onEnd, { once: true });
|
|
20
39
|
// The first abort's reason stays: that is how the call knows which came first.
|
|
21
40
|
const ended = () => failed(stop.signal.reason === timedOut ? { kind: 'timeout' } : { kind: 'aborted' });
|
|
22
41
|
const fired = new Promise((resolve) => stop.signal.addEventListener('abort', () => resolve(ENDED), { once: true }));
|
|
@@ -31,7 +50,7 @@ export async function call(transport, spec, signal) {
|
|
|
31
50
|
letGo(sent);
|
|
32
51
|
return ended();
|
|
33
52
|
}
|
|
34
|
-
let decision = decide(spec.retry, attempt, outcomeOf(sent),
|
|
53
|
+
let decision = decide(spec.retry, attempt, outcomeOf(sent), deadline.left());
|
|
35
54
|
if (decision.kind === 'stop') {
|
|
36
55
|
const result = await unlessFired(readJson(sent, spec.schema, stop.signal, spec.service, spec.keepsNoText === true), fired, () => undefined);
|
|
37
56
|
if (result === ENDED || stop.signal.aborted)
|
|
@@ -39,7 +58,7 @@ export async function call(transport, spec, signal) {
|
|
|
39
58
|
// A success whose body broke off is a transport failure too, so a read tries again under
|
|
40
59
|
// its rule. Any other status already decided: its answer stands, however its body ended.
|
|
41
60
|
if (brokeOff(sent, result))
|
|
42
|
-
decision = decide(spec.retry, attempt, { kind: 'unavailable' },
|
|
61
|
+
decision = decide(spec.retry, attempt, { kind: 'unavailable' }, deadline.left());
|
|
43
62
|
if (decision.kind === 'stop')
|
|
44
63
|
return withRetryAfter(result, sent);
|
|
45
64
|
}
|
|
@@ -57,6 +76,7 @@ export async function call(transport, spec, signal) {
|
|
|
57
76
|
// A minimal polyfill signal may have no removeEventListener; it keeps its one listener.
|
|
58
77
|
if (typeof signal?.removeEventListener === 'function')
|
|
59
78
|
signal.removeEventListener('abort', onAbort);
|
|
79
|
+
callEnd?.removeEventListener('abort', onEnd);
|
|
60
80
|
}
|
|
61
81
|
}
|
|
62
82
|
const ENDED = Symbol('ended');
|
|
@@ -91,7 +111,7 @@ function withRetryAfter(result, sent) {
|
|
|
91
111
|
if (result.ok || sent.kind !== 'response' || !answered(result.error))
|
|
92
112
|
return result;
|
|
93
113
|
const retryAfterMs = parseRetryAfterMs(sent.response.headers.get('retry-after'));
|
|
94
|
-
return retryAfterMs === undefined ? result : failed({ ...result.error, retryAfterMs });
|
|
114
|
+
return retryAfterMs === undefined ? result : failed({ ...result.error, retry_after_ms: retryAfterMs });
|
|
95
115
|
}
|
|
96
116
|
// Of what readJson gives for a response, only a failure status's answer has a kind other than
|
|
97
117
|
// `invalid` and a status.
|
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;AACpC,OAAO,EAAE,cAAc,EAAgD,MAAM,aAAa,CAAA;AAC1F,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAgC,MAAM,YAAY,CAAA;AAsBpF
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/core/call.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,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;AAsBpF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAI,SAAoB,EAAE,IAAiB,EAAE,MAAoB,EAAE,OAAqB;IAChH,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;I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Ac,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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The longest a timer waits: setTimeout cuts a longer delay to 1 ms. The one ceiling for every
|
|
3
|
+
* deadline and wait the SDK takes from a caller (#340's code review, 1-3).
|
|
4
|
+
*/
|
|
5
|
+
export declare const MAX_TIMER_MS = 2147483647;
|
|
6
|
+
/**
|
|
7
|
+
* A wait a caller gives, `name` its option as the error names it (`signInWithLoopback: timeoutMs`),
|
|
8
|
+
* in whole ms, rounded down: `fallback` when it's left out, `undefined` or `null`. One that can't be
|
|
9
|
+
* a wait (not a number, NaN, ±Infinity, or more than MAX_TIMER_MS once rounded down) is a TypeError
|
|
10
|
+
* naming the option, never its value: a programming error. A spent wait, under 1 ms, is returned as
|
|
11
|
+
* it is, runtime data for each caller to end as its own timeout (#340, #344, #345's code review).
|
|
12
|
+
*/
|
|
13
|
+
export declare function callerWaitMs<F extends number | undefined>(name: string, value: unknown, fallback: F): number | F;
|
|
14
|
+
/** A deadline, set by `deadlineIn`. */
|
|
15
|
+
export interface Deadline {
|
|
16
|
+
/** The time left, in whole ms, rounded down: 0 once it has passed, never below, nor for NaN. */
|
|
17
|
+
readonly left: () => number;
|
|
18
|
+
/**
|
|
19
|
+
* Whether it has passed: exactly when `left()` reads 0, so a check that lets a turn through never
|
|
20
|
+
* hands it a deadline of 0 ms (#337's code review, 1-2).
|
|
21
|
+
*/
|
|
22
|
+
readonly passed: () => boolean;
|
|
23
|
+
}
|
|
24
|
+
/** A deadline `ms` from now, on the monotonic clock. */
|
|
25
|
+
export declare function deadlineIn(ms: number): Deadline;
|
|
26
|
+
/**
|
|
27
|
+
* An instant, in ms since the epoch: the wall clock, for expiry (a token's `expires_at`, computed
|
|
28
|
+
* from when its request was sent, and checked against now). Never a deadline: use `deadlineIn`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const wallClock: () => number;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The SDK's deadlines and its wall-clock reads for expiry (#333). Not exported from the package.
|
|
3
|
+
*
|
|
4
|
+
* A deadline runs on the monotonic clock, `performance.now()`, as the timers that end a call, a
|
|
5
|
+
* session's limit and a keychain step do. On the wall clock, a clock change, a virtual machine
|
|
6
|
+
* resuming or (on Linux, whose monotonic clock skips sleep) a laptop waking would fail a call early
|
|
7
|
+
* or let its retries run past the deadline, while its timer still ran (#157 items 10 and 21).
|
|
8
|
+
*
|
|
9
|
+
* Every file in src reads `Date` and `performance` only through this module: the lint refuses both
|
|
10
|
+
* elsewhere (eslint.config.js, held by test/lint/deadline-clocks.test.mjs). Its exceptions are named
|
|
11
|
+
* there, each with its reason: fileLock.ts's own clocks, which its tests own (#298's rule); the
|
|
12
|
+
* keychain helper process, which counts the time left it's handed (`msLeft`) on its own monotonic
|
|
13
|
+
* clock, inside the cut its parent's going sets; and the date arithmetic in api/time.ts and
|
|
14
|
+
* api/log.ts, which parses and builds instants and reads no clock.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The longest a timer waits: setTimeout cuts a longer delay to 1 ms. The one ceiling for every
|
|
18
|
+
* deadline and wait the SDK takes from a caller (#340's code review, 1-3).
|
|
19
|
+
*/
|
|
20
|
+
export const MAX_TIMER_MS = 2_147_483_647;
|
|
21
|
+
/**
|
|
22
|
+
* A wait a caller gives, `name` its option as the error names it (`signInWithLoopback: timeoutMs`),
|
|
23
|
+
* in whole ms, rounded down: `fallback` when it's left out, `undefined` or `null`. One that can't be
|
|
24
|
+
* a wait (not a number, NaN, ±Infinity, or more than MAX_TIMER_MS once rounded down) is a TypeError
|
|
25
|
+
* naming the option, never its value: a programming error. A spent wait, under 1 ms, is returned as
|
|
26
|
+
* it is, runtime data for each caller to end as its own timeout (#340, #344, #345's code review).
|
|
27
|
+
*/
|
|
28
|
+
export function callerWaitMs(name, value, fallback) {
|
|
29
|
+
if (value === undefined || value === null)
|
|
30
|
+
return fallback;
|
|
31
|
+
const whole = typeof value === 'number' ? Math.floor(value) : Number.NaN;
|
|
32
|
+
if (!Number.isFinite(whole) || whole > MAX_TIMER_MS)
|
|
33
|
+
throw new TypeError(`${name} must be a number of ms, at most ${String(MAX_TIMER_MS)}`);
|
|
34
|
+
return whole;
|
|
35
|
+
}
|
|
36
|
+
/** A deadline `ms` from now, on the monotonic clock. */
|
|
37
|
+
export function deadlineIn(ms) {
|
|
38
|
+
const at = performance.now() + ms;
|
|
39
|
+
const left = () => {
|
|
40
|
+
const whole = Math.floor(at - performance.now());
|
|
41
|
+
// Not `Math.max(0, …)`, which keeps NaN: a deadline that isn't a number has no time in it.
|
|
42
|
+
return whole > 0 ? whole : 0;
|
|
43
|
+
};
|
|
44
|
+
return { left, passed: () => left() === 0 };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* An instant, in ms since the epoch: the wall clock, for expiry (a token's `expires_at`, computed
|
|
48
|
+
* from when its request was sent, and checked against now). Never a deadline: use `deadlineIn`.
|
|
49
|
+
*/
|
|
50
|
+
export const wallClock = () => Date.now();
|
|
51
|
+
//# sourceMappingURL=deadline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadline.js","sourceRoot":"","sources":["../../src/core/deadline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAA;AAEzC;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAA+B,IAAY,EAAE,KAAc,EAAE,QAAW;IAClG,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,QAAQ,CAAA;IAC1D,MAAM,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAA;IACxE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,YAAY;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,oCAAoC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;IAC3I,OAAO,KAAK,CAAA;AACd,CAAC;AAaD,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,CAAA;IACjC,MAAM,IAAI,GAAG,GAAW,EAAE;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAA;QAChD,2FAA2F;QAC3F,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9B,CAAC,CAAA;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAA;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiResult } from './result.js';
|
|
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): ApiResult<never>;
|
|
4
|
+
/** `invalid`, found by a check of an answer whose route answers 200 by its backend's own code. */
|
|
5
|
+
export declare const invalidAnswer: (issues: string) => ApiResult<never>;
|
|
6
|
+
/** `invalid`, found by a check of an answer whose route's success status isn't known: a create's. */
|
|
7
|
+
export declare const invalidStatusUnknown: (issues: string) => ApiResult<never>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* An `invalid` the SDK finds by checking an answer after its read (#368): a record that isn't the one
|
|
3
|
+
* asked for, another organisation's, a page that leaks, or an id that can't name the next path. It
|
|
4
|
+
* has one shape wherever it's found, and `issues` names a place or a rule, never an id or a value.
|
|
5
|
+
*
|
|
6
|
+
* Its `status` is assumed, never observed. A read takes any 2xx as ok, and its data carries no status
|
|
7
|
+
* (#368's decision log dropped carrying one, since that would change every read's shape). So it's the
|
|
8
|
+
* success status the route answers by its backend's own code: 200 for every GET the SDK sends, and
|
|
9
|
+
* for the two PUTs, whose pulse-admin routes declare it at dff6bf9b
|
|
10
|
+
* (adapters/connection/ingress/fastapi/__init__.py:423 and adapters/event_log/ingress/fastapi/__init__.py:164).
|
|
11
|
+
* Where a route's success status isn't known, there's none: the two creates, POST /clients and POST
|
|
12
|
+
* /event-logs, which come from a generic router with no recording of their answer.
|
|
13
|
+
*/
|
|
14
|
+
/** `invalid` with `status`, a status the SDK knows, or with none when it's undefined. */
|
|
15
|
+
export function invalidWith(issues, status) {
|
|
16
|
+
return { ok: false, error: status === undefined ? { kind: 'invalid', issues } : { kind: 'invalid', issues, status } };
|
|
17
|
+
}
|
|
18
|
+
/** `invalid`, found by a check of an answer whose route answers 200 by its backend's own code. */
|
|
19
|
+
export const invalidAnswer = (issues) => invalidWith(issues, 200);
|
|
20
|
+
/** `invalid`, found by a check of an answer whose route's success status isn't known: a create's. */
|
|
21
|
+
export const invalidStatusUnknown = (issues) => invalidWith(issues, undefined);
|
|
22
|
+
//# sourceMappingURL=invalid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid.js","sourceRoot":"","sources":["../../src/core/invalid.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;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/names.d.ts
CHANGED
|
@@ -22,6 +22,13 @@ declare const CONCEPTS: {
|
|
|
22
22
|
readonly history: {
|
|
23
23
|
readonly history: "backfill";
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Where a dataset's refresh stands (#343): pulse-admin's `data_refresh_status` on a connection.
|
|
27
|
+
* The field is renamed, its values keep pulse-admin's spelling (D563).
|
|
28
|
+
*/
|
|
29
|
+
readonly refresh_status: {
|
|
30
|
+
readonly refresh_status: "data_refresh_status";
|
|
31
|
+
};
|
|
25
32
|
};
|
|
26
33
|
export type Concept = keyof typeof CONCEPTS;
|
|
27
34
|
type Pairs<C extends Concept> = (typeof CONCEPTS)[C];
|
|
@@ -89,8 +96,12 @@ export declare const RANKED: readonly ["owner", "admin", "editor", "viewer"];
|
|
|
89
96
|
* doesn't know reads as one it has never seen (#265), so this list must follow pulse-auth's. The one
|
|
90
97
|
* list (#268): the live scripts read it from the build, through `roleFromBackend`, to stop a staff
|
|
91
98
|
* sign-in, and the tests walk it. Frozen, so nobody changes the SDK's rule by changing it, and not
|
|
92
|
-
* exported from the package.
|
|
93
|
-
*
|
|
99
|
+
* exported from the package. Every place that restates the staff rule in words changes with it by
|
|
100
|
+
* hand (#335's code review, 5): in docs/admin.md (#327), the `role`, `roles` and `unknown_roles`
|
|
101
|
+
* bullets of "Who you are" and the member's paragraph of "Your organisation's members"; in
|
|
102
|
+
* src/api/members.ts, `Member.role`'s, `Member.roles`' and `Member.unknown_roles`' docs and `zRoles`'
|
|
103
|
+
* comment; and, in src/flipstream.ts, `flipstream.members`' doc, which points at those three fields
|
|
104
|
+
* (#335 round 2, O2.F1). docs/admin.md's `role` bullet names these roles.
|
|
94
105
|
*/
|
|
95
106
|
export declare const STAFF_ROLES: readonly string[];
|
|
96
107
|
/**
|
package/dist/core/names.js
CHANGED
|
@@ -19,6 +19,11 @@ const CONCEPTS = {
|
|
|
19
19
|
* connection. The field is renamed, its values keep pulse-admin's spelling (D563).
|
|
20
20
|
*/
|
|
21
21
|
history: { history: 'backfill' },
|
|
22
|
+
/**
|
|
23
|
+
* Where a dataset's refresh stands (#343): pulse-admin's `data_refresh_status` on a connection.
|
|
24
|
+
* The field is renamed, its values keep pulse-admin's spelling (D563).
|
|
25
|
+
*/
|
|
26
|
+
refresh_status: { refresh_status: 'data_refresh_status' },
|
|
22
27
|
};
|
|
23
28
|
/**
|
|
24
29
|
* OAuth's and OpenID Connect's own calls, by endpoint: sign-in's exchange, refresh, revoke,
|
|
@@ -98,8 +103,12 @@ void everyRole; // read once, so unused-locals checks keep it
|
|
|
98
103
|
* doesn't know reads as one it has never seen (#265), so this list must follow pulse-auth's. The one
|
|
99
104
|
* list (#268): the live scripts read it from the build, through `roleFromBackend`, to stop a staff
|
|
100
105
|
* sign-in, and the tests walk it. Frozen, so nobody changes the SDK's rule by changing it, and not
|
|
101
|
-
* exported from the package.
|
|
102
|
-
*
|
|
106
|
+
* exported from the package. Every place that restates the staff rule in words changes with it by
|
|
107
|
+
* hand (#335's code review, 5): in docs/admin.md (#327), the `role`, `roles` and `unknown_roles`
|
|
108
|
+
* bullets of "Who you are" and the member's paragraph of "Your organisation's members"; in
|
|
109
|
+
* src/api/members.ts, `Member.role`'s, `Member.roles`' and `Member.unknown_roles`' docs and `zRoles`'
|
|
110
|
+
* comment; and, in src/flipstream.ts, `flipstream.members`' doc, which points at those three fields
|
|
111
|
+
* (#335 round 2, O2.F1). docs/admin.md's `role` bullet names these roles.
|
|
103
112
|
*/
|
|
104
113
|
export const STAFF_ROLES = Object.freeze(['godmode', 'swapper']);
|
|
105
114
|
const STAFF = new Set(STAFF_ROLES);
|
package/dist/core/names.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../src/core/names.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,uFAAuF;AACvF,MAAM,QAAQ,GAAG;IACf,gFAAgF;IAChF,OAAO,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE;IACxC;;;;OAIG;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,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;IAC7C,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;AACpE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiResult } from './result.js';
|
|
2
|
+
/**
|
|
3
|
+
* `not_found` exactly as a service answers it for a record nobody has, its own `code` and `message`
|
|
4
|
+
* included, so an answer the SDK makes for a record you can't see says no more than that (D571,
|
|
5
|
+
* #372). A fresh object on each call: a caller that changes one answer never changes another's
|
|
6
|
+
* (#373's code review, 8).
|
|
7
|
+
*/
|
|
8
|
+
export declare const notFound: (code: string, message: string) => ApiResult<never>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `not_found` exactly as a service answers it for a record nobody has, its own `code` and `message`
|
|
3
|
+
* included, so an answer the SDK makes for a record you can't see says no more than that (D571,
|
|
4
|
+
* #372). A fresh object on each call: a caller that changes one answer never changes another's
|
|
5
|
+
* (#373's code review, 8).
|
|
6
|
+
*/
|
|
7
|
+
export const notFound = (code, message) => ({ ok: false, error: { kind: 'not_found', status: 404, code, message } });
|
|
8
|
+
//# sourceMappingURL=notFound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notFound.js","sourceRoot":"","sources":["../../src/core/notFound.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,OAAe,EAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA"}
|
package/dist/core/result.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { PlannerErrorCode } from '../spec/query-planner/types.gen.js';
|
|
2
2
|
/**
|
|
3
|
-
* What every call returns: its data, or one failure with one meaning (D412). `
|
|
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
5
|
* request carrying it went out, on either arm, and absent when nothing was sent.
|
|
6
6
|
*/
|
|
7
7
|
export type ApiResult<T> = {
|
|
8
8
|
readonly ok: true;
|
|
9
9
|
readonly data: T;
|
|
10
|
-
readonly
|
|
10
|
+
readonly trace_id?: string;
|
|
11
11
|
} | {
|
|
12
12
|
readonly ok: false;
|
|
13
13
|
readonly error: ApiError;
|
|
14
|
-
readonly
|
|
14
|
+
readonly trace_id?: string;
|
|
15
15
|
};
|
|
16
16
|
/** The failures a status gives: the host answered, and said no. */
|
|
17
17
|
export type StatusKind = 'unauthorized' | 'forbidden' | 'not_found' | 'conflict' | 'rejected' | 'unavailable';
|
|
@@ -32,25 +32,25 @@ export type Said = {
|
|
|
32
32
|
readonly code: ErrorCode;
|
|
33
33
|
readonly message: string;
|
|
34
34
|
/** The request's id, once a host sends one. None does yet (D429). */
|
|
35
|
-
readonly
|
|
35
|
+
readonly request_id?: string;
|
|
36
36
|
readonly text?: never;
|
|
37
37
|
} | {
|
|
38
38
|
readonly text: string;
|
|
39
39
|
readonly code?: never;
|
|
40
40
|
readonly message?: never;
|
|
41
|
-
readonly
|
|
41
|
+
readonly request_id?: never;
|
|
42
42
|
} | {
|
|
43
43
|
readonly text?: never;
|
|
44
44
|
readonly code?: never;
|
|
45
45
|
readonly message?: never;
|
|
46
|
-
readonly
|
|
46
|
+
readonly request_id?: never;
|
|
47
47
|
};
|
|
48
48
|
/** A failure the host answered with a status, and what came with it. */
|
|
49
49
|
export type Answered = {
|
|
50
50
|
readonly kind: StatusKind;
|
|
51
51
|
readonly status: number;
|
|
52
52
|
/** How long the host asked the caller to wait (`Retry-After`), when it said so. */
|
|
53
|
-
readonly
|
|
53
|
+
readonly retry_after_ms?: number;
|
|
54
54
|
} & Said;
|
|
55
55
|
export type ApiError = Answered
|
|
56
56
|
/** No answer at all: offline, a body that broke off, or no token right now. */
|
|
@@ -59,8 +59,13 @@ export type ApiError = Answered
|
|
|
59
59
|
readonly status?: never;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Outside the contract: reported, never shown as empty. `status` is
|
|
63
|
-
*
|
|
62
|
+
* Outside the contract: reported, never shown as empty. `status` is set on a failure from an
|
|
63
|
+
* answer whose status the SDK knows. When the answer's own status or shape is outside the
|
|
64
|
+
* 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), it's the success status that route answers by its backend's
|
|
66
|
+
* own code, 200 for every read and both PUTs, assumed from a 2xx and never observed. A create's
|
|
67
|
+
* answer has none, since its route's success status isn't known. `text` is its body, when a 2xx
|
|
68
|
+
* body is not JSON.
|
|
64
69
|
*/
|
|
65
70
|
| {
|
|
66
71
|
readonly kind: 'invalid';
|
|
@@ -141,8 +146,8 @@ export type RefusedReason =
|
|
|
141
146
|
| 'callback';
|
|
142
147
|
/**
|
|
143
148
|
* A failed call, thrown by `orThrow`, carrying its `ApiError`. When the call's requests went out
|
|
144
|
-
* under a trace (#251), it carries that `
|
|
145
|
-
* `(request <
|
|
149
|
+
* under a trace (#251), it carries that `trace_id` too (#262), and its message ends with
|
|
150
|
+
* `(request <trace_id>)`, so whoever catches or prints it can find them in Logs.
|
|
146
151
|
*/
|
|
147
152
|
export declare class ApiFailure extends Error {
|
|
148
153
|
readonly error: ApiError;
|
|
@@ -150,7 +155,7 @@ export declare class ApiFailure extends Error {
|
|
|
150
155
|
* The call's W3C trace-id, when its requests went out under one; absent otherwise. Declared, not
|
|
151
156
|
* defined, so a class field doesn't make it an own property holding `undefined`.
|
|
152
157
|
*/
|
|
153
|
-
readonly
|
|
158
|
+
readonly trace_id?: string;
|
|
154
159
|
constructor(error: ApiError, traceId?: string);
|
|
155
160
|
}
|
|
156
161
|
/** The data, or the failure thrown as `ApiFailure`, for callers who want exceptions (D412). */
|
package/dist/core/result.js
CHANGED
|
@@ -50,8 +50,8 @@ function failureMessage(error) {
|
|
|
50
50
|
const TRACE_ID = /^[0-9a-f]{32}$/;
|
|
51
51
|
/**
|
|
52
52
|
* A failed call, thrown by `orThrow`, carrying its `ApiError`. When the call's requests went out
|
|
53
|
-
* under a trace (#251), it carries that `
|
|
54
|
-
* `(request <
|
|
53
|
+
* under a trace (#251), it carries that `trace_id` too (#262), and its message ends with
|
|
54
|
+
* `(request <trace_id>)`, so whoever catches or prints it can find them in Logs.
|
|
55
55
|
*/
|
|
56
56
|
export class ApiFailure extends Error {
|
|
57
57
|
error;
|
|
@@ -61,15 +61,15 @@ export class ApiFailure extends Error {
|
|
|
61
61
|
super(traced === undefined ? failureMessage(error) : `${failureMessage(error)} (request ${traced})`);
|
|
62
62
|
this.name = 'ApiFailure';
|
|
63
63
|
this.error = error;
|
|
64
|
-
// Only a trace-id, and only when there is one, so `'
|
|
64
|
+
// Only a trace-id, and only when there is one, so `'trace_id' in failure` means one went out.
|
|
65
65
|
if (traced !== undefined)
|
|
66
|
-
this.
|
|
66
|
+
this.trace_id = traced;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
/** The data, or the failure thrown as `ApiFailure`, for callers who want exceptions (D412). */
|
|
70
70
|
export function orThrow(result) {
|
|
71
71
|
if (!result.ok)
|
|
72
|
-
throw new ApiFailure(result.error, result.
|
|
72
|
+
throw new ApiFailure(result.error, result.trace_id);
|
|
73
73
|
return result.data;
|
|
74
74
|
}
|
|
75
75
|
//# sourceMappingURL=result.js.map
|