doover-js 0.8.0 → 0.8.1

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.
@@ -19,6 +19,65 @@ export interface MultiAgentMessagesParams {
19
19
  agent_message_limit?: number;
20
20
  field_name?: string[];
21
21
  }
22
+ /**
23
+ * One token-posture knob across all three layers, so a UI can show
24
+ * "inherited from organisation" vs "overridden on this device" and offer a reset
25
+ * without duplicating the precedence rule client-side.
26
+ */
27
+ export interface TokenPolicyField<T> {
28
+ /** What is actually enforced: `agent_override` if set, else `org_default`. */
29
+ effective: T | null;
30
+ /** This device's override. `null` means it inherits. */
31
+ agent_override: T | null;
32
+ /** The organisation-wide default inherited when not overridden. */
33
+ org_default: T | null;
34
+ }
35
+ export interface AgentTokenState {
36
+ /**
37
+ * Unix-ms revocation floor: every long-lived credential issued before this is
38
+ * rejected. `null` means nothing has ever been revoked for this agent.
39
+ */
40
+ tokens_valid_from: number | null;
41
+ /** Auth kill-switch — while true, every auth attempt is rejected. */
42
+ auth_locked: boolean;
43
+ self_rotation: TokenPolicyField<boolean>;
44
+ max_age_ms: TokenPolicyField<number>;
45
+ reuse_grace_ms: TokenPolicyField<number>;
46
+ }
47
+ /**
48
+ * A token-posture override. `null` on any field means "inherit the organisation
49
+ * default"; there is no way to express "explicitly off, ignoring the default",
50
+ * because every knob here is off when absent.
51
+ */
52
+ export interface AgentTokenPolicy {
53
+ /** Allow the device to trade its own credential for a fresh one. */
54
+ self_rotation?: boolean | null;
55
+ /**
56
+ * Hard maximum credential age. Only valid alongside `self_rotation` — without
57
+ * it the device cannot rotate before the deadline and will be locked out.
58
+ */
59
+ max_age_ms?: number | null;
60
+ /**
61
+ * Grace window after a rotation before a stale credential counts as reuse.
62
+ * Setting this opts the device into *automatic* lockout on reuse detection.
63
+ */
64
+ reuse_grace_ms?: number | null;
65
+ }
66
+ export interface ResourcePermission {
67
+ permission_id: string;
68
+ permission: string;
69
+ }
70
+ export interface AdhocTokenResponse {
71
+ /** Shown once. Not retrievable afterwards. */
72
+ token: string;
73
+ token_id: string | null;
74
+ }
75
+ export interface DeviceTokenResponse {
76
+ /** Shown once. Not stored anywhere and not retrievable afterwards. */
77
+ token: string;
78
+ /** Unix-ms issuance time, which is what the revocation floor compares against. */
79
+ issued_at_ms: number | null;
80
+ }
22
81
  export interface MultiAgentAggregatesParams {
23
82
  agent_id: string[];
24
83
  /**
@@ -56,4 +115,82 @@ export declare class AgentsApi {
56
115
  results: AgentAggregate[];
57
116
  count: number;
58
117
  }>;
118
+ /**
119
+ * Read an agent's credential state: the revocation floor, the auth
120
+ * kill-switch, and the token posture resolved across the per-agent override
121
+ * and the organisation default.
122
+ *
123
+ * Requires `AgentTokenRead`, which is read-only — a caller can display
124
+ * credential state (including an auth-lock banner, often the only explanation
125
+ * for why a device is offline) without being able to change any of it.
126
+ */
127
+ getTokenState(agentId: string): Promise<AgentTokenState>;
128
+ /**
129
+ * Replace an agent's token-posture override. Omitted or null fields mean
130
+ * "inherit the organisation default" — a full replacement rather than a
131
+ * merge, so clearing an override back to inherited is expressible.
132
+ *
133
+ * Rejected server-side if the resolved posture sets `max_age_ms` without
134
+ * `self_rotation`: a device that can't self-rotate has no way to trade its
135
+ * token in before the max age elapses, making that combination a scheduled
136
+ * outage.
137
+ */
138
+ setTokenPolicy(agentId: string, policy: AgentTokenPolicy): Promise<{
139
+ effective: AgentTokenPolicy;
140
+ }>;
141
+ /**
142
+ * Set or clear the auth kill-switch. While locked, every auth attempt for the
143
+ * agent is rejected regardless of token validity.
144
+ *
145
+ * doover-data sets this automatically on suspected token reuse, so clearing it
146
+ * is a routine incident-response action rather than an exotic one.
147
+ */
148
+ setAuthLock(agentId: string, locked: boolean): Promise<void>;
149
+ /**
150
+ * Revoke every outstanding long-lived credential for an agent by advancing the
151
+ * revocation floor. Mints nothing.
152
+ *
153
+ * This takes the device offline until it is re-provisioned. Break-glass:
154
+ * confirm before calling.
155
+ */
156
+ revokeAllTokens(agentId: string): Promise<{
157
+ tokens_valid_from: number;
158
+ }>;
159
+ /**
160
+ * Set the revocation floor to an explicit point, in either direction. `0` or
161
+ * `null` clears it.
162
+ *
163
+ * `revokeAllTokens` is the normal way to revoke. Lowering the floor reverses a
164
+ * revocation, so it is for undoing one made by mistake — not for recovering
165
+ * from a leak, where you should issue fresh credentials instead.
166
+ */
167
+ setRevocationFloor(agentId: string, tokensValidFrom: number | null): Promise<{
168
+ tokens_valid_from: number | null;
169
+ }>;
170
+ /**
171
+ * Mint a short-lived scoped JWT for ad-hoc access to an agent — debugging, a
172
+ * one-off script, an integration.
173
+ *
174
+ * This is the way to give a *person* access to a device. The device's own
175
+ * long-lived credential is deliberately not obtainable through the API: it is
176
+ * minted into an installer bundle and never shown. Expiry stands in for
177
+ * revocation here, so keep `timeout` as short as the task allows.
178
+ */
179
+ createAdhocToken(agentId: string, options?: {
180
+ permissions?: ResourcePermission[];
181
+ timeout?: number;
182
+ }): Promise<AdhocTokenResponse>;
183
+ /**
184
+ * Mint the device's long-lived credential and return it once, for manual
185
+ * provisioning — pasting into a device's config by hand. The installer download
186
+ * mints one into the bundle for you; this is the equivalent for a device you're
187
+ * configuring yourself.
188
+ *
189
+ * Always additive: the revocation floor is left alone, so minting can never
190
+ * knock a running device offline. `revoke_existing` is intentionally not
191
+ * exposed here — revoking is `revokeAllTokens`, a separate deliberate act.
192
+ *
193
+ * Returned once and stored nowhere. If it's lost, mint another.
194
+ */
195
+ createDeviceToken(agentId: string): Promise<DeviceTokenResponse>;
59
196
  }
