@hirefinn/sdk 0.5.0 → 0.5.2
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 +25 -12
- package/dist/cjs/client.d.ts +16 -6
- package/dist/cjs/client.js +9 -6
- package/dist/cjs/core.d.ts +18 -6
- package/dist/cjs/core.js +23 -7
- package/dist/cjs/errors.d.ts +40 -2
- package/dist/cjs/errors.js +44 -1
- package/dist/cjs/generated/openapi.d.ts +6259 -6222
- package/dist/cjs/generated/operations.d.ts +1 -1
- package/dist/cjs/generated/operations.js +23 -23
- package/dist/cjs/generated/resources.d.ts +47 -47
- package/dist/cjs/generated/resources.js +48 -48
- package/dist/cjs/index.d.ts +7 -7
- package/dist/cjs/index.js +16 -1
- package/dist/cjs/resources.d.ts +25 -17
- package/dist/cjs/resources.js +23 -18
- package/dist/cjs/types.d.ts +2 -2
- package/dist/cjs/webhooks.d.ts +58 -10
- package/dist/cjs/webhooks.js +53 -18
- package/dist/esm/client.d.ts +16 -6
- package/dist/esm/client.js +9 -6
- package/dist/esm/core.d.ts +18 -6
- package/dist/esm/core.js +22 -6
- package/dist/esm/errors.d.ts +40 -2
- package/dist/esm/errors.js +41 -0
- package/dist/esm/generated/openapi.d.ts +6259 -6222
- package/dist/esm/generated/operations.d.ts +1 -1
- package/dist/esm/generated/operations.js +23 -23
- package/dist/esm/generated/resources.d.ts +47 -47
- package/dist/esm/generated/resources.js +46 -46
- package/dist/esm/index.d.ts +7 -7
- package/dist/esm/index.js +4 -4
- package/dist/esm/resources.d.ts +25 -17
- package/dist/esm/resources.js +22 -17
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/webhooks.d.ts +58 -10
- package/dist/esm/webhooks.js +51 -17
- package/package.json +1 -1
package/dist/cjs/resources.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import type { FinnCore } from './core.js';
|
|
8
8
|
import { Resource, type B, type Id, type Q } from './resource.js';
|
|
9
9
|
import type { ApprovalHold, RequestOptions, Schemas } from './types.js';
|
|
10
|
-
import { AgentsGenerated, ApprovalsGenerated, AudiencesGenerated, CallsGenerated, CasesGenerated, ChatGenerated, ContactsGenerated, DeploymentsGenerated, DoNotCallGenerated,
|
|
10
|
+
import { AgentsGenerated, ApprovalsGenerated, AssistantsGenerated, AudiencesGenerated, CallsGenerated, CasesGenerated, ChatGenerated, ContactsGenerated, DeploymentsGenerated, DoNotCallGenerated, PhoneNumbersGenerated, VoicesGenerated, WalletGenerated } from './generated/resources.js';
|
|
11
11
|
export { Crm, Dialer, Organization, Sales, Webhooks } from './generated/resources.js';
|
|
12
12
|
export declare class Calls extends CallsGenerated {
|
|
13
13
|
/** Place an outbound call. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
|
|
@@ -43,17 +43,19 @@ export declare class Calls extends CallsGenerated {
|
|
|
43
43
|
data: import("./types.js").components["schemas"]["Call"];
|
|
44
44
|
}>;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
/** Assistants (voice agents): `/assistants`. Reached as `client.assistants` (and, deprecated, `client.finns`). */
|
|
47
|
+
export declare class Assistants extends AssistantsGenerated {
|
|
48
|
+
list(query?: Q<'/assistants', 'get'>, options?: RequestOptions): Promise<{
|
|
48
49
|
success: true;
|
|
49
|
-
data: import("./types.js").components["schemas"]["
|
|
50
|
+
data: import("./types.js").components["schemas"]["Assistant"][];
|
|
50
51
|
limit: number;
|
|
51
52
|
offset: number;
|
|
52
53
|
}>;
|
|
53
|
-
listAll(query?: Q<'/
|
|
54
|
+
listAll(query?: Q<'/assistants', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
|
|
54
55
|
id: string;
|
|
55
56
|
name: string;
|
|
56
57
|
status: string;
|
|
58
|
+
channel?: "voice" | "chat";
|
|
57
59
|
voice: string | null;
|
|
58
60
|
language: string | null;
|
|
59
61
|
language_group: string | null;
|
|
@@ -74,36 +76,42 @@ export declare class Finns extends FinnsGenerated {
|
|
|
74
76
|
created_at: string;
|
|
75
77
|
updated_at: string;
|
|
76
78
|
}, unknown>;
|
|
77
|
-
create(body: B<'/
|
|
79
|
+
create(body: B<'/assistants', 'post'>, options?: RequestOptions): Promise<{
|
|
78
80
|
success: true;
|
|
79
|
-
data: import("./types.js").components["schemas"]["
|
|
81
|
+
data: import("./types.js").components["schemas"]["Assistant"];
|
|
80
82
|
}>;
|
|
81
|
-
retrieve(
|
|
83
|
+
retrieve(assistantId: Id, options?: RequestOptions): Promise<{
|
|
82
84
|
success: true;
|
|
83
|
-
data: import("./types.js").components["schemas"]["
|
|
85
|
+
data: import("./types.js").components["schemas"]["Assistant"];
|
|
84
86
|
}>;
|
|
85
|
-
update(
|
|
87
|
+
update(assistantId: Id, body: B<'/assistants/{assistant_id}', 'patch'>, options?: RequestOptions): Promise<{
|
|
86
88
|
success: true;
|
|
87
|
-
data: import("./types.js").components["schemas"]["
|
|
89
|
+
data: import("./types.js").components["schemas"]["Assistant"];
|
|
88
90
|
}>;
|
|
89
|
-
delete(
|
|
91
|
+
delete(assistantId: Id, options?: RequestOptions): Promise<{
|
|
90
92
|
success: true;
|
|
91
|
-
data: import("./types.js").components["schemas"]["
|
|
93
|
+
data: import("./types.js").components["schemas"]["DeletedAssistant"];
|
|
92
94
|
}>;
|
|
93
|
-
listKnowledgeBase(
|
|
95
|
+
listKnowledgeBase(assistantId: Id, options?: RequestOptions): Promise<{
|
|
94
96
|
success: true;
|
|
95
97
|
data: import("./types.js").components["schemas"]["KnowledgeBaseDocument"][];
|
|
96
98
|
}>;
|
|
97
99
|
/** JSON body, or a FormData with the file for multipart upload. */
|
|
98
|
-
addKnowledgeBaseDocument(
|
|
100
|
+
addKnowledgeBaseDocument(assistantId: Id, body: B<'/assistants/{assistant_id}/knowledge_base', 'post'> | FormData, options?: RequestOptions): Promise<{
|
|
99
101
|
success: true;
|
|
100
102
|
data: import("./types.js").components["schemas"]["KnowledgeBaseDocument"];
|
|
101
103
|
}>;
|
|
102
|
-
postCallAnalysis(
|
|
104
|
+
postCallAnalysis(assistantId: Id, query?: Q<'/assistants/{assistant_id}/post_call_analysis', 'get'>, options?: RequestOptions): Promise<{
|
|
103
105
|
success: true;
|
|
104
|
-
data: import("./types.js").components["schemas"]["
|
|
106
|
+
data: import("./types.js").components["schemas"]["AssistantPostCallAnalysis"];
|
|
105
107
|
}>;
|
|
106
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Renamed to {@link Assistants}; `Finns` is the same class and will be removed in a future major version.
|
|
111
|
+
*/
|
|
112
|
+
export declare const Finns: typeof Assistants;
|
|
113
|
+
/** @deprecated Renamed to {@link Assistants}. */
|
|
114
|
+
export type Finns = Assistants;
|
|
107
115
|
export declare class Voices extends VoicesGenerated {
|
|
108
116
|
list(query?: Q<'/voices', 'get'>, options?: RequestOptions): Promise<{
|
|
109
117
|
success: true;
|
package/dist/cjs/resources.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Chat = exports.ChatContacts = exports.ChatConversations = exports.Agents = exports.Approvals = exports.Cases = exports.Contacts = exports.DoNotCall = exports.Wallet = exports.Deployments = exports.Audiences = exports.PhoneNumbers = exports.Voices = exports.Finns = exports.Calls = exports.Webhooks = exports.Sales = exports.Organization = exports.Dialer = exports.Crm = void 0;
|
|
3
|
+
exports.Chat = exports.ChatContacts = exports.ChatConversations = exports.Agents = exports.Approvals = exports.Cases = exports.Contacts = exports.DoNotCall = exports.Wallet = exports.Deployments = exports.Audiences = exports.PhoneNumbers = exports.Voices = exports.Finns = exports.Assistants = exports.Calls = exports.Webhooks = exports.Sales = exports.Organization = exports.Dialer = exports.Crm = void 0;
|
|
4
4
|
const errors_js_1 = require("./errors.js");
|
|
5
5
|
const pagination_js_1 = require("./pagination.js");
|
|
6
6
|
const resource_js_1 = require("./resource.js");
|
|
@@ -29,37 +29,42 @@ class Calls extends resources_js_1.CallsGenerated {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
exports.Calls = Calls;
|
|
32
|
-
|
|
32
|
+
/** Assistants (voice agents): `/assistants`. Reached as `client.assistants` (and, deprecated, `client.finns`). */
|
|
33
|
+
class Assistants extends resources_js_1.AssistantsGenerated {
|
|
33
34
|
list(query, options) {
|
|
34
|
-
return this.do('get', '/
|
|
35
|
+
return this.do('get', '/assistants', { query }, options);
|
|
35
36
|
}
|
|
36
37
|
listAll(query, options) {
|
|
37
|
-
return this.pager('/
|
|
38
|
+
return this.pager('/assistants', (0, pagination_js_1.offsetStrategy)(), query, undefined, options);
|
|
38
39
|
}
|
|
39
40
|
create(body, options) {
|
|
40
|
-
return this.do('post', '/
|
|
41
|
+
return this.do('post', '/assistants', { body }, options);
|
|
41
42
|
}
|
|
42
|
-
retrieve(
|
|
43
|
-
return this.do('get', '/
|
|
43
|
+
retrieve(assistantId, options) {
|
|
44
|
+
return this.do('get', '/assistants/{assistant_id}', { path: { assistant_id: assistantId } }, options);
|
|
44
45
|
}
|
|
45
|
-
update(
|
|
46
|
-
return this.do('patch', '/
|
|
46
|
+
update(assistantId, body, options) {
|
|
47
|
+
return this.do('patch', '/assistants/{assistant_id}', { path: { assistant_id: assistantId }, body }, options);
|
|
47
48
|
}
|
|
48
|
-
delete(
|
|
49
|
-
return this.do('delete', '/
|
|
49
|
+
delete(assistantId, options) {
|
|
50
|
+
return this.do('delete', '/assistants/{assistant_id}', { path: { assistant_id: assistantId } }, options);
|
|
50
51
|
}
|
|
51
|
-
listKnowledgeBase(
|
|
52
|
-
return this.do('get', '/
|
|
52
|
+
listKnowledgeBase(assistantId, options) {
|
|
53
|
+
return this.do('get', '/assistants/{assistant_id}/knowledge_base', { path: { assistant_id: assistantId } }, options);
|
|
53
54
|
}
|
|
54
55
|
/** JSON body, or a FormData with the file for multipart upload. */
|
|
55
|
-
addKnowledgeBaseDocument(
|
|
56
|
-
return this.do('post', '/
|
|
56
|
+
addKnowledgeBaseDocument(assistantId, body, options) {
|
|
57
|
+
return this.do('post', '/assistants/{assistant_id}/knowledge_base', { path: { assistant_id: assistantId }, body }, options);
|
|
57
58
|
}
|
|
58
|
-
postCallAnalysis(
|
|
59
|
-
return this.do('get', '/
|
|
59
|
+
postCallAnalysis(assistantId, query, options) {
|
|
60
|
+
return this.do('get', '/assistants/{assistant_id}/post_call_analysis', { path: { assistant_id: assistantId }, query }, options);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
exports.
|
|
63
|
+
exports.Assistants = Assistants;
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Renamed to {@link Assistants}; `Finns` is the same class and will be removed in a future major version.
|
|
66
|
+
*/
|
|
67
|
+
exports.Finns = Assistants;
|
|
63
68
|
class Voices extends resources_js_1.VoicesGenerated {
|
|
64
69
|
list(query, options) {
|
|
65
70
|
return this.do('get', '/voices', { query }, options);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -81,9 +81,9 @@ export interface RequestOptions {
|
|
|
81
81
|
* Pass `false` to send none, even on an endpoint where the SDK would make one up.
|
|
82
82
|
*/
|
|
83
83
|
idempotencyKey?: string | false;
|
|
84
|
-
/** Org to act in (
|
|
84
|
+
/** Org to act in (X-Org-Id header, formerly Finn-Org), for tokens that can use more than one org. */
|
|
85
85
|
org?: string;
|
|
86
|
-
/** API version date (
|
|
86
|
+
/** API version date (Api-Version header, formerly Finn-Version), e.g. `2026-11-01`. */
|
|
87
87
|
version?: string;
|
|
88
88
|
/** Retries after the first attempt. */
|
|
89
89
|
maxRetries?: number;
|
package/dist/cjs/webhooks.d.ts
CHANGED
|
@@ -2,21 +2,59 @@ 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
|
/**
|
|
16
39
|
* The body of a webhook delivery (the Finn envelope). Endpoints imported from Finn Chat with the `chat` envelope get
|
|
17
40
|
* Finn Chat's own body instead: `{ id, event, createdAt, orgId, data }`.
|
|
18
41
|
*/
|
|
19
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The fields a call webhook's `data` uses to name the agent (`call.completed`, `call.analyzed`, transcript events).
|
|
44
|
+
* `agent_id` / `agent_name` are the current names; servers before the rename send only `finn_id` / `finn_name`, and
|
|
45
|
+
* newer servers send both with the same values until the old names retire. Read `agent_id ?? finn_id`.
|
|
46
|
+
*/
|
|
47
|
+
export interface WebhookAgentFields {
|
|
48
|
+
/** The agent (assistant) that handled the call. */
|
|
49
|
+
agent_id?: string | null;
|
|
50
|
+
/** The agent's name, where the event carries one. */
|
|
51
|
+
agent_name?: string | null;
|
|
52
|
+
/** @deprecated Old name of `agent_id`, same value. */
|
|
53
|
+
finn_id?: string | null;
|
|
54
|
+
/** @deprecated Old name of `agent_name`, same value. */
|
|
55
|
+
finn_name?: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface WebhookEvent<T = Record<string, unknown> & WebhookAgentFields> {
|
|
20
58
|
/** e.g. `call.completed`, `contact.created`, `case.completed`. */
|
|
21
59
|
event: string;
|
|
22
60
|
/** Unique per event, and the same on every retry or redelivery of it: dedupe on it. */
|
|
@@ -33,10 +71,13 @@ export interface WebhookEvent<T = Record<string, unknown>> {
|
|
|
33
71
|
export declare class FinnWebhookVerificationError extends FinnSdkError {
|
|
34
72
|
constructor(message: string);
|
|
35
73
|
}
|
|
74
|
+
/** The neutral name of {@link FinnWebhookVerificationError}: the same class, so `instanceof` works with either name. */
|
|
75
|
+
export declare const WebhookVerificationError: typeof FinnWebhookVerificationError;
|
|
76
|
+
export type WebhookVerificationError = FinnWebhookVerificationError;
|
|
36
77
|
export interface VerifyWebhookOptions {
|
|
37
78
|
/** The raw request body, exactly as received (not re-serialised JSON). */
|
|
38
79
|
payload: string | Uint8Array;
|
|
39
|
-
/** The `X-Finn-Signature` value, or the request's headers to read it from. */
|
|
80
|
+
/** The `X-Webhook-Signature` (or older `X-Finn-Signature`) value, or the request's headers to read it from. */
|
|
40
81
|
header?: string | null;
|
|
41
82
|
headers?: Headers | Record<string, string | string[] | undefined>;
|
|
42
83
|
/** The endpoint's signing secret (`whsec_...`). Pass several while you rotate secrets. */
|
|
@@ -51,6 +92,13 @@ export declare function parseSignatureHeader(header: string): {
|
|
|
51
92
|
timestamp: number;
|
|
52
93
|
signatures: string[];
|
|
53
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Reads a webhook header from a request's headers (a `Headers` or a Node headers object, any case): the neutral
|
|
97
|
+
* `X-Webhook-*` name first, then the older `X-Finn-*` name. Returns null when neither is set.
|
|
98
|
+
*
|
|
99
|
+
* const event = readWebhookHeader(req.headers, 'event'); // 'call.completed'
|
|
100
|
+
*/
|
|
101
|
+
export declare function readWebhookHeader(headers: VerifyWebhookOptions['headers'], kind: WebhookHeaderKind): string | null;
|
|
54
102
|
/** Compares two byte arrays in time that depends only on their length. */
|
|
55
103
|
export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
56
104
|
/** Hex HMAC-SHA256 of `<timestamp>.<payload>`, the way Finn signs deliveries. */
|
|
@@ -64,4 +112,4 @@ export declare function signWebhookPayload(secret: string, timestamp: number | s
|
|
|
64
112
|
* ...
|
|
65
113
|
* });
|
|
66
114
|
*/
|
|
67
|
-
export declare function verifyWebhook<T = Record<string, unknown
|
|
115
|
+
export declare function verifyWebhook<T = Record<string, unknown> & WebhookAgentFields>(options: VerifyWebhookOptions): Promise<WebhookEvent<T>>;
|
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.WebhookVerificationError = 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. */
|
|
@@ -60,6 +83,8 @@ class FinnWebhookVerificationError extends errors_js_1.FinnSdkError {
|
|
|
60
83
|
}
|
|
61
84
|
}
|
|
62
85
|
exports.FinnWebhookVerificationError = FinnWebhookVerificationError;
|
|
86
|
+
/** The neutral name of {@link FinnWebhookVerificationError}: the same class, so `instanceof` works with either name. */
|
|
87
|
+
exports.WebhookVerificationError = FinnWebhookVerificationError;
|
|
63
88
|
/** Splits `t=...,v1=...` into its timestamp and v1 signatures. */
|
|
64
89
|
function parseSignatureHeader(header) {
|
|
65
90
|
let timestamp = NaN;
|
|
@@ -77,18 +102,27 @@ function parseSignatureHeader(header) {
|
|
|
77
102
|
}
|
|
78
103
|
return { timestamp, signatures };
|
|
79
104
|
}
|
|
80
|
-
function
|
|
81
|
-
if (!headers)
|
|
82
|
-
return null;
|
|
105
|
+
function readOne(headers, name) {
|
|
83
106
|
if (typeof headers.get === 'function')
|
|
84
|
-
return headers.get(
|
|
85
|
-
const want =
|
|
107
|
+
return headers.get(name) || null;
|
|
108
|
+
const want = name.toLowerCase();
|
|
86
109
|
for (const [k, v] of Object.entries(headers)) {
|
|
87
110
|
if (k.toLowerCase() === want)
|
|
88
|
-
return Array.isArray(v) ?
|
|
111
|
+
return (Array.isArray(v) ? v[0] : v) || null;
|
|
89
112
|
}
|
|
90
113
|
return null;
|
|
91
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Reads a webhook header from a request's headers (a `Headers` or a Node headers object, any case): the neutral
|
|
117
|
+
* `X-Webhook-*` name first, then the older `X-Finn-*` name. Returns null when neither is set.
|
|
118
|
+
*
|
|
119
|
+
* const event = readWebhookHeader(req.headers, 'event'); // 'call.completed'
|
|
120
|
+
*/
|
|
121
|
+
function readWebhookHeader(headers, kind) {
|
|
122
|
+
if (!headers)
|
|
123
|
+
return null;
|
|
124
|
+
return readOne(headers, exports.WEBHOOK_HEADERS[kind]) ?? readOne(headers, exports.LEGACY_WEBHOOK_HEADERS[kind]);
|
|
125
|
+
}
|
|
92
126
|
async function subtleCrypto() {
|
|
93
127
|
const c = globalThis.crypto;
|
|
94
128
|
if (c?.subtle)
|
|
@@ -148,12 +182,13 @@ async function verifyWebhook(options) {
|
|
|
148
182
|
const secrets = (typeof options.secret === 'string' ? [options.secret] : [...options.secret]).filter((s) => !!s);
|
|
149
183
|
if (secrets.length === 0)
|
|
150
184
|
throw new FinnWebhookVerificationError('Missing webhook signing secret.');
|
|
151
|
-
const header = options.header ??
|
|
152
|
-
if (!header)
|
|
153
|
-
throw new FinnWebhookVerificationError(`Missing ${exports.
|
|
185
|
+
const header = options.header ?? readWebhookHeader(options.headers, 'signature');
|
|
186
|
+
if (!header) {
|
|
187
|
+
throw new FinnWebhookVerificationError(`Missing ${exports.WEBHOOK_HEADERS.signature} (or ${exports.LEGACY_WEBHOOK_HEADERS.signature}) header.`);
|
|
188
|
+
}
|
|
154
189
|
const { timestamp, signatures } = parseSignatureHeader(header);
|
|
155
190
|
if (!Number.isFinite(timestamp) || signatures.length === 0) {
|
|
156
|
-
throw new FinnWebhookVerificationError(`Malformed ${exports.
|
|
191
|
+
throw new FinnWebhookVerificationError(`Malformed ${exports.WEBHOOK_HEADERS.signature} header: expected t=<unix>,v1=<hex>.`);
|
|
157
192
|
}
|
|
158
193
|
const tolerance = options.toleranceSeconds ?? exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS;
|
|
159
194
|
const now = options.now ?? Math.floor(Date.now() / 1000);
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { FinnCore, type FinnOptions } from './core.js';
|
|
2
|
-
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall,
|
|
2
|
+
import { Agents, Approvals, Assistants, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall, Organization, PhoneNumbers, Sales, Voices, Wallet, Webhooks, type WaitForApprovalOptions } from './resources.js';
|
|
3
3
|
import type { ApprovalHold, Schemas } from './types.js';
|
|
4
4
|
/**
|
|
5
|
-
* The
|
|
5
|
+
* The API client. `Client` is the neutral name of the same class.
|
|
6
6
|
*
|
|
7
|
-
* import {
|
|
8
|
-
* const
|
|
9
|
-
* const { data } = await
|
|
7
|
+
* import { Client } from '@hirefinn/sdk';
|
|
8
|
+
* const client = new Client({ apiKey: process.env.FINN_API_KEY });
|
|
9
|
+
* const { data } = await client.calls.list({ limit: 10 });
|
|
10
10
|
*/
|
|
11
11
|
export declare class Finn extends FinnCore {
|
|
12
12
|
readonly calls: Calls;
|
|
13
|
-
|
|
13
|
+
/** Assistants (voice agents): `/assistants`. */
|
|
14
|
+
readonly assistants: Assistants;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use {@link Finn.assistants}: the very same object (`client.finns === client.assistants`), kept so
|
|
17
|
+
* existing code runs. It calls `/assistants`, not the old `/finns` path.
|
|
18
|
+
*/
|
|
19
|
+
readonly finns: Assistants;
|
|
14
20
|
readonly voices: Voices;
|
|
15
21
|
readonly phoneNumbers: PhoneNumbers;
|
|
16
22
|
readonly audiences: Audiences;
|
|
@@ -40,3 +46,7 @@ export declare class Finn extends FinnCore {
|
|
|
40
46
|
/** Polls an approval until it is decided (see approvals.wait). */
|
|
41
47
|
waitForApproval(id: string, options?: WaitForApprovalOptions): Promise<ApprovalHold | Schemas['Approval']>;
|
|
42
48
|
}
|
|
49
|
+
/** The neutral name of the API client: the same class as {@link Finn}, so `instanceof` works with either name. */
|
|
50
|
+
export declare const Client: typeof Finn;
|
|
51
|
+
/** The neutral name of the API client. */
|
|
52
|
+
export type Client = Finn;
|
package/dist/esm/client.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { FinnCore } from './core.js';
|
|
2
|
-
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall,
|
|
2
|
+
import { Agents, Approvals, Assistants, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall, Organization, PhoneNumbers, Sales, Voices, Wallet, Webhooks, } from './resources.js';
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
4
|
+
* The API client. `Client` is the neutral name of the same class.
|
|
5
5
|
*
|
|
6
|
-
* import {
|
|
7
|
-
* const
|
|
8
|
-
* const { data } = await
|
|
6
|
+
* import { Client } from '@hirefinn/sdk';
|
|
7
|
+
* const client = new Client({ apiKey: process.env.FINN_API_KEY });
|
|
8
|
+
* const { data } = await client.calls.list({ limit: 10 });
|
|
9
9
|
*/
|
|
10
10
|
export class Finn extends FinnCore {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
super(options);
|
|
13
13
|
this.calls = new Calls(this);
|
|
14
|
-
this.
|
|
14
|
+
this.assistants = new Assistants(this);
|
|
15
|
+
this.finns = this.assistants;
|
|
15
16
|
this.voices = new Voices(this);
|
|
16
17
|
this.phoneNumbers = new PhoneNumbers(this);
|
|
17
18
|
this.audiences = new Audiences(this);
|
|
@@ -34,3 +35,5 @@ export class Finn extends FinnCore {
|
|
|
34
35
|
return this.approvals.wait(id, options);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
38
|
+
/** The neutral name of the API client: the same class as {@link Finn}, so `instanceof` works with either name. */
|
|
39
|
+
export const Client = Finn;
|
package/dist/esm/core.d.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
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.
|
|
4
|
-
/** The API version this SDK was built against, sent as
|
|
3
|
+
export declare const SDK_VERSION = "0.5.2";
|
|
4
|
+
/** The API version this SDK was built against, sent as Api-Version unless `version` says otherwise. */
|
|
5
5
|
export declare const DEFAULT_FINN_VERSION = "2026-11-01";
|
|
6
|
+
/** The neutral name of {@link DEFAULT_FINN_VERSION}. */
|
|
7
|
+
export declare const DEFAULT_API_VERSION = "2026-11-01";
|
|
8
|
+
/**
|
|
9
|
+
* Request headers the API renamed: old name -> the name the SDK sends. The API still accepts the old names, but answers
|
|
10
|
+
* `400` when a request carries both names with different values, so the SDK only ever sends the new one: an old name
|
|
11
|
+
* passed in `defaultHeaders` or per-request `headers` is sent under its new name.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RENAMED_REQUEST_HEADERS: Readonly<Record<string, string>>;
|
|
6
14
|
export interface FinnOptions {
|
|
7
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* `wsk_live_...` org key, `wsk_test_...` test key, or an OAuth `wsk_oat_...` token (older keys: `finn_live_...`,
|
|
17
|
+
* `finn_test_...`, `finn_oat_...`; both work). Sent as given. Defaults to env FINN_API_KEY.
|
|
18
|
+
*/
|
|
8
19
|
apiKey?: string;
|
|
9
20
|
/** Defaults to `https://api.hirefinn.ai/v1`. */
|
|
10
21
|
baseUrl?: string;
|
|
11
|
-
/** Org to act in (
|
|
22
|
+
/** Org to act in (X-Org-Id header, formerly Finn-Org). Needed only for tokens that can use more than one org. */
|
|
12
23
|
org?: string;
|
|
13
24
|
/**
|
|
14
|
-
* Pins the API version (
|
|
15
|
-
* version this SDK was built against; `null` sends no header (the key's pinned version,
|
|
25
|
+
* Pins the API version (Api-Version header, formerly Finn-Version), a date such as `2026-11-01`. Defaults to
|
|
26
|
+
* DEFAULT_FINN_VERSION, the version this SDK was built against; `null` sends no header (the key's pinned version,
|
|
27
|
+
* else the current one).
|
|
16
28
|
*/
|
|
17
29
|
version?: string | null;
|
|
18
30
|
/**
|
package/dist/esm/core.js
CHANGED
|
@@ -12,9 +12,25 @@ 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.
|
|
16
|
-
/** The API version this SDK was built against, sent as
|
|
15
|
+
export const SDK_VERSION = '0.5.2';
|
|
16
|
+
/** The API version this SDK was built against, sent as Api-Version unless `version` says otherwise. */
|
|
17
17
|
export const DEFAULT_FINN_VERSION = '2026-11-01';
|
|
18
|
+
/** The neutral name of {@link DEFAULT_FINN_VERSION}. */
|
|
19
|
+
export const DEFAULT_API_VERSION = DEFAULT_FINN_VERSION;
|
|
20
|
+
/**
|
|
21
|
+
* Request headers the API renamed: old name -> the name the SDK sends. The API still accepts the old names, but answers
|
|
22
|
+
* `400` when a request carries both names with different values, so the SDK only ever sends the new one: an old name
|
|
23
|
+
* passed in `defaultHeaders` or per-request `headers` is sent under its new name.
|
|
24
|
+
*/
|
|
25
|
+
export const RENAMED_REQUEST_HEADERS = Object.freeze({
|
|
26
|
+
'finn-version': 'Api-Version',
|
|
27
|
+
'finn-org': 'X-Org-Id',
|
|
28
|
+
});
|
|
29
|
+
/** Sets a header, sending a renamed one (Finn-Version, Finn-Org) under its new name. */
|
|
30
|
+
function setHeader(headers, name, value) {
|
|
31
|
+
const renamed = RENAMED_REQUEST_HEADERS[name.toLowerCase()];
|
|
32
|
+
headers.set(renamed ?? name, value);
|
|
33
|
+
}
|
|
18
34
|
// Browsers own the User-Agent header, so it is only set on server runtimes.
|
|
19
35
|
const IS_NODE = typeof globalThis.process?.versions?.node === 'string';
|
|
20
36
|
/** Writes that get an automatic Idempotency-Key (when autoIdempotency is on). */
|
|
@@ -164,13 +180,13 @@ export class FinnCore {
|
|
|
164
180
|
if (IS_NODE)
|
|
165
181
|
headers.set('User-Agent', `finn-node/${SDK_VERSION}`);
|
|
166
182
|
for (const [k, v] of Object.entries(__classPrivateFieldGet(this, _FinnCore_defaultHeaders, "f")))
|
|
167
|
-
headers
|
|
183
|
+
setHeader(headers, k, v);
|
|
168
184
|
const org = options.org ?? this.org;
|
|
169
185
|
if (org)
|
|
170
|
-
headers.set('
|
|
186
|
+
headers.set('X-Org-Id', org);
|
|
171
187
|
const version = options.version ?? this.version;
|
|
172
188
|
if (version)
|
|
173
|
-
headers.set('
|
|
189
|
+
headers.set('Api-Version', version);
|
|
174
190
|
if (key)
|
|
175
191
|
headers.set('Idempotency-Key', key);
|
|
176
192
|
let body;
|
|
@@ -183,7 +199,7 @@ export class FinnCore {
|
|
|
183
199
|
}
|
|
184
200
|
}
|
|
185
201
|
for (const [k, v] of Object.entries(options.headers ?? {}))
|
|
186
|
-
headers
|
|
202
|
+
setHeader(headers, k, v);
|
|
187
203
|
headers.set('Authorization', `Bearer ${__classPrivateFieldGet(this, _FinnCore_apiKey, "f")}`);
|
|
188
204
|
// Idempotent methods always; a POST/PATCH only with a key on a route that dedupes by it.
|
|
189
205
|
const canRetry = SAFE_TO_RETRY_METHODS.has(method) || (headers.has('Idempotency-Key') && honoursIdempotencyKey(method, req.path));
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -16,8 +16,17 @@ export interface FinnFieldError {
|
|
|
16
16
|
code: string;
|
|
17
17
|
message: string;
|
|
18
18
|
}
|
|
19
|
-
/** The shared error codes. Endpoints may also answer resource-specific codes such as `
|
|
19
|
+
/** The shared error codes. Endpoints may also answer resource-specific codes such as `assistant_not_found`. */
|
|
20
20
|
export type FinnErrorCode = 'invalid_request' | 'invalid_cursor' | 'unauthorized' | 'api_key_required' | 'invalid_api_key' | 'insufficient_scope' | 'forbidden' | 'not_found' | 'conflict' | 'idempotency_in_progress' | 'payload_too_large' | 'idempotency_key_reused' | 'rate_limited' | 'internal_error' | 'unavailable' | (string & {});
|
|
21
|
+
/**
|
|
22
|
+
* Error codes the API renamed: old code -> its neutral successor. The new paths (`/assistants`, ...) answer the neutral
|
|
23
|
+
* code; the old paths answered the old one. {@link FinnError.hasCode} matches either name.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RENAMED_ERROR_CODES: Readonly<Record<string, string>>;
|
|
26
|
+
/** The neutral name of an error code: `finn_not_found` -> `assistant_not_found`; any other code as it is. */
|
|
27
|
+
export declare const neutralErrorCode: (code: string) => string;
|
|
28
|
+
/** The old name of a renamed error code: `assistant_not_found` -> `finn_not_found`; null when it was never renamed. */
|
|
29
|
+
export declare const legacyErrorCode: (code: string) => string | null;
|
|
21
30
|
/** The code an error gets when the body does not name one (mirrors the backend's codeForStatus). */
|
|
22
31
|
export declare const codeForStatus: (status: number) => string;
|
|
23
32
|
/** Base class for every error the SDK throws. */
|
|
@@ -30,8 +39,13 @@ export declare class FinnSdkError extends Error {
|
|
|
30
39
|
export declare class FinnError extends FinnSdkError {
|
|
31
40
|
/** HTTP status. */
|
|
32
41
|
readonly status: number;
|
|
33
|
-
/** Stable error code. */
|
|
42
|
+
/** Stable error code, as the API sent it (neutral names such as `assistant_not_found` on the current paths). */
|
|
34
43
|
readonly code: FinnErrorCode;
|
|
44
|
+
/**
|
|
45
|
+
* The old name of a renamed code (`finn_not_found` for `assistant_not_found`, see RENAMED_ERROR_CODES), else null.
|
|
46
|
+
* For code that still compares against the old names; prefer {@link FinnError.hasCode}.
|
|
47
|
+
*/
|
|
48
|
+
readonly legacyCode: string | null;
|
|
35
49
|
/** Matches the `X-Request-Id` response header; quote it to support. */
|
|
36
50
|
readonly requestId: string | null;
|
|
37
51
|
/** Per-field problems (unified shape, and legacy bodies that name fields as a string list; `[]` otherwise). */
|
|
@@ -64,6 +78,11 @@ export declare class FinnError extends FinnSdkError {
|
|
|
64
78
|
body?: unknown;
|
|
65
79
|
headers?: Headers;
|
|
66
80
|
});
|
|
81
|
+
/**
|
|
82
|
+
* True when this error's code is `code`, by its old or its neutral name: `hasCode('finn_not_found')` and
|
|
83
|
+
* `hasCode('assistant_not_found')` both match either answer.
|
|
84
|
+
*/
|
|
85
|
+
hasCode(code: string): boolean;
|
|
67
86
|
/** Builds a FinnError from a failed response and its already-read body. */
|
|
68
87
|
static fromResponse(status: number, headers: Headers, body: unknown, statusText?: string): FinnError;
|
|
69
88
|
}
|
|
@@ -88,3 +107,22 @@ export declare class FinnApprovalTimeoutError extends FinnSdkError {
|
|
|
88
107
|
}
|
|
89
108
|
/** Retry-After as seconds: accepts delta-seconds or an HTTP date. */
|
|
90
109
|
export declare function parseRetryAfterSeconds(value: string | null, now?: number): number | null;
|
|
110
|
+
/** The neutral name of {@link FinnSdkError}. */
|
|
111
|
+
export declare const SdkError: typeof FinnSdkError;
|
|
112
|
+
export type SdkError = FinnSdkError;
|
|
113
|
+
/** The neutral name of {@link FinnError}. */
|
|
114
|
+
export declare const ApiError: typeof FinnError;
|
|
115
|
+
export type ApiError = FinnError;
|
|
116
|
+
/** The neutral name of {@link FinnConnectionError}. */
|
|
117
|
+
export declare const ApiConnectionError: typeof FinnConnectionError;
|
|
118
|
+
export type ApiConnectionError = FinnConnectionError;
|
|
119
|
+
/** The neutral name of {@link FinnTimeoutError}. */
|
|
120
|
+
export declare const ApiTimeoutError: typeof FinnTimeoutError;
|
|
121
|
+
export type ApiTimeoutError = FinnTimeoutError;
|
|
122
|
+
/** The neutral name of {@link FinnApprovalTimeoutError}. */
|
|
123
|
+
export declare const ApprovalTimeoutError: typeof FinnApprovalTimeoutError;
|
|
124
|
+
export type ApprovalTimeoutError = FinnApprovalTimeoutError;
|
|
125
|
+
/** The neutral name of {@link FinnErrorCode}. */
|
|
126
|
+
export type ErrorCode = FinnErrorCode;
|
|
127
|
+
/** The neutral name of {@link FinnFieldError}. */
|
|
128
|
+
export type FieldError = FinnFieldError;
|