@klappay/types 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-VTX32VJN.mjs → chunk-UEXXRQL3.mjs} +71 -10
- package/dist/chunk-UEXXRQL3.mjs.map +1 -0
- package/dist/{constants-Di4Qr6af.d.mts → constants-Cs8wjvTI.d.mts} +23 -9
- package/dist/{constants-Di4Qr6af.d.ts → constants-Cs8wjvTI.d.ts} +23 -9
- package/dist/constants.d.mts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +61 -9
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +3 -1
- package/dist/index.d.mts +303 -153
- package/dist/index.d.ts +303 -153
- package/dist/index.js +409 -314
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-VTX32VJN.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -4,14 +4,21 @@ import {
|
|
|
4
4
|
CHAIN_IDS,
|
|
5
5
|
EVM_NETWORKS,
|
|
6
6
|
NETWORK_EXPLORERS,
|
|
7
|
+
NETWORK_FAMILIES,
|
|
7
8
|
NETWORK_LABELS,
|
|
8
9
|
OPERATIONAL_NETWORKS,
|
|
10
|
+
SplitAddressSchema,
|
|
9
11
|
TOKEN_ADDRESSES,
|
|
10
12
|
TOKEN_DECIMALS,
|
|
11
13
|
TOKEN_DEPLOYMENTS,
|
|
14
|
+
addressesEqual,
|
|
12
15
|
getTokenDeployment,
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
isEvmAddress,
|
|
17
|
+
isPaymentDeploymentEnabled,
|
|
18
|
+
isSplitAddress,
|
|
19
|
+
isTronAddress,
|
|
20
|
+
tronAddress
|
|
21
|
+
} from "./chunk-UEXXRQL3.mjs";
|
|
15
22
|
|
|
16
23
|
// src/errors.ts
|
|
17
24
|
import { z } from "zod";
|
|
@@ -68,7 +75,7 @@ function findConflictingScopes(scopes) {
|
|
|
68
75
|
|
|
69
76
|
// src/networks.ts
|
|
70
77
|
import { z as z4 } from "zod";
|
|
71
|
-
var NetworkSchema = z4.enum(["base", "optimism", "polygon", "ethereum", "arbitrum", "avalanche", "bnb"]).describe("The blockchain a charge/payment is on.");
|
|
78
|
+
var NetworkSchema = z4.enum(["base", "optimism", "polygon", "ethereum", "arbitrum", "avalanche", "bnb", "tron", "arc"]).describe("The blockchain a charge/payment is on.");
|
|
72
79
|
|
|
73
80
|
// src/pagination.ts
|
|
74
81
|
import { z as z5 } from "zod";
|
|
@@ -178,7 +185,7 @@ var ChargeFeePayerSchema = z11.enum(["merchant", "payer"]).describe(
|
|
|
178
185
|
);
|
|
179
186
|
var CHARGE_EXPIRES_IN_MIN_SECONDS = 60;
|
|
180
187
|
var CHARGE_EXPIRES_IN_MAX_SECONDS = 3600;
|
|
181
|
-
var CHARGE_ACCEPTED_PAYMENTS_MAX =
|
|
188
|
+
var CHARGE_ACCEPTED_PAYMENTS_MAX = 18;
|
|
182
189
|
var AcceptedPaymentSchema = z11.object({
|
|
183
190
|
token: TokenSchema,
|
|
184
191
|
network: NetworkSchema
|
|
@@ -203,12 +210,21 @@ var AcceptedPaymentsSchema = z11.array(AcceptedPaymentSchema).min(1, "At least o
|
|
|
203
210
|
});
|
|
204
211
|
}
|
|
205
212
|
});
|
|
213
|
+
const families = new Set(pairs.map((pair) => NETWORK_FAMILIES[pair.network]));
|
|
214
|
+
if (families.size > 1) {
|
|
215
|
+
ctx.addIssue({
|
|
216
|
+
code: z11.ZodIssueCode.custom,
|
|
217
|
+
message: `acceptedPayments mixes networks from different split families (${[...families].sort().join(", ")}) \u2014 every network in this list must share the same underlying split factory, so a charge can only ever accept networks from one family at a time.`
|
|
218
|
+
});
|
|
219
|
+
}
|
|
206
220
|
}).describe(
|
|
207
|
-
`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\`.`
|
|
221
|
+
`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\`. Every network listed must also share the same split family (which networks are grouped together is an implementation detail, not part of this API's contract) \u2014 a charge predicts one split address up front and reuses it across every accepted network, which is only safe within one family; mixing families is rejected with \`400 validation_error\`.`
|
|
208
222
|
);
|
|
209
223
|
var CHARGE_SPLIT_RECIPIENTS_MAX = 5;
|
|
210
224
|
var SplitRecipientSchema = z11.object({
|
|
211
|
-
address:
|
|
225
|
+
address: SplitAddressSchema.describe(
|
|
226
|
+
"Address to send a slice of this charge to \u2014 an EVM 0x... address or a TRON T... address, matching whichever network family the charge accepts (acceptedPayments can only ever list networks from one split family at a time, so this always matches that same family)."
|
|
227
|
+
),
|
|
212
228
|
percent: z11.number().positive().max(100).describe(
|
|
213
229
|
"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."
|
|
214
230
|
),
|
|
@@ -268,8 +284,21 @@ var CreateChargeSchema = z11.object({
|
|
|
268
284
|
),
|
|
269
285
|
splitRecipients: SplitRecipientsInputSchema.optional(),
|
|
270
286
|
escrow: EscrowConfigSchema.optional().describe(
|
|
271
|
-
"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."
|
|
287
|
+
"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. **Requires every accepted network to be EVM** (Safe \u2014 the underlying custody contract \u2014 isn't deployed on Tron, and can never be; it's not an EVM chain) \u2014 rejected with `400 validation_error` otherwise."
|
|
272
288
|
)
|
|
289
|
+
}).superRefine((data, ctx) => {
|
|
290
|
+
if (!data.escrow) return;
|
|
291
|
+
const evmNetworks = EVM_NETWORKS;
|
|
292
|
+
const hasUnsupportedNetwork = data.acceptedPayments.some(
|
|
293
|
+
(pair) => !evmNetworks.includes(pair.network)
|
|
294
|
+
);
|
|
295
|
+
if (hasUnsupportedNetwork) {
|
|
296
|
+
ctx.addIssue({
|
|
297
|
+
code: z11.ZodIssueCode.custom,
|
|
298
|
+
message: "Escrow is not supported for this charge's network \u2014 Safe (the underlying custody contract) isn't an EVM chain there. Remove `escrow`, or accept payment on an EVM network instead.",
|
|
299
|
+
path: ["escrow"]
|
|
300
|
+
});
|
|
301
|
+
}
|
|
273
302
|
});
|
|
274
303
|
var ChargeSchema = z11.object({
|
|
275
304
|
id: z11.string().describe("Klappay-generated id, e.g. `ch_...`. Use this to look up the charge later."),
|
|
@@ -488,6 +517,7 @@ var MetricsFilterValueSchema = z15.union([
|
|
|
488
517
|
z15.string().max(255),
|
|
489
518
|
z15.number(),
|
|
490
519
|
z15.boolean(),
|
|
520
|
+
z15.null(),
|
|
491
521
|
z15.array(z15.union([z15.string().max(255), z15.number()])).min(1).max(50)
|
|
492
522
|
]);
|
|
493
523
|
var orderBySchema = z15.object({
|
|
@@ -827,9 +857,10 @@ var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
|
827
857
|
|
|
828
858
|
// src/recipients.ts
|
|
829
859
|
import { z as z18 } from "zod";
|
|
830
|
-
var EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
831
860
|
var CreateRecipientSchema = z18.object({
|
|
832
|
-
address:
|
|
861
|
+
address: SplitAddressSchema.describe(
|
|
862
|
+
"Address to register as a trusted split recipient for your organization \u2014 an EVM 0x... address or a TRON T... address."
|
|
863
|
+
),
|
|
833
864
|
label: z18.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
834
865
|
});
|
|
835
866
|
var RecipientSchema = z18.object({
|
|
@@ -844,14 +875,15 @@ var RecipientSchema = z18.object({
|
|
|
844
875
|
),
|
|
845
876
|
createdAt: z18.string().datetime()
|
|
846
877
|
});
|
|
878
|
+
var PaginatedRecipientsSchema = paginatedSchema(RecipientSchema);
|
|
847
879
|
var SetRecipientPayoutSchema = z18.object({
|
|
848
880
|
payout: z18.boolean().describe("New payout-eligibility value for this recipient.")
|
|
849
881
|
});
|
|
850
882
|
|
|
851
883
|
// src/timeline.ts
|
|
852
884
|
import { z as z19 } from "zod";
|
|
853
|
-
var TransactionSourceSchema = z19.enum(["contract_watcher", "reconciliation_job", "sandbox"]).describe(
|
|
854
|
-
"How this transfer was detected: `contract_watcher` (the normal path \u2014 a real-time
|
|
885
|
+
var TransactionSourceSchema = z19.enum(["contract_watcher", "reconciliation_job", "sandbox", "tron_watcher"]).describe(
|
|
886
|
+
"How this transfer was detected: `contract_watcher` (the normal path for EVM networks \u2014 a real-time WebSocket log subscription), `tron_watcher` (the TRON equivalent \u2014 a real-time ZeroMQ event subscription against a self-hosted node, a different underlying mechanism since TRON has no WebSocket log subscription), `reconciliation_job` (a fallback poller caught it after the watcher missed or delayed it), or `sandbox` (simulated via `POST /v1/sandbox/charges/{id}/trigger`, no real on-chain transfer)."
|
|
855
887
|
);
|
|
856
888
|
var TimelineEventTypeSchema = z19.enum([
|
|
857
889
|
"charge.created",
|
|
@@ -1054,6 +1086,7 @@ export {
|
|
|
1054
1086
|
MetricsQuerySchema,
|
|
1055
1087
|
MetricsResourceSchema,
|
|
1056
1088
|
NETWORK_EXPLORERS,
|
|
1089
|
+
NETWORK_FAMILIES,
|
|
1057
1090
|
NETWORK_LABELS,
|
|
1058
1091
|
NetworkSchema,
|
|
1059
1092
|
OPERATIONAL_NETWORKS,
|
|
@@ -1062,6 +1095,7 @@ export {
|
|
|
1062
1095
|
PAGINATION_LIMIT_MIN,
|
|
1063
1096
|
PaginatedChargesSchema,
|
|
1064
1097
|
PaginatedPendingDistributionsSchema,
|
|
1098
|
+
PaginatedRecipientsSchema,
|
|
1065
1099
|
PaginatedWebhookDeliveriesSchema,
|
|
1066
1100
|
PaginationQuerySchema,
|
|
1067
1101
|
PendingDistributionEventSchema,
|
|
@@ -1073,6 +1107,7 @@ export {
|
|
|
1073
1107
|
SandboxTriggerSchema,
|
|
1074
1108
|
SetRecipientPayoutSchema,
|
|
1075
1109
|
SettlementStatusSchema,
|
|
1110
|
+
SplitAddressSchema,
|
|
1076
1111
|
SplitDistributionStatusSchema,
|
|
1077
1112
|
SplitRecipientInputSchema,
|
|
1078
1113
|
SplitRecipientSchema,
|
|
@@ -1099,10 +1134,15 @@ export {
|
|
|
1099
1134
|
WebhookListItemSchema,
|
|
1100
1135
|
WebhookPayloadSchema,
|
|
1101
1136
|
WebhookSchema,
|
|
1137
|
+
addressesEqual,
|
|
1102
1138
|
findConflictingScopes,
|
|
1103
1139
|
getTokenDeployment,
|
|
1140
|
+
isEvmAddress,
|
|
1104
1141
|
isPaymentDeploymentEnabled,
|
|
1142
|
+
isSplitAddress,
|
|
1143
|
+
isTronAddress,
|
|
1105
1144
|
listSwapAlternatives,
|
|
1106
|
-
paginatedSchema
|
|
1145
|
+
paginatedSchema,
|
|
1146
|
+
tronAddress
|
|
1107
1147
|
};
|
|
1108
1148
|
//# sourceMappingURL=index.mjs.map
|