@devrev/airsync-sdk 2.0.0-beta.0
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/README.md +31 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +16 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +9 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.js +2 -0
- package/dist/attachments-streaming/attachments-streaming-pool.js +97 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +2 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +267 -0
- package/dist/common/constants.d.ts +25 -0
- package/dist/common/constants.d.ts.map +1 -0
- package/dist/common/constants.js +58 -0
- package/dist/common/control-protocol.d.ts +10 -0
- package/dist/common/control-protocol.d.ts.map +1 -0
- package/dist/common/control-protocol.js +31 -0
- package/dist/common/errors.d.ts +6 -0
- package/dist/common/errors.d.ts.map +1 -0
- package/dist/common/errors.js +4 -0
- package/dist/common/event-type-translation.d.ts +24 -0
- package/dist/common/event-type-translation.d.ts.map +1 -0
- package/dist/common/event-type-translation.js +117 -0
- package/dist/common/helpers.d.ts +41 -0
- package/dist/common/helpers.d.ts.map +1 -0
- package/dist/common/helpers.js +124 -0
- package/dist/common/install-initial-domain-mapping.d.ts +4 -0
- package/dist/common/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/common/install-initial-domain-mapping.js +58 -0
- package/dist/common/install-initial-domain-mapping.test.d.ts +2 -0
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +1 -0
- package/dist/common/install-initial-domain-mapping.test.js +207 -0
- package/dist/deprecated/adapter/index.d.ts +62 -0
- package/dist/deprecated/adapter/index.d.ts.map +1 -0
- package/dist/deprecated/adapter/index.js +151 -0
- package/dist/deprecated/common/helpers.d.ts +7 -0
- package/dist/deprecated/common/helpers.d.ts.map +1 -0
- package/dist/deprecated/common/helpers.js +47 -0
- package/dist/deprecated/demo-extractor/external_domain_metadata.json +38 -0
- package/dist/deprecated/demo-extractor/index.d.ts +18 -0
- package/dist/deprecated/demo-extractor/index.d.ts.map +1 -0
- package/dist/deprecated/demo-extractor/index.js +161 -0
- package/dist/deprecated/http/client.d.ts +22 -0
- package/dist/deprecated/http/client.d.ts.map +1 -0
- package/dist/deprecated/http/client.js +161 -0
- package/dist/deprecated/uploader/index.d.ts +35 -0
- package/dist/deprecated/uploader/index.d.ts.map +1 -0
- package/dist/deprecated/uploader/index.js +161 -0
- package/dist/http/axios-client-internal.d.ts +3 -0
- package/dist/http/axios-client-internal.d.ts.map +1 -0
- package/dist/http/axios-client-internal.js +66 -0
- package/dist/http/axios-client-internal.test.d.ts +2 -0
- package/dist/http/axios-client-internal.test.d.ts.map +1 -0
- package/dist/http/axios-client-internal.test.js +154 -0
- package/dist/http/axios-client.d.ts +27 -0
- package/dist/http/axios-client.d.ts.map +1 -0
- package/dist/http/axios-client.js +57 -0
- package/dist/http/constants.d.ts +4 -0
- package/dist/http/constants.d.ts.map +1 -0
- package/dist/http/constants.js +6 -0
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +18 -0
- package/dist/http/types.d.ts +17 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +2 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/logger/logger.constants.d.ts +6 -0
- package/dist/logger/logger.constants.d.ts.map +1 -0
- package/dist/logger/logger.constants.js +13 -0
- package/dist/logger/logger.context.d.ts +58 -0
- package/dist/logger/logger.context.d.ts.map +1 -0
- package/dist/logger/logger.context.js +86 -0
- package/dist/logger/logger.d.ts +89 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.interfaces.d.ts +43 -0
- package/dist/logger/logger.interfaces.d.ts.map +1 -0
- package/dist/logger/logger.interfaces.js +9 -0
- package/dist/logger/logger.js +196 -0
- package/dist/logger/logger.test.d.ts +2 -0
- package/dist/logger/logger.test.d.ts.map +1 -0
- package/dist/logger/logger.test.js +490 -0
- package/dist/mappers/mappers.d.ts +52 -0
- package/dist/mappers/mappers.d.ts.map +1 -0
- package/dist/mappers/mappers.interface.d.ts +294 -0
- package/dist/mappers/mappers.interface.d.ts.map +1 -0
- package/dist/mappers/mappers.interface.js +48 -0
- package/dist/mappers/mappers.js +83 -0
- package/dist/mappers/mappers.test.d.ts +2 -0
- package/dist/mappers/mappers.test.d.ts.map +1 -0
- package/dist/mappers/mappers.test.js +107 -0
- package/dist/multithreading/create-worker.d.ts +5 -0
- package/dist/multithreading/create-worker.d.ts.map +1 -0
- package/dist/multithreading/create-worker.js +28 -0
- package/dist/multithreading/create-worker.test.d.ts +2 -0
- package/dist/multithreading/create-worker.test.d.ts.map +1 -0
- package/dist/multithreading/create-worker.test.js +89 -0
- package/dist/multithreading/process-task.d.ts +3 -0
- package/dist/multithreading/process-task.d.ts.map +1 -0
- package/dist/multithreading/process-task.js +58 -0
- package/dist/multithreading/spawn/spawn.d.ts +30 -0
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.d.ts +21 -0
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.js +114 -0
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +2 -0
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.test.js +293 -0
- package/dist/multithreading/spawn/spawn.js +249 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +127 -0
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +91 -0
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +22 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.js +64 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +514 -0
- package/dist/multithreading/worker-adapter/worker-adapter.js +747 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.js +483 -0
- package/dist/multithreading/worker.d.ts +2 -0
- package/dist/multithreading/worker.d.ts.map +1 -0
- package/dist/multithreading/worker.js +9 -0
- package/dist/repo/repo.d.ts +18 -0
- package/dist/repo/repo.d.ts.map +1 -0
- package/dist/repo/repo.interfaces.d.ts +46 -0
- package/dist/repo/repo.interfaces.d.ts.map +1 -0
- package/dist/repo/repo.interfaces.js +2 -0
- package/dist/repo/repo.js +75 -0
- package/dist/repo/repo.test.d.ts +2 -0
- package/dist/repo/repo.test.d.ts.map +1 -0
- package/dist/repo/repo.test.js +131 -0
- package/dist/state/state.d.ts +30 -0
- package/dist/state/state.d.ts.map +1 -0
- package/dist/state/state.interfaces.d.ts +51 -0
- package/dist/state/state.interfaces.d.ts.map +1 -0
- package/dist/state/state.interfaces.js +21 -0
- package/dist/state/state.js +166 -0
- package/dist/state/state.test.d.ts +2 -0
- package/dist/state/state.test.d.ts.map +1 -0
- package/dist/state/state.test.js +224 -0
- package/dist/types/common.d.ts +50 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +25 -0
- package/dist/types/extraction.d.ts +417 -0
- package/dist/types/extraction.d.ts.map +1 -0
- package/dist/types/extraction.js +170 -0
- package/dist/types/extraction.test.d.ts +2 -0
- package/dist/types/extraction.test.d.ts.map +1 -0
- package/dist/types/extraction.test.js +70 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/loading.d.ts +147 -0
- package/dist/types/loading.d.ts.map +1 -0
- package/dist/types/loading.js +48 -0
- package/dist/types/workers.d.ts +161 -0
- package/dist/types/workers.d.ts.map +1 -0
- package/dist/types/workers.js +22 -0
- package/dist/uploader/uploader.d.ts +92 -0
- package/dist/uploader/uploader.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.d.ts +33 -0
- package/dist/uploader/uploader.helpers.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.js +139 -0
- package/dist/uploader/uploader.helpers.test.d.ts +2 -0
- package/dist/uploader/uploader.helpers.test.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.test.js +267 -0
- package/dist/uploader/uploader.interfaces.d.ts +95 -0
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -0
- package/dist/uploader/uploader.interfaces.js +2 -0
- package/dist/uploader/uploader.js +305 -0
- package/dist/uploader/uploader.test.d.ts +2 -0
- package/dist/uploader/uploader.test.d.ts.map +1 -0
- package/dist/uploader/uploader.test.js +589 -0
- package/package.json +60 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes a function within user log context, marking all logs as user-originated.
|
|
3
|
+
*
|
|
4
|
+
* Use this to wrap user-provided callback functions (e.g., task handlers, event callbacks).
|
|
5
|
+
* The context automatically propagates through any async operations within the function,
|
|
6
|
+
* ensuring that all console.log calls inside are correctly tagged as user logs.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The return type of the function
|
|
9
|
+
* @param fn - The function to execute within user context (can be sync or async)
|
|
10
|
+
* @returns The result of the function execution
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* await runWithUserLogContext(async () => {
|
|
15
|
+
* console.log('This is a user log'); // is_sdk_log: false
|
|
16
|
+
* await someAsyncOperation();
|
|
17
|
+
* console.log('Still a user log'); // is_sdk_log: false (context preserved)
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function runWithUserLogContext<T>(fn: () => T): T;
|
|
22
|
+
/**
|
|
23
|
+
* Executes a function within SDK log context, marking all logs as SDK-originated.
|
|
24
|
+
*
|
|
25
|
+
* Use this to wrap SDK internal operations (e.g., emit, postState, adapter methods).
|
|
26
|
+
* The context automatically propagates through any async operations within the function,
|
|
27
|
+
* ensuring that all console.log calls inside are correctly tagged as SDK logs.
|
|
28
|
+
*
|
|
29
|
+
* This allows proper nesting: SDK code can call user code via runWithUserLogContext,
|
|
30
|
+
* and when control returns to SDK code, logs are correctly attributed.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The return type of the function
|
|
33
|
+
* @param fn - The function to execute within SDK context (can be sync or async)
|
|
34
|
+
* @returns The result of the function execution
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* await runWithSdkLogContext(async () => {
|
|
39
|
+
* console.log('SDK internal log'); // is_sdk_log: true
|
|
40
|
+
* runWithUserLogContext(() => {
|
|
41
|
+
* console.log('User handler log'); // is_sdk_log: false
|
|
42
|
+
* });
|
|
43
|
+
* console.log('Back to SDK log'); // is_sdk_log: true
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function runWithSdkLogContext<T>(fn: () => T): T;
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves the current SDK log context value.
|
|
50
|
+
*
|
|
51
|
+
* Returns whether the current execution context is within SDK code (true) or user code (false).
|
|
52
|
+
* If no context has been set (e.g., during testing or edge cases), returns the provided default.
|
|
53
|
+
*
|
|
54
|
+
* @param defaultValue - The value to return if no context is currently set
|
|
55
|
+
* @returns `true` if in SDK context, `false` if in user context, or defaultValue if unset
|
|
56
|
+
*/
|
|
57
|
+
export declare function getSdkLogContextValue(defaultValue: boolean): boolean;
|
|
58
|
+
//# sourceMappingURL=logger.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.context.d.ts","sourceRoot":"","sources":["../../src/logger/logger.context.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAMpE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runWithUserLogContext = runWithUserLogContext;
|
|
4
|
+
exports.runWithSdkLogContext = runWithSdkLogContext;
|
|
5
|
+
exports.getSdkLogContextValue = getSdkLogContextValue;
|
|
6
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
7
|
+
/**
|
|
8
|
+
* Async-aware context storage for tracking whether code is executing within SDK or user context.
|
|
9
|
+
*
|
|
10
|
+
* AsyncLocalStorage is used instead of a simple global variable because it automatically
|
|
11
|
+
* propagates the context across async boundaries (await, Promise.then, setTimeout, etc.).
|
|
12
|
+
* This ensures that even after multiple await calls in user code, the logging context
|
|
13
|
+
* remains correct without requiring explicit context passing through function parameters.
|
|
14
|
+
*
|
|
15
|
+
* The stored boolean value indicates:
|
|
16
|
+
* - `true`: Code is executing within SDK internals (logs tagged as is_sdk_log: true)
|
|
17
|
+
* - `false`: Code is executing within user-provided handlers (logs tagged as is_sdk_log: false)
|
|
18
|
+
*/
|
|
19
|
+
const sdkLogContext = new node_async_hooks_1.AsyncLocalStorage();
|
|
20
|
+
/**
|
|
21
|
+
* Executes a function within user log context, marking all logs as user-originated.
|
|
22
|
+
*
|
|
23
|
+
* Use this to wrap user-provided callback functions (e.g., task handlers, event callbacks).
|
|
24
|
+
* The context automatically propagates through any async operations within the function,
|
|
25
|
+
* ensuring that all console.log calls inside are correctly tagged as user logs.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The return type of the function
|
|
28
|
+
* @param fn - The function to execute within user context (can be sync or async)
|
|
29
|
+
* @returns The result of the function execution
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* await runWithUserLogContext(async () => {
|
|
34
|
+
* console.log('This is a user log'); // is_sdk_log: false
|
|
35
|
+
* await someAsyncOperation();
|
|
36
|
+
* console.log('Still a user log'); // is_sdk_log: false (context preserved)
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function runWithUserLogContext(fn) {
|
|
41
|
+
return sdkLogContext.run(false, fn);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Executes a function within SDK log context, marking all logs as SDK-originated.
|
|
45
|
+
*
|
|
46
|
+
* Use this to wrap SDK internal operations (e.g., emit, postState, adapter methods).
|
|
47
|
+
* The context automatically propagates through any async operations within the function,
|
|
48
|
+
* ensuring that all console.log calls inside are correctly tagged as SDK logs.
|
|
49
|
+
*
|
|
50
|
+
* This allows proper nesting: SDK code can call user code via runWithUserLogContext,
|
|
51
|
+
* and when control returns to SDK code, logs are correctly attributed.
|
|
52
|
+
*
|
|
53
|
+
* @template T - The return type of the function
|
|
54
|
+
* @param fn - The function to execute within SDK context (can be sync or async)
|
|
55
|
+
* @returns The result of the function execution
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* await runWithSdkLogContext(async () => {
|
|
60
|
+
* console.log('SDK internal log'); // is_sdk_log: true
|
|
61
|
+
* runWithUserLogContext(() => {
|
|
62
|
+
* console.log('User handler log'); // is_sdk_log: false
|
|
63
|
+
* });
|
|
64
|
+
* console.log('Back to SDK log'); // is_sdk_log: true
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
function runWithSdkLogContext(fn) {
|
|
69
|
+
return sdkLogContext.run(true, fn);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves the current SDK log context value.
|
|
73
|
+
*
|
|
74
|
+
* Returns whether the current execution context is within SDK code (true) or user code (false).
|
|
75
|
+
* If no context has been set (e.g., during testing or edge cases), returns the provided default.
|
|
76
|
+
*
|
|
77
|
+
* @param defaultValue - The value to return if no context is currently set
|
|
78
|
+
* @returns `true` if in SDK context, `false` if in user context, or defaultValue if unset
|
|
79
|
+
*/
|
|
80
|
+
function getSdkLogContextValue(defaultValue) {
|
|
81
|
+
const storeValue = sdkLogContext.getStore();
|
|
82
|
+
if (typeof storeValue === 'boolean') {
|
|
83
|
+
return storeValue;
|
|
84
|
+
}
|
|
85
|
+
return defaultValue;
|
|
86
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
2
|
+
import { Console } from 'node:console';
|
|
3
|
+
import { AxiosErrorResponse, LoggerFactoryInterface, LogLevel, PrintableState } from './logger.interfaces';
|
|
4
|
+
/**
|
|
5
|
+
* Custom logger that extends Node.js Console with context-aware logging.
|
|
6
|
+
* Handles local development, main thread, and worker thread logging differently.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Logger extends Console {
|
|
9
|
+
private originalConsole;
|
|
10
|
+
private options?;
|
|
11
|
+
private tags;
|
|
12
|
+
constructor({ event, options }: LoggerFactoryInterface);
|
|
13
|
+
/**
|
|
14
|
+
* Converts any value to a string using `util.inspect()` for complex types.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The value to convert
|
|
17
|
+
* @returns String representation of the value
|
|
18
|
+
*/
|
|
19
|
+
private valueToString;
|
|
20
|
+
/**
|
|
21
|
+
* Truncates a message if it exceeds the maximum allowed length.
|
|
22
|
+
* Adds a suffix indicating how many characters were omitted.
|
|
23
|
+
*
|
|
24
|
+
* @param message - The message to truncate
|
|
25
|
+
* @returns Truncated message or original if within limits
|
|
26
|
+
*/
|
|
27
|
+
private truncateMessage;
|
|
28
|
+
/**
|
|
29
|
+
* Logs a pre-formatted message string to the console.
|
|
30
|
+
* In production mode, wraps the message with JSON formatting and event context tags.
|
|
31
|
+
* In local development mode, logs the message directly without JSON wrapping.
|
|
32
|
+
* This is useful when you need to log already-stringified content.
|
|
33
|
+
*
|
|
34
|
+
* @param message - The pre-formatted message string to log
|
|
35
|
+
* @param level - Log level (info, warn, error)
|
|
36
|
+
* @param isSdkLog - Flag indicating if the log originated from the SDK
|
|
37
|
+
*/
|
|
38
|
+
logFn(message: string, level: LogLevel, isSdkLog?: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Stringifies and logs arguments to the appropriate destination.
|
|
41
|
+
* On main thread, converts arguments to strings and calls logFn.
|
|
42
|
+
* In worker threads, forwards stringified arguments to the main thread for processing.
|
|
43
|
+
* All arguments are converted to strings using util.inspect and joined with spaces.
|
|
44
|
+
*
|
|
45
|
+
* @param args - Values to log (will be stringified and truncated if needed)
|
|
46
|
+
* @param level - Log level (info, warn, error)
|
|
47
|
+
*/
|
|
48
|
+
private stringifyAndLog;
|
|
49
|
+
log(...args: unknown[]): void;
|
|
50
|
+
info(...args: unknown[]): void;
|
|
51
|
+
warn(...args: unknown[]): void;
|
|
52
|
+
error(...args: unknown[]): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Converts a state object into a printable format where arrays are summarized.
|
|
56
|
+
* Arrays show their length, first item, and last item instead of all elements.
|
|
57
|
+
* Objects are recursively processed and primitives are returned as-is.
|
|
58
|
+
*
|
|
59
|
+
* @param state - State object to convert
|
|
60
|
+
* @returns Printable representation with summarized arrays
|
|
61
|
+
*/
|
|
62
|
+
export declare function getPrintableState(state: Record<string, any>): PrintableState;
|
|
63
|
+
/**
|
|
64
|
+
* Serializes an error into a structured format.
|
|
65
|
+
* Automatically detects and formats Axios errors with HTTP details.
|
|
66
|
+
* Returns other error types as-is.
|
|
67
|
+
*
|
|
68
|
+
* @param error - Error to serialize
|
|
69
|
+
* @returns Serialized error or original if not an Axios error
|
|
70
|
+
*/
|
|
71
|
+
export declare function serializeError(error: unknown): unknown;
|
|
72
|
+
/**
|
|
73
|
+
* Serializes an Axios error into a structured format with HTTP request/response details.
|
|
74
|
+
* Extracts method, URL, parameters, status code, headers, and data.
|
|
75
|
+
* Includes CORS/network failure indicator when no response is available.
|
|
76
|
+
*
|
|
77
|
+
* @param error - Axios error to serialize
|
|
78
|
+
* @returns Structured object with error details
|
|
79
|
+
*/
|
|
80
|
+
export declare function serializeAxiosError(error: AxiosError): AxiosErrorResponse;
|
|
81
|
+
/**
|
|
82
|
+
* Formats an Axios error to a printable format.
|
|
83
|
+
*
|
|
84
|
+
* @param error - Axios error to format
|
|
85
|
+
* @returns Formatted error object
|
|
86
|
+
* @deprecated Use {@link serializeAxiosError} instead
|
|
87
|
+
*/
|
|
88
|
+
export declare function formatAxiosError(error: AxiosError): object;
|
|
89
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyC,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AASvC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B;;;GAGG;AACH,qBAAa,MAAO,SAAQ,OAAO;IACjC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,OAAO,CAAC,CAAuB;IACvC,OAAO,CAAC,IAAI,CAAa;gBAEb,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,sBAAsB;IAWtD;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IASvB;;;;;;;;;OASG;IACH,KAAK,CACH,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,QAAQ,EACf,QAAQ,GAAE,OAAqC,GAC9C,IAAI;IAcP;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAgBd,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;AACD;;;;;;;GAOG;AAEH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,cAAc,CAqB5E;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKtD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAwBzE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RawAxiosResponseHeaders } from 'axios';
|
|
2
|
+
import type { AirdropEvent, EventContext } from '../types/extraction';
|
|
3
|
+
import type { WorkerAdapterOptions } from '../types/workers';
|
|
4
|
+
export interface LoggerFactoryInterface {
|
|
5
|
+
event: AirdropEvent;
|
|
6
|
+
options?: WorkerAdapterOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare enum LogLevel {
|
|
9
|
+
INFO = "info",
|
|
10
|
+
WARN = "warn",
|
|
11
|
+
ERROR = "error"
|
|
12
|
+
}
|
|
13
|
+
export interface PrintableArray {
|
|
14
|
+
type: 'array';
|
|
15
|
+
length: number;
|
|
16
|
+
firstItem?: any;
|
|
17
|
+
lastItem?: any;
|
|
18
|
+
}
|
|
19
|
+
export interface PrintableState {
|
|
20
|
+
[key: string]: any | PrintableArray | PrintableState;
|
|
21
|
+
}
|
|
22
|
+
export interface AxiosErrorResponse {
|
|
23
|
+
config: {
|
|
24
|
+
method: string | undefined;
|
|
25
|
+
params: any;
|
|
26
|
+
url: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
isAxiosError: boolean;
|
|
29
|
+
isCorsOrNoNetworkError: boolean;
|
|
30
|
+
response?: {
|
|
31
|
+
data: unknown;
|
|
32
|
+
headers: RawAxiosResponseHeaders;
|
|
33
|
+
status: number;
|
|
34
|
+
statusText: string;
|
|
35
|
+
};
|
|
36
|
+
code?: string;
|
|
37
|
+
message?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface LoggerTags extends EventContext {
|
|
40
|
+
sdk_version: string;
|
|
41
|
+
is_sdk_log: boolean;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=logger.interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.interfaces.d.ts","sourceRoot":"","sources":["../../src/logger/logger.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,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;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACrB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevel = void 0;
|
|
4
|
+
var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel["INFO"] = "info";
|
|
7
|
+
LogLevel["WARN"] = "warn";
|
|
8
|
+
LogLevel["ERROR"] = "error";
|
|
9
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
exports.getPrintableState = getPrintableState;
|
|
5
|
+
exports.serializeError = serializeError;
|
|
6
|
+
exports.serializeAxiosError = serializeAxiosError;
|
|
7
|
+
exports.formatAxiosError = formatAxiosError;
|
|
8
|
+
const axios_1 = require("axios");
|
|
9
|
+
const node_console_1 = require("node:console");
|
|
10
|
+
const node_util_1 = require("node:util");
|
|
11
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
12
|
+
const constants_1 = require("../common/constants");
|
|
13
|
+
const workers_1 = require("../types/workers");
|
|
14
|
+
const logger_constants_1 = require("./logger.constants");
|
|
15
|
+
const logger_context_1 = require("./logger.context");
|
|
16
|
+
const logger_interfaces_1 = require("./logger.interfaces");
|
|
17
|
+
/**
|
|
18
|
+
* Custom logger that extends Node.js Console with context-aware logging.
|
|
19
|
+
* Handles local development, main thread, and worker thread logging differently.
|
|
20
|
+
*/
|
|
21
|
+
class Logger extends node_console_1.Console {
|
|
22
|
+
constructor({ event, options }) {
|
|
23
|
+
super(process.stdout, process.stderr);
|
|
24
|
+
this.originalConsole = console;
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION, is_sdk_log: true });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts any value to a string using `util.inspect()` for complex types.
|
|
30
|
+
*
|
|
31
|
+
* @param value - The value to convert
|
|
32
|
+
* @returns String representation of the value
|
|
33
|
+
*/
|
|
34
|
+
valueToString(value) {
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
return (0, node_util_1.inspect)(value, logger_constants_1.INSPECT_OPTIONS);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Truncates a message if it exceeds the maximum allowed length.
|
|
42
|
+
* Adds a suffix indicating how many characters were omitted.
|
|
43
|
+
*
|
|
44
|
+
* @param message - The message to truncate
|
|
45
|
+
* @returns Truncated message or original if within limits
|
|
46
|
+
*/
|
|
47
|
+
truncateMessage(message) {
|
|
48
|
+
if (message.length > logger_constants_1.MAX_LOG_STRING_LENGTH) {
|
|
49
|
+
return `${message.substring(0, logger_constants_1.MAX_LOG_STRING_LENGTH)}... ${message.length - logger_constants_1.MAX_LOG_STRING_LENGTH} more characters`;
|
|
50
|
+
}
|
|
51
|
+
return message;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Logs a pre-formatted message string to the console.
|
|
55
|
+
* In production mode, wraps the message with JSON formatting and event context tags.
|
|
56
|
+
* In local development mode, logs the message directly without JSON wrapping.
|
|
57
|
+
* This is useful when you need to log already-stringified content.
|
|
58
|
+
*
|
|
59
|
+
* @param message - The pre-formatted message string to log
|
|
60
|
+
* @param level - Log level (info, warn, error)
|
|
61
|
+
* @param isSdkLog - Flag indicating if the log originated from the SDK
|
|
62
|
+
*/
|
|
63
|
+
logFn(message, level, isSdkLog = (0, logger_context_1.getSdkLogContextValue)(true)) {
|
|
64
|
+
var _a;
|
|
65
|
+
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) {
|
|
66
|
+
this.originalConsole[level](message);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const logObject = Object.assign(Object.assign({ message }, this.tags), { is_sdk_log: isSdkLog });
|
|
70
|
+
this.originalConsole[level](JSON.stringify(logObject));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Stringifies and logs arguments to the appropriate destination.
|
|
74
|
+
* On main thread, converts arguments to strings and calls logFn.
|
|
75
|
+
* In worker threads, forwards stringified arguments to the main thread for processing.
|
|
76
|
+
* All arguments are converted to strings using util.inspect and joined with spaces.
|
|
77
|
+
*
|
|
78
|
+
* @param args - Values to log (will be stringified and truncated if needed)
|
|
79
|
+
* @param level - Log level (info, warn, error)
|
|
80
|
+
*/
|
|
81
|
+
stringifyAndLog(args, level) {
|
|
82
|
+
let stringifiedArgs = args.map((arg) => this.valueToString(arg)).join(' ');
|
|
83
|
+
stringifiedArgs = this.truncateMessage(stringifiedArgs);
|
|
84
|
+
const isSdkLog = (0, logger_context_1.getSdkLogContextValue)(true);
|
|
85
|
+
if (node_worker_threads_1.isMainThread) {
|
|
86
|
+
this.logFn(stringifiedArgs, level, isSdkLog);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
90
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
91
|
+
payload: { stringifiedArgs, level, isSdkLog },
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
log(...args) {
|
|
96
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.INFO);
|
|
97
|
+
}
|
|
98
|
+
info(...args) {
|
|
99
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.INFO);
|
|
100
|
+
}
|
|
101
|
+
warn(...args) {
|
|
102
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.WARN);
|
|
103
|
+
}
|
|
104
|
+
error(...args) {
|
|
105
|
+
this.stringifyAndLog(args, logger_interfaces_1.LogLevel.ERROR);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.Logger = Logger;
|
|
109
|
+
/**
|
|
110
|
+
* Converts a state object into a printable format where arrays are summarized.
|
|
111
|
+
* Arrays show their length, first item, and last item instead of all elements.
|
|
112
|
+
* Objects are recursively processed and primitives are returned as-is.
|
|
113
|
+
*
|
|
114
|
+
* @param state - State object to convert
|
|
115
|
+
* @returns Printable representation with summarized arrays
|
|
116
|
+
*/
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
+
function getPrintableState(state) {
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
function processValue(value) {
|
|
121
|
+
if (Array.isArray(value)) {
|
|
122
|
+
return {
|
|
123
|
+
type: 'array',
|
|
124
|
+
length: value.length,
|
|
125
|
+
firstItem: value.length > 0 ? value[0] : undefined,
|
|
126
|
+
lastItem: value.length > 1 ? value[value.length - 1] : undefined,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
else if (typeof value === 'object' && value !== null) {
|
|
130
|
+
const processedObject = {};
|
|
131
|
+
for (const key in value) {
|
|
132
|
+
processedObject[key] = processValue(value[key]);
|
|
133
|
+
}
|
|
134
|
+
return processedObject;
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
return processValue(state);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Serializes an error into a structured format.
|
|
142
|
+
* Automatically detects and formats Axios errors with HTTP details.
|
|
143
|
+
* Returns other error types as-is.
|
|
144
|
+
*
|
|
145
|
+
* @param error - Error to serialize
|
|
146
|
+
* @returns Serialized error or original if not an Axios error
|
|
147
|
+
*/
|
|
148
|
+
function serializeError(error) {
|
|
149
|
+
if ((0, axios_1.isAxiosError)(error)) {
|
|
150
|
+
return serializeAxiosError(error);
|
|
151
|
+
}
|
|
152
|
+
return error;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Serializes an Axios error into a structured format with HTTP request/response details.
|
|
156
|
+
* Extracts method, URL, parameters, status code, headers, and data.
|
|
157
|
+
* Includes CORS/network failure indicator when no response is available.
|
|
158
|
+
*
|
|
159
|
+
* @param error - Axios error to serialize
|
|
160
|
+
* @returns Structured object with error details
|
|
161
|
+
*/
|
|
162
|
+
function serializeAxiosError(error) {
|
|
163
|
+
var _a, _b, _c;
|
|
164
|
+
const serializedAxiosError = {
|
|
165
|
+
config: {
|
|
166
|
+
method: (_a = error.config) === null || _a === void 0 ? void 0 : _a.method,
|
|
167
|
+
params: (_b = error.config) === null || _b === void 0 ? void 0 : _b.params,
|
|
168
|
+
url: (_c = error.config) === null || _c === void 0 ? void 0 : _c.url,
|
|
169
|
+
},
|
|
170
|
+
isAxiosError: true,
|
|
171
|
+
isCorsOrNoNetworkError: !error.response,
|
|
172
|
+
};
|
|
173
|
+
if (error.response) {
|
|
174
|
+
serializedAxiosError.response = {
|
|
175
|
+
data: error.response.data,
|
|
176
|
+
headers: error.response.headers,
|
|
177
|
+
status: error.response.status,
|
|
178
|
+
statusText: error.response.statusText,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
serializedAxiosError.code = error.code;
|
|
183
|
+
serializedAxiosError.message = error.message;
|
|
184
|
+
}
|
|
185
|
+
return serializedAxiosError;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Formats an Axios error to a printable format.
|
|
189
|
+
*
|
|
190
|
+
* @param error - Axios error to format
|
|
191
|
+
* @returns Formatted error object
|
|
192
|
+
* @deprecated Use {@link serializeAxiosError} instead
|
|
193
|
+
*/
|
|
194
|
+
function formatAxiosError(error) {
|
|
195
|
+
return serializeAxiosError(error);
|
|
196
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.test.d.ts","sourceRoot":"","sources":["../../src/logger/logger.test.ts"],"names":[],"mappings":""}
|