mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Improved example getCertificates for strict mode
This commit is contained in:
@@ -1,16 +1,26 @@
|
|||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const certificatesCache: Partial<{
|
interface Cache {
|
||||||
signerCert: Buffer;
|
certificates:
|
||||||
signerKey: Buffer;
|
| {
|
||||||
wwdr: Buffer;
|
signerCert: Buffer | string;
|
||||||
signerKeyPassphrase: string;
|
signerKey: Buffer | string;
|
||||||
}> = {};
|
wwdr: Buffer | string;
|
||||||
|
signerKeyPassphrase: string;
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getCertificates(): Promise<typeof certificatesCache> {
|
const cache: Cache = {
|
||||||
if (Object.keys(certificatesCache).length) {
|
certificates: undefined,
|
||||||
return certificatesCache;
|
};
|
||||||
|
|
||||||
|
export async function getCertificates(): Promise<
|
||||||
|
Exclude<Cache["certificates"], undefined>
|
||||||
|
> {
|
||||||
|
if (cache.certificates) {
|
||||||
|
return cache.certificates;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [signerCert, signerKey, wwdr, signerKeyPassphrase] =
|
const [signerCert, signerKey, wwdr, signerKeyPassphrase] =
|
||||||
@@ -30,12 +40,12 @@ export async function getCertificates(): Promise<typeof certificatesCache> {
|
|||||||
Promise.resolve("123456"),
|
Promise.resolve("123456"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Object.assign(certificatesCache, {
|
cache.certificates = {
|
||||||
signerCert,
|
signerCert,
|
||||||
signerKey,
|
signerKey,
|
||||||
wwdr,
|
wwdr,
|
||||||
signerKeyPassphrase,
|
signerKeyPassphrase,
|
||||||
});
|
};
|
||||||
|
|
||||||
return certificatesCache;
|
return cache.certificates;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user