ravcredit-lib 0.0.4 → 0.0.6

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.
Files changed (49) hide show
  1. package/fesm2022/ravcredit-lib.mjs +666 -2
  2. package/fesm2022/ravcredit-lib.mjs.map +1 -1
  3. package/index.d.ts +1598 -4
  4. package/package.json +3 -4
  5. package/esm2022/lib/ravcredit-lib.component.mjs +0 -19
  6. package/esm2022/lib/ravcredit-lib.service.mjs +0 -14
  7. package/esm2022/lib/v1/objects/oAddress.mjs +0 -10
  8. package/esm2022/lib/v1/objects/oBusiness.mjs +0 -2
  9. package/esm2022/lib/v1/objects/oClient.mjs +0 -2
  10. package/esm2022/lib/v1/objects/oConekta.mjs +0 -85
  11. package/esm2022/lib/v1/objects/oContract.mjs +0 -2
  12. package/esm2022/lib/v1/objects/oContractAll.mjs +0 -2
  13. package/esm2022/lib/v1/objects/oCustomer.mjs +0 -18
  14. package/esm2022/lib/v1/objects/oDevice.mjs +0 -2
  15. package/esm2022/lib/v1/objects/oFinancial.mjs +0 -2
  16. package/esm2022/lib/v1/objects/oGlobal.mjs +0 -86
  17. package/esm2022/lib/v1/objects/oLogIn.mjs +0 -17
  18. package/esm2022/lib/v1/objects/oNewPayment.mjs +0 -2
  19. package/esm2022/lib/v1/objects/oNotification.mjs +0 -17
  20. package/esm2022/lib/v1/objects/oPassport.mjs +0 -7
  21. package/esm2022/lib/v1/objects/oUser.mjs +0 -2
  22. package/esm2022/lib/v1/util/UtilBusiness.mjs +0 -171
  23. package/esm2022/lib/v1/util/UtilClient.mjs +0 -221
  24. package/esm2022/lib/v1/util/UtilContract.mjs +0 -331
  25. package/esm2022/lib/v1/util/UtilDynamiCore.mjs +0 -292
  26. package/esm2022/public-api.mjs +0 -25
  27. package/esm2022/ravcredit-lib.mjs +0 -5
  28. package/lib/ravcredit-lib.component.d.ts +0 -5
  29. package/lib/ravcredit-lib.service.d.ts +0 -6
  30. package/lib/v1/objects/oAddress.d.ts +0 -10
  31. package/lib/v1/objects/oBusiness.d.ts +0 -101
  32. package/lib/v1/objects/oClient.d.ts +0 -43
  33. package/lib/v1/objects/oConekta.d.ts +0 -305
  34. package/lib/v1/objects/oContract.d.ts +0 -23
  35. package/lib/v1/objects/oContractAll.d.ts +0 -21
  36. package/lib/v1/objects/oCustomer.d.ts +0 -17
  37. package/lib/v1/objects/oDevice.d.ts +0 -5
  38. package/lib/v1/objects/oFinancial.d.ts +0 -30
  39. package/lib/v1/objects/oGlobal.d.ts +0 -149
  40. package/lib/v1/objects/oLogIn.d.ts +0 -30
  41. package/lib/v1/objects/oNewPayment.d.ts +0 -11
  42. package/lib/v1/objects/oNotification.d.ts +0 -25
  43. package/lib/v1/objects/oPassport.d.ts +0 -55
  44. package/lib/v1/objects/oUser.d.ts +0 -25
  45. package/lib/v1/util/UtilBusiness.d.ts +0 -52
  46. package/lib/v1/util/UtilClient.d.ts +0 -34
  47. package/lib/v1/util/UtilContract.d.ts +0 -70
  48. package/lib/v1/util/UtilDynamiCore.d.ts +0 -453
  49. package/public-api.d.ts +0 -21
@@ -1,6 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, Component } from '@angular/core';
2
+ import { Injectable, Component, runInInjectionContext, inject } from '@angular/core';
3
3
  import { UntypedFormControl, Validators, UntypedFormArray } from '@angular/forms';
4
+ import { add, getDate, format } from 'date-fns';
5
+ import { es } from 'date-fns/locale/es';
6
+ import { openDB } from 'idb';
4
7
 
