@brownandroot/api 0.5.0 → 0.7.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/README.md +36 -16
- package/dist/index.d.ts +84 -27
- package/dist/index.js +53 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @brownandroot/api
|
|
2
2
|
|
|
3
|
-
TypeScript client for the Brown & Root APIHub
|
|
3
|
+
Read-only TypeScript client for the Brown & Root APIHub data service. All methods are GET-only — no create, update, or delete operations are supported.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -21,47 +21,67 @@ const client = new ApiHubClient({
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
-
###
|
|
24
|
+
### Employees
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
27
|
const employees = await client.getEmployees()
|
|
28
|
+
const employee = await client.getEmployee(12345)
|
|
29
|
+
const results = await client.searchByName('John')
|
|
30
|
+
const results = await client.searchByEmail('john@example.com')
|
|
31
|
+
const reports = await client.getBySupervisor(12345)
|
|
32
|
+
const chain = await client.getSupervisorChain(12345)
|
|
33
|
+
const { jde, employee } = await client.getJdeFromEmail('john@example.com')
|
|
28
34
|
```
|
|
29
35
|
|
|
30
|
-
###
|
|
36
|
+
### Business Units
|
|
31
37
|
|
|
32
38
|
```typescript
|
|
33
|
-
const
|
|
39
|
+
const units = await client.getBusinessUnits()
|
|
40
|
+
const unit = await client.getBusinessUnit('BU001')
|
|
34
41
|
```
|
|
35
42
|
|
|
36
|
-
###
|
|
37
|
-
|
|
38
|
-
Case-insensitive partial match:
|
|
43
|
+
### Cost Codes
|
|
39
44
|
|
|
40
45
|
```typescript
|
|
41
|
-
const
|
|
46
|
+
const codes = await client.getCostcodes()
|
|
47
|
+
const code = await client.getCostcode('CC001')
|
|
42
48
|
```
|
|
43
49
|
|
|
44
|
-
###
|
|
50
|
+
### Pay Types
|
|
45
51
|
|
|
46
52
|
```typescript
|
|
47
|
-
const
|
|
53
|
+
const types = await client.getPaytypes()
|
|
54
|
+
const type = await client.getPaytype('PT001')
|
|
48
55
|
```
|
|
49
56
|
|
|
50
|
-
###
|
|
57
|
+
### Work Orders
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const orders = await client.getWorkorders()
|
|
61
|
+
const order = await client.getWorkorder('WO001')
|
|
62
|
+
```
|
|
51
63
|
|
|
52
|
-
|
|
64
|
+
### LLM Logs
|
|
53
65
|
|
|
54
66
|
```typescript
|
|
55
|
-
const
|
|
56
|
-
// [directSupervisor, theirSupervisor, ...]
|
|
67
|
+
const logs = await client.getLlmLogs()
|
|
57
68
|
```
|
|
58
69
|
|
|
59
70
|
## Types
|
|
60
71
|
|
|
61
|
-
The package exports
|
|
72
|
+
The package exports interfaces for all resource types:
|
|
62
73
|
|
|
63
74
|
```typescript
|
|
64
|
-
import type {
|
|
75
|
+
import type {
|
|
76
|
+
Employee,
|
|
77
|
+
BusinessUnit,
|
|
78
|
+
Costcode,
|
|
79
|
+
Paytype,
|
|
80
|
+
Shift,
|
|
81
|
+
Workorder,
|
|
82
|
+
LlmLog,
|
|
83
|
+
ApiHubClientOptions,
|
|
84
|
+
} from '@brownandroot/api'
|
|
65
85
|
```
|
|
66
86
|
|
|
67
87
|
## Error Handling
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Employee type matching the API response shape.
|
|
3
3
|
*/
|
|
4
4
|
export interface Employee {
|
|
5
|
-
employeeId:
|
|
5
|
+
employeeId: string;
|
|
6
6
|
name: string | null;
|
|
7
7
|
email: string | null;
|
|
8
8
|
badgeNumber: string | null;
|
|
@@ -26,22 +26,25 @@ export interface Employee {
|
|
|
26
26
|
reportingLevel: string | null;
|
|
27
27
|
recordType: string | null;
|
|
28
28
|
payCycleCode: string | null;
|
|
29
|
-
dateTimeStamps: string | null;
|
|
30
29
|
benefitGroup: string | null;
|
|
31
|
-
supervisor:
|
|
30
|
+
supervisor: string | null;
|
|
32
31
|
adjustedServiceDate: string | null;
|
|
33
32
|
departmentCode: string | null;
|
|
34
|
-
dateUpdated: string | null;
|
|
35
33
|
nccerNumber: string | null;
|
|
36
|
-
mentor:
|
|
34
|
+
mentor: string | null;
|
|
37
35
|
source: string | null;
|
|
38
36
|
createdAt: string | null;
|
|
37
|
+
updatedAtJulian: number | null;
|
|
39
38
|
updatedAt: string | null;
|
|
40
39
|
}
|
|
41
40
|
export interface ApiHubClientOptions {
|
|
42
41
|
baseUrl: string;
|
|
43
42
|
apiKey: string;
|
|
44
43
|
}
|
|
44
|
+
export interface DropdownOption {
|
|
45
|
+
value: number | string;
|
|
46
|
+
label: string;
|
|
47
|
+
}
|
|
45
48
|
/**
|
|
46
49
|
* LLM log entry matching the API response shape.
|
|
47
50
|
*/
|
|
@@ -55,40 +58,86 @@ export interface LlmLog {
|
|
|
55
58
|
totalTokens: number | null;
|
|
56
59
|
createdAt: string | null;
|
|
57
60
|
}
|
|
58
|
-
export interface
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
export interface BusinessUnit {
|
|
62
|
+
id: string;
|
|
63
|
+
companyId: string;
|
|
64
|
+
description: string;
|
|
65
|
+
clientId: string | null;
|
|
66
|
+
clientDescription: string | null;
|
|
67
|
+
workOrderRequired: boolean;
|
|
68
|
+
isActive: boolean;
|
|
69
|
+
expirationDate: string | null;
|
|
70
|
+
createdBy: string;
|
|
71
|
+
createdAt: string;
|
|
72
|
+
updatedBy: string | null;
|
|
73
|
+
updatedAt: string | null;
|
|
74
|
+
subsector: string | null;
|
|
65
75
|
}
|
|
66
|
-
export interface
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
export interface Costcode {
|
|
77
|
+
id: string;
|
|
78
|
+
jdeCostCode: string | null;
|
|
79
|
+
description: string | null;
|
|
80
|
+
businessUnitId: string;
|
|
81
|
+
objectAccount: string | null;
|
|
82
|
+
suba: string | null;
|
|
83
|
+
isActive: boolean;
|
|
84
|
+
expirationDate: string | null;
|
|
85
|
+
createdBy: string;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
updatedBy: string | null;
|
|
88
|
+
updatedAt: string | null;
|
|
89
|
+
billFlag: string | null;
|
|
90
|
+
entryEffectiveDate: string | null;
|
|
91
|
+
entryFlag: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface Paytype {
|
|
94
|
+
id: string;
|
|
95
|
+
companyCode: string | null;
|
|
96
|
+
payClass: string | null;
|
|
97
|
+
description: string;
|
|
98
|
+
isActive: boolean;
|
|
99
|
+
sortOrder: string | null;
|
|
100
|
+
objectAccount: string | null;
|
|
101
|
+
category: string | null;
|
|
102
|
+
perDiemPayType: boolean;
|
|
103
|
+
type: string | null;
|
|
104
|
+
}
|
|
105
|
+
export interface Workorder {
|
|
106
|
+
id: string;
|
|
107
|
+
businessUnitId: string;
|
|
108
|
+
costCodeId: string | null;
|
|
109
|
+
clientWorkOrderId: string | null;
|
|
110
|
+
description: string | null;
|
|
111
|
+
completed: boolean;
|
|
112
|
+
area: string | null;
|
|
113
|
+
isActive: boolean;
|
|
114
|
+
expirationDate: string | null;
|
|
115
|
+
createdBy: string;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
updatedBy: string | null;
|
|
118
|
+
updatedAt: string | null;
|
|
119
|
+
parentWorkOrder: string | null;
|
|
120
|
+
workOrder2: string | null;
|
|
73
121
|
}
|
|
74
122
|
export declare class ApiHubClient {
|
|
75
123
|
private baseUrl;
|
|
76
124
|
private apiKey;
|
|
77
125
|
constructor(options: ApiHubClientOptions);
|
|
78
126
|
private request;
|
|
79
|
-
private requestWithBody;
|
|
80
127
|
/** Get all employees */
|
|
81
128
|
getEmployees(): Promise<Employee[]>;
|
|
129
|
+
/** Get employees formatted for dropdown controls */
|
|
130
|
+
getEmployeesDropdown(): Promise<DropdownOption[]>;
|
|
82
131
|
/** Get a single employee by employeeId */
|
|
83
|
-
getEmployee(employeeId:
|
|
132
|
+
getEmployee(employeeId: string): Promise<Employee>;
|
|
84
133
|
/** Search employees by name (case-insensitive partial match) */
|
|
85
134
|
searchByName(name: string): Promise<Employee[]>;
|
|
86
135
|
/** Get all employees reporting to a supervisor */
|
|
87
|
-
getBySupervisor(supervisorId:
|
|
136
|
+
getBySupervisor(supervisorId: string): Promise<Employee[]>;
|
|
88
137
|
/** Search employees by email (case-insensitive partial match) */
|
|
89
138
|
searchByEmail(email: string): Promise<Employee[]>;
|
|
90
139
|
/** Get the supervisor chain above an employee */
|
|
91
|
-
getSupervisorChain(employeeId:
|
|
140
|
+
getSupervisorChain(employeeId: string): Promise<Employee[]>;
|
|
92
141
|
/** Look up JDE number and employee data from email (with JDEService/CoreService fallback) */
|
|
93
142
|
getJdeFromEmail(email: string): Promise<{
|
|
94
143
|
jde: string | null;
|
|
@@ -96,8 +145,16 @@ export declare class ApiHubClient {
|
|
|
96
145
|
}>;
|
|
97
146
|
/** List all LLM log entries (newest first) */
|
|
98
147
|
getLlmLogs(): Promise<LlmLog[]>;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
148
|
+
getBusinessUnits(): Promise<BusinessUnit[]>;
|
|
149
|
+
getBusinessUnitsDropdown(): Promise<DropdownOption[]>;
|
|
150
|
+
getBusinessUnit(id: string): Promise<BusinessUnit>;
|
|
151
|
+
getCostcodes(): Promise<Costcode[]>;
|
|
152
|
+
getCostcodesDropdown(): Promise<DropdownOption[]>;
|
|
153
|
+
getCostcode(id: string): Promise<Costcode>;
|
|
154
|
+
getPaytypes(): Promise<Paytype[]>;
|
|
155
|
+
getPaytypesDropdown(): Promise<DropdownOption[]>;
|
|
156
|
+
getPaytype(id: string): Promise<Paytype>;
|
|
157
|
+
getWorkorders(): Promise<Workorder[]>;
|
|
158
|
+
getWorkordersDropdown(): Promise<DropdownOption[]>;
|
|
159
|
+
getWorkorder(id: string): Promise<Workorder>;
|
|
103
160
|
}
|
package/dist/index.js
CHANGED
|
@@ -15,25 +15,17 @@ export class ApiHubClient {
|
|
|
15
15
|
}
|
|
16
16
|
return res.json();
|
|
17
17
|
}
|
|
18
|
-
async requestWithBody(path, method, body) {
|
|
19
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
20
|
-
method,
|
|
21
|
-
headers: { 'x-api-key': this.apiKey, 'Content-Type': 'application/json' },
|
|
22
|
-
body: JSON.stringify(body),
|
|
23
|
-
});
|
|
24
|
-
if (!res.ok) {
|
|
25
|
-
const respBody = await res.json().catch(() => ({}));
|
|
26
|
-
throw new Error(respBody.error ?? `Request failed: ${res.status}`);
|
|
27
|
-
}
|
|
28
|
-
return res.json();
|
|
29
|
-
}
|
|
30
18
|
/** Get all employees */
|
|
31
19
|
async getEmployees() {
|
|
32
20
|
return this.request('/employees');
|
|
33
21
|
}
|
|
22
|
+
/** Get employees formatted for dropdown controls */
|
|
23
|
+
async getEmployeesDropdown() {
|
|
24
|
+
return this.request('/employees/dropdown');
|
|
25
|
+
}
|
|
34
26
|
/** Get a single employee by employeeId */
|
|
35
27
|
async getEmployee(employeeId) {
|
|
36
|
-
return this.request(`/employees/${employeeId}`);
|
|
28
|
+
return this.request(`/employees/${encodeURIComponent(employeeId)}`);
|
|
37
29
|
}
|
|
38
30
|
/** Search employees by name (case-insensitive partial match) */
|
|
39
31
|
async searchByName(name) {
|
|
@@ -41,7 +33,7 @@ export class ApiHubClient {
|
|
|
41
33
|
}
|
|
42
34
|
/** Get all employees reporting to a supervisor */
|
|
43
35
|
async getBySupervisor(supervisorId) {
|
|
44
|
-
return this.request(`/employees/by-supervisor/${supervisorId}`);
|
|
36
|
+
return this.request(`/employees/by-supervisor/${encodeURIComponent(supervisorId)}`);
|
|
45
37
|
}
|
|
46
38
|
/** Search employees by email (case-insensitive partial match) */
|
|
47
39
|
async searchByEmail(email) {
|
|
@@ -49,7 +41,7 @@ export class ApiHubClient {
|
|
|
49
41
|
}
|
|
50
42
|
/** Get the supervisor chain above an employee */
|
|
51
43
|
async getSupervisorChain(employeeId) {
|
|
52
|
-
return this.request(`/employees/${employeeId}/supervisor-chain`);
|
|
44
|
+
return this.request(`/employees/${encodeURIComponent(employeeId)}/supervisor-chain`);
|
|
53
45
|
}
|
|
54
46
|
/** Look up JDE number and employee data from email (with JDEService/CoreService fallback) */
|
|
55
47
|
async getJdeFromEmail(email) {
|
|
@@ -62,12 +54,52 @@ export class ApiHubClient {
|
|
|
62
54
|
async getLlmLogs() {
|
|
63
55
|
return this.request('/llm-logs');
|
|
64
56
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
// -----------------------------------------------------------------------
|
|
58
|
+
// Business Units
|
|
59
|
+
// -----------------------------------------------------------------------
|
|
60
|
+
async getBusinessUnits() {
|
|
61
|
+
return this.request('/business-units');
|
|
62
|
+
}
|
|
63
|
+
async getBusinessUnitsDropdown() {
|
|
64
|
+
return this.request('/business-units/dropdown');
|
|
65
|
+
}
|
|
66
|
+
async getBusinessUnit(id) {
|
|
67
|
+
return this.request(`/business-units/${encodeURIComponent(id)}`);
|
|
68
|
+
}
|
|
69
|
+
// -----------------------------------------------------------------------
|
|
70
|
+
// Cost Codes
|
|
71
|
+
// -----------------------------------------------------------------------
|
|
72
|
+
async getCostcodes() {
|
|
73
|
+
return this.request('/costcodes');
|
|
74
|
+
}
|
|
75
|
+
async getCostcodesDropdown() {
|
|
76
|
+
return this.request('/costcodes/dropdown');
|
|
77
|
+
}
|
|
78
|
+
async getCostcode(id) {
|
|
79
|
+
return this.request(`/costcodes/${encodeURIComponent(id)}`);
|
|
80
|
+
}
|
|
81
|
+
// -----------------------------------------------------------------------
|
|
82
|
+
// Pay Types
|
|
83
|
+
// -----------------------------------------------------------------------
|
|
84
|
+
async getPaytypes() {
|
|
85
|
+
return this.request('/paytypes');
|
|
86
|
+
}
|
|
87
|
+
async getPaytypesDropdown() {
|
|
88
|
+
return this.request('/paytypes/dropdown');
|
|
89
|
+
}
|
|
90
|
+
async getPaytype(id) {
|
|
91
|
+
return this.request(`/paytypes/${encodeURIComponent(id)}`);
|
|
92
|
+
}
|
|
93
|
+
// -----------------------------------------------------------------------
|
|
94
|
+
// Work Orders
|
|
95
|
+
// -----------------------------------------------------------------------
|
|
96
|
+
async getWorkorders() {
|
|
97
|
+
return this.request('/workorders');
|
|
98
|
+
}
|
|
99
|
+
async getWorkordersDropdown() {
|
|
100
|
+
return this.request('/workorders/dropdown');
|
|
68
101
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return this.requestWithBody(`/llm-logs/${id}`, 'PATCH', input);
|
|
102
|
+
async getWorkorder(id) {
|
|
103
|
+
return this.request(`/workorders/${encodeURIComponent(id)}`);
|
|
72
104
|
}
|
|
73
105
|
}
|