36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
"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;
|