@flipstream/sdk 0.11.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +179 -424
  3. package/dist/api/backend.d.ts +21 -3
  4. package/dist/api/backend.js +50 -10
  5. package/dist/api/backend.js.map +1 -1
  6. package/dist/api/credentials.js +4 -4
  7. package/dist/api/credentials.js.map +1 -1
  8. package/dist/api/datasets.d.ts +82 -14
  9. package/dist/api/datasets.js +193 -57
  10. package/dist/api/datasets.js.map +1 -1
  11. package/dist/api/index.d.ts +1 -1
  12. package/dist/api/log.d.ts +25 -20
  13. package/dist/api/log.js +63 -48
  14. package/dist/api/log.js.map +1 -1
  15. package/dist/api/me.js +9 -5
  16. package/dist/api/me.js.map +1 -1
  17. package/dist/api/members.d.ts +34 -1
  18. package/dist/api/members.js +67 -27
  19. package/dist/api/members.js.map +1 -1
  20. package/dist/api/wallet.d.ts +8 -5
  21. package/dist/api/wallet.js +40 -25
  22. package/dist/api/wallet.js.map +1 -1
  23. package/dist/api/workspaces.d.ts +35 -14
  24. package/dist/api/workspaces.js +53 -23
  25. package/dist/api/workspaces.js.map +1 -1
  26. package/dist/auth/discovery.d.ts +19 -6
  27. package/dist/auth/discovery.js +30 -6
  28. package/dist/auth/discovery.js.map +1 -1
  29. package/dist/auth/signIn.d.ts +18 -14
  30. package/dist/auth/signIn.js +29 -22
  31. package/dist/auth/signIn.js.map +1 -1
  32. package/dist/core/call.d.ts +13 -1
  33. package/dist/core/call.js +34 -9
  34. package/dist/core/call.js.map +1 -1
  35. package/dist/core/deadline.d.ts +30 -0
  36. package/dist/core/deadline.js +51 -0
  37. package/dist/core/deadline.js.map +1 -0
  38. package/dist/core/identify.d.ts +59 -14
  39. package/dist/core/identify.js +54 -20
  40. package/dist/core/identify.js.map +1 -1
  41. package/dist/core/invalid.d.ts +10 -0
  42. package/dist/core/invalid.js +28 -0
  43. package/dist/core/invalid.js.map +1 -0
  44. package/dist/core/names.d.ts +13 -2
  45. package/dist/core/names.js +11 -2
  46. package/dist/core/names.js.map +1 -1
  47. package/dist/core/notFound.d.ts +8 -0
  48. package/dist/core/notFound.js +8 -0
  49. package/dist/core/notFound.js.map +1 -0
  50. package/dist/core/read.d.ts +9 -0
  51. package/dist/core/read.js +14 -5
  52. package/dist/core/read.js.map +1 -1
  53. package/dist/core/result.d.ts +22 -13
  54. package/dist/core/result.js +5 -5
  55. package/dist/core/result.js.map +1 -1
  56. package/dist/core/retry.d.ts +5 -2
  57. package/dist/core/retry.js +6 -3
  58. package/dist/core/retry.js.map +1 -1
  59. package/dist/core/scope.d.ts +20 -0
  60. package/dist/core/scope.js +54 -0
  61. package/dist/core/scope.js.map +1 -0
  62. package/dist/core/shared.d.ts +39 -0
  63. package/dist/core/shared.js +177 -0
  64. package/dist/core/shared.js.map +1 -0
  65. package/dist/core/signal.d.ts +12 -0
  66. package/dist/core/signal.js +25 -0
  67. package/dist/core/signal.js.map +1 -0
  68. package/dist/flipstream.d.ts +223 -72
  69. package/dist/flipstream.js +225 -88
  70. package/dist/flipstream.js.map +1 -1
  71. package/dist/index.d.ts +1 -1
  72. package/dist/node/clientSecret.js +7 -6
  73. package/dist/node/clientSecret.js.map +1 -1
  74. package/dist/node/headless.d.ts +14 -6
  75. package/dist/node/headless.js +8 -6
  76. package/dist/node/headless.js.map +1 -1
  77. package/dist/node/index.d.ts +1 -1
  78. package/dist/node/index.js +1 -1
  79. package/dist/node/index.js.map +1 -1
  80. package/dist/node/keychainChild.js +26 -14
  81. package/dist/node/keychainChild.js.map +1 -1
  82. package/dist/node/keychainError.d.ts +3 -3
  83. package/dist/node/keychainStore.d.ts +10 -7
  84. package/dist/node/keychainStore.js +44 -23
  85. package/dist/node/keychainStore.js.map +1 -1
  86. package/dist/node/loopback.d.ts +13 -3
  87. package/dist/node/loopback.js +47 -5
  88. package/dist/node/loopback.js.map +1 -1
  89. package/dist/node/session.d.ts +17 -9
  90. package/dist/node/session.js +68 -50
  91. package/dist/node/session.js.map +1 -1
  92. package/dist/node/store.d.ts +35 -2
  93. package/dist/node/store.js +56 -12
  94. package/dist/node/store.js.map +1 -1
  95. package/dist/version.gen.js +1 -1
  96. package/docs/admin.md +558 -0
  97. package/docs/node-sign-in.md +63 -39
  98. package/package.json +1 -1
