32 lines
680 B
TypeScript
32 lines
680 B
TypeScript
export type PendingCheckout = {
|
|
packageId: number | null;
|
|
startedAt: number;
|
|
};
|
|
|
|
export const PENDING_CHECKOUT_TTL_MS = 1000 * 60 * 30;
|
|
|
|
export function isCheckoutExpired(
|
|
pending: PendingCheckout,
|
|
now = Date.now(),
|
|
ttl = PENDING_CHECKOUT_TTL_MS,
|
|
): boolean {
|
|
return now - pending.startedAt > ttl;
|
|
}
|
|
|
|
export function shouldClearPendingCheckout(
|
|
pending: PendingCheckout,
|
|
activePackageId: number | null,
|
|
now = Date.now(),
|
|
ttl = PENDING_CHECKOUT_TTL_MS,
|
|
): boolean {
|
|
if (isCheckoutExpired(pending, now, ttl)) {
|
|
return true;
|
|
}
|
|
|
|
if (pending.packageId && activePackageId && pending.packageId === activePackageId) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|