@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.
@@ -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;
@@ -3198,6 +3222,7 @@ function buildConditions(when = {}, raw = []) {
3198
3222
  if (when.connector != null) out.push(enumCondition("connector", when.connector));
3199
3223
  if (when.currency != null) out.push(enumCondition("currency", when.currency));
3200
3224
  if (when.cardNetwork != null) out.push(enumCondition("card_network", when.cardNetwork));
3225
+ if (when.billingCountry != null) out.push(enumCondition("billing_country", when.billingCountry));
3201
3226
  if (when.amountEquals != null) out.push(numberCondition("amount", "equal", when.amountEquals));
3202
3227
  if (when.amountGreaterThan != null) {
3203
3228
  out.push(numberCondition("amount", "greater_than", when.amountGreaterThan));
@@ -3205,9 +3230,83 @@ function buildConditions(when = {}, raw = []) {
3205
3230
  if (when.amountLessThan != null) {
3206
3231
  out.push(numberCondition("amount", "less_than", when.amountLessThan));
3207
3232
  }
3233
+ if (when.merchantVolumeEquals != null) {
3234
+ out.push(numberCondition("merchant_volume", "equal", when.merchantVolumeEquals));
3235
+ }
3236
+ if (when.merchantVolumeGreaterThan != null) {
3237
+ out.push(numberCondition("merchant_volume", "greater_than", when.merchantVolumeGreaterThan));
3238
+ }
3239
+ if (when.merchantVolumeLessThan != null) {
3240
+ out.push(numberCondition("merchant_volume", "less_than", when.merchantVolumeLessThan));
3241
+ }
3208
3242
  out.push(...raw);
3209
3243
  return out;
3210
3244
  }
3245
+ function leafToComparison(node) {
3246
+ return { lhs: node.lhs, comparison: node.comparison, value: node.value, metadata: {} };
3247
+ }
3248
+ function normalizeNode(node) {
3249
+ if (node.kind === "leaf") return node;
3250
+ const children = node.children.map(normalizeNode);
3251
+ const flat = [];
3252
+ for (const c of children) {
3253
+ if (c.kind === node.kind) flat.push(...c.children);
3254
+ else flat.push(c);
3255
+ }
3256
+ if (flat.length === 1) return flat[0];
3257
+ return { kind: node.kind, children: flat };
3258
+ }
3259
+ function toStatement(node) {
3260
+ if (node.kind === "leaf") return { condition: [leafToComparison(node)], nested: null };
3261
+ if (node.kind === "any") {
3262
+ return { condition: [], nested: node.children.map(toStatement) };
3263
+ }
3264
+ const leaves = node.children.filter((c) => c.kind === "leaf");
3265
+ const groups = node.children.filter((c) => c.kind !== "leaf");
3266
+ const condition = leaves.map(leafToComparison);
3267
+ if (groups.length === 0) return { condition, nested: null };
3268
+ const [first, ...rest] = groups;
3269
+ const nested = first.children.map((branch) => toStatement(normalizeNode(allOf(branch, ...rest))));
3270
+ return { condition, nested };
3271
+ }
3272
+ function assertNoEmptyAnyOf(node) {
3273
+ if (node.kind === "leaf") return;
3274
+ if (node.kind === "any" && node.children.length === 0) {
3275
+ throw new Error("feeProgram: an anyOf() group must have at least one condition");
3276
+ }
3277
+ node.children.forEach(assertNoEmptyAnyOf);
3278
+ }
3279
+ function encodeStatements(match) {
3280
+ const m = normalizeNode(match);
3281
+ if (m.kind === "any") return m.children.map(toStatement);
3282
+ return [toStatement(m)];
3283
+ }
3284
+ function comparisonToLeaf(c) {
3285
+ return { kind: "leaf", lhs: c.lhs, comparison: c.comparison, value: c.value };
3286
+ }
3287
+ function statementToNode(stmt) {
3288
+ const leaves = stmt.condition.map(comparisonToLeaf);
3289
+ if (stmt.nested && stmt.nested.length > 0) {
3290
+ const orNode = anyOf(...stmt.nested.map(statementToNode));
3291
+ if (leaves.length === 0) return orNode;
3292
+ return allOf(...leaves, orNode);
3293
+ }
3294
+ return leaves.length === 1 ? leaves[0] : allOf(...leaves);
3295
+ }
3296
+ function ruleMatchToTree(statements) {
3297
+ if (statements.length === 1) return normalizeNode(statementToNode(statements[0]));
3298
+ return normalizeNode(anyOf(...statements.map(statementToNode)));
3299
+ }
3300
+ function programToTree(program) {
3301
+ return {
3302
+ rules: program.rules.map((r) => ({
3303
+ name: r.name,
3304
+ match: ruleMatchToTree(r.statements),
3305
+ fee: r.connectorSelection.fee ?? null
3306
+ })),
3307
+ otherwise: program.defaultSelection.fee ?? null
3308
+ };
3309
+ }
3211
3310
  var FeeProgramBuilder = class {
3212
3311
  constructor() {
3213
3312
  this.rules = [];
@@ -3215,10 +3314,12 @@ var FeeProgramBuilder = class {
3215
3314
  }
3216
3315
  /** Append a rule. Provided `when`/`rawConditions` are ANDed. */
3217
3316
  rule(input) {
3317
+ if (input.match) assertNoEmptyAnyOf(input.match);
3318
+ const statements = input.match ? encodeStatements(input.match) : [{ condition: buildConditions(input.when, input.rawConditions) }];
3218
3319
  this.rules.push({
3219
3320
  name: input.name,
3220
3321
  connectorSelection: { fee: toFeeOutput(input.fee) },
3221
- statements: [{ condition: buildConditions(input.when, input.rawConditions) }]
3322
+ statements
3222
3323
  });
3223
3324
  return this;
3224
3325
  }
@@ -3887,6 +3988,11 @@ export {
3887
3988
  AvailabilityOverrides,
3888
3989
  Subscriptions,
3889
3990
  Delopay,
3991
+ leaf,
3992
+ allOf,
3993
+ anyOf,
3994
+ ruleMatchToTree,
3995
+ programToTree,
3890
3996
  FeeProgramBuilder,
3891
3997
  feeProgram,
3892
3998
  fontStack,
@@ -3918,4 +4024,4 @@ export {
3918
4024
  applyBrandingVariables,
3919
4025
  shadowFor
3920
4026
  };
3921
- //# sourceMappingURL=chunk-NNSPBDYP.js.map
4027
+ //# sourceMappingURL=chunk-ABYAZHZC.js.map