@hirefinn/sdk 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -11
- package/dist/cjs/client.d.ts +16 -6
- package/dist/cjs/client.js +9 -6
- package/dist/cjs/core.d.ts +18 -6
- package/dist/cjs/core.js +23 -7
- package/dist/cjs/errors.d.ts +40 -2
- package/dist/cjs/errors.js +44 -1
- package/dist/cjs/generated/openapi.d.ts +6259 -6222
- package/dist/cjs/generated/operations.d.ts +1 -1
- package/dist/cjs/generated/operations.js +23 -23
- package/dist/cjs/generated/resources.d.ts +47 -47
- package/dist/cjs/generated/resources.js +48 -48
- package/dist/cjs/index.d.ts +7 -7
- package/dist/cjs/index.js +13 -1
- package/dist/cjs/resources.d.ts +25 -17
- package/dist/cjs/resources.js +23 -18
- package/dist/cjs/types.d.ts +2 -2
- package/dist/cjs/webhooks.d.ts +20 -2
- package/dist/cjs/webhooks.js +3 -1
- package/dist/esm/client.d.ts +16 -6
- package/dist/esm/client.js +9 -6
- package/dist/esm/core.d.ts +18 -6
- package/dist/esm/core.js +22 -6
- package/dist/esm/errors.d.ts +40 -2
- package/dist/esm/errors.js +41 -0
- package/dist/esm/generated/openapi.d.ts +6259 -6222
- package/dist/esm/generated/operations.d.ts +1 -1
- package/dist/esm/generated/operations.js +23 -23
- package/dist/esm/generated/resources.d.ts +47 -47
- package/dist/esm/generated/resources.js +46 -46
- package/dist/esm/index.d.ts +7 -7
- package/dist/esm/index.js +4 -4
- package/dist/esm/resources.d.ts +25 -17
- package/dist/esm/resources.js +22 -17
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/webhooks.d.ts +20 -2
- package/dist/esm/webhooks.js +2 -0
- package/package.json +1 -1
package/dist/cjs/resources.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import type { FinnCore } from './core.js';
|
|
8
8
|
import { Resource, type B, type Id, type Q } from './resource.js';
|
|
9
9
|
import type { ApprovalHold, RequestOptions, Schemas } from './types.js';
|
|
10
|
-
import { AgentsGenerated, ApprovalsGenerated, AudiencesGenerated, CallsGenerated, CasesGenerated, ChatGenerated, ContactsGenerated, DeploymentsGenerated, DoNotCallGenerated,
|
|
10
|
+
import { AgentsGenerated, ApprovalsGenerated, AssistantsGenerated, AudiencesGenerated, CallsGenerated, CasesGenerated, ChatGenerated, ContactsGenerated, DeploymentsGenerated, DoNotCallGenerated, PhoneNumbersGenerated, VoicesGenerated, WalletGenerated } from './generated/resources.js';
|
|
11
11
|
export { Crm, Dialer, Organization, Sales, Webhooks } from './generated/resources.js';
|
|
12
12
|
export declare class Calls extends CallsGenerated {
|
|
13
13
|
/** Place an outbound call. Gets an automatic Idempotency-Key. May answer `pending_approval` (see isPendingApproval). */
|
|
@@ -43,17 +43,19 @@ export declare class Calls extends CallsGenerated {
|
|
|
43
43
|
data: import("./types.js").components["schemas"]["Call"];
|
|
44
44
|
}>;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
/** Assistants (voice agents): `/assistants`. Reached as `client.assistants` (and, deprecated, `client.finns`). */
|
|
47
|
+
export declare class Assistants extends AssistantsGenerated {
|
|
48
|
+
list(query?: Q<'/assistants', 'get'>, options?: RequestOptions): Promise<{
|
|
48
49
|
success: true;
|
|
49
|
-
data: import("./types.js").components["schemas"]["
|
|
50
|
+
data: import("./types.js").components["schemas"]["Assistant"][];
|
|
50
51
|
limit: number;
|
|
51
52
|
offset: number;
|
|
52
53
|
}>;
|
|
53
|
-
listAll(query?: Q<'/
|
|
54
|
+
listAll(query?: Q<'/assistants', 'get'>, options?: RequestOptions): import("./pagination.js").Paginator<{
|
|
54
55
|
id: string;
|
|
55
56
|
name: string;
|
|
56
57
|
status: string;
|
|
58
|
+
channel?: "voice" | "chat";
|
|
57
59
|
voice: string | null;
|
|
58
60
|
language: string | null;
|
|
59
61
|
language_group: string | null;
|
|
@@ -74,36 +76,42 @@ export declare class Finns extends FinnsGenerated {
|
|
|
74
76
|
created_at: string;
|
|
75
77
|
updated_at: string;
|
|
76
78
|
}, unknown>;
|
|
77
|
-
create(body: B<'/
|
|
79
|
+
create(body: B<'/assistants', 'post'>, options?: RequestOptions): Promise<{
|
|
78
80
|
success: true;
|
|
79
|
-
data: import("./types.js").components["schemas"]["
|
|
81
|
+
data: import("./types.js").components["schemas"]["Assistant"];
|
|
80
82
|
}>;
|
|
81
|
-
retrieve(
|
|
83
|
+
retrieve(assistantId: Id, options?: RequestOptions): Promise<{
|
|
82
84
|
success: true;
|
|
83
|
-
data: import("./types.js").components["schemas"]["
|
|
85
|
+
data: import("./types.js").components["schemas"]["Assistant"];
|
|
84
86
|
}>;
|
|
85
|
-
update(
|
|
87
|
+
update(assistantId: Id, body: B<'/assistants/{assistant_id}', 'patch'>, options?: RequestOptions): Promise<{
|
|
86
88
|
success: true;
|
|
87
|
-
data: import("./types.js").components["schemas"]["
|
|
89
|
+
data: import("./types.js").components["schemas"]["Assistant"];
|
|
88
90
|
}>;
|
|
89
|
-
delete(
|
|
91
|
+
delete(assistantId: Id, options?: RequestOptions): Promise<{
|
|
90
92
|
success: true;
|
|
91
|
-
data: import("./types.js").components["schemas"]["
|
|
93
|
+
data: import("./types.js").components["schemas"]["DeletedAssistant"];
|
|
92
94
|
}>;
|
|
93
|
-
listKnowledgeBase(
|
|
95
|
+
listKnowledgeBase(assistantId: Id, options?: RequestOptions): Promise<{
|
|
94
96
|
success: true;
|
|
95
97
|
data: import("./types.js").components["schemas"]["KnowledgeBaseDocument"][];
|
|
96
98
|
}>;
|
|
97
99
|
/** JSON body, or a FormData with the file for multipart upload. */
|
|
98
|
-
addKnowledgeBaseDocument(
|
|
100
|
+
addKnowledgeBaseDocument(assistantId: Id, body: B<'/assistants/{assistant_id}/knowledge_base', 'post'> | FormData, options?: RequestOptions): Promise<{
|
|
99
101
|
success: true;
|
|
100
102
|
data: import("./types.js").components["schemas"]["KnowledgeBaseDocument"];
|
|
101
103
|
}>;
|
|
102
|
-
postCallAnalysis(
|
|
104
|
+
postCallAnalysis(assistantId: Id, query?: Q<'/assistants/{assistant_id}/post_call_analysis', 'get'>, options?: RequestOptions): Promise<{
|
|
103
105
|
success: true;
|
|
104
|
-
data: import("./types.js").components["schemas"]["
|
|
106
|
+
data: import("./types.js").components["schemas"]["AssistantPostCallAnalysis"];
|
|
105
107
|
}>;
|
|
106
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Renamed to {@link Assistants}; `Finns` is the same class and will be removed in a future major version.
|
|
111
|
+
*/
|
|
112
|
+
export declare const Finns: typeof Assistants;
|
|
113
|
+
/** @deprecated Renamed to {@link Assistants}. */
|
|
114
|
+
export type Finns = Assistants;
|
|
107
115
|
export declare class Voices extends VoicesGenerated {
|
|
108
116
|
list(query?: Q<'/voices', 'get'>, options?: RequestOptions): Promise<{
|
|
109
117
|
success: true;
|
package/dist/cjs/resources.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Chat = exports.ChatContacts = exports.ChatConversations = exports.Agents = exports.Approvals = exports.Cases = exports.Contacts = exports.DoNotCall = exports.Wallet = exports.Deployments = exports.Audiences = exports.PhoneNumbers = exports.Voices = exports.Finns = exports.Calls = exports.Webhooks = exports.Sales = exports.Organization = exports.Dialer = exports.Crm = void 0;
|
|
3
|
+
exports.Chat = exports.ChatContacts = exports.ChatConversations = exports.Agents = exports.Approvals = exports.Cases = exports.Contacts = exports.DoNotCall = exports.Wallet = exports.Deployments = exports.Audiences = exports.PhoneNumbers = exports.Voices = exports.Finns = exports.Assistants = exports.Calls = exports.Webhooks = exports.Sales = exports.Organization = exports.Dialer = exports.Crm = void 0;
|
|
4
4
|
const errors_js_1 = require("./errors.js");
|
|
5
5
|
const pagination_js_1 = require("./pagination.js");
|
|
6
6
|
const resource_js_1 = require("./resource.js");
|
|
@@ -29,37 +29,42 @@ class Calls extends resources_js_1.CallsGenerated {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
exports.Calls = Calls;
|
|
32
|
-
|
|
32
|
+
/** Assistants (voice agents): `/assistants`. Reached as `client.assistants` (and, deprecated, `client.finns`). */
|
|
33
|
+
class Assistants extends resources_js_1.AssistantsGenerated {
|
|
33
34
|
list(query, options) {
|
|
34
|
-
return this.do('get', '/
|
|
35
|
+
return this.do('get', '/assistants', { query }, options);
|
|
35
36
|
}
|
|
36
37
|
listAll(query, options) {
|
|
37
|
-
return this.pager('/
|
|
38
|
+
return this.pager('/assistants', (0, pagination_js_1.offsetStrategy)(), query, undefined, options);
|
|
38
39
|
}
|
|
39
40
|
create(body, options) {
|
|
40
|
-
return this.do('post', '/
|
|
41
|
+
return this.do('post', '/assistants', { body }, options);
|
|
41
42
|
}
|
|
42
|
-
retrieve(
|
|
43
|
-
return this.do('get', '/
|
|
43
|
+
retrieve(assistantId, options) {
|
|
44
|
+
return this.do('get', '/assistants/{assistant_id}', { path: { assistant_id: assistantId } }, options);
|
|
44
45
|
}
|
|
45
|
-
update(
|
|
46
|
-
return this.do('patch', '/
|
|
46
|
+
update(assistantId, body, options) {
|
|
47
|
+
return this.do('patch', '/assistants/{assistant_id}', { path: { assistant_id: assistantId }, body }, options);
|
|
47
48
|
}
|
|
48
|
-
delete(
|
|
49
|
-
return this.do('delete', '/
|
|
49
|
+
delete(assistantId, options) {
|
|
50
|
+
return this.do('delete', '/assistants/{assistant_id}', { path: { assistant_id: assistantId } }, options);
|
|
50
51
|
}
|
|
51
|
-
listKnowledgeBase(
|
|
52
|
-
return this.do('get', '/
|
|
52
|
+
listKnowledgeBase(assistantId, options) {
|
|
53
|
+
return this.do('get', '/assistants/{assistant_id}/knowledge_base', { path: { assistant_id: assistantId } }, options);
|
|
53
54
|
}
|
|
54
55
|
/** JSON body, or a FormData with the file for multipart upload. */
|
|
55
|
-
addKnowledgeBaseDocument(
|
|
56
|
-
return this.do('post', '/
|
|
56
|
+
addKnowledgeBaseDocument(assistantId, body, options) {
|
|
57
|
+
return this.do('post', '/assistants/{assistant_id}/knowledge_base', { path: { assistant_id: assistantId }, body }, options);
|
|
57
58
|
}
|
|
58
|
-
postCallAnalysis(
|
|
59
|
-
return this.do('get', '/
|
|
59
|
+
postCallAnalysis(assistantId, query, options) {
|
|
60
|
+
return this.do('get', '/assistants/{assistant_id}/post_call_analysis', { path: { assistant_id: assistantId }, query }, options);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
exports.
|
|
63
|
+
exports.Assistants = Assistants;
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Renamed to {@link Assistants}; `Finns` is the same class and will be removed in a future major version.
|
|
66
|
+
*/
|
|
67
|
+
exports.Finns = Assistants;
|
|
63
68
|
class Voices extends resources_js_1.VoicesGenerated {
|
|
64
69
|
list(query, options) {
|
|
65
70
|
return this.do('get', '/voices', { query }, options);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -81,9 +81,9 @@ export interface RequestOptions {
|
|
|
81
81
|
* Pass `false` to send none, even on an endpoint where the SDK would make one up.
|
|
82
82
|
*/
|
|
83
83
|
idempotencyKey?: string | false;
|
|
84
|
-
/** Org to act in (
|
|
84
|
+
/** Org to act in (X-Org-Id header, formerly Finn-Org), for tokens that can use more than one org. */
|
|
85
85
|
org?: string;
|
|
86
|
-
/** API version date (
|
|
86
|
+
/** API version date (Api-Version header, formerly Finn-Version), e.g. `2026-11-01`. */
|
|
87
87
|
version?: string;
|
|
88
88
|
/** Retries after the first attempt. */
|
|
89
89
|
maxRetries?: number;
|
package/dist/cjs/webhooks.d.ts
CHANGED
|
@@ -39,7 +39,22 @@ export declare const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
|
39
39
|
* The body of a webhook delivery (the Finn envelope). Endpoints imported from Finn Chat with the `chat` envelope get
|
|
40
40
|
* Finn Chat's own body instead: `{ id, event, createdAt, orgId, data }`.
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The fields a call webhook's `data` uses to name the agent (`call.completed`, `call.analyzed`, transcript events).
|
|
44
|
+
* `agent_id` / `agent_name` are the current names; servers before the rename send only `finn_id` / `finn_name`, and
|
|
45
|
+
* newer servers send both with the same values until the old names retire. Read `agent_id ?? finn_id`.
|
|
46
|
+
*/
|
|
47
|
+
export interface WebhookAgentFields {
|
|
48
|
+
/** The agent (assistant) that handled the call. */
|
|
49
|
+
agent_id?: string | null;
|
|
50
|
+
/** The agent's name, where the event carries one. */
|
|
51
|
+
agent_name?: string | null;
|
|
52
|
+
/** @deprecated Old name of `agent_id`, same value. */
|
|
53
|
+
finn_id?: string | null;
|
|
54
|
+
/** @deprecated Old name of `agent_name`, same value. */
|
|
55
|
+
finn_name?: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface WebhookEvent<T = Record<string, unknown> & WebhookAgentFields> {
|
|
43
58
|
/** e.g. `call.completed`, `contact.created`, `case.completed`. */
|
|
44
59
|
event: string;
|
|
45
60
|
/** Unique per event, and the same on every retry or redelivery of it: dedupe on it. */
|
|
@@ -56,6 +71,9 @@ export interface WebhookEvent<T = Record<string, unknown>> {
|
|
|
56
71
|
export declare class FinnWebhookVerificationError extends FinnSdkError {
|
|
57
72
|
constructor(message: string);
|
|
58
73
|
}
|
|
74
|
+
/** The neutral name of {@link FinnWebhookVerificationError}: the same class, so `instanceof` works with either name. */
|
|
75
|
+
export declare const WebhookVerificationError: typeof FinnWebhookVerificationError;
|
|
76
|
+
export type WebhookVerificationError = FinnWebhookVerificationError;
|
|
59
77
|
export interface VerifyWebhookOptions {
|
|
60
78
|
/** The raw request body, exactly as received (not re-serialised JSON). */
|
|
61
79
|
payload: string | Uint8Array;
|
|
@@ -94,4 +112,4 @@ export declare function signWebhookPayload(secret: string, timestamp: number | s
|
|
|
94
112
|
* ...
|
|
95
113
|
* });
|
|
96
114
|
*/
|
|
97
|
-
export declare function verifyWebhook<T = Record<string, unknown
|
|
115
|
+
export declare function verifyWebhook<T = Record<string, unknown> & WebhookAgentFields>(options: VerifyWebhookOptions): Promise<WebhookEvent<T>>;
|
package/dist/cjs/webhooks.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.FinnWebhookVerificationError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.LEGACY_WEBHOOK_HEADERS = exports.WEBHOOK_HEADERS = void 0;
|
|
36
|
+
exports.WebhookVerificationError = exports.FinnWebhookVerificationError = exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.LEGACY_WEBHOOK_HEADERS = exports.WEBHOOK_HEADERS = void 0;
|
|
37
37
|
exports.parseSignatureHeader = parseSignatureHeader;
|
|
38
38
|
exports.readWebhookHeader = readWebhookHeader;
|
|
39
39
|
exports.timingSafeEqual = timingSafeEqual;
|
|
@@ -83,6 +83,8 @@ class FinnWebhookVerificationError extends errors_js_1.FinnSdkError {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
exports.FinnWebhookVerificationError = FinnWebhookVerificationError;
|
|
86
|
+
/** The neutral name of {@link FinnWebhookVerificationError}: the same class, so `instanceof` works with either name. */
|
|
87
|
+
exports.WebhookVerificationError = FinnWebhookVerificationError;
|
|
86
88
|
/** Splits `t=...,v1=...` into its timestamp and v1 signatures. */
|
|
87
89
|
function parseSignatureHeader(header) {
|
|
88
90
|
let timestamp = NaN;
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { FinnCore, type FinnOptions } from './core.js';
|
|
2
|
-
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall,
|
|
2
|
+
import { Agents, Approvals, Assistants, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall, Organization, PhoneNumbers, Sales, Voices, Wallet, Webhooks, type WaitForApprovalOptions } from './resources.js';
|
|
3
3
|
import type { ApprovalHold, Schemas } from './types.js';
|
|
4
4
|
/**
|
|
5
|
-
* The
|
|
5
|
+
* The API client. `Client` is the neutral name of the same class.
|
|
6
6
|
*
|
|
7
|
-
* import {
|
|
8
|
-
* const
|
|
9
|
-
* const { data } = await
|
|
7
|
+
* import { Client } from '@hirefinn/sdk';
|
|
8
|
+
* const client = new Client({ apiKey: process.env.FINN_API_KEY });
|
|
9
|
+
* const { data } = await client.calls.list({ limit: 10 });
|
|
10
10
|
*/
|
|
11
11
|
export declare class Finn extends FinnCore {
|
|
12
12
|
readonly calls: Calls;
|
|
13
|
-
|
|
13
|
+
/** Assistants (voice agents): `/assistants`. */
|
|
14
|
+
readonly assistants: Assistants;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use {@link Finn.assistants}: the very same object (`client.finns === client.assistants`), kept so
|
|
17
|
+
* existing code runs. It calls `/assistants`, not the old `/finns` path.
|
|
18
|
+
*/
|
|
19
|
+
readonly finns: Assistants;
|
|
14
20
|
readonly voices: Voices;
|
|
15
21
|
readonly phoneNumbers: PhoneNumbers;
|
|
16
22
|
readonly audiences: Audiences;
|
|
@@ -40,3 +46,7 @@ export declare class Finn extends FinnCore {
|
|
|
40
46
|
/** Polls an approval until it is decided (see approvals.wait). */
|
|
41
47
|
waitForApproval(id: string, options?: WaitForApprovalOptions): Promise<ApprovalHold | Schemas['Approval']>;
|
|
42
48
|
}
|
|
49
|
+
/** The neutral name of the API client: the same class as {@link Finn}, so `instanceof` works with either name. */
|
|
50
|
+
export declare const Client: typeof Finn;
|
|
51
|
+
/** The neutral name of the API client. */
|
|
52
|
+
export type Client = Finn;
|
package/dist/esm/client.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { FinnCore } from './core.js';
|
|
2
|
-
import { Agents, Approvals, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall,
|
|
2
|
+
import { Agents, Approvals, Assistants, Audiences, Calls, Cases, Chat, Contacts, Crm, Deployments, Dialer, DoNotCall, Organization, PhoneNumbers, Sales, Voices, Wallet, Webhooks, } from './resources.js';
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
4
|
+
* The API client. `Client` is the neutral name of the same class.
|
|
5
5
|
*
|
|
6
|
-
* import {
|
|
7
|
-
* const
|
|
8
|
-
* const { data } = await
|
|
6
|
+
* import { Client } from '@hirefinn/sdk';
|
|
7
|
+
* const client = new Client({ apiKey: process.env.FINN_API_KEY });
|
|
8
|
+
* const { data } = await client.calls.list({ limit: 10 });
|
|
9
9
|
*/
|
|
10
10
|
export class Finn extends FinnCore {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
super(options);
|
|
13
13
|
this.calls = new Calls(this);
|
|
14
|
-
this.
|
|
14
|
+
this.assistants = new Assistants(this);
|
|
15
|
+
this.finns = this.assistants;
|
|
15
16
|
this.voices = new Voices(this);
|
|
16
17
|
this.phoneNumbers = new PhoneNumbers(this);
|
|
17
18
|
this.audiences = new Audiences(this);
|
|
@@ -34,3 +35,5 @@ export class Finn extends FinnCore {
|
|
|
34
35
|
return this.approvals.wait(id, options);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
38
|
+
/** The neutral name of the API client: the same class as {@link Finn}, so `instanceof` works with either name. */
|
|
39
|
+
export const Client = Finn;
|
package/dist/esm/core.d.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
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.5.
|
|
4
|
-
/** The API version this SDK was built against, sent as
|
|
3
|
+
export declare const SDK_VERSION = "0.5.2";
|
|
4
|
+
/** The API version this SDK was built against, sent as Api-Version unless `version` says otherwise. */
|
|
5
5
|
export declare const DEFAULT_FINN_VERSION = "2026-11-01";
|
|
6
|
+
/** The neutral name of {@link DEFAULT_FINN_VERSION}. */
|
|
7
|
+
export declare const DEFAULT_API_VERSION = "2026-11-01";
|
|
8
|
+
/**
|
|
9
|
+
* Request headers the API renamed: old name -> the name the SDK sends. The API still accepts the old names, but answers
|
|
10
|
+
* `400` when a request carries both names with different values, so the SDK only ever sends the new one: an old name
|
|
11
|
+
* passed in `defaultHeaders` or per-request `headers` is sent under its new name.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RENAMED_REQUEST_HEADERS: Readonly<Record<string, string>>;
|
|
6
14
|
export interface FinnOptions {
|
|
7
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* `wsk_live_...` org key, `wsk_test_...` test key, or an OAuth `wsk_oat_...` token (older keys: `finn_live_...`,
|
|
17
|
+
* `finn_test_...`, `finn_oat_...`; both work). Sent as given. Defaults to env FINN_API_KEY.
|
|
18
|
+
*/
|
|
8
19
|
apiKey?: string;
|
|
9
20
|
/** Defaults to `https://api.hirefinn.ai/v1`. */
|
|
10
21
|
baseUrl?: string;
|
|
11
|
-
/** Org to act in (
|
|
22
|
+
/** Org to act in (X-Org-Id header, formerly Finn-Org). Needed only for tokens that can use more than one org. */
|
|
12
23
|
org?: string;
|
|
13
24
|
/**
|
|
14
|
-
* Pins the API version (
|
|
15
|
-
* version this SDK was built against; `null` sends no header (the key's pinned version,
|
|
25
|
+
* Pins the API version (Api-Version header, formerly Finn-Version), a date such as `2026-11-01`. Defaults to
|
|
26
|
+
* DEFAULT_FINN_VERSION, the version this SDK was built against; `null` sends no header (the key's pinned version,
|
|
27
|
+
* else the current one).
|
|
16
28
|
*/
|
|
17
29
|
version?: string | null;
|
|
18
30
|
/**
|
package/dist/esm/core.js
CHANGED
|
@@ -12,9 +12,25 @@ 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.5.
|
|
16
|
-
/** The API version this SDK was built against, sent as
|
|
15
|
+
export const SDK_VERSION = '0.5.2';
|
|
16
|
+
/** The API version this SDK was built against, sent as Api-Version unless `version` says otherwise. */
|
|
17
17
|
export const DEFAULT_FINN_VERSION = '2026-11-01';
|
|
18
|
+
/** The neutral name of {@link DEFAULT_FINN_VERSION}. */
|
|
19
|
+
export const DEFAULT_API_VERSION = DEFAULT_FINN_VERSION;
|
|
20
|
+
/**
|
|
21
|
+
* Request headers the API renamed: old name -> the name the SDK sends. The API still accepts the old names, but answers
|
|
22
|
+
* `400` when a request carries both names with different values, so the SDK only ever sends the new one: an old name
|
|
23
|
+
* passed in `defaultHeaders` or per-request `headers` is sent under its new name.
|
|
24
|
+
*/
|
|
25
|
+
export const RENAMED_REQUEST_HEADERS = Object.freeze({
|
|
26
|
+
'finn-version': 'Api-Version',
|
|
27
|
+
'finn-org': 'X-Org-Id',
|
|
28
|
+
});
|
|
29
|
+
/** Sets a header, sending a renamed one (Finn-Version, Finn-Org) under its new name. */
|
|
30
|
+
function setHeader(headers, name, value) {
|
|
31
|
+
const renamed = RENAMED_REQUEST_HEADERS[name.toLowerCase()];
|
|
32
|
+
headers.set(renamed ?? name, value);
|
|
33
|
+
}
|
|
18
34
|
// Browsers own the User-Agent header, so it is only set on server runtimes.
|
|
19
35
|
const IS_NODE = typeof globalThis.process?.versions?.node === 'string';
|
|
20
36
|
/** Writes that get an automatic Idempotency-Key (when autoIdempotency is on). */
|
|
@@ -164,13 +180,13 @@ export class FinnCore {
|
|
|
164
180
|
if (IS_NODE)
|
|
165
181
|
headers.set('User-Agent', `finn-node/${SDK_VERSION}`);
|
|
166
182
|
for (const [k, v] of Object.entries(__classPrivateFieldGet(this, _FinnCore_defaultHeaders, "f")))
|
|
167
|
-
headers
|
|
183
|
+
setHeader(headers, k, v);
|
|
168
184
|
const org = options.org ?? this.org;
|
|
169
185
|
if (org)
|
|
170
|
-
headers.set('
|
|
186
|
+
headers.set('X-Org-Id', org);
|
|
171
187
|
const version = options.version ?? this.version;
|
|
172
188
|
if (version)
|
|
173
|
-
headers.set('
|
|
189
|
+
headers.set('Api-Version', version);
|
|
174
190
|
if (key)
|
|
175
191
|
headers.set('Idempotency-Key', key);
|
|
176
192
|
let body;
|
|
@@ -183,7 +199,7 @@ export class FinnCore {
|
|
|
183
199
|
}
|
|
184
200
|
}
|
|
185
201
|
for (const [k, v] of Object.entries(options.headers ?? {}))
|
|
186
|
-
headers
|
|
202
|
+
setHeader(headers, k, v);
|
|
187
203
|
headers.set('Authorization', `Bearer ${__classPrivateFieldGet(this, _FinnCore_apiKey, "f")}`);
|
|
188
204
|
// Idempotent methods always; a POST/PATCH only with a key on a route that dedupes by it.
|
|
189
205
|
const canRetry = SAFE_TO_RETRY_METHODS.has(method) || (headers.has('Idempotency-Key') && honoursIdempotencyKey(method, req.path));
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -16,8 +16,17 @@ export interface FinnFieldError {
|
|
|
16
16
|
code: string;
|
|
17
17
|
message: string;
|
|
18
18
|
}
|
|
19
|
-
/** The shared error codes. Endpoints may also answer resource-specific codes such as `
|
|
19
|
+
/** The shared error codes. Endpoints may also answer resource-specific codes such as `assistant_not_found`. */
|
|
20
20
|
export type FinnErrorCode = 'invalid_request' | 'invalid_cursor' | 'unauthorized' | 'api_key_required' | 'invalid_api_key' | 'insufficient_scope' | 'forbidden' | 'not_found' | 'conflict' | 'idempotency_in_progress' | 'payload_too_large' | 'idempotency_key_reused' | 'rate_limited' | 'internal_error' | 'unavailable' | (string & {});
|
|
21
|
+
/**
|
|
22
|
+
* Error codes the API renamed: old code -> its neutral successor. The new paths (`/assistants`, ...) answer the neutral
|
|
23
|
+
* code; the old paths answered the old one. {@link FinnError.hasCode} matches either name.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RENAMED_ERROR_CODES: Readonly<Record<string, string>>;
|
|
26
|
+
/** The neutral name of an error code: `finn_not_found` -> `assistant_not_found`; any other code as it is. */
|
|
27
|
+
export declare const neutralErrorCode: (code: string) => string;
|
|
28
|
+
/** The old name of a renamed error code: `assistant_not_found` -> `finn_not_found`; null when it was never renamed. */
|
|
29
|
+
export declare const legacyErrorCode: (code: string) => string | null;
|
|
21
30
|
/** The code an error gets when the body does not name one (mirrors the backend's codeForStatus). */
|
|
22
31
|
export declare const codeForStatus: (status: number) => string;
|
|
23
32
|
/** Base class for every error the SDK throws. */
|
|
@@ -30,8 +39,13 @@ export declare class FinnSdkError extends Error {
|
|
|
30
39
|
export declare class FinnError extends FinnSdkError {
|
|
31
40
|
/** HTTP status. */
|
|
32
41
|
readonly status: number;
|
|
33
|
-
/** Stable error code. */
|
|
42
|
+
/** Stable error code, as the API sent it (neutral names such as `assistant_not_found` on the current paths). */
|
|
34
43
|
readonly code: FinnErrorCode;
|
|
44
|
+
/**
|
|
45
|
+
* The old name of a renamed code (`finn_not_found` for `assistant_not_found`, see RENAMED_ERROR_CODES), else null.
|
|
46
|
+
* For code that still compares against the old names; prefer {@link FinnError.hasCode}.
|
|
47
|
+
*/
|
|
48
|
+
readonly legacyCode: string | null;
|
|
35
49
|
/** Matches the `X-Request-Id` response header; quote it to support. */
|
|
36
50
|
readonly requestId: string | null;
|
|
37
51
|
/** Per-field problems (unified shape, and legacy bodies that name fields as a string list; `[]` otherwise). */
|
|
@@ -64,6 +78,11 @@ export declare class FinnError extends FinnSdkError {
|
|
|
64
78
|
body?: unknown;
|
|
65
79
|
headers?: Headers;
|
|
66
80
|
});
|
|
81
|
+
/**
|
|
82
|
+
* True when this error's code is `code`, by its old or its neutral name: `hasCode('finn_not_found')` and
|
|
83
|
+
* `hasCode('assistant_not_found')` both match either answer.
|
|
84
|
+
*/
|
|
85
|
+
hasCode(code: string): boolean;
|
|
67
86
|
/** Builds a FinnError from a failed response and its already-read body. */
|
|
68
87
|
static fromResponse(status: number, headers: Headers, body: unknown, statusText?: string): FinnError;
|
|
69
88
|
}
|
|
@@ -88,3 +107,22 @@ export declare class FinnApprovalTimeoutError extends FinnSdkError {
|
|
|
88
107
|
}
|
|
89
108
|
/** Retry-After as seconds: accepts delta-seconds or an HTTP date. */
|
|
90
109
|
export declare function parseRetryAfterSeconds(value: string | null, now?: number): number | null;
|
|
110
|
+
/** The neutral name of {@link FinnSdkError}. */
|
|
111
|
+
export declare const SdkError: typeof FinnSdkError;
|
|
112
|
+
export type SdkError = FinnSdkError;
|
|
113
|
+
/** The neutral name of {@link FinnError}. */
|
|
114
|
+
export declare const ApiError: typeof FinnError;
|
|
115
|
+
export type ApiError = FinnError;
|
|
116
|
+
/** The neutral name of {@link FinnConnectionError}. */
|
|
117
|
+
export declare const ApiConnectionError: typeof FinnConnectionError;
|
|
118
|
+
export type ApiConnectionError = FinnConnectionError;
|
|
119
|
+
/** The neutral name of {@link FinnTimeoutError}. */
|
|
120
|
+
export declare const ApiTimeoutError: typeof FinnTimeoutError;
|
|
121
|
+
export type ApiTimeoutError = FinnTimeoutError;
|
|
122
|
+
/** The neutral name of {@link FinnApprovalTimeoutError}. */
|
|
123
|
+
export declare const ApprovalTimeoutError: typeof FinnApprovalTimeoutError;
|
|
124
|
+
export type ApprovalTimeoutError = FinnApprovalTimeoutError;
|
|
125
|
+
/** The neutral name of {@link FinnErrorCode}. */
|
|
126
|
+
export type ErrorCode = FinnErrorCode;
|
|
127
|
+
/** The neutral name of {@link FinnFieldError}. */
|
|
128
|
+
export type FieldError = FinnFieldError;
|
package/dist/esm/errors.js
CHANGED
|
@@ -24,6 +24,28 @@ const CODE_FOR_STATUS = {
|
|
|
24
24
|
503: 'unavailable',
|
|
25
25
|
504: 'unavailable',
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Error codes the API renamed: old code -> its neutral successor. The new paths (`/assistants`, ...) answer the neutral
|
|
29
|
+
* code; the old paths answered the old one. {@link FinnError.hasCode} matches either name.
|
|
30
|
+
*/
|
|
31
|
+
export const RENAMED_ERROR_CODES = Object.freeze({
|
|
32
|
+
finn_not_found: 'assistant_not_found',
|
|
33
|
+
finn_in_use: 'assistant_in_use',
|
|
34
|
+
finn_paused: 'assistant_paused',
|
|
35
|
+
finn_not_draft: 'assistant_not_draft',
|
|
36
|
+
finn_not_yours: 'assistant_not_yours',
|
|
37
|
+
invalid_finn_id: 'invalid_assistant_id',
|
|
38
|
+
invalid_finn_version: 'invalid_api_version',
|
|
39
|
+
});
|
|
40
|
+
const LEGACY_FOR_NEUTRAL = Object.freeze(Object.fromEntries(Object.entries(RENAMED_ERROR_CODES).map(([old, neutral]) => [neutral, old])));
|
|
41
|
+
/** The neutral name of an error code: `finn_not_found` -> `assistant_not_found`; any other code as it is. */
|
|
42
|
+
export const neutralErrorCode = (code) => Object.hasOwn(RENAMED_ERROR_CODES, code) ? RENAMED_ERROR_CODES[code] : code;
|
|
43
|
+
/** The old name of a renamed error code: `assistant_not_found` -> `finn_not_found`; null when it was never renamed. */
|
|
44
|
+
export const legacyErrorCode = (code) => Object.hasOwn(LEGACY_FOR_NEUTRAL, code)
|
|
45
|
+
? LEGACY_FOR_NEUTRAL[code]
|
|
46
|
+
: Object.hasOwn(RENAMED_ERROR_CODES, code)
|
|
47
|
+
? code
|
|
48
|
+
: null;
|
|
27
49
|
/** The code an error gets when the body does not name one (mirrors the backend's codeForStatus). */
|
|
28
50
|
export const codeForStatus = (status) => CODE_FOR_STATUS[status] ?? (status >= 500 ? 'internal_error' : 'invalid_request');
|
|
29
51
|
/** Base class for every error the SDK throws. */
|
|
@@ -42,6 +64,7 @@ export class FinnError extends FinnSdkError {
|
|
|
42
64
|
this.name = 'FinnError';
|
|
43
65
|
this.status = init.status;
|
|
44
66
|
this.code = init.code;
|
|
67
|
+
this.legacyCode = legacyErrorCode(init.code);
|
|
45
68
|
this.requestId = init.requestId ?? null;
|
|
46
69
|
this.fields = init.fields ?? [];
|
|
47
70
|
this.docUrl = init.docUrl ?? null;
|
|
@@ -52,6 +75,13 @@ export class FinnError extends FinnSdkError {
|
|
|
52
75
|
this.body = init.body;
|
|
53
76
|
this.headers = init.headers ?? new Headers();
|
|
54
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* True when this error's code is `code`, by its old or its neutral name: `hasCode('finn_not_found')` and
|
|
80
|
+
* `hasCode('assistant_not_found')` both match either answer.
|
|
81
|
+
*/
|
|
82
|
+
hasCode(code) {
|
|
83
|
+
return neutralErrorCode(this.code) === neutralErrorCode(code);
|
|
84
|
+
}
|
|
55
85
|
/** Builds a FinnError from a failed response and its already-read body. */
|
|
56
86
|
static fromResponse(status, headers, body, statusText = '') {
|
|
57
87
|
const headerRequestId = headers.get('x-request-id');
|
|
@@ -164,3 +194,14 @@ function legacyFields(v, code, message) {
|
|
|
164
194
|
function isFieldError(v) {
|
|
165
195
|
return isRecord(v) && typeof v.field === 'string';
|
|
166
196
|
}
|
|
197
|
+
// Neutral names of the error classes: the same classes, so `instanceof` works with either name.
|
|
198
|
+
/** The neutral name of {@link FinnSdkError}. */
|
|
199
|
+
export const SdkError = FinnSdkError;
|
|
200
|
+
/** The neutral name of {@link FinnError}. */
|
|
201
|
+
export const ApiError = FinnError;
|
|
202
|
+
/** The neutral name of {@link FinnConnectionError}. */
|
|
203
|
+
export const ApiConnectionError = FinnConnectionError;
|
|
204
|
+
/** The neutral name of {@link FinnTimeoutError}. */
|
|
205
|
+
export const ApiTimeoutError = FinnTimeoutError;
|
|
206
|
+
/** The neutral name of {@link FinnApprovalTimeoutError}. */
|
|
207
|
+
export const ApprovalTimeoutError = FinnApprovalTimeoutError;
|