@deveye/types 0.20.2 → 0.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveye/types",
3
- "version": "0.20.2",
3
+ "version": "0.20.3",
4
4
  "description": "Shared contracts (types + zod schemas) for DevEye apps",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -3,23 +3,18 @@ import { deviceReportSchema, processCaptureSchema } from './report';
3
3
 
4
4
  /**
5
5
  * Lifecycle of a monitored machine (the Rust agent):
6
- * - `pending`: enrolled via a link code but not yet confirmed in the UI.
7
- * - `active`: confirmed; allowed to push metrics.
8
- * - `revoked`: access withdrawn; the agent is rejected (can be reactivated).
6
+ * - `pending`: a machine the workspace already knew, linked again. Its
7
+ * agent is refused at the socket until someone approves it.
8
+ * - `active`: in service. A first link lands here directly.
9
9
  * - `pending_deletion`: deletion requested; on its next connection the agent is
10
10
  * told to self-destruct, then the device is archived. Can
11
11
  * be cancelled until the agent reconnects.
12
- * - `archived`: agent destroyed/removed; the device no longer exists for
13
- * management, but its monitoring history is kept frozen and
14
- * remains browsable (read-only) until explicitly purged.
12
+ * - `archived`: access revoked or agent removed. The token is wiped, the
13
+ * monitoring history stays browsable (read-only) until
14
+ * purged, and linking the machine again brings it back as
15
+ * `pending`.
15
16
  */
16
- export const deviceStatusSchema = z.enum([
17
- 'pending',
18
- 'active',
19
- 'revoked',
20
- 'pending_deletion',
21
- 'archived'
22
- ]);
17
+ export const deviceStatusSchema = z.enum(['pending', 'active', 'pending_deletion', 'archived']);
23
18
  export type DeviceStatus = z.infer<typeof deviceStatusSchema>;
24
19
 
25
20
  export const devicePlatformSchema = z.enum(['linux', 'macos', 'windows']);
@@ -5,29 +5,24 @@ import { devicePlatformSchema, deviceSchema } from '../domain/device';
5
5
  * Device linking & enrollment (HTTP, distinct from the user feature protocol).
6
6
  *
7
7
  * Flow:
8
- * 1. A logged-in user requests a short-lived link code (web UI).
9
- * 2. The agent posts the code + machine fingerprint + public key to enroll.
10
- * 3. The server creates a `pending` device and returns a device token (JWT).
11
- * 4. The user confirms the device in the Clients page to activate it.
8
+ * 1. A member holding `devices: write` issues a short-lived link code for the
9
+ * active workspace.
10
+ * 2. The agent posts the code and its machine fingerprint to enroll.
11
+ * 3. A fingerprint new to the workspace is enrolled `active`, once the plan
12
+ * allows one more device (checked before the code is consumed). A known
13
+ * fingerprint takes over that device record: a fresh token replaces the
14
+ * old one and the device waits, `pending`, for someone to approve it.
12
15
  */
13
16
 
14
- /**
15
- * Hard cap on a code lifetime (30 days). A link code is a standing key to the
16
- * workspace: it always expires.
17
- */
18
- export const LINK_CODE_TTL_MAX_SECONDS = 30 * 24 * 60 * 60;
17
+ /** Hard cap on a code lifetime (one hour). A link code is a key to the workspace. */
18
+ export const LINK_CODE_TTL_MAX_SECONDS = 60 * 60;
19
19
 
20
20
  /**
21
21
  * Request a new link code. `ttlSeconds` omitted → server default lifetime,
22
22
  * otherwise a lifetime in seconds.
23
23
  */
24
24
  export const linkCodeRequestSchema = z.object({
25
- ttlSeconds: z.number().int().positive().max(LINK_CODE_TTL_MAX_SECONDS).optional(),
26
- /**
27
- * Approve the device the moment it enrols with this code, instead of
28
- * leaving it `pending` for manual approval. Defaults to `false`.
29
- */
30
- autoApprove: z.boolean().default(false)
25
+ ttlSeconds: z.number().int().positive().max(LINK_CODE_TTL_MAX_SECONDS).optional()
31
26
  });
32
27
 
33
28
  export type LinkCodeRequest = z.infer<typeof linkCodeRequestSchema>;
@@ -35,22 +30,13 @@ export type LinkCodeRequest = z.infer<typeof linkCodeRequestSchema>;
35
30
  export const linkCodeResponseSchema = z.object({
36
31
  /** Short human-typable code (e.g. shown in the UI, entered on the agent). */
37
32
  code: z.string().min(6).max(32),
38
- /** Unix seconds when the code expires; `null` means it never expires. */
39
- expiresAt: z.number().int().positive().nullable(),
40
- /** Whether a device enrolling with this code is approved automatically. */
41
- autoApprove: z.boolean()
33
+ /** Unix seconds when the code expires. */
34
+ expiresAt: z.number().int().positive()
42
35
  });
43
36
 
44
37
  export type LinkCodeResponse = z.infer<typeof linkCodeResponseSchema>;
45
38
 
