pha-hermes 1.16.0 → 1.18.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.
- package/dist/api/expenses/expenseClient.d.ts +1 -1
- package/dist/api/salesforce/apiClient.d.ts +1 -2
- package/dist/api/salesforce/auth/auth.d.ts +1 -1
- package/dist/api/salesforce/practitioner/practitionerClient.d.ts +4 -1
- package/dist/models/user.d.ts +1 -0
- package/dist/pha-hermes.cjs.development.js +38 -27
- package/dist/pha-hermes.cjs.development.js.map +1 -1
- package/dist/pha-hermes.cjs.production.min.js +1 -1
- package/dist/pha-hermes.cjs.production.min.js.map +1 -1
- package/dist/pha-hermes.esm.js +38 -27
- package/dist/pha-hermes.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/.env +5 -0
- package/src/api/expenses/expenseClient.ts +1 -1
- package/src/api/salesforce/apiClient.ts +10 -10
- package/src/api/salesforce/auth/auth.ts +2 -5
- package/src/api/salesforce/practitioner/practitionerClient.ts +20 -5
- package/src/models/user.ts +2 -1
|
@@ -5,7 +5,7 @@ import { SF_API_VERSION } from '../salesforce/apiClient'
|
|
|
5
5
|
type FrontendExpense = {
|
|
6
6
|
workorderPeriodId: string
|
|
7
7
|
amount: string
|
|
8
|
-
type: 'Other' | 'Lodging' | 'Transportation' | 'Travel (Hours
|
|
8
|
+
type: 'Other' | 'Lodging' | 'Transportation' | 'Travel (Hours)' | 'Per diem' | 'Meals'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
const EXPENSE_FIELD_MAP = {
|
|
@@ -20,23 +20,20 @@ export class SFApiClient {
|
|
|
20
20
|
payPeriodClient: SFPayPeriodClient
|
|
21
21
|
expenseClient: SFExpenseClient
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
async init(
|
|
24
|
+
baseUrl: string,
|
|
25
|
+
sfClientId: string,
|
|
26
|
+
sfClientSecret: string,
|
|
27
|
+
onTokenRefresh?: () => Promise<{ clientId: string; clientSecret: string }>
|
|
28
|
+
) {
|
|
24
29
|
this.baseUrl = baseUrl
|
|
25
|
-
this.axiosInstance.defaults.baseURL =
|
|
26
|
-
baseUrl ?? 'https://do0000000d247eaa--phealth.sandbox.my.salesforce.com'
|
|
30
|
+
this.axiosInstance.defaults.baseURL = baseUrl
|
|
27
31
|
this.authenticator = new SFAuthenticator(this.axiosInstance, this.baseUrl)
|
|
28
32
|
this.timesheetClient = new SFTimesheetClient(this.axiosInstance)
|
|
29
33
|
this.workorderClient = new SFWorkorderClient(this.axiosInstance)
|
|
30
34
|
this.practitionerClient = new SFPractitionerClient(this.axiosInstance)
|
|
31
35
|
this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance)
|
|
32
36
|
this.expenseClient = new SFExpenseClient(this.axiosInstance)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async init(
|
|
36
|
-
sfClientId: string,
|
|
37
|
-
sfClientSecret: string,
|
|
38
|
-
onTokenRefresh?: () => Promise<{ clientId: string; clientSecret: string }>
|
|
39
|
-
) {
|
|
40
37
|
// creates authenticator and adds token to axios instance
|
|
41
38
|
await this.authenticator.initializeAuth(sfClientId, sfClientSecret, onTokenRefresh)
|
|
42
39
|
}
|
|
@@ -45,6 +42,9 @@ export class SFApiClient {
|
|
|
45
42
|
this.instance = instance
|
|
46
43
|
}
|
|
47
44
|
getInstance(): SFApiClient {
|
|
45
|
+
if (!this.instance) {
|
|
46
|
+
throw new Error('Salesforce Api client not initialized')
|
|
47
|
+
}
|
|
48
48
|
return this.instance
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -8,9 +8,8 @@ export class SFAuthenticator {
|
|
|
8
8
|
private refreshToken: string | undefined = undefined
|
|
9
9
|
private tokenRefreshPromise: Promise<string> | null = null
|
|
10
10
|
|
|
11
|
-
constructor(authenticatedAxiosInstance: AxiosInstance, baseUrl
|
|
12
|
-
this.axiosTokenInstance.defaults.baseURL =
|
|
13
|
-
baseUrl ?? 'https://do0000000d247eaa--phealth.sandbox.my.salesforce.com'
|
|
11
|
+
constructor(authenticatedAxiosInstance: AxiosInstance, baseUrl: string) {
|
|
12
|
+
this.axiosTokenInstance.defaults.baseURL = baseUrl
|
|
14
13
|
this.authenticatedAxiosInstance = authenticatedAxiosInstance
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -86,7 +85,6 @@ export class SFAuthenticator {
|
|
|
86
85
|
'Authentication failed, either the RefreshToken, or ClientId and ClientSecret need to be provided'
|
|
87
86
|
)
|
|
88
87
|
}
|
|
89
|
-
|
|
90
88
|
const response = await this.axiosTokenInstance.post(
|
|
91
89
|
'/services/oauth2/token',
|
|
92
90
|
tokenFormRequestBody,
|
|
@@ -94,7 +92,6 @@ export class SFAuthenticator {
|
|
|
94
92
|
headers: tokenFormRequestBody.getHeaders()
|
|
95
93
|
}
|
|
96
94
|
)
|
|
97
|
-
|
|
98
95
|
this.token = response?.data?.['access_token']
|
|
99
96
|
if (!this.token) throw new Error('Authentication failed, could not get the access token')
|
|
100
97
|
return this.token
|
|
@@ -9,13 +9,27 @@ export class SFPractitionerClient {
|
|
|
9
9
|
this.axiosInstance = axiosInstance
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
async fetchPractitioners(
|
|
12
|
+
async fetchPractitioners(options?: {
|
|
13
|
+
createdAt?: string
|
|
14
|
+
limit?: number
|
|
15
|
+
}): Promise<Practitioner[]> {
|
|
13
16
|
try {
|
|
17
|
+
const conditions: string[] = [`Status__c = 'Active'`]
|
|
18
|
+
if (options?.createdAt) {
|
|
19
|
+
conditions.push(`CreatedDate > ${options.createdAt}`)
|
|
20
|
+
}
|
|
21
|
+
const whereClause = conditions.length ? `WHERE ${conditions.join(' AND ')}` : ''
|
|
22
|
+
const limitClause =
|
|
23
|
+
typeof options?.limit === 'number' && options.limit > 0
|
|
24
|
+
? `LIMIT ${Math.floor(options.limit)}`
|
|
25
|
+
: ''
|
|
14
26
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
15
27
|
const query = `
|
|
16
|
-
SELECT Id, FirstName__c, LastName__c, Email__c, StaffID__c
|
|
28
|
+
SELECT Id, FirstName__c, LastName__c, Email__c, StaffID__c, CreatedDate
|
|
17
29
|
FROM Personnel__c
|
|
18
|
-
|
|
30
|
+
${whereClause}
|
|
31
|
+
ORDER BY CreatedDate ASC, StaffID__c ASC
|
|
32
|
+
${limitClause}
|
|
19
33
|
`
|
|
20
34
|
const {
|
|
21
35
|
data: { records }
|
|
@@ -34,7 +48,7 @@ export class SFPractitionerClient {
|
|
|
34
48
|
try {
|
|
35
49
|
const url = `/services/data/${SF_API_VERSION}/query`
|
|
36
50
|
const query = `
|
|
37
|
-
SELECT Id, FirstName__c, LastName__c, Email__c, StaffID__c
|
|
51
|
+
SELECT Id, FirstName__c, LastName__c, Email__c, StaffID__c, CreatedDate
|
|
38
52
|
FROM Personnel__c
|
|
39
53
|
WHERE Status__c = 'Active' AND Email__c = '${email}'
|
|
40
54
|
`
|
|
@@ -60,6 +74,7 @@ function toPractitioner(raw: any): Practitioner {
|
|
|
60
74
|
firstName: raw.FirstName__c,
|
|
61
75
|
lastName: raw.LastName__c,
|
|
62
76
|
email: raw.Email__c,
|
|
63
|
-
staffId: raw.StaffID__c
|
|
77
|
+
staffId: raw.StaffID__c,
|
|
78
|
+
createdAt: raw.CreatedDate.replace(/\+0000$/, 'Z')
|
|
64
79
|
}
|
|
65
80
|
}
|