@flipstream/sdk 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +179 -424
  3. package/dist/api/backend.d.ts +21 -3
  4. package/dist/api/backend.js +50 -10
  5. package/dist/api/backend.js.map +1 -1
  6. package/dist/api/credentials.js +4 -4
  7. package/dist/api/credentials.js.map +1 -1
  8. package/dist/api/datasets.d.ts +82 -14
  9. package/dist/api/datasets.js +193 -57
  10. package/dist/api/datasets.js.map +1 -1
  11. package/dist/api/index.d.ts +1 -1
  12. package/dist/api/log.d.ts +25 -20
  13. package/dist/api/log.js +63 -48
  14. package/dist/api/log.js.map +1 -1
  15. package/dist/api/me.js +9 -5
  16. package/dist/api/me.js.map +1 -1
  17. package/dist/api/members.d.ts +34 -1
  18. package/dist/api/members.js +67 -27
  19. package/dist/api/members.js.map +1 -1
  20. package/dist/api/wallet.d.ts +8 -5
  21. package/dist/api/wallet.js +40 -25
  22. package/dist/api/wallet.js.map +1 -1
  23. package/dist/api/workspaces.d.ts +35 -14
  24. package/dist/api/workspaces.js +53 -23
  25. package/dist/api/workspaces.js.map +1 -1
  26. package/dist/auth/discovery.d.ts +19 -6
  27. package/dist/auth/discovery.js +30 -6
  28. package/dist/auth/discovery.js.map +1 -1
  29. package/dist/auth/signIn.d.ts +18 -14
  30. package/dist/auth/signIn.js +29 -22
  31. package/dist/auth/signIn.js.map +1 -1
  32. package/dist/core/call.d.ts +13 -1
  33. package/dist/core/call.js +34 -9
  34. package/dist/core/call.js.map +1 -1
  35. package/dist/core/deadline.d.ts +30 -0
  36. package/dist/core/deadline.js +51 -0
  37. package/dist/core/deadline.js.map +1 -0
  38. package/dist/core/identify.d.ts +59 -14
  39. package/dist/core/identify.js +54 -20
  40. package/dist/core/identify.js.map +1 -1
  41. package/dist/core/invalid.d.ts +10 -0
  42. package/dist/core/invalid.js +28 -0
  43. package/dist/core/invalid.js.map +1 -0
  44. package/dist/core/names.d.ts +13 -2
  45. package/dist/core/names.js +11 -2
  46. package/dist/core/names.js.map +1 -1
  47. package/dist/core/notFound.d.ts +8 -0
  48. package/dist/core/notFound.js +8 -0
  49. package/dist/core/notFound.js.map +1 -0
  50. package/dist/core/read.d.ts +9 -0
  51. package/dist/core/read.js +14 -5
  52. package/dist/core/read.js.map +1 -1
  53. package/dist/core/result.d.ts +22 -13
  54. package/dist/core/result.js +5 -5
  55. package/dist/core/result.js.map +1 -1
  56. package/dist/core/retry.d.ts +5 -2
  57. package/dist/core/retry.js +6 -3
  58. package/dist/core/retry.js.map +1 -1
  59. package/dist/core/scope.d.ts +20 -0
  60. package/dist/core/scope.js +54 -0
  61. package/dist/core/scope.js.map +1 -0
  62. package/dist/core/shared.d.ts +39 -0
  63. package/dist/core/shared.js +177 -0
  64. package/dist/core/shared.js.map +1 -0
  65. package/dist/core/signal.d.ts +12 -0
  66. package/dist/core/signal.js +25 -0
  67. package/dist/core/signal.js.map +1 -0
  68. package/dist/flipstream.d.ts +223 -72
  69. package/dist/flipstream.js +225 -88
  70. package/dist/flipstream.js.map +1 -1
  71. package/dist/index.d.ts +1 -1
  72. package/dist/node/clientSecret.js +7 -6
  73. package/dist/node/clientSecret.js.map +1 -1
  74. package/dist/node/headless.d.ts +14 -6
  75. package/dist/node/headless.js +8 -6
  76. package/dist/node/headless.js.map +1 -1
  77. package/dist/node/index.d.ts +1 -1
  78. package/dist/node/index.js +1 -1
  79. package/dist/node/index.js.map +1 -1
  80. package/dist/node/keychainChild.js +26 -14
  81. package/dist/node/keychainChild.js.map +1 -1
  82. package/dist/node/keychainError.d.ts +3 -3
  83. package/dist/node/keychainStore.d.ts +10 -7
  84. package/dist/node/keychainStore.js +44 -23
  85. package/dist/node/keychainStore.js.map +1 -1
  86. package/dist/node/loopback.d.ts +13 -3
  87. package/dist/node/loopback.js +47 -5
  88. package/dist/node/loopback.js.map +1 -1
  89. package/dist/node/session.d.ts +17 -9
  90. package/dist/node/session.js +68 -50
  91. package/dist/node/session.js.map +1 -1
  92. package/dist/node/store.d.ts +35 -2
  93. package/dist/node/store.js +56 -12
  94. package/dist/node/store.js.map +1 -1
  95. package/dist/version.gen.js +1 -1
  96. package/docs/admin.md +558 -0
  97. package/docs/node-sign-in.md +63 -39
  98. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { type Credential } from './api/credentials.js';
