@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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The base class of every resource (hand-written in resources.ts and generated in generated/resources.ts), and the
3
+ * type shorthands their method signatures use.
4
+ */
5
+ import type { FinnCore } from './core.js';
6
+ import { Paginator, type PageStrategy } from './pagination.js';
7
+ import type { BodyOf, HttpMethod, Operation, PathsFor, QueryOf, RequestOptions, ResultOf, paths } from './types.js';
8
+ /** The query of (P, M). */
9
+ export type Q<P extends keyof paths, M extends HttpMethod> = QueryOf<Operation<P, M>>;
10
+ /** The request body of (P, M). */
11
+ export type B<P extends keyof paths, M extends HttpMethod> = BodyOf<Operation<P, M>>;
12
+ /** What a method calling (P, M) resolves to. */
13
+ export type R<P extends keyof paths, M extends HttpMethod> = ResultOf<P & string, M, Operation<P, M>>;
14
+ /** The item type of a `{ data: Item[] }` list answer, or unknown. */
15
+ export type DataItem<T> = T extends {
16
+ data?: (infer I)[] | null;
17
+ } ? I : unknown;
18
+ export type Id = string;
19
+ interface Params {
20
+ path?: Record<string, string | number>;
21
+ query?: unknown;
22
+ body?: unknown;
23
+ }
24
+ export declare abstract class Resource {
25
+ protected readonly core: FinnCore;
26
+ constructor(core: FinnCore);
27
+ protected do<M extends HttpMethod, P extends PathsFor<M>>(method: M, path: P, params?: Params, options?: RequestOptions): Promise<R<P, M>>;
28
+ protected pager<Item>(path: PathsFor<'get'>, strategy: PageStrategy<unknown, Item>, query: unknown, pathParams?: Record<string, string>, options?: RequestOptions): Paginator<Item>;
29
+ }
30
+ export {};
@@ -0,0 +1,19 @@
1
+ import { Paginator } from './pagination.js';
2
+ export class Resource {
3
+ constructor(core) {
4
+ this.core = core;
5
+ }
6
+ async do(method, path, params = {}, options) {
7
+ const res = await this.core.rawRequest({
8
+ method,
9
+ path,
10
+ pathParams: params.path,
11
+ query: params.query,
12
+ body: params.body,
13
+ }, options);
14
+ return res.data;
15
+ }
16
+ pager(path, strategy, query, pathParams, options) {
17
+ return new Paginator(async (q) => (await this.core.rawRequest({ method: 'get', path, pathParams, query: q }, options)).data, strategy, (query ?? {}));
18
+ }
19
+ }
@@ -1,27 +1,15 @@
1
1
  /**
2
- * Resource classes: one typed method per operation in the spec, grouped the way the API reference groups them.
3
- * Every method takes an optional last `options` argument (RequestOptions): idempotencyKey, org, version,
4
- * maxRetries, timeoutMs, signal, headers.
2
+ * Hand-written resource classes: the named methods, pagination helpers and approval waits. Each class extends a
3
+ * generated base (src/generated/resources.ts) that adds a method for every other operation under the same tag, so
4
+ * together they cover every operation in the spec. Every method takes an optional last `options` argument
5
+ * (RequestOptions): idempotencyKey, org, version, maxRetries, timeoutMs, signal, headers.
5
6
  */
6
7
  import type { FinnCore } from './core.js';
