@hirefinn/sdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +217 -2
- package/dist/cjs/approval.d.ts +12 -0
- package/dist/cjs/approval.js +19 -0
- package/dist/cjs/client.d.ts +30 -0
- package/dist/cjs/client.js +35 -0
- package/dist/cjs/core.d.ts +81 -0
- package/dist/cjs/core.js +300 -0
- package/dist/cjs/errors.d.ts +90 -0
- package/dist/cjs/errors.js +165 -0
- package/dist/cjs/generated/openapi.d.ts +10729 -0
- package/dist/cjs/generated/openapi.js +2 -0
- package/dist/cjs/index.d.ts +13 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pagination.d.ts +36 -0
- package/dist/cjs/pagination.js +124 -0
- package/dist/cjs/resources.d.ts +845 -0
- package/dist/cjs/resources.js +395 -0
- package/dist/cjs/types.d.ts +148 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/webhooks.d.ts +57 -0
- package/dist/cjs/webhooks.js +181 -0
- package/dist/esm/approval.d.ts +12 -0
- package/dist/esm/approval.js +16 -0
- package/dist/esm/client.d.ts +30 -0
- package/dist/esm/client.js +31 -0
- package/dist/esm/core.d.ts +81 -0
- package/dist/esm/core.js +294 -0
- package/dist/esm/errors.d.ts +90 -0
- package/dist/esm/errors.js +155 -0
- package/dist/esm/generated/openapi.d.ts +10729 -0
- package/dist/esm/generated/openapi.js +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/pagination.d.ts +36 -0
- package/dist/esm/pagination.js +116 -0
- package/dist/esm/resources.d.ts +845 -0
- package/dist/esm/resources.js +377 -0
- package/dist/esm/types.d.ts +148 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/webhooks.d.ts +57 -0
- package/dist/esm/webhooks.js +140 -0
- package/package.json +53 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Finn (hirefinn.ai)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,218 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Finn TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed client for the [Finn](https://hirefinn.ai) public API (`https://api.hirefinn.ai/v1`).
|
|
4
|
+
Types are generated from the API's OpenAPI spec; the client is a thin hand-written layer over `fetch` with
|
|
5
|
+
retries, idempotency keys, typed errors, pagination and approval helpers. No runtime dependencies.
|
|
6
|
+
|
|
7
|
+
- Node 18+ and modern browsers (anything with `fetch`)
|
|
8
|
+
- ESM and CommonJS, with `.d.ts` types
|
|
9
|
+
|
|
10
|
+
> Status: pre-release (0.2.0). MIT licensed (see `LICENSE`).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @hirefinn/sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quickstart
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { Finn, isPendingApproval, FinnError } from '@hirefinn/sdk';
|
|
22
|
+
|
|
23
|
+
const finn = new Finn({ apiKey: process.env.FINN_API_KEY }); // finn_live_..., finn_test_... or an OAuth finn_oat_... token
|
|
24
|
+
|
|
25
|
+
// List, retrieve
|
|
26
|
+
const { data: finns } = await finn.finns.list({ limit: 20 });
|
|
27
|
+
const call = await finn.calls.retrieve('b7e3c9a2-4d1f-4e8b-9a6c-2f5d8e1b3c70');
|
|
28
|
+
|
|
29
|
+
// Place a call (gets an automatic Idempotency-Key, so it is safe to retry)
|
|
30
|
+
const res = await finn.calls.create({ finn_id: finns[0]!.id, to_number: '4155550142', country_code: '1' });
|
|
31
|
+
if (isPendingApproval(res)) {
|
|
32
|
+
// OAuth / MCP callers: outward and spending actions may wait for a person to approve them (HTTP 202)
|
|
33
|
+
console.log('Approve it here:', res.approve_url);
|
|
34
|
+
const outcome = await finn.waitForApproval(res.approval_id); // polls GET /approvals/{id}
|
|
35
|
+
console.log(outcome.status); // succeeded | failed | declined | expired
|
|
36
|
+
} else {
|
|
37
|
+
console.log('Dialing', res.data.call_uuid);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Every page, lazily
|
|
41
|
+
for await (const c of finn.calls.listAll({ status: 'completed' })) {
|
|
42
|
+
console.log(c.call_uuid);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Client options
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
new Finn({
|
|
50
|
+
apiKey, // default: process.env.FINN_API_KEY
|
|
51
|
+
baseUrl, // default: https://api.hirefinn.ai/v1
|
|
52
|
+
org, // Finn-Org header: which org a multi-org token acts in
|
|
53
|
+
version, // Finn-Version header: pins the API version, e.g. '2026-11-01'
|
|
54
|
+
maxRetries: 2, // retries after the first attempt
|
|
55
|
+
timeoutMs: 60_000, // per attempt
|
|
56
|
+
fetch, // custom fetch (tests, proxies, older runtimes)
|
|
57
|
+
autoIdempotency: true,
|
|
58
|
+
maxRetryAfterMs: 60_000,
|
|
59
|
+
defaultHeaders: {},
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Every method also takes a last `options` argument that overrides these per call:
|
|
64
|
+
`{ idempotencyKey, org, version, maxRetries, timeoutMs, signal, headers }`.
|
|
65
|
+
|
|
66
|
+
## Resources
|
|
67
|
+
|
|
68
|
+
| Property | Endpoints |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `finn.calls` | `create`, `list`, `listAll`, `retrieve` |
|
|
71
|
+
| `finn.finns` | `list`, `listAll`, `create`, `retrieve`, `update`, `delete`, `listKnowledgeBase`, `addKnowledgeBaseDocument`, `postCallAnalysis` |
|
|
72
|
+
| `finn.voices` | `list`, `listAll`, `retrieve` |
|
|
73
|
+
| `finn.phoneNumbers` | `list`, `listAll`, `searchAvailable`, `rent`, `retrieve`, `release` |
|
|
74
|
+
| `finn.audiences` | `list`, `listAll`, `create`, `retrieve`, `archive`, `listContacts`, `listAllContacts`, `addContacts`, `removeContact` |
|
|
75
|
+
| `finn.deployments` (campaigns) | `list`, `listAll`, `createOutbound`, `createInbound`, `retrieve`, `stop`, `stopInbound`, `analytics` |
|
|
76
|
+
| `finn.wallet` | `retrieve`, `listTransactions`, `listAllTransactions` |
|
|
77
|
+
| `finn.doNotCall` | `list`, `listAll`, `add`, `remove` |
|
|
78
|
+
| `finn.contacts` (CRM records) | `list`, `listAll`, `create`, `retrieve`, `update`, `timeline`, `timelineAll`, `addNote`, `listKinds`, `listFields` |
|
|
79
|
+
| `finn.cases` | `list`, `listAll`, `retrieve`, `listEvents`, `start` |
|
|
80
|
+
| `finn.approvals` | `list`, `listAll`, `retrieve`, `decide`, `approve`, `reject`, `wait` |
|
|
81
|
+
| `finn.agents` | `list`, `listAll`, `create`, `draft`, `retrieve`, `saveDraft`, `validate`, `test`, `publish`, `driveTest` |
|
|
82
|
+
| `finn.chat` | `listChannels`; `conversations.{list, listAll, start, retrieve, listMessages, listAllMessages, send}`; `contacts.{list, listAll, retrieve, update}` |
|
|
83
|
+
|
|
84
|
+
Methods return the response body exactly as the spec describes it (older voice endpoints wrap it in
|
|
85
|
+
`{ success, data }`). Request and response types come from `src/generated/openapi.ts`; schemas are exported as
|
|
86
|
+
`Schemas`, e.g. `Schemas['Call']`.
|
|
87
|
+
|
|
88
|
+
Anything in the spec is also reachable through the typed generic call:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const res = await finn.request('get', '/calls/{call_uuid}', { path: { call_uuid } });
|
|
92
|
+
const full = await finn.requestWithResponse('get', '/wallet'); // { data, status, headers, requestId, idempotentReplayed }
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
and endpoints newer than the SDK through `finn.rawRequest({ method, path, pathParams, query, body })`.
|
|
96
|
+
|
|
97
|
+
## Retries
|
|
98
|
+
|
|
99
|
+
Network errors, `408`, `429`, `502`, `503`, `504` and `409 idempotency_in_progress` are retried up to
|
|
100
|
+
`maxRetries` times, with exponential backoff (0.5 s, 1 s, 2 s ... up to 8 s, with jitter). A `Retry-After` header
|
|
101
|
+
is honoured; one longer than `maxRetryAfterMs` throws instead of waiting. A `500` is not retried.
|
|
102
|
+
|
|
103
|
+
`GET`, `PUT` and `DELETE` are always retried. A `POST` or `PATCH` is retried **only when it carries an
|
|
104
|
+
`Idempotency-Key` and its route dedupes by that key** (`IDEMPOTENT_WRITE_ROUTES`: calls, phone numbers,
|
|
105
|
+
deployments, chat start/send, agents, case start, `/crm/*` writes, sales play runs and draft skips). Other writes,
|
|
106
|
+
such as `finns.create` or `contacts.create`, are sent once: the API ignores the key there, so a retry after a timeout
|
|
107
|
+
could create a second record. Check with `honoursIdempotencyKey(method, path)`.
|
|
108
|
+
|
|
109
|
+
## Idempotency keys
|
|
110
|
+
|
|
111
|
+
These writes get a fresh `Idempotency-Key` automatically, reused across their retries:
|
|
112
|
+
`calls.create`, `phoneNumbers.rent`, `deployments.createOutbound`, `deployments.createInbound`,
|
|
113
|
+
`chat.conversations.start`, `chat.conversations.send`, `agents.create`, `cases.start`.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { idempotencyKey } from '@hirefinn/sdk';
|
|
117
|
+
|
|
118
|
+
const key = idempotencyKey(); // store it with your job
|
|
119
|
+
await finn.calls.create(body, { idempotencyKey: key }); // same key + same body within 24 h = same answer
|
|
120
|
+
await finn.calls.create(body, { idempotencyKey: false }); // opt out
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The API dedupes by key only on `IDEMPOTENT_WRITE_ROUTES`. Passing a key to another write (for example
|
|
124
|
+
`finns.create`) does not make it safe to retry, and the SDK does not retry it.
|
|
125
|
+
|
|
126
|
+
## Webhooks
|
|
127
|
+
|
|
128
|
+
Finn signs each delivery with `X-Finn-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`.
|
|
129
|
+
`verifyWebhook` checks it in constant time, refuses timestamps more than 300 s from now, and returns the parsed event.
|
|
130
|
+
Pass the **raw** body, not re-serialised JSON.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import express from 'express';
|
|
134
|
+
import { verifyWebhook, FinnWebhookVerificationError } from '@hirefinn/sdk';
|
|
135
|
+
|
|
136
|
+
app.post('/finn-webhook', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
137
|
+
try {
|
|
138
|
+
const event = await verifyWebhook({ payload: req.body, headers: req.headers, secret: process.env.FINN_WEBHOOK_SECRET! });
|
|
139
|
+
console.log(event.event, event.data);
|
|
140
|
+
res.sendStatus(200);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
if (err instanceof FinnWebhookVerificationError) return res.sendStatus(400);
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Options: `toleranceSeconds` (default 300), and `secret` can be an array while you rotate secrets.
|
|
149
|
+
|
|
150
|
+
## Approval holds
|
|
151
|
+
|
|
152
|
+
Outward and spending writes from OAuth and MCP callers can answer `202 { status: 'pending_approval', approval_id,
|
|
153
|
+
approve_url, expires_at, action, summary }` instead of doing the work: `calls.create`, `phoneNumbers.rent`,
|
|
154
|
+
`deployments.createOutbound`, `cases.start`, `chat.conversations.start` and `chat.conversations.send`. Their return
|
|
155
|
+
types include `PendingApproval`; narrow with `isPendingApproval(res)` and wait with `finn.waitForApproval(id)`.
|
|
156
|
+
|
|
157
|
+
## Errors
|
|
158
|
+
|
|
159
|
+
Every API error throws a `FinnError`, whichever of the API's error shapes it answered with:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
try {
|
|
163
|
+
await finn.calls.create(body);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (err instanceof FinnError) {
|
|
166
|
+
err.status; // 402
|
|
167
|
+
err.code; // 'insufficient_credits' (branch on this, not on message)
|
|
168
|
+
err.message;
|
|
169
|
+
err.requestId; // X-Request-Id, for support
|
|
170
|
+
err.fields; // [{ field, code, message }] on validation errors
|
|
171
|
+
err.actionUrl; // dashboard page that fixes it, when sent
|
|
172
|
+
err.requiredScope; // on 403 insufficient_scope
|
|
173
|
+
err.retryAfter; // seconds, on 429
|
|
174
|
+
err.details; // other fields from the body
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`FinnConnectionError` (no HTTP answer), `FinnTimeoutError` (per-attempt timeout) and `FinnApprovalTimeoutError`
|
|
180
|
+
(from `waitForApproval`) all extend `FinnSdkError`.
|
|
181
|
+
|
|
182
|
+
## Pagination
|
|
183
|
+
|
|
184
|
+
`listAll(...)` returns a `Paginator`: an async iterator over items that fetches pages as needed. It handles each
|
|
185
|
+
list style the API uses (cursor, offset, page and `before`).
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
for await (const agent of finn.agents.listAll()) { ... }
|
|
189
|
+
for await (const page of finn.calls.listAll({ limit: 200 }).pages()) { ... }
|
|
190
|
+
const first500 = await finn.contacts.listAll().toArray(500);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Regenerating from the spec
|
|
194
|
+
|
|
195
|
+
The spec is vendored at `spec/openapi.json`; the generated types at `src/generated/openapi.ts` are committed.
|
|
196
|
+
|
|
197
|
+
```sh
|
|
198
|
+
npm run generate # from spec/openapi.json
|
|
199
|
+
npm run generate -- ./path/to/openapi.json # from a file (also copied into spec/)
|
|
200
|
+
npm run generate -- https://host/openapi.json # from a URL (also copied into spec/)
|
|
201
|
+
BACKEND=../hirefinn-web-app-backend npm run spec:pull # from the backend repo's prod branch
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Then `npm run typecheck && npm test`.
|
|
205
|
+
|
|
206
|
+
`npm run spec:drift` compares the SDK with the live spec (`https://api.hirefinn.ai/v1/openapi.json`) and fails on
|
|
207
|
+
new or removed endpoints; CI runs it on every PR and daily. Endpoints the SDK knowingly leaves to `rawRequest` are
|
|
208
|
+
listed in `spec/uncovered-ops.json` (`node scripts/check-drift.mjs --write-baseline` rewrites it). New endpoints are reachable at once through `finn.request(...)`; add a
|
|
209
|
+
resource method in `src/resources.ts` for the ones worth a name.
|
|
210
|
+
|
|
211
|
+
## Development
|
|
212
|
+
|
|
213
|
+
```sh
|
|
214
|
+
npm install
|
|
215
|
+
npm run typecheck
|
|
216
|
+
npm test
|
|
217
|
+
npm run build # dist/esm + dist/cjs
|
|
218
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PendingApproval } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* True when a write was held for a person to approve (HTTP 202 `{ status: 'pending_approval', approval_id, ... }`).
|
|
4
|
+
* Outward and spending actions from OAuth and MCP callers can answer this instead of doing the work.
|
|
5
|
+
*
|
|
6
|
+
* const res = await finn.calls.create({ ... });
|
|
7
|
+
* if (isPendingApproval(res)) {
|
|
8
|
+
* console.log('Approve at', res.approve_url);
|
|
9
|
+
* const outcome = await finn.waitForApproval(res.approval_id);
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPendingApproval(value: unknown): value is PendingApproval;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPendingApproval = isPendingApproval;
|
|
4
|
+
/**
|
|
5
|
+
* True when a write was held for a person to approve (HTTP 202 `{ status: 'pending_approval', approval_id, ... }`).
|
|
6
|
+
* Outward and spending actions from OAuth and MCP callers can answer this instead of doing the work.
|
|
7
|
+
*
|
|
8
|
+
* const res = await finn.calls.create({ ... });
|
|
9
|
+
* if (isPendingApproval(res)) {
|
|
10
|
+
* console.log('Approve at', res.approve_url);
|
|
11
|
+
* const outcome = await finn.waitForApproval(res.approval_id);
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
function isPendingApproval(value) {
|
|
15
|
+
if (typeof value !== 'object' || value === null)
|
|
16
|
+
return false;
|
|
17
|
+
const v = value;
|
|
18
|
+
return v.status === 'pending_approval' && typeof v.approval_id === 'string';
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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';
|
|
3
|
+
import type { ApprovalHold, Schemas } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The Finn API client.
|
|
6
|
+
*
|
|
7
|
+
* import { Finn } from '@hirefinn/sdk';
|
|
8
|
+
* const finn = new Finn({ apiKey: process.env.FINN_API_KEY });
|
|
9
|
+
* const { data } = await finn.calls.list({ limit: 10 });
|
|
10
|
+
*/
|
|
11
|
+
export declare class Finn extends FinnCore {
|
|
12
|
+
readonly calls: Calls;
|
|
13
|
+
readonly finns: Finns;
|
|
14
|
+
readonly voices: Voices;
|
|
15
|
+
readonly phoneNumbers: PhoneNumbers;
|
|
16
|
+
readonly audiences: Audiences;
|
|
17
|
+
/** Campaigns: outbound and inbound deployments of a Finn. */
|
|
18
|
+
readonly deployments: Deployments;
|
|
19
|
+
readonly wallet: Wallet;
|
|
20
|
+
readonly doNotCall: DoNotCall;
|
|
21
|
+
/** CRM records (contacts and other record kinds). */
|
|
22
|
+
readonly contacts: Contacts;
|
|
23
|
+
readonly cases: Cases;
|
|
24
|
+
readonly approvals: Approvals;
|
|
25
|
+
readonly agents: Agents;
|
|
26
|
+
readonly chat: Chat;
|
|
27
|
+
constructor(options?: FinnOptions);
|
|
28
|
+
/** Polls an approval until it is decided (see approvals.wait). */
|
|
29
|
+
waitForApproval(id: string, options?: WaitForApprovalOptions): Promise<ApprovalHold | Schemas['Approval']>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Finn = void 0;
|
|
4
|
+
const core_js_1 = require("./core.js");
|
|
5
|
+
const resources_js_1 = require("./resources.js");
|
|
6
|
+
/**
|
|
7
|
+
* The Finn API client.
|
|
8
|
+
*
|
|
9
|
+
* import { Finn } from '@hirefinn/sdk';
|
|
10
|
+
* const finn = new Finn({ apiKey: process.env.FINN_API_KEY });
|
|
11
|
+
* const { data } = await finn.calls.list({ limit: 10 });
|
|
12
|
+
*/
|
|
13
|
+
class Finn extends core_js_1.FinnCore {
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
super(options);
|
|
16
|
+
this.calls = new resources_js_1.Calls(this);
|
|
17
|
+
this.finns = new resources_js_1.Finns(this);
|
|
18
|
+
this.voices = new resources_js_1.Voices(this);
|
|
19
|
+
this.phoneNumbers = new resources_js_1.PhoneNumbers(this);
|
|
20
|
+
this.audiences = new resources_js_1.Audiences(this);
|
|
21
|
+
this.deployments = new resources_js_1.Deployments(this);
|
|
22
|
+
this.wallet = new resources_js_1.Wallet(this);
|
|
23
|
+
this.doNotCall = new resources_js_1.DoNotCall(this);
|
|
24
|
+
this.contacts = new resources_js_1.Contacts(this);
|
|
25
|
+
this.cases = new resources_js_1.Cases(this);
|
|
26
|
+
this.approvals = new resources_js_1.Approvals(this);
|
|
27
|
+
this.agents = new resources_js_1.Agents(this);
|
|
28
|
+
this.chat = new resources_js_1.Chat(this);
|
|
29
|
+
}
|
|
30
|
+
/** Polls an approval until it is decided (see approvals.wait). */
|
|
31
|
+
waitForApproval(id, options) {
|
|
32
|
+
return this.approvals.wait(id, options);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Finn = Finn;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { FinnResponse, HttpMethod, Operation, PathsFor, RequestArgs, RequestOptions, ResultOf } from './types.js';
|
|
2
|
+
export declare const DEFAULT_BASE_URL = "https://api.hirefinn.ai/v1";
|
|
3
|
+
export declare const SDK_VERSION = "0.2.0";
|
|
4
|
+
export interface FinnOptions {
|
|
5
|
+
/** `finn_live_...` org key, `finn_test_...` test key, or an OAuth `finn_oat_...` token. Defaults to env FINN_API_KEY. */
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
/** Defaults to `https://api.hirefinn.ai/v1`. */
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
/** Org to act in (Finn-Org header). Needed only for tokens that can use more than one org. */
|
|
10
|
+
org?: string;
|
|
11
|
+
/** Pins the API version (Finn-Version header), a date such as `2026-11-01`. */
|
|
12
|
+
version?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Retries after the first attempt, on network errors, 408, 429, 502, 503 and 504. Only GET/HEAD/OPTIONS/PUT/DELETE
|
|
15
|
+
* are retried freely; a POST or PATCH is retried only when it carries an Idempotency-Key and its route dedupes by
|
|
16
|
+
* that key (IDEMPOTENT_WRITE_ROUTES). Default 2.
|
|
17
|
+
*/
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
/** Timeout per attempt in milliseconds. Default 60000. */
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
/** A fetch implementation. Defaults to the global fetch (Node 18+, browsers). */
|
|
22
|
+
fetch?: typeof fetch;
|
|
23
|
+
/**
|
|
24
|
+
* Send a generated Idempotency-Key on spending and outward writes (place a call, rent a number, deploy, start or
|
|
25
|
+
* send a chat, create an agent, start a case) when the caller did not pass one, so they can be retried safely.
|
|
26
|
+
* Default true.
|
|
27
|
+
*/
|
|
28
|
+
autoIdempotency?: boolean;
|
|
29
|
+
/** Longest Retry-After the SDK will wait out; a longer one throws instead. Default 60000 ms. */
|
|
30
|
+
maxRetryAfterMs?: number;
|
|
31
|
+
/** Headers sent on every request. */
|
|
32
|
+
defaultHeaders?: Record<string, string>;
|
|
33
|
+
/** Replaces the wait between retries (for tests). */
|
|
34
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/** Writes that get an automatic Idempotency-Key (when autoIdempotency is on). */
|
|
37
|
+
export declare const AUTO_IDEMPOTENCY_ROUTES: ReadonlySet<string>;
|
|
38
|
+
/**
|
|
39
|
+
* POST/PATCH routes where the API dedupes by Idempotency-Key (a retry with the same key and body replays the first
|
|
40
|
+
* answer). Only these writes are retried, and only when they carry a key: other routes ignore the header, so a retry
|
|
41
|
+
* after a timeout could create a second resource. `*` matches the rest of the path.
|
|
42
|
+
*/
|
|
43
|
+
export declare const IDEMPOTENT_WRITE_ROUTES: readonly string[];
|
|
44
|
+
/** True when the API dedupes this write by Idempotency-Key. `path` may be a template or a filled-in path. */
|
|
45
|
+
export declare function honoursIdempotencyKey(method: string, path: string): boolean;
|
|
46
|
+
/** A new random Idempotency-Key (a UUID v4). */
|
|
47
|
+
export declare function idempotencyKey(): string;
|
|
48
|
+
/** Untyped request input, for paths the spec does not have yet. */
|
|
49
|
+
export interface RawRequest {
|
|
50
|
+
method: HttpMethod | Uppercase<HttpMethod>;
|
|
51
|
+
/** Path below the base URL, e.g. `/calls/{call_uuid}` or `/calls/abc`. */
|
|
52
|
+
path: string;
|
|
53
|
+
/** Values for `{name}` placeholders in `path`. */
|
|
54
|
+
pathParams?: Record<string, string | number>;
|
|
55
|
+
query?: Record<string, unknown>;
|
|
56
|
+
body?: unknown;
|
|
57
|
+
}
|
|
58
|
+
export declare class FinnCore {
|
|
59
|
+
#private;
|
|
60
|
+
readonly baseUrl: string;
|
|
61
|
+
readonly org: string | undefined;
|
|
62
|
+
readonly version: string | undefined;
|
|
63
|
+
readonly maxRetries: number;
|
|
64
|
+
readonly timeoutMs: number;
|
|
65
|
+
readonly autoIdempotency: boolean;
|
|
66
|
+
readonly maxRetryAfterMs: number;
|
|
67
|
+
constructor(options?: FinnOptions);
|
|
68
|
+
/**
|
|
69
|
+
* Calls any operation in the spec, fully typed.
|
|
70
|
+
*
|
|
71
|
+
* const call = await finn.request('get', '/calls/{call_uuid}', { path: { call_uuid } });
|
|
72
|
+
*/
|
|
73
|
+
request<M extends HttpMethod, P extends PathsFor<M>>(method: M, path: P, ...args: RequestArgs<Operation<P, M>>): Promise<ResultOf<P, M, Operation<P, M>>>;
|
|
74
|
+
/** Same as request(), plus status, headers and request id. */
|
|
75
|
+
requestWithResponse<M extends HttpMethod, P extends PathsFor<M>>(method: M, path: P, ...args: RequestArgs<Operation<P, M>>): Promise<FinnResponse<ResultOf<P, M, Operation<P, M>>>>;
|
|
76
|
+
/** Untyped escape hatch for endpoints newer than this SDK's spec. */
|
|
77
|
+
rawRequest<T = unknown>(req: RawRequest, options?: RequestOptions): Promise<FinnResponse<T>>;
|
|
78
|
+
/** Builds the full URL: base + path with `{name}` filled in + query string. */
|
|
79
|
+
buildUrl(path: string, pathParams?: Record<string, string | number>, query?: Record<string, unknown>): string;
|
|
80
|
+
private fetchOnce;
|
|
81
|
+
}
|