46
- /** Toggle the auto-approval of an existing (still-active) link code. */
47
- export const linkCodeUpdateSchema = z.object({
48
- autoApprove: z.boolean()
49
- });
50
-
51
- export type LinkCodeUpdate = z.infer<typeof linkCodeUpdateSchema>;
52
-
53
- /** Currently-active (unconsumed, unexpired) link codes for the caller. */
39
+ /** The workspace's link codes still usable (unconsumed, unexpired). */
54
40
  export const linkCodesListResponseSchema = z.object({
55
41
  codes: z.array(linkCodeResponseSchema)
56
42
  });
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export type { ProtocolVersion } from './protocol/version';
9
9
  export {
10
10
  AGENT_ACK,
11
11
  AGENT_AUTH_EVENTS,
12
+ AGENT_CLOSE_PENDING_APPROVAL,
12
13
  AGENT_COLLECT,
13
14
  AGENT_CONFIG,
14
15
  AGENT_DESTROY,
@@ -1015,8 +1016,7 @@ export {
1015
1016
  LINK_CODE_TTL_MAX_SECONDS,
1016
1017
  linkCodeRequestSchema,
1017
1018
  linkCodeResponseSchema,
1018
- linkCodesListResponseSchema,
1019
- linkCodeUpdateSchema
1019
+ linkCodesListResponseSchema
1020
1020
  } from './http/device';
1021
1021
  export type {
1022
1022
  AgentManifest,
@@ -1030,8 +1030,7 @@ export type {
1030
1030
  EnrollDeviceResponse,
1031
1031
  LinkCodeRequest,
1032
1032
  LinkCodeResponse,
1033
- LinkCodesListResponse,
1034
- LinkCodeUpdate
1033
+ LinkCodesListResponse
1035
1034
  } from './http/device';
1036
1035
  export {
1037
1036
  BUILD_MANIFEST_PATH,
@@ -640,6 +640,14 @@ export const AGENT_CONFIG = 'agent.config' as const;
640
640
  export const AGENT_TOKEN_ROTATE = 'agent.tokenRotate' as const;
641
641
  export const agentTokenRotatePayloadSchema = z.object({ token: z.string().min(1).max(4096) });
642
642
  export type AgentTokenRotatePayload = z.infer<typeof agentTokenRotatePayloadSchema>;
643
+ /**
644
+ * WebSocket close code for an authenticated agent whose device waits for
645
+ * approval: it retries on a short fixed delay instead of backing off like a
646
+ * refused one. Every refusal (unknown, invalid or archived) stays `1008`, so
647
+ * only a holder of a valid token learns the device is pending. Mirrored by
648
+ * `CLOSE_PENDING_APPROVAL` in the agent's `runner.rs`.
649
+ */
650
+ export const AGENT_CLOSE_PENDING_APPROVAL = 4001;
643
651
  /** Tell the agent to self-destruct (wipe its local config + binary) and exit. */
644
652
  export const AGENT_DESTROY = 'agent.destroy' as const;
645
653
  /** Tell the agent to download, verify and swap in a newer signed binary. */
package/src/sdk/server.ts CHANGED
@@ -419,16 +419,13 @@ export interface SdkWorkspaceSummary {
419
419
  export interface AgentsFacade {
420
420
  isOnline(deviceId: string): boolean;
421
421
  /**
422
- * The three orders a device's lifecycle gives the hub. `requestDestroy`
422
+ * The two orders a device's lifecycle gives the hub. `requestDestroy`
423
423
  * asks the agent to uninstall itself (deletion path); `disconnectAgent`
424
- * closes its socket now (a revoked or force-deleted device);
425
- * `resetAgentSession` drops what the hub remembered of it (a device
426
- * confirmed or reactivated starts clean). All three answer `false` when
427
- * the agent is not connected, which is not an error.
424
+ * closes its socket now (a revoked or force-deleted device). Both answer
425
+ * `false` when the agent is not connected, which is not an error.
428
426
  */
429
427
  requestDestroy(deviceId: string): boolean;
430
428
  disconnectAgent(deviceId: string): boolean;
431
- resetAgentSession(deviceId: string): boolean;
432
429
  /**
433
430
  * The manifest of the agent binaries the app serves (the build version and,
434
431
  * per target, whether the binary is signed), or null while nothing is
@@ -627,7 +624,7 @@ export interface SdkDevice {
627
624
  id: string;
628
625
  name: string;
629
626
  online: boolean;
630
- /** `active` is the only status whose telemetry the app records. */
627
+ /** `active` is the only status whose agent the socket admits. */
631
628
  status: string;
632
629
  /** The account that enrolled the device (the actor of its audit lines). */
633
630
  ownerUserId: number;
@@ -283,7 +283,6 @@ function recordingAgents(recorded: RecordedCalls, docker: TestAgents = {}): DevE
283
283
  publishSyncState: () => undefined,
284
284
  requestDestroy: req('requestDestroy'),
285
285
  disconnectAgent: req('disconnectAgent'),
286
- resetAgentSession: req('resetAgentSession'),
287
286
  // Nothing synced: a test of the self-update flag feeds a manifest to
288
287
  // the module's own pure helper.
289
288
  servedManifest: () => Promise.resolve(null),