@scefira/dfw 0.1.14 → 0.2.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.
Files changed (42) hide show
  1. package/lib/DFWInstance.d.ts +20 -20
  2. package/lib/DFWInstance.js +55 -55
  3. package/lib/DFWUtils.d.ts +27 -27
  4. package/lib/DFWUtils.js +63 -63
  5. package/lib/DFWUtils.js.map +1 -1
  6. package/lib/index.d.ts +10 -10
  7. package/lib/index.js +25 -25
  8. package/lib/manager/APIManager.d.ts +47 -47
  9. package/lib/manager/APIManager.d.ts.map +1 -1
  10. package/lib/manager/APIManager.js +207 -233
  11. package/lib/manager/APIManager.js.map +1 -1
  12. package/lib/manager/DFWModule.d.ts +13 -13
  13. package/lib/manager/DFWModule.js +19 -19
  14. package/lib/manager/DatabaseManager.d.ts +8 -8
  15. package/lib/manager/DatabaseManager.js +24 -24
  16. package/lib/manager/FileManager.d.ts +130 -130
  17. package/lib/manager/FileManager.js +254 -254
  18. package/lib/manager/SecurityManager.d.ts +50 -50
  19. package/lib/manager/SecurityManager.d.ts.map +1 -1
  20. package/lib/manager/SecurityManager.js +187 -191
  21. package/lib/manager/SecurityManager.js.map +1 -1
  22. package/lib/manager/SessionManager.d.ts +40 -40
  23. package/lib/manager/SessionManager.d.ts.map +1 -1
  24. package/lib/manager/SessionManager.js +194 -173
  25. package/lib/manager/SessionManager.js.map +1 -1
  26. package/lib/manager/UserManager.d.ts +42 -42
  27. package/lib/manager/UserManager.js +62 -62
  28. package/lib/test.d.ts +1 -1
  29. package/lib/test.js +70 -70
  30. package/lib/test.js.map +1 -1
  31. package/lib/types/APIListenerConfig.d.ts +52 -52
  32. package/lib/types/APIListenerConfig.js +2 -2
  33. package/lib/types/DFWBoot.d.ts +18 -18
  34. package/lib/types/DFWBoot.d.ts.map +1 -1
  35. package/lib/types/DFWBoot.js +2 -2
  36. package/lib/types/DFWConfig.d.ts +54 -54
  37. package/lib/types/DFWConfig.js +2 -2
  38. package/lib/types/DFWRequestScheme.d.ts +33 -37
  39. package/lib/types/DFWRequestScheme.d.ts.map +1 -1
  40. package/lib/types/DFWRequestScheme.js +2 -2
  41. package/package.json +5 -4
  42. package/prisma/schema.prisma +5 -27
