@financeable/lenders 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FUNCTIONS.md +14 -37
- package/README.md +87 -135
- package/bin/mcp-server.js +1147 -1003
- package/bin/mcp-server.js.map +27 -16
- package/dist/commonjs/funcs/consumersCreatePepper.d.ts +3 -2
- package/dist/commonjs/funcs/consumersCreatePepper.d.ts.map +1 -1
- package/dist/commonjs/funcs/consumersCreatePepper.js +3 -1
- package/dist/commonjs/funcs/consumersCreatePepper.js.map +1 -1
- package/dist/commonjs/hooks/types.d.ts +2 -0
- package/dist/commonjs/hooks/types.d.ts.map +1 -1
- package/dist/commonjs/index.d.ts +2 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +3 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/lib/config.d.ts +7 -3
- package/dist/commonjs/lib/config.d.ts.map +1 -1
- package/dist/commonjs/lib/config.js +3 -3
- package/dist/commonjs/lib/config.js.map +1 -1
- package/dist/commonjs/lib/matchers.d.ts +6 -11
- package/dist/commonjs/lib/matchers.d.ts.map +1 -1
- package/dist/commonjs/lib/matchers.js +45 -31
- package/dist/commonjs/lib/matchers.js.map +1 -1
- package/dist/commonjs/lib/sdks.d.ts +4 -1
- package/dist/commonjs/lib/sdks.d.ts.map +1 -1
- package/dist/commonjs/lib/sdks.js +16 -16
- package/dist/commonjs/lib/sdks.js.map +1 -1
- package/dist/commonjs/mcp-server/mcp-server.js +1 -1
- package/dist/commonjs/mcp-server/server.js +1 -1
- package/dist/commonjs/models/components/apierrorcodes.d.ts +21 -0
- package/dist/commonjs/models/components/apierrorcodes.d.ts.map +1 -1
- package/dist/commonjs/models/components/apierrorcodes.js +7 -0
- package/dist/commonjs/models/components/apierrorcodes.js.map +1 -1
- package/dist/commonjs/models/errors/apierror.d.ts +8 -6
- package/dist/commonjs/models/errors/apierror.d.ts.map +1 -1
- package/dist/commonjs/models/errors/apierror.js +17 -10
- package/dist/commonjs/models/errors/apierror.js.map +1 -1
- package/dist/commonjs/models/errors/createpepperconsumer.d.ts +31 -10
- package/dist/commonjs/models/errors/createpepperconsumer.d.ts.map +1 -1
- package/dist/commonjs/models/errors/createpepperconsumer.js +56 -20
- package/dist/commonjs/models/errors/createpepperconsumer.js.map +1 -1
- package/dist/commonjs/models/errors/financeablelenderserror.d.ts +19 -0
- package/dist/commonjs/models/errors/financeablelenderserror.d.ts.map +1 -0
- package/dist/commonjs/models/errors/financeablelenderserror.js +20 -0
- package/dist/commonjs/models/errors/financeablelenderserror.js.map +1 -0
- package/dist/commonjs/models/errors/index.d.ts +1 -0
- package/dist/commonjs/models/errors/index.d.ts.map +1 -1
- package/dist/commonjs/models/errors/index.js +1 -0
- package/dist/commonjs/models/errors/index.js.map +1 -1
- package/dist/commonjs/models/errors/responsevalidationerror.d.ts +26 -0
- package/dist/commonjs/models/errors/responsevalidationerror.d.ts.map +1 -0
- package/dist/commonjs/models/errors/responsevalidationerror.js +66 -0
- package/dist/commonjs/models/errors/responsevalidationerror.js.map +1 -0
- package/dist/commonjs/models/errors/sdkvalidationerror.d.ts +1 -0
- package/dist/commonjs/models/errors/sdkvalidationerror.d.ts.map +1 -1
- package/dist/commonjs/models/errors/sdkvalidationerror.js +14 -0
- package/dist/commonjs/models/errors/sdkvalidationerror.js.map +1 -1
- package/dist/esm/funcs/consumersCreatePepper.d.ts +3 -2
- package/dist/esm/funcs/consumersCreatePepper.d.ts.map +1 -1
- package/dist/esm/funcs/consumersCreatePepper.js +3 -1
- package/dist/esm/funcs/consumersCreatePepper.js.map +1 -1
- package/dist/esm/hooks/types.d.ts +2 -0
- package/dist/esm/hooks/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/config.d.ts +7 -3
- package/dist/esm/lib/config.d.ts.map +1 -1
- package/dist/esm/lib/config.js +3 -3
- package/dist/esm/lib/config.js.map +1 -1
- package/dist/esm/lib/matchers.d.ts +6 -11
- package/dist/esm/lib/matchers.d.ts.map +1 -1
- package/dist/esm/lib/matchers.js +43 -30
- package/dist/esm/lib/matchers.js.map +1 -1
- package/dist/esm/lib/sdks.d.ts +4 -1
- package/dist/esm/lib/sdks.d.ts.map +1 -1
- package/dist/esm/lib/sdks.js +16 -16
- package/dist/esm/lib/sdks.js.map +1 -1
- package/dist/esm/mcp-server/mcp-server.js +1 -1
- package/dist/esm/mcp-server/server.js +1 -1
- package/dist/esm/models/components/apierrorcodes.d.ts +21 -0
- package/dist/esm/models/components/apierrorcodes.d.ts.map +1 -1
- package/dist/esm/models/components/apierrorcodes.js +7 -0
- package/dist/esm/models/components/apierrorcodes.js.map +1 -1
- package/dist/esm/models/errors/apierror.d.ts +8 -6
- package/dist/esm/models/errors/apierror.d.ts.map +1 -1
- package/dist/esm/models/errors/apierror.js +17 -10
- package/dist/esm/models/errors/apierror.js.map +1 -1
- package/dist/esm/models/errors/createpepperconsumer.d.ts +31 -10
- package/dist/esm/models/errors/createpepperconsumer.d.ts.map +1 -1
- package/dist/esm/models/errors/createpepperconsumer.js +56 -20
- package/dist/esm/models/errors/createpepperconsumer.js.map +1 -1
- package/dist/esm/models/errors/financeablelenderserror.d.ts +19 -0
- package/dist/esm/models/errors/financeablelenderserror.d.ts.map +1 -0
- package/dist/esm/models/errors/financeablelenderserror.js +16 -0
- package/dist/esm/models/errors/financeablelenderserror.js.map +1 -0
- package/dist/esm/models/errors/index.d.ts +1 -0
- package/dist/esm/models/errors/index.d.ts.map +1 -1
- package/dist/esm/models/errors/index.js +1 -0
- package/dist/esm/models/errors/index.js.map +1 -1
- package/dist/esm/models/errors/responsevalidationerror.d.ts +26 -0
- package/dist/esm/models/errors/responsevalidationerror.d.ts.map +1 -0
- package/dist/esm/models/errors/responsevalidationerror.js +29 -0
- package/dist/esm/models/errors/responsevalidationerror.js.map +1 -0
- package/dist/esm/models/errors/sdkvalidationerror.d.ts +1 -0
- package/dist/esm/models/errors/sdkvalidationerror.d.ts.map +1 -1
- package/dist/esm/models/errors/sdkvalidationerror.js +14 -0
- package/dist/esm/models/errors/sdkvalidationerror.js.map +1 -1
- package/docs/sdks/consumers/README.md +23 -39
- package/jsr.json +1 -1
- package/package.json +4 -4
- package/src/funcs/consumersCreatePepper.ts +23 -17
- package/src/hooks/types.ts +2 -0
- package/src/index.ts +2 -0
- package/src/lib/config.ts +7 -3
- package/src/lib/matchers.ts +64 -41
- package/src/lib/sdks.ts +29 -17
- package/src/mcp-server/mcp-server.ts +1 -1
- package/src/mcp-server/server.ts +1 -1
- package/src/models/components/apierrorcodes.ts +7 -0
- package/src/models/errors/apierror.ts +23 -16
- package/src/models/errors/createpepperconsumer.ts +75 -25
- package/src/models/errors/financeablelenderserror.ts +35 -0
- package/src/models/errors/index.ts +1 -0
- package/src/models/errors/responsevalidationerror.ts +50 -0
- package/src/models/errors/sdkvalidationerror.ts +12 -0
|
@@ -10,7 +10,7 @@ import { safeParse } from "../lib/schemas.js";
|
|
|
10
10
|
import { RequestOptions } from "../lib/sdks.js";
|
|
11
11
|
import { pathToFunc } from "../lib/url.js";
|
|
12
12
|
import * as components from "../models/components/index.js";
|
|
13
|
-
import {
|
|
13
|
+
import { FinanceableLendersError } from "../models/errors/financeablelenderserror.js";
|
|
14
14
|
import {
|
|
15
15
|
ConnectionError,
|
|
16
16
|
InvalidRequestError,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
UnexpectedClientError,
|
|
20
20
|
} from "../models/errors/httpclienterrors.js";
|
|
21
21
|
import * as errors from "../models/errors/index.js";
|
|
22
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
22
23
|
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
23
24
|
import * as operations from "../models/operations/index.js";
|
|
24
25
|
import { APICall, APIPromise } from "../types/async.js";
|
|
@@ -39,13 +40,14 @@ export function consumersCreatePepper(
|
|
|
39
40
|
| errors.CreatePepperConsumerConsumersResponseResponseBody
|
|
40
41
|
| errors.CreatePepperConsumerConsumersResponse404ResponseBody
|
|
41
42
|
| errors.CreatePepperConsumerConsumersResponse500ResponseBody
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
| InvalidRequestError
|
|
43
|
+
| FinanceableLendersError
|
|
44
|
+
| ResponseValidationError
|
|
45
|
+
| ConnectionError
|
|
46
46
|
| RequestAbortedError
|
|
47
47
|
| RequestTimeoutError
|
|
48
|
-
|
|
|
48
|
+
| InvalidRequestError
|
|
49
|
+
| UnexpectedClientError
|
|
50
|
+
| SDKValidationError
|
|
49
51
|
>
|
|
50
52
|
> {
|
|
51
53
|
return new APIPromise($do(
|
|
@@ -68,13 +70,14 @@ async function $do(
|
|
|
68
70
|
| errors.CreatePepperConsumerConsumersResponseResponseBody
|
|
69
71
|
| errors.CreatePepperConsumerConsumersResponse404ResponseBody
|
|
70
72
|
| errors.CreatePepperConsumerConsumersResponse500ResponseBody
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
| InvalidRequestError
|
|
73
|
+
| FinanceableLendersError
|
|
74
|
+
| ResponseValidationError
|
|
75
|
+
| ConnectionError
|
|
75
76
|
| RequestAbortedError
|
|
76
77
|
| RequestTimeoutError
|
|
77
|
-
|
|
|
78
|
+
| InvalidRequestError
|
|
79
|
+
| UnexpectedClientError
|
|
80
|
+
| SDKValidationError
|
|
78
81
|
>,
|
|
79
82
|
APICall,
|
|
80
83
|
]
|
|
@@ -98,6 +101,7 @@ async function $do(
|
|
|
98
101
|
}));
|
|
99
102
|
|
|
100
103
|
const context = {
|
|
104
|
+
options: client._options,
|
|
101
105
|
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
102
106
|
operationID: "createPepperConsumer",
|
|
103
107
|
oAuth2Scopes: [],
|
|
@@ -117,6 +121,7 @@ async function $do(
|
|
|
117
121
|
path: path,
|
|
118
122
|
headers: headers,
|
|
119
123
|
body: body,
|
|
124
|
+
userAgent: client._options.userAgent,
|
|
120
125
|
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
121
126
|
}, options);
|
|
122
127
|
if (!requestRes.ok) {
|
|
@@ -146,13 +151,14 @@ async function $do(
|
|
|
146
151
|
| errors.CreatePepperConsumerConsumersResponseResponseBody
|
|
147
152
|
| errors.CreatePepperConsumerConsumersResponse404ResponseBody
|
|
148
153
|
| errors.CreatePepperConsumerConsumersResponse500ResponseBody
|
|
149
|
-
|
|
|
150
|
-
|
|
|
151
|
-
|
|
|
152
|
-
| InvalidRequestError
|
|
154
|
+
| FinanceableLendersError
|
|
155
|
+
| ResponseValidationError
|
|
156
|
+
| ConnectionError
|
|
153
157
|
| RequestAbortedError
|
|
154
158
|
| RequestTimeoutError
|
|
155
|
-
|
|
|
159
|
+
| InvalidRequestError
|
|
160
|
+
| UnexpectedClientError
|
|
161
|
+
| SDKValidationError
|
|
156
162
|
>(
|
|
157
163
|
M.json(201, operations.CreatePepperConsumerResponseBody$inboundSchema),
|
|
158
164
|
M.jsonErr(400, errors.CreatePepperConsumerResponseBody$inboundSchema),
|
|
@@ -174,7 +180,7 @@ async function $do(
|
|
|
174
180
|
),
|
|
175
181
|
M.fail("4XX"),
|
|
176
182
|
M.fail("5XX"),
|
|
177
|
-
)(response, { extraFields: responseFields });
|
|
183
|
+
)(response, req, { extraFields: responseFields });
|
|
178
184
|
if (!result.ok) {
|
|
179
185
|
return [result, { status: "complete", request: req, response }];
|
|
180
186
|
}
|
package/src/hooks/types.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { SDKOptions } from "../lib/config.js";
|
|
5
6
|
import { HTTPClient, RequestInput } from "../lib/http.js";
|
|
6
7
|
import { RetryConfig } from "../lib/retries.js";
|
|
7
8
|
import { SecurityState } from "../lib/security.js";
|
|
@@ -13,6 +14,7 @@ export type HookContext = {
|
|
|
13
14
|
securitySource?: any | (() => Promise<any>);
|
|
14
15
|
retryConfig: RetryConfig;
|
|
15
16
|
resolvedSecurity: SecurityState | null;
|
|
17
|
+
options: SDKOptions;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
export type Awaitable<T> = T | Promise<T>;
|
package/src/index.ts
CHANGED
package/src/lib/config.ts
CHANGED
|
@@ -27,6 +27,10 @@ export type SDKOptions = {
|
|
|
27
27
|
* Allows overriding the default server URL used by the SDK
|
|
28
28
|
*/
|
|
29
29
|
serverURL?: string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Allows overriding the default user agent used by the SDK
|
|
32
|
+
*/
|
|
33
|
+
userAgent?: string | undefined;
|
|
30
34
|
/**
|
|
31
35
|
* Allows overriding the default retry config used by the SDK
|
|
32
36
|
*/
|
|
@@ -55,8 +59,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
55
59
|
export const SDK_METADATA = {
|
|
56
60
|
language: "typescript",
|
|
57
61
|
openapiDocVersion: "0.1.0",
|
|
58
|
-
sdkVersion: "0.0
|
|
59
|
-
genVersion: "2.
|
|
62
|
+
sdkVersion: "0.1.0",
|
|
63
|
+
genVersion: "2.624.0",
|
|
60
64
|
userAgent:
|
|
61
|
-
"speakeasy-sdk/typescript 0.0
|
|
65
|
+
"speakeasy-sdk/typescript 0.1.0 2.624.0 0.1.0 @financeable/lenders",
|
|
62
66
|
} as const;
|
package/src/lib/matchers.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { APIError } from "../models/errors/apierror.js";
|
|
6
|
-
import {
|
|
7
|
-
import { Result } from "../types/fp.js";
|
|
6
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
7
|
+
import { ERR, OK, Result } from "../types/fp.js";
|
|
8
8
|
import { matchResponse, matchStatusCode, StatusCodePredicate } from "./http.js";
|
|
9
9
|
import { isPlainObject } from "./is-plain-object.js";
|
|
10
|
-
import { safeParse } from "./schemas.js";
|
|
11
10
|
|
|
12
11
|
export type Encoding =
|
|
12
|
+
| "jsonl"
|
|
13
13
|
| "json"
|
|
14
14
|
| "text"
|
|
15
15
|
| "bytes"
|
|
@@ -19,6 +19,7 @@ export type Encoding =
|
|
|
19
19
|
| "fail";
|
|
20
20
|
|
|
21
21
|
const DEFAULT_CONTENT_TYPES: Record<Encoding, string> = {
|
|
22
|
+
jsonl: "application/jsonl",
|
|
22
23
|
json: "application/json",
|
|
23
24
|
text: "text/plain",
|
|
24
25
|
bytes: "application/octet-stream",
|
|
@@ -72,6 +73,21 @@ export function json<T>(
|
|
|
72
73
|
return { ...options, enc: "json", codes, schema };
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
export function jsonl<T>(
|
|
77
|
+
codes: StatusCodePredicate,
|
|
78
|
+
schema: Schema<T>,
|
|
79
|
+
options?: MatchOptions,
|
|
80
|
+
): ValueMatcher<T> {
|
|
81
|
+
return { ...options, enc: "jsonl", codes, schema };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function jsonlErr<E>(
|
|
85
|
+
codes: StatusCodePredicate,
|
|
86
|
+
schema: Schema<E>,
|
|
87
|
+
options?: MatchOptions,
|
|
88
|
+
): ErrorMatcher<E> {
|
|
89
|
+
return { ...options, err: true, enc: "jsonl", codes, schema };
|
|
90
|
+
}
|
|
75
91
|
export function textErr<E>(
|
|
76
92
|
codes: StatusCodePredicate,
|
|
77
93
|
schema: Schema<E>,
|
|
@@ -159,17 +175,19 @@ export type MatchedError<Matchers> = Matchers extends Matcher<any, infer E>[]
|
|
|
159
175
|
: never;
|
|
160
176
|
export type MatchFunc<T, E> = (
|
|
161
177
|
response: Response,
|
|
178
|
+
request: Request,
|
|
162
179
|
options?: { resultKey?: string; extraFields?: Record<string, unknown> },
|
|
163
180
|
) => Promise<[result: Result<T, E>, raw: unknown]>;
|
|
164
181
|
|
|
165
182
|
export function match<T, E>(
|
|
166
183
|
...matchers: Array<Matcher<T, E>>
|
|
167
|
-
): MatchFunc<T, E | APIError |
|
|
184
|
+
): MatchFunc<T, E | APIError | ResponseValidationError> {
|
|
168
185
|
return async function matchFunc(
|
|
169
186
|
response: Response,
|
|
187
|
+
request: Request,
|
|
170
188
|
options?: { resultKey?: string; extraFields?: Record<string, unknown> },
|
|
171
189
|
): Promise<
|
|
172
|
-
[result: Result<T, E | APIError |
|
|
190
|
+
[result: Result<T, E | APIError | ResponseValidationError>, raw: unknown]
|
|
173
191
|
> {
|
|
174
192
|
let raw: unknown;
|
|
175
193
|
let matcher: Matcher<T, E> | undefined;
|
|
@@ -188,21 +206,25 @@ export function match<T, E>(
|
|
|
188
206
|
}
|
|
189
207
|
|
|
190
208
|
if (!matcher) {
|
|
191
|
-
const responseBody = await response.text();
|
|
192
209
|
return [{
|
|
193
210
|
ok: false,
|
|
194
|
-
error: new APIError(
|
|
195
|
-
"Unexpected API response status or content-type",
|
|
211
|
+
error: new APIError("Unexpected Status or Content-Type", {
|
|
196
212
|
response,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
213
|
+
request,
|
|
214
|
+
body: await response.text().catch(() => ""),
|
|
215
|
+
}),
|
|
216
|
+
}, raw];
|
|
200
217
|
}
|
|
201
218
|
|
|
202
219
|
const encoding = matcher.enc;
|
|
220
|
+
let body = "";
|
|
203
221
|
switch (encoding) {
|
|
204
222
|
case "json":
|
|
205
|
-
|
|
223
|
+
body = await response.text();
|
|
224
|
+
raw = JSON.parse(body);
|
|
225
|
+
break;
|
|
226
|
+
case "jsonl":
|
|
227
|
+
raw = response.body;
|
|
206
228
|
break;
|
|
207
229
|
case "bytes":
|
|
208
230
|
raw = new Uint8Array(await response.arrayBuffer());
|
|
@@ -211,16 +233,19 @@ export function match<T, E>(
|
|
|
211
233
|
raw = response.body;
|
|
212
234
|
break;
|
|
213
235
|
case "text":
|
|
214
|
-
|
|
236
|
+
body = await response.text();
|
|
237
|
+
raw = body;
|
|
215
238
|
break;
|
|
216
239
|
case "sse":
|
|
217
240
|
raw = response.body;
|
|
218
241
|
break;
|
|
219
242
|
case "nil":
|
|
220
|
-
|
|
243
|
+
body = await response.text();
|
|
244
|
+
raw = undefined;
|
|
221
245
|
break;
|
|
222
246
|
case "fail":
|
|
223
|
-
|
|
247
|
+
body = await response.text();
|
|
248
|
+
raw = body;
|
|
224
249
|
break;
|
|
225
250
|
default:
|
|
226
251
|
encoding satisfies never;
|
|
@@ -230,11 +255,7 @@ export function match<T, E>(
|
|
|
230
255
|
if (matcher.enc === "fail") {
|
|
231
256
|
return [{
|
|
232
257
|
ok: false,
|
|
233
|
-
error: new APIError(
|
|
234
|
-
"API error occurred",
|
|
235
|
-
response,
|
|
236
|
-
typeof raw === "string" ? raw : "",
|
|
237
|
-
),
|
|
258
|
+
error: new APIError("API error occurred", { request, response, body }),
|
|
238
259
|
}, raw];
|
|
239
260
|
}
|
|
240
261
|
|
|
@@ -246,6 +267,9 @@ export function match<T, E>(
|
|
|
246
267
|
...options?.extraFields,
|
|
247
268
|
...(matcher.hdrs ? { Headers: unpackHeaders(response.headers) } : null),
|
|
248
269
|
...(isPlainObject(raw) ? raw : null),
|
|
270
|
+
request$: request,
|
|
271
|
+
response$: response,
|
|
272
|
+
body$: body,
|
|
249
273
|
};
|
|
250
274
|
} else if (resultKey) {
|
|
251
275
|
data = {
|
|
@@ -264,18 +288,20 @@ export function match<T, E>(
|
|
|
264
288
|
}
|
|
265
289
|
|
|
266
290
|
if ("err" in matcher) {
|
|
267
|
-
const result =
|
|
291
|
+
const result = safeParseResponse(
|
|
268
292
|
data,
|
|
269
293
|
(v: unknown) => matcher.schema.parse(v),
|
|
270
294
|
"Response validation failed",
|
|
295
|
+
{ request, response, body },
|
|
271
296
|
);
|
|
272
297
|
return [result.ok ? { ok: false, error: result.value } : result, raw];
|
|
273
298
|
} else {
|
|
274
299
|
return [
|
|
275
|
-
|
|
300
|
+
safeParseResponse(
|
|
276
301
|
data,
|
|
277
302
|
(v: unknown) => matcher.schema.parse(v),
|
|
278
303
|
"Response validation failed",
|
|
304
|
+
{ request, response, body },
|
|
279
305
|
),
|
|
280
306
|
raw,
|
|
281
307
|
];
|
|
@@ -298,25 +324,22 @@ export function unpackHeaders(headers: Headers): Record<string, string[]> {
|
|
|
298
324
|
return out;
|
|
299
325
|
}
|
|
300
326
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
export async function discardResponseBody(res: Response) {
|
|
308
|
-
const reader = res.body?.getReader();
|
|
309
|
-
if (reader == null) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
|
|
327
|
+
function safeParseResponse<Inp, Out>(
|
|
328
|
+
rawValue: Inp,
|
|
329
|
+
fn: (value: Inp) => Out,
|
|
330
|
+
errorMessage: string,
|
|
331
|
+
httpMeta: { response: Response; request: Request; body: string },
|
|
332
|
+
): Result<Out, ResponseValidationError> {
|
|
313
333
|
try {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
334
|
+
return OK(fn(rawValue));
|
|
335
|
+
} catch (err) {
|
|
336
|
+
return ERR(
|
|
337
|
+
new ResponseValidationError(errorMessage, {
|
|
338
|
+
cause: err,
|
|
339
|
+
rawValue,
|
|
340
|
+
rawMessage: errorMessage,
|
|
341
|
+
...httpMeta,
|
|
342
|
+
}),
|
|
343
|
+
);
|
|
321
344
|
}
|
|
322
345
|
}
|
package/src/lib/sdks.ts
CHANGED
|
@@ -47,12 +47,14 @@ export type RequestOptions = {
|
|
|
47
47
|
*/
|
|
48
48
|
serverURL?: string | URL;
|
|
49
49
|
/**
|
|
50
|
+
* @deprecated `fetchOptions` has been flattened into `RequestOptions`.
|
|
51
|
+
*
|
|
50
52
|
* Sets various request options on the `fetch` call made by an SDK method.
|
|
51
53
|
*
|
|
52
54
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options|Request}
|
|
53
55
|
*/
|
|
54
56
|
fetchOptions?: Omit<RequestInit, "method" | "body">;
|
|
55
|
-
}
|
|
57
|
+
} & Omit<RequestInit, "method" | "body">;
|
|
56
58
|
|
|
57
59
|
type RequestConfig = {
|
|
58
60
|
method: string;
|
|
@@ -63,6 +65,7 @@ type RequestConfig = {
|
|
|
63
65
|
headers?: HeadersInit;
|
|
64
66
|
security?: SecurityState | null;
|
|
65
67
|
uaHeader?: string;
|
|
68
|
+
userAgent?: string | undefined;
|
|
66
69
|
timeoutMs?: number;
|
|
67
70
|
};
|
|
68
71
|
|
|
@@ -94,19 +97,21 @@ export class ClientSDK {
|
|
|
94
97
|
} else {
|
|
95
98
|
this.#hooks = new SDKHooks();
|
|
96
99
|
}
|
|
97
|
-
this._options = { ...options, hooks: this.#hooks };
|
|
98
|
-
|
|
99
100
|
const url = serverURLFromOptions(options);
|
|
100
101
|
if (url) {
|
|
101
102
|
url.pathname = url.pathname.replace(/\/+$/, "") + "/";
|
|
102
103
|
}
|
|
104
|
+
|
|
103
105
|
const { baseURL, client } = this.#hooks.sdkInit({
|
|
104
106
|
baseURL: url,
|
|
105
107
|
client: options.httpClient || new HTTPClient(),
|
|
106
108
|
});
|
|
107
109
|
this._baseURL = baseURL;
|
|
108
110
|
this.#httpClient = client;
|
|
109
|
-
|
|
111
|
+
|
|
112
|
+
this._options = { ...options, hooks: this.#hooks };
|
|
113
|
+
|
|
114
|
+
this.#logger = this._options.debugLogger;
|
|
110
115
|
if (!this.#logger && env().FINACEABLELENDERS_DEBUG) {
|
|
111
116
|
this.#logger = console;
|
|
112
117
|
}
|
|
@@ -172,7 +177,9 @@ export class ClientSDK {
|
|
|
172
177
|
cookie = cookie.startsWith("; ") ? cookie.slice(2) : cookie;
|
|
173
178
|
headers.set("cookie", cookie);
|
|
174
179
|
|
|
175
|
-
const userHeaders = new Headers(
|
|
180
|
+
const userHeaders = new Headers(
|
|
181
|
+
options?.headers ?? options?.fetchOptions?.headers,
|
|
182
|
+
);
|
|
176
183
|
for (const [k, v] of userHeaders) {
|
|
177
184
|
headers.set(k, v);
|
|
178
185
|
}
|
|
@@ -180,23 +187,22 @@ export class ClientSDK {
|
|
|
180
187
|
// Only set user agent header in non-browser-like environments since CORS
|
|
181
188
|
// policy disallows setting it in browsers e.g. Chrome throws an error.
|
|
182
189
|
if (!isBrowserLike) {
|
|
183
|
-
headers.set(
|
|
190
|
+
headers.set(
|
|
191
|
+
conf.uaHeader ?? "user-agent",
|
|
192
|
+
conf.userAgent ?? SDK_METADATA.userAgent,
|
|
193
|
+
);
|
|
184
194
|
}
|
|
185
195
|
|
|
186
|
-
|
|
196
|
+
const fetchOptions: Omit<RequestInit, "method" | "body"> = {
|
|
197
|
+
...options?.fetchOptions,
|
|
198
|
+
...options,
|
|
199
|
+
};
|
|
187
200
|
if (!fetchOptions?.signal && conf.timeoutMs && conf.timeoutMs > 0) {
|
|
188
201
|
const timeoutSignal = AbortSignal.timeout(conf.timeoutMs);
|
|
189
|
-
|
|
190
|
-
fetchOptions = { signal: timeoutSignal };
|
|
191
|
-
} else {
|
|
192
|
-
fetchOptions.signal = timeoutSignal;
|
|
193
|
-
}
|
|
202
|
+
fetchOptions.signal = timeoutSignal;
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
if (conf.body instanceof ReadableStream) {
|
|
197
|
-
if (!fetchOptions) {
|
|
198
|
-
fetchOptions = {};
|
|
199
|
-
}
|
|
200
206
|
Object.assign(fetchOptions, { duplex: "half" });
|
|
201
207
|
}
|
|
202
208
|
|
|
@@ -302,7 +308,9 @@ export class ClientSDK {
|
|
|
302
308
|
}
|
|
303
309
|
}
|
|
304
310
|
|
|
305
|
-
const jsonLikeContentTypeRE =
|
|
311
|
+
const jsonLikeContentTypeRE = /(application|text)\/.*?\+*json.*/;
|
|
312
|
+
const jsonlLikeContentTypeRE =
|
|
313
|
+
/(application|text)\/(.*?\+*\bjsonl\b.*|.*?\+*\bx-ndjson\b.*)/;
|
|
306
314
|
async function logRequest(logger: Logger | undefined, req: Request) {
|
|
307
315
|
if (!logger) {
|
|
308
316
|
return;
|
|
@@ -368,9 +376,13 @@ async function logResponse(
|
|
|
368
376
|
logger.group("Body:");
|
|
369
377
|
switch (true) {
|
|
370
378
|
case matchContentType(res, "application/json")
|
|
371
|
-
|| jsonLikeContentTypeRE.test(ct):
|
|
379
|
+
|| jsonLikeContentTypeRE.test(ct) && !jsonlLikeContentTypeRE.test(ct):
|
|
372
380
|
logger.log(await res.clone().json());
|
|
373
381
|
break;
|
|
382
|
+
case matchContentType(res, "application/jsonl")
|
|
383
|
+
|| jsonlLikeContentTypeRE.test(ct):
|
|
384
|
+
logger.log(await res.clone().text());
|
|
385
|
+
break;
|
|
374
386
|
case matchContentType(res, "text/event-stream"):
|
|
375
387
|
logger.log(`<${contentType}>`);
|
|
376
388
|
break;
|
package/src/mcp-server/server.ts
CHANGED
|
@@ -18,6 +18,13 @@ export const ApiErrorCodes = {
|
|
|
18
18
|
NotFound: "NOT_FOUND",
|
|
19
19
|
MethodNotAllowed: "METHOD_NOT_ALLOWED",
|
|
20
20
|
Conflict: "CONFLICT",
|
|
21
|
+
MissingDocumentError: "MISSING_DOCUMENT_ERROR",
|
|
22
|
+
MaxRetriesExceededError: "MAX_RETRIES_EXCEEDED_ERROR",
|
|
23
|
+
DocumentFileTransferError: "DOCUMENT_FILE_TRANSFER_ERROR",
|
|
24
|
+
DocumentProcessingError: "DOCUMENT_PROCESSING_ERROR",
|
|
25
|
+
DocumentValidationError: "DOCUMENT_VALIDATION_ERROR",
|
|
26
|
+
DocumentExpiredError: "DOCUMENT_EXPIRED_ERROR",
|
|
27
|
+
DocumentInvalidError: "DOCUMENT_INVALID_ERROR",
|
|
21
28
|
} as const;
|
|
22
29
|
export type ApiErrorCodes = ClosedEnum<typeof ApiErrorCodes>;
|
|
23
30
|
|
|
@@ -2,26 +2,33 @@
|
|
|
2
2
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
public readonly statusCode: number;
|
|
7
|
-
public readonly contentType: string;
|
|
5
|
+
import { FinanceableLendersError } from "./financeablelenderserror.js";
|
|
8
6
|
|
|
7
|
+
/** The fallback error class if no more specific error class is matched */
|
|
8
|
+
export class APIError extends FinanceableLendersError {
|
|
9
9
|
constructor(
|
|
10
10
|
message: string,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
httpMeta: {
|
|
12
|
+
response: Response;
|
|
13
|
+
request: Request;
|
|
14
|
+
body: string;
|
|
15
|
+
},
|
|
13
16
|
) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
if (message) {
|
|
18
|
+
message += `: `;
|
|
19
|
+
}
|
|
20
|
+
message += `Status ${httpMeta.response.status}`;
|
|
21
|
+
const contentType = httpMeta.response.headers.get("content-type") || `""`;
|
|
22
|
+
if (contentType !== "application/json") {
|
|
23
|
+
message += ` Content-Type ${
|
|
24
|
+
contentType.includes(" ") ? `"${contentType}"` : contentType
|
|
25
|
+
}`;
|
|
26
|
+
}
|
|
27
|
+
const body = httpMeta.body || `""`;
|
|
28
|
+
message += body.length > 100 ? "\n" : " ";
|
|
29
|
+
message += `Body ${body}`;
|
|
30
|
+
message = message.trim();
|
|
31
|
+
super(message, httpMeta);
|
|
25
32
|
this.name = "APIError";
|
|
26
33
|
}
|
|
27
34
|
}
|