@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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateIncomingEventType = translateIncomingEventType;
|
|
4
|
+
exports.translateExtractorEventType = translateExtractorEventType;
|
|
5
|
+
exports.translateLoaderEventType = translateLoaderEventType;
|
|
6
|
+
exports.translateOutgoingEventType = translateOutgoingEventType;
|
|
7
|
+
const extraction_1 = require("../types/extraction");
|
|
8
|
+
const loading_1 = require("../types/loading");
|
|
9
|
+
/**
|
|
10
|
+
* Maps old incoming event type strings to new EventType enum values.
|
|
11
|
+
* This ensures backwards compatibility when the platform sends old event types.
|
|
12
|
+
* @param eventTypeString The raw event type string from the platform
|
|
13
|
+
* @returns The translated EventType enum value
|
|
14
|
+
*/
|
|
15
|
+
function translateIncomingEventType(eventTypeString) {
|
|
16
|
+
// Create a reverse mapping from OLD string values to NEW enum member names
|
|
17
|
+
const eventTypeMap = {
|
|
18
|
+
// Old extraction event types from platform -> New enum members
|
|
19
|
+
[extraction_1.EventType.ExtractionExternalSyncUnitsStart]: extraction_1.EventType.StartExtractingExternalSyncUnits,
|
|
20
|
+
[extraction_1.EventType.ExtractionMetadataStart]: extraction_1.EventType.StartExtractingMetadata,
|
|
21
|
+
[extraction_1.EventType.ExtractionDataStart]: extraction_1.EventType.StartExtractingData,
|
|
22
|
+
[extraction_1.EventType.ExtractionDataContinue]: extraction_1.EventType.ContinueExtractingData,
|
|
23
|
+
[extraction_1.EventType.ExtractionDataDelete]: extraction_1.EventType.StartDeletingExtractorState,
|
|
24
|
+
[extraction_1.EventType.ExtractionAttachmentsStart]: extraction_1.EventType.StartExtractingAttachments,
|
|
25
|
+
[extraction_1.EventType.ExtractionAttachmentsContinue]: extraction_1.EventType.ContinueExtractingAttachments,
|
|
26
|
+
[extraction_1.EventType.ExtractionAttachmentsDelete]: extraction_1.EventType.StartDeletingExtractorAttachmentsState,
|
|
27
|
+
// New extraction event types (already correct, map to new enum members)
|
|
28
|
+
[extraction_1.EventType.StartExtractingExternalSyncUnits]: extraction_1.EventType.StartExtractingExternalSyncUnits,
|
|
29
|
+
[extraction_1.EventType.StartExtractingMetadata]: extraction_1.EventType.StartExtractingMetadata,
|
|
30
|
+
[extraction_1.EventType.StartExtractingData]: extraction_1.EventType.StartExtractingData,
|
|
31
|
+
[extraction_1.EventType.ContinueExtractingData]: extraction_1.EventType.ContinueExtractingData,
|
|
32
|
+
[extraction_1.EventType.StartDeletingExtractorState]: extraction_1.EventType.StartDeletingExtractorState,
|
|
33
|
+
[extraction_1.EventType.StartExtractingAttachments]: extraction_1.EventType.StartExtractingAttachments,
|
|
34
|
+
[extraction_1.EventType.ContinueExtractingAttachments]: extraction_1.EventType.ContinueExtractingAttachments,
|
|
35
|
+
[extraction_1.EventType.StartDeletingExtractorAttachmentsState]: extraction_1.EventType.StartDeletingExtractorAttachmentsState,
|
|
36
|
+
// Loading events
|
|
37
|
+
[extraction_1.EventType.StartLoadingData]: extraction_1.EventType.StartLoadingData,
|
|
38
|
+
[extraction_1.EventType.ContinueLoadingData]: extraction_1.EventType.ContinueLoadingData,
|
|
39
|
+
[extraction_1.EventType.StartLoadingAttachments]: extraction_1.EventType.StartLoadingAttachments,
|
|
40
|
+
[extraction_1.EventType.ContinueLoadingAttachments]: extraction_1.EventType.ContinueLoadingAttachments,
|
|
41
|
+
[extraction_1.EventType.StartDeletingLoaderState]: extraction_1.EventType.StartDeletingLoaderState,
|
|
42
|
+
[extraction_1.EventType.StartDeletingLoaderAttachmentState]: extraction_1.EventType.StartDeletingLoaderAttachmentState,
|
|
43
|
+
// Unknown
|
|
44
|
+
[extraction_1.EventType.UnknownEventType]: extraction_1.EventType.UnknownEventType,
|
|
45
|
+
};
|
|
46
|
+
const translated = eventTypeMap[eventTypeString];
|
|
47
|
+
if (!translated) {
|
|
48
|
+
console.warn(`Unknown event type received: ${eventTypeString}. This may indicate a new event type or a typo.`);
|
|
49
|
+
// Return the original string cast as EventType as a fallback
|
|
50
|
+
return eventTypeString;
|
|
51
|
+
}
|
|
52
|
+
return translated;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Translates ExtractorEventType enum values by converting old enum members to new ones.
|
|
56
|
+
* Old enum members are deprecated and should be replaced with new ones.
|
|
57
|
+
*/
|
|
58
|
+
function translateExtractorEventType(eventType) {
|
|
59
|
+
var _a;
|
|
60
|
+
// Map old enum members to new enum members
|
|
61
|
+
const stringValue = eventType;
|
|
62
|
+
const mapping = {
|
|
63
|
+
// Old string values -> New enum members
|
|
64
|
+
[extraction_1.ExtractorEventType.ExtractionExternalSyncUnitsDone]: extraction_1.ExtractorEventType.ExternalSyncUnitExtractionDone,
|
|
65
|
+
[extraction_1.ExtractorEventType.ExtractionExternalSyncUnitsError]: extraction_1.ExtractorEventType.ExternalSyncUnitExtractionError,
|
|
66
|
+
[extraction_1.ExtractorEventType.ExtractionMetadataDone]: extraction_1.ExtractorEventType.MetadataExtractionDone,
|
|
67
|
+
[extraction_1.ExtractorEventType.ExtractionMetadataError]: extraction_1.ExtractorEventType.MetadataExtractionError,
|
|
68
|
+
[extraction_1.ExtractorEventType.ExtractionDataProgress]: extraction_1.ExtractorEventType.DataExtractionProgress,
|
|
69
|
+
[extraction_1.ExtractorEventType.ExtractionDataDelay]: extraction_1.ExtractorEventType.DataExtractionDelayed,
|
|
70
|
+
[extraction_1.ExtractorEventType.ExtractionDataDone]: extraction_1.ExtractorEventType.DataExtractionDone,
|
|
71
|
+
[extraction_1.ExtractorEventType.ExtractionDataError]: extraction_1.ExtractorEventType.DataExtractionError,
|
|
72
|
+
[extraction_1.ExtractorEventType.ExtractionDataDeleteDone]: extraction_1.ExtractorEventType.ExtractorStateDeletionDone,
|
|
73
|
+
[extraction_1.ExtractorEventType.ExtractionDataDeleteError]: extraction_1.ExtractorEventType.ExtractorStateDeletionError,
|
|
74
|
+
[extraction_1.ExtractorEventType.ExtractionAttachmentsProgress]: extraction_1.ExtractorEventType.AttachmentExtractionProgress,
|
|
75
|
+
[extraction_1.ExtractorEventType.ExtractionAttachmentsDelay]: extraction_1.ExtractorEventType.AttachmentExtractionDelayed,
|
|
76
|
+
[extraction_1.ExtractorEventType.ExtractionAttachmentsDone]: extraction_1.ExtractorEventType.AttachmentExtractionDone,
|
|
77
|
+
[extraction_1.ExtractorEventType.ExtractionAttachmentsError]: extraction_1.ExtractorEventType.AttachmentExtractionError,
|
|
78
|
+
[extraction_1.ExtractorEventType.ExtractionAttachmentsDeleteDone]: extraction_1.ExtractorEventType.ExtractorAttachmentsStateDeletionDone,
|
|
79
|
+
[extraction_1.ExtractorEventType.ExtractionAttachmentsDeleteError]: extraction_1.ExtractorEventType.ExtractorAttachmentsStateDeletionError,
|
|
80
|
+
};
|
|
81
|
+
// If there's a mapping, use it; otherwise return original (already new)
|
|
82
|
+
return (_a = mapping[stringValue]) !== null && _a !== void 0 ? _a : eventType;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Translates LoaderEventType enum values by converting old enum members to new ones.
|
|
86
|
+
* Old enum members are deprecated and should be replaced with new ones.
|
|
87
|
+
*/
|
|
88
|
+
function translateLoaderEventType(eventType) {
|
|
89
|
+
var _a;
|
|
90
|
+
// Map old enum members to new enum members
|
|
91
|
+
const stringValue = eventType;
|
|
92
|
+
const mapping = {
|
|
93
|
+
// Old string values -> New enum members
|
|
94
|
+
[loading_1.LoaderEventType.DataLoadingDelay]: loading_1.LoaderEventType.DataLoadingDelayed,
|
|
95
|
+
[loading_1.LoaderEventType.AttachmentsLoadingProgress]: loading_1.LoaderEventType.AttachmentLoadingProgress,
|
|
96
|
+
[loading_1.LoaderEventType.AttachmentsLoadingDelayed]: loading_1.LoaderEventType.AttachmentLoadingDelayed,
|
|
97
|
+
[loading_1.LoaderEventType.AttachmentsLoadingDone]: loading_1.LoaderEventType.AttachmentLoadingDone,
|
|
98
|
+
[loading_1.LoaderEventType.AttachmentsLoadingError]: loading_1.LoaderEventType.AttachmentLoadingError,
|
|
99
|
+
};
|
|
100
|
+
// If there's a mapping, use it; otherwise return original (already new)
|
|
101
|
+
return (_a = mapping[stringValue]) !== null && _a !== void 0 ? _a : eventType;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Translates any outgoing event type (Extractor or Loader) to ensure new event types are used.
|
|
105
|
+
*/
|
|
106
|
+
function translateOutgoingEventType(eventType) {
|
|
107
|
+
// Check if it's an ExtractorEventType by checking if the value exists in ExtractorEventType
|
|
108
|
+
if (Object.values(extraction_1.ExtractorEventType).includes(eventType)) {
|
|
109
|
+
return translateExtractorEventType(eventType);
|
|
110
|
+
}
|
|
111
|
+
// Otherwise treat as LoaderEventType
|
|
112
|
+
if (Object.values(loading_1.LoaderEventType).includes(eventType)) {
|
|
113
|
+
return translateLoaderEventType(eventType);
|
|
114
|
+
}
|
|
115
|
+
// If neither, return as-is
|
|
116
|
+
return eventType;
|
|
117
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the library version from the package.json file.
|
|
3
|
+
* @returns {string} The library version
|
|
4
|
+
*/
|
|
5
|
+
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
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Truncates a filename if it exceeds the maximum allowed length.
|
|
14
|
+
* @param {string} filename - The filename to truncate
|
|
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
|
|
27
|
+
*/
|
|
28
|
+
export interface MemoryInfo {
|
|
29
|
+
rssUsedMB: string;
|
|
30
|
+
rssUsedPercent: string;
|
|
31
|
+
heapUsedPercent: string;
|
|
32
|
+
externalMB: string;
|
|
33
|
+
arrayBuffersMB: string;
|
|
34
|
+
formattedMessage: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the memory usage information.
|
|
38
|
+
* @returns {MemoryInfo} The memory usage information
|
|
39
|
+
*/
|
|
40
|
+
export declare function getMemoryUsage(): MemoryInfo;
|
|
41
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/common/helpers.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,wBAAgB,iBAAiB,QAiBhC;AAED;;;;GAIG;AACH,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAGrC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAmBzD;AAED;;;;;;;;;GASG;AACH,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;;;GAGG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAmD3C"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getLibraryVersion = getLibraryVersion;
|
|
37
|
+
exports.sleep = sleep;
|
|
38
|
+
exports.truncateFilename = truncateFilename;
|
|
39
|
+
exports.getMemoryUsage = getMemoryUsage;
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const path = __importStar(require("path"));
|
|
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
|
+
function getLibraryVersion() {
|
|
49
|
+
var _a;
|
|
50
|
+
try {
|
|
51
|
+
const version = (_a = JSON.parse((0, fs_1.readFileSync)(path.resolve(__dirname, '../../package.json'), 'utf8'))) === null || _a === void 0 ? void 0 : _a.version;
|
|
52
|
+
if (version) {
|
|
53
|
+
return version;
|
|
54
|
+
}
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('Error reading adaas library version from package.json', error);
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
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
|
+
async function sleep(ms) {
|
|
68
|
+
console.log(`Sleeping for ${ms}ms.`);
|
|
69
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Truncates a filename if it exceeds the maximum allowed length.
|
|
73
|
+
* @param {string} filename - The filename to truncate
|
|
74
|
+
* @returns {string} The truncated filename
|
|
75
|
+
*/
|
|
76
|
+
function truncateFilename(filename) {
|
|
77
|
+
// If the filename is already within the limit, return it as is.
|
|
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}`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Gets the memory usage information.
|
|
91
|
+
* @returns {MemoryInfo} The memory usage information
|
|
92
|
+
*/
|
|
93
|
+
function getMemoryUsage() {
|
|
94
|
+
try {
|
|
95
|
+
const memUsage = process.memoryUsage();
|
|
96
|
+
const heapStats = v8.getHeapStatistics();
|
|
97
|
+
const rssUsedMB = memUsage.rss / 1024 / 1024;
|
|
98
|
+
const heapLimitMB = heapStats.heap_size_limit / 1024 / 1024;
|
|
99
|
+
const effectiveMemoryLimitMB = heapLimitMB;
|
|
100
|
+
// Calculate heap values for consistent format
|
|
101
|
+
const heapUsedMB = heapStats.used_heap_size / 1024 / 1024;
|
|
102
|
+
const heapTotalMB = heapStats.heap_size_limit / 1024 / 1024;
|
|
103
|
+
// Calculate external and buffer values (critical for detecting stream leaks)
|
|
104
|
+
const externalMB = memUsage.external / 1024 / 1024;
|
|
105
|
+
const arrayBuffersMB = memUsage.arrayBuffers / 1024 / 1024;
|
|
106
|
+
// Critical percentages for OOM detection
|
|
107
|
+
const rssUsedPercent = ((rssUsedMB / effectiveMemoryLimitMB) * 100).toFixed(2) + '%';
|
|
108
|
+
const heapUsedPercent = ((heapStats.used_heap_size / heapStats.heap_size_limit) * 100).toFixed(2) + '%';
|
|
109
|
+
// Detailed message showing RSS breakdown for leak detection
|
|
110
|
+
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
|
+
return {
|
|
112
|
+
rssUsedMB: rssUsedMB.toFixed(2),
|
|
113
|
+
rssUsedPercent,
|
|
114
|
+
heapUsedPercent,
|
|
115
|
+
externalMB: externalMB.toFixed(2),
|
|
116
|
+
arrayBuffersMB: arrayBuffersMB.toFixed(2),
|
|
117
|
+
formattedMessage,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
console.warn('Error retrieving memory usage', err);
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AirdropEvent } from '../types/extraction';
|
|
2
|
+
import { InitialDomainMapping } from '../types/common';
|
|
3
|
+
export declare function installInitialDomainMapping(event: AirdropEvent, initialDomainMappingJson: InitialDomainMapping): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=install-initial-domain-mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-initial-domain-mapping.d.ts","sourceRoot":"","sources":["../../src/common/install-initial-domain-mapping.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,YAAY,EACnB,wBAAwB,EAAE,oBAAoB,GAC7C,OAAO,CAAC,IAAI,CAAC,CA0Ff"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installInitialDomainMapping = installInitialDomainMapping;
|
|
4
|
+
const axios_client_internal_1 = require("../http/axios-client-internal");
|
|
5
|
+
const logger_1 = require("../logger/logger");
|
|
6
|
+
async function installInitialDomainMapping(event, initialDomainMappingJson) {
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
8
|
+
const devrevEndpoint = event.execution_metadata.devrev_endpoint;
|
|
9
|
+
const devrevToken = event.context.secrets.service_account_token;
|
|
10
|
+
const snapInId = event.context.snap_in_id;
|
|
11
|
+
if (!initialDomainMappingJson) {
|
|
12
|
+
console.warn('No initial domain mapping found.');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// Get snap-in details
|
|
16
|
+
const snapInResponse = await axios_client_internal_1.axiosClient.get(devrevEndpoint + '/internal/snap-ins.get', {
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: devrevToken,
|
|
19
|
+
},
|
|
20
|
+
params: {
|
|
21
|
+
id: snapInId,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const importSlug = (_d = (_c = (_b = (_a = snapInResponse.data) === null || _a === void 0 ? void 0 : _a.snap_in) === null || _b === void 0 ? void 0 : _b.imports) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name;
|
|
25
|
+
const snapInSlug = (_g = (_f = (_e = snapInResponse.data) === null || _e === void 0 ? void 0 : _e.snap_in) === null || _f === void 0 ? void 0 : _f.snap_in_version) === null || _g === void 0 ? void 0 : _g.slug;
|
|
26
|
+
if (!importSlug || !snapInSlug) {
|
|
27
|
+
const errorMessage = `No import slug or snap-in slug found. Snap-in response: ${snapInResponse.data}`;
|
|
28
|
+
throw new Error(errorMessage);
|
|
29
|
+
}
|
|
30
|
+
const startingRecipeBlueprint = initialDomainMappingJson === null || initialDomainMappingJson === void 0 ? void 0 : initialDomainMappingJson.starting_recipe_blueprint;
|
|
31
|
+
// Try to create a recipe blueprint
|
|
32
|
+
let recipeBlueprintId;
|
|
33
|
+
if (startingRecipeBlueprint &&
|
|
34
|
+
Object.keys(startingRecipeBlueprint).length !== 0) {
|
|
35
|
+
try {
|
|
36
|
+
const recipeBlueprintResponse = await axios_client_internal_1.axiosClient.post(`${devrevEndpoint}/internal/airdrop.recipe.blueprints.create`, Object.assign({}, startingRecipeBlueprint), {
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: devrevToken,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
recipeBlueprintId = recipeBlueprintResponse.data.recipe_blueprint.id;
|
|
42
|
+
console.log('Successfully created recipe blueprint with id: ' + recipeBlueprintId);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.warn('Error while creating recipe blueprint. Continuing without it.', (0, logger_1.serializeError)(error));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Install the initial domain mappings
|
|
49
|
+
const additionalMappings = initialDomainMappingJson.additional_mappings || {};
|
|
50
|
+
const initialDomainMappingInstallResponse = await axios_client_internal_1.axiosClient.post(`${devrevEndpoint}/internal/airdrop.recipe.initial-domain-mappings.install`, Object.assign(Object.assign({ external_system_type: 'ADaaS', import_slug: importSlug, snap_in_slug: snapInSlug }, (recipeBlueprintId && {
|
|
51
|
+
starting_recipe_blueprint: recipeBlueprintId,
|
|
52
|
+
})), additionalMappings), {
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: devrevToken,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
console.log('Successfully installed initial domain mapping', initialDomainMappingInstallResponse.data);
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-initial-domain-mapping.test.d.ts","sourceRoot":"","sources":["../../src/common/install-initial-domain-mapping.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const axios_client_internal_1 = require("../http/axios-client-internal");
|
|
8
|
+
const test_helpers_1 = require("../tests/test-helpers");
|
|
9
|
+
const extraction_1 = require("../types/extraction");
|
|
10
|
+
const install_initial_domain_mapping_1 = require("./install-initial-domain-mapping");
|
|
11
|
+
// Mock dependencies
|
|
12
|
+
jest.mock('axios', () => (Object.assign(Object.assign({}, jest.requireActual('axios')), { isAxiosError: jest.fn() })));
|
|
13
|
+
jest.mock('../http/axios-client-internal', () => {
|
|
14
|
+
const originalModule = jest.requireActual('../http/axios-client-internal');
|
|
15
|
+
return Object.assign(Object.assign({}, originalModule), { axiosClient: {
|
|
16
|
+
get: jest.fn(),
|
|
17
|
+
post: jest.fn(),
|
|
18
|
+
} });
|
|
19
|
+
});
|
|
20
|
+
jest.mock('../logger/logger');
|
|
21
|
+
const mockAxiosClient = axios_client_internal_1.axiosClient;
|
|
22
|
+
const mockIsAxiosError = axios_1.default.isAxiosError;
|
|
23
|
+
describe(install_initial_domain_mapping_1.installInitialDomainMapping.name, () => {
|
|
24
|
+
// Create mock objects
|
|
25
|
+
const mockEvent = (0, test_helpers_1.createEvent)({ eventType: extraction_1.EventType.ExtractionDataStart });
|
|
26
|
+
const mockInitialDomainMapping = {
|
|
27
|
+
starting_recipe_blueprint: {
|
|
28
|
+
name: 'Test Recipe Blueprint',
|
|
29
|
+
description: 'Test description',
|
|
30
|
+
},
|
|
31
|
+
additional_mappings: {
|
|
32
|
+
custom_field: 'custom_value',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const mockSnapInResponse = {
|
|
36
|
+
data: {
|
|
37
|
+
snap_in: {
|
|
38
|
+
imports: [{ name: 'import-slug-123' }],
|
|
39
|
+
snap_in_version: { slug: 'snap-in-slug-123' },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const mockEndpoint = 'http://localhost:3001';
|
|
44
|
+
const mockToken = 'test_token';
|
|
45
|
+
// After each test, clear all mocks to prevent state from leaking.
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
jest.clearAllMocks();
|
|
48
|
+
});
|
|
49
|
+
it('should successfully install initial domain mapping with recipe blueprint', async () => {
|
|
50
|
+
// Mock successful snap-in response
|
|
51
|
+
mockAxiosClient.get.mockResolvedValueOnce(mockSnapInResponse);
|
|
52
|
+
// Mock successful recipe blueprint creation
|
|
53
|
+
const mockRecipeBlueprintResponse = {
|
|
54
|
+
data: {
|
|
55
|
+
recipe_blueprint: {
|
|
56
|
+
id: 'recipe-blueprint-123',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
mockAxiosClient.post.mockResolvedValueOnce(mockRecipeBlueprintResponse);
|
|
61
|
+
// Mock successful domain mapping installation
|
|
62
|
+
const mockDomainMappingResponse = {
|
|
63
|
+
data: {
|
|
64
|
+
success: true,
|
|
65
|
+
mapping_id: 'mapping-123',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
mockAxiosClient.post.mockResolvedValueOnce(mockDomainMappingResponse);
|
|
69
|
+
await (0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, mockInitialDomainMapping);
|
|
70
|
+
// Verify snap-in details request
|
|
71
|
+
expect(mockAxiosClient.get).toHaveBeenCalledWith(`${mockEndpoint}/internal/snap-ins.get`, {
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: mockToken,
|
|
74
|
+
},
|
|
75
|
+
params: {
|
|
76
|
+
id: 'test_snap_in_id',
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
// Verify recipe blueprint creation
|
|
80
|
+
expect(mockAxiosClient.post).toHaveBeenCalledWith(`${mockEndpoint}/internal/airdrop.recipe.blueprints.create`, {
|
|
81
|
+
name: 'Test Recipe Blueprint',
|
|
82
|
+
description: 'Test description',
|
|
83
|
+
}, {
|
|
84
|
+
headers: {
|
|
85
|
+
Authorization: mockToken,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
// Verify domain mapping installation
|
|
89
|
+
expect(mockAxiosClient.post).toHaveBeenCalledWith(`${mockEndpoint}/internal/airdrop.recipe.initial-domain-mappings.install`, {
|
|
90
|
+
external_system_type: 'ADaaS',
|
|
91
|
+
import_slug: 'import-slug-123',
|
|
92
|
+
snap_in_slug: 'snap-in-slug-123',
|
|
93
|
+
starting_recipe_blueprint: 'recipe-blueprint-123',
|
|
94
|
+
custom_field: 'custom_value',
|
|
95
|
+
}, {
|
|
96
|
+
headers: {
|
|
97
|
+
Authorization: mockToken,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it('should successfully install without recipe blueprint when not provided', async () => {
|
|
102
|
+
const mappingWithoutBlueprint = {
|
|
103
|
+
additional_mappings: {
|
|
104
|
+
custom_field: 'custom_value',
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
mockAxiosClient.get.mockResolvedValueOnce(mockSnapInResponse);
|
|
108
|
+
const mockDomainMappingResponse = {
|
|
109
|
+
data: { success: true },
|
|
110
|
+
};
|
|
111
|
+
mockAxiosClient.post.mockResolvedValueOnce(mockDomainMappingResponse);
|
|
112
|
+
await (0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, mappingWithoutBlueprint);
|
|
113
|
+
// Should only make one POST request (no recipe blueprint creation)
|
|
114
|
+
expect(mockAxiosClient.post).toHaveBeenCalledTimes(1);
|
|
115
|
+
expect(mockAxiosClient.post).toHaveBeenCalledWith(`${mockEndpoint}/internal/airdrop.recipe.initial-domain-mappings.install`, {
|
|
116
|
+
external_system_type: 'ADaaS',
|
|
117
|
+
import_slug: 'import-slug-123',
|
|
118
|
+
snap_in_slug: 'snap-in-slug-123',
|
|
119
|
+
custom_field: 'custom_value',
|
|
120
|
+
}, {
|
|
121
|
+
headers: {
|
|
122
|
+
Authorization: mockToken,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
it('should handle empty starting_recipe_blueprint object', async () => {
|
|
127
|
+
const mappingWithEmptyBlueprint = {
|
|
128
|
+
starting_recipe_blueprint: {},
|
|
129
|
+
additional_mappings: {
|
|
130
|
+
custom_field: 'custom_value',
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
mockAxiosClient.get.mockResolvedValueOnce(mockSnapInResponse);
|
|
134
|
+
const mockDomainMappingResponse = {
|
|
135
|
+
data: { success: true },
|
|
136
|
+
};
|
|
137
|
+
mockAxiosClient.post.mockResolvedValueOnce(mockDomainMappingResponse);
|
|
138
|
+
await (0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, mappingWithEmptyBlueprint);
|
|
139
|
+
// Should only make one POST request (no recipe blueprint creation for empty object)
|
|
140
|
+
expect(mockAxiosClient.post).toHaveBeenCalledTimes(1);
|
|
141
|
+
});
|
|
142
|
+
it('[edge] should return early with warning when initial domain mapping is null', async () => {
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
144
|
+
await (0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, null);
|
|
145
|
+
expect(mockAxiosClient.get).not.toHaveBeenCalled();
|
|
146
|
+
expect(mockAxiosClient.post).not.toHaveBeenCalled();
|
|
147
|
+
});
|
|
148
|
+
it('[edge] should return early with warning when initial domain mapping is undefined', async () => {
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
|
+
await (0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, undefined);
|
|
151
|
+
expect(mockAxiosClient.get).not.toHaveBeenCalled();
|
|
152
|
+
expect(mockAxiosClient.post).not.toHaveBeenCalled();
|
|
153
|
+
});
|
|
154
|
+
it('[edge] should throw error when import slug is missing', async () => {
|
|
155
|
+
const snapInResponseWithoutImport = {
|
|
156
|
+
data: {
|
|
157
|
+
snap_in: {
|
|
158
|
+
imports: [],
|
|
159
|
+
snap_in_version: { slug: 'snap-in-slug-123' },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
mockAxiosClient.get.mockResolvedValueOnce(snapInResponseWithoutImport);
|
|
164
|
+
await expect((0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, mockInitialDomainMapping)).rejects.toThrow();
|
|
165
|
+
});
|
|
166
|
+
it('[edge] should throw error when snap-in slug is missing', async () => {
|
|
167
|
+
const snapInResponseWithoutSlug = {
|
|
168
|
+
data: {
|
|
169
|
+
snap_in: {
|
|
170
|
+
imports: [{ name: 'import-slug-123' }],
|
|
171
|
+
snap_in_version: {},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
mockAxiosClient.get.mockResolvedValueOnce(snapInResponseWithoutSlug);
|
|
176
|
+
await expect((0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, mockInitialDomainMapping)).rejects.toThrow();
|
|
177
|
+
});
|
|
178
|
+
it('should handle the error during recipe blueprint creation', async () => {
|
|
179
|
+
mockAxiosClient.get.mockResolvedValueOnce(mockSnapInResponse);
|
|
180
|
+
const genericError = new Error('Generic error during blueprint creation');
|
|
181
|
+
// Mock axios.isAxiosError to return false
|
|
182
|
+
mockIsAxiosError.mockReturnValue(false);
|
|
183
|
+
mockAxiosClient.post.mockRejectedValueOnce(genericError);
|
|
184
|
+
const mockDomainMappingResponse = {
|
|
185
|
+
data: { success: true },
|
|
186
|
+
};
|
|
187
|
+
mockAxiosClient.post.mockResolvedValueOnce(mockDomainMappingResponse);
|
|
188
|
+
await (0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, mockInitialDomainMapping);
|
|
189
|
+
// Should still proceed with domain mapping installation
|
|
190
|
+
expect(mockAxiosClient.post).toHaveBeenCalledTimes(2);
|
|
191
|
+
});
|
|
192
|
+
it('should propagate error from domain mapping installation', async () => {
|
|
193
|
+
mockAxiosClient.get.mockResolvedValueOnce(mockSnapInResponse);
|
|
194
|
+
// Mock successful recipe blueprint creation
|
|
195
|
+
const mockRecipeBlueprintResponse = {
|
|
196
|
+
data: {
|
|
197
|
+
recipe_blueprint: {
|
|
198
|
+
id: 'recipe-blueprint-123',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
mockAxiosClient.post.mockResolvedValueOnce(mockRecipeBlueprintResponse);
|
|
203
|
+
const domainMappingError = new Error('Domain mapping installation failed');
|
|
204
|
+
mockAxiosClient.post.mockRejectedValueOnce(domainMappingError);
|
|
205
|
+
await expect((0, install_initial_domain_mapping_1.installInitialDomainMapping)(mockEvent, mockInitialDomainMapping)).rejects.toThrow();
|
|
206
|
+
});
|
|
207
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AirdropEvent, EventData, ExtractorEventType } from '../../types/extraction';
|
|
2
|
+
import { Artifact } from '../../uploader/uploader.interfaces';
|
|
3
|
+
import { AdapterState } from '../../state/state.interfaces';
|
|
4
|
+
import { State } from '../../state/state';
|
|
5
|
+
/**
|
|
6
|
+
* Adapter class is used to interact with Airdrop platform. The class provides
|
|
7
|
+
* utilities to
|
|
8
|
+
* - emit control events to the platform
|
|
9
|
+
* - update the state of the extractor
|
|
10
|
+
* - set the last saved state in case of a timeout
|
|
11
|
+
*
|
|
12
|
+
* @class Adapter
|
|
13
|
+
* @constructor
|
|
14
|
+
* @deprecated
|
|
15
|
+
* @param {AirdropEvent} event - The event object received from the platform
|
|
16
|
+
* @param {object=} initialState - The initial state of the adapter
|
|
17
|
+
* @param {boolean=} isLocalDevelopment - A flag to indicate if the adapter is being used in local development
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Creates an adapter instance.
|
|
21
|
+
*
|
|
22
|
+
* @param {AirdropEvent} event - The event object received from the platform
|
|
23
|
+
* @param initialState
|
|
24
|
+
* @param {boolean=} isLocalDevelopment - A flag to indicate if the adapter is being used in local development
|
|
25
|
+
* @return The adapter instance
|
|
26
|
+
*/
|
|
27
|
+
export declare function createAdapter<ConnectorState>(event: AirdropEvent, initialState: ConnectorState, isLocalDevelopment?: boolean): Promise<Adapter<ConnectorState>>;
|
|
28
|
+
export declare class Adapter<ConnectorState> {
|
|
29
|
+
private adapterState;
|
|
30
|
+
private _artifacts;
|
|
31
|
+
private event;
|
|
32
|
+
private callbackUrl;
|
|
33
|
+
private devrevToken;
|
|
34
|
+
private startTime;
|
|
35
|
+
private heartBeatFn;
|
|
36
|
+
private exit;
|
|
37
|
+
private lambdaTimeout;
|
|
38
|
+
private heartBeatInterval;
|
|
39
|
+
constructor(event: AirdropEvent, adapterState: State<ConnectorState>, isLocalDevelopment?: boolean);
|
|
40
|
+
get state(): AdapterState<ConnectorState>;
|
|
41
|
+
set state(value: AdapterState<ConnectorState>);
|
|
42
|
+
get artifacts(): Artifact[];
|
|
43
|
+
set artifacts(value: Artifact[]);
|
|
44
|
+
/**
|
|
45
|
+
* Emits an event to the platform.
|
|
46
|
+
*
|
|
47
|
+
* @param {ExtractorEventType} newEventType - The event type to be emitted
|
|
48
|
+
* @param {EventData=} data - The data to be sent with the event
|
|
49
|
+
*/
|
|
50
|
+
emit(newEventType: ExtractorEventType, data?: EventData): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Exit the adapter. This will stop the heartbeat and no
|
|
53
|
+
* further events will be emitted.
|
|
54
|
+
*/
|
|
55
|
+
private exitAdapter;
|
|
56
|
+
/**
|
|
57
|
+
* Heartbeat function to check if the lambda is about to timeout.
|
|
58
|
+
* @returns true if 10 minutes have passed since the start of the lambda.
|
|
59
|
+
*/
|
|
60
|
+
private heartbeat;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deprecated/adapter/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,SAAS,EAET,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAK5D,OAAO,EAAE,KAAK,EAAsB,MAAM,mBAAmB,CAAC;AAI9D;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AAEH,wBAAsB,aAAa,CAAC,cAAc,EAChD,KAAK,EAAE,YAAY,EACnB,YAAY,EAAE,cAAc,EAC5B,kBAAkB,GAAE,OAAe,oCAiBpC;AAED,qBAAa,OAAO,CAAC,cAAc;IACjC,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAA4C;IAC/D,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,aAAa,CAA0B;IAC/C,OAAO,CAAC,iBAAiB,CAAqB;gBAG5C,KAAK,EAAE,YAAY,EACnB,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,EACnC,kBAAkB,GAAE,OAAe;IAwBrC,IAAI,KAAK,IAAI,YAAY,CAAC,cAAc,CAAC,CAExC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,cAAc,CAAC,EAE5C;IAED,IAAI,SAAS,IAAI,QAAQ,EAAE,CAE1B;IAED,IAAI,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAE9B;IAED;;;;;OAKG;IACG,IAAI,CAAC,YAAY,EAAE,kBAAkB,EAAE,IAAI,CAAC,EAAE,SAAS;IAoD7D;;;OAGG;IACH,OAAO,CAAC,WAAW;IAInB;;;OAGG;YACW,SAAS;CAiBxB"}
|