nestjs-apikey-module 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/api-key.module.d.ts +6 -0
- package/dist/api-key.module.js +57 -0
- package/dist/api-key.module.js.map +1 -0
- package/dist/config/enum.d.ts +5 -0
- package/dist/config/enum.js +10 -0
- package/dist/config/enum.js.map +1 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.js +7 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/decorators/api-key-actions.decorator.d.ts +2 -0
- package/dist/decorators/api-key-actions.decorator.js +8 -0
- package/dist/decorators/api-key-actions.decorator.js.map +1 -0
- package/dist/decorators/api-key-session.decorator.d.ts +1 -0
- package/dist/decorators/api-key-session.decorator.js +9 -0
- package/dist/decorators/api-key-session.decorator.js.map +1 -0
- package/dist/entities/api-key-action.entity.d.ts +7 -0
- package/dist/entities/api-key-action.entity.js +41 -0
- package/dist/entities/api-key-action.entity.js.map +1 -0
- package/dist/entities/api-key.entity.d.ts +17 -0
- package/dist/entities/api-key.entity.js +82 -0
- package/dist/entities/api-key.entity.js.map +1 -0
- package/dist/guards/api-key-strategy.guard.d.ts +10 -0
- package/dist/guards/api-key-strategy.guard.js +35 -0
- package/dist/guards/api-key-strategy.guard.js.map +1 -0
- package/dist/guards/api-key.guard.d.ts +9 -0
- package/dist/guards/api-key.guard.js +48 -0
- package/dist/guards/api-key.guard.js.map +1 -0
- package/dist/helpers/api-key-actions.helper.d.ts +2 -0
- package/dist/helpers/api-key-actions.helper.js +15 -0
- package/dist/helpers/api-key-actions.helper.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/api-key-context.interface.d.ts +5 -0
- package/dist/interfaces/api-key-context.interface.js +3 -0
- package/dist/interfaces/api-key-context.interface.js.map +1 -0
- package/dist/interfaces/api-key.interfaces.d.ts +30 -0
- package/dist/interfaces/api-key.interfaces.js +3 -0
- package/dist/interfaces/api-key.interfaces.js.map +1 -0
- package/dist/services/api-key.service.d.ts +21 -0
- package/dist/services/api-key.service.js +171 -0
- package/dist/services/api-key.service.js.map +1 -0
- package/dist/tasks/api-key-expiry.task.d.ts +13 -0
- package/dist/tasks/api-key-expiry.task.js +65 -0
- package/dist/tasks/api-key-expiry.task.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/utils/expiry.util.d.ts +1 -0
- package/dist/utils/expiry.util.js +8 -0
- package/dist/utils/expiry.util.js.map +1 -0
- package/dist/utils/key.util.d.ts +1 -0
- package/dist/utils/key.util.js +8 -0
- package/dist/utils/key.util.js.map +1 -0
- package/dist/utils/secret.util.d.ts +2 -0
- package/dist/utils/secret.util.js +13 -0
- package/dist/utils/secret.util.js.map +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# nestjs-apikey-module
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { IApiKeyModuleAsyncOptions, IApiKeyModuleOptions } from "./interfaces/api-key.interfaces";
|
|
3
|
+
export declare class ApiKeyModule {
|
|
4
|
+
static forRoot(options?: IApiKeyModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: IApiKeyModuleAsyncOptions): DynamicModule;
|
|
6
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 ApiKeyModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ApiKeyModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
13
|
+
const schedule_1 = require("@nestjs/schedule");
|
|
14
|
+
const api_key_entity_1 = require("./entities/api-key.entity");
|
|
15
|
+
const api_key_action_entity_1 = require("./entities/api-key-action.entity");
|
|
16
|
+
const api_key_service_1 = require("./services/api-key.service");
|
|
17
|
+
const api_key_expiry_task_1 = require("./tasks/api-key-expiry.task");
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
const TYPEORM_FEATURE = typeorm_1.TypeOrmModule.forFeature([
|
|
20
|
+
api_key_entity_1.ApiKeyEntity,
|
|
21
|
+
api_key_action_entity_1.ApiKeyActionEntity,
|
|
22
|
+
]);
|
|
23
|
+
let ApiKeyModule = ApiKeyModule_1 = class ApiKeyModule {
|
|
24
|
+
static forRoot(options = {}) {
|
|
25
|
+
return {
|
|
26
|
+
module: ApiKeyModule_1,
|
|
27
|
+
imports: [TYPEORM_FEATURE, schedule_1.ScheduleModule.forRoot()],
|
|
28
|
+
providers: [
|
|
29
|
+
{ provide: constants_1.API_KEY_MODULE_OPTIONS, useValue: options },
|
|
30
|
+
api_key_service_1.ApiKeyService,
|
|
31
|
+
api_key_expiry_task_1.ApiKeyExpiryTask,
|
|
32
|
+
],
|
|
33
|
+
exports: [api_key_service_1.ApiKeyService],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
static forRootAsync(options) {
|
|
37
|
+
return {
|
|
38
|
+
module: ApiKeyModule_1,
|
|
39
|
+
imports: [...(options.imports ?? []), TYPEORM_FEATURE, schedule_1.ScheduleModule.forRoot()],
|
|
40
|
+
providers: [
|
|
41
|
+
{
|
|
42
|
+
provide: constants_1.API_KEY_MODULE_OPTIONS,
|
|
43
|
+
useFactory: options.useFactory,
|
|
44
|
+
inject: options.inject ?? [],
|
|
45
|
+
},
|
|
46
|
+
api_key_service_1.ApiKeyService,
|
|
47
|
+
api_key_expiry_task_1.ApiKeyExpiryTask,
|
|
48
|
+
],
|
|
49
|
+
exports: [api_key_service_1.ApiKeyService],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.ApiKeyModule = ApiKeyModule;
|
|
54
|
+
exports.ApiKeyModule = ApiKeyModule = ApiKeyModule_1 = __decorate([
|
|
55
|
+
(0, common_1.Module)({})
|
|
56
|
+
], ApiKeyModule);
|
|
57
|
+
//# sourceMappingURL=api-key.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.module.js","sourceRoot":"","sources":["../libs/nestjs-apikey-module/src/api-key.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,6CAAgD;AAChD,+CAAkD;AAClD,8DAAyD;AACzD,4EAAsE;AACtE,gEAA2D;AAC3D,qEAA+D;AAK/D,2CAAqD;AAErD,MAAM,eAAe,GAAG,uBAAa,CAAC,UAAU,CAAC;IAC/C,6BAAY;IACZ,0CAAkB;CACnB,CAAC,CAAC;AAGI,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAOvB,MAAM,CAAC,OAAO,CAAC,UAAgC,EAAE;QAC/C,OAAO;YACL,MAAM,EAAE,cAAY;YACpB,OAAO,EAAE,CAAC,eAAe,EAAE,yBAAc,CAAC,OAAO,EAAE,CAAC;YACpD,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,kCAAsB,EAAE,QAAQ,EAAE,OAAO,EAAE;gBACtD,+BAAa;gBACb,sCAAgB;aACjB;YACD,OAAO,EAAE,CAAC,+BAAa,CAAC;SACzB,CAAC;IACJ,CAAC;IAeD,MAAM,CAAC,YAAY,CAAC,OAAkC;QACpD,OAAO;YACL,MAAM,EAAE,cAAY;YACpB,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,eAAe,EAAE,yBAAc,CAAC,OAAO,EAAE,CAAC;YAChF,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,kCAAsB;oBAC/B,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;iBAC7B;gBACD,+BAAa;gBACb,sCAAgB;aACjB;YACD,OAAO,EAAE,CAAC,+BAAa,CAAC;SACzB,CAAC;IACJ,CAAC;CACF,CAAA;AAjDY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,YAAY,CAiDxB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_KEY_STATUS = void 0;
|
|
4
|
+
var API_KEY_STATUS;
|
|
5
|
+
(function (API_KEY_STATUS) {
|
|
6
|
+
API_KEY_STATUS["ACTIVE"] = "ACTIVE";
|
|
7
|
+
API_KEY_STATUS["REVOKED"] = "REVOKED";
|
|
8
|
+
API_KEY_STATUS["EXPIRED"] = "EXPIRED";
|
|
9
|
+
})(API_KEY_STATUS || (exports.API_KEY_STATUS = API_KEY_STATUS = {}));
|
|
10
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/config/enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;AACrB,CAAC,EAJW,cAAc,8BAAd,cAAc,QAIzB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_KEY_SESSION_KEY = exports.API_KEY_ACTIONS_KEY = exports.API_KEY_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.API_KEY_MODULE_OPTIONS = "API_KEY_MODULE_OPTIONS";
|
|
5
|
+
exports.API_KEY_ACTIONS_KEY = "api_key_actions";
|
|
6
|
+
exports.API_KEY_SESSION_KEY = "apiKeySession";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAClD,QAAA,mBAAmB,GAAG,iBAAiB,CAAC;AACxC,QAAA,mBAAmB,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyActions = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const ApiKeyActions = (...rules) => (0, common_1.SetMetadata)(constants_1.API_KEY_ACTIONS_KEY, rules);
|
|
7
|
+
exports.ApiKeyActions = ApiKeyActions;
|
|
8
|
+
//# sourceMappingURL=api-key-actions.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-actions.decorator.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/decorators/api-key-actions.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,4CAAmD;AAe5C,MAAM,aAAa,GAAG,CAAC,GAAG,KAAyB,EAAE,EAAE,CAC5D,IAAA,oBAAW,EAAC,+BAAmB,EAAE,KAAK,CAAC,CAAC;AAD7B,QAAA,aAAa,iBACgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ApiKeySession: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeySession = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
exports.ApiKeySession = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
7
|
+
return ctx.switchToHttp().getRequest()[constants_1.API_KEY_SESSION_KEY] ?? null;
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=api-key-session.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-session.decorator.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/decorators/api-key-session.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AACxE,4CAAmD;AAStC,QAAA,aAAa,GAAG,IAAA,6BAAoB,EAC/C,CAAC,KAAc,EAAE,GAAqB,EAAE,EAAE;IACxC,OAAO,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC,+BAAmB,CAAC,IAAI,IAAI,CAAC;AACtE,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
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.ApiKeyActionEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const api_key_entity_1 = require("./api-key.entity");
|
|
15
|
+
let ApiKeyActionEntity = class ApiKeyActionEntity {
|
|
16
|
+
};
|
|
17
|
+
exports.ApiKeyActionEntity = ApiKeyActionEntity;
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
20
|
+
__metadata("design:type", Number)
|
|
21
|
+
], ApiKeyActionEntity.prototype, "id", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, typeorm_1.Column)({ name: "action_code", length: 100 }),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], ApiKeyActionEntity.prototype, "actionCode", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, typeorm_1.CreateDateColumn)({ name: "created_at" }),
|
|
28
|
+
__metadata("design:type", Date)
|
|
29
|
+
], ApiKeyActionEntity.prototype, "createdAt", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, typeorm_1.ManyToOne)(() => api_key_entity_1.ApiKeyEntity, (apiKey) => apiKey.actions, {
|
|
32
|
+
nullable: false,
|
|
33
|
+
onDelete: "CASCADE",
|
|
34
|
+
}),
|
|
35
|
+
(0, typeorm_1.JoinColumn)({ name: "api_key_id" }),
|
|
36
|
+
__metadata("design:type", api_key_entity_1.ApiKeyEntity)
|
|
37
|
+
], ApiKeyActionEntity.prototype, "apiKey", void 0);
|
|
38
|
+
exports.ApiKeyActionEntity = ApiKeyActionEntity = __decorate([
|
|
39
|
+
(0, typeorm_1.Entity)("api_key_actions")
|
|
40
|
+
], ApiKeyActionEntity);
|
|
41
|
+
//# sourceMappingURL=api-key-action.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-action.entity.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/entities/api-key-action.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAOiB;AACjB,qDAAgD;AAGzC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAgB9B,CAAA;AAhBY,gDAAkB;AAE7B;IADC,IAAA,gCAAsB,GAAE;;8CACd;AAGX;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;sDAC1B;AAGnB;IADC,IAAA,0BAAgB,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;8BAC9B,IAAI;qDAAC;AAOhB;IALC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,6BAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;QACzD,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,SAAS;KACpB,CAAC;IACD,IAAA,oBAAU,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;8BAC3B,6BAAY;kDAAC;6BAfV,kBAAkB;IAD9B,IAAA,gBAAM,EAAC,iBAAiB,CAAC;GACb,kBAAkB,CAgB9B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { API_KEY_STATUS } from "../config/enum";
|
|
2
|
+
import { ApiKeyActionEntity } from "./api-key-action.entity";
|
|
3
|
+
export declare class ApiKeyEntity {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
keyPrefix: string;
|
|
7
|
+
secretHash: string;
|
|
8
|
+
secretLast4: string;
|
|
9
|
+
status: API_KEY_STATUS;
|
|
10
|
+
expiresAt: Date | null;
|
|
11
|
+
lastUsedAt: Date | null;
|
|
12
|
+
lastUsedIp: string | null;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
revokedAt: Date | null;
|
|
15
|
+
revokeReason: string | null;
|
|
16
|
+
actions: ApiKeyActionEntity[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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.ApiKeyEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const enum_1 = require("../config/enum");
|
|
15
|
+
const api_key_action_entity_1 = require("./api-key-action.entity");
|
|
16
|
+
let ApiKeyEntity = class ApiKeyEntity {
|
|
17
|
+
};
|
|
18
|
+
exports.ApiKeyEntity = ApiKeyEntity;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, typeorm_1.PrimaryGeneratedColumn)("uuid"),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], ApiKeyEntity.prototype, "id", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, typeorm_1.Column)({ name: "name", length: 100 }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], ApiKeyEntity.prototype, "name", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, typeorm_1.Column)({ name: "key_prefix", length: 30, unique: true }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], ApiKeyEntity.prototype, "keyPrefix", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, typeorm_1.Column)({ name: "secret_hash", length: 255 }),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], ApiKeyEntity.prototype, "secretHash", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, typeorm_1.Column)({ name: "secret_last4", length: 4 }),
|
|
37
|
+
__metadata("design:type", String)
|
|
38
|
+
], ApiKeyEntity.prototype, "secretLast4", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, typeorm_1.Column)({
|
|
41
|
+
name: "status",
|
|
42
|
+
type: "enum",
|
|
43
|
+
enum: enum_1.API_KEY_STATUS,
|
|
44
|
+
default: enum_1.API_KEY_STATUS.ACTIVE,
|
|
45
|
+
}),
|
|
46
|
+
__metadata("design:type", String)
|
|
47
|
+
], ApiKeyEntity.prototype, "status", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, typeorm_1.Column)({ name: "expires_at", type: "datetime", nullable: true }),
|
|
50
|
+
__metadata("design:type", Date)
|
|
51
|
+
], ApiKeyEntity.prototype, "expiresAt", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, typeorm_1.Column)({ name: "last_used_at", type: "datetime", nullable: true }),
|
|
54
|
+
__metadata("design:type", Date)
|
|
55
|
+
], ApiKeyEntity.prototype, "lastUsedAt", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, typeorm_1.Column)({ name: "last_used_ip", length: 45, nullable: true }),
|
|
58
|
+
__metadata("design:type", String)
|
|
59
|
+
], ApiKeyEntity.prototype, "lastUsedIp", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, typeorm_1.CreateDateColumn)({ name: "created_at" }),
|
|
62
|
+
__metadata("design:type", Date)
|
|
63
|
+
], ApiKeyEntity.prototype, "createdAt", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, typeorm_1.Column)({ name: "revoked_at", type: "datetime", nullable: true }),
|
|
66
|
+
__metadata("design:type", Date)
|
|
67
|
+
], ApiKeyEntity.prototype, "revokedAt", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, typeorm_1.Column)({ name: "revoke_reason", length: 255, nullable: true }),
|
|
70
|
+
__metadata("design:type", String)
|
|
71
|
+
], ApiKeyEntity.prototype, "revokeReason", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, typeorm_1.OneToMany)(() => api_key_action_entity_1.ApiKeyActionEntity, (action) => action.apiKey, {
|
|
74
|
+
cascade: true,
|
|
75
|
+
eager: false,
|
|
76
|
+
}),
|
|
77
|
+
__metadata("design:type", Array)
|
|
78
|
+
], ApiKeyEntity.prototype, "actions", void 0);
|
|
79
|
+
exports.ApiKeyEntity = ApiKeyEntity = __decorate([
|
|
80
|
+
(0, typeorm_1.Entity)("api_keys")
|
|
81
|
+
], ApiKeyEntity);
|
|
82
|
+
//# sourceMappingURL=api-key.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.entity.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/entities/api-key.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAMiB;AACjB,yCAAgD;AAChD,mEAA6D;AAGtD,IAAM,YAAY,GAAlB,MAAM,YAAY;CA+CxB,CAAA;AA/CY,oCAAY;AAEvB;IADC,IAAA,gCAAsB,EAAC,MAAM,CAAC;;wCACpB;AAGX;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;0CACzB;AAGb;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;+CACvC;AAGlB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;gDAC1B;AAGnB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;;iDACxB;AAQpB;IANC,IAAA,gBAAM,EAAC;QACN,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,qBAAc;QACpB,OAAO,EAAE,qBAAc,CAAC,MAAM;KAC/B,CAAC;;4CACqB;AAGvB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8BACtD,IAAI;+CAAQ;AAGvB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8BACvD,IAAI;gDAAQ;AAGxB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACnC;AAG1B;IADC,IAAA,0BAAgB,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;8BAC9B,IAAI;+CAAC;AAGhB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8BACtD,IAAI;+CAAQ;AAGvB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;kDACnC;AAM5B;IAJC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,0CAAkB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;QAC9D,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,KAAK;KACb,CAAC;;6CAC4B;uBA9CnB,YAAY;IADxB,IAAA,gBAAM,EAAC,UAAU,CAAC;GACN,YAAY,CA+CxB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
3
|
+
import { ApiKeyGuard } from "./api-key.guard";
|
|
4
|
+
import { ApiKeyService } from "../services/api-key.service";
|
|
5
|
+
import { ApiKeyEntity } from "../entities/api-key.entity";
|
|
6
|
+
export declare abstract class ApiKeyStrategyGuard extends ApiKeyGuard {
|
|
7
|
+
constructor(apiKeyService: ApiKeyService, reflector: Reflector);
|
|
8
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
9
|
+
abstract resolve(apiKey: ApiKeyEntity, request: any): Promise<unknown>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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.ApiKeyStrategyGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const api_key_guard_1 = require("./api-key.guard");
|
|
16
|
+
const api_key_service_1 = require("../services/api-key.service");
|
|
17
|
+
const constants_1 = require("../constants");
|
|
18
|
+
let ApiKeyStrategyGuard = class ApiKeyStrategyGuard extends api_key_guard_1.ApiKeyGuard {
|
|
19
|
+
constructor(apiKeyService, reflector) {
|
|
20
|
+
super(apiKeyService, reflector);
|
|
21
|
+
}
|
|
22
|
+
async canActivate(context) {
|
|
23
|
+
await super.canActivate(context);
|
|
24
|
+
const request = context.switchToHttp().getRequest();
|
|
25
|
+
const apiKey = request[constants_1.API_KEY_SESSION_KEY];
|
|
26
|
+
request[constants_1.API_KEY_SESSION_KEY] = await this.resolve(apiKey, request);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.ApiKeyStrategyGuard = ApiKeyStrategyGuard;
|
|
31
|
+
exports.ApiKeyStrategyGuard = ApiKeyStrategyGuard = __decorate([
|
|
32
|
+
(0, common_1.Injectable)(),
|
|
33
|
+
__metadata("design:paramtypes", [api_key_service_1.ApiKeyService, core_1.Reflector])
|
|
34
|
+
], ApiKeyStrategyGuard);
|
|
35
|
+
//# sourceMappingURL=api-key-strategy.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-strategy.guard.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/guards/api-key-strategy.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8D;AAC9D,uCAAyC;AACzC,mDAA8C;AAC9C,iEAA4D;AAE5D,4CAAmD;AA0B5C,IAAe,mBAAmB,GAAlC,MAAe,mBAAoB,SAAQ,2BAAW;IAC3D,YAAY,aAA4B,EAAE,SAAoB;QAC5D,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAyB;QAEzC,MAAM,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAEjC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,MAAM,MAAM,GAAiB,OAAO,CAAC,+BAAmB,CAAC,CAAC;QAG1D,OAAO,CAAC,+BAAmB,CAAC,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEnE,OAAO,IAAI,CAAC;IACd,CAAC;CAUF,CAAA;AA1BqB,kDAAmB;8BAAnB,mBAAmB;IADxC,IAAA,mBAAU,GAAE;qCAEgB,+BAAa,EAAa,gBAAS;GAD1C,mBAAmB,CA0BxC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
3
|
+
import { ApiKeyService } from "../services/api-key.service";
|
|
4
|
+
export declare class ApiKeyGuard implements CanActivate {
|
|
5
|
+
protected readonly apiKeyService: ApiKeyService;
|
|
6
|
+
protected readonly reflector: Reflector;
|
|
7
|
+
constructor(apiKeyService: ApiKeyService, reflector: Reflector);
|
|
8
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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.ApiKeyGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const api_key_service_1 = require("../services/api-key.service");
|
|
16
|
+
const api_key_actions_helper_1 = require("../helpers/api-key-actions.helper");
|
|
17
|
+
const constants_1 = require("../constants");
|
|
18
|
+
let ApiKeyGuard = class ApiKeyGuard {
|
|
19
|
+
constructor(apiKeyService, reflector) {
|
|
20
|
+
this.apiKeyService = apiKeyService;
|
|
21
|
+
this.reflector = reflector;
|
|
22
|
+
}
|
|
23
|
+
async canActivate(context) {
|
|
24
|
+
const request = context.switchToHttp().getRequest();
|
|
25
|
+
const rawKey = request.headers["x-api-key"];
|
|
26
|
+
if (!rawKey) {
|
|
27
|
+
throw new common_1.UnauthorizedException("Missing x-api-key header.");
|
|
28
|
+
}
|
|
29
|
+
let apiKey = await this.apiKeyService.validate({
|
|
30
|
+
value: rawKey,
|
|
31
|
+
ip: request.ip,
|
|
32
|
+
});
|
|
33
|
+
const rules = this.reflector.get(constants_1.API_KEY_ACTIONS_KEY, context.getHandler());
|
|
34
|
+
const grantedCodes = (apiKey.actions ?? []).map((a) => a.actionCode);
|
|
35
|
+
if (!(0, api_key_actions_helper_1.evaluateApiKeyActions)(rules, grantedCodes)) {
|
|
36
|
+
throw new common_1.UnauthorizedException("API key does not have the required action permissions.");
|
|
37
|
+
}
|
|
38
|
+
request[constants_1.API_KEY_SESSION_KEY] = apiKey;
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.ApiKeyGuard = ApiKeyGuard;
|
|
43
|
+
exports.ApiKeyGuard = ApiKeyGuard = __decorate([
|
|
44
|
+
(0, common_1.Injectable)(),
|
|
45
|
+
__metadata("design:paramtypes", [api_key_service_1.ApiKeyService,
|
|
46
|
+
core_1.Reflector])
|
|
47
|
+
], ApiKeyGuard);
|
|
48
|
+
//# sourceMappingURL=api-key.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.guard.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/guards/api-key.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AACzC,iEAA4D;AAG5D,8EAA0E;AAC1E,4CAAwE;AAGjE,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,YACqB,aAA4B,EAC5B,SAAoB;QADpB,kBAAa,GAAb,aAAa,CAAe;QAC5B,cAAS,GAAT,SAAS,CAAW;IACtC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAGpD,MAAM,MAAM,GAAW,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,8BAAqB,CAAC,2BAA2B,CAAC,CAAC;QAC/D,CAAC;QAGD,IAAI,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC;YAC7C,KAAK,EAAE,MAAM;YACb,EAAE,EAAE,OAAO,CAAC,EAAE;SACf,CAAC,CAAC;QAGH,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAC9B,+BAAmB,EACnB,OAAO,CAAC,UAAU,EAAE,CACrB,CAAC;QAEF,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAErE,IAAI,CAAC,IAAA,8CAAqB,EAAC,KAAK,EAAE,YAAY,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,8BAAqB,CAC7B,wDAAwD,CACzD,CAAC;QACJ,CAAC;QAGD,OAAO,CAAC,+BAAmB,CAAC,GAAG,MAAM,CAAC;QAEtC,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxCY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAGyB,+BAAa;QACjB,gBAAS;GAH9B,WAAW,CAwCvB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateApiKeyActions = evaluateApiKeyActions;
|
|
4
|
+
function evaluateApiKeyActions(rules, grantedActions) {
|
|
5
|
+
if (!rules || rules.length === 0)
|
|
6
|
+
return true;
|
|
7
|
+
const granted = new Set(grantedActions);
|
|
8
|
+
return rules.some((rule) => {
|
|
9
|
+
if (Array.isArray(rule)) {
|
|
10
|
+
return rule.every((action) => granted.has(action));
|
|
11
|
+
}
|
|
12
|
+
return granted.has(rule);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=api-key-actions.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-actions.helper.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/helpers/api-key-actions.helper.ts"],"names":[],"mappings":";;AAcA,sDAcC;AAdD,SAAgB,qBAAqB,CACnC,KAAyB,EACzB,cAAwB;IAExB,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAE9C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;IAExC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./api-key.module";
|
|
2
|
+
export * from "./constants";
|
|
3
|
+
export * from "./config/enum";
|
|
4
|
+
export * from "./decorators/api-key-actions.decorator";
|
|
5
|
+
export * from "./decorators/api-key-session.decorator";
|
|
6
|
+
export * from "./guards/api-key.guard";
|
|
7
|
+
export * from "./guards/api-key-strategy.guard";
|
|
8
|
+
export * from "./helpers/api-key-actions.helper";
|
|
9
|
+
export * from "./interfaces/api-key.interfaces";
|
|
10
|
+
export * from "./entities/api-key.entity";
|
|
11
|
+
export * from "./entities/api-key-action.entity";
|
|
12
|
+
export * from "./interfaces/api-key-context.interface";
|
|
13
|
+
export * from "./services/api-key.service";
|
|
14
|
+
export * from "./tasks/api-key-expiry.task";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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("./api-key.module"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./config/enum"), exports);
|
|
20
|
+
__exportStar(require("./decorators/api-key-actions.decorator"), exports);
|
|
21
|
+
__exportStar(require("./decorators/api-key-session.decorator"), exports);
|
|
22
|
+
__exportStar(require("./guards/api-key.guard"), exports);
|
|
23
|
+
__exportStar(require("./guards/api-key-strategy.guard"), exports);
|
|
24
|
+
__exportStar(require("./helpers/api-key-actions.helper"), exports);
|
|
25
|
+
__exportStar(require("./interfaces/api-key.interfaces"), exports);
|
|
26
|
+
__exportStar(require("./entities/api-key.entity"), exports);
|
|
27
|
+
__exportStar(require("./entities/api-key-action.entity"), exports);
|
|
28
|
+
__exportStar(require("./interfaces/api-key-context.interface"), exports);
|
|
29
|
+
__exportStar(require("./services/api-key.service"), exports);
|
|
30
|
+
__exportStar(require("./tasks/api-key-expiry.task"), exports);
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../libs/nestjs-apikey-module/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,8CAA4B;AAC5B,gDAA8B;AAC9B,yEAAuD;AACvD,yEAAuD;AACvD,yDAAuC;AACvC,kEAAgD;AAChD,mEAAiD;AACjD,kEAAgD;AAChD,4DAA0C;AAC1C,mEAAiD;AACjD,yEAAuD;AACvD,6DAA2C;AAC3C,8DAA4C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-context.interface.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/interfaces/api-key-context.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ModuleMetadata } from "@nestjs/common";
|
|
2
|
+
import { ApiKeyEntity } from "../entities/api-key.entity";
|
|
3
|
+
export interface IApiKeyModuleOptions {
|
|
4
|
+
keyPrefix?: string;
|
|
5
|
+
bcryptSaltRounds?: number;
|
|
6
|
+
expiryCron?: string | false;
|
|
7
|
+
}
|
|
8
|
+
export interface IApiKeyModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
9
|
+
useFactory: (...args: any[]) => Promise<IApiKeyModuleOptions> | IApiKeyModuleOptions;
|
|
10
|
+
inject?: any[];
|
|
11
|
+
}
|
|
12
|
+
export interface ICreateApiKeyOptions {
|
|
13
|
+
name: string;
|
|
14
|
+
actions: string[];
|
|
15
|
+
expiresInDays?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ICreateApiKeyResult {
|
|
18
|
+
entity: ApiKeyEntity;
|
|
19
|
+
apikey: string;
|
|
20
|
+
}
|
|
21
|
+
export interface IRevokeApiKeyOptions {
|
|
22
|
+
id: string;
|
|
23
|
+
reason?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface IRotateApiKeyResult extends ICreateApiKeyResult {
|
|
26
|
+
}
|
|
27
|
+
export interface IApiKeyValidationOptions {
|
|
28
|
+
value: string;
|
|
29
|
+
ip?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.interfaces.js","sourceRoot":"","sources":["../../libs/nestjs-apikey-module/src/interfaces/api-key.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Repository } from "typeorm";
|
|
2
|
+
import { ApiKeyEntity } from "../entities/api-key.entity";
|
|
3
|
+
import { ApiKeyActionEntity } from "../entities/api-key-action.entity";
|
|
4
|
+
import { IApiKeyModuleOptions, IApiKeyValidationOptions, ICreateApiKeyOptions, ICreateApiKeyResult, IRevokeApiKeyOptions, IRotateApiKeyResult } from "../interfaces/api-key.interfaces";
|
|
5
|
+
export declare class ApiKeyService {
|
|
6
|
+
private readonly apiKeyRepo;
|
|
7
|
+
private readonly apiKeyActionRepo;
|
|
8
|
+
private readonly options;
|
|
9
|
+
constructor(apiKeyRepo: Repository<ApiKeyEntity>, apiKeyActionRepo: Repository<ApiKeyActionEntity>, options: IApiKeyModuleOptions);
|
|
10
|
+
create(data: ICreateApiKeyOptions): Promise<ICreateApiKeyResult>;
|
|
11
|
+
getById(id: string): Promise<ApiKeyEntity>;
|
|
12
|
+
getActiveById(id: string): Promise<ApiKeyEntity>;
|
|
13
|
+
getActiveByKeyPrefix(keyPrefix: string): Promise<ApiKeyEntity>;
|
|
14
|
+
revoke(options: IRevokeApiKeyOptions): Promise<void>;
|
|
15
|
+
rotate(id: string): Promise<IRotateApiKeyResult>;
|
|
16
|
+
validate(options: IApiKeyValidationOptions): Promise<ApiKeyEntity>;
|
|
17
|
+
remove(id: string): Promise<void>;
|
|
18
|
+
removeByKeyPrefix(keyPrefix: string): Promise<void>;
|
|
19
|
+
expireKeys(): Promise<void>;
|
|
20
|
+
expireByKeyPrefix(keyPrefix: string): Promise<void>;
|
|
21
|
+
}
|