@dapex-tech/elite-online-services 0.0.15 → 0.0.16

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.d.ts CHANGED
@@ -17,5 +17,6 @@ export declare function createClient(baseUrl?: string): {
17
17
  DriversService: typeof services.DriversService;
18
18
  HealthService: typeof services.HealthService;
19
19
  MainService: typeof services.MainService;
20
+ ManualCustomerService: typeof services.ManualCustomerService;
20
21
  VoucherService: typeof services.VoucherService;
21
22
  };
@@ -0,0 +1,30 @@
1
+ export type ManualCustomerCreateDto = {
2
+ /**
3
+ * First name
4
+ */
5
+ firstName: string;
6
+ /**
7
+ * Last name
8
+ */
9
+ lastName: string;
10
+ /**
11
+ * Phone country code
12
+ */
13
+ phoneCountryCode: string;
14
+ /**
15
+ * Phone number
16
+ */
17
+ phone: string;
18
+ /**
19
+ * Email
20
+ */
21
+ email: string;
22
+ /**
23
+ * Address
24
+ */
25
+ address: string;
26
+ /**
27
+ * Admin ID
28
+ */
29
+ adminId?: number;
30
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,42 @@
1
+ export type ManualCustomerDto = {
2
+ /**
3
+ * Manual customer ID
4
+ */
5
+ id: number;
6
+ /**
7
+ * First name
8
+ */
9
+ firstName: string;
10
+ /**
11
+ * Last name
12
+ */
13
+ lastName: string;
14
+ /**
15
+ * Phone country code
16
+ */
17
+ phoneCountryCode: string;
18
+ /**
19
+ * Phone number
20
+ */
21
+ phone: string;
22
+ /**
23
+ * Email
24
+ */
25
+ email: string;
26
+ /**
27
+ * Address
28
+ */
29
+ address: string;
30
+ /**
31
+ * Admin ID
32
+ */
33
+ adminId: number;
34
+ /**
35
+ * Created at timestamp
36
+ */
37
+ createdAt: string;
38
+ /**
39
+ * Updated at timestamp
40
+ */
41
+ updatedAt?: Record<string, any>;
42
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,30 @@
1
+ export type ManualCustomerUpdateDto = {
2
+ /**
3
+ * First name
4
+ */
5
+ firstName?: string;
6
+ /**
7
+ * Last name
8
+ */
9
+ lastName?: string;
10
+ /**
11
+ * Phone country code
12
+ */
13
+ phoneCountryCode?: string;
14
+ /**
15
+ * Phone number
16
+ */
17
+ phone?: string;
18
+ /**
19
+ * Email
20
+ */
21
+ email?: string;
22
+ /**
23
+ * Address
24
+ */
25
+ address?: string;
26
+ /**
27
+ * Admin ID
28
+ */
29
+ adminId?: number;
30
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,10 @@
1
1
  import type { AdminDto } from './AdminDto';
2
2
  import type { CustomerDto } from './CustomerDto';
3
3
  import type { DriverDto } from './DriverDto';
4
+ import type { ManualCustomerDto } from './ManualCustomerDto';
4
5
  import type { PaymentDto } from './PaymentDto';
5
6
  import type { TripLocationPointDto } from './TripLocationPointDto';
7
+ import type { VoucherDto } from './VoucherDto';
6
8
  export type TripDto = {
7
9
  /**
8
10
  * Trip ID
@@ -11,6 +13,8 @@ export type TripDto = {
11
13
  driverId?: Record<string, any> | null;
12
14
  customerId?: Record<string, any> | null;
13
15
  adminId?: Record<string, any> | null;
16
+ voucherId?: Record<string, any> | null;
17
+ manualCustomerId?: Record<string, any> | null;
14
18
  status?: TripDto.status;
15
19
  tripSource?: Record<string, any>;
16
20
  driverAssignmentMode?: Record<string, any>;
@@ -141,6 +145,14 @@ export type TripDto = {
141
145
  * Payments associated with the trip
142
146
  */
143
147
  payments?: Array<PaymentDto> | null;
148
+ /**
149
+ * Voucher information
150
+ */
151
+ voucher?: VoucherDto | null;
152
+ /**
153
+ * Manual customer information
154
+ */
155
+ manualCustomer?: ManualCustomerDto | null;
144
156
  };
145
157
  export declare namespace TripDto {
146
158
  enum status {
@@ -1,6 +1,8 @@
1
1
  export type TripUpdateDto = {
2
2
  driverId?: Record<string, any> | null;
3
3
  customerId?: Record<string, any> | null;
4
+ voucherId?: Record<string, any> | null;
5
+ manualCustomerId?: Record<string, any> | null;
4
6
  origin?: Record<string, any> | null;
5
7
  /**
6
8
  * Origin address
package/models/index.d.ts CHANGED
@@ -21,6 +21,9 @@ export * from './DriverTripActions';
21
21
  export * from './DriverUpdateDto';
22
22
  export * from './GenerateResetCodeDto';
23
23
  export * from './GenerateVerificationCodeDto';
24
+ export * from './ManualCustomerCreateDto';
25
+ export * from './ManualCustomerDto';
26
+ export * from './ManualCustomerUpdateDto';
24
27
  export * from './MessageResponseDto';
25
28
  export * from './OrderDto';
26
29
  export * from './PaymentDto';
package/models/index.js CHANGED
@@ -37,6 +37,9 @@ __exportStar(require("./DriverTripActions"), exports);
37
37
  __exportStar(require("./DriverUpdateDto"), exports);
38
38
  __exportStar(require("./GenerateResetCodeDto"), exports);
39
39
  __exportStar(require("./GenerateVerificationCodeDto"), exports);
40
+ __exportStar(require("./ManualCustomerCreateDto"), exports);
41
+ __exportStar(require("./ManualCustomerDto"), exports);
42
+ __exportStar(require("./ManualCustomerUpdateDto"), exports);
40
43
  __exportStar(require("./MessageResponseDto"), exports);
41
44
  __exportStar(require("./OrderDto"), exports);
42
45
  __exportStar(require("./PaymentDto"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dapex-tech/elite-online-services",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "private": false,
@@ -0,0 +1,45 @@
1
+ import type { ManualCustomerCreateDto } from '../models/ManualCustomerCreateDto';
2
+ import type { ManualCustomerDto } from '../models/ManualCustomerDto';
3
+ import type { ManualCustomerUpdateDto } from '../models/ManualCustomerUpdateDto';
4
+ import type { MessageResponseDto } from '../models/MessageResponseDto';
5
+ import type { OrderDto } from '../models/OrderDto';
6
+ import type { CancelablePromise } from '../core/CancelablePromise';
7
+ export declare class ManualCustomerService {
8
+ /**
9
+ * Create a new manual customer
10
+ * @param requestBody
11
+ * @returns ManualCustomerDto Manual customer created successfully.
12
+ * @throws ApiError
13
+ */
14
+ static create(requestBody: ManualCustomerCreateDto): CancelablePromise<ManualCustomerDto>;
15
+ /**
16
+ * Get all manual customers
17
+ * @param q Text to search for in name, phone, email, or address
18
+ * @param order Sorting options
19
+ * @returns ManualCustomerDto List of manual customers
20
+ * @throws ApiError
21
+ */
22
+ static findAll(q?: string, order?: OrderDto): CancelablePromise<Array<ManualCustomerDto>>;
23
+ /**
24
+ * Get a single manual customer by ID
25
+ * @param id
26
+ * @returns ManualCustomerDto Manual customer found
27
+ * @throws ApiError
28
+ */
29
+ static findById(id: number): CancelablePromise<ManualCustomerDto>;
30
+ /**
31
+ * Update a manual customer by ID
32
+ * @param id
33
+ * @param requestBody
34
+ * @returns ManualCustomerDto Manual customer updated successfully.
35
+ * @throws ApiError
36
+ */
37
+ static update(id: number, requestBody: ManualCustomerUpdateDto): CancelablePromise<ManualCustomerDto>;
38
+ /**
39
+ * Delete a manual customer by ID
40
+ * @param id
41
+ * @returns MessageResponseDto Manual customer deleted successfully.
42
+ * @throws ApiError
43
+ */
44
+ static remove(id: number): CancelablePromise<MessageResponseDto>;
45
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ManualCustomerService = void 0;
4
+ const OpenAPI_1 = require("../core/OpenAPI");
5
+ const request_1 = require("../core/request");
6
+ class ManualCustomerService {
7
+ /**
8
+ * Create a new manual customer
9
+ * @param requestBody
10
+ * @returns ManualCustomerDto Manual customer created successfully.
11
+ * @throws ApiError
12
+ */
13
+ static create(requestBody) {
14
+ return (0, request_1.request)(OpenAPI_1.OpenAPI, {
15
+ method: 'POST',
16
+ url: '/admins/manual-customers',
17
+ body: requestBody,
18
+ mediaType: 'application/json',
19
+ });
20
+ }
21
+ /**
22
+ * Get all manual customers
23
+ * @param q Text to search for in name, phone, email, or address
24
+ * @param order Sorting options
25
+ * @returns ManualCustomerDto List of manual customers
26
+ * @throws ApiError
27
+ */
28
+ static findAll(q, order) {
29
+ return (0, request_1.request)(OpenAPI_1.OpenAPI, {
30
+ method: 'GET',
31
+ url: '/admins/manual-customers',
32
+ query: {
33
+ 'q': q,
34
+ 'order': order,
35
+ },
36
+ });
37
+ }
38
+ /**
39
+ * Get a single manual customer by ID
40
+ * @param id
41
+ * @returns ManualCustomerDto Manual customer found
42
+ * @throws ApiError
43
+ */
44
+ static findById(id) {
45
+ return (0, request_1.request)(OpenAPI_1.OpenAPI, {
46
+ method: 'GET',
47
+ url: '/admins/manual-customers/{id}',
48
+ path: {
49
+ 'id': id,
50
+ },
51
+ });
52
+ }
53
+ /**
54
+ * Update a manual customer by ID
55
+ * @param id
56
+ * @param requestBody
57
+ * @returns ManualCustomerDto Manual customer updated successfully.
58
+ * @throws ApiError
59
+ */
60
+ static update(id, requestBody) {
61
+ return (0, request_1.request)(OpenAPI_1.OpenAPI, {
62
+ method: 'PATCH',
63
+ url: '/admins/manual-customers/{id}',
64
+ path: {
65
+ 'id': id,
66
+ },
67
+ body: requestBody,
68
+ mediaType: 'application/json',
69
+ });
70
+ }
71
+ /**
72
+ * Delete a manual customer by ID
73
+ * @param id
74
+ * @returns MessageResponseDto Manual customer deleted successfully.
75
+ * @throws ApiError
76
+ */
77
+ static remove(id) {
78
+ return (0, request_1.request)(OpenAPI_1.OpenAPI, {
79
+ method: 'DELETE',
80
+ url: '/admins/manual-customers/{id}',
81
+ path: {
82
+ 'id': id,
83
+ },
84
+ });
85
+ }
86
+ }
87
+ exports.ManualCustomerService = ManualCustomerService;
@@ -12,4 +12,5 @@ export * from './DriverTripsService';
12
12
  export * from './DriversService';
13
13
  export * from './HealthService';
14
14
  export * from './MainService';
15
+ export * from './ManualCustomerService';
15
16
  export * from './VoucherService';
package/services/index.js CHANGED
@@ -28,4 +28,5 @@ __exportStar(require("./DriverTripsService"), exports);
28
28
  __exportStar(require("./DriversService"), exports);
29
29
  __exportStar(require("./HealthService"), exports);
30
30
  __exportStar(require("./MainService"), exports);
31
+ __exportStar(require("./ManualCustomerService"), exports);
31
32
  __exportStar(require("./VoucherService"), exports);
@@ -26,4 +26,7 @@ export declare class SocketService {
26
26
  offTripUpdate(cb?: (data: any) => void): void;
27
27
  emitDriverStatusUpdate(data: DriverStatus): void;
28
28
  emitTripActionUpdate(data: DriverExecuteTripAction): void;
29
+ emitGetInfo(): void;
30
+ onGetInfoResponse(cb: (data: any) => void): void;
31
+ offGetInfoResponse(cb?: (data: any) => void): void;
29
32
  }
package/socketService.js CHANGED
@@ -125,5 +125,19 @@ class SocketService {
125
125
  emitTripActionUpdate(data) {
126
126
  this.emit('tripActionUpdate', { ...data });
127
127
  }
128
+ emitGetInfo() {
129
+ this.emit('getInfo', {});
130
+ }
131
+ onGetInfoResponse(cb) {
132
+ this.socket.on('getInfo:Response', cb);
133
+ }
134
+ offGetInfoResponse(cb) {
135
+ if (cb) {
136
+ this.socket.off('getInfo:Response', cb);
137
+ }
138
+ else {
139
+ this.socket.removeAllListeners('getInfo:Response');
140
+ }
141
+ }
128
142
  }
129
143
  exports.SocketService = SocketService;
package/sockets.md ADDED
@@ -0,0 +1,260 @@
1
+ # Sockets + Usage in AppContext
2
+
3
+ ## Install
4
+
5
+ Install the package with yarn:
6
+
7
+ ```bash
8
+ yarn add @dapex-tech/elite-online-services
9
+ ```
10
+
11
+ ## Basic socket usage
12
+
13
+ Import `SocketService` from the package:
14
+
15
+ ```ts
16
+ import { SocketService } from '@dapex-tech/elite-online-services';
17
+ ```
18
+
19
+ Call `SocketService.getInstance()` once, then pass the auth token to `setToken(token)` so the socket connects with the current user context.
20
+
21
+ ```ts
22
+ const socketInstance = SocketService.getInstance();
23
+ socketInstance.setToken(token);
24
+ ```
25
+
26
+ ## Global App Context
27
+
28
+ `AppContext` centralizes realtime app state (like `activeTrip`) and exposes it via `AppProvider` so any screen can react to socket events without prop-drilling. The provider subscribes to socket events, updates state in one place, and cleans up listeners on token change or unmount.
29
+
30
+ ```tsx
31
+ import { SocketService, TripDto } from '@dapex-tech/elite-online-services';
32
+ import { createContext, useContext, useEffect, useState } from 'react';
33
+
34
+ // Centralized context for global app state
35
+ // and functionality that requires realtime updates
36
+ type AppContextType = {
37
+ activeTrip: TripDto | null;
38
+ setActiveTrip: (trip: TripDto | null) => void;
39
+ // ... other relevant app state
40
+ };
41
+
42
+ export const AppContext = createContext<AppContextType>({
43
+ activeTrip: null,
44
+ setActiveTrip: () => {},
45
+ });
46
+
47
+ type AppProviderProps = {
48
+ token: string;
49
+ children: React.ReactNode;
50
+ };
51
+
52
+ export const AppProvider = ({ token, children }: AppProviderProps) => {
53
+ const [activeTrip, setActiveTrip] = useState<TripDto | null>(null);
54
+
55
+ // socket event handlers
56
+ const handleTripUpdate = (data: TripDto | null) => {
57
+ console.log('[app.context] trip status update', data);
58
+ if (data != null) {
59
+ const payload = data;
60
+ setActiveTrip(payload);
61
+ }
62
+ };
63
+
64
+ const handleDriverStatusUpdate = (data: unknown) => {
65
+ console.log('[app.context] driver status update', data);
66
+ // action on app state
67
+ };
68
+
69
+ // useEffect to initialize sockets and event handlers
70
+ // and clean up on unmount or token change
71
+ useEffect(() => {
72
+ const socketInstance = SocketService.getInstance();
73
+ socketInstance.setToken(token);
74
+
75
+ socketInstance.onTripUpdate(handleTripUpdate);
76
+ socketInstance.onDriverStatusUpdate(handleDriverStatusUpdate);
77
+ return () => {
78
+ socketInstance.offTripUpdate(handleTripUpdate);
79
+ socketInstance.offDriverStatusUpdate(handleDriverStatusUpdate);
80
+ };
81
+ }, [token]);
82
+
83
+ return (
84
+ <AppContext.Provider value={{ activeTrip, setActiveTrip }}>
85
+ {children}
86
+ </AppContext.Provider>
87
+ );
88
+ };
89
+
90
+ export const useApp = () => {
91
+ const context = useContext(AppContext);
92
+ if (!context) {
93
+ throw new Error('useApp must be used within an AppProvider');
94
+ }
95
+ return context;
96
+ };
97
+ ```
98
+
99
+ ```tsx
100
+ // Example usage: \_layout.tsx
101
+ <ThemeProvider>
102
+ <AppProvider token={token}>
103
+ <RootLayout />
104
+ </AppProvider>
105
+ </ThemeProvider>
106
+ ```
107
+
108
+ ```tsx
109
+ // Example usage: trips.tsx
110
+ const { activeTrip, setActiveTrip } = useApp();
111
+ ```
112
+
113
+ ## Emit
114
+
115
+ Emit from anywhere once the socket is connected:
116
+
117
+ ```ts
118
+ const instance = socketInstance;
119
+ if (!instance) return;
120
+
121
+ if (socketInstance.isConnected()) {
122
+ socketInstance.emit('my-event', { foo: 'bar' });
123
+ }
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Available methods in `SocketService`
129
+
130
+ Below is a list of the main public methods of the `SocketService` class, with a brief explanation and usage example:
131
+
132
+ ### `getInstance()`
133
+
134
+ Gets the singleton instance of the socket service.
135
+
136
+ ```ts
137
+ const socket = SocketService.getInstance();
138
+ ```
139
+
140
+ ### `setToken(token: string)`
141
+
142
+ Sets the authentication token and connects the socket with that user context.
143
+
144
+ ```ts
145
+ socket.setToken('my-jwt-token');
146
+ ```
147
+
148
+ ### `clearToken()`
149
+
150
+ Clears the token and disconnects the socket.
151
+
152
+ ```ts
153
+ socket.clearToken();
154
+ ```
155
+
156
+ ### `connect()`
157
+
158
+ Manually connects the socket (usually not needed if you use `setToken`).
159
+
160
+ ```ts
161
+ socket.connect();
162
+ ```
163
+
164
+ ### `disconnect()`
165
+
166
+ Manually disconnects the socket.
167
+
168
+ ```ts
169
+ socket.disconnect();
170
+ ```
171
+
172
+ ### `isConnected(): boolean`
173
+
174
+ Returns `true` if the socket is connected.
175
+
176
+ ```ts
177
+ if (socket.isConnected()) {
178
+ // ...
179
+ }
180
+ ```
181
+
182
+ ### `on(event: string, cb: (data) => void)`
183
+
184
+ Subscribe a callback to a custom event.
185
+
186
+ ```ts
187
+ socket.on('my-event', (data) => {
188
+ console.log(data);
189
+ });
190
+ ```
191
+
192
+ ### `off(event: string, cb?: Function)`
193
+
194
+ Removes a callback from an event, or all listeners if no callback is provided.
195
+
196
+ ```ts
197
+ socket.off('my-event', myCallback);
198
+ // or for all:
199
+ socket.off('my-event');
200
+ ```
201
+
202
+ ### `emit(event: string, data: any)`
203
+
204
+ Emits a custom event to the server.
205
+
206
+ ```ts
207
+ socket.emit('my-event', { foo: 'bar' });
208
+ ```
209
+
210
+ ### `onConnected(cb)` / `offConnected(cb?)`
211
+
212
+ Subscribe/unsubscribe to socket connection events.
213
+
214
+ ```ts
215
+ socket.onConnected(() => console.log('Connected!'));
216
+ socket.offConnected();
217
+ ```
218
+
219
+ ### `onDisconnected(cb)` / `offDisconnected(cb?)`
220
+
221
+ Subscribe/unsubscribe to socket disconnection events.
222
+
223
+ ```ts
224
+ socket.onDisconnected(() => console.log('Disconnected!'));
225
+ socket.offDisconnected();
226
+ ```
227
+
228
+ ### `onDriverStatusUpdate(cb)` / `offDriverStatusUpdate(cb?)`
229
+
230
+ Subscribe/unsubscribe to driver status updates.
231
+
232
+ ```ts
233
+ socket.onDriverStatusUpdate((status) => console.log('Status:', status));
234
+ socket.offDriverStatusUpdate();
235
+ ```
236
+
237
+ ### `onTripUpdate(cb)` / `offTripUpdate(cb?)`
238
+
239
+ Subscribe/unsubscribe to trip updates.
240
+
241
+ ```ts
242
+ socket.onTripUpdate((trip) => console.log('Trip:', trip));
243
+ socket.offTripUpdate();
244
+ ```
245
+
246
+ ### `emitDriverStatusUpdate(data)`
247
+
248
+ Emits a driver status update.
249
+
250
+ ```ts
251
+ socket.emitDriverStatusUpdate({ status: 'online' });
252
+ ```
253
+
254
+ ### `emitTripActionUpdate(data)`
255
+
256
+ Emits a driver trip action.
257
+
258
+ ```ts
259
+ socket.emitTripActionUpdate({ action: 'start', tripId: 123 });
260
+ ```