@private.me/xbind 1.3.0 → 2.3.4
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 -275
- package/dist-standalone/_deps/shared/cjs/index.js +1 -138
- package/dist-standalone/_deps/shared/cjs/types.js +1 -90
- package/dist-standalone/_deps/shared/errors.js +1 -262
- package/dist-standalone/_deps/shared/index.js +1 -77
- package/dist-standalone/_deps/shared/types.js +1 -91
- 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 -541
- 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 -516
- 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 +66 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -209
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -103
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -119
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -71
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -86
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -57
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -68
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -152
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -199
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -61
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -24
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -221
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -109
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -66
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -45
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -53
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -63
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -148
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -195
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -56
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -15
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -215
- 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,272 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module http-compat
|
|
4
|
-
* HTTP client compatibility adapters for xBind auto-upgrade
|
|
5
|
-
*
|
|
6
|
-
* Provides drop-in replacements for popular HTTP clients (fetch, axios, got)
|
|
7
|
-
* that transparently upgrade to xBind when both parties support it.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.createAxiosCompat = createAxiosCompat;
|
|
11
|
-
exports.createGotCompat = createGotCompat;
|
|
12
|
-
exports.wrapFetch = wrapFetch;
|
|
13
|
-
const xfetch_js_1 = require("./xfetch.js");
|
|
14
|
-
/**
|
|
15
|
-
* Create axios-compatible HTTP client with xBind auto-upgrade
|
|
16
|
-
*
|
|
17
|
-
* Drop-in replacement for axios that transparently upgrades to xBind.
|
|
18
|
-
*
|
|
19
|
-
* @returns Axios-compatible client
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* import { createAxiosCompat } from '@private.me/xbind/http-compat';
|
|
24
|
-
*
|
|
25
|
-
* const axios = createAxiosCompat();
|
|
26
|
-
*
|
|
27
|
-
* // Auto-upgrades to xBind if supported
|
|
28
|
-
* const response = await axios.get('https://api.example.com/data');
|
|
29
|
-
* console.log('Used xBind?', response.xbind?.used);
|
|
30
|
-
* console.log('Data:', response.data);
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
function createAxiosCompat() {
|
|
34
|
-
async function request(config) {
|
|
35
|
-
// Normalize config
|
|
36
|
-
const cfg = typeof config === 'string' ? { url: config } : config;
|
|
37
|
-
const method = cfg.method?.toUpperCase() ?? 'GET';
|
|
38
|
-
const url = cfg.baseURL
|
|
39
|
-
? new URL(cfg.url ?? '', cfg.baseURL).toString()
|
|
40
|
-
: cfg.url ?? '';
|
|
41
|
-
// Build headers
|
|
42
|
-
const headers = { ...cfg.headers };
|
|
43
|
-
// Build URL with query params
|
|
44
|
-
let finalUrl = url;
|
|
45
|
-
if (cfg.params) {
|
|
46
|
-
const params = new URLSearchParams();
|
|
47
|
-
for (const [key, value] of Object.entries(cfg.params)) {
|
|
48
|
-
params.append(key, String(value));
|
|
49
|
-
}
|
|
50
|
-
finalUrl = `${url}?${params.toString()}`;
|
|
51
|
-
}
|
|
52
|
-
// Build request body
|
|
53
|
-
let body;
|
|
54
|
-
if (cfg.data) {
|
|
55
|
-
if (typeof cfg.data === 'string') {
|
|
56
|
-
body = cfg.data;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
body = JSON.stringify(cfg.data);
|
|
60
|
-
headers['Content-Type'] = 'application/json';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Convert to xfetch options
|
|
64
|
-
const xfetchOpts = {
|
|
65
|
-
method,
|
|
66
|
-
headers,
|
|
67
|
-
body,
|
|
68
|
-
timeout: cfg.timeout,
|
|
69
|
-
forceXBind: cfg.forceXBind,
|
|
70
|
-
disableXBind: cfg.disableXBind,
|
|
71
|
-
};
|
|
72
|
-
// Make request via xfetch
|
|
73
|
-
const response = await (0, xfetch_js_1.xfetch)(finalUrl, xfetchOpts);
|
|
74
|
-
// Parse response body based on responseType
|
|
75
|
-
let data;
|
|
76
|
-
const responseType = cfg.responseType ?? 'json';
|
|
77
|
-
switch (responseType) {
|
|
78
|
-
case 'json':
|
|
79
|
-
data = (await response.json());
|
|
80
|
-
break;
|
|
81
|
-
case 'text':
|
|
82
|
-
data = (await response.text());
|
|
83
|
-
break;
|
|
84
|
-
case 'blob':
|
|
85
|
-
data = (await response.blob());
|
|
86
|
-
break;
|
|
87
|
-
case 'arraybuffer':
|
|
88
|
-
data = (await response.arrayBuffer());
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
data = (await response.json());
|
|
92
|
-
}
|
|
93
|
-
// Validate status if custom validator provided
|
|
94
|
-
if (cfg.validateStatus && !cfg.validateStatus(response.status)) {
|
|
95
|
-
throw new Error(`Request failed with status ${response.status}`);
|
|
96
|
-
}
|
|
97
|
-
// Convert headers to object
|
|
98
|
-
const responseHeaders = {};
|
|
99
|
-
response.headers.forEach((value, key) => {
|
|
100
|
-
responseHeaders[key] = value;
|
|
101
|
-
});
|
|
102
|
-
return {
|
|
103
|
-
data,
|
|
104
|
-
status: response.status,
|
|
105
|
-
statusText: response.statusText,
|
|
106
|
-
headers: responseHeaders,
|
|
107
|
-
config: cfg,
|
|
108
|
-
xbind: {
|
|
109
|
-
used: response.usedXBind,
|
|
110
|
-
protocol: response.transport.protocol,
|
|
111
|
-
latency: response.transport.latency,
|
|
112
|
-
peerDID: response.transport.peerDID,
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
// Convenience methods
|
|
117
|
-
async function get(url, config) {
|
|
118
|
-
return request({ ...config, url, method: 'GET' });
|
|
119
|
-
}
|
|
120
|
-
async function post(url, data, config) {
|
|
121
|
-
return request({ ...config, url, method: 'POST', data });
|
|
122
|
-
}
|
|
123
|
-
async function put(url, data, config) {
|
|
124
|
-
return request({ ...config, url, method: 'PUT', data });
|
|
125
|
-
}
|
|
126
|
-
async function patch(url, data, config) {
|
|
127
|
-
return request({ ...config, url, method: 'PATCH', data });
|
|
128
|
-
}
|
|
129
|
-
async function del(url, config) {
|
|
130
|
-
return request({ ...config, url, method: 'DELETE' });
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
request,
|
|
134
|
-
get,
|
|
135
|
-
post,
|
|
136
|
-
put,
|
|
137
|
-
patch,
|
|
138
|
-
delete: del,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Create got-compatible HTTP client with xBind auto-upgrade
|
|
143
|
-
*
|
|
144
|
-
* Drop-in replacement for got that transparently upgrades to xBind.
|
|
145
|
-
*
|
|
146
|
-
* @returns Got-compatible client
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* import { createGotCompat } from '@private.me/xbind/http-compat';
|
|
151
|
-
*
|
|
152
|
-
* const got = createGotCompat();
|
|
153
|
-
*
|
|
154
|
-
* // Auto-upgrades to xBind if supported
|
|
155
|
-
* const response = await got('https://api.example.com/data', {
|
|
156
|
-
* responseType: 'json',
|
|
157
|
-
* });
|
|
158
|
-
* console.log('Used xBind?', response.xbind?.used);
|
|
159
|
-
* console.log('Body:', response.body);
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
function createGotCompat() {
|
|
163
|
-
async function got(url, options) {
|
|
164
|
-
// Normalize options
|
|
165
|
-
const opts = typeof url === 'string' ? { ...options, url } : url;
|
|
166
|
-
const method = opts.method?.toUpperCase() ?? 'GET';
|
|
167
|
-
const finalUrl = opts.url ?? '';
|
|
168
|
-
// Build headers
|
|
169
|
-
const headers = { ...opts.headers };
|
|
170
|
-
// Build URL with search params
|
|
171
|
-
let urlWithParams = finalUrl;
|
|
172
|
-
if (opts.searchParams) {
|
|
173
|
-
const params = new URLSearchParams();
|
|
174
|
-
for (const [key, value] of Object.entries(opts.searchParams)) {
|
|
175
|
-
params.append(key, String(value));
|
|
176
|
-
}
|
|
177
|
-
urlWithParams = `${finalUrl}?${params.toString()}`;
|
|
178
|
-
}
|
|
179
|
-
// Build request body
|
|
180
|
-
let body;
|
|
181
|
-
if (opts.json) {
|
|
182
|
-
body = JSON.stringify(opts.json);
|
|
183
|
-
headers['Content-Type'] = 'application/json';
|
|
184
|
-
}
|
|
185
|
-
else if (opts.body) {
|
|
186
|
-
// Convert Buffer to string for compatibility with xfetch
|
|
187
|
-
// SAFETY: After instanceof check, both branches produce string type
|
|
188
|
-
body = (opts.body instanceof Buffer ? opts.body.toString() : opts.body);
|
|
189
|
-
}
|
|
190
|
-
// Extract timeout
|
|
191
|
-
const timeout = typeof opts.timeout === 'number'
|
|
192
|
-
? opts.timeout
|
|
193
|
-
: opts.timeout?.request;
|
|
194
|
-
// Convert to xfetch options
|
|
195
|
-
const xfetchOpts = {
|
|
196
|
-
method,
|
|
197
|
-
headers,
|
|
198
|
-
body,
|
|
199
|
-
timeout,
|
|
200
|
-
forceXBind: opts.forceXBind,
|
|
201
|
-
disableXBind: opts.disableXBind,
|
|
202
|
-
};
|
|
203
|
-
// Make request via xfetch
|
|
204
|
-
const response = await (0, xfetch_js_1.xfetch)(urlWithParams, xfetchOpts);
|
|
205
|
-
// Parse response body based on responseType
|
|
206
|
-
let responseBody;
|
|
207
|
-
const responseType = opts.responseType ?? 'text';
|
|
208
|
-
switch (responseType) {
|
|
209
|
-
case 'json':
|
|
210
|
-
responseBody = (await response.json());
|
|
211
|
-
break;
|
|
212
|
-
case 'text':
|
|
213
|
-
responseBody = (await response.text());
|
|
214
|
-
break;
|
|
215
|
-
case 'buffer':
|
|
216
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
217
|
-
responseBody = Buffer.from(arrayBuffer);
|
|
218
|
-
break;
|
|
219
|
-
default:
|
|
220
|
-
responseBody = (await response.text());
|
|
221
|
-
}
|
|
222
|
-
// Convert headers to object
|
|
223
|
-
const responseHeaders = {};
|
|
224
|
-
response.headers.forEach((value, key) => {
|
|
225
|
-
responseHeaders[key] = value;
|
|
226
|
-
});
|
|
227
|
-
return {
|
|
228
|
-
body: responseBody,
|
|
229
|
-
statusCode: response.status,
|
|
230
|
-
headers: responseHeaders,
|
|
231
|
-
url: response.url,
|
|
232
|
-
requestUrl: urlWithParams,
|
|
233
|
-
xbind: {
|
|
234
|
-
used: response.usedXBind,
|
|
235
|
-
protocol: response.transport.protocol,
|
|
236
|
-
latency: response.transport.latency,
|
|
237
|
-
peerDID: response.transport.peerDID,
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
// Convenience methods
|
|
242
|
-
got.get = (url, options) => got(url, { ...options, method: 'GET' });
|
|
243
|
-
got.post = (url, options) => got(url, { ...options, method: 'POST' });
|
|
244
|
-
got.put = (url, options) => got(url, { ...options, method: 'PUT' });
|
|
245
|
-
got.patch = (url, options) => got(url, { ...options, method: 'PATCH' });
|
|
246
|
-
got.delete = (url, options) => got(url, { ...options, method: 'DELETE' });
|
|
247
|
-
return got;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Wrap existing fetch implementation with xBind auto-upgrade
|
|
251
|
-
*
|
|
252
|
-
* Use this to upgrade an existing fetch instance (like node-fetch, cross-fetch, etc.)
|
|
253
|
-
*
|
|
254
|
-
* @param fetchImpl - Fetch implementation to wrap
|
|
255
|
-
* @returns Wrapped fetch with xBind support
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* ```typescript
|
|
259
|
-
* import { wrapFetch } from '@private.me/xbind/http-compat';
|
|
260
|
-
* import nodeFetch from 'node-fetch';
|
|
261
|
-
*
|
|
262
|
-
* const fetch = wrapFetch(nodeFetch);
|
|
263
|
-
*
|
|
264
|
-
* // Uses xBind if supported, falls back to node-fetch
|
|
265
|
-
* const response = await fetch('https://api.example.com/data');
|
|
266
|
-
* ```
|
|
267
|
-
*/
|
|
268
|
-
function wrapFetch(fetchImpl) {
|
|
269
|
-
// Return xfetch (which already handles auto-upgrade and fallback)
|
|
270
|
-
// The original fetchImpl is not used because xfetch uses global fetch
|
|
271
|
-
return xfetch_js_1.xfetch;
|
|
272
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createAxiosCompat=createAxiosCompat,exports.createGotCompat=createGotCompat,exports.wrapFetch=wrapFetch;const xfetch_js_1=require("./xfetch.js");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 s,n=r;if(e.params){const t=new URLSearchParams;for(const[a,r]of Object.entries(e.params))t.append(a,String(r));n=`${r}?${t.toString()}`}e.data&&("string"==typeof e.data?s=e.data:(s=JSON.stringify(e.data),o["Content-Type"]="application/json"));const c={method:a,headers:o,body:s,timeout:e.timeout,forceXBind:e.forceXBind,disableXBind:e.disableXBind},i=await(0,xfetch_js_1.xfetch)(n,c);let u;switch(e.responseType??"json"){case"json":default:u=await i.json();break;case"text":u=await i.text();break;case"blob":u=await i.blob();break;case"arraybuffer":u=await i.arrayBuffer()}if(e.validateStatus&&!e.validateStatus(i.status))throw new Error(`Request failed with status ${i.status}`);const d={};return i.headers.forEach((t,e)=>{d[e]=t}),{data:u,status:i.status,statusText:i.statusText,headers:d,config:e,xbind:{used:i.usedXBind,protocol:i.transport.protocol,latency:i.transport.latency,peerDID:i.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"})}}}function createGotCompat(){async function t(t,e){const a="string"==typeof t?{...e,url:t}:t,r=a.method?.toUpperCase()??"GET",o=a.url??"",s={...a.headers};let n,c=o;if(a.searchParams){const t=new URLSearchParams;for(const[e,r]of Object.entries(a.searchParams))t.append(e,String(r));c=`${o}?${t.toString()}`}a.json?(n=JSON.stringify(a.json),s["Content-Type"]="application/json"):a.body&&(n=a.body instanceof Buffer?a.body.toString():a.body);const i={method:r,headers:s,body:n,timeout:"number"==typeof a.timeout?a.timeout:a.timeout?.request,forceXBind:a.forceXBind,disableXBind:a.disableXBind},u=await(0,xfetch_js_1.xfetch)(c,i);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 p={};return u.headers.forEach((t,e)=>{p[e]=t}),{body:d,statusCode:u.status,headers:p,url:u.url,requestUrl:c,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}function wrapFetch(){return xfetch_js_1.xfetch}
|