@runnerpro/backend 1.1.14 → 1.2.1

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,102 @@
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.facebookPixel = exports.FACEBOOK_ACTION_SOURCE = exports.FACEBOOK_EVENT_NAME = exports.FACEBOOK_PIXEL_ID = void 0;
16
+ const facebook_nodejs_business_sdk_1 = __importDefault(require("facebook-nodejs-business-sdk"));
17
+ const ServerEvent = facebook_nodejs_business_sdk_1.default.ServerEvent;
18
+ const EventRequest = facebook_nodejs_business_sdk_1.default.EventRequest;
19
+ const UserData = facebook_nodejs_business_sdk_1.default.UserData;
20
+ const CustomData = facebook_nodejs_business_sdk_1.default.CustomData;
21
+ const FACEBOOK_PIXEL_ID = {
22
+ LANDING_PRUEBA_7_DIAS: '336438398867114',
23
+ LANDING_HTML: '312592961834318',
24
+ };
25
+ exports.FACEBOOK_PIXEL_ID = FACEBOOK_PIXEL_ID;
26
+ const FACEBOOK_TOKEN = {
27
+ 336438398867114: 'EAATqRkCVDPQBO1O2ZAStRkyQgiSzs12JYbEXeAClZCFpW9SJGJz2co0m1QcFMwQJvHPHzCmX9FDndWY11Cgmlmvem2ZB36IvDekEejDsmIGboRxbm1LagLik5DrTSr0CTARfi2oSMaRK062bNoTRP4QMRU6p799yDVBtmveQ068Tvs9DSJp2sLpli3WFWL8HQZDZD',
28
+ 312592961834318: 'EAATqRkCVDPQBO92Ls4A4lp0ZB7GTfy4rctQYI6KoIGsvpyPOnPZBF8CUs7ZBEsfrC78Mw1fZCXLzyvc2dxZBajavYrfy1FRvCImiarFyyY0GmIA9UVQFvtGNsI002t3psiBMiXZBiJiw0n5RBHWCT9ncbD6aQL5iw2v8a8Ce8YZBZCmxampxLPvWCy5YDTtn5PuPDQZDZD',
29
+ };
30
+ const FACEBOOK_EVENT_NAME = {
31
+ PAGE_VIEW: 'PageView',
32
+ LEAD: 'Lead',
33
+ PURCHASE: 'Purchase',
34
+ ADD_TO_CART: 'AddToCart',
35
+ INITIATE_CHECKOUT: 'InitiateCheckout',
36
+ COMPLETE_REGISTRATION: 'CompleteRegistration',
37
+ SEARCH: 'Search',
38
+ VIEW_CONTENT: 'ViewContent',
39
+ CONTACT: 'Contact',
40
+ CUSTOMIZE_PRODUCT: 'CustomizeProduct',
41
+ DONATE: 'Donate',
42
+ FIND_LOCATION: 'FindLocation',
43
+ SCHEDULE: 'Schedule',
44
+ START_TRIAL: 'StartTrial',
45
+ SUBMIT_APPLICATION: 'SubmitApplication',
46
+ SUBSCRIBE: 'Subscribe',
47
+ };
48
+ exports.FACEBOOK_EVENT_NAME = FACEBOOK_EVENT_NAME;
49
+ const FACEBOOK_ACTION_SOURCE = {
50
+ WEBSITE: 'website',
51
+ APP: 'app',
52
+ PHONE: 'phone_call',
53
+ CHAT: 'chat',
54
+ EMAIL: 'email',
55
+ SYSTEM_GENERATED: 'system_generated',
56
+ PHYSICAL_STORE: 'physical_store',
57
+ OTHER: 'other',
58
+ };
59
+ exports.FACEBOOK_ACTION_SOURCE = FACEBOOK_ACTION_SOURCE;
60
+ const facebookPixel = ({ req, pixelId, eventName, actionSource, email, valuePurchase }) => __awaiter(void 0, void 0, void 0, function* () {
61
+ if (process.env.NODE_ENV !== 'PROD')
62
+ return;
63
+ const access_token = FACEBOOK_TOKEN[pixelId];
64
+ // @ts-ignore
65
+ const current_timestamp = Math.floor(new Date() / 1000);
66
+ const userData = new UserData();
67
+ if (req) {
68
+ userData.setClientIpAddress(req.connection.remoteAddress);
69
+ userData.setClientUserAgent(req.headers['user-agent']);
70
+ }
71
+ if (email) {
72
+ userData.setEmail(email);
73
+ }
74
+ const serverEvent = new ServerEvent()
75
+ .setEventName(eventName)
76
+ .setEventTime(current_timestamp)
77
+ .setUserData(userData)
78
+ .setEventSourceUrl(getEventSourceUrlFromID(pixelId))
79
+ .setActionSource(actionSource);
80
+ if (valuePurchase) {
81
+ const customData = new CustomData().setCurrency('eur').setValue(valuePurchase);
82
+ serverEvent.setCustomData(customData);
83
+ }
84
+ const eventRequest1 = new EventRequest(access_token, pixelId).setEvents([serverEvent]);
85
+ try {
86
+ yield eventRequest1.execute();
87
+ }
88
+ catch (e) {
89
+ // eslint-disable-next-line no-console
90
+ console.error(e);
91
+ }
92
+ });
93
+ exports.facebookPixel = facebookPixel;
94
+ const getEventSourceUrlFromID = (pixelId) => {
95
+ if (pixelId === FACEBOOK_PIXEL_ID.LANDING_PRUEBA_7_DIAS) {
96
+ return 'https://landing.runnerpro.app/prueba-7-dias';
97
+ }
98
+ if (pixelId === FACEBOOK_PIXEL_ID.LANDING_HTML) {
99
+ return 'https://landing.runnerpro.app/';
100
+ }
101
+ return null;
102
+ };
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLetter = exports.getNumberByLetter = exports.appendSheet = 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;
3
+ exports.facebookPixel = exports.FACEBOOK_ACTION_SOURCE = exports.FACEBOOK_EVENT_NAME = exports.FACEBOOK_PIXEL_ID = exports.getLetter = exports.getNumberByLetter = exports.appendSheet = 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.CHANNEL_SLACK = exports.notifySlack = 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");
@@ -14,6 +14,9 @@ const err_1 = require("./err");
14
14
  Object.defineProperty(exports, "err", { enumerable: true, get: function () { return err_1.err; } });
