@webzaytsev/support-sdk 0.1.2 → 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 +80 -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.d.mts +2 -1
- package/dist/client.gen.d.ts +2 -1
- 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.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- 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 +50 -0
- package/dist/plugins.d.ts +50 -0
- package/dist/plugins.js +4 -0
- package/dist/plugins.js.map +1 -0
- package/dist/plugins.mjs +3 -0
- package/dist/plugins.mjs.map +1 -0
- package/dist/types.gen-Bkafu1bx.d.mts +356 -0
- package/dist/types.gen-Bkafu1bx.d.ts +356 -0
- package/dist/{types.gen-DHi9F3K-.d.mts → types.gen-D6uwMaOo.d.mts} +3 -358
- package/dist/{types.gen-DHi9F3K-.d.ts → types.gen-D6uwMaOo.d.ts} +3 -358
- package/package.json +11 -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:
|
|
@@ -213,13 +237,58 @@ setInterval(async () => {
|
|
|
213
237
|
|
|
214
238
|
---
|
|
215
239
|
|
|
240
|
+
## Plugin Types
|
|
241
|
+
|
|
242
|
+
The `extra` field in `WebProfileDto` is a general-purpose string key-value bag — you can put any data your backend needs to store alongside the user profile. The support bot plugins read specific keys from it.
|
|
243
|
+
|
|
244
|
+
Import typed helpers from `@webzaytsev/support-sdk/plugins`:
|
|
245
|
+
|
|
246
|
+
### Remnawave
|
|
247
|
+
|
|
248
|
+
The Remnawave plugin (`/sub` command, ticket info card) looks for a user identifier in `extra` using this priority order: `userId` → `remnawave_user_id` → `user_id`.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import type { RemnawaveWebProfile } from '@webzaytsev/support-sdk/plugins';
|
|
252
|
+
|
|
253
|
+
// Typed profile — extra.userId is required, any other keys are allowed
|
|
254
|
+
const profile: RemnawaveWebProfile = {
|
|
255
|
+
name: 'Ivan Petrov',
|
|
256
|
+
email: 'ivan@example.com',
|
|
257
|
+
extra: {
|
|
258
|
+
userId: 'ddc9c1c9-973c-46d9-acd7-8db629e7bc98', // Remnawave user UUID
|
|
259
|
+
plan: 'pro', // arbitrary extra data — allowed
|
|
260
|
+
region: 'eu-west', // also fine
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// Pass to POST /web/auth/token
|
|
265
|
+
await webAuthControllerIssueToken({
|
|
266
|
+
headers: { 'X-Internal-Api-Key': process.env.WEB_API_KEY },
|
|
267
|
+
body: { userId: 'user_42', userProfile: profile },
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
You can also use `RemnawaveExtra` if you only need the extra shape:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import type { RemnawaveExtra } from '@webzaytsev/support-sdk/plugins';
|
|
275
|
+
|
|
276
|
+
const extra: RemnawaveExtra & Record<string, string> = {
|
|
277
|
+
userId: 'ddc9c1c9-973c-46d9-acd7-8db629e7bc98',
|
|
278
|
+
};
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
216
283
|
## Exports
|
|
217
284
|
|
|
218
285
|
| Import path | Contents |
|
|
219
286
|
|---|---|
|
|
220
287
|
| `@webzaytsev/support-sdk` | SDK functions + TypeScript types |
|
|
221
|
-
| `@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 |
|
|
222
290
|
| `@webzaytsev/support-sdk/zod` | Zod schemas for all DTOs |
|
|
291
|
+
| `@webzaytsev/support-sdk/plugins` | Plugin-specific `extra` types (`RemnawaveExtra`, `RemnawaveWebProfile`) |
|
|
223
292
|
|
|
224
293
|
Both CJS (`require`) and ESM (`import`) are supported.
|
|
225
294
|
|