dutchman-bridge 1.0.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/README.md +212 -0
- package/dist/client/client.gen.d.ts +2 -0
- package/dist/client/client.gen.js +220 -0
- package/dist/client/index.d.ts +10 -0
- package/dist/client/index.js +17 -0
- package/dist/client/types.gen.d.ts +120 -0
- package/dist/client/types.gen.js +3 -0
- package/dist/client/utils.gen.d.ts +37 -0
- package/dist/client/utils.gen.js +241 -0
- package/dist/client.gen.d.ts +12 -0
- package/dist/client.gen.js +6 -0
- package/dist/core/auth.gen.d.ts +25 -0
- package/dist/core/auth.gen.js +18 -0
- package/dist/core/bodySerializer.gen.d.ts +25 -0
- package/dist/core/bodySerializer.gen.js +60 -0
- package/dist/core/params.gen.d.ts +43 -0
- package/dist/core/params.gen.js +112 -0
- package/dist/core/pathSerializer.gen.d.ts +33 -0
- package/dist/core/pathSerializer.gen.js +115 -0
- package/dist/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/core/queryKeySerializer.gen.js +98 -0
- package/dist/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/core/serverSentEvents.gen.js +135 -0
- package/dist/core/types.gen.d.ts +83 -0
- package/dist/core/types.gen.js +3 -0
- package/dist/core/utils.gen.d.ts +19 -0
- package/dist/core/utils.gen.js +93 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/sdk.gen.d.ts +339 -0
- package/dist/sdk.gen.js +794 -0
- package/dist/types.gen.d.ts +1935 -0
- package/dist/types.gen.js +3 -0
- package/package.json +32 -0
- package/src/client/client.gen.ts +277 -0
- package/src/client/index.ts +27 -0
- package/src/client/types.gen.ts +218 -0
- package/src/client/utils.gen.ts +316 -0
- package/src/client.gen.ts +16 -0
- package/src/core/auth.gen.ts +48 -0
- package/src/core/bodySerializer.gen.ts +82 -0
- package/src/core/params.gen.ts +178 -0
- package/src/core/pathSerializer.gen.ts +171 -0
- package/src/core/queryKeySerializer.gen.ts +117 -0
- package/src/core/serverSentEvents.gen.ts +242 -0
- package/src/core/types.gen.ts +110 -0
- package/src/core/utils.gen.ts +140 -0
- package/src/index.ts +5 -0
- package/src/sdk.gen.ts +887 -0
- package/src/types.gen.ts +2178 -0
package/README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# dutchman-bridge
|
|
2
|
+
|
|
3
|
+
TypeScript client for the [Dutchman Bridge](https://dutchmannetwork.online) Partner API.
|
|
4
|
+
It is generated from the API's OpenAPI specification, so every route, request body
|
|
5
|
+
and response is typed, and it is regenerated whenever the API changes.
|
|
6
|
+
|
|
7
|
+
- Runtime: Node 18+ (uses the global `fetch`) or any modern browser runtime — but keep
|
|
8
|
+
your API key on the server; never ship it to a browser.
|
|
9
|
+
- Ships compiled JavaScript (`dist/`) with `.d.ts` typings, plus the TypeScript
|
|
10
|
+
source (`src/`). No runtime dependencies, and nothing is compiled on install.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
The package is distributed from a private GitHub repository you have been given read
|
|
15
|
+
access to. Pin a tag in your `package.json`:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"dutchman-bridge": "github:Dutchman-io/dutchman-bridge-sdk#v1.0.0"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
or `npm install github:Dutchman-io/dutchman-bridge-sdk#v1.0.0`. npm needs credentials
|
|
26
|
+
that can read the repository — an SSH key or a `GITHUB_TOKEN`/git credential helper on
|
|
27
|
+
the machine running the install (including CI).
|
|
28
|
+
|
|
29
|
+
## Configure
|
|
30
|
+
|
|
31
|
+
Set the base URL and your API key once. The key is sent as the `x-api-key` header on
|
|
32
|
+
every request; it is issued from the partner console (*Dashboard → API key*).
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { client, DutchmanBridge } from 'dutchman-bridge';
|
|
36
|
+
|
|
37
|
+
client.setConfig({
|
|
38
|
+
baseUrl: 'https://app.dutchmannetwork.online',
|
|
39
|
+
// Called before each request; the value is sent as the x-api-key header.
|
|
40
|
+
auth: () => process.env.BRIDGE_API_KEY,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const bridge = new DutchmanBridge();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`auth` may also be a plain string. Setting the header yourself works too and is
|
|
47
|
+
equivalent: `client.setConfig({ baseUrl, headers: { 'x-api-key': apiKey } })`.
|
|
48
|
+
|
|
49
|
+
Need more than one key in the same process (several partner accounts)? Build a
|
|
50
|
+
dedicated client and hand it to the SDK:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { DutchmanBridge } from 'dutchman-bridge';
|
|
54
|
+
import { createClient, createConfig } from 'dutchman-bridge/dist/client';
|
|
55
|
+
|
|
56
|
+
const own = createClient(createConfig({ baseUrl, auth: otherApiKey }));
|
|
57
|
+
const other = new DutchmanBridge({ client: own });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Calling the API
|
|
61
|
+
|
|
62
|
+
`DutchmanBridge` exposes one property per API group. Each method takes a single
|
|
63
|
+
options object with `path`, `query` and/or `body`, and resolves to
|
|
64
|
+
`{ data, error, request, response }` — it never throws on an HTTP error unless you ask
|
|
65
|
+
it to (see [Errors](#errors)).
|
|
66
|
+
|
|
67
|
+
| Property | Routes |
|
|
68
|
+
| -------------------- | ------------------------------------------ |
|
|
69
|
+
| `bridge.customers` | register / fetch customers |
|
|
70
|
+
| `bridge.kyc` | KYC tiers, documents, status |
|
|
71
|
+
| `bridge.profile` | profile, settlement mode, withdrawals |
|
|
72
|
+
| `bridge.wallet` | balances, addresses, transactions, funding |
|
|
73
|
+
| `bridge.send` | on-chain sends |
|
|
74
|
+
| `bridge.globalSend` | cross-border payouts |
|
|
75
|
+
| `bridge.ramp` | buy / sell quotes and execution |
|
|
76
|
+
| `bridge.bank` | bank accounts |
|
|
77
|
+
| `bridge.receiving` | receiving accounts |
|
|
78
|
+
| `bridge.countries`, `bridge.features` | reference data |
|
|
79
|
+
| `bridge.webhook` | webhook URL, secret, deliveries, replay |
|
|
80
|
+
|
|
81
|
+
The classes are also exported individually (`Customers`, `Kyc`, `Webhook`, ...) if you
|
|
82
|
+
prefer `new Customers().register(...)`; they use the shared `client` unless given one.
|
|
83
|
+
|
|
84
|
+
### Responses
|
|
85
|
+
|
|
86
|
+
Every successful Partner API response is an envelope:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{ "success": true, "data": { ... } }
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Paginated lists add `meta.nextCursor`. The SDK types the whole envelope, so the payload
|
|
93
|
+
is `result.data.data`.
|
|
94
|
+
|
|
95
|
+
### 1. Register a customer
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const { data, error } = await bridge.customers.register({
|
|
99
|
+
body: {
|
|
100
|
+
firstName: 'Ada',
|
|
101
|
+
lastName: 'Okafor',
|
|
102
|
+
email: 'ada@example.com',
|
|
103
|
+
phoneNumber: '+2348012345678',
|
|
104
|
+
country: 'NG', // ISO alpha-2
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
if (error) throw error;
|
|
108
|
+
|
|
109
|
+
const customer = data.data; // PartnerCustomerDto
|
|
110
|
+
console.log(data.success, customer.id);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Store `customer.id`: every customer-scoped route takes it as `path.customerId`.
|
|
114
|
+
|
|
115
|
+
### 2. Submit Tier-1 KYC
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const { data, error } = await bridge.kyc.tier1({
|
|
119
|
+
path: { customerId: customer.id },
|
|
120
|
+
body: { bvn: '12345678901', nin: '12345678901' },
|
|
121
|
+
});
|
|
122
|
+
if (error) throw error;
|
|
123
|
+
console.log(data.data.status);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Poll `bridge.kyc.status({ path: { customerId } })`, or subscribe to the `kyc.*`
|
|
127
|
+
webhooks instead of polling.
|
|
128
|
+
|
|
129
|
+
### 3. List withdrawals, page by page
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
let cursor: string | undefined;
|
|
133
|
+
do {
|
|
134
|
+
const { data, error } = await bridge.profile.withdrawals({
|
|
135
|
+
path: { customerId: customer.id },
|
|
136
|
+
query: { limit: 50, cursor },
|
|
137
|
+
});
|
|
138
|
+
if (error) throw error;
|
|
139
|
+
|
|
140
|
+
for (const withdrawal of data.data) {
|
|
141
|
+
console.log(withdrawal.id, withdrawal.status, withdrawal.amount, withdrawal.currency);
|
|
142
|
+
}
|
|
143
|
+
cursor = data.meta.nextCursor ?? undefined; // null on the last page
|
|
144
|
+
} while (cursor);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Errors
|
|
148
|
+
|
|
149
|
+
On a non-2xx status `error` is the parsed JSON body and `data` is `undefined`. The API
|
|
150
|
+
answers every error in one shape:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
interface BridgeApiError {
|
|
154
|
+
success: false;
|
|
155
|
+
statusCode: number; // e.g. 401, 404, 409, 422
|
|
156
|
+
code: string; // stable machine-readable code, e.g. "UNAUTHORIZED"
|
|
157
|
+
message: string; // human-readable summary
|
|
158
|
+
error: string; // HTTP reason phrase
|
|
159
|
+
timestamp: string; // ISO-8601
|
|
160
|
+
path: string; // the request path
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Because the specification does not enumerate error responses, `error` is typed
|
|
165
|
+
`unknown`; narrow it with a cast or a type guard:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
const { data, error } = await bridge.wallet.balance({ path: { customerId } });
|
|
169
|
+
if (error) {
|
|
170
|
+
const err = error as BridgeApiError;
|
|
171
|
+
if (err.statusCode === 401) {
|
|
172
|
+
/* rotate the key from the partner console */
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`${err.code}: ${err.message}`);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Prefer exceptions? `client.setConfig({ throwOnError: true })` makes every call throw
|
|
179
|
+
the same object instead of returning it, and `data` is then always defined.
|
|
180
|
+
|
|
181
|
+
Network failures (DNS, timeouts) reject the promise as usual.
|
|
182
|
+
|
|
183
|
+
## Webhooks
|
|
184
|
+
|
|
185
|
+
Deposits, KYC state changes and withdrawal results are pushed to your backend. Register
|
|
186
|
+
a URL with `bridge.webhook.setUrl(...)`, verify each delivery's signature with the
|
|
187
|
+
secret from `bridge.webhook.config(...)`, and inspect or replay deliveries with
|
|
188
|
+
`bridge.webhook.deliveries` / `bridge.webhook.replay`. The envelope, event catalogue and
|
|
189
|
+
signature scheme are documented in the Webhooks guide of the API documentation
|
|
190
|
+
(`docs/docs/partner-webhooks.md` in the API repository; ask your Dutchman contact for
|
|
191
|
+
the hosted copy). The full OpenAPI specification this SDK is generated from is served
|
|
192
|
+
at `https://app.dutchmannetwork.online/api/docs`.
|
|
193
|
+
|
|
194
|
+
## Versioning
|
|
195
|
+
|
|
196
|
+
Tags follow `package.json` (`v1.0.0`, `v1.0.1`, ...). The `main` branch always holds
|
|
197
|
+
the latest generation and may move between tags; pin a tag in production.
|
|
198
|
+
|
|
199
|
+
## How this package is produced
|
|
200
|
+
|
|
201
|
+
`src/` is generated by [`@hey-api/openapi-ts`](https://heyapi.dev) from the Partner
|
|
202
|
+
API's OpenAPI document (`openapi-ts.config.ts`, only the `Partner API - *` routes), and
|
|
203
|
+
`dist/` is that source compiled with `tsc`. Both are committed on purpose: a git
|
|
204
|
+
dependency then needs no `prepare` step, so installs work with `--ignore-scripts`, with
|
|
205
|
+
pnpm/yarn as well as npm, and without the partner compiling TypeScript.
|
|
206
|
+
|
|
207
|
+
- `SPEC_SOURCE=<path or URL> npm run regenerate` regenerates and rebuilds. Unset, it
|
|
208
|
+
reads `../backend/docs/static/openapi.json` from a sibling backend checkout.
|
|
209
|
+
- The `Regenerate SDK` workflow does the same from production's
|
|
210
|
+
`https://app.dutchmannetwork.online/api/docs-json` on demand or weekly, and commits,
|
|
211
|
+
bumps the patch version and tags when the output changed. Production serves the spec
|
|
212
|
+
of the backend that is deployed, so regenerate after a backend deploy, not before.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createClient = void 0;
|
|
5
|
+
const serverSentEvents_gen_1 = require("../core/serverSentEvents.gen");
|
|
6
|
+
const utils_gen_1 = require("../core/utils.gen");
|
|
7
|
+
const utils_gen_2 = require("./utils.gen");
|
|
8
|
+
const createClient = (config = {}) => {
|
|
9
|
+
let _config = (0, utils_gen_2.mergeConfigs)((0, utils_gen_2.createConfig)(), config);
|
|
10
|
+
const getConfig = () => ({ ..._config });
|
|
11
|
+
const setConfig = (config) => {
|
|
12
|
+
_config = (0, utils_gen_2.mergeConfigs)(_config, config);
|
|
13
|
+
return getConfig();
|
|
14
|
+
};
|
|
15
|
+
const interceptors = (0, utils_gen_2.createInterceptors)();
|
|
16
|
+
const beforeRequest = async (options) => {
|
|
17
|
+
const opts = {
|
|
18
|
+
..._config,
|
|
19
|
+
...options,
|
|
20
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
21
|
+
headers: (0, utils_gen_2.mergeHeaders)(_config.headers, options.headers),
|
|
22
|
+
serializedBody: undefined,
|
|
23
|
+
};
|
|
24
|
+
if (opts.security) {
|
|
25
|
+
await (0, utils_gen_2.setAuthParams)(opts);
|
|
26
|
+
}
|
|
27
|
+
if (opts.requestValidator) {
|
|
28
|
+
await opts.requestValidator(opts);
|
|
29
|
+
}
|
|
30
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
31
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
32
|
+
}
|
|
33
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
34
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
35
|
+
opts.headers.delete('Content-Type');
|
|
36
|
+
}
|
|
37
|
+
const resolvedOpts = opts;
|
|
38
|
+
const url = (0, utils_gen_2.buildUrl)(resolvedOpts);
|
|
39
|
+
return { opts: resolvedOpts, url };
|
|
40
|
+
};
|
|
41
|
+
const request = async (options) => {
|
|
42
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
43
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
44
|
+
let request;
|
|
45
|
+
let response;
|
|
46
|
+
try {
|
|
47
|
+
const { opts, url } = await beforeRequest(options);
|
|
48
|
+
const requestInit = {
|
|
49
|
+
redirect: 'follow',
|
|
50
|
+
...opts,
|
|
51
|
+
body: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
52
|
+
};
|
|
53
|
+
request = new Request(url, requestInit);
|
|
54
|
+
for (const fn of interceptors.request.fns) {
|
|
55
|
+
if (fn) {
|
|
56
|
+
request = await fn(request, opts);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
60
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
61
|
+
const _fetch = opts.fetch;
|
|
62
|
+
response = await _fetch(request);
|
|
63
|
+
for (const fn of interceptors.response.fns) {
|
|
64
|
+
if (fn) {
|
|
65
|
+
response = await fn(response, request, opts);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const result = {
|
|
69
|
+
request,
|
|
70
|
+
response,
|
|
71
|
+
};
|
|
72
|
+
if (response.ok) {
|
|
73
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
74
|
+
? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
|
|
75
|
+
: opts.parseAs) ?? 'json';
|
|
76
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
77
|
+
let emptyData;
|
|
78
|
+
switch (parseAs) {
|
|
79
|
+
case 'arrayBuffer':
|
|
80
|
+
case 'blob':
|
|
81
|
+
case 'text':
|
|
82
|
+
emptyData = await response[parseAs]();
|
|
83
|
+
break;
|
|
84
|
+
case 'formData':
|
|
85
|
+
emptyData = new FormData();
|
|
86
|
+
break;
|
|
87
|
+
case 'stream':
|
|
88
|
+
emptyData = response.body;
|
|
89
|
+
break;
|
|
90
|
+
case 'json':
|
|
91
|
+
default:
|
|
92
|
+
emptyData = {};
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
return opts.responseStyle === 'data'
|
|
96
|
+
? emptyData
|
|
97
|
+
: {
|
|
98
|
+
data: emptyData,
|
|
99
|
+
...result,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
let data;
|
|
103
|
+
switch (parseAs) {
|
|
104
|
+
case 'arrayBuffer':
|
|
105
|
+
case 'blob':
|
|
106
|
+
case 'formData':
|
|
107
|
+
case 'text':
|
|
108
|
+
data = await response[parseAs]();
|
|
109
|
+
break;
|
|
110
|
+
case 'json': {
|
|
111
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
112
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
113
|
+
const text = await response.text();
|
|
114
|
+
data = text ? JSON.parse(text) : {};
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'stream':
|
|
118
|
+
return opts.responseStyle === 'data'
|
|
119
|
+
? response.body
|
|
120
|
+
: {
|
|
121
|
+
data: response.body,
|
|
122
|
+
...result,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (parseAs === 'json') {
|
|
126
|
+
if (opts.responseValidator) {
|
|
127
|
+
await opts.responseValidator(data);
|
|
128
|
+
}
|
|
129
|
+
if (opts.responseTransformer) {
|
|
130
|
+
data = await opts.responseTransformer(data);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return opts.responseStyle === 'data'
|
|
134
|
+
? data
|
|
135
|
+
: {
|
|
136
|
+
data,
|
|
137
|
+
...result,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const textError = await response.text();
|
|
141
|
+
let jsonError;
|
|
142
|
+
try {
|
|
143
|
+
jsonError = JSON.parse(textError);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// noop
|
|
147
|
+
}
|
|
148
|
+
throw jsonError ?? textError;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
let finalError = error;
|
|
152
|
+
for (const fn of interceptors.error.fns) {
|
|
153
|
+
if (fn) {
|
|
154
|
+
finalError = await fn(finalError, response, request, options);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
finalError = finalError || {};
|
|
158
|
+
if (throwOnError) {
|
|
159
|
+
throw finalError;
|
|
160
|
+
}
|
|
161
|
+
// TODO: we probably want to return error and improve types
|
|
162
|
+
return responseStyle === 'data'
|
|
163
|
+
? undefined
|
|
164
|
+
: {
|
|
165
|
+
error: finalError,
|
|
166
|
+
request,
|
|
167
|
+
response,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
172
|
+
const makeSseFn = (method) => async (options) => {
|
|
173
|
+
const { opts, url } = await beforeRequest(options);
|
|
174
|
+
return (0, serverSentEvents_gen_1.createSseClient)({
|
|
175
|
+
...opts,
|
|
176
|
+
body: opts.body,
|
|
177
|
+
method,
|
|
178
|
+
onRequest: async (url, init) => {
|
|
179
|
+
let request = new Request(url, init);
|
|
180
|
+
for (const fn of interceptors.request.fns) {
|
|
181
|
+
if (fn) {
|
|
182
|
+
request = await fn(request, opts);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return request;
|
|
186
|
+
},
|
|
187
|
+
serializedBody: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
188
|
+
url,
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
const _buildUrl = (options) => (0, utils_gen_2.buildUrl)({ ..._config, ...options });
|
|
192
|
+
return {
|
|
193
|
+
buildUrl: _buildUrl,
|
|
194
|
+
connect: makeMethodFn('CONNECT'),
|
|
195
|
+
delete: makeMethodFn('DELETE'),
|
|
196
|
+
get: makeMethodFn('GET'),
|
|
197
|
+
getConfig,
|
|
198
|
+
head: makeMethodFn('HEAD'),
|
|
199
|
+
interceptors,
|
|
200
|
+
options: makeMethodFn('OPTIONS'),
|
|
201
|
+
patch: makeMethodFn('PATCH'),
|
|
202
|
+
post: makeMethodFn('POST'),
|
|
203
|
+
put: makeMethodFn('PUT'),
|
|
204
|
+
request,
|
|
205
|
+
setConfig,
|
|
206
|
+
sse: {
|
|
207
|
+
connect: makeSseFn('CONNECT'),
|
|
208
|
+
delete: makeSseFn('DELETE'),
|
|
209
|
+
get: makeSseFn('GET'),
|
|
210
|
+
head: makeSseFn('HEAD'),
|
|
211
|
+
options: makeSseFn('OPTIONS'),
|
|
212
|
+
patch: makeSseFn('PATCH'),
|
|
213
|
+
post: makeSseFn('POST'),
|
|
214
|
+
put: makeSseFn('PUT'),
|
|
215
|
+
trace: makeSseFn('TRACE'),
|
|
216
|
+
},
|
|
217
|
+
trace: makeMethodFn('TRACE'),
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
exports.createClient = createClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { Auth } from '../core/auth.gen';
|
|
2
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
|
+
export { buildClientParams } from '../core/params.gen';
|
|
5
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
6
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
7
|
+
export type { ClientMeta } from '../core/types.gen';
|
|
8
|
+
export { createClient } from './client.gen';
|
|
9
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
10
|
+
export { createConfig, mergeHeaders } from './utils.gen';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.mergeHeaders = exports.createConfig = exports.createClient = exports.serializeQueryKeyValue = exports.buildClientParams = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = void 0;
|
|
5
|
+
var bodySerializer_gen_1 = require("../core/bodySerializer.gen");
|
|
6
|
+
Object.defineProperty(exports, "formDataBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.formDataBodySerializer; } });
|
|
7
|
+
Object.defineProperty(exports, "jsonBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.jsonBodySerializer; } });
|
|
8
|
+
Object.defineProperty(exports, "urlSearchParamsBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.urlSearchParamsBodySerializer; } });
|
|
9
|
+
var params_gen_1 = require("../core/params.gen");
|
|
10
|
+
Object.defineProperty(exports, "buildClientParams", { enumerable: true, get: function () { return params_gen_1.buildClientParams; } });
|
|
11
|
+
var queryKeySerializer_gen_1 = require("../core/queryKeySerializer.gen");
|
|
12
|
+
Object.defineProperty(exports, "serializeQueryKeyValue", { enumerable: true, get: function () { return queryKeySerializer_gen_1.serializeQueryKeyValue; } });
|
|
13
|
+
var client_gen_1 = require("./client.gen");
|
|
14
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_gen_1.createClient; } });
|
|
15
|
+
var utils_gen_1 = require("./utils.gen");
|
|
16
|
+
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return utils_gen_1.createConfig; } });
|
|
17
|
+
Object.defineProperty(exports, "mergeHeaders", { enumerable: true, get: function () { return utils_gen_1.mergeHeaders; } });
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { Auth } from '../core/auth.gen';
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
3
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
4
|
+
import type { Middleware } from './utils.gen';
|
|
5
|
+
export type ResponseStyle = 'data' | 'fields';
|
|
6
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for all requests made by this client.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: T['baseUrl'];
|
|
11
|
+
/**
|
|
12
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
13
|
+
* fetch instance.
|
|
14
|
+
*
|
|
15
|
+
* @default globalThis.fetch
|
|
16
|
+
*/
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/**
|
|
19
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
20
|
+
* options won't have any effect.
|
|
21
|
+
*
|
|
22
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
23
|
+
*/
|
|
24
|
+
next?: never;
|
|
25
|
+
/**
|
|
26
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
27
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
28
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
29
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
30
|
+
*
|
|
31
|
+
* @default 'auto'
|
|
32
|
+
*/
|
|
33
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
34
|
+
/**
|
|
35
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
36
|
+
*
|
|
37
|
+
* @default 'fields'
|
|
38
|
+
*/
|
|
39
|
+
responseStyle?: ResponseStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Throw an error instead of returning it in the response?
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
throwOnError?: T['throwOnError'];
|
|
46
|
+
}
|
|
47
|
+
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
|
+
responseStyle: TResponseStyle;
|
|
49
|
+
throwOnError: ThrowOnError;
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
51
|
+
/**
|
|
52
|
+
* Any body that you want to add to your request.
|
|
53
|
+
*
|
|
54
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
55
|
+
*/
|
|
56
|
+
body?: unknown;
|
|
57
|
+
path?: Record<string, unknown>;
|
|
58
|
+
query?: Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Security mechanism(s) to use for the request.
|
|
61
|
+
*/
|
|
62
|
+
security?: ReadonlyArray<Auth>;
|
|
63
|
+
url: Url;
|
|
64
|
+
}
|
|
65
|
+
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
headers: Headers;
|
|
67
|
+
serializedBody?: string;
|
|
68
|
+
}
|
|
69
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
70
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
71
|
+
request: Request;
|
|
72
|
+
response: Response;
|
|
73
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
74
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
75
|
+
error: undefined;
|
|
76
|
+
} | {
|
|
77
|
+
data: undefined;
|
|
78
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
79
|
+
}) & {
|
|
80
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
81
|
+
request?: Request;
|
|
82
|
+
/** response may be undefined, because error may be from building the request object itself or from a network error */
|
|
83
|
+
response?: Response;
|
|
84
|
+
}>;
|
|
85
|
+
export interface ClientOptions {
|
|
86
|
+
baseUrl?: string;
|
|
87
|
+
responseStyle?: ResponseStyle;
|
|
88
|
+
throwOnError?: boolean;
|
|
89
|
+
}
|
|
90
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
91
|
+
type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData>>;
|
|
92
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
93
|
+
type BuildUrlFn = <TData extends {
|
|
94
|
+
body?: unknown;
|
|
95
|
+
path?: Record<string, unknown>;
|
|
96
|
+
query?: Record<string, unknown>;
|
|
97
|
+
url: string;
|
|
98
|
+
}>(options: TData & Options<TData>) => string;
|
|
99
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
100
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
104
|
+
* and the returned object will become the client's initial configuration.
|
|
105
|
+
*
|
|
106
|
+
* You may want to initialize your client this way instead of calling
|
|
107
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
108
|
+
* to ensure your client always has the correct values.
|
|
109
|
+
*/
|
|
110
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
111
|
+
export interface TDataShape {
|
|
112
|
+
body?: unknown;
|
|
113
|
+
headers?: unknown;
|
|
114
|
+
path?: unknown;
|
|
115
|
+
query?: unknown;
|
|
116
|
+
url: string;
|
|
117
|
+
}
|
|
118
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
119
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
2
|
+
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => ((queryParams: T) => string);
|
|
4
|
+
/**
|
|
5
|
+
* Infers parseAs value from provided Content-Type header.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
+
export declare function setAuthParams(options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
export declare const buildUrl: Client['buildUrl'];
|
|
12
|
+
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
13
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
14
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
15
|
+
/** response may be undefined due to a network error where no response object is produced */
|
|
16
|
+
response: Res | undefined,
|
|
17
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
18
|
+
request: Req | undefined, options: Options) => Err | Promise<Err>;
|
|
19
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
20
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
21
|
+
declare class Interceptors<Interceptor> {
|
|
22
|
+
fns: Array<Interceptor | null>;
|
|
23
|
+
clear(): void;
|
|
24
|
+
eject(id: number | Interceptor): void;
|
|
25
|
+
exists(id: number | Interceptor): boolean;
|
|
26
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
27
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
28
|
+
use(fn: Interceptor): number;
|
|
29
|
+
}
|
|
30
|
+
export interface Middleware<Req, Res, Err, Options> {
|
|
31
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
32
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
33
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
34
|
+
}
|
|
35
|
+
export declare const createInterceptors: <Req, Res, Err, Options>() => Middleware<Req, Res, Err, Options>;
|
|
36
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
37
|
+
export {};
|