5
8
  class RavcreditLibService {
6
9
  constructor() { }
@@ -981,6 +984,17 @@ var ePassportTypes;
981
984
  })(ePassportTypes || (ePassportTypes = {}));
982
985
  /** ******************************** */
983
986
 
987
+ class UtilsHttp {
988
+ static CreateHeadersApi(token) {
989
+ return {
990
+ 'Content-Type': 'application/json',
991
+ 'Accept': 'application/json',
992
+ 'Access-Control-Allow-Headers': 'Content-Type',
993
+ 'Authorization': `Bearer ${token}`
994
+ };
995
+ }
996
+ }
997
+
984
998
  var eReferenceStatusRav;
985
999
  (function (eReferenceStatusRav) {
986
1000
  eReferenceStatusRav["Disponible"] = "Disponible";
@@ -1272,6 +1286,656 @@ class FactoryDynamiCore {
1272
1286
  }
1273
1287
  }
1274
1288
 
1289
+ var ePaymentType;
1290
+ (function (ePaymentType) {
1291
+ ePaymentType["OXXO"] = "OXXO";
1292
+ ePaymentType["ALTERNA"] = "ALTERNA";
1293
+ ePaymentType["OXXO_RECURRENT"] = "oxxo_recurrent";
1294
+ })(ePaymentType || (ePaymentType = {}));
1295
+ class FactoryConekta {
1296
+ static createOrder(client, contract, dateTime) {
1297
+ if (client.conekta_id == undefined)
1298
+ return {
1299
+ data: {
1300
+ charges: [],
1301
+ currency: "",
1302
+ customer_info: { customer_id: "" },
1303
+ line_items: []
1304
+ },
1305
+ id: ""
1306
+ };
1307
+ const customer_info = {
1308
+ customer_id: client.conekta_id
1309
+ };
1310
+ const week = ((3600 * 24) * 30) * 1000;
1311
+ let next = new Date().getTime() + week;
1312
+ next = Math.floor(next / 1000);
1313
+ const method = {
1314
+ type: "cash",
1315
+ expires_at: next,
1316
+ };
1317
+ const charge = {
1318
+ amount: contract.financial.weeklyPayment * 100,
1319
+ payment_method: method
1320
+ };
1321
+ const charges = [charge];
1322
+ const antifraud_info = {
1323
+ newKey: "Key"
1324
+ };
1325
+ const lineItem = {
1326
+ antifraud_info: antifraud_info,
1327
+ name: `Referencia credito ${client.name}`,
1328
+ quantity: 1,
1329
+ unit_price: contract.financial.weeklyPayment * 100,
1330
+ };
1331
+ const lineItems = [lineItem];
1332
+ const orderData = {
1333
+ customer_info: customer_info,
1334
+ charges: charges,
1335
+ currency: "MXN",
1336
+ line_items: lineItems
1337
+ };
1338
+ const order = {
1339
+ data: orderData,
1340
+ id: client.id
1341
+ };
1342
+ if (dateTime != undefined)
1343
+ order.date = dateTime;
1344
+ return order;
1345
+ }
1346
+ }
1347
+ // '
1348
+ // {
1349
+ // "customer_info": {
1350
+ // "name": "DevTest",
1351
+ // "email": "test@femsa.com",
1352
+ // "phone": "5522997233"
1353
+ // },
1354
+ // "currency": "MXN",
1355
+ // "line_items": [
1356
+ // {
1357
+ // "name": "Box of Cohiba S1s",
1358
+ // "quantity": 1,
1359
+ // "unit_price": 20000
1360
+ // }
1361
+ // ]
1362
+ // }
1363
+ // '
1364
+
1365
+ const ROUTE_NOTIFICATIONS = "notifications";
1366
+ const ROUTE_GLOBAL_REFERENCE2 = "/contract-reference";
1367
+ const prodFunction = "https://us-central1-ravcredit-2b079.cloudfunctions.net/CustomerNotification";
1368
+ const prodFunction2 = "https://customernotification-2imgfxveka-uc.a.run.app";
1369
+ const localTest = "http://127.0.0.1:5001/ravcredit-2b079/us-central1/CustomerNotification";
1370
+ const ravCreditFunctions = prodFunction;
1371
+ class FactoryNotification {
1372
+ static FormNotification(notification) {
1373
+ let data = cNotification;
1374
+ if (notification)
1375
+ data = notification;
1376
+ return {
1377
+ title: new UntypedFormControl(data.notification.title, [Validators.required, Validators.min(1)]),
1378
+ body: new UntypedFormControl(data.notification.body, [Validators.required, Validators.min(1)]),
1379
+ };
1380
+ }
1381
+ static CreateGlobalNotificationObj(data) {
1382
+ const o = {};
1383
+ if (data.notification) {
1384
+ const not = {};
1385
+ if (data.notification.body)
1386
+ not["body"] = data.notification.body;
1387
+ if (data.notification.title)
1388
+ not["title"] = data.notification.title;
1389
+ if (data.ids)
1390
+ not["ids"] = data.ids;
1391
+ if (data.tokens)
1392
+ not["tokens"] = data.tokens;
1393
+ if (data.type)
1394
+ not["type"] = data.type;
1395
+ if (data.data)
1396
+ if (data.data.route)
1397
+ not["route"] = data.data.route;
1398
+ o["data"] = not;
1399
+ }
1400
+ return o;
1401
+ }
1402
+ }
1403
+
1404
+ const keyUserID = "rc_uid";
1405
+ const dbVersion = 1;
1406
+ const dbName = "RavCreditDB";
1407
+ const keyPathId = "id";
1408
+ const dbAuthStore = "authStore";
1409
+ const dbUsersStore = "usersStore";
1410
+ const dbContractsStore = "contractsStore";
1411
+ const dbClientsStore = "clientsStore";
1412
+ const dbBusinessInfo = "businessInfo";
1413
+ const dbBusinessConfig = "businessConfig";
1414
+ const dbConektaClientsStore = "conektaClientsStore";
1415
+ const dbConektaReferencesStore = "conektaReferencesStore";
1416
+ const dbPassportReferencesStore = "passportReferencesStore";
1417
+ const dbDynamicReferencesStore = "dynamicReferencesStore";
1418
+ const dbDynamicAccountStore = "dynamicAccountStore";
1419
+ const dbNotificationsStore = "notificationsStore";
1420
+ const dbPaymentsStore = "paymentsStore";
1421
+ const dbIndexAuth = "iAuth";
1422
+ const dbIndexUsers = "iUsers";
1423
+ const dbIndexContracts = "iContracts";
1424
+ const dbIndexClients = "iClients";
1425
+ const dbIndexBusiness = "iBusiness";
1426
+ const dbIndexConektaClients = "iConecktaClients";
1427
+ const dbIndexConektaClientsRef = "iConecktaClientsRef";
1428
+ const dbIndexPassportClientsRef = "iPassportClientsRef";
1429
+ const dbIndexNotification = "iNotification";
1430
+ const dbIndexPayments = "iNotification";
1431
+ const dateFormat = "EEEE, dd MMM yyyy";
1432
+ const dateCompleteFormat = "EEEE, dd MMM yyyy hh:mm aaaa";
1433
+ const timeFormat = "hh:mm aaaa";
1434
+ const expiredPayment = "expiredPayment";
1435
+
1436
+ class IndexedDbService {
1437
+ indexDbStatus = false;
1438
+ iDb;
1439
+ constructor() {
1440
+ }
1441
+ async dbAuthorization() {
1442
+ // const k = this.getLocalUser()
1443
+ // if (k == null) return false
1444
+ //
1445
+ // const db = await openDB(dbName, dbVersion)
1446
+ // // utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
1447
+ // const auth = await db.get(dbAuthStore, k)
1448
+ // // utils auth = await store.get(k)
1449
+ // db.close()
1450
+ let auth = null;
1451
+ return auth;
1452
+ }
1453
+ /****************** SIMPLE Transactional - CRUD *************************************/
1454
+ async dbGetObject(store, data) {
1455
+ if (!data)
1456
+ return data;
1457
+ const db = await openDB(dbName, dbVersion);
1458
+ return await db.get(store, data);
1459
+ }
1460
+ async dbGetAllByStore(store, index) {
1461
+ const db = await openDB(dbName, dbVersion);
1462
+ return await db.getAll(store);
1463
+ }
1464
+ async dbAddObject(store, data) {
1465
+ try {
1466
+ const db = await openDB(dbName, dbVersion);
1467
+ await db.put(store, data);
1468
+ return true;
1469
+ }
1470
+ catch (e) {
1471
+ return false;
1472
+ }
1473
+ }
1474
+ async dbRemoveObject(store, data) {
1475
+ const db = await openDB(dbName, dbVersion);
1476
+ return await db.delete(store, data);
1477
+ }
1478
+ /********************************************************************************* **/
1479
+ async dbSignIn(store, data) {
1480
+ await this.iDb.put(store, data);
1481
+ const _data = data;
1482
+ this.setLocalStorage(keyUserID, _data.id);
1483
+ }
1484
+ /******************************** Local Storage *************************************/
1485
+ setLocalStorage(k, v) {
1486
+ localStorage.setItem(k, v);
1487
+ }
1488
+ getLocalStorage(k) {
1489
+ return localStorage.getItem(k);
1490
+ }
1491
+ deleteLocalStorage(k) {
1492
+ return localStorage.removeItem(k);
1493
+ }
1494
+ getLocalUser() {
1495
+ const k = localStorage.getItem(keyUserID);
1496
+ return (k);
1497
+ }
1498
+ /********************************************************************************* **/
1499
+ async getPlatformUser() {
1500
+ const k = this.getLocalStorage(keyUserID);
1501
+ if (k == null)
1502
+ return "";
1503
+ const db = await openDB(dbName, dbVersion);
1504
+ // utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
1505
+ const auth = await db.get(dbAuthStore, k);
1506
+ // utils auth = await store.get(k)
1507
+ db.close();
1508
+ return auth.name != "" ? auth.name : "";
1509
+ }
1510
+ async getToken() {
1511
+ const k = this.getLocalUser();
1512
+ if (k == null)
1513
+ return "";
1514
+ const db = await openDB(dbName, dbVersion);
1515
+ // utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
1516
+ const auth = await db.get(dbAuthStore, k);
1517
+ // utils auth = await store.get(k)
1518
+ db.close();
1519
+ return auth.access_token != "" ? auth.access_token : "";
1520
+ }
1521
+ async addObject(store, data) {
1522
+ try {
1523
+ const db = await openDB(dbName, dbVersion);
1524
+ await db.put(store, data);
1525
+ return true;
1526
+ }
1527
+ catch (e) {
1528
+ return false;
1529
+ }
1530
+ }
1531
+ async patchObject(store, data) {
1532
+ try {
1533
+ const db = await openDB(dbName, dbVersion);
1534
+ const txn = db.transaction(store, "readwrite");
1535
+ const obj = txn.objectStore(store);
1536
+ // const index = obj.index(keyPathCurp)
1537
+ await obj.put(data);
1538
+ return data;
1539
+ }
1540
+ catch (e) {
1541
+ console.error(e);
1542
+ return {};
1543
+ }
1544
+ }
1545
+ async updateObjectByID(store, id, data) {
1546
+ try {
1547
+ const db = await openDB(dbName, dbVersion);
1548
+ const res = await db.get(store, id);
1549
+ if (res != undefined)
1550
+ await this.removeObject(dbClientsStore, id);
1551
+ return await this.addObject(store, data);
1552
+ }
1553
+ catch (e) {
1554
+ console.error("updateObjectByID Catch Error:", e);
1555
+ return false;
1556
+ }
1557
+ }
1558
+ async upsertObjectById(store, id, data) {
1559
+ const db = await openDB(dbName, dbVersion);
1560
+ const res = await db.get(store, id);
1561
+ if (res)
1562
+ await this.removeObject(store, id);
1563
+ return await db.add(store, data);
1564
+ }
1565
+ async removeObject(store, data) {
1566
+ const db = await openDB(dbName, dbVersion);
1567
+ return await db.delete(store, data);
1568
+ }
1569
+ async deleteObjectByID(store, id) {
1570
+ try {
1571
+ const db = await openDB(dbName, dbVersion);
1572
+ const txn = db.transaction(store, "readwrite");
1573
+ const obj = txn.objectStore(store);
1574
+ const index = obj.index(keyPathId);
1575
+ const va2 = index.openCursor(id);
1576
+ va2.then(async (cursor) => {
1577
+ while (cursor) {
1578
+ cursor.delete();
1579
+ cursor = await cursor.continue();
1580
+ }
1581
+ });
1582
+ return va2;
1583
+ }
1584
+ catch (e) {
1585
+ console.error(e);
1586
+ return {};
1587
+ }
1588
+ }
1589
+ async cleanAll(store) {
1590
+ const db = await openDB(dbName, dbVersion);
1591
+ return await db.clear(store);
1592
+ }
1593
+ async getObject(store, data) {
1594
+ if (!data)
1595
+ return data;
1596
+ const db = await openDB(dbName, dbVersion);
1597
+ return await db.get(store, data);
1598
+ }
1599
+ async addBuildByStore(store, data) {
1600
+ for (const o of data) {
1601
+ const exists = await this.getObject(store, o["id"]);
1602
+ if (!exists)
1603
+ await this.addObject(store, o);
1604
+ else
1605
+ await this.updateObject(store, o);
1606
+ }
1607
+ }
1608
+ async updateObject(store, data) {
1609
+ const db = await openDB(dbName, dbVersion);
1610
+ await db.put(store, data);
1611
+ }
1612
+ async getAllByStore(store, index) {
1613
+ const db = await openDB(dbName, dbVersion);
1614
+ return await db.getAll(store);
1615
+ }
1616
+ async getAuthUser() {
1617
+ const data = await this.getAllByStore(dbAuthStore);
1618
+ return data[0];
1619
+ }
1620
+ async getAuthName() {
1621
+ const data = await this.getAuthUser();
1622
+ return data.name;
1623
+ }
1624
+ async getAuthUsername() {
1625
+ const data = await this.getAuthUser();
1626
+ return data.username;
1627
+ }
1628
+ async saveDataLocally(contract, client, providerData) {
1629
+ try {
1630
+ await this.addObject(dbClientsStore, client);
1631
+ await this.addObject(dbContractsStore, contract);
1632
+ if (!providerData)
1633
+ return false;
1634
+ if (contract.financial.provider === eProvider.Conekta) {
1635
+ await this.addObject(dbConektaClientsStore, providerData);
1636
+ await this.addObject(dbConektaReferencesStore, providerData);
1637
+ }
1638
+ else if (contract.financial.provider === eProvider.Passport) {
1639
+ await this.addObject(dbPassportReferencesStore, providerData);
1640
+ }
1641
+ else if (contract.financial.provider === eProvider.DynamiCore) {
1642
+ await this.addObject(dbDynamicReferencesStore, providerData);
1643
+ }
1644
+ return true;
1645
+ }
1646
+ catch (e) {
1647
+ console.error(e);
1648
+ return false;
1649
+ }
1650
+ }
1651
+ /******************** MERGE **************************************/
1652
+ async getAllClientContracts() {
1653
+ const clientContract = [];
1654
+ const clients = await this.getAllByStore(dbClientsStore);
1655
+ if (clients.length == 0)
1656
+ return [];
1657
+ for (let client of clients) {
1658
+ const contract = await this.getObject(dbContractsStore, client.contract);
1659
+ const e = { ...client, ...contract };
1660
+ // preserve the id value over concat models
1661
+ e.id = client.id;
1662
+ e.status = client.status;
1663
+ clientContract.push(e);
1664
+ }
1665
+ return clientContract;
1666
+ }
1667
+ /******************** MERGE **************************************/
1668
+ async dbGetAllClientContracts() {
1669
+ const clientContract = [];
1670
+ const clients = await this.dbGetAllByStore(dbClientsStore);
1671
+ if (clients.length == 0)
1672
+ return [];
1673
+ for (let client of clients) {
1674
+ const contract = await this.dbGetObject(dbContractsStore, client.contract);
1675
+ const e = { ...client, ...contract };
1676
+ // preserve the id value over concat models
1677
+ e.id = client.id;
1678
+ e.status = client.status;
1679
+ clientContract.push(e);
1680
+ }
1681
+ return clientContract;
1682
+ }
1683
+ /****************** BUSINESS INFO *************************************/
1684
+ async getBusinessInfo() {
1685
+ const config = await this.dbGetAllByStore(dbBusinessInfo);
1686
+ if (!config)
1687
+ return null;
1688
+ return config[0];
1689
+ }
1690
+ /****************** BUSINESS CONFIG ************************************/
1691
+ async getBusinessConfig() {
1692
+ const config = await this.dbGetAllByStore(dbBusinessConfig);
1693
+ if (!config)
1694
+ return null;
1695
+ return config[0];
1696
+ }
1697
+ async updateBusinessConfig(config) {
1698
+ // config.version = "1.0"
1699
+ await this.dbRemoveObject(dbBusinessConfig, "1.0");
1700
+ await this.dbAddObject(dbBusinessConfig, config);
1701
+ }
1702
+ async updateBusinessInfo(config) {
1703
+ config.version = "v2024";
1704
+ await this.dbRemoveObject(dbBusinessInfo, "v2024");
1705
+ await this.dbAddObject(dbBusinessInfo, config);
1706
+ }
1707
+ /**************** NOTIFICATIONS *********************************/
1708
+ async getLocalNotifications() {
1709
+ const notifications = await this.dbGetAllByStore(dbNotificationsStore);
1710
+ if (!notifications)
1711
+ return null;
1712
+ return notifications;
1713
+ }
1714
+ async updateNotifications(notifications) {
1715
+ for (const o of notifications) {
1716
+ const exists = await this.dbGetObject(dbNotificationsStore, o.notification_id);
1717
+ if (!exists) {
1718
+ await this.dbAddObject(dbNotificationsStore, o);
1719
+ }
1720
+ }
1721
+ }
1722
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: IndexedDbService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1723
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: IndexedDbService, providedIn: 'root' });
1724
+ }
1725
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: IndexedDbService, decorators: [{
1726
+ type: Injectable,
1727
+ args: [{
1728
+ providedIn: 'root'
1729
+ }]
1730
+ }], ctorParameters: () => [] });
1731
+
1732
+ class UtilTime {
1733
+ localeFns = es;
1734
+ static IsExpired(time) {
1735
+ const dateInit = new Date(time);
1736
+ const dayInit = dateInit.getDate();
1737
+ const monthInit = dateInit.getMonth() + 1;
1738
+ const dateActual = new Date();
1739
+ const dayActual = dateActual.getDate();
1740
+ const monthActual = dateActual.getMonth() + 1;
1741
+ if (monthActual > monthInit)
1742
+ return true;
1743
+ return dayActual > dayInit;
1744
+ }
1745
+ static getDates(initial, weeks) {
1746
+ const dates = [];
1747
+ let prev = initial;
1748
+ for (let i = 0; i < weeks; i++) {
1749
+ const date = add(prev, { weeks: 1 });
1750
+ dates.push({
1751
+ week: i + 1,
1752
+ date: date.getTime()
1753
+ });
1754
+ prev = date.getTime();
1755
+ }
1756
+ return dates;
1757
+ }
1758
+ static getPreviousWeek() {
1759
+ const today = new Date().getTime();
1760
+ const week = ((3600 * 24) * 7) * 1000;
1761
+ return today - week;
1762
+ }
1763
+ static getDayNum(date) {
1764
+ return getDate(date);
1765
+ }
1766
+ static getDayName(date) {
1767
+ return format(date, "EEEE", { locale: es });
1768
+ }
1769
+ static getMonthName(date) {
1770
+ return format(date, "MMMM", { locale: es }).toUpperCase();
1771
+ }
1772
+ static getYear(date) {
1773
+ return format(date, "yyyy");
1774
+ }
1775
+ static GetNextPayment(time, provider) {
1776
+ let week = 0;
1777
+ if (provider == eProvider.Conekta) {
1778
+ week = (((3600 * 24) * 7));
1779
+ }
1780
+ else if (provider == eProvider.DynamiCore) {
1781
+ week = (((3600 * 24) * 7) * 1000);
1782
+ }
1783
+ return this.getLocalTimeFromLong(time + week, provider);
1784
+ }
1785
+ static getLocalTimeFromLong(time, provider) {
1786
+ if (time <= 0)
1787
+ return "";
1788
+ let factor = this.GetFactor(provider);
1789
+ let dateTime = time * factor;
1790
+ let parsedDate = format(new Date(dateTime), dateFormat, {
1791
+ locale: es
1792
+ });
1793
+ return parsedDate;
1794
+ }
1795
+ static DelayPaymentLast(lastPayment, provider, injector) {
1796
+ let factor = this.GetFactor(provider);
1797
+ let now = new Date().getTime();
1798
+ let last = 0;
1799
+ if (provider == eProvider.Conekta)
1800
+ last = ((((3600 * 24) * 7)) + lastPayment) * factor;
1801
+ else if (provider == eProvider.DynamiCore)
1802
+ last = ((((3600 * 24) * 7) * 1000) + lastPayment) * factor;
1803
+ runInInjectionContext(injector, () => {
1804
+ const idb = inject(IndexedDbService);
1805
+ // const observable = inject(ObservablesService)
1806
+ idb.setLocalStorage(expiredPayment, String(now > last));
1807
+ // observable.isLate.next(now > last)
1808
+ });
1809
+ // 1751091565767
1810
+ // 1751557440
1811
+ return now > last;
1812
+ }
1813
+ static GetFactor(provider) {
1814
+ let factor = 1;
1815
+ if (provider == eProvider.Conekta)
1816
+ factor = 1000;
1817
+ return factor;
1818
+ }
1819
+ static GetEpochFromFormatedDate(date) {
1820
+ if (date == "")
1821
+ return 0;
1822
+ const _date = new Date(date);
1823
+ if (isNaN(_date.getTime()))
1824
+ return 0;
1825
+ return _date.getTime();
1826
+ }
1827
+ static GetTimeFromString(date) {
1828
+ return format(new Date(date), timeFormat, {
1829
+ locale: es
1830
+ });
1831
+ }
1832
+ static GetDateFromString(date) {
1833
+ return format(new Date(date), dateCompleteFormat, {
1834
+ locale: es
1835
+ });
1836
+ }
1837
+ // Quick sort
1838
+ static SortingByTime(payments) {
1839
+ if (payments.length <= 1)
1840
+ return payments;
1841
+ const pivot = payments[payments.length - 1];
1842
+ const pivotDate = new Date(pivot.created).getTime();
1843
+ const left = [];
1844
+ const right = [];
1845
+ for (let i = 0; i < payments.length - 1; i++) {
1846
+ const actualDate = new Date(payments[i].created).getTime();
1847
+ if (actualDate > pivotDate)
1848
+ left.push(payments[i]);
1849
+ else
1850
+ right.push(payments[i]);
1851
+ }
1852
+ return [...this.SortingByTime(left), pivot, ...this.SortingByTime(right)];
1853
+ }
1854
+ static SortingByTimeConekta(payments) {
1855
+ if (payments.length <= 1)
1856
+ return payments;
1857
+ const pivot = payments[payments.length - 1];
1858
+ let pivotDate = 0;
1859
+ if (pivot.charges.data == undefined)
1860
+ return payments;
1861
+ if (pivot.charges.data[0].paid_at != undefined) {
1862
+ pivotDate = pivot.charges.data[0].paid_at;
1863
+ }
1864
+ else {
1865
+ pivot.charges.data[0].created_at;
1866
+ }
1867
+ if (pivotDate <= 0)
1868
+ return payments;
1869
+ const left = [];
1870
+ const right = [];
1871
+ for (let i = 0; i < payments.length - 1; i++) {
1872
+ const actual = payments[i].charges.data[0].paid_at;
1873
+ if (actual <= 0)
1874
+ continue;
1875
+ if (actual > pivotDate)
1876
+ left.push(payments[i]);
1877
+ else
1878
+ right.push(payments[i]);
1879
+ }
1880
+ return [...this.SortingByTimeConekta(left), pivot, ...this.SortingByTimeConekta(right)];
1881
+ }
1882
+ }
1883
+
1884
+ const cContractMetrics = {
1885
+ total: 0,
1886
+ activated: 0,
1887
+ paused: 0,
1888
+ completed: 0,
1889
+ canceled: 0,
1890
+ late: 0,
1891
+ conektaCount: 0,
1892
+ dynamicCount: 0,
1893
+ passportCount: 0,
1894
+ rateTotal: 0,
1895
+ rateActive: 0,
1896
+ ratePaused: 0,
1897
+ rateComplete: 0,
1898
+ rateCanceled: 0,
1899
+ rateLate: 0
1900
+ };
1901
+
1902
+ class FactoryPassport {
1903
+ static CreatePassportReference(client, contract, dateTime) {
1904
+ const o = {
1905
+ passport: {
1906
+ type: ePassportTypes.CREATE,
1907
+ data: {
1908
+ name: client.name,
1909
+ email: client.email,
1910
+ amount: contract.financial.weeklyPayment,
1911
+ expirationDate: "",
1912
+ additional: {
1913
+ client: client.name,
1914
+ clientID: client.id,
1915
+ credit: client.status
1916
+ }
1917
+ }
1918
+ },
1919
+ contract: contract,
1920
+ date: dateTime
1921
+ };
1922
+ if (dateTime != undefined)
1923
+ o.date = dateTime;
1924
+ return o;
1925
+ }
1926
+ }
1927
+
1928
+ class FactoryPayment {
1929
+ static CreatePayment(data, provider) {
1930
+ const o = {};
1931
+ if (provider == eProvider.DynamiCore)
1932
+ o.dynamicPayment = data;
1933
+ if (provider == eProvider.Conekta)
1934
+ o.conektaPayment = data;
1935
+ return o;
1936
+ }
1937
+ }
1938
+
1275
1939
  /*
1276
1940
  * Public API Surface of ravcredit-lib
1277
1941
  */
