@netwo/saas-sdk-v1 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +118 -2
- package/fesm2022/netwo-saas-sdk-v1-openapi.zod-C8EyoRPK.mjs +3806 -0
- package/fesm2022/netwo-saas-sdk-v1-openapi.zod-C8EyoRPK.mjs.map +1 -0
- package/fesm2022/netwo-saas-sdk-v1.mjs +43 -0
- package/fesm2022/netwo-saas-sdk-v1.mjs.map +1 -0
- package/package.json +36 -3
- package/types/netwo-saas-sdk-v1.d.ts +15955 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Netwo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @netwo/saas-sdk-v1
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The contract of the Netwo public API v1 (`https://api.netwo.io/api/v1/...`): its schema, typed from the OpenAPI document,
|
|
4
|
+
to use with the client of [`@netwo/openapi-client`](https://www.npmjs.com/package/@netwo/openapi-client).
|
|
5
|
+
|
|
6
|
+
- `@netwo/openapi-client` sends the requests: client, Angular integration, transports, interceptors, type helpers.
|
|
7
|
+
- `@netwo/saas-sdk-v1` describes the API: `netwoV1Schema`, its type `NetwoV1Schema`, the `netwoV1Auth()` interceptor and
|
|
8
|
+
the header names.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
# npm
|
|
14
|
+
npm install @netwo/openapi-client @netwo/saas-sdk-v1
|
|
15
|
+
|
|
16
|
+
# pnpm
|
|
17
|
+
pnpm add @netwo/openapi-client @netwo/saas-sdk-v1
|
|
18
|
+
|
|
19
|
+
# yarn
|
|
20
|
+
yarn add @netwo/openapi-client @netwo/saas-sdk-v1
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`@netwo/openapi-client` is a peer dependency.
|
|
24
|
+
|
|
25
|
+
## With the Fetch API
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { createApiClient } from "@netwo/openapi-client";
|
|
29
|
+
import { firstValueFrom } from "rxjs";
|
|
30
|
+
import { fetchTransport } from "@netwo/openapi-client/fetch";
|
|
31
|
+
import { netwoV1Auth, netwoV1Schema } from "@netwo/saas-sdk-v1";
|
|
32
|
+
|
|
33
|
+
const netwo = createApiClient(netwoV1Schema, {
|
|
34
|
+
baseUrl: "https://api.netwo.io",
|
|
35
|
+
interceptors: [
|
|
36
|
+
netwoV1Auth({
|
|
37
|
+
apiKey: () => process.env.NETWO_API_KEY,
|
|
38
|
+
actorSlug: () => process.env.NETWO_ACTOR_SLUG,
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
transport: fetchTransport(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
netwo.get("/api/v1/cart").subscribe((carts) => console.log(carts));
|
|
45
|
+
|
|
46
|
+
// Or with a promise
|
|
47
|
+
const carts = await firstValueFrom(netwo.get("/api/v1/cart"));
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## With Angular
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// app.config.ts
|
|
54
|
+
import { provideHttpClient } from "@angular/common/http";
|
|
55
|
+
import { provideApiClient } from "@netwo/openapi-client/angular";
|
|
56
|
+
import { timeout } from "@netwo/openapi-client/interceptors";
|
|
57
|
+
import { netwoV1Auth, netwoV1Schema } from "@netwo/saas-sdk-v1";
|
|
58
|
+
|
|
59
|
+
export const appConfig: ApplicationConfig = {
|
|
60
|
+
providers: [
|
|
61
|
+
provideHttpClient(),
|
|
62
|
+
provideApiClient(netwoV1Schema, {
|
|
63
|
+
baseUrl: "https://api.netwo.io",
|
|
64
|
+
interceptors: [
|
|
65
|
+
// The handlers run in the injection context: they can use inject().
|
|
66
|
+
netwoV1Auth({ apiKey: () => inject(AuthStore).apiKey(), actorSlug: () => inject(AuthStore).actorSlug() }),
|
|
67
|
+
timeout(),
|
|
68
|
+
],
|
|
69
|
+
}),
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { injectApiClient, injectEndpoint } from "@netwo/openapi-client/angular";
|
|
76
|
+
import { netwoV1Schema } from "@netwo/saas-sdk-v1";
|
|
77
|
+
|
|
78
|
+
@Injectable({ providedIn: "root" })
|
|
79
|
+
export class CartService {
|
|
80
|
+
private readonly client = injectApiClient(netwoV1Schema);
|
|
81
|
+
|
|
82
|
+
getCart(cartId: string) {
|
|
83
|
+
return this.client.get("/api/v1/cart/{cart_id}", { path: { cart_id: cartId } });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// A reusable request, mapped to the models of the application.
|
|
87
|
+
readonly list = injectEndpoint(netwoV1Schema, (client) => client.get("/api/v1/cart").pipe(map(toCarts)));
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Authentication
|
|
92
|
+
|
|
93
|
+
`netwoV1Auth({ apiKey, actorSlug?, realm? })` sets `X-Api-Key`, `X-Actor-Slug` and `X-Realm` on the requests that do not
|
|
94
|
+
set them. A handler returns the value, or a getter (e.g. a signal). `client.without(netwoV1Auth)` removes it.
|
|
95
|
+
|
|
96
|
+
`X-Actor-Slug` and `X-Realm` are declared as provided by the client: they are optional in the requests, even when the
|
|
97
|
+
contract requires them. A request can still set them, e.g. to act on behalf of another actor:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
netwo.get("/api/v1/cart", { header: { "X-Actor-Slug": "other-actor" } });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The header names are exported: `API_KEY_HEADER`, `ACTOR_SLUG_HEADER`, `REALM_HEADER`.
|
|
104
|
+
|
|
105
|
+
## Types
|
|
106
|
+
|
|
107
|
+
The types of the API are derived from `NetwoV1Schema` with the helpers of `@netwo/openapi-client`:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import type { SchemaModels, SchemaQuery, SchemaResponseBody } from "@netwo/openapi-client";
|
|
111
|
+
import type { NetwoV1Schema } from "@netwo/saas-sdk-v1";
|
|
112
|
+
|
|
113
|
+
type CartDiscount = SchemaModels<NetwoV1Schema>["HttpCartDiscount"]; // components.schemas
|
|
114
|
+
type Carts = SchemaResponseBody<NetwoV1Schema, "get", "/api/v1/cart">; // success body
|
|
115
|
+
type CartSearch = SchemaQuery<NetwoV1Schema, "get", "/api/v1/cart">; // query parameters
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
See the [type helpers](https://www.npmjs.com/package/@netwo/openapi-client#7-type-helpers) for the full list
|
|
119
|
+
(`SchemaRequest`, `SchemaErrorBody`, `SchemaPathsWith`…).
|