primitive-admin 1.3.0-alpha.0 → 1.3.0-alpha.2
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/README.md +45 -0
- package/dist/src/commands/admins.js +91 -0
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/auth-passkeys.d.ts +7 -0
- package/dist/src/commands/auth-passkeys.js +99 -0
- package/dist/src/commands/auth-passkeys.js.map +1 -0
- package/dist/src/commands/auth-sessions.js +7 -28
- package/dist/src/commands/auth-sessions.js.map +1 -1
- package/dist/src/commands/auth.js +32 -6
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/db3-types.d.ts +27 -0
- package/dist/src/commands/db3-types.js +288 -2
- package/dist/src/commands/db3-types.js.map +1 -1
- package/dist/src/commands/db3.d.ts +16 -2
- package/dist/src/commands/db3.js +614 -5
- package/dist/src/commands/db3.js.map +1 -1
- package/dist/src/commands/documents.js +7 -0
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/functions.js +8 -3
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/hosting.js +177 -14
- package/dist/src/commands/hosting.js.map +1 -1
- package/dist/src/commands/metadata.js +14 -6
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/secrets.d.ts +38 -0
- package/dist/src/commands/secrets.js +102 -4
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/spent-tokens.d.ts +19 -0
- package/dist/src/commands/spent-tokens.js +79 -0
- package/dist/src/commands/spent-tokens.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +145 -0
- package/dist/src/commands/sync-app-settings.js +341 -8
- package/dist/src/commands/sync-app-settings.js.map +1 -1
- package/dist/src/commands/sync.d.ts +62 -15
- package/dist/src/commands/sync.js +437 -48
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/usage.d.ts +24 -0
- package/dist/src/commands/usage.js +54 -0
- package/dist/src/commands/usage.js.map +1 -1
- package/dist/src/commands/users.js +41 -1
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/lib/admin-login-tables.d.ts +31 -0
- package/dist/src/lib/admin-login-tables.js +75 -0
- package/dist/src/lib/admin-login-tables.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +241 -0
- package/dist/src/lib/api-client.js +203 -10
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +42 -3
- package/dist/src/lib/app-settings-descriptor.js +114 -1
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/auth-flow.d.ts +13 -0
- package/dist/src/lib/auth-flow.js +23 -2
- package/dist/src/lib/auth-flow.js.map +1 -1
- package/dist/src/lib/command-groups.js +2 -0
- package/dist/src/lib/command-groups.js.map +1 -1
- package/dist/src/lib/config-object-descriptor.js +6 -1
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +19 -0
- package/dist/src/lib/credentials-store.js +66 -2
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +2 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +3 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +20 -1
- package/dist/src/lib/db-type-records.js +17 -4
- package/dist/src/lib/db-type-records.js.map +1 -1
- package/dist/src/lib/db3-export.d.ts +43 -8
- package/dist/src/lib/db3-export.js +133 -13
- package/dist/src/lib/db3-export.js.map +1 -1
- package/dist/src/lib/db3-json-fields.d.ts +49 -0
- package/dist/src/lib/db3-json-fields.js +195 -0
- package/dist/src/lib/db3-json-fields.js.map +1 -0
- package/dist/src/lib/db3-type-archive.d.ts +59 -0
- package/dist/src/lib/db3-type-archive.js +95 -0
- package/dist/src/lib/db3-type-archive.js.map +1 -0
- package/dist/src/lib/db3-type-models.d.ts +15 -1
- package/dist/src/lib/db3-type-models.js +147 -16
- package/dist/src/lib/db3-type-models.js.map +1 -1
- package/dist/src/lib/document-export-record-log.d.ts +7 -0
- package/dist/src/lib/document-export-record-log.js +9 -0
- package/dist/src/lib/document-export-record-log.js.map +1 -1
- package/dist/src/lib/document-ingest-artifact.d.ts +6 -0
- package/dist/src/lib/document-ingest-artifact.js +20 -1
- package/dist/src/lib/document-ingest-artifact.js.map +1 -1
- package/dist/src/lib/function-authorize-check.js +5 -0
- package/dist/src/lib/function-authorize-check.js.map +1 -1
- package/dist/src/lib/function-authorize-view.d.ts +9 -0
- package/dist/src/lib/function-authorize-view.js +27 -4
- package/dist/src/lib/function-authorize-view.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +28 -0
- package/dist/src/lib/function-collect.js +129 -2
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.js +31 -2
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-grants-preflight.d.ts +99 -0
- package/dist/src/lib/function-grants-preflight.js +154 -2
- package/dist/src/lib/function-grants-preflight.js.map +1 -1
- package/dist/src/lib/function-lint.d.ts +29 -1
- package/dist/src/lib/function-lint.js +208 -0
- package/dist/src/lib/function-lint.js.map +1 -1
- package/dist/src/lib/function-sync.d.ts +73 -0
- package/dist/src/lib/function-sync.js +107 -2
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/generated-command-status.js +46 -8
- package/dist/src/lib/generated-command-status.js.map +1 -1
- package/dist/src/lib/generated-config-surfaces.d.ts +351 -9
- package/dist/src/lib/generated-config-surfaces.js +1009 -24
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +1 -1
- package/dist/src/lib/generated-sdk-types.js +1 -1
- package/dist/src/lib/generated-sdk-types.js.map +1 -1
- package/dist/src/lib/hosting-trust-step.d.ts +67 -0
- package/dist/src/lib/hosting-trust-step.js +279 -0
- package/dist/src/lib/hosting-trust-step.js.map +1 -0
- package/dist/src/lib/hosting-trust.d.ts +77 -0
- package/dist/src/lib/hosting-trust.js +194 -0
- package/dist/src/lib/hosting-trust.js.map +1 -0
- package/dist/src/lib/primitive-declaration.js +89 -10
- package/dist/src/lib/primitive-declaration.js.map +1 -1
- package/dist/src/lib/refresh-admin-credentials.d.ts +34 -4
- package/dist/src/lib/refresh-admin-credentials.js +85 -29
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
- package/dist/src/lib/refresh-stored-login.d.ts +85 -0
- package/dist/src/lib/refresh-stored-login.js +233 -0
- package/dist/src/lib/refresh-stored-login.js.map +1 -0
- package/dist/src/lib/row-field-rename.d.ts +18 -0
- package/dist/src/lib/row-field-rename.js +32 -0
- package/dist/src/lib/row-field-rename.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +13 -2
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +24 -1
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -1
- package/dist/src/lib/schema-defs-module.d.ts +29 -0
- package/dist/src/lib/schema-defs-module.js +103 -0
- package/dist/src/lib/schema-defs-module.js.map +1 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +6 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +74 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -1
- package/dist/src/lib/toml-list-edit.d.ts +33 -0
- package/dist/src/lib/toml-list-edit.js +481 -0
- package/dist/src/lib/toml-list-edit.js.map +1 -0
- package/dist/src/lib/toml-scalar-edit.d.ts +9 -0
- package/dist/src/lib/toml-scalar-edit.js +67 -1
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/usage-meters.d.ts +16 -0
- package/dist/src/lib/usage-meters.js +52 -0
- package/dist/src/lib/usage-meters.js.map +1 -0
- package/dist/src/types/index.d.ts +9 -0
- package/package.json +2 -2
|
@@ -5,7 +5,8 @@ import { pinRefusalHint } from "./pin-refusal-hint.js";
|
|
|
5
5
|
import { fetchWithTLS } from "./fetch.js";
|
|
6
6
|
import { CLI_VERSION_HEADER, cliVersionHeaderValue } from "./cli-version.js";
|
|
7
7
|
import { paginateAll, normalizeCliListEnvelope } from "./paginate.js";
|
|
8
|
-
import { RefreshError
|
|
8
|
+
import { RefreshError } from "./refresh-admin-credentials.js";
|
|
9
|
+
import { refreshFromStoredLogin } from "./refresh-stored-login.js";
|
|
9
10
|
/** The `X-Primitive-CLI-Version` value, read from the package file once per process. */
|
|
10
11
|
let cliVersion;
|
|
11
12
|
/**
|
|
@@ -170,6 +171,11 @@ export class TomlParseError extends ApiError {
|
|
|
170
171
|
return typeof d?.column === "number" ? d.column : undefined;
|
|
171
172
|
}
|
|
172
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* The query a db3 record call carries so a renamed field is answered under
|
|
176
|
+
* its current name, the name the type file gives it.
|
|
177
|
+
*/
|
|
178
|
+
const DB3_CURRENT_NAMES = "?names=current";
|
|
173
179
|
export class ApiClient {
|
|
174
180
|
/**
|
|
175
181
|
* Loaded on first use (`ensureAuthenticated`), never in a constructor.
|
|
@@ -215,9 +221,9 @@ export class ApiClient {
|
|
|
215
221
|
throw new ApiError("Not logged in. Run 'primitive login' first.", 401);
|
|
216
222
|
}
|
|
217
223
|
try {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
224
|
+
// #5926 — refresh from the login stored now, not the copy loaded at
|
|
225
|
+
// start: another process may have rotated its refresh token.
|
|
226
|
+
this.credentials = await refreshFromStoredLogin(this.credentials);
|
|
221
227
|
}
|
|
222
228
|
catch (err) {
|
|
223
229
|
if (err instanceof RefreshError) {
|
|
@@ -271,6 +277,7 @@ export class ApiClient {
|
|
|
271
277
|
if (response.status === 403 && this.stepUpApplies(response, text, path)) {
|
|
272
278
|
const retried = await send(credentials.stepUp.accessToken);
|
|
273
279
|
if (retried.response.ok) {
|
|
280
|
+
this.lastStatus = retried.response.status;
|
|
274
281
|
return answered(retried.text);
|
|
275
282
|
}
|
|
276
283
|
if (retried.response.status === 401) {
|
|
@@ -283,8 +290,11 @@ export class ApiClient {
|
|
|
283
290
|
if (!response.ok) {
|
|
284
291
|
throw this.responseError(response, text, path);
|
|
285
292
|
}
|
|
293
|
+
this.lastStatus = response.status;
|
|
286
294
|
return answered(text);
|
|
287
295
|
}
|
|
296
|
+
/** The HTTP status of the last request `request` answered without throwing. */
|
|
297
|
+
lastStatus;
|
|
288
298
|
/**
|
|
289
299
|
* Whether a 403 should be retried with the stored step-up: it names
|
|
290
300
|
* `admin` among the missing scopes, or it is a protected app's refusal of
|
|
@@ -669,6 +679,10 @@ export class ApiClient {
|
|
|
669
679
|
async getRateCounter(appId, key) {
|
|
670
680
|
return this.get(`/admin/api/apps/${appId}/rate-counters/${encodeURIComponent(key)}`);
|
|
671
681
|
}
|
|
682
|
+
/** A spent token of the app by id (`GET /admin/api/apps/:appId/spent-tokens/:tokenId`); 404 when it has not been used. */
|
|
683
|
+
async getSpentToken(appId, tokenId) {
|
|
684
|
+
return this.get(`/admin/api/apps/${appId}/spent-tokens/${encodeURIComponent(tokenId)}`);
|
|
685
|
+
}
|
|
672
686
|
/** Stop a users walk (`POST /admin/api/apps/:appId/users/walks/:runId/terminate`); batches in flight finish. */
|
|
673
687
|
async terminateUserWalk(appId, runId) {
|
|
674
688
|
return this.post(`/admin/api/apps/${appId}/users/walks/${encodeURIComponent(runId)}/terminate`, {});
|
|
@@ -866,6 +880,13 @@ export class ApiClient {
|
|
|
866
880
|
* its `inviteToken` (the bearer credential an accept link carries) and its
|
|
867
881
|
* `status`. Readable by an app admin/owner or the inviter.
|
|
868
882
|
*/
|
|
883
|
+
/**
|
|
884
|
+
* What an invitation shows before anyone signs in (#5848), by its token.
|
|
885
|
+
* The route reads no credential.
|
|
886
|
+
*/
|
|
887
|
+
async previewInvitation(appId, inviteToken) {
|
|
888
|
+
return this.get(`/app/${appId}/api/invitations/preview`, { inviteToken });
|
|
889
|
+
}
|
|
869
890
|
async getInvitation(appId, invitationId) {
|
|
870
891
|
return this.get(`/app/${appId}/api/invitations/${encodeURIComponent(invitationId)}`);
|
|
871
892
|
}
|
|
@@ -976,6 +997,14 @@ export class ApiClient {
|
|
|
976
997
|
async deleteAppSecret(appId, secretId) {
|
|
977
998
|
return this.delete(`/admin/api/apps/${appId}/secrets/${secretId}`);
|
|
978
999
|
}
|
|
1000
|
+
/**
|
|
1001
|
+
* What in the app's configuration names a secret key (#5845, beta): `{ key,
|
|
1002
|
+
* reserved, stored, references: [{ kind, id, name, field }], truncated }`.
|
|
1003
|
+
* Answers for any key, stored or not; never a value.
|
|
1004
|
+
*/
|
|
1005
|
+
async getAppSecretReferences(appId, key) {
|
|
1006
|
+
return this.get(`/admin/api/apps/${appId}/secrets/by-key/${encodeURIComponent(key)}/references`);
|
|
1007
|
+
}
|
|
979
1008
|
// ============================================
|
|
980
1009
|
// APP CONFIG VARS (issue #1364 — non-secret twin of secrets)
|
|
981
1010
|
// ============================================
|
|
@@ -1388,6 +1417,75 @@ export class ApiClient {
|
|
|
1388
1417
|
async revokeAdminSession(sessionId) {
|
|
1389
1418
|
return this.delete(`/admin/api/auth/sessions/${encodeURIComponent(sessionId)}`);
|
|
1390
1419
|
}
|
|
1420
|
+
/** The caller's admin passkeys under every relying party, newest first (#5978). */
|
|
1421
|
+
async listAdminPasskeys() {
|
|
1422
|
+
const result = await this.get("/admin/api/auth/passkeys");
|
|
1423
|
+
return { items: result?.items ?? [], hasMore: Boolean(result?.hasMore) };
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* One page of an admin's, or an address's, sign-in audit events, newest
|
|
1427
|
+
* first (super-admin). Exactly one of `adminId` and `email` is sent.
|
|
1428
|
+
*/
|
|
1429
|
+
async listAdminAuthEvents(params) {
|
|
1430
|
+
const result = await this.get("/super-admin/api/auth-events", params);
|
|
1431
|
+
return {
|
|
1432
|
+
items: result?.items ?? [],
|
|
1433
|
+
hasMore: Boolean(result?.hasMore),
|
|
1434
|
+
nextCursor: result?.nextCursor ?? null,
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
/** Delete one of the caller's admin passkeys (#5978). */
|
|
1438
|
+
async deleteAdminPasskey(passkeyId) {
|
|
1439
|
+
return this.delete(`/admin/api/auth/passkeys/${encodeURIComponent(passkeyId)}`);
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Reset another admin's sign-in (#5978, super-admin): clear their passkeys
|
|
1443
|
+
* and bound Google account. The route needs an unpinned `admin` step-up,
|
|
1444
|
+
* so a usable stored one is sent first; otherwise the login is, and the
|
|
1445
|
+
* server's refusal names the step-up command.
|
|
1446
|
+
*/
|
|
1447
|
+
async resetAdminSignIn(adminId) {
|
|
1448
|
+
const path = `/super-admin/api/admins/${encodeURIComponent(adminId)}/reset-sign-in`;
|
|
1449
|
+
const withStepUp = await this.sendWithAdminStepUp(path, "POST");
|
|
1450
|
+
if (withStepUp.sent)
|
|
1451
|
+
return withStepUp.body;
|
|
1452
|
+
return this.request(path, { method: "POST" });
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Send one request with the stored step-up when it can act on a platform
|
|
1456
|
+
* route that needs `admin`: unexpired, holding `admin`, and unpinned.
|
|
1457
|
+
* Answers `{ sent: false }` when there is no such step-up, or when the
|
|
1458
|
+
* server answered it 401 (it is dropped); the caller then sends the login.
|
|
1459
|
+
* Any other refusal throws as `request` would.
|
|
1460
|
+
*/
|
|
1461
|
+
async sendWithAdminStepUp(path, method) {
|
|
1462
|
+
const credentials = await this.ensureAuthenticated();
|
|
1463
|
+
const stepUp = credentials.stepUp;
|
|
1464
|
+
const usable = Boolean(stepUp?.accessToken) &&
|
|
1465
|
+
new Date(stepUp.expiresAt).getTime() > Date.now() &&
|
|
1466
|
+
(stepUp.scope ?? []).includes("admin") &&
|
|
1467
|
+
(stepUp.apps ?? []).length === 0;
|
|
1468
|
+
if (!usable)
|
|
1469
|
+
return { sent: false };
|
|
1470
|
+
const headers = {
|
|
1471
|
+
Authorization: `Bearer ${stepUp.accessToken}`,
|
|
1472
|
+
"Content-Type": "application/json",
|
|
1473
|
+
[CLI_VERSION_HEADER]: (cliVersion ??= cliVersionHeaderValue()),
|
|
1474
|
+
};
|
|
1475
|
+
if (credentials.globalAdminAppId) {
|
|
1476
|
+
headers["X-Global-Admin-App-Id"] = credentials.globalAdminAppId;
|
|
1477
|
+
}
|
|
1478
|
+
const response = await fetchWithTLS(`${credentials.serverUrl}${path}`, { method, headers });
|
|
1479
|
+
const text = await response.text();
|
|
1480
|
+
if (response.status === 401) {
|
|
1481
|
+
this.dropStepUp();
|
|
1482
|
+
return { sent: false };
|
|
1483
|
+
}
|
|
1484
|
+
if (!response.ok)
|
|
1485
|
+
throw this.responseError(response, text, path);
|
|
1486
|
+
this.lastStatus = response.status;
|
|
1487
|
+
return { sent: true, body: (text ? JSON.parse(text) : null) };
|
|
1488
|
+
}
|
|
1391
1489
|
// ============================================
|
|
1392
1490
|
// NAMED LOCKS (#1518)
|
|
1393
1491
|
// ============================================
|
|
@@ -2874,6 +2972,8 @@ export class ApiClient {
|
|
|
2874
2972
|
query.limit = queryOptions.limit;
|
|
2875
2973
|
if (queryOptions?.cursor)
|
|
2876
2974
|
query.cursor = queryOptions.cursor;
|
|
2975
|
+
// #6022 — the CLI prints a renamed field under its current name.
|
|
2976
|
+
query.names = "current";
|
|
2877
2977
|
const raw = await this.get(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}`, query);
|
|
2878
2978
|
return normalizeCliListEnvelope(raw);
|
|
2879
2979
|
}
|
|
@@ -2882,11 +2982,12 @@ export class ApiClient {
|
|
|
2882
2982
|
const query = {};
|
|
2883
2983
|
if (queryOptions?.filter)
|
|
2884
2984
|
query.filter = JSON.stringify(queryOptions.filter);
|
|
2985
|
+
query.names = "current";
|
|
2885
2986
|
return this.get(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/count`, query);
|
|
2886
2987
|
}
|
|
2887
2988
|
/** The db3 mount of {@link aggregateDocumentRecords}: `POST db3/:id/records/:model/aggregate`. */
|
|
2888
2989
|
async aggregateDb3Records(appId, db3Id, modelName, options) {
|
|
2889
|
-
return this.post(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/aggregate`, { options });
|
|
2990
|
+
return this.post(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/aggregate${DB3_CURRENT_NAMES}`, { options });
|
|
2890
2991
|
}
|
|
2891
2992
|
/**
|
|
2892
2993
|
* `POST db3/:id/records/:model/explain` (#5240): run a query, count or
|
|
@@ -2898,11 +2999,11 @@ export class ApiClient {
|
|
|
2898
2999
|
}
|
|
2899
3000
|
/** The db3 mount of {@link saveDocumentRecord}: `POST db3/:id/records/:model`. */
|
|
2900
3001
|
async saveDb3Record(appId, db3Id, modelName, body) {
|
|
2901
|
-
return this.post(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}`, body);
|
|
3002
|
+
return this.post(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}${DB3_CURRENT_NAMES}`, body);
|
|
2902
3003
|
}
|
|
2903
3004
|
/** The db3 mount of {@link patchDocumentRecord}: `PATCH db3/:id/records/:model/:recordId`. */
|
|
2904
3005
|
async patchDb3Record(appId, db3Id, modelName, recordId, body) {
|
|
2905
|
-
return this.patch(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}`, body);
|
|
3006
|
+
return this.patch(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}${DB3_CURRENT_NAMES}`, body);
|
|
2906
3007
|
}
|
|
2907
3008
|
/** The db3 mount of {@link deleteDocumentRecord}: `DELETE db3/:id/records/:model/:recordId`. */
|
|
2908
3009
|
async deleteDb3Record(appId, db3Id, modelName, recordId) {
|
|
@@ -2910,7 +3011,7 @@ export class ApiClient {
|
|
|
2910
3011
|
}
|
|
2911
3012
|
/** The db3 mount of {@link batchDocumentRecords}: `POST db3/:id/records/batch`. */
|
|
2912
3013
|
async batchDb3Records(appId, db3Id, operations) {
|
|
2913
|
-
return this.post(`${this.db3Path(appId, db3Id)}/records/batch`, { operations });
|
|
3014
|
+
return this.post(`${this.db3Path(appId, db3Id)}/records/batch${DB3_CURRENT_NAMES}`, { operations });
|
|
2914
3015
|
}
|
|
2915
3016
|
/**
|
|
2916
3017
|
* Several reads of a db3 in one request (#5243): `POST db3/:id/records/batch-read`,
|
|
@@ -2918,7 +3019,7 @@ export class ApiClient {
|
|
|
2918
3019
|
* answers a refused read in its place rather than refusing the request.
|
|
2919
3020
|
*/
|
|
2920
3021
|
async batchReadDb3Records(appId, db3Id, operations, options = {}) {
|
|
2921
|
-
return this.post(`${this.db3Path(appId, db3Id)}/records/batch-read`, {
|
|
3022
|
+
return this.post(`${this.db3Path(appId, db3Id)}/records/batch-read${DB3_CURRENT_NAMES}`, {
|
|
2922
3023
|
operations,
|
|
2923
3024
|
...(options.atomic === false ? { atomic: false } : {}),
|
|
2924
3025
|
});
|
|
@@ -3034,7 +3135,14 @@ export class ApiClient {
|
|
|
3034
3135
|
* `fields` to the record's field, answering `{ record, values }`.
|
|
3035
3136
|
*/
|
|
3036
3137
|
async incrementDb3Record(appId, db3Id, modelName, recordId, body) {
|
|
3037
|
-
return this.post(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}/increment`, body);
|
|
3138
|
+
return this.post(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}/increment${DB3_CURRENT_NAMES}`, body);
|
|
3139
|
+
}
|
|
3140
|
+
/**
|
|
3141
|
+
* `POST db3/:id/records/:model/clear` (#5994): empty one model in one
|
|
3142
|
+
* operation; `{ ok, model, rows, lsn, epoch, dropped, cost }`.
|
|
3143
|
+
*/
|
|
3144
|
+
async clearDb3Model(appId, db3Id, modelName, body = {}) {
|
|
3145
|
+
return this.post(`${this.db3Path(appId, db3Id)}/records/${encodeURIComponent(modelName)}/clear`, body);
|
|
3038
3146
|
}
|
|
3039
3147
|
/** `GET db3/:id/sync` (#4799): `{ id, sync }`. */
|
|
3040
3148
|
async getDb3Sync(appId, db3Id) {
|
|
@@ -3052,6 +3160,91 @@ export class ApiClient {
|
|
|
3052
3160
|
async setDb3AppAccess(appId, db3Id, level) {
|
|
3053
3161
|
return this.put(`${this.db3Path(appId, db3Id)}/app-access`, { level });
|
|
3054
3162
|
}
|
|
3163
|
+
/**
|
|
3164
|
+
* `PUT db3/:id/public-access` (#5842): mark the db3 public at `reader`, or
|
|
3165
|
+
* clear it with null; `signedOutAccess` is the app's setting, which decides
|
|
3166
|
+
* whether the value is honoured yet.
|
|
3167
|
+
*/
|
|
3168
|
+
async setDb3PublicAccess(appId, db3Id, level) {
|
|
3169
|
+
return this.put(`${this.db3Path(appId, db3Id)}/public-access`, { level });
|
|
3170
|
+
}
|
|
3171
|
+
/** `GET db3/:id/link-access`: `{ documentId, linkAccess, … }`, `linkAccess` null when off. */
|
|
3172
|
+
async getDb3LinkAccess(appId, db3Id) {
|
|
3173
|
+
return this.get(`${this.db3Path(appId, db3Id)}/link-access`);
|
|
3174
|
+
}
|
|
3175
|
+
/** `PUT db3/:id/link-access`: let anyone in the app with the id open the db3 at `level`. */
|
|
3176
|
+
async setDb3LinkAccess(appId, db3Id, level) {
|
|
3177
|
+
return this.put(`${this.db3Path(appId, db3Id)}/link-access`, { level });
|
|
3178
|
+
}
|
|
3179
|
+
/** `DELETE db3/:id/link-access`: turn the db3's link access off. */
|
|
3180
|
+
async clearDb3LinkAccess(appId, db3Id) {
|
|
3181
|
+
return this.delete(`${this.db3Path(appId, db3Id)}/link-access`);
|
|
3182
|
+
}
|
|
3183
|
+
/** `GET db3/:id/permissions`: the db3's user grants, a bare array of `{ userId, email, name, permission, grantedAt }`. */
|
|
3184
|
+
async listDb3Permissions(appId, db3Id) {
|
|
3185
|
+
return this.get(`${this.db3Path(appId, db3Id)}/permissions`);
|
|
3186
|
+
}
|
|
3187
|
+
/**
|
|
3188
|
+
* `PUT db3/:id/permissions`: grant one user, named by `userId` or `email`,
|
|
3189
|
+
* a level; `sendEmail` tells them, with `documentUrl` and `note` in the email.
|
|
3190
|
+
*/
|
|
3191
|
+
async grantDb3Permission(appId, db3Id, entry, email) {
|
|
3192
|
+
return this.put(`${this.db3Path(appId, db3Id)}/permissions`, { permissions: [entry], ...(email ?? {}) });
|
|
3193
|
+
}
|
|
3194
|
+
/** `DELETE db3/:id/permissions/:userId`, or `DELETE db3/:id/permissions?email=` for an email: revoke one user's grant. */
|
|
3195
|
+
async revokeDb3Permission(appId, db3Id, target) {
|
|
3196
|
+
if (target.email) {
|
|
3197
|
+
return this.delete(`${this.db3Path(appId, db3Id)}/permissions?email=${encodeURIComponent(target.email)}`);
|
|
3198
|
+
}
|
|
3199
|
+
if (!target.userId)
|
|
3200
|
+
throw new Error("revokeDb3Permission: userId or email is required");
|
|
3201
|
+
return this.delete(`${this.db3Path(appId, db3Id)}/permissions/${encodeURIComponent(target.userId)}`);
|
|
3202
|
+
}
|
|
3203
|
+
/** `GET db3/:id/group-permissions`: the db3's group grants, a bare array; `includeSystem` adds system groups'. */
|
|
3204
|
+
async listDb3GroupPermissions(appId, db3Id, options) {
|
|
3205
|
+
return this.get(`${this.db3Path(appId, db3Id)}/group-permissions`, options?.includeSystem ? { includeSystem: "true" } : undefined);
|
|
3206
|
+
}
|
|
3207
|
+
/** `POST db3/:id/group-permissions`: grant a group, named by its id, a level. */
|
|
3208
|
+
async grantDb3GroupPermission(appId, db3Id, groupId, permission) {
|
|
3209
|
+
return this.post(`${this.db3Path(appId, db3Id)}/group-permissions`, { groupId, permission });
|
|
3210
|
+
}
|
|
3211
|
+
/** `DELETE db3/:id/group-permissions/:groupId`: revoke a group's grant. */
|
|
3212
|
+
async revokeDb3GroupPermission(appId, db3Id, groupId) {
|
|
3213
|
+
return this.delete(`${this.db3Path(appId, db3Id)}/group-permissions/${encodeURIComponent(groupId)}`);
|
|
3214
|
+
}
|
|
3215
|
+
/** `GET db3/:id/pending-invitations`: `{ items }`, the grants waiting for an address to join the app. */
|
|
3216
|
+
async listDb3PendingInvitations(appId, db3Id) {
|
|
3217
|
+
return this.get(`${this.db3Path(appId, db3Id)}/pending-invitations`);
|
|
3218
|
+
}
|
|
3219
|
+
/** `DELETE db3/:id/pending-invitations/:invitationId`: cancel a pending invitation's grants on this db3. */
|
|
3220
|
+
async revokeDb3PendingInvitation(appId, db3Id, invitationId) {
|
|
3221
|
+
return this.delete(`${this.db3Path(appId, db3Id)}/pending-invitations/${encodeURIComponent(invitationId)}`);
|
|
3222
|
+
}
|
|
3223
|
+
/** `GET db3/:id/access-requests`: the pending access requests, a bare array. */
|
|
3224
|
+
async listDb3AccessRequests(appId, db3Id) {
|
|
3225
|
+
return this.get(`${this.db3Path(appId, db3Id)}/access-requests`);
|
|
3226
|
+
}
|
|
3227
|
+
/**
|
|
3228
|
+
* `POST db3/:id/access-requests`: the signed-in caller asks for access.
|
|
3229
|
+
* `created` is true when the request is new (201) and false when the
|
|
3230
|
+
* caller's pending request was updated (200).
|
|
3231
|
+
*/
|
|
3232
|
+
async createDb3AccessRequest(appId, db3Id, body) {
|
|
3233
|
+
const answer = await this.post(`${this.db3Path(appId, db3Id)}/access-requests`, body);
|
|
3234
|
+
return { answer, created: this.lastStatus === 201 };
|
|
3235
|
+
}
|
|
3236
|
+
/** `POST db3/:id/access-requests/:requestId/approve`: grant the requested level, or `permission`. */
|
|
3237
|
+
async approveDb3AccessRequest(appId, db3Id, requestId, body = {}) {
|
|
3238
|
+
return this.post(`${this.db3Path(appId, db3Id)}/access-requests/${encodeURIComponent(requestId)}/approve`, body);
|
|
3239
|
+
}
|
|
3240
|
+
/** `POST db3/:id/access-requests/:requestId/deny`: deny the request. */
|
|
3241
|
+
async denyDb3AccessRequest(appId, db3Id, requestId, body = {}) {
|
|
3242
|
+
return this.post(`${this.db3Path(appId, db3Id)}/access-requests/${encodeURIComponent(requestId)}/deny`, body);
|
|
3243
|
+
}
|
|
3244
|
+
/** `POST db3/:id/validate-access` with `{ userId }`: a named user's effective access to the db3. */
|
|
3245
|
+
async validateDb3AccessForUser(appId, db3Id, userId) {
|
|
3246
|
+
return this.post(`${this.db3Path(appId, db3Id)}/validate-access`, { userId });
|
|
3247
|
+
}
|
|
3055
3248
|
/** One custodian's db3s through the admin API (#4800): `custodian` is `app` or `user:<userId>`. */
|
|
3056
3249
|
async listDb3ByCustodian(appId, custodian, params) {
|
|
3057
3250
|
const result = await this.get(`/admin/api/apps/${appId}/db3`, { custodian, ...(params ?? {}) });
|