@delopay/sdk 0.164.0 → 0.165.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.
@@ -6496,6 +6496,66 @@ function surchargeWordFor(branding, isDiscount, locale) {
6496
6496
  locale
6497
6497
  );
6498
6498
  }
6499
+ var NOTICE_SECTIONS = ["summary", "payment"];
6500
+ var NOTICES_PER_SECTION = 3;
6501
+ var NOTICE_LABEL_MAX_LENGTH = 80;
6502
+ var NOTICE_ICONS = [
6503
+ "lock",
6504
+ "shield",
6505
+ "check",
6506
+ "truck",
6507
+ "package",
6508
+ "refresh",
6509
+ "star",
6510
+ "support",
6511
+ "globe",
6512
+ "tag",
6513
+ "heart",
6514
+ "leaf",
6515
+ "clock",
6516
+ "bank"
6517
+ ];
6518
+ var NOTICE_ICON_FALLBACK = "check";
6519
+ var NOTICE_ICON_PATHS = {
6520
+ lock: [
6521
+ "M6 10h12a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2z",
6522
+ "M8 10V7a4 4 0 0 1 8 0v3"
6523
+ ],
6524
+ shield: ["M12 3l7 3v6c0 4.2-2.9 7.6-7 9-4.1-1.4-7-4.8-7-9V6z", "M9 12l2.5 2.5 4-4.5"],
6525
+ check: ["M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z", "M8 12.5l3 3 5-6"],
6526
+ truck: [
6527
+ "M3 7.5h10v9H3z",
6528
+ "M13 11h4l3 3v2.5h-7z",
6529
+ "M8.8 18a1.8 1.8 0 1 1-3.6 0a1.8 1.8 0 1 1 3.6 0z",
6530
+ "M18.8 18a1.8 1.8 0 1 1-3.6 0a1.8 1.8 0 1 1 3.6 0z"
6531
+ ],
6532
+ package: [
6533
+ "M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",
6534
+ "M12 22V12",
6535
+ "M3.29 7L12 12l8.71-5"
6536
+ ],
6537
+ refresh: ["M20 12a8 8 0 1 1-2.5-5.8", "M20 4v5h-5"],
6538
+ star: ["m12 3.6 2.6 5.3 5.9.9-4.3 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.3-4.1 5.9-.9z"],
6539
+ support: [
6540
+ "M5 13v-1a7 7 0 0 1 14 0v1",
6541
+ "M3.5 14.5a1.8 1.8 0 0 1 1.8-1.8H7v5H5.3a1.8 1.8 0 0 1-1.8-1.8z",
6542
+ "M20.5 14.5a1.8 1.8 0 0 0-1.8-1.8H17v5h1.7a1.8 1.8 0 0 0 1.8-1.8z",
6543
+ "M19 17.7v.8a2.5 2.5 0 0 1-2.5 2.5H13"
6544
+ ],
6545
+ globe: [
6546
+ "M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z",
6547
+ "M3 12h18",
6548
+ "M12 3a14 14 0 0 1 0 18a14 14 0 0 1 0-18z"
6549
+ ],
6550
+ tag: ["M11 3H4v7l10 10 7-7z", "M9.1 7a1.3 1.3 0 1 1-2.6 0a1.3 1.3 0 1 1 2.6 0z"],
6551
+ heart: ["M12 20s-7-4.4-7-9.3A3.9 3.9 0 0 1 12 8a3.9 3.9 0 0 1 7 2.7c0 4.9-7 9.3-7 9.3z"],
6552
+ leaf: ["M20 4c0 9-5.4 13-9.5 13A4.5 4.5 0 0 1 6 12.5C6 7 12 4 20 4z", "M4 20c2-4.5 5-7.5 9-9.5"],
6553
+ clock: ["M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z", "M12 7v5l3 2"],
6554
+ bank: ["M3 9.5 12 4l9 5.5", "M5 10v8M9.5 10v8M14.5 10v8M19 10v8", "M3 20h18"]
6555
+ };
6556
+ function isNoticeIcon(value) {
6557
+ return typeof value === "string" && NOTICE_ICONS.includes(value);
6558
+ }
6499
6559
  var FONT_STACKS = {
6500
6560
  inter: "'Inter Variable', 'Inter', system-ui, -apple-system, sans-serif",
6501
6561
  system: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif",
@@ -6665,6 +6725,96 @@ var DEFAULT_BADGES_DARK = [
6665
6725
  borderColor: "#1e40af"
6666
6726
  }
6667
6727
  ];