@@ -232,6 +232,96 @@ class AgentsApi {
232
232
  count: responses.reduce((acc, r) => acc + r.count, 0),
233
233
  };
234
234
  }
235
+ /**
236
+ * Read an agent's credential state: the revocation floor, the auth
237
+ * kill-switch, and the token posture resolved across the per-agent override
238
+ * and the organisation default.
239
+ *
240
+ * Requires `AgentTokenRead`, which is read-only — a caller can display
241
+ * credential state (including an auth-lock banner, often the only explanation
242
+ * for why a device is offline) without being able to change any of it.
243
+ */
244
+ getTokenState(agentId) {
245
+ return this.rest.get(`/agents/${agentId}/token_state`);
246
+ }
247
+ /**
248
+ * Replace an agent's token-posture override. Omitted or null fields mean
249
+ * "inherit the organisation default" — a full replacement rather than a
250
+ * merge, so clearing an override back to inherited is expressible.
251
+ *
252
+ * Rejected server-side if the resolved posture sets `max_age_ms` without
253
+ * `self_rotation`: a device that can't self-rotate has no way to trade its
254
+ * token in before the max age elapses, making that combination a scheduled
255
+ * outage.
256
+ */
257
+ setTokenPolicy(agentId, policy) {
258
+ return this.rest.put(`/agents/${agentId}/token_policy`, policy);
259
+ }
260
+ /**
261
+ * Set or clear the auth kill-switch. While locked, every auth attempt for the
262
+ * agent is rejected regardless of token validity.
263
+ *
264
+ * doover-data sets this automatically on suspected token reuse, so clearing it
265
+ * is a routine incident-response action rather than an exotic one.
266
+ */
267
+ setAuthLock(agentId, locked) {
268
+ return this.rest.post(`/agents/${agentId}/auth_lock`, { locked });
269
+ }
270
+ /**
271
+ * Revoke every outstanding long-lived credential for an agent by advancing the
272
+ * revocation floor. Mints nothing.
273
+ *
274
+ * This takes the device offline until it is re-provisioned. Break-glass:
275
+ * confirm before calling.
276
+ */
277
+ revokeAllTokens(agentId) {
278
+ return this.rest.post(`/agents/${agentId}/token/revoke_all`, {});
279
+ }
280
+ /**
281
+ * Set the revocation floor to an explicit point, in either direction. `0` or
282
+ * `null` clears it.
283
+ *
284
+ * `revokeAllTokens` is the normal way to revoke. Lowering the floor reverses a
285
+ * revocation, so it is for undoing one made by mistake — not for recovering
286
+ * from a leak, where you should issue fresh credentials instead.
287
+ */
288
+ setRevocationFloor(agentId, tokensValidFrom) {
289
+ return this.rest.post(`/agents/${agentId}/token/floor`, { tokens_valid_from: tokensValidFrom });
290
+ }
291
+ /**
292
+ * Mint a short-lived scoped JWT for ad-hoc access to an agent — debugging, a
293
+ * one-off script, an integration.
294
+ *
295
+ * This is the way to give a *person* access to a device. The device's own
296
+ * long-lived credential is deliberately not obtainable through the API: it is
297
+ * minted into an installer bundle and never shown. Expiry stands in for
298
+ * revocation here, so keep `timeout` as short as the task allows.
299
+ */
300
+ createAdhocToken(agentId, options = {}) {
301
+ return this.rest.post(`/agents/${agentId}/token`, {
302
+ format: "jwt",
303
+ permissions: options.permissions ?? [],
304
+ timeout: options.timeout,
305
+ });
306
+ }
307
+ /**
308
+ * Mint the device's long-lived credential and return it once, for manual
309
+ * provisioning — pasting into a device's config by hand. The installer download
310
+ * mints one into the bundle for you; this is the equivalent for a device you're
311
+ * configuring yourself.
312
+ *
313
+ * Always additive: the revocation floor is left alone, so minting can never
314
+ * knock a running device offline. `revoke_existing` is intentionally not
315
+ * exposed here — revoking is `revokeAllTokens`, a separate deliberate act.
316
+ *
317
+ * Returned once and stored nowhere. If it's lost, mint another.
318
+ */
319
+ createDeviceToken(agentId) {
320
+ return this.rest.post(`/agents/${agentId}/token`, {
321
+ format: "mini_v1",
322
+ revoke_existing: false,
323
+ });
324
+ }
235
325
  }
