@elaraai/e3-cloud-client 0.0.0-stage → 1.0.90

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.
Files changed (63) hide show
  1. package/LICENSE.md +54 -0
  2. package/README.md +238 -2
  3. package/dist/src/admin-users.d.ts +36 -0
  4. package/dist/src/admin-users.d.ts.map +1 -0
  5. package/dist/src/admin-users.js +56 -0
  6. package/dist/src/admin-users.js.map +1 -0
  7. package/dist/src/apps.d.ts +210 -0
  8. package/dist/src/apps.d.ts.map +1 -0
  9. package/dist/src/apps.js +265 -0
  10. package/dist/src/apps.js.map +1 -0
  11. package/dist/src/deployment-settings.d.ts +63 -0
  12. package/dist/src/deployment-settings.d.ts.map +1 -0
  13. package/dist/src/deployment-settings.js +79 -0
  14. package/dist/src/deployment-settings.js.map +1 -0
  15. package/dist/src/feedback.d.ts +132 -0
  16. package/dist/src/feedback.d.ts.map +1 -0
  17. package/dist/src/feedback.js +166 -0
  18. package/dist/src/feedback.js.map +1 -0
  19. package/dist/src/history.d.ts +126 -0
  20. package/dist/src/history.d.ts.map +1 -0
  21. package/dist/src/history.js +144 -0
  22. package/dist/src/history.js.map +1 -0
  23. package/dist/src/index.d.ts +64 -0
  24. package/dist/src/index.d.ts.map +1 -0
  25. package/dist/src/index.js +67 -0
  26. package/dist/src/index.js.map +1 -0
  27. package/dist/src/invitations.d.ts +17 -0
  28. package/dist/src/invitations.d.ts.map +1 -0
  29. package/dist/src/invitations.js +31 -0
  30. package/dist/src/invitations.js.map +1 -0
  31. package/dist/src/me.d.ts +11 -0
  32. package/dist/src/me.d.ts.map +1 -0
  33. package/dist/src/me.js +18 -0
  34. package/dist/src/me.js.map +1 -0
  35. package/dist/src/records.d.ts +127 -0
  36. package/dist/src/records.d.ts.map +1 -0
  37. package/dist/src/records.js +226 -0
  38. package/dist/src/records.js.map +1 -0
  39. package/dist/src/roles.d.ts +72 -0
  40. package/dist/src/roles.d.ts.map +1 -0
  41. package/dist/src/roles.js +95 -0
  42. package/dist/src/roles.js.map +1 -0
  43. package/dist/src/schedules.d.ts +25 -0
  44. package/dist/src/schedules.d.ts.map +1 -0
  45. package/dist/src/schedules.js +45 -0
  46. package/dist/src/schedules.js.map +1 -0
  47. package/dist/src/secrets.d.ts +20 -0
  48. package/dist/src/secrets.d.ts.map +1 -0
  49. package/dist/src/secrets.js +37 -0
  50. package/dist/src/secrets.js.map +1 -0
  51. package/dist/src/task-configs.d.ts +101 -0
  52. package/dist/src/task-configs.d.ts.map +1 -0
  53. package/dist/src/task-configs.js +157 -0
  54. package/dist/src/task-configs.js.map +1 -0
  55. package/dist/src/user-settings.d.ts +34 -0
  56. package/dist/src/user-settings.d.ts.map +1 -0
  57. package/dist/src/user-settings.js +83 -0
  58. package/dist/src/user-settings.js.map +1 -0
  59. package/dist/src/users.d.ts +84 -0
  60. package/dist/src/users.d.ts.map +1 -0
  61. package/dist/src/users.js +100 -0
  62. package/dist/src/users.js.map +1 -0
  63. package/package.json +23 -3
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * Invitation API functions using BEAST2 format.
7
+ *
8
+ * Invitations are created implicitly by the add-user flow when the email has
9
+ * never logged in (the response's userId carries the `invited:` sentinel);
10
+ * these functions give admins visibility and revocation.
11
+ */
12
+ import { NullType } from '@elaraai/east';
13
+ import { InvitationListType } from '@elaraai/e3-cloud-types';
14
+ import { get, del } from '@elaraai/e3-api-client';
15
+ /**
16
+ * List all invitations (admin only), newest first.
17
+ */
18
+ export async function listInvitations(url, options) {
19
+ return get(url, '/admin/invitations', InvitationListType, options);
20
+ }
21
+ /**
22
+ * Revoke a pending invitation (admin only). No-op on absent/claimed.
23
+ */
24
+ export async function revokeInvitation(url, email, options) {
25
+ await del(url, `/admin/invitations/${encodeURIComponent(email.toLowerCase())}`, NullType, options);
26
+ }
27
+ /** Whether an add-user response denotes a recorded invitation (not yet a member). */
28
+ export function isInvitedSentinel(userId) {
29
+ return userId.startsWith('invited:');
30
+ }
31
+ //# sourceMappingURL=invitations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invitations.js","sourceRoot":"","sources":["../../src/invitations.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAuB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAuB,MAAM,wBAAwB,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW,EAAE,OAAuB;IACxE,OAAO,GAAG,CAAC,GAAG,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAW,EAAE,KAAa,EAAE,OAAuB;IACxF,MAAM,GAAG,CAAC,GAAG,EAAE,sBAAsB,kBAAkB,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACrG,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ import { type AdminUserMembership } from '@elaraai/e3-cloud-types';
6
+ import { type RequestOptions } from '@elaraai/e3-api-client';
7
+ /**
8
+ * List the caller's own repo memberships (any authenticated user).
9
+ */
10
+ export declare function myMemberships(url: string, options: RequestOptions): Promise<AdminUserMembership[]>;
11
+ //# sourceMappingURL=me.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../src/me.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAO,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAElE;;GAEG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAExG"}
package/dist/src/me.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * Self-scoped API functions using BEAST2 format: what the caller can know
7
+ * about themselves beyond whoami.
8
+ */
9
+ import { ArrayType } from '@elaraai/east';
10
+ import { AdminUserMembershipType } from '@elaraai/e3-cloud-types';
11
+ import { get } from '@elaraai/e3-api-client';
12
+ /**
13
+ * List the caller's own repo memberships (any authenticated user).
14
+ */
15
+ export async function myMemberships(url, options) {
16
+ return get(url, '/me/memberships', ArrayType(AdminUserMembershipType), options);
17
+ }
18
+ //# sourceMappingURL=me.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"me.js","sourceRoot":"","sources":["../../src/me.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAA4B,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,GAAG,EAAuB,MAAM,wBAAwB,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAW,EAAE,OAAuB;IACtE,OAAO,GAAG,CAAC,GAAG,EAAE,iBAAiB,EAAE,SAAS,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ import { type RecordList, type RecordAuditPage, type RecordBackupInfo, type RecordBackupList, type RecordBackupDownload, type RecordRollbackRequest, type RecordRestoreRequest } from '@elaraai/e3-cloud-types';
6
+ import { type DatasetPage, type RequestOptions, type MutationResult } from '@elaraai/e3-api-client';
7
+ /** Channel tag for the audit index's `source` field. */
8
+ export type RecordClientSource = 'web' | 'cli';
9
+ /**
10
+ * List a workspace's records with head commit info and backup counts.
11
+ */
12
+ export declare function listRecordInfos(url: string, repo: string, ws: string, options: RequestOptions): Promise<RecordList>;
13
+ /**
14
+ * Fetch one page of a record's durable audit index, newest first. Unlike the
15
+ * chain-walk history endpoint, entries survive `$compact` + GC.
16
+ *
17
+ * @param opts.limit - Page size (server default 50, cap 200)
18
+ * @param opts.before - Opaque cursor from a prior page's `nextBefore`
19
+ */
20
+ export declare function recordAudit(url: string, repo: string, ws: string, record: string, options: RequestOptions, opts?: {
21
+ limit?: number;
22
+ before?: string;
23
+ }): Promise<RecordAuditPage>;
24
+ /**
25
+ * A value's bytes, in order, from where the server says it is: one object
26
+ * (`objectGet`), or a collection's manifest, whose header and segments are
27
+ * fetched a few at a time ahead of the splice that joins them
28
+ * (`collectionGetStream`), each checked against its hash. The caller holds the
29
+ * segments in flight, never the value.
30
+ *
31
+ * @param url - Base URL of the e3 API server
32
+ * @param repo - Repository name
33
+ * @param value - Where the value is (a backup download's `value`)
34
+ * @param options - Request options including auth token
35
+ * @returns The value's bytes, a chunk at a time
36
+ */
37
+ export declare function recordValueChunks(url: string, repo: string, value: RecordBackupDownload['value'], options: RequestOptions): Promise<AsyncIterable<Uint8Array>>;
38
+ /**
39
+ * A record's value at a commit: whole, or — for a collection too large to
40
+ * answer in one response — how many rows it has, to read by pages
41
+ * ({@link recordStatePage}), and the manifest it can be downloaded by
42
+ * ({@link recordValueChunks}).
43
+ */
44
+ export type RecordStateAt = {
45
+ kind: 'value';
46
+ stateHash: string;
47
+ data: Uint8Array;
48
+ } | {
49
+ kind: 'pages';
50
+ stateHash: string;
51
+ rows: number;
52
+ bytes: number;
53
+ manifest: string;
54
+ };
55
+ /**
56
+ * Read a record's value at a commit. A value is self-describing beast2:
57
+ * decode it with `decodeBeast2`. A large value that is no collection is
58
+ * fetched through the objects route, whole.
59
+ */
60
+ export declare function recordStateAt(url: string, repo: string, ws: string, record: string, commitHash: string, options: RequestOptions): Promise<RecordStateAt>;
61
+ /**
62
+ * Read one page of a record's collection at a commit: its window, a beast2
63
+ * value of the type the collection is stored as, clamped by the server's byte
64
+ * budget, read as e3-api-client reads a dataset's page (`parsePage`). A
65
+ * commit's state never changes, so a page is immutable.
66
+ *
67
+ * @param window.offset - The first row (Array order, or Set/Dict key order)
68
+ * @param window.limit - The most rows (the server may answer fewer)
69
+ * @throws {ApiError} A page's refusal, as the server names it (a malformed
70
+ * window `bad_request`, a state that holds no collection), or the history's
71
+ * (a commit not in the record's history)
72
+ */
73
+ export declare function recordStatePage(url: string, repo: string, ws: string, record: string, commitHash: string, window: {
74
+ offset: number;
75
+ limit: number;
76
+ }, options: RequestOptions): Promise<DatasetPage>;
77
+ /**
78
+ * Roll a record back to a historical commit via an audited `$rollback`
79
+ * commit (roll-forward: history is preserved and downstream dataflow
80
+ * re-runs). Refused, with the reason, past a migration or to a commit a
81
+ * compaction cut from the chain. Owner/admin only.
82
+ */
83
+ export declare function rollbackRecord(url: string, repo: string, ws: string, record: string, req: RecordRollbackRequest, options: RequestOptions, source?: RecordClientSource): Promise<MutationResult>;
84
+ /**
85
+ * List a record's backups, newest first.
86
+ */
87
+ export declare function listRecordBackups(url: string, repo: string, ws: string, record: string, options: RequestOptions): Promise<RecordBackupList>;
88
+ /**
89
+ * Back up a record's current head: a row naming its state, which the
90
+ * platform keeps while the backup exists. Owner/admin only.
91
+ */
92
+ export declare function createRecordBackup(url: string, repo: string, ws: string, record: string, req: {
93
+ note?: string;
94
+ }, options: RequestOptions, source?: RecordClientSource): Promise<RecordBackupInfo>;
95
+ /**
96
+ * Restore a backup: an audited `$restore` commit pointing the record at the
97
+ * backup's state. Refused, with the reason, when the record's migrations or
98
+ * type are not the backup's. Owner/admin only.
99
+ */
100
+ export declare function restoreRecordBackup(url: string, repo: string, ws: string, record: string, id: string, req: RecordRestoreRequest, options: RequestOptions, source?: RecordClientSource): Promise<MutationResult>;
101
+ /**
102
+ * Where a backup's value is: the state it names, and the object holding the
103
+ * value (a collection's manifest, or one object). Owner/admin only.
104
+ */
105
+ export declare function recordBackupDownload(url: string, repo: string, ws: string, record: string, id: string, options: RequestOptions): Promise<RecordBackupDownload>;
106
+ /**
107
+ * A backup's value, a chunk at a time: a plain beast2 value of the record's
108
+ * type, downloaded by segments. For a caller that writes it to a file.
109
+ * Owner/admin only.
110
+ */
111
+ export declare function recordBackupStream(url: string, repo: string, ws: string, record: string, id: string, options: RequestOptions): Promise<{
112
+ stateHash: string;
113
+ chunks: AsyncIterable<Uint8Array>;
114
+ }>;
115
+ /**
116
+ * A backup's value, whole: a plain beast2 value of the record's type,
117
+ * downloaded by segments. Owner/admin only.
118
+ */
119
+ export declare function recordBackupValue(url: string, repo: string, ws: string, record: string, id: string, options: RequestOptions): Promise<{
120
+ stateHash: string;
121
+ data: Uint8Array;
122
+ }>;
123
+ /**
124
+ * Delete one backup, releasing its state. Owner/admin only.
125
+ */
126
+ export declare function deleteRecordBackup(url: string, repo: string, ws: string, record: string, id: string, options: RequestOptions): Promise<void>;
127
+ //# sourceMappingURL=records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../src/records.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAsBH,OAAO,EASL,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAE1B,MAAM,yB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+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * Record history, rollback and backup API functions using
7
+ * BEAST2 format. These extend the base record surface from
8
+ * `@elaraai/e3-api-client` (describe/mutate/history/compact) with the cloud's
9
+ * operator features: the durable audit index (survives `$compact` + GC),
10
+ * the record's value at a commit (whole, or by pages), `$rollback`/`$restore`
11
+ * commits, and backups: rows naming states, whose values download by
12
+ * segments.
13
+ *
14
+ * The mutating functions accept a `source` channel tag sent as the
15
+ * `X-E3-Client` header — recorded on the audit entry (`web` from the UI,
16
+ * `cli` from e3-cloud CLI; omitted ⇒ shown as plain api access).
17
+ *
18
+ * A value named by its hash is read as e3-api-client reads one
19
+ * (east-workspace#1057): an object with `objectGet`, a collection by its
20
+ * manifest with `collectionGetStream`, a page with `parsePage`, and a refusal
21
+ * answered in JSON with `parseErrorBody`.
22
+ */
23
+ import { NullType, decodeBeast2For, some, none } from '@elaraai/east';
24
+ import { RecordListType, RecordAuditPageType, RecordRollbackRequestType, RecordBackupInfoType, RecordBackupListType, RecordBackupCreateRequestType, RecordRestoreRequestType, RecordBackupDownloadType, } from '@elaraai/e3-cloud-types';
25
+ import { BEAST2_CONTENT_TYPE, ResponseType, MutationResultType } from '@elaraai/e3-types';
26
+ import { get, post, del, fetchWithAuth, objectGet, collectionGetStream, parsePage, parseErrorBody, ApiError, } from '@elaraai/e3-api-client';
27
+ const enc = encodeURIComponent;
28
+ const recordsBase = (repo, ws) => `/repos/${enc(repo)}/workspaces/${enc(ws)}/records`;
29
+ const recordBase = (repo, ws, record) => `${recordsBase(repo, ws)}/${enc(record)}`;
30
+ const sourceHeaders = (source) => source !== undefined ? { 'X-E3-Client': source } : undefined;
31
+ /**
32
+ * List a workspace's records with head commit info and backup counts.
33
+ */
34
+ export async function listRecordInfos(url, repo, ws, options) {
35
+ return get(url, recordsBase(repo, ws), RecordListType, options);
36
+ }
37
+ /**
38
+ * Fetch one page of a record's durable audit index, newest first. Unlike the
39
+ * chain-walk history endpoint, entries survive `$compact` + GC.
40
+ *
41
+ * @param opts.limit - Page size (server default 50, cap 200)
42
+ * @param opts.before - Opaque cursor from a prior page's `nextBefore`
43
+ */
44
+ export async function recordAudit(url, repo, ws, record, options, opts = {}) {
45
+ const params = new URLSearchParams();
46
+ if (opts.limit !== undefined)
47
+ params.set('limit', String(opts.limit));
48
+ if (opts.before !== undefined)
49
+ params.set('before', opts.before);
50
+ const query = params.toString();
51
+ return get(url, `${recordBase(repo, ws, record)}/audit${query ? `?${query}` : ''}`, RecordAuditPageType, options);
52
+ }
53
+ const decodeNullResponse = decodeBeast2For(ResponseType(NullType));
54
+ /** The error a response carries that is not the answer asked for: a JSON
55
+ * refusal, read as the rest of the client reads one, or the server's beast2
56
+ * error envelope. */
57
+ async function responseError(response) {
58
+ if (!response.ok)
59
+ return parseErrorBody(await response.text(), `http_${response.status}`);
60
+ try {
61
+ const decoded = decodeNullResponse(new Uint8Array(await response.arrayBuffer()));
62
+ if (decoded.type === 'error')
63
+ return new ApiError(decoded.value.type, decoded.value.value);
64
+ }
65
+ catch {
66
+ // Not an envelope either
67
+ }
68
+ return new ApiError('unexpected_response', { status: response.status });
69
+ }
70
+ /**
71
+ * A value's bytes, in order, from where the server says it is: one object
72
+ * (`objectGet`), or a collection's manifest, whose header and segments are
73
+ * fetched a few at a time ahead of the splice that joins them
74
+ * (`collectionGetStream`), each checked against its hash. The caller holds the
75
+ * segments in flight, never the value.
76
+ *
77
+ * @param url - Base URL of the e3 API server
78
+ * @param repo - Repository name
79
+ * @param value - Where the value is (a backup download's `value`)
80
+ * @param options - Request options including auth token
81
+ * @returns The value's bytes, a chunk at a time
82
+ */
83
+ export async function recordValueChunks(url, repo, value, options) {
84
+ if (value.type === 'object')
85
+ return inHand([await objectGet(url, repo, value.value, options)]);
86
+ return collectionGetStream(url, repo, value.value, options);
87
+ }
88
+ /** Chunks already in hand, as an async iterable. */
89
+ function inHand(chunks) {
90
+ return {
91
+ [Symbol.asyncIterator]() {
92
+ let next = 0;
93
+ return {
94
+ next: () => Promise.resolve(next < chunks.length
95
+ ? { done: false, value: chunks[next++] }
96
+ : { done: true, value: undefined }),
97
+ };
98
+ },
99
+ };
100
+ }
101
+ /** An iterable's chunks, as one array. */
102
+ async function collect(chunks) {
103
+ const parts = [];
104
+ let size = 0;
105
+ for await (const chunk of chunks) {
106
+ parts.push(chunk);
107
+ size += chunk.length;
108
+ }
109
+ if (parts.length === 1)
110
+ return parts[0];
111
+ const out = new Uint8Array(size);
112
+ let at = 0;
113
+ for (const part of parts) {
114
+ out.set(part, at);
115
+ at += part.length;
116
+ }
117
+ return out;
118
+ }
119
+ /**
120
+ * Read a record's value at a commit. A value is self-describing beast2:
121
+ * decode it with `decodeBeast2`. A large value that is no collection is
122
+ * fetched through the objects route, whole.
123
+ */
124
+ export async function recordStateAt(url, repo, ws, record, commitHash, options) {
125
+ const response = await fetchWithAuth(`${url}/api${recordBase(repo, ws, record)}/commits/${enc(commitHash)}/state`, {
126
+ method: 'GET',
127
+ headers: { Accept: BEAST2_CONTENT_TYPE },
128
+ }, options);
129
+ if (response.ok && (response.headers.get('Content-Type') ?? '').includes('application/json')) {
130
+ const body = await response.json();
131
+ if (body.object !== undefined) {
132
+ return { kind: 'value', stateHash: body.stateHash, data: await objectGet(url, repo, body.object, options) };
133
+ }
134
+ return { kind: 'pages', stateHash: body.stateHash, rows: body.rows ?? 0, bytes: body.bytes, manifest: body.manifest ?? '' };
135
+ }
136
+ const stateHash = response.headers.get('X-Content-SHA256');
137
+ if (response.ok && stateHash !== null)
138
+ return { kind: 'value', stateHash, data: new Uint8Array(await response.arrayBuffer()) };
139
+ throw await responseError(response);
140
+ }
141
+ /**
142
+ * Read one page of a record's collection at a commit: its window, a beast2
143
+ * value of the type the collection is stored as, clamped by the server's byte
144
+ * budget, read as e3-api-client reads a dataset's page (`parsePage`). A
145
+ * commit's state never changes, so a page is immutable.
146
+ *
147
+ * @param window.offset - The first row (Array order, or Set/Dict key order)
148
+ * @param window.limit - The most rows (the server may answer fewer)
149
+ * @throws {ApiError} A page's refusal, as the server names it (a malformed
150
+ * window `bad_request`, a state that holds no collection), or the history's
151
+ * (a commit not in the record's history)
152
+ */
153
+ export async function recordStatePage(url, repo, ws, record, commitHash, window, options) {
154
+ const params = new URLSearchParams({ page: 'true', offset: String(window.offset), limit: String(window.limit) });
155
+ const response = await fetchWithAuth(`${url}/api${recordBase(repo, ws, record)}/commits/${enc(commitHash)}/state?${params.toString()}`, {
156
+ method: 'GET',
157
+ headers: { Accept: BEAST2_CONTENT_TYPE },
158
+ }, options);
159
+ if (!response.ok || response.headers.get('X-Page-Count') === null)
160
+ throw await responseError(response);
161
+ return parsePage(response);
162
+ }
163
+ /**
164
+ * Roll a record back to a historical commit via an audited `$rollback`
165
+ * commit (roll-forward: history is preserved and downstream dataflow
166
+ * re-runs). Refused, with the reason, past a migration or to a commit a
167
+ * compaction cut from the chain. Owner/admin only.
168
+ */
169
+ export async function rollbackRecord(url, repo, ws, record, req, options, source) {
170
+ return post(url, `${recordBase(repo, ws, record)}/rollback`, req, RecordRollbackRequestType, MutationResultType, options, sourceHeaders(source));
171
+ }
172
+ /**
173
+ * List a record's backups, newest first.
174
+ */
175
+ export async function listRecordBackups(url, repo, ws, record, options) {
176
+ return get(url, `${recordBase(repo, ws, record)}/backups`, RecordBackupListType, options);
177
+ }
178
+ /**
179
+ * Back up a record's current head: a row naming its state, which the
180
+ * platform keeps while the backup exists. Owner/admin only.
181
+ */
182
+ export async function createRecordBackup(url, repo, ws, record, req, options, source) {
183
+ const body = {
184
+ note: req.note !== undefined ? some(req.note) : none,
185
+ };
186
+ return post(url, `${recordBase(repo, ws, record)}/backups`, body, RecordBackupCreateRequestType, RecordBackupInfoType, options, sourceHeaders(source));
187
+ }
188
+ /**
189
+ * Restore a backup: an audited `$restore` commit pointing the record at the
190
+ * backup's state. Refused, with the reason, when the record's migrations or
191
+ * type are not the backup's. Owner/admin only.
192
+ */
193
+ export async function restoreRecordBackup(url, repo, ws, record, id, req, options, source) {
194
+ return post(url, `${recordBase(repo, ws, record)}/backups/${enc(id)}/restore`, req, RecordRestoreRequestType, MutationResultType, options, sourceHeaders(source));
195
+ }
196
+ /**
197
+ * Where a backup's value is: the state it names, and the object holding the
198
+ * value (a collection's manifest, or one object). Owner/admin only.
199
+ */
200
+ export async function recordBackupDownload(url, repo, ws, record, id, options) {
201
+ return get(url, `${recordBase(repo, ws, record)}/backups/${enc(id)}/download`, RecordBackupDownloadType, options);
202
+ }
203
+ /**
204
+ * A backup's value, a chunk at a time: a plain beast2 value of the record's
205
+ * type, downloaded by segments. For a caller that writes it to a file.
206
+ * Owner/admin only.
207
+ */
208
+ export async function recordBackupStream(url, repo, ws, record, id, options) {
209
+ const where = await recordBackupDownload(url, repo, ws, record, id, options);
210
+ return { stateHash: where.stateHash, chunks: await recordValueChunks(url, repo, where.value, options) };
211
+ }
212
+ /**
213
+ * A backup's value, whole: a plain beast2 value of the record's type,
214
+ * downloaded by segments. Owner/admin only.
215
+ */
216
+ export async function recordBackupValue(url, repo, ws, record, id, options) {
217
+ const { stateHash, chunks } = await recordBackupStream(url, repo, ws, record, id, options);
218
+ return { stateHash, data: await collect(chunks) };
219
+ }
220
+ /**
221
+ * Delete one backup, releasing its state. Owner/admin only.
222
+ */
223
+ export async function deleteRecordBackup(url, repo, ws, record, id, options) {
224
+ await del(url, `${recordBase(repo, ws, record)}/backups/${enc(id)}`, NullType, options);
225
+ }
226
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/records.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,oBAAo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AE,EAAE,OAAO,CAAC,CAAC;IAC3F,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,GAAW,EACX,IAAY,EACZ,EAAU,EACV,MAAc,EACd,EAAU,EACV,OAAuB;IAEvB,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ import { type BusinessRole, type MyAccess, type RolePreview } from '@elaraai/e3-cloud-types';
6
+ import { type RequestOptions } from '@elaraai/e3-api-client';
7
+ /**
8
+ * A repository's business roles, by name (owner or admin).
9
+ *
10
+ * @param url - Base URL of the e3 API server
11
+ * @param repo - Repository name
12
+ * @param options - Request options including auth token
13
+ * @returns The roles
14
+ */
15
+ export declare function listRoles(url: string, repo: string, options: RequestOptions): Promise<BusinessRole[]>;
16
+ /**
17
+ * A business role (owner or admin).
18
+ *
19
+ * @param url - Base URL of the e3 API server
20
+ * @param repo - Repository name
21
+ * @param name - The role's name
22
+ * @param options - Request options including auth token
23
+ * @returns The role
24
+ * @throws When the repository has no role of the name (404 `not_found`)
25
+ */
26
+ export declare function getRole(url: string, repo: string, name: string, options: RequestOptions): Promise<BusinessRole>;
27
+ /**
28
+ * Writes a business role whole, made or replaced (owner or admin). Refused
29
+ * (400) for a name no role may have, a grant of the same app twice, of no
30
+ * page or a page twice, or of an app or page the repository does not have.
31
+ *
32
+ * @param url - Base URL of the e3 API server
33
+ * @param repo - Repository name
34
+ * @param role - The role
35
+ * @param options - Request options including auth token
36
+ * @returns The role, as stored
37
+ */
38
+ export declare function putRole(url: string, repo: string, role: BusinessRole, options: RequestOptions): Promise<BusinessRole>;
39
+ /**
40
+ * Removes a business role, idempotently (owner or admin). Refused (409
41
+ * `role_in_use`) while anyone of the repository holds it.
42
+ *
43
+ * @param url - Base URL of the e3 API server
44
+ * @param repo - Repository name
45
+ * @param name - The role's name
46
+ * @param options - Request options including auth token
47
+ */
48
+ export declare function deleteRole(url: string, repo: string, name: string, options: RequestOptions): Promise<void>;
49
+ /**
50
+ * What a user holding one role of a repository, and nothing else, gets
51
+ * (owner or admin; "Preview as role"): the apps their sidebar lists and what
52
+ * each grants them, as `myAppList` and `myAccess` would answer such a user.
53
+ *
54
+ * @param url - Base URL of the e3 API server
55
+ * @param repo - Repository name
56
+ * @param name - The role's name (the built-in All apps included)
57
+ * @param options - Request options including auth token
58
+ * @returns The apps, and what each grants
59
+ * @throws {ApiError} `not_found` for a role the repository has not
60
+ */
61
+ export declare function previewRole(url: string, repo: string, name: string, options: RequestOptions): Promise<RolePreview>;
62
+ /**
63
+ * What the caller's roles grant them: each app of the repositories they are
64
+ * no owner of, with its pages (every page, or those named). An owner's apps
65
+ * are every page of every one, which the answer leaves out.
66
+ *
67
+ * @param url - Base URL of the e3 API server
68
+ * @param options - Request options including auth token
69
+ * @returns Each app granted, with its pages
70
+ */
71
+ export declare function myAccess(url: string, options: RequestOptions): Promise<MyAccess>;
72
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/roles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM5E;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAE3G;AAED;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAErH;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAE3H;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhH;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAExH;AAED;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEtF"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * A repository's business roles: the jobs its users do
7
+ * (Rostering, Finance), each granting apps, every page of each or some. Its
8
+ * owners and the deployment's admins list, read, write and remove them; a
9
+ * person holds some, by name (`addUser` with a `user` role). And what a
10
+ * person's own roles grant them, which the console's and the kiosk's menus
11
+ * show.
12
+ */
13
+ import { NullType } from '@elaraai/east';
14
+ import { BusinessRoleListType, BusinessRoleType, MyAccessType, RolePreviewType, } from '@elaraai/e3-cloud-types';
15
+ import { del, get, put } from '@elaraai/e3-api-client';
16
+ const enc = encodeURIComponent;
17
+ const rolesBase = (repo) => `/repos/${enc(repo)}/roles`;
18
+ /**
19
+ * A repository's business roles, by name (owner or admin).
20
+ *
21
+ * @param url - Base URL of the e3 API server
22
+ * @param repo - Repository name
23
+ * @param options - Request options including auth token
24
+ * @returns The roles
25
+ */
26
+ export async function listRoles(url, repo, options) {
27
+ return get(url, rolesBase(repo), BusinessRoleListType, options);
28
+ }
29
+ /**
30
+ * A business role (owner or admin).
31
+ *
32
+ * @param url - Base URL of the e3 API server
33
+ * @param repo - Repository name
34
+ * @param name - The role's name
35
+ * @param options - Request options including auth token
36
+ * @returns The role
37
+ * @throws When the repository has no role of the name (404 `not_found`)
38
+ */
39
+ export async function getRole(url, repo, name, options) {
40
+ return get(url, `${rolesBase(repo)}/${enc(name)}`, BusinessRoleType, options);
41
+ }
42
+ /**
43
+ * Writes a business role whole, made or replaced (owner or admin). Refused
44
+ * (400) for a name no role may have, a grant of the same app twice, of no
45
+ * page or a page twice, or of an app or page the repository does not have.
46
+ *
47
+ * @param url - Base URL of the e3 API server
48
+ * @param repo - Repository name
49
+ * @param role - The role
50
+ * @param options - Request options including auth token
51
+ * @returns The role, as stored
52
+ */
53
+ export async function putRole(url, repo, role, options) {
54
+ return put(url, `${rolesBase(repo)}/${enc(role.name)}`, role, BusinessRoleType, BusinessRoleType, options);
55
+ }
56
+ /**
57
+ * Removes a business role, idempotently (owner or admin). Refused (409
58
+ * `role_in_use`) while anyone of the repository holds it.
59
+ *
60
+ * @param url - Base URL of the e3 API server
61
+ * @param repo - Repository name
62
+ * @param name - The role's name
63
+ * @param options - Request options including auth token
64
+ */
65
+ export async function deleteRole(url, repo, name, options) {
66
+ await del(url, `${rolesBase(repo)}/${enc(name)}`, NullType, options);
67
+ }
68
+ /**
69
+ * What a user holding one role of a repository, and nothing else, gets
70
+ * (owner or admin; "Preview as role"): the apps their sidebar lists and what
71
+ * each grants them, as `myAppList` and `myAccess` would answer such a user.
72
+ *
73
+ * @param url - Base URL of the e3 API server
74
+ * @param repo - Repository name
75
+ * @param name - The role's name (the built-in All apps included)
76
+ * @param options - Request options including auth token
77
+ * @returns The apps, and what each grants
78
+ * @throws {ApiError} `not_found` for a role the repository has not
79
+ */
80
+ export async function previewRole(url, repo, name, options) {
81
+ return get(url, `${rolesBase(repo)}/${enc(name)}/preview`, RolePreviewType, options);
82
+ }
83
+ /**
84
+ * What the caller's roles grant them: each app of the repositories they are
85
+ * no owner of, with its pages (every page, or those named). An owner's apps
86
+ * are every page of every one, which the answer leaves out.
87
+ *
88
+ * @param url - Base URL of the e3 API server
89
+ * @param options - Request options including auth token
90
+ * @returns Each app granted, with its pages
91
+ */
92
+ export async function myAccess(url, options) {
93
+ return get(url, '/me/access', MyAccessType, options);
94
+ }
95
+ //# sourceMappingURL=roles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/roles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EAGZ,eAAe,GAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAuB,MAAM,wBAAwB,CAAC;AAE5E,MAAM,GAAG,GAAG,kBAAkB,CAAC;AAE/B,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,IAAY,EAAE,OAAuB;IAChF,OAAO,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,oBAAoB,EAAE,OAA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