6728
+ var DEFAULT_NOTICES = [
6729
+ {
6730
+ id: "secure",
6731
+ section: "summary",
6732
+ icon: "shield",
6733
+ label: "Secure payment",
6734
+ labelTranslations: {
6735
+ de: "Sichere Zahlung",
6736
+ fr: "Paiement s\xE9curis\xE9",
6737
+ es: "Pago seguro",
6738
+ it: "Pagamento sicuro",
6739
+ nl: "Veilig betalen",
6740
+ zh: "\u5B89\u5168\u652F\u4ED8",
6741
+ "zh-Hant": "\u5B89\u5168\u4ED8\u6B3E",
6742
+ hi: "\u0938\u0941\u0930\u0915\u094D\u0937\u093F\u0924 \u092D\u0941\u0917\u0924\u093E\u0928",
6743
+ ar: "\u062F\u0641\u0639 \u0622\u0645\u0646"
6744
+ }
6745
+ },
6746
+ {
6747
+ id: "ssl",
6748
+ section: "summary",
6749
+ icon: "lock",
6750
+ label: "Encrypted \xB7 256-bit SSL",
6751
+ labelTranslations: {
6752
+ de: "Verschl\xFCsselt \xB7 256-Bit-SSL",
6753
+ fr: "Chiffr\xE9 \xB7 SSL 256 bits",
6754
+ es: "Cifrado \xB7 SSL de 256 bits",
6755
+ it: "Crittografato \xB7 SSL a 256 bit",
6756
+ nl: "Versleuteld \xB7 256-bit SSL",
6757
+ zh: "\u52A0\u5BC6 \xB7 256 \u4F4D SSL",
6758
+ "zh-Hant": "\u52A0\u5BC6 \xB7 256 \u4F4D\u5143 SSL",
6759
+ hi: "\u090F\u0928\u094D\u0915\u094D\u0930\u093F\u092A\u094D\u091F\u0947\u0921 \xB7 256-\u092C\u093F\u091F SSL",
6760
+ ar: "\u0645\u0634\u0641\u0651\u0631 \xB7 SSL \u0628\u0637\u0648\u0644 256 \u0628\u062A"
6761
+ }
6762
+ }
6763
+ ];
6764
+ function defaultNotices() {
6765
+ return DEFAULT_NOTICES.map(cloneNotice);
6766
+ }
6767
+ function cloneNotice(notice) {
6768
+ return { ...notice, labelTranslations: { ...notice.labelTranslations } };
6769
+ }
6770
+ function hexChannels(hex) {
6771
+ const raw = /^#([0-9a-f]{6})$/i.exec(hex.trim())?.[1];
6772
+ if (!raw) return null;
6773
+ return [
6774
+ parseInt(raw.slice(0, 2), 16),
6775
+ parseInt(raw.slice(2, 4), 16),
6776
+ parseInt(raw.slice(4, 6), 16)
6777
+ ];
6778
+ }
6779
+ function isThemeTintedBadgeColouring(textColor, fill, border) {
6780
+ const primary = hexChannels(textColor);
6781
+ const bg = hexChannels(fill);
6782
+ const line = hexChannels(border);
6783
+ if (!primary || !bg || !line) return false;
6784
+ const mixed = (surface, to, share) => Math.round(surface + (to - surface) * share);
6785
+ return primary.every((p, i) => {
6786
+ for (let surface = 0; surface <= 255; surface += 1) {
6787
+ if (mixed(surface, p, 0.08) === bg[i] && mixed(surface, p, 0.3) === line[i]) return true;
6788
+ }
6789
+ return false;
6790
+ });
6791
+ }
6792
+ function isDefaultBadgeSet(badges) {
6793
+ if (badges.length !== DEFAULT_BADGES.length) return false;
6794
+ const sameContent = badges.every(
6795
+ (badge, i) => badge.id === DEFAULT_BADGES[i]?.id && badge.label === DEFAULT_BADGES[i]?.label
6796
+ );
6797
+ if (!sameContent) return false;
6798
+ const colouring = (set) => set.map((b) => [b.textColor, b.backgroundColor, b.borderColor ?? ""].join("|").toLowerCase()).join("/");
6799
+ const mine = colouring(badges);
6800
+ if (mine === colouring(DEFAULT_BADGES) || mine === colouring(DEFAULT_BADGES_DARK)) return true;
6801
+ const [first] = badges;
6802
+ const border = first?.borderColor;
6803
+ if (!first || !border) return false;
6804
+ const same = (a, b) => (a ?? "").toLowerCase() === b.toLowerCase();
6805
+ return badges.every(
6806
+ (b) => same(b.textColor, first.textColor) && same(b.backgroundColor, first.backgroundColor) && same(b.borderColor, border)
6807
+ ) && isThemeTintedBadgeColouring(first.textColor, first.backgroundColor, border);
6808
+ }
6809
+ function resolveNoticesAndBadges(savedBadges, savedNotices) {
6810
+ if (savedNotices !== null) {
6811
+ return { trustBadges: savedBadges ?? [], notices: savedNotices };
6812
+ }
6813
+ if (savedBadges === null || isDefaultBadgeSet(savedBadges)) {
6814
+ return { trustBadges: [], notices: defaultNotices() };
6815
+ }
6816
+ return { trustBadges: savedBadges, notices: [] };
6817
+ }
6668
6818
  var METHOD_SECTION_ORDER_KEY = "methodSectionOrder";