@@ -1280,5 +1944,5 @@ class FactoryDynamiCore {
1280
1944
  * Generated bundle index. Do not edit.
1281
1945
  */
1282
1946
 
1283
- export { FactoryBusiness, FactoryClient, FactoryContract, FactoryDynamiCore, RavcreditLibComponent, RavcreditLibService, cAddress, cAuthConfig, cBusinessConfig, cBusinessDeadlines, cBusinessInfo, cClient, cClientConekta, cClientContract, cClientDynamicStatus, cConektaRecurrent, cContract, cDefinedSchedule, cDevice, cEmptyDay, cFinancial, cIDCCharge, cIDCCustomer, cIDCDataPii, cIDCGeneratedReference, cIDCPayment, cNotification, cOptionsClientStatus, cOxxoRecurrentSources, cOxxorecurrentSourcesData, cPaymentDalay, cSchedule, cSingleOptionClientStatus, cTopic, cTyClientContract, cUserReference, eAccountDynamicStatus, eAuthActions, eAuthType, eClientDynamicStatus, eClientStatus, eConektaOrderStatus, eConektaRes, eContractSteps, eLoginStatus, eNotificationType, ePassportTypes, eProcessStatus, eProvider, eReferenceStatusRav, eRoles, eRolesSelect, snackBarConfigAction, snackBarConfigNoAction, week };
1947
+ export { FactoryBusiness, FactoryClient, FactoryConekta, FactoryContract, FactoryDynamiCore, FactoryNotification, FactoryPassport, FactoryPayment, IndexedDbService, ROUTE_GLOBAL_REFERENCE2, ROUTE_NOTIFICATIONS, RavcreditLibComponent, RavcreditLibService, UtilTime, UtilsHttp, cAddress, cAuthConfig, cBusinessConfig, cBusinessDeadlines, cBusinessInfo, cClient, cClientConekta, cClientContract, cClientDynamicStatus, cConektaRecurrent, cContract, cContractMetrics, cDefinedSchedule, cDevice, cEmptyDay, cFinancial, cIDCCharge, cIDCCustomer, cIDCDataPii, cIDCGeneratedReference, cIDCPayment, cNotification, cOptionsClientStatus, cOxxoRecurrentSources, cOxxorecurrentSourcesData, cPaymentDalay, cSchedule, cSingleOptionClientStatus, cTopic, cTyClientContract, cUserReference, dateCompleteFormat, dateFormat, dbAuthStore, dbBusinessConfig, dbBusinessInfo, dbClientsStore, dbConektaClientsStore, dbConektaReferencesStore, dbContractsStore, dbDynamicAccountStore, dbDynamicReferencesStore, dbIndexAuth, dbIndexBusiness, dbIndexClients, dbIndexConektaClients, dbIndexConektaClientsRef, dbIndexContracts, dbIndexNotification, dbIndexPassportClientsRef, dbIndexPayments, dbIndexUsers, dbName, dbNotificationsStore, dbPassportReferencesStore, dbPaymentsStore, dbUsersStore, dbVersion, eAccountDynamicStatus, eAuthActions, eAuthType, eClientDynamicStatus, eClientStatus, eConektaOrderStatus, eConektaRes, eContractSteps, eLoginStatus, eNotificationType, ePassportTypes, ePaymentType, eProcessStatus, eProvider, eReferenceStatusRav, eRoles, eRolesSelect, expiredPayment, keyPathId, keyUserID, ravCreditFunctions, snackBarConfigAction, snackBarConfigNoAction, timeFormat, week };
1284
1948
  //# sourceMappingURL=ravcredit-lib.mjs.map