@runnerpro/backend 1.0.21 → 1.0.23

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 (40) hide show
  1. package/lib/cjs/chat/api/conversation.js +281 -0
  2. package/lib/cjs/chat/api/index.js +10 -0
  3. package/lib/cjs/chat/api/listConversations.js +50 -0
  4. package/lib/cjs/chat/exposed/conversation.js +36 -0
  5. package/lib/cjs/chat/exposed/index.js +8 -0
  6. package/lib/cjs/chat/index.js +41 -0
  7. package/lib/cjs/chat/utils/getRoom.js +10 -0
  8. package/lib/cjs/index.js +7 -1
  9. package/lib/cjs/locale/en.js +8 -0
  10. package/lib/cjs/locale/es.js +8 -0
  11. package/lib/cjs/locale/fr.js +8 -0
  12. package/lib/cjs/locale/index.js +18 -0
  13. package/lib/cjs/locale/it.js +8 -0
  14. package/lib/cjs/types/chat/api/conversation.d.ts +3 -0
  15. package/lib/cjs/types/chat/api/conversation.d.ts.map +1 -0
  16. package/lib/cjs/types/chat/api/index.d.ts +3 -0
  17. package/lib/cjs/types/chat/api/index.d.ts.map +1 -0
  18. package/lib/cjs/types/chat/api/listConversations.d.ts +7 -0
  19. package/lib/cjs/types/chat/api/listConversations.d.ts.map +1 -0
  20. package/lib/cjs/types/chat/exposed/conversation.d.ts +7 -0
  21. package/lib/cjs/types/chat/exposed/conversation.d.ts.map +1 -0
  22. package/lib/cjs/types/chat/exposed/index.d.ts +3 -0
  23. package/lib/cjs/types/chat/exposed/index.d.ts.map +1 -0
  24. package/lib/cjs/types/chat/index.d.ts +11 -0
  25. package/lib/cjs/types/chat/index.d.ts.map +1 -0
  26. package/lib/cjs/types/chat/utils/getRoom.d.ts +3 -0
  27. package/lib/cjs/types/chat/utils/getRoom.d.ts.map +1 -0
  28. package/lib/cjs/types/index.d.ts +4 -1
  29. package/lib/cjs/types/index.d.ts.map +1 -1
  30. package/lib/cjs/types/locale/en.d.ts +6 -0
  31. package/lib/cjs/types/locale/en.d.ts.map +1 -0
  32. package/lib/cjs/types/locale/es.d.ts +6 -0
  33. package/lib/cjs/types/locale/es.d.ts.map +1 -0
  34. package/lib/cjs/types/locale/fr.d.ts +6 -0
  35. package/lib/cjs/types/locale/fr.d.ts.map +1 -0
  36. package/lib/cjs/types/locale/index.d.ts +3 -0
  37. package/lib/cjs/types/locale/index.d.ts.map +1 -0
  38. package/lib/cjs/types/locale/it.d.ts +6 -0
  39. package/lib/cjs/types/locale/it.d.ts.map +1 -0
  40. package/package.json +9 -4
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.conversationRoute = void 0;
27
+ const fs_1 = __importDefault(require("fs"));
28
+ const path_1 = __importDefault(require("path"));
29
+ const util_1 = require("util");
30
+ const jimp_1 = __importDefault(require("jimp"));
31
+ const exifr_1 = __importDefault(require("exifr"));
32
+ const axios_1 = __importDefault(require("axios"));
33
+ const index_1 = require("../../index");
34
+ const common_1 = require("@runnerpro/common");
35
+ const index_2 = require("../../locale/index");
36
+ const multer_1 = __importDefault(require("multer"));
37
+ const conversationRoute = (_a) => {
38
+ var { router } = _a, params = __rest(_a, ["router"]);
39
+ const uploadFile = (0, multer_1.default)({
40
+ dest: 'uploads/',
41
+ limits: {
42
+ fileSize: 30 * 1024 * 1024,
43
+ files: 1,
44
+ },
45
+ });
46
+ router.get('/conversation', (req, res) => getConversation(req, res, params).catch((error) => (0, index_1.err)(req, res, error)));
47
+ router.get('/conversation/suggestion', (req, res) => getConversationSuggestion(req, res).catch((error) => (0, index_1.err)(req, res, error)));
48
+ router.get('/conversation/image/:id', (req, res) => getConversationImage(req, res, params).catch((error) => (0, index_1.err)(req, res, error)));
49
+ router.get('/conversation/file/:id', (req, res) => getConversationFile(req, res, params).catch((error) => (0, index_1.err)(req, res, error)));
50
+ router.post('/conversation/send', (req, res) => sendMessage(req, res, params).catch((error) => (0, index_1.err)(req, res, error)));
51
+ router.post('/conversation/send-file', uploadFile.single('file'), (req, res) => sendFile(req, res, params).catch((error) => (0, index_1.err)(req, res, error)));
52
+ router.post('/conversation/read', (req, res) => readMessage(req, res, params).catch((error) => (0, index_1.err)(req, res, error)));
53
+ router.post('/conversation/read-feelings', (req, res) => readFeelings(req, res, params).catch((error) => (0, index_1.err)(req, res, error)));
54
+ };
55
+ exports.conversationRoute = conversationRoute;
56
+ const getConversation = (req, res, { query, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const idCliente = isClient ? req.session.userid : req.query.id;
58
+ const [header] = yield query('SELECT [NAME], [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
59
+ let messages = yield query(`SELECT [CHAT MESSAGE].*,
60
+ [WORKOUT].[DATE] AS [WORKOUT DATE], [WORKOUT].[TYPE] AS [WORKOUT TYPE], [WORKOUT].[TITLE] AS [WORKOUT TITLE],
61
+ [FEELINGS], [FEELINGS DESCRIPTION]
62
+ FROM [CHAT MESSAGE]
63
+ LEFT JOIN [WORKOUT] ON [WORKOUT].[ID] = [CHAT MESSAGE].[ID WORKOUT]
64
+ WHERE [CHAT MESSAGE].[ID CLIENTE] = ? AND (${isClient} = FALSE OR [CHAT MESSAGE].[SHOW CLIENT] = TRUE)
65
+ ORDER BY [CHAT MESSAGE].[DATE] DESC
66
+ LIMIT 100`, [idCliente]);
67
+ messages = messages.reverse();
68
+ // Si el cliente no habla español, se muestran los mensajes en el idioma del cliente. El entrenador siempre ve los mensajes en español que están en la columna [TEXT]
69
+ if (header.preferredLanguage !== common_1.LANGUAGES.ES && isClient) {
70
+ messages = messages.map((message) => {
71
+ if (message.text)
72
+ message.text = message.textPreferredLanguage || message.text;
73
+ return message;
74
+ });
75
+ }
76
+ res.send({ header, messages });
77
+ markReadMessage({ isClient, query, idCliente });
78
+ });
79
+ const getConversationImage = (req, res, { query, bucket, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
80
+ const result = yield getChatFile({
81
+ query,
82
+ bucket,
83
+ id: req.params.id,
84
+ isClient,
85
+ userid: req.session.userid,
86
+ });
87
+ if (!result)
88
+ return res.status(404).send('Not found');
89
+ res.setHeader('Cache-Control', 'public, max-age=31536000');
90
+ res.setHeader('Expires', new Date(Date.now() + 31536000).toUTCString());
91
+ res.send({
92
+ file: result.file.toString('base64'),
93
+ mimetype: result.message.mimetype,
94
+ });
95
+ });
96
+ const getConversationFile = (req, res, { query, bucket, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
97
+ const result = yield getChatFile({
98
+ query,
99
+ bucket,
100
+ id: req.params.id,
101
+ isClient,
102
+ userid: req.session.userid,
103
+ });
104
+ if (!result)
105
+ return res.status(404).send('Not found');
106
+ res.writeHead(200, {
107
+ 'Content-Type': result.message.text,
108
+ 'Content-disposition': 'inline',
109
+ 'Content-Length': result.file.length,
110
+ });
111
+ res.end(result.file);
112
+ });
113
+ const getChatFile = ({ query, bucket, id, isClient, userid }) => __awaiter(void 0, void 0, void 0, function* () {
114
+ const idBBDD = id.includes('-original') ? id.replace('-original', '') : id;
115
+ const [message] = yield query('SELECT [MIMETYPE], [TEXT] FROM [CHAT MESSAGE] WHERE [ID] = ? AND (? = FALSE OR [ID CLIENTE] = ?)', [
116
+ idBBDD,
117
+ isClient,
118
+ userid,
119
+ ]);
120
+ if (!message)
121
+ return null;
122
+ try {
123
+ const [file] = yield bucket.file(`Chat/${id}`).download();
124
+ return { file, message };
125
+ }
126
+ catch (error) {
127
+ return null;
128
+ }
129
+ });
130
+ const getConversationSuggestion = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
131
+ let result;
132
+ try {
133
+ result = yield axios_1.default
134
+ .post(`${process.env.BACKEND_IA_URL}/api/chat/suggestion`, { userId: req.query.user }, {
135
+ headers: {
136
+ 'ngrok-skip-browser-warning': true, // working with ngrok
137
+ 'Content-Type': 'application/json',
138
+ Authorization: `Bearer ${process.env.IA_ACCESS_TOKEN}`,
139
+ },
140
+ })
141
+ .then((response) => response.data);
142
+ }
143
+ catch (e) {
144
+ (0, index_1.err)(null, null, e);
145
+ result = { error: 'Ha habido un error con el servidor' };
146
+ }
147
+ finally {
148
+ res.send(result);
149
+ }
150
+ });
151
+ const sendMessage = (req, res, { sendNotification, firebaseMessaging, query, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
152
+ const { text } = req.body;
153
+ const { userid } = req.session;
154
+ const idCliente = isClient ? req.session.userid : req.body.idCliente;
155
+ // Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
156
+ const { textSpanish, textPreferredLanguage, preferredLanguage } = yield getPreferredLanguageForChat({
157
+ text,
158
+ idCliente,
159
+ isClient,
160
+ query,
161
+ });
162
+ yield query('INSERT INTO [CHAT MESSAGE] ([ID CLIENTE], [ID SENDER], [TEXT], [TEXT PREFERRED LANGUAGE], [PREFERRED LANGUAGE], [TYPE]) VALUES (?, ?, ?, ?, ?, 1)', [isClient ? userid : idCliente, userid, textSpanish, textPreferredLanguage, preferredLanguage]);
163
+ if (!isClient) {
164
+ sendNotification({
165
+ firebaseMessaging,
166
+ idCliente,
167
+ body: `Rubén: ${textPreferredLanguage || textSpanish}`,
168
+ url: '/chat',
169
+ });
170
+ // Enviar el mensaje a la IA de vuelta para que aprenda que mensaje a acabado enviando el entrenador
171
+ yield axios_1.default.put(`${process.env.BACKEND_IA_URL}/api/chat/suggestion`, { userId: idCliente }, {
172
+ headers: {
173
+ 'ngrok-skip-browser-warning': true, // working with ngrok
174
+ 'Content-Type': 'application/json',
175
+ Authorization: `Bearer ${process.env.IA_ACCESS_TOKEN}`,
176
+ },
177
+ });
178
+ }
179
+ res.send({ status: 'ok' });
180
+ });
181
+ const getPreferredLanguageForChat = ({ text, idCliente, isClient, query }) => __awaiter(void 0, void 0, void 0, function* () {
182
+ const [{ preferredLanguage }] = yield query('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
183
+ if (preferredLanguage === common_1.LANGUAGES.ES)
184
+ return {
185
+ textSpanish: text,
186
+ textPreferredLanguage: null,
187
+ preferredLanguage: null,
188
+ };
189
+ const textPreferredLanguage = yield (0, index_1.translate)(text, {
190
+ fromLanguage: isClient ? preferredLanguage : common_1.LANGUAGES.ES,
191
+ toLanguage: isClient ? common_1.LANGUAGES.ES : preferredLanguage,
192
+ });
193
+ return {
194
+ textSpanish: isClient ? textPreferredLanguage : text,
195
+ textPreferredLanguage: isClient ? text : textPreferredLanguage,
196
+ preferredLanguage: preferredLanguage,
197
+ };
198
+ });
199
+ const sendFile = (req, res, { sendNotification, firebaseMessaging, query, isClient, bucket }) => __awaiter(void 0, void 0, void 0, function* () {
200
+ const { idCliente, type, duration } = req.body;
201
+ const { userid } = req.session;
202
+ const [{ id: idFile }] = yield query('INSERT INTO [CHAT MESSAGE] ([ID CLIENTE], [ID SENDER], [TEXT], [MIMETYPE], [DURATION], [TYPE]) VALUES (?, ?, ?, ?, ?, ?) RETURNING [ID]', [isClient ? userid : idCliente, userid, req.file.originalname, req.file.mimetype, duration || null, type || 2]);
203
+ const filePath = path_1.default.join('./uploads', req.file.filename);
204
+ const fileData = fs_1.default.readFileSync(filePath);
205
+ const files = [];
206
+ if (req.file.mimetype.includes('image')) {
207
+ try {
208
+ const fileDataResize = yield resizeImage(fileData, filePath, req.file.mimetype);
209
+ const fileDataOriented = yield orientationImage(fileData, filePath, null, req.file.mimetype);
210
+ files.push({ data: fileDataResize, id: idFile });
211
+ files.push({ data: fileDataOriented, id: `${idFile}-original` });
212
+ }
213
+ catch (error) {
214
+ (0, index_1.err)(null, null, error);
215
+ }
216
+ }
217
+ else {
218
+ files.push({ data: fileData, id: idFile });
219
+ }
220
+ for (const file of files) {
221
+ yield bucket.file(`Chat/${file.id}`).save(file.data);
222
+ }
223
+ fs_1.default.unlinkSync(filePath);
224
+ if (!isClient) {
225
+ const [cliente] = yield query('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
226
+ sendNotification({
227
+ firebaseMessaging,
228
+ idCliente,
229
+ body: `Rubén: ${(0, index_2.t)(Number(type) === 4 ? 'Audio' : 'Archivo adjunto', cliente.preferredLanguage)}`,
230
+ url: '/chat',
231
+ });
232
+ }
233
+ res.send({ idFile });
234
+ });
235
+ const readMessage = (req, res, { query, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
236
+ const { idCliente } = req.body;
237
+ yield markReadMessage({ isClient, query, idCliente });
238
+ res.send({ status: 'ok' });
239
+ });
240
+ const markReadMessage = ({ isClient, query, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
241
+ const conditionSender = isClient ? ' AND [ID SENDER] != ?' : ' AND [ID SENDER] = ?';
242
+ yield query('UPDATE [CHAT MESSAGE] SET [READ] = TRUE WHERE [ID CLIENTE] = ? AND [READ] = FALSE ' + conditionSender, [idCliente, idCliente]);
243
+ });
244
+ const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
245
+ if (mimetype.includes('webp'))
246
+ return data;
247
+ const sizeOf = (0, util_1.promisify)(require('image-size'));
248
+ const dimensions = yield sizeOf(filePath);
249
+ const imageWidth = dimensions.width;
250
+ const imageHeight = dimensions.height;
251
+ const newWidth = 400;
252
+ const newHeight = Math.round((imageHeight * newWidth) / imageWidth);
253
+ let image = yield jimp_1.default.read(filePath);
254
+ image = yield image.resize(newWidth, newHeight);
255
+ return orientationImage(data, image, null, mimetype);
256
+ });
257
+ const orientationImage = (data, filePath, image = null, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
258
+ if (mimetype.includes('webp'))
259
+ return data;
260
+ if (!image)
261
+ image = yield jimp_1.default.read(filePath);
262
+ const orientation = yield exifr_1.default.orientation(data);
263
+ let rotate = 0;
264
+ if (orientation === 6)
265
+ rotate = 90;
266
+ else if (orientation === 8)
267
+ rotate = -90;
268
+ else if (orientation === 3)
269
+ rotate = 180;
270
+ if (rotate) {
271
+ image = yield image.rotate(90);
272
+ }
273
+ return image.getBufferAsync(jimp_1.default.MIME_JPEG);
274
+ });
275
+ const readFeelings = (req, res, { query, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
276
+ const { id } = req.body;
277
+ if (!isClient) {
278
+ yield query('UPDATE [CHAT MESSAGE] SET [READ FEELINGS] = TRUE WHERE [ID] = ?', [id]);
279
+ }
280
+ res.send({ status: 'ok' });
281
+ });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chatApi = void 0;
4
+ const listConversations_1 = require("./listConversations");
5
+ const conversation_1 = require("./conversation");
6
+ const chatApi = (params) => {
7
+ (0, listConversations_1.listConversationsRoute)(params);
8
+ (0, conversation_1.conversationRoute)(params);
9
+ };
10
+ exports.chatApi = chatApi;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.listConversationsRoute = void 0;
24
+ const listConversationsRoute = (_a) => {
25
+ var { router, err } = _a, params = __rest(_a, ["router", "err"]);
26
+ router.get('/list', (req, res) => getList(req, res, params).catch((error) => err(req, res, error)));
27
+ };
28
+ exports.listConversationsRoute = listConversationsRoute;
29
+ const getList = (req, res, { query, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
30
+ if (isClient)
31
+ return res.send([]);
32
+ else {
33
+ const { page } = req.query;
34
+ const limit = 20;
35
+ const list = yield query(`
36
+ SELECT [C].[ID], [C].[NAME],
37
+ [CM].[DATE], [CM].[TEXT],
38
+ CASE WHEN [CM].[READ] = FALSE AND [CM].[ID SENDER] = [CM].[ID CLIENTE] THEN 0
39
+ ELSE 1 END AS [READ]
40
+ FROM [CLIENTE] AS [C]
41
+ LEFT JOIN (
42
+ SELECT *, ROW_NUMBER() OVER (PARTITION BY [ID CLIENTE] ORDER BY [DATE] DESC) AS [ROW]
43
+ FROM [CHAT MESSAGE]
44
+ ) AS [CM] ON [CM].[ID CLIENTE] = [C].[ID] AND [CM].[ROW] = 1
45
+ ORDER BY CASE WHEN [CM].[DATE] IS NULL THEN 1 ELSE 0 END, [CM].[DATE] DESC
46
+ LIMIT ? OFFSET ?
47
+ `, [limit, limit * page]);
48
+ res.send(list);
49
+ }
50
+ });
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.conversationRoute = void 0;
24
+ const getRoom_1 = require("../utils/getRoom");
25
+ const conversationRoute = (_a) => {
26
+ var { router, err } = _a, params = __rest(_a, ["router", "err"]);
27
+ router.post('/conversation/socket', (req, res) => socketConversation(req, res, params).catch((error) => err(req, res, error)));
28
+ };
29
+ exports.conversationRoute = conversationRoute;
30
+ const socketConversation = (req, res, { isClient }) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const { idCliente } = req.body;
32
+ const ioEmitter = req.app.get('socketIo');
33
+ const room = (0, getRoom_1.getRoom)(isClient, idCliente);
34
+ ioEmitter.sockets.in(room).emit('message', req.body);
35
+ res.send({ status: 'ok' });
36
+ });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chatExposed = void 0;
4
+ const conversation_1 = require("./conversation");
5
+ const chatExposed = (params) => {
6
+ (0, conversation_1.conversationRoute)(params);
7
+ };
8
+ exports.chatExposed = chatExposed;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.chat = void 0;
7
+ const socket_io_1 = __importDefault(require("socket.io"));
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const getRoom_1 = require("./utils/getRoom");
10
+ const index_1 = require("../index");
11
+ const chat = ({ server, app, verify_access_token, tokenExposed, backendExtremeUrl, frontendUrl, isClient }) => {
12
+ // @ts-ignore
13
+ const io = (0, socket_io_1.default)(server, {
14
+ cors: {
15
+ origin: frontendUrl,
16
+ },
17
+ });
18
+ app.set('socketIo', io);
19
+ io.use((socket, next) => {
20
+ socket.session = {};
21
+ verify_access_token(socket.handshake.query.token, socket.session, null, null, next);
22
+ }).on('connection', (socket) => {
23
+ const room = (0, getRoom_1.getRoom)(isClient, socket.session.userid);
24
+ socket.join(room);
25
+ socket.on('news', (data) => {
26
+ data.idSender = socket.session.userid;
27
+ data.date = new Date();
28
+ if (isClient)
29
+ data.idCliente = socket.session.userid;
30
+ socket.broadcast.to(room).emit('message', data);
31
+ axios_1.default
32
+ .post(backendExtremeUrl + '/exposed/chat/conversation/socket', data, {
33
+ headers: {
34
+ token: tokenExposed,
35
+ },
36
+ })
37
+ .catch((error) => (0, index_1.err)(null, null, error));
38
+ });
39
+ });
40
+ };
41
+ exports.chat = chat;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRoom = void 0;
4
+ const getRoom = (isClient, idClient = null) => {
5
+ if (!isClient)
6
+ return 'room-all';
7
+ else
8
+ return 'room-' + idClient;
9
+ };
10
+ exports.getRoom = getRoom;
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTranslation = exports.LANGUAGES = exports.translate = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
3
+ exports.chatExposed = exports.chatApi = exports.chat = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
4
4
  const sendNotification_1 = require("./sendNotification");
