@devrev/ts-adaas 1.11.1-beta.3 → 1.11.1-beta.5

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.
@@ -5,8 +5,8 @@ export declare class Logger extends Console {
5
5
  private originalConsole;
6
6
  private options?;
7
7
  private tags;
8
+ private sdkVersion;
8
9
  constructor({ event, options }: LoggerFactoryInterface);
9
- private valueToString;
10
10
  logFn(args: unknown[], level: LogLevel): void;
11
11
  log(...args: unknown[]): void;
12
12
  info(...args: unknown[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,UAAU,EAAyC,MAAM,OAAO,CAAC;AAG1E,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B,qBAAa,MAAO,SAAQ,OAAO;IACjC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,OAAO,CAAC,CAAuB;IACvC,OAAO,CAAC,IAAI,CAAqC;gBAErC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,sBAAsB;IAUtD,OAAO,CAAC,aAAa;IAYrB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IAepC,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI7B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAGzC;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,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AI,OAAO,OAAO,YAK5C,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAwBzE"}
@@ -1,5 +1,5 @@
1
1
  import { RawAxiosResponseHeaders } from 'axios';
2
- import { AirdropEvent } from '../types/extraction';
2
+ import { AirdropEvent, EventContext } from '../types/extraction';
3
3
  import { WorkerAdapterOptions } from '../types/workers';
4
4
  export interface LoggerFactoryInterface {
5
5
  event: AirdropEvent;
@@ -36,4 +36,7 @@ export interface AxiosErrorResponse {
36
36
  code?: string;
37
37
  message?: string;
38
38
  }
39
+ export interface LogTags extends EventContext {
40
+ sdk_version: string;
41
+ }
39
42
  //# sourceMappingURL=logger.interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.interfaces.d.ts","sourceRoot":"","sources":["../../src/logger/logger.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,CAAC,EAAE,GAAG,CAAC;IAEhB,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAE7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,cAAc,GAAG,cAAc,CAAC;CACtD;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QA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ACzB,CAAC;IACF,YAAY,EAAE,OAAO,CAAC;IACtB,sBAAsB,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,EAAE;QACT,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,EAAE,uBAAuB,CAAC;QACjC,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,OAAQ,SAAQ,YAAY;IAC3C,WAAW,EAAE,MAAM,CAAC;CACrB"}
@@ -7,34 +7,26 @@ exports.serializeAxiosError = serializeAxiosError;
7
7
  const node_console_1 = require("node:console");
8
8
  const node_util_1 = require("node:util");
9
9
  const axios_1 = require("axios");
10
+ const helpers_1 = require("../common/helpers");
10
11
  const logger_interfaces_1 = require("./logger.interfaces");
11
12
  class Logger extends node_console_1.Console {
12
13
  constructor({ event, options }) {
13
14
  super(process.stdout, process.stderr);
14
15
  this.originalConsole = console;
15
16
  this.options = options;
16
- this.tags = Object.assign(Object.assign({}, event.payload.event_context), { dev_oid: event.payload.event_context.dev_oid });
17
- }
18
- valueToString(value) {
19
- if (typeof value === 'string') {
20
- return value;
21
- }
22
- // Use Node.js built-in inspect for everything including errors
23
- return (0, node_util_1.inspect)(value, {
24
- compact: false,
25
- depth: Infinity,
26
- });
17
+ this.sdkVersion = (0, helpers_1.getLibraryVersion)();
18
+ this.tags = Object.assign(Object.assign({}, event.payload.event_context), { sdk_version: this.sdkVersion });
27
19
  }
28
20
  logFn(args, level) {
29
21
  var _a;
30
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) {
31
- this.originalConsole[level](...args);
32
- }
33
- else {
34
- const message = args.map((arg) => this.valueToString(arg)).join(' ');
35
- const logObject = Object.assign({ message }, this.tags);
36
- this.originalConsole[level](JSON.stringify(logObject));
37
- }
22
+ const message = args
23
+ .map((arg) => (0, node_util_1.inspect)(arg, {
24
+ compact: false,
25
+ depth: Infinity,
26
+ }))
27
+ .join(' ');
28
+ const logObject = Object.assign({ message }, (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) ? this.tags : {}));
29
+ this.originalConsole[level](logObject);
38
30
  }
39
31
  log(...args) {
40
32
  this.logFn(args, logger_interfaces_1.LogLevel.INFO);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const node_util_1 = require("node:util");
4
+ const helpers_1 = require("../common/helpers");
4
5
  const test_helpers_1 = require("../tests/test-helpers");
5
6
  const extraction_1 = require("../types/extraction");
6
7
  const logger_1 = require("./logger");
@@ -46,12 +47,12 @@ describe(logger_1.Logger.name, () => {
46
47
  jest.restoreAllMocks();
47
48
  });
48
49
  describe('constructor', () => {
49
- it('should initialize logger with event context and dev_oid', () => {
50
+ it('should initialize logger with event context and sdk_version', () => {
50
51
  const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
51
52
  // Access private property for testing
52
53
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
54
  const tags = logger.tags;
54
- expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid }));
55
+ expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { sdk_version: (0, helpers_1.getLibraryVersion)() }));
55
56
  });
56
57
  });
57
58
  describe('production logging', () => {
@@ -63,7 +64,9 @@ describe(logger_1.Logger.name, () => {
63
64
  it('should log single string message without backslashes', () => {
64
65
  const message = 'Worker is online. Started processing the task.';
65
66
  logger.info(message);
66
- expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid })));
67
+ const callArgs = mockConsoleInfo.mock.calls[0][0];
68
+ const logObject = typeof callArgs === 'string' ? JSON.parse(callArgs) : callArgs;
69
+ expect(logObject).toEqual(Object.assign(Object.assign({ message: `'${message}'` }, mockEvent.payload.event_context), { sdk_version: (0, helpers_1.getLibraryVersion)() }));
67
70
  });
68
71
  it('should log single object message with JSON stringify', () => {
69
72
  const data = { id: 123, name: 'test' };
@@ -72,7 +75,9 @@ describe(logger_1.Logger.name, () => {
72
75
  compact: false,
73
76
  depth: Infinity,
74
77
  });
75
- expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid })));
78
+ const callArgs = mockConsoleInfo.mock.calls[0][0];
79
+ const logObject = typeof callArgs === 'string' ? JSON.parse(callArgs) : callArgs;
80
+ expect(logObject).toEqual(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { sdk_version: (0, helpers_1.getLibraryVersion)() }));
76
81
  });
