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