@vesant-sdk/fraud 0.1.3-next.ec7157c → 0.2.0-dev.0520b46
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 +20 -20
- package/dist/index.d.mts +77 -77
- package/dist/index.d.ts +77 -77
- package/dist/index.js +150 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { ValidationError, BaseClient } from '@vesant-sdk/core';
|
|
|
3
3
|
// src/client.ts
|
|
4
4
|
|
|
5
5
|
// src/types/enums.ts
|
|
6
|
-
var
|
|
6
|
+
var TransactionTypeValues = [
|
|
7
7
|
"$sale",
|
|
8
8
|
"$authorize",
|
|
9
9
|
"$capture",
|
|
@@ -31,7 +31,7 @@ var TransactionType = {
|
|
|
31
31
|
Send: "$send",
|
|
32
32
|
Receive: "$receive"
|
|
33
33
|
};
|
|
34
|
-
var
|
|
34
|
+
var ChargebackStateValues = [
|
|
35
35
|
"$received",
|
|
36
36
|
"$accepted",
|
|
37
37
|
"$disputed",
|
|
@@ -45,7 +45,7 @@ var ChargebackState = {
|
|
|
45
45
|
Won: "$won",
|
|
46
46
|
Lost: "$lost"
|
|
47
47
|
};
|
|
48
|
-
var
|
|
48
|
+
var ChargebackReasonValues = [
|
|
49
49
|
"$fraud",
|
|
50
50
|
"$duplicate",
|
|
51
51
|
"$product_not_received",
|
|
@@ -73,28 +73,28 @@ var ChargebackReason = {
|
|
|
73
73
|
AchReversal: "$ach_reversal",
|
|
74
74
|
Other: "$other"
|
|
75
75
|
};
|
|
76
|
-
var
|
|
76
|
+
var LoginStatusValues = ["$success", "$failure"];
|
|
77
77
|
var LoginStatus = {
|
|
78
78
|
Success: "$success",
|
|
79
79
|
Failure: "$failure"
|
|
80
80
|
};
|
|
81
|
-
var
|
|
81
|
+
var LoginFailureReasonValues = [
|
|
82
82
|
"$account_unknown",
|
|
83
83
|
"$account_suspended",
|
|
84
84
|
"$account_disabled",
|
|
85
85
|
"$wrong_password"
|
|
86
86
|
];
|
|
87
|
-
var
|
|
87
|
+
var PasswordUpdateReasonValues = [
|
|
88
88
|
"$user_update",
|
|
89
89
|
"$forgot_password",
|
|
90
90
|
"$forced_reset"
|
|
91
91
|
];
|
|
92
92
|
var PasswordUpdateReason = {
|
|
93
|
-
UserUpdate:
|
|
94
|
-
ForgotPassword:
|
|
95
|
-
ForcedReset:
|
|
93
|
+
UserUpdate: PasswordUpdateReasonValues[0],
|
|
94
|
+
ForgotPassword: PasswordUpdateReasonValues[1],
|
|
95
|
+
ForcedReset: PasswordUpdateReasonValues[2]
|
|
96
96
|
};
|
|
97
|
-
var
|
|
97
|
+
var PasswordUpdateStatusValues = [
|
|
98
98
|
"$pending",
|
|
99
99
|
"$success",
|
|
100
100
|
"$failure"
|
|
@@ -104,12 +104,12 @@ var PasswordUpdateStatus = {
|
|
|
104
104
|
Success: "$success",
|
|
105
105
|
Failure: "$failure"
|
|
106
106
|
};
|
|
107
|
-
var
|
|
107
|
+
var WagerStatusValues = ["$accept", "$cancel"];
|
|
108
108
|
var WagerStatus = {
|
|
109
109
|
Accept: "$accept",
|
|
110
110
|
Cancel: "$cancel"
|
|
111
111
|
};
|
|
112
|
-
var
|
|
112
|
+
var TransactionStatusValues = [
|
|
113
113
|
"$success",
|
|
114
114
|
"$failure",
|
|
115
115
|
"$pending"
|
|
@@ -119,7 +119,7 @@ var TransactionStatus = {
|
|
|
119
119
|
Failure: "$failure",
|
|
120
120
|
Pending: "$pending"
|
|
121
121
|
};
|
|
122
|
-
var
|
|
122
|
+
var PaymentTypeValues = [
|
|
123
123
|
"$cash",
|
|
124
124
|
"$check",
|
|
125
125
|
"$credit_card",
|
|
@@ -171,7 +171,7 @@ var PaymentType = {
|
|
|
171
171
|
WireCredit: "$wire_credit",
|
|
172
172
|
WireDebit: "$wire_debit"
|
|
173
173
|
};
|
|
174
|
-
var
|
|
174
|
+
var WalletTypeValues = ["$crypto", "$digital", "$fiat"];
|
|
175
175
|
var WalletType = {
|
|
176
176
|
Crypto: "$crypto",
|
|
177
177
|
Digital: "$digital",
|
|
@@ -228,7 +228,7 @@ var PAYMENT_TYPE_ALIASES = {
|
|
|
228
228
|
wire_credit: "$wire_credit",
|
|
229
229
|
wire_debit: "$wire_debit"
|
|
230
230
|
};
|
|
231
|
-
var
|
|
231
|
+
var PAYMENT_METHOD_FIELD_WHITELIST = /* @__PURE__ */ new Set([
|
|
232
232
|
"payment_type",
|
|
233
233
|
"payment_gateway",
|
|
234
234
|
"card_bin",
|
|
@@ -265,18 +265,18 @@ function isDevEnvironment() {
|
|
|
265
265
|
function warnDeprecatedKey(key) {
|
|
266
266
|
if (!isDevEnvironment()) return;
|
|
267
267
|
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
|
|
268
|
+
account_number_last4: "[vesant-sdk/fraud] account_number_last4 is not a recognized field; use account_number_last5",
|
|
269
|
+
account_id: "[vesant-sdk/fraud] account_id is not a recognized field; moved to metadata",
|
|
270
|
+
wallet_address_last4: "[vesant-sdk/fraud] wallet_address_last4 is not a recognized field; moved to metadata",
|
|
271
|
+
crypto_currency: "[vesant-sdk/fraud] crypto_currency is not a recognized field on payment_method; moved to metadata",
|
|
272
|
+
network: "[vesant-sdk/fraud] network is not a recognized field on payment_method; moved to metadata"
|
|
273
273
|
};
|
|
274
274
|
const message = messages[key];
|
|
275
275
|
if (message) {
|
|
276
276
|
console.warn(message);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
function
|
|
279
|
+
function normalizePaymentType(value) {
|
|
280
280
|
if (value === void 0 || value === null) return void 0;
|
|
281
281
|
const trimmed = String(value).trim();
|
|
282
282
|
if (trimmed === "") return void 0;
|
|
@@ -284,12 +284,12 @@ function normalizeSiftPaymentType(value) {
|
|
|
284
284
|
const alias = PAYMENT_TYPE_ALIASES[normalized.toLowerCase()];
|
|
285
285
|
if (alias) return alias;
|
|
286
286
|
const withPrefix = `$${normalized}`;
|
|
287
|
-
if (
|
|
287
|
+
if (PaymentTypeValues.includes(withPrefix)) {
|
|
288
288
|
return withPrefix;
|
|
289
289
|
}
|
|
290
290
|
return void 0;
|
|
291
291
|
}
|
|
292
|
-
function
|
|
292
|
+
function toAccountNumberLast5(value) {
|
|
293
293
|
if (value === void 0 || value === null) return void 0;
|
|
294
294
|
const digits = String(value).replace(/\D/g, "");
|
|
295
295
|
if (digits.length === 0) return void 0;
|
|
@@ -300,11 +300,11 @@ function collectMetadataExtra(metadataExtras, key, value) {
|
|
|
300
300
|
if (value === void 0) return;
|
|
301
301
|
metadataExtras[key] = value;
|
|
302
302
|
}
|
|
303
|
-
function
|
|
303
|
+
function normalizePaymentMethod(raw) {
|
|
304
304
|
const metadataExtras = {};
|
|
305
305
|
const method = {};
|
|
306
306
|
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 =
|
|
307
|
+
const normalizedType = normalizePaymentType(rawPaymentType);
|
|
308
308
|
if (rawPaymentType !== void 0 && normalizedType === void 0) {
|
|
309
309
|
return null;
|
|
310
310
|
}
|
|
@@ -316,7 +316,7 @@ function normalizeSiftPaymentMethod(raw) {
|
|
|
316
316
|
}
|
|
317
317
|
const accountLast4 = raw.account_number_last4 ?? raw.$account_number_last4;
|
|
318
318
|
const accountLast5 = raw.account_number_last5 ?? raw.$account_number_last5;
|
|
319
|
-
const resolvedLast5 =
|
|
319
|
+
const resolvedLast5 = toAccountNumberLast5(accountLast5 ?? accountLast4);
|
|
320
320
|
if (resolvedLast5 !== void 0) {
|
|
321
321
|
method.account_number_last5 = resolvedLast5;
|
|
322
322
|
}
|
|
@@ -327,13 +327,13 @@ function normalizeSiftPaymentMethod(raw) {
|
|
|
327
327
|
const plainKey = key.startsWith("$") ? key.slice(1) : key;
|
|
328
328
|
if (METADATA_STRIP_KEYS.has(plainKey)) {
|
|
329
329
|
if (plainKey === "account_id") {
|
|
330
|
-
collectMetadataExtra(metadataExtras, "
|
|
330
|
+
collectMetadataExtra(metadataExtras, "payment_method_account_id", String(value));
|
|
331
331
|
} else {
|
|
332
332
|
collectMetadataExtra(metadataExtras, plainKey, value);
|
|
333
333
|
}
|
|
334
334
|
continue;
|
|
335
335
|
}
|
|
336
|
-
if (!
|
|
336
|
+
if (!PAYMENT_METHOD_FIELD_WHITELIST.has(plainKey)) {
|
|
337
337
|
collectMetadataExtra(metadataExtras, `payment_method_${plainKey}`, value);
|
|
338
338
|
continue;
|
|
339
339
|
}
|
|
@@ -349,29 +349,29 @@ function normalizeSiftPaymentMethod(raw) {
|
|
|
349
349
|
};
|
|
350
350
|
}
|
|
351
351
|
function mergeAccountIds(target, accountId) {
|
|
352
|
-
const existing = target.
|
|
352
|
+
const existing = target.payment_method_account_ids;
|
|
353
353
|
if (Array.isArray(existing)) {
|
|
354
354
|
existing.push(accountId);
|
|
355
355
|
return;
|
|
356
356
|
}
|
|
357
|
-
if (typeof target.
|
|
358
|
-
target.
|
|
359
|
-
delete target.
|
|
357
|
+
if (typeof target.payment_method_account_id === "string") {
|
|
358
|
+
target.payment_method_account_ids = [target.payment_method_account_id, accountId];
|
|
359
|
+
delete target.payment_method_account_id;
|
|
360
360
|
return;
|
|
361
361
|
}
|
|
362
|
-
target.
|
|
362
|
+
target.payment_method_account_id = accountId;
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function normalizePaymentMethods(methods) {
|
|
365
365
|
if (methods === void 0) return {};
|
|
366
366
|
const normalized = [];
|
|
367
367
|
const metadata = {};
|
|
368
368
|
for (const raw of methods) {
|
|
369
|
-
const result =
|
|
369
|
+
const result = normalizePaymentMethod(raw);
|
|
370
370
|
if (result === null) continue;
|
|
371
371
|
normalized.push(result.method);
|
|
372
372
|
if (result.metadataExtras) {
|
|
373
373
|
for (const [key, value] of Object.entries(result.metadataExtras)) {
|
|
374
|
-
if (key === "
|
|
374
|
+
if (key === "payment_method_account_id" && typeof value === "string") {
|
|
375
375
|
mergeAccountIds(metadata, value);
|
|
376
376
|
} else if (key in metadata && Array.isArray(metadata[key]) && Array.isArray(value)) {
|
|
377
377
|
metadata[key] = [...metadata[key], ...value];
|
|
@@ -388,21 +388,21 @@ function normalizeSiftPaymentMethods(methods) {
|
|
|
388
388
|
};
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
// src/normalization/
|
|
392
|
-
function
|
|
391
|
+
// src/normalization/reserved-keys.ts
|
|
392
|
+
function reservedKey(key) {
|
|
393
393
|
return key.startsWith("$") ? key : `$${key}`;
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function toReservedKeyedObject(value) {
|
|
396
396
|
if (value === null || value === void 0) {
|
|
397
397
|
return value;
|
|
398
398
|
}
|
|
399
399
|
if (Array.isArray(value)) {
|
|
400
|
-
return value.map((item) =>
|
|
400
|
+
return value.map((item) => toReservedKeyedObject(item));
|
|
401
401
|
}
|
|
402
402
|
if (typeof value === "object") {
|
|
403
403
|
const out = {};
|
|
404
404
|
for (const [key, nested] of Object.entries(value)) {
|
|
405
|
-
out[
|
|
405
|
+
out[reservedKey(key)] = toReservedKeyedObject(nested);
|
|
406
406
|
}
|
|
407
407
|
return out;
|
|
408
408
|
}
|
|
@@ -410,12 +410,13 @@ function toSiftKeyedObject(value) {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
// src/normalization/normalize.ts
|
|
413
|
-
var
|
|
413
|
+
var WIRE_USER_REFERENCE_KEY = "sift_user_id";
|
|
414
|
+
var BASE_RESERVED_FIELD_KEYS = [
|
|
414
415
|
"session_id",
|
|
415
416
|
"user_email",
|
|
416
417
|
"name",
|
|
417
418
|
"phone",
|
|
418
|
-
"
|
|
419
|
+
"payment_method_details",
|
|
419
420
|
"payment_methods",
|
|
420
421
|
"billing_address",
|
|
421
422
|
"shipping_address",
|
|
@@ -450,9 +451,9 @@ function createStrippedBody(rest, metadata, stripKeys) {
|
|
|
450
451
|
stripKeys
|
|
451
452
|
);
|
|
452
453
|
}
|
|
453
|
-
function
|
|
454
|
-
if (!onlyWhenNonEmpty || Object.keys(
|
|
455
|
-
body.metadata = mergeMetadata(metadata,
|
|
454
|
+
function applyReservedMetadata(body, metadata, reservedMetadata, onlyWhenNonEmpty = false) {
|
|
455
|
+
if (!onlyWhenNonEmpty || Object.keys(reservedMetadata).length > 0) {
|
|
456
|
+
body.metadata = mergeMetadata(metadata, reservedMetadata);
|
|
456
457
|
}
|
|
457
458
|
return body;
|
|
458
459
|
}
|
|
@@ -466,14 +467,14 @@ function collectRuleSignals(request, keys) {
|
|
|
466
467
|
}
|
|
467
468
|
return signals;
|
|
468
469
|
}
|
|
469
|
-
function
|
|
470
|
+
function buildBaseReservedMetadata(body) {
|
|
470
471
|
const {
|
|
471
472
|
event_type,
|
|
472
473
|
session_id,
|
|
473
474
|
user_email,
|
|
474
475
|
name,
|
|
475
476
|
phone,
|
|
476
|
-
|
|
477
|
+
payment_method_details,
|
|
477
478
|
payment_methods,
|
|
478
479
|
billing_address,
|
|
479
480
|
shipping_address,
|
|
@@ -495,83 +496,87 @@ function buildBaseSiftMetadata(body) {
|
|
|
495
496
|
metadata,
|
|
496
497
|
skip_payment_method_normalization
|
|
497
498
|
} = body;
|
|
498
|
-
const
|
|
499
|
+
const reservedMetadata = {
|
|
499
500
|
...metadata ?? {}
|
|
500
501
|
};
|
|
501
|
-
if (session_id !== void 0)
|
|
502
|
-
if (user_email !== void 0)
|
|
503
|
-
if (name !== void 0)
|
|
504
|
-
if (phone !== void 0)
|
|
505
|
-
if (
|
|
502
|
+
if (session_id !== void 0) reservedMetadata.$session_id = session_id;
|
|
503
|
+
if (user_email !== void 0) reservedMetadata.$user_email = user_email;
|
|
504
|
+
if (name !== void 0) reservedMetadata.$name = name;
|
|
505
|
+
if (phone !== void 0) reservedMetadata.$phone = phone;
|
|
506
|
+
if (payment_method_details !== void 0) {
|
|
506
507
|
if (skip_payment_method_normalization) {
|
|
507
|
-
|
|
508
|
+
reservedMetadata.$payment_method = toReservedKeyedObject(payment_method_details);
|
|
508
509
|
} else {
|
|
509
|
-
const result =
|
|
510
|
-
|
|
510
|
+
const result = normalizePaymentMethod(
|
|
511
|
+
payment_method_details
|
|
511
512
|
);
|
|
512
513
|
if (result !== null) {
|
|
513
|
-
|
|
514
|
+
reservedMetadata.$payment_method = toReservedKeyedObject(result.method);
|
|
514
515
|
if (result.metadataExtras) {
|
|
515
|
-
Object.assign(
|
|
516
|
+
Object.assign(reservedMetadata, result.metadataExtras);
|
|
516
517
|
}
|
|
517
518
|
}
|
|
518
519
|
}
|
|
519
520
|
}
|
|
520
521
|
if (payment_methods !== void 0) {
|
|
521
522
|
if (skip_payment_method_normalization) {
|
|
522
|
-
|
|
523
|
+
reservedMetadata.$payment_methods = toReservedKeyedObject(payment_methods);
|
|
523
524
|
} else {
|
|
524
|
-
const { payment_methods: normalized, metadata: pmMetadata } =
|
|
525
|
+
const { payment_methods: normalized, metadata: pmMetadata } = normalizePaymentMethods(
|
|
525
526
|
payment_methods
|
|
526
527
|
);
|
|
527
528
|
if (normalized !== void 0) {
|
|
528
|
-
|
|
529
|
+
reservedMetadata.$payment_methods = toReservedKeyedObject(normalized);
|
|
529
530
|
}
|
|
530
531
|
if (pmMetadata) {
|
|
531
|
-
Object.assign(
|
|
532
|
+
Object.assign(reservedMetadata, pmMetadata);
|
|
532
533
|
}
|
|
533
534
|
}
|
|
534
535
|
}
|
|
535
536
|
if (billing_address !== void 0) {
|
|
536
|
-
|
|
537
|
+
reservedMetadata.$billing_address = toReservedKeyedObject(billing_address);
|
|
537
538
|
}
|
|
538
539
|
if (shipping_address !== void 0) {
|
|
539
|
-
|
|
540
|
+
reservedMetadata.$shipping_address = toReservedKeyedObject(shipping_address);
|
|
540
541
|
}
|
|
541
|
-
if (app !== void 0)
|
|
542
|
+
if (app !== void 0) reservedMetadata.$app = toReservedKeyedObject(app);
|
|
542
543
|
if (browser !== void 0) {
|
|
543
|
-
|
|
544
|
+
reservedMetadata.$browser = toReservedKeyedObject(browser);
|
|
544
545
|
}
|
|
545
546
|
if (event_type === "$create_order" || event_type === "$update_account") {
|
|
546
547
|
if (verification_phone_number !== void 0) {
|
|
547
|
-
|
|
548
|
+
reservedMetadata.$verification_phone_number = verification_phone_number;
|
|
548
549
|
}
|
|
549
550
|
}
|
|
550
551
|
if (event_type === "$create_order") {
|
|
551
|
-
if (order_id !== void 0)
|
|
552
|
-
if (amount !== void 0)
|
|
553
|
-
if (currency_code !== void 0)
|
|
552
|
+
if (order_id !== void 0) reservedMetadata.$order_id = order_id;
|
|
553
|
+
if (amount !== void 0) reservedMetadata.$amount = amount;
|
|
554
|
+
if (currency_code !== void 0) reservedMetadata.$currency_code = currency_code;
|
|
554
555
|
if (exchange_rate !== void 0) {
|
|
555
|
-
|
|
556
|
+
reservedMetadata.$exchange_rate = toReservedKeyedObject(exchange_rate);
|
|
556
557
|
}
|
|
557
|
-
if (expedited_shipping !== void 0)
|
|
558
|
-
if (shipping_method !== void 0)
|
|
559
|
-
if (shipping_carrier !== void 0)
|
|
558
|
+
if (expedited_shipping !== void 0) reservedMetadata.$expedited_shipping = expedited_shipping;
|
|
559
|
+
if (shipping_method !== void 0) reservedMetadata.$shipping_method = shipping_method;
|
|
560
|
+
if (shipping_carrier !== void 0) reservedMetadata.$shipping_carrier = shipping_carrier;
|
|
560
561
|
if (shipping_tracking_numbers !== void 0) {
|
|
561
|
-
|
|
562
|
+
reservedMetadata.$shipping_tracking_numbers = shipping_tracking_numbers;
|
|
562
563
|
}
|
|
563
|
-
if (brand_name !== void 0)
|
|
564
|
-
if (site_country !== void 0)
|
|
565
|
-
if (site_domain !== void 0)
|
|
566
|
-
if (ip !== void 0)
|
|
564
|
+
if (brand_name !== void 0) reservedMetadata.$brand_name = brand_name;
|
|
565
|
+
if (site_country !== void 0) reservedMetadata.$site_country = site_country;
|
|
566
|
+
if (site_domain !== void 0) reservedMetadata.$site_domain = site_domain;
|
|
567
|
+
if (ip !== void 0) reservedMetadata.$ip = ip;
|
|
567
568
|
}
|
|
568
|
-
return
|
|
569
|
+
return reservedMetadata;
|
|
569
570
|
}
|
|
570
|
-
function
|
|
571
|
-
const
|
|
572
|
-
const stripped = stripSdkOnlyFields(body, [...
|
|
573
|
-
if (
|
|
574
|
-
stripped
|
|
571
|
+
function normalizeBaseReservedFields(body) {
|
|
572
|
+
const reservedMetadata = buildBaseReservedMetadata(body);
|
|
573
|
+
const stripped = stripSdkOnlyFields(body, [...BASE_RESERVED_FIELD_KEYS]);
|
|
574
|
+
if ("user_reference" in stripped) {
|
|
575
|
+
stripped[WIRE_USER_REFERENCE_KEY] = stripped.user_reference;
|
|
576
|
+
delete stripped.user_reference;
|
|
577
|
+
}
|
|
578
|
+
if (Object.keys(reservedMetadata).length > 0) {
|
|
579
|
+
stripped.metadata = reservedMetadata;
|
|
575
580
|
}
|
|
576
581
|
return stripped;
|
|
577
582
|
}
|
|
@@ -592,12 +597,12 @@ function normalizeUpdatePassword(request) {
|
|
|
592
597
|
"password_reason",
|
|
593
598
|
"password_status"
|
|
594
599
|
]);
|
|
595
|
-
const
|
|
600
|
+
const reservedMetadata = {
|
|
596
601
|
$reason: password_reason ?? PasswordUpdateReason.UserUpdate,
|
|
597
602
|
$status: password_status ?? PasswordUpdateStatus.Success
|
|
598
603
|
};
|
|
599
|
-
body =
|
|
600
|
-
return
|
|
604
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
605
|
+
return normalizeBaseReservedFields(body);
|
|
601
606
|
}
|
|
602
607
|
function normalizeWager(request) {
|
|
603
608
|
const { wager_type, wager_status, wager_event_type, wager_event_name, wager_event_id, metadata, ...rest } = request;
|
|
@@ -608,15 +613,15 @@ function normalizeWager(request) {
|
|
|
608
613
|
"wager_event_name",
|
|
609
614
|
"wager_event_id"
|
|
610
615
|
]);
|
|
611
|
-
const
|
|
616
|
+
const reservedMetadata = {
|
|
612
617
|
$wager_type: wager_type,
|
|
613
618
|
$wager_status: wager_status
|
|
614
619
|
};
|
|
615
|
-
if (wager_event_type)
|
|
616
|
-
if (wager_event_name)
|
|
617
|
-
if (wager_event_id)
|
|
618
|
-
body =
|
|
619
|
-
return
|
|
620
|
+
if (wager_event_type) reservedMetadata.$wager_event_type = wager_event_type;
|
|
621
|
+
if (wager_event_name) reservedMetadata.$wager_event_name = wager_event_name;
|
|
622
|
+
if (wager_event_id) reservedMetadata.$wager_event_id = wager_event_id;
|
|
623
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
624
|
+
return normalizeBaseReservedFields(body);
|
|
620
625
|
}
|
|
621
626
|
function normalizeLogin(request) {
|
|
622
627
|
const { login_status, login_failure_reason, metadata, ...rest } = request;
|
|
@@ -626,20 +631,20 @@ function normalizeLogin(request) {
|
|
|
626
631
|
"login_failure_reason",
|
|
627
632
|
...LOGIN_RULE_SIGNAL_KEYS
|
|
628
633
|
]);
|
|
629
|
-
const
|
|
634
|
+
const reservedMetadata = {
|
|
630
635
|
$login_status: effectiveStatus
|
|
631
636
|
};
|
|
632
637
|
if (effectiveStatus === LoginStatus.Failure && login_failure_reason) {
|
|
633
|
-
|
|
638
|
+
reservedMetadata.$failure_reason = login_failure_reason;
|
|
634
639
|
}
|
|
635
|
-
body =
|
|
640
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
636
641
|
body = applyRuleSignals(
|
|
637
642
|
body,
|
|
638
643
|
request,
|
|
639
644
|
LOGIN_RULE_SIGNAL_KEYS,
|
|
640
645
|
[]
|
|
641
646
|
);
|
|
642
|
-
return
|
|
647
|
+
return normalizeBaseReservedFields(body);
|
|
643
648
|
}
|
|
644
649
|
function normalizeTransaction(request) {
|
|
645
650
|
const { transaction_status, decline_category, transfer_recipient_user_id, metadata, ...rest } = request;
|
|
@@ -649,20 +654,20 @@ function normalizeTransaction(request) {
|
|
|
649
654
|
"transfer_recipient_user_id",
|
|
650
655
|
...TRANSACTION_RULE_SIGNAL_KEYS
|
|
651
656
|
]);
|
|
652
|
-
const
|
|
653
|
-
if (transaction_status)
|
|
654
|
-
if (decline_category)
|
|
657
|
+
const reservedMetadata = {};
|
|
658
|
+
if (transaction_status) reservedMetadata.$transaction_status = transaction_status;
|
|
659
|
+
if (decline_category) reservedMetadata.$decline_category = decline_category;
|
|
655
660
|
if (transfer_recipient_user_id) {
|
|
656
|
-
|
|
661
|
+
reservedMetadata.$transfer_recipient_user_id = transfer_recipient_user_id;
|
|
657
662
|
}
|
|
658
|
-
body =
|
|
663
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata, true);
|
|
659
664
|
body = applyRuleSignals(
|
|
660
665
|
body,
|
|
661
666
|
request,
|
|
662
667
|
TRANSACTION_RULE_SIGNAL_KEYS,
|
|
663
668
|
[]
|
|
664
669
|
);
|
|
665
|
-
return
|
|
670
|
+
return normalizeBaseReservedFields(body);
|
|
666
671
|
}
|
|
667
672
|
function normalizeUpdateAccount(request) {
|
|
668
673
|
const { metadata, ...rest } = request;
|
|
@@ -675,7 +680,7 @@ function normalizeUpdateAccount(request) {
|
|
|
675
680
|
UPDATE_ACCOUNT_RULE_SIGNAL_KEYS,
|
|
676
681
|
[]
|
|
677
682
|
);
|
|
678
|
-
return
|
|
683
|
+
return normalizeBaseReservedFields(body);
|
|
679
684
|
}
|
|
680
685
|
function normalizeCreateOrder(request) {
|
|
681
686
|
const { amount, currency_code, metadata, ...rest } = request;
|
|
@@ -683,15 +688,15 @@ function normalizeCreateOrder(request) {
|
|
|
683
688
|
"amount",
|
|
684
689
|
"currency_code"
|
|
685
690
|
]);
|
|
686
|
-
const
|
|
691
|
+
const reservedMetadata = {
|
|
687
692
|
$amount: amount,
|
|
688
693
|
$currency_code: currency_code
|
|
689
694
|
};
|
|
690
|
-
body =
|
|
691
|
-
return
|
|
695
|
+
body = applyReservedMetadata(body, metadata, reservedMetadata);
|
|
696
|
+
return normalizeBaseReservedFields(body);
|
|
692
697
|
}
|
|
693
698
|
function normalizeDefault(request) {
|
|
694
|
-
return
|
|
699
|
+
return normalizeBaseReservedFields({ ...request });
|
|
695
700
|
}
|
|
696
701
|
function normalizeScoreRequestForApi(request) {
|
|
697
702
|
switch (request.event_type) {
|
|
@@ -749,12 +754,12 @@ function isSupportedFraudEventType(eventType) {
|
|
|
749
754
|
}
|
|
750
755
|
|
|
751
756
|
// src/types/metadata.ts
|
|
752
|
-
var
|
|
757
|
+
var TYPED_METADATA_KEYS = {
|
|
753
758
|
session_id: "$session_id",
|
|
754
759
|
user_email: "$user_email",
|
|
755
760
|
name: "$name",
|
|
756
761
|
phone: "$phone",
|
|
757
|
-
|
|
762
|
+
payment_method_details: "$payment_method",
|
|
758
763
|
billing_address: "$billing_address",
|
|
759
764
|
payment_methods: "$payment_methods",
|
|
760
765
|
app: "$app",
|
|
@@ -773,7 +778,7 @@ var TYPED_SIFT_METADATA_KEYS = {
|
|
|
773
778
|
ip: "$ip"
|
|
774
779
|
};
|
|
775
780
|
function findMetadataConflictWithTypedFields(metadata, request) {
|
|
776
|
-
for (const [field, metaKey] of Object.entries(
|
|
781
|
+
for (const [field, metaKey] of Object.entries(TYPED_METADATA_KEYS)) {
|
|
777
782
|
if (request[field] !== void 0 && metadata[metaKey] !== void 0) {
|
|
778
783
|
return metaKey;
|
|
779
784
|
}
|
|
@@ -828,26 +833,26 @@ function validatePaymentMethods(request, errors, prefix) {
|
|
|
828
833
|
if (skipNormalization) {
|
|
829
834
|
for (const key of Object.keys(raw)) {
|
|
830
835
|
const plainKey = key.startsWith("$") ? key.slice(1) : key;
|
|
831
|
-
if (!
|
|
836
|
+
if (!PAYMENT_METHOD_FIELD_WHITELIST.has(plainKey)) {
|
|
832
837
|
errors.push(
|
|
833
|
-
`${prefix}payment_methods[${index}].${plainKey} is not a
|
|
838
|
+
`${prefix}payment_methods[${index}].${plainKey} is not a recognized payment method field`
|
|
834
839
|
);
|
|
835
840
|
}
|
|
836
841
|
}
|
|
837
842
|
const rawType2 = raw.payment_type !== void 0 ? String(raw.payment_type) : void 0;
|
|
838
|
-
if (rawType2 !== void 0 &&
|
|
843
|
+
if (rawType2 !== void 0 && normalizePaymentType(rawType2) === void 0) {
|
|
839
844
|
errors.push(
|
|
840
|
-
`${prefix}payment_methods[${index}].payment_type is not a
|
|
845
|
+
`${prefix}payment_methods[${index}].payment_type is not a recognized payment type`
|
|
841
846
|
);
|
|
842
847
|
}
|
|
843
848
|
return;
|
|
844
849
|
}
|
|
845
850
|
const rawType = raw.payment_type !== void 0 ? String(raw.payment_type) : raw.$payment_type !== void 0 ? String(raw.$payment_type) : void 0;
|
|
846
851
|
if (rawType !== void 0) {
|
|
847
|
-
const result =
|
|
852
|
+
const result = normalizePaymentMethod(raw);
|
|
848
853
|
if (result === null) {
|
|
849
854
|
errors.push(
|
|
850
|
-
`${prefix}payment_methods[${index}].payment_type is not a
|
|
855
|
+
`${prefix}payment_methods[${index}].payment_type is not a recognized payment type`
|
|
851
856
|
);
|
|
852
857
|
}
|
|
853
858
|
}
|
|
@@ -855,17 +860,17 @@ function validatePaymentMethods(request, errors, prefix) {
|
|
|
855
860
|
}
|
|
856
861
|
function validateBase(request, errors, prefix) {
|
|
857
862
|
assertNonEmpty(request.customer_id, "customer_id", errors, prefix);
|
|
858
|
-
assertNonEmpty(request.
|
|
863
|
+
assertNonEmpty(request.user_reference, "user_reference", errors, prefix);
|
|
859
864
|
assertNonEmpty(request.event_type, "event_type", errors, prefix);
|
|
860
865
|
validateMetadata(request.metadata, request, errors, prefix);
|
|
861
866
|
}
|
|
862
867
|
function validateLogin(request, errors, prefix) {
|
|
863
|
-
assertEnum(request.login_status,
|
|
868
|
+
assertEnum(request.login_status, LoginStatusValues, "login_status", errors, prefix);
|
|
864
869
|
if (request.login_failure_reason !== void 0) {
|
|
865
870
|
if (request.login_status === "$failure") {
|
|
866
871
|
assertEnum(
|
|
867
872
|
request.login_failure_reason,
|
|
868
|
-
|
|
873
|
+
LoginFailureReasonValues,
|
|
869
874
|
"login_failure_reason",
|
|
870
875
|
errors,
|
|
871
876
|
prefix
|
|
@@ -878,14 +883,14 @@ function validateLogin(request, errors, prefix) {
|
|
|
878
883
|
function validateUpdatePassword(request, errors, prefix) {
|
|
879
884
|
assertEnum(
|
|
880
885
|
request.password_reason,
|
|
881
|
-
|
|
886
|
+
PasswordUpdateReasonValues,
|
|
882
887
|
"password_reason",
|
|
883
888
|
errors,
|
|
884
889
|
prefix
|
|
885
890
|
);
|
|
886
891
|
assertEnum(
|
|
887
892
|
request.password_status,
|
|
888
|
-
|
|
893
|
+
PasswordUpdateStatusValues,
|
|
889
894
|
"password_status",
|
|
890
895
|
errors,
|
|
891
896
|
prefix
|
|
@@ -894,10 +899,10 @@ function validateUpdatePassword(request, errors, prefix) {
|
|
|
894
899
|
function validateTransaction(request, errors, prefix) {
|
|
895
900
|
assertPositiveAmount(request.amount, "amount", errors, prefix);
|
|
896
901
|
assertNonEmpty(request.currency, "currency", errors, prefix);
|
|
897
|
-
assertEnum(request.transaction_type,
|
|
902
|
+
assertEnum(request.transaction_type, TransactionTypeValues, "transaction_type", errors, prefix);
|
|
898
903
|
assertEnum(
|
|
899
904
|
request.transaction_status,
|
|
900
|
-
|
|
905
|
+
TransactionStatusValues,
|
|
901
906
|
"transaction_status",
|
|
902
907
|
errors,
|
|
903
908
|
prefix
|
|
@@ -916,7 +921,7 @@ function validateTransaction(request, errors, prefix) {
|
|
|
916
921
|
function validateWager(request, errors, prefix) {
|
|
917
922
|
assertNonEmpty(request.transaction_id, "transaction_id", errors, prefix);
|
|
918
923
|
assertNonEmpty(request.wager_type, "wager_type", errors, prefix);
|
|
919
|
-
assertEnum(request.wager_status,
|
|
924
|
+
assertEnum(request.wager_status, WagerStatusValues, "wager_status", errors, prefix);
|
|
920
925
|
if (!request.wager_status) {
|
|
921
926
|
errors.push(`${prefix}wager_status is required`);
|
|
922
927
|
}
|
|
@@ -951,10 +956,10 @@ function validateChargeback(request, errors, prefix) {
|
|
|
951
956
|
if (!hasTransactionId && !hasOrderId) {
|
|
952
957
|
errors.push(`${prefix}transaction_id or order_id is required`);
|
|
953
958
|
}
|
|
954
|
-
assertEnum(request.chargeback_state,
|
|
959
|
+
assertEnum(request.chargeback_state, ChargebackStateValues, "chargeback_state", errors, prefix);
|
|
955
960
|
assertEnum(
|
|
956
961
|
request.chargeback_reason,
|
|
957
|
-
|
|
962
|
+
ChargebackReasonValues,
|
|
958
963
|
"chargeback_reason",
|
|
959
964
|
errors,
|
|
960
965
|
prefix
|
|
@@ -1060,6 +1065,6 @@ function isFraudAlertCallbackEvent(value) {
|
|
|
1060
1065
|
return typeof value === "object" && value !== null && value.event_type === "fraud.alert.callback";
|
|
1061
1066
|
}
|
|
1062
1067
|
|
|
1063
|
-
export { CHARGEBACK_FRAUD_EVENT_TYPE, ChargebackReason,
|
|
1068
|
+
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, normalizePaymentType, normalizeScoreRequestForApi, toAccountNumberLast5, validateScoreRequest };
|
|
1064
1069
|
//# sourceMappingURL=index.mjs.map
|
|
1065
1070
|
//# sourceMappingURL=index.mjs.map
|