@hirefinn/sdk 0.3.0 → 0.5.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.
@@ -21,105 +21,105 @@ exports.CallsGenerated = CallsGenerated;
21
21
  class FinnsGenerated extends resource_js_1.Resource {
22
22
  /**
23
23
  * Draft a Finn with AI.
24
- * `POST /finns/generate`, operationId `generateFinn`.
24
+ * `POST /finns/generate`, operationId `generateFinn`, scope `finn:write`.
25
25
  */
26
26
  generate(body, options) {
27
27
  return this.do('post', '/finns/generate', { body }, options);
28
28
  }
29
29
  /**
30
30
  * Read a Finn's call flow.
31
- * `GET /finns/{finn_id}/flow`, operationId `getFinnFlow`.
31
+ * `GET /finns/{finn_id}/flow`, operationId `getFinnFlow`, scope `finn:read`.
32
32
  */
33
33
  getFlow(finnId, options) {
34
34
  return this.do('get', '/finns/{finn_id}/flow', { path: { finn_id: finnId } }, options);
35
35
  }
36
36
  /**
37
37
  * Turn a Finn's call flow on.
38
- * `POST /finns/{finn_id}/flow/enable`, operationId `enableFinnFlow`.
38
+ * `POST /finns/{finn_id}/flow/enable`, operationId `enableFinnFlow`, scope `finn:write`.
39
39
  */
40
40
  enableFlow(finnId, options) {
41
41
  return this.do('post', '/finns/{finn_id}/flow/enable', { path: { finn_id: finnId } }, options);
42
42
  }
43
43
  /**
44
44
  * Turn a Finn's call flow off.
45
- * `POST /finns/{finn_id}/flow/disable`, operationId `disableFinnFlow`.
45
+ * `POST /finns/{finn_id}/flow/disable`, operationId `disableFinnFlow`, scope `finn:write`.
46
46
  */
47
47
  disableFlow(finnId, options) {
48
48
  return this.do('post', '/finns/{finn_id}/flow/disable', { path: { finn_id: finnId } }, options);
49
49
  }
50
50
  /**
51
51
  * Read a Finn's settings.
52
- * `GET /finns/{finn_id}/settings`, operationId `getFinnSettings`.
52
+ * `GET /finns/{finn_id}/settings`, operationId `getFinnSettings`, scope `finn:read`.
53
53
  */
54
54
  getSettings(finnId, options) {
55
55
  return this.do('get', '/finns/{finn_id}/settings', { path: { finn_id: finnId } }, options);
56
56
  }
57
57
  /**
58
58
  * Read a Finn's variables.
59
- * `GET /finns/{finn_id}/variables`, operationId `getFinnVariables`.
59
+ * `GET /finns/{finn_id}/variables`, operationId `getFinnVariables`, scope `finn:read`.
60
60
  */
61
61
  getVariables(finnId, options) {
62
62
  return this.do('get', '/finns/{finn_id}/variables', { path: { finn_id: finnId } }, options);
63
63
  }
64
64
  /**
65
65
  * Edit a Finn's variables.
66
- * `PATCH /finns/{finn_id}/variables`, operationId `updateFinnVariables`.
66
+ * `PATCH /finns/{finn_id}/variables`, operationId `updateFinnVariables`, scope `finn:write`.
67
67
  */
68
68
  updateVariables(finnId, body, options) {
69
69
  return this.do('patch', '/finns/{finn_id}/variables', { path: { finn_id: finnId }, body }, options);
70
70
  }
71
71
  /**
72
72
  * Edit a Finn's agent handbook.
73
- * `PATCH /finns/{finn_id}/handbook`, operationId `updateFinnHandbook`.
73
+ * `PATCH /finns/{finn_id}/handbook`, operationId `updateFinnHandbook`, scope `finn:write`.
74
74
  */
75
75
  updateHandbook(finnId, body, options) {
76
76
  return this.do('patch', '/finns/{finn_id}/handbook', { path: { finn_id: finnId }, body }, options);
77
77
  }
78
78
  /**
79
79
  * Edit a Finn's speech settings.
80
- * `PATCH /finns/{finn_id}/speech_settings`, operationId `updateFinnSpeechSettings`.
80
+ * `PATCH /finns/{finn_id}/speech_settings`, operationId `updateFinnSpeechSettings`, scope `finn:write`.
81
81
  */
82
82
  updateSpeechSettings(finnId, body, options) {
83
83
  return this.do('patch', '/finns/{finn_id}/speech_settings', { path: { finn_id: finnId }, body }, options);
84
84
  }
85
85
  /**
86
86
  * Edit a draft Finn.
87
- * `PATCH /finns/{finn_id}/draft`, operationId `updateFinnDraft`.
87
+ * `PATCH /finns/{finn_id}/draft`, operationId `updateFinnDraft`, scope `finn:write`.
88
88
  */
89
89
  updateDraft(finnId, body, options) {
90
90
  return this.do('patch', '/finns/{finn_id}/draft', { path: { finn_id: finnId }, body }, options);
91
91
  }
92
92
  /**
93
93
  * Copy a Finn.
94
- * `POST /finns/{finn_id}/duplicate`, operationId `duplicateFinn`.
94
+ * `POST /finns/{finn_id}/duplicate`, operationId `duplicateFinn`, scope `finn:write`.
95
95
  */
96
96
  duplicate(finnId, body, options) {
97
97
  return this.do('post', '/finns/{finn_id}/duplicate', { path: { finn_id: finnId }, body }, options);
98
98
  }
99
99
  /**
100
100
  * Read a Finn's share link.
101
- * `GET /finns/{finn_id}/share_link`, operationId `getFinnShareLink`.
101
+ * `GET /finns/{finn_id}/share_link`, operationId `getFinnShareLink`, scope `finn:read`.
102
102
  */
103
103
  getShareLink(finnId, options) {
104
104
  return this.do('get', '/finns/{finn_id}/share_link', { path: { finn_id: finnId } }, options);
105
105
  }
106
106
  /**
107
107
  * Get or make a Finn's share link.
108
- * `POST /finns/{finn_id}/share_link`, operationId `createFinnShareLink`.
108
+ * `POST /finns/{finn_id}/share_link`, operationId `createFinnShareLink`, scope `finn:write`.
109
109
  */
110
110
  createShareLink(finnId, options) {
111
111
  return this.do('post', '/finns/{finn_id}/share_link', { path: { finn_id: finnId } }, options);
112
112
  }
113
113
  /**
114
114
  * A Finn's call stats.
115
- * `GET /finns/{finn_id}/stats`, operationId `getFinnStats`.
115
+ * `GET /finns/{finn_id}/stats`, operationId `getFinnStats`, scope `finn:read`.
116
116
  */
117
117
  getStats(finnId, query, options) {
118
118
  return this.do('get', '/finns/{finn_id}/stats', { path: { finn_id: finnId }, query }, options);
119
119
  }
120
120
  /**
121
121
  * Summarize a Finn's call outcomes.
122
- * `GET /finns/{finn_id}/outcomes`, operationId `getFinnOutcomes`.
122
+ * `GET /finns/{finn_id}/outcomes`, operationId `getFinnOutcomes`, scope `finn:read`.
123
123
  */
124
124
  getOutcomes(finnId, query, options) {
125
125
  return this.do('get', '/finns/{finn_id}/outcomes', { path: { finn_id: finnId }, query }, options);
@@ -184,12 +184,41 @@ exports.ApprovalsGenerated = ApprovalsGenerated;
184
184
  * Generated methods for the Agents tag; `Agents` in src/resources.ts adds the hand-written ones.
185
185
  */
186
186
  class AgentsGenerated extends resource_js_1.Resource {
187
+ /**
188
+ * Archive an agent.
189
+ * `POST /agents/{id}/archive`, operationId `archiveAgent`, scope `operator:build`.
190
+ */
191
+ archive(id, options) {
192
+ return this.do('post', '/agents/{id}/archive', { path: { id } }, options);
193
+ }
187
194
  }
188
195
  exports.AgentsGenerated = AgentsGenerated;
189
196
  /**
190
197
  * Generated methods for the Chat tag; `Chat` in src/resources.ts adds the hand-written ones.
191
198
  */
192
199
  class ChatGenerated extends resource_js_1.Resource {
200
+ /**
201
+ * Get a chat agent's settings.
202
+ * `GET /chat/agents/{agent_id}`, operationId `getChatAgent`, scope `chat:read`.
203
+ */
204
+ getAgent(agentId, options) {
205
+ return this.do('get', '/chat/agents/{agent_id}', { path: { agent_id: agentId } }, options);
206
+ }
207
+ /**
208
+ * Change a chat agent's settings.
209
+ * `PATCH /chat/agents/{agent_id}`, operationId `updateChatAgent`, scope `chat:write`.
210
+ * May answer `pending_approval` (see isPendingApproval).
211
+ */
212
+ updateAgent(agentId, body, options) {
213
+ return this.do('patch', '/chat/agents/{agent_id}', { path: { agent_id: agentId }, body }, options);
214
+ }
215
+ /**
216
+ * Test a chat agent.
217
+ * `POST /chat/agents/{agent_id}/test_turn`, operationId `testChatAgent`, scope `chat:write`.
218
+ */
219
+ testAgent(agentId, body, options) {
220
+ return this.do('post', '/chat/agents/{agent_id}/test_turn', { path: { agent_id: agentId }, body }, options);
221
+ }
193
222
  }
194
223
  exports.ChatGenerated = ChatGenerated;
195
224
  /**
@@ -544,6 +573,27 @@ class Dialer extends resource_js_1.Resource {
544
573
  getLeadBrief(id, query, options) {
545
574
  return this.do('get', '/dialer/leads/{id}/brief', { path: { id }, query }, options);
546
575
  }
576
+ /**
577
+ * Mark a dialer follow-up done.
578
+ * `POST /dialer/follow-ups/{call_id}/done`, operationId `markDialerFollowUpDone`, scope `dialer:write`.
579
+ */
580
+ markFollowUpDone(callId, options) {
581
+ return this.do('post', '/dialer/follow-ups/{call_id}/done', { path: { call_id: callId } }, options);
582
+ }
583
+ /**
584
+ * Set a finished call's disposition.
585
+ * `PUT /dialer/calls/{call_id}/disposition`, operationId `setDialerCallDisposition`, scope `dialer:write`.
586
+ */
587
+ setCallDisposition(callId, body, options) {
588
+ return this.do('put', '/dialer/calls/{call_id}/disposition', { path: { call_id: callId }, body }, options);
589
+ }
590
+ /**
591
+ * Add a note to a finished call.
592
+ * `POST /dialer/calls/{call_id}/notes`, operationId `addDialerCallNote`, scope `dialer:write`.
593
+ */
594
+ addCallNote(callId, body, options) {
595
+ return this.do('post', '/dialer/calls/{call_id}/notes', { path: { call_id: callId }, body }, options);
596
+ }
547
597
  }
548
598
  exports.Dialer = Dialer;
549
599
  /**
@@ -601,12 +651,33 @@ class Webhooks extends resource_js_1.Resource {
601
651
  return this.pager('/webhook_endpoints/{id}/deliveries', (0, pagination_js_1.cursorStrategy)('data'), query, { id }, options);
602
652
  }
603
653
  /**
604
- * List webhook events.
654
+ * List webhook event types.
605
655
  * `GET /events`, operationId `listEventTypes`, scope `admin:webhooks`.
606
656
  */
607
657
  listEventTypes(options) {
608
658
  return this.do('get', '/events', {}, options);
609
659
  }
660
+ /**
661
+ * Send a test event.
662
+ * `POST /webhook_endpoints/{id}/test`, operationId `testWebhookEndpoint`, scope `admin:webhooks`.
663
+ */
664
+ testEndpoint(id, options) {
665
+ return this.do('post', '/webhook_endpoints/{id}/test', { path: { id } }, options);
666
+ }
667
+ /**
668
+ * Redeliver an event.
669
+ * `POST /webhook_endpoints/{id}/deliveries/{delivery_id}/redeliver`, operationId `redeliverWebhookDelivery`, scope `admin:webhooks`.
670
+ */
671
+ redeliverDelivery(id, deliveryId, options) {
672
+ return this.do('post', '/webhook_endpoints/{id}/deliveries/{delivery_id}/redeliver', { path: { id, delivery_id: deliveryId } }, options);
673
+ }
674
+ /**
675
+ * Rotate the signing secret.
676
+ * `POST /webhook_endpoints/{id}/rotate_secret`, operationId `rotateWebhookEndpointSecret`, scope `admin:webhooks`.
677
+ */
678
+ rotateEndpointSecret(id, options) {
679
+ return this.do('post', '/webhook_endpoints/{id}/rotate_secret', { path: { id } }, options);
680
+ }
610
681
  }
