@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.
Files changed (44) hide show
  1. package/README.md +63 -13
  2. package/dist/cjs/client.d.ts +13 -1
  3. package/dist/cjs/client.js +5 -0
  4. package/dist/cjs/core.d.ts +16 -3
  5. package/dist/cjs/core.js +25 -6
  6. package/dist/cjs/errors.d.ts +1 -1
  7. package/dist/cjs/errors.js +11 -0
  8. package/dist/cjs/generated/openapi.d.ts +19867 -5738
  9. package/dist/cjs/generated/operations.d.ts +26 -0
  10. package/dist/cjs/generated/operations.js +176 -0
  11. package/dist/cjs/generated/resources.d.ts +1050 -0
  12. package/dist/cjs/generated/resources.js +816 -0
  13. package/dist/cjs/index.d.ts +2 -2
  14. package/dist/cjs/index.js +4 -1
  15. package/dist/cjs/pagination.d.ts +3 -0
  16. package/dist/cjs/pagination.js +26 -5
  17. package/dist/cjs/resource.d.ts +30 -0
  18. package/dist/cjs/resource.js +23 -0
  19. package/dist/cjs/resources.d.ts +64 -57
  20. package/dist/cjs/resources.js +31 -36
  21. package/dist/cjs/types.d.ts +11 -3
  22. package/dist/cjs/webhooks.d.ts +11 -1
  23. package/dist/esm/client.d.ts +13 -1
  24. package/dist/esm/client.js +6 -1
  25. package/dist/esm/core.d.ts +16 -3
  26. package/dist/esm/core.js +24 -5
  27. package/dist/esm/errors.d.ts +1 -1
  28. package/dist/esm/errors.js +11 -0
  29. package/dist/esm/generated/openapi.d.ts +19867 -5738
  30. package/dist/esm/generated/operations.d.ts +26 -0
  31. package/dist/esm/generated/operations.js +173 -0
  32. package/dist/esm/generated/resources.d.ts +1050 -0
  33. package/dist/esm/generated/resources.js +795 -0
  34. package/dist/esm/index.d.ts +2 -2
  35. package/dist/esm/index.js +2 -2
  36. package/dist/esm/pagination.d.ts +3 -0
  37. package/dist/esm/pagination.js +25 -5
  38. package/dist/esm/resource.d.ts +30 -0
  39. package/dist/esm/resource.js +19 -0
  40. package/dist/esm/resources.d.ts +64 -57
  41. package/dist/esm/resources.js +24 -34
  42. package/dist/esm/types.d.ts +11 -3
  43. package/dist/esm/webhooks.d.ts +11 -1
  44. package/package.json +2 -1
@@ -1,25 +1,10 @@
1
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
- }
2
+ import { afterStrategy, beforeStrategy, cursorStrategy, offsetStrategy, pageStrategy } from './pagination.js';
3
+ import { Resource } from './resource.js';
4
+ import { AgentsGenerated, ApprovalsGenerated, AudiencesGenerated, CallsGenerated, CasesGenerated, ChatGenerated, ContactsGenerated, DeploymentsGenerated, DoNotCallGenerated, FinnsGenerated, PhoneNumbersGenerated, VoicesGenerated, WalletGenerated, } from './generated/resources.js';
5
+ export { Crm, Dialer, Organization, Sales, Webhooks } from './generated/resources.js';
21
6
  // ---------------------------------------------------------------- Voice
