Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+37
@@ -0,0 +1,37 @@
|
||||
// AK-P16a · webhook-subscription renewal decision (PURE) — M25 Block E.
|
||||
//
|
||||
// Google Calendar push channels expire (~1 week). A worker cron renews channels
|
||||
// that will lapse soon, BEFORE they go silent. This module holds only the pure
|
||||
// decision (no DB/network) so the cron stays thin and the timing is unit-tested.
|
||||
// The renewal threshold (default 24h) gives ample margin against the cron cadence.
|
||||
|
||||
export const DEFAULT_RENEWAL_THRESHOLD_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||
|
||||
export interface WebhookRenewalInput {
|
||||
/** Current provider channel expiry (null = no active subscription). */
|
||||
readonly expiresAt: Date | null;
|
||||
readonly now: Date;
|
||||
readonly thresholdMs?: number;
|
||||
}
|
||||
|
||||
export interface WebhookRenewalDecision {
|
||||
readonly shouldRenew: boolean;
|
||||
/** Stable reason code (also a Klartext i18n suffix). */
|
||||
readonly reason: "no_subscription" | "expiring_soon" | "still_valid";
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide whether a connection's push channel needs renewal now. Renew when there
|
||||
* is no subscription yet, or it expires within `thresholdMs`.
|
||||
*/
|
||||
export function decideWebhookRenewal(input: WebhookRenewalInput): WebhookRenewalDecision {
|
||||
if (input.expiresAt === null) {
|
||||
return { shouldRenew: true, reason: "no_subscription" };
|
||||
}
|
||||
const threshold = input.thresholdMs ?? DEFAULT_RENEWAL_THRESHOLD_MS;
|
||||
const msLeft = input.expiresAt.getTime() - input.now.getTime();
|
||||
if (msLeft <= threshold) {
|
||||
return { shouldRenew: true, reason: "expiring_soon" };
|
||||
}
|
||||
return { shouldRenew: false, reason: "still_valid" };
|
||||
}
|
||||
Reference in new issue
Block a user