pha-hermes 1.15.0 → 1.17.0

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 (43) hide show
  1. package/dist/api/expenses/expenseClient.d.ts +1 -1
  2. package/dist/api/liphe_legacy/assignment/assignmentClient.d.ts +28 -0
  3. package/dist/api/{liphe1.0 → liphe_legacy}/auth/authClient.d.ts +1 -1
  4. package/dist/api/liphe_legacy/contract_request/contractRequestClient.d.ts +80 -0
  5. package/dist/api/liphe_legacy/contract_request_period/contractRequestPeriodClient.d.ts +47 -0
  6. package/dist/api/{lipheApiClient.d.ts → liphe_legacy/lipheApiClient.d.ts} +4 -2
  7. package/dist/api/liphe_legacy/practitioner/practitionerClient.d.ts +7 -0
  8. package/dist/api/{apiClient.d.ts → salesforce/apiClient.d.ts} +3 -4
  9. package/dist/api/{auth → salesforce/auth}/auth.d.ts +1 -1
  10. package/dist/api/{payperiod → salesforce/payperiod}/payperiodClient.d.ts +1 -7
  11. package/dist/api/{practitioner → salesforce/practitioner}/practitionerClient.d.ts +1 -1
  12. package/dist/api/{timesheet → salesforce/timesheet}/timesheetClient.d.ts +1 -1
  13. package/dist/api/{workorder → salesforce/workorder}/workorderClient.d.ts +1 -1
  14. package/dist/index.d.ts +8 -8
  15. package/dist/models/index.d.ts +13 -17
  16. package/dist/models/{practitioner.d.ts → user.d.ts} +4 -0
  17. package/dist/models/workorder.d.ts +20 -0
  18. package/dist/pha-hermes.cjs.development.js +253 -17
  19. package/dist/pha-hermes.cjs.development.js.map +1 -1
  20. package/dist/pha-hermes.cjs.production.min.js +1 -1
  21. package/dist/pha-hermes.cjs.production.min.js.map +1 -1
  22. package/dist/pha-hermes.esm.js +255 -18
  23. package/dist/pha-hermes.esm.js.map +1 -1
  24. package/package.json +2 -1
  25. package/src/api/expenses/expenseClient.ts +2 -2
  26. package/src/api/liphe_legacy/assignment/assignmentClient.ts +67 -0
  27. package/src/api/{liphe1.0 → liphe_legacy}/auth/authClient.ts +11 -2
  28. package/src/api/liphe_legacy/contract_request/contractRequestClient.ts +128 -0
  29. package/src/api/liphe_legacy/contract_request_period/contractRequestPeriodClient.ts +233 -0
  30. package/src/api/{lipheApiClient.ts → liphe_legacy/lipheApiClient.ts} +23 -3
  31. package/src/api/{liphe1.0 → liphe_legacy}/practitioner/practitionerClient.ts +12 -4
  32. package/src/api/{apiClient.ts → salesforce/apiClient.ts} +12 -12
  33. package/src/api/{auth → salesforce/auth}/auth.ts +2 -5
  34. package/src/api/{payperiod → salesforce/payperiod}/payperiodClient.ts +1 -8
  35. package/src/api/{practitioner → salesforce/practitioner}/practitionerClient.ts +1 -1
  36. package/src/api/{timesheet → salesforce/timesheet}/timesheetClient.ts +1 -1
  37. package/src/api/{workorder → salesforce/workorder}/workorderClient.ts +1 -1
  38. package/src/index.ts +13 -8
  39. package/src/models/index.ts +13 -18
  40. package/src/models/{practitioner.ts → user.ts} +5 -0
  41. package/src/models/workorder.ts +21 -0
  42. package/dist/api/liphe1.0/practitioner/practitionerClient.d.ts +0 -13
  43. package/src/api/.env +0 -5
@@ -1,5 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import FormData from 'form-data';
3
+ import axiosRetry from 'axios-retry';
3
4
 
