@shoppingapp.org/common 1.0.24 → 1.0.25
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/build/constants/auth/user.interfaces.d.ts +1 -1
- package/build/constants/globals.d.ts +4 -0
- package/build/constants/globals.js +3 -0
- package/build/index.d.ts +9 -8
- package/build/index.js +10 -9
- package/build/services/authentication.service.d.ts +7 -0
- package/build/services/authentication.service.js +50 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export * from './middlewares/current-user';
|
|
2
|
-
export * from './middlewares/error-handler
|
|
3
|
-
export * from './errors/bad-request-error
|
|
4
|
-
export * from './errors/custom-error
|
|
5
|
-
export * from './errors/database-connection-error
|
|
6
|
-
export * from './errors/not-authorized-error
|
|
7
|
-
export * from './errors/not-found-error
|
|
8
|
-
export * from './errors/request-validation-error
|
|
9
|
-
export * from './constants/auth/user.interfaces
|
|
2
|
+
export * from './middlewares/error-handler';
|
|
3
|
+
export * from './errors/bad-request-error';
|
|
4
|
+
export * from './errors/custom-error';
|
|
5
|
+
export * from './errors/database-connection-error';
|
|
6
|
+
export * from './errors/not-authorized-error';
|
|
7
|
+
export * from './errors/not-found-error';
|
|
8
|
+
export * from './errors/request-validation-error';
|
|
9
|
+
export * from './constants/auth/user.interfaces';
|
|
10
|
+
export * from './services/authentication.service';
|
package/build/index.js
CHANGED
|
@@ -15,12 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./middlewares/current-user"), exports);
|
|
18
|
-
// export * from './middlewares/require-auth
|
|
19
|
-
__exportStar(require("./middlewares/error-handler
|
|
20
|
-
__exportStar(require("./errors/bad-request-error
|
|
21
|
-
__exportStar(require("./errors/custom-error
|
|
22
|
-
__exportStar(require("./errors/database-connection-error
|
|
23
|
-
__exportStar(require("./errors/not-authorized-error
|
|
24
|
-
__exportStar(require("./errors/not-found-error
|
|
25
|
-
__exportStar(require("./errors/request-validation-error
|
|
26
|
-
__exportStar(require("./constants/auth/user.interfaces
|
|
18
|
+
// export * from './middlewares/require-auth';
|
|
19
|
+
__exportStar(require("./middlewares/error-handler"), exports); // 🔹 Fixed
|
|
20
|
+
__exportStar(require("./errors/bad-request-error"), exports); // 🔹 Fixed
|
|
21
|
+
__exportStar(require("./errors/custom-error"), exports); // 🔹 Fixed
|
|
22
|
+
__exportStar(require("./errors/database-connection-error"), exports); // 🔹 Fixed
|
|
23
|
+
__exportStar(require("./errors/not-authorized-error"), exports); // 🔹 Fixed
|
|
24
|
+
__exportStar(require("./errors/not-found-error"), exports); // 🔹 Fixed
|
|
25
|
+
__exportStar(require("./errors/request-validation-error"), exports);
|
|
26
|
+
__exportStar(require("./constants/auth/user.interfaces"), exports);
|
|
27
|
+
__exportStar(require("./services/authentication.service"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JwtPayload } from '../constants/globals';
|
|
2
|
+
export declare class AuthenticationService {
|
|
3
|
+
generateJwt(payload: JwtPayload, JWT_KEY: string): string;
|
|
4
|
+
pwdToHash(password: string): Promise<string>;
|
|
5
|
+
pwdCompare(storesPassword: string, suppliedPassword: string): Promise<boolean>;
|
|
6
|
+
verifyJt(jwtToken: string, JWT_KEY: string): JwtPayload;
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
exports.AuthenticationService = void 0;
|
|
16
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
|
+
const crypto_1 = require("crypto");
|
|
18
|
+
const util_1 = require("util");
|
|
19
|
+
const scryptAsync = (0, util_1.promisify)(crypto_1.scrypt);
|
|
20
|
+
class AuthenticationService {
|
|
21
|
+
generateJwt(payload, JWT_KEY) {
|
|
22
|
+
return jsonwebtoken_1.default.sign(payload, JWT_KEY);
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
pwdToHash(password) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const salt = (0, crypto_1.randomBytes)(8).toString('hex');
|
|
28
|
+
const buf = (yield scryptAsync(password, salt, 64));
|
|
29
|
+
return `${buf.toString('hex')}.${salt}`;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
;
|
|
33
|
+
pwdCompare(storesPassword, suppliedPassword) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const [hashedPassword, salt] = storesPassword.split('.');
|
|
36
|
+
if (!salt) {
|
|
37
|
+
throw new Error("Salt could not be extracted from the stored password.");
|
|
38
|
+
}
|
|
39
|
+
const buf = (yield scryptAsync(suppliedPassword, salt, 64));
|
|
40
|
+
return buf.toString('hex') == hashedPassword;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
;
|
|
44
|
+
verifyJt(jwtToken, JWT_KEY) {
|
|
45
|
+
return jsonwebtoken_1.default.verify(jwtToken, JWT_KEY);
|
|
46
|
+
}
|
|
47
|
+
;
|
|
48
|
+
}
|
|
49
|
+
exports.AuthenticationService = AuthenticationService;
|
|
50
|
+
;
|