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
@@ -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
+ }
@@ -20,12 +20,17 @@ export interface Agent {
20
20
  };
21
21
  extra_config: Record<string, unknown>;
22
22
  connection_determination?: "Online" | "Offline";
23
+ /** Server-evaluated warning indicator from `/agents`; `null` when unknown. */
24
+ has_warning?: boolean | null;
23
25
  __source?: SourceProvenance;
24
26
  }
25
27
  export interface User {
26
28
  id: string;
27
29
  email?: string;
28
30
  name?: string;
31
+ mfa_enabled?: boolean;
32
+ /** True when the current organisation requires MFA this user hasn't set up. */
33
+ mfa_required?: boolean;
29
34
  __source?: SourceProvenance;
30
35
  [key: string]: unknown;
31
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doover-js",
3
- "version": "0.14.1",
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",