4
5
  function _arrayLikeToArray(r, a) {
5
6
  (null == a || a > r.length) && (a = r.length);
@@ -363,7 +364,7 @@ var SFAuthenticator = /*#__PURE__*/function () {
363
364
  this.token = undefined;
364
365
  this.refreshToken = undefined;
365
366
  this.tokenRefreshPromise = null;
366
- this.axiosTokenInstance.defaults.baseURL = baseUrl != null ? baseUrl : 'https://do0000000d247eaa--phealth.sandbox.my.salesforce.com';
367
+ this.axiosTokenInstance.defaults.baseURL = baseUrl;
367
368
  this.authenticatedAxiosInstance = authenticatedAxiosInstance;
368
369
  }
369
370
  var _proto = SFAuthenticator.prototype;
@@ -1199,33 +1200,34 @@ function toExpense(raw) {
1199
1200
 
1200
1201
  var SF_API_VERSION = 'v57.0';
1201
1202
  var SFApiClient = /*#__PURE__*/function () {
1202
- function SFApiClient(baseUrl) {
1203
+ function SFApiClient() {
1203
1204
  this.instance = undefined;
1204
1205
  this.axiosInstance = axios.create();
1205
- this.baseUrl = baseUrl;
1206
- this.axiosInstance.defaults.baseURL = baseUrl != null ? baseUrl : 'https://do0000000d247eaa--phealth.sandbox.my.salesforce.com';
1207
- this.authenticator = new SFAuthenticator(this.axiosInstance, this.baseUrl);
1208
- this.timesheetClient = new SFTimesheetClient(this.axiosInstance);
1209
- this.workorderClient = new SFWorkorderClient(this.axiosInstance);
1210
- this.practitionerClient = new SFPractitionerClient(this.axiosInstance);
1211
- this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance);
1212
- this.expenseClient = new SFExpenseClient(this.axiosInstance);
1213
1206
  }
1214
1207
  var _proto = SFApiClient.prototype;
1215
1208
  _proto.init = /*#__PURE__*/function () {
1216
- var _init = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(sfClientId, sfClientSecret, onTokenRefresh) {
1209
+ var _init = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(baseUrl, sfClientId, sfClientSecret, onTokenRefresh) {
1217
1210
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1218
1211
  while (1) switch (_context.prev = _context.next) {
1219
1212
  case 0:
1220
- _context.next = 2;
1213
+ this.baseUrl = baseUrl;
1214
+ this.axiosInstance.defaults.baseURL = baseUrl;
1215
+ this.authenticator = new SFAuthenticator(this.axiosInstance, this.baseUrl);
1216
+ this.timesheetClient = new SFTimesheetClient(this.axiosInstance);
1217
+ this.workorderClient = new SFWorkorderClient(this.axiosInstance);
1218
+ this.practitionerClient = new SFPractitionerClient(this.axiosInstance);
1219
+ this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance);
1220
+ this.expenseClient = new SFExpenseClient(this.axiosInstance);
1221
+ // creates authenticator and adds token to axios instance
1222
+ _context.next = 10;
1221
1223
  return this.authenticator.initializeAuth(sfClientId, sfClientSecret, onTokenRefresh);
1222
- case 2:
1224
+ case 10:
1223
1225
  case "end":
1224
1226
  return _context.stop();
1225
1227
  }
1226
1228
  }, _callee, this);
1227
1229
  }));
