@xpr/nestjs-slack 0.2.0 → 0.3.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.
- package/package.json +1 -1
- package/slack.d.ts +2 -2
- package/slack.js +7 -2
- package/utils.d.ts +2 -0
- package/utils.js +20 -1
package/package.json
CHANGED
package/slack.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CustomTransportStrategy, type MessageHandler, Server } from
|
|
2
|
-
import { App, type AppOptions } from
|
|
1
|
+
import { type CustomTransportStrategy, type MessageHandler, Server } from '@nestjs/microservices';
|
|
2
|
+
import { App, type AppOptions } from '@slack/bolt';
|
|
3
3
|
export type SlackOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Slack application options with required types
|
package/slack.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const microservices_1 = require("@nestjs/microservices");
|
|
4
4
|
const bolt_1 = require("@slack/bolt");
|
|
5
5
|
const decorators_1 = require("./decorators");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
6
7
|
class Slack extends microservices_1.Server {
|
|
7
8
|
options;
|
|
8
9
|
#app;
|
|
@@ -23,7 +24,7 @@ class Slack extends microservices_1.Server {
|
|
|
23
24
|
this.#app && (await this.#app.stop());
|
|
24
25
|
}
|
|
25
26
|
on() {
|
|
26
|
-
throw new Error(
|
|
27
|
+
throw new Error('Use SlackEvent decorator to register events');
|
|
27
28
|
}
|
|
28
29
|
unwrap() {
|
|
29
30
|
return this.#app;
|
|
@@ -55,8 +56,12 @@ class Slack extends microservices_1.Server {
|
|
|
55
56
|
*/
|
|
56
57
|
app() {
|
|
57
58
|
if (!this.#app) {
|
|
59
|
+
// make sure to add logger if not provided
|
|
60
|
+
if (!this.options.slack.logger) {
|
|
61
|
+
this.options.slack.logger = (0, utils_1.adjustLogger)(this.logger);
|
|
62
|
+
}
|
|
58
63
|
this.#app = new bolt_1.App(this.options.slack);
|
|
59
|
-
this.logger.log(
|
|
64
|
+
this.logger.log('Bolt app created');
|
|
60
65
|
}
|
|
61
66
|
return this.#app;
|
|
62
67
|
}
|
package/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Logger } from '@slack/bolt';
|
|
1
2
|
export type Pattern = string | RegExp;
|
|
2
3
|
/**
|
|
3
4
|
* Create method decorator
|
|
@@ -11,3 +12,4 @@ export declare function eventDecorator<T>(type: string, event: T): MethodDecorat
|
|
|
11
12
|
* @param pattern how to identify the message
|
|
12
13
|
*/
|
|
13
14
|
export declare function messageDecorator(type: string, pattern: Pattern): MethodDecorator;
|
|
15
|
+
export declare function adjustLogger(logger: any): Logger;
|
package/utils.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.eventDecorator = eventDecorator;
|
|
4
4
|
exports.messageDecorator = messageDecorator;
|
|
5
|
+
exports.adjustLogger = adjustLogger;
|
|
5
6
|
const microservices_1 = require("@nestjs/microservices");
|
|
7
|
+
const bolt_1 = require("@slack/bolt");
|
|
6
8
|
const normalizePattern = (pattern) => {
|
|
7
|
-
if (typeof pattern ===
|
|
9
|
+
if (typeof pattern === 'string') {
|
|
8
10
|
return pattern;
|
|
9
11
|
}
|
|
10
12
|
if (pattern instanceof RegExp) {
|
|
@@ -34,3 +36,20 @@ function messageDecorator(type, pattern) {
|
|
|
34
36
|
pattern,
|
|
35
37
|
})(target, key, descriptor);
|
|
36
38
|
}
|
|
39
|
+
function adjustLogger(logger) {
|
|
40
|
+
if (!('debug' in logger && 'info' in logger && 'warn' in logger && 'error' in logger)) {
|
|
41
|
+
throw new Error('Logger must implement the minimal Logger interface');
|
|
42
|
+
}
|
|
43
|
+
return Object.assign(logger, {
|
|
44
|
+
setLevel(_) {
|
|
45
|
+
// don't allow library to set the level
|
|
46
|
+
},
|
|
47
|
+
setName(_) {
|
|
48
|
+
// don't allow library to set the name
|
|
49
|
+
},
|
|
50
|
+
getLevel() {
|
|
51
|
+
// always return the lowest supported level
|
|
52
|
+
return bolt_1.LogLevel.DEBUG;
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|