@delopay/sdk 0.73.0 → 0.75.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-RGA6KEKL.js → chunk-5J763YMV.js} +210 -6
- package/dist/chunk-5J763YMV.js.map +1 -0
- package/dist/index.cjs +223 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -4
- package/dist/index.d.ts +83 -4
- package/dist/index.js +27 -3
- package/dist/internal.cjs +223 -7
- 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 +27 -3
- package/dist/internal.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-RGA6KEKL.js.map +0 -1
package/dist/internal.cjs
CHANGED
|
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/internal.ts
|
|
21
21
|
var internal_exports = {};
|
|
22
22
|
__export(internal_exports, {
|
|
23
|
+
ALL_CUSTOM_FIELD_CONDITION_SOURCES: () => ALL_CUSTOM_FIELD_CONDITION_SOURCES,
|
|
24
|
+
ALL_CUSTOM_FIELD_OPERATORS: () => ALL_CUSTOM_FIELD_OPERATORS,
|
|
23
25
|
ALL_CUSTOM_FIELD_TYPES: () => ALL_CUSTOM_FIELD_TYPES,
|
|
24
26
|
Admin: () => Admin,
|
|
25
27
|
AdminPortal: () => AdminPortal,
|
|
@@ -31,7 +33,10 @@ __export(internal_exports, {
|
|
|
31
33
|
BRANDING_EXPORT_VERSION: () => BRANDING_EXPORT_VERSION,
|
|
32
34
|
CUSTOM_CSS_MAX_LENGTH: () => CUSTOM_CSS_MAX_LENGTH,
|
|
33
35
|
CUSTOM_FIELDS_MAX: () => CUSTOM_FIELDS_MAX,
|
|
36
|
+
CUSTOM_FIELD_CONDITIONS_MAX: () => CUSTOM_FIELD_CONDITIONS_MAX,
|
|
34
37
|
CUSTOM_FIELD_KEY_PATTERN: () => CUSTOM_FIELD_KEY_PATTERN,
|
|
38
|
+
CUSTOM_FIELD_OPERATORS_BY_SOURCE: () => CUSTOM_FIELD_OPERATORS_BY_SOURCE,
|
|
39
|
+
CUSTOM_FIELD_VALUELESS_OPERATORS: () => CUSTOM_FIELD_VALUELESS_OPERATORS,
|
|
35
40
|
Cache: () => Cache,
|
|
36
41
|
CardIssuers: () => CardIssuers,
|
|
37
42
|
Cards: () => Cards,
|
|
@@ -65,15 +70,21 @@ __export(internal_exports, {
|
|
|
65
70
|
buttonPadValue: () => buttonPadValue,
|
|
66
71
|
cloneBranding: () => cloneBranding,
|
|
67
72
|
cloneCustomField: () => cloneCustomField,
|
|
73
|
+
customFieldContextFromMetadata: () => customFieldContextFromMetadata,
|
|
74
|
+
customFieldOperatorTakesValue: () => customFieldOperatorTakesValue,
|
|
68
75
|
customFieldOptionLabel: () => customFieldOptionLabel,
|
|
69
76
|
customFieldText: () => customFieldText,
|
|
70
77
|
decodeBadges: () => decodeBadges,
|
|
71
78
|
decodeBranding: () => decodeBranding,
|
|
72
79
|
decodeCustomFields: () => decodeCustomFields,
|
|
73
80
|
defaultBranding: () => defaultBranding,
|
|
81
|
+
defaultCustomFieldVisibility: () => defaultCustomFieldVisibility,
|
|
82
|
+
defaultOperatorForSource: () => defaultOperatorForSource,
|
|
74
83
|
encodeBadges: () => encodeBadges,
|
|
75
84
|
encodeBranding: () => encodeBranding,
|
|
76
85
|
encodeCustomFields: () => encodeCustomFields,
|
|
86
|
+
evaluateCustomFieldCondition: () => evaluateCustomFieldCondition,
|
|
87
|
+
evaluateCustomFieldVisibility: () => evaluateCustomFieldVisibility,
|
|
77
88
|
feeProgram: () => feeProgram,
|
|
78
89
|
fontStack: () => fontStack,
|
|
79
90
|
fontWeightValue: () => fontWeightValue,
|
|
@@ -90,7 +101,8 @@ __export(internal_exports, {
|
|
|
90
101
|
sanitizeCustomCss: () => sanitizeCustomCss,
|
|
91
102
|
shadowFor: () => shadowFor,
|
|
92
103
|
surfacePadValue: () => surfacePadValue,
|
|
93
|
-
verticalGapValue: () => verticalGapValue
|
|
104
|
+
verticalGapValue: () => verticalGapValue,
|
|
105
|
+
visibleCustomFields: () => visibleCustomFields
|
|
94
106
|
});
|
|
95
107
|
module.exports = __toCommonJS(internal_exports);
|
|
96
108
|
|
|
@@ -3117,7 +3129,8 @@ var AvailabilityOverrides = class {
|
|
|
3117
3129
|
/**
|
|
3118
3130
|
* Preview the methods a customer in `country` would be shown for a shop —
|
|
3119
3131
|
* the connector ceiling narrowed by the smart country defaults and the
|
|
3120
|
-
* merchant overrides, without an active payment.
|
|
3132
|
+
* merchant overrides, without an active payment. Pass `amount` + `currency`
|
|
3133
|
+
* to also evaluate order-value rules.
|
|
3121
3134
|
* `GET /availability-overrides/preview`
|
|
3122
3135
|
*/
|
|
3123
3136
|
async preview(params) {
|
|
@@ -3125,7 +3138,10 @@ var AvailabilityOverrides = class {
|
|
|
3125
3138
|
query: {
|
|
3126
3139
|
merchant_id: params.merchant_id,
|
|
3127
3140
|
profile_id: params.profile_id,
|
|
3128
|
-
...params.country ? { country: params.country } : {}
|
|
3141
|
+
...params.country ? { country: params.country } : {},
|
|
3142
|
+
// `0` is a legitimate order value, so test for presence, not truthiness.
|
|
3143
|
+
...params.amount !== void 0 ? { amount: params.amount } : {},
|
|
3144
|
+
...params.currency ? { currency: params.currency } : {}
|
|
3129
3145
|
}
|
|
3130
3146
|
});
|
|
3131
3147
|
}
|
|
@@ -4003,7 +4019,11 @@ function cloneCustomField(f) {
|
|
|
4003
4019
|
labelTranslations: { ...f.labelTranslations },
|
|
4004
4020
|
placeholderTranslations: { ...f.placeholderTranslations },
|
|
4005
4021
|
helpTextTranslations: { ...f.helpTextTranslations },
|
|
4006
|
-
options: f.options.map((o) => ({ ...o, labelTranslations: { ...o.labelTranslations } }))
|
|
4022
|
+
options: f.options.map((o) => ({ ...o, labelTranslations: { ...o.labelTranslations } })),
|
|
4023
|
+
visibility: {
|
|
4024
|
+
...f.visibility,
|
|
4025
|
+
conditions: f.visibility.conditions.map((c) => ({ ...c }))
|
|
4026
|
+
}
|
|
4007
4027
|
};
|
|
4008
4028
|
}
|
|
4009
4029
|
var CUSTOM_CSS_MAX_LENGTH = 5e4;
|
|
@@ -4091,6 +4111,46 @@ var ALL_CUSTOM_FIELD_TYPES = [
|
|
|
4091
4111
|
"email",
|
|
4092
4112
|
"select"
|
|
4093
4113
|
];
|
|
4114
|
+
var CUSTOM_FIELD_CONDITIONS_MAX = 10;
|
|
4115
|
+
var ALL_CUSTOM_FIELD_CONDITION_SOURCES = [
|
|
4116
|
+
"metadata",
|
|
4117
|
+
"currency",
|
|
4118
|
+
"amount"
|
|
4119
|
+
];
|
|
4120
|
+
var ALL_CUSTOM_FIELD_OPERATORS = [
|
|
4121
|
+
"equals",
|
|
4122
|
+
"not_equals",
|
|
4123
|
+
"contains",
|
|
4124
|
+
"not_contains",
|
|
4125
|
+
"starts_with",
|
|
4126
|
+
"ends_with",
|
|
4127
|
+
"in",
|
|
4128
|
+
"not_in",
|
|
4129
|
+
"exists",
|
|
4130
|
+
"not_exists",
|
|
4131
|
+
"gt",
|
|
4132
|
+
"gte",
|
|
4133
|
+
"lt",
|
|
4134
|
+
"lte"
|
|
4135
|
+
];
|
|
4136
|
+
var CUSTOM_FIELD_OPERATORS_BY_SOURCE = {
|
|
4137
|
+
metadata: ALL_CUSTOM_FIELD_OPERATORS,
|
|
4138
|
+
currency: ["equals", "not_equals", "in", "not_in"],
|
|
4139
|
+
amount: ["equals", "not_equals", "gt", "gte", "lt", "lte"]
|
|
4140
|
+
};
|
|
4141
|
+
var CUSTOM_FIELD_VALUELESS_OPERATORS = [
|
|
4142
|
+
"exists",
|
|
4143
|
+
"not_exists"
|
|
4144
|
+
];
|
|
4145
|
+
function customFieldOperatorTakesValue(operator) {
|
|
4146
|
+
return !CUSTOM_FIELD_VALUELESS_OPERATORS.includes(operator);
|
|
4147
|
+
}
|
|
4148
|
+
function defaultOperatorForSource(source) {
|
|
4149
|
+
return CUSTOM_FIELD_OPERATORS_BY_SOURCE[source][0] ?? "equals";
|
|
4150
|
+
}
|
|
4151
|
+
function defaultCustomFieldVisibility() {
|
|
4152
|
+
return { mode: "always", match: "all", conditions: [] };
|
|
4153
|
+
}
|
|
4094
4154
|
function parseTranslations(raw) {
|
|
4095
4155
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
4096
4156
|
const out = {};
|
|
@@ -4099,6 +4159,41 @@ function parseTranslations(raw) {
|
|
|
4099
4159
|
}
|
|
4100
4160
|
return out;
|
|
4101
4161
|
}
|
|
4162
|
+
function normalizeCondition(raw, index) {
|
|
4163
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
4164
|
+
const c = raw;
|
|
4165
|
+
const source = pickEnum(
|
|
4166
|
+
c["source"],
|
|
4167
|
+
ALL_CUSTOM_FIELD_CONDITION_SOURCES,
|
|
4168
|
+
"metadata"
|
|
4169
|
+
);
|
|
4170
|
+
const allowed = CUSTOM_FIELD_OPERATORS_BY_SOURCE[source];
|
|
4171
|
+
const operator = pickEnum(
|
|
4172
|
+
c["operator"],
|
|
4173
|
+
allowed,
|
|
4174
|
+
defaultOperatorForSource(source)
|
|
4175
|
+
);
|
|
4176
|
+
const rawValue = c["value"];
|
|
4177
|
+
return {
|
|
4178
|
+
id: typeof c["id"] === "string" && c["id"] ? c["id"] : `cond-${index}`,
|
|
4179
|
+
source,
|
|
4180
|
+
// Only metadata conditions carry a key; drop anything else so the
|
|
4181
|
+
// encoded form stays canonical.
|
|
4182
|
+
key: source === "metadata" && typeof c["key"] === "string" ? c["key"].trim() : "",
|
|
4183
|
+
operator,
|
|
4184
|
+
value: typeof rawValue === "string" ? rawValue : typeof rawValue === "number" || typeof rawValue === "boolean" ? String(rawValue) : ""
|
|
4185
|
+
};
|
|
4186
|
+
}
|
|
4187
|
+
function normalizeVisibility(raw) {
|
|
4188
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return defaultCustomFieldVisibility();
|
|
4189
|
+
const v = raw;
|
|
4190
|
+
const conditions = Array.isArray(v["conditions"]) ? v["conditions"].slice(0, CUSTOM_FIELD_CONDITIONS_MAX).map(normalizeCondition).filter((c) => c !== null) : [];
|
|
4191
|
+
return {
|
|
4192
|
+
mode: pickEnum(v["mode"], ["always", "match"], "always"),
|
|
4193
|
+
match: pickEnum(v["match"], ["all", "any"], "all"),
|
|
4194
|
+
conditions
|
|
4195
|
+
};
|
|
4196
|
+
}
|
|
4102
4197
|
function parseBoundedInt(raw) {
|
|
4103
4198
|
const n = typeof raw === "number" ? raw : typeof raw === "string" ? Number(raw) : NaN;
|
|
4104
4199
|
if (!Number.isInteger(n) || n < 0) return null;
|
|
@@ -4136,7 +4231,8 @@ function normalizeCustomField(raw, index) {
|
|
|
4136
4231
|
// Guard inverted bounds at decode so consumers never see min > max.
|
|
4137
4232
|
maxLength: maxLength !== null && minLength !== null && maxLength < minLength ? null : maxLength,
|
|
4138
4233
|
defaultValue: typeof f["defaultValue"] === "string" ? f["defaultValue"] : "",
|
|
4139
|
-
options
|
|
4234
|
+
options,
|
|
4235
|
+
visibility: normalizeVisibility(f["visibility"])
|
|
4140
4236
|
};
|
|
4141
4237
|
}
|
|
4142
4238
|
function parseCustomFieldsLoose(raw) {
|
|
@@ -4180,10 +4276,118 @@ function encodeCustomFields(fields) {
|
|
|
4180
4276
|
...f.minLength !== null ? { minLength: f.minLength } : {},
|
|
4181
4277
|
...f.maxLength !== null ? { maxLength: f.maxLength } : {},
|
|
4182
4278
|
...f.defaultValue ? { defaultValue: f.defaultValue } : {},
|
|
4183
|
-
...f.type === "select" ? { options: f.options } : {}
|
|
4279
|
+
...f.type === "select" ? { options: f.options } : {},
|
|
4280
|
+
// Omitted for unconditional fields so the stored blob (and every
|
|
4281
|
+
// pre-feature payload) stays byte-identical to what it was.
|
|
4282
|
+
...f.visibility.mode === "match" ? { visibility: encodeVisibility(f.visibility) } : {}
|
|
4184
4283
|
}))
|
|
4185
4284
|
);
|
|
4186
4285
|
}
|
|
4286
|
+
function encodeVisibility(v) {
|
|
4287
|
+
return {
|
|
4288
|
+
mode: v.mode,
|
|
4289
|
+
match: v.match,
|
|
4290
|
+
conditions: v.conditions.map((c) => ({
|
|
4291
|
+
id: c.id,
|
|
4292
|
+
source: c.source,
|
|
4293
|
+
...c.source === "metadata" && c.key ? { key: c.key } : {},
|
|
4294
|
+
operator: c.operator,
|
|
4295
|
+
...customFieldOperatorTakesValue(c.operator) && c.value ? { value: c.value } : {}
|
|
4296
|
+
}))
|
|
4297
|
+
};
|
|
4298
|
+
}
|
|
4299
|
+
function customFieldContextFromMetadata(raw) {
|
|
4300
|
+
const out = {};
|
|
4301
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return out;
|
|
4302
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
4303
|
+
const flat = flattenMetadataValue(value);
|
|
4304
|
+
if (flat !== null) out[key] = flat;
|
|
4305
|
+
}
|
|
4306
|
+
return out;
|
|
4307
|
+
}
|
|
4308
|
+
function flattenMetadataValue(value) {
|
|
4309
|
+
if (typeof value === "string") return value;
|
|
4310
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
4311
|
+
if (value === null || value === void 0) return null;
|
|
4312
|
+
if (Array.isArray(value)) {
|
|
4313
|
+
return value.map((v) => flattenMetadataValue(v)).filter((v) => v !== null).join(",");
|
|
4314
|
+
}
|
|
4315
|
+
try {
|
|
4316
|
+
return JSON.stringify(value);
|
|
4317
|
+
} catch {
|
|
4318
|
+
return null;
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4321
|
+
function norm(value) {
|
|
4322
|
+
return value.trim().toLowerCase();
|
|
4323
|
+
}
|
|
4324
|
+
var DECIMAL_NUMBER_PATTERN = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
4325
|
+
function numeric(value) {
|
|
4326
|
+
const trimmed = value.trim();
|
|
4327
|
+
if (!DECIMAL_NUMBER_PATTERN.test(trimmed)) return null;
|
|
4328
|
+
const n = Number(trimmed);
|
|
4329
|
+
return Number.isFinite(n) ? n : null;
|
|
4330
|
+
}
|
|
4331
|
+
function splitList(value) {
|
|
4332
|
+
return value.split(",").map((part) => norm(part)).filter((part) => part.length > 0);
|
|
4333
|
+
}
|
|
4334
|
+
function operandFor(condition, ctx) {
|
|
4335
|
+
switch (condition.source) {
|
|
4336
|
+
case "currency":
|
|
4337
|
+
return ctx.currency;
|
|
4338
|
+
case "amount":
|
|
4339
|
+
return String(ctx.amount);
|
|
4340
|
+
case "metadata":
|
|
4341
|
+
return Object.prototype.hasOwnProperty.call(ctx.metadata, condition.key) ? ctx.metadata[condition.key] : void 0;
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
function evaluateCustomFieldCondition(condition, ctx) {
|
|
4345
|
+
const raw = operandFor(condition, ctx);
|
|
4346
|
+
const actual = raw ?? "";
|
|
4347
|
+
const expected = condition.value;
|
|
4348
|
+
switch (condition.operator) {
|
|
4349
|
+
case "exists":
|
|
4350
|
+
return raw !== void 0 && raw.trim().length > 0;
|
|
4351
|
+
case "not_exists":
|
|
4352
|
+
return raw === void 0 || raw.trim().length === 0;
|
|
4353
|
+
case "equals":
|
|
4354
|
+
return norm(actual) === norm(expected);
|
|
4355
|
+
case "not_equals":
|
|
4356
|
+
return norm(actual) !== norm(expected);
|
|
4357
|
+
case "contains":
|
|
4358
|
+
return norm(actual).includes(norm(expected));
|
|
4359
|
+
case "not_contains":
|
|
4360
|
+
return !norm(actual).includes(norm(expected));
|
|
4361
|
+
case "starts_with":
|
|
4362
|
+
return norm(actual).startsWith(norm(expected));
|
|
4363
|
+
case "ends_with":
|
|
4364
|
+
return norm(actual).endsWith(norm(expected));
|
|
4365
|
+
case "in":
|
|
4366
|
+
return splitList(expected).includes(norm(actual));
|
|
4367
|
+
case "not_in":
|
|
4368
|
+
return !splitList(expected).includes(norm(actual));
|
|
4369
|
+
case "gt":
|
|
4370
|
+
case "gte":
|
|
4371
|
+
case "lt":
|
|
4372
|
+
case "lte": {
|
|
4373
|
+
const a = numeric(actual);
|
|
4374
|
+
const b = numeric(expected);
|
|
4375
|
+
if (a === null || b === null) return false;
|
|
4376
|
+
if (condition.operator === "gt") return a > b;
|
|
4377
|
+
if (condition.operator === "gte") return a >= b;
|
|
4378
|
+
if (condition.operator === "lt") return a < b;
|
|
4379
|
+
return a <= b;
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4382
|
+
}
|
|
4383
|
+
function evaluateCustomFieldVisibility(field, ctx) {
|
|
4384
|
+
const { mode, match, conditions } = field.visibility;
|
|
4385
|
+
if (mode !== "match" || conditions.length === 0) return true;
|
|
4386
|
+
return match === "any" ? conditions.some((c) => evaluateCustomFieldCondition(c, ctx)) : conditions.every((c) => evaluateCustomFieldCondition(c, ctx));
|
|
4387
|
+
}
|
|
4388
|
+
function visibleCustomFields(fields, ctx) {
|
|
4389
|
+
return fields.filter((f) => f.enabled && evaluateCustomFieldVisibility(f, ctx));
|
|
4390
|
+
}
|
|
4187
4391
|
function translationFor(map, locale) {
|
|
4188
4392
|
if (!locale) return null;
|
|
4189
4393
|
const own = (k) => {
|
|
@@ -5124,6 +5328,8 @@ var DelopayInternal = class extends Delopay {
|
|
|
5124
5328
|
};
|
|
5125
5329
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5126
5330
|
0 && (module.exports = {
|
|
5331
|
+
ALL_CUSTOM_FIELD_CONDITION_SOURCES,
|
|
5332
|
+
ALL_CUSTOM_FIELD_OPERATORS,
|
|
5127
5333
|
ALL_CUSTOM_FIELD_TYPES,
|
|
5128
5334
|
Admin,
|
|
5129
5335
|
AdminPortal,
|
|
@@ -5135,7 +5341,10 @@ var DelopayInternal = class extends Delopay {
|
|
|
5135
5341
|
BRANDING_EXPORT_VERSION,
|
|
5136
5342
|
CUSTOM_CSS_MAX_LENGTH,
|
|
5137
5343
|
CUSTOM_FIELDS_MAX,
|
|
5344
|
+
CUSTOM_FIELD_CONDITIONS_MAX,
|
|
5138
5345
|
CUSTOM_FIELD_KEY_PATTERN,
|
|
5346
|
+
CUSTOM_FIELD_OPERATORS_BY_SOURCE,
|
|
5347
|
+
CUSTOM_FIELD_VALUELESS_OPERATORS,
|
|
5139
5348
|
Cache,
|
|
5140
5349
|
CardIssuers,
|
|
5141
5350
|
Cards,
|
|
@@ -5169,15 +5378,21 @@ var DelopayInternal = class extends Delopay {
|
|
|
5169
5378
|
buttonPadValue,
|
|
5170
5379
|
cloneBranding,
|
|
5171
5380
|
cloneCustomField,
|
|
5381
|
+
customFieldContextFromMetadata,
|
|
5382
|
+
customFieldOperatorTakesValue,
|
|
5172
5383
|
customFieldOptionLabel,
|
|
5173
5384
|
customFieldText,
|
|
5174
5385
|
decodeBadges,
|
|
5175
5386
|
decodeBranding,
|
|
5176
5387
|
decodeCustomFields,
|
|
5177
5388
|
defaultBranding,
|
|
5389
|
+
defaultCustomFieldVisibility,
|
|
5390
|
+
defaultOperatorForSource,
|
|
5178
5391
|
encodeBadges,
|
|
5179
5392
|
encodeBranding,
|
|
5180
5393
|
encodeCustomFields,
|
|
5394
|
+
evaluateCustomFieldCondition,
|
|
5395
|
+
evaluateCustomFieldVisibility,
|
|
5181
5396
|
feeProgram,
|
|
5182
5397
|
fontStack,
|
|
5183
5398
|
fontWeightValue,
|
|
@@ -5194,6 +5409,7 @@ var DelopayInternal = class extends Delopay {
|
|
|
5194
5409
|
sanitizeCustomCss,
|
|
5195
5410
|
shadowFor,
|
|
5196
5411
|
surfacePadValue,
|
|
5197
|
-
verticalGapValue
|
|
5412
|
+
verticalGapValue,
|
|
5413
|
+
visibleCustomFields
|
|
5198
5414
|
});
|
|
5199
5415
|
//# sourceMappingURL=internal.cjs.map
|