@hirefinn/sdk 0.2.0 → 0.4.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 +63 -13
- package/dist/cjs/client.d.ts +13 -1
- package/dist/cjs/client.js +5 -0
- package/dist/cjs/core.d.ts +16 -3
- package/dist/cjs/core.js +25 -6
- package/dist/cjs/errors.d.ts +1 -1
- package/dist/cjs/errors.js +11 -0
- package/dist/cjs/generated/openapi.d.ts +19867 -5738
- package/dist/cjs/generated/operations.d.ts +26 -0
- package/dist/cjs/generated/operations.js +176 -0
- package/dist/cjs/generated/resources.d.ts +1050 -0
- package/dist/cjs/generated/resources.js +816 -0
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/pagination.d.ts +3 -0
- package/dist/cjs/pagination.js +26 -5
- package/dist/cjs/resource.d.ts +30 -0
- package/dist/cjs/resource.js +23 -0
- package/dist/cjs/resources.d.ts +64 -57
- package/dist/cjs/resources.js +31 -36
- package/dist/cjs/types.d.ts +11 -3
- package/dist/cjs/webhooks.d.ts +11 -1
- package/dist/esm/client.d.ts +13 -1
- package/dist/esm/client.js +6 -1
- package/dist/esm/core.d.ts +16 -3
- package/dist/esm/core.js +24 -5
- package/dist/esm/errors.d.ts +1 -1
- package/dist/esm/errors.js +11 -0
- package/dist/esm/generated/openapi.d.ts +19867 -5738
- package/dist/esm/generated/operations.d.ts +26 -0
- package/dist/esm/generated/operations.js +173 -0
- package/dist/esm/generated/resources.d.ts +1050 -0
- package/dist/esm/generated/resources.js +795 -0
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/pagination.d.ts +3 -0
- package/dist/esm/pagination.js +25 -5
- package/dist/esm/resource.d.ts +30 -0
- package/dist/esm/resource.js +19 -0
- package/dist/esm/resources.d.ts +64 -57
- package/dist/esm/resources.js +24 -34
- package/dist/esm/types.d.ts +11 -3
- package/dist/esm/webhooks.d.ts +11 -1
- package/package.json +2 -1
package/dist/cjs/resources.js
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
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 = 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.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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
pathParams: params.path,
|
|
15
|
-
query: params.query,
|
|
16
|
-
body: params.body,
|
|
17
|
-
}, options);
|
|
18
|
-
return res.data;
|
|
19
|
-
}
|
|
20
|
-
pager(path, strategy, query, pathParams, options) {
|
|
21
|
-
return new pagination_js_1.Paginator(async (q) => (await this.core.rawRequest({ method: 'get', path, pathParams, query: q }, options)).data, strategy, (query ?? {}));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
6
|
+
const resource_js_1 = require("./resource.js");
|
|
7
|
+
const resources_js_1 = require("./generated/resources.js");
|
|
8
|
+
var resources_js_2 = require("./generated/resources.js");
|
|
9
|
+
Object.defineProperty(exports, "Crm", { enumerable: true, get: function () { return resources_js_2.Crm; } });
|
|
10
|
+
Object.defineProperty(exports, "Dialer", { enumerable: true, get: function () { return resources_js_2.Dialer; } });
|
|
11
|
+
Object.defineProperty(exports, "Organization", { enumerable: true, get: function () { return resources_js_2.Organization; } });
|
|
12
|
+
Object.defineProperty(exports, "Sales", { enumerable: true, get: function () { return resources_js_2.Sales; } });
|
|
13
|
+
Object.defineProperty(exports, "Webhooks", { enumerable: true, get: function () { return resources_js_2.Webhooks; } });
|
|
24
14
|
// ---------------------------------------------------------------- Voice
|
|
25
|
-
class Calls extends
|
|
15
|
+
class Calls extends resources_js_1.CallsGenerated {
|
|
26
16
|
/** Place an outbound call. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
|
|
27
17
|
create(body, options) {
|
|
28
18
|
return this.do('post', '/calls', { body }, options);
|
|
@@ -39,7 +29,7 @@ class Calls extends Resource {
|
|
|
39
29
|
}
|
|
40
30
|
}
|
|
41
31
|
exports.Calls = Calls;
|
|
42
|
-
class Finns extends
|
|
32
|
+
class Finns extends resources_js_1.FinnsGenerated {
|
|
43
33
|
list(query, options) {
|
|
44
34
|
return this.do('get', '/finns', { query }, options);
|
|
45
35
|
}
|
|
@@ -70,7 +60,7 @@ class Finns extends Resource {
|
|
|
70
60
|
}
|
|
71
61
|
}
|
|
72
62
|
exports.Finns = Finns;
|
|
73
|
-
class Voices extends
|
|
63
|
+
class Voices extends resources_js_1.VoicesGenerated {
|
|
74
64
|
list(query, options) {
|
|
75
65
|
return this.do('get', '/voices', { query }, options);
|
|
76
66
|
}
|
|
@@ -82,7 +72,7 @@ class Voices extends Resource {
|
|
|
82
72
|
}
|
|
83
73
|
}
|
|
84
74
|
exports.Voices = Voices;
|
|
85
|
-
class PhoneNumbers extends
|
|
75
|
+
class PhoneNumbers extends resources_js_1.PhoneNumbersGenerated {
|
|
86
76
|
list(query, options) {
|
|
87
77
|
return this.do('get', '/phone_numbers', { query }, options);
|
|
88
78
|
}
|
|
@@ -104,7 +94,7 @@ class PhoneNumbers extends Resource {
|
|
|
104
94
|
}
|
|
105
95
|
}
|
|
106
96
|
exports.PhoneNumbers = PhoneNumbers;
|
|
107
|
-
class Audiences extends
|
|
97
|
+
class Audiences extends resources_js_1.AudiencesGenerated {
|
|
108
98
|
list(query, options) {
|
|
109
99
|
return this.do('get', '/audiences', { query }, options);
|
|
110
100
|
}
|
|
@@ -134,7 +124,7 @@ class Audiences extends Resource {
|
|
|
134
124
|
}
|
|
135
125
|
}
|
|
136
126
|
exports.Audiences = Audiences;
|
|
137
|
-
class Deployments extends
|
|
127
|
+
class Deployments extends resources_js_1.DeploymentsGenerated {
|
|
138
128
|
list(query, options) {
|
|
139
129
|
return this.do('get', '/deployments', { query }, options);
|
|
140
130
|
}
|
|
@@ -163,7 +153,7 @@ class Deployments extends Resource {
|
|
|
163
153
|
}
|
|
164
154
|
}
|
|
165
155
|
exports.Deployments = Deployments;
|
|
166
|
-
class Wallet extends
|
|
156
|
+
class Wallet extends resources_js_1.WalletGenerated {
|
|
167
157
|
retrieve(options) {
|
|
168
158
|
return this.do('get', '/wallet', {}, options);
|
|
169
159
|
}
|
|
@@ -175,7 +165,7 @@ class Wallet extends Resource {
|
|
|
175
165
|
}
|
|
176
166
|
}
|
|
177
167
|
exports.Wallet = Wallet;
|
|
178
|
-
class DoNotCall extends
|
|
168
|
+
class DoNotCall extends resources_js_1.DoNotCallGenerated {
|
|
179
169
|
list(query, options) {
|
|
180
170
|
return this.do('get', '/do_not_call', { query }, options);
|
|
181
171
|
}
|
|
@@ -192,7 +182,7 @@ class DoNotCall extends Resource {
|
|
|
192
182
|
}
|
|
193
183
|
exports.DoNotCall = DoNotCall;
|
|
194
184
|
// ---------------------------------------------------------------- CRM
|
|
195
|
-
class Contacts extends
|
|
185
|
+
class Contacts extends resources_js_1.ContactsGenerated {
|
|
196
186
|
list(query, options) {
|
|
197
187
|
return this.do('get', '/contacts', { query }, options);
|
|
198
188
|
}
|
|
@@ -227,7 +217,7 @@ class Contacts extends Resource {
|
|
|
227
217
|
}
|
|
228
218
|
exports.Contacts = Contacts;
|
|
229
219
|
// ---------------------------------------------------------------- Operator
|
|
230
|
-
class Cases extends
|
|
220
|
+
class Cases extends resources_js_1.CasesGenerated {
|
|
231
221
|
list(query, options) {
|
|
232
222
|
return this.do('get', '/cases', { query }, options);
|
|
233
223
|
}
|
|
@@ -237,8 +227,13 @@ class Cases extends Resource {
|
|
|
237
227
|
retrieve(id, options) {
|
|
238
228
|
return this.do('get', '/cases/{id}', { path: { id } }, options);
|
|
239
229
|
}
|
|
240
|
-
|
|
241
|
-
|
|
230
|
+
/** One page of a case's events: pass the previous page's `next_after` as `after` for the next one. */
|
|
231
|
+
listEvents(id, query, options) {
|
|
232
|
+
return this.do('get', '/cases/{id}/events', { path: { id }, query }, options);
|
|
233
|
+
}
|
|
234
|
+
/** Every event of a case, oldest first, page by page (follows `next_after`). */
|
|
235
|
+
listAllEvents(id, query, options) {
|
|
236
|
+
return this.pager('/cases/{id}/events', (0, pagination_js_1.afterStrategy)('events', 'next_after'), query, { id }, options);
|
|
242
237
|
}
|
|
243
238
|
/** Start a case on an agent. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
|
|
244
239
|
start(agentId, body, options) {
|
|
@@ -248,7 +243,7 @@ class Cases extends Resource {
|
|
|
248
243
|
exports.Cases = Cases;
|
|
249
244
|
/** Statuses that are still waiting: holds (`pending`, `running`) and Operator approvals (`open`). */
|
|
250
245
|
const WAITING_STATUSES = new Set(['pending', 'running', 'open', 'pending_approval']);
|
|
251
|
-
class Approvals extends
|
|
246
|
+
class Approvals extends resources_js_1.ApprovalsGenerated {
|
|
252
247
|
list(query, options) {
|
|
253
248
|
return this.do('get', '/approvals', { query }, options);
|
|
254
249
|
}
|
|
@@ -305,7 +300,7 @@ function defaultPollSleep(ms, signal) {
|
|
|
305
300
|
signal?.addEventListener('abort', () => (clearTimeout(t), reject(signal.reason)), { once: true });
|
|
306
301
|
});
|
|
307
302
|
}
|
|
308
|
-
class Agents extends
|
|
303
|
+
class Agents extends resources_js_1.AgentsGenerated {
|
|
309
304
|
list(query, options) {
|
|
310
305
|
return this.do('get', '/agents', { query }, options);
|
|
311
306
|
}
|
|
@@ -341,7 +336,7 @@ class Agents extends Resource {
|
|
|
341
336
|
}
|
|
342
337
|
}
|
|
343
338
|
exports.Agents = Agents;
|
|
344
|
-
class ChatConversations extends Resource {
|
|
339
|
+
class ChatConversations extends resource_js_1.Resource {
|
|
345
340
|
list(query, options) {
|
|
346
341
|
return this.do('get', '/chat/conversations', { query }, options);
|
|
347
342
|
}
|
|
@@ -367,7 +362,7 @@ class ChatConversations extends Resource {
|
|
|
367
362
|
}
|
|
368
363
|
}
|
|
369
364
|
exports.ChatConversations = ChatConversations;
|
|
370
|
-
class ChatContacts extends Resource {
|
|
365
|
+
class ChatContacts extends resource_js_1.Resource {
|
|
371
366
|
list(query, options) {
|
|
372
367
|
return this.do('get', '/chat/contacts', { query }, options);
|
|
373
368
|
}
|
|
@@ -382,7 +377,7 @@ class ChatContacts extends Resource {
|
|
|
382
377
|
}
|
|
383
378
|
}
|
|
384
379
|
exports.ChatContacts = ChatContacts;
|
|
385
|
-
class Chat extends
|
|
380
|
+
class Chat extends resources_js_1.ChatGenerated {
|
|
386
381
|
constructor(core) {
|
|
387
382
|
super(core);
|
|
388
383
|
this.conversations = new ChatConversations(core);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* body and success response, so `finn.request('get', '/calls/{call_uuid}', ...)` is checked end to end.
|
|
4
4
|
*/
|
|
5
5
|
import type { components, operations, paths } from './generated/openapi.js';
|
|
6
|
+
import type { SpecHoldableRoute } from './generated/operations.js';
|
|
6
7
|
export type { components, operations, paths };
|
|
7
8
|
/** Every schema in the spec, e.g. `Schemas['Call']`. */
|
|
8
9
|
export type Schemas = components['schemas'];
|
|
@@ -142,7 +143,14 @@ export interface FinnResponse<T> {
|
|
|
142
143
|
/** True when the API replayed a saved answer for the same Idempotency-Key. */
|
|
143
144
|
idempotentReplayed: boolean;
|
|
144
145
|
}
|
|
145
|
-
/**
|
|
146
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Routes whose writes the API may hold for approval (HTTP 202 `pending_approval`): the ones listed here plus the
|
|
148
|
+
* ones the spec marks (`x-finn-hold`, or a 202 answer that says `pending_approval`).
|
|
149
|
+
*/
|
|
150
|
+
export type HoldableRoute = 'post /calls' | 'post /deployments' | 'post /phone_numbers' | 'post /agents/{id}/cases' | 'post /chat/conversations' | 'post /chat/conversations/{id}/messages' | SpecHoldableRoute;
|
|
151
|
+
/** The spec's own PendingApproval schema, replaced by the SDK's `PendingApproval` in results. */
|
|
152
|
+
type SpecPendingApproval = components['schemas'] extends {
|
|
153
|
+
PendingApproval: infer X;
|
|
154
|
+
} ? X : never;
|
|
147
155
|
/** What `request()` resolves to: the spec's success body, or PendingApproval on holdable routes. */
|
|
148
|
-
export type ResultOf<P extends string, M extends HttpMethod, O> = `${M} ${P}` extends HoldableRoute ? ResponseOf<O> | PendingApproval : ResponseOf<O>;
|
|
156
|
+
export type ResultOf<P extends string, M extends HttpMethod, O> = `${M} ${P}` extends HoldableRoute ? Exclude<ResponseOf<O>, SpecPendingApproval> | PendingApproval : ResponseOf<O>;
|
package/dist/cjs/webhooks.d.ts
CHANGED
|
@@ -12,11 +12,21 @@ export declare const WEBHOOK_SIGNATURE_HEADER = "X-Finn-Signature";
|
|
|
12
12
|
export declare const WEBHOOK_EVENT_HEADER = "X-Finn-Event";
|
|
13
13
|
/** Default largest gap, in seconds, between the signed timestamp and now. */
|
|
14
14
|
export declare const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The body of a webhook delivery (the Finn envelope). Endpoints imported from Finn Chat with the `chat` envelope get
|
|
17
|
+
* Finn Chat's own body instead: `{ id, event, createdAt, orgId, data }`.
|
|
18
|
+
*/
|
|
16
19
|
export interface WebhookEvent<T = Record<string, unknown>> {
|
|
17
20
|
/** e.g. `call.completed`, `contact.created`, `case.completed`. */
|
|
18
21
|
event: string;
|
|
22
|
+
/** Unique per event, and the same on every retry or redelivery of it: dedupe on it. */
|
|
23
|
+
event_id?: string;
|
|
24
|
+
/** When this delivery was sent. */
|
|
19
25
|
created_at: string;
|
|
26
|
+
/** When the event happened. */
|
|
27
|
+
occurred_at?: string;
|
|
28
|
+
/** The organization the event belongs to. */
|
|
29
|
+
org_id?: string;
|
|
20
30
|
data: T;
|
|
21
31
|
}
|
|
22
32
|
/** The delivery's signature is missing, malformed, wrong or too old. Answer the request with a 400. */
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FinnCore, type FinnOptions } from './core.js';
|
|
2
|
-
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Deployments, DoNotCall, Finns, PhoneNumbers, Voices, Wallet, type WaitForApprovalOptions } from './resources.js';
|
|
2
|
+
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall, Finns, Organization, PhoneNumbers, Sales, Voices, Wallet, Webhooks, type WaitForApprovalOptions } from './resources.js';
|
|
3
3
|
import type { ApprovalHold, Schemas } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* The Finn API client.
|
|
@@ -24,6 +24,18 @@ export declare class Finn extends FinnCore {
|
|
|
24
24
|
readonly approvals: Approvals;
|
|
25
25
|
readonly agents: Agents;
|
|
26
26
|
readonly chat: Chat;
|
|
27
|
+
/** CRM: records, stages, forms, documents, follow-ups, views and imports (`/crm`). */
|
|
28
|
+
readonly crm: Crm;
|
|
29
|
+
readonly dialer: Dialer;
|
|
30
|
+
/** Webhook endpoints, deliveries and event types. */
|
|
31
|
+
readonly webhooks: Webhooks;
|
|
32
|
+
/** The organization, its members, integrations and API keys. */
|
|
33
|
+
readonly organization: Organization;
|
|
34
|
+
/**
|
|
35
|
+
* Sales plays, prospects, drafts and threads.
|
|
36
|
+
* @experimental The Sales API is switched off for every organization; calls answer an error until it is on for yours.
|
|
37
|
+
*/
|
|
38
|
+
readonly sales: Sales;
|
|
27
39
|
constructor(options?: FinnOptions);
|
|
28
40
|
/** Polls an approval until it is decided (see approvals.wait). */
|
|
29
41
|
waitForApproval(id: string, options?: WaitForApprovalOptions): Promise<ApprovalHold | Schemas['Approval']>;
|
package/dist/esm/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FinnCore } from './core.js';
|
|
2
|
-
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Deployments, DoNotCall, Finns, PhoneNumbers, Voices, Wallet, } from './resources.js';
|
|
2
|
+
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall, Finns, Organization, PhoneNumbers, Sales, Voices, Wallet, Webhooks, } from './resources.js';
|
|
3
3
|
/**
|
|
4
4
|
* The Finn API client.
|
|
5
5
|
*
|
|
@@ -23,6 +23,11 @@ export class Finn extends FinnCore {
|
|
|
23
23
|
this.approvals = new Approvals(this);
|
|
24
24
|
this.agents = new Agents(this);
|
|
25
25
|
this.chat = new Chat(this);
|
|
26
|
+
this.crm = new Crm(this);
|
|
27
|
+
this.dialer = new Dialer(this);
|
|
28
|
+
this.webhooks = new Webhooks(this);
|
|
29
|
+
this.organization = new Organization(this);
|
|
30
|
+
this.sales = new Sales(this);
|
|
26
31
|
}
|
|
27
32
|
/** Polls an approval until it is decided (see approvals.wait). */
|
|
28
33
|
waitForApproval(id, options) {
|
package/dist/esm/core.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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.
|
|
3
|
+
export declare const SDK_VERSION = "0.4.0";
|
|
4
|
+
/** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
|
|
5
|
+
export declare const DEFAULT_FINN_VERSION = "2026-11-01";
|
|
4
6
|
export interface FinnOptions {
|
|
5
7
|
/** `finn_live_...` org key, `finn_test_...` test key, or an OAuth `finn_oat_...` token. Defaults to env FINN_API_KEY. */
|
|
6
8
|
apiKey?: string;
|
|
@@ -8,8 +10,11 @@ export interface FinnOptions {
|
|
|
8
10
|
baseUrl?: string;
|
|
9
11
|
/** Org to act in (Finn-Org header). Needed only for tokens that can use more than one org. */
|
|
10
12
|
org?: string;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Pins the API version (Finn-Version header), a date such as `2026-11-01`. Defaults to DEFAULT_FINN_VERSION, the
|
|
15
|
+
* version this SDK was built against; `null` sends no header (the key's pinned version, else the current one).
|
|
16
|
+
*/
|
|
17
|
+
version?: string | null;
|
|
13
18
|
/**
|
|
14
19
|
* Retries after the first attempt, on network errors, 408, 429, 502, 503 and 504. Only GET/HEAD/OPTIONS/PUT/DELETE
|
|
15
20
|
* are retried freely; a POST or PATCH is retried only when it carries an Idempotency-Key and its route dedupes by
|
|
@@ -28,6 +33,11 @@ export interface FinnOptions {
|
|
|
28
33
|
autoIdempotency?: boolean;
|
|
29
34
|
/** Longest Retry-After the SDK will wait out; a longer one throws instead. Default 60000 ms. */
|
|
30
35
|
maxRetryAfterMs?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Most time one request spends waiting between its retries, `Retry-After` waits included. A retry whose wait would
|
|
38
|
+
* go past it is not made: the last error is thrown instead. Default 20000 ms.
|
|
39
|
+
*/
|
|
40
|
+
maxRetryWaitMs?: number;
|
|
31
41
|
/** Headers sent on every request. */
|
|
32
42
|
defaultHeaders?: Record<string, string>;
|
|
33
43
|
/** Replaces the wait between retries (for tests). */
|
|
@@ -43,6 +53,8 @@ export declare const AUTO_IDEMPOTENCY_ROUTES: ReadonlySet<string>;
|
|
|
43
53
|
export declare const IDEMPOTENT_WRITE_ROUTES: readonly string[];
|
|
44
54
|
/** True when the API dedupes this write by Idempotency-Key. `path` may be a template or a filled-in path. */
|
|
45
55
|
export declare function honoursIdempotencyKey(method: string, path: string): boolean;
|
|
56
|
+
/** Default cap on the total wait between retries of one request (`maxRetryWaitMs`). */
|
|
57
|
+
export declare const DEFAULT_MAX_RETRY_WAIT_MS = 20000;
|
|
46
58
|
/** A new random Idempotency-Key (a UUID v4). */
|
|
47
59
|
export declare function idempotencyKey(): string;
|
|
48
60
|
/** Untyped request input, for paths the spec does not have yet. */
|
|
@@ -64,6 +76,7 @@ export declare class FinnCore {
|
|
|
64
76
|
readonly timeoutMs: number;
|
|
65
77
|
readonly autoIdempotency: boolean;
|
|
66
78
|
readonly maxRetryAfterMs: number;
|
|
79
|
+
readonly maxRetryWaitMs: number;
|
|
67
80
|
constructor(options?: FinnOptions);
|
|
68
81
|
/**
|
|
69
82
|
* Calls any operation in the spec, fully typed.
|
package/dist/esm/core.js
CHANGED
|
@@ -12,7 +12,11 @@ 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.
|
|
15
|
+
export const SDK_VERSION = '0.4.0';
|
|
16
|
+
/** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
|
|
17
|
+
export const DEFAULT_FINN_VERSION = '2026-11-01';
|
|
18
|
+
// Browsers own the User-Agent header, so it is only set on server runtimes.
|
|
19
|
+
const IS_NODE = typeof globalThis.process?.versions?.node === 'string';
|
|
16
20
|
/** Writes that get an automatic Idempotency-Key (when autoIdempotency is on). */
|
|
17
21
|
export const AUTO_IDEMPOTENCY_ROUTES = new Set([
|
|
18
22
|
'post /calls',
|
|
@@ -23,6 +27,7 @@ export const AUTO_IDEMPOTENCY_ROUTES = new Set([
|
|
|
23
27
|
'post /chat/conversations/{id}/messages',
|
|
24
28
|
'post /agents',
|
|
25
29
|
'post /agents/{id}/cases',
|
|
30
|
+
'post /webhook_endpoints',
|
|
26
31
|
]);
|
|
27
32
|
/**
|
|
28
33
|
* POST/PATCH routes where the API dedupes by Idempotency-Key (a retry with the same key and body replays the first
|
|
@@ -42,6 +47,11 @@ export const IDEMPOTENT_WRITE_ROUTES = [
|
|
|
42
47
|
'patch /crm/*',
|
|
43
48
|
'post /sales/plays/{slug}/run',
|
|
44
49
|
'post /sales/drafts/{id}/skip',
|
|
50
|
+
'post /webhook_endpoints',
|
|
51
|
+
'post /dialer/follow-ups/{call_id}/done',
|
|
52
|
+
'post /dialer/calls/{call_id}/notes',
|
|
53
|
+
'patch /chat/agents/{agent_id}',
|
|
54
|
+
'post /chat/agents/{agent_id}/test_turn',
|
|
45
55
|
];
|
|
46
56
|
const IDEMPOTENT_WRITE_MATCHERS = IDEMPOTENT_WRITE_ROUTES.map((route) => {
|
|
47
57
|
const [method, path] = route.split(' ');
|
|
@@ -60,6 +70,8 @@ export function honoursIdempotencyKey(method, path) {
|
|
|
60
70
|
const SAFE_TO_RETRY_METHODS = new Set(['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE']);
|
|
61
71
|
const RETRY_BASE_DELAY_MS = 500;
|
|
62
72
|
const RETRY_MAX_DELAY_MS = 8000;
|
|
73
|
+
/** Default cap on the total wait between retries of one request (`maxRetryWaitMs`). */
|
|
74
|
+
export const DEFAULT_MAX_RETRY_WAIT_MS = 20000;
|
|
63
75
|
/** A new random Idempotency-Key (a UUID v4). */
|
|
64
76
|
export function idempotencyKey() {
|
|
65
77
|
const c = globalThis.crypto;
|
|
@@ -113,11 +125,12 @@ export class FinnCore {
|
|
|
113
125
|
__classPrivateFieldSet(this, _FinnCore_fetch, f, "f");
|
|
114
126
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
115
127
|
this.org = options.org;
|
|
116
|
-
this.version = options.version;
|
|
128
|
+
this.version = options.version === undefined ? DEFAULT_FINN_VERSION : options.version ?? undefined;
|
|
117
129
|
this.maxRetries = options.maxRetries ?? 2;
|
|
118
130
|
this.timeoutMs = options.timeoutMs ?? 60000;
|
|
119
131
|
this.autoIdempotency = options.autoIdempotency ?? true;
|
|
120
132
|
this.maxRetryAfterMs = options.maxRetryAfterMs ?? 60000;
|
|
133
|
+
this.maxRetryWaitMs = options.maxRetryWaitMs ?? DEFAULT_MAX_RETRY_WAIT_MS;
|
|
121
134
|
__classPrivateFieldSet(this, _FinnCore_defaultHeaders, { ...(options.defaultHeaders ?? {}) }, "f");
|
|
122
135
|
__classPrivateFieldSet(this, _FinnCore_sleep, options.sleep ?? defaultSleep, "f");
|
|
123
136
|
}
|
|
@@ -148,6 +161,8 @@ export class FinnCore {
|
|
|
148
161
|
}
|
|
149
162
|
const headers = new Headers();
|
|
150
163
|
headers.set('Accept', 'application/json');
|
|
164
|
+
if (IS_NODE)
|
|
165
|
+
headers.set('User-Agent', `finn-node/${SDK_VERSION}`);
|
|
151
166
|
for (const [k, v] of Object.entries(__classPrivateFieldGet(this, _FinnCore_defaultHeaders, "f")))
|
|
152
167
|
headers.set(k, v);
|
|
153
168
|
const org = options.org ?? this.org;
|
|
@@ -174,6 +189,7 @@ export class FinnCore {
|
|
|
174
189
|
const canRetry = SAFE_TO_RETRY_METHODS.has(method) || (headers.has('Idempotency-Key') && honoursIdempotencyKey(method, req.path));
|
|
175
190
|
const maxRetries = canRetry ? Math.max(0, options.maxRetries ?? this.maxRetries) : 0;
|
|
176
191
|
const timeoutMs = options.timeoutMs ?? this.timeoutMs;
|
|
192
|
+
let waitedMs = 0;
|
|
177
193
|
for (let attempt = 0;; attempt += 1) {
|
|
178
194
|
let response;
|
|
179
195
|
try {
|
|
@@ -185,8 +201,10 @@ export class FinnCore {
|
|
|
185
201
|
const wrapped = err instanceof FinnTimeoutError
|
|
186
202
|
? err
|
|
187
203
|
: new FinnConnectionError(`Could not reach the Finn API: ${err?.message ?? err}`, { cause: err });
|
|
188
|
-
|
|
189
|
-
|
|
204
|
+
const wait = backoffMs(attempt);
|
|
205
|
+
if (attempt < maxRetries && waitedMs + wait <= this.maxRetryWaitMs) {
|
|
206
|
+
waitedMs += wait;
|
|
207
|
+
await __classPrivateFieldGet(this, _FinnCore_sleep, "f").call(this, wait, options.signal);
|
|
190
208
|
continue;
|
|
191
209
|
}
|
|
192
210
|
throw wrapped;
|
|
@@ -204,8 +222,9 @@ export class FinnCore {
|
|
|
204
222
|
const error = FinnError.fromResponse(response.status, response.headers, parsed, response.statusText);
|
|
205
223
|
if (attempt < maxRetries && isRetryable(error)) {
|
|
206
224
|
const wait = error.retryAfter != null ? error.retryAfter * 1000 : backoffMs(attempt);
|
|
207
|
-
if (wait > this.maxRetryAfterMs)
|
|
225
|
+
if (wait > this.maxRetryAfterMs || waitedMs + wait > this.maxRetryWaitMs)
|
|
208
226
|
throw error;
|
|
227
|
+
waitedMs += wait;
|
|
209
228
|
await __classPrivateFieldGet(this, _FinnCore_sleep, "f").call(this, wait, options.signal);
|
|
210
229
|
continue;
|
|
211
230
|
}
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class FinnError extends FinnSdkError {
|
|
|
34
34
|
readonly code: FinnErrorCode;
|
|
35
35
|
/** Matches the `X-Request-Id` response header; quote it to support. */
|
|
36
36
|
readonly requestId: string | null;
|
|
37
|
-
/** Per-field problems (unified shape
|
|
37
|
+
/** Per-field problems (unified shape, and legacy bodies that name fields as a string list; `[]` otherwise). */
|
|
38
38
|
readonly fields: FinnFieldError[];
|
|
39
39
|
/** Link to the error's documentation, when the API sent one. */
|
|
40
40
|
readonly docUrl: string | null;
|
package/dist/esm/errors.js
CHANGED
|
@@ -84,6 +84,7 @@ export class FinnError extends FinnSdkError {
|
|
|
84
84
|
requestId: str(request_id) ?? headerRequestId,
|
|
85
85
|
actionUrl: str(action_url),
|
|
86
86
|
requiredScope: str(required_scope),
|
|
87
|
+
fields: legacyFields(rest.fields, error, str(message)),
|
|
87
88
|
details: rest,
|
|
88
89
|
});
|
|
89
90
|
}
|
|
@@ -150,6 +151,16 @@ function isRecord(v) {
|
|
|
150
151
|
function str(v) {
|
|
151
152
|
return typeof v === 'string' && v !== '' ? v : null;
|
|
152
153
|
}
|
|
154
|
+
// Legacy bodies list the offending fields by name (`fields: ['dob']`) or as field errors; both become FinnFieldError.
|
|
155
|
+
function legacyFields(v, code, message) {
|
|
156
|
+
if (!Array.isArray(v))
|
|
157
|
+
return [];
|
|
158
|
+
return v.flatMap((f) => {
|
|
159
|
+
if (typeof f === 'string')
|
|
160
|
+
return [{ field: f, code, message: message ?? code }];
|
|
161
|
+
return isFieldError(f) ? [f] : [];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
153
164
|
function isFieldError(v) {
|
|
154
165
|
return isRecord(v) && typeof v.field === 'string';
|
|
155
166
|
}
|