@bueno-analytics/fleet-command 0.1.0 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0
2
+
3
+ ### 🚀 Features
4
+
5
+ - **fleet-command:** add an error field to the envelope
6
+
1
7
  ## 0.1.0
2
8
 
3
9
  ### 🚀 Features
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # fleet-command
2
2
 
3
- Zod schemas and types for the MQTT command contract between the Bueno fleet
4
- service and the edge gateways.
3
+ Zod schemas and types for the Bueno fleet command message contract.
5
4
 
6
5
  ---
7
6
 
@@ -18,34 +17,3 @@ yarn add @bueno-analytics/fleet-command
18
17
 
19
18
  npm install @bueno-analytics/fleet-command
20
19
  ```
21
-
22
- ## Usage
23
-
24
- Every message on the wire — request, reply or notification — is a
25
- `fleetMessage` envelope. Parse the envelope first, then parse `payload` with
26
- the schema the command names.
27
-
28
- `replyTo` is not a topic: it carries the bare per-pod routing token that the
29
- gateway appends to `v1/gateway/{id}/reply/` when publishing its reply.
30
-
31
- ```ts
32
- import { fleetCommands, fleetMessage } from '@bueno-analytics/fleet-command'
33
-
34
- const message = fleetMessage.parse(JSON.parse(raw))
35
-
36
- if (message.type === 'REQUEST' && message.command === 'list-plugins') {
37
- const request = fleetCommands['list-plugins'].request.parse(message.payload)
38
- }
39
- ```
40
-
41
- `fleetCommands` maps a command name to its `request` and `reply` schema, so a
42
- handler can look the pair up by the `command` field rather than branching on it.
43
-
44
- ## Commands
45
-
46
- | Command | Request | Reply |
47
- | -------------- | ------- | -------------------------------------- |
48
- | `list-plugins` | `{}` | `{ plugins: { id, name, version }[] }` |
49
-
50
- The envelope is shared with the fleet service's Kotlin `FleetMessage`; the two
51
- definitions must be kept in step.
@@ -1,4 +1,10 @@
1
1
  import { z } from 'zod';
2
+ export declare const fleetError: z.ZodObject<{
3
+ code: z.ZodString;
4
+ message: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type FleetError = z.infer<typeof fleetError>;
7
+ export type FleetErrorCode = 'UNKNOWN_COMMAND' | 'INVALID_REQUEST' | 'HANDLER_FAILED';
2
8
  export declare const fleetMessage: z.ZodObject<{
3
9
  messageId: z.ZodString;
4
10
  type: z.ZodEnum<{
@@ -10,6 +16,10 @@ export declare const fleetMessage: z.ZodObject<{
10
16
  replyTo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
11
17
  command: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
18
  payload: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
19
+ error: z.ZodOptional<z.ZodNullable<z.ZodObject<{
20
+ code: z.ZodString;
21
+ message: z.ZodString;
22
+ }, z.core.$strip>>>;
13
23
  ts: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
14
24
  }, z.core.$strip>;
15
25
  export type FleetMessage = z.infer<typeof fleetMessage>;
@@ -1,4 +1,9 @@
1
1
  import { z } from 'zod';
2
+ export const fleetError = z.object({
3
+ // Open string, not an enum: a gateway can ship a new code before its readers upgrade.
4
+ code: z.string(),
5
+ message: z.string(),
6
+ });
2
7
  // Envelope shared with forge-fleet's Kotlin `FleetMessage`; keep the two in step.
3
8
  export const fleetMessage = z.object({
4
9
  messageId: z.string(),
@@ -8,6 +13,7 @@ export const fleetMessage = z.object({
8
13
  replyTo: z.string().nullish(),
9
14
  command: z.string().nullish(),
10
15
  payload: z.unknown().nullish(),
16
+ error: fleetError.nullish(),
11
17
  // Null on offline: the LWT is frozen at connect and can't self-timestamp.
12
18
  ts: z.iso.datetime({ offset: true }).nullish(),
13
19
  });
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { type FleetCommandName, fleetCommands } from './fleetCommands.js';
2
- export { type FleetMessage, fleetMessage, type MessageType, } from './fleetMessage.js';
2
+ export { type FleetError, fleetError, type FleetErrorCode, type FleetMessage, fleetMessage, type MessageType, } from './fleetMessage.js';
3
3
  export { type ListPluginsReply, listPluginsReply, type ListPluginsRequest, listPluginsRequest, } from './listPlugins.js';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { fleetCommands } from './fleetCommands.js';
2
- export { fleetMessage, } from './fleetMessage.js';
2
+ export { fleetError, fleetMessage, } from './fleetMessage.js';
3
3
  export { listPluginsReply, listPluginsRequest, } from './listPlugins.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bueno-analytics/fleet-command",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Zod schemas and types for the Bueno fleet command message contract",
5
5
  "keywords": [],
6
6
  "license": "UNLICENSED",