@devrev/ts-adaas 1.2.2 → 1.2.4
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 +11 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +3 -1
- package/dist/common/control-protocol.js +5 -2
- package/dist/common/helpers.js +10 -1
- package/dist/http/axios-devrev-client.js +1 -1
- package/dist/repo/repo.interfaces.d.ts +1 -1
- package/dist/tests/test-helpers.js +1 -0
- package/dist/types/extraction.d.ts +1 -0
- package/dist/uploader/uploader.interfaces.d.ts +1 -1
- package/dist/workers/create-worker.js +1 -1
- package/dist/workers/spawn.js +12 -2
- package/dist/workers/worker-adapter.js +9 -4
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## Release Notes
|
|
4
4
|
|
|
5
|
+
### v1.2.4
|
|
6
|
+
|
|
7
|
+
- Do not fail the extraction of attachments if streaming of single attachment fails.
|
|
8
|
+
|
|
9
|
+
### v1.2.3
|
|
10
|
+
|
|
11
|
+
- Add `local` flag to use for local development of the ADaaS snap-ins.
|
|
12
|
+
- Send library version, snap-in version and snap-in slug in headers while emitting.
|
|
13
|
+
- Make `actor_id` field optional for `SsorAttachment` interface.
|
|
14
|
+
- Fix bugs related to event handling, error logging.
|
|
15
|
+
|
|
5
16
|
### v1.2.2
|
|
6
17
|
|
|
7
18
|
- Add library version as a part of control protocol.
|
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,14 +2,14 @@
|
|
|
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
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
6
|
const emit = async ({ event, eventType, data, }) => {
|
|
7
7
|
const newEvent = {
|
|
8
8
|
event_type: eventType,
|
|
9
9
|
event_context: event.payload.event_context,
|
|
10
10
|
event_data: Object.assign({}, data),
|
|
11
11
|
worker_metadata: {
|
|
12
|
-
adaas_library_version:
|
|
12
|
+
adaas_library_version: constants_1.LIBRARY_VERSION,
|
|
13
13
|
},
|
|
14
14
|
};
|
|
15
15
|
console.info('Emitting event', JSON.stringify(newEvent));
|
|
@@ -18,6 +18,9 @@ const emit = async ({ event, eventType, data, }) => {
|
|
|
18
18
|
Accept: 'application/json, text/plain, */*',
|
|
19
19
|
Authorization: event.context.secrets.service_account_token,
|
|
20
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,
|
|
21
24
|
},
|
|
22
25
|
});
|
|
23
26
|
};
|
package/dist/common/helpers.js
CHANGED
|
@@ -80,6 +80,11 @@ function getTimeoutErrorEventType(eventType) {
|
|
|
80
80
|
return {
|
|
81
81
|
eventType: loading_1.LoaderEventType.LoaderStateDeletionError,
|
|
82
82
|
};
|
|
83
|
+
case extraction_1.EventType.StartLoadingAttachments:
|
|
84
|
+
case extraction_1.EventType.ContinueLoadingAttachments:
|
|
85
|
+
return {
|
|
86
|
+
eventType: loading_1.LoaderEventType.AttachmentLoadingError,
|
|
87
|
+
};
|
|
83
88
|
case extraction_1.EventType.StartDeletingLoaderAttachmentState:
|
|
84
89
|
return {
|
|
85
90
|
eventType: loading_1.LoaderEventType.LoaderAttachmentStateDeletionError,
|
|
@@ -160,7 +165,11 @@ function getCircularReplacer() {
|
|
|
160
165
|
function getLibraryVersion() {
|
|
161
166
|
var _a;
|
|
162
167
|
try {
|
|
163
|
-
|
|
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 '';
|
|
164
173
|
}
|
|
165
174
|
catch (error) {
|
|
166
175
|
console.error('Error reading adaas library version from package.json', error);
|
|
@@ -13,7 +13,7 @@ exports.axiosDevRevClient = axiosDevRevClient;
|
|
|
13
13
|
retries: 5,
|
|
14
14
|
retryDelay: (retryCount, error) => {
|
|
15
15
|
var _a, _b;
|
|
16
|
-
console.warn('Retry attempt: ' + retryCount + 'to url: ' + ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) + '.');
|
|
16
|
+
console.warn('Retry attempt: ' + retryCount + ' to url: ' + ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) + '.');
|
|
17
17
|
if (error.response) {
|
|
18
18
|
const retry_after = (_b = error.response) === null || _b === void 0 ? void 0 : _b.headers['retry-after'];
|
|
19
19
|
if (retry_after) {
|
|
@@ -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',
|
|
@@ -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, () => {
|
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");
|
|
@@ -75,6 +77,14 @@ async function spawn({ event, initialState, workerPath, options, }) {
|
|
|
75
77
|
event,
|
|
76
78
|
connectorWorkerPath: workerPath,
|
|
77
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
|
+
}
|
|
78
88
|
if (script) {
|
|
79
89
|
try {
|
|
80
90
|
const worker = await (0, create_worker_1.createWorker)({
|
|
@@ -181,7 +191,7 @@ class Spawn {
|
|
|
181
191
|
return;
|
|
182
192
|
}
|
|
183
193
|
this.alreadyEmitted = true;
|
|
184
|
-
const timeoutEventType = (0,
|
|
194
|
+
const timeoutEventType = (0, helpers_2.getTimeoutErrorEventType)(this.event.payload.event_type);
|
|
185
195
|
if (timeoutEventType) {
|
|
186
196
|
const { eventType } = timeoutEventType;
|
|
187
197
|
try {
|
|
@@ -529,10 +529,12 @@ class WorkerAdapter {
|
|
|
529
529
|
parent_id: {
|
|
530
530
|
external: attachment.parent_id,
|
|
531
531
|
},
|
|
532
|
-
actor_id: {
|
|
533
|
-
external: attachment.author_id,
|
|
534
|
-
},
|
|
535
532
|
};
|
|
533
|
+
if (attachment.author_id) {
|
|
534
|
+
ssorAttachment.actor_id = {
|
|
535
|
+
external: attachment.author_id,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
536
538
|
await ((_b = this.getRepo('ssor_attachment')) === null || _b === void 0 ? void 0 : _b.push([ssorAttachment]));
|
|
537
539
|
}
|
|
538
540
|
return;
|
|
@@ -617,9 +619,12 @@ class WorkerAdapter {
|
|
|
617
619
|
const attachmentsToProcess = attachments.slice((_c = (_b = this.state.toDevRev) === null || _b === void 0 ? void 0 : _b.attachmentsMetadata) === null || _c === void 0 ? void 0 : _c.lastProcessed, attachments.length);
|
|
618
620
|
for (const attachment of attachmentsToProcess) {
|
|
619
621
|
const response = await this.processAttachment(attachment, stream);
|
|
620
|
-
if (
|
|
622
|
+
if (response === null || response === void 0 ? void 0 : response.delay) {
|
|
621
623
|
return response;
|
|
622
624
|
}
|
|
625
|
+
else if (response === null || response === void 0 ? void 0 : response.error) {
|
|
626
|
+
console.warn(`Skipping attachment with ID ${attachment.id} due to error.`);
|
|
627
|
+
}
|
|
623
628
|
if (this.state.toDevRev) {
|
|
624
629
|
this.state.toDevRev.attachmentsMetadata.lastProcessed += 1;
|
|
625
630
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devrev/ts-adaas",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
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"
|