@flipstream/sdk 0.11.0 → 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 +48 -0
- package/README.md +97 -412
- package/dist/api/backend.d.ts +10 -0
- package/dist/api/backend.js +24 -4
- package/dist/api/backend.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 +82 -14
- package/dist/api/datasets.js +193 -57
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/log.d.ts +25 -20
- package/dist/api/log.js +63 -48
- package/dist/api/log.js.map +1 -1
- package/dist/api/me.js +7 -4
- package/dist/api/me.js.map +1 -1
- package/dist/api/members.d.ts +34 -1
- package/dist/api/members.js +67 -27
- package/dist/api/members.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 +28 -7
- package/dist/api/workspaces.js +46 -16
- 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 +13 -2
- package/dist/core/names.js +11 -2
- 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 +136 -69
- 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 +26 -14
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +3 -3
- package/dist/node/keychainStore.d.ts +10 -7
- package/dist/node/keychainStore.js +44 -23
- 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 -38
- package/package.json +1 -1
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,O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QACzB,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,OAAO,MAAM,CAAC,KAAK,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,7 +2,7 @@ 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
7
|
/**
|
|
8
8
|
* Which services are on in a workspace (#291, os D94), as the console reads its `meta.cloud`:
|
|
@@ -60,11 +60,8 @@ export declare function createWorkspace(seam: Backend, send: Read, request: {
|
|
|
60
60
|
readonly name: string;
|
|
61
61
|
}): Promise<ApiResult<Workspace>>;
|
|
62
62
|
/**
|
|
63
|
-
* One of your organisation's workspaces,
|
|
64
|
-
*
|
|
65
|
-
* the workspace asked for. The organisation's failure, then the workspace's, is the answer. A read
|
|
66
|
-
* under a workspace uses it too, so the workspace itself is proved, never only its records (D556,
|
|
67
|
-
* 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.
|
|
68
65
|
*/
|
|
69
66
|
export declare function readOwnWorkspace<O extends {
|
|
70
67
|
readonly id: string;
|
|
@@ -72,12 +69,36 @@ export declare function readOwnWorkspace<O extends {
|
|
|
72
69
|
readonly organization: O;
|
|
73
70
|
readonly workspace: WorkspaceRecord;
|
|
74
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
|
+
}>>;
|
|
75
95
|
/** `flipstream.workspaces.get()`: one workspace, by `readOwnWorkspace`'s rules. */
|
|
76
96
|
export declare function readWorkspace(seam: Backend, read: Read, workspaceId: string): Promise<ApiResult<Workspace>>;
|
|
77
97
|
/**
|
|
78
98
|
* `flipstream.workspaces.rename()` and `delete()`: a person's to do in the console (D542), so they
|
|
79
99
|
* answer `needs_person` and never write. The workspace is read first, by `readOwnWorkspace`'s
|
|
80
|
-
* 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
|
|
81
102
|
* the organisation's short name and the workspace's canonical id, as the backend answered it.
|
|
82
103
|
*/
|
|
83
104
|
export declare function handOffWorkspace(seam: Backend, read: Read, workspaceId: string, action: WorkspaceHandOff): Promise<ApiResult<never>>;
|
package/dist/api/workspaces.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { parseJson } from '../core/body.js';
|
|
3
|
+
import { invalidAnswer, invalidStatusUnknown } from '../core/invalid.js';
|
|
4
|
+
import { notFound } from '../core/notFound.js';
|
|
3
5
|
import { needsPerson, zHandOffOrganization } from './handoff.js';
|
|
4
6
|
import { sameUuid } from './ids.js';
|
|
7
|
+
import { readUser } from './me.js';
|
|
8
|
+
import { opensWorkspace } from './members.js';
|
|
5
9
|
import { pageQuery } from './page.js';
|
|
6
10
|
import { unsent } from './unsent.js';
|
|
7
11
|
const id = z.string().min(1);
|
|
@@ -40,7 +44,6 @@ function servicesOf(meta = '') {
|
|
|
40
44
|
const zRecord = z.object({ id, name: z.string(), slug: z.string(), organization_id: id, meta: z.unknown().optional() });
|
|
41
45
|
const zOrganizationId = z.object({ id });
|
|
42
46
|
const publicOf = ({ id: workspaceId, name, slug, meta }) => ({ id: workspaceId, name, slug, services: servicesOf(meta) });
|
|
43
|
-
const invalid = (issues) => ({ ok: false, error: { kind: 'invalid', issues } });
|
|
44
47
|
/**
|
|
45
48
|
* `flipstream.workspaces.list()`: one page of your organisation's workspaces. Your organisation is
|
|
46
49
|
* read first, every time, with no cache, for its id. A workspace of another organisation makes the
|
|
@@ -57,9 +60,9 @@ export async function readWorkspaces(seam, read, page) {
|
|
|
57
60
|
if (!organization.ok)
|
|
58
61
|
return organization;
|
|
59
62
|
const ours = organization.data.id;
|
|
60
|
-
const spec = seam.workspacesOf(ours, sent, zRecord, (workspace) => workspace.organization_id
|
|
63
|
+
const spec = seam.workspacesOf(ours, sent, zRecord, (workspace) => sameUuid(workspace.organization_id, ours));
|
|
61
64
|
if (spec === null)
|
|
62
|
-
return
|
|
65
|
+
return invalidAnswer("the organisation's id can't name its workspaces");
|
|
63
66
|
const listed = await read(spec);
|
|
64
67
|
return listed.ok ? { ok: true, data: { ...listed.data, items: listed.data.items.map(publicOf) } } : listed;
|
|
65
68
|
}
|
|
@@ -90,33 +93,59 @@ export async function createWorkspace(seam, send, request) {
|
|
|
90
93
|
if (!made.ok)
|
|
91
94
|
return made;
|
|
92
95
|
if (!sameUuid(made.data.organization_id, organization.data.id))
|
|
93
|
-
return
|
|
96
|
+
return invalidStatusUnknown("the workspace made is another organisation's");
|
|
94
97
|
return { ok: true, data: publicOf(made.data) };
|
|
95
98
|
}
|
|
99
|
+
// pulse-admin's own 404 for a workspace nobody has, as recorded (test/recorded/admin/error-404.json;
|
|
100
|
+
// dff6bf9b, domain/client/__init__.py:122-129): a workspace you don't open answers exactly this, so it
|
|
101
|
+
// says no more than one nobody has (D571, #372).
|
|
102
|
+
const noSuchWorkspace = () => notFound('CLIENT_NOT_FOUND', 'Client not found!');
|
|
96
103
|
/**
|
|
97
|
-
* One of your organisation's workspaces,
|
|
98
|
-
*
|
|
99
|
-
* the workspace asked for. The organisation's failure, then the workspace's, is the answer. A read
|
|
100
|
-
* under a workspace uses it too, so the workspace itself is proved, never only its records (D556,
|
|
101
|
-
* as amended): pulse-admin answers an empty list for any workspace id.
|
|
104
|
+
* One of your organisation's workspaces, as `readOwnWorkspaceWith` reads it, with nothing beside it:
|
|
105
|
+
* for a call that reads or writes only after its workspace is proved.
|
|
102
106
|
*/
|
|
103
107
|
export async function readOwnWorkspace(seam, read, workspaceId, organizationSchema) {
|
|
108
|
+
const own = await readOwnWorkspaceWith(seam, read, workspaceId, organizationSchema, () => Promise.resolve(null));
|
|
109
|
+
return own.ok ? { ok: true, data: { organization: own.data.organization, workspace: own.data.workspace } } : own;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* One of your organisation's workspaces, and `alongside`'s answer, read once you're known to open
|
|
113
|
+
* it. Every call under one workspace known up front uses it (D556, as amended; D571), so the
|
|
114
|
+
* workspace itself is proved, never only its records: pulse-admin answers an empty list for any
|
|
115
|
+
* workspace id, and doesn't hold a limited member to their workspaces on every route.
|
|
116
|
+
* - **First, your organisation and you** (`readUser`), side by side. A workspace you don't open
|
|
117
|
+
* (`opensWorkspace`, D560) is then `not_found`, exactly as one nobody has, before anything under
|
|
118
|
+
* it is sent: no workspace read and no `alongside`, so its records, a dataset's embedded sign-in
|
|
119
|
+
* among them, are never fetched, and a refusal of them can't tell it apart (#373's code review, 3
|
|
120
|
+
* and 4).
|
|
121
|
+
* - **Then the workspace and `alongside`** (a list under it), side by side. A workspace of another
|
|
122
|
+
* organisation is invalid, as a staff token could otherwise reach it, and so is an answer that
|
|
123
|
+
* isn't the workspace asked for.
|
|
124
|
+
* The organisation's failure, then yours, then the workspace's, is the answer; `alongside`'s answer
|
|
125
|
+
* comes back as it is, for the caller to read after.
|
|
126
|
+
*/
|
|
127
|
+
export async function readOwnWorkspaceWith(seam, read, workspaceId, organizationSchema, alongside) {
|
|
104
128
|
const spec = seam.workspace(workspaceId, zRecord);
|
|
105
129
|
if (spec === null)
|
|
106
130
|
return { ok: false, error: { kind: 'refused', reason: 'path' } };
|
|
107
|
-
const [organization,
|
|
131
|
+
const [organization, you] = await Promise.all([read(seam.myOrganization(organizationSchema)), readUser(seam, read)]);
|
|
108
132
|
if (!organization.ok)
|
|
109
133
|
return organization;
|
|
134
|
+
if (!you.ok)
|
|
135
|
+
return you;
|
|
136
|
+
if (!opensWorkspace(you.data, workspaceId))
|
|
137
|
+
return noSuchWorkspace();
|
|
138
|
+
const [workspace, beside] = await Promise.all([read(spec), alongside()]);
|
|
110
139
|
if (!workspace.ok)
|
|
111
140
|
return workspace;
|
|
112
141
|
// Another workspace than the one asked for is never answered as it, as me() holds its user to
|
|
113
142
|
// userinfo's sub; neither id is echoed. The caller's id may be any form pulse-admin reads as the
|
|
114
|
-
// same UUID (sameUuid).
|
|
143
|
+
// same UUID (sameUuid), and so may the organisation's id the workspace names (#363).
|
|
115
144
|
if (!sameUuid(workspace.data.id, workspaceId))
|
|
116
|
-
return
|
|
117
|
-
if (workspace.data.organization_id
|
|
118
|
-
return
|
|
119
|
-
return { ok: true, data: { organization: organization.data, workspace: workspace.data } };
|
|
145
|
+
return invalidAnswer("the workspace read isn't the one asked for");
|
|
146
|
+
if (!sameUuid(workspace.data.organization_id, organization.data.id))
|
|
147
|
+
return invalidAnswer("the workspace read is another organisation's");
|
|
148
|
+
return { ok: true, data: { organization: organization.data, workspace: workspace.data, alongside: beside } };
|
|
120
149
|
}
|
|
121
150
|
/** `flipstream.workspaces.get()`: one workspace, by `readOwnWorkspace`'s rules. */
|
|
122
151
|
export async function readWorkspace(seam, read, workspaceId) {
|
|
@@ -126,7 +155,8 @@ export async function readWorkspace(seam, read, workspaceId) {
|
|
|
126
155
|
/**
|
|
127
156
|
* `flipstream.workspaces.rename()` and `delete()`: a person's to do in the console (D542), so they
|
|
128
157
|
* answer `needs_person` and never write. The workspace is read first, by `readOwnWorkspace`'s
|
|
129
|
-
* rules, so one that isn't yours is `not_found` or `invalid`, never
|
|
158
|
+
* rules, so one that isn't yours, or that you don't open, is `not_found` or `invalid`, never
|
|
159
|
+
* handed off. The address names
|
|
130
160
|
* the organisation's short name and the workspace's canonical id, as the backend answered it.
|
|
131
161
|
*/
|
|
132
162
|
export async function handOffWorkspace(seam, read, workspaceId, action) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/api/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/api/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAG9C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAyB,MAAM,cAAc,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAa,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAmBpC,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAE5B,mGAAmG;AACnG,oGAAoG;AACpG,gGAAgG;AAChG,8FAA8F;AAC9F,MAAM,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AAE/G;;;;;GAK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,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAa,EAAE,IAAU,EAAE,WAAmB,EAAE,MAAwB;IAC7G,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,oBAAoB,CAAC,CAAA;IACjF,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,OAAO,GAAG,CAAA;IACvB,OAAO,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAA;AACvG,CAAC"}
|
package/dist/auth/discovery.d.ts
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import type { ApiResult } from '../core/result.js';
|
|
2
2
|
import { type AuthCallOptions } from './transport.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* What sign-in needs from an authorization server's metadata (RFC 8414), and nothing more, in the
|
|
5
|
+
* metadata's own names (#353, D569).
|
|
6
|
+
*/
|
|
4
7
|
export interface AuthServer {
|
|
5
8
|
/** The issuer as its metadata names it: what a redirect's `iss` must equal (RFC 9207). */
|
|
6
9
|
readonly issuer: string;
|
|
7
10
|
/** Where the person is sent to sign in. */
|
|
8
|
-
readonly
|
|
11
|
+
readonly authorization_endpoint: string;
|
|
9
12
|
/** Where the code is exchanged for tokens. */
|
|
10
|
-
readonly
|
|
13
|
+
readonly token_endpoint: string;
|
|
11
14
|
/** Where a session is ended (RFC 7009), when the server has one. */
|
|
12
|
-
readonly
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
+
readonly revocation_endpoint?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The server puts `iss` on every redirect (RFC 9207), so a redirect without one is refused. False
|
|
18
|
+
* when its metadata doesn't say so.
|
|
19
|
+
*/
|
|
20
|
+
readonly authorization_response_iss_parameter_supported: boolean;
|
|
15
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* What a `server` given in place of discovery lacks, as `server.<field>` with what it must be, or
|
|
24
|
+
* null when it's an AuthServer's shape (#355's code review, 3): a discover() answer an app kept
|
|
25
|
+
* from a release before the snake rename (D569) holds camelCase names, and would otherwise be used
|
|
26
|
+
* as a server with no endpoints. Its values are checked where they're used.
|
|
27
|
+
*/
|
|
28
|
+
export declare function serverProblem(server: unknown): string | null;
|
|
16
29
|
/**
|
|
17
30
|
* The authorization server at `issuer`, from its RFC 8414 metadata. `refused`, with nothing sent,
|
|
18
31
|
* when `issuer` isn't an https URL, or with `allowLocalhostHttp`, an http one on this machine.
|
package/dist/auth/discovery.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
3
|
import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
|
|
4
|
+
/**
|
|
5
|
+
* What a `server` given in place of discovery lacks, as `server.<field>` with what it must be, or
|
|
6
|
+
* null when it's an AuthServer's shape (#355's code review, 3): a discover() answer an app kept
|
|
7
|
+
* from a release before the snake rename (D569) holds camelCase names, and would otherwise be used
|
|
8
|
+
* as a server with no endpoints. Its values are checked where they're used.
|
|
9
|
+
*/
|
|
10
|
+
export function serverProblem(server) {
|
|
11
|
+
if (typeof server !== 'object' || server === null)
|
|
12
|
+
return 'server must be discover()\'s answer';
|
|
13
|
+
const field = (name) => (Object.hasOwn(server, name) ? Reflect.get(server, name) : undefined);
|
|
14
|
+
for (const name of ['issuer', 'authorization_endpoint', 'token_endpoint']) {
|
|
15
|
+
if (typeof field(name) !== 'string')
|
|
16
|
+
return `server.${name} must be a string`;
|
|
17
|
+
}
|
|
18
|
+
const revocation = field('revocation_endpoint');
|
|
19
|
+
if (revocation !== undefined && typeof revocation !== 'string')
|
|
20
|
+
return 'server.revocation_endpoint must be a string, or left out';
|
|
21
|
+
if (typeof field('authorization_response_iss_parameter_supported') !== 'boolean')
|
|
22
|
+
return 'server.authorization_response_iss_parameter_supported must be a boolean';
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
4
25
|
// Unknown fields are kept and never read: `first_party_client_id` among them, which the SDK never
|
|
5
26
|
// uses in place of the app's own client ID (D421).
|
|
6
27
|
const zMetadata = z.looseObject({
|
|
@@ -41,10 +62,10 @@ export async function discover(issuer, options = {}) {
|
|
|
41
62
|
ok: true,
|
|
42
63
|
data: {
|
|
43
64
|
issuer: doc.issuer,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
...(doc.revocation_endpoint === undefined ? {} : {
|
|
47
|
-
|
|
65
|
+
authorization_endpoint: doc.authorization_endpoint,
|
|
66
|
+
token_endpoint: doc.token_endpoint,
|
|
67
|
+
...(doc.revocation_endpoint === undefined ? {} : { revocation_endpoint: doc.revocation_endpoint }),
|
|
68
|
+
authorization_response_iss_parameter_supported: doc.authorization_response_iss_parameter_supported === true,
|
|
48
69
|
},
|
|
49
70
|
};
|
|
50
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAwB,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE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AAoC,CAAA;IAChH,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/auth/signIn.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ApiError } from '../core/result.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type AuthServer } from './discovery.js';
|
|
3
3
|
import { type AuthCallOptions } from './transport.js';
|
|
4
4
|
/** What `startSignIn` takes. */
|
|
5
5
|
export interface SignInRequest {
|
|
@@ -14,30 +14,32 @@ export interface SignInRequest {
|
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* What finishing needs, held by the app between the two halves: only strings and a flag, so it
|
|
17
|
-
* survives a page load in the app's own storage. The verifier is a secret: never log it.
|
|
17
|
+
* survives a page load in the app's own storage. The verifier is a secret: never log it. Its
|
|
18
|
+
* fields are snake_case since the snake rename (#353, D569): a pending that a release before it
|
|
19
|
+
* made isn't one, so `finishSignIn` refuses it, and the person starts the sign-in again.
|
|
18
20
|
*/
|
|
19
21
|
export interface PendingSignIn {
|
|
20
22
|
/** What the redirect must carry back (CSRF). */
|
|
21
23
|
readonly state: string;
|
|
22
24
|
/** The PKCE code verifier: the secret the code is exchanged with. */
|
|
23
25
|
readonly verifier: string;
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
26
|
+
readonly client_id: string;
|
|
27
|
+
readonly redirect_uri: string;
|
|
26
28
|
/** The scopes asked for, space-separated (RFC 6749 §3.3). */
|
|
27
29
|
readonly scope: string;
|
|
28
|
-
/** The server's issuer, its token endpoint, and whether it puts `iss` on every redirect. */
|
|
30
|
+
/** The server's issuer, its token endpoint, and whether it puts `iss` on every redirect (RFC 9207). */
|
|
29
31
|
readonly issuer: string;
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
32
|
+
readonly token_endpoint: string;
|
|
33
|
+
readonly authorization_response_iss_parameter_supported: boolean;
|
|
32
34
|
}
|
|
33
|
-
/** What a sign-in gives. The app stores them; the SDK keeps no copy. */
|
|
35
|
+
/** What a sign-in gives, in snake_case (#353, D569). The app stores them; the SDK keeps no copy. */
|
|
34
36
|
export interface Tokens {
|
|
35
37
|
/** For the transport's token function: never log it. */
|
|
36
|
-
readonly
|
|
38
|
+
readonly access_token: string;
|
|
37
39
|
/** Absent when the server issued none. */
|
|
38
|
-
readonly
|
|
40
|
+
readonly refresh_token?: string;
|
|
39
41
|
/** When the access token expires, in ms since the epoch; absent when the server didn't say. */
|
|
40
|
-
readonly
|
|
42
|
+
readonly expires_at?: number;
|
|
41
43
|
/** The scopes granted, space-separated. */
|
|
42
44
|
readonly scope: string;
|
|
43
45
|
}
|
|
@@ -73,8 +75,9 @@ export type SignInResult = {
|
|
|
73
75
|
};
|
|
74
76
|
/**
|
|
75
77
|
* The URL to send the person to, and what finishing will need. Rejects with a TypeError, before
|
|
76
|
-
* anything is made, when the client ID is missing or empty, the redirect URI isn't absolute,
|
|
77
|
-
*
|
|
78
|
+
* anything is made, when the client ID is missing or empty, the redirect URI isn't absolute, the
|
|
79
|
+
* scopes are empty or one holds a space, or `server` isn't discover()'s answer in its snake_case
|
|
80
|
+
* names, naming the field it lacks: from TypeScript, none of these compiles. Always S256;
|
|
78
81
|
* no `resource` is sent, since the hosts share one audience.
|
|
79
82
|
*/
|
|
80
83
|
export declare function startSignIn(request: SignInRequest): Promise<{
|
|
@@ -94,7 +97,8 @@ export declare const isPendingSignIn: (value: unknown) => value is PendingSignIn
|
|
|
94
97
|
/**
|
|
95
98
|
* Finishes a sign-in: the redirect is read (`readCallback`), and only then is its code exchanged
|
|
96
99
|
* for tokens, once (`tokenCall`). A `pending` that isn't one (from
|
|
97
|
-
* storage the app couldn't read back
|
|
100
|
+
* storage the app couldn't read back, or one an earlier version made, in camelCase) is `refused`,
|
|
101
|
+
* with nothing sent. A public client's: an app
|
|
98
102
|
* with a server signs in as a confidential client with `@flipstream/sdk/node`'s `finishSignIn`.
|
|
99
103
|
*/
|
|
100
104
|
export declare function finishSignIn(callbackUrl: string | URL, pending: PendingSignIn, options?: AuthCallOptions): Promise<SignInResult>;
|