@inkeep/agents-work-apps 0.50.0 → 0.50.3

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 (57) hide show
  1. package/dist/_virtual/rolldown_runtime.js +32 -0
  2. package/dist/env.d.ts +2 -0
  3. package/dist/env.js +1 -0
  4. package/dist/github/mcp/auth.d.ts +2 -2
  5. package/dist/github/mcp/index.d.ts +2 -2
  6. package/dist/github/mcp/schemas.d.ts +1 -1
  7. package/dist/github/routes/tokenExchange.d.ts +2 -2
  8. package/dist/github/routes/webhooks.d.ts +2 -2
  9. package/dist/node_modules/.pnpm/@slack_logger@4.0.0/node_modules/@slack/logger/dist/index.js +89 -0
  10. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/package.js +85 -0
  11. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js +223 -0
  12. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js +367 -0
  13. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/UnrecoverableSocketModeStartError.js +20 -0
  14. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/errors.js +71 -0
  15. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/index.js +44 -0
  16. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/logger.js +32 -0
  17. package/dist/node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js +241 -0
  18. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/index.js +23 -0
  19. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js +107 -0
  20. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js +29 -0
  21. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js +226 -0
  22. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js +150 -0
  23. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js +57 -0
  24. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js +342 -0
  25. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js +457 -0
  26. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js +505 -0
  27. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js +123 -0
  28. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js +46 -0
  29. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js +203 -0
  30. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js +385 -0
  31. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js +985 -0
  32. package/dist/slack/dispatcher.d.ts +16 -0
  33. package/dist/slack/dispatcher.js +335 -0
  34. package/dist/slack/i18n/strings.d.ts +5 -5
  35. package/dist/slack/i18n/strings.js +9 -9
  36. package/dist/slack/index.d.ts +3 -1
  37. package/dist/slack/index.js +4 -2
  38. package/dist/slack/middleware/permissions.js +120 -107
  39. package/dist/slack/routes/events.js +10 -328
  40. package/dist/slack/routes/oauth.js +6 -3
  41. package/dist/slack/routes/users.js +12 -6
  42. package/dist/slack/routes/workspaces.js +31 -36
  43. package/dist/slack/services/blocks/index.js +7 -11
  44. package/dist/slack/services/commands/index.js +2 -2
  45. package/dist/slack/services/dev-config.d.ts +23 -0
  46. package/dist/slack/services/dev-config.js +91 -0
  47. package/dist/slack/services/events/app-mention.js +6 -17
  48. package/dist/slack/services/events/modal-submission.js +5 -5
  49. package/dist/slack/services/events/streaming.js +4 -3
  50. package/dist/slack/services/events/utils.js +8 -8
  51. package/dist/slack/services/index.js +1 -1
  52. package/dist/slack/services/modals.js +4 -4
  53. package/dist/slack/services/nango.d.ts +2 -0
  54. package/dist/slack/services/nango.js +84 -2
  55. package/dist/slack/socket-mode.d.ts +4 -0
  56. package/dist/slack/socket-mode.js +130 -0
  57. package/package.json +3 -2
