@devrev/ts-adaas 0.0.3 → 1.0.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 +182 -116
- package/dist/common/constants.d.ts +10 -0
- package/dist/common/constants.js +27 -0
- package/dist/common/control-protocol.d.ts +7 -0
- package/dist/common/control-protocol.js +41 -0
- package/dist/common/helpers.d.ts +4 -0
- package/dist/common/helpers.js +38 -0
- package/dist/common/install-initial-domain-mapping.d.ts +3 -0
- package/dist/common/install-initial-domain-mapping.js +87 -0
- package/dist/{src → deprecated}/adapter/index.d.ts +10 -7
- package/dist/{src → deprecated}/adapter/index.js +13 -10
- package/dist/{src → deprecated}/common/helpers.d.ts +1 -2
- package/dist/deprecated/common/helpers.js +47 -0
- package/dist/deprecated/demo-extractor/index.d.ts +17 -0
- package/dist/{src → deprecated}/demo-extractor/index.js +28 -22
- package/dist/{src → deprecated}/uploader/index.d.ts +1 -1
- package/dist/{src → deprecated}/uploader/index.js +3 -1
- package/dist/{src/http → http}/client.d.ts +2 -1
- package/dist/index.d.ts +10 -0
- package/dist/{src/index.js → index.js} +11 -3
- package/dist/logger/logger.d.ts +14 -0
- package/dist/logger/logger.interfaces.d.ts +14 -0
- package/dist/logger/logger.interfaces.js +9 -0
- package/dist/logger/logger.js +91 -0
- package/dist/logger/logger.test.js +49 -0
- package/dist/repo/repo.d.ts +14 -0
- package/dist/repo/repo.interfaces.d.ts +43 -0
- package/dist/repo/repo.interfaces.js +2 -0
- package/dist/repo/repo.js +68 -0
- package/dist/repo/repo.test.js +74 -0
- package/dist/state/state.d.ts +24 -0
- package/dist/state/state.interfaces.d.ts +24 -0
- package/dist/state/state.interfaces.js +2 -0
- package/dist/state/state.js +115 -0
- package/dist/tests/test-helpers.d.ts +9 -0
- package/dist/tests/test-helpers.interfaces.d.ts +11 -0
- package/dist/tests/test-helpers.interfaces.js +2 -0
- package/dist/tests/test-helpers.js +88 -0
- package/dist/tests/test-worker.js +16 -0
- package/dist/types/common.d.ts +39 -0
- package/dist/{src/types → types}/common.js +4 -0
- package/dist/{src/types → types}/extraction.d.ts +56 -12
- package/dist/{src/types → types}/extraction.js +12 -29
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +11 -0
- package/dist/types/workers.d.ts +142 -0
- package/dist/types/workers.js +23 -0
- package/dist/uploader/uploader.d.ts +38 -0
- package/dist/uploader/uploader.interfaces.d.ts +63 -0
- package/dist/uploader/uploader.interfaces.js +2 -0
- package/dist/uploader/uploader.js +351 -0
- package/dist/{tests → uploader}/uploader.test.js +7 -5
- package/dist/workers/create-worker.d.ts +4 -0
- package/dist/workers/create-worker.js +30 -0
- package/dist/workers/create-worker.test.js +25 -0
- package/dist/workers/default-workers/attachments-deletion.d.ts +1 -0
- package/dist/workers/default-workers/attachments-deletion.js +13 -0
- package/dist/workers/default-workers/attachments-extraction.d.ts +1 -0
- package/dist/workers/default-workers/attachments-extraction.js +49 -0
- package/dist/workers/default-workers/data-deletion.d.ts +1 -0
- package/dist/workers/default-workers/data-deletion.js +15 -0
- package/dist/workers/default-workers/data-extraction.d.ts +1 -0
- package/dist/workers/default-workers/data-extraction.js +101 -0
- package/dist/workers/default-workers/external-sync-units-extraction.d.ts +1 -0
- package/dist/workers/default-workers/external-sync-units-extraction.js +27 -0
- package/dist/workers/default-workers/metadata-extraction.d.ts +1 -0
- package/dist/workers/default-workers/metadata-extraction.js +26 -0
- package/dist/workers/dummy-extractor/data-normalization.d.ts +4 -0
- package/dist/workers/dummy-extractor/data-normalization.js +41 -0
- package/dist/workers/dummy-extractor/external_domain_metadata.json +58 -0
- package/dist/workers/process-task.d.ts +2 -0
- package/dist/workers/process-task.js +44 -0
- package/dist/workers/spawn.d.ts +25 -0
- package/dist/workers/spawn.js +163 -0
- package/dist/workers/worker-adapter.d.ts +48 -0
- package/dist/workers/worker-adapter.js +138 -0
- package/dist/workers/worker.d.ts +1 -0
- package/dist/workers/worker.js +6 -0
- package/package.json +9 -5
- package/dist/src/common/constants.d.ts +0 -2
- package/dist/src/common/constants.js +0 -10
- package/dist/src/common/helpers.js +0 -59
- package/dist/src/common/install-initial-domain-mapping.d.ts +0 -3
- package/dist/src/common/install-initial-domain-mapping.js +0 -60
- package/dist/src/demo-extractor/index.d.ts +0 -11
- package/dist/src/index.d.ts +0 -6
- package/dist/src/logging/index.d.ts +0 -18
- package/dist/src/logging/index.js +0 -39
- package/dist/src/state/index.d.ts +0 -23
- package/dist/src/state/index.js +0 -111
- package/dist/src/types/common.d.ts +0 -37
- package/dist/src/types/index.d.ts +0 -2
- package/dist/src/types/index.js +0 -18
- package/dist/tests/adapter.helpers.test.js +0 -60
- package/dist/tests/adapter.test.js +0 -123
- package/dist/tests/demo-extractor.test.js +0 -61
- package/dist/tests/state.test.js +0 -101
- /package/dist/{src → deprecated}/demo-extractor/external_domain_metadata.json +0 -0
- /package/dist/{src/http → http}/client.js +0 -0
- /package/dist/{src/http → http}/constants.d.ts +0 -0
- /package/dist/{src/http → http}/constants.js +0 -0
- /package/dist/{src/http → http}/index.d.ts +0 -0
- /package/dist/{src/http → http}/index.js +0 -0
- /package/dist/{src/http → http}/types.d.ts +0 -0
- /package/dist/{src/http → http}/types.js +0 -0
- /package/dist/{tests/adapter.helpers.test.d.ts → logger/logger.test.d.ts} +0 -0
- /package/dist/{tests/adapter.test.d.ts → repo/repo.test.d.ts} +0 -0
- /package/dist/tests/{demo-extractor.test.d.ts → test-worker.d.ts} +0 -0
- /package/dist/{tests → uploader}/uploader.test.d.ts +0 -0
- /package/dist/{tests/state.test.d.ts → workers/create-worker.test.d.ts} +0 -0
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Adapter =
|
|
6
|
+
exports.Adapter = void 0;
|
|
7
|
+
exports.createAdapter = createAdapter;
|
|
7
8
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const constants_1 = require("
|
|
9
|
+
const constants_1 = require("../../common/constants");
|
|
9
10
|
const helpers_1 = require("../common/helpers");
|
|
10
|
-
|
|
11
|
-
const state_1 = require("
|
|
11
|
+
// import { Logger } from '../../logger/logger';
|
|
12
|
+
const state_1 = require("../../state/state");
|
|
12
13
|
/**
|
|
13
14
|
* Adapter class is used to interact with Airdrop platform. The class provides
|
|
14
15
|
* utilities to
|
|
@@ -18,6 +19,7 @@ const state_1 = require("../state");
|
|
|
18
19
|
*
|
|
19
20
|
* @class Adapter
|
|
20
21
|
* @constructor
|
|
22
|
+
* @deprecated
|
|
21
23
|
* @param {AirdropEvent} event - The event object received from the platform
|
|
22
24
|
* @param {object=} initialState - The initial state of the adapter
|
|
23
25
|
* @param {boolean=} isLocalDevelopment - A flag to indicate if the adapter is being used in local development
|
|
@@ -32,19 +34,21 @@ const state_1 = require("../state");
|
|
|
32
34
|
*/
|
|
33
35
|
async function createAdapter(event, initialState, isLocalDevelopment = false) {
|
|
34
36
|
const newInitialState = structuredClone(initialState);
|
|
35
|
-
const adapterState = await (0, state_1.createAdapterState)(
|
|
37
|
+
const adapterState = await (0, state_1.createAdapterState)({
|
|
38
|
+
event,
|
|
39
|
+
initialState: newInitialState,
|
|
40
|
+
});
|
|
36
41
|
const a = new Adapter(event, adapterState, isLocalDevelopment);
|
|
37
42
|
return a;
|
|
38
43
|
}
|
|
39
|
-
exports.createAdapter = createAdapter;
|
|
40
44
|
class Adapter {
|
|
41
45
|
constructor(event, adapterState, isLocalDevelopment = false) {
|
|
46
|
+
// if (!isLocalDevelopment) {
|
|
47
|
+
// Logger.init(event);
|
|
48
|
+
// }
|
|
42
49
|
this.exit = false;
|
|
43
50
|
this.lambdaTimeout = 10 * 60 * 1000; // 10 minutes in milliseconds
|
|
44
51
|
this.heartBeatInterval = 30 * 1000; // 30 seconds in milliseconds
|
|
45
|
-
if (!isLocalDevelopment) {
|
|
46
|
-
logging_1.Logger.init(event);
|
|
47
|
-
}
|
|
48
52
|
this.adapterState = adapterState;
|
|
49
53
|
this._artifacts = [];
|
|
50
54
|
this.event = event;
|
|
@@ -122,7 +126,6 @@ class Adapter {
|
|
|
122
126
|
*/
|
|
123
127
|
exitAdapter() {
|
|
124
128
|
this.exit = true;
|
|
125
|
-
clearInterval(this.heartBeatFn);
|
|
126
129
|
}
|
|
127
130
|
/**
|
|
128
131
|
* Heartbeat function to check if the lambda is about to timeout.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EventType, ExtractorEventType } from '../../types/extraction';
|
|
2
2
|
export declare function createFormData(preparedArtifact: any, fetchedObjects: object[] | object): FormData;
|
|
3
|
-
export declare function createArtifact(preparedArtifact: any, fetchedObjects: object[] | object, entity: string): Artifact;
|
|
4
3
|
export declare function getTimeoutExtractorEventType(eventType: EventType): {
|
|
5
4
|
eventType: ExtractorEventType;
|
|
6
5
|
isError: boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFormData = createFormData;
|
|
4
|
+
exports.getTimeoutExtractorEventType = getTimeoutExtractorEventType;
|
|
5
|
+
const js_jsonl_1 = require("js-jsonl");
|
|
6
|
+
const extraction_1 = require("../../types/extraction");
|
|
7
|
+
function createFormData(
|
|
8
|
+
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
preparedArtifact, fetchedObjects) {
|
|
10
|
+
const formData = new FormData();
|
|
11
|
+
for (const item of preparedArtifact.form_data) {
|
|
12
|
+
formData.append(item.key, item.value);
|
|
13
|
+
}
|
|
14
|
+
const output = js_jsonl_1.jsonl.stringify(fetchedObjects);
|
|
15
|
+
formData.append('file', output);
|
|
16
|
+
return formData;
|
|
17
|
+
}
|
|
18
|
+
function getTimeoutExtractorEventType(eventType) {
|
|
19
|
+
switch (eventType) {
|
|
20
|
+
case extraction_1.EventType.ExtractionMetadataStart:
|
|
21
|
+
return {
|
|
22
|
+
eventType: extraction_1.ExtractorEventType.ExtractionMetadataError,
|
|
23
|
+
isError: true,
|
|
24
|
+
};
|
|
25
|
+
case extraction_1.EventType.ExtractionDataStart:
|
|
26
|
+
case extraction_1.EventType.ExtractionDataContinue:
|
|
27
|
+
return {
|
|
28
|
+
eventType: extraction_1.ExtractorEventType.ExtractionDataProgress,
|
|
29
|
+
isError: false,
|
|
30
|
+
};
|
|
31
|
+
case extraction_1.EventType.ExtractionAttachmentsStart:
|
|
32
|
+
case extraction_1.EventType.ExtractionAttachmentsContinue:
|
|
33
|
+
return {
|
|
34
|
+
eventType: extraction_1.ExtractorEventType.ExtractionAttachmentsProgress,
|
|
35
|
+
isError: false,
|
|
36
|
+
};
|
|
37
|
+
case extraction_1.EventType.ExtractionExternalSyncUnitsStart:
|
|
38
|
+
return {
|
|
39
|
+
eventType: extraction_1.ExtractorEventType.ExtractionExternalSyncUnitsError,
|
|
40
|
+
isError: true,
|
|
41
|
+
};
|
|
42
|
+
default:
|
|
43
|
+
console.log('Event type not recognized in getTimeoutExtractorEventType function: ' +
|
|
44
|
+
eventType);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AirdropEvent } from '../../types/extraction';
|
|
2
|
+
import { Adapter } from '../adapter';
|
|
3
|
+
type ConnectorState = object;
|
|
4
|
+
/**
|
|
5
|
+
* Demo extractor is a reference implementation of an ADaaS connector to facilitate rapid immersion into ADaaS.
|
|
6
|
+
*
|
|
7
|
+
* @class DemoExtractor
|
|
8
|
+
* @deprecated
|
|
9
|
+
**/
|
|
10
|
+
export declare class DemoExtractor {
|
|
11
|
+
private event;
|
|
12
|
+
private adapter;
|
|
13
|
+
private uploader;
|
|
14
|
+
constructor(event: AirdropEvent, adapter: Adapter<ConnectorState>);
|
|
15
|
+
run(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -4,9 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DemoExtractor = void 0;
|
|
7
|
-
const
|
|
7
|
+
const extraction_1 = require("../../types/extraction");
|
|
8
8
|
const uploader_1 = require("../uploader");
|
|
9
9
|
const external_domain_metadata_json_1 = __importDefault(require("./external_domain_metadata.json"));
|
|
10
|
+
/**
|
|
11
|
+
* Demo extractor is a reference implementation of an ADaaS connector to facilitate rapid immersion into ADaaS.
|
|
12
|
+
*
|
|
13
|
+
* @class DemoExtractor
|
|
14
|
+
* @deprecated
|
|
15
|
+
**/
|
|
10
16
|
class DemoExtractor {
|
|
11
17
|
constructor(event, adapter) {
|
|
12
18
|
this.event = event;
|
|
@@ -15,7 +21,7 @@ class DemoExtractor {
|
|
|
15
21
|
}
|
|
16
22
|
async run() {
|
|
17
23
|
switch (this.event.payload.event_type) {
|
|
18
|
-
case
|
|
24
|
+
case extraction_1.EventType.ExtractionExternalSyncUnitsStart: {
|
|
19
25
|
const externalSyncUnits = [
|
|
20
26
|
{
|
|
21
27
|
id: 'devrev',
|
|
@@ -23,25 +29,25 @@ class DemoExtractor {
|
|
|
23
29
|
description: 'Demo external sync unit',
|
|
24
30
|
},
|
|
25
31
|
];
|
|
26
|
-
await this.adapter.emit(
|
|
32
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionExternalSyncUnitsDone, {
|
|
27
33
|
external_sync_units: externalSyncUnits,
|
|
28
34
|
});
|
|
29
35
|
break;
|
|
30
36
|
}
|
|
31
|
-
case
|
|
37
|
+
case extraction_1.EventType.ExtractionMetadataStart: {
|
|
32
38
|
const { artifact, error } = await this.uploader.upload('metadata_1.jsonl', 'external_domain_metadata', external_domain_metadata_json_1.default);
|
|
33
39
|
if (error || !artifact) {
|
|
34
|
-
await this.adapter.emit(
|
|
40
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionMetadataError, {
|
|
35
41
|
error,
|
|
36
42
|
});
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
39
|
-
await this.adapter.emit(
|
|
45
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionMetadataDone, {
|
|
40
46
|
artifacts: [artifact],
|
|
41
47
|
});
|
|
42
48
|
break;
|
|
43
49
|
}
|
|
44
|
-
case
|
|
50
|
+
case extraction_1.EventType.ExtractionDataStart: {
|
|
45
51
|
const contacts = [
|
|
46
52
|
{
|
|
47
53
|
id: 'contact-1',
|
|
@@ -64,18 +70,18 @@ class DemoExtractor {
|
|
|
64
70
|
];
|
|
65
71
|
const { artifact, error } = await this.uploader.upload('contacts_1.json', 'contacts', contacts);
|
|
66
72
|
if (error || !artifact) {
|
|
67
|
-
await this.adapter.emit(
|
|
73
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionDataError, {
|
|
68
74
|
error,
|
|
69
75
|
});
|
|
70
76
|
return;
|
|
71
77
|
}
|
|
72
|
-
await this.adapter.emit(
|
|
78
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionDataProgress, {
|
|
73
79
|
progress: 50,
|
|
74
80
|
artifacts: [artifact],
|
|
75
81
|
});
|
|
76
82
|
break;
|
|
77
83
|
}
|
|
78
|
-
case
|
|
84
|
+
case extraction_1.EventType.ExtractionDataContinue: {
|
|
79
85
|
const users = [
|
|
80
86
|
{
|
|
81
87
|
id: 'user-1',
|
|
@@ -98,51 +104,51 @@ class DemoExtractor {
|
|
|
98
104
|
];
|
|
99
105
|
const { artifact, error } = await this.uploader.upload('users_1.json', 'users', users);
|
|
100
106
|
if (error || !artifact) {
|
|
101
|
-
await this.adapter.emit(
|
|
107
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionDataError, {
|
|
102
108
|
error,
|
|
103
109
|
});
|
|
104
110
|
return;
|
|
105
111
|
}
|
|
106
|
-
await this.adapter.emit(
|
|
112
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionDataDone, {
|
|
107
113
|
progress: 100,
|
|
108
114
|
artifacts: [artifact],
|
|
109
115
|
});
|
|
110
116
|
break;
|
|
111
117
|
}
|
|
112
|
-
case
|
|
113
|
-
await this.adapter.emit(
|
|
118
|
+
case extraction_1.EventType.ExtractionDataDelete: {
|
|
119
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionDataDeleteDone);
|
|
114
120
|
break;
|
|
115
121
|
}
|
|
116
|
-
case
|
|
122
|
+
case extraction_1.EventType.ExtractionAttachmentsStart: {
|
|
117
123
|
const attachment1 = ['This is attachment1.txt content'];
|
|
118
124
|
const { artifact, error } = await this.uploader.upload('attachment1.txt', 'attachment', attachment1);
|
|
119
125
|
if (error || !artifact) {
|
|
120
|
-
await this.adapter.emit(
|
|
126
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
121
127
|
error,
|
|
122
128
|
});
|
|
123
129
|
return;
|
|
124
130
|
}
|
|
125
|
-
await this.adapter.emit(
|
|
131
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionAttachmentsProgress, {
|
|
126
132
|
artifacts: [artifact],
|
|
127
133
|
});
|
|
128
134
|
break;
|
|
129
135
|
}
|
|
130
|
-
case
|
|
136
|
+
case extraction_1.EventType.ExtractionAttachmentsContinue: {
|
|
131
137
|
const attachment2 = ['This is attachment2.txt content'];
|
|
132
138
|
const { artifact, error } = await this.uploader.upload('attachment2.txt', 'attachment', attachment2);
|
|
133
139
|
if (error || !artifact) {
|
|
134
|
-
await this.adapter.emit(
|
|
140
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
135
141
|
error,
|
|
136
142
|
});
|
|
137
143
|
return;
|
|
138
144
|
}
|
|
139
|
-
await this.adapter.emit(
|
|
145
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionAttachmentsDone, {
|
|
140
146
|
artifacts: [artifact],
|
|
141
147
|
});
|
|
142
148
|
break;
|
|
143
149
|
}
|
|
144
|
-
case
|
|
145
|
-
await this.adapter.emit(
|
|
150
|
+
case extraction_1.EventType.ExtractionAttachmentsDelete: {
|
|
151
|
+
await this.adapter.emit(extraction_1.ExtractorEventType.ExtractionAttachmentsDeleteDone);
|
|
146
152
|
break;
|
|
147
153
|
}
|
|
148
154
|
default: {
|
|
@@ -106,7 +106,9 @@ class Uploader {
|
|
|
106
106
|
}
|
|
107
107
|
async uploadToArtifact(
|
|
108
108
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
|
-
preparedArtifact, fetchedObjects
|
|
109
|
+
preparedArtifact, fetchedObjects
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
) {
|
|
110
112
|
const formData = (0, helpers_1.createFormData)(preparedArtifact, fetchedObjects);
|
|
111
113
|
try {
|
|
112
114
|
const response = await axios_1.default.post(preparedArtifact.url, formData, {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RawAxiosRequestHeaders } from 'axios';
|
|
1
2
|
import { HTTPResponse } from './types';
|
|
2
3
|
export declare const defaultResponse: HTTPResponse;
|
|
3
4
|
export declare class HTTPClient {
|
|
@@ -12,5 +13,5 @@ export declare class HTTPClient {
|
|
|
12
13
|
* In case of rate limit exceeded, the function returns success as true and the delay time in seconds
|
|
13
14
|
* In case of any other error, the function returns success as false and the error message
|
|
14
15
|
*/
|
|
15
|
-
getCall(endpoint: string, headers:
|
|
16
|
+
getCall(endpoint: string, headers: RawAxiosRequestHeaders, params?: any): Promise<HTTPResponse>;
|
|
16
17
|
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './deprecated/adapter';
|
|
2
|
+
export * from './deprecated/demo-extractor';
|
|
3
|
+
export * from './deprecated/uploader';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './http';
|
|
6
|
+
export * from './common/install-initial-domain-mapping';
|
|
7
|
+
export { WorkerAdapter } from './workers/worker-adapter';
|
|
8
|
+
export { processTask } from './workers/process-task';
|
|
9
|
+
export { spawn } from './workers/spawn';
|
|
10
|
+
export * from './types/workers';
|
|
@@ -14,9 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
17
|
+
exports.spawn = exports.processTask = exports.WorkerAdapter = void 0;
|
|
18
|
+
__exportStar(require("./deprecated/adapter"), exports);
|
|
19
|
+
__exportStar(require("./deprecated/demo-extractor"), exports);
|
|
20
|
+
__exportStar(require("./deprecated/uploader"), exports);
|
|
20
21
|
__exportStar(require("./types"), exports);
|
|
21
22
|
__exportStar(require("./http"), exports);
|
|
22
23
|
__exportStar(require("./common/install-initial-domain-mapping"), exports);
|
|
24
|
+
var worker_adapter_1 = require("./workers/worker-adapter");
|
|
25
|
+
Object.defineProperty(exports, "WorkerAdapter", { enumerable: true, get: function () { return worker_adapter_1.WorkerAdapter; } });
|
|
26
|
+
var process_task_1 = require("./workers/process-task");
|
|
27
|
+
Object.defineProperty(exports, "processTask", { enumerable: true, get: function () { return process_task_1.processTask; } });
|
|
28
|
+
var spawn_1 = require("./workers/spawn");
|
|
29
|
+
Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { return spawn_1.spawn; } });
|
|
30
|
+
__exportStar(require("./types/workers"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Console } from 'node:console';
|
|
2
|
+
import { LogLevel, PrintableState } from './logger.interfaces';
|
|
3
|
+
import { AirdropEvent } from '../types';
|
|
4
|
+
import { AxiosError } from 'axios';
|
|
5
|
+
export declare class Logger extends Console {
|
|
6
|
+
constructor(event: AirdropEvent);
|
|
7
|
+
logFn(args: unknown[], level: LogLevel): void;
|
|
8
|
+
log(...args: unknown[]): void;
|
|
9
|
+
info(...args: unknown[]): void;
|
|
10
|
+
warn(...args: unknown[]): void;
|
|
11
|
+
error(...args: unknown[]): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function getPrintableState(state: Record<string, any>): PrintableState;
|
|
14
|
+
export declare function formatAxiosError(error: AxiosError): object;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
INFO = "info",
|
|
3
|
+
WARN = "warn",
|
|
4
|
+
ERROR = "error"
|
|
5
|
+
}
|
|
6
|
+
export interface PrintableArray {
|
|
7
|
+
type: 'array';
|
|
8
|
+
length: number;
|
|
9
|
+
firstItem?: any;
|
|
10
|
+
lastItem?: any;
|
|
11
|
+
}
|
|
12
|
+
export interface PrintableState {
|
|
13
|
+
[key: string]: any | PrintableArray | PrintableState;
|
|
14
|
+
}
|
|
@@ -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,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Logger = void 0;
|
|
7
|
+
exports.getPrintableState = getPrintableState;
|
|
8
|
+
exports.formatAxiosError = formatAxiosError;
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
|
+
const lambda_log_1 = __importDefault(require("lambda-log"));
|
|
11
|
+
const node_console_1 = require("node:console");
|
|
12
|
+
const logger_interfaces_1 = require("./logger.interfaces");
|
|
13
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
14
|
+
const workers_1 = require("../types/workers");
|
|
15
|
+
class Logger extends node_console_1.Console {
|
|
16
|
+
constructor(event) {
|
|
17
|
+
super(process.stdout, process.stderr);
|
|
18
|
+
lambda_log_1.default.options.levelKey = null;
|
|
19
|
+
lambda_log_1.default.options.tagsKey = null;
|
|
20
|
+
lambda_log_1.default.options.messageKey = 'message';
|
|
21
|
+
lambda_log_1.default.options.meta = Object.assign({}, event.payload.event_context);
|
|
22
|
+
}
|
|
23
|
+
logFn(args, level) {
|
|
24
|
+
if (node_worker_threads_1.isMainThread) {
|
|
25
|
+
lambda_log_1.default.log(level, JSON.stringify(args));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
29
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
30
|
+
payload: {
|
|
31
|
+
args,
|
|
32
|
+
level,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
log(...args) {
|
|
38
|
+
this.logFn(args, logger_interfaces_1.LogLevel.INFO);
|
|
39
|
+
}
|
|
40
|
+
info(...args) {
|
|
41
|
+
this.logFn(args, logger_interfaces_1.LogLevel.INFO);
|
|
42
|
+
}
|
|
43
|
+
warn(...args) {
|
|
44
|
+
this.logFn(args, logger_interfaces_1.LogLevel.WARN);
|
|
45
|
+
}
|
|
46
|
+
error(...args) {
|
|
47
|
+
this.logFn(args, logger_interfaces_1.LogLevel.ERROR);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Logger = Logger;
|
|
51
|
+
// Helper function to process each value in the state
|
|
52
|
+
function getPrintableState(state) {
|
|
53
|
+
function processValue(value) {
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
// If the value is an array, summarize it
|
|
56
|
+
return {
|
|
57
|
+
type: 'array',
|
|
58
|
+
length: value.length,
|
|
59
|
+
firstItem: value.length > 0 ? value[0] : undefined,
|
|
60
|
+
lastItem: value.length > 1 ? value[value.length - 1] : undefined,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
else if (typeof value === 'object' && value !== null) {
|
|
64
|
+
// If the value is an object, recursively process its properties
|
|
65
|
+
const processedObject = {};
|
|
66
|
+
for (const key in value) {
|
|
67
|
+
if (value.hasOwnProperty(key)) {
|
|
68
|
+
processedObject[key] = processValue(value[key]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return processedObject;
|
|
72
|
+
}
|
|
73
|
+
// For primitive types, return the value as is
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
// Process the state object directly since it's guaranteed to be an object
|
|
77
|
+
return processValue(state);
|
|
78
|
+
}
|
|
79
|
+
function formatAxiosError(error) {
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
if (error.response) {
|
|
82
|
+
return {
|
|
83
|
+
status: error.response.status,
|
|
84
|
+
data: error.response.data,
|
|
85
|
+
method: (_a = error.config) === null || _a === void 0 ? void 0 : _a.method,
|
|
86
|
+
baseURL: (_b = error.config) === null || _b === void 0 ? void 0 : _b.baseURL,
|
|
87
|
+
url: (_c = error.config) === null || _c === void 0 ? void 0 : _c.url,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return error;
|
|
91
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logger_1 = require("./logger");
|
|
4
|
+
it('getPrintableState should return printable state', () => {
|
|
5
|
+
const state = {
|
|
6
|
+
test_key: 'test_value',
|
|
7
|
+
big_array: Array.from({ length: 1000 }, (_, index) => index),
|
|
8
|
+
nested_object: {
|
|
9
|
+
nested_key: 'nested_value',
|
|
10
|
+
nested_array: Array.from({ length: 1000 }, (_, index) => index),
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const printableState = (0, logger_1.getPrintableState)(state);
|
|
14
|
+
expect(printableState).toEqual({
|
|
15
|
+
test_key: 'test_value',
|
|
16
|
+
big_array: {
|
|
17
|
+
type: 'array',
|
|
18
|
+
length: 1000,
|
|
19
|
+
firstItem: 0,
|
|
20
|
+
lastItem: 999,
|
|
21
|
+
},
|
|
22
|
+
nested_object: {
|
|
23
|
+
nested_key: 'nested_value',
|
|
24
|
+
nested_array: {
|
|
25
|
+
type: 'array',
|
|
26
|
+
length: 1000,
|
|
27
|
+
firstItem: 0,
|
|
28
|
+
lastItem: 999,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it('formatAxiosError should return formatted error', () => {
|
|
34
|
+
const error = {
|
|
35
|
+
response: {
|
|
36
|
+
status: 500,
|
|
37
|
+
data: 'Internal server error',
|
|
38
|
+
},
|
|
39
|
+
config: {
|
|
40
|
+
method: 'GET',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const formattedError = (0, logger_1.formatAxiosError)(error);
|
|
44
|
+
expect(formattedError).toEqual({
|
|
45
|
+
status: 500,
|
|
46
|
+
data: 'Internal server error',
|
|
47
|
+
method: 'GET',
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ErrorRecord } from '../types/common';
|
|
2
|
+
import { Item } from '../repo/repo.interfaces';
|
|
3
|
+
import { RepoFactoryInterface, NormalizedItem, NormalizedAttachment } from './repo.interfaces';
|
|
4
|
+
export declare class Repo {
|
|
5
|
+
readonly itemType: string;
|
|
6
|
+
private items;
|
|
7
|
+
private normalize?;
|
|
8
|
+
private uploader;
|
|
9
|
+
private onUpload;
|
|
10
|
+
constructor({ event, itemType, normalize, onUpload, options, }: RepoFactoryInterface);
|
|
11
|
+
getItems(): (NormalizedItem | NormalizedAttachment | Item)[];
|
|
12
|
+
upload(batch?: (NormalizedItem | NormalizedAttachment | Item)[]): Promise<void | ErrorRecord>;
|
|
13
|
+
push(items: Item[]): Promise<void | ErrorRecord>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Artifact } from '../uploader/uploader.interfaces';
|
|
2
|
+
import { AirdropEvent } from '../types/extraction';
|
|
3
|
+
import { WorkerAdapterOptions } from '../types/workers';
|
|
4
|
+
/**
|
|
5
|
+
* RepoInterface is an interface that defines the structure of a repo which is used to store and upload extracted data.
|
|
6
|
+
*/
|
|
7
|
+
export interface RepoInterface {
|
|
8
|
+
itemType: string;
|
|
9
|
+
normalize?: (record: object) => NormalizedItem | NormalizedAttachment;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* RepoFactoryInterface is an interface that defines the structure of a repo factory which is used to create a repo.
|
|
13
|
+
*/
|
|
14
|
+
export interface RepoFactoryInterface {
|
|
15
|
+
event: AirdropEvent;
|
|
16
|
+
itemType: string;
|
|
17
|
+
normalize?: (record: object) => NormalizedItem | NormalizedAttachment;
|
|
18
|
+
onUpload: (artifact: Artifact) => void;
|
|
19
|
+
options?: WorkerAdapterOptions;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* NormalizedItem is an interface of item after normalization.
|
|
23
|
+
*/
|
|
24
|
+
export interface NormalizedItem {
|
|
25
|
+
id: string;
|
|
26
|
+
created_date: string;
|
|
27
|
+
modified_date: string;
|
|
28
|
+
data: object;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* NormalizedAttachment is an interface of attachment after normalization.
|
|
32
|
+
*/
|
|
33
|
+
export interface NormalizedAttachment {
|
|
34
|
+
url: string;
|
|
35
|
+
id: string;
|
|
36
|
+
file_name: string;
|
|
37
|
+
author_id: string;
|
|
38
|
+
parent_id: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Item is an interface that defines the structure of an item.
|
|
42
|
+
*/
|
|
43
|
+
export type Item = Record<string, any>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Repo = void 0;
|
|
4
|
+
const constants_1 = require("../common/constants");
|
|
5
|
+
const uploader_1 = require("../uploader/uploader");
|
|
6
|
+
class Repo {
|
|
7
|
+
constructor({ event, itemType, normalize, onUpload, options, }) {
|
|
8
|
+
this.items = [];
|
|
9
|
+
this.itemType = itemType;
|
|
10
|
+
this.normalize = normalize;
|
|
11
|
+
this.onUpload = onUpload;
|
|
12
|
+
this.uploader = new uploader_1.Uploader({ event, options });
|
|
13
|
+
}
|
|
14
|
+
getItems() {
|
|
15
|
+
return this.items;
|
|
16
|
+
}
|
|
17
|
+
async upload(batch) {
|
|
18
|
+
const itemsToUpload = batch || this.items;
|
|
19
|
+
if (itemsToUpload.length > 0) {
|
|
20
|
+
console.log(`Uploading ${itemsToUpload.length} items of type ${this.itemType}.`);
|
|
21
|
+
const { artifact, error } = await this.uploader.upload(this.itemType, itemsToUpload);
|
|
22
|
+
if (error || !artifact) {
|
|
23
|
+
console.error('Error while uploading batch', error);
|
|
24
|
+
return error;
|
|
25
|
+
}
|
|
26
|
+
this.onUpload(artifact);
|
|
27
|
+
// Clear the uploaded items from the main items array if no batch was specified
|
|
28
|
+
if (!batch) {
|
|
29
|
+
this.items = [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
console.log(`No items to upload for type ${this.itemType}. Skipping upload.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async push(items) {
|
|
37
|
+
return new Promise(async (resolve, reject) => {
|
|
38
|
+
let recordsToPush;
|
|
39
|
+
// Normalize items if needed
|
|
40
|
+
if (this.normalize &&
|
|
41
|
+
!Object.values(constants_1.AIRDROP_DEFAULT_ITEM_TYPES).includes(this.itemType)) {
|
|
42
|
+
recordsToPush = items.map((item) => this.normalize(item));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
recordsToPush = items;
|
|
46
|
+
}
|
|
47
|
+
// Add the new records to the items array
|
|
48
|
+
this.items.push(...recordsToPush);
|
|
49
|
+
console.log(`Extracted ${this.items.length} items of type ${this.itemType}.`);
|
|
50
|
+
// Upload in batches while the number of items exceeds the batch size
|
|
51
|
+
while (this.items.length >= constants_1.ARTIFACT_BATCH_SIZE) {
|
|
52
|
+
// Slice out a batch of ARTIFACT_BATCH_SIZE items to upload
|
|
53
|
+
const batch = this.items.splice(0, constants_1.ARTIFACT_BATCH_SIZE);
|
|
54
|
+
try {
|
|
55
|
+
// Upload the batch
|
|
56
|
+
await this.upload(batch);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Error while uploading batch', error);
|
|
60
|
+
reject(error);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
resolve();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.Repo = Repo;
|