@flipstream/sdk 0.10.1 → 0.12.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.
- package/CHANGELOG.md +75 -0
- package/README.md +98 -348
- package/dist/api/account.d.ts +50 -0
- package/dist/api/account.js +102 -0
- package/dist/api/account.js.map +1 -0
- package/dist/api/backend.d.ts +18 -0
- package/dist/api/backend.js +35 -4
- package/dist/api/backend.js.map +1 -1
- package/dist/api/created.d.ts +1 -1
- package/dist/api/created.js +3 -2
- package/dist/api/created.js.map +1 -1
- package/dist/api/credentials.js +4 -4
- package/dist/api/credentials.js.map +1 -1
- package/dist/api/datasets.d.ts +94 -14
- package/dist/api/datasets.js +210 -59
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/index.d.ts +4 -3
- package/dist/api/log.d.ts +45 -24
- package/dist/api/log.js +113 -40
- package/dist/api/log.js.map +1 -1
- package/dist/api/me.d.ts +2 -0
- package/dist/api/me.js +9 -5
- package/dist/api/me.js.map +1 -1
- package/dist/api/members.d.ts +69 -7
- package/dist/api/members.js +110 -32
- package/dist/api/members.js.map +1 -1
- package/dist/api/time.js +4 -3
- package/dist/api/time.js.map +1 -1
- package/dist/api/wallet.d.ts +8 -5
- package/dist/api/wallet.js +36 -24
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +42 -7
- package/dist/api/workspaces.js +80 -20
- package/dist/api/workspaces.js.map +1 -1
- package/dist/auth/discovery.d.ts +19 -6
- package/dist/auth/discovery.js +25 -4
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.d.ts +18 -14
- package/dist/auth/signIn.js +29 -22
- package/dist/auth/signIn.js.map +1 -1
- package/dist/core/call.d.ts +4 -1
- package/dist/core/call.js +26 -6
- package/dist/core/call.js.map +1 -1
- package/dist/core/deadline.d.ts +30 -0
- package/dist/core/deadline.js +51 -0
- package/dist/core/deadline.js.map +1 -0
- package/dist/core/invalid.d.ts +7 -0
- package/dist/core/invalid.js +22 -0
- package/dist/core/invalid.js.map +1 -0
- package/dist/core/names.d.ts +31 -3
- package/dist/core/names.js +26 -6
- package/dist/core/names.js.map +1 -1
- package/dist/core/notFound.d.ts +8 -0
- package/dist/core/notFound.js +8 -0
- package/dist/core/notFound.js.map +1 -0
- package/dist/core/result.d.ts +17 -12
- package/dist/core/result.js +5 -5
- package/dist/core/result.js.map +1 -1
- package/dist/core/retry.d.ts +5 -2
- package/dist/core/retry.js +6 -3
- package/dist/core/retry.js.map +1 -1
- package/dist/core/scope.d.ts +20 -0
- package/dist/core/scope.js +54 -0
- package/dist/core/scope.js.map +1 -0
- package/dist/flipstream.d.ts +151 -70
- package/dist/flipstream.js +67 -45
- package/dist/flipstream.js.map +1 -1
- package/dist/node/clientSecret.js +5 -5
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/headless.d.ts +14 -6
- package/dist/node/headless.js +8 -6
- package/dist/node/headless.js.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.js +27 -10
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +3 -3
- package/dist/node/keychainStore.d.ts +16 -12
- package/dist/node/keychainStore.js +50 -28
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/loopback.d.ts +8 -1
- package/dist/node/loopback.js +19 -2
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +17 -9
- package/dist/node/session.js +55 -44
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +35 -2
- package/dist/node/store.js +56 -12
- package/dist/node/store.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/admin.md +503 -0
- package/docs/node-sign-in.md +60 -35
- package/package.json +1 -1
package/dist/api/members.js
CHANGED
|
@@ -1,43 +1,71 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { invalidAnswer } from '../core/invalid.js';
|
|
3
|
+
import { notFound } from '../core/notFound.js';
|
|
2
4
|
import { RANKED, roleFromBackend } from '../core/names.js';
|
|
5
|
+
import { createdById } from './created.js';
|
|
3
6
|
import { sameUuid } from './ids.js';
|
|
7
|
+
import { instant } from './time.js';
|
|
4
8
|
const id = z.string().min(1);
|
|
5
9
|
/**
|
|
6
|
-
* pulse-auth's roles, read as one of ours
|
|
7
|
-
*
|
|
10
|
+
* pulse-auth's roles, read as ours: every one of ours held, ranked highest first, the highest as
|
|
11
|
+
* `role`, and a count of the rest (#297). Staff whatever else they hold hold none of ours (D544),
|
|
12
|
+
* and a staff role is never counted: their other names count as anyone's do, so the count never
|
|
13
|
+
* sets them apart (#335's code review, 2). A role the SDK doesn't know is none of ours, never an
|
|
8
14
|
* error, and its name is never kept (#265): a known role beside it still wins. So the staff rule
|
|
9
15
|
* covers the staff roles this version knows, godmode and swapper, which are pulse-auth's own
|
|
10
|
-
* (GODMODE_ONLY_ROLES, at 0ae57c8).
|
|
16
|
+
* (GODMODE_ONLY_ROLES, at 0ae57c8); one it doesn't know yet is counted as any unknown name is.
|
|
11
17
|
*/
|
|
12
|
-
const
|
|
18
|
+
const zRoles = z
|
|
13
19
|
.array(z.string())
|
|
14
20
|
.nullable()
|
|
15
21
|
.transform((names) => {
|
|
16
22
|
const held = new Set();
|
|
23
|
+
const others = new Set();
|
|
17
24
|
let staff = false;
|
|
18
25
|
for (const name of names ?? []) {
|
|
19
26
|
const read = roleFromBackend(name);
|
|
20
|
-
if (read.kind === 'role')
|
|
21
|
-
held.add(read.role);
|
|
22
27
|
if (read.kind === 'staff')
|
|
23
28
|
staff = true;
|
|
29
|
+
else if (read.kind === 'role')
|
|
30
|
+
held.add(read.role);
|
|
31
|
+
else
|
|
32
|
+
others.add(name);
|
|
24
33
|
}
|
|
25
|
-
|
|
34
|
+
const roles = staff ? [] : RANKED.filter((role) => held.has(role));
|
|
35
|
+
return { role: roles[0] ?? null, roles, unknown_roles: others.size };
|
|
26
36
|
});
|
|
27
37
|
// A person's fields as pulse-auth answers them. An object schema keeps only the fields it names, so
|
|
28
|
-
// `account_id`, `scope_roles`, `idp_uid
|
|
38
|
+
// `account_id`, `scope_roles`, `idp_uid` and `meta` never reach a caller, nor the backend's `roles`
|
|
39
|
+
// as it has them: only as zRoles reads them.
|
|
40
|
+
// #294: when the account was made, and by whom. pulse-auth's User holds `created_on: datetime |
|
|
41
|
+
// None` and `created_by_id: str = ""` (domain/user/__init__.py:54-55 at 0ae57c8b). The maker is read
|
|
42
|
+
// by created.ts's createdById, as a dataset's and a log entry's are. The time is read through
|
|
43
|
+
// `instant`, as every time is, but leniently: anything that isn't one is null, never invalid, since
|
|
44
|
+
// one display-only field must never fail your identity (me()), a person's logbook or a page of every
|
|
45
|
+
// member (#326's code review, 1; D563's "unknown is null"). A dataset's and a log entry's stay
|
|
46
|
+
// strict: theirs fails one record. The embedded `created_by`, `updated_on` and `updated_by_id` are
|
|
47
|
+
// never read.
|
|
48
|
+
const accountMadeOn = z
|
|
49
|
+
.unknown()
|
|
50
|
+
.optional()
|
|
51
|
+
.transform((value) => {
|
|
52
|
+
const read = instant.safeParse(value);
|
|
53
|
+
return read.success ? read.data : null;
|
|
54
|
+
});
|
|
29
55
|
const PERSON = {
|
|
30
56
|
id,
|
|
31
57
|
email: z.string(),
|
|
32
58
|
first_name: z.string(),
|
|
33
59
|
last_name: z.string(),
|
|
34
|
-
roles:
|
|
60
|
+
roles: zRoles,
|
|
35
61
|
active: z.boolean(),
|
|
36
62
|
workspace_ids: z.array(z.string()).nullable(),
|
|
63
|
+
created_on: accountMadeOn,
|
|
64
|
+
created_by_id: createdById,
|
|
37
65
|
};
|
|
38
|
-
/** A person in our names:
|
|
39
|
-
function inOurs({ roles, workspace_ids, ...person }) {
|
|
40
|
-
return { ...person,
|
|
66
|
+
/** A person in our names: their roles as read, and no workspaces read as none. */
|
|
67
|
+
function inOurs({ roles: read, workspace_ids, ...person }) {
|
|
68
|
+
return { ...person, ...read, workspace_ids: workspace_ids ?? [] };
|
|
41
69
|
}
|
|
42
70
|
/** A person, as `flipstream.me()` answers its user: pulse-auth's user, in our names. */
|
|
43
71
|
export const zMember = z.object(PERSON).transform(inOurs);
|
|
@@ -45,14 +73,22 @@ export const zMember = z.object(PERSON).transform(inOurs);
|
|
|
45
73
|
// whether they're an API user, a key, which is never a member; the public Member drops both.
|
|
46
74
|
const zRecord = z.object({ ...PERSON, organization_id: z.string(), is_api_user: z.boolean() }).transform(inOurs);
|
|
47
75
|
const zOrganizationId = z.object({ id });
|
|
48
|
-
// What get reads first of the record pulse-auth answers:
|
|
49
|
-
// rest is kept, unread, for the
|
|
50
|
-
//
|
|
51
|
-
const zWho = z.looseObject({
|
|
52
|
-
|
|
53
|
-
|
|
76
|
+
// What get reads first of the record pulse-auth answers: whether it's a key, so a record that
|
|
77
|
+
// doesn't say is invalid from the read itself. The rest is kept, unread, for the checks after it:
|
|
78
|
+
// whose the record is, then the person, by list's own schema (#367's code review, 4).
|
|
79
|
+
const zWho = z.looseObject({ is_api_user: z.boolean() });
|
|
80
|
+
// Whose the record is, read before the person, so a record that isn't yours, or isn't the one asked
|
|
81
|
+
// for, says so rather than describing its fields (#367's code review, 3).
|
|
82
|
+
const zWhose = z.object({ id, organization_id: z.string() });
|
|
83
|
+
// The record without the two fields only a check reads. PERSON is an object schema, so nothing it
|
|
84
|
+
// doesn't name is left in the rest (#326's code review, 7).
|
|
85
|
+
function publicOf(record) {
|
|
86
|
+
const { organization_id: organization, is_api_user: key, ...member } = record;
|
|
87
|
+
void [organization, key]; // read once, so the unused-variables check keeps the two it drops
|
|
88
|
+
return member;
|
|
89
|
+
}
|
|
54
90
|
// A key's id is answered exactly as pulse-auth answers an id nobody has, so it says nothing more.
|
|
55
|
-
const noSuchMember =
|
|
91
|
+
const noSuchMember = () => notFound('USER_NOT_FOUND', 'User not found!');
|
|
56
92
|
/**
|
|
57
93
|
* `flipstream.members.list()`: one page of your organisation's people, not keys, in pulse-auth's
|
|
58
94
|
* own order, by email (no sort is sent, D550). pulse-auth leaves keys out itself; one it sends all
|
|
@@ -69,34 +105,76 @@ export async function listMembers(seam, read, page) {
|
|
|
69
105
|
return listed;
|
|
70
106
|
const foreign = listed.data.items.findIndex((member) => !sameUuid(member.organization_id, organization.data.id));
|
|
71
107
|
if (foreign !== -1)
|
|
72
|
-
return
|
|
108
|
+
return invalidAnswer(`records[${String(foreign)}] is another organisation's member`);
|
|
73
109
|
const key = listed.data.items.findIndex((member) => member.is_api_user);
|
|
74
110
|
if (key !== -1)
|
|
75
|
-
return
|
|
111
|
+
return invalidAnswer(`records[${String(key)}] is an API user, not a person`);
|
|
76
112
|
return { ok: true, data: { ...listed.data, items: listed.data.items.map(publicOf) } };
|
|
77
113
|
}
|
|
78
114
|
/**
|
|
79
115
|
* `flipstream.members.get()`: one of your organisation's people, by their id. An answer that isn't
|
|
80
116
|
* the person asked for, or is another organisation's, is invalid, echoing no id; an API user's is
|
|
81
117
|
* `not_found`, as an id nobody has, whatever else its record holds. Only then is the person read.
|
|
82
|
-
*
|
|
118
|
+
* Every invalid after the read keeps the response's status, 200.
|
|
119
|
+
* The organisation's failure, then the person's, is the answer. A caller that is reading your
|
|
120
|
+
* organisation already passes that read as `organization`, so it isn't read twice (#295); otherwise
|
|
121
|
+
* it's read here, and only once the path is known to be one, so a refused call sends nothing.
|
|
83
122
|
*/
|
|
84
|
-
export async function getMember(seam, read, request) {
|
|
123
|
+
export async function getMember(seam, read, request, organization) {
|
|
85
124
|
const spec = seam.user(request.member_id, zWho);
|
|
86
125
|
if (spec === null)
|
|
87
126
|
return { ok: false, error: { kind: 'refused', reason: 'path' } };
|
|
88
|
-
const [
|
|
89
|
-
if (!
|
|
90
|
-
return
|
|
127
|
+
const [ours, who] = await Promise.all([organization ?? read(seam.myOrganization(zOrganizationId)), read(spec)]);
|
|
128
|
+
if (!ours.ok)
|
|
129
|
+
return ours;
|
|
91
130
|
if (!who.ok)
|
|
92
131
|
return who;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!
|
|
96
|
-
return
|
|
132
|
+
const whose = zWhose.safeParse(who.data);
|
|
133
|
+
// A key is not_found even when whose it is can't be read, as an id nobody has (#367's code review, 8).
|
|
134
|
+
if (!whose.success)
|
|
135
|
+
return who.data.is_api_user ? noSuchMember() : invalidAnswer(z.prettifyError(whose.error));
|
|
136
|
+
if (!sameUuid(whose.data.id, request.member_id))
|
|
137
|
+
return invalidAnswer("the member read isn't the one asked for");
|
|
138
|
+
if (!sameUuid(whose.data.organization_id, ours.data.id))
|
|
139
|
+
return invalidAnswer("the member read is another organisation's");
|
|
97
140
|
if (who.data.is_api_user)
|
|
98
|
-
return noSuchMember;
|
|
141
|
+
return noSuchMember();
|
|
99
142
|
const person = zRecord.safeParse(who.data);
|
|
100
|
-
return person.success ? { ok: true, data: publicOf(person.data) } :
|
|
143
|
+
return person.success ? { ok: true, data: publicOf(person.data) } : invalidAnswer(z.prettifyError(person.error));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The workspaces `member` opens, by D560's rule, read so it fails closed: a person whose account
|
|
147
|
+
* names workspaces opens only those, unless their role is owner, admin or editor, which no list
|
|
148
|
+
* limits. A viewer is limited, and so is a role read as none (D559: pulse-auth's client-only role,
|
|
149
|
+
* or one this version doesn't know). An account that names none opens every workspace. Not exported
|
|
150
|
+
* from the package: `heldToYou` holds a page to the caller's (#295, #342).
|
|
151
|
+
*/
|
|
152
|
+
export function workspacesOpenedBy(member) {
|
|
153
|
+
const unlimited = member.role === 'owner' || member.role === 'admin' || member.role === 'editor';
|
|
154
|
+
return unlimited || member.workspace_ids.length === 0 ? 'every' : member.workspace_ids;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Whether `you` open the workspace `workspaceId`, by `workspacesOpenedBy`'s rule (D560), the ids
|
|
158
|
+
* compared as UUIDs (sameUuid). The one check that a page held to you (`heldToYou`) and every call
|
|
159
|
+
* under one workspace (D571, #372) share, so the rule can't drift between them.
|
|
160
|
+
*/
|
|
161
|
+
export function opensWorkspace(you, workspaceId) {
|
|
162
|
+
const opens = workspacesOpenedBy(you);
|
|
163
|
+
return opens === 'every' || opens.some((id) => sameUuid(id, workspaceId));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A page's `items` held to you (D556, D560): the first of another organisation than
|
|
167
|
+
* `organizationId`, then the first in a workspace `you` don't open (`workspacesOpenedBy`), is
|
|
168
|
+
* `invalid`, naming its place and never an id, with `noun` naming what the record is. Null when every
|
|
169
|
+
* one is yours to see. None is dropped. The one check that log.list({ member_id }) (#295) and
|
|
170
|
+
* datasets.list({ organization: true }) (#342) share, so the two can't drift apart (#342's code
|
|
171
|
+
* review, 7).
|
|
172
|
+
*/
|
|
173
|
+
export function heldToYou(items, organizationId, you, noun) {
|
|
174
|
+
const foreign = items.findIndex((item) => !sameUuid(item.organization_id, organizationId));
|
|
175
|
+
if (foreign !== -1)
|
|
176
|
+
return invalidAnswer(`records[${String(foreign)}] is another organisation's ${noun}`);
|
|
177
|
+
const closed = items.findIndex((item) => !opensWorkspace(you, item.workspace_id));
|
|
178
|
+
return closed === -1 ? null : invalidAnswer(`records[${String(closed)}].workspace_id is a workspace you don't open`);
|
|
101
179
|
}
|
|
102
180
|
//# sourceMappingURL=members.js.map
|
package/dist/api/members.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"members.js","sourceRoot":"","sources":["../../src/api/members.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,MAAM,EAAE,eAAe,EAAa,MAAM,kBAAkB,CAAA;AAGrE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"members.js","sourceRoot":"","sources":["../../src/api/members.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,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cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAA;IACjF,OAAO,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,8CAA8C,CAAC,CAAA;AACtH,CAAC"}
|
package/dist/api/time.js
CHANGED
|
@@ -8,9 +8,10 @@ import { z } from 'zod';
|
|
|
8
8
|
* generated from its spec, so Catalog.generatedAt is the planner's own string. The logbook's writes
|
|
9
9
|
* read a caller's times with it too (#219): a time it refuses there is a TypeError, never sent.
|
|
10
10
|
*/
|
|
11
|
-
// An ISO 8601 date and time, as pulse-admin and pulse-
|
|
12
|
-
// UTC, or none, for the naive times pulse-admin stores, which are UTC (the console reads them
|
|
13
|
-
// too).
|
|
11
|
+
// An ISO 8601 date and time, as pulse-admin, pulse-wallet and pulse-auth write one: with an offset,
|
|
12
|
+
// `Z` for UTC, or none, for the naive times pulse-admin stores, which are UTC (the console reads them
|
|
13
|
+
// so too). pulse-auth's are aware: its recorded users carry `…Z` times with microseconds
|
|
14
|
+
// (test/recorded/auth/users.json, a member's created_on, #294).
|
|
14
15
|
const ISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|([+-])(\d{2}):(\d{2}))?$/;
|
|
15
16
|
/**
|
|
16
17
|
* `text` as an instant in UTC, `…Z` with milliseconds (finer digits are dropped), or null when it
|
package/dist/api/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/api/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;;;;GAQG;AAEH,
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/api/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAA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CAAC,CAAA;IAC9E,OAAO,CAAC,CAAC,KAAK,CAAA;AAChB,CAAC,CAAC,CAAA"}
|
package/dist/api/wallet.d.ts
CHANGED
|
@@ -37,9 +37,12 @@ export interface Ledger {
|
|
|
37
37
|
export declare function readBalance(seam: Backend, read: Read): Promise<ApiResult<Balance | null>>;
|
|
38
38
|
/**
|
|
39
39
|
* `flipstream.wallet.transactions()`: your organisation's whole ledger, in one answer, with no
|
|
40
|
-
* paging
|
|
41
|
-
*
|
|
42
|
-
* ledger is
|
|
43
|
-
* wallet's verdict, the ledger's failure.
|
|
40
|
+
* paging, or null when it has no wallet, as `readBalance` answers (#374), so no wallet is said one
|
|
41
|
+
* way across the wallet's reads. Its rows carry no wallet id, so the balance is read beside it, and
|
|
42
|
+
* the ledger is answered only when that balance is your organisation's wallet (`readOwnWallet`). The
|
|
43
|
+
* answer is the first of: the balance's failure, the wallet's verdict, the ledger's failure. No
|
|
44
|
+
* wallet is a verdict: null, whatever the ledger read did (#375's code review, 1), unless it
|
|
45
|
+
* answered rows, or an answer it can't read, which may be rows: those are invalid (#375 round 2,
|
|
46
|
+
* O2.F1).
|
|
44
47
|
*/
|
|
45
|
-
export declare function readLedger(seam: Backend, read: Read): Promise<ApiResult<Ledger>>;
|
|
48
|
+
export declare function readLedger(seam: Backend, read: Read): Promise<ApiResult<Ledger | null>>;
|
package/dist/api/wallet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { invalidAnswer } from '../core/invalid.js';
|
|
2
3
|
import { sameUuid } from './ids.js';
|
|
3
4
|
import { instant } from './time.js';
|
|
4
5
|
/*
|
|
@@ -30,7 +31,6 @@ const zTransaction = z
|
|
|
30
31
|
created_on: instant,
|
|
31
32
|
})
|
|
32
33
|
.transform(({ dataset_id, ...row }) => ({ ...row, dataset_id: dataset_id === '' || dataset_id === null ? null : dataset_id }));
|
|
33
|
-
const invalid = (issues) => ({ ok: false, error: { kind: 'invalid', issues } });
|
|
34
34
|
/** Your organisation's id, read every time, with no cache: the wallet's id is the organisation's. */
|
|
35
35
|
async function organizationId(seam, read) {
|
|
36
36
|
const organization = await read(seam.myOrganization(zOrganizationId));
|
|
@@ -44,12 +44,26 @@ async function organizationId(seam, read) {
|
|
|
44
44
|
*/
|
|
45
45
|
function ownWallet(rows, organization) {
|
|
46
46
|
if (rows.some((row) => !sameUuid(row.wallet_id, organization)))
|
|
47
|
-
return
|
|
47
|
+
return invalidAnswer("a balance row is another wallet's");
|
|
48
48
|
const [row, ...more] = rows;
|
|
49
49
|
if (more.length > 0)
|
|
50
|
-
return
|
|
50
|
+
return invalidAnswer('more than one wallet for the organisation');
|
|
51
51
|
return { ok: true, data: row ?? null };
|
|
52
52
|
}
|
|
53
|
+
const UNNAMED = "the organisation's id can't name its wallet";
|
|
54
|
+
/**
|
|
55
|
+
* Whether your organisation has a wallet, decided in this one place for both reads (#375's code
|
|
56
|
+
* review, 5): its balance rows, read and held to `organization` by `ownWallet`, so a row is your
|
|
57
|
+
* wallet and null is none. The first of: the balance's failure, the wallet's verdict. `organization`
|
|
58
|
+
* is your organisation's id, read by the caller, so the ledger can be read beside the balance.
|
|
59
|
+
*/
|
|
60
|
+
async function readOwnWallet(seam, read, organization) {
|
|
61
|
+
const spec = seam.balanceOf(organization, zBalanceRow);
|
|
62
|
+
if (spec === null)
|
|
63
|
+
return invalidAnswer(UNNAMED);
|
|
64
|
+
const rows = await read(spec);
|
|
65
|
+
return rows.ok ? ownWallet(rows.data, organization) : rows;
|
|
66
|
+
}
|
|
53
67
|
/**
|
|
54
68
|
* `flipstream.wallet.balance()`: your organisation's balance, or null when it has no wallet. No
|
|
55
69
|
* wallet is a real state, not a fault, so it isn't `invalid`, and it isn't €0.00 either: a zero
|
|
@@ -59,44 +73,42 @@ export async function readBalance(seam, read) {
|
|
|
59
73
|
const organization = await organizationId(seam, read);
|
|
60
74
|
if (!organization.ok)
|
|
61
75
|
return organization;
|
|
62
|
-
const
|
|
63
|
-
if (spec === null)
|
|
64
|
-
return invalid("the organisation's id can't name its wallet");
|
|
65
|
-
const rows = await read(spec);
|
|
66
|
-
if (!rows.ok)
|
|
67
|
-
return rows;
|
|
68
|
-
const wallet = ownWallet(rows.data, organization.data);
|
|
76
|
+
const wallet = await readOwnWallet(seam, read, organization.data);
|
|
69
77
|
if (!wallet.ok)
|
|
70
78
|
return wallet;
|
|
71
79
|
return { ok: true, data: wallet.data === null ? null : { balance_micro: wallet.data.balance_micro, micro_per_euro: MICRO_PER_EURO } };
|
|
72
80
|
}
|
|
73
81
|
/**
|
|
74
82
|
* `flipstream.wallet.transactions()`: your organisation's whole ledger, in one answer, with no
|
|
75
|
-
* paging
|
|
76
|
-
*
|
|
77
|
-
* ledger is
|
|
78
|
-
* wallet's verdict, the ledger's failure.
|
|
83
|
+
* paging, or null when it has no wallet, as `readBalance` answers (#374), so no wallet is said one
|
|
84
|
+
* way across the wallet's reads. Its rows carry no wallet id, so the balance is read beside it, and
|
|
85
|
+
* the ledger is answered only when that balance is your organisation's wallet (`readOwnWallet`). The
|
|
86
|
+
* answer is the first of: the balance's failure, the wallet's verdict, the ledger's failure. No
|
|
87
|
+
* wallet is a verdict: null, whatever the ledger read did (#375's code review, 1), unless it
|
|
88
|
+
* answered rows, or an answer it can't read, which may be rows: those are invalid (#375 round 2,
|
|
89
|
+
* O2.F1).
|
|
79
90
|
*/
|
|
80
91
|
export async function readLedger(seam, read) {
|
|
81
92
|
const organization = await organizationId(seam, read);
|
|
82
93
|
if (!organization.ok)
|
|
83
94
|
return organization;
|
|
84
|
-
|
|
95
|
+
// Checked before either read is sent. The balance's path takes the same id, so once the
|
|
96
|
+
// ledger's can name it, so can the balance's, and readOwnWallet never refuses after this.
|
|
85
97
|
const ledgerSpec = seam.ledgerOf(organization.data, zTransaction);
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
88
|
-
const [
|
|
89
|
-
if (!balance.ok)
|
|
90
|
-
return balance;
|
|
98
|
+
if (ledgerSpec === null)
|
|
99
|
+
return invalidAnswer(UNNAMED);
|
|
100
|
+
const [wallet, ledger] = await Promise.all([readOwnWallet(seam, read, organization.data), read(ledgerSpec)]);
|
|
91
101
|
// The wallet's verdict comes from the balance, so it comes before the ledger's own failure: a
|
|
92
|
-
// caller never retries a ledger of a wallet that isn't theirs.
|
|
93
|
-
const wallet = ownWallet(balance.data, organization.data);
|
|
102
|
+
// caller never retries a ledger of a wallet that isn't theirs, nor of no wallet.
|
|
94
103
|
if (!wallet.ok)
|
|
95
104
|
return wallet;
|
|
105
|
+
if (wallet.data === null) {
|
|
106
|
+
if (!ledger.ok)
|
|
107
|
+
return ledger.error.kind === 'invalid' ? ledger : { ok: true, data: null };
|
|
108
|
+
return ledger.data.length > 0 ? invalidAnswer('ledger rows for an organisation with no wallet') : { ok: true, data: null };
|
|
109
|
+
}
|
|
96
110
|
if (!ledger.ok)
|
|
97
111
|
return ledger;
|
|
98
|
-
if (wallet.data === null && ledger.data.length > 0)
|
|
99
|
-
return invalid('ledger rows for an organisation with no wallet');
|
|
100
112
|
return { ok: true, data: { items: ledger.data, micro_per_euro: MICRO_PER_EURO } };
|
|
101
113
|
}
|
|
102
114
|
//# sourceMappingURL=wallet.js.map
|
package/dist/api/wallet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AAEH;;;;GAIG;AAC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AK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAC1F,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,gDAAgD,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IAC5H,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,EAAE,CAAA;AACnF,CAAC"}
|
package/dist/api/workspaces.d.ts
CHANGED
|
@@ -2,20 +2,34 @@ import { z } from 'zod';
|
|
|
2
2
|
import type { ApiResult } from '../core/result.js';
|
|
3
3
|
import type { Backend } from './backend.js';
|
|
4
4
|
import { type WorkspaceHandOff } from './handoff.js';
|
|
5
|
-
import type
|
|
5
|
+
import { type Read } from './me.js';
|
|
6
6
|
import { type Page, type PageRequest } from './page.js';
|
|
7
|
+
/**
|
|
8
|
+
* Which services are on in a workspace (#291, os D94), as the console reads its `meta.cloud`:
|
|
9
|
+
* `known`, with the keys of the services that are on, as the backend stores them; or `unreadable`,
|
|
10
|
+
* when its `meta` can't be read, so the services are neither on nor off.
|
|
11
|
+
*/
|
|
12
|
+
export type WorkspaceServices = {
|
|
13
|
+
readonly status: 'known';
|
|
14
|
+
readonly on: readonly string[];
|
|
15
|
+
} | {
|
|
16
|
+
readonly status: 'unreadable';
|
|
17
|
+
};
|
|
7
18
|
/** A workspace in your organisation (#208): a customer's client, in the backend's names. */
|
|
8
19
|
export interface Workspace {
|
|
9
20
|
readonly id: string;
|
|
10
21
|
readonly name: string;
|
|
11
22
|
/** Its short name, as the console's addresses spell it. */
|
|
12
23
|
readonly slug: string;
|
|
24
|
+
/** Which services are on in it (#291): see `WorkspaceServices`. */
|
|
25
|
+
readonly services: WorkspaceServices;
|
|
13
26
|
}
|
|
14
27
|
declare const zRecord: z.ZodObject<{
|
|
15
28
|
id: z.ZodString;
|
|
16
29
|
name: z.ZodString;
|
|
17
30
|
slug: z.ZodString;
|
|
18
31
|
organization_id: z.ZodString;
|
|
32
|
+
meta: z.ZodOptional<z.ZodUnknown>;
|
|
19
33
|
}, z.core.$strip>;
|
|
20
34
|
type WorkspaceRecord = z.output<typeof zRecord>;
|
|
21
35
|
/**
|
|
@@ -46,11 +60,8 @@ export declare function createWorkspace(seam: Backend, send: Read, request: {
|
|
|
46
60
|
readonly name: string;
|
|
47
61
|
}): Promise<ApiResult<Workspace>>;
|
|
48
62
|
/**
|
|
49
|
-
* One of your organisation's workspaces,
|
|
50
|
-
*
|
|
51
|
-
* the workspace asked for. The organisation's failure, then the workspace's, is the answer. A read
|
|
52
|
-
* under a workspace uses it too, so the workspace itself is proved, never only its records (D556,
|
|
53
|
-
* as amended): pulse-admin answers an empty list for any workspace id.
|
|
63
|
+
* One of your organisation's workspaces, as `readOwnWorkspaceWith` reads it, with nothing beside it:
|
|
64
|
+
* for a call that reads or writes only after its workspace is proved.
|
|
54
65
|
*/
|
|
55
66
|
export declare function readOwnWorkspace<O extends {
|
|
56
67
|
readonly id: string;
|
|
@@ -58,12 +69,36 @@ export declare function readOwnWorkspace<O extends {
|
|
|
58
69
|
readonly organization: O;
|
|
59
70
|
readonly workspace: WorkspaceRecord;
|
|
60
71
|
}>>;
|
|
72
|
+
/**
|
|
73
|
+
* One of your organisation's workspaces, and `alongside`'s answer, read once you're known to open
|
|
74
|
+
* it. Every call under one workspace known up front uses it (D556, as amended; D571), so the
|
|
75
|
+
* workspace itself is proved, never only its records: pulse-admin answers an empty list for any
|
|
76
|
+
* workspace id, and doesn't hold a limited member to their workspaces on every route.
|
|
77
|
+
* - **First, your organisation and you** (`readUser`), side by side. A workspace you don't open
|
|
78
|
+
* (`opensWorkspace`, D560) is then `not_found`, exactly as one nobody has, before anything under
|
|
79
|
+
* it is sent: no workspace read and no `alongside`, so its records, a dataset's embedded sign-in
|
|
80
|
+
* among them, are never fetched, and a refusal of them can't tell it apart (#373's code review, 3
|
|
81
|
+
* and 4).
|
|
82
|
+
* - **Then the workspace and `alongside`** (a list under it), side by side. A workspace of another
|
|
83
|
+
* organisation is invalid, as a staff token could otherwise reach it, and so is an answer that
|
|
84
|
+
* isn't the workspace asked for.
|
|
85
|
+
* The organisation's failure, then yours, then the workspace's, is the answer; `alongside`'s answer
|
|
86
|
+
* comes back as it is, for the caller to read after.
|
|
87
|
+
*/
|
|
88
|
+
export declare function readOwnWorkspaceWith<O extends {
|
|
89
|
+
readonly id: string;
|
|
90
|
+
}, A>(seam: Backend, read: Read, workspaceId: string, organizationSchema: z.ZodType<O>, alongside: () => Promise<A>): Promise<ApiResult<{
|
|
91
|
+
readonly organization: O;
|
|
92
|
+
readonly workspace: WorkspaceRecord;
|
|
93
|
+
readonly alongside: A;
|
|
94
|
+
}>>;
|
|
61
95
|
/** `flipstream.workspaces.get()`: one workspace, by `readOwnWorkspace`'s rules. */
|
|
62
96
|
export declare function readWorkspace(seam: Backend, read: Read, workspaceId: string): Promise<ApiResult<Workspace>>;
|
|
63
97
|
/**
|
|
64
98
|
* `flipstream.workspaces.rename()` and `delete()`: a person's to do in the console (D542), so they
|
|
65
99
|
* answer `needs_person` and never write. The workspace is read first, by `readOwnWorkspace`'s
|
|
66
|
-
* rules, so one that isn't yours is `not_found` or `invalid`, never
|
|
100
|
+
* rules, so one that isn't yours, or that you don't open, is `not_found` or `invalid`, never
|
|
101
|
+
* handed off. The address names
|
|
67
102
|
* the organisation's short name and the workspace's canonical id, as the backend answered it.
|
|
68
103
|
*/
|
|
69
104
|
export declare function handOffWorkspace(seam: Backend, read: Read, workspaceId: string, action: WorkspaceHandOff): Promise<ApiResult<never>>;
|