@webzaytsev/support-sdk 0.1.3 → 0.1.5
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 +36 -11
- package/dist/chunk-62GXFPNC.js +812 -0
- package/dist/chunk-62GXFPNC.js.map +1 -0
- package/dist/chunk-EBVUPKNG.mjs +809 -0
- package/dist/chunk-EBVUPKNG.mjs.map +1 -0
- package/dist/client.gen.js +4 -778
- package/dist/client.gen.js.map +1 -1
- package/dist/client.gen.mjs +1 -782
- package/dist/client.gen.mjs.map +1 -1
- package/dist/configure.d.mts +28 -0
- package/dist/configure.d.ts +28 -0
- package/dist/configure.js +15 -0
- package/dist/configure.js.map +1 -0
- package/dist/configure.mjs +13 -0
- package/dist/configure.mjs.map +1 -0
- package/dist/index.js +11 -815
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -805
- package/dist/index.mjs.map +1 -1
- package/dist/plugins.d.mts +26 -5
- package/dist/plugins.d.ts +26 -5
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -20,15 +20,31 @@ pnpm add @webzaytsev/support-sdk
|
|
|
20
20
|
|
|
21
21
|
## Quick Start
|
|
22
22
|
|
|
23
|
+
### 0. Configure the SDK
|
|
24
|
+
|
|
25
|
+
Call `configure()` once at app startup before making any requests. Both `baseUrl` and `token` can be updated at any time (e.g. after receiving a JWT).
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { configure } from '@webzaytsev/support-sdk/configure';
|
|
29
|
+
|
|
30
|
+
// Set base URL once at startup
|
|
31
|
+
configure({ baseUrl: 'https://sup.example.com' });
|
|
32
|
+
|
|
33
|
+
// After receiving a JWT from your backend, set the token:
|
|
34
|
+
configure({ baseUrl: 'https://sup.example.com', token: jwt });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
> **Important:** All SDK functions share a single client instance. Calling `configure()` applies to every subsequent API call.
|
|
38
|
+
|
|
23
39
|
### 1. Issue a JWT (server-side)
|
|
24
40
|
|
|
25
41
|
Your backend exchanges a server-to-server API key for a short-lived user JWT. This keeps your `WEB_API_KEY` secret out of the browser.
|
|
26
42
|
|
|
27
43
|
```typescript
|
|
28
44
|
import { webAuthControllerIssueToken } from '@webzaytsev/support-sdk';
|
|
29
|
-
import {
|
|
45
|
+
import { configure } from '@webzaytsev/support-sdk/configure';
|
|
30
46
|
|
|
31
|
-
|
|
47
|
+
configure({ baseUrl: 'https://support.example.com' });
|
|
32
48
|
|
|
33
49
|
// Called from YOUR backend, not from the browser
|
|
34
50
|
const { data } = await webAuthControllerIssueToken({
|
|
@@ -50,12 +66,12 @@ const { data } = await webAuthControllerIssueToken({
|
|
|
50
66
|
### 2. Configure the widget client (browser)
|
|
51
67
|
|
|
52
68
|
```typescript
|
|
53
|
-
import {
|
|
69
|
+
import { configure } from '@webzaytsev/support-sdk/configure';
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
// Attach JWT from your auth store; can be called again whenever token changes
|
|
72
|
+
configure({
|
|
56
73
|
baseUrl: 'https://support.example.com',
|
|
57
|
-
|
|
58
|
-
auth: () => localStorage.getItem('support_jwt') ?? '',
|
|
74
|
+
token: localStorage.getItem('support_jwt') ?? '',
|
|
59
75
|
});
|
|
60
76
|
```
|
|
61
77
|
|
|
@@ -151,15 +167,23 @@ All functions are imported from `@webzaytsev/support-sdk`.
|
|
|
151
167
|
### Client Configuration
|
|
152
168
|
|
|
153
169
|
```typescript
|
|
154
|
-
import {
|
|
170
|
+
import { configure } from '@webzaytsev/support-sdk/configure';
|
|
155
171
|
|
|
156
|
-
|
|
172
|
+
configure({
|
|
157
173
|
baseUrl: 'https://support.example.com',
|
|
158
|
-
|
|
159
|
-
auth: () => getJwtFromStorage(),
|
|
174
|
+
token: getJwtFromStorage(),
|
|
160
175
|
});
|
|
161
176
|
```
|
|
162
177
|
|
|
178
|
+
For advanced use cases (dynamic token refresh, interceptors) you can access the raw client directly:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { client } from '@webzaytsev/support-sdk/client';
|
|
182
|
+
|
|
183
|
+
// Dynamic token — called before every request
|
|
184
|
+
client.setConfig({ auth: () => getJwtFromStorage() });
|
|
185
|
+
```
|
|
186
|
+
|
|
163
187
|
### Zod Schemas
|
|
164
188
|
|
|
165
189
|
Runtime validation schemas are available for all request and response types:
|
|
@@ -261,7 +285,8 @@ const extra: RemnawaveExtra & Record<string, string> = {
|
|
|
261
285
|
| Import path | Contents |
|
|
262
286
|
|---|---|
|
|
263
287
|
| `@webzaytsev/support-sdk` | SDK functions + TypeScript types |
|
|
264
|
-
| `@webzaytsev/support-sdk/
|
|
288
|
+
| `@webzaytsev/support-sdk/configure` | `configure({ baseUrl, token })` — recommended setup entrypoint |
|
|
289
|
+
| `@webzaytsev/support-sdk/client` | `client` singleton, `createClient` — for advanced use |
|
|
265
290
|
| `@webzaytsev/support-sdk/zod` | Zod schemas for all DTOs |
|
|
266
291
|
| `@webzaytsev/support-sdk/plugins` | Plugin-specific `extra` types (`RemnawaveExtra`, `RemnawaveWebProfile`) |
|
|
267
292
|
|