pha-hermes 1.25.0 → 1.26.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.
@@ -0,0 +1,38 @@
1
+ import { AxiosInstance } from "axios";
2
+ export interface Account {
3
+ id: string;
4
+ name: string;
5
+ accountTypeName: AccountType;
6
+ regionName: string;
7
+ geographicalAreaName: string | null;
8
+ address: string | null;
9
+ city: string | null;
10
+ province: string | null;
11
+ postalCode: string | null;
12
+ phone: string | null;
13
+ phone2: string | null;
14
+ cellular: string | null;
15
+ fax: string | null;
16
+ email: string;
17
+ lang: 'eng' | 'fra';
18
+ }
19
+ export interface HealthAuthority extends Account {
20
+ accountTypeName: 'healthAuthority';
21
+ children: Establishment[];
22
+ }
23
+ export interface Establishment extends Account {
24
+ accountTypeName: 'establishment';
25
+ }
26
+ declare type AccountType = 'healthAuthority' | 'establishment';
27
+ export declare class SFAccounts {
28
+ private axiosInstance;
29
+ constructor(axiosInstance: AxiosInstance);
30
+ fetchAccounts<T extends Account>(type: AccountType, options?: {
31
+ parentId?: string;
32
+ pageSize?: number;
33
+ pageNumber?: number;
34
+ failfast?: boolean;
35
+ }): Promise<T[]>;
36
+ private buildAccount;
37
+ }
38
+ export {};
@@ -5,6 +5,7 @@ import { SFWorkorderClient } from './workorder/workorderClient';
5
5
  import { SFPayPeriodClient } from './payperiod/payperiodClient';
6
6
  import { SFExpenseClient } from './expenses/expenseClient';
7
7
  import { SFPriceClient } from './prices/priceClient';
8
+ import { SFAccounts } from './accounts/accounts';
8
9
  export declare const SF_API_VERSION: string;
