@xrpay/x402 0.0.0-stage → 0.1.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.
@@ -0,0 +1,99 @@
1
+ import { type X402ClientOptions } from "./client.cjs";
2
+ import { type PaymentPayload, type PaymentRequired, type SettlementResponse, type XrplNetwork } from "./protocol.cjs";
3
+ export interface RecoveryCredentials {
4
+ token: string;
5
+ idempotencyKey: string;
6
+ }
7
+ export interface PurchaseHandle extends RecoveryCredentials {
8
+ id: string;
9
+ origin: string;
10
+ /** Persist before broadcast; retries reuse this exact authorization. */
11
+ signedPayment?: PaymentPayload;
12
+ }
13
+ export interface DigitalProduct {
14
+ id: string;
15
+ productId: string;
16
+ name: string;
17
+ description: string | null;
18
+ image: string | null;
19
+ merchant: {
20
+ name: string;
21
+ slug: string;
22
+ };
23
+ price: {
24
+ currency: string;
25
+ unitAmount: string;
26
+ taxAmount: string;
27
+ taxInclusive: boolean;
28
+ totalAmount: string;
29
+ };
30
+ payment: {
31
+ network: XrplNetwork;
32
+ currency: "XRP" | "RLUSD";
33
+ payTo: string;
34
+ };
35
+ delivery: {
36
+ filename: string;
37
+ mimeType: string;
38
+ byteLength: number;
39
+ sha256: string;
40
+ };
41
+ purchaseUrl: string;
42
+ }
43
+ export interface AgentPurchase {
44
+ id: string;
45
+ status: "quoted" | "expired" | "settling" | "paid";
46
+ quote: Record<string, unknown>;
47
+ expiresAt: string;
48
+ paymentRequired: PaymentRequired;
49
+ paymentUrl: string;
50
+ orderId: string | null;
51
+ receiptUrl: string | null;
52
+ downloadUrl: string | null;
53
+ settlement: SettlementResponse | null;
54
+ }
55
+ export declare function createRecoveryCredentials(): RecoveryCredentials;
56
+ export declare class CommerceRequestError extends Error {
57
+ status: number;
58
+ constructor(message: string, status: number);
59
+ }
60
+ export declare class XRPayCommerceClient {
61
+ readonly origin: string;
62
+ private readonly fetcher;
63
+ private readonly payments?;
64
+ constructor(options?: {
65
+ origin?: string;
66
+ payment?: X402ClientOptions;
67
+ fetch?: typeof globalThis.fetch;
68
+ });
69
+ private path;
70
+ private headers;
71
+ private check;
72
+ private parse;
73
+ discover(options?: {
74
+ network?: XrplNetwork;
75
+ merchant?: string;
76
+ query?: string;
77
+ after?: string;
78
+ limit?: number;
79
+ }): Promise<{
80
+ products: DigitalProduct[];
81
+ nextCursor: string | null;
82
+ }>;
83
+ /** Generate and durably store credentials BEFORE this call so a lost create response can be retried. */
84
+ createPurchase(listingId: string, buyer: {
85
+ customerEmail: string;
86
+ payerAddress: string;
87
+ }, credentials: RecoveryCredentials): Promise<{
88
+ purchase: AgentPurchase;
89
+ handle: PurchaseHandle;
90
+ }>;
91
+ /** checkpoint must durably save the updated handle before any signed payment is sent. */
92
+ pay(handle: PurchaseHandle, checkpoint: (handle: PurchaseHandle) => Promise<void>): Promise<AgentPurchase>;
93
+ recover(handle: PurchaseHandle): Promise<AgentPurchase>;
94
+ receipt(handle: PurchaseHandle): Promise<Record<string, unknown>>;
95
+ download(handle: PurchaseHandle): Promise<{
96
+ bytes: Uint8Array;
97
+ sha256: string;
98
+ }>;
99
+ }
@@ -0,0 +1,99 @@
1
+ import { type X402ClientOptions } from "./client.js";
2
+ import { type PaymentPayload, type PaymentRequired, type SettlementResponse, type XrplNetwork } from "./protocol.js";
3
+ export interface RecoveryCredentials {
4
+ token: string;
5
+ idempotencyKey: string;
6
+ }
7
+ export interface PurchaseHandle extends RecoveryCredentials {
8
+ id: string;
9
+ origin: string;
10
+ /** Persist before broadcast; retries reuse this exact authorization. */
11
+ signedPayment?: PaymentPayload;
12
+ }
13
+ export interface DigitalProduct {
14
+ id: string;
15
+ productId: string;
16
+ name: string;
17
+ description: string | null;
18
+ image: string | null;
19
+ merchant: {
20
+ name: string;
21
+ slug: string;
22
+ };
23
+ price: {
24
+ currency: string;
25
+ unitAmount: string;
26
+ taxAmount: string;
27
+ taxInclusive: boolean;
28
+ totalAmount: string;
29
+ };
30
+ payment: {
31
+ network: XrplNetwork;
32
+ currency: "XRP" | "RLUSD";
33
+ payTo: string;
34
+ };
35
+ delivery: {
36
+ filename: string;
37
+ mimeType: string;
38
+ byteLength: number;
39
+ sha256: string;
40
+ };
41
+ purchaseUrl: string;
42
+ }
43
+ export interface AgentPurchase {
44
+ id: string;
45
+ status: "quoted" | "expired" | "settling" | "paid";
46
+ quote: Record<string, unknown>;
47
+ expiresAt: string;
48
+ paymentRequired: PaymentRequired;
49
+ paymentUrl: string;
50
+ orderId: string | null;
51
+ receiptUrl: string | null;
52
+ downloadUrl: string | null;
53
+ settlement: SettlementResponse | null;
54
+ }
55
+ export declare function createRecoveryCredentials(): RecoveryCredentials;
56
+ export declare class CommerceRequestError extends Error {
57
+ status: number;
58
+ constructor(message: string, status: number);
59
+ }
60
+ export declare class XRPayCommerceClient {
61
+ readonly origin: string;
62
+ private readonly fetcher;
63
+ private readonly payments?;
64
+ constructor(options?: {
65
+ origin?: string;
66
+ payment?: X402ClientOptions;
67
+ fetch?: typeof globalThis.fetch;
68
+ });
69
+ private path;
70
+ private headers;
71
+ private check;
72
+ private parse;
73
+ discover(options?: {
74
+ network?: XrplNetwork;
75
+ merchant?: string;
76
+ query?: string;
77
+ after?: string;
78
+ limit?: number;
79
+ }): Promise<{
80
+ products: DigitalProduct[];
81
+ nextCursor: string | null;
82
+ }>;
83
+ /** Generate and durably store credentials BEFORE this call so a lost create response can be retried. */
84
+ createPurchase(listingId: string, buyer: {
85
+ customerEmail: string;
86
+ payerAddress: string;
87
+ }, credentials: RecoveryCredentials): Promise<{
88
+ purchase: AgentPurchase;
89
+ handle: PurchaseHandle;
90
+ }>;
91
+ /** checkpoint must durably save the updated handle before any signed payment is sent. */
92
+ pay(handle: PurchaseHandle, checkpoint: (handle: PurchaseHandle) => Promise<void>): Promise<AgentPurchase>;
93
+ recover(handle: PurchaseHandle): Promise<AgentPurchase>;
94
+ receipt(handle: PurchaseHandle): Promise<Record<string, unknown>>;
95
+ download(handle: PurchaseHandle): Promise<{
96
+ bytes: Uint8Array;
97
+ sha256: string;
98
+ }>;
99
+ }