5
5
  Object.defineProperty(exports, "sendNotification", { enumerable: true, get: function () { return sendNotification_1.sendNotification; } });
6
6
  const sleep_1 = require("./sleep");
@@ -18,3 +18,9 @@ const translation_1 = require("./translation");
18
18
  Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return translation_1.translate; } });
19
19
  Object.defineProperty(exports, "LANGUAGES", { enumerable: true, get: function () { return translation_1.LANGUAGES; } });
20
20
  Object.defineProperty(exports, "useTranslation", { enumerable: true, get: function () { return translation_1.useTranslation; } });
21
+ const chat_1 = require("./chat");
22
+ Object.defineProperty(exports, "chat", { enumerable: true, get: function () { return chat_1.chat; } });
23
+ const api_1 = require("./chat/api");
24
+ Object.defineProperty(exports, "chatApi", { enumerable: true, get: function () { return api_1.chatApi; } });
25
+ const exposed_1 = require("./chat/exposed");
26
+ Object.defineProperty(exports, "chatExposed", { enumerable: true, get: function () { return exposed_1.chatExposed; } });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.en = void 0;
4
+ const en = {
5
+ 'Archivo adjunto': 'Attached file',
6
+ Audio: 'Audio',
7
+ };
8
+ exports.en = en;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.es = void 0;
4
+ const es = {
5
+ 'Archivo adjunto': 'Archivo adjunto',
6
+ Audio: 'Audio',
7
+ };
8
+ exports.es = es;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fr = void 0;
4
+ const fr = {
5
+ 'Archivo adjunto': 'Pièce jointe',
6
+ Audio: 'Audio',
7
+ };
8
+ exports.fr = fr;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.t = void 0;
4
+ const common_1 = require("@runnerpro/common");
5
+ const es_1 = require("./es");
6
+ const en_1 = require("./en");
7
+ const fr_1 = require("./fr");
8
+ const it_1 = require("./it");
9
+ const t = (key, language) => {
10
+ if (language === common_1.LANGUAGES.ES)
11
+ return es_1.es[key] || key;
12
+ if (language === common_1.LANGUAGES.FR)
13
+ return fr_1.fr[key] || key;
14
+ if (language === common_1.LANGUAGES.IT)
15
+ return it_1.it[key] || key;
16
+ return en_1.en[key] || key;
17
+ };
18
+ exports.t = t;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.it = void 0;
4
+ const it = {
5
+ 'Archivo adjunto': 'File allegato',
6
+ Audio: 'Audio',
7
+ };
8
+ exports.it = it;
@@ -0,0 +1,3 @@
1
+ declare const conversationRoute: ({ router, ...params }: any) => void;
2
+ export { conversationRoute };
3
+ //# sourceMappingURL=conversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAiBpD,CAAC;AAkQF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const chatApi: (params: any) => void;
2
+ export { chatApi };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/index.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,OAAO,uBAGZ,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare const listConversationsRoute: ({ router, err, ...params }: {
2
+ [x: string]: any;
3
+ router: any;
4
+ err: any;
5
+ }) => void;
6
+ export { listConversationsRoute };
7
+ //# sourceMappingURL=listConversations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listConversations.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/listConversations.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,sBAAsB;;;;UAE3B,CAAC;AA6BF,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare const conversationRoute: ({ router, err, ...params }: {
2
+ [x: string]: any;
3
+ router: any;
4
+ err: any;
5
+ }) => void;
6
+ export { conversationRoute };
7
+ //# sourceMappingURL=conversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/exposed/conversation.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,iBAAiB;;;;UAEtB,CAAC;AAUF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const chatExposed: (params: any) => void;
2
+ export { chatExposed };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/chat/exposed/index.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,WAAW,uBAEhB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ declare const chat: ({ server, app, verify_access_token, tokenExposed, backendExtremeUrl, frontendUrl, isClient }: {
2
+ server: any;
3
+ app: any;
4
+ verify_access_token: any;
5
+ tokenExposed: any;
6
+ backendExtremeUrl: any;
7
+ frontendUrl: any;
8
+ isClient: any;
9
+ }) => void;
10
+ export { chat };
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/chat/index.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,IAAI;;;;;;;;UA8BT,CAAC;AAEF,OAAO,EAAE,IAAI,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const getRoom: (isClient: any, idClient?: any) => string;
2
+ export { getRoom };
3
+ //# sourceMappingURL=getRoom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRoom.d.ts","sourceRoot":"","sources":["../../../../../src/chat/utils/getRoom.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,2CAGZ,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -5,5 +5,8 @@ import { sendMail } from './sendMail';
5
5
  import { err } from './err';
