@infrab4a/connect 4.1.2-beta.10 → 4.1.2-beta.12

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/index.cjs.js CHANGED
@@ -10,10 +10,10 @@ var lodash = require('lodash');
10
10
  var debug = require('debug');
11
11
  var tsCustomError = require('ts-custom-error');
12
12
  var axios = require('axios');
13
- var moment = require('moment');
14
13
  var firestore = require('firebase/firestore');
15
14
  var auth = require('firebase/auth');
16
15
  var gqlQueryBuilder = require('gql-query-builder');
16
+ var moment = require('moment');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
19
 
@@ -2353,6 +2353,215 @@ class AdyenCardService {
2353
2353
  }
2354
2354
  }
2355
2355
 
2356
+ class CheckoutAntiFraudService {
2357
+ constructor(orderRepository, orderBlockedRepository) {
2358
+ this.orderRepository = orderRepository;
2359
+ this.orderBlockedRepository = orderBlockedRepository;
2360
+ this.LIMIT_ORDERS_DAY = 2;
2361
+ this.LIMIT_ORDERS_WEEK = 7;
2362
+ this.LIMIT_BLOCKED_ORDERS_DAY = 5;
2363
+ }
2364
+ async validAntiFraud(checkout, boleto, pix, card) {
2365
+ if (this.couponValidation(checkout))
2366
+ return false;
2367
+ if (pix)
2368
+ return true;
2369
+ if (boleto && !this.verifyBoletoOrder(checkout))
2370
+ return false;
2371
+ if (card && !(await this.verifyBlockedOrderAttempts(checkout, card)))
2372
+ return false;
2373
+ if (card && !(await this.verifyDayAndWeekOrders(checkout, card)))
2374
+ return false;
2375
+ return true;
2376
+ }
2377
+ couponValidation(checkout) {
2378
+ var _a, _b;
2379
+ if (((_a = checkout.coupon) === null || _a === void 0 ? void 0 : _a.nickname) === 'FALHADEPAGAMENTO') {
2380
+ console.error(`Falha de pagamento com cupom. CheckoutId: ${JSON.stringify({
2381
+ checkoutId: checkout.id,
2382
+ user: checkout.user.id,
2383
+ coupon: (_b = checkout.coupon) === null || _b === void 0 ? void 0 : _b.nickname,
2384
+ })}`);
2385
+ return false;
2386
+ }
2387
+ return true;
2388
+ }
2389
+ async verifyDayAndWeekOrders(checkout, card) {
2390
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2391
+ const ordersPerDay = await this.validateOrdersByRange((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf, (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email, (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.phone, (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.zip, card, this.getDateRange('day'));
2392
+ for (const key in ordersPerDay) {
2393
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_DAY) {
2394
+ await this.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'day');
2395
+ return false;
2396
+ }
2397
+ }
2398
+ const ordersPerWeek = await this.validateOrdersByRange((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.cpf, (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.email, (_g = checkout.user) === null || _g === void 0 ? void 0 : _g.phone, (_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip, card, this.getDateRange('week'));
2399
+ for (const key in ordersPerWeek) {
2400
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_WEEK) {
2401
+ await this.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'week');
2402
+ return false;
2403
+ }
2404
+ }
2405
+ return true;
2406
+ }
2407
+ async validateOrdersByRange(cpf, email, phone, zip, card, range) {
2408
+ const ordersCpf = await this.countOrdersByField('user', 'cpf', cpf, range);
2409
+ const ordersByEmail = await this.countOrdersByField('user', 'email', email, range);
2410
+ const ordersByPhone = await this.countOrdersByField('user', 'phone', phone, range);
2411
+ const ordersByZip = await this.countOrdersByField('shippingAddress', 'zip', zip, range);
2412
+ return {
2413
+ cpf: ordersCpf,
2414
+ email: ordersByEmail,
2415
+ phone: ordersByPhone,
2416
+ zip: ordersByZip,
2417
+ };
2418
+ }
2419
+ async countOrdersByField(property, field, value, range) {
2420
+ const filters = {
2421
+ [property]: {
2422
+ [field]: value,
2423
+ },
2424
+ ['createdAt']: [
2425
+ { operator: exports.Where.GTE, value: range.firstDate },
2426
+ { operator: exports.Where.LTE, value: range.lastDate },
2427
+ ],
2428
+ };
2429
+ const docs = await (await this.orderRepository.find({ filters })).count;
2430
+ return docs;
2431
+ }
2432
+ async verifyBoletoOrder(checkout) {
2433
+ var _a;
2434
+ const maxOrderValue = 5000;
2435
+ if (checkout.totalPrice && checkout.totalPrice > maxOrderValue && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
2436
+ await this.createBlockedOrderOrPayment(checkout, 'Boleto not authorized', 'Boleto', 'day');
2437
+ return false;
2438
+ }
2439
+ return true;
2440
+ }
2441
+ async verifyBlockedOrderAttempts(checkout, card) {
2442
+ var _a, _b, _c, _d;
2443
+ const day = `${moment__namespace().format('YYYY-MM-DD')}T00:00:00`;
2444
+ const endOfDay = `${moment__namespace().format('YYYY-MM-DD')}T23:59:59`;
2445
+ const ordersBlockedWithCpf = await this.orderBlockedRepository
2446
+ .find({
2447
+ filters: {
2448
+ customer: { cpf: { operator: exports.Where.EQUALS, value: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf } },
2449
+ date: [
2450
+ { operator: exports.Where.GTE, value: new Date(day) },
2451
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2452
+ ],
2453
+ },
2454
+ })
2455
+ .then((data) => data.data);
2456
+ const ordersBlockedWithEmail = await this.orderBlockedRepository
2457
+ .find({
2458
+ filters: {
2459
+ customer: { email: { operator: exports.Where.EQUALS, value: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email } },
2460
+ date: [
2461
+ { operator: exports.Where.GTE, value: new Date(day) },
2462
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2463
+ ],
2464
+ },
2465
+ })
2466
+ .then((data) => data.data);
2467
+ const ordersBlockedWithCep = await this.orderBlockedRepository
2468
+ .find({
2469
+ filters: {
2470
+ customer: { shippingAddress: { zip: { operator: exports.Where.EQUALS, value: (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip } } },
2471
+ date: [
2472
+ { operator: exports.Where.GTE, value: new Date(day) },
2473
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2474
+ ],
2475
+ },
2476
+ })
2477
+ .then((data) => data.data);
2478
+ const ordersBlockedWithPhone = await this.orderBlockedRepository
2479
+ .find({
2480
+ filters: {
2481
+ customer: { phoneNumber: { operator: exports.Where.EQUALS, value: (_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone } },
2482
+ date: [
2483
+ { operator: exports.Where.GTE, value: new Date(day) },
2484
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2485
+ ],
2486
+ },
2487
+ })
2488
+ .then((data) => data.data);
2489
+ const blockedUniqueEmails = ordersBlockedWithEmail.filter((e) => {
2490
+ var _a;
2491
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf);
2492
+ });
2493
+ const blockedUniqueCeps = ordersBlockedWithCep.filter((e) => {
2494
+ var _a, _b;
2495
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) && e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email);
2496
+ });
2497
+ const blockedUniquePhone = ordersBlockedWithPhone.filter((e) => {
2498
+ var _a, _b, _c, _d, _e, _f;
2499
+ return (e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
2500
+ e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
2501
+ ((_d = (_c = e.customer.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip) === null || _d === void 0 ? void 0 : _d.toString()) !== ((_f = (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.zip) === null || _f === void 0 ? void 0 : _f.toString()));
2502
+ });
2503
+ const blockedAttempts = ordersBlockedWithCpf
2504
+ .concat(blockedUniqueEmails)
2505
+ .concat(blockedUniqueCeps)
2506
+ .concat(blockedUniquePhone);
2507
+ if (blockedAttempts.length >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2508
+ await this.createBlockedOrderOrPayment(checkout, 'More than 5 attempts have failed', 'Failed attempts', 'day', card || null);
2509
+ return false;
2510
+ }
2511
+ return true;
2512
+ }
2513
+ async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
2514
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2515
+ const paymentBlocked = {
2516
+ customer: {
2517
+ name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
2518
+ cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
2519
+ id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
2520
+ email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
2521
+ phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
2522
+ isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
2523
+ subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
2524
+ shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
2525
+ },
2526
+ blockType,
2527
+ limiteRange,
2528
+ type,
2529
+ card,
2530
+ checkout: {
2531
+ id: checkout.id,
2532
+ shop: checkout.shop,
2533
+ total: checkout.totalPrice,
2534
+ },
2535
+ date: new Date(),
2536
+ };
2537
+ await this.orderBlockedRepository.create(paymentBlocked);
2538
+ }
2539
+ getDateRange(range = 'day') {
2540
+ switch (range) {
2541
+ case 'day':
2542
+ return {
2543
+ firstDate: moment__namespace().startOf('D').valueOf(),
2544
+ lastDate: moment__namespace().endOf('D').valueOf(),
2545
+ };
2546
+ case 'week':
2547
+ return {
2548
+ firstDate: moment__namespace().subtract(7, 'd').startOf('D').valueOf(),
2549
+ lastDate: moment__namespace().endOf('D').valueOf(),
2550
+ };
2551
+ default:
2552
+ return {
2553
+ firstDate: moment__namespace().startOf('D').valueOf(),
2554
+ lastDate: moment__namespace().endOf('D').valueOf(),
2555
+ };
2556
+ }
2557
+ }
2558
+ formatZip(zip) {
2559
+ if (zip.length === 8)
2560
+ return zip.substring(0, 5) + '-' + zip.substring(5, 8);
2561
+ return zip;
2562
+ }
2563
+ }
2564
+
2356
2565
  class GlampointsPaymentService {
2357
2566
  pay(checkout) {
2358
2567
  const payment = {
@@ -6014,6 +6223,7 @@ exports.CategoryFirestoreRepository = CategoryFirestoreRepository;
6014
6223
  exports.CategoryHasuraGraphQL = CategoryHasuraGraphQL;
6015
6224
  exports.CategoryHasuraGraphQLRepository = CategoryHasuraGraphQLRepository;
6016
6225
  exports.Checkout = Checkout;
6226
+ exports.CheckoutAntiFraudService = CheckoutAntiFraudService;
6017
6227
  exports.CheckoutFirestoreRepository = CheckoutFirestoreRepository;
6018
6228
  exports.CheckoutSubscription = CheckoutSubscription;
6019
6229
  exports.CheckoutSubscriptionFirestoreRepository = CheckoutSubscriptionFirestoreRepository;
package/index.esm.js CHANGED
@@ -9,10 +9,10 @@ export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil,
9
9
  import { debug } from 'debug';
10
10
  import { CustomError } from 'ts-custom-error';
11
11
  import axios from 'axios';
12
- import * as moment from 'moment';
13
12
  import { collection, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc, Timestamp } from 'firebase/firestore';
14
13
  import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
15
14
  import { mutation, query as query$1 } from 'gql-query-builder';
15
+ import * as moment from 'moment';
16
16
 
17
17
  class BasePaymentMethodFactory {
18
18
  constructor(methods) {
@@ -2328,6 +2328,215 @@ class AdyenCardService {
2328
2328
  }
2329
2329
  }
2330
2330
 
2331
+ class CheckoutAntiFraudService {
2332
+ constructor(orderRepository, orderBlockedRepository) {
2333
+ this.orderRepository = orderRepository;
2334
+ this.orderBlockedRepository = orderBlockedRepository;
2335
+ this.LIMIT_ORDERS_DAY = 2;
2336
+ this.LIMIT_ORDERS_WEEK = 7;
2337
+ this.LIMIT_BLOCKED_ORDERS_DAY = 5;
2338
+ }
2339
+ async validAntiFraud(checkout, boleto, pix, card) {
2340
+ if (this.couponValidation(checkout))
2341
+ return false;
2342
+ if (pix)
2343
+ return true;
2344
+ if (boleto && !this.verifyBoletoOrder(checkout))
2345
+ return false;
2346
+ if (card && !(await this.verifyBlockedOrderAttempts(checkout, card)))
2347
+ return false;
2348
+ if (card && !(await this.verifyDayAndWeekOrders(checkout, card)))
2349
+ return false;
2350
+ return true;
2351
+ }
2352
+ couponValidation(checkout) {
2353
+ var _a, _b;
2354
+ if (((_a = checkout.coupon) === null || _a === void 0 ? void 0 : _a.nickname) === 'FALHADEPAGAMENTO') {
2355
+ console.error(`Falha de pagamento com cupom. CheckoutId: ${JSON.stringify({
2356
+ checkoutId: checkout.id,
2357
+ user: checkout.user.id,
2358
+ coupon: (_b = checkout.coupon) === null || _b === void 0 ? void 0 : _b.nickname,
2359
+ })}`);
2360
+ return false;
2361
+ }
2362
+ return true;
2363
+ }
2364
+ async verifyDayAndWeekOrders(checkout, card) {
2365
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2366
+ const ordersPerDay = await this.validateOrdersByRange((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf, (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email, (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.phone, (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.zip, card, this.getDateRange('day'));
2367
+ for (const key in ordersPerDay) {
2368
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_DAY) {
2369
+ await this.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'day');
2370
+ return false;
2371
+ }
2372
+ }
2373
+ const ordersPerWeek = await this.validateOrdersByRange((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.cpf, (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.email, (_g = checkout.user) === null || _g === void 0 ? void 0 : _g.phone, (_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip, card, this.getDateRange('week'));
2374
+ for (const key in ordersPerWeek) {
2375
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_WEEK) {
2376
+ await this.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'week');
2377
+ return false;
2378
+ }
2379
+ }
2380
+ return true;
2381
+ }
2382
+ async validateOrdersByRange(cpf, email, phone, zip, card, range) {
2383
+ const ordersCpf = await this.countOrdersByField('user', 'cpf', cpf, range);
2384
+ const ordersByEmail = await this.countOrdersByField('user', 'email', email, range);
2385
+ const ordersByPhone = await this.countOrdersByField('user', 'phone', phone, range);
2386
+ const ordersByZip = await this.countOrdersByField('shippingAddress', 'zip', zip, range);
2387
+ return {
2388
+ cpf: ordersCpf,
2389
+ email: ordersByEmail,
2390
+ phone: ordersByPhone,
2391
+ zip: ordersByZip,
2392
+ };
2393
+ }
2394
+ async countOrdersByField(property, field, value, range) {
2395
+ const filters = {
2396
+ [property]: {
2397
+ [field]: value,
2398
+ },
2399
+ ['createdAt']: [
2400
+ { operator: Where.GTE, value: range.firstDate },
2401
+ { operator: Where.LTE, value: range.lastDate },
2402
+ ],
2403
+ };
2404
+ const docs = await (await this.orderRepository.find({ filters })).count;
2405
+ return docs;
2406
+ }
2407
+ async verifyBoletoOrder(checkout) {
2408
+ var _a;
2409
+ const maxOrderValue = 5000;
2410
+ if (checkout.totalPrice && checkout.totalPrice > maxOrderValue && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
2411
+ await this.createBlockedOrderOrPayment(checkout, 'Boleto not authorized', 'Boleto', 'day');
2412
+ return false;
2413
+ }
2414
+ return true;
2415
+ }
2416
+ async verifyBlockedOrderAttempts(checkout, card) {
2417
+ var _a, _b, _c, _d;
2418
+ const day = `${moment().format('YYYY-MM-DD')}T00:00:00`;
2419
+ const endOfDay = `${moment().format('YYYY-MM-DD')}T23:59:59`;
2420
+ const ordersBlockedWithCpf = await this.orderBlockedRepository
2421
+ .find({
2422
+ filters: {
2423
+ customer: { cpf: { operator: Where.EQUALS, value: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf } },
2424
+ date: [
2425
+ { operator: Where.GTE, value: new Date(day) },
2426
+ { operator: Where.LTE, value: new Date(endOfDay) },
2427
+ ],
2428
+ },
2429
+ })
2430
+ .then((data) => data.data);
2431
+ const ordersBlockedWithEmail = await this.orderBlockedRepository
2432
+ .find({
2433
+ filters: {
2434
+ customer: { email: { operator: Where.EQUALS, value: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email } },
2435
+ date: [
2436
+ { operator: Where.GTE, value: new Date(day) },
2437
+ { operator: Where.LTE, value: new Date(endOfDay) },
2438
+ ],
2439
+ },
2440
+ })
2441
+ .then((data) => data.data);
2442
+ const ordersBlockedWithCep = await this.orderBlockedRepository
2443
+ .find({
2444
+ filters: {
2445
+ customer: { shippingAddress: { zip: { operator: Where.EQUALS, value: (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip } } },
2446
+ date: [
2447
+ { operator: Where.GTE, value: new Date(day) },
2448
+ { operator: Where.LTE, value: new Date(endOfDay) },
2449
+ ],
2450
+ },
2451
+ })
2452
+ .then((data) => data.data);
2453
+ const ordersBlockedWithPhone = await this.orderBlockedRepository
2454
+ .find({
2455
+ filters: {
2456
+ customer: { phoneNumber: { operator: Where.EQUALS, value: (_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone } },
2457
+ date: [
2458
+ { operator: Where.GTE, value: new Date(day) },
2459
+ { operator: Where.LTE, value: new Date(endOfDay) },
2460
+ ],
2461
+ },
2462
+ })
2463
+ .then((data) => data.data);
2464
+ const blockedUniqueEmails = ordersBlockedWithEmail.filter((e) => {
2465
+ var _a;
2466
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf);
2467
+ });
2468
+ const blockedUniqueCeps = ordersBlockedWithCep.filter((e) => {
2469
+ var _a, _b;
2470
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) && e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email);
2471
+ });
2472
+ const blockedUniquePhone = ordersBlockedWithPhone.filter((e) => {
2473
+ var _a, _b, _c, _d, _e, _f;
2474
+ return (e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
2475
+ e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
2476
+ ((_d = (_c = e.customer.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip) === null || _d === void 0 ? void 0 : _d.toString()) !== ((_f = (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.zip) === null || _f === void 0 ? void 0 : _f.toString()));
2477
+ });
2478
+ const blockedAttempts = ordersBlockedWithCpf
2479
+ .concat(blockedUniqueEmails)
2480
+ .concat(blockedUniqueCeps)
2481
+ .concat(blockedUniquePhone);
2482
+ if (blockedAttempts.length >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2483
+ await this.createBlockedOrderOrPayment(checkout, 'More than 5 attempts have failed', 'Failed attempts', 'day', card || null);
2484
+ return false;
2485
+ }
2486
+ return true;
2487
+ }
2488
+ async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
2489
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2490
+ const paymentBlocked = {
2491
+ customer: {
2492
+ name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
2493
+ cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
2494
+ id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
2495
+ email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
2496
+ phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
2497
+ isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
2498
+ subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
2499
+ shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
2500
+ },
2501
+ blockType,
2502
+ limiteRange,
2503
+ type,
2504
+ card,
2505
+ checkout: {
2506
+ id: checkout.id,
2507
+ shop: checkout.shop,
2508
+ total: checkout.totalPrice,
2509
+ },
2510
+ date: new Date(),
2511
+ };
2512
+ await this.orderBlockedRepository.create(paymentBlocked);
2513
+ }
2514
+ getDateRange(range = 'day') {
2515
+ switch (range) {
2516
+ case 'day':
2517
+ return {
2518
+ firstDate: moment().startOf('D').valueOf(),
2519
+ lastDate: moment().endOf('D').valueOf(),
2520
+ };
2521
+ case 'week':
2522
+ return {
2523
+ firstDate: moment().subtract(7, 'd').startOf('D').valueOf(),
2524
+ lastDate: moment().endOf('D').valueOf(),
2525
+ };
2526
+ default:
2527
+ return {
2528
+ firstDate: moment().startOf('D').valueOf(),
2529
+ lastDate: moment().endOf('D').valueOf(),
2530
+ };
2531
+ }
2532
+ }
2533
+ formatZip(zip) {
2534
+ if (zip.length === 8)
2535
+ return zip.substring(0, 5) + '-' + zip.substring(5, 8);
2536
+ return zip;
2537
+ }
2538
+ }
2539
+
2331
2540
  class GlampointsPaymentService {
2332
2541
  pay(checkout) {
2333
2542
  const payment = {
@@ -5850,4 +6059,4 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5850
6059
  }
5851
6060
  }
5852
6061
 
5853
- export { AccessoryImportances, Address, AdyenCardService, AdyenPaymentMethodFactory, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderFirestoreRepository, OrderStatus, PagarmeBankSlipService, PagarmeCardService, PagarmePaymentMethodFactory, PagarmePixService, Payment, PaymentFirestoreRepository, PaymentProviderFactory, PaymentTransaction, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
6062
+ export { AccessoryImportances, Address, AdyenCardService, AdyenPaymentMethodFactory, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutAntiFraudService, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderFirestoreRepository, OrderStatus, PagarmeBankSlipService, PagarmeCardService, PagarmePaymentMethodFactory, PagarmePixService, Payment, PaymentFirestoreRepository, PaymentProviderFactory, PaymentTransaction, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.1.2-beta.10",
3
+ "version": "4.1.2-beta.12",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -1,10 +1,11 @@
1
1
  import { PaymentProvider } from '../types';
2
+ import { AdyenPaymentMethodFactory } from './adyen-payment-method.factory';
2
3
  import { GlampointsPaymentMethodFactory } from './glampoints-payment-method.factory';
3
4
  import { PagarmePaymentMethodFactory } from './pagarme-payment-method.factory';
4
5
  type PaymentProviderFactoryFactories = {
5
- pagarMe: PagarmePaymentMethodFactory;
6
- adyen: PagarmePaymentMethodFactory;
7
- glampoints: GlampointsPaymentMethodFactory;
6
+ pagarMe?: PagarmePaymentMethodFactory;
7
+ adyen?: AdyenPaymentMethodFactory;
8
+ glampoints?: GlampointsPaymentMethodFactory;
8
9
  };
9
10
  export declare class PaymentProviderFactory {
10
11
  private readonly paymentProviders;
@@ -1,4 +1,5 @@
1
1
  export * from './adyen-card-payment.service';
2
+ export * from './antifraude.service';
2
3
  export * from './glampoints-payment.service';
3
4
  export * from './pagarme-bank-slip-payment.service';
4
5
  export * from './pagarme-card-payment.service';