smartacme/ts/smartacme.classes.cert.ts

40 lines
1.0 KiB
TypeScript

import * as plugins from './plugins.js';
/**
* Plain certificate record.
*/
export class SmartacmeCert {
public id: string;
public domainName: string;
public created: number;
public privateKey: string;
public publicKey: string;
public csr: string;
public validUntil: number;
constructor(data: Partial<SmartacmeCert> = {}) {
this.id = data.id || '';
this.domainName = data.domainName || '';
this.created = data.created || Date.now();
this.privateKey = data.privateKey || '';
this.publicKey = data.publicKey || '';
this.csr = data.csr || '';
this.validUntil = data.validUntil || 0;
}
/**
* Check if certificate is still valid.
*/
public isStillValid(): boolean {
return this.validUntil >= Date.now();
}
/**
* Check if certificate needs renewal (e.g., expires in <10 days).
*/
public shouldBeRenewed(): boolean {
const threshold = Date.now() + plugins.smarttime.getMilliSecondsFromUnits({ days: 10 });
return this.validUntil < threshold;
}
}