@tc-libs/api-key 0.9.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 +11 -0
- package/package.json +11 -0
- package/src/api-key.module.d.ts +2 -0
- package/src/api-key.module.js +20 -0
- package/src/api-key.module.js.map +1 -0
- package/src/api-key.module.options.d.ts +8 -0
- package/src/api-key.module.options.js +5 -0
- package/src/api-key.module.options.js.map +1 -0
- package/src/constants/api-key.constant.d.ts +1 -0
- package/src/constants/api-key.constant.js +5 -0
- package/src/constants/api-key.constant.js.map +1 -0
- package/src/constants/api-key.doc.d.ts +15 -0
- package/src/constants/api-key.doc.js +24 -0
- package/src/constants/api-key.doc.js.map +1 -0
- package/src/constants/api-key.list.constant.d.ts +7 -0
- package/src/constants/api-key.list.constant.js +11 -0
- package/src/constants/api-key.list.constant.js.map +1 -0
- package/src/constants/api-key.permissions.constants.d.ts +2 -0
- package/src/constants/api-key.permissions.constants.js +9 -0
- package/src/constants/api-key.permissions.constants.js.map +1 -0
- package/src/constants/index.d.ts +4 -0
- package/src/constants/index.js +8 -0
- package/src/constants/index.js.map +1 -0
- package/src/controllers/api-key.admin.controller.d.ts +11 -0
- package/src/controllers/api-key.admin.controller.js +97 -0
- package/src/controllers/api-key.admin.controller.js.map +1 -0
- package/src/controllers/api-key.controller.d.ts +16 -0
- package/src/controllers/api-key.controller.js +156 -0
- package/src/controllers/api-key.controller.js.map +1 -0
- package/src/controllers/api-key.public.controller.d.ts +16 -0
- package/src/controllers/api-key.public.controller.js +144 -0
- package/src/controllers/api-key.public.controller.js.map +1 -0
- package/src/controllers/index.d.ts +3 -0
- package/src/controllers/index.js +7 -0
- package/src/controllers/index.js.map +1 -0
- package/src/decorators/api-key.admin.decorator.d.ts +5 -0
- package/src/decorators/api-key.admin.decorator.js +26 -0
- package/src/decorators/api-key.admin.decorator.js.map +1 -0
- package/src/decorators/api-key.decorator.d.ts +3 -0
- package/src/decorators/api-key.decorator.js +18 -0
- package/src/decorators/api-key.decorator.js.map +1 -0
- package/src/decorators/api-key.public.decorator.d.ts +1 -0
- package/src/decorators/api-key.public.decorator.js +10 -0
- package/src/decorators/api-key.public.decorator.js.map +1 -0
- package/src/decorators/index.d.ts +2 -0
- package/src/decorators/index.js +6 -0
- package/src/decorators/index.js.map +1 -0
- package/src/docs/api-key.admin.doc.d.ts +7 -0
- package/src/docs/api-key.admin.doc.js +105 -0
- package/src/docs/api-key.admin.doc.js.map +1 -0
- package/src/docs/api-key.public.doc.d.ts +1 -0
- package/src/docs/api-key.public.doc.js +18 -0
- package/src/docs/api-key.public.doc.js.map +1 -0
- package/src/docs/index.d.ts +2 -0
- package/src/docs/index.js +6 -0
- package/src/docs/index.js.map +1 -0
- package/src/dtos/api-key.active.dto.d.ts +3 -0
- package/src/dtos/api-key.active.dto.js +22 -0
- package/src/dtos/api-key.active.dto.js.map +1 -0
- package/src/dtos/api-key.create.dto.d.ts +11 -0
- package/src/dtos/api-key.create.dto.js +62 -0
- package/src/dtos/api-key.create.dto.js.map +1 -0
- package/src/dtos/api-key.request.dto.d.ts +3 -0
- package/src/dtos/api-key.request.dto.js +23 -0
- package/src/dtos/api-key.request.dto.js.map +1 -0
- package/src/dtos/api-key.update-date.dto.d.ts +4 -0
- package/src/dtos/api-key.update-date.dto.js +39 -0
- package/src/dtos/api-key.update-date.dto.js.map +1 -0
- package/src/dtos/api-key.update.dto.d.ts +5 -0
- package/src/dtos/api-key.update.dto.js +12 -0
- package/src/dtos/api-key.update.dto.js.map +1 -0
- package/src/dtos/index.d.ts +5 -0
- package/src/dtos/index.js +9 -0
- package/src/dtos/index.js.map +1 -0
- package/src/errors/409/api.409.api-key.error.d.ts +7 -0
- package/src/errors/409/api.409.api-key.error.js +11 -0
- package/src/errors/409/api.409.api-key.error.js.map +1 -0
- package/src/guards/api-key.active.guard.d.ts +7 -0
- package/src/guards/api-key.active.guard.js +30 -0
- package/src/guards/api-key.active.guard.js.map +1 -0
- package/src/guards/api-key.expired.guard.d.ts +7 -0
- package/src/guards/api-key.expired.guard.js +29 -0
- package/src/guards/api-key.expired.guard.js.map +1 -0
- package/src/guards/api-key.not-found.guard.d.ts +4 -0
- package/src/guards/api-key.not-found.guard.js +20 -0
- package/src/guards/api-key.not-found.guard.js.map +1 -0
- package/src/guards/api-key.put-to-request-by-user.guard.d.ts +7 -0
- package/src/guards/api-key.put-to-request-by-user.guard.js +31 -0
- package/src/guards/api-key.put-to-request-by-user.guard.js.map +1 -0
- package/src/guards/api-key.put-to-request.guard.d.ts +7 -0
- package/src/guards/api-key.put-to-request.guard.js +25 -0
- package/src/guards/api-key.put-to-request.guard.js.map +1 -0
- package/src/guards/index.d.ts +6 -0
- package/src/guards/index.js +10 -0
- package/src/guards/index.js.map +1 -0
- package/src/guards/x-api-key/api-key.x-api-key.guard.d.ts +8 -0
- package/src/guards/x-api-key/api-key.x-api-key.guard.js +35 -0
- package/src/guards/x-api-key/api-key.x-api-key.guard.js.map +1 -0
- package/src/guards/x-api-key/api-key.x-api-key.strategy.d.ts +14 -0
- package/src/guards/x-api-key/api-key.x-api-key.strategy.js +69 -0
- package/src/guards/x-api-key/api-key.x-api-key.strategy.js.map +1 -0
- package/src/index.d.ts +12 -0
- package/src/index.js +16 -0
- package/src/index.js.map +1 -0
- package/src/interfaces/api-key.interface.d.ts +10 -0
- package/src/interfaces/api-key.interface.js +3 -0
- package/src/interfaces/api-key.interface.js.map +1 -0
- package/src/interfaces/index.d.ts +1 -0
- package/src/interfaces/index.js +5 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/repository/api-key.repository.module.d.ts +2 -0
- package/src/repository/api-key.repository.module.js +27 -0
- package/src/repository/api-key.repository.module.js.map +1 -0
- package/src/repository/entities/api-key.entity.d.ts +21 -0
- package/src/repository/entities/api-key.entity.js +98 -0
- package/src/repository/entities/api-key.entity.js.map +1 -0
- package/src/repository/index.d.ts +3 -0
- package/src/repository/index.js +7 -0
- package/src/repository/index.js.map +1 -0
- package/src/repository/repositories/api-key.repository.d.ts +11 -0
- package/src/repository/repositories/api-key.repository.js +28 -0
- package/src/repository/repositories/api-key.repository.js.map +1 -0
- package/src/serializations/api-key.create.serialization.d.ts +6 -0
- package/src/serializations/api-key.create.serialization.js +18 -0
- package/src/serializations/api-key.create.serialization.js.map +1 -0
- package/src/serializations/api-key.get.serialization.d.ts +13 -0
- package/src/serializations/api-key.get.serialization.js +86 -0
- package/src/serializations/api-key.get.serialization.js.map +1 -0
- package/src/serializations/api-key.list.serialization.d.ts +5 -0
- package/src/serializations/api-key.list.serialization.js +11 -0
- package/src/serializations/api-key.list.serialization.js.map +1 -0
- package/src/serializations/api-key.reset.serialization.d.ts +3 -0
- package/src/serializations/api-key.reset.serialization.js +8 -0
- package/src/serializations/api-key.reset.serialization.js.map +1 -0
- package/src/serializations/index.d.ts +4 -0
- package/src/serializations/index.js +8 -0
- package/src/serializations/index.js.map +1 -0
- package/src/services/api-key.service.d.ts +34 -0
- package/src/services/api-key.service.js +136 -0
- package/src/services/api-key.service.js.map +1 -0
- package/src/services/index.d.ts +1 -0
- package/src/services/index.js +5 -0
- package/src/services/index.js.map +1 -0
- package/src/tasks/api-key.inactive.task.d.ts +6 -0
- package/src/tasks/api-key.inactive.task.js +35 -0
- package/src/tasks/api-key.inactive.task.js.map +1 -0
- package/src/tasks/index.d.ts +1 -0
- package/src/tasks/index.js +5 -0
- package/src/tasks/index.js.map +1 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeySchema = exports.ApiKeyEntity = exports.ApiKeyDatabaseName = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const authentication_1 = require("@tc-libs/authentication");
|
|
6
|
+
const database_1 = require("@tc-libs/database");
|
|
7
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
8
|
+
const mongoose_2 = require("mongoose");
|
|
9
|
+
exports.ApiKeyDatabaseName = 'apikeys';
|
|
10
|
+
let ApiKeyEntity = class ApiKeyEntity extends database_1.DatabaseMongoEntityAbstract {
|
|
11
|
+
};
|
|
12
|
+
exports.ApiKeyEntity = ApiKeyEntity;
|
|
13
|
+
tslib_1.__decorate([
|
|
14
|
+
(0, mongoose_1.Prop)({
|
|
15
|
+
index: true,
|
|
16
|
+
required: true,
|
|
17
|
+
type: mongoose_2.SchemaTypes.ObjectId,
|
|
18
|
+
}),
|
|
19
|
+
tslib_1.__metadata("design:type", String)
|
|
20
|
+
], ApiKeyEntity.prototype, "user", void 0);
|
|
21
|
+
tslib_1.__decorate([
|
|
22
|
+
(0, mongoose_1.Prop)({
|
|
23
|
+
required: true,
|
|
24
|
+
type: String,
|
|
25
|
+
enum: authentication_1.ENUM_AUTH_ACCESS_FOR,
|
|
26
|
+
}),
|
|
27
|
+
tslib_1.__metadata("design:type", String)
|
|
28
|
+
], ApiKeyEntity.prototype, "accessFor", void 0);
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, mongoose_1.Prop)({
|
|
31
|
+
required: true,
|
|
32
|
+
index: true,
|
|
33
|
+
type: String,
|
|
34
|
+
minlength: 1,
|
|
35
|
+
maxlength: 100,
|
|
36
|
+
lowercase: true,
|
|
37
|
+
trim: true,
|
|
38
|
+
}),
|
|
39
|
+
tslib_1.__metadata("design:type", String)
|
|
40
|
+
], ApiKeyEntity.prototype, "name", void 0);
|
|
41
|
+
tslib_1.__decorate([
|
|
42
|
+
(0, mongoose_1.Prop)({
|
|
43
|
+
required: false,
|
|
44
|
+
type: String,
|
|
45
|
+
minlength: 1,
|
|
46
|
+
maxlength: 255,
|
|
47
|
+
}),
|
|
48
|
+
tslib_1.__metadata("design:type", String)
|
|
49
|
+
], ApiKeyEntity.prototype, "description", void 0);
|
|
50
|
+
tslib_1.__decorate([
|
|
51
|
+
(0, mongoose_1.Prop)({
|
|
52
|
+
required: true,
|
|
53
|
+
type: String,
|
|
54
|
+
unique: true,
|
|
55
|
+
index: true,
|
|
56
|
+
trim: true,
|
|
57
|
+
}),
|
|
58
|
+
tslib_1.__metadata("design:type", String)
|
|
59
|
+
], ApiKeyEntity.prototype, "key", void 0);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, mongoose_1.Prop)({
|
|
62
|
+
required: true,
|
|
63
|
+
trim: true,
|
|
64
|
+
type: String,
|
|
65
|
+
}),
|
|
66
|
+
tslib_1.__metadata("design:type", String)
|
|
67
|
+
], ApiKeyEntity.prototype, "hash", void 0);
|
|
68
|
+
tslib_1.__decorate([
|
|
69
|
+
(0, mongoose_1.Prop)({
|
|
70
|
+
required: true,
|
|
71
|
+
index: true,
|
|
72
|
+
type: Boolean,
|
|
73
|
+
}),
|
|
74
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
75
|
+
], ApiKeyEntity.prototype, "active", void 0);
|
|
76
|
+
tslib_1.__decorate([
|
|
77
|
+
(0, mongoose_1.Prop)({
|
|
78
|
+
required: false,
|
|
79
|
+
type: Date,
|
|
80
|
+
}),
|
|
81
|
+
tslib_1.__metadata("design:type", Date)
|
|
82
|
+
], ApiKeyEntity.prototype, "startDate", void 0);
|
|
83
|
+
tslib_1.__decorate([
|
|
84
|
+
(0, mongoose_1.Prop)({
|
|
85
|
+
required: false,
|
|
86
|
+
type: Date,
|
|
87
|
+
}),
|
|
88
|
+
tslib_1.__metadata("design:type", Date)
|
|
89
|
+
], ApiKeyEntity.prototype, "endDate", void 0);
|
|
90
|
+
exports.ApiKeyEntity = ApiKeyEntity = tslib_1.__decorate([
|
|
91
|
+
(0, database_1.DatabaseEntity)({ collection: exports.ApiKeyDatabaseName })
|
|
92
|
+
], ApiKeyEntity);
|
|
93
|
+
exports.ApiKeySchema = mongoose_1.SchemaFactory.createForClass(ApiKeyEntity);
|
|
94
|
+
exports.ApiKeySchema.pre('save', function (next) {
|
|
95
|
+
this.name = this.name.toLowerCase();
|
|
96
|
+
next();
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=api-key.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.entity.js","sourceRoot":"","sources":["../../../../../../packages/api-key/src/repository/entities/api-key.entity.ts"],"names":[],"mappings":";;;;AAAA,4DAA+D;AAC/D,gDAAgF;AAChF,+CAAuD;AACvD,uCAA8E;AAGjE,QAAA,kBAAkB,GAAG,SAAS,CAAC;AAGrC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,sCAA2B;CAoE5D,CAAA;AApEY,oCAAY;AAMvB;IALC,IAAA,eAAI,EAAC;QACJ,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,sBAAW,CAAC,QAAQ;KAC3B,CAAC;;0CACW;AAOb;IALC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,qCAAoB;KAC3B,CAAC;;+CAC8B;AAWhC;IATC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,IAAI;QACf,IAAI,EAAE,IAAI;KACX,CAAC;;0CACW;AAQb;IANC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,GAAG;KACf,CAAC;;iDACmB;AASrB;IAPC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,IAAI;KACX,CAAC;;yCACU;AAOZ;IALC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,MAAM;KACb,CAAC;;0CACW;AAOb;IALC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,OAAO;KACd,CAAC;;4CACc;AAMhB;IAJC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,IAAI;KACX,CAAC;sCACU,IAAI;+CAAC;AAMjB;IAJC,IAAA,eAAI,EAAC;QACJ,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,IAAI;KACX,CAAC;sCACQ,IAAI;6CAAC;uBAnEJ,YAAY;IADxB,IAAA,yBAAc,EAAC,EAAE,UAAU,EAAE,0BAAkB,EAAE,CAAC;GACtC,YAAY,CAoExB;AAEY,QAAA,YAAY,GAAG,wBAAa,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;AAIvE,oBAAY,CAAC,GAAG,CACd,MAAM,EACN,UAAU,IAA2C;IACnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IAEpC,IAAI,EAAE,CAAC;AACT,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./entities/api-key.entity"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./repositories/api-key.repository"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./api-key.repository.module"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/repository/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,4EAAkD;AAClD,sEAA4C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { AppCacheService } from '@tc-libs/app-cache';
|
|
3
|
+
import { DatabaseMongoRepositoryAbstract } from '@tc-libs/database';
|
|
4
|
+
import { Connection, Model } from 'mongoose';
|
|
5
|
+
import { ApiKeyDoc, ApiKeyEntity } from '../entities/api-key.entity';
|
|
6
|
+
export declare class ApiKeyRepository extends DatabaseMongoRepositoryAbstract<ApiKeyEntity, ApiKeyDoc> {
|
|
7
|
+
protected readonly ApiKeyDoc: Model<ApiKeyEntity>;
|
|
8
|
+
protected readonly connection: Connection;
|
|
9
|
+
protected readonly _logger: Logger;
|
|
10
|
+
constructor(ApiKeyDoc: Model<ApiKeyEntity>, connection: Connection, _cache: AppCacheService);
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var ApiKeyRepository_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ApiKeyRepository = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const app_cache_1 = require("@tc-libs/app-cache");
|
|
8
|
+
const database_1 = require("@tc-libs/database");
|
|
9
|
+
const mongoose_1 = require("mongoose");
|
|
10
|
+
const api_key_entity_1 = require("../entities/api-key.entity");
|
|
11
|
+
let ApiKeyRepository = ApiKeyRepository_1 = class ApiKeyRepository extends database_1.DatabaseMongoRepositoryAbstract {
|
|
12
|
+
constructor(ApiKeyDoc, connection, _cache) {
|
|
13
|
+
super(ApiKeyDoc, connection, _cache);
|
|
14
|
+
this.ApiKeyDoc = ApiKeyDoc;
|
|
15
|
+
this.connection = connection;
|
|
16
|
+
this._logger = new common_1.Logger(ApiKeyRepository_1.name);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.ApiKeyRepository = ApiKeyRepository;
|
|
20
|
+
exports.ApiKeyRepository = ApiKeyRepository = ApiKeyRepository_1 = tslib_1.__decorate([
|
|
21
|
+
(0, common_1.Injectable)(),
|
|
22
|
+
tslib_1.__param(0, (0, database_1.DatabaseModel)(api_key_entity_1.ApiKeyEntity.name)),
|
|
23
|
+
tslib_1.__param(1, (0, database_1.DatabaseConnection)()),
|
|
24
|
+
tslib_1.__metadata("design:paramtypes", [mongoose_1.Model,
|
|
25
|
+
mongoose_1.Connection,
|
|
26
|
+
app_cache_1.AppCacheService])
|
|
27
|
+
], ApiKeyRepository);
|
|
28
|
+
//# sourceMappingURL=api-key.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.repository.js","sourceRoot":"","sources":["../../../../../../packages/api-key/src/repository/repositories/api-key.repository.ts"],"names":[],"mappings":";;;;;AAAA,2CAAoD;AACpD,kDAAqD;AACrD,gDAI2B;AAC3B,uCAA6C;AAC7C,+DAAqE;AAG9D,IAAM,gBAAgB,wBAAtB,MAAM,gBAAiB,SAAQ,0CAGrC;IAEC,YAEE,SAAiD,EAEjD,UAAyC,EACzC,MAAuB;QAEvB,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QALlB,cAAS,GAAT,SAAS,CAAqB;QAE9B,eAAU,GAAV,UAAU,CAAY;QALxB,YAAO,GAAW,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;IASvE,CAAC;CACF,CAAA;AAdY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAOR,mBAAA,IAAA,wBAAa,EAAC,6BAAY,CAAC,IAAI,CAAC,CAAA;IAEhC,mBAAA,IAAA,6BAAkB,GAAE,CAAA;6CADS,gBAAK;QAEJ,qBAAU;QACjC,2BAAe;GAVd,gBAAgB,CAc5B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiKeyGetSerialization } from './api-key.get.serialization';
|
|
2
|
+
declare const ApiKeyCreateSerialization_base: import("@nestjs/common").Type<Pick<ApiKeyGetSerialization, "key" | "_id">>;
|
|
3
|
+
export declare class ApiKeyCreateSerialization extends ApiKeyCreateSerialization_base {
|
|
4
|
+
secret: string;
|
|
5
|
+
}
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyCreateSerialization = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const api_key_get_serialization_1 = require("./api-key.get.serialization");
|
|
7
|
+
class ApiKeyCreateSerialization extends (0, swagger_1.PickType)(api_key_get_serialization_1.ApiKeyGetSerialization, ['key', '_id']) {
|
|
8
|
+
}
|
|
9
|
+
exports.ApiKeyCreateSerialization = ApiKeyCreateSerialization;
|
|
10
|
+
tslib_1.__decorate([
|
|
11
|
+
(0, swagger_1.ApiProperty)({
|
|
12
|
+
description: 'Secret key of ApiKey, only show at once',
|
|
13
|
+
example: true,
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
tslib_1.__metadata("design:type", String)
|
|
17
|
+
], ApiKeyCreateSerialization.prototype, "secret", void 0);
|
|
18
|
+
//# sourceMappingURL=api-key.create.serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.create.serialization.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/serializations/api-key.create.serialization.ts"],"names":[],"mappings":";;;;AAAA,6CAAwD;AACxD,2EAAqE;AAErE,MAAa,yBAA0B,SAAQ,IAAA,kBAAQ,EACrD,kDAAsB,EACtB,CAAC,KAAK,EAAE,KAAK,CAAU,CACxB;CAOA;AAVD,8DAUC;AADC;IALC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,yCAAyC;QACtD,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf,CAAC;;yDACa"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ResponseIdSerialization } from '@tc-libs/response';
|
|
2
|
+
export declare class ApiKeyGetSerialization extends ResponseIdSerialization {
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
key: string;
|
|
6
|
+
hash: string;
|
|
7
|
+
active: boolean;
|
|
8
|
+
startDate?: Date;
|
|
9
|
+
endDate?: Date;
|
|
10
|
+
readonly createdAt: Date;
|
|
11
|
+
readonly updatedAt: Date;
|
|
12
|
+
readonly deletedAt?: Date;
|
|
13
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyGetSerialization = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const response_1 = require("@tc-libs/response");
|
|
6
|
+
const faker_1 = require("@faker-js/faker");
|
|
7
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
8
|
+
const class_transformer_1 = require("class-transformer");
|
|
9
|
+
class ApiKeyGetSerialization extends response_1.ResponseIdSerialization {
|
|
10
|
+
}
|
|
11
|
+
exports.ApiKeyGetSerialization = ApiKeyGetSerialization;
|
|
12
|
+
tslib_1.__decorate([
|
|
13
|
+
(0, swagger_1.ApiProperty)({
|
|
14
|
+
description: 'Alias name of api key',
|
|
15
|
+
example: faker_1.faker.person.jobTitle(),
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
tslib_1.__metadata("design:type", String)
|
|
19
|
+
], ApiKeyGetSerialization.prototype, "name", void 0);
|
|
20
|
+
tslib_1.__decorate([
|
|
21
|
+
(0, swagger_1.ApiProperty)({
|
|
22
|
+
description: 'Description of api key',
|
|
23
|
+
example: 'blabla description',
|
|
24
|
+
required: false,
|
|
25
|
+
}),
|
|
26
|
+
tslib_1.__metadata("design:type", String)
|
|
27
|
+
], ApiKeyGetSerialization.prototype, "description", void 0);
|
|
28
|
+
tslib_1.__decorate([
|
|
29
|
+
(0, swagger_1.ApiProperty)({
|
|
30
|
+
description: 'Unique key of api key',
|
|
31
|
+
example: faker_1.faker.string.alpha(115),
|
|
32
|
+
required: true,
|
|
33
|
+
}),
|
|
34
|
+
tslib_1.__metadata("design:type", String)
|
|
35
|
+
], ApiKeyGetSerialization.prototype, "key", void 0);
|
|
36
|
+
tslib_1.__decorate([
|
|
37
|
+
(0, class_transformer_1.Exclude)(),
|
|
38
|
+
tslib_1.__metadata("design:type", String)
|
|
39
|
+
], ApiKeyGetSerialization.prototype, "hash", void 0);
|
|
40
|
+
tslib_1.__decorate([
|
|
41
|
+
(0, swagger_1.ApiProperty)({
|
|
42
|
+
description: 'Active flag of api key',
|
|
43
|
+
example: true,
|
|
44
|
+
required: true,
|
|
45
|
+
}),
|
|
46
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
47
|
+
], ApiKeyGetSerialization.prototype, "active", void 0);
|
|
48
|
+
tslib_1.__decorate([
|
|
49
|
+
(0, swagger_1.ApiProperty)({
|
|
50
|
+
description: 'Api Key start date',
|
|
51
|
+
example: faker_1.faker.date.recent(),
|
|
52
|
+
required: false,
|
|
53
|
+
nullable: true,
|
|
54
|
+
}),
|
|
55
|
+
tslib_1.__metadata("design:type", Date)
|
|
56
|
+
], ApiKeyGetSerialization.prototype, "startDate", void 0);
|
|
57
|
+
tslib_1.__decorate([
|
|
58
|
+
(0, swagger_1.ApiProperty)({
|
|
59
|
+
description: 'Api Key end date',
|
|
60
|
+
example: faker_1.faker.date.recent(),
|
|
61
|
+
required: false,
|
|
62
|
+
nullable: true,
|
|
63
|
+
}),
|
|
64
|
+
tslib_1.__metadata("design:type", Date)
|
|
65
|
+
], ApiKeyGetSerialization.prototype, "endDate", void 0);
|
|
66
|
+
tslib_1.__decorate([
|
|
67
|
+
(0, swagger_1.ApiProperty)({
|
|
68
|
+
description: 'Date created at',
|
|
69
|
+
example: faker_1.faker.date.recent(),
|
|
70
|
+
required: false,
|
|
71
|
+
}),
|
|
72
|
+
tslib_1.__metadata("design:type", Date)
|
|
73
|
+
], ApiKeyGetSerialization.prototype, "createdAt", void 0);
|
|
74
|
+
tslib_1.__decorate([
|
|
75
|
+
(0, swagger_1.ApiProperty)({
|
|
76
|
+
description: 'Date updated at',
|
|
77
|
+
example: faker_1.faker.date.recent(),
|
|
78
|
+
required: false,
|
|
79
|
+
}),
|
|
80
|
+
tslib_1.__metadata("design:type", Date)
|
|
81
|
+
], ApiKeyGetSerialization.prototype, "updatedAt", void 0);
|
|
82
|
+
tslib_1.__decorate([
|
|
83
|
+
(0, class_transformer_1.Exclude)(),
|
|
84
|
+
tslib_1.__metadata("design:type", Date)
|
|
85
|
+
], ApiKeyGetSerialization.prototype, "deletedAt", void 0);
|
|
86
|
+
//# sourceMappingURL=api-key.get.serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.get.serialization.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/serializations/api-key.get.serialization.ts"],"names":[],"mappings":";;;;AAAA,gDAA4D;AAC5D,2CAAwC;AACxC,6CAA8C;AAC9C,yDAA4C;AAE5C,MAAa,sBAAuB,SAAQ,kCAAuB;CAgElE;AAhED,wDAgEC;AA1DC;IALC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,uBAAuB;QACpC,OAAO,EAAE,aAAK,CAAC,MAAM,CAAC,QAAQ,EAAE;QAChC,QAAQ,EAAE,IAAI;KACf,CAAC;;oDACW;AAOb;IALC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,wBAAwB;QACrC,OAAO,EAAE,oBAAoB;QAC7B,QAAQ,EAAE,KAAK;KAChB,CAAC;;2DACmB;AAOrB;IALC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,uBAAuB;QACpC,OAAO,EAAE,aAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;QAChC,QAAQ,EAAE,IAAI;KACf,CAAC;;mDACU;AAGZ;IADC,IAAA,2BAAO,GAAE;;oDACG;AAOb;IALC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,wBAAwB;QACrC,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf,CAAC;;sDACc;AAQhB;IANC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,oBAAoB;QACjC,OAAO,EAAE,aAAK,CAAC,IAAI,CAAC,MAAM,EAAE;QAC5B,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,IAAI;KACf,CAAC;sCACU,IAAI;yDAAC;AAQjB;IANC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,kBAAkB;QAC/B,OAAO,EAAE,aAAK,CAAC,IAAI,CAAC,MAAM,EAAE;QAC5B,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,IAAI;KACf,CAAC;sCACQ,IAAI;uDAAC;AAON;IALR,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,iBAAiB;QAC9B,OAAO,EAAE,aAAK,CAAC,IAAI,CAAC,MAAM,EAAE;QAC5B,QAAQ,EAAE,KAAK;KAChB,CAAC;sCACkB,IAAI;yDAAC;AAOhB;IALR,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,iBAAiB;QAC9B,OAAO,EAAE,aAAK,CAAC,IAAI,CAAC,MAAM,EAAE;QAC5B,QAAQ,EAAE,KAAK;KAChB,CAAC;sCACkB,IAAI;yDAAC;AAGhB;IADR,IAAA,2BAAO,GAAE;sCACW,IAAI;yDAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApiKeyGetSerialization } from './api-key.get.serialization';
|
|
2
|
+
declare const ApiKeyListSerialization_base: import("@nestjs/common").Type<Omit<ApiKeyGetSerialization, "description">>;
|
|
3
|
+
export declare class ApiKeyListSerialization extends ApiKeyListSerialization_base {
|
|
4
|
+
}
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyListSerialization = void 0;
|
|
4
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
5
|
+
const api_key_get_serialization_1 = require("./api-key.get.serialization");
|
|
6
|
+
class ApiKeyListSerialization extends (0, swagger_1.OmitType)(api_key_get_serialization_1.ApiKeyGetSerialization, [
|
|
7
|
+
'description',
|
|
8
|
+
]) {
|
|
9
|
+
}
|
|
10
|
+
exports.ApiKeyListSerialization = ApiKeyListSerialization;
|
|
11
|
+
//# sourceMappingURL=api-key.list.serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.list.serialization.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/serializations/api-key.list.serialization.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,2EAAqE;AAErE,MAAa,uBAAwB,SAAQ,IAAA,kBAAQ,EAAC,kDAAsB,EAAE;IAC5E,aAAa;CACL,CAAC;CAAG;AAFd,0DAEc"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyResetSerialization = void 0;
|
|
4
|
+
const api_key_create_serialization_1 = require("./api-key.create.serialization");
|
|
5
|
+
class ApiKeyResetSerialization extends api_key_create_serialization_1.ApiKeyCreateSerialization {
|
|
6
|
+
}
|
|
7
|
+
exports.ApiKeyResetSerialization = ApiKeyResetSerialization;
|
|
8
|
+
//# sourceMappingURL=api-key.reset.serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.reset.serialization.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/serializations/api-key.reset.serialization.ts"],"names":[],"mappings":";;;AAAA,iFAA2E;AAE3E,MAAa,wBAAyB,SAAQ,wDAAyB;CAAG;AAA1E,4DAA0E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./api-key.create.serialization"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./api-key.get.serialization"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./api-key.list.serialization"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./api-key.reset.serialization"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/serializations/index.ts"],"names":[],"mappings":";;;AAAA,yEAA+C;AAC/C,sEAA4C;AAC5C,uEAA6C;AAC7C,wEAA8C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AbstractService } from '@tc-libs/service';
|
|
2
|
+
import { Logger } from '@nestjs/common';
|
|
3
|
+
import { ApiKeyDoc, ApiKeyEntity, ApiKeyRepository } from '../repository';
|
|
4
|
+
import { IDatabaseFindOneOptions, IDatabaseExistOptions, IDatabaseManyOptions, IDatabaseCreateOptions } from '@tc-libs/database';
|
|
5
|
+
import { ApiKeyCreateDto, ApiKeyCreateRawDto, ApiKeyUpdateDateDto, ApiKeyUpdateDto } from '../dtos';
|
|
6
|
+
import { IApiKeyCreated } from '../interfaces';
|
|
7
|
+
import { PaginationService } from '@tc-libs/pagination';
|
|
8
|
+
import { StringService, DateService, HashService } from '@tc-libs/helper';
|
|
9
|
+
export declare class ApiKeyService extends AbstractService<ApiKeyEntity, ApiKeyDoc> {
|
|
10
|
+
protected readonly _paging: PaginationService;
|
|
11
|
+
private readonly helperStringService;
|
|
12
|
+
private readonly helperDateService;
|
|
13
|
+
private readonly _apiKey;
|
|
14
|
+
private readonly _hash;
|
|
15
|
+
private readonly env;
|
|
16
|
+
readonly logger: Logger;
|
|
17
|
+
readonly maxTokenPerUser = 5;
|
|
18
|
+
constructor(_paging: PaginationService, helperStringService: StringService, helperDateService: DateService, _apiKey: ApiKeyRepository, _hash: HashService);
|
|
19
|
+
checkIfUserIsCapped(user: string, options?: IDatabaseExistOptions): Promise<boolean>;
|
|
20
|
+
updateDate(repository: ApiKeyDoc, { startDate, endDate }: ApiKeyUpdateDateDto): Promise<ApiKeyDoc>;
|
|
21
|
+
findOneByKey(key: string, options?: IDatabaseFindOneOptions): Promise<ApiKeyDoc>;
|
|
22
|
+
findOneByActiveKey(key: string): Promise<ApiKeyDoc>;
|
|
23
|
+
createByUserId(user: string, env: string, { name, description, startDate, endDate }: ApiKeyCreateDto, options?: IDatabaseCreateOptions): Promise<IApiKeyCreated>;
|
|
24
|
+
createRaw(user: string, { name, description, key, secret, startDate, endDate }: ApiKeyCreateRawDto, options?: IDatabaseCreateOptions): Promise<IApiKeyCreated>;
|
|
25
|
+
active(repository: ApiKeyDoc): Promise<ApiKeyDoc>;
|
|
26
|
+
inactive(repository: ApiKeyDoc): Promise<ApiKeyDoc>;
|
|
27
|
+
reset(repository: ApiKeyDoc, secret: string): Promise<ApiKeyDoc>;
|
|
28
|
+
validateHashApiKey(plainHeader: string, hash: string): Promise<boolean>;
|
|
29
|
+
createKey(env: string): Promise<string>;
|
|
30
|
+
createSecret(): Promise<string>;
|
|
31
|
+
createHashApiKey(key: string, secret: string): Promise<string>;
|
|
32
|
+
update(repository: ApiKeyDoc, { name, description }: ApiKeyUpdateDto): Promise<ApiKeyDoc>;
|
|
33
|
+
inactiveManyByEndDate(options?: IDatabaseManyOptions): Promise<boolean>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var ApiKeyService_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ApiKeyService = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const service_1 = require("@tc-libs/service");
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const repository_1 = require("../repository");
|
|
9
|
+
const pagination_1 = require("@tc-libs/pagination");
|
|
10
|
+
const helper_1 = require("@tc-libs/helper");
|
|
11
|
+
const authentication_1 = require("@tc-libs/authentication");
|
|
12
|
+
let ApiKeyService = ApiKeyService_1 = class ApiKeyService extends service_1.AbstractService {
|
|
13
|
+
constructor(_paging, helperStringService, helperDateService, _apiKey, _hash) {
|
|
14
|
+
super(_apiKey, _paging);
|
|
15
|
+
this._paging = _paging;
|
|
16
|
+
this.helperStringService = helperStringService;
|
|
17
|
+
this.helperDateService = helperDateService;
|
|
18
|
+
this._apiKey = _apiKey;
|
|
19
|
+
this._hash = _hash;
|
|
20
|
+
this.logger = new common_1.Logger(ApiKeyService_1.name);
|
|
21
|
+
this.maxTokenPerUser = 5;
|
|
22
|
+
}
|
|
23
|
+
async checkIfUserIsCapped(user, options) {
|
|
24
|
+
return ((await this._apiKey.count({
|
|
25
|
+
user,
|
|
26
|
+
}, options)) >= this.maxTokenPerUser);
|
|
27
|
+
}
|
|
28
|
+
async updateDate(repository, { startDate, endDate }) {
|
|
29
|
+
repository.startDate = this.helperDateService.startOfDay(startDate);
|
|
30
|
+
repository.endDate = this.helperDateService.endOfDay(endDate);
|
|
31
|
+
return this._apiKey.save(repository);
|
|
32
|
+
}
|
|
33
|
+
async findOneByKey(key, options) {
|
|
34
|
+
return this._apiKey.findOne({ key }, options);
|
|
35
|
+
}
|
|
36
|
+
async findOneByActiveKey(key) {
|
|
37
|
+
return this._apiKey.findOne({
|
|
38
|
+
key,
|
|
39
|
+
active: true,
|
|
40
|
+
}, {
|
|
41
|
+
returnPlain: true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async createByUserId(user, env, { name, description, startDate, endDate }, options) {
|
|
45
|
+
const key = await this.createKey(env);
|
|
46
|
+
const secret = await this.createSecret();
|
|
47
|
+
const hash = await this.createHashApiKey(key, secret);
|
|
48
|
+
const dto = new repository_1.ApiKeyEntity();
|
|
49
|
+
dto.user = user;
|
|
50
|
+
dto.name = name;
|
|
51
|
+
dto.description = description;
|
|
52
|
+
dto.key = key;
|
|
53
|
+
dto.hash = hash;
|
|
54
|
+
dto.active = true;
|
|
55
|
+
dto.accessFor = authentication_1.ENUM_AUTH_ACCESS_FOR.USER;
|
|
56
|
+
if (startDate && endDate) {
|
|
57
|
+
dto.startDate = this.helperDateService.startOfDay(startDate);
|
|
58
|
+
dto.endDate = this.helperDateService.endOfDay(endDate);
|
|
59
|
+
}
|
|
60
|
+
const created = await this._apiKey.create(dto, options);
|
|
61
|
+
return { doc: created, secret };
|
|
62
|
+
}
|
|
63
|
+
async createRaw(user, { name, description, key, secret, startDate, endDate }, options) {
|
|
64
|
+
const hash = await this.createHashApiKey(key, secret);
|
|
65
|
+
const dto = new repository_1.ApiKeyEntity();
|
|
66
|
+
dto.name = name;
|
|
67
|
+
dto.user = user;
|
|
68
|
+
dto.description = description;
|
|
69
|
+
dto.key = key;
|
|
70
|
+
dto.hash = hash;
|
|
71
|
+
dto.active = true;
|
|
72
|
+
if (startDate && endDate) {
|
|
73
|
+
dto.startDate = this.helperDateService.startOfDay(startDate);
|
|
74
|
+
dto.endDate = this.helperDateService.endOfDay(endDate);
|
|
75
|
+
}
|
|
76
|
+
const created = await this._apiKey.create(dto, options);
|
|
77
|
+
return { doc: created, secret };
|
|
78
|
+
}
|
|
79
|
+
async active(repository) {
|
|
80
|
+
repository.active = true;
|
|
81
|
+
return this._apiKey.save(repository);
|
|
82
|
+
}
|
|
83
|
+
async inactive(repository) {
|
|
84
|
+
repository.active = false;
|
|
85
|
+
return this._apiKey.save(repository);
|
|
86
|
+
}
|
|
87
|
+
async reset(repository, secret) {
|
|
88
|
+
const hash = await this.createHashApiKey(repository.key, secret);
|
|
89
|
+
repository.hash = hash;
|
|
90
|
+
return this._apiKey.save(repository);
|
|
91
|
+
}
|
|
92
|
+
async validateHashApiKey(plainHeader, hash) {
|
|
93
|
+
return this._hash.sha256(plainHeader) === hash;
|
|
94
|
+
}
|
|
95
|
+
async createKey(env) {
|
|
96
|
+
return this.helperStringService.random(25, {
|
|
97
|
+
safe: false,
|
|
98
|
+
upperCase: true,
|
|
99
|
+
prefix: `${env}_`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async createSecret() {
|
|
103
|
+
return this.helperStringService.random(35, {
|
|
104
|
+
safe: false,
|
|
105
|
+
upperCase: true,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async createHashApiKey(key, secret) {
|
|
109
|
+
return this._hash.sha256(`${key}:${secret}`);
|
|
110
|
+
}
|
|
111
|
+
async update(repository, { name, description }) {
|
|
112
|
+
repository.name = name;
|
|
113
|
+
repository.description = description;
|
|
114
|
+
return this._apiKey.save(repository);
|
|
115
|
+
}
|
|
116
|
+
async inactiveManyByEndDate(options) {
|
|
117
|
+
return this._apiKey.updateMany({
|
|
118
|
+
endDate: {
|
|
119
|
+
$lte: this.helperDateService.create(),
|
|
120
|
+
},
|
|
121
|
+
active: true,
|
|
122
|
+
}, {
|
|
123
|
+
active: false,
|
|
124
|
+
}, options);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
exports.ApiKeyService = ApiKeyService;
|
|
128
|
+
exports.ApiKeyService = ApiKeyService = ApiKeyService_1 = tslib_1.__decorate([
|
|
129
|
+
(0, common_1.Injectable)(),
|
|
130
|
+
tslib_1.__metadata("design:paramtypes", [pagination_1.PaginationService,
|
|
131
|
+
helper_1.StringService,
|
|
132
|
+
helper_1.DateService,
|
|
133
|
+
repository_1.ApiKeyRepository,
|
|
134
|
+
helper_1.HashService])
|
|
135
|
+
], ApiKeyService);
|
|
136
|
+
//# sourceMappingURL=api-key.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.service.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/services/api-key.service.ts"],"names":[],"mappings":";;;;;AAAA,8CAAmD;AACnD,2CAAoD;AACpD,8CAA0E;AAe1E,oDAAwD;AACxD,4CAA0E;AAC1E,4DAA+D;AAGxD,IAAM,aAAa,qBAAnB,MAAM,aAAc,SAAQ,yBAAwC;IAKzE,YACqB,OAA0B,EAC5B,mBAAkC,EAClC,iBAA8B,EAC9B,OAAyB,EACzB,KAAkB;QAEnC,KAAK,CAAC,OAAO,EAA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AC;CACF,CAAA;AA9LY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;6CAOmB,8BAAiB;QACP,sBAAa;QACf,oBAAW;QACrB,6BAAgB;QAClB,oBAAW;GAV1B,aAAa,CA8LzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './api-key.service';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/services/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyInactiveTask = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const schedule_1 = require("@nestjs/schedule");
|
|
7
|
+
const services_1 = require("../services");
|
|
8
|
+
let ApiKeyInactiveTask = class ApiKeyInactiveTask {
|
|
9
|
+
constructor(apiKeyService) {
|
|
10
|
+
this.apiKeyService = apiKeyService;
|
|
11
|
+
}
|
|
12
|
+
async inactiveApiKey() {
|
|
13
|
+
try {
|
|
14
|
+
await this.apiKeyService.inactiveManyByEndDate();
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
throw new Error(err.message);
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.ApiKeyInactiveTask = ApiKeyInactiveTask;
|
|
23
|
+
tslib_1.__decorate([
|
|
24
|
+
(0, schedule_1.Cron)(schedule_1.CronExpression.EVERY_DAY_AT_MIDNIGHT, {
|
|
25
|
+
name: 'inactiveApiKey',
|
|
26
|
+
}),
|
|
27
|
+
tslib_1.__metadata("design:type", Function),
|
|
28
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
29
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
30
|
+
], ApiKeyInactiveTask.prototype, "inactiveApiKey", null);
|
|
31
|
+
exports.ApiKeyInactiveTask = ApiKeyInactiveTask = tslib_1.__decorate([
|
|
32
|
+
(0, common_1.Injectable)(),
|
|
33
|
+
tslib_1.__metadata("design:paramtypes", [services_1.ApiKeyService])
|
|
34
|
+
], ApiKeyInactiveTask);
|
|
35
|
+
//# sourceMappingURL=api-key.inactive.task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.inactive.task.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/tasks/api-key.inactive.task.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAC5C,+CAAwD;AACxD,0CAA4C;AAGrC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAKvD,AAAN,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,aAAa,CAAC,qBAAqB,EAAE,CAAC;QACnD,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO;IACT,CAAC;CACF,CAAA;AAfY,gDAAkB;AAMvB;IAHL,IAAA,eAAI,EAAC,yBAAc,CAAC,qBAAqB,EAAE;QAC1C,IAAI,EAAE,gBAAgB;KACvB,CAAC;;;;wDASD;6BAdU,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;6CAEiC,wBAAa;GAD9C,kBAAkB,CAe9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './api-key.inactive.task';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/api-key/src/tasks/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC"}
|