@runnerpro/backend 1.1.9 → 1.1.10

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,135 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getLetter = exports.getNumberByLetter = exports.writeSheet = exports.findCellByValue = exports.readSheet = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const googleapis_1 = require("googleapis");
18
+ const fs_1 = __importDefault(require("fs"));
19
+ const err_1 = require("../err");
20
+ // @ts-ignore
21
+ const credentials = JSON.parse(fs_1.default.readFileSync(path_1.default.join(process.cwd(), process.env.FIREBASE_ADMIN_CREDENTIALS)));
22
+ // ID de la hoja viene en la URL -> https://docs.google.com/spreadsheets/d/{__ID__}/edit#gid=0
23
+ const googleSheeIds = {
24
+ INFLUENCER: '1Uv5Prbjo4h0X74WzaGryKsEbnRX_QM8z0DGYZnvSJ-4',
25
+ NORTH_STAR: '1RkLAXb8iH-QKQ1MAeUZLpBN2lWvab4GMZkKbG-DNv64',
26
+ INFLUENCER_BUTTON: '1wSxtowC1yUUgkYDKhY_Wci6nZeYz13PiZuA7H_1tRfs',
27
+ };
28
+ // authenticate the service account
29
+ const googleAuth = new googleapis_1.google.auth.JWT(credentials.client_email, null, credentials.private_key.replace(/\\n/g, '\n'), 'https://www.googleapis.com/auth/spreadsheets');
30
+ const getSheetInstance = () => __awaiter(void 0, void 0, void 0, function* () {
31
+ return googleapis_1.google.sheets({ version: 'v4', auth: googleAuth });
32
+ });
33
+ function readSheet({ sheetInstance, sheetName, sheetPage, cellPositionStart, cellPositionEnd }) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ if (!sheetInstance)
37
+ sheetInstance = yield getSheetInstance();
38
+ const infoObjectFromSheet = yield sheetInstance.spreadsheets.values.get({
39
+ auth: googleAuth,
40
+ spreadsheetId: googleSheeIds[sheetName],
41
+ range: `${sheetPage}!${cellPositionStart}:${cellPositionEnd}`,
42
+ });
43
+ return infoObjectFromSheet.data.values;
44
+ }
45
+ catch (error) {
46
+ (0, err_1.err)('readSheet func() error', error, null, null);
47
+ }
48
+ });
49
+ }
50
+ exports.readSheet = readSheet;
51
+ const findCellByValue = ({ sheetName, sheetPage, value, positionX, positionXStart, positionY, positionYStart, valueType }) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const sheetInstance = yield getSheetInstance();
53
+ let array = [];
54
+ if (positionX) {
55
+ const readColumn = yield readSheet({
56
+ sheetInstance,
57
+ sheetName,
58
+ sheetPage,
59
+ cellPositionStart: `${positionX}${positionYStart || 1}`,
60
+ cellPositionEnd: `${positionX}${(positionYStart || 1) + 2000}`,
61
+ });
62
+ if (readColumn)
63
+ array = readColumn.map((row) => row[0] || '');
64
+ }
65
+ else {
66
+ const readRow = yield readSheet({
67
+ sheetInstance,
68
+ sheetName,
69
+ sheetPage,
70
+ cellPositionStart: `${positionXStart || 'A'}${positionY}`,
71
+ cellPositionEnd: `ZZ${positionY}`,
72
+ });
73
+ if (readRow && readRow[0])
74
+ array = readRow[0];
75
+ }
76
+ let index;
77
+ if (valueType === 'CONTAIN')
78
+ index = array.findIndex((cell) => cell.includes(value));
79
+ // @ts-ignore
80
+ else
81
+ index = array.indexOf(value);
82
+ if (index === -1)
83
+ return -1;
84
+ if (positionX)
85
+ return `${positionX}:${(positionYStart || 1) + index}`;
86
+ else
87
+ return `${getLetter((getNumberByLetter(positionXStart) || 1) + index)}:${positionY}`;
88
+ });
89
+ exports.findCellByValue = findCellByValue;
90
+ // funcion que pasandolee un numero te devuelve la letra de la columna excel (teniendo en cuenta que la A es la 1 y que la AA es la 27)
91
+ function getLetter(number) {
92
+ let letter = '';
93
+ if (number > 26) {
94
+ letter += String.fromCharCode(64 + Math.floor(number / 26)); // Agregar el cociente entero
95
+ number = number % 26;
96
+ if (number === 0) {
97
+ // Manejar el caso especial cuando el número es divisible por 26
98
+ letter = String.fromCharCode(letter.charCodeAt(0) - 1); // Restar 1 a la letra
99
+ number = 26; // Establecer el número a 26
100
+ }
101
+ }
102
+ letter += String.fromCharCode(64 + number);
103
+ return letter;
104
+ }
105
+ exports.getLetter = getLetter;
106
+ // funcion que pasandole unas letras de la columna de excel te devuelve el numero de la columna (teniendo en cuenta que la A es la 1 y que la AA es la 27)
107
+ function getNumberByLetter(letter) {
108
+ if (!letter)
109
+ return 1;
110
+ let number = 0;
111
+ for (let i = 0; i < letter.length; i++) {
112
+ number += (letter.charCodeAt(i) - 64) * Math.pow(26, letter.length - i - 1);
113
+ }
114
+ return number;
115
+ }
116
+ exports.getNumberByLetter = getNumberByLetter;
117
+ const writeSheet = ({ sheetInstance, sheetName, sheetPage, cellValue, cellPosition }) => __awaiter(void 0, void 0, void 0, function* () {
118
+ try {
119
+ if (!sheetInstance)
120
+ sheetInstance = yield getSheetInstance();
121
+ yield sheetInstance.spreadsheets.values.update({
122
+ auth: googleAuth,
123
+ spreadsheetId: googleSheeIds[sheetName],
124
+ range: `${sheetPage}!${cellPosition}:${cellPosition}`,
125
+ valueInputOption: 'RAW',
126
+ resource: {
127
+ values: [[cellValue]],
128
+ },
129
+ });
130
+ }
131
+ catch (error) {
132
+ (0, err_1.err)('updateSheet func() error', error, null, null);
133
+ }
134
+ });
135
+ exports.writeSheet = writeSheet;
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
3
+ exports.getLetter = exports.getNumberByLetter = exports.writeSheet = exports.findCellByValue = exports.readSheet = exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = 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");
@@ -30,3 +30,9 @@ Object.defineProperty(exports, "notionGetDatabase", { enumerable: true, get: fun
30
30
  Object.defineProperty(exports, "notionAddPage", { enumerable: true, get: function () { return notion_1.notionAddPage; } });
31
31
  Object.defineProperty(exports, "notionEditPage", { enumerable: true, get: function () { return notion_1.notionEditPage; } });
32
32
  Object.defineProperty(exports, "NOTION_DATABASES_ID", { enumerable: true, get: function () { return notion_1.NOTION_DATABASES_ID; } });
33
+ const googleSheet_1 = require("./googleSheet");
34
+ Object.defineProperty(exports, "readSheet", { enumerable: true, get: function () { return googleSheet_1.readSheet; } });
35
+ Object.defineProperty(exports, "findCellByValue", { enumerable: true, get: function () { return googleSheet_1.findCellByValue; } });
36
+ Object.defineProperty(exports, "writeSheet", { enumerable: true, get: function () { return googleSheet_1.writeSheet; } });
37
+ Object.defineProperty(exports, "getNumberByLetter", { enumerable: true, get: function () { return googleSheet_1.getNumberByLetter; } });
38
+ Object.defineProperty(exports, "getLetter", { enumerable: true, get: function () { return googleSheet_1.getLetter; } });
@@ -0,0 +1,28 @@
1
+ declare function readSheet({ sheetInstance, sheetName, sheetPage, cellPositionStart, cellPositionEnd }: {
2
+ sheetInstance: any;
3
+ sheetName: any;
4
+ sheetPage: any;
5
+ cellPositionStart: any;
6
+ cellPositionEnd: any;
7
+ }): Promise<any>;
8
+ declare const findCellByValue: ({ sheetName, sheetPage, value, positionX, positionXStart, positionY, positionYStart, valueType }: {
9
+ sheetName: any;
10
+ sheetPage: any;
11
+ value: any;
12
+ positionX: any;
13
+ positionXStart: any;
14
+ positionY: any;
15
+ positionYStart: any;
16
+ valueType: any;
17
+ }) => Promise<string | -1>;
18
+ declare function getLetter(number: any): string;
19
+ declare function getNumberByLetter(letter: any): number;
20
+ declare const writeSheet: ({ sheetInstance, sheetName, sheetPage, cellValue, cellPosition }: {
21
+ sheetInstance: any;
22
+ sheetName: any;
23
+ sheetPage: any;
24
+ cellValue: any;
25
+ cellPosition: any;
26
+ }) => Promise<void>;
27
+ export { readSheet, findCellByValue, writeSheet, getNumberByLetter, getLetter, };
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/googleSheet/index.ts"],"names":[],"mappings":"AA2BA,iBAAe,SAAS,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,EAAE;;;;;;CAAA,gBAcnG;AAED,QAAA,MAAM,eAAe;;;;;;;;;0BAgCpB,CAAC;AAGF,iBAAS,SAAS,CAAC,MAAM,KAAA,UAaxB;AAED,iBAAS,iBAAiB,CAAC,MAAM,KAAA,UAOhC;AAED,QAAA,MAAM,UAAU;;;;;;mBAgBf,CAAC;AAEF,OAAO,EACL,SAAS,EACT,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,SAAS,GACV,CAAC"}
@@ -7,5 +7,6 @@ import { fetchIA } from './fetch/fetchIA';
7
7
  import { translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription } from './translation';
8
8
  import { chat, chatApi, chatExposed, getCountNotificaciones } from './chat';
9
9
  import { notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID } from './notion';
10
- export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, };
10
+ import { readSheet, findCellByValue, writeSheet, getNumberByLetter, getLetter } from './googleSheet';
11
+ export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, readSheet, findCellByValue, writeSheet, getNumberByLetter, getLetter, };
11
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,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,IAAI,EAAE,OAAO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EACV,QAAQ,EACR,GAAG,EACH,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,EACd,gCAAgC,EAChC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,SAAS,GACV,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"
@@ -63,6 +63,7 @@
63
63
  "@google-cloud/translate": "^8.3.0",
64
64
  "@notionhq/client": "^2.2.15",
65
65
  "exifr": "^7.1.3",
66
+ "googleapis": "^144.0.0",
66
67
  "image-size": "^1.0.2",
67
68
  "multer": "^1.4.5-lts.1",
68
69
  "socket.io": "^4.7.2"