@intuitionrobotics/thunderstorm 0.42.74 → 0.42.75

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,36 @@
1
+ /**
2
+ * Created by AlanBen on 29/08/2019.
3
+ */
4
+ import { Module, OnApplicationError, ServerErrorSeverity } from "@intuitionrobotics/ts-common";
5
+ import { WebClientOptions } from "@slack/web-api";
6
+ declare type ConfigType = {
7
+ token: string;
8
+ defaultChannel: string;
9
+ throttlingTime?: number;
10
+ slackConfig?: Partial<WebClientOptions>;
11
+ };
12
+ declare type _SlackMessage = {
13
+ text: string;
14
+ channel: string;
15
+ };
16
+ export declare type SlackMessage = string | _SlackMessage;
17
+ export declare class SlackModule_Class extends Module<ConfigType> {
18
+ private web;
19
+ private messageMap;
20
+ constructor();
21
+ protected init(): void;
22
+ postMessage(slackMessage: SlackMessage): Promise<void>;
23
+ private postMessageImpl;
24
+ }
25
+ export declare const SlackModule: SlackModule_Class;
26
+ declare type ApiErrorConfig = {
27
+ exclude: string[];
28
+ minLevel: ServerErrorSeverity;
29
+ };
30
+ export declare class Slack_ServerApiError_Class extends Module<ApiErrorConfig> implements OnApplicationError {
31
+ constructor();
32
+ protected init(): void;
33
+ __processApplicationError(errorLevel: ServerErrorSeverity, module: Module, message: string): Promise<void>;
34
+ }
35
+ export declare const Slack_ServerApiError: Slack_ServerApiError_Class;
36
+ export {};
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ /*
3
+ * Storm contains a list of utility functions.. this project
4
+ * might be broken down into more smaller projects in the future.
5
+ *
6
+ * Copyright (C) 2020 Intuition Robotics
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
21
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
+ return new (P || (P = Promise))(function (resolve, reject) {
23
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
27
+ });
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.Slack_ServerApiError = exports.Slack_ServerApiError_Class = exports.SlackModule = exports.SlackModule_Class = void 0;
31
+ /**
32
+ * Created by AlanBen on 29/08/2019.
33
+ */
34
+ /*
35
+ * Storm contains a list of utility functions.. this project
36
+ * might be broken down into more smaller projects in the future.
37
+ *
38
+ * Copyright (C) 2020 Intuition Robotics
39
+ *
40
+ * Licensed under the Apache License, Version 2.0 (the "License");
41
+ * you may not use this file except in compliance with the License.
42
+ * You may obtain a copy of the License at
43
+ *
44
+ * http://www.apache.org/licenses/LICENSE-2.0
45
+ *
46
+ * Unless required by applicable law or agreed to in writing, software
47
+ * distributed under the License is distributed on an "AS IS" BASIS,
48
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
+ * See the License for the specific language governing permissions and
50
+ * limitations under the License.
51
+ */
52
+ const ts_common_1 = require("@intuitionrobotics/ts-common");
53
+ const web_api_1 = require("@slack/web-api");
54
+ class SlackModule_Class extends ts_common_1.Module {
55
+ constructor() {
56
+ super("slack");
57
+ this.messageMap = {};
58
+ }
59
+ init() {
60
+ if (!this.config.token)
61
+ return;
62
+ // throw new ImplementationMissingException('Missing config token for SlackModule. Please add it');
63
+ this.web = new web_api_1.WebClient(this.config.token, Object.assign({ rejectRateLimitedCalls: true }, this.config.slackConfig));
64
+ }
65
+ postMessage(slackMessage) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const parameters = typeof slackMessage === 'string' ? {
68
+ text: slackMessage,
69
+ channel: this.config.defaultChannel
70
+ } : slackMessage;
71
+ const time = this.messageMap[parameters.text];
72
+ if (time && ts_common_1.currentTimeMillies() - time < (this.config.throttlingTime || ts_common_1.Minute))
73
+ return;
74
+ try {
75
+ return yield this.postMessageImpl(parameters);
76
+ }
77
+ catch (e) {
78
+ this.logError(`Error while sending a message to channel: ${parameters.channel}`, e);
79
+ }
80
+ });
81
+ }
82
+ postMessageImpl(message) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const res = yield this.web.chat.postMessage(message);
85
+ this.messageMap[message.text] = ts_common_1.currentTimeMillies();
86
+ this.logDebug(`A message was posted to channel: ${message.channel} with message id ${res.ts} which contains the message ${message.text}`);
87
+ });
88
+ }
89
+ }
90
+ exports.SlackModule_Class = SlackModule_Class;
91
+ exports.SlackModule = new SlackModule_Class();
92
+ class Slack_ServerApiError_Class extends ts_common_1.Module {
93
+ constructor() {
94
+ super();
95
+ this.setDefaultConfig({ exclude: [], minLevel: ts_common_1.ServerErrorSeverity.Info });
96
+ }
97
+ init() {
98
+ }
99
+ __processApplicationError(errorLevel, module, message) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ if (ts_common_1.ServerErrorSeverity_Ordinal.indexOf(errorLevel) < ts_common_1.ServerErrorSeverity_Ordinal.indexOf(this.config.minLevel))
102
+ return;
103
+ for (const key of this.config.exclude || []) {
104
+ if (message.includes(key))
105
+ return;
106
+ }
107
+ yield exports.SlackModule.postMessage(`\`\`\`${message}\`\`\``);
108
+ });
109
+ }
110
+ }
111
+ exports.Slack_ServerApiError_Class = Slack_ServerApiError_Class;
112
+ exports.Slack_ServerApiError = new Slack_ServerApiError_Class();
113
+ //# sourceMappingURL=SlackModule.js.map
@@ -0,0 +1 @@
1
+ {"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5
5
  "keywords": [
6
6
  "IR",
@@ -29,12 +29,16 @@
29
29
  "dependencies": {
30
30
  "@intuitionrobotics/firebase": "~0.42.0",
31
31
  "@intuitionrobotics/ts-common": "~0.42.0",
32
+ "@slack/web-api": "^5.1.0",
32
33
  "axios": "^1.4.0",
34
+ "body-parser": "^1.19.0",
33
35
  "buffer": "^6.0.3",
36
+ "compression": "^1.7.4",
34
37
  "express": "^4.16.4",
38
+ "history": "^4.9.0",
35
39
  "react": "^16.0.0",
36
40
  "react-dom": "^16.0.0",
37
- "react-router": "^5.1.2",
41
+ "react-router-dom": "^5.1.2",
38
42
  "react-select": "^4.0.0"
39
43
  },
40
44
  "devDependencies": {
@@ -48,13 +52,8 @@
48
52
  "@types/react-router": "^5.1.4",
49
53
  "@types/react-router-dom": "^5.1.3",
50
54
  "@types/react-select": "^4.0.0",
51
- "body-parser": "^1.19.0",
52
- "compression": "^1.7.4",
53
- "history": "^4.9.0",
54
- "react-router-dom": "^5.1.2",
55
55
  "ts-node": "^9.1.1",
56
56
  "tslint": "^5.16.0",
57
- "typescript": "~4.1.0",
58
- "use-strict": "^1.0.1"
57
+ "typescript": "~4.1.0"
59
58
  }
60
59
  }