@@ -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, or
10
- * the scopes are empty or one holds a space: from TypeScript, none of these compiles. Always S256;
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.authorizationEndpoint);
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
- tokenEndpoint: server.tokenEndpoint,
43
- issuerOnRedirect: server.issuerOnRedirect,
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.issuerOnRedirect : iss !== pending.issuer)
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
- clientId: z.string().min(1),
72
- redirectUri: z.string().min(1),
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
- tokenEndpoint: z.string(),
76
- issuerOnRedirect: z.boolean(),
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.tokenEndpoint]) === null);
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) is `refused`, with nothing sent. A public client's: an app
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.tokenEndpoint, options.allowLocalhostHttp))
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.redirectUri,
113
- client_id: pending.clientId,
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 = Date.now();
118
- const answer = await call(authTransport(options), tokenCall('auth.token', pending.tokenEndpoint, form, 30_000, authorization), options.signal);
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
- accessToken: access_token,
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) ? { refreshToken: refresh_token } : {}),
128
- ...(expires_in === undefined ? {} : { expiresAt: sentAt + expires_in * 1000 }),
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,
@@ -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;AAGtC,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;AAoElG,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAA;AAE/F;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAsB;IACtD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IACzD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,kEAAkE,CAAC,CAAA;IAChH,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAA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type RetryRule } from './retry.js';
4
5
  import type { ApiRequest, Transport } from './transport.js';
@@ -14,10 +15,21 @@ export interface CallSpec<T> extends Omit<ApiRequest, 'signal'> {
14
15
  * alone (#278 round 1). Left out, the text is kept, as for every other call.
15
16
  */
16
17
  readonly keepsNoText?: true;
18
+ /**
19
+ * Inside one scope (`flipstream.scope()`, #376), one read serves every call that asks for it, by
20
+ * its key: your organisation's, your person's and a workspace's own. Left out, every call reads
21
+ * its own.
22
+ */
23
+ readonly shared?: SharedRule;
17
24
  }
18
25
  /**
19
26
  * One call: attempts under its rule, every attempt, wait and read under one signal that joins the
20
27
  * caller's with the deadline. Whichever fires first decides the answer, `timeout` or `aborted`
21
28
  * (#15), never mixed. The call ends when it fires, whatever the transport does with the signal.
29
+ * `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
30
+ * does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
31
+ * the caller's, so a caller's signal gets one listener a request, as before, and never one more.
32
+ * `answered` hears the status of the 2xx the call answers with, for a read several calls share
33
+ * (#376), each of which reads it by its own schema with that status.
22
34
  */
23
- export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal): Promise<ApiResult<T>>;
35
+ export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal, callEnd?: AbortSignal, answered?: (status: number) => void): Promise<ApiResult<T>>;
package/dist/core/call.js CHANGED
@@ -1,15 +1,35 @@
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';
5
+ import { stopListening } from './signal.js';
4
6
  /**
5
7
  * One call: attempts under its rule, every attempt, wait and read under one signal that joins the
6
8
  * caller's with the deadline. Whichever fires first decides the answer, `timeout` or `aborted`
7
9
  * (#15), never mixed. The call ends when it fires, whatever the transport does with the signal.
10
+ * `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
11
+ * does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
12
+ * the caller's, so a caller's signal gets one listener a request, as before, and never one more.
13
+ * `answered` hears the status of the 2xx the call answers with, for a read several calls share
14
+ * (#376), each of which reads it by its own schema with that status.
8
15
  */
