@pureq/pureq 1.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/LICENSE.md +21 -0
- package/README.md +932 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/scripts/benchmark.d.ts +2 -0
- package/dist/scripts/benchmark.d.ts.map +1 -0
- package/dist/scripts/benchmark.js +69 -0
- package/dist/scripts/benchmark.js.map +1 -0
- package/dist/scripts/edge-smoke-entry.d.ts +8 -0
- package/dist/scripts/edge-smoke-entry.d.ts.map +1 -0
- package/dist/scripts/edge-smoke-entry.js +23 -0
- package/dist/scripts/edge-smoke-entry.js.map +1 -0
- package/dist/src/adapters/fetchAdapter.d.ts +3 -0
- package/dist/src/adapters/fetchAdapter.d.ts.map +1 -0
- package/dist/src/adapters/fetchAdapter.js +4 -0
- package/dist/src/adapters/fetchAdapter.js.map +1 -0
- package/dist/src/adapters/instrumentedAdapter.d.ts +21 -0
- package/dist/src/adapters/instrumentedAdapter.d.ts.map +1 -0
- package/dist/src/adapters/instrumentedAdapter.js +25 -0
- package/dist/src/adapters/instrumentedAdapter.js.map +1 -0
- package/dist/src/client/createClient.d.ts +193 -0
- package/dist/src/client/createClient.d.ts.map +1 -0
- package/dist/src/client/createClient.js +310 -0
- package/dist/src/client/createClient.js.map +1 -0
- package/dist/src/executor/execute.d.ts +19 -0
- package/dist/src/executor/execute.d.ts.map +1 -0
- package/dist/src/executor/execute.js +121 -0
- package/dist/src/executor/execute.js.map +1 -0
- package/dist/src/index.d.ts +37 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +36 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/middleware/circuitBreaker.d.ts +77 -0
- package/dist/src/middleware/circuitBreaker.d.ts.map +1 -0
- package/dist/src/middleware/circuitBreaker.js +246 -0
- package/dist/src/middleware/circuitBreaker.js.map +1 -0
- package/dist/src/middleware/circuitBreakerKeys.d.ts +5 -0
- package/dist/src/middleware/circuitBreakerKeys.d.ts.map +1 -0
- package/dist/src/middleware/circuitBreakerKeys.js +30 -0
- package/dist/src/middleware/circuitBreakerKeys.js.map +1 -0
- package/dist/src/middleware/compose.d.ts +9 -0
- package/dist/src/middleware/compose.d.ts.map +1 -0
- package/dist/src/middleware/compose.js +45 -0
- package/dist/src/middleware/compose.js.map +1 -0
- package/dist/src/middleware/concurrencyLimit.d.ts +11 -0
- package/dist/src/middleware/concurrencyLimit.d.ts.map +1 -0
- package/dist/src/middleware/concurrencyLimit.js +126 -0
- package/dist/src/middleware/concurrencyLimit.js.map +1 -0
- package/dist/src/middleware/deadline.d.ts +10 -0
- package/dist/src/middleware/deadline.d.ts.map +1 -0
- package/dist/src/middleware/deadline.js +99 -0
- package/dist/src/middleware/deadline.js.map +1 -0
- package/dist/src/middleware/dedupe.d.ts +13 -0
- package/dist/src/middleware/dedupe.d.ts.map +1 -0
- package/dist/src/middleware/dedupe.js +46 -0
- package/dist/src/middleware/dedupe.js.map +1 -0
- package/dist/src/middleware/defaultTimeout.d.ts +6 -0
- package/dist/src/middleware/defaultTimeout.d.ts.map +1 -0
- package/dist/src/middleware/defaultTimeout.js +23 -0
- package/dist/src/middleware/defaultTimeout.js.map +1 -0
- package/dist/src/middleware/diagnostics.d.ts +28 -0
- package/dist/src/middleware/diagnostics.d.ts.map +1 -0
- package/dist/src/middleware/diagnostics.js +131 -0
- package/dist/src/middleware/diagnostics.js.map +1 -0
- package/dist/src/middleware/diagnosticsExporters.d.ts +27 -0
- package/dist/src/middleware/diagnosticsExporters.d.ts.map +1 -0
- package/dist/src/middleware/diagnosticsExporters.js +45 -0
- package/dist/src/middleware/diagnosticsExporters.js.map +1 -0
- package/dist/src/middleware/hedge.d.ts +17 -0
- package/dist/src/middleware/hedge.d.ts.map +1 -0
- package/dist/src/middleware/hedge.js +125 -0
- package/dist/src/middleware/hedge.js.map +1 -0
- package/dist/src/middleware/httpCache.d.ts +14 -0
- package/dist/src/middleware/httpCache.d.ts.map +1 -0
- package/dist/src/middleware/httpCache.js +126 -0
- package/dist/src/middleware/httpCache.js.map +1 -0
- package/dist/src/middleware/idempotencyKey.d.ts +12 -0
- package/dist/src/middleware/idempotencyKey.d.ts.map +1 -0
- package/dist/src/middleware/idempotencyKey.js +33 -0
- package/dist/src/middleware/idempotencyKey.js.map +1 -0
- package/dist/src/middleware/offlineQueue.d.ts +78 -0
- package/dist/src/middleware/offlineQueue.d.ts.map +1 -0
- package/dist/src/middleware/offlineQueue.js +189 -0
- package/dist/src/middleware/offlineQueue.js.map +1 -0
- package/dist/src/middleware/presets.d.ts +31 -0
- package/dist/src/middleware/presets.d.ts.map +1 -0
- package/dist/src/middleware/presets.js +122 -0
- package/dist/src/middleware/presets.js.map +1 -0
- package/dist/src/middleware/retry.d.ts +27 -0
- package/dist/src/middleware/retry.d.ts.map +1 -0
- package/dist/src/middleware/retry.js +189 -0
- package/dist/src/middleware/retry.js.map +1 -0
- package/dist/src/middleware/stalePolicy.d.ts +14 -0
- package/dist/src/middleware/stalePolicy.d.ts.map +1 -0
- package/dist/src/middleware/stalePolicy.js +13 -0
- package/dist/src/middleware/stalePolicy.js.map +1 -0
- package/dist/src/observability/otelMapping.d.ts +13 -0
- package/dist/src/observability/otelMapping.d.ts.map +1 -0
- package/dist/src/observability/otelMapping.js +31 -0
- package/dist/src/observability/otelMapping.js.map +1 -0
- package/dist/src/observability/otelProfiles.d.ts +16 -0
- package/dist/src/observability/otelProfiles.d.ts.map +1 -0
- package/dist/src/observability/otelProfiles.js +66 -0
- package/dist/src/observability/otelProfiles.js.map +1 -0
- package/dist/src/observability/redaction.d.ts +39 -0
- package/dist/src/observability/redaction.d.ts.map +1 -0
- package/dist/src/observability/redaction.js +112 -0
- package/dist/src/observability/redaction.js.map +1 -0
- package/dist/src/policy/guardrails.d.ts +14 -0
- package/dist/src/policy/guardrails.d.ts.map +1 -0
- package/dist/src/policy/guardrails.js +36 -0
- package/dist/src/policy/guardrails.js.map +1 -0
- package/dist/src/response/response.d.ts +58 -0
- package/dist/src/response/response.d.ts.map +1 -0
- package/dist/src/response/response.js +91 -0
- package/dist/src/response/response.js.map +1 -0
- package/dist/src/serializers/formUrlEncodedSerializer.d.ts +6 -0
- package/dist/src/serializers/formUrlEncodedSerializer.d.ts.map +1 -0
- package/dist/src/serializers/formUrlEncodedSerializer.js +38 -0
- package/dist/src/serializers/formUrlEncodedSerializer.js.map +1 -0
- package/dist/src/serializers/jsonBodySerializer.d.ts +3 -0
- package/dist/src/serializers/jsonBodySerializer.d.ts.map +1 -0
- package/dist/src/serializers/jsonBodySerializer.js +24 -0
- package/dist/src/serializers/jsonBodySerializer.js.map +1 -0
- package/dist/src/types/events.d.ts +49 -0
- package/dist/src/types/events.d.ts.map +1 -0
- package/dist/src/types/events.js +2 -0
- package/dist/src/types/events.js.map +1 -0
- package/dist/src/types/http.d.ts +78 -0
- package/dist/src/types/http.d.ts.map +1 -0
- package/dist/src/types/http.js +2 -0
- package/dist/src/types/http.js.map +1 -0
- package/dist/src/types/internal.d.ts +20 -0
- package/dist/src/types/internal.d.ts.map +1 -0
- package/dist/src/types/internal.js +2 -0
- package/dist/src/types/internal.js.map +1 -0
- package/dist/src/types/result.d.ts +32 -0
- package/dist/src/types/result.d.ts.map +1 -0
- package/dist/src/types/result.js +66 -0
- package/dist/src/types/result.js.map +1 -0
- package/dist/src/utils/crypto.d.ts +8 -0
- package/dist/src/utils/crypto.d.ts.map +1 -0
- package/dist/src/utils/crypto.js +21 -0
- package/dist/src/utils/crypto.js.map +1 -0
- package/dist/src/utils/policyTrace.d.ts +17 -0
- package/dist/src/utils/policyTrace.d.ts.map +1 -0
- package/dist/src/utils/policyTrace.js +34 -0
- package/dist/src/utils/policyTrace.js.map +1 -0
- package/dist/src/utils/stableKey.d.ts +17 -0
- package/dist/src/utils/stableKey.d.ts.map +1 -0
- package/dist/src/utils/stableKey.js +41 -0
- package/dist/src/utils/stableKey.js.map +1 -0
- package/dist/src/utils/url.d.ts +22 -0
- package/dist/src/utils/url.d.ts.map +1 -0
- package/dist/src/utils/url.js +2 -0
- package/dist/src/utils/url.js.map +1 -0
- package/dist/tests/adapter-serializer.test.d.ts +2 -0
- package/dist/tests/adapter-serializer.test.d.ts.map +1 -0
- package/dist/tests/adapter-serializer.test.js +59 -0
- package/dist/tests/adapter-serializer.test.js.map +1 -0
- package/dist/tests/browser-runtime.smoke.test.d.ts +2 -0
- package/dist/tests/browser-runtime.smoke.test.d.ts.map +1 -0
- package/dist/tests/browser-runtime.smoke.test.js +17 -0
- package/dist/tests/browser-runtime.smoke.test.js.map +1 -0
- package/dist/tests/circuit-breaker.test.d.ts +2 -0
- package/dist/tests/circuit-breaker.test.d.ts.map +1 -0
- package/dist/tests/circuit-breaker.test.js +184 -0
- package/dist/tests/circuit-breaker.test.js.map +1 -0
- package/dist/tests/client.integration.d.ts +2 -0
- package/dist/tests/client.integration.d.ts.map +1 -0
- package/dist/tests/client.integration.js +44 -0
- package/dist/tests/client.integration.js.map +1 -0
- package/dist/tests/client.integration.test.d.ts +2 -0
- package/dist/tests/client.integration.test.d.ts.map +1 -0
- package/dist/tests/client.integration.test.js +63 -0
- package/dist/tests/client.integration.test.js.map +1 -0
- package/dist/tests/compose.test.d.ts +2 -0
- package/dist/tests/compose.test.d.ts.map +1 -0
- package/dist/tests/compose.test.js +24 -0
- package/dist/tests/compose.test.js.map +1 -0
- package/dist/tests/concurrency-limit.test.d.ts +2 -0
- package/dist/tests/concurrency-limit.test.d.ts.map +1 -0
- package/dist/tests/concurrency-limit.test.js +87 -0
- package/dist/tests/concurrency-limit.test.js.map +1 -0
- package/dist/tests/deadline-middleware.test.d.ts +2 -0
- package/dist/tests/deadline-middleware.test.d.ts.map +1 -0
- package/dist/tests/deadline-middleware.test.js +38 -0
- package/dist/tests/deadline-middleware.test.js.map +1 -0
- package/dist/tests/dedupe-middleware.test.d.ts +2 -0
- package/dist/tests/dedupe-middleware.test.d.ts.map +1 -0
- package/dist/tests/dedupe-middleware.test.js +56 -0
- package/dist/tests/dedupe-middleware.test.js.map +1 -0
- package/dist/tests/default-timeout.test.d.ts +2 -0
- package/dist/tests/default-timeout.test.d.ts.map +1 -0
- package/dist/tests/default-timeout.test.js +28 -0
- package/dist/tests/default-timeout.test.js.map +1 -0
- package/dist/tests/diagnostics-exporters.test.d.ts +2 -0
- package/dist/tests/diagnostics-exporters.test.d.ts.map +1 -0
- package/dist/tests/diagnostics-exporters.test.js +41 -0
- package/dist/tests/diagnostics-exporters.test.js.map +1 -0
- package/dist/tests/diagnostics.test.d.ts +2 -0
- package/dist/tests/diagnostics.test.d.ts.map +1 -0
- package/dist/tests/diagnostics.test.js +38 -0
- package/dist/tests/diagnostics.test.js.map +1 -0
- package/dist/tests/error-metadata.test.d.ts +2 -0
- package/dist/tests/error-metadata.test.d.ts.map +1 -0
- package/dist/tests/error-metadata.test.js +23 -0
- package/dist/tests/error-metadata.test.js.map +1 -0
- package/dist/tests/execute-timeout.test.d.ts +2 -0
- package/dist/tests/execute-timeout.test.d.ts.map +1 -0
- package/dist/tests/execute-timeout.test.js +30 -0
- package/dist/tests/execute-timeout.test.js.map +1 -0
- package/dist/tests/form-serializer.test.d.ts +2 -0
- package/dist/tests/form-serializer.test.d.ts.map +1 -0
- package/dist/tests/form-serializer.test.js +16 -0
- package/dist/tests/form-serializer.test.js.map +1 -0
- package/dist/tests/hedge.test.d.ts +2 -0
- package/dist/tests/hedge.test.d.ts.map +1 -0
- package/dist/tests/hedge.test.js +45 -0
- package/dist/tests/hedge.test.js.map +1 -0
- package/dist/tests/http-cache.test.d.ts +2 -0
- package/dist/tests/http-cache.test.d.ts.map +1 -0
- package/dist/tests/http-cache.test.js +60 -0
- package/dist/tests/http-cache.test.js.map +1 -0
- package/dist/tests/idempotency-key.test.d.ts +2 -0
- package/dist/tests/idempotency-key.test.d.ts.map +1 -0
- package/dist/tests/idempotency-key.test.js +31 -0
- package/dist/tests/idempotency-key.test.js.map +1 -0
- package/dist/tests/instrumented-adapter.test.d.ts +2 -0
- package/dist/tests/instrumented-adapter.test.d.ts.map +1 -0
- package/dist/tests/instrumented-adapter.test.js +33 -0
- package/dist/tests/instrumented-adapter.test.js.map +1 -0
- package/dist/tests/interceptor-order.test.d.ts +2 -0
- package/dist/tests/interceptor-order.test.d.ts.map +1 -0
- package/dist/tests/interceptor-order.test.js +38 -0
- package/dist/tests/interceptor-order.test.js.map +1 -0
- package/dist/tests/json-helper.test.d.ts +2 -0
- package/dist/tests/json-helper.test.d.ts.map +1 -0
- package/dist/tests/json-helper.test.js +42 -0
- package/dist/tests/json-helper.test.js.map +1 -0
- package/dist/tests/observability.test.d.ts +2 -0
- package/dist/tests/observability.test.d.ts.map +1 -0
- package/dist/tests/observability.test.js +59 -0
- package/dist/tests/observability.test.js.map +1 -0
- package/dist/tests/offline-queue.test.d.ts +2 -0
- package/dist/tests/offline-queue.test.d.ts.map +1 -0
- package/dist/tests/offline-queue.test.js +35 -0
- package/dist/tests/offline-queue.test.js.map +1 -0
- package/dist/tests/otel-mapping.test.d.ts +2 -0
- package/dist/tests/otel-mapping.test.d.ts.map +1 -0
- package/dist/tests/otel-mapping.test.js +20 -0
- package/dist/tests/otel-mapping.test.js.map +1 -0
- package/dist/tests/policy-guardrails.test.d.ts +2 -0
- package/dist/tests/policy-guardrails.test.d.ts.map +1 -0
- package/dist/tests/policy-guardrails.test.js +25 -0
- package/dist/tests/policy-guardrails.test.js.map +1 -0
- package/dist/tests/presets.test.d.ts +2 -0
- package/dist/tests/presets.test.d.ts.map +1 -0
- package/dist/tests/presets.test.js +41 -0
- package/dist/tests/presets.test.js.map +1 -0
- package/dist/tests/public-api.contract.d.ts +2 -0
- package/dist/tests/public-api.contract.d.ts.map +1 -0
- package/dist/tests/public-api.contract.js +14 -0
- package/dist/tests/public-api.contract.js.map +1 -0
- package/dist/tests/public-api.contract.test.d.ts +2 -0
- package/dist/tests/public-api.contract.test.d.ts.map +1 -0
- package/dist/tests/public-api.contract.test.js +25 -0
- package/dist/tests/public-api.contract.test.js.map +1 -0
- package/dist/tests/redaction.test.d.ts +2 -0
- package/dist/tests/redaction.test.d.ts.map +1 -0
- package/dist/tests/redaction.test.js +23 -0
- package/dist/tests/redaction.test.js.map +1 -0
- package/dist/tests/retry-after-budget.test.d.ts +2 -0
- package/dist/tests/retry-after-budget.test.d.ts.map +1 -0
- package/dist/tests/retry-after-budget.test.js +72 -0
- package/dist/tests/retry-after-budget.test.js.map +1 -0
- package/dist/tests/retry-policy-trace.test.d.ts +2 -0
- package/dist/tests/retry-policy-trace.test.d.ts.map +1 -0
- package/dist/tests/retry-policy-trace.test.js +35 -0
- package/dist/tests/retry-policy-trace.test.js.map +1 -0
- package/dist/tests/retry-policy.test.d.ts +2 -0
- package/dist/tests/retry-policy.test.d.ts.map +1 -0
- package/dist/tests/retry-policy.test.js +51 -0
- package/dist/tests/retry-policy.test.js.map +1 -0
- package/dist/tests/retry.stress.d.ts +2 -0
- package/dist/tests/retry.stress.d.ts.map +1 -0
- package/dist/tests/retry.stress.js +21 -0
- package/dist/tests/retry.stress.js.map +1 -0
- package/dist/tests/retry.stress.test.d.ts +2 -0
- package/dist/tests/retry.stress.test.d.ts.map +1 -0
- package/dist/tests/retry.stress.test.js +21 -0
- package/dist/tests/retry.stress.test.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wrapper class for the standard Fetch `Response` object.
|
|
3
|
+
* Provides a clean interface for accessing body and metadata.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpResponse {
|
|
6
|
+
private readonly response;
|
|
7
|
+
constructor(res: Response);
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if status code is 200-299
|
|
10
|
+
*/
|
|
11
|
+
get ok(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* HTTP status code
|
|
14
|
+
*/
|
|
15
|
+
get status(): number;
|
|
16
|
+
/**
|
|
17
|
+
* Status description text
|
|
18
|
+
*/
|
|
19
|
+
get statusText(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Response headers object
|
|
22
|
+
*/
|
|
23
|
+
get headers(): Headers;
|
|
24
|
+
/**
|
|
25
|
+
* Parse the response body as JSON.
|
|
26
|
+
* Developers are expected to verify .ok before calling this.
|
|
27
|
+
*/
|
|
28
|
+
json<T = unknown>(): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Parse the response body as plain text
|
|
31
|
+
*/
|
|
32
|
+
text(): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Parse the response body as a Blob
|
|
35
|
+
*/
|
|
36
|
+
blob(): Promise<Blob>;
|
|
37
|
+
/**
|
|
38
|
+
* Parse the response body as ArrayBuffer
|
|
39
|
+
*/
|
|
40
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
41
|
+
/**
|
|
42
|
+
* Parse the response body as FormData
|
|
43
|
+
*/
|
|
44
|
+
formData(): Promise<FormData>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the underlying readable stream when available
|
|
47
|
+
*/
|
|
48
|
+
stream(): ReadableStream<Uint8Array> | null;
|
|
49
|
+
/**
|
|
50
|
+
* Get the underlying Fetch API Response object
|
|
51
|
+
*/
|
|
52
|
+
get native(): Response;
|
|
53
|
+
/**
|
|
54
|
+
* Clone the response to allow re-reading the body
|
|
55
|
+
*/
|
|
56
|
+
clone(): HttpResponse;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../src/response/response.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;gBAExB,GAAG,EAAE,QAAQ;IAIzB;;OAEG;IACH,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;OAGG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC;IAWrC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAIzC;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAInC;;OAEG;IACH,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI;IAI3C;;OAEG;IACH,IAAI,MAAM,IAAI,QAAQ,CAErB;IAED;;OAEG;IACH,KAAK,IAAI,YAAY;CAGtB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wrapper class for the standard Fetch `Response` object.
|
|
3
|
+
* Provides a clean interface for accessing body and metadata.
|
|
4
|
+
*/
|
|
5
|
+
export class HttpResponse {
|
|
6
|
+
constructor(res) {
|
|
7
|
+
this.response = res;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if status code is 200-299
|
|
11
|
+
*/
|
|
12
|
+
get ok() {
|
|
13
|
+
return this.response.ok;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* HTTP status code
|
|
17
|
+
*/
|
|
18
|
+
get status() {
|
|
19
|
+
return this.response.status;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Status description text
|
|
23
|
+
*/
|
|
24
|
+
get statusText() {
|
|
25
|
+
return this.response.statusText;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Response headers object
|
|
29
|
+
*/
|
|
30
|
+
get headers() {
|
|
31
|
+
return this.response.headers;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse the response body as JSON.
|
|
35
|
+
* Developers are expected to verify .ok before calling this.
|
|
36
|
+
*/
|
|
37
|
+
async json() {
|
|
38
|
+
try {
|
|
39
|
+
return (await this.response.json());
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof Error) {
|
|
43
|
+
throw new Error(`Failed to parse response as JSON: ${err.message}`);
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parse the response body as plain text
|
|
50
|
+
*/
|
|
51
|
+
async text() {
|
|
52
|
+
return this.response.text();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse the response body as a Blob
|
|
56
|
+
*/
|
|
57
|
+
async blob() {
|
|
58
|
+
return this.response.blob();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parse the response body as ArrayBuffer
|
|
62
|
+
*/
|
|
63
|
+
async arrayBuffer() {
|
|
64
|
+
return this.response.arrayBuffer();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parse the response body as FormData
|
|
68
|
+
*/
|
|
69
|
+
async formData() {
|
|
70
|
+
return this.response.formData();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the underlying readable stream when available
|
|
74
|
+
*/
|
|
75
|
+
stream() {
|
|
76
|
+
return this.response.body;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the underlying Fetch API Response object
|
|
80
|
+
*/
|
|
81
|
+
get native() {
|
|
82
|
+
return this.response;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clone the response to allow re-reading the body
|
|
86
|
+
*/
|
|
87
|
+
clone() {
|
|
88
|
+
return new HttpResponse(this.response.clone());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","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,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BodySerializer } from "../types/http";
|
|
2
|
+
export interface FormUrlEncodedSerializerOptions {
|
|
3
|
+
readonly arrayMode?: "repeat" | "comma";
|
|
4
|
+
}
|
|
5
|
+
export declare function createFormUrlEncodedSerializer(options?: FormUrlEncodedSerializerOptions): BodySerializer;
|
|
6
|
+
//# sourceMappingURL=formUrlEncodedSerializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formUrlEncodedSerializer.d.ts","sourceRoot":"","sources":["../../../src/serializers/formUrlEncodedSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;CACzC;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,GAAE,+BAAoC,GAC5C,cAAc,CA4ChB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function createFormUrlEncodedSerializer(options = {}) {
|
|
2
|
+
const arrayMode = options.arrayMode ?? "repeat";
|
|
3
|
+
return {
|
|
4
|
+
serialize(body) {
|
|
5
|
+
if (body === undefined || body === null) {
|
|
6
|
+
return { payload: null };
|
|
7
|
+
}
|
|
8
|
+
if (typeof body !== "object") {
|
|
9
|
+
return {
|
|
10
|
+
payload: String(body),
|
|
11
|
+
contentType: "application/x-www-form-urlencoded",
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const params = new URLSearchParams();
|
|
15
|
+
for (const [key, value] of Object.entries(body)) {
|
|
16
|
+
if (value === undefined || value === null) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
if (arrayMode === "comma") {
|
|
21
|
+
params.set(key, value.map((item) => String(item)).join(","));
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
for (const item of value) {
|
|
25
|
+
params.append(key, String(item));
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
params.set(key, String(value));
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
payload: params.toString(),
|
|
33
|
+
contentType: "application/x-www-form-urlencoded",
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=formUrlEncodedSerializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formUrlEncodedSerializer.js","sourceRoot":"","sources":["../../../src/serializers/formUrlEncodedSerializer.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,8BAA8B,CAC5C,UAA2C,EAAE;IAE7C,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAC;IAEhD,OAAO;QACL,SAAS,CAAC,IAAI;YACZ,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBACxC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAC3B,CAAC;YAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7B,OAAO;oBACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC;oBACrB,WAAW,EAAE,mCAAmC;iBACjD,CAAC;YACJ,CAAC;YAED,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;YAErC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAA+B,CAAC,EAAE,CAAC;gBAC3E,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBAC1C,SAAS;gBACX,CAAC;gBAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzB,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;wBAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;wBAC7D,SAAS;oBACX,CAAC;oBAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;wBACzB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;oBACnC,CAAC;oBACD,SAAS;gBACX,CAAC;gBAED,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACjC,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE;gBAC1B,WAAW,EAAE,mCAAmC;aACjD,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonBodySerializer.d.ts","sourceRoot":"","sources":["../../../src/serializers/jsonBodySerializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAcpD,eAAO,MAAM,kBAAkB,EAAE,cAehC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function isBodyInitLike(value) {
|
|
2
|
+
return (typeof value === "string" ||
|
|
3
|
+
value instanceof Blob ||
|
|
4
|
+
value instanceof FormData ||
|
|
5
|
+
value instanceof URLSearchParams ||
|
|
6
|
+
value instanceof ArrayBuffer ||
|
|
7
|
+
ArrayBuffer.isView(value) ||
|
|
8
|
+
value instanceof ReadableStream);
|
|
9
|
+
}
|
|
10
|
+
export const jsonBodySerializer = {
|
|
11
|
+
serialize(body) {
|
|
12
|
+
if (body === undefined || body === null) {
|
|
13
|
+
return { payload: null };
|
|
14
|
+
}
|
|
15
|
+
if (isBodyInitLike(body)) {
|
|
16
|
+
return { payload: body };
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
payload: JSON.stringify(body),
|
|
20
|
+
contentType: "application/json",
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=jsonBodySerializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonBodySerializer.js","sourceRoot":"","sources":["../../../src/serializers/jsonBodySerializer.ts"],"names":[],"mappings":"AAEA,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,YAAY,IAAI;QACrB,KAAK,YAAY,QAAQ;QACzB,KAAK,YAAY,eAAe;QAChC,KAAK,YAAY,WAAW;QAC5B,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;QACzB,KAAK,YAAY,cAAc,CAChC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAmB;IAChD,SAAS,CAAC,IAAI;QACZ,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACxC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;QAED,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;QAED,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAC7B,WAAW,EAAE,kBAAkB;SAChC,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { RequestConfig } from "./http";
|
|
2
|
+
import type { PureqErrorKind } from "./result";
|
|
3
|
+
export type TransportEventPhase = "start" | "success" | "error";
|
|
4
|
+
export interface PolicyTraceEntry {
|
|
5
|
+
readonly policy: string;
|
|
6
|
+
readonly decision: string;
|
|
7
|
+
readonly at: number;
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
readonly attempt?: number;
|
|
10
|
+
readonly waitTimeMs?: number;
|
|
11
|
+
readonly status?: number;
|
|
12
|
+
readonly source?: string;
|
|
13
|
+
readonly retryAfterMs?: number;
|
|
14
|
+
readonly budgetRemainingMs?: number;
|
|
15
|
+
readonly key?: string;
|
|
16
|
+
readonly ageMs?: number;
|
|
17
|
+
readonly ttlMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface TransportEvent {
|
|
20
|
+
readonly phase: TransportEventPhase;
|
|
21
|
+
readonly at: number;
|
|
22
|
+
readonly requestId?: string;
|
|
23
|
+
readonly method: RequestConfig["method"];
|
|
24
|
+
readonly url: string;
|
|
25
|
+
readonly startedAt?: number;
|
|
26
|
+
readonly durationMs?: number;
|
|
27
|
+
readonly status?: number;
|
|
28
|
+
readonly retryCount?: number;
|
|
29
|
+
readonly errorKind?: PureqErrorKind;
|
|
30
|
+
readonly policyTrace?: readonly PolicyTraceEntry[];
|
|
31
|
+
}
|
|
32
|
+
export type TransportStartEvent = TransportEvent & {
|
|
33
|
+
readonly phase: "start";
|
|
34
|
+
readonly startedAt: number;
|
|
35
|
+
};
|
|
36
|
+
export type TransportSuccessEvent = TransportEvent & {
|
|
37
|
+
readonly phase: "success";
|
|
38
|
+
readonly startedAt: number;
|
|
39
|
+
readonly durationMs: number;
|
|
40
|
+
readonly status: number;
|
|
41
|
+
readonly retryCount: number;
|
|
42
|
+
};
|
|
43
|
+
export type TransportErrorEvent = TransportEvent & {
|
|
44
|
+
readonly phase: "error";
|
|
45
|
+
readonly startedAt: number;
|
|
46
|
+
readonly durationMs: number;
|
|
47
|
+
readonly errorKind: PureqErrorKind;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/types/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC;AAEhE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,CAA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|
1
|
+
import type { HttpResponse } from "../response/response";
|
|
2
|
+
/**
|
|
3
|
+
* Standard HTTP methods supported by the library
|
|
4
|
+
*/
|
|
5
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
6
|
+
/**
|
|
7
|
+
* Allowed query value primitives
|
|
8
|
+
*/
|
|
9
|
+
export type QueryValue = string | number | boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Allowed query map
|
|
12
|
+
*/
|
|
13
|
+
export type QueryParams = Readonly<Record<string, QueryValue | readonly QueryValue[]>>;
|
|
14
|
+
export type HttpAdapter = (url: string, init: RequestInit) => Promise<Response>;
|
|
15
|
+
export interface BodySerializer {
|
|
16
|
+
readonly serialize: (body: unknown) => {
|
|
17
|
+
readonly payload: BodyInit | null;
|
|
18
|
+
readonly contentType?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Core Request configuration object
|
|
23
|
+
*/
|
|
24
|
+
export interface RequestConfig {
|
|
25
|
+
/**
|
|
26
|
+
* HTTP Method
|
|
27
|
+
*/
|
|
28
|
+
readonly method: HttpMethod;
|
|
29
|
+
/**
|
|
30
|
+
* Request URL
|
|
31
|
+
*/
|
|
32
|
+
readonly url: string;
|
|
33
|
+
/**
|
|
34
|
+
* Key-value map of path parameters (e.g., :userId)
|
|
35
|
+
*/
|
|
36
|
+
readonly params?: Readonly<Record<string, string>>;
|
|
37
|
+
/**
|
|
38
|
+
* Query parameters to append to the URL
|
|
39
|
+
*/
|
|
40
|
+
readonly query?: QueryParams;
|
|
41
|
+
/**
|
|
42
|
+
* Request body (typically object or string)
|
|
43
|
+
*/
|
|
44
|
+
readonly body?: unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Request headers
|
|
47
|
+
*/
|
|
48
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
49
|
+
/**
|
|
50
|
+
* Abort signal to cancel the request
|
|
51
|
+
*/
|
|
52
|
+
readonly signal?: AbortSignal;
|
|
53
|
+
/**
|
|
54
|
+
* Timeout in milliseconds
|
|
55
|
+
*/
|
|
56
|
+
readonly timeout?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Middleware function following the "Onion Model" pattern
|
|
60
|
+
*/
|
|
61
|
+
export type Middleware = (req: RequestConfig, next: (req: RequestConfig) => Promise<HttpResponse>) => Promise<HttpResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Request interceptor
|
|
64
|
+
*/
|
|
65
|
+
export type RequestInterceptor = (req: Readonly<RequestConfig>) => RequestConfig | Promise<RequestConfig>;
|
|
66
|
+
/**
|
|
67
|
+
* Response interceptor
|
|
68
|
+
*/
|
|
69
|
+
export type ResponseInterceptor = (res: HttpResponse, req: Readonly<RequestConfig>) => HttpResponse | Promise<HttpResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Prioritized interceptor registration
|
|
72
|
+
*/
|
|
73
|
+
export interface InterceptorEntry<T> {
|
|
74
|
+
readonly handler: T;
|
|
75
|
+
readonly priority?: number;
|
|
76
|
+
readonly name?: string;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/types/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1F;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,UAAU,EAAE,CAAC,CAAC,CAA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AAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAChC,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,QAAQ,CAAC,aAAa,CAAC,KACzB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/types/http.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RequestConfig, Middleware } from "./http";
|
|
2
|
+
import type { HttpResponse } from "../response/response";
|
|
3
|
+
/**
|
|
4
|
+
* Internal request state with middleware queue
|
|
5
|
+
*/
|
|
6
|
+
export interface InternalRequestConfig extends RequestConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Middleware chain local to this specific request
|
|
9
|
+
*/
|
|
10
|
+
readonly _middlewares: readonly Middleware[];
|
|
11
|
+
/**
|
|
12
|
+
* Optional metadata container for internal instrumentation.
|
|
13
|
+
*/
|
|
14
|
+
readonly _meta?: Readonly<Record<string, unknown>>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Type of a middleware executor after composition
|
|
18
|
+
*/
|
|
19
|
+
export type ComposedMiddleware = (req: InternalRequestConfig) => Promise<HttpResponse>;
|
|
20
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/types/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC1D;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7C;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,qBAAqB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/types/internal.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HttpResponse } from "../response/response";
|
|
2
|
+
export type Ok<T> = {
|
|
3
|
+
readonly ok: true;
|
|
4
|
+
readonly data: T;
|
|
5
|
+
};
|
|
6
|
+
export type Err<E> = {
|
|
7
|
+
readonly ok: false;
|
|
8
|
+
readonly error: E;
|
|
9
|
+
};
|
|
10
|
+
export type Result<T, E> = Ok<T> | Err<E>;
|
|
11
|
+
export type PureqErrorKind = "network" | "timeout" | "aborted" | "http" | "circuit-open" | "unknown";
|
|
12
|
+
export interface PureqErrorMetadata {
|
|
13
|
+
readonly requestId?: string;
|
|
14
|
+
readonly method?: string;
|
|
15
|
+
readonly url?: string;
|
|
16
|
+
readonly retryCount?: number;
|
|
17
|
+
readonly rootCause?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PureqError {
|
|
20
|
+
readonly kind: PureqErrorKind;
|
|
21
|
+
readonly message: string;
|
|
22
|
+
readonly cause: unknown;
|
|
23
|
+
readonly status?: number;
|
|
24
|
+
readonly statusText?: string;
|
|
25
|
+
readonly metadata?: PureqErrorMetadata;
|
|
26
|
+
}
|
|
27
|
+
export type HttpResult = Result<HttpResponse, PureqError>;
|
|
28
|
+
export declare function ok<T>(data: T): Ok<T>;
|
|
29
|
+
export declare function err<E>(error: E): Err<E>;
|
|
30
|
+
export declare function toPureqError(cause: unknown, metadata?: PureqErrorMetadata): PureqError;
|
|
31
|
+
export declare function httpErrorFromResponse(response: HttpResponse, metadata?: PureqErrorMetadata): PureqError;
|
|
32
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/types/result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,MAAM,EAAE,CAAC,CAAC,IAAI;IAClB,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAE1C,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;AAErG,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CACxC;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAE1D,wBAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAEpC;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAEvC;AAkBD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,GAAE,kBAAuB,GAAG,UAAU,CA4C1F;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,GAAE,kBAAuB,GAAG,UAAU,CAY3G"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function ok(data) {
|
|
2
|
+
return { ok: true, data };
|
|
3
|
+
}
|
|
4
|
+
export function err(error) {
|
|
5
|
+
return { ok: false, error };
|
|
6
|
+
}
|
|
7
|
+
function extractRetryCount(cause) {
|
|
8
|
+
if (typeof cause === "object" && cause !== null && "__pureqRetryCount" in cause) {
|
|
9
|
+
const value = cause.__pureqRetryCount;
|
|
10
|
+
return typeof value === "number" ? value : undefined;
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
function inferRootCause(cause) {
|
|
15
|
+
// DOMException extends Error, so a single instanceof Error check covers both.
|
|
16
|
+
if (cause instanceof Error) {
|
|
17
|
+
return cause.name;
|
|
18
|
+
}
|
|
19
|
+
return typeof cause;
|
|
20
|
+
}
|
|
21
|
+
export function toPureqError(cause, metadata = {}) {
|
|
22
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
23
|
+
const isTypeErrorLike = cause instanceof TypeError ||
|
|
24
|
+
(typeof cause === "object" &&
|
|
25
|
+
cause !== null &&
|
|
26
|
+
"name" in cause &&
|
|
27
|
+
cause.name === "TypeError");
|
|
28
|
+
const looksLikeNetworkMessage = /network|fetch|socket|econn|enotfound|timed out/i.test(message);
|
|
29
|
+
const retryCount = metadata.retryCount !== undefined ? metadata.retryCount : extractRetryCount(cause);
|
|
30
|
+
const rootCause = metadata.rootCause !== undefined ? metadata.rootCause : inferRootCause(cause);
|
|
31
|
+
const normalizedMetadata = {
|
|
32
|
+
...metadata,
|
|
33
|
+
...(retryCount !== undefined ? { retryCount } : {}),
|
|
34
|
+
...(rootCause !== undefined ? { rootCause } : {}),
|
|
35
|
+
};
|
|
36
|
+
if (cause instanceof Error && cause.message.includes("request timeout")) {
|
|
37
|
+
return { kind: "timeout", message, cause, metadata: normalizedMetadata };
|
|
38
|
+
}
|
|
39
|
+
if (cause instanceof DOMException &&
|
|
40
|
+
cause.name === "AbortError") {
|
|
41
|
+
return { kind: "aborted", message, cause, metadata: normalizedMetadata };
|
|
42
|
+
}
|
|
43
|
+
if (isTypeErrorLike || looksLikeNetworkMessage) {
|
|
44
|
+
return { kind: "network", message, cause, metadata: normalizedMetadata };
|
|
45
|
+
}
|
|
46
|
+
if (cause instanceof Error &&
|
|
47
|
+
(cause.name === "PureqCircuitOpenError" ||
|
|
48
|
+
message.includes("circuit breaker is open") ||
|
|
49
|
+
message.includes("half-open probe in flight"))) {
|
|
50
|
+
return { kind: "circuit-open", message, cause, metadata: normalizedMetadata };
|
|
51
|
+
}
|
|
52
|
+
return { kind: "unknown", message, cause, metadata: normalizedMetadata };
|
|
53
|
+
}
|
|
54
|
+
export function httpErrorFromResponse(response, metadata = {}) {
|
|
55
|
+
const base = `HTTP ${response.status}`;
|
|
56
|
+
const detail = response.statusText ? ` ${response.statusText}` : "";
|
|
57
|
+
return {
|
|
58
|
+
kind: "http",
|
|
59
|
+
message: `${base}${detail}`,
|
|
60
|
+
cause: response,
|
|
61
|
+
status: response.status,
|
|
62
|
+
statusText: response.statusText,
|
|
63
|
+
metadata,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/types/result.ts"],"names":[],"mappings":"AAmCA,MAAM,UAAU,EAAE,CAAI,IAAO;IAC3B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,GAAG,CAAI,KAAQ;IAC7B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,mBAAmB,IAAI,KAAK,EAAE,CAAC;QAChF,MAAM,KAAK,GAAI,KAAyC,CAAC,iBAAiB,CAAC;QAC3E,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,8EAA8E;IAC9E,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,OAAO,OAAO,KAAK,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,WAA+B,EAAE;IAC5E,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CA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uB,EAAE,CAAC;QAC/C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC3E,CAAC;IAED,IACE,KAAK,YAAY,KAAK;QACtB,CAAC,KAAK,CAAC,IAAI,KAAK,uBAAuB;YACrC,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAC;YAC3C,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC,EAChD,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAChF,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,QAAsB,EAAE,WAA+B,EAAE;IAC7F,MAAM,IAAI,GAAG,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAEpE,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,GAAG,IAAI,GAAG,MAAM,EAAE;QAC3B,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a cryptographically strong random ID.
|
|
3
|
+
* Prefers crypto.randomUUID, falls back to crypto.getRandomValues,
|
|
4
|
+
* and only uses Math.random as a last resort for environments
|
|
5
|
+
* without any Web Crypto API support.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateSecureId(prefix?: string): string;
|
|
8
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAexD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a cryptographically strong random ID.
|
|
3
|
+
* Prefers crypto.randomUUID, falls back to crypto.getRandomValues,
|
|
4
|
+
* and only uses Math.random as a last resort for environments
|
|
5
|
+
* without any Web Crypto API support.
|
|
6
|
+
*/
|
|
7
|
+
export function generateSecureId(prefix) {
|
|
8
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9
|
+
return crypto.randomUUID();
|
|
10
|
+
}
|
|
11
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
12
|
+
const bytes = new Uint8Array(16);
|
|
13
|
+
crypto.getRandomValues(bytes);
|
|
14
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
15
|
+
return prefix ? `${prefix}-${hex}` : hex;
|
|
16
|
+
}
|
|
17
|
+
// Last resort fallback for legacy environments without Web Crypto API.
|
|
18
|
+
// This is NOT cryptographically secure.
|
|
19
|
+
return `${prefix ?? "id"}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAe;IAC9C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC7E,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QAClF,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QACjC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC9B,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/E,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC3C,CAAC;IAED,uEAAuE;IACvE,wCAAwC;IACxC,OAAO,GAAG,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility for appending policy trace entries to the internal
|
|
3
|
+
* request metadata. The _meta object is intentionally mutable to allow
|
|
4
|
+
* trace accumulation as the request traverses the middleware pipeline.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: When forking requests (e.g. hedge middleware), callers
|
|
7
|
+
* must deep-copy _meta first to prevent cross-fork trace pollution.
|
|
8
|
+
*/
|
|
9
|
+
import type { RequestConfig } from "../types/http";
|
|
10
|
+
import type { PolicyTraceEntry } from "../types/events";
|
|
11
|
+
export declare function appendPolicyTrace(req: RequestConfig, entry: PolicyTraceEntry): void;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a deep copy of the internal _meta object so that forked
|
|
14
|
+
* request paths (e.g. primary vs hedge) do not share mutable state.
|
|
15
|
+
*/
|
|
16
|
+
export declare function deepCopyMeta(req: RequestConfig): Record<string, unknown>;
|
|
17
|
+
//# sourceMappingURL=policyTrace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policyTrace.d.ts","sourceRoot":"","sources":["../../../src/utils/policyTrace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAUnF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,aAAa,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
|