@delopay/sdk 0.35.1 → 0.37.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/index.cjs CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  DelopayError: () => DelopayError,
36
36
  Export: () => Export,
37
37
  FeatureMatrix: () => FeatureMatrix,
38
+ FeeProgramBuilder: () => FeeProgramBuilder,
38
39
  Files: () => Files,
39
40
  Forex: () => Forex,
40
41
  Regions: () => Regions,
@@ -50,6 +51,7 @@ __export(index_exports, {
50
51
  defaultBranding: () => defaultBranding,
51
52
  encodeBadges: () => encodeBadges,
52
53
  encodeBranding: () => encodeBranding,
54
+ feeProgram: () => feeProgram,
53
55
  fontStack: () => fontStack,
54
56
  fontWeightValue: () => fontWeightValue,
55
57
  inputPadValue: () => inputPadValue,
@@ -692,6 +694,7 @@ var Events = class {
692
694
  var Fees = class {
693
695
  constructor(request) {
694
696
  this.request = request;
697
+ this.rules = new FeeRulesManager(request);
695
698
  }
696
699
  /**
697
700
  * Create a merchant-scoped fee schedule (optionally per-shop).
@@ -733,6 +736,46 @@ var Fees = class {
733
736
  return this.request("DELETE", `/merchant-fees/${encodeURIComponent(feeId)}`);
734
737
  }
735
738
  };
739
+ var FeeRulesManager = class {
740
+ constructor(request) {
741
+ this.request = request;
742
+ }
743
+ /**
744
+ * Create or replace the merchant's fee-rule program (a new active version;
745
+ * the previous version is deactivated server-side).
746
+ *
747
+ * @param params - The program plus optional name / shop scope / validity window.
748
+ * @param merchantId - The merchant account ID.
749
+ */
750
+ async upsert(params, merchantId) {
751
+ const body = { ...params, fee_owner: "merchant" };
752
+ return this.request("PUT", "/merchant-fees/rules", {
753
+ body,
754
+ query: { merchant_id: merchantId }
755
+ });
756
+ }
757
+ /**
758
+ * Retrieve the merchant's active fee-rule program, or `null` if none.
759
+ *
760
+ * @param merchantId - The merchant account ID.
761
+ */
762
+ async retrieve(merchantId) {
763
+ return this.request("GET", "/merchant-fees/rules", {
764
+ query: { merchant_id: merchantId }
765
+ });
766
+ }
767
+ /**
768
+ * Deactivate the merchant's active fee-rule program (falls back to the flat
769
+ * fee schedules / volume tier). Idempotent.
770
+ *
771
+ * @param merchantId - The merchant account ID.
772
+ */
773
+ async delete(merchantId) {
774
+ await this.request("DELETE", "/merchant-fees/rules", {
775
+ query: { merchant_id: merchantId }
776
+ });
777
+ }
778
+ };
736
779
 
737
780
  // src/resources/mandates.ts
738
781
  var Mandates = class {
@@ -2381,51 +2424,23 @@ var Webhooks = {
2381
2424
  };
2382
2425
 
2383
2426
  // src/resources/analytics.ts
2384
- var AnalyticsDomain = class {
2385
- constructor(request, domain) {
2386
- this.request = request;
2387
- this.domain = domain;
2388
- }
2389
- /** Get metrics. `POST /analytics/metrics/{domain}` */
2390
- async metrics(params, scope) {
2391
- const prefix = scope ? `/analytics/${scope}` : "/analytics";
2392
- return this.request("POST", `${prefix}/metrics/${encodeURIComponent(this.domain)}`, {
2393
- body: [params]
2394
- });
2395
- }
2396
- /** Get filters. `POST /analytics/filters/{domain}` */
2397
- async filters(params, scope) {
2398
- const prefix = scope ? `/analytics/${scope}` : "/analytics";
2399
- return this.request("POST", `${prefix}/filters/${encodeURIComponent(this.domain)}`, {
2400
- body: params
2401
- });
2402
- }
2403
- /** Generate report. `POST /analytics/report/{domain}` */
2404
- async report(params, scope) {
2405
- const prefix = scope ? `/analytics/${scope}` : "/analytics";
2406
- return this.request("POST", `${prefix}/report/${encodeURIComponent(this.domain)}`, {
2407
- body: params
2408
- });
2409
- }
2410
- /** Sankey chart data. `POST /analytics/metrics/{domain}/sankey` */
2411
- async sankey(params, scope) {
2412
- const prefix = scope ? `/analytics/${scope}` : "/analytics";
2413
- return this.request("POST", `${prefix}/metrics/${encodeURIComponent(this.domain)}/sankey`, {
2414
- body: params
2415
- });
2416
- }
2417
- };
2418
2427
  var Analytics = class {
2419
2428
  constructor(request) {
2420
2429
  this.request = request;
2421
- this.payments = new AnalyticsDomain(request, "payments");
2422
- this.refunds = new AnalyticsDomain(request, "refunds");
2423
- this.disputes = new AnalyticsDomain(request, "disputes");
2424
- this.authEvents = new AnalyticsDomain(request, "auth_events");
2425
- this.sdkEvents = new AnalyticsDomain(request, "sdk_events");
2426
- this.frm = new AnalyticsDomain(request, "frm");
2427
- this.apiEvents = new AnalyticsDomain(request, "api_events");
2428
- this.routing = new AnalyticsDomain(request, "routing");
2430
+ }
2431
+ /**
2432
+ * Scoped, drill-level analytics dashboard for the authenticated merchant
2433
+ * (the same engine as the admin portal, pinned server-side to your own
2434
+ * merchant). The server ignores `merchant_id` — it always scopes to your
2435
+ * merchant, and to your single shop for profile-scoped users — so pass only
2436
+ * `project_id` / `shop_id` to drill and the window / `sections` fields.
2437
+ * Returns one drill level: the scope's daily series + previous window,
2438
+ * processor mix and direct children. `GET /analytics/scope`
2439
+ */
2440
+ async scope(params) {
2441
+ return this.request("GET", "/analytics/scope", {
2442
+ query: params
2443
+ });
2429
2444
  }
2430
2445
  /** Global search. `POST /analytics/search` */
2431
2446
  async search(params) {
@@ -3084,6 +3099,74 @@ var Delopay = class {
3084
3099
  /** Utility for verifying incoming webhook signatures (static, no instance needed). */
3085
3100
  Delopay.webhooks = Webhooks;
3086
3101
 
3102
+ // src/feeProgram.ts
3103
+ function toFeeOutput(spec) {
3104
+ const hasPct = spec.percentage != null;
3105
+ const hasFlat = spec.flat != null;
3106
+ const feeType = hasPct && hasFlat ? "combined" : hasFlat ? "flat" : "percentage";
3107
+ return {
3108
+ fee_type: feeType,
3109
+ percentage_fee: spec.percentage ?? null,
3110
+ flat_fee_amount: spec.flat ?? null,
3111
+ flat_fee_currency: spec.flatCurrency ?? null,
3112
+ min_fee_amount: spec.min ?? null,
3113
+ max_fee_amount: spec.max ?? null
3114
+ };
3115
+ }
3116
+ function enumCondition(lhs, value) {
3117
+ return { lhs, comparison: "equal", value: { type: "enum_variant", value }, metadata: {} };
3118
+ }
3119
+ function numberCondition(lhs, comparison, value) {
3120
+ return { lhs, comparison, value: { type: "number", value }, metadata: {} };
3121
+ }
3122
+ function buildConditions(when = {}, raw = []) {
3123
+ const out = [];
3124
+ if (when.paymentMethod != null) out.push(enumCondition("payment_method", when.paymentMethod));
3125
+ if (when.connector != null) out.push(enumCondition("connector", when.connector));
3126
+ if (when.currency != null) out.push(enumCondition("currency", when.currency));
3127
+ if (when.cardNetwork != null) out.push(enumCondition("card_network", when.cardNetwork));
3128
+ if (when.amountEquals != null) out.push(numberCondition("amount", "equal", when.amountEquals));
3129
+ if (when.amountGreaterThan != null) {
3130
+ out.push(numberCondition("amount", "greater_than", when.amountGreaterThan));
3131
+ }
3132
+ if (when.amountLessThan != null) {
3133
+ out.push(numberCondition("amount", "less_than", when.amountLessThan));
3134
+ }
3135
+ out.push(...raw);
3136
+ return out;
3137
+ }
3138
+ var FeeProgramBuilder = class {
3139
+ constructor() {
3140
+ this.rules = [];
3141
+ this.defaultFee = null;
3142
+ }
3143
+ /** Append a rule. Provided `when`/`rawConditions` are ANDed. */
3144
+ rule(input) {
3145
+ this.rules.push({
3146
+ name: input.name,
3147
+ connectorSelection: { fee: toFeeOutput(input.fee) },
3148
+ statements: [{ condition: buildConditions(input.when, input.rawConditions) }]
3149
+ });
3150
+ return this;
3151
+ }
3152
+ /** Set the default selection (applied when no rule matches). */
3153
+ otherwise(fee) {
3154
+ this.defaultFee = toFeeOutput(fee);
3155
+ return this;
3156
+ }
3157
+ /** Produce the wire-ready program. */
3158
+ build() {
3159
+ return {
3160
+ defaultSelection: { fee: this.defaultFee },
3161
+ rules: this.rules,
3162
+ metadata: {}
3163
+ };
3164
+ }
3165
+ };
3166
+ function feeProgram() {
3167
+ return new FeeProgramBuilder();
3168
+ }
3169
+
3087
3170
  // src/branding.ts
3088
3171
  var FONT_STACKS = {
3089
3172
  inter: "'Inter Variable', 'Inter', system-ui, -apple-system, sans-serif",
@@ -3731,6 +3814,7 @@ function shadowFor(style) {
3731
3814
  DelopayError,
3732
3815
  Export,
3733
3816
  FeatureMatrix,
3817
+ FeeProgramBuilder,
3734
3818
  Files,
3735
3819
  Forex,
3736
3820
  Regions,
@@ -3746,6 +3830,7 @@ function shadowFor(style) {
3746
3830
  defaultBranding,
3747
3831
  encodeBadges,
3748
3832
  encodeBranding,
3833
+ feeProgram,
3749
3834
  fontStack,
3750
3835
  fontWeightValue,
3751
3836
  inputPadValue,