@zola_do/authorization 0.1.9
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/authorization.module.d.ts +2 -0
- package/dist/authorization.module.js +46 -0
- package/dist/authorization.module.js.map +1 -0
- package/dist/decorators/allow-anonymous.decorator.d.ts +2 -0
- package/dist/decorators/allow-anonymous.decorator.js +8 -0
- package/dist/decorators/allow-anonymous.decorator.js.map +1 -0
- package/dist/decorators/current-user.decorator.d.ts +1 -0
- package/dist/decorators/current-user.decorator.js +9 -0
- package/dist/decorators/current-user.decorator.js.map +1 -0
- package/dist/guards/api-key.guard.d.ts +4 -0
- package/dist/guards/api-key.guard.js +38 -0
- package/dist/guards/api-key.guard.js.map +1 -0
- package/dist/guards/jwt-refresh.guard.d.ts +4 -0
- package/dist/guards/jwt-refresh.guard.js +18 -0
- package/dist/guards/jwt-refresh.guard.js.map +1 -0
- package/dist/guards/jwt.guard.d.ts +8 -0
- package/dist/guards/jwt.guard.js +59 -0
- package/dist/guards/jwt.guard.js.map +1 -0
- package/dist/guards/optional-jwt.guard.d.ts +8 -0
- package/dist/guards/optional-jwt.guard.js +54 -0
- package/dist/guards/optional-jwt.guard.js.map +1 -0
- package/dist/guards/permissions.guard.d.ts +2 -0
- package/dist/guards/permissions.guard.js +23 -0
- package/dist/guards/permissions.guard.js.map +1 -0
- package/dist/guards/throttler-behind-proxy.guard.d.ts +4 -0
- package/dist/guards/throttler-behind-proxy.guard.js +22 -0
- package/dist/guards/throttler-behind-proxy.guard.js.map +1 -0
- package/dist/guards/vendor.guard.d.ts +2 -0
- package/dist/guards/vendor.guard.js +19 -0
- package/dist/guards/vendor.guard.js.map +1 -0
- package/dist/helper/auth.helper.d.ts +17 -0
- package/dist/helper/auth.helper.js +289 -0
- package/dist/helper/auth.helper.js.map +1 -0
- package/dist/helper/jwt.type.d.ts +4 -0
- package/dist/helper/jwt.type.js +3 -0
- package/dist/helper/jwt.type.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/models/auth.model.d.ts +36 -0
- package/dist/models/auth.model.js +16 -0
- package/dist/models/auth.model.js.map +1 -0
- package/dist/strategy/jwt-refresh-token.strategy.d.ts +9 -0
- package/dist/strategy/jwt-refresh-token.strategy.js +22 -0
- package/dist/strategy/jwt-refresh-token.strategy.js.map +1 -0
- package/dist/strategy/jwt.strategy.d.ts +9 -0
- package/dist/strategy/jwt.strategy.js +22 -0
- package/dist/strategy/jwt.strategy.js.map +1 -0
- package/dist/utils/extract-user.d.ts +1 -0
- package/dist/utils/extract-user.js +31 -0
- package/dist/utils/extract-user.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AuthorizationModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
12
|
+
const passport_1 = require("@nestjs/passport");
|
|
13
|
+
const auth_helper_1 = require("./helper/auth.helper");
|
|
14
|
+
const jwt_strategy_1 = require("./strategy/jwt.strategy");
|
|
15
|
+
const jwt_refresh_token_strategy_1 = require("./strategy/jwt-refresh-token.strategy");
|
|
16
|
+
const jwt_refresh_guard_1 = require("./guards/jwt-refresh.guard");
|
|
17
|
+
const jwt_guard_1 = require("./guards/jwt.guard");
|
|
18
|
+
const core_1 = require("@nestjs/core");
|
|
19
|
+
const api_key_guard_1 = require("./guards/api-key.guard");
|
|
20
|
+
const optional_jwt_guard_1 = require("./guards/optional-jwt.guard");
|
|
21
|
+
let AuthorizationModule = class AuthorizationModule {
|
|
22
|
+
};
|
|
23
|
+
exports.AuthorizationModule = AuthorizationModule;
|
|
24
|
+
exports.AuthorizationModule = AuthorizationModule = __decorate([
|
|
25
|
+
(0, common_1.Module)({
|
|
26
|
+
imports: [
|
|
27
|
+
passport_1.PassportModule.register({ defaultStrategy: 'jwt', property: 'user' }),
|
|
28
|
+
jwt_1.JwtModule.register({}),
|
|
29
|
+
],
|
|
30
|
+
controllers: [],
|
|
31
|
+
providers: [
|
|
32
|
+
auth_helper_1.AuthHelper,
|
|
33
|
+
jwt_strategy_1.JwtStrategy,
|
|
34
|
+
jwt_1.JwtService,
|
|
35
|
+
jwt_refresh_token_strategy_1.JwtRefreshTokenStrategy,
|
|
36
|
+
core_1.Reflector,
|
|
37
|
+
jwt_guard_1.JwtGuard,
|
|
38
|
+
{ provide: core_1.APP_GUARD, useClass: jwt_guard_1.JwtGuard },
|
|
39
|
+
jwt_refresh_guard_1.JwtRefreshGuard,
|
|
40
|
+
api_key_guard_1.ApiKeyGuard,
|
|
41
|
+
optional_jwt_guard_1.OptionalJwtGuard,
|
|
42
|
+
],
|
|
43
|
+
exports: [core_1.Reflector, auth_helper_1.AuthHelper, jwt_1.JwtService],
|
|
44
|
+
})
|
|
45
|
+
], AuthorizationModule);
|
|
46
|
+
//# sourceMappingURL=authorization.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.module.js","sourceRoot":"","sources":["../src/authorization.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qCAAoD;AACpD,+CAAkD;AAClD,sDAAkD;AAClD,0DAAsD;AACtD,sFAAgF;AAChF,kEAA6D;AAC7D,kDAA8C;AAC9C,uCAAoD;AACpD,0DAAqD;AACrD,oEAA+D;AAsBxD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAAG,CAAA;AAAtB,kDAAmB;8BAAnB,mBAAmB;IApB/B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,yBAAc,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YACrE,eAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;SACvB;QACD,WAAW,EAAE,EAAE;QACf,SAAS,EAAE;YACT,wBAAU;YACV,0BAAW;YACX,gBAAU;YACV,oDAAuB;YACvB,gBAAS;YACT,oBAAQ;YACR,EAAE,OAAO,EAAE,gBAAS,EAAE,QAAQ,EAAE,oBAAQ,EAAE;YAC1C,mCAAe;YACf,2BAAW;YACX,qCAAgB;SACjB;QACD,OAAO,EAAE,CAAC,gBAAS,EAAE,wBAAU,EAAE,gBAAU,CAAC;KAC7C,CAAC;GACW,mBAAmB,CAAG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AllowAnonymous = exports.ALLOW_ANONYMOUS_META_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.ALLOW_ANONYMOUS_META_KEY = 'allowAnonymous';
|
|
6
|
+
const AllowAnonymous = () => (0, common_1.SetMetadata)(exports.ALLOW_ANONYMOUS_META_KEY, true);
|
|
7
|
+
exports.AllowAnonymous = AllowAnonymous;
|
|
8
|
+
//# sourceMappingURL=allow-anonymous.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allow-anonymous.decorator.js","sourceRoot":"","sources":["../../src/decorators/allow-anonymous.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,wBAAwB,GAAG,gBAAgB,CAAC;AAElD,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,gCAAwB,EAAE,IAAI,CAAC,CAAC;AAAnE,QAAA,cAAc,kBAAqD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CurrentUser: (...dataOrPipes: any[]) => ParameterDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentUser = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.CurrentUser = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
return request.user;
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=current-user.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-user.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-user.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAE3D,QAAA,WAAW,GAAG,IAAA,6BAAoB,EAC7C,CAAC,IAAa,EAAE,GAAqB,EAAE,EAAE;IACvC,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAEhD,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ApiKeyGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let ApiKeyGuard = class ApiKeyGuard {
|
|
12
|
+
async canActivate(context) {
|
|
13
|
+
try {
|
|
14
|
+
const request = context.switchToHttp().getRequest();
|
|
15
|
+
const headers = request.headers;
|
|
16
|
+
const apiKey = headers['x-api-key'];
|
|
17
|
+
if (!apiKey) {
|
|
18
|
+
throw new common_1.UnauthorizedException('api_key_not_provided');
|
|
19
|
+
}
|
|
20
|
+
const API_KEY = process.env.API_KEY;
|
|
21
|
+
if (!API_KEY) {
|
|
22
|
+
throw new common_1.UnauthorizedException('api_key_not_configured');
|
|
23
|
+
}
|
|
24
|
+
if (apiKey !== API_KEY) {
|
|
25
|
+
throw new common_1.UnauthorizedException('invalid_api_key');
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.ApiKeyGuard = ApiKeyGuard;
|
|
35
|
+
exports.ApiKeyGuard = ApiKeyGuard = __decorate([
|
|
36
|
+
(0, common_1.Injectable)()
|
|
37
|
+
], ApiKeyGuard);
|
|
38
|
+
//# sourceMappingURL=api-key.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.guard.js","sourceRoot":"","sources":["../../src/guards/api-key.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AAGjB,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YAChC,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;YACpC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,8BAAqB,CAAC,sBAAsB,CAAC,CAAC;YAC1D,CAAC;YAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;YACpC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,8BAAqB,CAAC,wBAAwB,CAAC,CAAC;YAC5D,CAAC;YAGD,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;gBACvB,MAAM,IAAI,8BAAqB,CAAC,iBAAiB,CAAC,CAAC;YACrD,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AAzBY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;GACA,WAAW,CAyBvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.JwtRefreshGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
let JwtRefreshGuard = class JwtRefreshGuard extends (0, passport_1.AuthGuard)('jwt-refresh') {
|
|
13
|
+
};
|
|
14
|
+
exports.JwtRefreshGuard = JwtRefreshGuard;
|
|
15
|
+
exports.JwtRefreshGuard = JwtRefreshGuard = __decorate([
|
|
16
|
+
(0, common_1.Injectable)()
|
|
17
|
+
], JwtRefreshGuard);
|
|
18
|
+
//# sourceMappingURL=jwt-refresh.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-refresh.guard.js","sourceRoot":"","sources":["../../src/guards/jwt-refresh.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,IAAA,oBAAS,EAAC,aAAa,CAAC;CAAG,CAAA;AAAnD,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;GACA,eAAe,CAAoC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
export declare class JwtGuard implements CanActivate {
|
|
4
|
+
private readonly reflector;
|
|
5
|
+
constructor(reflector: Reflector);
|
|
6
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
7
|
+
private extractTokenFromHeader;
|
|
8
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JwtGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const allow_anonymous_decorator_1 = require("../decorators/allow-anonymous.decorator");
|
|
16
|
+
const jsonwebtoken = require("jsonwebtoken");
|
|
17
|
+
const extract_user_1 = require("../utils/extract-user");
|
|
18
|
+
let JwtGuard = class JwtGuard {
|
|
19
|
+
constructor(reflector) {
|
|
20
|
+
this.reflector = reflector;
|
|
21
|
+
}
|
|
22
|
+
async canActivate(context) {
|
|
23
|
+
var _a;
|
|
24
|
+
try {
|
|
25
|
+
const request = context.switchToHttp().getRequest();
|
|
26
|
+
const isAnonymousAllowed = (_a = this.reflector) === null || _a === void 0 ? void 0 : _a.getAllAndOverride(allow_anonymous_decorator_1.ALLOW_ANONYMOUS_META_KEY, [context.getHandler(), context.getClass()]);
|
|
27
|
+
if (isAnonymousAllowed) {
|
|
28
|
+
request.isAnonymous = true;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const token = this.extractTokenFromHeader(request);
|
|
32
|
+
if (!token) {
|
|
33
|
+
throw new common_1.UnauthorizedException('JsonWebTokenError', 'jwt must be provided');
|
|
34
|
+
}
|
|
35
|
+
const secret = process.env.JWT_ACCESS_TOKEN_SECRET;
|
|
36
|
+
if (!secret) {
|
|
37
|
+
throw new common_1.UnauthorizedException('ConfigurationError', 'JWT_ACCESS_TOKEN_SECRET is not configured');
|
|
38
|
+
}
|
|
39
|
+
const user = jsonwebtoken.verify(token, secret);
|
|
40
|
+
const parsedUser = (0, extract_user_1.extractUser)(request, user);
|
|
41
|
+
request.user = parsedUser;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
extractTokenFromHeader(request) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const [type, token] = (_b = (_a = request.headers.authorization) === null || _a === void 0 ? void 0 : _a.split(' ')) !== null && _b !== void 0 ? _b : [];
|
|
51
|
+
return type === 'Bearer' ? token : undefined;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.JwtGuard = JwtGuard;
|
|
55
|
+
exports.JwtGuard = JwtGuard = __decorate([
|
|
56
|
+
(0, common_1.Injectable)(),
|
|
57
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
58
|
+
], JwtGuard);
|
|
59
|
+
//# sourceMappingURL=jwt.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.guard.js","sourceRoot":"","sources":["../../src/guards/jwt.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AAExB,uCAAyC;AACzC,uFAAmF;AACnF,6CAA4C;AAC5C,wDAAoD;AAG7C,IAAM,QAAQ,GAAd,MAAM,QAAQ;IACnB,YACmB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IACnC,CAAC;IAEL,KAAK,CAAC,WAAW,CAAC,OAAyB;;QACzC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YACpD,MAAM,kBAAkB,GAAG,MAAA,IAAI,CAAC,SAAS,0CAAE,iBAAiB,CAC1D,oDAAwB,EACxB,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAC3C,CAAC;YACF,IAAI,kBAAkB,EAAE,CAAC;gBACvB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;gBAC3B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,KAAK,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;YACnD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,IAAI,8BAAqB,CAC7B,mBAAmB,EACnB,sBAAsB,CACvB,CAAC;YACJ,CAAC;YAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;YACnD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,8BAAqB,CAC7B,oBAAoB,EACpB,2CAA2C,CAC5C,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAEhD,MAAM,UAAU,GAAQ,IAAA,0BAAW,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAEnD,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,sBAAsB,CAAC,OAAgB;;QAC7C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,aAAa,0CAAE,KAAK,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;QACtE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;CACF,CAAA;AAhDY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,mBAAU,GAAE;qCAGmB,gBAAS;GAF5B,QAAQ,CAgDpB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { AuthHelper } from '../helper/auth.helper';
|
|
3
|
+
export declare class OptionalJwtGuard implements CanActivate {
|
|
4
|
+
private readonly authHelper;
|
|
5
|
+
constructor(authHelper: AuthHelper);
|
|
6
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
7
|
+
private extractTokenFromHeader;
|
|
8
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OptionalJwtGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const auth_helper_1 = require("../helper/auth.helper");
|
|
15
|
+
const extract_user_1 = require("../utils/extract-user");
|
|
16
|
+
let OptionalJwtGuard = class OptionalJwtGuard {
|
|
17
|
+
constructor(authHelper) {
|
|
18
|
+
this.authHelper = authHelper;
|
|
19
|
+
}
|
|
20
|
+
async canActivate(context) {
|
|
21
|
+
try {
|
|
22
|
+
const request = context.switchToHttp().getRequest();
|
|
23
|
+
const token = this.extractTokenFromHeader(request);
|
|
24
|
+
if (!token) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const secret = process.env.JWT_ACCESS_TOKEN_SECRET;
|
|
28
|
+
if (!secret) {
|
|
29
|
+
if (process.env.NODE_ENV === 'production') {
|
|
30
|
+
console.warn('JWT_ACCESS_TOKEN_SECRET is not configured');
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
const user = await this.authHelper.verify(token, secret);
|
|
35
|
+
const parsedUser = (0, extract_user_1.extractUser)(request, user);
|
|
36
|
+
request.user = parsedUser;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
extractTokenFromHeader(request) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const [type, token] = (_b = (_a = request.headers.authorization) === null || _a === void 0 ? void 0 : _a.split(' ')) !== null && _b !== void 0 ? _b : [];
|
|
46
|
+
return type === 'Bearer' ? token : undefined;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.OptionalJwtGuard = OptionalJwtGuard;
|
|
50
|
+
exports.OptionalJwtGuard = OptionalJwtGuard = __decorate([
|
|
51
|
+
(0, common_1.Injectable)(),
|
|
52
|
+
__metadata("design:paramtypes", [auth_helper_1.AuthHelper])
|
|
53
|
+
], OptionalJwtGuard);
|
|
54
|
+
//# sourceMappingURL=optional-jwt.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional-jwt.guard.js","sourceRoot":"","sources":["../../src/guards/optional-jwt.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA2E;AAE3E,uDAAmD;AACnD,wDAAoD;AAG7C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEvD,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YACpD,MAAM,KAAK,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;YACnD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;YACnD,IAAI,CAAC,MAAM,EAAE,CAAC;gBAGZ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;oBAC1C,OAAO,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;gBAC5D,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAEzD,MAAM,UAAU,GAAQ,IAAA,0BAAW,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAEnD,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,sBAAsB,CAAC,OAAgB;;QAC7C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,aAAa,0CAAE,KAAK,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;QACtE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;CACF,CAAA;AApCY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAE8B,wBAAU;GADxC,gBAAgB,CAoC5B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionsGuard = PermissionsGuard;
|
|
4
|
+
function PermissionsGuard(permissions) {
|
|
5
|
+
class PermissionsGuardMixin {
|
|
6
|
+
canActivate(context) {
|
|
7
|
+
const request = context.switchToHttp().getRequest();
|
|
8
|
+
if (!permissions || request.isAnonymous) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const requiredPermissions = permissions.split('|');
|
|
12
|
+
if (requiredPermissions.length < 1) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const user = request.user;
|
|
16
|
+
const userPermissions = user === null || user === void 0 ? void 0 : user.permissions;
|
|
17
|
+
const isAllowed = requiredPermissions.some((requiredPermission) => userPermissions === null || userPermissions === void 0 ? void 0 : userPermissions.find((x) => x == requiredPermission.trim()));
|
|
18
|
+
return isAllowed;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return PermissionsGuardMixin;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=permissions.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.guard.js","sourceRoot":"","sources":["../../src/guards/permissions.guard.ts"],"names":[],"mappings":";;AAEA,4CA0BC;AA1BD,SAAgB,gBAAgB,CAAC,WAAmB;IAClD,MAAM,qBAAqB;QACzB,WAAW,CAAC,OAAyB;YACnC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YAEpD,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;gBACxC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,mBAAmB,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnD,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,IAAI,GAAQ,OAAO,CAAC,IAAI,CAAC;YAC/B,MAAM,eAAe,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC;YAE1C,MAAM,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,kBAAkB,EAAE,EAAE,CAChE,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,kBAAkB,CAAC,IAAI,EAAE,CAAC,CACrE,CAAC;YAEF,OAAO,SAAS,CAAC;QACnB,CAAC;KACF;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ThrottlerBehindProxyGuard = void 0;
|
|
10
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
let ThrottlerBehindProxyGuard = class ThrottlerBehindProxyGuard extends throttler_1.ThrottlerGuard {
|
|
13
|
+
async getTracker(req) {
|
|
14
|
+
var _a;
|
|
15
|
+
return ((_a = req.ips) === null || _a === void 0 ? void 0 : _a.length) ? req.ips[0] : req.ip;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.ThrottlerBehindProxyGuard = ThrottlerBehindProxyGuard;
|
|
19
|
+
exports.ThrottlerBehindProxyGuard = ThrottlerBehindProxyGuard = __decorate([
|
|
20
|
+
(0, common_1.Injectable)()
|
|
21
|
+
], ThrottlerBehindProxyGuard);
|
|
22
|
+
//# sourceMappingURL=throttler-behind-proxy.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttler-behind-proxy.guard.js","sourceRoot":"","sources":["../../src/guards/throttler-behind-proxy.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iDAAmD;AACnD,2CAA4C;AAMrC,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,0BAAc;IACjD,KAAK,CAAC,UAAU,CAAC,GAAwB;;QACjD,OAAO,CAAA,MAAA,GAAG,CAAC,GAAG,0CAAE,MAAM,EAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IAC/C,CAAC;CACF,CAAA;AAJY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAIrC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VendorGuard = VendorGuard;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
function VendorGuard() {
|
|
6
|
+
class VendorGuardMixin {
|
|
7
|
+
canActivate(context) {
|
|
8
|
+
const request = context.switchToHttp().getRequest();
|
|
9
|
+
const user = request.user;
|
|
10
|
+
const organization = user === null || user === void 0 ? void 0 : user.organization;
|
|
11
|
+
if ((organization === null || organization === void 0 ? void 0 : organization.id) != null) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
throw new common_1.ForbiddenException('vendor_registration_not_completed');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return VendorGuardMixin;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=vendor.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vendor.guard.js","sourceRoot":"","sources":["../../src/guards/vendor.guard.ts"],"names":[],"mappings":";;AAOA,kCAgBC;AAvBD,2CAKwB;AAExB,SAAgB,WAAW;IACzB,MAAM,gBAAgB;QACpB,WAAW,CAAC,OAAyB;YACnC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YACpD,MAAM,IAAI,GAAQ,OAAO,CAAC,IAAI,CAAC;YAC/B,MAAM,YAAY,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,CAAC;YAExC,IAAI,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,EAAE,KAAI,IAAI,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,IAAI,2BAAkB,CAAC,mCAAmC,CAAC,CAAC;QACpE,CAAC;KACF;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { JwtService } from '@nestjs/jwt';
|
|
2
|
+
export declare class AuthHelper {
|
|
3
|
+
private readonly jwt;
|
|
4
|
+
constructor(jwt: JwtService);
|
|
5
|
+
verify(token: string, secret: string): Promise<any>;
|
|
6
|
+
decode(token: string): Promise<unknown>;
|
|
7
|
+
generateAccessToken(payload: any): string;
|
|
8
|
+
generateRefreshToken(payload: any): string;
|
|
9
|
+
generateToken(account: any): Promise<{
|
|
10
|
+
accessToken: string;
|
|
11
|
+
refreshToken: string;
|
|
12
|
+
}>;
|
|
13
|
+
compareHashedValue(originalValue: string, hashedValue: string): boolean;
|
|
14
|
+
encodePassword(password: string): string;
|
|
15
|
+
generateOpt(): string;
|
|
16
|
+
verifyEmailTemplateForOtp(fullName: string, username: string, otp: string, duration: number): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthHelper = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
15
|
+
const bcrypt = require("bcrypt");
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
17
|
+
let AuthHelper = class AuthHelper {
|
|
18
|
+
constructor(jwt) {
|
|
19
|
+
this.jwt = jwt;
|
|
20
|
+
}
|
|
21
|
+
async verify(token, secret) {
|
|
22
|
+
const decoded = this.jwt.verify(token, { secret });
|
|
23
|
+
if (!decoded) {
|
|
24
|
+
throw new common_1.UnauthorizedException('invalid_token');
|
|
25
|
+
}
|
|
26
|
+
return decoded;
|
|
27
|
+
}
|
|
28
|
+
async decode(token) {
|
|
29
|
+
return this.jwt.decode(token, null);
|
|
30
|
+
}
|
|
31
|
+
generateAccessToken(payload) {
|
|
32
|
+
return this.jwt.sign(Object.assign({}, payload), {
|
|
33
|
+
secret: process.env.JWT_ACCESS_TOKEN_SECRET,
|
|
34
|
+
expiresIn: process.env.JWT_ACCESS_TOKEN_EXPIRES,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
generateRefreshToken(payload) {
|
|
38
|
+
return this.jwt.sign(Object.assign({}, payload), {
|
|
39
|
+
secret: process.env.JWT_REFRESH_TOKEN_SECRET,
|
|
40
|
+
expiresIn: process.env.JWT_REFRESH_TOKEN_EXPIRES,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async generateToken(account) {
|
|
44
|
+
const [accessToken, refreshToken] = await Promise.all([
|
|
45
|
+
this.jwt.signAsync({ id: account.id, email: account.email }, {
|
|
46
|
+
secret: process.env.JWT_ACCESS_TOKEN_SECRET,
|
|
47
|
+
expiresIn: process.env.JWT_ACCESS_TOKEN_EXPIRES,
|
|
48
|
+
}),
|
|
49
|
+
this.jwt.signAsync({ id: account.id }, {
|
|
50
|
+
secret: process.env.JWT_REFRESH_TOKEN_SECRET,
|
|
51
|
+
expiresIn: process.env.JWT_REFRESH_TOKEN_EXPIRES,
|
|
52
|
+
}),
|
|
53
|
+
]);
|
|
54
|
+
return { accessToken, refreshToken };
|
|
55
|
+
}
|
|
56
|
+
compareHashedValue(originalValue, hashedValue) {
|
|
57
|
+
return bcrypt.compareSync(originalValue, hashedValue);
|
|
58
|
+
}
|
|
59
|
+
encodePassword(password) {
|
|
60
|
+
const salt = bcrypt.genSaltSync(12);
|
|
61
|
+
return bcrypt.hashSync(password, salt);
|
|
62
|
+
}
|
|
63
|
+
generateOpt() {
|
|
64
|
+
const randomNumber = (0, crypto_1.randomInt)(100000, 999999);
|
|
65
|
+
return randomNumber.toString();
|
|
66
|
+
}
|
|
67
|
+
verifyEmailTemplateForOtp(fullName, username, otp, duration) {
|
|
68
|
+
return `<!DOCTYPE html>
|
|
69
|
+
<html lang="en">
|
|
70
|
+
<head>
|
|
71
|
+
<meta charset="UTF-8" />
|
|
72
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
73
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
74
|
+
<title>Static Template</title>
|
|
75
|
+
|
|
76
|
+
<link
|
|
77
|
+
href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap"
|
|
78
|
+
rel="stylesheet"
|
|
79
|
+
/>
|
|
80
|
+
</head>
|
|
81
|
+
<body
|
|
82
|
+
style="
|
|
83
|
+
margin: 0;
|
|
84
|
+
font-family: 'Poppins', sans-serif;
|
|
85
|
+
background: #ffffff;
|
|
86
|
+
font-size: 14px;
|
|
87
|
+
"
|
|
88
|
+
>
|
|
89
|
+
<header>
|
|
90
|
+
<table style="width: 100%;">
|
|
91
|
+
<tbody>
|
|
92
|
+
<tr style="height: 0;">
|
|
93
|
+
<td>
|
|
94
|
+
</td>
|
|
95
|
+
<td style="text-align: right;">
|
|
96
|
+
<span
|
|
97
|
+
style="font-size: 16px; line-height: 30px; color: #ffffff;"
|
|
98
|
+
>Oct 20, 2023</span
|
|
99
|
+
>
|
|
100
|
+
</td>
|
|
101
|
+
</tr>
|
|
102
|
+
</tbody>
|
|
103
|
+
</table>
|
|
104
|
+
</header>
|
|
105
|
+
|
|
106
|
+
<main>
|
|
107
|
+
<div
|
|
108
|
+
style="
|
|
109
|
+
padding: 92px 30px 115px;
|
|
110
|
+
background: #ffffff;
|
|
111
|
+
border-radius: 30px;
|
|
112
|
+
text-align: center;
|
|
113
|
+
"
|
|
114
|
+
>
|
|
115
|
+
<div style="width: 100%; max-width: 489px; margin: 0 auto;">
|
|
116
|
+
<p
|
|
117
|
+
style="
|
|
118
|
+
margin: 0;
|
|
119
|
+
margin-top: 5px;
|
|
120
|
+
font-size: 16px;
|
|
121
|
+
font-weight: 500;
|
|
122
|
+
"
|
|
123
|
+
>
|
|
124
|
+
Hey ${fullName},
|
|
125
|
+
</p>
|
|
126
|
+
<p
|
|
127
|
+
style="
|
|
128
|
+
margin: 0;
|
|
129
|
+
margin-top: 17px;
|
|
130
|
+
font-weight: 500;
|
|
131
|
+
letter-spacing: 0.56px;
|
|
132
|
+
"
|
|
133
|
+
>
|
|
134
|
+
Use the following OTP
|
|
135
|
+
to complete the procedure to verify your email address. OTP is
|
|
136
|
+
valid for
|
|
137
|
+
<span style="font-weight: 600; color: #1f1f1f;">${duration} minutes</span>.
|
|
138
|
+
Do not share this code with others.
|
|
139
|
+
</p>
|
|
140
|
+
<p
|
|
141
|
+
style="
|
|
142
|
+
margin: 0;
|
|
143
|
+
margin-top: 24px;
|
|
144
|
+
font-size: 16px;
|
|
145
|
+
font-weight: 500;
|
|
146
|
+
"
|
|
147
|
+
>
|
|
148
|
+
Your Username
|
|
149
|
+
</p>
|
|
150
|
+
<p
|
|
151
|
+
style="
|
|
152
|
+
margin: 0;
|
|
153
|
+
margin-top: 17px;
|
|
154
|
+
font-size: 28px;
|
|
155
|
+
font-weight: 600;
|
|
156
|
+
"
|
|
157
|
+
>
|
|
158
|
+
${username}
|
|
159
|
+
</p>
|
|
160
|
+
<p
|
|
161
|
+
style="
|
|
162
|
+
margin: 0;
|
|
163
|
+
margin-top: 17px;
|
|
164
|
+
font-size: 24px;
|
|
165
|
+
font-weight: 500;
|
|
166
|
+
color: #1f1f1f;
|
|
167
|
+
"
|
|
168
|
+
>
|
|
169
|
+
Your OTP
|
|
170
|
+
</p>
|
|
171
|
+
<p
|
|
172
|
+
style="
|
|
173
|
+
font-size: 40px;
|
|
174
|
+
font-weight: 600;
|
|
175
|
+
letter-spacing: 25px;
|
|
176
|
+
color: #fafafa;
|
|
177
|
+
background-color: #0d7801;
|
|
178
|
+
"
|
|
179
|
+
>
|
|
180
|
+
${otp}
|
|
181
|
+
</p>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<p
|
|
186
|
+
style="
|
|
187
|
+
max-width: 400px;
|
|
188
|
+
margin: 0 auto;
|
|
189
|
+
margin-top: 90px;
|
|
190
|
+
text-align: center;
|
|
191
|
+
font-weight: 500;
|
|
192
|
+
color: #8c8c8c;
|
|
193
|
+
"
|
|
194
|
+
>
|
|
195
|
+
Need help? Ask at
|
|
196
|
+
<a
|
|
197
|
+
href="mailto:megp@gmail.com"
|
|
198
|
+
style="color: #499fb6; text-decoration: none;"
|
|
199
|
+
>megp@gmail.com</a
|
|
200
|
+
>
|
|
201
|
+
or visit our
|
|
202
|
+
<a
|
|
203
|
+
href=""
|
|
204
|
+
target="_blank"
|
|
205
|
+
style="color: #499fb6; text-decoration: none;"
|
|
206
|
+
>Help Center</a
|
|
207
|
+
>
|
|
208
|
+
</p>
|
|
209
|
+
</main>
|
|
210
|
+
|
|
211
|
+
<footer
|
|
212
|
+
style="
|
|
213
|
+
width: 100%;
|
|
214
|
+
max-width: 490px;
|
|
215
|
+
margin: 20px auto 0;
|
|
216
|
+
text-align: center;
|
|
217
|
+
border-top: 1px solid #e6ebf1;
|
|
218
|
+
"
|
|
219
|
+
>
|
|
220
|
+
<p
|
|
221
|
+
style="
|
|
222
|
+
margin: 0;
|
|
223
|
+
margin-top: 40px;
|
|
224
|
+
font-size: 16px;
|
|
225
|
+
font-weight: 600;
|
|
226
|
+
color: #434343;
|
|
227
|
+
"
|
|
228
|
+
>
|
|
229
|
+
egp Malawi
|
|
230
|
+
</p>
|
|
231
|
+
<p style="margin: 0; margin-top: 8px; color: #434343;">
|
|
232
|
+
Lilongwe 3, Malawi.
|
|
233
|
+
</p>
|
|
234
|
+
<div style="margin: 0; margin-top: 16px;">
|
|
235
|
+
<a href="" target="_blank" style="display: inline-block;">
|
|
236
|
+
<img
|
|
237
|
+
width="36px"
|
|
238
|
+
alt="Facebook"
|
|
239
|
+
src="https://archisketch-resources.s3.ap-northeast-2.amazonaws.com/vrstyler/1661502815169_682499/email-template-icon-facebook"
|
|
240
|
+
/>
|
|
241
|
+
</a>
|
|
242
|
+
<a
|
|
243
|
+
href=""
|
|
244
|
+
target="_blank"
|
|
245
|
+
style="display: inline-block; margin-left: 8px;"
|
|
246
|
+
>
|
|
247
|
+
<img
|
|
248
|
+
width="36px"
|
|
249
|
+
alt="Instagram"
|
|
250
|
+
src="https://archisketch-resources.s3.ap-northeast-2.amazonaws.com/vrstyler/1661504218208_684135/email-template-icon-instagram"
|
|
251
|
+
/></a>
|
|
252
|
+
<a
|
|
253
|
+
href=""
|
|
254
|
+
target="_blank"
|
|
255
|
+
style="display: inline-block; margin-left: 8px;"
|
|
256
|
+
>
|
|
257
|
+
<img
|
|
258
|
+
width="36px"
|
|
259
|
+
alt="Twitter"
|
|
260
|
+
src="https://archisketch-resources.s3.ap-northeast-2.amazonaws.com/vrstyler/1661503043040_372004/email-template-icon-twitter"
|
|
261
|
+
/>
|
|
262
|
+
</a>
|
|
263
|
+
<a
|
|
264
|
+
href=""
|
|
265
|
+
target="_blank"
|
|
266
|
+
style="display: inline-block; margin-left: 8px;"
|
|
267
|
+
>
|
|
268
|
+
<img
|
|
269
|
+
width="36px"
|
|
270
|
+
alt="Youtube"
|
|
271
|
+
src="https://archisketch-resources.s3.ap-northeast-2.amazonaws.com/vrstyler/1661503195931_210869/email-template-icon-youtube"
|
|
272
|
+
/></a>
|
|
273
|
+
</div>
|
|
274
|
+
<p style="margin: 0; margin-top: 16px; color: #434343;">
|
|
275
|
+
Copyright © 2022 Company. All rights reserved.
|
|
276
|
+
</p>
|
|
277
|
+
</footer>
|
|
278
|
+
</div>
|
|
279
|
+
</body>
|
|
280
|
+
</html>
|
|
281
|
+
`;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
exports.AuthHelper = AuthHelper;
|
|
285
|
+
exports.AuthHelper = AuthHelper = __decorate([
|
|
286
|
+
(0, common_1.Injectable)(),
|
|
287
|
+
__metadata("design:paramtypes", [jwt_1.JwtService])
|
|
288
|
+
], AuthHelper);
|
|
289
|
+
//# sourceMappingURL=auth.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.helper.js","sourceRoot":"","sources":["../../src/helper/auth.helper.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
type Unit = "Years" | "Year" | "Yrs" | "Yr" | "Y" | "Weeks" | "Week" | "W" | "Days" | "Day" | "D" | "Hours" | "Hour" | "Hrs" | "Hr" | "H" | "Minutes" | "Minute" | "Mins" | "Min" | "M" | "Seconds" | "Second" | "Secs" | "Sec" | "s" | "Milliseconds" | "Millisecond" | "Msecs" | "Msec" | "Ms";
|
|
2
|
+
type UnitAnyCase = Unit | Uppercase<Unit> | Lowercase<Unit>;
|
|
3
|
+
export type StringValue = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.type.js","sourceRoot":"","sources":["../../src/helper/jwt.type.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './authorization.module';
|
|
2
|
+
export * from './decorators/allow-anonymous.decorator';
|
|
3
|
+
export * from './decorators/current-user.decorator';
|
|
4
|
+
export * from './guards/jwt.guard';
|
|
5
|
+
export * from './guards/permissions.guard';
|
|
6
|
+
export * from './helper/auth.helper';
|
|
7
|
+
export * from './guards/jwt-refresh.guard';
|
|
8
|
+
export * from './guards/throttler-behind-proxy.guard';
|
|
9
|
+
export * from './guards/api-key.guard';
|
|
10
|
+
export * from './guards/vendor.guard';
|
|
11
|
+
export * from './guards/optional-jwt.guard';
|
|
12
|
+
export * from './strategy/jwt-refresh-token.strategy';
|
|
13
|
+
export * from './strategy/jwt.strategy';
|
|
14
|
+
export * from './models/auth.model';
|
|
15
|
+
export * from './helper/jwt.type';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./authorization.module"), exports);
|
|
18
|
+
__exportStar(require("./decorators/allow-anonymous.decorator"), exports);
|
|
19
|
+
__exportStar(require("./decorators/current-user.decorator"), exports);
|
|
20
|
+
__exportStar(require("./guards/jwt.guard"), exports);
|
|
21
|
+
__exportStar(require("./guards/permissions.guard"), exports);
|
|
22
|
+
__exportStar(require("./helper/auth.helper"), exports);
|
|
23
|
+
__exportStar(require("./guards/jwt-refresh.guard"), exports);
|
|
24
|
+
__exportStar(require("./guards/throttler-behind-proxy.guard"), exports);
|
|
25
|
+
__exportStar(require("./guards/api-key.guard"), exports);
|
|
26
|
+
__exportStar(require("./guards/vendor.guard"), exports);
|
|
27
|
+
__exportStar(require("./guards/optional-jwt.guard"), exports);
|
|
28
|
+
__exportStar(require("./strategy/jwt-refresh-token.strategy"), exports);
|
|
29
|
+
__exportStar(require("./strategy/jwt.strategy"), exports);
|
|
30
|
+
__exportStar(require("./models/auth.model"), exports);
|
|
31
|
+
__exportStar(require("./helper/jwt.type"), exports);
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,yEAAuD;AACvD,sEAAoD;AACpD,qDAAmC;AACnC,6DAA2C;AAC3C,uDAAqC;AACrC,6DAA2C;AAC3C,wEAAsD;AACtD,yDAAuC;AACvC,wDAAsC;AACtC,8DAA4C;AAC5C,wEAAsD;AACtD,0DAAwC;AACxC,sDAAoC;AACpC,oDAAkC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ORGANIZATION_TYPE_ENUM } from '@zola_do/core';
|
|
2
|
+
export declare class OrganizationDto {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
shortName: string;
|
|
6
|
+
code: string;
|
|
7
|
+
preferentialTreatments: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare class UserDto {
|
|
10
|
+
userId: string;
|
|
11
|
+
organization: OrganizationDto;
|
|
12
|
+
permissions: string[];
|
|
13
|
+
roleSystems: string[];
|
|
14
|
+
applications: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare class AccountDto {
|
|
17
|
+
tenantId: number;
|
|
18
|
+
id: string;
|
|
19
|
+
username: string;
|
|
20
|
+
firstName: string;
|
|
21
|
+
lastName: string;
|
|
22
|
+
email: string;
|
|
23
|
+
phone: string;
|
|
24
|
+
isPhoneVerified: boolean;
|
|
25
|
+
origin: ORGANIZATION_TYPE_ENUM;
|
|
26
|
+
organizations: UserDto[];
|
|
27
|
+
}
|
|
28
|
+
export declare class CurrentUserDto extends UserDto {
|
|
29
|
+
tenantId: number;
|
|
30
|
+
id: string;
|
|
31
|
+
username: string;
|
|
32
|
+
firstName: string;
|
|
33
|
+
lastName: string;
|
|
34
|
+
email: string;
|
|
35
|
+
origin: ORGANIZATION_TYPE_ENUM;
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentUserDto = exports.AccountDto = exports.UserDto = exports.OrganizationDto = void 0;
|
|
4
|
+
class OrganizationDto {
|
|
5
|
+
}
|
|
6
|
+
exports.OrganizationDto = OrganizationDto;
|
|
7
|
+
class UserDto {
|
|
8
|
+
}
|
|
9
|
+
exports.UserDto = UserDto;
|
|
10
|
+
class AccountDto {
|
|
11
|
+
}
|
|
12
|
+
exports.AccountDto = AccountDto;
|
|
13
|
+
class CurrentUserDto extends UserDto {
|
|
14
|
+
}
|
|
15
|
+
exports.CurrentUserDto = CurrentUserDto;
|
|
16
|
+
//# sourceMappingURL=auth.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.model.js","sourceRoot":"","sources":["../../src/models/auth.model.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;CAM3B;AAND,0CAMC;AAED,MAAa,OAAO;CAMnB;AAND,0BAMC;AAED,MAAa,UAAU;CAWtB;AAXD,gCAWC;AAED,MAAa,cAAe,SAAQ,OAAO;CAQ1C;AARD,wCAQC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Strategy } from 'passport-jwt';
|
|
2
|
+
declare const JwtRefreshTokenStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
|
|
3
|
+
validate(...args: any[]): unknown;
|
|
4
|
+
};
|
|
5
|
+
export declare class JwtRefreshTokenStrategy extends JwtRefreshTokenStrategy_base {
|
|
6
|
+
constructor();
|
|
7
|
+
validate(payload: any): Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JwtRefreshTokenStrategy = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const passport_1 = require("@nestjs/passport");
|
|
6
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
7
|
+
(0, common_1.Injectable)();
|
|
8
|
+
class JwtRefreshTokenStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, 'jwt-refresh') {
|
|
9
|
+
constructor() {
|
|
10
|
+
const strategyOptions = {
|
|
11
|
+
jwtFromRequest: (req) => req.body.refresh_token,
|
|
12
|
+
ignoreExpiration: false,
|
|
13
|
+
secretOrKey: process.env.JWT_REFRESH_TOKEN_SECRET,
|
|
14
|
+
};
|
|
15
|
+
super(strategyOptions);
|
|
16
|
+
}
|
|
17
|
+
async validate(payload) {
|
|
18
|
+
return payload;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.JwtRefreshTokenStrategy = JwtRefreshTokenStrategy;
|
|
22
|
+
//# sourceMappingURL=jwt-refresh-token.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-refresh-token.strategy.js","sourceRoot":"","sources":["../../src/strategy/jwt-refresh-token.strategy.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAC5C,+CAAoD;AACpD,+CAAyD;AAEzD,IAAA,mBAAU,GAAE,CAAC;AACb,MAAa,uBAAwB,SAAQ,IAAA,2BAAgB,EAC3D,uBAAQ,EACR,aAAa,CACd;IACC;QACE,MAAM,eAAe,GAAoB;YACvC,cAAc,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa;YAC/C,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB;SAClD,CAAC;QAEF,KAAK,CAAC,eAAe,CAAC,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAY;QACzB,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAjBD,0DAiBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Strategy } from 'passport-jwt';
|
|
2
|
+
declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
|
|
3
|
+
validate(...args: any[]): unknown;
|
|
4
|
+
};
|
|
5
|
+
export declare class JwtStrategy extends JwtStrategy_base {
|
|
6
|
+
constructor();
|
|
7
|
+
validate(payload: any): Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JwtStrategy = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const passport_1 = require("@nestjs/passport");
|
|
6
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
7
|
+
(0, common_1.Injectable)();
|
|
8
|
+
class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
9
|
+
constructor() {
|
|
10
|
+
const strategyOptions = {
|
|
11
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
12
|
+
ignoreExpiration: false,
|
|
13
|
+
secretOrKey: process.env.JWT_ACCESS_TOKEN_SECRET,
|
|
14
|
+
};
|
|
15
|
+
super(strategyOptions);
|
|
16
|
+
}
|
|
17
|
+
async validate(payload) {
|
|
18
|
+
return payload;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.JwtStrategy = JwtStrategy;
|
|
22
|
+
//# sourceMappingURL=jwt.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../../src/strategy/jwt.strategy.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAC5C,+CAAoD;AACpD,+CAAqE;AAErE,IAAA,mBAAU,GAAE,CAAC;AACb,MAAa,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD;QACE,MAAM,eAAe,GAAoB;YACvC,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB;SACjD,CAAC;QAEF,KAAK,CAAC,eAAe,CAAC,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAY;QACzB,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAdD,kCAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const extractUser: (request: any, user: any) => any;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.extractUser = void 0;
|
|
15
|
+
const extractUser = (request, user) => {
|
|
16
|
+
const { organizations } = user, rest = __rest(user, ["organizations"]);
|
|
17
|
+
let parsedUser = rest;
|
|
18
|
+
if (organizations && organizations.length > 0) {
|
|
19
|
+
let organization;
|
|
20
|
+
if (request.headers && request.headers['x-organization-id']) {
|
|
21
|
+
organization = organizations.find((x) => x.organization.id == request.headers['x-organization-id']);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
organization = organizations[0];
|
|
25
|
+
}
|
|
26
|
+
parsedUser = Object.assign(Object.assign(Object.assign({}, parsedUser), { fullName: parsedUser.firstName + ' ' + parsedUser.lastName }), organization);
|
|
27
|
+
}
|
|
28
|
+
return parsedUser;
|
|
29
|
+
};
|
|
30
|
+
exports.extractUser = extractUser;
|
|
31
|
+
//# sourceMappingURL=extract-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-user.js","sourceRoot":"","sources":["../../src/utils/extract-user.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAO,MAAM,WAAW,GAAG,CAAC,OAAY,EAAE,IAAS,EAAE,EAAE;IACrD,MAAM,EAAE,aAAa,KAAc,IAAI,EAAb,IAAI,UAAK,IAAI,EAAjC,iBAA0B,CAAO,CAAC;IACxC,IAAI,UAAU,GAAQ,IAAI,CAAC;IAC3B,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,IAAI,YAAiB,CAAC;QAEtB,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC5D,YAAY,GAAG,aAAa,CAAC,IAAI,CAC/B,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CACtE,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;QAED,UAAU,iDACL,UAAU,KACb,QAAQ,EAAE,UAAU,CAAC,SAAS,GAAG,GAAG,GAAG,UAAU,CAAC,QAAQ,KACvD,YAAY,CAChB,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AArBW,QAAA,WAAW,eAqBtB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zola_do/authorization",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "JWT auth, guards, strategies for NestJS",
|
|
5
|
+
"author": "zolaDO",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": ["dist", "README.md"],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rimraf dist && tsc",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
25
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
26
|
+
"@nestjs/jwt": "^10.0.0 || ^11.0.0",
|
|
27
|
+
"@nestjs/passport": "^10.0.0 || ^11.0.0",
|
|
28
|
+
"@nestjs/platform-express": "^10.0.0 || ^11.0.0",
|
|
29
|
+
"@nestjs/throttler": "^5.0.0 || ^6.0.0",
|
|
30
|
+
"passport": "^0.7.0",
|
|
31
|
+
"passport-jwt": "^4.0.1",
|
|
32
|
+
"reflect-metadata": "^0.1.0 || ^0.2.0",
|
|
33
|
+
"rxjs": "^7.0.0 || ^8.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@nestjs/throttler": { "optional": true }
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@zola_do/core": "file:../core",
|
|
40
|
+
"bcrypt": "^6.0.0",
|
|
41
|
+
"jsonwebtoken": "^9.0.2"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/bcrypt": "^6.0.0",
|
|
45
|
+
"@types/passport-jwt": "^4.0.1",
|
|
46
|
+
"rimraf": "^6.1.0",
|
|
47
|
+
"typescript": "^5.9.3"
|
|
48
|
+
}
|
|
49
|
+
}
|