namirasoft-node 1.4.21 → 1.4.23
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/BaseApplication.js +7 -17
- package/dist/BaseApplication.js.map +1 -1
- package/dist/OTPOperation.d.ts +11 -2
- package/dist/OTPOperation.js +14 -4
- package/dist/OTPOperation.js.map +1 -1
- package/package.json +1 -1
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +432 -432
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +193 -193
- package/src/BaseCron.ts +54 -54
- package/src/BaseDatabase.ts +199 -199
- package/src/BaseEmailService.ts +38 -38
- package/src/BaseTable.ts +107 -107
- package/src/CommandOperation.ts +32 -32
- package/src/EmptyDatabase.ts +11 -11
- package/src/GmailService.ts +22 -22
- package/src/IPOperation.ts +38 -38
- package/src/Meta.ts +40 -40
- package/src/OTPOperation.ts +90 -71
- package/src/RequestHeaderService.ts +27 -27
- package/src/SMTPService.ts +26 -26
- package/src/ServerToServerOperation.ts +23 -23
- package/src/index.ts +16 -16
package/src/BaseTable.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { ArraySchema, BaseTypeSchema, BaseVariableSchema, ObjectSchema } from "namirasoft-schema";
|
|
2
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
-
import { ErrorOperation, BaseUUID } from "namirasoft-core";
|
|
4
|
-
|
|
5
|
-
export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption>
|
|
6
|
-
{
|
|
7
|
-
database: D;
|
|
8
|
-
uuid: BaseUUID;
|
|
9
|
-
constructor(database: D)
|
|
10
|
-
{
|
|
11
|
-
this.database = database;
|
|
12
|
-
this.uuid = new BaseUUID(this.getShortName());
|
|
13
|
-
}
|
|
14
|
-
public abstract getName(): string;
|
|
15
|
-
public abstract getShortName(): string;
|
|
16
|
-
protected addSecureColumns(columns: string[]): string[]
|
|
17
|
-
{
|
|
18
|
-
return columns;
|
|
19
|
-
}
|
|
20
|
-
protected addReadOnlyColumns(columns: string[]): string[]
|
|
21
|
-
{
|
|
22
|
-
return columns;
|
|
23
|
-
}
|
|
24
|
-
public getSecureColumns(): string[]
|
|
25
|
-
{
|
|
26
|
-
let columns: string[] = [];
|
|
27
|
-
return this.addSecureColumns(columns);
|
|
28
|
-
}
|
|
29
|
-
public getReadOnlyColumns(): string[]
|
|
30
|
-
{
|
|
31
|
-
let columns: string[] = [];
|
|
32
|
-
return this.addReadOnlyColumns(columns);
|
|
33
|
-
}
|
|
34
|
-
public secure(obj: any)
|
|
35
|
-
{
|
|
36
|
-
if (obj.dataValues)
|
|
37
|
-
obj = obj.dataValues;
|
|
38
|
-
let secureColumns: string[] = this.getSecureColumns();
|
|
39
|
-
secureColumns.forEach(col => delete obj[col]);
|
|
40
|
-
return obj;
|
|
41
|
-
}
|
|
42
|
-
public getArraySchema(require: boolean, name?: string): ArraySchema
|
|
43
|
-
{
|
|
44
|
-
let ans = this.getSchema(require, name);
|
|
45
|
-
return new ArraySchema(require, [ans]);
|
|
46
|
-
}
|
|
47
|
-
public getSchema(require: boolean, name?: string): ObjectSchema
|
|
48
|
-
{
|
|
49
|
-
let secureColumns: string[] = this.getSecureColumns();
|
|
50
|
-
let readOnlyColumns: string[] = this.getReadOnlyColumns();
|
|
51
|
-
let ans = new ObjectSchema(name ?? this.getName(), require, null);
|
|
52
|
-
this.forEachColumn((name, element) =>
|
|
53
|
-
{
|
|
54
|
-
if (!secureColumns.includes(name))
|
|
55
|
-
ans.addField(this.getVariableSchema(name, element, readOnlyColumns.includes(name)));
|
|
56
|
-
});
|
|
57
|
-
return ans;
|
|
58
|
-
}
|
|
59
|
-
public checkColumn(column: string)
|
|
60
|
-
{
|
|
61
|
-
let columns: string[] = [];
|
|
62
|
-
this.forEachColumn(name => columns.push(name));
|
|
63
|
-
if (!columns.includes(column))
|
|
64
|
-
ErrorOperation.throwHTTP(404, `Column '${column}' not found`);
|
|
65
|
-
}
|
|
66
|
-
public abstract forEachColumn(handler: (name: string, column: ModelColumnOption) => void): void;
|
|
67
|
-
private getVariableSchema(name: string, element: ModelColumnOption, read_only: boolean): BaseVariableSchema
|
|
68
|
-
{
|
|
69
|
-
let schema = this.getTypeSchema(element);
|
|
70
|
-
schema.read_only = read_only;
|
|
71
|
-
let es = this.getExamples();
|
|
72
|
-
schema.example = es[name] ?? "";
|
|
73
|
-
return new BaseVariableSchema(name, schema);
|
|
74
|
-
}
|
|
75
|
-
protected abstract getTypeSchema(element: ModelColumnOption): BaseTypeSchema;
|
|
76
|
-
protected getExamples(): { [name: string]: string }
|
|
77
|
-
{
|
|
78
|
-
return {};
|
|
79
|
-
}
|
|
80
|
-
public getSchemaNames(): string[]
|
|
81
|
-
{
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
public getSchemaByName(require: boolean, name?: string): ObjectSchema
|
|
85
|
-
{
|
|
86
|
-
let ans = this.getSchema(require, name);
|
|
87
|
-
if (name)
|
|
88
|
-
{
|
|
89
|
-
let names = this.getSchemaNames();
|
|
90
|
-
if (!names.includes(name))
|
|
91
|
-
throw new Error("Wrong schema name was provided: " + name);
|
|
92
|
-
this.setSchemaByName(ans);
|
|
93
|
-
}
|
|
94
|
-
return ans;
|
|
95
|
-
}
|
|
96
|
-
public getArraySchemaByName(require: boolean, name?: string): ArraySchema
|
|
97
|
-
{
|
|
98
|
-
let ans = this.getSchemaByName(require, name);
|
|
99
|
-
return new ArraySchema(require, [ans]);
|
|
100
|
-
}
|
|
101
|
-
protected setSchemaByName(_: ObjectSchema): void
|
|
102
|
-
{
|
|
103
|
-
}
|
|
104
|
-
public getNotFoundError(conditions: any | null)
|
|
105
|
-
{
|
|
106
|
-
return ErrorOperation.getHTTP(404, "Could not find " + this.getName() + " for " + JSON.stringify(conditions));
|
|
107
|
-
}
|
|
1
|
+
import { ArraySchema, BaseTypeSchema, BaseVariableSchema, ObjectSchema } from "namirasoft-schema";
|
|
2
|
+
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
+
import { ErrorOperation, BaseUUID } from "namirasoft-core";
|
|
4
|
+
|
|
5
|
+
export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption>
|
|
6
|
+
{
|
|
7
|
+
database: D;
|
|
8
|
+
uuid: BaseUUID;
|
|
9
|
+
constructor(database: D)
|
|
10
|
+
{
|
|
11
|
+
this.database = database;
|
|
12
|
+
this.uuid = new BaseUUID(this.getShortName());
|
|
13
|
+
}
|
|
14
|
+
public abstract getName(): string;
|
|
15
|
+
public abstract getShortName(): string;
|
|
16
|
+
protected addSecureColumns(columns: string[]): string[]
|
|
17
|
+
{
|
|
18
|
+
return columns;
|
|
19
|
+
}
|
|
20
|
+
protected addReadOnlyColumns(columns: string[]): string[]
|
|
21
|
+
{
|
|
22
|
+
return columns;
|
|
23
|
+
}
|
|
24
|
+
public getSecureColumns(): string[]
|
|
25
|
+
{
|
|
26
|
+
let columns: string[] = [];
|
|
27
|
+
return this.addSecureColumns(columns);
|
|
28
|
+
}
|
|
29
|
+
public getReadOnlyColumns(): string[]
|
|
30
|
+
{
|
|
31
|
+
let columns: string[] = [];
|
|
32
|
+
return this.addReadOnlyColumns(columns);
|
|
33
|
+
}
|
|
34
|
+
public secure(obj: any)
|
|
35
|
+
{
|
|
36
|
+
if (obj.dataValues)
|
|
37
|
+
obj = obj.dataValues;
|
|
38
|
+
let secureColumns: string[] = this.getSecureColumns();
|
|
39
|
+
secureColumns.forEach(col => delete obj[col]);
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
public getArraySchema(require: boolean, name?: string): ArraySchema
|
|
43
|
+
{
|
|
44
|
+
let ans = this.getSchema(require, name);
|
|
45
|
+
return new ArraySchema(require, [ans]);
|
|
46
|
+
}
|
|
47
|
+
public getSchema(require: boolean, name?: string): ObjectSchema
|
|
48
|
+
{
|
|
49
|
+
let secureColumns: string[] = this.getSecureColumns();
|
|
50
|
+
let readOnlyColumns: string[] = this.getReadOnlyColumns();
|
|
51
|
+
let ans = new ObjectSchema(name ?? this.getName(), require, null);
|
|
52
|
+
this.forEachColumn((name, element) =>
|
|
53
|
+
{
|
|
54
|
+
if (!secureColumns.includes(name))
|
|
55
|
+
ans.addField(this.getVariableSchema(name, element, readOnlyColumns.includes(name)));
|
|
56
|
+
});
|
|
57
|
+
return ans;
|
|
58
|
+
}
|
|
59
|
+
public checkColumn(column: string)
|
|
60
|
+
{
|
|
61
|
+
let columns: string[] = [];
|
|
62
|
+
this.forEachColumn(name => columns.push(name));
|
|
63
|
+
if (!columns.includes(column))
|
|
64
|
+
ErrorOperation.throwHTTP(404, `Column '${column}' not found`);
|
|
65
|
+
}
|
|
66
|
+
public abstract forEachColumn(handler: (name: string, column: ModelColumnOption) => void): void;
|
|
67
|
+
private getVariableSchema(name: string, element: ModelColumnOption, read_only: boolean): BaseVariableSchema
|
|
68
|
+
{
|
|
69
|
+
let schema = this.getTypeSchema(element);
|
|
70
|
+
schema.read_only = read_only;
|
|
71
|
+
let es = this.getExamples();
|
|
72
|
+
schema.example = es[name] ?? "";
|
|
73
|
+
return new BaseVariableSchema(name, schema);
|
|
74
|
+
}
|
|
75
|
+
protected abstract getTypeSchema(element: ModelColumnOption): BaseTypeSchema;
|
|
76
|
+
protected getExamples(): { [name: string]: string }
|
|
77
|
+
{
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
public getSchemaNames(): string[]
|
|
81
|
+
{
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
public getSchemaByName(require: boolean, name?: string): ObjectSchema
|
|
85
|
+
{
|
|
86
|
+
let ans = this.getSchema(require, name);
|
|
87
|
+
if (name)
|
|
88
|
+
{
|
|
89
|
+
let names = this.getSchemaNames();
|
|
90
|
+
if (!names.includes(name))
|
|
91
|
+
throw new Error("Wrong schema name was provided: " + name);
|
|
92
|
+
this.setSchemaByName(ans);
|
|
93
|
+
}
|
|
94
|
+
return ans;
|
|
95
|
+
}
|
|
96
|
+
public getArraySchemaByName(require: boolean, name?: string): ArraySchema
|
|
97
|
+
{
|
|
98
|
+
let ans = this.getSchemaByName(require, name);
|
|
99
|
+
return new ArraySchema(require, [ans]);
|
|
100
|
+
}
|
|
101
|
+
protected setSchemaByName(_: ObjectSchema): void
|
|
102
|
+
{
|
|
103
|
+
}
|
|
104
|
+
public getNotFoundError(conditions: any | null)
|
|
105
|
+
{
|
|
106
|
+
return ErrorOperation.getHTTP(404, "Could not find " + this.getName() + " for " + JSON.stringify(conditions));
|
|
107
|
+
}
|
|
108
108
|
}
|
package/src/CommandOperation.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { ExecException, exec, execSync } from 'child_process';
|
|
2
|
-
import { ConsoleOperation } from 'namirasoft-core';
|
|
3
|
-
export class CommandOperation
|
|
4
|
-
{
|
|
5
|
-
static exec(command: string, cwd: string | undefined)
|
|
6
|
-
{
|
|
7
|
-
exec(command, { cwd }, (error: ExecException | null, stdout: string, stderr: string) =>
|
|
8
|
-
{
|
|
9
|
-
if (error)
|
|
10
|
-
{
|
|
11
|
-
ConsoleOperation.error(`error: ${error.message}`);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (stderr)
|
|
15
|
-
{
|
|
16
|
-
ConsoleOperation.error(`stderr: ${stderr}`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
ConsoleOperation.log(`stdout:\n${stdout}`);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
static execSync(command: string, cwd: string | undefined)
|
|
23
|
-
{
|
|
24
|
-
try
|
|
25
|
-
{
|
|
26
|
-
return execSync(command, { cwd, encoding: 'utf-8' });
|
|
27
|
-
} catch (error: any)
|
|
28
|
-
{
|
|
29
|
-
ConsoleOperation.error(error.stdout);
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
import { ExecException, exec, execSync } from 'child_process';
|
|
2
|
+
import { ConsoleOperation } from 'namirasoft-core';
|
|
3
|
+
export class CommandOperation
|
|
4
|
+
{
|
|
5
|
+
static exec(command: string, cwd: string | undefined)
|
|
6
|
+
{
|
|
7
|
+
exec(command, { cwd }, (error: ExecException | null, stdout: string, stderr: string) =>
|
|
8
|
+
{
|
|
9
|
+
if (error)
|
|
10
|
+
{
|
|
11
|
+
ConsoleOperation.error(`error: ${error.message}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (stderr)
|
|
15
|
+
{
|
|
16
|
+
ConsoleOperation.error(`stderr: ${stderr}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
ConsoleOperation.log(`stdout:\n${stdout}`);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
static execSync(command: string, cwd: string | undefined)
|
|
23
|
+
{
|
|
24
|
+
try
|
|
25
|
+
{
|
|
26
|
+
return execSync(command, { cwd, encoding: 'utf-8' });
|
|
27
|
+
} catch (error: any)
|
|
28
|
+
{
|
|
29
|
+
ConsoleOperation.error(error.stdout);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
33
|
}
|
package/src/EmptyDatabase.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
2
|
-
|
|
3
|
-
export class EmptyDatabase extends BaseDatabase
|
|
4
|
-
{
|
|
5
|
-
override async init() { }
|
|
6
|
-
override connect() { }
|
|
7
|
-
override async sync(_: boolean) { }
|
|
8
|
-
public override getSortOptions(): string[]
|
|
9
|
-
{
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
1
|
+
import { BaseDatabase } from "./BaseDatabase";
|
|
2
|
+
|
|
3
|
+
export class EmptyDatabase extends BaseDatabase
|
|
4
|
+
{
|
|
5
|
+
override async init() { }
|
|
6
|
+
override connect() { }
|
|
7
|
+
override async sync(_: boolean) { }
|
|
8
|
+
public override getSortOptions(): string[]
|
|
9
|
+
{
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
12
|
}
|
package/src/GmailService.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import smtpTransport from 'nodemailer-smtp-transport';
|
|
2
|
-
import { BaseEmailService } from './BaseEmailService';
|
|
3
|
-
|
|
4
|
-
export class GmailService extends BaseEmailService
|
|
5
|
-
{
|
|
6
|
-
password: string;
|
|
7
|
-
constructor(username: string, password: string)
|
|
8
|
-
{
|
|
9
|
-
super(username);
|
|
10
|
-
this.password = password;
|
|
11
|
-
}
|
|
12
|
-
protected override getTransform(): any
|
|
13
|
-
{
|
|
14
|
-
return smtpTransport({
|
|
15
|
-
service: 'gmail',
|
|
16
|
-
host: 'smtp.gmail.com',
|
|
17
|
-
auth: {
|
|
18
|
-
user: this.username,
|
|
19
|
-
pass: this.password
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
1
|
+
import smtpTransport from 'nodemailer-smtp-transport';
|
|
2
|
+
import { BaseEmailService } from './BaseEmailService';
|
|
3
|
+
|
|
4
|
+
export class GmailService extends BaseEmailService
|
|
5
|
+
{
|
|
6
|
+
password: string;
|
|
7
|
+
constructor(username: string, password: string)
|
|
8
|
+
{
|
|
9
|
+
super(username);
|
|
10
|
+
this.password = password;
|
|
11
|
+
}
|
|
12
|
+
protected override getTransform(): any
|
|
13
|
+
{
|
|
14
|
+
return smtpTransport({
|
|
15
|
+
service: 'gmail',
|
|
16
|
+
host: 'smtp.gmail.com',
|
|
17
|
+
auth: {
|
|
18
|
+
user: this.username,
|
|
19
|
+
pass: this.password
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
23
|
}
|
package/src/IPOperation.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import * as express from 'express';
|
|
2
|
-
import { getClientIp } from '@supercharge/request-ip';
|
|
3
|
-
import { RequestHeaderService } from './RequestHeaderService';
|
|
4
|
-
import { ErrorOperation } from 'namirasoft-core';
|
|
5
|
-
|
|
6
|
-
export class IPOperation
|
|
7
|
-
{
|
|
8
|
-
static ERROR_MESSAGE_IP_IS_NOT_WHITELIST = `Ip does not match the whitelisted IP address: {0}`;
|
|
9
|
-
static getIP(req: express.Request): string
|
|
10
|
-
{
|
|
11
|
-
let ip = new RequestHeaderService(req, 'cf-connecting-ip').getString();
|
|
12
|
-
if (!ip)
|
|
13
|
-
ip = new RequestHeaderService(req, 'x-forwarded-for').getString();
|
|
14
|
-
if (!ip)
|
|
15
|
-
ip = getClientIp(req) ?? "";
|
|
16
|
-
ip = ip.split(',')[0];
|
|
17
|
-
return ip;
|
|
18
|
-
}
|
|
19
|
-
static isWhitelist(req: express.Request, whitelist: string[])
|
|
20
|
-
{
|
|
21
|
-
let ip = this.getIP(req);
|
|
22
|
-
if (!whitelist)
|
|
23
|
-
return true;
|
|
24
|
-
if (whitelist.length === 0)
|
|
25
|
-
return true;
|
|
26
|
-
if (whitelist.includes(ip))
|
|
27
|
-
return true;
|
|
28
|
-
for (let item of whitelist)
|
|
29
|
-
if (ip.substring(0, item.length) === item)
|
|
30
|
-
return true;
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
static checkWhitelist(req: express.Request, whitelist: string[])
|
|
34
|
-
{
|
|
35
|
-
let valid = this.isWhitelist(req, whitelist);
|
|
36
|
-
if (!valid)
|
|
37
|
-
ErrorOperation.throwHTTP(403, this.ERROR_MESSAGE_IP_IS_NOT_WHITELIST, this.getIP(req));
|
|
38
|
-
}
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { getClientIp } from '@supercharge/request-ip';
|
|
3
|
+
import { RequestHeaderService } from './RequestHeaderService';
|
|
4
|
+
import { ErrorOperation } from 'namirasoft-core';
|
|
5
|
+
|
|
6
|
+
export class IPOperation
|
|
7
|
+
{
|
|
8
|
+
static ERROR_MESSAGE_IP_IS_NOT_WHITELIST = `Ip does not match the whitelisted IP address: {0}`;
|
|
9
|
+
static getIP(req: express.Request): string
|
|
10
|
+
{
|
|
11
|
+
let ip = new RequestHeaderService(req, 'cf-connecting-ip').getString();
|
|
12
|
+
if (!ip)
|
|
13
|
+
ip = new RequestHeaderService(req, 'x-forwarded-for').getString();
|
|
14
|
+
if (!ip)
|
|
15
|
+
ip = getClientIp(req) ?? "";
|
|
16
|
+
ip = ip.split(',')[0];
|
|
17
|
+
return ip;
|
|
18
|
+
}
|
|
19
|
+
static isWhitelist(req: express.Request, whitelist: string[])
|
|
20
|
+
{
|
|
21
|
+
let ip = this.getIP(req);
|
|
22
|
+
if (!whitelist)
|
|
23
|
+
return true;
|
|
24
|
+
if (whitelist.length === 0)
|
|
25
|
+
return true;
|
|
26
|
+
if (whitelist.includes(ip))
|
|
27
|
+
return true;
|
|
28
|
+
for (let item of whitelist)
|
|
29
|
+
if (ip.substring(0, item.length) === item)
|
|
30
|
+
return true;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
static checkWhitelist(req: express.Request, whitelist: string[])
|
|
34
|
+
{
|
|
35
|
+
let valid = this.isWhitelist(req, whitelist);
|
|
36
|
+
if (!valid)
|
|
37
|
+
ErrorOperation.throwHTTP(403, this.ERROR_MESSAGE_IP_IS_NOT_WHITELIST, this.getIP(req));
|
|
38
|
+
}
|
|
39
39
|
}
|
package/src/Meta.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import * as express from 'express';
|
|
2
|
-
import { IncomingHttpHeaders } from "http";
|
|
3
|
-
import { IPOperation } from './IPOperation';
|
|
4
|
-
import { HTTPMethod } from 'namirasoft-core';
|
|
5
|
-
|
|
6
|
-
export class Meta
|
|
7
|
-
{
|
|
8
|
-
info: { name: string, tag: string, method: HTTPMethod, path: string, summary: string };
|
|
9
|
-
ip: string;
|
|
10
|
-
method: string;
|
|
11
|
-
url: string;
|
|
12
|
-
headers?: IncomingHttpHeaders;
|
|
13
|
-
body?: any;
|
|
14
|
-
start_time: Date | null = null;
|
|
15
|
-
end_time: Date | null = null;
|
|
16
|
-
duration: number | null = null;
|
|
17
|
-
code: number = 200;
|
|
18
|
-
message: string = "Success";
|
|
19
|
-
error: Error | null = null;
|
|
20
|
-
constructor(info: { name: string, tag: string, method: HTTPMethod, path: string, summary: string }, req: express.Request, sensitive: boolean)
|
|
21
|
-
{
|
|
22
|
-
this.info = info;
|
|
23
|
-
this.ip = IPOperation.getIP(req);
|
|
24
|
-
this.method = req.method;
|
|
25
|
-
this.url = req.originalUrl;
|
|
26
|
-
if (!sensitive)
|
|
27
|
-
{
|
|
28
|
-
this.headers = req.headers;
|
|
29
|
-
this.body = req.body;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
onStart()
|
|
33
|
-
{
|
|
34
|
-
this.start_time = new Date();
|
|
35
|
-
}
|
|
36
|
-
onFinish()
|
|
37
|
-
{
|
|
38
|
-
this.end_time = new Date();
|
|
39
|
-
this.duration = (this.end_time?.getTime() ?? 0) - (this.start_time?.getTime() ?? 0);
|
|
40
|
-
}
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { IncomingHttpHeaders } from "http";
|
|
3
|
+
import { IPOperation } from './IPOperation';
|
|
4
|
+
import { HTTPMethod } from 'namirasoft-core';
|
|
5
|
+
|
|
6
|
+
export class Meta
|
|
7
|
+
{
|
|
8
|
+
info: { name: string, tag: string, method: HTTPMethod, path: string, summary: string };
|
|
9
|
+
ip: string;
|
|
10
|
+
method: string;
|
|
11
|
+
url: string;
|
|
12
|
+
headers?: IncomingHttpHeaders;
|
|
13
|
+
body?: any;
|
|
14
|
+
start_time: Date | null = null;
|
|
15
|
+
end_time: Date | null = null;
|
|
16
|
+
duration: number | null = null;
|
|
17
|
+
code: number = 200;
|
|
18
|
+
message: string = "Success";
|
|
19
|
+
error: Error | null = null;
|
|
20
|
+
constructor(info: { name: string, tag: string, method: HTTPMethod, path: string, summary: string }, req: express.Request, sensitive: boolean)
|
|
21
|
+
{
|
|
22
|
+
this.info = info;
|
|
23
|
+
this.ip = IPOperation.getIP(req);
|
|
24
|
+
this.method = req.method;
|
|
25
|
+
this.url = req.originalUrl;
|
|
26
|
+
if (!sensitive)
|
|
27
|
+
{
|
|
28
|
+
this.headers = req.headers;
|
|
29
|
+
this.body = req.body;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
onStart()
|
|
33
|
+
{
|
|
34
|
+
this.start_time = new Date();
|
|
35
|
+
}
|
|
36
|
+
onFinish()
|
|
37
|
+
{
|
|
38
|
+
this.end_time = new Date();
|
|
39
|
+
this.duration = (this.end_time?.getTime() ?? 0) - (this.start_time?.getTime() ?? 0);
|
|
40
|
+
}
|
|
41
41
|
}
|