@markwharton/eh-payroll 2.0.0 → 2.0.1

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 (2) hide show
  1. package/README.md +57 -25
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -20,65 +20,97 @@ const client = new EHClient({
20
20
  });
21
21
 
22
22
  // Validate credentials
23
- await client.validateApiKey();
23
+ const validation = await client.validateApiKey();
24
+ if (!validation.ok) throw new Error(validation.error);
24
25
 
25
26
  // Get all employees
26
- const { employees } = await client.getEmployees();
27
+ const empResult = await client.getEmployees();
28
+ if (empResult.ok) console.log(empResult.data); // EHAuEmployee[]
27
29
 
28
30
  // Get employees filtered by location
29
- const { employees: filtered } = await client.getEmployees({ locationId: 5 });
31
+ const filteredResult = await client.getEmployees({ locationId: 5 });
32
+ if (filteredResult.ok) console.log(filteredResult.data); // EHAuEmployee[]
30
33
 
31
34
  // Get roster shifts for a date range (auto-paginates)
32
- const { rosterShifts } = await client.getRosterShifts('2026-02-03', '2026-02-09');
35
+ const rosterResult = await client.getRosterShifts('2026-02-03', '2026-02-09');
36
+ if (rosterResult.ok) console.log(rosterResult.data); // EHRosterShift[]
33
37
 
34
38
  // Get roster shifts with filters
35
- const { rosterShifts: published } = await client.getRosterShifts('2026-02-03', '2026-02-09', {
39
+ const pubResult = await client.getRosterShifts('2026-02-03', '2026-02-09', {
36
40
  employeeId: 42,
37
41
  shiftStatus: 'Published',
38
42
  selectAllRoles: true
39
43
  });
44
+ if (pubResult.ok) console.log(pubResult.data); // EHRosterShift[]
40
45
 
41
46
  // Get business locations
42
- const { locations } = await client.getLocations();
47
+ const locResult = await client.getLocations();
48
+ if (locResult.ok) console.log(locResult.data); // EHLocation[]
43
49
 
44
50
  // List kiosks
45
- const { kiosks } = await client.getKiosks();
51
+ const kioskResult = await client.getKiosks();
52
+ if (kioskResult.ok) console.log(kioskResult.data); // EHKiosk[]
46
53
 
47
54
  // Get kiosk staff (time and attendance)
48
- const { staff } = await client.getKioskStaff(kioskId);
55
+ const staffResult = await client.getKioskStaff(kioskId);
56
+ if (staffResult.ok) console.log(staffResult.data); // EHKioskEmployee[]
49
57
 
50
58
  // Get employee groups
51
- const { employeeGroups } = await client.getEmployeeGroups();
59
+ const groupResult = await client.getEmployeeGroups();
60
+ if (groupResult.ok) console.log(groupResult.data); // EHEmployeeGroup[]
52
61
 
53
62
  // Get standard hours for an employee (includes FTE value)
54
- const { standardHours } = await client.getStandardHours(employeeId);
63
+ const hoursResult = await client.getStandardHours(employeeId);
64
+ if (hoursResult.ok) console.log(hoursResult.data); // EHStandardHours
55
65
 
56
66
  // Discover available report columns
57
- const { fields } = await client.getReportFields();
67
+ const fieldsResult = await client.getReportFields();
68
+ if (fieldsResult.ok) console.log(fieldsResult.data); // EHReportField[]
58
69
 
59
70
  // Run Employee Details Report with selected columns
60
- const { records } = await client.getEmployeeDetailsReport({
71
+ const reportResult = await client.getEmployeeDetailsReport({
61
72
  selectedColumns: ['FirstName', 'Surname', 'ExternalId']
62
73
  });
74
+ if (reportResult.ok) console.log(reportResult.data); // Record<string, unknown>[]
63
75
  ```
64
76
 
65
- ## API Reference
77
+ ## Result Pattern
78
+
79
+ All methods return `Result<T>` objects rather than throwing exceptions. Always check `ok` before accessing `data`:
80
+
81
+ ```typescript
82
+ interface Result<T> {
83
+ ok: boolean;
84
+ data?: T; // present when ok is true
85
+ error?: string; // present when ok is false
86
+ status?: number; // HTTP status code on error
87
+ }
88
+ ```
66
89
 
67
- All methods return `{ data?, error? }` result objects rather than throwing exceptions.
90
+ ```typescript
91
+ const result = await client.getEmployees();
92
+ if (!result.ok) {
93
+ console.error(result.error, result.status);
94
+ return;
95
+ }
96
+ const employees = result.data;
97
+ ```
98
+
99
+ ## API Reference
68
100
 
69
101
  | Method | Parameters | Returns |
70
102
  |--------|-----------|---------|
71
- | `validateApiKey()` | — | `{ valid, error? }` |
72
- | `getEmployees(options?)` | `EHEmployeeOptions?` | `{ employees?, error? }` |
73
- | `getEmployee(employeeId)` | `number` | `{ employee?, error? }` |
74
- | `getStandardHours(employeeId)` | `number` | `{ standardHours?, error? }` |
75
- | `getLocations()` | — | `{ locations?, error? }` |
76
- | `getEmployeeGroups()` | — | `{ employeeGroups?, error? }` |
77
- | `getRosterShifts(from, to, options?)` | `string, string, EHRosterShiftOptions?` | `{ rosterShifts?, error? }` |
78
- | `getKiosks()` | — | `{ kiosks?, error? }` |
79
- | `getKioskStaff(kioskId, options?)` | `number, EHKioskStaffOptions?` | `{ staff?, error? }` |
80
- | `getReportFields()` | — | `{ fields?, error? }` |
81
- | `getEmployeeDetailsReport(options?)` | `EHEmployeeDetailsReportOptions?` | `{ records?, error? }` |
103
+ | `validateApiKey()` | — | `Result<void>` |
104
+ | `getEmployees(options?)` | `EHEmployeeOptions?` | `Result<EHAuEmployee[]>` |
105
+ | `getEmployee(employeeId)` | `number` | `Result<EHAuEmployee>` |
106
+ | `getStandardHours(employeeId)` | `number` | `Result<EHStandardHours>` |
107
+ | `getLocations()` | — | `Result<EHLocation[]>` |
108
+ | `getEmployeeGroups()` | — | `Result<EHEmployeeGroup[]>` |
109
+ | `getRosterShifts(from, to, options?)` | `string, string, EHRosterShiftOptions?` | `Result<EHRosterShift[]>` |
110
+ | `getKiosks()` | — | `Result<EHKiosk[]>` |
111
+ | `getKioskStaff(kioskId, options?)` | `number, EHKioskStaffOptions?` | `Result<EHKioskEmployee[]>` |
112
+ | `getReportFields()` | — | `Result<EHReportField[]>` |
113
+ | `getEmployeeDetailsReport(options?)` | `EHEmployeeDetailsReportOptions?` | `Result<Record<string, unknown>[]>` |
82
114
 
83
115
  ### `getRosterShifts()`
84
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markwharton/eh-payroll",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Employment Hero Payroll API client",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",