@flipstream/sdk 0.8.0 → 0.9.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 (48) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +161 -54
  3. package/dist/auth/discovery.js +1 -1
  4. package/dist/auth/discovery.js.map +1 -1
  5. package/dist/auth/signIn.js +7 -2
  6. package/dist/auth/signIn.js.map +1 -1
  7. package/dist/core/fetch.d.ts +5 -0
  8. package/dist/core/fetch.js +3 -0
  9. package/dist/core/fetch.js.map +1 -1
  10. package/dist/core/identify.d.ts +63 -0
  11. package/dist/core/identify.js +122 -0
  12. package/dist/core/identify.js.map +1 -0
  13. package/dist/core/names.d.ts +61 -0
  14. package/dist/core/names.js +73 -0
  15. package/dist/core/names.js.map +1 -0
  16. package/dist/core/read.js +8 -2
  17. package/dist/core/read.js.map +1 -1
  18. package/dist/core/result.d.ts +26 -3
  19. package/dist/core/result.js +22 -3
  20. package/dist/core/result.js.map +1 -1
  21. package/dist/core/transport.d.ts +6 -2
  22. package/dist/flipstream.d.ts +47 -3
  23. package/dist/flipstream.js +46 -5
  24. package/dist/flipstream.js.map +1 -1
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/node/clientSecret.js +1 -1
  29. package/dist/node/clientSecret.js.map +1 -1
  30. package/dist/node/index.d.ts +1 -0
  31. package/dist/node/index.js +1 -0
  32. package/dist/node/index.js.map +1 -1
  33. package/dist/node/keychainChild.js +10 -6
  34. package/dist/node/keychainChild.js.map +1 -1
  35. package/dist/node/keychainStore.d.ts +6 -3
  36. package/dist/node/keychainStore.js +6 -3
  37. package/dist/node/keychainStore.js.map +1 -1
  38. package/dist/node/session.d.ts +79 -29
  39. package/dist/node/session.js +52 -38
  40. package/dist/node/session.js.map +1 -1
  41. package/dist/node/store.d.ts +11 -1
  42. package/dist/node/store.js +14 -1
  43. package/dist/node/store.js.map +1 -1
  44. package/dist/query/query.d.ts +15 -10
  45. package/dist/query/query.js +21 -11
  46. package/dist/query/query.js.map +1 -1
  47. package/dist/version.gen.js +1 -1
  48. package/package.json +1 -1