611
682
  exports.Webhooks = Webhooks;
612
683
  /**
@@ -653,6 +724,13 @@ class Organization extends resource_js_1.Resource {
653
724
  listAllApiKeys(query, options) {
654
725
  return this.pager('/organization/api_keys', (0, pagination_js_1.cursorStrategy)('data'), query, undefined, options);
655
726
  }
727
+ /**
728
+ * Get API usage by key and day.
729
+ * `GET /usage`, operationId `getUsage`, scope `admin:read`.
730
+ */
731
+ getUsage(query, options) {
732
+ return this.do('get', '/usage', { query }, options);
733
+ }
656
734
  }
657
735
  exports.Organization = Organization;
658
736
  /**
@@ -688,6 +766,7 @@ class Sales extends resource_js_1.Resource {
688
766
  /**
689
767
  * Run a play.
690
768
  * `POST /sales/plays/{slug}/run`, operationId `runSalesPlay`, scope `sales:write`.
769
+ * May answer `pending_approval` (see isPendingApproval).
691
770
  * @experimental The Sales API is switched off for every organization, so these calls answer an error until it is switched on for yours. Names and shapes may change without a major version.
692
771
  */
693
772
  runPlay(slug, options) {
@@ -1,13 +1,13 @@
1
1
  export { Finn } from './client.js';
2
2
  export { Finn as default } from './client.js';
3
- export { FinnCore, DEFAULT_BASE_URL, SDK_VERSION, AUTO_IDEMPOTENCY_ROUTES, IDEMPOTENT_WRITE_ROUTES, honoursIdempotencyKey, idempotencyKey, } from './core.js';
3
+ export { FinnCore, DEFAULT_BASE_URL, SDK_VERSION, DEFAULT_FINN_VERSION, AUTO_IDEMPOTENCY_ROUTES, IDEMPOTENT_WRITE_ROUTES, honoursIdempotencyKey, idempotencyKey, DEFAULT_MAX_RETRY_WAIT_MS, } from './core.js';
4
4
  export { verifyWebhook, signWebhookPayload, parseSignatureHeader, timingSafeEqual, FinnWebhookVerificationError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, } from './webhooks.js';
5
5
  export type { VerifyWebhookOptions, WebhookEvent } from './webhooks.js';
6
6
  export type { FinnOptions, RawRequest } from './core.js';
7
7
  export { FinnSdkError, FinnError, FinnConnectionError, FinnTimeoutError, FinnApprovalTimeoutError, codeForStatus, parseRetryAfterSeconds, } from './errors.js';
8
8
  export type { FinnErrorCode, FinnFieldError } from './errors.js';
9
9
  export { isPendingApproval } from './approval.js';
10
- export { Paginator, cursorStrategy, offsetStrategy, pageStrategy, beforeStrategy } from './pagination.js';
10
+ export { Paginator, cursorStrategy, offsetStrategy, pageStrategy, beforeStrategy, afterStrategy } from './pagination.js';
11
11
  export type { PageStrategy } from './pagination.js';
12
12
  export * from './resources.js';
13
13
  export type { ApprovalHold, BodyOf, FinnResponse, HoldAction, HoldStatus, HoldableRoute, HttpMethod, Operation, PathParamsOf, PathsFor, PendingApproval, QueryOf, RequestOptions, RequestParams, ResponseOf, ResultOf, Schemas, components, operations, paths, } from './types.js';
package/dist/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.beforeStrategy = exports.pageStrategy = exports.offsetStrategy = exports.cursorStrategy = exports.Paginator = exports.isPendingApproval = exports.parseRetryAfterSeconds = exports.codeForStatus = exports.FinnApprovalTimeoutError = exports.FinnTimeoutError = exports.FinnConnectionError = exports.FinnError = exports.FinnSdkError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.FinnWebhookVerificationError = exports.timingSafeEqual = exports.parseSignatureHeader = exports.signWebhookPayload = exports.verifyWebhook = exports.idempotencyKey = exports.honoursIdempotencyKey = exports.IDEMPOTENT_WRITE_ROUTES = exports.AUTO_IDEMPOTENCY_ROUTES = exports.SDK_VERSION = exports.DEFAULT_BASE_URL = exports.FinnCore = exports.default = exports.Finn = void 0;
17
+ exports.afterStrategy = exports.beforeStrategy = exports.pageStrategy = exports.offsetStrategy = exports.cursorStrategy = exports.Paginator = exports.isPendingApproval = exports.parseRetryAfterSeconds = exports.codeForStatus = exports.FinnApprovalTimeoutError = exports.FinnTimeoutError = exports.FinnConnectionError = exports.FinnError = exports.FinnSdkError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.FinnWebhookVerificationError = exports.timingSafeEqual = exports.parseSignatureHeader = exports.signWebhookPayload = exports.verifyWebhook = exports.DEFAULT_MAX_RETRY_WAIT_MS = exports.idempotencyKey = exports.honoursIdempotencyKey = exports.IDEMPOTENT_WRITE_ROUTES = exports.AUTO_IDEMPOTENCY_ROUTES = exports.DEFAULT_FINN_VERSION = exports.SDK_VERSION = exports.DEFAULT_BASE_URL = exports.FinnCore = exports.default = exports.Finn = void 0;
18
18
  var client_js_1 = require("./client.js");
19
19
  Object.defineProperty(exports, "Finn", { enumerable: true, get: function () { return client_js_1.Finn; } });
20
20
  var client_js_2 = require("./client.js");
@@ -23,10 +23,12 @@ var core_js_1 = require("./core.js");
23
23
  Object.defineProperty(exports, "FinnCore", { enumerable: true, get: function () { return core_js_1.FinnCore; } });
24
24
  Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return core_js_1.DEFAULT_BASE_URL; } });
