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
@@ -6,6 +6,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var axios = _interopDefault(require('axios'));
8
8
  var FormData = _interopDefault(require('form-data'));
9
+ var axiosRetry = _interopDefault(require('axios-retry'));
9
10
 
10
11
  function _arrayLikeToArray(r, a) {
11
12
  (null == a || a > r.length) && (a = r.length);
@@ -369,7 +370,7 @@ var SFAuthenticator = /*#__PURE__*/function () {
369
370
  this.token = undefined;
370
371
  this.refreshToken = undefined;
371
372
  this.tokenRefreshPromise = null;
372
- this.axiosTokenInstance.defaults.baseURL = baseUrl != null ? baseUrl : 'https://do0000000d247eaa--phealth.sandbox.my.salesforce.com';
373
+ this.axiosTokenInstance.defaults.baseURL = baseUrl;
373
374
  this.authenticatedAxiosInstance = authenticatedAxiosInstance;
374
375
  }
375
376
  var _proto = SFAuthenticator.prototype;
@@ -1205,33 +1206,34 @@ function toExpense(raw) {
1205
1206
 
1206
1207
  var SF_API_VERSION = 'v57.0';
1207
1208
  var SFApiClient = /*#__PURE__*/function () {
1208
- function SFApiClient(baseUrl) {
1209
+ function SFApiClient() {
1209
1210
  this.instance = undefined;
1210
1211
  this.axiosInstance = axios.create();
1211
- this.baseUrl = baseUrl;
1212
- this.axiosInstance.defaults.baseURL = baseUrl != null ? baseUrl : 'https://do0000000d247eaa--phealth.sandbox.my.salesforce.com';
1213
- this.authenticator = new SFAuthenticator(this.axiosInstance, this.baseUrl);
1214
- this.timesheetClient = new SFTimesheetClient(this.axiosInstance);
1215
- this.workorderClient = new SFWorkorderClient(this.axiosInstance);
1216
- this.practitionerClient = new SFPractitionerClient(this.axiosInstance);
1217
- this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance);
1218
- this.expenseClient = new SFExpenseClient(this.axiosInstance);
1219
1212
  }
1220
1213
  var _proto = SFApiClient.prototype;
1221
1214
  _proto.init = /*#__PURE__*/function () {
1222
- var _init = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(sfClientId, sfClientSecret, onTokenRefresh) {
1215
+ var _init = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(baseUrl, sfClientId, sfClientSecret, onTokenRefresh) {
1223
1216
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1224
1217
  while (1) switch (_context.prev = _context.next) {
1225
1218
  case 0:
1226
- _context.next = 2;
1219
+ this.baseUrl = baseUrl;
1220
+ this.axiosInstance.defaults.baseURL = baseUrl;
1221
+ this.authenticator = new SFAuthenticator(this.axiosInstance, this.baseUrl);
1222
+ this.timesheetClient = new SFTimesheetClient(this.axiosInstance);
1223
+ this.workorderClient = new SFWorkorderClient(this.axiosInstance);
1224
+ this.practitionerClient = new SFPractitionerClient(this.axiosInstance);
1225
+ this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance);
1226
+ this.expenseClient = new SFExpenseClient(this.axiosInstance);
1227
+ // creates authenticator and adds token to axios instance
1228
+ _context.next = 10;
1227
1229
  return this.authenticator.initializeAuth(sfClientId, sfClientSecret, onTokenRefresh);
1228
- case 2:
1230
+ case 10:
1229
1231
  case "end":
1230
1232
  return _context.stop();
1231
1233
  }
1232
1234
  }, _callee, this);
1233
1235
  }));