15
15
  const fetchIA_1 = require("./fetch/fetchIA");
16
16
  Object.defineProperty(exports, "fetchIA", { enumerable: true, get: function () { return fetchIA_1.fetchIA; } });
17
+ const slack_1 = require("./slack");
18
+ Object.defineProperty(exports, "notifySlack", { enumerable: true, get: function () { return slack_1.notifySlack; } });
19
+ Object.defineProperty(exports, "CHANNEL_SLACK", { enumerable: true, get: function () { return slack_1.CHANNEL_SLACK; } });
17
20
  const translation_1 = require("./translation");
18
21
  Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return translation_1.translate; } });
19
22
  Object.defineProperty(exports, "LANGUAGES", { enumerable: true, get: function () { return translation_1.LANGUAGES; } });
@@ -37,3 +40,8 @@ Object.defineProperty(exports, "writeSheet", { enumerable: true, get: function (
37
40
  Object.defineProperty(exports, "appendSheet", { enumerable: true, get: function () { return googleSheet_1.appendSheet; } });
38
41
  Object.defineProperty(exports, "getNumberByLetter", { enumerable: true, get: function () { return googleSheet_1.getNumberByLetter; } });
39
42
  Object.defineProperty(exports, "getLetter", { enumerable: true, get: function () { return googleSheet_1.getLetter; } });
43
+ const facebookPixel_1 = require("./facebookPixel");
44
+ Object.defineProperty(exports, "FACEBOOK_PIXEL_ID", { enumerable: true, get: function () { return facebookPixel_1.FACEBOOK_PIXEL_ID; } });
45
+ Object.defineProperty(exports, "FACEBOOK_EVENT_NAME", { enumerable: true, get: function () { return facebookPixel_1.FACEBOOK_EVENT_NAME; } });
46
+ Object.defineProperty(exports, "FACEBOOK_ACTION_SOURCE", { enumerable: true, get: function () { return facebookPixel_1.FACEBOOK_ACTION_SOURCE; } });
47
+ Object.defineProperty(exports, "facebookPixel", { enumerable: true, get: function () { return facebookPixel_1.facebookPixel; } });
@@ -0,0 +1,28 @@
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.CHANNEL_SLACK = exports.notifySlack = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const notifySlack = ({ text, channel }) => {
9
+ axios_1.default.post('https://hooks.slack.com/services/' + (process.env.NODE_ENV !== 'PROD' ? CHANNEL_SLACK.TEST : channel), {
10
+ text,
11
+ }, {
12
+ headers: {
13
+ 'Content-Type': 'application/json',
14
+ },
15
+ });
16
+ };
17
+ exports.notifySlack = notifySlack;
18
+ /* Para añadir más channels
19
+ 1º Visitar https://api.slack.com/apps/A05QY9W6NJZ/incoming-webhooks?
20
+ 2º Añadir un nuevo webhook
21
+ 3º Copiar el webhook url y añadirlo a CHANNEL
22
+ */
23
+ const CHANNEL_SLACK = {
24
+ COACH: 'T05JCPFMXE0/B05UXA86WLS/RbuCBYuAnX6sedPttFQwkgbB',
25
+ BRUTAL: 'T05JCPFMXE0/B05RDSHESGZ/lHGRox6UiOkioUMHQscap9pA',
26
+ TEST: 'T05JCPFMXE0/B0601LMECSW/RsTOfjgMrxCPIvHAIttjwIPj',
27
+ };
28
+ exports.CHANNEL_SLACK = CHANNEL_SLACK;
@@ -0,0 +1,42 @@
1
+ declare const FACEBOOK_PIXEL_ID: {
2
+ LANDING_PRUEBA_7_DIAS: string;
3
+ LANDING_HTML: string;
4
+ };
5
+ declare const FACEBOOK_EVENT_NAME: {
6
+ PAGE_VIEW: string;
7
+ LEAD: string;
8
+ PURCHASE: string;
9
+ ADD_TO_CART: string;
10
+ INITIATE_CHECKOUT: string;
11
+ COMPLETE_REGISTRATION: string;
12
+ SEARCH: string;
13
+ VIEW_CONTENT: string;
14
+ CONTACT: string;
15
+ CUSTOMIZE_PRODUCT: string;
16
+ DONATE: string;
17
+ FIND_LOCATION: string;
18
+ SCHEDULE: string;
19
+ START_TRIAL: string;
20
+ SUBMIT_APPLICATION: string;
21
+ SUBSCRIBE: string;
22
+ };
23
+ declare const FACEBOOK_ACTION_SOURCE: {
24
+ WEBSITE: string;
25
+ APP: string;
26
+ PHONE: string;
27
+ CHAT: string;
28
+ EMAIL: string;
29
+ SYSTEM_GENERATED: string;
30
+ PHYSICAL_STORE: string;
31
+ OTHER: string;
32
+ };
33
+ declare const facebookPixel: ({ req, pixelId, eventName, actionSource, email, valuePurchase }: {
34
+ req: any;
35
+ pixelId: any;
36
+ eventName: any;
37
+ actionSource: any;
38
+ email: any;
39
+ valuePurchase: any;
40
+ }) => Promise<void>;
41
+ export { FACEBOOK_PIXEL_ID, FACEBOOK_EVENT_NAME, FACEBOOK_ACTION_SOURCE, facebookPixel };
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/facebookPixel/index.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,iBAAiB;;;CAGtB,CAAC;AASF,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;CAiBxB,CAAC;AAEF,QAAA,MAAM,sBAAsB;;;;;;;;;CAS3B,CAAC;AAEF,QAAA,MAAM,aAAa;;;;;;;mBAmClB,CAAC;AAYF,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,aAAa,EAAE,CAAC"}
@@ -4,9 +4,11 @@ import { query, batchQuery } from './db';
4
4
  import { sendMail } from './sendMail';
5
5
  import { err } from './err';
6
6
  import { fetchIA } from './fetch/fetchIA';
7
+ import { notifySlack, CHANNEL_SLACK } from './slack';
7
8
  import { translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription } from './translation';
8
9
  import { chat, chatApi, chatExposed, getCountNotificaciones } from './chat';
9
10
  import { notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID } from './notion';
10
11
  import { readSheet, findCellByValue, writeSheet, appendSheet, 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, appendSheet, getNumberByLetter, getLetter, };
12
+ import { FACEBOOK_PIXEL_ID, FACEBOOK_EVENT_NAME, FACEBOOK_ACTION_SOURCE, facebookPixel } from './facebookPixel';
13
+ export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, notifySlack, CHANNEL_SLACK, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, readSheet, findCellByValue, writeSheet, appendSheet, getNumberByLetter, getLetter, FACEBOOK_PIXEL_ID, FACEBOOK_EVENT_NAME, FACEBOOK_ACTION_SOURCE, facebookPixel, };
12
14
  //# 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,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAElH,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,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,WAAW,EACX,iBAAiB,EACjB,SAAS,GACV,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,O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;
5
+ declare const CHANNEL_SLACK: {
6
+ COACH: string;
7
+ BRUTAL: string;
8
+ TEST: string;
9
+ };
10
+ export { notifySlack, CHANNEL_SLACK, };
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/slack/index.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,WAAW;;;UAYhB,CAAC;AAQF,QAAA,MAAM,aAAa;;;;CAIlB,CAAC;AAEF,OAAO,EACL,WAAW,EACX,aAAa,GACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.1.14",
3
+ "version": "1.2.1",
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
+ "facebook-nodejs-business-sdk": "^21.0.5",
66
67
  "googleapis": "^144.0.0",
67
68
  "image-size": "^1.0.2",
68
69
  "multer": "^1.4.5-lts.1",