@desplega.ai/slack-mock 0.5.0 → 0.6.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/README.md CHANGED
@@ -89,6 +89,34 @@ What tests can do:
89
89
  The same operations exist over HTTP under `/mock/*` for use from another
90
90
  process (see `docs/design.md`).
91
91
 
92
+ ## HTTP mode (signed requests)
93
+
94
+ For apps that take Slack's HTTP transport, the mock can post deliveries to request URLs instead of
95
+ pushing them over a WebSocket. Every request carries `X-Slack-Request-Timestamp` and an
96
+ `X-Slack-Signature` (`v0=` HMAC-SHA256 of `v0:<timestamp>:<raw body>`) made with the signing secret
97
+ you give it.
98
+
99
+ ```bash
100
+ slack-mock serve --http-events-url http://127.0.0.1:3013/slack/events --signing-secret "$SLACK_SIGNING_SECRET" \
101
+ [--http-interactivity-url URL] [--http-commands-url URL] [--http-retry-delays-ms 1000,5000,30000]
102
+ ```
103
+
104
+ ```ts
105
+ const slack = await SlackMock.start({
106
+ httpDelivery: { eventsUrl, signingSecret, interactivityUrl, commandsUrl, retryDelaysMs: [1000, 5000], timeoutMs: 3000 },
107
+ });
108
+ ```
109
+
110
+ | Delivery | Request |
111
+ |---|---|
112
+ | Events API | JSON body (the `event_callback` payload). Redelivered on a non-2xx, a timeout (`timeoutMs`, default 3s) or a refused connection, with `X-Slack-Retry-Num` and `X-Slack-Retry-Reason` (`http_error`, `http_timeout`, `connection_failed`), after each `retryDelaysMs` entry (default 1 min, 5 min, 30 min). |
113
+ | Slash commands | Form-encoded fields. Posted once. A JSON response body is the ack payload. |
114
+ | Interactivity | Form with one `payload` field. Posted once. A JSON response body is the ack payload. |
115
+
116
+ Interactivity and slash commands go to `eventsUrl` unless their own URL is set. `deliveries()` lists every
117
+ request with its attempts and ack status. `new HttpDelivery(...).verifyUrl()` runs the `url_verification`
118
+ challenge. Socket Mode stays the default; with `httpDelivery` set no app connection is needed.
119
+
92
120
  ## Frames from a journal
93
121
 
94
122
  A run recorded with `dataFile` can be replayed into one PNG per event that touched a
@@ -142,7 +170,13 @@ Stitch the PNGs into a GIF with ffmpeg if you want motion; the mock only produce
142
170
  push), assistant.threads (status, title, prompts), agents.sessions.setStatus,
143
171
  pins, bots, team.
144
172
  - UI: Block Kit `markdown` blocks render as Markdown (headings, bold, italic,
145
- strike, links, lists, code); unknown blocks show a gray `unsupported: <type>` box.
173
+ strike, links, lists, code); `table` and `data_table` render as tables
174
+ (`column_settings` alignment, `data_table` pages at `page_size`, default 5);
175
+ `data_visualization` renders pie, bar, line and area charts as SVG. Their
176
+ documented limits (rows, cells, caption, 2 charts per message, chart labels
177
+ matching `axis_config.categories`) reject with `invalid_blocks` on
178
+ `chat.postMessage` and `chat.update`. Unknown blocks show a gray
179
+ `unsupported: <type>` box.
146
180
  Errors come back as `{ ok: false, error }` with the real codes
147
181
  (`not_in_channel`, `already_reacted`, `message_not_found`, `name_taken`,
148
182
  `expired_trigger_id`, `message_not_in_streaming_state`, ...).
@@ -0,0 +1,2 @@
1
+ /** Throws `invalid_blocks` the way Slack does when a message's blocks break a limit. */
2
+ export declare function validateBlocks(blocks: unknown[] | undefined): void;
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  SlackMock2,
5
5
  frames2
6
- } from "./index-z58p5wkc.js";
6
+ } from "./index-5hsxaq74.js";
7
7
  import {
8
8
  screenshot2
9
9
  } from "./index-xs37gskt.js";