236
326
  exports.AgentsApi = AgentsApi;
237
327
  // CloudFront fronts the channels-rest API with a hard 8,192-byte URL quota.
@@ -6,5 +6,5 @@
6
6
  * String-literal union (not a TS enum) so values serialise cleanly and can
7
7
  * appear in error messages / debug UIs verbatim.
8
8
  */
9
- export type Capability = "agents.list" | "agents.multiAgentMessages" | "agents.multiAgentAggregates" | "channels.list" | "channels.get" | "channels.create" | "channels.archive" | "channels.dataSeries" | "aggregates.get" | "aggregates.put" | "aggregates.patch" | "aggregates.attachment" | "messages.list" | "messages.listHistorical" | "messages.get" | "messages.post" | "messages.put" | "messages.delete" | "messages.attachment" | "messages.timeseries" | "messages.invocationLogs" | "gateway.subscribe" | "gateway.realtime" | "gateway.oneShot" | "rpc.send" | "alarms.read" | "alarms.write" | "connections.read" | "connections.write" | "notifications.read" | "notifications.write" | "permissions.read" | "permissions.write" | "processors.read" | "processors.write" | "turn.credentials" | "users.me";
9
+ export type Capability = "agents.list" | "agents.multiAgentMessages" | "agents.multiAgentAggregates" | "agents.tokenRead" | "agents.tokenManage" | "channels.list" | "channels.get" | "channels.create" | "channels.archive" | "channels.dataSeries" | "aggregates.get" | "aggregates.put" | "aggregates.patch" | "aggregates.attachment" | "messages.list" | "messages.listHistorical" | "messages.get" | "messages.post" | "messages.put" | "messages.delete" | "messages.attachment" | "messages.timeseries" | "messages.invocationLogs" | "gateway.subscribe" | "gateway.realtime" | "gateway.oneShot" | "rpc.send" | "alarms.read" | "alarms.write" | "connections.read" | "connections.write" | "notifications.read" | "notifications.write" | "permissions.read" | "permissions.write" | "processors.read" | "processors.write" | "turn.credentials" | "users.me";
10
10
  export declare const ALL_CAPABILITIES: readonly Capability[];
