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:
@@ -22,6 +22,8 @@
|
||||
import { getAdminUser } from "@/lib/admin-permissions";
|
||||
import { assertBrandAccess } from "@/lib/brand-scope";
|
||||
import { pool } from "@/lib/db";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { readFedExToken, writeFedExToken } from "@/lib/shipping/fedex-token-cache";
|
||||
|
||||
// ── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -55,13 +57,6 @@ export type RateResult =
|
||||
const FEDEX_BASE_URL = "https://apis.fedex.com";
|
||||
const FEDEX_SANDBOX_URL = "https://apis-sandbox.fedex.com";
|
||||
|
||||
interface FedExAuthToken {
|
||||
accessToken: string;
|
||||
expiresAt: number; // epoch ms
|
||||
}
|
||||
|
||||
let cachedToken: FedExAuthToken | null = null;
|
||||
|
||||
async function getFedExToken(settings: {
|
||||
fedexApiKey: string;
|
||||
fedexApiSecret: string;
|
||||
@@ -70,8 +65,9 @@ async function getFedExToken(settings: {
|
||||
const base = settings.useProduction ? FEDEX_BASE_URL : FEDEX_SANDBOX_URL;
|
||||
|
||||
// Reuse cached token if still valid (5 min buffer)
|
||||
if (cachedToken && Date.now() < cachedToken.expiresAt - 5 * 60 * 1000) {
|
||||
return { accessToken: cachedToken.accessToken };
|
||||
const cached = readFedExToken();
|
||||
if (cached && Date.now() < cached.expiresAt - 5 * 60 * 1000) {
|
||||
return { accessToken: cached.accessToken };
|
||||
}
|
||||
|
||||
const credentials = btoa(`${settings.fedexApiKey}:${settings.fedexApiSecret}`);
|
||||
@@ -91,10 +87,7 @@ async function getFedExToken(settings: {
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
cachedToken = {
|
||||
accessToken: data.access_token,
|
||||
expiresAt: Date.now() + data.expires_in * 1000,
|
||||
};
|
||||
writeFedExToken(data.access_token, data.expires_in);
|
||||
|
||||
return { accessToken: data.access_token };
|
||||
}
|
||||
@@ -152,7 +145,8 @@ async function loadShippingSettingsForBrand(brandId: string): Promise<ShippingSe
|
||||
export async function getFedExRates(
|
||||
orderId: string
|
||||
): Promise<RateResult> {
|
||||
const adminUser = await getAdminUser();
|
||||
|
||||
await getSession(); const adminUser = await getAdminUser();
|
||||
if (!adminUser) return { success: false, error: "Not authenticated" };
|
||||
if (!adminUser.can_manage_orders) {
|
||||
return { success: false, error: "Not authorized to view shipping rates" };
|
||||
|
||||
Reference in New Issue
Block a user