@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.
- package/core/domain/Command.d.ts +3 -0
- package/core/domain/Command.js +2 -0
- package/core/domain/Entity.d.ts +6 -0
- package/core/domain/Entity.js +13 -0
- package/core/domain/Identifier.d.ts +5 -0
- package/core/domain/Identifier.js +13 -0
- package/core/domain/UniqueId.d.ts +4 -0
- package/core/domain/UniqueId.js +11 -0
- package/core/domain/UseCase.d.ts +3 -0
- package/core/domain/UseCase.js +2 -0
- package/core/domain/ValueObject.d.ts +4 -0
- package/core/domain/ValueObject.js +10 -0
- package/core/domain/auth/Auth.d.ts +17 -0
- package/core/domain/auth/Auth.js +41 -0
- package/core/domain/auth/Authenticable.d.ts +4 -0
- package/core/domain/auth/Authenticable.js +2 -0
- package/core/domain/auth/Guard.d.ts +20 -0
- package/core/domain/auth/Guard.js +2 -0
- package/core/domain/auth/TokenGuard.d.ts +33 -0
- package/core/domain/auth/TokenGuard.js +94 -0
- package/core/domain/auth/UserProvider.d.ts +17 -0
- package/core/domain/auth/UserProvider.js +2 -0
- package/core/domain/cache/Cache.d.ts +8 -0
- package/core/domain/cache/Cache.js +2 -0
- package/core/domain/cache/Repo.d.ts +51 -0
- package/core/domain/cache/Repo.js +2 -0
- package/core/domain/cache/Store.d.ts +26 -0
- package/core/domain/cache/Store.js +2 -0
- package/core/domain/events/Event.d.ts +8 -0
- package/core/domain/events/Event.js +2 -0
- package/core/domain/events/Listener.d.ts +4 -0
- package/core/domain/events/Listener.js +2 -0
- package/core/domain/events/Worker.d.ts +3 -0
- package/core/domain/events/Worker.js +2 -0
- package/core/domain/loaders/Loader.d.ts +4 -0
- package/core/domain/loaders/Loader.js +2 -0
- package/core/domain/loaders/Manager.d.ts +3 -0
- package/core/domain/loaders/Manager.js +2 -0
- package/core/errors/AppError.d.ts +10 -0
- package/core/errors/AppError.js +16 -0
- package/core/errors/AuthenticationTokenMissingError.d.ts +5 -0
- package/core/errors/AuthenticationTokenMissingError.js +11 -0
- package/core/errors/BadRequestError.d.ts +5 -0
- package/core/errors/BadRequestError.js +11 -0
- package/core/errors/NotAuthorizedError.d.ts +5 -0
- package/core/errors/NotAuthorizedError.js +11 -0
- package/core/errors/NotFoundError.d.ts +5 -0
- package/core/errors/NotFoundError.js +11 -0
- package/core/errors/RequestValidationError.d.ts +10 -0
- package/core/errors/RequestValidationError.js +47 -0
- package/core/errors/ValidationError.d.ts +8 -0
- package/core/errors/ValidationError.js +19 -0
- package/core/errors/WrongAuthenticationTokenError.d.ts +5 -0
- package/core/errors/WrongAuthenticationTokenError.js +11 -0
- package/core/errors/WrongCredentialsError.d.ts +5 -0
- package/core/errors/WrongCredentialsError.js +11 -0
- package/core/index.d.ts +48 -0
- package/core/index.js +69 -0
- package/core/infrastructure/Container.d.ts +1 -0
- package/core/infrastructure/Container.js +8 -0
- package/core/infrastructure/Controller.d.ts +9 -0
- package/core/infrastructure/Controller.js +30 -0
- package/core/infrastructure/DatabaseRepository.d.ts +35 -0
- package/core/infrastructure/DatabaseRepository.js +2 -0
- package/core/infrastructure/Mapper.d.ts +2 -0
- package/core/infrastructure/Mapper.js +6 -0
- package/core/infrastructure/Repo.d.ts +2 -0
- package/core/infrastructure/Repo.js +6 -0
- package/core/infrastructure/cache/Cache.d.ts +47 -0
- package/core/infrastructure/cache/Cache.js +101 -0
- package/core/infrastructure/cache/InMemoryCache.d.ts +20 -0
- package/core/infrastructure/cache/InMemoryCache.js +62 -0
- package/core/infrastructure/cache/RedisCache.d.ts +15 -0
- package/core/infrastructure/cache/RedisCache.js +51 -0
- package/core/infrastructure/cache/Repo.d.ts +25 -0
- package/core/infrastructure/cache/Repo.js +103 -0
- package/core/infrastructure/cache/stores/ArrayStore.d.ts +17 -0
- package/core/infrastructure/cache/stores/ArrayStore.js +65 -0
- package/core/infrastructure/cache/stores/FileStore.d.ts +14 -0
- package/core/infrastructure/cache/stores/FileStore.js +171 -0
- package/core/infrastructure/cache/stores/NullStore.d.ts +9 -0
- package/core/infrastructure/cache/stores/NullStore.js +24 -0
- package/core/infrastructure/cache/stores/RedisStore.d.ts +13 -0
- package/core/infrastructure/cache/stores/RedisStore.js +44 -0
- package/core/infrastructure/events/ChannelEvent.d.ts +9 -0
- package/core/infrastructure/events/ChannelEvent.js +37 -0
- package/core/infrastructure/events/Connection.d.ts +8 -0
- package/core/infrastructure/events/Connection.js +30 -0
- package/core/infrastructure/events/Event.d.ts +16 -0
- package/core/infrastructure/events/Event.js +42 -0
- package/core/infrastructure/events/Listener.d.ts +23 -0
- package/core/infrastructure/events/Listener.js +77 -0
- package/core/infrastructure/events/Worker.d.ts +9 -0
- package/core/infrastructure/events/Worker.js +34 -0
- package/core/infrastructure/events/grpc/Connection.d.ts +9 -0
- package/core/infrastructure/events/grpc/Connection.js +34 -0
- package/core/infrastructure/events/grpc/Event.d.ts +12 -0
- package/core/infrastructure/events/grpc/Event.js +80 -0
- package/core/infrastructure/events/grpc/Listener.d.ts +16 -0
- package/core/infrastructure/events/grpc/Listener.js +74 -0
- package/core/infrastructure/events/rpc/Event.d.ts +13 -0
- package/core/infrastructure/events/rpc/Event.js +98 -0
- package/core/infrastructure/events/rpc/Listener.d.ts +6 -0
- package/core/infrastructure/events/rpc/Listener.js +30 -0
- package/core/infrastructure/http/App.d.ts +15 -0
- package/core/infrastructure/http/App.js +73 -0
- package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.js +8 -0
- package/core/infrastructure/http/middleware/errorMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/errorMiddleware.js +18 -0
- package/core/infrastructure/http/middleware/loggerMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/loggerMiddleware.js +17 -0
- package/core/infrastructure/http/middleware/routeNotFoundMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/routeNotFoundMiddleware.js +11 -0
- package/core/infrastructure/http/middleware/validationMiddleware.d.ts +4 -0
- package/core/infrastructure/http/middleware/validationMiddleware.js +35 -0
- package/core/infrastructure/loaders/Loader.d.ts +8 -0
- package/core/infrastructure/loaders/Loader.js +14 -0
- package/core/infrastructure/loaders/Manager.d.ts +7 -0
- package/core/infrastructure/loaders/Manager.js +24 -0
- package/core/modules/health/errors/ConnectionNotFoundError.d.ts +4 -0
- package/core/modules/health/errors/ConnectionNotFoundError.js +10 -0
- package/core/modules/health/errors/HealthCheckError.d.ts +3 -0
- package/core/modules/health/errors/HealthCheckError.js +10 -0
- package/core/modules/health/errors/TimeoutError.d.ts +4 -0
- package/core/modules/health/errors/TimeoutError.js +10 -0
- package/core/modules/health/useCases/health/HealthController.d.ts +20 -0
- package/core/modules/health/useCases/health/HealthController.js +75 -0
- package/core/modules/health/useCases/healthCheck/HealthCheck.d.ts +8 -0
- package/core/modules/health/useCases/healthCheck/HealthCheck.js +37 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.d.ts +8 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.js +48 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckResult.d.ts +6 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckResult.js +2 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicator.d.ts +7 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicator.js +14 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.d.ts +7 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.js +2 -0
- package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.d.ts +21 -0
- package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.js +69 -0
- package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.d.ts +27 -0
- package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.js +73 -0
- package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.d.ts +21 -0
- package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.js +66 -0
- package/core/modules/health/utils/promise.d.ts +1 -0
- package/core/modules/health/utils/promise.js +12 -0
- package/core/modules/service/useCases/detail/DetailController.d.ts +6 -0
- package/core/modules/service/useCases/detail/DetailController.js +25 -0
- package/core/utils/Crypto.d.ts +24 -0
- package/core/utils/Crypto.js +93 -0
- package/core/utils/Hash.d.ts +6 -0
- package/core/utils/Hash.js +23 -0
- package/core/utils/cache.d.ts +1 -0
- package/core/utils/cache.js +16 -0
- package/core/utils/commands.d.ts +2 -0
- package/core/utils/commands.js +7 -0
- package/core/utils/events.d.ts +3 -0
- package/core/utils/events.js +11 -0
- package/core/utils/logger.d.ts +2 -0
- package/core/utils/logger.js +15 -0
- package/core/utils/response.d.ts +4 -0
- package/core/utils/response.js +11 -0
- package/core/utils/validator.d.ts +4 -0
- package/core/utils/validator.js +48 -0
- package/domain/BalanceMutation.d.ts +18 -0
- package/domain/BalanceMutation.js +8 -0
- package/domain/ChannelWhatsapp.d.ts +18 -0
- package/domain/ChannelWhatsapp.js +2 -0
- package/domain/MessageTemplate.d.ts +26 -0
- package/domain/MessageTemplate.js +12 -0
- package/domain/MessageTemplateCategoryUpdate.d.ts +8 -0
- package/domain/MessageTemplateCategoryUpdate.js +2 -0
- package/domain/MessageTemplateStatusUpdate.d.ts +8 -0
- package/domain/MessageTemplateStatusUpdate.js +2 -0
- package/domain/Payment.d.ts +14 -0
- package/domain/Payment.js +8 -0
- package/domain/Report.d.ts +33 -0
- package/domain/Report.js +15 -0
- package/domain/TransactionMessaging.d.ts +33 -0
- package/domain/TransactionMessaging.js +11 -0
- package/domain/TransactionMessagingStatusUpdate.d.ts +6 -0
- package/domain/TransactionMessagingStatusUpdate.js +2 -0
- package/domain/User.d.ts +25 -0
- package/domain/User.js +19 -0
- package/domain/index.d.ts +10 -0
- package/domain/index.js +26 -0
- package/index.d.ts +3 -0
- package/index.js +19 -0
- package/package.json +57 -0
- package/readme.md +4 -0
- package/shared/index.d.ts +5 -0
- package/shared/index.js +21 -0
- package/shared/plugins/axios-logger-mongo.d.ts +5 -0
- package/shared/plugins/axios-logger-mongo.js +113 -0
- package/shared/plugins/axios.d.ts +1 -0
- package/shared/plugins/axios.js +31 -0
- package/shared/plugins/cursor.d.ts +29 -0
- package/shared/plugins/cursor.js +231 -0
- package/shared/plugins/mongoose.d.ts +31 -0
- package/shared/plugins/mongoose.js +125 -0
- package/shared/resources/JsonResource.d.ts +16 -0
- package/shared/resources/JsonResource.js +59 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Repo as Cache } from '../../../core/domain/cache/Repo';
|
|
2
|
+
import { Store } from '../../../core/domain/cache/Store';
|
|
3
|
+
export declare class Repo implements Cache {
|
|
4
|
+
protected store: Store;
|
|
5
|
+
protected ttl: number;
|
|
6
|
+
constructor(store: Store);
|
|
7
|
+
has(key: string): Promise<boolean>;
|
|
8
|
+
missing(key: string): Promise<boolean>;
|
|
9
|
+
get<T>(key: string, _default?: any): Promise<T | null>;
|
|
10
|
+
pull<T>(key: string, _default?: any): Promise<T | null>;
|
|
11
|
+
put(key: string, value: any, ttl?: number): Promise<boolean>;
|
|
12
|
+
add(key: string, value: any, ttl?: number): Promise<boolean>;
|
|
13
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
14
|
+
remember<T>(key: string, callback: Function, ttl?: number): Promise<T>;
|
|
15
|
+
rememberForever<T>(key: string, callback: Function): Promise<T>;
|
|
16
|
+
forget(key: string): Promise<boolean>;
|
|
17
|
+
flush(): Promise<boolean>;
|
|
18
|
+
getDefaultCacheTime(): number;
|
|
19
|
+
setDefaultCacheTime(ttl: number): Repo;
|
|
20
|
+
getStore(): Store;
|
|
21
|
+
setStore(store: Store): Repo;
|
|
22
|
+
protected itemKey(key: string): string;
|
|
23
|
+
protected getSeconds(ttl: any): number;
|
|
24
|
+
private value;
|
|
25
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Repo = void 0;
|
|
4
|
+
class Repo {
|
|
5
|
+
store;
|
|
6
|
+
ttl;
|
|
7
|
+
constructor(store) {
|
|
8
|
+
this.store = store;
|
|
9
|
+
this.ttl = 3600;
|
|
10
|
+
}
|
|
11
|
+
async has(key) {
|
|
12
|
+
return !!await this.get(key);
|
|
13
|
+
}
|
|
14
|
+
async missing(key) {
|
|
15
|
+
return !await this.has(key);
|
|
16
|
+
}
|
|
17
|
+
async get(key, _default) {
|
|
18
|
+
const value = await this.store.get(this.itemKey(key));
|
|
19
|
+
return value || await this.value(_default);
|
|
20
|
+
}
|
|
21
|
+
async pull(key, _default) {
|
|
22
|
+
const value = await this.get(key);
|
|
23
|
+
if (value) {
|
|
24
|
+
await this.forget(key);
|
|
25
|
+
}
|
|
26
|
+
return value || await this.value(_default);
|
|
27
|
+
}
|
|
28
|
+
async put(key, value, ttl = this.ttl) {
|
|
29
|
+
const seconds = this.getSeconds(ttl);
|
|
30
|
+
if (seconds <= 0) {
|
|
31
|
+
return await this.forget(key);
|
|
32
|
+
}
|
|
33
|
+
const result = await this.store.put(this.itemKey(key), value, seconds);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
async add(key, value, ttl = this.ttl) {
|
|
37
|
+
let seconds = undefined;
|
|
38
|
+
if (!ttl) {
|
|
39
|
+
seconds = this.getSeconds(ttl);
|
|
40
|
+
if (seconds <= 0) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (await this.missing(key)) {
|
|
45
|
+
return await this.put(key, value, seconds);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
async forever(key, value) {
|
|
50
|
+
const result = await this.store.forever(this.itemKey(key), value);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
async remember(key, callback, ttl = this.ttl) {
|
|
54
|
+
let value = await this.get(key);
|
|
55
|
+
if (value) {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
value = await this.value(callback);
|
|
59
|
+
await this.put(key, value, ttl);
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
async rememberForever(key, callback) {
|
|
63
|
+
let value = await this.get(key);
|
|
64
|
+
if (value) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
value = await this.value(callback());
|
|
68
|
+
await this.forever(key, value);
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
async forget(key) {
|
|
72
|
+
const result = await this.store.forget(this.itemKey(key));
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
async flush() {
|
|
76
|
+
const result = await this.store.flush();
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
getDefaultCacheTime() {
|
|
80
|
+
return this.ttl;
|
|
81
|
+
}
|
|
82
|
+
setDefaultCacheTime(ttl) {
|
|
83
|
+
this.ttl = ttl;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
getStore() {
|
|
87
|
+
return this.store;
|
|
88
|
+
}
|
|
89
|
+
setStore(store) {
|
|
90
|
+
this.store = store;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
itemKey(key) {
|
|
94
|
+
return this.store.getPrefix() + key;
|
|
95
|
+
}
|
|
96
|
+
getSeconds(ttl) {
|
|
97
|
+
return ttl;
|
|
98
|
+
}
|
|
99
|
+
async value(value) {
|
|
100
|
+
return typeof value === 'function' ? await value() : value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.Repo = Repo;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Store } from '../../../../core/domain/cache/Store';
|
|
3
|
+
type CacheRecord<T> = {
|
|
4
|
+
data: T;
|
|
5
|
+
expire?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class ArrayStore implements Store {
|
|
8
|
+
protected readonly store: Map<string, CacheRecord<any>>;
|
|
9
|
+
protected readonly timeoutRefs: Map<string, NodeJS.Timeout>;
|
|
10
|
+
get<T>(key: string): Promise<T | null>;
|
|
11
|
+
put(key: string, value: unknown, ttl: number): Promise<boolean>;
|
|
12
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
13
|
+
forget(key: string): Promise<boolean>;
|
|
14
|
+
flush(): Promise<boolean>;
|
|
15
|
+
getPrefix(): string;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayStore = void 0;
|
|
4
|
+
class ArrayStore {
|
|
5
|
+
store = new Map();
|
|
6
|
+
timeoutRefs = new Map();
|
|
7
|
+
async get(key) {
|
|
8
|
+
const now = Date.now();
|
|
9
|
+
const record = this.store.get(key);
|
|
10
|
+
const expiration = record?.expire ?? Infinity;
|
|
11
|
+
if (!record || expiration < now) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return record.data;
|
|
15
|
+
}
|
|
16
|
+
async put(key, value, ttl) {
|
|
17
|
+
const record = { data: value, expire: ttl * 1000 + Date.now() };
|
|
18
|
+
const oldRecord = this.store.get(key);
|
|
19
|
+
if (oldRecord) {
|
|
20
|
+
await this.forget(key);
|
|
21
|
+
}
|
|
22
|
+
const ref = setTimeout(async () => {
|
|
23
|
+
await this.forget(key);
|
|
24
|
+
}, ttl * 1000);
|
|
25
|
+
ref.unref();
|
|
26
|
+
this.timeoutRefs.set(key, ref);
|
|
27
|
+
this.store.set(key, record);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
async forever(key, value) {
|
|
31
|
+
const record = { data: value };
|
|
32
|
+
const oldRecord = this.store.get(key);
|
|
33
|
+
if (oldRecord) {
|
|
34
|
+
await this.forget(key);
|
|
35
|
+
}
|
|
36
|
+
this.store.set(key, record);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
async forget(key) {
|
|
40
|
+
let keys = [key];
|
|
41
|
+
if (key.includes('*')) {
|
|
42
|
+
const regExp = new RegExp(key.replace('*', '.*'));
|
|
43
|
+
keys = Array.from(this.store.keys()).filter((k) => k.match(regExp));
|
|
44
|
+
}
|
|
45
|
+
keys.forEach((key) => {
|
|
46
|
+
const timeoutRef = this.timeoutRefs.get(key);
|
|
47
|
+
if (timeoutRef) {
|
|
48
|
+
clearTimeout(timeoutRef);
|
|
49
|
+
this.timeoutRefs.delete(key);
|
|
50
|
+
}
|
|
51
|
+
this.store.delete(key);
|
|
52
|
+
});
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
async flush() {
|
|
56
|
+
this.timeoutRefs.forEach((ref) => clearTimeout(ref));
|
|
57
|
+
this.timeoutRefs.clear();
|
|
58
|
+
this.store.clear();
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
getPrefix() {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.ArrayStore = ArrayStore;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Store } from '../../../../core/domain/cache/Store';
|
|
2
|
+
export declare class FileStore implements Store {
|
|
3
|
+
protected directory: string;
|
|
4
|
+
constructor(directory: string);
|
|
5
|
+
get<T>(key: string): Promise<T | null>;
|
|
6
|
+
put(key: string, value: unknown, ttl: number): Promise<boolean>;
|
|
7
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
8
|
+
forget(key: string): Promise<boolean>;
|
|
9
|
+
flush(): Promise<boolean>;
|
|
10
|
+
getPrefix(): string;
|
|
11
|
+
protected getPayload<T>(key: string): Promise<T | null>;
|
|
12
|
+
protected path(key: string): string;
|
|
13
|
+
protected ensureDirectoryExists(path: string): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.FileStore = void 0;
|
|
30
|
+
const promises_1 = __importStar(require("fs/promises"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const crypto_1 = require("crypto");
|
|
33
|
+
class Hash {
|
|
34
|
+
static make(text) {
|
|
35
|
+
return (0, crypto_1.createHash)('sha256').update(text).digest('hex');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
class File {
|
|
39
|
+
static async exists(path) {
|
|
40
|
+
try {
|
|
41
|
+
await promises_1.default.access(path, promises_1.constants.F_OK);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
static async mkdir(path) {
|
|
48
|
+
try {
|
|
49
|
+
await promises_1.default.mkdir(path, { recursive: true });
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
static async read(path) {
|
|
57
|
+
try {
|
|
58
|
+
const value = await promises_1.default.readFile(path, 'utf-8');
|
|
59
|
+
return value ? JSON.parse(value) : null;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
static async store(path, data) {
|
|
66
|
+
try {
|
|
67
|
+
const json = JSON.stringify(data);
|
|
68
|
+
await promises_1.default.writeFile(path, json, 'utf-8');
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
static async delete(path) {
|
|
76
|
+
try {
|
|
77
|
+
await promises_1.default.unlink(path);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
static async rm(path) {
|
|
85
|
+
try {
|
|
86
|
+
await promises_1.default.rm(path, { recursive: true, force: true });
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
class FileStore {
|
|
95
|
+
directory;
|
|
96
|
+
constructor(directory) {
|
|
97
|
+
this.directory = path_1.default.resolve(directory);
|
|
98
|
+
}
|
|
99
|
+
async get(key) {
|
|
100
|
+
return await this.getPayload(key);
|
|
101
|
+
}
|
|
102
|
+
async put(key, value, ttl) {
|
|
103
|
+
const record = { data: value, expire: ttl * 1000 + Date.now() };
|
|
104
|
+
try {
|
|
105
|
+
const path = this.path(key);
|
|
106
|
+
await this.ensureDirectoryExists(path);
|
|
107
|
+
await File.store(path, record);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async forever(key, value) {
|
|
115
|
+
const record = { data: value };
|
|
116
|
+
try {
|
|
117
|
+
const path = this.path(key);
|
|
118
|
+
await this.ensureDirectoryExists(path);
|
|
119
|
+
await File.store(path, record);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async forget(key) {
|
|
127
|
+
try {
|
|
128
|
+
const path = this.path(key);
|
|
129
|
+
await File.delete(path);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async flush() {
|
|
137
|
+
try {
|
|
138
|
+
await File.rm(this.directory);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
getPrefix() {
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
async getPayload(key) {
|
|
149
|
+
const path = this.path(key);
|
|
150
|
+
let now = Date.now();
|
|
151
|
+
let record = await File.read(path);
|
|
152
|
+
const expiration = record?.expire ?? Infinity;
|
|
153
|
+
if (!record || expiration < now) {
|
|
154
|
+
await this.forget(key);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return record.data;
|
|
158
|
+
}
|
|
159
|
+
path(key) {
|
|
160
|
+
const hash = Hash.make(key);
|
|
161
|
+
const parts = hash.match(/.{2}/g).slice(0, 2);
|
|
162
|
+
return path_1.default.join(this.directory, ...parts, hash);
|
|
163
|
+
}
|
|
164
|
+
async ensureDirectoryExists(path) {
|
|
165
|
+
const directory = path_1.default.dirname(path);
|
|
166
|
+
if (!await File.exists(directory)) {
|
|
167
|
+
await File.mkdir(directory);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.FileStore = FileStore;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Store } from '../../../../core/domain/cache/Store';
|
|
2
|
+
export declare class NullStore implements Store {
|
|
3
|
+
get<T>(key: string): Promise<T | null>;
|
|
4
|
+
put(key: string, value: any, ttl: number): Promise<boolean>;
|
|
5
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
6
|
+
forget(key: string): Promise<boolean>;
|
|
7
|
+
flush(): Promise<boolean>;
|
|
8
|
+
getPrefix(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NullStore = void 0;
|
|
4
|
+
class NullStore {
|
|
5
|
+
async get(key) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
async put(key, value, ttl) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
async forever(key, value) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
async forget(key) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
async flush() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
getPrefix() {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.NullStore = NullStore;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Store } from '../../../../core/domain/cache/Store';
|
|
2
|
+
import { Redis } from 'ioredis';
|
|
3
|
+
export declare class RedisStore implements Store {
|
|
4
|
+
protected readonly redis: Redis;
|
|
5
|
+
protected readonly prefix: string;
|
|
6
|
+
constructor(redis: Redis, prefix?: string);
|
|
7
|
+
get<T>(key: string): Promise<T | null>;
|
|
8
|
+
put(key: string, value: unknown, ttl: number): Promise<boolean>;
|
|
9
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
10
|
+
forget(key: string): Promise<boolean>;
|
|
11
|
+
flush(): Promise<boolean>;
|
|
12
|
+
getPrefix(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisStore = void 0;
|
|
4
|
+
class RedisStore {
|
|
5
|
+
redis;
|
|
6
|
+
prefix;
|
|
7
|
+
constructor(redis, prefix = '') {
|
|
8
|
+
this.redis = redis;
|
|
9
|
+
this.prefix = prefix;
|
|
10
|
+
}
|
|
11
|
+
async get(key) {
|
|
12
|
+
try {
|
|
13
|
+
const value = await this.redis.get(key);
|
|
14
|
+
if (value) {
|
|
15
|
+
return JSON.parse(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
await this.forget(key);
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
async put(key, value, ttl) {
|
|
24
|
+
return !!await this.redis.set(key, JSON.stringify(value), 'EX', ttl);
|
|
25
|
+
}
|
|
26
|
+
async forever(key, value) {
|
|
27
|
+
return !!await this.redis.set(key, JSON.stringify(value));
|
|
28
|
+
}
|
|
29
|
+
async forget(key) {
|
|
30
|
+
const keys = await this.redis.keys(key);
|
|
31
|
+
const pipeline = this.redis.pipeline();
|
|
32
|
+
keys.forEach((key) => {
|
|
33
|
+
pipeline.del(key);
|
|
34
|
+
});
|
|
35
|
+
return !!await pipeline.exec();
|
|
36
|
+
}
|
|
37
|
+
async flush() {
|
|
38
|
+
return await this.forget('*');
|
|
39
|
+
}
|
|
40
|
+
getPrefix() {
|
|
41
|
+
return this.prefix;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.RedisStore = RedisStore;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChannelWrapper } from 'amqp-connection-manager';
|
|
2
|
+
type ChannelType = 'publisher' | 'default';
|
|
3
|
+
export declare class ChannelEvent {
|
|
4
|
+
private static channels;
|
|
5
|
+
private constructor();
|
|
6
|
+
private static createChannel;
|
|
7
|
+
static getChannel(channelType?: ChannelType): ChannelWrapper;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
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.ChannelEvent = void 0;
|
|
7
|
+
const Connection_1 = require("./Connection");
|
|
8
|
+
const logger_1 = __importDefault(require("../../../core/utils/logger"));
|
|
9
|
+
class ChannelEvent {
|
|
10
|
+
static channels = {
|
|
11
|
+
default: null,
|
|
12
|
+
publisher: null
|
|
13
|
+
};
|
|
14
|
+
constructor() {
|
|
15
|
+
//
|
|
16
|
+
}
|
|
17
|
+
static createChannel(channelType = 'default') {
|
|
18
|
+
const connection = channelType === 'default'
|
|
19
|
+
? Connection_1.Connection.getConnection('default')
|
|
20
|
+
: Connection_1.Connection.getConnection('publisher');
|
|
21
|
+
const channel = connection.createChannel({ json: true });
|
|
22
|
+
channel.on('error', (err) => {
|
|
23
|
+
logger_1.default.error('AMQP channel error:', { msg: err.message, stack: err.stack });
|
|
24
|
+
this.channels[channelType] = null;
|
|
25
|
+
});
|
|
26
|
+
channel.on('close', () => {
|
|
27
|
+
logger_1.default.error('AMQP channel error:', { msg: 'closed' });
|
|
28
|
+
this.channels[channelType] = null;
|
|
29
|
+
});
|
|
30
|
+
this.channels[channelType] = channel;
|
|
31
|
+
return channel;
|
|
32
|
+
}
|
|
33
|
+
static getChannel(channelType = 'default') {
|
|
34
|
+
return this.channels[channelType] ?? this.createChannel(channelType);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ChannelEvent = ChannelEvent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AmqpConnectionManager, Channel, ChannelWrapper } from 'amqp-connection-manager';
|
|
2
|
+
export { Channel, ChannelWrapper };
|
|
3
|
+
export declare class Connection {
|
|
4
|
+
private static connections;
|
|
5
|
+
private constructor();
|
|
6
|
+
private static createConnection;
|
|
7
|
+
static getConnection(connectionType?: string): AmqpConnectionManager;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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.Connection = void 0;
|
|
7
|
+
const amqp_connection_manager_1 = __importDefault(require("amqp-connection-manager"));
|
|
8
|
+
const logger_1 = __importDefault(require("../../../core/utils/logger"));
|
|
9
|
+
class Connection {
|
|
10
|
+
static connections = {};
|
|
11
|
+
constructor() {
|
|
12
|
+
//
|
|
13
|
+
}
|
|
14
|
+
static createConnection(connectionType = 'default') {
|
|
15
|
+
const connection = amqp_connection_manager_1.default.connect([process.env.APP_MQ]);
|
|
16
|
+
connection.on('connect', () => {
|
|
17
|
+
logger_1.default.debug('Connection established successfully.', { connectionType });
|
|
18
|
+
});
|
|
19
|
+
connection.on('disconnect', (params) => {
|
|
20
|
+
logger_1.default.warn('Connection lost. ', { connectionType, reason: params.err.message });
|
|
21
|
+
this.connections[connectionType] = null;
|
|
22
|
+
});
|
|
23
|
+
this.connections[connectionType] = connection;
|
|
24
|
+
return connection;
|
|
25
|
+
}
|
|
26
|
+
static getConnection(connectionType = 'default') {
|
|
27
|
+
return this.connections[connectionType] ?? this.createConnection(connectionType);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Connection = Connection;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Event as EventContract } from "../../../core/domain/events/Event";
|
|
2
|
+
import { AmqpConnectionManager, Channel, ChannelWrapper } from "amqp-connection-manager";
|
|
3
|
+
export { Channel, ChannelWrapper };
|
|
4
|
+
export declare abstract class Event<T> implements EventContract {
|
|
5
|
+
protected connection: AmqpConnectionManager;
|
|
6
|
+
protected channel: ChannelWrapper;
|
|
7
|
+
protected priority: number;
|
|
8
|
+
protected payload: T;
|
|
9
|
+
abstract exchange: string;
|
|
10
|
+
abstract topic: string;
|
|
11
|
+
constructor(payload: T);
|
|
12
|
+
init(): this;
|
|
13
|
+
protected setup(channel: Channel): void;
|
|
14
|
+
publish(options?: {}): Promise<boolean>;
|
|
15
|
+
publishWithoutPersistence(options?: {}): Promise<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Event = void 0;
|
|
4
|
+
const core_1 = require("../../../core");
|
|
5
|
+
const Connection_1 = require("./Connection");
|
|
6
|
+
const ChannelEvent_1 = require("./ChannelEvent");
|
|
7
|
+
class Event {
|
|
8
|
+
connection;
|
|
9
|
+
channel;
|
|
10
|
+
priority;
|
|
11
|
+
payload;
|
|
12
|
+
constructor(payload) {
|
|
13
|
+
this.connection = Connection_1.Connection.getConnection("publisher");
|
|
14
|
+
this.payload = payload;
|
|
15
|
+
this.priority = 0;
|
|
16
|
+
}
|
|
17
|
+
init() {
|
|
18
|
+
this.channel = ChannelEvent_1.ChannelEvent.getChannel("publisher");
|
|
19
|
+
this.channel.addSetup(this.setup.bind(this));
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
setup(channel) {
|
|
23
|
+
channel.assertExchange(this.exchange, "topic", { durable: false });
|
|
24
|
+
}
|
|
25
|
+
async publish(options = {}) {
|
|
26
|
+
core_1.logger.debug("Publish message %s", this.constructor.name);
|
|
27
|
+
const result = await this.channel.publish(this.exchange, this.topic, this.payload, Object.assign({
|
|
28
|
+
deliveryMode: 2,
|
|
29
|
+
persistent: true,
|
|
30
|
+
}, options));
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async publishWithoutPersistence(options = {}) {
|
|
34
|
+
core_1.logger.debug("Publish message %s", this.constructor.name);
|
|
35
|
+
const result = await this.channel.publish(this.exchange, this.topic, this.payload, Object.assign({
|
|
36
|
+
deliveryMode: 1,
|
|
37
|
+
persistent: false,
|
|
38
|
+
}, options));
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Event = Event;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Listener as ListenerContract } from '../../../core/domain/events/Listener';
|
|
2
|
+
import { AmqpConnectionManager, Channel, ChannelWrapper } from 'amqp-connection-manager';
|
|
3
|
+
import { Connection } from './Connection';
|
|
4
|
+
export { Channel, ChannelWrapper, Connection };
|
|
5
|
+
export declare abstract class Listener<T> implements ListenerContract {
|
|
6
|
+
protected static instance: Listener<any>;
|
|
7
|
+
protected connection: AmqpConnectionManager;
|
|
8
|
+
protected channel: ChannelWrapper;
|
|
9
|
+
protected service: string;
|
|
10
|
+
protected extraQueues: any;
|
|
11
|
+
abstract exchange: string;
|
|
12
|
+
abstract topic: string;
|
|
13
|
+
protected exclusiveConnection: boolean;
|
|
14
|
+
constructor();
|
|
15
|
+
init(): this;
|
|
16
|
+
protected setup(channel: Channel): void;
|
|
17
|
+
protected setupExtraQueue(channel: Channel, suffixes?: string[]): void;
|
|
18
|
+
abstract onMessage(data: T, ack: Function, nack?: Function): any;
|
|
19
|
+
listen(): Promise<import("amqplib").Replies.Consume>;
|
|
20
|
+
get queue(): string;
|
|
21
|
+
get connectionName(): string;
|
|
22
|
+
protected parseMessage(msg: any): any;
|
|
23
|
+
}
|