6669
6819
  var METHOD_SECTION_LABELS_KEY = "methodSectionLabels";
6670
6820
  var MIN_SECTION_ORDER = 1;
@@ -6951,7 +7101,11 @@ var DEFAULT_BRANDING_BASE = {
6951
7101
  var DEFAULT_BRANDING = {
6952
7102
  ...DEFAULT_BRANDING_BASE,
6953
7103
  ...LIGHT_PALETTE,
6954
- trustBadges: DEFAULT_BADGES.map((b) => ({ ...b })),
7104
+ // No badges by default since todos#218 — notices took their place.
7105
+ // `DEFAULT_BADGES` stays exported because `isDefaultBadgeSet` still has to
7106
+ // recognise the pair on shops saved before.
7107
+ trustBadges: [],
7108
+ notices: defaultNotices(),
6955
7109
  customFields: [],
6956
7110
  methodSectionOrder: defaultMethodSectionOrder(),
6957
7111
  methodSectionLabels: {}
@@ -6974,7 +7128,8 @@ var DEFAULT_BRANDING_DARK = {
6974
7128
  // end of the ramp — 10.69 and 9.29 against the dark surface, also pinned.
6975
7129
  surchargeColor: "#fbbf24",
6976
7130
  discountColor: "#34d399",
6977
- trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b })),
7131
+ trustBadges: [],
7132
+ notices: defaultNotices(),
6978
7133
  customFields: [],
6979
7134
  methodSectionOrder: defaultMethodSectionOrder(),
6980
7135
  methodSectionLabels: {}
@@ -6986,6 +7141,7 @@ function cloneBranding(b) {
6986
7141
  return {
6987
7142
  ...b,
6988
7143
  trustBadges: b.trustBadges.map((badge) => ({ ...badge })),
7144
+ notices: b.notices.map(cloneNotice),
6989
7145
  customFields: b.customFields.map(cloneCustomField),
6990
7146
  methodSectionOrder: { ...b.methodSectionOrder },
6991
7147
  methodSectionLabels: Object.fromEntries(
@@ -7095,6 +7251,80 @@ function encodeBadges(badges) {
7095
7251
  }))
7096
7252
  );
7097
7253
  }
