Skip to content

Commit 7424d98

Browse files
author
NumaryBot
committed
release(sdk): v2.0.0-beta.8
1 parent e034861 commit 7424d98

File tree

641 files changed

+46010
-32531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

641 files changed

+46010
-32531
lines changed

.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-env node */
2+
module.exports = {
3+
root: true,
4+
extends: [
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:import/recommended",
8+
"plugin:import/typescript",
9+
],
10+
parser: "@typescript-eslint/parser",
11+
plugins: ["@typescript-eslint"],
12+
settings: {
13+
"import/resolver": {
14+
typescript: true,
15+
node: true,
16+
},
17+
},
18+
rules: {
19+
// Handled by typescript compiler
20+
"@typescript-eslint/no-unused-vars": "off",
21+
"@typescript-eslint/ban-types": "off",
22+
"@typescript-eslint/no-namespace": "off",
23+
"@typescript-eslint/no-explicit-any": "off",
24+
"import/no-named-as-default-member": "off",
25+
26+
"import/no-default-export": "error",
27+
},
28+
};

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
dist/
2-
node_modules/
1+
/models
2+
/sdk/models/errors
3+
/sdk/types
4+
/lib
5+
/sdk
6+
/index.*
7+
/cjs
8+
/node_modules
9+
/.tsbuildinfo

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
/docs/**/*.md
3+
!/**/*.ts
4+
!/**/*.js
5+
!/**/*.map
6+
7+
/.eslintrc.js
8+
/cjs

.speakeasy/gen.lock