7
- import { Paginator, cursorStrategy } from './pagination.js';
8
- import type { ApprovalHold, BodyOf, HttpMethod, Operation, PathsFor, QueryOf, RequestOptions, ResultOf, Schemas, paths } from './types.js';
9
- type Q<P extends keyof paths, M extends HttpMethod> = QueryOf<Operation<P, M>>;
10
- type B<P extends keyof paths, M extends HttpMethod> = BodyOf<Operation<P, M>>;
11
- type R<P extends keyof paths, M extends HttpMethod> = ResultOf<P & string, M, Operation<P, M>>;
12
- type Id = string;
13
- interface Params {
14
- path?: Record<string, string | number>;
15
- query?: unknown;
16
- body?: unknown;
17
- }
18
- declare abstract class Resource {
19
- protected readonly core: FinnCore;
20
- constructor(core: FinnCore);
21
- protected do<M extends HttpMethod, P extends PathsFor<M>>(method: M, path: P, params?: Params, options?: RequestOptions): Promise<R<P, M>>;
22
- protected pager<Item>(path: PathsFor<'get'>, strategy: ReturnType<typeof cursorStrategy<Item>>, query: unknown, pathParams?: Record<string, string>, options?: RequestOptions): Paginator<Item>;
23
- }
24
- export declare class Calls extends Resource {
8
+ import { Resource, type B, type Id, type Q } from './resource.js';
9
+ import type { ApprovalHold, RequestOptions, Schemas } from './types.js';
10
+ import { AgentsGenerated, ApprovalsGenerated, AudiencesGenerated, CallsGenerated, CasesGenerated, ChatGenerated, ContactsGenerated, DeploymentsGenerated, DoNotCallGenerated, FinnsGenerated, PhoneNumbersGenerated, VoicesGenerated, WalletGenerated } from './generated/resources.js';
11
+ export { Crm, Dialer, Organization, Sales, Webhooks } from './generated/resources.js';
12
+ export declare class Calls extends CallsGenerated {
25
13
  /** Place an outbound call. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
26
14
  create(body: B<'/calls', 'post'>, options?: RequestOptions): Promise<{
27
15
  success: true;
@@ -35,7 +23,7 @@ export declare class Calls extends Resource {
35
23
  offset: number;
36
24
  }>;
37
25
  /** Every call matching the filters, page by page. */
38
- listAll(query?: Q<'/calls', 'get'>, options?: RequestOptions): Paginator<{
26
+ listAll(query?: Q<'/calls', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
39
27
  call_uuid: string;
40
28
  finn_id?: string | null;
41
29
  deployment_id?: string | null;
@@ -55,14 +43,14 @@ export declare class Calls extends Resource {
55
43
  data: import("./types.js").components["schemas"]["Call"];
56
44
  }>;
57
45
  }
58
- export declare class Finns extends Resource {
46
+ export declare class Finns extends FinnsGenerated {
59
47
  list(query?: Q<'/finns', 'get'>, options?: RequestOptions): Promise<{
60
48
  success: true;
61
49
  data: import("./types.js").components["schemas"]["Finn"][];
62
50
  limit: number;
63
51
  offset: number;
64
52
  }>;
65
- listAll(query?: Q<'/finns', 'get'>, options?: RequestOptions): Paginator<{
53
+ listAll(query?: Q<'/finns', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
66
54
  id: string;
67
55
  name: string;
68
56
  status: string;
@@ -116,7 +104,7 @@ export declare class Finns extends Resource {
116
104
  data: import("./types.js").components["schemas"]["FinnPostCallAnalysis"];
117
105
  }>;
118
106
  }
119
- export declare class Voices extends Resource {
107
+ export declare class Voices extends VoicesGenerated {
120
108
  list(query?: Q<'/voices', 'get'>, options?: RequestOptions): Promise<{
121
109
  success: true;
122
110
  data: import("./types.js").components["schemas"]["Voice"][];
@@ -124,7 +112,7 @@ export declare class Voices extends Resource {
124
112
  limit: number;
125
113
  offset: number;
126
114
  }>;
127
- listAll(query?: Q<'/voices', 'get'>, options?: RequestOptions): Paginator<{
115
+ listAll(query?: Q<'/voices', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
128
116
  voice_id: string;
129
117
  name: string | null;
130
118
  description: string;
@@ -140,14 +128,14 @@ export declare class Voices extends Resource {
140
128
  data: import("./types.js").components["schemas"]["Voice"];
141
129
  }>;
142
130
  }
143
- export declare class PhoneNumbers extends Resource {
131
+ export declare class PhoneNumbers extends PhoneNumbersGenerated {
144
132
  list(query?: Q<'/phone_numbers', 'get'>, options?: RequestOptions): Promise<{
145
133
  success: true;
146
134
  data: import("./types.js").components["schemas"]["PhoneNumber"][];
147
135
  limit: number;
148
136
  offset: number;
149
137
  }>;
150
- listAll(query?: Q<'/phone_numbers', 'get'>, options?: RequestOptions): Paginator<{
138
+ listAll(query?: Q<'/phone_numbers', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
151
139
  id: string;
152
140
  phone_number: string;
153
141
  status: string;
@@ -180,14 +168,14 @@ export declare class PhoneNumbers extends Resource {
180
168
  data: import("./types.js").components["schemas"]["ReleasedPhoneNumber"];
181
169
  }>;
182
170
  }
183
- export declare class Audiences extends Resource {
171
+ export declare class Audiences extends AudiencesGenerated {
184
172
  list(query?: Q<'/audiences', 'get'>, options?: RequestOptions): Promise<{
185
173
  success: true;
186
174
  data: import("./types.js").components["schemas"]["Audience"][];
187
175
  limit: number;
188
176
  offset: number;
189
177
  }>;
190
- listAll(query?: Q<'/audiences', 'get'>, options?: RequestOptions): Paginator<{
178
+ listAll(query?: Q<'/audiences', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
191
179
  id: string;
192
180
  name: string;
193
181
  contact_count: number;
@@ -217,7 +205,7 @@ export declare class Audiences extends Resource {
217
205
  limit: number;
218
206
  offset: number;
219
207
  }>;
220
- listAllContacts(audienceId: Id, query?: Q<'/audiences/{audience_id}/contacts', 'get'>, options?: RequestOptions): Paginator<{
208
+ listAllContacts(audienceId: Id, query?: Q<'/audiences/{audience_id}/contacts', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
221
209
  name?: string;
222
210
  phone_number?: string;
223
211
  country_code?: string;
@@ -236,14 +224,14 @@ export declare class Audiences extends Resource {
236
224
  contacts_removed: number;
237
225
  }>;
238
226
  }
239
- export declare class Deployments extends Resource {
227
+ export declare class Deployments extends DeploymentsGenerated {
240
228
  list(query?: Q<'/deployments', 'get'>, options?: RequestOptions): Promise<{
241
229
  success: true;
242
230
  data: import("./types.js").components["schemas"]["Deployment"][];
243
231
  limit: number;
244
232
  offset: number;
245
233
  }>;
246
- listAll(query?: Q<'/deployments', 'get'>, options?: RequestOptions): Paginator<{
234
+ listAll(query?: Q<'/deployments', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
247
235
  id: string;
248
236
  finn_id?: string | null;
249
237
  audience_id?: string | null;
@@ -287,7 +275,7 @@ export declare class Deployments extends Resource {
287
275
  data: import("./types.js").components["schemas"]["DeploymentAnalytics"];
288
276
  }>;
289
277
  }
290
- export declare class Wallet extends Resource {
278
+ export declare class Wallet extends WalletGenerated {
291
279
  retrieve(options?: RequestOptions): Promise<{
292
280
  success: true;
293
281
  data: import("./types.js").components["schemas"]["Wallet"];
@@ -298,7 +286,7 @@ export declare class Wallet extends Resource {
298
286
  limit: number;
299
287
  offset: number;
300
288
  }>;
301
- listAllTransactions(query?: Q<'/wallet/transactions', 'get'>, options?: RequestOptions): Paginator<{
289
+ listAllTransactions(query?: Q<'/wallet/transactions', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
302
290
  id: string;
303
291
  type: string;
304
292
  credits_delta: number;
@@ -307,7 +295,7 @@ export declare class Wallet extends Resource {
307
295
  created_at: string;
308
296
  }, unknown>;
309
297
  }
310
- export declare class DoNotCall extends Resource {
298
+ export declare class DoNotCall extends DoNotCallGenerated {
311
299
  list(query?: Q<'/do_not_call', 'get'>, options?: RequestOptions): Promise<{
312
300
  success: true;
313
301
  data: import("./types.js").components["schemas"]["DoNotCallEntry"][];
@@ -315,7 +303,7 @@ export declare class DoNotCall extends Resource {
315
303
  limit: number;
316
304
  offset: number;
317
305
  }>;
318
- listAll(query?: Q<'/do_not_call', 'get'>, options?: RequestOptions): Paginator<{
306
+ listAll(query?: Q<'/do_not_call', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
319
307
  phone_key: string;
320
308
  phone_number: string;
321
309
  sources: ("manual" | "crm_stage" | "rep_dialer" | "call_opt_out" | "chat_opt_out" | "import" | "api" | "operator" | "sales_ai")[];
@@ -337,7 +325,7 @@ export declare class DoNotCall extends Resource {
337
325
  removed_sources: string[];
338
326
  }>;
339
327
  }
340
- export declare class Contacts extends Resource {
328
+ export declare class Contacts extends ContactsGenerated {
341
329
  list(query?: Q<'/contacts', 'get'>, options?: RequestOptions): Promise<{
342
330
  contacts: import("./types.js").components["schemas"]["Record"][];
343
331
  totalCount: number;
@@ -345,7 +333,7 @@ export declare class Contacts extends Resource {
345
333
  pageSize: number;
346
334
  totalPages: number;
347
335
  }>;
348
- listAll(query?: Q<'/contacts', 'get'>, options?: RequestOptions): Paginator<{
336
+ listAll(query?: Q<'/contacts', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
349
337
  id: string;
350
338
  phone: string;
351
339
  phoneKey?: string;
@@ -401,7 +389,7 @@ export declare class Contacts extends Resource {
401
389
  [key: string]: number;
402
390
  };
403
391
  }>;
404
- timelineAll(id: Id, query?: Q<'/contacts/{id}/timeline', 'get'>, options?: RequestOptions): Paginator<{
392
+ timelineAll(id: Id, query?: Q<'/contacts/{id}/timeline', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
405
393
  id: string;
406
394
  kind: "call" | "chat" | "message" | "operator" | "note" | "form" | "change" | "file" | "view";
407
395
  type?: string;
@@ -426,12 +414,12 @@ export declare class Contacts extends Resource {
426
414
  fields: import("./types.js").components["schemas"]["FieldDefinition"][];
427
415
  }>;
428
416
  }
429
- export declare class Cases extends Resource {
417
+ export declare class Cases extends CasesGenerated {
430
418
  list(query?: Q<'/cases', 'get'>, options?: RequestOptions): Promise<{
431
419
  cases: import("./types.js").components["schemas"]["CaseSummary"][];
432
420
  next_before: string | null;
433
421
  }>;
434
- listAll(query?: Q<'/cases', 'get'>, options?: RequestOptions): Paginator<{
422
+ listAll(query?: Q<'/cases', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
435
423
  id: string;
436
424
  agent_id: string;
437
425
  agent_name: string;
@@ -510,12 +498,12 @@ export interface WaitForApprovalOptions {
510
498
  /** Replaces the wait between polls (for tests). */
511
499
  sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
512
500
  }
513
- export declare class Approvals extends Resource {
501
+ export declare class Approvals extends ApprovalsGenerated {
514
502
  list(query?: Q<'/approvals', 'get'>, options?: RequestOptions): Promise<{
515
- approvals: import("./types.js").components["schemas"]["Approval"][];
503
+ approvals: (import("./types.js").components["schemas"]["Approval"] | import("./types.js").components["schemas"]["ApiHold"])[];
516
504
  next_cursor: string | null;
517
505
  }>;
518
- listAll(query?: Q<'/approvals', 'get'>, options?: RequestOptions): Paginator<{
506
+ listAll(query?: Q<'/approvals', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
519
507
  id: string;
520
508
  case_id: string;
521
509
  case_title?: string | null;
@@ -648,13 +636,13 @@ export declare class Approvals extends Resource {
648
636
  */
649
637
  wait(id: Id, opts?: WaitForApprovalOptions): Promise<ApprovalHold | Schemas['Approval']>;
650
638
  }
651
- export declare class Agents extends Resource {
639
+ export declare class Agents extends AgentsGenerated {
652
640
  list(query?: Q<'/agents', 'get'>, options?: RequestOptions): Promise<{
653
641
  data: import("./types.js").components["schemas"]["AgentSummary"][];
654
642
  next_cursor: string | null;
655
643
  has_more: boolean;
656
644
  }>;
657
- listAll(query?: Q<'/agents', 'get'>, options?: RequestOptions): Paginator<{
645
+ listAll(query?: Q<'/agents', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
658
646
  id: string;
659
647
  name: string;
660
648
  status: "draft" | "live" | "paused" | "archived";
@@ -785,7 +773,7 @@ export declare class ChatConversations extends Resource {
785
773
  next_cursor: string | null;
786
774
  has_more: boolean;
787
775
  }>;
788
- listAll(query?: Q<'/chat/conversations', 'get'>, options?: RequestOptions): Paginator<ChatItem, unknown>;
776
+ listAll(query?: Q<'/chat/conversations', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<ChatItem, unknown>;
789
777
  /** Start a conversation (sends the first message). Gets an automatic Idempotency-Key (the API requires one). May answer `pending_approval`. */
790
778
  start(body: B<'/chat/conversations', 'post'>, options?: RequestOptions): Promise<{
791
779
  [key: string]: unknown;
@@ -806,11 +794,17 @@ export declare class ChatConversations extends Resource {
806
794
  next_cursor: string | null;
807
795
  has_more: boolean;
808
796
  }>;
809
- listAllMessages(id: Id, query?: Q<'/chat/conversations/{id}/messages', 'get'>, options?: RequestOptions): Paginator<ChatItem, unknown>;
797
+ listAllMessages(id: Id, query?: Q<'/chat/conversations/{id}/messages', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<ChatItem, unknown>;
810
798
  /** Send a message. Gets an automatic Idempotency-Key (the API requires one). May answer `pending_approval`. */
811
- send(id: Id, body: B<'/chat/conversations/{id}/messages', 'post'>, options?: RequestOptions): Promise<{
799
+ send(id: Id, body: B<'/chat/conversations/{id}/messages', 'post'>, options?: RequestOptions): Promise<({
800
+ message?: {
801
+ [key: string]: unknown;
802
+ };
803
+ ai_paused?: boolean;
804
+ notice?: string;
805
+ } & {
812
806
  [key: string]: unknown;
813
- } | import("./types.js").PendingApproval>;
807
+ }) | import("./types.js").PendingApproval>;
814
808
  }
815
809
  export declare class ChatContacts extends Resource {
816
810
  list(query?: Q<'/chat/contacts', 'get'>, options?: RequestOptions): Promise<{
@@ -822,7 +816,7 @@ export declare class ChatContacts extends Resource {
822
816
  } & {
823
817
  total?: number | null;
824
818
  }>;
825
- listAll(query?: Q<'/chat/contacts', 'get'>, options?: RequestOptions): Paginator<ChatItem, unknown>;
819
+ listAll(query?: Q<'/chat/contacts', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<ChatItem, unknown>;
826
820
  retrieve(id: Id, options?: RequestOptions): Promise<{
827
821
  [key: string]: unknown;
828
822
  }>;
@@ -830,7 +824,7 @@ export declare class ChatContacts extends Resource {
830
824
  [key: string]: unknown;
831
825
  }>;
832
826
  }
833
- export declare class Chat extends Resource {
827
+ export declare class Chat extends ChatGenerated {
834
828
  readonly conversations: ChatConversations;
835
829
  readonly contacts: ChatContacts;
836
830
  constructor(core: FinnCore);
@@ -842,4 +836,3 @@ export declare class Chat extends Resource {
842
836
  has_more: boolean;
843
837
  }>;
844
838
  }
845
- export {};
@@ -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 { 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
  }
@@ -235,7 +220,7 @@ export class Cases extends Resource {
235
220
  }
236
221
  /** Statuses that are still waiting: holds (`pending`, `running`) and Operator approvals (`open`). */
237
222
  const WAITING_STATUSES = new Set(['pending', 'running', 'open', 'pending_approval']);
238
- export class Approvals extends Resource {
223
+ export class Approvals extends ApprovalsGenerated {
239
224
  list(query, options) {
240
225
  return this.do('get', '/approvals', { query }, options);
241
226
  }
@@ -291,7 +276,7 @@ function defaultPollSleep(ms, signal) {
291
276
  signal?.addEventListener('abort', () => (clearTimeout(t), reject(signal.reason)), { once: true });
292
277
  });
293
278
  }
294
- export class Agents extends Resource {
279
+ export class Agents extends AgentsGenerated {
295
280
  list(query, options) {
296
281
  return this.do('get', '/agents', { query }, options);
297
282
  }
@@ -365,7 +350,7 @@ export class ChatContacts extends Resource {
365
350
  return this.do('patch', '/chat/contacts/{id}', { path: { id }, body }, options);
366
351
  }
367
352
  }
368
- export class Chat extends Resource {
353
+ export class Chat extends ChatGenerated {
369
354
  constructor(core) {
370
355
  super(core);
371
356
  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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hirefinn/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.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",