itlab-internal-services 0.0.3 → 1.0.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.
package/README.md
CHANGED
|
@@ -57,11 +57,11 @@ async delete(targetId: string): Promise<void>
|
|
|
57
57
|
### Content Service
|
|
58
58
|
|
|
59
59
|
```typescript
|
|
60
|
-
async verify(
|
|
60
|
+
async verify(content: Content): Promise<void>
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
|
-
async post(targetId: string,
|
|
64
|
+
async post(targetId: string, content: Content): Promise<void>
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
```typescript
|
|
@@ -31,15 +31,20 @@ let InternalGuard = class InternalGuard {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
InternalGuard = __decorate([
|
|
34
|
+
(0, common_1.Injectable)(),
|
|
34
35
|
__param(0, (0, common_1.Inject)(internal_constants_1.INTERNAL_MODULE_HEADER_TOKEN)),
|
|
35
36
|
__metadata("design:paramtypes", [String])
|
|
36
37
|
], InternalGuard);
|
|
37
38
|
exports.InternalGuard = InternalGuard;
|
|
38
|
-
class UnauthorizedApplicationException extends common_1.HttpException {
|
|
39
|
+
let UnauthorizedApplicationException = class UnauthorizedApplicationException extends common_1.HttpException {
|
|
39
40
|
constructor() {
|
|
40
41
|
super('Application unauthorized', common_1.HttpStatus.UNAUTHORIZED);
|
|
41
42
|
}
|
|
42
|
-
}
|
|
43
|
+
};
|
|
44
|
+
UnauthorizedApplicationException = __decorate([
|
|
45
|
+
(0, common_1.Injectable)(),
|
|
46
|
+
__metadata("design:paramtypes", [])
|
|
47
|
+
], UnauthorizedApplicationException);
|
|
43
48
|
exports.UnauthorizedApplicationException = UnauthorizedApplicationException;
|
|
44
49
|
const Internal = () => (0, common_1.applyDecorators)((0, swagger_1.ApiBasicAuth)(exports.INTERNAL_HEADER_KEY), (0, common_1.UseGuards)(InternalGuard), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Application unauthorized' }));
|
|
45
50
|
exports.Internal = Internal;
|
package/dist/guards/jwt.guard.js
CHANGED
|
@@ -31,6 +31,7 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
JwtStrategy = __decorate([
|
|
34
|
+
(0, common_1.Injectable)(),
|
|
34
35
|
__param(0, (0, common_1.Inject)(internal_constants_1.INTERNAL_MODULE_JWT_SECRET)),
|
|
35
36
|
__metadata("design:paramtypes", [String])
|
|
36
37
|
], JwtStrategy);
|
|
@@ -47,8 +48,11 @@ exports.JwtToken = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
|
47
48
|
const h = ctx.switchToHttp().getRequest().header('Authorization');
|
|
48
49
|
return h.replace('Bearer ', '');
|
|
49
50
|
});
|
|
50
|
-
class JwtGuard extends (0, passport_1.AuthGuard)('jwt') {
|
|
51
|
-
}
|
|
51
|
+
let JwtGuard = class JwtGuard extends (0, passport_1.AuthGuard)('jwt') {
|
|
52
|
+
};
|
|
53
|
+
JwtGuard = __decorate([
|
|
54
|
+
(0, common_1.Injectable)()
|
|
55
|
+
], JwtGuard);
|
|
52
56
|
exports.JwtGuard = JwtGuard;
|
|
53
57
|
const Jwt = () => (0, common_1.applyDecorators)((0, common_1.UseGuards)(JwtGuard), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized' }));
|
|
54
58
|
exports.Jwt = Jwt;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.Perms = exports.InsufficientPermissionsException = exports.PermsGuard = void 0;
|
|
4
13
|
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
5
15
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
16
|
const jwt_guard_1 = require("./jwt.guard");
|
|
7
17
|
const meta = 'permsguard';
|
|
@@ -11,7 +21,7 @@ function transformPermissions(permissions) {
|
|
|
11
21
|
});
|
|
12
22
|
return [...new Set(mapped.flat())];
|
|
13
23
|
}
|
|
14
|
-
class PermsGuard {
|
|
24
|
+
let PermsGuard = class PermsGuard {
|
|
15
25
|
constructor(reflector) {
|
|
16
26
|
this.reflector = reflector;
|
|
17
27
|
}
|
|
@@ -30,13 +40,21 @@ class PermsGuard {
|
|
|
30
40
|
return true;
|
|
31
41
|
throw new InsufficientPermissionsException();
|
|
32
42
|
}
|
|
33
|
-
}
|
|
43
|
+
};
|
|
44
|
+
PermsGuard = __decorate([
|
|
45
|
+
(0, common_1.Injectable)(),
|
|
46
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
47
|
+
], PermsGuard);
|
|
34
48
|
exports.PermsGuard = PermsGuard;
|
|
35
|
-
class InsufficientPermissionsException extends common_1.HttpException {
|
|
49
|
+
let InsufficientPermissionsException = class InsufficientPermissionsException extends common_1.HttpException {
|
|
36
50
|
constructor() {
|
|
37
51
|
super('Insufficient permissions', common_1.HttpStatus.UNAUTHORIZED);
|
|
38
52
|
}
|
|
39
|
-
}
|
|
53
|
+
};
|
|
54
|
+
InsufficientPermissionsException = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__metadata("design:paramtypes", [])
|
|
57
|
+
], InsufficientPermissionsException);
|
|
40
58
|
exports.InsufficientPermissionsException = InsufficientPermissionsException;
|
|
41
59
|
const Perms = (...perms) => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(meta, perms), (0, common_1.UseGuards)(jwt_guard_1.JwtGuard, PermsGuard), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiOperation)({ summary: 'Perms: ' + perms.join(', ') }), (0, swagger_1.ApiUnauthorizedResponse)({
|
|
42
60
|
description: 'Unauthorized or insufficient permissions',
|
|
@@ -6,7 +6,7 @@ export declare class ContentService {
|
|
|
6
6
|
protected readonly target: Targets;
|
|
7
7
|
constructor(instance?: AxiosInstance, target?: Targets);
|
|
8
8
|
protected prefix: string;
|
|
9
|
-
verify(
|
|
10
|
-
post(targetId: string,
|
|
9
|
+
verify(content: Content): Promise<void>;
|
|
10
|
+
post(targetId: string, content: Content): Promise<void>;
|
|
11
11
|
delete(targetId: string): Promise<void>;
|
|
12
12
|
}
|
|
@@ -35,21 +35,23 @@ let ContentService = class ContentService {
|
|
|
35
35
|
this.target = target;
|
|
36
36
|
this.prefix = 'content/internal';
|
|
37
37
|
}
|
|
38
|
-
verify(
|
|
38
|
+
verify(content) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
return new Promise((resolve, reject) => {
|
|
41
41
|
this.instance
|
|
42
|
-
.post(`${this.prefix}/verify`, { contents })
|
|
42
|
+
.post(`${this.prefix}/verify`, { contents: content })
|
|
43
43
|
.then(() => resolve())
|
|
44
44
|
.catch(({ response }) => reject(new common_1.HttpException(response.data, response.status)));
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
post(targetId,
|
|
48
|
+
post(targetId, content) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
50
|
return new Promise((resolve, reject) => {
|
|
51
51
|
this.instance
|
|
52
|
-
.post(`${this.prefix}/${this.target}/${targetId}`, {
|
|
52
|
+
.post(`${this.prefix}/${this.target}/${targetId}`, {
|
|
53
|
+
contents: content,
|
|
54
|
+
})
|
|
53
55
|
.then(() => resolve())
|
|
54
56
|
.catch(({ response }) => reject(new common_1.HttpException(response.data, response.status)));
|
|
55
57
|
});
|