@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/index.cjs CHANGED
@@ -54,6 +54,10 @@ __export(index_exports, {
54
54
  Files: () => Files,
55
55
  Forex: () => Forex,
56
56
  LOCALIZABLE_COPY_FIELDS: () => LOCALIZABLE_COPY_FIELDS,
57
+ MAX_SECTION_LABEL_LENGTH: () => MAX_SECTION_LABEL_LENGTH,
58
+ MAX_SECTION_ORDER: () => MAX_SECTION_ORDER,
59
+ METHOD_SECTIONS: () => METHOD_SECTIONS,
60
+ MIN_SECTION_ORDER: () => MIN_SECTION_ORDER,
57
61
  NATIVE_PANES_MAX: () => NATIVE_PANES_MAX,
58
62
  NATIVE_PANE_CATEGORY_KEYS: () => NATIVE_PANE_CATEGORY_KEYS,
59
63
  NATIVE_PANE_ICON_KEYS: () => NATIVE_PANE_ICON_KEYS,
@@ -64,6 +68,7 @@ __export(index_exports, {
64
68
  RTL_CHECKOUT_LOCALES: () => RTL_CHECKOUT_LOCALES,
65
69
  Regions: () => Regions,
66
70
  Risk: () => Risk,
71
+ SECTION_ALIASES: () => SECTION_ALIASES,
67
72
  STRIPE_FALLBACK_PANE_CATALOG: () => STRIPE_FALLBACK_PANE_CATALOG,
68
73
  STRIPE_FALLBACK_PANE_METHODS: () => STRIPE_FALLBACK_PANE_METHODS,
69
74
  STRIPE_NATIVE_PANE_METHODS: () => STRIPE_NATIVE_PANE_METHODS,
@@ -80,6 +85,7 @@ __export(index_exports, {
80
85
  Search: () => Search,
81
86
  Settlement: () => Settlement,
82
87
  Subscriptions: () => Subscriptions,
88
+ UNKNOWN_SECTION_ORDER: () => UNKNOWN_SECTION_ORDER,
83
89
  WCAG_AA_TEXT: () => WCAG_AA_TEXT,
84
90
  WCAG_AA_UI: () => WCAG_AA_UI,
85
91
  Webhooks: () => Webhooks,
@@ -88,12 +94,14 @@ __export(index_exports, {
88
94
  applyBrandingVariables: () => applyBrandingVariables,
89
95
  buildBrandingExport: () => buildBrandingExport,
90
96
  buttonPadValue: () => buttonPadValue,
97
+ canonicalSectionId: () => canonicalSectionId,
91
98
  checkoutCopy: () => checkoutCopy,
92
99
  checkoutLocaleDir: () => checkoutLocaleDir,
93
100
  cloneBranding: () => cloneBranding,
94
101
  cloneCustomField: () => cloneCustomField,
95
102
  cloneNativePane: () => cloneNativePane,
96
103
  clonePane: () => clonePane,
104
+ compareSections: () => compareSections,
97
105
  contrastRatio: () => contrastRatio,
98
106
  copyTranslationsKey: () => copyTranslationsKey,
99
107
  customFieldContextFromMetadata: () => customFieldContextFromMetadata,
@@ -104,10 +112,13 @@ __export(index_exports, {
104
112
  decodeBadges: () => decodeBadges,
105
113
  decodeBranding: () => decodeBranding,
106
114
  decodeCustomFields: () => decodeCustomFields,
115
+ decodeMethodSectionLabels: () => decodeMethodSectionLabels,
116
+ decodeMethodSectionOrder: () => decodeMethodSectionOrder,
107
117
  decodeNativePanes: () => decodeNativePanes,
108
118
  decodePanes: () => decodePanes,
109
119
  defaultBranding: () => defaultBranding,
110
120
  defaultCustomFieldVisibility: () => defaultCustomFieldVisibility,
121
+ defaultMethodSectionOrder: () => defaultMethodSectionOrder,
111
122
  defaultNativePane: () => defaultNativePane,
112
123
  defaultOperatorForSource: () => defaultOperatorForSource,
113
124
  defaultPane: () => defaultPane,
@@ -115,6 +126,8 @@ __export(index_exports, {
115
126
  encodeBadges: () => encodeBadges,
116
127
  encodeBranding: () => encodeBranding,
117
128
  encodeCustomFields: () => encodeCustomFields,
129
+ encodeMethodSectionLabels: () => encodeMethodSectionLabels,
130
+ encodeMethodSectionOrder: () => encodeMethodSectionOrder,
118
131
  encodeNativePanes: () => encodeNativePanes,
119
132
  encodePanes: () => encodePanes,
120
133
  evaluateCustomFieldCondition: () => evaluateCustomFieldCondition,
@@ -127,6 +140,7 @@ __export(index_exports, {
127
140
  isCheckboxChecked: () => isCheckboxChecked,
128
141
  isDarkSurface: () => isDarkSurface,
129
142
  isHexColor: () => isHexColor,
143
+ knownSectionLabelKey: () => knownSectionLabelKey,
130
144
  leaf: () => leaf,
131
145
  logoDimensions: () => logoDimensions,
132
146
  nativePaneMethodInfo: () => nativePaneMethodInfo,
@@ -143,12 +157,15 @@ __export(index_exports, {
143
157
  readableInkOn: () => readableInkOn,
144
158
  ruleMatchToTree: () => ruleMatchToTree,
145
159
  sanitizeCustomCss: () => sanitizeCustomCss,
160
+ sectionLabel: () => sectionLabel,
161
+ sectionOrderOf: () => sectionOrderOf,
146
162
  shadowFor: () => shadowFor,
147
163
  surchargeFigurePlan: () => surchargeFigurePlan,
148
164
  surchargeShowsLabel: () => surchargeShowsLabel,
149
165
  surchargeStyleDrawsAShape: () => surchargeStyleDrawsAShape,
150
166
  surchargeWordFor: () => surchargeWordFor,
151
167
  surfacePadValue: () => surfacePadValue,
168
+ validSectionOrder: () => validSectionOrder,
152
169
  validatePanes: () => validatePanes,
153
170
  verticalGapValue: () => verticalGapValue,
154
171
  visibleCustomFields: () => visibleCustomFields
@@ -5622,6 +5639,151 @@ var DEFAULT_BADGES_DARK = [
5622
5639
  borderColor: "#1e40af"
5623
5640
  }
5624
5641
  ];
5642
+ var METHOD_SECTION_ORDER_KEY = "methodSectionOrder";
5643
+ var METHOD_SECTION_LABELS_KEY = "methodSectionLabels";
5644
+ var MIN_SECTION_ORDER = 1;
5645
+ var MAX_SECTION_ORDER = 100;
5646
+ var MAX_SECTION_LABEL_LENGTH = 120;
5647
+ var METHOD_SECTIONS = [
5648
+ { id: "card", labelKey: "sections.card", order: 10 },
5649
+ { id: "wallet", labelKey: "sections.wallets", order: 20 },
5650
+ { id: "bnpl", labelKey: "sections.bnpl", order: 30 },
5651
+ { id: "bank_redirect", labelKey: "sections.onlineBanking", order: 40 },
5652
+ { id: "bank_transfer", labelKey: "sections.bankTransfer", order: 45 },
5653
+ { id: "crypto", labelKey: "sections.cryptocurrency", order: 50 },
5654
+ { id: "game_items", labelKey: "sections.gameItems", order: 60 },
5655
+ { id: "voucher", labelKey: "sections.vouchers", order: 70 },
5656
+ { id: "gift_card", labelKey: "sections.giftCards", order: 75 },
5657
+ { id: "reward", labelKey: "sections.rewards", order: 80 },
5658
+ { id: "cash", labelKey: "sections.cash", order: 90 }
5659
+ ];
5660
+ var SECTION_ALIASES = {
5661
+ card_redirect: "card"
5662
+ };
5663
+ var UNKNOWN_SECTION_ORDER = MAX_SECTION_ORDER;
5664
+ function canonicalSectionId(category) {
5665
+ return SECTION_ALIASES[category] ?? category;
5666
+ }
5667
+ function defaultMethodSectionOrder() {
5668
+ const order = {};
5669
+ for (const section of METHOD_SECTIONS) order[section.id] = section.order;
5670
+ return order;
5671
+ }
5672
+ function validSectionOrder(raw) {
5673
+ if (typeof raw !== "number" || !Number.isInteger(raw)) return null;
5674
+ if (raw < MIN_SECTION_ORDER || raw > MAX_SECTION_ORDER) return null;
5675
+ return raw;
5676
+ }
5677
+ function decodeMethodSectionOrder(raw) {
5678
+ const order = defaultMethodSectionOrder();
5679
+ if (raw === void 0) return order;
5680
+ let parsed;
5681
+ try {
5682
+ parsed = JSON.parse(raw);
5683
+ } catch {
5684
+ return order;
5685
+ }
5686
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return order;
5687
+ for (const [key, value] of Object.entries(parsed)) {
5688
+ const valid = validSectionOrder(value);
5689
+ if (valid === null) continue;
5690
+ order[canonicalSectionId(key)] = valid;
5691
+ }
5692
+ return order;
5693
+ }
5694
+ function encodeMethodSectionOrder(order) {
5695
+ return JSON.stringify(order);
5696
+ }
5697
+ function decodeMethodSectionLabels(raw) {
5698
+ if (raw === void 0) return {};
5699
+ let parsed;
5700
+ try {
5701
+ parsed = JSON.parse(raw);
5702
+ } catch {
5703
+ return {};
5704
+ }
5705
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
5706
+ const labels = {};
5707
+ for (const [section, byLocale] of Object.entries(parsed)) {
5708
+ if (!section || byLocale === null || typeof byLocale !== "object" || Array.isArray(byLocale)) {
5709
+ continue;
5710
+ }
5711
+ const kept = {};
5712
+ for (const [locale, text] of Object.entries(byLocale)) {
5713
+ if (typeof text !== "string") continue;
5714
+ const trimmed = text.trim();
5715
+ if (!trimmed) continue;
5716
+ kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);
5717
+ }
5718
+ if (Object.keys(kept).length > 0) labels[canonicalSectionId(section)] = kept;
5719
+ }
5720
+ return labels;
5721
+ }
5722
+ function encodeMethodSectionLabels(labels) {
5723
+ const cleaned = {};
5724
+ for (const [section, byLocale] of Object.entries(labels)) {
5725
+ const kept = {};
5726
+ for (const [locale, text] of Object.entries(byLocale)) {
5727
+ const trimmed = (text ?? "").trim();
5728
+ if (trimmed) kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);
5729
+ }
5730
+ if (Object.keys(kept).length > 0) cleaned[section] = kept;
5731
+ }
5732
+ return Object.keys(cleaned).length > 0 ? JSON.stringify(cleaned) : null;
5733
+ }
5734
+ function sectionCatalogueIndex(sectionId) {
5735
+ const index = METHOD_SECTIONS.findIndex((section) => section.id === sectionId);
5736
+ return index === -1 ? METHOD_SECTIONS.length : index;
5737
+ }
5738
+ function sectionOrderOf(order, category) {
5739
+ return order[canonicalSectionId(category)] ?? UNKNOWN_SECTION_ORDER;
5740
+ }
5741
+ function compareSections(order) {
5742
+ return (a, b) => {
5743
+ const left = canonicalSectionId(a);
5744
+ const right = canonicalSectionId(b);
5745
+ const byOrder = sectionOrderOf(order, left) - sectionOrderOf(order, right);
5746
+ if (byOrder !== 0) return byOrder;
5747
+ const byCatalogue = sectionCatalogueIndex(left) - sectionCatalogueIndex(right);
5748
+ if (byCatalogue !== 0) return byCatalogue;
5749
+ return left < right ? -1 : left > right ? 1 : 0;
5750
+ };
5751
+ }
5752
+ function sectionLabel(labels, category, locale, knownKey, translate) {
5753
+ const id = canonicalSectionId(category);
5754
+ if (id in labels) {
5755
+ const captions = labels[id];
5756
+ const matched = translationFor(captions, locale)?.trim();
5757
+ if (matched) return matched;
5758
+ for (const value of Object.values(captions)) {
5759
+ const any = value.trim();
5760
+ if (any) return any;
5761
+ }
5762
+ }
5763
+ if (knownKey) {
5764
+ const translated = translate(knownKey);
5765
+ if (translated) return translated;
5766
+ }
5767
+ return category;
5768
+ }
5769
+ function parseSectionOrderLoose(raw) {
5770
+ if (typeof raw === "string") return decodeMethodSectionOrder(raw);
5771
+ if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
5772
+ return decodeMethodSectionOrder(JSON.stringify(raw));
5773
+ }
5774
+ return defaultMethodSectionOrder();
5775
+ }
5776
+ function parseSectionLabelsLoose(raw) {
5777
+ if (typeof raw === "string") return decodeMethodSectionLabels(raw);
5778
+ if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
5779
+ return decodeMethodSectionLabels(JSON.stringify(raw));
5780
+ }
5781
+ return {};
5782
+ }
5783
+ function knownSectionLabelKey(category) {
5784
+ const id = canonicalSectionId(category);
5785
+ return METHOD_SECTIONS.find((section) => section.id === id)?.labelKey;
5786
+ }
5625
5787
  var DEFAULT_BRANDING_BASE = {
5626
5788
  displayName: "",
5627
5789
  logoUrl: "",
@@ -5710,7 +5872,9 @@ var DEFAULT_BRANDING = {
5710
5872
  ...DEFAULT_BRANDING_BASE,
5711
5873
  ...LIGHT_PALETTE,
5712
5874
  trustBadges: DEFAULT_BADGES.map((b) => ({ ...b })),
5713
- customFields: []
5875
+ customFields: [],
5876
+ methodSectionOrder: defaultMethodSectionOrder(),
5877
+ methodSectionLabels: {}
5714
5878
  };
5715
5879
  var DEFAULT_BRANDING_DARK = {
5716
5880
  ...DEFAULT_BRANDING_BASE,
@@ -5731,7 +5895,9 @@ var DEFAULT_BRANDING_DARK = {
5731
5895
  surchargeColor: "#fbbf24",
5732
5896
  discountColor: "#34d399",
5733
5897
  trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b })),
5734
- customFields: []
5898
+ customFields: [],
5899
+ methodSectionOrder: defaultMethodSectionOrder(),
5900
+ methodSectionLabels: {}
5735
5901
  };
5736
5902
  function defaultBranding() {
5737
5903
  return cloneBranding(DEFAULT_BRANDING);
@@ -5741,6 +5907,10 @@ function cloneBranding(b) {
5741
5907
  ...b,
5742
5908
  trustBadges: b.trustBadges.map((badge) => ({ ...badge })),
5743
5909
  customFields: b.customFields.map(cloneCustomField),
5910
+ methodSectionOrder: { ...b.methodSectionOrder },
5911
+ methodSectionLabels: Object.fromEntries(
5912
+ Object.entries(b.methodSectionLabels).map(([id, byLocale]) => [id, { ...byLocale }])
5913
+ ),
5744
5914
  // Copied, not shared. A spread alone would leave the clone pointing at the
5745
5915
  // original's maps, and the dashboard edits a clone precisely so the form
5746
5916
  // can be abandoned without touching what is saved.
@@ -6356,6 +6526,8 @@ function decodeBranding(source) {
6356
6526
  showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
6357
6527
  trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
6358
6528
  customFields: decodedCustomFields ?? [],
6529
+ methodSectionOrder: decodeMethodSectionOrder(extras[METHOD_SECTION_ORDER_KEY]),
6530
+ methodSectionLabels: decodeMethodSectionLabels(extras[METHOD_SECTION_LABELS_KEY]),
6359
6531
  headerText: s(source.payment_form_header_text),
6360
6532
  payButtonLabel: s(source.payment_button_text),
6361
6533
  cardTermsMessage: s(source.custom_message_for_card_terms),
@@ -6422,8 +6594,11 @@ function encodeBranding(branding, base) {
6422
6594
  logoShape: branding.logoShape,
6423
6595
  logoSize: branding.logoSize,
6424
6596
  labelStyle: branding.labelStyle,
6425
- trustBadges: encodeBadges(branding.trustBadges)
6597
+ trustBadges: encodeBadges(branding.trustBadges),
6598
+ [METHOD_SECTION_ORDER_KEY]: encodeMethodSectionOrder(branding.methodSectionOrder)
6426
6599
  };
6600
+ const sectionLabels = encodeMethodSectionLabels(branding.methodSectionLabels);
6601
+ if (sectionLabels) extras[METHOD_SECTION_LABELS_KEY] = sectionLabels;
6427
6602
  if (branding.customFields.length > 0) {
6428
6603
  extras["customFields"] = encodeCustomFields(branding.customFields);
6429
6604
  }
@@ -6625,6 +6800,10 @@ function parseImportedBranding(raw) {
6625
6800
  showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
6626
6801
  trustBadges,
6627
6802
  customFields,
6803
+ // An export writes the decoded maps; a hand-written file may carry the
6804
+ // JSON strings the bag uses. Both are accepted, and neither is required.
6805
+ methodSectionOrder: parseSectionOrderLoose(root[METHOD_SECTION_ORDER_KEY]),
6806
+ methodSectionLabels: parseSectionLabelsLoose(root[METHOD_SECTION_LABELS_KEY]),
6628
6807
  headerText: sStr(root["headerText"], dflt.headerText),
6629
6808
  payButtonLabel: sStr(root["payButtonLabel"], dflt.payButtonLabel),
6630
6809
  cardTermsMessage: sStr(root["cardTermsMessage"], dflt.cardTermsMessage),
@@ -7462,6 +7641,10 @@ var encodeNativePanes = encodePanes;
7462
7641
  Files,
7463
7642
  Forex,
7464
7643
  LOCALIZABLE_COPY_FIELDS,
7644
+ MAX_SECTION_LABEL_LENGTH,
7645
+ MAX_SECTION_ORDER,
7646
+ METHOD_SECTIONS,
7647
+ MIN_SECTION_ORDER,
7465
7648
  NATIVE_PANES_MAX,
7466
7649
  NATIVE_PANE_CATEGORY_KEYS,
7467
7650
  NATIVE_PANE_ICON_KEYS,
@@ -7472,6 +7655,7 @@ var encodeNativePanes = encodePanes;
7472
7655
  RTL_CHECKOUT_LOCALES,
7473
7656
  Regions,
7474
7657
  Risk,
7658
+ SECTION_ALIASES,
7475
7659
  STRIPE_FALLBACK_PANE_CATALOG,
7476
7660
  STRIPE_FALLBACK_PANE_METHODS,
7477
7661
  STRIPE_NATIVE_PANE_METHODS,
@@ -7488,6 +7672,7 @@ var encodeNativePanes = encodePanes;
7488
7672
  Search,
7489
7673
  Settlement,
7490
7674
  Subscriptions,
7675
+ UNKNOWN_SECTION_ORDER,
7491
7676
  WCAG_AA_TEXT,
7492
7677
  WCAG_AA_UI,
7493
7678
  Webhooks,
@@ -7496,12 +7681,14 @@ var encodeNativePanes = encodePanes;
7496
7681
  applyBrandingVariables,
7497
7682
  buildBrandingExport,
7498
7683
  buttonPadValue,
7684
+ canonicalSectionId,
7499
7685
  checkoutCopy,
7500
7686
  checkoutLocaleDir,
7501
7687
  cloneBranding,
7502
7688
  cloneCustomField,
7503
7689
  cloneNativePane,
7504
7690
  clonePane,
7691
+ compareSections,
7505
7692
  contrastRatio,
7506
7693
  copyTranslationsKey,
7507
7694
  customFieldContextFromMetadata,
@@ -7512,10 +7699,13 @@ var encodeNativePanes = encodePanes;
7512
7699
  decodeBadges,
7513
7700
  decodeBranding,
7514
7701
  decodeCustomFields,
7702
+ decodeMethodSectionLabels,
7703
+ decodeMethodSectionOrder,
7515
7704
  decodeNativePanes,
7516
7705
  decodePanes,
7517
7706
  defaultBranding,
7518
7707
  defaultCustomFieldVisibility,
7708
+ defaultMethodSectionOrder,
7519
7709
  defaultNativePane,
7520
7710
  defaultOperatorForSource,
7521
7711
  defaultPane,
@@ -7523,6 +7713,8 @@ var encodeNativePanes = encodePanes;
7523
7713
  encodeBadges,
7524
7714
  encodeBranding,
7525
7715
  encodeCustomFields,
7716
+ encodeMethodSectionLabels,
7717
+ encodeMethodSectionOrder,
7526
7718
  encodeNativePanes,
7527
7719
  encodePanes,
7528
7720
  evaluateCustomFieldCondition,
@@ -7535,6 +7727,7 @@ var encodeNativePanes = encodePanes;
7535
7727
  isCheckboxChecked,
7536
7728
  isDarkSurface,
7537
7729
  isHexColor,
7730
+ knownSectionLabelKey,
7538
7731
  leaf,
7539
7732
  logoDimensions,
7540
7733
  nativePaneMethodInfo,
@@ -7551,12 +7744,15 @@ var encodeNativePanes = encodePanes;
7551
7744
  readableInkOn,
7552
7745
  ruleMatchToTree,
7553
7746
  sanitizeCustomCss,
7747
+ sectionLabel,
7748
+ sectionOrderOf,
7554
7749
  shadowFor,
7555
7750
  surchargeFigurePlan,
7556
7751
  surchargeShowsLabel,
7557
7752
  surchargeStyleDrawsAShape,
7558
7753
  surchargeWordFor,
7559
7754
  surfacePadValue,
7755
+ validSectionOrder,
7560
7756
  validatePanes,
7561
7757
  verticalGapValue,
7562
7758
  visibleCustomFields