@delopay/sdk 0.47.0 → 0.49.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-ABYAZHZC.js} +108 -2
- package/dist/chunk-ABYAZHZC.js.map +1 -0
- package/dist/index.cjs +112 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -1
- package/dist/index.d.ts +98 -1
- package/dist/index.js +11 -1
- package/dist/internal.cjs +123 -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
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,8 @@ __export(index_exports, {
|
|
|
43
43
|
Search: () => Search,
|
|
44
44
|
Subscriptions: () => Subscriptions,
|
|
45
45
|
Webhooks: () => Webhooks,
|
|
46
|
+
allOf: () => allOf,
|
|
47
|
+
anyOf: () => anyOf,
|
|
46
48
|
applyBrandingVariables: () => applyBrandingVariables,
|
|
47
49
|
buildBrandingExport: () => buildBrandingExport,
|
|
48
50
|
buttonPadValue: () => buttonPadValue,
|
|
@@ -58,9 +60,12 @@ __export(index_exports, {
|
|
|
58
60
|
inputPadValue: () => inputPadValue,
|
|
59
61
|
isDarkSurface: () => isDarkSurface,
|
|
60
62
|
isHexColor: () => isHexColor,
|
|
63
|
+
leaf: () => leaf,
|
|
61
64
|
logoDimensions: () => logoDimensions,
|
|
62
65
|
parseImportedBranding: () => parseImportedBranding,
|
|
66
|
+
programToTree: () => programToTree,
|
|
63
67
|
radiusValue: () => radiusValue,
|
|
68
|
+
ruleMatchToTree: () => ruleMatchToTree,
|
|
64
69
|
sanitizeCustomCss: () => sanitizeCustomCss,
|
|
65
70
|
shadowFor: () => shadowFor,
|
|
66
71
|
surfacePadValue: () => surfacePadValue,
|
|
@@ -797,6 +802,20 @@ var FeeRulesManager = class {
|
|
|
797
802
|
query: { merchant_id: merchantId, profile_id: profileId }
|
|
798
803
|
});
|
|
799
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* Dry-run a candidate fee-rule program against a sample transaction.
|
|
807
|
+
* Returns the matched rule name, whether it fell through, and the computed fee.
|
|
808
|
+
* Does not persist anything.
|
|
809
|
+
*
|
|
810
|
+
* @param input - Candidate program + sample transaction fields.
|
|
811
|
+
* @param merchantId - The merchant account ID.
|
|
812
|
+
*/
|
|
813
|
+
async preview(input, merchantId) {
|
|
814
|
+
return this.request("POST", "/merchant-fees/rules/preview", {
|
|
815
|
+
body: input,
|
|
816
|
+
query: { merchant_id: merchantId }
|
|
817
|
+
});
|
|
818
|
+
}
|
|
800
819
|
};
|
|
801
820
|
|
|
802
821
|
// src/resources/mandates.ts
|
|
@@ -3243,6 +3262,16 @@ var Delopay = class {
|
|
|
3243
3262
|
Delopay.webhooks = Webhooks;
|
|
3244
3263
|
|
|
3245
3264
|
// src/feeProgram.ts
|
|
3265
|
+
function leaf(lhs, comparison, value) {
|
|
3266
|
+
const tagged = typeof value === "number" ? { type: "number", value } : { type: "enum_variant", value };
|
|
3267
|
+
return { kind: "leaf", lhs, comparison, value: tagged };
|
|
3268
|
+
}
|
|
3269
|
+
function allOf(...children) {
|
|
3270
|
+
return { kind: "all", children };
|
|
3271
|
+
}
|
|
3272
|
+
function anyOf(...children) {
|
|
3273
|
+
return { kind: "any", children };
|
|
3274
|
+
}
|
|
3246
3275
|
function toFeeOutput(spec) {
|
|
3247
3276
|
const hasPct = spec.percentage != null;
|
|
3248
3277
|
const hasFlat = spec.flat != null;
|
|
@@ -3268,6 +3297,7 @@ function buildConditions(when = {}, raw = []) {
|
|
|
3268
3297
|
if (when.connector != null) out.push(enumCondition("connector", when.connector));
|
|
3269
3298
|
if (when.currency != null) out.push(enumCondition("currency", when.currency));
|
|
3270
3299
|
if (when.cardNetwork != null) out.push(enumCondition("card_network", when.cardNetwork));
|
|
3300
|
+
if (when.billingCountry != null) out.push(enumCondition("billing_country", when.billingCountry));
|
|
3271
3301
|
if (when.amountEquals != null) out.push(numberCondition("amount", "equal", when.amountEquals));
|
|
3272
3302
|
if (when.amountGreaterThan != null) {
|
|
3273
3303
|
out.push(numberCondition("amount", "greater_than", when.amountGreaterThan));
|
|
@@ -3275,9 +3305,83 @@ function buildConditions(when = {}, raw = []) {
|
|
|
3275
3305
|
if (when.amountLessThan != null) {
|
|
3276
3306
|
out.push(numberCondition("amount", "less_than", when.amountLessThan));
|
|
3277
3307
|
}
|
|
3308
|
+
if (when.merchantVolumeEquals != null) {
|
|
3309
|
+
out.push(numberCondition("merchant_volume", "equal", when.merchantVolumeEquals));
|
|
3310
|
+
}
|
|
3311
|
+
if (when.merchantVolumeGreaterThan != null) {
|
|
3312
|
+
out.push(numberCondition("merchant_volume", "greater_than", when.merchantVolumeGreaterThan));
|
|
3313
|
+
}
|
|
3314
|
+
if (when.merchantVolumeLessThan != null) {
|
|
3315
|
+
out.push(numberCondition("merchant_volume", "less_than", when.merchantVolumeLessThan));
|
|
3316
|
+
}
|
|
3278
3317
|
out.push(...raw);
|
|
3279
3318
|
return out;
|
|
3280
3319
|
}
|
|
3320
|
+
function leafToComparison(node) {
|
|
3321
|
+
return { lhs: node.lhs, comparison: node.comparison, value: node.value, metadata: {} };
|
|
3322
|
+
}
|
|
3323
|
+
function normalizeNode(node) {
|
|
3324
|
+
if (node.kind === "leaf") return node;
|
|
3325
|
+
const children = node.children.map(normalizeNode);
|
|
3326
|
+
const flat = [];
|
|
3327
|
+
for (const c of children) {
|
|
3328
|
+
if (c.kind === node.kind) flat.push(...c.children);
|
|
3329
|
+
else flat.push(c);
|
|
3330
|
+
}
|
|
3331
|
+
if (flat.length === 1) return flat[0];
|
|
3332
|
+
return { kind: node.kind, children: flat };
|
|
3333
|
+
}
|
|
3334
|
+
function toStatement(node) {
|
|
3335
|
+
if (node.kind === "leaf") return { condition: [leafToComparison(node)], nested: null };
|
|
3336
|
+
if (node.kind === "any") {
|
|
3337
|
+
return { condition: [], nested: node.children.map(toStatement) };
|
|
3338
|
+
}
|
|
3339
|
+
const leaves = node.children.filter((c) => c.kind === "leaf");
|
|
3340
|
+
const groups = node.children.filter((c) => c.kind !== "leaf");
|
|
3341
|
+
const condition = leaves.map(leafToComparison);
|
|
3342
|
+
if (groups.length === 0) return { condition, nested: null };
|
|
3343
|
+
const [first, ...rest] = groups;
|
|
3344
|
+
const nested = first.children.map((branch) => toStatement(normalizeNode(allOf(branch, ...rest))));
|
|
3345
|
+
return { condition, nested };
|
|
3346
|
+
}
|
|
3347
|
+
function assertNoEmptyAnyOf(node) {
|
|
3348
|
+
if (node.kind === "leaf") return;
|
|
3349
|
+
if (node.kind === "any" && node.children.length === 0) {
|
|
3350
|
+
throw new Error("feeProgram: an anyOf() group must have at least one condition");
|
|
3351
|
+
}
|
|
3352
|
+
node.children.forEach(assertNoEmptyAnyOf);
|
|
3353
|
+
}
|
|
3354
|
+
function encodeStatements(match) {
|
|
3355
|
+
const m = normalizeNode(match);
|
|
3356
|
+
if (m.kind === "any") return m.children.map(toStatement);
|
|
3357
|
+
return [toStatement(m)];
|
|
3358
|
+
}
|
|
3359
|
+
function comparisonToLeaf(c) {
|
|
3360
|
+
return { kind: "leaf", lhs: c.lhs, comparison: c.comparison, value: c.value };
|
|
3361
|
+
}
|
|
3362
|
+
function statementToNode(stmt) {
|
|
3363
|
+
const leaves = stmt.condition.map(comparisonToLeaf);
|
|
3364
|
+
if (stmt.nested && stmt.nested.length > 0) {
|
|
3365
|
+
const orNode = anyOf(...stmt.nested.map(statementToNode));
|
|
3366
|
+
if (leaves.length === 0) return orNode;
|
|
3367
|
+
return allOf(...leaves, orNode);
|
|
3368
|
+
}
|
|
3369
|
+
return leaves.length === 1 ? leaves[0] : allOf(...leaves);
|
|
3370
|
+
}
|
|
3371
|
+
function ruleMatchToTree(statements) {
|
|
3372
|
+
if (statements.length === 1) return normalizeNode(statementToNode(statements[0]));
|
|
3373
|
+
return normalizeNode(anyOf(...statements.map(statementToNode)));
|
|
3374
|
+
}
|
|
3375
|
+
function programToTree(program) {
|
|
3376
|
+
return {
|
|
3377
|
+
rules: program.rules.map((r) => ({
|
|
3378
|
+
name: r.name,
|
|
3379
|
+
match: ruleMatchToTree(r.statements),
|
|
3380
|
+
fee: r.connectorSelection.fee ?? null
|
|
3381
|
+
})),
|
|
3382
|
+
otherwise: program.defaultSelection.fee ?? null
|
|
3383
|
+
};
|
|
3384
|
+
}
|
|
3281
3385
|
var FeeProgramBuilder = class {
|
|
3282
3386
|
constructor() {
|
|
3283
3387
|
this.rules = [];
|
|
@@ -3285,10 +3389,12 @@ var FeeProgramBuilder = class {
|
|
|
3285
3389
|
}
|
|
3286
3390
|
/** Append a rule. Provided `when`/`rawConditions` are ANDed. */
|
|
3287
3391
|
rule(input) {
|
|
3392
|
+
if (input.match) assertNoEmptyAnyOf(input.match);
|
|
3393
|
+
const statements = input.match ? encodeStatements(input.match) : [{ condition: buildConditions(input.when, input.rawConditions) }];
|
|
3288
3394
|
this.rules.push({
|
|
3289
3395
|
name: input.name,
|
|
3290
3396
|
connectorSelection: { fee: toFeeOutput(input.fee) },
|
|
3291
|
-
statements
|
|
3397
|
+
statements
|
|
3292
3398
|
});
|
|
3293
3399
|
return this;
|
|
3294
3400
|
}
|
|
@@ -3965,6 +4071,8 @@ function shadowFor(style) {
|
|
|
3965
4071
|
Search,
|
|
3966
4072
|
Subscriptions,
|
|
3967
4073
|
Webhooks,
|
|
4074
|
+
allOf,
|
|
4075
|
+
anyOf,
|
|
3968
4076
|
applyBrandingVariables,
|
|
3969
4077
|
buildBrandingExport,
|
|
3970
4078
|
buttonPadValue,
|
|
@@ -3980,9 +4088,12 @@ function shadowFor(style) {
|
|
|
3980
4088
|
inputPadValue,
|
|
3981
4089
|
isDarkSurface,
|
|
3982
4090
|
isHexColor,
|
|
4091
|
+
leaf,
|
|
3983
4092
|
logoDimensions,
|
|
3984
4093
|
parseImportedBranding,
|
|
4094
|
+
programToTree,
|
|
3985
4095
|
radiusValue,
|
|
4096
|
+
ruleMatchToTree,
|
|
3986
4097
|
sanitizeCustomCss,
|
|
3987
4098
|
shadowFor,
|
|
3988
4099
|
surfacePadValue,
|