25
25
  Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return core_js_1.SDK_VERSION; } });
26
+ Object.defineProperty(exports, "DEFAULT_FINN_VERSION", { enumerable: true, get: function () { return core_js_1.DEFAULT_FINN_VERSION; } });
26
27
  Object.defineProperty(exports, "AUTO_IDEMPOTENCY_ROUTES", { enumerable: true, get: function () { return core_js_1.AUTO_IDEMPOTENCY_ROUTES; } });
27
28
  Object.defineProperty(exports, "IDEMPOTENT_WRITE_ROUTES", { enumerable: true, get: function () { return core_js_1.IDEMPOTENT_WRITE_ROUTES; } });
28
29
  Object.defineProperty(exports, "honoursIdempotencyKey", { enumerable: true, get: function () { return core_js_1.honoursIdempotencyKey; } });
29
30
  Object.defineProperty(exports, "idempotencyKey", { enumerable: true, get: function () { return core_js_1.idempotencyKey; } });
31
+ Object.defineProperty(exports, "DEFAULT_MAX_RETRY_WAIT_MS", { enumerable: true, get: function () { return core_js_1.DEFAULT_MAX_RETRY_WAIT_MS; } });
30
32
  var webhooks_js_1 = require("./webhooks.js");
31
33
  Object.defineProperty(exports, "verifyWebhook", { enumerable: true, get: function () { return webhooks_js_1.verifyWebhook; } });
