@hlmr/sdk-js 1.0.22 → 1.0.24

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 (45) hide show
  1. package/dist/cjs/client/HlmrClient.d.ts +6 -1
  2. package/dist/cjs/client/HlmrClient.d.ts.map +1 -1
  3. package/dist/cjs/client/HlmrClient.js +2 -0
  4. package/dist/cjs/client/HlmrClient.js.map +1 -1
  5. package/dist/cjs/index.d.ts +2 -0
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js +3 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/modules/events.d.ts +46 -0
  10. package/dist/cjs/modules/events.d.ts.map +1 -0
  11. package/dist/cjs/modules/events.js +361 -0
  12. package/dist/cjs/modules/events.js.map +1 -0
  13. package/dist/cjs/types/events.d.ts +82 -0
  14. package/dist/cjs/types/events.d.ts.map +1 -0
  15. package/dist/cjs/types/events.js +3 -0
  16. package/dist/cjs/types/events.js.map +1 -0
  17. package/dist/esm/client/HlmrClient.d.ts +6 -1
  18. package/dist/esm/client/HlmrClient.d.ts.map +1 -1
  19. package/dist/esm/client/HlmrClient.js +2 -0
  20. package/dist/esm/client/HlmrClient.js.map +1 -1
  21. package/dist/esm/index.d.ts +2 -0
  22. package/dist/esm/index.d.ts.map +1 -1
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/modules/events.d.ts +46 -0
  26. package/dist/esm/modules/events.d.ts.map +1 -0
  27. package/dist/esm/modules/events.js +357 -0
  28. package/dist/esm/modules/events.js.map +1 -0
  29. package/dist/esm/types/events.d.ts +82 -0
  30. package/dist/esm/types/events.d.ts.map +1 -0
  31. package/dist/esm/types/events.js +2 -0
  32. package/dist/esm/types/events.js.map +1 -0
  33. package/dist/types/client/HlmrClient.d.ts +6 -1
  34. package/dist/types/client/HlmrClient.d.ts.map +1 -1
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/types/modules/events.d.ts +46 -0
  38. package/dist/types/modules/events.d.ts.map +1 -0
  39. package/dist/types/types/events.d.ts +82 -0
  40. package/dist/types/types/events.d.ts.map +1 -0
  41. package/dist/umd/hlmr-sdk.js +359 -0
  42. package/dist/umd/hlmr-sdk.js.map +1 -1
  43. package/dist/umd/hlmr-sdk.min.js +1 -1
  44. package/dist/umd/hlmr-sdk.min.js.map +1 -1
  45. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"HlmrClient.d.ts","sourceRoot":"","sources":["../../../src/client/HlmrClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAa;IAG/B,SAAgB,IAAI,EAAE,UAAU,CAAC;IAGjC,SAAgB,IAAI,EAAE,UAAU,CAAC;IAGjC,SAAgB,MAAM,EAAE,YAAY,CAAC;IAGrC,SAAgB,IAAI,EAAE,UAAU,CAAC;gBAErB,OAAO,EAAE,iBAAiB;IActC,OAAO,CAAC,WAAW;IAoCnB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAUnC,gBAAgB,IAAI,IAAI;IAOxB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAUlC,cAAc,IAAI,IAAI;IAOtB,SAAS,IAAI,OAAO,CAAC,gBAAgB,CAAC;IActC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAA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G,EAAE,MAAM,EACX,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAgB,EAC3D,IAAI,CAAC,EAAE,GAAG,EACV,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE;CAInE"}
@@ -5,6 +5,8 @@ export type { UserProfile } from './types/user';
5
5
  export type { SystemPingResponse, SystemPingOptions, SystemVersionResponse } from './types/system';
6
6
  export type { LogSessionOptions, LogSessionResponse } from './modules/apps';
7
7
  export { AppsModule } from './modules/apps';
8
+ export { EventsModule } from './modules/events';
9
+ export type { Subscription, SubscriptionOptions, SubscriptionFilters, EventNotification, SystemNotification, ConnectedMessage, SubscriptionConfirmedMessage, UnsubscribedMessage, ErrorMessage, WebSocketMessage, EventsModuleConfig, EventsModuleEvents } from './types/events';
8
10
  export { HlmrApiError } from './types/errors';
