@hirefinn/sdk 0.5.0 → 0.5.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.
- package/README.md +3 -1
- package/dist/cjs/core.d.ts +1 -1
- package/dist/cjs/core.js +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/webhooks.d.ts +38 -8
- package/dist/cjs/webhooks.js +51 -18
- package/dist/esm/core.d.ts +1 -1
- package/dist/esm/core.js +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/webhooks.d.ts +38 -8
- package/dist/esm/webhooks.js +49 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -169,7 +169,9 @@ make them safe to retry.
|
|
|
169
169
|
|
|
170
170
|
## Webhooks
|
|
171
171
|
|
|
172
|
-
Finn signs each delivery with `X-
|
|
172
|
+
Finn signs each delivery with `X-Webhook-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`
|
|
173
|
+
(also sent as `X-Finn-Signature` until that name is retired; `verifyWebhook` reads either, new name first). The event
|
|
174
|
+
name is in `X-Webhook-Event` (older `X-Finn-Event`); `readWebhookHeader(req.headers, 'event')` reads it the same way.
|
|
173
175
|
`verifyWebhook` checks it in constant time, refuses timestamps more than 300 s from now, and returns the parsed event.
|
|
174
176
|
Pass the **raw** body, not re-serialised JSON.
|
|
175
177
|
|
package/dist/cjs/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FinnResponse, HttpMethod, Operation, PathsFor, RequestArgs, RequestOptions, ResultOf } from './types.js';
|
|
2
2
|
export declare const DEFAULT_BASE_URL = "https://api.hirefinn.ai/v1";
|
|
3
|
-
export declare const SDK_VERSION = "0.5.
|
|
3
|
+
export declare const SDK_VERSION = "0.5.1";
|
|
4
4
|
/** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
|
|
5
5
|
export declare const DEFAULT_FINN_VERSION = "2026-11-01";
|
|
6
6
|
export interface FinnOptions {
|
package/dist/cjs/core.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.honoursIdempotencyKey = honoursIdempotencyKey;
|
|
|
17
17
|
exports.idempotencyKey = idempotencyKey;
|
|
18
18
|
const errors_js_1 = require("./errors.js");
|
|
19
19
|
exports.DEFAULT_BASE_URL = 'https://api.hirefinn.ai/v1';
|
|
20
|
-
exports.SDK_VERSION = '0.5.
|
|
20
|
+
exports.SDK_VERSION = '0.5.1';
|
|
21
21
|
/** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
|
|
22
22
|
exports.DEFAULT_FINN_VERSION = '2026-11-01';
|
|
23
23
|
// Browsers own the User-Agent header, so it is only set on server runtimes.
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { Finn } from './client.js';
|
|
2
2
|
export { Finn as default } from './client.js';
|
|
3
3
|
export { FinnCore, DEFAULT_BASE_URL, SDK_VERSION, DEFAULT_FINN_VERSION, AUTO_IDEMPOTENCY_ROUTES, IDEMPOTENT_WRITE_ROUTES, honoursIdempotencyKey, idempotencyKey, DEFAULT_MAX_RETRY_WAIT_MS, } from './core.js';
|
|
4
|
-
export { verifyWebhook, signWebhookPayload, parseSignatureHeader, timingSafeEqual, FinnWebhookVerificationError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './webhooks.js';
|
|
5
|
-
export type { VerifyWebhookOptions, WebhookEvent } from './webhooks.js';
|
|
4
|
+
export { verifyWebhook, signWebhookPayload, parseSignatureHeader, timingSafeEqual, FinnWebhookVerificationError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_HEADERS, LEGACY_WEBHOOK_HEADERS, readWebhookHeader, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './webhooks.js';
|
|
5
|
+
export type { VerifyWebhookOptions, WebhookEvent, WebhookHeaderKind } from './webhooks.js';
|
|
6
6
|
export type { FinnOptions, RawRequest } from './core.js';
|
|
7
7
|
export { FinnSdkError, FinnError, FinnConnectionError, FinnTimeoutError, FinnApprovalTimeoutError, codeForStatus, parseRetryAfterSeconds, } from './errors.js';
|
|
8
8
|
export type { FinnErrorCode, FinnFieldError } from './errors.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.afterStrategy = exports.beforeStrategy = exports.pageStrategy = exports.offsetStrategy = exports.cursorStrategy = exports.Paginator = exports.isPendingApproval = exports.parseRetryAfterSeconds = exports.codeForStatus = exports.FinnApprovalTimeoutError = exports.FinnTimeoutError = exports.FinnConnectionError = exports.FinnError = exports.FinnSdkError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.FinnWebhookVerificationError = exports.timingSafeEqual = exports.parseSignatureHeader = exports.signWebhookPayload = exports.verifyWebhook = exports.DEFAULT_MAX_RETRY_WAIT_MS = exports.idempotencyKey = exports.honoursIdempotencyKey = exports.IDEMPOTENT_WRITE_ROUTES = exports.AUTO_IDEMPOTENCY_ROUTES = exports.DEFAULT_FINN_VERSION = exports.SDK_VERSION = exports.DEFAULT_BASE_URL = exports.FinnCore = exports.default = exports.Finn = void 0;
|
|
17
|
+
exports.afterStrategy = exports.beforeStrategy = exports.pageStrategy = exports.offsetStrategy = exports.cursorStrategy = exports.Paginator = exports.isPendingApproval = exports.parseRetryAfterSeconds = exports.codeForStatus = exports.FinnApprovalTimeoutError = exports.FinnTimeoutError = exports.FinnConnectionError = exports.FinnError = exports.FinnSdkError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.readWebhookHeader = exports.LEGACY_WEBHOOK_HEADERS = exports.WEBHOOK_HEADERS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.FinnWebhookVerificationError = exports.timingSafeEqual = exports.parseSignatureHeader = exports.signWebhookPayload = exports.verifyWebhook = exports.DEFAULT_MAX_RETRY_WAIT_MS = exports.idempotencyKey = exports.honoursIdempotencyKey = exports.IDEMPOTENT_WRITE_ROUTES = exports.AUTO_IDEMPOTENCY_ROUTES = exports.DEFAULT_FINN_VERSION = exports.SDK_VERSION = exports.DEFAULT_BASE_URL = exports.FinnCore = exports.default = exports.Finn = void 0;
|
|
18
18
|
var client_js_1 = require("./client.js");
|
|
19
19
|
Object.defineProperty(exports, "Finn", { enumerable: true, get: function () { return client_js_1.Finn; } });
|
|
20
20
|
var client_js_2 = require("./client.js");
|
|
@@ -37,6 +37,9 @@ Object.defineProperty(exports, "timingSafeEqual", { enumerable: true, get: funct
|
|
|
37
37
|
Object.defineProperty(exports, "FinnWebhookVerificationError", { enumerable: true, get: function () { return webhooks_js_1.FinnWebhookVerificationError; } });
|
|
38
38
|
Object.defineProperty(exports, "WEBHOOK_SIGNATURE_HEADER", { enumerable: true, get: function () { return webhooks_js_1.WEBHOOK_SIGNATURE_HEADER; } });
|
|
39
39
|
Object.defineProperty(exports, "WEBHOOK_EVENT_HEADER", { enumerable: true, get: function () { return webhooks_js_1.WEBHOOK_EVENT_HEADER; } });
|
|
40
|
+
Object.defineProperty(exports, "WEBHOOK_HEADERS", { enumerable: true, get: function () { return webhooks_js_1.WEBHOOK_HEADERS; } });
|
|
41
|
+
Object.defineProperty(exports, "LEGACY_WEBHOOK_HEADERS", { enumerable: true, get: function () { return webhooks_js_1.LEGACY_WEBHOOK_HEADERS; } });
|
|
42
|
+
Object.defineProperty(exports, "readWebhookHeader", { enumerable: true, get: function () { return webhooks_js_1.readWebhookHeader; } });
|
|
40
43
|
Object.defineProperty(exports, "DEFAULT_WEBHOOK_TOLERANCE_SECONDS", { enumerable: true, get: function () { return webhooks_js_1.DEFAULT_WEBHOOK_TOLERANCE_SECONDS; } });
|
|
41
44
|
var errors_js_1 = require("./errors.js");
|
|
42
45
|
Object.defineProperty(exports, "FinnSdkError", { enumerable: true, get: function () { return errors_js_1.FinnSdkError; } });
|
package/dist/cjs/webhooks.d.ts
CHANGED
|
@@ -2,14 +2,37 @@ import { FinnSdkError } from './errors.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Webhook signature checks.
|
|
4
4
|
*
|
|
5
|
-
* Finn signs every delivery with `X-
|
|
6
|
-
* and names the event in `X-
|
|
7
|
-
*
|
|
5
|
+
* Finn signs every delivery with `X-Webhook-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`
|
|
6
|
+
* and names the event in `X-Webhook-Event`. Deliveries also carry the same values under the older `X-Finn-*` names
|
|
7
|
+
* until those are retired; the readers here take the neutral name first and fall back to the old one.
|
|
8
|
+
* verifyWebhook() checks the signature in constant time and refuses deliveries whose timestamp is too far from now,
|
|
9
|
+
* so a captured request cannot be replayed later.
|
|
8
10
|
*/
|
|
9
|
-
/**
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** Webhook header names. Read these first. */
|
|
12
|
+
export declare const WEBHOOK_HEADERS: {
|
|
13
|
+
readonly signature: "X-Webhook-Signature";
|
|
14
|
+
readonly event: "X-Webhook-Event";
|
|
15
|
+
readonly delivery: "X-Webhook-Delivery";
|
|
16
|
+
readonly timestamp: "X-Webhook-Timestamp";
|
|
17
|
+
};
|
|
18
|
+
/** The older names for the same headers, sent alongside {@link WEBHOOK_HEADERS} until they are retired. */
|
|
19
|
+
export declare const LEGACY_WEBHOOK_HEADERS: {
|
|
20
|
+
readonly signature: "X-Finn-Signature";
|
|
21
|
+
readonly event: "X-Finn-Event";
|
|
22
|
+
readonly delivery: "X-Finn-Delivery";
|
|
23
|
+
readonly timestamp: "X-Finn-Timestamp";
|
|
24
|
+
};
|
|
25
|
+
export type WebhookHeaderKind = keyof typeof WEBHOOK_HEADERS;
|
|
26
|
+
/**
|
|
27
|
+
* Header that carries the signature (older name).
|
|
28
|
+
* @deprecated Use `WEBHOOK_HEADERS.signature` (`X-Webhook-Signature`); verifyWebhook() reads either.
|
|
29
|
+
*/
|
|
30
|
+
export declare const WEBHOOK_SIGNATURE_HEADER: "X-Finn-Signature";
|
|
31
|
+
/**
|
|
32
|
+
* Header that carries the event name (older name).
|
|
33
|
+
* @deprecated Use `WEBHOOK_HEADERS.event` (`X-Webhook-Event`); readWebhookHeader() reads either.
|
|
34
|
+
*/
|
|
35
|
+
export declare const WEBHOOK_EVENT_HEADER: "X-Finn-Event";
|
|
13
36
|
/** Default largest gap, in seconds, between the signed timestamp and now. */
|
|
14
37
|
export declare const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
15
38
|
/**
|
|
@@ -36,7 +59,7 @@ export declare class FinnWebhookVerificationError extends FinnSdkError {
|
|
|
36
59
|
export interface VerifyWebhookOptions {
|
|
37
60
|
/** The raw request body, exactly as received (not re-serialised JSON). */
|
|
38
61
|
payload: string | Uint8Array;
|
|
39
|
-
/** The `X-Finn-Signature` value, or the request's headers to read it from. */
|
|
62
|
+
/** The `X-Webhook-Signature` (or older `X-Finn-Signature`) value, or the request's headers to read it from. */
|
|
40
63
|
header?: string | null;
|
|
41
64
|
headers?: Headers | Record<string, string | string[] | undefined>;
|
|
42
65
|
/** The endpoint's signing secret (`whsec_...`). Pass several while you rotate secrets. */
|
|
@@ -51,6 +74,13 @@ export declare function parseSignatureHeader(header: string): {
|
|
|
51
74
|
timestamp: number;
|
|
52
75
|
signatures: string[];
|
|
53
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Reads a webhook header from a request's headers (a `Headers` or a Node headers object, any case): the neutral
|
|
79
|
+
* `X-Webhook-*` name first, then the older `X-Finn-*` name. Returns null when neither is set.
|
|
80
|
+
*
|
|
81
|
+
* const event = readWebhookHeader(req.headers, 'event'); // 'call.completed'
|
|
82
|
+
*/
|
|
83
|
+
export declare function readWebhookHeader(headers: VerifyWebhookOptions['headers'], kind: WebhookHeaderKind): string | null;
|
|
54
84
|
/** Compares two byte arrays in time that depends only on their length. */
|
|
55
85
|
export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
56
86
|
/** Hex HMAC-SHA256 of `<timestamp>.<payload>`, the way Finn signs deliveries. */
|
package/dist/cjs/webhooks.js
CHANGED
|
@@ -33,8 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.FinnWebhookVerificationError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = void 0;
|
|
36
|
+
exports.FinnWebhookVerificationError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.LEGACY_WEBHOOK_HEADERS = exports.WEBHOOK_HEADERS = void 0;
|
|
37
37
|
exports.parseSignatureHeader = parseSignatureHeader;
|
|
38
|
+
exports.readWebhookHeader = readWebhookHeader;
|
|
38
39
|
exports.timingSafeEqual = timingSafeEqual;
|
|
39
40
|
exports.signWebhookPayload = signWebhookPayload;
|
|
40
41
|
exports.verifyWebhook = verifyWebhook;
|
|
@@ -42,14 +43,36 @@ const errors_js_1 = require("./errors.js");
|
|
|
42
43
|
/**
|
|
43
44
|
* Webhook signature checks.
|
|
44
45
|
*
|
|
45
|
-
* Finn signs every delivery with `X-
|
|
46
|
-
* and names the event in `X-
|
|
47
|
-
*
|
|
46
|
+
* Finn signs every delivery with `X-Webhook-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`
|
|
47
|
+
* and names the event in `X-Webhook-Event`. Deliveries also carry the same values under the older `X-Finn-*` names
|
|
48
|
+
* until those are retired; the readers here take the neutral name first and fall back to the old one.
|
|
49
|
+
* verifyWebhook() checks the signature in constant time and refuses deliveries whose timestamp is too far from now,
|
|
50
|
+
* so a captured request cannot be replayed later.
|
|
48
51
|
*/
|
|
49
|
-
/**
|
|
50
|
-
exports.
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
/** Webhook header names. Read these first. */
|
|
53
|
+
exports.WEBHOOK_HEADERS = {
|
|
54
|
+
signature: 'X-Webhook-Signature',
|
|
55
|
+
event: 'X-Webhook-Event',
|
|
56
|
+
delivery: 'X-Webhook-Delivery',
|
|
57
|
+
timestamp: 'X-Webhook-Timestamp',
|
|
58
|
+
};
|
|
59
|
+
/** The older names for the same headers, sent alongside {@link WEBHOOK_HEADERS} until they are retired. */
|
|
60
|
+
exports.LEGACY_WEBHOOK_HEADERS = {
|
|
61
|
+
signature: 'X-Finn-Signature',
|
|
62
|
+
event: 'X-Finn-Event',
|
|
63
|
+
delivery: 'X-Finn-Delivery',
|
|
64
|
+
timestamp: 'X-Finn-Timestamp',
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Header that carries the signature (older name).
|
|
68
|
+
* @deprecated Use `WEBHOOK_HEADERS.signature` (`X-Webhook-Signature`); verifyWebhook() reads either.
|
|
69
|
+
*/
|
|
70
|
+
exports.WEBHOOK_SIGNATURE_HEADER = exports.LEGACY_WEBHOOK_HEADERS.signature;
|
|
71
|
+
/**
|
|
72
|
+
* Header that carries the event name (older name).
|
|
73
|
+
* @deprecated Use `WEBHOOK_HEADERS.event` (`X-Webhook-Event`); readWebhookHeader() reads either.
|
|
74
|
+
*/
|
|
75
|
+
exports.WEBHOOK_EVENT_HEADER = exports.LEGACY_WEBHOOK_HEADERS.event;
|
|
53
76
|
/** Default largest gap, in seconds, between the signed timestamp and now. */
|
|
54
77
|
exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
55
78
|
/** The delivery's signature is missing, malformed, wrong or too old. Answer the request with a 400. */
|
|
@@ -77,18 +100,27 @@ function parseSignatureHeader(header) {
|
|
|
77
100
|
}
|
|
78
101
|
return { timestamp, signatures };
|
|
79
102
|
}
|
|
80
|
-
function
|
|
81
|
-
if (!headers)
|
|
82
|
-
return null;
|
|
103
|
+
function readOne(headers, name) {
|
|
83
104
|
if (typeof headers.get === 'function')
|
|
84
|
-
return headers.get(
|
|
85
|
-
const want =
|
|
105
|
+
return headers.get(name) || null;
|
|
106
|
+
const want = name.toLowerCase();
|
|
86
107
|
for (const [k, v] of Object.entries(headers)) {
|
|
87
108
|
if (k.toLowerCase() === want)
|
|
88
|
-
return Array.isArray(v) ?
|
|
109
|
+
return (Array.isArray(v) ? v[0] : v) || null;
|
|
89
110
|
}
|
|
90
111
|
return null;
|
|
91
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Reads a webhook header from a request's headers (a `Headers` or a Node headers object, any case): the neutral
|
|
115
|
+
* `X-Webhook-*` name first, then the older `X-Finn-*` name. Returns null when neither is set.
|
|
116
|
+
*
|
|
117
|
+
* const event = readWebhookHeader(req.headers, 'event'); // 'call.completed'
|
|
118
|
+
*/
|
|
119
|
+
function readWebhookHeader(headers, kind) {
|
|
120
|
+
if (!headers)
|
|
121
|
+
return null;
|
|
122
|
+
return readOne(headers, exports.WEBHOOK_HEADERS[kind]) ?? readOne(headers, exports.LEGACY_WEBHOOK_HEADERS[kind]);
|
|
123
|
+
}
|
|
92
124
|
async function subtleCrypto() {
|
|
93
125
|
const c = globalThis.crypto;
|
|
94
126
|
if (c?.subtle)
|
|
@@ -148,12 +180,13 @@ async function verifyWebhook(options) {
|
|
|
148
180
|
const secrets = (typeof options.secret === 'string' ? [options.secret] : [...options.secret]).filter((s) => !!s);
|
|
149
181
|
if (secrets.length === 0)
|
|
150
182
|
throw new FinnWebhookVerificationError('Missing webhook signing secret.');
|
|
151
|
-
const header = options.header ??
|
|
152
|
-
if (!header)
|
|
153
|
-
throw new FinnWebhookVerificationError(`Missing ${exports.
|
|
183
|
+
const header = options.header ?? readWebhookHeader(options.headers, 'signature');
|
|
184
|
+
if (!header) {
|
|
185
|
+
throw new FinnWebhookVerificationError(`Missing ${exports.WEBHOOK_HEADERS.signature} (or ${exports.LEGACY_WEBHOOK_HEADERS.signature}) header.`);
|
|
186
|
+
}
|
|
154
187
|
const { timestamp, signatures } = parseSignatureHeader(header);
|
|
155
188
|
if (!Number.isFinite(timestamp) || signatures.length === 0) {
|
|
156
|
-
throw new FinnWebhookVerificationError(`Malformed ${exports.
|
|
189
|
+
throw new FinnWebhookVerificationError(`Malformed ${exports.WEBHOOK_HEADERS.signature} header: expected t=<unix>,v1=<hex>.`);
|
|
157
190
|
}
|
|
158
191
|
const tolerance = options.toleranceSeconds ?? exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS;
|
|
159
192
|
const now = options.now ?? Math.floor(Date.now() / 1000);
|
package/dist/esm/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FinnResponse, HttpMethod, Operation, PathsFor, RequestArgs, RequestOptions, ResultOf } from './types.js';
|
|
2
2
|
export declare const DEFAULT_BASE_URL = "https://api.hirefinn.ai/v1";
|
|
3
|
-
export declare const SDK_VERSION = "0.5.
|
|
3
|
+
export declare const SDK_VERSION = "0.5.1";
|
|
4
4
|
/** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
|
|
5
5
|
export declare const DEFAULT_FINN_VERSION = "2026-11-01";
|
|
6
6
|
export interface FinnOptions {
|
package/dist/esm/core.js
CHANGED
|
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
var _FinnCore_apiKey, _FinnCore_fetch, _FinnCore_defaultHeaders, _FinnCore_sleep;
|
|
13
13
|
import { FinnConnectionError, FinnError, FinnSdkError, FinnTimeoutError } from './errors.js';
|
|
14
14
|
export const DEFAULT_BASE_URL = 'https://api.hirefinn.ai/v1';
|
|
15
|
-
export const SDK_VERSION = '0.5.
|
|
15
|
+
export const SDK_VERSION = '0.5.1';
|
|
16
16
|
/** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
|
|
17
17
|
export const DEFAULT_FINN_VERSION = '2026-11-01';
|
|
18
18
|
// Browsers own the User-Agent header, so it is only set on server runtimes.
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { Finn } from './client.js';
|
|
2
2
|
export { Finn as default } from './client.js';
|
|
3
3
|
export { FinnCore, DEFAULT_BASE_URL, SDK_VERSION, DEFAULT_FINN_VERSION, AUTO_IDEMPOTENCY_ROUTES, IDEMPOTENT_WRITE_ROUTES, honoursIdempotencyKey, idempotencyKey, DEFAULT_MAX_RETRY_WAIT_MS, } from './core.js';
|
|
4
|
-
export { verifyWebhook, signWebhookPayload, parseSignatureHeader, timingSafeEqual, FinnWebhookVerificationError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './webhooks.js';
|
|
5
|
-
export type { VerifyWebhookOptions, WebhookEvent } from './webhooks.js';
|
|
4
|
+
export { verifyWebhook, signWebhookPayload, parseSignatureHeader, timingSafeEqual, FinnWebhookVerificationError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_HEADERS, LEGACY_WEBHOOK_HEADERS, readWebhookHeader, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './webhooks.js';
|
|
5
|
+
export type { VerifyWebhookOptions, WebhookEvent, WebhookHeaderKind } from './webhooks.js';
|
|
6
6
|
export type { FinnOptions, RawRequest } from './core.js';
|
|
7
7
|
export { FinnSdkError, FinnError, FinnConnectionError, FinnTimeoutError, FinnApprovalTimeoutError, codeForStatus, parseRetryAfterSeconds, } from './errors.js';
|
|
8
8
|
export type { FinnErrorCode, FinnFieldError } from './errors.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Finn } from './client.js';
|
|
2
2
|
export { Finn as default } from './client.js';
|
|
3
3
|
export { FinnCore, DEFAULT_BASE_URL, SDK_VERSION, DEFAULT_FINN_VERSION, AUTO_IDEMPOTENCY_ROUTES, IDEMPOTENT_WRITE_ROUTES, honoursIdempotencyKey, idempotencyKey, DEFAULT_MAX_RETRY_WAIT_MS, } from './core.js';
|
|
4
|
-
export { verifyWebhook, signWebhookPayload, parseSignatureHeader, timingSafeEqual, FinnWebhookVerificationError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './webhooks.js';
|
|
4
|
+
export { verifyWebhook, signWebhookPayload, parseSignatureHeader, timingSafeEqual, FinnWebhookVerificationError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_HEADERS, LEGACY_WEBHOOK_HEADERS, readWebhookHeader, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './webhooks.js';
|
|
5
5
|
export { FinnSdkError, FinnError, FinnConnectionError, FinnTimeoutError, FinnApprovalTimeoutError, codeForStatus, parseRetryAfterSeconds, } from './errors.js';
|
|
6
6
|
export { isPendingApproval } from './approval.js';
|
|
7
7
|
export { Paginator, cursorStrategy, offsetStrategy, pageStrategy, beforeStrategy, afterStrategy } from './pagination.js';
|
package/dist/esm/webhooks.d.ts
CHANGED
|
@@ -2,14 +2,37 @@ import { FinnSdkError } from './errors.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Webhook signature checks.
|
|
4
4
|
*
|
|
5
|
-
* Finn signs every delivery with `X-
|
|
6
|
-
* and names the event in `X-
|
|
7
|
-
*
|
|
5
|
+
* Finn signs every delivery with `X-Webhook-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`
|
|
6
|
+
* and names the event in `X-Webhook-Event`. Deliveries also carry the same values under the older `X-Finn-*` names
|
|
7
|
+
* until those are retired; the readers here take the neutral name first and fall back to the old one.
|
|
8
|
+
* verifyWebhook() checks the signature in constant time and refuses deliveries whose timestamp is too far from now,
|
|
9
|
+
* so a captured request cannot be replayed later.
|
|
8
10
|
*/
|
|
9
|
-
/**
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** Webhook header names. Read these first. */
|
|
12
|
+
export declare const WEBHOOK_HEADERS: {
|
|
13
|
+
readonly signature: "X-Webhook-Signature";
|
|
14
|
+
readonly event: "X-Webhook-Event";
|
|
15
|
+
readonly delivery: "X-Webhook-Delivery";
|
|
16
|
+
readonly timestamp: "X-Webhook-Timestamp";
|
|
17
|
+
};
|
|
18
|
+
/** The older names for the same headers, sent alongside {@link WEBHOOK_HEADERS} until they are retired. */
|
|
19
|
+
export declare const LEGACY_WEBHOOK_HEADERS: {
|
|
20
|
+
readonly signature: "X-Finn-Signature";
|
|
21
|
+
readonly event: "X-Finn-Event";
|
|
22
|
+
readonly delivery: "X-Finn-Delivery";
|
|
23
|
+
readonly timestamp: "X-Finn-Timestamp";
|
|
24
|
+
};
|
|
25
|
+
export type WebhookHeaderKind = keyof typeof WEBHOOK_HEADERS;
|
|
26
|
+
/**
|
|
27
|
+
* Header that carries the signature (older name).
|
|
28
|
+
* @deprecated Use `WEBHOOK_HEADERS.signature` (`X-Webhook-Signature`); verifyWebhook() reads either.
|
|
29
|
+
*/
|
|
30
|
+
export declare const WEBHOOK_SIGNATURE_HEADER: "X-Finn-Signature";
|
|
31
|
+
/**
|
|
32
|
+
* Header that carries the event name (older name).
|
|
33
|
+
* @deprecated Use `WEBHOOK_HEADERS.event` (`X-Webhook-Event`); readWebhookHeader() reads either.
|
|
34
|
+
*/
|
|
35
|
+
export declare const WEBHOOK_EVENT_HEADER: "X-Finn-Event";
|
|
13
36
|
/** Default largest gap, in seconds, between the signed timestamp and now. */
|
|
14
37
|
export declare const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
15
38
|
/**
|
|
@@ -36,7 +59,7 @@ export declare class FinnWebhookVerificationError extends FinnSdkError {
|
|
|
36
59
|
export interface VerifyWebhookOptions {
|
|
37
60
|
/** The raw request body, exactly as received (not re-serialised JSON). */
|
|
38
61
|
payload: string | Uint8Array;
|
|
39
|
-
/** The `X-Finn-Signature` value, or the request's headers to read it from. */
|
|
62
|
+
/** The `X-Webhook-Signature` (or older `X-Finn-Signature`) value, or the request's headers to read it from. */
|
|
40
63
|
header?: string | null;
|
|
41
64
|
headers?: Headers | Record<string, string | string[] | undefined>;
|
|
42
65
|
/** The endpoint's signing secret (`whsec_...`). Pass several while you rotate secrets. */
|
|
@@ -51,6 +74,13 @@ export declare function parseSignatureHeader(header: string): {
|
|
|
51
74
|
timestamp: number;
|
|
52
75
|
signatures: string[];
|
|
53
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Reads a webhook header from a request's headers (a `Headers` or a Node headers object, any case): the neutral
|
|
79
|
+
* `X-Webhook-*` name first, then the older `X-Finn-*` name. Returns null when neither is set.
|
|
80
|
+
*
|
|
81
|
+
* const event = readWebhookHeader(req.headers, 'event'); // 'call.completed'
|
|
82
|
+
*/
|
|
83
|
+
export declare function readWebhookHeader(headers: VerifyWebhookOptions['headers'], kind: WebhookHeaderKind): string | null;
|
|
54
84
|
/** Compares two byte arrays in time that depends only on their length. */
|
|
55
85
|
export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
56
86
|
/** Hex HMAC-SHA256 of `<timestamp>.<payload>`, the way Finn signs deliveries. */
|
package/dist/esm/webhooks.js
CHANGED
|
@@ -2,14 +2,36 @@ import { FinnSdkError } from './errors.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Webhook signature checks.
|
|
4
4
|
*
|
|
5
|
-
* Finn signs every delivery with `X-
|
|
6
|
-
* and names the event in `X-
|
|
7
|
-
*
|
|
5
|
+
* Finn signs every delivery with `X-Webhook-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`
|
|
6
|
+
* and names the event in `X-Webhook-Event`. Deliveries also carry the same values under the older `X-Finn-*` names
|
|
7
|
+
* until those are retired; the readers here take the neutral name first and fall back to the old one.
|
|
8
|
+
* verifyWebhook() checks the signature in constant time and refuses deliveries whose timestamp is too far from now,
|
|
9
|
+
* so a captured request cannot be replayed later.
|
|
8
10
|
*/
|
|
9
|
-
/**
|
|
10
|
-
export const
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** Webhook header names. Read these first. */
|
|
12
|
+
export const WEBHOOK_HEADERS = {
|
|
13
|
+
signature: 'X-Webhook-Signature',
|
|
14
|
+
event: 'X-Webhook-Event',
|
|
15
|
+
delivery: 'X-Webhook-Delivery',
|
|
16
|
+
timestamp: 'X-Webhook-Timestamp',
|
|
17
|
+
};
|
|
18
|
+
/** The older names for the same headers, sent alongside {@link WEBHOOK_HEADERS} until they are retired. */
|
|
19
|
+
export const LEGACY_WEBHOOK_HEADERS = {
|
|
20
|
+
signature: 'X-Finn-Signature',
|
|
21
|
+
event: 'X-Finn-Event',
|
|
22
|
+
delivery: 'X-Finn-Delivery',
|
|
23
|
+
timestamp: 'X-Finn-Timestamp',
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Header that carries the signature (older name).
|
|
27
|
+
* @deprecated Use `WEBHOOK_HEADERS.signature` (`X-Webhook-Signature`); verifyWebhook() reads either.
|
|
28
|
+
*/
|
|
29
|
+
export const WEBHOOK_SIGNATURE_HEADER = LEGACY_WEBHOOK_HEADERS.signature;
|
|
30
|
+
/**
|
|
31
|
+
* Header that carries the event name (older name).
|
|
32
|
+
* @deprecated Use `WEBHOOK_HEADERS.event` (`X-Webhook-Event`); readWebhookHeader() reads either.
|
|
33
|
+
*/
|
|
34
|
+
export const WEBHOOK_EVENT_HEADER = LEGACY_WEBHOOK_HEADERS.event;
|
|
13
35
|
/** Default largest gap, in seconds, between the signed timestamp and now. */
|
|
14
36
|
export const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
15
37
|
/** The delivery's signature is missing, malformed, wrong or too old. Answer the request with a 400. */
|
|
@@ -36,18 +58,27 @@ export function parseSignatureHeader(header) {
|
|
|
36
58
|
}
|
|
37
59
|
return { timestamp, signatures };
|
|
38
60
|
}
|
|
39
|
-
function
|
|
40
|
-
if (!headers)
|
|
41
|
-
return null;
|
|
61
|
+
function readOne(headers, name) {
|
|
42
62
|
if (typeof headers.get === 'function')
|
|
43
|
-
return headers.get(
|
|
44
|
-
const want =
|
|
63
|
+
return headers.get(name) || null;
|
|
64
|
+
const want = name.toLowerCase();
|
|
45
65
|
for (const [k, v] of Object.entries(headers)) {
|
|
46
66
|
if (k.toLowerCase() === want)
|
|
47
|
-
return Array.isArray(v) ?
|
|
67
|
+
return (Array.isArray(v) ? v[0] : v) || null;
|
|
48
68
|
}
|
|
49
69
|
return null;
|
|
50
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Reads a webhook header from a request's headers (a `Headers` or a Node headers object, any case): the neutral
|
|
73
|
+
* `X-Webhook-*` name first, then the older `X-Finn-*` name. Returns null when neither is set.
|
|
74
|
+
*
|
|
75
|
+
* const event = readWebhookHeader(req.headers, 'event'); // 'call.completed'
|
|
76
|
+
*/
|
|
77
|
+
export function readWebhookHeader(headers, kind) {
|
|
78
|
+
if (!headers)
|
|
79
|
+
return null;
|
|
80
|
+
return readOne(headers, WEBHOOK_HEADERS[kind]) ?? readOne(headers, LEGACY_WEBHOOK_HEADERS[kind]);
|
|
81
|
+
}
|
|
51
82
|
async function subtleCrypto() {
|
|
52
83
|
const c = globalThis.crypto;
|
|
53
84
|
if (c?.subtle)
|
|
@@ -107,12 +138,13 @@ export async function verifyWebhook(options) {
|
|
|
107
138
|
const secrets = (typeof options.secret === 'string' ? [options.secret] : [...options.secret]).filter((s) => !!s);
|
|
108
139
|
if (secrets.length === 0)
|
|
109
140
|
throw new FinnWebhookVerificationError('Missing webhook signing secret.');
|
|
110
|
-
const header = options.header ??
|
|
111
|
-
if (!header)
|
|
112
|
-
throw new FinnWebhookVerificationError(`Missing ${
|
|
141
|
+
const header = options.header ?? readWebhookHeader(options.headers, 'signature');
|
|
142
|
+
if (!header) {
|
|
143
|
+
throw new FinnWebhookVerificationError(`Missing ${WEBHOOK_HEADERS.signature} (or ${LEGACY_WEBHOOK_HEADERS.signature}) header.`);
|
|
144
|
+
}
|
|
113
145
|
const { timestamp, signatures } = parseSignatureHeader(header);
|
|
114
146
|
if (!Number.isFinite(timestamp) || signatures.length === 0) {
|
|
115
|
-
throw new FinnWebhookVerificationError(`Malformed ${
|
|
147
|
+
throw new FinnWebhookVerificationError(`Malformed ${WEBHOOK_HEADERS.signature} header: expected t=<unix>,v1=<hex>.`);
|
|
116
148
|
}
|
|
117
149
|
const tolerance = options.toleranceSeconds ?? DEFAULT_WEBHOOK_TOLERANCE_SECONDS;
|
|
118
150
|
const now = options.now ?? Math.floor(Date.now() / 1000);
|