@flipstream/sdk 0.9.0 → 0.10.1
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 +73 -0
- package/README.md +534 -487
- package/dist/api/backend.d.ts +182 -0
- package/dist/api/backend.js +314 -0
- package/dist/api/backend.js.map +1 -0
- package/dist/api/created.d.ts +5 -0
- package/dist/api/created.js +15 -0
- package/dist/api/created.js.map +1 -0
- package/dist/api/credentials.d.ts +36 -0
- package/dist/api/credentials.js +94 -0
- package/dist/api/credentials.js.map +1 -0
- package/dist/api/datasets.d.ts +94 -0
- package/dist/api/datasets.js +212 -0
- package/dist/api/datasets.js.map +1 -0
- package/dist/api/handoff.d.ts +34 -0
- package/dist/api/handoff.js +52 -0
- package/dist/api/handoff.js.map +1 -0
- package/dist/api/ids.d.ts +7 -0
- package/dist/api/ids.js +27 -0
- package/dist/api/ids.js.map +1 -0
- package/dist/api/index.d.ts +9 -1
- package/dist/api/log.d.ts +95 -0
- package/dist/api/log.js +213 -0
- package/dist/api/log.js.map +1 -0
- package/dist/api/me.d.ts +58 -0
- package/dist/api/me.js +64 -0
- package/dist/api/me.js.map +1 -0
- package/dist/api/members.d.ts +48 -0
- package/dist/api/members.js +102 -0
- package/dist/api/members.js.map +1 -0
- package/dist/api/organization.d.ts +11 -0
- package/dist/api/organization.js +15 -0
- package/dist/api/organization.js.map +1 -0
- package/dist/api/page.d.ts +33 -0
- package/dist/api/page.js +38 -0
- package/dist/api/page.js.map +1 -0
- package/dist/api/time.d.ts +3 -0
- package/dist/api/time.js +49 -0
- package/dist/api/time.js.map +1 -0
- package/dist/api/unsent.d.ts +6 -0
- package/dist/api/unsent.js +9 -0
- package/dist/api/unsent.js.map +1 -0
- package/dist/api/wallet.d.ts +45 -0
- package/dist/api/wallet.js +102 -0
- package/dist/api/wallet.js.map +1 -0
- package/dist/api/workspaces.d.ts +70 -0
- package/dist/api/workspaces.js +108 -0
- package/dist/api/workspaces.js.map +1 -0
- package/dist/core/body.js +23 -5
- package/dist/core/body.js.map +1 -1
- package/dist/core/call.d.ts +6 -0
- package/dist/core/call.js +1 -1
- package/dist/core/call.js.map +1 -1
- package/dist/core/fetch.js +4 -1
- package/dist/core/fetch.js.map +1 -1
- package/dist/core/names.d.ts +39 -0
- package/dist/core/names.js +41 -0
- package/dist/core/names.js.map +1 -1
- package/dist/core/read.d.ts +1 -1
- package/dist/core/read.js +7 -4
- package/dist/core/read.js.map +1 -1
- package/dist/core/result.d.ts +41 -3
- package/dist/core/result.js +18 -4
- package/dist/core/result.js.map +1 -1
- package/dist/core/secrets.d.ts +2 -0
- package/dist/core/secrets.js +33 -0
- package/dist/core/secrets.js.map +1 -0
- package/dist/core/transport.d.ts +6 -2
- package/dist/flipstream.d.ts +296 -4
- package/dist/flipstream.js +172 -23
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/node/clientSecret.js +1 -0
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/fileLock.d.ts +20 -2
- package/dist/node/fileLock.js +22 -13
- package/dist/node/fileLock.js.map +1 -1
- package/dist/node/keychainStore.d.ts +10 -0
- package/dist/node/keychainStore.js +33 -13
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/session.d.ts +1 -2
- package/dist/node/session.js +22 -14
- package/dist/node/session.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/dist/version.gen.js.map +1 -1
- package/docs/node-sign-in.md +503 -0
- package/package.json +3 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { needsPerson, zHandOffOrganization } from './handoff.js';
|
|
2
|
+
/**
|
|
3
|
+
* `flipstream.organization.rename()`: a D542 hand-off (item 1), as `workspaces.rename` is. It reads
|
|
4
|
+
* `/organizations/me` alone, for the short name, and its failure is the answer. Then
|
|
5
|
+
* `needs_person`, never a write (the SDK never sends `PUT /organizations/{id}`, a full replace that
|
|
6
|
+
* also carries `settings`, B10), with the organisation's settings page where a console can be
|
|
7
|
+
* named. The name the caller gave is never echoed.
|
|
8
|
+
*/
|
|
9
|
+
export async function handOffOrganizationRename(seam, read) {
|
|
10
|
+
const organization = await read(seam.myOrganization(zHandOffOrganization));
|
|
11
|
+
if (!organization.ok)
|
|
12
|
+
return organization;
|
|
13
|
+
return needsPerson('organization.rename', seam.organizationSettings(organization.data.slug));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=organization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization.js","sourceRoot":"","sources":["../../src/api/organization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAGhE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,IAAa,EAAE,IAAU;IACvE,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAA;IAC1E,IAAI,CAAC,YAAY,CAAC,EAAE;QAAE,OAAO,YAAY,CAAA;IACzC,OAAO,WAAW,CAAC,qBAAqB,EAAE,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AAC9F,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** One page of a list: its items, how many match in all, and the limit and offset it was read with. */
|
|
3
|
+
export interface Page<T> {
|
|
4
|
+
readonly items: readonly T[];
|
|
5
|
+
readonly total: number;
|
|
6
|
+
/** The page size used: the one asked for, at most 1,000, or 100 when none was. */
|
|
7
|
+
readonly limit: number;
|
|
8
|
+
readonly offset: number;
|
|
9
|
+
}
|
|
10
|
+
/** What a list call takes, beside what it lists. */
|
|
11
|
+
export interface PageRequest {
|
|
12
|
+
readonly limit?: number;
|
|
13
|
+
readonly offset?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The limit and offset a list sends. A larger limit is clamped, so the page says what was used.
|
|
17
|
+
* Anything but a whole number, at least 1 for the limit and 0 for the offset, is a programming
|
|
18
|
+
* error, a TypeError, with nothing sent: a limit of 0 would ask pulse-admin for every record.
|
|
19
|
+
*/
|
|
20
|
+
export declare function pageQuery(request: PageRequest): {
|
|
21
|
+
readonly limit: number;
|
|
22
|
+
readonly offset: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A `{ count, records }` answer, read as a Page of `item`, for the `limit` and `offset` sent. It's
|
|
26
|
+
* outside the contract when its total is no whole number, or smaller than its page, when the page
|
|
27
|
+
* is longer than its limit, or when a record is outside the list asked for (`inScope`): such a
|
|
28
|
+
* record is never dropped quietly, and the issue names its place, never its value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function pageOf<T>(item: z.ZodType<T>, sent: {
|
|
31
|
+
readonly limit: number;
|
|
32
|
+
readonly offset: number;
|
|
33
|
+
}, inScope: (item: T) => boolean): z.ZodType<Page<T>>;
|
package/dist/api/page.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const DEFAULT_LIMIT = 100;
|
|
3
|
+
const MAX_LIMIT = 1000;
|
|
4
|
+
/**
|
|
5
|
+
* The limit and offset a list sends. A larger limit is clamped, so the page says what was used.
|
|
6
|
+
* Anything but a whole number, at least 1 for the limit and 0 for the offset, is a programming
|
|
7
|
+
* error, a TypeError, with nothing sent: a limit of 0 would ask pulse-admin for every record.
|
|
8
|
+
*/
|
|
9
|
+
export function pageQuery(request) {
|
|
10
|
+
const { limit = DEFAULT_LIMIT, offset = 0 } = request;
|
|
11
|
+
if (!Number.isSafeInteger(limit) || limit < 1)
|
|
12
|
+
throw new TypeError('a list\'s limit is a whole number of at least 1');
|
|
13
|
+
if (!Number.isSafeInteger(offset) || offset < 0)
|
|
14
|
+
throw new TypeError('a list\'s offset is a whole number of at least 0');
|
|
15
|
+
return { limit: Math.min(limit, MAX_LIMIT), offset };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A `{ count, records }` answer, read as a Page of `item`, for the `limit` and `offset` sent. It's
|
|
19
|
+
* outside the contract when its total is no whole number, or smaller than its page, when the page
|
|
20
|
+
* is longer than its limit, or when a record is outside the list asked for (`inScope`): such a
|
|
21
|
+
* record is never dropped quietly, and the issue names its place, never its value.
|
|
22
|
+
*/
|
|
23
|
+
export function pageOf(item, sent, inScope) {
|
|
24
|
+
return z
|
|
25
|
+
.object({ count: z.int().nonnegative(), records: z.array(item) })
|
|
26
|
+
.superRefine(({ count, records }, context) => {
|
|
27
|
+
if (records.length > sent.limit)
|
|
28
|
+
context.addIssue({ code: 'custom', path: ['records'], message: 'more records than the limit sent' });
|
|
29
|
+
if (count < records.length)
|
|
30
|
+
context.addIssue({ code: 'custom', path: ['count'], message: 'smaller than the records it came with' });
|
|
31
|
+
for (const [index, record] of records.entries()) {
|
|
32
|
+
if (!inScope(record))
|
|
33
|
+
context.addIssue({ code: 'custom', path: ['records', index], message: 'outside the list asked for' });
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.transform(({ count, records }) => ({ items: records, total: count, limit: sent.limit, offset: sent.offset }));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/api/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAwBvB,MAAM,aAAa,GAAG,GAAG,CAAA;AACzB,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,OAAoB;IAC5C,MAAM,EAAE,KAAK,GAAG,aAAa,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA;IACrD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IA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,EAAE,CAAC,CAAA;QAC7H,CAAC;IACH,CAAC,CAAC;SACD,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAClH,CAAC"}
|
package/dist/api/time.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/*
|
|
3
|
+
* The one place the seam's reads take a time from a backend (#73). Every time they answer, the
|
|
4
|
+
* logbook's start_date and end_date and a transaction's created_on alike, is read by `instant`
|
|
5
|
+
* below, so each comes out in one form: an ISO 8601 instant in UTC, `…Z` with milliseconds. A new
|
|
6
|
+
* field holding a time uses `instant` too, never `z.string()`, and a new rule for reading times goes
|
|
7
|
+
* here, where every field gets it. The query planner's answers are outside it: their schemas are
|
|
8
|
+
* generated from its spec, so Catalog.generatedAt is the planner's own string. The logbook's writes
|
|
9
|
+
* read a caller's times with it too (#219): a time it refuses there is a TypeError, never sent.
|
|
10
|
+
*/
|
|
11
|
+
// An ISO 8601 date and time, as pulse-admin and pulse-wallet write one: with an offset, `Z` for
|
|
12
|
+
// UTC, or none, for the naive times pulse-admin stores, which are UTC (the console reads them so
|
|
13
|
+
// too).
|
|
14
|
+
const ISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|([+-])(\d{2}):(\d{2}))?$/;
|
|
15
|
+
/**
|
|
16
|
+
* `text` as an instant in UTC, `…Z` with milliseconds (finer digits are dropped), or null when it
|
|
17
|
+
* isn't a real date and time in that form. Read by its parts, never by `Date.parse`, which guesses
|
|
18
|
+
* at strings it shouldn't take: a part out of range (a 30 February, an hour 24, an offset past
|
|
19
|
+
* 23:59) is null, not rolled over.
|
|
20
|
+
*/
|
|
21
|
+
function instantOf(text) {
|
|
22
|
+
const match = ISO.exec(text);
|
|
23
|
+
if (match === null)
|
|
24
|
+
return null;
|
|
25
|
+
const [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number);
|
|
26
|
+
const fraction = match[7] ?? '';
|
|
27
|
+
const [zone, sign, zoneHours, zoneMinutes] = match.slice(8);
|
|
28
|
+
if (year === undefined || month === undefined || day === undefined || hour === undefined || minute === undefined || second === undefined)
|
|
29
|
+
return null;
|
|
30
|
+
const local = Date.UTC(year, month - 1, day, hour, minute, second, Number(fraction.padEnd(3, '0').slice(0, 3)));
|
|
31
|
+
const back = new Date(local);
|
|
32
|
+
// Date.UTC rolls an out-of-range part into the next, and reads a year under 100 as 19xx.
|
|
33
|
+
const parts = [back.getUTCFullYear(), back.getUTCMonth() + 1, back.getUTCDate(), back.getUTCHours(), back.getUTCMinutes(), back.getUTCSeconds()];
|
|
34
|
+
if (parts.some((part, index) => part !== [year, month, day, hour, minute, second][index]))
|
|
35
|
+
return null;
|
|
36
|
+
if (Number(zoneHours ?? 0) > 23 || Number(zoneMinutes ?? 0) > 59)
|
|
37
|
+
return null;
|
|
38
|
+
const offset = zone === undefined || zone === 'Z' ? 0 : (sign === '-' ? -1 : 1) * (Number(zoneHours) * 60 + Number(zoneMinutes)) * 60_000;
|
|
39
|
+
return new Date(local - offset).toISOString();
|
|
40
|
+
}
|
|
41
|
+
/** A time from a backend, read as an instant in UTC (`instantOf`); anything else is an issue on its field. */
|
|
42
|
+
export const instant = z.string().transform((text, context) => {
|
|
43
|
+
const read = instantOf(text);
|
|
44
|
+
if (read !== null)
|
|
45
|
+
return read;
|
|
46
|
+
context.addIssue({ code: 'custom', message: 'not an ISO 8601 date and time' });
|
|
47
|
+
return z.NEVER;
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/api/time.ts"],"names":[],"mappings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AAE,OAAO,EAAE,+BAA+B,EAAE,CAAC,CAAA;IAC9E,OAAO,CAAC,CAAC,KAAK,CAAA;AAChB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ApiResult } from '../core/result.js';
|
|
2
|
+
/**
|
|
3
|
+
* The keys of a write's `request` it doesn't send, refused before anything is sent, as D513 refuses
|
|
4
|
+
* a query's (D557): on a write, a dropped key would look set. Null when there are none.
|
|
5
|
+
*/
|
|
6
|
+
export declare function unsent(request: object, sends: readonly string[]): ApiResult<never> | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys of a write's `request` it doesn't send, refused before anything is sent, as D513 refuses
|
|
3
|
+
* a query's (D557): on a write, a dropped key would look set. Null when there are none.
|
|
4
|
+
*/
|
|
5
|
+
export function unsent(request, sends) {
|
|
6
|
+
const [first, ...rest] = Object.keys(request).filter((key) => !sends.includes(key));
|
|
7
|
+
return first === undefined ? null : { ok: false, error: { kind: 'refused', reason: 'fields', fields: [first, ...rest] } };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=unsent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsent.js","sourceRoot":"","sources":["../../src/api/unsent.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE,KAAwB;IAC9D,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IACnF,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;AAC3H,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ApiResult } from '../core/result.js';
|
|
2
|
+
import type { Backend } from './backend.js';
|
|
3
|
+
import type { Read } from './me.js';
|
|
4
|
+
/** Your organisation's balance: integer micro, and how many make a euro. */
|
|
5
|
+
export interface Balance {
|
|
6
|
+
readonly balance_micro: number;
|
|
7
|
+
readonly micro_per_euro: number;
|
|
8
|
+
}
|
|
9
|
+
/** One row of the wallet's ledger, in micro. */
|
|
10
|
+
export interface Transaction {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/** A credit, a manual charge or usage today, by the wallet's own names; a type the SDK doesn't know is kept as it came. */
|
|
13
|
+
readonly type: string;
|
|
14
|
+
/**
|
|
15
|
+
* The dataset a usage row charged, or null for a row that charged none, such as a credit: the
|
|
16
|
+
* wallet's `connection_id`, empty or null.
|
|
17
|
+
*/
|
|
18
|
+
readonly dataset_id: string | null;
|
|
19
|
+
readonly description: string;
|
|
20
|
+
/** The row's amount: positive for a credit, negative for a charge, as the wallet writes it. */
|
|
21
|
+
readonly amount_micro: number;
|
|
22
|
+
readonly quantity: number;
|
|
23
|
+
readonly unit_price_micro: number;
|
|
24
|
+
/** When the row was written: an ISO 8601 instant in UTC, as `2026-10-31T13:08:25.312Z`. */
|
|
25
|
+
readonly created_on: string;
|
|
26
|
+
}
|
|
27
|
+
/** Your organisation's whole ledger, in one answer, and how many micro make a euro. */
|
|
28
|
+
export interface Ledger {
|
|
29
|
+
readonly items: readonly Transaction[];
|
|
30
|
+
readonly micro_per_euro: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `flipstream.wallet.balance()`: your organisation's balance, or null when it has no wallet. No
|
|
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.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readBalance(seam: Backend, read: Read): Promise<ApiResult<Balance | null>>;
|
|
38
|
+
/**
|
|
39
|
+
* `flipstream.wallet.transactions()`: your organisation's whole ledger, in one answer, with no
|
|
40
|
+
* paging. Its rows carry no wallet id, so the balance is read beside it, and the ledger is answered
|
|
41
|
+
* only when that balance is your organisation's wallet (`ownWallet`). With no wallet, only an empty
|
|
42
|
+
* ledger is; any row then is invalid. The answer is the first of: the balance's failure, the
|
|
43
|
+
* wallet's verdict, the ledger's failure.
|
|
44
|
+
*/
|
|
45
|
+
export declare function readLedger(seam: Backend, read: Read): Promise<ApiResult<Ledger>>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { sameUuid } from './ids.js';
|
|
3
|
+
import { instant } from './time.js';
|
|
4
|
+
/*
|
|
5
|
+
* The organisation's prepaid wallet, read only (#73, D541). There is no write call, by design:
|
|
6
|
+
* adding credit is a person's spending. Prices wait for pulse-wallet#19 (D553).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Micro in a euro: the wallet keeps money as integer micro, with no unit or currency, and this is
|
|
10
|
+
* the one place the SDK states its basis (D544), as the console's `MICRO_PER_EURO` does.
|
|
11
|
+
* pulse-wallet#4 will re-base it to 1,000,000, and that change must change this in the same release.
|
|
12
|
+
*/
|
|
13
|
+
const MICRO_PER_EURO = 10_000;
|
|
14
|
+
const id = z.string().min(1);
|
|
15
|
+
const zOrganizationId = z.object({ id });
|
|
16
|
+
const zBalanceRow = z.object({ wallet_id: id, balance_micro: z.int() });
|
|
17
|
+
// A row in our names, so the backend's `connection_id` is `dataset_id`. The wallet writes an empty
|
|
18
|
+
// one for a row that charged no dataset, and its contracts allow null too (#269); both are read
|
|
19
|
+
// here as null. An object schema keeps only the fields it names, so `product_id`, `product_name`
|
|
20
|
+
// and anything else never reach a caller.
|
|
21
|
+
const zTransaction = z
|
|
22
|
+
.object({
|
|
23
|
+
id,
|
|
24
|
+
type: z.string().min(1),
|
|
25
|
+
dataset_id: z.string().nullable(),
|
|
26
|
+
description: z.string(),
|
|
27
|
+
amount_micro: z.int(),
|
|
28
|
+
quantity: z.int(),
|
|
29
|
+
unit_price_micro: z.int(),
|
|
30
|
+
created_on: instant,
|
|
31
|
+
})
|
|
32
|
+
.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
|
+
/** Your organisation's id, read every time, with no cache: the wallet's id is the organisation's. */
|
|
35
|
+
async function organizationId(seam, read) {
|
|
36
|
+
const organization = await read(seam.myOrganization(zOrganizationId));
|
|
37
|
+
return organization.ok ? { ok: true, data: organization.data.id } : organization;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The guard both reads share: the balance's rows held to the organisation read. pulse-wallet scopes
|
|
41
|
+
* by the token, not the path, and answers the caller's own wallet for another organisation's id
|
|
42
|
+
* (#244's recording), so a row of another wallet is invalid, never read as yours. Two wallets are
|
|
43
|
+
* invalid too: an organisation has one. No rows is no wallet, null.
|
|
44
|
+
*/
|
|
45
|
+
function ownWallet(rows, organization) {
|
|
46
|
+
if (rows.some((row) => !sameUuid(row.wallet_id, organization)))
|
|
47
|
+
return invalid("a balance row is another wallet's");
|
|
48
|
+
const [row, ...more] = rows;
|
|
49
|
+
if (more.length > 0)
|
|
50
|
+
return invalid('more than one wallet for the organisation');
|
|
51
|
+
return { ok: true, data: row ?? null };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* `flipstream.wallet.balance()`: your organisation's balance, or null when it has no wallet. No
|
|
55
|
+
* wallet is a real state, not a fault, so it isn't `invalid`, and it isn't €0.00 either: a zero
|
|
56
|
+
* balance would claim a wallet that holds nothing.
|
|
57
|
+
*/
|
|
58
|
+
export async function readBalance(seam, read) {
|
|
59
|
+
const organization = await organizationId(seam, read);
|
|
60
|
+
if (!organization.ok)
|
|
61
|
+
return organization;
|
|
62
|
+
const spec = seam.balanceOf(organization.data, zBalanceRow);
|
|
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);
|
|
69
|
+
if (!wallet.ok)
|
|
70
|
+
return wallet;
|
|
71
|
+
return { ok: true, data: wallet.data === null ? null : { balance_micro: wallet.data.balance_micro, micro_per_euro: MICRO_PER_EURO } };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* `flipstream.wallet.transactions()`: your organisation's whole ledger, in one answer, with no
|
|
75
|
+
* paging. Its rows carry no wallet id, so the balance is read beside it, and the ledger is answered
|
|
76
|
+
* only when that balance is your organisation's wallet (`ownWallet`). With no wallet, only an empty
|
|
77
|
+
* ledger is; any row then is invalid. The answer is the first of: the balance's failure, the
|
|
78
|
+
* wallet's verdict, the ledger's failure.
|
|
79
|
+
*/
|
|
80
|
+
export async function readLedger(seam, read) {
|
|
81
|
+
const organization = await organizationId(seam, read);
|
|
82
|
+
if (!organization.ok)
|
|
83
|
+
return organization;
|
|
84
|
+
const balanceSpec = seam.balanceOf(organization.data, zBalanceRow);
|
|
85
|
+
const ledgerSpec = seam.ledgerOf(organization.data, zTransaction);
|
|
86
|
+
if (balanceSpec === null || ledgerSpec === null)
|
|
87
|
+
return invalid("the organisation's id can't name its wallet");
|
|
88
|
+
const [balance, ledger] = await Promise.all([read(balanceSpec), read(ledgerSpec)]);
|
|
89
|
+
if (!balance.ok)
|
|
90
|
+
return balance;
|
|
91
|
+
// 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);
|
|
94
|
+
if (!wallet.ok)
|
|
95
|
+
return wallet;
|
|
96
|
+
if (!ledger.ok)
|
|
97
|
+
return ledger;
|
|
98
|
+
if (wallet.data === null && ledger.data.length > 0)
|
|
99
|
+
return invalid('ledger rows for an organisation with no wallet');
|
|
100
|
+
return { ok: true, data: { items: ledger.data, micro_per_euro: MICRO_PER_EURO } };
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,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,CAAC,CAAC,GAAG,EAAE;IACrB,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE;IACjB,gBAAgB,EAAE,C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AAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;IACjE,IAAI,WAAW,KAAK,IAAI,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,OAAO,CAAC,6CAA6C,CAAC,CAAA;IAC9G,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;IAClF,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAA;IAC/B,8FAA8F;IAC9F,+DAA+D;IAC/D,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,CAAA;IACzD,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC,gDAAgD,CAAC,CAAA;IACpH,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,EAAE,CAAA;AACnF,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ApiResult } from '../core/result.js';
|
|
3
|
+
import type { Backend } from './backend.js';
|
|
4
|
+
import { type WorkspaceHandOff } from './handoff.js';
|
|
5
|
+
import type { Read } from './me.js';
|
|
6
|
+
import { type Page, type PageRequest } from './page.js';
|
|
7
|
+
/** A workspace in your organisation (#208): a customer's client, in the backend's names. */
|
|
8
|
+
export interface Workspace {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** Its short name, as the console's addresses spell it. */
|
|
12
|
+
readonly slug: string;
|
|
13
|
+
}
|
|
14
|
+
declare const zRecord: z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
slug: z.ZodString;
|
|
18
|
+
organization_id: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
type WorkspaceRecord = z.output<typeof zRecord>;
|
|
21
|
+
/**
|
|
22
|
+
* `flipstream.workspaces.list()`: one page of your organisation's workspaces. Your organisation is
|
|
23
|
+
* read first, every time, with no cache, for its id. A workspace of another organisation makes the
|
|
24
|
+
* page invalid. A bad limit or offset throws before anything is sent. No sort is sent (D550, as
|
|
25
|
+
* amended): an empty one gives pulse-admin's repository default, `name` for clients
|
|
26
|
+
* (ClientRepository.order_by, pulse-admin 72ec7ef), a single-column order with no tiebreaker, and
|
|
27
|
+
* names aren't unique. So pages read at different times can overlap or skip a workspace: when
|
|
28
|
+
* workspaces are added, removed or renamed in between, or when two share a name, and a changed
|
|
29
|
+
* `total` shows only some of it. A complete, stable list is one page, of up to 1,000.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readWorkspaces(seam: Backend, read: Read, page: PageRequest): Promise<ApiResult<Page<Workspace>>>;
|
|
32
|
+
/**
|
|
33
|
+
* `flipstream.workspaces.create()`: a new workspace in your organisation (#209), named `name`.
|
|
34
|
+
* Before anything is sent, a key it doesn't send is `refused` (`fields`, naming them, as D513 does
|
|
35
|
+
* for a query), since on a write the caller would believe a dropped slug or organisation was set,
|
|
36
|
+
* and a name that isn't a non-empty, non-blank string throws. Then your organisation is read, for
|
|
37
|
+
* its id; its failure is the answer, and nothing is posted. Then one POST, under what is left of
|
|
38
|
+
* the call's deadline, never tried again. Only a refusal (a 4xx kind), `refused` or `no_token`
|
|
39
|
+
* shows nothing was made; after any other failure it may have been. That includes `invalid`: an
|
|
40
|
+
* answer to the POST that fails the schema or names another organisation comes after the workspace
|
|
41
|
+
* was made, and the caller can't tell it from the organisation read's. The answer is the workspace
|
|
42
|
+
* pulse-admin made, with the short name it chose; one of another organisation is invalid, echoing
|
|
43
|
+
* no id.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createWorkspace(seam: Backend, send: Read, request: {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
}): Promise<ApiResult<Workspace>>;
|
|
48
|
+
/**
|
|
49
|
+
* One of your organisation's workspaces, read beside your organisation. A workspace of another
|
|
50
|
+
* organisation is invalid, as a staff token could otherwise reach it, and so is an answer that isn't
|
|
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.
|
|
54
|
+
*/
|
|
55
|
+
export declare function readOwnWorkspace<O extends {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
}>(seam: Backend, read: Read, workspaceId: string, organizationSchema: z.ZodType<O>): Promise<ApiResult<{
|
|
58
|
+
readonly organization: O;
|
|
59
|
+
readonly workspace: WorkspaceRecord;
|
|
60
|
+
}>>;
|
|
61
|
+
/** `flipstream.workspaces.get()`: one workspace, by `readOwnWorkspace`'s rules. */
|
|
62
|
+
export declare function readWorkspace(seam: Backend, read: Read, workspaceId: string): Promise<ApiResult<Workspace>>;
|
|
63
|
+
/**
|
|
64
|
+
* `flipstream.workspaces.rename()` and `delete()`: a person's to do in the console (D542), so they
|
|
65
|
+
* 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 handed off. The address names
|
|
67
|
+
* the organisation's short name and the workspace's canonical id, as the backend answered it.
|
|
68
|
+
*/
|
|
69
|
+
export declare function handOffWorkspace(seam: Backend, read: Read, workspaceId: string, action: WorkspaceHandOff): Promise<ApiResult<never>>;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { needsPerson, zHandOffOrganization } from './handoff.js';
|
|
3
|
+
import { sameUuid } from './ids.js';
|
|
4
|
+
import { pageQuery } from './page.js';
|
|
5
|
+
import { unsent } from './unsent.js';
|
|
6
|
+
const id = z.string().min(1);
|
|
7
|
+
// A workspace as read, with the organisation it's in, so a record of another one is caught; the
|
|
8
|
+
// public Workspace drops it. An object schema keeps only the fields it names, so `meta`,
|
|
9
|
+
// `settings`, `account_id` and the embedded `organization` and `owner` never reach a caller.
|
|
10
|
+
const zRecord = z.object({ id, name: z.string(), slug: z.string(), organization_id: id });
|
|
11
|
+
const zOrganizationId = z.object({ id });
|
|
12
|
+
const publicOf = ({ id: workspaceId, name, slug }) => ({ id: workspaceId, name, slug });
|
|
13
|
+
const invalid = (issues) => ({ ok: false, error: { kind: 'invalid', issues } });
|
|
14
|
+
/**
|
|
15
|
+
* `flipstream.workspaces.list()`: one page of your organisation's workspaces. Your organisation is
|
|
16
|
+
* read first, every time, with no cache, for its id. A workspace of another organisation makes the
|
|
17
|
+
* page invalid. A bad limit or offset throws before anything is sent. No sort is sent (D550, as
|
|
18
|
+
* amended): an empty one gives pulse-admin's repository default, `name` for clients
|
|
19
|
+
* (ClientRepository.order_by, pulse-admin 72ec7ef), a single-column order with no tiebreaker, and
|
|
20
|
+
* names aren't unique. So pages read at different times can overlap or skip a workspace: when
|
|
21
|
+
* workspaces are added, removed or renamed in between, or when two share a name, and a changed
|
|
22
|
+
* `total` shows only some of it. A complete, stable list is one page, of up to 1,000.
|
|
23
|
+
*/
|
|
24
|
+
export async function readWorkspaces(seam, read, page) {
|
|
25
|
+
const sent = pageQuery(page);
|
|
26
|
+
const organization = await read(seam.myOrganization(zOrganizationId));
|
|
27
|
+
if (!organization.ok)
|
|
28
|
+
return organization;
|
|
29
|
+
const ours = organization.data.id;
|
|
30
|
+
const spec = seam.workspacesOf(ours, sent, zRecord, (workspace) => workspace.organization_id === ours);
|
|
31
|
+
if (spec === null)
|
|
32
|
+
return invalid("the organisation's id can't name its workspaces");
|
|
33
|
+
const listed = await read(spec);
|
|
34
|
+
return listed.ok ? { ok: true, data: { ...listed.data, items: listed.data.items.map(publicOf) } } : listed;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `flipstream.workspaces.create()`: a new workspace in your organisation (#209), named `name`.
|
|
38
|
+
* Before anything is sent, a key it doesn't send is `refused` (`fields`, naming them, as D513 does
|
|
39
|
+
* for a query), since on a write the caller would believe a dropped slug or organisation was set,
|
|
40
|
+
* and a name that isn't a non-empty, non-blank string throws. Then your organisation is read, for
|
|
41
|
+
* its id; its failure is the answer, and nothing is posted. Then one POST, under what is left of
|
|
42
|
+
* the call's deadline, never tried again. Only a refusal (a 4xx kind), `refused` or `no_token`
|
|
43
|
+
* shows nothing was made; after any other failure it may have been. That includes `invalid`: an
|
|
44
|
+
* answer to the POST that fails the schema or names another organisation comes after the workspace
|
|
45
|
+
* was made, and the caller can't tell it from the organisation read's. The answer is the workspace
|
|
46
|
+
* pulse-admin made, with the short name it chose; one of another organisation is invalid, echoing
|
|
47
|
+
* no id.
|
|
48
|
+
*/
|
|
49
|
+
export async function createWorkspace(seam, send, request) {
|
|
50
|
+
const refused = unsent(request, ['name']);
|
|
51
|
+
if (refused !== null)
|
|
52
|
+
return refused;
|
|
53
|
+
const { name } = request;
|
|
54
|
+
if (typeof name !== 'string' || name.trim() === '')
|
|
55
|
+
throw new TypeError('workspaces.create: name must be a string with more than spaces in it');
|
|
56
|
+
const organization = await send(seam.myOrganization(zOrganizationId));
|
|
57
|
+
if (!organization.ok)
|
|
58
|
+
return organization;
|
|
59
|
+
const made = await send(seam.createWorkspace(organization.data.id, name, zRecord));
|
|
60
|
+
if (!made.ok)
|
|
61
|
+
return made;
|
|
62
|
+
if (!sameUuid(made.data.organization_id, organization.data.id))
|
|
63
|
+
return invalid("the workspace made is another organisation's");
|
|
64
|
+
return { ok: true, data: publicOf(made.data) };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* One of your organisation's workspaces, read beside your organisation. A workspace of another
|
|
68
|
+
* organisation is invalid, as a staff token could otherwise reach it, and so is an answer that isn't
|
|
69
|
+
* the workspace asked for. The organisation's failure, then the workspace's, is the answer. A read
|
|
70
|
+
* under a workspace uses it too, so the workspace itself is proved, never only its records (D556,
|
|
71
|
+
* as amended): pulse-admin answers an empty list for any workspace id.
|
|
72
|
+
*/
|
|
73
|
+
export async function readOwnWorkspace(seam, read, workspaceId, organizationSchema) {
|
|
74
|
+
const spec = seam.workspace(workspaceId, zRecord);
|
|
75
|
+
if (spec === null)
|
|
76
|
+
return { ok: false, error: { kind: 'refused', reason: 'path' } };
|
|
77
|
+
const [organization, workspace] = await Promise.all([read(seam.myOrganization(organizationSchema)), read(spec)]);
|
|
78
|
+
if (!organization.ok)
|
|
79
|
+
return organization;
|
|
80
|
+
if (!workspace.ok)
|
|
81
|
+
return workspace;
|
|
82
|
+
// Another workspace than the one asked for is never answered as it, as me() holds its user to
|
|
83
|
+
// userinfo's sub; neither id is echoed. The caller's id may be any form pulse-admin reads as the
|
|
84
|
+
// same UUID (sameUuid).
|
|
85
|
+
if (!sameUuid(workspace.data.id, workspaceId))
|
|
86
|
+
return invalid("the workspace read isn't the one asked for");
|
|
87
|
+
if (workspace.data.organization_id !== organization.data.id)
|
|
88
|
+
return invalid("the workspace read is another organisation's");
|
|
89
|
+
return { ok: true, data: { organization: organization.data, workspace: workspace.data } };
|
|
90
|
+
}
|
|
91
|
+
/** `flipstream.workspaces.get()`: one workspace, by `readOwnWorkspace`'s rules. */
|
|
92
|
+
export async function readWorkspace(seam, read, workspaceId) {
|
|
93
|
+
const own = await readOwnWorkspace(seam, read, workspaceId, zOrganizationId);
|
|
94
|
+
return own.ok ? { ok: true, data: publicOf(own.data.workspace) } : own;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* `flipstream.workspaces.rename()` and `delete()`: a person's to do in the console (D542), so they
|
|
98
|
+
* answer `needs_person` and never write. The workspace is read first, by `readOwnWorkspace`'s
|
|
99
|
+
* rules, so one that isn't yours is `not_found` or `invalid`, never handed off. The address names
|
|
100
|
+
* the organisation's short name and the workspace's canonical id, as the backend answered it.
|
|
101
|
+
*/
|
|
102
|
+
export async function handOffWorkspace(seam, read, workspaceId, action) {
|
|
103
|
+
const own = await readOwnWorkspace(seam, read, workspaceId, zHandOffOrganization);
|
|
104
|
+
if (!own.ok)
|
|
105
|
+
return own;
|
|
106
|
+
return needsPerson(action, seam.workspaceSettings(own.data.organization.slug, own.data.workspace.id));
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=workspaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/api/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAyB,MAAM,cAAc,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAUpC,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAE5B,gGAAgG;AAChG,yFAAyF;AACzF,6FAA6F;AAC7F,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAA;AAEzF,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;AAExC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EA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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/core/body.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { zErrorBody } from '../spec/query-planner/zod.gen.js';
|
|
2
3
|
export function parseJson(text) {
|
|
3
4
|
try {
|
|
@@ -16,13 +17,24 @@ const CODE_SHAPE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
|
16
17
|
/** A message is capped, by code point so the cap never splits a character in two. */
|
|
17
18
|
const MESSAGE_MAX = 500;
|
|
18
19
|
const capped = (message) => (message.length <= MESSAGE_MAX ? message : Array.from(message).slice(0, MESSAGE_MAX).join(''));
|
|
19
|
-
/**
|
|
20
|
-
const
|
|
21
|
-
const read =
|
|
20
|
+
/** A `{ code, message }` envelope read by `schema`, with a code of a code's shape and a capped message. */
|
|
21
|
+
const codeAndMessage = (schema) => (body) => {
|
|
22
|
+
const read = schema.safeParse(body);
|
|
22
23
|
if (!read.success || !CODE_SHAPE.test(read.data.code))
|
|
23
24
|
return null;
|
|
24
25
|
return { code: read.data.code, message: capped(read.data.message) };
|
|
25
26
|
};
|
|
27
|
+
/** The planner's `{ code, message }`, its spec's ErrorBody (D429). */
|
|
28
|
+
const planner = codeAndMessage(zErrorBody);
|
|
29
|
+
/**
|
|
30
|
+
* fractal's `ErrorMessage`, `{ code, message }`, which pulse-admin, pulse-auth and pulse-wallet
|
|
31
|
+
* send for a token, permission or domain error (`TOKEN_EXPIRED_EXCEPTION`, `ORGANIZATION_AMBIGUOUS`).
|
|
32
|
+
* Written from their exception handlers (pulse-admin dff6bf9, pulse-auth 0ae57c8,
|
|
33
|
+
* `adapters/ingress/fastapi`), since no spec declares it. Their 422 and 500 put a Python class name
|
|
34
|
+
* in `code` (`RequestValidationError`, `KeyError`), which isn't a code's shape, so those stay text,
|
|
35
|
+
* as FastAPI's own `{ detail }` does: it has no code at all.
|
|
36
|
+
*/
|
|
37
|
+
const fractal = codeAndMessage(z.object({ code: z.string(), message: z.string() }));
|
|
26
38
|
/**
|
|
27
39
|
* An OAuth code is lowercase (`invalid_grant`, RFC 6749 §5.2), so it has its own bound, kept as
|
|
28
40
|
* tight as a planner code's for the same reason.
|
|
@@ -48,9 +60,15 @@ const oauth = (body) => {
|
|
|
48
60
|
/**
|
|
49
61
|
* Each service's envelopes (D442): a host's error body is read only by the envelope that host
|
|
50
62
|
* sends, so a proxy's `{"error":"not_found"}` on the query host is never taken for an OAuth code.
|
|
51
|
-
* #91's `{ error: { code, message, request_id } }` joins `api` from its own spec
|
|
63
|
+
* #91's `{ error: { code, message, request_id } }` joins `api` from its own spec, once it has one.
|
|
52
64
|
*/
|
|
53
|
-
const ENVELOPES = {
|
|
65
|
+
const ENVELOPES = {
|
|
66
|
+
query: [planner],
|
|
67
|
+
auth: [oauth, fractal],
|
|
68
|
+
admin: [fractal],
|
|
69
|
+
wallet: [fractal],
|
|
70
|
+
api: [],
|
|
71
|
+
};
|
|
54
72
|
/**
|
|
55
73
|
* What a failure status from `service` came with: the first of its envelopes that reads the body,
|
|
56
74
|
* or the body as it came.
|
package/dist/core/body.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/core/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAQ7D,MAAM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C/D,MAAM,WAAW,GAAY,mBAAmB,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAA;IAC7F,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAC3E,IAAI,WAAW,KAAK,SAAS,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAC7E,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,CAAA;AAC5D,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,SAAS,GAAuD;IACpE,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,MAAM,EAAE,CAAC,OAAO,CAAC;IACjB,GAAG,EAAE,EAAE;CACR,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,OAAoB;IACrD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAC5B,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QACZ,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC9B,IAAI,KAAK,KAAK,IAAI;gBAAE,OAAO,KAAK,CAAA;QAClC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,CAAA;AACjB,CAAC"}
|
package/dist/core/call.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ export interface CallSpec<T> extends Omit<ApiRequest, 'signal'> {
|
|
|
8
8
|
/** How long the whole call may take: every attempt, every wait and the reading of the answer. */
|
|
9
9
|
readonly deadlineMs: number;
|
|
10
10
|
readonly retry: RetryRule;
|
|
11
|
+
/**
|
|
12
|
+
* The answer may hold a secret's value (a sign-in's, #70), so no body's text is kept: a 2xx that
|
|
13
|
+
* isn't JSON, or a failure body that isn't the host's own error shape, gives its kind and status
|
|
14
|
+
* alone (#278 round 1). Left out, the text is kept, as for every other call.
|
|
15
|
+
*/
|
|
16
|
+
readonly keepsNoText?: true;
|
|
11
17
|
}
|
|
12
18
|
/**
|
|
13
19
|
* One call: attempts under its rule, every attempt, wait and read under one signal that joins the
|
package/dist/core/call.js
CHANGED
|
@@ -33,7 +33,7 @@ export async function call(transport, spec, signal) {
|
|
|
33
33
|
}
|
|
34
34
|
let decision = decide(spec.retry, attempt, outcomeOf(sent), Date.now(), deadline);
|
|
35
35
|
if (decision.kind === 'stop') {
|
|
36
|
-
const result = await unlessFired(readJson(sent, spec.schema, stop.signal, spec.service), fired, () => undefined);
|
|
36
|
+
const result = await unlessFired(readJson(sent, spec.schema, stop.signal, spec.service, spec.keepsNoText === true), fired, () => undefined);
|
|
37
37
|
if (result === ENDED || stop.signal.aborted)
|
|
38
38
|
return ended();
|
|
39
39
|
// A success whose body broke off is a transport failure too, so a read tries again under
|