@flipstream/sdk 0.12.0 → 0.14.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 (87) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +128 -30
  3. package/dist/api/backend.d.ts +18 -3
  4. package/dist/api/backend.js +33 -6
  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.js +30 -50
  9. package/dist/api/datasets.js.map +1 -1
  10. package/dist/api/handoff.d.ts +1 -1
  11. package/dist/api/handoff.js +7 -0
  12. package/dist/api/handoff.js.map +1 -1
  13. package/dist/api/log.d.ts +4 -4
  14. package/dist/api/log.js +23 -42
  15. package/dist/api/log.js.map +1 -1
  16. package/dist/api/me.d.ts +5 -3
  17. package/dist/api/me.js +5 -4
  18. package/dist/api/me.js.map +1 -1
  19. package/dist/api/members.d.ts +40 -17
  20. package/dist/api/members.js +66 -29
  21. package/dist/api/members.js.map +1 -1
  22. package/dist/api/ownRecord.d.ts +46 -0
  23. package/dist/api/ownRecord.js +57 -0
  24. package/dist/api/ownRecord.js.map +1 -0
  25. package/dist/api/refusal.d.ts +14 -0
  26. package/dist/api/refusal.js +23 -0
  27. package/dist/api/refusal.js.map +1 -0
  28. package/dist/api/wallet.d.ts +2 -1
  29. package/dist/api/wallet.js +18 -21
  30. package/dist/api/wallet.js.map +1 -1
  31. package/dist/api/workspaces.d.ts +14 -9
  32. package/dist/api/workspaces.js +21 -15
  33. package/dist/api/workspaces.js.map +1 -1
  34. package/dist/auth/discovery.js +3 -1
  35. package/dist/auth/discovery.js.map +1 -1
  36. package/dist/core/call.d.ts +12 -2
  37. package/dist/core/call.js +5 -2
  38. package/dist/core/call.js.map +1 -1
  39. package/dist/core/identify.d.ts +65 -14
  40. package/dist/core/identify.js +69 -27
  41. package/dist/core/identify.js.map +1 -1
  42. package/dist/core/inPlaceOf.d.ts +6 -0
  43. package/dist/core/inPlaceOf.js +17 -0
  44. package/dist/core/inPlaceOf.js.map +1 -0
  45. package/dist/core/invalid.d.ts +32 -6
  46. package/dist/core/invalid.js +36 -17
  47. package/dist/core/invalid.js.map +1 -1
  48. package/dist/core/notFound.d.ts +2 -2
  49. package/dist/core/notFound.js.map +1 -1
  50. package/dist/core/read.d.ts +6 -3
  51. package/dist/core/read.js +5 -6
  52. package/dist/core/read.js.map +1 -1
  53. package/dist/core/result.d.ts +16 -8
  54. package/dist/core/result.js +1 -0
  55. package/dist/core/result.js.map +1 -1
  56. package/dist/core/shared.d.ts +43 -0
  57. package/dist/core/shared.js +178 -0
  58. package/dist/core/shared.js.map +1 -0
  59. package/dist/core/signal.d.ts +12 -0
  60. package/dist/core/signal.js +25 -0
  61. package/dist/core/signal.js.map +1 -0
  62. package/dist/flipstream.d.ts +160 -22
  63. package/dist/flipstream.js +207 -81
  64. package/dist/flipstream.js.map +1 -1
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.js +3 -2
  67. package/dist/index.js.map +1 -1
  68. package/dist/node/clientSecret.js +2 -1
  69. package/dist/node/clientSecret.js.map +1 -1
  70. package/dist/node/keychainChild.js +60 -25
  71. package/dist/node/keychainChild.js.map +1 -1
  72. package/dist/node/keychainError.d.ts +4 -1
  73. package/dist/node/keychainError.js.map +1 -1
  74. package/dist/node/keychainStore.js +42 -8
  75. package/dist/node/keychainStore.js.map +1 -1
  76. package/dist/node/loopback.d.ts +5 -2
  77. package/dist/node/loopback.js +28 -3
  78. package/dist/node/loopback.js.map +1 -1
  79. package/dist/node/session.js +11 -5
  80. package/dist/node/session.js.map +1 -1
  81. package/dist/query/query.d.ts +52 -8
  82. package/dist/query/query.js +133 -19
  83. package/dist/query/query.js.map +1 -1
  84. package/dist/version.gen.js +1 -1
  85. package/docs/admin.md +108 -4
  86. package/docs/node-sign-in.md +11 -5
  87. package/package.json +1 -1
