@walkeros/server-destination-slack 3.3.0-next-1776098542393

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.
@@ -0,0 +1,113 @@
1
+ import { DestinationServer, sendServer } from '@walkeros/server-core';
2
+ import { ChatPostMessageArguments, ChatPostMessageResponse, ChatPostEphemeralArguments, ChatPostEphemeralResponse, ConversationsOpenArguments, ConversationsOpenResponse, WebClient } from '@slack/web-api';
3
+ import { Flow } from '@walkeros/core';
4
+
5
+ /** A single Block Kit block (kept loose -- Slack does not export a union type). */
6
+ type SlackBlock = Record<string, unknown>;
7
+ interface Settings {
8
+ /** Slack Bot token (xoxb-...). Enables Web API mode. */
9
+ token?: string;
10
+ /** Incoming Webhook URL. Enables webhook mode. */
11
+ webhookUrl?: string;
12
+ /** Default channel ID or name. Required for Web API mode unless every rule provides one. */
13
+ channel?: string;
14
+ /** Default text template. Supports `${data.field}` interpolation against the walkerOS event. */
15
+ text?: string;
16
+ /** Default Block Kit blocks applied when no mapping override is set. */
17
+ blocks?: SlackBlock[];
18
+ /** Auto-add an event-name header block when generating default blocks. Default: true. */
19
+ includeHeader?: boolean;
20
+ /** Enable link unfurling. Default: false. */
21
+ unfurlLinks?: boolean;
22
+ /** Enable media unfurling. Default: false. */
23
+ unfurlMedia?: boolean;
24
+ /** Use mrkdwn formatting. Default: true. */
25
+ mrkdwn?: boolean;
26
+ /** Static thread_ts to reply to (rarely set at destination level). */
27
+ threadTs?: string;
28
+ /** Retry policy passed to WebClient. Default: 'default'. */
29
+ retryConfig?: 'default' | 'fiveRetriesInFiveMinutes' | 'none';
30
+ _client?: WebClient;
31
+ }
32
+ /**
33
+ * Mock-friendly interface for the WebClient methods the destination calls.
34
+ * Tests inject this via env.slackClient.
35
+ */
36
+ interface SlackClientMock {
37
+ chat: {
38
+ postMessage: (opts: ChatPostMessageArguments) => Promise<ChatPostMessageResponse>;
39
+ postEphemeral: (opts: ChatPostEphemeralArguments) => Promise<ChatPostEphemeralResponse>;
40
+ };
41
+ conversations: {
42
+ open: (opts: ConversationsOpenArguments) => Promise<ConversationsOpenResponse>;
43
+ };
44
+ }
45
+ /**
46
+ * Env -- optional SDK / transport overrides. Production leaves these undefined.
47
+ * Tests inject `slackClient` (Web API mode) and/or `sendServer` (webhook mode).
48
+ */
49
+ interface Env extends DestinationServer.Env {
50
+ slackClient?: SlackClientMock;
51
+ sendServer?: typeof sendServer;
52
+ }
53
+
54
+ declare const push: Env;
55
+ declare const simulation: string[];
56
+
57
+ declare const env_push: typeof push;
58
+ declare const env_simulation: typeof simulation;
59
+ declare namespace env {
60
+ export { env_push as push, env_simulation as simulation };
61
+ }
62
+
63
+ /**
64
+ * Extended step example that may carry destination-level settings overrides.
65
+ */
66
+ type SlackStepExample = Flow.StepExample & {
67
+ settings?: Partial<Settings>;
68
+ };
69
+ /**
70
+ * Purchase notification -- Web API mode, channel from mapping override,
71
+ * text template interpolated against event.data.
72
+ */
73
+ declare const purchaseAlert: SlackStepExample;
74
+ /**
75
+ * Error alert -- routes to a different channel via mapping override.
76
+ */
77
+ declare const errorAlert: SlackStepExample;
78
+ /**
79
+ * Welcome DM -- conversations.open(users) -> chat.postMessage(channel: D-id).
80
+ */
81
+ declare const welcomeDM: SlackStepExample;
82
+ /**
83
+ * Threaded checkout step -- thread_ts override puts the reply into a thread.
84
+ */
85
+ declare const threadedCheckoutStep: SlackStepExample;
86
+ /**
87
+ * Ephemeral message -- visible to one user in the target channel.
88
+ */
89
+ declare const ephemeralMessage: SlackStepExample;
90
+ /**
91
+ * Default blocks -- no custom text/blocks, destination auto-generates a
92
+ * Block Kit message from the event data.
93
+ */
94
+ declare const defaultBlocks: SlackStepExample;
95
+ /**
96
+ * Webhook mode -- no token, just webhookUrl. The destination calls sendServer
97
+ * with the JSON body. Channel is baked into the URL by Slack.
98
+ */
99
+ declare const deployNotification: SlackStepExample;
100
+
101
+ type step_SlackStepExample = SlackStepExample;
102
+ declare const step_defaultBlocks: typeof defaultBlocks;
103
+ declare const step_deployNotification: typeof deployNotification;
104
+ declare const step_ephemeralMessage: typeof ephemeralMessage;
105
+ declare const step_errorAlert: typeof errorAlert;
106
+ declare const step_purchaseAlert: typeof purchaseAlert;
107
+ declare const step_threadedCheckoutStep: typeof threadedCheckoutStep;
108
+ declare const step_welcomeDM: typeof welcomeDM;
109
+ declare namespace step {
110
+ export { type step_SlackStepExample as SlackStepExample, step_defaultBlocks as defaultBlocks, step_deployNotification as deployNotification, step_ephemeralMessage as ephemeralMessage, step_errorAlert as errorAlert, step_purchaseAlert as purchaseAlert, step_threadedCheckoutStep as threadedCheckoutStep, step_welcomeDM as welcomeDM };
111
+ }
112
+
113
+ export { env, step };
@@ -0,0 +1,113 @@
1
+ import { DestinationServer, sendServer } from '@walkeros/server-core';
2
+ import { ChatPostMessageArguments, ChatPostMessageResponse, ChatPostEphemeralArguments, ChatPostEphemeralResponse, ConversationsOpenArguments, ConversationsOpenResponse, WebClient } from '@slack/web-api';
3
+ import { Flow } from '@walkeros/core';
4
+
5
+ /** A single Block Kit block (kept loose -- Slack does not export a union type). */
6
+ type SlackBlock = Record<string, unknown>;
7
+ interface Settings {
8
+ /** Slack Bot token (xoxb-...). Enables Web API mode. */
9
+ token?: string;
10
+ /** Incoming Webhook URL. Enables webhook mode. */
11
+ webhookUrl?: string;
12
+ /** Default channel ID or name. Required for Web API mode unless every rule provides one. */
13
+ channel?: string;
14
+ /** Default text template. Supports `${data.field}` interpolation against the walkerOS event. */
15
+ text?: string;
16
+ /** Default Block Kit blocks applied when no mapping override is set. */
17
+ blocks?: SlackBlock[];
18
+ /** Auto-add an event-name header block when generating default blocks. Default: true. */
19
+ includeHeader?: boolean;
20
+ /** Enable link unfurling. Default: false. */
21
+ unfurlLinks?: boolean;
22
+ /** Enable media unfurling. Default: false. */
23
+ unfurlMedia?: boolean;
24
+ /** Use mrkdwn formatting. Default: true. */
25
+ mrkdwn?: boolean;
26
+ /** Static thread_ts to reply to (rarely set at destination level). */
27
+ threadTs?: string;
28
+ /** Retry policy passed to WebClient. Default: 'default'. */
29
+ retryConfig?: 'default' | 'fiveRetriesInFiveMinutes' | 'none';
30
+ _client?: WebClient;
31
+ }
32
+ /**
33
+ * Mock-friendly interface for the WebClient methods the destination calls.
34
+ * Tests inject this via env.slackClient.
35
+ */
36
+ interface SlackClientMock {
37
+ chat: {
38
+ postMessage: (opts: ChatPostMessageArguments) => Promise<ChatPostMessageResponse>;
39
+ postEphemeral: (opts: ChatPostEphemeralArguments) => Promise<ChatPostEphemeralResponse>;
40
+ };
41
+ conversations: {
42
+ open: (opts: ConversationsOpenArguments) => Promise<ConversationsOpenResponse>;
43
+ };
44
+ }
45
+ /**
46
+ * Env -- optional SDK / transport overrides. Production leaves these undefined.
47
+ * Tests inject `slackClient` (Web API mode) and/or `sendServer` (webhook mode).
48
+ */
49
+ interface Env extends DestinationServer.Env {
50
+ slackClient?: SlackClientMock;
51
+ sendServer?: typeof sendServer;
52
+ }
53
+
54
+ declare const push: Env;
55
+ declare const simulation: string[];
56
+
57
+ declare const env_push: typeof push;
58
+ declare const env_simulation: typeof simulation;
59
+ declare namespace env {
60
+ export { env_push as push, env_simulation as simulation };
61
+ }
62
+
63
+ /**
64
+ * Extended step example that may carry destination-level settings overrides.
65
+ */
66
+ type SlackStepExample = Flow.StepExample & {
67
+ settings?: Partial<Settings>;
68
+ };
69
+ /**
70
+ * Purchase notification -- Web API mode, channel from mapping override,
71
+ * text template interpolated against event.data.
72
+ */
73
+ declare const purchaseAlert: SlackStepExample;
74
+ /**
75
+ * Error alert -- routes to a different channel via mapping override.
76
+ */
77
+ declare const errorAlert: SlackStepExample;
78
+ /**
79
+ * Welcome DM -- conversations.open(users) -> chat.postMessage(channel: D-id).
80
+ */
81
+ declare const welcomeDM: SlackStepExample;
82
+ /**
83
+ * Threaded checkout step -- thread_ts override puts the reply into a thread.
84
+ */
85
+ declare const threadedCheckoutStep: SlackStepExample;
86
+ /**
87
+ * Ephemeral message -- visible to one user in the target channel.
88
+ */
89
+ declare const ephemeralMessage: SlackStepExample;
90
+ /**
91
+ * Default blocks -- no custom text/blocks, destination auto-generates a
92
+ * Block Kit message from the event data.
93
+ */
94
+ declare const defaultBlocks: SlackStepExample;
95
+ /**
96
+ * Webhook mode -- no token, just webhookUrl. The destination calls sendServer
97
+ * with the JSON body. Channel is baked into the URL by Slack.
98
+ */
99
+ declare const deployNotification: SlackStepExample;
100
+
101
+ type step_SlackStepExample = SlackStepExample;
102
+ declare const step_defaultBlocks: typeof defaultBlocks;
103
+ declare const step_deployNotification: typeof deployNotification;
104
+ declare const step_ephemeralMessage: typeof ephemeralMessage;
105
+ declare const step_errorAlert: typeof errorAlert;
106
+ declare const step_purchaseAlert: typeof purchaseAlert;
107
+ declare const step_threadedCheckoutStep: typeof threadedCheckoutStep;
108
+ declare const step_welcomeDM: typeof welcomeDM;
109
+ declare namespace step {
110
+ export { type step_SlackStepExample as SlackStepExample, step_defaultBlocks as defaultBlocks, step_deployNotification as deployNotification, step_ephemeralMessage as ephemeralMessage, step_errorAlert as errorAlert, step_purchaseAlert as purchaseAlert, step_threadedCheckoutStep as threadedCheckoutStep, step_welcomeDM as welcomeDM };
111
+ }
112
+
113
+ export { env, step };
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/examples/index.ts
21
+ var examples_exports = {};
22
+ __export(examples_exports, {
23
+ env: () => env_exports,
24
+ step: () => step_exports
25
+ });
26
+ module.exports = __toCommonJS(examples_exports);
27
+
28
+ // src/examples/env.ts
29
+ var env_exports = {};
30
+ __export(env_exports, {
31
+ push: () => push,
32
+ simulation: () => simulation
33
+ });
34
+ var okMessageResponse = {
35
+ ok: true,
36
+ channel: "CMOCK",
37
+ ts: "1700000000.000100"
38
+ };
39
+ var okEphemeralResponse = { ok: true };
40
+ var okOpenResponse = {
41
+ ok: true,
42
+ channel: { id: "D-MOCK-DM" }
43
+ };
44
+ function createMockClient() {
45
+ return {
46
+ chat: {
47
+ postMessage: () => Promise.resolve(okMessageResponse),
48
+ postEphemeral: () => Promise.resolve(okEphemeralResponse)
49
+ },
50
+ conversations: {
51
+ open: () => Promise.resolve(okOpenResponse)
52
+ }
53
+ };
54
+ }
55
+ var push = {
56
+ slackClient: createMockClient(),
57
+ sendServer: (() => Promise.resolve({ ok: true }))
58
+ };
59
+ var simulation = [
60
+ "call:slackClient.chat.postMessage",
61
+ "call:slackClient.chat.postEphemeral",
62
+ "call:slackClient.conversations.open",
63
+ "call:sendServer"
64
+ ];
65
+
66
+ // src/examples/step.ts
67
+ var step_exports = {};
68
+ __export(step_exports, {
69
+ defaultBlocks: () => defaultBlocks,
70
+ deployNotification: () => deployNotification,
71
+ ephemeralMessage: () => ephemeralMessage,
72
+ errorAlert: () => errorAlert,
73
+ purchaseAlert: () => purchaseAlert,
74
+ threadedCheckoutStep: () => threadedCheckoutStep,
75
+ welcomeDM: () => welcomeDM
76
+ });
77
+ var import_core = require("@walkeros/core");
78
+ var purchaseAlert = {
79
+ in: (0, import_core.getEvent)("order complete", {
80
+ timestamp: 1700000100,
81
+ data: {
82
+ id: "ORD-500",
83
+ total: 299.99,
84
+ currency: "EUR",
85
+ product: "Pro Plan"
86
+ },
87
+ user: { id: "buyer-42" }
88
+ }),
89
+ mapping: {
90
+ settings: {
91
+ channel: "#sales",
92
+ text: ":moneybag: New order: ${data.id} - ${data.total} ${data.currency}"
93
+ }
94
+ },
95
+ out: [
96
+ "slackClient.chat.postMessage",
97
+ {
98
+ channel: "#sales",
99
+ text: ":moneybag: New order: ORD-500 - 299.99 EUR",
100
+ unfurl_links: false,
101
+ unfurl_media: false,
102
+ mrkdwn: true
103
+ }
104
+ ]
105
+ };
106
+ var errorAlert = {
107
+ in: (0, import_core.getEvent)("error occur", {
108
+ timestamp: 1700000200,
109
+ data: {
110
+ message: "Payment gateway timeout",
111
+ code: "PGW_TIMEOUT",
112
+ severity: "critical"
113
+ }
114
+ }),
115
+ mapping: {
116
+ settings: {
117
+ channel: "#engineering-alerts",
118
+ text: ":rotating_light: Error: ${data.message}"
119
+ }
120
+ },
121
+ out: [
122
+ "slackClient.chat.postMessage",
123
+ {
124
+ channel: "#engineering-alerts",
125
+ text: ":rotating_light: Error: Payment gateway timeout",
126
+ unfurl_links: false,
127
+ unfurl_media: false,
128
+ mrkdwn: true
129
+ }
130
+ ]
131
+ };
132
+ var welcomeDM = {
133
+ in: (0, import_core.getEvent)("user signup", {
134
+ timestamp: 1700000300,
135
+ data: { plan: "enterprise" },
136
+ user: { id: "U-NEW-USER" }
137
+ }),
138
+ mapping: {
139
+ settings: {
140
+ dm: true,
141
+ user: "U-NEW-USER",
142
+ text: ":wave: Welcome aboard! You signed up for the ${data.plan} plan."
143
+ }
144
+ },
145
+ out: [
146
+ ["slackClient.conversations.open", { users: "U-NEW-USER" }],
147
+ [
148
+ "slackClient.chat.postMessage",
149
+ {
150
+ channel: "D-MOCK-DM",
151
+ text: ":wave: Welcome aboard! You signed up for the enterprise plan.",
152
+ unfurl_links: false,
153
+ unfurl_media: false,
154
+ mrkdwn: true
155
+ }
156
+ ]
157
+ ]
158
+ };
159
+ var threadedCheckoutStep = {
160
+ in: (0, import_core.getEvent)("checkout step", {
161
+ timestamp: 1700000400,
162
+ data: { step: "payment", sessionTs: "1700000000.000050" }
163
+ }),
164
+ mapping: {
165
+ settings: {
166
+ channel: "#sales",
167
+ text: "Checkout step: ${data.step}",
168
+ threadTs: "1700000000.000050",
169
+ replyBroadcast: true
170
+ }
171
+ },
172
+ out: [
173
+ "slackClient.chat.postMessage",
174
+ {
175
+ channel: "#sales",
176
+ text: "Checkout step: payment",
177
+ thread_ts: "1700000000.000050",
178
+ reply_broadcast: true,
179
+ unfurl_links: false,
180
+ unfurl_media: false,
181
+ mrkdwn: true
182
+ }
183
+ ]
184
+ };
185
+ var ephemeralMessage = {
186
+ in: (0, import_core.getEvent)("quota warning", {
187
+ timestamp: 1700000500,
188
+ data: { remaining: 5 }
189
+ }),
190
+ mapping: {
191
+ settings: {
192
+ channel: "#admin",
193
+ ephemeral: true,
194
+ user: "U-ADMIN-1",
195
+ text: "Heads up: ${data.remaining} requests remaining"
196
+ }
197
+ },
198
+ out: [
199
+ "slackClient.chat.postEphemeral",
200
+ {
201
+ channel: "#admin",
202
+ user: "U-ADMIN-1",
203
+ text: "Heads up: 5 requests remaining",
204
+ unfurl_links: false,
205
+ unfurl_media: false,
206
+ mrkdwn: true
207
+ }
208
+ ]
209
+ };
210
+ var defaultBlocks = {
211
+ in: (0, import_core.getEvent)("lead submit", {
212
+ timestamp: 1700000600,
213
+ data: { name: "Acme", email: "sales@acme.test" },
214
+ source: { type: "server", id: "crm", previous_id: "" }
215
+ }),
216
+ mapping: {
217
+ settings: {
218
+ channel: "#growth"
219
+ }
220
+ },
221
+ out: [
222
+ "slackClient.chat.postMessage",
223
+ {
224
+ channel: "#growth",
225
+ text: "lead submit",
226
+ blocks: [
227
+ {
228
+ type: "header",
229
+ text: { type: "plain_text", text: "lead submit" }
230
+ },
231
+ {
232
+ type: "section",
233
+ fields: [
234
+ { type: "mrkdwn", text: "*name:*\nAcme" },
235
+ { type: "mrkdwn", text: "*email:*\nsales@acme.test" }
236
+ ]
237
+ },
238
+ {
239
+ type: "context",
240
+ elements: [{ type: "mrkdwn", text: "Source: crm" }]
241
+ }
242
+ ],
243
+ unfurl_links: false,
244
+ unfurl_media: false,
245
+ mrkdwn: true
246
+ }
247
+ ]
248
+ };
249
+ var deployNotification = {
250
+ in: (0, import_core.getEvent)("deploy complete", {
251
+ timestamp: 1700000700,
252
+ data: { version: "1.4.2", environment: "prod" }
253
+ }),
254
+ settings: {
255
+ token: void 0,
256
+ webhookUrl: "https://hooks.slack.com/services/T00/B00/xxx"
257
+ },
258
+ mapping: {
259
+ settings: {
260
+ text: ":rocket: Deployment complete: ${data.version} to ${data.environment}"
261
+ }
262
+ },
263
+ out: [
264
+ "sendServer",
265
+ "https://hooks.slack.com/services/T00/B00/xxx",
266
+ {
267
+ text: ":rocket: Deployment complete: 1.4.2 to prod",
268
+ unfurl_links: false,
269
+ unfurl_media: false,
270
+ mrkdwn: true
271
+ }
272
+ ]
273
+ };
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ env,
277
+ step
278
+ });