@delopay/sdk 0.125.0 → 0.126.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
@@ -64,6 +64,10 @@ __export(internal_exports, {
64
64
  Forex: () => Forex,
65
65
  Gsm: () => Gsm,
66
66
  LOCALIZABLE_COPY_FIELDS: () => LOCALIZABLE_COPY_FIELDS,
67
+ MAX_SECTION_LABEL_LENGTH: () => MAX_SECTION_LABEL_LENGTH,
68
+ MAX_SECTION_ORDER: () => MAX_SECTION_ORDER,
69
+ METHOD_SECTIONS: () => METHOD_SECTIONS,
70
+ MIN_SECTION_ORDER: () => MIN_SECTION_ORDER,
67
71
  NATIVE_PANES_MAX: () => NATIVE_PANES_MAX,
68
72
  NATIVE_PANE_CATEGORY_KEYS: () => NATIVE_PANE_CATEGORY_KEYS,
69
73
  NATIVE_PANE_ICON_KEYS: () => NATIVE_PANE_ICON_KEYS,
@@ -76,6 +80,7 @@ __export(internal_exports, {
76
80
  RTL_CHECKOUT_LOCALES: () => RTL_CHECKOUT_LOCALES,
77
81
  Regions: () => Regions,
78
82
  Risk: () => Risk,
83
+ SECTION_ALIASES: () => SECTION_ALIASES,
79
84
  STRIPE_FALLBACK_PANE_CATALOG: () => STRIPE_FALLBACK_PANE_CATALOG,
80
85
  STRIPE_FALLBACK_PANE_METHODS: () => STRIPE_FALLBACK_PANE_METHODS,
81
86
  STRIPE_NATIVE_PANE_METHODS: () => STRIPE_NATIVE_PANE_METHODS,
@@ -92,6 +97,7 @@ __export(internal_exports, {
92
97
  Search: () => Search,
93
98
  Settlement: () => Settlement,
94
99
  Subscriptions: () => Subscriptions,
100
+ UNKNOWN_SECTION_ORDER: () => UNKNOWN_SECTION_ORDER,
95
101
  WCAG_AA_TEXT: () => WCAG_AA_TEXT,
96
102
  WCAG_AA_UI: () => WCAG_AA_UI,
97
103
  Webhooks: () => Webhooks,
@@ -100,12 +106,14 @@ __export(internal_exports, {
100
106
  applyBrandingVariables: () => applyBrandingVariables,
101
107
  buildBrandingExport: () => buildBrandingExport,
102
108
  buttonPadValue: () => buttonPadValue,
109
+ canonicalSectionId: () => canonicalSectionId,
103
110
  checkoutCopy: () => checkoutCopy,
104
111
  checkoutLocaleDir: () => checkoutLocaleDir,
105
112
  cloneBranding: () => cloneBranding,
106
113
  cloneCustomField: () => cloneCustomField,
107
114
  cloneNativePane: () => cloneNativePane,
108
115
  clonePane: () => clonePane,
116
+ compareSections: () => compareSections,
109
117
  contrastRatio: () => contrastRatio,
110
118
  copyTranslationsKey: () => copyTranslationsKey,
111
119
  customFieldContextFromMetadata: () => customFieldContextFromMetadata,
@@ -116,10 +124,13 @@ __export(internal_exports, {
116
124
  decodeBadges: () => decodeBadges,
117
125
  decodeBranding: () => decodeBranding,
118
126
  decodeCustomFields: () => decodeCustomFields,
127
+ decodeMethodSectionLabels: () => decodeMethodSectionLabels,
128
+ decodeMethodSectionOrder: () => decodeMethodSectionOrder,
119
129
  decodeNativePanes: () => decodeNativePanes,
120
130
  decodePanes: () => decodePanes,
121
131
  defaultBranding: () => defaultBranding,
122
132
  defaultCustomFieldVisibility: () => defaultCustomFieldVisibility,
133
+ defaultMethodSectionOrder: () => defaultMethodSectionOrder,
123
134
  defaultNativePane: () => defaultNativePane,
124
135
  defaultOperatorForSource: () => defaultOperatorForSource,
125
136
  defaultPane: () => defaultPane,
@@ -127,6 +138,8 @@ __export(internal_exports, {
127
138
  encodeBadges: () => encodeBadges,
128
139
  encodeBranding: () => encodeBranding,
129
140
  encodeCustomFields: () => encodeCustomFields,
141
+ encodeMethodSectionLabels: () => encodeMethodSectionLabels,
142
+ encodeMethodSectionOrder: () => encodeMethodSectionOrder,
130
143
  encodeNativePanes: () => encodeNativePanes,
131
144
  encodePanes: () => encodePanes,
132
145
  evaluateCustomFieldCondition: () => evaluateCustomFieldCondition,
@@ -139,6 +152,7 @@ __export(internal_exports, {
139
152
  isCheckboxChecked: () => isCheckboxChecked,
140
153
  isDarkSurface: () => isDarkSurface,
141
154
  isHexColor: () => isHexColor,
155
+ knownSectionLabelKey: () => knownSectionLabelKey,
142
156
  leaf: () => leaf,
143
157
  logoDimensions: () => logoDimensions,
144
158
  nativePaneMethodInfo: () => nativePaneMethodInfo,
@@ -155,12 +169,15 @@ __export(internal_exports, {
155
169
  readableInkOn: () => readableInkOn,
156
170
  ruleMatchToTree: () => ruleMatchToTree,
157
171
  sanitizeCustomCss: () => sanitizeCustomCss,
172
+ sectionLabel: () => sectionLabel,
173
+ sectionOrderOf: () => sectionOrderOf,
158
174
  shadowFor: () => shadowFor,
159
175
  surchargeFigurePlan: () => surchargeFigurePlan,
160
176
  surchargeShowsLabel: () => surchargeShowsLabel,
161
177
  surchargeStyleDrawsAShape: () => surchargeStyleDrawsAShape,
162
178
  surchargeWordFor: () => surchargeWordFor,
163
179
  surfacePadValue: () => surfacePadValue,
180
+ validSectionOrder: () => validSectionOrder,
164
181
  validatePanes: () => validatePanes,
165
182
  verticalGapValue: () => verticalGapValue,
166
183
  visibleCustomFields: () => visibleCustomFields
@@ -5634,6 +5651,151 @@ var DEFAULT_BADGES_DARK = [
5634
5651
  borderColor: "#1e40af"
5635
5652
  }
5636
5653
  ];
5654
+ var METHOD_SECTION_ORDER_KEY = "methodSectionOrder";
5655
+ var METHOD_SECTION_LABELS_KEY = "methodSectionLabels";
5656
+ var MIN_SECTION_ORDER = 1;
5657
+ var MAX_SECTION_ORDER = 100;
5658
+ var MAX_SECTION_LABEL_LENGTH = 120;
5659
+ var METHOD_SECTIONS = [
5660
+ { id: "card", labelKey: "sections.card", order: 10 },
5661
+ { id: "wallet", labelKey: "sections.wallets", order: 20 },
5662
+ { id: "bnpl", labelKey: "sections.bnpl", order: 30 },
5663
+ { id: "bank_redirect", labelKey: "sections.onlineBanking", order: 40 },
5664
+ { id: "bank_transfer", labelKey: "sections.bankTransfer", order: 45 },
5665
+ { id: "crypto", labelKey: "sections.cryptocurrency", order: 50 },
5666
+ { id: "game_items", labelKey: "sections.gameItems", order: 60 },
5667
+ { id: "voucher", labelKey: "sections.vouchers", order: 70 },
5668
+ { id: "gift_card", labelKey: "sections.giftCards", order: 75 },
5669
+ { id: "reward", labelKey: "sections.rewards", order: 80 },
5670
+ { id: "cash", labelKey: "sections.cash", order: 90 }
5671
+ ];
5672
+ var SECTION_ALIASES = {
5673
+ card_redirect: "card"
5674
+ };
5675
+ var UNKNOWN_SECTION_ORDER = MAX_SECTION_ORDER;
5676
+ function canonicalSectionId(category) {
5677
+ return SECTION_ALIASES[category] ?? category;
5678
+ }
5679
+ function defaultMethodSectionOrder() {
5680
+ const order = {};
5681
+ for (const section of METHOD_SECTIONS) order[section.id] = section.order;
5682
+ return order;
5683
+ }
5684
+ function validSectionOrder(raw) {
5685
+ if (typeof raw !== "number" || !Number.isInteger(raw)) return null;
5686
+ if (raw < MIN_SECTION_ORDER || raw > MAX_SECTION_ORDER) return null;
5687
+ return raw;
5688
+ }
5689
+ function decodeMethodSectionOrder(raw) {
5690
+ const order = defaultMethodSectionOrder();
5691
+ if (raw === void 0) return order;
5692
+ let parsed;
5693
+ try {
5694
+ parsed = JSON.parse(raw);
5695
+ } catch {
5696
+ return order;
5697
+ }
5698
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return order;
5699
+ for (const [key, value] of Object.entries(parsed)) {
5700
+ const valid = validSectionOrder(value);
5701
+ if (valid === null) continue;
5702
+ order[canonicalSectionId(key)] = valid;
5703
+ }
5704
+ return order;
5705
+ }
5706
+ function encodeMethodSectionOrder(order) {
5707
+ return JSON.stringify(order);
5708
+ }
5709
+ function decodeMethodSectionLabels(raw) {
5710
+ if (raw === void 0) return {};
5711
+ let parsed;
5712
+ try {
5713
+ parsed = JSON.parse(raw);
5714
+ } catch {
5715
+ return {};
5716
+ }
5717
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
5718
+ const labels = {};
5719
+ for (const [section, byLocale] of Object.entries(parsed)) {
5720
+ if (!section || byLocale === null || typeof byLocale !== "object" || Array.isArray(byLocale)) {
5721
+ continue;
5722
+ }
5723
+ const kept = {};
5724
+ for (const [locale, text] of Object.entries(byLocale)) {
5725
+ if (typeof text !== "string") continue;
5726
+ const trimmed = text.trim();
5727
+ if (!trimmed) continue;
5728
+ kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);
5729
+ }
5730
+ if (Object.keys(kept).length > 0) labels[canonicalSectionId(section)] = kept;
5731
+ }
5732
+ return labels;
5733
+ }
5734
+ function encodeMethodSectionLabels(labels) {
5735
+ const cleaned = {};
5736
+ for (const [section, byLocale] of Object.entries(labels)) {
5737
+ const kept = {};
5738
+ for (const [locale, text] of Object.entries(byLocale)) {
5739
+ const trimmed = (text ?? "").trim();
5740
+ if (trimmed) kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);
5741
+ }
5742
+ if (Object.keys(kept).length > 0) cleaned[section] = kept;
5743
+ }
5744
+ return Object.keys(cleaned).length > 0 ? JSON.stringify(cleaned) : null;
5745
+ }
5746
+ function sectionCatalogueIndex(sectionId) {
5747
+ const index = METHOD_SECTIONS.findIndex((section) => section.id === sectionId);
5748
+ return index === -1 ? METHOD_SECTIONS.length : index;
5749
+ }
5750
+ function sectionOrderOf(order, category) {
5751
+ return order[canonicalSectionId(category)] ?? UNKNOWN_SECTION_ORDER;
5752
+ }
5753
+ function compareSections(order) {
5754
+ return (a, b) => {
5755
+ const left = canonicalSectionId(a);
5756
+ const right = canonicalSectionId(b);
5757
+ const byOrder = sectionOrderOf(order, left) - sectionOrderOf(order, right);
5758
+ if (byOrder !== 0) return byOrder;
5759
+ const byCatalogue = sectionCatalogueIndex(left) - sectionCatalogueIndex(right);
5760
+ if (byCatalogue !== 0) return byCatalogue;
5761
+ return left < right ? -1 : left > right ? 1 : 0;
5762
+ };
5763
+ }
5764
+ function sectionLabel(labels, category, locale, knownKey, translate) {
5765
+ const id = canonicalSectionId(category);
5766
+ if (id in labels) {
5767
+ const captions = labels[id];
5768
+ const matched = translationFor(captions, locale)?.trim();
5769
+ if (matched) return matched;
5770
+ for (const value of Object.values(captions)) {
5771
+ const any = value.trim();
5772
+ if (any) return any;
5773
+ }
5774
+ }
5775
+ if (knownKey) {
5776
+ const translated = translate(knownKey);
5777
+ if (translated) return translated;
5778
+ }
5779
+ return category;
5780
+ }
5781
+ function parseSectionOrderLoose(raw) {
5782
+ if (typeof raw === "string") return decodeMethodSectionOrder(raw);
5783
+ if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
5784
+ return decodeMethodSectionOrder(JSON.stringify(raw));
5785
+ }
5786
+ return defaultMethodSectionOrder();
5787
+ }
5788
+ function parseSectionLabelsLoose(raw) {
5789
+ if (typeof raw === "string") return decodeMethodSectionLabels(raw);
5790
+ if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
5791
+ return decodeMethodSectionLabels(JSON.stringify(raw));
5792
+ }
5793
+ return {};
5794
+ }
5795
+ function knownSectionLabelKey(category) {
5796
+ const id = canonicalSectionId(category);
5797
+ return METHOD_SECTIONS.find((section) => section.id === id)?.labelKey;
5798
+ }
5637
5799
  var DEFAULT_BRANDING_BASE = {
5638
5800
  displayName: "",
5639
5801
  logoUrl: "",
@@ -5722,7 +5884,9 @@ var DEFAULT_BRANDING = {
5722
5884
  ...DEFAULT_BRANDING_BASE,
5723
5885
  ...LIGHT_PALETTE,
5724
5886
  trustBadges: DEFAULT_BADGES.map((b) => ({ ...b })),
5725
- customFields: []
5887
+ customFields: [],
5888
+ methodSectionOrder: defaultMethodSectionOrder(),
5889
+ methodSectionLabels: {}
5726
5890
  };
5727
5891
  var DEFAULT_BRANDING_DARK = {
5728
5892
  ...DEFAULT_BRANDING_BASE,
@@ -5743,7 +5907,9 @@ var DEFAULT_BRANDING_DARK = {
5743
5907
  surchargeColor: "#fbbf24",
5744
5908
  discountColor: "#34d399",
5745
5909
  trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b })),
5746
- customFields: []
5910
+ customFields: [],
5911
+ methodSectionOrder: defaultMethodSectionOrder(),
5912
+ methodSectionLabels: {}
5747
5913
  };
5748
5914
  function defaultBranding() {
5749
5915
  return cloneBranding(DEFAULT_BRANDING);
@@ -5753,6 +5919,10 @@ function cloneBranding(b) {
5753
5919
  ...b,
5754
5920
  trustBadges: b.trustBadges.map((badge) => ({ ...badge })),
5755
5921
  customFields: b.customFields.map(cloneCustomField),
5922
+ methodSectionOrder: { ...b.methodSectionOrder },
5923
+ methodSectionLabels: Object.fromEntries(
5924
+ Object.entries(b.methodSectionLabels).map(([id, byLocale]) => [id, { ...byLocale }])
5925
+ ),
5756
5926
  // Copied, not shared. A spread alone would leave the clone pointing at the
5757
5927
  // original's maps, and the dashboard edits a clone precisely so the form
5758
5928
  // can be abandoned without touching what is saved.
@@ -6368,6 +6538,8 @@ function decodeBranding(source) {
6368
6538
  showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
6369
6539
  trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
6370
6540
  customFields: decodedCustomFields ?? [],
6541
+ methodSectionOrder: decodeMethodSectionOrder(extras[METHOD_SECTION_ORDER_KEY]),
6542
+ methodSectionLabels: decodeMethodSectionLabels(extras[METHOD_SECTION_LABELS_KEY]),
6371
6543
  headerText: s(source.payment_form_header_text),
6372
6544
  payButtonLabel: s(source.payment_button_text),
6373
6545
  cardTermsMessage: s(source.custom_message_for_card_terms),
@@ -6434,8 +6606,11 @@ function encodeBranding(branding, base) {
6434
6606
  logoShape: branding.logoShape,
6435
6607
  logoSize: branding.logoSize,
6436
6608
  labelStyle: branding.labelStyle,
6437
- trustBadges: encodeBadges(branding.trustBadges)
6609
+ trustBadges: encodeBadges(branding.trustBadges),
6610
+ [METHOD_SECTION_ORDER_KEY]: encodeMethodSectionOrder(branding.methodSectionOrder)
6438
6611
  };
6612
+ const sectionLabels = encodeMethodSectionLabels(branding.methodSectionLabels);
6613
+ if (sectionLabels) extras[METHOD_SECTION_LABELS_KEY] = sectionLabels;
6439
6614
  if (branding.customFields.length > 0) {
6440
6615
  extras["customFields"] = encodeCustomFields(branding.customFields);
6441
6616
  }
@@ -6637,6 +6812,10 @@ function parseImportedBranding(raw) {
6637
6812
  showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
6638
6813
  trustBadges,
6639
6814
  customFields,
6815
+ // An export writes the decoded maps; a hand-written file may carry the
6816
+ // JSON strings the bag uses. Both are accepted, and neither is required.
6817
+ methodSectionOrder: parseSectionOrderLoose(root[METHOD_SECTION_ORDER_KEY]),
6818
+ methodSectionLabels: parseSectionLabelsLoose(root[METHOD_SECTION_LABELS_KEY]),
6640
6819
  headerText: sStr(root["headerText"], dflt.headerText),
6641
6820
  payButtonLabel: sStr(root["payButtonLabel"], dflt.payButtonLabel),
6642
6821
  cardTermsMessage: sStr(root["cardTermsMessage"], dflt.cardTermsMessage),
@@ -8458,6 +8637,10 @@ var DelopayInternal = class extends Delopay {
8458
8637
  Forex,
8459
8638
  Gsm,
8460
8639
  LOCALIZABLE_COPY_FIELDS,
8640
+ MAX_SECTION_LABEL_LENGTH,
8641
+ MAX_SECTION_ORDER,
8642
+ METHOD_SECTIONS,
8643
+ MIN_SECTION_ORDER,
8461
8644
  NATIVE_PANES_MAX,
8462
8645
  NATIVE_PANE_CATEGORY_KEYS,
8463
8646
  NATIVE_PANE_ICON_KEYS,
@@ -8470,6 +8653,7 @@ var DelopayInternal = class extends Delopay {
8470
8653
  RTL_CHECKOUT_LOCALES,
8471
8654
  Regions,
8472
8655
  Risk,
8656
+ SECTION_ALIASES,
8473
8657
  STRIPE_FALLBACK_PANE_CATALOG,
8474
8658
  STRIPE_FALLBACK_PANE_METHODS,
8475
8659
  STRIPE_NATIVE_PANE_METHODS,
@@ -8486,6 +8670,7 @@ var DelopayInternal = class extends Delopay {
8486
8670
  Search,
8487
8671
  Settlement,
8488
8672
  Subscriptions,
8673
+ UNKNOWN_SECTION_ORDER,
8489
8674
  WCAG_AA_TEXT,
8490
8675
  WCAG_AA_UI,
8491
8676
  Webhooks,
@@ -8494,12 +8679,14 @@ var DelopayInternal = class extends Delopay {
8494
8679
  applyBrandingVariables,
8495
8680
  buildBrandingExport,
8496
8681
  buttonPadValue,
8682
+ canonicalSectionId,
8497
8683
  checkoutCopy,
8498
8684
  checkoutLocaleDir,
8499
8685
  cloneBranding,
8500
8686
  cloneCustomField,
8501
8687
  cloneNativePane,
8502
8688
  clonePane,
8689
+ compareSections,
8503
8690
  contrastRatio,
8504
8691
  copyTranslationsKey,
8505
8692
  customFieldContextFromMetadata,
@@ -8510,10 +8697,13 @@ var DelopayInternal = class extends Delopay {
8510
8697
  decodeBadges,
8511
8698
  decodeBranding,
8512
8699
  decodeCustomFields,
8700
+ decodeMethodSectionLabels,
8701
+ decodeMethodSectionOrder,
8513
8702
  decodeNativePanes,
8514
8703
  decodePanes,
8515
8704
  defaultBranding,
8516
8705
  defaultCustomFieldVisibility,
8706
+ defaultMethodSectionOrder,
8517
8707
  defaultNativePane,
8518
8708
  defaultOperatorForSource,
8519
8709
  defaultPane,
@@ -8521,6 +8711,8 @@ var DelopayInternal = class extends Delopay {
8521
8711
  encodeBadges,
8522
8712
  encodeBranding,
8523
8713
  encodeCustomFields,
8714
+ encodeMethodSectionLabels,
8715
+ encodeMethodSectionOrder,
8524
8716
  encodeNativePanes,
8525
8717
  encodePanes,
8526
8718
  evaluateCustomFieldCondition,
@@ -8533,6 +8725,7 @@ var DelopayInternal = class extends Delopay {
8533
8725
  isCheckboxChecked,
8534
8726
  isDarkSurface,
8535
8727
  isHexColor,
8728
+ knownSectionLabelKey,
8536
8729
  leaf,
8537
8730
  logoDimensions,
8538
8731
  nativePaneMethodInfo,
@@ -8549,12 +8742,15 @@ var DelopayInternal = class extends Delopay {
8549
8742
  readableInkOn,
8550
8743
  ruleMatchToTree,
8551
8744
  sanitizeCustomCss,
8745
+ sectionLabel,
8746
+ sectionOrderOf,
8552
8747
  shadowFor,
8553
8748
  surchargeFigurePlan,
8554
8749
  surchargeShowsLabel,
8555
8750
  surchargeStyleDrawsAShape,
8556
8751
  surchargeWordFor,
8557
8752
  surfacePadValue,
8753
+ validSectionOrder,
8558
8754
  validatePanes,
8559
8755
  verticalGapValue,
8560
8756
  visibleCustomFields