@devrev/airsync-sdk 2.0.0-beta.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 +31 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +16 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +9 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.js +2 -0
- package/dist/attachments-streaming/attachments-streaming-pool.js +97 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +2 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +1 -0
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +267 -0
- package/dist/common/constants.d.ts +25 -0
- package/dist/common/constants.d.ts.map +1 -0
- package/dist/common/constants.js +58 -0
- package/dist/common/control-protocol.d.ts +10 -0
- package/dist/common/control-protocol.d.ts.map +1 -0
- package/dist/common/control-protocol.js +31 -0
- package/dist/common/errors.d.ts +6 -0
- package/dist/common/errors.d.ts.map +1 -0
- package/dist/common/errors.js +4 -0
- package/dist/common/event-type-translation.d.ts +24 -0
- package/dist/common/event-type-translation.d.ts.map +1 -0
- package/dist/common/event-type-translation.js +117 -0
- package/dist/common/helpers.d.ts +41 -0
- package/dist/common/helpers.d.ts.map +1 -0
- package/dist/common/helpers.js +124 -0
- package/dist/common/install-initial-domain-mapping.d.ts +4 -0
- package/dist/common/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/common/install-initial-domain-mapping.js +58 -0
- package/dist/common/install-initial-domain-mapping.test.d.ts +2 -0
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +1 -0
- package/dist/common/install-initial-domain-mapping.test.js +207 -0
- package/dist/deprecated/adapter/index.d.ts +62 -0
- package/dist/deprecated/adapter/index.d.ts.map +1 -0
- package/dist/deprecated/adapter/index.js +151 -0
- package/dist/deprecated/common/helpers.d.ts +7 -0
- package/dist/deprecated/common/helpers.d.ts.map +1 -0
- 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 +18 -0
- package/dist/deprecated/demo-extractor/index.d.ts.map +1 -0
- package/dist/deprecated/demo-extractor/index.js +161 -0
- package/dist/deprecated/http/client.d.ts +22 -0
- package/dist/deprecated/http/client.d.ts.map +1 -0
- package/dist/deprecated/http/client.js +161 -0
- package/dist/deprecated/uploader/index.d.ts +35 -0
- package/dist/deprecated/uploader/index.d.ts.map +1 -0
- package/dist/deprecated/uploader/index.js +161 -0
- package/dist/http/axios-client-internal.d.ts +3 -0
- package/dist/http/axios-client-internal.d.ts.map +1 -0
- package/dist/http/axios-client-internal.js +66 -0
- package/dist/http/axios-client-internal.test.d.ts +2 -0
- package/dist/http/axios-client-internal.test.d.ts.map +1 -0
- package/dist/http/axios-client-internal.test.js +154 -0
- package/dist/http/axios-client.d.ts +27 -0
- package/dist/http/axios-client.d.ts.map +1 -0
- package/dist/http/axios-client.js +57 -0
- package/dist/http/constants.d.ts +4 -0
- package/dist/http/constants.d.ts.map +1 -0
- package/dist/http/constants.js +6 -0
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +18 -0
- package/dist/http/types.d.ts +17 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +2 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/logger/logger.constants.d.ts +6 -0
- package/dist/logger/logger.constants.d.ts.map +1 -0
- package/dist/logger/logger.constants.js +13 -0
- package/dist/logger/logger.context.d.ts +58 -0
- package/dist/logger/logger.context.d.ts.map +1 -0
- package/dist/logger/logger.context.js +86 -0
- package/dist/logger/logger.d.ts +89 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.interfaces.d.ts +43 -0
- package/dist/logger/logger.interfaces.d.ts.map +1 -0
- package/dist/logger/logger.interfaces.js +9 -0
- package/dist/logger/logger.js +196 -0
- package/dist/logger/logger.test.d.ts +2 -0
- package/dist/logger/logger.test.d.ts.map +1 -0
- package/dist/logger/logger.test.js +490 -0
- package/dist/mappers/mappers.d.ts +52 -0
- package/dist/mappers/mappers.d.ts.map +1 -0
- package/dist/mappers/mappers.interface.d.ts +294 -0
- package/dist/mappers/mappers.interface.d.ts.map +1 -0
- package/dist/mappers/mappers.interface.js +48 -0
- package/dist/mappers/mappers.js +83 -0
- package/dist/mappers/mappers.test.d.ts +2 -0
- package/dist/mappers/mappers.test.d.ts.map +1 -0
- package/dist/mappers/mappers.test.js +107 -0
- package/dist/multithreading/create-worker.d.ts +5 -0
- package/dist/multithreading/create-worker.d.ts.map +1 -0
- package/dist/multithreading/create-worker.js +28 -0
- package/dist/multithreading/create-worker.test.d.ts +2 -0
- package/dist/multithreading/create-worker.test.d.ts.map +1 -0
- package/dist/multithreading/create-worker.test.js +89 -0
- package/dist/multithreading/process-task.d.ts +3 -0
- package/dist/multithreading/process-task.d.ts.map +1 -0
- package/dist/multithreading/process-task.js +58 -0
- package/dist/multithreading/spawn/spawn.d.ts +30 -0
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.d.ts +21 -0
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.js +114 -0
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +2 -0
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.helpers.test.js +293 -0
- package/dist/multithreading/spawn/spawn.js +249 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +127 -0
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +91 -0
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +22 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.js +64 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +514 -0
- package/dist/multithreading/worker-adapter/worker-adapter.js +747 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.test.js +483 -0
- package/dist/multithreading/worker.d.ts +2 -0
- package/dist/multithreading/worker.d.ts.map +1 -0
- package/dist/multithreading/worker.js +9 -0
- package/dist/repo/repo.d.ts +18 -0
- package/dist/repo/repo.d.ts.map +1 -0
- package/dist/repo/repo.interfaces.d.ts +46 -0
- package/dist/repo/repo.interfaces.d.ts.map +1 -0
- package/dist/repo/repo.interfaces.js +2 -0
- package/dist/repo/repo.js +75 -0
- package/dist/repo/repo.test.d.ts +2 -0
- package/dist/repo/repo.test.d.ts.map +1 -0
- package/dist/repo/repo.test.js +131 -0
- package/dist/state/state.d.ts +30 -0
- package/dist/state/state.d.ts.map +1 -0
- package/dist/state/state.interfaces.d.ts +51 -0
- package/dist/state/state.interfaces.d.ts.map +1 -0
- package/dist/state/state.interfaces.js +21 -0
- package/dist/state/state.js +166 -0
- package/dist/state/state.test.d.ts +2 -0
- package/dist/state/state.test.d.ts.map +1 -0
- package/dist/state/state.test.js +224 -0
- package/dist/types/common.d.ts +50 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +25 -0
- package/dist/types/extraction.d.ts +417 -0
- package/dist/types/extraction.d.ts.map +1 -0
- package/dist/types/extraction.js +170 -0
- package/dist/types/extraction.test.d.ts +2 -0
- package/dist/types/extraction.test.d.ts.map +1 -0
- package/dist/types/extraction.test.js +70 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/loading.d.ts +147 -0
- package/dist/types/loading.d.ts.map +1 -0
- package/dist/types/loading.js +48 -0
- package/dist/types/workers.d.ts +161 -0
- package/dist/types/workers.d.ts.map +1 -0
- package/dist/types/workers.js +22 -0
- package/dist/uploader/uploader.d.ts +92 -0
- package/dist/uploader/uploader.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.d.ts +33 -0
- package/dist/uploader/uploader.helpers.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.js +139 -0
- package/dist/uploader/uploader.helpers.test.d.ts +2 -0
- package/dist/uploader/uploader.helpers.test.d.ts.map +1 -0
- package/dist/uploader/uploader.helpers.test.js +267 -0
- package/dist/uploader/uploader.interfaces.d.ts +95 -0
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -0
- package/dist/uploader/uploader.interfaces.js +2 -0
- package/dist/uploader/uploader.js +305 -0
- package/dist/uploader/uploader.test.d.ts +2 -0
- package/dist/uploader/uploader.test.d.ts.map +1 -0
- package/dist/uploader/uploader.test.js +589 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# AirSync SDK
|
|
2
|
+
|
|
3
|
+
[](https://coveralls.io/github/devrev/adaas-sdk?branch=v2)
|
|
4
|
+
|
|
5
|
+
> **Note:** This is the v2 beta of the AirSync SDK (formerly Airdrop SDK). The package has been renamed from `@devrev/ts-adaas` to `@devrev/airsync-sdk`.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The AirSync SDK for TypeScript helps developers build snap-ins that integrate with DevRev's AirSync platform. This SDK simplifies the workflow for handling data extraction and loading, event-driven actions, state management, and artifact handling.
|
|
10
|
+
|
|
11
|
+
It provides features such as:
|
|
12
|
+
|
|
13
|
+
- Type Definitions: Structured types for AirSync control protocol
|
|
14
|
+
- Event Management: Easily emit events for different extraction or loading phases
|
|
15
|
+
- State Handling: Update and access state in real-time within tasks
|
|
16
|
+
- Artifact Management: Supports batched storage of artifacts
|
|
17
|
+
- Error & Timeout Support: Error handling and timeout management for long-running tasks
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @devrev/airsync-sdk@beta
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Changelog
|
|
26
|
+
|
|
27
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release notes and migration guides.
|
|
28
|
+
|
|
29
|
+
## Reference
|
|
30
|
+
|
|
31
|
+
Please refer to the [REFERENCE.md](./REFERENCE.md) file for more information on the types, interfaces and functions used in the library.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ProcessAttachmentReturnType } from '../types';
|
|
2
|
+
import { AttachmentsStreamingPoolParams } from './attachments-streaming-pool.interfaces';
|
|
3
|
+
export declare class AttachmentsStreamingPool<ConnectorState> {
|
|
4
|
+
private adapter;
|
|
5
|
+
private attachments;
|
|
6
|
+
private batchSize;
|
|
7
|
+
private delay;
|
|
8
|
+
private stream;
|
|
9
|
+
private totalProcessedCount;
|
|
10
|
+
private readonly PROGRESS_REPORT_INTERVAL;
|
|
11
|
+
constructor({ adapter, attachments, batchSize, stream, }: AttachmentsStreamingPoolParams<ConnectorState>);
|
|
12
|
+
private updateProgress;
|
|
13
|
+
streamAll(): Promise<ProcessAttachmentReturnType>;
|
|
14
|
+
startPoolStreaming(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=attachments-streaming-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments-streaming-pool.d.ts","sourceRoot":"","sources":["../../src/attachments-streaming/attachments-streaming-pool.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAEzF,qBAAa,wBAAwB,CAAC,cAAc;IAClD,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,MAAM,CAA4C;IAE1D,OAAO,CAAC,mBAAmB,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAM;gBAEnC,EACV,OAAO,EACP,WAAW,EACX,SAAc,EACd,MAAM,GACP,EAAE,8BAA8B,CAAC,cAAc,CAAC;YAQnC,cAAc;IAStB,SAAS,IAAI,OAAO,CAAC,2BAA2B,CAAC;IAuCjD,kBAAkB;CA0EzB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExternalSystemAttachmentStreamingFunction, NormalizedAttachment } from '../types';
|
|
2
|
+
import { WorkerAdapter } from '../multithreading/worker-adapter/worker-adapter';
|
|
3
|
+
export interface AttachmentsStreamingPoolParams<ConnectorState> {
|
|
4
|
+
adapter: WorkerAdapter<ConnectorState>;
|
|
5
|
+
attachments: NormalizedAttachment[];
|
|
6
|
+
batchSize?: number;
|
|
7
|
+
stream: ExternalSystemAttachmentStreamingFunction;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=attachments-streaming-pool.interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments-streaming-pool.interfaces.d.ts","sourceRoot":"","sources":["../../src/attachments-streaming/attachments-streaming-pool.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EACzC,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,MAAM,WAAW,8BAA8B,CAAC,cAAc;IAC5D,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,yCAAyC,CAAC;CACnD"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AttachmentsStreamingPool = void 0;
|
|
4
|
+
const helpers_1 = require("../common/helpers");
|
|
5
|
+
class AttachmentsStreamingPool {
|
|
6
|
+
constructor({ adapter, attachments, batchSize = 10, stream, }) {
|
|
7
|
+
this.totalProcessedCount = 0;
|
|
8
|
+
this.PROGRESS_REPORT_INTERVAL = 50;
|
|
9
|
+
this.adapter = adapter;
|
|
10
|
+
this.attachments = [...attachments]; // Create a copy we can mutate
|
|
11
|
+
this.batchSize = batchSize;
|
|
12
|
+
this.delay = undefined;
|
|
13
|
+
this.stream = stream;
|
|
14
|
+
}
|
|
15
|
+
async updateProgress() {
|
|
16
|
+
this.totalProcessedCount++;
|
|
17
|
+
if (this.totalProcessedCount % this.PROGRESS_REPORT_INTERVAL === 0) {
|
|
18
|
+
console.info(`Processed ${this.totalProcessedCount} attachments so far.`);
|
|
19
|
+
// Sleep for 100ms to avoid blocking the event loop
|
|
20
|
+
await (0, helpers_1.sleep)(100);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async streamAll() {
|
|
24
|
+
console.log(`Starting download of ${this.attachments.length} attachments, streaming ${this.batchSize} at once.`);
|
|
25
|
+
if (!this.adapter.state.toDevRev) {
|
|
26
|
+
const error = new Error('toDevRev state is not initialized');
|
|
27
|
+
console.error(error);
|
|
28
|
+
return { error };
|
|
29
|
+
}
|
|
30
|
+
// Get the list of successfully processed attachments in previous (possibly incomplete) batch extraction.
|
|
31
|
+
// If no such list exists, create an empty one.
|
|
32
|
+
if (!this.adapter.state.toDevRev.attachmentsMetadata
|
|
33
|
+
.lastProcessedAttachmentsIdsList) {
|
|
34
|
+
this.adapter.state.toDevRev.attachmentsMetadata.lastProcessedAttachmentsIdsList =
|
|
35
|
+
[];
|
|
36
|
+
}
|
|
37
|
+
// Start initial batch of promises up to batchSize limit
|
|
38
|
+
const initialBatchSize = Math.min(this.batchSize, this.attachments.length);
|
|
39
|
+
const initialPromises = [];
|
|
40
|
+
for (let i = 0; i < initialBatchSize; i++) {
|
|
41
|
+
initialPromises.push(this.startPoolStreaming());
|
|
42
|
+
}
|
|
43
|
+
// Wait for all promises to complete
|
|
44
|
+
await Promise.all(initialPromises);
|
|
45
|
+
if (this.delay) {
|
|
46
|
+
return { delay: this.delay };
|
|
47
|
+
}
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
async startPoolStreaming() {
|
|
51
|
+
var _a, _b, _c, _d;
|
|
52
|
+
// Process attachments until the attachments array is empty
|
|
53
|
+
while (this.attachments.length > 0) {
|
|
54
|
+
// If delay is set, stop streaming
|
|
55
|
+
if (this.delay) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
// If timeout is set, stop streaming
|
|
59
|
+
if (this.adapter.isTimeout) {
|
|
60
|
+
console.log('Timeout detected while streaming attachments. Stopping streaming.');
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
// Check if we can process next attachment
|
|
64
|
+
const attachment = this.attachments.shift();
|
|
65
|
+
if (!attachment) {
|
|
66
|
+
break; // Exit if no more attachments
|
|
67
|
+
}
|
|
68
|
+
if (this.adapter.state.toDevRev &&
|
|
69
|
+
((_a = this.adapter.state.toDevRev.attachmentsMetadata.lastProcessedAttachmentsIdsList) === null || _a === void 0 ? void 0 : _a.includes(attachment.id))) {
|
|
70
|
+
continue; // Skip if the attachment ID is already processed
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const response = await this.adapter.processAttachment(attachment, this.stream);
|
|
74
|
+
// Check if rate limit was hit
|
|
75
|
+
if (response === null || response === void 0 ? void 0 : response.delay) {
|
|
76
|
+
this.delay = response.delay; // Set the delay for rate limiting
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (response === null || response === void 0 ? void 0 : response.error) {
|
|
80
|
+
console.warn(`Skipping attachment with ID ${attachment.id} due to error returned by the stream function`, response.error);
|
|
81
|
+
await this.updateProgress();
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// No rate limiting, process normally
|
|
85
|
+
if ((_c = (_b = this.adapter.state.toDevRev) === null || _b === void 0 ? void 0 : _b.attachmentsMetadata) === null || _c === void 0 ? void 0 : _c.lastProcessedAttachmentsIdsList) {
|
|
86
|
+
(_d = this.adapter.state.toDevRev) === null || _d === void 0 ? void 0 : _d.attachmentsMetadata.lastProcessedAttachmentsIdsList.push(attachment.id);
|
|
87
|
+
}
|
|
88
|
+
await this.updateProgress();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.warn(`Skipping attachment with ID ${attachment.id} due to error in processAttachment function`, error);
|
|
92
|
+
await this.updateProgress();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.AttachmentsStreamingPool = AttachmentsStreamingPool;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments-streaming-pool.test.d.ts","sourceRoot":"","sources":["../../src/attachments-streaming/attachments-streaming-pool.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const attachments_streaming_pool_1 = require("./attachments-streaming-pool");
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
describe(attachments_streaming_pool_1.AttachmentsStreamingPool.name, () => {
|
|
6
|
+
let mockAdapter;
|
|
7
|
+
let mockStream;
|
|
8
|
+
let mockAttachments;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
// Create mock adapter
|
|
11
|
+
mockAdapter = {
|
|
12
|
+
state: {
|
|
13
|
+
attachments: { completed: false },
|
|
14
|
+
toDevRev: {
|
|
15
|
+
attachmentsMetadata: {
|
|
16
|
+
lastProcessedAttachmentsIdsList: [],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
processAttachment: jest
|
|
21
|
+
.fn()
|
|
22
|
+
.mockResolvedValue({}),
|
|
23
|
+
};
|
|
24
|
+
// Create mock stream function
|
|
25
|
+
mockStream = jest.fn().mockResolvedValue({ success: true });
|
|
26
|
+
// Create mock attachments
|
|
27
|
+
mockAttachments = [
|
|
28
|
+
{
|
|
29
|
+
id: 'attachment-1',
|
|
30
|
+
url: 'https://example.com/file1.pdf',
|
|
31
|
+
file_name: 'file1.pdf',
|
|
32
|
+
parent_id: 'parent-1',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'attachment-2',
|
|
36
|
+
url: 'https://example.com/file2.jpg',
|
|
37
|
+
file_name: 'file2.jpg',
|
|
38
|
+
parent_id: 'parent-2',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'attachment-3',
|
|
42
|
+
url: 'https://example.com/file3.doc',
|
|
43
|
+
file_name: 'file3.doc',
|
|
44
|
+
parent_id: 'parent-3',
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
// Mock console methods
|
|
48
|
+
jest.spyOn(console, 'log').mockImplementation();
|
|
49
|
+
jest.spyOn(console, 'error').mockImplementation();
|
|
50
|
+
jest.spyOn(console, 'warn').mockImplementation();
|
|
51
|
+
});
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
jest.restoreAllMocks();
|
|
55
|
+
});
|
|
56
|
+
describe(attachments_streaming_pool_1.AttachmentsStreamingPool.prototype.constructor.name, () => {
|
|
57
|
+
it('should initialize with default values', () => {
|
|
58
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
59
|
+
adapter: mockAdapter,
|
|
60
|
+
attachments: mockAttachments,
|
|
61
|
+
stream: mockStream,
|
|
62
|
+
});
|
|
63
|
+
expect(pool).toBeDefined();
|
|
64
|
+
expect(pool['adapter']).toBe(mockAdapter);
|
|
65
|
+
expect(pool['attachments']).toEqual(mockAttachments);
|
|
66
|
+
expect(pool['batchSize']).toBe(10);
|
|
67
|
+
expect(pool['stream']).toBe(mockStream);
|
|
68
|
+
});
|
|
69
|
+
it('should initialize with custom batch size', () => {
|
|
70
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
71
|
+
adapter: mockAdapter,
|
|
72
|
+
attachments: mockAttachments,
|
|
73
|
+
batchSize: 5,
|
|
74
|
+
stream: mockStream,
|
|
75
|
+
});
|
|
76
|
+
expect(pool['batchSize']).toBe(5);
|
|
77
|
+
});
|
|
78
|
+
it('should create a copy of attachments array', () => {
|
|
79
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
80
|
+
adapter: mockAdapter,
|
|
81
|
+
attachments: mockAttachments,
|
|
82
|
+
stream: mockStream,
|
|
83
|
+
});
|
|
84
|
+
expect(pool['attachments']).toEqual(mockAttachments);
|
|
85
|
+
expect(pool['attachments']).not.toBe(mockAttachments); // Different reference
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe(attachments_streaming_pool_1.AttachmentsStreamingPool.prototype.streamAll.name, () => {
|
|
89
|
+
it('should initialize lastProcessedAttachmentsIdsList if it does not exist', async () => {
|
|
90
|
+
mockAdapter.state.toDevRev.attachmentsMetadata.lastProcessedAttachmentsIdsList =
|
|
91
|
+
undefined;
|
|
92
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
93
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
94
|
+
adapter: mockAdapter,
|
|
95
|
+
attachments: mockAttachments,
|
|
96
|
+
stream: mockStream,
|
|
97
|
+
});
|
|
98
|
+
// Mock startPoolStreaming to avoid actual processing
|
|
99
|
+
jest
|
|
100
|
+
.spyOn(pool, 'startPoolStreaming')
|
|
101
|
+
.mockResolvedValue(undefined);
|
|
102
|
+
await pool.streamAll();
|
|
103
|
+
expect(mockAdapter.state.toDevRev.attachmentsMetadata
|
|
104
|
+
.lastProcessedAttachmentsIdsList).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
it('should process all attachments successfully', async () => {
|
|
107
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
108
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
109
|
+
adapter: mockAdapter,
|
|
110
|
+
attachments: mockAttachments,
|
|
111
|
+
stream: mockStream,
|
|
112
|
+
});
|
|
113
|
+
const result = await pool.streamAll();
|
|
114
|
+
expect(result).toEqual({});
|
|
115
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledTimes(3);
|
|
116
|
+
});
|
|
117
|
+
it('should handle empty attachments array', async () => {
|
|
118
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
119
|
+
adapter: mockAdapter,
|
|
120
|
+
attachments: [],
|
|
121
|
+
stream: mockStream,
|
|
122
|
+
});
|
|
123
|
+
const result = await pool.streamAll();
|
|
124
|
+
expect(result).toEqual({});
|
|
125
|
+
expect(mockAdapter.processAttachment).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
it('should return delay when rate limit is hit', async () => {
|
|
128
|
+
const delayResponse = { delay: 5000 };
|
|
129
|
+
mockAdapter.processAttachment.mockResolvedValue(delayResponse);
|
|
130
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
131
|
+
adapter: mockAdapter,
|
|
132
|
+
attachments: mockAttachments,
|
|
133
|
+
stream: mockStream,
|
|
134
|
+
});
|
|
135
|
+
const result = await pool.streamAll();
|
|
136
|
+
expect(result).toEqual({ delay: 5000 });
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe(attachments_streaming_pool_1.AttachmentsStreamingPool.prototype.startPoolStreaming.name, () => {
|
|
140
|
+
it('should skip already processed attachments', async () => {
|
|
141
|
+
mockAdapter.state.toDevRev.attachmentsMetadata.lastProcessedAttachmentsIdsList =
|
|
142
|
+
['attachment-1'];
|
|
143
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
144
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
145
|
+
adapter: mockAdapter,
|
|
146
|
+
attachments: mockAttachments,
|
|
147
|
+
stream: mockStream,
|
|
148
|
+
});
|
|
149
|
+
await pool.streamAll();
|
|
150
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledTimes(2); // Only 2 out of 3
|
|
151
|
+
});
|
|
152
|
+
it('should add successfully processed attachment IDs to the list', async () => {
|
|
153
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
154
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
155
|
+
adapter: mockAdapter,
|
|
156
|
+
attachments: mockAttachments,
|
|
157
|
+
stream: mockStream,
|
|
158
|
+
});
|
|
159
|
+
await pool.streamAll();
|
|
160
|
+
expect(mockAdapter.state.toDevRev.attachmentsMetadata
|
|
161
|
+
.lastProcessedAttachmentsIdsList).toEqual(['attachment-1', 'attachment-2', 'attachment-3']);
|
|
162
|
+
});
|
|
163
|
+
it('should handle processing errors gracefully', async () => {
|
|
164
|
+
const error = new Error('Processing failed');
|
|
165
|
+
mockAdapter.processAttachment
|
|
166
|
+
.mockResolvedValueOnce({}) // First attachment succeeds
|
|
167
|
+
.mockRejectedValueOnce(error) // Second attachment fails
|
|
168
|
+
.mockResolvedValueOnce({}); // Third attachment succeeds
|
|
169
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
170
|
+
adapter: mockAdapter,
|
|
171
|
+
attachments: mockAttachments,
|
|
172
|
+
stream: mockStream,
|
|
173
|
+
});
|
|
174
|
+
await pool.streamAll();
|
|
175
|
+
expect(console.warn).toHaveBeenCalledWith('Skipping attachment with ID attachment-2 due to error in processAttachment function', error);
|
|
176
|
+
expect(mockAdapter.state.toDevRev.attachmentsMetadata
|
|
177
|
+
.lastProcessedAttachmentsIdsList).toEqual(['attachment-1', 'attachment-3']);
|
|
178
|
+
});
|
|
179
|
+
it('should stop processing when rate limit delay is encountered', async () => {
|
|
180
|
+
mockAdapter.processAttachment
|
|
181
|
+
.mockResolvedValueOnce({}) // First attachment succeeds
|
|
182
|
+
.mockResolvedValueOnce({ delay: 5000 }) // Second attachment triggers rate limit
|
|
183
|
+
.mockResolvedValueOnce({}); // Third attachment succeeds
|
|
184
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
185
|
+
adapter: mockAdapter,
|
|
186
|
+
attachments: mockAttachments,
|
|
187
|
+
stream: mockStream,
|
|
188
|
+
});
|
|
189
|
+
await pool.streamAll();
|
|
190
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledTimes(3);
|
|
191
|
+
expect(mockAdapter.state.toDevRev.attachmentsMetadata
|
|
192
|
+
.lastProcessedAttachmentsIdsList).toEqual(['attachment-1', 'attachment-3']);
|
|
193
|
+
});
|
|
194
|
+
it('should pass correct parameters to processAttachment', async () => {
|
|
195
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
196
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
197
|
+
adapter: mockAdapter,
|
|
198
|
+
attachments: [mockAttachments[0]],
|
|
199
|
+
stream: mockStream,
|
|
200
|
+
});
|
|
201
|
+
await pool.streamAll();
|
|
202
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledWith(mockAttachments[0], mockStream);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
it('[edge] should handle single attachment', async () => {
|
|
206
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
207
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
208
|
+
adapter: mockAdapter,
|
|
209
|
+
attachments: [mockAttachments[0]],
|
|
210
|
+
stream: mockStream,
|
|
211
|
+
});
|
|
212
|
+
const result = await pool.streamAll();
|
|
213
|
+
expect(result).toEqual({});
|
|
214
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledTimes(1);
|
|
215
|
+
});
|
|
216
|
+
it('[edge] should handle batch size larger than attachments array', async () => {
|
|
217
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
218
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
219
|
+
adapter: mockAdapter,
|
|
220
|
+
attachments: mockAttachments,
|
|
221
|
+
batchSize: 100,
|
|
222
|
+
stream: mockStream,
|
|
223
|
+
});
|
|
224
|
+
await pool.streamAll();
|
|
225
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledTimes(3);
|
|
226
|
+
});
|
|
227
|
+
it('[edge] should handle batch size of 1', async () => {
|
|
228
|
+
mockAdapter.processAttachment.mockResolvedValue({});
|
|
229
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
230
|
+
adapter: mockAdapter,
|
|
231
|
+
attachments: mockAttachments,
|
|
232
|
+
batchSize: 1,
|
|
233
|
+
stream: mockStream,
|
|
234
|
+
});
|
|
235
|
+
await pool.streamAll();
|
|
236
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledTimes(3);
|
|
237
|
+
});
|
|
238
|
+
describe('concurrency behavior', () => {
|
|
239
|
+
it('should process attachments concurrently within batch size', async () => {
|
|
240
|
+
let processCallCount = 0;
|
|
241
|
+
const processPromises = [];
|
|
242
|
+
mockAdapter.processAttachment.mockImplementation(async () => {
|
|
243
|
+
const promise = new Promise((resolve) => {
|
|
244
|
+
setTimeout(() => {
|
|
245
|
+
processCallCount++;
|
|
246
|
+
resolve({});
|
|
247
|
+
}, 100);
|
|
248
|
+
});
|
|
249
|
+
processPromises.push(promise);
|
|
250
|
+
return promise;
|
|
251
|
+
});
|
|
252
|
+
const pool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
|
|
253
|
+
adapter: mockAdapter,
|
|
254
|
+
attachments: mockAttachments,
|
|
255
|
+
batchSize: 2,
|
|
256
|
+
stream: mockStream,
|
|
257
|
+
});
|
|
258
|
+
const startTime = Date.now();
|
|
259
|
+
await pool.streamAll();
|
|
260
|
+
const endTime = Date.now();
|
|
261
|
+
expect(mockAdapter.processAttachment).toHaveBeenCalledTimes(3);
|
|
262
|
+
expect(processCallCount).toBe(3);
|
|
263
|
+
// Should complete in roughly 200ms (2 batches of 100ms each) rather than 300ms (sequential)
|
|
264
|
+
expect(endTime - startTime).toBeLessThan(250);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EventType } from '../types/extraction';
|
|
2
|
+
export declare const ALLOWED_EXTRACTION_EVENT_TYPES: EventType[];
|
|
3
|
+
export declare const ALLOWED_LOADING_EVENT_TYPES: EventType[];
|
|
4
|
+
export declare const ALLOWED_EVENT_TYPES: EventType[];
|
|
5
|
+
export declare const STATELESS_EXTRACTION_EVENT_TYPES: EventType[];
|
|
6
|
+
export declare const STATELESS_LOADING_EVENT_TYPES: EventType[];
|
|
7
|
+
export declare const STATELESS_EVENT_TYPES: EventType[];
|
|
8
|
+
export declare const STATEFUL_EXTRACTION_EVENT_TYPES: EventType[];
|
|
9
|
+
export declare const STATEFUL_LOADING_EVENT_TYPES: EventType[];
|
|
10
|
+
export declare const STATEFUL_EVENT_TYPES: EventType[];
|
|
11
|
+
export declare const ARTIFACT_BATCH_SIZE = 2000;
|
|
12
|
+
export declare const MAX_DEVREV_ARTIFACT_SIZE: number;
|
|
13
|
+
export declare const MAX_DEVREV_FILENAME_LENGTH = 256;
|
|
14
|
+
export declare const MAX_DEVREV_FILENAME_EXTENSION_LENGTH = 20;
|
|
15
|
+
export declare const AIRDROP_DEFAULT_ITEM_TYPES: {
|
|
16
|
+
EXTERNAL_DOMAIN_METADATA: string;
|
|
17
|
+
ATTACHMENTS: string;
|
|
18
|
+
SSOR_ATTACHMENT: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const LIBRARY_VERSION: any;
|
|
21
|
+
export declare const DEFAULT_LAMBDA_TIMEOUT: number;
|
|
22
|
+
export declare const HARD_TIMEOUT_MULTIPLIER = 1.3;
|
|
23
|
+
export declare const MEMORY_LOG_INTERVAL: number;
|
|
24
|
+
export declare const DEFAULT_SLEEP_DELAY_MS: number;
|
|
25
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,eAAO,MAAM,8BAA8B,aAS1C,CAAC;AAEF,eAAO,MAAM,2BAA2B,aAKvC,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAG/B,CAAC;AAEF,eAAO,MAAM,gCAAgC,aAI5C,CAAC;AAEF,eAAO,MAAM,6BAA6B,aAGzC,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAGjC,CAAC;AAEF,eAAO,MAAM,+BAA+B,aAGzC,CAAC;AAEJ,eAAO,MAAM,4BAA4B,aAExC,CAAC;AAEF,eAAO,MAAM,oBAAoB,aAGhC,CAAC;AAEF,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,eAAO,MAAM,wBAAwB,QAAyB,CAAC;AAC/D,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,oCAAoC,KAAK,CAAC;AAEvD,eAAO,MAAM,0BAA0B;;;;CAItC,CAAC;AAEF,eAAO,MAAM,eAAe,KAAsB,CAAC;AAEnD,eAAO,MAAM,sBAAsB,QAAiB,CAAC;AACrD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAE7C,eAAO,MAAM,sBAAsB,QAAgB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_SLEEP_DELAY_MS = exports.MEMORY_LOG_INTERVAL = exports.HARD_TIMEOUT_MULTIPLIER = exports.DEFAULT_LAMBDA_TIMEOUT = exports.LIBRARY_VERSION = exports.AIRDROP_DEFAULT_ITEM_TYPES = exports.MAX_DEVREV_FILENAME_EXTENSION_LENGTH = exports.MAX_DEVREV_FILENAME_LENGTH = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.STATEFUL_EVENT_TYPES = exports.STATEFUL_LOADING_EVENT_TYPES = exports.STATEFUL_EXTRACTION_EVENT_TYPES = exports.STATELESS_EVENT_TYPES = exports.STATELESS_LOADING_EVENT_TYPES = exports.STATELESS_EXTRACTION_EVENT_TYPES = exports.ALLOWED_EVENT_TYPES = exports.ALLOWED_LOADING_EVENT_TYPES = exports.ALLOWED_EXTRACTION_EVENT_TYPES = void 0;
|
|
4
|
+
const extraction_1 = require("../types/extraction");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
exports.ALLOWED_EXTRACTION_EVENT_TYPES = [
|
|
7
|
+
extraction_1.EventType.StartExtractingExternalSyncUnits,
|
|
8
|
+
extraction_1.EventType.StartExtractingMetadata,
|
|
9
|
+
extraction_1.EventType.StartExtractingData,
|
|
10
|
+
extraction_1.EventType.ContinueExtractingData,
|
|
11
|
+
extraction_1.EventType.StartDeletingExtractorState,
|
|
12
|
+
extraction_1.EventType.StartExtractingAttachments,
|
|
13
|
+
extraction_1.EventType.ContinueExtractingAttachments,
|
|
14
|
+
extraction_1.EventType.StartDeletingExtractorAttachmentsState,
|
|
15
|
+
];
|
|
16
|
+
exports.ALLOWED_LOADING_EVENT_TYPES = [
|
|
17
|
+
extraction_1.EventType.StartLoadingData,
|
|
18
|
+
extraction_1.EventType.ContinueLoadingData,
|
|
19
|
+
extraction_1.EventType.StartDeletingLoaderState,
|
|
20
|
+
extraction_1.EventType.StartDeletingLoaderAttachmentState,
|
|
21
|
+
];
|
|
22
|
+
exports.ALLOWED_EVENT_TYPES = [
|
|
23
|
+
...exports.ALLOWED_EXTRACTION_EVENT_TYPES,
|
|
24
|
+
...exports.ALLOWED_LOADING_EVENT_TYPES,
|
|
25
|
+
];
|
|
26
|
+
exports.STATELESS_EXTRACTION_EVENT_TYPES = [
|
|
27
|
+
extraction_1.EventType.StartExtractingExternalSyncUnits,
|
|
28
|
+
extraction_1.EventType.StartDeletingExtractorState,
|
|
29
|
+
extraction_1.EventType.StartDeletingExtractorAttachmentsState,
|
|
30
|
+
];
|
|
31
|
+
exports.STATELESS_LOADING_EVENT_TYPES = [
|
|
32
|
+
extraction_1.EventType.StartDeletingLoaderState,
|
|
33
|
+
extraction_1.EventType.StartDeletingLoaderAttachmentState,
|
|
34
|
+
];
|
|
35
|
+
exports.STATELESS_EVENT_TYPES = [
|
|
36
|
+
...exports.STATELESS_EXTRACTION_EVENT_TYPES,
|
|
37
|
+
...exports.STATELESS_LOADING_EVENT_TYPES,
|
|
38
|
+
];
|
|
39
|
+
exports.STATEFUL_EXTRACTION_EVENT_TYPES = exports.ALLOWED_EXTRACTION_EVENT_TYPES.filter((eventType) => !exports.STATELESS_EXTRACTION_EVENT_TYPES.includes(eventType));
|
|
40
|
+
exports.STATEFUL_LOADING_EVENT_TYPES = exports.ALLOWED_LOADING_EVENT_TYPES.filter((eventType) => !exports.STATELESS_LOADING_EVENT_TYPES.includes(eventType));
|
|
41
|
+
exports.STATEFUL_EVENT_TYPES = [
|
|
42
|
+
...exports.STATEFUL_EXTRACTION_EVENT_TYPES,
|
|
43
|
+
...exports.STATEFUL_LOADING_EVENT_TYPES,
|
|
44
|
+
];
|
|
45
|
+
exports.ARTIFACT_BATCH_SIZE = 2000;
|
|
46
|
+
exports.MAX_DEVREV_ARTIFACT_SIZE = 2 * 1024 * 1024 * 1024; // 2GB
|
|
47
|
+
exports.MAX_DEVREV_FILENAME_LENGTH = 256;
|
|
48
|
+
exports.MAX_DEVREV_FILENAME_EXTENSION_LENGTH = 20; // 20 characters for the file extension
|
|
49
|
+
exports.AIRDROP_DEFAULT_ITEM_TYPES = {
|
|
50
|
+
EXTERNAL_DOMAIN_METADATA: 'external_domain_metadata',
|
|
51
|
+
ATTACHMENTS: 'attachments',
|
|
52
|
+
SSOR_ATTACHMENT: 'ssor_attachment',
|
|
53
|
+
};
|
|
54
|
+
exports.LIBRARY_VERSION = (0, helpers_1.getLibraryVersion)();
|
|
55
|
+
exports.DEFAULT_LAMBDA_TIMEOUT = 10 * 60 * 1000; // 10 minutes
|
|
56
|
+
exports.HARD_TIMEOUT_MULTIPLIER = 1.3;
|
|
57
|
+
exports.MEMORY_LOG_INTERVAL = 30 * 1000; // 30 seconds
|
|
58
|
+
exports.DEFAULT_SLEEP_DELAY_MS = 3 * 60 * 1000; // 3 minutes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { AirdropEvent, EventData, ExtractorEventType } from '../types/extraction';
|
|
3
|
+
import { LoaderEventType } from '../types/loading';
|
|
4
|
+
export interface EmitInterface {
|
|
5
|
+
event: AirdropEvent;
|
|
6
|
+
eventType: ExtractorEventType | LoaderEventType;
|
|
7
|
+
data?: EventData;
|
|
8
|
+
}
|
|
9
|
+
export declare const emit: ({ event, eventType, data, }: EmitInterface) => Promise<AxiosResponse>;
|
|
10
|
+
//# sourceMappingURL=control-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-protocol.d.ts","sourceRoot":"","sources":["../../src/common/control-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EACL,YAAY,EACZ,SAAS,EAET,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,kBAAkB,GAAG,eAAe,CAAC;IAChD,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,eAAO,MAAM,IAAI,GAAU,6BAIxB,aAAa,KAAG,OAAO,CAAC,aAAa,CAgCvC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emit = void 0;
|
|
4
|
+
const axios_client_internal_1 = require("../http/axios-client-internal");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const event_type_translation_1 = require("./event-type-translation");
|
|
7
|
+
const emit = async ({ event, eventType, data, }) => {
|
|
8
|
+
// Translate outgoing event type to ensure we always send new event types
|
|
9
|
+
// TODO: Remove when the old types are completely phased out
|
|
10
|
+
const translatedEventType = (0, event_type_translation_1.translateOutgoingEventType)(eventType);
|
|
11
|
+
const newEvent = {
|
|
12
|
+
event_type: translatedEventType,
|
|
13
|
+
event_context: event.payload.event_context,
|
|
14
|
+
event_data: Object.assign({}, data),
|
|
15
|
+
worker_metadata: {
|
|
16
|
+
adaas_library_version: constants_1.LIBRARY_VERSION,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
console.info('Emitting event', newEvent);
|
|
20
|
+
return axios_client_internal_1.axiosClient.post(event.payload.event_context.callback_url, Object.assign({}, newEvent), {
|
|
21
|
+
headers: {
|
|
22
|
+
Accept: 'application/json, text/plain, */*',
|
|
23
|
+
Authorization: event.context.secrets.service_account_token,
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
'X-DevRev-Client-Platform': event.payload.event_context.snap_in_slug,
|
|
26
|
+
'X-DevRev-Client-Id': event.payload.event_context.snap_in_version_id,
|
|
27
|
+
'X-DevRev-Client-Version': constants_1.LIBRARY_VERSION,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
exports.emit = emit;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const enum ExtractionCommonError {
|
|
2
|
+
EXTERNAL_SYNC_UNIT_DELETED = "ERROR_CODE=EXTERNAL_SYNC_UNIT_DELETED",
|
|
3
|
+
EXTERNAL_SYNC_UNIT_DEACTIVATED = "ERROR_CODE=EXTERNAL_SYNC_UNIT_DEACTIVATED",
|
|
4
|
+
USER_DELETED = "ERROR_CODE=USER_DELETED"
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/common/errors.ts"],"names":[],"mappings":"AAGA,0BAAkB,qBAAqB;IACrC,0BAA0B,0CAAgE;IAC1F,8BAA8B,8CAAoE;IAClG,YAAY,4BAAkD;CAC/D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventType, ExtractorEventType } from '../types/extraction';
|
|
2
|
+
import { LoaderEventType } from '../types/loading';
|
|
3
|
+
/**
|
|
4
|
+
* Maps old incoming event type strings to new EventType enum values.
|
|
5
|
+
* This ensures backwards compatibility when the platform sends old event types.
|
|
6
|
+
* @param eventTypeString The raw event type string from the platform
|
|
7
|
+
* @returns The translated EventType enum value
|
|
8
|
+
*/
|
|
9
|
+
export declare function translateIncomingEventType(eventTypeString: string): EventType;
|
|
10
|
+
/**
|
|
11
|
+
* Translates ExtractorEventType enum values by converting old enum members to new ones.
|
|
12
|
+
* Old enum members are deprecated and should be replaced with new ones.
|
|
13
|
+
*/
|
|
14
|
+
export declare function translateExtractorEventType(eventType: ExtractorEventType): ExtractorEventType;
|
|
15
|
+
/**
|
|
16
|
+
* Translates LoaderEventType enum values by converting old enum members to new ones.
|
|
17
|
+
* Old enum members are deprecated and should be replaced with new ones.
|
|
18
|
+
*/
|
|
19
|
+
export declare function translateLoaderEventType(eventType: LoaderEventType): LoaderEventType;
|
|
20
|
+
/**
|
|
21
|
+
* Translates any outgoing event type (Extractor or Loader) to ensure new event types are used.
|
|
22
|
+
*/
|
|
23
|
+
export declare function translateOutgoingEventType(eventType: ExtractorEventType | LoaderEventType): ExtractorEventType | LoaderEventType;
|
|
24
|
+
//# sourceMappingURL=event-type-translation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-type-translation.d.ts","sourceRoot":"","sources":["../../src/common/event-type-translation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAwD7E;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,kBAAkB,GAC5B,kBAAkB,CA0CpB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,eAAe,GACzB,eAAe,CAmBjB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,kBAAkB,GAAG,eAAe,GAC9C,kBAAkB,GAAG,eAAe,CAatC"}
|