@devrev/ts-adaas 1.2.1 → 1.2.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 +13 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +3 -1
- package/dist/common/control-protocol.js +7 -0
- package/dist/common/helpers.d.ts +1 -0
- package/dist/common/helpers.js +56 -0
- package/dist/{http → deprecated/http}/client.d.ts +1 -1
- package/dist/{http → deprecated/http}/client.js +1 -1
- package/dist/http/axios-client.js +13 -21
- package/dist/http/index.d.ts +0 -1
- package/dist/http/index.js +0 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/repo/repo.interfaces.d.ts +1 -1
- package/dist/state/state.js +6 -5
- package/dist/tests/test-helpers.js +1 -0
- package/dist/types/extraction.d.ts +1 -0
- package/dist/types/workers.d.ts +0 -4
- package/dist/uploader/uploader.interfaces.d.ts +1 -1
- package/dist/uploader/uploader.js +12 -12
- package/dist/workers/create-worker.js +1 -1
- package/dist/workers/default-workers/load-attachments.js +2 -2
- package/dist/workers/process-task.js +0 -1
- package/dist/workers/spawn.js +12 -3
- package/dist/workers/worker-adapter.d.ts +3 -4
- package/dist/workers/worker-adapter.js +115 -109
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
## Release Notes
|
|
4
4
|
|
|
5
|
+
### v1.2.3
|
|
6
|
+
|
|
7
|
+
- Add `local` flag to use for local development of the ADaaS snap-ins.
|
|
8
|
+
- Send library version, snap-in version and snap-in slug in headers while emitting.
|
|
9
|
+
- Make `actor_id` field optional for `SsorAttachment` interface.
|
|
10
|
+
- Fix bugs related to event handling, error logging.
|
|
11
|
+
|
|
12
|
+
### v1.2.2
|
|
13
|
+
|
|
14
|
+
- Add library version as a part of control protocol.
|
|
15
|
+
- Improve axios client and adapter logging.
|
|
16
|
+
- Fix bugs related to state handling.
|
|
17
|
+
|
|
5
18
|
### v1.2.1
|
|
6
19
|
|
|
7
20
|
- Reduced the `delayFactor` to minimize unnecessary delays.
|
package/dist/common/constants.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AIRDROP_DEFAULT_ITEM_TYPES = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.ALLOWED_EVENT_TYPES = exports.ALLOWED_LOADING_EVENT_TYPES = exports.ALLOWED_EXTRACTION_EVENT_TYPES = exports.STATELESS_EVENT_TYPES = void 0;
|
|
3
|
+
exports.LIBRARY_VERSION = exports.AIRDROP_DEFAULT_ITEM_TYPES = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.ALLOWED_EVENT_TYPES = exports.ALLOWED_LOADING_EVENT_TYPES = exports.ALLOWED_EXTRACTION_EVENT_TYPES = exports.STATELESS_EVENT_TYPES = void 0;
|
|
4
4
|
const extraction_1 = require("../types/extraction");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
5
6
|
exports.STATELESS_EVENT_TYPES = [
|
|
6
7
|
extraction_1.EventType.ExtractionExternalSyncUnitsStart,
|
|
7
8
|
extraction_1.EventType.ExtractionMetadataStart,
|
|
@@ -37,3 +38,4 @@ exports.AIRDROP_DEFAULT_ITEM_TYPES = {
|
|
|
37
38
|
ATTACHMENTS: 'attachments',
|
|
38
39
|
SSOR_ATTACHMENT: 'ssor_attachment',
|
|
39
40
|
};
|
|
41
|
+
exports.LIBRARY_VERSION = (0, helpers_1.getLibraryVersion)();
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.emit = void 0;
|
|
4
4
|
const axios_client_1 = require("../http/axios-client");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
5
6
|
const emit = async ({ event, eventType, data, }) => {
|
|
6
7
|
const newEvent = {
|
|
7
8
|
event_type: eventType,
|
|
8
9
|
event_context: event.payload.event_context,
|
|
9
10
|
event_data: Object.assign({}, data),
|
|
11
|
+
worker_metadata: {
|
|
12
|
+
adaas_library_version: constants_1.LIBRARY_VERSION,
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
15
|
console.info('Emitting event', JSON.stringify(newEvent));
|
|
12
16
|
return axios_client_1.axiosClient.post(event.payload.event_context.callback_url, Object.assign({}, newEvent), {
|
|
@@ -14,6 +18,9 @@ const emit = async ({ event, eventType, data, }) => {
|
|
|
14
18
|
Accept: 'application/json, text/plain, */*',
|
|
15
19
|
Authorization: event.context.secrets.service_account_token,
|
|
16
20
|
'Content-Type': 'application/json',
|
|
21
|
+
'X-DevRev-Client-Platform': event.payload.event_context.snap_in_slug,
|
|
22
|
+
'X-DevRev-Client-Id': event.payload.event_context.snap_in_version_id,
|
|
23
|
+
'X-DevRev-Client-Version': constants_1.LIBRARY_VERSION,
|
|
17
24
|
},
|
|
18
25
|
});
|
|
19
26
|
};
|
package/dist/common/helpers.d.ts
CHANGED
package/dist/common/helpers.js
CHANGED
|
@@ -1,12 +1,48 @@
|
|
|
1
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.getTimeoutErrorEventType = getTimeoutErrorEventType;
|
|
4
37
|
exports.getSyncDirection = getSyncDirection;
|
|
5
38
|
exports.getFilesToLoad = getFilesToLoad;
|
|
6
39
|
exports.addReportToLoaderReport = addReportToLoaderReport;
|
|
7
40
|
exports.getCircularReplacer = getCircularReplacer;
|
|
41
|
+
exports.getLibraryVersion = getLibraryVersion;
|
|
8
42
|
const extraction_1 = require("../types/extraction");
|
|
9
43
|
const loading_1 = require("../types/loading");
|
|
44
|
+
const fs_1 = require("fs");
|
|
45
|
+
const path = __importStar(require("path"));
|
|
10
46
|
function getTimeoutErrorEventType(eventType) {
|
|
11
47
|
switch (eventType) {
|
|
12
48
|
case extraction_1.EventType.ExtractionMetadataStart:
|
|
@@ -44,6 +80,11 @@ function getTimeoutErrorEventType(eventType) {
|
|
|
44
80
|
return {
|
|
45
81
|
eventType: loading_1.LoaderEventType.LoaderStateDeletionError,
|
|
46
82
|
};
|
|
83
|
+
case extraction_1.EventType.StartLoadingAttachments:
|
|
84
|
+
case extraction_1.EventType.ContinueLoadingAttachments:
|
|
85
|
+
return {
|
|
86
|
+
eventType: loading_1.LoaderEventType.AttachmentLoadingError,
|
|
87
|
+
};
|
|
47
88
|
case extraction_1.EventType.StartDeletingLoaderAttachmentState:
|
|
48
89
|
return {
|
|
49
90
|
eventType: loading_1.LoaderEventType.LoaderAttachmentStateDeletionError,
|
|
@@ -120,3 +161,18 @@ function getCircularReplacer() {
|
|
|
120
161
|
return value;
|
|
121
162
|
};
|
|
122
163
|
}
|
|
164
|
+
// read adaas library version from package.json
|
|
165
|
+
function getLibraryVersion() {
|
|
166
|
+
var _a;
|
|
167
|
+
try {
|
|
168
|
+
const version = (_a = JSON.parse((0, fs_1.readFileSync)(path.resolve(__dirname, '../../package.json'), 'utf8'))) === null || _a === void 0 ? void 0 : _a.version;
|
|
169
|
+
if (version) {
|
|
170
|
+
return version;
|
|
171
|
+
}
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
console.error('Error reading adaas library version from package.json', error);
|
|
176
|
+
return '';
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.HTTPClient = exports.defaultResponse = void 0;
|
|
37
37
|
const axios_1 = __importStar(require("axios"));
|
|
38
|
-
const constants_1 = require("
|
|
38
|
+
const constants_1 = require("../../http/constants");
|
|
39
39
|
exports.defaultResponse = {
|
|
40
40
|
data: {
|
|
41
41
|
delay: 0,
|
|
@@ -12,30 +12,22 @@ exports.axiosClient = axiosClient;
|
|
|
12
12
|
(0, axios_retry_1.default)(axiosClient, {
|
|
13
13
|
retries: 5,
|
|
14
14
|
retryDelay: (retryCount, error) => {
|
|
15
|
-
var _a;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
// exponential backoff algorithm: 1 * 2 ^ retryCount * 1000ms
|
|
17
|
+
const delay = axios_retry_1.default.exponentialDelay(retryCount, error, 1000);
|
|
18
|
+
console.warn(`Request to ${(_a = error.config) === null || _a === void 0 ? void 0 : _a.url} failed with response status code ${(_b = error.response) === null || _b === void 0 ? void 0 : _b.status}. Method ${(_c = error.config) === null || _c === void 0 ? void 0 : _c.method}. Retry count: ${retryCount}. Retrying in ${Math.round(delay / 1000)}s.`);
|
|
19
|
+
return delay;
|
|
19
20
|
},
|
|
20
21
|
retryCondition: (error) => {
|
|
21
|
-
var _a, _b, _c, _d;
|
|
22
|
-
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) &&
|
|
23
|
-
((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) >= 500 &&
|
|
24
|
-
((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) <= 599) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
else if (((_d = error.response) === null || _d === void 0 ? void 0 : _d.status) === 429) {
|
|
28
|
-
console.log('Rate limit exceeded. Delay: ' + error.response.headers['retry-after']);
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
onMaxRetryTimesExceeded(error, retryCount) {
|
|
36
22
|
var _a;
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
return (axios_retry_1.default.isNetworkOrIdempotentRequestError(error) &&
|
|
24
|
+
((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) !== 429);
|
|
25
|
+
},
|
|
26
|
+
onMaxRetryTimesExceeded(error) {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
(_b = (_a = error.config) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? true : delete _b.authorization;
|
|
29
|
+
(_d = (_c = error.config) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? true : delete _d.Authorization;
|
|
39
30
|
delete error.request._header;
|
|
31
|
+
console.warn('Max retry times exceeded. Error', error);
|
|
40
32
|
},
|
|
41
33
|
});
|
package/dist/http/index.d.ts
CHANGED
package/dist/http/index.js
CHANGED
|
@@ -14,6 +14,5 @@ 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
|
-
__exportStar(require("./client"), exports);
|
|
18
17
|
__exportStar(require("./types"), exports);
|
|
19
18
|
__exportStar(require("./axios-client"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './deprecated/adapter';
|
|
2
2
|
export * from './deprecated/demo-extractor';
|
|
3
3
|
export * from './deprecated/uploader';
|
|
4
|
+
export * from './deprecated/http/client';
|
|
4
5
|
export * from './types';
|
|
5
6
|
export * from './http';
|
|
6
7
|
export * from './common/install-initial-domain-mapping';
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.serializeAxiosError = exports.formatAxiosError = exports.spawn = exports
|
|
|
18
18
|
__exportStar(require("./deprecated/adapter"), exports);
|
|
19
19
|
__exportStar(require("./deprecated/demo-extractor"), exports);
|
|
20
20
|
__exportStar(require("./deprecated/uploader"), exports);
|
|
21
|
+
__exportStar(require("./deprecated/http/client"), exports);
|
|
21
22
|
__exportStar(require("./types"), exports);
|
|
22
23
|
__exportStar(require("./http"), exports);
|
|
23
24
|
__exportStar(require("./common/install-initial-domain-mapping"), exports);
|
package/dist/state/state.js
CHANGED
|
@@ -73,15 +73,16 @@ class State {
|
|
|
73
73
|
},
|
|
74
74
|
});
|
|
75
75
|
this.state = state || this.state;
|
|
76
|
-
console.log('State updated successfully to
|
|
76
|
+
console.log('State updated successfully to', (0, logger_1.getPrintableState)(this.state));
|
|
77
77
|
}
|
|
78
78
|
catch (error) {
|
|
79
79
|
if (axios_client_1.axios.isAxiosError(error)) {
|
|
80
|
-
console.error('Failed to update state
|
|
80
|
+
console.error('Failed to update state', (0, logger_1.serializeAxiosError)(error));
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
console.error('Failed to update state
|
|
83
|
+
console.error('Failed to update state', error);
|
|
84
84
|
}
|
|
85
|
+
process.exit(1);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
/**
|
|
@@ -105,7 +106,7 @@ class State {
|
|
|
105
106
|
},
|
|
106
107
|
});
|
|
107
108
|
this.state = JSON.parse(response.data.state);
|
|
108
|
-
console.log('State fetched successfully. Current state
|
|
109
|
+
console.log('State fetched successfully. Current state', (0, logger_1.getPrintableState)(this.state));
|
|
109
110
|
return this.state;
|
|
110
111
|
}
|
|
111
112
|
catch (error) {
|
|
@@ -118,7 +119,7 @@ class State {
|
|
|
118
119
|
}
|
|
119
120
|
else {
|
|
120
121
|
console.error('Failed to fetch state.', error);
|
|
121
|
-
|
|
122
|
+
process.exit(1);
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
}
|
|
@@ -31,6 +31,7 @@ function createEvent({ eventType, externalSyncUnits = [], progress, error, delay
|
|
|
31
31
|
mode: 'test_mode',
|
|
32
32
|
request_id: 'test_request_id',
|
|
33
33
|
snap_in_slug: 'test_snap_in_slug',
|
|
34
|
+
snap_in_version_id: 'test_snap_in_version_id',
|
|
34
35
|
sync_run: 'test_sync_run',
|
|
35
36
|
sync_run_id: 'test_sync_run_id',
|
|
36
37
|
sync_tier: 'test_sync_tier',
|
package/dist/types/workers.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Worker } from 'worker_threads';
|
|
2
|
-
import { MessagePort } from 'node:worker_threads';
|
|
3
2
|
import { State } from '../state/state';
|
|
4
3
|
import { WorkerAdapter } from '../workers/worker-adapter';
|
|
5
4
|
import { ExtractorEventType, AirdropEvent } from './extraction';
|
|
@@ -10,13 +9,11 @@ import { LoaderEventType } from './loading';
|
|
|
10
9
|
* @constructor
|
|
11
10
|
* @param {AirdropEvent} event - The event object received from the platform
|
|
12
11
|
* @param {object=} initialState - The initial state of the adapter
|
|
13
|
-
* @param {MessagePort} parentPort - The parent port of the worker thread
|
|
14
12
|
* @param {WorkerAdapterInterface} options - The options to create a new instance of WorkerAdapter class
|
|
15
13
|
*/
|
|
16
14
|
export interface WorkerAdapterInterface<ConnectorState> {
|
|
17
15
|
event: AirdropEvent;
|
|
18
16
|
adapterState: State<ConnectorState>;
|
|
19
|
-
parentPort: MessagePort;
|
|
20
17
|
options?: WorkerAdapterOptions;
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
@@ -139,5 +136,4 @@ export interface WorkerData<ConnectorState> {
|
|
|
139
136
|
export interface GetWorkerPathInterface {
|
|
140
137
|
event: AirdropEvent;
|
|
141
138
|
connectorWorkerPath?: string | null;
|
|
142
|
-
options?: WorkerAdapterOptions;
|
|
143
139
|
}
|
|
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Uploader = void 0;
|
|
40
40
|
const fs_1 = __importStar(require("fs"));
|
|
41
|
-
const
|
|
41
|
+
const axios_client_1 = require("../http/axios-client");
|
|
42
42
|
const zlib_1 = __importDefault(require("zlib"));
|
|
43
43
|
const js_jsonl_1 = require("js-jsonl");
|
|
44
44
|
const form_data_1 = __importDefault(require("form-data"));
|
|
@@ -67,7 +67,7 @@ class Uploader {
|
|
|
67
67
|
if (this.isLocalDevelopment) {
|
|
68
68
|
await this.downloadToLocal(itemType, fetchedObjects);
|
|
69
69
|
}
|
|
70
|
-
//
|
|
70
|
+
// compress the fetched objects to a gzipped jsonl object
|
|
71
71
|
const file = this.compressGzip(js_jsonl_1.jsonl.stringify(fetchedObjects));
|
|
72
72
|
if (!file) {
|
|
73
73
|
return {
|
|
@@ -76,21 +76,21 @@ class Uploader {
|
|
|
76
76
|
}
|
|
77
77
|
const filename = itemType + '.jsonl.gz';
|
|
78
78
|
const fileType = 'application/x-gzip';
|
|
79
|
-
//
|
|
79
|
+
// prepare the artifact for uploading
|
|
80
80
|
const preparedArtifact = await this.prepareArtifact(filename, fileType);
|
|
81
81
|
if (!preparedArtifact) {
|
|
82
82
|
return {
|
|
83
83
|
error: { message: 'Error while preparing artifact.' },
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
//
|
|
86
|
+
// upload the file to the prepared artifact
|
|
87
87
|
const uploadedArtifact = await this.uploadToArtifact(preparedArtifact, file);
|
|
88
88
|
if (!uploadedArtifact) {
|
|
89
89
|
return {
|
|
90
90
|
error: { message: 'Error while uploading artifact.' },
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
//
|
|
93
|
+
// return the artifact information to the platform
|
|
94
94
|
const artifact = {
|
|
95
95
|
id: preparedArtifact.id,
|
|
96
96
|
item_type: itemType,
|
|
@@ -108,7 +108,7 @@ class Uploader {
|
|
|
108
108
|
return response.data;
|
|
109
109
|
}
|
|
110
110
|
catch (error) {
|
|
111
|
-
if (
|
|
111
|
+
if (axios_client_1.axios.isAxiosError(error)) {
|
|
112
112
|
console.error('Error while preparing artifact.', (0, logger_1.serializeAxiosError)(error));
|
|
113
113
|
}
|
|
114
114
|
else {
|
|
@@ -125,13 +125,13 @@ class Uploader {
|
|
|
125
125
|
}
|
|
126
126
|
formData.append('file', file);
|
|
127
127
|
try {
|
|
128
|
-
const response = await
|
|
128
|
+
const response = await axios_client_1.axiosClient.post(preparedArtifact.url, formData, {
|
|
129
129
|
headers: Object.assign({}, formData.getHeaders()),
|
|
130
130
|
});
|
|
131
131
|
return response;
|
|
132
132
|
}
|
|
133
133
|
catch (error) {
|
|
134
|
-
if (
|
|
134
|
+
if (axios_client_1.axios.isAxiosError(error)) {
|
|
135
135
|
console.error('Error while uploading artifact.', (0, logger_1.serializeAxiosError)(error));
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
@@ -151,7 +151,7 @@ class Uploader {
|
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
153
|
try {
|
|
154
|
-
const response = await
|
|
154
|
+
const response = await axios_client_1.axiosClient.post(preparedArtifact.url, formData, {
|
|
155
155
|
headers: Object.assign(Object.assign({}, formData.getHeaders()), (!fileStreamResponse.headers['content-length'] && {
|
|
156
156
|
'Content-Length': constants_1.MAX_DEVREV_ARTIFACT_SIZE,
|
|
157
157
|
})),
|
|
@@ -159,7 +159,7 @@ class Uploader {
|
|
|
159
159
|
return response;
|
|
160
160
|
}
|
|
161
161
|
catch (error) {
|
|
162
|
-
if (
|
|
162
|
+
if (axios_client_1.axios.isAxiosError(error)) {
|
|
163
163
|
console.error('Error while streaming artifact.', (0, logger_1.serializeAxiosError)(error));
|
|
164
164
|
}
|
|
165
165
|
else {
|
|
@@ -212,13 +212,13 @@ class Uploader {
|
|
|
212
212
|
}
|
|
213
213
|
async downloadArtifact(artifactUrl) {
|
|
214
214
|
try {
|
|
215
|
-
const response = await
|
|
215
|
+
const response = await axios_client_1.axiosClient.get(artifactUrl, {
|
|
216
216
|
responseType: 'arraybuffer',
|
|
217
217
|
});
|
|
218
218
|
return response.data;
|
|
219
219
|
}
|
|
220
220
|
catch (error) {
|
|
221
|
-
if (
|
|
221
|
+
if (axios_client_1.axios.isAxiosError(error)) {
|
|
222
222
|
console.error('Error while downloading artifact from URL.', (0, logger_1.serializeAxiosError)(error));
|
|
223
223
|
}
|
|
224
224
|
else {
|
|
@@ -16,7 +16,7 @@ async function createWorker(workerData) {
|
|
|
16
16
|
workerData,
|
|
17
17
|
});
|
|
18
18
|
worker.on(workers_1.WorkerEvent.WorkerError, (error) => {
|
|
19
|
-
logger.error('Worker error',
|
|
19
|
+
logger.error('Worker error', error);
|
|
20
20
|
reject();
|
|
21
21
|
});
|
|
22
22
|
worker.on(workers_1.WorkerEvent.WorkerOnline, () => {
|
|
@@ -6,8 +6,8 @@ const types_1 = require("../../types");
|
|
|
6
6
|
task: async ({ adapter }) => {
|
|
7
7
|
await adapter.emit(types_1.LoaderEventType.UnknownEventType, {
|
|
8
8
|
error: {
|
|
9
|
-
message: 'Event type ' + adapter.event.payload.event_type + ' not supported.'
|
|
10
|
-
}
|
|
9
|
+
message: 'Event type ' + adapter.event.payload.event_type + ' not supported.',
|
|
10
|
+
},
|
|
11
11
|
});
|
|
12
12
|
},
|
|
13
13
|
onTimeout: async ({ adapter }) => {
|
|
@@ -22,7 +22,6 @@ function processTask({ task, onTimeout, }) {
|
|
|
22
22
|
const adapter = new worker_adapter_1.WorkerAdapter({
|
|
23
23
|
event,
|
|
24
24
|
adapterState,
|
|
25
|
-
parentPort: node_worker_threads_1.parentPort,
|
|
26
25
|
options,
|
|
27
26
|
});
|
|
28
27
|
node_worker_threads_1.parentPort.on(workers_1.WorkerEvent.WorkerMessage, async (message) => {
|
package/dist/workers/spawn.js
CHANGED
|
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Spawn = void 0;
|
|
7
7
|
exports.spawn = spawn;
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const helpers_1 = require("yargs/helpers");
|
|
10
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
9
11
|
const extraction_1 = require("../types/extraction");
|
|
10
12
|
const control_protocol_1 = require("../common/control-protocol");
|
|
11
|
-
const
|
|
13
|
+
const helpers_2 = require("../common/helpers");
|
|
12
14
|
const logger_1 = require("../logger/logger");
|
|
13
15
|
const workers_1 = require("../types/workers");
|
|
14
16
|
const create_worker_1 = require("./create-worker");
|
|
@@ -74,8 +76,15 @@ async function spawn({ event, initialState, workerPath, options, }) {
|
|
|
74
76
|
const script = getWorkerPath({
|
|
75
77
|
event,
|
|
76
78
|
connectorWorkerPath: workerPath,
|
|
77
|
-
options,
|
|
78
79
|
});
|
|
80
|
+
if (options === null || options === void 0 ? void 0 : options.isLocalDevelopment) {
|
|
81
|
+
logger.warn('WARN: isLocalDevelopment is deprecated. Please use the -- local flag instead.');
|
|
82
|
+
}
|
|
83
|
+
// read the command line arguments to check if the local flag is passed
|
|
84
|
+
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).argv;
|
|
85
|
+
if (argv._.includes('local')) {
|
|
86
|
+
options = Object.assign(Object.assign({}, (options || {})), { isLocalDevelopment: true });
|
|
87
|
+
}
|
|
79
88
|
if (script) {
|
|
80
89
|
try {
|
|
81
90
|
const worker = await (0, create_worker_1.createWorker)({
|
|
@@ -182,7 +191,7 @@ class Spawn {
|
|
|
182
191
|
return;
|
|
183
192
|
}
|
|
184
193
|
this.alreadyEmitted = true;
|
|
185
|
-
const timeoutEventType = (0,
|
|
194
|
+
const timeoutEventType = (0, helpers_2.getTimeoutErrorEventType)(this.event.payload.event_type);
|
|
186
195
|
if (timeoutEventType) {
|
|
187
196
|
const { eventType } = timeoutEventType;
|
|
188
197
|
try {
|
|
@@ -6,7 +6,7 @@ import { WorkerAdapterInterface, WorkerAdapterOptions } from '../types/workers';
|
|
|
6
6
|
import { Repo } from '../repo/repo';
|
|
7
7
|
import { NormalizedAttachment, RepoInterface } from '../repo/repo.interfaces';
|
|
8
8
|
import { ExternalSystemItem, ItemTypesToLoadParams, ItemTypeToLoad, LoaderReport, LoadItemResponse, LoadItemTypesResponse } from '../types/loading';
|
|
9
|
-
export declare function createWorkerAdapter<ConnectorState>({ event, adapterState,
|
|
9
|
+
export declare function createWorkerAdapter<ConnectorState>({ event, adapterState, options, }: WorkerAdapterInterface<ConnectorState>): WorkerAdapter<ConnectorState>;
|
|
10
10
|
/**
|
|
11
11
|
* WorkerAdapter class is used to interact with Airdrop platform. It is passed to the snap-in
|
|
12
12
|
* as parameter in processTask and onTimeout functions. The class provides
|
|
@@ -27,14 +27,13 @@ export declare class WorkerAdapter<ConnectorState> {
|
|
|
27
27
|
private adapterState;
|
|
28
28
|
private _artifacts;
|
|
29
29
|
private hasWorkerEmitted;
|
|
30
|
-
private parentPort;
|
|
31
30
|
private isTimeout;
|
|
32
31
|
private repos;
|
|
33
32
|
private loaderReports;
|
|
34
33
|
private _processedFiles;
|
|
35
34
|
private mappers;
|
|
36
35
|
private uploader;
|
|
37
|
-
constructor({ event, adapterState,
|
|
36
|
+
constructor({ event, adapterState, options, }: WorkerAdapterInterface<ConnectorState>);
|
|
38
37
|
get state(): AdapterState<ConnectorState>;
|
|
39
38
|
set state(value: AdapterState<ConnectorState>);
|
|
40
39
|
get reports(): LoaderReport[];
|
|
@@ -64,7 +63,7 @@ export declare class WorkerAdapter<ConnectorState> {
|
|
|
64
63
|
item: ExternalSystemItem;
|
|
65
64
|
itemTypeToLoad: ItemTypeToLoad;
|
|
66
65
|
}): Promise<LoadItemResponse>;
|
|
67
|
-
processAttachment
|
|
66
|
+
processAttachment(attachment: NormalizedAttachment, stream: ExternalSystemAttachmentStreamingFunction): Promise<ProcessAttachmentReturnType>;
|
|
68
67
|
loadAttachment({ item, create, }: {
|
|
69
68
|
item: ExternalSystemAttachment;
|
|
70
69
|
create: ExternalSystemLoadingFunction<ExternalSystemAttachment>;
|
|
@@ -6,6 +6,7 @@ const axios_devrev_client_1 = require("../http/axios-devrev-client");
|
|
|
6
6
|
const extraction_1 = require("../types/extraction");
|
|
7
7
|
const loading_1 = require("../types/loading");
|
|
8
8
|
const constants_1 = require("../common/constants");
|
|
9
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
9
10
|
const control_protocol_1 = require("../common/control-protocol");
|
|
10
11
|
const workers_1 = require("../types/workers");
|
|
11
12
|
const repo_1 = require("../repo/repo");
|
|
@@ -14,11 +15,10 @@ const mappers_1 = require("../mappers/mappers");
|
|
|
14
15
|
const uploader_1 = require("../uploader/uploader");
|
|
15
16
|
const logger_1 = require("../logger/logger");
|
|
16
17
|
const mappers_interface_1 = require("../mappers/mappers.interface");
|
|
17
|
-
function createWorkerAdapter({ event, adapterState,
|
|
18
|
+
function createWorkerAdapter({ event, adapterState, options, }) {
|
|
18
19
|
return new WorkerAdapter({
|
|
19
20
|
event,
|
|
20
21
|
adapterState,
|
|
21
|
-
parentPort,
|
|
22
22
|
options,
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -37,56 +37,12 @@ function createWorkerAdapter({ event, adapterState, parentPort, options, }) {
|
|
|
37
37
|
*
|
|
38
38
|
*/
|
|
39
39
|
class WorkerAdapter {
|
|
40
|
-
constructor({ event, adapterState,
|
|
40
|
+
constructor({ event, adapterState, options, }) {
|
|
41
41
|
this.repos = [];
|
|
42
|
-
this.processAttachment = async (attachment, stream) => {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
const { httpStream, delay, error } = await stream({
|
|
45
|
-
item: attachment,
|
|
46
|
-
event: this.event,
|
|
47
|
-
});
|
|
48
|
-
if (error) {
|
|
49
|
-
console.warn('Error while streaming attachment', error === null || error === void 0 ? void 0 : error.message);
|
|
50
|
-
return { error };
|
|
51
|
-
}
|
|
52
|
-
else if (delay) {
|
|
53
|
-
return { delay };
|
|
54
|
-
}
|
|
55
|
-
if (httpStream) {
|
|
56
|
-
const fileType = ((_a = httpStream.headers) === null || _a === void 0 ? void 0 : _a['content-type']) || 'application/octet-stream';
|
|
57
|
-
const preparedArtifact = await this.uploader.prepareArtifact(attachment.file_name, fileType);
|
|
58
|
-
if (!preparedArtifact) {
|
|
59
|
-
console.warn('Error while preparing artifact for attachment ID ' +
|
|
60
|
-
attachment.id +
|
|
61
|
-
'. Skipping attachment');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const uploadedArtifact = await this.uploader.streamToArtifact(preparedArtifact, httpStream);
|
|
65
|
-
if (!uploadedArtifact) {
|
|
66
|
-
console.warn('Error while preparing artifact for attachment ID ' + attachment.id);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const ssorAttachment = {
|
|
70
|
-
id: {
|
|
71
|
-
devrev: preparedArtifact.id,
|
|
72
|
-
external: attachment.id,
|
|
73
|
-
},
|
|
74
|
-
parent_id: {
|
|
75
|
-
external: attachment.parent_id,
|
|
76
|
-
},
|
|
77
|
-
actor_id: {
|
|
78
|
-
external: attachment.author_id,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
await ((_b = this.getRepo('ssor_attachment')) === null || _b === void 0 ? void 0 : _b.push([ssorAttachment]));
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
};
|
|
85
42
|
this.event = event;
|
|
86
43
|
this.options = options;
|
|
87
44
|
this.adapterState = adapterState;
|
|
88
45
|
this._artifacts = [];
|
|
89
|
-
this.parentPort = parentPort;
|
|
90
46
|
this.hasWorkerEmitted = false;
|
|
91
47
|
this.isTimeout = false;
|
|
92
48
|
// Loader
|
|
@@ -156,9 +112,7 @@ class WorkerAdapter {
|
|
|
156
112
|
*/
|
|
157
113
|
async emit(newEventType, data) {
|
|
158
114
|
if (this.hasWorkerEmitted) {
|
|
159
|
-
console.warn(
|
|
160
|
-
newEventType +
|
|
161
|
-
'. Lambda is going to be stopped.');
|
|
115
|
+
console.warn(`Trying to emit event with event type: ${newEventType}. Ignoring emit request because it has already been emitted.`);
|
|
162
116
|
return;
|
|
163
117
|
}
|
|
164
118
|
// We want to upload all the repos before emitting the event, except for the external sync units done event
|
|
@@ -167,15 +121,20 @@ class WorkerAdapter {
|
|
|
167
121
|
}
|
|
168
122
|
// If the extraction is done, we want to save the timestamp of the last successful sync
|
|
169
123
|
if (newEventType === extraction_1.ExtractorEventType.ExtractionAttachmentsDone) {
|
|
124
|
+
console.log(`Overwriting lastSuccessfulSyncStarted with lastSyncStarted (${this.state.lastSyncStarted}).`);
|
|
170
125
|
this.state.lastSuccessfulSyncStarted = this.state.lastSyncStarted;
|
|
171
126
|
this.state.lastSyncStarted = '';
|
|
172
127
|
}
|
|
173
128
|
// We want to save the state every time we emit an event, except for the start and delete events
|
|
174
129
|
if (!constants_1.STATELESS_EVENT_TYPES.includes(this.event.payload.event_type)) {
|
|
175
|
-
console.log(`Saving state before emitting event with event type:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
130
|
+
console.log(`Saving state before emitting event with event type: ${newEventType}.`);
|
|
131
|
+
try {
|
|
132
|
+
await this.adapterState.postState(this.state);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error('Error while posting state', error);
|
|
136
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
|
|
137
|
+
}
|
|
179
138
|
}
|
|
180
139
|
try {
|
|
181
140
|
await (0, control_protocol_1.emit)({
|
|
@@ -190,17 +149,17 @@ class WorkerAdapter {
|
|
|
190
149
|
payload: { eventType: newEventType },
|
|
191
150
|
};
|
|
192
151
|
this.artifacts = [];
|
|
193
|
-
this.parentPort.postMessage(message);
|
|
194
152
|
this.hasWorkerEmitted = true;
|
|
153
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(message);
|
|
195
154
|
}
|
|
196
155
|
catch (error) {
|
|
197
156
|
if (axios_devrev_client_1.axios.isAxiosError(error)) {
|
|
198
|
-
console.error(
|
|
157
|
+
console.error(`Error while emitting event with event type: ${newEventType}`, (0, logger_1.serializeAxiosError)(error));
|
|
199
158
|
}
|
|
200
159
|
else {
|
|
201
|
-
console.error(
|
|
160
|
+
console.error(`Unknown error while emitting event with event type: ${newEventType}`, error);
|
|
202
161
|
}
|
|
203
|
-
|
|
162
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
|
|
204
163
|
}
|
|
205
164
|
}
|
|
206
165
|
async uploadAllRepos() {
|
|
@@ -212,33 +171,40 @@ class WorkerAdapter {
|
|
|
212
171
|
this.isTimeout = true;
|
|
213
172
|
}
|
|
214
173
|
async loadItemTypes({ itemTypesToLoad, }) {
|
|
215
|
-
var _a
|
|
174
|
+
var _a;
|
|
216
175
|
if (this.event.payload.event_type === extraction_1.EventType.StartLoadingData) {
|
|
176
|
+
const itemTypes = itemTypesToLoad.map((itemTypeToLoad) => itemTypeToLoad.itemType);
|
|
177
|
+
if (!itemTypes.length) {
|
|
178
|
+
console.warn('No item types to load, returning.');
|
|
179
|
+
return {
|
|
180
|
+
reports: this.reports,
|
|
181
|
+
processed_files: this.processedFiles,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const filesToLoad = await this.getLoaderBatches({
|
|
185
|
+
supportedItemTypes: itemTypes,
|
|
186
|
+
});
|
|
217
187
|
this.adapterState.state.fromDevRev = {
|
|
218
|
-
filesToLoad
|
|
219
|
-
supportedItemTypes: itemTypesToLoad.map((it) => it.itemType),
|
|
220
|
-
}),
|
|
188
|
+
filesToLoad,
|
|
221
189
|
};
|
|
222
190
|
}
|
|
223
|
-
if (
|
|
191
|
+
if (!this.adapterState.state.fromDevRev ||
|
|
192
|
+
!this.adapterState.state.fromDevRev.filesToLoad.length) {
|
|
224
193
|
console.warn('No files to load, returning.');
|
|
225
194
|
return {
|
|
226
195
|
reports: this.reports,
|
|
227
196
|
processed_files: this.processedFiles,
|
|
228
197
|
};
|
|
229
198
|
}
|
|
230
|
-
console.log('Files to load in state', (
|
|
231
|
-
outerloop: for (const fileToLoad of
|
|
199
|
+
console.log('Files to load in state', (_a = this.adapterState.state.fromDevRev) === null || _a === void 0 ? void 0 : _a.filesToLoad);
|
|
200
|
+
outerloop: for (const fileToLoad of this.adapterState.state.fromDevRev
|
|
201
|
+
.filesToLoad) {
|
|
232
202
|
const itemTypeToLoad = itemTypesToLoad.find((itemTypeToLoad) => itemTypeToLoad.itemType === fileToLoad.itemType);
|
|
233
203
|
if (!itemTypeToLoad) {
|
|
234
204
|
console.error(`Item type to load not found for item type: ${fileToLoad.itemType}.`);
|
|
235
|
-
await (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
data: {
|
|
239
|
-
error: {
|
|
240
|
-
message: `Item type to load not found for item type: ${fileToLoad.itemType}.`,
|
|
241
|
-
},
|
|
205
|
+
await this.emit(loading_1.LoaderEventType.DataLoadingError, {
|
|
206
|
+
error: {
|
|
207
|
+
message: `Item type to load not found for item type: ${fileToLoad.itemType}.`,
|
|
242
208
|
},
|
|
243
209
|
});
|
|
244
210
|
break;
|
|
@@ -249,8 +215,12 @@ class WorkerAdapter {
|
|
|
249
215
|
isGzipped: true,
|
|
250
216
|
}));
|
|
251
217
|
if (!transformerFile) {
|
|
252
|
-
console.error(
|
|
253
|
-
|
|
218
|
+
console.error(`Transformer file not found for artifact ID: ${fileToLoad.id}.`);
|
|
219
|
+
await this.emit(loading_1.LoaderEventType.DataLoadingError, {
|
|
220
|
+
error: {
|
|
221
|
+
message: `Transformer file not found for artifact ID: ${fileToLoad.id}.`,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
254
224
|
}
|
|
255
225
|
for (let i = fileToLoad.lineToProcess; i < fileToLoad.count; i++) {
|
|
256
226
|
const { report, rateLimit } = await this.loadItem({
|
|
@@ -258,14 +228,10 @@ class WorkerAdapter {
|
|
|
258
228
|
itemTypeToLoad,
|
|
259
229
|
});
|
|
260
230
|
if (rateLimit === null || rateLimit === void 0 ? void 0 : rateLimit.delay) {
|
|
261
|
-
await (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
delay: rateLimit.delay,
|
|
266
|
-
reports: this.reports,
|
|
267
|
-
processed_files: this.processedFiles,
|
|
268
|
-
},
|
|
231
|
+
await this.emit(loading_1.LoaderEventType.DataLoadingDelay, {
|
|
232
|
+
delay: rateLimit.delay,
|
|
233
|
+
reports: this.reports,
|
|
234
|
+
processed_files: this.processedFiles,
|
|
269
235
|
});
|
|
270
236
|
break outerloop;
|
|
271
237
|
}
|
|
@@ -315,6 +281,7 @@ class WorkerAdapter {
|
|
|
315
281
|
}
|
|
316
282
|
if (!this.adapterState.state.fromDevRev ||
|
|
317
283
|
((_a = this.adapterState.state.fromDevRev) === null || _a === void 0 ? void 0 : _a.filesToLoad.length) === 0) {
|
|
284
|
+
console.log('No files to load, returning.');
|
|
318
285
|
return {
|
|
319
286
|
reports: this.reports,
|
|
320
287
|
processed_files: this.processedFiles,
|
|
@@ -327,7 +294,7 @@ class WorkerAdapter {
|
|
|
327
294
|
isGzipped: true,
|
|
328
295
|
}));
|
|
329
296
|
if (!transformerFile) {
|
|
330
|
-
console.error(
|
|
297
|
+
console.error(`Transformer file not found for artifact ID: ${fileToLoad.id}.`);
|
|
331
298
|
break outerloop;
|
|
332
299
|
}
|
|
333
300
|
for (let i = fileToLoad.lineToProcess; i < fileToLoad.count; i++) {
|
|
@@ -336,14 +303,10 @@ class WorkerAdapter {
|
|
|
336
303
|
create,
|
|
337
304
|
});
|
|
338
305
|
if (rateLimit === null || rateLimit === void 0 ? void 0 : rateLimit.delay) {
|
|
339
|
-
await (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
delay: rateLimit.delay,
|
|
344
|
-
reports: this.reports,
|
|
345
|
-
processed_files: this.processedFiles,
|
|
346
|
-
},
|
|
306
|
+
await this.emit(loading_1.LoaderEventType.DataLoadingDelay, {
|
|
307
|
+
delay: rateLimit.delay,
|
|
308
|
+
reports: this.reports,
|
|
309
|
+
processed_files: this.processedFiles,
|
|
347
310
|
});
|
|
348
311
|
break outerloop;
|
|
349
312
|
}
|
|
@@ -374,14 +337,14 @@ class WorkerAdapter {
|
|
|
374
337
|
});
|
|
375
338
|
const syncMapperRecord = syncMapperRecordResponse.data;
|
|
376
339
|
if (!syncMapperRecord) {
|
|
377
|
-
console.
|
|
340
|
+
console.warn('Failed to get sync mapper record from response.');
|
|
378
341
|
return {
|
|
379
342
|
error: {
|
|
380
343
|
message: 'Failed to get sync mapper record from response.',
|
|
381
344
|
},
|
|
382
345
|
};
|
|
383
346
|
}
|
|
384
|
-
// Update item
|
|
347
|
+
// Update item in external system
|
|
385
348
|
const { id, modifiedDate, delay, error } = await itemTypeToLoad.update({
|
|
386
349
|
item,
|
|
387
350
|
mappers: this.mappers,
|
|
@@ -390,7 +353,7 @@ class WorkerAdapter {
|
|
|
390
353
|
if (id) {
|
|
391
354
|
if (modifiedDate) {
|
|
392
355
|
try {
|
|
393
|
-
|
|
356
|
+
await this.mappers.update({
|
|
394
357
|
id: syncMapperRecord.sync_mapper_record.id,
|
|
395
358
|
sync_unit: this.event.payload.event_context.sync_unit,
|
|
396
359
|
status: mappers_interface_1.SyncMapperRecordStatus.OPERATIONAL,
|
|
@@ -409,11 +372,10 @@ class WorkerAdapter {
|
|
|
409
372
|
add: [devrevId],
|
|
410
373
|
},
|
|
411
374
|
});
|
|
412
|
-
console.log('Updated sync mapper record', JSON.stringify(updateSyncMapperRecordResponse.data));
|
|
413
375
|
}
|
|
414
376
|
catch (error) {
|
|
415
377
|
if (axios_devrev_client_1.axios.isAxiosError(error)) {
|
|
416
|
-
console.
|
|
378
|
+
console.warn('Failed to update sync mapper record', (0, logger_1.serializeAxiosError)(error));
|
|
417
379
|
return {
|
|
418
380
|
error: {
|
|
419
381
|
message: error.message,
|
|
@@ -421,7 +383,7 @@ class WorkerAdapter {
|
|
|
421
383
|
};
|
|
422
384
|
}
|
|
423
385
|
else {
|
|
424
|
-
console.
|
|
386
|
+
console.warn('Failed to update sync mapper record', error);
|
|
425
387
|
return {
|
|
426
388
|
error: {
|
|
427
389
|
message: 'Failed to update sync mapper record' + error,
|
|
@@ -438,7 +400,7 @@ class WorkerAdapter {
|
|
|
438
400
|
};
|
|
439
401
|
}
|
|
440
402
|
else if (delay) {
|
|
441
|
-
console.log(
|
|
403
|
+
console.log(`Rate limited while updating item in external system, delaying for ${delay} seconds.`);
|
|
442
404
|
return {
|
|
443
405
|
rateLimit: {
|
|
444
406
|
delay,
|
|
@@ -446,7 +408,7 @@ class WorkerAdapter {
|
|
|
446
408
|
};
|
|
447
409
|
}
|
|
448
410
|
else {
|
|
449
|
-
console.
|
|
411
|
+
console.warn('Failed to update item in external system', error);
|
|
450
412
|
return {
|
|
451
413
|
report: {
|
|
452
414
|
item_type: itemTypeToLoad.itemType,
|
|
@@ -454,12 +416,12 @@ class WorkerAdapter {
|
|
|
454
416
|
},
|
|
455
417
|
};
|
|
456
418
|
}
|
|
457
|
-
// Update mapper (optional)
|
|
419
|
+
// TODO: Update mapper (optional)
|
|
458
420
|
}
|
|
459
421
|
catch (error) {
|
|
460
422
|
if (axios_devrev_client_1.axios.isAxiosError(error)) {
|
|
461
423
|
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
462
|
-
// Create item
|
|
424
|
+
// Create item in external system if mapper record not found
|
|
463
425
|
const { id, delay, error } = await itemTypeToLoad.create({
|
|
464
426
|
item,
|
|
465
427
|
mappers: this.mappers,
|
|
@@ -468,13 +430,12 @@ class WorkerAdapter {
|
|
|
468
430
|
if (id) {
|
|
469
431
|
// Create mapper
|
|
470
432
|
try {
|
|
471
|
-
|
|
433
|
+
await this.mappers.create({
|
|
472
434
|
sync_unit: this.event.payload.event_context.sync_unit,
|
|
473
435
|
status: mappers_interface_1.SyncMapperRecordStatus.OPERATIONAL,
|
|
474
436
|
external_ids: [id],
|
|
475
437
|
targets: [devrevId],
|
|
476
438
|
});
|
|
477
|
-
console.log('Created sync mapper record', createdSyncMapperRecordResponse.data.sync_mapper_record.id);
|
|
478
439
|
return {
|
|
479
440
|
report: {
|
|
480
441
|
item_type: itemTypeToLoad.itemType,
|
|
@@ -484,14 +445,14 @@ class WorkerAdapter {
|
|
|
484
445
|
}
|
|
485
446
|
catch (error) {
|
|
486
447
|
if (axios_devrev_client_1.axios.isAxiosError(error)) {
|
|
487
|
-
console.
|
|
448
|
+
console.warn('Failed to create sync mapper record', (0, logger_1.serializeAxiosError)(error));
|
|
488
449
|
return {
|
|
489
450
|
error: {
|
|
490
451
|
message: error.message,
|
|
491
452
|
},
|
|
492
453
|
};
|
|
493
454
|
}
|
|
494
|
-
console.
|
|
455
|
+
console.warn('Failed to create sync mapper record', error);
|
|
495
456
|
return {
|
|
496
457
|
error: {
|
|
497
458
|
message: 'Failed to create sync mapper record' + error,
|
|
@@ -507,7 +468,7 @@ class WorkerAdapter {
|
|
|
507
468
|
};
|
|
508
469
|
}
|
|
509
470
|
else {
|
|
510
|
-
console.
|
|
471
|
+
console.warn('Failed to create item in external system', error);
|
|
511
472
|
return {
|
|
512
473
|
report: {
|
|
513
474
|
item_type: itemTypeToLoad.itemType,
|
|
@@ -517,7 +478,7 @@ class WorkerAdapter {
|
|
|
517
478
|
}
|
|
518
479
|
}
|
|
519
480
|
else {
|
|
520
|
-
console.
|
|
481
|
+
console.warn('Failed to get sync mapper record', (0, logger_1.serializeAxiosError)(error));
|
|
521
482
|
return {
|
|
522
483
|
error: {
|
|
523
484
|
message: error.message,
|
|
@@ -525,7 +486,7 @@ class WorkerAdapter {
|
|
|
525
486
|
};
|
|
526
487
|
}
|
|
527
488
|
}
|
|
528
|
-
console.
|
|
489
|
+
console.warn('Failed to get sync mapper record', error);
|
|
529
490
|
return {
|
|
530
491
|
error: {
|
|
531
492
|
message: 'Failed to get sync mapper record' + error,
|
|
@@ -533,6 +494,51 @@ class WorkerAdapter {
|
|
|
533
494
|
};
|
|
534
495
|
}
|
|
535
496
|
}
|
|
497
|
+
async processAttachment(attachment, stream) {
|
|
498
|
+
var _a, _b;
|
|
499
|
+
const { httpStream, delay, error } = await stream({
|
|
500
|
+
item: attachment,
|
|
501
|
+
event: this.event,
|
|
502
|
+
});
|
|
503
|
+
if (error) {
|
|
504
|
+
console.warn('Error while streaming attachment', error === null || error === void 0 ? void 0 : error.message);
|
|
505
|
+
return { error };
|
|
506
|
+
}
|
|
507
|
+
else if (delay) {
|
|
508
|
+
return { delay };
|
|
509
|
+
}
|
|
510
|
+
if (httpStream) {
|
|
511
|
+
const fileType = ((_a = httpStream.headers) === null || _a === void 0 ? void 0 : _a['content-type']) || 'application/octet-stream';
|
|
512
|
+
const preparedArtifact = await this.uploader.prepareArtifact(attachment.file_name, fileType);
|
|
513
|
+
if (!preparedArtifact) {
|
|
514
|
+
console.warn('Error while preparing artifact for attachment ID ' +
|
|
515
|
+
attachment.id +
|
|
516
|
+
'. Skipping attachment');
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const uploadedArtifact = await this.uploader.streamToArtifact(preparedArtifact, httpStream);
|
|
520
|
+
if (!uploadedArtifact) {
|
|
521
|
+
console.warn('Error while preparing artifact for attachment ID ' + attachment.id);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const ssorAttachment = {
|
|
525
|
+
id: {
|
|
526
|
+
devrev: preparedArtifact.id,
|
|
527
|
+
external: attachment.id,
|
|
528
|
+
},
|
|
529
|
+
parent_id: {
|
|
530
|
+
external: attachment.parent_id,
|
|
531
|
+
},
|
|
532
|
+
};
|
|
533
|
+
if (attachment.author_id) {
|
|
534
|
+
ssorAttachment.actor_id = {
|
|
535
|
+
external: attachment.author_id,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
await ((_b = this.getRepo('ssor_attachment')) === null || _b === void 0 ? void 0 : _b.push([ssorAttachment]));
|
|
539
|
+
}
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
536
542
|
async loadAttachment({ item, create, }) {
|
|
537
543
|
// Create item
|
|
538
544
|
const { id, delay, error } = await create({
|
|
@@ -556,7 +562,7 @@ class WorkerAdapter {
|
|
|
556
562
|
};
|
|
557
563
|
}
|
|
558
564
|
else {
|
|
559
|
-
console.
|
|
565
|
+
console.warn('Failed to create attachment in external system', error);
|
|
560
566
|
return {
|
|
561
567
|
report: {
|
|
562
568
|
item_type: 'attachment',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devrev/ts-adaas",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "DevRev ADaaS (AirDrop-as-a-Service) Typescript SDK.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@types/jest": "^29.5.12",
|
|
27
27
|
"@types/lambda-log": "^3.0.3",
|
|
28
28
|
"@types/node": "20.16.11",
|
|
29
|
+
"@types/yargs": "^17.0.33",
|
|
29
30
|
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
|
30
31
|
"@typescript-eslint/parser": "^7.12.0",
|
|
31
32
|
"eslint": "^8.57.0",
|
|
@@ -42,7 +43,8 @@
|
|
|
42
43
|
"form-data": "^4.0.1",
|
|
43
44
|
"js-jsonl": "^1.1.1",
|
|
44
45
|
"lambda-log": "^3.1.0",
|
|
45
|
-
"ts-node": "^10.9.2"
|
|
46
|
+
"ts-node": "^10.9.2",
|
|
47
|
+
"yargs": "^17.7.2"
|
|
46
48
|
},
|
|
47
49
|
"files": [
|
|
48
50
|
"dist"
|