mblabs-roccato-backend-commons 1.0.7 → 1.1.0

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 (95) hide show
  1. package/bitbucket-pipelines.yml +6 -48
  2. package/dist/database/entities/account.d.ts +1 -2
  3. package/dist/database/entities/account.js +2 -7
  4. package/dist/database/entities/address.d.ts +2 -1
  5. package/dist/database/entities/address.js +6 -5
  6. package/dist/database/entities/company-address.d.ts +2 -0
  7. package/dist/database/entities/company-address.js +7 -0
  8. package/dist/database/migrations/1748448589934-CreateAccountsTable.js +1 -6
  9. package/dist/database/migrations/1750432386920-CreateAddressTable.js +0 -5
  10. package/dist/database/migrations/index.js +0 -4
  11. package/dist/interfaces/aws.d.ts +41 -67
  12. package/dist/interfaces/azure.d.ts +38 -61
  13. package/dist/interfaces/firebase.d.ts +3 -7
  14. package/dist/interfaces/gcp.d.ts +5 -11
  15. package/dist/interfaces/grafana.d.ts +2 -6
  16. package/dist/interfaces/keycloak.d.ts +4 -171
  17. package/dist/interfaces/nodemailer.d.ts +16 -20
  18. package/dist/interfaces/redis.d.ts +8 -49
  19. package/dist/interfaces/sendgrid.d.ts +13 -15
  20. package/dist/services/aws/cloudwatch.d.ts +1 -1
  21. package/dist/services/aws/cloudwatch.js +38 -38
  22. package/dist/services/aws/pinpoint.d.ts +3 -3
  23. package/dist/services/aws/pinpoint.js +29 -29
  24. package/dist/services/aws/s3.d.ts +5 -5
  25. package/dist/services/aws/s3.js +55 -59
  26. package/dist/services/aws/secret-manager.d.ts +1 -1
  27. package/dist/services/aws/secret-manager.js +5 -5
  28. package/dist/services/aws/sqs.d.ts +3 -3
  29. package/dist/services/aws/sqs.js +16 -16
  30. package/dist/services/azure/application-insights.d.ts +4 -4
  31. package/dist/services/azure/application-insights.js +12 -12
  32. package/dist/services/azure/communication.d.ts +3 -3
  33. package/dist/services/azure/communication.js +17 -17
  34. package/dist/services/azure/keyvault.d.ts +1 -1
  35. package/dist/services/azure/keyvault.js +3 -3
  36. package/dist/services/azure/storage-blob.d.ts +3 -3
  37. package/dist/services/azure/storage-blob.js +22 -22
  38. package/dist/services/firebase.d.ts +2 -2
  39. package/dist/services/firebase.js +10 -12
  40. package/dist/services/gcp/drive.d.ts +1 -1
  41. package/dist/services/gcp/drive.js +4 -4
  42. package/dist/services/gcp/secrets.d.ts +1 -1
  43. package/dist/services/gcp/secrets.js +8 -6
  44. package/dist/services/gcp/sheets.d.ts +1 -1
  45. package/dist/services/gcp/sheets.js +6 -6
  46. package/dist/services/grafana.d.ts +2 -2
  47. package/dist/services/grafana.js +12 -12
  48. package/dist/services/keycloak.d.ts +2 -14
  49. package/dist/services/keycloak.js +24 -300
  50. package/dist/services/nodemailer.d.ts +2 -2
  51. package/dist/services/nodemailer.js +109 -19
  52. package/dist/services/redis.d.ts +8 -6
  53. package/dist/services/redis.js +24 -53
  54. package/dist/services/sendgrid.d.ts +1 -1
  55. package/dist/services/sendgrid.js +10 -10
  56. package/package.json +1 -1
  57. package/src/database/entities/account.ts +3 -5
  58. package/src/database/entities/address.ts +7 -4
  59. package/src/database/entities/company-address.ts +5 -0
  60. package/src/database/migrations/1748448589934-CreateAccountsTable.ts +1 -6
  61. package/src/database/migrations/1750432386920-CreateAddressTable.ts +0 -5
  62. package/src/database/migrations/index.ts +0 -4
  63. package/src/interfaces/aws.ts +55 -81
  64. package/src/interfaces/azure.ts +50 -71
  65. package/src/interfaces/firebase.ts +6 -10
  66. package/src/interfaces/gcp.ts +8 -14
  67. package/src/interfaces/grafana.ts +5 -9
  68. package/src/interfaces/keycloak.ts +7 -190
  69. package/src/interfaces/nodemailer.ts +18 -22
  70. package/src/interfaces/redis.ts +8 -54
  71. package/src/interfaces/sendgrid.ts +14 -16
  72. package/src/services/aws/cloudwatch.ts +39 -39
  73. package/src/services/aws/pinpoint.ts +30 -30
  74. package/src/services/aws/s3.ts +55 -59
  75. package/src/services/aws/secret-manager.ts +7 -8
  76. package/src/services/aws/sqs.ts +17 -23
  77. package/src/services/azure/application-insights.ts +12 -12
  78. package/src/services/azure/communication.ts +18 -18
  79. package/src/services/azure/keyvault.ts +3 -3
  80. package/src/services/azure/storage-blob.ts +30 -34
  81. package/src/services/firebase.ts +11 -21
  82. package/src/services/gcp/drive.ts +5 -8
  83. package/src/services/gcp/secrets.ts +10 -9
  84. package/src/services/gcp/sheets.ts +7 -10
  85. package/src/services/grafana.ts +12 -18
  86. package/src/services/keycloak.ts +25 -381
  87. package/src/services/nodemailer.ts +110 -19
  88. package/src/services/redis.ts +22 -58
  89. package/src/services/sendgrid.ts +11 -11
  90. package/dist/database/migrations/1750690818577-CreateAccountAddressTable.d.ts +0 -5
  91. package/dist/database/migrations/1750690818577-CreateAccountAddressTable.js +0 -94
  92. package/dist/database/migrations/1750691840822-CreateAccountDetailsTable.d.ts +0 -5
  93. package/dist/database/migrations/1750691840822-CreateAccountDetailsTable.js +0 -99
  94. package/src/database/migrations/1750690818577-CreateAccountAddressTable.ts +0 -98
  95. package/src/database/migrations/1750691840822-CreateAccountDetailsTable.ts +0 -99
