@fragmentpay/server 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Frag / FragmentPay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @fragmentpay/server
2
+
3
+ Runtime-agnostic Frag SDK. Zero dependencies. Works in Node 18+, Bun, Deno,
4
+ Cloudflare Workers, Vercel Edge, and every runtime with global `fetch`.
5
+
6
+ All inputs are validated at runtime — bad parameters throw `FragValidationError`
7
+ with a clear path (e.g. `[frag] createIntent.amount: min 0.01`) before a
8
+ network round-trip.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @fragmentpay/server
14
+ # or: bun add @fragmentpay/server
15
+ # or: pnpm add @fragmentpay/server
16
+ ```
17
+
18
+ ## Required environment variables
19
+
20
+ | Name | Where | Example |
21
+ | ------------------------ | -------------- | --------------------------------------- |
22
+ | `FRAG_SECRET_KEY` | server only | `sk_live_…` or `sk_test_…` |
23
+ | `FRAG_WEBHOOK_SECRET` | server only | value shown when you create the webhook |
24
+ | `FRAG_BASE_URL` *(opt.)* | server only | override host, default `https://api.frag.dev` |
25
+
26
+ Never expose `sk_…` in a browser bundle.
27
+
28
+ ## End-to-end example (copy-paste)
29
+
30
+ **1. Create an intent from your backend**
31
+
32
+ ```ts
33
+ // server/frag.ts
34
+ import { Frag } from "@fragmentpay/server";
35
+
36
+ export const frag = new Frag({ secretKey: process.env.FRAG_SECRET_KEY! });
37
+
38
+ export async function startCheckout(orderId: string, cents: number, email: string) {
39
+ const intent = await frag.paymentIntents.create({
40
+ amount: cents / 100,
41
+ currency: "USD",
42
+ customerEmail: email,
43
+ settlement: {
44
+ chain: "base",
45
+ token: "USDC",
46
+ address: process.env.MERCHANT_USDC_ADDRESS!,
47
+ },
48
+ successUrl: "https://shop.example.com/thanks",
49
+ cancelUrl: "https://shop.example.com/cart",
50
+ metadata: { order_id: orderId },
51
+ idempotencyKey: `order_${orderId}`,
52
+ });
53
+ return { intentId: intent.id, checkoutUrl: intent.checkout_url };
54
+ }
55
+ ```
56
+
57
+ **2. Verify inbound webhooks**
58
+
59
+ ```ts
60
+ // server/webhook.ts
61
+ import { verifyWebhook } from "@fragmentpay/server";
62
+
63
+ export async function POST(req: Request) {
64
+ const payload = await req.text();
65
+ const event = await verifyWebhook({
66
+ payload,
67
+ signature: req.headers.get("x-frag-signature"),
68
+ secret: process.env.FRAG_WEBHOOK_SECRET!,
69
+ });
70
+
71
+ if (event.type === "payment_intent.settled") {
72
+ await markOrderPaid(event.data as { id: string; metadata: { order_id: string } });
73
+ }
74
+ return new Response("ok");
75
+ }
76
+ ```
77
+
78
+ **3. React drop-in on the frontend** — see `@fragmentpay/react`.
79
+
80
+ ## Validation errors
81
+
82
+ Every method validates its arguments and throws a `FragValidationError`
83
+ before touching the network:
84
+
85
+ ```ts
86
+ frag.paymentIntents.create({ amount: -5 });
87
+ // FragValidationError: [frag] createIntent.amount: min 0.01
88
+ ```
89
+
90
+ ## Public API surface
91
+
92
+ - `frag.paymentIntents.{create, retrieve, list, cancel, transactions, route}`
93
+ - `frag.refunds.{create, retrieve, list}`
94
+ - `frag.payouts.{retrieve, list, replay}`
95
+ - `frag.webhookEndpoints.{create, list, retrieve, update, delete, rotateSecret}`
96
+ - `frag.tokens.list({ chain })`
97
+ - `verifyWebhook({ payload, signature, secret })`
98
+ - `FragError` (HTTP + upstream) and `FragValidationError` (input)
99
+
100
+ ## License
101
+
102
+ MIT
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Zero-dependency runtime validators for Frag SDK payloads.
3
+ *
4
+ * Every public method funnels user input through these guards so mistakes
5
+ * (wrong type, missing field, malformed id) fail fast with a clear message
6
+ * instead of surfacing as an HTTP 400 later.
7
+ */
8
+ declare class FragValidationError extends Error {
9
+ readonly path: string;
10
+ constructor(path: string, message: string);
11
+ }
12
+
13
+ /**
14
+ * @fragmentpay/server
15
+ *
16
+ * Runtime-agnostic Frag SDK. Uses only global fetch + crypto.subtle so it
17
+ * works in Node 18+, Bun, Deno, Cloudflare Workers, and every edge runtime.
18
+ *
19
+ * Zero runtime dependencies. Full coverage of the public REST surface at
20
+ * /api/public/v1/*.
21
+ */
22
+
23
+ type Chain = "solana" | "ethereum" | "base" | "arbitrum" | "optimism" | "polygon" | "bnb";
24
+ type IntentStatus = "created" | "requires_payment" | "quoted" | "awaiting_signature" | "executing" | "partially_filled" | "settled" | "failed" | "expired" | "cancelled" | "refunded";
25
+ type PayoutStatus = "queued" | "pending" | "paid" | "failed" | "paused";
26
+ type RefundStatus = "pending" | "paid" | "failed" | "cancelled";
27
+ interface Settlement {
28
+ chain: Chain | string;
29
+ token: string;
30
+ address: string;
31
+ exactAmount?: string;
32
+ }
33
+ interface CreateIntentInput {
34
+ amount: number | string;
35
+ currency?: string;
36
+ settlement?: Partial<Settlement>;
37
+ customerEmail?: string;
38
+ metadata?: Record<string, string | number | boolean>;
39
+ successUrl?: string;
40
+ cancelUrl?: string;
41
+ /** Override merchant default expiry (seconds, 60..86400). */
42
+ expiresInSeconds?: number;
43
+ /** Idempotency-Key for safe client retries. */
44
+ idempotencyKey?: string;
45
+ }
46
+ interface PaymentIntent {
47
+ id: string;
48
+ amount: string;
49
+ currency: string;
50
+ status: IntentStatus;
51
+ checkout_url: string;
52
+ expires_at: string;
53
+ created_at: string;
54
+ metadata?: Record<string, unknown>;
55
+ }
56
+ interface IntentTransaction {
57
+ id: string;
58
+ payment_intent_id: string;
59
+ chain: string;
60
+ token: string;
61
+ amount: string;
62
+ amount_usd: number | null;
63
+ status: string;
64
+ tx_hash: string | null;
65
+ from_address: string | null;
66
+ created_at: string;
67
+ }
68
+ interface RouteCandidate {
69
+ id: string;
70
+ provider: string;
71
+ chosen: boolean;
72
+ ai_pick: boolean;
73
+ score: number;
74
+ from_chain: string;
75
+ to_chain: string;
76
+ from_token: string;
77
+ to_token: string;
78
+ to_amount_usd: number | null;
79
+ fee_usd: number | null;
80
+ gas_usd: number | null;
81
+ duration_sec: number | null;
82
+ reason: string | null;
83
+ error: string | null;
84
+ created_at: string;
85
+ }
86
+ interface Refund {
87
+ id: string;
88
+ payment_intent_id: string;
89
+ amount_usd: number;
90
+ chain: string;
91
+ token: string;
92
+ destination: string;
93
+ reason: string;
94
+ status: RefundStatus;
95
+ tx_hash: string | null;
96
+ created_at: string;
97
+ paid_at: string | null;
98
+ failure_reason?: string | null;
99
+ }
100
+ interface Payout {
101
+ id: string;
102
+ payment_intent_id: string | null;
103
+ rail: string;
104
+ destination: string;
105
+ chain: string;
106
+ token: string;
107
+ amount: string;
108
+ currency: string;
109
+ status: PayoutStatus;
110
+ tx_hash: string | null;
111
+ failure_reason: string | null;
112
+ attempts: number;
113
+ next_attempt_at: string | null;
114
+ paid_at: string | null;
115
+ created_at: string;
116
+ }
117
+ interface WebhookEndpoint {
118
+ id: string;
119
+ url: string;
120
+ events: string[];
121
+ enabled: boolean;
122
+ created_at: string;
123
+ /** Present only in create + rotate-secret responses. */
124
+ signing_secret?: string;
125
+ }
126
+ interface FragToken {
127
+ chain: Chain | string;
128
+ address: string;
129
+ symbol: string;
130
+ name?: string;
131
+ decimals: number;
132
+ verified: boolean;
133
+ min_liquidity_usd?: number;
134
+ }
135
+ type WebhookEventType = "payment_intent.created" | "payment_intent.quoted" | "payment_intent.executing" | "payment_intent.executed" | "payment_intent.settled" | "payment_intent.failed" | "payment_intent.expired" | "payment_intent.cancelled" | "payment_intent.refunded" | "quote.created" | "settlement.confirmed" | "payout.pending" | "payout.paid" | "payout.failed" | "refund.pending" | "refund.paid" | "refund.failed";
136
+ interface WebhookEvent<T = unknown> {
137
+ id: string;
138
+ type: WebhookEventType;
139
+ data: T;
140
+ created_at: string;
141
+ }
142
+ interface FragOptions {
143
+ apiKey: string;
144
+ baseUrl?: string;
145
+ fetch?: typeof fetch;
146
+ /** Request timeout in ms. Default 30_000. Set 0 to disable. */
147
+ timeout?: number;
148
+ /** Max retries on 429/5xx (jittered exponential backoff). Default 2. */
149
+ retries?: number;
150
+ /** Log redacted request/response info via console.debug. */
151
+ debug?: boolean;
152
+ }
153
+ declare class FragError extends Error {
154
+ readonly status: number;
155
+ readonly code: string;
156
+ readonly requestId?: string;
157
+ readonly raw: unknown;
158
+ constructor(status: number, code: string, message: string, raw: unknown, requestId?: string);
159
+ }
160
+ type Requester = <T>(path: string, init?: RequestInit & {
161
+ idempotencyKey?: string;
162
+ query?: Record<string, string | number | boolean | undefined>;
163
+ }) => Promise<T>;
164
+ declare class FragmentPay {
165
+ #private;
166
+ readonly paymentIntents: PaymentIntentResource;
167
+ readonly refunds: RefundResource;
168
+ readonly payouts: PayoutResource;
169
+ readonly webhookEndpoints: WebhookEndpointResource;
170
+ readonly webhooks: WebhookHelpers;
171
+ readonly tokens: TokenResource;
172
+ constructor(opts: FragOptions);
173
+ setDebug(on: boolean): void;
174
+ }
175
+ declare class PaymentIntentResource {
176
+ private req;
177
+ constructor(req: Requester);
178
+ create(input: CreateIntentInput): Promise<PaymentIntent>;
179
+ retrieve(id: string): Promise<PaymentIntent>;
180
+ list(params?: {
181
+ limit?: number;
182
+ status?: IntentStatus;
183
+ }): Promise<{
184
+ data: PaymentIntent[];
185
+ }>;
186
+ cancel(id: string): Promise<PaymentIntent>;
187
+ transactions(id: string): Promise<{
188
+ data: IntentTransaction[];
189
+ }>;
190
+ route(id: string): Promise<{
191
+ data: RouteCandidate[];
192
+ }>;
193
+ }
194
+ declare class RefundResource {
195
+ private req;
196
+ constructor(req: Requester);
197
+ create(input: {
198
+ paymentIntentId: string;
199
+ amountUsd: number;
200
+ destination: string;
201
+ reason?: string;
202
+ idempotencyKey?: string;
203
+ }): Promise<Refund>;
204
+ retrieve(id: string): Promise<Refund>;
205
+ list(params?: {
206
+ paymentIntentId?: string;
207
+ limit?: number;
208
+ }): Promise<{
209
+ data: Refund[];
210
+ }>;
211
+ }
212
+ declare class PayoutResource {
213
+ private req;
214
+ constructor(req: Requester);
215
+ retrieve(id: string): Promise<Payout>;
216
+ list(params?: {
217
+ status?: PayoutStatus;
218
+ paymentIntentId?: string;
219
+ limit?: number;
220
+ }): Promise<{
221
+ data: Payout[];
222
+ }>;
223
+ replay(id: string): Promise<{
224
+ replayed: boolean;
225
+ result: unknown;
226
+ }>;
227
+ }
228
+ declare class WebhookEndpointResource {
229
+ private req;
230
+ constructor(req: Requester);
231
+ create(input: {
232
+ url: string;
233
+ events: WebhookEventType[] | string[];
234
+ enabled?: boolean;
235
+ }): Promise<WebhookEndpoint>;
236
+ list(): Promise<{
237
+ data: WebhookEndpoint[];
238
+ }>;
239
+ retrieve(id: string): Promise<WebhookEndpoint>;
240
+ update(id: string, patch: Partial<{
241
+ url: string;
242
+ events: string[];
243
+ enabled: boolean;
244
+ }>): Promise<WebhookEndpoint>;
245
+ delete(id: string): Promise<{
246
+ deleted: true;
247
+ }>;
248
+ rotateSecret(id: string): Promise<WebhookEndpoint>;
249
+ }
250
+ declare class TokenResource {
251
+ private req;
252
+ constructor(req: Requester);
253
+ list(params?: {
254
+ chain?: Chain | string;
255
+ }): Promise<{
256
+ data: FragToken[];
257
+ }>;
258
+ }
259
+ declare class WebhookHelpers {
260
+ verify(payload: string, header: string | null, secret: string, tolerance?: number): Promise<boolean>;
261
+ parse<T = unknown>(payload: string): WebhookEvent<T>;
262
+ }
263
+ interface VerifyWebhookInput {
264
+ payload: string;
265
+ signature: string | null | undefined;
266
+ secret: string;
267
+ tolerance?: number;
268
+ }
269
+ /** Verify + parse in one call. Throws FragError on any failure. */
270
+ declare function verifyWebhook<T = unknown>(input: VerifyWebhookInput): Promise<WebhookEvent<T>>;
271
+ declare class Frag extends FragmentPay {
272
+ constructor(opts: FragOptions | {
273
+ secretKey: string;
274
+ baseUrl?: string;
275
+ fetch?: typeof fetch;
276
+ timeout?: number;
277
+ retries?: number;
278
+ debug?: boolean;
279
+ });
280
+ }
281
+
282
+ export { type Chain, type CreateIntentInput, Frag, FragError, type FragOptions, type FragToken, FragValidationError, FragmentPay, type IntentStatus, type IntentTransaction, type PaymentIntent, type Payout, type PayoutStatus, type Refund, type RefundStatus, type RouteCandidate, type Settlement, type VerifyWebhookInput, type WebhookEndpoint, type WebhookEvent, type WebhookEventType, verifyWebhook };
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Zero-dependency runtime validators for Frag SDK payloads.
3
+ *
4
+ * Every public method funnels user input through these guards so mistakes
5
+ * (wrong type, missing field, malformed id) fail fast with a clear message
6
+ * instead of surfacing as an HTTP 400 later.
7
+ */
8
+ declare class FragValidationError extends Error {
9
+ readonly path: string;
10
+ constructor(path: string, message: string);
11
+ }
12
+
13
+ /**
14
+ * @fragmentpay/server
15
+ *
16
+ * Runtime-agnostic Frag SDK. Uses only global fetch + crypto.subtle so it
17
+ * works in Node 18+, Bun, Deno, Cloudflare Workers, and every edge runtime.
18
+ *
19
+ * Zero runtime dependencies. Full coverage of the public REST surface at
20
+ * /api/public/v1/*.
21
+ */
22
+
23
+ type Chain = "solana" | "ethereum" | "base" | "arbitrum" | "optimism" | "polygon" | "bnb";
24
+ type IntentStatus = "created" | "requires_payment" | "quoted" | "awaiting_signature" | "executing" | "partially_filled" | "settled" | "failed" | "expired" | "cancelled" | "refunded";
25
+ type PayoutStatus = "queued" | "pending" | "paid" | "failed" | "paused";
26
+ type RefundStatus = "pending" | "paid" | "failed" | "cancelled";
27
+ interface Settlement {
28
+ chain: Chain | string;
29
+ token: string;
30
+ address: string;
31
+ exactAmount?: string;
32
+ }
33
+ interface CreateIntentInput {
34
+ amount: number | string;
35
+ currency?: string;
36
+ settlement?: Partial<Settlement>;
37
+ customerEmail?: string;
38
+ metadata?: Record<string, string | number | boolean>;
39
+ successUrl?: string;
40
+ cancelUrl?: string;
41
+ /** Override merchant default expiry (seconds, 60..86400). */
42
+ expiresInSeconds?: number;
43
+ /** Idempotency-Key for safe client retries. */
44
+ idempotencyKey?: string;
45
+ }
46
+ interface PaymentIntent {
47
+ id: string;
48
+ amount: string;
49
+ currency: string;
50
+ status: IntentStatus;
51
+ checkout_url: string;
52
+ expires_at: string;
53
+ created_at: string;
54
+ metadata?: Record<string, unknown>;
55
+ }
56
+ interface IntentTransaction {
57
+ id: string;
58
+ payment_intent_id: string;
59
+ chain: string;
60
+ token: string;
61
+ amount: string;
62
+ amount_usd: number | null;
63
+ status: string;
64
+ tx_hash: string | null;
65
+ from_address: string | null;
66
+ created_at: string;
67
+ }
68
+ interface RouteCandidate {
69
+ id: string;
70
+ provider: string;
71
+ chosen: boolean;
72
+ ai_pick: boolean;
73
+ score: number;
74
+ from_chain: string;
75
+ to_chain: string;
76
+ from_token: string;
77
+ to_token: string;
78
+ to_amount_usd: number | null;
79
+ fee_usd: number | null;
80
+ gas_usd: number | null;
81
+ duration_sec: number | null;
82
+ reason: string | null;
83
+ error: string | null;
84
+ created_at: string;
85
+ }
86
+ interface Refund {
87
+ id: string;
88
+ payment_intent_id: string;
89
+ amount_usd: number;
90
+ chain: string;
91
+ token: string;
92
+ destination: string;
93
+ reason: string;
94
+ status: RefundStatus;
95
+ tx_hash: string | null;
96
+ created_at: string;
97
+ paid_at: string | null;
98
+ failure_reason?: string | null;
99
+ }
100
+ interface Payout {
101
+ id: string;
102
+ payment_intent_id: string | null;
103
+ rail: string;
104
+ destination: string;
105
+ chain: string;
106
+ token: string;
107
+ amount: string;
108
+ currency: string;
109
+ status: PayoutStatus;
110
+ tx_hash: string | null;
111
+ failure_reason: string | null;
112
+ attempts: number;
113
+ next_attempt_at: string | null;
114
+ paid_at: string | null;
115
+ created_at: string;
116
+ }
117
+ interface WebhookEndpoint {
118
+ id: string;
119
+ url: string;
120
+ events: string[];
121
+ enabled: boolean;
122
+ created_at: string;
123
+ /** Present only in create + rotate-secret responses. */
124
+ signing_secret?: string;
125
+ }
126
+ interface FragToken {
127
+ chain: Chain | string;
128
+ address: string;
129
+ symbol: string;
130
+ name?: string;
131
+ decimals: number;
132
+ verified: boolean;
133
+ min_liquidity_usd?: number;
134
+ }
135
+ type WebhookEventType = "payment_intent.created" | "payment_intent.quoted" | "payment_intent.executing" | "payment_intent.executed" | "payment_intent.settled" | "payment_intent.failed" | "payment_intent.expired" | "payment_intent.cancelled" | "payment_intent.refunded" | "quote.created" | "settlement.confirmed" | "payout.pending" | "payout.paid" | "payout.failed" | "refund.pending" | "refund.paid" | "refund.failed";
136
+ interface WebhookEvent<T = unknown> {
137
+ id: string;
138
+ type: WebhookEventType;
139
+ data: T;
140
+ created_at: string;
141
+ }
142
+ interface FragOptions {
143
+ apiKey: string;
144
+ baseUrl?: string;
145
+ fetch?: typeof fetch;
146
+ /** Request timeout in ms. Default 30_000. Set 0 to disable. */
147
+ timeout?: number;
148
+ /** Max retries on 429/5xx (jittered exponential backoff). Default 2. */
149
+ retries?: number;
150
+ /** Log redacted request/response info via console.debug. */
151
+ debug?: boolean;
152
+ }
153
+ declare class FragError extends Error {
154
+ readonly status: number;
155
+ readonly code: string;
156
+ readonly requestId?: string;
157
+ readonly raw: unknown;
158
+ constructor(status: number, code: string, message: string, raw: unknown, requestId?: string);
159
+ }
160
+ type Requester = <T>(path: string, init?: RequestInit & {
161
+ idempotencyKey?: string;
162
+ query?: Record<string, string | number | boolean | undefined>;
163
+ }) => Promise<T>;
164
+ declare class FragmentPay {
165
+ #private;
166
+ readonly paymentIntents: PaymentIntentResource;
167
+ readonly refunds: RefundResource;
168
+ readonly payouts: PayoutResource;
169
+ readonly webhookEndpoints: WebhookEndpointResource;
170
+ readonly webhooks: WebhookHelpers;
171
+ readonly tokens: TokenResource;
172
+ constructor(opts: FragOptions);
173
+ setDebug(on: boolean): void;
174
+ }
175
+ declare class PaymentIntentResource {
176
+ private req;
177
+ constructor(req: Requester);
178
+ create(input: CreateIntentInput): Promise<PaymentIntent>;
179
+ retrieve(id: string): Promise<PaymentIntent>;
180
+ list(params?: {
181
+ limit?: number;
182
+ status?: IntentStatus;
183
+ }): Promise<{
184
+ data: PaymentIntent[];
185
+ }>;
186
+ cancel(id: string): Promise<PaymentIntent>;
187
+ transactions(id: string): Promise<{
188
+ data: IntentTransaction[];
189
+ }>;
190
+ route(id: string): Promise<{
191
+ data: RouteCandidate[];
192
+ }>;
193
+ }
194
+ declare class RefundResource {
195
+ private req;
196
+ constructor(req: Requester);
197
+ create(input: {
198
+ paymentIntentId: string;
199
+ amountUsd: number;
200
+ destination: string;
201
+ reason?: string;
202
+ idempotencyKey?: string;
203
+ }): Promise<Refund>;
204
+ retrieve(id: string): Promise<Refund>;
205
+ list(params?: {
206
+ paymentIntentId?: string;
207
+ limit?: number;
208
+ }): Promise<{
209
+ data: Refund[];
210
+ }>;
211
+ }
212
+ declare class PayoutResource {
213
+ private req;
214
+ constructor(req: Requester);
215
+ retrieve(id: string): Promise<Payout>;
216
+ list(params?: {
217
+ status?: PayoutStatus;
218
+ paymentIntentId?: string;
219
+ limit?: number;
220
+ }): Promise<{
221
+ data: Payout[];
222
+ }>;
223
+ replay(id: string): Promise<{
224
+ replayed: boolean;
225
+ result: unknown;
226
+ }>;
227
+ }
228
+ declare class WebhookEndpointResource {
229
+ private req;
230
+ constructor(req: Requester);
231
+ create(input: {
232
+ url: string;
233
+ events: WebhookEventType[] | string[];
234
+ enabled?: boolean;
235
+ }): Promise<WebhookEndpoint>;
236
+ list(): Promise<{
237
+ data: WebhookEndpoint[];
238
+ }>;
239
+ retrieve(id: string): Promise<WebhookEndpoint>;
240
+ update(id: string, patch: Partial<{
241
+ url: string;
242
+ events: string[];
243
+ enabled: boolean;
244
+ }>): Promise<WebhookEndpoint>;
245
+ delete(id: string): Promise<{
246
+ deleted: true;
247
+ }>;
248
+ rotateSecret(id: string): Promise<WebhookEndpoint>;
249
+ }
250
+ declare class TokenResource {
251
+ private req;
252
+ constructor(req: Requester);
253
+ list(params?: {
254
+ chain?: Chain | string;
255
+ }): Promise<{
256
+ data: FragToken[];
257
+ }>;
258
+ }
259
+ declare class WebhookHelpers {
260
+ verify(payload: string, header: string | null, secret: string, tolerance?: number): Promise<boolean>;
261
+ parse<T = unknown>(payload: string): WebhookEvent<T>;
262
+ }
263
+ interface VerifyWebhookInput {
264
+ payload: string;
265
+ signature: string | null | undefined;
266
+ secret: string;
267
+ tolerance?: number;
268
+ }
269
+ /** Verify + parse in one call. Throws FragError on any failure. */
270
+ declare function verifyWebhook<T = unknown>(input: VerifyWebhookInput): Promise<WebhookEvent<T>>;
271
+ declare class Frag extends FragmentPay {
272
+ constructor(opts: FragOptions | {
273
+ secretKey: string;
274
+ baseUrl?: string;
275
+ fetch?: typeof fetch;
276
+ timeout?: number;
277
+ retries?: number;
278
+ debug?: boolean;
279
+ });
280
+ }
281
+
282
+ export { type Chain, type CreateIntentInput, Frag, FragError, type FragOptions, type FragToken, FragValidationError, FragmentPay, type IntentStatus, type IntentTransaction, type PaymentIntent, type Payout, type PayoutStatus, type Refund, type RefundStatus, type RouteCandidate, type Settlement, type VerifyWebhookInput, type WebhookEndpoint, type WebhookEvent, type WebhookEventType, verifyWebhook };