@oapiex/sdk-kit 0.1.1 → 0.1.3
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 +361 -1
- package/dist/contracts.d.cts +2 -2
- package/dist/contracts.d.ts +2 -2
- package/dist/{index-BYtse_Mh.d.cts → index-DUI9uPJQ.d.ts} +69 -10
- package/dist/{index-sMTTpEJS.d.ts → index-JjhthUpt.d.cts} +69 -10
- package/dist/index.cjs +292 -42
- package/dist/index.d.cts +102 -13
- package/dist/index.d.ts +102 -13
- package/dist/index.js +288 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,361 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @oapiex/sdk-kit
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@oapiex/sdk-kit)
|
|
4
|
+
[](https://www.npmjs.com/package/@oapiex/sdk-kit)
|
|
5
|
+
[](https://github.com/toneflix/oapiex/blob/main/LICENSE)
|
|
6
|
+
[](https://codecov.io/gh/toneflix/oapiex)
|
|
7
|
+
[](https://github.com/toneflix/oapiex/actions/workflows/publish.yml)
|
|
8
|
+
[](https://github.com/toneflix/oapiex/actions/workflows/docs.yml)
|
|
9
|
+
[](https://github.com/toneflix/oapiex/actions/workflows/test.yml)
|
|
10
|
+
|
|
11
|
+
Core runtime primitives for SDKs generated by oapiex.
|
|
12
|
+
|
|
13
|
+
This package provides the shared building blocks used by generated SDK packages:
|
|
14
|
+
|
|
15
|
+
- `Core` for authenticated SDK instances
|
|
16
|
+
- `BaseApi` for SDK-specific API binders and API classes
|
|
17
|
+
- `createSdk()` for manifest-driven runtime SDKs
|
|
18
|
+
- shared HTTP utilities, exceptions, contracts, and helper types
|
|
19
|
+
|
|
20
|
+
Most consumers will install a generated SDK package instead of using this package directly. Use `@oapiex/sdk-kit` when you want to build or customize an SDK on top of the generated OpenAPI manifest output.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @oapiex/sdk-kit
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
### Class-based SDK
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { BaseApi, Core, Http } from '@oapiex/sdk-kit';
|
|
34
|
+
|
|
35
|
+
class ExampleApi extends BaseApi {
|
|
36
|
+
async list() {
|
|
37
|
+
await this.core.validateAccess();
|
|
38
|
+
|
|
39
|
+
const { data } = await Http.send(
|
|
40
|
+
this.core.builder.buildTargetUrl('/v1/examples', {}, {}),
|
|
41
|
+
'GET',
|
|
42
|
+
{},
|
|
43
|
+
{},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class ApiBinder extends BaseApi {
|
|
51
|
+
examples!: ExampleApi;
|
|
52
|
+
|
|
53
|
+
protected override boot() {
|
|
54
|
+
this.examples = new ExampleApi(this.core);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class ExampleCore extends Core {
|
|
59
|
+
static override apiClass = ApiBinder;
|
|
60
|
+
|
|
61
|
+
declare api: ApiBinder;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const sdk = new ExampleCore({
|
|
65
|
+
clientId: process.env.CLIENT_ID!,
|
|
66
|
+
clientSecret: process.env.CLIENT_SECRET!,
|
|
67
|
+
environment: 'sandbox',
|
|
68
|
+
urls: {
|
|
69
|
+
sandbox: 'https://sandbox-api.example.com',
|
|
70
|
+
},
|
|
71
|
+
headers: {
|
|
72
|
+
'X-SDK-Version': '1.0.0',
|
|
73
|
+
},
|
|
74
|
+
timeout: 10000,
|
|
75
|
+
auth: {
|
|
76
|
+
type: 'bearer',
|
|
77
|
+
token: process.env.ACCESS_TOKEN!,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await sdk.api.examples.list();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Runtime manifest SDK
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { createSdk, type RuntimeSdkBundle } from '@oapiex/sdk-kit';
|
|
88
|
+
|
|
89
|
+
const bundle = {
|
|
90
|
+
document: {},
|
|
91
|
+
manifest: {
|
|
92
|
+
groups: [
|
|
93
|
+
{
|
|
94
|
+
className: 'Example',
|
|
95
|
+
propertyName: 'examples',
|
|
96
|
+
operations: [
|
|
97
|
+
{
|
|
98
|
+
path: '/v1/examples',
|
|
99
|
+
method: 'GET',
|
|
100
|
+
methodName: 'list',
|
|
101
|
+
responseType: 'Example[]',
|
|
102
|
+
inputType: 'Record<string, never>',
|
|
103
|
+
queryType: 'Record<string, never>',
|
|
104
|
+
headerType: 'Record<string, never>',
|
|
105
|
+
paramsType: 'Record<string, never>',
|
|
106
|
+
hasBody: false,
|
|
107
|
+
bodyRequired: false,
|
|
108
|
+
pathParams: [],
|
|
109
|
+
queryParams: [],
|
|
110
|
+
headerParams: [],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
} satisfies RuntimeSdkBundle;
|
|
117
|
+
|
|
118
|
+
const sdk = createSdk(bundle, {
|
|
119
|
+
clientId: process.env.CLIENT_ID!,
|
|
120
|
+
clientSecret: process.env.CLIENT_SECRET!,
|
|
121
|
+
environment: 'sandbox',
|
|
122
|
+
auth: {
|
|
123
|
+
type: 'apiKey',
|
|
124
|
+
name: 'X-API-Key',
|
|
125
|
+
value: process.env.API_KEY!,
|
|
126
|
+
in: 'header',
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await sdk.api.examples.list();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Init Options
|
|
134
|
+
|
|
135
|
+
`Core` and `createSdk()` both accept the same `InitOptions` object.
|
|
136
|
+
|
|
137
|
+
- `clientId`: required API client identifier
|
|
138
|
+
- `clientSecret`: required API client secret
|
|
139
|
+
- `environment`: selects `sandbox` or `live`
|
|
140
|
+
- `urls`: optional base URL overrides per environment
|
|
141
|
+
- `headers`: optional default headers added to every request
|
|
142
|
+
- `timeout`: optional Axios timeout in milliseconds
|
|
143
|
+
- `encryptionKey`: optional runtime encryption key override
|
|
144
|
+
- `auth`: one auth strategy or an array of strategies applied to outgoing requests
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
const sdk = new Core({
|
|
148
|
+
clientId: process.env.CLIENT_ID!,
|
|
149
|
+
clientSecret: process.env.CLIENT_SECRET!,
|
|
150
|
+
environment: 'sandbox',
|
|
151
|
+
urls: {
|
|
152
|
+
sandbox: 'https://sandbox-api.example.com',
|
|
153
|
+
live: 'https://api.example.com',
|
|
154
|
+
},
|
|
155
|
+
headers: {
|
|
156
|
+
'X-Trace-Source': 'example-sdk',
|
|
157
|
+
},
|
|
158
|
+
timeout: 15000,
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Auth Shapes
|
|
163
|
+
|
|
164
|
+
The `auth` option accepts any `AuthConfig` supported by the transport layer.
|
|
165
|
+
|
|
166
|
+
### Bearer
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
auth: {
|
|
170
|
+
type: 'bearer',
|
|
171
|
+
token: process.env.ACCESS_TOKEN!,
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Basic
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
auth: {
|
|
179
|
+
type: 'basic',
|
|
180
|
+
username: process.env.API_USERNAME!,
|
|
181
|
+
password: process.env.API_PASSWORD!,
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### API Key
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
auth: {
|
|
189
|
+
type: 'apiKey',
|
|
190
|
+
name: 'X-API-Key',
|
|
191
|
+
value: process.env.API_KEY!,
|
|
192
|
+
in: 'header',
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### OAuth2 Token
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
auth: {
|
|
200
|
+
type: 'oauth2',
|
|
201
|
+
accessToken: process.env.ACCESS_TOKEN!,
|
|
202
|
+
tokenType: 'Bearer',
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Multiple Strategies
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
auth: [
|
|
210
|
+
{
|
|
211
|
+
type: 'apiKey',
|
|
212
|
+
name: 'X-Partner-Key',
|
|
213
|
+
value: process.env.PARTNER_KEY!,
|
|
214
|
+
in: 'header',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
type: 'apiKey',
|
|
218
|
+
name: 'api_key',
|
|
219
|
+
value: process.env.QUERY_KEY!,
|
|
220
|
+
in: 'query',
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Custom
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
auth: {
|
|
229
|
+
type: 'custom',
|
|
230
|
+
apply: async (request) => ({
|
|
231
|
+
...request,
|
|
232
|
+
headers: {
|
|
233
|
+
...request.headers,
|
|
234
|
+
Authorization: `Token ${process.env.CUSTOM_TOKEN!}`,
|
|
235
|
+
},
|
|
236
|
+
}),
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Generated SDK packages can now expose auth helper functions derived from OpenAPI `securitySchemes`, plus `securitySchemes` and `security` metadata exports for inspection.
|
|
241
|
+
|
|
242
|
+
## Access Validator Auth Refresh
|
|
243
|
+
|
|
244
|
+
`setAccessValidator()` can be used to replace auth before the actual SDK request is sent. This is useful for APIs like Flutterwave where you first exchange API keys for a bearer token.
|
|
245
|
+
|
|
246
|
+
The validator can:
|
|
247
|
+
|
|
248
|
+
- return `true` to allow the request as-is
|
|
249
|
+
- return a string to fail validation with a custom message
|
|
250
|
+
- return an `AuthConfig` or `AuthConfig[]` to replace auth for the pending request
|
|
251
|
+
- return a partial config object such as `{ auth, headers, timeout }`
|
|
252
|
+
- call `core.setAuth(...)` or `core.configure(...)` directly
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
import axios from 'axios';
|
|
256
|
+
import { Core } from '@oapiex/sdk-kit';
|
|
257
|
+
|
|
258
|
+
const sdk = new Core({
|
|
259
|
+
clientId: process.env.CLIENT_ID!,
|
|
260
|
+
clientSecret: process.env.CLIENT_SECRET!,
|
|
261
|
+
environment: 'sandbox',
|
|
262
|
+
urls: {
|
|
263
|
+
sandbox: 'https://developersandbox-api.example.com',
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
sdk.setAccessValidator(async (core) => {
|
|
268
|
+
const response = await axios.post(
|
|
269
|
+
'https://developersandbox-api.example.com/auth/token',
|
|
270
|
+
{
|
|
271
|
+
client_id: core.getClientId(),
|
|
272
|
+
client_secret: core.getClientSecret(),
|
|
273
|
+
},
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
type: 'bearer',
|
|
278
|
+
token: response.data.access_token,
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
await sdk.api.examples.list();
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
If you need to update more than auth, return a config object instead:
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
sdk.setAccessValidator(async (core) => {
|
|
289
|
+
const response = await axios.post(
|
|
290
|
+
'https://developersandbox-api.example.com/auth/token',
|
|
291
|
+
{
|
|
292
|
+
client_id: core.getClientId(),
|
|
293
|
+
client_secret: core.getClientSecret(),
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
auth: {
|
|
299
|
+
type: 'bearer',
|
|
300
|
+
token: response.data.access_token,
|
|
301
|
+
},
|
|
302
|
+
headers: {
|
|
303
|
+
'X-Token-Source': 'access-validator',
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
If the token endpoint returns an expiry value, use `createAccessTokenCache()` so the validator does not fetch a new token on every request.
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import axios from 'axios';
|
|
313
|
+
import { Core, createAccessTokenCache } from '@oapiex/sdk-kit';
|
|
314
|
+
|
|
315
|
+
const sdk = new Core({
|
|
316
|
+
clientId: process.env.CLIENT_ID!,
|
|
317
|
+
clientSecret: process.env.CLIENT_SECRET!,
|
|
318
|
+
environment: 'sandbox',
|
|
319
|
+
urls: {
|
|
320
|
+
sandbox: 'https://developersandbox-api.example.com',
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const tokenCache = createAccessTokenCache(async (core) => {
|
|
325
|
+
const response = await axios.post(
|
|
326
|
+
'https://developersandbox-api.example.com/auth/token',
|
|
327
|
+
{
|
|
328
|
+
client_id: core.getClientId(),
|
|
329
|
+
client_secret: core.getClientSecret(),
|
|
330
|
+
},
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
token: response.data.access_token,
|
|
335
|
+
expiresInSeconds: Math.max((response.data.expires_in ?? 60) - 30, 1),
|
|
336
|
+
};
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
sdk.setAccessValidator(tokenCache);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Main Exports
|
|
343
|
+
|
|
344
|
+
- `Core`: base SDK client with environment setup, access validation, and runtime bundle support
|
|
345
|
+
- `BaseApi`: base class for SDK-specific API binders and API classes
|
|
346
|
+
- `createSdk()`: helper for creating a runtime SDK from a manifest bundle
|
|
347
|
+
- `AuthConfig`: shared auth strategy union used by `InitOptions.auth`
|
|
348
|
+
- `createAccessTokenCache()`: helper for caching validator-fetched tokens until expiry
|
|
349
|
+
- `setAccessValidator()`: hook for readiness checks, auth refresh, and config replacement before requests
|
|
350
|
+
- `Http`, `Builder`, and exceptions: lower-level request and error primitives
|
|
351
|
+
- `InitOptions`, `UnifiedResponse`, and runtime manifest types: shared contracts for generated SDKs
|
|
352
|
+
|
|
353
|
+
## Commands
|
|
354
|
+
|
|
355
|
+
Run these inside `packages/sdk-kit`:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
pnpm test
|
|
359
|
+
pnpm build
|
|
360
|
+
pnpm coverage
|
|
361
|
+
```
|
package/dist/contracts.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { AuthErrorResponse, AuthResponse, CountryCode, CountryCodeRestricted, CurrencyCode, CursorPagination, ErrorResponse, InitOptions, NormalPagination, PageInfoMeta, Response, ResponseStatus, SuccessResponse, UnifiedResponse, UserConfig, ValidationError, ValidationErrorResponse, XGenericObject };
|
|
1
|
+
import { A as CurrencyCode, C as UserConfig, D as XGenericObject, E as ValidationErrorResponse, O as CountryCode, S as UnifiedResponse, T as ValidationError, _ as OAuth2AuthConfig, a as AuthErrorResponse, b as ResponseStatus, c as BasicAuthConfig, d as CustomAuthConfig, f as Environment, g as NormalPagination, h as InitOptions, i as AuthConfig, k as CountryCodeRestricted, l as BearerAuthConfig, m as HttpMethod, n as AccessValidationResult, o as AuthRequestConfig, p as ErrorResponse, r as ApiKeyAuthConfig, s as AuthResponse, t as AccessValidationConfigUpdate, u as CursorPagination, v as PageInfoMeta, w as UserUrls, x as SuccessResponse, y as Response } from "./index-JjhthUpt.cjs";
|
|
2
|
+
export { AccessValidationConfigUpdate, AccessValidationResult, ApiKeyAuthConfig, AuthConfig, AuthErrorResponse, AuthRequestConfig, AuthResponse, BasicAuthConfig, BearerAuthConfig, CountryCode, CountryCodeRestricted, CurrencyCode, CursorPagination, CustomAuthConfig, Environment, ErrorResponse, HttpMethod, InitOptions, NormalPagination, OAuth2AuthConfig, PageInfoMeta, Response, ResponseStatus, SuccessResponse, UnifiedResponse, UserConfig, UserUrls, ValidationError, ValidationErrorResponse, XGenericObject };
|
package/dist/contracts.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { AuthErrorResponse, AuthResponse, CountryCode, CountryCodeRestricted, CurrencyCode, CursorPagination, ErrorResponse, InitOptions, NormalPagination, PageInfoMeta, Response, ResponseStatus, SuccessResponse, UnifiedResponse, UserConfig, ValidationError, ValidationErrorResponse, XGenericObject };
|
|
1
|
+
import { A as CurrencyCode, C as UserConfig, D as XGenericObject, E as ValidationErrorResponse, O as CountryCode, S as UnifiedResponse, T as ValidationError, _ as OAuth2AuthConfig, a as AuthErrorResponse, b as ResponseStatus, c as BasicAuthConfig, d as CustomAuthConfig, f as Environment, g as NormalPagination, h as InitOptions, i as AuthConfig, k as CountryCodeRestricted, l as BearerAuthConfig, m as HttpMethod, n as AccessValidationResult, o as AuthRequestConfig, p as ErrorResponse, r as ApiKeyAuthConfig, s as AuthResponse, t as AccessValidationConfigUpdate, u as CursorPagination, v as PageInfoMeta, w as UserUrls, x as SuccessResponse, y as Response } from "./index-DUI9uPJQ.js";
|
|
2
|
+
export { AccessValidationConfigUpdate, AccessValidationResult, ApiKeyAuthConfig, AuthConfig, AuthErrorResponse, AuthRequestConfig, AuthResponse, BasicAuthConfig, BearerAuthConfig, CountryCode, CountryCodeRestricted, CurrencyCode, CursorPagination, CustomAuthConfig, Environment, ErrorResponse, HttpMethod, InitOptions, NormalPagination, OAuth2AuthConfig, PageInfoMeta, Response, ResponseStatus, SuccessResponse, UnifiedResponse, UserConfig, UserUrls, ValidationError, ValidationErrorResponse, XGenericObject };
|
|
@@ -9,6 +9,8 @@ interface XGenericObject {
|
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/Contracts/Core.d.ts
|
|
12
|
+
type Environment = 'sandbox' | 'live';
|
|
13
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
12
14
|
type ResponseStatus = 'failed' | 'success';
|
|
13
15
|
interface ValidationError {
|
|
14
16
|
'field_name': string;
|
|
@@ -78,30 +80,87 @@ interface NormalPagination {
|
|
|
78
80
|
interface PageInfoMeta {
|
|
79
81
|
page_info: NormalPagination;
|
|
80
82
|
}
|
|
83
|
+
interface UserUrls {
|
|
84
|
+
live?: string;
|
|
85
|
+
sandbox?: string;
|
|
86
|
+
}
|
|
87
|
+
interface BearerAuthConfig {
|
|
88
|
+
type: 'bearer';
|
|
89
|
+
token: string;
|
|
90
|
+
prefix?: string;
|
|
91
|
+
}
|
|
92
|
+
interface OAuth2AuthConfig {
|
|
93
|
+
type: 'oauth2';
|
|
94
|
+
accessToken: string;
|
|
95
|
+
tokenType?: string;
|
|
96
|
+
}
|
|
97
|
+
interface BasicAuthConfig {
|
|
98
|
+
type: 'basic';
|
|
99
|
+
username: string;
|
|
100
|
+
password: string;
|
|
101
|
+
}
|
|
102
|
+
interface ApiKeyAuthConfig {
|
|
103
|
+
type: 'apiKey';
|
|
104
|
+
name: string;
|
|
105
|
+
value: string;
|
|
106
|
+
in?: 'header' | 'query' | 'cookie';
|
|
107
|
+
prefix?: string;
|
|
108
|
+
}
|
|
109
|
+
interface AuthRequestConfig {
|
|
110
|
+
url: string;
|
|
111
|
+
method: HttpMethod;
|
|
112
|
+
headers: Record<string, string>;
|
|
113
|
+
params: XGenericObject;
|
|
114
|
+
body?: unknown;
|
|
115
|
+
}
|
|
116
|
+
interface CustomAuthConfig {
|
|
117
|
+
type: 'custom';
|
|
118
|
+
apply: (request: AuthRequestConfig) => AuthRequestConfig | Promise<AuthRequestConfig>;
|
|
119
|
+
}
|
|
120
|
+
type AuthConfig = BearerAuthConfig | OAuth2AuthConfig | BasicAuthConfig | ApiKeyAuthConfig | CustomAuthConfig;
|
|
121
|
+
type AccessValidationConfigUpdate = Partial<UserConfig> | AuthConfig | AuthConfig[];
|
|
122
|
+
type AccessValidationResult = boolean | string | void | AccessValidationConfigUpdate;
|
|
81
123
|
interface InitOptions {
|
|
82
124
|
/**
|
|
83
|
-
* Your
|
|
125
|
+
* Your API Public Key
|
|
84
126
|
*/
|
|
85
127
|
clientId: string;
|
|
86
128
|
/**
|
|
87
|
-
* Your
|
|
129
|
+
* Your API Secret Key
|
|
88
130
|
*/
|
|
89
131
|
clientSecret: string;
|
|
90
132
|
/**
|
|
91
|
-
* Your
|
|
133
|
+
* Your API Encryption Key
|
|
92
134
|
*/
|
|
93
135
|
encryptionKey?: string;
|
|
94
136
|
/**
|
|
95
137
|
* Environment to use
|
|
96
138
|
*/
|
|
97
|
-
environment?:
|
|
139
|
+
environment?: Environment;
|
|
140
|
+
/**
|
|
141
|
+
* Override environment base URLs.
|
|
142
|
+
*/
|
|
143
|
+
urls?: UserUrls;
|
|
144
|
+
/**
|
|
145
|
+
* Default headers applied to every request.
|
|
146
|
+
*/
|
|
147
|
+
headers?: Record<string, string>;
|
|
148
|
+
/**
|
|
149
|
+
* Request timeout in milliseconds.
|
|
150
|
+
*/
|
|
151
|
+
timeout?: number;
|
|
152
|
+
/**
|
|
153
|
+
* Request authentication strategy or strategies.
|
|
154
|
+
*/
|
|
155
|
+
auth?: AuthConfig | AuthConfig[];
|
|
98
156
|
}
|
|
99
157
|
interface UserConfig {
|
|
100
|
-
environment?:
|
|
101
|
-
urls
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
158
|
+
environment?: Environment;
|
|
159
|
+
urls?: UserUrls;
|
|
160
|
+
headers?: Record<string, string>;
|
|
161
|
+
timeout?: number;
|
|
162
|
+
encryptionKey?: string;
|
|
163
|
+
auth?: AuthConfig | AuthConfig[];
|
|
105
164
|
}
|
|
106
165
|
//#endregion
|
|
107
|
-
export {
|
|
166
|
+
export { CurrencyCode as A, UserConfig as C, XGenericObject as D, ValidationErrorResponse as E, CountryCode as O, UnifiedResponse as S, ValidationError as T, OAuth2AuthConfig as _, AuthErrorResponse as a, ResponseStatus as b, BasicAuthConfig as c, CustomAuthConfig as d, Environment as f, NormalPagination as g, InitOptions as h, AuthConfig as i, CountryCodeRestricted as k, BearerAuthConfig as l, HttpMethod as m, AccessValidationResult as n, AuthRequestConfig as o, ErrorResponse as p, ApiKeyAuthConfig as r, AuthResponse as s, AccessValidationConfigUpdate as t, CursorPagination as u, PageInfoMeta as v, UserUrls as w, SuccessResponse as x, Response as y };
|
|
@@ -9,6 +9,8 @@ interface XGenericObject {
|
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/Contracts/Core.d.ts
|
|
12
|
+
type Environment = 'sandbox' | 'live';
|
|
13
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
12
14
|
type ResponseStatus = 'failed' | 'success';
|
|
13
15
|
interface ValidationError {
|
|
14
16
|
'field_name': string;
|
|
@@ -78,30 +80,87 @@ interface NormalPagination {
|
|
|
78
80
|
interface PageInfoMeta {
|
|
79
81
|
page_info: NormalPagination;
|
|
80
82
|
}
|
|
83
|
+
interface UserUrls {
|
|
84
|
+
live?: string;
|
|
85
|
+
sandbox?: string;
|
|
86
|
+
}
|
|
87
|
+
interface BearerAuthConfig {
|
|
88
|
+
type: 'bearer';
|
|
89
|
+
token: string;
|
|
90
|
+
prefix?: string;
|
|
91
|
+
}
|
|
92
|
+
interface OAuth2AuthConfig {
|
|
93
|
+
type: 'oauth2';
|
|
94
|
+
accessToken: string;
|
|
95
|
+
tokenType?: string;
|
|
96
|
+
}
|
|
97
|
+
interface BasicAuthConfig {
|
|
98
|
+
type: 'basic';
|
|
99
|
+
username: string;
|
|
100
|
+
password: string;
|
|
101
|
+
}
|
|
102
|
+
interface ApiKeyAuthConfig {
|
|
103
|
+
type: 'apiKey';
|
|
104
|
+
name: string;
|
|
105
|
+
value: string;
|
|
106
|
+
in?: 'header' | 'query' | 'cookie';
|
|
107
|
+
prefix?: string;
|
|
108
|
+
}
|
|
109
|
+
interface AuthRequestConfig {
|
|
110
|
+
url: string;
|
|
111
|
+
method: HttpMethod;
|
|
112
|
+
headers: Record<string, string>;
|
|
113
|
+
params: XGenericObject;
|
|
114
|
+
body?: unknown;
|
|
115
|
+
}
|
|
116
|
+
interface CustomAuthConfig {
|
|
117
|
+
type: 'custom';
|
|
118
|
+
apply: (request: AuthRequestConfig) => AuthRequestConfig | Promise<AuthRequestConfig>;
|
|
119
|
+
}
|
|
120
|
+
type AuthConfig = BearerAuthConfig | OAuth2AuthConfig | BasicAuthConfig | ApiKeyAuthConfig | CustomAuthConfig;
|
|
121
|
+
type AccessValidationConfigUpdate = Partial<UserConfig> | AuthConfig | AuthConfig[];
|
|
122
|
+
type AccessValidationResult = boolean | string | void | AccessValidationConfigUpdate;
|
|
81
123
|
interface InitOptions {
|
|
82
124
|
/**
|
|
83
|
-
* Your
|
|
125
|
+
* Your API Public Key
|
|
84
126
|
*/
|
|
85
127
|
clientId: string;
|
|
86
128
|
/**
|
|
87
|
-
* Your
|
|
129
|
+
* Your API Secret Key
|
|
88
130
|
*/
|
|
89
131
|
clientSecret: string;
|
|
90
132
|
/**
|
|
91
|
-
* Your
|
|
133
|
+
* Your API Encryption Key
|
|
92
134
|
*/
|
|
93
135
|
encryptionKey?: string;
|
|
94
136
|
/**
|
|
95
137
|
* Environment to use
|
|
96
138
|
*/
|
|
97
|
-
environment?:
|
|
139
|
+
environment?: Environment;
|
|
140
|
+
/**
|
|
141
|
+
* Override environment base URLs.
|
|
142
|
+
*/
|
|
143
|
+
urls?: UserUrls;
|
|
144
|
+
/**
|
|
145
|
+
* Default headers applied to every request.
|
|
146
|
+
*/
|
|
147
|
+
headers?: Record<string, string>;
|
|
148
|
+
/**
|
|
149
|
+
* Request timeout in milliseconds.
|
|
150
|
+
*/
|
|
151
|
+
timeout?: number;
|
|
152
|
+
/**
|
|
153
|
+
* Request authentication strategy or strategies.
|
|
154
|
+
*/
|
|
155
|
+
auth?: AuthConfig | AuthConfig[];
|
|
98
156
|
}
|
|
99
157
|
interface UserConfig {
|
|
100
|
-
environment?:
|
|
101
|
-
urls
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
158
|
+
environment?: Environment;
|
|
159
|
+
urls?: UserUrls;
|
|
160
|
+
headers?: Record<string, string>;
|
|
161
|
+
timeout?: number;
|
|
162
|
+
encryptionKey?: string;
|
|
163
|
+
auth?: AuthConfig | AuthConfig[];
|
|
105
164
|
}
|
|
106
165
|
//#endregion
|
|
107
|
-
export {
|
|
166
|
+
export { CurrencyCode as A, UserConfig as C, XGenericObject as D, ValidationErrorResponse as E, CountryCode as O, UnifiedResponse as S, ValidationError as T, OAuth2AuthConfig as _, AuthErrorResponse as a, ResponseStatus as b, BasicAuthConfig as c, CustomAuthConfig as d, Environment as f, NormalPagination as g, InitOptions as h, AuthConfig as i, CountryCodeRestricted as k, BearerAuthConfig as l, HttpMethod as m, AccessValidationResult as n, AuthRequestConfig as o, ErrorResponse as p, ApiKeyAuthConfig as r, AuthResponse as s, AccessValidationConfigUpdate as t, CursorPagination as u, PageInfoMeta as v, UserUrls as w, SuccessResponse as x, Response as y };
|