@private.me/xbind 1.2.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/AGENTS.md +778 -0
- package/LICENSE.md +27 -0
- package/README.md +400 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +29 -0
- package/dist-standalone/_deps/crypto/base64.js +97 -0
- package/dist-standalone/_deps/crypto/cjs/base64.js +103 -0
- package/dist-standalone/_deps/crypto/cjs/errors.js +119 -0
- package/dist-standalone/_deps/crypto/cjs/hmac.js +71 -0
- package/dist-standalone/_deps/crypto/cjs/index.js +86 -0
- package/dist-standalone/_deps/crypto/cjs/padding.js +57 -0
- package/dist-standalone/_deps/crypto/cjs/share-header.js +68 -0
- package/dist-standalone/_deps/crypto/cjs/shares.js +152 -0
- package/dist-standalone/_deps/crypto/cjs/tlv.js +199 -0
- package/dist-standalone/_deps/crypto/cjs/uuid.js +61 -0
- package/dist-standalone/_deps/crypto/cjs/verify.js +24 -0
- package/dist-standalone/_deps/crypto/cjs/xorida.js +221 -0
- package/dist-standalone/_deps/crypto/errors.d.ts +51 -0
- package/dist-standalone/_deps/crypto/errors.js +109 -0
- package/dist-standalone/_deps/crypto/hmac.d.ts +39 -0
- package/dist-standalone/_deps/crypto/hmac.js +66 -0
- package/dist-standalone/_deps/crypto/index.d.ts +20 -0
- package/dist-standalone/_deps/crypto/index.js +45 -0
- package/dist-standalone/_deps/crypto/padding.d.ts +19 -0
- package/dist-standalone/_deps/crypto/padding.js +53 -0
- package/dist-standalone/_deps/crypto/share-header.d.ts +44 -0
- package/dist-standalone/_deps/crypto/share-header.js +63 -0
- package/dist-standalone/_deps/crypto/shares.d.ts +27 -0
- package/dist-standalone/_deps/crypto/shares.js +148 -0
- package/dist-standalone/_deps/crypto/tlv.d.ts +26 -0
- package/dist-standalone/_deps/crypto/tlv.js +195 -0
- package/dist-standalone/_deps/crypto/uuid.d.ts +22 -0
- package/dist-standalone/_deps/crypto/uuid.js +56 -0
- package/dist-standalone/_deps/crypto/verify.d.ts +15 -0
- package/dist-standalone/_deps/crypto/verify.js +15 -0
- package/dist-standalone/_deps/crypto/xorida.d.ts +44 -0
- package/dist-standalone/_deps/crypto/xorida.js +215 -0
- package/dist-standalone/_deps/mldsa-wasm/LICENSE +24 -0
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -0
- package/dist-standalone/_deps/mldsa-wasm/package.json +46 -0
- package/dist-standalone/_deps/mldsa-wasm/types/mldsa.d.ts +30 -0
- package/dist-standalone/_deps/shared/cjs/errors.js +582 -0
- package/dist-standalone/_deps/shared/cjs/index.js +492 -0
- package/dist-standalone/_deps/shared/cjs/package.json +1 -0
- package/dist-standalone/_deps/shared/cjs/types.js +403 -0
- package/dist-standalone/_deps/shared/errors.d.ts +48 -0
- package/dist-standalone/_deps/shared/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/errors.js +192 -0
- package/dist-standalone/_deps/shared/errors.js.map +1 -0
- package/dist-standalone/_deps/shared/index.d.ts +4 -0
- package/dist-standalone/_deps/shared/index.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/index.js +78 -0
- package/dist-standalone/_deps/shared/index.js.map +1 -0
- package/dist-standalone/_deps/shared/types.d.ts +1097 -0
- package/dist-standalone/_deps/shared/types.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/types.js +89 -0
- package/dist-standalone/_deps/shared/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/package.json +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +83 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +143 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +119 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +8 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.js +253 -0
- package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.js +16 -0
- package/dist-standalone/_deps/ux-helpers/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js +79 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.js +138 -0
- package/dist-standalone/_deps/ux-helpers/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.js +116 -0
- package/dist-standalone/_deps/ux-helpers/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.js +7 -0
- package/dist-standalone/_deps/ux-helpers/types.js.map +1 -0
- package/dist-standalone/_deps/xchange/auto-accept.d.ts +127 -0
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/package.json +1 -0
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -0
- package/dist-standalone/_deps/xchange/errors.d.ts +69 -0
- package/dist-standalone/_deps/xchange/errors.js +1 -0
- package/dist-standalone/_deps/xchange/index.d.ts +15 -0
- package/dist-standalone/_deps/xchange/index.js +1 -0
- package/dist-standalone/_deps/xchange/invite-client.d.ts +178 -0
- package/dist-standalone/_deps/xchange/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/lazy-init.d.ts +176 -0
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/trust-integration.d.ts +102 -0
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/xchange.d.ts +60 -0
- package/dist-standalone/_deps/xchange/xchange.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/package.json +1 -0
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts +126 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts +41 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/errors.js.map +1 -0
- package/dist-standalone/_deps/xregistry/index.d.ts +8 -0
- package/dist-standalone/_deps/xregistry/index.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/index.js +1 -0
- package/dist-standalone/_deps/xregistry/index.js.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts +85 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/registry.js.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts +81 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/schema.js.map +1 -0
- package/dist-standalone/_deps/xregistry/types.d.ts +95 -0
- package/dist-standalone/_deps/xregistry/types.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/types.js +1 -0
- package/dist-standalone/_deps/xregistry/types.js.map +1 -0
- package/dist-standalone/agent-call.d.ts +286 -0
- package/dist-standalone/agent-call.js +642 -0
- package/dist-standalone/agent-sdk.d.ts +207 -0
- package/dist-standalone/agent-sdk.js +328 -0
- package/dist-standalone/agent.d.ts +670 -0
- package/dist-standalone/agent.js +1529 -0
- package/dist-standalone/approval.d.ts +145 -0
- package/dist-standalone/approval.js +193 -0
- package/dist-standalone/auth.d.ts +75 -0
- package/dist-standalone/auth.js +219 -0
- package/dist-standalone/auto-accept.d.ts +102 -0
- package/dist-standalone/auto-accept.js +229 -0
- package/dist-standalone/backup-config.d.ts +150 -0
- package/dist-standalone/backup-config.js +201 -0
- package/dist-standalone/checkpoint.d.ts +125 -0
- package/dist-standalone/checkpoint.js +186 -0
- package/dist-standalone/cjs/agent-call.js +651 -0
- package/dist-standalone/cjs/agent-sdk.js +332 -0
- package/dist-standalone/cjs/agent.js +1566 -0
- package/dist-standalone/cjs/approval.js +199 -0
- package/dist-standalone/cjs/auth.js +225 -0
- package/dist-standalone/cjs/auto-accept.js +233 -0
- package/dist-standalone/cjs/backup-config.js +207 -0
- package/dist-standalone/cjs/checkpoint.js +193 -0
- package/dist-standalone/cjs/cli/init.js +487 -0
- package/dist-standalone/cjs/connect.js +312 -0
- package/dist-standalone/cjs/did-document.js +101 -0
- package/dist-standalone/cjs/did-privateme.js +130 -0
- package/dist-standalone/cjs/did-web.js +201 -0
- package/dist-standalone/cjs/discovery.js +462 -0
- package/dist-standalone/cjs/dual-mode.js +251 -0
- package/dist-standalone/cjs/email-templates.js +313 -0
- package/dist-standalone/cjs/email-transport.js +239 -0
- package/dist-standalone/cjs/envelope.js +510 -0
- package/dist-standalone/cjs/errors.js +562 -0
- package/dist-standalone/cjs/gateway-state.js +55 -0
- package/dist-standalone/cjs/gateway-transport.js +120 -0
- package/dist-standalone/cjs/guardrails.js +223 -0
- package/dist-standalone/cjs/http-compat.js +272 -0
- package/dist-standalone/cjs/identity.js +541 -0
- package/dist-standalone/cjs/index.js +224 -0
- package/dist-standalone/cjs/invitation.js +421 -0
- package/dist-standalone/cjs/invite.js +328 -0
- package/dist-standalone/cjs/key-agreement.js +246 -0
- package/dist-standalone/cjs/lazy-init.js +300 -0
- package/dist-standalone/cjs/mdns-discovery.js +202 -0
- package/dist-standalone/cjs/nonce-store.js +66 -0
- package/dist-standalone/cjs/package.json +3 -0
- package/dist-standalone/cjs/pairing-manager.js +223 -0
- package/dist-standalone/cjs/policy.js +320 -0
- package/dist-standalone/cjs/redis-nonce-store.js +76 -0
- package/dist-standalone/cjs/registry-middleware.js +50 -0
- package/dist-standalone/cjs/retry-transport.js +102 -0
- package/dist-standalone/cjs/security-policy.js +204 -0
- package/dist-standalone/cjs/split-channel.js +177 -0
- package/dist-standalone/cjs/subscription-proof.js +230 -0
- package/dist-standalone/cjs/succession.js +148 -0
- package/dist-standalone/cjs/transport.js +63 -0
- package/dist-standalone/cjs/trust-registry.js +742 -0
- package/dist-standalone/cjs/verify.js +25 -0
- package/dist-standalone/cjs/xfetch.js +252 -0
- package/dist-standalone/cli/init.d.ts +63 -0
- package/dist-standalone/cli/init.js +450 -0
- package/dist-standalone/connect.d.ts +143 -0
- package/dist-standalone/connect.js +274 -0
- package/dist-standalone/did-document.d.ts +65 -0
- package/dist-standalone/did-document.js +96 -0
- package/dist-standalone/did-privateme.d.ts +70 -0
- package/dist-standalone/did-privateme.js +121 -0
- package/dist-standalone/did-web.d.ts +73 -0
- package/dist-standalone/did-web.js +196 -0
- package/dist-standalone/discovery.d.ts +176 -0
- package/dist-standalone/discovery.js +458 -0
- package/dist-standalone/dual-mode.d.ts +145 -0
- package/dist-standalone/dual-mode.js +247 -0
- package/dist-standalone/email-templates.d.ts +41 -0
- package/dist-standalone/email-templates.js +309 -0
- package/dist-standalone/email-transport.d.ts +139 -0
- package/dist-standalone/email-transport.js +232 -0
- package/dist-standalone/envelope.d.ts +288 -0
- package/dist-standalone/envelope.js +497 -0
- package/dist-standalone/errors.d.ts +74 -0
- package/dist-standalone/errors.js +548 -0
- package/dist-standalone/gateway-state.d.ts +32 -0
- package/dist-standalone/gateway-state.js +51 -0
- package/dist-standalone/gateway-transport.d.ts +59 -0
- package/dist-standalone/gateway-transport.js +116 -0
- package/dist-standalone/guardrails.d.ts +136 -0
- package/dist-standalone/guardrails.js +216 -0
- package/dist-standalone/http-compat.d.ts +150 -0
- package/dist-standalone/http-compat.js +267 -0
- package/dist-standalone/identity.d.ts +176 -0
- package/dist-standalone/identity.js +516 -0
- package/dist-standalone/index.d.ts +83 -0
- package/dist-standalone/index.js +51 -0
- package/dist-standalone/invitation.d.ts +211 -0
- package/dist-standalone/invitation.js +415 -0
- package/dist-standalone/invite.d.ts +192 -0
- package/dist-standalone/invite.js +324 -0
- package/dist-standalone/key-agreement.d.ts +122 -0
- package/dist-standalone/key-agreement.js +236 -0
- package/dist-standalone/lazy-init.d.ts +167 -0
- package/dist-standalone/lazy-init.js +295 -0
- package/dist-standalone/mdns-discovery.d.ts +117 -0
- package/dist-standalone/mdns-discovery.js +195 -0
- package/dist-standalone/nonce-store.d.ts +39 -0
- package/dist-standalone/nonce-store.js +62 -0
- package/dist-standalone/package.json +11 -0
- package/dist-standalone/pairing-manager.d.ts +147 -0
- package/dist-standalone/pairing-manager.js +219 -0
- package/dist-standalone/policy.d.ts +150 -0
- package/dist-standalone/policy.js +315 -0
- package/dist-standalone/redis-nonce-store.d.ts +93 -0
- package/dist-standalone/redis-nonce-store.js +72 -0
- package/dist-standalone/registry-middleware.d.ts +38 -0
- package/dist-standalone/registry-middleware.js +47 -0
- package/dist-standalone/retry-transport.d.ts +76 -0
- package/dist-standalone/retry-transport.js +98 -0
- package/dist-standalone/security-policy.d.ts +146 -0
- package/dist-standalone/security-policy.js +198 -0
- package/dist-standalone/split-channel.d.ts +69 -0
- package/dist-standalone/split-channel.js +171 -0
- package/dist-standalone/subscription-proof.d.ts +103 -0
- package/dist-standalone/subscription-proof.js +224 -0
- package/dist-standalone/succession.d.ts +57 -0
- package/dist-standalone/succession.js +142 -0
- package/dist-standalone/transport.d.ts +50 -0
- package/dist-standalone/transport.js +59 -0
- package/dist-standalone/trust-registry.d.ts +286 -0
- package/dist-standalone/trust-registry.js +702 -0
- package/dist-standalone/verify.d.ts +16 -0
- package/dist-standalone/verify.js +16 -0
- package/dist-standalone/xfetch.d.ts +129 -0
- package/dist-standalone/xfetch.js +247 -0
- package/llms.txt +800 -0
- package/package.json +79 -0
- package/share1.dat +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway transport adapter for delivering envelopes to Xail inbox users.
|
|
3
|
+
*
|
|
4
|
+
* Sends envelopes via POST /gateway/deliver on the hosted gateway API.
|
|
5
|
+
* For agent-to-agent (M2M), use HttpsTransportAdapter with direct URLs.
|
|
6
|
+
* Optionally polls for incoming messages.
|
|
7
|
+
*/
|
|
8
|
+
import type { Result } from '@private.me/shared';
|
|
9
|
+
import type { TransportEnvelope } from './envelope.js';
|
|
10
|
+
import type { XailTransportAdapter, TransportError, EnvelopeHandler } from './transport.js';
|
|
11
|
+
/** Options for GatewayTransport. */
|
|
12
|
+
export interface GatewayTransportOptions {
|
|
13
|
+
/** API key for gateway authentication. */
|
|
14
|
+
readonly apiKey: string;
|
|
15
|
+
/** Gateway base URL. Required — no default to prevent accidental sends. */
|
|
16
|
+
readonly gateway: string;
|
|
17
|
+
/** Request timeout in ms. Default: 15000. */
|
|
18
|
+
readonly timeoutMs?: number;
|
|
19
|
+
/** Custom fetch implementation (for testing). */
|
|
20
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
21
|
+
/** Polling interval for incoming messages in ms. Default: 0 (disabled). */
|
|
22
|
+
readonly pollIntervalMs?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Transport adapter for the Xail Gateway.
|
|
26
|
+
*
|
|
27
|
+
* Sends envelopes via POST /gateway/deliver with API key auth.
|
|
28
|
+
* Optionally polls GET /gateway/messages/:did for incoming messages.
|
|
29
|
+
*/
|
|
30
|
+
export declare class GatewayTransport implements XailTransportAdapter {
|
|
31
|
+
private readonly apiKey;
|
|
32
|
+
private readonly gateway;
|
|
33
|
+
private readonly timeoutMs;
|
|
34
|
+
private readonly fetchFn;
|
|
35
|
+
private readonly pollIntervalMs;
|
|
36
|
+
private handlers;
|
|
37
|
+
private pollTimer;
|
|
38
|
+
private senderDid;
|
|
39
|
+
constructor(opts: GatewayTransportOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Send a signed envelope to a recipient via the gateway.
|
|
42
|
+
* @param envelope - The signed transport envelope.
|
|
43
|
+
* @param _recipientDid - Recipient DID (already in envelope.recipient).
|
|
44
|
+
* @returns Success or transport error.
|
|
45
|
+
*/
|
|
46
|
+
send(envelope: TransportEnvelope, _recipientDid: string): Promise<Result<void, TransportError>>;
|
|
47
|
+
/** Register a handler for incoming envelopes. */
|
|
48
|
+
onReceive(handler: EnvelopeHandler): void;
|
|
49
|
+
/**
|
|
50
|
+
* Start polling for incoming messages.
|
|
51
|
+
* Must be called after Agent.create() sets the sender DID.
|
|
52
|
+
* @param did - The agent's own DID for polling.
|
|
53
|
+
*/
|
|
54
|
+
startPolling(did: string): void;
|
|
55
|
+
/** Shut down the transport (stop polling, clear handlers). */
|
|
56
|
+
dispose(): void;
|
|
57
|
+
/** Poll for incoming messages and dispatch to handlers. */
|
|
58
|
+
private poll;
|
|
59
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway transport adapter for delivering envelopes to Xail inbox users.
|
|
3
|
+
*
|
|
4
|
+
* Sends envelopes via POST /gateway/deliver on the hosted gateway API.
|
|
5
|
+
* For agent-to-agent (M2M), use HttpsTransportAdapter with direct URLs.
|
|
6
|
+
* Optionally polls for incoming messages.
|
|
7
|
+
*/
|
|
8
|
+
import { ok, err } from"./_deps/shared/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Transport adapter for the Xail Gateway.
|
|
11
|
+
*
|
|
12
|
+
* Sends envelopes via POST /gateway/deliver with API key auth.
|
|
13
|
+
* Optionally polls GET /gateway/messages/:did for incoming messages.
|
|
14
|
+
*/
|
|
15
|
+
export class GatewayTransport {
|
|
16
|
+
apiKey;
|
|
17
|
+
gateway;
|
|
18
|
+
timeoutMs;
|
|
19
|
+
fetchFn;
|
|
20
|
+
pollIntervalMs;
|
|
21
|
+
handlers = [];
|
|
22
|
+
pollTimer = null;
|
|
23
|
+
senderDid = null;
|
|
24
|
+
constructor(opts) {
|
|
25
|
+
this.apiKey = opts.apiKey;
|
|
26
|
+
this.gateway = opts.gateway.replace(/\/$/, '');
|
|
27
|
+
this.timeoutMs = opts.timeoutMs ?? 15_000;
|
|
28
|
+
this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
29
|
+
this.pollIntervalMs = opts.pollIntervalMs ?? 0;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Send a signed envelope to a recipient via the gateway.
|
|
33
|
+
* @param envelope - The signed transport envelope.
|
|
34
|
+
* @param _recipientDid - Recipient DID (already in envelope.recipient).
|
|
35
|
+
* @returns Success or transport error.
|
|
36
|
+
*/
|
|
37
|
+
async send(envelope, _recipientDid) {
|
|
38
|
+
const url = `${this.gateway}/gateway/deliver`;
|
|
39
|
+
try {
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
42
|
+
const response = await this.fetchFn(url, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify(envelope),
|
|
49
|
+
signal: controller.signal,
|
|
50
|
+
});
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
return err(response.status === 404
|
|
54
|
+
? 'RECIPIENT_UNREACHABLE'
|
|
55
|
+
: 'SEND_FAILED');
|
|
56
|
+
}
|
|
57
|
+
return ok(undefined);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
if (e instanceof DOMException && e.name === 'AbortError') {
|
|
61
|
+
return err('TIMEOUT');
|
|
62
|
+
}
|
|
63
|
+
return err('NETWORK_ERROR');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Register a handler for incoming envelopes. */
|
|
67
|
+
onReceive(handler) {
|
|
68
|
+
this.handlers.push(handler);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Start polling for incoming messages.
|
|
72
|
+
* Must be called after Agent.create() sets the sender DID.
|
|
73
|
+
* @param did - The agent's own DID for polling.
|
|
74
|
+
*/
|
|
75
|
+
startPolling(did) {
|
|
76
|
+
this.senderDid = did;
|
|
77
|
+
if (this.pollIntervalMs > 0 && !this.pollTimer) {
|
|
78
|
+
this.pollTimer = setInterval(() => void this.poll(), this.pollIntervalMs);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Shut down the transport (stop polling, clear handlers). */
|
|
82
|
+
dispose() {
|
|
83
|
+
if (this.pollTimer) {
|
|
84
|
+
clearInterval(this.pollTimer);
|
|
85
|
+
this.pollTimer = null;
|
|
86
|
+
}
|
|
87
|
+
this.handlers = [];
|
|
88
|
+
}
|
|
89
|
+
/** Poll for incoming messages and dispatch to handlers. */
|
|
90
|
+
async poll() {
|
|
91
|
+
if (!this.senderDid)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
const url = `${this.gateway}/gateway/messages/${encodeURIComponent(this.senderDid)}`;
|
|
95
|
+
const res = await this.fetchFn(url, {
|
|
96
|
+
headers: { Authorization: `Bearer ${this.apiKey}` },
|
|
97
|
+
});
|
|
98
|
+
if (!res.ok)
|
|
99
|
+
return;
|
|
100
|
+
const data = (await res.json());
|
|
101
|
+
for (const msg of data.messages) {
|
|
102
|
+
for (const handler of this.handlers) {
|
|
103
|
+
handler(msg.envelope);
|
|
104
|
+
}
|
|
105
|
+
// Ack delivery
|
|
106
|
+
await this.fetchFn(`${this.gateway}/gateway/ack/${msg.id}`, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: { Authorization: `Bearer ${this.apiKey}` },
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Silent failure — polling errors are non-fatal
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module guardrails
|
|
3
|
+
* Enhanced error messages with actionable suggestions for policy violations
|
|
4
|
+
*
|
|
5
|
+
* When policies deny requests, guardrails provide specific, actionable
|
|
6
|
+
* guidance on how to fix the issue or what to request from admins.
|
|
7
|
+
*/
|
|
8
|
+
import type { PolicyViolationDetails } from './policy.js';
|
|
9
|
+
/**
|
|
10
|
+
* Policy violation error with actionable suggestions
|
|
11
|
+
*/
|
|
12
|
+
export declare class PolicyDenied extends Error {
|
|
13
|
+
/** Which policy rule was violated */
|
|
14
|
+
readonly rule: string;
|
|
15
|
+
/** What the policy allows */
|
|
16
|
+
readonly allowed: unknown;
|
|
17
|
+
/** What was requested */
|
|
18
|
+
readonly requested: unknown;
|
|
19
|
+
/** Actionable suggestion for how to fix */
|
|
20
|
+
readonly suggestion: string;
|
|
21
|
+
/** Full policy violation details */
|
|
22
|
+
readonly details?: PolicyViolationDetails | undefined;
|
|
23
|
+
constructor(
|
|
24
|
+
/** Which policy rule was violated */
|
|
25
|
+
rule: string,
|
|
26
|
+
/** What the policy allows */
|
|
27
|
+
allowed: unknown,
|
|
28
|
+
/** What was requested */
|
|
29
|
+
requested: unknown,
|
|
30
|
+
/** Actionable suggestion for how to fix */
|
|
31
|
+
suggestion: string,
|
|
32
|
+
/** Full policy violation details */
|
|
33
|
+
details?: PolicyViolationDetails | undefined);
|
|
34
|
+
/**
|
|
35
|
+
* Format error for AI agent consumption
|
|
36
|
+
*
|
|
37
|
+
* Structured format optimized for LLM parsing
|
|
38
|
+
*/
|
|
39
|
+
toAgentFormat(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Format error for human consumption
|
|
42
|
+
*
|
|
43
|
+
* User-friendly format with clear next steps
|
|
44
|
+
*/
|
|
45
|
+
toUserFormat(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Format error for logs (structured JSON)
|
|
48
|
+
*/
|
|
49
|
+
toLogFormat(): Record<string, unknown>;
|
|
50
|
+
private formatValue;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Guardrail builder - fluent API for creating policy errors with suggestions
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const error = Guardrails.amountExceeded({
|
|
58
|
+
* requested: 5000,
|
|
59
|
+
* limit: 1000,
|
|
60
|
+
* type: 'per-transaction'
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* throw error;
|
|
64
|
+
* // ❌ Policy Violation: maxAmount
|
|
65
|
+
* // You requested: $5,000
|
|
66
|
+
* // Policy allows: $1,000
|
|
67
|
+
* // 💡 Suggestion: Reduce amount to $1,000 or request policy update from admin
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare class Guardrails {
|
|
71
|
+
/**
|
|
72
|
+
* Amount exceeded (per-transaction limit)
|
|
73
|
+
*/
|
|
74
|
+
static amountExceeded(options: {
|
|
75
|
+
requested: number;
|
|
76
|
+
limit: number;
|
|
77
|
+
type: 'per-transaction' | 'daily' | 'monthly';
|
|
78
|
+
}): PolicyDenied;
|
|
79
|
+
/**
|
|
80
|
+
* Rate limit exceeded
|
|
81
|
+
*/
|
|
82
|
+
static rateLimitExceeded(options: {
|
|
83
|
+
current: number;
|
|
84
|
+
limit: number;
|
|
85
|
+
windowMs: number;
|
|
86
|
+
}): PolicyDenied;
|
|
87
|
+
/**
|
|
88
|
+
* Tool not allowed
|
|
89
|
+
*/
|
|
90
|
+
static toolDenied(options: {
|
|
91
|
+
tool: string;
|
|
92
|
+
allowed: string[];
|
|
93
|
+
}): PolicyDenied;
|
|
94
|
+
/**
|
|
95
|
+
* Scope not allowed
|
|
96
|
+
*/
|
|
97
|
+
static scopeDenied(options: {
|
|
98
|
+
scope: string;
|
|
99
|
+
allowed: string[];
|
|
100
|
+
}): PolicyDenied;
|
|
101
|
+
/**
|
|
102
|
+
* Field filter denied (data access restriction)
|
|
103
|
+
*/
|
|
104
|
+
static fieldDenied(options: {
|
|
105
|
+
field: string;
|
|
106
|
+
allowed: string[];
|
|
107
|
+
tool: string;
|
|
108
|
+
}): PolicyDenied;
|
|
109
|
+
/**
|
|
110
|
+
* Time window restriction
|
|
111
|
+
*/
|
|
112
|
+
static timeWindowDenied(options: {
|
|
113
|
+
current: Date;
|
|
114
|
+
allowedStart: string;
|
|
115
|
+
allowedEnd: string;
|
|
116
|
+
}): PolicyDenied;
|
|
117
|
+
/**
|
|
118
|
+
* Generic policy violation
|
|
119
|
+
*/
|
|
120
|
+
static custom(options: {
|
|
121
|
+
rule: string;
|
|
122
|
+
allowed: unknown;
|
|
123
|
+
requested: unknown;
|
|
124
|
+
suggestion: string;
|
|
125
|
+
}): PolicyDenied;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Helper: Extract actionable suggestion from AgentError details
|
|
129
|
+
*
|
|
130
|
+
* Used by agent.call() to convert PolicyViolationDetails into PolicyDenied
|
|
131
|
+
*/
|
|
132
|
+
export declare function extractSuggestion(details: PolicyViolationDetails): string;
|
|
133
|
+
/**
|
|
134
|
+
* Helper: Convert PolicyViolationDetails to PolicyDenied
|
|
135
|
+
*/
|
|
136
|
+
export declare function toPolicyDenied(details: PolicyViolationDetails): PolicyDenied;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module guardrails
|
|
3
|
+
* Enhanced error messages with actionable suggestions for policy violations
|
|
4
|
+
*
|
|
5
|
+
* When policies deny requests, guardrails provide specific, actionable
|
|
6
|
+
* guidance on how to fix the issue or what to request from admins.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Policy violation error with actionable suggestions
|
|
10
|
+
*/
|
|
11
|
+
export class PolicyDenied extends Error {
|
|
12
|
+
rule;
|
|
13
|
+
allowed;
|
|
14
|
+
requested;
|
|
15
|
+
suggestion;
|
|
16
|
+
details;
|
|
17
|
+
constructor(
|
|
18
|
+
/** Which policy rule was violated */
|
|
19
|
+
rule,
|
|
20
|
+
/** What the policy allows */
|
|
21
|
+
allowed,
|
|
22
|
+
/** What was requested */
|
|
23
|
+
requested,
|
|
24
|
+
/** Actionable suggestion for how to fix */
|
|
25
|
+
suggestion,
|
|
26
|
+
/** Full policy violation details */
|
|
27
|
+
details) {
|
|
28
|
+
super(`Policy violation: ${rule}`);
|
|
29
|
+
this.rule = rule;
|
|
30
|
+
this.allowed = allowed;
|
|
31
|
+
this.requested = requested;
|
|
32
|
+
this.suggestion = suggestion;
|
|
33
|
+
this.details = details;
|
|
34
|
+
this.name = 'PolicyDenied';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Format error for AI agent consumption
|
|
38
|
+
*
|
|
39
|
+
* Structured format optimized for LLM parsing
|
|
40
|
+
*/
|
|
41
|
+
toAgentFormat() {
|
|
42
|
+
return [
|
|
43
|
+
`POLICY_VIOLATION: ${this.rule}`,
|
|
44
|
+
`REQUESTED: ${JSON.stringify(this.requested)}`,
|
|
45
|
+
`ALLOWED: ${JSON.stringify(this.allowed)}`,
|
|
46
|
+
`SUGGESTION: ${this.suggestion}`,
|
|
47
|
+
].join('\n');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Format error for human consumption
|
|
51
|
+
*
|
|
52
|
+
* User-friendly format with clear next steps
|
|
53
|
+
*/
|
|
54
|
+
toUserFormat() {
|
|
55
|
+
return [
|
|
56
|
+
`❌ Policy Violation: ${this.rule}`,
|
|
57
|
+
'',
|
|
58
|
+
`You requested: ${this.formatValue(this.requested)}`,
|
|
59
|
+
`Policy allows: ${this.formatValue(this.allowed)}`,
|
|
60
|
+
'',
|
|
61
|
+
`💡 Suggestion: ${this.suggestion}`,
|
|
62
|
+
].join('\n');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Format error for logs (structured JSON)
|
|
66
|
+
*/
|
|
67
|
+
toLogFormat() {
|
|
68
|
+
return {
|
|
69
|
+
error: 'PolicyDenied',
|
|
70
|
+
rule: this.rule,
|
|
71
|
+
allowed: this.allowed,
|
|
72
|
+
requested: this.requested,
|
|
73
|
+
suggestion: this.suggestion,
|
|
74
|
+
details: this.details,
|
|
75
|
+
timestamp: new Date().toISOString(),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
formatValue(value) {
|
|
79
|
+
if (typeof value === 'number') {
|
|
80
|
+
// Format currency if it looks like money
|
|
81
|
+
if (this.rule.includes('amount') || this.rule.includes('Amount')) {
|
|
82
|
+
return `$${value.toLocaleString()}`;
|
|
83
|
+
}
|
|
84
|
+
return value.toLocaleString();
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
return value.map((v) => `"${String(v)}"`).join(', ');
|
|
88
|
+
}
|
|
89
|
+
return JSON.stringify(value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Guardrail builder - fluent API for creating policy errors with suggestions
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const error = Guardrails.amountExceeded({
|
|
98
|
+
* requested: 5000,
|
|
99
|
+
* limit: 1000,
|
|
100
|
+
* type: 'per-transaction'
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* throw error;
|
|
104
|
+
* // ❌ Policy Violation: maxAmount
|
|
105
|
+
* // You requested: $5,000
|
|
106
|
+
* // Policy allows: $1,000
|
|
107
|
+
* // 💡 Suggestion: Reduce amount to $1,000 or request policy update from admin
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export class Guardrails {
|
|
111
|
+
/**
|
|
112
|
+
* Amount exceeded (per-transaction limit)
|
|
113
|
+
*/
|
|
114
|
+
static amountExceeded(options) {
|
|
115
|
+
let rule;
|
|
116
|
+
let suggestion;
|
|
117
|
+
switch (options.type) {
|
|
118
|
+
case 'per-transaction':
|
|
119
|
+
rule = 'maxAmount';
|
|
120
|
+
suggestion = `Reduce amount to $${options.limit.toLocaleString()} or request policy update from admin`;
|
|
121
|
+
break;
|
|
122
|
+
case 'daily':
|
|
123
|
+
rule = 'dailyAmount';
|
|
124
|
+
suggestion = `Reduce amount to stay within daily limit of $${options.limit.toLocaleString()}, or wait until tomorrow`;
|
|
125
|
+
break;
|
|
126
|
+
case 'monthly':
|
|
127
|
+
rule = 'monthlyAmount';
|
|
128
|
+
suggestion = `Reduce amount to stay within monthly limit of $${options.limit.toLocaleString()}, or wait until next month`;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return new PolicyDenied(rule, options.limit, options.requested, suggestion);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Rate limit exceeded
|
|
135
|
+
*/
|
|
136
|
+
static rateLimitExceeded(options) {
|
|
137
|
+
const windowSec = options.windowMs / 1000;
|
|
138
|
+
const suggestion = windowSec >= 60
|
|
139
|
+
? `Wait ${Math.ceil(windowSec / 60)} minutes before making additional calls`
|
|
140
|
+
: `Wait ${windowSec} seconds before making additional calls`;
|
|
141
|
+
return new PolicyDenied('callsPerMinute', options.limit, options.current + 1, suggestion);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Tool not allowed
|
|
145
|
+
*/
|
|
146
|
+
static toolDenied(options) {
|
|
147
|
+
const [service] = options.tool.split(':');
|
|
148
|
+
const suggestion = options.allowed.length === 0
|
|
149
|
+
? `No tools are currently allowed. Request approval from admin to enable "${options.tool}"`
|
|
150
|
+
: `Request approval from admin to add "${options.tool}" or "${service}:*" to allowed tools`;
|
|
151
|
+
return new PolicyDenied('allowedTools', options.allowed, options.tool, suggestion);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Scope not allowed
|
|
155
|
+
*/
|
|
156
|
+
static scopeDenied(options) {
|
|
157
|
+
const suggestion = options.allowed.length === 0
|
|
158
|
+
? `No scopes are currently allowed. Request approval from admin to enable "${options.scope}"`
|
|
159
|
+
: `Request approval from admin to add "${options.scope}" to allowed scopes`;
|
|
160
|
+
return new PolicyDenied('allowedScopes', options.allowed, options.scope, suggestion);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Field filter denied (data access restriction)
|
|
164
|
+
*/
|
|
165
|
+
static fieldDenied(options) {
|
|
166
|
+
const suggestion = `Field "${options.field}" is restricted. Contact admin to update policy.fieldFilters for "${options.tool}"`;
|
|
167
|
+
return new PolicyDenied('fieldFilters', options.allowed, options.field, suggestion);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Time window restriction
|
|
171
|
+
*/
|
|
172
|
+
static timeWindowDenied(options) {
|
|
173
|
+
const suggestion = `Actions are only allowed between ${options.allowedStart} and ${options.allowedEnd}. Current time is ${options.current.toTimeString()}`;
|
|
174
|
+
return new PolicyDenied('timeWindow', `${options.allowedStart} - ${options.allowedEnd}`, options.current.toTimeString(), suggestion);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Generic policy violation
|
|
178
|
+
*/
|
|
179
|
+
static custom(options) {
|
|
180
|
+
return new PolicyDenied(options.rule, options.allowed, options.requested, options.suggestion);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Helper: Extract actionable suggestion from AgentError details
|
|
185
|
+
*
|
|
186
|
+
* Used by agent.call() to convert PolicyViolationDetails into PolicyDenied
|
|
187
|
+
*/
|
|
188
|
+
export function extractSuggestion(details) {
|
|
189
|
+
return details.fix ?? 'Contact administrator to update policy';
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Helper: Convert PolicyViolationDetails to PolicyDenied
|
|
193
|
+
*/
|
|
194
|
+
export function toPolicyDenied(details) {
|
|
195
|
+
let rule;
|
|
196
|
+
switch (details.constraint) {
|
|
197
|
+
case 'amountPerTxn':
|
|
198
|
+
rule = 'maxAmount';
|
|
199
|
+
break;
|
|
200
|
+
case 'dailyAmount':
|
|
201
|
+
rule = 'dailyAmount';
|
|
202
|
+
break;
|
|
203
|
+
case 'callsPerMinute':
|
|
204
|
+
rule = 'callsPerMinute';
|
|
205
|
+
break;
|
|
206
|
+
case 'scope':
|
|
207
|
+
rule = 'allowedScopes';
|
|
208
|
+
break;
|
|
209
|
+
case 'tool':
|
|
210
|
+
rule = 'allowedTools';
|
|
211
|
+
break;
|
|
212
|
+
default:
|
|
213
|
+
rule = String(details.constraint);
|
|
214
|
+
}
|
|
215
|
+
return new PolicyDenied(rule, details.allowed, details.requested, details.fix, details);
|
|
216
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
* Axios-compatible request config
|
|
11
|
+
*/
|
|
12
|
+
export interface AxiosRequestConfig {
|
|
13
|
+
url?: string;
|
|
14
|
+
method?: string;
|
|
15
|
+
baseURL?: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
params?: Record<string, unknown>;
|
|
18
|
+
data?: unknown;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
responseType?: 'json' | 'text' | 'blob' | 'arraybuffer';
|
|
21
|
+
validateStatus?: (status: number) => boolean;
|
|
22
|
+
forceXBind?: boolean;
|
|
23
|
+
disableXBind?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Axios-compatible response
|
|
27
|
+
*/
|
|
28
|
+
export interface AxiosResponse<T = unknown> {
|
|
29
|
+
data: T;
|
|
30
|
+
status: number;
|
|
31
|
+
statusText: string;
|
|
32
|
+
headers: Record<string, string>;
|
|
33
|
+
config: AxiosRequestConfig;
|
|
34
|
+
request?: unknown;
|
|
35
|
+
xbind?: {
|
|
36
|
+
used: boolean;
|
|
37
|
+
protocol: 'xbind' | 'http' | 'https';
|
|
38
|
+
latency?: number;
|
|
39
|
+
peerDID?: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Got-compatible options
|
|
44
|
+
*/
|
|
45
|
+
export interface GotOptions {
|
|
46
|
+
url?: string;
|
|
47
|
+
method?: string;
|
|
48
|
+
headers?: Record<string, string>;
|
|
49
|
+
searchParams?: Record<string, string | number | boolean>;
|
|
50
|
+
json?: unknown;
|
|
51
|
+
body?: string | Buffer;
|
|
52
|
+
timeout?: number | {
|
|
53
|
+
request?: number;
|
|
54
|
+
};
|
|
55
|
+
responseType?: 'json' | 'text' | 'buffer';
|
|
56
|
+
forceXBind?: boolean;
|
|
57
|
+
disableXBind?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Got-compatible response
|
|
61
|
+
*/
|
|
62
|
+
export interface GotResponse<T = unknown> {
|
|
63
|
+
body: T;
|
|
64
|
+
statusCode: number;
|
|
65
|
+
headers: Record<string, string>;
|
|
66
|
+
url: string;
|
|
67
|
+
requestUrl: string;
|
|
68
|
+
xbind?: {
|
|
69
|
+
used: boolean;
|
|
70
|
+
protocol: 'xbind' | 'http' | 'https';
|
|
71
|
+
latency?: number;
|
|
72
|
+
peerDID?: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create axios-compatible HTTP client with xBind auto-upgrade
|
|
77
|
+
*
|
|
78
|
+
* Drop-in replacement for axios that transparently upgrades to xBind.
|
|
79
|
+
*
|
|
80
|
+
* @returns Axios-compatible client
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { createAxiosCompat } from '@private.me/xbind/http-compat';
|
|
85
|
+
*
|
|
86
|
+
* const axios = createAxiosCompat();
|
|
87
|
+
*
|
|
88
|
+
* // Auto-upgrades to xBind if supported
|
|
89
|
+
* const response = await axios.get('https://api.example.com/data');
|
|
90
|
+
* console.log('Used xBind?', response.xbind?.used);
|
|
91
|
+
* console.log('Data:', response.data);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function createAxiosCompat(): {
|
|
95
|
+
request: <T = unknown>(config: AxiosRequestConfig | string) => Promise<AxiosResponse<T>>;
|
|
96
|
+
get: <T = unknown>(url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
|
|
97
|
+
post: <T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
|
|
98
|
+
put: <T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
|
|
99
|
+
patch: <T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
|
|
100
|
+
delete: <T = unknown>(url: string, config?: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Create got-compatible HTTP client with xBind auto-upgrade
|
|
104
|
+
*
|
|
105
|
+
* Drop-in replacement for got that transparently upgrades to xBind.
|
|
106
|
+
*
|
|
107
|
+
* @returns Got-compatible client
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { createGotCompat } from '@private.me/xbind/http-compat';
|
|
112
|
+
*
|
|
113
|
+
* const got = createGotCompat();
|
|
114
|
+
*
|
|
115
|
+
* // Auto-upgrades to xBind if supported
|
|
116
|
+
* const response = await got('https://api.example.com/data', {
|
|
117
|
+
* responseType: 'json',
|
|
118
|
+
* });
|
|
119
|
+
* console.log('Used xBind?', response.xbind?.used);
|
|
120
|
+
* console.log('Body:', response.body);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function createGotCompat(): {
|
|
124
|
+
<T = unknown>(url: string | GotOptions, options?: GotOptions): Promise<GotResponse<T>>;
|
|
125
|
+
get<T = unknown>(url: string, options?: GotOptions): Promise<GotResponse<T>>;
|
|
126
|
+
post<T = unknown>(url: string, options?: GotOptions): Promise<GotResponse<T>>;
|
|
127
|
+
put<T = unknown>(url: string, options?: GotOptions): Promise<GotResponse<T>>;
|
|
128
|
+
patch<T = unknown>(url: string, options?: GotOptions): Promise<GotResponse<T>>;
|
|
129
|
+
delete<T = unknown>(url: string, options?: GotOptions): Promise<GotResponse<T>>;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Wrap existing fetch implementation with xBind auto-upgrade
|
|
133
|
+
*
|
|
134
|
+
* Use this to upgrade an existing fetch instance (like node-fetch, cross-fetch, etc.)
|
|
135
|
+
*
|
|
136
|
+
* @param fetchImpl - Fetch implementation to wrap
|
|
137
|
+
* @returns Wrapped fetch with xBind support
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* import { wrapFetch } from '@private.me/xbind/http-compat';
|
|
142
|
+
* import nodeFetch from 'node-fetch';
|
|
143
|
+
*
|
|
144
|
+
* const fetch = wrapFetch(nodeFetch);
|
|
145
|
+
*
|
|
146
|
+
* // Uses xBind if supported, falls back to node-fetch
|
|
147
|
+
* const response = await fetch('https://api.example.com/data');
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function wrapFetch(fetchImpl: typeof fetch): typeof xfetch;
|