Files
memind/wechat/suspended-user-push-policy.mjs
john c36558e0f3
Memind CI / Test, build, and release guards (push) Successful in 4m20s
feat(wechat): keep morning/weather push for suspended billing users
欠费停用用户仍送达早安与天气,跳过复杂页面订阅与定时任务补发。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-22 16:30:40 +08:00

50 lines
1.7 KiB
JavaScript

import { resolvePushSubscriptionFromMetadataSource } from './push-subscription-catalog.mjs';
/** 欠费停用(suspended)用户仍必须送达的基础推送。 */
export const SUSPENDED_ESSENTIAL_PUSH_KEYS = Object.freeze(['morning', 'weather']);
export function isSuspendedBillingUser(statusOrUser) {
const status = typeof statusOrUser === 'string'
? statusOrUser
: String(statusOrUser?.status ?? '').trim();
return status === 'suspended';
}
export function resolvePushSubscriptionKeyFromSource(source) {
return resolvePushSubscriptionFromMetadataSource(source)?.key ?? null;
}
export function isPushSubscriptionSource(source) {
return resolvePushSubscriptionKeyFromSource(source) != null;
}
export function isEssentialPushSubscriptionKey(key) {
return SUSPENDED_ESSENTIAL_PUSH_KEYS.includes(String(key ?? '').trim());
}
export function isEssentialPushSubscriptionSource(source) {
const key = resolvePushSubscriptionKeyFromSource(source);
return key ? isEssentialPushSubscriptionKey(key) : false;
}
export function canCommitPushSubscriptionForSuspendedUser(catalogKey) {
return isEssentialPushSubscriptionKey(catalogKey);
}
export function shouldSkipPushReminderForSuspendedUser({ userStatus, pushSource }) {
if (!isSuspendedBillingUser(userStatus)) return false;
if (!isPushSubscriptionSource(pushSource)) return false;
return !isEssentialPushSubscriptionSource(pushSource);
}
export function sanitizeDeliveryForSuspendedUser(delivery, { userStatus, pushSource } = {}) {
if (!delivery || !isSuspendedBillingUser(userStatus)) return delivery;
if (shouldSkipPushReminderForSuspendedUser({ userStatus, pushSource })) {
return null;
}
return {
...delivery,
verifiedHtmlUrls: [],
};
}