@webzaytsev/support-sdk 0.1.3 → 0.1.4

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
@@ -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 { client } from '@webzaytsev/support-sdk/client';
45
+ import { configure } from '@webzaytsev/support-sdk/configure';
30
46
 
31
- client.setConfig({ baseUrl: 'https://support.example.com' });
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 { client } from '@webzaytsev/support-sdk/client';
69
+ import { configure } from '@webzaytsev/support-sdk/configure';
54
70
 
55
- client.setConfig({
71
+ // Attach JWT from your auth store; can be called again whenever token changes
72
+ configure({
56
73
  baseUrl: 'https://support.example.com',
57
- // Attach JWT from your auth store on every request
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 { client } from '@webzaytsev/support-sdk/client';
170
+ import { configure } from '@webzaytsev/support-sdk/configure';
155
171
 
156
- client.setConfig({
172
+ configure({
157
173
  baseUrl: 'https://support.example.com',
158
- // Called before every request — return the Bearer token
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/client` | `client` singleton, `createClient` |
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