@markwharton/eh-payroll 2.0.1 → 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/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/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.0
|
|
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",
|