Lines changed: 1106 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ async function run() {
4747

4848
const res = await sdk.getVersions();
4949

50-
if (res.statusCode == 200) {
51-
// handle response
50+
if (res?.statusCode !== 200) {
51+
throw new Error("Unexpected status code: " + res?.statusCode || "-");
5252
}
53+
54+
// handle response
5355
}
5456

5557
run();
@@ -71,7 +73,6 @@ run();
7173
* [createSecret](docs/sdks/auth/README.md#createsecret) - Add a secret to a client
7274
* [deleteClient](docs/sdks/auth/README.md#deleteclient) - Delete client
7375
* [deleteSecret](docs/sdks/auth/README.md#deletesecret) - Delete a secret from a client
74-
* [getServerInfo](docs/sdks/auth/README.md#getserverinfo) - Get server info
7576
* [listClients](docs/sdks/auth/README.md#listclients) - List clients
7677
* [listUsers](docs/sdks/auth/README.md#listusers) - List users
7778
* [readClient](docs/sdks/auth/README.md#readclient) - Read client
@@ -247,45 +248,46 @@ run();
247248
<!-- Start Error Handling [errors] -->
248249
## Error Handling
249250

250-
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
251+
All SDK methods return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
251252

252253
| Error Object | Status Code | Content Type |
253254
| -------------------- | -------------------- | -------------------- |
254255
| errors.ErrorResponse | 400,404 | application/json |
255-
| errors.SDKError | 400-600 | */* |
256+
| errors.SDKError | 4xx-5xx | */* |
256257

257258
Example
258259

259260
```typescript
260261
import { SDK } from "@formance/formance-sdk";
262+
import * as errors from "@formance/formance-sdk/sdk/models/errors";
261263

262264
async function run() {
263265
const sdk = new SDK({
264266
authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
265267
});
266268

267-
let res;
268-
try {
269-
res = await sdk.ledger.addMetadataToAccount({
269+
const res = await sdk.ledger
270+
.addMetadataToAccount({
270271
requestBody: {
271272
key: "string",
272273
},
273274
address: "users:001",
274275
ledger: "ledger001",
276+
})
277+
.catch((err) => {
278+
if (err instanceof errors.ErrorResponse) {
279+
console.error(err); // handle exception
280+
return null;
281+
} else {
282+
throw err;
283+
}
275284
});
276-
} catch (err) {
277-
if (err instanceof errors.ErrorResponse) {
278-
console.error(err); // handle exception
279-
throw err;
280-
} else if (err instanceof errors.SDKError) {
281-
console.error(err); // handle exception
282-
throw err;
283-
}
284-
}
285285

286-
if (res.statusCode == 200) {
287-
// handle response
286+
if (res?.statusCode !== 200) {
287+
throw new Error("Unexpected status code: " + res?.statusCode || "-");
288288
}
289+
290+
// handle response
289291
}
290292

291293
run();
@@ -304,69 +306,60 @@ You can override the default server globally by passing a server index to the `s
304306
| - | ------ | --------- |
305307
| 0 | `http://localhost` | None |
306308

307-
#### Example
308-
309-
```typescript
310-
import { SDK } from "@formance/formance-sdk";
311-
312-
async function run() {
313-
const sdk = new SDK({
314-
serverIdx: 0,
315-
authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
316-
});
317-
318-
const res = await sdk.getVersions();
319-
320-
if (res.statusCode == 200) {
321-
// handle response
322-
}
323-
}
324-
325-
run();
326309

327-
```
328310

329311

330312
### Override Server URL Per-Client
331313

332314
The default server can also be overridden globally by passing a URL to the `serverURL: str` optional parameter when initializing the SDK client instance. For example:
333-
```typescript
334-
import { SDK } from "@formance/formance-sdk";
315+
<!-- End Server Selection [server] -->
335316

336-
async function run() {
337-
const sdk = new SDK({
338-
serverURL: "http://localhost",
339-
authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
340-
});
317+
<!-- Start Custom HTTP Client [http-client] -->
318+
## Custom HTTP Client
341319

342-
const res = await sdk.getVersions();
320+
The TypeScript SDK makes API calls using an `HTTPClient` that wraps the native
321+
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This
322+
client is a thin wrapper around `fetch` and provides the ability to attach hooks
323+
around the request lifecycle that can be used to modify the request or handle
324+
errors and response.
343325

344-
if (res.statusCode == 200) {
345-
// handle response
346-
}
347-
}
326+
The `HTTPClient` constructor takes an optional `fetcher` argument that can be
327+
used to integrate a third-party HTTP client or when writing tests to mock out
328+
the HTTP client and feed in fixtures.
348329

349-
run();
330+
The following example shows how to use the `"beforeRequest"` hook to to add a
331+
custom header and a timeout to requests and how to use the `"requestError"` hook
332+
to log errors:
350333

351-
```
352-
<!-- End Server Selection [server] -->
334+
```typescript
335+
import { SDK } from "@formance/formance-sdk";
336+
import { HTTPClient } from "@formance/formance-sdk/lib/http";
353337

354-
<!-- Start Custom HTTP Client [http-client] -->
355-
## Custom HTTP Client
338+
const httpClient = new HTTPClient({
339+
// fetcher takes a function that has the same signature as native `fetch`.
340+
fetcher: (request) => {
341+
return fetch(request);
342+
}
343+
});
356344

357-
The Typescript SDK makes API calls using the [axios](https://axios-http.com/docs/intro) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom `AxiosInstance` object.
345+
httpClient.addHook("beforeRequest", (request) => {
346+
const nextRequest = new Request(request, {
347+
signal: request.signal || AbortSignal.timeout(5000);
348+
});
358349

359-
For example, you could specify a header for every request that your sdk makes as follows:
350+
nextRequest.headers.set("x-custom-header", "custom value");
360351

361-
```typescript
362-
import { @formance/formance-sdk } from "SDK";
363-
import axios from "axios";
352+
return nextRequest;
353+
});
364354

365-
const httpClient = axios.create({
366-
headers: {'x-custom-header': 'someValue'}
367-
})
355+
httpClient.addHook("requestError", (error, request) => {
356+
console.group("Request Error");
357+
console.log("Reason:", `${error}`);
358+
console.log("Endpoint:", `${request.method} ${request.url}`);
359+
console.groupEnd();
360+
});
368361

369-
const sdk = new SDK({defaultClient: httpClient});
362+
const sdk = new SDK({ httpClient });
370363
```
371364
<!-- End Custom HTTP Client [http-client] -->
372365

@@ -392,9 +385,11 @@ async function run() {
392385

393386
const res = await sdk.getVersions();
394387

395-
if (res.statusCode == 200) {
396-
// handle response
388+
if (res?.statusCode !== 200) {
389+
throw new Error("Unexpected status code: " + res?.statusCode || "-");
397390
}
391+
392+
// handle response
398393
}
399394

400395
run();

USAGE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ async function run() {
99

1010
const res = await sdk.getVersions();
1111

12-
if (res.statusCode == 200) {
13-
// handle response
12+
if (res?.statusCode !== 200) {
13+
throw new Error("Unexpected status code: " + res?.statusCode || "-");
1414
}
15+
16+
// handle response
1517
}
1618

1719
run();

docs/sdk/models/operations/activateconfigresponse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
| `configResponse` | [shared.ConfigResponse](../../../sdk/models/shared/configresponse.md) | :heavy_minus_sign: | Config successfully activated. |
99
| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
1010
| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation |
11-
| `rawResponse` | [AxiosResponse](https://axios-http.com/docs/res_schema) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
11+
| `rawResponse` | [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
1212
| `webhooksErrorResponse` | *errors.WebhooksErrorResponse* | :heavy_minus_sign: | Error |

docs/sdk/models/operations/addaccounttopoolresponse.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
## Fields
55

6-
| Field | Type | Required | Description |
7-
| ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- |
8-
| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
9-
| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation |
10-
| `rawResponse` | [AxiosResponse](https://axios-http.com/docs/res_schema) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
6+
| Field | Type | Required | Description |
7+
| --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- |
8+
| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
9+
| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation |
10+
| `rawResponse` | [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |

docs/sdk/models/operations/addmetadataontransactionresponse.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
## Fields
55

6-
| Field | Type | Required | Description |
7-
| ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- |
8-
| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
9-
| `errorResponse` | *errors.ErrorResponse* | :heavy_minus_sign: | Error |
10-
| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation |
11-
| `rawResponse` | [AxiosResponse](https://axios-http.com/docs/res_schema) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
6+
| Field | Type | Required | Description |
7+
| --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- |
8+
| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
9+
| `errorResponse` | *errors.ErrorResponse* | :heavy_minus_sign: | Error |
10+
| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation |
11+
| `rawResponse` | [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |

docs/sdk/models/operations/addmetadatatoaccountresponse.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
## Fields
55

6-
| Field | Type | Required | Description |
7-
| ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- |
8-
| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
9-
| `errorResponse` | *errors.ErrorResponse* | :heavy_minus_sign: | Error |
10-
| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation |
11-
| `rawResponse` | [AxiosResponse](https://axios-http.com/docs/res_schema) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |
6+
| Field | Type | Required | Description |
7+
| --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- |
8+
| `contentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation |
9+
| `errorResponse` | *errors.ErrorResponse* | :heavy_minus_sign: | Error |
10+
| `statusCode` | *number* | :heavy_check_mark: | HTTP response status code for this operation |
11+
| `rawResponse` | [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) | :heavy_check_mark: | Raw HTTP response; suitable for custom response parsing |

0 commit comments

Comments
 (0)