nuki-api-js 0.2.1 → 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/README.md CHANGED
@@ -1,13 +1,68 @@
1
- # Nuki API JavaScript SDK
1
+ # nuki-api-js
2
2
 
3
- Unofficial Nuki API JavaScript SDK built from the OpenAPI specification and with TypeScript types.
3
+ Auto-generated, fully typed client for the [Nuki Web API](https://api.nuki.io/).
4
+
5
+ ## Features
6
+
7
+ - **Fully typed** - every operation, parameter and response is generated from the official OpenAPI spec
8
+ - **Tree-shakable** - only the operations you import end up in your bundle
9
+ - **Runtime agnostic** - uses the global `fetch`, or bring your own implementation
10
+ - **Effect support** - optional [Effect](https://effect.website) bindings via `nuki-api-js/effect`
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install nuki-api-js
16
+ ```
17
+
18
+ ## Quick Start
4
19
 
5
20
  ```ts
6
- const nuki = new NukiApi({ token: 'token' });
21
+ import { NukiApi } from "nuki-api-js";
7
22
 
8
- // Direct methods
9
- const { accountId, name } = await nuki.request('GET /account', {});
23
+ const client = new NukiApi({ token: process.env.NUKI_TOKEN ?? null });
10
24
 
11
- // Namespaced methods
12
- await nuki.api.smartlock.postSmartlockLockActionResource({ pathParams: { smartlockId: 'smartlockId' } });
25
+ const accounts = await client.api.account.getAccountsResource({});
13
26
  ```
27
+
28
+ Operations are grouped by tag: `client.api.<tag>.<operation>(params)`.
29
+
30
+ ### Custom fetch
31
+
32
+ ```ts
33
+ const client = new NukiApi({
34
+ token: process.env.NUKI_TOKEN ?? null,
35
+ fetch: myFetchImplementation,
36
+ });
37
+ ```
38
+
39
+ ## Effect
40
+
41
+ The `effect` entrypoint exposes every operation as an `Effect`. It requires `effect` as a peer dependency.
42
+
43
+ ```ts
44
+ import { Effect } from "effect";
45
+ import { ApiService, makeApiLayer } from "nuki-api-js/effect";
46
+
47
+ const program = ApiService.account.getAccountsResource({});
48
+
49
+ await Effect.runPromise(
50
+ program.pipe(Effect.provide(makeApiLayer({ token: process.env.NUKI_TOKEN })))
51
+ );
52
+ ```
53
+
54
+ Errors are typed as `ApiError`, `NetworkError` and `ValidationError`.
55
+
56
+ ## Entrypoints
57
+
58
+ | Import | Contents |
59
+ | --- | --- |
60
+ | `nuki-api-js` | client class, operations, schemas and types |
61
+ | `nuki-api-js/components` | operations grouped by tag and by path |
62
+ | `nuki-api-js/schemas` | Zod schemas for every operation |
63
+ | `nuki-api-js/types` | TypeScript types for every operation |
64
+ | `nuki-api-js/effect` | Effect bindings |
65
+
66
+ ## License
67
+
68
+ ISC