9
11
  export type { JSendResponse, JSendSuccessResponse, JSendFailResponse, JSendErrorResponse } from './types/errors';
10
12
  export type { HttpClient } from './utils/http';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,WAAW,EACZ,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG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AgB,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,UAAU,EACX,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG3F,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnF,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,QAAQ,gBAAgB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { HttpClient } from '../utils/http';
2
+ import type { Subscription, SubscriptionOptions, ConnectedMessage, EventsModuleConfig, EventsModuleEvents } from '../types/events';
3
+ type EventCallback<K extends keyof EventsModuleEvents> = EventsModuleEvents[K];
4
+ export declare class EventsModule {
5
+ private http;
6
+ private config;
7
+ private ws;
8
+ private pingIntervalId;
9
+ private reconnectAttempts;
10
+ private reconnectTimeoutId;
11
+ private isConnecting;
12
+ private isManualDisconnect;
13
+ private subscriptions;
14
+ private pendingSubscriptions;
15
+ private listeners;
16
+ private userId;
17
+ constructor(http: HttpClient, config?: EventsModuleConfig);
18
+ connect(): Promise<ConnectedMessage>;
19
+ private _connect;
20
+ disconnect(): void;
21
+ subscribe(domain: string, resource: string, options?: SubscriptionOptions): Promise<Subscription>;
22
+ unsubscribe(subscriptionId: string): Promise<void>;
23
+ on<K extends keyof EventsModuleEvents>(event: K, callback: EventCallback<K>): void;
24
+ off<K extends keyof EventsModuleEvents>(event: K, callback: EventCallback<K>): void;
25
+ get isConnected(): boolean;
26
+ get currentUserId(): string | null;
27
+ getSubscriptions(): Map<string, {
28
+ domain: string;
29
+ resource: string;
30
+ options?: SubscriptionOptions;
31
+ }>;
32
+ ping(): void;
33
+ updateConfig(config: Partial<EventsModuleConfig>): void;
34
+ private _buildWebSocketUrl;
35
+ private _handleMessage;
36
+ private _handleSubscriptionConfirmed;
37
+ private _emit;
38
+ private _startPingInterval;
39
+ private _stopPingInterval;
40
+ private _scheduleReconnect;
41
+ private _resubscribeAll;
42
+ private _cleanup;
43
+ private _generateId;
44
+ }
45
+ export {};
46
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/modules/events.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EAInB,gBAAgB,EAKhB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAYzB,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,kBAAkB,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAK/E,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAA+B;IAC7C,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,cAAc,CAA+C;IACrE,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,kBAAkB,CAA8C;IACxE,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,kBAAkB,CAAS;IAGnC,OAAO,CAAC,aAAa,CAA+F;IACpH,OAAO,CAAC,oBAAoB,CAMb;IAGf,OAAO,CAAC,SAAS,CAA2D;IAG5E,OAAO,CAAC,MAAM,CAAuB;gBAEzB,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAUnD,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;YAgB5B,QAAQ;IAwEtB,UAAU,IAAI,IAAI;IAsBZ,SAAS,CACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,YAAY,CAAC;IA2DlB,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BxD,EAAE,CAAC,CAAC,SAAS,MAAM,kBAAkB,EACnC,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,GACzB,IAAI;IAaP,GAAG,CAAC,CAAC,SAAS,MAAM,kBAAkB,EACpC,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,GACzB,IAAI;IAUP,IAAI,WAAW,IAAI,OAAO,CAEzB;IAKD,IAAI,aAAa,IAAI,MAAM,GAAG,IAAI,CAEjC;IAKD,gBAAgB,IAAI,GAAG,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,mBAAmB,CAAA;KAAE,CAAC;IAOpG,IAAI,IAAI,IAAI;IASZ,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,IAAI;IAYvD,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,cAAc;IAsDtB,OAAO,CAAC,4BAA4B;IAmBpC,OAAO,CAAC,KAAK;IAgBb,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,kBAAkB;YAmCZ,eAAe;IAsB7B,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,WAAW;CAOpB"}
@@ -0,0 +1,82 @@
1
+ export interface SubscriptionFilters {
2
+ chat_ids?: string[];
3
+ trip_ids?: string[];
4
+ user_ids?: string[];
5
+ events?: string[];
6
+ }
7
+ export interface SubscriptionOptions {
8
+ filters?: SubscriptionFilters;
9
+ include_data?: boolean;
10
+ }
11
+ export interface Subscription {
12
+ id: string;
13
+ domain: string;
14
+ resource: string;
15
+ filters: SubscriptionFilters;
16
+ }
17
+ export interface EventNotification {
18
+ type: 'notification';
19
+ subscription_id: string;
20
+ domain: string;
21
+ resource: string;
22
+ event: string;
23
+ resource_id: string;
24
+ chat_id?: string;
25
+ trip_id?: string;
26
+ user_id?: string;
27
+ timestamp: string;
28
+ [key: string]: any;
29
+ }
30
+ export interface SystemNotification {
31
+ type: 'system_notification';
32
+ event: string;
33
+ domain: 'system';
34
+ resource: string;
35
+ action?: string;
36
+ message?: string;
37
+ [key: string]: any;
38
+ }
39
+ export interface ConnectedMessage {
40
+ type: 'connected';
41
+ user_id: string;
42
+ message: string;
43
+ system_subscriptions: string[];
44
+ }
45
+ export interface SubscriptionConfirmedMessage {
46
+ type: 'subscription_confirmed';
47
+ subscription_id: string;
48
+ domain: string;
49
+ resource: string;
50
+ filters: SubscriptionFilters;
51
+ }
52
+ export interface UnsubscribedMessage {
53
+ type: 'unsubscribed';
54
+ subscription_id: string;
55
+ }
56
+ export interface PongMessage {
57
+ type: 'pong';
58
+ }
59
+ export interface ErrorMessage {
60
+ type: 'error';
61
+ message: string;
62
+ code: number;
63
+ }
64
+ export type WebSocketMessage = ConnectedMessage | SubscriptionConfirmedMessage | UnsubscribedMessage | EventNotification | SystemNotification | PongMessage | ErrorMessage;
65
+ export interface EventsModuleEvents {
66
+ connect: (message: ConnectedMessage) => void;
67
+ disconnect: (reason?: string) => void;
68
+ notification: (notification: EventNotification) => void;
69
+ system_notification: (notification: SystemNotification) => void;
70
+ error: (error: ErrorMessage | Error) => void;
71
+ subscription_confirmed: (subscription: SubscriptionConfirmedMessage) => void;
72
+ reconnecting: (attempt: number) => void;
73
+ }
74
+ export interface EventsModuleConfig {
75
+ pingInterval?: number;
76
+ autoReconnect?: boolean;
77
+ maxReconnectAttempts?: number;
78
+ reconnectDelay?: number;
79
+ maxReconnectDelay?: number;
80
+ debug?: boolean;
81
+ }
82
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.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C;AAKD,MAAM,WAAW,kBAAkB;IAKjC,YAAY,CAAC,EAAE,MAAM,CAAC;IAItB,aAAa,CAAC,EAAE,OAAO,CAAC;IAIxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAK9B,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAI3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -373,6 +373,363 @@
373
373
  }
