@foldspace-fe/casdoor-next-auth-kit 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/billing/index.d.ts +16 -0
  2. package/dist/billing/index.js +28 -0
  3. package/dist/billing/index.js.map +1 -0
  4. package/dist/callback-BTzHQK_r.d.ts +12 -0
  5. package/dist/casdoor/index.d.ts +28 -0
  6. package/dist/casdoor/index.js +40 -0
  7. package/dist/casdoor/index.js.map +1 -0
  8. package/dist/chunk-6E27SZ7V.js +291 -0
  9. package/dist/chunk-6E27SZ7V.js.map +1 -0
  10. package/dist/chunk-DONQHN4U.js +56 -0
  11. package/dist/chunk-DONQHN4U.js.map +1 -0
  12. package/dist/chunk-IQEVUR77.js +909 -0
  13. package/dist/chunk-IQEVUR77.js.map +1 -0
  14. package/dist/chunk-RGTVPBH7.js +182 -0
  15. package/dist/chunk-RGTVPBH7.js.map +1 -0
  16. package/dist/chunk-T2M5MVPE.js +20 -0
  17. package/dist/chunk-T2M5MVPE.js.map +1 -0
  18. package/dist/chunk-XMBHIEYL.js +1 -0
  19. package/dist/chunk-XMBHIEYL.js.map +1 -0
  20. package/dist/chunk-Y4GJ2AEI.js +192 -0
  21. package/dist/chunk-Y4GJ2AEI.js.map +1 -0
  22. package/dist/cli.d.ts +2 -0
  23. package/dist/cli.js +437 -0
  24. package/dist/cli.js.map +1 -0
  25. package/dist/index.d.ts +77 -0
  26. package/dist/index.js +148 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/next/index.d.ts +17 -0
  29. package/dist/next/index.js +24 -0
  30. package/dist/next/index.js.map +1 -0
  31. package/dist/options-JUwZSXu2.d.ts +40 -0
  32. package/dist/react/index.d.ts +242 -0
  33. package/dist/react/index.js +774 -0
  34. package/dist/react/index.js.map +1 -0
  35. package/dist/skills/casdoor-next-auth-kit/SKILL.md +158 -0
  36. package/dist/skills/casdoor-next-auth-kit/references/casdoor-api-reference.md +2387 -0
  37. package/dist/skills/casdoor-next-auth-kit/references/swagger.json +3686 -0
  38. package/dist/types-BPsPs5Rv.d.ts +337 -0
  39. package/dist/types-DqVXdUge.d.ts +121 -0
  40. package/package.json +69 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/provider.tsx","../../src/react/hooks.ts","../../src/billing/react.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\nimport type { Session } from 'next-auth';\nimport { SessionProvider } from 'next-auth/react';\n\nexport function AuthProvider({\n children,\n session,\n}: {\n children: ReactNode;\n session?: Session | null;\n}) {\n return <SessionProvider session={session}>{children}</SessionProvider>;\n}\n","'use client';\n\nimport { useSession } from 'next-auth/react';\nimport { buildAuthJumpHref } from '../core/redirect';\nimport type { AuthSession } from '../next/options';\n\nexport type AuthRole = 'guest' | 'user' | 'admin';\n\nexport interface AuthUserSummary {\n id: string | null;\n name: string;\n email: string | null;\n image: string | null;\n isAuthenticated: boolean;\n isAdmin: boolean;\n tokenBalance: number;\n isVip: boolean;\n role: AuthRole;\n}\n\nexport interface AuthActions {\n loginHref: string;\n signupHref: string;\n logoutHref: string;\n accountHref: string;\n adminHref: string;\n}\n\nexport interface AuthActionsOptions {\n redirect?: string | null;\n}\n\nfunction getUserSummary(session: AuthSession | null | undefined): AuthUserSummary {\n const user = session?.user;\n const name = user?.name || '登录';\n const isAuthenticated = Boolean(user);\n const isAdmin = Boolean(user?.isAdmin);\n const role: AuthRole = !isAuthenticated ? 'guest' : isAdmin ? 'admin' : 'user';\n\n return {\n id: user?.id ?? null,\n name,\n email: user?.email ?? null,\n image: user?.image ?? null,\n isAuthenticated,\n isAdmin,\n tokenBalance: Number(user?.tokenBalance ?? 2580),\n isVip: Boolean(user?.isVip ?? true),\n role,\n };\n}\n\nexport function useAuthSession() {\n return useSession() as ReturnType<typeof useSession> & {\n data: AuthSession | null | undefined;\n };\n}\n\nexport function useAuthUser(): AuthUserSummary {\n const { data: session } = useAuthSession();\n return getUserSummary(session ?? null);\n}\n\nexport function useAuthRole(): AuthRole {\n return useAuthUser().role;\n}\n\nexport function useAuthActions(options: AuthActionsOptions = {}): AuthActions {\n const user = useAuthUser();\n const redirect = options.redirect ?? null;\n\n return {\n loginHref: buildAuthJumpHref('login', redirect ?? undefined),\n signupHref: buildAuthJumpHref('signup', redirect ?? undefined),\n logoutHref: '/logout',\n accountHref: user.isAdmin ? '/admin' : '/user/account',\n adminHref: '/admin',\n };\n}\n","'use client';\n\nimport {\n type Context,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n type ReactNode,\n} from 'react';\n\nimport {\n buildBillingActionPayload,\n deriveBillingCreditsState,\n deriveBillingEntitlements,\n filterProductsByKind,\n normalizeBillingPurchaseStatus,\n normalizeBillingCatalogConfig,\n normalizeBillingRuntimeConfig,\n resolveBillingItem,\n resolveBillingProductSnapshot,\n resolveBillingSubscriptionProduct,\n} from './runtime';\nimport type {\n BillingActionExecutor,\n BillingActionKind,\n BillingActionPayload,\n BillingApiClient,\n BillingCatalogConfig,\n BillingCoreContextValue,\n BillingCreditsContextValue,\n BillingCreditsState,\n BillingDefaults,\n BillingEntitlementState,\n BillingLoaders,\n BillingOrderHistoryItem,\n BillingPaymentHistoryItem,\n BillingItem,\n BillingProductState,\n BillingProductContextValue,\n BillingProductSnapshot,\n BillingPurchaseStatus,\n BillingRuntimeConfig,\n BillingStatusState,\n BillingSubscriptionContextValue,\n BillingSubscriptionHistoryItem,\n BillingSubscriptionPurchaseConfig,\n BillingSubscriptionState,\n BillingProductPurchaseConfig,\n} from './types';\n\nexport interface BillingProviderProps {\n children: ReactNode;\n apiClient: BillingApiClient;\n loaders?: BillingLoaders;\n runtimeConfigLoader?: BillingLoaders['runtimeConfigLoader'];\n actionExecutor?: BillingActionExecutor;\n defaults?: BillingDefaults;\n runtimeConfig?: BillingRuntimeConfig | BillingCatalogConfig;\n subscription?: BillingSubscriptionState;\n subscriptionHistory?: BillingSubscriptionHistoryItem[];\n products?: BillingProductState[];\n orderHistory?: BillingOrderHistoryItem[];\n paymentHistory?: BillingPaymentHistoryItem[];\n credits?: BillingCreditsState;\n entitlements?: BillingEntitlementState;\n status?: BillingStatusState;\n purchaseStatus?: BillingPurchaseStatus;\n autoRefresh?: boolean;\n}\n\nexport type BillingCoreProviderProps = BillingProviderProps;\nexport interface BillingSubscriptionProviderProps {\n children: ReactNode;\n availablePlans?: BillingItem[];\n subscription?: BillingSubscriptionState;\n subscriptionHistory?: BillingSubscriptionHistoryItem[];\n entitlements?: BillingEntitlementState;\n status?: BillingStatusState;\n}\n\nexport interface BillingProductProviderProps {\n children: ReactNode;\n availableProducts?: BillingItem[];\n products?: BillingProductState[];\n orderHistory?: BillingOrderHistoryItem[];\n paymentHistory?: BillingPaymentHistoryItem[];\n status?: BillingStatusState;\n}\n\nexport interface BillingCreditsProviderProps {\n children: ReactNode;\n credits?: BillingCreditsState;\n status?: BillingStatusState;\n}\n\nexport interface BillingPipelineOptions {\n onBeforeAction?: (payload: BillingActionPayload) => Promise<BillingActionPayload>;\n onAfterAction?: (result: { redirectTo?: string; nextAction?: string }) => Promise<void>;\n onError?: (error: unknown) => Promise<void>;\n}\n\nconst BillingCoreContext = createContext<BillingCoreContextValue | null>(null);\nconst BillingSubscriptionContext = createContext<BillingSubscriptionContextValue | null>(null);\nconst BillingProductContext = createContext<BillingProductContextValue | null>(null);\nconst BillingCreditsContext = createContext<BillingCreditsContextValue | null>(null);\n\nfunction useOptionalContext<T>(context: Context<T | null>): T | null {\n return useContext(context);\n}\n\nfunction useRequiredCoreContext(): BillingCoreContextValue {\n const context = useContext(BillingCoreContext);\n if (!context) {\n throw new Error('Billing hooks must be used inside BillingProvider or BillingCoreProvider.');\n }\n return context;\n}\n\nfunction choose<T>(primary: T | undefined, fallback: T | undefined): T | undefined {\n return primary ?? fallback;\n}\n\nfunction getLatestOrder(orders: BillingOrderHistoryItem[] | undefined): BillingOrderHistoryItem | undefined {\n return [...(orders ?? [])].sort((a, b) => {\n const left = Date.parse(b.updatedAt ?? b.createdAt ?? '') || 0;\n const right = Date.parse(a.updatedAt ?? a.createdAt ?? '') || 0;\n return left - right;\n })[0];\n}\n\nfunction getLatestPayment(payments: BillingPaymentHistoryItem[] | undefined): BillingPaymentHistoryItem | undefined {\n return [...(payments ?? [])].sort((a, b) => {\n const left = Date.parse(b.updatedAt ?? b.createdAt ?? '') || 0;\n const right = Date.parse(a.updatedAt ?? a.createdAt ?? '') || 0;\n return left - right;\n })[0];\n}\n\nfunction normalizeRuntimeConfigInput(config?: BillingRuntimeConfig | BillingCatalogConfig | null): BillingRuntimeConfig | undefined {\n if (!config) return undefined;\n return normalizeBillingRuntimeConfig(config);\n}\n\nfunction normalizeCatalogConfigInput(config?: BillingRuntimeConfig | BillingCatalogConfig | null): BillingCatalogConfig | undefined {\n if (!config) return undefined;\n return normalizeBillingCatalogConfig(config);\n}\n\nfunction buildCoreValue(input: {\n apiClient: BillingApiClient;\n loaders?: BillingLoaders;\n runtimeConfigLoader?: BillingLoaders['runtimeConfigLoader'];\n actionExecutor?: BillingActionExecutor;\n defaults?: BillingDefaults;\n runtimeConfig?: BillingRuntimeConfig | BillingCatalogConfig;\n runtimeCatalog?: BillingCatalogConfig;\n runtimeConfigLoading: boolean;\n runtimeConfigError: string | null;\n subscription?: BillingSubscriptionState;\n subscriptionHistory?: BillingSubscriptionHistoryItem[];\n products?: BillingProductState[];\n orderHistory?: BillingOrderHistoryItem[];\n paymentHistory?: BillingPaymentHistoryItem[];\n credits?: BillingCreditsState;\n entitlements?: BillingEntitlementState;\n purchaseStatus?: BillingPurchaseStatus;\n status: BillingStatusState;\n refresh: () => Promise<void>;\n runAction: (payload: BillingActionPayload) => Promise<{\n redirectTo?: string;\n nextAction?: string;\n status?: 'pending' | 'succeeded' | 'failed';\n }>;\n setRuntimeConfig: (config?: BillingRuntimeConfig) => void;\n setSubscription: (value?: BillingSubscriptionState) => void;\n setSubscriptionHistory: (value?: BillingSubscriptionHistoryItem[]) => void;\n setProducts: (value?: BillingProductState[]) => void;\n setOrderHistory: (value?: BillingOrderHistoryItem[]) => void;\n setPaymentHistory: (value?: BillingPaymentHistoryItem[]) => void;\n setCredits: (value?: BillingCreditsState) => void;\n setEntitlements: (value?: BillingEntitlementState) => void;\n setPurchaseStatus: (status?: BillingPurchaseStatus) => void;\n setStatus: (status: BillingStatusState | ((current: BillingStatusState) => BillingStatusState)) => void;\n}): BillingCoreContextValue {\n return {\n apiClient: input.apiClient,\n loaders: input.loaders,\n runtimeConfigLoader: input.runtimeConfigLoader,\n actionExecutor: input.actionExecutor,\n defaults: input.defaults,\n runtimeConfig: input.runtimeConfig,\n runtimeCatalog: input.runtimeCatalog,\n runtimeConfigLoading: input.runtimeConfigLoading,\n runtimeConfigError: input.runtimeConfigError,\n subscription: input.subscription,\n subscriptionHistory: input.subscriptionHistory,\n products: input.products,\n orderHistory: input.orderHistory,\n paymentHistory: input.paymentHistory,\n credits: input.credits,\n entitlements: input.entitlements,\n purchaseStatus: input.purchaseStatus,\n status: input.status,\n refresh: input.refresh,\n runAction: input.runAction,\n setRuntimeConfig: input.setRuntimeConfig,\n setSubscription: input.setSubscription,\n setSubscriptionHistory: input.setSubscriptionHistory,\n setProducts: input.setProducts,\n setOrderHistory: input.setOrderHistory,\n setPaymentHistory: input.setPaymentHistory,\n setCredits: input.setCredits,\n setEntitlements: input.setEntitlements,\n setPurchaseStatus: input.setPurchaseStatus,\n setStatus: input.setStatus,\n };\n}\n\nexport function BillingProvider({\n children,\n apiClient,\n loaders,\n runtimeConfigLoader,\n actionExecutor,\n defaults,\n runtimeConfig: runtimeConfigProp,\n subscription: subscriptionProp,\n subscriptionHistory: subscriptionHistoryProp,\n products: productsProp,\n orderHistory: orderHistoryProp,\n paymentHistory: paymentHistoryProp,\n credits: creditsProp,\n entitlements: entitlementsProp,\n status: statusProp,\n purchaseStatus: purchaseStatusProp,\n autoRefresh = true,\n}: BillingProviderProps) {\n const [runtimeConfig, setRuntimeConfig] = useState<BillingRuntimeConfig | undefined>(normalizeRuntimeConfigInput(runtimeConfigProp));\n const [runtimeCatalog, setRuntimeCatalog] = useState<BillingCatalogConfig | undefined>(normalizeCatalogConfigInput(runtimeConfigProp));\n const [runtimeConfigLoading, setRuntimeConfigLoading] = useState(false);\n const [runtimeConfigError, setRuntimeConfigError] = useState<string | null>(null);\n const [subscription, setSubscription] = useState<BillingSubscriptionState | undefined>(subscriptionProp);\n const [subscriptionHistory, setSubscriptionHistory] = useState<BillingSubscriptionHistoryItem[] | undefined>(subscriptionHistoryProp);\n const [products, setProducts] = useState<BillingProductState[] | undefined>(productsProp);\n const [orderHistory, setOrderHistory] = useState<BillingOrderHistoryItem[] | undefined>(orderHistoryProp);\n const [paymentHistory, setPaymentHistory] = useState<BillingPaymentHistoryItem[] | undefined>(paymentHistoryProp);\n const [credits, setCredits] = useState<BillingCreditsState | undefined>(creditsProp);\n const [entitlements, setEntitlements] = useState<BillingEntitlementState | undefined>(entitlementsProp);\n const [purchaseStatus, setPurchaseStatus] = useState<BillingPurchaseStatus | undefined>(purchaseStatusProp);\n const [status, setStatus] = useState<BillingStatusState>(\n statusProp ?? { loading: false, refreshing: false, error: null },\n );\n\n useEffect(() => {\n if (runtimeConfigProp) {\n setRuntimeConfig(normalizeRuntimeConfigInput(runtimeConfigProp));\n setRuntimeCatalog(normalizeCatalogConfigInput(runtimeConfigProp));\n }\n }, [runtimeConfigProp]);\n\n useEffect(() => {\n if (subscriptionProp) setSubscription(subscriptionProp);\n }, [subscriptionProp]);\n\n useEffect(() => {\n if (subscriptionHistoryProp) setSubscriptionHistory(subscriptionHistoryProp);\n }, [subscriptionHistoryProp]);\n\n useEffect(() => {\n if (productsProp) setProducts(productsProp);\n }, [productsProp]);\n\n useEffect(() => {\n if (orderHistoryProp) setOrderHistory(orderHistoryProp);\n }, [orderHistoryProp]);\n\n useEffect(() => {\n if (paymentHistoryProp) setPaymentHistory(paymentHistoryProp);\n }, [paymentHistoryProp]);\n\n useEffect(() => {\n if (creditsProp) setCredits(creditsProp);\n }, [creditsProp]);\n\n useEffect(() => {\n if (entitlementsProp) setEntitlements(entitlementsProp);\n }, [entitlementsProp]);\n\n useEffect(() => {\n if (purchaseStatusProp) setPurchaseStatus(purchaseStatusProp);\n }, [purchaseStatusProp]);\n\n useEffect(() => {\n if (statusProp) setStatus(statusProp);\n }, [statusProp]);\n\n const refresh = useCallback(async () => {\n const catalogKey = runtimeCatalog?.catalogKey ?? runtimeConfig?.catalogKey ?? 'default';\n const runtimeLoader = runtimeConfigLoader ?? apiClient.fetchRuntimeConfig;\n const resolvedLoaders = loaders ?? {};\n const subscriptionLoader = resolvedLoaders.subscriptionLoader ?? apiClient.fetchSubscription;\n const subscriptionHistoryLoader = resolvedLoaders.subscriptionHistoryLoader ?? apiClient.fetchSubscriptionHistory;\n const productsLoader = resolvedLoaders.productsLoader ?? apiClient.fetchProducts;\n const orderHistoryLoader = resolvedLoaders.orderHistoryLoader ?? apiClient.fetchOrderHistory;\n const paymentHistoryLoader = resolvedLoaders.paymentHistoryLoader ?? apiClient.fetchPaymentHistory;\n const purchaseStatusLoader = resolvedLoaders.purchaseStatusLoader ?? apiClient.fetchPurchaseStatus;\n const creditsLoader = resolvedLoaders.creditsLoader ?? apiClient.fetchCredits;\n const entitlementsLoader = resolvedLoaders.entitlementsLoader ?? apiClient.fetchEntitlements;\n\n setRuntimeConfigLoading(true);\n setRuntimeConfigError(null);\n setStatus((current) => ({ ...current, loading: true, refreshing: true, error: null }));\n\n try {\n const nextRuntimeCatalog = normalizeCatalogConfigInput(await runtimeLoader(catalogKey));\n const nextRuntimeConfig = nextRuntimeCatalog ? normalizeRuntimeConfigInput(nextRuntimeCatalog) : undefined;\n if (nextRuntimeConfig) {\n setRuntimeCatalog(nextRuntimeCatalog);\n setRuntimeConfig(nextRuntimeConfig);\n }\n\n const nextCatalogKey = nextRuntimeConfig?.catalogKey ?? nextRuntimeCatalog?.catalogKey ?? catalogKey;\n\n const [\n nextSubscription,\n nextSubscriptionHistory,\n nextProducts,\n nextOrderHistory,\n nextPaymentHistory,\n nextCredits,\n nextEntitlements,\n ] = await Promise.all([\n subscriptionLoader({ catalogKey: nextCatalogKey }),\n subscriptionHistoryLoader({ catalogKey: nextCatalogKey }),\n productsLoader({ catalogKey: nextCatalogKey }),\n orderHistoryLoader({ catalogKey: nextCatalogKey }),\n paymentHistoryLoader({ catalogKey: nextCatalogKey }),\n creditsLoader({ catalogKey: nextCatalogKey }),\n entitlementsLoader({ catalogKey: nextCatalogKey }),\n ]);\n\n const subscriptionWithProduct = nextSubscription\n ? {\n ...nextSubscription,\n product: resolveBillingSubscriptionProduct(nextSubscription, nextRuntimeConfig ?? runtimeConfig),\n }\n : undefined;\n const normalizedCredits = deriveBillingCreditsState(nextCredits, nextProducts, nextRuntimeConfig?.conversionRules ?? runtimeConfig?.conversionRules);\n const normalizedEntitlements = nextEntitlements ?? deriveBillingEntitlements(subscriptionWithProduct, nextProducts, normalizedCredits, nextRuntimeConfig ?? runtimeConfig);\n const latestOrder = getLatestOrder(nextOrderHistory);\n const latestPayment = getLatestPayment(nextPaymentHistory);\n const fetchedPurchaseStatus = await purchaseStatusLoader({\n orderId: latestOrder?.orderId,\n paymentId: latestPayment?.paymentId,\n transactionId: latestPayment?.transactionId ?? latestOrder?.transactionId,\n }).catch(() => undefined);\n const normalizedPurchaseStatus = normalizeBillingPurchaseStatus(\n fetchedPurchaseStatus,\n latestOrder,\n latestPayment,\n );\n\n setSubscription(subscriptionWithProduct);\n setSubscriptionHistory(nextSubscriptionHistory);\n setProducts(nextProducts);\n setOrderHistory(nextOrderHistory);\n setPaymentHistory(nextPaymentHistory);\n setCredits(normalizedCredits);\n setEntitlements(normalizedEntitlements);\n setPurchaseStatus(normalizedPurchaseStatus);\n setStatus({ loading: false, refreshing: false, error: null, lastFetchedAt: new Date().toISOString() });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n setRuntimeConfigError(message);\n setStatus((current) => ({ ...current, loading: false, refreshing: false, error: message }));\n } finally {\n setRuntimeConfigLoading(false);\n }\n }, [apiClient, loaders, runtimeConfig, runtimeConfigLoader, runtimeCatalog]);\n\n const runAction = useCallback(\n async (payload: BillingActionPayload) => {\n const prepared = buildBillingActionPayload(payload, runtimeConfig);\n const executor = actionExecutor ?? ((input: BillingActionPayload) => apiClient.createAction(input));\n\n setPurchaseStatus((current) => ({\n actionKey: prepared.key,\n orderId: current?.orderId,\n paymentId: current?.paymentId,\n transactionId: current?.transactionId,\n status: 'pending',\n redirectTo: current?.redirectTo,\n updatedAt: new Date().toISOString(),\n }));\n setStatus((current) => ({ ...current, loading: true, refreshing: true, error: null }));\n\n try {\n const result = await executor(prepared);\n setPurchaseStatus((current) => ({\n actionKey: prepared.key,\n orderId: current?.orderId,\n paymentId: current?.paymentId,\n transactionId: current?.transactionId,\n status: result.status === 'failed' ? 'failed' : result.status === 'succeeded' ? 'paid' : 'pending',\n redirectTo: result.redirectTo ?? current?.redirectTo,\n updatedAt: new Date().toISOString(),\n }));\n if (result.redirectTo || result.nextAction) {\n // host handles the redirect/next action, we only persist the result\n }\n await refresh();\n return result;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n setPurchaseStatus((current) => ({\n actionKey: prepared.key,\n orderId: current?.orderId,\n paymentId: current?.paymentId,\n transactionId: current?.transactionId,\n status: 'failed',\n redirectTo: current?.redirectTo,\n updatedAt: new Date().toISOString(),\n }));\n setStatus((current) => ({ ...current, loading: false, refreshing: false, error: message }));\n throw error;\n }\n },\n [actionExecutor, apiClient, refresh, runtimeConfig],\n );\n\n useEffect(() => {\n if (!autoRefresh) return;\n if (runtimeConfigLoading) return;\n if (!runtimeConfig && !runtimeConfigError) {\n void refresh();\n }\n }, [autoRefresh, refresh, runtimeConfig, runtimeConfigError, runtimeConfigLoading]);\n\n const coreValue = useMemo(\n () =>\n buildCoreValue({\n apiClient,\n loaders,\n runtimeConfigLoader,\n actionExecutor,\n defaults,\n runtimeConfig,\n runtimeCatalog,\n runtimeConfigLoading,\n runtimeConfigError,\n subscription,\n subscriptionHistory,\n products,\n orderHistory,\n paymentHistory,\n credits,\n entitlements,\n purchaseStatus,\n status,\n refresh,\n runAction,\n setRuntimeConfig,\n setSubscription,\n setSubscriptionHistory,\n setProducts,\n setOrderHistory,\n setPaymentHistory,\n setCredits,\n setEntitlements,\n setPurchaseStatus,\n setStatus,\n }),\n [\n actionExecutor,\n apiClient,\n credits,\n defaults,\n entitlements,\n orderHistory,\n paymentHistory,\n products,\n purchaseStatus,\n refresh,\n runAction,\n runtimeConfig,\n runtimeConfigError,\n runtimeConfigLoader,\n runtimeConfigLoading,\n runtimeCatalog,\n loaders,\n status,\n subscription,\n subscriptionHistory,\n ],\n );\n\n return (\n <BillingCoreContext.Provider value={coreValue}>\n <SubscriptionProvider subscription={subscription} subscriptionHistory={subscriptionHistory} entitlements={entitlements} status={status}>\n <ProductProvider products={products} orderHistory={orderHistory} paymentHistory={paymentHistory} status={status}>\n <CreditsProvider credits={credits} status={status}>{children}</CreditsProvider>\n </ProductProvider>\n </SubscriptionProvider>\n </BillingCoreContext.Provider>\n );\n}\n\nexport function BillingCoreProvider(props: BillingCoreProviderProps) {\n return <BillingProvider {...props} />;\n}\n\nexport function SubscriptionProvider({\n children,\n availablePlans,\n subscription,\n subscriptionHistory,\n entitlements,\n status,\n}: BillingSubscriptionProviderProps) {\n const core = useOptionalContext(BillingCoreContext);\n const value = useMemo<BillingSubscriptionContextValue>(\n () => ({\n availablePlans: choose(availablePlans, core?.runtimeConfig?.items?.filter((item) => item.kind === 'subscription')),\n subscription: choose(subscription, core?.subscription),\n subscriptionHistory: choose(subscriptionHistory, core?.subscriptionHistory),\n entitlements: choose(entitlements, core?.entitlements),\n status: choose(status, core?.status),\n }),\n [availablePlans, core?.entitlements, core?.runtimeConfig?.items, core?.status, core?.subscription, core?.subscriptionHistory, entitlements, status, subscription, subscriptionHistory],\n );\n\n return <BillingSubscriptionContext.Provider value={value}>{children}</BillingSubscriptionContext.Provider>;\n}\n\nexport function ProductProvider({\n children,\n availableProducts,\n products,\n orderHistory,\n paymentHistory,\n status,\n}: BillingProductProviderProps) {\n const core = useOptionalContext(BillingCoreContext);\n const value = useMemo<BillingProductContextValue>(\n () => ({\n availableProducts: choose(availableProducts, core?.runtimeConfig?.items?.filter((item) => item.kind === 'product' || item.kind === 'credits')),\n products: choose(products, core?.products),\n orderHistory: choose(orderHistory, core?.orderHistory),\n paymentHistory: choose(paymentHistory, core?.paymentHistory),\n status: choose(status, core?.status),\n }),\n [availableProducts, core?.orderHistory, core?.paymentHistory, core?.products, core?.runtimeConfig?.items, core?.status, orderHistory, paymentHistory, products, status],\n );\n\n return <BillingProductContext.Provider value={value}>{children}</BillingProductContext.Provider>;\n}\n\nexport function CreditsProvider({ children, credits, status }: BillingCreditsProviderProps) {\n const core = useOptionalContext(BillingCoreContext);\n const value = useMemo<BillingCreditsContextValue>(\n () => ({\n credits: choose(credits, core?.credits),\n status: choose(status, core?.status),\n }),\n [credits, core?.credits, core?.status, status],\n );\n\n return <BillingCreditsContext.Provider value={value}>{children}</BillingCreditsContext.Provider>;\n}\n\nexport interface BillingCatalogState {\n catalog?: BillingRuntimeConfig | BillingCatalogConfig;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingContext(): BillingCoreContextValue {\n return useRequiredCoreContext();\n}\n\nexport function useBillingCatalog(): BillingCatalogState {\n const core = useRequiredCoreContext();\n return useMemo(\n () => ({\n catalog: core.runtimeCatalog ?? core.runtimeConfig,\n loading: core.runtimeConfigLoading,\n error: core.runtimeConfigError,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeCatalog, core.runtimeConfig, core.runtimeConfigError, core.runtimeConfigLoading],\n );\n}\n\nexport interface BillingItemState {\n item?: BillingProductSnapshot;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingItem(itemKey: string): BillingItemState {\n const core = useRequiredCoreContext();\n return useMemo(() => {\n const item = resolveBillingItem(core.runtimeConfig?.items, itemKey);\n return {\n item: resolveBillingProductSnapshot(item),\n loading: core.runtimeConfigLoading,\n error: core.runtimeConfigError,\n refresh: core.refresh,\n };\n }, [core.refresh, core.runtimeConfig?.items, core.runtimeConfigError, core.runtimeConfigLoading, itemKey]);\n}\n\nexport interface BillingProductsState {\n products: BillingProductState[];\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingProducts(options: { userId?: string; catalogKey?: string; kind?: 'product' | 'credits' } = {}): BillingProductsState {\n const core = useRequiredCoreContext();\n const productContext = useOptionalContext(BillingProductContext);\n const products = choose(productContext?.products, core.products) ?? [];\n return useMemo(\n () => ({\n products: filterProductsByKind(products, options.kind),\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, options.kind, products],\n );\n}\n\nexport interface BillingAvailablePlansState {\n plans: BillingItem[];\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingAvailablePlans(): BillingAvailablePlansState {\n const core = useRequiredCoreContext();\n const subscriptionContext = useOptionalContext(BillingSubscriptionContext);\n const plans = choose(subscriptionContext?.availablePlans, core.runtimeConfig?.items?.filter((item) => item.kind === 'subscription')) ?? [];\n return useMemo(\n () => ({\n plans,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfig?.items, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, plans],\n );\n}\n\nexport interface BillingAvailableProductsState {\n items: BillingItem[];\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingAvailableProducts(): BillingAvailableProductsState {\n const core = useRequiredCoreContext();\n const productContext = useOptionalContext(BillingProductContext);\n const items = choose(productContext?.availableProducts, core.runtimeConfig?.items?.filter((item) => item.kind === 'product' || item.kind === 'credits')) ?? [];\n return useMemo(\n () => ({\n items,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfig?.items, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, items],\n );\n}\n\nexport interface BillingOrderHistoryState {\n orders: BillingOrderHistoryItem[];\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingOrderHistory(_options: { userId?: string; catalogKey?: string; productKey?: string } = {}): BillingOrderHistoryState {\n const core = useRequiredCoreContext();\n const productContext = useOptionalContext(BillingProductContext);\n const orders = choose(productContext?.orderHistory, core.orderHistory) ?? [];\n return useMemo(\n () => ({\n orders,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, orders],\n );\n}\n\nexport interface BillingPaymentHistoryState {\n payments: BillingPaymentHistoryItem[];\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingPaymentHistory(_options: { userId?: string; catalogKey?: string } = {}): BillingPaymentHistoryState {\n const core = useRequiredCoreContext();\n const productContext = useOptionalContext(BillingProductContext);\n const payments = choose(productContext?.paymentHistory, core.paymentHistory) ?? [];\n return useMemo(\n () => ({\n payments,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, payments],\n );\n}\n\nexport interface BillingSubscriptionStateView {\n subscription?: BillingSubscriptionState;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingSubscription(): BillingSubscriptionStateView {\n const core = useRequiredCoreContext();\n const subscriptionContext = useOptionalContext(BillingSubscriptionContext);\n return useMemo(\n () => ({\n subscription: choose(subscriptionContext?.subscription, core.subscription),\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, core.subscription, subscriptionContext?.subscription],\n );\n}\n\nexport interface BillingSubscriptionProductState {\n product?: BillingProductSnapshot;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingSubscriptionProduct(): BillingSubscriptionProductState {\n const core = useRequiredCoreContext();\n const subscriptionContext = useOptionalContext(BillingSubscriptionContext);\n const subscription = choose(subscriptionContext?.subscription, core.subscription);\n return useMemo(\n () => ({\n product: subscription?.product ?? resolveBillingSubscriptionProduct(subscription, core.runtimeConfig),\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfig, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, subscription],\n );\n}\n\nexport interface BillingSubscriptionHistoryState {\n history: BillingSubscriptionHistoryItem[];\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingSubscriptionHistory(_options: { userId?: string; catalogKey?: string } = {}): BillingSubscriptionHistoryState {\n const core = useRequiredCoreContext();\n const subscriptionContext = useOptionalContext(BillingSubscriptionContext);\n const history = choose(subscriptionContext?.subscriptionHistory, core.subscriptionHistory) ?? [];\n return useMemo(\n () => ({\n history,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, history],\n );\n}\n\nexport interface BillingCreditsStateView {\n credits?: BillingCreditsState;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingCredits(): BillingCreditsStateView {\n const core = useRequiredCoreContext();\n const creditsContext = useOptionalContext(BillingCreditsContext);\n const credits = choose(creditsContext?.credits, core.credits) ?? deriveBillingCreditsState(undefined, core.products, core.runtimeConfig?.conversionRules);\n return useMemo(\n () => ({\n credits,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfig?.conversionRules, core.runtimeConfigError, core.runtimeConfigLoading, core.products, core.status.error, core.status.loading, credits],\n );\n}\n\nexport interface BillingEntitlementsStateView {\n entitlements?: BillingEntitlementState;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingEntitlements(): BillingEntitlementsStateView {\n const core = useRequiredCoreContext();\n const subscriptionContext = useOptionalContext(BillingSubscriptionContext);\n const entitlements =\n choose(subscriptionContext?.entitlements, core.entitlements) ??\n deriveBillingEntitlements(subscriptionContext?.subscription ?? core.subscription, core.products, core.credits, core.runtimeConfig);\n return useMemo(\n () => ({\n entitlements,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.credits, core.products, core.refresh, core.runtimeConfig, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, entitlements, subscriptionContext?.subscription, core.subscription],\n );\n}\n\nexport interface BillingPurchaseStatusView {\n purchaseStatus?: BillingPurchaseStatus;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingPurchaseStatus(): BillingPurchaseStatusView {\n const core = useRequiredCoreContext();\n const productContext = useOptionalContext(BillingProductContext);\n const order = getLatestOrder(choose(productContext?.orderHistory, core.orderHistory));\n const payment = getLatestPayment(choose(productContext?.paymentHistory, core.paymentHistory));\n const purchaseStatus = core.purchaseStatus ?? normalizeBillingPurchaseStatus(undefined, order, payment);\n return useMemo(\n () => ({\n purchaseStatus,\n loading: core.runtimeConfigLoading || core.status.loading,\n error: core.runtimeConfigError ?? core.status.error,\n refresh: core.refresh,\n }),\n [core.purchaseStatus, core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, order, payment, purchaseStatus],\n );\n}\n\nexport interface BillingStatusView {\n status: BillingStatusState;\n}\n\nexport function useBillingStatus(): BillingStatusView {\n const core = useRequiredCoreContext();\n return useMemo(() => ({ status: core.status }), [core.status]);\n}\n\nexport interface BillingRefreshView {\n refresh: () => Promise<void>;\n}\n\nexport function useBillingRefresh(): BillingRefreshView {\n const core = useRequiredCoreContext();\n return useMemo(() => ({ refresh: core.refresh }), [core.refresh]);\n}\n\nexport interface BillingPipelineResult {\n run: (payload: BillingActionPayload) => Promise<void>;\n loading: boolean;\n error: string | null;\n purchaseStatus?: BillingPurchaseStatus;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingPipeline(options: BillingPipelineOptions = {}): BillingPipelineResult {\n const core = useRequiredCoreContext();\n const purchaseStatusView = useBillingPurchaseStatus();\n\n const run = useCallback(\n async (payload: BillingActionPayload) => {\n const prepared = options.onBeforeAction ? await options.onBeforeAction(payload) : payload;\n try {\n const result = await core.runAction(prepared);\n if (options.onAfterAction) {\n await options.onAfterAction({ redirectTo: result.redirectTo, nextAction: result.nextAction });\n }\n } catch (error) {\n if (options.onError) {\n await options.onError(error);\n }\n throw error;\n }\n },\n [core, options],\n );\n\n return useMemo(\n () => ({\n run,\n loading: core.status.loading || core.runtimeConfigLoading,\n error: core.status.error ?? core.runtimeConfigError,\n purchaseStatus: purchaseStatusView.purchaseStatus,\n refresh: core.refresh,\n }),\n [core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, purchaseStatusView.purchaseStatus, run],\n );\n}\n\nexport interface BillingActionHookResult {\n run: (payload: BillingActionPayload) => Promise<void>;\n loading: boolean;\n error: string | null;\n}\n\nfunction useBillingActionRunner(kind: BillingActionKind, defaults?: Partial<BillingActionPayload>): BillingActionHookResult {\n const pipeline = useBillingPipeline();\n const run = useCallback(\n async (payload: BillingActionPayload) => {\n await pipeline.run({\n ...defaults,\n ...payload,\n kind,\n });\n },\n [defaults, kind, pipeline],\n );\n\n return useMemo(\n () => ({\n run,\n loading: pipeline.loading,\n error: pipeline.error,\n }),\n [pipeline.error, pipeline.loading, run],\n );\n}\n\nexport function useSubscribePlan(): BillingActionHookResult {\n return useBillingActionRunner('subscribe');\n}\n\nexport function useManageSubscription(): BillingActionHookResult {\n return useBillingActionRunner('manage');\n}\n\nexport function useUpgradePlan(): BillingActionHookResult {\n return useBillingActionRunner('upgrade');\n}\n\nexport function useCancelSubscription(): BillingActionHookResult {\n return useBillingActionRunner('cancel');\n}\n\nexport function usePurchaseCredits(): BillingActionHookResult {\n return useBillingActionRunner('purchase');\n}\n\nexport function usePurchaseProduct(): BillingActionHookResult {\n return useBillingActionRunner('purchase');\n}\n\nexport interface BillingProductStateView {\n product?: BillingProductState;\n loading: boolean;\n error: string | null;\n refresh: () => Promise<void>;\n}\n\nexport function useBillingProduct(productKey: string): BillingProductStateView {\n const productsState = useBillingProducts();\n const product = productsState.products.find((item) => item.productKey === productKey);\n return useMemo(\n () => ({\n product,\n loading: productsState.loading,\n error: productsState.error,\n refresh: productsState.refresh,\n }),\n [product, productsState.error, productsState.loading, productsState.refresh],\n );\n}\n\nexport function useBillingCatalogConfig(): BillingCatalogState {\n return useBillingCatalog();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAIA,SAAS,uBAAuB;AASvB;AAPF,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAC,mBAAgB,SAAmB,UAAS;AACtD;;;ACZA,SAAS,kBAAkB;AA8B3B,SAAS,eAAe,SAA0D;AAChF,QAAM,OAAO,SAAS;AACtB,QAAM,OAAO,MAAM,QAAQ;AAC3B,QAAM,kBAAkB,QAAQ,IAAI;AACpC,QAAM,UAAU,QAAQ,MAAM,OAAO;AACrC,QAAM,OAAiB,CAAC,kBAAkB,UAAU,UAAU,UAAU;AAExE,SAAO;AAAA,IACL,IAAI,MAAM,MAAM;AAAA,IAChB;AAAA,IACA,O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,SAAS,cAAc,OAAO,cAAc,SAAS,cAAc,OAAO;AAAA,EAC7E;AACF;AAEO,SAAS,0BAA+C;AAC7D,SAAO,kBAAkB;AAC3B;","names":["jsx"]}
@@ -0,0 +1,158 @@
1
+ ---
2
+ name: casdoor-next-auth-kit
3
+ description: Use when maintaining the shared Casdoor auth kit, generated route shells, React auth hooks, or the host-project skill installation flow.
4
+ metadata:
5
+ short-description: Shared Casdoor auth kit source of truth
6
+ ---
7
+
8
+ # Casdoor Next Auth Kit
9
+
10
+ 本 skill 用于维护可复用的 `@foldspace-fe/casdoor-next-auth-kit` 认证套件仓库,以及消费该套件的宿主项目。当用户需要修改认证流程、路由壳模板、React 认证钩子、或执行宿主项目的 skill 安装流程时,应激活此 skill。
11
+
12
+ ## 源码仓库
13
+
14
+ - 仓库路径:`/root/projects/foldspace-stack/casdoor-next-auth-kit`
15
+ - 包名:`@foldspace-fe/casdoor-next-auth-kit`
16
+ - 宿主项目副本位置:`.agents/skills/casdoor-next-auth-kit/`
17
+
18
+ 所有认证相关的源码、模板和配置均以上述仓库为唯一真相来源。宿主项目通过 CLI 工具获取生成物,不应直接修改套件内部代码。
19
+
20
+ ## 支持的命令
21
+
22
+ ```bash
23
+ npx @foldspace-fe/casdoor-next-auth-kit init # 初始化:安装 skill、生成路由壳、配置 Next.js
24
+ npx @foldspace-fe/casdoor-next-auth-kit update # 更新:重新生成路由壳、同步 skill 文件
25
+ npx @foldspace-fe/casdoor-next-auth-kit check # 检查:验证宿主项目配置与生成物是否一致
26
+ ```
27
+
28
+ `init` 会将整个 skill 目录复制到宿主项目的 `.agents/skills/` 目录,并在宿主项目中生成路由壳文件。`update` 用于套件升级后同步变更。`check` 用于 CI 或手动验证,确保宿主项目未偏离套件的预期状态。
29
+
30
+ ### 宿主项目里的用法
31
+
32
+ 在宿主项目根目录执行下面的命令,不要在源码仓库内对宿主目录做手工 copy:
33
+
34
+ ```bash
35
+ npx @foldspace-fe/casdoor-next-auth-kit init
36
+ npx @foldspace-fe/casdoor-next-auth-kit update
37
+ npx @foldspace-fe/casdoor-next-auth-kit check
38
+ ```
39
+
40
+ - `init` 适合第一次接入宿主项目,缺少受管路由壳、`.env*`、`prisma/auth-kit.prisma` 或 skill 副本时使用
41
+ - `update` 适合本仓库源码变更后,或宿主项目安装到新版本后使用
42
+ - `check` 不会改文件,只做一致性校验,适合在 CI 或手动排查时执行
43
+
44
+ 如果宿主项目使用的是本地 `file:` 依赖或工作区链接,先在本仓库执行 `pnpm build`,再回到宿主项目执行 `pnpm install` 或 `npx @foldspace-fe/casdoor-next-auth-kit update`,否则可能看到旧产物。
45
+
46
+ ## 套件提供的功能
47
+
48
+ - `AuthProvider` — React 认证上下文 Provider,包裹整个应用提供会话状态
49
+ - `useAuthSession` — 获取当前 NextAuth 会话对象
50
+ - `useAuthUser` — 获取当前登录用户信息(含 Casdoor 用户字段)
51
+ - `useAuthRole` — 获取当前用户的角色信息,用于权限判断
52
+ - `useAuthActions` — 提供登录、注册、注销等认证操作方法
53
+ - Casdoor 登录 / 注册入口处理器 — 处理用户进入认证流程的初始交互
54
+ - callback / logout / nextauth 路由处理器 — 处理 OAuth 回调、注销和 NextAuth 路由请求
55
+ - 无头电商代理处理器 — 将电商相关 API 请求代理到后端服务
56
+ - 宿主路由壳模板 — 为宿主项目生成 Next.js 路由页面模板,统一认证 UI 体验
57
+ - 数据库契约和同步接口 — 定义宿主项目必须实现的用户数据字段和同步行为
58
+ - `BillingProvider` / `BillingCoreProvider` — headless billing runtime 的根 Provider
59
+ - `SubscriptionProvider` / `ProductProvider` / `CreditsProvider` — 分域 billing Provider,按需注入订阅、商品和额度状态
60
+ - `useBillingAvailablePlans` / `useBillingAvailableProducts` — 从配置或注入的 catalog 中读取可订阅套餐和可购买商品列表
61
+ - `useBillingSubscription` / `useBillingSubscriptionHistory` / `useBillingSubscriptionProduct` — 查看当前订阅、订阅历史和当前订阅对应产品
62
+ - `useBillingProducts` / `useBillingProduct` / `useBillingOrderHistory` / `useBillingPaymentHistory` — 查看商品状态、订单历史和支付历史
63
+ - `useBillingCredits` / `useBillingEntitlements` / `useBillingPurchaseStatus` — 查看额度、权益和归一化购买状态
64
+ - `useSubscribePlan` / `usePurchaseProduct` / `usePurchaseCredits` — 发起订阅、虚拟商品购买和积分购买动作
65
+ - `useBillingRefresh` / `useBillingPipeline` — 刷新 billing 状态和编排动作执行链路
66
+
67
+ ## 路由模型
68
+
69
+ 认证套件采用同源路由架构,所有认证相关页面均在宿主应用域名下呈现:
70
+
71
+ - `/auth/login` — 宿主项目的登录入口路由,用户点击登录后进入此页面
72
+ - `/auth/signup` — 宿主项目的注册入口路由,用户点击注册后进入此页面
73
+ - `/login/oauth/authorize` — 同源登录授权壳,宿主项目渲染 Casdoor 的登录表单界面
74
+ - `/signup/oauth/authorize` — 同源注册授权壳,宿主项目渲染 Casdoor 的注册表单界面
75
+ - `/callback` — OAuth 回调路由,处理 Casdoor 认证成功后的回调
76
+ - `/logout` — 注销路由,清除会话并跳转
77
+ - `/auth/api/*` — Casdoor API 代理,所有个人操作的 API 请求通过此路径转发
78
+
79
+ 入口路由(login/signup)负责将用户引导至授权壳,授权壳在同源 iframe 或内嵌组件中渲染 Casdoor 界面,避免用户感知到离开宿主应用。
80
+
81
+ ## UX 边界
82
+
83
+ - 保持 Casdoor 认证体验完全内嵌于宿主应用,用户不应感知到"跳转到另一个网站"
84
+ - 优先使用同源路由壳和代理处理器,而非直接让浏览器导航到 Casdoor 原始页面
85
+ - 宿主用户应体验到一个统一的应用,不应看到宿主 UI 和 Casdoor UI 之间的割裂
86
+ - 所有认证交互(登录、注册、MFA、密码重置等)均应在宿主应用域名下完成
87
+
88
+ ## 数据库边界
89
+
90
+ - 套件定义必需的用户字段、同步行为和适配器接口(契约),但不实现持久化
91
+ - 宿主项目拥有 Prisma schema、迁移脚本和持久化实现的完全控制权
92
+ - 业务特有的数据表和写入逻辑应保留在宿主项目中,不应混入认证套件
93
+ - 套件通过接口约定宿主项目必须提供哪些字段(如 Casdoor 用户 ID、用户名等),宿主项目自行决定存储方式
94
+
95
+ ## Skill 分发流程
96
+
97
+ 1. 在独立仓库中更新此 skill 目录中的 `SKILL.md`、`references/` 和相关源码
98
+ 2. 使用 `scripts/install-skill.mjs` 将整个 skill 目录复制到宿主项目的 `.agents/skills/` 目录
99
+ 3. 如果生成的路由壳文件有变更,重新运行宿主项目的检查命令确认一致性
100
+
101
+ ### 更新成功的排查方法
102
+
103
+ 当你执行 `npx @foldspace-fe/casdoor-next-auth-kit update` 后,可以按下面顺序确认是否真的生效:
104
+
105
+ 1. 先看终端输出
106
+ - 成功更新时,CLI 会输出 `Updated managed route shells, env files, and skill file.`
107
+ - 如果有文件变化,会额外打印 `+`、`~` 或 `-` 的路径列表
108
+ 2. 再运行一致性检查
109
+ - `npx @foldspace-fe/casdoor-next-auth-kit check`
110
+ - 成功时应输出 `All managed files are present.`
111
+ 3. 核对受管文件是否已经刷新
112
+ - `app/(auth-kit)/...`
113
+ - `prisma/auth-kit.prisma`
114
+ - `.env`、`.env.local`、`.env.production`、`.env.example`
115
+ - `.agents/skills/casdoor-next-auth-kit/SKILL.md`
116
+ 4. 如果 `check` 仍然报缺失,优先排查这些问题
117
+ - 宿主项目还没重新安装到新的包产物,先回到本仓库执行 `pnpm build`
118
+ - 宿主项目没重新安装依赖,执行 `pnpm install` 后再跑一次 `update`
119
+ - 当前目录不是宿主项目根目录,CLI 写到了错误位置
120
+ - 旧的受管文件仍然存在,需要先让 `update` 完成删除和重建,再执行 `check`
121
+
122
+ 分发流程确保宿主项目始终从独立仓库获取最新的 skill 定义、参考资料和生成物,避免各宿主项目各自维护不一致的认证配置。
123
+
124
+ ## API 参考
125
+
126
+ - `references/casdoor-api-reference.md` — Casdoor 个人操作 API 参考(markdown 格式,路径含 `/auth/` 前缀)
127
+ - `references/swagger.json` — 相同内容的 Swagger 2.0 格式(仅包含个人相关端点,已过滤管理类 API)
128
+
129
+ 这两个参考文件覆盖了认证套件通过 `/auth/api/*` 代理的 Casdoor API 端点。利用它们可以了解套件的无头代理处理器支持哪些面向个人用户的操作(账户管理、登录注册、商品购买、订单查询、支付、订阅等)。
130
+
131
+ ## Billing Headless 参考
132
+
133
+ Billing headless 能力的方案、接口草案和设计图已经放在仓库文档中:
134
+
135
+ - `docs/billing/README.md` — billing 分类文档入口和功能总览
136
+ - `docs/billing/examples/billing-catalog.example.ts` — billing catalog 配置示例
137
+ - `docs/billing/examples/pricing-section.example.tsx` — pricing section 页面骨架示例
138
+ - `docs/billing/examples/order-history-page.example.tsx` — 订单和订阅历史页面骨架示例
139
+ - `docs/billing/examples/mock-billing-api-client.example.ts` — mock api client 示例
140
+
141
+ Billing 的宿主接入方式是:
142
+
143
+ 1. 在宿主应用里通过 `BillingProvider` 注入 `runtimeConfig` 或显式的 `availablePlans` / `availableProducts`
144
+ 2. 使用 `useSubscribePlan`、`usePurchaseProduct`、`usePurchaseCredits` 发起动作
145
+ 3. 使用 `useBillingSubscription`、`useBillingOrderHistory`、`useBillingPaymentHistory`、`useBillingCredits` 查看状态
146
+ 4. 使用 `useBillingPipeline` 或 `actionExecutor` 接入宿主自己的支付、跳转和后端编排逻辑
147
+
148
+ Billing 只面向数字商品和 SaaS 订阅,不包含 UI 组件,也不包含物流、地址、发货或其他非商品功能。
149
+
150
+ ## 宿主项目集成要点
151
+
152
+ - 优先使用套件提供的 React 钩子(如 `useAuthSession`、`useAuthActions`),而非直接导入 `next-auth/react`
153
+ - 保持宿主路由壳文件尽量简洁,认证逻辑应由套件内部处理
154
+ - 使用套件 CLI 工具管理生成文件,不要手动修改生成的路由壳代码
155
+ - 宿主项目的 AGENTS.md 应指向此仓库,以便 AI 代理获取最新上下文
156
+ - Billing 相关接入优先导入 `@foldspace-fe/casdoor-next-auth-kit/react` 和 `@foldspace-fe/casdoor-next-auth-kit/billing`
157
+ - Billing 的可购买列表优先由宿主配置注入,必要时再由 runtimeConfig 派生,而不是在页面里硬编码
158
+ - Billing 只应基于 `references/swagger.json` 的个人相关端点和宿主编排实现,不要把管理侧 API 当成运行时依赖