mvc-common-toolkit 1.43.10 → 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/constants.d.ts +59 -0
- package/dist/src/constants.js +69 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/gateways/alibaba-cloud-gateway.d.ts +30 -0
- package/dist/src/gateways/alibaba-cloud-gateway.js +120 -0
- package/dist/src/gateways/alibaba-cloud-gateway.js.map +1 -0
- package/dist/src/gateways/http-audit-gateway.d.ts +20 -0
- package/dist/src/gateways/http-audit-gateway.js +76 -0
- package/dist/src/gateways/http-audit-gateway.js.map +1 -0
- package/dist/src/gateways/index.d.ts +5 -0
- package/dist/src/gateways/index.js +22 -0
- package/dist/src/gateways/index.js.map +1 -0
- package/dist/src/gateways/internal-auth-gateway.d.ts +8 -0
- package/dist/src/gateways/internal-auth-gateway.js +40 -0
- package/dist/src/gateways/internal-auth-gateway.js.map +1 -0
- package/dist/src/gateways/stdout-audit-gateway.d.ts +7 -0
- package/dist/src/gateways/stdout-audit-gateway.js +25 -0
- package/dist/src/gateways/stdout-audit-gateway.js.map +1 -0
- package/dist/src/gateways/webhook-audit-gateway.d.ts +14 -0
- package/dist/src/gateways/webhook-audit-gateway.js +27 -0
- package/dist/src/gateways/webhook-audit-gateway.js.map +1 -0
- package/dist/src/interfaces.d.ts +218 -0
- package/dist/src/interfaces.js +3 -0
- package/dist/src/interfaces.js.map +1 -0
- package/dist/src/models/audit-log.d.ts +77 -0
- package/dist/src/models/audit-log.js +92 -0
- package/dist/src/models/audit-log.js.map +1 -0
- package/dist/src/models/index.d.ts +1 -0
- package/dist/src/models/index.js +18 -0
- package/dist/src/models/index.js.map +1 -0
- package/dist/src/pkg/array-helper.d.ts +1 -0
- package/dist/src/pkg/array-helper.js +12 -0
- package/dist/src/pkg/array-helper.js.map +1 -0
- package/dist/src/pkg/bcrypt-helper.d.ts +2 -0
- package/dist/src/pkg/bcrypt-helper.js +36 -0
- package/dist/src/pkg/bcrypt-helper.js.map +1 -0
- package/dist/src/pkg/crypto-helper.d.ts +2 -0
- package/dist/src/pkg/crypto-helper.js +16 -0
- package/dist/src/pkg/crypto-helper.js.map +1 -0
- package/dist/src/pkg/encryption-helper.d.ts +18 -0
- package/dist/src/pkg/encryption-helper.js +89 -0
- package/dist/src/pkg/encryption-helper.js.map +1 -0
- package/dist/src/pkg/encryption-helper.spec.d.ts +1 -0
- package/dist/src/pkg/encryption-helper.spec.js +238 -0
- package/dist/src/pkg/encryption-helper.spec.js.map +1 -0
- package/dist/src/pkg/filter-helper.d.ts +2 -0
- package/dist/src/pkg/filter-helper.js +102 -0
- package/dist/src/pkg/filter-helper.js.map +1 -0
- package/dist/src/pkg/filter-helper.spec.d.ts +1 -0
- package/dist/src/pkg/filter-helper.spec.js +94 -0
- package/dist/src/pkg/filter-helper.spec.js.map +1 -0
- package/dist/src/pkg/geoip-helper.d.ts +2 -0
- package/dist/src/pkg/geoip-helper.js +32 -0
- package/dist/src/pkg/geoip-helper.js.map +1 -0
- package/dist/src/pkg/hash-helper.d.ts +1 -0
- package/dist/src/pkg/hash-helper.js +37 -0
- package/dist/src/pkg/hash-helper.js.map +1 -0
- package/dist/src/pkg/http-request-utils.d.ts +4 -0
- package/dist/src/pkg/http-request-utils.js +55 -0
- package/dist/src/pkg/http-request-utils.js.map +1 -0
- package/dist/src/pkg/index.d.ts +19 -0
- package/dist/src/pkg/index.js +46 -0
- package/dist/src/pkg/index.js.map +1 -0
- package/dist/src/pkg/key-helper.d.ts +2 -0
- package/dist/src/pkg/key-helper.js +20 -0
- package/dist/src/pkg/key-helper.js.map +1 -0
- package/dist/src/pkg/logger.d.ts +9 -0
- package/dist/src/pkg/logger.js +23 -0
- package/dist/src/pkg/logger.js.map +1 -0
- package/dist/src/pkg/object-helper.d.ts +2 -0
- package/dist/src/pkg/object-helper.js +37 -0
- package/dist/src/pkg/object-helper.js.map +1 -0
- package/dist/src/pkg/paginated-cache-registry.d.ts +8 -0
- package/dist/src/pkg/paginated-cache-registry.js +23 -0
- package/dist/src/pkg/paginated-cache-registry.js.map +1 -0
- package/dist/src/pkg/query-helper.d.ts +3 -0
- package/dist/src/pkg/query-helper.js +60 -0
- package/dist/src/pkg/query-helper.js.map +1 -0
- package/dist/src/pkg/referral-tree-utils.d.ts +33 -0
- package/dist/src/pkg/referral-tree-utils.js +71 -0
- package/dist/src/pkg/referral-tree-utils.js.map +1 -0
- package/dist/src/pkg/scripts/index.d.ts +1 -0
- package/dist/src/pkg/scripts/index.js +28 -0
- package/dist/src/pkg/scripts/index.js.map +1 -0
- package/dist/src/pkg/scripts/lua.d.ts +10 -0
- package/dist/src/pkg/scripts/lua.js +109 -0
- package/dist/src/pkg/scripts/lua.js.map +1 -0
- package/dist/src/pkg/sort-helper.d.ts +3 -0
- package/dist/src/pkg/sort-helper.js +18 -0
- package/dist/src/pkg/sort-helper.js.map +1 -0
- package/dist/src/pkg/string-utils.d.ts +10 -0
- package/dist/src/pkg/string-utils.js +79 -0
- package/dist/src/pkg/string-utils.js.map +1 -0
- package/dist/src/pkg/task-helper.d.ts +2 -0
- package/dist/src/pkg/task-helper.js +30 -0
- package/dist/src/pkg/task-helper.js.map +1 -0
- package/dist/src/pkg/trading-pair-helper.d.ts +9 -0
- package/dist/src/pkg/trading-pair-helper.js +44 -0
- package/dist/src/pkg/trading-pair-helper.js.map +1 -0
- package/dist/src/pkg/trading-pair-helper.spec.d.ts +1 -0
- package/dist/src/pkg/trading-pair-helper.spec.js +132 -0
- package/dist/src/pkg/trading-pair-helper.spec.js.map +1 -0
- package/dist/src/pkg/workflow/delayed-task-registry.d.ts +10 -0
- package/dist/src/pkg/workflow/delayed-task-registry.js +67 -0
- package/dist/src/pkg/workflow/delayed-task-registry.js.map +1 -0
- package/dist/src/pkg/workflow/delayed-task.d.ts +18 -0
- package/dist/src/pkg/workflow/delayed-task.js +95 -0
- package/dist/src/pkg/workflow/delayed-task.js.map +1 -0
- package/dist/src/pkg/workflow/index.d.ts +5 -0
- package/dist/src/pkg/workflow/index.js +22 -0
- package/dist/src/pkg/workflow/index.js.map +1 -0
- package/dist/src/pkg/workflow/processing-milestone.d.ts +18 -0
- package/dist/src/pkg/workflow/processing-milestone.js +39 -0
- package/dist/src/pkg/workflow/processing-milestone.js.map +1 -0
- package/dist/src/pkg/workflow/retry-task.d.ts +24 -0
- package/dist/src/pkg/workflow/retry-task.js +89 -0
- package/dist/src/pkg/workflow/retry-task.js.map +1 -0
- package/dist/src/pkg/workflow/retry-task.spec.d.ts +1 -0
- package/dist/src/pkg/workflow/retry-task.spec.js +145 -0
- package/dist/src/pkg/workflow/retry-task.spec.js.map +1 -0
- package/dist/src/pkg/workflow/sync-taskqueue.d.ts +32 -0
- package/dist/src/pkg/workflow/sync-taskqueue.js +108 -0
- package/dist/src/pkg/workflow/sync-taskqueue.js.map +1 -0
- package/dist/src/pkg/worksheet.utils.d.ts +27 -0
- package/dist/src/pkg/worksheet.utils.js +116 -0
- package/dist/src/pkg/worksheet.utils.js.map +1 -0
- package/dist/src/services/audit-service.d.ts +7 -0
- package/dist/src/services/audit-service.js +32 -0
- package/dist/src/services/audit-service.js.map +1 -0
- package/dist/src/services/excel.service.d.ts +25 -0
- package/dist/src/services/excel.service.js +95 -0
- package/dist/src/services/excel.service.js.map +1 -0
- package/dist/src/services/http-service.d.ts +7 -0
- package/dist/src/services/http-service.js +67 -0
- package/dist/src/services/http-service.js.map +1 -0
- package/dist/src/services/index.d.ts +8 -0
- package/dist/src/services/index.js +25 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/kafka-service.d.ts +15 -0
- package/dist/src/services/kafka-service.js +68 -0
- package/dist/src/services/kafka-service.js.map +1 -0
- package/dist/src/services/mailer-service.d.ts +15 -0
- package/dist/src/services/mailer-service.js +44 -0
- package/dist/src/services/mailer-service.js.map +1 -0
- package/dist/src/services/paginated-cache.d.ts +16 -0
- package/dist/src/services/paginated-cache.js +115 -0
- package/dist/src/services/paginated-cache.js.map +1 -0
- package/dist/src/services/paginated-cache.spec.d.ts +1 -0
- package/dist/src/services/paginated-cache.spec.js +284 -0
- package/dist/src/services/paginated-cache.spec.js.map +1 -0
- package/dist/src/services/redis-service.d.ts +33 -0
- package/dist/src/services/redis-service.js +230 -0
- package/dist/src/services/redis-service.js.map +1 -0
- package/dist/src/services/security-service.d.ts +11 -0
- package/dist/src/services/security-service.js +68 -0
- package/dist/src/services/security-service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/constants.ts +66 -0
- package/src/gateways/alibaba-cloud-gateway.ts +127 -0
- package/src/gateways/http-audit-gateway.ts +104 -0
- package/src/gateways/index.ts +5 -0
- package/src/gateways/internal-auth-gateway.ts +42 -0
- package/src/gateways/stdout-audit-gateway.ts +23 -0
- package/src/gateways/webhook-audit-gateway.ts +33 -0
- package/src/interfaces.ts +304 -0
- package/src/models/audit-log.ts +126 -0
- package/src/models/index.ts +1 -0
- package/src/pkg/array-helper.ts +7 -0
- package/src/pkg/bcrypt-helper.ts +9 -0
- package/src/pkg/crypto-helper.ts +18 -0
- package/src/pkg/encryption-helper.spec.ts +423 -0
- package/src/pkg/encryption-helper.ts +155 -0
- package/src/pkg/filter-helper.spec.ts +105 -0
- package/src/pkg/filter-helper.ts +139 -0
- package/src/pkg/geoip-helper.ts +5 -0
- package/src/pkg/hash-helper.ts +12 -0
- package/src/pkg/http-request-utils.ts +75 -0
- package/src/pkg/index.ts +19 -0
- package/src/pkg/key-helper.ts +20 -0
- package/src/pkg/logger.ts +23 -0
- package/src/pkg/object-helper.ts +42 -0
- package/src/pkg/paginated-cache-registry.ts +25 -0
- package/src/pkg/query-helper.ts +79 -0
- package/src/pkg/referral-tree-utils.ts +165 -0
- package/src/pkg/scripts/index.ts +1 -0
- package/src/pkg/scripts/lua.ts +112 -0
- package/src/pkg/sort-helper.ts +19 -0
- package/src/pkg/string-utils.ts +104 -0
- package/src/pkg/task-helper.ts +25 -0
- package/src/pkg/trading-pair-helper.spec.ts +146 -0
- package/src/pkg/trading-pair-helper.ts +78 -0
- package/src/pkg/workflow/delayed-task-registry.ts +54 -0
- package/src/pkg/workflow/delayed-task.ts +106 -0
- package/src/pkg/workflow/index.ts +5 -0
- package/src/pkg/workflow/processing-milestone.ts +54 -0
- package/src/pkg/workflow/retry-task.spec.ts +194 -0
- package/src/pkg/workflow/retry-task.ts +119 -0
- package/src/pkg/workflow/sync-taskqueue.ts +118 -0
- package/src/pkg/worksheet.utils.ts +178 -0
- package/src/services/audit-service.ts +22 -0
- package/src/services/excel.service.ts +103 -0
- package/src/services/http-service.ts +71 -0
- package/src/services/index.ts +8 -0
- package/src/services/kafka-service.ts +81 -0
- package/src/services/mailer-service.ts +43 -0
- package/src/services/paginated-cache.spec.ts +519 -0
- package/src/services/paginated-cache.ts +122 -0
- package/src/services/redis-service.ts +238 -0
- package/src/services/security-service.ts +80 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import OSS from "ali-oss";
|
|
2
|
+
import axios, { HttpStatusCode } from "axios";
|
|
3
|
+
import Core from "@alicloud/pop-core";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
CloudStorageClient,
|
|
7
|
+
PutObjectOption,
|
|
8
|
+
STSResponse,
|
|
9
|
+
} from "../interfaces";
|
|
10
|
+
|
|
11
|
+
export interface AlibabaCloudGatewayConfig {
|
|
12
|
+
accessKey: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
apiVersion?: string;
|
|
15
|
+
endpoint: string;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
oss: {
|
|
18
|
+
bucketName: string;
|
|
19
|
+
region: string;
|
|
20
|
+
};
|
|
21
|
+
sts: {
|
|
22
|
+
roleArn: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class AlibabaCloudGateway implements CloudStorageClient {
|
|
27
|
+
protected coreClient: Core;
|
|
28
|
+
protected ossClient: OSS;
|
|
29
|
+
|
|
30
|
+
constructor(protected config: AlibabaCloudGatewayConfig) {
|
|
31
|
+
this.coreClient = new Core({
|
|
32
|
+
accessKeyId: config.accessKey,
|
|
33
|
+
accessKeySecret: config.secret,
|
|
34
|
+
apiVersion: config.apiVersion || "2015-04-01",
|
|
35
|
+
endpoint: config.endpoint,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.ossClient = new OSS({
|
|
39
|
+
accessKeyId: config.accessKey,
|
|
40
|
+
accessKeySecret: config.secret,
|
|
41
|
+
region: config.oss.region,
|
|
42
|
+
bucket: config.oss.bucketName,
|
|
43
|
+
timeout: config.timeout || 3000,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async generateTmpCredentials(
|
|
48
|
+
sessionID: string
|
|
49
|
+
): Promise<STSResponse["Credentials"]> {
|
|
50
|
+
const requestResponse: STSResponse = await this.coreClient.request(
|
|
51
|
+
"AssumeRole",
|
|
52
|
+
{
|
|
53
|
+
RoleArn: this.config.sts.roleArn,
|
|
54
|
+
RoleSessionName: sessionID,
|
|
55
|
+
DurationSeconds: this.config.timeout || 900,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
method: "POST",
|
|
59
|
+
contentType: "application/json",
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return requestResponse.Credentials;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public async uploadLocalToBucket(
|
|
67
|
+
fileName: string,
|
|
68
|
+
fileData: Buffer,
|
|
69
|
+
options?: PutObjectOption
|
|
70
|
+
): Promise<string> {
|
|
71
|
+
const putResult = await this.ossClient.put(fileName, fileData, {
|
|
72
|
+
timeout: options?.timeout || 15000, // 15s
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (options?.domain) {
|
|
76
|
+
return `${options.domain}/${fileName}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (putResult?.url?.includes("http://")) {
|
|
80
|
+
return putResult.url.replace("http://", "https://");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return putResult.url;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public async deleteObject(filePath: string): Promise<void> {
|
|
87
|
+
await this.ossClient.delete(filePath);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public async uploadRemoteObjectToBucket(
|
|
91
|
+
fileName: string,
|
|
92
|
+
remoteUrl: string,
|
|
93
|
+
options?: PutObjectOption
|
|
94
|
+
): Promise<string> {
|
|
95
|
+
const response = await axios.get(remoteUrl, { responseType: "stream" });
|
|
96
|
+
if (response.status !== HttpStatusCode.Ok) {
|
|
97
|
+
throw new Error("failed to fetch from remote url");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { data } = response;
|
|
101
|
+
|
|
102
|
+
const putResult = await this.ossClient.put(fileName, data, {
|
|
103
|
+
timeout: options.timeout || 15000, // 15s
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (options?.domain) {
|
|
107
|
+
return `${options.domain}/${fileName}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (putResult?.url?.includes("http://")) {
|
|
111
|
+
return putResult.url.replace("http://", "https://");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return putResult.url;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public getObjectReadStream(fileName: string): Promise<OSS.GetStreamResult> {
|
|
118
|
+
return this.ossClient.getStream(fileName);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public writeFileToDestination(
|
|
122
|
+
fileName: string,
|
|
123
|
+
destination: string | WritableStream
|
|
124
|
+
): Promise<OSS.GetObjectResult> {
|
|
125
|
+
return this.ossClient.get(fileName, destination);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
+
|
|
3
|
+
import { LOG_LEVEL } from "../constants";
|
|
4
|
+
import { AuditGateway } from "../interfaces";
|
|
5
|
+
import { maskFn } from "../pkg/string-utils";
|
|
6
|
+
|
|
7
|
+
export interface HttpAuditGatewayConfig {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
appName?: string;
|
|
10
|
+
auth: {
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class HttpAuditGateway implements AuditGateway {
|
|
17
|
+
protected baseURL: string;
|
|
18
|
+
protected access_token: string;
|
|
19
|
+
|
|
20
|
+
constructor(protected config: HttpAuditGatewayConfig) {
|
|
21
|
+
if (!config.baseUrl) {
|
|
22
|
+
throw new Error("Missing base url config");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.baseURL = config.baseUrl;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public async publish(
|
|
29
|
+
logId: string,
|
|
30
|
+
level: LOG_LEVEL,
|
|
31
|
+
content: Record<string, any>
|
|
32
|
+
) {
|
|
33
|
+
if (!this.access_token) {
|
|
34
|
+
await this.auth();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const response = await this.send(logId, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
url: "/event/create",
|
|
40
|
+
data: {
|
|
41
|
+
...content,
|
|
42
|
+
level,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return response?.data;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private async auth(logId = "system", forceReAuth = false) {
|
|
50
|
+
if (this.access_token || forceReAuth) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const authResponse = await this.send<{ access_token: string }>(
|
|
55
|
+
logId,
|
|
56
|
+
{
|
|
57
|
+
method: "POST",
|
|
58
|
+
url: "/auth/login",
|
|
59
|
+
data: this.config.auth,
|
|
60
|
+
},
|
|
61
|
+
false,
|
|
62
|
+
false
|
|
63
|
+
); // not retry, not use token
|
|
64
|
+
|
|
65
|
+
this.access_token = authResponse?.data?.access_token;
|
|
66
|
+
|
|
67
|
+
return !!this.access_token;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
protected async send<T>(
|
|
71
|
+
logId: string,
|
|
72
|
+
options: AxiosRequestConfig,
|
|
73
|
+
is_retry = false,
|
|
74
|
+
use_access_token = true
|
|
75
|
+
): Promise<AxiosResponse<T>> {
|
|
76
|
+
console.log(
|
|
77
|
+
`[${logId}] ${
|
|
78
|
+
is_retry ? "Resend" : "Send"
|
|
79
|
+
} to Audit Service: ${JSON.stringify(options, maskFn)}`
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
options.baseURL = this.baseURL;
|
|
83
|
+
if (use_access_token) {
|
|
84
|
+
options.headers = {
|
|
85
|
+
Authorization: `Bearer ${this.access_token}`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const response = await axios.request(options);
|
|
90
|
+
|
|
91
|
+
// use token, status 401, not retry => auth & retry
|
|
92
|
+
if (response?.status == 401 && use_access_token && !is_retry) {
|
|
93
|
+
console.log(`[${logId}] Retrying...`);
|
|
94
|
+
|
|
95
|
+
const isAuthSuccess = await this.auth(logId, true);
|
|
96
|
+
|
|
97
|
+
if (isAuthSuccess) {
|
|
98
|
+
return this.send(logId, options, true);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HttpService,
|
|
3
|
+
InternalAuthGatewayOptions,
|
|
4
|
+
InternalAuthLoginResult,
|
|
5
|
+
InternalServiceAuthResult,
|
|
6
|
+
OperationResult,
|
|
7
|
+
} from "../interfaces";
|
|
8
|
+
|
|
9
|
+
export class InternalAuthGateway {
|
|
10
|
+
constructor(
|
|
11
|
+
protected httpService: HttpService,
|
|
12
|
+
protected options: InternalAuthGatewayOptions
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
public async login(): Promise<OperationResult<InternalAuthLoginResult>> {
|
|
16
|
+
return this.httpService.send(
|
|
17
|
+
"post",
|
|
18
|
+
`${this.options.endpointURL}/actors/login`,
|
|
19
|
+
{
|
|
20
|
+
body: {
|
|
21
|
+
secret: this.options.secret,
|
|
22
|
+
},
|
|
23
|
+
serviceName: this.options.serviceName,
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public async verify(
|
|
29
|
+
accessToken: string
|
|
30
|
+
): Promise<OperationResult<InternalServiceAuthResult>> {
|
|
31
|
+
return this.httpService.send(
|
|
32
|
+
"post",
|
|
33
|
+
`${this.options.endpointURL}/actors/verify`,
|
|
34
|
+
{
|
|
35
|
+
body: {
|
|
36
|
+
accessToken,
|
|
37
|
+
},
|
|
38
|
+
serviceName: this.options.serviceName,
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LOG_LEVEL } from "../constants";
|
|
2
|
+
import { loggers } from "../pkg";
|
|
3
|
+
import { AuditGateway, Logger } from "../interfaces";
|
|
4
|
+
|
|
5
|
+
export class StdOutAuditGateway implements AuditGateway {
|
|
6
|
+
protected logger: Logger;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.logger = new loggers.PinoLogger();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public async publish(
|
|
13
|
+
logId: string,
|
|
14
|
+
level: LOG_LEVEL,
|
|
15
|
+
content: any
|
|
16
|
+
): Promise<any> {
|
|
17
|
+
return this.logger.info(
|
|
18
|
+
`[LogId ${logId}]`,
|
|
19
|
+
`[${level.toUpperCase}]`,
|
|
20
|
+
content
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LOG_LEVEL } from "../constants";
|
|
2
|
+
import { AuditGateway, HttpService } from "../interfaces";
|
|
3
|
+
|
|
4
|
+
interface WebhookAuditGatewayConfig {
|
|
5
|
+
projectName: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class WebhookAuditGateway implements AuditGateway {
|
|
9
|
+
public static contentField = "content";
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
protected webhookURL: string,
|
|
13
|
+
protected httpService: HttpService,
|
|
14
|
+
protected config: WebhookAuditGatewayConfig
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
public publish(logId: string, level: LOG_LEVEL, content: any): Promise<any> {
|
|
18
|
+
const logContent =
|
|
19
|
+
content && typeof content === "object"
|
|
20
|
+
? JSON.stringify(content)
|
|
21
|
+
: content;
|
|
22
|
+
const msg = `[${this.config.projectName}] | [${level}] | [${logId}]: ${logContent}`;
|
|
23
|
+
|
|
24
|
+
return this.httpService.send("post", this.webhookURL, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
},
|
|
28
|
+
body: {
|
|
29
|
+
[WebhookAuditGateway.contentField]: msg,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { Borders, CellValue, Style } from "exceljs";
|
|
2
|
+
import {
|
|
3
|
+
Consumer,
|
|
4
|
+
ConsumerConfig,
|
|
5
|
+
ConsumerRunConfig,
|
|
6
|
+
ConsumerSubscribeTopics,
|
|
7
|
+
Producer,
|
|
8
|
+
ProducerConfig,
|
|
9
|
+
ProducerRecord,
|
|
10
|
+
TopicPartitionOffsetAndMetadata,
|
|
11
|
+
} from "kafkajs";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
FILTER_OPERATOR,
|
|
15
|
+
HttpMethod,
|
|
16
|
+
LOG_LEVEL,
|
|
17
|
+
SET_CACHE_POLICY,
|
|
18
|
+
} from "./constants";
|
|
19
|
+
import { AxiosRequestConfig } from "axios";
|
|
20
|
+
|
|
21
|
+
export interface Subscription {
|
|
22
|
+
unsubscribe(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DelayedTaskOps {
|
|
26
|
+
callback: () => void;
|
|
27
|
+
startOnCreate?: boolean;
|
|
28
|
+
timeout: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TaskRescheduleOps {
|
|
32
|
+
msFromNow?: number;
|
|
33
|
+
runTime?: Date;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TaskQueue {
|
|
37
|
+
push<T = any>(queueName: string, name: string, handler: any): Promise<T>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type DelayFn = (callback: () => void, timeout: number) => Subscription;
|
|
41
|
+
|
|
42
|
+
export type TaskFn = () => any | Promise<any>;
|
|
43
|
+
|
|
44
|
+
export interface ITask {
|
|
45
|
+
id: string;
|
|
46
|
+
isRunning: boolean;
|
|
47
|
+
isCancelled: boolean;
|
|
48
|
+
isCron: boolean;
|
|
49
|
+
start(): Promise<void>;
|
|
50
|
+
cancel(): Promise<void>;
|
|
51
|
+
lastRun(): Promise<Date>;
|
|
52
|
+
nextRun(): Promise<Date>;
|
|
53
|
+
reschedule(options: TaskRescheduleOps): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface TaskRegistry {
|
|
57
|
+
register(options: DelayedTaskOps): Promise<ITask>;
|
|
58
|
+
count(): Promise<number>;
|
|
59
|
+
getTasks(): Promise<ITask[]>;
|
|
60
|
+
getTaskById(id: string): Promise<ITask>;
|
|
61
|
+
cancelTaskById(id: string): Promise<void>;
|
|
62
|
+
startTaskById(id: string): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface SQLRunner {
|
|
66
|
+
query<T = any>(sql: string, ...args: any[]): Promise<T>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface HttpRequestOption extends AxiosRequestConfig {
|
|
70
|
+
serviceName?: string;
|
|
71
|
+
body?: any;
|
|
72
|
+
query?: any;
|
|
73
|
+
headers?: Record<string, string>;
|
|
74
|
+
reqId?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface Logger {
|
|
78
|
+
info(message: string, ...args: any[]): void;
|
|
79
|
+
error(message: string, ...args: any[]): void;
|
|
80
|
+
warn(message: string, ...args: any[]): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface HttpService {
|
|
84
|
+
send<T = any>(
|
|
85
|
+
method: HttpMethod,
|
|
86
|
+
url: string,
|
|
87
|
+
options: HttpRequestOption
|
|
88
|
+
): Promise<OperationResult<T>>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface InternalAuthGatewayOptions {
|
|
92
|
+
endpointURL: string;
|
|
93
|
+
secret: string;
|
|
94
|
+
serviceName?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface InternalAuthLoginResult {
|
|
98
|
+
accessToken?: string;
|
|
99
|
+
code?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface InternalServiceAuthResult {
|
|
103
|
+
name: string;
|
|
104
|
+
type: "internal" | "external";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface DeleteByPatternOptions {
|
|
108
|
+
includePrefixInScanPattern: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface CacheService {
|
|
112
|
+
ttl(key: string): Promise<number>;
|
|
113
|
+
get(key: string): Promise<any>;
|
|
114
|
+
set(key: string, value: any, option?: SetCacheOption): Promise<any>;
|
|
115
|
+
del(...keys: string[]): Promise<void>;
|
|
116
|
+
incrBy(key: string, value?: number): Promise<number>;
|
|
117
|
+
incrByFloat(key: string, value: number): Promise<number>;
|
|
118
|
+
decrBy(key: string, value: number): Promise<number>;
|
|
119
|
+
deleteByPattern(pattern: string): Promise<void>;
|
|
120
|
+
getNumber(key: string): Promise<number | undefined>;
|
|
121
|
+
expire(key: string, ttl: number): Promise<number>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface IPaginatedDataCache<T = any> {
|
|
125
|
+
generateCacheKey(
|
|
126
|
+
filter?: Record<string, any>,
|
|
127
|
+
limit?: number,
|
|
128
|
+
offset?: number
|
|
129
|
+
): string;
|
|
130
|
+
getCurrentVersion(): Promise<number>;
|
|
131
|
+
getCachedPaginatedData(
|
|
132
|
+
filter: Record<string, any>,
|
|
133
|
+
limit: number,
|
|
134
|
+
offset: number
|
|
135
|
+
): Promise<PaginationResult<T>>;
|
|
136
|
+
setCachedPaginatedData(
|
|
137
|
+
filter: Record<string, any>,
|
|
138
|
+
limit: number,
|
|
139
|
+
offset: number,
|
|
140
|
+
data: PaginationResult<T>,
|
|
141
|
+
ttlInSecs?: number
|
|
142
|
+
): Promise<any>;
|
|
143
|
+
incrementCacheVersion(ttl?: number): Promise<number>;
|
|
144
|
+
}
|
|
145
|
+
export interface PaginationResult<T = any> {
|
|
146
|
+
rows: T[];
|
|
147
|
+
total: number;
|
|
148
|
+
limit: number;
|
|
149
|
+
offset: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface HashCacheService {
|
|
153
|
+
hset(key: string, field: string, value: any): Promise<void>;
|
|
154
|
+
hget(key: string, field: string): Promise<string>;
|
|
155
|
+
hlen(key: string): Promise<number>;
|
|
156
|
+
hincrbyfloat(key: string, field: string, value?: number): Promise<string>;
|
|
157
|
+
hincrby(key: string, field: string, value?: number): Promise<number>;
|
|
158
|
+
hkeys(key: string): Promise<string[]>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface ListCacheService {
|
|
162
|
+
lpush(key: string, value: any): Promise<void>;
|
|
163
|
+
lset(key: string, index: number, value: any): Promise<void>;
|
|
164
|
+
lrem(
|
|
165
|
+
key: string,
|
|
166
|
+
count: string | number,
|
|
167
|
+
element: string | Buffer | number
|
|
168
|
+
): Promise<number>;
|
|
169
|
+
rpush(key: string, value: any): Promise<void>;
|
|
170
|
+
lrange(key: string, start: number, end: number): Promise<string[]>;
|
|
171
|
+
lindex(key: string, index: number): Promise<string>;
|
|
172
|
+
llen(key: string): Promise<number>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export type LuaCall = [script: string, numberOfKeys: number, ...args: any[]];
|
|
176
|
+
|
|
177
|
+
export interface CacheScriptEvaluator {
|
|
178
|
+
eval(script: string, numberOfKeys: number, ...args: any[]): Promise<any>;
|
|
179
|
+
multiEval(calls: LuaCall[]): Promise<any[]>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface LockResult {
|
|
183
|
+
isLocked: boolean;
|
|
184
|
+
attemptsLeft: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface CRUDService<T = any> {
|
|
188
|
+
findById(userId: any, ...options: any[]): Promise<T>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface SetCacheOption<Policy = SET_CACHE_POLICY> {
|
|
192
|
+
policy: Policy;
|
|
193
|
+
value?: any;
|
|
194
|
+
}
|
|
195
|
+
export interface IMessageQueueService {
|
|
196
|
+
initProducer(config?: any): Promise<void>;
|
|
197
|
+
initConsumer(config?: any): Promise<void>;
|
|
198
|
+
listen(subscribeConfig: any, runConfig: any): Promise<void>;
|
|
199
|
+
publish(record: any): Promise<void>;
|
|
200
|
+
commitOffsets(data: TopicPartitionOffsetAndMetadata[]): Promise<void>;
|
|
201
|
+
producer: Producer;
|
|
202
|
+
consumer: Consumer;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface HttpResponse<T = any> {
|
|
206
|
+
success?: boolean;
|
|
207
|
+
code?: string;
|
|
208
|
+
httpCode?: number;
|
|
209
|
+
message?: string;
|
|
210
|
+
data?: T;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface IKafkaService extends IMessageQueueService {
|
|
214
|
+
initProducer(config?: ProducerConfig): Promise<void>;
|
|
215
|
+
initConsumer(config?: ConsumerConfig): Promise<void>;
|
|
216
|
+
listen(
|
|
217
|
+
subscribeConfig: ConsumerSubscribeTopics,
|
|
218
|
+
runConfig: ConsumerRunConfig
|
|
219
|
+
): Promise<void>;
|
|
220
|
+
publish(record: ProducerRecord): Promise<void>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface PutObjectOption {
|
|
224
|
+
domain: string;
|
|
225
|
+
timeout?: number;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface CloudStorageClient {
|
|
229
|
+
generateTmpCredentials(sessionId: string): Promise<any>;
|
|
230
|
+
getObjectReadStream(fileName: string): Promise<any>;
|
|
231
|
+
deleteObject(filePath: string): Promise<void>;
|
|
232
|
+
uploadLocalToBucket(
|
|
233
|
+
fileName: string,
|
|
234
|
+
fileData: Buffer,
|
|
235
|
+
options?: PutObjectOption
|
|
236
|
+
): Promise<string>;
|
|
237
|
+
uploadRemoteObjectToBucket(
|
|
238
|
+
fileName: string,
|
|
239
|
+
remoteUrl: string,
|
|
240
|
+
options?: PutObjectOption
|
|
241
|
+
): Promise<string>;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface IFilter {
|
|
245
|
+
field: string;
|
|
246
|
+
operator: FILTER_OPERATOR;
|
|
247
|
+
value: any;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export type SORT_DIRECTION = "ASC" | "DESC";
|
|
251
|
+
|
|
252
|
+
export interface ISort {
|
|
253
|
+
columnName: string;
|
|
254
|
+
direction: SORT_DIRECTION;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface EmailSender {
|
|
258
|
+
send(mailOptions: SendMailOptions): Promise<void>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface SendMailOptions {
|
|
262
|
+
from?: string;
|
|
263
|
+
to?: string | string[];
|
|
264
|
+
cc?: string | string[];
|
|
265
|
+
bcc?: string | string[];
|
|
266
|
+
subject: string;
|
|
267
|
+
text?: string;
|
|
268
|
+
html?: string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface ICellOptions {
|
|
272
|
+
style?: Partial<Style>;
|
|
273
|
+
border?: Partial<Borders>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface ICellData {
|
|
277
|
+
value: CellValue;
|
|
278
|
+
options?: ICellOptions;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface STSResponse {
|
|
282
|
+
RequestId: string;
|
|
283
|
+
AssumedRoleUser: any;
|
|
284
|
+
Credentials: {
|
|
285
|
+
SecurityToken: string;
|
|
286
|
+
AccessKeyId: string;
|
|
287
|
+
AccessKeySecret: string;
|
|
288
|
+
Expiration: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export interface AuditGateway {
|
|
293
|
+
publish(logId: string, level: LOG_LEVEL, content: any): Promise<any>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface OperationResult<T = any> {
|
|
297
|
+
success: boolean;
|
|
298
|
+
data?: T;
|
|
299
|
+
message?: string;
|
|
300
|
+
code?: string;
|
|
301
|
+
httpCode?: number;
|
|
302
|
+
metadata?: any;
|
|
303
|
+
action?: string;
|
|
304
|
+
}
|