2
- import { type Dataset, type DatasetListRequest, type DatasetType } from './api/datasets.js';
2
+ import { type Dataset, type DatasetListRequest, type DatasetOrganizationListRequest, type DatasetType } from './api/datasets.js';
3
3
  import { type LogAddRequest, type LogEntry, type LogListRequest, type LogMemberListRequest, type LogUpdateRequest } from './api/log.js';
4
4
  import { type Me } from './api/me.js';
5
5
  import { type Member } from './api/members.js';
@@ -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: {
@@ -56,7 +58,11 @@ export interface Identification {
56
58
  readonly conversationId?: string;
57
59
  }
58
60
  export type FlipstreamOptions = Identification & (
59
- /** The console: its own transport, which attaches the token and decides what may go. */
61
+ /**
62
+ * The console: its own transport, which attaches the token and decides what may go. When it
63
+ * rejects, the call rejects once none of its reads is still waited on: its other reads are ended
64
+ * through their signal, and the rejection is the first to reject in the order started (#349).
65
+ */
60
66
  {
61
67
  readonly transport: Transport;
62
68
  readonly hosts?: Hosts;
@@ -84,7 +90,13 @@ export type FlipstreamOptions = Identification & (
84
90
  export interface CallOptions {
85
91
  /** Ends the call at once: its answer is `aborted`. */
86
92
  readonly signal?: AbortSignal;
87
- /** The whole call's deadline, every attempt and wait included; the endpoint's own when left out. */
93
+ /**
94
+ * The whole call's deadline, every attempt and wait included; the endpoint's own when left out
95
+ * or `null`. A number of ms up to 2147483647, the most a timer holds, taken in whole ms, rounded
96
+ * down. One that can't be a deadline (not a number, NaN, ±Infinity, or more than that once rounded
97
+ * down) is a TypeError naming the call, with nothing sent. A spent deadline, under 1 ms or one
98
+ * spent before a request goes out, answers `timeout`, and sends nothing (#339).
99
+ */
88
100
  readonly deadlineMs?: number;
89
101
  /**
90
102
  * This call's conversation, in place of the client's, under the same rule. One that breaks it
@@ -93,11 +105,45 @@ export interface CallOptions {
93
105
  readonly conversationId?: string;
94
106
  /**
95
107
  * The caller's own W3C trace context, carried on: the call keeps its trace-id and flags, with a
96
- * parent-id of its own for each attempt, and its result's `traceId` is that trace-id (#251). One
108
+ * parent-id of its own for each attempt, and its result's `trace_id` is that trace-id (#251). One
97
109
  * that isn't a valid version-00 traceparent is dropped, as W3C Trace Context says, and the call
98
110
  * starts its own trace.
99
111
  */
100
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
+ /**
131
+ * One piece of work's shared reads (#376, D573): a route's load in the console, a command in the
132
+ * CLI. Made by `flipstream.scope()`, taken by each call as `{ scope }`, and ended by `close()`, or
133
+ * by `await using`, which calls it when the block ends.
134
+ */
135
+ export interface Scope {
136
+ /**
137
+ * Ends the scope: every shared read still on its way is ended, and its waiting calls answer
138
+ * `aborted`. Answers once each has settled. A call that takes the scope after this reads its own,
139
+ * as outside a scope. Closing it again does nothing more.
140
+ */
141
+ close(): Promise<void>;
142
+ /**
143
+ * `close()`, so `await using` closes the scope when its block ends. Only where the runtime has
144
+ * `Symbol.asyncDispose`; `close()` itself works everywhere (#377's code review, 5).
145
+ */
146
+ [Symbol.asyncDispose](): Promise<void>;
101
147
  }
102
148
  /** What `createFlipstream` gives: each call settles into an `ApiResult`, never a thrown error (D412). */
103
149
  export interface Flipstream {
@@ -141,8 +187,10 @@ export interface Flipstream {
141
187
  };
142
188
  /**
143
189
  * Your organisation's workspaces (#208), through the admin API. Each call reads your organisation
144
- * first, for its id, under one deadline for both reads (the call's, or 30 s); its failure is the
145
- * answer. A workspace of another organisation is `invalid`, never dropped or shown.
190
+ * first, for its id, and a call under one workspace reads you beside it, all under one deadline
191
+ * (the call's, or 30 s); the first failure is the answer. A workspace of another organisation is
192
+ * `invalid`, never dropped or shown. A call under one workspace answers `not_found` for one you
193
+ * don't open, as for one nobody has: see "The workspaces you open" in docs/admin.md (#372).
146
194
  */
147
195
  readonly workspaces: {
148
196
  /**
@@ -151,10 +199,17 @@ export interface Flipstream {
151
199
  * backend's, by name alone (D550): pages read at different times can overlap or skip a
152
200
  * workspace when workspaces are added, removed or renamed in between, or when two share a name.
153
201
  * A changed `total` shows some of that; an unchanged one doesn't prove none happened. For a
154
- * complete, stable list, read it in one page, of up to 1,000.
202
+ * complete, stable list, read it in one page, of up to 1,000. The list isn't held to the
203
+ * workspaces you open (#372's round 1, O1.F1): the backend scopes it only for an account whose
204
+ * roles are exactly `['viewer']`, so another account the SDK holds to its workspaces (a role
205
+ * read as none, say) can list ones every other call answers `not_found` for.
155
206
  */
156
207
  list(request?: PageRequest, options?: CallOptions): Promise<ApiResult<Page<Workspace>>>;
157
- /** One workspace, by its id. An id that can't stay one path segment is `refused` (`path`), with nothing sent. */
208
+ /**
209
+ * One workspace, by its id. An id that can't stay one path segment is `refused` (`path`), with
210
+ * nothing sent. Your organisation and you are read first, so one you don't open is `not_found`,
211
+ * exactly as one nobody has, with nothing under it read.
212
+ */
158
213
  get(request: {
159
214
  readonly workspace_id: string;
160
215
  }, options?: CallOptions): Promise<ApiResult<Workspace>>;
@@ -176,7 +231,8 @@ export interface Flipstream {
176
231
  /**
177
232
  * A rename is a person's, in the console (D542): it answers `needs_person`, with why and, where
178
233
  * the console can be named, the workspace's settings page. It never writes, and the name isn't
179
- * sent: the person types it there. A workspace that isn't yours is `not_found`, never handed off.
234
+ * sent: the person types it there. A workspace that isn't yours, or that you don't open, is
235
+ * `not_found`, never handed off.
180
236
  */
181
237
  rename(request: {
182
238
  readonly workspace_id: string;
@@ -191,8 +247,10 @@ export interface Flipstream {
191
247
  }, options?: CallOptions): Promise<ApiResult<never>>;
192
248
  };
193
249
  /**
194
- * The logbook (#218, #295), on the admin host: a workspace's notes on time ranges, and one member's
195
- * entries across your organisation's workspaces.
250
+ * The logbook (#218, #295), on the admin host: a workspace's notes on time ranges, and one
251
+ * member's entries across your organisation's workspaces. A call under one workspace answers
252
+ * `not_found` for one you don't open, as for one nobody has: see "The workspaces you open" in
253
+ * docs/admin.md (#372).
196
254
  */
197
255
  readonly log: {
198
256
  /**
@@ -200,16 +258,16 @@ export interface Flipstream {
200
258
  * workspace of your organisation (`{ member_id }`, #295). Exactly one of the two: both, or neither,
201
259
  * rejects with a TypeError, with nothing sent.
202
260
  *
203
- * A workspace's entries come newest first by when they were written: the backend's
204
- * own order, since no other is asked for. When an entry was written never changes, so editing
205
- * one doesn't move it, but pages read at different times can overlap or skip an entry when one
206
- * is written or removed in between, and entries written at the same moment have no fixed order
207
- * among themselves. A changed `total` shows that something was added or removed; an unchanged
208
- * one doesn't prove nothing was. The workspace is read beside the list (#249), with your
209
- * organisation, under one deadline: one nobody has is `not_found`, and another organisation's is
210
- * `invalid`, never an empty page. An entry of another workspace or organisation makes the answer
211
- * `invalid`, never dropped. A limit or offset that isn't a whole number in range rejects, with
212
- * nothing sent, as every list's does.
261
+ * A workspace's entries come newest first by when they were written: the backend's own order,
262
+ * since no other is asked for. When an entry was written never changes, so editing one doesn't
263
+ * move it, but pages read at different times can overlap or skip an entry when one is written
264
+ * or removed in between, and entries written at the same moment have no fixed order among
265
+ * themselves. A changed `total` shows that something was added or removed; an unchanged one
266
+ * doesn't prove nothing was. Your organisation and you are read first, then the workspace
267
+ * beside the list (#249, #372), under one deadline: one nobody has, or one you don't open, is
268
+ * `not_found`, and another organisation's is `invalid`, never an empty page. An entry of
269
+ * another workspace or organisation makes the answer `invalid`, never dropped. A limit or
270
+ * offset that isn't a whole number in range rejects, with nothing sent, as every list's does.
213
271
  *
214
272
  * A member's: your organisation, you and the member are read first, under the same deadline. A
215
273
  * person who isn't a member, or a key, is `not_found`, and another organisation's member
@@ -220,8 +278,10 @@ export interface Flipstream {
220
278
  */
221
279
  list(request: LogListRequest | LogMemberListRequest, options?: CallOptions): Promise<ApiResult<Page<LogEntry>>>;
222
280
  /**
223
- * One entry, by its id, read beside your organisation (#249); `not_found` when there's none, and
224
- * `invalid` when the answer is another entry, or another organisation's.
281
+ * One entry, by its id, read beside your organisation and you (#249, #372); `not_found` when
282
+ * there's none, or it's in a workspace you don't open, and `invalid` when the answer is another
283
+ * entry, or another organisation's. A failure of the entry's own read is the backend's, as it
284
+ * answered.
225
285
  */
226
286
  get(request: {
227
287
  readonly log_id: string;
@@ -231,8 +291,9 @@ export interface Flipstream {
231
291
  * `refused` (`fields`, naming them), and a description that isn't a non-blank string, a time
232
292
  * not written as `2026-10-05T00:00:00Z` (a fraction may follow the seconds, and an offset such
233
293
  * as `+02:00`, or none, may take the place of the `Z`), or a start after the end rejects with a
234
- * TypeError. The workspace is read first: one nobody has is `not_found`, and another
235
- * organisation's `invalid`, with nothing written. Times go as UTC instants; one with no offset is
294
+ * TypeError. Your organisation and you are read first, then the workspace: one nobody has, or
295
+ * one you don't open, is `not_found`, and another organisation's `invalid`, with nothing
296
+ * written. Times go as UTC instants; one with no offset is
236
297
  * read as UTC. Who may write is the backend's rule, not the SDK's: Owners, Admins and Editors
237
298
  * add; an Editor changes or removes only their own entries, and Owners and Admins any. Until the
238
299
  * backend enforces it (pulse-admin#161, for Editors), a Viewer can also add, change and remove
@@ -243,44 +304,80 @@ export interface Flipstream {
243
304
  add(request: LogAddRequest, options?: CallOptions): Promise<ApiResult<LogEntry>>;
244
305
  /**
245
306
  * An entry's words or range changed (#219), with the same rules as `add`, and at least one
246
- * change. The entry is read first (one that isn't yours is `not_found` or `invalid`, with
247
- * nothing written), then sent back whole: what you change, and the rest exactly as stored. When
248
- * you give a time, a start after the end, the stored one included, rejects with a TypeError, with
249
- * nothing written. Since the whole entry goes back, a change someone else made between the read
250
- * and the write is overwritten.
307
+ * change. The entry is read first, as `get` reads it (one that isn't yours, or is in a
308
+ * workspace you don't open, is `not_found` or `invalid`, with nothing written), then sent back
309
+ * whole: what you change, and the rest exactly as stored. When you give a time, a start after
310
+ * the end, the stored one included, rejects with a TypeError, with nothing written. Since the
311
+ * whole entry goes back, a change someone else made between the read and the write is
312
+ * overwritten.
251
313
  */
252
314
  update(request: LogUpdateRequest, options?: CallOptions): Promise<ApiResult<LogEntry>>;
253
315
  /**
254
316
  * An entry removed (#219), directly: a log entry isn't one of the hand-offs. The entry is read
255
- * first (one that isn't yours is `not_found` or `invalid`, with nothing removed); an ok is
256
- * `null`.
317
+ * first, as `get` reads it (one that isn't yours, or is in a workspace you don't open, is
318
+ * `not_found` or `invalid`, with nothing removed); an ok is `null`.
257
319
  */
258
320
  remove(request: {
259
321
  readonly log_id: string;
260
322
  }, options?: CallOptions): Promise<ApiResult<null>>;
261
323
  };
262
324
  /**
263
- * A workspace's datasets (#211), on the admin host: its uploads and connected accounts, the
264
- * backend's connections. Each call reads your organisation beside the datasets, and a list reads
265
- * its workspace too, under one deadline for every read (the call's, or 30 s). The organisation's
266
- * failure, then the workspace's, then the datasets', is the answer, and a dataset of another
267
- * organisation is `invalid`, never dropped or shown. The backend's answers embed each dataset's
268
- * sign-in, so a body that isn't its JSON is never kept: a failure of the dataset's own read or
269
- * write has no `text` (#279). The organisation's and the workspace's reads keep theirs.
325
+ * A workspace's datasets (#211), or your organisation's (#342), on the admin host: uploads and
326
+ * connected accounts, the backend's connections. Each call reads your organisation and you, under
327
+ * one deadline for every read (the call's, or 30 s). A workspace's calls read those first, then
328
+ * the workspace beside its datasets, so the organisation's failure, then yours, then the
329
+ * workspace's, then the datasets', is the answer; a dataset by its id is read beside them. A
330
+ * dataset of another organisation is
331
+ * `invalid`, never dropped or shown. The backend's answers embed each dataset's sign-in, so a
332
+ * body that isn't its JSON is never kept: a failure of the dataset's own read or write has no
333
+ * `text` (#279). The organisation's and the workspace's reads keep theirs. A call under one
334
+ * workspace answers `not_found` for one you don't open, as for one nobody has: see "The
335
+ * workspaces you open" in docs/admin.md (#372).
270
336
  */
271
337
  readonly datasets: {
272
338
  /**
273
339
  * One page of the workspace's datasets: `limit` (100 when left out, at most 1,000) and `offset`
274
340
  * (0). A limit or offset that isn't a whole number in range rejects with a TypeError, with
275
- * nothing sent. The order is the backend's, by name alone (D550): pages read at different
276
- * times can overlap or skip a dataset when datasets are added, removed or renamed in between,
277
- * or when two share a name. A changed `total` shows some of that; an unchanged one doesn't
278
- * prove none happened. For a complete, stable list, read it in one page, of up to 1,000. A
279
- * dataset of another workspace makes the answer `invalid`, never dropped. A workspace nobody has
280
- * is `not_found`, and another organisation's is `invalid`, never an empty page.
341
+ * nothing sent. The order is the backend's, by name alone (D550): pages read at different times
342
+ * can overlap or skip a dataset when datasets are added, removed or renamed in between, or when
343
+ * two share a name. A changed `total` shows some of that; an unchanged one doesn't prove none
344
+ * happened. For a complete, stable list, read it in one page, of up to 1,000. A dataset of
345
+ * another workspace makes the answer `invalid`, never dropped. A workspace nobody has, or one
346
+ * you don't open, is `not_found`, and another organisation's is `invalid`, never an empty page.
347
+ *
348
+ * `{ organization: true }` instead of a workspace (#342): your organisation's datasets, in every
349
+ * workspace you open, paged and ordered as a workspace's are. Exactly one of `workspace_id` and
350
+ * `organization: true`: both, neither, or an `organization` that isn't `true` rejects with a
351
+ * TypeError, with nothing sent. Your organisation is read first, since its id names the route,
352
+ * and the list once it answers, with you read beside both: two round trips in a row, under the
353
+ * same deadline. No workspace is read. Every dataset must be your organisation's and in a
354
+ * workspace you open (if your account names workspaces, only those, unless you're an owner, an
355
+ * admin or an editor): any other makes the answer `invalid`, never dropped. The backend holds a
356
+ * viewer to their workspaces too; this is the second check. Your organisation's failure (an id
357
+ * that can't name the route among them), then yours, then the datasets', is the answer.
358
+ */
359
+ list(request: DatasetListRequest | DatasetOrganizationListRequest, options?: CallOptions): Promise<ApiResult<Page<Dataset>>>;
360
+ /**
361
+ * How many datasets the workspace has (#364): `{ count }`, from the backend's own count, the
362
+ * total of one page of one dataset, read as `list` reads a page. Of that dataset only its
363
+ * workspace and organisation are read, so one `list` would refuse for anything else can't lose
364
+ * the count, while one of another workspace or organisation, or a page whose count is smaller
365
+ * than it or above 0 with no dataset on it, is `invalid`. The workspace is read beside it, by
366
+ * `list`'s rules for it: a workspace nobody has, or one you don't open, is `not_found`, and
367
+ * another organisation's `invalid`, never a count of 0. The organisation's failure, then yours,
368
+ * then the workspace's, then the count's, is the answer. A `workspace_id` that isn't a string
369
+ * rejects with a TypeError, with nothing sent. A count across your organisation isn't here yet.
370
+ */
371
+ count(request: {
372
+ readonly workspace_id: string;
373
+ }, options?: CallOptions): Promise<ApiResult<{
374
+ readonly count: number;
375
+ }>>;
376
+ /**
377
+ * One dataset, by its id, read beside your organisation and you; `not_found` when there's none,
378
+ * or it's in a workspace you don't open, and `invalid` when the answer is another dataset. A
379
+ * failure of the dataset's own read is the backend's, as it answered.
281
380
  */
282
- list(request: DatasetListRequest, options?: CallOptions): Promise<ApiResult<Page<Dataset>>>;
283
- /** One dataset, by its id; `not_found` when there's none, and `invalid` when the answer is another dataset. */
284
381
  get(request: {
285
382
  readonly dataset_id: string;
286
383
  }, options?: CallOptions): Promise<ApiResult<Dataset>>;
@@ -288,16 +385,17 @@ export interface Flipstream {
288
385
  * Pauses a dataset (#212): the answer is the `Dataset`, `active` false. Pausing a paused one
289
386
  * sends the same write and answers the same. Before anything is sent, a key other than
290
387
  * `dataset_id` is `refused` (`fields`, naming them), and an id that isn't a string rejects with
291
- * a TypeError. The dataset is read first, fresh: one nobody has is `not_found`, and another
292
- * organisation's `invalid`, with nothing written. Then `active` alone is sent, so a rename made
293
- * meanwhile stays. The dataset is read fresh again after the write, and the answer is that read:
294
- * one whose `active` isn't the one asked for is `invalid`, since the write may not have been
388
+ * a TypeError. The dataset is read first, fresh, beside your organisation and you: one nobody
389
+ * has, or one in a workspace you don't open, is `not_found`, and another organisation's
390
+ * `invalid`, with nothing written. Then `active` alone is sent, so a rename made meanwhile
391
+ * stays. The dataset is read fresh again after the write, and the answer is that read: one
392
+ * whose `active` isn't the one asked for is `invalid`, since the write may not have been
295
393
  * stored. That read comes after the write was sent, so its failure that would say nothing was
296
- * written (a 4xx kind, `refused`, `no_token`) is `invalid` too, naming its kind. Who may is
297
- * the backend's rule: Owners, Admins and Editors pause and resume, and a Viewer doesn't. Anyone
298
- * it refuses gets `forbidden`. A write is never tried again: only a refusal (a 4xx kind),
299
- * `refused` or `no_token` shows nothing was written. After any other failure it may have been;
300
- * pausing again is safe, since it's the same write.
394
+ * written (a 4xx kind, `refused`, `no_token`) is `invalid` too, naming its kind, with that
395
+ * read's status when it had one. Who may is the backend's rule: Owners, Admins and Editors
396
+ * pause and resume, and a Viewer doesn't. Anyone it refuses gets `forbidden`. A write is never
397
+ * tried again: only a refusal (a 4xx kind), `refused` or `no_token` shows nothing was written.
398
+ * After any other failure it may have been; pausing again is safe, since it's the same write.
301
399
  */
302
400
  pause(request: {
303
401
  readonly dataset_id: string;
@@ -309,9 +407,9 @@ export interface Flipstream {
309
407
  /**
310
408
  * Deleting a dataset is a person's to do, in the console (D542, D546): it removes the dataset's
311
409
  * data for good, and the console can't delete one yet. Never a write: it reads the dataset (one
312
- * nobody has is `not_found`, and another organisation's `invalid`), then answers `needs_person`
313
- * with `why`, and the dataset's page as `url`, with what it shows as `sees`, where a console can
314
- * be named.
410
+ * nobody has, or one in a workspace you don't open, is `not_found`, and another organisation's
411
+ * `invalid`), then answers `needs_person` with `why`, and the dataset's page as `url`, with
412
+ * what it shows as `sees`, where a console can be named.
315
413
  */
316
414
  delete(request: {
317
415
  readonly dataset_id: string;
@@ -359,7 +457,8 @@ export interface Flipstream {
359
457
  * your organisation first, for the wallet's id, under one deadline for both reads; its failure is
360
458
  * the answer. Who may read it is the wallet's rule, not the SDK's: today Owners and Admins, and
361
459
  * Editors too once pulse-wallet#15 lands. Anyone the wallet refuses gets `forbidden`, never an
362
- * empty ledger. Amounts are integer micro, and each answer says how many make a euro.
460
+ * empty ledger. Both reads answer null when your organisation has no wallet (#374). Amounts are
461
+ * integer micro, and every answer that holds them says how many make a euro, in `micro_per_euro`.
363
462
  */
364
463
  readonly wallet: {
365
464
  /**
@@ -369,18 +468,22 @@ export interface Flipstream {
369
468
  */
370
469
  balance(options?: CallOptions): Promise<ApiResult<Balance | null>>;
371
470
  /**
372
- * Your whole ledger, in one answer, with no paging. Its rows carry no wallet id, so the balance
373
- * is read beside it, and the ledger is answered only when that is your organisation's wallet.
471
+ * Your whole ledger, in one answer, with no paging, or null when the organisation has no
472
+ * wallet, as `balance()` answers: a wallet with no rows is an empty ledger, never null. Its rows
473
+ * carry no wallet id, so the balance is read beside it, and the ledger is answered only when
474
+ * that is your organisation's wallet. The balance settles no wallet: null, even when the
475
+ * ledger can't be read, and a ledger row then is `invalid`, as is a ledger answer the SDK
476
+ * can't read, which may hold rows.
374
477
  */
375
- transactions(options?: CallOptions): Promise<ApiResult<Ledger>>;
478
+ transactions(options?: CallOptions): Promise<ApiResult<Ledger | null>>;
376
479
  };
377
480
  /**
378
- * Your organisation's people (#220), from the auth host, each as `me()` answers you: one role by
379
- * D544's rule, and `null` for none and for Flipstream's staff. People, not keys: an API user, a
380
- * service account, is never listed, counted or answered (`get` of one is `not_found`), as the
381
- * console's People has it. An open invitation is listed, with an empty `first_name`. Each call
382
- * reads your organisation beside them, under one deadline for both reads (the call's, or 30 s).
383
- * The organisation's failure, then the people's, is the answer, and a person of another
481
+ * Your organisation's people (#220), from the auth host, each as `me()` answers you, their roles
482
+ * as `Member`'s `role`, `roles` and `unknown_roles` say (D544, #297). People, not keys: an API
483
+ * user, a service account, is never listed, counted or answered (`get` of one is `not_found`), as
484
+ * the console's People has it. An open invitation is listed, with an empty `first_name`. Each
485
+ * call reads your organisation beside them, under one deadline for both reads (the call's, or
486
+ * 30 s). The organisation's failure, then the people's, is the answer, and a person of another
384
487
  * organisation is `invalid`, never dropped or shown.
385
488
  */
386
489
  readonly members: {
@@ -405,6 +508,54 @@ export interface Flipstream {
405
508
  readonly member_id: string;
406
509
  }, options?: CallOptions): Promise<ApiResult<Member>>;
407
510
  };
511
+ /**
512
+ * A scope for one piece of work, such as a page's load or a command (#376, D573): every call that
513
+ * takes it as `{ scope }` shares your organisation read (`GET /organizations/me`), your person read
514
+ * (userinfo, then `/users/{sub}`) and a workspace's own read (`GET /clients/{id}`), where outside
515
+ * a scope each call reads them for itself, every time.
516
+ * - They're read from the backend at the first call that needs them, and every later call reuses
517
+ * that read, still on its way or answered. Nothing is taken on your word.
518
+ * - A shared read is the starting call's own read, its deadline and retries, under a trace of its
519
+ * own, and every call it answers names that trace. Each call keeps its own `deadlineMs` and
520
+ * signal: they end that call's wait, never the read, and a call still waiting when the read times
521
+ * out at its starter's deadline reads again. A read no call waits on any more is ended.
522
+ * - A definitive failure (`forbidden`, `not_found`, `conflict`, `refused`, `rejected` but a 408 or
523
+ * 425, and `invalid` but a 2xx whose body isn't JSON or a status outside the contract) is every
524
+ * later call's answer too, as its own copy, with no new read. A transient one is the answer of
525
+ * the calls that waited on it, and the next call reads again.
526
+ * - A 401 on a shared read, or an app's transport answering one `cancelled`, drops every shared
527
+ * read, so the next call reads them all again. A token that switches to another person or
528
+ * organisation isn't seen otherwise: close the scope on a sign-out or a switch.
529
+ * - Close it when the work is done (`close()`, or `await using`). It keeps each answer until then:
530
+ * it's one piece of work, never a session. Nothing is kept past it.
531
+ */
532
+ scope(): Scope;
533
+ /**
534
+ * `scope()` for the length of `run`: `run` gets the client with every call in the scope, and the
535
+ * scope is closed when `run` settles, so it can't be left open. `run`'s answer is `withScope`'s,
536
+ * and so is its rejection.
537
+ */
538
+ withScope<T>(run: (flipstream: ScopedFlipstream) => Promise<T>): Promise<T>;
408
539
  }
540
+ /** The client inside `withScope`: every call in its scope, and no scope of its own (#376). */
541
+ export type ScopedFlipstream = Omit<Flipstream, 'scope' | 'withScope'>;
542
+ /** Flipstream's deployed hosts: a client's defaults, and what `createFlipstreamFor`'s `deployed` stands in for. */
543
+ export declare const DEFAULT_HOSTS: {
544
+ readonly query: "https://query.flipstream.io";
545
+ readonly auth: "https://auth.flipstream.io";
546
+ readonly admin: "https://pulse.admin.api.flipstream.io";
547
+ readonly wallet: "https://pulse.wallet.api.flipstream.io";
548
+ };
549
+ /** The hosts a client takes as Flipstream's own deployment, whatever it was configured with. */
550
+ export type DeployedHosts = {
551
+ readonly [Service in keyof typeof DEFAULT_HOSTS]: string;
552
+ };
409
553
  /** The SDK, for one caller (D421): the console with its transport, or anyone with a token function. */
410
554
  export declare function createFlipstream(options: FlipstreamOptions): Flipstream;
555
+ /**
556
+ * `createFlipstream`, with `deployed` as Flipstream's own hosts: what decides whether a configured
557
+ * admin host is Flipstream's, for the console it names. The package doesn't export it: the contract
558
+ * cases (scripts/surface.mjs) use it so a local server can stand in for a deployed host, as
559
+ * `createFileLock` takes a test's timings (#378's code review, 1).
560
+ */
561
+ export declare function createFlipstreamFor(options: FlipstreamOptions, deployed: DeployedHosts): Flipstream;