@7k-inari/api-client 0.3.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.
@@ -0,0 +1,89 @@
1
+ import { ConnectRequest, Event, EventType } from "./proto/inari/agent/v1/agent_pb";
2
+ import {
3
+ CapabilityAction,
4
+ CapabilityKind,
5
+ CapabilityUpdate,
6
+ ManagementMode,
7
+ Ping,
8
+ ResyncResponse,
9
+ StatusUpdate,
10
+ } from "./proto/inari/agent/v1/events_pb";
11
+ import {
12
+ ApplyBundle,
13
+ CommandAck,
14
+ CommandResult,
15
+ CommitPolicy,
16
+ InvokeAction,
17
+ RegisterArgoCDApp,
18
+ RenderRgdInstance,
19
+ } from "./proto/inari/agent/v1/commands_pb";
20
+ import {
21
+ RegisterClusterRequest,
22
+ RegisterClusterResponse,
23
+ } from "./proto/inari/agent/v1/registration_pb";
24
+ import { RegistrationService } from "./proto/inari/agent/v1/registration_connect";
25
+ import { EventStreamService } from "./proto/inari/agent/v1/agent_connect";
26
+ import { getHealth } from "./rest/client";
27
+
28
+ const event = new Event({
29
+ eventId: "evt-1",
30
+ resourceId: "res-1",
31
+ type: "inari.agent.heartbeat.v1",
32
+ sequence: 7n,
33
+ });
34
+ const bytes = event.toBinary();
35
+ const decoded = Event.fromBinary(bytes);
36
+ if (decoded.eventId !== "evt-1") throw new Error("round trip failed");
37
+ if (decoded.sequence !== 7n) throw new Error("sequence round trip failed");
38
+
39
+ const req = new ConnectRequest({ event });
40
+ if (req.event?.type !== event.type) throw new Error("wrapper failed");
41
+
42
+ const cap = new CapabilityUpdate({
43
+ fullSync: true,
44
+ stateChecksum: "sha256:abc",
45
+ capabilities: [
46
+ {
47
+ kind: CapabilityKind.CRD,
48
+ name: "widgets.example.com",
49
+ managementMode: ManagementMode.OBSERVE_ONLY,
50
+ action: CapabilityAction.UPSERT,
51
+ },
52
+ ],
53
+ });
54
+ if (cap.capabilities[0]?.kind !== CapabilityKind.CRD) throw new Error("capability failed");
55
+
56
+ const status = new StatusUpdate({ message: "ok" });
57
+ if (status.message !== "ok") throw new Error("status failed");
58
+
59
+ const ping = new Ping({ sequence: 1n });
60
+ if (ping.sequence !== 1n) throw new Error("ping failed");
61
+
62
+ const resync = new ResyncResponse({ appliedThroughSequence: 42n });
63
+ if (resync.appliedThroughSequence !== 42n) throw new Error("resync failed");
64
+
65
+ const bundle = new ApplyBundle({
66
+ commandId: "cmd-1",
67
+ source: { case: "ociRef", value: "oci://registry/bundle:v1" },
68
+ policy: CommitPolicy.PULL_REQUEST,
69
+ });
70
+ if (bundle.source.case !== "ociRef") throw new Error("apply-bundle failed");
71
+
72
+ const app = new RegisterArgoCDApp({ commandId: "cmd-2", name: "web" });
73
+ const action = new InvokeAction({ commandId: "cmd-3", action: "restart" });
74
+ const rgd = new RenderRgdInstance({ commandId: "cmd-4", rgdRef: "oci://registry/rgd:v1" });
75
+ const ack = new CommandAck({ commandId: "cmd-1", result: CommandResult.APPLIED });
76
+ void [app, action, rgd, ack];
77
+
78
+ const regReq = new RegisterClusterRequest({ registrationToken: "tok-1" });
79
+ const regResp = new RegisterClusterResponse({ clientId: "cluster-1" });
80
+ if (regReq.registrationToken !== "tok-1" || regResp.clientId !== "cluster-1") {
81
+ throw new Error("registration failed");
82
+ }
83
+
84
+ if (EventType.CAPABILITY_UPDATE !== 1) throw new Error("enum failed");
85
+
86
+ void RegistrationService;
87
+ void EventStreamService;
88
+ void getHealth;
89
+ console.log("smoke ok");
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@7k-inari/api-client",
3
+ "version": "0.3.0",
4
+ "description": "Generated TypeScript client for the Inari control plane contract (inari-api).",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./gen/ts/rest/client.ts",
8
+ "types": "./gen/ts/rest/client.ts",
9
+ "files": [
10
+ "gen/ts"
11
+ ],
12
+ "scripts": {
13
+ "generate:rest": "orval --config orval.config.ts",
14
+ "typecheck": "tsc --noEmit"
15
+ },
16
+ "dependencies": {
17
+ "@bufbuild/protobuf": "^1.10.0",
18
+ "@connectrpc/connect": "^1.6.1"
19
+ },
20
+ "devDependencies": {
21
+ "@redocly/cli": "^1.25.0",
22
+ "orval": "^7.5.0",
23
+ "typescript": "^5.6.0"
24
+ }
25
+ }