@devrev/airsync-sdk 2.0.0-beta.1 → 2.0.0-beta.10
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 +7 -21
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +6 -7
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +4 -3
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +69 -61
- package/dist/common/constants.d.ts +15 -12
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +20 -34
- package/dist/common/helpers.d.ts +3 -27
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +6 -36
- package/dist/http/{axios-client-internal.d.ts → client.d.ts} +1 -1
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/{axios-client-internal.js → client.js} +7 -4
- package/dist/http/errors.d.ts +8 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +31 -0
- package/dist/index.d.ts +30 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -28
- package/dist/logger/logger.d.ts +13 -70
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +4 -7
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +67 -92
- package/dist/mappers/mappers.d.ts +10 -43
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.d.ts +173 -0
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -0
- package/dist/mappers/{mappers.interface.js → mappers.interfaces.js} +1 -10
- package/dist/mappers/mappers.js +32 -46
- package/dist/multithreading/adapters/base-adapter.d.ts +39 -0
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/base-adapter.js +212 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts +49 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/extraction-adapter.js +375 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts +26 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts +12 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/{worker-adapter/worker-adapter.helpers.js → adapters/loading-adapter.helpers.js} +2 -12
- package/dist/multithreading/adapters/loading-adapter.js +279 -0
- package/dist/multithreading/emit.d.ts +11 -0
- package/dist/multithreading/emit.d.ts.map +1 -0
- package/dist/multithreading/emit.js +25 -0
- package/dist/multithreading/process-task.d.ts +6 -1
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +120 -82
- package/dist/multithreading/spawn/spawn.d.ts +10 -11
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts +12 -11
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +142 -77
- package/dist/multithreading/spawn/spawn.js +59 -75
- package/dist/multithreading/worker.js +16 -5
- package/dist/repo/repo.d.ts +14 -5
- package/dist/repo/repo.d.ts.map +1 -1
- package/dist/repo/repo.helpers.d.ts +6 -0
- package/dist/repo/repo.helpers.d.ts.map +1 -0
- package/dist/repo/repo.helpers.js +16 -0
- package/dist/repo/repo.interfaces.d.ts +11 -20
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +36 -22
- package/dist/state/base-state.d.ts +58 -0
- package/dist/state/base-state.d.ts.map +1 -0
- package/dist/state/base-state.js +242 -0
- package/dist/state/extraction-state.d.ts +14 -0
- package/dist/state/extraction-state.d.ts.map +1 -0
- package/dist/state/extraction-state.js +140 -0
- package/dist/state/install-initial-domain-mapping.d.ts +4 -0
- package/dist/state/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/{common → state}/install-initial-domain-mapping.js +5 -7
- package/dist/state/loading-state.d.ts +8 -0
- package/dist/state/loading-state.d.ts.map +1 -0
- package/dist/state/loading-state.js +29 -0
- package/dist/state/state.d.ts +3 -29
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.interfaces.d.ts +31 -12
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +17 -1
- package/dist/state/state.js +9 -164
- package/dist/state/time-value-resolver.d.ts +17 -0
- package/dist/state/time-value-resolver.d.ts.map +1 -0
- package/dist/state/time-value-resolver.js +110 -0
- package/dist/testing/mock-event.d.ts +10 -0
- package/dist/testing/mock-event.d.ts.map +1 -0
- package/dist/testing/mock-event.js +96 -0
- package/dist/testing/mock-server.d.ts +31 -0
- package/dist/testing/mock-server.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.d.ts +54 -0
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.js +4 -0
- package/dist/testing/mock-server.js +297 -0
- package/dist/testing/test-adapters.d.ts +22 -0
- package/dist/testing/test-adapters.d.ts.map +1 -0
- package/dist/testing/test-adapters.js +32 -0
- package/dist/types/common.d.ts +4 -37
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +2 -17
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +28 -0
- package/dist/types/external-domain-metadata.d.ts +40 -162
- package/dist/types/external-domain-metadata.d.ts.map +1 -1
- package/dist/types/extraction.d.ts +135 -278
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +46 -133
- package/dist/types/loading.d.ts +15 -55
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +1 -23
- package/dist/types/workers.d.ts +70 -103
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +1 -6
- package/dist/uploader/uploader.d.ts +10 -61
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.d.ts +7 -27
- package/dist/uploader/uploader.helpers.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.js +80 -30
- package/dist/uploader/uploader.interfaces.d.ts +19 -54
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -1
- package/dist/uploader/uploader.interfaces.js +8 -0
- package/dist/uploader/uploader.js +72 -124
- package/docs/MIGRATION.md +696 -0
- package/package.json +35 -22
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +0 -2
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +0 -1
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +0 -321
- package/dist/common/control-protocol.d.ts +0 -10
- package/dist/common/control-protocol.d.ts.map +0 -1
- package/dist/common/control-protocol.js +0 -31
- package/dist/common/errors.d.ts +0 -6
- package/dist/common/errors.d.ts.map +0 -1
- package/dist/common/errors.js +0 -4
- package/dist/common/event-type-translation.d.ts +0 -24
- package/dist/common/event-type-translation.d.ts.map +0 -1
- package/dist/common/event-type-translation.js +0 -117
- package/dist/common/install-initial-domain-mapping.d.ts +0 -4
- package/dist/common/install-initial-domain-mapping.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.d.ts +0 -2
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.js +0 -208
- package/dist/deprecated/adapter/index.d.ts +0 -62
- package/dist/deprecated/adapter/index.d.ts.map +0 -1
- package/dist/deprecated/adapter/index.js +0 -151
- package/dist/deprecated/common/helpers.d.ts +0 -7
- package/dist/deprecated/common/helpers.d.ts.map +0 -1
- package/dist/deprecated/common/helpers.js +0 -47
- package/dist/deprecated/demo-extractor/external_domain_metadata.json +0 -38
- package/dist/deprecated/demo-extractor/index.d.ts +0 -18
- package/dist/deprecated/demo-extractor/index.d.ts.map +0 -1
- package/dist/deprecated/demo-extractor/index.js +0 -161
- package/dist/deprecated/http/client.d.ts +0 -22
- package/dist/deprecated/http/client.d.ts.map +0 -1
- package/dist/deprecated/http/client.js +0 -161
- package/dist/deprecated/uploader/index.d.ts +0 -35
- package/dist/deprecated/uploader/index.d.ts.map +0 -1
- package/dist/deprecated/uploader/index.js +0 -161
- package/dist/http/axios-client-internal.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.d.ts +0 -2
- package/dist/http/axios-client-internal.test.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.js +0 -154
- package/dist/http/axios-client.d.ts +0 -27
- package/dist/http/axios-client.d.ts.map +0 -1
- package/dist/http/axios-client.js +0 -57
- package/dist/http/constants.d.ts +0 -4
- package/dist/http/constants.d.ts.map +0 -1
- package/dist/http/constants.js +0 -6
- package/dist/http/index.d.ts +0 -3
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -18
- package/dist/http/types.d.ts +0 -17
- package/dist/http/types.d.ts.map +0 -1
- package/dist/http/types.js +0 -2
- package/dist/logger/logger.constants.d.ts +0 -6
- package/dist/logger/logger.constants.d.ts.map +0 -1
- package/dist/logger/logger.constants.js +0 -13
- package/dist/logger/logger.context.d.ts +0 -58
- package/dist/logger/logger.context.d.ts.map +0 -1
- package/dist/logger/logger.context.js +0 -86
- package/dist/logger/logger.test.d.ts +0 -2
- package/dist/logger/logger.test.d.ts.map +0 -1
- package/dist/logger/logger.test.js +0 -490
- package/dist/mappers/mappers.interface.d.ts +0 -294
- package/dist/mappers/mappers.interface.d.ts.map +0 -1
- package/dist/mappers/mappers.test.d.ts +0 -2
- package/dist/mappers/mappers.test.d.ts.map +0 -1
- package/dist/mappers/mappers.test.js +0 -107
- package/dist/multithreading/create-worker.test.d.ts +0 -2
- package/dist/multithreading/create-worker.test.d.ts.map +0 -1
- package/dist/multithreading/create-worker.test.js +0 -89
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +0 -2
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/spawn/spawn.helpers.test.js +0 -293
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +0 -127
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +0 -91
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +0 -22
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +0 -514
- package/dist/multithreading/worker-adapter/worker-adapter.js +0 -745
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.test.js +0 -483
- package/dist/repo/repo.test.d.ts +0 -2
- package/dist/repo/repo.test.d.ts.map +0 -1
- package/dist/repo/repo.test.js +0 -131
- package/dist/state/state.test.d.ts +0 -2
- package/dist/state/state.test.d.ts.map +0 -1
- package/dist/state/state.test.js +0 -224
- package/dist/types/extraction.test.d.ts +0 -2
- package/dist/types/extraction.test.d.ts.map +0 -1
- package/dist/types/extraction.test.js +0 -70
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/uploader/uploader.helpers.test.d.ts +0 -2
- package/dist/uploader/uploader.helpers.test.d.ts.map +0 -1
- package/dist/uploader/uploader.helpers.test.js +0 -267
- package/dist/uploader/uploader.test.d.ts +0 -2
- package/dist/uploader/uploader.test.d.ts.map +0 -1
- package/dist/uploader/uploader.test.js +0 -589
package/README.md
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
# AirSync SDK
|
|
2
2
|
|
|
3
|
-
[](https://coveralls.io/github/devrev/adaas-sdk?branch=main)
|
|
4
4
|
|
|
5
|
-
|
|
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
|
|
5
|
+
TypeScript SDK for building AirSync snap-ins (connectors) that sync data between external systems and DevRev. It handles the AirSync control protocol for you: worker threads, timeouts, state, artifact uploads, attachment streaming and loading.
|
|
18
6
|
|
|
19
7
|
## Installation
|
|
20
8
|
|
|
21
9
|
```bash
|
|
22
|
-
npm install @devrev/airsync-sdk
|
|
10
|
+
npm install @devrev/airsync-sdk
|
|
23
11
|
```
|
|
24
12
|
|
|
25
|
-
##
|
|
26
|
-
|
|
27
|
-
See [CHANGELOG.md](./CHANGELOG.md) for release notes and migration guides.
|
|
28
|
-
|
|
29
|
-
## Reference
|
|
13
|
+
## Documentation
|
|
30
14
|
|
|
31
|
-
|
|
15
|
+
- [Architecture](docs/ARCHITECTURE.md): how the SDK works and how it talks to the AirSync platform.
|
|
16
|
+
- [Migration from v1](docs/MIGRATION.md): moving from `@devrev/ts-adaas` to `@devrev/airsync-sdk`.
|
|
17
|
+
- [Contributing](docs/CONTRIBUTING.md): workflow, versioning and testing conventions.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProcessAttachmentReturnType } from '../types';
|
|
1
|
+
import { ProcessAttachmentReturnType } from '../types/extraction';
|
|
2
2
|
import { AttachmentsStreamingPoolParams } from './attachments-streaming-pool.interfaces';
|
|
3
3
|
export declare class AttachmentsStreamingPool<ConnectorState> {
|
|
4
4
|
private adapter;
|
|
@@ -9,14 +9,13 @@ export declare class AttachmentsStreamingPool<ConnectorState> {
|
|
|
9
9
|
private totalProcessedCount;
|
|
10
10
|
private readonly PROGRESS_REPORT_INTERVAL;
|
|
11
11
|
constructor({ adapter, attachments, batchSize, stream, }: AttachmentsStreamingPoolParams<ConnectorState>);
|
|
12
|
-
private
|
|
12
|
+
private recordProcessedAttachment;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @param attachments - The attachments list to migrate (either string[] or ProcessedAttachment[])
|
|
17
|
-
* @returns Migrated array of ProcessedAttachment objects, or empty array if input is invalid
|
|
14
|
+
* Backfills `status` on entries recorded before the field existed (those
|
|
15
|
+
* only ever held successes); state from >= v1.15.2 needs no shape migration.
|
|
18
16
|
*/
|
|
19
|
-
private
|
|
17
|
+
private backfillProcessedAttachmentStatus;
|
|
18
|
+
private updateProgress;
|
|
20
19
|
streamAll(): Promise<ProcessAttachmentReturnType>;
|
|
21
20
|
startPoolStreaming(): Promise<void>;
|
|
22
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachments-streaming-pool.d.ts","sourceRoot":"","sources":["../../src/attachments-streaming/attachments-streaming-pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"attachments-streaming-pool.d.ts","sourceRoot":"","sources":["../../src/attachments-streaming/attachments-streaming-pool.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAEzF,qBAAa,wBAAwB,CAAC,cAAc;IAClD,OAAO,CAAC,OAAO,CAAoC;IACnD,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;IAQjD,OAAO,CAAC,yBAAyB;IAyBjC;;;OAGG;IACH,OAAO,CAAC,iCAAiC;YAS3B,cAAc;IAUtB,SAAS,IAAI,OAAO,CAAC,2BAA2B,CAAC;IA6CjD,kBAAkB;CAwFzB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ExtractionAdapter } from '../multithreading/adapters/extraction-adapter';
|
|
2
|
+
import { NormalizedAttachment } from '../repo/repo.interfaces';
|
|
3
|
+
import { ExternalSystemAttachmentStreamingFunction } from '../types/extraction';
|
|
3
4
|
export interface AttachmentsStreamingPoolParams<ConnectorState> {
|
|
4
|
-
adapter:
|
|
5
|
+
adapter: ExtractionAdapter<ConnectorState>;
|
|
5
6
|
attachments: NormalizedAttachment[];
|
|
6
7
|
batchSize?: number;
|
|
7
8
|
stream: ExternalSystemAttachmentStreamingFunction;
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"attachments-streaming-pool.interfaces.d.ts","sourceRoot":"","sources":["../../src/attachments-streaming/attachments-streaming-pool.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,yCAAyC,EAAE,MAAM,qBAAqB,CAAC;AAEhF,MAAM,WAAW,8BAA8B,CAAC,cAAc;IAC5D,OAAO,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;IAC3C,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,yCAAyC,CAAC;CACnD"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AttachmentsStreamingPool = void 0;
|
|
4
4
|
const helpers_1 = require("../common/helpers");
|
|
5
|
+
const state_interfaces_1 = require("../state/state.interfaces");
|
|
5
6
|
class AttachmentsStreamingPool {
|
|
6
7
|
constructor({ adapter, attachments, batchSize = 10, stream, }) {
|
|
7
8
|
this.totalProcessedCount = 0;
|
|
@@ -12,112 +13,119 @@ class AttachmentsStreamingPool {
|
|
|
12
13
|
this.delay = undefined;
|
|
13
14
|
this.stream = stream;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
recordProcessedAttachment(attachment, status) {
|
|
17
|
+
var _a;
|
|
18
|
+
const attachmentsMetadata = (_a = this.adapter.sdkState.toDevRev) === null || _a === void 0 ? void 0 : _a.attachmentsMetadata;
|
|
19
|
+
if (!(attachmentsMetadata === null || attachmentsMetadata === void 0 ? void 0 : attachmentsMetadata.lastProcessedAttachmentsIdsList)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const processedAttachmentsIdsList = attachmentsMetadata.lastProcessedAttachmentsIdsList;
|
|
23
|
+
const alreadyRecorded = processedAttachmentsIdsList.some((it) => it.id === attachment.id && it.parent_id === attachment.parent_id);
|
|
24
|
+
if (!alreadyRecorded) {
|
|
25
|
+
processedAttachmentsIdsList.push({
|
|
26
|
+
id: attachment.id,
|
|
27
|
+
parent_id: attachment.parent_id,
|
|
28
|
+
status,
|
|
29
|
+
});
|
|
21
30
|
}
|
|
22
31
|
}
|
|
23
32
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @param attachments - The attachments list to migrate (either string[] or ProcessedAttachment[])
|
|
27
|
-
* @returns Migrated array of ProcessedAttachment objects, or empty array if input is invalid
|
|
33
|
+
* Backfills `status` on entries recorded before the field existed (those
|
|
34
|
+
* only ever held successes); state from >= v1.15.2 needs no shape migration.
|
|
28
35
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
id: it,
|
|
43
|
-
parent_id: '',
|
|
44
|
-
}));
|
|
36
|
+
backfillProcessedAttachmentStatus(attachments) {
|
|
37
|
+
return attachments.map((it) => {
|
|
38
|
+
var _a;
|
|
39
|
+
return (Object.assign(Object.assign({}, it), { status: (_a = it.status) !== null && _a !== void 0 ? _a : state_interfaces_1.ProcessedAttachmentStatus.Success }));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async updateProgress() {
|
|
43
|
+
this.totalProcessedCount++;
|
|
44
|
+
if (this.totalProcessedCount % this.PROGRESS_REPORT_INTERVAL === 0) {
|
|
45
|
+
console.info(`Processed ${this.totalProcessedCount} attachments so far.`);
|
|
46
|
+
// Let a pending soft-timeout message (WorkerMessageExit) be delivered so
|
|
47
|
+
// adapter.isTimeout can flip before the next batch is processed.
|
|
48
|
+
await (0, helpers_1.yieldToEventLoop)();
|
|
45
49
|
}
|
|
46
|
-
return [];
|
|
47
50
|
}
|
|
48
51
|
async streamAll() {
|
|
49
52
|
console.log(`Starting download of ${this.attachments.length} attachments, streaming ${this.batchSize} at once.`);
|
|
50
|
-
if (!this.adapter.
|
|
51
|
-
const
|
|
52
|
-
console.error(
|
|
53
|
-
return { error };
|
|
53
|
+
if (!this.adapter.sdkState.toDevRev) {
|
|
54
|
+
const message = 'toDevRev state is not initialized';
|
|
55
|
+
console.error(message);
|
|
56
|
+
return { status: 'error', error: { message } };
|
|
54
57
|
}
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
if (!this.adapter.state.toDevRev.attachmentsMetadata
|
|
58
|
+
// Attachments processed (successfully or not) by a previous, possibly incomplete, run.
|
|
59
|
+
if (!this.adapter.sdkState.toDevRev.attachmentsMetadata
|
|
58
60
|
.lastProcessedAttachmentsIdsList) {
|
|
59
|
-
this.adapter.
|
|
61
|
+
this.adapter.sdkState.toDevRev.attachmentsMetadata.lastProcessedAttachmentsIdsList =
|
|
60
62
|
[];
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.migrateProcessedAttachments(this.adapter.state.toDevRev.attachmentsMetadata
|
|
64
|
+
this.adapter.sdkState.toDevRev.attachmentsMetadata.lastProcessedAttachmentsIdsList =
|
|
65
|
+
this.backfillProcessedAttachmentStatus(this.adapter.sdkState.toDevRev.attachmentsMetadata
|
|
65
66
|
.lastProcessedAttachmentsIdsList);
|
|
66
|
-
// Start initial batch of promises up to batchSize limit
|
|
67
67
|
const initialBatchSize = Math.min(this.batchSize, this.attachments.length);
|
|
68
68
|
const initialPromises = [];
|
|
69
69
|
for (let i = 0; i < initialBatchSize; i++) {
|
|
70
70
|
initialPromises.push(this.startPoolStreaming());
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
await Promise.race([
|
|
73
|
+
Promise.all(initialPromises),
|
|
74
|
+
this.adapter.timeoutSignal,
|
|
75
|
+
]);
|
|
74
76
|
if (this.delay) {
|
|
75
|
-
return { delay: this.delay };
|
|
77
|
+
return { status: 'delay', delaySeconds: this.delay };
|
|
76
78
|
}
|
|
77
|
-
return {};
|
|
79
|
+
return { status: 'success' };
|
|
78
80
|
}
|
|
79
81
|
async startPoolStreaming() {
|
|
80
|
-
var _a
|
|
81
|
-
// Process attachments until the attachments array is empty
|
|
82
|
+
var _a;
|
|
82
83
|
while (this.attachments.length > 0) {
|
|
83
|
-
// If delay is set, stop streaming
|
|
84
84
|
if (this.delay) {
|
|
85
85
|
break;
|
|
86
86
|
}
|
|
87
|
-
// If timeout is set, stop streaming
|
|
88
87
|
if (this.adapter.isTimeout) {
|
|
89
88
|
console.log('Timeout detected while streaming attachments. Stopping streaming.');
|
|
90
89
|
break;
|
|
91
90
|
}
|
|
92
|
-
// Check if we can process next attachment
|
|
93
91
|
const attachment = this.attachments.shift();
|
|
94
92
|
if (!attachment) {
|
|
95
|
-
break;
|
|
93
|
+
break;
|
|
96
94
|
}
|
|
97
|
-
if (this.adapter.
|
|
98
|
-
((_a = this.adapter.
|
|
99
|
-
continue; //
|
|
95
|
+
if (this.adapter.sdkState.toDevRev &&
|
|
96
|
+
((_a = this.adapter.sdkState.toDevRev.attachmentsMetadata.lastProcessedAttachmentsIdsList) === null || _a === void 0 ? void 0 : _a.some((it) => it.id == attachment.id && it.parent_id == attachment.parent_id))) {
|
|
97
|
+
continue; // Already processed in a previous run
|
|
100
98
|
}
|
|
101
99
|
try {
|
|
102
100
|
const response = await this.adapter.processAttachment(attachment, this.stream);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.delay = response.delay; // Set the delay for rate limiting
|
|
101
|
+
if (response.status === 'delay') {
|
|
102
|
+
this.delay = response.delaySeconds;
|
|
106
103
|
return;
|
|
107
104
|
}
|
|
108
|
-
if (response ===
|
|
109
|
-
|
|
105
|
+
if (response.status === 'error') {
|
|
106
|
+
const fileExtension = attachment.file_name.split('.').pop() || '';
|
|
107
|
+
const fileSizeInfo = response.error.fileSize
|
|
108
|
+
? `and size ${response.error.fileSize} bytes `
|
|
109
|
+
: '';
|
|
110
|
+
const contentTypeInfo = attachment.content_type
|
|
111
|
+
? `and content_type ${attachment.content_type} `
|
|
112
|
+
: '';
|
|
113
|
+
console.warn(`Skipping attachment with ID ${attachment.id} with extension ${fileExtension} ${fileSizeInfo}${contentTypeInfo}due to error returned by the stream function`, response.error.message);
|
|
114
|
+
this.recordProcessedAttachment(attachment, state_interfaces_1.ProcessedAttachmentStatus.Failed);
|
|
110
115
|
await this.updateProgress();
|
|
111
116
|
continue;
|
|
112
117
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
(_d = this.adapter.state.toDevRev) === null || _d === void 0 ? void 0 : _d.attachmentsMetadata.lastProcessedAttachmentsIdsList.push({ id: attachment.id, parent_id: attachment.parent_id });
|
|
118
|
+
if (!this.adapter.isTimeout) {
|
|
119
|
+
this.recordProcessedAttachment(attachment, state_interfaces_1.ProcessedAttachmentStatus.Success);
|
|
116
120
|
}
|
|
117
121
|
await this.updateProgress();
|
|
118
122
|
}
|
|
119
123
|
catch (error) {
|
|
120
|
-
|
|
124
|
+
const fileExtension = attachment.file_name.split('.').pop() || '';
|
|
125
|
+
const contentTypeInfo = attachment.content_type
|
|
126
|
+
? ` and content_type ${attachment.content_type}`
|
|
127
|
+
: '';
|
|
128
|
+
console.warn(`Skipping attachment with ID ${attachment.id} with extension ${fileExtension}${contentTypeInfo} due to error in processAttachment function`, error);
|
|
121
129
|
await this.updateProgress();
|
|
122
130
|
}
|
|
123
131
|
}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
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
2
|
export declare const STATELESS_EXTRACTION_EVENT_TYPES: EventType[];
|
|
6
3
|
export declare const STATELESS_LOADING_EVENT_TYPES: EventType[];
|
|
7
4
|
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
5
|
export declare const ARTIFACT_BATCH_SIZE = 2000;
|
|
12
6
|
export declare const MAX_DEVREV_ARTIFACT_SIZE: number;
|
|
13
7
|
export declare const MAX_DEVREV_FILENAME_LENGTH = 256;
|
|
14
8
|
export declare const MAX_DEVREV_FILENAME_EXTENSION_LENGTH = 20;
|
|
15
|
-
export declare const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
export declare const MAX_EVENT_SIZE_BYTES = 200000;
|
|
10
|
+
export declare const EVENT_SIZE_THRESHOLD_BYTES: number;
|
|
11
|
+
export declare const SSOR_ATTACHMENT: string;
|
|
12
|
+
export declare const UNKNOWN_EVENT_TYPE = "UNKNOWN_EVENT_TYPE";
|
|
13
|
+
export declare enum AirSyncDefaultItemTypes {
|
|
14
|
+
EXTERNAL_DOMAIN_METADATA = "external_domain_metadata",
|
|
15
|
+
ATTACHMENTS = "attachments",
|
|
16
|
+
EXTERNAL_SYNC_UNITS = "external_sync_units"
|
|
17
|
+
}
|
|
20
18
|
export declare const LIBRARY_VERSION: any;
|
|
21
19
|
export declare const DEFAULT_LAMBDA_TIMEOUT: number;
|
|
22
20
|
export declare const HARD_TIMEOUT_MULTIPLIER = 1.3;
|
|
23
21
|
export declare const MEMORY_LOG_INTERVAL: number;
|
|
24
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Sentinel for an unbounded extraction timestamp (TimeValueType.UNBOUNDED),
|
|
24
|
+
* stored as workersOldest. The Unix epoch guarantees no real timestamp can be
|
|
25
|
+
* earlier, so subsequent syncs cannot accidentally overwrite the boundary.
|
|
26
|
+
*/
|
|
27
|
+
export declare const UNBOUNDED_DATE_TIME_VALUE = "1970-01-01T00:00:00.000Z";
|
|
25
28
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIhD,eAAO,MAAM,gCAAgC,aAI5C,CAAC;AAEF,eAAO,MAAM,6BAA6B,aAGzC,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAGjC,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;AAGvD,eAAO,MAAM,oBAAoB,SAAU,CAAC;AAE5C,eAAO,MAAM,0BAA0B,QAEtC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,MAA0B,CAAC;AACzD,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,oBAAY,uBAAuB;IACjC,wBAAwB,6BAA6B;IACrD,WAAW,gBAAgB;IAC3B,mBAAmB,wBAAwB;CAC5C;AAED,eAAO,MAAM,eAAe,KAAsB,CAAC;AAEnD,eAAO,MAAM,sBAAsB,QAAiB,CAAC;AACrD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,6BAA6B,CAAC"}
|
package/dist/common/constants.js
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UNBOUNDED_DATE_TIME_VALUE = exports.MEMORY_LOG_INTERVAL = exports.HARD_TIMEOUT_MULTIPLIER = exports.DEFAULT_LAMBDA_TIMEOUT = exports.LIBRARY_VERSION = exports.AirSyncDefaultItemTypes = exports.UNKNOWN_EVENT_TYPE = exports.SSOR_ATTACHMENT = exports.EVENT_SIZE_THRESHOLD_BYTES = exports.MAX_EVENT_SIZE_BYTES = exports.MAX_DEVREV_FILENAME_EXTENSION_LENGTH = exports.MAX_DEVREV_FILENAME_LENGTH = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.STATELESS_EVENT_TYPES = exports.STATELESS_LOADING_EVENT_TYPES = exports.STATELESS_EXTRACTION_EVENT_TYPES = void 0;
|
|
4
4
|
const extraction_1 = require("../types/extraction");
|
|
5
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
6
|
exports.STATELESS_EXTRACTION_EVENT_TYPES = [
|
|
27
7
|
extraction_1.EventType.StartExtractingExternalSyncUnits,
|
|
28
8
|
extraction_1.EventType.StartDeletingExtractorState,
|
|
@@ -36,23 +16,29 @@ exports.STATELESS_EVENT_TYPES = [
|
|
|
36
16
|
...exports.STATELESS_EXTRACTION_EVENT_TYPES,
|
|
37
17
|
...exports.STATELESS_LOADING_EVENT_TYPES,
|
|
38
18
|
];
|
|
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
19
|
exports.ARTIFACT_BATCH_SIZE = 2000;
|
|
46
20
|
exports.MAX_DEVREV_ARTIFACT_SIZE = 2 * 1024 * 1024 * 1024; // 2GB
|
|
47
21
|
exports.MAX_DEVREV_FILENAME_LENGTH = 256;
|
|
48
|
-
exports.MAX_DEVREV_FILENAME_EXTENSION_LENGTH = 20;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
22
|
+
exports.MAX_DEVREV_FILENAME_EXTENSION_LENGTH = 20;
|
|
23
|
+
// Max SQS message size is 250KB, we want to leave some room for the other data in the message
|
|
24
|
+
exports.MAX_EVENT_SIZE_BYTES = 200000;
|
|
25
|
+
// We want to leave some room for the other data in the message and process the rest of queued messages
|
|
26
|
+
exports.EVENT_SIZE_THRESHOLD_BYTES = Math.floor(exports.MAX_EVENT_SIZE_BYTES * 0.8);
|
|
27
|
+
exports.SSOR_ATTACHMENT = 'ssor_attachment';
|
|
28
|
+
exports.UNKNOWN_EVENT_TYPE = 'UNKNOWN_EVENT_TYPE';
|
|
29
|
+
var AirSyncDefaultItemTypes;
|
|
30
|
+
(function (AirSyncDefaultItemTypes) {
|
|
31
|
+
AirSyncDefaultItemTypes["EXTERNAL_DOMAIN_METADATA"] = "external_domain_metadata";
|
|
32
|
+
AirSyncDefaultItemTypes["ATTACHMENTS"] = "attachments";
|
|
33
|
+
AirSyncDefaultItemTypes["EXTERNAL_SYNC_UNITS"] = "external_sync_units";
|
|
34
|
+
})(AirSyncDefaultItemTypes || (exports.AirSyncDefaultItemTypes = AirSyncDefaultItemTypes = {}));
|
|
54
35
|
exports.LIBRARY_VERSION = (0, helpers_1.getLibraryVersion)();
|
|
55
36
|
exports.DEFAULT_LAMBDA_TIMEOUT = 10 * 60 * 1000; // 10 minutes
|
|
56
37
|
exports.HARD_TIMEOUT_MULTIPLIER = 1.3;
|
|
57
38
|
exports.MEMORY_LOG_INTERVAL = 30 * 1000; // 30 seconds
|
|
58
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Sentinel for an unbounded extraction timestamp (TimeValueType.UNBOUNDED),
|
|
41
|
+
* stored as workersOldest. The Unix epoch guarantees no real timestamp can be
|
|
42
|
+
* earlier, so subsequent syncs cannot accidentally overwrite the boundary.
|
|
43
|
+
*/
|
|
44
|
+
exports.UNBOUNDED_DATE_TIME_VALUE = '1970-01-01T00:00:00.000Z';
|
package/dist/common/helpers.d.ts
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the library version from the package.json file.
|
|
3
|
-
* @returns {string} The library version
|
|
4
|
-
*/
|
|
5
1
|
export declare function getLibraryVersion(): any;
|
|
6
|
-
/**
|
|
7
|
-
* Sleeps for a given number of milliseconds.
|
|
8
|
-
* @param {number} ms - The number of milliseconds to sleep
|
|
9
|
-
* @returns {Promise<void>} A promise that resolves after the given number of milliseconds
|
|
10
|
-
*/
|
|
11
2
|
export declare function sleep(ms: number): Promise<unknown>;
|
|
12
3
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @returns {string} The truncated filename
|
|
16
|
-
*/
|
|
17
|
-
export declare function truncateFilename(filename: string): string;
|
|
18
|
-
/**
|
|
19
|
-
* MemoryInfo is an interface that represents the memory usage information.
|
|
20
|
-
* @interface MemoryInfo
|
|
21
|
-
* @property {string} rssUsedMB - The RSS used in MB
|
|
22
|
-
* @property {string} rssUsedPercent - The RSS used percentage
|
|
23
|
-
* @property {string} heapUsedPercent - The heap used percentage
|
|
24
|
-
* @property {string} externalMB - The external memory used in MB
|
|
25
|
-
* @property {string} arrayBuffersMB - The array buffers memory used in MB
|
|
26
|
-
* @property {string} formattedMessage - The formatted message
|
|
4
|
+
* Yields once to the event loop so pending events (e.g. worker messages) can
|
|
5
|
+
* be delivered before continuing.
|
|
27
6
|
*/
|
|
7
|
+
export declare function yieldToEventLoop(): Promise<void>;
|
|
28
8
|
export interface MemoryInfo {
|
|
29
9
|
rssUsedMB: string;
|
|
30
10
|
rssUsedPercent: string;
|
|
@@ -33,9 +13,5 @@ export interface MemoryInfo {
|
|
|
33
13
|
arrayBuffersMB: string;
|
|
34
14
|
formattedMessage: string;
|
|
35
15
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Gets the memory usage information.
|
|
38
|
-
* @returns {MemoryInfo} The memory usage information
|
|
39
|
-
*/
|
|
40
16
|
export declare function getMemoryUsage(): MemoryInfo;
|
|
41
17
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/common/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/common/helpers.ts"],"names":[],"mappings":"AAIA,wBAAgB,iBAAiB,QAchC;AAED,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAErC;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEtD;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,cAAc,IAAI,UAAU,CA+C3C"}
|
package/dist/common/helpers.js
CHANGED
|
@@ -35,16 +35,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.getLibraryVersion = getLibraryVersion;
|
|
37
37
|
exports.sleep = sleep;
|
|
38
|
-
exports.
|
|
38
|
+
exports.yieldToEventLoop = yieldToEventLoop;
|
|
39
39
|
exports.getMemoryUsage = getMemoryUsage;
|
|
40
40
|
const fs_1 = require("fs");
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
42
|
const v8 = __importStar(require("v8"));
|
|
43
|
-
const constants_1 = require("./constants");
|
|
44
|
-
/**
|
|
45
|
-
* Gets the library version from the package.json file.
|
|
46
|
-
* @returns {string} The library version
|
|
47
|
-
*/
|
|
48
43
|
function getLibraryVersion() {
|
|
49
44
|
var _a;
|
|
50
45
|
try {
|
|
@@ -55,41 +50,20 @@ function getLibraryVersion() {
|
|
|
55
50
|
return '';
|
|
56
51
|
}
|
|
57
52
|
catch (error) {
|
|
58
|
-
console.error('Error reading
|
|
53
|
+
console.error('Error reading SDK version from package.json', error);
|
|
59
54
|
return '';
|
|
60
55
|
}
|
|
61
56
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Sleeps for a given number of milliseconds.
|
|
64
|
-
* @param {number} ms - The number of milliseconds to sleep
|
|
65
|
-
* @returns {Promise<void>} A promise that resolves after the given number of milliseconds
|
|
66
|
-
*/
|
|
67
57
|
async function sleep(ms) {
|
|
68
|
-
console.log(`Sleeping for ${ms}ms.`);
|
|
69
58
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
70
59
|
}
|
|
71
60
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @returns {string} The truncated filename
|
|
61
|
+
* Yields once to the event loop so pending events (e.g. worker messages) can
|
|
62
|
+
* be delivered before continuing.
|
|
75
63
|
*/
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
if (filename.length <= constants_1.MAX_DEVREV_FILENAME_LENGTH) {
|
|
79
|
-
return filename;
|
|
80
|
-
}
|
|
81
|
-
console.warn(`Filename length exceeds the maximum limit of ${constants_1.MAX_DEVREV_FILENAME_LENGTH} characters. Truncating filename.`);
|
|
82
|
-
const extension = filename.slice(-constants_1.MAX_DEVREV_FILENAME_EXTENSION_LENGTH);
|
|
83
|
-
// Calculate how many characters are available for the name part after accounting for the extension and "..."
|
|
84
|
-
const availableNameLength = constants_1.MAX_DEVREV_FILENAME_LENGTH - constants_1.MAX_DEVREV_FILENAME_EXTENSION_LENGTH - 3; // -3 for "..."
|
|
85
|
-
// Truncate the name part and add an ellipsis
|
|
86
|
-
const truncatedFilename = filename.slice(0, availableNameLength);
|
|
87
|
-
return `${truncatedFilename}...${extension}`;
|
|
64
|
+
async function yieldToEventLoop() {
|
|
65
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
88
66
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets the memory usage information.
|
|
91
|
-
* @returns {MemoryInfo} The memory usage information
|
|
92
|
-
*/
|
|
93
67
|
function getMemoryUsage() {
|
|
94
68
|
try {
|
|
95
69
|
const memUsage = process.memoryUsage();
|
|
@@ -97,16 +71,12 @@ function getMemoryUsage() {
|
|
|
97
71
|
const rssUsedMB = memUsage.rss / 1024 / 1024;
|
|
98
72
|
const heapLimitMB = heapStats.heap_size_limit / 1024 / 1024;
|
|
99
73
|
const effectiveMemoryLimitMB = heapLimitMB;
|
|
100
|
-
// Calculate heap values for consistent format
|
|
101
74
|
const heapUsedMB = heapStats.used_heap_size / 1024 / 1024;
|
|
102
75
|
const heapTotalMB = heapStats.heap_size_limit / 1024 / 1024;
|
|
103
|
-
// Calculate external and buffer values (critical for detecting stream leaks)
|
|
104
76
|
const externalMB = memUsage.external / 1024 / 1024;
|
|
105
77
|
const arrayBuffersMB = memUsage.arrayBuffers / 1024 / 1024;
|
|
106
|
-
// Critical percentages for OOM detection
|
|
107
78
|
const rssUsedPercent = ((rssUsedMB / effectiveMemoryLimitMB) * 100).toFixed(2) + '%';
|
|
108
79
|
const heapUsedPercent = ((heapStats.used_heap_size / heapStats.heap_size_limit) * 100).toFixed(2) + '%';
|
|
109
|
-
// Detailed message showing RSS breakdown for leak detection
|
|
110
80
|
const formattedMessage = `Memory: RSS ${rssUsedMB.toFixed(2)}/${effectiveMemoryLimitMB.toFixed(2)}MB (${rssUsedPercent}) [Heap ${heapUsedMB.toFixed(2)}/${heapTotalMB.toFixed(2)}MB (${heapUsedPercent}) + External ${externalMB.toFixed(2)}MB + Buffers ${arrayBuffersMB.toFixed(2)}MB].`;
|
|
111
81
|
return {
|
|
112
82
|
rssUsedMB: rssUsedMB.toFixed(2),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,WAAW,+BAEf,CAAC;AAmFH,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -34,11 +34,10 @@ exports.axiosClient = axiosClient;
|
|
|
34
34
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
35
35
|
const retryAfter = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['retry-after']) ||
|
|
36
36
|
((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d['Retry-After']);
|
|
37
|
-
// 5xx errors
|
|
38
37
|
if (((_e = error.response) === null || _e === void 0 ? void 0 : _e.status) && error.response.status >= 500) {
|
|
39
38
|
return true;
|
|
40
39
|
}
|
|
41
|
-
// 429
|
|
40
|
+
// 429 only when a valid non-negative Retry-After header is present
|
|
42
41
|
else if (((_f = error.response) === null || _f === void 0 ? void 0 : _f.status) &&
|
|
43
42
|
error.response.status === 429 &&
|
|
44
43
|
retryAfter &&
|
|
@@ -46,12 +45,16 @@ exports.axiosClient = axiosClient;
|
|
|
46
45
|
Number(retryAfter) >= 0) {
|
|
47
46
|
return true;
|
|
48
47
|
}
|
|
49
|
-
// Network errors for idempotent requests
|
|
48
|
+
// Network errors for idempotent requests; 429 already handled above
|
|
50
49
|
else if (axios_retry_1.default.isNetworkOrIdempotentRequestError(error) &&
|
|
51
50
|
((_g = error.response) === null || _g === void 0 ? void 0 : _g.status) !== 429) {
|
|
52
51
|
return true;
|
|
53
52
|
}
|
|
54
|
-
//
|
|
53
|
+
// axios-retry excludes ECONNABORTED (client-side timeout only, never a
|
|
54
|
+
// server response) from isNetworkError, so handle it here separately.
|
|
55
|
+
else if (error.code === 'ECONNABORTED') {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
55
58
|
else {
|
|
56
59
|
return false;
|
|
57
60
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Rejection for failed SDK calls to the DevRev platform. */
|
|
2
|
+
export declare class AirSyncHttpError extends Error {
|
|
3
|
+
readonly status?: number;
|
|
4
|
+
constructor(message: string, status?: number);
|
|
5
|
+
}
|
|
6
|
+
export declare function toAirSyncHttpError(error: unknown): AirSyncHttpError;
|
|
7
|
+
export declare function isNotFound(error: unknown): boolean;
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAK7C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAgBnE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAElD"}
|