374
374
  }
375
375
 
376
+ const DEFAULT_CONFIG = {
377
+ pingInterval: 30000,
378
+ autoReconnect: true,
379
+ maxReconnectAttempts: 5,
380
+ reconnectDelay: 1000,
381
+ maxReconnectDelay: 30000,
382
+ debug: false
383
+ };
384
+ class EventsModule {
385
+ constructor(http, config) {
386
+ this.ws = null;
387
+ this.pingIntervalId = null;
388
+ this.reconnectAttempts = 0;
389
+ this.reconnectTimeoutId = null;
390
+ this.isConnecting = false;
391
+ this.isManualDisconnect = false;
392
+ this.subscriptions = new Map();
393
+ this.pendingSubscriptions = new Map();
394
+ this.listeners = new Map();
395
+ this.userId = null;
396
+ this.http = http;
397
+ this.config = { ...DEFAULT_CONFIG, ...config };
398
+ }
399
+ async connect() {
400
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
401
+ throw new Error('Already connected');
402
+ }
403
+ if (this.isConnecting) {
404
+ throw new Error('Connection in progress');
405
+ }
406
+ this.isConnecting = true;
407
+ this.isManualDisconnect = false;
408
+ this.reconnectAttempts = 0;
409
+ return this._connect();
410
+ }
411
+ async _connect() {
412
+ return new Promise((resolve, reject) => {
413
+ try {
414
+ const wsUrl = this._buildWebSocketUrl();
415
+ if (this.config.debug) {
416
+ console.log('[EventsModule] Connecting to:', wsUrl);
417
+ }
418
+ this.ws = new WebSocket(wsUrl);
419
+ const connectionTimeout = setTimeout(() => {
420
+ if (this.ws && this.ws.readyState !== WebSocket.OPEN) {
421
+ this.ws.close();
422
+ this.isConnecting = false;
423
+ reject(new Error('Connection timeout'));
424
+ }
425
+ }, 10000);
426
+ this.ws.onopen = () => {
427
+ if (this.config.debug) {
428
+ console.log('[EventsModule] WebSocket connected');
429
+ }
430
+ clearTimeout(connectionTimeout);
431
+ this._startPingInterval();
432
+ };
433
+ this.ws.onmessage = (event) => {
434
+ try {
435
+ const message = JSON.parse(event.data);
436
+ this._handleMessage(message, resolve);
437
+ }
438
+ catch (err) {
439
+ if (this.config.debug) {
440
+ console.error('[EventsModule] Failed to parse message:', err);
441
+ }
442
+ }
443
+ };
444
+ this.ws.onerror = (error) => {
445
+ if (this.config.debug) {
446
+ console.error('[EventsModule] WebSocket error:', error);
447
+ }
448
+ clearTimeout(connectionTimeout);
449
+ this.isConnecting = false;
450
+ this._emit('error', new Error('WebSocket error'));
451
+ };
452
+ this.ws.onclose = (event) => {
453
+ if (this.config.debug) {
454
+ console.log('[EventsModule] WebSocket closed:', event.code, event.reason);
455
+ }
456
+ clearTimeout(connectionTimeout);
457
+ this._stopPingInterval();
458
+ this.isConnecting = false;
459
+ this._emit('disconnect', event.reason || 'Connection closed');
460
+ if (!this.isManualDisconnect && this.config.autoReconnect) {
461
+ this._scheduleReconnect();
462
+ }
463
+ };
464
+ }
465
+ catch (err) {
466
+ this.isConnecting = false;
467
+ reject(err);
468
+ }
469
+ });
470
+ }
471
+ disconnect() {
472
+ this.isManualDisconnect = true;
473
+ this._cleanup();
474
+ if (this.ws) {
475
+ this.ws.close(1000, 'Client disconnect');
476
+ this.ws = null;
477
+ }
478
+ if (this.config.debug) {
479
+ console.log('[EventsModule] Disconnected');
480
+ }
481
+ }
482
+ async subscribe(domain, resource, options) {
483
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
484
+ throw new Error('Not connected');
485
+ }
486
+ const subscriptionId = this._generateId();
487
+ return new Promise((resolve, reject) => {
488
+ const subscriptionData = options
489
+ ? { domain, resource, options }
490
+ : { domain, resource };
491
+ const pendingData = {
492
+ resolve: (sub) => {
493
+ this.subscriptions.set(sub.id, subscriptionData);
494
+ resolve(sub);
495
+ },
496
+ reject,
497
+ ...subscriptionData
498
+ };
499
+ this.pendingSubscriptions.set(subscriptionId, pendingData);
500
+ const message = {
501
+ type: 'subscribe',
502
+ subscription_id: subscriptionId,
503
+ domain,
504
+ resource,
505
+ options: {
506
+ filters: (options === null || options === void 0 ? void 0 : options.filters) || {},
507
+ include_data: (options === null || options === void 0 ? void 0 : options.include_data) || false
508
+ }
509
+ };
510
+ this.ws.send(JSON.stringify(message));
511
+ if (this.config.debug) {
512
+ console.log('[EventsModule] Subscribing:', message);
513
+ }
514
+ setTimeout(() => {
515
+ if (this.pendingSubscriptions.has(subscriptionId)) {
516
+ this.pendingSubscriptions.delete(subscriptionId);
517
+ reject(new Error('Subscription timeout'));
518
+ }
519
+ }, 10000);
520
+ });
521
+ }
522
+ async unsubscribe(subscriptionId) {
523
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
524
+ throw new Error('Not connected');
525
+ }
526
+ return new Promise((resolve, reject) => {
527
+ const message = {
528
+ type: 'unsubscribe',
529
+ subscription_id: subscriptionId
530
+ };
531
+ this.ws.send(JSON.stringify(message));
532
+ this.subscriptions.delete(subscriptionId);
533
+ if (this.config.debug) {
534
+ console.log('[EventsModule] Unsubscribing:', subscriptionId);
535
+ }
536
+ resolve();
537
+ });
538
+ }
539
+ on(event, callback) {
540
+ if (!this.listeners.has(event)) {
541
+ this.listeners.set(event, new Set());
542
+ }
543
+ this.listeners.get(event).add(callback);
544
+ }
545
+ off(event, callback) {
546
+ const listeners = this.listeners.get(event);
547
+ if (listeners) {
548
+ listeners.delete(callback);
549
+ }
550
+ }
551
+ get isConnected() {
552
+ return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
553
+ }
554
+ get currentUserId() {
555
+ return this.userId;
556
+ }
557
+ getSubscriptions() {
558
+ return new Map(this.subscriptions);
559
+ }
560
+ ping() {
561
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
562
+ this.ws.send(JSON.stringify({ type: 'ping' }));
563
+ }
564
+ }
565
+ updateConfig(config) {
566
+ this.config = { ...this.config, ...config };
567
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
568
+ this._stopPingInterval();
569
+ this._startPingInterval();
570
+ }
571
+ }
572
+ _buildWebSocketUrl() {
573
+ const httpConfig = this.http.config;
574
+ const baseUrl = httpConfig.baseUrl;
575
+ const bearerToken = httpConfig.bearerToken;
576
+ const wsUrl = baseUrl
577
+ .replace('https://', 'wss://')
578
+ .replace('http://', 'ws://');
579
+ const url = new URL(`${wsUrl}/v1/events/ws`);
580
+ if (bearerToken) {
581
+ url.searchParams.set('token', bearerToken);
582
+ }
583
+ return url.toString();
584
+ }
585
+ _handleMessage(message, connectResolve) {
586
+ if (this.config.debug) {
587
+ console.log('[EventsModule] Message received:', message);
588
+ }
589
+ switch (message.type) {
590
+ case 'connected':
591
+ this.isConnecting = false;
592
+ this.userId = message.user_id;
593
+ this._emit('connect', message);
594
+ if (connectResolve) {
595
+ connectResolve(message);
596
+ }
597
+ if (this.reconnectAttempts > 0) {
598
+ this._resubscribeAll();
599
+ }
600
+ this.reconnectAttempts = 0;
601
+ break;
602
+ case 'subscription_confirmed':
603
+ this._handleSubscriptionConfirmed(message);
604
+ break;
605
+ case 'unsubscribed':
606
+ this.subscriptions.delete(message.subscription_id);
607
+ break;
608
+ case 'notification':
609
+ this._emit('notification', message);
610
+ break;
611
+ case 'system_notification':
612
+ this._emit('system_notification', message);
613
+ break;
614
+ case 'pong':
615
+ break;
616
+ case 'error':
617
+ this._emit('error', message);
618
+ break;
619
+ default:
620
+ if (this.config.debug) {
621
+ console.warn('[EventsModule] Unknown message type:', message.type);
622
+ }
623
+ }
624
+ }
625
+ _handleSubscriptionConfirmed(message) {
626
+ const pending = this.pendingSubscriptions.get(message.subscription_id);
627
+ if (pending) {
628
+ this.pendingSubscriptions.delete(message.subscription_id);
629
+ const subscription = {
630
+ id: message.subscription_id,
631
+ domain: message.domain,
632
+ resource: message.resource,
633
+ filters: message.filters
634
+ };
635
+ pending.resolve(subscription);
636
+ }
637
+ this._emit('subscription_confirmed', message);
638
+ }
639
+ _emit(event, ...args) {
640
+ const listeners = this.listeners.get(event);
641
+ if (listeners) {
642
+ listeners.forEach((callback) => {
643
+ try {
644
+ callback(...args);
645
+ }
646
+ catch (err) {
647
+ console.error(`[EventsModule] Error in ${event} listener:`, err);
648
+ }
649
+ });
650
+ }
651
+ }
652
+ _startPingInterval() {
653
+ if (this.config.pingInterval > 0) {
654
+ this.pingIntervalId = setInterval(() => {
655
+ this.ping();
656
+ }, this.config.pingInterval);
657
+ if (this.config.debug) {
658
+ console.log('[EventsModule] Ping interval started:', this.config.pingInterval);
659
+ }
660
+ }
661
+ }
662
+ _stopPingInterval() {
663
+ if (this.pingIntervalId) {
664
+ clearInterval(this.pingIntervalId);
665
+ this.pingIntervalId = null;
666
+ }
667
+ }
668
+ _scheduleReconnect() {
669
+ if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
670
+ if (this.config.debug) {
671
+ console.log('[EventsModule] Max reconnect attempts reached');
672
+ }
673
+ this._emit('error', new Error('Max reconnect attempts reached'));
674
+ return;
675
+ }
676
+ this.reconnectAttempts++;
677
+ const delay = Math.min(this.config.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1), this.config.maxReconnectDelay);
678
+ if (this.config.debug) {
679
+ console.log(`[EventsModule] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts})`);
680
+ }
681
+ this._emit('reconnecting', this.reconnectAttempts);
682
+ this.reconnectTimeoutId = setTimeout(async () => {
683
+ try {
684
+ await this._connect();
685
+ }
686
+ catch (err) {
687
+ if (this.config.debug) {
688
+ console.error('[EventsModule] Reconnect failed:', err);
689
+ }
690
+ }
691
+ }, delay);
692
+ }
693
+ async _resubscribeAll() {
694
+ if (this.config.debug) {
695
+ console.log('[EventsModule] Re-subscribing to', this.subscriptions.size, 'subscriptions');
696
+ }
697
+ const subscriptionsToRestore = new Map(this.subscriptions);
698
+ this.subscriptions.clear();
699
+ for (const [id, sub] of subscriptionsToRestore) {
700
+ try {
701
+ await this.subscribe(sub.domain, sub.resource, sub.options);
702
+ if (this.config.debug) {
703
+ console.log('[EventsModule] Re-subscribed:', sub.domain, sub.resource);
704
+ }
705
+ }
706
+ catch (err) {
707
+ if (this.config.debug) {
708
+ console.error('[EventsModule] Failed to re-subscribe:', err);
709
+ }
710
+ }
711
+ }
712
+ }
713
+ _cleanup() {
714
+ this._stopPingInterval();
715
+ if (this.reconnectTimeoutId) {
716
+ clearTimeout(this.reconnectTimeoutId);
717
+ this.reconnectTimeoutId = null;
718
+ }
719
+ for (const pending of this.pendingSubscriptions.values()) {
720
+ pending.reject(new Error('Connection closed'));
721
+ }
722
+ this.pendingSubscriptions.clear();
723
+ }
724
+ _generateId() {
725
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
726
+ const r = (Math.random() * 16) | 0;
727
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
728
+ return v.toString(16);
729
+ });
730
+ }
731
+ }
732
+
376
733
  class HlmrClient {
377
734
  constructor(options) {
378
735
  const config = this.buildConfig(options);
@@ -381,6 +738,7 @@
381
738
  this.user = new UserModule(this.httpClient);
382
739
  this.system = new SystemModule(this.httpClient);
383
740
  this.apps = new AppsModule(this.httpClient);
741
+ this.events = new EventsModule(this.httpClient, options.eventsConfig);
384
742
  }
385
743
  buildConfig(options) {
386
744
  var _a, _b, _c;
@@ -528,6 +886,7 @@
528
886
  const SDK_NAME = 'hlmr-sdk-js';
529
887
 
530
888
  exports.AppsModule = AppsModule;
889
+ exports.EventsModule = EventsModule;
531
890
  exports.HlmrApiError = HlmrApiError;
532
891
  exports.HlmrClient = HlmrClient;
533
892
  exports.SDK_NAME = SDK_NAME;