@devrev/ts-adaas 0.0.1 → 0.0.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/README.md +20 -4
- package/dist/src/adapter/index.d.ts +35 -30
- package/dist/src/adapter/index.js +93 -56
- package/dist/src/common/constants.d.ts +2 -0
- package/dist/src/common/constants.js +10 -0
- package/dist/src/{adapter → common}/helpers.d.ts +4 -1
- package/dist/src/{adapter → common}/helpers.js +16 -4
- package/dist/src/common/install-initial-domain-mapping.d.ts +3 -0
- package/dist/src/common/install-initial-domain-mapping.js +60 -0
- package/dist/src/demo-extractor/external_domain_metadata.json +38 -0
- package/dist/src/demo-extractor/index.d.ts +8 -1
- package/dist/src/demo-extractor/index.js +79 -73
- package/dist/src/http/client.d.ts +1 -1
- package/dist/src/http/client.js +2 -2
- package/dist/src/http/index.d.ts +0 -1
- package/dist/src/http/index.js +0 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/logging/index.d.ts +5 -18
- package/dist/src/logging/index.js +20 -41
- package/dist/src/state/index.d.ts +23 -0
- package/dist/src/state/index.js +111 -0
- package/dist/src/types/common.d.ts +4 -0
- package/dist/src/types/extraction.d.ts +17 -5
- package/dist/src/uploader/index.d.ts +4 -2
- package/dist/src/uploader/index.js +61 -4
- package/dist/tests/adapter.helpers.test.js +60 -0
- package/dist/tests/adapter.test.js +107 -57
- package/dist/tests/demo-extractor.test.js +45 -81
- package/dist/tests/state.test.js +101 -0
- package/dist/tests/uploader.test.js +29 -0
- package/package.json +1 -1
- package/dist/src/adapter/index.test.js +0 -105
- package/dist/src/demo-extractor/recipe.json +0 -37
- package/dist/tests/helpers.test.js +0 -38
- package/dist/tests/test-helpers.d.ts +0 -2
- package/dist/tests/test-helpers.js +0 -33
- package/dist/tests/types.test.js +0 -71
- /package/dist/{src/adapter/index.test.d.ts → tests/adapter.helpers.test.d.ts} +0 -0
- /package/dist/tests/{helpers.test.d.ts → state.test.d.ts} +0 -0
- /package/dist/tests/{types.test.d.ts → uploader.test.d.ts} +0 -0
|
@@ -5,143 +5,149 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DemoExtractor = void 0;
|
|
7
7
|
const types_1 = require("../types");
|
|
8
|
-
const adapter_1 = require("../adapter");
|
|
9
8
|
const uploader_1 = require("../uploader");
|
|
10
|
-
const
|
|
9
|
+
const external_domain_metadata_json_1 = __importDefault(require("./external_domain_metadata.json"));
|
|
11
10
|
class DemoExtractor {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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) {
|
|
17
18
|
case types_1.EventType.ExtractionExternalSyncUnitsStart: {
|
|
18
19
|
const externalSyncUnits = [
|
|
19
20
|
{
|
|
20
21
|
id: 'devrev',
|
|
21
22
|
name: 'devrev',
|
|
22
|
-
description: '
|
|
23
|
-
item_count: 0,
|
|
23
|
+
description: 'Demo external sync unit',
|
|
24
24
|
},
|
|
25
25
|
];
|
|
26
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionExternalSyncUnitsDone, {
|
|
26
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionExternalSyncUnitsDone, {
|
|
27
27
|
external_sync_units: externalSyncUnits,
|
|
28
28
|
});
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
31
31
|
case types_1.EventType.ExtractionMetadataStart: {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fields: ['name', 'lastName'],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
item: 'users',
|
|
39
|
-
fields: ['name', 'lastName'],
|
|
40
|
-
},
|
|
41
|
-
];
|
|
42
|
-
const { artifact, error } = await uploader.upload('loopback_metadata_1.jsonl', 'metadata', metadata);
|
|
43
|
-
if (error) {
|
|
44
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionMetadataError, {
|
|
32
|
+
const { artifact, error } = await this.uploader.upload('metadata_1.jsonl', 'external_domain_metadata', external_domain_metadata_json_1.default);
|
|
33
|
+
if (error || !artifact) {
|
|
34
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataError, {
|
|
45
35
|
error,
|
|
46
36
|
});
|
|
37
|
+
return;
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
39
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataDone, {
|
|
40
|
+
artifacts: [artifact],
|
|
41
|
+
});
|
|
52
42
|
break;
|
|
53
43
|
}
|
|
54
44
|
case types_1.EventType.ExtractionDataStart: {
|
|
55
45
|
const contacts = [
|
|
56
46
|
{
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
id: 'contact-1',
|
|
48
|
+
created_date: '1999-12-25T01:00:03+01:00',
|
|
49
|
+
modified_date: '1999-12-25T01:00:03+01:00',
|
|
50
|
+
data: {
|
|
51
|
+
email: 'johnsmith@test.com',
|
|
52
|
+
name: 'John Smith',
|
|
53
|
+
},
|
|
59
54
|
},
|
|
60
55
|
{
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
id: 'contact-2',
|
|
57
|
+
created_date: '1999-12-27T15:31:34+01:00',
|
|
58
|
+
modified_date: '2002-04-09T01:55:31+02:00',
|
|
59
|
+
data: {
|
|
60
|
+
email: 'janesmith@test.com',
|
|
61
|
+
name: 'Jane Smith',
|
|
62
|
+
},
|
|
63
63
|
},
|
|
64
64
|
];
|
|
65
|
-
const { artifact, error } = await uploader.upload('
|
|
66
|
-
if (error) {
|
|
67
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
|
|
65
|
+
const { artifact, error } = await this.uploader.upload('contacts_1.json', 'contacts', contacts);
|
|
66
|
+
if (error || !artifact) {
|
|
67
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
|
|
68
68
|
error,
|
|
69
69
|
});
|
|
70
|
+
return;
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
}
|
|
72
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataProgress, {
|
|
73
|
+
progress: 50,
|
|
74
|
+
artifacts: [artifact],
|
|
75
|
+
});
|
|
77
76
|
break;
|
|
78
77
|
}
|
|
79
78
|
case types_1.EventType.ExtractionDataContinue: {
|
|
80
79
|
const users = [
|
|
81
80
|
{
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
id: 'user-1',
|
|
82
|
+
created_date: '1999-12-25T01:00:03+01:00',
|
|
83
|
+
modified_date: '1999-12-25T01:00:03+01:00',
|
|
84
|
+
data: {
|
|
85
|
+
email: 'johndoe@test.com',
|
|
86
|
+
name: 'John Doe',
|
|
87
|
+
},
|
|
84
88
|
},
|
|
85
89
|
{
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
id: 'user-2',
|
|
91
|
+
created_date: '1999-12-27T15:31:34+01:00',
|
|
92
|
+
modified_date: '2002-04-09T01:55:31+02:00',
|
|
93
|
+
data: {
|
|
94
|
+
email: 'janedoe@test.com',
|
|
95
|
+
name: 'Jane Doe',
|
|
96
|
+
},
|
|
88
97
|
},
|
|
89
98
|
];
|
|
90
|
-
const { artifact, error } = await uploader.upload('
|
|
91
|
-
if (error) {
|
|
92
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
|
|
99
|
+
const { artifact, error } = await this.uploader.upload('users_1.json', 'users', users);
|
|
100
|
+
if (error || !artifact) {
|
|
101
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
|
|
93
102
|
error,
|
|
94
103
|
});
|
|
104
|
+
return;
|
|
95
105
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
await adapter.update({ artifact: recipe });
|
|
101
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionDataDone, {
|
|
102
|
-
progress: 100,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
106
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataDone, {
|
|
107
|
+
progress: 100,
|
|
108
|
+
artifacts: [artifact],
|
|
109
|
+
});
|
|
105
110
|
break;
|
|
106
111
|
}
|
|
107
112
|
case types_1.EventType.ExtractionDataDelete: {
|
|
108
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionDataDeleteDone);
|
|
113
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataDeleteDone);
|
|
109
114
|
break;
|
|
110
115
|
}
|
|
111
116
|
case types_1.EventType.ExtractionAttachmentsStart: {
|
|
112
117
|
const attachment1 = ['This is attachment1.txt content'];
|
|
113
|
-
const { artifact, error } = await uploader.upload('attachment1.txt', 'attachment', attachment1);
|
|
114
|
-
if (error) {
|
|
115
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
118
|
+
const { artifact, error } = await this.uploader.upload('attachment1.txt', 'attachment', attachment1);
|
|
119
|
+
if (error || !artifact) {
|
|
120
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
116
121
|
error,
|
|
117
122
|
});
|
|
123
|
+
return;
|
|
118
124
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
125
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsProgress, {
|
|
126
|
+
artifacts: [artifact],
|
|
127
|
+
});
|
|
123
128
|
break;
|
|
124
129
|
}
|
|
125
130
|
case types_1.EventType.ExtractionAttachmentsContinue: {
|
|
126
131
|
const attachment2 = ['This is attachment2.txt content'];
|
|
127
|
-
const { artifact, error } = await uploader.upload('attachment2.txt', 'attachment', attachment2);
|
|
128
|
-
if (error) {
|
|
129
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
132
|
+
const { artifact, error } = await this.uploader.upload('attachment2.txt', 'attachment', attachment2);
|
|
133
|
+
if (error || !artifact) {
|
|
134
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsError, {
|
|
130
135
|
error,
|
|
131
136
|
});
|
|
137
|
+
return;
|
|
132
138
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
139
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsDone, {
|
|
140
|
+
artifacts: [artifact],
|
|
141
|
+
});
|
|
137
142
|
break;
|
|
138
143
|
}
|
|
139
144
|
case types_1.EventType.ExtractionAttachmentsDelete: {
|
|
140
|
-
await adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsDeleteDone);
|
|
145
|
+
await this.adapter.emit(types_1.ExtractorEventType.ExtractionAttachmentsDeleteDone);
|
|
141
146
|
break;
|
|
142
147
|
}
|
|
143
148
|
default: {
|
|
144
|
-
console.
|
|
149
|
+
console.error('Event in DemoExtractor run not recognized: ' +
|
|
150
|
+
JSON.stringify(this.event.payload.event_type));
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
}
|
package/dist/src/http/client.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.defaultResponse = void 0;
|
|
26
|
+
exports.HTTPClient = exports.defaultResponse = void 0;
|
|
27
27
|
const axios_1 = __importStar(require("axios"));
|
|
28
28
|
const constants_1 = require("./constants");
|
|
29
29
|
exports.defaultResponse = {
|
|
@@ -144,4 +144,4 @@ class HTTPClient {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
exports.
|
|
147
|
+
exports.HTTPClient = HTTPClient;
|
package/dist/src/http/index.d.ts
CHANGED
package/dist/src/http/index.js
CHANGED
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./client"), exports);
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
|
-
__exportStar(require("./constants"), exports);
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -18,3 +18,5 @@ __exportStar(require("./adapter"), exports);
|
|
|
18
18
|
__exportStar(require("./demo-extractor"), exports);
|
|
19
19
|
__exportStar(require("./uploader"), exports);
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./http"), exports);
|
|
22
|
+
__exportStar(require("./common/install-initial-domain-mapping"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { AirdropEvent } from '../types';
|
|
2
|
+
export declare enum LogLevel {
|
|
2
3
|
INFO = "info",
|
|
3
4
|
WARN = "warn",
|
|
4
|
-
ERROR = "error"
|
|
5
|
-
DEBUG = "debug"
|
|
5
|
+
ERROR = "error"
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Logger class to log messages based on the log level.
|
|
@@ -10,22 +10,9 @@ declare enum LogLevel {
|
|
|
10
10
|
* - INFO
|
|
11
11
|
* - WARN
|
|
12
12
|
* - ERROR
|
|
13
|
-
* - DEBUG
|
|
14
13
|
*
|
|
15
14
|
* The log tags can be set to any key-value pair.
|
|
16
15
|
*/
|
|
17
|
-
declare class Logger {
|
|
18
|
-
|
|
19
|
-
private logTags;
|
|
20
|
-
private static instance;
|
|
21
|
-
private constructor();
|
|
22
|
-
private log;
|
|
23
|
-
static getInstance(level: LogLevel, logTags?: Record<string, any>): Logger;
|
|
24
|
-
setTags(tags: Record<string, any>): void;
|
|
25
|
-
addTags(tags: Record<string, any>): void;
|
|
26
|
-
info(message: string): void;
|
|
27
|
-
warn(message: string): void;
|
|
28
|
-
error(message: string): void;
|
|
29
|
-
debug(message: string): void;
|
|
16
|
+
export declare class Logger {
|
|
17
|
+
static init(event: AirdropEvent): void;
|
|
30
18
|
}
|
|
31
|
-
export default Logger;
|
|
@@ -1,60 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = exports.LogLevel = void 0;
|
|
3
4
|
var LogLevel;
|
|
4
5
|
(function (LogLevel) {
|
|
5
6
|
LogLevel["INFO"] = "info";
|
|
6
7
|
LogLevel["WARN"] = "warn";
|
|
7
8
|
LogLevel["ERROR"] = "error";
|
|
8
|
-
|
|
9
|
-
})(LogLevel || (LogLevel = {}));
|
|
9
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
10
10
|
/**
|
|
11
11
|
* Logger class to log messages based on the log level.
|
|
12
12
|
* The log level can be set to one of the following:
|
|
13
13
|
* - INFO
|
|
14
14
|
* - WARN
|
|
15
15
|
* - ERROR
|
|
16
|
-
* - DEBUG
|
|
17
16
|
*
|
|
18
17
|
* The log tags can be set to any key-value pair.
|
|
19
18
|
*/
|
|
20
19
|
class Logger {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
// Set log tags destructively.
|
|
40
|
-
setTags(tags) {
|
|
41
|
-
this.logTags = tags;
|
|
42
|
-
}
|
|
43
|
-
// Add log tags. If the key already exists, it will be overwritten.
|
|
44
|
-
addTags(tags) {
|
|
45
|
-
this.logTags = Object.assign(Object.assign({}, this.logTags), tags);
|
|
46
|
-
}
|
|
47
|
-
info(message) {
|
|
48
|
-
this.log(LogLevel.INFO, message);
|
|
49
|
-
}
|
|
50
|
-
warn(message) {
|
|
51
|
-
this.log(LogLevel.WARN, message);
|
|
52
|
-
}
|
|
53
|
-
error(message) {
|
|
54
|
-
this.log(LogLevel.ERROR, message);
|
|
55
|
-
}
|
|
56
|
-
debug(message) {
|
|
57
|
-
this.log(LogLevel.DEBUG, message);
|
|
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
|
+
};
|
|
58
37
|
}
|
|
59
38
|
}
|
|
60
|
-
exports.
|
|
39
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { InputData
|
|
1
|
+
import { InputData } from '@devrev/typescript-sdk/dist/snap-ins';
|
|
2
2
|
import { Artifact, ErrorRecord } from './common';
|
|
3
3
|
export declare enum EventType {
|
|
4
4
|
ExtractionExternalSyncUnitsStart = "EXTRACTION_EXTERNAL_SYNC_UNITS_START",
|
|
@@ -43,7 +43,7 @@ export interface ExternalSyncUnit {
|
|
|
43
43
|
id: string;
|
|
44
44
|
name: string;
|
|
45
45
|
description: string;
|
|
46
|
-
item_count
|
|
46
|
+
item_count?: number;
|
|
47
47
|
}
|
|
48
48
|
export interface EventContextIn {
|
|
49
49
|
mode: string;
|
|
@@ -55,6 +55,7 @@ export interface EventContextIn {
|
|
|
55
55
|
sync_run_id: string;
|
|
56
56
|
external_system_id: string;
|
|
57
57
|
uuid: string;
|
|
58
|
+
worker_data_url: string;
|
|
58
59
|
}
|
|
59
60
|
export interface EventContextOut {
|
|
60
61
|
uuid: string;
|
|
@@ -85,9 +86,16 @@ export interface DomainObjectState {
|
|
|
85
86
|
count: number;
|
|
86
87
|
}
|
|
87
88
|
export interface AirdropEvent {
|
|
88
|
-
context:
|
|
89
|
+
context: {
|
|
90
|
+
secrets: {
|
|
91
|
+
service_account_token: string;
|
|
92
|
+
};
|
|
93
|
+
snap_in_version_id: string;
|
|
94
|
+
};
|
|
89
95
|
payload: AirdropMessage;
|
|
90
|
-
execution_metadata:
|
|
96
|
+
execution_metadata: {
|
|
97
|
+
devrev_endpoint: string;
|
|
98
|
+
};
|
|
91
99
|
input_data: InputData;
|
|
92
100
|
}
|
|
93
101
|
export interface AirdropMessage {
|
|
@@ -100,6 +108,10 @@ export interface AirdropMessage {
|
|
|
100
108
|
export interface ExtractorEvent {
|
|
101
109
|
event_type: string;
|
|
102
110
|
event_context: EventContextOut;
|
|
103
|
-
extractor_state
|
|
111
|
+
extractor_state?: string;
|
|
104
112
|
event_data?: EventData;
|
|
105
113
|
}
|
|
114
|
+
export type AdapterState<ExtractorState> = ExtractorState & {
|
|
115
|
+
lastSyncStarted?: string;
|
|
116
|
+
lastSuccessfulSyncStarted?: string;
|
|
117
|
+
};
|
|
@@ -10,11 +10,12 @@ import { UploadResponse } from '../types/common';
|
|
|
10
10
|
* @constructor
|
|
11
11
|
* @param {string} endpoint - The endpoint of the DevRev platform
|
|
12
12
|
* @param {string} token - The token to authenticate with the DevRev platform
|
|
13
|
+
* @param {boolean} local - Flag to indicate if the uploader should upload to the file-system.
|
|
13
14
|
*/
|
|
14
15
|
export declare class Uploader {
|
|
15
16
|
private betaDevrevSdk;
|
|
16
|
-
private
|
|
17
|
-
constructor(endpoint: string, token: string);
|
|
17
|
+
private local;
|
|
18
|
+
constructor(endpoint: string, token: string, local?: boolean);
|
|
18
19
|
/**
|
|
19
20
|
*
|
|
20
21
|
* Uploads the file to the DevRev platform. The file is uploaded to the platform
|
|
@@ -29,4 +30,5 @@ export declare class Uploader {
|
|
|
29
30
|
upload(filename: string, entity: string, fetchedObjects: object[] | object, filetype?: string): Promise<UploadResponse>;
|
|
30
31
|
private prepareArtifact;
|
|
31
32
|
private uploadToArtifact;
|
|
33
|
+
private downloadToLocal;
|
|
32
34
|
}
|