@delopay/sdk 0.18.2 → 0.19.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
@@ -25,11 +25,18 @@ __export(internal_exports, {
25
25
  Analytics: () => Analytics,
26
26
  AnalyticsDashboard: () => AnalyticsDashboard,
27
27
  AuditLogs: () => AuditLogs,
28
+ BRANDING_EXPORT_FORMAT: () => BRANDING_EXPORT_FORMAT,
29
+ BRANDING_EXPORT_VERSION: () => BRANDING_EXPORT_VERSION,
30
+ CUSTOM_CSS_MAX_LENGTH: () => CUSTOM_CSS_MAX_LENGTH,
28
31
  Cache: () => Cache,
29
32
  CardIssuers: () => CardIssuers,
30
33
  Cards: () => Cards,
31
34
  Configs: () => Configs,
32
35
  ConnectorRestrictions: () => ConnectorRestrictions,
36
+ DEFAULT_BADGES: () => DEFAULT_BADGES,
37
+ DEFAULT_BADGES_DARK: () => DEFAULT_BADGES_DARK,
38
+ DEFAULT_BRANDING: () => DEFAULT_BRANDING,
39
+ DEFAULT_BRANDING_DARK: () => DEFAULT_BRANDING_DARK,
33
40
  Delopay: () => Delopay,
34
41
  DelopayAuthenticationError: () => DelopayAuthenticationError,
35
42
  DelopayError: () => DelopayError,
@@ -43,7 +50,28 @@ __export(internal_exports, {
43
50
  PlatformFees: () => PlatformFees,
44
51
  Regions: () => Regions,
45
52
  Subscriptions: () => Subscriptions,
46
- Webhooks: () => Webhooks
53
+ Webhooks: () => Webhooks,
54
+ applyBrandingVariables: () => applyBrandingVariables,
55
+ buildBrandingExport: () => buildBrandingExport,
56
+ buttonPadValue: () => buttonPadValue,
57
+ cloneBranding: () => cloneBranding,
58
+ decodeBadges: () => decodeBadges,
59
+ decodeBranding: () => decodeBranding,
60
+ defaultBranding: () => defaultBranding,
61
+ encodeBadges: () => encodeBadges,
62
+ encodeBranding: () => encodeBranding,
63
+ fontStack: () => fontStack,
64
+ fontWeightValue: () => fontWeightValue,
65
+ inputPadValue: () => inputPadValue,
66
+ isDarkSurface: () => isDarkSurface,
67
+ isHexColor: () => isHexColor,
68
+ logoDimensions: () => logoDimensions,
69
+ parseImportedBranding: () => parseImportedBranding,
70
+ radiusValue: () => radiusValue,
71
+ sanitizeCustomCss: () => sanitizeCustomCss,
72
+ shadowFor: () => shadowFor,
73
+ surfacePadValue: () => surfacePadValue,
74
+ verticalGapValue: () => verticalGapValue
47
75
  });
48
76
  module.exports = __toCommonJS(internal_exports);
49
77
 
@@ -2934,6 +2962,641 @@ var Delopay = class {
2934
2962
  /** Utility for verifying incoming webhook signatures (static, no instance needed). */
2935
2963
  Delopay.webhooks = Webhooks;
2936
2964
 
2965
+ // src/branding.ts
2966
+ var FONT_STACKS = {
2967
+ inter: "'Inter Variable', 'Inter', system-ui, -apple-system, sans-serif",
2968
+ system: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif",
2969
+ serif: "Georgia, 'Times New Roman', serif",
2970
+ mono: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
2971
+ roboto: "'Roboto', system-ui, sans-serif",
2972
+ poppins: "'Poppins', system-ui, sans-serif",
2973
+ manrope: "'Manrope Variable', 'Manrope', system-ui, sans-serif",
2974
+ "dm-sans": "'DM Sans Variable', 'DM Sans', system-ui, sans-serif",
2975
+ "space-grotesk": "'Space Grotesk Variable', 'Space Grotesk', system-ui, sans-serif",
2976
+ "plex-sans": "'IBM Plex Sans', system-ui, sans-serif",
2977
+ "work-sans": "'Work Sans Variable', 'Work Sans', system-ui, sans-serif",
2978
+ "open-sans": "'Open Sans Variable', 'Open Sans', system-ui, sans-serif",
2979
+ lora: "'Lora Variable', 'Lora', Georgia, serif",
2980
+ playfair: "'Playfair Display Variable', 'Playfair Display', Georgia, serif",
2981
+ "plex-mono": "'IBM Plex Mono', ui-monospace, monospace",
2982
+ "jetbrains-mono": "'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace"
2983
+ };
2984
+ var RADIUS_PX = {
2985
+ square: "0px",
2986
+ small: "6px",
2987
+ medium: "12px",
2988
+ large: "20px",
2989
+ pill: "999px"
2990
+ };
2991
+ var FONT_WEIGHT_NUMERIC = {
2992
+ regular: "400",
2993
+ medium: "500",
2994
+ semibold: "600",
2995
+ bold: "700"
2996
+ };
2997
+ var SURFACE_PAD = {
2998
+ compact: "1rem",
2999
+ comfortable: "1.5rem",
3000
+ spacious: "2rem"
3001
+ };
3002
+ var VERTICAL_GAP = {
3003
+ compact: "0.75rem",
3004
+ comfortable: "1rem",
3005
+ spacious: "1.5rem"
3006
+ };
3007
+ var INPUT_PAD = {
3008
+ sm: "0.5rem 0.75rem",
3009
+ md: "0.625rem 0.75rem",
3010
+ lg: "0.875rem 0.875rem"
3011
+ };
3012
+ var BUTTON_PAD = {
3013
+ sm: "0.625rem 1rem",
3014
+ md: "0.875rem 1.25rem",
3015
+ lg: "1.125rem 1.5rem"
3016
+ };
3017
+ function fontStack(family) {
3018
+ return FONT_STACKS[family] ?? FONT_STACKS.inter;
3019
+ }
3020
+ function radiusValue(radius) {
3021
+ return RADIUS_PX[radius] ?? RADIUS_PX.medium;
3022
+ }
3023
+ function fontWeightValue(weight) {
3024
+ return FONT_WEIGHT_NUMERIC[weight] ?? "600";
3025
+ }
3026
+ function surfacePadValue(scale) {
3027
+ return SURFACE_PAD[scale] ?? SURFACE_PAD.comfortable;
3028
+ }
3029
+ function verticalGapValue(scale) {
3030
+ return VERTICAL_GAP[scale] ?? VERTICAL_GAP.comfortable;
3031
+ }
3032
+ function inputPadValue(size) {
3033
+ return INPUT_PAD[size] ?? INPUT_PAD.md;
3034
+ }
3035
+ function buttonPadValue(size) {
3036
+ return BUTTON_PAD[size] ?? BUTTON_PAD.md;
3037
+ }
3038
+ function logoDimensions(size) {
3039
+ switch (size) {
3040
+ case "sm":
3041
+ return { px: 36, radius: 8 };
3042
+ case "lg":
3043
+ return { px: 64, radius: 16 };
3044
+ case "md":
3045
+ default:
3046
+ return { px: 48, radius: 12 };
3047
+ }
3048
+ }
3049
+ var HEX_RE = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
3050
+ function isHexColor(value) {
3051
+ return HEX_RE.test(value.trim());
3052
+ }
3053
+ function isDarkSurface(color) {
3054
+ const m = color.replace("#", "").trim();
3055
+ if (m.length !== 3 && m.length !== 6) return false;
3056
+ const full = m.length === 3 ? m.split("").map((c) => c + c).join("") : m;
3057
+ const r = parseInt(full.slice(0, 2), 16);
3058
+ const g = parseInt(full.slice(2, 4), 16);
3059
+ const b = parseInt(full.slice(4, 6), 16);
3060
+ if ([r, g, b].some(Number.isNaN)) return false;
3061
+ const luma = (r * 299 + g * 587 + b * 114) / 1e3;
3062
+ return luma < 128;
3063
+ }
3064
+ var LIGHT_PALETTE = {
3065
+ primary: "#1E4FEB",
3066
+ background: "#f8fafc",
3067
+ surface: "#ffffff",
3068
+ text: "#1e293b",
3069
+ heading: "#0A1130",
3070
+ muted: "#64748b",
3071
+ border: "#e2e8f0",
3072
+ accentText: "#1E4FEB",
3073
+ buttonBackground: "#0A1130",
3074
+ buttonText: "#ffffff"
3075
+ };
3076
+ var DEFAULT_BADGES = [
3077
+ {
3078
+ id: "secure",
3079
+ label: "Secure",
3080
+ textColor: "#047857",
3081
+ backgroundColor: "#ecfdf5",
3082
+ borderColor: "#a7f3d0"
3083
+ },
3084
+ {
3085
+ id: "ssl",
3086
+ label: "256-bit SSL",
3087
+ textColor: "#1E4FEB",
3088
+ backgroundColor: "#eff6ff",
3089
+ borderColor: "#bfdbfe"
3090
+ }
3091
+ ];
3092
+ var DEFAULT_BADGES_DARK = [
3093
+ {
3094
+ id: "secure",
3095
+ label: "Secure",
3096
+ textColor: "#34d399",
3097
+ backgroundColor: "#064e3b",
3098
+ borderColor: "#065f46"
3099
+ },
3100
+ {
3101
+ id: "ssl",
3102
+ label: "256-bit SSL",
3103
+ textColor: "#60a5fa",
3104
+ backgroundColor: "#172554",
3105
+ borderColor: "#1e40af"
3106
+ }
3107
+ ];
3108
+ var DEFAULT_BRANDING_BASE = {
3109
+ displayName: "",
3110
+ logoUrl: "",
3111
+ tagline: "",
3112
+ // Logo + summary gradient OFF by default — an unconfigured DeloPay
3113
+ // checkout reads cleaner without a placeholder logo block, and the
3114
+ // gradient implies a primary tint the merchant hasn't yet picked.
3115
+ showLogo: false,
3116
+ logoShape: "rounded",
3117
+ logoSize: "md",
3118
+ fontFamily: "inter",
3119
+ headingWeight: "semibold",
3120
+ radiusSurface: "medium",
3121
+ radiusInput: "medium",
3122
+ radiusButton: "medium",
3123
+ radiusBadge: "pill",
3124
+ surfaceStyle: "elevated",
3125
+ surfacePadding: "comfortable",
3126
+ verticalGap: "comfortable",
3127
+ inputSize: "md",
3128
+ buttonSize: "md",
3129
+ layout: "split",
3130
+ summaryPosition: "left",
3131
+ showOrderSummary: true,
3132
+ summaryGradient: false,
3133
+ showTotal: true,
3134
+ totalLabel: "Total",
3135
+ showCurrencyCode: false,
3136
+ showOrderItems: true,
3137
+ headerText: "",
3138
+ payButtonLabel: "",
3139
+ cardTermsMessage: "",
3140
+ footerText: "",
3141
+ supportEmail: "",
3142
+ paymentLayout: "tabs",
3143
+ labelStyle: "above",
3144
+ showPoweredBy: true,
3145
+ customCss: ""
3146
+ };
3147
+ var DEFAULT_BRANDING = {
3148
+ ...DEFAULT_BRANDING_BASE,
3149
+ ...LIGHT_PALETTE,
3150
+ trustBadges: DEFAULT_BADGES.map((b) => ({ ...b }))
3151
+ };
3152
+ var DEFAULT_BRANDING_DARK = {
3153
+ ...DEFAULT_BRANDING_BASE,
3154
+ primary: "#1E4FEB",
3155
+ background: "#020617",
3156
+ surface: "#0f172a",
3157
+ text: "#e2e8f0",
3158
+ heading: "#f8fafc",
3159
+ muted: "#94a3b8",
3160
+ border: "#1e293b",
3161
+ accentText: "#60a5fa",
3162
+ buttonBackground: "#1E4FEB",
3163
+ buttonText: "#ffffff",
3164
+ surfaceStyle: "flat",
3165
+ trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b }))
3166
+ };
3167
+ function defaultBranding() {
3168
+ return cloneBranding(DEFAULT_BRANDING);
3169
+ }
3170
+ function cloneBranding(b) {
3171
+ return { ...b, trustBadges: b.trustBadges.map((badge) => ({ ...badge })) };
3172
+ }
3173
+ var CUSTOM_CSS_MAX_LENGTH = 5e4;
3174
+ function sanitizeCustomCss(raw) {
3175
+ if (typeof raw !== "string") return null;
3176
+ const trimmed = raw.trim();
3177
+ if (trimmed.length === 0) return null;
3178
+ if (trimmed.length > CUSTOM_CSS_MAX_LENGTH) return null;
3179
+ let out = trimmed;
3180
+ out = out.replace(/<\/style/gi, "<\\/style");
3181
+ out = out.replace(/@import\b[^;]*;?/gi, "");
3182
+ out = out.replace(/expression\s*\(/gi, "/* expression( */");
3183
+ out = out.replace(/(^|[^a-z-])behavior\s*:/gi, "$1/* behavior: */");
3184
+ out = out.replace(/-moz-binding\s*:/gi, "/* -moz-binding: */");
3185
+ out = out.replace(/url\s*\(\s*["']?\s*javascript:/gi, "url(invalid:");
3186
+ return out;
3187
+ }
3188
+ var BRANDING_GROUP_KEY = "branding";
3189
+ var ALL_FONT_FAMILIES = [
3190
+ "inter",
3191
+ "system",
3192
+ "serif",
3193
+ "mono",
3194
+ "roboto",
3195
+ "poppins",
3196
+ "manrope",
3197
+ "dm-sans",
3198
+ "space-grotesk",
3199
+ "plex-sans",
3200
+ "work-sans",
3201
+ "open-sans",
3202
+ "lora",
3203
+ "playfair",
3204
+ "plex-mono",
3205
+ "jetbrains-mono"
3206
+ ];
3207
+ var ALL_RADII = ["square", "small", "medium", "large", "pill"];
3208
+ var NON_PILL_RADII = ["square", "small", "medium", "large"];
3209
+ function pickEnum(value, allowed, fallback) {
3210
+ if (typeof value !== "string") return fallback;
3211
+ return allowed.includes(value) ? value : fallback;
3212
+ }
3213
+ function parseBool(value, fallback) {
3214
+ if (typeof value === "boolean") return value;
3215
+ if (value === "true") return true;
3216
+ if (value === "false") return false;
3217
+ return fallback;
3218
+ }
3219
+ function s(value) {
3220
+ return typeof value === "string" ? value : "";
3221
+ }
3222
+ function decodeBadges(raw) {
3223
+ if (raw === void 0) return null;
3224
+ try {
3225
+ const parsed = JSON.parse(raw);
3226
+ if (!Array.isArray(parsed)) return null;
3227
+ return parsed.filter((b) => !!b && typeof b === "object").map((b, i) => ({
3228
+ id: typeof b["id"] === "string" && b["id"] ? b["id"] : `badge-${i}`,
3229
+ label: typeof b["label"] === "string" ? b["label"] : "",
3230
+ textColor: typeof b["textColor"] === "string" ? b["textColor"] : "#0f172a",
3231
+ backgroundColor: typeof b["backgroundColor"] === "string" ? b["backgroundColor"] : "#f1f5f9",
3232
+ borderColor: typeof b["borderColor"] === "string" && b["borderColor"] ? b["borderColor"] : null
3233
+ })).filter((b) => b.label.length > 0);
3234
+ } catch {
3235
+ return null;
3236
+ }
3237
+ }
3238
+ function encodeBadges(badges) {
3239
+ return JSON.stringify(
3240
+ badges.map((b) => ({
3241
+ id: b.id,
3242
+ label: b.label,
3243
+ textColor: b.textColor,
3244
+ backgroundColor: b.backgroundColor,
3245
+ ...b.borderColor ? { borderColor: b.borderColor } : {}
3246
+ }))
3247
+ );
3248
+ }
3249
+ function decodeBranding(source) {
3250
+ if (!source) return cloneBranding(DEFAULT_BRANDING);
3251
+ const extras = source.sdk_ui_rules?.[BRANDING_GROUP_KEY] ?? {};
3252
+ const decodedBadges = decodeBadges(extras["trustBadges"]);
3253
+ const displayName = s(source.merchant_name) || s(source.seller_name);
3254
+ const logoUrl = s(source.merchant_logo) || s(source.logo);
3255
+ const tagline = s(extras["tagline"]) || s(source.merchant_description);
3256
+ const labelStyle = (() => {
3257
+ const fromBag = extras["labelStyle"];
3258
+ if (fromBag === "above" || fromBag === "hidden") return fromBag;
3259
+ if (fromBag === "floating") return "above";
3260
+ const legacy = source.payment_form_label_type;
3261
+ if (legacy === "above" || legacy === "floating") return "above";
3262
+ if (legacy === "hidden" || legacy === "never") return "hidden";
3263
+ return DEFAULT_BRANDING.labelStyle;
3264
+ })();
3265
+ return {
3266
+ displayName,
3267
+ logoUrl,
3268
+ tagline,
3269
+ showLogo: parseBool(extras["showLogo"], DEFAULT_BRANDING.showLogo),
3270
+ logoShape: pickEnum(
3271
+ extras["logoShape"],
3272
+ ["square", "rounded", "circle"],
3273
+ DEFAULT_BRANDING.logoShape
3274
+ ),
3275
+ logoSize: pickEnum(extras["logoSize"], ["sm", "md", "lg"], DEFAULT_BRANDING.logoSize),
3276
+ primary: s(source.theme) || DEFAULT_BRANDING.primary,
3277
+ background: s(source.background_colour) || DEFAULT_BRANDING.background,
3278
+ surface: s(extras["surface"]) || DEFAULT_BRANDING.surface,
3279
+ text: s(extras["text"]) || DEFAULT_BRANDING.text,
3280
+ heading: s(extras["heading"]) || s(extras["text"]) || DEFAULT_BRANDING.heading,
3281
+ muted: s(extras["muted"]) || DEFAULT_BRANDING.muted,
3282
+ border: s(extras["border"]) || DEFAULT_BRANDING.border,
3283
+ accentText: s(extras["accentText"]) || s(source.theme) || DEFAULT_BRANDING.accentText,
3284
+ buttonBackground: s(source.payment_button_colour) || s(source.theme) || DEFAULT_BRANDING.buttonBackground,
3285
+ buttonText: s(source.payment_button_text_colour) || DEFAULT_BRANDING.buttonText,
3286
+ fontFamily: pickEnum(
3287
+ extras["fontFamily"],
3288
+ ALL_FONT_FAMILIES,
3289
+ DEFAULT_BRANDING.fontFamily
3290
+ ),
3291
+ headingWeight: pickEnum(
3292
+ extras["headingWeight"],
3293
+ ["regular", "medium", "semibold", "bold"],
3294
+ DEFAULT_BRANDING.headingWeight
3295
+ ),
3296
+ radiusSurface: pickEnum(
3297
+ extras["radiusSurface"],
3298
+ NON_PILL_RADII,
3299
+ DEFAULT_BRANDING.radiusSurface
3300
+ ),
3301
+ radiusInput: pickEnum(
3302
+ extras["radiusInput"],
3303
+ NON_PILL_RADII,
3304
+ DEFAULT_BRANDING.radiusInput
3305
+ ),
3306
+ radiusButton: pickEnum(
3307
+ extras["radiusButton"],
3308
+ ALL_RADII,
3309
+ DEFAULT_BRANDING.radiusButton
3310
+ ),
3311
+ radiusBadge: pickEnum(
3312
+ extras["radiusBadge"],
3313
+ ALL_RADII,
3314
+ DEFAULT_BRANDING.radiusBadge
3315
+ ),
3316
+ surfaceStyle: pickEnum(
3317
+ extras["surfaceStyle"],
3318
+ ["flat", "outlined", "elevated"],
3319
+ DEFAULT_BRANDING.surfaceStyle
3320
+ ),
3321
+ surfacePadding: pickEnum(
3322
+ extras["surfacePadding"],
3323
+ ["compact", "comfortable", "spacious"],
3324
+ DEFAULT_BRANDING.surfacePadding
3325
+ ),
3326
+ verticalGap: pickEnum(
3327
+ extras["verticalGap"],
3328
+ ["compact", "comfortable", "spacious"],
3329
+ DEFAULT_BRANDING.verticalGap
3330
+ ),
3331
+ inputSize: pickEnum(
3332
+ extras["inputSize"],
3333
+ ["sm", "md", "lg"],
3334
+ DEFAULT_BRANDING.inputSize
3335
+ ),
3336
+ buttonSize: pickEnum(
3337
+ extras["buttonSize"],
3338
+ ["sm", "md", "lg"],
3339
+ DEFAULT_BRANDING.buttonSize
3340
+ ),
3341
+ layout: pickEnum(
3342
+ extras["layout"],
3343
+ ["compact", "split"],
3344
+ DEFAULT_BRANDING.layout
3345
+ ),
3346
+ summaryPosition: pickEnum(
3347
+ extras["summaryPosition"],
3348
+ ["left", "right"],
3349
+ DEFAULT_BRANDING.summaryPosition
3350
+ ),
3351
+ showOrderSummary: parseBool(extras["showOrderSummary"], DEFAULT_BRANDING.showOrderSummary),
3352
+ summaryGradient: parseBool(extras["summaryGradient"], DEFAULT_BRANDING.summaryGradient),
3353
+ showTotal: parseBool(extras["showTotal"], DEFAULT_BRANDING.showTotal),
3354
+ totalLabel: s(extras["totalLabel"]) || DEFAULT_BRANDING.totalLabel,
3355
+ showCurrencyCode: parseBool(extras["showCurrencyCode"], DEFAULT_BRANDING.showCurrencyCode),
3356
+ showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
3357
+ trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
3358
+ headerText: s(source.payment_form_header_text),
3359
+ payButtonLabel: s(source.payment_button_text),
3360
+ cardTermsMessage: s(source.custom_message_for_card_terms),
3361
+ footerText: s(extras["footerText"]),
3362
+ supportEmail: s(extras["supportEmail"]),
3363
+ paymentLayout: pickEnum(
3364
+ source.sdk_layout,
3365
+ ["tabs", "accordion", "spaced_accordion"],
3366
+ DEFAULT_BRANDING.paymentLayout
3367
+ ),
3368
+ labelStyle,
3369
+ showPoweredBy: source.branding_visibility !== false,
3370
+ customCss: s(extras["customCss"])
3371
+ };
3372
+ }
3373
+ function encodeBranding(branding, base) {
3374
+ const trim = (v) => {
3375
+ const t = v.trim();
3376
+ return t.length > 0 ? t : null;
3377
+ };
3378
+ const existingRules = base?.["sdk_ui_rules"] ?? {};
3379
+ const extras = {
3380
+ surface: branding.surface,
3381
+ text: branding.text,
3382
+ heading: branding.heading,
3383
+ muted: branding.muted,
3384
+ border: branding.border,
3385
+ accentText: branding.accentText,
3386
+ fontFamily: branding.fontFamily,
3387
+ headingWeight: branding.headingWeight,
3388
+ radiusSurface: branding.radiusSurface,
3389
+ radiusInput: branding.radiusInput,
3390
+ radiusButton: branding.radiusButton,
3391
+ radiusBadge: branding.radiusBadge,
3392
+ surfaceStyle: branding.surfaceStyle,
3393
+ surfacePadding: branding.surfacePadding,
3394
+ verticalGap: branding.verticalGap,
3395
+ inputSize: branding.inputSize,
3396
+ buttonSize: branding.buttonSize,
3397
+ layout: branding.layout,
3398
+ summaryPosition: branding.summaryPosition,
3399
+ showOrderSummary: String(branding.showOrderSummary),
3400
+ summaryGradient: String(branding.summaryGradient),
3401
+ showTotal: String(branding.showTotal),
3402
+ totalLabel: branding.totalLabel,
3403
+ showCurrencyCode: String(branding.showCurrencyCode),
3404
+ showOrderItems: String(branding.showOrderItems),
3405
+ showLogo: String(branding.showLogo),
3406
+ logoShape: branding.logoShape,
3407
+ logoSize: branding.logoSize,
3408
+ labelStyle: branding.labelStyle,
3409
+ trustBadges: encodeBadges(branding.trustBadges)
3410
+ };
3411
+ const tagline = trim(branding.tagline);
3412
+ if (tagline) extras["tagline"] = tagline;
3413
+ const footer = trim(branding.footerText);
3414
+ if (footer) extras["footerText"] = footer;
3415
+ const support = trim(branding.supportEmail);
3416
+ if (support) extras["supportEmail"] = support;
3417
+ const css = trim(branding.customCss);
3418
+ if (css) extras["customCss"] = css;
3419
+ const nextRules = {
3420
+ ...existingRules,
3421
+ [BRANDING_GROUP_KEY]: extras
3422
+ };
3423
+ const legacyLabel = branding.labelStyle === "hidden" ? "never" : "above";
3424
+ const flatFields = {
3425
+ theme: branding.primary,
3426
+ logo: trim(branding.logoUrl),
3427
+ seller_name: trim(branding.displayName),
3428
+ sdk_layout: branding.paymentLayout,
3429
+ payment_button_text: trim(branding.payButtonLabel),
3430
+ payment_button_colour: branding.buttonBackground,
3431
+ payment_button_text_colour: branding.buttonText,
3432
+ background_colour: branding.background,
3433
+ payment_form_header_text: trim(branding.headerText),
3434
+ payment_form_label_type: legacyLabel,
3435
+ custom_message_for_card_terms: trim(branding.cardTermsMessage),
3436
+ sdk_ui_rules: nextRules,
3437
+ branding_visibility: branding.showPoweredBy
3438
+ };
3439
+ return {
3440
+ ...base,
3441
+ ...flatFields
3442
+ };
3443
+ }
3444
+ var BRANDING_EXPORT_FORMAT = "delopay-checkout-branding";
3445
+ var BRANDING_EXPORT_VERSION = 1;
3446
+ function buildBrandingExport(branding) {
3447
+ return {
3448
+ format: BRANDING_EXPORT_FORMAT,
3449
+ version: BRANDING_EXPORT_VERSION,
3450
+ exported_at: (/* @__PURE__ */ new Date()).toISOString(),
3451
+ branding: cloneBranding(branding)
3452
+ };
3453
+ }
3454
+ function parseImportedBranding(raw) {
3455
+ const root = isObject(raw) && isObject(raw["branding"]) ? raw["branding"] : isObject(raw) ? raw : null;
3456
+ if (!root) return cloneBranding(DEFAULT_BRANDING);
3457
+ const dflt = DEFAULT_BRANDING;
3458
+ const sStr = (v, fallback) => typeof v === "string" ? v : fallback;
3459
+ const sHex = (v, fallback) => typeof v === "string" && isHexColor(v) ? v : fallback;
3460
+ const trustBadges = parseTrustBadgesLoose(root["trustBadges"]) ?? dflt.trustBadges.map((b) => ({ ...b }));
3461
+ const labelStyle = (() => {
3462
+ const v = root["labelStyle"];
3463
+ if (v === "above" || v === "hidden") return v;
3464
+ return dflt.labelStyle;
3465
+ })();
3466
+ return {
3467
+ displayName: sStr(root["displayName"], dflt.displayName),
3468
+ logoUrl: sStr(root["logoUrl"], dflt.logoUrl),
3469
+ tagline: sStr(root["tagline"], dflt.tagline),
3470
+ showLogo: parseBool(root["showLogo"], dflt.showLogo),
3471
+ logoShape: pickEnum(
3472
+ root["logoShape"],
3473
+ ["square", "rounded", "circle"],
3474
+ dflt.logoShape
3475
+ ),
3476
+ logoSize: pickEnum(root["logoSize"], ["sm", "md", "lg"], dflt.logoSize),
3477
+ primary: sHex(root["primary"], dflt.primary),
3478
+ background: sHex(root["background"], dflt.background),
3479
+ surface: sHex(root["surface"], dflt.surface),
3480
+ text: sHex(root["text"], dflt.text),
3481
+ heading: sHex(root["heading"], dflt.heading),
3482
+ muted: sHex(root["muted"], dflt.muted),
3483
+ border: sHex(root["border"], dflt.border),
3484
+ accentText: sHex(root["accentText"], dflt.accentText),
3485
+ buttonBackground: sHex(root["buttonBackground"], dflt.buttonBackground),
3486
+ buttonText: sHex(root["buttonText"], dflt.buttonText),
3487
+ fontFamily: pickEnum(root["fontFamily"], ALL_FONT_FAMILIES, dflt.fontFamily),
3488
+ headingWeight: pickEnum(
3489
+ root["headingWeight"],
3490
+ ["regular", "medium", "semibold", "bold"],
3491
+ dflt.headingWeight
3492
+ ),
3493
+ radiusSurface: pickEnum(
3494
+ root["radiusSurface"],
3495
+ NON_PILL_RADII,
3496
+ dflt.radiusSurface
3497
+ ),
3498
+ radiusInput: pickEnum(root["radiusInput"], NON_PILL_RADII, dflt.radiusInput),
3499
+ radiusButton: pickEnum(root["radiusButton"], ALL_RADII, dflt.radiusButton),
3500
+ radiusBadge: pickEnum(root["radiusBadge"], ALL_RADII, dflt.radiusBadge),
3501
+ surfaceStyle: pickEnum(
3502
+ root["surfaceStyle"],
3503
+ ["flat", "outlined", "elevated"],
3504
+ dflt.surfaceStyle
3505
+ ),
3506
+ surfacePadding: pickEnum(
3507
+ root["surfacePadding"],
3508
+ ["compact", "comfortable", "spacious"],
3509
+ dflt.surfacePadding
3510
+ ),
3511
+ verticalGap: pickEnum(
3512
+ root["verticalGap"],
3513
+ ["compact", "comfortable", "spacious"],
3514
+ dflt.verticalGap
3515
+ ),
3516
+ inputSize: pickEnum(root["inputSize"], ["sm", "md", "lg"], dflt.inputSize),
3517
+ buttonSize: pickEnum(root["buttonSize"], ["sm", "md", "lg"], dflt.buttonSize),
3518
+ layout: pickEnum(root["layout"], ["compact", "split"], dflt.layout),
3519
+ summaryPosition: pickEnum(
3520
+ root["summaryPosition"],
3521
+ ["left", "right"],
3522
+ dflt.summaryPosition
3523
+ ),
3524
+ showOrderSummary: parseBool(root["showOrderSummary"], dflt.showOrderSummary),
3525
+ summaryGradient: parseBool(root["summaryGradient"], dflt.summaryGradient),
3526
+ showTotal: parseBool(root["showTotal"], dflt.showTotal),
3527
+ totalLabel: sStr(root["totalLabel"], dflt.totalLabel),
3528
+ showCurrencyCode: parseBool(root["showCurrencyCode"], dflt.showCurrencyCode),
3529
+ showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
3530
+ trustBadges,
3531
+ headerText: sStr(root["headerText"], dflt.headerText),
3532
+ payButtonLabel: sStr(root["payButtonLabel"], dflt.payButtonLabel),
3533
+ cardTermsMessage: sStr(root["cardTermsMessage"], dflt.cardTermsMessage),
3534
+ footerText: sStr(root["footerText"], dflt.footerText),
3535
+ supportEmail: sStr(root["supportEmail"], dflt.supportEmail),
3536
+ paymentLayout: pickEnum(
3537
+ root["paymentLayout"],
3538
+ ["tabs", "accordion", "spaced_accordion"],
3539
+ dflt.paymentLayout
3540
+ ),
3541
+ labelStyle,
3542
+ showPoweredBy: parseBool(root["showPoweredBy"], dflt.showPoweredBy),
3543
+ customCss: sStr(root["customCss"], dflt.customCss).slice(0, CUSTOM_CSS_MAX_LENGTH)
3544
+ };
3545
+ }
3546
+ function isObject(v) {
3547
+ return typeof v === "object" && v !== null && !Array.isArray(v);
3548
+ }
3549
+ function parseTrustBadgesLoose(raw) {
3550
+ if (!Array.isArray(raw)) return null;
3551
+ return raw.filter(isObject).map((b, i) => ({
3552
+ id: typeof b["id"] === "string" && b["id"] ? b["id"] : `badge-${i}`,
3553
+ label: typeof b["label"] === "string" ? b["label"] : "",
3554
+ textColor: typeof b["textColor"] === "string" && isHexColor(b["textColor"]) ? b["textColor"] : "#0f172a",
3555
+ backgroundColor: typeof b["backgroundColor"] === "string" && isHexColor(b["backgroundColor"]) ? b["backgroundColor"] : "#f1f5f9",
3556
+ borderColor: typeof b["borderColor"] === "string" && isHexColor(b["borderColor"]) ? b["borderColor"] : null
3557
+ })).filter((b) => b.label.length > 0);
3558
+ }
3559
+ function applyBrandingVariables(el, b) {
3560
+ const set = (k, v) => {
3561
+ el.style.setProperty(k, v);
3562
+ };
3563
+ set("--dp-primary", b.primary);
3564
+ set("--dp-bg", b.background);
3565
+ set("--dp-surface", b.surface);
3566
+ set("--dp-text", b.text);
3567
+ set("--dp-heading", b.heading);
3568
+ set("--dp-muted", b.muted);
3569
+ set("--dp-border", b.border);
3570
+ set("--dp-accent-text", b.accentText);
3571
+ set("--dp-btn-bg", b.buttonBackground);
3572
+ set("--dp-btn-fg", b.buttonText);
3573
+ set("--dp-radius-surface", radiusValue(b.radiusSurface));
3574
+ set("--dp-radius-input", radiusValue(b.radiusInput));
3575
+ set("--dp-radius-button", radiusValue(b.radiusButton));
3576
+ set("--dp-radius-badge", radiusValue(b.radiusBadge));
3577
+ set("--dp-font", fontStack(b.fontFamily));
3578
+ set("--dp-heading-weight", fontWeightValue(b.headingWeight));
3579
+ set("--dp-pad-surface", SURFACE_PAD[b.surfacePadding]);
3580
+ set("--dp-gap-vertical", VERTICAL_GAP[b.verticalGap]);
3581
+ set("--dp-input-pad", INPUT_PAD[b.inputSize]);
3582
+ set("--dp-button-pad", BUTTON_PAD[b.buttonSize]);
3583
+ set("--dp-shadow", shadowFor(b.surfaceStyle));
3584
+ set(
3585
+ "--dp-surface-border",
3586
+ b.surfaceStyle === "outlined" ? `1px solid ${b.border}` : "1px solid transparent"
3587
+ );
3588
+ }
3589
+ function shadowFor(style) {
3590
+ switch (style) {
3591
+ case "elevated":
3592
+ return "0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 32px -12px rgba(15, 23, 42, 0.08)";
3593
+ case "outlined":
3594
+ case "flat":
3595
+ default:
3596
+ return "none";
3597
+ }
3598
+ }
3599
+
2937
3600
  // src/internal/resources/admin.ts
2938
3601
  var Admin = class {
2939
3602
  constructor(request) {
@@ -3276,11 +3939,18 @@ var DelopayInternal = class extends Delopay {
3276
3939
  Analytics,
3277
3940
  AnalyticsDashboard,
3278
3941
  AuditLogs,
3942
+ BRANDING_EXPORT_FORMAT,
3943
+ BRANDING_EXPORT_VERSION,
3944
+ CUSTOM_CSS_MAX_LENGTH,
3279
3945
  Cache,
3280
3946
  CardIssuers,
3281
3947
  Cards,
3282
3948
  Configs,
3283
3949
  ConnectorRestrictions,
3950
+ DEFAULT_BADGES,
3951
+ DEFAULT_BADGES_DARK,
3952
+ DEFAULT_BRANDING,
3953
+ DEFAULT_BRANDING_DARK,
3284
3954
  Delopay,
3285
3955
  DelopayAuthenticationError,
3286
3956
  DelopayError,
@@ -3294,6 +3964,27 @@ var DelopayInternal = class extends Delopay {
3294
3964
  PlatformFees,
3295
3965
  Regions,
3296
3966
  Subscriptions,
3297
- Webhooks
3967
+ Webhooks,
3968
+ applyBrandingVariables,
3969
+ buildBrandingExport,
3970
+ buttonPadValue,
3971
+ cloneBranding,
3972
+ decodeBadges,
3973
+ decodeBranding,
3974
+ defaultBranding,
3975
+ encodeBadges,
3976
+ encodeBranding,
3977
+ fontStack,
3978
+ fontWeightValue,
3979
+ inputPadValue,
3980
+ isDarkSurface,
3981
+ isHexColor,
3982
+ logoDimensions,
3983
+ parseImportedBranding,
3984
+ radiusValue,
3985
+ sanitizeCustomCss,
3986
+ shadowFor,
3987
+ surfacePadValue,
3988
+ verticalGapValue
3298
3989
  });
3299
3990
  //# sourceMappingURL=internal.cjs.map