@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 +21 -0
- package/README.md +40 -0
- package/dist/index.cjs +313 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +137 -1
- package/dist/index.d.ts +137 -1
- package/dist/index.js +308 -156
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Writable, Readable } from 'node:stream';
|
|
1
2
|
import { KeyObject } from 'node:crypto';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -964,6 +965,11 @@ declare abstract class BasePlatformAdapter {
|
|
|
964
965
|
protected dispatchOnce(seen: SeenIds, event: MessageEvent, label: string): Promise<"ok" | "no_handler" | "handler_threw" | "duplicate">;
|
|
965
966
|
/** `out.text`, translated to the platform's markup when `out.format` is `markdown`. */
|
|
966
967
|
protected outboundText(out: OutboundMessage): string;
|
|
968
|
+
/**
|
|
969
|
+
* `attachments_unsupported` when `out` carries attachments and this adapter does not declare
|
|
970
|
+
* `supportsAttachments`, otherwise `undefined`. Call it first in `sendMessage`.
|
|
971
|
+
*/
|
|
972
|
+
protected refuseAttachments(out: OutboundMessage): SendResult | undefined;
|
|
967
973
|
/**
|
|
968
974
|
* The local checks every text-only `sendMessage` makes before a request, in this order:
|
|
969
975
|
* `empty_text`, `not_connected`, then `invalid_channel` when `channel.valid` rejects the id.
|
|
@@ -1035,6 +1041,71 @@ declare abstract class BasePlatformAdapter {
|
|
|
1035
1041
|
stopTyping(_channelId: string): Promise<void>;
|
|
1036
1042
|
}
|
|
1037
1043
|
|
|
1044
|
+
/**
|
|
1045
|
+
* A JSON-RPC 2.0 client over a child's stdio, one message per line.
|
|
1046
|
+
*
|
|
1047
|
+
* signal-cli's `jsonRpc` mode reads requests on stdin and writes responses and notifications on
|
|
1048
|
+
* stdout. Two failure paths here would otherwise end the host process, and both were measured:
|
|
1049
|
+
* an `EPIPE` on a stdin the child already closed, raised as an `error` event nobody listens to,
|
|
1050
|
+
* and a `JSON.parse` throw on a stray log line inside a stream listener. The first is listened
|
|
1051
|
+
* to and the second is caught and reported, so a dying or noisy child costs its own requests and
|
|
1052
|
+
* nothing else.
|
|
1053
|
+
*
|
|
1054
|
+
* @public
|
|
1055
|
+
*/
|
|
1056
|
+
|
|
1057
|
+
/** The child process shape the client drives: its three pipes, `kill`, and `close`/`error` events. */
|
|
1058
|
+
interface JsonRpcChild {
|
|
1059
|
+
readonly stdin: Writable;
|
|
1060
|
+
readonly stdout: Readable;
|
|
1061
|
+
readonly stderr: Readable;
|
|
1062
|
+
kill(signal?: NodeJS.Signals | number): boolean;
|
|
1063
|
+
on(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
|
1064
|
+
on(event: "error", listener: (err: Error) => void): this;
|
|
1065
|
+
}
|
|
1066
|
+
/** How one request ended. Never a rejection: every outcome is a value the caller maps. */
|
|
1067
|
+
type RpcOutcome = {
|
|
1068
|
+
readonly kind: "result";
|
|
1069
|
+
readonly result: unknown;
|
|
1070
|
+
} | {
|
|
1071
|
+
readonly kind: "error";
|
|
1072
|
+
readonly code: number;
|
|
1073
|
+
readonly message: string;
|
|
1074
|
+
readonly data?: unknown;
|
|
1075
|
+
} | {
|
|
1076
|
+
readonly kind: "timeout";
|
|
1077
|
+
} | {
|
|
1078
|
+
readonly kind: "disconnected";
|
|
1079
|
+
};
|
|
1080
|
+
/** A server-to-client message with no id. */
|
|
1081
|
+
interface RpcNotification {
|
|
1082
|
+
readonly method: string;
|
|
1083
|
+
readonly params: unknown;
|
|
1084
|
+
}
|
|
1085
|
+
/** Line-framed JSON-RPC over one child. Dead once the child exits or `close()` is called. */
|
|
1086
|
+
declare class JsonRpcLineClient {
|
|
1087
|
+
private readonly child;
|
|
1088
|
+
private readonly label;
|
|
1089
|
+
private readonly onNotification;
|
|
1090
|
+
private readonly onClosed;
|
|
1091
|
+
private counter;
|
|
1092
|
+
private readonly pending;
|
|
1093
|
+
private alive;
|
|
1094
|
+
/**
|
|
1095
|
+
* @param child - the running child; the client attaches to its pipes and events
|
|
1096
|
+
* @param label - the stderr tag, e.g. `gateway-signal`
|
|
1097
|
+
* @param onNotification - called for every message that carries a method and no id
|
|
1098
|
+
* @param onClosed - called once, when the child exits or fails
|
|
1099
|
+
*/
|
|
1100
|
+
constructor(child: JsonRpcChild, label: string, onNotification: (notification: RpcNotification) => void, onClosed: (reason: string) => void);
|
|
1101
|
+
/** Send `method` and wait for its answer, at most `timeoutMs`. */
|
|
1102
|
+
request(method: string, params: unknown, timeoutMs: number): Promise<RpcOutcome>;
|
|
1103
|
+
/** Settle every pending request as `disconnected` and stop accepting new ones. Idempotent. */
|
|
1104
|
+
close(reason: string): void;
|
|
1105
|
+
private settle;
|
|
1106
|
+
private handleLine;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1038
1109
|
/**
|
|
1039
1110
|
* Map an HTTP status to a failed SendResult: 429 -> rate_limit (retryAfterMs from a Retry-After
|
|
1040
1111
|
* value in seconds or an HTTP date), 401 -> auth_failed, 403 -> permission_denied,
|
|
@@ -1531,6 +1602,28 @@ interface CreateChannelsResult {
|
|
|
1531
1602
|
*/
|
|
1532
1603
|
declare function createChannels(entries: ReadonlyArray<ChannelEntry>): CreateChannelsResult;
|
|
1533
1604
|
|
|
1605
|
+
/**
|
|
1606
|
+
* How the core's two outbound builders treat `attachments` (B-674): `GatewayRunner`'s `ctx.reply`
|
|
1607
|
+
* and `DeliveryRouter.send` both carry a non-empty list and both refuse it for an adapter that
|
|
1608
|
+
* does not declare `supportsAttachments`.
|
|
1609
|
+
*
|
|
1610
|
+
* The refusal here is defence in depth: every adapter in this repository refuses on its own, but an
|
|
1611
|
+
* adapter written elsewhere inherits `supportsAttachments = false` and may ignore the field, sending
|
|
1612
|
+
* the text alone and reporting success. Refusing before the adapter is called keeps the image from
|
|
1613
|
+
* being dropped in silence whichever adapter receives it.
|
|
1614
|
+
*/
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* `attachments_unsupported` when `outbound` carries attachments and `adapter` does not declare
|
|
1618
|
+
* `supportsAttachments`, otherwise `undefined`. Makes no platform call.
|
|
1619
|
+
*
|
|
1620
|
+
* `GatewayRunner` and `DeliveryRouter` call it before they reach an adapter; an adapter calls it
|
|
1621
|
+
* (or {@link BasePlatformAdapter.refuseAttachments}) to refuse on a direct `sendMessage`. Absent,
|
|
1622
|
+
* `null` and empty `attachments` pass; any other value without a zero length, such as `{}` from a
|
|
1623
|
+
* JavaScript caller, is refused.
|
|
1624
|
+
*/
|
|
1625
|
+
declare function refuseUnsupportedAttachments(adapter: BasePlatformAdapter, outbound: OutboundMessage): SendResult | undefined;
|
|
1626
|
+
|
|
1534
1627
|
/**
|
|
1535
1628
|
* `DeliveryRouter` — outbound dispatch by platform (T3.1, ADR D175).
|
|
1536
1629
|
*
|
|
@@ -1577,6 +1670,20 @@ declare class DeliveryRouter {
|
|
|
1577
1670
|
send(req: DeliveryRequest): Promise<SendResult>;
|
|
1578
1671
|
}
|
|
1579
1672
|
|
|
1673
|
+
/** Options for {@link reportDiagnostic}. */
|
|
1674
|
+
interface ReportDiagnosticOptions {
|
|
1675
|
+
/** A failure (as opposed to an informational line). Default false. */
|
|
1676
|
+
readonly failure?: boolean;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Redact, prefix with `[tag] `, and write one line.
|
|
1680
|
+
*
|
|
1681
|
+
* Every diagnostic line from the gateway goes through here, so redaction (and
|
|
1682
|
+
* later, routing) happens in one place. `options.failure` does not change the
|
|
1683
|
+
* output today; it marks the line for routing once the SDK exports its emitters.
|
|
1684
|
+
*/
|
|
1685
|
+
declare function reportDiagnostic(tag: string, message: string, _options?: ReportDiagnosticOptions): void;
|
|
1686
|
+
|
|
1580
1687
|
/**
|
|
1581
1688
|
* `GatewayLifecycleError` — a lifecycle method was called from a state that
|
|
1582
1689
|
* cannot honour it.
|
|
@@ -2628,4 +2735,33 @@ interface WebhookHandlerOptions {
|
|
|
2628
2735
|
*/
|
|
2629
2736
|
declare function createWebhookHandler(options: WebhookHandlerOptions): (request: Request) => Promise<Response>;
|
|
2630
2737
|
|
|
2631
|
-
|
|
2738
|
+
/** Text encoding of a digest as sent in a webhook header. */
|
|
2739
|
+
type DigestEncoding = "hex" | "base64" | "base64url";
|
|
2740
|
+
/** Constant-time string compare; false (never a throw) on length mismatch or an empty side. */
|
|
2741
|
+
declare function safeEqualString(expected: string, received: string): boolean;
|
|
2742
|
+
/** Options for {@link verifyHmac}. */
|
|
2743
|
+
interface VerifyHmacOptions {
|
|
2744
|
+
readonly algorithm: "sha256" | "sha1";
|
|
2745
|
+
/** One secret, or several to accept during rotation. An empty secret throws RangeError. */
|
|
2746
|
+
readonly secrets: string | readonly string[];
|
|
2747
|
+
readonly message: string | Uint8Array;
|
|
2748
|
+
/** The header value as received; `undefined` or "" fails. */
|
|
2749
|
+
readonly signature: string | undefined;
|
|
2750
|
+
readonly encoding: DigestEncoding;
|
|
2751
|
+
/** Stripped before compare, e.g. "sha256=". A header without it fails. */
|
|
2752
|
+
readonly prefix?: string;
|
|
2753
|
+
/** Hex compare ignores case when true. Default false. */
|
|
2754
|
+
readonly caseInsensitive?: boolean;
|
|
2755
|
+
}
|
|
2756
|
+
/** Verify an HMAC webhook signature in constant time, accepting any of the given secrets. */
|
|
2757
|
+
declare function verifyHmac(opts: VerifyHmacOptions): boolean;
|
|
2758
|
+
/** Plain digest (no key), for platforms that hash secret+fields: zalo, wechat, wecom. */
|
|
2759
|
+
declare function verifyDigest(opts: {
|
|
2760
|
+
algorithm: "sha256" | "sha1";
|
|
2761
|
+
message: string;
|
|
2762
|
+
signature: string | undefined;
|
|
2763
|
+
encoding: DigestEncoding;
|
|
2764
|
+
prefix?: string;
|
|
2765
|
+
}): boolean;
|
|
2766
|
+
|
|
2767
|
+
export { type AccessPolicyOptions, type AdapterCapabilities, type AdapterState, type AgentBindingRule, type AgentBindings, type AgentBindingsOptions, type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type BuiltChannel, type BuzzMessageEvent, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelConfigInput, type ChannelConfigReaders, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChatCommand, type ChunkByGraphemeOptions, type ChunkTextOptions, type ClickClackMessageEvent, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type CredentialStore, DEFAULT_WEBHOOK_MAX_BYTES, type DecodedJwt, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DigestEncoding, type DiscordMessageEvent, type DmPolicy, type DmScope, type EmailMessageEvent, type EnvConfig, type FeishuLarkMessageEvent, type FenceRegion, type FetchedToken, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type InboundAudio, type IngestResult, type IrcMessageEvent, type JsonRpcChild, JsonRpcLineClient, type JwksKeySet, type JwksKeySetOptions, type JwksLookup, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MediaUnderstandingOptions, type MessageEvent, type NextcloudTalkMessageEvent, type NostrMessageEvent, type OnErrorContext, type OutboundAttachment, type OutboundMessage, type PairingStore, type ParsedChatCommand, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type QQMessageEvent, type RaftMessageEvent, type RawBodyCaptureOptions, type RawBodyRequest, ReconnectBackoff, type ReconnectBackoffOptions, type ReconnectPolicy, type ReportDiagnosticOptions, type RpcNotification, type RpcOutcome, type SMSMessageEvent, type ScopedStrategyOptions, SeenIds, type SendError, type SendErrorCode, type SendResult, type SenderIdentity, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type SplitKeepingRowsOptions, type StartResult, type SynologyChatMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type TlonUrbitMessageEvent, type TokenCache, type TokenCacheOptions, type TwitchMessageEvent, type UncoveredShape, type VerifyHmacOptions, type VerifyJwtResult, type WeChatMessageEvent, type WeComMessageEvent, type WebhookAnswer, type WebhookHandlerOptions, type WebhookRequest, WeixinAdapterBase, type WeixinAdapterConfig, type WeixinFetch, type WeixinSendRequest, type WeixinWebhookAnswer, type WhatsAppMessageEvent, type XMessageEvent, type XThreadTweet, type YuanbaoMessageEvent, type ZaloMessageEvent, type ZaloPersonalMessageEvent, bindingStrategy, channelConfigReaders, channelRendering, chunkByGrapheme, chunkText, commandHook, configFromEnv, createAccessPolicyHook, createAgentBindings, createChannels, createFileCredentialStore, createFilePairingStore, createTokenCache, createWebhookHandler, decodeJwt, defaultStrategy, helpText, isAuthenticatedSender, jwksKeySet, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, refuseUnsupportedAttachments, reportDiagnostic, safeEqualString, scanFences, scopedStrategy, selectVariant, sendErrorFromHttp, senderKey, splitKeepingRows, statusForDeliver, toDialect, verifyDigest, verifyHmac, verifyRs256Jwt, withMediaUnderstanding };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Writable, Readable } from 'node:stream';
|
|
1
2
|
import { KeyObject } from 'node:crypto';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -964,6 +965,11 @@ declare abstract class BasePlatformAdapter {
|
|
|
964
965
|
protected dispatchOnce(seen: SeenIds, event: MessageEvent, label: string): Promise<"ok" | "no_handler" | "handler_threw" | "duplicate">;
|
|
965
966
|
/** `out.text`, translated to the platform's markup when `out.format` is `markdown`. */
|
|
966
967
|
protected outboundText(out: OutboundMessage): string;
|
|
968
|
+
/**
|
|
969
|
+
* `attachments_unsupported` when `out` carries attachments and this adapter does not declare
|
|
970
|
+
* `supportsAttachments`, otherwise `undefined`. Call it first in `sendMessage`.
|
|
971
|
+
*/
|
|
972
|
+
protected refuseAttachments(out: OutboundMessage): SendResult | undefined;
|
|
967
973
|
/**
|
|
968
974
|
* The local checks every text-only `sendMessage` makes before a request, in this order:
|
|
969
975
|
* `empty_text`, `not_connected`, then `invalid_channel` when `channel.valid` rejects the id.
|
|
@@ -1035,6 +1041,71 @@ declare abstract class BasePlatformAdapter {
|
|
|
1035
1041
|
stopTyping(_channelId: string): Promise<void>;
|
|
1036
1042
|
}
|
|
1037
1043
|
|
|
1044
|
+
/**
|
|
1045
|
+
* A JSON-RPC 2.0 client over a child's stdio, one message per line.
|
|
1046
|
+
*
|
|
1047
|
+
* signal-cli's `jsonRpc` mode reads requests on stdin and writes responses and notifications on
|
|
1048
|
+
* stdout. Two failure paths here would otherwise end the host process, and both were measured:
|
|
1049
|
+
* an `EPIPE` on a stdin the child already closed, raised as an `error` event nobody listens to,
|
|
1050
|
+
* and a `JSON.parse` throw on a stray log line inside a stream listener. The first is listened
|
|
1051
|
+
* to and the second is caught and reported, so a dying or noisy child costs its own requests and
|
|
1052
|
+
* nothing else.
|
|
1053
|
+
*
|
|
1054
|
+
* @public
|
|
1055
|
+
*/
|
|
1056
|
+
|
|
1057
|
+
/** The child process shape the client drives: its three pipes, `kill`, and `close`/`error` events. */
|
|
1058
|
+
interface JsonRpcChild {
|
|
1059
|
+
readonly stdin: Writable;
|
|
1060
|
+
readonly stdout: Readable;
|
|
1061
|
+
readonly stderr: Readable;
|
|
1062
|
+
kill(signal?: NodeJS.Signals | number): boolean;
|
|
1063
|
+
on(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
|
1064
|
+
on(event: "error", listener: (err: Error) => void): this;
|
|
1065
|
+
}
|
|
1066
|
+
/** How one request ended. Never a rejection: every outcome is a value the caller maps. */
|
|
1067
|
+
type RpcOutcome = {
|
|
1068
|
+
readonly kind: "result";
|
|
1069
|
+
readonly result: unknown;
|
|
1070
|
+
} | {
|
|
1071
|
+
readonly kind: "error";
|
|
1072
|
+
readonly code: number;
|
|
1073
|
+
readonly message: string;
|
|
1074
|
+
readonly data?: unknown;
|
|
1075
|
+
} | {
|
|
1076
|
+
readonly kind: "timeout";
|
|
1077
|
+
} | {
|
|
1078
|
+
readonly kind: "disconnected";
|
|
1079
|
+
};
|
|
1080
|
+
/** A server-to-client message with no id. */
|
|
1081
|
+
interface RpcNotification {
|
|
1082
|
+
readonly method: string;
|
|
1083
|
+
readonly params: unknown;
|
|
1084
|
+
}
|
|
1085
|
+
/** Line-framed JSON-RPC over one child. Dead once the child exits or `close()` is called. */
|
|
1086
|
+
declare class JsonRpcLineClient {
|
|
1087
|
+
private readonly child;
|
|
1088
|
+
private readonly label;
|
|
1089
|
+
private readonly onNotification;
|
|
1090
|
+
private readonly onClosed;
|
|
1091
|
+
private counter;
|
|
1092
|
+
private readonly pending;
|
|
1093
|
+
private alive;
|
|
1094
|
+
/**
|
|
1095
|
+
* @param child - the running child; the client attaches to its pipes and events
|
|
1096
|
+
* @param label - the stderr tag, e.g. `gateway-signal`
|
|
1097
|
+
* @param onNotification - called for every message that carries a method and no id
|
|
1098
|
+
* @param onClosed - called once, when the child exits or fails
|
|
1099
|
+
*/
|
|
1100
|
+
constructor(child: JsonRpcChild, label: string, onNotification: (notification: RpcNotification) => void, onClosed: (reason: string) => void);
|
|
1101
|
+
/** Send `method` and wait for its answer, at most `timeoutMs`. */
|
|
1102
|
+
request(method: string, params: unknown, timeoutMs: number): Promise<RpcOutcome>;
|
|
1103
|
+
/** Settle every pending request as `disconnected` and stop accepting new ones. Idempotent. */
|
|
1104
|
+
close(reason: string): void;
|
|
1105
|
+
private settle;
|
|
1106
|
+
private handleLine;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1038
1109
|
/**
|
|
1039
1110
|
* Map an HTTP status to a failed SendResult: 429 -> rate_limit (retryAfterMs from a Retry-After
|
|
1040
1111
|
* value in seconds or an HTTP date), 401 -> auth_failed, 403 -> permission_denied,
|
|
@@ -1531,6 +1602,28 @@ interface CreateChannelsResult {
|
|
|
1531
1602
|
*/
|
|
1532
1603
|
declare function createChannels(entries: ReadonlyArray<ChannelEntry>): CreateChannelsResult;
|
|
1533
1604
|
|
|
1605
|
+
/**
|
|
1606
|
+
* How the core's two outbound builders treat `attachments` (B-674): `GatewayRunner`'s `ctx.reply`
|
|
1607
|
+
* and `DeliveryRouter.send` both carry a non-empty list and both refuse it for an adapter that
|
|
1608
|
+
* does not declare `supportsAttachments`.
|
|
1609
|
+
*
|
|
1610
|
+
* The refusal here is defence in depth: every adapter in this repository refuses on its own, but an
|
|
1611
|
+
* adapter written elsewhere inherits `supportsAttachments = false` and may ignore the field, sending
|
|
1612
|
+
* the text alone and reporting success. Refusing before the adapter is called keeps the image from
|
|
1613
|
+
* being dropped in silence whichever adapter receives it.
|
|
1614
|
+
*/
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* `attachments_unsupported` when `outbound` carries attachments and `adapter` does not declare
|
|
1618
|
+
* `supportsAttachments`, otherwise `undefined`. Makes no platform call.
|
|
1619
|
+
*
|
|
1620
|
+
* `GatewayRunner` and `DeliveryRouter` call it before they reach an adapter; an adapter calls it
|
|
1621
|
+
* (or {@link BasePlatformAdapter.refuseAttachments}) to refuse on a direct `sendMessage`. Absent,
|
|
1622
|
+
* `null` and empty `attachments` pass; any other value without a zero length, such as `{}` from a
|
|
1623
|
+
* JavaScript caller, is refused.
|
|
1624
|
+
*/
|
|
1625
|
+
declare function refuseUnsupportedAttachments(adapter: BasePlatformAdapter, outbound: OutboundMessage): SendResult | undefined;
|
|
1626
|
+
|
|
1534
1627
|
/**
|
|
1535
1628
|
* `DeliveryRouter` — outbound dispatch by platform (T3.1, ADR D175).
|
|
1536
1629
|
*
|
|
@@ -1577,6 +1670,20 @@ declare class DeliveryRouter {
|
|
|
1577
1670
|
send(req: DeliveryRequest): Promise<SendResult>;
|
|
1578
1671
|
}
|
|
1579
1672
|
|
|
1673
|
+
/** Options for {@link reportDiagnostic}. */
|
|
1674
|
+
interface ReportDiagnosticOptions {
|
|
1675
|
+
/** A failure (as opposed to an informational line). Default false. */
|
|
1676
|
+
readonly failure?: boolean;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Redact, prefix with `[tag] `, and write one line.
|
|
1680
|
+
*
|
|
1681
|
+
* Every diagnostic line from the gateway goes through here, so redaction (and
|
|
1682
|
+
* later, routing) happens in one place. `options.failure` does not change the
|
|
1683
|
+
* output today; it marks the line for routing once the SDK exports its emitters.
|
|
1684
|
+
*/
|
|
1685
|
+
declare function reportDiagnostic(tag: string, message: string, _options?: ReportDiagnosticOptions): void;
|
|
1686
|
+
|
|
1580
1687
|
/**
|
|
1581
1688
|
* `GatewayLifecycleError` — a lifecycle method was called from a state that
|
|
1582
1689
|
* cannot honour it.
|
|
@@ -2628,4 +2735,33 @@ interface WebhookHandlerOptions {
|
|
|
2628
2735
|
*/
|
|
2629
2736
|
declare function createWebhookHandler(options: WebhookHandlerOptions): (request: Request) => Promise<Response>;
|
|
2630
2737
|
|
|
2631
|
-
|
|
2738
|
+
/** Text encoding of a digest as sent in a webhook header. */
|
|
2739
|
+
type DigestEncoding = "hex" | "base64" | "base64url";
|
|
2740
|
+
/** Constant-time string compare; false (never a throw) on length mismatch or an empty side. */
|
|
2741
|
+
declare function safeEqualString(expected: string, received: string): boolean;
|
|
2742
|
+
/** Options for {@link verifyHmac}. */
|
|
2743
|
+
interface VerifyHmacOptions {
|
|
2744
|
+
readonly algorithm: "sha256" | "sha1";
|
|
2745
|
+
/** One secret, or several to accept during rotation. An empty secret throws RangeError. */
|
|
2746
|
+
readonly secrets: string | readonly string[];
|
|
2747
|
+
readonly message: string | Uint8Array;
|
|
2748
|
+
/** The header value as received; `undefined` or "" fails. */
|
|
2749
|
+
readonly signature: string | undefined;
|
|
2750
|
+
readonly encoding: DigestEncoding;
|
|
2751
|
+
/** Stripped before compare, e.g. "sha256=". A header without it fails. */
|
|
2752
|
+
readonly prefix?: string;
|
|
2753
|
+
/** Hex compare ignores case when true. Default false. */
|
|
2754
|
+
readonly caseInsensitive?: boolean;
|
|
2755
|
+
}
|
|
2756
|
+
/** Verify an HMAC webhook signature in constant time, accepting any of the given secrets. */
|
|
2757
|
+
declare function verifyHmac(opts: VerifyHmacOptions): boolean;
|
|
2758
|
+
/** Plain digest (no key), for platforms that hash secret+fields: zalo, wechat, wecom. */
|
|
2759
|
+
declare function verifyDigest(opts: {
|
|
2760
|
+
algorithm: "sha256" | "sha1";
|
|
2761
|
+
message: string;
|
|
2762
|
+
signature: string | undefined;
|
|
2763
|
+
encoding: DigestEncoding;
|
|
2764
|
+
prefix?: string;
|
|
2765
|
+
}): boolean;
|
|
2766
|
+
|
|
2767
|
+
export { type AccessPolicyOptions, type AdapterCapabilities, type AdapterState, type AgentBindingRule, type AgentBindings, type AgentBindingsOptions, type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type BuiltChannel, type BuzzMessageEvent, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelConfigInput, type ChannelConfigReaders, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChatCommand, type ChunkByGraphemeOptions, type ChunkTextOptions, type ClickClackMessageEvent, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type CredentialStore, DEFAULT_WEBHOOK_MAX_BYTES, type DecodedJwt, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DigestEncoding, type DiscordMessageEvent, type DmPolicy, type DmScope, type EmailMessageEvent, type EnvConfig, type FeishuLarkMessageEvent, type FenceRegion, type FetchedToken, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type InboundAudio, type IngestResult, type IrcMessageEvent, type JsonRpcChild, JsonRpcLineClient, type JwksKeySet, type JwksKeySetOptions, type JwksLookup, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MediaUnderstandingOptions, type MessageEvent, type NextcloudTalkMessageEvent, type NostrMessageEvent, type OnErrorContext, type OutboundAttachment, type OutboundMessage, type PairingStore, type ParsedChatCommand, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type QQMessageEvent, type RaftMessageEvent, type RawBodyCaptureOptions, type RawBodyRequest, ReconnectBackoff, type ReconnectBackoffOptions, type ReconnectPolicy, type ReportDiagnosticOptions, type RpcNotification, type RpcOutcome, type SMSMessageEvent, type ScopedStrategyOptions, SeenIds, type SendError, type SendErrorCode, type SendResult, type SenderIdentity, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type SplitKeepingRowsOptions, type StartResult, type SynologyChatMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type TlonUrbitMessageEvent, type TokenCache, type TokenCacheOptions, type TwitchMessageEvent, type UncoveredShape, type VerifyHmacOptions, type VerifyJwtResult, type WeChatMessageEvent, type WeComMessageEvent, type WebhookAnswer, type WebhookHandlerOptions, type WebhookRequest, WeixinAdapterBase, type WeixinAdapterConfig, type WeixinFetch, type WeixinSendRequest, type WeixinWebhookAnswer, type WhatsAppMessageEvent, type XMessageEvent, type XThreadTweet, type YuanbaoMessageEvent, type ZaloMessageEvent, type ZaloPersonalMessageEvent, bindingStrategy, channelConfigReaders, channelRendering, chunkByGrapheme, chunkText, commandHook, configFromEnv, createAccessPolicyHook, createAgentBindings, createChannels, createFileCredentialStore, createFilePairingStore, createTokenCache, createWebhookHandler, decodeJwt, defaultStrategy, helpText, isAuthenticatedSender, jwksKeySet, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, refuseUnsupportedAttachments, reportDiagnostic, safeEqualString, scanFences, scopedStrategy, selectVariant, sendErrorFromHttp, senderKey, splitKeepingRows, statusForDeliver, toDialect, verifyDigest, verifyHmac, verifyRs256Jwt, withMediaUnderstanding };
|