blackcoffee2 2.1.0 → 2.1.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/.env.example +67 -0
- package/CHANGELOG.md +167 -0
- package/README.md +1 -3
- package/config/database.json +11 -0
- package/controllers/admin/AuthController.js +2 -1
- package/core/ViewHelper.js +75 -0
- package/core/hotReload.js +1 -1
- package/data/blackcoffee_admin.db-shm +0 -0
- package/data/blackcoffee_admin.db-wal +0 -0
- package/includes/adminAuth.js +5 -3
- package/includes/sessions.js +1 -1
- package/otrack.tar.gz +0 -0
- package/package.json +4 -2
- package/programatically/initFlow.js +2 -2
- package/test-aplicacion.con-logisession/BlackCoffee.js +0 -226
- package/test-aplicacion.con-logisession/SSL_SETUP.md +0 -53
- package/test-aplicacion.con-logisession/certs/ca-certificate.pem +0 -32
- package/test-aplicacion.con-logisession/certs/ca-private-key.pem +0 -52
- package/test-aplicacion.con-logisession/certs/certificate-2048.pem +0 -22
- package/test-aplicacion.con-logisession/certs/certificate.pem +0 -32
- package/test-aplicacion.con-logisession/certs/private-key-2048.pem +0 -28
- package/test-aplicacion.con-logisession/certs/private-key.pem +0 -52
- package/test-aplicacion.con-logisession/config/iaQueueSetup.js +0 -84
- package/test-aplicacion.con-logisession/config/qwen-rules.json +0 -39
- package/test-aplicacion.con-logisession/controllers/analyticsController.js +0 -117
- package/test-aplicacion.con-logisession/controllers/auth/AdminAuthController.js +0 -142
- package/test-aplicacion.con-logisession/controllers/auth/AuthController.js +0 -439
- package/test-aplicacion.con-logisession/controllers/auth/AuthViewController.js +0 -223
- package/test-aplicacion.con-logisession/controllers/endpointController.js +0 -66
- package/test-aplicacion.con-logisession/controllers/example.js +0 -183
- package/test-aplicacion.con-logisession/controllers/iaQueueController.js +0 -367
- package/test-aplicacion.con-logisession/controllers/queueController.js +0 -206
- package/test-aplicacion.con-logisession/controllers/qwenQueueController.js +0 -197
- package/test-aplicacion.con-logisession/controllers/test.js +0 -0
- package/test-aplicacion.con-logisession/controllers/tracking/EventsNoFinishController.js +0 -78
- package/test-aplicacion.con-logisession/controllers/tracking/TrackingController.js +0 -412
- package/test-aplicacion.con-logisession/controllers/tracking/TrackingControllerWithLoadModel.js +0 -437
- package/test-aplicacion.con-logisession/hooks/admin-hooks.js +0 -20
- package/test-aplicacion.con-logisession/hooks/general-hooks.js +0 -97
- package/test-aplicacion.con-logisession/hooks/queue-hooks.js +0 -64
- package/test-aplicacion.con-logisession/hooks/route-directory-hooks.js +0 -38
- package/test-aplicacion.con-logisession/hooks/security-hooks.js +0 -24
- package/test-aplicacion.con-logisession/insitu-admin-client/README.md +0 -69
- package/test-aplicacion.con-logisession/insitu-admin-client/package.json +0 -23
- package/test-aplicacion.con-logisession/insitu-admin-client.js +0 -257
- package/test-aplicacion.con-logisession/models/ExampleModel.js +0 -88
- package/test-aplicacion.con-logisession/models/QueueJobModel.js +0 -263
- package/test-aplicacion.con-logisession/models/TokenModel.js +0 -207
- package/test-aplicacion.con-logisession/models/auth/AuthModel.js +0 -66
- package/test-aplicacion.con-logisession/models/auth/UserModel.js +0 -189
- package/test-aplicacion.con-logisession/models/tracking/CompletedCartModel.js +0 -213
- package/test-aplicacion.con-logisession/models/tracking/EventModel.js +0 -366
- package/test-aplicacion.con-logisession/models/tracking/EventsNoFinishModel.js +0 -131
- package/test-aplicacion.con-logisession/models/tracking/SessionModel.js +0 -360
- package/test-aplicacion.con-logisession/models/tracking/SiteFlowModel.js +0 -286
- package/test-aplicacion.con-logisession/models/tracking/TokenModel.js +0 -207
- package/test-aplicacion.con-logisession/package-lock.json +0 -3313
- package/test-aplicacion.con-logisession/package.json +0 -32
- package/test-aplicacion.con-logisession/public/blackcoffee-welcome/index.html +0 -1339
- package/test-aplicacion.con-logisession/public/css/style.css +0 -64
- package/test-aplicacion.con-logisession/public/ejemplo-estatica/index.html +0 -18
- package/test-aplicacion.con-logisession/public/ejemplo-estatica/script.js +0 -16
- package/test-aplicacion.con-logisession/public/ejemplo-estatica/styles.css +0 -43
- package/test-aplicacion.con-logisession/public/images/logo.svg +0 -7
- package/test-aplicacion.con-logisession/public/js/main.js +0 -67
- package/test-aplicacion.con-logisession/routes/analytics-routes.json +0 -8
- package/test-aplicacion.con-logisession/routes/auth-routes.json +0 -98
- package/test-aplicacion.con-logisession/routes/blackcoffee-welcome-routes.json +0 -20
- package/test-aplicacion.con-logisession/routes/duplicate-test-routes.json.disabled +0 -16
- package/test-aplicacion.con-logisession/routes/ejemplo-estatica-routes.json +0 -11
- package/test-aplicacion.con-logisession/routes/endpoints-routes.json +0 -8
- package/test-aplicacion.con-logisession/routes/ia-queue-routes.json +0 -26
- package/test-aplicacion.con-logisession/routes/product-routes.json.disabled +0 -20
- package/test-aplicacion.con-logisession/routes/queue-routes.json +0 -32
- package/test-aplicacion.con-logisession/routes/qwen-routes.json +0 -14
- package/test-aplicacion.con-logisession/routes/static-routes.json +0 -29
- package/test-aplicacion.con-logisession/routes/tracking-routes.json +0 -58
- package/test-aplicacion.con-logisession/routes/tracking-with-loadmodel-routes.json +0 -51
- package/test-aplicacion.con-logisession/utils/dbAdapter.js +0 -88
- package/test-aplicacion.con-logisession/utils/qbWrapper.js +0 -4
- package/test-aplicacion.con-logisession/utils/queueProcessor.js +0 -305
- package/test-aplicacion.con-logisession/utils/qwenRulesService.js +0 -131
- package/test-aplicacion.con-logisession/utils/tokenHelper.js +0 -22
- package/test-aplicacion.con-logisession/views/auth/dashboard.html +0 -443
- package/test-aplicacion.con-logisession/views/auth/forgot-password.html +0 -200
- package/test-aplicacion.con-logisession/views/auth/login.html +0 -213
- package/test-aplicacion.con-logisession/views/auth/register.html +0 -294
- package/test-aplicacion.con-logisession/views/contact/form.html +0 -47
- package/test-aplicacion.con-logisession/views/products/index.html +0 -39
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Controlador de Tracking para OTrack
|
|
3
|
-
* TrackingController.js
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { ControllerBase } = require('insitu-js');
|
|
7
|
-
const SessionModel = require('../../models/tracking/SessionModel');
|
|
8
|
-
const SiteFlowModel = require('../../models/tracking/SiteFlowModel');
|
|
9
|
-
const EventModel = require('../../models/tracking/EventModel');
|
|
10
|
-
const CompletedCartModel = require('../../models/tracking/CompletedCartModel');
|
|
11
|
-
const { validateToken } = require('../../utils/tokenHelper');
|
|
12
|
-
|
|
13
|
-
class TrackingController extends ControllerBase {
|
|
14
|
-
constructor(options = {}) {
|
|
15
|
-
super(options);
|
|
16
|
-
|
|
17
|
-
// Inicializar modelos
|
|
18
|
-
this.sessionModel = new SessionModel();
|
|
19
|
-
this.siteFlowModel = new SiteFlowModel();
|
|
20
|
-
this.eventModel = new EventModel();
|
|
21
|
-
this.completedCartModel = new CompletedCartModel();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Endpoint para registrar sesiones
|
|
25
|
-
async registerSession(req, res) {
|
|
26
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
27
|
-
if (res.headersSent) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const { session_id, user_id, device, country, ip, user, wtf_session, site_url, token } = req.body;
|
|
33
|
-
|
|
34
|
-
// Llamar al modelo para registrar la sesión
|
|
35
|
-
const result = await this.sessionModel.registerSession({
|
|
36
|
-
session_id,
|
|
37
|
-
user_id,
|
|
38
|
-
device,
|
|
39
|
-
country,
|
|
40
|
-
ip,
|
|
41
|
-
user,
|
|
42
|
-
wtf_session,
|
|
43
|
-
site_url,
|
|
44
|
-
token
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
48
|
-
res.end(JSON.stringify(result));
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error('[ERROR] registerSession:', error);
|
|
51
|
-
|
|
52
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
53
|
-
if (res.headersSent) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Determinar el código de estado HTTP según el error
|
|
58
|
-
let statusCode = 500;
|
|
59
|
-
let errorMessage = 'Error interno del servidor';
|
|
60
|
-
|
|
61
|
-
if (error.message === 'Token inválido') {
|
|
62
|
-
statusCode = 401;
|
|
63
|
-
errorMessage = 'Token inválido';
|
|
64
|
-
} else if (error.message === 'session_id es requerido') {
|
|
65
|
-
statusCode = 400;
|
|
66
|
-
errorMessage = 'session_id es requerido';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
70
|
-
res.end(JSON.stringify({ error: errorMessage }));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Endpoint para registrar eventos
|
|
75
|
-
async registerEventA(req, res) {
|
|
76
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
77
|
-
if (res.headersSent) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
const {
|
|
83
|
-
session_header_id, event_type, qty, product_id, sku, product_name,
|
|
84
|
-
url, price, old_qty, new_qty, compressed_data, data_hash,
|
|
85
|
-
event_timestamp, session_id, wtf_session, site_url, token
|
|
86
|
-
} = req.body;
|
|
87
|
-
|
|
88
|
-
// Llamar al modelo para registrar el evento
|
|
89
|
-
const result = await this.eventModel.registerEvent({
|
|
90
|
-
session_header_id, event_type, qty, product_id, sku, product_name,
|
|
91
|
-
url, price, old_qty, new_qty, compressed_data, data_hash,
|
|
92
|
-
event_timestamp, session_id, wtf_session, site_url, token
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
96
|
-
res.end(JSON.stringify(result));
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error('[ERROR] registerEventA:', error);
|
|
99
|
-
|
|
100
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
101
|
-
if (res.headersSent) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Determinar el código de estado HTTP según el error
|
|
106
|
-
let statusCode = 500;
|
|
107
|
-
let errorMessage = 'Error interno del servidor';
|
|
108
|
-
|
|
109
|
-
if (error.message === 'Token inválido') {
|
|
110
|
-
statusCode = 401;
|
|
111
|
-
errorMessage = 'Token inválido';
|
|
112
|
-
} else if (error.message === 'event_type es requerido') {
|
|
113
|
-
statusCode = 400;
|
|
114
|
-
errorMessage = 'event_type es requerido';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
118
|
-
res.end(JSON.stringify({ error: errorMessage }));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Endpoint para insertar flujos de sitio
|
|
123
|
-
async insertSiteFlow(req, res) {
|
|
124
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
125
|
-
if (res.headersSent) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
const {
|
|
131
|
-
session_header_id, event_type, qty, product_id, sku, product_name,
|
|
132
|
-
url, price, old_qty, new_qty, compressed_data, data_hash,
|
|
133
|
-
event_timestamp, session_id, wtf_session, site_url, token
|
|
134
|
-
} = req.body;
|
|
135
|
-
|
|
136
|
-
// Llamar al modelo para insertar el flujo de sitio
|
|
137
|
-
const result = await this.siteFlowModel.insertSiteFlow({
|
|
138
|
-
session_header_id, event_type, qty, product_id, sku, product_name,
|
|
139
|
-
url, price, old_qty, new_qty, compressed_data, data_hash,
|
|
140
|
-
event_timestamp, session_id, wtf_session, site_url, token
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
144
|
-
res.end(JSON.stringify(result));
|
|
145
|
-
} catch (error) {
|
|
146
|
-
console.error('[ERROR] insertSiteFlow:', error);
|
|
147
|
-
|
|
148
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
149
|
-
if (res.headersSent) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Determinar el código de estado HTTP según el error
|
|
154
|
-
let statusCode = 500;
|
|
155
|
-
let errorMessage = 'Error interno del servidor';
|
|
156
|
-
|
|
157
|
-
if (error.message === 'Token inválido') {
|
|
158
|
-
statusCode = 401;
|
|
159
|
-
errorMessage = 'Token inválido';
|
|
160
|
-
} else if (error.message === 'event_type es requerido') {
|
|
161
|
-
statusCode = 400;
|
|
162
|
-
errorMessage = 'event_type es requerido';
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
166
|
-
res.end(JSON.stringify({ error: errorMessage }));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
// Endpoint para obtener sesiones con paginación, filtros y búsqueda
|
|
170
|
-
async getSessions(req, res) {
|
|
171
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
172
|
-
if (res.headersSent) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
// Verificar autenticación: puede ser por token o por sesión
|
|
178
|
-
const isAuthenticated = await this.checkAuthentication(req);
|
|
179
|
-
|
|
180
|
-
if (!isAuthenticated) {
|
|
181
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
182
|
-
res.end(JSON.stringify({
|
|
183
|
-
error: 'Autenticación requerida (token o sesión)'
|
|
184
|
-
}));
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Obtener parámetros de consulta
|
|
189
|
-
const queryParams = { ...req.query };
|
|
190
|
-
|
|
191
|
-
// Obtener los resultados usando el modelo
|
|
192
|
-
const result = await this.sessionModel.getSessions(queryParams);
|
|
193
|
-
|
|
194
|
-
// Convertir BigInt a string para evitar problemas de serialización
|
|
195
|
-
const serializedResult = JSON.parse(JSON.stringify(result, (key, value) =>
|
|
196
|
-
typeof value === 'bigint' ? value.toString() : value
|
|
197
|
-
));
|
|
198
|
-
|
|
199
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
200
|
-
res.end(JSON.stringify(serializedResult));
|
|
201
|
-
} catch (error) {
|
|
202
|
-
console.error('Error en getSessions:', error);
|
|
203
|
-
if (!res.headersSent) {
|
|
204
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
205
|
-
res.end(JSON.stringify({
|
|
206
|
-
total: 0,
|
|
207
|
-
rows: [],
|
|
208
|
-
error: error.message
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Endpoint para obtener eventos con paginación, filtros y búsqueda
|
|
215
|
-
async getEvents(req, res) {
|
|
216
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
217
|
-
if (res.headersSent) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
// Verificar autenticación: puede ser por token o por sesión
|
|
223
|
-
const isAuthenticated = await this.checkAuthentication(req);
|
|
224
|
-
|
|
225
|
-
if (!isAuthenticated) {
|
|
226
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
227
|
-
res.end(JSON.stringify({
|
|
228
|
-
error: 'Autenticación requerida (token o sesión)'
|
|
229
|
-
}));
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Obtener parámetros de consulta
|
|
234
|
-
const queryParams = { ...req.query };
|
|
235
|
-
|
|
236
|
-
// Obtener los resultados usando el modelo
|
|
237
|
-
const result = await this.eventModel.getEvents(queryParams);
|
|
238
|
-
|
|
239
|
-
// Convertir BigInt a string para evitar problemas de serialización
|
|
240
|
-
const serializedResult = JSON.parse(JSON.stringify(result, (key, value) =>
|
|
241
|
-
typeof value === 'bigint' ? value.toString() : value
|
|
242
|
-
));
|
|
243
|
-
|
|
244
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
245
|
-
res.end(JSON.stringify(serializedResult));
|
|
246
|
-
} catch (error) {
|
|
247
|
-
console.error('Error en getEvents:', error);
|
|
248
|
-
if (!res.headersSent) {
|
|
249
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
250
|
-
res.end(JSON.stringify({
|
|
251
|
-
total: 0,
|
|
252
|
-
rows: [],
|
|
253
|
-
error: error.message
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Endpoint para obtener flujos de sitio con paginación, filtros y búsqueda
|
|
260
|
-
async getSiteFlow(req, res) {
|
|
261
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
262
|
-
if (res.headersSent) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
try {
|
|
267
|
-
// Verificar autenticación: puede ser por token o por sesión
|
|
268
|
-
const isAuthenticated = await this.checkAuthentication(req);
|
|
269
|
-
|
|
270
|
-
if (!isAuthenticated) {
|
|
271
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
272
|
-
res.end(JSON.stringify({
|
|
273
|
-
error: 'Autenticación requerida (token o sesión)'
|
|
274
|
-
}));
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// Obtener parámetros de consulta
|
|
279
|
-
const queryParams = { ...req.query };
|
|
280
|
-
|
|
281
|
-
// Obtener los resultados usando el modelo
|
|
282
|
-
const result = await this.siteFlowModel.getSiteFlow(queryParams);
|
|
283
|
-
|
|
284
|
-
// Convertir BigInt a string para evitar problemas de serialización
|
|
285
|
-
const serializedResult = JSON.parse(JSON.stringify(result, (key, value) =>
|
|
286
|
-
typeof value === 'bigint' ? value.toString() : value
|
|
287
|
-
));
|
|
288
|
-
|
|
289
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
290
|
-
res.end(JSON.stringify(serializedResult));
|
|
291
|
-
} catch (error) {
|
|
292
|
-
console.error('Error en getSiteFlow:', error);
|
|
293
|
-
if (!res.headersSent) {
|
|
294
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
295
|
-
res.end(JSON.stringify({
|
|
296
|
-
total: 0,
|
|
297
|
-
rows: [],
|
|
298
|
-
error: error.message
|
|
299
|
-
}));
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// Endpoint para obtener completed carts con filtros
|
|
305
|
-
async getCompletedCarts(req, res) {
|
|
306
|
-
// Verificar si la respuesta ya ha sido enviada
|
|
307
|
-
if (res.headersSent) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
try {
|
|
312
|
-
// Verificar autenticación: puede ser por token o por sesión
|
|
313
|
-
const isAuthenticated = await this.checkAuthentication(req);
|
|
314
|
-
|
|
315
|
-
if (!isAuthenticated) {
|
|
316
|
-
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
317
|
-
res.end(JSON.stringify({
|
|
318
|
-
error: 'Autenticación requerida (token o sesión)'
|
|
319
|
-
}));
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Obtener parámetros de consulta
|
|
324
|
-
const queryParams = { ...req.query };
|
|
325
|
-
|
|
326
|
-
// Obtener los resultados usando el modelo
|
|
327
|
-
const result = await this.completedCartModel.getCompletedCarts(queryParams);
|
|
328
|
-
|
|
329
|
-
// Convertir BigInt a string para evitar problemas de serialización
|
|
330
|
-
const serializedResult = JSON.parse(JSON.stringify(result, (key, value) =>
|
|
331
|
-
typeof value === 'bigint' ? value.toString() : value
|
|
332
|
-
));
|
|
333
|
-
|
|
334
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
335
|
-
res.end(JSON.stringify(serializedResult));
|
|
336
|
-
} catch (error) {
|
|
337
|
-
console.error('Error en getCompletedCarts:', error);
|
|
338
|
-
if (!res.headersSent) {
|
|
339
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
340
|
-
res.end(JSON.stringify({
|
|
341
|
-
total: 0,
|
|
342
|
-
rows: [],
|
|
343
|
-
error: error.message
|
|
344
|
-
}));
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// Método para validar token
|
|
350
|
-
async validateToken(token) {
|
|
351
|
-
try {
|
|
352
|
-
const isValid = await require('../../utils/tokenHelper').validateToken(token);
|
|
353
|
-
return isValid;
|
|
354
|
-
} catch (error) {
|
|
355
|
-
console.error('Error validando token:', error);
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Método para verificar autenticación (token o sesión)
|
|
361
|
-
async checkAuthentication(req) {
|
|
362
|
-
// Primero verificar si hay un token de autorización
|
|
363
|
-
const authHeader = req.headers['authorization'];
|
|
364
|
-
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
365
|
-
const token = authHeader.substring(7); // Remover 'Bearer ' del principio
|
|
366
|
-
const isValidToken = await this.validateToken(token);
|
|
367
|
-
return isValidToken;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Luego verificar si hay una sesión válida
|
|
371
|
-
if (req.session && req.session.data && req.session.data.authenticated) {
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// Si no hay token ni sesión válidos
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Exportar métodos individualmente para que RouteLoader pueda acceder a ellos
|
|
381
|
-
const controllerInstance = new TrackingController();
|
|
382
|
-
|
|
383
|
-
module.exports = {
|
|
384
|
-
registerSession: (req, res) => {
|
|
385
|
-
controllerInstance.setRequestResponse(req, res);
|
|
386
|
-
controllerInstance.registerSession(req, res);
|
|
387
|
-
},
|
|
388
|
-
registerEventA: (req, res) => {
|
|
389
|
-
controllerInstance.setRequestResponse(req, res);
|
|
390
|
-
controllerInstance.registerEventA(req, res);
|
|
391
|
-
},
|
|
392
|
-
insertSiteFlow: (req, res) => {
|
|
393
|
-
controllerInstance.setRequestResponse(req, res);
|
|
394
|
-
controllerInstance.insertSiteFlow(req, res);
|
|
395
|
-
},
|
|
396
|
-
getSessions: (req, res) => {
|
|
397
|
-
controllerInstance.setRequestResponse(req, res);
|
|
398
|
-
controllerInstance.getSessions(req, res);
|
|
399
|
-
},
|
|
400
|
-
getEvents: (req, res) => {
|
|
401
|
-
controllerInstance.setRequestResponse(req, res);
|
|
402
|
-
controllerInstance.getEvents(req, res);
|
|
403
|
-
},
|
|
404
|
-
getSiteFlow: (req, res) => {
|
|
405
|
-
controllerInstance.setRequestResponse(req, res);
|
|
406
|
-
controllerInstance.getSiteFlow(req, res);
|
|
407
|
-
},
|
|
408
|
-
getCompletedCarts: (req, res) => {
|
|
409
|
-
controllerInstance.setRequestResponse(req, res);
|
|
410
|
-
controllerInstance.getCompletedCarts(req, res);
|
|
411
|
-
}
|
|
412
|
-
};
|