@@ -15,6 +15,8 @@ var USAGE = `slack-mock: a mock Slack server (Web API + Socket Mode) for testing
15
15
  Usage:
16
16
  slack-mock serve [--port 4040] [--host 127.0.0.1] [--data ./data/slack.jsonl] [--manifest app.json]
17
17
  [--no-seed] [--quiet] [--panel 50] [--auth user:pass] [--public-url https://mock.example.com]
18
+ [--http-events-url URL --signing-secret SECRET [--http-interactivity-url URL]
19
+ [--http-commands-url URL] [--http-retry-delays-ms 1000,5000,30000]]
18
20
  slack-mock screenshot <url> --out shot.png [--width 800] [--height 1000]
19
21
  slack-mock frames --journal data.jsonl --channel C0GENERAL0 [--thread 1788516626.286000] --out ./frames
20
22
  [--manifest app.json] [--width 800] [--height 700] [--no-desktop]
@@ -41,10 +43,25 @@ async function main(argv) {
41
43
  quiet: { type: "boolean", default: false },
42
44
  panel: { type: "string" },
43
45
  auth: { type: "string" },
44
- "public-url": { type: "string" }
46
+ "public-url": { type: "string" },
47
+ "http-events-url": { type: "string" },
48
+ "http-interactivity-url": { type: "string" },
49
+ "http-commands-url": { type: "string" },
50
+ "http-retry-delays-ms": { type: "string" },
51
+ "signing-secret": { type: "string" }
45
52
  }
46
53
  });
54
+ const eventsUrl = values["http-events-url"];
55
+ if (eventsUrl && !values["signing-secret"])
56
+ throw new Error("--http-events-url needs --signing-secret");
47
57
  const mock = await SlackMock2.start({
58
+ httpDelivery: eventsUrl ? {
59
+ eventsUrl,
60
+ interactivityUrl: values["http-interactivity-url"],
61
+ commandsUrl: values["http-commands-url"],
62
+ signingSecret: values["signing-secret"],
63
+ retryDelaysMs: values["http-retry-delays-ms"] ? values["http-retry-delays-ms"].split(",").map(Number) : undefined
64
+ } : undefined,
48
65
  panelWidth: values.panel,
49
66
  adminAuth: values.auth,
50
67
  publicUrl: values["public-url"],
@@ -0,0 +1,61 @@
1
+ import { type AckResult, type DeliveryRecord, type EnvelopeType } from "./socket-mode.ts";
2
+ export interface HttpDeliveryOptions {
3
+ /** Events API "Request URL". Receives `events_api` payloads as signed JSON. */
4
+ eventsUrl: string;
5
+ /** Interactivity "Request URL" (block_actions, view_submission). Default: `eventsUrl`. */
6
+ interactivityUrl?: string;
7
+ /** Slash command "Request URL". Default: `eventsUrl`. */
8
+ commandsUrl?: string;
9
+ /** The app's signing secret. Every request is signed with it, like Slack. */
10
+ signingSecret: string;
11
+ /** Wait before each Events API redelivery (Slack: about 1 minute, 5 minutes, 30 minutes). */
12
+ retryDelaysMs?: number[];
13
+ /** How long to wait for the HTTP response before counting a timeout (Slack: 3s). */
14
+ timeoutMs?: number;
15
+ log?: (msg: string) => void;
16
+ }
17
+ /** `v0=` + hex HMAC-SHA256 of `v0:<timestamp>:<raw body>`, the `X-Slack-Signature` value. */
18
+ export declare function slackSignature(secret: string, timestamp: string | number, body: string): string;
19
+ export declare class HttpDeliveryError extends Error {
20
+ }
21
+ /** Thrown by a delivery cut short by `shutdown()`; the mock treats it as a clean stop. */
22
+ export declare class HttpDeliveryStoppedError extends HttpDeliveryError {
23
+ constructor();
24
+ }
25
+ /**
26
+ * The HTTP side of the mock: the same deliveries as Socket Mode, posted to the
27
+ * app's request URLs and signed with its signing secret. Events API requests are
28
+ * redelivered with `X-Slack-Retry-Num` / `X-Slack-Retry-Reason` when the app does
29
+ * not answer 2xx in time; slash commands and interactivity are posted once, as
30
+ * Slack does, and the response body is the ack payload.
31
+ */
32
+ export declare class HttpDelivery {
33
+ /** Every request sent, in order, with its ack status. */
34
+ readonly history: DeliveryRecord[];
35
+ readonly opts: Required<Omit<HttpDeliveryOptions, "log" | "interactivityUrl" | "commandsUrl">> & {
36
+ interactivityUrl: string;
37
+ commandsUrl: string;
38
+ log: (msg: string) => void;
39
+ };
40
+ private readonly stopController;
41
+ private retryTimers;
42
+ constructor(opts: HttpDeliveryOptions);
43
+ /**
44
+ * Cancel everything pending: abort in-flight requests, wake every retry wait so its
45
+ * `send` rejects with `HttpDeliveryStoppedError`, and refuse new requests.
46
+ */
47
+ shutdown(): void;
48
+ private get stopped();
49
+ /** Wait `ms` before a redelivery; `shutdown()` ends the wait early. */
50
+ private waitToRetry;
51
+ /** An HTTP app is always "connected": nothing to wait for. */
52
+ get connectionCount(): number;
53
+ waitForConnection(): Promise<void>;
54
+ /** Slack's URL verification: POST a `url_verification` challenge and expect it echoed back. */
55
+ verifyUrl(): Promise<boolean>;
56
+ send(type: EnvelopeType, payload: unknown, _acceptsResponsePayload?: boolean): Promise<AckResult>;
57
+ private retryHeaders;
58
+ /** Events go as JSON; slash commands as a form; interactivity as a form with one `payload` field. */
59
+ private encode;
60
+ private post;
61
+ }