Session 15: Intelligence hardening — park factors, weather, Tank01 prefetch, pace factors, signal audit, founder pricing fix (1405 tests)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kev
2026-06-11 16:21:18 -04:00
parent f5d79cf70d
commit 167996d99a
20 changed files with 1550 additions and 28 deletions
+25 -14
View File
@@ -7,15 +7,18 @@ function getStripe() {
return _stripe;
}
// Session 15 — fallback strings like 'price_analyst_monthly' would
// 400 from Stripe in production (they're not real `price_xxx` IDs).
// All maps now fall back to null; getPriceId then returns the
// PRICE_UNCONFIGURED sentinel for unset values. Founder prices
// additionally fall back to the standard tier price so a user with
// a valid founder code on a deploy that doesn't yet have founder
// prices wired still gets a successful checkout at standard rate.
const PRICE_MAP = {
analyst: process.env.STRIPE_PRICE_ANALYST || 'price_analyst_monthly',
analyst_founder: process.env.STRIPE_PRICE_ANALYST_FOUNDER || 'price_analyst_founder',
desk: process.env.STRIPE_PRICE_DESK || 'price_desk_monthly',
desk_founder: process.env.STRIPE_PRICE_DESK_FOUNDER || 'price_desk_founder',
// Session 14 — Africa tier ($4.99/mo). The Stripe product must be
// created in the dashboard before STRIPE_PRICE_AFRICA carries a real
// ID. Until then `getPriceId('africa')` returns a sentinel that
// surfaces a clean error to the user via the route handler.
analyst: process.env.STRIPE_PRICE_ANALYST || null,
analyst_founder: process.env.STRIPE_PRICE_ANALYST_FOUNDER || null,
desk: process.env.STRIPE_PRICE_DESK || null,
desk_founder: process.env.STRIPE_PRICE_DESK_FOUNDER || null,
africa: process.env.STRIPE_PRICE_AFRICA || null,
};
@@ -38,13 +41,21 @@ function isFounderCodeValid(code) {
function getPriceId(tier, founderCode) {
const isFounder = isFounderCodeValid(founderCode);
if (tier === 'analyst') return isFounder ? PRICE_MAP.analyst_founder : PRICE_MAP.analyst;
if (tier === 'desk') return isFounder ? PRICE_MAP.desk_founder : PRICE_MAP.desk;
if (tier === 'analyst') {
// Session 15 — if a valid founder code is presented but the
// founder price ID isn't wired (env unset), gracefully fall
// back to the standard analyst price rather than 503'ing the
// user. The founder discount is operator-controlled; the
// checkout itself shouldn't break.
if (isFounder && PRICE_MAP.analyst_founder) return PRICE_MAP.analyst_founder;
return PRICE_MAP.analyst || PRICE_UNCONFIGURED;
}
if (tier === 'desk') {
if (isFounder && PRICE_MAP.desk_founder) return PRICE_MAP.desk_founder;
return PRICE_MAP.desk || PRICE_UNCONFIGURED;
}
if (tier === 'africa') {
// Africa tier doesn't have a founder discount — it IS the
// discount. Returns the sentinel when STRIPE_PRICE_AFRICA is
// unset so the route handler can produce a clean error instead
// of forwarding a null price ID to Stripe.
// Africa tier has no founder discount — it IS the discount.
return PRICE_MAP.africa || PRICE_UNCONFIGURED;
}
throw new Error(`Invalid tier: ${tier}`);