@hirefinn/sdk 0.2.0 → 0.3.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 +39 -9
- package/dist/cjs/client.d.ts +13 -1
- package/dist/cjs/client.js +5 -0
- package/dist/cjs/core.d.ts +1 -1
- package/dist/cjs/core.js +3 -1
- package/dist/cjs/generated/openapi.d.ts +17426 -5875
- package/dist/cjs/generated/operations.d.ts +26 -0
- package/dist/cjs/generated/operations.js +165 -0
- package/dist/cjs/generated/resources.d.ts +887 -0
- package/dist/cjs/generated/resources.js +737 -0
- package/dist/cjs/resource.d.ts +30 -0
- package/dist/cjs/resource.js +23 -0
- package/dist/cjs/resources.d.ts +47 -54
- package/dist/cjs/resources.js +24 -34
- package/dist/cjs/types.d.ts +11 -3
- package/dist/esm/client.d.ts +13 -1
- package/dist/esm/client.js +6 -1
- package/dist/esm/core.d.ts +1 -1
- package/dist/esm/core.js +3 -1
- package/dist/esm/generated/openapi.d.ts +17426 -5875
- package/dist/esm/generated/operations.d.ts +26 -0
- package/dist/esm/generated/operations.js +162 -0
- package/dist/esm/generated/resources.d.ts +887 -0
- package/dist/esm/generated/resources.js +716 -0
- package/dist/esm/resource.d.ts +30 -0
- package/dist/esm/resource.js +19 -0
- package/dist/esm/resources.d.ts +47 -54
- package/dist/esm/resources.js +17 -32
- package/dist/esm/types.d.ts +11 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ retries, idempotency keys, typed errors, pagination and approval helpers. No run
|
|
|
7
7
|
- Node 18+ and modern browsers (anything with `fetch`)
|
|
8
8
|
- ESM and CommonJS, with `.d.ts` types
|
|
9
9
|
|
|
10
|
-
> Status: pre-release (0.
|
|
10
|
+
> Status: pre-release (0.3.0). MIT licensed (see `LICENSE`).
|
|
11
11
|
|
|
12
12
|
## Install
|
|
13
13
|
|
|
@@ -81,6 +81,9 @@ Every method also takes a last `options` argument that overrides these per call:
|
|
|
81
81
|
| `finn.agents` | `list`, `listAll`, `create`, `draft`, `retrieve`, `saveDraft`, `validate`, `test`, `publish`, `driveTest` |
|
|
82
82
|
| `finn.chat` | `listChannels`; `conversations.{list, listAll, start, retrieve, listMessages, listAllMessages, send}`; `contacts.{list, listAll, retrieve, update}` |
|
|
83
83
|
|
|
84
|
+
The other operations (`finn.crm`, `finn.dialer`, `finn.webhooks`, `finn.organization`, `finn.sales` and more
|
|
85
|
+
`finn.finns` methods) are generated from the spec: see [Coverage](#coverage).
|
|
86
|
+
|
|
84
87
|
Methods return the response body exactly as the spec describes it (older voice endpoints wrap it in
|
|
85
88
|
`{ success, data }`). Request and response types come from `src/generated/openapi.ts`; schemas are exported as
|
|
86
89
|
`Schemas`, e.g. `Schemas['Call']`.
|
|
@@ -94,6 +97,30 @@ const full = await finn.requestWithResponse('get', '/wallet'); // { data, status
|
|
|
94
97
|
|
|
95
98
|
and endpoints newer than the SDK through `finn.rawRequest({ method, path, pathParams, query, body })`.
|
|
96
99
|
|
|
100
|
+
### Coverage
|
|
101
|
+
|
|
102
|
+
<!-- generated:coverage:start (scripts/generate.mjs; do not edit by hand) -->
|
|
103
|
+
The SDK covers **154 of 154** operations in the spec (Finn API v1):
|
|
104
|
+
72 through the hand-written methods above and 82 through generated ones, listed here.
|
|
105
|
+
|
|
106
|
+
| Property | Generated methods |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `finn.finns` | `generate`, `getFlow`, `enableFlow`, `disableFlow`, `getSettings`, `getVariables`, `updateVariables`, `updateHandbook`, `updateSpeechSettings`, `updateDraft`, `duplicate`, `getShareLink`, `createShareLink`, `getStats`, `getOutcomes` |
|
|
109
|
+
| `finn.crm` | `getSetup`, `getFilterSchema`, `searchRecords`, `queryRecords`, `countRecords`, `countRecordsByStage`, `getRecord`, `updateRecord`, `getRecordTimeline`, `getStageGate`, `listRecordDocuments`, `listRecordFiles`, `attachFile`, `getFormsChecklist`, `listFormSubmissions`, `listFormDrafts`, `listForms`, `listFollowUps`, `listAllFollowUps`, `getFollowUpStats`, `getMyWork`, `listViews`, `saveView`, `getSummary`, `getStageCounts`, `getSpeed`, `listDuplicates`, `ask`, `addNote`, `createFollowUp`, `updateFollowUp`, `createRecord`, `setStageCheck`, `assignReferenceNo`, `setDocumentStatus`, `saveFormDraft`, `draftDocument`, `moveRecordStage`, `submitForm`, `createFormLink`, `createUploadLink`, `guessImportColumns`, `importRecords` |
|
|
110
|
+
| `finn.dialer` | `listSessions`, `listAllSessions`, `getSession`, `getAnalytics`, `listFollowUps`, `getLeadBrief` |
|
|
111
|
+
| `finn.webhooks` | `listEndpoints`, `listAllEndpoints`, `createEndpoint`, `getEndpoint`, `updateEndpoint`, `deleteEndpoint`, `listDeliveries`, `listAllDeliveries`, `listEventTypes` |
|
|
112
|
+
| `finn.organization` | `get`, `listMembers`, `listAllMembers`, `listIntegrations`, `listAllIntegrations`, `listApiKeys`, `listAllApiKeys` |
|
|
113
|
+
| `finn.sales` (experimental) | `listPlays`, `listPlayRuns`, `listProspects`, `runPlay`, `listDrafts`, `updateDraft`, `skipDraft`, `listThreads`, `getThread` |
|
|
114
|
+
<!-- generated:coverage:end -->
|
|
115
|
+
|
|
116
|
+
Generated methods are named after the spec's `operationId` without the area's noun (`getFinnFlow` is
|
|
117
|
+
`finn.finns.getFlow`, `searchCrmRecords` is `finn.crm.searchRecords`). Path parameters come first, in path order,
|
|
118
|
+
then the body, then the query, then `options`. List operations that page by `cursor` also get a `listAll...` helper.
|
|
119
|
+
|
|
120
|
+
**`finn.sales` is experimental.** The Sales API (`/sales`) is switched off for every organization today, so its calls
|
|
121
|
+
answer an error until Finn turns it on for yours. Its methods are generated so the SDK matches the spec, and they may
|
|
122
|
+
change without a major version.
|
|
123
|
+
|
|
97
124
|
## Retries
|
|
98
125
|
|
|
99
126
|
Network errors, `408`, `429`, `502`, `503`, `504` and `409 idempotency_in_progress` are retried up to
|
|
@@ -102,7 +129,7 @@ is honoured; one longer than `maxRetryAfterMs` throws instead of waiting. A `500
|
|
|
102
129
|
|
|
103
130
|
`GET`, `PUT` and `DELETE` are always retried. A `POST` or `PATCH` is retried **only when it carries an
|
|
104
131
|
`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,
|
|
132
|
+
deployments, chat start/send, agents, case start, `/crm/*` writes, sales play runs and draft skips, webhook endpoint create). Other writes,
|
|
106
133
|
such as `finns.create` or `contacts.create`, are sent once: the API ignores the key there, so a retry after a timeout
|
|
107
134
|
could create a second record. Check with `honoursIdempotencyKey(method, path)`.
|
|
108
135
|
|
|
@@ -110,7 +137,7 @@ could create a second record. Check with `honoursIdempotencyKey(method, path)`.
|
|
|
110
137
|
|
|
111
138
|
These writes get a fresh `Idempotency-Key` automatically, reused across their retries:
|
|
112
139
|
`calls.create`, `phoneNumbers.rent`, `deployments.createOutbound`, `deployments.createInbound`,
|
|
113
|
-
`chat.conversations.start`, `chat.conversations.send`, `agents.create`, `cases.start`.
|
|
140
|
+
`chat.conversations.start`, `chat.conversations.send`, `agents.create`, `cases.start`, `webhooks.createEndpoint`.
|
|
114
141
|
|
|
115
142
|
```ts
|
|
116
143
|
import { idempotencyKey } from '@hirefinn/sdk';
|
|
@@ -121,7 +148,9 @@ await finn.calls.create(body, { idempotencyKey: false }); // opt out
|
|
|
121
148
|
```
|
|
122
149
|
|
|
123
150
|
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.
|
|
151
|
+
`finns.create`) does not make it safe to retry, and the SDK does not retry it. The generated CRM and Sales writes
|
|
152
|
+
(`crm.*`, `sales.runPlay`, `sales.skipDraft`) are on that list but get no automatic key: pass `{ idempotencyKey }` to
|
|
153
|
+
make them safe to retry.
|
|
125
154
|
|
|
126
155
|
## Webhooks
|
|
127
156
|
|
|
@@ -151,7 +180,9 @@ Options: `toleranceSeconds` (default 300), and `secret` can be an array while yo
|
|
|
151
180
|
|
|
152
181
|
Outward and spending writes from OAuth and MCP callers can answer `202 { status: 'pending_approval', approval_id,
|
|
153
182
|
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
|
|
183
|
+
`deployments.createOutbound`, `cases.start`, `chat.conversations.start` and `chat.conversations.send`, and the CRM
|
|
184
|
+
writes `crm.moveRecordStage`, `crm.submitForm`, `crm.createFormLink`, `crm.createUploadLink` and
|
|
185
|
+
`crm.importRecords`. Their return
|
|
155
186
|
types include `PendingApproval`; narrow with `isPendingApproval(res)` and wait with `finn.waitForApproval(id)`.
|
|
156
187
|
|
|
157
188
|
## Errors
|
|
@@ -203,10 +234,9 @@ BACKEND=../hirefinn-web-app-backend npm run spec:pull # from the backend repo'
|
|
|
203
234
|
|
|
204
235
|
Then `npm run typecheck && npm test`.
|
|
205
236
|
|
|
206
|
-
`npm run spec:drift` compares the SDK with the live spec (`https://api.hirefinn.ai/v1/openapi.json`) and fails
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
resource method in `src/resources.ts` for the ones worth a name.
|
|
237
|
+
`npm run spec:drift` compares the SDK with the live spec (`https://api.hirefinn.ai/v1/openapi.json`) and fails when
|
|
238
|
+
the spec has an operation the SDK has no method for, or the SDK calls one the spec dropped; CI runs it on every PR
|
|
239
|
+
and daily. `npm run generate -- --check` fails when the committed generated code is older than `spec/openapi.json`.
|
|
210
240
|
|
|
211
241
|
## Development
|
|
212
242
|
|
package/dist/cjs/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/cjs/client.js
CHANGED
|
@@ -26,6 +26,11 @@ class Finn extends core_js_1.FinnCore {
|
|
|
26
26
|
this.approvals = new resources_js_1.Approvals(this);
|
|
27
27
|
this.agents = new resources_js_1.Agents(this);
|
|
28
28
|
this.chat = new resources_js_1.Chat(this);
|
|
29
|
+
this.crm = new resources_js_1.Crm(this);
|
|
30
|
+
this.dialer = new resources_js_1.Dialer(this);
|
|
31
|
+
this.webhooks = new resources_js_1.Webhooks(this);
|
|
32
|
+
this.organization = new resources_js_1.Organization(this);
|
|
33
|
+
this.sales = new resources_js_1.Sales(this);
|
|
29
34
|
}
|
|
30
35
|
/** Polls an approval until it is decided (see approvals.wait). */
|
|
31
36
|
waitForApproval(id, options) {
|
package/dist/cjs/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FinnResponse, HttpMethod, Operation, PathsFor, RequestArgs, RequestOptions, ResultOf } from './types.js';
|
|
2
2
|
export declare const DEFAULT_BASE_URL = "https://api.hirefinn.ai/v1";
|
|
3
|
-
export declare const SDK_VERSION = "0.
|
|
3
|
+
export declare const SDK_VERSION = "0.3.0";
|
|
4
4
|
export interface FinnOptions {
|
|
5
5
|
/** `finn_live_...` org key, `finn_test_...` test key, or an OAuth `finn_oat_...` token. Defaults to env FINN_API_KEY. */
|
|
6
6
|
apiKey?: string;
|
package/dist/cjs/core.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.honoursIdempotencyKey = honoursIdempotencyKey;
|
|
|
17
17
|
exports.idempotencyKey = idempotencyKey;
|
|
18
18
|
const errors_js_1 = require("./errors.js");
|
|
19
19
|
exports.DEFAULT_BASE_URL = 'https://api.hirefinn.ai/v1';
|
|
20
|
-
exports.SDK_VERSION = '0.
|
|
20
|
+
exports.SDK_VERSION = '0.3.0';
|
|
21
21
|
/** Writes that get an automatic Idempotency-Key (when autoIdempotency is on). */
|
|
22
22
|
exports.AUTO_IDEMPOTENCY_ROUTES = new Set([
|
|
23
23
|
'post /calls',
|
|
@@ -28,6 +28,7 @@ exports.AUTO_IDEMPOTENCY_ROUTES = new Set([
|
|
|
28
28
|
'post /chat/conversations/{id}/messages',
|
|
29
29
|
'post /agents',
|
|
30
30
|
'post /agents/{id}/cases',
|
|
31
|
+
'post /webhook_endpoints',
|
|
31
32
|
]);
|
|
32
33
|
/**
|
|
33
34
|
* POST/PATCH routes where the API dedupes by Idempotency-Key (a retry with the same key and body replays the first
|
|
@@ -47,6 +48,7 @@ exports.IDEMPOTENT_WRITE_ROUTES = [
|
|
|
47
48
|
'patch /crm/*',
|
|
48
49
|
'post /sales/plays/{slug}/run',
|
|
49
50
|
'post /sales/drafts/{id}/skip',
|
|
51
|
+
'post /webhook_endpoints',
|
|
50
52
|
];
|
|
51
53
|
const IDEMPOTENT_WRITE_MATCHERS = exports.IDEMPOTENT_WRITE_ROUTES.map((route) => {
|
|
52
54
|
const [method, path] = route.split(' ');
|