@dapex-tech/elite-online-services 0.0.1 → 0.0.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/createClient.ts +2 -1
- package/models/CreateDriverDto.ts +3 -3
- package/models/UpdateDriverDto.ts +3 -3
- package/package.json +1 -1
- package/socketService.ts +119 -99
package/createClient.ts
CHANGED
|
@@ -4,8 +4,9 @@ import * as services from './services';
|
|
|
4
4
|
/**
|
|
5
5
|
* Crea un cliente SDK con la URL base configurada
|
|
6
6
|
*/
|
|
7
|
-
export function createClient(baseUrl?: string) {
|
|
7
|
+
export function createClient(baseUrl?: string, token?: string) {
|
|
8
8
|
OpenAPI.BASE = baseUrl || process.env.API_URL || 'http://localhost:3000';
|
|
9
|
+
OpenAPI.TOKEN = token || process.env.API_TOKEN || '';
|
|
9
10
|
return {
|
|
10
11
|
...services, // todos los servicios agrupados
|
|
11
12
|
};
|
|
@@ -12,7 +12,7 @@ export type CreateDriverDto = {
|
|
|
12
12
|
*/
|
|
13
13
|
last_name: string;
|
|
14
14
|
/**
|
|
15
|
-
* Driver Phone Number (10
|
|
15
|
+
* Driver Phone Number (10 digits)
|
|
16
16
|
*/
|
|
17
17
|
phone: string;
|
|
18
18
|
/**
|
|
@@ -20,7 +20,7 @@ export type CreateDriverDto = {
|
|
|
20
20
|
*/
|
|
21
21
|
email: string;
|
|
22
22
|
/**
|
|
23
|
-
* Driver Password (6-20
|
|
23
|
+
* Driver Password (6-20 characters)
|
|
24
24
|
*/
|
|
25
25
|
password: string;
|
|
26
26
|
/**
|
|
@@ -32,7 +32,7 @@ export type CreateDriverDto = {
|
|
|
32
32
|
*/
|
|
33
33
|
type: string;
|
|
34
34
|
/**
|
|
35
|
-
* Driver State (
|
|
35
|
+
* Driver State (active/inactive)
|
|
36
36
|
*/
|
|
37
37
|
state?: boolean;
|
|
38
38
|
/**
|
|
@@ -12,7 +12,7 @@ export type UpdateDriverDto = {
|
|
|
12
12
|
*/
|
|
13
13
|
last_name?: string;
|
|
14
14
|
/**
|
|
15
|
-
* Driver Phone Number (10
|
|
15
|
+
* Driver Phone Number (10 digits)
|
|
16
16
|
*/
|
|
17
17
|
phone?: string;
|
|
18
18
|
/**
|
|
@@ -20,7 +20,7 @@ export type UpdateDriverDto = {
|
|
|
20
20
|
*/
|
|
21
21
|
email?: string;
|
|
22
22
|
/**
|
|
23
|
-
* Driver Password (6-20
|
|
23
|
+
* Driver Password (6-20 characters)
|
|
24
24
|
*/
|
|
25
25
|
password?: string;
|
|
26
26
|
/**
|
|
@@ -32,7 +32,7 @@ export type UpdateDriverDto = {
|
|
|
32
32
|
*/
|
|
33
33
|
type?: string;
|
|
34
34
|
/**
|
|
35
|
-
* Driver State (
|
|
35
|
+
* Driver State (active/inactive)
|
|
36
36
|
*/
|
|
37
37
|
state?: boolean;
|
|
38
38
|
/**
|
package/package.json
CHANGED
package/socketService.ts
CHANGED
|
@@ -2,104 +2,124 @@ import { io, Socket } from 'socket.io-client';
|
|
|
2
2
|
import { DriverLocationMap, DriverLocationWithClientID } from './types';
|
|
3
3
|
|
|
4
4
|
export class SocketService {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
5
|
+
private socket: Socket;
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
constructor(baseUrl: string) {
|
|
9
|
+
this.socket = io(baseUrl, { transports: ['websocket'] });
|
|
10
|
+
}
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
constructor(baseUrl: string, token?: string) {
|
|
14
|
+
this.socket = io(baseUrl, {
|
|
15
|
+
transports: ['websocket'],
|
|
16
|
+
auth: token ? { token } : undefined, // ✅ send token if available
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
connect() {
|
|
21
|
+
this.socket.connect();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
disconnect() {
|
|
25
|
+
this.socket.disconnect();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
isConnected(): boolean {
|
|
29
|
+
return this.socket.connected;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isActive(): boolean {
|
|
33
|
+
return this.socket.active;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
on<T = any>(event: string, cb: (data: T) => void) {
|
|
37
|
+
this.socket.on(event, cb);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
off(event: string, cb?: (...args: any[]) => void) {
|
|
41
|
+
if (cb) {
|
|
42
|
+
this.socket.off(event, cb);
|
|
43
|
+
} else {
|
|
44
|
+
this.socket.removeAllListeners(event);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
emit<T = any>(event: string, data: T) {
|
|
49
|
+
this.socket.emit(event, data);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Custom methods
|
|
53
|
+
sendMessage(message: string) {
|
|
54
|
+
this.emit('message', { text: message });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onMessageReceived(cb: (data: { text: string }) => void) {
|
|
58
|
+
this.on('messageReceived', cb);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
offMessageReceived(cb: (data: { text: string }) => void) {
|
|
62
|
+
this.off('messageReceived', cb);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
updateLocation(data: DriverLocationWithClientID) {
|
|
66
|
+
this.emit('updateLocation', { ...data });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onLocationUpdated(cb: (data: DriverLocationMap) => void) {
|
|
70
|
+
this.on('locationUpdated', cb);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
offLocationUpdated(cb: (data: DriverLocationMap) => void) {
|
|
74
|
+
this.off('locationUpdated', cb);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onAllLocations(cb: (data: DriverLocationMap) => void) {
|
|
78
|
+
this.on('allLocations', cb);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
offAllLocations(cb: (data: DriverLocationMap) => void) {
|
|
82
|
+
this.off('allLocations', cb);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
sendHeartbeat(clientID: string) {
|
|
86
|
+
this.emit('heartbeat', { clientID });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onHeartbeatReceived(cb: (data: { clientID: string; timestamp: number }) => void) {
|
|
90
|
+
this.on('heartbeatReceived', cb);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
offHeartbeatReceived(cb: (data: { clientID: string; timestamp: number }) => void) {
|
|
94
|
+
this.off('heartbeatReceived', cb);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
onAllHeartbeats(cb: (data: { [clientID: string]: number }) => void) {
|
|
98
|
+
this.on('allHeartbeats', cb);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
offAllHeartbeats(cb: (data: { [clientID: string]: number }) => void) {
|
|
102
|
+
this.off('allHeartbeats', cb);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
updateServiceOrderStatus(orderID: string, status: number) {
|
|
106
|
+
this.emit('serviceOrderStatusUpdate', { orderID, status });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
onServiceOrderStatusUpdated(callback: (data: { orderID: string, status: number }) => void) {
|
|
110
|
+
this.on('serviceOrderStatusUpdated', callback);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
offServiceOrderStatusUpdated(callback: (data: { orderID: string, status: number }) => void) {
|
|
114
|
+
this.off('serviceOrderStatusUpdated', callback);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
onAllServiceOrderStatuses(callback: (statuses: { [orderID: string]: number }) => void) {
|
|
118
|
+
this.on('allServiceOrderStatuses', callback);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
offAllServiceOrderStatuses(callback: (statuses: { [orderID: string]: number }) => void) {
|
|
122
|
+
this.off('allServiceOrderStatuses', callback);
|
|
123
|
+
}
|
|
104
124
|
|
|
105
125
|
}
|