9
10
  export declare class SFApiClient {
10
11
  private instance;
@@ -17,6 +18,7 @@ export declare class SFApiClient {
17
18
  payPeriodClient: SFPayPeriodClient;
18
19
  expenseClient: SFExpenseClient;
19
20
  priceClient: SFPriceClient;
21
+ accountsClient: SFAccounts;
20
22
  init(baseUrl: string, sfClientId: string, sfClientSecret: string, onTokenRefresh?: () => Promise<{
21
23
  clientId: string;
22
24
  clientSecret: string;
@@ -1360,6 +1360,131 @@ var SFPriceClient = /*#__PURE__*/function () {
1360
1360
  return SFPriceClient;
1361
1361
  }();
1362
1362
 
1363
+ var ACCOUNT_FIELDS = ['Id', 'Name', 'BillingCity', 'BillingState', 'BillingPostalCode', 'BillingCountry', 'BillingAddress', 'Phone', 'Fax', 'Type'];
1364
+ var SFAccounts = /*#__PURE__*/function () {
1365
+ function SFAccounts(axiosInstance) {
1366
+ this.axiosInstance = axiosInstance;
1367
+ }
1368
+ var _proto = SFAccounts.prototype;
1369
+ _proto.fetchAccounts = /*#__PURE__*/function () {
1370
+ var _fetchAccounts = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(type, options) {
1371
+ var _this = this;
1372
+ var accountType, query, response, accounts, i, pageNumber, childAccounts, returnedPageSize, _options$pageSize, pageAccounts;
1373
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1374
+ while (1) switch (_context.prev = _context.next) {
1375
+ case 0:
1376
+ _context.prev = 0;
1377
+ _context.t0 = type;
1378
+ _context.next = _context.t0 === 'healthAuthority' ? 4 : _context.t0 === 'establishment' ? 6 : 7;
1379
+ break;
1380
+ case 4:
1381
+ accountType = 'Health Authority';
1382
+ return _context.abrupt("break", 7);
1383
+ case 6:
1384
+ accountType = 'Hospital';
1385
+ case 7:
1386
+ query = "SELECT " + ACCOUNT_FIELDS.join(',') + " FROM Account WHERE Type = '" + accountType + "'";
1387
+ if (options != null && options.parentId) query += " AND ParentId = '" + options.parentId + "'";
1388
+ if (options != null && options.pageSize) query += " LIMIT " + options.pageSize;
1389
+ if (options != null && options.pageNumber) query += " OFFSET " + options.pageNumber * options.pageSize;
1390
+ _context.next = 13;
1391
+ return this.axiosInstance.get("/services/data/v57.0/query?q=" + query);
1392
+ case 13:
1393
+ response = _context.sent;
1394
+ accounts = response.data.records.map(function (record) {
1395
+ return _this.buildAccount(record);
1396
+ });
1397
+ _context.t1 = _regeneratorRuntime().keys(accounts);
1398
+ case 16:
1399
+ if ((_context.t2 = _context.t1()).done) {
1400
+ _context.next = 32;
1401
+ break;
1402
+ }
1403
+ i = _context.t2.value;
1404
+ if (!(accounts[i].accountTypeName === 'healthAuthority')) {
1405
+ _context.next = 30;
1406
+ break;
1407
+ }
1408
+ pageNumber = 0;
1409
+ childAccounts = [];
1410
+ returnedPageSize = 0;
1411
+ case 22:
1412
+ _context.next = 24;
1413
+ return this.fetchAccounts('establishment', {
1414
+ parentId: accounts[i].id,
1415
+ pageSize: (_options$pageSize = options == null ? void 0 : options.pageSize) != null ? _options$pageSize : 100,
1416
+ pageNumber: pageNumber,
1417
+ failfast: options == null ? void 0 : options.failfast
1418
+ });
1419
+ case 24:
1420
+ pageAccounts = _context.sent;
1421
+ childAccounts.push.apply(childAccounts, pageAccounts);
1422
+ returnedPageSize = pageAccounts.length;
1423
+ pageNumber++;
1424
+ case 28:
1425
+ if (returnedPageSize > 0) {
1426
+ _context.next = 22;
1427
+ break;
1428
+ }
1429
+ case 29:
1430
+ accounts[i].children = childAccounts;
1431
+ case 30:
1432
+ _context.next = 16;
1433
+ break;
1434
+ case 32:
1435
+ return _context.abrupt("return", accounts);
1436
+ case 35:
1437
+ _context.prev = 35;
1438
+ _context.t3 = _context["catch"](0);
1439
+ console.error("Error fetching " + type + "s: ", _context.t3.message);
1440
+ if (!(options != null && options.failfast)) {
1441
+ _context.next = 40;
1442
+ break;
1443
+ }
1444
+ throw _context.t3;
1445
+ case 40:
1446
+ return _context.abrupt("return", []);
1447
+ case 41:
1448
+ case "end":
1449
+ return _context.stop();
1450
+ }
1451
+ }, _callee, this, [[0, 35]]);
1452
+ }));
1453
+ function fetchAccounts(_x, _x2) {
1454
+ return _fetchAccounts.apply(this, arguments);
1455
+ }
1456
+ return fetchAccounts;
1457
+ }();
1458
+ _proto.buildAccount = function buildAccount(record) {
1459
+ var accountType;
1460
+ switch (record.Type) {
1461
+ case 'Health Authority':
1462
+ accountType = 'healthAuthority';
1463
+ break;
1464
+ case 'Hospital':
1465
+ accountType = 'establishment';
1466
+ }
1467
+ return {
1468
+ id: record.Id,
1469
+ name: record.Name,
1470
+ address: record.BillingAddress,
1471
+ city: record.BillingCity,
1472
+ province: record.BillingState,
1473
+ postalCode: record.BillingPostalCode,
1474
+ geographicalAreaName: record.BillingGeocodeAccuracy,
1475
+ phone: record.Phone,
1476
+ fax: record.Fax,
1477
+ regionName: record.RegionName,
1478
+ accountTypeName: accountType,
1479
+ email: null,
1480
+ phone2: null,
1481
+ cellular: null,
1482
+ lang: 'eng'
1483
+ };
1484
+ };
1485
+ return SFAccounts;
1486
+ }();
1487
+
1363
1488
  var SF_API_VERSION = 'v57.0';
1364
1489
  var SFApiClient = /*#__PURE__*/function () {
1365
1490
  function SFApiClient() {
@@ -1381,10 +1506,11 @@ var SFApiClient = /*#__PURE__*/function () {
1381
1506
  this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance);
1382
1507
  this.expenseClient = new SFExpenseClient(this.axiosInstance);
1383
1508
  this.priceClient = new SFPriceClient(this.axiosInstance);
1509
+ this.accountsClient = new SFAccounts(this.axiosInstance);
1384
1510
  // creates authenticator and adds token to axios instance
1385
- _context.next = 11;
1511
+ _context.next = 12;
1386
1512
  return this.authenticator.initializeAuth(sfClientId, sfClientSecret, onTokenRefresh);
1387
- case 11:
1513
+ case 12:
1388
1514
  case "end":
1389
1515
  return _context.stop();
1390
1516
  }