@netwo/saas-sdk-v1 0.0.0-stage → 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/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,117 @@
1
- # Temporary Holding Version
1
+ # @netwo/saas-sdk-v1
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ pnpm add @netwo/openapi-client @netwo/saas-sdk-v1
14
+ ```
15
+
16
+ `@netwo/openapi-client` is a peer dependency: a single copy is shared by all the SDKs of an application (same
17
+ `ApiError`, same Angular providers, same interceptors).
18
+
19
+ ## With the Fetch API
20
+
21
+ ```ts
22
+ import { createApiClient } from "@netwo/openapi-client";
23
+ import { firstValueFrom } from "rxjs";
24
+ import { fetchTransport } from "@netwo/openapi-client/fetch";
25
+ import { netwoV1Auth, netwoV1Schema } from "@netwo/saas-sdk-v1";
26
+
27
+ const netwo = createApiClient(netwoV1Schema, {
28
+ baseUrl: "https://api.netwo.io",
29
+ interceptors: [
30
+ netwoV1Auth({
31
+ apiKey: () => process.env.NETWO_API_KEY,
32
+ actorSlug: () => process.env.NETWO_ACTOR_SLUG,
33
+ }),
34
+ ],
35
+ transport: fetchTransport(),
36
+ });
37
+
38
+ netwo.get("/api/v1/cart").subscribe((carts) => console.log(carts));
39
+
40
+ // Or with a promise
41
+ const carts = await firstValueFrom(netwo.get("/api/v1/cart"));
42
+ ```
43
+
44
+ ## With Angular
45
+
46
+ ```ts
47
+ // app.config.ts
48
+ import { provideHttpClient } from "@angular/common/http";
49
+ import { provideApiClient } from "@netwo/openapi-client/angular";
50
+ import { timeout } from "@netwo/openapi-client/interceptors";
51
+ import { netwoV1Auth, netwoV1Schema } from "@netwo/saas-sdk-v1";
52
+
53
+ export const appConfig: ApplicationConfig = {
54
+ providers: [
55
+ provideHttpClient(),
56
+ provideApiClient(netwoV1Schema, {
57
+ baseUrl: "https://api.netwo.io",
58
+ interceptors: [
59
+ // The handlers run in the injection context: they can use inject().
60
+ netwoV1Auth({ apiKey: () => inject(AuthStore).apiKey(), actorSlug: () => inject(AuthStore).actorSlug() }),
61
+ timeout(),
62
+ ],
63
+ }),
64
+ ],
65
+ };
66
+ ```
67
+
68
+ ```ts
69
+ import { injectApiClient, injectEndpoint } from "@netwo/openapi-client/angular";
70
+ import { netwoV1Schema } from "@netwo/saas-sdk-v1";
71
+
72
+ @Injectable({ providedIn: "root" })
73
+ export class CartService {
74
+ private readonly client = injectApiClient(netwoV1Schema);
75
+
76
+ getCart(cartId: string) {
77
+ return this.client.get("/api/v1/cart/{cart_id}", { path: { cart_id: cartId } });
78
+ }
79
+
80
+ // A reusable request, mapped to the models of the application.
81
+ readonly list = injectEndpoint(netwoV1Schema, (client) => client.get("/api/v1/cart").pipe(map(toCarts)));
82
+ }
83
+ ```
84
+
85
+ ## Authentication
86
+
87
+ `netwoV1Auth({ apiKey, actorSlug?, realm? })` sets `X-Api-Key`, `X-Actor-Slug` and `X-Realm` on the requests that do not
88
+ set them. A handler returns the value, or a getter (e.g. a signal). `client.without(netwoV1Auth)` removes it.
89
+
90
+ `X-Actor-Slug` and `X-Realm` are declared as provided by the client: they are optional in the requests, even when the
91
+ contract requires them. A request can still set them, e.g. to act on behalf of another actor:
92
+
93
+ ```ts
94
+ netwo.get("/api/v1/cart", { header: { "X-Actor-Slug": "other-actor" } });
95
+ ```
96
+
97
+ The header names are exported: `API_KEY_HEADER`, `ACTOR_SLUG_HEADER`, `REALM_HEADER`.
98
+
99
+ ## Types
100
+
101
+ The types of the API are derived from `NetwoV1Schema` with the helpers of `@netwo/openapi-client`:
102
+
103
+ ```ts
104
+ import type { SchemaModels, SchemaQuery, SchemaResponseBody } from "@netwo/openapi-client";
105
+ import type { NetwoV1Schema } from "@netwo/saas-sdk-v1";
106
+
107
+ type CartDiscount = SchemaModels<NetwoV1Schema>["HttpCartDiscount"]; // components.schemas
108
+ type Carts = SchemaResponseBody<NetwoV1Schema, "get", "/api/v1/cart">; // success body
109
+ type CartSearch = SchemaQuery<NetwoV1Schema, "get", "/api/v1/cart">; // query parameters
110
+ ```
111
+
112
+ See the [type helpers](https://www.npmjs.com/package/@netwo/openapi-client#7-type-helpers) for the full list
113
+ (`SchemaRequest`, `SchemaErrorBody`, `SchemaPathsWith`…). To keep short names in an application, declare aliases once:
114
+
115
+ ```ts
116
+ export type NetwoV1Model = SchemaModels<NetwoV1Schema>;
117
+ ```
@@ -0,0 +1,40 @@
1
+ import { defineInterceptor, apiSchema } from '@netwo/openapi-client';
2
+ import { headers } from '@netwo/openapi-client/interceptors';
3
+
4
+ /** The actor on behalf of whom the request is sent. */
5
+ const ACTOR_SLUG_HEADER = 'X-Actor-Slug';
6
+ /** The API key authenticating the requests. */
7
+ const API_KEY_HEADER = 'X-Api-Key';
8
+ /** The targeted environment. */
9
+ const REALM_HEADER = 'X-Realm';
10
+
11
+ /**
12
+ * Sets the authentication headers of the public API v1, when the request does not set them.
13
+ * The handlers run in the environment context (they can use `inject()` in Angular).
14
+ *
15
+ * ```ts
16
+ * interceptors: [netwoV1Auth({ apiKey: () => env.NETWO_API_KEY, actorSlug: () => env.NETWO_ACTOR_SLUG })]
17
+ * ```
18
+ *
19
+ * `client.without(netwoV1Auth)` removes it.
20
+ */
21
+ const netwoV1Auth = defineInterceptor(({ apiKey, actorSlug, realm }) => headers({
22
+ [API_KEY_HEADER]: apiKey,
23
+ ...(actorSlug && { [ACTOR_SLUG_HEADER]: actorSlug }),
24
+ ...(realm && { [REALM_HEADER]: realm }),
25
+ }).intercept);
26
+
27
+ /**
28
+ * The public API v1 of Netwo (`https://api.netwo.io/api/v1/...`).
29
+ *
30
+ * The requests are authenticated by an API key. `X-Actor-Slug` and `X-Realm` are set by the client
31
+ * (`netwoV1Auth()` interceptor), so they are optional in the requests.
32
+ */
33
+ const netwoV1Schema = apiSchema('saas-v1');
34
+
35
+ /**
36
+ * Generated bundle index. Do not edit.
37
+ */
38
+
39
+ export { ACTOR_SLUG_HEADER, API_KEY_HEADER, REALM_HEADER, netwoV1Auth, netwoV1Schema };
40
+ //# sourceMappingURL=netwo-saas-sdk-v1.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"netwo-saas-sdk-v1.mjs","sources":["../../../../../../libs/saas/sdk/v1/src/lib/headers.ts","../../../../../../libs/saas/sdk/v1/src/lib/auth.ts","../../../../../../libs/saas/sdk/v1/src/lib/schema.ts","../../../../../../libs/saas/sdk/v1/src/netwo-saas-sdk-v1.ts"],"sourcesContent":["/** The actor on behalf of whom the request is sent. */\nexport const ACTOR_SLUG_HEADER = 'X-Actor-Slug';\n\n/** The API key authenticating the requests. */\nexport const API_KEY_HEADER = 'X-Api-Key';\n\n/** The targeted environment. */\nexport const REALM_HEADER = 'X-Realm';\n","import { defineInterceptor } from '@netwo/openapi-client';\nimport { HeaderHandler, headers } from '@netwo/openapi-client/interceptors';\nimport { ACTOR_SLUG_HEADER, API_KEY_HEADER, REALM_HEADER } from './headers';\n\nexport interface NetwoV1AuthOptions {\n /** The API key authenticating the requests. */\n readonly apiKey: HeaderHandler;\n /** The actor on behalf of whom the requests are sent. */\n readonly actorSlug?: HeaderHandler;\n /** The targeted environment. */\n readonly realm?: HeaderHandler;\n}\n\n/**\n * Sets the authentication headers of the public API v1, when the request does not set them.\n * The handlers run in the environment context (they can use `inject()` in Angular).\n *\n * ```ts\n * interceptors: [netwoV1Auth({ apiKey: () => env.NETWO_API_KEY, actorSlug: () => env.NETWO_ACTOR_SLUG })]\n * ```\n *\n * `client.without(netwoV1Auth)` removes it.\n */\nexport const netwoV1Auth = defineInterceptor(\n ({ apiKey, actorSlug, realm }: NetwoV1AuthOptions) =>\n headers({\n [API_KEY_HEADER]: apiKey,\n ...(actorSlug && { [ACTOR_SLUG_HEADER]: actorSlug }),\n ...(realm && { [REALM_HEADER]: realm }),\n }).intercept,\n);\n","import { apiSchema } from '@netwo/openapi-client';\nimport type { ACTOR_SLUG_HEADER, REALM_HEADER } from './headers';\nimport type { OpenApi } from './openapi';\n\n/**\n * The public API v1 of Netwo (`https://api.netwo.io/api/v1/...`).\n *\n * The requests are authenticated by an API key. `X-Actor-Slug` and `X-Realm` are set by the client\n * (`netwoV1Auth()` interceptor), so they are optional in the requests.\n */\nexport const netwoV1Schema = apiSchema<\n OpenApi,\n { providedHeaders: typeof REALM_HEADER | typeof ACTOR_SLUG_HEADER }\n>('saas-v1');\n\n/**\n * The type of the schema, to derive the types of the API with the helpers of `@netwo/openapi-client`:\n * `SchemaModels<NetwoV1Schema>['HttpCartDiscount']`, `SchemaResponseBody<NetwoV1Schema, 'get', '/api/v1/cart'>`…\n */\nexport type NetwoV1Schema = typeof netwoV1Schema;\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAAA;AACO,MAAM,iBAAiB,GAAG;AAEjC;AACO,MAAM,cAAc,GAAG;AAE9B;AACO,MAAM,YAAY,GAAG;;ACM5B;;;;;;;;;AASG;AACI,MAAM,WAAW,GAAG,iBAAiB,CAC1C,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAsB,KAC/C,OAAO,CAAC;IACN,CAAC,cAAc,GAAG,MAAM;IACxB,IAAI,SAAS,IAAI,EAAE,CAAC,iBAAiB,GAAG,SAAS,EAAE,CAAC;IACpD,IAAI,KAAK,IAAI,EAAE,CAAC,YAAY,GAAG,KAAK,EAAE,CAAC;CACxC,CAAC,CAAC,SAAS;;ACzBhB;;;;;AAKG;MACU,aAAa,GAAG,SAAS,CAGpC,SAAS;;ACbX;;AAEG;;"}
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@netwo/saas-sdk-v1",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Typed schema and authentication of the Netwo public API v1, for @netwo/openapi-client.",
5
+ "license": "MIT",
6
+ "homepage": "https://www.netwo.io",
7
+ "sideEffects": false,
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "peerDependencies": {
12
+ "@netwo/openapi-client": "^1.0.0"
13
+ },
14
+ "module": "fesm2022/netwo-saas-sdk-v1.mjs",
15
+ "typings": "types/netwo-saas-sdk-v1.d.ts",
16
+ "exports": {
17
+ "./package.json": {
18
+ "default": "./package.json"
19
+ },
20
+ ".": {
21
+ "types": "./types/netwo-saas-sdk-v1.d.ts",
22
+ "default": "./fesm2022/netwo-saas-sdk-v1.mjs"
23
+ }
24
+ },
25
+ "type": "module",
26
+ "dependencies": {
27
+ "tslib": "^2.3.0"
28
+ }
6
29
  }