@devrev/airsync-sdk 2.0.0-beta.1 → 2.0.0-beta.2
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 +0 -4
- package/dist/airsync-sdk.d.ts +1802 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +13 -2
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +201 -6
- package/dist/common/constants.d.ts +16 -5
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +20 -6
- package/dist/common/control-protocol.d.ts +2 -2
- package/dist/common/control-protocol.d.ts.map +1 -1
- package/dist/common/control-protocol.js +1 -5
- package/dist/common/helpers.d.ts +8 -0
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +15 -0
- package/dist/common/install-initial-domain-mapping.d.ts +2 -2
- package/dist/common/install-initial-domain-mapping.test.js +5 -2
- package/dist/common/test-utils.d.ts +19 -0
- package/dist/common/test-utils.d.ts.map +1 -0
- package/dist/common/test-utils.js +101 -0
- package/dist/common/time-value-resolver.d.ts +47 -0
- package/dist/common/time-value-resolver.d.ts.map +1 -0
- package/dist/common/time-value-resolver.js +141 -0
- package/dist/common/time-value-resolver.test.d.ts +2 -0
- package/dist/common/time-value-resolver.test.d.ts.map +1 -0
- package/dist/common/time-value-resolver.test.js +268 -0
- package/dist/http/axios-client-internal.d.ts.map +1 -1
- package/dist/http/axios-client-internal.js +7 -0
- package/dist/http/axios-client-internal.test.js +21 -0
- package/dist/http/axios-client.d.ts.map +1 -1
- package/dist/http/axios-client.js +6 -3
- package/dist/http/index.d.ts +0 -1
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +0 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/logger/logger.d.ts +1 -17
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +2 -2
- package/dist/logger/logger.js +35 -27
- package/dist/logger/logger.test.js +66 -19
- package/dist/mappers/mappers.interface.d.ts +5 -5
- package/dist/mappers/mappers.interface.js +3 -3
- package/dist/mappers/mappers.test.js +8 -10
- package/dist/mock-server/mock-server.d.ts +47 -0
- package/dist/mock-server/mock-server.d.ts.map +1 -0
- package/dist/mock-server/mock-server.interfaces.d.ts +73 -0
- package/dist/mock-server/mock-server.interfaces.d.ts.map +1 -0
- package/dist/mock-server/mock-server.interfaces.js +4 -0
- package/dist/mock-server/mock-server.js +278 -0
- package/dist/multithreading/create-worker.test.js +36 -17
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +15 -48
- package/dist/multithreading/process-task.test.d.ts +2 -0
- package/dist/multithreading/process-task.test.d.ts.map +1 -0
- package/dist/multithreading/process-task.test.js +146 -0
- package/dist/multithreading/spawn/spawn.d.ts +3 -3
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +6 -14
- package/dist/multithreading/spawn/spawn.helpers.test.js +8 -8
- package/dist/multithreading/spawn/spawn.js +20 -25
- package/dist/multithreading/spawn/spawn.test.d.ts +2 -0
- package/dist/multithreading/spawn/spawn.test.d.ts.map +1 -0
- package/dist/multithreading/spawn/spawn.test.js +232 -0
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +49 -1
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +11 -5
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +1 -1
- package/dist/multithreading/worker-adapter/worker-adapter.emit.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.emit.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.emit.test.js +390 -0
- package/dist/multithreading/worker-adapter/worker-adapter.extraction.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.extraction.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.extraction.test.js +799 -0
- package/dist/multithreading/worker-adapter/worker-adapter.js +232 -131
- package/dist/multithreading/worker-adapter/worker-adapter.loading.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.loading.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.loading.test.js +596 -0
- package/dist/multithreading/worker-adapter/worker-adapter.serialization.test.d.ts +2 -0
- package/dist/multithreading/worker-adapter/worker-adapter.serialization.test.d.ts.map +1 -0
- package/dist/multithreading/worker-adapter/worker-adapter.serialization.test.js +71 -0
- package/dist/repo/repo.d.ts.map +1 -1
- package/dist/repo/repo.interfaces.d.ts +4 -2
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +4 -3
- package/dist/repo/repo.test.js +60 -7
- package/dist/state/state.d.ts +7 -1
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.extract-window.test.d.ts +2 -0
- package/dist/state/state.extract-window.test.d.ts.map +1 -0
- package/dist/state/state.extract-window.test.js +163 -0
- package/dist/state/state.interfaces.d.ts +17 -7
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +4 -2
- package/dist/state/state.js +111 -12
- package/dist/state/state.pending-boundaries.test.d.ts +2 -0
- package/dist/state/state.pending-boundaries.test.d.ts.map +1 -0
- package/dist/state/state.pending-boundaries.test.js +189 -0
- package/dist/state/state.post-state.test.d.ts +2 -0
- package/dist/state/state.post-state.test.d.ts.map +1 -0
- package/dist/state/state.post-state.test.js +77 -0
- package/dist/state/state.test.js +117 -73
- package/dist/state/state.time-value-resolution.test.d.ts +2 -0
- package/dist/state/state.time-value-resolution.test.d.ts.map +1 -0
- package/dist/state/state.time-value-resolution.test.js +175 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/common.d.ts +0 -25
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +1 -11
- package/dist/types/external-domain-metadata.d.ts +20 -1
- package/dist/types/external-domain-metadata.d.ts.map +1 -1
- package/dist/types/extraction.d.ts +89 -218
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +56 -124
- package/dist/types/extraction.test.js +69 -43
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -3
- package/dist/types/loading.d.ts +4 -24
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +1 -22
- package/dist/types/workers.d.ts +31 -14
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +1 -0
- package/dist/uploader/uploader.d.ts +1 -0
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.test.js +0 -11
- package/dist/uploader/uploader.interfaces.d.ts +3 -3
- package/dist/uploader/uploader.js +53 -20
- package/dist/uploader/uploader.test.js +22 -10
- package/package.json +10 -13
- 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/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/types.d.ts +0 -17
- package/dist/http/types.d.ts.map +0 -1
- package/dist/http/types.js +0 -2
- 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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TimeUnit, TimeValue } from '../types/extraction';
|
|
2
|
+
import { SdkState } from '../state/state.interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Parses a shorthand duration string into its numeric value and unit.
|
|
5
|
+
* Supported units:
|
|
6
|
+
* - 'ns' for nanoseconds
|
|
7
|
+
* - 'us' or 'µs' for microseconds
|
|
8
|
+
* - 'ms' for milliseconds
|
|
9
|
+
* - 's' for seconds
|
|
10
|
+
* - 'm' for minutes
|
|
11
|
+
* - 'h' for hours
|
|
12
|
+
*
|
|
13
|
+
* @throws Error if the format is invalid
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseDuration(shorthand: string): {
|
|
16
|
+
value: number;
|
|
17
|
+
unit: TimeUnit;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Applies a shorthand duration to a base ISO 8601 timestamp.
|
|
21
|
+
*
|
|
22
|
+
* @param baseTimestamp - ISO 8601 timestamp to apply duration to
|
|
23
|
+
* @param duration - Shorthand duration string (e.g. '100ns', '500ms', '30s', '5m', '2h')
|
|
24
|
+
* @param operation - Whether to 'add' or 'subtract' the duration
|
|
25
|
+
* @returns ISO 8601 timestamp with the duration applied
|
|
26
|
+
*/
|
|
27
|
+
export declare function applyDuration(baseTimestamp: string, duration: string, operation: 'add' | 'subtract'): string;
|
|
28
|
+
/**
|
|
29
|
+
* Resolves a TimeValue into a concrete ISO 8601 timestamp string.
|
|
30
|
+
*
|
|
31
|
+
* Resolution rules:
|
|
32
|
+
* - ABSOLUTE: Returns the value directly (must be an ISO 8601 timestamp)
|
|
33
|
+
* - NOW: Returns the current time as ISO 8601
|
|
34
|
+
* - UNBOUNDED: Returns UNBOUNDED_DATE_TIME_VALUE ('1970-01-01T00:00:00.000Z')
|
|
35
|
+
* - WORKERS_OLDEST: Returns workersOldest from state, or throws if not set
|
|
36
|
+
* - WORKERS_NEWEST: Returns workersNewest from state, or throws if not set
|
|
37
|
+
* - WORKERS_OLDEST_MINUS_WINDOW: Subtracts duration from workersOldest, or throws if not set
|
|
38
|
+
* - WORKERS_NEWEST_PLUS_WINDOW: Adds duration to workersNewest, or throws if not set
|
|
39
|
+
*
|
|
40
|
+
* @param timeValue - The TimeValue to resolve
|
|
41
|
+
* @param state - The current SDK state containing workersOldest and workersNewest
|
|
42
|
+
* @returns Resolved ISO 8601 timestamp string
|
|
43
|
+
* @throws Error if required TimeValue.value is missing for ABSOLUTE or *_WINDOW types
|
|
44
|
+
* @throws Error if workersOldest/workersNewest is not set in state for WORKERS_* types
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveTimeValue(timeValue: TimeValue, state: SdkState): string;
|
|
47
|
+
//# sourceMappingURL=time-value-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-value-resolver.d.ts","sourceRoot":"","sources":["../../src/common/time-value-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAiB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB,CAcA;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,KAAK,GAAG,UAAU,GAC5B,MAAM,CA6BR;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,QAAQ,GACd,MAAM,CA2ER"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDuration = parseDuration;
|
|
4
|
+
exports.applyDuration = applyDuration;
|
|
5
|
+
exports.resolveTimeValue = resolveTimeValue;
|
|
6
|
+
const extraction_1 = require("../types/extraction");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
/**
|
|
9
|
+
* Parses a shorthand duration string into its numeric value and unit.
|
|
10
|
+
* Supported units:
|
|
11
|
+
* - 'ns' for nanoseconds
|
|
12
|
+
* - 'us' or 'µs' for microseconds
|
|
13
|
+
* - 'ms' for milliseconds
|
|
14
|
+
* - 's' for seconds
|
|
15
|
+
* - 'm' for minutes
|
|
16
|
+
* - 'h' for hours
|
|
17
|
+
*
|
|
18
|
+
* @throws Error if the format is invalid
|
|
19
|
+
*/
|
|
20
|
+
function parseDuration(shorthand) {
|
|
21
|
+
const validUnits = Object.values(extraction_1.TimeUnit).join('|');
|
|
22
|
+
const match = shorthand.match(new RegExp(`^(\\d+(?:\\.\\d+)?)(${validUnits})$`));
|
|
23
|
+
if (!match) {
|
|
24
|
+
throw new Error(`Invalid duration format: '${shorthand}'. Expected format like '100ns', '500ms', '30s', '5m', or '2h'.`);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
value: parseFloat(match[1]),
|
|
28
|
+
unit: match[2],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Applies a shorthand duration to a base ISO 8601 timestamp.
|
|
33
|
+
*
|
|
34
|
+
* @param baseTimestamp - ISO 8601 timestamp to apply duration to
|
|
35
|
+
* @param duration - Shorthand duration string (e.g. '100ns', '500ms', '30s', '5m', '2h')
|
|
36
|
+
* @param operation - Whether to 'add' or 'subtract' the duration
|
|
37
|
+
* @returns ISO 8601 timestamp with the duration applied
|
|
38
|
+
*/
|
|
39
|
+
function applyDuration(baseTimestamp, duration, operation) {
|
|
40
|
+
const { value, unit } = parseDuration(duration);
|
|
41
|
+
const date = new Date(baseTimestamp);
|
|
42
|
+
const sign = operation === 'add' ? 1 : -1;
|
|
43
|
+
switch (unit) {
|
|
44
|
+
case extraction_1.TimeUnit.NANOSECONDS:
|
|
45
|
+
// JavaScript Date works in milliseconds, so convert nanoseconds
|
|
46
|
+
date.setTime(date.getTime() + sign * value * 0.000001);
|
|
47
|
+
break;
|
|
48
|
+
case extraction_1.TimeUnit.MICROSECONDS:
|
|
49
|
+
case extraction_1.TimeUnit.MICROSECONDS_MU:
|
|
50
|
+
date.setTime(date.getTime() + sign * value * 0.001);
|
|
51
|
+
break;
|
|
52
|
+
case extraction_1.TimeUnit.MILLISECONDS:
|
|
53
|
+
date.setTime(date.getTime() + sign * value);
|
|
54
|
+
break;
|
|
55
|
+
case extraction_1.TimeUnit.SECONDS:
|
|
56
|
+
date.setUTCSeconds(date.getUTCSeconds() + sign * value);
|
|
57
|
+
break;
|
|
58
|
+
case extraction_1.TimeUnit.MINUTES:
|
|
59
|
+
date.setUTCMinutes(date.getUTCMinutes() + sign * value);
|
|
60
|
+
break;
|
|
61
|
+
case extraction_1.TimeUnit.HOURS:
|
|
62
|
+
date.setUTCHours(date.getUTCHours() + sign * value);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
return date.toISOString();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resolves a TimeValue into a concrete ISO 8601 timestamp string.
|
|
69
|
+
*
|
|
70
|
+
* Resolution rules:
|
|
71
|
+
* - ABSOLUTE: Returns the value directly (must be an ISO 8601 timestamp)
|
|
72
|
+
* - NOW: Returns the current time as ISO 8601
|
|
73
|
+
* - UNBOUNDED: Returns UNBOUNDED_DATE_TIME_VALUE ('1970-01-01T00:00:00.000Z')
|
|
74
|
+
* - WORKERS_OLDEST: Returns workersOldest from state, or throws if not set
|
|
75
|
+
* - WORKERS_NEWEST: Returns workersNewest from state, or throws if not set
|
|
76
|
+
* - WORKERS_OLDEST_MINUS_WINDOW: Subtracts duration from workersOldest, or throws if not set
|
|
77
|
+
* - WORKERS_NEWEST_PLUS_WINDOW: Adds duration to workersNewest, or throws if not set
|
|
78
|
+
*
|
|
79
|
+
* @param timeValue - The TimeValue to resolve
|
|
80
|
+
* @param state - The current SDK state containing workersOldest and workersNewest
|
|
81
|
+
* @returns Resolved ISO 8601 timestamp string
|
|
82
|
+
* @throws Error if required TimeValue.value is missing for ABSOLUTE or *_WINDOW types
|
|
83
|
+
* @throws Error if workersOldest/workersNewest is not set in state for WORKERS_* types
|
|
84
|
+
*/
|
|
85
|
+
function resolveTimeValue(timeValue, state) {
|
|
86
|
+
switch (timeValue.type) {
|
|
87
|
+
case extraction_1.TimeValueType.ABSOLUTE_TIME: {
|
|
88
|
+
if (!timeValue.value) {
|
|
89
|
+
throw new Error('TimeValue of type ABSOLUTE must have a value (ISO 8601 timestamp).');
|
|
90
|
+
}
|
|
91
|
+
// Normalize to consistent ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ)
|
|
92
|
+
// to ensure string comparisons in boundary expansion are safe.
|
|
93
|
+
const parsed = new Date(timeValue.value);
|
|
94
|
+
if (isNaN(parsed.getTime())) {
|
|
95
|
+
throw new Error(`TimeValue of type ABSOLUTE has an invalid ISO 8601 timestamp: '${timeValue.value}'.`);
|
|
96
|
+
}
|
|
97
|
+
return parsed.toISOString();
|
|
98
|
+
}
|
|
99
|
+
case extraction_1.TimeValueType.CURRENT_TIME: {
|
|
100
|
+
return new Date().toISOString();
|
|
101
|
+
}
|
|
102
|
+
case extraction_1.TimeValueType.UNBOUNDED: {
|
|
103
|
+
return constants_1.UNBOUNDED_DATE_TIME_VALUE;
|
|
104
|
+
}
|
|
105
|
+
case extraction_1.TimeValueType.WORKERS_OLDEST: {
|
|
106
|
+
if (!state.workersOldest) {
|
|
107
|
+
// To support backwards-compatibility for the old state
|
|
108
|
+
return constants_1.UNBOUNDED_DATE_TIME_VALUE;
|
|
109
|
+
}
|
|
110
|
+
return state.workersOldest;
|
|
111
|
+
}
|
|
112
|
+
case extraction_1.TimeValueType.WORKERS_NEWEST: {
|
|
113
|
+
if (!state.workersNewest) {
|
|
114
|
+
throw new Error('Field workersNewest is not set in state. Cannot resolve TimeValue of type WORKERS_NEWEST without a prior extraction boundary.');
|
|
115
|
+
}
|
|
116
|
+
return state.workersNewest;
|
|
117
|
+
}
|
|
118
|
+
case extraction_1.TimeValueType.WORKERS_OLDEST_MINUS_WINDOW: {
|
|
119
|
+
if (!timeValue.value) {
|
|
120
|
+
throw new Error("TimeValue of type WORKERS_OLDEST_MINUS_WINDOW must have a value (duration, e.g. '30s', '5m', '2h').");
|
|
121
|
+
}
|
|
122
|
+
if (!state.workersOldest) {
|
|
123
|
+
// To support backwards-compatibility for the old state
|
|
124
|
+
return constants_1.UNBOUNDED_DATE_TIME_VALUE;
|
|
125
|
+
}
|
|
126
|
+
return applyDuration(state.workersOldest, timeValue.value, 'subtract');
|
|
127
|
+
}
|
|
128
|
+
case extraction_1.TimeValueType.WORKERS_NEWEST_PLUS_WINDOW: {
|
|
129
|
+
if (!timeValue.value) {
|
|
130
|
+
throw new Error("TimeValue of type WORKERS_NEWEST_PLUS_WINDOW must have a value (duration, e.g. '30s', '5m', '2h').");
|
|
131
|
+
}
|
|
132
|
+
if (!state.workersNewest) {
|
|
133
|
+
throw new Error('Field workersNewest is not set in state. Cannot resolve TimeValue of type WORKERS_NEWEST_PLUS_WINDOW without a prior extraction boundary.');
|
|
134
|
+
}
|
|
135
|
+
return applyDuration(state.workersNewest, timeValue.value, 'add');
|
|
136
|
+
}
|
|
137
|
+
default: {
|
|
138
|
+
throw new Error(`Unknown TimeValueType: '${timeValue.type}'.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-value-resolver.test.d.ts","sourceRoot":"","sources":["../../src/common/time-value-resolver.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const extraction_1 = require("../types/extraction");
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const time_value_resolver_1 = require("./time-value-resolver");
|
|
6
|
+
describe('time-value-resolver', () => {
|
|
7
|
+
describe('parseDuration', () => {
|
|
8
|
+
it('should parse nanoseconds', () => {
|
|
9
|
+
expect((0, time_value_resolver_1.parseDuration)('100ns')).toEqual({ value: 100, unit: 'ns' });
|
|
10
|
+
expect((0, time_value_resolver_1.parseDuration)('1ns')).toEqual({ value: 1, unit: 'ns' });
|
|
11
|
+
});
|
|
12
|
+
it('should parse microseconds', () => {
|
|
13
|
+
expect((0, time_value_resolver_1.parseDuration)('500us')).toEqual({ value: 500, unit: 'us' });
|
|
14
|
+
expect((0, time_value_resolver_1.parseDuration)('500µs')).toEqual({ value: 500, unit: 'µs' });
|
|
15
|
+
});
|
|
16
|
+
it('should parse milliseconds', () => {
|
|
17
|
+
expect((0, time_value_resolver_1.parseDuration)('250ms')).toEqual({ value: 250, unit: 'ms' });
|
|
18
|
+
expect((0, time_value_resolver_1.parseDuration)('1ms')).toEqual({ value: 1, unit: 'ms' });
|
|
19
|
+
});
|
|
20
|
+
it('should parse seconds', () => {
|
|
21
|
+
expect((0, time_value_resolver_1.parseDuration)('30s')).toEqual({ value: 30, unit: 's' });
|
|
22
|
+
expect((0, time_value_resolver_1.parseDuration)('1s')).toEqual({ value: 1, unit: 's' });
|
|
23
|
+
expect((0, time_value_resolver_1.parseDuration)('3600s')).toEqual({ value: 3600, unit: 's' });
|
|
24
|
+
});
|
|
25
|
+
it('should parse minutes', () => {
|
|
26
|
+
expect((0, time_value_resolver_1.parseDuration)('5m')).toEqual({ value: 5, unit: 'm' });
|
|
27
|
+
expect((0, time_value_resolver_1.parseDuration)('1m')).toEqual({ value: 1, unit: 'm' });
|
|
28
|
+
expect((0, time_value_resolver_1.parseDuration)('60m')).toEqual({ value: 60, unit: 'm' });
|
|
29
|
+
});
|
|
30
|
+
it('should parse hours', () => {
|
|
31
|
+
expect((0, time_value_resolver_1.parseDuration)('2h')).toEqual({ value: 2, unit: 'h' });
|
|
32
|
+
expect((0, time_value_resolver_1.parseDuration)('24h')).toEqual({ value: 24, unit: 'h' });
|
|
33
|
+
expect((0, time_value_resolver_1.parseDuration)('168h')).toEqual({ value: 168, unit: 'h' });
|
|
34
|
+
});
|
|
35
|
+
it('should parse fractional values', () => {
|
|
36
|
+
expect((0, time_value_resolver_1.parseDuration)('1.5h')).toEqual({ value: 1.5, unit: 'h' });
|
|
37
|
+
expect((0, time_value_resolver_1.parseDuration)('0.5s')).toEqual({ value: 0.5, unit: 's' });
|
|
38
|
+
expect((0, time_value_resolver_1.parseDuration)('2.5m')).toEqual({ value: 2.5, unit: 'm' });
|
|
39
|
+
});
|
|
40
|
+
it('should throw on invalid format', () => {
|
|
41
|
+
expect(() => (0, time_value_resolver_1.parseDuration)('')).toThrow('Invalid duration format');
|
|
42
|
+
expect(() => (0, time_value_resolver_1.parseDuration)('7')).toThrow('Invalid duration format');
|
|
43
|
+
expect(() => (0, time_value_resolver_1.parseDuration)('s')).toThrow('Invalid duration format');
|
|
44
|
+
expect(() => (0, time_value_resolver_1.parseDuration)('7d')).toThrow('Invalid duration format');
|
|
45
|
+
expect(() => (0, time_value_resolver_1.parseDuration)('7y')).toThrow('Invalid duration format');
|
|
46
|
+
expect(() => (0, time_value_resolver_1.parseDuration)('abc')).toThrow('Invalid duration format');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('applyDuration', () => {
|
|
50
|
+
describe('subtract', () => {
|
|
51
|
+
it('should subtract seconds', () => {
|
|
52
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:30.000Z', '30s', 'subtract');
|
|
53
|
+
expect(result).toBe('2024-01-15T00:00:00.000Z');
|
|
54
|
+
});
|
|
55
|
+
it('should subtract minutes', () => {
|
|
56
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:05:00.000Z', '5m', 'subtract');
|
|
57
|
+
expect(result).toBe('2024-01-15T00:00:00.000Z');
|
|
58
|
+
});
|
|
59
|
+
it('should subtract hours', () => {
|
|
60
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T02:00:00.000Z', '2h', 'subtract');
|
|
61
|
+
expect(result).toBe('2024-01-15T00:00:00.000Z');
|
|
62
|
+
});
|
|
63
|
+
it('should subtract milliseconds', () => {
|
|
64
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:00.500Z', '500ms', 'subtract');
|
|
65
|
+
expect(result).toBe('2024-01-15T00:00:00.000Z');
|
|
66
|
+
});
|
|
67
|
+
it('should handle crossing day boundary', () => {
|
|
68
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T01:00:00.000Z', '2h', 'subtract');
|
|
69
|
+
expect(result).toBe('2024-01-14T23:00:00.000Z');
|
|
70
|
+
});
|
|
71
|
+
it('should subtract 168 hours (7 days equivalent)', () => {
|
|
72
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:00.000Z', '168h', 'subtract');
|
|
73
|
+
expect(result).toBe('2024-01-08T00:00:00.000Z');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('add', () => {
|
|
77
|
+
it('should add seconds', () => {
|
|
78
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:00.000Z', '30s', 'add');
|
|
79
|
+
expect(result).toBe('2024-01-15T00:00:30.000Z');
|
|
80
|
+
});
|
|
81
|
+
it('should add minutes', () => {
|
|
82
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:00.000Z', '5m', 'add');
|
|
83
|
+
expect(result).toBe('2024-01-15T00:05:00.000Z');
|
|
84
|
+
});
|
|
85
|
+
it('should add hours', () => {
|
|
86
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:00.000Z', '2h', 'add');
|
|
87
|
+
expect(result).toBe('2024-01-15T02:00:00.000Z');
|
|
88
|
+
});
|
|
89
|
+
it('should add milliseconds', () => {
|
|
90
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:00.000Z', '500ms', 'add');
|
|
91
|
+
expect(result).toBe('2024-01-15T00:00:00.500Z');
|
|
92
|
+
});
|
|
93
|
+
it('should handle crossing day boundary', () => {
|
|
94
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T23:00:00.000Z', '2h', 'add');
|
|
95
|
+
expect(result).toBe('2024-01-16T01:00:00.000Z');
|
|
96
|
+
});
|
|
97
|
+
it('should add 168 hours (7 days equivalent)', () => {
|
|
98
|
+
const result = (0, time_value_resolver_1.applyDuration)('2024-01-15T00:00:00.000Z', '168h', 'add');
|
|
99
|
+
expect(result).toBe('2024-01-22T00:00:00.000Z');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe('resolveTimeValue', () => {
|
|
104
|
+
const baseState = {
|
|
105
|
+
workersOldest: '2024-01-01T00:00:00.000Z',
|
|
106
|
+
workersNewest: '2024-06-01T00:00:00.000Z',
|
|
107
|
+
};
|
|
108
|
+
describe('ABSOLUTE_TIME type', () => {
|
|
109
|
+
it('should return the value normalized to ISO 8601', () => {
|
|
110
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.ABSOLUTE_TIME, value: '2024-03-15T12:00:00Z' }, baseState);
|
|
111
|
+
expect(result).toBe('2024-03-15T12:00:00.000Z');
|
|
112
|
+
});
|
|
113
|
+
it('should normalize timestamps without milliseconds', () => {
|
|
114
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.ABSOLUTE_TIME, value: '2024-01-01T00:00:00Z' }, baseState);
|
|
115
|
+
expect(result).toBe('2024-01-01T00:00:00.000Z');
|
|
116
|
+
});
|
|
117
|
+
it('should preserve timestamps already in normalized format', () => {
|
|
118
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({
|
|
119
|
+
type: extraction_1.TimeValueType.ABSOLUTE_TIME,
|
|
120
|
+
value: '2024-06-15T10:30:00.000Z',
|
|
121
|
+
}, baseState);
|
|
122
|
+
expect(result).toBe('2024-06-15T10:30:00.000Z');
|
|
123
|
+
});
|
|
124
|
+
it('should throw if value is missing', () => {
|
|
125
|
+
expect(() => (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.ABSOLUTE_TIME }, baseState)).toThrow('must have a value');
|
|
126
|
+
});
|
|
127
|
+
it('should throw a descriptive error if value is an invalid timestamp', () => {
|
|
128
|
+
expect(() => (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.ABSOLUTE_TIME, value: 'not-a-date' }, baseState)).toThrow("invalid ISO 8601 timestamp: 'not-a-date'");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe('CURRENT_TIME type', () => {
|
|
132
|
+
it('should return current time as ISO string', () => {
|
|
133
|
+
const before = new Date().toISOString();
|
|
134
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.CURRENT_TIME }, baseState);
|
|
135
|
+
const after = new Date().toISOString();
|
|
136
|
+
expect(result >= before).toBe(true);
|
|
137
|
+
expect(result <= after).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('UNBOUNDED type', () => {
|
|
141
|
+
it('should return UNBOUNDED_DATE_TIME_VALUE', () => {
|
|
142
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.UNBOUNDED }, baseState);
|
|
143
|
+
expect(result).toBe(constants_1.UNBOUNDED_DATE_TIME_VALUE);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe('WORKERS_OLDEST type', () => {
|
|
147
|
+
it('should return workersOldest from state', () => {
|
|
148
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_OLDEST }, baseState);
|
|
149
|
+
expect(result).toBe('2024-01-01T00:00:00.000Z');
|
|
150
|
+
});
|
|
151
|
+
it('should return UNBOUNDED_DATE_TIME_VALUE if workersOldest is not set', () => {
|
|
152
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_OLDEST }, { workersOldest: '' });
|
|
153
|
+
expect(result).toBe(constants_1.UNBOUNDED_DATE_TIME_VALUE);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe('WORKERS_NEWEST type', () => {
|
|
157
|
+
it('should return workersNewest from state', () => {
|
|
158
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_NEWEST }, baseState);
|
|
159
|
+
expect(result).toBe('2024-06-01T00:00:00.000Z');
|
|
160
|
+
});
|
|
161
|
+
it('should throw if workersNewest is not set', () => {
|
|
162
|
+
expect(() => (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_NEWEST }, { workersNewest: '' })).toThrow('workersNewest is not set in state');
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('WORKERS_OLDEST_MINUS_WINDOW type', () => {
|
|
166
|
+
it('should subtract duration from workersOldest', () => {
|
|
167
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({
|
|
168
|
+
type: extraction_1.TimeValueType.WORKERS_OLDEST_MINUS_WINDOW,
|
|
169
|
+
value: '168h',
|
|
170
|
+
}, baseState);
|
|
171
|
+
expect(result).toBe('2023-12-25T00:00:00.000Z');
|
|
172
|
+
});
|
|
173
|
+
it('should subtract minutes from workersOldest', () => {
|
|
174
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({
|
|
175
|
+
type: extraction_1.TimeValueType.WORKERS_OLDEST_MINUS_WINDOW,
|
|
176
|
+
value: '30m',
|
|
177
|
+
}, baseState);
|
|
178
|
+
expect(result).toBe('2023-12-31T23:30:00.000Z');
|
|
179
|
+
});
|
|
180
|
+
it('should return UNBOUNDED_DATE_TIME_VALUE if workersOldest is not set', () => {
|
|
181
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({
|
|
182
|
+
type: extraction_1.TimeValueType.WORKERS_OLDEST_MINUS_WINDOW,
|
|
183
|
+
value: '2h',
|
|
184
|
+
}, { workersOldest: '' });
|
|
185
|
+
expect(result).toBe(constants_1.UNBOUNDED_DATE_TIME_VALUE);
|
|
186
|
+
});
|
|
187
|
+
it('should throw if value (duration) is missing', () => {
|
|
188
|
+
expect(() => (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_OLDEST_MINUS_WINDOW }, baseState)).toThrow('must have a value');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe('WORKERS_NEWEST_PLUS_WINDOW type', () => {
|
|
192
|
+
it('should add duration to workersNewest', () => {
|
|
193
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({
|
|
194
|
+
type: extraction_1.TimeValueType.WORKERS_NEWEST_PLUS_WINDOW,
|
|
195
|
+
value: '168h',
|
|
196
|
+
}, baseState);
|
|
197
|
+
expect(result).toBe('2024-06-08T00:00:00.000Z');
|
|
198
|
+
});
|
|
199
|
+
it('should add minutes to workersNewest', () => {
|
|
200
|
+
const result = (0, time_value_resolver_1.resolveTimeValue)({
|
|
201
|
+
type: extraction_1.TimeValueType.WORKERS_NEWEST_PLUS_WINDOW,
|
|
202
|
+
value: '30m',
|
|
203
|
+
}, baseState);
|
|
204
|
+
expect(result).toBe('2024-06-01T00:30:00.000Z');
|
|
205
|
+
});
|
|
206
|
+
it('should throw if workersNewest is not set', () => {
|
|
207
|
+
expect(() => (0, time_value_resolver_1.resolveTimeValue)({
|
|
208
|
+
type: extraction_1.TimeValueType.WORKERS_NEWEST_PLUS_WINDOW,
|
|
209
|
+
value: '2h',
|
|
210
|
+
}, { workersNewest: '' })).toThrow('workersNewest is not set in state');
|
|
211
|
+
});
|
|
212
|
+
it('should throw if value (duration) is missing', () => {
|
|
213
|
+
expect(() => (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_NEWEST_PLUS_WINDOW }, baseState)).toThrow('must have a value');
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
describe('Unknown type', () => {
|
|
217
|
+
it('should throw for unknown type', () => {
|
|
218
|
+
expect(() =>
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
220
|
+
(0, time_value_resolver_1.resolveTimeValue)({ type: 'unknown' }, baseState)).toThrow('Unknown TimeValueType');
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
describe('Real-world scenarios', () => {
|
|
224
|
+
const FIXED_NOW = '2026-02-26T15:30:00.000Z';
|
|
225
|
+
const scenarioState = {
|
|
226
|
+
workersOldest: '2024-01-01T00:00:00.000Z',
|
|
227
|
+
workersNewest: '2024-06-01T00:00:00.000Z',
|
|
228
|
+
};
|
|
229
|
+
beforeEach(() => {
|
|
230
|
+
jest.useFakeTimers();
|
|
231
|
+
jest.setSystemTime(new Date(FIXED_NOW));
|
|
232
|
+
});
|
|
233
|
+
afterEach(() => {
|
|
234
|
+
jest.useRealTimers();
|
|
235
|
+
});
|
|
236
|
+
it('Initial Import: UNBOUNDED start, CURRENT_TIME end', () => {
|
|
237
|
+
const start = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.UNBOUNDED }, scenarioState);
|
|
238
|
+
const end = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.CURRENT_TIME }, scenarioState);
|
|
239
|
+
expect(start).toBe(constants_1.UNBOUNDED_DATE_TIME_VALUE);
|
|
240
|
+
expect(end).toBe(FIXED_NOW);
|
|
241
|
+
});
|
|
242
|
+
it('Normal Import: WORKERS_NEWEST start, CURRENT_TIME end', () => {
|
|
243
|
+
const start = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_NEWEST }, scenarioState);
|
|
244
|
+
const end = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.CURRENT_TIME }, scenarioState);
|
|
245
|
+
expect(start).toBe('2024-06-01T00:00:00.000Z');
|
|
246
|
+
expect(end).toBe(FIXED_NOW);
|
|
247
|
+
});
|
|
248
|
+
it('POC Import: ABSOLUTE_TIME start, CURRENT_TIME end', () => {
|
|
249
|
+
const start = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.ABSOLUTE_TIME, value: '2024-01-01T00:00:00Z' }, scenarioState);
|
|
250
|
+
const end = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.CURRENT_TIME }, scenarioState);
|
|
251
|
+
expect(start).toBe('2024-01-01T00:00:00.000Z');
|
|
252
|
+
expect(end).toBe(FIXED_NOW);
|
|
253
|
+
});
|
|
254
|
+
it('Computer Import: WORKERS_OLDEST_MINUS_WINDOW start, WORKERS_OLDEST end', () => {
|
|
255
|
+
const start = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_OLDEST_MINUS_WINDOW, value: '168h' }, scenarioState);
|
|
256
|
+
const end = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.WORKERS_OLDEST }, scenarioState);
|
|
257
|
+
expect(start).toBe('2023-12-25T00:00:00.000Z');
|
|
258
|
+
expect(end).toBe('2024-01-01T00:00:00.000Z');
|
|
259
|
+
});
|
|
260
|
+
it('Reconciliation: ABSOLUTE_TIME start, ABSOLUTE_TIME end', () => {
|
|
261
|
+
const start = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.ABSOLUTE_TIME, value: '2026-01-01T00:00:00Z' }, scenarioState);
|
|
262
|
+
const end = (0, time_value_resolver_1.resolveTimeValue)({ type: extraction_1.TimeValueType.ABSOLUTE_TIME, value: '2026-03-31T23:59:59Z' }, scenarioState);
|
|
263
|
+
expect(start).toBe('2026-01-01T00:00:00.000Z');
|
|
264
|
+
expect(end).toBe('2026-03-31T23:59:59.000Z');
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios-client-internal.d.ts","sourceRoot":"","sources":["../../src/http/axios-client-internal.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,WAAW,+BAEf,CAAC;
|
|
1
|
+
{"version":3,"file":"axios-client-internal.d.ts","sourceRoot":"","sources":["../../src/http/axios-client-internal.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,WAAW,+BAEf,CAAC;AAyFH,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -51,6 +51,13 @@ exports.axiosClient = axiosClient;
|
|
|
51
51
|
((_g = error.response) === null || _g === void 0 ? void 0 : _g.status) !== 429) {
|
|
52
52
|
return true;
|
|
53
53
|
}
|
|
54
|
+
// Request timeout errors (ECONNABORTED) — axios-retry explicitly excludes
|
|
55
|
+
// ECONNABORTED from isNetworkError, so we handle it here separately.
|
|
56
|
+
// Axios only produces ECONNABORTED on client-side timeouts and browser
|
|
57
|
+
// cancellations, never on server responses, so no response guard is needed.
|
|
58
|
+
else if (error.code === 'ECONNABORTED') {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
54
61
|
// all other errors
|
|
55
62
|
else {
|
|
56
63
|
return false;
|
|
@@ -151,4 +151,25 @@ describe('Internal Axios Client', () => {
|
|
|
151
151
|
await expect(axios_client_internal_1.axiosClient.get(jest_setup_1.mockServer.baseUrl + '/test-endpoint')).rejects.toThrow();
|
|
152
152
|
expect(jest_setup_1.mockServer.getRequestCount('GET', '/test-endpoint')).toBe(1);
|
|
153
153
|
});
|
|
154
|
+
it('should retry on request timeout (ECONNABORTED)', async () => {
|
|
155
|
+
// The mock server delays the first response by 500ms, but we set a per-request
|
|
156
|
+
// timeout of 150ms so the first request times out with ECONNABORTED.
|
|
157
|
+
// After the 1 timed-out failure, the server responds immediately (no delay),
|
|
158
|
+
// so the retry succeeds quickly without waiting for full exponential backoff.
|
|
159
|
+
jest_setup_1.mockServer.setRoute({
|
|
160
|
+
path: '/test-endpoint',
|
|
161
|
+
method: 'GET',
|
|
162
|
+
status: 200,
|
|
163
|
+
retry: {
|
|
164
|
+
failureCount: 1,
|
|
165
|
+
errorStatus: 200,
|
|
166
|
+
delay: 500,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
await axios_client_internal_1.axiosClient.get(jest_setup_1.mockServer.baseUrl + '/test-endpoint', {
|
|
170
|
+
timeout: 150,
|
|
171
|
+
});
|
|
172
|
+
// Should have made 2 requests: 1 that timed out + 1 successful retry
|
|
173
|
+
expect(jest_setup_1.mockServer.getRequestCount('GET', '/test-endpoint')).toBe(2);
|
|
174
|
+
});
|
|
154
175
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios-client.d.ts","sourceRoot":"","sources":["../../src/http/axios-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAqB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"axios-client.d.ts","sourceRoot":"","sources":["../../src/http/axios-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAqB,MAAM,OAAO,CAAC;AAI1C,QAAA,MAAM,WAAW,+BAAiB,CAAC;AAuCnC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -30,15 +30,18 @@ exports.axiosClient = exports.axios = void 0;
|
|
|
30
30
|
const axios_1 = __importDefault(require("axios"));
|
|
31
31
|
exports.axios = axios_1.default;
|
|
32
32
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
33
|
+
const logger_context_1 = require("../logger/logger.context");
|
|
33
34
|
const axiosClient = axios_1.default.create();
|
|
34
35
|
exports.axiosClient = axiosClient;
|
|
35
36
|
(0, axios_retry_1.default)(axiosClient, {
|
|
36
37
|
retries: 5,
|
|
37
38
|
retryDelay: (retryCount, error) => {
|
|
38
|
-
var _a, _b, _c;
|
|
39
39
|
// exponential backoff algorithm: 1 * 2 ^ retryCount * 1000ms
|
|
40
40
|
const delay = axios_retry_1.default.exponentialDelay(retryCount, error, 1000);
|
|
41
|
-
|
|
41
|
+
(0, logger_context_1.runWithUserLogContext)(() => {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
return console.warn(`Request to ${(_a = error.config) === null || _a === void 0 ? void 0 : _a.url} failed with response status code ${(_b = error.response) === null || _b === void 0 ? void 0 : _b.status}. Method ${(_c = error.config) === null || _c === void 0 ? void 0 : _c.method}. Retry count: ${retryCount}. Retrying in ${Math.round(delay / 1000)}s.`);
|
|
44
|
+
});
|
|
42
45
|
return delay;
|
|
43
46
|
},
|
|
44
47
|
retryCondition: (error) => {
|
|
@@ -52,6 +55,6 @@ exports.axiosClient = axiosClient;
|
|
|
52
55
|
(_b = (_a = error.config) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? true : delete _b.authorization;
|
|
53
56
|
(_d = (_c = error.config) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? true : delete _d.Authorization;
|
|
54
57
|
delete error.request._header;
|
|
55
|
-
console.warn('Max retry times exceeded. Error', error);
|
|
58
|
+
(0, logger_context_1.runWithUserLogContext)(() => console.warn('Max retry times exceeded. Error', error));
|
|
56
59
|
},
|
|
57
60
|
});
|
package/dist/http/index.d.ts
CHANGED
package/dist/http/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/http/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './deprecated/demo-extractor';
|
|
3
|
-
export * from './deprecated/http/client';
|
|
4
|
-
export * from './deprecated/uploader';
|
|
5
|
-
export * from './http';
|
|
6
|
-
export * from './types';
|
|
7
|
-
export * from './common/install-initial-domain-mapping';
|
|
1
|
+
export { AirSyncDefaultItemTypes } from './common/constants';
|
|
8
2
|
export { ExtractionCommonError } from './common/errors';
|
|
3
|
+
export * from './common/install-initial-domain-mapping';
|
|
4
|
+
export * from './http';
|
|
5
|
+
export { serializeAxiosError } from './logger/logger';
|
|
6
|
+
export { MockServer } from './mock-server/mock-server';
|
|
7
|
+
export type { RequestInfo, RetryConfig, RouteConfig, } from './mock-server/mock-server.interfaces';
|
|
9
8
|
export { processTask } from './multithreading/process-task';
|
|
10
9
|
export { spawn } from './multithreading/spawn/spawn';
|
|
11
10
|
export { WorkerAdapter } from './multithreading/worker-adapter/worker-adapter';
|
|
11
|
+
export { createMockEvent, MOCK_SERVER_DEFAULT_URL } from './common/test-utils';
|
|
12
|
+
export type { DeepPartial } from './common/test-utils';
|
|
13
|
+
export * from './types';
|
|
12
14
|
export * from './types/workers';
|
|
13
|
-
export { formatAxiosError, serializeAxiosError } from './logger/logger';
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,cAAc,yCAAyC,CAAC;AACxD,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,YAAY,EACV,WAAW,EACX,WAAW,EACX,WAAW,GACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,21 +14,23 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
__exportStar(require("./deprecated/http/client"), exports);
|
|
21
|
-
__exportStar(require("./deprecated/uploader"), exports);
|
|
22
|
-
__exportStar(require("./http"), exports);
|
|
23
|
-
__exportStar(require("./types"), exports);
|
|
17
|
+
exports.MOCK_SERVER_DEFAULT_URL = exports.createMockEvent = exports.WorkerAdapter = exports.spawn = exports.processTask = exports.MockServer = exports.serializeAxiosError = exports.AirSyncDefaultItemTypes = void 0;
|
|
18
|
+
var constants_1 = require("./common/constants");
|
|
19
|
+
Object.defineProperty(exports, "AirSyncDefaultItemTypes", { enumerable: true, get: function () { return constants_1.AirSyncDefaultItemTypes; } });
|
|
24
20
|
__exportStar(require("./common/install-initial-domain-mapping"), exports);
|
|
21
|
+
__exportStar(require("./http"), exports);
|
|
22
|
+
var logger_1 = require("./logger/logger");
|
|
23
|
+
Object.defineProperty(exports, "serializeAxiosError", { enumerable: true, get: function () { return logger_1.serializeAxiosError; } });
|
|
24
|
+
var mock_server_1 = require("./mock-server/mock-server");
|
|
25
|
+
Object.defineProperty(exports, "MockServer", { enumerable: true, get: function () { return mock_server_1.MockServer; } });
|
|
25
26
|
var process_task_1 = require("./multithreading/process-task");
|
|
26
27
|
Object.defineProperty(exports, "processTask", { enumerable: true, get: function () { return process_task_1.processTask; } });
|
|
27
28
|
var spawn_1 = require("./multithreading/spawn/spawn");
|
|
28
29
|
Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { return spawn_1.spawn; } });
|
|
29
30
|
var worker_adapter_1 = require("./multithreading/worker-adapter/worker-adapter");
|
|
30
31
|
Object.defineProperty(exports, "WorkerAdapter", { enumerable: true, get: function () { return worker_adapter_1.WorkerAdapter; } });
|
|
32
|
+
var test_utils_1 = require("./common/test-utils");
|
|
33
|
+
Object.defineProperty(exports, "createMockEvent", { enumerable: true, get: function () { return test_utils_1.createMockEvent; } });
|
|
34
|
+
Object.defineProperty(exports, "MOCK_SERVER_DEFAULT_URL", { enumerable: true, get: function () { return test_utils_1.MOCK_SERVER_DEFAULT_URL; } });
|
|
35
|
+
__exportStar(require("./types"), exports);
|
|
31
36
|
__exportStar(require("./types/workers"), exports);
|
|
32
|
-
var logger_1 = require("./logger/logger");
|
|
33
|
-
Object.defineProperty(exports, "formatAxiosError", { enumerable: true, get: function () { return logger_1.formatAxiosError; } });
|
|
34
|
-
Object.defineProperty(exports, "serializeAxiosError", { enumerable: true, get: function () { return logger_1.serializeAxiosError; } });
|