@@ -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,GAAG,kDAAkD,CAAA;AACtE,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AACpC,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAErC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA8C,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AAE5H;;;GAGG;AACH,SAAS,OAAO,CAAC,MAAc,EAAE,IAAY;IAC3C,OAAO,IAAI,SAAS,CAAC,qBAAqB,MAAM,YAAY,IAAI,+BAA+B,CAAC,CAAA;AAClG,CAAC;AAED,MAAM,YAAY,GAAG,8EAA8E,CAAA;AACnG,MAAM,iBAAiB,GAAG,yDAAyD,CAAA;AAEnF,SAAS,OAAO,CAAC,KAAc,EAAE,MAAc;IAC7C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,OAAO,CAAC,MAAM,EAAE,2BAA2B,YAAY,EAAE,CAAC,CAAA;IACtF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,KAAK,CAAA;IAC/C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,O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AC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAA;AACtF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW;QAAE,OAAO,SAAS,CAAA;IACrF,8DAA8D;IAC9D,MAAM,QAAQ,GAAY,OAAO,CAAC,QAAQ,CAAA;IAC1C,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC9D,OAAO,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,61 @@
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
+ export type Concept = keyof typeof CONCEPTS;
10
+ type Pairs<C extends Concept> = (typeof CONCEPTS)[C];
11
+ type Ours<C extends Concept> = keyof Pairs<C>;
12
+ type Theirs<C extends Concept> = Pairs<C>[Ours<C>];
13
+ /** `T`, a request in our names, with each of ours in `C` given the backend's: as the wire carries it. */
14
+ export type ToBackend<T, C extends Concept> = {
15
+ [K in keyof T as K extends Ours<C> ? Pairs<C>[K] & string : K]: T[K];
16
+ };
17
+ /**
18
+ * `T`'s named properties, without its index signatures. Through `keyof T` alone they're lost beside
19
+ * one: `keyof { [key: string]: string; connection_id: string }` is `string | number`, and
20
+ * `string | 'connection_id'` is `string`, so the key looked for would be hidden.
21
+ */
22
+ type Named<T> = {
23
+ [K in keyof T as string extends K ? never : number extends K ? never : K]-?: T[K];
24
+ };
25
+ /**
26
+ * Every named key `T` holds, at any depth, through arrays, nested objects and an index signature's
27
+ * values. Each property's value is walked on its own, and only the keys found are joined: joined
28
+ * first, an `unknown` beside it (`QueryResponse.periodAlignment`) would absorb what it holds.
29
+ */
30
+ type KeysIn<T> = T extends readonly (infer Item)[] ? KeysIn<Item> : T extends object ? keyof Named<T> | {
31
+ [K in keyof Named<T>]: KeysIn<Named<T>[K]>;
32
+ }[keyof Named<T>] | (T extends {
33
+ readonly [key: string]: infer Value;
34
+ } ? KeysIn<Value> : never) : never;
35
+ /** The backend's names of `C` that answer type `T` holds anywhere: `never` while it holds none. */
36
+ export type BackendNamesIn<T, C extends Concept> = Extract<KeysIn<T>, Theirs<C>>;
37
+ /** The call a record goes out in or comes back from, as its spec names it. */
38
+ type Call = Pick<ApiRequest, 'endpoint'>;
39
+ /**
40
+ * OAuth's and OpenID Connect's own calls, by endpoint: sign-in's exchange, refresh, revoke,
41
+ * discovery and userinfo, and a device code's request and its token (RFC 8628, #116). Their
42
+ * `client_id` is the app's sign-in client, a different thing from a customer's client (a
43
+ * workspace), so they're never translated, whatever concepts they name. It's decided here, by the
44
+ * call, so no call can opt its way past it. The auth server's other calls, such as its users with
45
+ * the customer's `client_ids`, are translated as any call is. Sign-in's authorize URL is no call:
46
+ * `startSignIn` builds it, and nothing in sign-in or the session imports this module.
47
+ */
48
+ export declare const OAUTH_ENDPOINTS: ReadonlySet<string>;
49
+ /**
50
+ * A request's `record` with the backend's names of `concepts`, for `call`; unchanged, as a copy,
51
+ * for OAuth's own. Its fields are the SDK's own, picked from what the endpoint declares, so
52
+ * one that holds both names of a pair is the SDK's mistake: a TypeError.
53
+ */
54
+ export declare function toBackend(call: Call, concepts: readonly Concept[], record: object): Record<string, unknown>;
55
+ /**
56
+ * An answer's `record` with our names of `concepts`, for `call`; unchanged, as a copy, for OAuth's
57
+ * own. Null when it holds both names of a pair: the backend's answer is then outside the
58
+ * contract, and the endpoint reads it as `invalid`.
59
+ */
60
+ export declare function fromBackend(call: Call, concepts: readonly Concept[], record: object): Record<string, unknown> | null;
61
+ export {};
@@ -0,0 +1,73 @@
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
+ /**
13
+ * OAuth's and OpenID Connect's own calls, by endpoint: sign-in's exchange, refresh, revoke,
14
+ * discovery and userinfo, and a device code's request and its token (RFC 8628, #116). Their
15
+ * `client_id` is the app's sign-in client, a different thing from a customer's client (a
16
+ * workspace), so they're never translated, whatever concepts they name. It's decided here, by the
17
+ * call, so no call can opt its way past it. The auth server's other calls, such as its users with
18
+ * the customer's `client_ids`, are translated as any call is. Sign-in's authorize URL is no call:
19
+ * `startSignIn` builds it, and nothing in sign-in or the session imports this module.
20
+ */
21
+ export const OAUTH_ENDPOINTS = new Set([
22
+ 'auth.discover',
23
+ 'auth.openid_configuration',
24
+ 'auth.token',
25
+ 'auth.refresh',
26
+ 'auth.revoke',
27
+ 'auth.userinfo',
28
+ 'auth.device',
29
+ 'auth.device_token',
30
+ ]);
31
+ const translated = (call) => !OAUTH_ENDPOINTS.has(call.endpoint);
32
+ /** Each pair of `concepts`, from one side's name to the other's. */
33
+ function mapping(concepts, direction) {
34
+ const pairs = concepts.flatMap((concept) => Object.entries(CONCEPTS[concept]));
35
+ return new Map(direction === 'out' ? pairs : pairs.map(([ours, theirs]) => [theirs, ours]));
36
+ }
37
+ /**
38
+ * `record` with each key in `names` renamed, as a copy, in its order; or null when it holds both
39
+ * names of one pair, which would leave one of two values standing for both. Only the record's own
40
+ * keys: what a value holds is data (a query's filters, an answer's rows), so an endpoint passes
41
+ * each record that names a concept itself. A copy made with `Object.fromEntries`, so a key named
42
+ * `__proto__` stays an own key and changes no prototype.
43
+ */
44
+ function renamed(record, names) {
45
+ const entries = Object.entries(record);
46
+ const twice = entries.some(([key]) => {
47
+ const name = names.get(key);
48
+ return name !== undefined && Object.hasOwn(record, name);
49
+ });
50
+ return twice ? null : Object.fromEntries(entries.map(([key, value]) => [names.get(key) ?? key, value]));
51
+ }
52
+ /**
53
+ * A request's `record` with the backend's names of `concepts`, for `call`; unchanged, as a copy,
54
+ * for OAuth's own. Its fields are the SDK's own, picked from what the endpoint declares, so
55
+ * one that holds both names of a pair is the SDK's mistake: a TypeError.
56
+ */
57
+ export function toBackend(call, concepts, record) {
58
+ if (!translated(call))
59
+ return { ...record };
60
+ const out = renamed(record, mapping(concepts, 'out'));
61
+ if (out === null)
62
+ throw new TypeError(`${call.endpoint}: a request holds both names of one field`);
63
+ return out;
64
+ }
65
+ /**
66
+ * An answer's `record` with our names of `concepts`, for `call`; unchanged, as a copy, for OAuth's
67
+ * own. Null when it holds both names of a pair: the backend's answer is then outside the
68
+ * contract, and the endpoint reads it as `invalid`.
69
+ */
70
+ export function fromBackend(call, concepts, record) {
71
+ return translated(call) ? renamed(record, mapping(concepts, 'in')) : { ...record };
72
+ }
73
+ //# 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;CACqC,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,CA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MAAM,UAAU,SAAS,CAAC,IAAU,EAAE,QAA4B,EAAE,MAAc;IAChF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAAA;IAC3C,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;IACrD,IAAI,GAAG,KAAK,IAAI;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,CAAC,QAAQ,2CAA2C,CAAC,CAAA;IAClG,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,QAA4B,EAAE,MAAc;IAClF,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAA;AACpF,CAAC"}
package/dist/core/read.js CHANGED
@@ -1,11 +1,17 @@
1
1
  import { z } from 'zod';
