@delopay/sdk 0.70.0 → 0.71.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/{chunk-ASCCS4NN.js → chunk-RGA6KEKL.js} +159 -4
- package/dist/{chunk-ASCCS4NN.js.map → chunk-RGA6KEKL.js.map} +1 -1
- package/dist/index.cjs +167 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +19 -1
- package/dist/internal.cjs +167 -3
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +19 -1
- package/dist/internal.js.map +1 -1
- package/package.json +1 -1
|
@@ -3872,7 +3872,8 @@ var DEFAULT_BRANDING_BASE = {
|
|
|
3872
3872
|
var DEFAULT_BRANDING = {
|
|
3873
3873
|
...DEFAULT_BRANDING_BASE,
|
|
3874
3874
|
...LIGHT_PALETTE,
|
|
3875
|
-
trustBadges: DEFAULT_BADGES.map((b) => ({ ...b }))
|
|
3875
|
+
trustBadges: DEFAULT_BADGES.map((b) => ({ ...b })),
|
|
3876
|
+
customFields: []
|
|
3876
3877
|
};
|
|
3877
3878
|
var DEFAULT_BRANDING_DARK = {
|
|
3878
3879
|
...DEFAULT_BRANDING_BASE,
|
|
@@ -3887,13 +3888,27 @@ var DEFAULT_BRANDING_DARK = {
|
|
|
3887
3888
|
buttonBackground: "#1E4FEB",
|
|
3888
3889
|
buttonText: "#ffffff",
|
|
3889
3890
|
surfaceStyle: "flat",
|
|
3890
|
-
trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b }))
|
|
3891
|
+
trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b })),
|
|
3892
|
+
customFields: []
|
|
3891
3893
|
};
|
|
3892
3894
|
function defaultBranding() {
|
|
3893
3895
|
return cloneBranding(DEFAULT_BRANDING);
|
|
3894
3896
|
}
|
|
3895
3897
|
function cloneBranding(b) {
|
|
3896
|
-
return {
|
|
3898
|
+
return {
|
|
3899
|
+
...b,
|
|
3900
|
+
trustBadges: b.trustBadges.map((badge) => ({ ...badge })),
|
|
3901
|
+
customFields: b.customFields.map(cloneCustomField)
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
function cloneCustomField(f) {
|
|
3905
|
+
return {
|
|
3906
|
+
...f,
|
|
3907
|
+
labelTranslations: { ...f.labelTranslations },
|
|
3908
|
+
placeholderTranslations: { ...f.placeholderTranslations },
|
|
3909
|
+
helpTextTranslations: { ...f.helpTextTranslations },
|
|
3910
|
+
options: f.options.map((o) => ({ ...o, labelTranslations: { ...o.labelTranslations } }))
|
|
3911
|
+
};
|
|
3897
3912
|
}
|
|
3898
3913
|
var CUSTOM_CSS_MAX_LENGTH = 5e4;
|
|
3899
3914
|
function sanitizeCustomCss(raw) {
|
|
@@ -3971,10 +3986,135 @@ function encodeBadges(badges) {
|
|
|
3971
3986
|
}))
|
|
3972
3987
|
);
|
|
3973
3988
|
}
|
|
3989
|
+
var CUSTOM_FIELDS_MAX = 20;
|
|
3990
|
+
var CUSTOM_FIELD_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,39}$/;
|
|
3991
|
+
var ALL_CUSTOM_FIELD_TYPES = [
|
|
3992
|
+
"text",
|
|
3993
|
+
"textarea",
|
|
3994
|
+
"password",
|
|
3995
|
+
"email",
|
|
3996
|
+
"select"
|
|
3997
|
+
];
|
|
3998
|
+
function parseTranslations(raw) {
|
|
3999
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
4000
|
+
const out = {};
|
|
4001
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
4002
|
+
if (typeof v === "string" && v.length > 0) out[k] = v;
|
|
4003
|
+
}
|
|
4004
|
+
return out;
|
|
4005
|
+
}
|
|
4006
|
+
function parseBoundedInt(raw) {
|
|
4007
|
+
const n = typeof raw === "number" ? raw : typeof raw === "string" ? Number(raw) : NaN;
|
|
4008
|
+
if (!Number.isInteger(n) || n < 0) return null;
|
|
4009
|
+
return Math.min(n, 5e3);
|
|
4010
|
+
}
|
|
4011
|
+
function normalizeCustomField(raw, index) {
|
|
4012
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
4013
|
+
const f = raw;
|
|
4014
|
+
const key = typeof f["key"] === "string" ? f["key"].trim() : "";
|
|
4015
|
+
if (!CUSTOM_FIELD_KEY_PATTERN.test(key)) return null;
|
|
4016
|
+
const type = pickEnum(f["type"], ALL_CUSTOM_FIELD_TYPES, "text");
|
|
4017
|
+
const options = type === "select" && Array.isArray(f["options"]) ? f["options"].filter((o) => !!o && typeof o === "object").map((o) => {
|
|
4018
|
+
const value = typeof o["value"] === "string" ? o["value"] : "";
|
|
4019
|
+
return {
|
|
4020
|
+
value,
|
|
4021
|
+
label: typeof o["label"] === "string" && o["label"] ? o["label"] : value,
|
|
4022
|
+
labelTranslations: parseTranslations(o["labelTranslations"])
|
|
4023
|
+
};
|
|
4024
|
+
}).filter((o) => o.value.length > 0) : [];
|
|
4025
|
+
const minLength = parseBoundedInt(f["minLength"]);
|
|
4026
|
+
const maxLength = parseBoundedInt(f["maxLength"]);
|
|
4027
|
+
return {
|
|
4028
|
+
id: typeof f["id"] === "string" && f["id"] ? f["id"] : `field-${index}`,
|
|
4029
|
+
key,
|
|
4030
|
+
type,
|
|
4031
|
+
label: typeof f["label"] === "string" && f["label"] ? f["label"] : key,
|
|
4032
|
+
labelTranslations: parseTranslations(f["labelTranslations"]),
|
|
4033
|
+
placeholder: typeof f["placeholder"] === "string" ? f["placeholder"] : "",
|
|
4034
|
+
placeholderTranslations: parseTranslations(f["placeholderTranslations"]),
|
|
4035
|
+
helpText: typeof f["helpText"] === "string" ? f["helpText"] : "",
|
|
4036
|
+
helpTextTranslations: parseTranslations(f["helpTextTranslations"]),
|
|
4037
|
+
required: parseBool(f["required"], false),
|
|
4038
|
+
enabled: parseBool(f["enabled"], true),
|
|
4039
|
+
minLength,
|
|
4040
|
+
// Guard inverted bounds at decode so consumers never see min > max.
|
|
4041
|
+
maxLength: maxLength !== null && minLength !== null && maxLength < minLength ? null : maxLength,
|
|
4042
|
+
defaultValue: typeof f["defaultValue"] === "string" ? f["defaultValue"] : "",
|
|
4043
|
+
options
|
|
4044
|
+
};
|
|
4045
|
+
}
|
|
4046
|
+
function parseCustomFieldsLoose(raw) {
|
|
4047
|
+
if (!Array.isArray(raw)) return null;
|
|
4048
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4049
|
+
const out = [];
|
|
4050
|
+
for (let i = 0; i < raw.length && out.length < CUSTOM_FIELDS_MAX; i++) {
|
|
4051
|
+
const field = normalizeCustomField(raw[i], i);
|
|
4052
|
+
if (!field || seen.has(field.key)) continue;
|
|
4053
|
+
seen.add(field.key);
|
|
4054
|
+
out.push(field);
|
|
4055
|
+
}
|
|
4056
|
+
return out;
|
|
4057
|
+
}
|
|
4058
|
+
function decodeCustomFields(raw) {
|
|
4059
|
+
if (raw === void 0) return null;
|
|
4060
|
+
try {
|
|
4061
|
+
return parseCustomFieldsLoose(JSON.parse(raw));
|
|
4062
|
+
} catch {
|
|
4063
|
+
return null;
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
function encodeCustomFields(fields) {
|
|
4067
|
+
const nonEmpty = (m) => {
|
|
4068
|
+
const entries = Object.entries(m).filter(([, v]) => v.trim().length > 0);
|
|
4069
|
+
return entries.length > 0 ? Object.fromEntries(entries) : void 0;
|
|
4070
|
+
};
|
|
4071
|
+
return JSON.stringify(
|
|
4072
|
+
fields.map((f) => ({
|
|
4073
|
+
id: f.id,
|
|
4074
|
+
key: f.key,
|
|
4075
|
+
type: f.type,
|
|
4076
|
+
label: f.label,
|
|
4077
|
+
...nonEmpty(f.labelTranslations) ? { labelTranslations: nonEmpty(f.labelTranslations) } : {},
|
|
4078
|
+
...f.placeholder ? { placeholder: f.placeholder } : {},
|
|
4079
|
+
...nonEmpty(f.placeholderTranslations) ? { placeholderTranslations: nonEmpty(f.placeholderTranslations) } : {},
|
|
4080
|
+
...f.helpText ? { helpText: f.helpText } : {},
|
|
4081
|
+
...nonEmpty(f.helpTextTranslations) ? { helpTextTranslations: nonEmpty(f.helpTextTranslations) } : {},
|
|
4082
|
+
...f.required ? { required: true } : {},
|
|
4083
|
+
...f.enabled ? {} : { enabled: false },
|
|
4084
|
+
...f.minLength !== null ? { minLength: f.minLength } : {},
|
|
4085
|
+
...f.maxLength !== null ? { maxLength: f.maxLength } : {},
|
|
4086
|
+
...f.defaultValue ? { defaultValue: f.defaultValue } : {},
|
|
4087
|
+
...f.type === "select" ? { options: f.options } : {}
|
|
4088
|
+
}))
|
|
4089
|
+
);
|
|
4090
|
+
}
|
|
4091
|
+
function translationFor(map, locale) {
|
|
4092
|
+
if (!locale) return null;
|
|
4093
|
+
const own = (k) => {
|
|
4094
|
+
const v = Object.prototype.hasOwnProperty.call(map, k) ? map[k] : void 0;
|
|
4095
|
+
return typeof v === "string" && v.length > 0 ? v : null;
|
|
4096
|
+
};
|
|
4097
|
+
const exact = own(locale);
|
|
4098
|
+
if (exact) return exact;
|
|
4099
|
+
const base = locale.split("-")[0];
|
|
4100
|
+
return base && base !== locale ? own(base) : null;
|
|
4101
|
+
}
|
|
4102
|
+
function customFieldText(field, part, locale) {
|
|
4103
|
+
const map = part === "label" ? field.labelTranslations : part === "placeholder" ? field.placeholderTranslations : field.helpTextTranslations;
|
|
4104
|
+
const translated = translationFor(map, locale);
|
|
4105
|
+
if (translated) return translated;
|
|
4106
|
+
const fallback = field[part];
|
|
4107
|
+
if (fallback) return fallback;
|
|
4108
|
+
return part === "label" ? field.key : "";
|
|
4109
|
+
}
|
|
4110
|
+
function customFieldOptionLabel(option, locale) {
|
|
4111
|
+
return translationFor(option.labelTranslations, locale) ?? (option.label || option.value);
|
|
4112
|
+
}
|
|
3974
4113
|
function decodeBranding(source) {
|
|
3975
4114
|
if (!source) return cloneBranding(DEFAULT_BRANDING);
|
|
3976
4115
|
const extras = source.sdk_ui_rules?.[BRANDING_GROUP_KEY] ?? {};
|
|
3977
4116
|
const decodedBadges = decodeBadges(extras["trustBadges"]);
|
|
4117
|
+
const decodedCustomFields = decodeCustomFields(extras["customFields"]);
|
|
3978
4118
|
const displayName = s(source.merchant_name) || s(source.seller_name);
|
|
3979
4119
|
const logoUrl = s(source.merchant_logo) || s(source.logo);
|
|
3980
4120
|
const tagline = s(extras["tagline"]) || s(source.merchant_description);
|
|
@@ -4076,6 +4216,7 @@ function decodeBranding(source) {
|
|
|
4076
4216
|
showCurrencyCode: parseBool(extras["showCurrencyCode"], DEFAULT_BRANDING.showCurrencyCode),
|
|
4077
4217
|
showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
|
|
4078
4218
|
trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
|
|
4219
|
+
customFields: decodedCustomFields ?? [],
|
|
4079
4220
|
headerText: s(source.payment_form_header_text),
|
|
4080
4221
|
payButtonLabel: s(source.payment_button_text),
|
|
4081
4222
|
cardTermsMessage: s(source.custom_message_for_card_terms),
|
|
@@ -4129,6 +4270,9 @@ function encodeBranding(branding, base) {
|
|
|
4129
4270
|
labelStyle: branding.labelStyle,
|
|
4130
4271
|
trustBadges: encodeBadges(branding.trustBadges)
|
|
4131
4272
|
};
|
|
4273
|
+
if (branding.customFields.length > 0) {
|
|
4274
|
+
extras["customFields"] = encodeCustomFields(branding.customFields);
|
|
4275
|
+
}
|
|
4132
4276
|
const tagline = trim(branding.tagline);
|
|
4133
4277
|
if (tagline) extras["tagline"] = tagline;
|
|
4134
4278
|
const footer = trim(branding.footerText);
|
|
@@ -4179,6 +4323,7 @@ function parseImportedBranding(raw) {
|
|
|
4179
4323
|
const sStr = (v, fallback) => typeof v === "string" ? v : fallback;
|
|
4180
4324
|
const sHex = (v, fallback) => typeof v === "string" && isHexColor(v) ? v : fallback;
|
|
4181
4325
|
const trustBadges = parseTrustBadgesLoose(root["trustBadges"]) ?? dflt.trustBadges.map((b) => ({ ...b }));
|
|
4326
|
+
const customFields = parseCustomFieldsLoose(root["customFields"]) ?? [];
|
|
4182
4327
|
const labelStyle = (() => {
|
|
4183
4328
|
const v = root["labelStyle"];
|
|
4184
4329
|
if (v === "above" || v === "hidden") return v;
|
|
@@ -4249,6 +4394,7 @@ function parseImportedBranding(raw) {
|
|
|
4249
4394
|
showCurrencyCode: parseBool(root["showCurrencyCode"], dflt.showCurrencyCode),
|
|
4250
4395
|
showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
|
|
4251
4396
|
trustBadges,
|
|
4397
|
+
customFields,
|
|
4252
4398
|
headerText: sStr(root["headerText"], dflt.headerText),
|
|
4253
4399
|
payButtonLabel: sStr(root["payButtonLabel"], dflt.payButtonLabel),
|
|
4254
4400
|
cardTermsMessage: sStr(root["cardTermsMessage"], dflt.cardTermsMessage),
|
|
@@ -4357,10 +4503,19 @@ export {
|
|
|
4357
4503
|
DEFAULT_BRANDING_DARK,
|
|
4358
4504
|
defaultBranding,
|
|
4359
4505
|
cloneBranding,
|
|
4506
|
+
cloneCustomField,
|
|
4360
4507
|
CUSTOM_CSS_MAX_LENGTH,
|
|
4361
4508
|
sanitizeCustomCss,
|
|
4362
4509
|
decodeBadges,
|
|
4363
4510
|
encodeBadges,
|
|
4511
|
+
CUSTOM_FIELDS_MAX,
|
|
4512
|
+
CUSTOM_FIELD_KEY_PATTERN,
|
|
4513
|
+
ALL_CUSTOM_FIELD_TYPES,
|
|
4514
|
+
parseCustomFieldsLoose,
|
|
4515
|
+
decodeCustomFields,
|
|
4516
|
+
encodeCustomFields,
|
|
4517
|
+
customFieldText,
|
|
4518
|
+
customFieldOptionLabel,
|
|
4364
4519
|
decodeBranding,
|
|
4365
4520
|
encodeBranding,
|
|
4366
4521
|
BRANDING_EXPORT_FORMAT,
|
|
@@ -4370,4 +4525,4 @@ export {
|
|
|
4370
4525
|
applyBrandingVariables,
|
|
4371
4526
|
shadowFor
|
|
4372
4527
|
};
|
|
4373
|
-
//# sourceMappingURL=chunk-
|
|
4528
|
+
//# sourceMappingURL=chunk-RGA6KEKL.js.map
|