@aptana/multichannel-common 2.9.12

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 (202) hide show
  1. package/core/domain/Command.d.ts +3 -0
  2. package/core/domain/Command.js +2 -0
  3. package/core/domain/Entity.d.ts +6 -0
  4. package/core/domain/Entity.js +13 -0
  5. package/core/domain/Identifier.d.ts +5 -0
  6. package/core/domain/Identifier.js +13 -0
  7. package/core/domain/UniqueId.d.ts +4 -0
  8. package/core/domain/UniqueId.js +11 -0
  9. package/core/domain/UseCase.d.ts +3 -0
  10. package/core/domain/UseCase.js +2 -0
  11. package/core/domain/ValueObject.d.ts +4 -0
  12. package/core/domain/ValueObject.js +10 -0
  13. package/core/domain/auth/Auth.d.ts +17 -0
  14. package/core/domain/auth/Auth.js +41 -0
  15. package/core/domain/auth/Authenticable.d.ts +4 -0
  16. package/core/domain/auth/Authenticable.js +2 -0
  17. package/core/domain/auth/Guard.d.ts +20 -0
  18. package/core/domain/auth/Guard.js +2 -0
  19. package/core/domain/auth/TokenGuard.d.ts +33 -0
  20. package/core/domain/auth/TokenGuard.js +94 -0
  21. package/core/domain/auth/UserProvider.d.ts +17 -0
  22. package/core/domain/auth/UserProvider.js +2 -0
  23. package/core/domain/cache/Cache.d.ts +8 -0
  24. package/core/domain/cache/Cache.js +2 -0
  25. package/core/domain/cache/Repo.d.ts +51 -0
  26. package/core/domain/cache/Repo.js +2 -0
  27. package/core/domain/cache/Store.d.ts +26 -0
  28. package/core/domain/cache/Store.js +2 -0
  29. package/core/domain/events/Event.d.ts +8 -0
  30. package/core/domain/events/Event.js +2 -0
  31. package/core/domain/events/Listener.d.ts +4 -0
  32. package/core/domain/events/Listener.js +2 -0
  33. package/core/domain/events/Worker.d.ts +3 -0
  34. package/core/domain/events/Worker.js +2 -0
  35. package/core/domain/loaders/Loader.d.ts +4 -0
  36. package/core/domain/loaders/Loader.js +2 -0
  37. package/core/domain/loaders/Manager.d.ts +3 -0
  38. package/core/domain/loaders/Manager.js +2 -0
  39. package/core/errors/AppError.d.ts +10 -0
  40. package/core/errors/AppError.js +16 -0
  41. package/core/errors/AuthenticationTokenMissingError.d.ts +5 -0
  42. package/core/errors/AuthenticationTokenMissingError.js +11 -0
  43. package/core/errors/BadRequestError.d.ts +5 -0
  44. package/core/errors/BadRequestError.js +11 -0
  45. package/core/errors/NotAuthorizedError.d.ts +5 -0
  46. package/core/errors/NotAuthorizedError.js +11 -0
  47. package/core/errors/NotFoundError.d.ts +5 -0
  48. package/core/errors/NotFoundError.js +11 -0
  49. package/core/errors/RequestValidationError.d.ts +10 -0
  50. package/core/errors/RequestValidationError.js +47 -0
  51. package/core/errors/ValidationError.d.ts +8 -0
  52. package/core/errors/ValidationError.js +19 -0
  53. package/core/errors/WrongAuthenticationTokenError.d.ts +5 -0
  54. package/core/errors/WrongAuthenticationTokenError.js +11 -0
  55. package/core/errors/WrongCredentialsError.d.ts +5 -0
  56. package/core/errors/WrongCredentialsError.js +11 -0
  57. package/core/index.d.ts +48 -0
  58. package/core/index.js +69 -0
  59. package/core/infrastructure/Container.d.ts +1 -0
  60. package/core/infrastructure/Container.js +8 -0
  61. package/core/infrastructure/Controller.d.ts +9 -0
  62. package/core/infrastructure/Controller.js +30 -0
  63. package/core/infrastructure/DatabaseRepository.d.ts +35 -0
  64. package/core/infrastructure/DatabaseRepository.js +2 -0
  65. package/core/infrastructure/Mapper.d.ts +2 -0
  66. package/core/infrastructure/Mapper.js +6 -0
  67. package/core/infrastructure/Repo.d.ts +2 -0
  68. package/core/infrastructure/Repo.js +6 -0
  69. package/core/infrastructure/cache/Cache.d.ts +47 -0
  70. package/core/infrastructure/cache/Cache.js +101 -0
  71. package/core/infrastructure/cache/InMemoryCache.d.ts +20 -0
  72. package/core/infrastructure/cache/InMemoryCache.js +62 -0
  73. package/core/infrastructure/cache/RedisCache.d.ts +15 -0
  74. package/core/infrastructure/cache/RedisCache.js +51 -0
  75. package/core/infrastructure/cache/Repo.d.ts +25 -0
  76. package/core/infrastructure/cache/Repo.js +103 -0
  77. package/core/infrastructure/cache/stores/ArrayStore.d.ts +17 -0
  78. package/core/infrastructure/cache/stores/ArrayStore.js +65 -0
  79. package/core/infrastructure/cache/stores/FileStore.d.ts +14 -0
  80. package/core/infrastructure/cache/stores/FileStore.js +171 -0
  81. package/core/infrastructure/cache/stores/NullStore.d.ts +9 -0
  82. package/core/infrastructure/cache/stores/NullStore.js +24 -0
  83. package/core/infrastructure/cache/stores/RedisStore.d.ts +13 -0
  84. package/core/infrastructure/cache/stores/RedisStore.js +44 -0
  85. package/core/infrastructure/events/ChannelEvent.d.ts +9 -0
  86. package/core/infrastructure/events/ChannelEvent.js +37 -0
  87. package/core/infrastructure/events/Connection.d.ts +8 -0
  88. package/core/infrastructure/events/Connection.js +30 -0
  89. package/core/infrastructure/events/Event.d.ts +16 -0
  90. package/core/infrastructure/events/Event.js +42 -0
  91. package/core/infrastructure/events/Listener.d.ts +23 -0
  92. package/core/infrastructure/events/Listener.js +77 -0
  93. package/core/infrastructure/events/Worker.d.ts +9 -0
  94. package/core/infrastructure/events/Worker.js +34 -0
  95. package/core/infrastructure/events/grpc/Connection.d.ts +9 -0
  96. package/core/infrastructure/events/grpc/Connection.js +34 -0
  97. package/core/infrastructure/events/grpc/Event.d.ts +12 -0
  98. package/core/infrastructure/events/grpc/Event.js +80 -0
  99. package/core/infrastructure/events/grpc/Listener.d.ts +16 -0
  100. package/core/infrastructure/events/grpc/Listener.js +74 -0
  101. package/core/infrastructure/events/rpc/Event.d.ts +13 -0
  102. package/core/infrastructure/events/rpc/Event.js +98 -0
  103. package/core/infrastructure/events/rpc/Listener.d.ts +6 -0
  104. package/core/infrastructure/events/rpc/Listener.js +30 -0
  105. package/core/infrastructure/http/App.d.ts +15 -0
  106. package/core/infrastructure/http/App.js +73 -0
  107. package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.d.ts +2 -0
  108. package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.js +8 -0
  109. package/core/infrastructure/http/middleware/errorMiddleware.d.ts +2 -0
  110. package/core/infrastructure/http/middleware/errorMiddleware.js +18 -0
  111. package/core/infrastructure/http/middleware/loggerMiddleware.d.ts +2 -0
  112. package/core/infrastructure/http/middleware/loggerMiddleware.js +17 -0
  113. package/core/infrastructure/http/middleware/routeNotFoundMiddleware.d.ts +2 -0
  114. package/core/infrastructure/http/middleware/routeNotFoundMiddleware.js +11 -0
  115. package/core/infrastructure/http/middleware/validationMiddleware.d.ts +4 -0
  116. package/core/infrastructure/http/middleware/validationMiddleware.js +35 -0
  117. package/core/infrastructure/loaders/Loader.d.ts +8 -0
  118. package/core/infrastructure/loaders/Loader.js +14 -0
  119. package/core/infrastructure/loaders/Manager.d.ts +7 -0
  120. package/core/infrastructure/loaders/Manager.js +24 -0
  121. package/core/modules/health/errors/ConnectionNotFoundError.d.ts +4 -0
  122. package/core/modules/health/errors/ConnectionNotFoundError.js +10 -0
  123. package/core/modules/health/errors/HealthCheckError.d.ts +3 -0
  124. package/core/modules/health/errors/HealthCheckError.js +10 -0
  125. package/core/modules/health/errors/TimeoutError.d.ts +4 -0
  126. package/core/modules/health/errors/TimeoutError.js +10 -0
  127. package/core/modules/health/useCases/health/HealthController.d.ts +20 -0
  128. package/core/modules/health/useCases/health/HealthController.js +75 -0
  129. package/core/modules/health/useCases/healthCheck/HealthCheck.d.ts +8 -0
  130. package/core/modules/health/useCases/healthCheck/HealthCheck.js +37 -0
  131. package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.d.ts +8 -0
  132. package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.js +48 -0
  133. package/core/modules/health/useCases/healthCheck/HealthCheckResult.d.ts +6 -0
  134. package/core/modules/health/useCases/healthCheck/HealthCheckResult.js +2 -0
  135. package/core/modules/health/useCases/healthIndicator/HealthIndicator.d.ts +7 -0
  136. package/core/modules/health/useCases/healthIndicator/HealthIndicator.js +14 -0
  137. package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.d.ts +7 -0
  138. package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.js +2 -0
  139. package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.d.ts +21 -0
  140. package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.js +69 -0
  141. package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.d.ts +27 -0
  142. package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.js +73 -0
  143. package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.d.ts +21 -0
  144. package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.js +66 -0
  145. package/core/modules/health/utils/promise.d.ts +1 -0
  146. package/core/modules/health/utils/promise.js +12 -0
  147. package/core/modules/service/useCases/detail/DetailController.d.ts +6 -0
  148. package/core/modules/service/useCases/detail/DetailController.js +25 -0
  149. package/core/utils/Crypto.d.ts +24 -0
  150. package/core/utils/Crypto.js +93 -0
  151. package/core/utils/Hash.d.ts +6 -0
  152. package/core/utils/Hash.js +23 -0
  153. package/core/utils/cache.d.ts +1 -0
  154. package/core/utils/cache.js +16 -0
  155. package/core/utils/commands.d.ts +2 -0
  156. package/core/utils/commands.js +7 -0
  157. package/core/utils/events.d.ts +3 -0
  158. package/core/utils/events.js +11 -0
  159. package/core/utils/logger.d.ts +2 -0
  160. package/core/utils/logger.js +15 -0
  161. package/core/utils/response.d.ts +4 -0
  162. package/core/utils/response.js +11 -0
  163. package/core/utils/validator.d.ts +4 -0
  164. package/core/utils/validator.js +48 -0
  165. package/domain/BalanceMutation.d.ts +18 -0
  166. package/domain/BalanceMutation.js +8 -0
  167. package/domain/ChannelWhatsapp.d.ts +18 -0
  168. package/domain/ChannelWhatsapp.js +2 -0
  169. package/domain/MessageTemplate.d.ts +26 -0
  170. package/domain/MessageTemplate.js +12 -0
  171. package/domain/MessageTemplateCategoryUpdate.d.ts +8 -0
  172. package/domain/MessageTemplateCategoryUpdate.js +2 -0
  173. package/domain/MessageTemplateStatusUpdate.d.ts +8 -0
  174. package/domain/MessageTemplateStatusUpdate.js +2 -0
  175. package/domain/Payment.d.ts +14 -0
  176. package/domain/Payment.js +8 -0
  177. package/domain/Report.d.ts +33 -0
  178. package/domain/Report.js +15 -0
  179. package/domain/TransactionMessaging.d.ts +33 -0
  180. package/domain/TransactionMessaging.js +11 -0
  181. package/domain/TransactionMessagingStatusUpdate.d.ts +6 -0
  182. package/domain/TransactionMessagingStatusUpdate.js +2 -0
  183. package/domain/User.d.ts +25 -0
  184. package/domain/User.js +19 -0
  185. package/domain/index.d.ts +10 -0
  186. package/domain/index.js +26 -0
  187. package/index.d.ts +3 -0
  188. package/index.js +19 -0
  189. package/package.json +57 -0
  190. package/readme.md +4 -0
  191. package/shared/index.d.ts +5 -0
  192. package/shared/index.js +21 -0
  193. package/shared/plugins/axios-logger-mongo.d.ts +5 -0
  194. package/shared/plugins/axios-logger-mongo.js +113 -0
  195. package/shared/plugins/axios.d.ts +1 -0
  196. package/shared/plugins/axios.js +31 -0
  197. package/shared/plugins/cursor.d.ts +29 -0
  198. package/shared/plugins/cursor.js +231 -0
  199. package/shared/plugins/mongoose.d.ts +31 -0
  200. package/shared/plugins/mongoose.js +125 -0
  201. package/shared/resources/JsonResource.d.ts +16 -0
  202. package/shared/resources/JsonResource.js +59 -0
