@klappay/types 3.8.0 → 4.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.
- package/README.md +20 -2
- package/dist/chunk-WKIOAEJ3.mjs +137 -0
- package/dist/chunk-WKIOAEJ3.mjs.map +1 -0
- package/dist/{constants-DQGVNS9O.d.mts → constants-021Ybu31.d.mts} +11 -2
- package/dist/{constants-DQGVNS9O.d.ts → constants-021Ybu31.d.ts} +11 -2
- package/dist/constants.d.mts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +51 -20
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +9 -3
- package/dist/index.d.mts +57 -8
- package/dist/index.d.ts +57 -8
- package/dist/index.js +342 -284
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +301 -268
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-KZ3646WX.mjs +0 -109
- package/dist/chunk-KZ3646WX.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -105,6 +105,7 @@ __export(index_exports, {
|
|
|
105
105
|
SwapQuoteSchema: () => SwapQuoteSchema,
|
|
106
106
|
TOKEN_ADDRESSES: () => TOKEN_ADDRESSES,
|
|
107
107
|
TOKEN_DECIMALS: () => TOKEN_DECIMALS,
|
|
108
|
+
TOKEN_DEPLOYMENTS: () => TOKEN_DEPLOYMENTS,
|
|
108
109
|
TimelineEventSchema: () => TimelineEventSchema,
|
|
109
110
|
TimelineEventTypeSchema: () => TimelineEventTypeSchema,
|
|
110
111
|
TokenSchema: () => TokenSchema,
|
|
@@ -124,6 +125,8 @@ __export(index_exports, {
|
|
|
124
125
|
WebhookPayloadSchema: () => WebhookPayloadSchema,
|
|
125
126
|
WebhookSchema: () => WebhookSchema,
|
|
126
127
|
findConflictingScopes: () => findConflictingScopes,
|
|
128
|
+
getTokenDeployment: () => getTokenDeployment,
|
|
129
|
+
isPaymentDeploymentEnabled: () => isPaymentDeploymentEnabled,
|
|
127
130
|
listSwapAlternatives: () => listSwapAlternatives,
|
|
128
131
|
paginatedSchema: () => paginatedSchema
|
|
129
132
|
});
|
|
@@ -146,7 +149,7 @@ var ErrorPayloadSchema = import_zod.z.object({
|
|
|
146
149
|
// src/environment.ts
|
|
147
150
|
var import_zod2 = require("zod");
|
|
148
151
|
var EnvironmentSchema = import_zod2.z.enum(["live", "test"]).describe(
|
|
149
|
-
"`live` or `test`, matching the `klap_live_.../klap_test_...` prefix of the API key that created or is scoped to this resource. `live`
|
|
152
|
+
"`live` or `test`, matching the `klap_live_.../klap_test_...` prefix of the API key that created or is scoped to this resource. `live` uses the selected network's mainnet with real funds; `test` uses its separately configured testnet. Token contracts and availability are resolved per network/environment; a missing test deployment never falls back to live."
|
|
150
153
|
);
|
|
151
154
|
|
|
152
155
|
// src/api-key-scopes.ts
|
|
@@ -261,39 +264,64 @@ var import_zod6 = require("zod");
|
|
|
261
264
|
|
|
262
265
|
// src/tokens.constants.ts
|
|
263
266
|
var TOKEN_DECIMALS = 6;
|
|
264
|
-
var
|
|
267
|
+
var TOKEN_DEPLOYMENTS = {
|
|
265
268
|
USDC: {
|
|
266
269
|
base: {
|
|
267
|
-
live: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
268
|
-
test: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
|
|
270
|
+
live: { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", decimals: 6 },
|
|
271
|
+
test: { address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", decimals: 6 }
|
|
269
272
|
},
|
|
270
273
|
optimism: {
|
|
271
|
-
live: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
272
|
-
test: "0x5fd84259d66Cd46123540766Be93DFE6D43130D7"
|
|
274
|
+
live: { address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85", decimals: 6 },
|
|
275
|
+
test: { address: "0x5fd84259d66Cd46123540766Be93DFE6D43130D7", decimals: 6 }
|
|
273
276
|
},
|
|
274
|
-
polygon: { live: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359" },
|
|
277
|
+
polygon: { live: { address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", decimals: 6 } },
|
|
275
278
|
ethereum: {
|
|
276
|
-
live: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
277
|
-
test: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
|
|
279
|
+
live: { address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", decimals: 6 },
|
|
280
|
+
test: { address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", decimals: 6 }
|
|
278
281
|
},
|
|
279
|
-
arbitrum: { live: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831" },
|
|
280
|
-
avalanche: { live: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E" },
|
|
281
|
-
bnb: { live: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d" }
|
|
282
|
+
arbitrum: { live: { address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", decimals: 6 } },
|
|
283
|
+
avalanche: { live: { address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E", decimals: 6 } },
|
|
284
|
+
bnb: { live: { address: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d", decimals: 18 } }
|
|
282
285
|
},
|
|
283
286
|
USDT: {
|
|
284
|
-
base: { live: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2" },
|
|
285
|
-
optimism: { live: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58" },
|
|
286
|
-
polygon: { live: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F" },
|
|
287
|
-
ethereum: { live: "0xdAC17F958D2ee523a2206206994597C13D831ec7" },
|
|
288
|
-
arbitrum: { live: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9" },
|
|
289
|
-
avalanche: { live: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7" },
|
|
290
|
-
bnb: { live: "0x55d398326f99059fF775485246999027B3197955" }
|
|
287
|
+
base: { live: { address: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2", decimals: 6 } },
|
|
288
|
+
optimism: { live: { address: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58", decimals: 6 } },
|
|
289
|
+
polygon: { live: { address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", decimals: 6 } },
|
|
290
|
+
ethereum: { live: { address: "0xdAC17F958D2ee523a2206206994597C13D831ec7", decimals: 6 } },
|
|
291
|
+
arbitrum: { live: { address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", decimals: 6 } },
|
|
292
|
+
avalanche: { live: { address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7", decimals: 6 } },
|
|
293
|
+
bnb: { live: { address: "0x55d398326f99059fF775485246999027B3197955", decimals: 18 } }
|
|
291
294
|
}
|
|
292
295
|
};
|
|
296
|
+
function getTokenDeployment(token, network, environment) {
|
|
297
|
+
return TOKEN_DEPLOYMENTS[token][network]?.[environment];
|
|
298
|
+
}
|
|
299
|
+
function isPaymentDeploymentEnabled(token, network, environment) {
|
|
300
|
+
if (network === "bnb" && environment === "live") return false;
|
|
301
|
+
return getTokenDeployment(token, network, environment) !== void 0;
|
|
302
|
+
}
|
|
303
|
+
function deriveAddresses(deployments) {
|
|
304
|
+
const addresses = {};
|
|
305
|
+
for (const network of EVM_NETWORKS) {
|
|
306
|
+
const byEnvironment = deployments[network];
|
|
307
|
+
if (!byEnvironment) continue;
|
|
308
|
+
const networkAddresses = {};
|
|
309
|
+
for (const environment of ["live", "test"]) {
|
|
310
|
+
const deployment = byEnvironment[environment];
|
|
311
|
+
if (deployment) networkAddresses[environment] = deployment.address;
|
|
312
|
+
}
|
|
313
|
+
addresses[network] = networkAddresses;
|
|
314
|
+
}
|
|
315
|
+
return addresses;
|
|
316
|
+
}
|
|
317
|
+
var TOKEN_ADDRESSES = {
|
|
318
|
+
USDC: deriveAddresses(TOKEN_DEPLOYMENTS.USDC),
|
|
319
|
+
USDT: deriveAddresses(TOKEN_DEPLOYMENTS.USDT)
|
|
320
|
+
};
|
|
293
321
|
|
|
294
322
|
// src/tokens.ts
|
|
295
323
|
var TokenSchema = import_zod6.z.enum(["USDC", "USDT"]).describe(
|
|
296
|
-
|
|
324
|
+
"Which stablecoin the payer will send. Availability depends on `network` and `environment`; check `GET /v1/networks` before creating a charge. Unconfigured or disabled pairs are rejected with `422 token_not_supported`. Base, Optimism, and Ethereum have USDC test deployments; no test USDT is configured. The catalog includes both BNB Chain tokens for historical interpretation, but payments with either are currently disabled. Both configured BNB contracts are Binance-Peg tokens with 18 decimals; the other configured deployments use 6. Binance-Peg tokens carry Binance custody/backing risk and must not be represented as direct Circle/Tether issuance. Resolve address and decimals together with `getTokenDeployment`; a catalog entry alone does not imply payment availability."
|
|
297
325
|
);
|
|
298
326
|
|
|
299
327
|
// src/alt-tokens.ts
|
|
@@ -338,7 +366,7 @@ function listSwapAlternatives(networks) {
|
|
|
338
366
|
}
|
|
339
367
|
|
|
340
368
|
// src/charges.ts
|
|
341
|
-
var
|
|
369
|
+
var import_zod11 = require("zod");
|
|
342
370
|
|
|
343
371
|
// src/checkout-metadata.ts
|
|
344
372
|
var import_zod8 = require("zod");
|
|
@@ -379,38 +407,44 @@ var RefundEscrowRequestSchema = import_zod9.z.object({
|
|
|
379
407
|
)
|
|
380
408
|
});
|
|
381
409
|
|
|
410
|
+
// src/exact-amount.ts
|
|
411
|
+
var import_zod10 = require("zod");
|
|
412
|
+
var ExactAmountSchema = import_zod10.z.string().regex(/^(0|[1-9]\d*)(?:\.\d{1,18})?$(?!\s)/).describe(
|
|
413
|
+
"Nonnegative amount in whole currency/token units, as a decimal string with at most 18 fractional digits and no scientific notation."
|
|
414
|
+
);
|
|
415
|
+
|
|
382
416
|
// src/charges.ts
|
|
383
|
-
var ChargeStatusSchema =
|
|
417
|
+
var ChargeStatusSchema = import_zod11.z.enum(["pending", "partially_paid", "confirmed", "expired", "underpaid"]).describe(
|
|
384
418
|
"Payment progress, from the payer side. `pending`: created, nothing received yet. `partially_paid`: some funds received, less than `amount`. `confirmed`: full amount received (or more \u2014 see `isOverpaid`). `expired`: `expiresAt` passed with zero funds received. `underpaid`: `expiresAt` passed while `partially_paid`. Every status is reached automatically, on its own timeline \u2014 there is no merchant-initiated cancellation. This never reflects whether funds actually reached the merchant \u2014 see `settlementStatus` for that."
|
|
385
419
|
);
|
|
386
|
-
var SettlementStatusSchema =
|
|
420
|
+
var SettlementStatusSchema = import_zod11.z.enum(["pending", "completed", "failed"]).describe(
|
|
387
421
|
"Progress of the payout to the merchant's wallet, a separate step from `status` \u2014 `status: confirmed` only means the payment was detected on-chain, not that the merchant has been paid yet. `pending`: payment detected, payout not yet attempted. `completed`: the merchant's wallet has the funds. `failed`: the payout attempt failed and retries were exhausted (rare; contact support). `null` on the parent `Charge` means no payout has been attempted yet \u2014 nothing has been received, or the charge is still in progress."
|
|
388
422
|
);
|
|
389
|
-
var ChargeFeePayerSchema =
|
|
423
|
+
var ChargeFeePayerSchema = import_zod11.z.enum(["merchant", "payer"]).describe(
|
|
390
424
|
"Who ends up covering Klappay's `feePercent`. `merchant` (default): `amount` is exactly what you asked for, and Klappay's fee is deducted from your own payout \u2014 you net `amount * (1 - feePercent / 100)`. `payer` : `amount` is grossed up at creation time so that, after the same fee deduction, you still net the amount you originally requested \u2014 the payer sees and sends the larger, fee-inclusive total. Frozen at creation like every other fee input; does not change how `feeAmount`/`merchantAmount` are computed on read, only what `amount` was set to in the first place."
|
|
391
425
|
);
|
|
392
426
|
var CHARGE_EXPIRES_IN_MIN_SECONDS = 60;
|
|
393
427
|
var CHARGE_EXPIRES_IN_MAX_SECONDS = 3600;
|
|
394
428
|
var CHARGE_ACCEPTED_PAYMENTS_MAX = 14;
|
|
395
|
-
var AcceptedPaymentSchema =
|
|
429
|
+
var AcceptedPaymentSchema = import_zod11.z.object({
|
|
396
430
|
token: TokenSchema,
|
|
397
431
|
network: NetworkSchema
|
|
398
432
|
});
|
|
399
|
-
var AcceptedPaymentsSchema =
|
|
433
|
+
var AcceptedPaymentsSchema = import_zod11.z.array(AcceptedPaymentSchema).min(1, "At least one accepted payment is required.").max(CHARGE_ACCEPTED_PAYMENTS_MAX).superRefine((pairs, ctx) => {
|
|
400
434
|
const seen = /* @__PURE__ */ new Set();
|
|
401
435
|
pairs.forEach((pair, index) => {
|
|
402
436
|
const key = `${pair.token}:${pair.network}`;
|
|
403
437
|
if (seen.has(key)) {
|
|
404
438
|
ctx.addIssue({
|
|
405
|
-
code:
|
|
439
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
406
440
|
message: `Duplicate accepted payment: ${pair.token} on ${pair.network}.`,
|
|
407
441
|
path: [index]
|
|
408
442
|
});
|
|
409
443
|
}
|
|
410
444
|
seen.add(key);
|
|
411
|
-
if (!OPERATIONAL_NETWORKS.
|
|
445
|
+
if (!OPERATIONAL_NETWORKS.some((network) => network === pair.network)) {
|
|
412
446
|
ctx.addIssue({
|
|
413
|
-
code:
|
|
447
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
414
448
|
message: `Network "${pair.network}" isn't live yet \u2014 only ${OPERATIONAL_NETWORKS.join(", ")} today.`,
|
|
415
449
|
path: [index, "network"]
|
|
416
450
|
});
|
|
@@ -420,32 +454,32 @@ var AcceptedPaymentsSchema = import_zod10.z.array(AcceptedPaymentSchema).min(1,
|
|
|
420
454
|
`Every \`(token, network)\` pair the payer is allowed to pay with \u2014 at least one, up to ${CHARGE_ACCEPTED_PAYMENTS_MAX}. This list is also the only restriction knob: the payer can use any combination of the pairs listed here, and every transfer on one of them is credited and sums toward the charge total (see \`paidWith\`) \u2014 e.g. a charge accepting USDC and USDT can be confirmed by $9 in USDC plus $1 in USDT, or by USDC arriving on two different accepted networks. To require payment in one specific token on one specific network, list only that single pair \u2014 a transfer on any pair not in this list is still recorded (for audit) but never credited. Each network must be live (see \`GET /v1/networks\` for the current matrix) \u2014 an unconfigured \`(token, network)\` combination for your environment is rejected with \`422 token_not_supported\`.`
|
|
421
455
|
);
|
|
422
456
|
var CHARGE_SPLIT_RECIPIENTS_MAX = 5;
|
|
423
|
-
var SplitRecipientSchema =
|
|
424
|
-
address:
|
|
425
|
-
percent:
|
|
457
|
+
var SplitRecipientSchema = import_zod11.z.object({
|
|
458
|
+
address: import_zod11.z.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe("EVM address to send a slice of this charge to."),
|
|
459
|
+
percent: import_zod11.z.number().positive().max(100).describe(
|
|
426
460
|
"Percent of *your own* net share (i.e. of `100 - feePercent`, not of the charge's gross `amount`) to route to this address instead of your own payout wallet. Klappay's fee is computed on the gross amount first and is never diluted by how you choose to split what's left \u2014 see `docs/payments.md`'s \"Settling the payout\" section for the exact math."
|
|
427
461
|
),
|
|
428
|
-
label:
|
|
462
|
+
label: import_zod11.z.string().min(1).max(64).optional().describe(
|
|
429
463
|
'Free-form label for your own bookkeeping (e.g. `"supplier"`, `"sales rep"`) \u2014 echoed back unchanged, never interpreted by Klappay.'
|
|
430
464
|
)
|
|
431
465
|
});
|
|
432
|
-
var SplitRecipientInputSchema =
|
|
433
|
-
recipientId:
|
|
466
|
+
var SplitRecipientInputSchema = import_zod11.z.object({
|
|
467
|
+
recipientId: import_zod11.z.string().describe(
|
|
434
468
|
"id of a `Recipient` you already registered via `POST /v1/recipients` (not a raw address) \u2014 see `recipients:write`/`charges:split_write` scopes. A leaked `charges:write`-only key can never redirect payout to a brand new address this way, only reference one already trusted."
|
|
435
469
|
),
|
|
436
|
-
percent:
|
|
470
|
+
percent: import_zod11.z.number().positive().max(100).describe(
|
|
437
471
|
"Percent of *your own* net share (i.e. of `100 - feePercent`, not of the charge's gross `amount`) to route to this recipient instead of your own payout wallet. Klappay's fee is computed on the gross amount first and is never diluted by how you choose to split what's left \u2014 see `docs/payments.md`'s \"Settling the payout\" section for the exact math."
|
|
438
472
|
),
|
|
439
|
-
label:
|
|
473
|
+
label: import_zod11.z.string().min(1).max(64).optional().describe(
|
|
440
474
|
'Free-form label for your own bookkeeping (e.g. `"supplier"`, `"sales rep"`) \u2014 echoed back unchanged, never interpreted by Klappay. Independent of the label the recipient was registered with.'
|
|
441
475
|
)
|
|
442
476
|
});
|
|
443
|
-
var SplitRecipientsInputSchema =
|
|
477
|
+
var SplitRecipientsInputSchema = import_zod11.z.array(SplitRecipientInputSchema).max(CHARGE_SPLIT_RECIPIENTS_MAX).superRefine((recipients, ctx) => {
|
|
444
478
|
const seen = /* @__PURE__ */ new Set();
|
|
445
479
|
recipients.forEach((recipient, index) => {
|
|
446
480
|
if (seen.has(recipient.recipientId)) {
|
|
447
481
|
ctx.addIssue({
|
|
448
|
-
code:
|
|
482
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
449
483
|
message: `Duplicate split recipientId: ${recipient.recipientId}.`,
|
|
450
484
|
path: [index, "recipientId"]
|
|
451
485
|
});
|
|
@@ -456,27 +490,27 @@ var SplitRecipientsInputSchema = import_zod10.z.array(SplitRecipientInputSchema)
|
|
|
456
490
|
`Optional extra recipients for this charge's split \u2014 e.g. a supplier or the sales rep who closed the deal \u2014 up to ${CHARGE_SPLIT_RECIPIENTS_MAX}, each referenced by \`recipientId\` (see \`POST /v1/recipients\`), never a raw address. Requires the \`charges:split_write\` scope in addition to \`charges:write\`. Frozen at creation exactly like everything else that shapes the split address; cannot be changed afterward. The sum of every \`percent\` here must fit within \`100 - feePercent\` (your own net share) \u2014 a request that doesn't is rejected with \`422 split_recipients_exceed_available_percent\`.`
|
|
457
491
|
);
|
|
458
492
|
var CHARGE_AMOUNT_MAX = 999999999999;
|
|
459
|
-
var CreateChargeSchema =
|
|
460
|
-
amount:
|
|
493
|
+
var CreateChargeSchema = import_zod11.z.object({
|
|
494
|
+
amount: import_zod11.z.number().positive().max(CHARGE_AMOUNT_MAX).describe(
|
|
461
495
|
"Amount to charge, in `currency` units (e.g. `49.9` = $49.90) \u2014 up to 6 decimal places; anything more precise is silently truncated. Required \u2014 every charge has a target amount, the first credited transfer that reaches it confirms the charge. With `feePayer: 'payer'` (see below), this is your own desired net amount, not the total the payer ends up sending \u2014 the response's `amount` is grossed up to cover `feePercent`, while `merchantAmount` on the response echoes back this exact value."
|
|
462
496
|
),
|
|
463
497
|
feePayer: ChargeFeePayerSchema.optional().default("merchant"),
|
|
464
|
-
currency:
|
|
498
|
+
currency: import_zod11.z.literal("USD").default("USD").describe("Always `USD` today \u2014 the only supported currency."),
|
|
465
499
|
acceptedPayments: AcceptedPaymentsSchema,
|
|
466
|
-
expiresIn:
|
|
500
|
+
expiresIn: import_zod11.z.number().int().min(CHARGE_EXPIRES_IN_MIN_SECONDS).max(CHARGE_EXPIRES_IN_MAX_SECONDS).describe(
|
|
467
501
|
"Seconds, not minutes or milliseconds \u2014 how long the charge stays open before it expires. Required, min 60, max 3600 (60 minutes) \u2014 sized off the slowest chain Klappay supports today (Ethereum mainnet, where a safely-confirmed transfer takes up to ~15 minutes), leaving real margin for payer-side delay (gas spikes, wallet friction) on top of that. Cannot be extended or shortened after creation."
|
|
468
502
|
),
|
|
469
|
-
idempotencyKey:
|
|
503
|
+
idempotencyKey: import_zod11.z.string().min(1).max(255).optional().describe(
|
|
470
504
|
"Scoped to your tenant. Replaying the same key with the exact same request body returns the original charge unchanged instead of creating a duplicate \u2014 safe to retry a request after a timeout without double-charging. Reusing the same key with a different body (including a different `escrow` config) is rejected with `409 idempotency_key_reused`, never silently returned as the original charge."
|
|
471
505
|
),
|
|
472
|
-
externalRef:
|
|
506
|
+
externalRef: import_zod11.z.string().min(1).max(255).optional().describe(
|
|
473
507
|
"An opaque correlation id from your own system (e.g. an order id) \u2014 echoed back on the charge and in every webhook payload. Not interpreted or validated by Klappay."
|
|
474
508
|
),
|
|
475
|
-
source:
|
|
509
|
+
source: import_zod11.z.string().min(1).max(64).optional().describe(
|
|
476
510
|
'Free-form label for what created this charge (e.g. `"checkout"`, `"invoice"`) \u2014 useful if you create charges from more than one flow and want to tell them apart later. Not a fixed enum; use whatever values make sense to you.'
|
|
477
511
|
),
|
|
478
512
|
metadata: MetadataWithKlappaySchema.optional(),
|
|
479
|
-
redirectUrl:
|
|
513
|
+
redirectUrl: import_zod11.z.string().url().refine((value) => /^https?:\/\//.test(value), "must use http or https").optional().describe(
|
|
480
514
|
"Where to send the payer once this charge resolves, if you use Klappay's hosted checkout page (see `checkoutUrl` on the read shape) \u2014 ignored otherwise. Must be `http(s)` \u2014 a browser will navigate here, so `javascript:`/`data:` and other non-navigational schemes are rejected. Otherwise not validated beyond being well-formed; what happens at that destination is yours to build."
|
|
481
515
|
),
|
|
482
516
|
splitRecipients: SplitRecipientsInputSchema.optional(),
|
|
@@ -484,77 +518,86 @@ var CreateChargeSchema = import_zod10.z.object({
|
|
|
484
518
|
"Configure this charge as an escrow instead of a normal payment. Funds land in a dedicated, non-custodial Safe (not the usual split address) and only `releaserAddress` (or, if omitted, your API key's own `payoutAddress`) can ever release them \u2014 via `POST /v1/charges/{id}/release`, signed on their end, never something Klappay can trigger or redirect. Omit this field entirely for a normal charge."
|
|
485
519
|
)
|
|
486
520
|
});
|
|
487
|
-
var ChargeSchema =
|
|
488
|
-
id:
|
|
489
|
-
amount:
|
|
490
|
-
"The
|
|
521
|
+
var ChargeSchema = import_zod11.z.object({
|
|
522
|
+
id: import_zod11.z.string().describe("Klappay-generated id, e.g. `ch_...`. Use this to look up the charge later."),
|
|
523
|
+
amount: import_zod11.z.number().describe(
|
|
524
|
+
"The total the payer must send, in `currency` units (up to 6 decimal places). This legacy JSON number can lose precision; use `amountExact` for calculations and payment preparation. With `feePayer: 'merchant'` (the default) this is what you requested at creation. With `feePayer: 'payer'` this is grossed up to cover `feePercent` \u2014 see `merchantAmount` for what you requested/will actually net."
|
|
525
|
+
),
|
|
526
|
+
amountExact: ExactAmountSchema.regex(/^(0|[1-9]\d*)(?:\.\d{1,6})?$/).optional().describe(
|
|
527
|
+
'Exact total the payer must send, in `currency` units, as a nonnegative decimal string with at most 6 fractional digits and no scientific notation (e.g. `"100.000001"`). Use this instead of `amount` for arithmetic. Optional for compatibility with older API responses.'
|
|
491
528
|
),
|
|
492
529
|
feePayer: ChargeFeePayerSchema,
|
|
493
|
-
feePercent:
|
|
530
|
+
feePercent: import_zod11.z.number().describe(
|
|
494
531
|
"Klappay's fee for this charge, as a percent of `amount` (e.g. `2` = 2%) \u2014 includes any escrow surcharge if this charge is an escrow. Frozen at creation; see `feeAmount`/`merchantAmount` for the actual amounts this works out to."
|
|
495
532
|
),
|
|
496
|
-
feeAmount:
|
|
497
|
-
merchantAmount:
|
|
533
|
+
feeAmount: import_zod11.z.number().describe("`amount * feePercent / 100`, in `currency` units \u2014 Klappay's cut of this charge."),
|
|
534
|
+
merchantAmount: import_zod11.z.number().describe(
|
|
498
535
|
"`amount - feeAmount`, in `currency` units \u2014 what you actually net once the payout settles, regardless of `feePayer` (this is always what the split delivers to you; `feePayer` only affects what `amount` was set to at creation)."
|
|
499
536
|
),
|
|
500
|
-
amountReceived:
|
|
501
|
-
"Cumulative amount
|
|
537
|
+
amountReceived: import_zod11.z.number().nullable().describe(
|
|
538
|
+
"Cumulative amount received on-chain so far, in `currency` units. This legacy JSON number can lose precision; use `amountReceivedExact` for arithmetic with up to 18 fractional digits. `null` until the first transfer arrives. Can exceed `amount` \u2014 see `isOverpaid`."
|
|
502
539
|
),
|
|
503
|
-
|
|
540
|
+
amountReceivedExact: ExactAmountSchema.nullable().optional().describe(
|
|
541
|
+
'Exact cumulative amount received on-chain, in `currency` units, as a nonnegative decimal string with at most 18 fractional digits and no scientific notation (e.g. `"0.0000000001"`). `null` until the first transfer arrives. Can exceed `amountExact`. Optional for compatibility with older API responses.'
|
|
542
|
+
),
|
|
543
|
+
paymentUnavailable: import_zod11.z.boolean().optional().describe(
|
|
544
|
+
"When `true`, payment processing for this charge is temporarily unavailable. Do not offer payment instructions, request another transfer, or fulfill from its monetary/status fields until availability is restored. The charge retains its existing business status. Optional for compatibility with older API responses."
|
|
545
|
+
),
|
|
546
|
+
isOverpaid: import_zod11.z.boolean().describe(
|
|
504
547
|
"`true` if `amountReceived` ended up greater than `amount`. Klappay never refunds the difference automatically \u2014 see the docs for why."
|
|
505
548
|
),
|
|
506
|
-
currency:
|
|
507
|
-
acceptedPayments:
|
|
549
|
+
currency: import_zod11.z.string().describe("Always `USD` today \u2014 the only supported currency."),
|
|
550
|
+
acceptedPayments: import_zod11.z.array(AcceptedPaymentSchema).describe(
|
|
508
551
|
"Every `(token, network)` pair this charge was configured to accept, unchanged after creation."
|
|
509
552
|
),
|
|
510
|
-
paidWith:
|
|
553
|
+
paidWith: import_zod11.z.array(AcceptedPaymentSchema).describe(
|
|
511
554
|
"Every distinct `(token, network)` pair that has actually contributed a credited transfer so far \u2014 empty until the first one arrives. Can hold more than one entry: a charge accepting several pairs can be paid across a combination of them, and every entry here sums toward `amountReceived`."
|
|
512
555
|
),
|
|
513
|
-
swapAlternatives:
|
|
556
|
+
swapAlternatives: import_zod11.z.array(SwapAlternativeSchema).describe(
|
|
514
557
|
"Every `(token, network)` pair the payer can pay with instead, via `POST /v1/charges/{id}/quote` \u2014 derived from the networks in `acceptedPayments` (e.g. a charge accepting USDC on both Base and Optimism lists `ETH` on Base and `ETH` on Optimism separately, since they're different networks the payer has to choose between, not one merged option). Pass an entry's `token`/`network` straight through as `inputToken`/`inputNetwork`. Recomputed on every read against Klappay's current trusted list, not frozen at creation \u2014 empty if this charge's networks have no trusted alt-token, if swap-to-pay isn't configured on this deployment, or if `environment` is `test` (0x, who powers the swap, has no testnet support at all \u2014 `POST /v1/charges/{id}/quote` always rejects a test-environment charge with `422 swap_test_environment_unsupported`)."
|
|
515
558
|
),
|
|
516
|
-
address:
|
|
559
|
+
address: import_zod11.z.string().describe(
|
|
517
560
|
"The on-chain address the payer must send funds to \u2014 identical across every accepted network (0xSplits addresses are chain-agnostic). Unique per charge, predicted at creation time \u2014 funds sent here go directly to the merchant, Klappay never custodies them."
|
|
518
561
|
),
|
|
519
562
|
status: ChargeStatusSchema,
|
|
520
563
|
settlementStatus: SettlementStatusSchema.nullable(),
|
|
521
564
|
environment: EnvironmentSchema,
|
|
522
|
-
apiKeyId:
|
|
565
|
+
apiKeyId: import_zod11.z.string().nullable().describe(
|
|
523
566
|
"Which of your API keys created this charge. `null` for a charge created before this field existed."
|
|
524
567
|
),
|
|
525
|
-
txHash:
|
|
568
|
+
txHash: import_zod11.z.string().nullable().describe(
|
|
526
569
|
"Transaction hash of the most recent transfer detected for this charge. `null` until a payment is detected."
|
|
527
570
|
),
|
|
528
|
-
externalRef:
|
|
529
|
-
source:
|
|
571
|
+
externalRef: import_zod11.z.string().nullable(),
|
|
572
|
+
source: import_zod11.z.string().nullable(),
|
|
530
573
|
metadata: MetadataWithKlappaySchema.nullable(),
|
|
531
|
-
redirectUrl:
|
|
532
|
-
checkoutUrl:
|
|
574
|
+
redirectUrl: import_zod11.z.string().nullable().describe("Echoes the `redirectUrl` set at creation, if any. `null` if none was set."),
|
|
575
|
+
checkoutUrl: import_zod11.z.string().nullable().describe(
|
|
533
576
|
"Link to Klappay's hosted checkout page for this charge. `null` if this deployment has no hosted checkout configured \u2014 build your own payment UI from `address`/`acceptedPayments` instead."
|
|
534
577
|
),
|
|
535
|
-
splitRecipients:
|
|
536
|
-
createdAt:
|
|
537
|
-
expiresAt:
|
|
578
|
+
splitRecipients: import_zod11.z.array(SplitRecipientSchema).describe("Echoes whatever extra split recipients were set at creation \u2014 empty array if none."),
|
|
579
|
+
createdAt: import_zod11.z.string().datetime(),
|
|
580
|
+
expiresAt: import_zod11.z.string().datetime().describe(
|
|
538
581
|
"When this charge stops accepting payment, if still `pending`/`partially_paid` by then."
|
|
539
582
|
),
|
|
540
|
-
confirmedAt:
|
|
541
|
-
settledAt:
|
|
583
|
+
confirmedAt: import_zod11.z.string().datetime().nullable().describe("When `status` first reached `confirmed`. `null` until then."),
|
|
584
|
+
settledAt: import_zod11.z.string().datetime().nullable().describe(
|
|
542
585
|
"When `settlementStatus` first reached `completed` \u2014 the merchant's wallet actually has the funds. `null` until then, including while `settlementStatus` is `pending`/`failed`."
|
|
543
586
|
),
|
|
544
|
-
lastActivityAt:
|
|
587
|
+
lastActivityAt: import_zod11.z.string().datetime().describe(
|
|
545
588
|
"When a transfer was last credited toward this charge, or `createdAt` if none has arrived yet."
|
|
546
589
|
),
|
|
547
|
-
escrow:
|
|
548
|
-
releaserAddress:
|
|
549
|
-
releasedAt:
|
|
550
|
-
refundedAt:
|
|
590
|
+
escrow: import_zod11.z.object({
|
|
591
|
+
releaserAddress: import_zod11.z.string().describe("The only address that can ever release this escrow \u2014 never Klappay."),
|
|
592
|
+
releasedAt: import_zod11.z.string().datetime().nullable().describe("When the release actually executed on-chain. `null` until then."),
|
|
593
|
+
refundedAt: import_zod11.z.string().datetime().nullable().describe(
|
|
551
594
|
"When the refund actually executed on-chain. `null` until then. Mutually exclusive with `releasedAt` \u2014 an escrow can only ever be released or refunded once, never both."
|
|
552
595
|
)
|
|
553
596
|
}).nullable().describe(
|
|
554
597
|
"Present only when this charge was created as an escrow (see `escrow` on the create request) \u2014 `null` for a normal charge."
|
|
555
598
|
)
|
|
556
599
|
});
|
|
557
|
-
var ListChargesSchema =
|
|
600
|
+
var ListChargesSchema = import_zod11.z.object({
|
|
558
601
|
status: ChargeStatusSchema.optional(),
|
|
559
602
|
token: TokenSchema.optional().describe(
|
|
560
603
|
"Filters on `paidWith.token` \u2014 the pair actually paid, not accepted."
|
|
@@ -563,13 +606,13 @@ var ListChargesSchema = import_zod10.z.object({
|
|
|
563
606
|
"Filters on `paidWith.network` \u2014 the pair actually paid, not accepted."
|
|
564
607
|
),
|
|
565
608
|
environment: EnvironmentSchema.optional(),
|
|
566
|
-
since:
|
|
609
|
+
since: import_zod11.z.string().datetime().optional().describe(
|
|
567
610
|
"Only return charges created at or after this timestamp (filters on `createdAt`, not on when the status last changed). If polling as a fallback for missed webhooks, use a window at least as wide as the longest `expiresIn` your charges use, or you can miss a long-lived charge that changed status outside a narrower window."
|
|
568
611
|
),
|
|
569
|
-
isOverpaid:
|
|
612
|
+
isOverpaid: import_zod11.z.enum(["true", "false"]).transform((v) => v === "true").optional()
|
|
570
613
|
}).extend(PaginationQuerySchema.shape);
|
|
571
614
|
var PaginatedChargesSchema = paginatedSchema(ChargeSchema);
|
|
572
|
-
var GetChargeQrCodeQuerySchema =
|
|
615
|
+
var GetChargeQrCodeQuerySchema = import_zod11.z.object({
|
|
573
616
|
token: TokenSchema.optional().describe(
|
|
574
617
|
"Which accepted `(token, network)` pair to encode in the QR \u2014 required if `acceptedPayments` has more than one pair, since there is no single unambiguous default to fall back to. Ignored (and unnecessary) when the charge accepts exactly one pair."
|
|
575
618
|
),
|
|
@@ -577,19 +620,19 @@ var GetChargeQrCodeQuerySchema = import_zod10.z.object({
|
|
|
577
620
|
});
|
|
578
621
|
|
|
579
622
|
// src/charge-check.ts
|
|
580
|
-
var
|
|
623
|
+
var import_zod13 = require("zod");
|
|
581
624
|
|
|
582
625
|
// src/confirmation-progress.ts
|
|
583
|
-
var
|
|
584
|
-
var ConfirmationProgressSchema =
|
|
626
|
+
var import_zod12 = require("zod");
|
|
627
|
+
var ConfirmationProgressSchema = import_zod12.z.object({
|
|
585
628
|
network: NetworkSchema.describe("Which network the transfer was seen on."),
|
|
586
|
-
blocksSeen:
|
|
629
|
+
blocksSeen: import_zod12.z.number().int().min(0).describe(
|
|
587
630
|
"How many blocks have passed since the transfer's own block, as of this update \u2014 a raw block count, not seconds. Grows toward `blocksRequired` as the network's blocks keep arriving."
|
|
588
631
|
),
|
|
589
|
-
blocksRequired:
|
|
632
|
+
blocksRequired: import_zod12.z.number().int().min(1).describe(
|
|
590
633
|
"This network's minimum confirmation depth (a fixed, per-network constant) \u2014 the transfer is only credited once `blocksSeen` reaches this value."
|
|
591
634
|
),
|
|
592
|
-
percent:
|
|
635
|
+
percent: import_zod12.z.number().int().min(0).max(99).describe(
|
|
593
636
|
'`blocksSeen`/`blocksRequired` as a rounded-down 0-99 percentage, for a progress bar. Never reaches 100 by construction \u2014 once a transfer is deep enough it is credited immediately and this stops being reported at all (the charge event itself is the "done" signal).'
|
|
594
637
|
)
|
|
595
638
|
}).describe(
|
|
@@ -597,8 +640,8 @@ var ConfirmationProgressSchema = import_zod11.z.object({
|
|
|
597
640
|
);
|
|
598
641
|
|
|
599
642
|
// src/charge-check.ts
|
|
600
|
-
var CheckChargeRequestSchema =
|
|
601
|
-
txHash:
|
|
643
|
+
var CheckChargeRequestSchema = import_zod13.z.object({
|
|
644
|
+
txHash: import_zod13.z.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be a 32-byte transaction hash").optional().describe(
|
|
602
645
|
"The on-chain transaction hash to verify directly, if you already have it \u2014 e.g. right after a swap-to-pay or wallet-connect transaction is sent. Costs a single RPC call instead of scanning a block range, so the check resolves faster and cheaper. Omit to fall back to scanning recent transfers to this charge's address, the same lookup the background reconciliation pass runs. Never trusted at face value \u2014 whatever this transaction actually contains on-chain is what gets credited, regardless of any amount/token implied elsewhere."
|
|
603
646
|
),
|
|
604
647
|
network: NetworkSchema.optional().describe(
|
|
@@ -608,7 +651,7 @@ var CheckChargeRequestSchema = import_zod12.z.object({
|
|
|
608
651
|
message: "`txHash` and `network` must be provided together, or both omitted"
|
|
609
652
|
});
|
|
610
653
|
var CheckChargeResponseSchema = ChargeSchema.extend({
|
|
611
|
-
transactionSender:
|
|
654
|
+
transactionSender: import_zod13.z.string().nullable().describe(
|
|
612
655
|
"The `txHash` transaction's own sender (`from`) \u2014 who actually signed and submitted it on-chain, which stays the payer's own wallet even when the transaction swaps through a router/aggregator on the way to paying, unlike the credited transfer's `from` (which can be the router/pool contract, not the payer). `null` unless `txHash`/`network` was passed in the request and a successful receipt was found for it \u2014 a hint-less background scan, an unaccepted network, or a not-found/reverted transaction all leave this `null`."
|
|
613
656
|
),
|
|
614
657
|
confirmationProgress: ConfirmationProgressSchema.nullable().describe(
|
|
@@ -617,61 +660,61 @@ var CheckChargeResponseSchema = ChargeSchema.extend({
|
|
|
617
660
|
});
|
|
618
661
|
|
|
619
662
|
// src/distributions.ts
|
|
620
|
-
var
|
|
621
|
-
var SplitDistributionStatusSchema =
|
|
663
|
+
var import_zod14 = require("zod");
|
|
664
|
+
var SplitDistributionStatusSchema = import_zod14.z.enum(["pending", "processing", "completed", "failed"]).describe(
|
|
622
665
|
"Status of one payout attempt to the merchant, for a single `(token, network)` pair \u2014 a charge that settles across more than one pair has one of these per pair. `pending`: queued, not yet claimed by a distributor. `processing`: a distributor (Klappay's own worker, or anyone racing to call `distribute()` first, see `PendingDistributionSchema`) has claimed it and is submitting the on-chain transaction. `completed`: the merchant's wallet has the funds. `failed`: every automatic retry was exhausted."
|
|
623
666
|
);
|
|
624
|
-
var PendingDistributionRecipientSchema =
|
|
625
|
-
address:
|
|
626
|
-
percentAllocation:
|
|
667
|
+
var PendingDistributionRecipientSchema = import_zod14.z.object({
|
|
668
|
+
address: import_zod14.z.string().describe("On-chain recipient address."),
|
|
669
|
+
percentAllocation: import_zod14.z.number().describe("This recipient's share of the split, as a percentage (e.g. `99.0991` = 99.0991%).")
|
|
627
670
|
});
|
|
628
|
-
var PendingDistributionSchema =
|
|
629
|
-
splitAddress:
|
|
671
|
+
var PendingDistributionSchema = import_zod14.z.object({
|
|
672
|
+
splitAddress: import_zod14.z.string().describe("The on-chain 0xSplits address to call `distribute()` on."),
|
|
630
673
|
network: NetworkSchema,
|
|
631
674
|
token: TokenSchema,
|
|
632
|
-
recipients:
|
|
675
|
+
recipients: import_zod14.z.array(PendingDistributionRecipientSchema).describe(
|
|
633
676
|
"The exact recipient list to pass to `distribute()` \u2014 the split contract only stores a hash of this config, so the caller must supply the identical array to prove it matches. Always present, never reconstructed from partial data."
|
|
634
677
|
),
|
|
635
|
-
distributorFeePercent:
|
|
678
|
+
distributorFeePercent: import_zod14.z.number().describe(
|
|
636
679
|
"Percentage of the split balance paid to whoever calls `distribute()` first (e.g. `0.1` = 0.1%). Frozen at charge creation, same for every distribution today."
|
|
637
680
|
),
|
|
638
|
-
estimatedRewardAmount:
|
|
681
|
+
estimatedRewardAmount: import_zod14.z.number().describe(
|
|
639
682
|
"Estimate only, in the charge's `currency` units, based on the amount Klappay detected on-chain \u2014 not a live read of the split's current balance. Read the balance yourself before submitting a transaction; a stale estimate is harmless (see the docs), never a reason to skip that check."
|
|
640
683
|
),
|
|
641
|
-
availableSince:
|
|
642
|
-
graceEndsAt:
|
|
684
|
+
availableSince: import_zod14.z.string().datetime().describe("When this distribution entered its grace period."),
|
|
685
|
+
graceEndsAt: import_zod14.z.string().datetime().describe(
|
|
643
686
|
"When Klappay's own worker may claim this distribution. Racing to call `distribute()` after this timestamp is possible but increasingly likely to lose to the worker."
|
|
644
687
|
)
|
|
645
688
|
});
|
|
646
689
|
var PaginatedPendingDistributionsSchema = paginatedSchema(PendingDistributionSchema);
|
|
647
|
-
var ListenPendingDistributionsQuerySchema =
|
|
648
|
-
limit:
|
|
690
|
+
var ListenPendingDistributionsQuerySchema = import_zod14.z.object({
|
|
691
|
+
limit: import_zod14.z.coerce.number().int().min(0).max(PAGINATION_LIMIT_MAX).default(0).describe(
|
|
649
692
|
"How many currently-claimable distributions to emit as an initial snapshot right after connecting \u2014 each as a synthetic `distribution.available` event \u2014 before continuing with real-time deltas. `0` (the default, same as omitting it) sends no snapshot at all, matching this endpoint's original behavior: connect first, then call `GET /v1/distributions/pending` yourself to bootstrap. Not a page \u2014 there is no cursor for this snapshot, so if more than `limit` are claimable at connect time, the excess is simply not sent; call `GET /v1/distributions/pending` directly for a complete, paginated listing."
|
|
650
693
|
)
|
|
651
694
|
});
|
|
652
|
-
var PendingDistributionEventSchema =
|
|
653
|
-
|
|
654
|
-
type:
|
|
695
|
+
var PendingDistributionEventSchema = import_zod14.z.discriminatedUnion("type", [
|
|
696
|
+
import_zod14.z.object({
|
|
697
|
+
type: import_zod14.z.literal("distribution.available"),
|
|
655
698
|
distribution: PendingDistributionSchema
|
|
656
699
|
}),
|
|
657
|
-
|
|
658
|
-
type:
|
|
659
|
-
splitAddress:
|
|
700
|
+
import_zod14.z.object({
|
|
701
|
+
type: import_zod14.z.literal("distribution.claimed"),
|
|
702
|
+
splitAddress: import_zod14.z.string().describe("No longer claimable \u2014 either settled by someone, or picked up by the worker.")
|
|
660
703
|
})
|
|
661
704
|
]);
|
|
662
705
|
|
|
663
706
|
// src/metrics.ts
|
|
664
|
-
var
|
|
665
|
-
var MetricsResourceSchema =
|
|
707
|
+
var import_zod15 = require("zod");
|
|
708
|
+
var MetricsResourceSchema = import_zod15.z.enum(["charges", "transactions", "distributions"]).describe(
|
|
666
709
|
"Which underlying dataset to query. `charges`: one row per charge. `transactions`: one row per detected on-chain transfer \u2014 a charge paid in installments has more than one. `distributions`: one row per payout attempt to the merchant, one per `(token, network)` pair a charge settled across."
|
|
667
710
|
);
|
|
668
|
-
var MetricsAggregationSchema =
|
|
711
|
+
var MetricsAggregationSchema = import_zod15.z.enum(["count", "sum", "avg", "min", "max"]).describe(
|
|
669
712
|
"`count` counts matching rows and never takes `field`. `sum`/`avg`/`min`/`max` require `field` to be set to one of the resource\u2019s numeric fields."
|
|
670
713
|
);
|
|
671
|
-
var MetricsFilterOperatorSchema =
|
|
714
|
+
var MetricsFilterOperatorSchema = import_zod15.z.enum(["eq", "neq", "in", "gt", "gte", "lt", "lte"]).describe(
|
|
672
715
|
"`in` expects an array value (max 50 entries); every other operator expects a single scalar."
|
|
673
716
|
);
|
|
674
|
-
var MetricsDateGranularitySchema =
|
|
717
|
+
var MetricsDateGranularitySchema = import_zod15.z.enum(["day", "week", "month", "year"]).describe(
|
|
675
718
|
"Bucket width for a `date_bucket` `groupBy` entry \u2014 Postgres `date_trunc` semantics (UTC)."
|
|
676
719
|
);
|
|
677
720
|
var metricsQueryEnvironmentSchema = EnvironmentSchema.describe(
|
|
@@ -684,31 +727,31 @@ var METRICS_QUERY_MAX_GROUP_BY = 3;
|
|
|
684
727
|
var METRICS_QUERY_MAX_FILTERS = 20;
|
|
685
728
|
var METRICS_QUERY_MAX_METRICS = 10;
|
|
686
729
|
var METRIC_ALIAS_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
687
|
-
var metricAliasSchema =
|
|
730
|
+
var metricAliasSchema = import_zod15.z.string().min(1).max(64).regex(
|
|
688
731
|
METRIC_ALIAS_PATTERN,
|
|
689
732
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 this becomes a SQL column alias."
|
|
690
733
|
).optional();
|
|
691
|
-
var MetricsFilterValueSchema =
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
734
|
+
var MetricsFilterValueSchema = import_zod15.z.union([
|
|
735
|
+
import_zod15.z.string().max(255),
|
|
736
|
+
import_zod15.z.number(),
|
|
737
|
+
import_zod15.z.boolean(),
|
|
738
|
+
import_zod15.z.array(import_zod15.z.union([import_zod15.z.string().max(255), import_zod15.z.number()])).min(1).max(50)
|
|
696
739
|
]);
|
|
697
|
-
var orderBySchema =
|
|
698
|
-
key:
|
|
740
|
+
var orderBySchema = import_zod15.z.object({
|
|
741
|
+
key: import_zod15.z.string().min(1).max(64).regex(
|
|
699
742
|
METRIC_ALIAS_PATTERN,
|
|
700
743
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 every valid output column name already looks like this."
|
|
701
744
|
).describe(
|
|
702
745
|
"An output column name from this same query \u2014 either a `groupBy` field name, or a metric\u2019s `alias` (or its default name: `${aggregation}` for `count`, `${aggregation}_${field}` otherwise, e.g. `sum_amount`). Must match `^[a-zA-Z_][a-zA-Z0-9_]*$` \u2014 every real output column name already does, so this only ever rejects a value that could never have been one."
|
|
703
746
|
),
|
|
704
|
-
direction:
|
|
747
|
+
direction: import_zod15.z.enum(["asc", "desc"])
|
|
705
748
|
}).describe(
|
|
706
749
|
"Sort the result rows by any output column \u2014 including the bucket field itself for a `date_bucket` query (e.g. `createdAt`). Omit to get ascending-by-bucket order for a date-bucketed query, or implementation-defined (not guaranteed stable) order otherwise."
|
|
707
750
|
);
|
|
708
|
-
var limitSchema =
|
|
751
|
+
var limitSchema = import_zod15.z.number().int().min(1).max(METRICS_QUERY_MAX_ROW_LIMIT).default(METRICS_QUERY_DEFAULT_ROW_LIMIT).describe(
|
|
709
752
|
`Max rows to return, ${1}\u2013${METRICS_QUERY_MAX_ROW_LIMIT}, default ${METRICS_QUERY_DEFAULT_ROW_LIMIT}. If more rows matched, \`meta.truncated\` is \`true\` on the response \u2014 narrow the query instead of just raising this.`
|
|
710
753
|
);
|
|
711
|
-
var ChargesQueryFieldSchema =
|
|
754
|
+
var ChargesQueryFieldSchema = import_zod15.z.enum([
|
|
712
755
|
"status",
|
|
713
756
|
"source",
|
|
714
757
|
"apiKeyId",
|
|
@@ -719,124 +762,124 @@ var ChargesQueryFieldSchema = import_zod14.z.enum([
|
|
|
719
762
|
]).describe(
|
|
720
763
|
"A `Charge` field to filter or group by \u2014 see `ChargeStatusSchema` for `status`'s own possible values (charges.md). `source`/`externalRef` are free-form strings your own integration set at creation, not a fixed enum. `escrowReleaserAddress` is `null` for a normal charge \u2014 filter `escrowReleaserAddress` with operator `neq`/value `null` to isolate escrow-configured charges (see `escrow` in charges.md)."
|
|
721
764
|
);
|
|
722
|
-
var ChargesMetricFieldSchema =
|
|
765
|
+
var ChargesMetricFieldSchema = import_zod15.z.enum(["amount", "amountReceived", "feePercent", "escrowFeePercent"]).describe(
|
|
723
766
|
"A `Charge` numeric field to aggregate. `amount`/`amountReceived` are decimal currency amounts (requested vs. actually received \u2014 see `charges.md`). `feePercent` is the platform fee frozen on the charge at creation, e.g. `1.5` means 1.5%. `escrowFeePercent` is the additional escrow-specific fee component, only present on escrow-configured charges \u2014 see `docs/payments.md`."
|
|
724
767
|
);
|
|
725
|
-
var ChargesDateFieldSchema =
|
|
768
|
+
var ChargesDateFieldSchema = import_zod15.z.enum(["createdAt", "confirmedAt", "lastActivityAt", "expiresAt", "escrowReleasedAt"]).describe(
|
|
726
769
|
"A `Charge` timestamp to filter/bucket by. `confirmedAt` is `null` until the charge reaches `confirmed` \u2014 a `dateRange`/`date_bucket` on it implicitly excludes every charge that never confirmed. `expiresAt` is always present (set at creation), useful for e.g. finding charges expiring soon or measuring how close to expiry charges typically resolve. `escrowReleasedAt` is `null` until an escrow-configured charge is actually released \u2014 same implicit-exclusion behavior as `confirmedAt`, scoped to escrow charges only."
|
|
727
770
|
);
|
|
728
|
-
var ChargesFilterSchema =
|
|
771
|
+
var ChargesFilterSchema = import_zod15.z.object({
|
|
729
772
|
field: ChargesQueryFieldSchema,
|
|
730
773
|
operator: MetricsFilterOperatorSchema,
|
|
731
774
|
value: MetricsFilterValueSchema
|
|
732
775
|
});
|
|
733
|
-
var ChargesGroupBySchema =
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
type:
|
|
776
|
+
var ChargesGroupBySchema = import_zod15.z.union([
|
|
777
|
+
import_zod15.z.object({ type: import_zod15.z.literal("field"), field: ChargesQueryFieldSchema }),
|
|
778
|
+
import_zod15.z.object({
|
|
779
|
+
type: import_zod15.z.literal("date_bucket"),
|
|
737
780
|
field: ChargesDateFieldSchema,
|
|
738
781
|
granularity: MetricsDateGranularitySchema
|
|
739
782
|
})
|
|
740
783
|
]);
|
|
741
|
-
var ChargesMetricSchema =
|
|
784
|
+
var ChargesMetricSchema = import_zod15.z.object({
|
|
742
785
|
aggregation: MetricsAggregationSchema,
|
|
743
786
|
field: ChargesMetricFieldSchema.optional(),
|
|
744
787
|
alias: metricAliasSchema
|
|
745
788
|
});
|
|
746
|
-
var ChargesMetricsQuerySchema =
|
|
747
|
-
resource:
|
|
789
|
+
var ChargesMetricsQuerySchema = import_zod15.z.object({
|
|
790
|
+
resource: import_zod15.z.literal("charges"),
|
|
748
791
|
environment: metricsQueryEnvironmentSchema,
|
|
749
|
-
dateRange:
|
|
792
|
+
dateRange: import_zod15.z.object({
|
|
750
793
|
field: ChargesDateFieldSchema,
|
|
751
|
-
from:
|
|
752
|
-
to:
|
|
794
|
+
from: import_zod15.z.string().max(64).datetime(),
|
|
795
|
+
to: import_zod15.z.string().max(64).datetime()
|
|
753
796
|
}),
|
|
754
|
-
groupBy:
|
|
755
|
-
metrics:
|
|
756
|
-
filters:
|
|
797
|
+
groupBy: import_zod15.z.array(ChargesGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
798
|
+
metrics: import_zod15.z.array(ChargesMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
799
|
+
filters: import_zod15.z.array(ChargesFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
757
800
|
orderBy: orderBySchema.optional(),
|
|
758
801
|
limit: limitSchema
|
|
759
802
|
});
|
|
760
|
-
var TransactionsQueryFieldSchema =
|
|
803
|
+
var TransactionsQueryFieldSchema = import_zod15.z.enum(["network", "token", "source", "causedTransition"]).describe(
|
|
761
804
|
"A `Transaction` field to filter or group by \u2014 see `NetworkSchema`/`TokenSchema`/`TransactionSourceSchema` for their possible values. `causedTransition` is `true` only for the transfer(s) that actually flipped the charge's `status` \u2014 a charge paid in installments can have more than one; filtering/grouping on it excludes no-op duplicate transfers (see `TimelineEvent.causedTransition` in charges.md for the full explanation)."
|
|
762
805
|
);
|
|
763
|
-
var TransactionsMetricFieldSchema =
|
|
764
|
-
var TransactionsDateFieldSchema =
|
|
765
|
-
var TransactionsFilterSchema =
|
|
806
|
+
var TransactionsMetricFieldSchema = import_zod15.z.enum(["amount"]).describe("The transfer amount, in the charge's `currency` units.");
|
|
807
|
+
var TransactionsDateFieldSchema = import_zod15.z.enum(["detectedAt"]).describe("When Klappay detected this transfer on-chain (not when it was mined).");
|
|
808
|
+
var TransactionsFilterSchema = import_zod15.z.object({
|
|
766
809
|
field: TransactionsQueryFieldSchema,
|
|
767
810
|
operator: MetricsFilterOperatorSchema,
|
|
768
811
|
value: MetricsFilterValueSchema
|
|
769
812
|
});
|
|
770
|
-
var TransactionsGroupBySchema =
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
type:
|
|
813
|
+
var TransactionsGroupBySchema = import_zod15.z.union([
|
|
814
|
+
import_zod15.z.object({ type: import_zod15.z.literal("field"), field: TransactionsQueryFieldSchema }),
|
|
815
|
+
import_zod15.z.object({
|
|
816
|
+
type: import_zod15.z.literal("date_bucket"),
|
|
774
817
|
field: TransactionsDateFieldSchema,
|
|
775
818
|
granularity: MetricsDateGranularitySchema
|
|
776
819
|
})
|
|
777
820
|
]);
|
|
778
|
-
var TransactionsMetricSchema =
|
|
821
|
+
var TransactionsMetricSchema = import_zod15.z.object({
|
|
779
822
|
aggregation: MetricsAggregationSchema,
|
|
780
823
|
field: TransactionsMetricFieldSchema.optional(),
|
|
781
824
|
alias: metricAliasSchema
|
|
782
825
|
});
|
|
783
|
-
var TransactionsMetricsQuerySchema =
|
|
784
|
-
resource:
|
|
826
|
+
var TransactionsMetricsQuerySchema = import_zod15.z.object({
|
|
827
|
+
resource: import_zod15.z.literal("transactions"),
|
|
785
828
|
environment: metricsQueryEnvironmentSchema,
|
|
786
|
-
dateRange:
|
|
829
|
+
dateRange: import_zod15.z.object({
|
|
787
830
|
field: TransactionsDateFieldSchema,
|
|
788
|
-
from:
|
|
789
|
-
to:
|
|
831
|
+
from: import_zod15.z.string().max(64).datetime(),
|
|
832
|
+
to: import_zod15.z.string().max(64).datetime()
|
|
790
833
|
}),
|
|
791
|
-
groupBy:
|
|
792
|
-
metrics:
|
|
793
|
-
filters:
|
|
834
|
+
groupBy: import_zod15.z.array(TransactionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
835
|
+
metrics: import_zod15.z.array(TransactionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
836
|
+
filters: import_zod15.z.array(TransactionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
794
837
|
orderBy: orderBySchema.optional(),
|
|
795
838
|
limit: limitSchema
|
|
796
839
|
});
|
|
797
|
-
var DistributionsQueryFieldSchema =
|
|
840
|
+
var DistributionsQueryFieldSchema = import_zod15.z.enum(["status", "network", "token", "distributorAddress"]).describe(
|
|
798
841
|
"A `SplitDistribution` field to filter or group by \u2014 see `SplitDistributionStatusSchema`/`NetworkSchema`/`TokenSchema` for their possible values. `distributorAddress` is the public on-chain address that actually called `distribute()` for a `completed` distribution \u2014 Klappay's own operator address if settled by Klappay's own worker, a community keeper's address if settled externally (or `null` on the rare case that lookup failed), `null` for every non-`completed` status."
|
|
799
842
|
);
|
|
800
|
-
var DistributionsMetricFieldSchema =
|
|
843
|
+
var DistributionsMetricFieldSchema = import_zod15.z.enum(["attempts"]).describe(
|
|
801
844
|
"How many times a payout was attempted for this settlement so far \u2014 incremented on every attempt, whether it succeeded or is being retried after failing. A high `attempts` alongside `status: 'failed'` means every automatic retry was exhausted."
|
|
802
845
|
);
|
|
803
|
-
var DistributionsDateFieldSchema =
|
|
846
|
+
var DistributionsDateFieldSchema = import_zod15.z.enum(["createdAt", "processingStartedAt", "completedAt"]).describe(
|
|
804
847
|
"`createdAt`: when this settlement was queued. `processingStartedAt`: when a worker began its most recent attempt at the payout \u2014 `null` until the first attempt, then overwritten on every subsequent retry, so it reflects the *latest* attempt's start, not the first. `completedAt`: when it actually paid out \u2014 `null` until `status` reaches `completed`, so a `dateRange`/`date_bucket` on it implicitly excludes every distribution still pending/processing/failed."
|
|
805
848
|
);
|
|
806
|
-
var DistributionsFilterSchema =
|
|
849
|
+
var DistributionsFilterSchema = import_zod15.z.object({
|
|
807
850
|
field: DistributionsQueryFieldSchema,
|
|
808
851
|
operator: MetricsFilterOperatorSchema,
|
|
809
852
|
value: MetricsFilterValueSchema
|
|
810
853
|
});
|
|
811
|
-
var DistributionsGroupBySchema =
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
type:
|
|
854
|
+
var DistributionsGroupBySchema = import_zod15.z.union([
|
|
855
|
+
import_zod15.z.object({ type: import_zod15.z.literal("field"), field: DistributionsQueryFieldSchema }),
|
|
856
|
+
import_zod15.z.object({
|
|
857
|
+
type: import_zod15.z.literal("date_bucket"),
|
|
815
858
|
field: DistributionsDateFieldSchema,
|
|
816
859
|
granularity: MetricsDateGranularitySchema
|
|
817
860
|
})
|
|
818
861
|
]);
|
|
819
|
-
var DistributionsMetricSchema =
|
|
862
|
+
var DistributionsMetricSchema = import_zod15.z.object({
|
|
820
863
|
aggregation: MetricsAggregationSchema,
|
|
821
864
|
field: DistributionsMetricFieldSchema.optional(),
|
|
822
865
|
alias: metricAliasSchema
|
|
823
866
|
});
|
|
824
|
-
var DistributionsMetricsQuerySchema =
|
|
825
|
-
resource:
|
|
867
|
+
var DistributionsMetricsQuerySchema = import_zod15.z.object({
|
|
868
|
+
resource: import_zod15.z.literal("distributions"),
|
|
826
869
|
environment: metricsQueryEnvironmentSchema,
|
|
827
|
-
dateRange:
|
|
870
|
+
dateRange: import_zod15.z.object({
|
|
828
871
|
field: DistributionsDateFieldSchema,
|
|
829
|
-
from:
|
|
830
|
-
to:
|
|
872
|
+
from: import_zod15.z.string().max(64).datetime(),
|
|
873
|
+
to: import_zod15.z.string().max(64).datetime()
|
|
831
874
|
}),
|
|
832
|
-
groupBy:
|
|
833
|
-
metrics:
|
|
834
|
-
filters:
|
|
875
|
+
groupBy: import_zod15.z.array(DistributionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
876
|
+
metrics: import_zod15.z.array(DistributionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
877
|
+
filters: import_zod15.z.array(DistributionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
835
878
|
orderBy: orderBySchema.optional(),
|
|
836
879
|
limit: limitSchema
|
|
837
880
|
});
|
|
838
881
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
839
|
-
var MetricsQuerySchema =
|
|
882
|
+
var MetricsQuerySchema = import_zod15.z.discriminatedUnion("resource", [
|
|
840
883
|
ChargesMetricsQuerySchema,
|
|
841
884
|
TransactionsMetricsQuerySchema,
|
|
842
885
|
DistributionsMetricsQuerySchema
|
|
@@ -845,7 +888,7 @@ var MetricsQuerySchema = import_zod14.z.discriminatedUnion("resource", [
|
|
|
845
888
|
const to = new Date(input.dateRange.to);
|
|
846
889
|
if (from >= to) {
|
|
847
890
|
ctx.addIssue({
|
|
848
|
-
code:
|
|
891
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
849
892
|
message: "`dateRange.from` must be before `dateRange.to`.",
|
|
850
893
|
path: ["dateRange", "from"]
|
|
851
894
|
});
|
|
@@ -853,7 +896,7 @@ var MetricsQuerySchema = import_zod14.z.discriminatedUnion("resource", [
|
|
|
853
896
|
const spanDays = (to.getTime() - from.getTime()) / ONE_DAY_MS;
|
|
854
897
|
if (spanDays > MAX_METRICS_QUERY_DATE_RANGE_DAYS) {
|
|
855
898
|
ctx.addIssue({
|
|
856
|
-
code:
|
|
899
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
857
900
|
message: `\`dateRange\` cannot span more than ${MAX_METRICS_QUERY_DATE_RANGE_DAYS} days.`,
|
|
858
901
|
path: ["dateRange", "to"]
|
|
859
902
|
});
|
|
@@ -861,7 +904,7 @@ var MetricsQuerySchema = import_zod14.z.discriminatedUnion("resource", [
|
|
|
861
904
|
const dateBucketCount = input.groupBy.filter((entry) => entry.type === "date_bucket").length;
|
|
862
905
|
if (dateBucketCount > 1) {
|
|
863
906
|
ctx.addIssue({
|
|
864
|
-
code:
|
|
907
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
865
908
|
message: "At most one `date_bucket` entry is allowed in `groupBy`.",
|
|
866
909
|
path: ["groupBy"]
|
|
867
910
|
});
|
|
@@ -869,7 +912,7 @@ var MetricsQuerySchema = import_zod14.z.discriminatedUnion("resource", [
|
|
|
869
912
|
input.metrics.forEach((metric, index) => {
|
|
870
913
|
if (metric.aggregation !== "count" && metric.field === void 0) {
|
|
871
914
|
ctx.addIssue({
|
|
872
|
-
code:
|
|
915
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
873
916
|
message: "`field` is required unless `aggregation` is `count`.",
|
|
874
917
|
path: ["metrics", index, "field"]
|
|
875
918
|
});
|
|
@@ -878,7 +921,7 @@ var MetricsQuerySchema = import_zod14.z.discriminatedUnion("resource", [
|
|
|
878
921
|
const aliases = input.metrics.map((metric) => metric.alias).filter((alias) => alias !== void 0);
|
|
879
922
|
if (new Set(aliases).size !== aliases.length) {
|
|
880
923
|
ctx.addIssue({
|
|
881
|
-
code:
|
|
924
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
882
925
|
message: "Every `metrics[].alias` must be unique.",
|
|
883
926
|
path: ["metrics"]
|
|
884
927
|
});
|
|
@@ -887,32 +930,32 @@ var MetricsQuerySchema = import_zod14.z.discriminatedUnion("resource", [
|
|
|
887
930
|
input.metrics.forEach((metric, index) => {
|
|
888
931
|
if (metric.alias !== void 0 && reservedNames.has(metric.alias)) {
|
|
889
932
|
ctx.addIssue({
|
|
890
|
-
code:
|
|
933
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
891
934
|
message: `\`alias\` "${metric.alias}" collides with a \`groupBy\` field name (or the reserved word "bucket") \u2014 choose a different alias.`,
|
|
892
935
|
path: ["metrics", index, "alias"]
|
|
893
936
|
});
|
|
894
937
|
}
|
|
895
938
|
});
|
|
896
939
|
});
|
|
897
|
-
var MetricsQueryResultRowSchema =
|
|
898
|
-
|
|
899
|
-
|
|
940
|
+
var MetricsQueryResultRowSchema = import_zod15.z.record(
|
|
941
|
+
import_zod15.z.string(),
|
|
942
|
+
import_zod15.z.union([import_zod15.z.string(), import_zod15.z.number(), import_zod15.z.boolean(), import_zod15.z.null()])
|
|
900
943
|
);
|
|
901
|
-
var MetricsQueryResultSchema =
|
|
902
|
-
data:
|
|
903
|
-
meta:
|
|
944
|
+
var MetricsQueryResultSchema = import_zod15.z.object({
|
|
945
|
+
data: import_zod15.z.array(MetricsQueryResultRowSchema),
|
|
946
|
+
meta: import_zod15.z.object({
|
|
904
947
|
resource: MetricsResourceSchema,
|
|
905
948
|
environment: EnvironmentSchema,
|
|
906
|
-
rowCount:
|
|
907
|
-
truncated:
|
|
949
|
+
rowCount: import_zod15.z.number().int().describe("Number of rows in `data`."),
|
|
950
|
+
truncated: import_zod15.z.boolean().describe(
|
|
908
951
|
"`true` if more rows matched than `limit` allowed \u2014 `data` holds only the first `limit`."
|
|
909
952
|
)
|
|
910
953
|
})
|
|
911
954
|
});
|
|
912
955
|
|
|
913
956
|
// src/webhook-events.ts
|
|
914
|
-
var
|
|
915
|
-
var ChargeWebhookEventTypeSchema =
|
|
957
|
+
var import_zod16 = require("zod");
|
|
958
|
+
var ChargeWebhookEventTypeSchema = import_zod16.z.enum([
|
|
916
959
|
"charge.created",
|
|
917
960
|
"charge.partially_paid",
|
|
918
961
|
"charge.confirmed",
|
|
@@ -926,14 +969,14 @@ var ChargeWebhookEventTypeSchema = import_zod15.z.enum([
|
|
|
926
969
|
]).describe(
|
|
927
970
|
'Note the distinction between `charge.confirmed` and `charge.settled`: `confirmed` means the payment was detected on-chain; `settled` means the merchant\'s wallet actually received the funds \u2014 a separate, later step. Subscribe to `confirmed` if you only need "will I get paid," or `settled` if you need "has the money actually arrived." `charge.overpaid` fires alongside `charge.confirmed`/`charge.partially_paid` whenever the cumulative amount received ends up above `amount` (see `Charge.isOverpaid`). `charge.escrow_released` fires once an escrow-configured charge\'s funds have been moved out of its Safe to the split address by `POST /v1/charges/{id}/release` \u2014 a normal `charge.settled` still follows once the split itself finishes distributing. `charge.escrow_refunded` fires once an escrow-configured charge\'s funds have been moved out of its Safe back to the payer by `POST /v1/charges/{id}/refund` \u2014 mutually exclusive with `charge.escrow_released`, an escrow charge only ever emits one of the two. Every event in this category carries the full `Charge` object as `data`.'
|
|
928
971
|
);
|
|
929
|
-
var WebhookDeliveryEventTypeSchema =
|
|
972
|
+
var WebhookDeliveryEventTypeSchema = import_zod16.z.enum(["webhook.delivery_failed", "webhook.delivery_recovered", "webhook.endpoint_unhealthy"]).describe(
|
|
930
973
|
"Meta-events about the health of your own webhook endpoints \u2014 useful for monitoring without polling `GET /v1/webhooks/{id}/deliveries`. `webhook.endpoint_unhealthy` fires once when a webhook's failure rate over the trailing 24h crosses 20%, and `webhook.delivery_recovered` fires once when a delivery to that webhook next succeeds. `data` for every event in this category: `{ webhookId, url, failureRatio? }` (`failureRatio` only present on `webhook.endpoint_unhealthy`)."
|
|
931
974
|
);
|
|
932
|
-
var WebhookEventTypeSchema =
|
|
975
|
+
var WebhookEventTypeSchema = import_zod16.z.union([
|
|
933
976
|
ChargeWebhookEventTypeSchema,
|
|
934
977
|
WebhookDeliveryEventTypeSchema
|
|
935
978
|
]);
|
|
936
|
-
var WebhookCategorySchema =
|
|
979
|
+
var WebhookCategorySchema = import_zod16.z.enum(["payments", "webhooks"]).describe(
|
|
937
980
|
"Subscribe to every event in a category via `eventCategories` instead of listing events one by one \u2014 new events added to a category later arrive automatically, no subscription update needed."
|
|
938
981
|
);
|
|
939
982
|
function buildCategoryMap() {
|
|
@@ -963,101 +1006,101 @@ var TriggerableChargeEventSchema = ChargeWebhookEventTypeSchema.exclude([
|
|
|
963
1006
|
);
|
|
964
1007
|
|
|
965
1008
|
// src/webhooks.ts
|
|
966
|
-
var
|
|
1009
|
+
var import_zod17 = require("zod");
|
|
967
1010
|
var WEBHOOK_EVENTS_WILDCARD = "*";
|
|
968
|
-
var CreateWebhookSchema =
|
|
969
|
-
url:
|
|
1011
|
+
var CreateWebhookSchema = import_zod17.z.object({
|
|
1012
|
+
url: import_zod17.z.string().max(2048).url().describe(
|
|
970
1013
|
"Must be HTTPS and resolve to a public address \u2014 private/internal IPs are rejected."
|
|
971
1014
|
),
|
|
972
|
-
events:
|
|
1015
|
+
events: import_zod17.z.array(import_zod17.z.union([WebhookEventTypeSchema, import_zod17.z.literal(WEBHOOK_EVENTS_WILDCARD)])).max(Object.keys(EVENT_CATEGORY_MAP).length + 1).default([]).describe(
|
|
973
1016
|
'Individual event types to receive, or `"*"` for every event (combine with `excludeEvents` to opt back out of specific ones). Omit in favor of `eventCategories` if you want whole categories instead.'
|
|
974
1017
|
),
|
|
975
|
-
eventCategories:
|
|
1018
|
+
eventCategories: import_zod17.z.array(WebhookCategorySchema).max(WebhookCategorySchema.options.length).default([]).describe(
|
|
976
1019
|
"Subscribe to every event in these categories. At least one of `events` or `eventCategories` is required."
|
|
977
1020
|
),
|
|
978
|
-
excludeEvents:
|
|
1021
|
+
excludeEvents: import_zod17.z.array(WebhookEventTypeSchema).max(Object.keys(EVENT_CATEGORY_MAP).length).default([]).describe(
|
|
979
1022
|
'Event types to exclude even if selected via `events: ["*"]` or `eventCategories`.'
|
|
980
1023
|
)
|
|
981
1024
|
}).refine((v) => v.events.length > 0 || v.eventCategories.length > 0, {
|
|
982
1025
|
message: "must select at least one event via `events` or `eventCategories`",
|
|
983
1026
|
path: ["events"]
|
|
984
1027
|
});
|
|
985
|
-
var WebhookSchema =
|
|
986
|
-
id:
|
|
1028
|
+
var WebhookSchema = import_zod17.z.object({
|
|
1029
|
+
id: import_zod17.z.string(),
|
|
987
1030
|
environment: EnvironmentSchema.nullable().describe(
|
|
988
1031
|
"Which environment's API key created this webhook \u2014 `live` or `test`. Every event is only ever delivered to a webhook whose `environment` matches the event's own (or to a webhook with `environment: null`, which receives every environment \u2014 the case for every webhook created before this field existed)."
|
|
989
1032
|
),
|
|
990
|
-
url:
|
|
991
|
-
events:
|
|
992
|
-
eventCategories:
|
|
993
|
-
excludeEvents:
|
|
994
|
-
isWildcard:
|
|
995
|
-
secret:
|
|
1033
|
+
url: import_zod17.z.string(),
|
|
1034
|
+
events: import_zod17.z.array(WebhookEventTypeSchema),
|
|
1035
|
+
eventCategories: import_zod17.z.array(WebhookCategorySchema),
|
|
1036
|
+
excludeEvents: import_zod17.z.array(WebhookEventTypeSchema),
|
|
1037
|
+
isWildcard: import_zod17.z.boolean(),
|
|
1038
|
+
secret: import_zod17.z.string().describe(
|
|
996
1039
|
"The signing secret, used to verify the `X-Klappay-Signature` header on every delivery. Returned in full only this once \u2014 store it now, it is not recoverable afterward. Header format: `t=<unix-seconds>,v1=<hex-encoded HMAC-SHA256>`. Compute the expected signature as `HMAC-SHA256(secret, \"${t}.${raw request body}\")` (hex-encoded) and compare it to `v1` using a constant-time comparison; as a replay-protection measure, also reject if `t` is too far from the current time \u2014 Klappay does not enforce or check any particular tolerance server-side, so the exact threshold is entirely the receiver's own policy call. An official SDK's `constructEvent()`/`verifySignature()` do this for you, defaulting to a 300-second tolerance, overridable via `constructEvent`'s `toleranceSeconds` option \u2014 see github.com/klappay for available SDKs."
|
|
997
1040
|
),
|
|
998
|
-
createdAt:
|
|
1041
|
+
createdAt: import_zod17.z.string().datetime()
|
|
999
1042
|
});
|
|
1000
1043
|
var WebhookListItemSchema = WebhookSchema.omit({ secret: true }).extend({
|
|
1001
|
-
hint:
|
|
1044
|
+
hint: import_zod17.z.string().describe("A truncated, safe-to-display form of the secret (e.g. `whsec_...ab12`).")
|
|
1002
1045
|
});
|
|
1003
|
-
var WebhookPayloadSchema =
|
|
1004
|
-
id:
|
|
1046
|
+
var WebhookPayloadSchema = import_zod17.z.object({
|
|
1047
|
+
id: import_zod17.z.string().describe(
|
|
1005
1048
|
"Unique id for this specific delivery \u2014 also sent as the `X-Klappay-Delivery` header."
|
|
1006
1049
|
),
|
|
1007
1050
|
event: WebhookEventTypeSchema,
|
|
1008
|
-
createdAt:
|
|
1009
|
-
data:
|
|
1051
|
+
createdAt: import_zod17.z.string().datetime(),
|
|
1052
|
+
data: import_zod17.z.unknown().describe(
|
|
1010
1053
|
"Event-specific data. Charge events (`charge.*`) carry the full `Charge` object; webhook-delivery events carry a smaller, event-specific object \u2014 see `WebhookEventDataMap`/`TypedWebhookPayload` for the exact shape per event, or docs/webhooks.md."
|
|
1011
1054
|
)
|
|
1012
1055
|
});
|
|
1013
|
-
var WebhookDeliveryStatusSchema =
|
|
1014
|
-
var WebhookDeliverySchema =
|
|
1015
|
-
id:
|
|
1016
|
-
webhookId:
|
|
1056
|
+
var WebhookDeliveryStatusSchema = import_zod17.z.enum(["pending", "delivered", "failed"]);
|
|
1057
|
+
var WebhookDeliverySchema = import_zod17.z.object({
|
|
1058
|
+
id: import_zod17.z.string(),
|
|
1059
|
+
webhookId: import_zod17.z.string(),
|
|
1017
1060
|
event: WebhookEventTypeSchema,
|
|
1018
1061
|
status: WebhookDeliveryStatusSchema.describe(
|
|
1019
1062
|
"`pending`: still retrying. `delivered`: got a 2xx response. `failed`: retries exhausted (5 attempts over ~24h) \u2014 use `POST /v1/webhooks/{id}/deliveries/{deliveryId}/retry` to try again manually."
|
|
1020
1063
|
),
|
|
1021
|
-
attempts:
|
|
1022
|
-
responseCode:
|
|
1064
|
+
attempts: import_zod17.z.number(),
|
|
1065
|
+
responseCode: import_zod17.z.number().nullable().describe(
|
|
1023
1066
|
"HTTP status your endpoint returned on the most recent attempt. `null` if every attempt failed to connect at all."
|
|
1024
1067
|
),
|
|
1025
|
-
nextRetryAt:
|
|
1026
|
-
deliveredAt:
|
|
1027
|
-
createdAt:
|
|
1068
|
+
nextRetryAt: import_zod17.z.string().datetime().nullable(),
|
|
1069
|
+
deliveredAt: import_zod17.z.string().datetime().nullable(),
|
|
1070
|
+
createdAt: import_zod17.z.string().datetime()
|
|
1028
1071
|
});
|
|
1029
1072
|
var ListWebhookDeliveriesSchema = PaginationQuerySchema;
|
|
1030
1073
|
var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
1031
1074
|
|
|
1032
1075
|
// src/recipients.ts
|
|
1033
|
-
var
|
|
1076
|
+
var import_zod18 = require("zod");
|
|
1034
1077
|
var EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
1035
|
-
var CreateRecipientSchema =
|
|
1036
|
-
address:
|
|
1037
|
-
label:
|
|
1078
|
+
var CreateRecipientSchema = import_zod18.z.object({
|
|
1079
|
+
address: import_zod18.z.string().regex(EVM_ADDRESS_REGEX, "must be a 20-byte hex address").describe("EVM address to register as a trusted split recipient for your organization."),
|
|
1080
|
+
label: import_zod18.z.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
1038
1081
|
});
|
|
1039
|
-
var RecipientSchema =
|
|
1040
|
-
id:
|
|
1082
|
+
var RecipientSchema = import_zod18.z.object({
|
|
1083
|
+
id: import_zod18.z.string().describe(
|
|
1041
1084
|
"Klappay-generated id, e.g. `rc_...` \u2014 this, not the raw address, is what a charge's `splitRecipients[].recipientId` references."
|
|
1042
1085
|
),
|
|
1043
1086
|
environment: EnvironmentSchema,
|
|
1044
|
-
address:
|
|
1045
|
-
label:
|
|
1046
|
-
payout:
|
|
1087
|
+
address: import_zod18.z.string(),
|
|
1088
|
+
label: import_zod18.z.string().nullable(),
|
|
1089
|
+
payout: import_zod18.z.boolean().describe(
|
|
1047
1090
|
"Whether this recipient is eligible to be used as an API key's `payoutAddress` (in addition to being referenceable in a split, which every non-revoked recipient already is). Set via `PATCH /v1/recipients/{id}` \u2014 requires the `recipients:manage_payout` scope, deliberately separate from `recipients:write`."
|
|
1048
1091
|
),
|
|
1049
|
-
createdAt:
|
|
1092
|
+
createdAt: import_zod18.z.string().datetime()
|
|
1050
1093
|
});
|
|
1051
|
-
var SetRecipientPayoutSchema =
|
|
1052
|
-
payout:
|
|
1094
|
+
var SetRecipientPayoutSchema = import_zod18.z.object({
|
|
1095
|
+
payout: import_zod18.z.boolean().describe("New payout-eligibility value for this recipient.")
|
|
1053
1096
|
});
|
|
1054
1097
|
|
|
1055
1098
|
// src/timeline.ts
|
|
1056
|
-
var
|
|
1057
|
-
var TransactionSourceSchema =
|
|
1058
|
-
"How this transfer was detected: `
|
|
1099
|
+
var import_zod19 = require("zod");
|
|
1100
|
+
var TransactionSourceSchema = import_zod19.z.enum(["contract_watcher", "reconciliation_job", "sandbox"]).describe(
|
|
1101
|
+
"How this transfer was detected: `contract_watcher` (the normal path \u2014 a real-time on-chain event subscription), `reconciliation_job` (a fallback poller caught it after the watcher missed or delayed it), or `sandbox` (simulated via `POST /v1/sandbox/charges/{id}/trigger`, no real on-chain transfer)."
|
|
1059
1102
|
);
|
|
1060
|
-
var TimelineEventTypeSchema =
|
|
1103
|
+
var TimelineEventTypeSchema = import_zod19.z.enum([
|
|
1061
1104
|
"charge.created",
|
|
1062
1105
|
"charge.expired",
|
|
1063
1106
|
"transaction.detected",
|
|
@@ -1069,13 +1112,13 @@ var TimelineEventTypeSchema = import_zod18.z.enum([
|
|
|
1069
1112
|
]).describe(
|
|
1070
1113
|
"`charge.created`: the charge was created. `charge.expired`: `expiresAt` passed with no full payment. `transaction.detected`: a raw on-chain transfer was seen (see the `event`-shaped fields below for details \u2014 a charge can have more than one, e.g. a partial payment followed by the rest). `split.distributed`: a payout to the merchant completed on-chain, for one contributing `(token, network)` pair \u2014 a charge settled across more than one pair emits one of these per pair (see the `token`/`network` fields below). `webhook.dispatched`/`webhook.delivered`/`webhook.failed`: one specific delivery *attempt* for one webhook subscription \u2014 `failed` here means this single attempt failed, not that all retries were exhausted (see `WebhookDeliveryStatusSchema` for the exhausted-all-retries state). `transfer.reclaimed`: an on-chain transfer was detected but never reached its network's required confirmation depth before vanishing (reverted, or dropped from the canonical chain) \u2014 see `txHash` below for which transfer."
|
|
1071
1114
|
);
|
|
1072
|
-
var TimelineEventSchema =
|
|
1115
|
+
var TimelineEventSchema = import_zod19.z.object({
|
|
1073
1116
|
type: TimelineEventTypeSchema,
|
|
1074
|
-
at:
|
|
1075
|
-
txHash:
|
|
1117
|
+
at: import_zod19.z.string().datetime(),
|
|
1118
|
+
txHash: import_zod19.z.string().optional().describe(
|
|
1076
1119
|
"Present for `transaction.detected`, `split.distributed`, and `transfer.reclaimed` events only."
|
|
1077
1120
|
),
|
|
1078
|
-
amount:
|
|
1121
|
+
amount: import_zod19.z.number().optional().describe(
|
|
1079
1122
|
"Present for `transaction.detected` events only \u2014 the amount that specific transfer carried."
|
|
1080
1123
|
),
|
|
1081
1124
|
source: TransactionSourceSchema.optional().describe(
|
|
@@ -1087,102 +1130,114 @@ var TimelineEventSchema = import_zod18.z.object({
|
|
|
1087
1130
|
network: NetworkSchema.optional().describe(
|
|
1088
1131
|
"Present for `transaction.detected` and `split.distributed` events \u2014 which network this specific transfer, or settlement, used."
|
|
1089
1132
|
),
|
|
1090
|
-
causedTransition:
|
|
1133
|
+
causedTransition: import_zod19.z.boolean().optional().describe(
|
|
1091
1134
|
"Present for `transaction.detected` events only. `true` if this specific transfer changed the charge's status (e.g. PENDING\u2192CONFIRMED) \u2014 a charge paid in installments can have more than one such event."
|
|
1092
1135
|
),
|
|
1093
1136
|
event: WebhookEventTypeSchema.optional().describe(
|
|
1094
1137
|
"Present for `webhook.*` events only \u2014 which event type this delivery was for."
|
|
1095
1138
|
),
|
|
1096
|
-
responseCode:
|
|
1139
|
+
responseCode: import_zod19.z.number().nullable().optional().describe(
|
|
1097
1140
|
"Present for `webhook.*` events only \u2014 HTTP status your endpoint returned, or `null` if the request never connected."
|
|
1098
1141
|
),
|
|
1099
|
-
attempts:
|
|
1142
|
+
attempts: import_zod19.z.number().optional().describe(
|
|
1100
1143
|
"Present for `webhook.*` events only \u2014 how many delivery attempts have been made so far."
|
|
1101
1144
|
)
|
|
1102
1145
|
});
|
|
1103
1146
|
|
|
1104
1147
|
// src/health.ts
|
|
1105
|
-
var
|
|
1106
|
-
var HealthSchema =
|
|
1107
|
-
status:
|
|
1148
|
+
var import_zod20 = require("zod");
|
|
1149
|
+
var HealthSchema = import_zod20.z.object({
|
|
1150
|
+
status: import_zod20.z.enum(["ok", "error"]).describe(
|
|
1108
1151
|
"`error` when the database connectivity check fails \u2014 the HTTP status code mirrors this (503 instead of 200), so a plain uptime check (not just a JSON-aware one) still catches a DB outage."
|
|
1109
1152
|
),
|
|
1110
|
-
version:
|
|
1111
|
-
timestamp:
|
|
1112
|
-
db:
|
|
1113
|
-
pendingWebhooks:
|
|
1114
|
-
oldestPendingChargeAgeSeconds:
|
|
1115
|
-
|
|
1153
|
+
version: import_zod20.z.string(),
|
|
1154
|
+
timestamp: import_zod20.z.string().datetime(),
|
|
1155
|
+
db: import_zod20.z.enum(["ok", "error"]).describe("Result of a real database connectivity check, not just a process-alive check."),
|
|
1156
|
+
pendingWebhooks: import_zod20.z.number().describe("Count of webhook deliveries still awaiting a successful attempt."),
|
|
1157
|
+
oldestPendingChargeAgeSeconds: import_zod20.z.number().nullable().describe("Age of the oldest still-unpaid charge, in seconds. `null` if there are none."),
|
|
1158
|
+
lastContractWatcherEventAgeSeconds: import_zod20.z.number().nullable().describe(
|
|
1116
1159
|
"Seconds since the last on-chain payment notification was received \u2014 a cheap signal for whether payment detection is currently working. `null` if none have ever been received."
|
|
1117
1160
|
)
|
|
1118
1161
|
});
|
|
1119
1162
|
|
|
1120
1163
|
// src/sandbox.ts
|
|
1121
|
-
var
|
|
1122
|
-
var SandboxTriggerSchema =
|
|
1164
|
+
var import_zod21 = require("zod");
|
|
1165
|
+
var SandboxTriggerSchema = import_zod21.z.object({
|
|
1123
1166
|
event: TriggerableChargeEventSchema,
|
|
1124
|
-
amount:
|
|
1167
|
+
amount: import_zod21.z.number().positive().max(CHARGE_AMOUNT_MAX).optional().describe(
|
|
1125
1168
|
"Used with `charge.partially_paid` (amount to simulate as received so far \u2014 must be less than the charge amount, defaults to half of it if omitted) and with `charge.overpaid` (amount received \u2014 must be greater than the charge amount, defaults to 1.5x it if omitted). Ignored for every other event."
|
|
1126
1169
|
)
|
|
1127
1170
|
});
|
|
1128
1171
|
|
|
1129
1172
|
// src/capabilities.ts
|
|
1130
|
-
var
|
|
1131
|
-
var CapabilitiesSchema =
|
|
1132
|
-
acceptedPayments:
|
|
1133
|
-
"Every `(token, network)` pair
|
|
1173
|
+
var import_zod22 = require("zod");
|
|
1174
|
+
var CapabilitiesSchema = import_zod22.z.object({
|
|
1175
|
+
acceptedPayments: import_zod22.z.array(AcceptedPaymentSchema).describe(
|
|
1176
|
+
"Every `(token, network)` pair enabled for your environment right now, using the same deployment metadata and availability policy as `POST /v1/charges`. Cataloged but disabled pairs are omitted. Availability can change between requests, so handle `422 token_not_supported` when creating a charge. Use this to build a picker UI instead of hardcoding the matrix client-side."
|
|
1134
1177
|
)
|
|
1135
1178
|
});
|
|
1136
1179
|
|
|
1137
1180
|
// src/swap.ts
|
|
1138
|
-
var
|
|
1139
|
-
var CreateSwapQuoteSchema =
|
|
1181
|
+
var import_zod23 = require("zod");
|
|
1182
|
+
var CreateSwapQuoteSchema = import_zod23.z.object({
|
|
1140
1183
|
inputToken: AltTokenSchema.describe(
|
|
1141
1184
|
"Which alt-cryptocurrency the payer wants to send \u2014 must be one of this charge's `swapAlternatives`, or `422 token_not_supported`."
|
|
1142
1185
|
),
|
|
1143
1186
|
inputNetwork: NetworkSchema.describe(
|
|
1144
|
-
"Which network the payer will send `inputToken` on. Also picks which of this charge's `acceptedPayments` pairs the swap resolves to \u2014 a charge accepting USDC on both Base and Optimism resolves to whichever `inputNetwork` you pass. If the charge accepts more than one token on that same network, Klappay
|
|
1187
|
+
"Which network the payer will send `inputToken` on. Also picks which of this charge's `acceptedPayments` pairs the swap resolves to \u2014 a charge accepting USDC on both Base and Optimism resolves to whichever `inputNetwork` you pass. If the charge accepts more than one token on that same network, Klappay applies its token preference among enabled pairs the charge accepts. BNB Chain payments are currently disabled for both cataloged Binance-Peg tokens."
|
|
1145
1188
|
),
|
|
1146
|
-
takerAddress:
|
|
1189
|
+
takerAddress: import_zod23.z.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe(
|
|
1147
1190
|
"The payer's own wallet address \u2014 the account that will sign and submit the swap transaction. Not validated against anything else; any well-formed address is accepted, since Klappay never custodies these funds."
|
|
1148
1191
|
)
|
|
1149
1192
|
});
|
|
1150
|
-
var SwapQuoteSchema =
|
|
1193
|
+
var SwapQuoteSchema = import_zod23.z.object({
|
|
1151
1194
|
inputToken: AltTokenSchema,
|
|
1152
1195
|
inputNetwork: NetworkSchema,
|
|
1153
|
-
inputAmount:
|
|
1196
|
+
inputAmount: import_zod23.z.number().describe(
|
|
1154
1197
|
"The ceiling of `inputToken` the payer needs available to sign for, in whole units (not wei/base units) \u2014 not necessarily the exact final cost. Any `inputToken` beyond what the swap actually needs (price moved favorably, less slippage than budgeted) is swapped back and refunded to the payer automatically, in the same transaction \u2014 never a separate step or a Klappay-side refund."
|
|
1155
1198
|
),
|
|
1199
|
+
inputAmountExact: ExactAmountSchema.optional().describe(
|
|
1200
|
+
"Exact ceiling of `inputToken` the payer needs available, in whole token units as a nonnegative decimal string with at most 18 fractional digits and no scientific notation. Prefer this over the legacy numeric `inputAmount`. Optional for compatibility with older API responses."
|
|
1201
|
+
),
|
|
1156
1202
|
outputToken: TokenSchema.describe(
|
|
1157
1203
|
"Which of this charge's `acceptedPayments` tokens the swap resolves to."
|
|
1158
1204
|
),
|
|
1159
1205
|
outputNetwork: NetworkSchema,
|
|
1160
|
-
outputAmount:
|
|
1161
|
-
"The
|
|
1206
|
+
outputAmount: import_zod23.z.number().describe(
|
|
1207
|
+
"The stablecoin amount requested by this quote, in whole `outputToken` units. Covers the remaining balance, rounded up only if the selected token cannot represent it exactly. This legacy JSON number can lose precision; use `outputAmountExact` for arithmetic. The actual transfer is verified on-chain before crediting the charge."
|
|
1162
1208
|
),
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1209
|
+
outputAmountExact: ExactAmountSchema.optional().describe(
|
|
1210
|
+
"Exact stablecoin amount requested by this quote, in whole `outputToken` units as a nonnegative decimal string with no scientific notation. Covers the remaining charge balance and rounds upward only to the smallest representable token unit when needed. Optional for compatibility with older API responses."
|
|
1211
|
+
),
|
|
1212
|
+
fees: import_zod23.z.object({
|
|
1213
|
+
klappayFee: import_zod23.z.number().describe(
|
|
1214
|
+
"Klappay's own swap fee (1% today), in `outputToken` units \u2014 paid by the payer and already reflected in `inputAmount`, separate from the merchant's own `feePercent`. Never subtracted from `outputAmount`."
|
|
1215
|
+
),
|
|
1216
|
+
klappayFeeExact: ExactAmountSchema.optional().describe(
|
|
1217
|
+
"Exact Klappay swap fee in whole `outputToken` units as a nonnegative decimal string with at most 18 fractional digits and no scientific notation. Already reflected in the input ceiling. Optional for compatibility with older API responses."
|
|
1218
|
+
),
|
|
1219
|
+
zeroExFee: import_zod23.z.number().nullable().describe(
|
|
1220
|
+
"0x's own protocol fee for this specific token pair, in `outputToken` units, or `null` when this pair isn't currently one 0x charges on. Paid by the payer and already reflected in `inputAmount`, never subtracted from `outputAmount` \u2014 Klappay never sees this fee, it goes straight to 0x."
|
|
1166
1221
|
),
|
|
1167
|
-
|
|
1168
|
-
"0x
|
|
1222
|
+
zeroExFeeExact: ExactAmountSchema.nullable().optional().describe(
|
|
1223
|
+
"Exact 0x fee in whole `outputToken` units as a nonnegative decimal string with at most 18 fractional digits and no scientific notation, or `null` when no fee applies. Already reflected in the input ceiling. Optional for compatibility with older API responses."
|
|
1169
1224
|
)
|
|
1170
1225
|
}).describe(
|
|
1171
1226
|
"Every fee the payer is charged for using swap-to-pay, broken out by who collects it \u2014 both already reflected in `inputAmount`, shown here separately for transparency. Neither ever reduces `outputAmount`."
|
|
1172
1227
|
),
|
|
1173
|
-
expiresAt:
|
|
1228
|
+
expiresAt: import_zod23.z.string().datetime().describe(
|
|
1174
1229
|
"When this quote's price is no longer safely valid \u2014 a rough guide for the payer's UI countdown only. The actual price guarantee is enforced on-chain by the swap transaction itself (a signed Permit2 deadline, or a minimum-output check for a native-currency sell), not by this timestamp \u2014 submitting after it expires either reverts on-chain or simply gets re-quoted at the current price, never silently executes at a stale rate."
|
|
1175
1230
|
),
|
|
1176
|
-
transaction:
|
|
1177
|
-
to:
|
|
1178
|
-
data:
|
|
1179
|
-
value:
|
|
1231
|
+
transaction: import_zod23.z.object({
|
|
1232
|
+
to: import_zod23.z.string().describe("Contract address the payer's wallet must send this transaction to."),
|
|
1233
|
+
data: import_zod23.z.string().describe("Calldata \u2014 opaque, must be sent unmodified."),
|
|
1234
|
+
value: import_zod23.z.string().describe(
|
|
1180
1235
|
"Native currency (ETH/BNB/MATIC/AVAX) to attach, in wei \u2014 `\"0\"` when `inputToken` isn't this network's native currency."
|
|
1181
1236
|
)
|
|
1182
1237
|
}).describe(
|
|
1183
1238
|
"Pass this directly to the payer's wallet (e.g. viem/ethers `sendTransaction`) \u2014 Klappay never touches the payer's private key or submits anything on their behalf. If `permit2` is present on this response, sign that first and append the signature to this `data` before sending; if `permit2` is absent, send `transaction` as-is with no extra step."
|
|
1184
1239
|
),
|
|
1185
|
-
permit2:
|
|
1240
|
+
permit2: import_zod23.z.object({ eip712: import_zod23.z.record(import_zod23.z.unknown()) }).nullish().describe(
|
|
1186
1241
|
"Present only when `inputToken` is an ERC-20 (today, only `BTC`) \u2014 the payer's wallet must sign this EIP-712 message and append the signature to `transaction.data` before sending, since an ERC-20 sell needs a Permit2 allowance signature that a native-currency sell doesn't. `null` (never omitted, in a genuine 0x-backed quote) when `inputToken` is a network's own native currency (ETH/BNB/MATIC/AVAX) \u2014 `transaction` is then ready to sign and send directly, no extra step."
|
|
1187
1242
|
)
|
|
1188
1243
|
});
|
|
@@ -1273,6 +1328,7 @@ var SwapQuoteSchema = import_zod22.z.object({
|
|
|
1273
1328
|
SwapQuoteSchema,
|
|
1274
1329
|
TOKEN_ADDRESSES,
|
|
1275
1330
|
TOKEN_DECIMALS,
|
|
1331
|
+
TOKEN_DEPLOYMENTS,
|
|
1276
1332
|
TimelineEventSchema,
|
|
1277
1333
|
TimelineEventTypeSchema,
|
|
1278
1334
|
TokenSchema,
|
|
@@ -1292,6 +1348,8 @@ var SwapQuoteSchema = import_zod22.z.object({
|
|
|
1292
1348
|
WebhookPayloadSchema,
|
|
1293
1349
|
WebhookSchema,
|
|
1294
1350
|
findConflictingScopes,
|
|
1351
|
+
getTokenDeployment,
|
|
1352
|
+
isPaymentDeploymentEnabled,
|
|
1295
1353
|
listSwapAlternatives,
|
|
1296
1354
|
paginatedSchema
|
|
1297
1355
|
});
|