@@ -1,174 +1,195 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const DFWModule_1 = __importDefault(require("./DFWModule"));
16
- const luxon_1 = require("luxon");
17
- const DFWUtils_1 = __importDefault(require("../DFWUtils"));
18
- const SecurityManager_1 = __importDefault(require("./SecurityManager"));
19
- const DEFAULT_SESSION_EXPIRE_DAYS = 7;
20
- class SessionManager extends DFWModule_1.default {
21
- constructor(DFW) {
22
- super(DFW);
23
- this.stkFieldName = "stk";
24
- this.sidFieldName = "sid";
25
- this.middleware = (req, res) => __awaiter(this, void 0, void 0, function* () {
26
- req.dfw.session = {
27
- isLogged: false,
28
- user: undefined,
29
- record: undefined,
30
- };
31
- req.dfw.SessionManager = this;
32
- if (req.dfw.__meta.config.noSession)
33
- return;
34
- if (!req.cookies || !req.cookies.sid || !req.cookies.stk) {
35
- req.dfw.session = yield this.regenerateSessionAsync(req);
36
- }
37
- else {
38
- let session = yield this.db.dfw_session.findFirst({
39
- where: { id: Number(req.cookies.sid), token: req.cookies.stk },
40
- include: {
41
- user: true
42
- },
43
- });
44
- req.dfw.session = session ? { record: session, user: session.user, isLogged: session.user ? true : false } : yield this.regenerateSessionAsync(req);
45
- }
46
- this.setSessionCookies(req, res);
47
- res.on("finish", () => __awaiter(this, void 0, void 0, function* () {
48
- var _a;
49
- if (!req.dfw.__meta.config.noSession) {
50
- yield req.dfw.db.dfw_session.update({
51
- data: {
52
- ip: req.ip,
53
- agent: (_a = req.headers['user-agent']) !== null && _a !== void 0 ? _a : "",
54
- expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
55
- },
56
- where: {
57
- id: Number(req.dfw.session.record.id)
58
- }
59
- });
60
- }
61
- }));
62
- });
63
- this.sessionExpirationDays = DFW.config.session && DFW.config.session.daysToExpire ? DFW.config.session.daysToExpire : DEFAULT_SESSION_EXPIRE_DAYS;
64
- }
65
- /**
66
- *
67
- * @param req
68
- * @param res
69
- */
70
- regenerateSessionAsync(req) {
71
- var _a;
72
- return __awaiter(this, void 0, void 0, function* () {
73
- let token = DFWUtils_1.default.uuid();
74
- let session = yield this.db.dfw_session.create({
75
- data: {
76
- token,
77
- agent: (_a = req.headers['user-agent']) !== null && _a !== void 0 ? _a : "",
78
- ip: req.ip,
79
- expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
80
- }
81
- });
82
- return { isLogged: false, record: session, user: undefined };
83
- });
84
- }
85
- /**
86
- *
87
- * @param user
88
- * @param password
89
- * @param persist undefined => onli browser session time | number => number in days that sessiopn keeps opened
90
- */
91
- loginAsync(req, user, password) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- if (!user || !password)
94
- return false;
95
- // Retrive user with credentials
96
- let userObj = yield req.dfw.UserManager.getUserAsync(user);
97
- if (userObj) {
98
- if (SecurityManager_1.default.verifyPassword(userObj.encodedKey, password)) {
99
- let sessionUpdated = yield this.db.dfw_session.update({
100
- include: {
101
- user: true
102
- },
103
- where: { id: Number(req.dfw.session.record.id) },
104
- data: {
105
- idUser: Number(userObj.id),
106
- expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
107
- }
108
- });
109
- req.dfw.session = { isLogged: true, record: sessionUpdated, user: userObj };
110
- return true;
111
- }
112
- }
113
- yield DFWUtils_1.default.sleepAsync(2500); // if login attempt fail ocurs a time gap for security to reduce guess oportunities
114
- return false;
115
- });
116
- }
117
- /**
118
- *
119
- * @param req
120
- * @param res
121
- */
122
- logoutAsync(req) {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- let sessionUpdated = yield req.dfw.db.dfw_session.update({
125
- include: {
126
- user: {
127
- select: {
128
- id: true,
129
- email: true,
130
- nick: true
131
- }
132
- }
133
- },
134
- where: { id: Number(req.dfw.session.record.id) },
135
- data: {
136
- idUser: null,
137
- }
138
- });
139
- req.dfw.session = { isLogged: false, record: sessionUpdated };
140
- });
141
- }
142
- /**
143
- * set (or reset) cookies if needed
144
- * @param req
145
- * @param res
146
- */
147
- setSessionCookies(req, res) {
148
- var _a;
149
- let cookieOptions = this.instance.config.session ? (_a = this.instance.config.session.cookieOptions) !== null && _a !== void 0 ? _a : {} : {};
150
- let diffCookies = req.cookies.sid != req.dfw.session.record.id || req.cookies.stk != req.dfw.session.record.token;
151
- if (!diffCookies)
152
- return; // no diference in cookies prevent reset cookies
153
- res.cookie(this.sidFieldName, req.dfw.session.record.id, cookieOptions);
154
- res.cookie(this.stkFieldName, req.dfw.session.record.token, cookieOptions);
155
- req.cookies.sid = req.dfw.session.record.id;
156
- req.cookies.stk = req.dfw.session.record.token;
157
- }
158
- /**
159
- * Destroy all sessions that expires 1 day ago
160
- */
161
- sweepExpiredSessionsAsync() {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- yield this.db.dfw_session.deleteMany({
164
- where: {
165
- expire: {
166
- lt: luxon_1.DateTime.now().minus({ days: 1 }).toJSDate()
167
- }
168
- }
169
- });
170
- });
171
- }
172
- }
173
- exports.default = SessionManager;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const DFWModule_1 = __importDefault(require("./DFWModule"));
16
+ const luxon_1 = require("luxon");
17
+ const DFWUtils_1 = __importDefault(require("../DFWUtils"));
18
+ const SecurityManager_1 = __importDefault(require("./SecurityManager"));
19
+ const DEFAULT_SESSION_EXPIRE_DAYS = 7;
20
+ class SessionManager extends DFWModule_1.default {
21
+ constructor(DFW) {
22
+ super(DFW);
23
+ this.stkFieldName = "stk";
24
+ this.sidFieldName = "sid";
25
+ this.middleware = (req, res) => __awaiter(this, void 0, void 0, function* () {
26
+ req.dfw.session = {
27
+ isLogged: false,
28
+ user: undefined,
29
+ record: undefined,
30
+ };
31
+ req.dfw.SessionManager = this;
32
+ if (req.dfw.__meta.config.noSession)
33
+ return;
34
+ if (!req.cookies || !req.cookies.sid || !req.cookies.stk) {
35
+ req.dfw.session = yield this.regenerateSessionAsync(req);
36
+ }
37
+ else {
38
+ let session = yield this.db.dfw_session.findFirst({
39
+ where: { id: Number(req.cookies.sid), token: req.cookies.stk },
40
+ include: {
41
+ user: {
42
+ include: {
43
+ credentials: {
44
+ select: {
45
+ id: true,
46
+ name: true,
47
+ access: {
48
+ select: {
49
+ id: true,
50
+ name: true
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ },
58
+ });
59
+ req.dfw.session = session ? { record: session, user: session.user, isLogged: session.user ? true : false } : yield this.regenerateSessionAsync(req);
60
+ }
61
+ this.setSessionCookies(req, res);
62
+ res.on("finish", () => __awaiter(this, void 0, void 0, function* () {
63
+ var _a;
64
+ if (!req.dfw.__meta.config.noSession) {
65
+ yield req.dfw.db.dfw_session.update({
66
+ data: {
67
+ ip: req.ip,
68
+ agent: (_a = req.headers['user-agent']) !== null && _a !== void 0 ? _a : "",
69
+ expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
70
+ },
71
+ where: {
72
+ id: Number(req.dfw.session.record.id)
73
+ }
74
+ });
75
+ }
76
+ }));
77
+ });
78
+ this.sessionExpirationDays = DFW.config.session && DFW.config.session.daysToExpire ? DFW.config.session.daysToExpire : DEFAULT_SESSION_EXPIRE_DAYS;
79
+ }
80
+ /**
81
+ *
82
+ * @param req
83
+ * @param res
84
+ */
85
+ regenerateSessionAsync(req) {
86
+ var _a;
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ let token = DFWUtils_1.default.uuid();
89
+ let session = yield this.db.dfw_session.create({
90
+ data: {
91
+ token,
92
+ agent: (_a = req.headers['user-agent']) !== null && _a !== void 0 ? _a : "",
93
+ ip: req.ip,
94
+ expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
95
+ }
96
+ });
97
+ return { isLogged: false, record: session, user: undefined };
98
+ });
99
+ }
100
+ /**
101
+ *
102
+ * @param user
103
+ * @param password
104
+ * @param persist undefined => onli browser session time | number => number in days that sessiopn keeps opened
105
+ */
106
+ loginAsync(req, user, password) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ if (!user || !password)
109
+ return false;
110
+ // Retrive user with credentials
111
+ let userObj = yield req.dfw.UserManager.getUserAsync(user);
112
+ if (userObj) {
113
+ if (SecurityManager_1.default.verifyPassword(userObj.encodedKey, password)) {
114
+ let sessionUpdated = yield this.db.dfw_session.update({
115
+ include: {
116
+ user: {
117
+ include: {
118
+ credentials: {
119
+ select: {
120
+ id: true,
121
+ name: true,
122
+ access: {
123
+ select: {
124
+ id: true,
125
+ name: true
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ },
133
+ where: { id: Number(req.dfw.session.record.id) },
134
+ data: {
135
+ idUser: Number(userObj.id),
136
+ expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
137
+ }
138
+ });
139
+ req.dfw.session = { isLogged: true, record: sessionUpdated, user: userObj };
140
+ return true;
141
+ }
142
+ }
143
+ yield DFWUtils_1.default.sleepAsync(2500); // if login attempt fail ocurs a time gap for security to reduce guess oportunities
144
+ return false;
145
+ });
146
+ }
147
+ /**
148
+ *
149
+ * @param req
150
+ * @param res
151
+ */
152
+ logoutAsync(req) {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ let sessionUpdated = yield req.dfw.db.dfw_session.update({
155
+ where: { id: Number(req.dfw.session.record.id) },
156
+ data: {
157
+ idUser: null,
158
+ }
159
+ });
160
+ req.dfw.session = { isLogged: false, record: sessionUpdated };
161
+ });
162
+ }
163
+ /**
164
+ * set (or reset) cookies if needed
165
+ * @param req
166
+ * @param res
167
+ */
168
+ setSessionCookies(req, res) {
169
+ var _a;
170
+ let cookieOptions = this.instance.config.session ? (_a = this.instance.config.session.cookieOptions) !== null && _a !== void 0 ? _a : {} : {};
171
+ let diffCookies = req.cookies.sid != req.dfw.session.record.id || req.cookies.stk != req.dfw.session.record.token;
172
+ if (!diffCookies)
173
+ return; // no diference in cookies prevent reset cookies
174
+ res.cookie(this.sidFieldName, req.dfw.session.record.id, cookieOptions);
175
+ res.cookie(this.stkFieldName, req.dfw.session.record.token, cookieOptions);
176
+ req.cookies.sid = req.dfw.session.record.id;
177
+ req.cookies.stk = req.dfw.session.record.token;
178
+ }
179
+ /**
180
+ * Destroy all sessions that expires 1 day ago
181
+ */
182
+ sweepExpiredSessionsAsync() {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ yield this.db.dfw_session.deleteMany({
185
+ where: {
186
+ expire: {
187
+ lt: luxon_1.DateTime.now().minus({ days: 1 }).toJSDate()
188
+ }
189
+ }
190
+ });
191
+ });
192
+ }
193
+ }
194
+ exports.default = SessionManager;
174
195
  //# sourceMappingURL=SessionManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../src/manager/SessionManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,4DAAoC;AACpC,iCAAiC;AACjC,2DAAmC;AACnC,wEAAgD;AAGhD,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAEtC,MAAqB,cAAe,SAAQ,mBAAS;IAMjD,YAAY,GAAgB;QACxB,KAAK,CAAC,GAAG,CAAC,CAAC;QAJC,iBAAY,GAAW,KAAK,CAAC;QAC7B,iBAAY,GAAW,KAAK,CAAC;QAOtC,eAAU,GAAG,CAAO,GAAe,EAAE,GAAa,EAAE,EAAE;YACzD,GAAG,CAAC,GAAG,CAAC,OAAO,GAAG;gBACd,QAAQ,EAAE,KAAK;gBACf,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,SAAgB;aAC3B,CAAA;YAED,GAAG,CAAC,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC;YAE9B,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS;gBAAE,OAAO;YAE5C,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE;gBACtD,GAAG,CAAC,GAAG,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;aAC5D;iBAAM;gBACH,IAAI,OAAO,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;oBAC9C,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,C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AAE,gBAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;qBACnD;iBACJ;aACJ,CAAC,CAAC;QACP,CAAC;KAAA;CACJ;AAtLD,iCAsLC"}
@@ -1,43 +1,43 @@
1
- import { Response } from "express";
2
- import DFWModule from "./DFWModule";
3
- import { DFWRequest } from "../types/DFWRequestScheme";
4
- import DFWInstance from "../DFWInstance";
5
- import { dfw_credential, dfw_user } from "@prisma/client";
6
- export default class UserManager extends DFWModule {
7
- constructor(DFW: DFWInstance);
8
- middleware: ({ dfw }: DFWRequest, res: Response) => Promise<void>;
9
- createUserAsync(email: string, nick: string, password?: string): Promise<import("@prisma/client/runtime/library").GetResult<{
10
- id: number;
11
- nick: string;
12
- email: string;
13
- status: number | null;
14
- encodedKey: string | null;
15
- createdAt: Date;
16
- updatedAt: Date;
17
- }, unknown, never> & {}>;
18
- getUserAsync(reference: string): Promise<(import("@prisma/client/runtime/library").GetResult<{
19
- id: number;
20
- nick: string;
21
- email: string;
22
- status: number | null;
23
- encodedKey: string | null;
24
- createdAt: Date;
25
- updatedAt: Date;
26
- }, unknown, never> & {}) | null>;
27
- createCredentiaASync(name: string, description?: string): Promise<import("@prisma/client/runtime/library").GetResult<{
28
- id: number;
29
- name: string;
30
- description: string | null;
31
- createdAt: Date;
32
- updatedAt: Date;
33
- }, unknown, never> & {}>;
34
- createAccessAsync(name: string, description?: string): Promise<import("@prisma/client/runtime/library").GetResult<{
35
- id: number;
36
- name: string;
37
- description: string | null;
38
- createdAt: Date;
39
- updatedAt: Date;
40
- }, unknown, never> & {}>;
41
- assignCredentialAsync(user: number | dfw_user, credential: dfw_credential | number | string | any[]): Promise<dfw_credential[]>;
42
- }
1
+ import { Response } from "express";
2
+ import DFWModule from "./DFWModule";
3
+ import { DFWRequest } from "../types/DFWRequestScheme";
4
+ import DFWInstance from "../DFWInstance";
5
+ import { dfw_credential, dfw_user } from "@prisma/client";
6
+ export default class UserManager extends DFWModule {
7
+ constructor(DFW: DFWInstance);
8
+ middleware: ({ dfw }: DFWRequest, res: Response) => Promise<void>;
9
+ createUserAsync(email: string, nick: string, password?: string): Promise<import("@prisma/client/runtime/library").GetResult<{
10
+ id: number;
11
+ nick: string;
12
+ email: string;
13
+ status: number | null;
14
+ encodedKey: string | null;
15
+ createdAt: Date;
16
+ updatedAt: Date;
17
+ }, unknown> & {}>;
18
+ getUserAsync(reference: string): Promise<(import("@prisma/client/runtime/library").GetResult<{
19
+ id: number;
20
+ nick: string;
21
+ email: string;
22
+ status: number | null;
23
+ encodedKey: string | null;
24
+ createdAt: Date;
25
+ updatedAt: Date;
26
+ }, unknown> & {}) | null>;
27
+ createCredentiaASync(name: string, description?: string): Promise<import("@prisma/client/runtime/library").GetResult<{
28
+ id: number;
29
+ name: string;
30
+ description: string | null;
31
+ createdAt: Date;
32
+ updatedAt: Date;
33
+ }, unknown> & {}>;
34
+ createAccessAsync(name: string, description?: string): Promise<import("@prisma/client/runtime/library").GetResult<{
35
+ id: number;
36
+ name: string;
37
+ description: string | null;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ }, unknown> & {}>;
41
+ assignCredentialAsync(user: number | dfw_user, credential: dfw_credential | number | string | any[]): Promise<dfw_credential[]>;
42
+ }
43
43
  //# sourceMappingURL=UserManager.d.ts.map
@@ -1,63 +1,63 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const SecurityManager_1 = __importDefault(require("./SecurityManager"));
16
- const DFWUtils_1 = __importDefault(require("../DFWUtils"));
17
- const DFWModule_1 = __importDefault(require("./DFWModule"));
18
- class UserManager extends DFWModule_1.default {
19
- constructor(DFW) {
20
- super(DFW);
21
- this.middleware = ({ dfw }, res) => __awaiter(this, void 0, void 0, function* () {
22
- dfw.UserManager = this;
23
- });
24
- }
25
- createUserAsync(email, nick, password) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- return this.db.dfw_user.create({
28
- data: {
29
- nick,
30
- email,
31
- encodedKey: password ? SecurityManager_1.default.encryptPassword(password) : undefined
32
- }
33
- });
34
- });
35
- }
36
- getUserAsync(reference) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- if (DFWUtils_1.default.isEmail(reference)) {
39
- return yield this.db.dfw_user.findFirst({ where: { email: reference } });
40
- }
41
- else {
42
- return yield this.db.dfw_user.findFirst({ where: { nick: reference } });
43
- }
44
- });
45
- }
46
- createCredentiaASync(name, description) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- return this.db.dfw_credential.create({ data: { name, description } });
49
- });
50
- }
51
- createAccessAsync(name, description) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- return this.db.dfw_access.create({ data: { name, description } });
54
- });
55
- }
56
- assignCredentialAsync(user, credential) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- return this.instance.SecurityManager.use(this.db).addCredentialToAsync(user, credential);
59
- });
60
- }
61
- }
62
- exports.default = UserManager;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const SecurityManager_1 = __importDefault(require("./SecurityManager"));
16
+ const DFWUtils_1 = __importDefault(require("../DFWUtils"));
17
+ const DFWModule_1 = __importDefault(require("./DFWModule"));
18
+ class UserManager extends DFWModule_1.default {
19
+ constructor(DFW) {
20
+ super(DFW);
21
+ this.middleware = ({ dfw }, res) => __awaiter(this, void 0, void 0, function* () {
22
+ dfw.UserManager = this;
23
+ });
24
+ }
25
+ createUserAsync(email, nick, password) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return this.db.dfw_user.create({
28
+ data: {
29
+ nick,
30
+ email,
31
+ encodedKey: password ? SecurityManager_1.default.encryptPassword(password) : undefined
32
+ }
33
+ });
34
+ });
35
+ }
36
+ getUserAsync(reference) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (DFWUtils_1.default.isEmail(reference)) {
39
+ return yield this.db.dfw_user.findFirst({ where: { email: reference } });
40
+ }
41
+ else {
42
+ return yield this.db.dfw_user.findFirst({ where: { nick: reference } });
43
+ }
44
+ });
45
+ }
46
+ createCredentiaASync(name, description) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return this.db.dfw_credential.create({ data: { name, description } });
49
+ });
50
+ }
51
+ createAccessAsync(name, description) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ return this.db.dfw_access.create({ data: { name, description } });
54
+ });
55
+ }
56
+ assignCredentialAsync(user, credential) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ return this.instance.SecurityManager.use(this.db).addCredentialToAsync(user, credential);
59
+ });
60
+ }
61
+ }
62
+ exports.default = UserManager;
63
63
  //# sourceMappingURL=UserManager.js.map
package/lib/test.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=test.d.ts.map