@delopay/sdk 0.46.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/internal.cjs CHANGED
@@ -55,6 +55,8 @@ __export(internal_exports, {
55
55
  Search: () => Search,
56
56
  Subscriptions: () => Subscriptions,
57
57
  Webhooks: () => Webhooks,
58
+ allOf: () => allOf,
59
+ anyOf: () => anyOf,
58
60
  applyBrandingVariables: () => applyBrandingVariables,
59
61
  buildBrandingExport: () => buildBrandingExport,
60
62
  buttonPadValue: () => buttonPadValue,
@@ -70,9 +72,12 @@ __export(internal_exports, {
70
72
  inputPadValue: () => inputPadValue,
71
73
  isDarkSurface: () => isDarkSurface,
72
74
  isHexColor: () => isHexColor,
75
+ leaf: () => leaf,
73
76
  logoDimensions: () => logoDimensions,
74
77
  parseImportedBranding: () => parseImportedBranding,
78
+ programToTree: () => programToTree,
75
79
  radiusValue: () => radiusValue,
80
+ ruleMatchToTree: () => ruleMatchToTree,
76
81
  sanitizeCustomCss: () => sanitizeCustomCss,
77
82
  shadowFor: () => shadowFor,
78
83
  surfacePadValue: () => surfacePadValue,
@@ -809,6 +814,20 @@ var FeeRulesManager = class {
809
814
  query: { merchant_id: merchantId, profile_id: profileId }
810
815
  });
811
816
  }
817
+ /**
818
+ * Dry-run a candidate fee-rule program against a sample transaction.
819
+ * Returns the matched rule name, whether it fell through, and the computed fee.
820
+ * Does not persist anything.
821
+ *
822
+ * @param input - Candidate program + sample transaction fields.
823
+ * @param merchantId - The merchant account ID.
824
+ */
825
+ async preview(input, merchantId) {
826
+ return this.request("POST", "/merchant-fees/rules/preview", {
827
+ body: input,
828
+ query: { merchant_id: merchantId }
829
+ });
830
+ }
812
831
  };
813
832
 
814
833
  // src/resources/mandates.ts
@@ -2741,6 +2760,21 @@ var AvailabilityOverrides = class {
2741
2760
  async delete(id) {
2742
2761
  return this.request("DELETE", `/availability-overrides/${encodeURIComponent(id)}`);
2743
2762
  }
2763
+ /**
2764
+ * Preview the methods a customer in `country` would be shown for a shop —
2765
+ * the connector ceiling narrowed by the smart country defaults and the
2766
+ * merchant overrides, without an active payment.
2767
+ * `GET /availability-overrides/preview`
2768
+ */
2769
+ async preview(params) {
2770
+ return this.request("GET", "/availability-overrides/preview", {
2771
+ query: {
2772
+ merchant_id: params.merchant_id,
2773
+ profile_id: params.profile_id,
2774
+ ...params.country ? { country: params.country } : {}
2775
+ }
2776
+ });
2777
+ }
2744
2778
  };
2745
2779
 
2746
2780
  // src/resources/subscriptions.ts
@@ -3240,6 +3274,16 @@ var Delopay = class {
3240
3274
  Delopay.webhooks = Webhooks;
3241
3275
 
3242
3276
  // src/feeProgram.ts
3277
+ function leaf(lhs, comparison, value) {
3278
+ const tagged = typeof value === "number" ? { type: "number", value } : { type: "enum_variant", value };
3279
+ return { kind: "leaf", lhs, comparison, value: tagged };
3280
+ }
3281
+ function allOf(...children) {
3282
+ return { kind: "all", children };
3283
+ }
3284
+ function anyOf(...children) {
3285
+ return { kind: "any", children };
3286
+ }
3243
3287
  function toFeeOutput(spec) {
3244
3288
  const hasPct = spec.percentage != null;
3245
3289
  const hasFlat = spec.flat != null;
@@ -3272,9 +3316,83 @@ function buildConditions(when = {}, raw = []) {
3272
3316
  if (when.amountLessThan != null) {
3273
3317
  out.push(numberCondition("amount", "less_than", when.amountLessThan));
3274
3318
  }
3319
+ if (when.merchantVolumeEquals != null) {
3320
+ out.push(numberCondition("merchant_volume", "equal", when.merchantVolumeEquals));
3321
+ }
3322
+ if (when.merchantVolumeGreaterThan != null) {
3323
+ out.push(numberCondition("merchant_volume", "greater_than", when.merchantVolumeGreaterThan));
3324
+ }
3325
+ if (when.merchantVolumeLessThan != null) {
3326
+ out.push(numberCondition("merchant_volume", "less_than", when.merchantVolumeLessThan));
3327
+ }
3275
3328
  out.push(...raw);
3276
3329
  return out;
3277
3330
  }
3331
+ function leafToComparison(node) {
3332
+ return { lhs: node.lhs, comparison: node.comparison, value: node.value, metadata: {} };
3333
+ }
3334
+ function normalizeNode(node) {
3335
+ if (node.kind === "leaf") return node;
3336
+ const children = node.children.map(normalizeNode);
3337
+ const flat = [];
3338
+ for (const c of children) {
3339
+ if (c.kind === node.kind) flat.push(...c.children);
3340
+ else flat.push(c);
3341
+ }
3342
+ if (flat.length === 1) return flat[0];
3343
+ return { kind: node.kind, children: flat };
3344
+ }
3345
+ function toStatement(node) {
3346
+ if (node.kind === "leaf") return { condition: [leafToComparison(node)], nested: null };
3347
+ if (node.kind === "any") {
3348
+ return { condition: [], nested: node.children.map(toStatement) };
3349
+ }
3350
+ const leaves = node.children.filter((c) => c.kind === "leaf");
3351
+ const groups = node.children.filter((c) => c.kind !== "leaf");
3352
+ const condition = leaves.map(leafToComparison);
3353
+ if (groups.length === 0) return { condition, nested: null };
3354
+ const [first, ...rest] = groups;
3355
+ const nested = first.children.map((branch) => toStatement(normalizeNode(allOf(branch, ...rest))));
3356
+ return { condition, nested };
3357
+ }
3358
+ function assertNoEmptyAnyOf(node) {
3359
+ if (node.kind === "leaf") return;
3360
+ if (node.kind === "any" && node.children.length === 0) {
3361
+ throw new Error("feeProgram: an anyOf() group must have at least one condition");
3362
+ }
3363
+ node.children.forEach(assertNoEmptyAnyOf);
3364
+ }
3365
+ function encodeStatements(match) {
3366
+ const m = normalizeNode(match);
3367
+ if (m.kind === "any") return m.children.map(toStatement);
3368
+ return [toStatement(m)];
3369
+ }
3370
+ function comparisonToLeaf(c) {
3371
+ return { kind: "leaf", lhs: c.lhs, comparison: c.comparison, value: c.value };
3372
+ }
3373
+ function statementToNode(stmt) {
3374
+ const leaves = stmt.condition.map(comparisonToLeaf);
3375
+ if (stmt.nested && stmt.nested.length > 0) {
3376
+ const orNode = anyOf(...stmt.nested.map(statementToNode));
3377
+ if (leaves.length === 0) return orNode;
3378
+ return allOf(...leaves, orNode);
3379
+ }
3380
+ return leaves.length === 1 ? leaves[0] : allOf(...leaves);
3381
+ }
3382
+ function ruleMatchToTree(statements) {
3383
+ if (statements.length === 1) return normalizeNode(statementToNode(statements[0]));
3384
+ return normalizeNode(anyOf(...statements.map(statementToNode)));
3385
+ }
3386
+ function programToTree(program) {
3387
+ return {
3388
+ rules: program.rules.map((r) => ({
3389
+ name: r.name,
3390
+ match: ruleMatchToTree(r.statements),
3391
+ fee: r.connectorSelection.fee ?? null
3392
+ })),
3393
+ otherwise: program.defaultSelection.fee ?? null
3394
+ };
3395
+ }
3278
3396
  var FeeProgramBuilder = class {
3279
3397
  constructor() {
3280
3398
  this.rules = [];
@@ -3282,10 +3400,12 @@ var FeeProgramBuilder = class {
3282
3400
  }
3283
3401
  /** Append a rule. Provided `when`/`rawConditions` are ANDed. */
3284
3402
  rule(input) {
3403
+ if (input.match) assertNoEmptyAnyOf(input.match);
3404
+ const statements = input.match ? encodeStatements(input.match) : [{ condition: buildConditions(input.when, input.rawConditions) }];
3285
3405
  this.rules.push({
3286
3406
  name: input.name,
3287
3407
  connectorSelection: { fee: toFeeOutput(input.fee) },
3288
- statements: [{ condition: buildConditions(input.when, input.rawConditions) }]
3408
+ statements
3289
3409
  });
3290
3410
  return this;
3291
3411
  }
@@ -4384,6 +4504,17 @@ var PlatformFeeRulesManager = class {
4384
4504
  query: { merchant_id: merchantId, profile_id: profileId }
4385
4505
  });
4386
4506
  }
4507
+ /**
4508
+ * Dry-run a candidate fee-rule program against a sample transaction.
4509
+ * Returns the matched rule name, whether it fell through, and the computed fee.
4510
+ * Does not persist anything.
4511
+ */
4512
+ async preview(input, merchantId) {
4513
+ return this.request("POST", "/admin/fees/rules/preview", {
4514
+ body: input,
4515
+ query: { merchant_id: merchantId }
4516
+ });
4517
+ }
4387
4518
  };
4388
4519
 
4389
4520
  // src/internal/client.ts
@@ -4441,6 +4572,8 @@ var DelopayInternal = class extends Delopay {
4441
4572
  Search,
4442
4573
  Subscriptions,
4443
4574
  Webhooks,
4575
+ allOf,
4576
+ anyOf,
4444
4577
  applyBrandingVariables,
4445
4578
  buildBrandingExport,
4446
4579
  buttonPadValue,
@@ -4456,9 +4589,12 @@ var DelopayInternal = class extends Delopay {
4456
4589
  inputPadValue,
4457
4590
  isDarkSurface,
4458
4591
  isHexColor,
4592
+ leaf,
4459
4593
  logoDimensions,
4460
4594
  parseImportedBranding,
4595
+ programToTree,
4461
4596
  radiusValue,
4597
+ ruleMatchToTree,
4462
4598
  sanitizeCustomCss,
4463
4599
  shadowFor,
4464
4600
  surfacePadValue,