22
- export class Calls extends Resource {
7
+ export class Calls extends CallsGenerated {
23
8
  /** Place an outbound call. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
24
9
  create(body, options) {
25
10
  return this.do('post', '/calls', { body }, options);
@@ -35,7 +20,7 @@ export class Calls extends Resource {
35
20
  return this.do('get', '/calls/{call_uuid}', { path: { call_uuid: callUuid } }, options);
36
21
  }
37
22
  }
38
- export class Finns extends Resource {
23
+ export class Finns extends FinnsGenerated {
39
24
  list(query, options) {
40
25
  return this.do('get', '/finns', { query }, options);
41
26
  }
@@ -65,7 +50,7 @@ export class Finns extends Resource {
65
50
  return this.do('get', '/finns/{finn_id}/post_call_analysis', { path: { finn_id: finnId }, query }, options);
66
51
  }
67
52
  }
68
- export class Voices extends Resource {
53
+ export class Voices extends VoicesGenerated {
69
54
  list(query, options) {
70
55
  return this.do('get', '/voices', { query }, options);
71
56
  }
@@ -76,7 +61,7 @@ export class Voices extends Resource {
76
61
  return this.do('get', '/voices/{voice_id}', { path: { voice_id: voiceId } }, options);
77
62
  }
78
63
  }
79
- export class PhoneNumbers extends Resource {
64
+ export class PhoneNumbers extends PhoneNumbersGenerated {
80
65
  list(query, options) {
81
66
  return this.do('get', '/phone_numbers', { query }, options);
82
67
  }
@@ -97,7 +82,7 @@ export class PhoneNumbers extends Resource {
97
82
  return this.do('delete', '/phone_numbers/{id}', { path: { id } }, options);
98
83
  }
99
84
  }
100
- export class Audiences extends Resource {
85
+ export class Audiences extends AudiencesGenerated {
101
86
  list(query, options) {
102
87
  return this.do('get', '/audiences', { query }, options);
103
88
  }
@@ -126,7 +111,7 @@ export class Audiences extends Resource {
126
111
  return this.do('delete', '/audiences/{audience_id}/contacts/{phone}', { path: { audience_id: audienceId, phone } }, options);
127
112
  }
128
113
  }
129
- export class Deployments extends Resource {
114
+ export class Deployments extends DeploymentsGenerated {
130
115
  list(query, options) {
131
116
  return this.do('get', '/deployments', { query }, options);
132
117
  }
@@ -154,7 +139,7 @@ export class Deployments extends Resource {
154
139
  return this.do('get', '/deployments/{id}/analytics', { path: { id }, query }, options);
155
140
  }
156
141
  }
157
- export class Wallet extends Resource {
142
+ export class Wallet extends WalletGenerated {
158
143
  retrieve(options) {
159
144
  return this.do('get', '/wallet', {}, options);
160
145
  }
@@ -165,7 +150,7 @@ export class Wallet extends Resource {
165
150
  return this.pager('/wallet/transactions', offsetStrategy(), query, undefined, options);
166
151
  }
167
152
  }
168
- export class DoNotCall extends Resource {
153
+ export class DoNotCall extends DoNotCallGenerated {
169
154
  list(query, options) {
170
155
  return this.do('get', '/do_not_call', { query }, options);
171
156
  }
@@ -181,7 +166,7 @@ export class DoNotCall extends Resource {
181
166
  }
182
167
  }
183
168
  // ---------------------------------------------------------------- CRM
184
- export class Contacts extends Resource {
169
+ export class Contacts extends ContactsGenerated {
185
170
  list(query, options) {
186
171
  return this.do('get', '/contacts', { query }, options);
187
172
  }
@@ -215,7 +200,7 @@ export class Contacts extends Resource {
215
200
  }
216
201
  }
217
202
  // ---------------------------------------------------------------- Operator
218
- export class Cases extends Resource {
203
+ export class Cases extends CasesGenerated {
219
204
  list(query, options) {
220
205
  return this.do('get', '/cases', { query }, options);
221
206
  }
@@ -225,8 +210,13 @@ export class Cases extends Resource {
225
210
  retrieve(id, options) {
226
211
  return this.do('get', '/cases/{id}', { path: { id } }, options);
227
212
  }
228
- listEvents(id, options) {
229
- return this.do('get', '/cases/{id}/events', { path: { id } }, options);
213
+ /** One page of a case's events: pass the previous page's `next_after` as `after` for the next one. */
214
+ listEvents(id, query, options) {
215
+ return this.do('get', '/cases/{id}/events', { path: { id }, query }, options);
216
+ }
217
+ /** Every event of a case, oldest first, page by page (follows `next_after`). */
218
+ listAllEvents(id, query, options) {
219
+ return this.pager('/cases/{id}/events', afterStrategy('events', 'next_after'), query, { id }, options);
230
220
  }
231
221
  /** Start a case on an agent. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
232
222
  start(agentId, body, options) {
@@ -235,7 +225,7 @@ export class Cases extends Resource {
235
225
  }
236
226
  /** Statuses that are still waiting: holds (`pending`, `running`) and Operator approvals (`open`). */
237
227
  const WAITING_STATUSES = new Set(['pending', 'running', 'open', 'pending_approval']);
238
- export class Approvals extends Resource {
228
+ export class Approvals extends ApprovalsGenerated {
239
229
  list(query, options) {
240
230
  return this.do('get', '/approvals', { query }, options);
241
231
  }
@@ -291,7 +281,7 @@ function defaultPollSleep(ms, signal) {
291
281
  signal?.addEventListener('abort', () => (clearTimeout(t), reject(signal.reason)), { once: true });
292
282
  });
293
283
  }
294
- export class Agents extends Resource {
284
+ export class Agents extends AgentsGenerated {
295
285
  list(query, options) {
296
286
  return this.do('get', '/agents', { query }, options);
297
287
  }
@@ -365,7 +355,7 @@ export class ChatContacts extends Resource {
365
355
  return this.do('patch', '/chat/contacts/{id}', { path: { id }, body }, options);
366
356
  }
367
357
  }
368
- export class Chat extends Resource {
358
+ export class Chat extends ChatGenerated {
369
359
  constructor(core) {
370
360
  super(core);
371
361
  this.conversations = new ChatConversations(core);
@@ -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
- /** Routes whose writes the API may hold for approval (HTTP 202 `pending_approval`). */
146
- export type HoldableRoute = 'post /calls' | 'post /deployments' | 'post /phone_numbers' | 'post /agents/{id}/cases' | 'post /chat/conversations' | 'post /chat/conversations/{id}/messages';
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>;
@@ -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
- /** The body of every webhook delivery. */
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hirefinn/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Typed TypeScript client for the Finn public API (hirefinn.ai).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,6 +39,7 @@
39
39
  "homepage": "https://hirefinn.ai",
40
40
  "scripts": {
41
41
  "generate": "node scripts/generate.mjs",
42
+ "generate:check": "node scripts/generate.mjs --check",
42
43
  "spec:pull": "sh scripts/pull-spec.sh",
43
44
  "build": "node scripts/build.mjs",
44
45
  "typecheck": "tsc -p tsconfig.json --noEmit",