@dynamic-labs/logger 2.1.0-alpha.5 → 2.1.0-alpha.7

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,18 @@
1
1
 
2
+ ## [2.1.0-alpha.7](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.6...v2.1.0-alpha.7) (2024-04-25)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * restore embedded wallet session iframe element conflict ([#5474](https://github.com/dynamic-labs/DynamicAuth/issues/5474)) ([c157477](https://github.com/dynamic-labs/DynamicAuth/commit/c157477ea126b3130b13b711796bdd06215e7af1))
8
+
9
+ ## [2.1.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.5...v2.1.0-alpha.6) (2024-04-24)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * embedded wallets headless session control fixes ([#5469](https://github.com/dynamic-labs/DynamicAuth/issues/5469)) ([92e6c35](https://github.com/dynamic-labs/DynamicAuth/commit/92e6c359d2710fd4f5f5a6fedc4acf6c4bab78ba))
15
+
2
16
  ## [2.1.0-alpha.5](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.4...v2.1.0-alpha.5) (2024-04-23)
3
17
 
4
18
 
@@ -0,0 +1,36 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ function __awaiter(thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ }
30
+
31
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
+ var e = new Error(message);
33
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
+ };
35
+
36
+ exports.__awaiter = __awaiter;
@@ -0,0 +1,32 @@
1
+ 'use client'
2
+ /******************************************************************************
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
15
+ ***************************************************************************** */
16
+
17
+ function __awaiter(thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ }
26
+
27
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
28
+ var e = new Error(message);
29
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
30
+ };
31
+
32
+ export { __awaiter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/logger",
3
- "version": "2.1.0-alpha.5",
3
+ "version": "2.1.0-alpha.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
package/src/index.cjs CHANGED
@@ -3,28 +3,62 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
+ var _tslib = require('../_virtual/_tslib.cjs');
7
+ var types = require('./types.cjs');
8
+ var deepMerge = require('./utils/deepMerge.cjs');
9
+ var processArgs = require('./utils/processArgs.cjs');
10
+
6
11
  /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
7
- exports.LogLevel = void 0;
8
- (function (LogLevel) {
9
- LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
10
- LogLevel[LogLevel["INFO"] = 1] = "INFO";
11
- LogLevel[LogLevel["WARN"] = 2] = "WARN";
12
- LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
13
- LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
14
- })(exports.LogLevel || (exports.LogLevel = {}));
12
+ const IGNORE_MESSAGES = ['Failed to send logs to server'];
13
+ const messageQueue = [];
15
14
  class Logger {
16
15
  constructor(name, level) {
17
16
  this.name = name;
17
+ this.meta = undefined;
18
18
  if (level === undefined && process.env['NODE_ENV'] !== 'production') {
19
- this.level = exports.LogLevel.DEBUG;
19
+ this.level = types.LogLevel.DEBUG;
20
20
  }
21
21
  else if (level === undefined) {
22
- this.level = exports.LogLevel.WARN;
22
+ this.level = types.LogLevel.WARN;
23
23
  }
24
24
  else {
25
25
  this.level = level;
26
26
  }
27
27
  }
28
+ static setEmitErrors(emit) {
29
+ if (emit !== undefined) {
30
+ Logger.globalKeys.emitErrors = emit;
31
+ }
32
+ }
33
+ static setEnvironmentId(environmentId) {
34
+ if (environmentId !== undefined) {
35
+ Logger.globalKeys.environmentId = environmentId;
36
+ }
37
+ }
38
+ static setGlobalKey(key, value) {
39
+ if (!Logger.globalKeys) {
40
+ Logger.globalKeys = {};
41
+ }
42
+ Logger.globalKeys[key] = value;
43
+ }
44
+ setMetaData(key, value) {
45
+ if (!this.meta) {
46
+ this.meta = {};
47
+ }
48
+ const data = {};
49
+ key.split('.').reduce((acc, k, i, arr) => {
50
+ if (i === arr.length - 1) {
51
+ acc[k] = value;
52
+ }
53
+ else {
54
+ if (!acc[k]) {
55
+ acc[k] = {};
56
+ }
57
+ return acc[k];
58
+ }
59
+ }, data);
60
+ this.meta = deepMerge.deepMerge(this.meta, data);
61
+ }
28
62
  getNameArray(name) {
29
63
  return Array.isArray(name) ? name : [name];
30
64
  }
@@ -32,13 +66,13 @@ class Logger {
32
66
  return new Logger([...this.getNameArray(this.name), ...this.getNameArray(name)], level !== null && level !== void 0 ? level : this.level);
33
67
  }
34
68
  get logLevel() {
35
- return exports.LogLevel[this.level];
69
+ return types.LogLevel[this.level];
36
70
  }
37
71
  setLogLevel(level) {
38
- if (level in exports.LogLevel && typeof level === 'string') {
39
- this.level = exports.LogLevel[level];
72
+ if (level in types.LogLevel && typeof level === 'string') {
73
+ this.level = types.LogLevel[level];
40
74
  }
41
- else if (level in exports.LogLevel && typeof level === 'number') {
75
+ else if (level in types.LogLevel && typeof level === 'number') {
42
76
  this.level = level;
43
77
  }
44
78
  else {
@@ -59,36 +93,104 @@ class Logger {
59
93
  message = JSON.stringify(message);
60
94
  }
61
95
  const names = (Array.isArray(this.name) ? this.name : [this.name]).map((name) => `[${name}]`);
62
- return `${names.join('')} [${exports.LogLevel[level]}]: ${message}`;
96
+ return `${names.join('')} [${types.LogLevel[level]}]: ${message}`;
97
+ }
98
+ captureAndSend(level, message, ...args) {
99
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
100
+ if (Logger.globalKeys.emitErrors &&
101
+ !IGNORE_MESSAGES.includes(message === null || message === void 0 ? void 0 : message.toString()) &&
102
+ typeof window !== 'undefined') {
103
+ this.emitHttpLogs(level, message, ...args);
104
+ }
105
+ });
106
+ }
107
+ emitHttpLogs(level, message, ...args) {
108
+ messageQueue.push({ args, level, message });
109
+ if (messageQueue.length === 1) {
110
+ /**
111
+ * Batching the logs to send them in a single request
112
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide#batching_operations
113
+ *
114
+ * Essentially, multiple calls to log in the same event loop will be batched into a single request
115
+ */
116
+ queueMicrotask(() => _tslib.__awaiter(this, void 0, void 0, function* () {
117
+ var _a, _b;
118
+ const messages = [];
119
+ messageQueue.forEach((msg) => {
120
+ const body = {};
121
+ const { objectArgs, remainingArgs } = processArgs.processArgs(msg);
122
+ Object.assign(body, ...objectArgs);
123
+ Object.assign(body, {
124
+ level: types.LogLevel[msg.level],
125
+ message: [msg.message, ...remainingArgs].join(' '),
126
+ meta: this.meta,
127
+ url: {
128
+ hostname: window.location.hostname,
129
+ origin: window.location.origin,
130
+ pathname: window.location.pathname,
131
+ port: window.location.port,
132
+ protocol: window.location.protocol,
133
+ },
134
+ });
135
+ messages.push(body);
136
+ });
137
+ try {
138
+ if (!((_a = Logger.globalKeys) === null || _a === void 0 ? void 0 : _a.environmentId)) {
139
+ throw new Error('Environment ID not set');
140
+ }
141
+ yield fetch(`https://logs.dynamicauth.com/api/v1/${(_b = Logger.globalKeys) === null || _b === void 0 ? void 0 : _b.environmentId}`, {
142
+ body: JSON.stringify(messages),
143
+ headers: {
144
+ 'Content-Type': 'application/json',
145
+ },
146
+ method: 'POST',
147
+ mode: 'cors',
148
+ referrerPolicy: 'origin-when-cross-origin',
149
+ });
150
+ }
151
+ catch (error) {
152
+ this.debug('Failed to send logs to server', error);
153
+ }
154
+ messageQueue.length = 0;
155
+ }));
156
+ }
63
157
  }
64
158
  log(level, message, ...args) {
65
- if (level < this.level || level === exports.LogLevel.MUTE) {
159
+ if (level < this.level || level === types.LogLevel.MUTE) {
66
160
  return;
67
161
  }
68
162
  const fmtMsg = this.formatMessage(level, message);
69
163
  switch (level) {
70
- case exports.LogLevel.WARN:
164
+ case types.LogLevel.WARN:
71
165
  console.warn(fmtMsg, ...args);
72
166
  break;
73
- case exports.LogLevel.ERROR:
167
+ case types.LogLevel.ERROR:
74
168
  console.error(fmtMsg, ...args);
75
169
  break;
76
170
  default:
77
171
  console.log(fmtMsg, ...args);
78
172
  }
173
+ if (level === types.LogLevel.ERROR) {
174
+ this.captureAndSend(level, message, ...args);
175
+ }
79
176
  }
80
177
  debug(message, ...args) {
81
- this.log(exports.LogLevel.DEBUG, message, ...args);
178
+ this.log(types.LogLevel.DEBUG, message, ...args);
82
179
  }
83
180
  info(message, ...args) {
84
- this.log(exports.LogLevel.INFO, message, ...args);
181
+ this.log(types.LogLevel.INFO, message, ...args);
85
182
  }
86
183
  warn(message, ...args) {
87
- this.log(exports.LogLevel.WARN, message, ...args);
184
+ this.log(types.LogLevel.WARN, message, ...args);
88
185
  }
89
186
  error(message, ...args) {
90
- this.log(exports.LogLevel.ERROR, message, ...args);
187
+ this.log(types.LogLevel.ERROR, message, ...args);
91
188
  }
92
189
  }
190
+ Logger.globalKeys = {};
93
191
 
192
+ Object.defineProperty(exports, 'LogLevel', {
193
+ enumerable: true,
194
+ get: function () { return types.LogLevel; }
195
+ });
94
196
  exports.Logger = Logger;
package/src/index.d.ts CHANGED
@@ -1,24 +1,25 @@
1
- export declare enum LogLevel {
2
- DEBUG = 0,
3
- INFO = 1,
4
- WARN = 2,
5
- ERROR = 3,
6
- MUTE = 99
7
- }
8
- type Message = string | Error | unknown;
1
+ import { LogLevel, Message } from './types';
2
+ export { LogLevel } from './types';
9
3
  export declare class Logger {
10
4
  private name;
11
5
  private level;
6
+ private static globalKeys;
7
+ private meta;
12
8
  constructor(name: string | string[], level?: LogLevel);
9
+ static setEmitErrors(emit?: boolean): void;
10
+ static setEnvironmentId(environmentId?: string): void;
11
+ static setGlobalKey(key: string, value: any): void;
12
+ setMetaData(key: string, value: any): void;
13
13
  private getNameArray;
14
14
  createLogger(name: string | string[], level?: LogLevel): Logger;
15
15
  get logLevel(): string;
16
16
  setLogLevel(level: LogLevel | keyof typeof LogLevel): void;
17
17
  private formatMessage;
18
+ private captureAndSend;
19
+ private emitHttpLogs;
18
20
  log(level: LogLevel, message: Message, ...args: any[]): void;
19
21
  debug(message: Message, ...args: any[]): void;
20
22
  info(message: Message, ...args: any[]): void;
21
23
  warn(message: Message, ...args: any[]): void;
22
24
  error(message: Message, ...args: any[]): void;
23
25
  }
24
- export {};
package/src/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  'use client'
2
+ import { __awaiter } from '../_virtual/_tslib.js';
3
+ import { LogLevel } from './types.js';
4
+ export { LogLevel } from './types.js';
5
+ import { deepMerge } from './utils/deepMerge.js';
6
+ import { processArgs } from './utils/processArgs.js';
7
+
2
8
  /* eslint-disable @typescript-eslint/no-explicit-any, no-console */
3
- var LogLevel;
4
- (function (LogLevel) {
5
- LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
6
- LogLevel[LogLevel["INFO"] = 1] = "INFO";
7
- LogLevel[LogLevel["WARN"] = 2] = "WARN";
8
- LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
9
- LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
10
- })(LogLevel || (LogLevel = {}));
9
+ const IGNORE_MESSAGES = ['Failed to send logs to server'];
10
+ const messageQueue = [];
11
11
  class Logger {
12
12
  constructor(name, level) {
13
13
  this.name = name;
14
+ this.meta = undefined;
14
15
  if (level === undefined && process.env['NODE_ENV'] !== 'production') {
15
16
  this.level = LogLevel.DEBUG;
16
17
  }
@@ -21,6 +22,40 @@ class Logger {
21
22
  this.level = level;
22
23
  }
23
24
  }
25
+ static setEmitErrors(emit) {
26
+ if (emit !== undefined) {
27
+ Logger.globalKeys.emitErrors = emit;
28
+ }
29
+ }
30
+ static setEnvironmentId(environmentId) {
31
+ if (environmentId !== undefined) {
32
+ Logger.globalKeys.environmentId = environmentId;
33
+ }
34
+ }
35
+ static setGlobalKey(key, value) {
36
+ if (!Logger.globalKeys) {
37
+ Logger.globalKeys = {};
38
+ }
39
+ Logger.globalKeys[key] = value;
40
+ }
41
+ setMetaData(key, value) {
42
+ if (!this.meta) {
43
+ this.meta = {};
44
+ }
45
+ const data = {};
46
+ key.split('.').reduce((acc, k, i, arr) => {
47
+ if (i === arr.length - 1) {
48
+ acc[k] = value;
49
+ }
50
+ else {
51
+ if (!acc[k]) {
52
+ acc[k] = {};
53
+ }
54
+ return acc[k];
55
+ }
56
+ }, data);
57
+ this.meta = deepMerge(this.meta, data);
58
+ }
24
59
  getNameArray(name) {
25
60
  return Array.isArray(name) ? name : [name];
26
61
  }
@@ -57,6 +92,66 @@ class Logger {
57
92
  const names = (Array.isArray(this.name) ? this.name : [this.name]).map((name) => `[${name}]`);
58
93
  return `${names.join('')} [${LogLevel[level]}]: ${message}`;
59
94
  }
95
+ captureAndSend(level, message, ...args) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ if (Logger.globalKeys.emitErrors &&
98
+ !IGNORE_MESSAGES.includes(message === null || message === void 0 ? void 0 : message.toString()) &&
99
+ typeof window !== 'undefined') {
100
+ this.emitHttpLogs(level, message, ...args);
101
+ }
102
+ });
103
+ }
104
+ emitHttpLogs(level, message, ...args) {
105
+ messageQueue.push({ args, level, message });
106
+ if (messageQueue.length === 1) {
107
+ /**
108
+ * Batching the logs to send them in a single request
109
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide#batching_operations
110
+ *
111
+ * Essentially, multiple calls to log in the same event loop will be batched into a single request
112
+ */
113
+ queueMicrotask(() => __awaiter(this, void 0, void 0, function* () {
114
+ var _a, _b;
115
+ const messages = [];
116
+ messageQueue.forEach((msg) => {
117
+ const body = {};
118
+ const { objectArgs, remainingArgs } = processArgs(msg);
119
+ Object.assign(body, ...objectArgs);
120
+ Object.assign(body, {
121
+ level: LogLevel[msg.level],
122
+ message: [msg.message, ...remainingArgs].join(' '),
123
+ meta: this.meta,
124
+ url: {
125
+ hostname: window.location.hostname,
126
+ origin: window.location.origin,
127
+ pathname: window.location.pathname,
128
+ port: window.location.port,
129
+ protocol: window.location.protocol,
130
+ },
131
+ });
132
+ messages.push(body);
133
+ });
134
+ try {
135
+ if (!((_a = Logger.globalKeys) === null || _a === void 0 ? void 0 : _a.environmentId)) {
136
+ throw new Error('Environment ID not set');
137
+ }
138
+ yield fetch(`https://logs.dynamicauth.com/api/v1/${(_b = Logger.globalKeys) === null || _b === void 0 ? void 0 : _b.environmentId}`, {
139
+ body: JSON.stringify(messages),
140
+ headers: {
141
+ 'Content-Type': 'application/json',
142
+ },
143
+ method: 'POST',
144
+ mode: 'cors',
145
+ referrerPolicy: 'origin-when-cross-origin',
146
+ });
147
+ }
148
+ catch (error) {
149
+ this.debug('Failed to send logs to server', error);
150
+ }
151
+ messageQueue.length = 0;
152
+ }));
153
+ }
154
+ }
60
155
  log(level, message, ...args) {
61
156
  if (level < this.level || level === LogLevel.MUTE) {
62
157
  return;
@@ -72,6 +167,9 @@ class Logger {
72
167
  default:
73
168
  console.log(fmtMsg, ...args);
74
169
  }
170
+ if (level === LogLevel.ERROR) {
171
+ this.captureAndSend(level, message, ...args);
172
+ }
75
173
  }
76
174
  debug(message, ...args) {
77
175
  this.log(LogLevel.DEBUG, message, ...args);
@@ -86,5 +184,6 @@ class Logger {
86
184
  this.log(LogLevel.ERROR, message, ...args);
87
185
  }
88
186
  }
187
+ Logger.globalKeys = {};
89
188
 
90
- export { LogLevel, Logger };
189
+ export { Logger };
package/src/types.cjs ADDED
@@ -0,0 +1,13 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ exports.LogLevel = void 0;
7
+ (function (LogLevel) {
8
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
9
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
10
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
11
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
12
+ LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
13
+ })(exports.LogLevel || (exports.LogLevel = {}));
package/src/types.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export declare enum LogLevel {
2
+ DEBUG = 0,
3
+ INFO = 1,
4
+ WARN = 2,
5
+ ERROR = 3,
6
+ MUTE = 99
7
+ }
8
+ export type Message = string | Error | unknown;
9
+ export type MessageQueueMessage = {
10
+ level: LogLevel;
11
+ message: Message;
12
+ args: any[];
13
+ };
package/src/types.js ADDED
@@ -0,0 +1,11 @@
1
+ 'use client'
2
+ var LogLevel;
3
+ (function (LogLevel) {
4
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
5
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
6
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
7
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
8
+ LogLevel[LogLevel["MUTE"] = 99] = "MUTE";
9
+ })(LogLevel || (LogLevel = {}));
10
+
11
+ export { LogLevel };
@@ -0,0 +1,57 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const deepMerge = (obj1, obj2) => {
7
+ if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {
8
+ // If either obj1 or obj2 is not an object, return obj1
9
+ return obj2;
10
+ }
11
+ // Create a new object to store the merged result
12
+ const result = Object.assign({}, obj1);
13
+ for (const key in obj2) {
14
+ if (Object.prototype.hasOwnProperty.call(obj2, key)) {
15
+ if (typeof obj2[key] === 'object' &&
16
+ Object.prototype.hasOwnProperty.call(obj1, key) &&
17
+ typeof obj1[key] === 'object') {
18
+ // If both obj1 and obj2 have objects with the same key, recursively merge them
19
+ result[key] = deepMerge(obj1[key], obj2[key]);
20
+ }
21
+ else {
22
+ // Otherwise, simply assign the value from obj2 to the result
23
+ result[key] = obj2[key];
24
+ }
25
+ }
26
+ }
27
+ return result;
28
+ };
29
+ // Example usage:
30
+ //
31
+ // const obj1 = {
32
+ // a: 1,
33
+ // b: {
34
+ // c: 2,
35
+ // d: 3,
36
+ // },
37
+ // };
38
+ //
39
+ // const obj2 = {
40
+ // a: 4,
41
+ // b: {
42
+ // c: 5,
43
+ // },
44
+ // e: 6,
45
+ // };
46
+ //
47
+ // const result = {
48
+ // a: 4,
49
+ // b: {
50
+ // c: 5,
51
+ // d: 3,
52
+ // },
53
+ // e: 6,
54
+ // };
55
+ //
56
+
57
+ exports.deepMerge = deepMerge;
@@ -0,0 +1 @@
1
+ export declare const deepMerge: <T>(obj1: any, obj2: any) => T;
@@ -0,0 +1,53 @@
1
+ 'use client'
2
+ const deepMerge = (obj1, obj2) => {
3
+ if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {
4
+ // If either obj1 or obj2 is not an object, return obj1
5
+ return obj2;
6
+ }
7
+ // Create a new object to store the merged result
8
+ const result = Object.assign({}, obj1);
9
+ for (const key in obj2) {
10
+ if (Object.prototype.hasOwnProperty.call(obj2, key)) {
11
+ if (typeof obj2[key] === 'object' &&
12
+ Object.prototype.hasOwnProperty.call(obj1, key) &&
13
+ typeof obj1[key] === 'object') {
14
+ // If both obj1 and obj2 have objects with the same key, recursively merge them
15
+ result[key] = deepMerge(obj1[key], obj2[key]);
16
+ }
17
+ else {
18
+ // Otherwise, simply assign the value from obj2 to the result
19
+ result[key] = obj2[key];
20
+ }
21
+ }
22
+ }
23
+ return result;
24
+ };
25
+ // Example usage:
26
+ //
27
+ // const obj1 = {
28
+ // a: 1,
29
+ // b: {
30
+ // c: 2,
31
+ // d: 3,
32
+ // },
33
+ // };
34
+ //
35
+ // const obj2 = {
36
+ // a: 4,
37
+ // b: {
38
+ // c: 5,
39
+ // },
40
+ // e: 6,
41
+ // };
42
+ //
43
+ // const result = {
44
+ // a: 4,
45
+ // b: {
46
+ // c: 5,
47
+ // d: 3,
48
+ // },
49
+ // e: 6,
50
+ // };
51
+ //
52
+
53
+ export { deepMerge };
@@ -0,0 +1,21 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Split args into object and non-object args
8
+ * @param message
9
+ * @returns
10
+ */
11
+ const processArgs = (message) => {
12
+ // Apply object args to body
13
+ const objectArgs = message.args.filter((arg) => typeof arg === 'object');
14
+ // Capture remaining non-object args
15
+ const remainingArgs = message.args
16
+ .filter((arg) => typeof arg !== 'object' || arg instanceof Error)
17
+ .map((arg) => arg.toString());
18
+ return { objectArgs, remainingArgs };
19
+ };
20
+
21
+ exports.processArgs = processArgs;
@@ -0,0 +1,10 @@
1
+ import { MessageQueueMessage } from '../types';
2
+ /**
3
+ * Split args into object and non-object args
4
+ * @param message
5
+ * @returns
6
+ */
7
+ export declare const processArgs: (message: MessageQueueMessage) => {
8
+ objectArgs: any[];
9
+ remainingArgs: any[];
10
+ };
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ /**
3
+ * Split args into object and non-object args
4
+ * @param message
5
+ * @returns
6
+ */
7
+ const processArgs = (message) => {
8
+ // Apply object args to body
9
+ const objectArgs = message.args.filter((arg) => typeof arg === 'object');
10
+ // Capture remaining non-object args
11
+ const remainingArgs = message.args
12
+ .filter((arg) => typeof arg !== 'object' || arg instanceof Error)
13
+ .map((arg) => arg.toString());
14
+ return { objectArgs, remainingArgs };
15
+ };
16
+
17
+ export { processArgs };