@dnotifier-realtime/dnotifier 1.1.8 → 1.1.12

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.
Files changed (61) hide show
  1. package/README.md +531 -16
  2. package/dist/cjs/dnotifier.js +1 -1
  3. package/dist/cjs/providers/openai.js +1 -1
  4. package/dist/cjs/transport/httpTransport.js +1 -1
  5. package/dist/cjs/transport/websocketTransport.js +1 -1
  6. package/dist/cjs/utils/buffer.js +1 -1
  7. package/dist/cjs/utils/frame.js +1 -1
  8. package/dist/cjs/utils/id.js +1 -1
  9. package/dist/cjs/utils/payload.js +1 -1
  10. package/dist/config/endpoints.d.ts +9 -3
  11. package/dist/config/endpoints.d.ts.map +1 -1
  12. package/dist/config/endpoints.js +1 -1
  13. package/dist/dnotifier.cjs +872 -19
  14. package/dist/dnotifier.d.ts +22 -1
  15. package/dist/dnotifier.d.ts.map +1 -1
  16. package/dist/dnotifier.js +1 -1
  17. package/dist/providers/openai.js +1 -1
  18. package/dist/transport/httpTransport.js +1 -1
  19. package/dist/transport/websocketTransport.js +1 -1
  20. package/dist/utils/buffer.js +1 -1
  21. package/dist/utils/frame.js +1 -1
  22. package/dist/utils/id.js +1 -1
  23. package/dist/utils/logs.js +1 -1
  24. package/dist/utils/payload.js +1 -1
  25. package/dist/workflow/agent.d.ts +13 -0
  26. package/dist/workflow/agent.d.ts.map +1 -0
  27. package/dist/workflow/agent.js +1 -0
  28. package/dist/workflow/context.d.ts +54 -0
  29. package/dist/workflow/context.d.ts.map +1 -0
  30. package/dist/workflow/context.js +1 -0
  31. package/dist/workflow/errors.d.ts +9 -0
  32. package/dist/workflow/errors.d.ts.map +1 -0
  33. package/dist/workflow/errors.js +1 -0
  34. package/dist/workflow/ids.d.ts +3 -0
  35. package/dist/workflow/ids.d.ts.map +1 -0
  36. package/dist/workflow/ids.js +1 -0
  37. package/dist/workflow/index.d.ts +6 -0
  38. package/dist/workflow/index.d.ts.map +1 -0
  39. package/dist/workflow/index.js +1 -0
  40. package/dist/workflow/jsonPayload.d.ts +3 -0
  41. package/dist/workflow/jsonPayload.d.ts.map +1 -0
  42. package/dist/workflow/jsonPayload.js +1 -0
  43. package/dist/workflow/mockObservabilityClient.d.ts +47 -0
  44. package/dist/workflow/mockObservabilityClient.d.ts.map +1 -0
  45. package/dist/workflow/mockObservabilityClient.js +1 -0
  46. package/dist/workflow/observability.d.ts +35 -0
  47. package/dist/workflow/observability.d.ts.map +1 -0
  48. package/dist/workflow/observability.js +1 -0
  49. package/dist/workflow/runner.d.ts +17 -0
  50. package/dist/workflow/runner.d.ts.map +1 -0
  51. package/dist/workflow/runner.js +1 -0
  52. package/dist/workflow/stepTypes.d.ts +25 -0
  53. package/dist/workflow/stepTypes.d.ts.map +1 -0
  54. package/dist/workflow/stepTypes.js +1 -0
  55. package/dist/workflow/workflow.d.ts +18 -0
  56. package/dist/workflow/workflow.d.ts.map +1 -0
  57. package/dist/workflow/workflow.js +1 -0
  58. package/dist/workflow/workflowObservabilityClient.d.ts +41 -0
  59. package/dist/workflow/workflowObservabilityClient.d.ts.map +1 -0
  60. package/dist/workflow/workflowObservabilityClient.js +1 -0
  61. package/package.json +1 -1
package/README.md CHANGED
@@ -1,31 +1,546 @@
1
- # DNotifier SDK
1
+ # DNotifier JavaScript SDK
2
2
 
3
- 🚀 **DNotifier** is a real-time notification & messaging SDK supporting **WebSocket and HTTP transports**, **binary streaming**, and **framed packet communication** — built for scalable and reliable real-time systems.
3
+ **DNotifier** is a real-time notification and messaging SDK for **Node.js** and **browsers**. It supports **WebSocket** and **HTTP** transports, **binary streaming**, framed packets, an **AI pipeline**, **knowledge-base (RAG)** APIs, optional **session logging**, and **multi-step workflows** with agents and observability.
4
4
 
5
5
  ---
6
6
 
7
- ## ✨ Features
7
+ ## Features
8
8
 
9
- - 🔌 WebSocket & HTTP transport support
10
- - 🔐 Secure authentication handshake
11
- - 📩 Real-time messaging
12
- - 📦 Binary data transfer (files, images, media)
13
- - 🧠 Automatic packet framing & decoding
14
- - ⚡ Handles partial packets & large payloads
15
- - 🔄 Consistent client ↔ server protocol
16
- - 🧩 Simple and developer-friendly API
9
+ - WebSocket and HTTP transport
10
+ - Secure authentication handshake
11
+ - Real-time messaging (text and binary)
12
+ - Large payloads with automatic chunking and reassembly
13
+ - AI: `sendAI`, `fetchAIHistory`, semantic `search`
14
+ - Knowledge base: add, update, get, list, delete, and search documents
15
+ - Chat history fetch and delete
16
+ - Optional SDK session logging (`logs: true`)
17
+ - Workflows: named agents, sequential pipelines, dashboard observability
18
+ - Plan limits from auth (`getPlanLimits`)
17
19
 
18
20
  ---
19
21
 
20
- ## 📦 Installation
22
+ ## Installation
21
23
 
22
24
  ```bash
23
- npm i @dnotifier-realtime/dnotifier
25
+ npm install @dnotifier-realtime/dnotifier
24
26
  ```
25
27
 
26
28
  ---
27
29
 
28
- ## 📖 How to use
30
+ ## Quick start
29
31
 