6
6
  import { fetchIA } from './fetch/fetchIA';
7
7
  import { translate, LANGUAGES, useTranslation } from './translation';
8
- export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, useTranslation, };
8
+ import { chat } from './chat';
9
+ import { chatApi } from './chat/api';
10
+ import { chatExposed } from './chat/exposed';
11
+ export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, useTranslation, chat, chatApi, chatExposed };
9
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,GAAG,EACH,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,GACf,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const en: {
2
+ 'Archivo adjunto': string;
3
+ Audio: string;
4
+ };
5
+ export { en };
6
+ //# sourceMappingURL=en.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../../../src/locale/en.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,EAAE;;;CAGP,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const es: {
2
+ 'Archivo adjunto': string;
3
+ Audio: string;
4
+ };
5
+ export { es };
6
+ //# sourceMappingURL=es.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"es.d.ts","sourceRoot":"","sources":["../../../../src/locale/es.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,EAAE;;;CAGP,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const fr: {
2
+ 'Archivo adjunto': string;
3
+ Audio: string;
4
+ };
5
+ export { fr };
6
+ //# sourceMappingURL=fr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fr.d.ts","sourceRoot":"","sources":["../../../../src/locale/fr.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,EAAE;;;CAGP,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const t: (key: any, language: any) => any;
2
+ export { t };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/locale/index.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,CAAC,kCAKN,CAAC;AAEF,OAAO,EAAE,CAAC,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const it: {
2
+ 'Archivo adjunto': string;
3
+ Audio: string;
4
+ };
5
+ export { it };
6
+ //# sourceMappingURL=it.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"it.d.ts","sourceRoot":"","sources":["../../../../src/locale/it.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,EAAE;;;CAGP,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"
@@ -54,13 +54,18 @@
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@parse/node-apn": "6.0.1",
57
+ "@runnerpro/common": "^1.2.10",
57
58
  "axios": "^1.6.7",
58
59
  "nodemailer": "6.9.9",
59
- "@runnerpro/common": "^1.2.10",
60
- "pg": "8.11.3"
60
+ "pg": "8.11.3",
61
+ "jimp": "^0.22.10"
61
62
  },
62
63
  "dependencies": {
63
- "@google-cloud/translate": "^8.3.0"
64
+ "@google-cloud/translate": "^8.3.0",
65
+ "exifr": "^7.1.3",
66
+ "image-size": "^1.0.2",
67
+ "multer": "^1.4.5-lts.1",
68
+ "socket.io": "^4.7.2"
64
69
  }
65
70
  }
66
71