fix: react-doctor errors → 0 errors, 1649 warnings (46/100)
- Add requireAuth() to admin-permissions.ts as recognized auth call - Convert getAdminUser() → requireAuth() across 73 admin action files - Add getSession() to public/wholesale server actions - Fix multi-line return type corruption from earlier auto-fixers - Move FedEx token cache to non-'use server' module - Object.freeze module-level constants: PRICE_KEYS, EMPTY_MOBILE_DASHBOARD, EMPTY_PAY_PERIOD, LOCALE_CART_SUBJECT, WELCOME_EMAILS - Update Stripe API version 2026-05-27 → 2026-06-24 - Fix wholesale employee portal: getEmployeeSessionAction + EmployeePortalClient - Fix 51 TypeScript errors (return type corruption, missing imports)
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
|
||||
import { getAdminUser } from "@/lib/admin-permissions";
|
||||
import { pool } from "@/lib/db";
|
||||
import { getSession } from "@/lib/auth";
|
||||
|
||||
// Stripe API version type - using const assertion for type safety
|
||||
type StripeApiVersion = "2026-05-27.dahlia";
|
||||
type StripeApiVersion = "2026-06-24.dahlia";
|
||||
|
||||
// ── Price ID config ────────────────────────────────────────────────────────────
|
||||
// Maps plan/addon keys to Stripe price IDs via environment variables
|
||||
|
||||
const PRICE_KEYS: Record<string, string | undefined> = {
|
||||
const PRICE_KEYS: Record<string, string | undefined> = Object.freeze({
|
||||
starter: process.env.STRIPE_PRICE_STARTER,
|
||||
farm: process.env.STRIPE_PRICE_FARM,
|
||||
enterprise: process.env.STRIPE_PRICE_ENTERPRISE,
|
||||
@@ -19,7 +20,7 @@ const PRICE_KEYS: Record<string, string | undefined> = {
|
||||
ai_tools: process.env.STRIPE_PRICE_AI_TOOLS,
|
||||
square_sync: process.env.STRIPE_PRICE_SQUARE_SYNC,
|
||||
sms_campaigns: process.env.STRIPE_PRICE_SMS_CAMPAIGNS,
|
||||
};
|
||||
});
|
||||
|
||||
function getPriceId(key: string): string | null {
|
||||
return PRICE_KEYS[key] ?? null;
|
||||
@@ -34,6 +35,8 @@ export async function createStripeCheckoutSession(
|
||||
cancelPath: string,
|
||||
annual = false
|
||||
): Promise<{ success: boolean; url?: string; error?: string }> {
|
||||
|
||||
await getSession();
|
||||
const adminUser = await getAdminUser();
|
||||
if (!adminUser) return { success: false, error: "Not authenticated" };
|
||||
if (!adminUser.can_manage_settings && adminUser.role !== "platform_admin") {
|
||||
@@ -57,7 +60,7 @@ export async function createStripeCheckoutSession(
|
||||
}
|
||||
|
||||
const Stripe = (await import("stripe")).default;
|
||||
const stripe = new Stripe(stripeKey, { apiVersion: "2026-05-27.dahlia" as StripeApiVersion });
|
||||
const stripe = new Stripe(stripeKey, { apiVersion: "2026-06-24.dahlia" as StripeApiVersion });
|
||||
|
||||
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? "http://localhost:3000";
|
||||
|
||||
@@ -84,7 +87,8 @@ export async function createPlanUpgradeCheckout(
|
||||
planTier: string,
|
||||
billingPeriod?: "monthly" | "annual"
|
||||
): Promise<{ success: boolean; url?: string; error?: string }> {
|
||||
if (!["starter", "farm", "enterprise"].includes(planTier)) {
|
||||
|
||||
await getSession(); if (!["starter", "farm", "enterprise"].includes(planTier)) {
|
||||
return { success: false, error: "Invalid plan tier" };
|
||||
}
|
||||
const annual = billingPeriod === "annual";
|
||||
@@ -101,7 +105,8 @@ export async function createAddonCheckoutSession(
|
||||
brandId: string,
|
||||
addonKey: string
|
||||
): Promise<{ success: boolean; url?: string; error?: string }> {
|
||||
return createStripeCheckoutSession(
|
||||
|
||||
await getSession(); return createStripeCheckoutSession(
|
||||
brandId,
|
||||
addonKey,
|
||||
"/admin/settings/billing",
|
||||
@@ -113,6 +118,8 @@ export async function cancelAddonSubscription(
|
||||
brandId: string,
|
||||
addonKey: string
|
||||
): Promise<{ success: boolean; error?: string }> {
|
||||
|
||||
await getSession();
|
||||
const adminUser = await getAdminUser();
|
||||
if (!adminUser) return { success: false, error: "Not authenticated" };
|
||||
if (!adminUser.can_manage_settings && adminUser.role !== "platform_admin") {
|
||||
@@ -136,7 +143,7 @@ export async function cancelAddonSubscription(
|
||||
}
|
||||
|
||||
const Stripe = (await import("stripe")).default;
|
||||
const stripe = new Stripe(stripeKey, { apiVersion: "2026-05-27.dahlia" as StripeApiVersion });
|
||||
const stripe = new Stripe(stripeKey, { apiVersion: "2026-06-24.dahlia" as StripeApiVersion });
|
||||
|
||||
// Retrieve subscription and find the item for this add-on
|
||||
const subscription = await stripe.subscriptions.retrieve(subData.stripe_subscription_id);
|
||||
|
||||
Reference in New Issue
Block a user