@private.me/xbind 1.3.5 → 3.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/LICENSES.md +212 -0
- package/README.md +388 -6
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
- package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
- package/dist-standalone/_deps/shared/cjs/index.js +1 -496
- package/dist-standalone/_deps/shared/cjs/types.js +1 -317
- package/dist-standalone/_deps/shared/errors.js +1 -255
- package/dist-standalone/_deps/shared/index.js +1 -74
- package/dist-standalone/_deps/shared/types.js +1 -90
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/search.js +1 -1
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
- package/dist-standalone/_deps/xchange/errors.js +1 -1
- package/dist-standalone/_deps/xchange/index.js +1 -1
- package/dist-standalone/_deps/xchange/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/xchange.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
- package/dist-standalone/_deps/xregistry/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/index.js +1 -1
- package/dist-standalone/_deps/xregistry/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/types.js +1 -1
- package/dist-standalone/agent-call.js +1 -642
- package/dist-standalone/agent-sdk.js +1 -328
- package/dist-standalone/agent.d.ts +95 -5
- package/dist-standalone/agent.js +1 -1545
- package/dist-standalone/approval.js +1 -193
- package/dist-standalone/async-iterators.d.ts +275 -0
- package/dist-standalone/async-iterators.js +1 -0
- package/dist-standalone/auth.js +1 -219
- package/dist-standalone/auto-accept.js +1 -229
- package/dist-standalone/backup-config.js +1 -201
- package/dist-standalone/backup.d.ts +114 -0
- package/dist-standalone/backup.js +1 -0
- package/dist-standalone/batch-operations.d.ts +297 -0
- package/dist-standalone/batch-operations.js +1 -0
- package/dist-standalone/cancellation.d.ts +301 -0
- package/dist-standalone/cancellation.js +1 -0
- package/dist-standalone/checkpoint.js +1 -186
- package/dist-standalone/circuit-breaker.d.ts +351 -0
- package/dist-standalone/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/agent-call.js +1 -651
- package/dist-standalone/cjs/agent-sdk.js +1 -332
- package/dist-standalone/cjs/agent.js +1 -1582
- package/dist-standalone/cjs/approval.js +1 -199
- package/dist-standalone/cjs/async-iterators.js +1 -0
- package/dist-standalone/cjs/auth.js +1 -225
- package/dist-standalone/cjs/auto-accept.js +1 -233
- package/dist-standalone/cjs/backup-config.js +1 -207
- package/dist-standalone/cjs/backup.js +1 -0
- package/dist-standalone/cjs/batch-operations.js +1 -0
- package/dist-standalone/cjs/cancellation.js +1 -0
- package/dist-standalone/cjs/checkpoint.js +1 -193
- package/dist-standalone/cjs/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/cli/init.js +1 -486
- package/dist-standalone/cjs/config-validation.js +1 -0
- package/dist-standalone/cjs/connect.js +1 -312
- package/dist-standalone/cjs/connection-pool.js +1 -0
- package/dist-standalone/cjs/correlation-id.js +1 -339
- package/dist-standalone/cjs/crypto-utils.js +1 -0
- package/dist-standalone/cjs/debug-mode.js +1 -0
- package/dist-standalone/cjs/did-document.js +1 -101
- package/dist-standalone/cjs/did-privateme.js +1 -130
- package/dist-standalone/cjs/did-web.js +1 -201
- package/dist-standalone/cjs/discovery.js +1 -462
- package/dist-standalone/cjs/dual-mode.js +1 -251
- package/dist-standalone/cjs/email-templates.js +1 -313
- package/dist-standalone/cjs/email-transport.js +1 -239
- package/dist-standalone/cjs/envelope.js +1 -510
- package/dist-standalone/cjs/errors.js +1 -826
- package/dist-standalone/cjs/event-emitter.js +1 -0
- package/dist-standalone/cjs/gateway-state.js +1 -55
- package/dist-standalone/cjs/gateway-transport.js +1 -120
- package/dist-standalone/cjs/graceful-degradation.js +1 -0
- package/dist-standalone/cjs/guardrails.js +1 -223
- package/dist-standalone/cjs/health-check.js +1 -0
- package/dist-standalone/cjs/http-compat.js +1 -272
- package/dist-standalone/cjs/http-status-map.js +1 -571
- package/dist-standalone/cjs/identity.js +1 -540
- package/dist-standalone/cjs/index.js +1 -237
- package/dist-standalone/cjs/invitation.js +1 -421
- package/dist-standalone/cjs/invite.js +1 -328
- package/dist-standalone/cjs/key-agreement.js +1 -246
- package/dist-standalone/cjs/lazy-init.js +1 -300
- package/dist-standalone/cjs/logger.js +1 -0
- package/dist-standalone/cjs/mdns-discovery.js +1 -202
- package/dist-standalone/cjs/nonce-store.js +1 -66
- package/dist-standalone/cjs/pairing-manager.js +1 -223
- package/dist-standalone/cjs/plugin-system.js +1 -0
- package/dist-standalone/cjs/plugins/logging.js +1 -0
- package/dist-standalone/cjs/plugins/metrics.js +1 -0
- package/dist-standalone/cjs/plugins/validation.js +1 -0
- package/dist-standalone/cjs/policy.js +1 -320
- package/dist-standalone/cjs/progress-callbacks.js +1 -0
- package/dist-standalone/cjs/redis-nonce-store.js +1 -76
- package/dist-standalone/cjs/registry-middleware.js +1 -50
- package/dist-standalone/cjs/retry-strategies.js +1 -0
- package/dist-standalone/cjs/retry-transport.js +1 -102
- package/dist-standalone/cjs/runtime/browser.js +1 -0
- package/dist-standalone/cjs/runtime/edge.js +1 -0
- package/dist-standalone/cjs/runtime/react-native.js +1 -0
- package/dist-standalone/cjs/security-policy.js +1 -245
- package/dist-standalone/cjs/serialization.js +1 -0
- package/dist-standalone/cjs/split-channel.js +1 -177
- package/dist-standalone/cjs/subscription-proof.js +1 -230
- package/dist-standalone/cjs/succession.js +1 -148
- package/dist-standalone/cjs/timeouts.js +1 -0
- package/dist-standalone/cjs/trace-context.js +1 -0
- package/dist-standalone/cjs/trace-spans.js +1 -0
- package/dist-standalone/cjs/transport.js +1 -63
- package/dist-standalone/cjs/trust-registry.js +1 -742
- package/dist-standalone/cjs/types/error-response.js +1 -56
- package/dist-standalone/cjs/vault-auth.js +1 -0
- package/dist-standalone/cjs/vault-store-loader.js +1 -0
- package/dist-standalone/cjs/verify.js +1 -25
- package/dist-standalone/cjs/version-info.js +1 -0
- package/dist-standalone/cjs/xfetch.js +1 -252
- package/dist-standalone/cli/init.js +1 -449
- package/dist-standalone/cli/setup.js +1 -514
- package/dist-standalone/cli/types.js +1 -27
- package/dist-standalone/cli/xbind.js +1 -148
- package/dist-standalone/config-validation.d.ts +185 -0
- package/dist-standalone/config-validation.js +1 -0
- package/dist-standalone/connect.js +1 -274
- package/dist-standalone/connection-pool.d.ts +251 -0
- package/dist-standalone/connection-pool.js +1 -0
- package/dist-standalone/correlation-id.js +1 -326
- package/dist-standalone/crypto-utils.d.ts +60 -0
- package/dist-standalone/crypto-utils.js +1 -0
- package/dist-standalone/debug-mode.d.ts +286 -0
- package/dist-standalone/debug-mode.js +1 -0
- package/dist-standalone/did-document.js +1 -96
- package/dist-standalone/did-privateme.js +1 -121
- package/dist-standalone/did-web.js +1 -196
- package/dist-standalone/discovery.js +1 -458
- package/dist-standalone/dual-mode.js +1 -247
- package/dist-standalone/email-templates.js +1 -309
- package/dist-standalone/email-transport.js +1 -232
- package/dist-standalone/envelope.d.ts +29 -1
- package/dist-standalone/envelope.js +1 -497
- package/dist-standalone/errors.d.ts +10 -0
- package/dist-standalone/errors.js +1 -811
- package/dist-standalone/event-emitter.d.ts +395 -0
- package/dist-standalone/event-emitter.js +1 -0
- package/dist-standalone/gateway-state.js +1 -51
- package/dist-standalone/gateway-transport.js +1 -116
- package/dist-standalone/graceful-degradation.d.ts +246 -0
- package/dist-standalone/graceful-degradation.js +1 -0
- package/dist-standalone/guardrails.js +1 -216
- package/dist-standalone/health-check.d.ts +150 -0
- package/dist-standalone/health-check.js +1 -0
- package/dist-standalone/http-compat.js +1 -267
- package/dist-standalone/http-status-map.js +1 -561
- package/dist-standalone/identity.d.ts +64 -1
- package/dist-standalone/identity.js +1 -515
- package/dist-standalone/index.d.ts +45 -3
- package/dist-standalone/index.js +1 -52
- package/dist-standalone/invitation.js +1 -415
- package/dist-standalone/invite.js +1 -324
- package/dist-standalone/key-agreement.d.ts +61 -13
- package/dist-standalone/key-agreement.js +1 -236
- package/dist-standalone/lazy-init.js +1 -295
- package/dist-standalone/logger.d.ts +77 -0
- package/dist-standalone/logger.js +1 -0
- package/dist-standalone/mdns-discovery.js +1 -195
- package/dist-standalone/nonce-store.d.ts +16 -3
- package/dist-standalone/nonce-store.js +1 -62
- package/dist-standalone/package.json +0 -1
- package/dist-standalone/pairing-manager.js +1 -219
- package/dist-standalone/plugin-system.d.ts +145 -0
- package/dist-standalone/plugin-system.js +1 -0
- package/dist-standalone/policy.js +1 -315
- package/dist-standalone/progress-callbacks.d.ts +394 -0
- package/dist-standalone/progress-callbacks.js +1 -0
- package/dist-standalone/redis-nonce-store.js +1 -72
- package/dist-standalone/registry-middleware.js +1 -47
- package/dist-standalone/retry-strategies.d.ts +382 -0
- package/dist-standalone/retry-strategies.js +1 -0
- package/dist-standalone/retry-transport.js +1 -98
- package/dist-standalone/security-policy.js +1 -239
- package/dist-standalone/serialization.d.ts +244 -0
- package/dist-standalone/serialization.js +1 -0
- package/dist-standalone/split-channel.d.ts +49 -1
- package/dist-standalone/split-channel.js +1 -171
- package/dist-standalone/subscription-proof.js +1 -224
- package/dist-standalone/succession.js +1 -142
- package/dist-standalone/timeouts.d.ts +275 -0
- package/dist-standalone/timeouts.js +1 -0
- package/dist-standalone/trace-context.d.ts +252 -0
- package/dist-standalone/trace-context.js +1 -0
- package/dist-standalone/trace-spans.d.ts +360 -0
- package/dist-standalone/trace-spans.js +1 -0
- package/dist-standalone/transport.js +1 -59
- package/dist-standalone/trust-registry.d.ts +106 -5
- package/dist-standalone/trust-registry.js +1 -702
- package/dist-standalone/vault-auth.d.ts +91 -0
- package/dist-standalone/vault-auth.js +1 -0
- package/dist-standalone/vault-store-loader.d.ts +110 -0
- package/dist-standalone/vault-store-loader.js +1 -0
- package/dist-standalone/verify.js +1 -16
- package/dist-standalone/version-info.d.ts +259 -0
- package/dist-standalone/version-info.js +1 -0
- package/dist-standalone/xfetch.js +1 -247
- package/llms.txt +1 -0
- package/package.json +65 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -222
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
- package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -199
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -134
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -145
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -159
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -92
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -295
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -364
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -136
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -71
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -366
- package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/errors.js.map +0 -1
- package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/index.js.map +0 -1
- package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
- package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/index.js.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
- package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/types.js.map +0 -1
|
@@ -1,267 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @module http-compat
|
|
3
|
-
* HTTP client compatibility adapters for xBind auto-upgrade
|
|
4
|
-
*
|
|
5
|
-
* Provides drop-in replacements for popular HTTP clients (fetch, axios, got)
|
|
6
|
-
* that transparently upgrade to xBind when both parties support it.
|
|
7
|
-
*/
|
|
8
|
-
import { xfetch } from './xfetch.js';
|
|
9
|
-
/**
|
|
10
|
-
* Create axios-compatible HTTP client with xBind auto-upgrade
|
|
11
|
-
*
|
|
12
|
-
* Drop-in replacement for axios that transparently upgrades to xBind.
|
|
13
|
-
*
|
|
14
|
-
* @returns Axios-compatible client
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { createAxiosCompat } from '@private.me/xbind/http-compat';
|
|
19
|
-
*
|
|
20
|
-
* const axios = createAxiosCompat();
|
|
21
|
-
*
|
|
22
|
-
* // Auto-upgrades to xBind if supported
|
|
23
|
-
* const response = await axios.get('https://api.example.com/data');
|
|
24
|
-
* console.log('Used xBind?', response.xbind?.used);
|
|
25
|
-
* console.log('Data:', response.data);
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export function createAxiosCompat() {
|
|
29
|
-
async function request(config) {
|
|
30
|
-
// Normalize config
|
|
31
|
-
const cfg = typeof config === 'string' ? { url: config } : config;
|
|
32
|
-
const method = cfg.method?.toUpperCase() ?? 'GET';
|
|
33
|
-
const url = cfg.baseURL
|
|
34
|
-
? new URL(cfg.url ?? '', cfg.baseURL).toString()
|
|
35
|
-
: cfg.url ?? '';
|
|
36
|
-
// Build headers
|
|
37
|
-
const headers = { ...cfg.headers };
|
|
38
|
-
// Build URL with query params
|
|
39
|
-
let finalUrl = url;
|
|
40
|
-
if (cfg.params) {
|
|
41
|
-
const params = new URLSearchParams();
|
|
42
|
-
for (const [key, value] of Object.entries(cfg.params)) {
|
|
43
|
-
params.append(key, String(value));
|
|
44
|
-
}
|
|
45
|
-
finalUrl = `${url}?${params.toString()}`;
|
|
46
|
-
}
|
|
47
|
-
// Build request body
|
|
48
|
-
let body;
|
|
49
|
-
if (cfg.data) {
|
|
50
|
-
if (typeof cfg.data === 'string') {
|
|
51
|
-
body = cfg.data;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
body = JSON.stringify(cfg.data);
|
|
55
|
-
headers['Content-Type'] = 'application/json';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Convert to xfetch options
|
|
59
|
-
const xfetchOpts = {
|
|
60
|
-
method,
|
|
61
|
-
headers,
|
|
62
|
-
body,
|
|
63
|
-
timeout: cfg.timeout,
|
|
64
|
-
forceXBind: cfg.forceXBind,
|
|
65
|
-
disableXBind: cfg.disableXBind,
|
|
66
|
-
};
|
|
67
|
-
// Make request via xfetch
|
|
68
|
-
const response = await xfetch(finalUrl, xfetchOpts);
|
|
69
|
-
// Parse response body based on responseType
|
|
70
|
-
let data;
|
|
71
|
-
const responseType = cfg.responseType ?? 'json';
|
|
72
|
-
switch (responseType) {
|
|
73
|
-
case 'json':
|
|
74
|
-
data = (await response.json());
|
|
75
|
-
break;
|
|
76
|
-
case 'text':
|
|
77
|
-
data = (await response.text());
|
|
78
|
-
break;
|
|
79
|
-
case 'blob':
|
|
80
|
-
data = (await response.blob());
|
|
81
|
-
break;
|
|
82
|
-
case 'arraybuffer':
|
|
83
|
-
data = (await response.arrayBuffer());
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
data = (await response.json());
|
|
87
|
-
}
|
|
88
|
-
// Validate status if custom validator provided
|
|
89
|
-
if (cfg.validateStatus && !cfg.validateStatus(response.status)) {
|
|
90
|
-
throw new Error(`Request failed with status ${response.status}`);
|
|
91
|
-
}
|
|
92
|
-
// Convert headers to object
|
|
93
|
-
const responseHeaders = {};
|
|
94
|
-
response.headers.forEach((value, key) => {
|
|
95
|
-
responseHeaders[key] = value;
|
|
96
|
-
});
|
|
97
|
-
return {
|
|
98
|
-
data,
|
|
99
|
-
status: response.status,
|
|
100
|
-
statusText: response.statusText,
|
|
101
|
-
headers: responseHeaders,
|
|
102
|
-
config: cfg,
|
|
103
|
-
xbind: {
|
|
104
|
-
used: response.usedXBind,
|
|
105
|
-
protocol: response.transport.protocol,
|
|
106
|
-
latency: response.transport.latency,
|
|
107
|
-
peerDID: response.transport.peerDID,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
// Convenience methods
|
|
112
|
-
async function get(url, config) {
|
|
113
|
-
return request({ ...config, url, method: 'GET' });
|
|
114
|
-
}
|
|
115
|
-
async function post(url, data, config) {
|
|
116
|
-
return request({ ...config, url, method: 'POST', data });
|
|
117
|
-
}
|
|
118
|
-
async function put(url, data, config) {
|
|
119
|
-
return request({ ...config, url, method: 'PUT', data });
|
|
120
|
-
}
|
|
121
|
-
async function patch(url, data, config) {
|
|
122
|
-
return request({ ...config, url, method: 'PATCH', data });
|
|
123
|
-
}
|
|
124
|
-
async function del(url, config) {
|
|
125
|
-
return request({ ...config, url, method: 'DELETE' });
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
request,
|
|
129
|
-
get,
|
|
130
|
-
post,
|
|
131
|
-
put,
|
|
132
|
-
patch,
|
|
133
|
-
delete: del,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Create got-compatible HTTP client with xBind auto-upgrade
|
|
138
|
-
*
|
|
139
|
-
* Drop-in replacement for got that transparently upgrades to xBind.
|
|
140
|
-
*
|
|
141
|
-
* @returns Got-compatible client
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* import { createGotCompat } from '@private.me/xbind/http-compat';
|
|
146
|
-
*
|
|
147
|
-
* const got = createGotCompat();
|
|
148
|
-
*
|
|
149
|
-
* // Auto-upgrades to xBind if supported
|
|
150
|
-
* const response = await got('https://api.example.com/data', {
|
|
151
|
-
* responseType: 'json',
|
|
152
|
-
* });
|
|
153
|
-
* console.log('Used xBind?', response.xbind?.used);
|
|
154
|
-
* console.log('Body:', response.body);
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
export function createGotCompat() {
|
|
158
|
-
async function got(url, options) {
|
|
159
|
-
// Normalize options
|
|
160
|
-
const opts = typeof url === 'string' ? { ...options, url } : url;
|
|
161
|
-
const method = opts.method?.toUpperCase() ?? 'GET';
|
|
162
|
-
const finalUrl = opts.url ?? '';
|
|
163
|
-
// Build headers
|
|
164
|
-
const headers = { ...opts.headers };
|
|
165
|
-
// Build URL with search params
|
|
166
|
-
let urlWithParams = finalUrl;
|
|
167
|
-
if (opts.searchParams) {
|
|
168
|
-
const params = new URLSearchParams();
|
|
169
|
-
for (const [key, value] of Object.entries(opts.searchParams)) {
|
|
170
|
-
params.append(key, String(value));
|
|
171
|
-
}
|
|
172
|
-
urlWithParams = `${finalUrl}?${params.toString()}`;
|
|
173
|
-
}
|
|
174
|
-
// Build request body
|
|
175
|
-
let body;
|
|
176
|
-
if (opts.json) {
|
|
177
|
-
body = JSON.stringify(opts.json);
|
|
178
|
-
headers['Content-Type'] = 'application/json';
|
|
179
|
-
}
|
|
180
|
-
else if (opts.body) {
|
|
181
|
-
// Convert Buffer to string for compatibility with xfetch
|
|
182
|
-
// SAFETY: After instanceof check, both branches produce string type
|
|
183
|
-
body = (opts.body instanceof Buffer ? opts.body.toString() : opts.body);
|
|
184
|
-
}
|
|
185
|
-
// Extract timeout
|
|
186
|
-
const timeout = typeof opts.timeout === 'number'
|
|
187
|
-
? opts.timeout
|
|
188
|
-
: opts.timeout?.request;
|
|
189
|
-
// Convert to xfetch options
|
|
190
|
-
const xfetchOpts = {
|
|
191
|
-
method,
|
|
192
|
-
headers,
|
|
193
|
-
body,
|
|
194
|
-
timeout,
|
|
195
|
-
forceXBind: opts.forceXBind,
|
|
196
|
-
disableXBind: opts.disableXBind,
|
|
197
|
-
};
|
|
198
|
-
// Make request via xfetch
|
|
199
|
-
const response = await xfetch(urlWithParams, xfetchOpts);
|
|
200
|
-
// Parse response body based on responseType
|
|
201
|
-
let responseBody;
|
|
202
|
-
const responseType = opts.responseType ?? 'text';
|
|
203
|
-
switch (responseType) {
|
|
204
|
-
case 'json':
|
|
205
|
-
responseBody = (await response.json());
|
|
206
|
-
break;
|
|
207
|
-
case 'text':
|
|
208
|
-
responseBody = (await response.text());
|
|
209
|
-
break;
|
|
210
|
-
case 'buffer':
|
|
211
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
212
|
-
responseBody = Buffer.from(arrayBuffer);
|
|
213
|
-
break;
|
|
214
|
-
default:
|
|
215
|
-
responseBody = (await response.text());
|
|
216
|
-
}
|
|
217
|
-
// Convert headers to object
|
|
218
|
-
const responseHeaders = {};
|
|
219
|
-
response.headers.forEach((value, key) => {
|
|
220
|
-
responseHeaders[key] = value;
|
|
221
|
-
});
|
|
222
|
-
return {
|
|
223
|
-
body: responseBody,
|
|
224
|
-
statusCode: response.status,
|
|
225
|
-
headers: responseHeaders,
|
|
226
|
-
url: response.url,
|
|
227
|
-
requestUrl: urlWithParams,
|
|
228
|
-
xbind: {
|
|
229
|
-
used: response.usedXBind,
|
|
230
|
-
protocol: response.transport.protocol,
|
|
231
|
-
latency: response.transport.latency,
|
|
232
|
-
peerDID: response.transport.peerDID,
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
// Convenience methods
|
|
237
|
-
got.get = (url, options) => got(url, { ...options, method: 'GET' });
|
|
238
|
-
got.post = (url, options) => got(url, { ...options, method: 'POST' });
|
|
239
|
-
got.put = (url, options) => got(url, { ...options, method: 'PUT' });
|
|
240
|
-
got.patch = (url, options) => got(url, { ...options, method: 'PATCH' });
|
|
241
|
-
got.delete = (url, options) => got(url, { ...options, method: 'DELETE' });
|
|
242
|
-
return got;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Wrap existing fetch implementation with xBind auto-upgrade
|
|
246
|
-
*
|
|
247
|
-
* Use this to upgrade an existing fetch instance (like node-fetch, cross-fetch, etc.)
|
|
248
|
-
*
|
|
249
|
-
* @param fetchImpl - Fetch implementation to wrap
|
|
250
|
-
* @returns Wrapped fetch with xBind support
|
|
251
|
-
*
|
|
252
|
-
* @example
|
|
253
|
-
* ```typescript
|
|
254
|
-
* import { wrapFetch } from '@private.me/xbind/http-compat';
|
|
255
|
-
* import nodeFetch from 'node-fetch';
|
|
256
|
-
*
|
|
257
|
-
* const fetch = wrapFetch(nodeFetch);
|
|
258
|
-
*
|
|
259
|
-
* // Uses xBind if supported, falls back to node-fetch
|
|
260
|
-
* const response = await fetch('https://api.example.com/data');
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
263
|
-
export function wrapFetch(fetchImpl) {
|
|
264
|
-
// Return xfetch (which already handles auto-upgrade and fallback)
|
|
265
|
-
// The original fetchImpl is not used because xfetch uses global fetch
|
|
266
|
-
return xfetch;
|
|
267
|
-
}
|
|
1
|
+
import{xfetch}from"./xfetch.js";export function createAxiosCompat(){async function t(t){const e="string"==typeof t?{url:t}:t,a=e.method?.toUpperCase()??"GET",r=e.baseURL?new URL(e.url??"",e.baseURL).toString():e.url??"",o={...e.headers};let n,s=r;if(e.params){const t=new URLSearchParams;for(const[a,r]of Object.entries(e.params))t.append(a,String(r));s=`${r}?${t.toString()}`}e.data&&("string"==typeof e.data?n=e.data:(n=JSON.stringify(e.data),o["Content-Type"]="application/json"));const i={method:a,headers:o,body:n,timeout:e.timeout,forceXBind:e.forceXBind,disableXBind:e.disableXBind},c=await xfetch(s,i);let u;switch(e.responseType??"json"){case"json":default:u=await c.json();break;case"text":u=await c.text();break;case"blob":u=await c.blob();break;case"arraybuffer":u=await c.arrayBuffer()}if(e.validateStatus&&!e.validateStatus(c.status))throw new Error(`Request failed with status ${c.status}`);const d={};return c.headers.forEach((t,e)=>{d[e]=t}),{data:u,status:c.status,statusText:c.statusText,headers:d,config:e,xbind:{used:c.usedXBind,protocol:c.transport.protocol,latency:c.transport.latency,peerDID:c.transport.peerDID}}}return{request:t,get:async function(e,a){return t({...a,url:e,method:"GET"})},post:async function(e,a,r){return t({...r,url:e,method:"POST",data:a})},put:async function(e,a,r){return t({...r,url:e,method:"PUT",data:a})},patch:async function(e,a,r){return t({...r,url:e,method:"PATCH",data:a})},delete:async function(e,a){return t({...a,url:e,method:"DELETE"})}}}export function createGotCompat(){async function t(t,e){const a="string"==typeof t?{...e,url:t}:t,r=a.method?.toUpperCase()??"GET",o=a.url??"",n={...a.headers};let s,i=o;if(a.searchParams){const t=new URLSearchParams;for(const[e,r]of Object.entries(a.searchParams))t.append(e,String(r));i=`${o}?${t.toString()}`}a.json?(s=JSON.stringify(a.json),n["Content-Type"]="application/json"):a.body&&(s=a.body instanceof Buffer?a.body.toString():a.body);const c={method:r,headers:n,body:s,timeout:"number"==typeof a.timeout?a.timeout:a.timeout?.request,forceXBind:a.forceXBind,disableXBind:a.disableXBind},u=await xfetch(i,c);let d;switch(a.responseType??"text"){case"json":d=await u.json();break;case"text":default:d=await u.text();break;case"buffer":const t=await u.arrayBuffer();d=Buffer.from(t)}const f={};return u.headers.forEach((t,e)=>{f[e]=t}),{body:d,statusCode:u.status,headers:f,url:u.url,requestUrl:i,xbind:{used:u.usedXBind,protocol:u.transport.protocol,latency:u.transport.latency,peerDID:u.transport.peerDID}}}return t.get=(e,a)=>t(e,{...a,method:"GET"}),t.post=(e,a)=>t(e,{...a,method:"POST"}),t.put=(e,a)=>t(e,{...a,method:"PUT"}),t.patch=(e,a)=>t(e,{...a,method:"PATCH"}),t.delete=(e,a)=>t(e,{...a,method:"DELETE"}),t}export function wrapFetch(){return xfetch}
|