@theokit/gateway 0.8.0 → 0.10.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 +133 -0
- package/README.md +82 -0
- package/dist/index.cjs +168 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +168 -7
- package/dist/index.d.ts +168 -7
- package/dist/index.js +165 -1
- package/dist/index.js.map +1 -1
- package/package.json +22 -6
package/dist/index.d.ts
CHANGED
|
@@ -108,6 +108,23 @@ interface WhatsAppMessageEvent extends BaseMessageEvent {
|
|
|
108
108
|
readonly phoneNumberId?: string;
|
|
109
109
|
/** Contact's profile name when Meta provides it. */
|
|
110
110
|
readonly contactName?: string;
|
|
111
|
+
/**
|
|
112
|
+
* The address this arrived on, verbatim — what a reply must be sent to.
|
|
113
|
+
*
|
|
114
|
+
* `channel.id` is normalised to digits, which is what an allowlist compares and what a session
|
|
115
|
+
* key is built from. The normalisation strips the DOMAIN, and the domain is what says which
|
|
116
|
+
* kind of identifier it is: `@s.whatsapp.net` a phone, `@g.us` a group, `@lid` an account's
|
|
117
|
+
* linked identity. A note-to-self arrives addressed by LID, so answering `channel.id` rebuilds
|
|
118
|
+
* `…@s.whatsapp.net` — an address that does not exist, and a send that reports ok and lands
|
|
119
|
+
* nowhere (#84).
|
|
120
|
+
*
|
|
121
|
+
* `sendMessage` accepts this verbatim: a `to` containing `@` is already an address and is
|
|
122
|
+
* passed through untouched.
|
|
123
|
+
*
|
|
124
|
+
* Present on the baileys backend. The cloud backend addresses recipients by phone and has no
|
|
125
|
+
* JID to report.
|
|
126
|
+
*/
|
|
127
|
+
readonly channelJid?: string;
|
|
111
128
|
/**
|
|
112
129
|
* Which backend produced this event.
|
|
113
130
|
*
|
|
@@ -429,6 +446,36 @@ declare abstract class BasePlatformAdapter {
|
|
|
429
446
|
* ten to it.
|
|
430
447
|
*/
|
|
431
448
|
abstract onInbound(handler: (event: MessageEvent) => Promise<void>): () => void;
|
|
449
|
+
/**
|
|
450
|
+
* Deliver an inbound event that arrived OUT OF BAND, and report what the handler did with it.
|
|
451
|
+
*
|
|
452
|
+
* Six adapters self-deliver once connected — long polling, a gateway socket, Socket Mode, a sync
|
|
453
|
+
* loop, IMAP. The webhook platforms cannot: the payload arrives on an HTTP route the application
|
|
454
|
+
* owns, and until this existed there was no supported call that joined the two. `onInbound` had no
|
|
455
|
+
* public counterpart, so `GatewayRunner` was reachable for eight platforms and not for LINE or
|
|
456
|
+
* WhatsApp Cloud, which every app then wired by hand beside the runner instead of through it
|
|
457
|
+
* (#83).
|
|
458
|
+
*
|
|
459
|
+
* The return value distinguishes the three outcomes a caller can act on, because they are not the
|
|
460
|
+
* same problem: nobody subscribed, the handler ran, or the handler threw. Answering a webhook 200
|
|
461
|
+
* for the first is wrong — the provider would stop retrying a message nothing received.
|
|
462
|
+
*
|
|
463
|
+
* Implementations should be one line over {@link runHandler}, which owns the containment.
|
|
464
|
+
*/
|
|
465
|
+
abstract deliver(event: MessageEvent): Promise<"ok" | "no_handler" | "handler_threw">;
|
|
466
|
+
/**
|
|
467
|
+
* Run a subscribed handler and contain its failure. The body of {@link deliver}, written once.
|
|
468
|
+
*
|
|
469
|
+
* A handler is USER code and may throw. An adapter must contain that throw, name it as the
|
|
470
|
+
* handler's failure rather than the platform's, and keep delivering — one bad message ends
|
|
471
|
+
* neither the process nor the connection. Two adapters once discarded the rejection with `void`,
|
|
472
|
+
* which under Node's default ends the process; two more reported it as a platform-client error,
|
|
473
|
+
* sending whoever debugged their own handler to the wrong repository (#41).
|
|
474
|
+
*
|
|
475
|
+
* Ten copies of that knowledge is ten chances to get it wrong, so it lives here. The platform tag
|
|
476
|
+
* is taken from `this.platform`, which is the only part that differed between them.
|
|
477
|
+
*/
|
|
478
|
+
protected runHandler(handler: ((event: MessageEvent) => Promise<void>) | undefined, event: MessageEvent): Promise<"ok" | "no_handler" | "handler_threw">;
|
|
432
479
|
/** Lifecycle: emit a typing indicator. Default: noop. */
|
|
433
480
|
startTyping(_channelId: string): Promise<void>;
|
|
434
481
|
/** Lifecycle: stop the typing indicator. Default: noop. */
|
|
@@ -607,12 +654,6 @@ interface GatewayHook {
|
|
|
607
654
|
* @public
|
|
608
655
|
*/
|
|
609
656
|
|
|
610
|
-
/**
|
|
611
|
-
* Runs registered hooks at the right fire points. Stateless — safe to
|
|
612
|
-
* construct per-event if hooks need event-scoped storage.
|
|
613
|
-
*
|
|
614
|
-
* @public
|
|
615
|
-
*/
|
|
616
657
|
declare class HookExecutor {
|
|
617
658
|
private readonly hooks;
|
|
618
659
|
constructor(hooks: ReadonlyArray<GatewayHook>);
|
|
@@ -906,4 +947,124 @@ interface ChunkByGraphemeOptions {
|
|
|
906
947
|
*/
|
|
907
948
|
declare function chunkByGrapheme(text: string, options: ChunkByGraphemeOptions): string[];
|
|
908
949
|
|
|
909
|
-
|
|
950
|
+
/**
|
|
951
|
+
* Markdown → the target channel's own dialect (B-019 FR-005).
|
|
952
|
+
*
|
|
953
|
+
* ## Why this exists here, and not in an adapter
|
|
954
|
+
*
|
|
955
|
+
* Measured 2026-09-17 across every `adapter.ts` and `split.ts` in the ten packages: **no package
|
|
956
|
+
* transforms a single character of text.** What exists is markdown ESCAPE (discord, mattermost),
|
|
957
|
+
* HTML escape (email), phone normalisation (whatsapp) and post-cut newline cleanup (telegram's
|
|
958
|
+
* splitter). `OutboundMessage.format` is read by all ten — `adapter-contract.test.ts` proves it —
|
|
959
|
+
* but reading a flag is not translating a body.
|
|
960
|
+
*
|
|
961
|
+
* So the agent answered `**Bom Sucesso (MG)**` and both LINE and WhatsApp delivered the asterisks
|
|
962
|
+
* to a real phone. The adapters refuse the translation deliberately and they are right to:
|
|
963
|
+
* `gateway-whatsapp` reads `format` only to warn once, because emphasis there is inline in the
|
|
964
|
+
* text rather than a transport flag. An adapter is transport.
|
|
965
|
+
*
|
|
966
|
+
* Translation is PRESENTATION — it depends on what was said and on where it is going at the same
|
|
967
|
+
* time — so it belongs to the presenter. It is exported from here as a pure function and CALLED by
|
|
968
|
+
* the channel presenter in `theokit`, never the reverse: `@theokit/gateway` must not depend on
|
|
969
|
+
* `@theokit/presenter`, or a gateway stops being usable without an agent.
|
|
970
|
+
*
|
|
971
|
+
* ## What it deliberately does NOT do
|
|
972
|
+
*
|
|
973
|
+
* It is not a markdown parser. It rewrites the four inline markers that reach a chat surface in
|
|
974
|
+
* practice — bold, italic, strikethrough, inline code — and it leaves everything else alone:
|
|
975
|
+
* links, headings, lists, block quotes and fenced code are untouched, because no measurement here
|
|
976
|
+
* says what they should become on a platform with no equivalent.
|
|
977
|
+
*
|
|
978
|
+
* A platform it has not been taught is passed through UNCHANGED. Inventing a mapping would be
|
|
979
|
+
* wrong invisibly; passing `**bold**` through is wrong where somebody can see it.
|
|
980
|
+
*/
|
|
981
|
+
/**
|
|
982
|
+
* Rewrite `text` for `platform`.
|
|
983
|
+
*
|
|
984
|
+
* @param text - the assembled answer, in markdown as the model produced it
|
|
985
|
+
* @param platform - the destination; one this function has not been taught passes through
|
|
986
|
+
* @returns the text in the platform's dialect, or unchanged when none is known
|
|
987
|
+
* @public
|
|
988
|
+
*/
|
|
989
|
+
declare function toDialect(text: string, platform: string): string;
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* The half of an Express webhook server that is the same for every platform.
|
|
993
|
+
*
|
|
994
|
+
* `gateway-line` and `gateway-sms` each ship one, and they shared 101 of ~170 lines: the lazy
|
|
995
|
+
* `express` load, the raw-body capture with the hang it documents, and the start/stop lifecycle.
|
|
996
|
+
* What differs is signature verification, body parsing and routing, which are genuinely
|
|
997
|
+
* per-platform (#89).
|
|
998
|
+
*
|
|
999
|
+
* The duplication had already been paid for. Commit `11000cc` fixed a write-once latch that made
|
|
1000
|
+
* `start()` after `stop()` return without creating a listener — a port nothing answers on, with no
|
|
1001
|
+
* error and no log — and it had to fix it in BOTH files, because the latch lives in the copied
|
|
1002
|
+
* half. That is the DRY test verbatim: change it here, change it there.
|
|
1003
|
+
*
|
|
1004
|
+
* ## Why here, and not in a new package
|
|
1005
|
+
*
|
|
1006
|
+
* The core had no HTTP concern, and `express` is a peer dependency of exactly the two packages that
|
|
1007
|
+
* duplicate this — so the obvious objection to putting it here is that it would impose express on
|
|
1008
|
+
* all ten adapters.
|
|
1009
|
+
*
|
|
1010
|
+
* It does not, because nothing here imports express. Every shape below is structural: a request is
|
|
1011
|
+
* whatever has `readableEnded` and `on`, a listener is whatever has `listen` and `close`. The
|
|
1012
|
+
* packages that use express keep declaring it; this module never learns the name.
|
|
1013
|
+
*
|
|
1014
|
+
* Exported rather than internal: the two packages that consume it are separate npm packages, so
|
|
1015
|
+
* "internal to this repository" is not a thing the module system can express.
|
|
1016
|
+
*
|
|
1017
|
+
* @public
|
|
1018
|
+
*/
|
|
1019
|
+
/** What the capture middleware reads. Express's `Request` satisfies it; so does a bare stream. */
|
|
1020
|
+
interface RawBodyRequest {
|
|
1021
|
+
readonly readableEnded?: boolean;
|
|
1022
|
+
readonly complete?: boolean;
|
|
1023
|
+
setEncoding(encoding: string): unknown;
|
|
1024
|
+
on(event: string, listener: (arg: never) => void): unknown;
|
|
1025
|
+
}
|
|
1026
|
+
/** What a started listener must be able to do. `http.Server` satisfies it. */
|
|
1027
|
+
interface ListenerLike {
|
|
1028
|
+
close(cb?: (err?: Error) => void): unknown;
|
|
1029
|
+
}
|
|
1030
|
+
/** What can start a listener. Express's app satisfies it. */
|
|
1031
|
+
interface ListenableApp {
|
|
1032
|
+
listen(port: number, cb: () => void): ListenerLike;
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Load a peer dependency, or fail with a message that says what to install.
|
|
1036
|
+
*
|
|
1037
|
+
* The error is the point. A bare `Cannot find module 'express'` reaches a consumer who did not
|
|
1038
|
+
* write the import and cannot tell whether the package is broken or a step is missing.
|
|
1039
|
+
*/
|
|
1040
|
+
declare function loadPeer<T>(load: () => Promise<unknown>, onMissing: () => never): Promise<T>;
|
|
1041
|
+
/**
|
|
1042
|
+
* Middleware that captures the RAW request body before anything parses it.
|
|
1043
|
+
*
|
|
1044
|
+
* Every provider signs the exact bytes, so a body that was parsed and re-serialised hashes
|
|
1045
|
+
* differently and fails verification for a correct request. The bytes are attached as `rawBody`.
|
|
1046
|
+
*
|
|
1047
|
+
* @param tag the package name for the diagnostic, so a reader knows which router is complaining
|
|
1048
|
+
*/
|
|
1049
|
+
declare function rawBodyCapture(tag: string): (rawReq: unknown, _res: unknown, next: (err?: unknown) => void) => void;
|
|
1050
|
+
/**
|
|
1051
|
+
* The start/stop pair, with the latches that make a restart a restart.
|
|
1052
|
+
*
|
|
1053
|
+
* Both flags used to be write-once, in both packages. After a `stop()`, `start()` hit `if (started)`
|
|
1054
|
+
* and returned without creating a listener — the server was silently dead — and the next `stop()`
|
|
1055
|
+
* was a no-op for the same reason, in the other direction. Anything that restarts a gateway hit it:
|
|
1056
|
+
* a config reload, a reconnect after a network fault, a supervisor cycling a process in-band.
|
|
1057
|
+
*
|
|
1058
|
+
* `injected` is for the case where the caller owns the app: there is no listener to open or close,
|
|
1059
|
+
* and `start()`/`stop()` must still be callable and idempotent.
|
|
1060
|
+
*/
|
|
1061
|
+
declare function listenerLifecycle(opts: {
|
|
1062
|
+
readonly app: ListenableApp;
|
|
1063
|
+
readonly port: number;
|
|
1064
|
+
readonly injected: boolean;
|
|
1065
|
+
}): {
|
|
1066
|
+
start(): Promise<void>;
|
|
1067
|
+
stop(): Promise<void>;
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
export { type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, CREDENTIAL_SHAPES, type ChunkByGraphemeOptions, type ChunkTextOptions, type CoveredShape, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type EmailMessageEvent, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type HookDecision, HookExecutor, type HookName, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MessageEvent, type OnErrorContext, type OutboundMessage, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type RawBodyRequest, type SMSMessageEvent, type SendResult, SessionRouter, type SlackMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type UncoveredShape, type WhatsAppMessageEvent, chunkByGrapheme, chunkText, defaultStrategy, listenerLifecycle, loadPeer, maskShapes, rawBodyCapture, redactSecrets, toDialect };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,30 @@ import { Security } from '@theokit/sdk';
|
|
|
2
2
|
|
|
3
3
|
// src/adapter/base.ts
|
|
4
4
|
var BasePlatformAdapter = class {
|
|
5
|
+
/**
|
|
6
|
+
* Run a subscribed handler and contain its failure. The body of {@link deliver}, written once.
|
|
7
|
+
*
|
|
8
|
+
* A handler is USER code and may throw. An adapter must contain that throw, name it as the
|
|
9
|
+
* handler's failure rather than the platform's, and keep delivering — one bad message ends
|
|
10
|
+
* neither the process nor the connection. Two adapters once discarded the rejection with `void`,
|
|
11
|
+
* which under Node's default ends the process; two more reported it as a platform-client error,
|
|
12
|
+
* sending whoever debugged their own handler to the wrong repository (#41).
|
|
13
|
+
*
|
|
14
|
+
* Ten copies of that knowledge is ten chances to get it wrong, so it lives here. The platform tag
|
|
15
|
+
* is taken from `this.platform`, which is the only part that differed between them.
|
|
16
|
+
*/
|
|
17
|
+
async runHandler(handler, event) {
|
|
18
|
+
if (handler === void 0) return "no_handler";
|
|
19
|
+
try {
|
|
20
|
+
await handler(event);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
23
|
+
process.stderr.write(`[${this.platform}] handler threw: ${message}
|
|
24
|
+
`);
|
|
25
|
+
return "handler_threw";
|
|
26
|
+
}
|
|
27
|
+
return "ok";
|
|
28
|
+
}
|
|
5
29
|
/** Lifecycle: emit a typing indicator. Default: noop. */
|
|
6
30
|
async startTyping(_channelId) {
|
|
7
31
|
}
|
|
@@ -129,9 +153,44 @@ function redactSecrets(value) {
|
|
|
129
153
|
}
|
|
130
154
|
|
|
131
155
|
// src/hooks/executor.ts
|
|
156
|
+
var HOOK_PHASES = ["pre_inbound", "post_outbound", "on_error"];
|
|
157
|
+
function malformedHook(index, why) {
|
|
158
|
+
return new GatewayConfigurationError("gateway", {
|
|
159
|
+
code: "malformed_hook",
|
|
160
|
+
message: `gateway: hooks[${index}] ${why}`,
|
|
161
|
+
detail: `hooks[${index}]`
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function assertHook(entry, index) {
|
|
165
|
+
if (typeof entry !== "object" || entry === null) {
|
|
166
|
+
throw malformedHook(index, `is ${entry === null ? "null" : typeof entry}, not a hook object`);
|
|
167
|
+
}
|
|
168
|
+
const hook = entry;
|
|
169
|
+
if (typeof hook.name !== "string" || hook.name.length === 0) {
|
|
170
|
+
throw malformedHook(
|
|
171
|
+
index,
|
|
172
|
+
"has no name \u2014 every hook is named so a log can say which one acted"
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const declared = HOOK_PHASES.filter((phase) => hook[phase] !== void 0);
|
|
176
|
+
if (declared.length === 0) {
|
|
177
|
+
throw malformedHook(
|
|
178
|
+
index,
|
|
179
|
+
`("${hook.name}") declares none of ${HOOK_PHASES.join(", ")} \u2014 it would never run`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
for (const phase of declared) {
|
|
183
|
+
if (typeof hook[phase] !== "function") {
|
|
184
|
+
throw malformedHook(index, `("${hook.name}") declares ${phase}, which is not callable`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
132
188
|
var HookExecutor = class {
|
|
133
189
|
constructor(hooks) {
|
|
134
190
|
this.hooks = hooks;
|
|
191
|
+
hooks.forEach((hook, index) => {
|
|
192
|
+
assertHook(hook, index);
|
|
193
|
+
});
|
|
135
194
|
}
|
|
136
195
|
hooks;
|
|
137
196
|
/**
|
|
@@ -287,6 +346,15 @@ var GatewayRunner = class {
|
|
|
287
346
|
);
|
|
288
347
|
this.connected = false;
|
|
289
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* @internal Test seam, following `EmailAdapter._threadStoreSize`. The drain set must SHRINK: a
|
|
351
|
+
* settled dispatch that is never removed is a leak that grows for the life of the process, and it
|
|
352
|
+
* is invisible from the outside — `stop()` drains correctly either way, because settled promises
|
|
353
|
+
* resolve immediately whether or not anyone deleted them.
|
|
354
|
+
*/
|
|
355
|
+
get _inflightSize() {
|
|
356
|
+
return this.inflight.size;
|
|
357
|
+
}
|
|
290
358
|
/** @internal */
|
|
291
359
|
async dispatch(event) {
|
|
292
360
|
const ctx = this.buildContext(event);
|
|
@@ -477,6 +545,102 @@ function chunkByGrapheme(text, options) {
|
|
|
477
545
|
return parts;
|
|
478
546
|
}
|
|
479
547
|
|
|
480
|
-
|
|
548
|
+
// src/text/dialect.ts
|
|
549
|
+
var DIALECTS = {
|
|
550
|
+
// WhatsApp emphasis is inline and single-character: *bold*, _italic_, ~strike~, ```mono```.
|
|
551
|
+
whatsapp: { bold: "*", italic: "_", strike: "~", code: "```" },
|
|
552
|
+
// LINE text messages carry no rich text at all — decoration is emoji-only. Markers are dropped.
|
|
553
|
+
line: {},
|
|
554
|
+
// SMS is plain text by definition of the medium.
|
|
555
|
+
sms: {}
|
|
556
|
+
};
|
|
557
|
+
var PATTERN = /\*\*(?<bold>.+?)\*\*|~~(?<strike>.+?)~~|(?<![*\w])\*(?!\s)(?<italicStar>.+?)(?<!\s)\*(?!\*)|(?<![_\w])_(?!\s)(?<italicUnderscore>.+?)(?<!\s)_(?!\w)|`(?<code>.+?)`/gu;
|
|
558
|
+
var GROUP_MARKERS = [
|
|
559
|
+
["bold", "bold"],
|
|
560
|
+
["strike", "strike"],
|
|
561
|
+
["italicStar", "italic"],
|
|
562
|
+
["italicUnderscore", "italic"],
|
|
563
|
+
["code", "code"]
|
|
564
|
+
];
|
|
565
|
+
function toDialect(text, platform) {
|
|
566
|
+
const dialect = DIALECTS[platform];
|
|
567
|
+
if (dialect === void 0) return text;
|
|
568
|
+
return text.replace(PATTERN, (matched, ...args) => {
|
|
569
|
+
const groups = args.at(-1);
|
|
570
|
+
if (groups === void 0) return matched;
|
|
571
|
+
for (const [group, marker] of GROUP_MARKERS) {
|
|
572
|
+
const content = groups[group];
|
|
573
|
+
if (content === void 0) continue;
|
|
574
|
+
const wrap = dialect[marker];
|
|
575
|
+
return wrap === void 0 ? content : `${wrap}${content}${wrap}`;
|
|
576
|
+
}
|
|
577
|
+
return matched;
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// src/webhook/express-server.ts
|
|
582
|
+
async function loadPeer(load, onMissing) {
|
|
583
|
+
try {
|
|
584
|
+
const mod = await load();
|
|
585
|
+
return mod.default ?? mod;
|
|
586
|
+
} catch {
|
|
587
|
+
onMissing();
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function rawBodyCapture(tag) {
|
|
591
|
+
return (rawReq, _res, next) => {
|
|
592
|
+
const req = rawReq;
|
|
593
|
+
if (req.readableEnded === true || req.complete === true) {
|
|
594
|
+
process.stderr.write(
|
|
595
|
+
`[${tag}] raw body already consumed before signature capture \u2014 mount this router BEFORE any global body parser, or signature verification cannot see the bytes it must hash
|
|
596
|
+
`
|
|
597
|
+
);
|
|
598
|
+
req.rawBody = "";
|
|
599
|
+
next();
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
let buf = "";
|
|
603
|
+
req.setEncoding("utf8");
|
|
604
|
+
req.on("data", (chunk) => {
|
|
605
|
+
buf += chunk;
|
|
606
|
+
});
|
|
607
|
+
req.on("end", () => {
|
|
608
|
+
req.rawBody = buf;
|
|
609
|
+
next();
|
|
610
|
+
});
|
|
611
|
+
req.on("error", (err) => next(err));
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
function listenerLifecycle(opts) {
|
|
615
|
+
let started = false;
|
|
616
|
+
let stopped = false;
|
|
617
|
+
let listener;
|
|
618
|
+
return {
|
|
619
|
+
async start() {
|
|
620
|
+
if (started || opts.injected) {
|
|
621
|
+
started = true;
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
stopped = false;
|
|
625
|
+
await new Promise((resolve) => {
|
|
626
|
+
listener = opts.app.listen(opts.port, () => resolve());
|
|
627
|
+
});
|
|
628
|
+
started = true;
|
|
629
|
+
},
|
|
630
|
+
async stop() {
|
|
631
|
+
if (stopped) return;
|
|
632
|
+
stopped = true;
|
|
633
|
+
started = false;
|
|
634
|
+
const current = listener;
|
|
635
|
+
listener = void 0;
|
|
636
|
+
if (current === void 0) return;
|
|
637
|
+
await new Promise((resolve) => {
|
|
638
|
+
current.close(() => resolve());
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export { BasePlatformAdapter, CREDENTIAL_SHAPES, DeliveryRouter, GatewayConfigurationError, GatewayLifecycleError, GatewayRunner, HookExecutor, SessionRouter, chunkByGrapheme, chunkText, defaultStrategy, listenerLifecycle, loadPeer, maskShapes, rawBodyCapture, redactSecrets, toDialect };
|
|
481
645
|
//# sourceMappingURL=index.js.map
|
|
482
646
|
//# sourceMappingURL=index.js.map
|