doover-js 0.14.1 → 0.15.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.
Files changed (44) hide show
  1. package/dist/apis/agents-api.d.ts +108 -0
  2. package/dist/apis/agents-api.js +64 -6
  3. package/dist/apis/users-api.d.ts +2 -0
  4. package/dist/apis/users-api.js +4 -0
  5. package/dist/client/doover-client.d.ts +3 -0
  6. package/dist/client/doover-client.js +4 -0
  7. package/dist/client/local-agent-client.js +7 -0
  8. package/dist/client/multiplex-client.js +7 -0
  9. package/dist/esm/apis/agents-api.d.ts +108 -0
  10. package/dist/esm/apis/agents-api.js +64 -6
  11. package/dist/esm/apis/users-api.d.ts +2 -0
  12. package/dist/esm/apis/users-api.js +4 -0
  13. package/dist/esm/client/doover-client.d.ts +3 -0
  14. package/dist/esm/client/doover-client.js +4 -0
  15. package/dist/esm/client/local-agent-client.js +7 -0
  16. package/dist/esm/client/multiplex-client.js +7 -0
  17. package/dist/esm/http/errors.d.ts +4 -0
  18. package/dist/esm/http/errors.js +11 -0
  19. package/dist/esm/http/index.d.ts +1 -1
  20. package/dist/esm/http/index.js +1 -1
  21. package/dist/esm/http/rest-client.d.ts +4 -0
  22. package/dist/esm/http/rest-client.js +22 -4
  23. package/dist/esm/index.d.ts +2 -2
  24. package/dist/esm/index.js +1 -1
  25. package/dist/esm/package.json +1 -1
  26. package/dist/esm/react/index.d.ts +5 -4
  27. package/dist/esm/react/index.js +2 -1
  28. package/dist/esm/react/useAgentCredentials.d.ts +30 -0
  29. package/dist/esm/react/useAgentCredentials.js +69 -0
  30. package/dist/esm/types/viewer.d.ts +5 -0
  31. package/dist/http/errors.d.ts +4 -0
  32. package/dist/http/errors.js +14 -1
  33. package/dist/http/index.d.ts +1 -1
  34. package/dist/http/index.js +3 -1
  35. package/dist/http/rest-client.d.ts +4 -0
  36. package/dist/http/rest-client.js +21 -3
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +4 -2
  39. package/dist/react/index.d.ts +5 -4
  40. package/dist/react/index.js +10 -1
  41. package/dist/react/useAgentCredentials.d.ts +30 -0
  42. package/dist/react/useAgentCredentials.js +79 -0
  43. package/dist/types/viewer.d.ts +5 -0
  44. package/package.json +1 -1
@@ -43,6 +43,8 @@ export interface AgentTokenState {
43
43
  self_rotation: TokenPolicyField<boolean>;
44
44
  max_age_ms: TokenPolicyField<number>;
45
45
  reuse_grace_ms: TokenPolicyField<number>;
46
+ /** Whether v1 mini-tokens and OAuth client secrets are refused. */
47
+ require_key_auth: TokenPolicyField<boolean>;
46
48
  }
47
49
  /**
48
50
  * A token-posture override. `null` on any field means "inherit the organisation
@@ -62,6 +64,11 @@ export interface AgentTokenPolicy {
62
64
  * Setting this opts the device into *automatic* lockout on reuse detection.
63
65
  */
64
66
  reuse_grace_ms?: number | null;
67
+ /**
68
+ * Refuse v1 mini-tokens and OAuth client secrets, so only key pairs and API
69
+ * keys work for this device.
70
+ */
71
+ require_key_auth?: boolean | null;
65
72
  }