7254
+ var NOTICE_ID_MAX_LENGTH = 40;
7255
+ function capNoticeText(value) {
7256
+ return Array.from(value).slice(0, NOTICE_LABEL_MAX_LENGTH).join("");
7257
+ }
7258
+ function normalizeNotices(list) {
7259
+ const seen = /* @__PURE__ */ new Set();
7260
+ const perSection = /* @__PURE__ */ new Map();
7261
+ const out = [];
7262
+ list.forEach((raw, index) => {
7263
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
7264
+ const src = raw;
7265
+ const label = typeof src["label"] === "string" ? capNoticeText(src["label"]) : "";
7266
+ const labelTranslations = {};
7267
+ for (const [locale, text] of Object.entries(parseTranslations(src["labelTranslations"]))) {
7268
+ labelTranslations[locale] = capNoticeText(text);
7269
+ }
7270
+ if (label.trim().length === 0 && Object.keys(labelTranslations).length === 0) return;
7271
+ const section = pickEnum(src["section"], NOTICE_SECTIONS, "summary");
7272
+ const used = perSection.get(section) ?? 0;
7273
+ if (used >= NOTICES_PER_SECTION) return;
7274
+ perSection.set(section, used + 1);
7275
+ let id = typeof src["id"] === "string" ? src["id"].replace(/[^A-Za-z0-9_-]/g, "").slice(0, NOTICE_ID_MAX_LENGTH) : "";
7276
+ if (!id || seen.has(id)) id = `notice-${index + 1}`;
7277
+ while (seen.has(id)) id = `${id}x`;
7278
+ seen.add(id);
7279
+ out.push({
7280
+ id,
7281
+ section,
7282
+ icon: isNoticeIcon(src["icon"]) ? src["icon"] : NOTICE_ICON_FALLBACK,
7283
+ label,
7284
+ labelTranslations
7285
+ });
7286
+ });
7287
+ return out;
7288
+ }
7289
+ function decodeNotices(raw) {
7290
+ if (raw === void 0) return null;
7291
+ let parsed;
7292
+ try {
7293
+ parsed = JSON.parse(raw);
7294
+ } catch {
7295
+ return null;
7296
+ }
7297
+ return Array.isArray(parsed) ? normalizeNotices(parsed) : null;
7298
+ }
7299
+ function parseNoticesLoose(raw) {
7300
+ if (typeof raw === "string") return decodeNotices(raw);
7301
+ return Array.isArray(raw) ? normalizeNotices(raw) : null;
7302
+ }
7303
+ function encodeNotices(notices) {
7304
+ return JSON.stringify(
7305
+ notices.map((n) => {
7306
+ const translations = Object.entries(n.labelTranslations).filter(
7307
+ ([, text]) => text.trim().length > 0
7308
+ );
7309
+ return {
7310
+ id: n.id,
7311
+ section: n.section,
7312
+ icon: n.icon,
7313
+ label: n.label,
7314
+ ...translations.length > 0 ? { labelTranslations: Object.fromEntries(translations) } : {}
7315
+ };
7316
+ })
7317
+ );
7318
+ }
7319
+ function noticeText(notice, locale) {
7320
+ return translationFor(notice.labelTranslations, locale) ?? notice.label;
7321
+ }
7322
+ function noticesIn(notices, section) {
7323
+ return notices.filter((n) => n.section === section).slice(0, NOTICES_PER_SECTION);
7324
+ }
7325
+ function shownNotices(notices, section, locale) {
7326
+ return noticesIn(notices, section).map((notice) => ({ notice, text: noticeText(notice, locale).trim() })).filter((entry) => entry.text.length > 0);
7327
+ }
7098
7328
  var CUSTOM_FIELDS_MAX = 20;
7099
7329
  var CUSTOM_FIELD_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,39}$/;
