@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.
@@ -5465,6 +5465,151 @@ var DEFAULT_BADGES_DARK = [
5465
5465
  borderColor: "#1e40af"
5466
5466
  }
5467
5467
  ];
5468
+ var METHOD_SECTION_ORDER_KEY = "methodSectionOrder";
5469
+ var METHOD_SECTION_LABELS_KEY = "methodSectionLabels";
5470
+ var MIN_SECTION_ORDER = 1;
5471
+ var MAX_SECTION_ORDER = 100;
5472
+ var MAX_SECTION_LABEL_LENGTH = 120;
5473
+ var METHOD_SECTIONS = [
5474
+ { id: "card", labelKey: "sections.card", order: 10 },
5475
+ { id: "wallet", labelKey: "sections.wallets", order: 20 },
5476
+ { id: "bnpl", labelKey: "sections.bnpl", order: 30 },
5477
+ { id: "bank_redirect", labelKey: "sections.onlineBanking", order: 40 },
5478
+ { id: "bank_transfer", labelKey: "sections.bankTransfer", order: 45 },
5479
+ { id: "crypto", labelKey: "sections.cryptocurrency", order: 50 },
5480
+ { id: "game_items", labelKey: "sections.gameItems", order: 60 },
5481
+ { id: "voucher", labelKey: "sections.vouchers", order: 70 },
5482
+ { id: "gift_card", labelKey: "sections.giftCards", order: 75 },
5483
+ { id: "reward", labelKey: "sections.rewards", order: 80 },
5484
+ { id: "cash", labelKey: "sections.cash", order: 90 }
5485
+ ];
5486
+ var SECTION_ALIASES = {
5487
+ card_redirect: "card"
5488
+ };
5489
+ var UNKNOWN_SECTION_ORDER = MAX_SECTION_ORDER;
5490
+ function canonicalSectionId(category) {
5491
+ return SECTION_ALIASES[category] ?? category;
5492
+ }
5493
+ function defaultMethodSectionOrder() {
5494
+ const order = {};
5495
+ for (const section of METHOD_SECTIONS) order[section.id] = section.order;
5496
+ return order;
5497
+ }
5498
+ function validSectionOrder(raw) {
5499
+ if (typeof raw !== "number" || !Number.isInteger(raw)) return null;
5500
+ if (raw < MIN_SECTION_ORDER || raw > MAX_SECTION_ORDER) return null;
5501
+ return raw;
5502
+ }
5503
+ function decodeMethodSectionOrder(raw) {
5504
+ const order = defaultMethodSectionOrder();
5505
+ if (raw === void 0) return order;
5506
+ let parsed;
5507
+ try {
5508
+ parsed = JSON.parse(raw);
5509
+ } catch {
5510
+ return order;
5511
+ }
5512
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return order;
5513
+ for (const [key, value] of Object.entries(parsed)) {
5514
+ const valid = validSectionOrder(value);
5515
+ if (valid === null) continue;
5516
+ order[canonicalSectionId(key)] = valid;
5517
+ }
5518
+ return order;
5519
+ }
5520
+ function encodeMethodSectionOrder(order) {
5521
+ return JSON.stringify(order);
5522
+ }
5523
+ function decodeMethodSectionLabels(raw) {
5524
+ if (raw === void 0) return {};
5525
+ let parsed;
5526
+ try {
5527
+ parsed = JSON.parse(raw);
5528
+ } catch {
5529
+ return {};
5530
+ }
5531
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
5532
+ const labels = {};
5533
+ for (const [section, byLocale] of Object.entries(parsed)) {
5534
+ if (!section || byLocale === null || typeof byLocale !== "object" || Array.isArray(byLocale)) {
5535
+ continue;
5536
+ }
5537
+ const kept = {};
5538
+ for (const [locale, text] of Object.entries(byLocale)) {
5539
+ if (typeof text !== "string") continue;
5540
+ const trimmed = text.trim();
5541
+ if (!trimmed) continue;
5542
+ kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);
5543
+ }
5544
+ if (Object.keys(kept).length > 0) labels[canonicalSectionId(section)] = kept;
5545
+ }
5546
+ return labels;
5547
+ }
5548
+ function encodeMethodSectionLabels(labels) {
5549
+ const cleaned = {};
5550
+ for (const [section, byLocale] of Object.entries(labels)) {
5551
+ const kept = {};
5552
+ for (const [locale, text] of Object.entries(byLocale)) {
5553
+ const trimmed = (text ?? "").trim();
5554
+ if (trimmed) kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);
5555
+ }
5556
+ if (Object.keys(kept).length > 0) cleaned[section] = kept;
5557
+ }
5558
+ return Object.keys(cleaned).length > 0 ? JSON.stringify(cleaned) : null;
5559
+ }
5560
+ function sectionCatalogueIndex(sectionId) {
5561
+ const index = METHOD_SECTIONS.findIndex((section) => section.id === sectionId);
5562
+ return index === -1 ? METHOD_SECTIONS.length : index;
5563
+ }
5564
+ function sectionOrderOf(order, category) {
5565
+ return order[canonicalSectionId(category)] ?? UNKNOWN_SECTION_ORDER;
5566
+ }
5567
+ function compareSections(order) {
5568
+ return (a, b) => {
5569
+ const left = canonicalSectionId(a);
5570
+ const right = canonicalSectionId(b);
5571
+ const byOrder = sectionOrderOf(order, left) - sectionOrderOf(order, right);
5572
+ if (byOrder !== 0) return byOrder;
5573
+ const byCatalogue = sectionCatalogueIndex(left) - sectionCatalogueIndex(right);
5574
+ if (byCatalogue !== 0) return byCatalogue;
5575
+ return left < right ? -1 : left > right ? 1 : 0;
5576
+ };
5577
+ }
5578
+ function sectionLabel(labels, category, locale, knownKey, translate) {
5579
+ const id = canonicalSectionId(category);
5580
+ if (id in labels) {
5581
+ const captions = labels[id];
5582
+ const matched = translationFor(captions, locale)?.trim();
5583
+ if (matched) return matched;
5584
+ for (const value of Object.values(captions)) {
5585
+ const any = value.trim();
5586
+ if (any) return any;
5587
+ }
5588
+ }
5589
+ if (knownKey) {
5590
+ const translated = translate(knownKey);
5591
+ if (translated) return translated;
5592
+ }
5593
+ return category;
5594
+ }
5595
+ function parseSectionOrderLoose(raw) {
5596
+ if (typeof raw === "string") return decodeMethodSectionOrder(raw);
5597
+ if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
5598
+ return decodeMethodSectionOrder(JSON.stringify(raw));
5599
+ }
5600
+ return defaultMethodSectionOrder();
5601
+ }
5602
+ function parseSectionLabelsLoose(raw) {
5603
+ if (typeof raw === "string") return decodeMethodSectionLabels(raw);
5604
+ if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
5605
+ return decodeMethodSectionLabels(JSON.stringify(raw));
5606
+ }
5607
+ return {};
5608
+ }
5609
+ function knownSectionLabelKey(category) {
5610
+ const id = canonicalSectionId(category);
5611
+ return METHOD_SECTIONS.find((section) => section.id === id)?.labelKey;
5612
+ }
5468
5613
  var DEFAULT_BRANDING_BASE = {
5469
5614
  displayName: "",
5470
5615
  logoUrl: "",
@@ -5553,7 +5698,9 @@ var DEFAULT_BRANDING = {
5553
5698
  ...DEFAULT_BRANDING_BASE,
5554
5699
  ...LIGHT_PALETTE,
5555
5700
  trustBadges: DEFAULT_BADGES.map((b) => ({ ...b })),
5556
- customFields: []
5701
+ customFields: [],
5702
+ methodSectionOrder: defaultMethodSectionOrder(),
5703
+ methodSectionLabels: {}
5557
5704
  };
5558
5705
  var DEFAULT_BRANDING_DARK = {
5559
5706
  ...DEFAULT_BRANDING_BASE,
@@ -5574,7 +5721,9 @@ var DEFAULT_BRANDING_DARK = {
5574
5721
  surchargeColor: "#fbbf24",
5575
5722
  discountColor: "#34d399",
5576
5723
  trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b })),
