plenna_utilities 1.12.0 → 1.13.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.
Files changed (58) hide show
  1. package/package.json +2 -1
  2. package/dist/index.d.ts +0 -12
  3. package/dist/index.js +0 -33
  4. package/dist/src/AI/bedrock/index.d.ts +0 -10
  5. package/dist/src/AI/bedrock/index.js +0 -27
  6. package/dist/src/airTable/index.d.ts +0 -21
  7. package/dist/src/airTable/index.js +0 -82
  8. package/dist/src/alerts/application/send-alert-impl.service.d.ts +0 -8
  9. package/dist/src/alerts/application/send-alert-impl.service.js +0 -20
  10. package/dist/src/alerts/domain/interfaces/alerts.d.ts +0 -51
  11. package/dist/src/alerts/domain/interfaces/alerts.js +0 -2
  12. package/dist/src/alerts/domain/services/send-alert.service.d.ts +0 -4
  13. package/dist/src/alerts/domain/services/send-alert.service.js +0 -6
  14. package/dist/src/alerts/domain/usecases/send-alert.usecase.d.ts +0 -9
  15. package/dist/src/alerts/domain/usecases/send-alert.usecase.js +0 -49
  16. package/dist/src/alerts/presenter/index.d.ts +0 -2
  17. package/dist/src/alerts/presenter/index.js +0 -11
  18. package/dist/src/common/custom/types/index.d.ts +0 -4
  19. package/dist/src/common/custom/types/index.js +0 -2
  20. package/dist/src/common/domain/alerts/alerts.d.ts +0 -4
  21. package/dist/src/common/domain/alerts/alerts.js +0 -6
  22. package/dist/src/common/domain/configurations/configurations.d.ts +0 -3
  23. package/dist/src/common/domain/configurations/configurations.js +0 -6
  24. package/dist/src/common/domain/interfaces/products.interfaces.d.ts +0 -3
  25. package/dist/src/common/domain/interfaces/products.interfaces.js +0 -7
  26. package/dist/src/common/domain/interfaces/usecases.interface.d.ts +0 -3
  27. package/dist/src/common/domain/interfaces/usecases.interface.js +0 -2
  28. package/dist/src/common/domain/shared/date.transformer.d.ts +0 -4
  29. package/dist/src/common/domain/shared/date.transformer.js +0 -49
  30. package/dist/src/common/domain/shared/index.d.ts +0 -2
  31. package/dist/src/common/domain/shared/index.js +0 -18
  32. package/dist/src/common/domain/shared/interpolation.transformer.d.ts +0 -3
  33. package/dist/src/common/domain/shared/interpolation.transformer.js +0 -16
  34. package/dist/src/common/infrastructure/slack/slack.d.ts +0 -7
  35. package/dist/src/common/infrastructure/slack/slack.js +0 -37
  36. package/dist/src/common/infrastructure/yaml-converter/configurations/slack.yaml +0 -137
  37. package/dist/src/common/infrastructure/yaml-converter/yaml-converter.d.ts +0 -4
  38. package/dist/src/common/infrastructure/yaml-converter/yaml-converter.js +0 -28
  39. package/dist/src/customerio/index.d.ts +0 -11
  40. package/dist/src/customerio/index.js +0 -63
  41. package/dist/src/general/index.d.ts +0 -3
  42. package/dist/src/general/index.js +0 -41
  43. package/dist/src/general/interfaces.d.ts +0 -4
  44. package/dist/src/general/interfaces.js +0 -2
  45. package/dist/src/google/index.d.ts +0 -38
  46. package/dist/src/google/index.js +0 -118
  47. package/dist/src/google/requestBuilder.d.ts +0 -14
  48. package/dist/src/google/requestBuilder.js +0 -60
  49. package/dist/src/lambdas/index.d.ts +0 -28
  50. package/dist/src/lambdas/index.js +0 -64
  51. package/dist/src/mailer/index.d.ts +0 -9
  52. package/dist/src/mailer/index.js +0 -34
  53. package/dist/src/respira/index.d.ts +0 -65
  54. package/dist/src/respira/index.js +0 -42
  55. package/dist/src/s3/index.d.ts +0 -9
  56. package/dist/src/s3/index.js +0 -44
  57. package/dist/src/time/index.d.ts +0 -7
  58. package/dist/src/time/index.js +0 -49