7100
7330
  var ALL_CUSTOM_FIELD_TYPES = [
@@ -7438,7 +7668,10 @@ function customFieldOptionLabel(option, locale) {
7438
7668
  function decodeBranding(source) {
7439
7669
  if (!source) return cloneBranding(DEFAULT_BRANDING);
7440
7670
  const extras = source.sdk_ui_rules?.[BRANDING_GROUP_KEY] ?? {};
7441
- const decodedBadges = decodeBadges(extras["trustBadges"]);
7671
+ const trustRow = resolveNoticesAndBadges(
7672
+ decodeBadges(extras["trustBadges"]),
7673
+ decodeNotices(extras["notices"])
7674
+ );
7442
7675
  const decodedCustomFields = decodeCustomFields(extras["customFields"]);
7443
7676
  const displayName = s(source.merchant_name) || s(source.seller_name);
7444
7677
  const logoUrl = s(source.merchant_logo) || s(source.logo);
@@ -7617,7 +7850,8 @@ function decodeBranding(source) {
7617
7850
  totalLabel: s(extras["totalLabel"]) || DEFAULT_BRANDING.totalLabel,
7618
7851
  showCurrencyCode: parseBool(extras["showCurrencyCode"], DEFAULT_BRANDING.showCurrencyCode),
7619
7852
  showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
7620
- trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
7853
+ trustBadges: trustRow.trustBadges,
7854
+ notices: trustRow.notices,
7621
7855
  customFields: decodedCustomFields ?? [],
7622
7856
  methodSectionOrder: decodeMethodSectionOrder(extras[METHOD_SECTION_ORDER_KEY]),
7623
7857
  methodSectionLabels: decodeMethodSectionLabels(extras[METHOD_SECTION_LABELS_KEY]),
@@ -7901,9 +8135,14 @@ function encodeBranding(branding, base) {
7901
8135
  nomupayApplePayButtonType: branding.nomupayApplePayButtonType,
7902
8136
  nomupayGooglePayButtonColor: branding.nomupayGooglePayButtonColor,
7903
8137
  nomupayGooglePayButtonType: branding.nomupayGooglePayButtonType,
7904
- trustBadges: encodeBadges(branding.trustBadges),
8138
+ // Always written, `[]` included — its presence is what stops a later
8139
+ // decode from migrating the shop again (`resolveNoticesAndBadges`).
8140
+ notices: encodeNotices(branding.notices),
7905
8141
  [METHOD_SECTION_ORDER_KEY]: encodeMethodSectionOrder(branding.methodSectionOrder)
7906
8142
  };
8143
+ if (branding.trustBadges.length > 0) {
8144
+ extras["trustBadges"] = encodeBadges(branding.trustBadges);
8145
+ }
7907
8146
  const sectionLabels = encodeMethodSectionLabels(branding.methodSectionLabels);
7908
8147
  if (sectionLabels) extras[METHOD_SECTION_LABELS_KEY] = sectionLabels;
7909
8148
  if (branding.customFields.length > 0) {
@@ -7969,7 +8208,10 @@ function parseImportedBranding(raw) {
7969
8208
  const dflt = DEFAULT_BRANDING;
7970
8209
  const sStr = (v, fallback) => typeof v === "string" ? v : fallback;
7971
8210
  const sHex = (v, fallback) => typeof v === "string" && isHexColor(v) ? v : fallback;
7972
- const trustBadges = parseTrustBadgesLoose(root["trustBadges"]) ?? dflt.trustBadges.map((b) => ({ ...b }));
8211
+ const { trustBadges, notices } = resolveNoticesAndBadges(
8212
+ parseTrustBadgesLoose(root["trustBadges"]),
8213
+ parseNoticesLoose(root["notices"])
8214
+ );
7973
8215
  const customFields = parseCustomFieldsLoose(root["customFields"]) ?? [];
7974
8216
  const labelStyle = (() => {
7975
8217
  const v = root["labelStyle"];
@@ -8112,6 +8354,7 @@ function parseImportedBranding(raw) {
8112
8354
  showCurrencyCode: parseBool(root["showCurrencyCode"], dflt.showCurrencyCode),
8113
8355
  showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
8114
8356
  trustBadges,
8357
+ notices,
8115
8358
  customFields,
8116
8359
  // An export writes the decoded maps; a hand-written file may carry the
8117
8360
  // JSON strings the bag uses. Both are accepted, and neither is required.
@@ -9361,6 +9604,13 @@ export {
9361
9604
  copyTranslationsKey,
9362
9605
  checkoutCopy,
9363
9606
  surchargeWordFor,
9607
+ NOTICE_SECTIONS,
9608
+ NOTICES_PER_SECTION,
9609
+ NOTICE_LABEL_MAX_LENGTH,
9610
+ NOTICE_ICONS,
9611
+ NOTICE_ICON_FALLBACK,
9612
+ NOTICE_ICON_PATHS,
9613
+ isNoticeIcon,
9364
9614
  fontStack,
9365
9615
  radiusValue,
9366
9616
  fontWeightValue,
@@ -9376,6 +9626,11 @@ export {
9376
9626
  isDarkSurface,
9377
9627
  DEFAULT_BADGES,
9378
9628
  DEFAULT_BADGES_DARK,
9629
+ DEFAULT_NOTICES,
9630
+ defaultNotices,
9631
+ cloneNotice,
9632
+ isDefaultBadgeSet,
9633
+ resolveNoticesAndBadges,
9379
9634
  MIN_SECTION_ORDER,
9380
9635
  MAX_SECTION_ORDER,
9381
9636
  MAX_SECTION_LABEL_LENGTH,
@@ -9402,6 +9657,12 @@ export {
9402
9657
  sanitizeCustomCss,
9403
9658
  decodeBadges,
9404
9659
  encodeBadges,
9660
+ decodeNotices,
9661
+ parseNoticesLoose,
9662
+ encodeNotices,
9663
+ noticeText,
9664
+ noticesIn,
9665
+ shownNotices,
9405
9666
  CUSTOM_FIELDS_MAX,
9406
9667
  CUSTOM_FIELD_KEY_PATTERN,
9407
9668
  ALL_CUSTOM_FIELD_TYPES,
@@ -9464,4 +9725,4 @@ export {
9464
9725
  decodeNativePanes,
9465
9726
  encodeNativePanes
9466
9727
  };
9467
- //# sourceMappingURL=chunk-GCJDY4KX.js.map
9728
+ //# sourceMappingURL=chunk-CP5M5WR6.js.map