@flipstream/sdk 0.8.0 → 0.10.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 +92 -0
- package/README.md +707 -66
- 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/auth/discovery.js +1 -1
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.js +7 -2
- package/dist/auth/signIn.js.map +1 -1
- 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.d.ts +5 -0
- package/dist/core/fetch.js +7 -1
- package/dist/core/fetch.js.map +1 -1
- package/dist/core/identify.d.ts +63 -0
- package/dist/core/identify.js +122 -0
- package/dist/core/identify.js.map +1 -0
- package/dist/core/names.d.ts +100 -0
- package/dist/core/names.js +114 -0
- package/dist/core/names.js.map +1 -0
- package/dist/core/read.d.ts +1 -1
- package/dist/core/read.js +15 -6
- package/dist/core/read.js.map +1 -1
- package/dist/core/result.d.ts +67 -6
- package/dist/core/result.js +39 -6
- 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 +12 -4
- package/dist/flipstream.d.ts +341 -5
- package/dist/flipstream.js +203 -13
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/node/clientSecret.js +2 -1
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.js +10 -6
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainStore.d.ts +6 -3
- package/dist/node/keychainStore.js +6 -3
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/session.d.ts +78 -29
- package/dist/node/session.js +74 -52
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +11 -1
- package/dist/node/store.js +14 -1
- package/dist/node/store.js.map +1 -1
- package/dist/query/query.d.ts +15 -10
- package/dist/query/query.js +21 -11
- package/dist/query/query.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/dist/version.gen.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isSecretKey } from '../core/secrets.js';
|
|
3
|
+
import { credentialNeedsPerson } from './handoff.js';
|
|
4
|
+
import { sameUuid } from './ids.js';
|
|
5
|
+
import { pageQuery } from './page.js';
|
|
6
|
+
import { instant } from './time.js';
|
|
7
|
+
/**
|
|
8
|
+
* An issue at each place in `value` that may hold a sign-in's value: its path, never what it holds.
|
|
9
|
+
* Each is fatal, so nothing after this check (the allowlist, the page's scope check) ever reads a
|
|
10
|
+
* flagged record (#278 round 1).
|
|
11
|
+
*/
|
|
12
|
+
function flagValues(value, path, context) {
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
for (const [index, item] of value.entries())
|
|
15
|
+
flagValues(item, [...path, index], context);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (typeof value !== 'object' || value === null)
|
|
19
|
+
return;
|
|
20
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
21
|
+
if (isSecretKey(key))
|
|
22
|
+
context.addIssue({ code: 'custom', path: [...path, key], message: "may hold a sign-in's value, so nothing is answered", continue: false });
|
|
23
|
+
else
|
|
24
|
+
flagValues(inner, [...path, key], context);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const id = z.string().min(1);
|
|
28
|
+
// A sign-in as read, before the allowlist: an empty `data` is the normal state (the value is in
|
|
29
|
+
// Secret Manager); any other `data`, or a secret-like key anywhere, makes the answer invalid.
|
|
30
|
+
const zRecord = z
|
|
31
|
+
.unknown()
|
|
32
|
+
.superRefine((record, context) => {
|
|
33
|
+
if (typeof record !== 'object' || record === null)
|
|
34
|
+
return;
|
|
35
|
+
const data = 'data' in record ? record.data : undefined;
|
|
36
|
+
if (data !== undefined && data !== null && data !== '')
|
|
37
|
+
context.addIssue({ code: 'custom', path: ['data'], message: "holds what may be a sign-in's value, so nothing is answered", continue: false });
|
|
38
|
+
flagValues(record, [], context);
|
|
39
|
+
})
|
|
40
|
+
.pipe(z.object({
|
|
41
|
+
id,
|
|
42
|
+
name: z.string(),
|
|
43
|
+
type: z.string().min(1).nullable(),
|
|
44
|
+
datasource_types: z
|
|
45
|
+
.array(z.string())
|
|
46
|
+
.nullable()
|
|
47
|
+
.transform((types) => types ?? []),
|
|
48
|
+
created_on: instant,
|
|
49
|
+
organization_id: id,
|
|
50
|
+
}));
|
|
51
|
+
const zOrganizationId = z.object({ id });
|
|
52
|
+
const publicOf = ({ id: credentialId, name, type, datasource_types, created_on }) => ({ id: credentialId, name, type, datasource_types, created_on });
|
|
53
|
+
const invalid = (issues) => ({ ok: false, error: { kind: 'invalid', issues } });
|
|
54
|
+
const refusedPath = { ok: false, error: { kind: 'refused', reason: 'path' } };
|
|
55
|
+
/**
|
|
56
|
+
* `flipstream.credentials.list()`: one page of your organisation's sign-ins, as metadata. A bad
|
|
57
|
+
* limit or offset throws, with nothing sent. Your organisation is read first, for its id; its
|
|
58
|
+
* failure is the answer. A sign-in of another organisation, or one holding what may be a value, makes
|
|
59
|
+
* the answer invalid, naming its place.
|
|
60
|
+
*/
|
|
61
|
+
export async function listCredentials(seam, read, request = {}) {
|
|
62
|
+
pageQuery(request);
|
|
63
|
+
const organization = await read(seam.myOrganization(zOrganizationId));
|
|
64
|
+
if (!organization.ok)
|
|
65
|
+
return organization;
|
|
66
|
+
// A record is checked before this runs, but the scope check never throws on what it's given.
|
|
67
|
+
const spec = seam.organizationCredentials(organization.data.id, request, zRecord, (record) => typeof record.organization_id === 'string' && sameUuid(record.organization_id, organization.data.id));
|
|
68
|
+
if (spec === null)
|
|
69
|
+
return invalid("the organisation's id can't name its sign-ins");
|
|
70
|
+
const listed = await read(spec);
|
|
71
|
+
return listed.ok ? { ok: true, data: { ...listed.data, items: listed.data.items.map(publicOf) } } : listed;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* `flipstream.credentials.revoke()` and `delete()`: D542 hand-offs (D546). The sign-in is read
|
|
75
|
+
* beside your organisation, under `list`'s check: one nobody has is `not_found`, and another
|
|
76
|
+
* organisation's, or an answer that isn't the one asked for, is invalid, echoing no id. Then
|
|
77
|
+
* `needs_person`, never a write.
|
|
78
|
+
*/
|
|
79
|
+
export async function handOffCredential(seam, read, credentialId, action) {
|
|
80
|
+
const spec = seam.credential(credentialId, zRecord);
|
|
81
|
+
if (spec === null)
|
|
82
|
+
return refusedPath;
|
|
83
|
+
const [organization, credential] = await Promise.all([read(seam.myOrganization(zOrganizationId)), read(spec)]);
|
|
84
|
+
if (!organization.ok)
|
|
85
|
+
return organization;
|
|
86
|
+
if (!credential.ok)
|
|
87
|
+
return credential;
|
|
88
|
+
if (!sameUuid(credential.data.id, credentialId))
|
|
89
|
+
return invalid("the sign-in read isn't the one asked for");
|
|
90
|
+
if (!sameUuid(credential.data.organization_id, organization.data.id))
|
|
91
|
+
return invalid("the sign-in read is another organisation's");
|
|
92
|
+
return credentialNeedsPerson(action);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/api/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD,OAAO,EAAE,qBAAqB,EAA0B,MAAM,cAAc,CAAA;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA4BnC;;;;GAIG;AACH,SAAS,UAAU,CAAC,KAAc,EAAE,IAAkC,EAAE,OAAwB;IAC9F,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,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G,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC9G,IAAI,CAAC,YAAY,CAAC,EAAE;QAAE,OAAO,YAAY,CAAA;IACzC,IAAI,CAAC,UAAU,CAAC,EAAE;QAAE,OAAO,UAAU,CAAA;IACrC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,YAAY,CAAC;QAAE,OAAO,OAAO,CAAC,0CAA0C,CAAC,CAAA;IAC3G,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,OAAO,OAAO,CAAC,4CAA4C,CAAC,CAAA;IAClI,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ApiResult } from '../core/result.js';
|
|
2
|
+
import type { Backend } from './backend.js';
|
|
3
|
+
import type { Read } from './me.js';
|
|
4
|
+
import type { Page } from './page.js';
|
|
5
|
+
/**
|
|
6
|
+
* A dataset type this version of the SDK knows: pulse-admin's DataSourceType at admin 0.0.126, in
|
|
7
|
+
* its own spelling, since D540 renames fields, never values. Written out, so the public type names
|
|
8
|
+
* nothing the package doesn't export (#99).
|
|
9
|
+
*/
|
|
10
|
+
export type DatasetType = 'google_analytics_4' | 'google_search_console' | 'google_ads' | 'google_business_profile' | 'google_sheets' | 'linkedin_ads' | 'pulse' | 'weather' | 'meta_ads' | 'facebook_pages' | 'llm_scrape_chatgpt' | 'llm_scrape_perplexity' | 'llm_scrape_gemini' | 'serp_scrape_google_organic' | 'serp_scrape_google_shopping' | 'serp_scrape_google_maps' | 'serp_scrape_youtube';
|
|
11
|
+
/**
|
|
12
|
+
* How much of a dataset's history is in the warehouse (#293): pulse-admin's `backfill`, in its own
|
|
13
|
+
* spelling, since D540 renames fields, never values.
|
|
14
|
+
* - `not_available`: no history is loaded for its kind of dataset.
|
|
15
|
+
* - `todo`: its history hasn't started loading. pulse-admin makes every new dataset `todo`, and
|
|
16
|
+
* pulse-dagster sets `not_available` only when it first runs for one, so `todo` may never start
|
|
17
|
+
* for a type that loads no history.
|
|
18
|
+
* - `started`: its history is loading, from the first load until it's in; a load that keeps failing
|
|
19
|
+
* stays `started`.
|
|
20
|
+
* - `done`: its history is in.
|
|
21
|
+
*
|
|
22
|
+
* An app merges them as it needs: the console shows `todo` and `started` alike as "coming in".
|
|
23
|
+
*/
|
|
24
|
+
export type DatasetHistory = 'not_available' | 'todo' | 'started' | 'done';
|
|
25
|
+
/** A dataset in a workspace (#211): an upload or a connected account alike, the backend's connection. */
|
|
26
|
+
export interface Dataset {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly workspace_id: string;
|
|
30
|
+
/**
|
|
31
|
+
* What it holds: a `DatasetType`, or a type this version doesn't know yet, kept as it came, so a
|
|
32
|
+
* new connector never makes a workspace's datasets unreadable (D493). Null when the backend holds
|
|
33
|
+
* none for it: pulse-admin's model allows that, so it's a real state, and one such dataset never
|
|
34
|
+
* makes the whole list invalid.
|
|
35
|
+
*/
|
|
36
|
+
readonly type: DatasetType | (string & Record<never, never>) | null;
|
|
37
|
+
/** Whether it's switched on. */
|
|
38
|
+
readonly active: boolean;
|
|
39
|
+
/** When it was made: an ISO 8601 instant in UTC (#231). Null when the backend holds none. */
|
|
40
|
+
readonly created_on: string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Who made it: a person's id (#231). Name them with `flipstream.members.get`; when it doesn't
|
|
43
|
+
* answer ok (see its docs), show the maker as unknown, for example for a dataset Flipstream staff
|
|
44
|
+
* made through a swap token. Null when the backend holds none, or holds its empty default.
|
|
45
|
+
*/
|
|
46
|
+
readonly created_by_id: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* How much of its history is in the warehouse (#293): see `DatasetHistory`. Null when it's
|
|
49
|
+
* unknown: the backend holds none, or a value this version doesn't know, so show "Not available
|
|
50
|
+
* yet", never a value of your own (os D1348).
|
|
51
|
+
*/
|
|
52
|
+
readonly history: DatasetHistory | null;
|
|
53
|
+
}
|
|
54
|
+
/** What `flipstream.datasets.list()` takes: the workspace, and the page, as every list does. */
|
|
55
|
+
export interface DatasetListRequest {
|
|
56
|
+
readonly workspace_id: string;
|
|
57
|
+
/** At most 1,000, and 100 when left out. */
|
|
58
|
+
readonly limit?: number;
|
|
59
|
+
readonly offset?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* `flipstream.datasets.list()`: one page of a workspace's datasets, in the backend's own order, by
|
|
63
|
+
* name (no sort is sent, D550). The workspace is read beside the list, by `readOwnWorkspace`'s
|
|
64
|
+
* rules, so one nobody has is `not_found` and another organisation's is invalid, never an empty
|
|
65
|
+
* page. A row of another workspace is invalid, naming its place; the caller's id may be any form
|
|
66
|
+
* pulse-admin reads as the same UUID (sameUuid). A row of another organisation is invalid too,
|
|
67
|
+
* naming its place, never an id. The organisation's failure, then the workspace's, then the
|
|
68
|
+
* list's, is the answer, whichever finishes first. A bad limit or offset throws, as every list's
|
|
69
|
+
* does.
|
|
70
|
+
*/
|
|
71
|
+
export declare function listDatasets(seam: Backend, read: Read, request: DatasetListRequest): Promise<ApiResult<Page<Dataset>>>;
|
|
72
|
+
/** `flipstream.datasets.get()`: one dataset, by its id, by `readOwnDataset`'s rules. */
|
|
73
|
+
export declare function getDataset(seam: Backend, read: Read, request: {
|
|
74
|
+
readonly dataset_id: string;
|
|
75
|
+
}): Promise<ApiResult<Dataset>>;
|
|
76
|
+
/**
|
|
77
|
+
* `flipstream.datasets.delete()`: a D542 hand-off (D546), as `workspaces.delete` is. The dataset is
|
|
78
|
+
* read by `readOwnDataset`'s rules, so one nobody has is `not_found` and another organisation's
|
|
79
|
+
* invalid, before any hand-off. Then `needs_person`, never a write, with the console's dataset page
|
|
80
|
+
* where a console can be named (os D1334).
|
|
81
|
+
*/
|
|
82
|
+
export declare function handOffDatasetDelete(seam: Backend, read: Read, request: {
|
|
83
|
+
readonly dataset_id: string;
|
|
84
|
+
}): Promise<ApiResult<never>>;
|
|
85
|
+
/** `flipstream.datasets.pause()`: `active` false, by `setActive`'s rules. */
|
|
86
|
+
export declare const pauseDataset: (seam: Backend, send: Read, request: {
|
|
87
|
+
readonly dataset_id: string;
|
|
88
|
+
}) => Promise<ApiResult<Dataset>>;
|
|
89
|
+
/** `flipstream.datasets.resume()`: `active` true, by `setActive`'s rules. */
|
|
90
|
+
export declare const resumeDataset: (seam: Backend, send: Read, request: {
|
|
91
|
+
readonly dataset_id: string;
|
|
92
|
+
}) => Promise<ApiResult<Dataset>>;
|
|
93
|
+
/** `flipstream.datasetTypes.list()`: the types this version knows, with no request; a copy for each caller. */
|
|
94
|
+
export declare function listDatasetTypes(): ApiResult<readonly DatasetType[]>;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { needsPerson, zHandOffOrganization } from './handoff.js';
|
|
3
|
+
import { sameUuid } from './ids.js';
|
|
4
|
+
import { createdById, createdOn } from './created.js';
|
|
5
|
+
import { unsent } from './unsent.js';
|
|
6
|
+
import { readOwnWorkspace } from './workspaces.js';
|
|
7
|
+
/**
|
|
8
|
+
* Every `DatasetType`, in the spec's order. Admin 0.0.126 has no route for them, so
|
|
9
|
+
* `datasetTypes.list()` answers this list, as MCP's `list_connection_types` does.
|
|
10
|
+
*/
|
|
11
|
+
const DATASET_TYPES = [
|
|
12
|
+
'google_analytics_4',
|
|
13
|
+
'google_search_console',
|
|
14
|
+
'google_ads',
|
|
15
|
+
'google_business_profile',
|
|
16
|
+
'google_sheets',
|
|
17
|
+
'linkedin_ads',
|
|
18
|
+
'pulse',
|
|
19
|
+
'weather',
|
|
20
|
+
'meta_ads',
|
|
21
|
+
'facebook_pages',
|
|
22
|
+
'llm_scrape_chatgpt',
|
|
23
|
+
'llm_scrape_perplexity',
|
|
24
|
+
'llm_scrape_gemini',
|
|
25
|
+
'serp_scrape_google_organic',
|
|
26
|
+
'serp_scrape_google_shopping',
|
|
27
|
+
'serp_scrape_google_maps',
|
|
28
|
+
'serp_scrape_youtube',
|
|
29
|
+
];
|
|
30
|
+
// Fails to compile when DatasetType gains a type the list doesn't hold.
|
|
31
|
+
const everyType = true;
|
|
32
|
+
void everyType; // read once, so unused-locals checks keep it
|
|
33
|
+
const id = z.string().min(1);
|
|
34
|
+
// A dataset as read, in our names, so client_id is workspace_id, with the organisation it's in, so
|
|
35
|
+
// a record of another one is caught; the public Dataset drops it. An object schema keeps only the
|
|
36
|
+
// fields it names, so `secret`, `secret_id`, `parameters`, `settings`, `meta` and the embedded
|
|
37
|
+
// `client` and `organization` never reach a caller.
|
|
38
|
+
// #231: when it was made, and by whom, each null when left out; pulse-admin's empty default for the
|
|
39
|
+
// maker's id counts as left out. The embedded `created_by` is never read (#67).
|
|
40
|
+
// #293: its history, pulse-admin's `backfill` under our name (names.ts, D563), its values kept as
|
|
41
|
+
// they came. A null, a value this version doesn't know, or none at all is null, never a guess and
|
|
42
|
+
// never invalid, so a new backend value never makes a workspace's list unreadable (#265's rule).
|
|
43
|
+
// `backfill_started` and `backfill_done` are a second copy, never read.
|
|
44
|
+
const HISTORIES = ['not_available', 'todo', 'started', 'done'];
|
|
45
|
+
// Fails to compile when DatasetHistory gains a value HISTORIES doesn't hold (#303 round 2, O2.F2).
|
|
46
|
+
const everyHistory = true;
|
|
47
|
+
void everyHistory; // read once, so unused-locals checks keep it
|
|
48
|
+
const KNOWN_HISTORIES = new Set(HISTORIES);
|
|
49
|
+
const isHistory = (value) => typeof value === 'string' && KNOWN_HISTORIES.has(value);
|
|
50
|
+
// `.optional()` is what lets the key be missing: without it, zod answers a missing key "expected
|
|
51
|
+
// nonoptional" and the dataset is invalid (#303's code review, 8; the test with no backfill).
|
|
52
|
+
// The name is the record's, so `backfill` never holds one of the SDK's values (finding 9).
|
|
53
|
+
const history = z
|
|
54
|
+
.unknown()
|
|
55
|
+
.optional()
|
|
56
|
+
.transform((value) => (isHistory(value) ? value : null));
|
|
57
|
+
const zRecord = z.object({
|
|
58
|
+
id,
|
|
59
|
+
name: z.string(),
|
|
60
|
+
workspace_id: id,
|
|
61
|
+
type: z.string().min(1).nullable(),
|
|
62
|
+
active: z.boolean(),
|
|
63
|
+
organization_id: id,
|
|
64
|
+
created_on: createdOn,
|
|
65
|
+
created_by_id: createdById,
|
|
66
|
+
history,
|
|
67
|
+
});
|
|
68
|
+
const zOrganizationId = z.object({ id });
|
|
69
|
+
const publicOf = ({ id: datasetId, name, workspace_id, type, active, created_on, created_by_id, history }) => ({ id: datasetId, name, workspace_id, type, active, created_on, created_by_id, history });
|
|
70
|
+
const invalid = (issues) => ({ ok: false, error: { kind: 'invalid', issues } });
|
|
71
|
+
const refusedPath = { ok: false, error: { kind: 'refused', reason: 'path' } };
|
|
72
|
+
/**
|
|
73
|
+
* `flipstream.datasets.list()`: one page of a workspace's datasets, in the backend's own order, by
|
|
74
|
+
* name (no sort is sent, D550). The workspace is read beside the list, by `readOwnWorkspace`'s
|
|
75
|
+
* rules, so one nobody has is `not_found` and another organisation's is invalid, never an empty
|
|
76
|
+
* page. A row of another workspace is invalid, naming its place; the caller's id may be any form
|
|
77
|
+
* pulse-admin reads as the same UUID (sameUuid). A row of another organisation is invalid too,
|
|
78
|
+
* naming its place, never an id. The organisation's failure, then the workspace's, then the
|
|
79
|
+
* list's, is the answer, whichever finishes first. A bad limit or offset throws, as every list's
|
|
80
|
+
* does.
|
|
81
|
+
*/
|
|
82
|
+
export async function listDatasets(seam, read, request) {
|
|
83
|
+
const { workspace_id, ...page } = request;
|
|
84
|
+
const spec = seam.workspaceDatasets(workspace_id, page, zRecord, (dataset) => sameUuid(dataset.workspace_id, workspace_id));
|
|
85
|
+
if (spec === null)
|
|
86
|
+
return refusedPath;
|
|
87
|
+
const [own, listed] = await Promise.all([readOwnWorkspace(seam, read, workspace_id, zOrganizationId), read(spec)]);
|
|
88
|
+
if (!own.ok)
|
|
89
|
+
return own;
|
|
90
|
+
if (!listed.ok)
|
|
91
|
+
return listed;
|
|
92
|
+
const foreign = listed.data.items.findIndex((dataset) => !sameUuid(dataset.organization_id, own.data.organization.id));
|
|
93
|
+
if (foreign !== -1)
|
|
94
|
+
return invalid(`records[${String(foreign)}] is another organisation's dataset`);
|
|
95
|
+
return { ok: true, data: { ...listed.data, items: listed.data.items.map(publicOf) } };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The dataset `spec` reads, `datasetId`, read beside your organisation (D556): an answer that isn't
|
|
99
|
+
* the dataset asked for, or is another organisation's, is invalid, echoing no id. The organisation's
|
|
100
|
+
* failure, then the dataset's, is the answer. Both come back: the dataset, and your organisation, as
|
|
101
|
+
* `organizationSchema` reads it, so only the reads that need more than its id ask for more (#280).
|
|
102
|
+
*/
|
|
103
|
+
async function readOwnDataset(seam, read, spec, datasetId, organizationSchema) {
|
|
104
|
+
const [organization, dataset] = await Promise.all([read(seam.myOrganization(organizationSchema)), read(spec)]);
|
|
105
|
+
if (!organization.ok)
|
|
106
|
+
return organization;
|
|
107
|
+
if (!dataset.ok)
|
|
108
|
+
return dataset;
|
|
109
|
+
if (!sameUuid(dataset.data.id, datasetId))
|
|
110
|
+
return invalid("the dataset read isn't the one asked for");
|
|
111
|
+
if (!sameUuid(dataset.data.organization_id, organization.data.id))
|
|
112
|
+
return invalid("the dataset read is another organisation's");
|
|
113
|
+
return { ok: true, data: { dataset: dataset.data, organization: organization.data } };
|
|
114
|
+
}
|
|
115
|
+
/** `flipstream.datasets.get()`: one dataset, by its id, by `readOwnDataset`'s rules. */
|
|
116
|
+
export async function getDataset(seam, read, request) {
|
|
117
|
+
const spec = seam.dataset(request.dataset_id, zRecord);
|
|
118
|
+
if (spec === null)
|
|
119
|
+
return refusedPath;
|
|
120
|
+
const own = await readOwnDataset(seam, read, spec, request.dataset_id, zOrganizationId);
|
|
121
|
+
return own.ok ? { ok: true, data: publicOf(own.data.dataset) } : own;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* `flipstream.datasets.delete()`: a D542 hand-off (D546), as `workspaces.delete` is. The dataset is
|
|
125
|
+
* read by `readOwnDataset`'s rules, so one nobody has is `not_found` and another organisation's
|
|
126
|
+
* invalid, before any hand-off. Then `needs_person`, never a write, with the console's dataset page
|
|
127
|
+
* where a console can be named (os D1334).
|
|
128
|
+
*/
|
|
129
|
+
export async function handOffDatasetDelete(seam, read, request) {
|
|
130
|
+
const spec = seam.dataset(request.dataset_id, zRecord);
|
|
131
|
+
if (spec === null)
|
|
132
|
+
return refusedPath;
|
|
133
|
+
// Only the hand-off reads the short name, for its url; every other read takes the id alone.
|
|
134
|
+
const own = await readOwnDataset(seam, read, spec, request.dataset_id, zHandOffOrganization);
|
|
135
|
+
if (!own.ok)
|
|
136
|
+
return own;
|
|
137
|
+
return needsPerson('dataset.delete', seam.datasetPage(own.data.organization.slug, own.data.dataset.workspace_id, own.data.dataset.id));
|
|
138
|
+
}
|
|
139
|
+
/** `record` held to the dataset `was`: its id, its workspace and its organisation; null when it is. */
|
|
140
|
+
function otherThan(record, was, what) {
|
|
141
|
+
if (!sameUuid(record.id, was.id))
|
|
142
|
+
return invalid(`the dataset ${what} isn't the one asked for`);
|
|
143
|
+
if (!sameUuid(record.workspace_id, was.workspace_id))
|
|
144
|
+
return invalid(`the dataset ${what} is another workspace's`);
|
|
145
|
+
if (!sameUuid(record.organization_id, was.organization_id))
|
|
146
|
+
return invalid(`the dataset ${what} is another organisation's`);
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const stateOf = (active) => (active ? 'active' : 'paused');
|
|
150
|
+
/** A failure as far as it may be told: its kind, and its status when it has one, never a value. */
|
|
151
|
+
const kindOf = (error) => ('status' in error && error.status !== undefined ? `${error.kind} ${String(error.status)}` : error.kind);
|
|
152
|
+
// The kinds that already say a write may have been made, kept as they come after it: every other
|
|
153
|
+
// kind (a 4xx refusal, refused, no_token) would say nothing was written (#272 round 3).
|
|
154
|
+
const MAY_HAVE_WRITTEN = new Set(['timeout', 'aborted', 'cancelled', 'unavailable', 'invalid']);
|
|
155
|
+
/**
|
|
156
|
+
* `flipstream.datasets.pause()` and `resume()` (#212): `active` set as asked, by D557's rules. Before
|
|
157
|
+
* anything is sent, a key other than `dataset_id` is `refused` (`fields`), and an id that isn't a
|
|
158
|
+
* string is a TypeError. The dataset is read fresh, past pulse-admin's cache, beside your
|
|
159
|
+
* organisation (`readOwnDataset`). Then one PUT sends `{ active }` alone (os D313): the same PUT
|
|
160
|
+
* whatever it was, so each verb is idempotent. Its answer is held to the dataset, its workspace,
|
|
161
|
+
* your organisation and the `active` asked for. Then the dataset is read fresh again, and that read
|
|
162
|
+
* is the answer, held the same way: pulse-admin can answer a PUT with what was sent without storing
|
|
163
|
+
* it, so only the read shows the write held (#272 round 1). That read comes after the write was
|
|
164
|
+
* sent, so a failure of it that would say nothing was written (a 4xx kind, `refused`, `no_token`)
|
|
165
|
+
* is `invalid`, naming its kind (#272 round 2); a `timeout`, `aborted`, `cancelled`, `unavailable`
|
|
166
|
+
* or `invalid` already says the write may have been made, and keeps its kind (#272 round 3).
|
|
167
|
+
*/
|
|
168
|
+
async function setActive(seam, send, call, request, active) {
|
|
169
|
+
const refused = unsent(request, ['dataset_id']);
|
|
170
|
+
if (refused !== null)
|
|
171
|
+
return refused;
|
|
172
|
+
const { dataset_id: datasetId } = request;
|
|
173
|
+
if (typeof datasetId !== 'string')
|
|
174
|
+
throw new TypeError(`datasets.${call}: dataset_id must be a string`);
|
|
175
|
+
const fresh = seam.freshDataset(datasetId, zRecord);
|
|
176
|
+
if (fresh === null)
|
|
177
|
+
return refusedPath;
|
|
178
|
+
const stored = await readOwnDataset(seam, send, fresh, datasetId, zOrganizationId);
|
|
179
|
+
if (!stored.ok)
|
|
180
|
+
return stored;
|
|
181
|
+
const was = stored.data.dataset;
|
|
182
|
+
const spec = seam.setDatasetActive(was.id, active, zRecord);
|
|
183
|
+
const after = seam.freshDataset(was.id, zRecord);
|
|
184
|
+
if (spec === null || after === null)
|
|
185
|
+
return refusedPath;
|
|
186
|
+
const written = await send(spec);
|
|
187
|
+
if (!written.ok)
|
|
188
|
+
return written;
|
|
189
|
+
const wrong = otherThan(written.data, was, 'written');
|
|
190
|
+
if (wrong !== null)
|
|
191
|
+
return wrong;
|
|
192
|
+
if (written.data.active !== active)
|
|
193
|
+
return invalid(`the dataset written is ${stateOf(written.data.active)}, not ${stateOf(active)} as asked`);
|
|
194
|
+
const read = await send(after);
|
|
195
|
+
if (!read.ok)
|
|
196
|
+
return MAY_HAVE_WRITTEN.has(read.error.kind) ? read : invalid(`the write was sent, and the read after it failed: ${kindOf(read.error)}`);
|
|
197
|
+
const moved = otherThan(read.data, was, 'read after the write');
|
|
198
|
+
if (moved !== null)
|
|
199
|
+
return moved;
|
|
200
|
+
if (read.data.active !== active)
|
|
201
|
+
return invalid(`the dataset read after the write is ${stateOf(read.data.active)}, not ${stateOf(active)} as asked: the write may not have been stored`);
|
|
202
|
+
return { ok: true, data: publicOf(read.data) };
|
|
203
|
+
}
|
|
204
|
+
/** `flipstream.datasets.pause()`: `active` false, by `setActive`'s rules. */
|
|
205
|
+
export const pauseDataset = (seam, send, request) => setActive(seam, send, 'pause', request, false);
|
|
206
|
+
/** `flipstream.datasets.resume()`: `active` true, by `setActive`'s rules. */
|
|
207
|
+
export const resumeDataset = (seam, send, request) => setActive(seam, send, 'resume', request, true);
|
|
208
|
+
/** `flipstream.datasetTypes.list()`: the types this version knows, with no request; a copy for each caller. */
|
|
209
|
+
export function listDatasetTypes() {
|
|
210
|
+
return { ok: true, data: [...DATASET_TYPES] };
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=datasets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasets.js","sourceRoot":"","sources":["../../src/api/datasets.ts"],"names":[],"mappings":"A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AAC,CAAC,OAAO,CAAC,qDAAqD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACtJ,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,sBAAsB,CAAC,CAAA;IAC/D,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAChC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,OAAO,CAAC,uCAAuC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,+CAA+C,CAAC,CAAA;IACxL,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAChD,CAAC;AAED,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAa,EAAE,IAAU,EAAE,OAAwC,EAA+B,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;AAEhL,6EAA6E;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAa,EAAE,IAAU,EAAE,OAAwC,EAA+B,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AAEjL,+GAA+G;AAC/G,MAAM,UAAU,gBAAgB;IAC9B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ApiResult, HandOffAction } from '../core/result.js';
|
|
3
|
+
/**
|
|
4
|
+
* Your organisation as a hand-off reads it from `/organizations/me`: its id, for D556's checks, and
|
|
5
|
+
* its short name, for the console's address. One schema for every hand-off, so they all accept the
|
|
6
|
+
* same answers (#281).
|
|
7
|
+
*/
|
|
8
|
+
export declare const zHandOffOrganization: z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
slug: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
/** Why a person does it, and what they will see at its page. */
|
|
13
|
+
declare const WORDS: {
|
|
14
|
+
readonly [A in Extract<HandOffAction, 'workspace.rename' | 'workspace.delete' | 'dataset.delete' | 'organization.rename'>]: {
|
|
15
|
+
readonly why: string;
|
|
16
|
+
readonly sees: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** A hand-off whose console page can be named. */
|
|
20
|
+
export type PagedHandOff = keyof typeof WORDS;
|
|
21
|
+
export type WorkspaceHandOff = Extract<PagedHandOff, 'workspace.rename' | 'workspace.delete'>;
|
|
22
|
+
/** The hand-off for `action`, with `url` and what it shows when there is a page to send the person to. */
|
|
23
|
+
export declare function needsPerson(action: PagedHandOff, url: string | undefined): ApiResult<never>;
|
|
24
|
+
/**
|
|
25
|
+
* Why a person does a sign-in's revoke or delete (#70, D546). No console page names a sign-in yet,
|
|
26
|
+
* so these give `why` alone, with no `url`, until the os lead names one.
|
|
27
|
+
*/
|
|
28
|
+
declare const CREDENTIAL_WORDS: {
|
|
29
|
+
readonly [A in Extract<HandOffAction, 'credential.revoke' | 'credential.delete'>]: string;
|
|
30
|
+
};
|
|
31
|
+
export type CredentialHandOff = keyof typeof CREDENTIAL_WORDS;
|
|
32
|
+
/** The hand-off for a sign-in's `action`: why, and no `url`, since no console page names a sign-in yet. */
|
|
33
|
+
export declare function credentialNeedsPerson(action: CredentialHandOff): ApiResult<never>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/*
|
|
3
|
+
* D542's hand-offs: a call that is a person's to do answers `needs_person`, with why and, where the
|
|
4
|
+
* console can be named, where. The words are the SDK's own, in plain British English, never a
|
|
5
|
+
* value the caller gave. Each hand-off adds its row here; the addresses are the transport module's.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Your organisation as a hand-off reads it from `/organizations/me`: its id, for D556's checks, and
|
|
9
|
+
* its short name, for the console's address. One schema for every hand-off, so they all accept the
|
|
10
|
+
* same answers (#281).
|
|
11
|
+
*/
|
|
12
|
+
export const zHandOffOrganization = z.object({ id: z.string().min(1), slug: z.string() });
|
|
13
|
+
/** Why a person does it, and what they will see at its page. */
|
|
14
|
+
const WORDS = {
|
|
15
|
+
'workspace.rename': {
|
|
16
|
+
why: "Renaming a workspace is done by a person, in the workspace's settings in the console.",
|
|
17
|
+
sees: "The workspace's settings, where its name and short name can be changed.",
|
|
18
|
+
},
|
|
19
|
+
'workspace.delete': {
|
|
20
|
+
why: "Deleting a workspace needs a person to confirm it in the console, and the console can't delete a workspace yet.",
|
|
21
|
+
sees: "The workspace's settings. There's no delete there yet.",
|
|
22
|
+
},
|
|
23
|
+
// #225: the organisation's settings page (os 744add09, $org.o.settings), where Owners and Admins
|
|
24
|
+
// change its name and short name.
|
|
25
|
+
'organization.rename': {
|
|
26
|
+
why: "Renaming your organisation is done by a person, in the organisation's settings in the console.",
|
|
27
|
+
sees: "The organisation's settings, where Owners and Admins change its name and short name.",
|
|
28
|
+
},
|
|
29
|
+
// #217: the os console's Dataset page has no delete yet (os 744add09).
|
|
30
|
+
'dataset.delete': {
|
|
31
|
+
why: "Deleting a dataset removes its data for good, so a person confirms it in the console, and the console can't delete a dataset yet.",
|
|
32
|
+
sees: "The dataset's page in the warehouse. There's no delete there yet.",
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
/** The hand-off for `action`, with `url` and what it shows when there is a page to send the person to. */
|
|
36
|
+
export function needsPerson(action, url) {
|
|
37
|
+
const { why, sees } = WORDS[action];
|
|
38
|
+
return { ok: false, error: url === undefined ? { kind: 'needs_person', action, why } : { kind: 'needs_person', action, why, url, sees } };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Why a person does a sign-in's revoke or delete (#70, D546). No console page names a sign-in yet,
|
|
42
|
+
* so these give `why` alone, with no `url`, until the os lead names one.
|
|
43
|
+
*/
|
|
44
|
+
const CREDENTIAL_WORDS = {
|
|
45
|
+
'credential.revoke': 'Revoking a sign-in breaks every dataset that reads with it, so a person confirms it in the console.',
|
|
46
|
+
'credential.delete': 'Deleting a sign-in breaks every dataset that reads with it, so a person confirms it in the console.',
|
|
47
|
+
};
|
|
48
|
+
/** The hand-off for a sign-in's `action`: why, and no `url`, since no console page names a sign-in yet. */
|
|
49
|
+
export function credentialNeedsPerson(action) {
|
|
50
|
+
return { ok: false, error: { kind: 'needs_person', action, why: CREDENTIAL_WORDS[action] } };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=handoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/api/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAEzF,gEAAgE;AAChE,MAAM,KAAK,GAAoL;IAC7L,kBAAkB,EAAE;QAClB,GAAG,EAAE,uFAAuF;QAC5F,IAAI,EAAE,yEAAyE;KAChF;IACD,kBAAkB,EAAE;QAClB,GAAG,EAAE,iHAAiH;QACtH,IAAI,EAAE,wDAAwD;KAC/D;IACD,iGAAiG;IACjG,kCAAkC;IAClC,qBAAqB,EAAE;QACrB,GAAG,EAAE,gGAAgG;QACrG,IAAI,EAAE,sFAAsF;KAC7F;IACD,uEAAuE;IACvE,gBAAgB,EAAE;QAChB,GAAG,EAAE,mIAAmI;QACxI,IAAI,EAAE,mEAAmE;KAC1E;CACF,CAAA;AAMD,0GAA0G;AAC1G,MAAM,UAAU,WAAW,CAAC,MAAoB,EAAE,GAAuB;IACvE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IACnC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAA;AAC3I,CAAC;AAED;;;GAGG;AACH,MAAM,gBAAgB,GAAkG;IACtH,mBAAmB,EAAE,qGAAqG;IAC1H,mBAAmB,EAAE,qGAAqG;CAC3H,CAAA;AAID,2GAA2G;AAC3G,MAAM,UAAU,qBAAqB,CAAC,MAAyB;IAC7D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;AAC9F,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `a` and `b` name the same record. Two UUIDs are the same when their canonical forms match:
|
|
3
|
+
* lowercase, with no `urn:uuid:` before them, no braces round them and no hyphens, as pulse-admin's
|
|
4
|
+
* UUID parsing reads them. Any other value compares exactly as given, case and hyphens included,
|
|
5
|
+
* and is never the same as a UUID.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sameUuid(a: string, b: string): boolean;
|
package/dist/api/ids.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The seam's one id comparison (#243). pulse-admin's routes read an id path segment as a UUID
|
|
3
|
+
* (FastAPI's `UUID`, pulse-admin 72ec7ef, through pydantic v2's parsing, the uuid crate's
|
|
4
|
+
* parse_str), which takes capitals, braces, no hyphens and a `urn:uuid:` prefix (#245), and answer
|
|
5
|
+
* with the canonical lowercase form. So an id a caller gave and the id an answer carries are compared
|
|
6
|
+
* here, never with `===`, by every read that checks the answer is the record asked for.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* `id`'s canonical form when it's a UUID (lowercase, no `urn:uuid:`, no braces, no hyphens), or null
|
|
10
|
+
* when it isn't one.
|
|
11
|
+
*/
|
|
12
|
+
function canonical(id) {
|
|
13
|
+
const bare = id.toLowerCase().replace(/^urn:uuid:/, '').replace(/^\{(.*)\}$/, '$1').replaceAll('-', '');
|
|
14
|
+
return /^[0-9a-f]{32}$/.test(bare) ? bare : null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Whether `a` and `b` name the same record. Two UUIDs are the same when their canonical forms match:
|
|
18
|
+
* lowercase, with no `urn:uuid:` before them, no braces round them and no hyphens, as pulse-admin's
|
|
19
|
+
* UUID parsing reads them. Any other value compares exactly as given, case and hyphens included,
|
|
20
|
+
* and is never the same as a UUID.
|
|
21
|
+
*/
|
|
22
|
+
export function sameUuid(a, b) {
|
|
23
|
+
const left = canonical(a);
|
|
24
|
+
const right = canonical(b);
|
|
25
|
+
return left === null || right === null ? a === b : left === right;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/api/ids.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,SAAS,SAAS,CAAC,EAAU;IAC3B,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACvG,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IAC1B,OAAO,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAA;AACnE,CAAC"}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export type { Credential } from './credentials.js';
|
|
2
|
+
export type { Dataset, DatasetHistory, DatasetListRequest, DatasetType } from './datasets.js';
|
|
3
|
+
export type { LogAddRequest, LogEntry, LogListRequest, LogUpdateRequest } from './log.js';
|
|
4
|
+
export type { Me, Organization, OrganizationAccess } from './me.js';
|
|
5
|
+
export type { Member } from './members.js';
|
|
6
|
+
export type { Page, PageRequest } from './page.js';
|
|
7
|
+
export type { Balance, Ledger, Transaction } from './wallet.js';
|
|
8
|
+
export type { Workspace } from './workspaces.js';
|
|
9
|
+
export type { Role } from '../core/names.js';
|