@invoiceleaf/integration-sdk 1.5.0 → 2.0.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/dist/context/IntegrationContext.d.ts +105 -24
- package/dist/context/IntegrationContext.d.ts.map +1 -1
- package/dist/context/types.d.ts +98 -25
- package/dist/context/types.d.ts.map +1 -1
- package/dist/helpers/defineHandler.d.ts +120 -5
- package/dist/helpers/defineHandler.d.ts.map +1 -1
- package/dist/helpers/defineHandler.js +5 -5
- package/dist/helpers/defineHandler.js.map +1 -1
- package/dist/helpers/firstFinite.d.ts +13 -0
- package/dist/helpers/firstFinite.d.ts.map +1 -0
- package/dist/helpers/firstFinite.js +20 -0
- package/dist/helpers/firstFinite.js.map +1 -0
- package/dist/helpers/httpRetry.d.ts +70 -0
- package/dist/helpers/httpRetry.d.ts.map +1 -0
- package/dist/helpers/httpRetry.js +166 -0
- package/dist/helpers/httpRetry.js.map +1 -0
- package/dist/helpers/toBoundedInt.d.ts +14 -0
- package/dist/helpers/toBoundedInt.d.ts.map +1 -0
- package/dist/helpers/toBoundedInt.js +26 -0
- package/dist/helpers/toBoundedInt.js.map +1 -0
- package/dist/helpers/toDateOnly.d.ts +22 -0
- package/dist/helpers/toDateOnly.d.ts.map +1 -0
- package/dist/helpers/toDateOnly.js +40 -0
- package/dist/helpers/toDateOnly.js.map +1 -0
- package/dist/helpers/toErrorMessage.d.ts +14 -0
- package/dist/helpers/toErrorMessage.d.ts.map +1 -0
- package/dist/helpers/toErrorMessage.js +19 -0
- package/dist/helpers/toErrorMessage.js.map +1 -0
- package/dist/helpers/toFiniteNumber.d.ts +12 -0
- package/dist/helpers/toFiniteNumber.d.ts.map +1 -0
- package/dist/helpers/toFiniteNumber.js +17 -0
- package/dist/helpers/toFiniteNumber.js.map +1 -0
- package/dist/helpers/trimToUndefined.d.ts +12 -0
- package/dist/helpers/trimToUndefined.d.ts.map +1 -0
- package/dist/helpers/trimToUndefined.js +18 -0
- package/dist/helpers/trimToUndefined.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/types/actions.d.ts +2 -0
- package/dist/types/actions.d.ts.map +1 -1
- package/dist/types/invocation.d.ts +1 -1
- package/dist/types/invocation.d.ts.map +1 -1
- package/dist/types/manifest.d.ts +4 -2
- package/dist/types/manifest.d.ts.map +1 -1
- package/dist/types/triggers.d.ts +3 -2
- package/dist/types/triggers.d.ts.map +1 -1
- package/dist/types/triggers.js +1 -1
- package/dist/types/triggers.js.map +1 -1
- package/package.json +7 -5
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import type { IntegrationContext } from '../context/IntegrationContext.js';
|
|
2
|
+
/**
|
|
3
|
+
* Standard base result shape that all integration handlers should return.
|
|
4
|
+
*
|
|
5
|
+
* Integrations are free to extend this interface with domain-specific fields
|
|
6
|
+
* (e.g. `documentId`, `synced`, `failures`), but every handler result should
|
|
7
|
+
* at minimum include `success` so the runtime can determine outcome without
|
|
8
|
+
* inspecting opaque payloads.
|
|
9
|
+
*/
|
|
10
|
+
export interface HandlerResult {
|
|
11
|
+
/** Whether the handler completed successfully. */
|
|
12
|
+
success: boolean;
|
|
13
|
+
/** Human-readable summary (present on success or failure). */
|
|
14
|
+
message?: string;
|
|
15
|
+
/** Error description when `success` is false. */
|
|
16
|
+
error?: string;
|
|
17
|
+
/** If true the handler intentionally did no work (e.g. notification disabled). */
|
|
18
|
+
skipped?: boolean;
|
|
19
|
+
/** Machine-readable reason code when `skipped` is true. */
|
|
20
|
+
reason?: string;
|
|
21
|
+
/** Arbitrary structured details the caller may inspect. */
|
|
22
|
+
details?: Record<string, unknown>;
|
|
23
|
+
}
|
|
2
24
|
/**
|
|
3
25
|
* Handler function type.
|
|
4
26
|
*/
|
|
@@ -28,8 +50,8 @@ export type IntegrationHandler<TInput = unknown, TOutput = unknown, TConfig = Re
|
|
|
28
50
|
* @example
|
|
29
51
|
* ```typescript
|
|
30
52
|
* interface ExportInput {
|
|
31
|
-
*
|
|
32
|
-
*
|
|
53
|
+
* startDate: number;
|
|
54
|
+
* endDate: number;
|
|
33
55
|
* format: 'csv' | 'xml';
|
|
34
56
|
* }
|
|
35
57
|
*
|
|
@@ -40,11 +62,11 @@ export type IntegrationHandler<TInput = unknown, TOutput = unknown, TConfig = Re
|
|
|
40
62
|
*
|
|
41
63
|
* export const exportToDATEV = defineHandler<ExportInput, ExportOutput>(
|
|
42
64
|
* async (input, context) => {
|
|
43
|
-
* context.logger.info('Starting export', {
|
|
65
|
+
* context.logger.info('Starting export', { startDate: input.startDate });
|
|
44
66
|
*
|
|
45
67
|
* const documents = await context.data.listDocuments({
|
|
46
|
-
*
|
|
47
|
-
*
|
|
68
|
+
* startDate: input.startDate,
|
|
69
|
+
* endDate: input.endDate,
|
|
48
70
|
* });
|
|
49
71
|
*
|
|
50
72
|
* const exportResult = await context.data.createExport({
|
|
@@ -63,6 +85,10 @@ export type IntegrationHandler<TInput = unknown, TOutput = unknown, TConfig = Re
|
|
|
63
85
|
export declare function defineHandler<TInput = unknown, TOutput = unknown, TConfig = Record<string, unknown>>(handler: HandlerFunction<TInput, TOutput, TConfig>): HandlerFunction<TInput, TOutput, TConfig>;
|
|
64
86
|
/**
|
|
65
87
|
* Event handler input types for built-in events.
|
|
88
|
+
*
|
|
89
|
+
* Each input shape matches the normalized payload produced by the backend
|
|
90
|
+
* IntegrationEventDispatcher.normalizeEventPayload(). All event payloads
|
|
91
|
+
* include a `spaceId` field identifying the workspace where the event occurred.
|
|
66
92
|
*/
|
|
67
93
|
export interface DocumentCreatedInput {
|
|
68
94
|
documentId: string;
|
|
@@ -73,6 +99,7 @@ export interface DocumentCreatedInput {
|
|
|
73
99
|
companyId?: string;
|
|
74
100
|
categoryId?: string;
|
|
75
101
|
};
|
|
102
|
+
spaceId: string;
|
|
76
103
|
}
|
|
77
104
|
export interface DocumentUpdatedInput {
|
|
78
105
|
documentId: string;
|
|
@@ -82,6 +109,7 @@ export interface DocumentUpdatedInput {
|
|
|
82
109
|
status: string;
|
|
83
110
|
};
|
|
84
111
|
changes: string[];
|
|
112
|
+
spaceId: string;
|
|
85
113
|
}
|
|
86
114
|
export interface DocumentProcessedInput {
|
|
87
115
|
documentId: string;
|
|
@@ -93,9 +121,23 @@ export interface DocumentProcessedInput {
|
|
|
93
121
|
totalAmount?: number;
|
|
94
122
|
currency?: string;
|
|
95
123
|
};
|
|
124
|
+
spaceId: string;
|
|
96
125
|
}
|
|
97
126
|
export interface DocumentDeletedInput {
|
|
98
127
|
documentId: string;
|
|
128
|
+
spaceId: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Generic document event input for sync-on-event handlers.
|
|
132
|
+
* Supports both direct invocation (`documentId` at top level)
|
|
133
|
+
* and event payload shape (`document.id` nested).
|
|
134
|
+
*/
|
|
135
|
+
export interface DocumentEventInput {
|
|
136
|
+
documentId?: string;
|
|
137
|
+
document?: {
|
|
138
|
+
id?: string;
|
|
139
|
+
};
|
|
140
|
+
spaceId?: string;
|
|
99
141
|
}
|
|
100
142
|
export interface CompanyCreatedInput {
|
|
101
143
|
companyId: string;
|
|
@@ -104,6 +146,60 @@ export interface CompanyCreatedInput {
|
|
|
104
146
|
name: string;
|
|
105
147
|
taxId?: string;
|
|
106
148
|
};
|
|
149
|
+
spaceId: string;
|
|
150
|
+
}
|
|
151
|
+
export interface CompanyUpdatedInput {
|
|
152
|
+
companyId: string;
|
|
153
|
+
company: {
|
|
154
|
+
id: string;
|
|
155
|
+
name: string;
|
|
156
|
+
taxId?: string;
|
|
157
|
+
};
|
|
158
|
+
spaceId: string;
|
|
159
|
+
}
|
|
160
|
+
export interface CompanyDeletedInput {
|
|
161
|
+
companyId: string;
|
|
162
|
+
spaceId: string;
|
|
163
|
+
}
|
|
164
|
+
export interface TagCreatedInput {
|
|
165
|
+
tagId: string;
|
|
166
|
+
tag: {
|
|
167
|
+
id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
};
|
|
170
|
+
spaceId: string;
|
|
171
|
+
}
|
|
172
|
+
export interface TagUpdatedInput {
|
|
173
|
+
tagId: string;
|
|
174
|
+
tag: {
|
|
175
|
+
id: string;
|
|
176
|
+
name: string;
|
|
177
|
+
};
|
|
178
|
+
spaceId: string;
|
|
179
|
+
}
|
|
180
|
+
export interface TagDeletedInput {
|
|
181
|
+
tagId: string;
|
|
182
|
+
spaceId: string;
|
|
183
|
+
}
|
|
184
|
+
export interface CategoryCreatedInput {
|
|
185
|
+
categoryId: string;
|
|
186
|
+
category: {
|
|
187
|
+
id: string;
|
|
188
|
+
name: string;
|
|
189
|
+
};
|
|
190
|
+
spaceId: string;
|
|
191
|
+
}
|
|
192
|
+
export interface CategoryUpdatedInput {
|
|
193
|
+
categoryId: string;
|
|
194
|
+
category: {
|
|
195
|
+
id: string;
|
|
196
|
+
name: string;
|
|
197
|
+
};
|
|
198
|
+
spaceId: string;
|
|
199
|
+
}
|
|
200
|
+
export interface CategoryDeletedInput {
|
|
201
|
+
categoryId: string;
|
|
202
|
+
spaceId: string;
|
|
107
203
|
}
|
|
108
204
|
export interface ExportCompletedInput {
|
|
109
205
|
exportId: string;
|
|
@@ -114,6 +210,7 @@ export interface ExportCompletedInput {
|
|
|
114
210
|
downloadUrl?: string;
|
|
115
211
|
documentCount?: number;
|
|
116
212
|
};
|
|
213
|
+
spaceId: string;
|
|
117
214
|
}
|
|
118
215
|
export interface ReminderTriggeredInput {
|
|
119
216
|
reminderId: string;
|
|
@@ -129,6 +226,24 @@ export interface ReminderTriggeredInput {
|
|
|
129
226
|
aiMode?: 'off' | 'light_rewrite' | 'tool_enabled' | string;
|
|
130
227
|
};
|
|
131
228
|
}
|
|
229
|
+
export interface SpaceMemberAddedInput {
|
|
230
|
+
memberId: string;
|
|
231
|
+
member: {
|
|
232
|
+
id: string;
|
|
233
|
+
userId?: string;
|
|
234
|
+
role?: string;
|
|
235
|
+
};
|
|
236
|
+
spaceId: string;
|
|
237
|
+
}
|
|
238
|
+
export interface SpaceMemberRemovedInput {
|
|
239
|
+
memberId: string;
|
|
240
|
+
member: {
|
|
241
|
+
id: string;
|
|
242
|
+
userId?: string;
|
|
243
|
+
role?: string;
|
|
244
|
+
};
|
|
245
|
+
spaceId: string;
|
|
246
|
+
}
|
|
132
247
|
export interface WebhookInput {
|
|
133
248
|
headers: Record<string, string>;
|
|
134
249
|
body: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineHandler.d.ts","sourceRoot":"","sources":["../../src/helpers/defineHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"defineHandler.d.ts","sourceRoot":"","sources":["../../src/helpers/defineHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAM3E;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAMD;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CACpG,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,KACjC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;;;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|
|
7
|
+
* startDate: number;
|
|
8
|
+
* endDate: number;
|
|
9
9
|
* format: 'csv' | 'xml';
|
|
10
10
|
* }
|
|
11
11
|
*
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
*
|
|
17
17
|
* export const exportToDATEV = defineHandler<ExportInput, ExportOutput>(
|
|
18
18
|
* async (input, context) => {
|
|
19
|
-
* context.logger.info('Starting export', {
|
|
19
|
+
* context.logger.info('Starting export', { startDate: input.startDate });
|
|
20
20
|
*
|
|
21
21
|
* const documents = await context.data.listDocuments({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* startDate: input.startDate,
|
|
23
|
+
* endDate: input.endDate,
|
|
24
24
|
* });
|
|
25
25
|
*
|
|
26
26
|
* const exportResult = await context.data.createExport({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineHandler.js","sourceRoot":"","sources":["../../src/helpers/defineHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defineHandler.js","sourceRoot":"","sources":["../../src/helpers/defineHandler.ts"],"names":[],"mappings":"AAgEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAkD;IAElD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first finite number from the provided values, or `undefined` if none are finite.
|
|
3
|
+
*
|
|
4
|
+
* Useful for picking the best available numeric value from multiple optional sources
|
|
5
|
+
* (e.g. totalAmount, netAmount, amountDue).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* firstFinite(item.totalAmount, item.netAmount, 0); // => first finite value
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function firstFinite(...values: Array<number | undefined>): number | undefined;
|
|
13
|
+
//# sourceMappingURL=firstFinite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firstFinite.d.ts","sourceRoot":"","sources":["../../src/helpers/firstFinite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAOpF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first finite number from the provided values, or `undefined` if none are finite.
|
|
3
|
+
*
|
|
4
|
+
* Useful for picking the best available numeric value from multiple optional sources
|
|
5
|
+
* (e.g. totalAmount, netAmount, amountDue).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* firstFinite(item.totalAmount, item.netAmount, 0); // => first finite value
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function firstFinite(...values) {
|
|
13
|
+
for (const value of values) {
|
|
14
|
+
if (Number.isFinite(value)) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=firstFinite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firstFinite.js","sourceRoot":"","sources":["../../src/helpers/firstFinite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,MAAiC;IAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAe,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared HTTP retry logic for integration API clients.
|
|
3
|
+
*
|
|
4
|
+
* All integration clients share identical retry semantics:
|
|
5
|
+
* - GET requests retry on 429 / 500 / 502 / 503 / 504 and network errors.
|
|
6
|
+
* - Mutating requests (POST / PUT / DELETE) only retry on 429 (rate-limit).
|
|
7
|
+
* - Exponential backoff capped at 2 000 ms, up to 3 attempts.
|
|
8
|
+
* - Per-request timeout with AbortController.
|
|
9
|
+
*/
|
|
10
|
+
/** Status codes safe to retry for idempotent (GET) requests. */
|
|
11
|
+
export declare const RETRYABLE_STATUSES: Set<number>;
|
|
12
|
+
/** Status codes safe to retry for mutating (POST/PUT/DELETE) requests. */
|
|
13
|
+
export declare const SAFE_RETRY_STATUSES_FOR_MUTATING: Set<number>;
|
|
14
|
+
/** Default maximum number of request attempts. */
|
|
15
|
+
export declare const DEFAULT_MAX_REQUEST_ATTEMPTS = 3;
|
|
16
|
+
/** Default per-request timeout in milliseconds. */
|
|
17
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
18
|
+
/**
|
|
19
|
+
* Returns exponential-backoff delay for the given attempt, capped at 2 000 ms.
|
|
20
|
+
*
|
|
21
|
+
* Attempt 1 → 250 ms, attempt 2 → 500 ms, attempt 3+ → 2 000 ms.
|
|
22
|
+
*/
|
|
23
|
+
export declare function backoffMs(attempt: number): number;
|
|
24
|
+
/** Promise-based sleep. */
|
|
25
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Options for {@link requestWithRetry} and {@link requestResponseWithRetry}.
|
|
28
|
+
*/
|
|
29
|
+
export interface RequestWithRetryOptions {
|
|
30
|
+
/** HTTP method — determines whether the request is treated as idempotent. */
|
|
31
|
+
method?: string;
|
|
32
|
+
/** Maximum number of attempts (default: 3). */
|
|
33
|
+
maxAttempts?: number;
|
|
34
|
+
/** Per-request timeout in milliseconds (default: 30 000). */
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
/** Whether to include the response body in thrown errors (default: true). */
|
|
37
|
+
includeBodyInError?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Factory that turns a failed HTTP response into an error instance.
|
|
40
|
+
* If not provided, a generic `Error` is thrown.
|
|
41
|
+
*/
|
|
42
|
+
createError?: (message: string, status: number, responseBody: string) => Error & {
|
|
43
|
+
status: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Whether the request is semantically idempotent, regardless of HTTP method.
|
|
47
|
+
* Overrides the default GET-based heuristic. Useful for APIs like Dropbox
|
|
48
|
+
* that use POST for read operations.
|
|
49
|
+
*/
|
|
50
|
+
idempotent?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Executes an HTTP request with retry, backoff, and timeout.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const data = await requestWithRetry<MyResponse>(url, init, {
|
|
58
|
+
* method: 'POST',
|
|
59
|
+
* createError: (msg, status, body) => new MyApiError(msg, status, body),
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function requestWithRetry<T>(url: string, init: RequestInit, options?: RequestWithRetryOptions): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Like {@link requestWithRetry}, but returns the raw `Response` instead of
|
|
66
|
+
* parsing JSON. Useful for binary downloads where the caller needs to read
|
|
67
|
+
* headers or stream the body.
|
|
68
|
+
*/
|
|
69
|
+
export declare function requestResponseWithRetry(url: string, init: RequestInit, options?: RequestWithRetryOptions): Promise<Response>;
|
|
70
|
+
//# sourceMappingURL=httpRetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpRetry.d.ts","sourceRoot":"","sources":["../../src/helpers/httpRetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,aAAqC,CAAC;AAErE,0EAA0E;AAC1E,eAAO,MAAM,gCAAgC,aAAiB,CAAC;AAE/D,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,mDAAmD;AACnD,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,2BAA2B;AAC3B,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,KAAK,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACpG;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,CAAC,CAAC,CAuFZ;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,QAAQ,CAAC,CAyEnB"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared HTTP retry logic for integration API clients.
|
|
3
|
+
*
|
|
4
|
+
* All integration clients share identical retry semantics:
|
|
5
|
+
* - GET requests retry on 429 / 500 / 502 / 503 / 504 and network errors.
|
|
6
|
+
* - Mutating requests (POST / PUT / DELETE) only retry on 429 (rate-limit).
|
|
7
|
+
* - Exponential backoff capped at 2 000 ms, up to 3 attempts.
|
|
8
|
+
* - Per-request timeout with AbortController.
|
|
9
|
+
*/
|
|
10
|
+
/** Status codes safe to retry for idempotent (GET) requests. */
|
|
11
|
+
export const RETRYABLE_STATUSES = new Set([429, 500, 502, 503, 504]);
|
|
12
|
+
/** Status codes safe to retry for mutating (POST/PUT/DELETE) requests. */
|
|
13
|
+
export const SAFE_RETRY_STATUSES_FOR_MUTATING = new Set([429]);
|
|
14
|
+
/** Default maximum number of request attempts. */
|
|
15
|
+
export const DEFAULT_MAX_REQUEST_ATTEMPTS = 3;
|
|
16
|
+
/** Default per-request timeout in milliseconds. */
|
|
17
|
+
export const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
|
|
18
|
+
/**
|
|
19
|
+
* Returns exponential-backoff delay for the given attempt, capped at 2 000 ms.
|
|
20
|
+
*
|
|
21
|
+
* Attempt 1 → 250 ms, attempt 2 → 500 ms, attempt 3+ → 2 000 ms.
|
|
22
|
+
*/
|
|
23
|
+
export function backoffMs(attempt) {
|
|
24
|
+
return Math.min(2000, 250 * 2 ** (attempt - 1));
|
|
25
|
+
}
|
|
26
|
+
/** Promise-based sleep. */
|
|
27
|
+
export function sleep(ms) {
|
|
28
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Executes an HTTP request with retry, backoff, and timeout.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const data = await requestWithRetry<MyResponse>(url, init, {
|
|
36
|
+
* method: 'POST',
|
|
37
|
+
* createError: (msg, status, body) => new MyApiError(msg, status, body),
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export async function requestWithRetry(url, init, options = {}) {
|
|
42
|
+
const { method = 'GET', maxAttempts = DEFAULT_MAX_REQUEST_ATTEMPTS, timeoutMs = DEFAULT_REQUEST_TIMEOUT_MS, includeBodyInError = true, createError, idempotent, } = options;
|
|
43
|
+
let lastError = null;
|
|
44
|
+
const isIdempotent = idempotent ?? method === 'GET';
|
|
45
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
48
|
+
// Combine the timeout signal with any caller-supplied signal so that
|
|
49
|
+
// either one can abort the request.
|
|
50
|
+
const signals = [controller.signal];
|
|
51
|
+
if (init.signal)
|
|
52
|
+
signals.push(init.signal);
|
|
53
|
+
const combinedSignal = signals.length > 1 ? AbortSignal.any(signals) : controller.signal;
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(url, { ...init, signal: combinedSignal });
|
|
56
|
+
const body = await response.text();
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
const error = createError
|
|
59
|
+
? createError(`API request failed with status ${response.status}`, response.status, includeBodyInError ? body : '')
|
|
60
|
+
: Object.assign(new Error(`API request failed with status ${response.status}`), { status: response.status, responseBody: includeBodyInError ? body : '' });
|
|
61
|
+
const canRetryStatus = isIdempotent
|
|
62
|
+
? RETRYABLE_STATUSES.has(response.status)
|
|
63
|
+
: SAFE_RETRY_STATUSES_FOR_MUTATING.has(response.status);
|
|
64
|
+
if (attempt < maxAttempts && canRetryStatus) {
|
|
65
|
+
await sleep(backoffMs(attempt));
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
if (body.length === 0) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(body);
|
|
75
|
+
}
|
|
76
|
+
catch (parseError) {
|
|
77
|
+
const msg = `Failed to parse API response: ${String(parseError)}`;
|
|
78
|
+
throw createError
|
|
79
|
+
? createError(msg, response.status, body.slice(0, 500))
|
|
80
|
+
: new Error(msg);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
lastError = error;
|
|
85
|
+
const errorStatus = error.status;
|
|
86
|
+
if (typeof errorStatus === 'number') {
|
|
87
|
+
const canRetryStatus = isIdempotent
|
|
88
|
+
? RETRYABLE_STATUSES.has(errorStatus)
|
|
89
|
+
: SAFE_RETRY_STATUSES_FOR_MUTATING.has(errorStatus);
|
|
90
|
+
if (attempt < maxAttempts && canRetryStatus) {
|
|
91
|
+
await sleep(backoffMs(attempt));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (isIdempotent && attempt < maxAttempts) {
|
|
96
|
+
// Network errors — only retry for idempotent requests.
|
|
97
|
+
await sleep(backoffMs(attempt));
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
clearTimeout(timeout);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw lastError ?? new Error('Request failed after retries.');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Like {@link requestWithRetry}, but returns the raw `Response` instead of
|
|
110
|
+
* parsing JSON. Useful for binary downloads where the caller needs to read
|
|
111
|
+
* headers or stream the body.
|
|
112
|
+
*/
|
|
113
|
+
export async function requestResponseWithRetry(url, init, options = {}) {
|
|
114
|
+
const { method = 'GET', maxAttempts = DEFAULT_MAX_REQUEST_ATTEMPTS, timeoutMs = DEFAULT_REQUEST_TIMEOUT_MS, includeBodyInError = true, createError, idempotent, } = options;
|
|
115
|
+
let lastError = null;
|
|
116
|
+
const isIdempotent = idempotent ?? method === 'GET';
|
|
117
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
118
|
+
const controller = new AbortController();
|
|
119
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
120
|
+
const signals = [controller.signal];
|
|
121
|
+
if (init.signal)
|
|
122
|
+
signals.push(init.signal);
|
|
123
|
+
const combinedSignal = signals.length > 1 ? AbortSignal.any(signals) : controller.signal;
|
|
124
|
+
try {
|
|
125
|
+
const response = await fetch(url, { ...init, signal: combinedSignal });
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
const body = includeBodyInError ? await response.text() : '';
|
|
128
|
+
const error = createError
|
|
129
|
+
? createError(`API request failed with status ${response.status}`, response.status, body)
|
|
130
|
+
: Object.assign(new Error(`API request failed with status ${response.status}`), { status: response.status, responseBody: body });
|
|
131
|
+
const canRetryStatus = isIdempotent
|
|
132
|
+
? RETRYABLE_STATUSES.has(response.status)
|
|
133
|
+
: SAFE_RETRY_STATUSES_FOR_MUTATING.has(response.status);
|
|
134
|
+
if (attempt < maxAttempts && canRetryStatus) {
|
|
135
|
+
await sleep(backoffMs(attempt));
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
return response;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
lastError = error;
|
|
144
|
+
const errorStatus = error.status;
|
|
145
|
+
if (typeof errorStatus === 'number') {
|
|
146
|
+
const canRetryStatus = isIdempotent
|
|
147
|
+
? RETRYABLE_STATUSES.has(errorStatus)
|
|
148
|
+
: SAFE_RETRY_STATUSES_FOR_MUTATING.has(errorStatus);
|
|
149
|
+
if (attempt < maxAttempts && canRetryStatus) {
|
|
150
|
+
await sleep(backoffMs(attempt));
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (isIdempotent && attempt < maxAttempts) {
|
|
155
|
+
await sleep(backoffMs(attempt));
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
clearTimeout(timeout);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
throw lastError ?? new Error('Request failed after retries.');
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=httpRetry.js.map
|
|
@@ -0,0 +1 @@
|
|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O,WAAW,KAAK,QAAQ,EAAE,CAAC;gBACpC,MAAM,cAAc,GAAG,YAAY;oBACjC,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC;oBACrC,CAAC,CAAC,gCAAgC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBACtD,IAAI,OAAO,GAAG,WAAW,IAAI,cAAc,EAAE,CAAC;oBAC5C,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;oBAChC,SAAS;gBACX,CAAC;YACH,CAAC;iBAAM,IAAI,YAAY,IAAI,OAAO,GAAG,WAAW,EAAE,CAAC;gBACjD,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;gBAChC,SAAS;YACX,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a numeric value to an integer within the given `[min, max]` range.
|
|
3
|
+
*
|
|
4
|
+
* Returns `fallback` when the input is not a finite number.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* toBoundedInt(7.9, 5, 1, 10); // => 7
|
|
9
|
+
* toBoundedInt(undefined, 5, 1, 10); // => 5
|
|
10
|
+
* toBoundedInt(100, 5, 1, 10); // => 10
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function toBoundedInt(value: number | undefined, fallback: number, min: number, max: number): number;
|
|
14
|
+
//# sourceMappingURL=toBoundedInt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBoundedInt.d.ts","sourceRoot":"","sources":["../../src/helpers/toBoundedInt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,MAAM,CAYR"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a numeric value to an integer within the given `[min, max]` range.
|
|
3
|
+
*
|
|
4
|
+
* Returns `fallback` when the input is not a finite number.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* toBoundedInt(7.9, 5, 1, 10); // => 7
|
|
9
|
+
* toBoundedInt(undefined, 5, 1, 10); // => 5
|
|
10
|
+
* toBoundedInt(100, 5, 1, 10); // => 10
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function toBoundedInt(value, fallback, min, max) {
|
|
14
|
+
if (!Number.isFinite(value)) {
|
|
15
|
+
return fallback;
|
|
16
|
+
}
|
|
17
|
+
const rounded = Math.floor(value);
|
|
18
|
+
if (rounded < min) {
|
|
19
|
+
return min;
|
|
20
|
+
}
|
|
21
|
+
if (rounded > max) {
|
|
22
|
+
return max;
|
|
23
|
+
}
|
|
24
|
+
return rounded;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=toBoundedInt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBoundedInt.js","sourceRoot":"","sources":["../../src/helpers/toBoundedInt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAyB,EACzB,QAAgB,EAChB,GAAW,EACX,GAAW;IAEX,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAe,CAAC,CAAC;IAC5C,IAAI,OAAO,GAAG,GAAG,EAAE,CAAC;QAClB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,OAAO,GAAG,GAAG,EAAE,CAAC;QAClB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a date string to `YYYY-MM-DD` format, or returns `undefined` if invalid.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* toDateOnly('2024-03-15T10:30:00Z'); // => '2024-03-15'
|
|
7
|
+
* toDateOnly('not-a-date'); // => undefined
|
|
8
|
+
* toDateOnly(undefined); // => undefined
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function toDateOnly(value: string | undefined): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Converts a Unix timestamp (milliseconds) to `YYYY-MM-DD` format, or returns `undefined` if invalid.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* toDateOnlyFromTimestamp(1710489600000); // => '2024-03-15'
|
|
18
|
+
* toDateOnlyFromTimestamp(undefined); // => undefined
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function toDateOnlyFromTimestamp(value: number | undefined): string | undefined;
|
|
22
|
+
//# sourceMappingURL=toDateOnly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toDateOnly.d.ts","sourceRoot":"","sources":["../../src/helpers/toDateOnly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CASxE;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CASrF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a date string to `YYYY-MM-DD` format, or returns `undefined` if invalid.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* toDateOnly('2024-03-15T10:30:00Z'); // => '2024-03-15'
|
|
7
|
+
* toDateOnly('not-a-date'); // => undefined
|
|
8
|
+
* toDateOnly(undefined); // => undefined
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export function toDateOnly(value) {
|
|
12
|
+
if (!value) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const date = new Date(value);
|
|
16
|
+
if (Number.isNaN(date.getTime())) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return date.toISOString().slice(0, 10);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Converts a Unix timestamp (milliseconds) to `YYYY-MM-DD` format, or returns `undefined` if invalid.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* toDateOnlyFromTimestamp(1710489600000); // => '2024-03-15'
|
|
27
|
+
* toDateOnlyFromTimestamp(undefined); // => undefined
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function toDateOnlyFromTimestamp(value) {
|
|
31
|
+
if (!Number.isFinite(value)) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const date = new Date(value);
|
|
35
|
+
if (Number.isNaN(date.getTime())) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return date.toISOString().slice(0, 10);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=toDateOnly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toDateOnly.js","sourceRoot":"","sources":["../../src/helpers/toDateOnly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,KAAyB;IAClD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAyB;IAC/D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAe,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACzC,CAAC"}
|