1234
- function init(_x, _x2, _x3) {
1236
+ function init(_x, _x2, _x3, _x4) {
1235
1237
  return _init.apply(this, arguments);
1236
1238
  }
1237
1239
  return init;
@@ -1240,6 +1242,9 @@ var SFApiClient = /*#__PURE__*/function () {
1240
1242
  this.instance = instance;
1241
1243
  };
1242
1244
  _proto.getInstance = function getInstance() {
1245
+ if (!this.instance) {
1246
+ throw new Error('Salesforce Api client not initialized');
1247
+ }
1243
1248
  return this.instance;
1244
1249
  };
1245
1250
  _proto.fetchRoles = /*#__PURE__*/function () {
@@ -1292,6 +1297,12 @@ var LipheAuthenticator = /*#__PURE__*/function () {
1292
1297
  this.token = undefined;
1293
1298
  this.tokenRefreshPromise = null;
1294
1299
  this.authenticatedAxiosInstance = authenticatedAxiosInstance;
1300
+ axiosRetry(this.axiosTokenInstance, {
1301
+ retries: 10,
1302
+ retryDelay: function retryDelay(retryCount) {
1303
+ return Math.min(1000 * Math.pow(2, retryCount - 1), 30000);
1304
+ }
1305
+ });
1295
1306
  this.email = email;
1296
1307
  this.password = password;
1297
1308
  this.type = type;
@@ -1380,7 +1391,7 @@ var LipheAuthenticator = /*#__PURE__*/function () {
1380
1391
  form.append('password', this.password);
1381
1392
  form.append('type', this.type);
1382
1393
  _context3.next = 6;
1383
- return this.axiosTokenInstance.post('/v2/signin', form, {
1394
+ return this.axiosTokenInstance.post('v2/signin', form, {
1384
1395
  headers: form.getHeaders()
1385
1396
  });
1386
1397
  case 6:
@@ -1431,7 +1442,7 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1431
1442
  break;
1432
1443
  }
1433
1444
  _context.next = 7;
1434
- return this.axios.get('/v2/employees', {
1445
+ return this.axios.get('v2/employees', {
1435
1446
  params: {
1436
1447
  agency_id: agencyId,
1437
1448
  page: page
@@ -1461,7 +1472,15 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1461
1472
  _context.next = 4;
1462
1473
  break;
1463
1474
  case 17:
1464
- return _context.abrupt("return", practitioners);
1475
+ return _context.abrupt("return", practitioners.map(function (p) {
1476
+ return {
1477
+ id: String(p.id),
1478
+ firstName: p.firstname,
1479
+ lastName: p.lastname,
1480
+ email: p.email,
1481
+ staffId: String(p.id)
1482
+ };
1483
+ }));
1465
1484
  case 18:
1466
1485
  case "end":
1467
1486
  return _context.stop();
@@ -1476,6 +1495,200 @@ var LiphePractitionerClient = /*#__PURE__*/function () {
1476
1495
  return LiphePractitionerClient;
1477
1496
  }();
1478
1497
 
1498
+ var ContractRequestPeriodClient = /*#__PURE__*/function () {
1499
+ function ContractRequestPeriodClient(axiosInstance) {
1500
+ this.axiosInstance = axiosInstance;
1501
+ }
1502
+ var _proto = ContractRequestPeriodClient.prototype;
1503
+ _proto.fetchAllContractRequestPeriods = /*#__PURE__*/function () {
1504
+ var _fetchAllContractRequestPeriods = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(agencyId, from, to, page, activeAssignationsOnly, assignedPractitionerId) {
1505
+ var url, params, periods, nextPage, response, _iterator, _step, period;
1506
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1507
+ while (1) switch (_context.prev = _context.next) {
1508
+ case 0:
1509
+ if (page === void 0) {
1510
+ page = 1;
1511
+ }
1512
+ if (activeAssignationsOnly === void 0) {
1513
+ activeAssignationsOnly = true;
1514
+ }
1515
+ url = "v2/contract-request-periods/agency/" + agencyId;
1516
+ params = new URLSearchParams();
1517
+ periods = [];
1518
+ nextPage = true;
1519
+ if (from) {
1520
+ params.append('from', from.toISOString().split('T')[0] + ' 00:00:00');
1521
+ }
1522
+ if (to) {
1523
+ params.append('to', to.toISOString().split('T')[0] + ' 23:59:59');
1524
+ }
1525
+ if (page) {
1526
+ params.append('page', page.toString());
1527
+ }
1528
+ if (activeAssignationsOnly) {
1529
+ params.append('active_assignations_only', activeAssignationsOnly ? '1' : '0');
1530
+ }
1531
+ if (assignedPractitionerId) {
1532
+ params.append('assigned_employee_id', assignedPractitionerId);
1533
+ }
1534
+ case 11:
1535
+ if (!nextPage) {
1536
+ _context.next = 21;
1537
+ break;
1538
+ }
1539
+ params.set('page', page.toString());
1540
+ _context.next = 15;
1541
+ return this.axiosInstance.get(url, {
1542
+ params: params
1543
+ });
1544
+ case 15:
1545
+ response = _context.sent;
1546
+ for (_iterator = _createForOfIteratorHelperLoose(response.data.data); !(_step = _iterator()).done;) {
1547
+ period = _step.value;
1548
+ periods.push({
1549
+ id: period.id.toString(),
1550
+ name: period.id.toString(),
1551
+ establishmentId: period.contract_request.community.id.toString(),
1552
+ region: period.contract_request.community.contact.address_state,
1553
+ establishmentName: period.contract_request.community.name,
1554
+ role: this.getRole(period),
1555
+ practitionerId: period.assignment.selected_client.id,
1556
+ startDate: new Date(period.start_date),
1557
+ endDate: new Date(period.end_date),
1558
+ createdAt: new Date(period.created_at),
1559
+ updatedAt: new Date(period.updated_at)
1560
+ });
1561
+ }
1562
+ nextPage = page < response.data.meta.last_page;
1563
+ page++;
1564
+ _context.next = 11;
1565
+ break;
1566
+ case 21:
1567
+ return _context.abrupt("return", periods);
1568
+ case 22:
1569
+ case "end":
1570
+ return _context.stop();
1571
+ }
1572
+ }, _callee, this);
1573
+ }));
1574
+ function fetchAllContractRequestPeriods(_x, _x2, _x3, _x4, _x5, _x6) {
1575
+ return _fetchAllContractRequestPeriods.apply(this, arguments);
1576
+ }
1577
+ return fetchAllContractRequestPeriods;
1578
+ }();
1579
+ _proto.fetchContractRequestPeriod = /*#__PURE__*/function () {
1580
+ var _fetchContractRequestPeriod = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(workorderId) {
1581
+ var url, params, response;
1582
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1583
+ while (1) switch (_context2.prev = _context2.next) {
1584
+ case 0:
1585
+ url = "v2/contract-request-periods/" + workorderId;
1586
+ params = new URLSearchParams();
1587
+ _context2.next = 4;
1588
+ return this.axiosInstance.get(url, {
1589
+ params: params
1590
+ });
1591
+ case 4:
1592
+ response = _context2.sent;
1593
+ return _context2.abrupt("return", response.data.data);
1594
+ case 6:
1595
+ case "end":
1596
+ return _context2.stop();
1597
+ }
1598
+ }, _callee2, this);
1599
+ }));
1600
+ function fetchContractRequestPeriod(_x7) {
1601
+ return _fetchContractRequestPeriod.apply(this, arguments);
1602
+ }
1603
+ return fetchContractRequestPeriod;
1604
+ }();
1605
+ _proto.getPayPeriodDatesForPayPeriodId = /*#__PURE__*/function () {
1606
+ var _getPayPeriodDatesForPayPeriodId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payPeriodId) {
1607
+ var period, payPeriods, firstPayPeriodDate, lastPayPeriodDate, weeksBetween, i, tempDate, startDate, endDate;
1608
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1609
+ while (1) switch (_context3.prev = _context3.next) {
1610
+ case 0:
1611
+ _context3.next = 2;
1612
+ return this.fetchContractRequestPeriod(payPeriodId);
1613
+ case 2:
1614
+ period = _context3.sent;
1615
+ payPeriods = [];
1616
+ firstPayPeriodDate = this.getPayPeriodDayBeforeStartDate(new Date(period.assignment.selected_client.agency.date_first_periode_paie), new Date(period.start_date));
1617
+ lastPayPeriodDate = this.getLastDayOfPayPeriod(new Date(firstPayPeriodDate), new Date(period.end_date)); // Calculate the number of weeks between lastPayPeriodDate and firstPayPeriodDate
1618
+ weeksBetween = this.calculateWeeksBetween(firstPayPeriodDate, lastPayPeriodDate);
1619
+ for (i = 0; i < weeksBetween; i++) {
1620
+ tempDate = new Date(firstPayPeriodDate);
1621
+ startDate = new Date(tempDate.setDate(tempDate.getDate() + 7 * i));
1622
+ endDate = new Date(tempDate.setDate(tempDate.getDate() + 6));
1623
+ payPeriods.push({
1624
+ payPeriodId: '',
1625
+ startDate: startDate.toISOString().split('T')[0],
1626
+ endDate: endDate.toISOString().split('T')[0],
1627
+ workorderId: payPeriodId
1628
+ });
1629
+ }
1630
+ return _context3.abrupt("return", payPeriods);
1631
+ case 9:
1632
+ case "end":
1633
+ return _context3.stop();
1634
+ }
1635
+ }, _callee3, this);
1636
+ }));
1637
+ function getPayPeriodDatesForPayPeriodId(_x8) {
1638
+ return _getPayPeriodDatesForPayPeriodId.apply(this, arguments);
1639
+ }
1640
+ return getPayPeriodDatesForPayPeriodId;
1641
+ }();
1642
+ _proto.getRole = function getRole(period) {
1643
+ if (period.contract_request.job.translations.length === 0) {
1644
+ return '';
1645
+ }
1646
+ if (period.contract_request.job.translations.length > 1) {
1647
+ var roleTranslation = period.contract_request.job.translations.find(function (translation) {
1648
+ return translation.locale === 'en';
1649
+ });
1650
+ return roleTranslation == null ? void 0 : roleTranslation.content;
1651
+ } else {
1652
+ return period.contract_request.job.translations[0].content;
1653
+ }
1654
+ }
1655
+ /**
1656
+ * Calculates the pay period day of week that comes before the start date
1657
+ * @param firstPayPeriodDate The first pay period date from the agency
1658
+ * @param startDate The start date to find the pay period before
1659
+ * @returns The day of week (0-6, where 0 is Sunday) of the pay period before start_date
1660
+ */;
1661
+ _proto.getPayPeriodDayBeforeStartDate = function getPayPeriodDayBeforeStartDate(firstPayPeriodDate, startDate) {
1662
+ var payPeriodDayOfWeek = firstPayPeriodDate.getDay();
1663
+ // Calculate the most recent pay period date that falls before start_date
1664
+ var tempDate = new Date(startDate);
1665
+ // Go back one week at a time until we find a date that matches the pay period day of week
1666
+ while (tempDate.getDay() !== payPeriodDayOfWeek) {
1667
+ tempDate.setDate(tempDate.getDate() - 1);
1668
+ }
1669
+ // If the calculated date is not before start_date, go back another week
1670
+ if (tempDate >= startDate) {
1671
+ tempDate.setDate(tempDate.getDate() - 7);
1672
+ }
1673
+ return tempDate;
1674
+ };
1675
+ _proto.getLastDayOfPayPeriod = function getLastDayOfPayPeriod(firstPayPeriodDate, endDate) {
1676
+ var tempDate = new Date(firstPayPeriodDate);
1677
+ // Go back one week at a time until we find a date that matches the pay period day of week
1678
+ while (endDate > tempDate) {
1679
+ tempDate.setDate(tempDate.getDate() + 7);
1680
+ }
1681
+ return tempDate;
1682
+ };
1683
+ _proto.calculateWeeksBetween = function calculateWeeksBetween(startDate, endDate) {
1684
+ var diffTime = Math.abs(endDate.getTime() - startDate.getTime());
1685
+ var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
1686
+ var weeks = Math.floor(diffDays / 7);
1687
+ return weeks;
1688
+ };
1689
+ return ContractRequestPeriodClient;
1690
+ }();
1691
+
1479
1692
  var LipheApiClient = /*#__PURE__*/function () {
1480
1693
  function LipheApiClient(baseUrl, email, password, type) {
1481
1694
  if (type === void 0) {
@@ -1485,7 +1698,17 @@ var LipheApiClient = /*#__PURE__*/function () {
1485
1698
  this.axiosInstance = axios.create();
1486
1699
  this.axiosInstance.defaults.baseURL = baseUrl;
1487
1700
  this.authenticator = new LipheAuthenticator(this.axiosInstance, baseUrl, email, password, type);
1701
+ axiosRetry(this.axiosInstance, {
1702
+ retries: 10,
1703
+ retryDelay: function retryDelay(retryCount) {
1704
+ return Math.min(1000 * Math.pow(2, retryCount - 1), 30000);
1705
+ },
1706
+ onRetry: function onRetry(retryCount, error) {
1707
+ console.log("Retry attempt " + retryCount + " failed: " + error.message);
1708
+ }
1709
+ });
1488
1710
  this.practitionerClient = new LiphePractitionerClient(this.axiosInstance);
1711
+ this.contractRequestPeriodClient = new ContractRequestPeriodClient(this.axiosInstance);
1489
1712
  }
1490
1713
  var _proto = LipheApiClient.prototype;
1491
1714
  _proto.init = /*#__PURE__*/function () {
@@ -1518,6 +1741,19 @@ var LipheApiClient = /*#__PURE__*/function () {
1518
1741
  return LipheApiClient;
1519
1742
  }();
1520
1743
 
1744
+ (function (Agency) {
1745
+ Agency["CHCA"] = "7";
1746
+ Agency["CodeBleu"] = "5";
1747
+ Agency["NordikOntario"] = "6";
1748
+ Agency["PHA"] = "8";
1749
+ Agency["PremierSoin"] = "1";
1750
+ Agency["PremierSoinNordik"] = "3";
1751
+ Agency["SolutionNursing"] = "4";
1752
+ Agency["SolutionsStaffing"] = "9";
1753
+ Agency["Transport"] = "2";
1754
+ Agency["SSI"] = "99";
1755
+ })(exports.Agency || (exports.Agency = {}));
1756
+
1521
1757
  exports.LipheApiClient = LipheApiClient;
1522
1758
  exports.LipheAuthenticator = LipheAuthenticator;
1523
1759
  exports.LiphePractitionerClient = LiphePractitionerClient;