5577
- customFields: []
5724
+ customFields: [],
5725
+ methodSectionOrder: defaultMethodSectionOrder(),
5726
+ methodSectionLabels: {}
5578
5727
  };
5579
5728
  function defaultBranding() {
5580
5729
  return cloneBranding(DEFAULT_BRANDING);
@@ -5584,6 +5733,10 @@ function cloneBranding(b) {
5584
5733
  ...b,
5585
5734
  trustBadges: b.trustBadges.map((badge) => ({ ...badge })),
5586
5735
  customFields: b.customFields.map(cloneCustomField),
5736
+ methodSectionOrder: { ...b.methodSectionOrder },
5737
+ methodSectionLabels: Object.fromEntries(
5738
+ Object.entries(b.methodSectionLabels).map(([id, byLocale]) => [id, { ...byLocale }])
5739
+ ),
5587
5740
  // Copied, not shared. A spread alone would leave the clone pointing at the
5588
5741
  // original's maps, and the dashboard edits a clone precisely so the form
5589
5742
  // can be abandoned without touching what is saved.
@@ -6199,6 +6352,8 @@ function decodeBranding(source) {
6199
6352
  showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
6200
6353
  trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
6201
6354
  customFields: decodedCustomFields ?? [],
6355
+ methodSectionOrder: decodeMethodSectionOrder(extras[METHOD_SECTION_ORDER_KEY]),
6356
+ methodSectionLabels: decodeMethodSectionLabels(extras[METHOD_SECTION_LABELS_KEY]),
6202
6357
  headerText: s(source.payment_form_header_text),
6203
6358
  payButtonLabel: s(source.payment_button_text),
6204
6359
  cardTermsMessage: s(source.custom_message_for_card_terms),
@@ -6265,8 +6420,11 @@ function encodeBranding(branding, base) {
6265
6420
  logoShape: branding.logoShape,
6266
6421
  logoSize: branding.logoSize,
6267
6422
  labelStyle: branding.labelStyle,
6268
- trustBadges: encodeBadges(branding.trustBadges)
6423
+ trustBadges: encodeBadges(branding.trustBadges),
6424
+ [METHOD_SECTION_ORDER_KEY]: encodeMethodSectionOrder(branding.methodSectionOrder)
6269
6425
  };
6426
+ const sectionLabels = encodeMethodSectionLabels(branding.methodSectionLabels);
6427
+ if (sectionLabels) extras[METHOD_SECTION_LABELS_KEY] = sectionLabels;
6270
6428
  if (branding.customFields.length > 0) {
6271
6429
  extras["customFields"] = encodeCustomFields(branding.customFields);
6272
6430
  }
@@ -6468,6 +6626,10 @@ function parseImportedBranding(raw) {
6468
6626
  showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
6469
6627
  trustBadges,
6470
6628
  customFields,
6629
+ // An export writes the decoded maps; a hand-written file may carry the
6630
+ // JSON strings the bag uses. Both are accepted, and neither is required.
6631
+ methodSectionOrder: parseSectionOrderLoose(root[METHOD_SECTION_ORDER_KEY]),
6632
+ methodSectionLabels: parseSectionLabelsLoose(root[METHOD_SECTION_LABELS_KEY]),
6471
6633
  headerText: sStr(root["headerText"], dflt.headerText),
6472
6634
  payButtonLabel: sStr(root["payButtonLabel"], dflt.payButtonLabel),
6473
6635
  cardTermsMessage: sStr(root["cardTermsMessage"], dflt.cardTermsMessage),
@@ -7333,6 +7495,23 @@ export {
7333
7495
  isDarkSurface,
7334
7496
  DEFAULT_BADGES,
7335
7497
  DEFAULT_BADGES_DARK,
7498
+ MIN_SECTION_ORDER,
7499
+ MAX_SECTION_ORDER,
7500
+ MAX_SECTION_LABEL_LENGTH,
7501
+ METHOD_SECTIONS,
7502
+ SECTION_ALIASES,
7503
+ UNKNOWN_SECTION_ORDER,
7504
+ canonicalSectionId,
7505
+ defaultMethodSectionOrder,
7506
+ validSectionOrder,
7507
+ decodeMethodSectionOrder,
7508
+ encodeMethodSectionOrder,
7509
+ decodeMethodSectionLabels,
7510
+ encodeMethodSectionLabels,
7511
+ sectionOrderOf,
7512
+ compareSections,
7513
+ sectionLabel,
7514
+ knownSectionLabelKey,
7336
7515
  DEFAULT_BRANDING,
7337
7516
  DEFAULT_BRANDING_DARK,
7338
7517
  defaultBranding,
@@ -7404,4 +7583,4 @@ export {
7404
7583
  decodeNativePanes,
7405
7584
  encodeNativePanes
7406
7585
  };
7407
- //# sourceMappingURL=chunk-VJIRHNXT.js.map
7586
+ //# sourceMappingURL=chunk-D44FJRXS.js.map