fase(9): auth module with casl rbac and session management
This commit is contained in:
35
dist/modules/auth/domain/entities/ApiKey.js
vendored
Normal file
35
dist/modules/auth/domain/entities/ApiKey.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApiKey = void 0;
|
||||
const AggregateRoot_1 = require("../../../../shared/domain/AggregateRoot");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
class ApiKey extends AggregateRoot_1.AggregateRoot {
|
||||
static create(props, id) {
|
||||
const keyId = id ?? UniqueId_1.UniqueId.create();
|
||||
return new ApiKey({
|
||||
...props,
|
||||
createdAt: new Date(),
|
||||
}, keyId);
|
||||
}
|
||||
static reconstitute(props, id) {
|
||||
return new ApiKey(props, id);
|
||||
}
|
||||
get userId() { return this.props.userId; }
|
||||
get orgId() { return this.props.orgId; }
|
||||
get name() { return this.props.name; }
|
||||
get keyHash() { return this.props.keyHash; }
|
||||
get keyPrefix() { return this.props.keyPrefix; }
|
||||
get permissions() { return this.props.permissions; }
|
||||
get expiresAt() { return this.props.expiresAt; }
|
||||
get lastUsedAt() { return this.props.lastUsedAt; }
|
||||
get createdAt() { return this.props.createdAt; }
|
||||
isExpired() {
|
||||
if (!this.props.expiresAt)
|
||||
return false;
|
||||
return new Date() > this.props.expiresAt;
|
||||
}
|
||||
markUsed() {
|
||||
this.props.lastUsedAt = new Date();
|
||||
}
|
||||
}
|
||||
exports.ApiKey = ApiKey;
|
||||
Reference in New Issue
Block a user