meocord 4.0.0 → 4.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # meocord
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#290](https://github.com/meocord/meocord/pull/290) [`6e6e68e`](https://github.com/meocord/meocord/commit/6e6e68eff696481b40810b2bf713f2bec769b564) Thanks [@l7aromeo](https://github.com/l7aromeo)! - `Logger` prints objects as `console.log` does, and redacts the bot's credentials from everything it prints: non-enumerable properties no longer appear, and objects print four levels deep.
8
+
9
+ - Nested data a bot logs, such as a payload or its settings, still shows in full, and a discord.js structure prints a few hundred lines instead of everything it reaches.
10
+ - An error prints as before: its stack, its own properties such as `code`, its `cause`, and an `AggregateError`'s errors. Its message and stack are no longer printed a second time below it.
11
+ - Nothing to change in your code.
12
+
3
13
  ## 4.0.0
4
14
 
5
15
  MeoCord 4 builds with Rsbuild instead of webpack, requires Node.js 22.13 and dotenv 18, and can
@@ -31,7 +31,7 @@ let configLoaded = false;
31
31
  try {
32
32
  // Called through a variable so a bundler does not try to resolve the path while building the
33
33
  // application; the file is only there once the build is done.
34
- const load = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('_shared/theme-C8w8ivsR.cjs', document.baseURI).href)));
34
+ const load = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('_shared/theme-Bt2Xw_fH.cjs', document.baseURI).href)));
35
35
  const loaded = load(compiledPath);
36
36
  return loaded.default ?? loaded;
