@dynamic-labs/logger 4.46.3 → 4.47.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,4 +1,25 @@
1
1
 
2
+ ### [4.47.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.47.0...v4.47.1) (2025-11-24)
3
+
4
+
5
+ ### Features
6
+
7
+ * add aptos non-native coins to sendBalance ([#9914](https://github.com/dynamic-labs/dynamic-auth/issues/9914)) ([0f0f855](https://github.com/dynamic-labs/dynamic-auth/commit/0f0f855229a052eb280831c81d235b0164f26ff3))
8
+ * add aptos non-native token sending to dynamic widget ([#9915](https://github.com/dynamic-labs/dynamic-auth/issues/9915)) ([c91c117](https://github.com/dynamic-labs/dynamic-auth/commit/c91c1172d5185c151f9b4cac1a0757f6d72304ca))
9
+ * **react-native:** add waas wallet upgrade to react-native ([#9936](https://github.com/dynamic-labs/dynamic-auth/issues/9936)) ([024366e](https://github.com/dynamic-labs/dynamic-auth/commit/024366e179b284353d0b05667e916a01520b2874))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * remove noise from wallet connect when it is disabled ([#9945](https://github.com/dynamic-labs/dynamic-auth/issues/9945)) ([ada6511](https://github.com/dynamic-labs/dynamic-auth/commit/ada6511e2d25351f1b63312eb4810752f6d95ad6))
15
+
16
+ ## [4.47.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.46.3...v4.47.0) (2025-11-21)
17
+
18
+
19
+ ### Features
20
+
21
+ * add Google Drive backup functionality to widget ([#9899](https://github.com/dynamic-labs/dynamic-auth/issues/9899)) ([c787c5b](https://github.com/dynamic-labs/dynamic-auth/commit/c787c5baa7cf4ec4522418fdbe915923b1481312))
22
+
2
23
  ### [4.46.3](https://github.com/dynamic-labs/dynamic-auth/compare/v4.46.2...v4.46.3) (2025-11-20)
3
24
 
4
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/logger",
3
- "version": "4.46.3",
3
+ "version": "4.47.1",
4
4
  "description": "A simple client side logging library used in Dynamic SDK",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
package/src/index.cjs CHANGED
@@ -10,15 +10,34 @@ var types = require('./types.cjs');
10
10
  var createCircularReferenceReplacer = require('./utils/createCircularReferenceReplacer.cjs');
11
11
  var mapLogLevel = require('./utils/mapLogLevel.cjs');
12
12
  var processArgs = require('./utils/processArgs.cjs');
13
+ var getStack = require('./utils/getStack.cjs');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
16
17
  var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
17
18
 
18
19
  /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
20
+ // 1. Define a unique global key
21
+ const LOGGER_GLOBAL_STATE_KEY = Symbol.for('__DYNAMIC_LOGGER_GLOBAL_STATE__');
22
+ // 3. Initialize or retrieve the global state
23
+ const globalState = globalThis[LOGGER_GLOBAL_STATE_KEY] || {
24
+ events: new EventEmitter__default["default"](),
25
+ keys: { emitErrors: true },
26
+ logLevel: undefined,
27
+ metaData: new MetaData.MetaData(),
28
+ troubleshootModeEnabled: false,
29
+ };
30
+ // Ensure the state persists on the global object
31
+ globalThis[LOGGER_GLOBAL_STATE_KEY] = globalState;
19
32
  const IGNORE_MESSAGES = ['Failed to send logs to server'];
20
33
  const messageQueue = [];
21
34
  class Logger {
35
+ static get troubleshootModeEnabled() {
36
+ return globalState.troubleshootModeEnabled;
37
+ }
38
+ static set troubleshootModeEnabled(val) {
39
+ globalState.troubleshootModeEnabled = val;
40
+ }
22
41
  constructor(name, level) {
23
42
  this.name = name;
24
43
  this._level = undefined;
@@ -42,12 +61,12 @@ class Logger {
42
61
  }
43
62
  static setEmitErrors(emit) {
44
63
  if (emit !== undefined) {
45
- Logger.globalKeys.emitErrors = emit;
64
+ globalState.keys.emitErrors = emit;
46
65
  }
47
66
  }
48
67
  static setEnvironmentId(environmentId) {
49
68
  if (environmentId !== undefined) {
50
- Logger.globalKeys.environmentId = environmentId;
69
+ globalState.keys.environmentId = environmentId;
51
70
  }
52
71
  }
53
72
  getNameArray(name) {
@@ -63,15 +82,15 @@ class Logger {
63
82
  this._level = mapLogLevel.mapLogLevel(level);
64
83
  }
65
84
  static setLogLevel(level) {
66
- Logger.globalLogLevel = mapLogLevel.mapLogLevel(level);
85
+ globalState.logLevel = mapLogLevel.mapLogLevel(level);
67
86
  }
68
87
  static resetLogLevel() {
69
- Logger.globalLogLevel = undefined;
88
+ globalState.logLevel = undefined;
70
89
  }
71
90
  get level() {
72
91
  var _a;
73
- if (Logger.globalLogLevel && !this._level) {
74
- return Logger.globalLogLevel;
92
+ if (globalState.logLevel && !this._level) {
93
+ return globalState.logLevel;
75
94
  }
76
95
  if (this._level === undefined &&
77
96
  typeof process !== 'undefined' &&
@@ -102,7 +121,7 @@ class Logger {
102
121
  }
103
122
  captureAndSend(level, message, ...args) {
104
123
  return _tslib.__awaiter(this, void 0, void 0, function* () {
105
- if (Logger.globalKeys.emitErrors &&
124
+ if (globalState.keys.emitErrors &&
106
125
  !IGNORE_MESSAGES.includes(message === null || message === void 0 ? void 0 : message.toString()) &&
107
126
  typeof window !== 'undefined') {
108
127
  this.emitHttpLogs(level, message, { args });
@@ -110,7 +129,8 @@ class Logger {
110
129
  });
111
130
  }
112
131
  emitHttpLogs(level, message, { args = [], transformMeta = (meta) => meta }) {
113
- messageQueue.push({ args, level, message, stack: new Error().stack });
132
+ const stack = getStack.getStack(this.emitHttpLogs);
133
+ messageQueue.push({ args, level, message, stack });
114
134
  if (messageQueue.length === 1) {
115
135
  /**
116
136
  * Batching the logs to send them in a single request
@@ -119,9 +139,10 @@ class Logger {
119
139
  * Essentially, multiple calls to log in the same event loop will be batched into a single request
120
140
  */
121
141
  queueMicrotask(() => _tslib.__awaiter(this, void 0, void 0, function* () {
122
- var _a, _b;
142
+ // Grab all pending messages immediately and clear the queue
143
+ const currentBatch = messageQueue.splice(0, messageQueue.length);
123
144
  const messages = [];
124
- messageQueue.forEach((msg) => {
145
+ currentBatch.forEach((msg) => {
125
146
  var _a, _b, _c, _d, _e, _f;
126
147
  const body = {};
127
148
  const { objectArgs, remainingArgs } = processArgs.processArgs(msg);
@@ -129,7 +150,7 @@ class Logger {
129
150
  Object.assign(body, {
130
151
  level: types.LogLevel[msg.level],
131
152
  message: [msg.message, ...remainingArgs].join(' '),
132
- meta: transformMeta(Logger.globalMetaData.merge(this.metaData).get()),
153
+ meta: transformMeta(globalState.metaData.merge(this.metaData).get()),
133
154
  stack: msg.stack,
134
155
  url: {
135
156
  hostname: (_a = window.location) === null || _a === void 0 ? void 0 : _a.hostname,
@@ -143,10 +164,10 @@ class Logger {
143
164
  messages.push(body);
144
165
  });
145
166
  try {
146
- if (!((_a = Logger.globalKeys) === null || _a === void 0 ? void 0 : _a.environmentId)) {
167
+ if (!globalState.keys.environmentId) {
147
168
  throw new Error('Environment ID not set');
148
169
  }
149
- yield fetch(`https://logs.dynamicauth.com/api/v1/${(_b = Logger.globalKeys) === null || _b === void 0 ? void 0 : _b.environmentId}`, {
170
+ yield fetch(`https://logs.dynamicauth.com/api/v1/${globalState.keys.environmentId}`, {
150
171
  body: JSON.stringify(messages),
151
172
  headers: {
152
173
  'Content-Type': 'application/json',
@@ -159,7 +180,7 @@ class Logger {
159
180
  catch (error) {
160
181
  this.debug('Failed to send logs to server', error);
161
182
  }
162
- messageQueue.length = 0;
183
+ // REMOVE: messageQueue.length = 0;
163
184
  }));
164
185
  }
165
186
  }
@@ -179,7 +200,7 @@ class Logger {
179
200
  (level < this.level || level === types.LogLevel.MUTE)) {
180
201
  return;
181
202
  }
182
- Logger.events.emit('log', level, message, ...args);
203
+ globalState.events.emit('log', level, message, ...args);
183
204
  const fmtMsg = this.formatMessage(level, message);
184
205
  switch (level) {
185
206
  case types.LogLevel.WARN:
@@ -211,13 +232,9 @@ class Logger {
211
232
  this.log(types.LogLevel.ERROR, message, ...args);
212
233
  }
213
234
  }
214
- Logger.globalLogLevel = undefined;
215
- Logger.globalKeys = {
216
- emitErrors: true,
217
- };
218
- Logger.troubleshootModeEnabled = false;
219
- Logger.globalMetaData = new MetaData.MetaData();
220
- Logger.events = new EventEmitter__default["default"]();
235
+ Logger.globalMetaData = globalState.metaData;
236
+ // REPLACED: public static events = new EventEmitter...
237
+ Logger.events = globalState.events;
221
238
 
222
239
  Object.defineProperty(exports, 'LogLevel', {
223
240
  enumerable: true,
package/src/index.d.ts CHANGED
@@ -20,18 +20,17 @@ export type InstrumentOptions = {
20
20
  };
21
21
  export declare class Logger {
22
22
  private name;
23
- private static globalLogLevel;
24
23
  private _level;
25
- private static globalKeys;
26
- static troubleshootModeEnabled: boolean;
24
+ static get troubleshootModeEnabled(): boolean;
25
+ static set troubleshootModeEnabled(val: boolean);
27
26
  static globalMetaData: MetaData;
28
27
  metaData: MetaData;
28
+ static events: EventEmitter<{
29
+ log: (level: LogLevel, message: unknown, ...args: any[]) => void;
30
+ }, any>;
29
31
  constructor(name: string | string[], level?: LogLevel);
30
32
  static setEmitErrors(emit?: boolean): void;
31
33
  static setEnvironmentId(environmentId?: string): void;
32
- static events: EventEmitter<{
33
- log: (level: LogLevel, message: Message, ...args: any[]) => void;
34
- }, any>;
35
34
  private getNameArray;
36
35
  createLogger(name: string | string[], level?: LogLevel): Logger;
37
36
  get logLevel(): string;
package/src/index.js CHANGED
@@ -7,11 +7,30 @@ export { LogLevel } from './types.js';
7
7
  import { createCircularReferenceReplacer } from './utils/createCircularReferenceReplacer.js';
8
8
  import { mapLogLevel } from './utils/mapLogLevel.js';
9
9
  import { processArgs } from './utils/processArgs.js';
10
+ import { getStack } from './utils/getStack.js';
10
11
 
11
12
  /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
13
+ // 1. Define a unique global key
14
+ const LOGGER_GLOBAL_STATE_KEY = Symbol.for('__DYNAMIC_LOGGER_GLOBAL_STATE__');
15
+ // 3. Initialize or retrieve the global state
16
+ const globalState = globalThis[LOGGER_GLOBAL_STATE_KEY] || {
17
+ events: new EventEmitter(),
18
+ keys: { emitErrors: true },
19
+ logLevel: undefined,
20
+ metaData: new MetaData(),
21
+ troubleshootModeEnabled: false,
22
+ };
23
+ // Ensure the state persists on the global object
24
+ globalThis[LOGGER_GLOBAL_STATE_KEY] = globalState;
12
25
  const IGNORE_MESSAGES = ['Failed to send logs to server'];
13
26
  const messageQueue = [];
14
27
  class Logger {
28
+ static get troubleshootModeEnabled() {
29
+ return globalState.troubleshootModeEnabled;
30
+ }
31
+ static set troubleshootModeEnabled(val) {
32
+ globalState.troubleshootModeEnabled = val;
33
+ }
15
34
  constructor(name, level) {
16
35
  this.name = name;
17
36
  this._level = undefined;
@@ -35,12 +54,12 @@ class Logger {
35
54
  }
36
55
  static setEmitErrors(emit) {
37
56
  if (emit !== undefined) {
38
- Logger.globalKeys.emitErrors = emit;
57
+ globalState.keys.emitErrors = emit;
39
58
  }
40
59
  }
41
60
  static setEnvironmentId(environmentId) {
42
61
  if (environmentId !== undefined) {
43
- Logger.globalKeys.environmentId = environmentId;
62
+ globalState.keys.environmentId = environmentId;
44
63
  }
45
64
  }
46
65
  getNameArray(name) {
@@ -56,15 +75,15 @@ class Logger {
56
75
  this._level = mapLogLevel(level);
57
76
  }
58
77
  static setLogLevel(level) {
59
- Logger.globalLogLevel = mapLogLevel(level);
78
+ globalState.logLevel = mapLogLevel(level);
60
79
  }
61
80
  static resetLogLevel() {
62
- Logger.globalLogLevel = undefined;
81
+ globalState.logLevel = undefined;
63
82
  }
64
83
  get level() {
65
84
  var _a;
66
- if (Logger.globalLogLevel && !this._level) {
67
- return Logger.globalLogLevel;
85
+ if (globalState.logLevel && !this._level) {
86
+ return globalState.logLevel;
68
87
  }
69
88
  if (this._level === undefined &&
70
89
  typeof process !== 'undefined' &&
@@ -95,7 +114,7 @@ class Logger {
95
114
  }
96
115
  captureAndSend(level, message, ...args) {
97
116
  return __awaiter(this, void 0, void 0, function* () {
98
- if (Logger.globalKeys.emitErrors &&
117
+ if (globalState.keys.emitErrors &&
99
118
  !IGNORE_MESSAGES.includes(message === null || message === void 0 ? void 0 : message.toString()) &&
100
119
  typeof window !== 'undefined') {
101
120
  this.emitHttpLogs(level, message, { args });
@@ -103,7 +122,8 @@ class Logger {
103
122
  });
104
123
  }
105
124
  emitHttpLogs(level, message, { args = [], transformMeta = (meta) => meta }) {
106
- messageQueue.push({ args, level, message, stack: new Error().stack });
125
+ const stack = getStack(this.emitHttpLogs);
126
+ messageQueue.push({ args, level, message, stack });
107
127
  if (messageQueue.length === 1) {
108
128
  /**
109
129
  * Batching the logs to send them in a single request
@@ -112,9 +132,10 @@ class Logger {
112
132
  * Essentially, multiple calls to log in the same event loop will be batched into a single request
113
133
  */
114
134
  queueMicrotask(() => __awaiter(this, void 0, void 0, function* () {
115
- var _a, _b;
135
+ // Grab all pending messages immediately and clear the queue
136
+ const currentBatch = messageQueue.splice(0, messageQueue.length);
116
137
  const messages = [];
117
- messageQueue.forEach((msg) => {
138
+ currentBatch.forEach((msg) => {
118
139
  var _a, _b, _c, _d, _e, _f;
119
140
  const body = {};
120
141
  const { objectArgs, remainingArgs } = processArgs(msg);
@@ -122,7 +143,7 @@ class Logger {
122
143
  Object.assign(body, {
123
144
  level: LogLevel[msg.level],
124
145
  message: [msg.message, ...remainingArgs].join(' '),
125
- meta: transformMeta(Logger.globalMetaData.merge(this.metaData).get()),
146
+ meta: transformMeta(globalState.metaData.merge(this.metaData).get()),
126
147
  stack: msg.stack,
127
148
  url: {
128
149
  hostname: (_a = window.location) === null || _a === void 0 ? void 0 : _a.hostname,
@@ -136,10 +157,10 @@ class Logger {
136
157
  messages.push(body);
137
158
  });
138
159
  try {
139
- if (!((_a = Logger.globalKeys) === null || _a === void 0 ? void 0 : _a.environmentId)) {
160
+ if (!globalState.keys.environmentId) {
140
161
  throw new Error('Environment ID not set');
141
162
  }
142
- yield fetch(`https://logs.dynamicauth.com/api/v1/${(_b = Logger.globalKeys) === null || _b === void 0 ? void 0 : _b.environmentId}`, {
163
+ yield fetch(`https://logs.dynamicauth.com/api/v1/${globalState.keys.environmentId}`, {
143
164
  body: JSON.stringify(messages),
144
165
  headers: {
145
166
  'Content-Type': 'application/json',
@@ -152,7 +173,7 @@ class Logger {
152
173
  catch (error) {
153
174
  this.debug('Failed to send logs to server', error);
154
175
  }
155
- messageQueue.length = 0;
176
+ // REMOVE: messageQueue.length = 0;
156
177
  }));
157
178
  }
158
179
  }
@@ -172,7 +193,7 @@ class Logger {
172
193
  (level < this.level || level === LogLevel.MUTE)) {
173
194
  return;
174
195
  }
175
- Logger.events.emit('log', level, message, ...args);
196
+ globalState.events.emit('log', level, message, ...args);
176
197
  const fmtMsg = this.formatMessage(level, message);
177
198
  switch (level) {
178
199
  case LogLevel.WARN:
@@ -204,12 +225,8 @@ class Logger {
204
225
  this.log(LogLevel.ERROR, message, ...args);
205
226
  }
206
227
  }
207
- Logger.globalLogLevel = undefined;
208
- Logger.globalKeys = {
209
- emitErrors: true,
210
- };
211
- Logger.troubleshootModeEnabled = false;
212
- Logger.globalMetaData = new MetaData();
213
- Logger.events = new EventEmitter();
228
+ Logger.globalMetaData = globalState.metaData;
229
+ // REPLACED: public static events = new EventEmitter...
230
+ Logger.events = globalState.events;
214
231
 
215
232
  export { Logger };
@@ -0,0 +1,24 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const getStack = (constructorOpt) => {
7
+ const err = {};
8
+ // Standard V8 API to capture stack trace
9
+ if (Error.captureStackTrace) {
10
+ Error.captureStackTrace(err, constructorOpt);
11
+ return err.stack;
12
+ }
13
+ // Fallback for non-V8 environments (e.g. Firefox/Safari)
14
+ // We manually strip the top frames if we are using new Error()
15
+ const { stack } = new Error();
16
+ if (stack && constructorOpt) {
17
+ // Simple heuristic: skip the top lines usually associated with Error creation
18
+ // This is less precise than captureStackTrace but often sufficient for fallbacks
19
+ return stack.split('\n').slice(2).join('\n');
20
+ }
21
+ return stack;
22
+ };
23
+
24
+ exports.getStack = getStack;
@@ -0,0 +1 @@
1
+ export declare const getStack: (constructorOpt?: (...args: any[]) => any) => string | undefined;
@@ -0,0 +1,20 @@
1
+ 'use client'
2
+ const getStack = (constructorOpt) => {
3
+ const err = {};
4
+ // Standard V8 API to capture stack trace
5
+ if (Error.captureStackTrace) {
6
+ Error.captureStackTrace(err, constructorOpt);
7
+ return err.stack;
8
+ }
9
+ // Fallback for non-V8 environments (e.g. Firefox/Safari)
10
+ // We manually strip the top frames if we are using new Error()
11
+ const { stack } = new Error();
12
+ if (stack && constructorOpt) {
13
+ // Simple heuristic: skip the top lines usually associated with Error creation
14
+ // This is less precise than captureStackTrace but often sufficient for fallbacks
15
+ return stack.split('\n').slice(2).join('\n');
16
+ }
17
+ return stack;
18
+ };
19
+
20
+ export { getStack };