@@ -0,0 +1,31 @@
1
+ import { Schema, Model } from 'mongoose';
2
+ interface PaginationMeta {
3
+ limit: number | undefined;
4
+ offset: number | undefined;
5
+ total: number | undefined;
6
+ }
7
+ export declare class PaginationModel<T> {
8
+ meta: PaginationMeta;
9
+ docs: T[];
10
+ }
11
+ export interface PaginationOptions {
12
+ query?: any | undefined;
13
+ aggregate?: any | undefined;
14
+ populate?: any | undefined;
15
+ select?: any | undefined;
16
+ search?: {
17
+ value: string | undefined;
18
+ fields: string[] | undefined;
19
+ };
20
+ sort?: any | undefined;
21
+ projection?: any | undefined;
22
+ page?: {
23
+ limit?: any | undefined;
24
+ offset?: any | undefined;
25
+ };
26
+ }
27
+ export interface Pagination<T> extends Model<T> {
28
+ paginate(options?: PaginationOptions | undefined, onError?: Function | undefined): Promise<PaginationModel<T> | undefined>;
29
+ }
30
+ export declare function mongoosePaginate<T>(schema: Schema<T>): void;
31
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mongoosePaginate = exports.PaginationModel = void 0;
4
+ class PaginationModel {
5
+ meta = {
6
+ limit: 0,
7
+ offset: 0,
8
+ total: undefined,
9
+ };
10
+ docs = [];
11
+ }
12
+ exports.PaginationModel = PaginationModel;
13
+ function mongoosePaginate(schema) {
14
+ schema.statics.paginate = async function paginate(options, onError) {
15
+ // INIT
16
+ let query = options?.query ?? {};
17
+ let aggregate = options?.aggregate ?? undefined;
18
+ let populate = options?.populate ?? undefined;
19
+ let select = options?.select ?? undefined;
20
+ let search = options?.search ?? undefined;
21
+ let sort = options?.sort ?? '-_id';
22
+ let projection = options?.projection ?? {};
23
+ // PAGING
24
+ const limit = parseInt(options?.page?.limit) > 0 ? parseInt(options?.page?.limit) : 0;
25
+ const skip = parseInt(options?.page?.offset) > 0 ? parseInt(options?.page?.offset) : 0;
26
+ // SEARCHING
27
+ if (search
28
+ && search.value
29
+ && search.fields
30
+ && search.fields.length) {
31
+ let searchQuery = {
32
+ '$regex': search.value,
33
+ '$options': 'i',
34
+ };
35
+ if (search.fields?.length == 1) {
36
+ query[search.fields[0]] = searchQuery;
37
+ }
38
+ else {
39
+ if (!query.$or) {
40
+ query.$or = [];
41
+ }
42
+ search.fields.forEach(function (el) {
43
+ let obj = {};
44
+ obj[el] = searchQuery;
45
+ query.$or.push(obj);
46
+ });
47
+ }
48
+ }
49
+ // QUERY
50
+ let docsPromise;
51
+ if (aggregate != undefined) {
52
+ var mQuery = this.aggregate(aggregate);
53
+ if (select != undefined) {
54
+ mQuery = mQuery.project(select);
55
+ }
56
+ }
57
+ else {
58
+ var mQuery = this.find(query, projection);
59
+ if (select != undefined) {
60
+ mQuery = mQuery.select(select);
61
+ }
62
+ if (populate != undefined) {
63
+ mQuery = mQuery.populate(populate);
64
+ }
65
+ }
66
+ if (sort != undefined) {
67
+ mQuery = mQuery.sort(sort);
68
+ }
69
+ if (limit > 0) {
70
+ mQuery = mQuery.skip(skip);
71
+ mQuery = mQuery.limit(limit);
72
+ }
73
+ docsPromise = mQuery.exec();
74
+ // COUNTING
75
+ let countPromise;
76
+ if (aggregate != undefined) {
77
+ countPromise = this.aggregate(aggregate).count('count');
78
+ }
79
+ else {
80
+ countPromise = this.countDocuments(query).exec();
81
+ }
82
+ // PERFORM
83
+ try {
84
+ const [counts, docs] = await Promise.all([countPromise, docsPromise]);
85
+ let count = 0;
86
+ if (aggregate != undefined) {
87
+ if (counts != undefined
88
+ && counts[0] != undefined
89
+ && counts[0]['count'] != undefined) {
90
+ count = counts[0]['count'];
91
+ }
92
+ }
93
+ else {
94
+ count = counts;
95
+ }
96
+ const myModel = new PaginationModel();
97
+ myModel.meta.total = count;
98
+ myModel.meta.offset = skip;
99
+ if (limit > 0) {
100
+ myModel.meta.limit = limit;
101
+ }
102
+ if (limit == 0) {
103
+ myModel.meta.limit = 0;
104
+ }
105
+ myModel.docs = docs;
106
+ return myModel;
107
+ }
108
+ catch (error) {
109
+ if (onError != undefined) {
110
+ onError(error);
111
+ }
112
+ return undefined;
113
+ }
114
+ };
115
+ const options = {
116
+ virtuals: true,
117
+ transform: function (doc, ret) {
118
+ ret.id = ret._id;
119
+ delete ret.__v;
120
+ }
121
+ };
122
+ schema.set('toJSON', options);
123
+ schema.set('toObject', options);
124
+ }
125
+ exports.mongoosePaginate = mongoosePaginate;
@@ -0,0 +1,16 @@
1
+ export declare class JsonResource {
2
+ [property: string]: any;
3
+ protected hidden: string[];
4
+ protected fillable: string[];
5
+ protected attributes: any;
6
+ constructor(attributes: object);
7
+ protected fill(attributes: any): void;
8
+ protected isAttribute(key: string): boolean;
9
+ protected getAttribute(key: string): any;
10
+ protected setAttribute(key: string, value: any): void;
11
+ protected getHidden(): string[];
12
+ protected setHidden(keys: string[]): void;
13
+ protected getFillable(): string[];
14
+ protected setFillable(keys: string[]): void;
15
+ toJSON(): any;
16
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonResource = void 0;
4
+ class JsonResource {
5
+ hidden = [];
6
+ fillable = [];
7
+ attributes = {};
8
+ constructor(attributes) {
9
+ this.fill(attributes);
10
+ return new Proxy(this, {
11
+ get: (target, property) => {
12
+ if (target.isAttribute(property)) {
13
+ return target.getAttribute(property);
14
+ }
15
+ return target[property];
16
+ },
17
+ set: (target, property, value) => {
18
+ target.setAttribute(property, value);
19
+ return true;
20
+ }
21
+ });
22
+ }
23
+ fill(attributes) {
24
+ for (const key in attributes) {
25
+ this.setAttribute(key, attributes[key]);
26
+ }
27
+ }
28
+ isAttribute(key) {
29
+ return this.attributes.hasOwnProperty(key);
30
+ }
31
+ getAttribute(key) {
32
+ return this.attributes[key];
33
+ }
34
+ setAttribute(key, value) {
35
+ this.attributes[key] = value;
36
+ }
37
+ getHidden() {
38
+ return this.hidden;
39
+ }
40
+ setHidden(keys) {
41
+ this.hidden = keys;
42
+ }
43
+ getFillable() {
44
+ return this.fillable;
45
+ }
46
+ setFillable(keys) {
47
+ this.fillable = keys;
48
+ }
49
+ toJSON() {
50
+ return Object.keys(this.attributes)
51
+ .filter(key => this.getFillable().includes(key))
52
+ .filter(key => !this.getHidden().includes(key))
53
+ .reduce((target, key) => {
54
+ target[key] = this.attributes[key];
55
+ return target;
56
+ }, {});
57
+ }
58
+ }
59
+ exports.JsonResource = JsonResource;