@@ -1,137 +0,0 @@
1
- templates:
2
- noInfo:
3
- channel: 'C08S575SWCF'
4
- text: '🚨 Error de Agenda'
5
- blocks:
6
- - type: header
7
- text:
8
- type: plain_text
9
- text: '🚨 Error de Agenda'
10
- emoji: true
11
- - type: section
12
- text:
13
- type: mrkdwn
14
- text: '*Motivo:* Se creó una cita en Huli con información errónea, por lo que esta agenda no es válida.'
15
- fields:
16
- - type: mrkdwn
17
- text: "*ID de cita en Huli:*\n{huliId}"
18
- - type: mrkdwn
19
- text: "*Persona que intentó agendar:*\n<{bookingUser}>"
20
- - type: mrkdwn
21
- text: "*Fecha y hora de la cita:*\n{date}"
22
- - type: mrkdwn
23
- text: "*¿Qué pasó?:*\n{text}"
24
- - type: mrkdwn
25
- text: "*¿Qué debes hacer?:*\n{toDo}"
26
- - type: mrkdwn
27
- text: "*Fecha de reporte:*\n{reportDate}"
28
- - type: divider
29
- - type: context
30
- elements:
31
- - type: mrkdwn
32
- text: 'Generado automáticamente por el sistema de validación de agendas.'
33
-
34
- noAvailableDoctorsSchedule:
35
- channel: 'C09E6K166KH'
36
- text: '🚨 No hay disponibilidad en el calendario de doctores'
37
- blocks:
38
- - type: header
39
- text:
40
- type: plain_text
41
- text: '🚫 La px no encontró disponibilidad en calendario'
42
- emoji: true
43
- - type: divider
44
- - type: section
45
- fields:
46
- - type: mrkdwn
47
- text: "*Servicio:*\n{serviceTitle}"
48
- - type: mrkdwn
49
- text: "*Modalidad:*\n{serviceModality}"
50
- - type: mrkdwn
51
- text: "*Especialidad:*\n{serviceSpecialty}"
52
- - type: mrkdwn
53
- text: "*Plenna Id:*\n{servicePlennaId}"
54
- - type: divider
55
- - type: section
56
- fields:
57
- - type: mrkdwn
58
- text: "*Especialista:*\n{doctorName}"
59
- - type: mrkdwn
60
- text: "*Correo:*\n{doctorEmail}"
61
- - type: mrkdwn
62
- text: "*Clínica:*\n{clinicName}"
63
- - type: mrkdwn
64
- text: "*Última fecha de busqueda:*\n{lastDateSearch}"
65
- - type: divider
66
- - type: section
67
- fields:
68
- - type: mrkdwn
69
- text: "*Paciente:*\n{patientName}"
70
- - type: mrkdwn
71
- text: "*Correo de px:*\n{patientEmail}"
72
- - type: mrkdwn
73
- text: "*Teléfono de paciente:*\n{patientPhone}"
74
- - type: divider
75
- - type: section
76
- text:
77
- type: plain_text
78
- emoji: true
79
- text: '🕵️‍ Verifica que hayan horarios configurados en Huli para esta doctora.'
80
- - type: divider
81
- - type: section
82
- fields:
83
- - type: mrkdwn
84
- text: "*¿Es paciente recurrente?:*\n{isRecurringPatient}"
85
- - type: mrkdwn
86
- text: "*Doctor@ en su health team:*\n{doctorRecurringPatient}"
87
-
88
- patientNeedsACloserAppointment:
89
- channel: 'C09ELN5A92S'
90
- text: '🕒 La paciente busca una cita antes de la programada'
91
- blocks:
92
- - type: header
93
- text:
94
- type: plain_text
95
- text: '🕒 La paciente busca una cita antes de la programada'
96
- emoji: true
97
- - type: divider
98
- - type: section
99
- fields:
100
- - type: mrkdwn
101
- text: "*Paciente:*\n{patientName}"
102
- - type: mrkdwn
103
- text: "*Correo de px:*\n{patientEmail}"
104
- - type: mrkdwn
105
- text: "*Teléfono de paciente:*\n{patientPhone}"
106
- - type: divider
107
- - type: section
108
- fields:
109
- - type: mrkdwn
110
- text: "*Servicio:*\n{serviceTitle}"
111
- - type: mrkdwn
112
- text: "*Modalidad:*\n{serviceModality}"
113
- - type: mrkdwn
114
- text: "*Especialidad:*\n{serviceSpecialty}"
115
- - type: mrkdwn
116
- text: "*Plenna Id:*\n{servicePlennaId}"
117
- - type: divider
118
- - type: section
119
- fields:
120
- - type: mrkdwn
121
- text: "*Especialista de la cita:*\n{doctorName}"
122
- - type: mrkdwn
123
- text: "*Correo de la especialista:*\n{doctorEmail}"
124
- - type: mrkdwn
125
- text: "*Clínica de la cita:*\n{clinicName}"
126
- - type: mrkdwn
127
- text: "*Fecha de la cita:*\n{dateAppointment}"
128
- - type: mrkdwn
129
- text: "*Hora de la cita:*\n{hourAppointment}"
130
- - type: divider
131
- - type: section
132
- fields:
133
- - type: mrkdwn
134
- text: "*¿Es paciente recurrente?:*\n{isRecurringPatient}"
135
- - type: mrkdwn
136
- text: "*Doctor@ en su health team:*\n{doctorRecurringPatient}"
137
-
@@ -1,4 +0,0 @@
1
- import { Configuration } from '../../../common/domain/configurations/configurations';
2
- export declare class ConfigurationYaml extends Configuration {
3
- getConfiguration<T>(product: string, customPath?: string): Promise<T | undefined>;
4
- }
@@ -1,28 +0,0 @@
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.ConfigurationYaml = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const yaml_1 = __importDefault(require("yaml"));
10
- const configurations_1 = require("../../../common/domain/configurations/configurations");
11
- class ConfigurationYaml extends configurations_1.Configuration {
12
- async getConfiguration(product, customPath) {
13
- try {
14
- const finalPath = typeof customPath === 'string' && customPath.trim() !== ''
15
- ? path_1.default.resolve(customPath)
16
- : path_1.default.resolve(__dirname, 'configurations');
17
- const yamlFilePath = path_1.default.join(finalPath, `${product.replace(/ /g, '_').toLocaleLowerCase()}.yaml`);
18
- const yamlContent = fs_1.default.readFileSync(yamlFilePath, 'utf-8');
19
- const yamlObject = yaml_1.default.parse(yamlContent);
20
- return yamlObject;
21
- }
22
- catch (error) {
23
- console.error(`Error loading YAML configuration for ${product}:`, error);
24
- return undefined;
25
- }
26
- }
27
- }
28
- exports.ConfigurationYaml = ConfigurationYaml;
@@ -1,11 +0,0 @@
1
- import { type SendEmailRequestOptions, type SendPushRequestOptions } from 'customerio-node/dist/lib/api/requests';
2
- export type PushRequestOptions = SendPushRequestOptions;
3
- export type EmailRequestOptions = SendEmailRequestOptions;
4
- export declare class CustomerIo {
5
- private readonly key;
6
- constructor(key: string);
7
- sendPushNotification(requestOptions: PushRequestOptions): Promise<boolean>;
8
- sendEmail(requestOptions: EmailRequestOptions): Promise<boolean>;
9
- sendPushNotificationWithResponse(requestOptions: PushRequestOptions): Promise<Record<string, unknown>>;
10
- sendEmailWithResponse(requestOptions: EmailRequestOptions): Promise<Record<string, unknown>>;
11
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CustomerIo = void 0;
4
- const customerio_node_1 = require("customerio-node");
5
- class CustomerIo {
6
- key;
7
- constructor(key) {
8
- this.key = key;
9
- }
10
- async sendPushNotification(requestOptions) {
11
- try {
12
- const request = new customerio_node_1.SendPushRequest(requestOptions);
13
- const api = new customerio_node_1.APIClient(this.key, { region: customerio_node_1.RegionUS });
14
- const response = await api.sendPush(request);
15
- console.log('Sent push notification success: ', response);
16
- return true;
17
- }
18
- catch (error) {
19
- console.error('Failed to send push notification: ', error);
20
- return false;
21
- }
22
- }
23
- async sendEmail(requestOptions) {
24
- try {
25
- const request = new customerio_node_1.SendEmailRequest(requestOptions);
26
- const api = new customerio_node_1.APIClient(this.key, { region: customerio_node_1.RegionUS });
27
- const response = await api.sendEmail(request);
28
- console.log('Sent email success: ', response);
29
- return true;
30
- }
31
- catch (error) {
32
- console.error('Failed to send email: ', error);
33
- return false;
34
- }
35
- }
36
- async sendPushNotificationWithResponse(requestOptions) {
37
- try {
38
- const request = new customerio_node_1.SendPushRequest(requestOptions);
39
- const api = new customerio_node_1.APIClient(this.key, { region: customerio_node_1.RegionUS });
40
- const response = await api.sendPush(request);
41
- console.log('Sent push notification success: ', response);
42
- return response;
43
- }
44
- catch (error) {
45
- console.error('Failed to send push notification: ', error);
46
- return { error };
47
- }
48
- }
49
- async sendEmailWithResponse(requestOptions) {
50
- try {
51
- const request = new customerio_node_1.SendEmailRequest(requestOptions);
52
- const api = new customerio_node_1.APIClient(this.key, { region: customerio_node_1.RegionUS });
53
- const response = await api.sendEmail(request);
54
- console.log('Sent email success: ', response);
55
- return response;
56
- }
57
- catch (error) {
58
- console.error('Failed to send email: ', error);
59
- return { error };
60
- }
61
- }
62
- }
63
- exports.CustomerIo = CustomerIo;
@@ -1,3 +0,0 @@
1
- import { type IFlattenOptions } from './interfaces';
2
- export declare const flatten: <T>(input: T, reference?: string, output?: Record<string, unknown>, opts?: IFlattenOptions) => Record<string, unknown>;
3
- export declare const unflatten: (input: Record<string, unknown>, delimiter?: string) => Record<string, unknown>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unflatten = exports.flatten = void 0;
4
- const flatten = (input, reference = '', output = {}, opts = { secure: true, delimiter: '|' }) => {
5
- for (const key in input) {
6
- const value = input[key];
7
- const newKey = reference !== '' ? `${reference}${opts.delimiter}${key}` : key;
8
- const isObject = typeof value === 'object';
9
- const isInstanceOfObject = value instanceof Object;
10
- const isInstanceOfDate = value instanceof Date;
11
- const isArray = Array.isArray(value);
12
- if (isObject && isInstanceOfObject && !isInstanceOfDate && (!isArray || !opts.secure)) {
13
- (0, exports.flatten)(value, newKey, output, opts);
14
- }
15
- else {
16
- output[newKey] = value;
17
- }
18
- }
19
- return output;
20
- };
21
- exports.flatten = flatten;
22
- const unflatten = (input, delimiter = '|') => {
23
- const output = {};
24
- Object.keys(input).forEach((key) => {
25
- const keys = key.split(delimiter);
26
- let currentLevel = output;
27
- keys.forEach((part, index) => {
28
- if (index === keys.length - 1) {
29
- currentLevel[part] = input[key];
30
- }
31
- else {
32
- if (currentLevel[part] === undefined) {
33
- currentLevel[part] = {};
34
- }
35
- currentLevel = currentLevel[part];
36
- }
37
- });
38
- });
39
- return output;
40
- };
41
- exports.unflatten = unflatten;
@@ -1,4 +0,0 @@
1
- export interface IFlattenOptions {
2
- secure: boolean;
3
- delimiter: string;
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,38 +0,0 @@
1
- import { docs_v1 } from '@googleapis/docs';
2
- import { GoogleAuth, type JWTInput } from 'google-auth-library';
3
- import { type JSONClient } from 'google-auth-library/build/src/auth/googleauth';
4
- import { type IPlennaGoogleBase } from './requestBuilder';
5
- interface cloneDocumentResponse {
6
- success: boolean;
7
- documentId?: string;
8
- }
9
- interface updateDocumentResponse {
10
- success: boolean;
11
- documentId?: string;
12
- }
13
- interface deleteDocumentResponse {
14
- success: boolean;
15
- documentId?: string;
16
- }
17
- export interface ISchemaRequest extends docs_v1.Schema$Request {
18
- }
19
- export interface IInsertText extends docs_v1.Schema$InsertTextRequest {
20
- }
21
- export interface ITextStyles extends docs_v1.Schema$UpdateTextStyleRequest {
22
- }
23
- export interface ICredentials extends JWTInput {
24
- }
25
- export declare class PlennaGoogleService {
26
- private readonly credentials;
27
- constructor(credentials: ICredentials);
28
- authorization(): GoogleAuth<JSONClient>;
29
- getDocument(documentId: string): Promise<docs_v1.Schema$Document | undefined>;
30
- cloneDocument(documentId: string, folderId: string): Promise<cloneDocumentResponse>;
31
- buildPayload(template?: Array<Partial<IPlennaGoogleBase>>): ISchemaRequest[];
32
- addTextToRequest(text: IInsertText, style: ITextStyles): ISchemaRequest[];
33
- updateDocument(id: string, requests?: ISchemaRequest[]): Promise<updateDocumentResponse>;
34
- exportDocumentAsUrl(fileId: string): Promise<string | undefined>;
35
- exportDocumentAsFile(fileId: string): Promise<ArrayBuffer | undefined>;
36
- deleteDocument(fileId: string): Promise<deleteDocumentResponse>;
37
- }
38
- export {};
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlennaGoogleService = void 0;
4
- const docs_1 = require("@googleapis/docs");
5
- const drive_1 = require("@googleapis/drive");
6
- const google_auth_library_1 = require("google-auth-library");
7
- const requestBuilder_1 = require("./requestBuilder");
8
- class PlennaGoogleService {
9
- credentials;
10
- constructor(credentials) {
11
- this.credentials = credentials;
12
- }
13
- authorization() {
14
- return new google_auth_library_1.GoogleAuth({
15
- credentials: this.credentials,
16
- scopes: [
17
- 'https://www.googleapis.com/auth/documents',
18
- 'https://www.googleapis.com/auth/drive'
19
- ]
20
- });
21
- }
22
- async getDocument(documentId) {
23
- const authClient = this.authorization();
24
- const client = new docs_1.docs_v1.Docs({ auth: authClient });
25
- try {
26
- return await client.documents.get({ documentId });
27
- }
28
- catch (error) {
29
- console.log(error);
30
- }
31
- }
32
- async cloneDocument(documentId, folderId) {
33
- const authClient = this.authorization();
34
- const gdrive = new drive_1.drive_v3.Drive({ auth: authClient });
35
- try {
36
- const fileId = await gdrive.files.copy({
37
- fileId: documentId,
38
- requestBody: {
39
- name: new Date().toISOString(),
40
- parents: [folderId]
41
- },
42
- fields: '*'
43
- });
44
- return { success: true, documentId: fileId?.data?.id ?? '' };
45
- }
46
- catch (error) {
47
- console.log(error);
48
- return { success: false };
49
- }
50
- }
51
- buildPayload(template = []) {
52
- return (0, requestBuilder_1.payloadBuilder)(template);
53
- }
54
- addTextToRequest(text, style) {
55
- return [
56
- {
57
- insertText: text
58
- },
59
- {
60
- updateTextStyle: style
61
- }
62
- ];
63
- }
64
- async updateDocument(id, requests = []) {
65
- const authClient = this.authorization();
66
- const client = new docs_1.docs_v1.Docs({ auth: authClient });
67
- try {
68
- const updated = await client.documents.batchUpdate({
69
- documentId: id,
70
- requestBody: { requests }
71
- });
72
- return { success: true, documentId: updated?.data?.documentId ?? '' };
73
- }
74
- catch (error) {
75
- console.log(error);
76
- return { success: false };
77
- }
78
- }
79
- async exportDocumentAsUrl(fileId) {
80
- const authClient = this.authorization();
81
- const gdrive = new drive_1.drive_v3.Drive({ auth: authClient });
82
- try {
83
- const response = await gdrive.files.get({ fileId, fields: 'exportLinks' });
84
- const exportLinks = response?.data?.exportLinks ?? {};
85
- const link = exportLinks['application/pdf'];
86
- return link;
87
- }
88
- catch (error) {
89
- console.log(error);
90
- }
91
- }
92
- async exportDocumentAsFile(fileId) {
93
- try {
94
- const link = await this.exportDocumentAsUrl(fileId);
95
- const token = await this.authorization().getAccessToken();
96
- if (typeof link === 'string') {
97
- const resp = await fetch(link, { headers: { Authorization: `Bearer ${token}` } });
98
- return await resp.arrayBuffer();
99
- }
100
- }
101
- catch (error) {
102
- console.log(error);
103
- }
104
- }
105
- async deleteDocument(fileId) {
106
- const authClient = this.authorization();
107
- const gdrive = new drive_1.drive_v3.Drive({ auth: authClient });
108
- try {
109
- await gdrive.files.delete({ fileId });
110
- return { success: true, documentId: fileId };
111
- }
112
- catch (error) {
113
- console.log(error);
114
- return { success: false };
115
- }
116
- }
117
- }
118
- exports.PlennaGoogleService = PlennaGoogleService;
@@ -1,14 +0,0 @@
1
- import { type docs_v1 } from '@googleapis/docs';
2
- export type documentType = 'text' | 'image' | 'deleteRow';
3
- export interface ISchemaRequest extends docs_v1.Schema$Request {
4
- }
5
- export interface IPlennaGoogleBase {
6
- doc_type: documentType;
7
- identifier?: string;
8
- value?: string;
9
- rowToDelete?: {
10
- tableStartLocation?: number;
11
- rowIndex?: number;
12
- };
13
- }
14
- export declare const payloadBuilder: (template: Array<Partial<IPlennaGoogleBase>>) => docs_v1.Schema$Request[];
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.payloadBuilder = void 0;
4
- const getPayload = (type, variable, value, rowToDelete) => {
5
- if (type === 'deleteRow') {
6
- if (rowToDelete === undefined) {
7
- return undefined;
8
- }
9
- return {
10
- deleteTableRow: {
11
- tableCellLocation: {
12
- tableStartLocation: {
13
- index: rowToDelete.tableStartLocation
14
- },
15
- rowIndex: rowToDelete.rowIndex
16
- }
17
- }
18
- };
19
- }
20
- else if (['text', 'image'].includes(type)) {
21
- if (variable === undefined) {
22
- return undefined;
23
- }
24
- if (value === undefined) {
25
- return undefined;
26
- }
27
- const templates = {
28
- text: {
29
- replaceAllText: {
30
- containsText: {
31
- text: `[${variable}]`,
32
- matchCase: true
33
- },
34
- replaceText: value
35
- }
36
- },
37
- image: {
38
- replaceImage: {
39
- imageObjectId: variable,
40
- uri: value
41
- }
42
- }
43
- };
44
- return templates[type];
45
- }
46
- };
47
- const payloadBuilder = (template) => {
48
- const payload = [];
49
- template.forEach(field => {
50
- if (field.doc_type !== undefined) {
51
- const val = getPayload(field.doc_type, field.identifier, field.value, field.rowToDelete);
52
- if (val !== undefined) {
53
- payload.push(val);
54
- }
55
- }
56
- });
57
- console.log(payload);
58
- return payload.filter(v => v);
59
- };
60
- exports.payloadBuilder = payloadBuilder;
@@ -1,28 +0,0 @@
1
- import { type APIGatewayProxyResult } from 'aws-lambda';
2
- export type httpCode = 200 | 400 | 401 | 403 | 404 | 500;
3
- export interface IPlennaStatus {
4
- code: number;
5
- message: string;
6
- httpCode: httpCode;
7
- }
8
- export declare class HttpStatusCode {
9
- httpCode: httpCode;
10
- constructor(code: httpCode);
11
- }
12
- export declare class Result {
13
- private readonly statusCode;
14
- private readonly code;
15
- private readonly message;
16
- private readonly data?;
17
- private readonly headers;
18
- constructor(statusCode: httpCode, code: number, message: string, data?: unknown, headers?: Record<string, unknown>);
19
- bodyToString(): APIGatewayProxyResult;
20
- }
21
- export declare class PlennaError extends Error implements HttpStatusCode {
22
- code: number;
23
- message: string;
24
- httpCode: httpCode;
25
- constructor(status: IPlennaStatus);
26
- }
27
- export declare const success: (data: object, headers?: Record<string, unknown>) => APIGatewayProxyResult;
28
- export declare const error: (httpStatusCode: httpCode, message: string, code?: number) => APIGatewayProxyResult;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.error = exports.success = exports.PlennaError = exports.Result = exports.HttpStatusCode = void 0;
4
- class HttpStatusCode {
5
- httpCode;
6
- constructor(code) {
7
- this.httpCode = code;
8
- }
9
- }
10
- exports.HttpStatusCode = HttpStatusCode;
11
- class Result {
12
- statusCode;
13
- code;
14
- message;
15
- data;
16
- headers;
17
- constructor(statusCode, code, message, data, headers) {
18
- this.statusCode = statusCode;
19
- this.code = code;
20
- this.message = message;
21
- this.data = data;
22
- this.headers = { ...headers };
23
- }
24
- bodyToString() {
25
- const exposedHeaders = Object.entries(this.headers).map(([key]) => key).join(',');
26
- return {
27
- statusCode: this.statusCode,
28
- headers: {
29
- ...this.headers,
30
- 'Access-Control-Allow-Origin': '*',
31
- 'Access-Control-Expose-Headers': exposedHeaders,
32
- 'Access-Control-Allow-Credentials': true
33
- },
34
- body: JSON.stringify({
35
- code: this.code,
36
- message: this.message,
37
- data: this.data
38
- })
39
- };
40
- }
41
- }
42
- exports.Result = Result;
43
- class PlennaError extends Error {
44
- code;
45
- message;
46
- httpCode;
47
- constructor(status) {
48
- super();
49
- this.code = status.code;
50
- this.message = status.message;
51
- this.httpCode = status.httpCode;
52
- }
53
- }
54
- exports.PlennaError = PlennaError;
55
- const success = (data, headers) => {
56
- const result = new Result(200, 0, 'success', data, headers);
57
- return result.bodyToString();
58
- };
59
- exports.success = success;
60
- const error = (httpStatusCode, message, code = 0) => {
61
- const result = new Result(httpStatusCode, code, message);
62
- return result.bodyToString();
63
- };
64
- exports.error = error;
@@ -1,9 +0,0 @@
1
- export interface IDestiny {
2
- name: string;
3
- email: string;
4
- }
5
- export declare class Mailer {
6
- private readonly apiKey;
7
- constructor(apiKey: string);
8
- sendEmail(templateId: number, destiny: IDestiny[], params: Record<string, string>): Promise<boolean>;
9
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Mailer = void 0;
4
- class Mailer {
5
- apiKey;
6
- constructor(apiKey) {
7
- this.apiKey = apiKey;
8
- }
9
- async sendEmail(templateId, destiny, params) {
10
- try {
11
- const response = await fetch('https://api.sendinblue.com/v3/smtp/email', {
12
- method: 'post',
13
- headers: {
14
- accept: 'application/json',
15
- 'api-key': this.apiKey,
16
- 'content-type': 'application/json'
17
- },
18
- body: JSON.stringify({
19
- to: destiny,
20
- params,
21
- templateId
22
- })
23
- });
24
- console.log(JSON.stringify(response));
25
- return true;
26
- }
27
- catch (error) {
28
- console.log(JSON.stringify(error));
29
- console.log('error sending email');
30
- return false;
31
- }
32
- }
33
- }
34
- exports.Mailer = Mailer;