@hirefinn/sdk 0.0.0-stage → 0.1.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 +177 -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 +69 -0
- package/dist/cjs/core.js +265 -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 +11 -0
- package/dist/cjs/index.js +44 -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 +144 -0
- package/dist/cjs/types.js +2 -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 +69 -0
- package/dist/esm/core.js +260 -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 +11 -0
- package/dist/esm/index.js +7 -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 +144 -0
- package/dist/esm/types.js +1 -0
- package/package.json +51 -4
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { FinnApprovalTimeoutError } from './errors.js';
|
|
2
|
+
import { Paginator, beforeStrategy, cursorStrategy, offsetStrategy, pageStrategy, } from './pagination.js';
|
|
3
|
+
class Resource {
|
|
4
|
+
constructor(core) {
|
|
5
|
+
this.core = core;
|
|
6
|
+
}
|
|
7
|
+
async do(method, path, params = {}, options) {
|
|
8
|
+
const res = await this.core.rawRequest({
|
|
9
|
+
method,
|
|
10
|
+
path,
|
|
11
|
+
pathParams: params.path,
|
|
12
|
+
query: params.query,
|
|
13
|
+
body: params.body,
|
|
14
|
+
}, options);
|
|
15
|
+
return res.data;
|
|
16
|
+
}
|
|
17
|
+
pager(path, strategy, query, pathParams, options) {
|
|
18
|
+
return new Paginator(async (q) => (await this.core.rawRequest({ method: 'get', path, pathParams, query: q }, options)).data, strategy, (query ?? {}));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// ---------------------------------------------------------------- Voice
|
|
22
|
+
export class Calls extends Resource {
|
|
23
|
+
/** Place an outbound call. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
|
|
24
|
+
create(body, options) {
|
|
25
|
+
return this.do('post', '/calls', { body }, options);
|
|
26
|
+
}
|
|
27
|
+
list(query, options) {
|
|
28
|
+
return this.do('get', '/calls', { query }, options);
|
|
29
|
+
}
|
|
30
|
+
/** Every call matching the filters, page by page. */
|
|
31
|
+
listAll(query, options) {
|
|
32
|
+
return this.pager('/calls', offsetStrategy(), query, undefined, options);
|
|
33
|
+
}
|
|
34
|
+
retrieve(callUuid, options) {
|
|
35
|
+
return this.do('get', '/calls/{call_uuid}', { path: { call_uuid: callUuid } }, options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class Finns extends Resource {
|
|
39
|
+
list(query, options) {
|
|
40
|
+
return this.do('get', '/finns', { query }, options);
|
|
41
|
+
}
|
|
42
|
+
listAll(query, options) {
|
|
43
|
+
return this.pager('/finns', offsetStrategy(), query, undefined, options);
|
|
44
|
+
}
|
|
45
|
+
create(body, options) {
|
|
46
|
+
return this.do('post', '/finns', { body }, options);
|
|
47
|
+
}
|
|
48
|
+
retrieve(finnId, options) {
|
|
49
|
+
return this.do('get', '/finns/{finn_id}', { path: { finn_id: finnId } }, options);
|
|
50
|
+
}
|
|
51
|
+
update(finnId, body, options) {
|
|
52
|
+
return this.do('patch', '/finns/{finn_id}', { path: { finn_id: finnId }, body }, options);
|
|
53
|
+
}
|
|
54
|
+
delete(finnId, options) {
|
|
55
|
+
return this.do('delete', '/finns/{finn_id}', { path: { finn_id: finnId } }, options);
|
|
56
|
+
}
|
|
57
|
+
listKnowledgeBase(finnId, options) {
|
|
58
|
+
return this.do('get', '/finns/{finn_id}/knowledge_base', { path: { finn_id: finnId } }, options);
|
|
59
|
+
}
|
|
60
|
+
/** JSON body, or a FormData with the file for multipart upload. */
|
|
61
|
+
addKnowledgeBaseDocument(finnId, body, options) {
|
|
62
|
+
return this.do('post', '/finns/{finn_id}/knowledge_base', { path: { finn_id: finnId }, body }, options);
|
|
63
|
+
}
|
|
64
|
+
postCallAnalysis(finnId, query, options) {
|
|
65
|
+
return this.do('get', '/finns/{finn_id}/post_call_analysis', { path: { finn_id: finnId }, query }, options);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export class Voices extends Resource {
|
|
69
|
+
list(query, options) {
|
|
70
|
+
return this.do('get', '/voices', { query }, options);
|
|
71
|
+
}
|
|
72
|
+
listAll(query, options) {
|
|
73
|
+
return this.pager('/voices', offsetStrategy(), query, undefined, options);
|
|
74
|
+
}
|
|
75
|
+
retrieve(voiceId, options) {
|
|
76
|
+
return this.do('get', '/voices/{voice_id}', { path: { voice_id: voiceId } }, options);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export class PhoneNumbers extends Resource {
|
|
80
|
+
list(query, options) {
|
|
81
|
+
return this.do('get', '/phone_numbers', { query }, options);
|
|
82
|
+
}
|
|
83
|
+
listAll(query, options) {
|
|
84
|
+
return this.pager('/phone_numbers', offsetStrategy(), query, undefined, options);
|
|
85
|
+
}
|
|
86
|
+
searchAvailable(query, options) {
|
|
87
|
+
return this.do('get', '/phone_numbers/available', { query }, options);
|
|
88
|
+
}
|
|
89
|
+
/** Rent a number (spends credits). Gets an automatic Idempotency-Key. May answer `pending_approval`. */
|
|
90
|
+
rent(body, options) {
|
|
91
|
+
return this.do('post', '/phone_numbers', { body }, options);
|
|
92
|
+
}
|
|
93
|
+
retrieve(id, options) {
|
|
94
|
+
return this.do('get', '/phone_numbers/{id}', { path: { id } }, options);
|
|
95
|
+
}
|
|
96
|
+
release(id, options) {
|
|
97
|
+
return this.do('delete', '/phone_numbers/{id}', { path: { id } }, options);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export class Audiences extends Resource {
|
|
101
|
+
list(query, options) {
|
|
102
|
+
return this.do('get', '/audiences', { query }, options);
|
|
103
|
+
}
|
|
104
|
+
listAll(query, options) {
|
|
105
|
+
return this.pager('/audiences', offsetStrategy(), query, undefined, options);
|
|
106
|
+
}
|
|
107
|
+
create(body, options) {
|
|
108
|
+
return this.do('post', '/audiences', { body }, options);
|
|
109
|
+
}
|
|
110
|
+
retrieve(audienceId, options) {
|
|
111
|
+
return this.do('get', '/audiences/{audience_id}', { path: { audience_id: audienceId } }, options);
|
|
112
|
+
}
|
|
113
|
+
archive(audienceId, options) {
|
|
114
|
+
return this.do('delete', '/audiences/{audience_id}', { path: { audience_id: audienceId } }, options);
|
|
115
|
+
}
|
|
116
|
+
listContacts(audienceId, query, options) {
|
|
117
|
+
return this.do('get', '/audiences/{audience_id}/contacts', { path: { audience_id: audienceId }, query }, options);
|
|
118
|
+
}
|
|
119
|
+
listAllContacts(audienceId, query, options) {
|
|
120
|
+
return this.pager('/audiences/{audience_id}/contacts', offsetStrategy(), query, { audience_id: audienceId }, options);
|
|
121
|
+
}
|
|
122
|
+
addContacts(audienceId, body, options) {
|
|
123
|
+
return this.do('post', '/audiences/{audience_id}/contacts', { path: { audience_id: audienceId }, body }, options);
|
|
124
|
+
}
|
|
125
|
+
removeContact(audienceId, phone, options) {
|
|
126
|
+
return this.do('delete', '/audiences/{audience_id}/contacts/{phone}', { path: { audience_id: audienceId, phone } }, options);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export class Deployments extends Resource {
|
|
130
|
+
list(query, options) {
|
|
131
|
+
return this.do('get', '/deployments', { query }, options);
|
|
132
|
+
}
|
|
133
|
+
listAll(query, options) {
|
|
134
|
+
return this.pager('/deployments', offsetStrategy(), query, undefined, options);
|
|
135
|
+
}
|
|
136
|
+
/** Start an outbound campaign (spends credits). Gets an automatic Idempotency-Key. May answer `pending_approval`. */
|
|
137
|
+
createOutbound(body, options) {
|
|
138
|
+
return this.do('post', '/deployments', { body }, options);
|
|
139
|
+
}
|
|
140
|
+
/** Gets an automatic Idempotency-Key. */
|
|
141
|
+
createInbound(body, options) {
|
|
142
|
+
return this.do('post', '/deployments/inbound', { body }, options);
|
|
143
|
+
}
|
|
144
|
+
retrieve(id, options) {
|
|
145
|
+
return this.do('get', '/deployments/{id}', { path: { id } }, options);
|
|
146
|
+
}
|
|
147
|
+
stop(id, options) {
|
|
148
|
+
return this.do('post', '/deployments/{id}/stop', { path: { id } }, options);
|
|
149
|
+
}
|
|
150
|
+
stopInbound(finnId, options) {
|
|
151
|
+
return this.do('post', '/deployments/inbound/{finn_id}/stop', { path: { finn_id: finnId } }, options);
|
|
152
|
+
}
|
|
153
|
+
analytics(id, query, options) {
|
|
154
|
+
return this.do('get', '/deployments/{id}/analytics', { path: { id }, query }, options);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export class Wallet extends Resource {
|
|
158
|
+
retrieve(options) {
|
|
159
|
+
return this.do('get', '/wallet', {}, options);
|
|
160
|
+
}
|
|
161
|
+
listTransactions(query, options) {
|
|
162
|
+
return this.do('get', '/wallet/transactions', { query }, options);
|
|
163
|
+
}
|
|
164
|
+
listAllTransactions(query, options) {
|
|
165
|
+
return this.pager('/wallet/transactions', offsetStrategy(), query, undefined, options);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export class DoNotCall extends Resource {
|
|
169
|
+
list(query, options) {
|
|
170
|
+
return this.do('get', '/do_not_call', { query }, options);
|
|
171
|
+
}
|
|
172
|
+
listAll(query, options) {
|
|
173
|
+
return this.pager('/do_not_call', offsetStrategy(), query, undefined, options);
|
|
174
|
+
}
|
|
175
|
+
add(body, options) {
|
|
176
|
+
return this.do('post', '/do_not_call', { body }, options);
|
|
177
|
+
}
|
|
178
|
+
/** Needs the `voice:dnc:write` scope. */
|
|
179
|
+
remove(phone, options) {
|
|
180
|
+
return this.do('delete', '/do_not_call/{phone}', { path: { phone } }, options);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------- CRM
|
|
184
|
+
export class Contacts extends Resource {
|
|
185
|
+
list(query, options) {
|
|
186
|
+
return this.do('get', '/contacts', { query }, options);
|
|
187
|
+
}
|
|
188
|
+
listAll(query, options) {
|
|
189
|
+
return this.pager('/contacts', pageStrategy('contacts'), query, undefined, options);
|
|
190
|
+
}
|
|
191
|
+
create(body, options) {
|
|
192
|
+
return this.do('post', '/contacts', { body }, options);
|
|
193
|
+
}
|
|
194
|
+
retrieve(id, options) {
|
|
195
|
+
return this.do('get', '/contacts/{id}', { path: { id } }, options);
|
|
196
|
+
}
|
|
197
|
+
update(id, body, options) {
|
|
198
|
+
return this.do('patch', '/contacts/{id}', { path: { id }, body }, options);
|
|
199
|
+
}
|
|
200
|
+
timeline(id, query, options) {
|
|
201
|
+
return this.do('get', '/contacts/{id}/timeline', { path: { id }, query }, options);
|
|
202
|
+
}
|
|
203
|
+
timelineAll(id, query, options) {
|
|
204
|
+
return this.pager('/contacts/{id}/timeline', beforeStrategy('items', 'next'), query, { id }, options);
|
|
205
|
+
}
|
|
206
|
+
addNote(id, body, options) {
|
|
207
|
+
return this.do('post', '/contacts/{id}/notes', { path: { id }, body }, options);
|
|
208
|
+
}
|
|
209
|
+
/** Record kinds (contact, company, ...). */
|
|
210
|
+
listKinds(options) {
|
|
211
|
+
return this.do('get', '/record_kinds', {}, options);
|
|
212
|
+
}
|
|
213
|
+
listFields(query, options) {
|
|
214
|
+
return this.do('get', '/fields', { query }, options);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// ---------------------------------------------------------------- Operator
|
|
218
|
+
export class Cases extends Resource {
|
|
219
|
+
list(query, options) {
|
|
220
|
+
return this.do('get', '/cases', { query }, options);
|
|
221
|
+
}
|
|
222
|
+
listAll(query, options) {
|
|
223
|
+
return this.pager('/cases', beforeStrategy('cases', 'next_before'), query, undefined, options);
|
|
224
|
+
}
|
|
225
|
+
retrieve(id, options) {
|
|
226
|
+
return this.do('get', '/cases/{id}', { path: { id } }, options);
|
|
227
|
+
}
|
|
228
|
+
listEvents(id, options) {
|
|
229
|
+
return this.do('get', '/cases/{id}/events', { path: { id } }, options);
|
|
230
|
+
}
|
|
231
|
+
/** Start a case on an agent. Gets an automatic Idempotency-Key. */
|
|
232
|
+
start(agentId, body, options) {
|
|
233
|
+
return this.do('post', '/agents/{id}/cases', { path: { id: agentId }, body }, options);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** Statuses that are still waiting: holds (`pending`, `running`) and Operator approvals (`open`). */
|
|
237
|
+
const WAITING_STATUSES = new Set(['pending', 'running', 'open', 'pending_approval']);
|
|
238
|
+
export class Approvals extends Resource {
|
|
239
|
+
list(query, options) {
|
|
240
|
+
return this.do('get', '/approvals', { query }, options);
|
|
241
|
+
}
|
|
242
|
+
listAll(query, options) {
|
|
243
|
+
return this.pager('/approvals', cursorStrategy('approvals'), query, undefined, options);
|
|
244
|
+
}
|
|
245
|
+
/** An Operator approval, or a held API request (`source: 'api_hold'`) made by this caller. */
|
|
246
|
+
async retrieve(id, options) {
|
|
247
|
+
const body = await this.do('get', '/approvals/{id}', { path: { id } }, options);
|
|
248
|
+
return unwrapApproval(body);
|
|
249
|
+
}
|
|
250
|
+
decide(id, body, options) {
|
|
251
|
+
return this.do('post', '/approvals/{id}/decide', { path: { id }, body }, options);
|
|
252
|
+
}
|
|
253
|
+
approve(id, body, options) {
|
|
254
|
+
return this.do('post', '/approvals/{id}/approve', { path: { id }, body }, options);
|
|
255
|
+
}
|
|
256
|
+
reject(id, body, options) {
|
|
257
|
+
return this.do('post', '/approvals/{id}/reject', { path: { id }, body }, options);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Polls `GET /approvals/{id}` until the approval leaves `pending` / `running` / `open`, and returns it.
|
|
261
|
+
* For a held API request, `status` ends as `succeeded`, `failed`, `declined` or `expired`, and `result` holds
|
|
262
|
+
* the held request's own answer.
|
|
263
|
+
*/
|
|
264
|
+
async wait(id, opts = {}) {
|
|
265
|
+
const interval = opts.intervalMs ?? 3000;
|
|
266
|
+
const deadline = Date.now() + (opts.timeoutMs ?? 15 * 60000);
|
|
267
|
+
const sleep = opts.sleep ?? defaultPollSleep;
|
|
268
|
+
let last = null;
|
|
269
|
+
for (;;) {
|
|
270
|
+
const approval = await this.retrieve(id, { signal: opts.signal });
|
|
271
|
+
opts.onPoll?.(approval);
|
|
272
|
+
last = typeof approval.status === 'string' ? approval.status : null;
|
|
273
|
+
if (last !== null && !WAITING_STATUSES.has(last))
|
|
274
|
+
return approval;
|
|
275
|
+
if (Date.now() + interval > deadline)
|
|
276
|
+
throw new FinnApprovalTimeoutError(id, last);
|
|
277
|
+
await sleep(interval, opts.signal);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function unwrapApproval(body) {
|
|
282
|
+
const b = (body ?? {});
|
|
283
|
+
const inner = (typeof b.data === 'object' && b.data) || (typeof b.approval === 'object' && b.approval) || b;
|
|
284
|
+
return inner;
|
|
285
|
+
}
|
|
286
|
+
function defaultPollSleep(ms, signal) {
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
if (signal?.aborted)
|
|
289
|
+
return reject(signal.reason);
|
|
290
|
+
const t = setTimeout(resolve, ms);
|
|
291
|
+
signal?.addEventListener('abort', () => (clearTimeout(t), reject(signal.reason)), { once: true });
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
export class Agents extends Resource {
|
|
295
|
+
list(query, options) {
|
|
296
|
+
return this.do('get', '/agents', { query }, options);
|
|
297
|
+
}
|
|
298
|
+
listAll(query, options) {
|
|
299
|
+
return this.pager('/agents', cursorStrategy('data'), query, undefined, options);
|
|
300
|
+
}
|
|
301
|
+
/** Create a draft agent (never live). Gets an automatic Idempotency-Key. */
|
|
302
|
+
create(body, options) {
|
|
303
|
+
return this.do('post', '/agents', { body }, options);
|
|
304
|
+
}
|
|
305
|
+
/** Draft an agent from a description, without saving it. */
|
|
306
|
+
draft(body, options) {
|
|
307
|
+
return this.do('post', '/agents/draft', { body }, options);
|
|
308
|
+
}
|
|
309
|
+
retrieve(id, options) {
|
|
310
|
+
return this.do('get', '/agents/{id}', { path: { id } }, options);
|
|
311
|
+
}
|
|
312
|
+
saveDraft(id, body, options) {
|
|
313
|
+
return this.do('put', '/agents/{id}/draft', { path: { id }, body }, options);
|
|
314
|
+
}
|
|
315
|
+
validate(id, options) {
|
|
316
|
+
return this.do('post', '/agents/{id}/validate', { path: { id } }, options);
|
|
317
|
+
}
|
|
318
|
+
test(id, body, options) {
|
|
319
|
+
return this.do('post', '/agents/{id}/test', { path: { id }, body }, options);
|
|
320
|
+
}
|
|
321
|
+
publish(id, options) {
|
|
322
|
+
return this.do('post', '/agents/{id}/publish', { path: { id } }, options);
|
|
323
|
+
}
|
|
324
|
+
/** Drive a test case one step (`action` as the spec lists it). */
|
|
325
|
+
driveTest(caseId, action, body, options) {
|
|
326
|
+
return this.do('post', '/cases/{id}/test/{action}', { path: { id: caseId, action }, body }, options);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
export class ChatConversations extends Resource {
|
|
330
|
+
list(query, options) {
|
|
331
|
+
return this.do('get', '/chat/conversations', { query }, options);
|
|
332
|
+
}
|
|
333
|
+
listAll(query, options) {
|
|
334
|
+
return this.pager('/chat/conversations', cursorStrategy('data'), query, undefined, options);
|
|
335
|
+
}
|
|
336
|
+
/** Start a conversation (sends the first message). Gets an automatic Idempotency-Key (the API requires one). */
|
|
337
|
+
start(body, options) {
|
|
338
|
+
return this.do('post', '/chat/conversations', { body }, options);
|
|
339
|
+
}
|
|
340
|
+
retrieve(id, options) {
|
|
341
|
+
return this.do('get', '/chat/conversations/{id}', { path: { id } }, options);
|
|
342
|
+
}
|
|
343
|
+
listMessages(id, query, options) {
|
|
344
|
+
return this.do('get', '/chat/conversations/{id}/messages', { path: { id }, query }, options);
|
|
345
|
+
}
|
|
346
|
+
listAllMessages(id, query, options) {
|
|
347
|
+
return this.pager('/chat/conversations/{id}/messages', cursorStrategy('data'), query, { id }, options);
|
|
348
|
+
}
|
|
349
|
+
/** Send a message. Gets an automatic Idempotency-Key (the API requires one). */
|
|
350
|
+
send(id, body, options) {
|
|
351
|
+
return this.do('post', '/chat/conversations/{id}/messages', { path: { id }, body }, options);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
export class ChatContacts extends Resource {
|
|
355
|
+
list(query, options) {
|
|
356
|
+
return this.do('get', '/chat/contacts', { query }, options);
|
|
357
|
+
}
|
|
358
|
+
listAll(query, options) {
|
|
359
|
+
return this.pager('/chat/contacts', cursorStrategy('data'), query, undefined, options);
|
|
360
|
+
}
|
|
361
|
+
retrieve(id, options) {
|
|
362
|
+
return this.do('get', '/chat/contacts/{id}', { path: { id } }, options);
|
|
363
|
+
}
|
|
364
|
+
update(id, body, options) {
|
|
365
|
+
return this.do('patch', '/chat/contacts/{id}', { path: { id }, body }, options);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
export class Chat extends Resource {
|
|
369
|
+
constructor(core) {
|
|
370
|
+
super(core);
|
|
371
|
+
this.conversations = new ChatConversations(core);
|
|
372
|
+
this.contacts = new ChatContacts(core);
|
|
373
|
+
}
|
|
374
|
+
listChannels(options) {
|
|
375
|
+
return this.do('get', '/chat/channels', {}, options);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type helpers over the generated OpenAPI types. They turn a (path, method) pair into its path params, query,
|
|
3
|
+
* body and success response, so `finn.request('get', '/calls/{call_uuid}', ...)` is checked end to end.
|
|
4
|
+
*/
|
|
5
|
+
import type { components, operations, paths } from './generated/openapi.js';
|
|
6
|
+
export type { components, operations, paths };
|
|
7
|
+
/** Every schema in the spec, e.g. `Schemas['Call']`. */
|
|
8
|
+
export type Schemas = components['schemas'];
|
|
9
|
+
export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
10
|
+
/** Paths that support method M. */
|
|
11
|
+
export type PathsFor<M extends HttpMethod> = {
|
|
12
|
+
[P in keyof paths]: paths[P] extends {
|
|
13
|
+
[K in M]: infer O;
|
|
14
|
+
} ? ([O] extends [undefined] ? never : P) : never;
|
|
15
|
+
}[keyof paths];
|
|
16
|
+
/** The operation at (P, M). */
|
|
17
|
+
export type Operation<P extends keyof paths, M extends HttpMethod> = paths[P] extends {
|
|
18
|
+
[K in M]: infer O;
|
|
19
|
+
} ? O : never;
|
|
20
|
+
type ParamsOf<O> = O extends {
|
|
21
|
+
parameters: infer X;
|
|
22
|
+
} ? X : Record<string, never>;
|
|
23
|
+
type NonNever<T> = [T] extends [never] ? undefined : T;
|
|
24
|
+
export type PathParamsOf<O> = ParamsOf<O> extends {
|
|
25
|
+
path?: infer X;
|
|
26
|
+
} ? NonNever<Exclude<X, undefined>> : undefined;
|
|
27
|
+
export type QueryOf<O> = ParamsOf<O> extends {
|
|
28
|
+
query?: infer X;
|
|
29
|
+
} ? NonNever<Exclude<X, undefined>> : undefined;
|
|
30
|
+
export type BodyOf<O> = O extends {
|
|
31
|
+
requestBody?: infer RB;
|
|
32
|
+
} ? Exclude<RB, undefined> extends {
|
|
33
|
+
content: infer C;
|
|
34
|
+
} ? C extends {
|
|
35
|
+
'application/json': infer B;
|
|
36
|
+
} ? B : C extends {
|
|
37
|
+
'multipart/form-data': infer B;
|
|
38
|
+
} ? B : undefined : undefined : undefined;
|
|
39
|
+
type BodyRequired<O> = O extends {
|
|
40
|
+
requestBody: {
|
|
41
|
+
content: unknown;
|
|
42
|
+
};
|
|
43
|
+
} ? true : false;
|
|
44
|
+
type JsonOf<R> = R extends {
|
|
45
|
+
content: {
|
|
46
|
+
'application/json': infer B;
|
|
47
|
+
};
|
|
48
|
+
} ? B : undefined;
|
|
49
|
+
/** The JSON body of every 2xx response of O, as a union. */
|
|
50
|
+
export type ResponseOf<O> = O extends {
|
|
51
|
+
responses: infer R;
|
|
52
|
+
} ? {
|
|
53
|
+
[S in keyof R]: S extends 200 | 201 | 202 | 204 | '200' | '201' | '202' | '204' ? JsonOf<R[S]> : never;
|
|
54
|
+
}[keyof R] : unknown;
|
|
55
|
+
/** The `params` argument of `finn.request(method, path, params)`. */
|
|
56
|
+
export type RequestParams<O> = (PathParamsOf<O> extends undefined ? {
|
|
57
|
+
path?: undefined;
|
|
58
|
+
} : {
|
|
59
|
+
path: PathParamsOf<O>;
|
|
60
|
+
}) & (QueryOf<O> extends undefined ? {
|
|
61
|
+
query?: undefined;
|
|
62
|
+
} : {
|
|
63
|
+
query?: QueryOf<O>;
|
|
64
|
+
}) & (BodyOf<O> extends undefined ? {
|
|
65
|
+
body?: undefined;
|
|
66
|
+
} : BodyRequired<O> extends true ? {
|
|
67
|
+
body: BodyOf<O>;
|
|
68
|
+
} : {
|
|
69
|
+
body?: BodyOf<O>;
|
|
70
|
+
});
|
|
71
|
+
type HasRequiredKeys<T> = {
|
|
72
|
+
[K in keyof T]-?: object extends Pick<T, K> ? never : K;
|
|
73
|
+
}[keyof T] extends never ? false : true;
|
|
74
|
+
/** Rest arguments after (method, path): params are required only when the operation has required inputs. */
|
|
75
|
+
export type RequestArgs<O> = HasRequiredKeys<RequestParams<O>> extends true ? [params: RequestParams<O>, options?: RequestOptions] : [params?: RequestParams<O>, options?: RequestOptions];
|
|
76
|
+
/** Per-request options. Each one overrides the client's setting for this call only. */
|
|
77
|
+
export interface RequestOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Idempotency-Key for this request. A retry with the same key and body within 24 hours returns the first answer.
|
|
80
|
+
* Pass `false` to send none, even on an endpoint where the SDK would make one up.
|
|
81
|
+
*/
|
|
82
|
+
idempotencyKey?: string | false;
|
|
83
|
+
/** Org to act in (Finn-Org header), for tokens that can use more than one org. */
|
|
84
|
+
org?: string;
|
|
85
|
+
/** API version date (Finn-Version header), e.g. `2026-11-01`. */
|
|
86
|
+
version?: string;
|
|
87
|
+
/** Retries after the first attempt. */
|
|
88
|
+
maxRetries?: number;
|
|
89
|
+
/** Timeout per attempt, in milliseconds. */
|
|
90
|
+
timeoutMs?: number;
|
|
91
|
+
/** Cancels the request (and its retries). */
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
/** Extra headers. They win over the SDK's own, except Authorization. */
|
|
94
|
+
headers?: Record<string, string>;
|
|
95
|
+
}
|
|
96
|
+
/** The answer of an outward or spending action that is waiting for a person to approve it (HTTP 202). */
|
|
97
|
+
export interface PendingApproval {
|
|
98
|
+
status: 'pending_approval';
|
|
99
|
+
/** Poll `GET /approvals/{approval_id}` (or call `finn.approvals.wait(id)`) for the outcome. */
|
|
100
|
+
approval_id: string;
|
|
101
|
+
/** The page in Finn where a person approves it. */
|
|
102
|
+
approve_url: string;
|
|
103
|
+
expires_at: string | null;
|
|
104
|
+
action?: string;
|
|
105
|
+
summary?: unknown;
|
|
106
|
+
}
|
|
107
|
+
/** Status of a held API request as `GET /approvals/{id}` reports it. */
|
|
108
|
+
export type HoldStatus = 'pending' | 'running' | 'succeeded' | 'failed' | 'declined' | 'expired';
|
|
109
|
+
/** A held API request as `GET /approvals/{id}` returns it to the caller that made it. */
|
|
110
|
+
export interface ApprovalHold {
|
|
111
|
+
id: string;
|
|
112
|
+
object: 'approval';
|
|
113
|
+
source: 'api_hold';
|
|
114
|
+
status: HoldStatus;
|
|
115
|
+
action: string;
|
|
116
|
+
class: string;
|
|
117
|
+
summary: unknown;
|
|
118
|
+
approve_url: string | null;
|
|
119
|
+
expires_at: string | null;
|
|
120
|
+
created_at: string | null;
|
|
121
|
+
decided_at: string | null;
|
|
122
|
+
finished_at: string | null;
|
|
123
|
+
/** True when a run started long ago and never reported back. */
|
|
124
|
+
outcome_unknown: boolean;
|
|
125
|
+
/** The held request's own answer once it ran. */
|
|
126
|
+
result: {
|
|
127
|
+
status: number;
|
|
128
|
+
body: unknown;
|
|
129
|
+
} | null;
|
|
130
|
+
}
|
|
131
|
+
/** A response together with its HTTP status and headers. */
|
|
132
|
+
export interface FinnResponse<T> {
|
|
133
|
+
data: T;
|
|
134
|
+
status: number;
|
|
135
|
+
headers: Headers;
|
|
136
|
+
/** X-Request-Id. */
|
|
137
|
+
requestId: string | null;
|
|
138
|
+
/** True when the API replayed a saved answer for the same Idempotency-Key. */
|
|
139
|
+
idempotentReplayed: boolean;
|
|
140
|
+
}
|
|
141
|
+
/** Routes whose writes the API may hold for approval (HTTP 202 `pending_approval`). */
|
|
142
|
+
export type HoldableRoute = 'post /calls' | 'post /deployments' | 'post /phone_numbers';
|
|
143
|
+
/** What `request()` resolves to: the spec's success body, or PendingApproval on holdable routes. */
|
|
144
|
+
export type ResultOf<P extends string, M extends HttpMethod, O> = `${M} ${P}` extends HoldableRoute ? ResponseOf<O> | PendingApproval : ResponseOf<O>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hirefinn/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed TypeScript client for the Finn public API (hirefinn.ai).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/cjs/index.js",
|
|
8
|
+
"module": "./dist/esm/index.js",
|
|
9
|
+
"types": "./dist/esm/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/esm/index.d.ts",
|
|
14
|
+
"default": "./dist/esm/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"default": "./dist/cjs/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/Hire-FinnAI/finn-sdk-ts.git"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://hirefinn.ai",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"generate": "node scripts/generate.mjs",
|
|
42
|
+
"spec:pull": "sh scripts/pull-spec.sh",
|
|
43
|
+
"build": "node scripts/build.mjs",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"prepack": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"openapi-typescript": "7.13.0",
|
|
50
|
+
"typescript": "5.9.3",
|
|
51
|
+
"vitest": "4.1.12"
|
|
52
|
+
}
|
|
53
|
+
}
|