@flipstream/sdk 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +707 -66
  3. package/dist/api/backend.d.ts +182 -0
  4. package/dist/api/backend.js +314 -0
  5. package/dist/api/backend.js.map +1 -0
  6. package/dist/api/created.d.ts +5 -0
  7. package/dist/api/created.js +15 -0
  8. package/dist/api/created.js.map +1 -0
  9. package/dist/api/credentials.d.ts +36 -0
  10. package/dist/api/credentials.js +94 -0
  11. package/dist/api/credentials.js.map +1 -0
  12. package/dist/api/datasets.d.ts +94 -0
  13. package/dist/api/datasets.js +212 -0
  14. package/dist/api/datasets.js.map +1 -0
  15. package/dist/api/handoff.d.ts +34 -0
  16. package/dist/api/handoff.js +52 -0
  17. package/dist/api/handoff.js.map +1 -0
  18. package/dist/api/ids.d.ts +7 -0
  19. package/dist/api/ids.js +27 -0
  20. package/dist/api/ids.js.map +1 -0
  21. package/dist/api/index.d.ts +9 -1
  22. package/dist/api/log.d.ts +95 -0
  23. package/dist/api/log.js +213 -0
  24. package/dist/api/log.js.map +1 -0
  25. package/dist/api/me.d.ts +58 -0
  26. package/dist/api/me.js +64 -0
  27. package/dist/api/me.js.map +1 -0
  28. package/dist/api/members.d.ts +48 -0
  29. package/dist/api/members.js +102 -0
  30. package/dist/api/members.js.map +1 -0
  31. package/dist/api/organization.d.ts +11 -0
  32. package/dist/api/organization.js +15 -0
  33. package/dist/api/organization.js.map +1 -0
  34. package/dist/api/page.d.ts +33 -0
  35. package/dist/api/page.js +38 -0
  36. package/dist/api/page.js.map +1 -0
  37. package/dist/api/time.d.ts +3 -0
  38. package/dist/api/time.js +49 -0
  39. package/dist/api/time.js.map +1 -0
  40. package/dist/api/unsent.d.ts +6 -0
  41. package/dist/api/unsent.js +9 -0
  42. package/dist/api/unsent.js.map +1 -0
  43. package/dist/api/wallet.d.ts +45 -0
  44. package/dist/api/wallet.js +102 -0
  45. package/dist/api/wallet.js.map +1 -0
  46. package/dist/api/workspaces.d.ts +70 -0
  47. package/dist/api/workspaces.js +108 -0
  48. package/dist/api/workspaces.js.map +1 -0
  49. package/dist/auth/discovery.js +1 -1
  50. package/dist/auth/discovery.js.map +1 -1
  51. package/dist/auth/signIn.js +7 -2
  52. package/dist/auth/signIn.js.map +1 -1
  53. package/dist/core/body.js +23 -5
  54. package/dist/core/body.js.map +1 -1
  55. package/dist/core/call.d.ts +6 -0
  56. package/dist/core/call.js +1 -1
  57. package/dist/core/call.js.map +1 -1
  58. package/dist/core/fetch.d.ts +5 -0
  59. package/dist/core/fetch.js +7 -1
  60. package/dist/core/fetch.js.map +1 -1
  61. package/dist/core/identify.d.ts +63 -0
  62. package/dist/core/identify.js +122 -0
  63. package/dist/core/identify.js.map +1 -0
  64. package/dist/core/names.d.ts +100 -0
  65. package/dist/core/names.js +114 -0
  66. package/dist/core/names.js.map +1 -0
  67. package/dist/core/read.d.ts +1 -1
  68. package/dist/core/read.js +15 -6
  69. package/dist/core/read.js.map +1 -1
  70. package/dist/core/result.d.ts +67 -6
  71. package/dist/core/result.js +39 -6
  72. package/dist/core/result.js.map +1 -1
  73. package/dist/core/secrets.d.ts +2 -0
  74. package/dist/core/secrets.js +33 -0
  75. package/dist/core/secrets.js.map +1 -0
  76. package/dist/core/transport.d.ts +12 -4
  77. package/dist/flipstream.d.ts +341 -5
  78. package/dist/flipstream.js +203 -13
  79. package/dist/flipstream.js.map +1 -1
  80. package/dist/index.d.ts +2 -2
  81. package/dist/index.js +1 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/node/clientSecret.js +2 -1
  84. package/dist/node/clientSecret.js.map +1 -1
  85. package/dist/node/index.d.ts +1 -0
  86. package/dist/node/index.js +1 -0
  87. package/dist/node/index.js.map +1 -1
  88. package/dist/node/keychainChild.js +10 -6
  89. package/dist/node/keychainChild.js.map +1 -1
  90. package/dist/node/keychainStore.d.ts +6 -3
  91. package/dist/node/keychainStore.js +6 -3
  92. package/dist/node/keychainStore.js.map +1 -1
  93. package/dist/node/session.d.ts +78 -29
  94. package/dist/node/session.js +74 -52
  95. package/dist/node/session.js.map +1 -1
  96. package/dist/node/store.d.ts +11 -1
  97. package/dist/node/store.js +14 -1
  98. package/dist/node/store.js.map +1 -1
  99. package/dist/query/query.d.ts +15 -10
  100. package/dist/query/query.js +21 -11
  101. package/dist/query/query.js.map +1 -1
  102. package/dist/version.gen.js +1 -1
  103. package/dist/version.gen.js.map +1 -1
  104. package/package.json +2 -2
