@inkeep/agents-work-apps 0.0.0-dev-20260401162720 → 0.0.0-dev-20260401192843

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 (34) hide show
  1. package/dist/github/mcp/auth.d.ts +2 -2
  2. package/dist/github/mcp/index.d.ts +2 -2
  3. package/dist/github/routes/setup.d.ts +2 -2
  4. package/dist/github/routes/tokenExchange.d.ts +2 -2
  5. package/dist/github/routes/webhooks.d.ts +2 -2
  6. package/dist/slack/mcp/auth.d.ts +2 -2
  7. package/dist/slack/mcp/index.d.ts +2 -2
  8. package/dist/slack/middleware/permissions.d.ts +3 -3
  9. package/dist/slack/socket-mode.js +1 -2
  10. package/package.json +4 -3
  11. package/dist/_virtual/rolldown_runtime.js +0 -32
  12. package/dist/node_modules/.pnpm/@slack_logger@4.0.0/node_modules/@slack/logger/dist/index.js +0 -89
  13. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/package.js +0 -85
  14. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js +0 -223
  15. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js +0 -367
  16. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/UnrecoverableSocketModeStartError.js +0 -20
  17. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/errors.js +0 -71
  18. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/index.js +0 -44
  19. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/logger.js +0 -32
  20. package/dist/node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js +0 -241
  21. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/index.js +0 -23
  22. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js +0 -107
  23. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js +0 -29
  24. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js +0 -226
  25. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js +0 -150
  26. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js +0 -57
  27. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js +0 -342
  28. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js +0 -457
  29. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js +0 -505
  30. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js +0 -123
  31. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js +0 -46
  32. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js +0 -203
  33. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js +0 -385
  34. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js +0 -985
@@ -1,7 +1,7 @@
1
- import * as hono0 from "hono";
1
+ import * as hono2 from "hono";
2
2
 
3
3
  //#region src/github/mcp/auth.d.ts