@@ -5,6 +5,8 @@ exports.ALL_CAPABILITIES = [
5
5
  "agents.list",
6
6
  "agents.multiAgentMessages",
7
7
  "agents.multiAgentAggregates",
8
+ "agents.tokenRead",
9
+ "agents.tokenManage",
8
10
  "channels.list",
9
11
  "channels.get",
10
12
  "channels.create",
@@ -183,6 +183,13 @@ const METHOD_TO_CAPABILITY = {
183
183
  "agents.listAgents": "agents.list",
184
184
  "agents.getMultiAgentMessages": "agents.multiAgentMessages",
185
185
  "agents.getMultiAgentAggregates": "agents.multiAgentAggregates",
186
+ "agents.getTokenState": "agents.tokenRead",
187
+ "agents.setTokenPolicy": "agents.tokenManage",
188
+ "agents.setAuthLock": "agents.tokenManage",
189
+ "agents.revokeAllTokens": "agents.tokenManage",
190
+ "agents.setRevocationFloor": "agents.tokenManage",
191
+ "agents.createAdhocToken": "agents.tokenManage",
192
+ "agents.createDeviceToken": "agents.tokenManage",
186
193
  "channels.listChannels": "channels.list",
187
194
  "channels.getChannel": "channels.get",
188
195
  "channels.createChannel": "channels.create",
@@ -660,6 +660,13 @@ class MultiplexClient {
660
660
  const merged = (0, multiplex_merge_1.dedupeBy)([].concat(...responses.map((r) => r.results)), (a) => a.agent_id);
661
661
  return { results: merged, count: merged.length };
662
662
  },
663
+ getTokenState: self.makeFanoutFirst("agents.getTokenState", "agents.tokenRead"),
664
+ setTokenPolicy: self.routedWrite("agents.setTokenPolicy", "agents.tokenManage"),
665
+ setAuthLock: self.routedWrite("agents.setAuthLock", "agents.tokenManage"),
666
+ revokeAllTokens: self.routedWrite("agents.revokeAllTokens", "agents.tokenManage"),
667
+ setRevocationFloor: self.routedWrite("agents.setRevocationFloor", "agents.tokenManage"),
668
+ createAdhocToken: self.routedWrite("agents.createAdhocToken", "agents.tokenManage"),
669
+ createDeviceToken: self.routedWrite("agents.createDeviceToken", "agents.tokenManage"),
663
670
  };
664
671
  }
