@cuylabs/channel-slack 0.1.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.
Files changed (47) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +168 -0
  3. package/dist/activity-ByrD9Ftr.d.ts +66 -0
  4. package/dist/assistant.d.ts +58 -0
  5. package/dist/assistant.js +188 -0
  6. package/dist/bolt.d.ts +344 -0
  7. package/dist/bolt.js +705 -0
  8. package/dist/chunk-BODPT4I6.js +322 -0
  9. package/dist/chunk-FPCE5V5Y.js +292 -0
  10. package/dist/chunk-FX2JOVX5.js +405 -0
  11. package/dist/chunk-JZG4IETE.js +141 -0
  12. package/dist/chunk-NE57BLLU.js +0 -0
  13. package/dist/chunk-TWJGVDA2.js +108 -0
  14. package/dist/core.d.ts +425 -0
  15. package/dist/core.js +42 -0
  16. package/dist/diagnostics.d.ts +105 -0
  17. package/dist/diagnostics.js +8 -0
  18. package/dist/feedback.d.ts +137 -0
  19. package/dist/feedback.js +128 -0
  20. package/dist/history.d.ts +266 -0
  21. package/dist/history.js +747 -0
  22. package/dist/index.d.ts +4 -0
  23. package/dist/index.js +57 -0
  24. package/dist/logging-Bl3HfcC8.d.ts +8 -0
  25. package/dist/policy.d.ts +130 -0
  26. package/dist/policy.js +16 -0
  27. package/dist/setup.d.ts +165 -0
  28. package/dist/setup.js +453 -0
  29. package/dist/shared.d.ts +2 -0
  30. package/dist/shared.js +43 -0
  31. package/dist/targets.d.ts +113 -0
  32. package/dist/targets.js +484 -0
  33. package/dist/users.d.ts +109 -0
  34. package/dist/users.js +240 -0
  35. package/docs/concepts/activity.md +33 -0
  36. package/docs/concepts/bolt-runtime.md +30 -0
  37. package/docs/concepts/message-policy.md +49 -0
  38. package/docs/concepts/setup-requirements.md +44 -0
  39. package/docs/concepts/supplemental-history.md +55 -0
  40. package/docs/recipes/app-mention-handler.md +34 -0
  41. package/docs/recipes/assistant-thread-handler.md +28 -0
  42. package/docs/recipes/generate-slack-manifest.md +28 -0
  43. package/docs/recipes/history-visibility.md +36 -0
  44. package/docs/recipes/socket-mode-app.md +29 -0
  45. package/docs/reference/channel-slack-boundary.md +50 -0
  46. package/docs/reference/exports.md +32 -0
  47. package/package.json +130 -0
