@oapiex/sdk-kit 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,132 @@
|
|
|
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
|
+
});
|
|
69
|
+
|
|
70
|
+
await sdk.api.examples.list();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Runtime manifest SDK
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { createSdk, type RuntimeSdkBundle } from '@oapiex/sdk-kit';
|
|
77
|
+
|
|
78
|
+
const bundle = {
|
|
79
|
+
document: {},
|
|
80
|
+
manifest: {
|
|
81
|
+
groups: [
|
|
82
|
+
{
|
|
83
|
+
className: 'Example',
|
|
84
|
+
propertyName: 'examples',
|
|
85
|
+
operations: [
|
|
86
|
+
{
|
|
87
|
+
path: '/v1/examples',
|
|
88
|
+
method: 'GET',
|
|
89
|
+
methodName: 'list',
|
|
90
|
+
responseType: 'Example[]',
|
|
91
|
+
inputType: 'Record<string, never>',
|
|
92
|
+
queryType: 'Record<string, never>',
|
|
93
|
+
headerType: 'Record<string, never>',
|
|
94
|
+
paramsType: 'Record<string, never>',
|
|
95
|
+
hasBody: false,
|
|
96
|
+
bodyRequired: false,
|
|
97
|
+
pathParams: [],
|
|
98
|
+
queryParams: [],
|
|
99
|
+
headerParams: [],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
} satisfies RuntimeSdkBundle;
|
|
106
|
+
|
|
107
|
+
const sdk = createSdk(bundle, {
|
|
108
|
+
clientId: process.env.CLIENT_ID!,
|
|
109
|
+
clientSecret: process.env.CLIENT_SECRET!,
|
|
110
|
+
environment: 'sandbox',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
await sdk.api.examples.list();
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Main Exports
|
|
117
|
+
|
|
118
|
+
- `Core`: base SDK client with environment setup, access validation, and runtime bundle support
|
|
119
|
+
- `BaseApi`: base class for SDK-specific API binders and API classes
|
|
120
|
+
- `createSdk()`: helper for creating a runtime SDK from a manifest bundle
|
|
121
|
+
- `Http`, `Builder`, and exceptions: lower-level request and error primitives
|
|
122
|
+
- `InitOptions`, `UnifiedResponse`, and runtime manifest types: shared contracts for generated SDKs
|
|
123
|
+
|
|
124
|
+
## Commands
|
|
125
|
+
|
|
126
|
+
Run these inside `packages/sdk-kit`:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pnpm test
|
|
130
|
+
pnpm build
|
|
131
|
+
pnpm coverage
|
|
132
|
+
```
|
package/dist/index.d.cts
CHANGED
|
@@ -262,7 +262,7 @@ declare class HttpException extends Error {
|
|
|
262
262
|
* @param code
|
|
263
263
|
* @param data
|
|
264
264
|
*/
|
|
265
|
-
static fromCode(code: number, data: Required<UnifiedResponse>, parent?: Error): BadRequestException |
|
|
265
|
+
static fromCode(code: number, data: Required<UnifiedResponse>, parent?: Error): BadRequestException | ForbiddenRequestException | UnauthorizedRequestException | HttpException;
|
|
266
266
|
}
|
|
267
267
|
//#endregion
|
|
268
268
|
//#region src/Apis/BaseApi.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -263,7 +263,7 @@ declare class HttpException extends Error {
|
|
|
263
263
|
* @param code
|
|
264
264
|
* @param data
|
|
265
265
|
*/
|
|
266
|
-
static fromCode(code: number, data: Required<UnifiedResponse>, parent?: Error): BadRequestException |
|
|
266
|
+
static fromCode(code: number, data: Required<UnifiedResponse>, parent?: Error): BadRequestException | ForbiddenRequestException | UnauthorizedRequestException | HttpException;
|
|
267
267
|
}
|
|
268
268
|
//#endregion
|
|
269
269
|
//#region src/Apis/BaseApi.d.ts
|
package/package.json
CHANGED