66
73
  export interface ResourcePermission {
67
74
  permission_id: string;
@@ -72,6 +79,67 @@ export interface AdhocTokenResponse {
72
79
  token: string;
73
80
  token_id: string | null;
74
81
  }
82
+ export type CredentialKind = "api_key" | "device_key" | "enrolment_code";
83
+ /**
84
+ * Narrows an API key below its agent's own access; the key can do what both
85
+ * allow. A restricted key never gets control-plane or superuser powers.
86
+ */
87
+ export interface KeyRestriction {
88
+ /** Only reading and subscribing. */
89
+ read_only?: boolean;
90
+ /** Only these agents and their channels. Omit for everything. */
91
+ agents?: string[];
92
+ /**
93
+ * A custom policy instead of `read_only` and `agents`: named-action
94
+ * statements, `data:` actions only. Still intersected with the agent's
95
+ * own access.
96
+ */
97
+ policy?: KeyPolicy;
98
+ }
99
+ export interface KeyPolicy {
100
+ statements: {
101
+ effect: "allow" | "deny";
102
+ actions: string[];
103
+ resources: string[];
104
+ /** Missing request values never widen access. */
105
+ conditions?: {
106
+ source_ip?: {
107
+ in: string[];
108
+ } | {
109
+ not_in: string[];
110
+ };
111
+ transport?: {
112
+ in: string[];
113
+ } | {
114
+ not_in: string[];
115
+ };
116
+ };
117
+ }[];
118
+ }
119
+ /** An agent's API key or device key. Never includes the secret. */
120
+ export interface AgentCredential {
121
+ id: string;
122
+ /** The agent it belongs to. */
123
+ agent_id: string;
124
+ kind: CredentialKind;
125
+ name: string;
126
+ /** The agent (user or device) that created it. */
127
+ created_by: string;
128
+ created_ms: number;
129
+ /** Updated at most hourly. */
130
+ last_used_ms?: number | null;
131
+ /** Set once revoked. A revoked credential stays listed. */
132
+ revoked_ms?: number | null;
133
+ restriction?: KeyRestriction | null;
134
+ /** Unix ms after which it stops working. Null: never. */
135
+ expires_ms?: number | null;
136
+ /** For an enrolment code: the device key it enrolled, once used. */
137
+ enrolled_key?: string | null;
138
+ }
139
+ export interface CreatedCredential extends AgentCredential {
140
+ /** The API key itself (`dv_key_…`). Shown once; absent for a device key. */
141
+ key?: string;
142
+ }
75
143
  export interface DeviceTokenResponse {
76
144
  /** Shown once. Not stored anywhere and not retrievable afterwards. */
77
145
  token: string;
@@ -193,4 +261,44 @@ export declare class AgentsApi {
193
261
  * Returned once and stored nowhere. If it's lost, mint another.
194
262
  */
195
263
  createDeviceToken(agentId: string): Promise<DeviceTokenResponse>;
264
+ /**
265
+ * An agent's API keys and device keys, newest first, revoked ones included.
266
+ * Requires `AgentTokenRead`.
267
+ */
268
+ listCredentials(agentId: string): Promise<AgentCredential[]>;
269
+ /**
270
+ * Every credential on an organisation's agents (devices and service
271
+ * accounts) that you may list, each with its `agent_id`, newest first.
272
+ */
273
+ listOrganisationCredentials(organisationId: string): Promise<AgentCredential[]>;
274
+ /**
275
+ * Mint an API key for an agent. It acts as the agent, with the agent's
276
+ * grants, as `Authorization: Bearer dv_key_…`, and works against doover-data
277
+ * only for now. The key is in the response once and never again.
278
+ *
279
+ * `restriction` narrows it (read-only, chosen agents) and `expiresMs` ends
280
+ * it; both only ever take access away from what the agent has.
281
+ */
282
+ createApiKey(agentId: string, name: string, options?: {
283
+ restriction?: KeyRestriction;
284
+ expiresMs?: number;
285
+ }): Promise<CreatedCredential>;
286
+ /**
287
+ * Register a device's P-256 public key (PEM or JWK). The device then
288
+ * authenticates to `/oauth2/token` with assertions signed by its private key
289
+ * and gets 24 hour tokens.
290
+ */
291
+ addDeviceKey(agentId: string, name: string, publicKey: string): Promise<CreatedCredential>;
292
+ /**
293
+ * Mint an enrolment code for a device: the device redeems it once at
294
+ * `POST /enrol` with its public key, which adds a device public key to it.
295
+ * The code is in the response once. Expires after 4 hours unless
296
+ * `expiresMs` says otherwise (at most 7 days).
297
+ */
298
+ createEnrolmentCode(agentId: string, name: string, expiresMs?: number): Promise<CreatedCredential>;
299
+ /**
300
+ * Revoke an API key or device key. Takes effect at once, including for
301
+ * tokens already issued from a device key.
302
+ */
303
+ revokeCredential(agentId: string, credentialId: string): Promise<void>;
196
304
  }
@@ -6,9 +6,7 @@ function isPlainObject(value) {
6
6
  return typeof value === "object" && value !== null && !Array.isArray(value);
7
7
  }
8
8
  function buildUserDisplayName(rawUser) {
9
- const source = isPlainObject(rawUser)
10
- ? rawUser
11
- : {};
9
+ const source = isPlainObject(rawUser) ? rawUser : {};
12
10
  const firstName = typeof source.first_name === "string" ? source.first_name.trim() : "";
13
11
  const lastName = typeof source.last_name === "string" ? source.last_name.trim() : "";
14
12
  const fullName = `${firstName} ${lastName}`.trim();
@@ -85,9 +83,7 @@ function normalizeOrganisationEntry(rawOrganisation) {
85
83
  };
86
84
  }
87
85
  function normalizeUserEntry(rawUser) {
88
- const source = isPlainObject(rawUser)
89
- ? rawUser
90
- : {};
86
+ const source = isPlainObject(rawUser) ? rawUser : {};
91
87
  const id = typeof source.id === "string" ? source.id : String(source.id ?? "");
92
88
  const username = typeof source.username === "string" ? source.username : "";
93
89
  const email = typeof source.email === "string" ? source.email : "";
@@ -322,6 +318,68 @@ class AgentsApi {
322
318
  revoke_existing: false,
323
319
  });
324
320
  }
321
+ /**
322
+ * An agent's API keys and device keys, newest first, revoked ones included.
323
+ * Requires `AgentTokenRead`.
324
+ */
325
+ listCredentials(agentId) {
326
+ return this.rest.get(`/agents/${agentId}/credentials`);
327
+ }
328
+ /**
329
+ * Every credential on an organisation's agents (devices and service
330
+ * accounts) that you may list, each with its `agent_id`, newest first.
331
+ */
332
+ listOrganisationCredentials(organisationId) {
333
+ return this.rest.get(`/organisations/${organisationId}/credentials`);
334
+ }
335
+ /**
336
+ * Mint an API key for an agent. It acts as the agent, with the agent's
337
+ * grants, as `Authorization: Bearer dv_key_…`, and works against doover-data
338
+ * only for now. The key is in the response once and never again.
339
+ *
340
+ * `restriction` narrows it (read-only, chosen agents) and `expiresMs` ends
341
+ * it; both only ever take access away from what the agent has.
342
+ */
343
+ createApiKey(agentId, name, options = {}) {
344
+ return this.rest.post(`/agents/${agentId}/credentials`, {
345
+ kind: "api_key",
346
+ name,
347
+ restriction: options.restriction,
348
+ expires_ms: options.expiresMs,
349
+ });
350
+ }
351
+ /**
352
+ * Register a device's P-256 public key (PEM or JWK). The device then
353
+ * authenticates to `/oauth2/token` with assertions signed by its private key
354
+ * and gets 24 hour tokens.
355
+ */
356
+ addDeviceKey(agentId, name, publicKey) {
357
+ return this.rest.post(`/agents/${agentId}/credentials`, {
358
+ kind: "device_key",
359
+ name,
360
+ public_key: publicKey,
361
+ });
362
+ }
363
+ /**
364
+ * Mint an enrolment code for a device: the device redeems it once at
365
+ * `POST /enrol` with its public key, which adds a device public key to it.
366
+ * The code is in the response once. Expires after 4 hours unless
367
+ * `expiresMs` says otherwise (at most 7 days).
368
+ */
369
+ createEnrolmentCode(agentId, name, expiresMs) {
370
+ return this.rest.post(`/agents/${agentId}/credentials`, {
371
+ kind: "enrolment_code",
372
+ name,
373
+ expires_ms: expiresMs,
374
+ });
375
+ }
376
+ /**
377
+ * Revoke an API key or device key. Takes effect at once, including for
378
+ * tokens already issued from a device key.
379
+ */
380
+ revokeCredential(agentId, credentialId) {
381
+ return this.rest.delete(`/agents/${agentId}/credentials/${credentialId}`);
382
+ }
325
383
  }