30
- - **Product website:** [dnotifier.com](https://www.dnotifier.com)
31
- - **Documentation:** [Product docs](https://dnotifier.gitbook.io/product-docs) — setup, integration, and full API usage
32
+ ```js
33
+ import { DNotifier } from "@dnotifier-realtime/dnotifier";
34
+
35
+ const notifier = new DNotifier({
36
+ appId: "your-app-id",
37
+ secret: "your-app-secret",
38
+ transport: "ws", // or "http"
39
+ userId: "user-123",
40
+ onConnected: () => console.log("Connected"),
41
+ onMessage: (msg) => {
42
+ console.log("From:", msg.metadata.sender);
43
+ console.log("Payload:", msg.payload.toJSON());
44
+ },
45
+ onDisconnected: () => console.log("Disconnected"),
46
+ });
47
+
48
+ await notifier.connect();
49
+
50
+ notifier.send({
51
+ senderId: "user-123",
52
+ receiverId: "user-456",
53
+ data: { type: "text", text: "Hello from DNotifier" },
54
+ });
55
+ ```
56
+
57
+ For **Node.js WebSocket**, pass a `WebSocket` implementation:
58
+
59
+ ```js
60
+ import WebSocket from "ws";
61
+
62
+ const notifier = new DNotifier({
63
+ appId: "your-app-id",
64
+ secret: "your-app-secret",
65
+ transport: "ws",
66
+ userId: "user-123",
67
+ WebSocketImpl: WebSocket,
68
+ onConnected: () => {},
69
+ onMessage: () => {},
70
+ onDisconnected: () => {},
71
+ });
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Connection and configuration
77
+
78
+ | Option | Type | Description |
79
+ |--------|------|-------------|
80
+ | `appId` | `string` | Your DNotifier application id |
81
+ | `secret` | `string` | Application secret |
82
+ | `transport` | `"ws"` \| `"http"` | `"ws"` for realtime messaging; `"http"` for RPC-style AI/RAG calls |
83
+ | `userId` | `string` | End-user or agent id for auth and routing |
84
+ | `logs` | `boolean` | When `true`, tracks AI sessions in the DNotifier logs dashboard |
85
+ | `url` | `string` | Optional custom WebSocket URL |
86
+ | `WebSocketImpl` | `class` | Required in Node when using `transport: "ws"` |
87
+ | `onConnected` | `function` | Called when the client is ready |
88
+ | `onMessage` | `function` | Called with `{ metadata, payload }` for incoming messages |
89
+ | `onDisconnected` | `function` | Called when the connection closes |
90
+
91
+ ```js
92
+ await notifier.connect();
93
+
94
+ const limits = notifier.getPlanLimits();
95
+ console.log(limits?.aiEnabled, limits?.maxAIRequestsPerMonth);
96
+ ```
97
+
98
+ After `connect()`, these properties are available:
99
+
100
+ | Property | Description |
101
+ |----------|-------------|
102
+ | `isConnected` | Whether the client is connected |
103
+ | `aiEnabled` | Whether AI is enabled for the current plan |
104
+ | `authToken` | Auth token from the last successful connect |
105
+ | `messageSizeLimit` | Max message size in bytes (from plan) |
106
+
107
+ ---
108
+
109
+ ## Real-time messaging
110
+
111
+ ### Text and structured messages
112
+
113
+ Use any `type` in `data` that fits your app (`text`, `image`, `audio`, `doc`, etc.):
114
+
115
+ ```js
116
+ await notifier.send({
117
+ senderId: "user-123",
118
+ receiverId: "user-456",
119
+ data: {
120
+ type: "text",
121
+ text: "hello from dnotifier sdk!",
122
+ },
123
+ saveHistory: true, // default true
124
+ });
125
+ ```
126
+
127
+ Send to multiple receivers:
128
+
129
+ ```js
130
+ await notifier.send({
131
+ senderId: "user-123",
132
+ receiverIds: ["user-456", "user-789"],
133
+ data: { type: "text", text: "Hello everyone" },
134
+ });
135
+ ```
136
+
137
+ ### Images, audio, and binary
138
+
139
+ Prefer `send()` with a typed payload. The SDK chunks large payloads automatically.
140
+
141
+ ```js
142
+ import { readFileSync } from "fs";
143
+
144
+ const imageBytes = readFileSync("./photo.png");
145
+
146
+ await notifier.send({
147
+ senderId: "user-123",
148
+ receiverId: "user-456",
149
+ data: {
150
+ type: "image",
151
+ content: imageBytes,
152
+ },
153
+ });
154
+ ```
155
+
156
+ Handle incoming messages in `onMessage`:
157
+
158
+ ```js
159
+ onMessage: (msg) => {
160
+ const body = msg.payload.toJSON();
161
+ if (body?.type === "image") {
162
+ // body.content — image bytes or base64 depending on your app convention
163
+ } else if (body?.type === "text") {
164
+ console.log(body.text);
165
+ }
166
+ },
167
+ ```
168
+
169
+ ### Raw binary (`sendBinary`)
170
+
171
+ ```js
172
+ notifier.sendBinary({
173
+ senderId: "user-123",
174
+ receiverIds: ["user-456"],
175
+ buffer: new Uint8Array([0x00, 0x01, 0x02]),
176
+ type: "binary",
177
+ });
178
+ ```
179
+
180
+ ---
181
+
182
+ ## AI
183
+
184
+ Requires `aiEnabled` on your plan. Use `transport: "http"` for request/response AI calls.
185
+
186
+ ### Simple prompt
187
+
188
+ ```js
189
+ const response = await notifier.sendAI({
190
+ senderId: "user-123",
191
+ message: { text: "Summarize our refund policy in two sentences." },
192
+ });
193
+ ```
194
+
195
+ ### Chat-style messages
196
+
197
+ ```js
198
+ const response = await notifier.sendAI({
199
+ senderId: "user-123",
200
+ message: {
201
+ useKnowledgeBase: true,
202
+ messages: [
203
+ { role: "system", content: "You are a helpful support agent." },
204
+ { role: "user", content: "How do I reset my password?" },
205
+ ],
206
+ },
207
+ saveHistory: true,
208
+ });
209
+ ```
210
+
211
+ ### Continue an existing session
212
+
213
+ ```js
214
+ const first = await notifier.sendAI({
215
+ senderId: "user-123",
216
+ message: { text: "Start a new support session." },
217
+ });
218
+
219
+ const sessionId = first?.metadata?.packet?.id;
220
+
221
+ await notifier.sendAI({
222
+ senderId: "user-123",
223
+ sessionId,
224
+ message: { text: "Follow-up question in the same session." },
225
+ });
226
+ ```
227
+
228
+ ### AI history
229
+
230
+ ```js
231
+ const history = await notifier.fetchAIHistory({ senderId: "user-123" });
232
+
233
+ await notifier.deleteAIHistoryMessage({
234
+ senderId: "user-123",
235
+ messageId: "message-id-to-delete",
236
+ });
237
+ ```
238
+
239
+ ---
240
+
241
+ ## Knowledge base (RAG)
242
+
243
+ ```js
244
+ // Add
245
+ await notifier.addDocument({
246
+ senderId: "user-123",
247
+ recordId: "doc-001",
248
+ content: "Refund requests are processed within 5 business days.",
249
+ type: "text",
250
+ metadata: { source: "help-center" },
251
+ });
252
+
253
+ // Update
254
+ await notifier.updateDocument({
255
+ senderId: "user-123",
256
+ recordId: "doc-001",
257
+ content: "Updated refund policy text...",
258
+ type: "text",
259
+ });
260
+
261
+ // Get one document
262
+ const doc = await notifier.getDocument({
263
+ senderId: "user-123",
264
+ recordId: "doc-001",
265
+ });
266
+
267
+ // List
268
+ const list = await notifier.listDocuments({
269
+ senderId: "user-123",
270
+ limit: 20,
271
+ offset: 0,
272
+ type: "text",
273
+ });
274
+
275
+ // Semantic search
276
+ const hits = await notifier.search({
277
+ senderId: "user-123",
278
+ query: "how long do refunds take",
279
+ limit: 5,
280
+ minSimilarity: 0.7,
281
+ filterbySource: "help-center",
282
+ });
283
+
284
+ // Delete
285
+ await notifier.deleteDocument({
286
+ senderId: "user-123",
287
+ recordId: "doc-001",
288
+ });
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Chat history
294
+
295
+ ```js
296
+ await notifier.fetchChatHistory({
297
+ senderId: "user-123",
298
+ receiverIds: ["user-456"],
299
+ });
300
+ // Server responds via onMessage with the history payload.
301
+
302
+ await notifier.deleteChatHistoryMessage({
303
+ senderId: "user-123",
304
+ messageId: "message-id-to-delete",
305
+ });
306
+ ```
307
+
308
+ ---
309
+
310
+ ## Session logging
311
+
312
+ Enable automatic AI session tracking in the DNotifier dashboard:
313
+
314
+ ```js
315
+ const notifier = new DNotifier({
316
+ appId: "your-app-id",
317
+ secret: "your-app-secret",
318
+ transport: "http",
319
+ userId: "user-123",
320
+ logs: true,
321
+ onConnected: () => {},
322
+ onMessage: () => {},
323
+ onDisconnected: () => {},
324
+ });
325
+ ```
326
+
327
+ When `logs: true`, `sendAI` reports session start, completion, and token usage to DNotifier.
328
+
329
+ ---
330
+
331
+ ## Workflows and agents
332
+
333
+ Build deterministic, multi-step AI pipelines with **named agents**, shared **workflow state**, and optional **observability** (execution and step telemetry in the DNotifier workflow dashboard).
334
+
335
+ ### 1. Define agents
336
+
337
+ ```js
338
+ import { DNotifier } from "@dnotifier-realtime/dnotifier";
339
+
340
+ const intentAgent = DNotifier.defineAgent({
341
+ name: "intent-agent",
342
+ async run(ctx) {
343
+ await ctx.sendAI({
344
+ message: { text: "Classify: search or general?" },
345
+ saveHistory: false,
346
+ label: "Intent classification",
347
+ });
348
+ return { intent: "search" };
349
+ },
350
+ });
351
+
352
+ const generalAgent = DNotifier.defineAgent({
353
+ name: "general-agent",
354
+ async run(ctx) {
355
+ const question = ctx.input?.question ?? ctx.input;
356
+ return { answer: `You asked: ${question}` };
357
+ },
358
+ });
359
+ ```
360
+
361
+ ### 2. Define a workflow
362
+
363
+ ```js
364
+ const workflow = new DNotifier.Workflow({
365
+ name: "intent-router",
366
+ description: "Route user input to search or general Q&A",
367
+ observability: true,
368
+ async entry(ctx) {
369
+ const { intent } = await ctx.runAgent("intent-agent");
370
+
371
+ if (intent === "search") {
372
+ await ctx.search({
373
+ query: String(ctx.input),
374
+ limit: 5,
375
+ label: "Knowledge search",
376
+ });
377
+ return { branch: "search" };
378
+ }
379
+
380
+ const answer = await ctx.runAgent("general-agent", {
381
+ input: { question: ctx.input },
382
+ });
383
+ return { branch: "general", answer };
384
+ },
385
+ }).registerAgents({
386
+ "intent-agent": intentAgent,
387
+ "general-agent": generalAgent,
388
+ });
389
+ ```
390
+
391
+ ### 3. Run the workflow
392
+
393
+ ```js
394
+ const notifier = new DNotifier({
395
+ appId: "your-app-id",
396
+ secret: "your-app-secret",
397
+ transport: "http",
398
+ userId: "user-123",
399
+ onConnected: () => {},
400
+ onMessage: () => {},
401
+ onDisconnected: () => {},
402
+ });
403
+
404
+ await notifier.connect();
405
+
406
+ const run = await notifier.runWorkflow({
407
+ workflow,
408
+ input: "How does messaging work?",
409
+ });
410
+
411
+ console.log(run.executionId); // present when observability: true
412
+ console.log(run.result); // { branch: "search" } or similar
413
+ console.log(run.state); // shared state from the run
414
+ ```
415
+
416
+ ### Multi-stage pipeline example
417
+
418
+ ```js
419
+ const createAgent = DNotifier.defineAgent({
420
+ name: "content-creator",
421
+ async run(ctx) {
422
+ const brief = ctx.input;
423
+ const aiResponse = await ctx.sendAI({
424
+ message: {
425
+ useKnowledgeBase: false,
426
+ messages: [
427
+ { role: "system", content: "Write a blog draft in markdown." },
428
+ { role: "user", content: `Topic: ${brief.topic}` },
429
+ ],
430
+ },
431
+ saveHistory: false,
432
+ label: "Draft creation",
433
+ });
434
+ const content = aiResponse?.data?.content ?? "";
435
+ ctx.state.draft = content;
436
+ return { content };
437
+ },
438
+ });
439
+
440
+ const workflow = new DNotifier.Workflow({
441
+ name: "blog-article-writer",
442
+ description: "Create, refine, and optimize a blog post",
443
+ observability: true,
444
+ async entry(ctx) {
445
+ const draft = await ctx.runAgent("content-creator");
446
+ const refined = await ctx.runAgent("clarity-editor", {
447
+ input: { content: draft.content },
448
+ });
449
+ return { article: refined.content };
450
+ },
451
+ }).registerAgents({
452
+ "content-creator": createAgent,
453
+ "clarity-editor": clarityEditorAgent,
454
+ });
455
+ ```
456
+
457
+ ### `WorkflowContext` (inside `entry` and agent `run`)
458
+
459
+ | Member / method | Description |
460
+ |-----------------|-------------|
461
+ | `ctx.input` | Workflow input passed to `runWorkflow` (or overridden per `runAgent`) |
462
+ | `ctx.state` | Shared mutable object for the current execution |
463
+ | `ctx.agentName` | Name of the agent currently running (inside agent handlers) |
464
+ | `ctx.runAgent(name, { input? })` | Invoke a registered agent |
465
+ | `ctx.sendAI({ message, saveHistory?, label? })` | AI call; steps recorded when observability is on |
466
+ | `ctx.fetchAIHistory({ label? })` | Fetch AI history |
467
+ | `ctx.search({ query, limit?, minSimilarity?, filterbySource?, label? })` | Semantic search |
468
+ | `ctx.addDocument(opts)` | Add knowledge-base document |
469
+ | `ctx.updateDocument(opts)` | Update document |
470
+ | `ctx.deleteDocument(opts)` | Delete document |
471
+ | `ctx.listDocuments(opts?)` | List documents |
472
+ | `ctx.getDocument(opts)` | Get document by id |
473
+ | `ctx.recordStep({ label, input?, output?, status?, type? })` | Record a custom step when observability is enabled |
474
+
475
+ When `observability: true` on the workflow, SDK calls and `recordStep` are sent to the DNotifier workflow dashboard. No extra setup is required beyond `connect()`.
476
+
477
+ ---
478
+
479
+ ## API reference
480
+
481
+ ### `DNotifier`
482
+
483
+ | Method | Description |
484
+ |--------|-------------|
485
+ | `connect()` | Authenticate and connect |
486
+ | `disconnect()` | Close the WebSocket connection |
487
+ | `getPlanLimits()` | Plan limits from last auth |
488
+ | `send({ senderId, receiverId?, receiverIds?, data, saveHistory? })` | Send a message |
489
+ | `sendBinary({ senderId, receiverIds, buffer, type? })` | Send raw bytes |
490
+ | `sendAI({ senderId, message, saveHistory?, sessionId? })` | Send to AI pipeline |
491
+ | `fetchAIHistory({ senderId })` | Fetch AI conversation history |
492
+ | `deleteAIHistoryMessage({ senderId, messageId })` | Delete one AI history message |
493
+ | `fetchChatHistory({ senderId, receiverIds })` | Request chat history (response via `onMessage`) |
494
+ | `deleteChatHistoryMessage({ senderId, messageId })` | Delete one chat history message |
495
+ | `search({ senderId, query, limit?, minSimilarity?, filterbySource? })` | Semantic search over knowledge base |
496
+ | `addDocument({ senderId, recordId, content, type?, metadata? })` | Add a document |
497
+ | `updateDocument({ senderId, recordId, content, type?, metadata? })` | Update a document |
498
+ | `getDocument({ senderId, recordId })` | Get a document |
499
+ | `listDocuments({ senderId, limit?, offset?, type? })` | List documents |
500
+ | `deleteDocument({ senderId, recordId })` | Delete a document |
501
+ | `runWorkflow({ workflow, input, senderId? })` | Run a workflow after `connect()` |
502
+ | `sendWithOpenAI(...)` | **Deprecated** — use `sendAI` |
503
+
504
+ ### Workflow exports
505
+
506
+ | Export | Description |
507
+ |--------|-------------|
508
+ | `DNotifier.defineAgent({ name, run })` | Create a named agent |
509
+ | `DNotifier.Workflow` | Workflow definition class |
510
+ | `DNotifier.WorkflowContext` | Context type passed to `entry` and agent `run` |
511
+ | `DNotifier.WorkflowError` | Workflow validation and runtime errors |
512
+ | `Agent` | Agent class (also available via `defineAgent`) |
513
+
514
+ `runWorkflow` is the recommended way to execute a workflow. `WorkflowRunner` is exported for advanced custom hosting but is not required for typical use.
515
+
516
+ ### Message and payload types
517
+
518
+ **`DNotifierMessage`**
519
+
520
+ - `metadata` — `{ id, sender, timestamp, type }`
521
+ - `payload` — `Payload` instance
522
+
523
+ **`Payload`**
524
+
525
+ - `toJSON()` — parse JSON body
526
+ - `toString()` — string body
527
+ - `toBase64()` — base64 string
528
+ - `raw()` — raw bytes
529
+
530
+ **`getPlanLimits()` return value**
531
+
532
+ - `messagesHardLimit`, `maxAIRequestsPerMonth`, `maxAIWordsPerMonth`
533
+ - `knowledgeBaseMaxWords`, `aiEnabled`, `maxUsers`, `maxRowsPerUser`
534
+
535
+ **`runWorkflow` return value**
536
+
537
+ - `result` — return value of the workflow `entry` function
538
+ - `state` — final shared workflow state
539
+ - `executionId` — present when `observability: true`
540
+
541
+ ---
542
+
543
+ ## Links
544
+
545
+ - **Product:** [dnotifier.com](https://www.dnotifier.com)
546
+ - **Documentation:** [Product docs](https://dnotifier.gitbook.io/product-docs)
@@ -1 +1 @@
1
- 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['DNotifier']=void 0x0;const httpTransport_js_1=require('./transport/httpTransport.js'),websocketTransport_js_1=require('./transport/websocketTransport.js'),id_js_1=require('./utils/id.js'),frame_js_1=require('./utils/frame.js'),payload_js_1=require('./utils/payload.js'),buffer_js_1=require('./utils/buffer.js'),openai_js_1=require('./providers/openai.js');class DNotifier{constructor({appId:_0x4acb67,secret:_0x2c50ab,transport:_0x572700,userId:_0xcab45d,onConnected:_0x38b056,onMessage:_0xaca590,onDisconnected:_0x20b534,WebSocketImpl:_0x3862e5}){if(!(_0x4acb67&&_0x2c50ab&&_0x572700&&_0xcab45d))throw new Error('appId,\x20secret,\x20transport,\x20and\x20userId\x20are\x20required');this['appId']=_0x4acb67,this['secret']=_0x2c50ab,this['userId']=_0xcab45d,this['url']='wss://link.dchatter.com/ws',this['onConnectedCallback']=_0x38b056||(()=>{}),this['onMessageCallback']=_0xaca590||(()=>{}),this['onDisconnectedCallback']=_0x20b534||(()=>{}),this['isConnected']=!0x1,this['transport']='ws'===_0x572700?new websocketTransport_js_1['WebsocketTransport'](_0x3862e5):new httpTransport_js_1['HttpTransport']();}async['connect'](){const _0x2a549a=new httpTransport_js_1['HttpTransport']({'url':'https://link.dchatter.com/api/v1/sdk/auth'}),_0x1d95c2=await _0x2a549a['send']({'appId':this['appId'],'appSecret':this['secret'],'userID':this['userId']});if(0xc8!==_0x1d95c2['_responseCode'])throw new Error('Authentication\x20Failed.');this['authToken']=_0x1d95c2['_responseData'],await this['transport']['connect'](this['url']);const _0x4a2272={'type':'text','code':0x65,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],this['userId']),'timestamp':Date['now'](),'token':this['authToken']},_0x1ddb5e=(0x0,buffer_js_1['toUint8'])(JSON['stringify']({'token':this['authToken']})),_0x3733ab=(0x0,frame_js_1['framePacket'])(_0x4a2272,_0x1ddb5e);this['transport']['sendBinary'](_0x3733ab);let _0x5cf114=!0x1;this['transport']['on']('message',_0x1cd462=>{try{const {metadata:_0x50628a,data:_0x1ab013}=_0x1cd462;if(!_0x5cf114&&'102'===_0x50628a['packet']['code']&&_0x50628a['packet']['sender']['includes']((0x0,id_js_1['prefixId'])(this['appId'],this['userId'])))return _0x5cf114=!0x0,this['isConnected']=!0x0,void this['onConnectedCallback']();_0x5cf114&&this['onMessageCallback']({'metadata':{'sender':_0x50628a['packet']['sender'],'timestamp':_0x50628a['packet']['timestamp']},'payload':new payload_js_1['Payload'](_0x1ab013)});}catch(_0x5c1ec0){console['error']('Packet\x20error:',_0x5c1ec0);}}),this['transport']['on']('close',({code:_0x2bc633,reason:_0x455404})=>{this['isConnected']&&(this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':_0x2bc633,'reason':_0x455404||'Disconnected'}));}),this['transport']['on']('error',_0x219d97=>{this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':0x1f4,'reason':(null==_0x219d97?void 0x0:_0x219d97['message'])||'Transport\x20error'});});}['send']({senderId:_0x42f16c,receiverId:_0x4b4da2,receiverIds:_0xa0635a,data:_0x28520f}){if(!_0x42f16c)throw new Error('senderId\x20required');if(!_0x4b4da2&&!_0xa0635a)throw new Error('receiverId\x20or\x20receiverIds\x20required');const _0x33123d=null!=_0xa0635a?_0xa0635a:[_0x4b4da2],_0xe3889f={'type':'text','code':0xc8,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x42f16c),'receivers':_0x33123d['map'](_0xca208e=>(0x0,id_js_1['prefixId'])(this['appId'],_0xca208e)),'timestamp':Date['now'](),'token':this['authToken']},_0x259f1d=(0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x28520f)),_0x1dbb46=(0x0,frame_js_1['framePacket'])(_0xe3889f,_0x259f1d);this['transport']['sendBinary'](_0x1dbb46);}['sendBinary']({senderId:_0x371743,receiverIds:_0x170adb,buffer:_0x3e1011,type:_0x54b36e='binary'}){if(!_0x371743)throw new Error('senderId\x20required');if(!_0x3e1011)throw new Error('buffer\x20is\x20required');const _0x4bac63={'type':_0x54b36e,'code':0xca,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x371743),'receivers':_0x170adb['map'](_0x3cd1ad=>(0x0,id_js_1['prefixId'])(this['appId'],_0x3cd1ad)),'timestamp':Date['now'](),'token':this['authToken']},_0x2f2b57=(0x0,frame_js_1['framePacket'])(_0x4bac63,_0x3e1011);this['transport']['sendBinary'](_0x2f2b57);}async['sendWithOpenAI']({senderId:_0x1b9d79,message:_0x5c2470,openaiApiKey:_0xd8bb4a,model:_0x5d2b7b,baseUrl:_0x3a85c3}){if(!_0x1b9d79)throw new Error('senderId\x20is\x20required');if(!_0x5c2470)throw new Error('message\x20is\x20required');if(!_0xd8bb4a)throw new Error('openaiApiKey\x20is\x20required');const {content:_0x8e0b0e}=await(0x0,openai_js_1['chatStream'])({'apiKey':_0xd8bb4a,'model':_0x5d2b7b,'messages':_0x5c2470,'baseUrl':_0x3a85c3}),_0x37a63a={'type':'openai','content':_0x8e0b0e,'ts':Date['now']()};return this['onMessageCallback']({'metadata':{'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x1b9d79),'timestamp':Date['now']()},'payload':new payload_js_1['Payload']((0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x37a63a)))}),{'content':_0x8e0b0e};}}exports['DNotifier']=DNotifier;
1
+ 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['DNotifier']=void 0x0;const httpTransport_js_1=require('./transport/httpTransport.js'),websocketTransport_js_1=require('./transport/websocketTransport.js'),id_js_1=require('./utils/id.js'),frame_js_1=require('./utils/frame.js'),payload_js_1=require('./utils/payload.js'),buffer_js_1=require('./utils/buffer.js'),openai_js_1=require('./providers/openai.js');class DNotifier{constructor({appId:_0x2d0ac5,secret:_0x2dd256,transport:_0x4414f1,userId:_0x30279a,onConnected:_0x348073,onMessage:_0x2bea6c,onDisconnected:_0x2519ae,WebSocketImpl:_0x970ea1}){if(!(_0x2d0ac5&&_0x2dd256&&_0x4414f1&&_0x30279a))throw new Error('appId,\x20secret,\x20transport,\x20and\x20userId\x20are\x20required');this['appId']=_0x2d0ac5,this['secret']=_0x2dd256,this['userId']=_0x30279a,this['url']='wss://link.dchatter.com/ws',this['onConnectedCallback']=_0x348073||(()=>{}),this['onMessageCallback']=_0x2bea6c||(()=>{}),this['onDisconnectedCallback']=_0x2519ae||(()=>{}),this['isConnected']=!0x1,this['transport']='ws'===_0x4414f1?new websocketTransport_js_1['WebsocketTransport'](_0x970ea1):new httpTransport_js_1['HttpTransport']();}async['connect'](){const _0x138609=new httpTransport_js_1['HttpTransport']({'url':'https://link.dchatter.com/api/v1/sdk/auth'}),_0x1ee829=await _0x138609['send']({'appId':this['appId'],'appSecret':this['secret'],'userID':this['userId']});if(0xc8!==_0x1ee829['_responseCode'])throw new Error('Authentication\x20Failed.');this['authToken']=_0x1ee829['_responseData'],await this['transport']['connect'](this['url']);const _0x230e0a={'type':'text','code':0x65,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],this['userId']),'timestamp':Date['now'](),'token':this['authToken']},_0x4d6cab=(0x0,buffer_js_1['toUint8'])(JSON['stringify']({'token':this['authToken']})),_0x40b9ec=(0x0,frame_js_1['framePacket'])(_0x230e0a,_0x4d6cab);this['transport']['sendBinary'](_0x40b9ec);let _0x1ea75e=!0x1;this['transport']['on']('message',_0x2beb21=>{try{const {metadata:_0x3d371d,data:_0x116d4d}=_0x2beb21;if(!_0x1ea75e&&'102'===_0x3d371d['packet']['code']&&_0x3d371d['packet']['sender']['includes']((0x0,id_js_1['prefixId'])(this['appId'],this['userId'])))return _0x1ea75e=!0x0,this['isConnected']=!0x0,void this['onConnectedCallback']();_0x1ea75e&&this['onMessageCallback']({'metadata':{'sender':_0x3d371d['packet']['sender'],'timestamp':_0x3d371d['packet']['timestamp']},'payload':new payload_js_1['Payload'](_0x116d4d)});}catch(_0x3b7966){console['error']('Packet\x20error:',_0x3b7966);}}),this['transport']['on']('close',({code:_0x167bea,reason:_0x5e52a5})=>{this['isConnected']&&(this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':_0x167bea,'reason':_0x5e52a5||'Disconnected'}));}),this['transport']['on']('error',_0x551e9a=>{this['isConnected']=!0x1,this['onDisconnectedCallback']({'code':0x1f4,'reason':(null==_0x551e9a?void 0x0:_0x551e9a['message'])||'Transport\x20error'});});}['send']({senderId:_0x2330c5,receiverId:_0x1774ae,receiverIds:_0x53cb3c,data:_0x5bde23}){if(!_0x2330c5)throw new Error('senderId\x20required');if(!_0x1774ae&&!_0x53cb3c)throw new Error('receiverId\x20or\x20receiverIds\x20required');const _0x34a7ea=null!=_0x53cb3c?_0x53cb3c:[_0x1774ae],_0x410ffd={'type':'text','code':0xc8,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x2330c5),'receivers':_0x34a7ea['map'](_0x194b7f=>(0x0,id_js_1['prefixId'])(this['appId'],_0x194b7f)),'timestamp':Date['now'](),'token':this['authToken']},_0x38a125=(0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x5bde23)),_0x29b8b9=(0x0,frame_js_1['framePacket'])(_0x410ffd,_0x38a125);this['transport']['sendBinary'](_0x29b8b9);}['sendBinary']({senderId:_0x5670e9,receiverIds:_0x11d68a,buffer:_0x880b56,type:_0x6aeb24='binary'}){if(!_0x5670e9)throw new Error('senderId\x20required');if(!_0x880b56)throw new Error('buffer\x20is\x20required');const _0x188dec={'type':_0x6aeb24,'code':0xca,'appId':this['appId'],'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x5670e9),'receivers':_0x11d68a['map'](_0x591fdd=>(0x0,id_js_1['prefixId'])(this['appId'],_0x591fdd)),'timestamp':Date['now'](),'token':this['authToken']},_0x2deb96=(0x0,frame_js_1['framePacket'])(_0x188dec,_0x880b56);this['transport']['sendBinary'](_0x2deb96);}async['sendWithOpenAI']({senderId:_0x3e1c3f,message:_0x1e8016,openaiApiKey:_0x4a892a,model:_0x18f183,baseUrl:_0x4b4c7e}){if(!_0x3e1c3f)throw new Error('senderId\x20is\x20required');if(!_0x1e8016)throw new Error('message\x20is\x20required');if(!_0x4a892a)throw new Error('openaiApiKey\x20is\x20required');const {content:_0x412637}=await(0x0,openai_js_1['chatStream'])({'apiKey':_0x4a892a,'model':_0x18f183,'messages':_0x1e8016,'baseUrl':_0x4b4c7e}),_0x6cafb5={'type':'openai','content':_0x412637,'ts':Date['now']()};return this['onMessageCallback']({'metadata':{'sender':(0x0,id_js_1['prefixId'])(this['appId'],_0x3e1c3f),'timestamp':Date['now']()},'payload':new payload_js_1['Payload']((0x0,buffer_js_1['toUint8'])(JSON['stringify'](_0x6cafb5)))}),{'content':_0x412637};}}exports['DNotifier']=DNotifier;
@@ -1 +1 @@
1
- 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['chat']=chat,exports['chatStream']=chatStream;const DEFAULT_BASE_URL='https://api.openai.com',DEFAULT_MODEL='gpt-4o-mini';function normalizeMessages(_0x2a405d){if('string'==typeof _0x2a405d)return[{'role':'user','content':_0x2a405d}];if(Array['isArray'](_0x2a405d)&&_0x2a405d['length']>0x0)return _0x2a405d['map'](_0x1fa0e2=>({'role':_0x1fa0e2['role']||'user','content':'string'==typeof _0x1fa0e2['content']?_0x1fa0e2['content']:String(_0x1fa0e2['content'])}));throw new Error('message\x20must\x20be\x20a\x20non-empty\x20string\x20or\x20array\x20of\x20{\x20role,\x20content\x20}');}async function chat(_0x4086d0){var _0x1f597d,_0x1f7290,_0x15f541,_0x4f6576,_0xb4cfd9,_0x3af545;const {apiKey:_0x2c6179,model:_0x411603=DEFAULT_MODEL,messages:_0x59acb6,baseUrl:_0x2bbe3b=DEFAULT_BASE_URL}=_0x4086d0;if(!_0x2c6179||!_0x59acb6)throw new Error('openai.chat:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x501e8f=_0x2bbe3b['replace'](/\/$/,'')+'/v1/chat/completions',_0x9c781f={'model':_0x411603,'messages':normalizeMessages(_0x59acb6),'stream':!0x1},_0xe66c93=await fetch(_0x501e8f,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x2c6179},'body':JSON['stringify'](_0x9c781f)}),_0x118765=await _0xe66c93['json']();if(!_0xe66c93['ok']){const _0x1cd00=new Error((null===(_0x1f597d=null==_0x118765?void 0x0:_0x118765['error'])||void 0x0===_0x1f597d?void 0x0:_0x1f597d['message'])||'OpenAI\x20API\x20error:\x20'+_0xe66c93['status']);throw _0x1cd00['status']=_0xe66c93['status'],_0x1cd00['code']=null===(_0x1f7290=null==_0x118765?void 0x0:_0x118765['error'])||void 0x0===_0x1f7290?void 0x0:_0x1f7290['code'],_0x1cd00;}return{'content':null!==(_0x3af545=null===(_0xb4cfd9=null===(_0x4f6576=null===(_0x15f541=null==_0x118765?void 0x0:_0x118765['choices'])||void 0x0===_0x15f541?void 0x0:_0x15f541[0x0])||void 0x0===_0x4f6576?void 0x0:_0x4f6576['message'])||void 0x0===_0xb4cfd9?void 0x0:_0xb4cfd9['content'])&&void 0x0!==_0x3af545?_0x3af545:'','usage':null==_0x118765?void 0x0:_0x118765['usage'],'raw':_0x118765};}async function chatStream(_0x5bed47){var _0x3b6032,_0x3d9926,_0x288d90,_0x568609,_0x61537f;const {apiKey:_0x286ba3,model:_0x739efb=DEFAULT_MODEL,messages:_0x17ce44,baseUrl:_0x50eae8=DEFAULT_BASE_URL,onChunk:_0x28c42e}=_0x5bed47;if(!_0x286ba3||!_0x17ce44)throw new Error('openai.chatStream:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x26bfec=_0x50eae8['replace'](/\/$/,'')+'/v1/chat/completions',_0x2d23a3={'model':_0x739efb,'messages':normalizeMessages(_0x17ce44),'stream':!0x0},_0xab6b5a=await fetch(_0x26bfec,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x286ba3},'body':JSON['stringify'](_0x2d23a3)});if(!_0xab6b5a['ok']){const _0x3f8424=await _0xab6b5a['json']()['catch'](()=>({})),_0x1193ca=new Error((null===(_0x3b6032=null==_0x3f8424?void 0x0:_0x3f8424['error'])||void 0x0===_0x3b6032?void 0x0:_0x3b6032['message'])||'OpenAI\x20API\x20error:\x20'+_0xab6b5a['status']);throw _0x1193ca['status']=_0xab6b5a['status'],_0x1193ca['code']=null===(_0x3d9926=null==_0x3f8424?void 0x0:_0x3f8424['error'])||void 0x0===_0x3d9926?void 0x0:_0x3d9926['code'],_0x1193ca;}const _0x1583bd=_0xab6b5a['body']['getReader'](),_0x4f7713=new TextDecoder();let _0x4d8a4f='',_0x52658c='';for(;;){const {done:_0x3e1fc6,value:_0x53d91d}=await _0x1583bd['read']();if(_0x3e1fc6)break;_0x52658c+=_0x4f7713['decode'](_0x53d91d,{'stream':!0x0});const _0x22759d=_0x52658c['split']('\x0a');_0x52658c=_0x22759d['pop']()||'';for(const _0x130a60 of _0x22759d){const _0x244f87=_0x130a60['trim']();if(''!==_0x244f87&&'data:\x20[DONE]'!==_0x244f87&&_0x244f87['startsWith']('data:\x20'))try{const _0x48dead=JSON['parse'](_0x244f87['slice'](0x6)),_0xb24c2d=null===(_0x61537f=null===(_0x568609=null===(_0x288d90=null==_0x48dead?void 0x0:_0x48dead['choices'])||void 0x0===_0x288d90?void 0x0:_0x288d90[0x0])||void 0x0===_0x568609?void 0x0:_0x568609['delta'])||void 0x0===_0x61537f?void 0x0:_0x61537f['content'];'string'==typeof _0xb24c2d&&(_0x4d8a4f+=_0xb24c2d,_0x28c42e&&_0x28c42e(_0xb24c2d));}catch(_0x1c1859){}}}return{'content':_0x4d8a4f};}
1
+ 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['chat']=chat,exports['chatStream']=chatStream;const DEFAULT_BASE_URL='https://api.openai.com',DEFAULT_MODEL='gpt-4o-mini';function normalizeMessages(_0x54ffd7){if('string'==typeof _0x54ffd7)return[{'role':'user','content':_0x54ffd7}];if(Array['isArray'](_0x54ffd7)&&_0x54ffd7['length']>0x0)return _0x54ffd7['map'](_0x45fdca=>({'role':_0x45fdca['role']||'user','content':'string'==typeof _0x45fdca['content']?_0x45fdca['content']:String(_0x45fdca['content'])}));throw new Error('message\x20must\x20be\x20a\x20non-empty\x20string\x20or\x20array\x20of\x20{\x20role,\x20content\x20}');}async function chat(_0x173788){var _0x250e3f,_0x318866,_0x476456,_0x294e3c,_0x53a3e0,_0x3baccc;const {apiKey:_0x4272d0,model:_0x39c37e=DEFAULT_MODEL,messages:_0x4d38f9,baseUrl:_0x3e65a6=DEFAULT_BASE_URL}=_0x173788;if(!_0x4272d0||!_0x4d38f9)throw new Error('openai.chat:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x5d24d3=_0x3e65a6['replace'](/\/$/,'')+'/v1/chat/completions',_0x5e9380={'model':_0x39c37e,'messages':normalizeMessages(_0x4d38f9),'stream':!0x1},_0x44a5d0=await fetch(_0x5d24d3,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x4272d0},'body':JSON['stringify'](_0x5e9380)}),_0x167666=await _0x44a5d0['json']();if(!_0x44a5d0['ok']){const _0x1ef961=new Error((null===(_0x250e3f=null==_0x167666?void 0x0:_0x167666['error'])||void 0x0===_0x250e3f?void 0x0:_0x250e3f['message'])||'OpenAI\x20API\x20error:\x20'+_0x44a5d0['status']);throw _0x1ef961['status']=_0x44a5d0['status'],_0x1ef961['code']=null===(_0x318866=null==_0x167666?void 0x0:_0x167666['error'])||void 0x0===_0x318866?void 0x0:_0x318866['code'],_0x1ef961;}return{'content':null!==(_0x3baccc=null===(_0x53a3e0=null===(_0x294e3c=null===(_0x476456=null==_0x167666?void 0x0:_0x167666['choices'])||void 0x0===_0x476456?void 0x0:_0x476456[0x0])||void 0x0===_0x294e3c?void 0x0:_0x294e3c['message'])||void 0x0===_0x53a3e0?void 0x0:_0x53a3e0['content'])&&void 0x0!==_0x3baccc?_0x3baccc:'','usage':null==_0x167666?void 0x0:_0x167666['usage'],'raw':_0x167666};}async function chatStream(_0x3a9009){var _0x302718,_0x4cd852,_0x289975,_0x1d0950,_0x14827f;const {apiKey:_0x56b1af,model:_0x32843b=DEFAULT_MODEL,messages:_0x59b16b,baseUrl:_0x5615be=DEFAULT_BASE_URL,onChunk:_0xd26da5}=_0x3a9009;if(!_0x56b1af||!_0x59b16b)throw new Error('openai.chatStream:\x20apiKey\x20and\x20messages\x20are\x20required');const _0x50d6a2=_0x5615be['replace'](/\/$/,'')+'/v1/chat/completions',_0x20bfa0={'model':_0x32843b,'messages':normalizeMessages(_0x59b16b),'stream':!0x0},_0x501dc8=await fetch(_0x50d6a2,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x56b1af},'body':JSON['stringify'](_0x20bfa0)});if(!_0x501dc8['ok']){const _0x4e007f=await _0x501dc8['json']()['catch'](()=>({})),_0x2c2b0e=new Error((null===(_0x302718=null==_0x4e007f?void 0x0:_0x4e007f['error'])||void 0x0===_0x302718?void 0x0:_0x302718['message'])||'OpenAI\x20API\x20error:\x20'+_0x501dc8['status']);throw _0x2c2b0e['status']=_0x501dc8['status'],_0x2c2b0e['code']=null===(_0x4cd852=null==_0x4e007f?void 0x0:_0x4e007f['error'])||void 0x0===_0x4cd852?void 0x0:_0x4cd852['code'],_0x2c2b0e;}const _0xed459d=_0x501dc8['body']['getReader'](),_0x1bd02e=new TextDecoder();let _0x5a7838='',_0x2a324c='';for(;;){const {done:_0x57c169,value:_0x14e7ae}=await _0xed459d['read']();if(_0x57c169)break;_0x2a324c+=_0x1bd02e['decode'](_0x14e7ae,{'stream':!0x0});const _0x4e8f35=_0x2a324c['split']('\x0a');_0x2a324c=_0x4e8f35['pop']()||'';for(const _0x16d679 of _0x4e8f35){const _0x35a2c7=_0x16d679['trim']();if(''!==_0x35a2c7&&'data:\x20[DONE]'!==_0x35a2c7&&_0x35a2c7['startsWith']('data:\x20'))try{const _0x4b25fb=JSON['parse'](_0x35a2c7['slice'](0x6)),_0x289235=null===(_0x14827f=null===(_0x1d0950=null===(_0x289975=null==_0x4b25fb?void 0x0:_0x4b25fb['choices'])||void 0x0===_0x289975?void 0x0:_0x289975[0x0])||void 0x0===_0x1d0950?void 0x0:_0x1d0950['delta'])||void 0x0===_0x14827f?void 0x0:_0x14827f['content'];'string'==typeof _0x289235&&(_0x5a7838+=_0x289235,_0xd26da5&&_0xd26da5(_0x289235));}catch(_0x3626a1){}}}return{'content':_0x5a7838};}
@@ -1 +1 @@
1
- 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['HttpTransport']=void 0x0;class HttpTransport{constructor({url:_0x2cd93d}){this['url']=_0x2cd93d;}async['send'](_0xb2f490){const _0x44fc36=await fetch(''+this['url'],{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify'](_0xb2f490)});if(!_0x44fc36['ok']){const _0x21e92d=await _0x44fc36['text']();throw new Error('DNotifier\x20HTTP\x20error:\x20'+_0x21e92d);}return await _0x44fc36['json']();}['sendBinary'](){throw new Error('Binary\x20is\x20not\x20supported\x20over\x20HTTP\x20yet');}}exports['HttpTransport']=HttpTransport;
1
+ 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['HttpTransport']=void 0x0;class HttpTransport{constructor({url:_0x44d5ef}){this['url']=_0x44d5ef;}async['send'](_0x50d460){const _0x177c62=await fetch(''+this['url'],{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify'](_0x50d460)});if(!_0x177c62['ok']){const _0xbaa202=await _0x177c62['text']();throw new Error('DNotifier\x20HTTP\x20error:\x20'+_0xbaa202);}return await _0x177c62['json']();}['sendBinary'](){throw new Error('Binary\x20is\x20not\x20supported\x20over\x20HTTP\x20yet');}}exports['HttpTransport']=HttpTransport;
@@ -1 +1 @@
1
- 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['WebsocketTransport']=void 0x0;const events_1=require('events'),frame_js_1=require('../utils/frame.js');class WebsocketTransport extends events_1['default']{constructor(_0x57711d=null){if(super(),this['socket']=null,this['WebSocketImpl']=_0x57711d||('undefined'!=typeof window?window['WebSocket']:null),!this['WebSocketImpl'])throw new Error('No\x20WebSocket\x20implementation\x20provided');}['connect'](_0x4e7f3e){return new Promise((_0x4b39b9,_0x3b8334)=>{this['socket']=new this['WebSocketImpl'](_0x4e7f3e),'undefined'!=typeof window&&(this['socket']['binaryType']='arrayBuffer'),this['_on']('open',()=>_0x4b39b9(!0x0)),this['_on']('error',_0x2b1671=>{console['error']('WS\x20error',_0x2b1671),_0x3b8334(_0x2b1671);}),this['_on']('close',_0x586e5d=>{const _0x495a1f=null==_0x586e5d?void 0x0:_0x586e5d['code'],_0x2a6880=null==_0x586e5d?void 0x0:_0x586e5d['reason'];this['emit']('close',{'code':_0x495a1f,'reason':_0x2a6880});}),this['_on']('message',async(_0x2784e5,_0x2903de)=>{var _0x1d953e,_0xc527ab=null!==(_0x1d953e=null==_0x2784e5?void 0x0:_0x2784e5['data'])&&void 0x0!==_0x1d953e?_0x1d953e:_0x2784e5;'undefined'!=typeof Blob&&_0xc527ab instanceof Blob&&(_0xc527ab=await _0xc527ab['arrayBuffer']());const _0x253ffe=(0x0,frame_js_1['decodePacket'])(_0xc527ab);_0x253ffe&&this['emit']('message',_0x253ffe,_0x2903de);});});}['_on'](_0x1f7cfc,_0x1e04d2){this['socket']['on']?this['socket']['on'](_0x1f7cfc,_0x1e04d2):this['socket']['on'+_0x1f7cfc]=_0x1e04d2;}['send'](_0x2fc584){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x2fc584);}['sendBinary'](_0x1724fb){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x1724fb);}['isOpen'](){return this['socket']&&this['socket']['readyState']===this['WebSocketImpl']['OPEN'];}['close'](){var _0x850b4b;null===(_0x850b4b=this['socket'])||void 0x0===_0x850b4b||_0x850b4b['close']();}}exports['WebsocketTransport']=WebsocketTransport;
1
+ 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['WebsocketTransport']=void 0x0;const events_1=require('events'),frame_js_1=require('../utils/frame.js');class WebsocketTransport extends events_1['default']{constructor(_0x28bcad=null){if(super(),this['socket']=null,this['WebSocketImpl']=_0x28bcad||('undefined'!=typeof window?window['WebSocket']:null),!this['WebSocketImpl'])throw new Error('No\x20WebSocket\x20implementation\x20provided');}['connect'](_0x336f38){return new Promise((_0x14e651,_0x46bd84)=>{this['socket']=new this['WebSocketImpl'](_0x336f38),'undefined'!=typeof window&&(this['socket']['binaryType']='arrayBuffer'),this['_on']('open',()=>_0x14e651(!0x0)),this['_on']('error',_0x470468=>{console['error']('WS\x20error',_0x470468),_0x46bd84(_0x470468);}),this['_on']('close',_0x49f215=>{const _0xceb9eb=null==_0x49f215?void 0x0:_0x49f215['code'],_0x34b5b9=null==_0x49f215?void 0x0:_0x49f215['reason'];this['emit']('close',{'code':_0xceb9eb,'reason':_0x34b5b9});}),this['_on']('message',async(_0x5f3da4,_0x5d05da)=>{var _0xe2d887,_0x1b0737=null!==(_0xe2d887=null==_0x5f3da4?void 0x0:_0x5f3da4['data'])&&void 0x0!==_0xe2d887?_0xe2d887:_0x5f3da4;'undefined'!=typeof Blob&&_0x1b0737 instanceof Blob&&(_0x1b0737=await _0x1b0737['arrayBuffer']());const _0x4fd694=(0x0,frame_js_1['decodePacket'])(_0x1b0737);_0x4fd694&&this['emit']('message',_0x4fd694,_0x5d05da);});});}['_on'](_0x2c77ab,_0x36c4b7){this['socket']['on']?this['socket']['on'](_0x2c77ab,_0x36c4b7):this['socket']['on'+_0x2c77ab]=_0x36c4b7;}['send'](_0x1bdd55){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x1bdd55);}['sendBinary'](_0x2ba019){if(!this['isOpen']())throw new Error('WebSocket\x20not\x20connected');this['socket']['send'](_0x2ba019);}['isOpen'](){return this['socket']&&this['socket']['readyState']===this['WebSocketImpl']['OPEN'];}['close'](){var _0x57cbd5;null===(_0x57cbd5=this['socket'])||void 0x0===_0x57cbd5||_0x57cbd5['close']();}}exports['WebsocketTransport']=WebsocketTransport;
@@ -1 +1 @@
1
- 'use strict';function toUint8(_0x2a7e17){return'undefined'!=typeof Buffer?Buffer['from'](_0x2a7e17,'utf8'):new TextEncoder()['encode'](_0x2a7e17);}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['toUint8']=toUint8;
1
+ 'use strict';function toUint8(_0x17e743){return'undefined'!=typeof Buffer?Buffer['from'](_0x17e743,'utf8'):new TextEncoder()['encode'](_0x17e743);}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['toUint8']=toUint8;
@@ -1 +1 @@
1
- 'use strict';function framePacket(_0x11ae21,_0x345ef3){const _0x47aaf3=Buffer['from'](JSON['stringify'](_0x11ae21)),_0x3fbb94=Buffer['isBuffer'](_0x345ef3)?_0x345ef3:Buffer['from'](_0x345ef3),_0x440b2b=Buffer['alloc'](0x4+_0x47aaf3['length']+0x4+_0x3fbb94['length']);let _0xf757ee=0x0;return _0x440b2b['writeUInt32BE'](_0x47aaf3['length'],_0xf757ee),_0xf757ee+=0x4,_0x47aaf3['copy'](_0x440b2b,_0xf757ee),_0xf757ee+=_0x47aaf3['length'],_0x440b2b['writeUInt32BE'](_0x3fbb94['length'],_0xf757ee),_0xf757ee+=0x4,_0x3fbb94['copy'](_0x440b2b,_0xf757ee),_0x440b2b;}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['framePacket']=framePacket,exports['decodePacket']=decodePacket;let internalBuffer=Buffer['alloc'](0x0);function decodePacket(_0x414e2d){try{Buffer['isBuffer'](_0x414e2d)||(_0x414e2d=Buffer['from'](_0x414e2d)),internalBuffer=Buffer['concat']([internalBuffer,_0x414e2d]);let _0x480459=0x0;if(internalBuffer['length']<0x4)return null;const _0x39eb9b=internalBuffer['readUInt32BE'](_0x480459);if(_0x480459+=0x4,internalBuffer['length']<_0x480459+_0x39eb9b)return null;const _0x219003=internalBuffer['slice'](_0x480459,_0x480459+_0x39eb9b),_0x5d7041=JSON['parse'](_0x219003['toString']());if(_0x480459+=_0x39eb9b,internalBuffer['length']<_0x480459+0x4)return null;const _0x14af69=internalBuffer['readUInt32BE'](_0x480459);if(_0x480459+=0x4,internalBuffer['length']<_0x480459+_0x14af69)return null;const _0x198ef1=internalBuffer['slice'](_0x480459,_0x480459+_0x14af69);_0x480459+=_0x14af69,internalBuffer=internalBuffer['slice'](_0x480459);let _0x14738d=_0x198ef1;if('text'===_0x5d7041['type'])try{_0x14738d=JSON['parse'](_0x198ef1['toString']('utf8'));}catch{_0x14738d=_0x198ef1;}return{'metadata':_0x5d7041,'data':_0x14738d};}catch(_0x10923d){return console['error']('decodePacket\x20error:',_0x10923d),null;}}
1
+ 'use strict';function framePacket(_0x484078,_0x18be5e){const _0x5c81f3=Buffer['from'](JSON['stringify'](_0x484078)),_0x5de600=Buffer['isBuffer'](_0x18be5e)?_0x18be5e:Buffer['from'](_0x18be5e),_0x43806e=Buffer['alloc'](0x4+_0x5c81f3['length']+0x4+_0x5de600['length']);let _0x40595f=0x0;return _0x43806e['writeUInt32BE'](_0x5c81f3['length'],_0x40595f),_0x40595f+=0x4,_0x5c81f3['copy'](_0x43806e,_0x40595f),_0x40595f+=_0x5c81f3['length'],_0x43806e['writeUInt32BE'](_0x5de600['length'],_0x40595f),_0x40595f+=0x4,_0x5de600['copy'](_0x43806e,_0x40595f),_0x43806e;}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports['framePacket']=framePacket,exports['decodePacket']=decodePacket;let internalBuffer=Buffer['alloc'](0x0);function decodePacket(_0x11f4ce){try{Buffer['isBuffer'](_0x11f4ce)||(_0x11f4ce=Buffer['from'](_0x11f4ce)),internalBuffer=Buffer['concat']([internalBuffer,_0x11f4ce]);let _0x543990=0x0;if(internalBuffer['length']<0x4)return null;const _0x307b16=internalBuffer['readUInt32BE'](_0x543990);if(_0x543990+=0x4,internalBuffer['length']<_0x543990+_0x307b16)return null;const _0x3bfd49=internalBuffer['slice'](_0x543990,_0x543990+_0x307b16),_0x32f23a=JSON['parse'](_0x3bfd49['toString']());if(_0x543990+=_0x307b16,internalBuffer['length']<_0x543990+0x4)return null;const _0x2b8b30=internalBuffer['readUInt32BE'](_0x543990);if(_0x543990+=0x4,internalBuffer['length']<_0x543990+_0x2b8b30)return null;const _0x11d62c=internalBuffer['slice'](_0x543990,_0x543990+_0x2b8b30);_0x543990+=_0x2b8b30,internalBuffer=internalBuffer['slice'](_0x543990);let _0x178f53=_0x11d62c;if('text'===_0x32f23a['type'])try{_0x178f53=JSON['parse'](_0x11d62c['toString']('utf8'));}catch{_0x178f53=_0x11d62c;}return{'metadata':_0x32f23a,'data':_0x178f53};}catch(_0x48c432){return console['error']('decodePacket\x20error:',_0x48c432),null;}}