77
82
  it('should log multiple arguments joined with space', () => {
78
83
  const text = 'Successfully fetched';
@@ -82,7 +87,9 @@ describe(logger_1.Logger.name, () => {
82
87
  compact: false,
83
88
  depth: Infinity,
84
89
  });
85
- expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid })));
90
+ const callArgs = mockConsoleInfo.mock.calls[0][0];
91
+ const logObject = typeof callArgs === 'string' ? JSON.parse(callArgs) : callArgs;
92
+ expect(logObject).toEqual(Object.assign(Object.assign({ message: `'${text}' ${expectedDataMessage}` }, mockEvent.payload.event_context), { sdk_version: (0, helpers_1.getLibraryVersion)() }));
86
93
  });
87
94
  it('should handle mixed string and object arguments', () => {
88
95
  const text1 = 'Processing';
@@ -93,7 +100,9 @@ describe(logger_1.Logger.name, () => {
93
100
  compact: false,
94
101
  depth: Infinity,
95
102
  });
96
- expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid })));
103
+ const callArgs = mockConsoleInfo.mock.calls[0][0];
104
+ const logObject = typeof callArgs === 'string' ? JSON.parse(callArgs) : callArgs;
105
+ expect(logObject).toEqual(Object.assign(Object.assign({ message: `'${text1}' ${expectedDataMessage} '${text2}'` }, mockEvent.payload.event_context), { sdk_version: (0, helpers_1.getLibraryVersion)() }));
97
106
  });
98
107
  });
99
108
  describe('local development logging', () => {
@@ -106,7 +115,14 @@ describe(logger_1.Logger.name, () => {
106
115
  const message = 'Test message';
107
116
  const data = { test: true };
108
117
  logger.info(message, data);
109
- expect(mockConsoleInfo).toHaveBeenCalledWith(message, data);
118
+ // In local development, the logger still uses logFn but without tags
119
+ const expectedMessage = `'${message}' ${(0, node_util_1.inspect)(data, {
120
+ compact: false,
121
+ depth: Infinity,
122
+ })}`;
123
+ expect(mockConsoleInfo).toHaveBeenCalledWith({
124
+ message: expectedMessage,
125
+ });
110
126
  });
111
127
  });
112
128
  describe('log levels', () => {
@@ -142,19 +158,21 @@ describe(logger_1.Logger.name, () => {
142
158
  logger.info('');
143
159
  expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
144
160
  const callArgs = mockConsoleInfo.mock.calls[0][0];
145
- const logObject = JSON.parse(callArgs);
146
- expect(logObject.message).toBe('');
161
+ const logObject = typeof callArgs === 'string' ? JSON.parse(callArgs) : callArgs;
162
+ expect(logObject.message).toBe("''"); // inspect wraps empty string in quotes
147
163
  expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_oid);
148
164
  expect(logObject.request_id).toBe(mockEvent.payload.event_context.request_id);
165
+ expect(logObject.sdk_version).toBe((0, helpers_1.getLibraryVersion)());
149
166
  });
150
167
  it('[edge] should handle null and undefined values', () => {
151
168
  logger.info('test', null, undefined);
152
169
  expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
153
170
  const callArgs = mockConsoleInfo.mock.calls[0][0];
154
- const logObject = JSON.parse(callArgs);
155
- // inspect shows 'null' and 'undefined' as strings
156
- expect(logObject.message).toBe('test null undefined');
171
+ const logObject = typeof callArgs === 'string' ? JSON.parse(callArgs) : callArgs;
172
+ // inspect shows 'null' and 'undefined' as strings, and wraps strings in quotes
173
+ expect(logObject.message).toBe("'test' null undefined");
157
174
  expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_oid);
175
+ expect(logObject.sdk_version).toBe((0, helpers_1.getLibraryVersion)());
158
176
  });
159
177
  it('[edge] should handle complex nested objects', () => {
160
178
  const complexObject = {
@@ -168,7 +186,7 @@ describe(logger_1.Logger.name, () => {
168
186
  logger.info(complexObject);
169
187
  expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
170
188
  const callArgs = mockConsoleInfo.mock.calls[0][0];
171
- const logObject = JSON.parse(callArgs);
189
+ const logObject = typeof callArgs === 'string' ? JSON.parse(callArgs) : callArgs;
172
190
  // The logger uses inspect() with formatting, not JSON.stringify()
173
191
  const expectedMessage = require('util').inspect(complexObject, {
174
192
  compact: false,
@@ -177,6 +195,7 @@ describe(logger_1.Logger.name, () => {
177
195
  expect(logObject.message).toBe(expectedMessage);
178
196
  expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_oid);
179
197
  expect(typeof logObject.callback_url).toBe('string');
198
+ expect(logObject.sdk_version).toBe((0, helpers_1.getLibraryVersion)());
180
199
  });
181
200
  });
182
201
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/ts-adaas",
3
- "version": "1.11.1-beta.3",
3
+ "version": "1.11.1-beta.5",
4
4
  "description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",