@scefira/dfw 0.1.15 → 0.2.1

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 +195 -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 +4 -3
  42. package/prisma/schema.prisma +5 -27
@@ -1,174 +1,196 @@
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, expire: { gte: new Date() } },
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, _b;
64
+ if (!req.dfw.__meta.config.noSession) {
65
+ if (req.dfw.session.record.ip !== req.ip || req.dfw.session.record.agent !== ((_a = req.headers['user-agent']) !== null && _a !== void 0 ? _a : "")) {
66
+ yield req.dfw.db.dfw_session.update({
67
+ data: {
68
+ ip: req.ip,
69
+ agent: (_b = req.headers['user-agent']) !== null && _b !== void 0 ? _b : "",
70
+ },
71
+ where: {
72
+ id: Number(req.dfw.session.record.id)
73
+ }
74
+ });
75
+ }
76
+ }
77
+ }));
78
+ });
79
+ this.sessionExpirationDays = DFW.config.session && DFW.config.session.daysToExpire ? DFW.config.session.daysToExpire : DEFAULT_SESSION_EXPIRE_DAYS;
80
+ }
81
+ /**
82
+ *
83
+ * @param req
84
+ * @param res
85
+ */
86
+ regenerateSessionAsync(req) {
87
+ var _a;
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ let token = DFWUtils_1.default.uuid();
90
+ let session = yield this.db.dfw_session.create({
91
+ data: {
92
+ token,
93
+ agent: (_a = req.headers['user-agent']) !== null && _a !== void 0 ? _a : "",
94
+ ip: req.ip,
95
+ expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
96
+ }
97
+ });
98
+ return { isLogged: false, record: session, user: undefined };
99
+ });
100
+ }
101
+ /**
102
+ *
103
+ * @param user
104
+ * @param password
105
+ * @param persist undefined => onli browser session time | number => number in days that sessiopn keeps opened
106
+ */
107
+ loginAsync(req, user, password) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ if (!user || !password)
110
+ return false;
111
+ // Retrive user with credentials
112
+ let userObj = yield req.dfw.UserManager.getUserAsync(user);
113
+ if (userObj) {
114
+ if (SecurityManager_1.default.verifyPassword(userObj.encodedKey, password)) {
115
+ let sessionUpdated = yield this.db.dfw_session.update({
116
+ include: {
117
+ user: {
118
+ include: {
119
+ credentials: {
120
+ select: {
121
+ id: true,
122
+ name: true,
123
+ access: {
124
+ select: {
125
+ id: true,
126
+ name: true
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ },
134
+ where: { id: Number(req.dfw.session.record.id) },
135
+ data: {
136
+ idUser: Number(userObj.id),
137
+ expire: luxon_1.DateTime.now().plus({ days: this.sessionExpirationDays }).toJSDate()
138
+ }
139
+ });
140
+ req.dfw.session = { isLogged: true, record: sessionUpdated, user: userObj };
141
+ return true;
142
+ }
143
+ }
144
+ yield DFWUtils_1.default.sleepAsync(2500); // if login attempt fail ocurs a time gap for security to reduce guess oportunities
145
+ return false;
146
+ });
147
+ }
148
+ /**
149
+ *
150
+ * @param req
151
+ * @param res
152
+ */
153
+ logoutAsync(req) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ let sessionUpdated = yield req.dfw.db.dfw_session.update({
156
+ where: { id: Number(req.dfw.session.record.id) },
157
+ data: {
158
+ idUser: null,
159
+ }
160
+ });
161
+ req.dfw.session = { isLogged: false, record: sessionUpdated };
162
+ });
163
+ }
164
+ /**
165
+ * set (or reset) cookies if needed
166
+ * @param req
167
+ * @param res
168
+ */
169
+ setSessionCookies(req, res) {
170
+ var _a;
171
+ let cookieOptions = this.instance.config.session ? (_a = this.instance.config.session.cookieOptions) !== null && _a !== void 0 ? _a : {} : {};
172
+ let diffCookies = req.cookies.sid != req.dfw.session.record.id || req.cookies.stk != req.dfw.session.record.token;
173
+ if (!diffCookies)
174
+ return; // no diference in cookies prevent reset cookies
175
+ res.cookie(this.sidFieldName, req.dfw.session.record.id, cookieOptions);
176
+ res.cookie(this.stkFieldName, req.dfw.session.record.token, cookieOptions);
177
+ req.cookies.sid = req.dfw.session.record.id;
178
+ req.cookies.stk = req.dfw.session.record.token;
179
+ }
180
+ /**
181
+ * Destroy all sessions that expires 1 day ago
182
+ */
183
+ sweepExpiredSessionsAsync() {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ yield this.db.dfw_session.deleteMany({
186
+ where: {
187
+ expire: {
188
+ lt: luxon_1.DateTime.now().minus({ days: 1 }).toJSDate()
189
+ }
190
+ }
191
+ });
192
+ });
193
+ }
194
+ }
195
+ exports.default = SessionManager;
174
196
  //# 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,CAA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CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IACnD,CAAC;IAED;;OAEG;IACU,yBAAyB;;YAClC,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC;gBACjC,KAAK,EAAE;oBACH,MAAM,EAAE;wBACJ,EAAE,EAAE,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;AAvLD,iCAuLC"}
@@ -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