@@ -2,67 +2,38 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const redis_1 = require("redis");
4
4
  class RedisService {
5
- async set({ credentials, data }) {
6
- const client = (0, redis_1.createClient)({
5
+ credentials;
6
+ client;
7
+ constructor(credentials) {
8
+ this.credentials = credentials;
9
+ this.client = (0, redis_1.createClient)({
7
10
  socket: {
8
11
  host: credentials.host,
9
12
  port: credentials.port,
10
13
  },
11
14
  password: credentials.password,
12
15
  });
13
- const options = {
14
- ...data.ttl && {
15
- expiration: {
16
- type: 'EX',
17
- value: data.ttl,
18
- },
19
- },
20
- };
21
- await client.connect();
22
- await client.set(data.key, JSON.stringify(data.value), options);
23
- await client.close();
16
+ this.client.connect();
24
17
  }
25
- async get({ credentials, data }) {
26
- const client = (0, redis_1.createClient)({
27
- socket: {
28
- host: credentials.host,
29
- port: credentials.port,
30
- },
31
- password: credentials.password,
32
- });
33
- await client.connect();
34
- const response = await client.get(data.key);
35
- await client.close();
36
- return {
37
- data: typeof response === 'string' ? JSON.parse(response) : null,
38
- };
18
+ async set(key, value, ttl) {
19
+ const data = JSON.stringify(value);
20
+ if (ttl) {
21
+ await this.client.set(key, data, { EX: ttl });
22
+ }
23
+ else {
24
+ await this.client.set(key, data);
25
+ }
39
26
  }
40
- async del({ credentials, data }) {
41
- const client = (0, redis_1.createClient)({
42
- socket: {
43
- host: credentials.host,
44
- port: credentials.port,
45
- },
46
- password: credentials.password,
47
- });
48
- await client.connect();
49
- await client.del(data.key);
50
- await client.close();
27
+ async get(key) {
28
+ const data = await this.client.get(key);
29
+ return typeof data === 'string' ? JSON.parse(data) : null;
51
30
  }
52
- async exists({ credentials, data }) {
53
- const client = (0, redis_1.createClient)({
54
- socket: {
55
- host: credentials.host,
56
- port: credentials.port,
57
- },
58
- password: credentials.password,
59
- });
60
- await client.connect();
61
- const exists = await client.exists(data.key);
62
- await client.close();
63
- return {
64
- exists: !!exists,
65
- };
31
+ async del(key) {
32
+ await this.client.del(key);
33
+ }
34
+ async exists(key) {
35
+ const exists = await this.client.exists(key);
36
+ return exists === 1;
66
37
  }
67
38
  }
68
- exports.default = new RedisService();
39
+ exports.default = RedisService;
@@ -1,6 +1,6 @@
1
1
  import { ISendgridService, Sendgrid } from '../interfaces/sendgrid';
2
2
  declare class SendgridService implements ISendgridService {
3
- sendMail({ credentials, data }: Sendgrid.SendMail.Request): Promise<void>;
3
+ sendMail(req: Sendgrid.SendMail.Request): Promise<void>;
4
4
  }
5
5
  declare const _default: SendgridService;
6
6
  export default _default;
@@ -5,17 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const mail_1 = __importDefault(require("@sendgrid/mail"));
7
7
  class SendgridService {
8
- async sendMail({ credentials, data }) {
9
- mail_1.default.setApiKey(credentials.apiKey);
8
+ async sendMail(req) {
9
+ mail_1.default.setApiKey(req.credentials.apiKey);
10
10
  await mail_1.default.send({
11
- from: data.from,
12
- to: data.to,
13
- subject: data.subject,
14
- text: data.text,
15
- html: data.html,
16
- templateId: data.template,
17
- attachments: data.attachments,
18
- dynamicTemplateData: data.substitutions,
11
+ from: req.from,
12
+ to: req.to,
13
+ subject: req.subject,
14
+ text: req.text,
15
+ html: req.html,
16
+ templateId: req.template,
17
+ attachments: req.attachments,
18
+ dynamicTemplateData: req.substitutions,
19
19
  });
20
20
  }
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mblabs-roccato-backend-commons",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,10 +21,7 @@ export default class AccountEntity extends BaseEntity {
21
21
  public email?: string;
22
22
 
23
23
  @Column({ type: 'varchar', nullable: true })
24
- public personalDocument?: string;
25
-
26
- @Column({ type: 'varchar', nullable: true })
27
- public businessDocument?: string;
24
+ public cellphone?: string;
28
25
 
29
26
  @ManyToOne((): ObjectType<ProfileEntity> => ProfileEntity)
30
27
  @JoinColumn({ name: 'profileId', referencedColumnName: 'id' })
@@ -35,6 +32,7 @@ export default class AccountEntity extends BaseEntity {
35
32
 
36
33
  constructor (partial: Partial<AccountEntity>) {
37
34
  super();
35
+
38
36
  Object.assign(this, partial);
39
37
  }
40
- }
38
+ }
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  Column,
3
3
  Entity,
4
+ OneToMany,
4
5
  } from 'typeorm';
5
6
 
6
7
  import BaseEntity from './base';
8
+ import CompanyAddressEntity from './company-address';
7
9
 
8
10
  @Entity('address')
9
11
  export default class AddressEntity extends BaseEntity {
12
+
10
13
  @Column({ type: 'varchar', nullable: true })
11
14
  public zipcode?: string;
12
15
 
@@ -22,14 +25,14 @@ export default class AddressEntity extends BaseEntity {
22
25
  @Column({ type: 'varchar', nullable: true })
23
26
  public city?: string;
24
27
 
25
- @Column({ type: 'varchar', nullable: true })
26
- public neighborhood?: string;
27
-
28
28
  @Column({ type: 'varchar', nullable: true })
29
29
  public state?: string;
30
30
 
31
+ @OneToMany(() => CompanyAddressEntity, (companyAddress) => companyAddress.address)
32
+ public companyAddresses?: CompanyAddressEntity[];
33
+
31
34
  constructor (partial: Partial<AddressEntity>) {
32
35
  super();
33
36
  Object.assign(this, partial);
34
37
  }
35
- }
38
+ }
@@ -1,5 +1,6 @@
1
1
  import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
2
2
 
3
+ import AddressEntity from './address';
3
4
  import BaseEntity from './base';
4
5
  import CompanyEntity from './company';
5
6
 
@@ -15,6 +16,10 @@ export default class CompanyAddressEntity extends BaseEntity {
15
16
  @JoinColumn({ name: 'companyId' })
16
17
  public company?: CompanyEntity;
17
18
 
19
+ @ManyToOne(() => AddressEntity, (address) => address.companyAddresses)
20
+ @JoinColumn({ name: 'addressId' })
21
+ public address?: AddressEntity;
22
+
18
23
  constructor (partial: Partial<CompanyAddressEntity>) {
19
24
  super();
20
25
  Object.assign(this, partial);
@@ -36,12 +36,7 @@ export class CreateAccountsTable1748448589934 implements MigrationInterface {
36
36
  isNullable: true,
37
37
  },
38
38
  {
39
- name: 'personalDocument',
40
- type: 'varchar',
41
- isNullable: true,
42
- },
43
- {
44
- name: 'businessDocument',
39
+ name: 'cellphone',
45
40
  type: 'varchar',
46
41
  isNullable: true,
47
42
  },
@@ -40,11 +40,6 @@ export class CreateAddressTable1750432386920 implements MigrationInterface {
40
40
  type: 'varchar',
41
41
  isNullable: true,
42
42
  },
43
- {
44
- name: 'neighborhood',
45
- type: 'varchar',
46
- isNullable: true,
47
- },
48
43
  {
49
44
  name: 'city',
50
45
  type: 'varchar',
@@ -12,8 +12,6 @@ import { CreateAccountContactTable1750432386914 } from './1750432386914-CreateAc
12
12
  import { CreateAddressTable1750432386920 } from './1750432386920-CreateAddressTable';
13
13
  import { CreateCompanyTable1750437883213 } from './1750437883213-CreateCompanyTable';
14
14
  import { CreateCompanyAddressTable1750440116105 } from './1750440116105-CreateCompanyAddressTable';
15
- import { CreateAccountAddressTable1750690818577 } from './1750690818577-CreateAccountAddressTable';
16
- import { CreateAccountDetailsTable1750691840822 } from './1750691840822-CreateAccountDetailsTable';
17
15
 
18
16
  export const Migrations = [
19
17
  Init1748448461165,
@@ -30,6 +28,4 @@ export const Migrations = [
30
28
  CreateAddressTable1750432386920,
31
29
  CreateCompanyTable1750437883213,
32
30
  CreateCompanyAddressTable1750440116105,
33
- CreateAccountAddressTable1750690818577,
34
- CreateAccountDetailsTable1750691840822,
35
31
  ];
@@ -19,12 +19,10 @@ interface UploadOptions {
19
19
  export namespace AmazonCloudwatch {
20
20
  export namespace CreateLogEvent {
21
21
  export interface Request {
22
- data: {
23
- application: string;
24
- group: string;
25
- stream: string;
26
- events: InputLogEvent[];
27
- };
22
+ application: string;
23
+ group: string;
24
+ stream: string;
25
+ events: InputLogEvent[];
28
26
  credentials: Credentials;
29
27
  }
30
28
  }
@@ -33,41 +31,35 @@ export namespace AmazonCloudwatch {
33
31
  export namespace AmazonPinpoint {
34
32
  export namespace SendMail {
35
33
  export interface Request {
36
- data: {
37
- application: string;
38
- subject: string;
39
- text: string;
40
- emails: string | string[];
41
- from: string;
42
- variables?: Record<string, string | number>;
43
- };
34
+ applicationId: string;
35
+ subject: string;
36
+ text: string;
37
+ emails: string | string[];
38
+ from: string;
39
+ variables?: Record<string, string | number>;
44
40
  credentials: Credentials;
45
41
  }
46
42
  }
47
43
 
48
44
  export namespace SendTemplateMail {
49
45
  export interface Request {
50
- data: {
51
- application: string;
52
- template: string;
53
- emails: string | string[];
54
- from: string;
55
- variables?: Record<string, string | number>;
56
- };
46
+ applicationId: string;
47
+ template: string;
48
+ emails: string | string[];
49
+ from: string;
50
+ variables?: Record<string, string | number>;
57
51
  credentials: Credentials;
58
52
  }
59
53
  }
60
54
 
61
55
  export namespace SendSMS {
62
56
  export interface Request {
63
- data: {
64
- application: string;
65
- sender: string;
66
- text: string;
67
- phones: string | string[];
68
- type?: 'PROMOTIONAL' | 'TRANSACTIONAL';
69
- variables?: Record<string, string | number>;
70
- };
57
+ applicationId: string;
58
+ sender: string;
59
+ text: string;
60
+ phones: string | string[];
61
+ type?: 'PROMOTIONAL' | 'TRANSACTIONAL';
62
+ variables?: Record<string, string | number>;
71
63
  credentials: Credentials;
72
64
  }
73
65
  }
@@ -76,12 +68,10 @@ export namespace AmazonPinpoint {
76
68
  export namespace AmazonS3 {
77
69
  export namespace GetSignedUrl {
78
70
  export interface Request {
79
- data: {
80
- filename: string;
81
- bucket: string;
82
- folder?: string;
83
- isUpload?: boolean;
84
- };
71
+ filename: string;
72
+ bucket: string;
73
+ folder?: string;
74
+ isUpload?: boolean;
85
75
  credentials: Credentials;
86
76
  }
87
77
 
@@ -92,11 +82,9 @@ export namespace AmazonS3 {
92
82
 
93
83
  export namespace UploadBase64 {
94
84
  export interface Request {
95
- data: {
96
- file: string;
97
- bucket: string;
98
- options?: UploadOptions;
99
- };
85
+ file: string;
86
+ bucket: string;
87
+ options?: UploadOptions;
100
88
  credentials: Credentials;
101
89
  }
102
90
 
@@ -109,11 +97,9 @@ export namespace AmazonS3 {
109
97
 
110
98
  export namespace UploadBuffer {
111
99
  export interface Request {
112
- data: {
113
- file: Buffer;
114
- bucket: string;
115
- options?: UploadOptions;
116
- };
100
+ file: Buffer;
101
+ bucket: string;
102
+ options?: UploadOptions;
117
103
  credentials: Credentials;
118
104
  }
119
105
 
@@ -126,21 +112,17 @@ export namespace AmazonS3 {
126
112
 
127
113
  export namespace DeleteFile {
128
114
  export interface Request {
129
- data: {
130
- filename: string;
131
- bucket: string;
132
- folder?: string;
133
- };
115
+ filename: string;
116
+ bucket: string;
117
+ folder?: string;
134
118
  credentials: Credentials;
135
119
  }
136
120
  }
137
121
 
138
122
  export namespace ListFiles {
139
123
  export interface Request {
140
- data: {
141
- bucket: string;
142
- folder?: string;
143
- };
124
+ bucket: string;
125
+ folder?: string;
144
126
  credentials: Credentials;
145
127
  }
146
128
 
@@ -153,9 +135,7 @@ export namespace AmazonS3 {
153
135
  export namespace AmazonSecretManager {
154
136
  export namespace GetSecret {
155
137
  export interface Request {
156
- data: {
157
- secret: string;
158
- };
138
+ secretId: string;
159
139
  credentials: Credentials;
160
140
  }
161
141
 
@@ -168,19 +148,15 @@ export namespace AmazonSecretManager {
168
148
  export namespace AmazonSQS {
169
149
  export namespace PublishMessage {
170
150
  export interface Request {
171
- data: {
172
- queue: string;
173
- message: unknown;
174
- };
151
+ queue: string;
152
+ message: unknown;
175
153
  credentials: Credentials;
176
154
  }
177
155
  }
178
156
 
179
157
  export namespace ConsumeMessage {
180
158
  export interface Request {
181
- data: {
182
- queue: string;
183
- };
159
+ queue: string;
184
160
  credentials: Credentials;
185
161
  }
186
162
 
@@ -191,9 +167,7 @@ export namespace AmazonSQS {
191
167
 
192
168
  export namespace ConsumeMessages {
193
169
  export interface Request {
194
- data: {
195
- queue: string;
196
- };
170
+ queue: string;
197
171
  credentials: Credentials;
198
172
  }
199
173
 
@@ -204,29 +178,29 @@ export namespace AmazonSQS {
204
178
  }
205
179
 
206
180
  export interface IAmazonCloudwatchService {
207
- createLogEvent(req: AmazonCloudwatch.CreateLogEvent.Request): Promise<void>;
181
+ createLogEvent (req: AmazonCloudwatch.CreateLogEvent.Request): Promise<void>;
208
182
  }
209
183
 
210
184
  export interface IAmazonPinpointService {
211
- sendMail(req: AmazonPinpoint.SendMail.Request): Promise<void>;
212
- sendTemplateMail(req: AmazonPinpoint.SendTemplateMail.Request): Promise<void>;
213
- sendSMS(req: AmazonPinpoint.SendSMS.Request): Promise<void>;
185
+ sendMail (req: AmazonPinpoint.SendMail.Request): Promise<void>;
186
+ sendTemplateMail (req: AmazonPinpoint.SendTemplateMail.Request): Promise<void>;
187
+ sendSMS (req: AmazonPinpoint.SendSMS.Request): Promise<void>;
214
188
  }
215
189
 
216
190
  export interface IAmazonS3Service {
217
- getSignedUrl(req: AmazonS3.GetSignedUrl.Request): Promise<AmazonS3.GetSignedUrl.Response>;
218
- uploadBase64(req: AmazonS3.UploadBase64.Request): Promise<AmazonS3.UploadBase64.Response>;
219
- uploadBuffer(req: AmazonS3.UploadBuffer.Request): Promise<AmazonS3.UploadBuffer.Response>;
220
- deleteFile(req: AmazonS3.DeleteFile.Request): Promise<void>;
221
- listFiles(req: AmazonS3.ListFiles.Request): Promise<AmazonS3.ListFiles.Response>;
191
+ getSignedUrl (req: AmazonS3.GetSignedUrl.Request): Promise<AmazonS3.GetSignedUrl.Response>;
192
+ uploadBase64 (req: AmazonS3.UploadBase64.Request): Promise<AmazonS3.UploadBase64.Response>;
193
+ uploadBuffer (req: AmazonS3.UploadBuffer.Request): Promise<AmazonS3.UploadBuffer.Response>;
194
+ deleteFile (req: AmazonS3.DeleteFile.Request): Promise<void>;
195
+ listFiles (req: AmazonS3.ListFiles.Request): Promise<AmazonS3.ListFiles.Response>;
222
196
  }
223
197
 
224
198
  export interface IAmazonSecretManagerService {
225
- getSecret<T>(req: AmazonSecretManager.GetSecret.Request): Promise<AmazonSecretManager.GetSecret.Response<T>>;
199
+ getSecret <T>(req: AmazonSecretManager.GetSecret.Request): Promise<AmazonSecretManager.GetSecret.Response<T>>;
226
200
  }
227
201
 
228
202
  export interface IAmazonSQSService {
229
- publishMessage(req: AmazonSQS.PublishMessage.Request): Promise<void>;
230
- consumeMessage<T>(req: AmazonSQS.ConsumeMessage.Request): Promise<AmazonSQS.ConsumeMessage.Response<T>>;
231
- consumeMessages<T>(req: AmazonSQS.ConsumeMessages.Request): Promise<AmazonSQS.ConsumeMessages.Response<T>>;
232
- }
203
+ publishMessage (req: AmazonSQS.PublishMessage.Request): Promise<void>;
204
+ consumeMessage<T> (req: AmazonSQS.ConsumeMessage.Request): Promise<AmazonSQS.ConsumeMessage.Response<T>>;
205
+ consumeMessages<T> (req: AmazonSQS.ConsumeMessages.Request): Promise<AmazonSQS.ConsumeMessages.Response<T>>;
206
+ }