@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,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity = void 0;
|
|
4
|
+
const UniqueId_1 = require("../../core/domain/UniqueId");
|
|
5
|
+
class Entity {
|
|
6
|
+
_id;
|
|
7
|
+
props;
|
|
8
|
+
constructor(props, id) {
|
|
9
|
+
this._id = id ?? new UniqueId_1.UniqueId();
|
|
10
|
+
this.props = props;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Entity = Entity;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Identifier = void 0;
|
|
4
|
+
class Identifier {
|
|
5
|
+
value;
|
|
6
|
+
constructor(value) {
|
|
7
|
+
this.value = value;
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return String(this.value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Identifier = Identifier;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueId = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const Identifier_1 = require("../../core/domain/Identifier");
|
|
6
|
+
class UniqueId extends Identifier_1.Identifier {
|
|
7
|
+
constructor(id) {
|
|
8
|
+
super(id ?? (0, node_crypto_1.randomUUID)());
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.UniqueId = UniqueId;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import TokenGuard from './TokenGuard';
|
|
2
|
+
import UserProvider from './UserProvider';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
*/
|
|
6
|
+
export declare class Auth {
|
|
7
|
+
private static _instance;
|
|
8
|
+
private _provider;
|
|
9
|
+
private _request;
|
|
10
|
+
private constructor();
|
|
11
|
+
static getInstance(): Auth;
|
|
12
|
+
static guard(): TokenGuard;
|
|
13
|
+
setUserProvider(provider: UserProvider): this;
|
|
14
|
+
setRequest(request: any): this;
|
|
15
|
+
private tokenGuard;
|
|
16
|
+
}
|
|
17
|
+
export default Auth;
|
|
@@ -0,0 +1,41 @@
|
|
|
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.Auth = void 0;
|
|
7
|
+
const TokenGuard_1 = __importDefault(require("./TokenGuard"));
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
11
|
+
class Auth {
|
|
12
|
+
static _instance;
|
|
13
|
+
_provider;
|
|
14
|
+
_request;
|
|
15
|
+
constructor() {
|
|
16
|
+
//
|
|
17
|
+
}
|
|
18
|
+
static getInstance() {
|
|
19
|
+
if (!this._instance) {
|
|
20
|
+
this._instance = new Auth();
|
|
21
|
+
}
|
|
22
|
+
return this._instance;
|
|
23
|
+
}
|
|
24
|
+
static guard() {
|
|
25
|
+
return Auth.getInstance()
|
|
26
|
+
.tokenGuard();
|
|
27
|
+
}
|
|
28
|
+
setUserProvider(provider) {
|
|
29
|
+
this._provider = provider;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
setRequest(request) {
|
|
33
|
+
this._request = request;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
tokenGuard() {
|
|
37
|
+
return new TokenGuard_1.default(this._provider, this._request);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Auth = Auth;
|
|
41
|
+
exports.default = Auth;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Authenticable from './Authenticable';
|
|
2
|
+
export interface Guard {
|
|
3
|
+
/**
|
|
4
|
+
* Determine if the current user is authenticated.
|
|
5
|
+
*/
|
|
6
|
+
check(): Promise<boolean>;
|
|
7
|
+
/**
|
|
8
|
+
* Determine if the current user is a guest.
|
|
9
|
+
*/
|
|
10
|
+
guest(): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Set the current user.
|
|
13
|
+
*/
|
|
14
|
+
setUser(user: Authenticable): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Get the currently authenticated user.
|
|
17
|
+
*/
|
|
18
|
+
user(): Promise<Authenticable | null>;
|
|
19
|
+
}
|
|
20
|
+
export default Guard;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Authenticable from './Authenticable';
|
|
2
|
+
import Guard from './Guard';
|
|
3
|
+
import UserProvider from './UserProvider';
|
|
4
|
+
export declare class TokenGuard implements Guard {
|
|
5
|
+
/**
|
|
6
|
+
* The request instance.
|
|
7
|
+
*/
|
|
8
|
+
private _req;
|
|
9
|
+
/**
|
|
10
|
+
* The user provider implementation.
|
|
11
|
+
*/
|
|
12
|
+
private _provider;
|
|
13
|
+
/**
|
|
14
|
+
* The currently authenticated user.
|
|
15
|
+
*/
|
|
16
|
+
private _user;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new authtentication guard.
|
|
19
|
+
*/
|
|
20
|
+
constructor(provider: UserProvider, req: any);
|
|
21
|
+
/**
|
|
22
|
+
* Determine if the current user is authenticated. If not, throw an error.
|
|
23
|
+
*/
|
|
24
|
+
authenticate(): Promise<Authenticable>;
|
|
25
|
+
check(): Promise<boolean>;
|
|
26
|
+
guest(): Promise<boolean>;
|
|
27
|
+
setUser(user: Authenticable): Promise<void>;
|
|
28
|
+
setRequest(req: any): Promise<void>;
|
|
29
|
+
user(): Promise<Authenticable | null>;
|
|
30
|
+
private getTokenFromRequest;
|
|
31
|
+
private getUserKeyTokenFromRequest;
|
|
32
|
+
}
|
|
33
|
+
export default TokenGuard;
|
|
@@ -0,0 +1,94 @@
|
|
|
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.TokenGuard = void 0;
|
|
7
|
+
const WrongCredentialsError_1 = __importDefault(require("../../../core/errors/WrongCredentialsError"));
|
|
8
|
+
class TokenGuard {
|
|
9
|
+
/**
|
|
10
|
+
* The request instance.
|
|
11
|
+
*/
|
|
12
|
+
_req;
|
|
13
|
+
/**
|
|
14
|
+
* The user provider implementation.
|
|
15
|
+
*/
|
|
16
|
+
_provider;
|
|
17
|
+
/**
|
|
18
|
+
* The currently authenticated user.
|
|
19
|
+
*/
|
|
20
|
+
_user;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new authtentication guard.
|
|
23
|
+
*/
|
|
24
|
+
constructor(provider, req) {
|
|
25
|
+
this._provider = provider;
|
|
26
|
+
this._req = req;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Determine if the current user is authenticated. If not, throw an error.
|
|
30
|
+
*/
|
|
31
|
+
async authenticate() {
|
|
32
|
+
const user = await this.user();
|
|
33
|
+
if (user) {
|
|
34
|
+
return user;
|
|
35
|
+
}
|
|
36
|
+
throw new WrongCredentialsError_1.default();
|
|
37
|
+
}
|
|
38
|
+
async check() {
|
|
39
|
+
return !!(await this.user());
|
|
40
|
+
}
|
|
41
|
+
async guest() {
|
|
42
|
+
return !(await this.check);
|
|
43
|
+
}
|
|
44
|
+
async setUser(user) {
|
|
45
|
+
// this._user = user;
|
|
46
|
+
}
|
|
47
|
+
async setRequest(req) {
|
|
48
|
+
this._req = req;
|
|
49
|
+
}
|
|
50
|
+
async user() {
|
|
51
|
+
// if (this._user) {
|
|
52
|
+
// return this._user;
|
|
53
|
+
// }
|
|
54
|
+
let user = null;
|
|
55
|
+
let token = this.getTokenFromRequest();
|
|
56
|
+
let { userKey, userToken } = this.getUserKeyTokenFromRequest();
|
|
57
|
+
if (token) {
|
|
58
|
+
user = await this._provider.getByToken(token);
|
|
59
|
+
}
|
|
60
|
+
if (userKey && userToken) {
|
|
61
|
+
user = await this._provider.getByUserKeyAndUserToken(userKey, userToken);
|
|
62
|
+
}
|
|
63
|
+
return user;
|
|
64
|
+
// return this._user = user!;
|
|
65
|
+
}
|
|
66
|
+
getTokenFromRequest() {
|
|
67
|
+
let token = this._req.query['api_token'];
|
|
68
|
+
if (!token) {
|
|
69
|
+
token = this._req.body['api_token'];
|
|
70
|
+
}
|
|
71
|
+
if (!token && this._req.header('API-Token')) {
|
|
72
|
+
token = this._req.header('API-Token');
|
|
73
|
+
}
|
|
74
|
+
if (!token && this._req.header('Authorization')) {
|
|
75
|
+
const authorization = this._req.header('Authorization');
|
|
76
|
+
let [_, bearerToken] = authorization.split(' ');
|
|
77
|
+
token = bearerToken;
|
|
78
|
+
}
|
|
79
|
+
return token;
|
|
80
|
+
}
|
|
81
|
+
getUserKeyTokenFromRequest() {
|
|
82
|
+
let userKey = this._req.query['userkey'];
|
|
83
|
+
let userToken = this._req.query['usertoken'];
|
|
84
|
+
if (!userKey) {
|
|
85
|
+
userKey = this._req.body['userkey'];
|
|
86
|
+
}
|
|
87
|
+
if (!userToken) {
|
|
88
|
+
userToken = this._req.body['usertoken'];
|
|
89
|
+
}
|
|
90
|
+
return { userKey, userToken };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.TokenGuard = TokenGuard;
|
|
94
|
+
exports.default = TokenGuard;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Authenticable from './Authenticable';
|
|
2
|
+
export interface UserProvider {
|
|
3
|
+
/**
|
|
4
|
+
* Get user by their unique identifier.
|
|
5
|
+
*/
|
|
6
|
+
getById(id: any): Promise<Authenticable | null>;
|
|
7
|
+
/**
|
|
8
|
+
* Get user by their api token.
|
|
9
|
+
*/
|
|
10
|
+
getByToken(token: string): Promise<Authenticable | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Get user by the given credentials.
|
|
13
|
+
*/
|
|
14
|
+
getByCredentials(credentials: object): Promise<Authenticable | null>;
|
|
15
|
+
getByUserKeyAndUserToken(userKey: string, userToken: string): Promise<Authenticable | null>;
|
|
16
|
+
}
|
|
17
|
+
export default UserProvider;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Store } from '../../../core/domain/cache/Store';
|
|
2
|
+
export interface Repo {
|
|
3
|
+
/**
|
|
4
|
+
* Determine if an item exists in the cache.
|
|
5
|
+
*/
|
|
6
|
+
has(key: string): Promise<boolean>;
|
|
7
|
+
/**
|
|
8
|
+
* Determine if an item doesn't exist in the cache.
|
|
9
|
+
*/
|
|
10
|
+
missing(key: string): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve an item from the cache by key.
|
|
13
|
+
*/
|
|
14
|
+
get<T>(key: string, _default?: unknown): Promise<T | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieve an item from the cache and delete it.
|
|
17
|
+
*/
|
|
18
|
+
pull<T>(key: string, _default?: unknown): Promise<T | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Store an item in the cache.
|
|
21
|
+
*/
|
|
22
|
+
put(key: string, value: unknown, ttl?: number): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Store an item in the cache if the key does not exist.
|
|
25
|
+
*/
|
|
26
|
+
add(key: string, value: unknown, ttl?: number): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Store an item in the cache indefinitely.
|
|
29
|
+
*/
|
|
30
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Get an item from the cache, or execute the given Closure and store the result.
|
|
33
|
+
*/
|
|
34
|
+
remember<T>(key: string, callback: Function, ttl?: number): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Get an item from the cache, or execute the given Closure and store the result forever.
|
|
37
|
+
*/
|
|
38
|
+
rememberForever<T>(key: string, callback: Function): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Remove an item from the cache.
|
|
41
|
+
*/
|
|
42
|
+
forget(key: string): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Remove all items from the cache.
|
|
45
|
+
*/
|
|
46
|
+
flush(): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the cache store implementation.
|
|
49
|
+
*/
|
|
50
|
+
getStore(): Store;
|
|
51
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Store {
|
|
2
|
+
/**
|
|
3
|
+
* Fetches a value from the cache.
|
|
4
|
+
*/
|
|
5
|
+
get<T>(key: string): Promise<T | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Store an item in the cache for a given number of seconds.
|
|
8
|
+
*/
|
|
9
|
+
put(key: string, value: unknown, ttl: number): Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Store an item in the cache indefinitely.
|
|
12
|
+
*/
|
|
13
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* Remove an item from the cache.
|
|
16
|
+
*/
|
|
17
|
+
forget(key: string): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Remove all items from the cache.
|
|
20
|
+
*/
|
|
21
|
+
flush(): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the cache key prefix.
|
|
24
|
+
*/
|
|
25
|
+
getPrefix(): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppError = void 0;
|
|
4
|
+
class AppError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
message;
|
|
7
|
+
constructor(message, status = 500) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.message = message;
|
|
10
|
+
this.status = status;
|
|
11
|
+
}
|
|
12
|
+
serializeErrors() {
|
|
13
|
+
return [{ message: this.message }];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.AppError = AppError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationTokenMissingError = void 0;
|
|
4
|
+
const AppError_1 = require("../../core/errors/AppError");
|
|
5
|
+
class AuthenticationTokenMissingError extends AppError_1.AppError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Authentication token missing', 401);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.AuthenticationTokenMissingError = AuthenticationTokenMissingError;
|
|
11
|
+
exports.default = AuthenticationTokenMissingError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BadRequestError = void 0;
|
|
4
|
+
const AppError_1 = require("../../core/errors/AppError");
|
|
5
|
+
class BadRequestError extends AppError_1.AppError {
|
|
6
|
+
constructor(message = 'Bad Request') {
|
|
7
|
+
super(message, 400);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.BadRequestError = BadRequestError;
|
|
11
|
+
exports.default = BadRequestError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotAuthorizedError = void 0;
|
|
4
|
+
const AppError_1 = require("../../core/errors/AppError");
|
|
5
|
+
class NotAuthorizedError extends AppError_1.AppError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('You\'re not authorized', 403);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.NotAuthorizedError = NotAuthorizedError;
|
|
11
|
+
exports.default = NotAuthorizedError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotFoundError = void 0;
|
|
4
|
+
const AppError_1 = require("../../core/errors/AppError");
|
|
5
|
+
class NotFoundError extends AppError_1.AppError {
|
|
6
|
+
constructor(message = 'Not Found') {
|
|
7
|
+
super(message, 404);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.NotFoundError = NotFoundError;
|
|
11
|
+
exports.default = NotFoundError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
import { AppError, ErrorMessage } from '../../core/errors/AppError';
|
|
3
|
+
export declare class RequestValidationError extends AppError {
|
|
4
|
+
protected errors: ValidationError[];
|
|
5
|
+
constructor(errors: ValidationError[]);
|
|
6
|
+
serializeErrors(): ErrorMessage[];
|
|
7
|
+
private mapChildrenToValidationErrors;
|
|
8
|
+
private prependConstraintsWithParentProp;
|
|
9
|
+
}
|
|
10
|
+
export default RequestValidationError;
|