plenna_utilities 1.7.0 → 1.7.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/dist/index.d.ts CHANGED
@@ -7,3 +7,4 @@ export * from './src/customerio';
7
7
  export * from './src/mailer';
8
8
  export * from './src/airTable';
9
9
  export * from './src/alerts/presenter';
10
+ export * from './src/common/domain/shared';
package/dist/index.js CHANGED
@@ -28,3 +28,4 @@ __exportStar(require("./src/customerio"), exports);
28
28
  __exportStar(require("./src/mailer"), exports);
29
29
  __exportStar(require("./src/airTable"), exports);
30
30
  __exportStar(require("./src/alerts/presenter"), exports);
31
+ __exportStar(require("./src/common/domain/shared"), exports);
@@ -36,12 +36,14 @@ export interface ITemplatesConfiguration {
36
36
  export interface AlertTemplateInput {
37
37
  template?: string;
38
38
  date?: string;
39
+ reportDate?: string;
39
40
  text?: string;
40
41
  bookingUser?: string;
41
42
  channel?: string;
42
43
  origin?: string;
43
44
  huliId?: string;
44
45
  threadTs?: string;
46
+ toDo?: string;
45
47
  }
46
48
  export interface AlertResponse {
47
49
  channel: string;
@@ -14,12 +14,10 @@ class SendAlertUseCase {
14
14
  try {
15
15
  const [input] = args;
16
16
  const alertData = input;
17
- if (alertData?.origin === null || alertData?.origin === undefined)
18
- return;
19
- if (alertData?.channel !== '' && alertData?.channel !== undefined) {
17
+ if ((0, interpolation_transformer_1.isNonEmpty)(alertData?.channel) || !(0, interpolation_transformer_1.isNonEmpty)(alertData?.template)) {
20
18
  const alert = {
21
- channel: alertData.channel ?? '',
22
- text: alertData.text ?? '',
19
+ channel: alertData?.channel ?? '',
20
+ text: alertData?.text ?? '',
23
21
  threadTs: alertData?.threadTs
24
22
  };
25
23
  return await this.alertService.sendAlert(alert);
@@ -31,6 +29,9 @@ class SendAlertUseCase {
31
29
  const templateInfo = getConfiguration.templates[templateKey];
32
30
  if (templateInfo === null && templateInfo === undefined)
33
31
  throw new Error('template not found');
32
+ templateInfo.channel = (0, interpolation_transformer_1.isNonEmpty)(alertData?.channel)
33
+ ? alertData.channel ?? ''
34
+ : templateInfo.channel;
34
35
  if (templateInfo.blocks !== undefined) {
35
36
  templateInfo.blocks.forEach((block) => {
36
37
  if (block.type === 'section' && block.fields != null) {
@@ -0,0 +1,4 @@
1
+ export declare const formatDate: (isoDate: string) => string;
2
+ export declare const formatHour: (time24: string) => string;
3
+ export declare const getDifferenceInMinutes: (startTime: string, endTime: string) => number;
4
+ export declare const formatIsoDateToSpanish: (isoString: string) => string;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatIsoDateToSpanish = exports.getDifferenceInMinutes = exports.formatHour = exports.formatDate = void 0;
4
+ const formatDate = (isoDate) => {
5
+ const [year, month, day] = isoDate.split('-').map(Number);
6
+ const fecha = new Date(year, month - 1, day);
7
+ return fecha.toLocaleDateString('es-MX', {
8
+ day: 'numeric',
9
+ month: 'long',
10
+ year: 'numeric'
11
+ });
12
+ };
13
+ exports.formatDate = formatDate;
14
+ const formatHour = (time24) => {
15
+ const [hours, minutes, seconds] = time24.split(':').map(Number);
16
+ const date = new Date();
17
+ date.setHours(hours, minutes, seconds);
18
+ let formatted = date.toLocaleTimeString('es-MX', {
19
+ hour: 'numeric',
20
+ minute: '2-digit',
21
+ hour12: true
22
+ });
23
+ if (formatted.startsWith('0:')) {
24
+ formatted = formatted.replace('0:', '12:');
25
+ }
26
+ return formatted;
27
+ };
28
+ exports.formatHour = formatHour;
29
+ const getDifferenceInMinutes = (startTime, endTime) => {
30
+ const [h1, m1, s1] = startTime.split(':').map(Number);
31
+ const [h2, m2, s2] = endTime.split(':').map(Number);
32
+ const startDate = new Date();
33
+ startDate.setHours(h1, m1, s1, 0);
34
+ const endDate = new Date();
35
+ endDate.setHours(h2, m2, s2, 0);
36
+ const diffMs = endDate.getTime() - startDate.getTime();
37
+ return Math.floor(diffMs / 60000);
38
+ };
39
+ exports.getDifferenceInMinutes = getDifferenceInMinutes;
40
+ const formatIsoDateToSpanish = (isoString) => {
41
+ const date = new Date(isoString);
42
+ return date.toLocaleDateString('es-MX', {
43
+ day: 'numeric',
44
+ month: 'long',
45
+ year: 'numeric',
46
+ timeZone: 'America/Mexico_City'
47
+ });
48
+ };
49
+ exports.formatIsoDateToSpanish = formatIsoDateToSpanish;
@@ -0,0 +1,2 @@
1
+ export * from './date.transformer';
2
+ export * from './interpolation.transformer';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./date.transformer"), exports);
18
+ __exportStar(require("./interpolation.transformer"), exports);
@@ -1,2 +1,3 @@
1
1
  import { type AlertTemplateInput, type FieldObject } from '../../../alerts/domain/interfaces/alerts';
2
2
  export declare function interpolateFields(fields: FieldObject[], input: AlertTemplateInput): FieldObject[];
3
+ export declare const isNonEmpty: (value?: string) => boolean;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNonEmpty = void 0;
3
4
  exports.interpolateFields = interpolateFields;
4
5
  function interpolateFields(fields, input) {
5
6
  return fields.map((field) => {
@@ -11,3 +12,5 @@ function interpolateFields(fields, input) {
11
12
  return { ...field, text };
12
13
  });
13
14
  }
15
+ const isNonEmpty = (value) => { return value !== '' && value !== undefined; };
16
+ exports.isNonEmpty = isNonEmpty;
@@ -1,7 +1,7 @@
1
1
  templates:
2
2
  noInfo:
3
3
  channel: 'C08S575SWCF'
4
- text: 'Alerta !!!'
4
+ text: '🚨 Error de Agenda'
5
5
  blocks:
6
6
  - type: header
7
7
  text:
@@ -11,20 +11,20 @@ templates:
11
11
  - type: section
12
12
  text:
13
13
  type: mrkdwn
14
- text: '*Motivo:* Se ha creado una agenda con información erronea!!'
14
+ text: '*Motivo:* Se creó una cita en Huli con información errónea, por lo que esta agenda no es válida.'
15
15
  fields:
16
16
  - type: mrkdwn
17
17
  text: "*ID de cita en Huli:*\n{huliId}"
18
18
  - type: mrkdwn
19
19
  text: "*Persona que intentó agendar:*\n<{bookingUser}>"
20
20
  - type: mrkdwn
21
- text: "*¿Qué pasó?:*\n{text}"
21
+ text: "*Fecha y hora de la cita:*\n{date}"
22
22
  - type: mrkdwn
23
- text: "*¿Qué debes hacer?:*\ncancelar y volver a crear la cita correctamente."
23
+ text: "*¿Qué pasó?:*\n{text}"
24
24
  - type: mrkdwn
25
- text: "*Fecha:*\n{date}"
25
+ text: "*¿Qué debes hacer?:*\n{toDo}"
26
26
  - type: mrkdwn
27
- text: "*Origen:*\n{origin}"
27
+ text: "*Fecha de reporte:*\n{reportDate}"
28
28
  - type: divider
29
29
  - type: context
30
30
  elements:
@@ -5,4 +5,3 @@ export declare const getAge: (date: Date) => string;
5
5
  export declare const getDeltaTime: (start: Date, end: Date) => number;
6
6
  export declare const getMonthDifference: (startDate: Date, endDate: Date) => number;
7
7
  export declare const addWorkDays: (startDate: Date, days: number) => Date;
8
- export declare const helloTime: () => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.helloTime = exports.addWorkDays = exports.getMonthDifference = exports.getDeltaTime = exports.getAge = exports.compare = exports.isValidNumeric = exports.fixAppointmentDateStart = void 0;
3
+ exports.addWorkDays = exports.getMonthDifference = exports.getDeltaTime = exports.getAge = exports.compare = exports.isValidNumeric = exports.fixAppointmentDateStart = void 0;
4
4
  const fixAppointmentDateStart = (date, start) => {
5
5
  const [hour, minutes] = start.split(':');
6
6
  const fixedDate = new Date(date).setUTCHours(parseInt(hour ?? 0) + 6, parseInt(minutes ?? 0));
@@ -47,7 +47,3 @@ const addWorkDays = (startDate, days) => {
47
47
  return targetDate;
48
48
  };
49
49
  exports.addWorkDays = addWorkDays;
50
- const helloTime = () => {
51
- console.log('hola');
52
- };
53
- exports.helloTime = helloTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plenna_utilities",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "plenna's utils for backend projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",