4
- declare const githubMcpAuth: () => hono0.MiddlewareHandler<{
4
+ declare const githubMcpAuth: () => hono2.MiddlewareHandler<{
5
5
  Variables: {
6
6
  toolId: string;
7
7
  tenantId: string;
@@ -1,5 +1,5 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types5 from "hono/types";
2
+ import * as hono_types4 from "hono/types";
3
3
 
4
4
  //#region src/github/mcp/index.d.ts
5
5
  declare const app: Hono<{
@@ -8,6 +8,6 @@ declare const app: Hono<{
8
8
  tenantId: string;
9
9
  projectId: string;
10
10
  };
11
- }, hono_types5.BlankSchema, "/">;
11
+ }, hono_types4.BlankSchema, "/">;
12
12
  //#endregion
13
13
  export { app as default };
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types6 from "hono/types";
2
+ import * as hono_types7 from "hono/types";
3
3
 
4
4
  //#region src/github/routes/setup.d.ts
5
- declare const app: Hono<hono_types6.BlankEnv, hono_types6.BlankSchema, "/">;
5
+ declare const app: Hono<hono_types7.BlankEnv, hono_types7.BlankSchema, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types3 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_types3.BlankEnv, hono_types3.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_types8 from "hono/types";
2
+ import * as hono_types9 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_types8.BlankEnv, hono_types8.BlankSchema, "/">;
10
+ declare const app: Hono<hono_types9.BlankEnv, hono_types9.BlankSchema, "/">;
11
11
  //#endregion
12
12
  export { WebhookVerificationResult, app as default, verifyWebhookSignature };
@@ -1,7 +1,7 @@
1
- import * as hono0 from "hono";
1
+ import * as hono1 from "hono";
2
2
 
3
3
  //#region src/slack/mcp/auth.d.ts
4
- declare const slackMcpAuth: () => hono0.MiddlewareHandler<{
4
+ declare const slackMcpAuth: () => hono1.MiddlewareHandler<{
5
5
  Variables: {
6
6
  toolId: string;
7
7
  tenantId: string;
@@ -1,5 +1,5 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types10 from "hono/types";
2
+ import * as hono_types0 from "hono/types";
3
3
 
4
4
  //#region src/slack/mcp/index.d.ts
5
5
  interface ChannelInfo {
@@ -18,6 +18,6 @@ declare const app: Hono<{
18
18
  tenantId: string;
19
19
  projectId: string;
20
20
  };
21
- }, hono_types10.BlankSchema, "/">;
21
+ }, hono_types0.BlankSchema, "/">;
22
22
  //#endregion
23
23
  export { ChannelInfo, app as default, pruneStaleChannelIds };
@@ -1,5 +1,5 @@
1
1
  import { ManageAppVariables } from "../types.js";
2
- import * as hono1 from "hono";
2
+ import * as hono0 from "hono";
3
3
 
4
4
  //#region src/slack/middleware/permissions.d.ts
5
5
  /**
@@ -14,7 +14,7 @@ declare const requireWorkspaceAdmin: <Env extends {
14
14
  Variables: ManageAppVariables;
15
15
  } = {
16
16
  Variables: ManageAppVariables;
17
- }>() => hono1.MiddlewareHandler<Env, string, {}, Response>;
17
+ }>() => hono0.MiddlewareHandler<Env, string, {}, Response>;
18
18
  /**
19
19
  * Middleware that requires either:
20
20
  * 1. Org admin/owner role (can modify any channel), OR
@@ -26,6 +26,6 @@ declare const requireChannelMemberOrAdmin: <Env extends {
26
26
  Variables: ManageAppVariables;
27
27
  } = {
28
28
  Variables: ManageAppVariables;
29
- }>() => hono1.MiddlewareHandler<Env, string, {}, Response>;
29
+ }>() => hono0.MiddlewareHandler<Env, string, {}, Response>;
30
30
  //#endregion
31
31
  export { isOrgAdmin, requireChannelMemberOrAdmin, requireWorkspaceAdmin };
@@ -1,4 +1,3 @@
1
- import { __toESM } from "../_virtual/rolldown_runtime.js";
2
1
  import { getLogger } from "../logger.js";
3
2
  import { SLACK_SPAN_KEYS, SLACK_SPAN_NAMES, tracer } from "./tracer.js";
4
3
  import { handleCommand } from "./services/commands/index.js";
@@ -15,7 +14,7 @@ async function startSocketMode(appToken) {
15
14
  logger.info({}, "Socket Mode client already running (HMR reload detected), skipping");
16
15
  return;
17
16
  }
18
- const { SocketModeClient } = await import("../node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/index.js").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
17
+ const { SocketModeClient } = await import("@slack/socket-mode");
19
18
  const client = new SocketModeClient({ appToken });
20
19
  setupSocketModeListeners(client);
21
20
  await client.start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-work-apps",
3
- "version": "0.0.0-dev-20260401162720",
3
+ "version": "0.0.0-dev-20260401192843",
4
4
  "description": "First party integrations for Inkeep Agents",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -25,6 +25,7 @@
25
25
  "@octokit/auth-app": "^8.1.2",
26
26
  "@octokit/rest": "^22.0.1",
27
27
  "@opentelemetry/api": "^1.9.0",
28
+ "@slack/socket-mode": "^2.0.5",
28
29
  "@slack/types": "^2.18.0",
29
30
  "@slack/web-api": "^7.9.1",
30
31
  "drizzle-orm": "^0.44.7",
@@ -34,14 +35,13 @@
34
35
  "minimatch": "^10.2.1",
35
36
  "oxfmt": "^0.42.0",
36
37
  "slack-block-builder": "^2.8.0",
37
- "@inkeep/agents-core": "0.0.0-dev-20260401162720"
38
+ "@inkeep/agents-core": "0.0.0-dev-20260401192843"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "@hono/zod-openapi": "^1.1.5",
41
42
  "zod": "^4.3.6"
42
43
  },
43
44
  "devDependencies": {
44
- "@slack/socket-mode": "^2.0.5",
45
45
  "@types/node": "^20.11.24",
46
46
  "typescript": "^6.0.2",
47
47
  "vitest": "^3.2.4"
@@ -64,6 +64,7 @@
64
64
  "directory": "packages/agents-workapps"
65
65
  },
66
66
  "scripts": {
67
+ "knip": "knip --directory ../.. --workspace packages/agents-work-apps --dependencies",
67
68
  "build": "tsdown",
68
69
  "dev": "pnpm build --watch",
69
70
  "test": "vitest --run",
@@ -1,32 +0,0 @@
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 };
@@ -1,89 +0,0 @@
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 };
@@ -1,85 +0,0 @@
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 };
@@ -1,223 +0,0 @@
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 };