32
34
  Object.defineProperty(exports, "signWebhookPayload", { enumerable: true, get: function () { return webhooks_js_1.signWebhookPayload; } });
@@ -52,4 +54,5 @@ Object.defineProperty(exports, "cursorStrategy", { enumerable: true, get: functi
52
54
  Object.defineProperty(exports, "offsetStrategy", { enumerable: true, get: function () { return pagination_js_1.offsetStrategy; } });
53
55
  Object.defineProperty(exports, "pageStrategy", { enumerable: true, get: function () { return pagination_js_1.pageStrategy; } });
54
56
  Object.defineProperty(exports, "beforeStrategy", { enumerable: true, get: function () { return pagination_js_1.beforeStrategy; } });
57
+ Object.defineProperty(exports, "afterStrategy", { enumerable: true, get: function () { return pagination_js_1.afterStrategy; } });
55
58
  __exportStar(require("./resources.js"), exports);
@@ -5,6 +5,7 @@
5
5
  * - offset (older voice lists: calls, finns, audiences, ...): `?limit=&offset=` → `{ data, limit, offset, total? }`
6
6
  * - page (contacts): `?page=&page_size=` → `{ contacts, page, totalPages }`
7
7
  * - before (cases, timeline): `?before=` → `{ cases, next_before }` or `{ items, next }`
8
+ * - after (case events): `?after=&limit=` → `{ events, next_after }`
8
9
  *
9
10
  * for await (const call of finn.calls.listAll({ status: 'completed' })) { ... }
10
11
  * for await (const page of finn.calls.listAll().pages()) { ... }
@@ -33,4 +34,6 @@ export declare function offsetStrategy<Item>(key?: string): PageStrategy<unknown
33
34
  export declare function pageStrategy<Item>(key: string): PageStrategy<unknown, Item>;
34
35
  /** `?before=` lists answering `{ [key], [nextKey] }`. */
35
36
  export declare function beforeStrategy<Item>(key: string, nextKey: string): PageStrategy<unknown, Item>;
37
+ /** `?after=` lists answering `{ [key], [nextKey] }`, where `nextKey` is the last sequence number on the page. */
38
+ export declare function afterStrategy<Item>(key: string, nextKey: string): PageStrategy<unknown, Item>;
36
39
  export {};
@@ -6,6 +6,7 @@
6
6
  * - offset (older voice lists: calls, finns, audiences, ...): `?limit=&offset=` → `{ data, limit, offset, total? }`
7
7
  * - page (contacts): `?page=&page_size=` → `{ contacts, page, totalPages }`
8
8
  * - before (cases, timeline): `?before=` → `{ cases, next_before }` or `{ items, next }`
9
+ * - after (case events): `?after=&limit=` → `{ events, next_after }`
9
10
  *
10
11
  * for await (const call of finn.calls.listAll({ status: 'completed' })) { ... }
11
12
  * for await (const page of finn.calls.listAll().pages()) { ... }
@@ -28,6 +29,7 @@ exports.cursorStrategy = cursorStrategy;
28
29
  exports.offsetStrategy = offsetStrategy;
29
30
  exports.pageStrategy = pageStrategy;
30
31
  exports.beforeStrategy = beforeStrategy;
32
+ exports.afterStrategy = afterStrategy;
31
33
  class Paginator {
32
34
  constructor(fetchPage, strategy, query = {}) {
33
35
  _Paginator_fetchPage.set(this, void 0);
@@ -43,8 +45,9 @@ class Paginator {
43
45
  while (query) {
44
46
  const res = await __classPrivateFieldGet(this, _Paginator_fetchPage, "f").call(this, query);
45
47
  yield res;
46
- const count = __classPrivateFieldGet(this, _Paginator_strategy, "f").items(res).length;
47
- query = count === 0 ? null : __classPrivateFieldGet(this, _Paginator_strategy, "f").next(res, query, count);
48
+ // An empty page ends the list only when the strategy finds no next page: the API filters some lists after
49
+ // paging (hidden cases, chat notes), so a page can come back empty with a cursor that still moves on.
50
+ query = __classPrivateFieldGet(this, _Paginator_strategy, "f").next(res, query, __classPrivateFieldGet(this, _Paginator_strategy, "f").items(res).length);
48
51
  }
49
52
  }
50
53
  async *[(_Paginator_fetchPage = new WeakMap(), _Paginator_strategy = new WeakMap(), _Paginator_query = new WeakMap(), Symbol.asyncIterator)]() {
@@ -74,7 +77,7 @@ function cursorStrategy(key = 'data') {
74
77
  next: (res, query) => {
75
78
  const r = rec(res);
76
79
  const cursor = r.next_cursor;
77
- if (r.has_more === false || typeof cursor !== 'string' || cursor === '')
80
+ if (r.has_more === false || typeof cursor !== 'string' || cursor === '' || cursor === query.cursor)
78
81
  return null;
79
82
  return { ...query, cursor };
80
83
  },
@@ -85,6 +88,8 @@ function offsetStrategy(key = 'data') {
85
88
  return {
86
89
  items: (res) => arr(rec(res)[key]),
87
90
  next: (res, query, count) => {
91
+ if (count === 0)
92
+ return null;
88
93
  const r = rec(res);
89
94
  const offset = typeof r.offset === 'number' ? r.offset : Number(query.offset ?? 0);
90
95
  const limit = typeof r.limit === 'number' ? r.limit : Number(query.limit ?? count);
@@ -101,7 +106,9 @@ function offsetStrategy(key = 'data') {
101
106
  function pageStrategy(key) {
102
107
  return {
103
108
  items: (res) => arr(rec(res)[key]),
104
- next: (res, query) => {
109
+ next: (res, query, count) => {
110
+ if (count === 0)
111
+ return null;
105
112
  const r = rec(res);
106
113
  const page = typeof r.page === 'number' ? r.page : Number(query.page ?? 1);
107
114
  if (typeof r.totalPages === 'number' && page >= r.totalPages)
@@ -116,9 +123,23 @@ function beforeStrategy(key, nextKey) {
116
123
  items: (res) => arr(rec(res)[key]),
117
124
  next: (res, query) => {
118
125
  const next = rec(res)[nextKey];
119
- if (next === null || next === undefined || next === '')
126
+ if (next === null || next === undefined || next === '' || String(next) === String(query.before ?? ''))
120
127
  return null;
121
128
  return { ...query, before: next };
122
129
  },
123
130
  };
124
131
  }
132
+ /** `?after=` lists answering `{ [key], [nextKey] }`, where `nextKey` is the last sequence number on the page. */
133
+ function afterStrategy(key, nextKey) {
134
+ return {
135
+ items: (res) => arr(rec(res)[key]),
136
+ next: (res, query, count) => {
137
+ const next = rec(res)[nextKey];
138
+ if (typeof next !== 'number' || String(next) === String(query.after ?? ''))
139
+ return null;
140
+ if (query.limit !== undefined && count < Number(query.limit))
141
+ return null;
142
+ return { ...query, after: next };
143
+ },
144
+ };
145
+ }
@@ -257,7 +257,7 @@ export declare class Deployments extends DeploymentsGenerated {
257
257
  createInbound(body: B<'/deployments/inbound', 'post'>, options?: RequestOptions): Promise<{
258
258
  success: true;
259
259
  data: import("./types.js").components["schemas"]["Deployment"];
260
- }>;
260
+ } | import("./types.js").PendingApproval>;
261
261
  retrieve(id: Id, options?: RequestOptions): Promise<{
262
262
  success: true;
263
263
  data: import("./types.js").components["schemas"]["Deployment"];
@@ -475,10 +475,24 @@ export declare class Cases extends CasesGenerated {
475
475
  } & {
476
476
  [key: string]: unknown;
477
477
  }>;
478
- listEvents(id: Id, options?: RequestOptions): Promise<{
478
+ /** One page of a case's events: pass the previous page's `next_after` as `after` for the next one. */
479
+ listEvents(id: Id, query?: Q<'/cases/{id}/events', 'get'>, options?: RequestOptions): Promise<{
479
480
  events: import("./types.js").components["schemas"]["CaseEvent"][];
480
481
  next_after: number;
481
482
  }>;
483
+ /** Every event of a case, oldest first, page by page (follows `next_after`). */
484
+ listAllEvents(id: Id, query?: Q<'/cases/{id}/events', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
485
+ seq: number;
486
+ type: string;
487
+ actor_type: string;
488
+ actor_id?: string;
489
+ step_id?: string;
490
+ thread_id?: string;
491
+ data?: unknown;
492
+ at: string;
493
+ } & {
494
+ [key: string]: unknown;
495
+ }, unknown>;
482
496
  /** Start a case on an agent. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
483
497
  start(agentId: Id, body?: B<'/agents/{id}/cases', 'post'>, options?: RequestOptions): Promise<{
484
498
  case_id: string;
@@ -822,7 +836,7 @@ export declare class ChatContacts extends Resource {
822
836
  }>;
823
837
  update(id: Id, body: B<'/chat/contacts/{id}', 'patch'>, options?: RequestOptions): Promise<{
824
838
  [key: string]: unknown;
825
- }>;
839
+ } | import("./types.js").PendingApproval>;
826
840
  }
827
841
  export declare class Chat extends ChatGenerated {
828
842
  readonly conversations: ChatConversations;
@@ -227,8 +227,13 @@ class Cases extends resources_js_1.CasesGenerated {
227
227
  retrieve(id, options) {
228
228
  return this.do('get', '/cases/{id}', { path: { id } }, options);
229
229
  }
230
- listEvents(id, options) {
231
- return this.do('get', '/cases/{id}/events', { path: { id } }, options);
230
+ /** One page of a case's events: pass the previous page's `next_after` as `after` for the next one. */
231
+ listEvents(id, query, options) {
232
+ return this.do('get', '/cases/{id}/events', { path: { id }, query }, options);
233
+ }
234
+ /** Every event of a case, oldest first, page by page (follows `next_after`). */
235
+ listAllEvents(id, query, options) {
236
+ return this.pager('/cases/{id}/events', (0, pagination_js_1.afterStrategy)('events', 'next_after'), query, { id }, options);
232
237
  }
233
238
  /** Start a case on an agent. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
234
239
  start(agentId, body, options) {
@@ -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. */
@@ -1,6 +1,8 @@
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.0";
3
+ export declare const SDK_VERSION = "0.5.0";
4
+ /** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
5
+ export declare const DEFAULT_FINN_VERSION = "2026-11-01";
4
6
  export interface FinnOptions {
5
7
  /** `finn_live_...` org key, `finn_test_...` test key, or an OAuth `finn_oat_...` token. Defaults to env FINN_API_KEY. */
6
8
  apiKey?: string;
@@ -8,8 +10,11 @@ export interface FinnOptions {
8
10
  baseUrl?: string;
9
11
  /** Org to act in (Finn-Org header). Needed only for tokens that can use more than one org. */
10
12
  org?: string;
11
- /** Pins the API version (Finn-Version header), a date such as `2026-11-01`. */
12
- version?: string;
13
+ /**
14
+ * Pins the API version (Finn-Version header), a date such as `2026-11-01`. Defaults to DEFAULT_FINN_VERSION, the
15
+ * version this SDK was built against; `null` sends no header (the key's pinned version, else the current one).
16
+ */
17
+ version?: string | null;
13
18
  /**
14
19
  * Retries after the first attempt, on network errors, 408, 429, 502, 503 and 504. Only GET/HEAD/OPTIONS/PUT/DELETE
15
20
  * are retried freely; a POST or PATCH is retried only when it carries an Idempotency-Key and its route dedupes by
@@ -28,6 +33,11 @@ export interface FinnOptions {
28
33
  autoIdempotency?: boolean;
29
34
  /** Longest Retry-After the SDK will wait out; a longer one throws instead. Default 60000 ms. */
30
35
  maxRetryAfterMs?: number;
36
+ /**
37
+ * Most time one request spends waiting between its retries, `Retry-After` waits included. A retry whose wait would
38
+ * go past it is not made: the last error is thrown instead. Default 20000 ms.
39
+ */
40
+ maxRetryWaitMs?: number;
31
41
  /** Headers sent on every request. */
32
42
  defaultHeaders?: Record<string, string>;
33
43
  /** Replaces the wait between retries (for tests). */
@@ -43,6 +53,8 @@ export declare const AUTO_IDEMPOTENCY_ROUTES: ReadonlySet<string>;
43
53
  export declare const IDEMPOTENT_WRITE_ROUTES: readonly string[];
44
54
  /** True when the API dedupes this write by Idempotency-Key. `path` may be a template or a filled-in path. */
45
55
  export declare function honoursIdempotencyKey(method: string, path: string): boolean;
56
+ /** Default cap on the total wait between retries of one request (`maxRetryWaitMs`). */
57
+ export declare const DEFAULT_MAX_RETRY_WAIT_MS = 20000;
46
58
  /** A new random Idempotency-Key (a UUID v4). */
47
59
  export declare function idempotencyKey(): string;
48
60
  /** Untyped request input, for paths the spec does not have yet. */
@@ -64,6 +76,7 @@ export declare class FinnCore {
64
76
  readonly timeoutMs: number;
65
77
  readonly autoIdempotency: boolean;
66
78
  readonly maxRetryAfterMs: number;
79
+ readonly maxRetryWaitMs: number;
67
80
  constructor(options?: FinnOptions);
68
81
  /**
69
82
  * Calls any operation in the spec, fully typed.
package/dist/esm/core.js CHANGED
@@ -12,7 +12,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  var _FinnCore_apiKey, _FinnCore_fetch, _FinnCore_defaultHeaders, _FinnCore_sleep;
13
13
  import { FinnConnectionError, FinnError, FinnSdkError, FinnTimeoutError } from './errors.js';
14
14
  export const DEFAULT_BASE_URL = 'https://api.hirefinn.ai/v1';
15
- export const SDK_VERSION = '0.3.0';
15
+ export const SDK_VERSION = '0.5.0';
16
+ /** The API version this SDK was built against, sent as Finn-Version unless `version` says otherwise. */
17
+ export const DEFAULT_FINN_VERSION = '2026-11-01';
18
+ // Browsers own the User-Agent header, so it is only set on server runtimes.
19
+ const IS_NODE = typeof globalThis.process?.versions?.node === 'string';
16
20
  /** Writes that get an automatic Idempotency-Key (when autoIdempotency is on). */
17
21
  export const AUTO_IDEMPOTENCY_ROUTES = new Set([
18
22
  'post /calls',
@@ -44,6 +48,10 @@ export const IDEMPOTENT_WRITE_ROUTES = [
44
48
  'post /sales/plays/{slug}/run',
45
49
  'post /sales/drafts/{id}/skip',
46
50
  'post /webhook_endpoints',
51
+ 'post /dialer/follow-ups/{call_id}/done',
52
+ 'post /dialer/calls/{call_id}/notes',
53
+ 'patch /chat/agents/{agent_id}',
54
+ 'post /chat/agents/{agent_id}/test_turn',
47
55
  ];
48
56
  const IDEMPOTENT_WRITE_MATCHERS = IDEMPOTENT_WRITE_ROUTES.map((route) => {
49
57
  const [method, path] = route.split(' ');
@@ -62,6 +70,8 @@ export function honoursIdempotencyKey(method, path) {
62
70
  const SAFE_TO_RETRY_METHODS = new Set(['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE']);
63
71
  const RETRY_BASE_DELAY_MS = 500;
64
72
  const RETRY_MAX_DELAY_MS = 8000;
73
+ /** Default cap on the total wait between retries of one request (`maxRetryWaitMs`). */
74
+ export const DEFAULT_MAX_RETRY_WAIT_MS = 20000;
65
75
  /** A new random Idempotency-Key (a UUID v4). */
66
76
  export function idempotencyKey() {
67
77
  const c = globalThis.crypto;
@@ -115,11 +125,12 @@ export class FinnCore {
115
125
  __classPrivateFieldSet(this, _FinnCore_fetch, f, "f");
116
126
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
117
127
  this.org = options.org;
118
- this.version = options.version;
128
+ this.version = options.version === undefined ? DEFAULT_FINN_VERSION : options.version ?? undefined;
119
129
  this.maxRetries = options.maxRetries ?? 2;
120
130
  this.timeoutMs = options.timeoutMs ?? 60000;
121
131
  this.autoIdempotency = options.autoIdempotency ?? true;
122
132
  this.maxRetryAfterMs = options.maxRetryAfterMs ?? 60000;
133
+ this.maxRetryWaitMs = options.maxRetryWaitMs ?? DEFAULT_MAX_RETRY_WAIT_MS;
123
134
  __classPrivateFieldSet(this, _FinnCore_defaultHeaders, { ...(options.defaultHeaders ?? {}) }, "f");
124
135
  __classPrivateFieldSet(this, _FinnCore_sleep, options.sleep ?? defaultSleep, "f");
125
136
  }
@@ -150,6 +161,8 @@ export class FinnCore {
150
161
  }
151
162
  const headers = new Headers();
152
163
  headers.set('Accept', 'application/json');
164
+ if (IS_NODE)
165
+ headers.set('User-Agent', `finn-node/${SDK_VERSION}`);
153
166
  for (const [k, v] of Object.entries(__classPrivateFieldGet(this, _FinnCore_defaultHeaders, "f")))
154
167
  headers.set(k, v);
155
168
  const org = options.org ?? this.org;
@@ -176,6 +189,7 @@ export class FinnCore {
176
189
  const canRetry = SAFE_TO_RETRY_METHODS.has(method) || (headers.has('Idempotency-Key') && honoursIdempotencyKey(method, req.path));
177
190
  const maxRetries = canRetry ? Math.max(0, options.maxRetries ?? this.maxRetries) : 0;
178
191
  const timeoutMs = options.timeoutMs ?? this.timeoutMs;
192
+ let waitedMs = 0;
179
193
  for (let attempt = 0;; attempt += 1) {
180
194
  let response;
181
195
  try {
@@ -187,8 +201,10 @@ export class FinnCore {
187
201
  const wrapped = err instanceof FinnTimeoutError
188
202
  ? err
189
203
  : new FinnConnectionError(`Could not reach the Finn API: ${err?.message ?? err}`, { cause: err });
190
- if (attempt < maxRetries) {
191
- await __classPrivateFieldGet(this, _FinnCore_sleep, "f").call(this, backoffMs(attempt), options.signal);
204
+ const wait = backoffMs(attempt);
205
+ if (attempt < maxRetries && waitedMs + wait <= this.maxRetryWaitMs) {
206
+ waitedMs += wait;
207
+ await __classPrivateFieldGet(this, _FinnCore_sleep, "f").call(this, wait, options.signal);
192
208
  continue;
193
209
  }
194
210
  throw wrapped;
@@ -206,8 +222,9 @@ export class FinnCore {
206
222
  const error = FinnError.fromResponse(response.status, response.headers, parsed, response.statusText);
207
223
  if (attempt < maxRetries && isRetryable(error)) {
208
224
  const wait = error.retryAfter != null ? error.retryAfter * 1000 : backoffMs(attempt);
209
- if (wait > this.maxRetryAfterMs)
225
+ if (wait > this.maxRetryAfterMs || waitedMs + wait > this.maxRetryWaitMs)
210
226
  throw error;
227
+ waitedMs += wait;
211
228
  await __classPrivateFieldGet(this, _FinnCore_sleep, "f").call(this, wait, options.signal);
212
229
  continue;
213
230
  }
@@ -34,7 +34,7 @@ export declare class FinnError extends FinnSdkError {
34
34
  readonly code: FinnErrorCode;
35
35
  /** Matches the `X-Request-Id` response header; quote it to support. */
36
36
  readonly requestId: string | null;
37
- /** Per-field problems (unified shape only; `[]` otherwise). */
37
+ /** Per-field problems (unified shape, and legacy bodies that name fields as a string list; `[]` otherwise). */
38
38
  readonly fields: FinnFieldError[];
39
39
  /** Link to the error's documentation, when the API sent one. */
40
40
  readonly docUrl: string | null;