@theokit/gateway 0.27.0 → 0.28.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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.28.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 6d42c80: Widen the `@theokit/sdk` peer range to `>=4.62.0 <10` so npm admits SDK 6, 7, 8 and 9.
8
+
9
+ ## 0.28.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 483b5d9: Add `JsonRpcLineClient`, `RpcOutcome`, `RpcNotification` and `JsonRpcChild`: a line-framed JSON-RPC client for a child process, keeping the error `data` member.
14
+ - 6ac37d3: Export `refuseUnsupportedAttachments` and add a protected `refuseAttachments` helper on `BasePlatformAdapter`, so an adapter no longer needs its own copy of the attachment refusal.
15
+ - e1f837c: Add `reportDiagnostic(tag, message, options?)` and `ReportDiagnosticOptions`: one place that redacts a diagnostic line and writes `[tag] message` to stderr. Every diagnostic line in core now goes through it, so a handler error that echoes a token is redacted in `BasePlatformAdapter.runHandler` and the Weixin connect failure too.
16
+ - c2e7954: Export `verifyHmac`, `verifyDigest`, `safeEqualString` and `DigestEncoding` for webhook signature checks, with secret rotation and constant-time comparison.
17
+
18
+ ### Patch Changes
19
+
20
+ - 6f73151: Remove the two package-local copies of the line-framed JSON-RPC client: `gateway-signal` and `gateway-imessage` now use the one `JsonRpcLineClient` exported by `@theokit/gateway`, so a single implementation exists. Raises their `@theokit/gateway` peer floor to `>=0.27.0`, the first core release that exports it.
21
+ - 03c3a2c: Use the core `JsonRpcLineClient` instead of a local copy, and raise the `@theokit/gateway` peer floor to 0.27.0.
22
+ - 776b2a8: `splitKeepingRows` decides whether a straddled table row fits a part by reading only that row, instead of walking `partLimit` units from the row's start first. With `unit: "codepoint"` that walk cost as much again as the cut itself on every part a row straddled, which put `gateway-nextcloud-talk`'s `splitForTalk` at 1.55x to 1.7x of the plain cut on a 1,000,000-character table in CI, past its 1.5x budget. The parts are the same.
23
+
3
24
  ## 0.27.0
4
25
 
5
26
  ### Minor Changes
package/README.md CHANGED
@@ -144,6 +144,8 @@ if (sent.error?.code === "attachments_unsupported") {
144
144
  | `attachments_unsupported` | the adapter cannot send attachments, the outbound is an edit, or (Telegram) an attachment's `kind` is neither `image` nor `audio` |
145
145
  | `invalid_attachment` | Telegram only: `attachments` is not a list, holds more than 10 attachments, an entry has no bytes, an image is over 10 MiB, or an audio clip is over 50 MiB or its `mediaType` is not `audio/*` |
146
146
 
147
+ An adapter that is called directly (not through `GatewayRunner` or `DeliveryRouter`) refuses attachments it cannot send with `this.refuseAttachments(out)`, a protected helper on `BasePlatformAdapter` that returns `attachments_unsupported` or `undefined`. The function behind it, `refuseUnsupportedAttachments(adapter, out)`, is exported from `@theokit/gateway`.
148
+
147
149
  ## Voice notes and spoken replies
148
150
 
149
151
  An inbound event may carry `audio`, an `InboundAudio`: the voice note's bytes (`data`, a
@@ -396,6 +398,15 @@ running at that moment does not store its result. A failed fetch rejects every w
396
398
  is not cached. The signal passed to `get` reaches `fetchToken` only for the caller that starts the
397
399
  fetch. `now` replaces the clock in tests.
398
400
 
401
+ ## Talking JSON-RPC to a child process
402
+
403
+ `JsonRpcLineClient` speaks line-framed JSON-RPC 2.0 over a child's stdio. `request(method, params, timeoutMs)` always resolves an `RpcOutcome` (`result`, `error` with `code`, `message` and optional `data`, `timeout`, or `disconnected`) and never rejects. Messages with a method and no id go to `onNotification`; non-JSON and non-object lines are skipped. When the child closes or errors, every pending request settles as `disconnected` and `onClosed` fires once. `close(reason)` does the same without killing the child.
404
+
405
+ ```ts
406
+ const rpc = new JsonRpcLineClient(child, "my-adapter", onNotification, onClosed);
407
+ const outcome = await rpc.request("version", {}, 5_000);
408
+ ```
409
+
399
410
  ## Architecture (5 pieces)
400
411
 
401
412
  | Module | Responsibility |
@@ -684,6 +695,31 @@ assuming this one's.
684
695
  Adapters whose transport is a long-lived connection rather than a webhook own that transport and do
685
696
  not go through this seam.
686
697
 
698
+ ## Verifying webhook signatures
699
+
700
+ `verifyHmac`, `verifyDigest` and `safeEqualString` do the constant-time
701
+ signature compare that webhook adapters otherwise hand-write. They return
702
+ `false` (never throw) for a missing, empty, malformed or wrong-prefix
703
+ signature; an empty `secrets` value throws `RangeError`.
704
+
705
+ ```ts
706
+ import { verifyHmac } from "@theokit/gateway";
707
+
708
+ // WhatsApp-style: `X-Hub-Signature-256: sha256=<hex>`, over the raw body.
709
+ const ok = verifyHmac({
710
+ algorithm: "sha256",
711
+ secrets: [currentSecret, previousSecret], // accepts either during rotation
712
+ message: rawBody,
713
+ signature: req.headers["x-hub-signature-256"] as string | undefined,
714
+ encoding: "hex",
715
+ prefix: "sha256=",
716
+ caseInsensitive: true,
717
+ });
718
+ ```
719
+
720
+ Timestamp windows and field sorting (WeChat, WeCom) stay with the caller; pass
721
+ the built message to `verifyDigest` for keyless SHA-1/SHA-256 schemes.
722
+
687
723
  ## Verifying a JWT-signed request
688
724
 
689
725
  Platforms that sign requests with an RS256 JWT can share one key-set cache and verifier:
@@ -726,3 +762,7 @@ const backoff = new ReconnectBackoff({ initialDelayMs: 1000, maxDelayMs: 30_000
726
762
  Defaults match `ReconnectPolicy` (1 s initial, 60 s cap, factor 2). A connection open for at least
727
763
  `stableAfterMs` (default 60 s) resets the delay. A negative or non-finite delay, or a `factor`
728
764
  below 1, throws a `RangeError` naming the field.
765
+
766
+ ### Reporting diagnostics
767
+
768
+ An adapter should report a diagnostic line through `reportDiagnostic(tag, message)` rather than writing to `process.stderr` itself. It redacts credential-shaped values in `message` and writes `[tag] message` to stderr, so the redaction and any later routing live in one place. Pass `{ failure: true }` for a failure.