665
672
  // ===== non-core generic facade =====
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { getDooverClient, peekDooverClient, resetDooverClient, } from "./client/
7
7
  export { DooverStatsCollector } from "./client/stats";
8
8
  export type { DooverStatsSnapshot, RestStatsSnapshot, GatewayStatsSnapshot, } from "./client/stats";
9
9
  export { AgentsApi } from "./apis/agents-api";
10
+ export type { AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, } from "./apis/agents-api";
10
11
  export { AggregatesApi } from "./apis/aggregates-api";
11
12
  export { AlarmsApi } from "./apis/alarms-api";
12
13
  export { ChannelsApi } from "./apis/channels-api";
@@ -33,4 +33,6 @@ export type { UseMultiAgentChannelMessagesOptions, UseMultiAgentChannelMessagesR
33
33
  export { useDeviceMap } from "./useDeviceMap";
34
34
  export type { DeviceMapEntry, UseDeviceMapOptions, UseDeviceMapResult, } from "./useDeviceMap";
35
35
  export { useTurnCredentials } from "./useTurnCredentials";
36
+ export { useAgentTokenState, useSetAgentTokenPolicy, useSetAgentAuthLock, useRevokeAgentTokens, useSetRevocationFloor, useCreateAdhocToken, useCreateDeviceToken, agentTokenStateQueryKey, } from "./useAgentTokenState";
37
+ export type { UseAgentTokenStateOptions } from "./useAgentTokenState";
36
38
  export { getSharedQueryClient, resetSharedQueryClient, } from "./sharedQueryClient";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetSharedQueryClient = exports.getSharedQueryClient = exports.useTurnCredentials = exports.useDeviceMap = 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.resetSharedQueryClient = exports.getSharedQueryClient = exports.agentTokenStateQueryKey = exports.useCreateDeviceToken = exports.useCreateAdhocToken = exports.useSetRevocationFloor = exports.useRevokeAgentTokens = exports.useSetAgentAuthLock = exports.useSetAgentTokenPolicy = exports.useAgentTokenState = exports.useTurnCredentials = exports.useDeviceMap = 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_1 = require("./context");
5
5
  Object.defineProperty(exports, "DooverProvider", { enumerable: true, get: function () { return context_1.DooverProvider; } });
6
6
  Object.defineProperty(exports, "useDooverClient", { enumerable: true, get: function () { return context_1.useDooverClient; } });
@@ -48,6 +48,15 @@ var useDeviceMap_1 = require("./useDeviceMap");
48
48
  Object.defineProperty(exports, "useDeviceMap", { enumerable: true, get: function () { return useDeviceMap_1.useDeviceMap; } });
49
49
  var useTurnCredentials_1 = require("./useTurnCredentials");
50
50
  Object.defineProperty(exports, "useTurnCredentials", { enumerable: true, get: function () { return useTurnCredentials_1.useTurnCredentials; } });
51
+ var useAgentTokenState_1 = require("./useAgentTokenState");
52
+ Object.defineProperty(exports, "useAgentTokenState", { enumerable: true, get: function () { return useAgentTokenState_1.useAgentTokenState; } });
53
+ Object.defineProperty(exports, "useSetAgentTokenPolicy", { enumerable: true, get: function () { return useAgentTokenState_1.useSetAgentTokenPolicy; } });
54
+ Object.defineProperty(exports, "useSetAgentAuthLock", { enumerable: true, get: function () { return useAgentTokenState_1.useSetAgentAuthLock; } });
55
+ Object.defineProperty(exports, "useRevokeAgentTokens", { enumerable: true, get: function () { return useAgentTokenState_1.useRevokeAgentTokens; } });
56
+ Object.defineProperty(exports, "useSetRevocationFloor", { enumerable: true, get: function () { return useAgentTokenState_1.useSetRevocationFloor; } });
57
+ Object.defineProperty(exports, "useCreateAdhocToken", { enumerable: true, get: function () { return useAgentTokenState_1.useCreateAdhocToken; } });
58
+ Object.defineProperty(exports, "useCreateDeviceToken", { enumerable: true, get: function () { return useAgentTokenState_1.useCreateDeviceToken; } });
59
+ Object.defineProperty(exports, "agentTokenStateQueryKey", { enumerable: true, get: function () { return useAgentTokenState_1.agentTokenStateQueryKey; } });
51
60
  var sharedQueryClient_1 = require("./sharedQueryClient");
52
61
  Object.defineProperty(exports, "getSharedQueryClient", { enumerable: true, get: function () { return sharedQueryClient_1.getSharedQueryClient; } });
53
62
  Object.defineProperty(exports, "resetSharedQueryClient", { enumerable: true, get: function () { return sharedQueryClient_1.resetSharedQueryClient; } });
@@ -0,0 +1,70 @@
1
+ import { type UseQueryResult } from "@tanstack/react-query";
2
+ import type { AgentTokenPolicy, AgentTokenState, ResourcePermission } from "../apis/agents-api";
3
+ export declare function agentTokenStateQueryKey(agentId: string | undefined): readonly ["doover", "agent", string | null, "tokenState"];
4
+ export interface UseAgentTokenStateOptions {
5
+ enabled?: boolean;
6
+ staleTime?: number;
7
+ }
8
+ /**
9
+ * Read an agent's credential state — revocation floor, auth kill-switch, and the
10
+ * token posture resolved across the per-agent override and organisation default.
11
+ *
12
+ * Deliberately short `staleTime`: `auth_locked` can be flipped by doover-data
13
+ * itself (automatic lockout on suspected token reuse), so this value changes
14
+ * without any action from this client. Showing a stale "not locked" on the one
15
+ * screen someone opens *because* their device went offline would be worse than
16
+ * an extra fetch.
17
+ */
18
+ export declare function useAgentTokenState(agentId: string | undefined, options?: UseAgentTokenStateOptions): UseQueryResult<AgentTokenState>;
19
+ /**
20
+ * Write an agent's token-posture override. Full replacement — a null field means
21
+ * "inherit the organisation default".
22
+ *
23
+ * Invalidates the token-state query on success so the inherited-vs-overridden
24
+ * display reflects the write without the caller wiring that up.
25
+ */
26
+ export declare function useSetAgentTokenPolicy(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<{
27
+ effective: AgentTokenPolicy;
28
+ }, Error, AgentTokenPolicy, unknown>;
29
+ /** Set or clear the auth kill-switch. */
30
+ export declare function useSetAgentAuthLock(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<void, Error, boolean, unknown>;
31
+ /**
32
+ * Mint a short-lived scoped token for ad-hoc access to an agent.
33
+ *
34
+ * Does not invalidate the token-state query: an ad-hoc token is a JWT with its
35
+ * own expiry and doesn't touch the revocation floor or the agent's posture, so
36
+ * there is nothing in that query for it to change.
37
+ *
38
+ * The resulting token is returned once and is not retrievable afterwards — hand
39
+ * it straight to the user and don't cache it.
40
+ */
41
+ export declare function useCreateAdhocToken(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api").AdhocTokenResponse, Error, {
42
+ permissions?: ResourcePermission[];
43
+ timeout?: number;
44
+ }, unknown>;
45
+ /**
46
+ * Set the revocation floor to an explicit point; pass `0` or `null` to clear it.
47
+ *
48
+ * Lowering it reverses a revocation, so this is for undoing one made by mistake
49
+ * rather than for recovering a device whose credentials leaked.
50
+ */
51
+ export declare function useSetRevocationFloor(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<{
52
+ tokens_valid_from: number | null;
53
+ }, Error, number | null, unknown>;
54
+ /**
55
+ * Mint the device's long-lived credential for manual provisioning, returned once.
56
+ *
57
+ * Invalidates the token-state query so the revocation floor display stays honest
58
+ * — the mint itself is additive and doesn't move the floor, but refetching keeps
59
+ * this in step with anything else that has changed since the panel loaded.
60
+ */
61
+ export declare function useCreateDeviceToken(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<import("../apis/agents-api").DeviceTokenResponse, Error, void, unknown>;
62
+ /**
63
+ * Revoke every outstanding long-lived credential for an agent.
64
+ *
65
+ * Break-glass: the device stays offline until it is re-provisioned. Confirm with
66
+ * the user before calling.
67
+ */
68
+ export declare function useRevokeAgentTokens(agentId: string | undefined): import("@tanstack/react-query").UseMutationResult<{
69
+ tokens_valid_from: number;
70
+ }, Error, void, unknown>;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agentTokenStateQueryKey = agentTokenStateQueryKey;
4
+ exports.useAgentTokenState = useAgentTokenState;
5
+ exports.useSetAgentTokenPolicy = useSetAgentTokenPolicy;
6
+ exports.useSetAgentAuthLock = useSetAgentAuthLock;
7
+ exports.useCreateAdhocToken = useCreateAdhocToken;
8
+ exports.useSetRevocationFloor = useSetRevocationFloor;
9
+ exports.useCreateDeviceToken = useCreateDeviceToken;
10
+ exports.useRevokeAgentTokens = useRevokeAgentTokens;
11
+ const react_query_1 = require("@tanstack/react-query");
12
+ const context_1 = require("./context");
13
+ function agentTokenStateQueryKey(agentId) {
14
+ return ["doover", "agent", agentId ?? null, "tokenState"];
15
+ }
16
+ /**
17
+ * Read an agent's credential state — revocation floor, auth kill-switch, and the
18
+ * token posture resolved across the per-agent override and organisation default.
19
+ *
20
+ * Deliberately short `staleTime`: `auth_locked` can be flipped by doover-data
21
+ * itself (automatic lockout on suspected token reuse), so this value changes
22
+ * without any action from this client. Showing a stale "not locked" on the one
23
+ * screen someone opens *because* their device went offline would be worse than
24
+ * an extra fetch.
25
+ */
26
+ function useAgentTokenState(agentId, options) {
27
+ const client = (0, context_1.useDooverClient)();
28
+ return (0, react_query_1.useQuery)({
29
+ queryKey: agentTokenStateQueryKey(agentId),
30
+ enabled: (options?.enabled ?? true) && Boolean(agentId),
31
+ staleTime: options?.staleTime ?? 15 * 1000,
32
+ queryFn: () => client.agents.getTokenState(agentId),
33
+ });
34
+ }
35
+ /**
36
+ * Write an agent's token-posture override. Full replacement — a null field means
37
+ * "inherit the organisation default".
38
+ *
39
+ * Invalidates the token-state query on success so the inherited-vs-overridden
40
+ * display reflects the write without the caller wiring that up.
41
+ */
42
+ function useSetAgentTokenPolicy(agentId) {
43
+ const client = (0, context_1.useDooverClient)();
44
+ const queryClient = (0, react_query_1.useQueryClient)();
45
+ return (0, react_query_1.useMutation)({
46
+ mutationFn: (policy) => client.agents.setTokenPolicy(agentId, policy),
47
+ onSuccess: () => {
48
+ void queryClient.invalidateQueries({
49
+ queryKey: agentTokenStateQueryKey(agentId),
50
+ });
51
+ },
52
+ });
53
+ }
54
+ /** Set or clear the auth kill-switch. */
55
+ function useSetAgentAuthLock(agentId) {
56
+ const client = (0, context_1.useDooverClient)();
57
+ const queryClient = (0, react_query_1.useQueryClient)();
58
+ return (0, react_query_1.useMutation)({
59
+ mutationFn: (locked) => client.agents.setAuthLock(agentId, locked),
60
+ onSuccess: () => {
61
+ void queryClient.invalidateQueries({
62
+ queryKey: agentTokenStateQueryKey(agentId),
63
+ });
64
+ },
65
+ });
66
+ }
67
+ /**
68
+ * Mint a short-lived scoped token for ad-hoc access to an agent.
69
+ *
70
+ * Does not invalidate the token-state query: an ad-hoc token is a JWT with its
71
+ * own expiry and doesn't touch the revocation floor or the agent's posture, so
72
+ * there is nothing in that query for it to change.
73
+ *
74
+ * The resulting token is returned once and is not retrievable afterwards — hand
75
+ * it straight to the user and don't cache it.
76
+ */
77
+ function useCreateAdhocToken(agentId) {
78
+ const client = (0, context_1.useDooverClient)();
79
+ return (0, react_query_1.useMutation)({
80
+ mutationFn: (options) => client.agents.createAdhocToken(agentId, options),
81
+ });
82
+ }
83
+ /**
84
+ * Set the revocation floor to an explicit point; pass `0` or `null` to clear it.
85
+ *
86
+ * Lowering it reverses a revocation, so this is for undoing one made by mistake
87
+ * rather than for recovering a device whose credentials leaked.
88
+ */
89
+ function useSetRevocationFloor(agentId) {
90
+ const client = (0, context_1.useDooverClient)();
91
+ const queryClient = (0, react_query_1.useQueryClient)();
92
+ return (0, react_query_1.useMutation)({
93
+ mutationFn: (tokensValidFrom) => client.agents.setRevocationFloor(agentId, tokensValidFrom),
94
+ onSuccess: () => {
95
+ void queryClient.invalidateQueries({
96
+ queryKey: agentTokenStateQueryKey(agentId),
97
+ });
98
+ },
99
+ });
100
+ }
101
+ /**
102
+ * Mint the device's long-lived credential for manual provisioning, returned once.
103
+ *
104
+ * Invalidates the token-state query so the revocation floor display stays honest
105
+ * — the mint itself is additive and doesn't move the floor, but refetching keeps
106
+ * this in step with anything else that has changed since the panel loaded.
107
+ */
108
+ function useCreateDeviceToken(agentId) {
109
+ const client = (0, context_1.useDooverClient)();
110
+ const queryClient = (0, react_query_1.useQueryClient)();
111
+ return (0, react_query_1.useMutation)({
112
+ mutationFn: () => client.agents.createDeviceToken(agentId),
113
+ onSuccess: () => {
114
+ void queryClient.invalidateQueries({
115
+ queryKey: agentTokenStateQueryKey(agentId),
116
+ });
117
+ },
118
+ });
119
+ }
120
+ /**
121
+ * Revoke every outstanding long-lived credential for an agent.
122
+ *
123
+ * Break-glass: the device stays offline until it is re-provisioned. Confirm with
124
+ * the user before calling.
125
+ */
126
+ function useRevokeAgentTokens(agentId) {
127
+ const client = (0, context_1.useDooverClient)();
128
+ const queryClient = (0, react_query_1.useQueryClient)();
129
+ return (0, react_query_1.useMutation)({
130
+ mutationFn: () => client.agents.revokeAllTokens(agentId),
131
+ onSuccess: () => {
132
+ void queryClient.invalidateQueries({
133
+ queryKey: agentTokenStateQueryKey(agentId),
134
+ });
135
+ },
136
+ });
137
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doover-js",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "TypeScript client for Doover.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",