ztechno_core 0.0.38 → 0.0.42
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/lib/crypto_service.d.ts +1 -5
- package/lib/index.d.ts +10 -0
- package/lib/index.js +0 -2
- package/lib/mail_service.d.ts +1 -20
- package/lib/translate_service.d.ts +1 -13
- package/lib/user_service.d.ts +2 -24
- package/lib/user_service.js +11 -11
- package/package.json +1 -1
package/lib/crypto_service.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
iv: string;
|
|
3
|
-
encryptedData: string;
|
|
4
|
-
};
|
|
1
|
+
import { HashStruct } from './typings/crypto_service';
|
|
5
2
|
export declare class ZCryptoService {
|
|
6
3
|
static encrypt(text: string): HashStruct;
|
|
7
4
|
static decrypt(data: HashStruct): string;
|
|
@@ -22,4 +19,3 @@ export declare class ZCryptoService {
|
|
|
22
19
|
),
|
|
23
20
|
): string;
|
|
24
21
|
}
|
|
25
|
-
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -4,4 +4,14 @@ import { ZMailService } from './mail_service';
|
|
|
4
4
|
import { ZSqlService } from './sql_service';
|
|
5
5
|
import { ZTranslateService } from './translate_service';
|
|
6
6
|
import { ZUserService } from './user_service';
|
|
7
|
+
export { HashStruct } from './typings/crypto_service';
|
|
8
|
+
export {
|
|
9
|
+
MailOptions,
|
|
10
|
+
MailOptionsBase,
|
|
11
|
+
MailOptionsHtml,
|
|
12
|
+
MailOptionsText,
|
|
13
|
+
MailServiceOptions,
|
|
14
|
+
} from './typings/mail_service';
|
|
15
|
+
export { TranslateData, ZDom, ZNode, ZNodeText, dbTranslationRow } from './typings/translate_service';
|
|
16
|
+
export { ZRequiredUserColumns, ZUser, ZUserCredentials, ZUserSession } from './typings/user_service';
|
|
7
17
|
export { ZCryptoService, ZMailService, ZSqlService, ZTranslateService, ZUserService, ZEngineBase };
|
package/lib/index.js
CHANGED
package/lib/mail_service.d.ts
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
auth: {
|
|
3
|
-
user: string;
|
|
4
|
-
pass: string;
|
|
5
|
-
};
|
|
6
|
-
mailSender: string;
|
|
7
|
-
};
|
|
8
|
-
type MailOptionsText = {
|
|
9
|
-
recipient: string;
|
|
10
|
-
subject: string;
|
|
11
|
-
from?: string;
|
|
12
|
-
body: string;
|
|
13
|
-
};
|
|
14
|
-
type MailOptionsHtml = {
|
|
15
|
-
recipient: string;
|
|
16
|
-
subject: string;
|
|
17
|
-
from?: string;
|
|
18
|
-
html: string;
|
|
19
|
-
};
|
|
1
|
+
import { MailOptionsHtml, MailOptionsText, MailServiceOptions } from './typings/mail_service';
|
|
20
2
|
export declare class ZMailService {
|
|
21
3
|
private opt;
|
|
22
4
|
constructor(opt: MailServiceOptions);
|
|
23
5
|
send(mailOpts: MailOptionsText | MailOptionsHtml): Promise<any>;
|
|
24
6
|
}
|
|
25
|
-
export {};
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { ZSqlService } from './sql_service';
|
|
2
|
-
|
|
3
|
-
value: string;
|
|
4
|
-
meta?: {
|
|
5
|
-
prefix: string;
|
|
6
|
-
suffix: string;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
type dbTranslationRow = {
|
|
10
|
-
lang: string;
|
|
11
|
-
key: string;
|
|
12
|
-
value: string;
|
|
13
|
-
};
|
|
2
|
+
import { TranslateData, dbTranslationRow } from '.';
|
|
14
3
|
export declare class ZTranslateService {
|
|
15
4
|
private opt;
|
|
16
5
|
private localCache;
|
|
@@ -56,4 +45,3 @@ export declare class ZTranslateService {
|
|
|
56
45
|
}>;
|
|
57
46
|
private fetchAll;
|
|
58
47
|
}
|
|
59
|
-
export {};
|
package/lib/user_service.d.ts
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
import { ZSqlService } from './sql_service';
|
|
2
|
-
|
|
3
|
-
id: number;
|
|
4
|
-
name: string;
|
|
5
|
-
session: string;
|
|
6
|
-
role: string | null;
|
|
7
|
-
admin: 0 | 1;
|
|
8
|
-
updated_at: any;
|
|
9
|
-
created_at: any;
|
|
10
|
-
};
|
|
11
|
-
type ZRequiredUserColumns = {
|
|
12
|
-
name: string;
|
|
13
|
-
role: string | null;
|
|
14
|
-
pass: string;
|
|
15
|
-
admin: 0 | 1;
|
|
16
|
-
};
|
|
17
|
-
type ZUserCredentials = {
|
|
18
|
-
name: string;
|
|
19
|
-
pass: string;
|
|
20
|
-
};
|
|
21
|
-
type ZUserSession = {
|
|
22
|
-
session: string;
|
|
23
|
-
};
|
|
2
|
+
import { ZRequiredUserColumns, ZUser, ZUserSession, ZUserCredentials } from './typings/user_service';
|
|
24
3
|
export declare class ZUserService {
|
|
25
4
|
private tableName;
|
|
26
5
|
private sqlService;
|
|
@@ -30,7 +9,7 @@ export declare class ZUserService {
|
|
|
30
9
|
checkTableHasAdmin(): Promise<boolean>;
|
|
31
10
|
private createTable;
|
|
32
11
|
ensureTableExists(): Promise<void>;
|
|
33
|
-
register({
|
|
12
|
+
register({ email, pass, role, admin }: ZRequiredUserColumns): Promise<{
|
|
34
13
|
session: string;
|
|
35
14
|
}>;
|
|
36
15
|
find(opt: { email: string }): Promise<ZUser | undefined>;
|
|
@@ -42,4 +21,3 @@ export declare class ZUserService {
|
|
|
42
21
|
private genSession;
|
|
43
22
|
private hashPass;
|
|
44
23
|
}
|
|
45
|
-
export {};
|
package/lib/user_service.js
CHANGED
|
@@ -26,7 +26,7 @@ class ZUserService {
|
|
|
26
26
|
await this.sqlService.query(`
|
|
27
27
|
CREATE TABLE \`${this.tableName}\` (
|
|
28
28
|
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
29
|
-
\`
|
|
29
|
+
\`email\` varchar(64) NOT NULL,
|
|
30
30
|
\`role\` varchar(64) DEFAULT NULL,
|
|
31
31
|
\`pass\` varchar(512) NOT NULL,
|
|
32
32
|
\`session\` varchar(512) NOT NULL,
|
|
@@ -34,8 +34,8 @@ class ZUserService {
|
|
|
34
34
|
\`updated_at\` datetime NOT NULL DEFAULT current_timestamp(),
|
|
35
35
|
\`created_at\` datetime NOT NULL DEFAULT current_timestamp(),
|
|
36
36
|
PRIMARY KEY (\`id\`),
|
|
37
|
-
UNIQUE KEY \`
|
|
38
|
-
KEY \`
|
|
37
|
+
UNIQUE KEY \`email_UNIQUE\` (\`email\`),
|
|
38
|
+
KEY \`email\` (\`email\`),
|
|
39
39
|
KEY \`createdat\` (\`created_at\`),
|
|
40
40
|
KEY \`updatedat\` (\`updated_at\`),
|
|
41
41
|
KEY \`session\` (\`session\`)
|
|
@@ -48,14 +48,14 @@ class ZUserService {
|
|
|
48
48
|
await this.createTable();
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
async register({
|
|
52
|
-
const session = this.genSession({
|
|
51
|
+
async register({ email, pass, role, admin }) {
|
|
52
|
+
const session = this.genSession({ email, pass });
|
|
53
53
|
await this.sqlService.query(
|
|
54
54
|
`
|
|
55
|
-
INSERT INTO \`${this.tableName}\` (
|
|
55
|
+
INSERT INTO \`${this.tableName}\` (email, pass, session, role, admin)
|
|
56
56
|
VALUES (?, ?, ?, ?, ?)
|
|
57
57
|
`,
|
|
58
|
-
[
|
|
58
|
+
[email, this.hashPass({ email, pass }), session, role, admin],
|
|
59
59
|
);
|
|
60
60
|
return { session };
|
|
61
61
|
}
|
|
@@ -69,7 +69,7 @@ class ZUserService {
|
|
|
69
69
|
return rows[0];
|
|
70
70
|
}
|
|
71
71
|
async auth(opt) {
|
|
72
|
-
if (!opt.session && !opt.
|
|
72
|
+
if (!opt.session && !opt.email && !opt.pass) {
|
|
73
73
|
return { authenticated: false };
|
|
74
74
|
}
|
|
75
75
|
const res = await (opt.session
|
|
@@ -83,16 +83,16 @@ class ZUserService {
|
|
|
83
83
|
`
|
|
84
84
|
SELECT id, name, session, role, admin, updated_at, created_at FROM \`${this.tableName}\`
|
|
85
85
|
WHERE name=? AND pass=?`,
|
|
86
|
-
[opt.
|
|
86
|
+
[opt.email, this.hashPass(opt)],
|
|
87
87
|
));
|
|
88
88
|
return res.length === 0 ? { authenticated: false } : { user: res[0], session: res[0].session, authenticated: true };
|
|
89
89
|
}
|
|
90
|
-
genSession({ name }) {
|
|
90
|
+
genSession({ email: name }) {
|
|
91
91
|
const salt = this.salt;
|
|
92
92
|
const data = name + Date.now() * Math.random();
|
|
93
93
|
return crypto_service_1.ZCryptoService.hash('sha256', data, { saltMode: 'simple', salt });
|
|
94
94
|
}
|
|
95
|
-
hashPass({
|
|
95
|
+
hashPass({ email, pass }) {
|
|
96
96
|
const salt = name + this.salt;
|
|
97
97
|
return crypto_service_1.ZCryptoService.hash('sha256', pass, { saltMode: 'simple', salt });
|
|
98
98
|
}
|