@@ -28,13 +28,15 @@ export type TokenFunction = (ask: TokenAsk) => string | Promise<string>;
28
28
  /**
29
29
  * Who a client's requests say sent them (#192, D527), whichever way the client is made. In Node,
30
30
  * each signed-in request to an API host carries them; the signed-out `health` and the auth server
31
- * never get them. In a browser, none go yet: the hosts' CORS doesn't allow the headers until
32
- * query-planner#48.
31
+ * never get them. In a browser (a page with a `document`), only the deployed query API's origin
32
+ * does: not a custom query host, and not pulse-admin or pulse-wallet yet (#196). Another runtime
33
+ * that isn't Node sends none.
33
34
  */
34
35
  export interface Identification {
35
36
  /**
36
37
  * The app making the calls, required: every signed-in request says which app sent it, as
37
- * `User-Agent: <name>/<version> flipstream-sdk/<version> node/<version>`. Each is 1 to 64 of
38
+ * `User-Agent: <name>/<version> flipstream-sdk/<version> node/<version>` in Node, and from a
39
+ * browser as `Flipstream-Client: <name>/<version> flipstream-sdk/<version>`. Each is 1 to 64 of
38
40
  * RFC 9110's token characters (letters, digits and !#$%&'*+-.^_`|~), or a TypeError at creation.
39
41
  */
40
42
  readonly app: {
@@ -108,6 +110,61 @@ export interface CallOptions {
108
110
  * starts its own trace.
109
111
  */
110
112
  readonly traceparent?: string;
113
+ /**
114
+ * The scope this call shares reads in: one `flipstream.scope()` made (#376). One this client
115
+ * didn't make is a TypeError naming the call, with nothing sent. A closed one shares nothing: the
116
+ * call reads its own, as outside a scope.
117
+ */
118
+ readonly scope?: Scope;
119
+ }
120
+ declare global {
121
+ interface SymbolConstructor {
122
+ /**
123
+ * Declared with the SDK's types, as Node's own types declare it, so a project with only the
124
+ * ES2022 and DOM libs reads `Scope` too (#377 round 2, O2.F1). `await using` itself still needs
125
+ * TypeScript's `ESNext.Disposable` lib, and a runtime that has the symbol.
126
+ */
127
+ readonly asyncDispose: unique symbol;
128
+ }
129
+ }
130
+ /** How a scope is made (#409, D579): `flipstream.scope(options)` and `withScope(run, options)`. */
131
+ export interface ScopeOptions {
132
+ /**
133
+ * The caller's own W3C trace context, for the scope's shared reads, as a call's `traceparent` is
134
+ * for its own requests: each shared read goes out under its trace-id and flags, with a parent-id of
135
+ * its own for each attempt. So one piece of work, such as a CLI command, is one trace.
136
+ * - **A call names the request that answered it** as its `trace_id` (#376): a shared read's whose
137
+ * failure is its answer, else its own requests', else the first shared read it asked for. So a
138
+ * call answered by shared reads alone, such as `me()`, names the scope's trace-id, even when it
139
+ * was given a `traceparent` of its own.
140
+ * - **Only where the SDK sends a trace:** Node's requests to the admin host, your organisation's
141
+ * and a workspace's own reads. The sign-in server, where your person is read, never gets one
142
+ * (#192), and from a browser the admin host gets none yet (#380), so there the option changes
143
+ * nothing.
144
+ * - **One that isn't a valid version-00 traceparent,** a value that isn't a string included, is
145
+ * dropped, as a call's is, and the shared reads keep traces of their own.
146
+ * - It never reaches a call's own requests, and a call's own `traceparent` never reaches a shared
147
+ * read.
148
+ */
149
+ readonly traceparent?: string;
150
+ }
151
+ /**
152
+ * One piece of work's shared reads (#376, D573): a route's load in the console, a command in the
153
+ * CLI. Made by `flipstream.scope()`, taken by each call as `{ scope }`, and ended by `close()`, or
154
+ * by `await using`, which calls it when the block ends.
155
+ */
156
+ export interface Scope {
157
+ /**
158
+ * Ends the scope: every shared read still on its way is ended, and its waiting calls answer
159
+ * `aborted`. Answers once each has settled. A call that takes the scope after this reads its own,
160
+ * as outside a scope. Closing it again does nothing more.
161
+ */
162
+ close(): Promise<void>;
163
+ /**
164
+ * `close()`, so `await using` closes the scope when its block ends. Only where the runtime has
165
+ * `Symbol.asyncDispose`; `close()` itself works everywhere (#377's code review, 5).
166
+ */
167
+ [Symbol.asyncDispose](): Promise<void>;
111
168
  }
112
169
  /** What `createFlipstream` gives: each call settles into an `ApiResult`, never a thrown error (D412). */
113
170
  export interface Flipstream {
@@ -117,6 +174,13 @@ export interface Flipstream {
117
174
  readonly source: string;
118
175
  }, options?: CallOptions): Promise<ApiResult<CatalogSource>>;
119
176
  };
177
+ /**
178
+ * A query's answer. Every row, and its totals, are keyed by the dimensions and metrics asked for,
179
+ * and only those: any other key makes the answer `invalid`, so it never reaches you as data. The
180
+ * error names at most five of the keys, each shaped like a field name, and counts the rest, never
181
+ * a value (#237). A query that asks for no dimension and no metric is `refused`, with `reason`
182
+ * `nothing_asked`, and nothing is sent: no answer to it could pass that check.
183
+ */
120
184
  query(request: QueryRequest, options?: CallOptions): Promise<ApiResult<QueryResponse>>;
121
185
  /**
122
186
  * Whether the planner answers, signed out: `GET /health` with no token. It goes through neither
@@ -154,7 +218,8 @@ export interface Flipstream {
154
218
  * first, for its id, and a call under one workspace reads you beside it, all under one deadline
155
219
  * (the call's, or 30 s); the first failure is the answer. A workspace of another organisation is
156
220
  * `invalid`, never dropped or shown. A call under one workspace answers `not_found` for one you
157
- * don't open, as for one nobody has: see "The workspaces you open" in docs/admin.md (#372).
221
+ * don't open, as for one nobody has, and so does one for a workspace whose own read pulse-admin
222
+ * refuses (D578): see "The workspaces you open" in docs/admin.md (#372).
158
223
  */
159
224
  readonly workspaces: {
160
225
  /**
@@ -172,7 +237,8 @@ export interface Flipstream {
172
237
  /**
173
238
  * One workspace, by its id. An id that can't stay one path segment is `refused` (`path`), with
174
239
  * nothing sent. Your organisation and you are read first, so one you don't open is `not_found`,
175
- * exactly as one nobody has, with nothing under it read.
240
+ * exactly as one nobody has, with nothing under it read. One whose own read pulse-admin refuses,
241
+ * its own 403 (`FORBIDDEN_EXCEPTION`), is `not_found` too, as one nobody has (D578).
176
242
  */
177
243
  get(request: {
178
244
  readonly workspace_id: string;
@@ -195,8 +261,8 @@ export interface Flipstream {
195
261
  /**
196
262
  * A rename is a person's, in the console (D542): it answers `needs_person`, with why and, where
197
263
  * the console can be named, the workspace's settings page. It never writes, and the name isn't
198
- * sent: the person types it there. A workspace that isn't yours, or that you don't open, is
199
- * `not_found`, never handed off.
264
+ * sent: the person types it there. A workspace that isn't yours, that you don't open, or whose
265
+ * read pulse-admin refuses (D578), is `not_found`, never handed off.
200
266
  */
201
267
  rename(request: {
202
268
  readonly workspace_id: string;
@@ -213,8 +279,9 @@ export interface Flipstream {
213
279
  /**
214
280
  * The logbook (#218, #295), on the admin host: a workspace's notes on time ranges, and one
215
281
  * member's entries across your organisation's workspaces. A call under one workspace answers
216
- * `not_found` for one you don't open, as for one nobody has: see "The workspaces you open" in
217
- * docs/admin.md (#372).
282
+ * `not_found` for one you don't open, as for one nobody has, and so does one for a workspace or an
283
+ * entry whose own read pulse-admin refuses (D578): see "The workspaces you open" in docs/admin.md
284
+ * (#372).
218
285
  */
219
286
  readonly log: {
220
287
  /**
@@ -228,7 +295,8 @@ export interface Flipstream {
228
295
  * or removed in between, and entries written at the same moment have no fixed order among
229
296
  * themselves. A changed `total` shows that something was added or removed; an unchanged one
230
297
  * doesn't prove nothing was. Your organisation and you are read first, then the workspace
231
- * beside the list (#249, #372), under one deadline: one nobody has, or one you don't open, is
298
+ * beside the list (#249, #372), under one deadline: one nobody has, one you don't open, or one
299
+ * whose read pulse-admin refuses (D578), is
232
300
  * `not_found`, and another organisation's is `invalid`, never an empty page. An entry of
233
301
  * another workspace or organisation makes the answer `invalid`, never dropped. A limit or
234
302
  * offset that isn't a whole number in range rejects, with nothing sent, as every list's does.
@@ -245,7 +313,8 @@ export interface Flipstream {
245
313
  * One entry, by its id, read beside your organisation and you (#249, #372); `not_found` when
246
314
  * there's none, or it's in a workspace you don't open, and `invalid` when the answer is another
247
315
  * entry, or another organisation's. A failure of the entry's own read is the backend's, as it
248
- * answered.
316
+ * answered, but pulse-admin's own refusal (its 403, `FORBIDDEN_EXCEPTION`): that says the entry
317
+ * exists, so it's `not_found`, as one nobody has (D578).
249
318
  */
250
319
  get(request: {
251
320
  readonly log_id: string;
@@ -255,8 +324,9 @@ export interface Flipstream {
255
324
  * `refused` (`fields`, naming them), and a description that isn't a non-blank string, a time
256
325
  * not written as `2026-10-05T00:00:00Z` (a fraction may follow the seconds, and an offset such
257
326
  * as `+02:00`, or none, may take the place of the `Z`), or a start after the end rejects with a
258
- * TypeError. Your organisation and you are read first, then the workspace: one nobody has, or
259
- * one you don't open, is `not_found`, and another organisation's `invalid`, with nothing
327
+ * TypeError. Your organisation and you are read first, then the workspace: one nobody has, one
328
+ * you don't open, or one whose read pulse-admin refuses (D578), is `not_found`, and another
329
+ * organisation's `invalid`, with nothing
260
330
  * written. Times go as UTC instants; one with no offset is
261
331
  * read as UTC. Who may write is the backend's rule, not the SDK's: Owners, Admins and Editors
262
332
  * add; an Editor changes or removes only their own entries, and Owners and Admins any. Until the
@@ -294,9 +364,11 @@ export interface Flipstream {
294
364
  * dataset of another organisation is
295
365
  * `invalid`, never dropped or shown. The backend's answers embed each dataset's sign-in, so a
296
366
  * body that isn't its JSON is never kept: a failure of the dataset's own read or write has no
297
- * `text` (#279). The organisation's and the workspace's reads keep theirs. A call under one
298
- * workspace answers `not_found` for one you don't open, as for one nobody has: see "The
299
- * workspaces you open" in docs/admin.md (#372).
367
+ * `text` (#279). The organisation's and the workspace's reads keep theirs, but pulse-admin's own
368
+ * refusal of the workspace's read, which is `not_found`. A call under one workspace answers
369
+ * `not_found` for one you don't open, as for one nobody has, and so does one for a workspace or a
370
+ * dataset whose own read pulse-admin refuses (D578): see "The workspaces you open" in
371
+ * docs/admin.md (#372).
300
372
  */
301
373
  readonly datasets: {
302
374
  /**
@@ -306,8 +378,9 @@ export interface Flipstream {
306
378
  * can overlap or skip a dataset when datasets are added, removed or renamed in between, or when
307
379
  * two share a name. A changed `total` shows some of that; an unchanged one doesn't prove none
308
380
  * happened. For a complete, stable list, read it in one page, of up to 1,000. A dataset of
309
- * another workspace makes the answer `invalid`, never dropped. A workspace nobody has, or one
310
- * you don't open, is `not_found`, and another organisation's is `invalid`, never an empty page.
381
+ * another workspace makes the answer `invalid`, never dropped. A workspace nobody has, one you
382
+ * don't open, or one whose read pulse-admin refuses (D578), is `not_found`, and another
383
+ * organisation's is `invalid`, never an empty page.
311
384
  *
312
385
  * `{ organization: true }` instead of a workspace (#342): your organisation's datasets, in every
313
386
  * workspace you open, paged and ordered as a workspace's are. Exactly one of `workspace_id` and
@@ -327,7 +400,8 @@ export interface Flipstream {
327
400
  * workspace and organisation are read, so one `list` would refuse for anything else can't lose
328
401
  * the count, while one of another workspace or organisation, or a page whose count is smaller
329
402
  * than it or above 0 with no dataset on it, is `invalid`. The workspace is read beside it, by
330
- * `list`'s rules for it: a workspace nobody has, or one you don't open, is `not_found`, and
403
+ * `list`'s rules for it: a workspace nobody has, one you don't open, or one whose read
404
+ * pulse-admin refuses (D578), is `not_found`, and
331
405
  * another organisation's `invalid`, never a count of 0. The organisation's failure, then yours,
332
406
  * then the workspace's, then the count's, is the answer. A `workspace_id` that isn't a string
333
407
  * rejects with a TypeError, with nothing sent. A count across your organisation isn't here yet.
@@ -340,7 +414,9 @@ export interface Flipstream {
340
414
  /**
341
415
  * One dataset, by its id, read beside your organisation and you; `not_found` when there's none,
342
416
  * or it's in a workspace you don't open, and `invalid` when the answer is another dataset. A
343
- * failure of the dataset's own read is the backend's, as it answered.
417
+ * failure of the dataset's own read is the backend's, as it answered, but pulse-admin's own
418
+ * refusal (its 403, `FORBIDDEN_EXCEPTION`): that says the dataset exists, so it's `not_found`,
419
+ * as one nobody has (D578).
344
420
  */
345
421
  get(request: {
346
422
  readonly dataset_id: string;
@@ -350,7 +426,8 @@ export interface Flipstream {
350
426
  * sends the same write and answers the same. Before anything is sent, a key other than
351
427
  * `dataset_id` is `refused` (`fields`, naming them), and an id that isn't a string rejects with
352
428
  * a TypeError. The dataset is read first, fresh, beside your organisation and you: one nobody
353
- * has, or one in a workspace you don't open, is `not_found`, and another organisation's
429
+ * has, one in a workspace you don't open, or one whose read pulse-admin refuses (D578), is
430
+ * `not_found`, and another organisation's
354
431
  * `invalid`, with nothing written. Then `active` alone is sent, so a rename made meanwhile
355
432
  * stays. The dataset is read fresh again after the write, and the answer is that read: one
356
433
  * whose `active` isn't the one asked for is `invalid`, since the write may not have been
@@ -371,7 +448,8 @@ export interface Flipstream {
371
448
  /**
372
449
  * Deleting a dataset is a person's to do, in the console (D542, D546): it removes the dataset's
373
450
  * data for good, and the console can't delete one yet. Never a write: it reads the dataset (one
374
- * nobody has, or one in a workspace you don't open, is `not_found`, and another organisation's
451
+ * nobody has, one in a workspace you don't open, or one whose read pulse-admin refuses (D578), is
452
+ * `not_found`, and another organisation's
375
453
  * `invalid`), then answers `needs_person` with `why`, and the dataset's page as `url`, with
376
454
  * what it shows as `sees`, where a console can be named.
377
455
  */
@@ -471,7 +549,67 @@ export interface Flipstream {
471
549
  get(request: {
472
550
  readonly member_id: string;
473
551
  }, options?: CallOptions): Promise<ApiResult<Member>>;
552
+ /**
553
+ * Removing someone from your organisation is a person's to do, in the console (D542): it can't
554
+ * be undone. Never a write: it reads the person by `get`'s rules (one there's no such person
555
+ * for you, such as an API key, is `not_found`, a read pulse-auth refuses is `forbidden`, and
556
+ * another organisation's is `invalid`), then answers `needs_person` with `why`, and the
557
+ * person's page as `url`, with what it shows as `sees`, where a console can be named.
558
+ */
559
+ remove(request: {
560
+ readonly member_id: string;
561
+ }, options?: CallOptions): Promise<ApiResult<never>>;
474
562
  };
563
+ /**
564
+ * A scope for one piece of work, such as a page's load or a command (#376, D573): every call that
565
+ * takes it as `{ scope }` shares your organisation read (`GET /organizations/me`), your person read
566
+ * (userinfo, then `/users/{sub}`) and a workspace's own read (`GET /clients/{id}`), where outside
567
+ * a scope each call reads them for itself, every time.
568
+ * - They're read from the backend at the first call that needs them, and every later call reuses
569
+ * that read, still on its way or answered. Nothing is taken on your word.
570
+ * - A shared read is the starting call's own read, its deadline and retries, under a trace of its
571
+ * own, or the scope's `traceparent`'s trace when it's given one (`ScopeOptions`, #409), and every
572
+ * call it answers names that trace. A call's own `traceparent` never reaches it. Each call keeps
573
+ * its own `deadlineMs` and signal: they end that call's wait, never the read, and a call still
574
+ * waiting when the read times out at its starter's deadline reads again. A read no call waits on
575
+ * any more is ended.
576
+ * - A definitive failure (`forbidden`, `not_found`, `conflict`, `refused`, `rejected` but a 408 or
577
+ * 425, and `invalid` but a 2xx whose body isn't JSON or a status outside the contract) is every
578
+ * later call's answer too, as its own copy, with no new read. A transient one is the answer of
579
+ * the calls that waited on it, and the next call reads again.
580
+ * - A 401 on a shared read, or an app's transport answering one `cancelled`, drops every shared
581
+ * read, so the next call reads them all again. A token that switches to another person or
582
+ * organisation isn't seen otherwise: close the scope on a sign-out or a switch.
583
+ * - Close it when the work is done (`close()`, or `await using`). It keeps each answer until then:
584
+ * it's one piece of work, never a session. Nothing is kept past it.
585
+ */
586
+ scope(options?: ScopeOptions): Scope;
587
+ /**
588
+ * `scope(options)` for the length of `run`: `run` gets the client with every call in the scope, and
589
+ * the scope is closed when `run` settles, so it can't be left open. `run`'s answer is
590
+ * `withScope`'s, and so is its rejection.
591
+ */
592
+ withScope<T>(run: (flipstream: ScopedFlipstream) => Promise<T>, options?: ScopeOptions): Promise<T>;
475
593
  }
594
+ /** The client inside `withScope`: every call in its scope, and no scope of its own (#376). */
595
+ export type ScopedFlipstream = Omit<Flipstream, 'scope' | 'withScope'>;
596
+ /** Flipstream's deployed hosts: a client's defaults, and what `createFlipstreamFor`'s `deployed` stands in for. */
597
+ export declare const DEFAULT_HOSTS: {
598
+ readonly query: "https://query.flipstream.io";
599
+ readonly auth: "https://auth.flipstream.io";
600
+ readonly admin: "https://pulse.admin.api.flipstream.io";
601
+ readonly wallet: "https://pulse.wallet.api.flipstream.io";
602
+ };
603
+ /** The hosts a client takes as Flipstream's own deployment, whatever it was configured with. */
604
+ export type DeployedHosts = {
605
+ readonly [Service in keyof typeof DEFAULT_HOSTS]: string;
606
+ };
476
607
  /** The SDK, for one caller (D421): the console with its transport, or anyone with a token function. */
477
608
  export declare function createFlipstream(options: FlipstreamOptions): Flipstream;
609
+ /**
610
+ * `createFlipstream`, with `deployed` as Flipstream's own hosts: what decides whether a configured
611
+ * admin host is Flipstream's, for the console it names. The package doesn't export it: the contract
612
+ * cases (scripts/surface.mjs) use it so a local server can stand in for a deployed host, as
613
+ * `createFileLock` takes a test's timings (#378's code review, 1).
614
+ */
615
+ export declare function createFlipstreamFor(options: FlipstreamOptions, deployed: DeployedHosts): Flipstream;