@xpr/nestjs-slack 0.3.0 → 0.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpr/nestjs-slack",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "NestJS server implementation of the Slack Assistant",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/slack.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type CustomTransportStrategy, type MessageHandler, Server } from '@nestjs/microservices';
2
- import { App, type AppOptions } from '@slack/bolt';
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
@@ -24,7 +24,7 @@ class Slack extends microservices_1.Server {
24
24
  this.#app && (await this.#app.stop());
25
25
  }
26
26
  on() {
27
- throw new Error('Use SlackEvent decorator to register events');
27
+ throw new Error("Use SlackEvent decorator to register events");
28
28
  }
29
29
  unwrap() {
30
30
  return this.#app;
@@ -61,7 +61,7 @@ class Slack extends microservices_1.Server {
61
61
  this.options.slack.logger = (0, utils_1.adjustLogger)(this.logger);
62
62
  }
63
63
  this.#app = new bolt_1.App(this.options.slack);
64
- this.logger.log('Bolt app created');
64
+ this.logger.log("Bolt app created");
65
65
  }
66
66
  return this.#app;
67
67
  }
package/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Logger } from '@slack/bolt';
1
+ import { type Logger } from "@slack/bolt";
2
2
  export type Pattern = string | RegExp;
3
3
  /**
4
4
  * Create method decorator
package/utils.js CHANGED
@@ -6,7 +6,7 @@ exports.adjustLogger = adjustLogger;
6
6
  const microservices_1 = require("@nestjs/microservices");
7
7
  const bolt_1 = require("@slack/bolt");
8
8
  const normalizePattern = (pattern) => {
9
- if (typeof pattern === 'string') {
9
+ if (typeof pattern === "string") {
10
10
  return pattern;
11
11
  }
12
12
  if (pattern instanceof RegExp) {
@@ -37,18 +37,28 @@ function messageDecorator(type, pattern) {
37
37
  })(target, key, descriptor);
38
38
  }
39
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');
40
+ // this patch required to support NestJS logger that not use the standard "info"
41
+ // and use "log" instead
42
+ if (logger["log"] && !logger["info"]) {
43
+ logger["info"] = logger["log"].bind(logger);
44
+ }
45
+ // minimal logger interface required by @slack/bolt library
46
+ for (const method of ["debug", "info", "warn", "error"]) {
47
+ if (typeof logger[method] !== "function") {
48
+ throw new Error(`Logger must implement "${method}" method`);
49
+ }
42
50
  }
43
51
  return Object.assign(logger, {
44
52
  setLevel(_) {
45
53
  // don't allow library to set the level
46
54
  },
47
- setName(_) {
48
- // don't allow library to set the name
55
+ setName(name) {
56
+ // search for all possible setName/setContext methods, use "noop" if none
57
+ (logger.setName ?? logger.setContext ?? ((i) => i))(name);
49
58
  },
50
59
  getLevel() {
51
- // always return the lowest supported level
60
+ // always return the lowest supported level (by library, not real logger)
61
+ // to avoid filtering log messages by library instead of real logger
52
62
  return bolt_1.LogLevel.DEBUG;
53
63
  },
54
64
  });