326
384
  exports.AgentsApi = AgentsApi;
327
385
  // CloudFront fronts the channels-rest API with a hard 8,192-byte URL quota.
@@ -5,4 +5,6 @@ export declare class UsersApi {
5
5
  private readonly controlApiUrl?;
6
6
  constructor(rest: RestClient, controlApiUrl?: string | undefined);
7
7
  getMe(): Promise<User>;
8
+ /** Re-read the user's MFA enrollment from the identity provider. */
9
+ refreshMfa(): Promise<User>;
8
10
  }
@@ -9,5 +9,9 @@ class UsersApi {
9
9
  getMe() {
10
10
  return this.rest.get("/users/me", undefined, this.controlApiUrl);
11
11
  }
12
+ /** Re-read the user's MFA enrollment from the identity provider. */
13
+ refreshMfa() {
14
+ return this.rest.post("/users/me/mfa/refresh/", undefined, undefined, this.controlApiUrl);
15
+ }
12
16
  }
13
17
  exports.UsersApi = UsersApi;
@@ -3,6 +3,7 @@ import { type NetworkStatusSource } from "./network-status.js";
3
3
  import { OrganisationsApi } from "../apis/organisations-api.js";
4
4
  import type { DooverAuth } from "../auth/doover-auth.js";
5
5
  import { RestClient, type DooverClientConfig } from "../http/rest-client.js";
