doover-js 0.14.2 → 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.
@@ -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.
@@ -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",
@@ -671,6 +671,12 @@ class MultiplexClient {
671
671
  setRevocationFloor: self.routedWrite("agents.setRevocationFloor", "agents.tokenManage"),
672
672
  createAdhocToken: self.routedWrite("agents.createAdhocToken", "agents.tokenManage"),
673
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"),
674
680
  };
675
681
  }
676
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
@@ -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",
@@ -668,6 +668,12 @@ export class MultiplexClient {
668
668
  setRevocationFloor: self.routedWrite("agents.setRevocationFloor", "agents.tokenManage"),
669
669
  createAdhocToken: self.routedWrite("agents.createAdhocToken", "agents.tokenManage"),
670
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"),
671
677
  };
672
678
  }
673
679
  // ===== non-core generic facade =====
@@ -78,7 +78,10 @@ export class RestClient {
78
78
  }
79
79
  }
80
80
  prepareRequest(options) {
81
- const method = options.method ?? "GET";
81
+ // fetch normalises GET, POST, PUT and DELETE but not PATCH, and a CORS
82
+ // preflight compares methods case-sensitively; refine's custom calls
83
+ // pass them lowercase.
84
+ const method = (options.method ?? "GET").toUpperCase();
82
85
  const url = this.buildUrl(options.baseUrl ?? this.config.dataRestUrl, options.path, options.query);
83
86
  const headers = new Headers(options.headers);
84
87
  const body = this.normalizeBody(options.body, headers);
@@ -7,7 +7,7 @@ export { getDooverClient, peekDooverClient, resetDooverClient, } from "./client/
7
7
  export { DooverStatsCollector } from "./client/stats.js";
8
8
  export type { DooverStatsSnapshot, RestStatsSnapshot, GatewayStatsSnapshot, } from "./client/stats.js";
9
9
  export { AgentsApi } from "./apis/agents-api.js";
10
- export type { AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, } from "./apis/agents-api.js";
10
+ export type { AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, AgentCredential, CreatedCredential, CredentialKind, KeyRestriction, KeyPolicy, } from "./apis/agents-api.js";
11
11
  export { AggregatesApi } from "./apis/aggregates-api.js";
12
12
  export { AlarmsApi } from "./apis/alarms-api.js";
13
13
  export { ChannelsApi } from "./apis/channels-api.js";
@@ -1 +1 @@
1
- {"name":"doover-js","version":"0.14.2","type":"module","sideEffects":false}
1
+ {"name":"doover-js","version":"0.15.0","type":"module","sideEffects":false}
@@ -1,13 +1,13 @@
1
1
  export { DooverProvider, useDooverClient } from "./context.js";
2
2
  export type { DooverProviderProps } from "./context.js";
3
- export type { DataClientStatus, DataClientConnectionState, AgentScope } from "../client/data-client.js";
3
+ export type { DataClientStatus, DataClientConnectionState, AgentScope, } from "../client/data-client.js";
4
4
  export { useClientStatus } from "./useClientStatus.js";
5
5
  export { useOfflineStatus, hasOfflineStatus } from "./useOfflineStatus.js";
6
- export type { OfflineStatusSnapshot, OfflineStatusClient } from "./useOfflineStatus.js";
6
+ export type { OfflineStatusSnapshot, OfflineStatusClient, } from "./useOfflineStatus.js";
7
7
  export { useConnectionState } from "./useConnectionState.js";
8
- export type { ConnectionState, ConnectionStatus } from "./useConnectionState.js";
8
+ export type { ConnectionState, ConnectionStatus, } from "./useConnectionState.js";
9
9
  export { useAgentConnections, agentConnectionsQueryKey, } from "./useAgentConnections.js";
10
- export { useChannelSubscription, } from "./useChannelSubscription.js";
10
+ export { useChannelSubscription } from "./useChannelSubscription.js";
11
11
  export type { ChannelSubscriptionHandlers } from "./useChannelSubscription.js";
12
12
  export { useChannelAggregate, channelAggregateQueryKey, } from "./useChannelAggregate.js";
13
13
  export type { UseChannelAggregateOptions, UseChannelAggregateResult, } from "./useChannelAggregate.js";
@@ -35,5 +35,6 @@ export type { DeviceMapEntry, UseDeviceMapOptions, UseDeviceMapResult, } from ".
35
35
  export { useTurnCredentials } from "./useTurnCredentials.js";
36
36
  export { useAgentTokenState, useSetAgentTokenPolicy, useSetAgentAuthLock, useRevokeAgentTokens, useSetRevocationFloor, useCreateAdhocToken, useCreateDeviceToken, agentTokenStateQueryKey, } from "./useAgentTokenState.js";
37
37
  export type { UseAgentTokenStateOptions } from "./useAgentTokenState.js";
38
+ export { useAgentCredentials, useOrganisationCredentials, organisationCredentialsQueryKey, useCreateApiKey, useAddDeviceKey, useCreateEnrolmentCode, useRevokeCredential, agentCredentialsQueryKey, } from "./useAgentCredentials.js";
38
39
  export { getSharedQueryClient, resetSharedQueryClient, } from "./sharedQueryClient.js";
39
40
  export { useServiceReachability } from "./useServiceReachability.js";
@@ -3,7 +3,7 @@ export { useClientStatus } from "./useClientStatus.js";
3
3
  export { useOfflineStatus, hasOfflineStatus } from "./useOfflineStatus.js";
4
4
  export { useConnectionState } from "./useConnectionState.js";
5
5
  export { useAgentConnections, agentConnectionsQueryKey, } from "./useAgentConnections.js";
6
- export { useChannelSubscription, } from "./useChannelSubscription.js";
6
+ export { useChannelSubscription } from "./useChannelSubscription.js";
7
7
  export { useChannelAggregate, channelAggregateQueryKey, } from "./useChannelAggregate.js";
8
8
  export { useAgentChannel } from "./useAgentChannel.js";
9
9
  export { useSendMessage } from "./useSendMessage.js";
@@ -18,5 +18,6 @@ export { useMultiAgentChannelMessages, multiAgentChannelMessagesQueryKey, MULTI_
18
18
  export { useDeviceMap } from "./useDeviceMap.js";
19
19
  export { useTurnCredentials } from "./useTurnCredentials.js";
20
20
  export { useAgentTokenState, useSetAgentTokenPolicy, useSetAgentAuthLock, useRevokeAgentTokens, useSetRevocationFloor, useCreateAdhocToken, useCreateDeviceToken, agentTokenStateQueryKey, } from "./useAgentTokenState.js";
21
+ export { useAgentCredentials, useOrganisationCredentials, organisationCredentialsQueryKey, useCreateApiKey, useAddDeviceKey, useCreateEnrolmentCode, useRevokeCredential, agentCredentialsQueryKey, } from "./useAgentCredentials.js";
21
22
  export { getSharedQueryClient, resetSharedQueryClient, } from "./sharedQueryClient.js";
22
23
  export { useServiceReachability } from "./useServiceReachability.js";
@@ -0,0 +1,30 @@
1
+ import { type UseQueryResult } from "@tanstack/react-query";
2
+ import type { AgentCredential, KeyRestriction } from "../apis/agents-api.js";
3
+ export declare function agentCredentialsQueryKey(agentId: string | undefined): readonly ["doover", "agent", string | null, "credentials"];
4
+ export declare function organisationCredentialsQueryKey(organisationId: string | undefined): readonly ["doover", "organisation", string | null, "credentials"];
5
+ /** Every credential on an organisation's agents, revoked ones included. */
6
+ export declare function useOrganisationCredentials(organisationId: string | undefined, options?: {
7
+ enabled?: boolean;
8
+ }): UseQueryResult<AgentCredential[]>;
9
+ /** An agent's API keys and device keys, revoked ones included. */
10
+ export declare function useAgentCredentials(agentId: string | undefined, options?: {
11
+ enabled?: boolean;
12
+ }): UseQueryResult<AgentCredential[]>;
13
+ /** Mint an API key. The key is in the result once; hand it straight to the user. */
14
+ export declare function useCreateApiKey(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api.js").CreatedCredential, Error, {
15
+ name: string;
16
+ restriction?: KeyRestriction;
17
+ expiresMs?: number;
18
+ }, unknown>;
19
+ /** Register a device's P-256 public key (PEM or JWK). */
20
+ export declare function useAddDeviceKey(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api.js").CreatedCredential, Error, {
21
+ name: string;
22
+ publicKey: string;
23
+ }, unknown>;
24
+ /** Mint a one-time enrolment code for a device. Shown once. */
25
+ export declare function useCreateEnrolmentCode(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api.js").CreatedCredential, Error, {
26
+ name: string;
27
+ expiresMs?: number;
28
+ }, unknown>;
29
+ /** Revoke an API key or device key. Takes effect at once. */
30
+ export declare function useRevokeCredential(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<void, Error, string, unknown>;
@@ -0,0 +1,69 @@
1
+ import { useMutation, useQuery, useQueryClient, } from "@tanstack/react-query";
2
+ import { useDooverClient } from "./context.js";
3
+ export function agentCredentialsQueryKey(agentId) {
4
+ return ["doover", "agent", agentId ?? null, "credentials"];
5
+ }
6
+ export function organisationCredentialsQueryKey(organisationId) {
7
+ return [
8
+ "doover",
9
+ "organisation",
10
+ organisationId ?? null,
11
+ "credentials",
12
+ ];
13
+ }
14
+ /** Every credential on an organisation's agents, revoked ones included. */
15
+ export function useOrganisationCredentials(organisationId, options) {
16
+ const client = useDooverClient();
17
+ return useQuery({
18
+ queryKey: organisationCredentialsQueryKey(organisationId),
19
+ enabled: (options?.enabled ?? true) && Boolean(organisationId),
20
+ queryFn: () => client.agents.listOrganisationCredentials(organisationId),
21
+ });
22
+ }
23
+ /** An agent's API keys and device keys, revoked ones included. */
24
+ export function useAgentCredentials(agentId, options) {
25
+ const client = useDooverClient();
26
+ return useQuery({
27
+ queryKey: agentCredentialsQueryKey(agentId),
28
+ enabled: (options?.enabled ?? true) && Boolean(agentId),
29
+ queryFn: () => client.agents.listCredentials(agentId),
30
+ });
31
+ }
32
+ function useCredentialMutation(agentId, mutationFn) {
33
+ const queryClient = useQueryClient();
34
+ return useMutation({
35
+ mutationFn: (vars) => mutationFn(agentId, vars),
36
+ onSuccess: () => {
37
+ void queryClient.invalidateQueries({
38
+ queryKey: agentCredentialsQueryKey(agentId),
39
+ });
40
+ // Org-wide lists include this agent's keys.
41
+ void queryClient.invalidateQueries({
42
+ queryKey: ["doover", "organisation"],
43
+ });
44
+ },
45
+ });
46
+ }
47
+ /** Mint an API key. The key is in the result once; hand it straight to the user. */
48
+ export function useCreateApiKey(agentId) {
49
+ const client = useDooverClient();
50
+ return useCredentialMutation(agentId, (id, vars) => client.agents.createApiKey(id, vars.name, {
51
+ restriction: vars.restriction,
52
+ expiresMs: vars.expiresMs,
53
+ }));
54
+ }
55
+ /** Register a device's P-256 public key (PEM or JWK). */
56
+ export function useAddDeviceKey(agentId) {
57
+ const client = useDooverClient();
58
+ return useCredentialMutation(agentId, (id, vars) => client.agents.addDeviceKey(id, vars.name, vars.publicKey));
59
+ }
60
+ /** Mint a one-time enrolment code for a device. Shown once. */
61
+ export function useCreateEnrolmentCode(agentId) {
62
+ const client = useDooverClient();
63
+ return useCredentialMutation(agentId, (id, vars) => client.agents.createEnrolmentCode(id, vars.name, vars.expiresMs));
64
+ }
65
+ /** Revoke an API key or device key. Takes effect at once. */
66
+ export function useRevokeCredential(agentId) {
67
+ const client = useDooverClient();
68
+ return useCredentialMutation(agentId, (id, credentialId) => client.agents.revokeCredential(id, credentialId));
69
+ }
@@ -81,7 +81,10 @@ class RestClient {
81
81
  }
82
82
  }
83
83
  prepareRequest(options) {
84
- const method = options.method ?? "GET";
84
+ // fetch normalises GET, POST, PUT and DELETE but not PATCH, and a CORS
85
+ // preflight compares methods case-sensitively; refine's custom calls
86
+ // pass them lowercase.
87
+ const method = (options.method ?? "GET").toUpperCase();
85
88
  const url = this.buildUrl(options.baseUrl ?? this.config.dataRestUrl, options.path, options.query);
86
89
  const headers = new Headers(options.headers);
87
90
  const body = this.normalizeBody(options.body, headers);
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { getDooverClient, peekDooverClient, resetDooverClient, } from "./client/
7
7
  export { DooverStatsCollector } from "./client/stats.js";
8
8
  export type { DooverStatsSnapshot, RestStatsSnapshot, GatewayStatsSnapshot, } from "./client/stats.js";
9
9
  export { AgentsApi } from "./apis/agents-api.js";
10
- export type { AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, } from "./apis/agents-api.js";
10
+ export type { AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, AgentCredential, CreatedCredential, CredentialKind, KeyRestriction, KeyPolicy, } from "./apis/agents-api.js";
11
11
  export { AggregatesApi } from "./apis/aggregates-api.js";
12
12
  export { AlarmsApi } from "./apis/alarms-api.js";
13
13
  export { ChannelsApi } from "./apis/channels-api.js";
@@ -1,13 +1,13 @@
1
1
  export { DooverProvider, useDooverClient } from "./context.js";
2
2
  export type { DooverProviderProps } from "./context.js";
3
- export type { DataClientStatus, DataClientConnectionState, AgentScope } from "../client/data-client.js";
3
+ export type { DataClientStatus, DataClientConnectionState, AgentScope, } from "../client/data-client.js";
4
4
  export { useClientStatus } from "./useClientStatus.js";
5
5
  export { useOfflineStatus, hasOfflineStatus } from "./useOfflineStatus.js";
6
- export type { OfflineStatusSnapshot, OfflineStatusClient } from "./useOfflineStatus.js";
6
+ export type { OfflineStatusSnapshot, OfflineStatusClient, } from "./useOfflineStatus.js";
7
7
  export { useConnectionState } from "./useConnectionState.js";
8
- export type { ConnectionState, ConnectionStatus } from "./useConnectionState.js";
8
+ export type { ConnectionState, ConnectionStatus, } from "./useConnectionState.js";
9
9
  export { useAgentConnections, agentConnectionsQueryKey, } from "./useAgentConnections.js";
10
- export { useChannelSubscription, } from "./useChannelSubscription.js";
10
+ export { useChannelSubscription } from "./useChannelSubscription.js";
11
11
  export type { ChannelSubscriptionHandlers } from "./useChannelSubscription.js";
12
12
  export { useChannelAggregate, channelAggregateQueryKey, } from "./useChannelAggregate.js";
13
13
  export type { UseChannelAggregateOptions, UseChannelAggregateResult, } from "./useChannelAggregate.js";
@@ -35,5 +35,6 @@ export type { DeviceMapEntry, UseDeviceMapOptions, UseDeviceMapResult, } from ".
35
35
  export { useTurnCredentials } from "./useTurnCredentials.js";
36
36
  export { useAgentTokenState, useSetAgentTokenPolicy, useSetAgentAuthLock, useRevokeAgentTokens, useSetRevocationFloor, useCreateAdhocToken, useCreateDeviceToken, agentTokenStateQueryKey, } from "./useAgentTokenState.js";
37
37
  export type { UseAgentTokenStateOptions } from "./useAgentTokenState.js";
38
+ export { useAgentCredentials, useOrganisationCredentials, organisationCredentialsQueryKey, useCreateApiKey, useAddDeviceKey, useCreateEnrolmentCode, useRevokeCredential, agentCredentialsQueryKey, } from "./useAgentCredentials.js";
38
39
  export { getSharedQueryClient, resetSharedQueryClient, } from "./sharedQueryClient.js";
39
40
  export { useServiceReachability } from "./useServiceReachability.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useServiceReachability = exports.resetSharedQueryClient = exports.getSharedQueryClient = exports.agentTokenStateQueryKey = exports.useCreateDeviceToken = exports.useCreateAdhocToken = exports.useSetRevocationFloor = exports.useRevokeAgentTokens = exports.useSetAgentAuthLock = exports.useSetAgentTokenPolicy = exports.useAgentTokenState = exports.useTurnCredentials = exports.useDeviceMap = exports.MULTI_AGENT_MAX_WINDOW_MS = exports.multiAgentChannelMessagesQueryKey = exports.useMultiAgentChannelMessages = exports.multiAgentAggregatesQueryKey = exports.useMultiAgentAggregates = exports.useSendRpc = exports.invocationLogsQueryKey = exports.useInvocationLogs = exports.channelMessageQueryKey = exports.useChannelMessage = exports.channelMessagesQueryKey = exports.useChannelMessages = exports.useUpdateMessage = exports.useUpdateAggregate = exports.useSendMessage = exports.useAgentChannel = exports.channelAggregateQueryKey = exports.useChannelAggregate = exports.useChannelSubscription = exports.agentConnectionsQueryKey = exports.useAgentConnections = exports.useConnectionState = exports.hasOfflineStatus = exports.useOfflineStatus = exports.useClientStatus = exports.useDooverClient = exports.DooverProvider = void 0;
3
+ exports.useServiceReachability = exports.resetSharedQueryClient = exports.getSharedQueryClient = exports.agentCredentialsQueryKey = exports.useRevokeCredential = exports.useCreateEnrolmentCode = exports.useAddDeviceKey = exports.useCreateApiKey = exports.organisationCredentialsQueryKey = exports.useOrganisationCredentials = exports.useAgentCredentials = exports.agentTokenStateQueryKey = exports.useCreateDeviceToken = exports.useCreateAdhocToken = exports.useSetRevocationFloor = exports.useRevokeAgentTokens = exports.useSetAgentAuthLock = exports.useSetAgentTokenPolicy = exports.useAgentTokenState = exports.useTurnCredentials = exports.useDeviceMap = exports.MULTI_AGENT_MAX_WINDOW_MS = exports.multiAgentChannelMessagesQueryKey = exports.useMultiAgentChannelMessages = exports.multiAgentAggregatesQueryKey = exports.useMultiAgentAggregates = exports.useSendRpc = exports.invocationLogsQueryKey = exports.useInvocationLogs = exports.channelMessageQueryKey = exports.useChannelMessage = exports.channelMessagesQueryKey = exports.useChannelMessages = exports.useUpdateMessage = exports.useUpdateAggregate = exports.useSendMessage = exports.useAgentChannel = exports.channelAggregateQueryKey = exports.useChannelAggregate = exports.useChannelSubscription = exports.agentConnectionsQueryKey = exports.useAgentConnections = exports.useConnectionState = exports.hasOfflineStatus = exports.useOfflineStatus = exports.useClientStatus = exports.useDooverClient = exports.DooverProvider = void 0;
4
4
  var context_js_1 = require("./context.js");
5
5
  Object.defineProperty(exports, "DooverProvider", { enumerable: true, get: function () { return context_js_1.DooverProvider; } });
6
6
  Object.defineProperty(exports, "useDooverClient", { enumerable: true, get: function () { return context_js_1.useDooverClient; } });
@@ -58,6 +58,15 @@ Object.defineProperty(exports, "useSetRevocationFloor", { enumerable: true, get:
58
58
  Object.defineProperty(exports, "useCreateAdhocToken", { enumerable: true, get: function () { return useAgentTokenState_js_1.useCreateAdhocToken; } });
59
59
  Object.defineProperty(exports, "useCreateDeviceToken", { enumerable: true, get: function () { return useAgentTokenState_js_1.useCreateDeviceToken; } });
60
60
  Object.defineProperty(exports, "agentTokenStateQueryKey", { enumerable: true, get: function () { return useAgentTokenState_js_1.agentTokenStateQueryKey; } });
61
+ var useAgentCredentials_js_1 = require("./useAgentCredentials.js");
62
+ Object.defineProperty(exports, "useAgentCredentials", { enumerable: true, get: function () { return useAgentCredentials_js_1.useAgentCredentials; } });
63
+ Object.defineProperty(exports, "useOrganisationCredentials", { enumerable: true, get: function () { return useAgentCredentials_js_1.useOrganisationCredentials; } });
64
+ Object.defineProperty(exports, "organisationCredentialsQueryKey", { enumerable: true, get: function () { return useAgentCredentials_js_1.organisationCredentialsQueryKey; } });
65
+ Object.defineProperty(exports, "useCreateApiKey", { enumerable: true, get: function () { return useAgentCredentials_js_1.useCreateApiKey; } });
66
+ Object.defineProperty(exports, "useAddDeviceKey", { enumerable: true, get: function () { return useAgentCredentials_js_1.useAddDeviceKey; } });
67
+ Object.defineProperty(exports, "useCreateEnrolmentCode", { enumerable: true, get: function () { return useAgentCredentials_js_1.useCreateEnrolmentCode; } });
68
+ Object.defineProperty(exports, "useRevokeCredential", { enumerable: true, get: function () { return useAgentCredentials_js_1.useRevokeCredential; } });
69
+ Object.defineProperty(exports, "agentCredentialsQueryKey", { enumerable: true, get: function () { return useAgentCredentials_js_1.agentCredentialsQueryKey; } });
61
70
  var sharedQueryClient_js_1 = require("./sharedQueryClient.js");
62
71
  Object.defineProperty(exports, "getSharedQueryClient", { enumerable: true, get: function () { return sharedQueryClient_js_1.getSharedQueryClient; } });
63
72
  Object.defineProperty(exports, "resetSharedQueryClient", { enumerable: true, get: function () { return sharedQueryClient_js_1.resetSharedQueryClient; } });
@@ -0,0 +1,30 @@
1
+ import { type UseQueryResult } from "@tanstack/react-query";
2
+ import type { AgentCredential, KeyRestriction } from "../apis/agents-api.js";
3
+ export declare function agentCredentialsQueryKey(agentId: string | undefined): readonly ["doover", "agent", string | null, "credentials"];
4
+ export declare function organisationCredentialsQueryKey(organisationId: string | undefined): readonly ["doover", "organisation", string | null, "credentials"];
5
+ /** Every credential on an organisation's agents, revoked ones included. */
6
+ export declare function useOrganisationCredentials(organisationId: string | undefined, options?: {
7
+ enabled?: boolean;
8
+ }): UseQueryResult<AgentCredential[]>;
9
+ /** An agent's API keys and device keys, revoked ones included. */
10
+ export declare function useAgentCredentials(agentId: string | undefined, options?: {
11
+ enabled?: boolean;
12
+ }): UseQueryResult<AgentCredential[]>;
13
+ /** Mint an API key. The key is in the result once; hand it straight to the user. */
14
+ export declare function useCreateApiKey(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api.js").CreatedCredential, Error, {
15
+ name: string;
16
+ restriction?: KeyRestriction;
17
+ expiresMs?: number;
18
+ }, unknown>;
19
+ /** Register a device's P-256 public key (PEM or JWK). */
20
+ export declare function useAddDeviceKey(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api.js").CreatedCredential, Error, {
21
+ name: string;
22
+ publicKey: string;
23
+ }, unknown>;
24
+ /** Mint a one-time enrolment code for a device. Shown once. */
25
+ export declare function useCreateEnrolmentCode(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api.js").CreatedCredential, Error, {
26
+ name: string;
27
+ expiresMs?: number;
28
+ }, unknown>;
29
+ /** Revoke an API key or device key. Takes effect at once. */
30
+ export declare function useRevokeCredential(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<void, Error, string, unknown>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agentCredentialsQueryKey = agentCredentialsQueryKey;
4
+ exports.organisationCredentialsQueryKey = organisationCredentialsQueryKey;
5
+ exports.useOrganisationCredentials = useOrganisationCredentials;
6
+ exports.useAgentCredentials = useAgentCredentials;
7
+ exports.useCreateApiKey = useCreateApiKey;
8
+ exports.useAddDeviceKey = useAddDeviceKey;
9
+ exports.useCreateEnrolmentCode = useCreateEnrolmentCode;
10
+ exports.useRevokeCredential = useRevokeCredential;
11
+ const react_query_1 = require("@tanstack/react-query");
12
+ const context_js_1 = require("./context.js");
13
+ function agentCredentialsQueryKey(agentId) {
14
+ return ["doover", "agent", agentId ?? null, "credentials"];
15
+ }
16
+ function organisationCredentialsQueryKey(organisationId) {
17
+ return [
18
+ "doover",
19
+ "organisation",
20
+ organisationId ?? null,
21
+ "credentials",
22
+ ];
23
+ }
24
+ /** Every credential on an organisation's agents, revoked ones included. */
25
+ function useOrganisationCredentials(organisationId, options) {
26
+ const client = (0, context_js_1.useDooverClient)();
27
+ return (0, react_query_1.useQuery)({
28
+ queryKey: organisationCredentialsQueryKey(organisationId),
29
+ enabled: (options?.enabled ?? true) && Boolean(organisationId),
30
+ queryFn: () => client.agents.listOrganisationCredentials(organisationId),
31
+ });
32
+ }
33
+ /** An agent's API keys and device keys, revoked ones included. */
34
+ function useAgentCredentials(agentId, options) {
35
+ const client = (0, context_js_1.useDooverClient)();
36
+ return (0, react_query_1.useQuery)({
37
+ queryKey: agentCredentialsQueryKey(agentId),
38
+ enabled: (options?.enabled ?? true) && Boolean(agentId),
39
+ queryFn: () => client.agents.listCredentials(agentId),
40
+ });
41
+ }
42
+ function useCredentialMutation(agentId, mutationFn) {
43
+ const queryClient = (0, react_query_1.useQueryClient)();
44
+ return (0, react_query_1.useMutation)({
45
+ mutationFn: (vars) => mutationFn(agentId, vars),
46
+ onSuccess: () => {
47
+ void queryClient.invalidateQueries({
48
+ queryKey: agentCredentialsQueryKey(agentId),
49
+ });
50
+ // Org-wide lists include this agent's keys.
51
+ void queryClient.invalidateQueries({
52
+ queryKey: ["doover", "organisation"],
53
+ });
54
+ },
55
+ });
56
+ }
57
+ /** Mint an API key. The key is in the result once; hand it straight to the user. */
58
+ function useCreateApiKey(agentId) {
59
+ const client = (0, context_js_1.useDooverClient)();
60
+ return useCredentialMutation(agentId, (id, vars) => client.agents.createApiKey(id, vars.name, {
61
+ restriction: vars.restriction,
62
+ expiresMs: vars.expiresMs,
63
+ }));
64
+ }
65
+ /** Register a device's P-256 public key (PEM or JWK). */
66
+ function useAddDeviceKey(agentId) {
67
+ const client = (0, context_js_1.useDooverClient)();
68
+ return useCredentialMutation(agentId, (id, vars) => client.agents.addDeviceKey(id, vars.name, vars.publicKey));
69
+ }
70
+ /** Mint a one-time enrolment code for a device. Shown once. */
71
+ function useCreateEnrolmentCode(agentId) {
72
+ const client = (0, context_js_1.useDooverClient)();
73
+ return useCredentialMutation(agentId, (id, vars) => client.agents.createEnrolmentCode(id, vars.name, vars.expiresMs));
74
+ }
75
+ /** Revoke an API key or device key. Takes effect at once. */
76
+ function useRevokeCredential(agentId) {
77
+ const client = (0, context_js_1.useDooverClient)();
78
+ return useCredentialMutation(agentId, (id, credentialId) => client.agents.revokeCredential(id, credentialId));
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doover-js",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "description": "TypeScript client for Doover.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",