@klappay/types 3.1.1 → 3.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/README.md +1 -1
- package/dist/index.d.mts +93 -1
- package/dist/index.d.ts +93 -1
- package/dist/index.js +280 -239
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +277 -239
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ __export(index_exports, {
|
|
|
41
41
|
ChargesDateFieldSchema: () => ChargesDateFieldSchema,
|
|
42
42
|
ChargesMetricFieldSchema: () => ChargesMetricFieldSchema,
|
|
43
43
|
ChargesQueryFieldSchema: () => ChargesQueryFieldSchema,
|
|
44
|
+
CheckChargeRequestSchema: () => CheckChargeRequestSchema,
|
|
44
45
|
CheckoutProductSchema: () => CheckoutProductSchema,
|
|
45
46
|
CreateChargeSchema: () => CreateChargeSchema,
|
|
46
47
|
CreateRecipientSchema: () => CreateRecipientSchema,
|
|
@@ -53,6 +54,7 @@ __export(index_exports, {
|
|
|
53
54
|
EVM_NETWORKS: () => EVM_NETWORKS,
|
|
54
55
|
EnvironmentSchema: () => EnvironmentSchema,
|
|
55
56
|
ErrorPayloadSchema: () => ErrorPayloadSchema,
|
|
57
|
+
EscrowConfigSchema: () => EscrowConfigSchema,
|
|
56
58
|
GetChargeQrCodeQuerySchema: () => GetChargeQrCodeQuerySchema,
|
|
57
59
|
HealthSchema: () => HealthSchema,
|
|
58
60
|
KlappayCheckoutMetadataSchema: () => KlappayCheckoutMetadataSchema,
|
|
@@ -88,6 +90,7 @@ __export(index_exports, {
|
|
|
88
90
|
PendingDistributionRecipientSchema: () => PendingDistributionRecipientSchema,
|
|
89
91
|
PendingDistributionSchema: () => PendingDistributionSchema,
|
|
90
92
|
RecipientSchema: () => RecipientSchema,
|
|
93
|
+
ReleaseEscrowRequestSchema: () => ReleaseEscrowRequestSchema,
|
|
91
94
|
SandboxTriggerSchema: () => SandboxTriggerSchema,
|
|
92
95
|
SetRecipientPayoutSchema: () => SetRecipientPayoutSchema,
|
|
93
96
|
SettlementStatusSchema: () => SettlementStatusSchema,
|
|
@@ -331,7 +334,7 @@ function listSwapAlternatives(networks) {
|
|
|
331
334
|
}
|
|
332
335
|
|
|
333
336
|
// src/charges.ts
|
|
334
|
-
var
|
|
337
|
+
var import_zod10 = require("zod");
|
|
335
338
|
|
|
336
339
|
// src/checkout-metadata.ts
|
|
337
340
|
var import_zod8 = require("zod");
|
|
@@ -354,27 +357,40 @@ var MetadataWithKlappaySchema = import_zod8.z.object({ klappay: KlappayCheckoutM
|
|
|
354
357
|
"Arbitrary key/value data, returned as-is on every read. Put whatever you want in here \u2014 none of it is validated, except the `klappay` key, which is reserved for Klappay: if present, it must match `KlappayCheckoutMetadataSchema` exactly, or the whole request is rejected with `400 validation_error`."
|
|
355
358
|
);
|
|
356
359
|
|
|
360
|
+
// src/escrow.ts
|
|
361
|
+
var import_zod9 = require("zod");
|
|
362
|
+
var EscrowConfigSchema = import_zod9.z.object({
|
|
363
|
+
releaserAddress: import_zod9.z.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").optional().describe(
|
|
364
|
+
"The only address ever authorized to release this charge's escrowed funds \u2014 set once at creation, immutable after. Klappay never holds a key with any release authority of its own; every release requires a signature from this address, verified on-chain, never taken on faith. Omit to default to the API key's own `payoutAddress` \u2014 the common case where the merchant releasing their own charge is the same wallet they already get paid to. Pass an explicit address only when the releaser is a different party (e.g. an operational key distinct from the payout wallet). Not validated against anything else \u2014 any well-formed address is accepted, since Klappay never custodies these funds."
|
|
365
|
+
)
|
|
366
|
+
});
|
|
367
|
+
var ReleaseEscrowRequestSchema = import_zod9.z.object({
|
|
368
|
+
signature: import_zod9.z.string().regex(/^0x[0-9a-fA-F]+$/, "must be hex-encoded signature bytes").describe(
|
|
369
|
+
"The Safe transaction signature authorizing this release, produced by signing the escrow's predetermined release transaction (destination and amount are fixed at escrow creation, never client-supplied here) with the private key behind this charge's `escrowReleaserAddress` \u2014 never anything Klappay can produce itself. Independently verified on-chain before anything moves; a mismatched, malformed, or missing signature is rejected, never trusted at face value."
|
|
370
|
+
)
|
|
371
|
+
});
|
|
372
|
+
|
|
357
373
|
// src/charges.ts
|
|
358
|
-
var ChargeStatusSchema =
|
|
374
|
+
var ChargeStatusSchema = import_zod10.z.enum(["pending", "partially_paid", "confirmed", "expired", "underpaid"]).describe(
|
|
359
375
|
"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."
|
|
360
376
|
);
|
|
361
|
-
var SettlementStatusSchema =
|
|
377
|
+
var SettlementStatusSchema = import_zod10.z.enum(["pending", "completed", "failed"]).describe(
|
|
362
378
|
"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."
|
|
363
379
|
);
|
|
364
380
|
var CHARGE_EXPIRES_IN_MIN_SECONDS = 60;
|
|
365
381
|
var CHARGE_EXPIRES_IN_MAX_SECONDS = 3600;
|
|
366
382
|
var CHARGE_ACCEPTED_PAYMENTS_MAX = 14;
|
|
367
|
-
var AcceptedPaymentSchema =
|
|
383
|
+
var AcceptedPaymentSchema = import_zod10.z.object({
|
|
368
384
|
token: TokenSchema,
|
|
369
385
|
network: NetworkSchema
|
|
370
386
|
});
|
|
371
|
-
var AcceptedPaymentsSchema =
|
|
387
|
+
var AcceptedPaymentsSchema = import_zod10.z.array(AcceptedPaymentSchema).min(1, "At least one accepted payment is required.").max(CHARGE_ACCEPTED_PAYMENTS_MAX).superRefine((pairs, ctx) => {
|
|
372
388
|
const seen = /* @__PURE__ */ new Set();
|
|
373
389
|
pairs.forEach((pair, index) => {
|
|
374
390
|
const key = `${pair.token}:${pair.network}`;
|
|
375
391
|
if (seen.has(key)) {
|
|
376
392
|
ctx.addIssue({
|
|
377
|
-
code:
|
|
393
|
+
code: import_zod10.z.ZodIssueCode.custom,
|
|
378
394
|
message: `Duplicate accepted payment: ${pair.token} on ${pair.network}.`,
|
|
379
395
|
path: [index]
|
|
380
396
|
});
|
|
@@ -382,7 +398,7 @@ var AcceptedPaymentsSchema = import_zod9.z.array(AcceptedPaymentSchema).min(1, "
|
|
|
382
398
|
seen.add(key);
|
|
383
399
|
if (!OPERATIONAL_NETWORKS.includes(pair.network)) {
|
|
384
400
|
ctx.addIssue({
|
|
385
|
-
code:
|
|
401
|
+
code: import_zod10.z.ZodIssueCode.custom,
|
|
386
402
|
message: `Network "${pair.network}" isn't live yet \u2014 only ${OPERATIONAL_NETWORKS.join(", ")} today.`,
|
|
387
403
|
path: [index, "network"]
|
|
388
404
|
});
|
|
@@ -392,32 +408,32 @@ var AcceptedPaymentsSchema = import_zod9.z.array(AcceptedPaymentSchema).min(1, "
|
|
|
392
408
|
`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\`.`
|
|
393
409
|
);
|
|
394
410
|
var CHARGE_SPLIT_RECIPIENTS_MAX = 5;
|
|
395
|
-
var SplitRecipientSchema =
|
|
396
|
-
address:
|
|
397
|
-
percent:
|
|
411
|
+
var SplitRecipientSchema = import_zod10.z.object({
|
|
412
|
+
address: import_zod10.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."),
|
|
413
|
+
percent: import_zod10.z.number().positive().max(100).describe(
|
|
398
414
|
"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."
|
|
399
415
|
),
|
|
400
|
-
label:
|
|
416
|
+
label: import_zod10.z.string().min(1).max(64).optional().describe(
|
|
401
417
|
'Free-form label for your own bookkeeping (e.g. `"supplier"`, `"sales rep"`) \u2014 echoed back unchanged, never interpreted by Klappay.'
|
|
402
418
|
)
|
|
403
419
|
});
|
|
404
|
-
var SplitRecipientInputSchema =
|
|
405
|
-
recipientId:
|
|
420
|
+
var SplitRecipientInputSchema = import_zod10.z.object({
|
|
421
|
+
recipientId: import_zod10.z.string().describe(
|
|
406
422
|
"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."
|
|
407
423
|
),
|
|
408
|
-
percent:
|
|
424
|
+
percent: import_zod10.z.number().positive().max(100).describe(
|
|
409
425
|
"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."
|
|
410
426
|
),
|
|
411
|
-
label:
|
|
427
|
+
label: import_zod10.z.string().min(1).max(64).optional().describe(
|
|
412
428
|
'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.'
|
|
413
429
|
)
|
|
414
430
|
});
|
|
415
|
-
var SplitRecipientsInputSchema =
|
|
431
|
+
var SplitRecipientsInputSchema = import_zod10.z.array(SplitRecipientInputSchema).max(CHARGE_SPLIT_RECIPIENTS_MAX).superRefine((recipients, ctx) => {
|
|
416
432
|
const seen = /* @__PURE__ */ new Set();
|
|
417
433
|
recipients.forEach((recipient, index) => {
|
|
418
434
|
if (seen.has(recipient.recipientId)) {
|
|
419
435
|
ctx.addIssue({
|
|
420
|
-
code:
|
|
436
|
+
code: import_zod10.z.ZodIssueCode.custom,
|
|
421
437
|
message: `Duplicate split recipientId: ${recipient.recipientId}.`,
|
|
422
438
|
path: [index, "recipientId"]
|
|
423
439
|
});
|
|
@@ -428,82 +444,91 @@ var SplitRecipientsInputSchema = import_zod9.z.array(SplitRecipientInputSchema).
|
|
|
428
444
|
`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\`.`
|
|
429
445
|
);
|
|
430
446
|
var CHARGE_AMOUNT_MAX = 999999999999;
|
|
431
|
-
var CreateChargeSchema =
|
|
432
|
-
amount:
|
|
447
|
+
var CreateChargeSchema = import_zod10.z.object({
|
|
448
|
+
amount: import_zod10.z.number().positive().max(CHARGE_AMOUNT_MAX).describe(
|
|
433
449
|
"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."
|
|
434
450
|
),
|
|
435
|
-
currency:
|
|
451
|
+
currency: import_zod10.z.literal("USD").default("USD").describe("Always `USD` today \u2014 the only supported currency."),
|
|
436
452
|
acceptedPayments: AcceptedPaymentsSchema,
|
|
437
|
-
expiresIn:
|
|
453
|
+
expiresIn: import_zod10.z.number().int().min(CHARGE_EXPIRES_IN_MIN_SECONDS).max(CHARGE_EXPIRES_IN_MAX_SECONDS).describe(
|
|
438
454
|
"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."
|
|
439
455
|
),
|
|
440
|
-
idempotencyKey:
|
|
456
|
+
idempotencyKey: import_zod10.z.string().min(1).max(255).optional().describe(
|
|
441
457
|
"Scoped to your tenant. Replaying the same key returns the original charge unchanged instead of creating a duplicate \u2014 safe to retry a request after a timeout without double-charging."
|
|
442
458
|
),
|
|
443
|
-
externalRef:
|
|
459
|
+
externalRef: import_zod10.z.string().min(1).max(255).optional().describe(
|
|
444
460
|
"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."
|
|
445
461
|
),
|
|
446
|
-
source:
|
|
462
|
+
source: import_zod10.z.string().min(1).max(64).optional().describe(
|
|
447
463
|
'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.'
|
|
448
464
|
),
|
|
449
465
|
metadata: MetadataWithKlappaySchema.optional(),
|
|
450
|
-
redirectUrl:
|
|
466
|
+
redirectUrl: import_zod10.z.string().url().refine((value) => /^https?:\/\//.test(value), "must use http or https").optional().describe(
|
|
451
467
|
"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."
|
|
452
468
|
),
|
|
453
|
-
splitRecipients: SplitRecipientsInputSchema.optional()
|
|
469
|
+
splitRecipients: SplitRecipientsInputSchema.optional(),
|
|
470
|
+
escrow: EscrowConfigSchema.optional().describe(
|
|
471
|
+
"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."
|
|
472
|
+
)
|
|
454
473
|
});
|
|
455
|
-
var ChargeSchema =
|
|
456
|
-
id:
|
|
457
|
-
amount:
|
|
458
|
-
amountReceived:
|
|
474
|
+
var ChargeSchema = import_zod10.z.object({
|
|
475
|
+
id: import_zod10.z.string().describe("Klappay-generated id, e.g. `ch_...`. Use this to look up the charge later."),
|
|
476
|
+
amount: import_zod10.z.number().describe("The amount originally requested, in `currency` units (up to 6 decimal places)."),
|
|
477
|
+
amountReceived: import_zod10.z.number().nullable().describe(
|
|
459
478
|
"Cumulative amount actually received on-chain so far, in `currency` units (up to 6 decimal places). `null` until the first transfer arrives. Can exceed `amount` \u2014 see `isOverpaid`."
|
|
460
479
|
),
|
|
461
|
-
isOverpaid:
|
|
480
|
+
isOverpaid: import_zod10.z.boolean().describe(
|
|
462
481
|
"`true` if `amountReceived` ended up greater than `amount`. Klappay never refunds the difference automatically \u2014 see the docs for why."
|
|
463
482
|
),
|
|
464
|
-
currency:
|
|
465
|
-
acceptedPayments:
|
|
483
|
+
currency: import_zod10.z.string().describe("Always `USD` today \u2014 the only supported currency."),
|
|
484
|
+
acceptedPayments: import_zod10.z.array(AcceptedPaymentSchema).describe(
|
|
466
485
|
"Every `(token, network)` pair this charge was configured to accept, unchanged after creation."
|
|
467
486
|
),
|
|
468
|
-
paidWith:
|
|
487
|
+
paidWith: import_zod10.z.array(AcceptedPaymentSchema).describe(
|
|
469
488
|
"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`."
|
|
470
489
|
),
|
|
471
|
-
swapAlternatives:
|
|
490
|
+
swapAlternatives: import_zod10.z.array(SwapAlternativeSchema).describe(
|
|
472
491
|
"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`)."
|
|
473
492
|
),
|
|
474
|
-
address:
|
|
493
|
+
address: import_zod10.z.string().describe(
|
|
475
494
|
"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."
|
|
476
495
|
),
|
|
477
496
|
status: ChargeStatusSchema,
|
|
478
497
|
settlementStatus: SettlementStatusSchema.nullable(),
|
|
479
498
|
environment: EnvironmentSchema,
|
|
480
|
-
apiKeyId:
|
|
499
|
+
apiKeyId: import_zod10.z.string().nullable().describe(
|
|
481
500
|
"Which of your API keys created this charge. `null` for a charge created before this field existed."
|
|
482
501
|
),
|
|
483
|
-
txHash:
|
|
502
|
+
txHash: import_zod10.z.string().nullable().describe(
|
|
484
503
|
"Transaction hash of the most recent transfer detected for this charge. `null` until a payment is detected."
|
|
485
504
|
),
|
|
486
|
-
externalRef:
|
|
487
|
-
source:
|
|
505
|
+
externalRef: import_zod10.z.string().nullable(),
|
|
506
|
+
source: import_zod10.z.string().nullable(),
|
|
488
507
|
metadata: MetadataWithKlappaySchema.nullable(),
|
|
489
|
-
redirectUrl:
|
|
490
|
-
checkoutUrl:
|
|
508
|
+
redirectUrl: import_zod10.z.string().nullable().describe("Echoes the `redirectUrl` set at creation, if any. `null` if none was set."),
|
|
509
|
+
checkoutUrl: import_zod10.z.string().nullable().describe(
|
|
491
510
|
"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."
|
|
492
511
|
),
|
|
493
|
-
splitRecipients:
|
|
494
|
-
createdAt:
|
|
495
|
-
expiresAt:
|
|
512
|
+
splitRecipients: import_zod10.z.array(SplitRecipientSchema).describe("Echoes whatever extra split recipients were set at creation \u2014 empty array if none."),
|
|
513
|
+
createdAt: import_zod10.z.string().datetime(),
|
|
514
|
+
expiresAt: import_zod10.z.string().datetime().describe(
|
|
496
515
|
"When this charge stops accepting payment, if still `pending`/`partially_paid` by then."
|
|
497
516
|
),
|
|
498
|
-
confirmedAt:
|
|
499
|
-
settledAt:
|
|
517
|
+
confirmedAt: import_zod10.z.string().datetime().nullable().describe("When `status` first reached `confirmed`. `null` until then."),
|
|
518
|
+
settledAt: import_zod10.z.string().datetime().nullable().describe(
|
|
500
519
|
"When `settlementStatus` first reached `completed` \u2014 the merchant's wallet actually has the funds. `null` until then, including while `settlementStatus` is `pending`/`failed`."
|
|
501
520
|
),
|
|
502
|
-
lastActivityAt:
|
|
521
|
+
lastActivityAt: import_zod10.z.string().datetime().describe(
|
|
503
522
|
"When a transfer was last credited toward this charge, or `createdAt` if none has arrived yet."
|
|
523
|
+
),
|
|
524
|
+
escrow: import_zod10.z.object({
|
|
525
|
+
releaserAddress: import_zod10.z.string().describe("The only address that can ever release this escrow \u2014 never Klappay."),
|
|
526
|
+
releasedAt: import_zod10.z.string().datetime().nullable().describe("When the release actually executed on-chain. `null` until then.")
|
|
527
|
+
}).nullable().describe(
|
|
528
|
+
"Present only when this charge was created as an escrow (see `escrow` on the create request) \u2014 `null` for a normal charge."
|
|
504
529
|
)
|
|
505
530
|
});
|
|
506
|
-
var ListChargesSchema =
|
|
531
|
+
var ListChargesSchema = import_zod10.z.object({
|
|
507
532
|
status: ChargeStatusSchema.optional(),
|
|
508
533
|
token: TokenSchema.optional().describe(
|
|
509
534
|
"Filters on `paidWith.token` \u2014 the pair actually paid, not accepted."
|
|
@@ -512,75 +537,88 @@ var ListChargesSchema = import_zod9.z.object({
|
|
|
512
537
|
"Filters on `paidWith.network` \u2014 the pair actually paid, not accepted."
|
|
513
538
|
),
|
|
514
539
|
environment: EnvironmentSchema.optional(),
|
|
515
|
-
since:
|
|
540
|
+
since: import_zod10.z.string().datetime().optional().describe(
|
|
516
541
|
"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."
|
|
517
542
|
),
|
|
518
|
-
isOverpaid:
|
|
543
|
+
isOverpaid: import_zod10.z.enum(["true", "false"]).transform((v) => v === "true").optional()
|
|
519
544
|
}).extend(PaginationQuerySchema.shape);
|
|
520
545
|
var PaginatedChargesSchema = paginatedSchema(ChargeSchema);
|
|
521
|
-
var GetChargeQrCodeQuerySchema =
|
|
546
|
+
var GetChargeQrCodeQuerySchema = import_zod10.z.object({
|
|
522
547
|
token: TokenSchema.optional().describe(
|
|
523
548
|
"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."
|
|
524
549
|
),
|
|
525
550
|
network: NetworkSchema.optional()
|
|
526
551
|
});
|
|
527
552
|
|
|
553
|
+
// src/charge-check.ts
|
|
554
|
+
var import_zod11 = require("zod");
|
|
555
|
+
var CheckChargeRequestSchema = import_zod11.z.object({
|
|
556
|
+
txHash: import_zod11.z.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be a 32-byte transaction hash").optional().describe(
|
|
557
|
+
"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."
|
|
558
|
+
),
|
|
559
|
+
network: NetworkSchema.optional().describe(
|
|
560
|
+
"Which network `txHash` is on \u2014 required together with `txHash`, since a transaction hash alone doesn't identify a chain. Must be one of the networks this charge actually accepts payment on, or `422 payment_pair_not_accepted`."
|
|
561
|
+
)
|
|
562
|
+
}).refine((data) => Boolean(data.txHash) === Boolean(data.network), {
|
|
563
|
+
message: "`txHash` and `network` must be provided together, or both omitted"
|
|
564
|
+
});
|
|
565
|
+
|
|
528
566
|
// src/distributions.ts
|
|
529
|
-
var
|
|
530
|
-
var SplitDistributionStatusSchema =
|
|
567
|
+
var import_zod12 = require("zod");
|
|
568
|
+
var SplitDistributionStatusSchema = import_zod12.z.enum(["pending", "processing", "completed", "failed"]).describe(
|
|
531
569
|
"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."
|
|
532
570
|
);
|
|
533
|
-
var PendingDistributionRecipientSchema =
|
|
534
|
-
address:
|
|
535
|
-
percentAllocation:
|
|
571
|
+
var PendingDistributionRecipientSchema = import_zod12.z.object({
|
|
572
|
+
address: import_zod12.z.string().describe("On-chain recipient address."),
|
|
573
|
+
percentAllocation: import_zod12.z.number().describe("This recipient's share of the split, as a percentage (e.g. `99.0991` = 99.0991%).")
|
|
536
574
|
});
|
|
537
|
-
var PendingDistributionSchema =
|
|
538
|
-
splitAddress:
|
|
575
|
+
var PendingDistributionSchema = import_zod12.z.object({
|
|
576
|
+
splitAddress: import_zod12.z.string().describe("The on-chain 0xSplits address to call `distribute()` on."),
|
|
539
577
|
network: NetworkSchema,
|
|
540
578
|
token: TokenSchema,
|
|
541
|
-
recipients:
|
|
579
|
+
recipients: import_zod12.z.array(PendingDistributionRecipientSchema).describe(
|
|
542
580
|
"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."
|
|
543
581
|
),
|
|
544
|
-
distributorFeePercent:
|
|
582
|
+
distributorFeePercent: import_zod12.z.number().describe(
|
|
545
583
|
"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."
|
|
546
584
|
),
|
|
547
|
-
estimatedRewardAmount:
|
|
585
|
+
estimatedRewardAmount: import_zod12.z.number().describe(
|
|
548
586
|
"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."
|
|
549
587
|
),
|
|
550
|
-
availableSince:
|
|
551
|
-
graceEndsAt:
|
|
588
|
+
availableSince: import_zod12.z.string().datetime().describe("When this distribution entered its grace period."),
|
|
589
|
+
graceEndsAt: import_zod12.z.string().datetime().describe(
|
|
552
590
|
"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."
|
|
553
591
|
)
|
|
554
592
|
});
|
|
555
593
|
var PaginatedPendingDistributionsSchema = paginatedSchema(PendingDistributionSchema);
|
|
556
|
-
var ListenPendingDistributionsQuerySchema =
|
|
557
|
-
limit:
|
|
594
|
+
var ListenPendingDistributionsQuerySchema = import_zod12.z.object({
|
|
595
|
+
limit: import_zod12.z.coerce.number().int().min(0).max(PAGINATION_LIMIT_MAX).default(0).describe(
|
|
558
596
|
"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."
|
|
559
597
|
)
|
|
560
598
|
});
|
|
561
|
-
var PendingDistributionEventSchema =
|
|
562
|
-
|
|
563
|
-
type:
|
|
599
|
+
var PendingDistributionEventSchema = import_zod12.z.discriminatedUnion("type", [
|
|
600
|
+
import_zod12.z.object({
|
|
601
|
+
type: import_zod12.z.literal("distribution.available"),
|
|
564
602
|
distribution: PendingDistributionSchema
|
|
565
603
|
}),
|
|
566
|
-
|
|
567
|
-
type:
|
|
568
|
-
splitAddress:
|
|
604
|
+
import_zod12.z.object({
|
|
605
|
+
type: import_zod12.z.literal("distribution.claimed"),
|
|
606
|
+
splitAddress: import_zod12.z.string().describe("No longer claimable \u2014 either settled by someone, or picked up by the worker.")
|
|
569
607
|
})
|
|
570
608
|
]);
|
|
571
609
|
|
|
572
610
|
// src/metrics.ts
|
|
573
|
-
var
|
|
574
|
-
var MetricsResourceSchema =
|
|
611
|
+
var import_zod13 = require("zod");
|
|
612
|
+
var MetricsResourceSchema = import_zod13.z.enum(["charges", "transactions", "distributions"]).describe(
|
|
575
613
|
"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."
|
|
576
614
|
);
|
|
577
|
-
var MetricsAggregationSchema =
|
|
615
|
+
var MetricsAggregationSchema = import_zod13.z.enum(["count", "sum", "avg", "min", "max"]).describe(
|
|
578
616
|
"`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."
|
|
579
617
|
);
|
|
580
|
-
var MetricsFilterOperatorSchema =
|
|
618
|
+
var MetricsFilterOperatorSchema = import_zod13.z.enum(["eq", "neq", "in", "gt", "gte", "lt", "lte"]).describe(
|
|
581
619
|
"`in` expects an array value (max 50 entries); every other operator expects a single scalar."
|
|
582
620
|
);
|
|
583
|
-
var MetricsDateGranularitySchema =
|
|
621
|
+
var MetricsDateGranularitySchema = import_zod13.z.enum(["day", "week", "month", "year"]).describe(
|
|
584
622
|
"Bucket width for a `date_bucket` `groupBy` entry \u2014 Postgres `date_trunc` semantics (UTC)."
|
|
585
623
|
);
|
|
586
624
|
var metricsQueryEnvironmentSchema = EnvironmentSchema.describe(
|
|
@@ -593,151 +631,151 @@ var METRICS_QUERY_MAX_GROUP_BY = 3;
|
|
|
593
631
|
var METRICS_QUERY_MAX_FILTERS = 20;
|
|
594
632
|
var METRICS_QUERY_MAX_METRICS = 10;
|
|
595
633
|
var METRIC_ALIAS_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
596
|
-
var metricAliasSchema =
|
|
634
|
+
var metricAliasSchema = import_zod13.z.string().min(1).max(64).regex(
|
|
597
635
|
METRIC_ALIAS_PATTERN,
|
|
598
636
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 this becomes a SQL column alias."
|
|
599
637
|
).optional();
|
|
600
|
-
var MetricsFilterValueSchema =
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
638
|
+
var MetricsFilterValueSchema = import_zod13.z.union([
|
|
639
|
+
import_zod13.z.string().max(255),
|
|
640
|
+
import_zod13.z.number(),
|
|
641
|
+
import_zod13.z.boolean(),
|
|
642
|
+
import_zod13.z.array(import_zod13.z.union([import_zod13.z.string().max(255), import_zod13.z.number()])).min(1).max(50)
|
|
605
643
|
]);
|
|
606
|
-
var orderBySchema =
|
|
607
|
-
key:
|
|
644
|
+
var orderBySchema = import_zod13.z.object({
|
|
645
|
+
key: import_zod13.z.string().min(1).max(64).regex(
|
|
608
646
|
METRIC_ALIAS_PATTERN,
|
|
609
647
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 every valid output column name already looks like this."
|
|
610
648
|
).describe(
|
|
611
649
|
"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."
|
|
612
650
|
),
|
|
613
|
-
direction:
|
|
651
|
+
direction: import_zod13.z.enum(["asc", "desc"])
|
|
614
652
|
}).describe(
|
|
615
653
|
"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."
|
|
616
654
|
);
|
|
617
|
-
var limitSchema =
|
|
655
|
+
var limitSchema = import_zod13.z.number().int().min(1).max(METRICS_QUERY_MAX_ROW_LIMIT).default(METRICS_QUERY_DEFAULT_ROW_LIMIT).describe(
|
|
618
656
|
`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.`
|
|
619
657
|
);
|
|
620
|
-
var ChargesQueryFieldSchema =
|
|
658
|
+
var ChargesQueryFieldSchema = import_zod13.z.enum(["status", "source", "apiKeyId", "currency", "isOverpaid", "externalRef"]).describe(
|
|
621
659
|
"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."
|
|
622
660
|
);
|
|
623
|
-
var ChargesMetricFieldSchema =
|
|
661
|
+
var ChargesMetricFieldSchema = import_zod13.z.enum(["amount", "amountReceived", "feePercent"]).describe(
|
|
624
662
|
"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%."
|
|
625
663
|
);
|
|
626
|
-
var ChargesDateFieldSchema =
|
|
664
|
+
var ChargesDateFieldSchema = import_zod13.z.enum(["createdAt", "confirmedAt", "lastActivityAt", "expiresAt"]).describe(
|
|
627
665
|
"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."
|
|
628
666
|
);
|
|
629
|
-
var ChargesFilterSchema =
|
|
667
|
+
var ChargesFilterSchema = import_zod13.z.object({
|
|
630
668
|
field: ChargesQueryFieldSchema,
|
|
631
669
|
operator: MetricsFilterOperatorSchema,
|
|
632
670
|
value: MetricsFilterValueSchema
|
|
633
671
|
});
|
|
634
|
-
var ChargesGroupBySchema =
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
type:
|
|
672
|
+
var ChargesGroupBySchema = import_zod13.z.union([
|
|
673
|
+
import_zod13.z.object({ type: import_zod13.z.literal("field"), field: ChargesQueryFieldSchema }),
|
|
674
|
+
import_zod13.z.object({
|
|
675
|
+
type: import_zod13.z.literal("date_bucket"),
|
|
638
676
|
field: ChargesDateFieldSchema,
|
|
639
677
|
granularity: MetricsDateGranularitySchema
|
|
640
678
|
})
|
|
641
679
|
]);
|
|
642
|
-
var ChargesMetricSchema =
|
|
680
|
+
var ChargesMetricSchema = import_zod13.z.object({
|
|
643
681
|
aggregation: MetricsAggregationSchema,
|
|
644
682
|
field: ChargesMetricFieldSchema.optional(),
|
|
645
683
|
alias: metricAliasSchema
|
|
646
684
|
});
|
|
647
|
-
var ChargesMetricsQuerySchema =
|
|
648
|
-
resource:
|
|
685
|
+
var ChargesMetricsQuerySchema = import_zod13.z.object({
|
|
686
|
+
resource: import_zod13.z.literal("charges"),
|
|
649
687
|
environment: metricsQueryEnvironmentSchema,
|
|
650
|
-
dateRange:
|
|
688
|
+
dateRange: import_zod13.z.object({
|
|
651
689
|
field: ChargesDateFieldSchema,
|
|
652
|
-
from:
|
|
653
|
-
to:
|
|
690
|
+
from: import_zod13.z.string().max(64).datetime(),
|
|
691
|
+
to: import_zod13.z.string().max(64).datetime()
|
|
654
692
|
}),
|
|
655
|
-
groupBy:
|
|
656
|
-
metrics:
|
|
657
|
-
filters:
|
|
693
|
+
groupBy: import_zod13.z.array(ChargesGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
694
|
+
metrics: import_zod13.z.array(ChargesMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
695
|
+
filters: import_zod13.z.array(ChargesFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
658
696
|
orderBy: orderBySchema.optional(),
|
|
659
697
|
limit: limitSchema
|
|
660
698
|
});
|
|
661
|
-
var TransactionsQueryFieldSchema =
|
|
699
|
+
var TransactionsQueryFieldSchema = import_zod13.z.enum(["network", "token", "source", "causedTransition"]).describe(
|
|
662
700
|
"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)."
|
|
663
701
|
);
|
|
664
|
-
var TransactionsMetricFieldSchema =
|
|
665
|
-
var TransactionsDateFieldSchema =
|
|
666
|
-
var TransactionsFilterSchema =
|
|
702
|
+
var TransactionsMetricFieldSchema = import_zod13.z.enum(["amount"]).describe("The transfer amount, in the charge's `currency` units.");
|
|
703
|
+
var TransactionsDateFieldSchema = import_zod13.z.enum(["detectedAt"]).describe("When Klappay detected this transfer on-chain (not when it was mined).");
|
|
704
|
+
var TransactionsFilterSchema = import_zod13.z.object({
|
|
667
705
|
field: TransactionsQueryFieldSchema,
|
|
668
706
|
operator: MetricsFilterOperatorSchema,
|
|
669
707
|
value: MetricsFilterValueSchema
|
|
670
708
|
});
|
|
671
|
-
var TransactionsGroupBySchema =
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
type:
|
|
709
|
+
var TransactionsGroupBySchema = import_zod13.z.union([
|
|
710
|
+
import_zod13.z.object({ type: import_zod13.z.literal("field"), field: TransactionsQueryFieldSchema }),
|
|
711
|
+
import_zod13.z.object({
|
|
712
|
+
type: import_zod13.z.literal("date_bucket"),
|
|
675
713
|
field: TransactionsDateFieldSchema,
|
|
676
714
|
granularity: MetricsDateGranularitySchema
|
|
677
715
|
})
|
|
678
716
|
]);
|
|
679
|
-
var TransactionsMetricSchema =
|
|
717
|
+
var TransactionsMetricSchema = import_zod13.z.object({
|
|
680
718
|
aggregation: MetricsAggregationSchema,
|
|
681
719
|
field: TransactionsMetricFieldSchema.optional(),
|
|
682
720
|
alias: metricAliasSchema
|
|
683
721
|
});
|
|
684
|
-
var TransactionsMetricsQuerySchema =
|
|
685
|
-
resource:
|
|
722
|
+
var TransactionsMetricsQuerySchema = import_zod13.z.object({
|
|
723
|
+
resource: import_zod13.z.literal("transactions"),
|
|
686
724
|
environment: metricsQueryEnvironmentSchema,
|
|
687
|
-
dateRange:
|
|
725
|
+
dateRange: import_zod13.z.object({
|
|
688
726
|
field: TransactionsDateFieldSchema,
|
|
689
|
-
from:
|
|
690
|
-
to:
|
|
727
|
+
from: import_zod13.z.string().max(64).datetime(),
|
|
728
|
+
to: import_zod13.z.string().max(64).datetime()
|
|
691
729
|
}),
|
|
692
|
-
groupBy:
|
|
693
|
-
metrics:
|
|
694
|
-
filters:
|
|
730
|
+
groupBy: import_zod13.z.array(TransactionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
731
|
+
metrics: import_zod13.z.array(TransactionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
732
|
+
filters: import_zod13.z.array(TransactionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
695
733
|
orderBy: orderBySchema.optional(),
|
|
696
734
|
limit: limitSchema
|
|
697
735
|
});
|
|
698
|
-
var DistributionsQueryFieldSchema =
|
|
736
|
+
var DistributionsQueryFieldSchema = import_zod13.z.enum(["status", "network", "token", "distributorAddress"]).describe(
|
|
699
737
|
"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."
|
|
700
738
|
);
|
|
701
|
-
var DistributionsMetricFieldSchema =
|
|
739
|
+
var DistributionsMetricFieldSchema = import_zod13.z.enum(["attempts"]).describe(
|
|
702
740
|
"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."
|
|
703
741
|
);
|
|
704
|
-
var DistributionsDateFieldSchema =
|
|
742
|
+
var DistributionsDateFieldSchema = import_zod13.z.enum(["createdAt", "processingStartedAt", "completedAt"]).describe(
|
|
705
743
|
"`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."
|
|
706
744
|
);
|
|
707
|
-
var DistributionsFilterSchema =
|
|
745
|
+
var DistributionsFilterSchema = import_zod13.z.object({
|
|
708
746
|
field: DistributionsQueryFieldSchema,
|
|
709
747
|
operator: MetricsFilterOperatorSchema,
|
|
710
748
|
value: MetricsFilterValueSchema
|
|
711
749
|
});
|
|
712
|
-
var DistributionsGroupBySchema =
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
type:
|
|
750
|
+
var DistributionsGroupBySchema = import_zod13.z.union([
|
|
751
|
+
import_zod13.z.object({ type: import_zod13.z.literal("field"), field: DistributionsQueryFieldSchema }),
|
|
752
|
+
import_zod13.z.object({
|
|
753
|
+
type: import_zod13.z.literal("date_bucket"),
|
|
716
754
|
field: DistributionsDateFieldSchema,
|
|
717
755
|
granularity: MetricsDateGranularitySchema
|
|
718
756
|
})
|
|
719
757
|
]);
|
|
720
|
-
var DistributionsMetricSchema =
|
|
758
|
+
var DistributionsMetricSchema = import_zod13.z.object({
|
|
721
759
|
aggregation: MetricsAggregationSchema,
|
|
722
760
|
field: DistributionsMetricFieldSchema.optional(),
|
|
723
761
|
alias: metricAliasSchema
|
|
724
762
|
});
|
|
725
|
-
var DistributionsMetricsQuerySchema =
|
|
726
|
-
resource:
|
|
763
|
+
var DistributionsMetricsQuerySchema = import_zod13.z.object({
|
|
764
|
+
resource: import_zod13.z.literal("distributions"),
|
|
727
765
|
environment: metricsQueryEnvironmentSchema,
|
|
728
|
-
dateRange:
|
|
766
|
+
dateRange: import_zod13.z.object({
|
|
729
767
|
field: DistributionsDateFieldSchema,
|
|
730
|
-
from:
|
|
731
|
-
to:
|
|
768
|
+
from: import_zod13.z.string().max(64).datetime(),
|
|
769
|
+
to: import_zod13.z.string().max(64).datetime()
|
|
732
770
|
}),
|
|
733
|
-
groupBy:
|
|
734
|
-
metrics:
|
|
735
|
-
filters:
|
|
771
|
+
groupBy: import_zod13.z.array(DistributionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
772
|
+
metrics: import_zod13.z.array(DistributionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
773
|
+
filters: import_zod13.z.array(DistributionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
736
774
|
orderBy: orderBySchema.optional(),
|
|
737
775
|
limit: limitSchema
|
|
738
776
|
});
|
|
739
777
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
740
|
-
var MetricsQuerySchema =
|
|
778
|
+
var MetricsQuerySchema = import_zod13.z.discriminatedUnion("resource", [
|
|
741
779
|
ChargesMetricsQuerySchema,
|
|
742
780
|
TransactionsMetricsQuerySchema,
|
|
743
781
|
DistributionsMetricsQuerySchema
|
|
@@ -746,7 +784,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
746
784
|
const to = new Date(input.dateRange.to);
|
|
747
785
|
if (from >= to) {
|
|
748
786
|
ctx.addIssue({
|
|
749
|
-
code:
|
|
787
|
+
code: import_zod13.z.ZodIssueCode.custom,
|
|
750
788
|
message: "`dateRange.from` must be before `dateRange.to`.",
|
|
751
789
|
path: ["dateRange", "from"]
|
|
752
790
|
});
|
|
@@ -754,7 +792,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
754
792
|
const spanDays = (to.getTime() - from.getTime()) / ONE_DAY_MS;
|
|
755
793
|
if (spanDays > MAX_METRICS_QUERY_DATE_RANGE_DAYS) {
|
|
756
794
|
ctx.addIssue({
|
|
757
|
-
code:
|
|
795
|
+
code: import_zod13.z.ZodIssueCode.custom,
|
|
758
796
|
message: `\`dateRange\` cannot span more than ${MAX_METRICS_QUERY_DATE_RANGE_DAYS} days.`,
|
|
759
797
|
path: ["dateRange", "to"]
|
|
760
798
|
});
|
|
@@ -762,7 +800,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
762
800
|
const dateBucketCount = input.groupBy.filter((entry) => entry.type === "date_bucket").length;
|
|
763
801
|
if (dateBucketCount > 1) {
|
|
764
802
|
ctx.addIssue({
|
|
765
|
-
code:
|
|
803
|
+
code: import_zod13.z.ZodIssueCode.custom,
|
|
766
804
|
message: "At most one `date_bucket` entry is allowed in `groupBy`.",
|
|
767
805
|
path: ["groupBy"]
|
|
768
806
|
});
|
|
@@ -770,7 +808,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
770
808
|
input.metrics.forEach((metric, index) => {
|
|
771
809
|
if (metric.aggregation !== "count" && metric.field === void 0) {
|
|
772
810
|
ctx.addIssue({
|
|
773
|
-
code:
|
|
811
|
+
code: import_zod13.z.ZodIssueCode.custom,
|
|
774
812
|
message: "`field` is required unless `aggregation` is `count`.",
|
|
775
813
|
path: ["metrics", index, "field"]
|
|
776
814
|
});
|
|
@@ -779,7 +817,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
779
817
|
const aliases = input.metrics.map((metric) => metric.alias).filter((alias) => alias !== void 0);
|
|
780
818
|
if (new Set(aliases).size !== aliases.length) {
|
|
781
819
|
ctx.addIssue({
|
|
782
|
-
code:
|
|
820
|
+
code: import_zod13.z.ZodIssueCode.custom,
|
|
783
821
|
message: "Every `metrics[].alias` must be unique.",
|
|
784
822
|
path: ["metrics"]
|
|
785
823
|
});
|
|
@@ -788,32 +826,32 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
788
826
|
input.metrics.forEach((metric, index) => {
|
|
789
827
|
if (metric.alias !== void 0 && reservedNames.has(metric.alias)) {
|
|
790
828
|
ctx.addIssue({
|
|
791
|
-
code:
|
|
829
|
+
code: import_zod13.z.ZodIssueCode.custom,
|
|
792
830
|
message: `\`alias\` "${metric.alias}" collides with a \`groupBy\` field name (or the reserved word "bucket") \u2014 choose a different alias.`,
|
|
793
831
|
path: ["metrics", index, "alias"]
|
|
794
832
|
});
|
|
795
833
|
}
|
|
796
834
|
});
|
|
797
835
|
});
|
|
798
|
-
var MetricsQueryResultRowSchema =
|
|
799
|
-
|
|
800
|
-
|
|
836
|
+
var MetricsQueryResultRowSchema = import_zod13.z.record(
|
|
837
|
+
import_zod13.z.string(),
|
|
838
|
+
import_zod13.z.union([import_zod13.z.string(), import_zod13.z.number(), import_zod13.z.boolean(), import_zod13.z.null()])
|
|
801
839
|
);
|
|
802
|
-
var MetricsQueryResultSchema =
|
|
803
|
-
data:
|
|
804
|
-
meta:
|
|
840
|
+
var MetricsQueryResultSchema = import_zod13.z.object({
|
|
841
|
+
data: import_zod13.z.array(MetricsQueryResultRowSchema),
|
|
842
|
+
meta: import_zod13.z.object({
|
|
805
843
|
resource: MetricsResourceSchema,
|
|
806
844
|
environment: EnvironmentSchema,
|
|
807
|
-
rowCount:
|
|
808
|
-
truncated:
|
|
845
|
+
rowCount: import_zod13.z.number().int().describe("Number of rows in `data`."),
|
|
846
|
+
truncated: import_zod13.z.boolean().describe(
|
|
809
847
|
"`true` if more rows matched than `limit` allowed \u2014 `data` holds only the first `limit`."
|
|
810
848
|
)
|
|
811
849
|
})
|
|
812
850
|
});
|
|
813
851
|
|
|
814
852
|
// src/webhook-events.ts
|
|
815
|
-
var
|
|
816
|
-
var ChargeWebhookEventTypeSchema =
|
|
853
|
+
var import_zod14 = require("zod");
|
|
854
|
+
var ChargeWebhookEventTypeSchema = import_zod14.z.enum([
|
|
817
855
|
"charge.created",
|
|
818
856
|
"charge.partially_paid",
|
|
819
857
|
"charge.confirmed",
|
|
@@ -825,14 +863,14 @@ var ChargeWebhookEventTypeSchema = import_zod12.z.enum([
|
|
|
825
863
|
]).describe(
|
|
826
864
|
'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`). Every event in this category carries the full `Charge` object as `data`.'
|
|
827
865
|
);
|
|
828
|
-
var WebhookDeliveryEventTypeSchema =
|
|
866
|
+
var WebhookDeliveryEventTypeSchema = import_zod14.z.enum(["webhook.delivery_failed", "webhook.delivery_recovered", "webhook.endpoint_unhealthy"]).describe(
|
|
829
867
|
"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`)."
|
|
830
868
|
);
|
|
831
|
-
var WebhookEventTypeSchema =
|
|
869
|
+
var WebhookEventTypeSchema = import_zod14.z.union([
|
|
832
870
|
ChargeWebhookEventTypeSchema,
|
|
833
871
|
WebhookDeliveryEventTypeSchema
|
|
834
872
|
]);
|
|
835
|
-
var WebhookCategorySchema =
|
|
873
|
+
var WebhookCategorySchema = import_zod14.z.enum(["payments", "webhooks"]).describe(
|
|
836
874
|
"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."
|
|
837
875
|
);
|
|
838
876
|
function buildCategoryMap() {
|
|
@@ -860,101 +898,101 @@ var TriggerableChargeEventSchema = ChargeWebhookEventTypeSchema.exclude([
|
|
|
860
898
|
);
|
|
861
899
|
|
|
862
900
|
// src/webhooks.ts
|
|
863
|
-
var
|
|
901
|
+
var import_zod15 = require("zod");
|
|
864
902
|
var WEBHOOK_EVENTS_WILDCARD = "*";
|
|
865
|
-
var CreateWebhookSchema =
|
|
866
|
-
url:
|
|
903
|
+
var CreateWebhookSchema = import_zod15.z.object({
|
|
904
|
+
url: import_zod15.z.string().max(2048).url().describe(
|
|
867
905
|
"Must be HTTPS and resolve to a public address \u2014 private/internal IPs are rejected."
|
|
868
906
|
),
|
|
869
|
-
events:
|
|
907
|
+
events: import_zod15.z.array(import_zod15.z.union([WebhookEventTypeSchema, import_zod15.z.literal(WEBHOOK_EVENTS_WILDCARD)])).max(Object.keys(EVENT_CATEGORY_MAP).length + 1).default([]).describe(
|
|
870
908
|
'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.'
|
|
871
909
|
),
|
|
872
|
-
eventCategories:
|
|
910
|
+
eventCategories: import_zod15.z.array(WebhookCategorySchema).max(WebhookCategorySchema.options.length).default([]).describe(
|
|
873
911
|
"Subscribe to every event in these categories. At least one of `events` or `eventCategories` is required."
|
|
874
912
|
),
|
|
875
|
-
excludeEvents:
|
|
913
|
+
excludeEvents: import_zod15.z.array(WebhookEventTypeSchema).max(Object.keys(EVENT_CATEGORY_MAP).length).default([]).describe(
|
|
876
914
|
'Event types to exclude even if selected via `events: ["*"]` or `eventCategories`.'
|
|
877
915
|
)
|
|
878
916
|
}).refine((v) => v.events.length > 0 || v.eventCategories.length > 0, {
|
|
879
917
|
message: "must select at least one event via `events` or `eventCategories`",
|
|
880
918
|
path: ["events"]
|
|
881
919
|
});
|
|
882
|
-
var WebhookSchema =
|
|
883
|
-
id:
|
|
920
|
+
var WebhookSchema = import_zod15.z.object({
|
|
921
|
+
id: import_zod15.z.string(),
|
|
884
922
|
environment: EnvironmentSchema.nullable().describe(
|
|
885
923
|
"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)."
|
|
886
924
|
),
|
|
887
|
-
url:
|
|
888
|
-
events:
|
|
889
|
-
eventCategories:
|
|
890
|
-
excludeEvents:
|
|
891
|
-
isWildcard:
|
|
892
|
-
secret:
|
|
925
|
+
url: import_zod15.z.string(),
|
|
926
|
+
events: import_zod15.z.array(WebhookEventTypeSchema),
|
|
927
|
+
eventCategories: import_zod15.z.array(WebhookCategorySchema),
|
|
928
|
+
excludeEvents: import_zod15.z.array(WebhookEventTypeSchema),
|
|
929
|
+
isWildcard: import_zod15.z.boolean(),
|
|
930
|
+
secret: import_zod15.z.string().describe(
|
|
893
931
|
"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."
|
|
894
932
|
),
|
|
895
|
-
createdAt:
|
|
933
|
+
createdAt: import_zod15.z.string().datetime()
|
|
896
934
|
});
|
|
897
935
|
var WebhookListItemSchema = WebhookSchema.omit({ secret: true }).extend({
|
|
898
|
-
hint:
|
|
936
|
+
hint: import_zod15.z.string().describe("A truncated, safe-to-display form of the secret (e.g. `whsec_...ab12`).")
|
|
899
937
|
});
|
|
900
|
-
var WebhookPayloadSchema =
|
|
901
|
-
id:
|
|
938
|
+
var WebhookPayloadSchema = import_zod15.z.object({
|
|
939
|
+
id: import_zod15.z.string().describe(
|
|
902
940
|
"Unique id for this specific delivery \u2014 also sent as the `X-Klappay-Delivery` header."
|
|
903
941
|
),
|
|
904
942
|
event: WebhookEventTypeSchema,
|
|
905
|
-
createdAt:
|
|
906
|
-
data:
|
|
943
|
+
createdAt: import_zod15.z.string().datetime(),
|
|
944
|
+
data: import_zod15.z.unknown().describe(
|
|
907
945
|
"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."
|
|
908
946
|
)
|
|
909
947
|
});
|
|
910
|
-
var WebhookDeliveryStatusSchema =
|
|
911
|
-
var WebhookDeliverySchema =
|
|
912
|
-
id:
|
|
913
|
-
webhookId:
|
|
948
|
+
var WebhookDeliveryStatusSchema = import_zod15.z.enum(["pending", "delivered", "failed"]);
|
|
949
|
+
var WebhookDeliverySchema = import_zod15.z.object({
|
|
950
|
+
id: import_zod15.z.string(),
|
|
951
|
+
webhookId: import_zod15.z.string(),
|
|
914
952
|
event: WebhookEventTypeSchema,
|
|
915
953
|
status: WebhookDeliveryStatusSchema.describe(
|
|
916
954
|
"`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."
|
|
917
955
|
),
|
|
918
|
-
attempts:
|
|
919
|
-
responseCode:
|
|
956
|
+
attempts: import_zod15.z.number(),
|
|
957
|
+
responseCode: import_zod15.z.number().nullable().describe(
|
|
920
958
|
"HTTP status your endpoint returned on the most recent attempt. `null` if every attempt failed to connect at all."
|
|
921
959
|
),
|
|
922
|
-
nextRetryAt:
|
|
923
|
-
deliveredAt:
|
|
924
|
-
createdAt:
|
|
960
|
+
nextRetryAt: import_zod15.z.string().datetime().nullable(),
|
|
961
|
+
deliveredAt: import_zod15.z.string().datetime().nullable(),
|
|
962
|
+
createdAt: import_zod15.z.string().datetime()
|
|
925
963
|
});
|
|
926
964
|
var ListWebhookDeliveriesSchema = PaginationQuerySchema;
|
|
927
965
|
var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
928
966
|
|
|
929
967
|
// src/recipients.ts
|
|
930
|
-
var
|
|
968
|
+
var import_zod16 = require("zod");
|
|
931
969
|
var EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
932
|
-
var CreateRecipientSchema =
|
|
933
|
-
address:
|
|
934
|
-
label:
|
|
970
|
+
var CreateRecipientSchema = import_zod16.z.object({
|
|
971
|
+
address: import_zod16.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."),
|
|
972
|
+
label: import_zod16.z.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
935
973
|
});
|
|
936
|
-
var RecipientSchema =
|
|
937
|
-
id:
|
|
974
|
+
var RecipientSchema = import_zod16.z.object({
|
|
975
|
+
id: import_zod16.z.string().describe(
|
|
938
976
|
"Klappay-generated id, e.g. `rc_...` \u2014 this, not the raw address, is what a charge's `splitRecipients[].recipientId` references."
|
|
939
977
|
),
|
|
940
978
|
environment: EnvironmentSchema,
|
|
941
|
-
address:
|
|
942
|
-
label:
|
|
943
|
-
payout:
|
|
979
|
+
address: import_zod16.z.string(),
|
|
980
|
+
label: import_zod16.z.string().nullable(),
|
|
981
|
+
payout: import_zod16.z.boolean().describe(
|
|
944
982
|
"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`."
|
|
945
983
|
),
|
|
946
|
-
createdAt:
|
|
984
|
+
createdAt: import_zod16.z.string().datetime()
|
|
947
985
|
});
|
|
948
|
-
var SetRecipientPayoutSchema =
|
|
949
|
-
payout:
|
|
986
|
+
var SetRecipientPayoutSchema = import_zod16.z.object({
|
|
987
|
+
payout: import_zod16.z.boolean().describe("New payout-eligibility value for this recipient.")
|
|
950
988
|
});
|
|
951
989
|
|
|
952
990
|
// src/timeline.ts
|
|
953
|
-
var
|
|
954
|
-
var TransactionSourceSchema =
|
|
991
|
+
var import_zod17 = require("zod");
|
|
992
|
+
var TransactionSourceSchema = import_zod17.z.enum(["moralis_webhook", "reconciliation_job", "sandbox"]).describe(
|
|
955
993
|
"How this transfer was detected: `moralis_webhook` (the normal path), `reconciliation_job` (a fallback poller caught it after the webhook was missed or delayed), or `sandbox` (simulated via `POST /v1/sandbox/charges/{id}/trigger`, no real on-chain transfer)."
|
|
956
994
|
);
|
|
957
|
-
var TimelineEventTypeSchema =
|
|
995
|
+
var TimelineEventTypeSchema = import_zod17.z.enum([
|
|
958
996
|
"charge.created",
|
|
959
997
|
"charge.expired",
|
|
960
998
|
"transaction.detected",
|
|
@@ -965,11 +1003,11 @@ var TimelineEventTypeSchema = import_zod15.z.enum([
|
|
|
965
1003
|
]).describe(
|
|
966
1004
|
"`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)."
|
|
967
1005
|
);
|
|
968
|
-
var TimelineEventSchema =
|
|
1006
|
+
var TimelineEventSchema = import_zod17.z.object({
|
|
969
1007
|
type: TimelineEventTypeSchema,
|
|
970
|
-
at:
|
|
971
|
-
txHash:
|
|
972
|
-
amount:
|
|
1008
|
+
at: import_zod17.z.string().datetime(),
|
|
1009
|
+
txHash: import_zod17.z.string().optional().describe("Present for `transaction.detected` and `split.distributed` events only."),
|
|
1010
|
+
amount: import_zod17.z.number().optional().describe(
|
|
973
1011
|
"Present for `transaction.detected` events only \u2014 the amount that specific transfer carried."
|
|
974
1012
|
),
|
|
975
1013
|
source: TransactionSourceSchema.optional().describe(
|
|
@@ -981,102 +1019,102 @@ var TimelineEventSchema = import_zod15.z.object({
|
|
|
981
1019
|
network: NetworkSchema.optional().describe(
|
|
982
1020
|
"Present for `transaction.detected` and `split.distributed` events \u2014 which network this specific transfer, or settlement, used."
|
|
983
1021
|
),
|
|
984
|
-
causedTransition:
|
|
1022
|
+
causedTransition: import_zod17.z.boolean().optional().describe(
|
|
985
1023
|
"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."
|
|
986
1024
|
),
|
|
987
1025
|
event: WebhookEventTypeSchema.optional().describe(
|
|
988
1026
|
"Present for `webhook.*` events only \u2014 which event type this delivery was for."
|
|
989
1027
|
),
|
|
990
|
-
responseCode:
|
|
1028
|
+
responseCode: import_zod17.z.number().nullable().optional().describe(
|
|
991
1029
|
"Present for `webhook.*` events only \u2014 HTTP status your endpoint returned, or `null` if the request never connected."
|
|
992
1030
|
),
|
|
993
|
-
attempts:
|
|
1031
|
+
attempts: import_zod17.z.number().optional().describe(
|
|
994
1032
|
"Present for `webhook.*` events only \u2014 how many delivery attempts have been made so far."
|
|
995
1033
|
)
|
|
996
1034
|
});
|
|
997
1035
|
|
|
998
1036
|
// src/health.ts
|
|
999
|
-
var
|
|
1000
|
-
var HealthSchema =
|
|
1001
|
-
status:
|
|
1037
|
+
var import_zod18 = require("zod");
|
|
1038
|
+
var HealthSchema = import_zod18.z.object({
|
|
1039
|
+
status: import_zod18.z.enum(["ok", "error"]).describe(
|
|
1002
1040
|
"`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."
|
|
1003
1041
|
),
|
|
1004
|
-
version:
|
|
1005
|
-
timestamp:
|
|
1006
|
-
db:
|
|
1007
|
-
pendingWebhooks:
|
|
1008
|
-
oldestPendingChargeAgeSeconds:
|
|
1009
|
-
lastMoralisEventAgeSeconds:
|
|
1042
|
+
version: import_zod18.z.string(),
|
|
1043
|
+
timestamp: import_zod18.z.string().datetime(),
|
|
1044
|
+
db: import_zod18.z.enum(["ok", "error"]).describe("Result of a real database connectivity check, not just a process-alive check."),
|
|
1045
|
+
pendingWebhooks: import_zod18.z.number().describe("Count of webhook deliveries still awaiting a successful attempt."),
|
|
1046
|
+
oldestPendingChargeAgeSeconds: import_zod18.z.number().nullable().describe("Age of the oldest still-unpaid charge, in seconds. `null` if there are none."),
|
|
1047
|
+
lastMoralisEventAgeSeconds: import_zod18.z.number().nullable().describe(
|
|
1010
1048
|
"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."
|
|
1011
1049
|
)
|
|
1012
1050
|
});
|
|
1013
1051
|
|
|
1014
1052
|
// src/sandbox.ts
|
|
1015
|
-
var
|
|
1016
|
-
var SandboxTriggerSchema =
|
|
1053
|
+
var import_zod19 = require("zod");
|
|
1054
|
+
var SandboxTriggerSchema = import_zod19.z.object({
|
|
1017
1055
|
event: TriggerableChargeEventSchema,
|
|
1018
|
-
amount:
|
|
1056
|
+
amount: import_zod19.z.number().positive().max(CHARGE_AMOUNT_MAX).optional().describe(
|
|
1019
1057
|
"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."
|
|
1020
1058
|
)
|
|
1021
1059
|
});
|
|
1022
1060
|
|
|
1023
1061
|
// src/capabilities.ts
|
|
1024
|
-
var
|
|
1025
|
-
var CapabilitiesSchema =
|
|
1026
|
-
acceptedPayments:
|
|
1062
|
+
var import_zod20 = require("zod");
|
|
1063
|
+
var CapabilitiesSchema = import_zod20.z.object({
|
|
1064
|
+
acceptedPayments: import_zod20.z.array(AcceptedPaymentSchema).describe(
|
|
1027
1065
|
"Every `(token, network)` pair actually configured for your environment right now \u2014 read straight from the same lookup `POST /v1/charges` validates `acceptedPayments` against, so it can never list a pair that charge creation would then reject. Use this to build a picker UI instead of hardcoding the matrix client-side."
|
|
1028
1066
|
)
|
|
1029
1067
|
});
|
|
1030
1068
|
|
|
1031
1069
|
// src/swap.ts
|
|
1032
|
-
var
|
|
1033
|
-
var CreateSwapQuoteSchema =
|
|
1070
|
+
var import_zod21 = require("zod");
|
|
1071
|
+
var CreateSwapQuoteSchema = import_zod21.z.object({
|
|
1034
1072
|
inputToken: AltTokenSchema.describe(
|
|
1035
1073
|
"Which alt-cryptocurrency the payer wants to send \u2014 must be one of this charge's `swapAlternatives`, or `422 token_not_supported`."
|
|
1036
1074
|
),
|
|
1037
1075
|
inputNetwork: NetworkSchema.describe(
|
|
1038
1076
|
"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 breaks the tie using its own trust ranking for that network (e.g. USDT over USDC on BNB Chain, where \"USDC\" is a third-party Binance-Peg token, not Circle's) \u2014 never a token the charge doesn't actually accept."
|
|
1039
1077
|
),
|
|
1040
|
-
takerAddress:
|
|
1078
|
+
takerAddress: import_zod21.z.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe(
|
|
1041
1079
|
"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."
|
|
1042
1080
|
)
|
|
1043
1081
|
});
|
|
1044
|
-
var SwapQuoteSchema =
|
|
1082
|
+
var SwapQuoteSchema = import_zod21.z.object({
|
|
1045
1083
|
inputToken: AltTokenSchema,
|
|
1046
1084
|
inputNetwork: NetworkSchema,
|
|
1047
|
-
inputAmount:
|
|
1085
|
+
inputAmount: import_zod21.z.number().describe(
|
|
1048
1086
|
"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."
|
|
1049
1087
|
),
|
|
1050
1088
|
outputToken: TokenSchema.describe(
|
|
1051
1089
|
"Which of this charge's `acceptedPayments` tokens the swap resolves to."
|
|
1052
1090
|
),
|
|
1053
1091
|
outputNetwork: NetworkSchema,
|
|
1054
|
-
outputAmount:
|
|
1092
|
+
outputAmount: import_zod21.z.number().describe(
|
|
1055
1093
|
"The exact remaining amount owed on this charge (`amount - amountReceived`), in `currency` units \u2014 always what the merchant's split address receives, regardless of `inputAmount`."
|
|
1056
1094
|
),
|
|
1057
|
-
fees:
|
|
1058
|
-
klappayFee:
|
|
1095
|
+
fees: import_zod21.z.object({
|
|
1096
|
+
klappayFee: import_zod21.z.number().describe(
|
|
1059
1097
|
"Klappay's own swap fee (1% today), in `outputToken` units \u2014 paid by the payer, on top of `inputAmount`, separate from the merchant's own `feePercent`. Never subtracted from `outputAmount`."
|
|
1060
1098
|
),
|
|
1061
|
-
zeroExFee:
|
|
1099
|
+
zeroExFee: import_zod21.z.number().nullable().describe(
|
|
1062
1100
|
"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. Also paid by the payer on top of `inputAmount`, also never subtracted from `outputAmount` \u2014 Klappay never sees this fee, it goes straight to 0x."
|
|
1063
1101
|
)
|
|
1064
1102
|
}).describe(
|
|
1065
1103
|
"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`."
|
|
1066
1104
|
),
|
|
1067
|
-
expiresAt:
|
|
1105
|
+
expiresAt: import_zod21.z.string().datetime().describe(
|
|
1068
1106
|
"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."
|
|
1069
1107
|
),
|
|
1070
|
-
transaction:
|
|
1071
|
-
to:
|
|
1072
|
-
data:
|
|
1073
|
-
value:
|
|
1108
|
+
transaction: import_zod21.z.object({
|
|
1109
|
+
to: import_zod21.z.string().describe("Contract address the payer's wallet must send this transaction to."),
|
|
1110
|
+
data: import_zod21.z.string().describe("Calldata \u2014 opaque, must be sent unmodified."),
|
|
1111
|
+
value: import_zod21.z.string().describe(
|
|
1074
1112
|
"Native currency (ETH/BNB/MATIC/AVAX) to attach, in wei \u2014 `\"0\"` when `inputToken` isn't this network's native currency."
|
|
1075
1113
|
)
|
|
1076
1114
|
}).describe(
|
|
1077
1115
|
"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."
|
|
1078
1116
|
),
|
|
1079
|
-
permit2:
|
|
1117
|
+
permit2: import_zod21.z.object({ eip712: import_zod21.z.record(import_zod21.z.unknown()) }).nullish().describe(
|
|
1080
1118
|
"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."
|
|
1081
1119
|
)
|
|
1082
1120
|
});
|
|
@@ -1103,6 +1141,7 @@ var SwapQuoteSchema = import_zod19.z.object({
|
|
|
1103
1141
|
ChargesDateFieldSchema,
|
|
1104
1142
|
ChargesMetricFieldSchema,
|
|
1105
1143
|
ChargesQueryFieldSchema,
|
|
1144
|
+
CheckChargeRequestSchema,
|
|
1106
1145
|
CheckoutProductSchema,
|
|
1107
1146
|
CreateChargeSchema,
|
|
1108
1147
|
CreateRecipientSchema,
|
|
@@ -1115,6 +1154,7 @@ var SwapQuoteSchema = import_zod19.z.object({
|
|
|
1115
1154
|
EVM_NETWORKS,
|
|
1116
1155
|
EnvironmentSchema,
|
|
1117
1156
|
ErrorPayloadSchema,
|
|
1157
|
+
EscrowConfigSchema,
|
|
1118
1158
|
GetChargeQrCodeQuerySchema,
|
|
1119
1159
|
HealthSchema,
|
|
1120
1160
|
KlappayCheckoutMetadataSchema,
|
|
@@ -1150,6 +1190,7 @@ var SwapQuoteSchema = import_zod19.z.object({
|
|
|
1150
1190
|
PendingDistributionRecipientSchema,
|
|
1151
1191
|
PendingDistributionSchema,
|
|
1152
1192
|
RecipientSchema,
|
|
1193
|
+
ReleaseEscrowRequestSchema,
|
|
1153
1194
|
SandboxTriggerSchema,
|
|
1154
1195
|
SetRecipientPayoutSchema,
|
|
1155
1196
|
SettlementStatusSchema,
|