2
2
  import { parseJson, said } from './body.js';
3
3
  import { classifyStatus } from './result.js';
4
+ // The reasons a transport may give, tied to its type: a reason TransportResult gains fails to
5
+ // compile here until it's mapped. Checked as an own key, because an app's own transport may be
6
+ // plain JavaScript and give any (#199).
7
+ const FROM_TRANSPORT = { destination: true, identification: true };
4
8
  /** Why a transport has no answer to read. */
5
9
  export function noAnswer(sent) {
6
10
  switch (sent.kind) {
7
- case 'refused':
8
- return { kind: 'refused' };
11
+ case 'refused': {
12
+ const { reason } = sent;
13
+ return Object.hasOwn(FROM_TRANSPORT, reason) ? { kind: 'refused', reason } : { kind: 'refused' };
14
+ }
9
15
  case 'unavailable':
10
16
  return { kind: 'unavailable' };
11
17
  case 'cancelled':
@@ -1 +1 @@
1
- {"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AAAA,OA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CAAC,CAAA"}
@@ -68,12 +68,13 @@ export type ApiError = Answered
68
68
  readonly kind: 'timeout';
69
69
  }
70
70
  /**
71
- * Nothing was sent, by rule: the destination isn't one of the configured hosts over https, a
72
- * path value can't stay one segment ('', '.', '..'), or the request has keys the call doesn't
73
- * send, named in `fields`. No token was asked for, and none went anywhere.
71
+ * Nothing was sent, by rule, and `reason` says which (#199). Every refusal the SDK returns has
72
+ * one; only an error an app builds itself may leave it out. No token was asked for, and none went
73
+ * anywhere, but for `identification`: the token was asked for, to check, and went nowhere.
74
74
  */
75
75
  | {
76
76
  readonly kind: 'refused';
77
+ readonly reason?: RefusedReason;
77
78
  readonly fields?: readonly [string, ...string[]];
78
79
  }
79
80
  /** The token function failed, or gave no token, so nothing was sent; `cause` is what it threw. */
@@ -87,6 +88,28 @@ export type ApiError = Answered
87
88
  * contract, so it is reported, never quietly passed.
88
89
  */
89
90
  export declare function classifyStatus(status: number): 'success' | StatusKind | 'outside-contract';
91
+ /** Why a call was refused before anything was sent (#199, D536). */
92
+ export type RefusedReason =
93
+ /**
94
+ * Not an allowed host: a configured one, or for sign-in the issuer's own, over https, or over
95
+ * http on this machine with `allowLocalhostHttp`, for the client as for sign-in.
96
+ */
97
+ 'destination'
98
+ /** A value identifying the app, its agent or the conversation holds the access token (#192). */
99
+ | 'identification'
100
+ /** A path value that can't stay one segment: '', '.' or '..'. */
101
+ | 'path'
102
+ /** A call's own `conversationId` that breaks its rule. */
103
+ | 'conversation-id'
104
+ /** The request has keys the call doesn't send, named in `fields` (D513). */
105
+ | 'fields'
106
+ /**
107
+ * Sign-in: a pending sign-in that isn't one, wasn't started by this app at this server, or whose
108
+ * token endpoint breaks its issuer's rule (an app's own server can give it one).
109
+ */
110
+ | 'pending'
111
+ /** Sign-in: a callback URL that can't be read. */
112
+ | 'callback';
90
113
  /** A failed call, thrown by `orThrow`, carrying its `ApiError`. */
91
114
  export declare class ApiFailure extends Error {
92
115
  readonly error: ApiError;
@@ -22,13 +22,32 @@ export function classifyStatus(status) {
22
22
  return 'rejected';
23
23
  return 'outside-contract';
24
24
  }
25
+ // What orThrow's message says of each reason. A message names the rule, never a value: not the
26
+ // token, a conversationId or a URL, which may be secrets in the wrong place.
27
+ const REFUSED_BECAUSE = {
28
+ destination: "its destination isn't an allowed host (https, or http on this machine with allowLocalhostHttp)",
29
+ identification: 'a value identifying the app, its agent or the conversation holds the access token',
30
+ path: "a path value can't be '', '.' or '..'",
31
+ 'conversation-id': "the call's conversationId isn't 1 to 128 of A-Z, a-z, 0-9, ., _, : and -",
32
+ pending: "the pending sign-in isn't one this app started at this server, or its token endpoint breaks its issuer's rule",
33
+ callback: "the callback URL can't be read",
34
+ };
35
+ function failureMessage(error) {
36
+ if (error.kind !== 'refused')
37
+ return `the call failed: ${error.kind}`;
38
+ if (error.fields !== undefined)
39
+ return `the call failed: refused, for fields it doesn't send: ${error.fields.join(', ')}`;
40
+ // An own key only: a reason outside the type, from plain JavaScript or another version, says
41
+ // nothing more than "refused", never "as undefined".
42
+ const { reason } = error;
43
+ const because = reason !== undefined && reason !== 'fields' && Object.hasOwn(REFUSED_BECAUSE, reason) ? REFUSED_BECAUSE[reason] : undefined;
44
+ return because === undefined ? 'the call failed: refused' : `the call failed: refused, as ${because}`;
45
+ }
25
46
  /** A failed call, thrown by `orThrow`, carrying its `ApiError`. */
26
47
  export class ApiFailure extends Error {
27
48
  error;
28
49
  constructor(error) {
29
- super(error.kind === 'refused' && error.fields !== undefined
30
- ? `the call failed: refused, for fields it doesn't send: ${error.fields.join(', ')}`
31
- : `the call failed: ${error.kind}`);
50
+ super(failureMessage(error));
32
51
  this.name = 'ApiFailure';
33
52
  this.error = error;
34
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAgFA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;QAAE,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E,MAAM,EAAE,GAAG,KAAK,CAAA;IACxB,MAAM,OAAO,GAAG,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC3I,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,gCAAgC,OAAO,EAAE,CAAA;AACvG,CAAC;AAED,mEAAmE;AACnE,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,KAAK,CAAU;IAExB,YAAY,KAAe;QACzB,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,UAAU,OAAO,CAAI,MAAoB;IAC7C,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAClD,OAAO,MAAM,CAAC,IAAI,CAAA;AACpB,CAAC"}
@@ -30,10 +30,14 @@ export type Transport = (call: ApiRequest) => Promise<TransportResult>;
30
30
  */
31
31
  export type CancelReason = 'principal-changed' | 'scope-changed' | 'aborted';
32
32
  export type TransportResult =
33
- /** A destination outside the allowlist: no token went anywhere. */
33
+ /**
34
+ * Nothing was sent. `destination`: outside the allowlist, so no token went anywhere.
35
+ * `identification`: a value that identifies the app, its agent or the conversation holds the
36
+ * access token, which goes in the authorization header only (#192).
37
+ */
34
38
  {
35
39
  readonly kind: 'refused';
36
- readonly reason: 'destination';
40
+ readonly reason: 'destination' | 'identification';
37
41
  } | {
38
42
  readonly kind: 'response';
39
43
  readonly response: Response;
@@ -8,7 +8,37 @@ import type { Catalog, CatalogSource, QueryResponse } from './spec/query-planner
8
8
  export type Hosts = Readonly<Partial<Record<ServiceName, string>>>;
9
9
  /** Asked before every attempt, and once more after a 401 with the token the host refused. */
10
10
  export type TokenFunction = (ask: TokenAsk) => string | Promise<string>;
11
- export type FlipstreamOptions =
11
+ /**
12
+ * Who a client's requests say sent them (#192, D527), whichever way the client is made. In Node,
13
+ * each signed-in request to an API host carries them; the signed-out `health` and the auth server
14
+ * never get them. In a browser, none go yet: the hosts' CORS doesn't allow the headers until
15
+ * query-planner#48.
16
+ */
17
+ export interface Identification {
18
+ /**
19
+ * The app making the calls, required: every signed-in request says which app sent it, as
20
+ * `User-Agent: <name>/<version> flipstream-sdk/<version> node/<version>`. Each is 1 to 64 of
21
+ * RFC 9110's token characters (letters, digits and !#$%&'*+-.^_`|~), or a TypeError at creation.
22
+ */
23
+ readonly app: {
24
+ readonly name: string;
25
+ readonly version: string;
26
+ };
27
+ /**
28
+ * The agent running the app, when one does, under the same rule: sent as `baggage`, with
29
+ * OpenTelemetry's names `gen_ai.agent.name` and `gen_ai.agent.version`.
30
+ */
31
+ readonly agent?: {
32
+ readonly name: string;
33
+ readonly version: string;
34
+ };
35
+ /**
36
+ * The conversation or run the calls belong to, as `gen_ai.conversation.id`: 1 to 128 of A-Z,
37
+ * a-z, 0-9, `.`, `_`, `:` and `-`, or a TypeError at creation. A call's own replaces it.
38
+ */
39
+ readonly conversationId?: string;
40
+ }
41
+ export type FlipstreamOptions = Identification & (
12
42
  /** The console: its own transport, which attaches the token and decides what may go. */
13
43
  {
14
44
  readonly transport: Transport;
@@ -33,12 +63,23 @@ export type FlipstreamOptions =
33
63
  /** Plain http to a loopback host, for development and tests only. Off unless set. */
34
64
  readonly allowLocalhostHttp?: boolean;
35
65
  readonly transport?: never;
36
- };
66
+ });
37
67
  export interface CallOptions {
38
68
  /** Ends the call at once: its answer is `aborted`. */
39
69
  readonly signal?: AbortSignal;
40
70
  /** The whole call's deadline, every attempt and wait included; the endpoint's own when left out. */
41
71
  readonly deadlineMs?: number;
72
+ /**
73
+ * This call's conversation, in place of the client's, under the same rule. One that breaks it
74
+ * refuses the call, with nothing sent. `health` sends none, but a broken one refuses it too.
75
+ */
76
+ readonly conversationId?: string;
77
+ /**
78
+ * The caller's own W3C trace context, carried on: the call keeps its trace-id and flags, with a
79
+ * parent-id of its own for each attempt. One that isn't a valid version-00 traceparent is
80
+ * dropped, as W3C Trace Context says, and the call starts its own trace.
81
+ */
82
+ readonly traceparent?: string;
42
83
  }
43
84
  /** What `createFlipstream` gives: each call settles into an `ApiResult`, never a thrown error (D412). */
44
85
  export interface Flipstream {
@@ -52,7 +93,10 @@ export interface Flipstream {
52
93
  /**
53
94
  * Whether the planner answers, signed out: `GET /health` with no token. It goes through neither
54
95
  * the app's transport nor the token function, since they hold the token, but straight to the
55
- * query host, under the same destination rule. A 200 with an object of strings is up.
96
+ * query host, under the same destination rule. A 200 with an object of strings is up. In Node it
97
+ * says only who the SDK is, `User-Agent: flipstream-sdk/<version> node/<version>` with a
98
+ * `traceparent`, and none of the client's `app`, `agent` or `conversationId` (D535): with no
99
+ * token, nothing could check that they don't hold it.
56
100
  */
57
101
  health(options?: CallOptions): Promise<ApiResult<Health>>;
58
102
  }
@@ -1,37 +1,78 @@
1
1
  import { call } from './core/call.js';
2
2
  import { fetchTransport, tokenlessTransport } from './core/fetch.js';
3
+ import { callerSender, identityOf, isConversationId, nodeVersion, sdkSender, traceFor, traceparent, valueHolds } from './core/identify.js';
3
4
  import { catalogGet, catalogList, consoleWarn } from './query/catalog.js';
4
5
  import { healthCheck } from './query/health.js';
5
6
  import { queryRun, unsentFields } from './query/query.js';
6
7
  const DEFAULT_HOSTS = { query: 'https://query.flipstream.io' };
8
+ const refused = (reason) => ({ ok: false, error: { kind: 'refused', reason } });
7
9
  /** The SDK, for one caller (D421): the console with its transport, or anyone with a token function. */
8
10
  export function createFlipstream(options) {
11
+ // First, so a client that can't say who it is throws before anything else is set up.
12
+ const identity = identityOf(options);
13
+ const node = nodeVersion();
14
+ // The values the caller gave, keyed by the Request that carries them, so the token function's
15
+ // transport can refuse one whose values hold the access token: only the transport has the token.
16
+ const carried = new WeakMap();
17
+ const holdsToken = (request, token) => (carried.get(request) ?? []).some((value) => valueHolds(value, token));
9
18
  const hosts = { ...DEFAULT_HOSTS, ...options.hosts };
10
19
  const transport = options.transport !== undefined
11
20
  ? options.transport
12
- : fetchTransport({ token: options.token, fetch: options.fetch, hosts, allowLocalhostHttp: options.allowLocalhostHttp });
21
+ : fetchTransport({ token: options.token, fetch: options.fetch, hosts, allowLocalhostHttp: options.allowLocalhostHttp, holdsToken });
13
22
  const base = (hosts.query ?? DEFAULT_HOSTS.query).replace(/\/+$/, '');
14
23
  const warn = options.onWarning ?? consoleWarn;
15
24
  // For health alone (#111), whichever way the SDK was made: only the query host, so the call that
16
25
  // works signed out can go nowhere else.
17
26
  const signedOut = tokenlessTransport({ fetch: options.fetch, hosts: { query: base }, allowLocalhostHttp: options.allowLocalhostHttp });
18
- const send = (spec, { signal, deadlineMs } = {}, via = transport) => call(via, deadlineMs === undefined ? spec : { ...spec, deadlineMs }, signal);
27
+ /**
28
+ * `spec` with what its requests say about who sent them, in Node: one trace for the call, and a
29
+ * parent-id for each request, retries and a 401's resend included.
30
+ */
31
+ const identified = (spec, sender, trace) => ({
32
+ ...spec,
33
+ makeRequest: () => {
34
+ const built = spec.makeRequest();
35
+ const headers = new Headers(built.headers);
36
+ headers.set('user-agent', sender.userAgent);
37
+ headers.set('traceparent', traceparent(trace));
38
+ if (sender.baggage !== undefined)
39
+ headers.set('baggage', sender.baggage);
40
+ const request = new Request(built, { headers });
41
+ carried.set(request, sender.values);
42
+ return request;
43
+ },
44
+ });
45
+ /** One call. `signedIn` is false for health alone, which says only who the SDK is (D535). */
46
+ const send = (spec, callOptions = {}, signedIn = true) => {
47
+ // One flag picks both the transport and what the request says: only the signed-in transport
48
+ // checks the caller's values against the token, so a signed-out call can never carry them.
49
+ const via = signedIn ? transport : signedOut;
50
+ const { signal, deadlineMs } = callOptions;
51
+ // Refused before anything is sent, like a field the call doesn't send: the token function isn't asked.
52
+ if (callOptions.conversationId !== undefined && !isConversationId(callOptions.conversationId))
53
+ return Promise.resolve(refused('conversation-id'));
54
+ const timed = deadlineMs === undefined ? spec : { ...spec, deadlineMs };
55
+ if (node === undefined)
56
+ return call(via, timed, signal);
57
+ const sender = signedIn ? callerSender(identity, callOptions.conversationId ?? identity.conversationId, node) : sdkSender(node);
58
+ return call(via, identified(timed, sender, traceFor(callOptions.traceparent)), signal);
59
+ };
19
60
  return {
20
61
  catalog: {
21
62
  list: (callOptions) => send(catalogList(base, warn), callOptions),
22
63
  get(request, callOptions) {
23
64
  const spec = catalogGet(base, request.source, warn);
24
65
  // Refused before anything is sent: the token function isn't asked, and nothing is spent.
25
- return spec === null ? Promise.resolve({ ok: false, error: { kind: 'refused' } }) : send(spec, callOptions);
66
+ return spec === null ? Promise.resolve(refused('path')) : send(spec, callOptions);
26
67
  },
27
68
  },
28
69
  // Async, so a request that isn't an object rejects, as D436's do, rather than throwing here.
29
70
  async query(request, callOptions) {
30
71
  const fields = unsentFields(request);
31
72
  // Refused before anything is sent, like catalog.get's: the token function isn't asked.
32
- return fields === null ? send(queryRun(base, request), callOptions) : { ok: false, error: { kind: 'refused', fields } };
73
+ return fields === null ? send(queryRun(base, request), callOptions) : { ok: false, error: { kind: 'refused', reason: 'fields', fields } };
33
74
  },
34
- health: (callOptions) => send(healthCheck(base), callOptions, signedOut),
75
+ health: (callOptions) => send(healthCheck(base), callOptions, false),
35
76
  };
36
77
  }
37
78
  //# sourceMappingURL=flipstream.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"flipstream.js","sourceRoot":"","sources":["../src/flipstream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAiB,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAiB,MAAM,iBAAiB,CAAA;AAGnF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAA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AI,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC;YACjE,GAAG,CAAC,OAAO,EAAE,WAAW;gBACtB,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;gBACnD,yFAAyF;gBACzF,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;YACnF,CAAC;SACF;QACD,6FAA6F;QAC7F,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW;YAC9B,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;YACpC,uFAAuF;YACvF,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAA;QAC3I,CAAC;QACD,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC;KACrE,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export { createFlipstream } from './flipstream.js';
2
- export type { CallOptions, Flipstream, FlipstreamOptions, Hosts, TokenFunction } from './flipstream.js';
2
+ export type { CallOptions, Flipstream, FlipstreamOptions, Hosts, Identification, TokenFunction } from './flipstream.js';
3
3
  export { refusedQueryFields } from './query/query.js';
4
4
  export type { QueryRequest } from './query/query.js';
5
5
  export type { Health } from './query/health.js';
6
6
  export { isPlannerCode } from './query/errors.js';
7
7
  export { ApiFailure, orThrow } from './core/result.js';
8
- export type { Answered, ApiError, ApiResult, ErrorCode, Said, StatusKind } from './core/result.js';
8
+ export type { Answered, ApiError, ApiResult, ErrorCode, RefusedReason, Said, StatusKind } from './core/result.js';
9
9
  export type { ApiRequest, CancelReason, ServiceName, Transport, TransportResult } from './core/transport.js';
10
10
  export type { TokenAsk } from './core/fetch.js';
11
11
  export type { Catalog, CatalogSource, CurrencyFormat, CustomDimensions, DateFormat, Dimension, ErrorBody, Format, Metric, NumberFormat, PercentageFormat, PlannerErrorCode, QueryResponse, Row, SortSpec, Source, StringFormat, UnknownFormat, } from './spec/query-planner/types.gen.js';