9
- export async function call(transport, spec, signal) {
10
- if (signal?.aborted === true)
16
+ export async function call(transport, spec, signal, callEnd, answered) {
17
+ if (signal?.aborted === true || callEnd?.aborted === true)
11
18
  return failed({ kind: 'aborted' });
12
- const deadline = Date.now() + spec.deadlineMs;
19
+ // A call with no time for it is over before it starts: nothing is sent, as nothing is for a caller
20
+ // that has already aborted (#339). No time is what a deadline's passed() calls it (#337): under
21
+ // 1 ms, or not a number. A caller that checked its own deadline a moment before may still hand on
22
+ // under 1 ms, the time left read again. It's read off the value handed, as passed() reads it the
23
+ // moment the deadline is set: a microsecond later, a deadline of 1 ms already reads passed, and a
24
+ // call given 1 ms would never go out. A deadline past what a timer holds would fire after 1 ms,
25
+ // so it's none either; the public `deadlineMs` is refused before it gets here (#340's code
26
+ // review, 1-3).
27
+ if (!(spec.deadlineMs >= 1) || spec.deadlineMs > MAX_TIMER_MS)
28
+ return failed({ kind: 'timeout' });
29
+ // On the monotonic clock, as the timer below is, so whether a wait fits is read as the timer
30
+ // counts: a wall clock stepped back would start waits past it, one stepped forward refuse waits
31
+ // that fit (#333).
32
+ const deadline = deadlineIn(spec.deadlineMs);
13
33
  // Owned here, strongly: the timer and the caller's listener each hold `stop`, so the deadline
14
34
  // reaches every attempt, however weakly a transport or its fetch keeps the signal (#57).
15
35
  const stop = new AbortController();
@@ -17,6 +37,8 @@ export async function call(transport, spec, signal) {
17
37
  const timer = setTimeout(() => stop.abort(timedOut), spec.deadlineMs);
18
38
  const onAbort = () => stop.abort(signal?.reason);
19
39
  signal?.addEventListener('abort', onAbort, { once: true });
40
+ const onEnd = () => stop.abort(callEnd?.reason);
41
+ callEnd?.addEventListener('abort', onEnd, { once: true });
20
42
  // The first abort's reason stays: that is how the call knows which came first.
21
43
  const ended = () => failed(stop.signal.reason === timedOut ? { kind: 'timeout' } : { kind: 'aborted' });
22
44
  const fired = new Promise((resolve) => stop.signal.addEventListener('abort', () => resolve(ENDED), { once: true }));
@@ -31,7 +53,7 @@ export async function call(transport, spec, signal) {
31
53
  letGo(sent);
32
54
  return ended();
33
55
  }
34
- let decision = decide(spec.retry, attempt, outcomeOf(sent), Date.now(), deadline);
56
+ let decision = decide(spec.retry, attempt, outcomeOf(sent), deadline.left());
35
57
  if (decision.kind === 'stop') {
36
58
  const result = await unlessFired(readJson(sent, spec.schema, stop.signal, spec.service, spec.keepsNoText === true), fired, () => undefined);
37
59
  if (result === ENDED || stop.signal.aborted)
@@ -39,9 +61,12 @@ export async function call(transport, spec, signal) {
39
61
  // A success whose body broke off is a transport failure too, so a read tries again under
40
62
  // its rule. Any other status already decided: its answer stands, however its body ended.
41
63
  if (brokeOff(sent, result))
42
- decision = decide(spec.retry, attempt, { kind: 'unavailable' }, Date.now(), deadline);
43
- if (decision.kind === 'stop')
64
+ decision = decide(spec.retry, attempt, { kind: 'unavailable' }, deadline.left());
65
+ if (decision.kind === 'stop') {
66
+ if (result.ok && sent.kind === 'response')
67
+ answered?.(sent.response.status);
44
68
  return withRetryAfter(result, sent);
69
+ }
45
70
  }
46
71
  else {
47
72
  letGo(sent);
@@ -55,8 +80,8 @@ export async function call(transport, spec, signal) {
55
80
  finally {
56
81
  clearTimeout(timer);
57
82
  // A minimal polyfill signal may have no removeEventListener; it keeps its one listener.
58
- if (typeof signal?.removeEventListener === 'function')
59
- signal.removeEventListener('abort', onAbort);
83
+ stopListening(signal, onAbort);
84
+ callEnd?.removeEventListener('abort', onEnd);
60
85
  }
61
86
  }
62
87
  const ENDED = Symbol('ended');
@@ -91,7 +116,7 @@ function withRetryAfter(result, sent) {
91
116
  if (result.ok || sent.kind !== 'response' || !answered(result.error))
92
117
  return result;
93
118
  const retryAfterMs = parseRetryAfterMs(sent.response.headers.get('retry-after'));
94
- return retryAfterMs === undefined ? result : failed({ ...result.error, retryAfterMs });
119
+ return retryAfterMs === undefined ? result : failed({ ...result.error, retry_after_ms: retryAfterMs });
95
120
  }
96
121
  // Of what readJson gives for a response, only a failure status's answer has a kind other than
97
122
  // `invalid` and a status.
@@ -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;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAI,SAAoB,EAAE,IAAiB,EAAE,MAAoB;IACzF,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,CAAA;IAC7C,8FAA8F;IAC9F,yFAAyF;IACzF,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAA;IAClC,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,GAAG,IAAI,CAAC,QAAQ,2BAA2B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;IAC1H,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IACrE,MAAM,OAAO,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtD,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;I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AE,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"}
@@ -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"}
@@ -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
- /** What a request says about who sent it: its User-Agent and baggage, and the caller's values in them. */
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 userAgent: string;
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: `User-Agent: <app>/<version> flipstream-sdk/<version> node/<version>`, and
42
- * `baggage` with OpenTelemetry's GenAI names, each value percent-encoded, only when there is an
43
- * agent or a conversation: no empty header.
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, nodeVersion: string): Sender;
51
+ export declare function callerSender(identity: Identity, conversationId: string | undefined, runtime: Identifying): Sender;
46
52
  /**
47
- * Health's, signed out (D535): `User-Agent: flipstream-sdk/<version> node/<version>` alone. It asks
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(nodeVersion: string): Sender;
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
- * Node's version, where these headers go out: Node, or a runtime that says it is Node's (Bun, Deno),
59
- * with no `window`. In a browser, a CORS preflight would refuse every call until the hosts allow
60
- * the headers (query-planner#48), so none go there yet. Electron's renderer and a jsdom test, which
61
- * have both, send none: an unidentified request still works, a refused preflight doesn't.
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 nodeVersion(): string | undefined;
108
+ export declare function identifies(runtime: Identifying, service: ServiceName, atDeployedOrigin: boolean): boolean;
@@ -68,29 +68,34 @@ function randomHex(bytes, zero) {
68
68
  }
69
69
  }
70
70
  /**
71
- * A signed-in call's: `User-Agent: <app>/<version> flipstream-sdk/<version> node/<version>`, and
72
- * `baggage` with OpenTelemetry's GenAI names, each value percent-encoded, only when there is an
73
- * agent or a conversation: no empty header.
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, nodeVersion) {
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
- userAgent: `${app.name}/${app.version} ${sdkSender(nodeVersion).userAgent}`,
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): `User-Agent: flipstream-sdk/<version> node/<version>` alone. It asks
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(nodeVersion) {
93
- return { userAgent: `flipstream-sdk/${version} node/${nodeVersion}`, baggage: undefined, values: [] };
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's version, where these headers go out: Node, or a runtime that says it is Node's (Bun, Deno),
110
- * with no `window`. In a browser, a CORS preflight would refuse every call until the hosts allow
111
- * the headers (query-planner#48), so none go there yet. Electron's renderer and a jsdom test, which
112
- * have both, send none: an unidentified request still works, a refused preflight doesn't.
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 nodeVersion() {
115
- if (typeof window !== 'undefined' || typeof process === 'undefined')
116
- return undefined;
117
- // A bundler's stand-in `process` may have no versions at all.
118
- const versions = process.versions;
119
- const node = isRecord(versions) ? versions['node'] : undefined;
120
- return typeof node === 'string' && PRODUCT_TOKEN.test(node) ? node : undefined;
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