@devrev/ts-adaas 1.12.3-beta.1 → 1.12.3-beta.3
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/common/control-protocol.js +1 -1
- package/dist/common/event-type-translation.d.ts +4 -4
- package/dist/common/event-type-translation.js +7 -7
- package/dist/types/workers.d.ts +4 -3
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/workers/spawn.d.ts.map +1 -1
- package/dist/workers/spawn.js +12 -36
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ const axios_client_internal_1 = require("../http/axios-client-internal");
|
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const event_type_translation_1 = require("./event-type-translation");
|
|
7
7
|
const emit = async ({ event, eventType, data, }) => {
|
|
8
|
-
//
|
|
8
|
+
// Translate outgoing event type to ensure we always send new event types
|
|
9
9
|
// TODO: Remove when the old types are completely phased out
|
|
10
10
|
const translatedEventType = (0, event_type_translation_1.translateOutgoingEventType)(eventType);
|
|
11
11
|
const newEvent = {
|
|
@@ -4,21 +4,21 @@ import { LoaderEventType } from '../types/loading';
|
|
|
4
4
|
* Maps old incoming event type strings to new EventType enum values.
|
|
5
5
|
* This ensures backwards compatibility when the platform sends old event types.
|
|
6
6
|
* @param eventTypeString The raw event type string from the platform
|
|
7
|
-
* @returns The
|
|
7
|
+
* @returns The translated EventType enum value
|
|
8
8
|
*/
|
|
9
9
|
export declare function translateIncomingEventType(eventTypeString: string): EventType;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Translates ExtractorEventType enum values by converting old enum members to new ones.
|
|
12
12
|
* Old enum members are deprecated and should be replaced with new ones.
|
|
13
13
|
*/
|
|
14
14
|
export declare function translateExtractorEventType(eventType: ExtractorEventType): ExtractorEventType;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Translates LoaderEventType enum values by converting old enum members to new ones.
|
|
17
17
|
* Old enum members are deprecated and should be replaced with new ones.
|
|
18
18
|
*/
|
|
19
19
|
export declare function translateLoaderEventType(eventType: LoaderEventType): LoaderEventType;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Translates any outgoing event type (Extractor or Loader) to ensure new event types are used.
|
|
22
22
|
*/
|
|
23
23
|
export declare function translateOutgoingEventType(eventType: ExtractorEventType | LoaderEventType): ExtractorEventType | LoaderEventType;
|
|
24
24
|
//# sourceMappingURL=event-type-translation.d.ts.map
|
|
@@ -10,7 +10,7 @@ const loading_1 = require("../types/loading");
|
|
|
10
10
|
* Maps old incoming event type strings to new EventType enum values.
|
|
11
11
|
* This ensures backwards compatibility when the platform sends old event types.
|
|
12
12
|
* @param eventTypeString The raw event type string from the platform
|
|
13
|
-
* @returns The
|
|
13
|
+
* @returns The translated EventType enum value
|
|
14
14
|
*/
|
|
15
15
|
function translateIncomingEventType(eventTypeString) {
|
|
16
16
|
// Create a reverse mapping from OLD string values to NEW enum member names
|
|
@@ -43,16 +43,16 @@ function translateIncomingEventType(eventTypeString) {
|
|
|
43
43
|
// Unknown
|
|
44
44
|
[extraction_1.EventType.UnknownEventType]: extraction_1.EventType.UnknownEventType,
|
|
45
45
|
};
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
46
|
+
const translated = eventTypeMap[eventTypeString];
|
|
47
|
+
if (!translated) {
|
|
48
48
|
console.warn(`Unknown event type received: ${eventTypeString}. This may indicate a new event type or a typo.`);
|
|
49
49
|
// Return the original string cast as EventType as a fallback
|
|
50
50
|
return eventTypeString;
|
|
51
51
|
}
|
|
52
|
-
return
|
|
52
|
+
return translated;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Translates ExtractorEventType enum values by converting old enum members to new ones.
|
|
56
56
|
* Old enum members are deprecated and should be replaced with new ones.
|
|
57
57
|
*/
|
|
58
58
|
function translateExtractorEventType(eventType) {
|
|
@@ -82,7 +82,7 @@ function translateExtractorEventType(eventType) {
|
|
|
82
82
|
return (_a = mapping[stringValue]) !== null && _a !== void 0 ? _a : eventType;
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* Translates LoaderEventType enum values by converting old enum members to new ones.
|
|
86
86
|
* Old enum members are deprecated and should be replaced with new ones.
|
|
87
87
|
*/
|
|
88
88
|
function translateLoaderEventType(eventType) {
|
|
@@ -101,7 +101,7 @@ function translateLoaderEventType(eventType) {
|
|
|
101
101
|
return (_a = mapping[stringValue]) !== null && _a !== void 0 ? _a : eventType;
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
104
|
+
* Translates any outgoing event type (Extractor or Loader) to ensure new event types are used.
|
|
105
105
|
*/
|
|
106
106
|
function translateOutgoingEventType(eventType) {
|
|
107
107
|
// Check if it's an ExtractorEventType by checking if the value exists in ExtractorEventType
|
package/dist/types/workers.d.ts
CHANGED
|
@@ -24,12 +24,14 @@ export interface WorkerAdapterInterface<ConnectorState> {
|
|
|
24
24
|
* @param {boolean=} isLocalDevelopment - A flag to indicate if the adapter is being used in local development
|
|
25
25
|
* @param {number=} timeout - The timeout for the worker thread
|
|
26
26
|
* @param {number=} batchSize - Maximum number of extracted items in a batch
|
|
27
|
-
* @param {
|
|
27
|
+
* @param {string=} baseWorkerPath - The base path for the worker files, usually `__dirname`
|
|
28
|
+
* @param {Record<EventType, string>=} workerPathOverrides - A map of event types to custom worker paths to override default worker paths
|
|
28
29
|
*/
|
|
29
30
|
export interface WorkerAdapterOptions {
|
|
30
31
|
isLocalDevelopment?: boolean;
|
|
31
32
|
timeout?: number;
|
|
32
33
|
batchSize?: number;
|
|
34
|
+
baseWorkerPath?: string;
|
|
33
35
|
workerPathOverrides?: Partial<Record<EventType, string>>;
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
@@ -137,7 +139,6 @@ export interface WorkerData<ConnectorState> {
|
|
|
137
139
|
*/
|
|
138
140
|
export interface GetWorkerPathInterface {
|
|
139
141
|
event: AirdropEvent;
|
|
140
|
-
|
|
141
|
-
callerDir?: string | null;
|
|
142
|
+
workerBasePath?: string | null;
|
|
142
143
|
}
|
|
143
144
|
//# sourceMappingURL=workers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../../src/types/workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB,CAAC,cAAc;IACpD,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED
|
|
1
|
+
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../../src/types/workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB,CAAC,cAAc;IACpD,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,KAAK,CAAC,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E;AAED;;GAEG;AACH,oBAAY,WAAW;IACrB,aAAa,YAAY;IACzB,YAAY,WAAW;IACvB,WAAW,UAAU;IACrB,UAAU,SAAS;CACpB;AAED;;GAEG;AACH,oBAAY,oBAAoB;IAC9B,oBAAoB,SAAS;IAC7B,iBAAiB,SAAS;IAC1B,gBAAgB,QAAQ;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,oBAAoB,CAAC,oBAAoB,CAAC;IACnD,OAAO,EAAE;QACP,SAAS,EAAE,kBAAkB,GAAG,eAAe,CAAC;KACjD,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,oBAAoB,CAAC,iBAAiB,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,cAAc;IACxC,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,YAAY,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,qBAAqB,EACrB,cAAc,EAGf,MAAM,kBAAkB,CAAC;AAmC1B;;;;;;;;;;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,CAqGvD;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,OAAO,CAA4C;IAC3D,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,MAAM,CAAS;gBACX,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,eAAe,GAChB,EAAE,cAAc;IAgGjB,OAAO,CAAC,aAAa;YAYP,kBAAkB;CAiCjC"}
|
package/dist/workers/spawn.js
CHANGED
|
@@ -15,10 +15,7 @@ const extraction_1 = require("../types/extraction");
|
|
|
15
15
|
const workers_1 = require("../types/workers");
|
|
16
16
|
const constants_1 = require("../common/constants");
|
|
17
17
|
const create_worker_1 = require("./create-worker");
|
|
18
|
-
|
|
19
|
-
function getWorkerPath({ event, connectorWorkerPath, callerDir }) {
|
|
20
|
-
if (connectorWorkerPath)
|
|
21
|
-
return connectorWorkerPath;
|
|
18
|
+
function getWorkerPath({ event, workerBasePath }) {
|
|
22
19
|
let path = null;
|
|
23
20
|
switch (event.payload.event_type) {
|
|
24
21
|
case extraction_1.EventType.StartExtractingExternalSyncUnits:
|
|
@@ -36,30 +33,7 @@ function getWorkerPath({ event, connectorWorkerPath, callerDir }) {
|
|
|
36
33
|
path = '/workers/attachments-extraction';
|
|
37
34
|
break;
|
|
38
35
|
}
|
|
39
|
-
return path ?
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Gets the directory of the file that called into the SDK (the snap-in's file)
|
|
43
|
-
* by inspecting the call stack and finding the first file outside the SDK.
|
|
44
|
-
*/
|
|
45
|
-
function getCallerDirectory() {
|
|
46
|
-
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
47
|
-
Error.prepareStackTrace = (_, stack) => stack;
|
|
48
|
-
const err = new Error();
|
|
49
|
-
Error.captureStackTrace(err);
|
|
50
|
-
const stack = err.stack;
|
|
51
|
-
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
52
|
-
// Iterate through the stack to find the first file that's not part of the SDK
|
|
53
|
-
for (const callSite of stack) {
|
|
54
|
-
const filename = callSite.getFileName();
|
|
55
|
-
if (filename &&
|
|
56
|
-
!filename.includes('@devrev/ts-adaas') &&
|
|
57
|
-
!filename.includes('adaas-sdk')) {
|
|
58
|
-
return path_1.default.dirname(filename);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Fallback to __dirname if we can't determine the caller
|
|
62
|
-
return __dirname;
|
|
36
|
+
return path ? workerBasePath + path : null;
|
|
63
37
|
}
|
|
64
38
|
/**
|
|
65
39
|
* Creates a new instance of Spawn class.
|
|
@@ -73,13 +47,12 @@ function getCallerDirectory() {
|
|
|
73
47
|
* @returns {Promise<Spawn>} - A new instance of Spawn class
|
|
74
48
|
*/
|
|
75
49
|
async function spawn({ event, initialState, workerPath, initialDomainMapping, options, }) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Normalize incoming event type for backwards compatibility
|
|
50
|
+
var _a;
|
|
51
|
+
// Translates incoming event type for backwards compatibility
|
|
79
52
|
// This allows the SDK to accept both old and new event type formats
|
|
80
53
|
const originalEventType = event.payload.event_type;
|
|
81
54
|
const translatedEventType = (0, event_type_translation_1.translateIncomingEventType)(event.payload.event_type);
|
|
82
|
-
// Update the event with the
|
|
55
|
+
// Update the event with the translated event type
|
|
83
56
|
event.payload.event_type = translatedEventType;
|
|
84
57
|
if (translatedEventType !== originalEventType) {
|
|
85
58
|
console.log(`Event type translated from ${originalEventType} to ${translatedEventType}.`);
|
|
@@ -96,15 +69,18 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
96
69
|
// eslint-disable-next-line no-global-assign
|
|
97
70
|
console = new logger_1.Logger({ event, options });
|
|
98
71
|
let script = null;
|
|
99
|
-
if (
|
|
72
|
+
if (workerPath != null) {
|
|
73
|
+
script = workerPath;
|
|
74
|
+
}
|
|
75
|
+
else if ((options === null || options === void 0 ? void 0 : options.baseWorkerPath) != null &&
|
|
76
|
+
(options === null || options === void 0 ? void 0 : options.workerPathOverrides) != null &&
|
|
100
77
|
options.workerPathOverrides[translatedEventType] != null) {
|
|
101
|
-
script =
|
|
78
|
+
script = options.baseWorkerPath + options.workerPathOverrides[translatedEventType];
|
|
102
79
|
}
|
|
103
80
|
else {
|
|
104
81
|
script = getWorkerPath({
|
|
105
82
|
event,
|
|
106
|
-
|
|
107
|
-
callerDir: callerDir
|
|
83
|
+
workerBasePath: (_a = options === null || options === void 0 ? void 0 : options.baseWorkerPath) !== null && _a !== void 0 ? _a : __dirname
|
|
108
84
|
});
|
|
109
85
|
}
|
|
110
86
|
if (script) {
|
package/package.json
CHANGED