@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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionMessagingStatus = void 0;
|
|
4
|
+
var TransactionMessagingStatus;
|
|
5
|
+
(function (TransactionMessagingStatus) {
|
|
6
|
+
TransactionMessagingStatus["Created"] = "created";
|
|
7
|
+
TransactionMessagingStatus["Paid"] = "paid";
|
|
8
|
+
TransactionMessagingStatus["Published"] = "published";
|
|
9
|
+
TransactionMessagingStatus["Succeeded"] = "succeeded";
|
|
10
|
+
TransactionMessagingStatus["Failed"] = "failed";
|
|
11
|
+
})(TransactionMessagingStatus = exports.TransactionMessagingStatus || (exports.TransactionMessagingStatus = {}));
|
package/domain/User.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum RoleEnum {
|
|
2
|
+
Admin = "admin",
|
|
3
|
+
Finance = "finance",
|
|
4
|
+
Operational = "operational",
|
|
5
|
+
Member = "member"
|
|
6
|
+
}
|
|
7
|
+
export declare enum StatusEnum {
|
|
8
|
+
Active = "active",
|
|
9
|
+
Archived = "archived"
|
|
10
|
+
}
|
|
11
|
+
export declare enum ProviderEnum {
|
|
12
|
+
Email = "email"
|
|
13
|
+
}
|
|
14
|
+
interface User {
|
|
15
|
+
id?: string;
|
|
16
|
+
provider: ProviderEnum;
|
|
17
|
+
uid: string;
|
|
18
|
+
password: string | undefined;
|
|
19
|
+
name: string;
|
|
20
|
+
email: string;
|
|
21
|
+
accountId: string | undefined;
|
|
22
|
+
token: string | undefined;
|
|
23
|
+
status: StatusEnum;
|
|
24
|
+
}
|
|
25
|
+
export default User;
|
package/domain/User.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderEnum = exports.StatusEnum = exports.RoleEnum = void 0;
|
|
4
|
+
var RoleEnum;
|
|
5
|
+
(function (RoleEnum) {
|
|
6
|
+
RoleEnum["Admin"] = "admin";
|
|
7
|
+
RoleEnum["Finance"] = "finance";
|
|
8
|
+
RoleEnum["Operational"] = "operational";
|
|
9
|
+
RoleEnum["Member"] = "member";
|
|
10
|
+
})(RoleEnum = exports.RoleEnum || (exports.RoleEnum = {}));
|
|
11
|
+
var StatusEnum;
|
|
12
|
+
(function (StatusEnum) {
|
|
13
|
+
StatusEnum["Active"] = "active";
|
|
14
|
+
StatusEnum["Archived"] = "archived";
|
|
15
|
+
})(StatusEnum = exports.StatusEnum || (exports.StatusEnum = {}));
|
|
16
|
+
var ProviderEnum;
|
|
17
|
+
(function (ProviderEnum) {
|
|
18
|
+
ProviderEnum["Email"] = "email";
|
|
19
|
+
})(ProviderEnum = exports.ProviderEnum || (exports.ProviderEnum = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './TransactionMessaging';
|
|
2
|
+
export * from './TransactionMessagingStatusUpdate';
|
|
3
|
+
export * from './MessageTemplate';
|
|
4
|
+
export * from './MessageTemplateStatusUpdate';
|
|
5
|
+
export * from './MessageTemplateCategoryUpdate';
|
|
6
|
+
export * from './ChannelWhatsapp';
|
|
7
|
+
export * from './Payment';
|
|
8
|
+
export * from './BalanceMutation';
|
|
9
|
+
export * from './Report';
|
|
10
|
+
export * from './User';
|
package/domain/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TransactionMessaging"), exports);
|
|
18
|
+
__exportStar(require("./TransactionMessagingStatusUpdate"), exports);
|
|
19
|
+
__exportStar(require("./MessageTemplate"), exports);
|
|
20
|
+
__exportStar(require("./MessageTemplateStatusUpdate"), exports);
|
|
21
|
+
__exportStar(require("./MessageTemplateCategoryUpdate"), exports);
|
|
22
|
+
__exportStar(require("./ChannelWhatsapp"), exports);
|
|
23
|
+
__exportStar(require("./Payment"), exports);
|
|
24
|
+
__exportStar(require("./BalanceMutation"), exports);
|
|
25
|
+
__exportStar(require("./Report"), exports);
|
|
26
|
+
__exportStar(require("./User"), exports);
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./core"), exports);
|
|
18
|
+
__exportStar(require("./domain"), exports);
|
|
19
|
+
__exportStar(require("./shared"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aptana/multichannel-common",
|
|
3
|
+
"version": "2.9.12",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"waba"
|
|
8
|
+
],
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/aptana/multichannel-common.git"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc && tsc-alias",
|
|
16
|
+
"prebuild": "rimraf dist",
|
|
17
|
+
"postbuild": "cp package.json readme.md dist"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@grpc/grpc-js": "^1.10.6",
|
|
21
|
+
"@grpc/proto-loader": "^0.7.12",
|
|
22
|
+
"amqp-connection-manager": "^4.1.11",
|
|
23
|
+
"axios": "^1.7.4",
|
|
24
|
+
"axios-curlirize": "1.3.7",
|
|
25
|
+
"class-transformer": "^0.5.1",
|
|
26
|
+
"class-validator": "^0.14.0",
|
|
27
|
+
"compression": "^1.7.4",
|
|
28
|
+
"cors": "^2.8.5",
|
|
29
|
+
"express": "^4.18.2",
|
|
30
|
+
"express-async-errors": "^3.1.1",
|
|
31
|
+
"helmet": "^7.0.0",
|
|
32
|
+
"ioredis": "^5.4.1",
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"mongoose": "^7.0.0",
|
|
35
|
+
"morgan": "^1.10.0",
|
|
36
|
+
"morgan-json": "^1.1.0",
|
|
37
|
+
"protobufjs": "^7.2.6",
|
|
38
|
+
"sequelize": "^6.37.3",
|
|
39
|
+
"typedi": "^0.10.0",
|
|
40
|
+
"winston": "^3.8.2"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/amqplib": "^0.10.1",
|
|
44
|
+
"@types/axios-curlirize": "^1.3.2",
|
|
45
|
+
"@types/compression": "^1.7.2",
|
|
46
|
+
"@types/cors": "^2.8.13",
|
|
47
|
+
"@types/express": "^4.17.17",
|
|
48
|
+
"@types/lodash": "^4.17.6",
|
|
49
|
+
"@types/morgan": "^1.9.4",
|
|
50
|
+
"@types/morgan-json": "^1.1.3",
|
|
51
|
+
"@types/node": "^18.13.1",
|
|
52
|
+
"npm": "^9.8.1",
|
|
53
|
+
"rimraf": "^4.1.2",
|
|
54
|
+
"tsc-alias": "^1.8.7",
|
|
55
|
+
"typescript": "^4.9.5"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/readme.md
ADDED
package/shared/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("../shared/plugins/axios"), exports);
|
|
18
|
+
__exportStar(require("../shared/plugins/axios-logger-mongo"), exports);
|
|
19
|
+
__exportStar(require("../shared/plugins/mongoose"), exports);
|
|
20
|
+
__exportStar(require("../shared/plugins/cursor"), exports);
|
|
21
|
+
__exportStar(require("../shared/resources/JsonResource"), exports);
|
|
@@ -0,0 +1,113 @@
|
|
|
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.useMongoLogger = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const querystring_1 = __importDefault(require("querystring"));
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const NAMESPACE = 'axios-logger-mongo';
|
|
11
|
+
const logRequest = (logModel) => (axiosConfig) => {
|
|
12
|
+
axiosConfig[NAMESPACE] = Object.assign({
|
|
13
|
+
requestTimestamp: Date.now()
|
|
14
|
+
}, axiosConfig);
|
|
15
|
+
return axiosConfig;
|
|
16
|
+
};
|
|
17
|
+
function createRequestObject({ axiosConfig, axiosRequest }) {
|
|
18
|
+
const url = new URL(axiosConfig.url);
|
|
19
|
+
const requestHeaders = {
|
|
20
|
+
host: url.host,
|
|
21
|
+
...lodash_1.default.mapKeys(axiosConfig.headers, (val, key) => key.toLowerCase()),
|
|
22
|
+
};
|
|
23
|
+
let requestBody;
|
|
24
|
+
if (requestHeaders['content-type'] &&
|
|
25
|
+
requestHeaders['content-type'].startsWith('application/json')) {
|
|
26
|
+
try {
|
|
27
|
+
requestBody = JSON.parse(axiosConfig.data);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
requestBody = requestBody || null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
requestBody = axiosConfig.data || null;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
method: axiosRequest.method || axiosConfig.method.toUpperCase(),
|
|
38
|
+
path: axiosRequest.path || url.pathname,
|
|
39
|
+
headers: requestHeaders,
|
|
40
|
+
query: {
|
|
41
|
+
...querystring_1.default.parse(url.search.replace('?', '')),
|
|
42
|
+
...axiosConfig.params,
|
|
43
|
+
},
|
|
44
|
+
body: requestBody,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createResponseObject({ axiosResponse }) {
|
|
48
|
+
let body = axiosResponse.data || null;
|
|
49
|
+
return {
|
|
50
|
+
status: axiosResponse.status,
|
|
51
|
+
statusText: axiosResponse.statusText,
|
|
52
|
+
headers: axiosResponse.headers,
|
|
53
|
+
body,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const logResponse = (logModel) => (axiosResponse) => {
|
|
57
|
+
const axiosConfig = axiosResponse.config;
|
|
58
|
+
const axiosRequest = axiosResponse.request;
|
|
59
|
+
const { requestTimestamp } = axiosConfig[NAMESPACE];
|
|
60
|
+
const responseTimestamp = Date.now();
|
|
61
|
+
const request = createRequestObject({
|
|
62
|
+
axiosConfig,
|
|
63
|
+
axiosRequest
|
|
64
|
+
});
|
|
65
|
+
const response = createResponseObject({
|
|
66
|
+
axiosResponse
|
|
67
|
+
});
|
|
68
|
+
logModel.create({
|
|
69
|
+
request,
|
|
70
|
+
response,
|
|
71
|
+
error: null,
|
|
72
|
+
requestTimestamp,
|
|
73
|
+
responseTimestamp,
|
|
74
|
+
duration: responseTimestamp - requestTimestamp
|
|
75
|
+
});
|
|
76
|
+
return axiosResponse;
|
|
77
|
+
};
|
|
78
|
+
const logError = (logModel) => (axiosError) => {
|
|
79
|
+
const axiosConfig = axiosError.config;
|
|
80
|
+
const axiosRequest = axiosError.request;
|
|
81
|
+
const { requestTimestamp } = axiosConfig[NAMESPACE];
|
|
82
|
+
const responseTimestamp = Date.now();
|
|
83
|
+
const request = createRequestObject({
|
|
84
|
+
axiosConfig,
|
|
85
|
+
axiosRequest,
|
|
86
|
+
});
|
|
87
|
+
const response = null;
|
|
88
|
+
const error = axiosError.message;
|
|
89
|
+
logModel.create({
|
|
90
|
+
request,
|
|
91
|
+
response,
|
|
92
|
+
error,
|
|
93
|
+
requestTimestamp,
|
|
94
|
+
responseTimestamp,
|
|
95
|
+
duration: responseTimestamp - requestTimestamp,
|
|
96
|
+
});
|
|
97
|
+
return Promise.reject(axiosError);
|
|
98
|
+
};
|
|
99
|
+
function useMongoLogger(axios, { mongoURL, collectionName }) {
|
|
100
|
+
mongoose_1.default.connect(mongoURL);
|
|
101
|
+
const logSchema = new mongoose_1.default.Schema({
|
|
102
|
+
request: mongoose_1.default.Schema.Types.Mixed,
|
|
103
|
+
response: mongoose_1.default.Schema.Types.Mixed,
|
|
104
|
+
error: mongoose_1.default.Schema.Types.Mixed,
|
|
105
|
+
requestTimestamp: mongoose_1.default.Schema.Types.Mixed,
|
|
106
|
+
responseTimestamp: mongoose_1.default.Schema.Types.Mixed,
|
|
107
|
+
duration: mongoose_1.default.Schema.Types.Mixed,
|
|
108
|
+
}, { timestamps: true });
|
|
109
|
+
const logModel = mongoose_1.default.model('AxiosLog', logSchema, collectionName);
|
|
110
|
+
axios.interceptors.request.use(logRequest(logModel));
|
|
111
|
+
axios.interceptors.response.use(logResponse(logModel), logError(logModel));
|
|
112
|
+
}
|
|
113
|
+
exports.useMongoLogger = useMongoLogger;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const axios: import("axios").AxiosInstance;
|
|
@@ -0,0 +1,31 @@
|
|
|
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.axios = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const axios_curlirize_1 = __importDefault(require("axios-curlirize"));
|
|
9
|
+
exports.axios = axios_1.default.create({
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
'Accept': 'application/json',
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
exports.axios.interceptors.request.use(function (config) {
|
|
16
|
+
// Do something before request is sent
|
|
17
|
+
return config;
|
|
18
|
+
}, function (error) {
|
|
19
|
+
// Do something with request error
|
|
20
|
+
return Promise.reject(error);
|
|
21
|
+
});
|
|
22
|
+
exports.axios.interceptors.response.use(function (response) {
|
|
23
|
+
// Any status code that lie within the range of 2xx cause this function to trigger
|
|
24
|
+
// Do something with response data
|
|
25
|
+
return response.data;
|
|
26
|
+
}, function (error) {
|
|
27
|
+
// Any status codes that falls outside the range of 2xx cause this function to trigger
|
|
28
|
+
// Do something with response error
|
|
29
|
+
return Promise.reject(error);
|
|
30
|
+
});
|
|
31
|
+
(0, axios_curlirize_1.default)(exports.axios);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Schema, Model } from 'mongoose';
|
|
2
|
+
export declare class CursorPaginationModel<T> {
|
|
3
|
+
meta: {
|
|
4
|
+
cursors?: {
|
|
5
|
+
next?: string | undefined;
|
|
6
|
+
previous?: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
limit: number;
|
|
9
|
+
};
|
|
10
|
+
docs: T[];
|
|
11
|
+
}
|
|
12
|
+
export interface CursorPaginationOptions {
|
|
13
|
+
query?: any;
|
|
14
|
+
aggregate?: any;
|
|
15
|
+
populate?: any;
|
|
16
|
+
select?: any;
|
|
17
|
+
search?: {
|
|
18
|
+
value: string | undefined;
|
|
19
|
+
fields: string[] | undefined;
|
|
20
|
+
};
|
|
21
|
+
sort?: any;
|
|
22
|
+
projection?: any;
|
|
23
|
+
cursor?: string;
|
|
24
|
+
limit?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CursorPagination<T> extends Model<T> {
|
|
27
|
+
cursor(options?: CursorPaginationOptions, onError?: Function): Promise<CursorPaginationModel<T> | undefined>;
|
|
28
|
+
}
|
|
29
|
+
export declare function mongooseCursorPaginate<T>(schema: Schema<T>): void;
|
|
@@ -0,0 +1,231 @@
|
|
|
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.mongooseCursorPaginate = exports.CursorPaginationModel = void 0;
|
|
7
|
+
const core_1 = require("../../core");
|
|
8
|
+
const moment_1 = __importDefault(require("moment"));
|
|
9
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
+
class CursorPaginationModel {
|
|
11
|
+
meta = { limit: 0 };
|
|
12
|
+
docs = [];
|
|
13
|
+
}
|
|
14
|
+
exports.CursorPaginationModel = CursorPaginationModel;
|
|
15
|
+
function mongooseCursorPaginate(schema) {
|
|
16
|
+
schema.statics.cursor = async function cursor(options, onError) {
|
|
17
|
+
let baseQuery = options?.query ? { ...options.query } : {};
|
|
18
|
+
let limit = parseInt(options?.limit ?? '10');
|
|
19
|
+
let fetchLimit = limit + 1;
|
|
20
|
+
let direction = 'next';
|
|
21
|
+
let sort = options?.sort ||
|
|
22
|
+
(options?.aggregate?.find((agg) => agg.$sort) || {}).$sort ||
|
|
23
|
+
{ _id: -1 };
|
|
24
|
+
if (options?.cursor) {
|
|
25
|
+
try {
|
|
26
|
+
const decodedStr = core_1.Crypto.decrypt(options.cursor);
|
|
27
|
+
const decoded = JSON.parse(decodedStr);
|
|
28
|
+
core_1.logger.debug({ decoded });
|
|
29
|
+
direction = decoded.direction;
|
|
30
|
+
const sortQuery = decoded.query?.sort || {};
|
|
31
|
+
delete decoded.query?.sort;
|
|
32
|
+
for (const key of Object.keys(sort)) {
|
|
33
|
+
let value = sortQuery[key];
|
|
34
|
+
if (key.endsWith('At') && typeof value === 'string') {
|
|
35
|
+
value = (0, moment_1.default)(value).toDate();
|
|
36
|
+
}
|
|
37
|
+
if (value !== undefined) {
|
|
38
|
+
const operator = direction === 'next'
|
|
39
|
+
? (sort[key] === 1 ? '$gte' : '$lte')
|
|
40
|
+
: (sort[key] === 1 ? '$lte' : '$gte');
|
|
41
|
+
baseQuery.$or = [
|
|
42
|
+
{ [key]: { [operator]: value } },
|
|
43
|
+
{ [key]: { $exists: false } },
|
|
44
|
+
{ [key]: null }
|
|
45
|
+
];
|
|
46
|
+
if (decoded.query?.[key]) {
|
|
47
|
+
baseQuery.$or = baseQuery.$or.map((condition) => ({
|
|
48
|
+
...condition,
|
|
49
|
+
...decoded.query[key]
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
core_1.logger.debug({ baseQueryBeforeMerge: baseQuery, decodedQuery: decoded.query });
|
|
55
|
+
// Deep merge decoded.query ke baseQuery dengan handling khusus untuk aggregation
|
|
56
|
+
for (const key in decoded.query) {
|
|
57
|
+
if (key === '_id') {
|
|
58
|
+
// Merge _id conditions secara khusus
|
|
59
|
+
baseQuery._id = baseQuery._id
|
|
60
|
+
? { ...baseQuery._id, ...decoded.query._id }
|
|
61
|
+
: decoded.query._id;
|
|
62
|
+
}
|
|
63
|
+
else if (key !== 'sort') {
|
|
64
|
+
// Skip $or karena sudah dibuat di loop sebelumnya
|
|
65
|
+
// Untuk field lain, merge langsung
|
|
66
|
+
if (key !== '$or') {
|
|
67
|
+
baseQuery[key] = decoded.query[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
core_1.logger.debug({ baseQueryAfterMerge: baseQuery });
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
if (onError)
|
|
75
|
+
onError(e);
|
|
76
|
+
core_1.logger.debug({ e, stack: e.stack });
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (baseQuery && baseQuery._id) {
|
|
81
|
+
['gte', 'lte', 'ne'].forEach(op => {
|
|
82
|
+
if (baseQuery._id[`$${op}`] && typeof baseQuery._id[`$${op}`] === 'string') {
|
|
83
|
+
baseQuery._id[`$${op}`] = new mongoose_1.default.Types.ObjectId(baseQuery._id[`$${op}`]);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
let effectiveQuery = { ...baseQuery };
|
|
88
|
+
if (options?.search &&
|
|
89
|
+
options.search.value &&
|
|
90
|
+
options.search.fields &&
|
|
91
|
+
options.search.fields.length) {
|
|
92
|
+
const searchQuery = {
|
|
93
|
+
$regex: options.search.value,
|
|
94
|
+
$options: 'i',
|
|
95
|
+
};
|
|
96
|
+
if (options.search.fields.length === 1) {
|
|
97
|
+
effectiveQuery[options.search.fields[0]] = searchQuery;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
effectiveQuery.$or = options.search.fields.map(field => ({ [field]: searchQuery }));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (direction === 'previous') {
|
|
104
|
+
sort = Object.fromEntries(Object.entries(sort).map(([key, value]) => [key, -value]));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
sort = Object.fromEntries(Object.entries(sort).map(([key, value]) => [key, parseInt(value)]));
|
|
108
|
+
}
|
|
109
|
+
const projection = options?.projection ?? {};
|
|
110
|
+
const populate = options?.populate;
|
|
111
|
+
core_1.logger.debug({ effectiveQuery });
|
|
112
|
+
let mQuery;
|
|
113
|
+
if (options?.aggregate) {
|
|
114
|
+
const aggregatePipeline = [...options.aggregate];
|
|
115
|
+
const matchIndex = aggregatePipeline.findIndex(stage => stage.$match);
|
|
116
|
+
if (matchIndex !== -1) {
|
|
117
|
+
aggregatePipeline[matchIndex].$match = {
|
|
118
|
+
...aggregatePipeline[matchIndex].$match,
|
|
119
|
+
...effectiveQuery
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
else if (Object.keys(effectiveQuery).length > 0) {
|
|
123
|
+
aggregatePipeline.unshift({ $match: effectiveQuery });
|
|
124
|
+
}
|
|
125
|
+
const sortIndex = aggregatePipeline.findIndex(stage => stage.$sort);
|
|
126
|
+
if (sortIndex !== -1) {
|
|
127
|
+
aggregatePipeline[sortIndex].$sort = sort;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
aggregatePipeline.unshift({ $sort: sort });
|
|
131
|
+
}
|
|
132
|
+
const limitIndex = aggregatePipeline.findIndex(stage => stage.$limit);
|
|
133
|
+
if (limitIndex !== -1) {
|
|
134
|
+
aggregatePipeline[limitIndex].$limit = fetchLimit;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
aggregatePipeline.unshift({ $limit: fetchLimit });
|
|
138
|
+
}
|
|
139
|
+
core_1.logger.debug({ aggregatePipeline });
|
|
140
|
+
mQuery = this.aggregate(aggregatePipeline);
|
|
141
|
+
if (options.select) {
|
|
142
|
+
mQuery = mQuery.project(options.select);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
mQuery = this.find(effectiveQuery, projection);
|
|
147
|
+
if (options?.select) {
|
|
148
|
+
mQuery = mQuery.select(options.select);
|
|
149
|
+
}
|
|
150
|
+
if (populate) {
|
|
151
|
+
mQuery = mQuery.populate(populate);
|
|
152
|
+
}
|
|
153
|
+
mQuery = mQuery.sort(sort).limit(fetchLimit);
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
let docs = await mQuery.exec();
|
|
157
|
+
let hasMore = docs.length > fetchLimit - 1;
|
|
158
|
+
if (direction === 'next') {
|
|
159
|
+
if (hasMore) {
|
|
160
|
+
docs.pop();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (direction === 'previous') {
|
|
164
|
+
if (hasMore) {
|
|
165
|
+
docs.pop();
|
|
166
|
+
}
|
|
167
|
+
docs = docs.reverse();
|
|
168
|
+
}
|
|
169
|
+
const sortKeys = Object.keys(sort);
|
|
170
|
+
let newCursorNext = undefined;
|
|
171
|
+
let newCursorPrevious = undefined;
|
|
172
|
+
if (docs.length > 0) {
|
|
173
|
+
const lastDoc = docs[docs.length - 1];
|
|
174
|
+
const firstDoc = docs[0];
|
|
175
|
+
const buildSortValues = (doc) => {
|
|
176
|
+
return sortKeys.reduce((acc, key) => {
|
|
177
|
+
acc[key] = doc[key];
|
|
178
|
+
return acc;
|
|
179
|
+
}, {});
|
|
180
|
+
};
|
|
181
|
+
if ((direction === 'next' && hasMore) || direction === 'previous') {
|
|
182
|
+
newCursorNext = core_1.Crypto.encrypt(JSON.stringify({
|
|
183
|
+
query: {
|
|
184
|
+
_id: { $ne: lastDoc._id },
|
|
185
|
+
sort: buildSortValues(lastDoc)
|
|
186
|
+
},
|
|
187
|
+
direction: 'next'
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
if (options?.cursor) {
|
|
191
|
+
if (direction === 'next' || (direction === 'previous' && hasMore)) {
|
|
192
|
+
newCursorPrevious = core_1.Crypto.encrypt(JSON.stringify({
|
|
193
|
+
query: {
|
|
194
|
+
_id: { $ne: firstDoc._id },
|
|
195
|
+
sort: buildSortValues(firstDoc)
|
|
196
|
+
},
|
|
197
|
+
direction: 'previous'
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
let cursors = { next: newCursorNext, previous: newCursorPrevious };
|
|
203
|
+
if (!newCursorNext && !newCursorPrevious) {
|
|
204
|
+
cursors = undefined;
|
|
205
|
+
}
|
|
206
|
+
const result = new CursorPaginationModel();
|
|
207
|
+
result.meta = {
|
|
208
|
+
limit,
|
|
209
|
+
cursors
|
|
210
|
+
};
|
|
211
|
+
result.docs = docs;
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (onError)
|
|
216
|
+
onError(error);
|
|
217
|
+
core_1.logger.debug({ error, stack: error.stack });
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const toJSONOptions = {
|
|
222
|
+
virtuals: true,
|
|
223
|
+
transform: function (doc, ret) {
|
|
224
|
+
ret.id = ret._id;
|
|
225
|
+
delete ret.__v;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
schema.set('toJSON', toJSONOptions);
|
|
229
|
+
schema.set('toObject', toJSONOptions);
|
|
230
|
+
}
|
|
231
|
+
exports.mongooseCursorPaginate = mongooseCursorPaginate;
|