37
37
  } catch (error) {
@@ -42,6 +42,34 @@ let configLoaded = false;
42
42
 
43
43
  dayjs.extend(utc);
44
44
  dayjs.extend(timezone);
45
+ /**
46
+ * How deep an object argument prints: nested data a bot logs, such as a payload or its settings, shows in full, while
47
+ * a discord.js structure, which reaches its client and every cache, stops at a few hundred lines.
48
+ */ const OBJECT_DEPTH = 4;
49
+ /** What a value registered with {@link hideInLogs} prints as. */ const REDACTED = '[redacted]';
50
+ /**
51
+ * The shortest value registered: a bot's credential is far longer, and a short value, such as a test's placeholder,
52
+ * would replace ordinary words in every line.
53
+ */ const MIN_HIDDEN_LENGTH = 16;
54
+ const hiddenValues = new Set();
55
+ /**
56
+ * Keeps `value`, such as the bot's credential, out of every line Logger prints from now on, whatever object, string
57
+ * or error carries it: as given, trimmed, and without the `Bot ` or `Bearer ` prefix discord.js strips.
58
+ */ function hideInLogs(value) {
59
+ if (typeof value !== 'string') return;
60
+ const trimmed = value.trim();
61
+ for (const form of [
62
+ trimmed,
63
+ trimmed.replace(/^(Bot|Bearer)\s*/i, '')
64
+ ]){
65
+ if (form.length >= MIN_HIDDEN_LENGTH) hiddenValues.add(form);
66
+ }
67
+ }
68
+ const redact = (text)=>{
69
+ let out = text;
70
+ for (const value of hiddenValues)out = out.replaceAll(value, REDACTED);
71
+ return out;
72
+ };
45
73
  class Logger {
46
74
  log(...args) {
47
75
  this.logWithContext('log', args);
@@ -63,12 +91,11 @@ class Logger {
63
91
  }
64
92
  formatMessage(message, logType) {
65
93
  if (typeof message === 'object' && message !== null) {
94
+ // As console.log inspects: without non-enumerable properties, which discord.js uses to keep its internals out of logs
66
95
  return node_util.inspect(message, {
67
- showHidden: true,
68
- depth: null,
96
+ depth: OBJECT_DEPTH,
69
97
  colors: true,
70
- compact: false,
71
- showProxy: true
98
+ compact: false
72
99
  });
73
100
  }
74
101
  return (this.colorMap[logType] || ((msg)=>msg))(message);
@@ -76,6 +103,7 @@ class Logger {
76
103
  logWithContext(logLevel, messages) {
77
104
  if (messages.length === 0) return;
78
105
  const config = loadMeoCordConfig();
106
+ hideInLogs(config?.discordToken);
79
107
  const logType = logLevel.toUpperCase();
80
108
  const applyColor = this.colorMap[logType] || ((msg)=>msg);
81
109
  const formattedMessages = messages.map((message)=>this.formatMessage(message, logType));
@@ -90,7 +118,7 @@ class Logger {
90
118
  coloredContext,
91
119
  ...formattedMessages
92
120
  ].filter((log)=>!!log);
93
- console[logLevel](...logTexts);
121
+ console[logLevel](...logTexts.map(redact));
94
122
  }
95
123
  constructor(context){
96
124
  this.context = context;
@@ -113,4 +141,5 @@ Theme.warningColor = '#FFC107';
113
141
 
114
142
  exports.Logger = Logger;
115
143
  exports.Theme = Theme;
144
+ exports.hideInLogs = hideInLogs;
116
145
  exports.loadMeoCordConfig = loadMeoCordConfig;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var theme = require('../_shared/theme-C8w8ivsR.cjs');
3
+ var theme = require('../_shared/theme-Bt2Xw_fH.cjs');
4
4
  require('node:util');
5
5
  require('dayjs');
6
6
  require('dayjs/plugin/utc.js');
@@ -3,7 +3,7 @@
3
3
  require('reflect-metadata');
4
4
  var inversify = require('inversify');
5
5
  var discord_js = require('discord.js');
6
- var theme = require('../_shared/theme-C8w8ivsR.cjs');
6
+ var theme = require('../_shared/theme-Bt2Xw_fH.cjs');
7
7
  var controller_decorator = require('../_shared/controller.decorator-DnKZ29W4.cjs');
8
8
  var lodashEs = require('lodash-es');
9
9
  var enum_index = require('../enum/index.cjs');
@@ -467,6 +467,8 @@ class MeoCordApp {
467
467
  this.isShuttingDown = false;
468
468
  this.activityInterval = null;
469
469
  this.controllerInstancesCache = new Map();
470
+ // First, so nothing logged from here on, before login or after, prints it
471
+ theme.hideInLogs(discordToken);
470
472
  this.bot = this.discordClient;
471
473
  process.on('SIGINT', ()=>this.gracefulShutdown());
472
474
  process.on('SIGTERM', ()=>this.gracefulShutdown());
@@ -7,6 +7,34 @@ import chalk from 'chalk';
7
7
 
8
8
  dayjs.extend(utc);
9
9
  dayjs.extend(timezone);
10
+ /**
11
+ * How deep an object argument prints: nested data a bot logs, such as a payload or its settings, shows in full, while
12
+ * a discord.js structure, which reaches its client and every cache, stops at a few hundred lines.
13
+ */ const OBJECT_DEPTH = 4;
14
+ /** What a value registered with {@link hideInLogs} prints as. */ const REDACTED = '[redacted]';
15
+ /**
16
+ * The shortest value registered: a bot's credential is far longer, and a short value, such as a test's placeholder,
17
+ * would replace ordinary words in every line.
18
+ */ const MIN_HIDDEN_LENGTH = 16;
19
+ const hiddenValues = new Set();
20
+ /**
21
+ * Keeps `value`, such as the bot's credential, out of every line Logger prints from now on, whatever object, string
22
+ * or error carries it: as given, trimmed, and without the `Bot ` or `Bearer ` prefix discord.js strips.
23
+ */ function hideInLogs(value) {
24
+ if (typeof value !== 'string') return;
25
+ const trimmed = value.trim();
26
+ for (const form of [
27
+ trimmed,
28
+ trimmed.replace(/^(Bot|Bearer)\s*/i, '')
29
+ ]){
30
+ if (form.length >= MIN_HIDDEN_LENGTH) hiddenValues.add(form);
31
+ }
32
+ }
33
+ const redact = (text)=>{
34
+ let out = text;
35
+ for (const value of hiddenValues)out = out.replaceAll(value, REDACTED);
36
+ return out;
37
+ };
10
38
  class Logger {
11
39
  log(...args) {
12
40
  this.logWithContext('log', args);
@@ -28,12 +56,11 @@ class Logger {
28
56
  }
29
57
  formatMessage(message, logType) {
30
58
  if (typeof message === 'object' && message !== null) {
59
+ // As console.log inspects: without non-enumerable properties, which discord.js uses to keep its internals out of logs
31
60
  return inspect(message, {
32
- showHidden: true,
33
- depth: null,
61
+ depth: OBJECT_DEPTH,
34
62
  colors: true,
35
- compact: false,
36
- showProxy: true
63
+ compact: false
37
64
  });
38
65
  }
39
66
  return (this.colorMap[logType] || ((msg)=>msg))(message);
@@ -41,6 +68,7 @@ class Logger {
41
68
  logWithContext(logLevel, messages) {
42
69
  if (messages.length === 0) return;
43
70
  const config = loadMeoCordConfig();
71
+ hideInLogs(config?.discordToken);
44
72
  const logType = logLevel.toUpperCase();
45
73
  const applyColor = this.colorMap[logType] || ((msg)=>msg);
46
74
  const formattedMessages = messages.map((message)=>this.formatMessage(message, logType));
@@ -55,7 +83,7 @@ class Logger {
55
83
  coloredContext,
56
84
  ...formattedMessages
57
85
  ].filter((log)=>!!log);
58
- console[logLevel](...logTexts);
86
+ console[logLevel](...logTexts.map(redact));
59
87
  }
60
88
  constructor(context){
61
89
  this.context = context;
@@ -69,4 +97,4 @@ class Logger {
69
97
  }
70
98
  }
71
99
 
72
- export { Logger };
100
+ export { Logger, REDACTED, hideInLogs };
@@ -1,5 +1,5 @@
1
1
  import { ApplicationCommandType, SlashCommandBuilder, MessageFlagsBitField } from 'discord.js';
2
- import { Logger } from '../common/logger.js';
2
+ import { Logger, hideInLogs } from '../common/logger.js';
3
3
  import '../common/theme.js';
4
4
  import { getCommandMap, PARAM_SEPARATOR, getAutocompleteHandlers, getMessageHandlers, getReactionHandlers } from '../decorator/controller.decorator.js';
5
5
  import { sample } from 'lodash-es';
@@ -450,6 +450,8 @@ class MeoCordApp {
450
450
  this.isShuttingDown = false;
451
451
  this.activityInterval = null;
452
452
  this.controllerInstancesCache = new Map();
453
+ // First, so nothing logged from here on, before login or after, prints it
454
+ hideInLogs(discordToken);
453
455
  this.bot = this.discordClient;
454
456
  process.on('SIGINT', ()=>this.gracefulShutdown());
455
457
  process.on('SIGTERM', ()=>this.gracefulShutdown());
@@ -1,4 +1,4 @@
1
- var version = "4.0.0";
1
+ var version = "4.0.1";
2
2
  var packageJson = {
3
3
  version: version};
4
4
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "meocord",
3
3
  "description": "Decorator-based Discord bot framework built on discord.js. Brings NestJS-style controllers, dependency injection, guards, and testing utilities to bot development — with a full CLI and TypeScript-first design.",
4
- "version": "4.0.0",
4
+ "version": "4.0.1",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=22.13"
@@ -26,11 +26,11 @@
26
26
  "bin": "./dist/esm/bin/meocord.js",
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "git+https://github.com/l7aromeo/meocord.git"
29
+ "url": "git+https://github.com/meocord/meocord.git"
30
30
  },
31
- "homepage": "https://github.com/l7aromeo/meocord#readme",
31
+ "homepage": "https://meocord.dev",
32
32
  "bugs": {
33
- "url": "https://github.com/l7aromeo/meocord/issues"
33
+ "url": "https://github.com/meocord/meocord/issues"
34
34
  },
35
35
  "license": "MIT",
36
36
  "exports": {