@devrev/ts-adaas 1.11.1-beta.15 → 1.11.1-beta.17
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/dist/logger/logger.d.ts +7 -30
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +1 -5
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +4 -76
- package/dist/logger/logger.test.js +12 -114
- package/dist/workers/create-worker.d.ts.map +1 -1
- package/dist/workers/create-worker.js +4 -2
- package/dist/workers/process-task.js +1 -1
- package/dist/workers/spawn.d.ts.map +1 -1
- package/dist/workers/spawn.js +2 -2
- package/package.json +1 -1
package/dist/logger/logger.d.ts
CHANGED
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
import { Console } from 'node:console';
|
|
2
2
|
import { AxiosError } from 'axios';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare abstract class BaseLogger extends Console {
|
|
10
|
-
protected originalConsole: Console;
|
|
11
|
-
protected options?: WorkerAdapterOptions;
|
|
12
|
-
protected tags: LoggerTags;
|
|
13
|
-
protected constructor({ event, options }: LoggerFactoryInterface);
|
|
3
|
+
import { AxiosErrorResponse, LoggerFactoryInterface, LogLevel, PrintableState } from './logger.interfaces';
|
|
4
|
+
export declare class Logger extends Console {
|
|
5
|
+
private originalConsole;
|
|
6
|
+
private options?;
|
|
7
|
+
private tags;
|
|
8
|
+
constructor({ event, options }: LoggerFactoryInterface);
|
|
14
9
|
private valueToString;
|
|
15
|
-
|
|
10
|
+
logFn(args: unknown[], level: LogLevel): void;
|
|
16
11
|
log(...args: unknown[]): void;
|
|
17
12
|
info(...args: unknown[]): void;
|
|
18
13
|
warn(...args: unknown[]): void;
|
|
19
14
|
error(...args: unknown[]): void;
|
|
20
15
|
}
|
|
21
|
-
/**
|
|
22
|
-
* User logger - marked with sdk_log: false
|
|
23
|
-
* Exported for public use via createUserLogger() factory.
|
|
24
|
-
*/
|
|
25
|
-
export declare class UserLogger extends BaseLogger {
|
|
26
|
-
constructor({ event, options }: LoggerFactoryInterface);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Factory function to create a verified SDK logger.
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
export declare function getInternalLogger(event: LoggerFactoryInterface['event'], options?: LoggerFactoryInterface['options']): BaseLogger;
|
|
33
|
-
/**
|
|
34
|
-
* Factory function to create a user logger (unverified).
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
export declare function createUserLogger(event: LoggerFactoryInterface['event'], options?: LoggerFactoryInterface['options']): UserLogger;
|
|
38
16
|
export declare function getPrintableState(state: Record<string, any>): PrintableState;
|
|
39
17
|
/**
|
|
40
18
|
* @deprecated
|
|
@@ -42,5 +20,4 @@ export declare function getPrintableState(state: Record<string, any>): Printable
|
|
|
42
20
|
export declare function formatAxiosError(error: AxiosError): object;
|
|
43
21
|
export declare const serializeError: (error: unknown) => unknown;
|
|
44
22
|
export declare function serializeAxiosError(error: AxiosError): AxiosErrorResponse;
|
|
45
|
-
export {};
|
|
46
23
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -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;
|
|
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,GAAG,cAAc,CAyB5E;AACD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D;AAED,eAAO,MAAM,cAAc,GAAI,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
|
|
2
|
+
import { AirdropEvent } from '../types/extraction';
|
|
3
3
|
import { WorkerAdapterOptions } from '../types/workers';
|
|
4
4
|
export interface LoggerFactoryInterface {
|
|
5
5
|
event: AirdropEvent;
|
|
@@ -19,10 +19,6 @@ export interface PrintableArray {
|
|
|
19
19
|
export interface PrintableState {
|
|
20
20
|
[key: string]: any | PrintableArray | PrintableState;
|
|
21
21
|
}
|
|
22
|
-
export interface LoggerTags extends EventContext {
|
|
23
|
-
dev_oid: string;
|
|
24
|
-
sdk_log: boolean;
|
|
25
|
-
}
|
|
26
22
|
export interface AxiosErrorResponse {
|
|
27
23
|
config: {
|
|
28
24
|
method: string | undefined;
|
|
@@ -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,
|
|
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;QAE3B,MAAM,EAAE,GAAG,CAAC;QACZ,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;KACzB,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"}
|
package/dist/logger/logger.js
CHANGED
|
@@ -1,50 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.serializeError = exports.
|
|
7
|
-
exports.getInternalLogger = getInternalLogger;
|
|
8
|
-
exports.createUserLogger = createUserLogger;
|
|
3
|
+
exports.serializeError = exports.Logger = void 0;
|
|
9
4
|
exports.getPrintableState = getPrintableState;
|
|
10
5
|
exports.formatAxiosError = formatAxiosError;
|
|
11
6
|
exports.serializeAxiosError = serializeAxiosError;
|
|
12
7
|
const node_console_1 = require("node:console");
|
|
13
|
-
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
14
8
|
const node_util_1 = require("node:util");
|
|
15
9
|
const axios_1 = require("axios");
|
|
16
10
|
const logger_interfaces_1 = require("./logger.interfaces");
|
|
17
|
-
|
|
18
|
-
* Runtime-generated token for internal SDK logger access.
|
|
19
|
-
* Stored in module closure - not accessible from outside.
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
const INTERNAL_LOGGER_TOKEN = node_crypto_1.default.getRandomValues(new Uint8Array(32));
|
|
23
|
-
/**
|
|
24
|
-
* Verify that a token matches the internal token.
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
function verifyToken(token) {
|
|
28
|
-
if (token.length !== INTERNAL_LOGGER_TOKEN.length) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
// Constant-time comparison to prevent timing attacks
|
|
32
|
-
let result = 0;
|
|
33
|
-
for (let i = 0; i < token.length; i++) {
|
|
34
|
-
result |= token[i] ^ INTERNAL_LOGGER_TOKEN[i];
|
|
35
|
-
}
|
|
36
|
-
return result === 0;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Abstract base logger class. Not exported - use factory functions instead.
|
|
40
|
-
* @internal
|
|
41
|
-
*/
|
|
42
|
-
class BaseLogger extends node_console_1.Console {
|
|
11
|
+
class Logger extends node_console_1.Console {
|
|
43
12
|
constructor({ event, options }) {
|
|
44
13
|
super(process.stdout, process.stderr);
|
|
45
14
|
this.originalConsole = console;
|
|
46
15
|
this.options = options;
|
|
47
|
-
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { dev_oid: event.payload.event_context.dev_oid
|
|
16
|
+
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { dev_oid: event.payload.event_context.dev_oid });
|
|
48
17
|
}
|
|
49
18
|
valueToString(value) {
|
|
50
19
|
if (typeof value === 'string') {
|
|
@@ -80,48 +49,7 @@ class BaseLogger extends node_console_1.Console {
|
|
|
80
49
|
this.logFn(args, logger_interfaces_1.LogLevel.ERROR);
|
|
81
50
|
}
|
|
82
51
|
}
|
|
83
|
-
|
|
84
|
-
* Internal SDK logger - marked with sdk_log: true
|
|
85
|
-
* Only accessible through getInternalLogger() factory with valid token.
|
|
86
|
-
* @internal
|
|
87
|
-
*/
|
|
88
|
-
class InternalLogger extends BaseLogger {
|
|
89
|
-
constructor({ event, options }, token) {
|
|
90
|
-
if (!verifyToken(token)) {
|
|
91
|
-
let base64Token = Buffer.from(token).toString('base64');
|
|
92
|
-
throw new Error(`Unauthorized: Invalid token for InternalLogger. Token provided: '${base64Token}'.`);
|
|
93
|
-
}
|
|
94
|
-
super({ event, options });
|
|
95
|
-
this.tags.sdk_log = true;
|
|
96
|
-
Object.freeze(this.tags); // Immutable after construction
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* User logger - marked with sdk_log: false
|
|
101
|
-
* Exported for public use via createUserLogger() factory.
|
|
102
|
-
*/
|
|
103
|
-
class UserLogger extends BaseLogger {
|
|
104
|
-
constructor({ event, options }) {
|
|
105
|
-
super({ event, options });
|
|
106
|
-
// sdk_log already false from BaseLogger
|
|
107
|
-
Object.freeze(this.tags); // Immutable after construction
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.UserLogger = UserLogger;
|
|
111
|
-
/**
|
|
112
|
-
* Factory function to create a verified SDK logger.
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
function getInternalLogger(event, options) {
|
|
116
|
-
return new InternalLogger({ event, options }, INTERNAL_LOGGER_TOKEN);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Factory function to create a user logger (unverified).
|
|
120
|
-
* @internal
|
|
121
|
-
*/
|
|
122
|
-
function createUserLogger(event, options) {
|
|
123
|
-
return new UserLogger({ event, options });
|
|
124
|
-
}
|
|
52
|
+
exports.Logger = Logger;
|
|
125
53
|
// Helper function to process each value in the state
|
|
126
54
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
55
|
function getPrintableState(state) {
|
|
@@ -14,7 +14,7 @@ jest.mock('node:worker_threads', () => ({
|
|
|
14
14
|
isMainThread: true,
|
|
15
15
|
parentPort: null,
|
|
16
16
|
}));
|
|
17
|
-
describe(
|
|
17
|
+
describe(logger_1.Logger.name, () => {
|
|
18
18
|
let mockEvent;
|
|
19
19
|
let mockOptions;
|
|
20
20
|
beforeEach(() => {
|
|
@@ -46,32 +46,24 @@ describe('UserLogger', () => {
|
|
|
46
46
|
jest.restoreAllMocks();
|
|
47
47
|
});
|
|
48
48
|
describe('constructor', () => {
|
|
49
|
-
it('should initialize
|
|
50
|
-
const logger =
|
|
49
|
+
it('should initialize logger with event context and dev_oid', () => {
|
|
50
|
+
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
51
51
|
// Access private property for testing
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
53
|
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
|
-
});
|
|
56
|
-
it('should freeze tags to prevent modification', () => {
|
|
57
|
-
const logger = (0, logger_1.createUserLogger)(mockEvent, mockOptions);
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
-
const tags = logger.tags;
|
|
60
|
-
expect(() => {
|
|
61
|
-
tags.sdk_log = true;
|
|
62
|
-
}).toThrow();
|
|
54
|
+
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid }));
|
|
63
55
|
});
|
|
64
56
|
});
|
|
65
57
|
describe('production logging', () => {
|
|
66
58
|
let logger;
|
|
67
59
|
beforeEach(() => {
|
|
68
60
|
mockOptions.isLocalDevelopment = false;
|
|
69
|
-
logger =
|
|
61
|
+
logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
70
62
|
});
|
|
71
63
|
it('should log single string message without backslashes', () => {
|
|
72
64
|
const message = 'Worker is online. Started processing the task.';
|
|
73
65
|
logger.info(message);
|
|
74
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid
|
|
66
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid })));
|
|
75
67
|
});
|
|
76
68
|
it('should log single object message with JSON stringify', () => {
|
|
77
69
|
const data = { id: 123, name: 'test' };
|
|
@@ -80,7 +72,7 @@ describe('UserLogger', () => {
|
|
|
80
72
|
compact: false,
|
|
81
73
|
depth: Infinity,
|
|
82
74
|
});
|
|
83
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid
|
|
75
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid })));
|
|
84
76
|
});
|
|
85
77
|
it('should log multiple arguments joined with space', () => {
|
|
86
78
|
const text = 'Successfully fetched';
|
|
@@ -90,7 +82,7 @@ describe('UserLogger', () => {
|
|
|
90
82
|
compact: false,
|
|
91
83
|
depth: Infinity,
|
|
92
84
|
});
|
|
93
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid
|
|
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 })));
|
|
94
86
|
});
|
|
95
87
|
it('should handle mixed string and object arguments', () => {
|
|
96
88
|
const text1 = 'Processing';
|
|
@@ -101,14 +93,14 @@ describe('UserLogger', () => {
|
|
|
101
93
|
compact: false,
|
|
102
94
|
depth: Infinity,
|
|
103
95
|
});
|
|
104
|
-
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
|
|
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 })));
|
|
105
97
|
});
|
|
106
98
|
});
|
|
107
99
|
describe('local development logging', () => {
|
|
108
100
|
let logger;
|
|
109
101
|
beforeEach(() => {
|
|
110
102
|
mockOptions.isLocalDevelopment = true;
|
|
111
|
-
logger =
|
|
103
|
+
logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
112
104
|
});
|
|
113
105
|
it('should use regular console methods in local development', () => {
|
|
114
106
|
const message = 'Test message';
|
|
@@ -121,7 +113,7 @@ describe('UserLogger', () => {
|
|
|
121
113
|
let logger;
|
|
122
114
|
beforeEach(() => {
|
|
123
115
|
mockOptions.isLocalDevelopment = false;
|
|
124
|
-
logger =
|
|
116
|
+
logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
125
117
|
});
|
|
126
118
|
it('should call console.info for info level', () => {
|
|
127
119
|
logger.info('test message');
|
|
@@ -144,7 +136,7 @@ describe('UserLogger', () => {
|
|
|
144
136
|
let logger;
|
|
145
137
|
beforeEach(() => {
|
|
146
138
|
mockOptions.isLocalDevelopment = false;
|
|
147
|
-
logger =
|
|
139
|
+
logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
148
140
|
});
|
|
149
141
|
it('[edge] should handle empty string message', () => {
|
|
150
142
|
logger.info('');
|
|
@@ -244,97 +236,3 @@ it('serializeAxiosError should return formatted error', () => {
|
|
|
244
236
|
},
|
|
245
237
|
});
|
|
246
238
|
});
|
|
247
|
-
describe('Logger Factory Pattern', () => {
|
|
248
|
-
let mockEvent;
|
|
249
|
-
beforeEach(() => {
|
|
250
|
-
mockConsoleInfo.mockClear();
|
|
251
|
-
mockConsoleWarn.mockClear();
|
|
252
|
-
mockConsoleError.mockClear();
|
|
253
|
-
mockEvent = (0, test_helpers_1.createEvent)({
|
|
254
|
-
eventType: extraction_1.EventType.ExtractionDataStart,
|
|
255
|
-
eventContextOverrides: {
|
|
256
|
-
request_id: 'test-request-id',
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
describe('getInternalLogger', () => {
|
|
261
|
-
it('should create a logger with sdk_log: true', () => {
|
|
262
|
-
const logger = (0, logger_1.getInternalLogger)(mockEvent);
|
|
263
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
264
|
-
const tags = logger.tags;
|
|
265
|
-
expect(tags.sdk_log).toBe(true);
|
|
266
|
-
});
|
|
267
|
-
it('should freeze tags to prevent modification', () => {
|
|
268
|
-
const logger = (0, logger_1.getInternalLogger)(mockEvent);
|
|
269
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
270
|
-
const tags = logger.tags;
|
|
271
|
-
expect(() => {
|
|
272
|
-
tags.sdk_log = false;
|
|
273
|
-
}).toThrow();
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
describe('createUserLogger', () => {
|
|
277
|
-
it('should create a logger with sdk_log: false', () => {
|
|
278
|
-
const logger = (0, logger_1.createUserLogger)(mockEvent);
|
|
279
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
280
|
-
const tags = logger.tags;
|
|
281
|
-
expect(tags.sdk_log).toBe(false);
|
|
282
|
-
});
|
|
283
|
-
it('should freeze tags to prevent modification', () => {
|
|
284
|
-
const logger = (0, logger_1.createUserLogger)(mockEvent);
|
|
285
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
286
|
-
const tags = logger.tags;
|
|
287
|
-
expect(() => {
|
|
288
|
-
tags.sdk_log = true;
|
|
289
|
-
}).toThrow();
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
describe('Security Verification', () => {
|
|
293
|
-
it('should not allow creating VerifiedLogger directly', () => {
|
|
294
|
-
// VerifiedLogger is not exported, so it cannot be imported
|
|
295
|
-
// This test documents the design: only getInternalLogger() creates verified loggers
|
|
296
|
-
const logger = (0, logger_1.getInternalLogger)(mockEvent);
|
|
297
|
-
expect(logger).toBeDefined();
|
|
298
|
-
// Verify that the internal logger has sdk_log set to true
|
|
299
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
300
|
-
expect(logger.tags.sdk_log).toBe(true);
|
|
301
|
-
});
|
|
302
|
-
it('should not allow modifying sdk_log flag after construction', () => {
|
|
303
|
-
const userLogger = (0, logger_1.createUserLogger)(mockEvent);
|
|
304
|
-
const internalLogger = (0, logger_1.getInternalLogger)(mockEvent);
|
|
305
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
306
|
-
const userTags = userLogger.tags;
|
|
307
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
308
|
-
const internalTags = internalLogger.tags;
|
|
309
|
-
// Both should be frozen
|
|
310
|
-
expect(() => {
|
|
311
|
-
userTags.sdk_log = true;
|
|
312
|
-
}).toThrow();
|
|
313
|
-
expect(() => {
|
|
314
|
-
internalTags.sdk_log = false;
|
|
315
|
-
}).toThrow();
|
|
316
|
-
});
|
|
317
|
-
it('should reject invalid tokens when trying to create VerifiedLogger', () => {
|
|
318
|
-
const InternalLoggerFunction = logger_1.getInternalLogger;
|
|
319
|
-
// Try to directly construct with invalid token
|
|
320
|
-
// We need to get access to VerifiedLogger somehow - but it's not exported
|
|
321
|
-
// Instead, we test that the token verification exists by testing the behavior
|
|
322
|
-
const logger = InternalLoggerFunction(mockEvent);
|
|
323
|
-
expect(logger).toBeDefined();
|
|
324
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
325
|
-
expect(logger.tags.sdk_log).toBe(true);
|
|
326
|
-
});
|
|
327
|
-
it('token should be runtime-generated and unique per module load', () => {
|
|
328
|
-
// Create two loggers from getInternalLogger
|
|
329
|
-
const logger1 = (0, logger_1.getInternalLogger)(mockEvent);
|
|
330
|
-
const logger2 = (0, logger_1.getInternalLogger)(mockEvent);
|
|
331
|
-
// Both should have sdk_log: true (same token used internally)
|
|
332
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
333
|
-
expect(logger1.tags.sdk_log).toBe(true);
|
|
334
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
335
|
-
expect(logger2.tags.sdk_log).toBe(true);
|
|
336
|
-
// But they should be different instances
|
|
337
|
-
expect(logger1).not.toBe(logger2);
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/workers/create-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAE3D,iBAAe,YAAY,CAAC,cAAc,EACxC,UAAU,EAAE,UAAU,CAAC,cAAc,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/workers/create-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAE3D,iBAAe,YAAY,CAAC,cAAc,EACxC,UAAU,EAAE,UAAU,CAAC,cAAc,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -7,8 +7,10 @@ const workers_1 = require("../types/workers");
|
|
|
7
7
|
async function createWorker(workerData) {
|
|
8
8
|
return new Promise((resolve, reject) => {
|
|
9
9
|
if (node_worker_threads_1.isMainThread) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const logger = new logger_1.Logger({
|
|
11
|
+
event: workerData.event,
|
|
12
|
+
options: workerData.options,
|
|
13
|
+
});
|
|
12
14
|
const workerFile = __dirname + '/worker.js';
|
|
13
15
|
const worker = new node_worker_threads_1.Worker(workerFile, {
|
|
14
16
|
workerData,
|
|
@@ -15,7 +15,7 @@ function processTask({ task, onTimeout, }) {
|
|
|
15
15
|
const initialDomainMapping = node_worker_threads_1.workerData.initialDomainMapping;
|
|
16
16
|
const options = node_worker_threads_1.workerData.options;
|
|
17
17
|
// eslint-disable-next-line no-global-assign
|
|
18
|
-
console =
|
|
18
|
+
console = new logger_1.Logger({ event, options });
|
|
19
19
|
const adapterState = await (0, state_1.createAdapterState)({
|
|
20
20
|
event,
|
|
21
21
|
initialState,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAWA,OAAO,EAEL,qBAAqB,EACrB,cAAc,EAGf,MAAM,kBAAkB,CAAC;AA4D1B;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,cAAc,EAAE,EAC1C,KAAK,EACL,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,OAAO,GACR,EAAE,qBAAqB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAmEvD;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,oBAAoB,CAAkC;IAC9D,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,wBAAwB,CAA6C;
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAWA,OAAO,EAEL,qBAAqB,EACrB,cAAc,EAGf,MAAM,kBAAkB,CAAC;AA4D1B;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,cAAc,EAAE,EAC1C,KAAK,EACL,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,OAAO,GACR,EAAE,qBAAqB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAmEvD;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,oBAAoB,CAAkC;IAC9D,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,wBAAwB,CAA6C;IAC7E,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA4C;gBAE/C,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,cAAc;IA8F/D,OAAO,CAAC,aAAa;YAYP,kBAAkB;CA8BjC"}
|
package/dist/workers/spawn.js
CHANGED
|
@@ -72,7 +72,7 @@ function getWorkerPath({ event, connectorWorkerPath, }) {
|
|
|
72
72
|
* @returns {Promise<Spawn>} - A new instance of Spawn class
|
|
73
73
|
*/
|
|
74
74
|
async function spawn({ event, initialState, workerPath, initialDomainMapping, options, }) {
|
|
75
|
-
const logger =
|
|
75
|
+
const logger = new logger_1.Logger({ event, options });
|
|
76
76
|
const script = getWorkerPath({
|
|
77
77
|
event,
|
|
78
78
|
connectorWorkerPath: workerPath,
|
|
@@ -134,7 +134,7 @@ class Spawn {
|
|
|
134
134
|
this.defaultLambdaTimeout = constants_1.DEFAULT_LAMBDA_TIMEOUT;
|
|
135
135
|
this.alreadyEmitted = false;
|
|
136
136
|
this.event = event;
|
|
137
|
-
this.logger =
|
|
137
|
+
this.logger = new logger_1.Logger({ event, options });
|
|
138
138
|
this.lambdaTimeout = (options === null || options === void 0 ? void 0 : options.timeout)
|
|
139
139
|
? Math.min(options.timeout, this.defaultLambdaTimeout)
|
|
140
140
|
: this.defaultLambdaTimeout;
|
package/package.json
CHANGED