@siglo/http 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +38 -2
- package/dist/client/fetch.d.ts +46 -0
- package/dist/client/fetch.d.ts.map +1 -0
- package/dist/client/fetch.js +330 -0
- package/dist/client/fetch.js.map +1 -0
- package/dist/client/retry.d.ts +30 -0
- package/dist/client/retry.d.ts.map +1 -0
- package/dist/client/retry.js +82 -0
- package/dist/client/retry.js.map +1 -0
- package/dist/client/trace.d.ts +23 -0
- package/dist/client/trace.d.ts.map +1 -0
- package/dist/client/trace.js +103 -0
- package/dist/client/trace.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/policy/asl-bridge.d.ts +21 -0
- package/dist/policy/asl-bridge.d.ts.map +1 -0
- package/dist/policy/asl-bridge.js +82 -0
- package/dist/policy/asl-bridge.js.map +1 -0
- package/dist/schema/validator.d.ts +14 -0
- package/dist/schema/validator.d.ts.map +1 -0
- package/dist/schema/validator.js +154 -0
- package/dist/schema/validator.js.map +1 -0
- package/dist/step.d.ts +15 -0
- package/dist/step.d.ts.map +1 -0
- package/dist/step.js +165 -0
- package/dist/step.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +18 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-agent.d.ts +64 -0
- package/dist/testing/mock-agent.d.ts.map +1 -0
- package/dist/testing/mock-agent.js +233 -0
- package/dist/testing/mock-agent.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Jerico de guzman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @siglo/http
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Enterprise-grade, resilient, W3C-traced HTTP client steps for Siglo workflows.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
- **Coordinated Retries & Backoff**: Smart status code classifier (`429`, `502`, `503`, `504`) with `Retry-After` parsing (both integer seconds and RFC 1123 HTTP dates) and full jitter.
|
|
8
|
+
- **ASL Network Egress Perimeter**: Automatic validation against Siglo's AsyncLocalStorage (ASL) network security policies (`allowNetwork`) with host verification.
|
|
9
|
+
- **W3C Distributed Tracing**: Automatic injection of W3C `traceparent` and `tracestate` headers linked to active OpenTelemetry spans.
|
|
10
|
+
- **Standard Schema Validation**: Native validation of request payloads and response bodies with Standard Schema (`zod`, `valibot`, `arktype`, etc.).
|
|
11
|
+
- **Sagas & Rollback Compensation**: Declarative `.compensateWithHttp()` automatically registers REST rollbacks in Siglo's CompensationManager.
|
|
12
|
+
- **Deterministic Testing**: `@siglo/http/testing` includes `createMockHttpServer` for mocking requests without launching network listeners.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @siglo/http
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Basic Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { flow } from '@siglo/core';
|
|
24
|
+
import { httpStep } from '@siglo/http';
|
|
25
|
+
|
|
26
|
+
export const getUser = httpStep('getUser', {
|
|
27
|
+
url: 'https://api.example.com/users/123',
|
|
28
|
+
method: 'GET',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const workflow = flow(getUser);
|
|
32
|
+
const result = await workflow.run({});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The package re-exports the official `StandardSchemaV1` and `StandardJSONSchemaV1`
|
|
36
|
+
types from `@standard-schema/spec`, including `StandardSchemaV1.InferInput<S>` and
|
|
37
|
+
`StandardSchemaV1.InferOutput<S>`. Runtime validation preserves transformed values
|
|
38
|
+
(including `undefined`) and supports structured diagnostic path segments. Native
|
|
39
|
+
JSON Schema conversion is a separate capability from runtime validation.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { InspectionCapturePolicy } from '@siglo/core';
|
|
2
|
+
import { Span } from '@opentelemetry/api';
|
|
3
|
+
import { HttpMethod, HttpMetadata } from '../types';
|
|
4
|
+
export interface ExecuteHttpRequestOptions {
|
|
5
|
+
capture?: InspectionCapturePolicy;
|
|
6
|
+
stepName: string;
|
|
7
|
+
url: string;
|
|
8
|
+
method?: HttpMethod;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
11
|
+
body?: unknown;
|
|
12
|
+
responseType?: 'json' | 'text' | 'blob' | 'arrayBuffer';
|
|
13
|
+
retryOnStatus?: number[];
|
|
14
|
+
maxRetries?: number;
|
|
15
|
+
allowNotFound?: boolean;
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
signal?: any;
|
|
18
|
+
span?: Span;
|
|
19
|
+
clock?: {
|
|
20
|
+
now(): number;
|
|
21
|
+
};
|
|
22
|
+
sleep?: (ms: number) => Promise<void>;
|
|
23
|
+
customFetch?: typeof globalThis.fetch;
|
|
24
|
+
}
|
|
25
|
+
export interface HttpResponseResult<T = any> {
|
|
26
|
+
data: T;
|
|
27
|
+
metadata: HttpMetadata;
|
|
28
|
+
notFound?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves an AbortSignal from a candidate which could be an AbortSignal or a Siglo getter function.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveAbortSignal(candidate: any): AbortSignal | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Builds the full URL including query parameters.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildUrlWithQuery(baseUrl: string, query?: Record<string, string | number | boolean | undefined>): string;
|
|
38
|
+
/**
|
|
39
|
+
* Formats a cURL command string representation for debugging and observability.
|
|
40
|
+
*/
|
|
41
|
+
export declare function generateCurlCommand(url: string, method: string, headers: Record<string, string>, body: unknown): string;
|
|
42
|
+
/**
|
|
43
|
+
* Core resilient HTTP client execution with retry, backoff, tracing, and timeout.
|
|
44
|
+
*/
|
|
45
|
+
export declare function executeHttpRequest<T = any>(options: ExecuteHttpRequestOptions): Promise<HttpResponseResult<T>>;
|
|
46
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["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EG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,GAAG,GAAG,WAAW,GAAG,SAAS,CAmB1E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAC5D,MAAM,CA0BR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,IAAI,EAAE,OAAO,GACZ,MAAM,CAkBR;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAC9C,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAwRhC"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAbortSignal = resolveAbortSignal;
|
|
4
|
+
exports.buildUrlWithQuery = buildUrlWithQuery;
|
|
5
|
+
exports.generateCurlCommand = generateCurlCommand;
|
|
6
|
+
exports.executeHttpRequest = executeHttpRequest;
|
|
7
|
+
const core_1 = require("@siglo/core");
|
|
8
|
+
const core_2 = require("@siglo/core");
|
|
9
|
+
const retry_1 = require("./retry");
|
|
10
|
+
const trace_1 = require("./trace");
|
|
11
|
+
const asl_bridge_1 = require("../policy/asl-bridge");
|
|
12
|
+
/**
|
|
13
|
+
* Resolves an AbortSignal from a candidate which could be an AbortSignal or a Siglo getter function.
|
|
14
|
+
*/
|
|
15
|
+
function resolveAbortSignal(candidate) {
|
|
16
|
+
if (!candidate)
|
|
17
|
+
return undefined;
|
|
18
|
+
if (typeof candidate === 'function') {
|
|
19
|
+
try {
|
|
20
|
+
const res = candidate();
|
|
21
|
+
if (res && (res instanceof AbortSignal || typeof res.addEventListener === 'function')) {
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Ignore getter call error
|
|
27
|
+
}
|
|
28
|
+
if (candidate.val && (candidate.val instanceof AbortSignal || typeof candidate.val.addEventListener === 'function')) {
|
|
29
|
+
return candidate.val;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (candidate instanceof AbortSignal || typeof candidate.addEventListener === 'function') {
|
|
33
|
+
return candidate;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds the full URL including query parameters.
|
|
39
|
+
*/
|
|
40
|
+
function buildUrlWithQuery(baseUrl, query) {
|
|
41
|
+
if (!query || Object.keys(query).length === 0) {
|
|
42
|
+
return baseUrl;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(baseUrl);
|
|
46
|
+
for (const [key, value] of Object.entries(query)) {
|
|
47
|
+
if (value !== undefined) {
|
|
48
|
+
url.searchParams.append(key, String(value));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return url.toString();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// If not a full URL (e.g. relative), use string concatenation
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
for (const [key, value] of Object.entries(query)) {
|
|
57
|
+
if (value !== undefined) {
|
|
58
|
+
params.append(key, String(value));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const queryString = params.toString();
|
|
62
|
+
if (!queryString)
|
|
63
|
+
return baseUrl;
|
|
64
|
+
const separator = baseUrl.includes('?') ? '&' : '?';
|
|
65
|
+
return `${baseUrl}${separator}${queryString}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Formats a cURL command string representation for debugging and observability.
|
|
70
|
+
*/
|
|
71
|
+
function generateCurlCommand(url, method, headers, body) {
|
|
72
|
+
const parts = ['curl', '-X', method.toUpperCase(), `'${url}'`];
|
|
73
|
+
for (const [key, val] of Object.entries(headers)) {
|
|
74
|
+
// Redact Authorization headers or sensitive tokens in cURL string for security
|
|
75
|
+
const sanitizedVal = key.toLowerCase() === 'authorization' || key.toLowerCase() === 'proxy-authorization'
|
|
76
|
+
? '[REDACTED]'
|
|
77
|
+
: val;
|
|
78
|
+
parts.push(`-H '${key}: ${sanitizedVal}'`);
|
|
79
|
+
}
|
|
80
|
+
if (body !== undefined && body !== null && method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'HEAD') {
|
|
81
|
+
const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
|
|
82
|
+
parts.push(`-d '${bodyStr}'`);
|
|
83
|
+
}
|
|
84
|
+
return parts.join(' ');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Core resilient HTTP client execution with retry, backoff, tracing, and timeout.
|
|
88
|
+
*/
|
|
89
|
+
async function executeHttpRequest(options) {
|
|
90
|
+
const { stepName, url: rawUrl, method = 'GET', headers: rawHeaders = {}, query, body, responseType = 'json', retryOnStatus = [...retry_1.DEFAULT_RETRY_STATUSES], maxRetries = 3, allowNotFound = false, timeoutMs, signal: rawSignal, span: customSpan, clock, sleep: customSleep, customFetch } = options;
|
|
91
|
+
const externalSignal = resolveAbortSignal(rawSignal);
|
|
92
|
+
const fetchFn = customFetch || globalThis.fetch;
|
|
93
|
+
const sleepFn = customSleep || ((ms) => new Promise(resolve => setTimeout(resolve, ms)));
|
|
94
|
+
const nowFn = clock ? clock.now.bind(clock) : () => Date.now();
|
|
95
|
+
const finalUrl = buildUrlWithQuery(rawUrl, query);
|
|
96
|
+
const hostInfo = (0, asl_bridge_1.extractHostInfo)(finalUrl);
|
|
97
|
+
const normalizedMethod = method.toUpperCase();
|
|
98
|
+
const headers = { ...rawHeaders };
|
|
99
|
+
// Set default Content-Type for JSON body if not present
|
|
100
|
+
let requestBody = undefined;
|
|
101
|
+
if (body !== undefined && body !== null && normalizedMethod !== 'GET' && normalizedMethod !== 'HEAD') {
|
|
102
|
+
const hasContentType = Object.keys(headers).some(k => k.toLowerCase() === 'content-type');
|
|
103
|
+
if (typeof body === 'object' && !(body instanceof ArrayBuffer) && !(body instanceof Uint8Array)) {
|
|
104
|
+
if (!hasContentType) {
|
|
105
|
+
headers['Content-Type'] = 'application/json';
|
|
106
|
+
}
|
|
107
|
+
requestBody = JSON.stringify(body);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
requestBody = body;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// W3C Trace context injection
|
|
114
|
+
(0, trace_1.injectTraceHeaders)(headers, customSpan);
|
|
115
|
+
const traceId = (0, trace_1.getActiveTraceId)(customSpan);
|
|
116
|
+
// Record active span attributes
|
|
117
|
+
(0, trace_1.recordRequestSpanAttributes)(normalizedMethod, finalUrl, hostInfo.hostname, customSpan);
|
|
118
|
+
const cUrl = generateCurlCommand(finalUrl, normalizedMethod, headers, body);
|
|
119
|
+
let retryAttempts = 0;
|
|
120
|
+
const startTime = nowFn();
|
|
121
|
+
while (true) {
|
|
122
|
+
const attemptStarted = nowFn();
|
|
123
|
+
let responseObserved = false;
|
|
124
|
+
let inspected = false;
|
|
125
|
+
let responseStatus;
|
|
126
|
+
const content = {
|
|
127
|
+
...(0, core_1.captureInspection)(options.capture, 'requestHeaders', rawHeaders),
|
|
128
|
+
...(0, core_1.captureInspection)(options.capture, 'requestBody', body),
|
|
129
|
+
};
|
|
130
|
+
const inspectAttempt = (status, retryDelayMs, retryAfterMs, retryDelaySource, failed = false) => {
|
|
131
|
+
inspected = true;
|
|
132
|
+
(0, core_1.recordInspection)({
|
|
133
|
+
version: 1, kind: 'http', outcome: !failed && status !== undefined && status < 400 ? 'success' : 'failure',
|
|
134
|
+
method: normalizedMethod, url: finalUrl, status, requestAttempt: retryAttempts + 1,
|
|
135
|
+
content, durationMs: Math.max(0, nowFn() - attemptStarted), retryDelayMs, retryAfterMs, retryDelaySource, traceId, policy: status === undefined ? 'unknown' : 'allowed'
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
// Setup cooperative AbortController combining externalSignal and step timeout
|
|
139
|
+
const controller = new AbortController();
|
|
140
|
+
let timeoutId = undefined;
|
|
141
|
+
let timedOut = false;
|
|
142
|
+
if (timeoutMs && timeoutMs > 0) {
|
|
143
|
+
timeoutId = setTimeout(() => {
|
|
144
|
+
timedOut = true;
|
|
145
|
+
controller.abort(new Error(`HTTP request timed out after ${timeoutMs}ms`));
|
|
146
|
+
}, timeoutMs);
|
|
147
|
+
}
|
|
148
|
+
const onExternalAbort = () => {
|
|
149
|
+
controller.abort(externalSignal?.reason);
|
|
150
|
+
};
|
|
151
|
+
if (externalSignal) {
|
|
152
|
+
if (externalSignal.aborted) {
|
|
153
|
+
controller.abort(externalSignal.reason);
|
|
154
|
+
}
|
|
155
|
+
else if (typeof externalSignal.addEventListener === 'function') {
|
|
156
|
+
externalSignal.addEventListener('abort', onExternalAbort, { once: true });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const response = await fetchFn(finalUrl, {
|
|
161
|
+
method: normalizedMethod,
|
|
162
|
+
headers,
|
|
163
|
+
body: requestBody,
|
|
164
|
+
signal: controller.signal
|
|
165
|
+
});
|
|
166
|
+
if (timeoutId)
|
|
167
|
+
clearTimeout(timeoutId);
|
|
168
|
+
if (externalSignal && typeof externalSignal.removeEventListener === 'function') {
|
|
169
|
+
externalSignal.removeEventListener('abort', onExternalAbort);
|
|
170
|
+
}
|
|
171
|
+
responseObserved = true;
|
|
172
|
+
responseStatus = response.status;
|
|
173
|
+
(0, trace_1.recordResponseSpanAttributes)(response.status, customSpan);
|
|
174
|
+
const durationMs = nowFn() - startTime;
|
|
175
|
+
const responseHeaders = {};
|
|
176
|
+
response.headers.forEach((val, key) => {
|
|
177
|
+
responseHeaders[key] = val;
|
|
178
|
+
});
|
|
179
|
+
Object.assign(content, (0, core_1.captureInspection)(options.capture, 'responseHeaders', responseHeaders));
|
|
180
|
+
const metadata = {
|
|
181
|
+
status: response.status,
|
|
182
|
+
statusText: response.statusText,
|
|
183
|
+
durationMs,
|
|
184
|
+
url: finalUrl,
|
|
185
|
+
method: normalizedMethod,
|
|
186
|
+
headers: responseHeaders,
|
|
187
|
+
traceId,
|
|
188
|
+
retryAttempts,
|
|
189
|
+
cUrl
|
|
190
|
+
};
|
|
191
|
+
const retryAfterMs = (0, retry_1.parseRetryAfter)(response.headers.get('retry-after'), nowFn);
|
|
192
|
+
// Handle 404 with allowNotFound
|
|
193
|
+
if (response.status === 404 && allowNotFound) {
|
|
194
|
+
inspectAttempt(response.status);
|
|
195
|
+
return {
|
|
196
|
+
data: null,
|
|
197
|
+
notFound: true,
|
|
198
|
+
metadata
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// Check if status is retryable (e.g. 429, 502, 503, 504)
|
|
202
|
+
if ((0, retry_1.isRetryableStatus)(response.status, retryOnStatus)) {
|
|
203
|
+
if (retryAttempts < maxRetries) {
|
|
204
|
+
const delayMs = retryAfterMs ?? (0, retry_1.calculateBackoffDelay)(retryAttempts + 1);
|
|
205
|
+
inspectAttempt(response.status, delayMs, retryAfterMs, retryAfterMs === undefined ? 'backoff' : 'retry-after');
|
|
206
|
+
retryAttempts++;
|
|
207
|
+
await sleepFn(delayMs);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
// Exhausted retries on retryable status
|
|
211
|
+
const errorText = await response.text().catch(() => '');
|
|
212
|
+
Object.assign(content, (0, core_1.captureInspection)(options.capture, 'responseBody', errorText));
|
|
213
|
+
inspectAttempt(response.status, undefined, retryAfterMs);
|
|
214
|
+
const error = new core_2.SigloError(`HTTP ${response.status} ${response.statusText}${errorText ? `: ${errorText}` : ''}`, {
|
|
215
|
+
stepName,
|
|
216
|
+
phase: 'action',
|
|
217
|
+
retryable: true,
|
|
218
|
+
status: response.status,
|
|
219
|
+
metadata: { httpMetadata: metadata }
|
|
220
|
+
});
|
|
221
|
+
error.status = response.status;
|
|
222
|
+
error.httpMetadata = metadata;
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
// Handle other non-2xx status codes (fatal client/server errors)
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
const errorText = await response.text().catch(() => '');
|
|
228
|
+
Object.assign(content, (0, core_1.captureInspection)(options.capture, 'responseBody', errorText));
|
|
229
|
+
inspectAttempt(response.status, undefined, retryAfterMs);
|
|
230
|
+
const error = new core_2.SigloError(`HTTP ${response.status} ${response.statusText}${errorText ? `: ${errorText}` : ''}`, {
|
|
231
|
+
stepName,
|
|
232
|
+
phase: 'action',
|
|
233
|
+
retryable: false,
|
|
234
|
+
status: response.status,
|
|
235
|
+
metadata: { httpMetadata: metadata }
|
|
236
|
+
});
|
|
237
|
+
error.status = response.status;
|
|
238
|
+
error.httpMetadata = metadata;
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
// Parse successful response body
|
|
242
|
+
let parsedData;
|
|
243
|
+
if (response.status === 204) {
|
|
244
|
+
parsedData = null;
|
|
245
|
+
}
|
|
246
|
+
else if (responseType === 'text') {
|
|
247
|
+
parsedData = await response.text();
|
|
248
|
+
}
|
|
249
|
+
else if (responseType === 'blob') {
|
|
250
|
+
parsedData = await response.blob();
|
|
251
|
+
}
|
|
252
|
+
else if (responseType === 'arrayBuffer') {
|
|
253
|
+
parsedData = await response.arrayBuffer();
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// Default: 'json'
|
|
257
|
+
const text = await response.text();
|
|
258
|
+
Object.assign(content, (0, core_1.captureInspection)(options.capture, 'responseBody', text));
|
|
259
|
+
parsedData = text.trim().length > 0 ? JSON.parse(text) : {};
|
|
260
|
+
}
|
|
261
|
+
Object.assign(content, (0, core_1.captureInspection)(options.capture, 'responseBody', parsedData));
|
|
262
|
+
inspectAttempt(response.status, undefined, retryAfterMs);
|
|
263
|
+
return {
|
|
264
|
+
data: parsedData,
|
|
265
|
+
metadata
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
const transportRetryDelay = !responseObserved && !timedOut && !externalSignal?.aborted &&
|
|
270
|
+
err?.name !== 'AbortError' && !err?.message?.includes('aborted') && !(err instanceof core_2.SigloError) &&
|
|
271
|
+
(0, retry_1.isTransientNetworkError)(err) && retryAttempts < maxRetries
|
|
272
|
+
? (0, retry_1.calculateBackoffDelay)(retryAttempts + 1) : undefined;
|
|
273
|
+
if (!inspected)
|
|
274
|
+
inspectAttempt(responseStatus, transportRetryDelay, undefined, transportRetryDelay === undefined ? undefined : 'backoff', true);
|
|
275
|
+
if (timeoutId)
|
|
276
|
+
clearTimeout(timeoutId);
|
|
277
|
+
if (externalSignal && typeof externalSignal.removeEventListener === 'function') {
|
|
278
|
+
externalSignal.removeEventListener('abort', onExternalAbort);
|
|
279
|
+
}
|
|
280
|
+
if (timedOut) {
|
|
281
|
+
throw new core_2.StepTimeoutException(stepName, timeoutMs || 0, {
|
|
282
|
+
stepName,
|
|
283
|
+
phase: 'action',
|
|
284
|
+
cause: err
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
if (err?.name === 'AbortError' || err?.message?.includes('aborted') || externalSignal?.aborted) {
|
|
288
|
+
throw new core_2.CancellationException(err?.message || 'HTTP request aborted', {
|
|
289
|
+
stepName,
|
|
290
|
+
phase: 'action',
|
|
291
|
+
cause: err
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
// If already a SigloError, rethrow
|
|
295
|
+
if (err instanceof core_2.SigloError) {
|
|
296
|
+
throw err;
|
|
297
|
+
}
|
|
298
|
+
// Check if transient network transport error
|
|
299
|
+
if ((0, retry_1.isTransientNetworkError)(err) && retryAttempts < maxRetries) {
|
|
300
|
+
retryAttempts++;
|
|
301
|
+
const delayMs = transportRetryDelay ?? (0, retry_1.calculateBackoffDelay)(retryAttempts);
|
|
302
|
+
await sleepFn(delayMs);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
// Fatal network or unhandled failure
|
|
306
|
+
const durationMs = nowFn() - startTime;
|
|
307
|
+
const metadata = {
|
|
308
|
+
status: 0,
|
|
309
|
+
statusText: err?.code || 'FETCH_ERROR',
|
|
310
|
+
durationMs,
|
|
311
|
+
url: finalUrl,
|
|
312
|
+
method: normalizedMethod,
|
|
313
|
+
headers: {},
|
|
314
|
+
traceId,
|
|
315
|
+
retryAttempts,
|
|
316
|
+
cUrl
|
|
317
|
+
};
|
|
318
|
+
const error = new core_2.SigloError(`HTTP request failed to ${finalUrl}: ${err?.message || err}`, {
|
|
319
|
+
stepName,
|
|
320
|
+
phase: 'action',
|
|
321
|
+
retryable: (0, retry_1.isTransientNetworkError)(err),
|
|
322
|
+
cause: err,
|
|
323
|
+
metadata: { httpMetadata: metadata }
|
|
324
|
+
});
|
|
325
|
+
error.httpMetadata = metadata;
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/client/fetch.ts"],"names":[],"mappings":";;AAgDA,gDAmBC;AAKD,8CA6BC;AAKD,kDAuBC;AAKD,gDA0RC;AAhaD,sCAA8G;AAC9G,sCAAsF;AAGtF,mCAMiB;AACjB,mCAKiB;AACjB,qDAAuD;AA4BvD;;GAEG;AACH,SAAgB,kBAAkB,CAAC,SAAc;IAC/C,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;QACpC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;YACxB,IAAI,GAAG,IAAI,CAAC,GAAG,YAAY,WAAW,IAAI,OAAO,GAAG,CAAC,gBAAgB,KAAK,UAAU,CAAC,EAAE,CAAC;gBACtF,OAAO,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ACb,IAAI;aACL,CAAC;YAEF,MAAM,KAAK,GAAG,IAAI,iBAAU,CAAC,0BAA0B,QAAQ,KAAK,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,EAAE;gBACzF,QAAQ;gBACR,KAAK,EAAE,QAAQ;gBACf,SAAS,EAAE,IAAA,+BAAuB,EAAC,GAAG,CAAC;gBACvC,KAAK,EAAE,GAAG;gBACV,QAAQ,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE;aACrC,CAAC,CAAC;YACF,KAAa,CAAC,YAAY,GAAG,QAAQ,CAAC;YACvC,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses the HTTP `Retry-After` header value into milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - Scenario A: Integer seconds (e.g. "120")
|
|
6
|
+
* - Scenario B: RFC 1123 HTTP Date (e.g. "Wed, 21 Oct 2026 07:28:00 GMT")
|
|
7
|
+
*
|
|
8
|
+
* @param headerValue The raw header string or null/undefined
|
|
9
|
+
* @param now Optional timestamp provider (useful with FakeClock in tests)
|
|
10
|
+
* @returns Delay in milliseconds, or undefined if absent/invalid
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseRetryAfter(headerValue: string | null | undefined, now?: () => number): number | undefined;
|
|
13
|
+
export declare const DEFAULT_RETRY_STATUSES: readonly number[];
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a given status code is configured as retryable.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isRetryableStatus(status: number, retryOnStatus?: number[]): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if an error is a transient transport/network error suitable for retry.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isTransientNetworkError(error: any): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Calculates exponential backoff with full decorrelated jitter.
|
|
24
|
+
*
|
|
25
|
+
* @param attempt 0-indexed attempt count
|
|
26
|
+
* @param baseDelayMs Base delay in milliseconds (defaults to 100ms)
|
|
27
|
+
* @param maxDelayMs Maximum backoff cap (defaults to 10000ms)
|
|
28
|
+
*/
|
|
29
|
+
export declare function calculateBackoffDelay(attempt: number, baseDelayMs?: number, maxDelayMs?: number): number;
|
|
30
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/client/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,GAAG,GAAE,MAAM,MAAyB,GACnC,MAAM,GAAG,SAAS,CAwBpB;AAED,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAAyB,CAAC;AAE9E;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,GAAE,MAAM,EAAgC,GAAG,OAAO,CAEhH;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAsB3D;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,WAAW,GAAE,MAAY,EACzB,UAAU,GAAE,MAAc,GACzB,MAAM,CAIR"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_RETRY_STATUSES = void 0;
|
|
4
|
+
exports.parseRetryAfter = parseRetryAfter;
|
|
5
|
+
exports.isRetryableStatus = isRetryableStatus;
|
|
6
|
+
exports.isTransientNetworkError = isTransientNetworkError;
|
|
7
|
+
exports.calculateBackoffDelay = calculateBackoffDelay;
|
|
8
|
+
/**
|
|
9
|
+
* Parses the HTTP `Retry-After` header value into milliseconds.
|
|
10
|
+
*
|
|
11
|
+
* Supports:
|
|
12
|
+
* - Scenario A: Integer seconds (e.g. "120")
|
|
13
|
+
* - Scenario B: RFC 1123 HTTP Date (e.g. "Wed, 21 Oct 2026 07:28:00 GMT")
|
|
14
|
+
*
|
|
15
|
+
* @param headerValue The raw header string or null/undefined
|
|
16
|
+
* @param now Optional timestamp provider (useful with FakeClock in tests)
|
|
17
|
+
* @returns Delay in milliseconds, or undefined if absent/invalid
|
|
18
|
+
*/
|
|
19
|
+
function parseRetryAfter(headerValue, now = () => Date.now()) {
|
|
20
|
+
if (!headerValue || typeof headerValue !== 'string') {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const trimmed = headerValue.trim();
|
|
24
|
+
if (!trimmed) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
// Scenario A: Integer / decimal seconds (e.g. "120" or "1.5")
|
|
28
|
+
const seconds = Number(trimmed);
|
|
29
|
+
if (Number.isFinite(seconds)) {
|
|
30
|
+
return seconds >= 0 && Number.isFinite(seconds * 1000) ? Math.round(seconds * 1000) : undefined;
|
|
31
|
+
}
|
|
32
|
+
// Scenario B: RFC 1123 HTTP Date (e.g. "Wed, 21 Oct 2026 07:28:00 GMT")
|
|
33
|
+
const parsedDate = Date.parse(trimmed);
|
|
34
|
+
if (!Number.isNaN(parsedDate)) {
|
|
35
|
+
const delay = parsedDate - now();
|
|
36
|
+
return Math.max(0, delay);
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
exports.DEFAULT_RETRY_STATUSES = [429, 502, 503, 504];
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a given status code is configured as retryable.
|
|
43
|
+
*/
|
|
44
|
+
function isRetryableStatus(status, retryOnStatus = [...exports.DEFAULT_RETRY_STATUSES]) {
|
|
45
|
+
return retryOnStatus.includes(status);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Checks if an error is a transient transport/network error suitable for retry.
|
|
49
|
+
*/
|
|
50
|
+
function isTransientNetworkError(error) {
|
|
51
|
+
if (!error)
|
|
52
|
+
return false;
|
|
53
|
+
const code = error.code || error.cause?.code;
|
|
54
|
+
if (typeof code === 'string') {
|
|
55
|
+
const transientCodes = ['ECONNRESET', 'ETIMEDOUT', 'EAI_AGAIN', 'UND_ERR_CONNECT_TIMEOUT', 'ENOTFOUND', 'ECONNREFUSED'];
|
|
56
|
+
if (transientCodes.includes(code)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const message = (error.message || '').toLowerCase();
|
|
61
|
+
if (message.includes('fetch failed') ||
|
|
62
|
+
message.includes('network') ||
|
|
63
|
+
message.includes('socket hung up') ||
|
|
64
|
+
message.includes('econnreset') ||
|
|
65
|
+
message.includes('etimedout')) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Calculates exponential backoff with full decorrelated jitter.
|
|
72
|
+
*
|
|
73
|
+
* @param attempt 0-indexed attempt count
|
|
74
|
+
* @param baseDelayMs Base delay in milliseconds (defaults to 100ms)
|
|
75
|
+
* @param maxDelayMs Maximum backoff cap (defaults to 10000ms)
|
|
76
|
+
*/
|
|
77
|
+
function calculateBackoffDelay(attempt, baseDelayMs = 100, maxDelayMs = 10000) {
|
|
78
|
+
const exponential = Math.min(maxDelayMs, baseDelayMs * Math.pow(2, attempt));
|
|
79
|
+
// Full jitter: random between 0 and exponential
|
|
80
|
+
return Math.floor(Math.random() * (exponential + 1));
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/client/retry.ts"],"names":[],"mappings":";;;AAWA,0CA2BC;AAOD,8CAEC;AAKD,0DAsBC;AASD,sDAQC;AA3FD;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAC7B,WAAsC,EACtC,MAAoB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|
+
[key: string]: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Injects W3C distributed trace context (traceparent and tracestate) into request headers
|
|
8
|
+
* from the active OpenTelemetry span and context.
|
|
9
|
+
*/
|
|
10
|
+
export declare function injectTraceHeaders(carrier?: Record<string, string>, customSpan?: any): Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Attaches standard HTTP semantic convention attributes to the active OpenTelemetry span.
|
|
13
|
+
*/
|
|
14
|
+
export declare function recordRequestSpanAttributes(method: string, url: string, serverAddress: string, customSpan?: any): void;
|
|
15
|
+
/**
|
|
16
|
+
* Attaches standard response semantic convention attributes to the active OpenTelemetry span.
|
|
17
|
+
*/
|
|
18
|
+
export declare function recordResponseSpanAttributes(statusCode: number, customSpan?: any): void;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts current active traceId if present.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getActiveTraceId(customSpan?: any): string | undefined;
|
|
23
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/client/trace.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,UAAU,CAAC,EAAE,GAAG,GACf,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiCxB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,GAAG,GACf,IAAI,CAWN;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,GAAG,GACf,IAAI,CAeN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAkBrE"}
|