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