z-zero-mcp-server 1.9.0 → 1.10.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/README.md +56 -15
- package/dist/base_backend.js +50 -0
- package/dist/index.js +385 -155
- package/dist/ucp_bridge.d.ts +166 -0
- package/dist/ucp_bridge.js +886 -0
- package/package.json +4 -1
- package/dist/mock_backend.d.ts +0 -32
- package/dist/mock_backend.js +0 -150
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { CardData, PaymentResult } from "./types.js";
|
|
2
|
+
import * as https from "node:https";
|
|
3
|
+
declare function assertSafeUcpUrl(rawUrl: string, what: string): void;
|
|
4
|
+
/** Expand any IPv6 literal (::, zone id, embedded dotted IPv4) to 8 numeric groups; null if malformed. */
|
|
5
|
+
declare function expandIpv6(ip: string): number[] | null;
|
|
6
|
+
/**
|
|
7
|
+
* RFC1918 / loopback / link-local / CGNAT / multicast / unspecified for IPv4;
|
|
8
|
+
* for IPv6: ::/96 (unspecified, loopback, deprecated IPv4-compatible), IPv4-mapped
|
|
9
|
+
* ::ffff:0:0/96 in ANY spelling (dotted or hex — "::ffff:7f00:1" IS 127.0.0.1),
|
|
10
|
+
* NAT64 64:ff9b::/96, ULA fc00::/7, link-local fe80::/10, site-local fec0::/10,
|
|
11
|
+
* multicast ff00::/8. Unparseable literals are treated as unsafe.
|
|
12
|
+
*/
|
|
13
|
+
declare function isPrivateIp(ip: string): boolean;
|
|
14
|
+
type ResolvedAddr = {
|
|
15
|
+
address: string;
|
|
16
|
+
family: number;
|
|
17
|
+
};
|
|
18
|
+
/** Lookup override that ignores the hostname and returns ONLY the pre-vetted addresses. */
|
|
19
|
+
export declare function makePinnedLookup(addrs: ResolvedAddr[]): (...args: any[]) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Redirect policy (pure, unit-tested):
|
|
22
|
+
* - non-GET requests NEVER follow redirects (an MCP POST must land where discovery said);
|
|
23
|
+
* - cross-origin GET redirects are followed but credential-bearing headers are stripped.
|
|
24
|
+
*/
|
|
25
|
+
export declare function planRedirect(current: string, location: string, init: {
|
|
26
|
+
method?: string;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
}): {
|
|
29
|
+
next: string;
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
};
|
|
32
|
+
interface SafeResponse {
|
|
33
|
+
status: number;
|
|
34
|
+
ok: boolean;
|
|
35
|
+
headers: {
|
|
36
|
+
get(name: string): string | null;
|
|
37
|
+
};
|
|
38
|
+
text(): Promise<string>;
|
|
39
|
+
json(): Promise<any>;
|
|
40
|
+
}
|
|
41
|
+
interface SafeInit {
|
|
42
|
+
method?: string;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
body?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface PinnedRequestOpts {
|
|
47
|
+
deadlineMs?: number;
|
|
48
|
+
maxBodyBytes?: number;
|
|
49
|
+
/** Transport override for tests (e.g. http.request against a local server). Production: https.request. */
|
|
50
|
+
requestFn?: typeof https.request;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* One request whose TCP connection is pinned to the vetted addresses (SNI/Host stay the hostname).
|
|
54
|
+
* Guards against slow-loris (absolute deadline → destroy) and response bombs (body cap → destroy).
|
|
55
|
+
*/
|
|
56
|
+
export declare function pinnedRequest(url: string, init: SafeInit, addrs: ResolvedAddr[], opts?: PinnedRequestOpts): Promise<SafeResponse>;
|
|
57
|
+
export declare function minorUnitExponent(currency: string | null | undefined): number;
|
|
58
|
+
export declare function minorToMajor(minor: number | null, currency: string | null | undefined): number | null;
|
|
59
|
+
export interface UcpPaymentHandler {
|
|
60
|
+
handler_name: string;
|
|
61
|
+
id: string;
|
|
62
|
+
version: string;
|
|
63
|
+
config: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
export interface UcpDiscovery {
|
|
66
|
+
version: string;
|
|
67
|
+
mcpEndpoint: string;
|
|
68
|
+
handlers: UcpPaymentHandler[];
|
|
69
|
+
cardHandler: UcpPaymentHandler | null;
|
|
70
|
+
raw: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Fetches and parses a merchant's UCP discovery document.
|
|
74
|
+
* Returns null when the merchant does not speak UCP (→ caller falls back to Playwright).
|
|
75
|
+
* Throws only on SSRF rejection (never silently "fall back" past a blocked host).
|
|
76
|
+
*/
|
|
77
|
+
export declare function ucpDiscover(merchantUrl: string): Promise<UcpDiscovery | null>;
|
|
78
|
+
export declare class UcpMcpClient {
|
|
79
|
+
private endpoint;
|
|
80
|
+
private opts;
|
|
81
|
+
private nextId;
|
|
82
|
+
private sessionId;
|
|
83
|
+
private initialized;
|
|
84
|
+
constructor(endpoint: string, opts?: {
|
|
85
|
+
bearerToken?: string;
|
|
86
|
+
userAgent?: string;
|
|
87
|
+
agentProfile?: string;
|
|
88
|
+
});
|
|
89
|
+
private headers;
|
|
90
|
+
private rpc;
|
|
91
|
+
private ensureInitialized;
|
|
92
|
+
/** Calls a UCP tool. Retries once through the initialize handshake on "not initialized" errors. */
|
|
93
|
+
callTool(name: string, args: Record<string, unknown>): Promise<any>;
|
|
94
|
+
/**
|
|
95
|
+
* MCP tool results wrap payloads in content blocks; UCP puts JSON in structuredContent
|
|
96
|
+
* or a text block. Shopify marks results isError even when the payload is a perfectly
|
|
97
|
+
* valid checkout resource in a recoverable state (e.g. delivery_address_required) —
|
|
98
|
+
* so a parseable UCP resource is RETURNED, never thrown; only opaque errors throw.
|
|
99
|
+
*/
|
|
100
|
+
private unwrap;
|
|
101
|
+
}
|
|
102
|
+
export interface UcpBuyer {
|
|
103
|
+
email: string;
|
|
104
|
+
first_name?: string;
|
|
105
|
+
last_name?: string;
|
|
106
|
+
phone?: string;
|
|
107
|
+
}
|
|
108
|
+
export interface UcpAddress {
|
|
109
|
+
first_name?: string;
|
|
110
|
+
last_name?: string;
|
|
111
|
+
street_address: string;
|
|
112
|
+
extended_address?: string;
|
|
113
|
+
address_locality: string;
|
|
114
|
+
address_region?: string;
|
|
115
|
+
address_country: string;
|
|
116
|
+
postal_code: string;
|
|
117
|
+
phone_number?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface UcpLineItem {
|
|
120
|
+
/** Merchant product/variant identifier, e.g. a Shopify variant GID or product URL */
|
|
121
|
+
item_id: string;
|
|
122
|
+
quantity: number;
|
|
123
|
+
}
|
|
124
|
+
export interface UcpQuote {
|
|
125
|
+
checkout_id: string;
|
|
126
|
+
status: string;
|
|
127
|
+
total_minor: number | null;
|
|
128
|
+
total_major: number | null;
|
|
129
|
+
currency: string | null;
|
|
130
|
+
continue_url: string | null;
|
|
131
|
+
messages: string[];
|
|
132
|
+
raw: any;
|
|
133
|
+
}
|
|
134
|
+
declare function summarizeCheckout(checkout: any): Omit<UcpQuote, "raw">;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a checkout for the given line items and returns the merchant's quote
|
|
137
|
+
* (total, status, escalation info). NO money moves here — this is the read step
|
|
138
|
+
* the agent uses before requesting a JIT card for the exact total.
|
|
139
|
+
*/
|
|
140
|
+
export declare function ucpCreateCheckout(client: UcpMcpClient, items: UcpLineItem[], buyer: UcpBuyer, shippingAddress?: UcpAddress): Promise<UcpQuote>;
|
|
141
|
+
export declare function ucpGetCheckout(client: UcpMcpClient, checkoutId: string): Promise<UcpQuote>;
|
|
142
|
+
export interface UcpPayParams {
|
|
143
|
+
merchantUrl: string;
|
|
144
|
+
checkoutId: string;
|
|
145
|
+
cardData: CardData;
|
|
146
|
+
buyer: UcpBuyer;
|
|
147
|
+
billingAddress: UcpAddress;
|
|
148
|
+
bearerToken?: string;
|
|
149
|
+
/** Existing client (keeps session); a new one is built when omitted. */
|
|
150
|
+
client?: UcpMcpClient;
|
|
151
|
+
expectedTotalMajor?: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Attaches the card instrument and completes the checkout.
|
|
155
|
+
* Mirrors playwright_bridge semantics: returns PaymentResult where success=true
|
|
156
|
+
* ONLY on a merchant-confirmed order (that is the caller's sole burn gate).
|
|
157
|
+
*/
|
|
158
|
+
export declare function ucpPayCheckout(params: UcpPayParams): Promise<PaymentResult>;
|
|
159
|
+
export declare const __ucpInternals: {
|
|
160
|
+
isPrivateIp: typeof isPrivateIp;
|
|
161
|
+
expandIpv6: typeof expandIpv6;
|
|
162
|
+
assertSafeUcpUrl: typeof assertSafeUcpUrl;
|
|
163
|
+
summarizeCheckout: typeof summarizeCheckout;
|
|
164
|
+
pinnedRequest: typeof pinnedRequest;
|
|
165
|
+
};
|
|
166
|
+
export {};
|