package/dist/bolt.d.ts ADDED
@@ -0,0 +1,344 @@
1
+ import { Application } from 'express';
2
+ import { AppOptions, ExpressReceiverOptions, App, ExpressReceiver, SocketModeReceiverOptions } from '@slack/bolt';
3
+ import { IncomingMessage, ServerResponse } from 'node:http';
4
+ import { L as Logger } from './logging-Bl3HfcC8.js';
5
+
6
+ /**
7
+ * OAuth and installation type declarations for the direct Slack adapter.
8
+ *
9
+ * Pure types — no runtime imports beyond `node:http` request/response.
10
+ * Mirrors the public surface of `@slack/oauth` enough that callers can
11
+ * implement custom installation/state stores without depending on Bolt's
12
+ * internal types.
13
+ */
14
+
15
+ type SlackDirectAuthMode = "single-workspace" | "oauth" | "authorize";
16
+ interface SlackOAuthError extends Error {
17
+ code: string;
18
+ }
19
+ interface SlackInstallURLOptions {
20
+ scopes?: string[];
21
+ userScopes?: string[];
22
+ redirectUri?: string;
23
+ metadata?: string;
24
+ teamId?: string;
25
+ }
26
+ interface SlackInstallationQuery {
27
+ teamId: string | undefined;
28
+ enterpriseId: string | undefined;
29
+ userId?: string;
30
+ conversationId?: string;
31
+ isEnterpriseInstall: boolean;
32
+ }
33
+ interface SlackInstallation {
34
+ team?: {
35
+ id: string;
36
+ name?: string;
37
+ } | undefined;
38
+ enterprise?: {
39
+ id: string;
40
+ name?: string;
41
+ } | undefined;
42
+ user: {
43
+ id: string;
44
+ token?: string;
45
+ refreshToken?: string;
46
+ expiresAt?: number;
47
+ scopes?: string[];
48
+ };
49
+ bot?: {
50
+ token: string;
51
+ refreshToken?: string;
52
+ expiresAt?: number;
53
+ scopes: string[];
54
+ id?: string;
55
+ userId?: string;
56
+ };
57
+ incomingWebhook?: {
58
+ url: string;
59
+ channel?: string;
60
+ channelId?: string;
61
+ configurationUrl?: string;
62
+ };
63
+ appId?: string;
64
+ tokenType?: "bot";
65
+ enterpriseUrl?: string;
66
+ isEnterpriseInstall?: boolean;
67
+ authVersion?: "v1" | "v2";
68
+ metadata?: string;
69
+ }
70
+ interface SlackInstallationStore {
71
+ storeInstallation(installation: SlackInstallation, logger?: unknown): Promise<void>;
72
+ fetchInstallation(query: SlackInstallationQuery, logger?: unknown): Promise<SlackInstallation>;
73
+ deleteInstallation?(query: SlackInstallationQuery, logger?: unknown): Promise<void>;
74
+ }
75
+ interface SlackStateStore {
76
+ generateStateParam(installOptions: SlackInstallURLOptions, now: Date): Promise<string>;
77
+ verifyStateParam(now: Date, state: string): Promise<SlackInstallURLOptions>;
78
+ }
79
+ interface SlackOAuthInstallPathOptions {
80
+ beforeRedirection?: (request: IncomingMessage, response: ServerResponse, options?: SlackInstallURLOptions) => Promise<boolean>;
81
+ }
82
+ interface SlackOAuthCallbackOptions {
83
+ beforeInstallation?: (options: SlackInstallURLOptions, request: IncomingMessage, response: ServerResponse) => Promise<boolean>;
84
+ afterInstallation?: (installation: SlackInstallation, options: SlackInstallURLOptions, request: IncomingMessage, response: ServerResponse) => Promise<boolean>;
85
+ success?: (installation: SlackInstallation, options: SlackInstallURLOptions, request: IncomingMessage, response: ServerResponse) => void;
86
+ successAsync?: (installation: SlackInstallation, options: SlackInstallURLOptions, request: IncomingMessage, response: ServerResponse) => Promise<void>;
87
+ failure?: (error: SlackOAuthError, options: SlackInstallURLOptions, request: IncomingMessage, response: ServerResponse) => void;
88
+ failureAsync?: (error: SlackOAuthError, options: SlackInstallURLOptions, request: IncomingMessage, response: ServerResponse) => Promise<void>;
89
+ }
90
+ interface SlackAuthorizeSource {
91
+ teamId: string | undefined;
92
+ enterpriseId: string | undefined;
93
+ userId?: string;
94
+ conversationId?: string;
95
+ isEnterpriseInstall: boolean;
96
+ }
97
+ interface SlackAuthorizeResult {
98
+ botToken?: string;
99
+ userToken?: string;
100
+ botId?: string;
101
+ botUserId?: string;
102
+ userId?: string;
103
+ teamId?: string;
104
+ enterpriseId?: string;
105
+ [key: string]: unknown;
106
+ }
107
+ type SlackAuthorizeFn = (source: SlackAuthorizeSource, body?: unknown) => Promise<SlackAuthorizeResult>;
108
+ interface SlackSingleWorkspaceAuthOptions {
109
+ mode?: "single-workspace";
110
+ botToken?: string;
111
+ botId?: string;
112
+ botUserId?: string;
113
+ }
114
+ interface SlackOAuthAuthOptions {
115
+ mode: "oauth";
116
+ clientId?: string;
117
+ clientSecret?: string;
118
+ stateSecret?: string;
119
+ installationStore: SlackInstallationStore;
120
+ stateStore?: SlackStateStore;
121
+ stateVerification?: boolean;
122
+ legacyStateVerification?: boolean;
123
+ stateCookieName?: string;
124
+ stateCookieExpirationSeconds?: number;
125
+ redirectUri?: string;
126
+ scopes?: string[];
127
+ userScopes?: string[];
128
+ metadata?: string;
129
+ installPath?: string;
130
+ callbackPath?: string;
131
+ renderHtmlForInstallPath?: (url: string) => string;
132
+ installPathOptions?: SlackOAuthInstallPathOptions;
133
+ callbackOptions?: SlackOAuthCallbackOptions;
134
+ directInstall?: boolean;
135
+ authVersion?: "v1" | "v2";
136
+ authorizationUrl?: string;
137
+ }
138
+ interface SlackCustomAuthorizeAuthOptions {
139
+ mode: "authorize";
140
+ authorize: SlackAuthorizeFn;
141
+ }
142
+ type SlackDirectAuthOptions = SlackSingleWorkspaceAuthOptions | SlackOAuthAuthOptions | SlackCustomAuthorizeAuthOptions;
143
+
144
+ /**
145
+ * `createSlackBoltApp` — builds a Bolt `App` + `ExpressReceiver` pair from
146
+ * the package's structured `CreateSlackBoltAppOptions`. Supports
147
+ * single-workspace, OAuth, and custom-authorize auth modes.
148
+ */
149
+
150
+ interface CreateSlackBoltAppOptions {
151
+ /**
152
+ * Slack signing secret used to verify inbound requests.
153
+ * Defaults to `SLACK_SIGNING_SECRET`.
154
+ */
155
+ signingSecret?: string;
156
+ /**
157
+ * Exact Slack Events API endpoint path.
158
+ * Defaults to `/slack/events`.
159
+ */
160
+ path?: string;
161
+ /**
162
+ * Direct-mode auth configuration.
163
+ *
164
+ * - omit for single-workspace token mode
165
+ * - use `{ mode: "oauth", ... }` for Bolt-managed installs
166
+ * - use `{ mode: "authorize", authorize }` for external token resolution
167
+ */
168
+ auth?: SlackDirectAuthOptions;
169
+ /**
170
+ * Convenience override for single-workspace mode.
171
+ * Defaults to `SLACK_BOT_TOKEN`.
172
+ */
173
+ botToken?: string;
174
+ /**
175
+ * Pre-existing Express app to mount onto.
176
+ */
177
+ app?: Application;
178
+ processBeforeResponse?: boolean;
179
+ signatureVerification?: boolean;
180
+ /**
181
+ * Additional Bolt `App` options passed through after this package sets
182
+ * receiver/auth. Use for logger/clientOptions and other native Bolt config.
183
+ */
184
+ boltAppOptions?: Partial<Omit<AppOptions, "receiver" | "token" | "authorize" | "botId" | "botUserId">>;
185
+ /**
186
+ * Additional Bolt `ExpressReceiver` options passed through after this
187
+ * package sets signing/auth/endpoints. Use for router, custom properties,
188
+ * and receiver-level error handlers.
189
+ */
190
+ receiverOptions?: Partial<Omit<ExpressReceiverOptions, "signingSecret" | "endpoints" | "processBeforeResponse" | "signatureVerification" | "app" | "clientId" | "clientSecret" | "stateSecret" | "installationStore" | "redirectUri" | "scopes" | "installerOptions">>;
191
+ }
192
+ interface CreateSlackBoltAppResult {
193
+ /** Bolt `App` used for event registration and outbound Slack calls. */
194
+ boltApp: App;
195
+ /** Bolt `ExpressReceiver` that owns request verification and OAuth routes. */
196
+ receiver: ExpressReceiver;
197
+ /** Express app that should receive `receiver.router`. */
198
+ app: Application;
199
+ /** Resolved direct auth mode. */
200
+ authMode: SlackDirectAuthMode;
201
+ /** Exact normalized events endpoint path. */
202
+ routePath: string;
203
+ }
204
+ declare function createSlackBoltApp(options?: CreateSlackBoltAppOptions): Promise<CreateSlackBoltAppResult>;
205
+
206
+ /**
207
+ * `createSlackSocketBoltApp` — builds a Socket Mode Bolt `App` from the
208
+ * package's structured auth options. Mirrors `createSlackBoltApp` without
209
+ * owning any assistant/app surface mounting.
210
+ */
211
+
212
+ type ControlledSocketBoltAppOption = "receiver" | "socketMode" | "appToken" | "token" | "authorize" | "botId" | "botUserId" | "clientId" | "clientSecret" | "stateSecret" | "redirectUri" | "installationStore" | "scopes" | "installerOptions";
213
+ type ControlledSocketModeReceiverOption = "appToken" | "clientId" | "clientSecret" | "stateSecret" | "redirectUri" | "installationStore" | "scopes" | "installerOptions" | "logger" | "logLevel";
214
+ interface CreateSlackSocketBoltAppOptions {
215
+ /**
216
+ * Slack app-level token (`xapp-...`) with `connections:write` scope.
217
+ * @default process.env.SLACK_APP_TOKEN
218
+ */
219
+ appToken?: string;
220
+ /**
221
+ * Convenience override for single-workspace mode.
222
+ * @default process.env.SLACK_BOT_TOKEN
223
+ */
224
+ botToken?: string;
225
+ /**
226
+ * Direct-mode auth configuration.
227
+ *
228
+ * - omit for single-workspace token mode
229
+ * - use `{ mode: "oauth", ... }` for Bolt-managed installs
230
+ * - use `{ mode: "authorize", authorize }` for external token resolution
231
+ */
232
+ auth?: SlackDirectAuthOptions;
233
+ /**
234
+ * Additional Bolt `App` options passed after this package sets Socket Mode
235
+ * and auth. Use for logger/clientOptions and non-auth native Bolt config.
236
+ */
237
+ boltAppOptions?: Partial<Omit<AppOptions, ControlledSocketBoltAppOption>>;
238
+ /**
239
+ * Additional native Socket Mode receiver options. Use this for websocket
240
+ * health tuning such as ping timeouts, reconnect behavior, and receiver
241
+ * error handling. Auth/OAuth fields stay controlled by this helper.
242
+ */
243
+ socketModeReceiverOptions?: Partial<Omit<SocketModeReceiverOptions, ControlledSocketModeReceiverOption>>;
244
+ }
245
+ interface CreateSlackSocketBoltAppResult {
246
+ boltApp: App;
247
+ authMode: SlackDirectAuthMode;
248
+ }
249
+ declare function createSlackSocketBoltApp(options?: CreateSlackSocketBoltAppOptions): Promise<CreateSlackSocketBoltAppResult>;
250
+
251
+ interface SlackSocketModeProcessLockOptions {
252
+ appSlug: string;
253
+ appToken?: string;
254
+ enabled?: boolean;
255
+ lockDir?: string;
256
+ logger?: Logger;
257
+ }
258
+ interface SlackSocketModeProcessLock {
259
+ path: string;
260
+ release(): void;
261
+ }
262
+ declare function acquireSlackSocketModeProcessLock({ appSlug, appToken, enabled, lockDir, logger, }: SlackSocketModeProcessLockOptions): SlackSocketModeProcessLock | undefined;
263
+
264
+ type SlackSdkLogLevel = "debug" | "info" | "warn" | "error";
265
+ interface SlackSdkLogger {
266
+ debug(...msg: unknown[]): void;
267
+ error(...msg: unknown[]): void;
268
+ getLevel(): SlackSdkLogLevel;
269
+ info(...msg: unknown[]): void;
270
+ setLevel(nextLevel: SlackSdkLogLevel): void;
271
+ setName(nextName: string): void;
272
+ warn(...msg: unknown[]): void;
273
+ }
274
+ type SlackSocketModeRuntimePolicy = "single-instance" | "external-coordination";
275
+ interface SlackSocketModeReceiverRuntimeOptions {
276
+ autoReconnectEnabled?: boolean;
277
+ clientPingTimeout?: number;
278
+ pingPongLoggingEnabled?: boolean;
279
+ serverPingTimeout?: number;
280
+ }
281
+ interface SlackSocketModeRuntimeOptions {
282
+ appSlug: string;
283
+ appToken?: string;
284
+ autoReconnectEnabled?: boolean;
285
+ clientPingTimeoutMs?: number;
286
+ exitProcess?: (code: number) => never | void;
287
+ lockDir?: string;
288
+ lockEnabled?: boolean;
289
+ logger?: Logger;
290
+ logLevel?: "debug" | "info" | "warn" | "error";
291
+ pingPongLoggingEnabled?: boolean;
292
+ restartGuardEnabled?: boolean;
293
+ restartGuardMaxWarnings?: number;
294
+ restartGuardWindowMs?: number;
295
+ runtimePolicy?: SlackSocketModeRuntimePolicy;
296
+ serverPingTimeoutMs?: number;
297
+ }
298
+ interface SlackSocketModeRuntime {
299
+ boltAppOptions: {
300
+ logger: SlackSdkLogger;
301
+ };
302
+ close(): void;
303
+ socketModeReceiverOptions: SlackSocketModeReceiverRuntimeOptions;
304
+ }
305
+ interface SlackSocketModeRestartGuard {
306
+ record(message: string): void;
307
+ }
308
+ declare function createSlackSocketModeRuntime({ appSlug, appToken, autoReconnectEnabled, clientPingTimeoutMs, exitProcess, lockDir, lockEnabled, logger, logLevel, pingPongLoggingEnabled, restartGuardEnabled, restartGuardMaxWarnings, restartGuardWindowMs, runtimePolicy, serverPingTimeoutMs, }: SlackSocketModeRuntimeOptions): SlackSocketModeRuntime;
309
+ declare function createSlackSocketModeRestartGuard({ enabled, exitProcess, logger, maxWarnings, windowMs, }: {
310
+ enabled: boolean;
311
+ exitProcess: (code: number) => never | void;
312
+ logger?: Logger;
313
+ maxWarnings: number;
314
+ windowMs: number;
315
+ }): SlackSocketModeRestartGuard;
316
+ declare function createSlackSdkLogger({ level, logger, restartGuard, }: {
317
+ level: "debug" | "info" | "warn" | "error";
318
+ logger?: Logger;
319
+ restartGuard?: SlackSocketModeRestartGuard;
320
+ }): SlackSdkLogger;
321
+ declare function redactSlackSocketModeLogValue(value: unknown, depth?: number): unknown;
322
+
323
+ declare class InMemorySlackInstallationStore implements SlackInstallationStore {
324
+ private devDB;
325
+ storeInstallation(installation: SlackInstallation): Promise<void>;
326
+ fetchInstallation(query: SlackInstallationQuery): Promise<SlackInstallation>;
327
+ deleteInstallation(query: SlackInstallationQuery): Promise<void>;
328
+ }
329
+ declare function createInMemorySlackInstallationStore(): SlackInstallationStore;
330
+ declare class JsonFileSlackInstallationStore implements SlackInstallationStore {
331
+ private readonly filePath;
332
+ private pending;
333
+ constructor(filePath: string);
334
+ storeInstallation(installation: SlackInstallation): Promise<void>;
335
+ fetchInstallation(query: SlackInstallationQuery): Promise<SlackInstallation>;
336
+ deleteInstallation(query: SlackInstallationQuery): Promise<void>;
337
+ private withLock;
338
+ private readInstallations;
339
+ private writeInstallations;
340
+ }
341
+ declare function createJsonFileSlackInstallationStore(filePath: string): SlackInstallationStore;
342
+ declare function getSlackInstallationKey(input: SlackInstallation | SlackInstallationQuery): string;
343
+
344
+ export { type CreateSlackBoltAppOptions, type CreateSlackBoltAppResult, type CreateSlackSocketBoltAppOptions, type CreateSlackSocketBoltAppResult, InMemorySlackInstallationStore, JsonFileSlackInstallationStore, type SlackAuthorizeFn, type SlackAuthorizeResult, type SlackAuthorizeSource, type SlackCustomAuthorizeAuthOptions, type SlackDirectAuthMode, type SlackDirectAuthOptions, type SlackInstallation, type SlackInstallationQuery, type SlackInstallationStore, type SlackOAuthAuthOptions, type SlackOAuthCallbackOptions, type SlackOAuthError, type SlackOAuthInstallPathOptions, type SlackSdkLogLevel, type SlackSdkLogger, type SlackSingleWorkspaceAuthOptions, type SlackSocketModeProcessLock, type SlackSocketModeProcessLockOptions, type SlackSocketModeReceiverRuntimeOptions, type SlackSocketModeRestartGuard, type SlackSocketModeRuntime, type SlackSocketModeRuntimeOptions, type SlackSocketModeRuntimePolicy, type SlackStateStore, acquireSlackSocketModeProcessLock, createInMemorySlackInstallationStore, createJsonFileSlackInstallationStore, createSlackBoltApp, createSlackSdkLogger, createSlackSocketBoltApp, createSlackSocketModeRestartGuard, createSlackSocketModeRuntime, getSlackInstallationKey, redactSlackSocketModeLogValue };