@dapex-tech/elite-online-services 0.0.0-development

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.
@@ -0,0 +1,322 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ import { ApiError } from './ApiError';
6
+ import type { ApiRequestOptions } from './ApiRequestOptions';
7
+ import type { ApiResult } from './ApiResult';
8
+ import { CancelablePromise } from './CancelablePromise';
9
+ import type { OnCancel } from './CancelablePromise';
10
+ import type { OpenAPIConfig } from './OpenAPI';
11
+
12
+ export const isDefined = <T>(value: T | null | undefined): value is Exclude<T, null | undefined> => {
13
+ return value !== undefined && value !== null;
14
+ };
15
+
16
+ export const isString = (value: any): value is string => {
17
+ return typeof value === 'string';
18
+ };
19
+
20
+ export const isStringWithValue = (value: any): value is string => {
21
+ return isString(value) && value !== '';
22
+ };
23
+
24
+ export const isBlob = (value: any): value is Blob => {
25
+ return (
26
+ typeof value === 'object' &&
27
+ typeof value.type === 'string' &&
28
+ typeof value.stream === 'function' &&
29
+ typeof value.arrayBuffer === 'function' &&
30
+ typeof value.constructor === 'function' &&
31
+ typeof value.constructor.name === 'string' &&
32
+ /^(Blob|File)$/.test(value.constructor.name) &&
33
+ /^(Blob|File)$/.test(value[Symbol.toStringTag])
34
+ );
35
+ };
36
+
37
+ export const isFormData = (value: any): value is FormData => {
38
+ return value instanceof FormData;
39
+ };
40
+
41
+ export const base64 = (str: string): string => {
42
+ try {
43
+ return btoa(str);
44
+ } catch (err) {
45
+ // @ts-ignore
46
+ return Buffer.from(str).toString('base64');
47
+ }
48
+ };
49
+
50
+ export const getQueryString = (params: Record<string, any>): string => {
51
+ const qs: string[] = [];
52
+
53
+ const append = (key: string, value: any) => {
54
+ qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
55
+ };
56
+
57
+ const process = (key: string, value: any) => {
58
+ if (isDefined(value)) {
59
+ if (Array.isArray(value)) {
60
+ value.forEach(v => {
61
+ process(key, v);
62
+ });
63
+ } else if (typeof value === 'object') {
64
+ Object.entries(value).forEach(([k, v]) => {
65
+ process(`${key}[${k}]`, v);
66
+ });
67
+ } else {
68
+ append(key, value);
69
+ }
70
+ }
71
+ };
72
+
73
+ Object.entries(params).forEach(([key, value]) => {
74
+ process(key, value);
75
+ });
76
+
77
+ if (qs.length > 0) {
78
+ return `?${qs.join('&')}`;
79
+ }
80
+
81
+ return '';
82
+ };
83
+
84
+ const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
85
+ const encoder = config.ENCODE_PATH || encodeURI;
86
+
87
+ const path = options.url
88
+ .replace('{api-version}', config.VERSION)
89
+ .replace(/{(.*?)}/g, (substring: string, group: string) => {
90
+ if (options.path?.hasOwnProperty(group)) {
91
+ return encoder(String(options.path[group]));
92
+ }
93
+ return substring;
94
+ });
95
+
96
+ const url = `${config.BASE}${path}`;
97
+ if (options.query) {
98
+ return `${url}${getQueryString(options.query)}`;
99
+ }
100
+ return url;
101
+ };
102
+
103
+ export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
104
+ if (options.formData) {
105
+ const formData = new FormData();
106
+
107
+ const process = (key: string, value: any) => {
108
+ if (isString(value) || isBlob(value)) {
109
+ formData.append(key, value);
110
+ } else {
111
+ formData.append(key, JSON.stringify(value));
112
+ }
113
+ };
114
+
115
+ Object.entries(options.formData)
116
+ .filter(([_, value]) => isDefined(value))
117
+ .forEach(([key, value]) => {
118
+ if (Array.isArray(value)) {
119
+ value.forEach(v => process(key, v));
120
+ } else {
121
+ process(key, value);
122
+ }
123
+ });
124
+
125
+ return formData;
126
+ }
127
+ return undefined;
128
+ };
129
+
130
+ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
131
+
132
+ export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => {
133
+ if (typeof resolver === 'function') {
134
+ return (resolver as Resolver<T>)(options);
135
+ }
136
+ return resolver;
137
+ };
138
+
139
+ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
140
+ const [token, username, password, additionalHeaders] = await Promise.all([
141
+ resolve(options, config.TOKEN),
142
+ resolve(options, config.USERNAME),
143
+ resolve(options, config.PASSWORD),
144
+ resolve(options, config.HEADERS),
145
+ ]);
146
+
147
+ const headers = Object.entries({
148
+ Accept: 'application/json',
149
+ ...additionalHeaders,
150
+ ...options.headers,
151
+ })
152
+ .filter(([_, value]) => isDefined(value))
153
+ .reduce((headers, [key, value]) => ({
154
+ ...headers,
155
+ [key]: String(value),
156
+ }), {} as Record<string, string>);
157
+
158
+ if (isStringWithValue(token)) {
159
+ headers['Authorization'] = `Bearer ${token}`;
160
+ }
161
+
162
+ if (isStringWithValue(username) && isStringWithValue(password)) {
163
+ const credentials = base64(`${username}:${password}`);
164
+ headers['Authorization'] = `Basic ${credentials}`;
165
+ }
166
+
167
+ if (options.body !== undefined) {
168
+ if (options.mediaType) {
169
+ headers['Content-Type'] = options.mediaType;
170
+ } else if (isBlob(options.body)) {
171
+ headers['Content-Type'] = options.body.type || 'application/octet-stream';
172
+ } else if (isString(options.body)) {
173
+ headers['Content-Type'] = 'text/plain';
174
+ } else if (!isFormData(options.body)) {
175
+ headers['Content-Type'] = 'application/json';
176
+ }
177
+ }
178
+
179
+ return new Headers(headers);
180
+ };
181
+
182
+ export const getRequestBody = (options: ApiRequestOptions): any => {
183
+ if (options.body !== undefined) {
184
+ if (options.mediaType?.includes('/json')) {
185
+ return JSON.stringify(options.body)
186
+ } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
187
+ return options.body;
188
+ } else {
189
+ return JSON.stringify(options.body);
190
+ }
191
+ }
192
+ return undefined;
193
+ };
194
+
195
+ export const sendRequest = async (
196
+ config: OpenAPIConfig,
197
+ options: ApiRequestOptions,
198
+ url: string,
199
+ body: any,
200
+ formData: FormData | undefined,
201
+ headers: Headers,
202
+ onCancel: OnCancel
203
+ ): Promise<Response> => {
204
+ const controller = new AbortController();
205
+
206
+ const request: RequestInit = {
207
+ headers,
208
+ body: body ?? formData,
209
+ method: options.method,
210
+ signal: controller.signal,
211
+ };
212
+
213
+ if (config.WITH_CREDENTIALS) {
214
+ request.credentials = config.CREDENTIALS;
215
+ }
216
+
217
+ onCancel(() => controller.abort());
218
+
219
+ return await fetch(url, request);
220
+ };
221
+
222
+ export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => {
223
+ if (responseHeader) {
224
+ const content = response.headers.get(responseHeader);
225
+ if (isString(content)) {
226
+ return content;
227
+ }
228
+ }
229
+ return undefined;
230
+ };
231
+
232
+ export const getResponseBody = async (response: Response): Promise<any> => {
233
+ if (response.status !== 204) {
234
+ try {
235
+ const contentType = response.headers.get('Content-Type');
236
+ if (contentType) {
237
+ const jsonTypes = ['application/json', 'application/problem+json']
238
+ const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
239
+ if (isJSON) {
240
+ return await response.json();
241
+ } else {
242
+ return await response.text();
243
+ }
244
+ }
245
+ } catch (error) {
246
+ console.error(error);
247
+ }
248
+ }
249
+ return undefined;
250
+ };
251
+
252
+ export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
253
+ const errors: Record<number, string> = {
254
+ 400: 'Bad Request',
255
+ 401: 'Unauthorized',
256
+ 403: 'Forbidden',
257
+ 404: 'Not Found',
258
+ 500: 'Internal Server Error',
259
+ 502: 'Bad Gateway',
260
+ 503: 'Service Unavailable',
261
+ ...options.errors,
262
+ }
263
+
264
+ const error = errors[result.status];
265
+ if (error) {
266
+ throw new ApiError(options, result, error);
267
+ }
268
+
269
+ if (!result.ok) {
270
+ const errorStatus = result.status ?? 'unknown';
271
+ const errorStatusText = result.statusText ?? 'unknown';
272
+ const errorBody = (() => {
273
+ try {
274
+ return JSON.stringify(result.body, null, 2);
275
+ } catch (e) {
276
+ return undefined;
277
+ }
278
+ })();
279
+
280
+ throw new ApiError(options, result,
281
+ `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
282
+ );
283
+ }
284
+ };
285
+
286
+ /**
287
+ * Request method
288
+ * @param config The OpenAPI configuration object
289
+ * @param options The request options from the service
290
+ * @returns CancelablePromise<T>
291
+ * @throws ApiError
292
+ */
293
+ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> => {
294
+ return new CancelablePromise(async (resolve, reject, onCancel) => {
295
+ try {
296
+ const url = getUrl(config, options);
297
+ const formData = getFormData(options);
298
+ const body = getRequestBody(options);
299
+ const headers = await getHeaders(config, options);
300
+
301
+ if (!onCancel.isCancelled) {
302
+ const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
303
+ const responseBody = await getResponseBody(response);
304
+ const responseHeader = getResponseHeader(response, options.responseHeader);
305
+
306
+ const result: ApiResult = {
307
+ url,
308
+ ok: response.ok,
309
+ status: response.status,
310
+ statusText: response.statusText,
311
+ body: responseHeader ?? responseBody,
312
+ };
313
+
314
+ catchErrorCodes(options, result);
315
+
316
+ resolve(result.body);
317
+ }
318
+ } catch (error) {
319
+ reject(error);
320
+ }
321
+ });
322
+ };
@@ -0,0 +1,12 @@
1
+ import { OpenAPI } from './core/OpenAPI';
2
+ import * as services from './services';
3
+
4
+ /**
5
+ * Crea un cliente SDK con la URL base configurada
6
+ */
7
+ export function createClient(baseUrl?: string) {
8
+ OpenAPI.BASE = baseUrl || process.env.API_URL || 'http://localhost:3000';
9
+ return {
10
+ ...services, // todos los servicios agrupados
11
+ };
12
+ }
package/index.ts ADDED
@@ -0,0 +1,10 @@
1
+
2
+ export * from './models';
3
+ export * from './core';
4
+ export * from './services';
5
+ export * from './types';
6
+
7
+ export * from './createClient';
8
+ export * from './socketService';
9
+
10
+
@@ -0,0 +1,31 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type AdminDto = {
6
+ /**
7
+ * Admin First Name
8
+ */
9
+ first_name: string;
10
+ /**
11
+ * Admin Last Name
12
+ */
13
+ last_name: string;
14
+ /**
15
+ * Admin Phone Number
16
+ */
17
+ phone: string;
18
+ /**
19
+ * Admin Email
20
+ */
21
+ email: string;
22
+ /**
23
+ * Admin Password
24
+ */
25
+ password: string;
26
+ /**
27
+ * Admin Role ID
28
+ */
29
+ role_id: number;
30
+ };
31
+
@@ -0,0 +1,31 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type CreateAdminDto = {
6
+ /**
7
+ * Admin First Name
8
+ */
9
+ first_name: string;
10
+ /**
11
+ * Admin Last Name
12
+ */
13
+ last_name: string;
14
+ /**
15
+ * Admin Phone Number
16
+ */
17
+ phone: string;
18
+ /**
19
+ * Admin Email
20
+ */
21
+ email: string;
22
+ /**
23
+ * Admin Password
24
+ */
25
+ password: string;
26
+ /**
27
+ * Admin Role ID
28
+ */
29
+ role_id: number;
30
+ };
31
+
@@ -0,0 +1,47 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type CreateDriverDto = {
6
+ /**
7
+ * Driver First Name
8
+ */
9
+ first_name: string;
10
+ /**
11
+ * Driver Last Name
12
+ */
13
+ last_name: string;
14
+ /**
15
+ * Driver Phone Number (10 dígitos)
16
+ */
17
+ phone: string;
18
+ /**
19
+ * Driver Email
20
+ */
21
+ email: string;
22
+ /**
23
+ * Driver Password (6-20 caracteres)
24
+ */
25
+ password: string;
26
+ /**
27
+ * Driver License Number
28
+ */
29
+ license: string;
30
+ /**
31
+ * Driver Type (e.g., internal, external)
32
+ */
33
+ type: string;
34
+ /**
35
+ * Driver State (activo/inactivo)
36
+ */
37
+ state?: boolean;
38
+ /**
39
+ * Last Location
40
+ */
41
+ last_location?: string;
42
+ /**
43
+ * Last Heartbeat
44
+ */
45
+ last_heartbeat?: string;
46
+ };
47
+
@@ -0,0 +1,27 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type CreateUserDto = {
6
+ /**
7
+ * User First Name
8
+ */
9
+ first_name: string;
10
+ /**
11
+ * User Last Name
12
+ */
13
+ last_name: string;
14
+ /**
15
+ * User Email
16
+ */
17
+ email: string;
18
+ /**
19
+ * User Password
20
+ */
21
+ password: string;
22
+ /**
23
+ * User Phone Number
24
+ */
25
+ phone: string;
26
+ };
27
+
@@ -0,0 +1,47 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type DriverDto = {
6
+ /**
7
+ * Driver First Name
8
+ */
9
+ first_name: string;
10
+ /**
11
+ * Driver Last Name
12
+ */
13
+ last_name: string;
14
+ /**
15
+ * Driver Phone Number (10 dígitos)
16
+ */
17
+ phone: string;
18
+ /**
19
+ * Driver Email
20
+ */
21
+ email: string;
22
+ /**
23
+ * Driver Password (6-20 caracteres)
24
+ */
25
+ password: string;
26
+ /**
27
+ * Driver License Number
28
+ */
29
+ license: string;
30
+ /**
31
+ * Driver Type (e.g., internal, external)
32
+ */
33
+ type: string;
34
+ /**
35
+ * Driver State (activo/inactivo)
36
+ */
37
+ state?: boolean;
38
+ /**
39
+ * Last Location
40
+ */
41
+ last_location?: string;
42
+ /**
43
+ * Last Heartbeat
44
+ */
45
+ last_heartbeat?: string;
46
+ };
47
+
@@ -0,0 +1,15 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type LoginDto = {
6
+ /**
7
+ * Email must be valid
8
+ */
9
+ email: string;
10
+ /**
11
+ * Password must be at least 6 characters long
12
+ */
13
+ password: string;
14
+ };
15
+
@@ -0,0 +1,31 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type UpdateAdminDto = {
6
+ /**
7
+ * Admin First Name Updated
8
+ */
9
+ first_name: string;
10
+ /**
11
+ * Admin Last Name Updated
12
+ */
13
+ last_name: string;
14
+ /**
15
+ * Admin Phone Number Updated
16
+ */
17
+ phone: string;
18
+ /**
19
+ * Admin Email Updated
20
+ */
21
+ email: string;
22
+ /**
23
+ * Admin Password Updated
24
+ */
25
+ password: string;
26
+ /**
27
+ * Admin Role ID Updated
28
+ */
29
+ role_id: number;
30
+ };
31
+
@@ -0,0 +1,47 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type UpdateDriverDto = {
6
+ /**
7
+ * Driver First Name
8
+ */
9
+ first_name?: string;
10
+ /**
11
+ * Driver Last Name
12
+ */
13
+ last_name?: string;
14
+ /**
15
+ * Driver Phone Number (10 dígitos)
16
+ */
17
+ phone?: string;
18
+ /**
19
+ * Driver Email
20
+ */
21
+ email?: string;
22
+ /**
23
+ * Driver Password (6-20 caracteres)
24
+ */
25
+ password?: string;
26
+ /**
27
+ * Driver License Number
28
+ */
29
+ license?: string;
30
+ /**
31
+ * Driver Type (e.g., internal, external)
32
+ */
33
+ type?: string;
34
+ /**
35
+ * Driver State (activo/inactivo)
36
+ */
37
+ state?: boolean;
38
+ /**
39
+ * Last Location
40
+ */
41
+ last_location?: string;
42
+ /**
43
+ * Last Heartbeat
44
+ */
45
+ last_heartbeat?: string;
46
+ };
47
+
@@ -0,0 +1,27 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type UpdateUserDto = {
6
+ /**
7
+ * First name of the user
8
+ */
9
+ first_name?: string;
10
+ /**
11
+ * Last name of the user
12
+ */
13
+ last_name?: string;
14
+ /**
15
+ * Phone number (10 digits)
16
+ */
17
+ phone?: string;
18
+ /**
19
+ * Unique email
20
+ */
21
+ email?: string;
22
+ /**
23
+ * Password (6-20 characters)
24
+ */
25
+ password?: string;
26
+ };
27
+
@@ -0,0 +1,27 @@
1
+ /* generated using openapi-typescript-codegen -- do not edit */
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ export type UserDto = {
6
+ /**
7
+ * User First Name
8
+ */
9
+ first_name: string;
10
+ /**
11
+ * User Last Name
12
+ */
13
+ last_name: string;
14
+ /**
15
+ * User Email
16
+ */
17
+ email: string;
18
+ /**
19
+ * User Password
20
+ */
21
+ password: string;
22
+ /**
23
+ * User Phone Number
24
+ */
25
+ phone: string;
26
+ };
27
+
@@ -0,0 +1,10 @@
1
+ export * from './AdminDto';
2
+ export * from './CreateAdminDto';
3
+ export * from './CreateDriverDto';
4
+ export * from './CreateUserDto';
5
+ export * from './DriverDto';
6
+ export * from './LoginDto';
7
+ export * from './UpdateAdminDto';
8
+ export * from './UpdateDriverDto';
9
+ export * from './UpdateUserDto';
10
+ export * from './UserDto';