@klappay/types 3.1.1 → 3.2.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 +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +202 -187
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -187
- 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,
|
|
@@ -525,62 +526,75 @@ var GetChargeQrCodeQuerySchema = import_zod9.z.object({
|
|
|
525
526
|
network: NetworkSchema.optional()
|
|
526
527
|
});
|
|
527
528
|
|
|
528
|
-
// src/
|
|
529
|
+
// src/charge-check.ts
|
|
529
530
|
var import_zod10 = require("zod");
|
|
530
|
-
var
|
|
531
|
+
var CheckChargeRequestSchema = import_zod10.z.object({
|
|
532
|
+
txHash: import_zod10.z.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be a 32-byte transaction hash").optional().describe(
|
|
533
|
+
"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."
|
|
534
|
+
),
|
|
535
|
+
network: NetworkSchema.optional().describe(
|
|
536
|
+
"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`."
|
|
537
|
+
)
|
|
538
|
+
}).refine((data) => Boolean(data.txHash) === Boolean(data.network), {
|
|
539
|
+
message: "`txHash` and `network` must be provided together, or both omitted"
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// src/distributions.ts
|
|
543
|
+
var import_zod11 = require("zod");
|
|
544
|
+
var SplitDistributionStatusSchema = import_zod11.z.enum(["pending", "processing", "completed", "failed"]).describe(
|
|
531
545
|
"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
546
|
);
|
|
533
|
-
var PendingDistributionRecipientSchema =
|
|
534
|
-
address:
|
|
535
|
-
percentAllocation:
|
|
547
|
+
var PendingDistributionRecipientSchema = import_zod11.z.object({
|
|
548
|
+
address: import_zod11.z.string().describe("On-chain recipient address."),
|
|
549
|
+
percentAllocation: import_zod11.z.number().describe("This recipient's share of the split, as a percentage (e.g. `99.0991` = 99.0991%).")
|
|
536
550
|
});
|
|
537
|
-
var PendingDistributionSchema =
|
|
538
|
-
splitAddress:
|
|
551
|
+
var PendingDistributionSchema = import_zod11.z.object({
|
|
552
|
+
splitAddress: import_zod11.z.string().describe("The on-chain 0xSplits address to call `distribute()` on."),
|
|
539
553
|
network: NetworkSchema,
|
|
540
554
|
token: TokenSchema,
|
|
541
|
-
recipients:
|
|
555
|
+
recipients: import_zod11.z.array(PendingDistributionRecipientSchema).describe(
|
|
542
556
|
"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
557
|
),
|
|
544
|
-
distributorFeePercent:
|
|
558
|
+
distributorFeePercent: import_zod11.z.number().describe(
|
|
545
559
|
"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
560
|
),
|
|
547
|
-
estimatedRewardAmount:
|
|
561
|
+
estimatedRewardAmount: import_zod11.z.number().describe(
|
|
548
562
|
"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
563
|
),
|
|
550
|
-
availableSince:
|
|
551
|
-
graceEndsAt:
|
|
564
|
+
availableSince: import_zod11.z.string().datetime().describe("When this distribution entered its grace period."),
|
|
565
|
+
graceEndsAt: import_zod11.z.string().datetime().describe(
|
|
552
566
|
"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
567
|
)
|
|
554
568
|
});
|
|
555
569
|
var PaginatedPendingDistributionsSchema = paginatedSchema(PendingDistributionSchema);
|
|
556
|
-
var ListenPendingDistributionsQuerySchema =
|
|
557
|
-
limit:
|
|
570
|
+
var ListenPendingDistributionsQuerySchema = import_zod11.z.object({
|
|
571
|
+
limit: import_zod11.z.coerce.number().int().min(0).max(PAGINATION_LIMIT_MAX).default(0).describe(
|
|
558
572
|
"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
573
|
)
|
|
560
574
|
});
|
|
561
|
-
var PendingDistributionEventSchema =
|
|
562
|
-
|
|
563
|
-
type:
|
|
575
|
+
var PendingDistributionEventSchema = import_zod11.z.discriminatedUnion("type", [
|
|
576
|
+
import_zod11.z.object({
|
|
577
|
+
type: import_zod11.z.literal("distribution.available"),
|
|
564
578
|
distribution: PendingDistributionSchema
|
|
565
579
|
}),
|
|
566
|
-
|
|
567
|
-
type:
|
|
568
|
-
splitAddress:
|
|
580
|
+
import_zod11.z.object({
|
|
581
|
+
type: import_zod11.z.literal("distribution.claimed"),
|
|
582
|
+
splitAddress: import_zod11.z.string().describe("No longer claimable \u2014 either settled by someone, or picked up by the worker.")
|
|
569
583
|
})
|
|
570
584
|
]);
|
|
571
585
|
|
|
572
586
|
// src/metrics.ts
|
|
573
|
-
var
|
|
574
|
-
var MetricsResourceSchema =
|
|
587
|
+
var import_zod12 = require("zod");
|
|
588
|
+
var MetricsResourceSchema = import_zod12.z.enum(["charges", "transactions", "distributions"]).describe(
|
|
575
589
|
"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
590
|
);
|
|
577
|
-
var MetricsAggregationSchema =
|
|
591
|
+
var MetricsAggregationSchema = import_zod12.z.enum(["count", "sum", "avg", "min", "max"]).describe(
|
|
578
592
|
"`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
593
|
);
|
|
580
|
-
var MetricsFilterOperatorSchema =
|
|
594
|
+
var MetricsFilterOperatorSchema = import_zod12.z.enum(["eq", "neq", "in", "gt", "gte", "lt", "lte"]).describe(
|
|
581
595
|
"`in` expects an array value (max 50 entries); every other operator expects a single scalar."
|
|
582
596
|
);
|
|
583
|
-
var MetricsDateGranularitySchema =
|
|
597
|
+
var MetricsDateGranularitySchema = import_zod12.z.enum(["day", "week", "month", "year"]).describe(
|
|
584
598
|
"Bucket width for a `date_bucket` `groupBy` entry \u2014 Postgres `date_trunc` semantics (UTC)."
|
|
585
599
|
);
|
|
586
600
|
var metricsQueryEnvironmentSchema = EnvironmentSchema.describe(
|
|
@@ -593,151 +607,151 @@ var METRICS_QUERY_MAX_GROUP_BY = 3;
|
|
|
593
607
|
var METRICS_QUERY_MAX_FILTERS = 20;
|
|
594
608
|
var METRICS_QUERY_MAX_METRICS = 10;
|
|
595
609
|
var METRIC_ALIAS_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
596
|
-
var metricAliasSchema =
|
|
610
|
+
var metricAliasSchema = import_zod12.z.string().min(1).max(64).regex(
|
|
597
611
|
METRIC_ALIAS_PATTERN,
|
|
598
612
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 this becomes a SQL column alias."
|
|
599
613
|
).optional();
|
|
600
|
-
var MetricsFilterValueSchema =
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
614
|
+
var MetricsFilterValueSchema = import_zod12.z.union([
|
|
615
|
+
import_zod12.z.string().max(255),
|
|
616
|
+
import_zod12.z.number(),
|
|
617
|
+
import_zod12.z.boolean(),
|
|
618
|
+
import_zod12.z.array(import_zod12.z.union([import_zod12.z.string().max(255), import_zod12.z.number()])).min(1).max(50)
|
|
605
619
|
]);
|
|
606
|
-
var orderBySchema =
|
|
607
|
-
key:
|
|
620
|
+
var orderBySchema = import_zod12.z.object({
|
|
621
|
+
key: import_zod12.z.string().min(1).max(64).regex(
|
|
608
622
|
METRIC_ALIAS_PATTERN,
|
|
609
623
|
"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
624
|
).describe(
|
|
611
625
|
"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
626
|
),
|
|
613
|
-
direction:
|
|
627
|
+
direction: import_zod12.z.enum(["asc", "desc"])
|
|
614
628
|
}).describe(
|
|
615
629
|
"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
630
|
);
|
|
617
|
-
var limitSchema =
|
|
631
|
+
var limitSchema = import_zod12.z.number().int().min(1).max(METRICS_QUERY_MAX_ROW_LIMIT).default(METRICS_QUERY_DEFAULT_ROW_LIMIT).describe(
|
|
618
632
|
`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
633
|
);
|
|
620
|
-
var ChargesQueryFieldSchema =
|
|
634
|
+
var ChargesQueryFieldSchema = import_zod12.z.enum(["status", "source", "apiKeyId", "currency", "isOverpaid", "externalRef"]).describe(
|
|
621
635
|
"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
636
|
);
|
|
623
|
-
var ChargesMetricFieldSchema =
|
|
637
|
+
var ChargesMetricFieldSchema = import_zod12.z.enum(["amount", "amountReceived", "feePercent"]).describe(
|
|
624
638
|
"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
639
|
);
|
|
626
|
-
var ChargesDateFieldSchema =
|
|
640
|
+
var ChargesDateFieldSchema = import_zod12.z.enum(["createdAt", "confirmedAt", "lastActivityAt", "expiresAt"]).describe(
|
|
627
641
|
"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
642
|
);
|
|
629
|
-
var ChargesFilterSchema =
|
|
643
|
+
var ChargesFilterSchema = import_zod12.z.object({
|
|
630
644
|
field: ChargesQueryFieldSchema,
|
|
631
645
|
operator: MetricsFilterOperatorSchema,
|
|
632
646
|
value: MetricsFilterValueSchema
|
|
633
647
|
});
|
|
634
|
-
var ChargesGroupBySchema =
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
type:
|
|
648
|
+
var ChargesGroupBySchema = import_zod12.z.union([
|
|
649
|
+
import_zod12.z.object({ type: import_zod12.z.literal("field"), field: ChargesQueryFieldSchema }),
|
|
650
|
+
import_zod12.z.object({
|
|
651
|
+
type: import_zod12.z.literal("date_bucket"),
|
|
638
652
|
field: ChargesDateFieldSchema,
|
|
639
653
|
granularity: MetricsDateGranularitySchema
|
|
640
654
|
})
|
|
641
655
|
]);
|
|
642
|
-
var ChargesMetricSchema =
|
|
656
|
+
var ChargesMetricSchema = import_zod12.z.object({
|
|
643
657
|
aggregation: MetricsAggregationSchema,
|
|
644
658
|
field: ChargesMetricFieldSchema.optional(),
|
|
645
659
|
alias: metricAliasSchema
|
|
646
660
|
});
|
|
647
|
-
var ChargesMetricsQuerySchema =
|
|
648
|
-
resource:
|
|
661
|
+
var ChargesMetricsQuerySchema = import_zod12.z.object({
|
|
662
|
+
resource: import_zod12.z.literal("charges"),
|
|
649
663
|
environment: metricsQueryEnvironmentSchema,
|
|
650
|
-
dateRange:
|
|
664
|
+
dateRange: import_zod12.z.object({
|
|
651
665
|
field: ChargesDateFieldSchema,
|
|
652
|
-
from:
|
|
653
|
-
to:
|
|
666
|
+
from: import_zod12.z.string().max(64).datetime(),
|
|
667
|
+
to: import_zod12.z.string().max(64).datetime()
|
|
654
668
|
}),
|
|
655
|
-
groupBy:
|
|
656
|
-
metrics:
|
|
657
|
-
filters:
|
|
669
|
+
groupBy: import_zod12.z.array(ChargesGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
670
|
+
metrics: import_zod12.z.array(ChargesMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
671
|
+
filters: import_zod12.z.array(ChargesFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
658
672
|
orderBy: orderBySchema.optional(),
|
|
659
673
|
limit: limitSchema
|
|
660
674
|
});
|
|
661
|
-
var TransactionsQueryFieldSchema =
|
|
675
|
+
var TransactionsQueryFieldSchema = import_zod12.z.enum(["network", "token", "source", "causedTransition"]).describe(
|
|
662
676
|
"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
677
|
);
|
|
664
|
-
var TransactionsMetricFieldSchema =
|
|
665
|
-
var TransactionsDateFieldSchema =
|
|
666
|
-
var TransactionsFilterSchema =
|
|
678
|
+
var TransactionsMetricFieldSchema = import_zod12.z.enum(["amount"]).describe("The transfer amount, in the charge's `currency` units.");
|
|
679
|
+
var TransactionsDateFieldSchema = import_zod12.z.enum(["detectedAt"]).describe("When Klappay detected this transfer on-chain (not when it was mined).");
|
|
680
|
+
var TransactionsFilterSchema = import_zod12.z.object({
|
|
667
681
|
field: TransactionsQueryFieldSchema,
|
|
668
682
|
operator: MetricsFilterOperatorSchema,
|
|
669
683
|
value: MetricsFilterValueSchema
|
|
670
684
|
});
|
|
671
|
-
var TransactionsGroupBySchema =
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
type:
|
|
685
|
+
var TransactionsGroupBySchema = import_zod12.z.union([
|
|
686
|
+
import_zod12.z.object({ type: import_zod12.z.literal("field"), field: TransactionsQueryFieldSchema }),
|
|
687
|
+
import_zod12.z.object({
|
|
688
|
+
type: import_zod12.z.literal("date_bucket"),
|
|
675
689
|
field: TransactionsDateFieldSchema,
|
|
676
690
|
granularity: MetricsDateGranularitySchema
|
|
677
691
|
})
|
|
678
692
|
]);
|
|
679
|
-
var TransactionsMetricSchema =
|
|
693
|
+
var TransactionsMetricSchema = import_zod12.z.object({
|
|
680
694
|
aggregation: MetricsAggregationSchema,
|
|
681
695
|
field: TransactionsMetricFieldSchema.optional(),
|
|
682
696
|
alias: metricAliasSchema
|
|
683
697
|
});
|
|
684
|
-
var TransactionsMetricsQuerySchema =
|
|
685
|
-
resource:
|
|
698
|
+
var TransactionsMetricsQuerySchema = import_zod12.z.object({
|
|
699
|
+
resource: import_zod12.z.literal("transactions"),
|
|
686
700
|
environment: metricsQueryEnvironmentSchema,
|
|
687
|
-
dateRange:
|
|
701
|
+
dateRange: import_zod12.z.object({
|
|
688
702
|
field: TransactionsDateFieldSchema,
|
|
689
|
-
from:
|
|
690
|
-
to:
|
|
703
|
+
from: import_zod12.z.string().max(64).datetime(),
|
|
704
|
+
to: import_zod12.z.string().max(64).datetime()
|
|
691
705
|
}),
|
|
692
|
-
groupBy:
|
|
693
|
-
metrics:
|
|
694
|
-
filters:
|
|
706
|
+
groupBy: import_zod12.z.array(TransactionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
707
|
+
metrics: import_zod12.z.array(TransactionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
708
|
+
filters: import_zod12.z.array(TransactionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
695
709
|
orderBy: orderBySchema.optional(),
|
|
696
710
|
limit: limitSchema
|
|
697
711
|
});
|
|
698
|
-
var DistributionsQueryFieldSchema =
|
|
712
|
+
var DistributionsQueryFieldSchema = import_zod12.z.enum(["status", "network", "token", "distributorAddress"]).describe(
|
|
699
713
|
"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
714
|
);
|
|
701
|
-
var DistributionsMetricFieldSchema =
|
|
715
|
+
var DistributionsMetricFieldSchema = import_zod12.z.enum(["attempts"]).describe(
|
|
702
716
|
"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
717
|
);
|
|
704
|
-
var DistributionsDateFieldSchema =
|
|
718
|
+
var DistributionsDateFieldSchema = import_zod12.z.enum(["createdAt", "processingStartedAt", "completedAt"]).describe(
|
|
705
719
|
"`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
720
|
);
|
|
707
|
-
var DistributionsFilterSchema =
|
|
721
|
+
var DistributionsFilterSchema = import_zod12.z.object({
|
|
708
722
|
field: DistributionsQueryFieldSchema,
|
|
709
723
|
operator: MetricsFilterOperatorSchema,
|
|
710
724
|
value: MetricsFilterValueSchema
|
|
711
725
|
});
|
|
712
|
-
var DistributionsGroupBySchema =
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
type:
|
|
726
|
+
var DistributionsGroupBySchema = import_zod12.z.union([
|
|
727
|
+
import_zod12.z.object({ type: import_zod12.z.literal("field"), field: DistributionsQueryFieldSchema }),
|
|
728
|
+
import_zod12.z.object({
|
|
729
|
+
type: import_zod12.z.literal("date_bucket"),
|
|
716
730
|
field: DistributionsDateFieldSchema,
|
|
717
731
|
granularity: MetricsDateGranularitySchema
|
|
718
732
|
})
|
|
719
733
|
]);
|
|
720
|
-
var DistributionsMetricSchema =
|
|
734
|
+
var DistributionsMetricSchema = import_zod12.z.object({
|
|
721
735
|
aggregation: MetricsAggregationSchema,
|
|
722
736
|
field: DistributionsMetricFieldSchema.optional(),
|
|
723
737
|
alias: metricAliasSchema
|
|
724
738
|
});
|
|
725
|
-
var DistributionsMetricsQuerySchema =
|
|
726
|
-
resource:
|
|
739
|
+
var DistributionsMetricsQuerySchema = import_zod12.z.object({
|
|
740
|
+
resource: import_zod12.z.literal("distributions"),
|
|
727
741
|
environment: metricsQueryEnvironmentSchema,
|
|
728
|
-
dateRange:
|
|
742
|
+
dateRange: import_zod12.z.object({
|
|
729
743
|
field: DistributionsDateFieldSchema,
|
|
730
|
-
from:
|
|
731
|
-
to:
|
|
744
|
+
from: import_zod12.z.string().max(64).datetime(),
|
|
745
|
+
to: import_zod12.z.string().max(64).datetime()
|
|
732
746
|
}),
|
|
733
|
-
groupBy:
|
|
734
|
-
metrics:
|
|
735
|
-
filters:
|
|
747
|
+
groupBy: import_zod12.z.array(DistributionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
748
|
+
metrics: import_zod12.z.array(DistributionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
749
|
+
filters: import_zod12.z.array(DistributionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
736
750
|
orderBy: orderBySchema.optional(),
|
|
737
751
|
limit: limitSchema
|
|
738
752
|
});
|
|
739
753
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
740
|
-
var MetricsQuerySchema =
|
|
754
|
+
var MetricsQuerySchema = import_zod12.z.discriminatedUnion("resource", [
|
|
741
755
|
ChargesMetricsQuerySchema,
|
|
742
756
|
TransactionsMetricsQuerySchema,
|
|
743
757
|
DistributionsMetricsQuerySchema
|
|
@@ -746,7 +760,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
746
760
|
const to = new Date(input.dateRange.to);
|
|
747
761
|
if (from >= to) {
|
|
748
762
|
ctx.addIssue({
|
|
749
|
-
code:
|
|
763
|
+
code: import_zod12.z.ZodIssueCode.custom,
|
|
750
764
|
message: "`dateRange.from` must be before `dateRange.to`.",
|
|
751
765
|
path: ["dateRange", "from"]
|
|
752
766
|
});
|
|
@@ -754,7 +768,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
754
768
|
const spanDays = (to.getTime() - from.getTime()) / ONE_DAY_MS;
|
|
755
769
|
if (spanDays > MAX_METRICS_QUERY_DATE_RANGE_DAYS) {
|
|
756
770
|
ctx.addIssue({
|
|
757
|
-
code:
|
|
771
|
+
code: import_zod12.z.ZodIssueCode.custom,
|
|
758
772
|
message: `\`dateRange\` cannot span more than ${MAX_METRICS_QUERY_DATE_RANGE_DAYS} days.`,
|
|
759
773
|
path: ["dateRange", "to"]
|
|
760
774
|
});
|
|
@@ -762,7 +776,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
762
776
|
const dateBucketCount = input.groupBy.filter((entry) => entry.type === "date_bucket").length;
|
|
763
777
|
if (dateBucketCount > 1) {
|
|
764
778
|
ctx.addIssue({
|
|
765
|
-
code:
|
|
779
|
+
code: import_zod12.z.ZodIssueCode.custom,
|
|
766
780
|
message: "At most one `date_bucket` entry is allowed in `groupBy`.",
|
|
767
781
|
path: ["groupBy"]
|
|
768
782
|
});
|
|
@@ -770,7 +784,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
770
784
|
input.metrics.forEach((metric, index) => {
|
|
771
785
|
if (metric.aggregation !== "count" && metric.field === void 0) {
|
|
772
786
|
ctx.addIssue({
|
|
773
|
-
code:
|
|
787
|
+
code: import_zod12.z.ZodIssueCode.custom,
|
|
774
788
|
message: "`field` is required unless `aggregation` is `count`.",
|
|
775
789
|
path: ["metrics", index, "field"]
|
|
776
790
|
});
|
|
@@ -779,7 +793,7 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
779
793
|
const aliases = input.metrics.map((metric) => metric.alias).filter((alias) => alias !== void 0);
|
|
780
794
|
if (new Set(aliases).size !== aliases.length) {
|
|
781
795
|
ctx.addIssue({
|
|
782
|
-
code:
|
|
796
|
+
code: import_zod12.z.ZodIssueCode.custom,
|
|
783
797
|
message: "Every `metrics[].alias` must be unique.",
|
|
784
798
|
path: ["metrics"]
|
|
785
799
|
});
|
|
@@ -788,32 +802,32 @@ var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
|
788
802
|
input.metrics.forEach((metric, index) => {
|
|
789
803
|
if (metric.alias !== void 0 && reservedNames.has(metric.alias)) {
|
|
790
804
|
ctx.addIssue({
|
|
791
|
-
code:
|
|
805
|
+
code: import_zod12.z.ZodIssueCode.custom,
|
|
792
806
|
message: `\`alias\` "${metric.alias}" collides with a \`groupBy\` field name (or the reserved word "bucket") \u2014 choose a different alias.`,
|
|
793
807
|
path: ["metrics", index, "alias"]
|
|
794
808
|
});
|
|
795
809
|
}
|
|
796
810
|
});
|
|
797
811
|
});
|
|
798
|
-
var MetricsQueryResultRowSchema =
|
|
799
|
-
|
|
800
|
-
|
|
812
|
+
var MetricsQueryResultRowSchema = import_zod12.z.record(
|
|
813
|
+
import_zod12.z.string(),
|
|
814
|
+
import_zod12.z.union([import_zod12.z.string(), import_zod12.z.number(), import_zod12.z.boolean(), import_zod12.z.null()])
|
|
801
815
|
);
|
|
802
|
-
var MetricsQueryResultSchema =
|
|
803
|
-
data:
|
|
804
|
-
meta:
|
|
816
|
+
var MetricsQueryResultSchema = import_zod12.z.object({
|
|
817
|
+
data: import_zod12.z.array(MetricsQueryResultRowSchema),
|
|
818
|
+
meta: import_zod12.z.object({
|
|
805
819
|
resource: MetricsResourceSchema,
|
|
806
820
|
environment: EnvironmentSchema,
|
|
807
|
-
rowCount:
|
|
808
|
-
truncated:
|
|
821
|
+
rowCount: import_zod12.z.number().int().describe("Number of rows in `data`."),
|
|
822
|
+
truncated: import_zod12.z.boolean().describe(
|
|
809
823
|
"`true` if more rows matched than `limit` allowed \u2014 `data` holds only the first `limit`."
|
|
810
824
|
)
|
|
811
825
|
})
|
|
812
826
|
});
|
|
813
827
|
|
|
814
828
|
// src/webhook-events.ts
|
|
815
|
-
var
|
|
816
|
-
var ChargeWebhookEventTypeSchema =
|
|
829
|
+
var import_zod13 = require("zod");
|
|
830
|
+
var ChargeWebhookEventTypeSchema = import_zod13.z.enum([
|
|
817
831
|
"charge.created",
|
|
818
832
|
"charge.partially_paid",
|
|
819
833
|
"charge.confirmed",
|
|
@@ -825,14 +839,14 @@ var ChargeWebhookEventTypeSchema = import_zod12.z.enum([
|
|
|
825
839
|
]).describe(
|
|
826
840
|
'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
841
|
);
|
|
828
|
-
var WebhookDeliveryEventTypeSchema =
|
|
842
|
+
var WebhookDeliveryEventTypeSchema = import_zod13.z.enum(["webhook.delivery_failed", "webhook.delivery_recovered", "webhook.endpoint_unhealthy"]).describe(
|
|
829
843
|
"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
844
|
);
|
|
831
|
-
var WebhookEventTypeSchema =
|
|
845
|
+
var WebhookEventTypeSchema = import_zod13.z.union([
|
|
832
846
|
ChargeWebhookEventTypeSchema,
|
|
833
847
|
WebhookDeliveryEventTypeSchema
|
|
834
848
|
]);
|
|
835
|
-
var WebhookCategorySchema =
|
|
849
|
+
var WebhookCategorySchema = import_zod13.z.enum(["payments", "webhooks"]).describe(
|
|
836
850
|
"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
851
|
);
|
|
838
852
|
function buildCategoryMap() {
|
|
@@ -860,101 +874,101 @@ var TriggerableChargeEventSchema = ChargeWebhookEventTypeSchema.exclude([
|
|
|
860
874
|
);
|
|
861
875
|
|
|
862
876
|
// src/webhooks.ts
|
|
863
|
-
var
|
|
877
|
+
var import_zod14 = require("zod");
|
|
864
878
|
var WEBHOOK_EVENTS_WILDCARD = "*";
|
|
865
|
-
var CreateWebhookSchema =
|
|
866
|
-
url:
|
|
879
|
+
var CreateWebhookSchema = import_zod14.z.object({
|
|
880
|
+
url: import_zod14.z.string().max(2048).url().describe(
|
|
867
881
|
"Must be HTTPS and resolve to a public address \u2014 private/internal IPs are rejected."
|
|
868
882
|
),
|
|
869
|
-
events:
|
|
883
|
+
events: import_zod14.z.array(import_zod14.z.union([WebhookEventTypeSchema, import_zod14.z.literal(WEBHOOK_EVENTS_WILDCARD)])).max(Object.keys(EVENT_CATEGORY_MAP).length + 1).default([]).describe(
|
|
870
884
|
'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
885
|
),
|
|
872
|
-
eventCategories:
|
|
886
|
+
eventCategories: import_zod14.z.array(WebhookCategorySchema).max(WebhookCategorySchema.options.length).default([]).describe(
|
|
873
887
|
"Subscribe to every event in these categories. At least one of `events` or `eventCategories` is required."
|
|
874
888
|
),
|
|
875
|
-
excludeEvents:
|
|
889
|
+
excludeEvents: import_zod14.z.array(WebhookEventTypeSchema).max(Object.keys(EVENT_CATEGORY_MAP).length).default([]).describe(
|
|
876
890
|
'Event types to exclude even if selected via `events: ["*"]` or `eventCategories`.'
|
|
877
891
|
)
|
|
878
892
|
}).refine((v) => v.events.length > 0 || v.eventCategories.length > 0, {
|
|
879
893
|
message: "must select at least one event via `events` or `eventCategories`",
|
|
880
894
|
path: ["events"]
|
|
881
895
|
});
|
|
882
|
-
var WebhookSchema =
|
|
883
|
-
id:
|
|
896
|
+
var WebhookSchema = import_zod14.z.object({
|
|
897
|
+
id: import_zod14.z.string(),
|
|
884
898
|
environment: EnvironmentSchema.nullable().describe(
|
|
885
899
|
"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
900
|
),
|
|
887
|
-
url:
|
|
888
|
-
events:
|
|
889
|
-
eventCategories:
|
|
890
|
-
excludeEvents:
|
|
891
|
-
isWildcard:
|
|
892
|
-
secret:
|
|
901
|
+
url: import_zod14.z.string(),
|
|
902
|
+
events: import_zod14.z.array(WebhookEventTypeSchema),
|
|
903
|
+
eventCategories: import_zod14.z.array(WebhookCategorySchema),
|
|
904
|
+
excludeEvents: import_zod14.z.array(WebhookEventTypeSchema),
|
|
905
|
+
isWildcard: import_zod14.z.boolean(),
|
|
906
|
+
secret: import_zod14.z.string().describe(
|
|
893
907
|
"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
908
|
),
|
|
895
|
-
createdAt:
|
|
909
|
+
createdAt: import_zod14.z.string().datetime()
|
|
896
910
|
});
|
|
897
911
|
var WebhookListItemSchema = WebhookSchema.omit({ secret: true }).extend({
|
|
898
|
-
hint:
|
|
912
|
+
hint: import_zod14.z.string().describe("A truncated, safe-to-display form of the secret (e.g. `whsec_...ab12`).")
|
|
899
913
|
});
|
|
900
|
-
var WebhookPayloadSchema =
|
|
901
|
-
id:
|
|
914
|
+
var WebhookPayloadSchema = import_zod14.z.object({
|
|
915
|
+
id: import_zod14.z.string().describe(
|
|
902
916
|
"Unique id for this specific delivery \u2014 also sent as the `X-Klappay-Delivery` header."
|
|
903
917
|
),
|
|
904
918
|
event: WebhookEventTypeSchema,
|
|
905
|
-
createdAt:
|
|
906
|
-
data:
|
|
919
|
+
createdAt: import_zod14.z.string().datetime(),
|
|
920
|
+
data: import_zod14.z.unknown().describe(
|
|
907
921
|
"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
922
|
)
|
|
909
923
|
});
|
|
910
|
-
var WebhookDeliveryStatusSchema =
|
|
911
|
-
var WebhookDeliverySchema =
|
|
912
|
-
id:
|
|
913
|
-
webhookId:
|
|
924
|
+
var WebhookDeliveryStatusSchema = import_zod14.z.enum(["pending", "delivered", "failed"]);
|
|
925
|
+
var WebhookDeliverySchema = import_zod14.z.object({
|
|
926
|
+
id: import_zod14.z.string(),
|
|
927
|
+
webhookId: import_zod14.z.string(),
|
|
914
928
|
event: WebhookEventTypeSchema,
|
|
915
929
|
status: WebhookDeliveryStatusSchema.describe(
|
|
916
930
|
"`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
931
|
),
|
|
918
|
-
attempts:
|
|
919
|
-
responseCode:
|
|
932
|
+
attempts: import_zod14.z.number(),
|
|
933
|
+
responseCode: import_zod14.z.number().nullable().describe(
|
|
920
934
|
"HTTP status your endpoint returned on the most recent attempt. `null` if every attempt failed to connect at all."
|
|
921
935
|
),
|
|
922
|
-
nextRetryAt:
|
|
923
|
-
deliveredAt:
|
|
924
|
-
createdAt:
|
|
936
|
+
nextRetryAt: import_zod14.z.string().datetime().nullable(),
|
|
937
|
+
deliveredAt: import_zod14.z.string().datetime().nullable(),
|
|
938
|
+
createdAt: import_zod14.z.string().datetime()
|
|
925
939
|
});
|
|
926
940
|
var ListWebhookDeliveriesSchema = PaginationQuerySchema;
|
|
927
941
|
var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
928
942
|
|
|
929
943
|
// src/recipients.ts
|
|
930
|
-
var
|
|
944
|
+
var import_zod15 = require("zod");
|
|
931
945
|
var EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
932
|
-
var CreateRecipientSchema =
|
|
933
|
-
address:
|
|
934
|
-
label:
|
|
946
|
+
var CreateRecipientSchema = import_zod15.z.object({
|
|
947
|
+
address: import_zod15.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."),
|
|
948
|
+
label: import_zod15.z.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
935
949
|
});
|
|
936
|
-
var RecipientSchema =
|
|
937
|
-
id:
|
|
950
|
+
var RecipientSchema = import_zod15.z.object({
|
|
951
|
+
id: import_zod15.z.string().describe(
|
|
938
952
|
"Klappay-generated id, e.g. `rc_...` \u2014 this, not the raw address, is what a charge's `splitRecipients[].recipientId` references."
|
|
939
953
|
),
|
|
940
954
|
environment: EnvironmentSchema,
|
|
941
|
-
address:
|
|
942
|
-
label:
|
|
943
|
-
payout:
|
|
955
|
+
address: import_zod15.z.string(),
|
|
956
|
+
label: import_zod15.z.string().nullable(),
|
|
957
|
+
payout: import_zod15.z.boolean().describe(
|
|
944
958
|
"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
959
|
),
|
|
946
|
-
createdAt:
|
|
960
|
+
createdAt: import_zod15.z.string().datetime()
|
|
947
961
|
});
|
|
948
|
-
var SetRecipientPayoutSchema =
|
|
949
|
-
payout:
|
|
962
|
+
var SetRecipientPayoutSchema = import_zod15.z.object({
|
|
963
|
+
payout: import_zod15.z.boolean().describe("New payout-eligibility value for this recipient.")
|
|
950
964
|
});
|
|
951
965
|
|
|
952
966
|
// src/timeline.ts
|
|
953
|
-
var
|
|
954
|
-
var TransactionSourceSchema =
|
|
967
|
+
var import_zod16 = require("zod");
|
|
968
|
+
var TransactionSourceSchema = import_zod16.z.enum(["moralis_webhook", "reconciliation_job", "sandbox"]).describe(
|
|
955
969
|
"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
970
|
);
|
|
957
|
-
var TimelineEventTypeSchema =
|
|
971
|
+
var TimelineEventTypeSchema = import_zod16.z.enum([
|
|
958
972
|
"charge.created",
|
|
959
973
|
"charge.expired",
|
|
960
974
|
"transaction.detected",
|
|
@@ -965,11 +979,11 @@ var TimelineEventTypeSchema = import_zod15.z.enum([
|
|
|
965
979
|
]).describe(
|
|
966
980
|
"`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
981
|
);
|
|
968
|
-
var TimelineEventSchema =
|
|
982
|
+
var TimelineEventSchema = import_zod16.z.object({
|
|
969
983
|
type: TimelineEventTypeSchema,
|
|
970
|
-
at:
|
|
971
|
-
txHash:
|
|
972
|
-
amount:
|
|
984
|
+
at: import_zod16.z.string().datetime(),
|
|
985
|
+
txHash: import_zod16.z.string().optional().describe("Present for `transaction.detected` and `split.distributed` events only."),
|
|
986
|
+
amount: import_zod16.z.number().optional().describe(
|
|
973
987
|
"Present for `transaction.detected` events only \u2014 the amount that specific transfer carried."
|
|
974
988
|
),
|
|
975
989
|
source: TransactionSourceSchema.optional().describe(
|
|
@@ -981,102 +995,102 @@ var TimelineEventSchema = import_zod15.z.object({
|
|
|
981
995
|
network: NetworkSchema.optional().describe(
|
|
982
996
|
"Present for `transaction.detected` and `split.distributed` events \u2014 which network this specific transfer, or settlement, used."
|
|
983
997
|
),
|
|
984
|
-
causedTransition:
|
|
998
|
+
causedTransition: import_zod16.z.boolean().optional().describe(
|
|
985
999
|
"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
1000
|
),
|
|
987
1001
|
event: WebhookEventTypeSchema.optional().describe(
|
|
988
1002
|
"Present for `webhook.*` events only \u2014 which event type this delivery was for."
|
|
989
1003
|
),
|
|
990
|
-
responseCode:
|
|
1004
|
+
responseCode: import_zod16.z.number().nullable().optional().describe(
|
|
991
1005
|
"Present for `webhook.*` events only \u2014 HTTP status your endpoint returned, or `null` if the request never connected."
|
|
992
1006
|
),
|
|
993
|
-
attempts:
|
|
1007
|
+
attempts: import_zod16.z.number().optional().describe(
|
|
994
1008
|
"Present for `webhook.*` events only \u2014 how many delivery attempts have been made so far."
|
|
995
1009
|
)
|
|
996
1010
|
});
|
|
997
1011
|
|
|
998
1012
|
// src/health.ts
|
|
999
|
-
var
|
|
1000
|
-
var HealthSchema =
|
|
1001
|
-
status:
|
|
1013
|
+
var import_zod17 = require("zod");
|
|
1014
|
+
var HealthSchema = import_zod17.z.object({
|
|
1015
|
+
status: import_zod17.z.enum(["ok", "error"]).describe(
|
|
1002
1016
|
"`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
1017
|
),
|
|
1004
|
-
version:
|
|
1005
|
-
timestamp:
|
|
1006
|
-
db:
|
|
1007
|
-
pendingWebhooks:
|
|
1008
|
-
oldestPendingChargeAgeSeconds:
|
|
1009
|
-
lastMoralisEventAgeSeconds:
|
|
1018
|
+
version: import_zod17.z.string(),
|
|
1019
|
+
timestamp: import_zod17.z.string().datetime(),
|
|
1020
|
+
db: import_zod17.z.enum(["ok", "error"]).describe("Result of a real database connectivity check, not just a process-alive check."),
|
|
1021
|
+
pendingWebhooks: import_zod17.z.number().describe("Count of webhook deliveries still awaiting a successful attempt."),
|
|
1022
|
+
oldestPendingChargeAgeSeconds: import_zod17.z.number().nullable().describe("Age of the oldest still-unpaid charge, in seconds. `null` if there are none."),
|
|
1023
|
+
lastMoralisEventAgeSeconds: import_zod17.z.number().nullable().describe(
|
|
1010
1024
|
"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
1025
|
)
|
|
1012
1026
|
});
|
|
1013
1027
|
|
|
1014
1028
|
// src/sandbox.ts
|
|
1015
|
-
var
|
|
1016
|
-
var SandboxTriggerSchema =
|
|
1029
|
+
var import_zod18 = require("zod");
|
|
1030
|
+
var SandboxTriggerSchema = import_zod18.z.object({
|
|
1017
1031
|
event: TriggerableChargeEventSchema,
|
|
1018
|
-
amount:
|
|
1032
|
+
amount: import_zod18.z.number().positive().max(CHARGE_AMOUNT_MAX).optional().describe(
|
|
1019
1033
|
"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
1034
|
)
|
|
1021
1035
|
});
|
|
1022
1036
|
|
|
1023
1037
|
// src/capabilities.ts
|
|
1024
|
-
var
|
|
1025
|
-
var CapabilitiesSchema =
|
|
1026
|
-
acceptedPayments:
|
|
1038
|
+
var import_zod19 = require("zod");
|
|
1039
|
+
var CapabilitiesSchema = import_zod19.z.object({
|
|
1040
|
+
acceptedPayments: import_zod19.z.array(AcceptedPaymentSchema).describe(
|
|
1027
1041
|
"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
1042
|
)
|
|
1029
1043
|
});
|
|
1030
1044
|
|
|
1031
1045
|
// src/swap.ts
|
|
1032
|
-
var
|
|
1033
|
-
var CreateSwapQuoteSchema =
|
|
1046
|
+
var import_zod20 = require("zod");
|
|
1047
|
+
var CreateSwapQuoteSchema = import_zod20.z.object({
|
|
1034
1048
|
inputToken: AltTokenSchema.describe(
|
|
1035
1049
|
"Which alt-cryptocurrency the payer wants to send \u2014 must be one of this charge's `swapAlternatives`, or `422 token_not_supported`."
|
|
1036
1050
|
),
|
|
1037
1051
|
inputNetwork: NetworkSchema.describe(
|
|
1038
1052
|
"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
1053
|
),
|
|
1040
|
-
takerAddress:
|
|
1054
|
+
takerAddress: import_zod20.z.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe(
|
|
1041
1055
|
"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
1056
|
)
|
|
1043
1057
|
});
|
|
1044
|
-
var SwapQuoteSchema =
|
|
1058
|
+
var SwapQuoteSchema = import_zod20.z.object({
|
|
1045
1059
|
inputToken: AltTokenSchema,
|
|
1046
1060
|
inputNetwork: NetworkSchema,
|
|
1047
|
-
inputAmount:
|
|
1061
|
+
inputAmount: import_zod20.z.number().describe(
|
|
1048
1062
|
"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
1063
|
),
|
|
1050
1064
|
outputToken: TokenSchema.describe(
|
|
1051
1065
|
"Which of this charge's `acceptedPayments` tokens the swap resolves to."
|
|
1052
1066
|
),
|
|
1053
1067
|
outputNetwork: NetworkSchema,
|
|
1054
|
-
outputAmount:
|
|
1068
|
+
outputAmount: import_zod20.z.number().describe(
|
|
1055
1069
|
"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
1070
|
),
|
|
1057
|
-
fees:
|
|
1058
|
-
klappayFee:
|
|
1071
|
+
fees: import_zod20.z.object({
|
|
1072
|
+
klappayFee: import_zod20.z.number().describe(
|
|
1059
1073
|
"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
1074
|
),
|
|
1061
|
-
zeroExFee:
|
|
1075
|
+
zeroExFee: import_zod20.z.number().nullable().describe(
|
|
1062
1076
|
"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
1077
|
)
|
|
1064
1078
|
}).describe(
|
|
1065
1079
|
"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
1080
|
),
|
|
1067
|
-
expiresAt:
|
|
1081
|
+
expiresAt: import_zod20.z.string().datetime().describe(
|
|
1068
1082
|
"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
1083
|
),
|
|
1070
|
-
transaction:
|
|
1071
|
-
to:
|
|
1072
|
-
data:
|
|
1073
|
-
value:
|
|
1084
|
+
transaction: import_zod20.z.object({
|
|
1085
|
+
to: import_zod20.z.string().describe("Contract address the payer's wallet must send this transaction to."),
|
|
1086
|
+
data: import_zod20.z.string().describe("Calldata \u2014 opaque, must be sent unmodified."),
|
|
1087
|
+
value: import_zod20.z.string().describe(
|
|
1074
1088
|
"Native currency (ETH/BNB/MATIC/AVAX) to attach, in wei \u2014 `\"0\"` when `inputToken` isn't this network's native currency."
|
|
1075
1089
|
)
|
|
1076
1090
|
}).describe(
|
|
1077
1091
|
"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
1092
|
),
|
|
1079
|
-
permit2:
|
|
1093
|
+
permit2: import_zod20.z.object({ eip712: import_zod20.z.record(import_zod20.z.unknown()) }).nullish().describe(
|
|
1080
1094
|
"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
1095
|
)
|
|
1082
1096
|
});
|
|
@@ -1103,6 +1117,7 @@ var SwapQuoteSchema = import_zod19.z.object({
|
|
|
1103
1117
|
ChargesDateFieldSchema,
|
|
1104
1118
|
ChargesMetricFieldSchema,
|
|
1105
1119
|
ChargesQueryFieldSchema,
|
|
1120
|
+
CheckChargeRequestSchema,
|
|
1106
1121
|
CheckoutProductSchema,
|
|
1107
1122
|
CreateChargeSchema,
|
|
1108
1123
|
CreateRecipientSchema,
|