1228
- function init(_x, _x2, _x3) {
1230
+ function init(_x, _x2, _x3, _x4) {
1229
1231
  return _init.apply(this, arguments);
1230
1232
  }
1231
1233
  return init;
@@ -1234,6 +1236,9 @@ var SFApiClient = /*#__PURE__*/function () {
1234
1236
  this.instance = instance;
1235
1237
  };
1236
1238
  _proto.getInstance = function getInstance() {
1239
+ if (!this.instance) {
1240
+ throw new Error('Salesforce Api client not initialized');
1241
+ }
1237
1242
  return this.instance;
1238
1243
  };
1239
1244
  _proto.fetchRoles = /*#__PURE__*/function () {
@@ -1286,6 +1291,12 @@ var LipheAuthenticator = /*#__PURE__*/function () {
1286
1291
  this.token = undefined;
1287
1292
  this.tokenRefreshPromise = null;
1288
1293
  this.authenticatedAxiosInstance = authenticatedAxiosInstance;
1294
+ axiosRetry(this.axiosTokenInstance, {
1295
+ retries: 10,
1296
+ retryDelay: function retryDelay(retryCount) {
1297
+ return Math.min(1000 * Math.pow(2, retryCount - 1), 30000);
1298
+ }
1299
+ });
1289
1300
  this.email = email;
1290
1301
  this.password = password;
1291
1302
  this.type = type;
@@ -1374,7 +1385,7 @@ var LipheAuthenticator = /*#__PURE__*/function () {
1374
1385
  form.append('password', this.password);
1375
1386
  form.append('type', this.type);
1376
1387
  _context3.next = 6;
1377
- return this.axiosTokenInstance.post('/v2/signin', form, {
1388
+ return this.axiosTokenInstance.post('v2/signin', form, {
1378
1389
  headers: form.getHeaders()
1379
1390
  });
1380
1391
  case 6:
@@ -1425,7 +1436,7 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1425
1436
  break;
1426
1437
  }
1427
1438
  _context.next = 7;
1428
- return this.axios.get('/v2/employees', {
1439
+ return this.axios.get('v2/employees', {
1429
1440
  params: {
1430
1441
  agency_id: agencyId,
1431
1442
  page: page
@@ -1455,7 +1466,15 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1455
1466
  _context.next = 4;
1456
1467
  break;
1457
1468
  case 17:
1458
- return _context.abrupt("return", practitioners);
1469
+ return _context.abrupt("return", practitioners.map(function (p) {
1470
+ return {
1471
+ id: String(p.id),
1472
+ firstName: p.firstname,
1473
+ lastName: p.lastname,
1474
+ email: p.email,
1475
+ staffId: String(p.id)
1476
+ };
1477
+ }));
1459
1478
  case 18:
1460
1479
  case "end":
1461
1480
  return _context.stop();
@@ -1470,6 +1489,200 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1470
1489
  return LiphePractitionerClient;
1471
1490
  }();
1472
1491
 
1492
+ var ContractRequestPeriodClient = /*#__PURE__*/function () {
1493
+ function ContractRequestPeriodClient(axiosInstance) {
1494
+ this.axiosInstance = axiosInstance;
1495
+ }
1496
+ var _proto = ContractRequestPeriodClient.prototype;
1497
+ _proto.fetchAllContractRequestPeriods = /*#__PURE__*/function () {
1498
+ var _fetchAllContractRequestPeriods = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(agencyId, from, to, page, activeAssignationsOnly, assignedPractitionerId) {
1499
+ var url, params, periods, nextPage, response, _iterator, _step, period;
1500
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1501
+ while (1) switch (_context.prev = _context.next) {
1502
+ case 0:
1503
+ if (page === void 0) {
1504
+ page = 1;
1505
+ }
1506
+ if (activeAssignationsOnly === void 0) {
1507
+ activeAssignationsOnly = true;
1508
+ }
1509
+ url = "v2/contract-request-periods/agency/" + agencyId;
1510
+ params = new URLSearchParams();
1511
+ periods = [];
1512
+ nextPage = true;
1513
+ if (from) {
1514
+ params.append('from', from.toISOString().split('T')[0] + ' 00:00:00');
1515
+ }
1516
+ if (to) {
1517
+ params.append('to', to.toISOString().split('T')[0] + ' 23:59:59');
1518
+ }
1519
+ if (page) {
1520
+ params.append('page', page.toString());
1521
+ }
1522
+ if (activeAssignationsOnly) {
1523
+ params.append('active_assignations_only', activeAssignationsOnly ? '1' : '0');
1524
+ }
1525
+ if (assignedPractitionerId) {
1526
+ params.append('assigned_employee_id', assignedPractitionerId);
1527
+ }
1528
+ case 11:
1529
+ if (!nextPage) {
1530
+ _context.next = 21;
1531
+ break;
1532
+ }
1533
+ params.set('page', page.toString());
1534
+ _context.next = 15;
1535
+ return this.axiosInstance.get(url, {
1536
+ params: params
1537
+ });
1538
+ case 15:
1539
+ response = _context.sent;
1540
+ for (_iterator = _createForOfIteratorHelperLoose(response.data.data); !(_step = _iterator()).done;) {
1541
+ period = _step.value;
1542
+ periods.push({
1543
+ id: period.id.toString(),
1544
+ name: period.id.toString(),
1545
+ establishmentId: period.contract_request.community.id.toString(),
1546
+ region: period.contract_request.community.contact.address_state,
1547
+ establishmentName: period.contract_request.community.name,
1548
+ role: this.getRole(period),
1549
+ practitionerId: period.assignment.selected_client.id,
1550
+ startDate: new Date(period.start_date),
1551
+ endDate: new Date(period.end_date),
1552
+ createdAt: new Date(period.created_at),
1553
+ updatedAt: new Date(period.updated_at)
1554
+ });
1555
+ }
1556
+ nextPage = page < response.data.meta.last_page;
1557
+ page++;
1558
+ _context.next = 11;
1559
+ break;
1560
+ case 21:
1561
+ return _context.abrupt("return", periods);
1562
+ case 22:
1563
+ case "end":
1564
+ return _context.stop();
1565
+ }
1566
+ }, _callee, this);
1567
+ }));
1568
+ function fetchAllContractRequestPeriods(_x, _x2, _x3, _x4, _x5, _x6) {
1569
+ return _fetchAllContractRequestPeriods.apply(this, arguments);
1570
+ }
1571
+ return fetchAllContractRequestPeriods;
1572
+ }();
1573
+ _proto.fetchContractRequestPeriod = /*#__PURE__*/function () {
1574
+ var _fetchContractRequestPeriod = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(workorderId) {
1575
+ var url, params, response;
1576
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1577
+ while (1) switch (_context2.prev = _context2.next) {
1578
+ case 0:
1579
+ url = "v2/contract-request-periods/" + workorderId;
1580
+ params = new URLSearchParams();
1581
+ _context2.next = 4;
1582
+ return this.axiosInstance.get(url, {
1583
+ params: params
1584
+ });
1585
+ case 4:
1586
+ response = _context2.sent;
1587
+ return _context2.abrupt("return", response.data.data);
1588
+ case 6:
1589
+ case "end":
1590
+ return _context2.stop();
1591
+ }
1592
+ }, _callee2, this);
1593
+ }));
1594
+ function fetchContractRequestPeriod(_x7) {
1595
+ return _fetchContractRequestPeriod.apply(this, arguments);
1596
+ }
1597
+ return fetchContractRequestPeriod;
1598
+ }();
1599
+ _proto.getPayPeriodDatesForPayPeriodId = /*#__PURE__*/function () {
1600
+ var _getPayPeriodDatesForPayPeriodId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payPeriodId) {
1601
+ var period, payPeriods, firstPayPeriodDate, lastPayPeriodDate, weeksBetween, i, tempDate, startDate, endDate;
1602
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1603
+ while (1) switch (_context3.prev = _context3.next) {
1604
+ case 0:
1605
+ _context3.next = 2;
1606
+ return this.fetchContractRequestPeriod(payPeriodId);
1607
+ case 2:
1608
+ period = _context3.sent;
1609
+ payPeriods = [];
1610
+ firstPayPeriodDate = this.getPayPeriodDayBeforeStartDate(new Date(period.assignment.selected_client.agency.date_first_periode_paie), new Date(period.start_date));
1611
+ lastPayPeriodDate = this.getLastDayOfPayPeriod(new Date(firstPayPeriodDate), new Date(period.end_date)); // Calculate the number of weeks between lastPayPeriodDate and firstPayPeriodDate
1612
+ weeksBetween = this.calculateWeeksBetween(firstPayPeriodDate, lastPayPeriodDate);
1613
+ for (i = 0; i < weeksBetween; i++) {
1614
+ tempDate = new Date(firstPayPeriodDate);
1615
+ startDate = new Date(tempDate.setDate(tempDate.getDate() + 7 * i));
1616
+ endDate = new Date(tempDate.setDate(tempDate.getDate() + 6));
1617
+ payPeriods.push({
1618
+ payPeriodId: '',
1619
+ startDate: startDate.toISOString().split('T')[0],
1620
+ endDate: endDate.toISOString().split('T')[0],
1621
+ workorderId: payPeriodId
1622
+ });
1623
+ }
1624
+ return _context3.abrupt("return", payPeriods);
1625
+ case 9:
1626
+ case "end":
1627
+ return _context3.stop();
1628
+ }
1629
+ }, _callee3, this);
1630
+ }));
1631
+ function getPayPeriodDatesForPayPeriodId(_x8) {
1632
+ return _getPayPeriodDatesForPayPeriodId.apply(this, arguments);
1633
+ }
1634
+ return getPayPeriodDatesForPayPeriodId;
1635
+ }();
1636
+ _proto.getRole = function getRole(period) {
1637
+ if (period.contract_request.job.translations.length === 0) {
1638
+ return '';
1639
+ }
1640
+ if (period.contract_request.job.translations.length > 1) {
1641
+ var roleTranslation = period.contract_request.job.translations.find(function (translation) {
1642
+ return translation.locale === 'en';
1643
+ });
1644
+ return roleTranslation == null ? void 0 : roleTranslation.content;
1645
+ } else {
1646
+ return period.contract_request.job.translations[0].content;
1647
+ }
1648
+ }
1649
+ /**
1650
+ * Calculates the pay period day of week that comes before the start date
1651
+ * @param firstPayPeriodDate The first pay period date from the agency
1652
+ * @param startDate The start date to find the pay period before
1653
+ * @returns The day of week (0-6, where 0 is Sunday) of the pay period before start_date
1654
+ */;
1655
+ _proto.getPayPeriodDayBeforeStartDate = function getPayPeriodDayBeforeStartDate(firstPayPeriodDate, startDate) {
1656
+ var payPeriodDayOfWeek = firstPayPeriodDate.getDay();
1657
+ // Calculate the most recent pay period date that falls before start_date
1658
+ var tempDate = new Date(startDate);
1659
+ // Go back one week at a time until we find a date that matches the pay period day of week
1660
+ while (tempDate.getDay() !== payPeriodDayOfWeek) {
1661
+ tempDate.setDate(tempDate.getDate() - 1);
1662
+ }
1663
+ // If the calculated date is not before start_date, go back another week
1664
+ if (tempDate >= startDate) {
1665
+ tempDate.setDate(tempDate.getDate() - 7);
1666
+ }
1667
+ return tempDate;
1668
+ };
1669
+ _proto.getLastDayOfPayPeriod = function getLastDayOfPayPeriod(firstPayPeriodDate, endDate) {
1670
+ var tempDate = new Date(firstPayPeriodDate);
1671
+ // Go back one week at a time until we find a date that matches the pay period day of week
1672
+ while (endDate > tempDate) {
1673
+ tempDate.setDate(tempDate.getDate() + 7);
1674
+ }
1675
+ return tempDate;
1676
+ };
1677
+ _proto.calculateWeeksBetween = function calculateWeeksBetween(startDate, endDate) {
1678
+ var diffTime = Math.abs(endDate.getTime() - startDate.getTime());
1679
+ var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
1680
+ var weeks = Math.floor(diffDays / 7);
1681
+ return weeks;
1682
+ };
1683
+ return ContractRequestPeriodClient;
1684
+ }();
1685
+
1473
1686
  var LipheApiClient = /*#__PURE__*/function () {
1474
1687
  function LipheApiClient(baseUrl, email, password, type) {
1475
1688
  if (type === void 0) {
@@ -1479,7 +1692,17 @@ var LipheApiClient = /*#__PURE__*/function () {
1479
1692
  this.axiosInstance = axios.create();
1480
1693
  this.axiosInstance.defaults.baseURL = baseUrl;
1481
1694
  this.authenticator = new LipheAuthenticator(this.axiosInstance, baseUrl, email, password, type);
1695
+ axiosRetry(this.axiosInstance, {
1696
+ retries: 10,
1697
+ retryDelay: function retryDelay(retryCount) {
1698
+ return Math.min(1000 * Math.pow(2, retryCount - 1), 30000);
1699
+ },
1700
+ onRetry: function onRetry(retryCount, error) {
1701
+ console.log("Retry attempt " + retryCount + " failed: " + error.message);
1702
+ }
1703
+ });
1482
1704
  this.practitionerClient = new LiphePractitionerClient(this.axiosInstance);
1705
+ this.contractRequestPeriodClient = new ContractRequestPeriodClient(this.axiosInstance);
1483
1706
  }
1484
1707
  var _proto = LipheApiClient.prototype;
1485
1708
  _proto.init = /*#__PURE__*/function () {
@@ -1512,5 +1735,19 @@ var LipheApiClient = /*#__PURE__*/function () {
1512
1735
  return LipheApiClient;
1513
1736
  }();
1514
1737
 
1515
- export { LipheApiClient, LipheAuthenticator, LiphePractitionerClient, SFApiClient, SFAuthenticator, SFExpenseClient, SFPractitionerClient, SFTimesheetClient };
1738
+ var Agency;
1739
+ (function (Agency) {
1740
+ Agency["CHCA"] = "7";
1741
+ Agency["CodeBleu"] = "5";
1742
+ Agency["NordikOntario"] = "6";
1743
+ Agency["PHA"] = "8";
1744
+ Agency["PremierSoin"] = "1";
1745
+ Agency["PremierSoinNordik"] = "3";
1746
+ Agency["SolutionNursing"] = "4";
1747
+ Agency["SolutionsStaffing"] = "9";
1748
+ Agency["Transport"] = "2";
1749
+ Agency["SSI"] = "99";
1750
+ })(Agency || (Agency = {}));
1751
+
1752
+ export { Agency, LipheApiClient, LipheAuthenticator, LiphePractitionerClient, SFApiClient, SFAuthenticator, SFExpenseClient, SFPractitionerClient, SFTimesheetClient };
1516
1753
  //# sourceMappingURL=pha-hermes.esm.js.map