@wokuapp/sdk 0.2.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 Woku
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 ADDED
@@ -0,0 +1,138 @@
1
+ <div align="center">
2
+
3
+ # @wokuapp/sdk
4
+
5
+ Official **server-side** SDK for the [Woku](https://woku.app) management API.
6
+
7
+ [![npm](https://img.shields.io/npm/v/@wokuapp/sdk)](https://www.npmjs.com/package/@wokuapp/sdk)
8
+ [![license](https://img.shields.io/npm/l/@wokuapp/sdk)](../../LICENSE)
9
+ [![types](https://img.shields.io/npm/types/@wokuapp/sdk)](https://www.npmjs.com/package/@wokuapp/sdk)
10
+
11
+ </div>
12
+
13
+ ## Why
14
+
15
+ Manage your entire Woku account from your backend with one typed client:
16
+ trackers, VoC tools (NPS/CSAT/CES), wokus, forms, flows, action plans,
17
+ support tickets, delivery tracking and survey sends over the public `/v1` API.
18
+
19
+ - **Typed** request bodies (generated from the OpenAPI spec) and response models.
20
+ - **Automatic retries** with full-jitter backoff and `Retry-After` support.
21
+ - **Idempotent creates**: creates carry an auto-generated `Idempotency-Key`, so
22
+ a retry after a blip never creates twice. Action calls (`send`, `test`,
23
+ `reply`) are never silently replayed.
24
+ - **Auto-paginated** lists: `for await (const item of await woku.tickets.list())`.
25
+ - **Typed errors** with the server `request_id` for support.
26
+ - **Zero runtime dependencies.**
27
+
28
+ > **Server-only.** The secret key grants full management access, so the SDK
29
+ > refuses to run in a browser. Never ship it to a client bundle.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ npm install @wokuapp/sdk
35
+ # or: pnpm add @wokuapp/sdk / yarn add @wokuapp/sdk
36
+ ```
37
+
38
+ Requires Node.js 18+ (uses the global `fetch`).
39
+
40
+ ## Quickstart
41
+
42
+ ```ts
43
+ import { Woku } from '@wokuapp/sdk';
44
+
45
+ const woku = new Woku({ apiKey: process.env.WOKU_API_KEY });
46
+
47
+ // Create a tracker definition (idempotent).
48
+ const tracker = await woku.trackers.create({
49
+ name: 'Store #1',
50
+ system: 'retail',
51
+ });
52
+
53
+ // Create an NPS tool and send it.
54
+ const tool = await woku.npsTools.create({
55
+ name: 'Post-purchase',
56
+ npsMessage: 'How likely are you to recommend us?',
57
+ });
58
+ await woku.nps.sendInvitations({
59
+ channel: 'email',
60
+ npsToolId: tool._id,
61
+ recipients: ['ana@example.com'],
62
+ });
63
+
64
+ // Read delivery + response rate.
65
+ const stats = await woku.dispatches.stats({ channel: 'email' });
66
+ console.log(stats.responseRate);
67
+ ```
68
+
69
+ The key is read from `WOKU_API_KEY` when you omit `apiKey`. You can also pass
70
+ it directly: `new Woku('sk_live_...')`.
71
+
72
+ ## Pagination
73
+
74
+ List methods return a `Page`. Iterate every item across pages, or walk pages:
75
+
76
+ ```ts
77
+ for await (const ticket of await woku.tickets.list({ severity: 'high' })) {
78
+ console.log(ticket.title);
79
+ }
80
+
81
+ const first = await woku.dispatches.list({ channel: 'whatsapp' });
82
+ if (first.hasNextPage()) {
83
+ const second = await first.getNextPage();
84
+ }
85
+ ```
86
+
87
+ ## Errors
88
+
89
+ Every failure is a `WokuError`. HTTP errors are typed subclasses carrying the
90
+ status, parsed body and `requestId`:
91
+
92
+ ```ts
93
+ import { NotFoundError, RateLimitError } from '@wokuapp/sdk';
94
+
95
+ try {
96
+ await woku.tickets.get('nonexistent');
97
+ } catch (err) {
98
+ if (err instanceof NotFoundError) {
99
+ console.error(err.status, err.requestId); // 404, "req_..."
100
+ } else if (err instanceof RateLimitError) {
101
+ console.error('retry after', err.retryAfterSeconds);
102
+ }
103
+ }
104
+ ```
105
+
106
+ Transport failures (DNS/TLS/timeout/abort) are `WokuConnectionError` /
107
+ `WokuTimeoutError`.
108
+
109
+ ## Configuration
110
+
111
+ ```ts
112
+ new Woku({
113
+ apiKey: process.env.WOKU_API_KEY,
114
+ baseURL: 'https://clientapi.woku.app', // default
115
+ timeout: 60_000, // ms, default
116
+ maxRetries: 2, // default
117
+ });
118
+ ```
119
+
120
+ Per-call overrides go in the last argument of any method:
121
+
122
+ ```ts
123
+ await woku.tickets.list(
124
+ { severity: 'high' },
125
+ { timeout: 10_000, maxRetries: 0 },
126
+ );
127
+ await woku.npsTools.create(body, { idempotencyKey: 'my-key' });
128
+ ```
129
+
130
+ ## Resources
131
+
132
+ `trackers`, `npsTools` / `csatTools` / `cesTools`, `nps` / `csat` / `ces`,
133
+ `wokus`, `forms`, `flows`, `actionPlans`, `actionPlanGroups`, `tickets`,
134
+ `ticketDestinations`, `dispatches`, `reports`, `company`, `quarantines`.
135
+
136
+ ## License
137
+
138
+ MIT