package/dist/core/body.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { z } from 'zod';
1
2
  import { zErrorBody } from '../spec/query-planner/zod.gen.js';
2
3
  export function parseJson(text) {
3
4
  try {
@@ -16,13 +17,24 @@ const CODE_SHAPE = /^[A-Z][A-Z0-9_]{0,63}$/;
16
17
  /** A message is capped, by code point so the cap never splits a character in two. */
17
18
  const MESSAGE_MAX = 500;
18
19
  const capped = (message) => (message.length <= MESSAGE_MAX ? message : Array.from(message).slice(0, MESSAGE_MAX).join(''));
19
- /** The planner's `{ code, message }`, its spec's ErrorBody (D429), with a code of a code's shape. */
20
- const planner = (body) => {
21
- const read = zErrorBody.safeParse(body);
20
+ /** A `{ code, message }` envelope read by `schema`, with a code of a code's shape and a capped message. */
21
+ const codeAndMessage = (schema) => (body) => {
22
+ const read = schema.safeParse(body);
22
23
  if (!read.success || !CODE_SHAPE.test(read.data.code))
23
24
  return null;
24
25
  return { code: read.data.code, message: capped(read.data.message) };
25
26
  };
27
+ /** The planner's `{ code, message }`, its spec's ErrorBody (D429). */
28
+ const planner = codeAndMessage(zErrorBody);
29
+ /**
30
+ * fractal's `ErrorMessage`, `{ code, message }`, which pulse-admin, pulse-auth and pulse-wallet
31
+ * send for a token, permission or domain error (`TOKEN_EXPIRED_EXCEPTION`, `ORGANIZATION_AMBIGUOUS`).
32
+ * Written from their exception handlers (pulse-admin dff6bf9, pulse-auth 0ae57c8,
33
+ * `adapters/ingress/fastapi`), since no spec declares it. Their 422 and 500 put a Python class name
34
+ * in `code` (`RequestValidationError`, `KeyError`), which isn't a code's shape, so those stay text,
35
+ * as FastAPI's own `{ detail }` does: it has no code at all.
36
+ */
37
+ const fractal = codeAndMessage(z.object({ code: z.string(), message: z.string() }));
26
38
  /**
27
39
  * An OAuth code is lowercase (`invalid_grant`, RFC 6749 §5.2), so it has its own bound, kept as
28
40
  * tight as a planner code's for the same reason.
@@ -48,9 +60,15 @@ const oauth = (body) => {
48
60
  /**
49
61
  * Each service's envelopes (D442): a host's error body is read only by the envelope that host
50
62
  * sends, so a proxy's `{"error":"not_found"}` on the query host is never taken for an OAuth code.
51
- * #91's `{ error: { code, message, request_id } }` joins `api` from its own spec (SD37).
63
+ * #91's `{ error: { code, message, request_id } }` joins `api` from its own spec, once it has one.
52
64
  */
53
- const ENVELOPES = { query: [planner], auth: [oauth], api: [] };
65
+ const ENVELOPES = {
66
+ query: [planner],
67
+ auth: [oauth, fractal],
68
+ admin: [fractal],
69
+ wallet: [fractal],
70
+ api: [],
71
+ };
54
72
  /**
55
73
  * What a failure status from `service` came with: the first of its envelopes that reads the body,
56
74
  * or the body as it came.
@@ -1 +1 @@
1
- {"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/core/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAQ7D,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAA;IACtB,CAAC;AACH,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,GAAG,wBAAwB,CAAA;AAE3C,qFAAqF;AACrF,MAAM,WAAW,GAAG,GAAG,CAAA;AACvB,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EAAE,CAAA;AACjB,CAAC"}
@@ -8,6 +8,12 @@ export interface CallSpec<T> extends Omit<ApiRequest, 'signal'> {
8
8
  /** How long the whole call may take: every attempt, every wait and the reading of the answer. */
9
9
  readonly deadlineMs: number;
10
10
  readonly retry: RetryRule;
11
+ /**
12
+ * The answer may hold a secret's value (a sign-in's, #70), so no body's text is kept: a 2xx that
13
+ * isn't JSON, or a failure body that isn't the host's own error shape, gives its kind and status
14
+ * alone (#278 round 1). Left out, the text is kept, as for every other call.
15
+ */
16
+ readonly keepsNoText?: true;
11
17
  }
12
18
  /**
13
19
  * One call: attempts under its rule, every attempt, wait and read under one signal that joins the
package/dist/core/call.js CHANGED
@@ -33,7 +33,7 @@ export async function call(transport, spec, signal) {
33
33
  }
34
34
  let decision = decide(spec.retry, attempt, outcomeOf(sent), Date.now(), deadline);
35
35
  if (decision.kind === 'stop') {
36
- const result = await unlessFired(readJson(sent, spec.schema, stop.signal, spec.service), fired, () => undefined);
36
+ const result = await unlessFired(readJson(sent, spec.schema, stop.signal, spec.service, spec.keepsNoText === true), fired, () => undefined);
37
37
  if (result === ENDED || stop.signal.aborted)
38
38
  return ended();
39
39
  // A success whose body broke off is a transport failure too, so a read tries again under
@@ -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;AAgBpF;;;;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,GA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AAE,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"}
@@ -15,6 +15,11 @@ export interface FetchTransportOptions {
15
15
  readonly hosts: Readonly<Partial<Record<ServiceName, string>>>;
16
16
  /** Plain http to a loopback host (localhost, 127.0.0.1, [::1]): development and tests only. */
17
17
  readonly allowLocalhostHttp?: boolean | undefined;
18
+ /**
19
+ * Whether `request`, as built, carries `token` where only its authorization header may: then it
20
+ * is refused, unsent (#192). createFlipstream's check of the values that identify the caller.
21
+ */
22
+ readonly holdsToken?: ((request: Request, token: string) => boolean) | undefined;
18
23
  }
19
24
  /**
20
25
  * Plain http to this machine (localhost, 127.0.0.1, [::1]), which `allowLocalhostHttp` lets
@@ -1,4 +1,7 @@
1
- const SERVICES = ['query', 'api', 'auth'];
1
+ const SERVICES = ['query', 'api', 'auth', 'admin', 'wallet'];
2
+ // Fails to compile when ServiceName gains a service SERVICES doesn't list, so no host is left unread.
3
+ const everyService = true;
4
+ void everyService; // read once, so unused-locals checks keep it
2
5
  const LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]']);
3
6
  /**
4
7
  * Plain http to this machine (localhost, 127.0.0.1, [::1]), which `allowLocalhostHttp` lets
@@ -9,6 +12,7 @@ export function isLoopbackHttp(url) {
9
12
  }
10
13
  const ABORTED = { kind: 'aborted' };
11
14
  const REFUSED = { kind: 'refused', reason: 'destination' };
15
+ const HOLDS_TOKEN = { kind: 'refused', reason: 'identification' };
12
16
  export function fetchTransport(options) {
13
17
  const send = options.fetch ?? globalThis.fetch;
14
18
  const allowed = destinations(options);
@@ -26,6 +30,8 @@ export function fetchTransport(options) {
26
30
  return token;
27
31
  if (call.signal.aborted)
28
32
  return ABORTED;
33
+ if (options.holdsToken?.(built, token.token) === true)
34
+ return HOLDS_TOKEN;
29
35
  const headers = new Headers(built.headers);
30
36
  try {
31
37
  headers.set('authorization', `Bearer ${token.token}`);
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/core/fetch.ts"],"names":[],"mappings":"AA2BA,MAAM,QAAQ,GAA2B,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AACjE,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAA;AAElF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,GAAQ;IACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC/D,CAAC;AACD,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAW,CAAA;AAC5C,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAW,CAAA;AAOnE,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAA;IAC9C,MAA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AK,QAAQ,IAAI,KAAK,KAAK,EAAE;QACvC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;QACjC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,kCAAkC,CAAC,EAAE,EACpF,CAAC,KAAc,EAAS,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CACzD,CAAA;IACH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;IAC7C,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;AACH,CAAC"}
@@ -0,0 +1,63 @@
1
+ /** An app's or an agent's name and version, as a product token: `name/version`. */
2
+ export interface Product {
3
+ readonly name: string;
4
+ readonly version: string;
5
+ }
6
+ /** What a client says about itself, checked once, at creation. */
7
+ export interface Identity {
8
+ readonly app: Product;
9
+ readonly agent: Product | undefined;
10
+ readonly conversationId: string | undefined;
11
+ }
12
+ export declare function isConversationId(value: unknown): value is string;
13
+ /** The client's identity from createFlipstream's options, or a TypeError naming what breaks its rule. */
14
+ export declare function identityOf(options: {
15
+ readonly app?: unknown;
16
+ readonly agent?: unknown;
17
+ readonly conversationId?: unknown;
18
+ }): Identity;
19
+ /** One call's trace: the caller's trace-id and flags when it passed a valid traceparent, or new ones. */
20
+ export interface Trace {
21
+ readonly traceId: string;
22
+ readonly flags: string;
23
+ }
24
+ /**
25
+ * The trace a call goes out under. A caller's own `traceparent` is carried on when it is one;
26
+ * otherwise, as W3C Trace Context says of one that can't be parsed, the call starts its own. A new
27
+ * trace is sampled (`01`), so a backend that samples on its parent records it: the query log
28
+ * needs every request (D527).
29
+ */
30
+ export declare function traceFor(callerTraceparent: unknown): Trace;
31
+ /** The traceparent of one attempt: the call's trace, with a parent-id of its own. */
32
+ 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
+ export interface Sender {
35
+ readonly userAgent: string;
36
+ readonly baggage: string | undefined;
37
+ /** Each of which must never hold the access token. */
38
+ readonly values: readonly string[];
39
+ }
40
+ /**
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.
44
+ */
45
+ export declare function callerSender(identity: Identity, conversationId: string | undefined, nodeVersion: string): Sender;
46
+ /**
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.
49
+ */
50
+ export declare function sdkSender(nodeVersion: string): Sender;
51
+ /**
52
+ * Whether a caller's `value` holds the access token (#199): contains it, for a token of real
53
+ * length; equals it, for a shorter one, which as a substring turns up in ordinary values ('abc' in
54
+ * 'abcdef') and would refuse them by chance.
55
+ */
56
+ export declare function valueHolds(value: string, token: string): boolean;
57
+ /**
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.
62
+ */
63
+ export declare function nodeVersion(): string | undefined;
@@ -0,0 +1,122 @@
1
+ import { version } from '../version.gen.js';
2
+ // RFC 9110 §5.6.2's tchar, 1 to 64: no space, no delimiter, no control character, nothing past ASCII.
3
+ const PRODUCT_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]{1,64}$/;
4
+ const CONVERSATION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
5
+ // Version 00, lowercase hex, as W3C Trace Context Level 1 writes it.
6
+ const TRACEPARENT = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
7
+ const ZERO_TRACE_ID = '0'.repeat(32);
8
+ const ZERO_PARENT_ID = '0'.repeat(16);
9
+ const isRecord = (value) => typeof value === 'object' && value !== null;
10
+ /**
11
+ * A field that isn't one, as a TypeError naming the option and its rule, never its value: a value
12
+ * may be a secret put in the wrong place, and an error message ends up in logs.
13
+ */
14
+ function invalid(option, rule) {
15
+ return new TypeError(`createFlipstream: ${option} must be ${rule}; nothing is sent until it is`);
16
+ }
17
+ const PRODUCT_RULE = "1 to 64 of RFC 9110's token characters (letters, digits and !#$%&'*+-.^_`|~)";
18
+ const CONVERSATION_RULE = '1 to 128 of the characters A-Z, a-z, 0-9, ., _, : and -';
19
+ function product(value, option) {
20
+ if (!isRecord(value))
21
+ throw invalid(option, `{ name, version }, each ${PRODUCT_RULE}`);
22
+ const { name, version: productVersion } = value;
23
+ if (typeof name !== 'string' || !PRODUCT_TOKEN.test(name))
24
+ throw invalid(`${option}.name`, PRODUCT_RULE);
25
+ if (typeof productVersion !== 'string' || !PRODUCT_TOKEN.test(productVersion))
26
+ throw invalid(`${option}.version`, PRODUCT_RULE);
27
+ return { name, version: productVersion };
28
+ }
29
+ export function isConversationId(value) {
30
+ return typeof value === 'string' && CONVERSATION_ID.test(value);
31
+ }
32
+ /** The client's identity from createFlipstream's options, or a TypeError naming what breaks its rule. */
33
+ export function identityOf(options) {
34
+ if (options.app === undefined)
35
+ throw invalid('app', `given: { name, version }, so each request says which app sent it`);
36
+ const app = product(options.app, 'app');
37
+ const agent = options.agent === undefined ? undefined : product(options.agent, 'agent');
38
+ const { conversationId } = options;
39
+ if (conversationId !== undefined && !isConversationId(conversationId))
40
+ throw invalid('conversationId', CONVERSATION_RULE);
41
+ return { app, agent, conversationId };
42
+ }
43
+ /**
44
+ * The trace a call goes out under. A caller's own `traceparent` is carried on when it is one;
45
+ * otherwise, as W3C Trace Context says of one that can't be parsed, the call starts its own. A new
46
+ * trace is sampled (`01`), so a backend that samples on its parent records it: the query log
47
+ * needs every request (D527).
48
+ */
49
+ export function traceFor(callerTraceparent) {
50
+ const match = typeof callerTraceparent === 'string' ? TRACEPARENT.exec(callerTraceparent) : null;
51
+ if (match !== null) {
52
+ const [, traceId, parentId, flags] = match;
53
+ if (traceId !== undefined && parentId !== undefined && flags !== undefined && traceId !== ZERO_TRACE_ID && parentId !== ZERO_PARENT_ID)
54
+ return { traceId, flags };
55
+ }
56
+ return { traceId: randomHex(16, ZERO_TRACE_ID), flags: '01' };
57
+ }
58
+ /** The traceparent of one attempt: the call's trace, with a parent-id of its own. */
59
+ export function traceparent(trace) {
60
+ return `00-${trace.traceId}-${randomHex(8, ZERO_PARENT_ID)}-${trace.flags}`;
61
+ }
62
+ /** `bytes` random bytes as lowercase hex, never `zero`, which W3C Trace Context makes invalid. */
63
+ function randomHex(bytes, zero) {
64
+ for (;;) {
65
+ const hex = Array.from(crypto.getRandomValues(new Uint8Array(bytes)), (byte) => byte.toString(16).padStart(2, '0')).join('');
66
+ if (hex !== zero)
67
+ return hex;
68
+ }
69
+ }
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.
74
+ */
75
+ export function callerSender(identity, conversationId, nodeVersion) {
76
+ const { app, agent } = identity;
77
+ const members = [];
78
+ if (agent !== undefined)
79
+ members.push(`gen_ai.agent.name=${encodeURIComponent(agent.name)}`, `gen_ai.agent.version=${encodeURIComponent(agent.version)}`);
80
+ if (conversationId !== undefined)
81
+ members.push(`gen_ai.conversation.id=${encodeURIComponent(conversationId)}`);
82
+ return {
83
+ userAgent: `${app.name}/${app.version} ${sdkSender(nodeVersion).userAgent}`,
84
+ baggage: members.length > 0 ? members.join(',') : undefined,
85
+ values: [app.name, app.version, ...(agent === undefined ? [] : [agent.name, agent.version]), ...(conversationId === undefined ? [] : [conversationId])],
86
+ };
87
+ }
88
+ /**
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.
91
+ */
92
+ export function sdkSender(nodeVersion) {
93
+ return { userAgent: `flipstream-sdk/${version} node/${nodeVersion}`, baggage: undefined, values: [] };
94
+ }
95
+ /**
96
+ * The shortest token looked for inside a value. A real access token, a JWT, runs to hundreds of
97
+ * characters; one shorter than this is a test's or a local server's.
98
+ */
99
+ const TOKEN_SEARCHED_FROM = 16;
100
+ /**
101
+ * Whether a caller's `value` holds the access token (#199): contains it, for a token of real
102
+ * length; equals it, for a shorter one, which as a substring turns up in ordinary values ('abc' in
103
+ * 'abcdef') and would refuse them by chance.
104
+ */
105
+ export function valueHolds(value, token) {
106
+ return token.length >= TOKEN_SEARCHED_FROM ? value.includes(token) : value === token;
107
+ }
108
+ /**
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.
113
+ */
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
+ }
122
+ //# sourceMappingURL=identify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identify.js","sourceRoot":"","sources":["../../src/core/identify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAuB3C,sGAAsG;AACtG,MAAM,aAAa,GAAG,qCAAqC,CAAA;AAC3D,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAClD,qEAAqE;AACrE,MAAM,WAAW,G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,OAAO,IAAI,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AAChF,CAAC"}
@@ -0,0 +1,100 @@
1
+ import type { ApiRequest } from './transport.js';
2
+ /** One table of name pairs per concept: each of ours, to the backend's name for it. */
3
+ declare const CONCEPTS: {
4
+ /** A connection is a dataset, an upload or a connected account alike (D539). */
5
+ readonly dataset: {
6
+ readonly dataset_id: "connection_id";
7
+ };
8
+ /**
9
+ * A customer's client is a workspace (D540): one field, a list of them (a person's, on
10
+ * pulse-auth's user), and the count on an organisation. Never OAuth's `client_id`, which the rule
11
+ * below keeps.
12
+ */
13
+ readonly workspace: {
14
+ readonly workspace_id: "client_id";
15
+ readonly workspace_ids: "client_ids";
16
+ readonly workspaces_count: "clients_count";
17
+ };
18
+ /**
19
+ * How much of a dataset's history is in the warehouse (#293): pulse-admin's `backfill` on a
20
+ * connection. The field is renamed, its values keep pulse-admin's spelling (D563).
21
+ */
22
+ readonly history: {
23
+ readonly history: "backfill";
24
+ };
25
+ };
26
+ export type Concept = keyof typeof CONCEPTS;
27
+ type Pairs<C extends Concept> = (typeof CONCEPTS)[C];
28
+ type Ours<C extends Concept> = keyof Pairs<C>;
29
+ type Theirs<C extends Concept> = Pairs<C>[Ours<C>];
30
+ /** `T`, a request in our names, with each of ours in `C` given the backend's: as the wire carries it. */
31
+ export type ToBackend<T, C extends Concept> = {
32
+ [K in keyof T as K extends Ours<C> ? Pairs<C>[K] & string : K]: T[K];
33
+ };
34
+ /**
35
+ * `T`'s named properties, without its index signatures. Through `keyof T` alone they're lost beside
36
+ * one: `keyof { [key: string]: string; connection_id: string }` is `string | number`, and
37
+ * `string | 'connection_id'` is `string`, so the key looked for would be hidden.
38
+ */
39
+ type Named<T> = {
40
+ [K in keyof T as string extends K ? never : number extends K ? never : K]-?: T[K];
41
+ };
42
+ /**
43
+ * Every named key `T` holds, at any depth, through arrays, nested objects and an index signature's
44
+ * values. Each property's value is walked on its own, and only the keys found are joined: joined
45
+ * first, an `unknown` beside it (`QueryResponse.periodAlignment`) would absorb what it holds.
46
+ */
47
+ type KeysIn<T> = T extends readonly (infer Item)[] ? KeysIn<Item> : T extends object ? keyof Named<T> | {
48
+ [K in keyof Named<T>]: KeysIn<Named<T>[K]>;
49
+ }[keyof Named<T>] | (T extends {
50
+ readonly [key: string]: infer Value;
51
+ } ? KeysIn<Value> : never) : never;
52
+ /** The backend's names of `C` that answer type `T` holds anywhere: `never` while it holds none. */
53
+ export type BackendNamesIn<T, C extends Concept> = Extract<KeysIn<T>, Theirs<C>>;
54
+ /** The call a record goes out in or comes back from, as its spec names it. */
55
+ type Call = Pick<ApiRequest, 'endpoint'>;
56
+ /**
57
+ * OAuth's and OpenID Connect's own calls, by endpoint: sign-in's exchange, refresh, revoke,
58
+ * discovery and userinfo, and a device code's request and its token (RFC 8628, #116). Their
59
+ * `client_id` is the app's sign-in client, a different thing from a customer's client (a
60
+ * workspace), so they're never translated, whatever concepts they name. It's decided here, by the
61
+ * call, so no call can opt its way past it. The auth server's other calls, such as its users with
62
+ * the customer's `client_ids`, are translated as any call is. Sign-in's authorize URL is no call:
63
+ * `startSignIn` builds it, and nothing in sign-in or the session imports this module.
64
+ */
65
+ export declare const OAUTH_ENDPOINTS: ReadonlySet<string>;
66
+ /**
67
+ * A request's `record` with the backend's names of `concepts`, for `call`; unchanged, as a copy,
68
+ * for OAuth's own. Its fields are the SDK's own, picked from what the endpoint declares, so
69
+ * one that holds both names of a pair is the SDK's mistake: a TypeError.
70
+ */
71
+ export declare function toBackend(call: Call, concepts: readonly Concept[], record: object): Record<string, unknown>;
72
+ /**
73
+ * An answer's `record` with our names of `concepts`, for `call`; unchanged, as a copy, for OAuth's
74
+ * own. Null when it holds both names of a pair: the backend's answer is then outside the
75
+ * contract, and the endpoint reads it as `invalid`.
76
+ */
77
+ export declare function fromBackend(call: Call, concepts: readonly Concept[], record: object): Record<string, unknown> | null;
78
+ /**
79
+ * A person's role in an organisation, in our names. Staff's roles are never one (D544). Written
80
+ * out, so the public type names nothing the package doesn't export (#99).
81
+ */
82
+ export type Role = 'owner' | 'admin' | 'editor' | 'viewer';
83
+ /** Our roles, highest first: a person holding several is read by the highest (D544). */
84
+ export declare const RANKED: readonly ["owner", "admin", "editor", "viewer"];
85
+ /** How one of pulse-auth's role names reads: one of ours, staff's, or no role of ours. */
86
+ export type RoleRead = {
87
+ readonly kind: 'role';
88
+ readonly role: Role;
89
+ } | {
90
+ readonly kind: 'staff';
91
+ } | {
92
+ readonly kind: 'none';
93
+ };
94
+ /**
95
+ * pulse-auth's role `name`, in our names. Any other name is no role of ours, never an error
96
+ * (#265): pulse-auth's `user` until Douwe says what it means (D544), its `client` while there's no
97
+ * guest role (D559), and one the SDK has never seen.
98
+ */
99
+ export declare function roleFromBackend(name: string): RoleRead;
100
+ export {};
@@ -0,0 +1,114 @@
1
+ /*
2
+ * The one place the SDK's names meet the backend's (D540). Callers read ours, the names in the
3
+ * console (D539: a connection is a dataset), while the backend keeps its own, and no SDK change
4
+ * asks it to rename anything. So a call's request goes out with the backend's names, and its
5
+ * answer comes back with ours, through the two functions below, and nowhere else.
6
+ */
7
+ /** One table of name pairs per concept: each of ours, to the backend's name for it. */
8
+ const CONCEPTS = {
9
+ /** A connection is a dataset, an upload or a connected account alike (D539). */
10
+ dataset: { dataset_id: 'connection_id' },
11
+ /**
12
+ * A customer's client is a workspace (D540): one field, a list of them (a person's, on
13
+ * pulse-auth's user), and the count on an organisation. Never OAuth's `client_id`, which the rule
14
+ * below keeps.
15
+ */
16
+ workspace: { workspace_id: 'client_id', workspace_ids: 'client_ids', workspaces_count: 'clients_count' },
17
+ /**
18
+ * How much of a dataset's history is in the warehouse (#293): pulse-admin's `backfill` on a
19
+ * connection. The field is renamed, its values keep pulse-admin's spelling (D563).
20
+ */
21
+ history: { history: 'backfill' },
22
+ };
23
+ /**
24
+ * OAuth's and OpenID Connect's own calls, by endpoint: sign-in's exchange, refresh, revoke,
25
+ * discovery and userinfo, and a device code's request and its token (RFC 8628, #116). Their
26
+ * `client_id` is the app's sign-in client, a different thing from a customer's client (a
27
+ * workspace), so they're never translated, whatever concepts they name. It's decided here, by the
28
+ * call, so no call can opt its way past it. The auth server's other calls, such as its users with
29
+ * the customer's `client_ids`, are translated as any call is. Sign-in's authorize URL is no call:
30
+ * `startSignIn` builds it, and nothing in sign-in or the session imports this module.
31
+ */
32
+ export const OAUTH_ENDPOINTS = new Set([
33
+ 'auth.discover',
34
+ 'auth.openid_configuration',
35
+ 'auth.token',
36
+ 'auth.refresh',
37
+ 'auth.revoke',
38
+ 'auth.userinfo',
39
+ 'auth.device',
40
+ 'auth.device_token',
41
+ ]);
42
+ const translated = (call) => !OAUTH_ENDPOINTS.has(call.endpoint);
43
+ /** Each pair of `concepts`, from one side's name to the other's. */
44
+ function mapping(concepts, direction) {
45
+ const pairs = concepts.flatMap((concept) => Object.entries(CONCEPTS[concept]));
46
+ return new Map(direction === 'out' ? pairs : pairs.map(([ours, theirs]) => [theirs, ours]));
47
+ }
48
+ /**
49
+ * `record` with each key in `names` renamed, as a copy, in its order; or null when it holds both
50
+ * names of one pair, which would leave one of two values standing for both. Only the record's own
51
+ * keys: what a value holds is data (a query's filters, an answer's rows), so an endpoint passes
52
+ * each record that names a concept itself. A copy made with `Object.fromEntries`, so a key named
53
+ * `__proto__` stays an own key and changes no prototype.
54
+ */
55
+ function renamed(record, names) {
56
+ const entries = Object.entries(record);
57
+ const twice = entries.some(([key]) => {
58
+ const name = names.get(key);
59
+ return name !== undefined && Object.hasOwn(record, name);
60
+ });
61
+ return twice ? null : Object.fromEntries(entries.map(([key, value]) => [names.get(key) ?? key, value]));
62
+ }
63
+ /**
64
+ * A request's `record` with the backend's names of `concepts`, for `call`; unchanged, as a copy,
65
+ * for OAuth's own. Its fields are the SDK's own, picked from what the endpoint declares, so
66
+ * one that holds both names of a pair is the SDK's mistake: a TypeError.
67
+ */
68
+ export function toBackend(call, concepts, record) {
69
+ if (!translated(call))
70
+ return { ...record };
71
+ const out = renamed(record, mapping(concepts, 'out'));
72
+ if (out === null)
73
+ throw new TypeError(`${call.endpoint}: a request holds both names of one field`);
74
+ return out;
75
+ }
76
+ /**
77
+ * An answer's `record` with our names of `concepts`, for `call`; unchanged, as a copy, for OAuth's
78
+ * own. Null when it holds both names of a pair: the backend's answer is then outside the
79
+ * contract, and the endpoint reads it as `invalid`.
80
+ */
81
+ export function fromBackend(call, concepts, record) {
82
+ return translated(call) ? renamed(record, mapping(concepts, 'in')) : { ...record };
83
+ }
84
+ /**
85
+ * Each of our roles, by pulse-auth's name for it. There's no guest role yet (D559): a person
86
+ * limited to some workspaces is a viewer, and their `workspace_ids` say which.
87
+ */
88
+ const ROLES = { owner: 'owner', admin: 'admin', editor: 'editor', viewer: 'viewer' };
89
+ /** Our roles, highest first: a person holding several is read by the highest (D544). */
90
+ export const RANKED = ['owner', 'admin', 'editor', 'viewer'];
91
+ // Fails to compile when Role gains a role RANKED doesn't rank.
92
+ const everyRole = true;
93
+ void everyRole; // read once, so unused-locals checks keep it
94
+ /**
95
+ * Flipstream staff's roles, which no public type holds (D544): the roles that reach across
96
+ * organisations, pulse-auth's GODMODE_ONLY_ROLES (pulse-auth 0ae57c8, custom/domain/user/roles.py).
97
+ * Staff read as no role whatever else they hold, but only by these names: a staff role this version
98
+ * doesn't know reads as none of ours, like any other unknown role (#265), so this list must follow
99
+ * pulse-auth's.
100
+ */
101
+ const STAFF = new Set(['godmode', 'swapper']);
102
+ const OURS = new Map(RANKED.map((role) => [ROLES[role], role]));
103
+ /**
104
+ * pulse-auth's role `name`, in our names. Any other name is no role of ours, never an error
105
+ * (#265): pulse-auth's `user` until Douwe says what it means (D544), its `client` while there's no
106
+ * guest role (D559), and one the SDK has never seen.
107
+ */
108
+ export function roleFromBackend(name) {
109
+ const role = OURS.get(name);
110
+ if (role !== undefined)
111
+ return { kind: 'role', role };
112
+ return STAFF.has(name) ? { kind: 'staff' } : { kind: 'none' };
113
+ }
114
+ //# sourceMappingURL=names.js.map
@@ -0,0 +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;IACH,SAAS,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE;IACxG;;;OAGG;IACH,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;CAC6C,CAAA;AAmC/E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IAC1D,eAAe;IACf,2BAA2B;IAC3B,YAAY;IACZ,cAAc;IACd,aAAa;IACb,eAAe;IACf,aAAa;IACb,mBAAmB;CACpB,CAAC,CAAA;AAEF,MAAM,UAAU,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAE/E,oEAAoE;AACpE,SAAS,OAAO,CAAC,QAA4B,EAAE,SAAuB;IACpE,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAsB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAClG,OAAO,IAAI,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;AAC7F,CAAC;AAED;;;;;;GAMG;AACH,SAAS,OAAO,CAAC,MAAc,EAAE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AAM,EAAE,CAAA;AACpF,CAAC;AAQD;;;GAGG;AACH,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAA0C,CAAA;AAE5H,wFAAwF;AACxF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAoC,CAAA;AAC/F,+DAA+D;AAC/D,MAAM,SAAS,GAA4E,IAAI,CAAA;AAC/F,KAAK,SAAS,CAAA,CAAC,6CAA6C;AAE5D;;;;;;GAMG;AACH,MAAM,KAAK,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;AAElE,MAAM,IAAI,GAA8B,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;AAK1F;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;IACrD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAC/D,CAAC"}
@@ -13,5 +13,5 @@ export declare function noAnswer(sent: NoAnswer): ApiError;
13
13
  * not JSON, or fails its schema, is `invalid`: reported, never shown as empty. Zod's issues name
14
14
  * paths and expected types, never the body's values.
15
15
  */
16
- export declare function readJson<T>(sent: TransportResult, schema: z.ZodType<T>, signal: AbortSignal, service: ServiceName): Promise<ApiResult<T>>;
16
+ export declare function readJson<T>(sent: TransportResult, schema: z.ZodType<T>, signal: AbortSignal, service: ServiceName, keepsNoText?: boolean): Promise<ApiResult<T>>;
17
17
  export {};