holy-agents-kits 0.1.0 → 0.2.0
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.
- package/README.md +48 -16
- package/bin/cli.js +2 -2
- package/package.json +2 -1
- package/skills/fy-new-api-app-framework/SKILL.md +148 -0
- package/skills/fy-new-api-app-framework/references/pitfalls.md +14 -0
- package/skills/fy-new-api-app-framework/references/playbook.md +188 -0
- package/skills/fy-new-api-app-framework/references/standards/admin-dashboard.md +420 -0
- package/skills/fy-new-api-app-framework/references/standards/api-contract.md +277 -0
- package/skills/fy-new-api-app-framework/references/standards/billing.md +449 -0
- package/skills/fy-new-api-app-framework/references/standards/daisyui.md +258 -0
- package/skills/fy-new-api-app-framework/references/standards/identity.md +401 -0
- package/skills/fy-new-api-app-framework/references/standards/local-acceptance.md +75 -0
- package/skills/fy-new-api-app-framework/references/standards/nextjs.md +200 -0
- package/skills/fy-new-api-app-framework/references/standards/relay.md +73 -0
- package/skills/fy-new-api-app-framework/references/standards/security.md +52 -0
- package/skills/fy-new-api-app-framework/references/standards/supabase.md +347 -0
- package/skills/fy-new-api-app-framework/references/standards/ui-ux.md +191 -0
- package/skills/fy-new-api-app-framework/references/standards/vercel.md +185 -0
- package/skills/fy-new-api-app-framework/references/vendor/README.md +102 -0
- package/skills/fy-new-api-app-framework/references/vendor/nextjs-react-typescript/SKILL.md +52 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/AGENTS.md +3750 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/README.md +123 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/SKILL.md +148 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/_sections.md +46 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/_template.md +28 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/advanced-effect-event-deps.md +56 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/async-api-routes.md +38 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/async-defer-await.md +82 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/async-dependencies.md +51 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/async-parallel.md +28 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/bundle-barrel-imports.md +60 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/bundle-preload.md +50 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-early-exit.md +50 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-flatmap-filter.md +60 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-index-maps.md +37 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-request-idle-callback.md +105 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-activity.md +26 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-resource-hints.md +85 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-script-defer-async.md +68 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-memo.md +44 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-no-inline-components.md +82 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-use-deferred-value.md +59 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-cache-react.md +76 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-hoist-static-io.md +149 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-no-shared-module-state.md +50 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-parallel-nested-fetching.md +34 -0
- package/skills/fy-new-api-app-framework/references/vendor/vercel-react-best-practices/rules/server-serialization.md +38 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/.vercelignore +10 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/AGENTS.md +44 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/README.md +152 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/bun.lock +1141 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/eslint.config.mjs +18 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/next.config.ts +16 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/package.json +46 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/public/file.svg +1 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/public/globe.svg +1 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/public/next.svg +1 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/public/vercel.svg +1 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/public/window.svg +1 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/scripts/bootstrap.ps1 +319 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/scripts/seed-assets.ts +274 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/characters/_components/CharactersClient.tsx +249 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/characters/page.tsx +58 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/history/page.tsx +91 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/layout.tsx +91 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/poses/page.tsx +177 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/profile/_components/Catalog.tsx +113 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/profile/_components/Payments.tsx +248 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/profile/_components/ProfileClient.tsx +193 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/profile/_components/__tests__/profile.browser.test.mjs +615 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/profile/_components/profile-data.ts +157 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/profile/_components/use-gateway-resource.ts +30 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/profile/page.tsx +27 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/studio/_components/StudioClient.tsx +732 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/studio/page.tsx +158 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/wardrobe/_components/PersonalWardrobeClient.tsx +178 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/(consumer)/wardrobe/page.tsx +249 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/__tests__/interactions.test.js +162 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/_components/admin-request.ts +22 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/_components/layout-inner.tsx +112 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/_components/page-header.tsx +10 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/_components/responsive-pagination.tsx +29 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/characters/page.tsx +60 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/generations/page.tsx +264 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/layout.tsx +54 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/models/page.tsx +265 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/outfits/page.tsx +179 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/page.tsx +143 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/plans/page.tsx +3 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/poses/page.tsx +97 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/admin/prompts/page.tsx +212 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/admin/[table]/route.ts +137 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/admin/__tests__/security.test.js +203 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/admin/gateway-models/route.ts +18 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/admin/generation-references/route.ts +103 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/admin/signed-url/route.ts +22 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/admin/stats/route.ts +67 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/auth/logout/route.ts +12 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/characters/route.ts +124 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/gateway/catalog/route.ts +8 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/gateway/checkout/route.ts +14 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/gateway/logs/route.ts +17 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/gateway/payment-methods/route.ts +8 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/gateway/topup/route.ts +14 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/gateway/userinfo/route.ts +8 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/generate/[id]/advance/route.ts +30 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/generate/__tests__/route.test.js +163 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/generate/quote/route.ts +69 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/generate/route.ts +151 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/media/[bucket]/[...path]/route.ts +36 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/models/route.ts +50 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/outfits/__tests__/route.test.js +168 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/api/outfits/route.ts +160 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/auth/callback/route.ts +75 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/favicon.ico +0 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/globals.css +4 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/layout.tsx +16 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/login/page.tsx +23 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/app/page.tsx +8 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/components/CharacterUploader.tsx +224 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/components/GarmentUploader.tsx +245 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/components/MediaCard.tsx +83 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/components/login-card.tsx +80 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/components/logout-button.tsx +40 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/__tests__/gateway.test.js +831 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/__tests__/media.test.js +150 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/admin/requireAdmin.ts +36 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/config.ts +27 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/constants.ts +11 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/gateway-bff.ts +26 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/gateway-contract.ts +72 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/gateway-errors.ts +139 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/gateway-session.ts +270 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/gateway.ts +610 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/generated-image.test.mjs +33 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/generated-image.ts +124 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/media-urls.ts +46 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/storage.ts +12 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/supabase/admin.ts +18 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/supabase/client.ts +20 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/supabase/server.ts +33 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/advance.test.js +217 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/image.test.js +70 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/manifest.test.js +49 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/orchestrate.test.js +162 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/parse-garment.test.js +167 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/persona.test.js +176 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/quote.test.js +46 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/recognize.test.js +101 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/rollback.test.js +81 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/__tests__/wear.test.js +100 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/advance.ts +223 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/image.ts +108 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/manifest.ts +29 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/models.ts +46 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/orchestrate.ts +202 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/parse-garment.ts +203 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/persona.ts +138 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/pricing.ts +150 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/prompts.ts +63 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/quote.ts +32 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/recognize.ts +131 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/rollback.ts +72 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/tryon/wear.ts +151 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/lib/types.ts +215 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/src/proxy.ts +42 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/config.toml +426 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/fix_client_id_fn.sql +19 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261110000001_init_schema.sql +224 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261110000002_add_models_and_prompt_templates.sql +109 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261110000003_gateway_sessions.sql +84 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261110000004_admin_scope.sql +219 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261110000005_private_media.sql +51 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261111000006_model_usage_image_vision.sql +145 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261111000007_personal_garments_and_pipeline.sql +157 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261111000008_tryon_temp_storage_rls.sql +33 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/supabase/migrations/20261111000009_pose_snapshot.sql +6 -0
- package/skills/fy-new-api-app-framework/references/web/outfit-demo/tsconfig.json +34 -0
- package/skills/fy-new-api-app-framework/scripts/bootstrap.ps1 +289 -0
- package/skills/fy-new-api-app-framework/scripts/bootstrap.sh +397 -0
- package/skills/fy-new-api-app-framework/scripts/check-env.ps1 +298 -0
- package/skills/fy-new-api-app-framework/scripts/check-env.sh +255 -0
- package/skills/fy-newapi-cli/SKILL.md +139 -0
- package/skills/fy-newapi-cli/references/api.md +53 -0
- package/skills/fy-newapi-cli/references/commands.md +143 -0
- package/skills/fy-newapi-cli/references/scopes.md +30 -0
- package/skills/{jenkins-ci → jenkins-cli}/SKILL.md +2 -2
- package/skills/jenkins-controller/SKILL.md +2 -2
- package/skills/jenkins-controller/references/troubleshooting.md +1 -1
- package/skills/skill-creator-v2/scripts/__pycache__/skill_schema.cpython-313.pyc +0 -0
- package/skills/skill-creator-v2/scripts/skill_schema.py +2 -1
- package/skills/skill-creator-v2/scripts/__pycache__/skill_schema.cpython-39.pyc +0 -0
- /package/skills/{jenkins-ci → jenkins-cli}/references/dood-and-gitlab.md +0 -0
- /package/skills/{jenkins-ci → jenkins-cli}/references/lint-rules.md +0 -0
- /package/skills/{jenkins-ci → jenkins-cli}/references/pipeline-authoring.md +0 -0
- /package/skills/{jenkins-ci → jenkins-cli}/references/troubleshooting.md +0 -0
- /package/skills/{jenkins-ci → jenkins-cli}/scripts/generate_shared_library.py +0 -0
- /package/skills/{jenkins-ci → jenkins-cli}/scripts/validate_jenkinsfile.py +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# holy-agents-kits
|
|
2
2
|
|
|
3
|
-
> 一组可直接加载的 Agent Skill:Jenkins
|
|
3
|
+
> 一组可直接加载的 Agent Skill:Jenkins 流水线与控制器、基于 new-api 的应用开发与命令行运维、Skill 本身怎么开发与校验。
|
|
4
4
|
> 一条命令装进你的 agent。
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
7
|
npx holy-agents-kits list
|
|
8
|
-
npx holy-agents-kits install jenkins-
|
|
8
|
+
npx holy-agents-kits install jenkins-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## 技能一览
|
|
@@ -13,7 +13,7 @@ npx holy-agents-kits install jenkins-ci
|
|
|
13
13
|
```mermaid
|
|
14
14
|
mindmap
|
|
15
15
|
root((holy-agents-kits))
|
|
16
|
-
jenkins-
|
|
16
|
+
jenkins-cli
|
|
17
17
|
写 / 改 Jenkinsfile
|
|
18
18
|
DooD 构建与部署
|
|
19
19
|
GitLab 凭据与 webhook
|
|
@@ -23,6 +23,16 @@ mindmap
|
|
|
23
23
|
宿主 Jenkins 迁移
|
|
24
24
|
nginx 切流与回滚
|
|
25
25
|
全量体检
|
|
26
|
+
fy-new-api-app-framework
|
|
27
|
+
身份接入 OAuth / OIDC
|
|
28
|
+
AI relay 与计费
|
|
29
|
+
Next.js + Supabase + Vercel
|
|
30
|
+
参考 demo 应用
|
|
31
|
+
fy-newapi-cli
|
|
32
|
+
用户 / 渠道 / Token 管理
|
|
33
|
+
日志与服务器选项
|
|
34
|
+
订阅套餐与 OAuth 应用
|
|
35
|
+
无面板脚本化运维
|
|
26
36
|
skill-creator-v2
|
|
27
37
|
Skill 骨架生成
|
|
28
38
|
正文拆分 references
|
|
@@ -32,11 +42,14 @@ mindmap
|
|
|
32
42
|
|
|
33
43
|
| Skill | 解决什么 | 你会怎么说 |
|
|
34
44
|
|---|---|---|
|
|
35
|
-
| `jenkins-
|
|
45
|
+
| `jenkins-cli` | 写/改/校验 Jenkinsfile,DooD 构建部署,接 GitLab | 「帮我写条流水线」「这个 Jenkinsfile 报错」 |
|
|
36
46
|
| `jenkins-controller` | 控制器容器的部署、迁移、切流、口令轮换、体检 | 「Jenkins 容器起不来」「切回宿主机」 |
|
|
47
|
+
| `fy-new-api-app-framework` | 用 new-api 做身份与 AI 网关,开发外部 Web 应用(含参考 demo) | 「用 new-api 做登录」「接 new-api 的计费和充值」 |
|
|
48
|
+
| `fy-newapi-cli` | 在终端运维 new-api:用户、渠道、Token、日志、套餐 | 「登进 new-api 看下渠道」「给它建个 API key」 |
|
|
37
49
|
| `skill-creator-v2` | 开发、拆分、校验、评测 Skill 本身 | 「写一个 skill」「SKILL.md 太长」 |
|
|
38
50
|
|
|
39
|
-
两个 Jenkins 技能互为边界:`jenkins-
|
|
51
|
+
两个 Jenkins 技能互为边界:`jenkins-cli` 只管流水线,`jenkins-controller` 只管控制器本身,触发时不会互相抢。
|
|
52
|
+
两个 new-api 技能同样分工:`fy-new-api-app-framework` 管「在 new-api 外面写应用」,`fy-newapi-cli` 管「运维已经在跑的 new-api」。
|
|
40
53
|
|
|
41
54
|
## 安装
|
|
42
55
|
|
|
@@ -45,16 +58,16 @@ mindmap
|
|
|
45
58
|
npx holy-agents-kits list
|
|
46
59
|
|
|
47
60
|
# 安装指定 skill(默认装到 ~/.agents/skills)
|
|
48
|
-
npx holy-agents-kits install jenkins-
|
|
61
|
+
npx holy-agents-kits install jenkins-cli
|
|
49
62
|
|
|
50
63
|
# 一次装多个
|
|
51
|
-
npx holy-agents-kits install jenkins-
|
|
64
|
+
npx holy-agents-kits install jenkins-cli jenkins-controller
|
|
52
65
|
|
|
53
66
|
# 装到当前项目,而不是用户目录
|
|
54
|
-
npx holy-agents-kits install jenkins-
|
|
67
|
+
npx holy-agents-kits install jenkins-cli --dir .agents/skills
|
|
55
68
|
|
|
56
69
|
# 已存在时覆盖
|
|
57
|
-
npx holy-agents-kits install jenkins-
|
|
70
|
+
npx holy-agents-kits install jenkins-cli --force
|
|
58
71
|
```
|
|
59
72
|
|
|
60
73
|
| 参数 | 作用 |
|
|
@@ -67,9 +80,9 @@ npx holy-agents-kits install jenkins-ci --force
|
|
|
67
80
|
|
|
68
81
|
**卸载**:删除 `~/.agents/skills/<skill-name>` 目录即可。安装器不会写注册表,不会留残留。
|
|
69
82
|
|
|
70
|
-
##
|
|
83
|
+
## 五个技能分别做什么
|
|
71
84
|
|
|
72
|
-
### jenkins-
|
|
85
|
+
### jenkins-cli —— 流水线怎么写
|
|
73
86
|
|
|
74
87
|
**可观察行为**:让 agent 产出结构完整、能过 lint 的 Jenkinsfile;判断 lint 告警该不该修;按症状定位流水线故障。
|
|
75
88
|
|
|
@@ -83,7 +96,23 @@ npx holy-agents-kits install jenkins-ci --force
|
|
|
83
96
|
|
|
84
97
|
**用法**:说「部署一套带账密的 Jenkins」「把宿主 Jenkins 迁到容器」「切回宿主」,agent 调对应脚本;先 `--dry-run` 看计划。
|
|
85
98
|
|
|
86
|
-
**边界**:写流水线、改 Jenkinsfile 用 `jenkins-
|
|
99
|
+
**边界**:写流水线、改 Jenkinsfile 用 `jenkins-cli`。
|
|
100
|
+
|
|
101
|
+
### fy-new-api-app-framework —— 用 new-api 做身份与 AI 网关
|
|
102
|
+
|
|
103
|
+
**可观察行为**:产出一套可运行的外部 Web 应用——new-api 登录(OAuth 2.0 / OIDC)、AI relay 调用、配额与充值/订阅计费,附带一份 Next.js + Supabase + Vercel 的参考 demo(虚拟试衣)。
|
|
104
|
+
|
|
105
|
+
**用法**:说「用 new-api 做登录和计费,搭个外部 Web 应用」,agent 会先读身份与计费契约,再按默认技术栈落地;换栈时契约仍然有效。
|
|
106
|
+
|
|
107
|
+
**边界**:new-api 自身的后台功能不在这里改;默认栈(Next.js / Supabase / Vercel)只是默认值,不是强制项。
|
|
108
|
+
|
|
109
|
+
### fy-newapi-cli —— new-api 的终端运维
|
|
110
|
+
|
|
111
|
+
**可观察行为**:用一条命令管理运行中的 new-api——登录、看/改用户、渠道、API Token、日志、服务器选项、订阅套餐、OAuth 应用;也能给 agent 建 API key,或把管理 API 脚本化。
|
|
112
|
+
|
|
113
|
+
**用法**:说「登进 new-api 看下渠道状态」「给我建个 API key」,agent 用 `fy-newapi-cli` 直连管理 API(服务器地址 + `nap_` 开头的个人访问令牌)。
|
|
114
|
+
|
|
115
|
+
**边界**:不改 new-api 源码,不直接碰数据库;这些问题交给应用开发技能或 new-api 本身的技能。
|
|
87
116
|
|
|
88
117
|
### skill-creator-v2 —— 技能本身的开发与评测
|
|
89
118
|
|
|
@@ -98,16 +127,19 @@ npx holy-agents-kits install jenkins-ci --force
|
|
|
98
127
|
```
|
|
99
128
|
holy-agents-kits/
|
|
100
129
|
├── skills/
|
|
101
|
-
│ ├── jenkins-
|
|
102
|
-
│ ├── jenkins-controller/
|
|
103
|
-
│
|
|
104
|
-
├──
|
|
130
|
+
│ ├── jenkins-cli/ SKILL.md + references/ + scripts/
|
|
131
|
+
│ ├── jenkins-controller/ SKILL.md + references/ + scripts/
|
|
132
|
+
│ ├── fy-new-api-app-framework/ SKILL.md + references/(含参考 demo)+ scripts/
|
|
133
|
+
│ ├── fy-newapi-cli/ SKILL.md
|
|
134
|
+
│ └── skill-creator-v2/ SKILL.md + references/ + scripts/
|
|
135
|
+
├── bin/cli.js 安装器(零依赖)
|
|
105
136
|
└── package.json
|
|
106
137
|
```
|
|
107
138
|
|
|
108
139
|
## 前提与边界
|
|
109
140
|
|
|
110
141
|
- 两个 Jenkins 技能里的脚本面向真实环境:需要 Docker、SSH 可达的服务器、`test-190/jenkins` 部署包。没有环境时可以先读 `references/` 里的做法与排障表。
|
|
142
|
+
- 两个 new-api 技能需要一个已经部署好的 new-api 实例;`fy-newapi-cli` 还要一条 `nap_` 开头的个人访问令牌。参考 demo 需要 Node.js、Supabase 与 Vercel 账号。
|
|
111
143
|
- `skill-creator-v2` 的触发率评测脚本依赖 `claude` CLI;本机没有时走人工跑用例的降级路径,技能里写明了。
|
|
112
144
|
- 本仓库只放技能与方法,不含业务代码、部署包和任何真实凭据。
|
|
113
145
|
|
package/bin/cli.js
CHANGED
|
@@ -22,8 +22,8 @@ function usage() {
|
|
|
22
22
|
-h, --help 显示本帮助
|
|
23
23
|
|
|
24
24
|
示例:
|
|
25
|
-
npx holy-agents-kits install jenkins-
|
|
26
|
-
npx holy-agents-kits install jenkins-
|
|
25
|
+
npx holy-agents-kits install jenkins-cli
|
|
26
|
+
npx holy-agents-kits install jenkins-cli jenkins-controller --dir .agents/skills`);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function skillNames() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "holy-agents-kits",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Agent Skills 合集:Jenkins 流水线、Jenkins 控制器、Skill 开发与校验。一条命令装进你的 agent。",
|
|
5
5
|
"bin": {
|
|
6
6
|
"holy-agents-kits": "bin/cli.js"
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"skill",
|
|
23
23
|
"jenkins",
|
|
24
24
|
"jenkinsfile",
|
|
25
|
+
"new-api",
|
|
25
26
|
"ci",
|
|
26
27
|
"claude",
|
|
27
28
|
"trae"
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fy-new-api-app-framework
|
|
3
|
+
description: Development framework for building an external Web app against new-api — identity (OAuth 2.0/OIDC), AI relay, quota/top-up/subscription billing, plus a reference outfit demo app (Next.js + Supabase + Vercel).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# new-api App Development Framework (Web)
|
|
7
|
+
|
|
8
|
+
This skill is the standard for building an external **Web** application that uses new-api as its identity provider and AI gateway. It applies to SaaS products, enterprise internal tools, and demos that must run the complete chain: stack and project structure, frontend standards, the Supabase backend, Vercel deployment, and the new-api contracts for identity, AI relay, users, quota, top-up, and subscriptions. The identity and billing chapters are new-api product contracts and stay valid when you deviate from the default stack; the stack chapters are defaults, not requirements.
|
|
9
|
+
|
|
10
|
+
Deviate only when an existing platform standard, an offline/on-premise requirement, a non-Web target, or a regulatory constraint makes the default stack impossible. When you deviate, **Step 2 (Identity)** and **Step 4 (Users, Quota, and Payments)** remain normative, and the security properties must survive: server-side secret storage, PKCE, state validation, token rotation, no token in logs.
|
|
11
|
+
|
|
12
|
+
## Default Stack
|
|
13
|
+
|
|
14
|
+
Next.js (App Router) · TypeScript strict · React 19 · Tailwind CSS v4 + DaisyUI 5 · Supabase (Auth, Postgres + RLS, Edge Functions, Storage) · Vercel · bun · new-api OAuth 2.0 / OIDC (Authorization Code + PKCE; confidential BFF or public client).
|
|
15
|
+
|
|
16
|
+
The consumer app uses Tailwind + DaisyUI. An admin console is the one deliberate exception: Ant Design 5 + `@refinedev/core`, in a separate route tree that never shares a layout with the consumer app.
|
|
17
|
+
|
|
18
|
+
## Reference Index
|
|
19
|
+
|
|
20
|
+
This file is the contract and index; read the matching file before implementing that layer.
|
|
21
|
+
|
|
22
|
+
| Topic | File |
|
|
23
|
+
|-------|------|
|
|
24
|
+
| Steps 0–8 in full: bootstrap, project tree, endpoint/scope tables, env vars, security checklist, token lifecycle, scopes, model whitelist | `references/playbook.md` |
|
|
25
|
+
| Production-bug constraints | `references/pitfalls.md` |
|
|
26
|
+
| Frontend framework, rendering, caching, performance | `references/standards/nextjs.md` |
|
|
27
|
+
| UI components and UI/UX principles | `references/standards/daisyui.md`, `references/standards/ui-ux.md` |
|
|
28
|
+
| Supabase: CLI, Auth, RLS, Edge Functions, Storage, limits | `references/standards/supabase.md` |
|
|
29
|
+
| API contract: pagination, envelope, error codes, i18n keys | `references/standards/api-contract.md` |
|
|
30
|
+
| Deployment on Vercel (env vars, preview, rollback) | `references/standards/vercel.md` |
|
|
31
|
+
| Admin console (Next.js + Ant Design + Refine + Supabase) | `references/standards/admin-dashboard.md` |
|
|
32
|
+
| Identity contract and code (Step 2) | `references/standards/identity.md` |
|
|
33
|
+
| AI relay: BFF proxy code, rules, direct calls (Step 3) | `references/standards/relay.md` |
|
|
34
|
+
| Quota, `userinfo`, PAT, sessions, payments, credits (Step 4) | `references/standards/billing.md` |
|
|
35
|
+
| Security checklist and token lifecycle, in full | `references/standards/security.md` |
|
|
36
|
+
| Local acceptance: Cloudflare Tunnel and Supabase URL config | `references/standards/local-acceptance.md` |
|
|
37
|
+
| Runnable demo app / vendor provenance | `references/web/outfit-demo/README.md`, `references/vendor/README.md` |
|
|
38
|
+
| Environment self-check and bootstrap scripts | `scripts/check-env.*`, `scripts/bootstrap.*` |
|
|
39
|
+
|
|
40
|
+
## Prerequisites
|
|
41
|
+
|
|
42
|
+
1. A new-api instance running and accessible over HTTPS, plus admin access to its dashboard to create an OAuth application.
|
|
43
|
+
2. One of: a backend (BFF) that can store `client_secret` (confidential client), or a browser SPA / mini-program using PKCE with a **public client** (`public_client = true`, no secret). Supabase direct mode uses the public option.
|
|
44
|
+
|
|
45
|
+
## Credential Surfaces
|
|
46
|
+
|
|
47
|
+
Each new-api surface accepts a different credential; sending the wrong one is the most common integration failure. OAuth access tokens work on `/v1/*` and `/oauth/*`; every `/api/*` dashboard endpoint rejects them; personal access tokens (`nap_...`) and browser sessions cover the dashboard and admin routes. App-scoped plans, products, top-up, quota, and usage need no dashboard session — `/oauth/*` covers them. Full endpoint table: `references/playbook.md` § Credential Surfaces.
|
|
48
|
+
|
|
49
|
+
## End-to-End Development Workflow
|
|
50
|
+
|
|
51
|
+
Deliver an external App from zero to production in this order. Every step has a CLI; do not skip one and do not leave the wiring for later.
|
|
52
|
+
|
|
53
|
+
1. **Create the new-api sub-project and the App repo.** `fy-newapi-cli` creates the OAuth app, scopes, and quota pool; `gh repo create` creates the sub-App repository. Confirm `client_id` (`nac_...`) and redirect URIs before moving on.
|
|
54
|
+
2. **Create the Supabase and Vercel projects.** Supabase CLI (`supabase init`, `supabase link --project-ref <ref>`, `supabase db push`) and Vercel CLI (`vercel link`); run Step 0's bootstrap/self-check so the `custom:newapi` provider and `GATEWAY_PUBLIC_URL` issuer agree.
|
|
55
|
+
3. **Develop the sub-App and deploy a test environment.** Build against Supabase (auth + RLS, Edge Functions, Storage), deploy a preview/staging environment with `vercel`, and verify login, relay, and billing there.
|
|
56
|
+
4. **Configure plans, products, and the payment callback.** `fy-newapi-cli plan create/update` and `product create/update` define App-scoped plans/products; wire the payment return/callback URL so `waffo_pancake`/online checkouts can confirm and credit the App pool.
|
|
57
|
+
5. **Go live.** `vercel --prod` promotes the verified environment. Update the three origins together (Vercel production domain, OAuth redirect + post-logout URIs, Supabase Site URL + redirect allow list) in one change window.
|
|
58
|
+
|
|
59
|
+
### fy-newapi-cli updates must sync the skills (mandatory)
|
|
60
|
+
|
|
61
|
+
The `fy-newapi-cli` npm package bundles **both** this skill and `fy-newapi-cli` through `cmd/fy-newapi-cli/npm/scripts/prepare-skill.js`, whose `SKILLS` array is `['fy-newapi-cli', 'fy-new-api-app-framework']`. Every time a `fy-newapi-cli` command or its behavior changes, update both `SKILL.md` files in the same change; never ship a CLI carrying an older skill.
|
|
62
|
+
|
|
63
|
+
## Step 0: Environment Bootstrap
|
|
64
|
+
|
|
65
|
+
Run the self-check before anything else: `./scripts/check-env.sh --install` (macOS/Linux) or `./scripts/check-env.ps1 -Install` (Windows) installs missing CLIs, verifies the gateway/Supabase env vars, asserts `discovery.issuer` equals `GATEWAY_PUBLIC_URL`, confirms `custom:newapi`, and runs the authorize smoke test. Non-zero exit means stop and fix. Commands, bootstrap arguments, and the scaffold command: `references/playbook.md` § Step 0.
|
|
66
|
+
|
|
67
|
+
## Step 1: Project Structure
|
|
68
|
+
|
|
69
|
+
App Router layout: `src/app/**` routes, `src/lib/supabase/{client,server}.ts`, `src/lib/gateway-session.ts` (refresh + 401 retry), `src/proxy.ts` (session refresh; `middleware.ts` before Next.js 16), `supabase/` migrations and functions. Only trusted server code imports the secret key, never a Client Component, never with a `NEXT_PUBLIC_` prefix. Full tree and reasoning: `references/playbook.md` § Step 1.
|
|
70
|
+
|
|
71
|
+
## Step 2: Identity (OAuth / OIDC)
|
|
72
|
+
|
|
73
|
+
new-api is the OIDC identity provider; your app never stores new-api passwords. Authorization Code + PKCE is the only supported flow. Full contract and code: `references/standards/identity.md`.
|
|
74
|
+
|
|
75
|
+
- **Public or confidential, decide once**: a server that can keep a secret uses a confidential client (BFF, `client_secret` server-only); an SPA or mini-program uses a public client (`public_client = true`, no secret, PKCE mandatory). Never enable public mode for a server-side app.
|
|
76
|
+
- Generate `state`, `nonce`, and the PKCE `code_verifier` on the server, keep them in HttpOnly / `Secure` / `SameSite=Lax` cookies, and validate `state` and the verifier on the callback.
|
|
77
|
+
- Supabase direct mode: the provider identifier must be exactly `custom:newapi`; the gateway must already be publicly reachable over HTTPS with an issuer equal to its public base URL **before** the provider is created; the app's redirect URI is `https://<project>.supabase.co/auth/v1/callback`.
|
|
78
|
+
- Supabase does not refresh a custom provider's token: refresh through `POST <gateway>/oauth/token` before the 1 hour expiry, store the rotated refresh token, sign out on `invalid_grant`, and revoke the refresh token on logout.
|
|
79
|
+
|
|
80
|
+
## Step 3: AI Relay Calls
|
|
81
|
+
|
|
82
|
+
All AI traffic goes to `/v1/*` with the OAuth access token; that token is not a dashboard credential and `/api/*` rejects it. Proxy code and rules: `references/standards/relay.md`.
|
|
83
|
+
|
|
84
|
+
- BFF: a Route Handler attaches the token and returns `upstream.body` so streams stay unbuffered; public clients call the gateway directly.
|
|
85
|
+
- Never log the `Authorization` header, token, request body, or upstream body; log method, path, status, latency, and a request id only. Never forward cookies, `client_secret`, or dashboard PATs upstream.
|
|
86
|
+
- Retry a `401` exactly once after refresh, then surface it.
|
|
87
|
+
- Relay billing for an OAuth access token is **App-scoped**: pre-consume, settlement, and refund use the quota pool of the App that owns the token (`app_quota`), never the user's platform wallet. Async task endpoints (video, music, Midjourney, other submissions) follow the same rule and are isolated by `app_id`: an App token can only read, remix, or cancel tasks its own App created.
|
|
88
|
+
|
|
89
|
+
## Step 4: Users, Quota, and Payments
|
|
90
|
+
|
|
91
|
+
The dashboard user system lives under `/api/*`, which OAuth tokens cannot reach. App-scoped identity, quota, plans, products, top-up, and usage are exposed under `/oauth/*` and accept the OAuth access token directly. Endpoint/scope table, payment matrix, and error codes: `references/playbook.md` § Step 4 and `references/standards/billing.md`.
|
|
92
|
+
|
|
93
|
+
- **Two balances, one billing rule**: `quota` is the platform wallet, `app_quota` is the App pool. Relay pre-consume, settlement, and refund for an OAuth token only touch that App pool.
|
|
94
|
+
- **An App pool starts empty** (wallet row created lazily with `0`) and grows only through top-up checkout or an App product purchase. Balance top-up is a transfer, not a grant.
|
|
95
|
+
- **A browser return URL or a `pending` order is never proof of payment**; confirm by re-reading `app_quota` from `/oauth/userinfo`, and link accounts on `sub` (never on mutable `username` / `email`).
|
|
96
|
+
- `amount` is always in the configured display unit — never send a quota value as an `amount`.
|
|
97
|
+
|
|
98
|
+
## Step 5: Backend on Supabase
|
|
99
|
+
|
|
100
|
+
Mandatory for any app that stores new-api users or business data in Supabase. Client/key matrix and Edge Function rules: `references/playbook.md` § Step 5; conventions: `references/standards/supabase.md`.
|
|
101
|
+
|
|
102
|
+
- **RLS + `client_id` is the enforcement point**: every business table carries `client_id text not null`; policies enforce both `current_app_client_id()` and `auth.uid()`, bound to exactly one verified `auth.identities` row with `provider = 'custom:newapi'`. Missing, malformed, mismatched, or ambiguous identities must deny access.
|
|
103
|
+
- Never trust `user_metadata`, `raw_user_meta_data`, or request fields for tenant, gateway identity, or admin grants; any server-written mapping must first verify the provider identity and issuer. Empty RLS results are not a reason to fall back to editable claims or anon Storage access.
|
|
104
|
+
- **Media goes to Supabase Storage**: the database keeps only `bucket` + `path` (`{client_id}/{user_id}/{uuid}.{ext}`), reads use short-lived signed URLs from private buckets, and MIME type and size are validated server-side.
|
|
105
|
+
|
|
106
|
+
## Step 6: Frontend Standards
|
|
107
|
+
|
|
108
|
+
Conventions: `references/standards/nextjs.md`, `references/standards/daisyui.md`, `references/standards/ui-ux.md`, plus `references/vendor/`.
|
|
109
|
+
|
|
110
|
+
- Server Components by default; `'use client'` only on the smallest interactive leaf. Never pass an access token, refresh token, `client_secret`, or service-role key into a Client Component.
|
|
111
|
+
- **Compose, do not rebuild**: containers are `card` + `card-body`, inputs are `input` / `textarea` / `select`, dialogs are `dialog.modal` + `modal-box`; Tailwind utilities are for layout only. Invalid DaisyUI 5 classes (`input-bordered`, `card-compact`, `join`, `chip-*`, ...) silently do nothing — valid/invalid list in `references/playbook.md` § Step 6 and `references/standards/daisyui.md#8`.
|
|
112
|
+
- **OAuth callback is server-side and single-use**: exchange the code in a Route Handler `GET` with exactly one `exchangeCodeForSession`. Never call it from a client effect — React 19 StrictMode runs it twice and Supabase returns `invalid flow state`.
|
|
113
|
+
- Every data view needs loading, empty, and error states; destructive actions need confirmation; payment and logout show the resulting state.
|
|
114
|
+
|
|
115
|
+
## Step 7: Deploy with Vercel
|
|
116
|
+
|
|
117
|
+
Deployment commands, preview handling, rollback, and the environment-variable table: `references/standards/vercel.md` and `references/playbook.md` § Step 7.
|
|
118
|
+
|
|
119
|
+
- **Update the three origins together** in one change window: the Vercel production domain (`APP_ORIGIN`), the new-api OAuth app redirect and post-logout URIs, and Supabase Auth (Site URL + redirect allow list). In direct mode the redirect URI stays `https://<project>.supabase.co/auth/v1/callback`.
|
|
120
|
+
- Preview deployments get a new origin each time: never register a wildcard redirect URI, never treat a preview or tunnel URL as a permanent address.
|
|
121
|
+
|
|
122
|
+
## Step 8: Admin Dashboard
|
|
123
|
+
|
|
124
|
+
Optional surface: Next.js App Router + Ant Design 5 + `@refinedev/core` + Supabase. Conventions: `references/standards/admin-dashboard.md`.
|
|
125
|
+
|
|
126
|
+
- **The app's admin role is not the new-api role** (`1` / `10` / `100`): store it in `auth.users.app_metadata.admin_role` (service-role writes only) or in an `app_admins` table; never read a role from `user_metadata`, a query string, or a request body.
|
|
127
|
+
- Every admin Route Handler and the admin layout call the same `requireAdmin()`; client checks and `proxy.ts` are not authorization boundaries. Ant Design and DaisyUI never share a layout or route tree.
|
|
128
|
+
- The first admin is the OAuth app creator (`INITIAL_ADMIN_SUB` → `app_admins`); no endpoint or "first signup wins" rule may create one.
|
|
129
|
+
|
|
130
|
+
## Known Failure Modes
|
|
131
|
+
|
|
132
|
+
Nine rules distilled from production bugs: authorize redirect back to the gateway, `X-Forwarded-Proto` behind a TLS proxy, consent CSRF, MySQL reserved words, plaintext CLI servers, resumable serverless work, per-model billing, render order, inviter persistence. Read `references/pitfalls.md` before reviewing a flow that touches them.
|
|
133
|
+
|
|
134
|
+
## Security Checklist and Token Lifecycle
|
|
135
|
+
|
|
136
|
+
Non-negotiables: secrets stay server-side, `state` / PKCE are validated on callback, tokens are never logged or written to `user_metadata`, a rotated refresh token replaces the old one, and a browser return URL is never payment proof. Full checklist, token TTLs (access 1 hour, refresh 30 days, code 60 seconds), and the refresh procedure: `references/playbook.md` and `references/standards/security.md`.
|
|
137
|
+
|
|
138
|
+
## Scopes Reference
|
|
139
|
+
|
|
140
|
+
| Scope | Grants access to |
|
|
141
|
+
|-------|-----------------|
|
|
142
|
+
| `openid` | User ID (sub claim) — required for OIDC |
|
|
143
|
+
| `profile` | Username, display name |
|
|
144
|
+
| `email` | Email address |
|
|
145
|
+
| `api:read` | Read-only AI endpoints (`GET` / `HEAD` / `OPTIONS`), quota in `/oauth/userinfo`, App plans/products, `/oauth/logs` |
|
|
146
|
+
| `api:write` | Non-read AI endpoints (chat, images, embeddings, ...) and plan/product/top-up checkout |
|
|
147
|
+
|
|
148
|
+
These scopes belong to OAuth access tokens only. Dashboard PATs use a separate catalog (`profile:*`, `wallet:*`, `billing:*`, ...); list it with `GET /api/user/access_tokens/scopes`. Per-App model restriction (`ai_model_whitelist`) and scope details: `references/playbook.md` § Scopes Reference.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Hard-Won Constraints (from production bugs)
|
|
2
|
+
|
|
3
|
+
Each entry is a rule distilled from a real fix; the short hash links it to the commit for traceability. Violating one of these reproduces the original bug.
|
|
4
|
+
|
|
5
|
+
- **After sign-in, return to the gateway authorize page, not the dashboard** (`4ff7a8a6c`). When an unauthenticated `/oauth/authorize` redirects the user to sign-in, the post-login navigation MUST take the browser back to `/oauth/authorize` with a full page load (`window.location.assign`), never SPA client routing. Client navigation matches `/oauth/authorize` to the frontend `/oauth/$provider` route and shows a "missing code" error.
|
|
6
|
+
- **Honor `X-Forwarded-Proto` in same-origin checks behind a TLS proxy** (`10934556f`). When the gateway runs behind a TLS-terminating reverse proxy, origin validation MUST derive the scheme from `X-Forwarded-Proto` (fall back to `r.TLS`, then URL scheme) instead of assuming plaintext when `r.TLS == nil`; otherwise legitimate HTTPS requests are rejected as "request origin is not allowed". Keep session-cookie origin guards distrusting the client-supplied header.
|
|
7
|
+
- **Consent endpoints: no redundant `Origin`/`Sec-Fetch-Site` gate, and a fresh CSRF token on every load** (`2fa17c384`, `9d8ea00f8`). The consent `POST /oauth/authorize` relies on the session-bound CSRF token only — do NOT stack an extra `Origin`/`Sec-Fetch-Site` check (proxies/browsers strip it and legitimate submissions 403). Issue the CSRF token freshly on consent page load instead of carrying one in the redirect URL that may expire before submit.
|
|
8
|
+
- **Quote MySQL reserved-word columns such as `key` / `group`** (`fbc535356`). Never write raw SQL like `WHERE key = ?` against a reserved-word column — use the ORM struct form (`Where(&model.Option{Key: ...})`) or `commonKeyCol` / `commonGroupCol`, or MySQL raises error 1064.
|
|
9
|
+
- **The CLI must reject a plaintext non-loopback server before printing the authorize URL** (`0618ec20a`). Validate the server (scheme + reachability) and reject any non-loopback `http://` endpoint BEFORE emitting `/cli/authorize`, so the authorization code and token never travel in plaintext to a remote host.
|
|
10
|
+
- **Make long-running serverless work resumable** (`7dc68bd0c`). On Vercel/Edge, a long generation/try-on pipeline MUST be broken into idempotent, resumable steps (stepwise advance) with state persisted between steps, never one monolithic request — otherwise a platform timeout loses all progress.
|
|
11
|
+
- **Resumable advance calling protocol** (`7dc68bd0c`): the create endpoint returns the task id immediately (never blocks on generation), then the browser polls `POST /api/generate/[id]/advance` one step at a time. Each `/advance` call reads the gateway access token from the request cookie, so it cannot run as a server-side background job — the browser must keep polling with its session. Steps are idempotent: stage outputs are persisted per step, so a closed tab pauses (not fails) the task, and re-entering with the same inputs re-runs `advance` from the persisted state (the create endpoint dedupes back to the original id).
|
|
12
|
+
- **Bill by the configured per-model price and surface real relay errors** (`26103a132`). The pre-generation quote MUST use the actually configured per-model price, never a hardcoded/frozen fee. Never swallow upstream relay errors: preserve the relay error code and HTTP status and pass through the real reason instead of a generic "request failed".
|
|
13
|
+
- **Render the generated result before history, with thumbnails** (`4c1ab5023`). After generation, show the result inline first and do not auto-redirect to history; render result thumbnails for succeeded rows so ordering and content stay correct under streaming/concurrent completion.
|
|
14
|
+
- **Persist the inviter when creating an OAuth user** (`48a6c87f9`). When `findOrCreateOAuthUser` creates a new user from OAuth login, persist the resolved `inviter_id` (from the affiliate code) onto the new user in the same atomic create, so the inviter relation is not silently dropped.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Implementation Playbook
|
|
2
|
+
|
|
3
|
+
Step-level detail for `fy-new-api-app-framework`. SKILL.md keeps the contract and the
|
|
4
|
+
non-negotiable rules; this file holds the commands, tables, and checklists for each step.
|
|
5
|
+
|
|
6
|
+
## Step 0: Environment Bootstrap
|
|
7
|
+
|
|
8
|
+
Install the toolchain and prove both sides of the trust chain agree. Run every command in the working copy you are building.
|
|
9
|
+
|
|
10
|
+
### 0.1 One command with optional auto-install
|
|
11
|
+
|
|
12
|
+
`./scripts/check-env.ps1 -Install` (Windows) / `./scripts/check-env.sh --install` (macOS/Linux). Without the flag they only verify and print the exact fix; with it they install missing CLIs through the platform package manager or npm (including `supabase` and `vercel`) and re-run the checks. `fy-newapi-cli` is bundled with the `fy-newapi-cli` skill and is verified, not installed.
|
|
13
|
+
|
|
14
|
+
### 0.2 Install the CLIs manually
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
Windows: winget install Oven-sh.Bun GoLang.Go Supabase.CLI Cloudflare.cloudflared
|
|
18
|
+
macOS/Linux: brew install oven-sh/bun/bun go supabase/tap/supabase cloudflared
|
|
19
|
+
Both: bun add -g vercel · fy-newapi-cli --version # verified, not installed
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 0.3 One-shot bootstrap
|
|
23
|
+
|
|
24
|
+
```text
|
|
25
|
+
Windows: Copy-Item "<skill-root>/scripts/bootstrap.ps1" .\scripts\bootstrap.ps1; .\scripts\bootstrap.ps1 -ProjectName "My App" [-ClientIdOverride <id>] [-PackRoot <dir>]
|
|
26
|
+
macOS/Linux: cp "<skill-root>/scripts/bootstrap.sh" scripts/bootstrap.sh; bash scripts/bootstrap.sh --project-name "My App" [--client-id <id>] [--pack-root <dir>]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Both scripts are project-agnostic (no hardcoded paths) and need `fy-newapi-cli` logged in, the `supabase` CLI, and `bun` only when a pack root is given. They run eight steps: probe login, self user, and OAuth apps (reusing an existing public client) → `supabase link` via that app's project ref → read anon + service_role keys → write `.env.local` → `supabase db push` → check or rebuild `custom:newapi` (DELETE + POST on issuer mismatch) → authorize smoke test (302 = OK) → resolve the first admin's `auth.users` UUID, insert `app_admins(role='owner')`, and write `INITIAL_ADMIN_SUB` back. bootstrap 自动把 scopes 设为 `openid profile email api:read api:write`,Supabase provider scopes 同步更新——这保证登录后你既拿到身份也拿到额度/充值/日志能力。
|
|
30
|
+
|
|
31
|
+
Manual equivalent: `supabase login`, `supabase init` (new `supabase/` only), `supabase link --project-ref <project-ref>`, `supabase db push`, `supabase functions deploy user-sync`.
|
|
32
|
+
|
|
33
|
+
### 0.4 Run the self-check
|
|
34
|
+
|
|
35
|
+
Both scripts verify the six CLIs exist, the four env vars below are set, `discovery.issuer` equals `GATEWAY_PUBLIC_URL`, `custom:newapi` exists with a matching issuer, and `GET <supabase>/auth/v1/authorize?provider=custom:newapi` returns 302/303/307. Any failure exits non-zero with the fix; do not continue to Step 1 until it passes.
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
macOS/Linux: GATEWAY_BASE_URL=... GATEWAY_PUBLIC_URL=... SUPABASE_URL=... SUPABASE_SECRET_KEY=... ./scripts/check-env.sh
|
|
39
|
+
Windows: $env:GATEWAY_BASE_URL='...'; $env:GATEWAY_PUBLIC_URL='...'; $env:SUPABASE_URL='...'; $env:SUPABASE_SECRET_KEY='...'; ./scripts/check-env.ps1
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 0.5 Scaffold the Next.js app
|
|
43
|
+
|
|
44
|
+
`bunx create-next-app@latest my-app --typescript --app --tailwind --eslint --src-dir --import-alias "@/*"`, then `cd my-app && bun add @supabase/supabase-js @supabase/ssr && bun add -D daisyui@latest`. Enable DaisyUI in `src/app/globals.css` (`@import "tailwindcss";` + `@plugin "daisyui";`), then run `bun run dev` and `bun run build`.
|
|
45
|
+
|
|
46
|
+
## Step 1: Project Structure
|
|
47
|
+
|
|
48
|
+
Use the App Router: route handlers own server secrets; pages stay renderable on the server.
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
my-app/
|
|
52
|
+
├─ src/
|
|
53
|
+
│ ├─ app/
|
|
54
|
+
│ │ ├─ layout.tsx # root layout, theme, providers
|
|
55
|
+
│ │ ├─ globals.css # Tailwind v4 + @plugin "daisyui";
|
|
56
|
+
│ │ ├─ page.tsx # /
|
|
57
|
+
│ │ ├─ login/page.tsx # /login
|
|
58
|
+
│ │ ├─ auth/
|
|
59
|
+
│ │ │ ├─ start/route.ts # begins OAuth (BFF mode)
|
|
60
|
+
│ │ │ └─ callback/route.ts # code exchange (BFF) or page.tsx (public)
|
|
61
|
+
│ │ ├─ wardrobe/page.tsx # /wardrobe
|
|
62
|
+
│ │ ├─ history/page.tsx # /history
|
|
63
|
+
│ │ ├─ profile/page.tsx # /profile
|
|
64
|
+
│ │ └─ api/relay/[...path]/route.ts # optional BFF proxy for /v1/*
|
|
65
|
+
│ ├─ components/ # DaisyUI-composed UI
|
|
66
|
+
│ ├─ lib/
|
|
67
|
+
│ │ ├─ supabase/client.ts # browser client (anon key)
|
|
68
|
+
│ │ ├─ supabase/server.ts # server client (cookies)
|
|
69
|
+
│ │ ├─ gateway-session.ts # gateway refresh + 401 retry
|
|
70
|
+
│ │ └─ gateway.ts # AI relay calls
|
|
71
|
+
│ └─ proxy.ts # Supabase session refresh (middleware.ts pre-16)
|
|
72
|
+
├─ supabase/{config.toml, migrations/<timestamp>_*.sql, functions/user-sync/index.ts}
|
|
73
|
+
└─ public/ · .env.example · next.config.ts · package.json · tsconfig.json
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`src/lib/supabase/client.ts` uses only the anon/publishable key and is safe in the browser; `server.ts` reads cookies and still uses the anon key unless a route explicitly needs elevated privileges. The `service_role` / secret key is imported only by trusted server code or an Edge Function, never by a Client Component and never with a `NEXT_PUBLIC_` prefix. Business data access goes through Supabase + RLS; if you choose a BFF instead, business tables can live in your own database, but the identity and billing chapters still apply. The runnable reference app follows this layout, with the consumer routes under `(consumer)` route groups and an `admin/` tree for the Ant Design console; see `references/web/outfit-demo/README.md`.
|
|
77
|
+
|
|
78
|
+
## Step 4: Users, Quota, and Payments — endpoint contracts
|
|
79
|
+
|
|
80
|
+
| Endpoint | Scope | Contract |
|
|
81
|
+
|----------|-------|----------|
|
|
82
|
+
| `GET /oauth/userinfo` | `openid`; `api:read` for quota | `sub`, plus `username` / `name` (`profile`) and `email` (`email`). With `api:read`: `quota`, `used_quota`, `request_count`, `group`, and `app_quota` / `app_used_quota` for the token's App. |
|
|
83
|
+
| `GET /oauth/subscription/plans` | `api:read` | `{"plans":[{"plan":{...}}]}` — enabled plans owned by this App only. |
|
|
84
|
+
| `POST /oauth/subscription/checkout` | `api:write` | `{"plan_id":1,"payment_method":"balance"}`; balance returns `{"status":"success","payment_method":"balance"}`, online methods return a `pending` order with a checkout link. |
|
|
85
|
+
| `GET /oauth/products` | `api:read` | `{"products":[{id,name,description,price_amount,currency,quota_amount,max_purchase_per_user}]}` — enabled products of this App only. |
|
|
86
|
+
| `POST /oauth/products/checkout` | `api:write` | `{"product_id":1,"payment_method":"balance"}`; balance returns `{"status":"success","order_id":"...","quota_amount":...}`, `waffo_pancake` returns `checkout_url`. |
|
|
87
|
+
| `POST /oauth/topup/checkout` | `api:write` | `{"amount":10,"payment_method":"balance"}`; balance returns `{"status":"success","quota":...}`, `waffo_pancake` returns `checkout_url` / `order_id` / `expires_at`. |
|
|
88
|
+
| `GET /oauth/logs` | `api:read` | Redacted request logs of the token owner. |
|
|
89
|
+
|
|
90
|
+
- **Payment matrix** — plans: `balance`, `epay`, `stripe`, `creem`, `waffo_pancake`; products: `balance`, `waffo_pancake`; App top-up: `balance`, `waffo_pancake`. Any other value returns `400` `unsupported_payment_method`. `balance` on a plan or product debits the App pool; `balance` on top-up moves platform balance into the App pool.
|
|
91
|
+
- **Cross-App purchase is rejected**: a plan or product owned by another App, a disabled plan/product, or a reached per-user purchase limit returns `403 access_denied` or `400 checkout_failed`; a missing `plan_id` / `product_id` returns `400 invalid_request`, as does an omitted `payment_method` on plan or product checkout (top-up defaults to `waffo_pancake`).
|
|
92
|
+
- **No OAuth endpoint reads App subscription state or App order history yet**: treat the checkout response as an order handle, confirm top-up/product effects by re-reading `/oauth/userinfo` (`app_quota`), keep your own record for plans, and never treat a browser return URL or a `pending` order as proof of payment.
|
|
93
|
+
- Link accounts on `sub` from `GET /oauth/userinfo`; `username` and `email` are mutable and email may be empty. OAuth login never creates a new-api user.
|
|
94
|
+
- 外部 app 用 OAuth access token 调 `/oauth/userinfo` 拿身份与额度,站内充值走 `/oauth/topup/checkout`(modal),套餐/商品走 `/oauth/subscription/*` 和 `/oauth/products*`,日志走 `/oauth/logs`;不要跳 newapi 仪表板。
|
|
95
|
+
- 每个 App 在后台独立配置自己的套餐与商品(按 `app_id` 归属),外部 app 只看到自己 App 的那一份;后台按 App 筛选用户与订单见 `references/standards/api-contract.md`。
|
|
96
|
+
- PATs (`nap_...`, shown once, scoped, `expires_at` at least 1 hour ahead when set) need a browser session and a security proof; a PAT cannot mint another PAT and never exceeds the user's role.
|
|
97
|
+
- `amount` is in the configured display unit — never send a quota value as an `amount`.
|
|
98
|
+
|
|
99
|
+
## Step 5: Backend on Supabase — client matrix
|
|
100
|
+
|
|
101
|
+
| Client | Key | Rule |
|
|
102
|
+
|--------|-----|------|
|
|
103
|
+
| Browser | anon / publishable | Relies on RLS for authorization |
|
|
104
|
+
| Server | `@supabase/ssr` + cookies | Same session in Server Components and Route Handlers |
|
|
105
|
+
| Session refresh | `proxy.ts` (`middleware.ts` before Next.js 16) | `getUser()` keeps the cookie session fresh and protects routes |
|
|
106
|
+
| Trusted server / Edge Function | `service_role` / secret | Bypasses RLS; never expose it and never prefix it with `NEXT_PUBLIC_` |
|
|
107
|
+
|
|
108
|
+
- Edge Functions verify the caller with `supabase.auth.getUser()`, resolve `gateway_user_id` / `client_id` through the same protected provider identity and server mapping/config, and use the service-role key only inside the function. Work beyond the function limits returns a job id (see **Long-Running Work and Supabase Limits** in `references/standards/supabase.md`).
|
|
109
|
+
- The app-side `seed-assets.ts` uploads a `pack.json` asset library and upserts by `(client_id, provider_id)`; bootstrap runs it when a pack root is given (see **Seeding the Asset Packs** in `references/standards/supabase.md`).
|
|
110
|
+
|
|
111
|
+
## Step 6: Frontend standards
|
|
112
|
+
|
|
113
|
+
- Server Components by default; `'use client'` only on the smallest interactive leaf.
|
|
114
|
+
- Reuse an existing component before writing markup; compose DaisyUI (`btn`, `card`, `navbar`, `drawer`, `modal`, `table`, `tabs`, `alert`, `loading`, `skeleton`) and set the theme once with `data-theme` on `<html>`.
|
|
115
|
+
- **Only valid DaisyUI 5 classes**: `input-bordered`, `textarea-bordered`, `select-bordered`, `card-compact`, `card-bordered`, `tabs-boxed`, the removed `join`/`join-item`, and the non-existent `chip-*` silently do nothing. Use `input` / `textarea` / `select` / `card-sm` / `card-border` / `tabs-box`/`tabs-border`, plain `flex gap-*` or `label.input` for grouped inputs, and `btn btn-xs` for filter chips. Run the acceptance commands in `references/standards/daisyui.md#8` before delivery.
|
|
116
|
+
- **Compose, do not rebuild**: containers, inputs, alerts, and dialogs must be `card` + `card-body`, `input` / `textarea` / `select`, `alert`, and `dialog.modal` + `modal-box`; Tailwind utilities are for layout only.
|
|
117
|
+
|
|
118
|
+
## Step 7: Deploy with Vercel — environment variables
|
|
119
|
+
|
|
120
|
+
| Variable | Exposure | Purpose |
|
|
121
|
+
|----------|----------|---------|
|
|
122
|
+
| `NEXT_PUBLIC_SUPABASE_URL` | Browser | Supabase project URL |
|
|
123
|
+
| `NEXT_PUBLIC_SUPABASE_ANON_KEY` | Browser | Supabase anon/publishable key, protected by RLS |
|
|
124
|
+
| `SUPABASE_SECRET_KEY` | Server only | Admin API, Edge Function secrets, migrations |
|
|
125
|
+
| `GATEWAY_BASE_URL` | Server; `NEXT_PUBLIC_GATEWAY_BASE_URL` in public mode | Gateway origin used by Route Handlers or the browser |
|
|
126
|
+
| `GATEWAY_PUBLIC_URL` | Server | Public issuer; must equal the Supabase provider issuer |
|
|
127
|
+
| `GATEWAY_CLIENT_ID` | Browser or server; `NEXT_PUBLIC_GATEWAY_CLIENT_ID` in public mode | `nac_...`, safe to expose |
|
|
128
|
+
| `GATEWAY_CLIENT_SECRET` | Server only | Confidential client secret, never `NEXT_PUBLIC_` |
|
|
129
|
+
| `APP_ORIGIN` | Server | Stable production origin for redirects |
|
|
130
|
+
| `INITIAL_ADMIN_SUB` | Server (optional) | Developer's `sub` (`oauth_apps.created_by`) for the one-time first-owner grant |
|
|
131
|
+
|
|
132
|
+
- Preview deployments get a new origin each time: do not register a wildcard redirect URI. Changing the Supabase project domain changes the callback URL, so recreate `custom:newapi` afterwards. Never treat a preview or tunnel URL as a permanent deployment address.
|
|
133
|
+
|
|
134
|
+
## Step 8: Admin dashboard
|
|
135
|
+
|
|
136
|
+
- What OAuth gives the console: `sub` always, `username` / `name` with `profile`, `email` with `email`; the `id_token` carries no name, email, or role. Key the admin account on `sub`.
|
|
137
|
+
- **The app's admin role is not the new-api role** (`1` / `10` / `100`): store it in `auth.users.app_metadata.admin_role` (service-role writes only) or in an `app_admins` table; never read a role from `user_metadata`, a query string, or a request body.
|
|
138
|
+
- Every admin Route Handler and the admin layout call the same `requireAdmin()`; client checks and `proxy.ts` are not authorization boundaries.
|
|
139
|
+
- Ant Design (admin) and Tailwind + DaisyUI (consumer) never share a layout or route tree; `accessControlProvider` mirrors the server guard, never replaces it.
|
|
140
|
+
- **The first admin defaults to the developer who created the OAuth app**: `oauth_apps.created_by` equals their `sub`, so set `INITIAL_ADMIN_SUB` and seed `app_admins` once out of band. No endpoint or "first signup wins" rule may create an admin; block self-promotion and removing the last owner.
|
|
141
|
+
|
|
142
|
+
## Security Checklist
|
|
143
|
+
|
|
144
|
+
- [ ] Confidential clients keep `client_secret` in backend env vars only; public clients have no secret and rely on PKCE.
|
|
145
|
+
- [ ] `redirect_uri` exactly matches a registered URI, and the PKCE verifier from that request is validated on callback.
|
|
146
|
+
- [ ] `state` is validated against a server-held value; `nonce` is per request and validated when an `id_token` is consumed.
|
|
147
|
+
- [ ] State, verifier, and session cookies are `HttpOnly`, `Secure` in production, and `SameSite=Lax`.
|
|
148
|
+
- [ ] Gateway tokens stay in memory and are never logged or written to `user_metadata`; a rotated refresh token replaces the old one.
|
|
149
|
+
- [ ] OAuth tokens are used for `/v1/*` and `/oauth/*` (`userinfo`, `subscription/*`, `products*`, `topup/checkout`, `logs`) only; every `/api/*` dashboard endpoint rejects them.
|
|
150
|
+
- [ ] Async tasks and Midjourney calls made with an App access token settle against the App quota pool and can only access tasks created by the same App (`app_id` isolation); no `app_task_unsupported` capability limit applies.
|
|
151
|
+
- [ ] A browser return URL or `pending` order is never proof of payment; admin permissions come from your own store and the server guard.
|
|
152
|
+
- [ ] `SUPABASE_SECRET_KEY` is imported only by `server-only` code and never exposed through `NEXT_PUBLIC_*`.
|
|
153
|
+
- [ ] All media lives in Supabase Storage private buckets; only `bucket` + `path` is in Postgres.
|
|
154
|
+
- [ ] Balance, credits, orders, and usage come from new-api; there is no local ledger.
|
|
155
|
+
|
|
156
|
+
Full list: `references/standards/security.md`.
|
|
157
|
+
|
|
158
|
+
## Token Lifecycle
|
|
159
|
+
|
|
160
|
+
- **Access token**: JWT, 1 hour TTL, used to call AI APIs and userinfo.
|
|
161
|
+
- **Refresh token**: Opaque, 30 day TTL, rotated on each use.
|
|
162
|
+
- **Authorization code**: Single-use, 60 second TTL.
|
|
163
|
+
- **The provider token is not refreshed for you**: read `provider_token` / `provider_refresh_token` at login, refresh via `POST <gateway>/oauth/token` (`grant_type=refresh_token`) when less than 60 s remain, persist the rotated refresh token, and on `invalid_grant` clear local state and send the user through login again. A relay `401` is retried once with a fresh token, never in a loop.
|
|
164
|
+
|
|
165
|
+
Details: `references/standards/security.md`.
|
|
166
|
+
|
|
167
|
+
## Scopes Reference
|
|
168
|
+
|
|
169
|
+
| Scope | Grants access to |
|
|
170
|
+
|-------|-----------------|
|
|
171
|
+
| `openid` | User ID (sub claim) — required for OIDC |
|
|
172
|
+
| `profile` | Username, display name |
|
|
173
|
+
| `email` | Email address |
|
|
174
|
+
| `api:read` | Read-only AI endpoints (`GET` / `HEAD` / `OPTIONS`, e.g. `/v1/models`), quota in `/oauth/userinfo`, App plans/products, and `/oauth/logs` |
|
|
175
|
+
| `api:write` | Non-read AI endpoints (chat, images, embeddings, ...) and plan/product/top-up checkout. Request both if the app also reads. |
|
|
176
|
+
|
|
177
|
+
These scopes belong to OAuth access tokens only. Dashboard personal access tokens use a separate catalog (`profile:read`, `profile:write`, `account_security:write`, `wallet:read`, `wallet:write`, `billing:read`, `billing:write`, ...); list it with `GET /api/user/access_tokens/scopes`.
|
|
178
|
+
|
|
179
|
+
## Model Whitelist per App
|
|
180
|
+
|
|
181
|
+
Each OAuth App in new-api can restrict which AI models are available:
|
|
182
|
+
|
|
183
|
+
```sql
|
|
184
|
+
-- In new-api admin, set on the OAuth App:
|
|
185
|
+
ai_model_whitelist = '["gpt-4o-mini","gpt-4o"]'
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
When set, the relay rejects any model not in the list. Leave empty to allow all models. This is enforced in `controller/relay.go` via `service.CheckOAuthAppModelWhitelist()`.
|