@devrev/ts-adaas 0.0.2 → 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 +186 -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/external_domain_metadata.json +38 -0
- package/dist/deprecated/demo-extractor/index.d.ts +17 -0
- package/dist/deprecated/demo-extractor/index.js +161 -0
- 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/index.js +30 -0
- 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 +57 -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/demo-extractor/index.d.ts +0 -11
- package/dist/src/demo-extractor/index.js +0 -157
- package/dist/src/demo-extractor/initial_domain_mapping.json +0 -107
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.js +0 -21
- 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 -33
- 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 -122
- package/dist/tests/demo-extractor.test.js +0 -60
- package/dist/tests/state.test.js +0 -100
- /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
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTimeoutExtractorEventType = exports.createArtifact = exports.createFormData = void 0;
|
|
4
|
-
const js_jsonl_1 = require("js-jsonl");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
function createFormData(
|
|
7
|
-
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
preparedArtifact, fetchedObjects) {
|
|
9
|
-
const formData = new FormData();
|
|
10
|
-
for (const item of preparedArtifact.form_data) {
|
|
11
|
-
formData.append(item.key, item.value);
|
|
12
|
-
}
|
|
13
|
-
const output = js_jsonl_1.jsonl.stringify(fetchedObjects);
|
|
14
|
-
formData.append('file', output);
|
|
15
|
-
return formData;
|
|
16
|
-
}
|
|
17
|
-
exports.createFormData = createFormData;
|
|
18
|
-
function createArtifact(
|
|
19
|
-
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
preparedArtifact, fetchedObjects, entity) {
|
|
21
|
-
const itemCount = Array.isArray(fetchedObjects) ? fetchedObjects.length : 1;
|
|
22
|
-
return {
|
|
23
|
-
item_count: itemCount,
|
|
24
|
-
id: preparedArtifact.id,
|
|
25
|
-
item_type: entity,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
exports.createArtifact = createArtifact;
|
|
29
|
-
function getTimeoutExtractorEventType(eventType) {
|
|
30
|
-
switch (eventType) {
|
|
31
|
-
case types_1.EventType.ExtractionMetadataStart:
|
|
32
|
-
return {
|
|
33
|
-
eventType: types_1.ExtractorEventType.ExtractionMetadataError,
|
|
34
|
-
isError: true,
|
|
35
|
-
};
|
|
36
|
-
case types_1.EventType.ExtractionDataStart:
|
|
37
|
-
case types_1.EventType.ExtractionDataContinue:
|
|
38
|
-
return {
|
|
39
|
-
eventType: types_1.ExtractorEventType.ExtractionDataProgress,
|
|
40
|
-
isError: false,
|
|
41
|
-
};
|
|
42
|
-
case types_1.EventType.ExtractionAttachmentsStart:
|
|
43
|
-
case types_1.EventType.ExtractionAttachmentsContinue:
|
|
44
|
-
return {
|
|
45
|
-
eventType: types_1.ExtractorEventType.ExtractionAttachmentsProgress,
|
|
46
|
-
isError: false,
|
|
47
|
-
};
|
|
48
|
-
case types_1.EventType.ExtractionExternalSyncUnitsStart:
|
|
49
|
-
return {
|
|
50
|
-
eventType: types_1.ExtractorEventType.ExtractionExternalSyncUnitsError,
|
|
51
|
-
isError: true,
|
|
52
|
-
};
|
|
53
|
-
default:
|
|
54
|
-
console.log('Event type not recognized in getTimeoutExtractorEventType function: ' +
|
|
55
|
-
eventType);
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.getTimeoutExtractorEventType = getTimeoutExtractorEventType;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AirdropEvent } from '../types';
|
|
2
|
-
import { Adapter } from '../adapter';
|
|
3
|
-
type ExtractorState = object;
|
|
4
|
-
export declare class DemoExtractor {
|
|
5
|
-
private event;
|
|
6
|
-
private adapter;
|
|
7
|
-
private uploader;
|
|
8
|
-
constructor(event: AirdropEvent, adapter: Adapter<ExtractorState>);
|
|
9
|
-
run(): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export {};
|
|
@@ -1,157 +0,0 @@
|
|
|
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.DemoExtractor = void 0;
|
|
7
|
-
const types_1 = require("../types");
|
|
8
|
-
const uploader_1 = require("../uploader");
|
|
9
|
-
const initial_domain_mapping_json_1 = __importDefault(require("./initial_domain_mapping.json"));
|
|
10
|
-
class DemoExtractor {
|
|
11
|
-
constructor(event, adapter) {
|
|
12
|
-
this.event = event;
|
|
13
|
-
this.adapter = adapter;
|
|
14
|
-
this.uploader = new uploader_1.Uploader(this.event.execution_metadata.devrev_endpoint, this.event.context.secrets.service_account_token);
|
|
15
|
-
}
|
|
16
|
-
async run() {
|
|
17
|
-
switch (this.event.payload.event_type) {
|
|
18
|
-
case types_1.EventType.ExtractionExternalSyncUnitsStart: {
|
|
19
|
-
const externalSyncUnits = [
|
|
20
|
-
{
|
|
21
|
-
id: 'devrev',
|
|
22
|
-
name: 'devrev',
|
|
23
|
-
description: 'Demo external sync unit',
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionExternalSyncUnitsDone, {
|
|
27
|
-
external_sync_units: externalSyncUnits,
|
|
28
|
-
});
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
case types_1.EventType.ExtractionMetadataStart: {
|
|
32
|
-
const metadata = [
|
|
33
|
-
{
|
|
34
|
-
item: 'contacts',
|
|
35
|
-
fields: ['id', 'name', 'lastName'],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
item: 'users',
|
|
39
|
-
fields: ['id', 'name', 'lastName'],
|
|
40
|
-
},
|
|
41
|
-
];
|
|
42
|
-
const { artifact, error } = await this.uploader.upload('loopback_metadata_1.jsonl', 'metadata', metadata);
|
|
43
|
-
if (error || !artifact) {
|
|
44
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataError, {
|
|
45
|
-
error,
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const { artifact: recipe, error: recipeError } = await this.uploader.upload('recipe.json', 'initial_domain_mapping', initial_domain_mapping_json_1.default);
|
|
50
|
-
if (recipeError || !recipe) {
|
|
51
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataError, {
|
|
52
|
-
error: recipeError,
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataDone, {
|
|
57
|
-
progress: 50,
|
|
58
|
-
artifacts: [artifact, recipe],
|
|
59
|
-
});
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
case types_1.EventType.ExtractionDataStart: {
|
|
63
|
-
const contacts = [
|
|
64
|
-
{
|
|
65
|
-
id: 1,
|
|
66
|
-
name: 'John',
|
|
67
|
-
lastName: 'Doe',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: 2,
|
|
71
|
-
name: 'Jane',
|
|
72
|
-
lastName: 'Doe',
|
|
73
|
-
},
|
|
74
|
-
];
|
|
75
|
-
const { artifact, error } = await this.uploader.upload('loopback_contacts_1.json', 'contacts', contacts);
|
|
76
|
-
if (error || !artifact) {
|
|
77
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
|
|
78
|
-
error,
|
|
79
|
-
});
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataProgress, {
|
|
83
|
-
progress: 50,
|
|
84
|
-
artifacts: [artifact],
|
|
85
|
-
});
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
case types_1.EventType.ExtractionDataContinue: {
|
|
89
|
-
const users = [
|
|
90
|
-
{
|
|
91
|
-
id: 1,
|
|
92
|
-
name: 'John',
|
|
93
|
-
lastName: 'Phd',
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
id: 2,
|
|
97
|
-
name: 'Jane',
|
|
98
|
-
lastName: 'Phd',
|
|
99
|
-
},
|
|
100
|
-
];
|
|
101
|
-
const { artifact, error } = await this.uploader.upload('loopback_users_1.json', 'users', users);
|
|
102
|
-
if (error || !artifact) {
|
|
103
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
|
|
104
|
-
error,
|
|
105
|
-
});
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataDone, {
|
|
109
|
-
progress: 100,
|
|
110
|
-
artifacts: [artifact],
|
|
111
|
-
});
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case types_1.EventType.ExtractionDataDelete: {
|
|
115
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataDeleteDone);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case types_1.EventType.ExtractionAttachmentsStart: {
|
|
119
|
-
const attachment1 = ['This is attachment1.txt content'];
|
|
120
|
-
const { artifact, error } = await this.uploader.upload('attachment1.txt', 'attachment', attachment1);
|
|
121
|
-
if (error || !artifact) {
|
|
122
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
123
|
-
error,
|
|
124
|
-
});
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsProgress, {
|
|
128
|
-
artifacts: [artifact],
|
|
129
|
-
});
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
case types_1.EventType.ExtractionAttachmentsContinue: {
|
|
133
|
-
const attachment2 = ['This is attachment2.txt content'];
|
|
134
|
-
const { artifact, error } = await this.uploader.upload('attachment2.txt', 'attachment', attachment2);
|
|
135
|
-
if (error || !artifact) {
|
|
136
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
137
|
-
error,
|
|
138
|
-
});
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsDone, {
|
|
142
|
-
artifacts: [artifact],
|
|
143
|
-
});
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
case types_1.EventType.ExtractionAttachmentsDelete: {
|
|
147
|
-
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsDeleteDone);
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
default: {
|
|
151
|
-
console.error('Event in DemoExtractor run not recognized: ' +
|
|
152
|
-
JSON.stringify(this.event.payload.event_type));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.DemoExtractor = DemoExtractor;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"initial_object_mappings": [
|
|
3
|
-
{
|
|
4
|
-
"external_type": "contacts",
|
|
5
|
-
"possible_targets": {
|
|
6
|
-
"rev_user": {
|
|
7
|
-
"initial_field_mappings": [
|
|
8
|
-
{
|
|
9
|
-
"destination_field": {
|
|
10
|
-
"id": "id",
|
|
11
|
-
"is_required": true
|
|
12
|
-
},
|
|
13
|
-
"selected_resolutions": ["id"],
|
|
14
|
-
"resolutions": {
|
|
15
|
-
"id": {
|
|
16
|
-
"source_field_description": {
|
|
17
|
-
"id": "id",
|
|
18
|
-
"is_required": true
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"is_finished": true
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"destination_field": {
|
|
26
|
-
"id": "display_name",
|
|
27
|
-
"is_required": true
|
|
28
|
-
},
|
|
29
|
-
"selected_resolutions": ["name"],
|
|
30
|
-
"resolutions": {
|
|
31
|
-
"name": {
|
|
32
|
-
"source_field_description": {
|
|
33
|
-
"id": "name",
|
|
34
|
-
"is_required": true
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"is_finished": true
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"default_target": "rev_user",
|
|
44
|
-
"allow_item_type_decisions": true
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"external_type": "users",
|
|
48
|
-
"possible_targets": {
|
|
49
|
-
"dev_user": {
|
|
50
|
-
"initial_field_mappings": [
|
|
51
|
-
{
|
|
52
|
-
"destination_field": {
|
|
53
|
-
"id": "id",
|
|
54
|
-
"is_required": true
|
|
55
|
-
},
|
|
56
|
-
"selected_resolutions": ["id"],
|
|
57
|
-
"resolutions": {
|
|
58
|
-
"id": {
|
|
59
|
-
"source_field_description": {
|
|
60
|
-
"id": "id",
|
|
61
|
-
"is_required": true
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
"is_finished": true
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
"destination_field": {
|
|
69
|
-
"id": "display_name",
|
|
70
|
-
"is_required": true
|
|
71
|
-
},
|
|
72
|
-
"selected_resolutions": ["name"],
|
|
73
|
-
"resolutions": {
|
|
74
|
-
"name": {
|
|
75
|
-
"source_field_description": {
|
|
76
|
-
"id": "name",
|
|
77
|
-
"is_required": true
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
"is_finished": true
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
"default_target": "dev_user",
|
|
87
|
-
"allow_item_type_decisions": true
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
"external_type": "tickets",
|
|
91
|
-
"possible_targets": {
|
|
92
|
-
"work.ticket": {}
|
|
93
|
-
},
|
|
94
|
-
"default_target": "work.ticket",
|
|
95
|
-
"allow_item_type_decisions": true
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"external_type": "conversations",
|
|
99
|
-
"possible_targets": {
|
|
100
|
-
"comment": {}
|
|
101
|
-
},
|
|
102
|
-
"default_target": "comment",
|
|
103
|
-
"allow_item_type_decisions": true
|
|
104
|
-
}
|
|
105
|
-
],
|
|
106
|
-
"external_system_short_name": "Freshdesk"
|
|
107
|
-
}
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./adapter"), exports);
|
|
18
|
-
__exportStar(require("./demo-extractor"), exports);
|
|
19
|
-
__exportStar(require("./uploader"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
21
|
-
__exportStar(require("./http"), exports);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AirdropEvent } from '../types';
|
|
2
|
-
export declare enum LogLevel {
|
|
3
|
-
INFO = "info",
|
|
4
|
-
WARN = "warn",
|
|
5
|
-
ERROR = "error"
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Logger class to log messages based on the log level.
|
|
9
|
-
* The log level can be set to one of the following:
|
|
10
|
-
* - INFO
|
|
11
|
-
* - WARN
|
|
12
|
-
* - ERROR
|
|
13
|
-
*
|
|
14
|
-
* The log tags can be set to any key-value pair.
|
|
15
|
-
*/
|
|
16
|
-
export declare class Logger {
|
|
17
|
-
static init(event: AirdropEvent): void;
|
|
18
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = 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 = {}));
|
|
10
|
-
/**
|
|
11
|
-
* Logger class to log messages based on the log level.
|
|
12
|
-
* The log level can be set to one of the following:
|
|
13
|
-
* - INFO
|
|
14
|
-
* - WARN
|
|
15
|
-
* - ERROR
|
|
16
|
-
*
|
|
17
|
-
* The log tags can be set to any key-value pair.
|
|
18
|
-
*/
|
|
19
|
-
class Logger {
|
|
20
|
-
static init(event) {
|
|
21
|
-
const origLog = console.log;
|
|
22
|
-
console.log = (message) => {
|
|
23
|
-
origLog(`[${LogLevel.INFO.toUpperCase()}]: ${message}`, Object.assign({}, event.payload.event_context));
|
|
24
|
-
};
|
|
25
|
-
const origInfo = console.info;
|
|
26
|
-
console.info = (message) => {
|
|
27
|
-
origInfo(`[${LogLevel.INFO.toUpperCase()}]: ${message}`, Object.assign({}, event.payload.event_context));
|
|
28
|
-
};
|
|
29
|
-
const origWarn = console.warn;
|
|
30
|
-
console.warn = (message) => {
|
|
31
|
-
origWarn(`[${LogLevel.WARN.toUpperCase()}]: ${message}`, Object.assign({}, event.payload.event_context));
|
|
32
|
-
};
|
|
33
|
-
const origError = console.error;
|
|
34
|
-
console.error = (message) => {
|
|
35
|
-
origError(`[${LogLevel.ERROR.toUpperCase()}]: ${message}`, Object.assign({}, event.payload.event_context));
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.Logger = Logger;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { AdapterState, AirdropEvent } from '../types';
|
|
2
|
-
export declare function createAdapterState<ExtractorState>(event: AirdropEvent, initialState: ExtractorState): Promise<State<ExtractorState>>;
|
|
3
|
-
export declare class State<ExtractorState> {
|
|
4
|
-
private _state;
|
|
5
|
-
private event;
|
|
6
|
-
private workerUrl;
|
|
7
|
-
private devrevToken;
|
|
8
|
-
constructor(event: AirdropEvent, initialState: ExtractorState);
|
|
9
|
-
get state(): AdapterState<ExtractorState>;
|
|
10
|
-
set state(value: AdapterState<ExtractorState>);
|
|
11
|
-
/**
|
|
12
|
-
* Updates the state of the adapter.
|
|
13
|
-
*
|
|
14
|
-
* @param {object} state - The state to be updated
|
|
15
|
-
*/
|
|
16
|
-
postState(state: AdapterState<ExtractorState>): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* Fetches the state of the adapter.
|
|
19
|
-
*
|
|
20
|
-
* @return The state of the adapter
|
|
21
|
-
*/
|
|
22
|
-
fetchState(initialState: ExtractorState): Promise<AdapterState<ExtractorState> | unknown>;
|
|
23
|
-
}
|
package/dist/src/state/index.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.State = exports.createAdapterState = void 0;
|
|
27
|
-
const axios_1 = __importStar(require("axios"));
|
|
28
|
-
const constants_1 = require("../common/constants");
|
|
29
|
-
async function createAdapterState(event, initialState) {
|
|
30
|
-
const newInitialState = structuredClone(initialState);
|
|
31
|
-
const as = new State(event, newInitialState);
|
|
32
|
-
if (!constants_1.STATELESS_EVENT_TYPES.includes(event.payload.event_type)) {
|
|
33
|
-
console.log('Fetching state');
|
|
34
|
-
await as.fetchState(newInitialState);
|
|
35
|
-
}
|
|
36
|
-
return as;
|
|
37
|
-
}
|
|
38
|
-
exports.createAdapterState = createAdapterState;
|
|
39
|
-
class State {
|
|
40
|
-
constructor(event, initialState) {
|
|
41
|
-
this._state = Object.assign({ lastSyncStarted: '', lastSuccessfulSyncStarted: '' }, initialState);
|
|
42
|
-
this.event = event;
|
|
43
|
-
this.workerUrl = event.payload.event_context.worker_data_url;
|
|
44
|
-
this.devrevToken = event.context.secrets.service_account_token;
|
|
45
|
-
}
|
|
46
|
-
get state() {
|
|
47
|
-
return this._state;
|
|
48
|
-
}
|
|
49
|
-
set state(value) {
|
|
50
|
-
this._state = value;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Updates the state of the adapter.
|
|
54
|
-
*
|
|
55
|
-
* @param {object} state - The state to be updated
|
|
56
|
-
*/
|
|
57
|
-
async postState(state) {
|
|
58
|
-
try {
|
|
59
|
-
await axios_1.default.post(this.workerUrl + '.update', {
|
|
60
|
-
state: JSON.stringify(state),
|
|
61
|
-
}, {
|
|
62
|
-
headers: {
|
|
63
|
-
Authorization: this.devrevToken,
|
|
64
|
-
},
|
|
65
|
-
params: {
|
|
66
|
-
sync_unit: this.event.payload.event_context.sync_unit_id,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
this.state = state;
|
|
70
|
-
console.log('State updated successfully');
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.error('Failed to update state, error:' + error);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Fetches the state of the adapter.
|
|
78
|
-
*
|
|
79
|
-
* @return The state of the adapter
|
|
80
|
-
*/
|
|
81
|
-
async fetchState(initialState) {
|
|
82
|
-
var _a;
|
|
83
|
-
const state = Object.assign(Object.assign({}, initialState), { lastSyncStarted: '', lastSuccessfulSyncStarted: '' });
|
|
84
|
-
console.log('Fetching state with sync unit id: ' +
|
|
85
|
-
this.event.payload.event_context.sync_unit_id);
|
|
86
|
-
try {
|
|
87
|
-
const response = await axios_1.default.post(this.workerUrl + '.get', {}, {
|
|
88
|
-
headers: {
|
|
89
|
-
Authorization: this.devrevToken,
|
|
90
|
-
},
|
|
91
|
-
params: {
|
|
92
|
-
sync_unit: this.event.payload.event_context.sync_unit_id,
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
this.state = JSON.parse(response.data.state);
|
|
96
|
-
console.log('State fetched successfully');
|
|
97
|
-
return this.state;
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
if ((0, axios_1.isAxiosError)(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
101
|
-
console.log('State not found, returning initial state');
|
|
102
|
-
this.state = state;
|
|
103
|
-
this.postState(this.state);
|
|
104
|
-
return this.state;
|
|
105
|
-
}
|
|
106
|
-
console.error('Failed to fetch state, error:' + error);
|
|
107
|
-
return error;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.State = State;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export declare enum ErrorLevel {
|
|
2
|
-
Warning = "WARNING",
|
|
3
|
-
Error = "ERROR",
|
|
4
|
-
Info = "INFO"
|
|
5
|
-
}
|
|
6
|
-
export interface ErrorRecord {
|
|
7
|
-
message: string;
|
|
8
|
-
}
|
|
9
|
-
export interface LogRecord {
|
|
10
|
-
level: ErrorLevel;
|
|
11
|
-
message: string;
|
|
12
|
-
}
|
|
13
|
-
export interface Artifact {
|
|
14
|
-
id: string;
|
|
15
|
-
item_type: string;
|
|
16
|
-
item_count: number;
|
|
17
|
-
}
|
|
18
|
-
export interface ArtifactsPrepareResponse {
|
|
19
|
-
url: string;
|
|
20
|
-
id: string;
|
|
21
|
-
form_data: {
|
|
22
|
-
key: string;
|
|
23
|
-
value: string;
|
|
24
|
-
}[];
|
|
25
|
-
}
|
|
26
|
-
export interface AdapterUpdateParams {
|
|
27
|
-
artifact?: Artifact;
|
|
28
|
-
extractor_state?: object;
|
|
29
|
-
}
|
|
30
|
-
export interface UploadResponse {
|
|
31
|
-
artifact?: Artifact;
|
|
32
|
-
error?: ErrorRecord;
|
|
33
|
-
}
|
package/dist/src/types/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./common"), exports);
|
|
18
|
-
__exportStar(require("./extraction"), exports);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helpers_1 = require("../src/common/helpers");
|
|
4
|
-
const types_1 = require("../src/types");
|
|
5
|
-
describe('adapter.helpers.ts', () => {
|
|
6
|
-
it("should create a FormData object with the correct 'key' and 'value'", () => {
|
|
7
|
-
const preparedArtifact = {
|
|
8
|
-
form_data: [{ key: 'key', value: 'value' }],
|
|
9
|
-
};
|
|
10
|
-
const fetchedObjects = [{ key: 'value' }];
|
|
11
|
-
const formData = (0, helpers_1.createFormData)(preparedArtifact, fetchedObjects);
|
|
12
|
-
expect(formData).toBeInstanceOf(FormData);
|
|
13
|
-
expect(formData.get('key')).toBe('value');
|
|
14
|
-
});
|
|
15
|
-
it("should create a FormData object with the correct 'file' key", () => {
|
|
16
|
-
const preparedArtifact = {
|
|
17
|
-
form_data: [{ key: 'key', value: 'value' }],
|
|
18
|
-
};
|
|
19
|
-
const fetchedObjects = [{ key: 'value' }];
|
|
20
|
-
const formData = (0, helpers_1.createFormData)(preparedArtifact, fetchedObjects);
|
|
21
|
-
expect(formData.get('file')).toBeDefined();
|
|
22
|
-
});
|
|
23
|
-
it("should create an Artifact object with the correct 'item_count', 'id', and 'item_type'", () => {
|
|
24
|
-
const preparedArtifact = { id: 'id' };
|
|
25
|
-
const fetchedObjects = [{ key: 'value' }];
|
|
26
|
-
const entity = 'entity';
|
|
27
|
-
const artifact = (0, helpers_1.createArtifact)(preparedArtifact, fetchedObjects, entity);
|
|
28
|
-
expect(artifact).toEqual({
|
|
29
|
-
item_count: 1,
|
|
30
|
-
id: 'id',
|
|
31
|
-
item_type: 'entity',
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
it('should return the correct ExtractorEventType', () => {
|
|
35
|
-
expect((0, helpers_1.getTimeoutExtractorEventType)(types_1.EventType.ExtractionMetadataStart)).toStrictEqual({
|
|
36
|
-
eventType: types_1.ExtractorEventType.ExtractionMetadataError,
|
|
37
|
-
isError: true,
|
|
38
|
-
});
|
|
39
|
-
expect((0, helpers_1.getTimeoutExtractorEventType)(types_1.EventType.ExtractionDataStart)).toStrictEqual({
|
|
40
|
-
eventType: types_1.ExtractorEventType.ExtractionDataProgress,
|
|
41
|
-
isError: false,
|
|
42
|
-
});
|
|
43
|
-
expect((0, helpers_1.getTimeoutExtractorEventType)(types_1.EventType.ExtractionDataContinue)).toStrictEqual({
|
|
44
|
-
eventType: types_1.ExtractorEventType.ExtractionDataProgress,
|
|
45
|
-
isError: false,
|
|
46
|
-
});
|
|
47
|
-
expect((0, helpers_1.getTimeoutExtractorEventType)(types_1.EventType.ExtractionAttachmentsStart)).toStrictEqual({
|
|
48
|
-
eventType: types_1.ExtractorEventType.ExtractionAttachmentsProgress,
|
|
49
|
-
isError: false,
|
|
50
|
-
});
|
|
51
|
-
expect((0, helpers_1.getTimeoutExtractorEventType)(types_1.EventType.ExtractionAttachmentsContinue)).toStrictEqual({
|
|
52
|
-
eventType: types_1.ExtractorEventType.ExtractionAttachmentsProgress,
|
|
53
|
-
isError: false,
|
|
54
|
-
});
|
|
55
|
-
expect((0, helpers_1.getTimeoutExtractorEventType)(types_1.EventType.ExtractionExternalSyncUnitsStart)).toStrictEqual({
|
|
56
|
-
eventType: types_1.ExtractorEventType.ExtractionExternalSyncUnitsError,
|
|
57
|
-
isError: true,
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|