@reeve-iot/workload-client 0.0.0-stage → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +180 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/session/MessageDeduplicator.d.ts +22 -0
- package/dist/session/MessageDeduplicator.d.ts.map +1 -0
- package/dist/session/MessageDeduplicator.js +49 -0
- package/dist/session/MessageDeduplicator.js.map +1 -0
- package/dist/session/SessionDataKind.d.ts +13 -0
- package/dist/session/SessionDataKind.d.ts.map +1 -0
- package/dist/session/SessionDataKind.js +11 -0
- package/dist/session/SessionDataKind.js.map +1 -0
- package/dist/session/SessionEnvelope.d.ts +40 -0
- package/dist/session/SessionEnvelope.d.ts.map +1 -0
- package/dist/session/SessionEnvelope.js +9 -0
- package/dist/session/SessionEnvelope.js.map +1 -0
- package/dist/session/SessionProtocol.d.ts +61 -0
- package/dist/session/SessionProtocol.d.ts.map +1 -0
- package/dist/session/SessionProtocol.js +283 -0
- package/dist/session/SessionProtocol.js.map +1 -0
- package/dist/session/WorkloadSessionClient.d.ts +114 -0
- package/dist/session/WorkloadSessionClient.d.ts.map +1 -0
- package/dist/session/WorkloadSessionClient.js +462 -0
- package/dist/session/WorkloadSessionClient.js.map +1 -0
- package/dist/session/backoff.d.ts +32 -0
- package/dist/session/backoff.d.ts.map +1 -0
- package/dist/session/backoff.js +54 -0
- package/dist/session/backoff.js.map +1 -0
- package/dist/session/owner.d.ts +34 -0
- package/dist/session/owner.d.ts.map +1 -0
- package/dist/session/owner.js +2 -0
- package/dist/session/owner.js.map +1 -0
- package/dist/session/rest.d.ts +83 -0
- package/dist/session/rest.d.ts.map +1 -0
- package/dist/session/rest.js +140 -0
- package/dist/session/rest.js.map +1 -0
- package/dist/session/transport.d.ts +51 -0
- package/dist/session/transport.d.ts.map +1 -0
- package/dist/session/transport.js +190 -0
- package/dist/session/transport.js.map +1 -0
- package/dist/session/types.d.ts +114 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +19 -0
- package/dist/session/types.js.map +1 -0
- package/dist/tls/caCertificate.d.ts +5 -0
- package/dist/tls/caCertificate.d.ts.map +1 -0
- package/dist/tls/caCertificate.js +26 -0
- package/dist/tls/caCertificate.js.map +1 -0
- package/dist/tls/trustedCaCertificates.d.ts +4 -0
- package/dist/tls/trustedCaCertificates.d.ts.map +1 -0
- package/dist/tls/trustedCaCertificates.js +16 -0
- package/dist/tls/trustedCaCertificates.js.map +1 -0
- package/package.json +63 -4
- package/src/index.ts +59 -0
- package/src/session/MessageDeduplicator.ts +55 -0
- package/src/session/SessionDataKind.ts +14 -0
- package/src/session/SessionEnvelope.ts +32 -0
- package/src/session/SessionProtocol.ts +351 -0
- package/src/session/WorkloadSessionClient.ts +597 -0
- package/src/session/backoff.ts +68 -0
- package/src/session/owner.ts +39 -0
- package/src/session/rest.ts +228 -0
- package/src/session/transport.ts +224 -0
- package/src/session/types.ts +130 -0
- package/src/tls/caCertificate.ts +29 -0
- package/src/tls/trustedCaCertificates.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 grzonu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,181 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reeve-iot/workload-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Session client for the Reeve workload gateway, for writing Node.js sidecars (device adapters) that connect to a
|
|
4
|
+
Reeve instance the way the built-in .NET adapters do.
|
|
5
|
+
|
|
6
|
+
It is a TypeScript port of the .NET `Reeve.Adapters.Protocol` `WorkloadSessionClient`. The client owns the session
|
|
7
|
+
lifecycle, so a sidecar only implements a small owner interface and publishes data:
|
|
8
|
+
|
|
9
|
+
- connects a WebSocket transport to `wss://…/ws/workloads/{instanceId}` with the credential in the
|
|
10
|
+
`Authorization: Bearer <rwt_…>` header (never the query string);
|
|
11
|
+
- sends **HELLO** `{ instanceId, appVersion, specHash, protocol:{version,minSupported}, apiSchema? }` and
|
|
12
|
+
awaits **HELLO_ACK** (negotiated `heartbeatSeconds`, `sessionId`);
|
|
13
|
+
- pushes a full-state **SNAPSHOT before any incremental DATA** on every (re)connect (snapshot-on-reconnect —
|
|
14
|
+
reconnection is *resync, not replay*), split over as many SNAPSHOT frames as keep each one within the
|
|
15
|
+
gateway's frame limit (`MAX_FRAME_BYTES`, 1 MiB of UTF-8 JSON; a larger frame closes the session). A single
|
|
16
|
+
device or state entry that cannot fit a frame on its own fails the session with `SnapshotEntryTooLargeError`
|
|
17
|
+
(reported to `onSessionFaulted`) before anything is sent;
|
|
18
|
+
- self-**heartbeats** at the negotiated cadence and answers server heartbeats;
|
|
19
|
+
- **acks + de-dupes** inbound frames (`messageId`, at-least-once), routes **COMMAND → COMMAND_RESPONSE**,
|
|
20
|
+
and reconnects on `reauth`/`close`;
|
|
21
|
+
- **reconnects** with exponential backoff + full jitter (start ~500 ms, cap 30 s), reset by a session that served for
|
|
22
|
+
the cap or ended on a gateway CLOSE frame;
|
|
23
|
+
- has a bounded outbound queue (1024 frames, drop-on-full; a fresh snapshot follows once the backlog drains).
|
|
24
|
+
- bounds inbound transport buffering by pausing socket reads at 64 queued frames / 256 KiB and resuming
|
|
25
|
+
below 16 frames / 64 KiB; it closes only past 1024 frames / 4 MiB, and caps each inbound message at 4 MiB.
|
|
26
|
+
|
|
27
|
+
> **Scope:** the generic workload protocol only: the three generic DATA messages (`state`, `discovered`, `health`),
|
|
28
|
+
> snapshot, command and response, and control frames. Sidecars layer adapter-specific message types on top.
|
|
29
|
+
|
|
30
|
+
The wire format is byte-compatible with the .NET client (the same `/ws/workloads/{instanceId}`
|
|
31
|
+
gateway serves both): camelCase envelope `{ messageId, type, payload?, dataKind? }`, `type` and `dataKind` as
|
|
32
|
+
stable camelCase **strings** (never integer ordinals), `dataKind ∈ {state,discovered,health}` only on DATA
|
|
33
|
+
frames. This is verified by cross-language tests (see [Wire conformance](#wire-conformance)).
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @reeve-iot/workload-client
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The package is published on [npmjs.com](https://www.npmjs.com/package/@reeve-iot/workload-client). It depends on [`ws`](https://github.com/websockets/ws) `^8` and needs Node.js 18 or newer.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
For workloads that receive the host CA list, call `applyTrustedCaCertificates()` first in `main`, before opening any TLS connection. This includes the gateway connection. The call reads `REEVE_TRUSTED_CA_CERTIFICATES`, adds its PEM certificates to Node's default roots, and leaves the defaults in place. An empty or unset variable does nothing. Invalid PEM throws `CaCertificateError`.
|
|
50
|
+
|
|
51
|
+
The call needs both `tls.getCACertificates` (Node v22.15 / v23.10) and `tls.setDefaultCACertificates` (Node v22.19 / v24.5). Node 22.15–22.18 has only the first API and also throws `CaCertificateError` for a non-empty variable. The package still supports Node ≥ 18 for workloads that do not use this optional call.
|
|
52
|
+
|
|
53
|
+
The call applies to the current thread only. Worker threads must call it themselves before opening TLS connections.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { applyTrustedCaCertificates } from '@reeve-iot/workload-client';
|
|
57
|
+
|
|
58
|
+
async function main(): Promise<void> {
|
|
59
|
+
applyTrustedCaCertificates();
|
|
60
|
+
// Create clients and connect only after trust is configured.
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void main();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import {
|
|
68
|
+
WorkloadSessionClient,
|
|
69
|
+
type WorkloadSessionOwner,
|
|
70
|
+
type SnapshotPayload,
|
|
71
|
+
type AdapterCommand,
|
|
72
|
+
type AdapterCommandResponse,
|
|
73
|
+
} from '@reeve-iot/workload-client';
|
|
74
|
+
|
|
75
|
+
// Your sidecar's device model provides the snapshot and handles commands.
|
|
76
|
+
const owner: WorkloadSessionOwner = {
|
|
77
|
+
buildSnapshot(): SnapshotPayload {
|
|
78
|
+
return {
|
|
79
|
+
devices: [{ externalId: 'dev-1', vendor: 'acme', friendlyName: 'Lamp' }],
|
|
80
|
+
states: [{ externalId: 'dev-1', telemetry: { on: true } }],
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
handleCommand(command: AdapterCommand): AdapterCommandResponse {
|
|
84
|
+
// ... actuate the device ...
|
|
85
|
+
return { correlationId: command.correlationId, success: true };
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const client = new WorkloadSessionClient({
|
|
90
|
+
gatewayUrl: process.env.REEVE_GATEWAY_URL!, // wss://…/ws/workloads/{instanceId}
|
|
91
|
+
token: process.env.REEVE_WORKLOAD_TOKEN!, // rwt_…
|
|
92
|
+
instanceId: process.env.REEVE_INSTANCE_ID!, // GUID; must match the URL + token binding
|
|
93
|
+
appVersion: '1.0.0',
|
|
94
|
+
specHash: process.env.REEVE_SPEC_HASH!,
|
|
95
|
+
// The payload dialect the plugin module and this sidecar speak to each other. The backend injects it from
|
|
96
|
+
// `workloads[].extensions.reeve.apiSchema`, so pass it through. It is undefined when the manifest declares
|
|
97
|
+
// none, and then gates nothing. It is not `protocol`, the session envelope spoken to the gateway.
|
|
98
|
+
apiSchema: process.env.REEVE_API_SCHEMA,
|
|
99
|
+
owner,
|
|
100
|
+
observer: {
|
|
101
|
+
onSessionEstablished: () => console.log('session up'),
|
|
102
|
+
onReconnectScheduled: (attempt, delayMs) => console.log(`reconnect #${attempt} in ${delayMs}ms`),
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
client.start();
|
|
107
|
+
|
|
108
|
+
// Publish the three generic DATA messages. Non-blocking; returns false if the outbound queue is full
|
|
109
|
+
// (dropped — a fresh snapshot follows once the backlog drains).
|
|
110
|
+
client.publishState({ externalId: 'dev-1', telemetry: { on: false } });
|
|
111
|
+
client.publishDiscovered({ externalId: 'dev-2', vendor: 'acme' });
|
|
112
|
+
client.publishHealth({
|
|
113
|
+
adapterType: 'my-adapter',
|
|
114
|
+
instanceId: process.env.REEVE_INSTANCE_ID!,
|
|
115
|
+
status: 'Online',
|
|
116
|
+
version: '1.0.0',
|
|
117
|
+
capabilities: ['switch'],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Every publish method throws when its payload cannot be serialized.
|
|
121
|
+
// A kind private to your plugin. Best-effort: no snapshot carries it, so re-publish a kind that holds current
|
|
122
|
+
// state from observer.onSnapshotSent, which runs after every connect and every repair snapshot.
|
|
123
|
+
client.publishData({ status: 'online' }, 'my-adapter.radio-health');
|
|
124
|
+
|
|
125
|
+
// On shutdown:
|
|
126
|
+
await client.stop();
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Public API
|
|
130
|
+
|
|
131
|
+
| Export | Purpose |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| `WorkloadSessionClient` | The session client. `start()`, `stop()`, `publishState/Discovered/Health()`, `publishData(payload, dataKind)`, `runAsync(signal)`. |
|
|
134
|
+
| `WorkloadSessionClientOptions` | Constructor options (gateway URL, token, instance, versions, owner, tuning + injectable seams). |
|
|
135
|
+
| `WorkloadSessionOwner` | Your sidecar implements `buildSnapshot()` + `handleCommand()`. |
|
|
136
|
+
| `WorkloadSessionObserver` | Optional lifecycle callbacks (established / snapshot / reconnect / reauth / close). |
|
|
137
|
+
| `WorkloadClientTransport`, `WorkloadClientTransportFactory` | Transport seam (inject a mock for tests). |
|
|
138
|
+
| `WsWorkloadClientTransport`, `WsWorkloadClientTransportFactory` | Production `ws` transport (bearer header; re-reads the token per connect for reauth). |
|
|
139
|
+
| `SessionProtocol` | Frame construction + (de)serialization + safe parsing (never throws). |
|
|
140
|
+
| `SessionEnvelope`, `SessionFrameType`, `SessionDataKind`, `SessionParseError` | Wire types. |
|
|
141
|
+
| `ReconnectBackoff`, `MessageDeduplicator` | Backoff (full jitter) + at-least-once de-dup primitives. |
|
|
142
|
+
| `applyTrustedCaCertificates` | Add trusted CA certificates to Node's default roots. |
|
|
143
|
+
| Payload models | `HelloFrame`, `HelloAckFrame`, `DeviceStateMessage`, `DiscoveredDeviceMessage`, `AdapterHealthMessage`, `AdapterCommand`, `AdapterCommandResponse`, `SnapshotPayload`, … |
|
|
144
|
+
|
|
145
|
+
### Testability
|
|
146
|
+
|
|
147
|
+
Transport, inter-attempt delay, heartbeat delay, and the backoff jitter sample are all injectable
|
|
148
|
+
(`transportFactory`, `delay`, `heartbeatDelay`, `backoffSample`), so the whole client can be unit-tested against an
|
|
149
|
+
in-memory mock gateway with no real socket and no real sleeps. See `tests/` for the pattern.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Wire conformance
|
|
154
|
+
|
|
155
|
+
The client's wire bytes are checked against the .NET serializer:
|
|
156
|
+
|
|
157
|
+
- `npm run test:conformance` runs a small .NET harness (`tools/dotnet-wire-conformance`) that serializes each generic
|
|
158
|
+
frame with the `Reeve.Adapters.Protocol.SessionProtocol.Serialize` the gateway uses, and asserts the TypeScript
|
|
159
|
+
output matches field for field (ignoring only the random `messageId`).
|
|
160
|
+
- The same harness can start the `Reeve.Adapters.Protocol.MockGateway` (Kestrel), and the client then connects over a
|
|
161
|
+
real WebSocket: HELLO, HELLO_ACK, snapshot, DATA, ack.
|
|
162
|
+
|
|
163
|
+
Both need a `dotnet` SDK and the repository's .NET protocol project, and skip themselves otherwise. `npm test` runs
|
|
164
|
+
only the fast in-memory unit suite.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Scripts
|
|
169
|
+
|
|
170
|
+
| Script | What it does |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `npm run build` | `tsc` → `dist/` (ESM + `.d.ts`). |
|
|
173
|
+
| `npm test` | Fast in-memory unit suite (protocol, backoff, de-dup, client). |
|
|
174
|
+
| `npm run test:conformance` | Cross-language wire-compat + live-socket e2e vs the real .NET gateway (needs `dotnet`). |
|
|
175
|
+
| `npm run test:all` | Everything (`RUN_DOTNET_CONFORMANCE=1`). |
|
|
176
|
+
| `npm run lint` | Type-check the whole package (`tsc --noEmit`). |
|
|
177
|
+
| `npm pack` | Produce the package tarball (`dist`, `src`, `README`, `LICENSE`). |
|
|
178
|
+
|
|
179
|
+
## Licence
|
|
180
|
+
|
|
181
|
+
MIT.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { WorkloadSessionClient, PROTOCOL_VERSION, type WorkloadSessionClientOptions, } from './session/WorkloadSessionClient.js';
|
|
2
|
+
export type { WorkloadSessionOwner, WorkloadSessionObserver } from './session/owner.js';
|
|
3
|
+
export { type WorkloadClientTransport, type WorkloadClientTransportFactory, WsWorkloadClientTransport, WsWorkloadClientTransportFactory, } from './session/transport.js';
|
|
4
|
+
export { ReconnectBackoff, type ReconnectBackoffOptions } from './session/backoff.js';
|
|
5
|
+
export { MessageDeduplicator } from './session/MessageDeduplicator.js';
|
|
6
|
+
export { WorkloadRestClient, WorkloadRestEnvVars, WorkloadRestError, WorkloadNotConsentedError, WorkloadUnauthorizedError, type WorkloadSelfConfig, type WorkloadRestClientOptions, type FetchLike, type FetchLikeResponse, } from './session/rest.js';
|
|
7
|
+
export { SessionProtocol, MAX_FRAME_BYTES, SnapshotEntryTooLargeError } from './session/SessionProtocol.js';
|
|
8
|
+
export { type SessionEnvelope, type SessionParseResult, type PayloadReadResult, SessionParseError, } from './session/SessionEnvelope.js';
|
|
9
|
+
export { SessionDataKind, SESSION_DATA_KINDS } from './session/SessionDataKind.js';
|
|
10
|
+
export { SessionFrameType, SESSION_FRAME_TYPES, type ProtocolRange, type HelloFrame, type HelloAckFrame, type ReauthFrame, type AckFrame, type CloseFrame, type ErrorFrame, type AdapterStatus, type AdapterHealthMessage, type DiscoveredDeviceMessage, type DeviceStateMessage, type AdapterCommand, type AdapterCommandResponse, type SnapshotPayload, } from './session/types.js';
|
|
11
|
+
export { applyTrustedCaCertificates, CaCertificateError } from './tls/trustedCaCertificates.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,4BAA4B,GAClC,MAAM,oCAAoC,CAAC;AAE5C,YAAY,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAExF,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EACzB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,SAAS,EACd,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC5G,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAEnF,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { WorkloadSessionClient, PROTOCOL_VERSION, } from './session/WorkloadSessionClient.js';
|
|
2
|
+
export { WsWorkloadClientTransport, WsWorkloadClientTransportFactory, } from './session/transport.js';
|
|
3
|
+
export { ReconnectBackoff } from './session/backoff.js';
|
|
4
|
+
export { MessageDeduplicator } from './session/MessageDeduplicator.js';
|
|
5
|
+
export { WorkloadRestClient, WorkloadRestEnvVars, WorkloadRestError, WorkloadNotConsentedError, WorkloadUnauthorizedError, } from './session/rest.js';
|
|
6
|
+
export { SessionProtocol, MAX_FRAME_BYTES, SnapshotEntryTooLargeError } from './session/SessionProtocol.js';
|
|
7
|
+
export { SessionParseError, } from './session/SessionEnvelope.js';
|
|
8
|
+
export { SessionDataKind, SESSION_DATA_KINDS } from './session/SessionDataKind.js';
|
|
9
|
+
export { SessionFrameType, SESSION_FRAME_TYPES, } from './session/types.js';
|
|
10
|
+
export { applyTrustedCaCertificates, CaCertificateError } from './tls/trustedCaCertificates.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,oCAAoC,CAAC;AAI5C,OAAO,EAGL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAgC,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,GAK1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC5G,OAAO,EAIL,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAEnF,OAAO,EACL,gBAAgB,EAChB,mBAAmB,GAepB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** A bounded de-dup window over frame `messageId`s, reflecting the session's AT-LEAST-ONCE delivery contract.
|
|
2
|
+
* FIFO eviction keeps a long session from leaking; best-effort per-connection, not a durable exactly-once store. */
|
|
3
|
+
export declare class MessageDeduplicator {
|
|
4
|
+
/** Default number of recent message ids to remember. */
|
|
5
|
+
static readonly DEFAULT_CAPACITY = 4096;
|
|
6
|
+
private readonly cap;
|
|
7
|
+
private readonly seen;
|
|
8
|
+
private readonly order;
|
|
9
|
+
constructor(capacity?: number);
|
|
10
|
+
/** The bounded number of recent ids retained. */
|
|
11
|
+
get capacity(): number;
|
|
12
|
+
/** The number of ids currently tracked. */
|
|
13
|
+
get count(): number;
|
|
14
|
+
/** Records `messageId` as seen: `true` on first sighting (process the frame), `false` for a duplicate within
|
|
15
|
+
* the current window (drop it). Adding past capacity evicts the oldest. */
|
|
16
|
+
trySee(messageId: string): boolean;
|
|
17
|
+
/** Whether `messageId` is currently in the window, WITHOUT recording it. */
|
|
18
|
+
hasSeen(messageId: string): boolean;
|
|
19
|
+
/** Clears the window. */
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=MessageDeduplicator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageDeduplicator.d.ts","sourceRoot":"","sources":["../../src/session/MessageDeduplicator.ts"],"names":[],"mappings":"AAAA;oHACoH;AACpH,qBAAa,mBAAmB;IAC9B,wDAAwD;IACxD,MAAM,CAAC,QAAQ,CAAC,gBAAgB,QAAQ;IAExC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IAEtC,YAAY,QAAQ,GAAE,MAA6C,EAKlE;IAED,iDAAiD;IACjD,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,2CAA2C;IAC3C,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;+EAC2E;IAC3E,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAajC;IAED,4EAA4E;IAC5E,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAElC;IAED,yBAAyB;IACzB,KAAK,IAAI,IAAI,CAGZ;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** A bounded de-dup window over frame `messageId`s, reflecting the session's AT-LEAST-ONCE delivery contract.
|
|
2
|
+
* FIFO eviction keeps a long session from leaking; best-effort per-connection, not a durable exactly-once store. */
|
|
3
|
+
export class MessageDeduplicator {
|
|
4
|
+
/** Default number of recent message ids to remember. */
|
|
5
|
+
static DEFAULT_CAPACITY = 4096;
|
|
6
|
+
cap;
|
|
7
|
+
seen = new Set();
|
|
8
|
+
order = [];
|
|
9
|
+
constructor(capacity = MessageDeduplicator.DEFAULT_CAPACITY) {
|
|
10
|
+
if (!Number.isInteger(capacity) || capacity <= 0) {
|
|
11
|
+
throw new RangeError(`Capacity must be a positive integer (got ${capacity}).`);
|
|
12
|
+
}
|
|
13
|
+
this.cap = capacity;
|
|
14
|
+
}
|
|
15
|
+
/** The bounded number of recent ids retained. */
|
|
16
|
+
get capacity() {
|
|
17
|
+
return this.cap;
|
|
18
|
+
}
|
|
19
|
+
/** The number of ids currently tracked. */
|
|
20
|
+
get count() {
|
|
21
|
+
return this.seen.size;
|
|
22
|
+
}
|
|
23
|
+
/** Records `messageId` as seen: `true` on first sighting (process the frame), `false` for a duplicate within
|
|
24
|
+
* the current window (drop it). Adding past capacity evicts the oldest. */
|
|
25
|
+
trySee(messageId) {
|
|
26
|
+
if (this.seen.has(messageId)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
this.seen.add(messageId);
|
|
30
|
+
this.order.push(messageId);
|
|
31
|
+
if (this.order.length > this.cap) {
|
|
32
|
+
const evicted = this.order.shift();
|
|
33
|
+
if (evicted !== undefined) {
|
|
34
|
+
this.seen.delete(evicted);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
/** Whether `messageId` is currently in the window, WITHOUT recording it. */
|
|
40
|
+
hasSeen(messageId) {
|
|
41
|
+
return this.seen.has(messageId);
|
|
42
|
+
}
|
|
43
|
+
/** Clears the window. */
|
|
44
|
+
clear() {
|
|
45
|
+
this.seen.clear();
|
|
46
|
+
this.order.length = 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=MessageDeduplicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageDeduplicator.js","sourceRoot":"","sources":["../../src/session/MessageDeduplicator.ts"],"names":[],"mappings":"AAAA;oHACoH;AACpH,MAAM,OAAO,mBAAmB;IAC9B,wDAAwD;IACxD,MAAM,CAAU,gBAAgB,GAAG,IAAI,CAAC;IAEvB,GAAG,CAAS;IACZ,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IACzB,KAAK,GAAa,EAAE,CAAC;IAEtC,YAAY,QAAQ,GAAW,mBAAmB,CAAC,gBAAgB;QACjE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,UAAU,CAAC,4CAA4C,QAAQ,IAAI,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC;IACtB,CAAC;IAED,iDAAiD;IACjD,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,2CAA2C;IAC3C,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED;+EAC2E;IAC3E,MAAM,CAAC,SAAiB;QACtB,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4EAA4E;IAC5E,OAAO,CAAC,SAAiB;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,yBAAyB;IACzB,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The sub-discriminator for a DATA frame, so the gateway routes deterministically rather than by shape. OPEN by
|
|
2
|
+
* design: `dataKind` is a free camelCase STRING, and downstream kinds never appear here. */
|
|
3
|
+
export declare const SessionDataKind: {
|
|
4
|
+
readonly State: 'state';
|
|
5
|
+
readonly Discovered: 'discovered';
|
|
6
|
+
readonly Health: 'health';
|
|
7
|
+
};
|
|
8
|
+
/** A DATA-frame kind: one of the well-known generic kinds, OR any downstream/Matter string (open). */
|
|
9
|
+
export type SessionDataKind = string;
|
|
10
|
+
/** The set of WELL-KNOWN generic data-kind strings. NOT a closed allowlist for parsing — an unrecognized
|
|
11
|
+
* downstream `dataKind` is retained verbatim, not rejected. */
|
|
12
|
+
export declare const SESSION_DATA_KINDS: ReadonlySet<string>;
|
|
13
|
+
//# sourceMappingURL=SessionDataKind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionDataKind.d.ts","sourceRoot":"","sources":["../../src/session/SessionDataKind.ts"],"names":[],"mappings":"AAAA;4FAC4F;AAC5F,eAAO,MAAM,eAAe;aAC1B,KAAK,EAAE,OAAO;aACd,UAAU,EAAE,YAAY;aACxB,MAAM,EAAE,QAAQ;CACR,CAAC;AAEX,sGAAsG;AACtG,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;+DAC+D;AAC/D,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAA2C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The sub-discriminator for a DATA frame, so the gateway routes deterministically rather than by shape. OPEN by
|
|
2
|
+
* design: `dataKind` is a free camelCase STRING, and downstream kinds never appear here. */
|
|
3
|
+
export const SessionDataKind = {
|
|
4
|
+
State: 'state',
|
|
5
|
+
Discovered: 'discovered',
|
|
6
|
+
Health: 'health',
|
|
7
|
+
};
|
|
8
|
+
/** The set of WELL-KNOWN generic data-kind strings. NOT a closed allowlist for parsing — an unrecognized
|
|
9
|
+
* downstream `dataKind` is retained verbatim, not rejected. */
|
|
10
|
+
export const SESSION_DATA_KINDS = new Set(Object.values(SessionDataKind));
|
|
11
|
+
//# sourceMappingURL=SessionDataKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionDataKind.js","sourceRoot":"","sources":["../../src/session/SessionDataKind.ts"],"names":[],"mappings":"AAAA;4FAC4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,QAAQ;CACR,CAAC;AAKX;+DAC+D;AAC/D,MAAM,CAAC,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SessionDataKind } from './SessionDataKind.js';
|
|
2
|
+
import type { SessionFrameType } from './types.js';
|
|
3
|
+
/** The WS session frame envelope, camelCase, ported from the .NET record. `messageId` is the de-dup key
|
|
4
|
+
* under at-least-once delivery; `dataKind` is present ONLY on DATA frames and stays off the wire otherwise. */
|
|
5
|
+
export interface SessionEnvelope {
|
|
6
|
+
messageId: string;
|
|
7
|
+
type: SessionFrameType;
|
|
8
|
+
payload?: unknown;
|
|
9
|
+
dataKind?: SessionDataKind;
|
|
10
|
+
}
|
|
11
|
+
/** Defined, non-throwing failure reasons for parsing/reading a session frame (mirrors .NET `SessionParseError`). */
|
|
12
|
+
export declare const SessionParseError: {
|
|
13
|
+
readonly None: 'none';
|
|
14
|
+
readonly MalformedJson: 'malformedJson';
|
|
15
|
+
readonly MissingMessageId: 'missingMessageId';
|
|
16
|
+
readonly UnknownFrameType: 'unknownFrameType';
|
|
17
|
+
readonly PayloadTypeMismatch: 'payloadTypeMismatch';
|
|
18
|
+
};
|
|
19
|
+
export type SessionParseError = (typeof SessionParseError)[keyof typeof SessionParseError];
|
|
20
|
+
/** Result of parsing a raw wire string into a {@link SessionEnvelope}. Never throws. */
|
|
21
|
+
export type SessionParseResult = {
|
|
22
|
+
isSuccess: true;
|
|
23
|
+
envelope: SessionEnvelope;
|
|
24
|
+
error: typeof SessionParseError.None;
|
|
25
|
+
} | {
|
|
26
|
+
isSuccess: false;
|
|
27
|
+
envelope: undefined;
|
|
28
|
+
error: Exclude<SessionParseError, typeof SessionParseError.None>;
|
|
29
|
+
};
|
|
30
|
+
/** Result of reading a typed payload out of a {@link SessionEnvelope}. Never throws. */
|
|
31
|
+
export type PayloadReadResult<T> = {
|
|
32
|
+
isSuccess: true;
|
|
33
|
+
payload: T;
|
|
34
|
+
error: typeof SessionParseError.None;
|
|
35
|
+
} | {
|
|
36
|
+
isSuccess: false;
|
|
37
|
+
payload: undefined;
|
|
38
|
+
error: Exclude<SessionParseError, typeof SessionParseError.None>;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=SessionEnvelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionEnvelope.d.ts","sourceRoot":"","sources":["../../src/session/SessionEnvelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;+GAC+G;AAC/G,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,oHAAoH;AACpH,eAAO,MAAM,iBAAiB;aAC5B,IAAI,EAAE,MAAM;aACZ,aAAa,EAAE,eAAe;aAC9B,gBAAgB,EAAE,kBAAkB;aACpC,gBAAgB,EAAE,kBAAkB;aACpC,mBAAmB,EAAE,qBAAqB;CAClC,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE3F,wFAAwF;AACxF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,OAAO,iBAAiB,CAAC,IAAI,CAAA;CAAE,GACpF;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC,iBAAiB,EAAE,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC;AAEhH,wFAAwF;AACxF,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAC3B;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,OAAO,iBAAiB,CAAC,IAAI,CAAA;CAAE,GACrE;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC,iBAAiB,EAAE,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Defined, non-throwing failure reasons for parsing/reading a session frame (mirrors .NET `SessionParseError`). */
|
|
2
|
+
export const SessionParseError = {
|
|
3
|
+
None: 'none',
|
|
4
|
+
MalformedJson: 'malformedJson',
|
|
5
|
+
MissingMessageId: 'missingMessageId',
|
|
6
|
+
UnknownFrameType: 'unknownFrameType',
|
|
7
|
+
PayloadTypeMismatch: 'payloadTypeMismatch',
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=SessionEnvelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionEnvelope.js","sourceRoot":"","sources":["../../src/session/SessionEnvelope.ts"],"names":[],"mappings":"AAYA,oHAAoH;AACpH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,MAAM;IACZ,aAAa,EAAE,eAAe;IAC9B,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,mBAAmB,EAAE,qBAAqB;CAClC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type SessionEnvelope, type PayloadReadResult, type SessionParseResult } from './SessionEnvelope.js';
|
|
2
|
+
import { type HelloFrame, type HelloAckFrame, type ReauthFrame, type AckFrame, type CloseFrame, type ErrorFrame, type SnapshotPayload, type AdapterCommand, type AdapterCommandResponse, type DeviceStateMessage, type DiscoveredDeviceMessage, type AdapterHealthMessage } from './types.js';
|
|
3
|
+
/** The largest frame the workload gateway accepts, in bytes of UTF-8 JSON. A larger frame closes the session. */
|
|
4
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
5
|
+
/** Thrown by {@link SessionProtocol.createSnapshotFrames} when one snapshot entry does not fit a frame on its own. */
|
|
6
|
+
export declare class SnapshotEntryTooLargeError extends Error {
|
|
7
|
+
readonly section: 'devices' | 'states';
|
|
8
|
+
readonly index: number;
|
|
9
|
+
readonly frameBytes: number;
|
|
10
|
+
readonly maxFrameBytes: number;
|
|
11
|
+
constructor(section: 'devices' | 'states', index: number, frameBytes: number, maxFrameBytes: number);
|
|
12
|
+
}
|
|
13
|
+
/** Byte-compatible on the wire with the .NET `SessionProtocol`: camelCase STRING discriminators, never ordinals,
|
|
14
|
+
* and `parse`/`tryRead*` never throw so a socket read-loop survives a hostile or newer peer. */
|
|
15
|
+
export declare const SessionProtocol: {
|
|
16
|
+
createHello(hello: HelloFrame): SessionEnvelope;
|
|
17
|
+
createHelloAck(ack: HelloAckFrame): SessionEnvelope;
|
|
18
|
+
createReauth(reauth: ReauthFrame): SessionEnvelope;
|
|
19
|
+
createClose(close: CloseFrame): SessionEnvelope;
|
|
20
|
+
createError(error: ErrorFrame): SessionEnvelope;
|
|
21
|
+
createSnapshot(snapshot: SnapshotPayload): SessionEnvelope;
|
|
22
|
+
/** Splits a snapshot into as few SNAPSHOT frames as fit under `maxFrameBytes` each, keeping entry order.
|
|
23
|
+
* The gateway upserts every entry, so several frames apply as one snapshot. Always returns at least one frame;
|
|
24
|
+
* throws {@link SnapshotEntryTooLargeError} before returning anything when one entry cannot fit alone. */
|
|
25
|
+
createSnapshotFrames(snapshot: SnapshotPayload, maxFrameBytes?: number): SessionEnvelope[];
|
|
26
|
+
createCommand(command: AdapterCommand): SessionEnvelope;
|
|
27
|
+
createCommandResponse(response: AdapterCommandResponse): SessionEnvelope;
|
|
28
|
+
/** Creates an Ack envelope for the given `ackedMessageId`. */
|
|
29
|
+
createAck(ackedMessageId: string): SessionEnvelope;
|
|
30
|
+
/** Creates a payload-less Heartbeat envelope. */
|
|
31
|
+
createHeartbeat(): SessionEnvelope;
|
|
32
|
+
/** The GENERIC extensibility seam: a DATA envelope carrying `payload` verbatim under an ARBITRARY `dataKind`,
|
|
33
|
+
* so a downstream package can add a kind without editing this client. The typed helpers route through here. */
|
|
34
|
+
createData(payload: unknown, dataKind: string): SessionEnvelope;
|
|
35
|
+
/** Creates a DATA(state) envelope, stamped with `dataKind:"state"`. */
|
|
36
|
+
createDataState(state: DeviceStateMessage): SessionEnvelope;
|
|
37
|
+
/** Creates a DATA(discovered) envelope, stamped with `dataKind:"discovered"`. */
|
|
38
|
+
createDataDiscovered(discovered: DiscoveredDeviceMessage): SessionEnvelope;
|
|
39
|
+
/** Creates a DATA(health) envelope, stamped with `dataKind:"health"`. */
|
|
40
|
+
createDataHealth(health: AdapterHealthMessage): SessionEnvelope;
|
|
41
|
+
/** Serializes an envelope to its canonical camelCase wire JSON string (undefined fields omitted). */
|
|
42
|
+
serialize(env: SessionEnvelope): string;
|
|
43
|
+
/** Serializes an envelope to UTF-8 wire bytes. */
|
|
44
|
+
serializeToUtf8Bytes(env: SessionEnvelope): Uint8Array;
|
|
45
|
+
/** Parses a raw wire string into a {@link SessionEnvelope}. Never throws. */
|
|
46
|
+
parse(json: string): SessionParseResult;
|
|
47
|
+
/** Parses UTF-8 wire bytes into a {@link SessionEnvelope}. Never throws. */
|
|
48
|
+
parseBytes(utf8: Uint8Array): SessionParseResult;
|
|
49
|
+
tryReadHelloAck(env: SessionEnvelope): PayloadReadResult<HelloAckFrame>;
|
|
50
|
+
tryReadAck(env: SessionEnvelope): PayloadReadResult<AckFrame>;
|
|
51
|
+
tryReadCommand(env: SessionEnvelope): PayloadReadResult<AdapterCommand>;
|
|
52
|
+
tryReadCommandResponse(env: SessionEnvelope): PayloadReadResult<AdapterCommandResponse>;
|
|
53
|
+
tryReadReauth(env: SessionEnvelope): PayloadReadResult<ReauthFrame>;
|
|
54
|
+
tryReadClose(env: SessionEnvelope): PayloadReadResult<CloseFrame>;
|
|
55
|
+
tryReadError(env: SessionEnvelope): PayloadReadResult<ErrorFrame>;
|
|
56
|
+
tryReadSnapshot(env: SessionEnvelope): PayloadReadResult<SnapshotPayload>;
|
|
57
|
+
/** Reads a DATA frame's payload as `T` ONLY when its `dataKind` equals `expectedDataKind`. Returns a defined
|
|
58
|
+
* `PayloadTypeMismatch` — never throws — on any mismatch or a missing/non-object payload. */
|
|
59
|
+
tryReadData<T>(env: SessionEnvelope, expectedDataKind: string): PayloadReadResult<T>;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=SessionProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionProtocol.d.ts","sourceRoot":"","sources":["../../src/session/SessionProtocol.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAExB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAC1B,MAAM,YAAY,CAAC;AAKpB,iHAAiH;AACjH,eAAO,MAAM,eAAe,QAAc,CAAC;AAE3C,sHAAsH;AACtH,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,QAAQ,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM;IAJhC,YACW,OAAO,EAAE,SAAS,GAAG,QAAQ,EAC7B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EAO/B;CACF;AAED;gGACgG;AAChG,eAAO,MAAM,eAAe;IAC1B,WAAW,QAAQ,UAAU,GAAG,eAAe;IAI/C,cAAc,MAAM,aAAa,GAAG,eAAe;IAInD,YAAY,SAAS,WAAW,GAAG,eAAe;IAIlD,WAAW,QAAQ,UAAU,GAAG,eAAe;IAI/C,WAAW,QAAQ,UAAU,GAAG,eAAe;IAI/C,cAAc,WAAW,eAAe,GAAG,eAAe;IAI1D;;8GAE0G;IAC1G,oBAAoB,WAAW,eAAe,kBAAiB,MAAM,GAAqB,eAAe,EAAE;IAmC3G,aAAa,UAAU,cAAc,GAAG,eAAe;IAIvD,qBAAqB,WAAW,sBAAsB,GAAG,eAAe;IAIxE,8DAA8D;IAC9D,SAAS,iBAAiB,MAAM,GAAG,eAAe;IAKlD,iDAAiD;IACjD,eAAe,IAAI,eAAe;IAIlC;mHAC+G;IAC/G,UAAU,UAAU,OAAO,YAAY,MAAM,GAAG,eAAe;IAI/D,uEAAuE;IACvE,eAAe,QAAQ,kBAAkB,GAAG,eAAe;IAI3D,iFAAiF;IACjF,oBAAoB,aAAa,uBAAuB,GAAG,eAAe;IAI1E,yEAAyE;IACzE,gBAAgB,SAAS,oBAAoB,GAAG,eAAe;IAI/D,qGAAqG;IACrG,SAAS,MAAM,eAAe,GAAG,MAAM;IAIvC,kDAAkD;IAClD,oBAAoB,MAAM,eAAe,GAAG,UAAU;IAItD,6EAA6E;IAC7E,KAAK,OAAO,MAAM,GAAG,kBAAkB;IA8CvC,4EAA4E;IAC5E,UAAU,OAAO,UAAU,GAAG,kBAAkB;IAQhD,eAAe,MAAM,eAAe,GAAG,iBAAiB,CAAC,aAAa,CAAC;IAIvE,UAAU,MAAM,eAAe,GAAG,iBAAiB,CAAC,QAAQ,CAAC;IAI7D,cAAc,MAAM,eAAe,GAAG,iBAAiB,CAAC,cAAc,CAAC;IAIvE,sBAAsB,MAAM,eAAe,GAAG,iBAAiB,CAAC,sBAAsB,CAAC;IAIvF,aAAa,MAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,CAAC;IAInE,YAAY,MAAM,eAAe,GAAG,iBAAiB,CAAC,UAAU,CAAC;IAIjE,YAAY,MAAM,eAAe,GAAG,iBAAiB,CAAC,UAAU,CAAC;IAIjE,eAAe,MAAM,eAAe,GAAG,iBAAiB,CAAC,eAAe,CAAC;IAIzE;iGAC6F;IAC7F,WAAW,CAAC,CAAC,OAAO,eAAe,oBAAoB,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC;CAUrF,CAAC"}
|