@delopay/sdk 0.47.0 → 0.48.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-NNSPBDYP.js → chunk-SX46W7E4.js} +107 -2
- package/dist/chunk-SX46W7E4.js.map +1 -0
- package/dist/index.cjs +111 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -1
- package/dist/index.d.ts +91 -1
- package/dist/index.js +11 -1
- package/dist/internal.cjs +122 -1
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +9 -3
- package/dist/internal.d.ts +9 -3
- package/dist/internal.js +22 -1
- package/dist/internal.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-NNSPBDYP.js.map +0 -1
|
@@ -727,6 +727,20 @@ var FeeRulesManager = class {
|
|
|
727
727
|
query: { merchant_id: merchantId, profile_id: profileId }
|
|
728
728
|
});
|
|
729
729
|
}
|
|
730
|
+
/**
|
|
731
|
+
* Dry-run a candidate fee-rule program against a sample transaction.
|
|
732
|
+
* Returns the matched rule name, whether it fell through, and the computed fee.
|
|
733
|
+
* Does not persist anything.
|
|
734
|
+
*
|
|
735
|
+
* @param input - Candidate program + sample transaction fields.
|
|
736
|
+
* @param merchantId - The merchant account ID.
|
|
737
|
+
*/
|
|
738
|
+
async preview(input, merchantId) {
|
|
739
|
+
return this.request("POST", "/merchant-fees/rules/preview", {
|
|
740
|
+
body: input,
|
|
741
|
+
query: { merchant_id: merchantId }
|
|
742
|
+
});
|
|
743
|
+
}
|
|
730
744
|
};
|
|
731
745
|
|
|
732
746
|
// src/resources/mandates.ts
|
|
@@ -3173,6 +3187,16 @@ var Delopay = class {
|
|
|
3173
3187
|
Delopay.webhooks = Webhooks;
|
|
3174
3188
|
|
|
3175
3189
|
// src/feeProgram.ts
|
|
3190
|
+
function leaf(lhs, comparison, value) {
|
|
3191
|
+
const tagged = typeof value === "number" ? { type: "number", value } : { type: "enum_variant", value };
|
|
3192
|
+
return { kind: "leaf", lhs, comparison, value: tagged };
|
|
3193
|
+
}
|
|
3194
|
+
function allOf(...children) {
|
|
3195
|
+
return { kind: "all", children };
|
|
3196
|
+
}
|
|
3197
|
+
function anyOf(...children) {
|
|
3198
|
+
return { kind: "any", children };
|
|
3199
|
+
}
|
|
3176
3200
|
function toFeeOutput(spec) {
|
|
3177
3201
|
const hasPct = spec.percentage != null;
|
|
3178
3202
|
const hasFlat = spec.flat != null;
|
|
@@ -3205,9 +3229,83 @@ function buildConditions(when = {}, raw = []) {
|
|
|
3205
3229
|
if (when.amountLessThan != null) {
|
|
3206
3230
|
out.push(numberCondition("amount", "less_than", when.amountLessThan));
|
|
3207
3231
|
}
|
|
3232
|
+
if (when.merchantVolumeEquals != null) {
|
|
3233
|
+
out.push(numberCondition("merchant_volume", "equal", when.merchantVolumeEquals));
|
|
3234
|
+
}
|
|
3235
|
+
if (when.merchantVolumeGreaterThan != null) {
|
|
3236
|
+
out.push(numberCondition("merchant_volume", "greater_than", when.merchantVolumeGreaterThan));
|
|
3237
|
+
}
|
|
3238
|
+
if (when.merchantVolumeLessThan != null) {
|
|
3239
|
+
out.push(numberCondition("merchant_volume", "less_than", when.merchantVolumeLessThan));
|
|
3240
|
+
}
|
|
3208
3241
|
out.push(...raw);
|
|
3209
3242
|
return out;
|
|
3210
3243
|
}
|
|
3244
|
+
function leafToComparison(node) {
|
|
3245
|
+
return { lhs: node.lhs, comparison: node.comparison, value: node.value, metadata: {} };
|
|
3246
|
+
}
|
|
3247
|
+
function normalizeNode(node) {
|
|
3248
|
+
if (node.kind === "leaf") return node;
|
|
3249
|
+
const children = node.children.map(normalizeNode);
|
|
3250
|
+
const flat = [];
|
|
3251
|
+
for (const c of children) {
|
|
3252
|
+
if (c.kind === node.kind) flat.push(...c.children);
|
|
3253
|
+
else flat.push(c);
|
|
3254
|
+
}
|
|
3255
|
+
if (flat.length === 1) return flat[0];
|
|
3256
|
+
return { kind: node.kind, children: flat };
|
|
3257
|
+
}
|
|
3258
|
+
function toStatement(node) {
|
|
3259
|
+
if (node.kind === "leaf") return { condition: [leafToComparison(node)], nested: null };
|
|
3260
|
+
if (node.kind === "any") {
|
|
3261
|
+
return { condition: [], nested: node.children.map(toStatement) };
|
|
3262
|
+
}
|
|
3263
|
+
const leaves = node.children.filter((c) => c.kind === "leaf");
|
|
3264
|
+
const groups = node.children.filter((c) => c.kind !== "leaf");
|
|
3265
|
+
const condition = leaves.map(leafToComparison);
|
|
3266
|
+
if (groups.length === 0) return { condition, nested: null };
|
|
3267
|
+
const [first, ...rest] = groups;
|
|
3268
|
+
const nested = first.children.map((branch) => toStatement(normalizeNode(allOf(branch, ...rest))));
|
|
3269
|
+
return { condition, nested };
|
|
3270
|
+
}
|
|
3271
|
+
function assertNoEmptyAnyOf(node) {
|
|
3272
|
+
if (node.kind === "leaf") return;
|
|
3273
|
+
if (node.kind === "any" && node.children.length === 0) {
|
|
3274
|
+
throw new Error("feeProgram: an anyOf() group must have at least one condition");
|
|
3275
|
+
}
|
|
3276
|
+
node.children.forEach(assertNoEmptyAnyOf);
|
|
3277
|
+
}
|
|
3278
|
+
function encodeStatements(match) {
|
|
3279
|
+
const m = normalizeNode(match);
|
|
3280
|
+
if (m.kind === "any") return m.children.map(toStatement);
|
|
3281
|
+
return [toStatement(m)];
|
|
3282
|
+
}
|
|
3283
|
+
function comparisonToLeaf(c) {
|
|
3284
|
+
return { kind: "leaf", lhs: c.lhs, comparison: c.comparison, value: c.value };
|
|
3285
|
+
}
|
|
3286
|
+
function statementToNode(stmt) {
|
|
3287
|
+
const leaves = stmt.condition.map(comparisonToLeaf);
|
|
3288
|
+
if (stmt.nested && stmt.nested.length > 0) {
|
|
3289
|
+
const orNode = anyOf(...stmt.nested.map(statementToNode));
|
|
3290
|
+
if (leaves.length === 0) return orNode;
|
|
3291
|
+
return allOf(...leaves, orNode);
|
|
3292
|
+
}
|
|
3293
|
+
return leaves.length === 1 ? leaves[0] : allOf(...leaves);
|
|
3294
|
+
}
|
|
3295
|
+
function ruleMatchToTree(statements) {
|
|
3296
|
+
if (statements.length === 1) return normalizeNode(statementToNode(statements[0]));
|
|
3297
|
+
return normalizeNode(anyOf(...statements.map(statementToNode)));
|
|
3298
|
+
}
|
|
3299
|
+
function programToTree(program) {
|
|
3300
|
+
return {
|
|
3301
|
+
rules: program.rules.map((r) => ({
|
|
3302
|
+
name: r.name,
|
|
3303
|
+
match: ruleMatchToTree(r.statements),
|
|
3304
|
+
fee: r.connectorSelection.fee ?? null
|
|
3305
|
+
})),
|
|
3306
|
+
otherwise: program.defaultSelection.fee ?? null
|
|
3307
|
+
};
|
|
3308
|
+
}
|
|
3211
3309
|
var FeeProgramBuilder = class {
|
|
3212
3310
|
constructor() {
|
|
3213
3311
|
this.rules = [];
|
|
@@ -3215,10 +3313,12 @@ var FeeProgramBuilder = class {
|
|
|
3215
3313
|
}
|
|
3216
3314
|
/** Append a rule. Provided `when`/`rawConditions` are ANDed. */
|
|
3217
3315
|
rule(input) {
|
|
3316
|
+
if (input.match) assertNoEmptyAnyOf(input.match);
|
|
3317
|
+
const statements = input.match ? encodeStatements(input.match) : [{ condition: buildConditions(input.when, input.rawConditions) }];
|
|
3218
3318
|
this.rules.push({
|
|
3219
3319
|
name: input.name,
|
|
3220
3320
|
connectorSelection: { fee: toFeeOutput(input.fee) },
|
|
3221
|
-
statements
|
|
3321
|
+
statements
|
|
3222
3322
|
});
|
|
3223
3323
|
return this;
|
|
3224
3324
|
}
|
|
@@ -3887,6 +3987,11 @@ export {
|
|
|
3887
3987
|
AvailabilityOverrides,
|
|
3888
3988
|
Subscriptions,
|
|
3889
3989
|
Delopay,
|
|
3990
|
+
leaf,
|
|
3991
|
+
allOf,
|
|
3992
|
+
anyOf,
|
|
3993
|
+
ruleMatchToTree,
|
|
3994
|
+
programToTree,
|
|
3890
3995
|
FeeProgramBuilder,
|
|
3891
3996
|
feeProgram,
|
|
3892
3997
|
fontStack,
|
|
@@ -3918,4 +4023,4 @@ export {
|
|
|
3918
4023
|
applyBrandingVariables,
|
|
3919
4024
|
shadowFor
|
|
3920
4025
|
};
|
|
3921
|
-
//# sourceMappingURL=chunk-
|
|
4026
|
+
//# sourceMappingURL=chunk-SX46W7E4.js.map
|