@@ -0,0 +1,32 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
+ key = keys[i];
15
+ if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ }
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
30
+
31
+ //#endregion
32
+ export { __commonJSMin, __require, __toESM };
package/dist/env.d.ts CHANGED
@@ -33,6 +33,7 @@ declare const envSchema: z.ZodObject<{
33
33
  SLACK_SIGNING_SECRET: z.ZodOptional<z.ZodString>;
34
34
  SLACK_BOT_TOKEN: z.ZodOptional<z.ZodString>;
35
35
  SLACK_APP_URL: z.ZodOptional<z.ZodString>;
36
+ SLACK_APP_TOKEN: z.ZodOptional<z.ZodString>;
36
37
  NANGO_SECRET_KEY: z.ZodOptional<z.ZodString>;
37
38
  NANGO_SLACK_SECRET_KEY: z.ZodOptional<z.ZodString>;
38
39
  NANGO_SLACK_INTEGRATION_ID: z.ZodOptional<z.ZodString>;
@@ -57,6 +58,7 @@ declare const env: {
57
58
  SLACK_SIGNING_SECRET?: string | undefined;
58
59
  SLACK_BOT_TOKEN?: string | undefined;
59
60
  SLACK_APP_URL?: string | undefined;
61
+ SLACK_APP_TOKEN?: string | undefined;
60
62
  NANGO_SECRET_KEY?: string | undefined;
61
63
  NANGO_SLACK_SECRET_KEY?: string | undefined;
62
64
  NANGO_SLACK_INTEGRATION_ID?: string | undefined;
package/dist/env.js CHANGED
@@ -35,6 +35,7 @@ const envSchema = z.object({
35
35
  SLACK_SIGNING_SECRET: z.string().optional().describe("Slack App Signing Secret"),
36
36
  SLACK_BOT_TOKEN: z.string().optional().describe("Slack Bot Token (for testing)"),
37
37
  SLACK_APP_URL: z.string().optional().describe("Slack App Install URL"),
38
+ SLACK_APP_TOKEN: z.string().optional().describe("Slack App-Level Token for Socket Mode (xapp-*)"),
38
39
  NANGO_SECRET_KEY: z.string().optional().describe("Nango Secret Key"),
39
40
  NANGO_SLACK_SECRET_KEY: z.string().optional().describe("Nango Slack-specific Secret Key"),
40
41
  NANGO_SLACK_INTEGRATION_ID: z.string().optional().describe("Nango Slack Integration ID"),
@@ -1,7 +1,7 @@
1
- import * as hono0 from "hono";
1
+ import * as hono1 from "hono";
2
2
 
3
3
  //#region src/github/mcp/auth.d.ts
4
- declare const githubMcpAuth: () => hono0.MiddlewareHandler<{
4
+ declare const githubMcpAuth: () => hono1.MiddlewareHandler<{
5
5
  Variables: {
6
6
  toolId: string;
7
7
  };
@@ -1,11 +1,11 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types7 from "hono/types";
2
+ import * as hono_types9 from "hono/types";
3
3
 
4
4
  //#region src/github/mcp/index.d.ts
5
5
  declare const app: Hono<{
6
6
  Variables: {
7
7
  toolId: string;
8
8
  };
9
- }, hono_types7.BlankSchema, "/">;
9
+ }, hono_types9.BlankSchema, "/">;
10
10
  //#endregion
11
11
  export { app as default };
@@ -76,8 +76,8 @@ declare const ChangedFileSchema: z.ZodObject<{
76
76
  path: z.ZodString;
77
77
  status: z.ZodEnum<{
78
78
  added: "added";
79
- removed: "removed";
80
79
  modified: "modified";
80
+ removed: "removed";
81
81
  renamed: "renamed";
82
82
  copied: "copied";
83
83
  changed: "changed";
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types8 from "hono/types";
2
+ import * as hono_types5 from "hono/types";
3
3
 
4
4
  //#region src/github/routes/tokenExchange.d.ts
5
- declare const app: Hono<hono_types8.BlankEnv, hono_types8.BlankSchema, "/">;
5
+ declare const app: Hono<hono_types5.BlankEnv, hono_types5.BlankSchema, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,5 +1,5 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types5 from "hono/types";
2
+ import * as hono_types7 from "hono/types";
3
3
 
4
4
  //#region src/github/routes/webhooks.d.ts
5
5
  interface WebhookVerificationResult {
@@ -7,6 +7,6 @@ interface WebhookVerificationResult {
7
7
  error?: string;
8
8
  }
9
9
  declare function verifyWebhookSignature(payload: string, signature: string | undefined, secret: string): WebhookVerificationResult;
10
- declare const app: Hono<hono_types5.BlankEnv, hono_types5.BlankSchema, "/">;
10
+ declare const app: Hono<hono_types7.BlankEnv, hono_types7.BlankSchema, "/">;
11
11
  //#endregion
12
12
  export { WebhookVerificationResult, app as default, verifyWebhookSignature };
@@ -0,0 +1,89 @@
1
+ import { __commonJSMin } from "../../../../../../../_virtual/rolldown_runtime.js";
2
+
3
+ //#region ../../node_modules/.pnpm/@slack+logger@4.0.0/node_modules/@slack/logger/dist/index.js
4
+ var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConsoleLogger = exports.LogLevel = void 0;
7
+ /**
8
+ * Severity levels for log entries
9
+ */
10
+ var LogLevel;
11
+ (function(LogLevel) {
12
+ LogLevel["ERROR"] = "error";
13
+ LogLevel["WARN"] = "warn";
14
+ LogLevel["INFO"] = "info";
15
+ LogLevel["DEBUG"] = "debug";
16
+ })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
17
+ /**
18
+ * Default logger which logs to stdout and stderr
19
+ */
20
+ var ConsoleLogger = class ConsoleLogger {
21
+ constructor() {
22
+ this.level = LogLevel.INFO;
23
+ this.name = "";
24
+ }
25
+ getLevel() {
26
+ return this.level;
27
+ }
28
+ /**
29
+ * Sets the instance's log level so that only messages which are equal or more severe are output to the console.
30
+ */
31
+ setLevel(level) {
32
+ this.level = level;
33
+ }
34
+ /**
35
+ * Set the instance's name, which will appear on each log line before the message.
36
+ */
37
+ setName(name) {
38
+ this.name = name;
39
+ }
40
+ /**
41
+ * Log a debug message
42
+ */
43
+ debug(...msg) {
44
+ if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.DEBUG, this.level)) console.debug(ConsoleLogger.labels.get(LogLevel.DEBUG), this.name, ...msg);
45
+ }
46
+ /**
47
+ * Log an info message
48
+ */
49
+ info(...msg) {
50
+ if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.INFO, this.level)) console.info(ConsoleLogger.labels.get(LogLevel.INFO), this.name, ...msg);
51
+ }
52
+ /**
53
+ * Log a warning message
54
+ */
55
+ warn(...msg) {
56
+ if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.WARN, this.level)) console.warn(ConsoleLogger.labels.get(LogLevel.WARN), this.name, ...msg);
57
+ }
58
+ /**
59
+ * Log an error message
60
+ */
61
+ error(...msg) {
62
+ if (ConsoleLogger.isMoreOrEqualSevere(LogLevel.ERROR, this.level)) console.error(ConsoleLogger.labels.get(LogLevel.ERROR), this.name, ...msg);
63
+ }
64
+ /**
65
+ * Helper to compare two log levels and determine if a is equal or more severe than b
66
+ */
67
+ static isMoreOrEqualSevere(a, b) {
68
+ return ConsoleLogger.severity[a] >= ConsoleLogger.severity[b];
69
+ }
70
+ };
71
+ exports.ConsoleLogger = ConsoleLogger;
72
+ /** Map of labels for each log level */
73
+ ConsoleLogger.labels = (() => {
74
+ const map = Object.entries(LogLevel).map(([key, value]) => [value, `[${key}] `]);
75
+ return new Map(map);
76
+ })();
77
+ /** Map of severity as comparable numbers for each log level */
78
+ ConsoleLogger.severity = {
79
+ [LogLevel.ERROR]: 400,
80
+ [LogLevel.WARN]: 300,
81
+ [LogLevel.INFO]: 200,
82
+ [LogLevel.DEBUG]: 100
83
+ };
84
+ }));
85
+
86
+ //#endregion
87
+ export default require_dist();
88
+
89
+ export { require_dist };
@@ -0,0 +1,85 @@
1
+ import { __commonJSMin } from "../../../../../../../_virtual/rolldown_runtime.js";
2
+
3
+ //#region ../../node_modules/.pnpm/@slack+socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/package.json
4
+ var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
5
+ module.exports = {
6
+ "name": "@slack/socket-mode",
7
+ "version": "2.0.5",
8
+ "description": "Official library for using the Slack Platform's Socket Mode API",
9
+ "author": "Slack Technologies, LLC",
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "slack",
13
+ "socket",
14
+ "websocket",
15
+ "firewall",
16
+ "bot",
17
+ "client",
18
+ "http",
19
+ "websocket",
20
+ "api",
21
+ "proxy",
22
+ "state",
23
+ "connection"
24
+ ],
25
+ "main": "dist/src/index.js",
26
+ "types": "./dist/src/index.d.ts",
27
+ "files": ["dist/**/*"],
28
+ "engines": {
29
+ "node": ">= 18",
30
+ "npm": ">= 8.6.0"
31
+ },
32
+ "repository": "slackapi/node-slack-sdk",
33
+ "homepage": "https://tools.slack.dev/node-slack-sdk/socket-mode",
34
+ "publishConfig": { "access": "public" },
35
+ "bugs": { "url": "https://github.com/slackapi/node-slack-sdk/issues" },
36
+ "scripts": {
37
+ "prepare": "npm run build",
38
+ "build": "npm run build:clean && tsc",
39
+ "build:clean": "shx rm -rf ./dist ./coverage",
40
+ "docs": "npx typedoc --plugin typedoc-plugin-markdown",
41
+ "lint": "npx @biomejs/biome check .",
42
+ "lint:fix": "npx @biomejs/biome check --write .",
43
+ "test:unit": "mocha --config ./test/.mocharc.json src/**/*.spec.ts",
44
+ "test:coverage": "c8 --config ./test/.c8rc.json npm run test:unit",
45
+ "test:integration": "mocha --config ./test/.mocharc.json test/integration.spec.js",
46
+ "test": "npm run lint && npm run build && npm run test:coverage && npm run test:integration",
47
+ "watch": "npx nodemon --watch 'src' --ext 'ts' --exec npm test"
48
+ },
49
+ "dependencies": {
50
+ "@slack/logger": "^4",
51
+ "@slack/web-api": "^7.10.0",
52
+ "@types/node": ">=18",
53
+ "@types/ws": "^8",
54
+ "eventemitter3": "^5",
55
+ "ws": "^8"
56
+ },
57
+ "devDependencies": {
58
+ "@biomejs/biome": "^2.0.5",
59
+ "@tsconfig/recommended": "^1.0.7",
60
+ "@types/chai": "^4",
61
+ "@types/mocha": "^10",
62
+ "@types/proxyquire": "^1.3.31",
63
+ "@types/sinon": "^17",
64
+ "c8": "^10.1.2",
65
+ "chai": "^4",
66
+ "mocha": "^11",
67
+ "mocha-junit-reporter": "^2.2.1",
68
+ "mocha-multi-reporters": "^1.5.1",
69
+ "nodemon": "^3.1.0",
70
+ "proxyquire": "^2.1.3",
71
+ "shx": "^0.4.0",
72
+ "sinon": "^21",
73
+ "source-map-support": "^0.5.21",
74
+ "ts-node": "^10",
75
+ "typedoc": "^0.28.7",
76
+ "typedoc-plugin-markdown": "^4.7.0",
77
+ "typescript": "5.9.2"
78
+ }
79
+ };
80
+ }));
81
+
82
+ //#endregion
83
+ export default require_package();
84
+
85
+ export { require_package };
@@ -0,0 +1,223 @@
1
+ import { __commonJSMin } from "../../../../../../../../_virtual/rolldown_runtime.js";
2
+ import { require_errors } from "./errors.js";
3
+ import { require_logger } from "./logger.js";
4
+ import { require_ws } from "../../../../../../ws@8.19.0/node_modules/ws/index.js";
5
+
6
+ //#region ../../node_modules/.pnpm/@slack+socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js
7
+ var require_SlackWebSocket = /* @__PURE__ */ __commonJSMin(((exports) => {
8
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === void 0) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
12
+ enumerable: true,
13
+ get: function() {
14
+ return m[k];
15
+ }
16
+ };
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === void 0) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", {
24
+ enumerable: true,
25
+ value: v
26
+ });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = exports && exports.__importStar || (function() {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function(o$1) {
33
+ var ar = [];
34
+ for (var k in o$1) if (Object.prototype.hasOwnProperty.call(o$1, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function(mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) {
43
+ for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
44
+ }
45
+ __setModuleDefault(result, mod);
46
+ return result;
47
+ };
48
+ })();
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.SlackWebSocket = exports.WS_READY_STATES = void 0;
51
+ const ws_1 = require_ws();
52
+ const errors_1 = require_errors();
53
+ const logger_1 = __importStar(require_logger());
54
+ exports.WS_READY_STATES = [
55
+ "CONNECTING",
56
+ "OPEN",
57
+ "CLOSING",
58
+ "CLOSED"
59
+ ];
60
+ /**
61
+ * Encapsulates the Slack-specific details around establishing a WebSocket connection with the Slack backend.
62
+ * Manages the ping/pong heartbeat of the connection.
63
+ */
64
+ var SlackWebSocket = class SlackWebSocket {
65
+ constructor({ url, client, httpAgent, logger, logLevel = logger_1.LogLevel.INFO, pingInterval = 5e3, pingPongLoggingEnabled = false, serverPingTimeoutMS = 3e4, clientPingTimeoutMS = 5e3 }) {
66
+ this.options = {
67
+ url,
68
+ client,
69
+ httpAgent,
70
+ logLevel,
71
+ pingInterval,
72
+ pingPongLoggingEnabled,
73
+ serverPingTimeoutMS,
74
+ clientPingTimeoutMS
75
+ };
76
+ if (logger) this.logger = logger;
77
+ else this.logger = logger_1.default.getLogger(SlackWebSocket.loggerName, logLevel);
78
+ this.websocket = null;
79
+ this.closeFrameReceived = false;
80
+ }
81
+ /**
82
+ * Establishes a connection with the Slack backend
83
+ */
84
+ connect() {
85
+ this.logger.debug("Initiating new WebSocket connection.");
86
+ const options = {
87
+ perMessageDeflate: false,
88
+ agent: this.options.httpAgent
89
+ };
90
+ this.websocket = new ws_1.WebSocket(this.options.url, options);
91
+ this.websocket.addEventListener("open", (_event) => {
92
+ this.logger.debug("WebSocket open event received (connection established)!");
93
+ this.monitorPingToSlack();
94
+ });
95
+ this.websocket.addEventListener("error", (event) => {
96
+ this.logger.error(`WebSocket error occurred: ${event.message}`);
97
+ this.disconnect();
98
+ this.options.client.emit("error", (0, errors_1.websocketErrorWithOriginal)(event.error));
99
+ });
100
+ this.websocket.on("message", (msg, isBinary) => {
101
+ this.options.client.emit("ws_message", msg, isBinary);
102
+ });
103
+ this.websocket.on("close", (code, data) => {
104
+ this.logger.debug(`WebSocket close frame received (code: ${code}, reason: ${data.toString()})`);
105
+ this.closeFrameReceived = true;
106
+ this.disconnect();
107
+ });
108
+ this.websocket.on("ping", (data) => {
109
+ if (this.options.pingPongLoggingEnabled) this.logger.debug(`WebSocket received ping from Slack server (data: ${data.toString()})`);
110
+ this.monitorPingFromSlack();
111
+ });
112
+ this.websocket.on("pong", (data) => {
113
+ if (this.options.pingPongLoggingEnabled) this.logger.debug(`WebSocket received pong from Slack server (data: ${data.toString()})`);
114
+ this.lastPongReceivedTimestamp = Date.now();
115
+ });
116
+ }
117
+ /**
118
+ * Disconnects the WebSocket connection with Slack, if connected.
119
+ */
120
+ disconnect() {
121
+ if (this.websocket) if (this.closeFrameReceived) {
122
+ this.logger.debug("Terminating WebSocket (close frame received).");
123
+ this.terminate();
124
+ } else {
125
+ this.logger.debug("Sending close frame (status=1000).");
126
+ this.websocket.close(1e3);
127
+ }
128
+ else {
129
+ this.logger.debug("WebSocket already disconnected, flushing remainder.");
130
+ this.terminate();
131
+ }
132
+ }
133
+ /**
134
+ * Clean up any underlying intervals, timeouts and the WebSocket.
135
+ */
136
+ terminate() {
137
+ var _a, _b;
138
+ (_a = this.websocket) === null || _a === void 0 || _a.removeAllListeners();
139
+ (_b = this.websocket) === null || _b === void 0 || _b.terminate();
140
+ this.websocket = null;
141
+ clearTimeout(this.serverPingTimeout);
142
+ clearInterval(this.clientPingTimeout);
143
+ this.options.client.emit("close");
144
+ }
145
+ /**
146
+ * Returns true if the underlying WebSocket connection is active, meaning the underlying
147
+ * {@link https://github.com/websockets/ws/blob/master/doc/ws.md#ready-state-constants WebSocket ready state is "OPEN"}.
148
+ */
149
+ isActive() {
150
+ if (!this.websocket) {
151
+ this.logger.debug("isActive(): websocket not instantiated!");
152
+ return false;
153
+ }
154
+ this.logger.debug(`isActive(): websocket ready state is ${exports.WS_READY_STATES[this.websocket.readyState]}`);
155
+ return this.websocket.readyState === 1;
156
+ }
157
+ /**
158
+ * Retrieve the underlying WebSocket readyState. Returns `undefined` if the WebSocket has not been instantiated,
159
+ * otherwise will return a number between 0 and 3 inclusive representing the ready states.
160
+ * The ready state constants are documented in the {@link https://github.com/websockets/ws/blob/master/doc/ws.md#ready-state-constants `ws` API docs }
161
+ */
162
+ get readyState() {
163
+ var _a;
164
+ return (_a = this.websocket) === null || _a === void 0 ? void 0 : _a.readyState;
165
+ }
166
+ /**
167
+ * Sends data via the underlying WebSocket. Accepts an errorback argument.
168
+ */
169
+ send(data, cb) {
170
+ var _a;
171
+ (_a = this.websocket) === null || _a === void 0 || _a.send(data, cb);
172
+ }
173
+ /**
174
+ * Confirms WebSocket connection is still active; fires whenever a ping event is received
175
+ * If we don't receive another ping from the peer before the timeout, we initiate closing the connection.
176
+ */
177
+ monitorPingFromSlack() {
178
+ clearTimeout(this.serverPingTimeout);
179
+ this.serverPingTimeout = setTimeout(() => {
180
+ this.logger.warn(`A ping wasn't received from the server before the timeout of ${this.options.serverPingTimeoutMS}ms!`);
181
+ this.disconnect();
182
+ }, this.options.serverPingTimeoutMS);
183
+ }
184
+ /**
185
+ * Monitors WebSocket connection health; sends a ping to peer, and expects a pong within a certain timeframe.
186
+ * If that expectation is not met, we disconnect the websocket.
187
+ */
188
+ monitorPingToSlack() {
189
+ this.lastPongReceivedTimestamp = void 0;
190
+ let pingAttemptCount = 0;
191
+ clearInterval(this.clientPingTimeout);
192
+ this.clientPingTimeout = setInterval(() => {
193
+ var _a;
194
+ const now = Date.now();
195
+ try {
196
+ const pingMessage = `Ping from client (${now})`;
197
+ (_a = this.websocket) === null || _a === void 0 || _a.ping(pingMessage);
198
+ if (this.lastPongReceivedTimestamp === void 0) pingAttemptCount += 1;
199
+ else pingAttemptCount = 0;
200
+ if (this.options.pingPongLoggingEnabled) this.logger.debug(`Sent ping to Slack: ${pingMessage}`);
201
+ } catch (e) {
202
+ this.logger.error(`Failed to send ping to Slack (error: ${e})`);
203
+ this.disconnect();
204
+ return;
205
+ }
206
+ let isInvalid = pingAttemptCount > 3;
207
+ if (this.lastPongReceivedTimestamp !== void 0) isInvalid = now - this.lastPongReceivedTimestamp > this.options.clientPingTimeoutMS;
208
+ if (isInvalid) {
209
+ this.logger.warn(`A pong wasn't received from the server before the timeout of ${this.options.clientPingTimeoutMS}ms!`);
210
+ this.disconnect();
211
+ }
212
+ }, this.options.clientPingTimeoutMS / 3);
213
+ this.logger.debug("Started monitoring pings to and pongs from Slack.");
214
+ }
215
+ };
216
+ exports.SlackWebSocket = SlackWebSocket;
217
+ SlackWebSocket.loggerName = "SlackWebSocket";
218
+ }));
219
+
220
+ //#endregion
221
+ export default require_SlackWebSocket();
222
+
223
+ export { require_SlackWebSocket };