@vesant-sdk/fraud 0.1.3 → 0.2.0-dev.03a9c84
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/README.md +24 -21
- package/dist/index.d.mts +78 -81
- package/dist/index.d.ts +78 -81
- package/dist/index.js +167 -212
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -198
- package/dist/index.mjs.map +1 -1
- package/package.json +51 -48
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { ValidationError, BaseClient } from '@vesant-sdk/core';
|
|
1
|
+
import { PAYMENT_TYPE_VALUES, normalizePaymentType, ValidationError, BaseClient } from '@vesant-sdk/core';
|
|
2
|
+
export { normalizePaymentType } from '@vesant-sdk/core';
|
|
2
3
|
|
|
3
4
|
// src/client.ts
|
|
4
|
-
|
|
5
|
-
// src/types/enums.ts
|
|
6
|
-
var SiftTransactionTypeValues = [
|
|
5
|
+
var TransactionTypeValues = [
|
|
7
6
|
"$sale",
|
|
8
7
|
"$authorize",
|
|
9
8
|
"$capture",
|
|
@@ -31,7 +30,7 @@ var TransactionType = {
|
|
|
31
30
|
Send: "$send",
|
|
32
31
|
Receive: "$receive"
|
|
33
32
|
};
|
|
34
|
-
var
|
|
33
|
+
var ChargebackStateValues = [
|
|
35
34
|
"$received",
|
|
36
35
|
"$accepted",
|
|
37
36
|
"$disputed",
|
|
@@ -45,7 +44,7 @@ var ChargebackState = {
|
|
|
45
44
|
Won: "$won",
|
|
46
45
|
Lost: "$lost"
|
|
47
46
|
};
|
|
48
|
-
var
|
|
47
|
+
var ChargebackReasonValues = [
|
|
49
48
|
"$fraud",
|
|
50
49
|
"$duplicate",
|
|
51
50
|
"$product_not_received",
|
|
@@ -73,28 +72,28 @@ var ChargebackReason = {
|
|
|
73
72
|
AchReversal: "$ach_reversal",
|
|
74
73
|
Other: "$other"
|
|
75
74
|
};
|
|
76
|
-
var
|
|
75
|
+
var LoginStatusValues = ["$success", "$failure"];
|
|
77
76
|
var LoginStatus = {
|
|
78
77
|
Success: "$success",
|
|
79
78
|
Failure: "$failure"
|
|
80
79
|
};
|
|
81
|
-
var
|
|
80
|
+
var LoginFailureReasonValues = [
|
|
82
81
|
"$account_unknown",
|
|
83
82
|
"$account_suspended",
|
|
84
83
|
"$account_disabled",
|
|
85
84
|
"$wrong_password"
|
|
86
85
|
];
|
|
87
|
-
var
|
|
86
|
+
var PasswordUpdateReasonValues = [
|
|
88
87
|
"$user_update",
|
|
89
88
|
"$forgot_password",
|
|
90
89
|
"$forced_reset"
|
|
91
90
|
];
|
|
92
91
|
var PasswordUpdateReason = {
|
|
93
|
-
UserUpdate:
|
|
94
|
-
ForgotPassword:
|
|
95
|
-
ForcedReset:
|
|
92
|
+
UserUpdate: PasswordUpdateReasonValues[0],
|
|
93
|
+
ForgotPassword: PasswordUpdateReasonValues[1],
|
|
94
|
+
ForcedReset: PasswordUpdateReasonValues[2]
|
|
96
95
|
};
|
|
97
|
-
var
|
|
96
|
+
var PasswordUpdateStatusValues = [
|
|
98
97
|
"$pending",
|
|
99
98
|
"$success",
|
|
100
99
|
"$failure"
|
|
@@ -104,12 +103,12 @@ var PasswordUpdateStatus = {
|
|
|
104
103
|
Success: "$success",
|
|
105
104
|
Failure: "$failure"
|
|
106
105
|
};
|
|
107
|
-
var
|
|
106
|
+
var WagerStatusValues = ["$accept", "$cancel"];
|
|
108
107
|
var WagerStatus = {
|
|
109
108
|
Accept: "$accept",
|
|
110
109
|
Cancel: "$cancel"
|
|
111
110
|
};
|
|
112
|
-
var
|
|
111
|
+
var TransactionStatusValues = [
|
|
113
112
|
"$success",
|
|
114
113
|
"$failure",
|
|
115
114
|
"$pending"
|
|
@@ -119,32 +118,7 @@ var TransactionStatus = {
|
|
|
119
118
|
Failure: "$failure",
|
|
120
119
|
Pending: "$pending"
|
|
121
120
|
};
|
|
122
|
-
var
|
|
123
|
-
"$cash",
|
|
124
|
-
"$check",
|
|
125
|
-
"$credit_card",
|
|
126
|
-
"$crypto_currency",
|
|
127
|
-
"$debit_card",
|
|
128
|
-
"$digital_wallet",
|
|
129
|
-
"$electronic_fund_transfer",
|
|
130
|
-
"$financing",
|
|
131
|
-
"$gift_card",
|
|
132
|
-
"$invoice",
|
|
133
|
-
"$in_app_purchase",
|
|
134
|
-
"$money_order",
|
|
135
|
-
"$points",
|
|
136
|
-
"$prepaid_card",
|
|
137
|
-
"$store_credit",
|
|
138
|
-
"$third_party_processor",
|
|
139
|
-
"$voucher",
|
|
140
|
-
"$sepa_credit",
|
|
141
|
-
"$sepa_instant_credit",
|
|
142
|
-
"$sepa_direct_debit",
|
|
143
|
-
"$ach_credit",
|
|
144
|
-
"$ach_debit",
|
|
145
|
-
"$wire_credit",
|
|
146
|
-
"$wire_debit"
|
|
147
|
-
];
|
|
121
|
+
var PaymentTypeValues = PAYMENT_TYPE_VALUES;
|
|
148
122
|
var PaymentType = {
|
|
149
123
|
Cash: "$cash",
|
|
150
124
|
Check: "$check",
|
|
@@ -171,7 +145,7 @@ var PaymentType = {
|
|
|
171
145
|
WireCredit: "$wire_credit",
|
|
172
146
|
WireDebit: "$wire_debit"
|
|
173
147
|
};
|
|
174
|
-
var
|
|
148
|
+
var WalletTypeValues = ["$crypto", "$digital", "$fiat"];
|
|
175
149
|
var WalletType = {
|
|
176
150
|
Crypto: "$crypto",
|
|
177
151
|
Digital: "$digital",
|
|
@@ -199,36 +173,7 @@ var TRANSACTION_RULE_SIGNAL_KEYS = [
|
|
|
199
173
|
"days_since_last_activity",
|
|
200
174
|
"hours_since_account_creation"
|
|
201
175
|
];
|
|
202
|
-
|
|
203
|
-
// src/normalization/payment-methods.ts
|
|
204
|
-
var PAYMENT_TYPE_ALIASES = {
|
|
205
|
-
bank_account: "$electronic_fund_transfer",
|
|
206
|
-
electronic_fund_transfer: "$electronic_fund_transfer",
|
|
207
|
-
credit_card: "$credit_card",
|
|
208
|
-
crypto_currency: "$crypto_currency",
|
|
209
|
-
debit_card: "$debit_card",
|
|
210
|
-
digital_wallet: "$digital_wallet",
|
|
211
|
-
cash: "$cash",
|
|
212
|
-
check: "$check",
|
|
213
|
-
financing: "$financing",
|
|
214
|
-
gift_card: "$gift_card",
|
|
215
|
-
invoice: "$invoice",
|
|
216
|
-
in_app_purchase: "$in_app_purchase",
|
|
217
|
-
money_order: "$money_order",
|
|
218
|
-
points: "$points",
|
|
219
|
-
prepaid_card: "$prepaid_card",
|
|
220
|
-
store_credit: "$store_credit",
|
|
221
|
-
third_party_processor: "$third_party_processor",
|
|
222
|
-
voucher: "$voucher",
|
|
223
|
-
sepa_credit: "$sepa_credit",
|
|
224
|
-
sepa_instant_credit: "$sepa_instant_credit",
|
|
225
|
-
sepa_direct_debit: "$sepa_direct_debit",
|
|
226
|
-
ach_credit: "$ach_credit",
|
|
227
|
-
ach_debit: "$ach_debit",
|
|
228
|
-
wire_credit: "$wire_credit",
|
|
229
|
-
wire_debit: "$wire_debit"
|
|
230
|
-
};
|
|
231
|
-
var SIFT_PAYMENT_METHOD_WHITELIST = /* @__PURE__ */ new Set([
|
|
176
|
+
var PAYMENT_METHOD_FIELD_WHITELIST = /* @__PURE__ */ new Set([
|
|
232
177
|
"payment_type",
|
|
233
178
|
"payment_gateway",
|
|
234
179
|
"card_bin",
|
|
@@ -265,31 +210,18 @@ function isDevEnvironment() {
|
|
|
265
210
|
function warnDeprecatedKey(key) {
|
|
266
211
|
if (!isDevEnvironment()) return;
|
|
267
212
|
const messages = {
|
|
268
|
-
account_number_last4: "[vesant-sdk/fraud] account_number_last4 is not a
|
|
269
|
-
account_id: "[vesant-sdk/fraud] account_id is not a
|
|
270
|
-
wallet_address_last4: "[vesant-sdk/fraud] wallet_address_last4 is not a
|
|
271
|
-
crypto_currency: "[vesant-sdk/fraud] crypto_currency is not a
|
|
272
|
-
network: "[vesant-sdk/fraud] network is not a
|
|
213
|
+
account_number_last4: "[vesant-sdk/fraud] account_number_last4 is not a recognized field; use account_number_last5",
|
|
214
|
+
account_id: "[vesant-sdk/fraud] account_id is not a recognized field; moved to metadata",
|
|
215
|
+
wallet_address_last4: "[vesant-sdk/fraud] wallet_address_last4 is not a recognized field; moved to metadata",
|
|
216
|
+
crypto_currency: "[vesant-sdk/fraud] crypto_currency is not a recognized field on payment_method; moved to metadata",
|
|
217
|
+
network: "[vesant-sdk/fraud] network is not a recognized field on payment_method; moved to metadata"
|
|
273
218
|
};
|
|
274
219
|
const message = messages[key];
|
|
275
220
|
if (message) {
|
|
276
221
|
console.warn(message);
|
|
277
222
|
}
|
|
278
223
|
}
|
|
279
|
-
function
|
|
280
|
-
if (value === void 0 || value === null) return void 0;
|
|
281
|
-
const trimmed = String(value).trim();
|
|
282
|
-
if (trimmed === "") return void 0;
|
|
283
|
-
const normalized = trimmed.startsWith("$") ? trimmed.slice(1) : trimmed;
|
|
284
|
-
const alias = PAYMENT_TYPE_ALIASES[normalized.toLowerCase()];
|
|
285
|
-
if (alias) return alias;
|
|
286
|
-
const withPrefix = `$${normalized}`;
|
|
287
|
-
if (SiftPaymentTypeValues.includes(withPrefix)) {
|
|
288
|
-
return withPrefix;
|
|
289
|
-
}
|
|
290
|
-
return void 0;
|
|
291
|
-
}
|
|
292
|
-
function toSiftAccountNumberLast5(value) {
|
|
224
|
+
function toAccountNumberLast5(value) {
|
|
293
225
|
if (value === void 0 || value === null) return void 0;
|
|
294
226
|
const digits = String(value).replace(/\D/g, "");
|
|
295
227
|
if (digits.length === 0) return void 0;
|
|
@@ -300,11 +232,11 @@ function collectMetadataExtra(metadataExtras, key, value) {
|
|
|
300
232
|
if (value === void 0) return;
|
|
301
233
|
metadataExtras[key] = value;
|
|
302
234
|
}
|
|
303
|
-
function
|
|
235
|
+
function normalizePaymentMethod(raw) {
|
|
304
236
|
const metadataExtras = {};
|
|
305
237
|
const method = {};
|
|
306
238
|
const rawPaymentType = raw.payment_type !== void 0 ? String(raw.payment_type) : raw.$payment_type !== void 0 ? String(raw.$payment_type) : void 0;
|
|
307
|
-
const normalizedType =
|
|
239
|
+
const normalizedType = normalizePaymentType(rawPaymentType);
|
|
308
240
|
if (rawPaymentType !== void 0 && normalizedType === void 0) {
|
|
309
241
|
return null;
|
|
310
242
|
}
|
|
@@ -316,7 +248,7 @@ function normalizeSiftPaymentMethod(raw) {
|
|
|
316
248
|
}
|
|
317
249
|
const accountLast4 = raw.account_number_last4 ?? raw.$account_number_last4;
|
|
318
250
|
const accountLast5 = raw.account_number_last5 ?? raw.$account_number_last5;
|
|
319
|
-
const resolvedLast5 =
|
|
251
|
+
const resolvedLast5 = toAccountNumberLast5(accountLast5 ?? accountLast4);
|
|
320
252
|
if (resolvedLast5 !== void 0) {
|
|
321
253
|
method.account_number_last5 = resolvedLast5;
|
|
322
254
|
}
|
|
@@ -327,13 +259,13 @@ function normalizeSiftPaymentMethod(raw) {
|
|
|
327
259
|
const plainKey = key.startsWith("$") ? key.slice(1) : key;
|
|
328
260
|
if (METADATA_STRIP_KEYS.has(plainKey)) {
|
|
329
261
|
if (plainKey === "account_id") {
|
|
330
|
-
collectMetadataExtra(metadataExtras, "
|
|
262
|
+
collectMetadataExtra(metadataExtras, "payment_method_account_id", String(value));
|
|
331
263
|
} else {
|
|
332
264
|
collectMetadataExtra(metadataExtras, plainKey, value);
|
|
333
265
|
}
|
|
334
266
|
continue;
|
|
335
267
|
}
|
|
336
|
-
if (!
|
|
268
|
+
if (!PAYMENT_METHOD_FIELD_WHITELIST.has(plainKey)) {
|
|
337
269
|
collectMetadataExtra(metadataExtras, `payment_method_${plainKey}`, value);
|
|
338
270
|
continue;
|
|
339
271
|
}
|
|
@@ -349,29 +281,29 @@ function normalizeSiftPaymentMethod(raw) {
|
|
|
349
281
|
};
|
|
350
282
|
}
|
|
351
283
|
function mergeAccountIds(target, accountId) {
|
|
352
|
-
const existing = target.
|
|
284
|
+
const existing = target.payment_method_account_ids;
|
|
353
285
|
if (Array.isArray(existing)) {
|
|
354
286
|
existing.push(accountId);
|
|
355
287
|
return;
|
|
356
288
|
}
|
|
357
|
-
if (typeof target.
|
|
358
|
-
target.
|
|
359
|
-
delete target.
|
|
289
|
+
if (typeof target.payment_method_account_id === "string") {
|
|
290
|
+
target.payment_method_account_ids = [target.payment_method_account_id, accountId];
|
|
291
|
+
delete target.payment_method_account_id;
|
|
360
292
|
return;
|
|
361
293
|
}
|
|
362
|
-
target.
|
|
294
|
+
target.payment_method_account_id = accountId;
|
|
363
295
|
}
|
|
364
|
-
function
|
|
296
|
+
function normalizePaymentMethods(methods) {
|
|
365
297
|
if (methods === void 0) return {};
|
|
366
298
|
const normalized = [];
|
|
367
299
|
const metadata = {};
|
|
368
300
|
for (const raw of methods) {
|
|
369
|
-
const result =
|
|
301
|
+
const result = normalizePaymentMethod(raw);
|
|
370
302
|
if (result === null) continue;
|
|
371
303
|
normalized.push(result.method);
|
|
372
304
|
if (result.metadataExtras) {
|
|
373
305
|
for (const [key, value] of Object.entries(result.metadataExtras)) {
|
|
374
|
-
if (key === "
|
|
306
|
+
if (key === "payment_method_account_id" && typeof value === "string") {
|
|
375
307
|
mergeAccountIds(metadata, value);
|
|
376
308
|
} else if (key in metadata && Array.isArray(metadata[key]) && Array.isArray(value)) {
|
|
377
309
|
metadata[key] = [...metadata[key], ...value];
|
|
@@ -388,21 +320,21 @@ function normalizeSiftPaymentMethods(methods) {
|
|
|
388
320
|
};
|
|
389
321
|
}
|
|
390
322
|
|
|
391
|
-
// src/normalization/
|
|
392
|
-
function
|
|
323
|
+
// src/normalization/reserved-keys.ts
|
|
324
|
+
function reservedKey(key) {
|
|
393
325
|
return key.startsWith("$") ? key : `$${key}`;
|
|
394
326
|
}
|
|
395
|
-
function
|
|
327
|
+
function toReservedKeyedObject(value) {
|
|
396
328
|
if (value === null || value === void 0) {
|
|
397
329
|
return value;
|
|
398
330
|
}
|
|
399
331
|
if (Array.isArray(value)) {
|
|
400
|
-
return value.map((item) =>
|
|
332
|
+
return value.map((item) => toReservedKeyedObject(item));
|
|
401
333
|
}
|
|
402
334
|
if (typeof value === "object") {
|
|
403
335
|
const out = {};
|
|
404
336
|
for (const [key, nested] of Object.entries(value)) {
|
|
405
|
-
out[
|
|
337
|
+
out[reservedKey(key)] = toReservedKeyedObject(nested);
|
|
406
338
|
}
|
|
407
339
|
return out;
|
|
408
340
|
}
|
|
@@ -410,12 +342,13 @@ function toSiftKeyedObject(value) {
|
|
|
410
342
|
}
|
|
411
343
|
|
|
412
344
|
// src/normalization/normalize.ts
|
|
413
|
-
var
|
|
345
|
+
var WIRE_USER_REFERENCE_KEY = "sift_user_id";
|
|
346
|
+
var BASE_RESERVED_FIELD_KEYS = [
|
|
414
347
|
"session_id",
|
|
415
348
|
"user_email",
|
|
416
349
|
"name",
|
|
417
350
|
"phone",
|
|
418
|
-
"
|
|
351
|
+
"payment_method_details",
|
|
419
352
|
"payment_methods",
|
|
420
353
|
"billing_address",
|
|
421
354
|
"shipping_address",
|
|
@@ -450,9 +383,9 @@ function createStrippedBody(rest, metadata, stripKeys) {
|
|
|
450
383
|
stripKeys
|
|
451
384
|
);
|
|
452
385
|
}
|
|
453
|
-
function
|
|
454
|
-
if (!onlyWhenNonEmpty || Object.keys(
|
|
455
|
-
body.metadata = mergeMetadata(metadata,
|
|
386
|
+
function applyReservedMetadata(body, metadata, reservedMetadata, onlyWhenNonEmpty = false) {
|
|
387
|
+
if (!onlyWhenNonEmpty || Object.keys(reservedMetadata).length > 0) {
|
|
388
|
+
body.metadata = mergeMetadata(metadata, reservedMetadata);
|
|
456
389
|
}
|
|
457
390
|
return body;
|
|
458
391
|
}
|
|
@@ -466,14 +399,14 @@ function collectRuleSignals(request, keys) {
|
|
|
466
399
|
}
|
|
467
400
|
return signals;
|
|
468
401
|
}
|
|
469
|
-
function
|
|
402
|
+
function buildBaseReservedMetadata(body) {
|
|
470
403
|
const {
|
|
471
404
|
event_type,
|
|
472
405
|
session_id,
|
|
473
406
|
user_email,
|
|
474
407
|
name,
|
|
475
408
|
phone,
|
|
476
|
-
|
|
409
|
+
payment_method_details,
|
|
477
410
|
payment_methods,
|
|
478
411
|
billing_address,
|
|
479
412
|
shipping_address,
|
|
@@ -495,83 +428,90 @@ function buildBaseSiftMetadata(body) {
|
|
|
495
428
|
metadata,
|
|
496
429
|
skip_payment_method_normalization
|
|
497
430
|
} = body;
|
|
498
|
-
const
|
|
431
|
+
const reservedMetadata = {
|
|
499
432
|
...metadata ?? {}
|
|
500
433
|
};
|
|
501
|
-
if (session_id !== void 0)
|
|
502
|
-
if (user_email !== void 0)
|
|
503
|
-
if (name !== void 0)
|
|
504
|
-
if (phone !== void 0)
|
|
505
|
-
if (
|
|
434
|
+
if (session_id !== void 0) reservedMetadata.$session_id = session_id;
|
|
435
|
+
if (user_email !== void 0) reservedMetadata.$user_email = user_email;
|
|
436
|
+
if (name !== void 0) reservedMetadata.$name = name;
|
|
437
|
+
if (phone !== void 0) reservedMetadata.$phone = phone;
|
|
438
|
+
if (payment_method_details !== void 0) {
|
|
506
439
|
if (skip_payment_method_normalization) {
|
|
507
|
-
|
|
440
|
+
reservedMetadata.$payment_method = toReservedKeyedObject(payment_method_details);
|
|
508
441
|
} else {
|
|
509
|
-
const result =
|
|
510
|
-
|
|
442
|
+
const result = normalizePaymentMethod(
|
|
443
|
+
payment_method_details
|
|
511
444
|
);
|
|
512
445
|
if (result !== null) {
|
|
513
|
-
|
|
446
|
+
reservedMetadata.$payment_method = toReservedKeyedObject(result.method);
|
|
514
447
|
if (result.metadataExtras) {
|
|
515
|
-
Object.assign(
|
|
448
|
+
Object.assign(reservedMetadata, result.metadataExtras);
|
|
516
449
|
}
|
|
517
450
|
}
|
|
518
451
|
}
|
|
519
452
|
}
|
|
520
453
|
if (payment_methods !== void 0) {
|
|
521
454
|
if (skip_payment_method_normalization) {
|
|
522
|
-
|
|
455
|
+
reservedMetadata.$payment_methods = toReservedKeyedObject(payment_methods);
|
|
523
456
|
} else {
|
|
524
|
-
const { payment_methods: normalized, metadata: pmMetadata } =
|
|
457
|
+
const { payment_methods: normalized, metadata: pmMetadata } = normalizePaymentMethods(
|
|
525
458
|
payment_methods
|
|
526
459
|
);
|
|
527
460
|
if (normalized !== void 0) {
|
|
528
|
-
|
|
461
|
+
reservedMetadata.$payment_methods = toReservedKeyedObject(normalized);
|
|
529
462
|
}
|
|
530
463
|
if (pmMetadata) {
|
|
531
|
-
Object.assign(
|
|
464
|
+
Object.assign(reservedMetadata, pmMetadata);
|
|
532
465
|
}
|
|
533
466
|
}
|
|
534
467
|
}
|
|
535
468
|
if (billing_address !== void 0) {
|
|
536
|
-
|
|
469
|
+
reservedMetadata.$billing_address = toReservedKeyedObject(billing_address);
|
|
537
470
|
}
|
|
538
471
|
if (shipping_address !== void 0) {
|
|
539
|
-
|
|
472
|
+
reservedMetadata.$shipping_address = toReservedKeyedObject(shipping_address);
|
|
540
473
|
}
|
|
541
|
-
if (app !== void 0)
|
|
474
|
+
if (app !== void 0) reservedMetadata.$app = toReservedKeyedObject(app);
|
|
542
475
|
if (browser !== void 0) {
|
|
543
|
-
|
|
476
|
+
reservedMetadata.$browser = toReservedKeyedObject(browser);
|
|
544
477
|
}
|
|
545
478
|
if (event_type === "$create_order" || event_type === "$update_account") {
|
|
546
479
|
if (verification_phone_number !== void 0) {
|
|
547
|
-
|
|
480
|
+
reservedMetadata.$verification_phone_number = verification_phone_number;
|
|
548
481
|
}
|
|
549
482
|
}
|
|
550
483
|
if (event_type === "$create_order") {
|
|
551
|
-
if (order_id !== void 0)
|
|
552
|
-
if (amount !== void 0)
|
|
553
|
-
if (currency_code !== void 0)
|
|
484
|
+
if (order_id !== void 0) reservedMetadata.$order_id = order_id;
|
|
485
|
+
if (amount !== void 0) reservedMetadata.$amount = amount;
|
|
486
|
+
if (currency_code !== void 0) reservedMetadata.$currency_code = currency_code;
|
|
554
487
|
if (exchange_rate !== void 0) {
|
|
555
|
-
|
|
488
|
+
reservedMetadata.$exchange_rate = toReservedKeyedObject(exchange_rate);
|
|
556
489
|
}
|
|
557
|
-
if (expedited_shipping !== void 0)
|
|
558
|
-
if (shipping_method !== void 0)
|
|
559
|
-
if (shipping_carrier !== void 0)
|
|
490
|
+
if (expedited_shipping !== void 0) reservedMetadata.$expedited_shipping = expedited_shipping;
|
|
491
|
+
if (shipping_method !== void 0) reservedMetadata.$shipping_method = shipping_method;
|
|
492
|
+
if (shipping_carrier !== void 0) reservedMetadata.$shipping_carrier = shipping_carrier;
|
|
560
493
|
if (shipping_tracking_numbers !== void 0) {
|
|
561
|
-
|
|
494
|
+
reservedMetadata.$shipping_tracking_numbers = shipping_tracking_numbers;
|
|
562
495
|
}
|
|
563
|
-
if (brand_name !== void 0)
|
|
564
|
-
if (site_country !== void 0)
|
|
565
|
-
if (site_domain !== void 0)
|
|
566
|
-
if (ip !== void 0)
|
|
496
|
+
if (brand_name !== void 0) reservedMetadata.$brand_name = brand_name;
|
|
497
|
+
if (site_country !== void 0) reservedMetadata.$site_country = site_country;
|
|
498
|
+
if (site_domain !== void 0) reservedMetadata.$site_domain = site_domain;
|
|
499
|
+
if (ip !== void 0) reservedMetadata.$ip = ip;
|
|
567
500
|
}
|
|
568
|
-
return
|
|
501
|
+
return reservedMetadata;
|
|
569
502
|
}
|
|
570
|
-
function
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
503
|
+
function normalizeBaseReservedFields(body) {
|
|
504
|
+
const reservedMetadata = buildBaseReservedMetadata(body);
|
|
505
|
+
if (typeof reservedMetadata.payment_method === "string") {
|
|
506
|
+
reservedMetadata.payment_method = normalizePaymentType(reservedMetadata.payment_method) ?? reservedMetadata.payment_method;
|
|
507
|
+
}
|
|
508
|
+
const stripped = stripSdkOnlyFields(body, [...BASE_RESERVED_FIELD_KEYS]);
|
|
509
|
+
if ("user_reference" in stripped) {
|
|
510
|
+
stripped[WIRE_USER_REFERENCE_KEY] = stripped.user_reference;
|
|
511
|
+
delete stripped.user_reference;
|
|
512
|
+
}
|
|
513
|
+
if (Object.keys(reservedMetadata).length > 0) {
|
|
514
|
+
stripped.metadata = reservedMetadata;
|
|
575
515
|
}
|
|
576
516
|
return stripped;
|
|
577
517
|
}
|
|
@@ -592,12 +532,12 @@ function normalizeUpdatePassword(request) {
|
|
|
592
532
|
"password_reason",
|
|
593
533
|
"password_status"
|
|
594
534
|
]);
|
|
595
|
-
const
|
|
535
|
+
const reservedMetadata = {
|
|
596
536
|
$reason: password_reason ?? PasswordUpdateReason.UserUpdate,
|
|
597
537
|
$status: password_status ?? PasswordUpdateStatus.Success
|
|
598
538
|
};
|
|
599
|
-
body =
|
|
600
|
-
return
|
|
539
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
540
|
+
return normalizeBaseReservedFields(body);
|
|
601
541
|
}
|
|
602
542
|
function normalizeWager(request) {
|
|
603
543
|
const { wager_type, wager_status, wager_event_type, wager_event_name, wager_event_id, metadata, ...rest } = request;
|
|
@@ -608,15 +548,15 @@ function normalizeWager(request) {
|
|
|
608
548
|
"wager_event_name",
|
|
609
549
|
"wager_event_id"
|
|
610
550
|
]);
|
|
611
|
-
const
|
|
551
|
+
const reservedMetadata = {
|
|
612
552
|
$wager_type: wager_type,
|
|
613
553
|
$wager_status: wager_status
|
|
614
554
|
};
|
|
615
|
-
if (wager_event_type)
|
|
616
|
-
if (wager_event_name)
|
|
617
|
-
if (wager_event_id)
|
|
618
|
-
body =
|
|
619
|
-
return
|
|
555
|
+
if (wager_event_type) reservedMetadata.$wager_event_type = wager_event_type;
|
|
556
|
+
if (wager_event_name) reservedMetadata.$wager_event_name = wager_event_name;
|
|
557
|
+
if (wager_event_id) reservedMetadata.$wager_event_id = wager_event_id;
|
|
558
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
559
|
+
return normalizeBaseReservedFields(body);
|
|
620
560
|
}
|
|
621
561
|
function normalizeLogin(request) {
|
|
622
562
|
const { login_status, login_failure_reason, metadata, ...rest } = request;
|
|
@@ -626,20 +566,20 @@ function normalizeLogin(request) {
|
|
|
626
566
|
"login_failure_reason",
|
|
627
567
|
...LOGIN_RULE_SIGNAL_KEYS
|
|
628
568
|
]);
|
|
629
|
-
const
|
|
569
|
+
const reservedMetadata = {
|
|
630
570
|
$login_status: effectiveStatus
|
|
631
571
|
};
|
|
632
572
|
if (effectiveStatus === LoginStatus.Failure && login_failure_reason) {
|
|
633
|
-
|
|
573
|
+
reservedMetadata.$failure_reason = login_failure_reason;
|
|
634
574
|
}
|
|
635
|
-
body =
|
|
575
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
636
576
|
body = applyRuleSignals(
|
|
637
577
|
body,
|
|
638
578
|
request,
|
|
639
579
|
LOGIN_RULE_SIGNAL_KEYS,
|
|
640
580
|
[]
|
|
641
581
|
);
|
|
642
|
-
return
|
|
582
|
+
return normalizeBaseReservedFields(body);
|
|
643
583
|
}
|
|
644
584
|
function normalizeTransaction(request) {
|
|
645
585
|
const { transaction_status, decline_category, transfer_recipient_user_id, metadata, ...rest } = request;
|
|
@@ -649,20 +589,20 @@ function normalizeTransaction(request) {
|
|
|
649
589
|
"transfer_recipient_user_id",
|
|
650
590
|
...TRANSACTION_RULE_SIGNAL_KEYS
|
|
651
591
|
]);
|
|
652
|
-
const
|
|
653
|
-
if (transaction_status)
|
|
654
|
-
if (decline_category)
|
|
592
|
+
const reservedMetadata = {};
|
|
593
|
+
if (transaction_status) reservedMetadata.$transaction_status = transaction_status;
|
|
594
|
+
if (decline_category) reservedMetadata.$decline_category = decline_category;
|
|
655
595
|
if (transfer_recipient_user_id) {
|
|
656
|
-
|
|
596
|
+
reservedMetadata.$transfer_recipient_user_id = transfer_recipient_user_id;
|
|
657
597
|
}
|
|
658
|
-
body =
|
|
598
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata, true);
|
|
659
599
|
body = applyRuleSignals(
|
|
660
600
|
body,
|
|
661
601
|
request,
|
|
662
602
|
TRANSACTION_RULE_SIGNAL_KEYS,
|
|
663
603
|
[]
|
|
664
604
|
);
|
|
665
|
-
return
|
|
605
|
+
return normalizeBaseReservedFields(body);
|
|
666
606
|
}
|
|
667
607
|
function normalizeUpdateAccount(request) {
|
|
668
608
|
const { metadata, ...rest } = request;
|
|
@@ -675,7 +615,7 @@ function normalizeUpdateAccount(request) {
|
|
|
675
615
|
UPDATE_ACCOUNT_RULE_SIGNAL_KEYS,
|
|
676
616
|
[]
|
|
677
617
|
);
|
|
678
|
-
return
|
|
618
|
+
return normalizeBaseReservedFields(body);
|
|
679
619
|
}
|
|
680
620
|
function normalizeCreateOrder(request) {
|
|
681
621
|
const { amount, currency_code, metadata, ...rest } = request;
|
|
@@ -683,15 +623,15 @@ function normalizeCreateOrder(request) {
|
|
|
683
623
|
"amount",
|
|
684
624
|
"currency_code"
|
|
685
625
|
]);
|
|
686
|
-
const
|
|
626
|
+
const reservedMetadata = {
|
|
687
627
|
$amount: amount,
|
|
688
628
|
$currency_code: currency_code
|
|
689
629
|
};
|
|
690
|
-
body =
|
|
691
|
-
return
|
|
630
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
631
|
+
return normalizeBaseReservedFields(body);
|
|
692
632
|
}
|
|
693
633
|
function normalizeDefault(request) {
|
|
694
|
-
return
|
|
634
|
+
return normalizeBaseReservedFields({ ...request });
|
|
695
635
|
}
|
|
696
636
|
function normalizeScoreRequestForApi(request) {
|
|
697
637
|
switch (request.event_type) {
|
|
@@ -749,12 +689,12 @@ function isSupportedFraudEventType(eventType) {
|
|
|
749
689
|
}
|
|
750
690
|
|
|
751
691
|
// src/types/metadata.ts
|
|
752
|
-
var
|
|
692
|
+
var TYPED_METADATA_KEYS = {
|
|
753
693
|
session_id: "$session_id",
|
|
754
694
|
user_email: "$user_email",
|
|
755
695
|
name: "$name",
|
|
756
696
|
phone: "$phone",
|
|
757
|
-
|
|
697
|
+
payment_method_details: "$payment_method",
|
|
758
698
|
billing_address: "$billing_address",
|
|
759
699
|
payment_methods: "$payment_methods",
|
|
760
700
|
app: "$app",
|
|
@@ -773,7 +713,7 @@ var TYPED_SIFT_METADATA_KEYS = {
|
|
|
773
713
|
ip: "$ip"
|
|
774
714
|
};
|
|
775
715
|
function findMetadataConflictWithTypedFields(metadata, request) {
|
|
776
|
-
for (const [field, metaKey] of Object.entries(
|
|
716
|
+
for (const [field, metaKey] of Object.entries(TYPED_METADATA_KEYS)) {
|
|
777
717
|
if (request[field] !== void 0 && metadata[metaKey] !== void 0) {
|
|
778
718
|
return metaKey;
|
|
779
719
|
}
|
|
@@ -828,44 +768,56 @@ function validatePaymentMethods(request, errors, prefix) {
|
|
|
828
768
|
if (skipNormalization) {
|
|
829
769
|
for (const key of Object.keys(raw)) {
|
|
830
770
|
const plainKey = key.startsWith("$") ? key.slice(1) : key;
|
|
831
|
-
if (!
|
|
771
|
+
if (!PAYMENT_METHOD_FIELD_WHITELIST.has(plainKey)) {
|
|
832
772
|
errors.push(
|
|
833
|
-
`${prefix}payment_methods[${index}].${plainKey} is not a
|
|
773
|
+
`${prefix}payment_methods[${index}].${plainKey} is not a recognized payment method field`
|
|
834
774
|
);
|
|
835
775
|
}
|
|
836
776
|
}
|
|
837
777
|
const rawType2 = raw.payment_type !== void 0 ? String(raw.payment_type) : void 0;
|
|
838
|
-
if (rawType2 !== void 0 &&
|
|
778
|
+
if (rawType2 !== void 0 && normalizePaymentType(rawType2) === void 0) {
|
|
839
779
|
errors.push(
|
|
840
|
-
`${prefix}payment_methods[${index}].payment_type is not a
|
|
780
|
+
`${prefix}payment_methods[${index}].payment_type is not a recognized payment type`
|
|
841
781
|
);
|
|
842
782
|
}
|
|
843
783
|
return;
|
|
844
784
|
}
|
|
845
785
|
const rawType = raw.payment_type !== void 0 ? String(raw.payment_type) : raw.$payment_type !== void 0 ? String(raw.$payment_type) : void 0;
|
|
846
786
|
if (rawType !== void 0) {
|
|
847
|
-
const result =
|
|
787
|
+
const result = normalizePaymentMethod(raw);
|
|
848
788
|
if (result === null) {
|
|
849
789
|
errors.push(
|
|
850
|
-
`${prefix}payment_methods[${index}].payment_type is not a
|
|
790
|
+
`${prefix}payment_methods[${index}].payment_type is not a recognized payment type`
|
|
851
791
|
);
|
|
852
792
|
}
|
|
853
793
|
}
|
|
854
794
|
});
|
|
855
795
|
}
|
|
796
|
+
function validatePaymentMethodSignal(value, field, errors, prefix) {
|
|
797
|
+
if (value === void 0) return;
|
|
798
|
+
if (typeof value !== "string" || normalizePaymentType(value) === void 0) {
|
|
799
|
+
errors.push(`${prefix}${field} is not a recognized payment type`);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
856
802
|
function validateBase(request, errors, prefix) {
|
|
857
803
|
assertNonEmpty(request.customer_id, "customer_id", errors, prefix);
|
|
858
|
-
assertNonEmpty(request.
|
|
804
|
+
assertNonEmpty(request.user_reference, "user_reference", errors, prefix);
|
|
859
805
|
assertNonEmpty(request.event_type, "event_type", errors, prefix);
|
|
860
806
|
validateMetadata(request.metadata, request, errors, prefix);
|
|
807
|
+
validatePaymentMethodSignal(
|
|
808
|
+
request.metadata?.payment_method,
|
|
809
|
+
"metadata.payment_method",
|
|
810
|
+
errors,
|
|
811
|
+
prefix
|
|
812
|
+
);
|
|
861
813
|
}
|
|
862
814
|
function validateLogin(request, errors, prefix) {
|
|
863
|
-
assertEnum(request.login_status,
|
|
815
|
+
assertEnum(request.login_status, LoginStatusValues, "login_status", errors, prefix);
|
|
864
816
|
if (request.login_failure_reason !== void 0) {
|
|
865
817
|
if (request.login_status === "$failure") {
|
|
866
818
|
assertEnum(
|
|
867
819
|
request.login_failure_reason,
|
|
868
|
-
|
|
820
|
+
LoginFailureReasonValues,
|
|
869
821
|
"login_failure_reason",
|
|
870
822
|
errors,
|
|
871
823
|
prefix
|
|
@@ -878,14 +830,14 @@ function validateLogin(request, errors, prefix) {
|
|
|
878
830
|
function validateUpdatePassword(request, errors, prefix) {
|
|
879
831
|
assertEnum(
|
|
880
832
|
request.password_reason,
|
|
881
|
-
|
|
833
|
+
PasswordUpdateReasonValues,
|
|
882
834
|
"password_reason",
|
|
883
835
|
errors,
|
|
884
836
|
prefix
|
|
885
837
|
);
|
|
886
838
|
assertEnum(
|
|
887
839
|
request.password_status,
|
|
888
|
-
|
|
840
|
+
PasswordUpdateStatusValues,
|
|
889
841
|
"password_status",
|
|
890
842
|
errors,
|
|
891
843
|
prefix
|
|
@@ -894,14 +846,15 @@ function validateUpdatePassword(request, errors, prefix) {
|
|
|
894
846
|
function validateTransaction(request, errors, prefix) {
|
|
895
847
|
assertPositiveAmount(request.amount, "amount", errors, prefix);
|
|
896
848
|
assertNonEmpty(request.currency, "currency", errors, prefix);
|
|
897
|
-
assertEnum(request.transaction_type,
|
|
849
|
+
assertEnum(request.transaction_type, TransactionTypeValues, "transaction_type", errors, prefix);
|
|
898
850
|
assertEnum(
|
|
899
851
|
request.transaction_status,
|
|
900
|
-
|
|
852
|
+
TransactionStatusValues,
|
|
901
853
|
"transaction_status",
|
|
902
854
|
errors,
|
|
903
855
|
prefix
|
|
904
856
|
);
|
|
857
|
+
validatePaymentMethodSignal(request.payment_method, "payment_method", errors, prefix);
|
|
905
858
|
if (request.decline_category !== void 0 && request.transaction_status !== "$failure") {
|
|
906
859
|
errors.push(
|
|
907
860
|
`${prefix}decline_category is only allowed when transaction_status is '$failure'`
|
|
@@ -916,7 +869,7 @@ function validateTransaction(request, errors, prefix) {
|
|
|
916
869
|
function validateWager(request, errors, prefix) {
|
|
917
870
|
assertNonEmpty(request.transaction_id, "transaction_id", errors, prefix);
|
|
918
871
|
assertNonEmpty(request.wager_type, "wager_type", errors, prefix);
|
|
919
|
-
assertEnum(request.wager_status,
|
|
872
|
+
assertEnum(request.wager_status, WagerStatusValues, "wager_status", errors, prefix);
|
|
920
873
|
if (!request.wager_status) {
|
|
921
874
|
errors.push(`${prefix}wager_status is required`);
|
|
922
875
|
}
|
|
@@ -951,10 +904,10 @@ function validateChargeback(request, errors, prefix) {
|
|
|
951
904
|
if (!hasTransactionId && !hasOrderId) {
|
|
952
905
|
errors.push(`${prefix}transaction_id or order_id is required`);
|
|
953
906
|
}
|
|
954
|
-
assertEnum(request.chargeback_state,
|
|
907
|
+
assertEnum(request.chargeback_state, ChargebackStateValues, "chargeback_state", errors, prefix);
|
|
955
908
|
assertEnum(
|
|
956
909
|
request.chargeback_reason,
|
|
957
|
-
|
|
910
|
+
ChargebackReasonValues,
|
|
958
911
|
"chargeback_reason",
|
|
959
912
|
errors,
|
|
960
913
|
prefix
|
|
@@ -1060,6 +1013,6 @@ function isFraudAlertCallbackEvent(value) {
|
|
|
1060
1013
|
return typeof value === "object" && value !== null && value.event_type === "fraud.alert.callback";
|
|
1061
1014
|
}
|
|
1062
1015
|
|
|
1063
|
-
export { CHARGEBACK_FRAUD_EVENT_TYPE, ChargebackReason,
|
|
1016
|
+
export { CHARGEBACK_FRAUD_EVENT_TYPE, ChargebackReason, ChargebackReasonValues, ChargebackState, ChargebackStateValues, FraudClient, LOGIN_RULE_SIGNAL_KEYS, LoginFailureReasonValues, LoginStatus, LoginStatusValues, PLANNED_FRAUD_EVENT_TYPES, PasswordUpdateReason, PasswordUpdateReasonValues, PasswordUpdateStatus, PasswordUpdateStatusValues, PaymentType, PaymentTypeValues, SCORED_FRAUD_EVENT_TYPES, SUPPORTED_FRAUD_EVENT_TYPES, TRANSACTION_RULE_SIGNAL_KEYS, TYPED_METADATA_KEYS, TransactionStatus, TransactionStatusValues, TransactionType, TransactionTypeValues, UPDATE_ACCOUNT_RULE_SIGNAL_KEYS, WagerStatus, WagerStatusValues, WalletType, WalletTypeValues, buildScoreRequestPreview, findMetadataConflictWithTypedFields, isFraudAlertCallbackEvent, isPlannedFraudEventType, isSupportedFraudEventType, normalizePaymentMethod, normalizePaymentMethods, normalizeScoreRequestForApi, toAccountNumberLast5, validateScoreRequest };
|
|
1064
1017
|
//# sourceMappingURL=index.mjs.map
|
|
1065
1018
|
//# sourceMappingURL=index.mjs.map
|