6
+ import type { DooverMfaRequiredError } from "../http/errors.js";
6
7
  import { DooverDataProvider } from "../viewer/doover-data-provider.js";
7
8
  import { type Capability } from "./capabilities.js";
8
9
  import type { AgentsApiLike, AggregatesApiLike, AlarmsApiLike, ChannelsApiLike, ConnectionsApiLike, DataClient, DataClientStatus, AgentScope, GatewayClientLike, MessagesApiLike, NotificationsApiLike, PermissionsApiLike, ProcessorsApiLike, RpcDispatcherLike, TurnApiLike, UsersApiLike } from "./data-client.js";
@@ -40,6 +41,8 @@ export declare class DooverClient implements DataClient {
40
41
  enableStats(): void;
41
42
  disableStats(): void;
42
43
  getStats(): DooverStatsSnapshot;
44
+ /** Called whenever a request is refused because the organisation requires MFA. */
45
+ onMfaRequired(listener: (error: DooverMfaRequiredError) => void): () => void;
43
46
  getCapabilities(): ReadonlySet<Capability>;
44
47
  supports(cap: Capability): boolean;
45
48
  getAgentScope(): Promise<AgentScope>;
@@ -90,6 +90,10 @@ class DooverClient {
90
90
  enableStats() { this.stats.setEnabled(true); }
91
91
  disableStats() { this.stats.setEnabled(false); }
92
92
  getStats() { return this.stats.snapshot(); }
93
+ /** Called whenever a request is refused because the organisation requires MFA. */
94
+ onMfaRequired(listener) {
95
+ return this.rest.onMfaRequired(listener);
96
+ }
93
97
  // --- DataClient: capabilities ---
94
98
  getCapabilities() { return ALL_CAPS_SET; }
95
99
  supports(cap) { return ALL_CAPS_SET.has(cap); }
@@ -190,6 +190,12 @@ const METHOD_TO_CAPABILITY = {
190
190
  "agents.setRevocationFloor": "agents.tokenManage",
191
191
  "agents.createAdhocToken": "agents.tokenManage",
192
192
  "agents.createDeviceToken": "agents.tokenManage",
193
+ "agents.listCredentials": "agents.tokenRead",
194
+ "agents.listOrganisationCredentials": "agents.tokenRead",
195
+ "agents.createApiKey": "agents.tokenManage",
196
+ "agents.addDeviceKey": "agents.tokenManage",
197
+ "agents.createEnrolmentCode": "agents.tokenManage",
198
+ "agents.revokeCredential": "agents.tokenManage",
193
199
  "channels.listChannels": "channels.list",
194
200
  "channels.getChannel": "channels.get",
195
201
  "channels.createChannel": "channels.create",
@@ -212,6 +218,7 @@ const METHOD_TO_CAPABILITY = {
212
218
  "messages.getInvocationLogs": "messages.invocationLogs",
213
219
  "rpc.send": "rpc.send",
214
220
  "users.getMe": "users.me",
221
+ "users.refreshMfa": "users.me",
215
222
  "turn.createTurnToken": "turn.credentials",
216
223
  };
217
224
  function guessCapability(subclient) {
@@ -62,6 +62,7 @@ const NONCORE_METHODS = {
62
62
  // turn / users
63
63
  "turn.createTurnToken": { cap: "turn.credentials", kind: "read-fanout-first", agentScoped: false },
64
64
  "users.getMe": { cap: "users.me", kind: "read-fanout-first", agentScoped: false },
65
+ "users.refreshMfa": { cap: "users.me", kind: "read-fanout-first", agentScoped: false },
65
66
  };
66
67
  class MultiplexClient {
67
68
  constructor(options) {
@@ -670,6 +671,12 @@ class MultiplexClient {
670
671
  setRevocationFloor: self.routedWrite("agents.setRevocationFloor", "agents.tokenManage"),
671
672
  createAdhocToken: self.routedWrite("agents.createAdhocToken", "agents.tokenManage"),
672
673
  createDeviceToken: self.routedWrite("agents.createDeviceToken", "agents.tokenManage"),
674
+ listCredentials: self.makeFanoutFirst("agents.listCredentials", "agents.tokenRead"),
675
+ listOrganisationCredentials: self.makeFanoutFirst("agents.listOrganisationCredentials", "agents.tokenRead"),
676
+ createApiKey: self.routedWrite("agents.createApiKey", "agents.tokenManage"),
677
+ addDeviceKey: self.routedWrite("agents.addDeviceKey", "agents.tokenManage"),
678
+ createEnrolmentCode: self.routedWrite("agents.createEnrolmentCode", "agents.tokenManage"),
679
+ revokeCredential: self.routedWrite("agents.revokeCredential", "agents.tokenManage"),
673
680
  };
674
681
  }
675
682
  // ===== non-core generic facade =====
@@ -43,6 +43,8 @@ export interface AgentTokenState {
43
43
  self_rotation: TokenPolicyField<boolean>;
44
44
  max_age_ms: TokenPolicyField<number>;
45
45
  reuse_grace_ms: TokenPolicyField<number>;
46
+ /** Whether v1 mini-tokens and OAuth client secrets are refused. */
47
+ require_key_auth: TokenPolicyField<boolean>;
46
48
  }
47
49
  /**
48
50
  * A token-posture override. `null` on any field means "inherit the organisation
@@ -62,6 +64,11 @@ export interface AgentTokenPolicy {
62
64
  * Setting this opts the device into *automatic* lockout on reuse detection.
63
65
  */
64
66
  reuse_grace_ms?: number | null;
67
+ /**
68
+ * Refuse v1 mini-tokens and OAuth client secrets, so only key pairs and API
69
+ * keys work for this device.
70
+ */
71
+ require_key_auth?: boolean | null;
65
72
  }
66
73
  export interface ResourcePermission {
67
74
  permission_id: string;
@@ -72,6 +79,67 @@ export interface AdhocTokenResponse {
72
79
  token: string;
73
80
  token_id: string | null;
74
81
  }
82
+ export type CredentialKind = "api_key" | "device_key" | "enrolment_code";
83
+ /**
84
+ * Narrows an API key below its agent's own access; the key can do what both
85
+ * allow. A restricted key never gets control-plane or superuser powers.
86
+ */
87
+ export interface KeyRestriction {
88
+ /** Only reading and subscribing. */
89
+ read_only?: boolean;
90
+ /** Only these agents and their channels. Omit for everything. */
91
+ agents?: string[];
92
+ /**
93
+ * A custom policy instead of `read_only` and `agents`: named-action
94
+ * statements, `data:` actions only. Still intersected with the agent's
95
+ * own access.
96
+ */
97
+ policy?: KeyPolicy;
98
+ }
99
+ export interface KeyPolicy {
100
+ statements: {
101
+ effect: "allow" | "deny";
102
+ actions: string[];
103
+ resources: string[];
104
+ /** Missing request values never widen access. */
105
+ conditions?: {
106
+ source_ip?: {
107
+ in: string[];
108
+ } | {
109
+ not_in: string[];
110
+ };
111
+ transport?: {
112
+ in: string[];
113
+ } | {
114
+ not_in: string[];
115
+ };
116
+ };
117
+ }[];
118
+ }
119
+ /** An agent's API key or device key. Never includes the secret. */
120
+ export interface AgentCredential {
121
+ id: string;
122
+ /** The agent it belongs to. */
123
+ agent_id: string;
124
+ kind: CredentialKind;
125
+ name: string;
126
+ /** The agent (user or device) that created it. */
127
+ created_by: string;
128
+ created_ms: number;
129
+ /** Updated at most hourly. */
130
+ last_used_ms?: number | null;
131
+ /** Set once revoked. A revoked credential stays listed. */
132
+ revoked_ms?: number | null;
133
+ restriction?: KeyRestriction | null;
134
+ /** Unix ms after which it stops working. Null: never. */
135
+ expires_ms?: number | null;
136
+ /** For an enrolment code: the device key it enrolled, once used. */
137
+ enrolled_key?: string | null;
138
+ }
139
+ export interface CreatedCredential extends AgentCredential {
140
+ /** The API key itself (`dv_key_…`). Shown once; absent for a device key. */
141
+ key?: string;
142
+ }
75
143
  export interface DeviceTokenResponse {
76
144
  /** Shown once. Not stored anywhere and not retrievable afterwards. */
77
145
  token: string;
@@ -193,4 +261,44 @@ export declare class AgentsApi {
193
261
  * Returned once and stored nowhere. If it's lost, mint another.
194
262
  */
195
263
  createDeviceToken(agentId: string): Promise<DeviceTokenResponse>;
264
+ /**
265
+ * An agent's API keys and device keys, newest first, revoked ones included.
266
+ * Requires `AgentTokenRead`.
267
+ */
268
+ listCredentials(agentId: string): Promise<AgentCredential[]>;
269
+ /**
270
+ * Every credential on an organisation's agents (devices and service
271
+ * accounts) that you may list, each with its `agent_id`, newest first.
272
+ */
273
+ listOrganisationCredentials(organisationId: string): Promise<AgentCredential[]>;
274
+ /**
275
+ * Mint an API key for an agent. It acts as the agent, with the agent's
276
+ * grants, as `Authorization: Bearer dv_key_…`, and works against doover-data
277
+ * only for now. The key is in the response once and never again.
278
+ *
279
+ * `restriction` narrows it (read-only, chosen agents) and `expiresMs` ends
280
+ * it; both only ever take access away from what the agent has.
281
+ */
282
+ createApiKey(agentId: string, name: string, options?: {
283
+ restriction?: KeyRestriction;
284
+ expiresMs?: number;
285
+ }): Promise<CreatedCredential>;
286
+ /**
287
+ * Register a device's P-256 public key (PEM or JWK). The device then
288
+ * authenticates to `/oauth2/token` with assertions signed by its private key
289
+ * and gets 24 hour tokens.
290
+ */
291
+ addDeviceKey(agentId: string, name: string, publicKey: string): Promise<CreatedCredential>;
292
+ /**
293
+ * Mint an enrolment code for a device: the device redeems it once at
294
+ * `POST /enrol` with its public key, which adds a device public key to it.
295
+ * The code is in the response once. Expires after 4 hours unless
296
+ * `expiresMs` says otherwise (at most 7 days).
297
+ */
298
+ createEnrolmentCode(agentId: string, name: string, expiresMs?: number): Promise<CreatedCredential>;
299
+ /**
300
+ * Revoke an API key or device key. Takes effect at once, including for
301
+ * tokens already issued from a device key.
302
+ */
303
+ revokeCredential(agentId: string, credentialId: string): Promise<void>;
196
304
  }
@@ -3,9 +3,7 @@ function isPlainObject(value) {
3
3
  return typeof value === "object" && value !== null && !Array.isArray(value);
4
4
  }
5
5
  function buildUserDisplayName(rawUser) {
6
- const source = isPlainObject(rawUser)
7
- ? rawUser
8
- : {};
6
+ const source = isPlainObject(rawUser) ? rawUser : {};
9
7
  const firstName = typeof source.first_name === "string" ? source.first_name.trim() : "";
10
8
  const lastName = typeof source.last_name === "string" ? source.last_name.trim() : "";
11
9
  const fullName = `${firstName} ${lastName}`.trim();
@@ -82,9 +80,7 @@ function normalizeOrganisationEntry(rawOrganisation) {
82
80
  };
83
81
  }
84
82
  function normalizeUserEntry(rawUser) {
85
- const source = isPlainObject(rawUser)
86
- ? rawUser
87
- : {};
83
+ const source = isPlainObject(rawUser) ? rawUser : {};
88
84
  const id = typeof source.id === "string" ? source.id : String(source.id ?? "");
89
85
  const username = typeof source.username === "string" ? source.username : "";
90
86
  const email = typeof source.email === "string" ? source.email : "";
@@ -319,6 +315,68 @@ export class AgentsApi {
319
315
  revoke_existing: false,
320
316
  });
321
317
  }
318
+ /**
319
+ * An agent's API keys and device keys, newest first, revoked ones included.
320
+ * Requires `AgentTokenRead`.
321
+ */
322
+ listCredentials(agentId) {
323
+ return this.rest.get(`/agents/${agentId}/credentials`);
324
+ }
325
+ /**
326
+ * Every credential on an organisation's agents (devices and service
327
+ * accounts) that you may list, each with its `agent_id`, newest first.
328
+ */
329
+ listOrganisationCredentials(organisationId) {
330
+ return this.rest.get(`/organisations/${organisationId}/credentials`);
331
+ }
332
+ /**
333
+ * Mint an API key for an agent. It acts as the agent, with the agent's
334
+ * grants, as `Authorization: Bearer dv_key_…`, and works against doover-data
335
+ * only for now. The key is in the response once and never again.
336
+ *
337
+ * `restriction` narrows it (read-only, chosen agents) and `expiresMs` ends
338
+ * it; both only ever take access away from what the agent has.
339
+ */
340
+ createApiKey(agentId, name, options = {}) {
341
+ return this.rest.post(`/agents/${agentId}/credentials`, {
342
+ kind: "api_key",
343
+ name,
344
+ restriction: options.restriction,
345
+ expires_ms: options.expiresMs,
346
+ });
347
+ }
348
+ /**
349
+ * Register a device's P-256 public key (PEM or JWK). The device then
350
+ * authenticates to `/oauth2/token` with assertions signed by its private key
351
+ * and gets 24 hour tokens.
352
+ */
353
+ addDeviceKey(agentId, name, publicKey) {
354
+ return this.rest.post(`/agents/${agentId}/credentials`, {
355
+ kind: "device_key",
356
+ name,
357
+ public_key: publicKey,
358
+ });
359
+ }
360
+ /**
361
+ * Mint an enrolment code for a device: the device redeems it once at
362
+ * `POST /enrol` with its public key, which adds a device public key to it.
363
+ * The code is in the response once. Expires after 4 hours unless
364
+ * `expiresMs` says otherwise (at most 7 days).
365
+ */
366
+ createEnrolmentCode(agentId, name, expiresMs) {
367
+ return this.rest.post(`/agents/${agentId}/credentials`, {
368
+ kind: "enrolment_code",
369
+ name,
370
+ expires_ms: expiresMs,
371
+ });
372
+ }
373
+ /**
374
+ * Revoke an API key or device key. Takes effect at once, including for
375
+ * tokens already issued from a device key.
376
+ */
377
+ revokeCredential(agentId, credentialId) {
378
+ return this.rest.delete(`/agents/${agentId}/credentials/${credentialId}`);
379
+ }
322
380
  }
323
381
  // CloudFront fronts the channels-rest API with a hard 8,192-byte URL quota.
324
382
  // Each agent adds ~30 chars (`agent_id=<19-digit snowflake>&`), so 250 IDs
@@ -5,4 +5,6 @@ export declare class UsersApi {
5
5
  private readonly controlApiUrl?;
6
6
  constructor(rest: RestClient, controlApiUrl?: string | undefined);
7
7
  getMe(): Promise<User>;
8
+ /** Re-read the user's MFA enrollment from the identity provider. */
9
+ refreshMfa(): Promise<User>;
8
10
  }
@@ -6,4 +6,8 @@ export class UsersApi {
6
6
  getMe() {
7
7
  return this.rest.get("/users/me", undefined, this.controlApiUrl);
8
8
  }
9
+ /** Re-read the user's MFA enrollment from the identity provider. */
10
+ refreshMfa() {
11
+ return this.rest.post("/users/me/mfa/refresh/", undefined, undefined, this.controlApiUrl);
12
+ }
9
13
  }
@@ -3,6 +3,7 @@ import { type NetworkStatusSource } from "./network-status.js";
3
3
  import { OrganisationsApi } from "../apis/organisations-api.js";
4
4
  import type { DooverAuth } from "../auth/doover-auth.js";
5
5
  import { RestClient, type DooverClientConfig } from "../http/rest-client.js";
6
+ import type { DooverMfaRequiredError } from "../http/errors.js";
6
7
  import { DooverDataProvider } from "../viewer/doover-data-provider.js";
7
8
  import { type Capability } from "./capabilities.js";
8
9
  import type { AgentsApiLike, AggregatesApiLike, AlarmsApiLike, ChannelsApiLike, ConnectionsApiLike, DataClient, DataClientStatus, AgentScope, GatewayClientLike, MessagesApiLike, NotificationsApiLike, PermissionsApiLike, ProcessorsApiLike, RpcDispatcherLike, TurnApiLike, UsersApiLike } from "./data-client.js";
@@ -40,6 +41,8 @@ export declare class DooverClient implements DataClient {
40
41
  enableStats(): void;
41
42
  disableStats(): void;
42
43
  getStats(): DooverStatsSnapshot;
44
+ /** Called whenever a request is refused because the organisation requires MFA. */
45
+ onMfaRequired(listener: (error: DooverMfaRequiredError) => void): () => void;
43
46
  getCapabilities(): ReadonlySet<Capability>;
44
47
  supports(cap: Capability): boolean;
45
48
  getAgentScope(): Promise<AgentScope>;
@@ -87,6 +87,10 @@ export class DooverClient {
87
87
  enableStats() { this.stats.setEnabled(true); }
88
88
  disableStats() { this.stats.setEnabled(false); }
89
89
  getStats() { return this.stats.snapshot(); }
90
+ /** Called whenever a request is refused because the organisation requires MFA. */
91
+ onMfaRequired(listener) {
92
+ return this.rest.onMfaRequired(listener);
93
+ }
90
94
  // --- DataClient: capabilities ---
91
95
  getCapabilities() { return ALL_CAPS_SET; }
92
96
  supports(cap) { return ALL_CAPS_SET.has(cap); }
@@ -186,6 +186,12 @@ const METHOD_TO_CAPABILITY = {
186
186
  "agents.setRevocationFloor": "agents.tokenManage",
187
187
  "agents.createAdhocToken": "agents.tokenManage",
188
188
  "agents.createDeviceToken": "agents.tokenManage",
189
+ "agents.listCredentials": "agents.tokenRead",
190
+ "agents.listOrganisationCredentials": "agents.tokenRead",
191
+ "agents.createApiKey": "agents.tokenManage",
192
+ "agents.addDeviceKey": "agents.tokenManage",
193
+ "agents.createEnrolmentCode": "agents.tokenManage",
194
+ "agents.revokeCredential": "agents.tokenManage",
189
195
  "channels.listChannels": "channels.list",
190
196
  "channels.getChannel": "channels.get",
191
197
  "channels.createChannel": "channels.create",
@@ -208,6 +214,7 @@ const METHOD_TO_CAPABILITY = {
208
214
  "messages.getInvocationLogs": "messages.invocationLogs",
209
215
  "rpc.send": "rpc.send",
210
216
  "users.getMe": "users.me",
217
+ "users.refreshMfa": "users.me",
211
218
  "turn.createTurnToken": "turn.credentials",
212
219
  };
213
220
  function guessCapability(subclient) {
@@ -59,6 +59,7 @@ const NONCORE_METHODS = {
59
59
  // turn / users
60
60
  "turn.createTurnToken": { cap: "turn.credentials", kind: "read-fanout-first", agentScoped: false },
61
61
  "users.getMe": { cap: "users.me", kind: "read-fanout-first", agentScoped: false },
62
+ "users.refreshMfa": { cap: "users.me", kind: "read-fanout-first", agentScoped: false },
62
63
  };
63
64
  export class MultiplexClient {
64
65
  constructor(options) {
@@ -667,6 +668,12 @@ export class MultiplexClient {
667
668
  setRevocationFloor: self.routedWrite("agents.setRevocationFloor", "agents.tokenManage"),
668
669
  createAdhocToken: self.routedWrite("agents.createAdhocToken", "agents.tokenManage"),
669
670
  createDeviceToken: self.routedWrite("agents.createDeviceToken", "agents.tokenManage"),
671
+ listCredentials: self.makeFanoutFirst("agents.listCredentials", "agents.tokenRead"),
672
+ listOrganisationCredentials: self.makeFanoutFirst("agents.listOrganisationCredentials", "agents.tokenRead"),
673
+ createApiKey: self.routedWrite("agents.createApiKey", "agents.tokenManage"),
674
+ addDeviceKey: self.routedWrite("agents.addDeviceKey", "agents.tokenManage"),
675
+ createEnrolmentCode: self.routedWrite("agents.createEnrolmentCode", "agents.tokenManage"),
676
+ revokeCredential: self.routedWrite("agents.revokeCredential", "agents.tokenManage"),
670
677
  };
671
678
  }
672
679
  // ===== non-core generic facade =====
@@ -11,6 +11,10 @@ export declare class DooverApiError extends Error {
11
11
  message?: string;
12
12
  });
13
13
  }
14
+ export declare class DooverMfaRequiredError extends DooverApiError {
15
+ constructor(params: ConstructorParameters<typeof DooverApiError>[0]);
16
+ }
17
+ export declare function isMfaRequiredBody(body: unknown): boolean;
14
18
  export declare class DooverValidationError extends Error {
15
19
  constructor(message: string);
16
20
  }
@@ -8,6 +8,17 @@ export class DooverApiError extends Error {
8
8
  this.method = params.method;
9
9
  }
10
10
  }
11
+ export class DooverMfaRequiredError extends DooverApiError {
12
+ constructor(params) {
13
+ super(params);
14
+ this.name = "DooverMfaRequiredError";
15
+ }
16
+ }
17
+ export function isMfaRequiredBody(body) {
18
+ return (typeof body === "object" &&
19
+ body !== null &&
20
+ body.code === "mfa_required");
21
+ }
11
22
  export class DooverValidationError extends Error {
12
23
  constructor(message) {
13
24
  super(message);
@@ -1,3 +1,3 @@
1
1
  export { RestClient } from "./rest-client.js";
2
2
  export type { DooverClientConfig, RequestOptions } from "./rest-client.js";
3
- export { DooverApiError, DooverGatewayError, DooverValidationError } from "./errors.js";
3
+ export { DooverApiError, DooverGatewayError, DooverMfaRequiredError, DooverValidationError, isMfaRequiredBody, } from "./errors.js";