@webzaytsev/support-sdk 0.1.0 → 0.1.2
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 +230 -0
- package/dist/client.gen.d.mts +14 -0
- package/dist/client.gen.d.ts +6 -5
- package/dist/client.gen.js +785 -6
- package/dist/client.gen.js.map +1 -1
- package/dist/client.gen.mjs +784 -0
- package/dist/client.gen.mjs.map +1 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.ts +58 -3
- package/dist/index.js +878 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +869 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.gen-DHi9F3K-.d.mts +670 -0
- package/dist/types.gen-DHi9F3K-.d.ts +670 -0
- package/dist/zod.gen.d.mts +267 -0
- package/dist/zod.gen.d.ts +34 -32
- package/dist/zod.gen.js +170 -177
- package/dist/zod.gen.js.map +1 -1
- package/dist/zod.gen.mjs +119 -0
- package/dist/zod.gen.mjs.map +1 -0
- package/package.json +18 -8
- package/dist/client/client.gen.d.ts +0 -3
- package/dist/client/client.gen.d.ts.map +0 -1
- package/dist/client/client.gen.js +0 -221
- package/dist/client/client.gen.js.map +0 -1
- package/dist/client/index.d.ts +0 -9
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -18
- package/dist/client/index.js.map +0 -1
- package/dist/client/types.gen.d.ts +0 -121
- package/dist/client/types.gen.d.ts.map +0 -1
- package/dist/client/types.gen.js +0 -4
- package/dist/client/types.gen.js.map +0 -1
- package/dist/client/utils.gen.d.ts +0 -38
- package/dist/client/utils.gen.d.ts.map +0 -1
- package/dist/client/utils.gen.js +0 -242
- package/dist/client/utils.gen.js.map +0 -1
- package/dist/client.gen.d.ts.map +0 -1
- package/dist/core/auth.gen.d.ts +0 -19
- package/dist/core/auth.gen.d.ts.map +0 -1
- package/dist/core/auth.gen.js +0 -19
- package/dist/core/auth.gen.js.map +0 -1
- package/dist/core/bodySerializer.gen.d.ts +0 -26
- package/dist/core/bodySerializer.gen.d.ts.map +0 -1
- package/dist/core/bodySerializer.gen.js +0 -61
- package/dist/core/bodySerializer.gen.js.map +0 -1
- package/dist/core/params.gen.d.ts +0 -44
- package/dist/core/params.gen.d.ts.map +0 -1
- package/dist/core/params.gen.js +0 -105
- package/dist/core/params.gen.js.map +0 -1
- package/dist/core/pathSerializer.gen.d.ts +0 -34
- package/dist/core/pathSerializer.gen.d.ts.map +0 -1
- package/dist/core/pathSerializer.gen.js +0 -116
- package/dist/core/pathSerializer.gen.js.map +0 -1
- package/dist/core/queryKeySerializer.gen.d.ts +0 -19
- package/dist/core/queryKeySerializer.gen.d.ts.map +0 -1
- package/dist/core/queryKeySerializer.gen.js +0 -99
- package/dist/core/queryKeySerializer.gen.js.map +0 -1
- package/dist/core/serverSentEvents.gen.d.ts +0 -72
- package/dist/core/serverSentEvents.gen.d.ts.map +0 -1
- package/dist/core/serverSentEvents.gen.js +0 -136
- package/dist/core/serverSentEvents.gen.js.map +0 -1
- package/dist/core/types.gen.d.ts +0 -79
- package/dist/core/types.gen.d.ts.map +0 -1
- package/dist/core/types.gen.js +0 -4
- package/dist/core/types.gen.js.map +0 -1
- package/dist/core/utils.gen.d.ts +0 -20
- package/dist/core/utils.gen.d.ts.map +0 -1
- package/dist/core/utils.gen.js +0 -94
- package/dist/core/utils.gen.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/sdk.gen.d.ts +0 -56
- package/dist/sdk.gen.d.ts.map +0 -1
- package/dist/sdk.gen.js +0 -105
- package/dist/sdk.gen.js.map +0 -1
- package/dist/types.gen.d.ts +0 -355
- package/dist/types.gen.d.ts.map +0 -1
- package/dist/types.gen.js +0 -4
- package/dist/types.gen.js.map +0 -1
- package/dist/zod.gen.d.ts.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# @webzaytsev/support-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the **Support Bot Web API** — a Telegram-based customer support system with a REST/SSE web interface.
|
|
4
|
+
|
|
5
|
+
> **Note:** The support bot itself is a private, commercial product. This SDK is published publicly so that frontend teams can integrate the support widget without needing access to the backend source code.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @webzaytsev/support-sdk
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @webzaytsev/support-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Runtime requirements:** Node.js 18+ or any modern browser (Fetch API).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Issue a JWT (server-side)
|
|
24
|
+
|
|
25
|
+
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
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { webAuthControllerIssueToken } from '@webzaytsev/support-sdk';
|
|
29
|
+
import { client } from '@webzaytsev/support-sdk/client';
|
|
30
|
+
|
|
31
|
+
client.setConfig({ baseUrl: 'https://support.example.com' });
|
|
32
|
+
|
|
33
|
+
// Called from YOUR backend, not from the browser
|
|
34
|
+
const { data } = await webAuthControllerIssueToken({
|
|
35
|
+
headers: { 'X-Internal-Api-Key': process.env.WEB_API_KEY },
|
|
36
|
+
body: {
|
|
37
|
+
userId: 'user_42',
|
|
38
|
+
userProfile: {
|
|
39
|
+
name: 'Ivan Petrov',
|
|
40
|
+
email: 'ivan@example.com',
|
|
41
|
+
extra: { plan: 'pro', subscriptionId: 'sub_123' },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// data.token — pass this to the frontend widget
|
|
47
|
+
// data.expiresAt — ISO timestamp
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Configure the widget client (browser)
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { client } from '@webzaytsev/support-sdk/client';
|
|
54
|
+
|
|
55
|
+
client.setConfig({
|
|
56
|
+
baseUrl: 'https://support.example.com',
|
|
57
|
+
// Attach JWT from your auth store on every request
|
|
58
|
+
auth: () => localStorage.getItem('support_jwt') ?? '',
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 3. Send a message
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { webTicketsControllerSendMessage } from '@webzaytsev/support-sdk';
|
|
66
|
+
|
|
67
|
+
const { data } = await webTicketsControllerSendMessage({
|
|
68
|
+
body: { text: 'My subscription is not working' },
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log(data.ticketId, data.messageId);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 4. Hydrate the widget on load
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { webTicketsControllerGetCurrentTicket } from '@webzaytsev/support-sdk';
|
|
78
|
+
|
|
79
|
+
const { data } = await webTicketsControllerGetCurrentTicket();
|
|
80
|
+
|
|
81
|
+
if (data.ticket) {
|
|
82
|
+
renderMessages(data.messages); // oldest-first order
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 5. Subscribe to real-time events (SSE)
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { webTicketsControllerSseStream } from '@webzaytsev/support-sdk';
|
|
90
|
+
|
|
91
|
+
const stream = webTicketsControllerSseStream({
|
|
92
|
+
path: { id: ticketId },
|
|
93
|
+
// ?access_token= is used automatically when auth is configured
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
for await (const event of stream) {
|
|
97
|
+
const e = event.data;
|
|
98
|
+
switch (e.type) {
|
|
99
|
+
case 'message':
|
|
100
|
+
appendMessage({ id: e.data?.messageId, text: e.data?.text });
|
|
101
|
+
break;
|
|
102
|
+
case 'resolved':
|
|
103
|
+
showResolvedBanner();
|
|
104
|
+
break;
|
|
105
|
+
case 'heartbeat':
|
|
106
|
+
// keep-alive, no action needed
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 6. Upload an image
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { webUploadsControllerUpload, webTicketsControllerSendMessage } from '@webzaytsev/support-sdk';
|
|
116
|
+
|
|
117
|
+
const formData = new FormData();
|
|
118
|
+
formData.append('file', selectedFile);
|
|
119
|
+
|
|
120
|
+
const { data: upload } = await webUploadsControllerUpload({ body: formData });
|
|
121
|
+
|
|
122
|
+
// Attach the upload to the next message
|
|
123
|
+
await webTicketsControllerSendMessage({
|
|
124
|
+
body: {
|
|
125
|
+
text: 'See the screenshot',
|
|
126
|
+
attachmentIds: [upload.uploadId],
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## API Reference
|
|
134
|
+
|
|
135
|
+
### SDK Functions
|
|
136
|
+
|
|
137
|
+
All functions are imported from `@webzaytsev/support-sdk`.
|
|
138
|
+
|
|
139
|
+
| Function | Method | Description |
|
|
140
|
+
|---|---|---|
|
|
141
|
+
| `webAuthControllerIssueToken` | `POST /web/auth/token` | Issue user JWT *(server-side, requires API key)* |
|
|
142
|
+
| `webTicketsControllerSendMessage` | `POST /web/messages` | Send message (creates or reopens ticket) |
|
|
143
|
+
| `webTicketsControllerGetCurrentTicket` | `GET /web/tickets/current` | Get open ticket + message history |
|
|
144
|
+
| `webTicketsControllerGetMessages` | `GET /web/tickets/:id/messages` | Poll messages since cursor |
|
|
145
|
+
| `webTicketsControllerSseStream` | `GET /web/tickets/:id/stream` | SSE real-time event stream |
|
|
146
|
+
| `webTicketsControllerEscalate` | `POST /web/tickets/:id/escalate` | Mark ticket as unresolved (escalate) |
|
|
147
|
+
| `webTicketsControllerResolveByUser` | `POST /web/tickets/:id/resolve` | Confirm issue is resolved |
|
|
148
|
+
| `webUploadsControllerUpload` | `POST /web/uploads` | Upload an image (jpeg/png/webp, max 10 MB) |
|
|
149
|
+
| `webUploadsControllerGetUpload` | `GET /web/uploads/:id` | Stream an uploaded image |
|
|
150
|
+
|
|
151
|
+
### Client Configuration
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { client } from '@webzaytsev/support-sdk/client';
|
|
155
|
+
|
|
156
|
+
client.setConfig({
|
|
157
|
+
baseUrl: 'https://support.example.com',
|
|
158
|
+
// Called before every request — return the Bearer token
|
|
159
|
+
auth: () => getJwtFromStorage(),
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Zod Schemas
|
|
164
|
+
|
|
165
|
+
Runtime validation schemas are available for all request and response types:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { zSendMessageDto, zCurrentTicketResponseDto, zWebSseEventDto } from '@webzaytsev/support-sdk/zod';
|
|
169
|
+
|
|
170
|
+
// Validate before sending
|
|
171
|
+
const parsed = zSendMessageDto.parse({ text: 'Hello' });
|
|
172
|
+
|
|
173
|
+
// Validate API response at runtime
|
|
174
|
+
const ticket = zCurrentTicketResponseDto.parse(apiResponse);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## SSE Event Types
|
|
180
|
+
|
|
181
|
+
The `webTicketsControllerSseStream` endpoint emits the following events:
|
|
182
|
+
|
|
183
|
+
| `type` | Description | `data` fields |
|
|
184
|
+
|---|---|---|
|
|
185
|
+
| `message` | New message from moderator or bot | `messageId`, `text`, `attachmentIds?`, `createdAt` |
|
|
186
|
+
| `resolved` | Ticket marked as resolved | — |
|
|
187
|
+
| `reopened` | Ticket reopened after resolution | — |
|
|
188
|
+
| `escalation_ack` | Escalation acknowledged | `escalatableMessageId`, `source` |
|
|
189
|
+
| `closed` | Ticket closed by moderator | — |
|
|
190
|
+
| `heartbeat` | Keep-alive ping (~15 s interval) | — |
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Polling Fallback
|
|
195
|
+
|
|
196
|
+
If SSE is unavailable (e.g. behind a proxy that buffers responses), use `webTicketsControllerGetMessages` with cursor-based polling:
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
let cursor: string | null = null;
|
|
200
|
+
|
|
201
|
+
setInterval(async () => {
|
|
202
|
+
const { data } = await webTicketsControllerGetMessages({
|
|
203
|
+
path: { id: ticketId },
|
|
204
|
+
query: { since: cursor ?? undefined, limit: 50 },
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (data.messages.length > 0) {
|
|
208
|
+
appendMessages(data.messages); // oldest-first
|
|
209
|
+
cursor = data.nextCursor;
|
|
210
|
+
}
|
|
211
|
+
}, 5000);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Exports
|
|
217
|
+
|
|
218
|
+
| Import path | Contents |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `@webzaytsev/support-sdk` | SDK functions + TypeScript types |
|
|
221
|
+
| `@webzaytsev/support-sdk/client` | `client` singleton, `createClient` |
|
|
222
|
+
| `@webzaytsev/support-sdk/zod` | Zod schemas for all DTOs |
|
|
223
|
+
|
|
224
|
+
Both CJS (`require`) and ESM (`import`) are supported.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
MIT — the SDK is free to use. The support bot backend is a private commercial product.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { b as ClientOptions, a as ClientOptions$1, c as Config, C as Client } from './types.gen-DHi9F3K-.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
5
|
+
* and the returned object will become the client's initial configuration.
|
|
6
|
+
*
|
|
7
|
+
* You may want to initialize your client this way instead of calling
|
|
8
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
9
|
+
* to ensure your client always has the correct values.
|
|
10
|
+
*/
|
|
11
|
+
type CreateClientConfig<T extends ClientOptions = ClientOptions$1> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
|
+
declare const client: Client;
|
|
13
|
+
|
|
14
|
+
export { type CreateClientConfig, client };
|
package/dist/client.gen.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { b as ClientOptions, a as ClientOptions$1, c as Config, C as Client } from './types.gen-DHi9F3K-.js';
|
|
2
|
+
|
|
3
3
|
/**
|
|
4
4
|
* The `createClientConfig()` function will be called on client initialization
|
|
5
5
|
* and the returned object will become the client's initial configuration.
|
|
@@ -8,6 +8,7 @@ import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
|
8
8
|
* `setConfig()`. This is useful for example if you're using Next.js
|
|
9
9
|
* to ensure your client always has the correct values.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type CreateClientConfig<T extends ClientOptions = ClientOptions$1> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
|
+
declare const client: Client;
|
|
13
|
+
|
|
14
|
+
export { type CreateClientConfig, client };
|