@flipstream/sdk 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +48 -20
- package/dist/api/backend.d.ts +7 -0
- package/dist/api/backend.js +7 -0
- 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.js +30 -50
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/handoff.d.ts +1 -1
- package/dist/api/handoff.js +7 -0
- package/dist/api/handoff.js.map +1 -1
- package/dist/api/log.d.ts +4 -4
- package/dist/api/log.js +23 -42
- package/dist/api/log.js.map +1 -1
- package/dist/api/me.d.ts +5 -3
- package/dist/api/me.js +3 -3
- package/dist/api/me.js.map +1 -1
- package/dist/api/members.d.ts +40 -17
- package/dist/api/members.js +66 -29
- package/dist/api/members.js.map +1 -1
- package/dist/api/ownRecord.d.ts +46 -0
- package/dist/api/ownRecord.js +57 -0
- package/dist/api/ownRecord.js.map +1 -0
- package/dist/api/refusal.d.ts +14 -0
- package/dist/api/refusal.js +23 -0
- package/dist/api/refusal.js.map +1 -0
- package/dist/api/wallet.d.ts +2 -1
- package/dist/api/wallet.js +18 -24
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +7 -2
- package/dist/api/workspaces.js +14 -8
- package/dist/api/workspaces.js.map +1 -1
- package/dist/auth/discovery.js +4 -5
- package/dist/auth/discovery.js.map +1 -1
- package/dist/core/call.d.ts +5 -4
- package/dist/core/call.js +5 -7
- package/dist/core/call.js.map +1 -1
- package/dist/core/identify.d.ts +6 -0
- package/dist/core/identify.js +15 -7
- package/dist/core/identify.js.map +1 -1
- package/dist/core/inPlaceOf.d.ts +6 -0
- package/dist/core/inPlaceOf.js +17 -0
- package/dist/core/inPlaceOf.js.map +1 -0
- package/dist/core/invalid.d.ts +32 -9
- package/dist/core/invalid.js +36 -23
- package/dist/core/invalid.js.map +1 -1
- package/dist/core/notFound.d.ts +2 -2
- package/dist/core/notFound.js.map +1 -1
- package/dist/core/read.d.ts +4 -10
- package/dist/core/read.js +1 -11
- package/dist/core/read.js.map +1 -1
- package/dist/core/result.d.ts +13 -9
- package/dist/core/result.js +1 -0
- package/dist/core/result.js.map +1 -1
- package/dist/core/shared.d.ts +13 -9
- package/dist/core/shared.js +7 -6
- package/dist/core/shared.js.map +1 -1
- package/dist/flipstream.d.ts +81 -27
- package/dist/flipstream.js +37 -26
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/node/keychainChild.js +60 -25
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +4 -1
- package/dist/node/keychainError.js.map +1 -1
- package/dist/node/keychainStore.js +42 -8
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/session.js +6 -7
- package/dist/node/session.js.map +1 -1
- package/dist/query/query.d.ts +52 -8
- package/dist/query/query.js +133 -19
- package/dist/query/query.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/admin.md +53 -4
- package/docs/node-sign-in.md +8 -4
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownRecord.js","sourceRoot":"","sources":["../../src/api/ownRecord.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAA2B,MAAM,oBAAoB,CAAA;AAGvE,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,kBAAkB,EAAE,MAAM,cAAc,CAAA;AASjD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAa,EACb,IAAU,EACV,IAAiB,EAC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,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Failed } from '../core/invalid.js';
|
|
2
|
+
/**
|
|
3
|
+
* A record's or a workspace's own read's failure, as the call answers it: the one rule
|
|
4
|
+
* `readOwnRecord` and `readOwnWorkspaceWith` use (D578, #406; #410's code review, 2, 3 and 8).
|
|
5
|
+
* - **pulse-admin's own refusal of it** says it exists, so it answers `noSuch`, exactly as one
|
|
6
|
+
* nobody has, as one in a workspace you don't open does (D571). It's answered in place of the
|
|
7
|
+
* refusal (`inPlaceOf`), so the call still names the read it came from, as for the backend's own
|
|
8
|
+
* 404 (#410's code review, 1).
|
|
9
|
+
* - **Any other failure** passes as it came: a 403 that isn't pulse-admin's own, from a proxy, a
|
|
10
|
+
* gateway or a sign-in page in front of it, or pulse-admin's refusal of the token, says nothing
|
|
11
|
+
* about the record, and masking it would make a setup that refuses everything read as nothing
|
|
12
|
+
* existing.
|
|
13
|
+
*/
|
|
14
|
+
export declare function refusedAsNobodyHas(failed: Failed, noSuch: () => Failed): Failed;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { inPlaceOf } from '../core/inPlaceOf.js';
|
|
2
|
+
// pulse-admin's own refusal: its ForbiddenException, a 403 with its JSON error, code
|
|
3
|
+
// FORBIDDEN_EXCEPTION (dff6bf9b, adapters/ingress/fastapi/__init__.py:124-133: the code is the
|
|
4
|
+
// exception's class name, as `{ code, message }`). Its other 403, TOKEN_INVALID_EXCEPTION, refuses
|
|
5
|
+
// the token, not a record.
|
|
6
|
+
const REFUSED = 'FORBIDDEN_EXCEPTION';
|
|
7
|
+
/**
|
|
8
|
+
* A record's or a workspace's own read's failure, as the call answers it: the one rule
|
|
9
|
+
* `readOwnRecord` and `readOwnWorkspaceWith` use (D578, #406; #410's code review, 2, 3 and 8).
|
|
10
|
+
* - **pulse-admin's own refusal of it** says it exists, so it answers `noSuch`, exactly as one
|
|
11
|
+
* nobody has, as one in a workspace you don't open does (D571). It's answered in place of the
|
|
12
|
+
* refusal (`inPlaceOf`), so the call still names the read it came from, as for the backend's own
|
|
13
|
+
* 404 (#410's code review, 1).
|
|
14
|
+
* - **Any other failure** passes as it came: a 403 that isn't pulse-admin's own, from a proxy, a
|
|
15
|
+
* gateway or a sign-in page in front of it, or pulse-admin's refusal of the token, says nothing
|
|
16
|
+
* about the record, and masking it would make a setup that refuses everything read as nothing
|
|
17
|
+
* existing.
|
|
18
|
+
*/
|
|
19
|
+
export function refusedAsNobodyHas(failed, noSuch) {
|
|
20
|
+
const { error } = failed;
|
|
21
|
+
return error.kind === 'forbidden' && error.code === REFUSED ? inPlaceOf(failed, noSuch()) : failed;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=refusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusal.js","sourceRoot":"","sources":["../../src/api/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAGhD,qFAAqF;AACrF,+FAA+F;AAC/F,mGAAmG;AACnG,2BAA2B;AAC3B,MAAM,OAAO,GAAG,qBAAqB,CAAA;AAErC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,MAAoB;IACrE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxB,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AACpG,CAAC"}
|
package/dist/api/wallet.d.ts
CHANGED
|
@@ -32,7 +32,8 @@ export interface Ledger {
|
|
|
32
32
|
/**
|
|
33
33
|
* `flipstream.wallet.balance()`: your organisation's balance, or null when it has no wallet. No
|
|
34
34
|
* wallet is a real state, not a fault, so it isn't `invalid`, and it isn't €0.00 either: a zero
|
|
35
|
-
* balance would claim a wallet that holds nothing.
|
|
35
|
+
* balance would claim a wallet that holds nothing. Your organisation is read first, every time, with
|
|
36
|
+
* no cache (once for a whole scope, #376), as `transactions()` reads it: the wallet's id is its id.
|
|
36
37
|
*/
|
|
37
38
|
export declare function readBalance(seam: Backend, read: Read): Promise<ApiResult<Balance | null>>;
|
|
38
39
|
/**
|
package/dist/api/wallet.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { invalidIn } from '../core/invalid.js';
|
|
3
3
|
import { sameUuid } from './ids.js';
|
|
4
4
|
import { instant } from './time.js';
|
|
5
5
|
/*
|
|
@@ -31,26 +31,19 @@ const zTransaction = z
|
|
|
31
31
|
created_on: instant,
|
|
32
32
|
})
|
|
33
33
|
.transform(({ dataset_id, ...row }) => ({ ...row, dataset_id: dataset_id === '' || dataset_id === null ? null : dataset_id }));
|
|
34
|
-
/**
|
|
35
|
-
* Your organisation's id, read every time, with no cache, but once for a whole scope (#376): the
|
|
36
|
-
* wallet's id is the organisation's.
|
|
37
|
-
*/
|
|
38
|
-
async function organizationId(seam, read) {
|
|
39
|
-
const organization = await read(seam.myOrganization(zOrganizationId));
|
|
40
|
-
return organization.ok ? { ok: true, data: organization.data.id } : organization;
|
|
41
|
-
}
|
|
42
34
|
/**
|
|
43
35
|
* The guard both reads share: the balance's rows held to the organisation read. pulse-wallet scopes
|
|
44
36
|
* by the token, not the path, and answers the caller's own wallet for another organisation's id
|
|
45
37
|
* (#244's recording), so a row of another wallet is invalid, never read as yours. Two wallets are
|
|
46
38
|
* invalid too: an organisation has one. No rows is no wallet, null.
|
|
47
39
|
*/
|
|
48
|
-
function ownWallet(
|
|
40
|
+
function ownWallet(balance, organization) {
|
|
41
|
+
const rows = balance.data;
|
|
49
42
|
if (rows.some((row) => !sameUuid(row.wallet_id, organization)))
|
|
50
|
-
return
|
|
43
|
+
return invalidIn(balance, "a balance row is another wallet's");
|
|
51
44
|
const [row, ...more] = rows;
|
|
52
45
|
if (more.length > 0)
|
|
53
|
-
return
|
|
46
|
+
return invalidIn(balance, 'more than one wallet for the organisation');
|
|
54
47
|
return { ok: true, data: row ?? null };
|
|
55
48
|
}
|
|
56
49
|
const UNNAMED = "the organisation's id can't name its wallet";
|
|
@@ -58,25 +51,26 @@ const UNNAMED = "the organisation's id can't name its wallet";
|
|
|
58
51
|
* Whether your organisation has a wallet, decided in this one place for both reads (#375's code
|
|
59
52
|
* review, 5): its balance rows, read and held to `organization` by `ownWallet`, so a row is your
|
|
60
53
|
* wallet and null is none. The first of: the balance's failure, the wallet's verdict. `organization`
|
|
61
|
-
* is your organisation
|
|
54
|
+
* is your organisation, read by the caller, so the ledger can be read beside the balance.
|
|
62
55
|
*/
|
|
63
56
|
async function readOwnWallet(seam, read, organization) {
|
|
64
|
-
const spec = seam.balanceOf(organization, zBalanceRow);
|
|
57
|
+
const spec = seam.balanceOf(organization.data.id, zBalanceRow);
|
|
65
58
|
if (spec === null)
|
|
66
|
-
return
|
|
59
|
+
return invalidIn(organization, UNNAMED);
|
|
67
60
|
const rows = await read(spec);
|
|
68
|
-
return rows.ok ? ownWallet(rows
|
|
61
|
+
return rows.ok ? ownWallet(rows, organization.data.id) : rows;
|
|
69
62
|
}
|
|
70
63
|
/**
|
|
71
64
|
* `flipstream.wallet.balance()`: your organisation's balance, or null when it has no wallet. No
|
|
72
65
|
* wallet is a real state, not a fault, so it isn't `invalid`, and it isn't €0.00 either: a zero
|
|
73
|
-
* balance would claim a wallet that holds nothing.
|
|
66
|
+
* balance would claim a wallet that holds nothing. Your organisation is read first, every time, with
|
|
67
|
+
* no cache (once for a whole scope, #376), as `transactions()` reads it: the wallet's id is its id.
|
|
74
68
|
*/
|
|
75
69
|
export async function readBalance(seam, read) {
|
|
76
|
-
const organization = await
|
|
70
|
+
const organization = await read(seam.myOrganization(zOrganizationId));
|
|
77
71
|
if (!organization.ok)
|
|
78
72
|
return organization;
|
|
79
|
-
const wallet = await readOwnWallet(seam, read, organization
|
|
73
|
+
const wallet = await readOwnWallet(seam, read, organization);
|
|
80
74
|
if (!wallet.ok)
|
|
81
75
|
return wallet;
|
|
82
76
|
return { ok: true, data: wallet.data === null ? null : { balance_micro: wallet.data.balance_micro, micro_per_euro: MICRO_PER_EURO } };
|
|
@@ -92,15 +86,15 @@ export async function readBalance(seam, read) {
|
|
|
92
86
|
* O2.F1).
|
|
93
87
|
*/
|
|
94
88
|
export async function readLedger(seam, read) {
|
|
95
|
-
const organization = await
|
|
89
|
+
const organization = await read(seam.myOrganization(zOrganizationId));
|
|
96
90
|
if (!organization.ok)
|
|
97
91
|
return organization;
|
|
98
92
|
// Checked before either read is sent. The balance's path takes the same id, so once the
|
|
99
93
|
// ledger's can name it, so can the balance's, and readOwnWallet never refuses after this.
|
|
100
|
-
const ledgerSpec = seam.ledgerOf(organization.data, zTransaction);
|
|
94
|
+
const ledgerSpec = seam.ledgerOf(organization.data.id, zTransaction);
|
|
101
95
|
if (ledgerSpec === null)
|
|
102
|
-
return
|
|
103
|
-
const [wallet, ledger] = await Promise.all([readOwnWallet(seam, read, organization
|
|
96
|
+
return invalidIn(organization, UNNAMED);
|
|
97
|
+
const [wallet, ledger] = await Promise.all([readOwnWallet(seam, read, organization), read(ledgerSpec)]);
|
|
104
98
|
// The wallet's verdict comes from the balance, so it comes before the ledger's own failure: a
|
|
105
99
|
// caller never retries a ledger of a wallet that isn't theirs, nor of no wallet.
|
|
106
100
|
if (!wallet.ok)
|
|
@@ -108,7 +102,7 @@ export async function readLedger(seam, read) {
|
|
|
108
102
|
if (wallet.data === null) {
|
|
109
103
|
if (!ledger.ok)
|
|
110
104
|
return ledger.error.kind === 'invalid' ? ledger : { ok: true, data: null };
|
|
111
|
-
return ledger.data.length > 0 ?
|
|
105
|
+
return ledger.data.length > 0 ? invalidIn(ledger, 'ledger rows for an organisation with no wallet') : { ok: true, data: null };
|
|
112
106
|
}
|
|
113
107
|
if (!ledger.ok)
|
|
114
108
|
return ledger;
|
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;AACvB,OAAO,EAAE,
|
|
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,SAAS,EAAc,MAAM,oBAAoB,CAAA;AAG1D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,cAAc,GAAG,MAAM,CAAA;AAiC7B,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAC5B,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;AACxC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAGvE,mGAAmG;AACnG,gGAAgG;AAChG,iGAAiG;AACjG,0CAA0C;AAC1C,MAAM,YAAY,GAA2B,CAAC;KAC3C,MAAM,CAAC;IACN,EAAE;IACF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,YAAY,EAAE,CA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S,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;IAChE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;IACvG,8FAA8F;IAC9F,iFAAiF;IACjF,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;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,SAAS,CAAC,MAAM,EAAE,gDAAgD,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IAChI,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
|
@@ -81,9 +81,14 @@ export declare function readOwnWorkspace<O extends {
|
|
|
81
81
|
* and 4).
|
|
82
82
|
* - **Then the workspace and `alongside`** (a list under it), side by side. A workspace of another
|
|
83
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.
|
|
84
|
+
* isn't the workspace asked for. pulse-admin's own refusal of the workspace's read is `not_found`,
|
|
85
|
+
* exactly as one nobody has, since it says the workspace exists (`refusedAsNobodyHas`, D578), for
|
|
86
|
+
* every call under a named workspace. A 403 on `alongside`, or on a write after it, is the
|
|
87
|
+
* caller's, as it came.
|
|
85
88
|
* 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.
|
|
89
|
+
* comes back as it is, for the caller to read after. This isn't `readOwnRecord`'s rule, which reads
|
|
90
|
+
* a record beside you because the record names its workspace only once read: a workspace named up
|
|
91
|
+
* front is read only once you're known to open it, so one you don't open is never fetched.
|
|
87
92
|
*/
|
|
88
93
|
export declare function readOwnWorkspaceWith<O extends {
|
|
89
94
|
readonly id: string;
|
package/dist/api/workspaces.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { parseJson } from '../core/body.js';
|
|
3
|
-
import {
|
|
3
|
+
import { invalidIn } from '../core/invalid.js';
|
|
4
4
|
import { notFound } from '../core/notFound.js';
|
|
5
5
|
import { needsPerson, zHandOffOrganization } from './handoff.js';
|
|
6
6
|
import { sameUuid } from './ids.js';
|
|
7
7
|
import { readUser } from './me.js';
|
|
8
8
|
import { opensWorkspace } from './members.js';
|
|
9
|
+
import { refusedAsNobodyHas } from './refusal.js';
|
|
9
10
|
import { pageQuery } from './page.js';
|
|
10
11
|
import { unsent } from './unsent.js';
|
|
11
12
|
const id = z.string().min(1);
|
|
@@ -62,7 +63,7 @@ export async function readWorkspaces(seam, read, page) {
|
|
|
62
63
|
const ours = organization.data.id;
|
|
63
64
|
const spec = seam.workspacesOf(ours, sent, zRecord, (workspace) => sameUuid(workspace.organization_id, ours));
|
|
64
65
|
if (spec === null)
|
|
65
|
-
return
|
|
66
|
+
return invalidIn(organization, "the organisation's id can't name its workspaces");
|
|
66
67
|
const listed = await read(spec);
|
|
67
68
|
return listed.ok ? { ok: true, data: { ...listed.data, items: listed.data.items.map(publicOf) } } : listed;
|
|
68
69
|
}
|
|
@@ -93,7 +94,7 @@ export async function createWorkspace(seam, send, request) {
|
|
|
93
94
|
if (!made.ok)
|
|
94
95
|
return made;
|
|
95
96
|
if (!sameUuid(made.data.organization_id, organization.data.id))
|
|
96
|
-
return
|
|
97
|
+
return invalidIn(made, "the workspace made is another organisation's");
|
|
97
98
|
return { ok: true, data: publicOf(made.data) };
|
|
98
99
|
}
|
|
99
100
|
// pulse-admin's own 404 for a workspace nobody has, as recorded (test/recorded/admin/error-404.json;
|
|
@@ -120,9 +121,14 @@ export async function readOwnWorkspace(seam, read, workspaceId, organizationSche
|
|
|
120
121
|
* and 4).
|
|
121
122
|
* - **Then the workspace and `alongside`** (a list under it), side by side. A workspace of another
|
|
122
123
|
* 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
|
+
* isn't the workspace asked for. pulse-admin's own refusal of the workspace's read is `not_found`,
|
|
125
|
+
* exactly as one nobody has, since it says the workspace exists (`refusedAsNobodyHas`, D578), for
|
|
126
|
+
* every call under a named workspace. A 403 on `alongside`, or on a write after it, is the
|
|
127
|
+
* caller's, as it came.
|
|
124
128
|
* 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.
|
|
129
|
+
* comes back as it is, for the caller to read after. This isn't `readOwnRecord`'s rule, which reads
|
|
130
|
+
* a record beside you because the record names its workspace only once read: a workspace named up
|
|
131
|
+
* front is read only once you're known to open it, so one you don't open is never fetched.
|
|
126
132
|
*/
|
|
127
133
|
export async function readOwnWorkspaceWith(seam, read, workspaceId, organizationSchema, alongside) {
|
|
128
134
|
const spec = seam.workspace(workspaceId, zRecord);
|
|
@@ -137,14 +143,14 @@ export async function readOwnWorkspaceWith(seam, read, workspaceId, organization
|
|
|
137
143
|
return noSuchWorkspace();
|
|
138
144
|
const [workspace, beside] = await Promise.all([read(spec), alongside()]);
|
|
139
145
|
if (!workspace.ok)
|
|
140
|
-
return workspace;
|
|
146
|
+
return refusedAsNobodyHas(workspace, noSuchWorkspace);
|
|
141
147
|
// Another workspace than the one asked for is never answered as it, as me() holds its user to
|
|
142
148
|
// userinfo's sub; neither id is echoed. The caller's id may be any form pulse-admin reads as the
|
|
143
149
|
// same UUID (sameUuid), and so may the organisation's id the workspace names (#363).
|
|
144
150
|
if (!sameUuid(workspace.data.id, workspaceId))
|
|
145
|
-
return
|
|
151
|
+
return invalidIn(workspace, "the workspace read isn't the one asked for");
|
|
146
152
|
if (!sameUuid(workspace.data.organization_id, organization.data.id))
|
|
147
|
-
return
|
|
153
|
+
return invalidIn(workspace, "the workspace read is another organisation's");
|
|
148
154
|
return { ok: true, data: { organization: organization.data, workspace: workspace.data, alongside: beside } };
|
|
149
155
|
}
|
|
150
156
|
/** `flipstream.workspaces.get()`: one workspace, by `readOwnWorkspace`'s rules. */
|
|
@@ -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;AAC3C,OAAO,EAAE,
|
|
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,SAAS,EAAe,MAAM,oBAAoB,CAAA;AAC3D,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,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C"}
|
package/dist/auth/discovery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
|
-
import {
|
|
3
|
+
import { invalidIn } from '../core/invalid.js';
|
|
4
4
|
import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
|
|
5
5
|
/**
|
|
6
6
|
* What a `server` given in place of discovery lacks, as `server.<field>` with what it must be, or
|
|
@@ -44,7 +44,6 @@ const zMetadata = z.looseObject({
|
|
|
44
44
|
export async function discover(issuer, options = {}) {
|
|
45
45
|
if (typeof issuer !== 'string' || !isSignInUrl(issuer, options.allowLocalhostHttp))
|
|
46
46
|
return { ok: false, error: { kind: 'refused', reason: 'destination' } };
|
|
47
|
-
let status;
|
|
48
47
|
const read = await call(authTransport(options), {
|
|
49
48
|
effect: 'read',
|
|
50
49
|
service: 'auth',
|
|
@@ -53,14 +52,14 @@ export async function discover(issuer, options = {}) {
|
|
|
53
52
|
schema: zMetadata,
|
|
54
53
|
deadlineMs: 10_000,
|
|
55
54
|
retry: 'read',
|
|
56
|
-
}, options.signal
|
|
55
|
+
}, options.signal);
|
|
57
56
|
if (!read.ok)
|
|
58
57
|
return read;
|
|
59
58
|
const doc = read.data;
|
|
60
59
|
const problem = problemWith(doc, issuer);
|
|
61
|
-
// Any server the app names,
|
|
60
|
+
// Any server the app names, with the status its answer came with, as every check has (invalid.ts).
|
|
62
61
|
if (problem !== null)
|
|
63
|
-
return
|
|
62
|
+
return invalidIn(read, problem);
|
|
64
63
|
return {
|
|
65
64
|
ok: true,
|
|
66
65
|
data: {
|
|
@@ -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;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version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AE,SAAS,CAAC,CAAA;IAClD,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,OAAO,CAAA;IACpC,IAAI,GAAG,CAAC,gCAAgC,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,IAAI;QAAE,OAAO,oCAAoC,CAAA;IAChH,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/core/call.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
+
import type { HeardResult } from './invalid.js';
|
|
2
3
|
import type { SharedRule } from './shared.js';
|
|
3
|
-
import { type ApiResult } from './result.js';
|
|
4
4
|
import { type RetryRule } from './retry.js';
|
|
5
5
|
import type { ApiRequest, Transport } from './transport.js';
|
|
6
6
|
/** One endpoint's call: what it sends, and the rules it is sent under, declared next to its schema. */
|
|
@@ -29,7 +29,8 @@ export interface CallSpec<T> extends Omit<ApiRequest, 'signal'> {
|
|
|
29
29
|
* `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
|
|
30
30
|
* does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
|
|
31
31
|
* the caller's, so a caller's signal gets one listener a request, as before, and never one more.
|
|
32
|
-
*
|
|
33
|
-
* (#
|
|
32
|
+
* Its answer is read from the attempt that ends it, so a check of it after takes that attempt's
|
|
33
|
+
* status (invalid.ts, #385). It's handed on as readJson read it, a `Heard` answer (#394), never
|
|
34
|
+
* rebuilt.
|
|
34
35
|
*/
|
|
35
|
-
export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal, callEnd?: AbortSignal
|
|
36
|
+
export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal, callEnd?: AbortSignal): Promise<HeardResult<T>>;
|
package/dist/core/call.js
CHANGED
|
@@ -10,10 +10,11 @@ import { stopListening } from './signal.js';
|
|
|
10
10
|
* `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
|
|
11
11
|
* does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
|
|
12
12
|
* the caller's, so a caller's signal gets one listener a request, as before, and never one more.
|
|
13
|
-
*
|
|
14
|
-
* (#
|
|
13
|
+
* Its answer is read from the attempt that ends it, so a check of it after takes that attempt's
|
|
14
|
+
* status (invalid.ts, #385). It's handed on as readJson read it, a `Heard` answer (#394), never
|
|
15
|
+
* rebuilt.
|
|
15
16
|
*/
|
|
16
|
-
export async function call(transport, spec, signal, callEnd
|
|
17
|
+
export async function call(transport, spec, signal, callEnd) {
|
|
17
18
|
if (signal?.aborted === true || callEnd?.aborted === true)
|
|
18
19
|
return failed({ kind: 'aborted' });
|
|
19
20
|
// A call with no time for it is over before it starts: nothing is sent, as nothing is for a caller
|
|
@@ -62,11 +63,8 @@ export async function call(transport, spec, signal, callEnd, answered) {
|
|
|
62
63
|
// its rule. Any other status already decided: its answer stands, however its body ended.
|
|
63
64
|
if (brokeOff(sent, result))
|
|
64
65
|
decision = decide(spec.retry, attempt, { kind: 'unavailable' }, deadline.left());
|
|
65
|
-
if (decision.kind === 'stop')
|
|
66
|
-
if (result.ok && sent.kind === 'response')
|
|
67
|
-
answered?.(sent.response.status);
|
|
66
|
+
if (decision.kind === 'stop')
|
|
68
67
|
return withRetryAfter(result, sent);
|
|
69
|
-
}
|
|
70
68
|
}
|
|
71
69
|
else {
|
|
72
70
|
letGo(sent);
|
package/dist/core/call.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/core/call.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/core/call.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,cAAc,EAAgC,MAAM,aAAa,CAAA;AAC1E,OAAO,EAAE,MAAM,EAAE,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CAAC,CAAA;YACzC,OAAO,EAAE,CAAA;QACX,CAAC,CAAA;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAClC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,KAAe,EAAU,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA"}
|
package/dist/core/identify.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface Trace {
|
|
|
22
22
|
readonly traceId: string;
|
|
23
23
|
readonly flags: string;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* A caller's own `traceparent`'s trace: its trace-id and flags, when it's a valid version-00 one.
|
|
27
|
+
* Undefined for anything else, a value that isn't a string included, which W3C Trace Context says
|
|
28
|
+
* to drop.
|
|
29
|
+
*/
|
|
30
|
+
export declare function callerTrace(callerTraceparent: unknown): Trace | undefined;
|
|
25
31
|
/**
|
|
26
32
|
* The trace a call goes out under. A caller's own `traceparent` is carried on when it is one;
|
|
27
33
|
* otherwise, as W3C Trace Context says of one that can't be parsed, the call starts its own. A new
|
package/dist/core/identify.js
CHANGED
|
@@ -40,6 +40,20 @@ export function identityOf(options) {
|
|
|
40
40
|
throw invalid('conversationId', CONVERSATION_RULE);
|
|
41
41
|
return { app, agent, conversationId };
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* A caller's own `traceparent`'s trace: its trace-id and flags, when it's a valid version-00 one.
|
|
45
|
+
* Undefined for anything else, a value that isn't a string included, which W3C Trace Context says
|
|
46
|
+
* to drop.
|
|
47
|
+
*/
|
|
48
|
+
export function callerTrace(callerTraceparent) {
|
|
49
|
+
const match = typeof callerTraceparent === 'string' ? TRACEPARENT.exec(callerTraceparent) : null;
|
|
50
|
+
if (match === null)
|
|
51
|
+
return undefined;
|
|
52
|
+
const [, traceId, parentId, flags] = match;
|
|
53
|
+
if (traceId === undefined || parentId === undefined || flags === undefined || traceId === ZERO_TRACE_ID || parentId === ZERO_PARENT_ID)
|
|
54
|
+
return undefined;
|
|
55
|
+
return { traceId, flags };
|
|
56
|
+
}
|
|
43
57
|
/**
|
|
44
58
|
* The trace a call goes out under. A caller's own `traceparent` is carried on when it is one;
|
|
45
59
|
* otherwise, as W3C Trace Context says of one that can't be parsed, the call starts its own. A new
|
|
@@ -47,13 +61,7 @@ export function identityOf(options) {
|
|
|
47
61
|
* needs every request (D527).
|
|
48
62
|
*/
|
|
49
63
|
export function traceFor(callerTraceparent) {
|
|
50
|
-
|
|
51
|
-
if (match !== null) {
|
|
52
|
-
const [, traceId, parentId, flags] = match;
|
|
53
|
-
if (traceId !== undefined && parentId !== undefined && flags !== undefined && traceId !== ZERO_TRACE_ID && parentId !== ZERO_PARENT_ID)
|
|
54
|
-
return { traceId, flags };
|
|
55
|
-
}
|
|
56
|
-
return { traceId: randomHex(16, ZERO_TRACE_ID), flags: '01' };
|
|
64
|
+
return callerTrace(callerTraceparent) ?? { traceId: randomHex(16, ZERO_TRACE_ID), flags: '01' };
|
|
57
65
|
}
|
|
58
66
|
/** The traceparent of one attempt: the call's trace, with a parent-id of its own. */
|
|
59
67
|
export function traceparent(trace) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../src/core/identify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAyB3C,sGAAsG;AACtG,MAAM,aAAa,GAAG,qCAAqC,CAAA;AAC3D,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAClD,qEAAqE;AACrE,MAAM,WAAW,GAAG,kDAAkD,CAAA;AACtE,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AACpC,MAAM,cAAc,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,CAAC,IAAI,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAClG,CAAC;IACD,OAAO,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAClF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAyF;IAC9G,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IACpC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE;IACrC,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE;IACtC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE;IACnC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;CACtC,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAoB,EAAE,OAAoB,EAAE,gBAAyB;IAC9F,OAAO,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAA;AAC7G,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Failed } from './invalid.js';
|
|
2
|
+
import type { ApiError } from './result.js';
|
|
3
|
+
/** `replacement`, answered in place of `failed`, and remembered as standing for it. */
|
|
4
|
+
export declare function inPlaceOf(failed: Failed, replacement: Failed): Failed;
|
|
5
|
+
/** The failure `error` was answered in place of, or `error` itself when it wasn't. */
|
|
6
|
+
export declare function standsFor(error: ApiError): ApiError;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A failure the SDK answers in place of another (#410's code review, 1): D578's `not_found` for a
|
|
3
|
+
* record the backend refused. The call still names the request the refusal came from, as it does
|
|
4
|
+
* for the backend's own 404, so in a scope, where that request may be a shared read, the trace can't
|
|
5
|
+
* tell the two apart, and Logs still leads to the refusal.
|
|
6
|
+
*/
|
|
7
|
+
const replaced = new WeakMap();
|
|
8
|
+
/** `replacement`, answered in place of `failed`, and remembered as standing for it. */
|
|
9
|
+
export function inPlaceOf(failed, replacement) {
|
|
10
|
+
replaced.set(replacement.error, failed.error);
|
|
11
|
+
return replacement;
|
|
12
|
+
}
|
|
13
|
+
/** The failure `error` was answered in place of, or `error` itself when it wasn't. */
|
|
14
|
+
export function standsFor(error) {
|
|
15
|
+
return replaced.get(error) ?? error;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=inPlaceOf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inPlaceOf.js","sourceRoot":"","sources":["../../src/core/inPlaceOf.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAsB,CAAA;AAElD,uFAAuF;AACvF,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,WAAmB;IAC3D,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7C,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,SAAS,CAAC,KAAe;IACvC,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAA;AACrC,CAAC"}
|
package/dist/core/invalid.d.ts
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ApiResult } from './result.js';
|
|
3
|
+
type Answer<T> = Extract<ApiResult<T>, {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
}>;
|
|
6
|
+
/** A result's failure, as the public `ApiResult` describes it. */
|
|
7
|
+
export type Failed = Extract<ApiResult<never>, {
|
|
4
8
|
readonly ok: false;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
9
|
+
}>;
|
|
10
|
+
declare class HeardMark {
|
|
11
|
+
private heardMark;
|
|
12
|
+
}
|
|
13
|
+
/** An answer readParsed read from a 2xx, its status remembered: the one kind a check takes (#394). */
|
|
14
|
+
export type Heard<T> = Answer<T> & HeardMark;
|
|
15
|
+
/** A read's result as readParsed hands it on, and every layer after it: a `Heard` answer, or a failure. */
|
|
16
|
+
export type HeardResult<T> = Heard<T> | Failed;
|
|
17
|
+
/** The fault readParsed answers if it couldn't remember an answer it read. */
|
|
18
|
+
export declare const UNHEARD = "the answer couldn't be remembered with its status, so it isn't handed on";
|
|
19
|
+
/**
|
|
20
|
+
* `value`, a 2xx's JSON, read by `schema`: the data, as a `Heard` answer with the response's
|
|
21
|
+
* `status` remembered for a check of it after, or `invalid` with that `status`. readJson's own last
|
|
22
|
+
* step, and the one a scope's shared read takes for each call (#377's code review, 10), so both give
|
|
23
|
+
* one shape, status and issue text. Zod's issues name paths and expected types, never the body's
|
|
24
|
+
* values. The one place an answer becomes `Heard` (#398's code review, 3).
|
|
25
|
+
*/
|
|
26
|
+
export declare function readParsed<T>(value: unknown, schema: z.ZodType<T>, status: number | undefined): HeardResult<T>;
|
|
27
|
+
/** The status `answer` came with, as readParsed remembered it; none when its read heard none. */
|
|
28
|
+
export declare function statusOf(answer: Heard<unknown>): number | undefined;
|
|
29
|
+
/** `invalid`, found by a check of `answer` after its read, with the status `answer` came with (#385). */
|
|
30
|
+
export declare function invalidIn(answer: Heard<unknown>, issues: string): Failed;
|
|
31
|
+
/** `invalid` with `status`, a status the failure came with, or with none when it's undefined. */
|
|
32
|
+
export declare function invalidWith(issues: string, status: number | undefined): Failed;
|
|
33
|
+
export {};
|