@markwharton/eh-payroll 2.0.0 → 2.1.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 +57 -25
- package/dist/client.js +4 -11
- package/dist/errors.d.ts +8 -10
- package/dist/errors.js +8 -20
- package/dist/index.d.ts +3 -4
- package/dist/index.js +3 -5
- package/dist/types.d.ts +2 -12
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -16
- package/package.json +2 -2
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
47
|
+
const locResult = await client.getLocations();
|
|
48
|
+
if (locResult.ok) console.log(locResult.data); // EHLocation[]
|
|
43
49
|
|
|
44
50
|
// List kiosks
|
|
45
|
-
const
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
##
|
|
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
|
-
|
|
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()` | — | `
|
|
72
|
-
| `getEmployees(options?)` | `EHEmployeeOptions?` | `
|
|
73
|
-
| `getEmployee(employeeId)` | `number` | `
|
|
74
|
-
| `getStandardHours(employeeId)` | `number` | `
|
|
75
|
-
| `getLocations()` | — | `
|
|
76
|
-
| `getEmployeeGroups()` | — | `
|
|
77
|
-
| `getRosterShifts(from, to, options?)` | `string, string, EHRosterShiftOptions?` | `
|
|
78
|
-
| `getKiosks()` | — | `
|
|
79
|
-
| `getKioskStaff(kioskId, options?)` | `number, EHKioskStaffOptions?` | `
|
|
80
|
-
| `getReportFields()` | — | `
|
|
81
|
-
| `getEmployeeDetailsReport(options?)` | `EHEmployeeDetailsReportOptions?` | `
|
|
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/dist/client.js
CHANGED
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
* @see https://api.keypay.com.au/
|
|
8
8
|
*/
|
|
9
9
|
import { AU_EMPLOYEE_OPERATIONAL_FIELDS, AU_EMPLOYEE_FIELDS, LOCATION_FIELDS, EMPLOYEE_GROUP_FIELDS, ROSTER_SHIFT_FIELDS, KIOSK_FIELDS, KIOSK_EMPLOYEE_FIELDS, } from './types.js';
|
|
10
|
-
import { buildBasicAuthHeader
|
|
10
|
+
import { buildBasicAuthHeader } from './utils.js';
|
|
11
11
|
import { parseEHErrorResponse } from './errors.js';
|
|
12
12
|
import { EH_API_BASE, EH_REGION_URLS } from './constants.js';
|
|
13
|
-
import { TTLCache, getErrorMessage, fetchWithRetry, ok, err } from '@markwharton/api-core';
|
|
14
|
-
import { RateLimiter } from './rate-limiter.js';
|
|
13
|
+
import { TTLCache, pickFields, RateLimiter, getErrorMessage, fetchWithRetry, resolveRetryConfig, ok, err } from '@markwharton/api-core';
|
|
15
14
|
/** Default page size for paginated endpoints */
|
|
16
15
|
const DEFAULT_PAGE_SIZE = 100;
|
|
17
16
|
// ============================================================================
|
|
@@ -52,13 +51,7 @@ export class EHClient {
|
|
|
52
51
|
reportFieldsTtl: config.cache?.reportFieldsTtl ?? 600000,
|
|
53
52
|
};
|
|
54
53
|
// Initialize retry config with defaults if provided
|
|
55
|
-
|
|
56
|
-
this.retryConfig = {
|
|
57
|
-
maxRetries: config.retry.maxRetries ?? 3,
|
|
58
|
-
initialDelayMs: config.retry.initialDelayMs ?? 1000,
|
|
59
|
-
maxDelayMs: config.retry.maxDelayMs ?? 10000,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
54
|
+
this.retryConfig = resolveRetryConfig(config.retry);
|
|
62
55
|
// Initialize rate limiter (default: 5 req/s per API spec)
|
|
63
56
|
const rateLimitPerSecond = config.rateLimitPerSecond ?? 5;
|
|
64
57
|
if (rateLimitPerSecond > 0) {
|
|
@@ -149,7 +142,7 @@ export class EHClient {
|
|
|
149
142
|
return err(`Unexpected response: HTTP ${response.status}`, response.status);
|
|
150
143
|
}
|
|
151
144
|
catch (error) {
|
|
152
|
-
return err(getErrorMessage(error
|
|
145
|
+
return err(getErrorMessage(error, 'Connection failed'));
|
|
153
146
|
}
|
|
154
147
|
}
|
|
155
148
|
// ============================================================================
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Employment Hero Payroll Error Handling
|
|
3
3
|
*
|
|
4
|
-
* EH/KeyPay API returns errors in
|
|
4
|
+
* EH/KeyPay API returns errors in standard JSON formats handled by api-core:
|
|
5
5
|
* - {"message":"..."} or {"error":"..."}
|
|
6
6
|
* - Plain text
|
|
7
7
|
* - HTML error pages (for server errors)
|
|
8
8
|
*/
|
|
9
|
+
import { ApiError } from '@markwharton/api-core';
|
|
10
|
+
import type { ParsedError } from '@markwharton/api-core';
|
|
9
11
|
/**
|
|
10
12
|
* Parsed EH error response
|
|
11
13
|
*/
|
|
12
|
-
export
|
|
13
|
-
/** Human-readable error message */
|
|
14
|
-
message: string;
|
|
15
|
-
}
|
|
14
|
+
export type EHParsedError = ParsedError;
|
|
16
15
|
/**
|
|
17
16
|
* Parse EH API error response text into a human-readable message.
|
|
18
17
|
*
|
|
18
|
+
* Delegates to api-core's parseJsonErrorResponse — EH uses standard
|
|
19
|
+
* JSON error formats with no API-specific extensions.
|
|
20
|
+
*
|
|
19
21
|
* @param errorText - Raw error response text
|
|
20
22
|
* @param statusCode - HTTP status code
|
|
21
23
|
* @returns Parsed error with message
|
|
@@ -24,11 +26,7 @@ export declare function parseEHErrorResponse(errorText: string, statusCode: numb
|
|
|
24
26
|
/**
|
|
25
27
|
* Custom error class for EH API errors
|
|
26
28
|
*/
|
|
27
|
-
export declare class EHError extends
|
|
28
|
-
/** HTTP status code */
|
|
29
|
-
status: number;
|
|
30
|
-
/** Raw error response */
|
|
31
|
-
rawResponse?: string;
|
|
29
|
+
export declare class EHError extends ApiError {
|
|
32
30
|
constructor(message: string, status: number, options?: {
|
|
33
31
|
rawResponse?: string;
|
|
34
32
|
});
|
package/dist/errors.js
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Employment Hero Payroll Error Handling
|
|
3
3
|
*
|
|
4
|
-
* EH/KeyPay API returns errors in
|
|
4
|
+
* EH/KeyPay API returns errors in standard JSON formats handled by api-core:
|
|
5
5
|
* - {"message":"..."} or {"error":"..."}
|
|
6
6
|
* - Plain text
|
|
7
7
|
* - HTML error pages (for server errors)
|
|
8
8
|
*/
|
|
9
|
+
import { ApiError, parseJsonErrorResponse } from '@markwharton/api-core';
|
|
9
10
|
/**
|
|
10
11
|
* Parse EH API error response text into a human-readable message.
|
|
11
12
|
*
|
|
13
|
+
* Delegates to api-core's parseJsonErrorResponse — EH uses standard
|
|
14
|
+
* JSON error formats with no API-specific extensions.
|
|
15
|
+
*
|
|
12
16
|
* @param errorText - Raw error response text
|
|
13
17
|
* @param statusCode - HTTP status code
|
|
14
18
|
* @returns Parsed error with message
|
|
15
19
|
*/
|
|
16
20
|
export function parseEHErrorResponse(errorText, statusCode) {
|
|
17
|
-
|
|
18
|
-
const errorJson = JSON.parse(errorText);
|
|
19
|
-
// Common EH error format
|
|
20
|
-
if (errorJson.message) {
|
|
21
|
-
return { message: errorJson.message };
|
|
22
|
-
}
|
|
23
|
-
if (errorJson.error) {
|
|
24
|
-
return { message: errorJson.error };
|
|
25
|
-
}
|
|
26
|
-
return { message: `HTTP ${statusCode}` };
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
// Not JSON, return as-is or fallback
|
|
30
|
-
return { message: errorText || `HTTP ${statusCode}` };
|
|
31
|
-
}
|
|
21
|
+
return parseJsonErrorResponse(errorText, statusCode);
|
|
32
22
|
}
|
|
33
23
|
/**
|
|
34
24
|
* Custom error class for EH API errors
|
|
35
25
|
*/
|
|
36
|
-
export class EHError extends
|
|
26
|
+
export class EHError extends ApiError {
|
|
37
27
|
constructor(message, status, options) {
|
|
38
|
-
super(message);
|
|
28
|
+
super(message, status, options);
|
|
39
29
|
this.name = 'EHError';
|
|
40
|
-
this.status = status;
|
|
41
|
-
this.rawResponse = options?.rawResponse;
|
|
42
30
|
}
|
|
43
31
|
/**
|
|
44
32
|
* Create an EHError from an API response
|
package/dist/index.d.ts
CHANGED
|
@@ -23,10 +23,9 @@ export { EHClient } from './client.js';
|
|
|
23
23
|
export type { EHConfig, EHCacheConfig, EHRetryConfig, EHEmployee, EHEmployeeOptions, EHSingleEmployeeOptions, EHStandardHours, EHLocation, EHEmployeeGroup, EHRosterShift, EHRosterShiftOptions, EHAttendanceStatus, EHKiosk, EHKioskEmployee, EHKioskStaffOptions, EHReportField, EHEmployeeDetailsReportOptions, } from './types.js';
|
|
24
24
|
export { AU_EMPLOYEE_OPERATIONAL_FIELDS, AU_EMPLOYEE_PII_FIELDS, AU_EMPLOYEE_FIELDS, LOCATION_FIELDS, EMPLOYEE_GROUP_FIELDS, ROSTER_SHIFT_FIELDS, KIOSK_FIELDS, KIOSK_EMPLOYEE_FIELDS, } from './types.js';
|
|
25
25
|
export type { EHAuEmployee } from './employee-types.generated.js';
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export type { Result, RetryConfig } from '@markwharton/api-core';
|
|
26
|
+
export { buildBasicAuthHeader } from './utils.js';
|
|
27
|
+
export { ok, err, getErrorMessage, pickFields, RateLimiter } from '@markwharton/api-core';
|
|
28
|
+
export type { Result, RetryConfig, OnRequestCallback, BaseClientConfig } from '@markwharton/api-core';
|
|
30
29
|
export { EH_API_BASE, EH_REGION_URLS } from './constants.js';
|
|
31
30
|
export type { EHRegion } from './constants.js';
|
|
32
31
|
export { EHError, parseEHErrorResponse } from './errors.js';
|
package/dist/index.js
CHANGED
|
@@ -23,12 +23,10 @@
|
|
|
23
23
|
export { EHClient } from './client.js';
|
|
24
24
|
// Field key constants (whitelists for pickFields)
|
|
25
25
|
export { AU_EMPLOYEE_OPERATIONAL_FIELDS, AU_EMPLOYEE_PII_FIELDS, AU_EMPLOYEE_FIELDS, LOCATION_FIELDS, EMPLOYEE_GROUP_FIELDS, ROSTER_SHIFT_FIELDS, KIOSK_FIELDS, KIOSK_EMPLOYEE_FIELDS, } from './types.js';
|
|
26
|
-
// Rate limiting
|
|
27
|
-
export { RateLimiter } from './rate-limiter.js';
|
|
28
26
|
// Utilities
|
|
29
|
-
export { buildBasicAuthHeader
|
|
30
|
-
//
|
|
31
|
-
export { ok, err, getErrorMessage } from '@markwharton/api-core';
|
|
27
|
+
export { buildBasicAuthHeader } from './utils.js';
|
|
28
|
+
// Re-exported from @markwharton/api-core
|
|
29
|
+
export { ok, err, getErrorMessage, pickFields, RateLimiter } from '@markwharton/api-core';
|
|
32
30
|
// Constants
|
|
33
31
|
export { EH_API_BASE, EH_REGION_URLS } from './constants.js';
|
|
34
32
|
// Errors
|
package/dist/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Based on the API reference and KeyPay .NET SDK models.
|
|
6
6
|
*/
|
|
7
7
|
import type { EHRegion } from './constants.js';
|
|
8
|
-
import type { RetryConfig } from '@markwharton/api-core';
|
|
8
|
+
import type { RetryConfig, BaseClientConfig } from '@markwharton/api-core';
|
|
9
9
|
/**
|
|
10
10
|
* Cache configuration for EHClient
|
|
11
11
|
*
|
|
@@ -35,25 +35,15 @@ export type EHRetryConfig = RetryConfig;
|
|
|
35
35
|
/**
|
|
36
36
|
* Employment Hero Payroll configuration for API access
|
|
37
37
|
*/
|
|
38
|
-
export interface EHConfig {
|
|
38
|
+
export interface EHConfig extends BaseClientConfig {
|
|
39
39
|
/** API key for authentication (used as Basic Auth username) */
|
|
40
40
|
apiKey: string;
|
|
41
41
|
/** Business ID to operate on */
|
|
42
42
|
businessId: number;
|
|
43
43
|
/** API region (default: 'au'). Sets the base URL automatically. */
|
|
44
44
|
region?: EHRegion;
|
|
45
|
-
/** Override base URL directly (takes priority over region) */
|
|
46
|
-
baseUrl?: string;
|
|
47
|
-
/** Optional callback invoked on each API request (for debugging/logging) */
|
|
48
|
-
onRequest?: (info: {
|
|
49
|
-
method: string;
|
|
50
|
-
url: string;
|
|
51
|
-
description?: string;
|
|
52
|
-
}) => void;
|
|
53
45
|
/** Enable caching with optional TTL overrides. Omit to disable caching. */
|
|
54
46
|
cache?: EHCacheConfig;
|
|
55
|
-
/** Retry configuration for transient failures (429, 503). Omit to disable retry. */
|
|
56
|
-
retry?: EHRetryConfig;
|
|
57
47
|
/** Max requests per second (default: 5 per API spec). Set 0 to disable. */
|
|
58
48
|
rateLimitPerSecond?: number;
|
|
59
49
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -7,8 +7,3 @@
|
|
|
7
7
|
* EH API uses the API key as the username with an empty password.
|
|
8
8
|
*/
|
|
9
9
|
export declare function buildBasicAuthHeader(apiKey: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Pick only specified keys from an object.
|
|
12
|
-
* Strips any upstream fields not in the whitelist.
|
|
13
|
-
*/
|
|
14
|
-
export declare function pickFields<T>(obj: Record<string, unknown>, keys: readonly string[]): T;
|
package/dist/utils.js
CHANGED
|
@@ -12,19 +12,3 @@
|
|
|
12
12
|
export function buildBasicAuthHeader(apiKey) {
|
|
13
13
|
return 'Basic ' + btoa(apiKey + ':');
|
|
14
14
|
}
|
|
15
|
-
// ============================================================================
|
|
16
|
-
// Field Stripping
|
|
17
|
-
// ============================================================================
|
|
18
|
-
/**
|
|
19
|
-
* Pick only specified keys from an object.
|
|
20
|
-
* Strips any upstream fields not in the whitelist.
|
|
21
|
-
*/
|
|
22
|
-
export function pickFields(obj, keys) {
|
|
23
|
-
const result = {};
|
|
24
|
-
for (const key of keys) {
|
|
25
|
-
if (key in obj) {
|
|
26
|
-
result[key] = obj[key];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markwharton/eh-payroll",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Employment Hero Payroll API client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"clean": "rm -rf dist"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@markwharton/api-core": "^1.
|
|
19
|
+
"@markwharton/api-core": "^1.2.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^20.10.0",
|