create-fullstack-scaffold 0.1.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 +154 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +439 -0
- package/dist/cli/index.js.map +1 -0
- package/package.json +171 -0
- package/template/.agents/skills/writing-hookify-rules/SKILL.md +408 -0
- package/template/.ai-context.md +368 -0
- package/template/.claude/hookify.block-dangerous-commands.local.md +41 -0
- package/template/.claude/hookify.check-api-types.local.md +111 -0
- package/template/.claude/hookify.check-duplicate-types.local.md +287 -0
- package/template/.claude/hookify.check-test-assertions.local.md +93 -0
- package/template/.claude/hookify.remind-add-tests.local.md +209 -0
- package/template/.claude/hookify.remind-db-migration.local.md +58 -0
- package/template/.claude/hookify.remind-run-tests.local.md +52 -0
- package/template/.claude/hookify.warn-any-type.local.md +203 -0
- package/template/.claude/hookify.warn-console-log.local.md +73 -0
- package/template/.claude/rules/00-project-config.md +147 -0
- package/template/.claude/rules/01-file-types.md +127 -0
- package/template/.claude/rules/02-git-workflow.md +167 -0
- package/template/.claude/rules/10-api-type-inference.md +555 -0
- package/template/.claude/rules/20-server-api.md +349 -0
- package/template/.claude/rules/21-server-entrypoint.md +257 -0
- package/template/.claude/rules/30-client-components.md +314 -0
- package/template/.claude/rules/31-client-services.md +768 -0
- package/template/.claude/rules/32-client-state-zustand.md +324 -0
- package/template/.claude/rules/33-client-app-entry.md +276 -0
- package/template/.claude/rules/34-client-admin-module.md +445 -0
- package/template/.claude/rules/35-cli-module.md +259 -0
- package/template/.claude/rules/40-admin-module.md +495 -0
- package/template/.claude/rules/40-shared-types.md +450 -0
- package/template/.claude/rules/50-websocket.md +245 -0
- package/template/.claude/rules/51-sse.md +372 -0
- package/template/.claude/rules/52-cloudflare-realtime.md +384 -0
- package/template/.claude/rules/60-testing-standards.md +245 -0
- package/template/.claude/rules/61-hono-testing.md +200 -0
- package/template/.claude/scripts/README.md +187 -0
- package/template/.claude/scripts/check-duplicate-types.ts +188 -0
- package/template/.claude/scripts/post-edit-check-incremental.sh +61 -0
- package/template/.claude/scripts/post-edit-check.sh +22 -0
- package/template/.claude/scripts/pre-tool-use-check.sh +86 -0
- package/template/.claude/scripts/test-pre-tool-use.sh +73 -0
- package/template/.claude/scripts/validate-git-changes.sh +38 -0
- package/template/.claude/settings.json +32 -0
- package/template/.claude/skills/writing-hookify-rules/SKILL.md +408 -0
- package/template/.dev-context-compact.md +54 -0
- package/template/.dev-context.md +621 -0
- package/template/.dev-guide.md +243 -0
- package/template/.env.example +60 -0
- package/template/.eslintrc.routes.json +39 -0
- package/template/.husky/_/husky.sh +27 -0
- package/template/.husky/commit-msg +4 -0
- package/template/.husky/post-commit +4 -0
- package/template/.husky/pre-commit +19 -0
- package/template/.husky/pre-push +12 -0
- package/template/.prettierignore +22 -0
- package/template/.prettierrc +8 -0
- package/template/.sessions/3/2026-03-26T05-41-09-154Z_03bb597f-3898-4a2e-8c08-5746bbe8d95e.jsonl +18 -0
- package/template/.sessions/3/2026-03-26T05-48-30-052Z_12de4774-9cb3-494c-9852-bd1e6b0003c3.jsonl +6 -0
- package/template/.vscode/extensions.json +8 -0
- package/template/.vscode/settings.json +4 -0
- package/template/.workspaces/3/hello.py +1 -0
- package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite +0 -0
- package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite-shm +0 -0
- package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite-wal +0 -0
- package/template/CLAUDE.md +296 -0
- package/template/DESIGN.md +260 -0
- package/template/DEV_CONTEXT_GUIDE.md +366 -0
- package/template/DEV_TOOLS_README.md +396 -0
- package/template/FRAMEWORK_HISTORY.md +34 -0
- package/template/PROJECT_SUMMARY.md +325 -0
- package/template/QUICKSTART.md +305 -0
- package/template/README.md +154 -0
- package/template/STRUCTURE.txt +81 -0
- package/template/admin.html +13 -0
- package/template/auth-inject.html +33 -0
- package/template/commitlint.config.js +12 -0
- package/template/docs/PERMISSION_ARCHITECTURE.md +279 -0
- package/template/docs/PERMISSION_EXAMPLES.md +230 -0
- package/template/docs/PERMISSION_SYSTEM.md +301 -0
- package/template/docs/SMART_TEST.md +171 -0
- package/template/docs/runtime-abstract.md +253 -0
- package/template/drizzle/0000_rainy_boomer.sql +101 -0
- package/template/drizzle/0001_add_todo_attachments.sql +12 -0
- package/template/drizzle/0002_chilly_magneto.sql +89 -0
- package/template/drizzle/meta/0000_snapshot.json +652 -0
- package/template/drizzle/meta/0001_snapshot.json +735 -0
- package/template/drizzle/meta/0002_snapshot.json +1198 -0
- package/template/drizzle/meta/_journal.json +27 -0
- package/template/drizzle.config.ts +13 -0
- package/template/eslint-rules/README-no-middleware-in-routes.md +154 -0
- package/template/eslint-rules/__tests__/enforce-valid-method.test.ts +251 -0
- package/template/eslint-rules/__tests__/layer-boundary.test.ts +102 -0
- package/template/eslint-rules/__tests__/module-boundary.test.ts +77 -0
- package/template/eslint-rules/__tests__/no-direct-zod-import-in-file-routes.test.ts +45 -0
- package/template/eslint-rules/__tests__/no-new-old-service-naming.test.ts +76 -0
- package/template/eslint-rules/e2e-test-location.js +153 -0
- package/template/eslint-rules/enforce-valid-method.js +217 -0
- package/template/eslint-rules/flat-routes-services.js +69 -0
- package/template/eslint-rules/framework-protect.js +186 -0
- package/template/eslint-rules/layer-boundary.js +164 -0
- package/template/eslint-rules/limit-type-complexity.js +130 -0
- package/template/eslint-rules/middleware-location.js +162 -0
- package/template/eslint-rules/module-boundary.js +125 -0
- package/template/eslint-rules/no-ambiguous-file-paths.js +64 -0
- package/template/eslint-rules/no-any-on-apiclient.js +173 -0
- package/template/eslint-rules/no-boolean-success.js +43 -0
- package/template/eslint-rules/no-deep-relative-imports.js +69 -0
- package/template/eslint-rules/no-direct-fetch.js +122 -0
- package/template/eslint-rules/no-direct-ws-sse.js +57 -0
- package/template/eslint-rules/no-direct-zod-import-in-file-routes.js +54 -0
- package/template/eslint-rules/no-disable-direct-fetch.js +57 -0
- package/template/eslint-rules/no-disable-type-safe-client.js +58 -0
- package/template/eslint-rules/no-inline-schema.js +220 -0
- package/template/eslint-rules/no-middleware-in-routes.js +81 -0
- package/template/eslint-rules/no-new-old-service-naming.js +123 -0
- package/template/eslint-rules/no-type-assertion-in-rpc.js +99 -0
- package/template/eslint-rules/no-type-assertion-on-shared-types.js +109 -0
- package/template/eslint-rules/no-util-functions-in-service.js +128 -0
- package/template/eslint-rules/prefer-shared-types.js +352 -0
- package/template/eslint-rules/protect-ws-sse-interface.js +66 -0
- package/template/eslint-rules/require-antd-generic-types.js +73 -0
- package/template/eslint-rules/require-file-openapi-props.js +114 -0
- package/template/eslint-rules/require-hono-chain-syntax.js +129 -0
- package/template/eslint-rules/require-nullable-for-optional.js +99 -0
- package/template/eslint-rules/require-response-helpers.js +140 -0
- package/template/eslint-rules/require-type-safe-test-client.js +106 -0
- package/template/eslint-rules/route-location.js +72 -0
- package/template/eslint.config.js +231 -0
- package/template/index.html +17 -0
- package/template/lint-scripts/DIRECTORY_RULES.md +335 -0
- package/template/lint-scripts/README.md +299 -0
- package/template/lint-scripts/TESTING.md +273 -0
- package/template/lint-scripts/ai-context-generator.ts +159 -0
- package/template/lint-scripts/check-framework-modify.sh +8 -0
- package/template/lint-scripts/check-menu-permissions.js +242 -0
- package/template/lint-scripts/check-refs.ts +165 -0
- package/template/lint-scripts/check-route-auth-complete.js +260 -0
- package/template/lint-scripts/check-route-auth.js +212 -0
- package/template/lint-scripts/check-route-permissions.js +210 -0
- package/template/lint-scripts/config/project.config.ts +358 -0
- package/template/lint-scripts/dev-context-analyzer.ts +707 -0
- package/template/lint-scripts/dev-guide-generator.ts +830 -0
- package/template/lint-scripts/dev-server.ts +58 -0
- package/template/lint-scripts/eslint-route-auth.js +158 -0
- package/template/lint-scripts/eslint-routes-permission.js +147 -0
- package/template/lint-scripts/fix-route-auth.js +245 -0
- package/template/lint-scripts/framework/check-modify.ts +152 -0
- package/template/lint-scripts/framework/hash-utils.ts +180 -0
- package/template/lint-scripts/framework/init-baseline.ts +84 -0
- package/template/lint-scripts/framework/update-baseline.ts +148 -0
- package/template/lint-scripts/post-commit-track.ts +66 -0
- package/template/lint-scripts/quick-test.sh +27 -0
- package/template/lint-scripts/smart-test.ts +268 -0
- package/template/lint-scripts/test-history.ts +360 -0
- package/template/lint-scripts/test-tracker.ts +350 -0
- package/template/lint-scripts/validate-all.ts +250 -0
- package/template/lint-scripts/validators/api-coverage.validator.ts +355 -0
- package/template/lint-scripts/validators/client-rpc.validator.ts +190 -0
- package/template/lint-scripts/validators/client-tests.validator.ts +155 -0
- package/template/lint-scripts/validators/console-log.validator.ts +122 -0
- package/template/lint-scripts/validators/directory-structure.validator.ts +181 -0
- package/template/lint-scripts/validators/imports.validator.ts +180 -0
- package/template/lint-scripts/validators/index.ts +271 -0
- package/template/lint-scripts/validators/md-refs.validator.ts +165 -0
- package/template/lint-scripts/validators/module-tests.validator.ts +112 -0
- package/template/lint-scripts/validators/sensitive.validator.ts +185 -0
- package/template/lint-scripts/validators/server-rpc.validator.ts +141 -0
- package/template/lint-scripts/validators/test-quality.validator.ts +257 -0
- package/template/lint-scripts/validators/todos.validator.ts +126 -0
- package/template/lint-scripts/watch-validator.ts +131 -0
- package/template/modules.config.ts +71 -0
- package/template/package-lock.json +14554 -0
- package/template/package.json +158 -0
- package/template/patches/@hono+zod-openapi+1.2.2.patch +67 -0
- package/template/patches/@hono+zod-validator+0.7.6.patch +13 -0
- package/template/patches/hono+4.12.16.patch +246 -0
- package/template/patches/typescript+5.8.3.patch +26 -0
- package/template/playwright.config.ts +60 -0
- package/template/pnpm-lock.yaml +7137 -0
- package/template/postcss.config.js +6 -0
- package/template/scripts/create-template.ts +1724 -0
- package/template/src/admin/App.tsx +59 -0
- package/template/src/admin/components/AccountSwitcher.tsx +104 -0
- package/template/src/admin/components/CaptchaModal.tsx +150 -0
- package/template/src/admin/components/NotificationDrawer.tsx +213 -0
- package/template/src/admin/components/PageHeader.tsx +45 -0
- package/template/src/admin/components/PermissionConfigEditor.tsx +237 -0
- package/template/src/admin/components/PermissionGuard.tsx +108 -0
- package/template/src/admin/components/PermissionTree.tsx +193 -0
- package/template/src/admin/components/ProtectedRoute.tsx +33 -0
- package/template/src/admin/components/StatsCard.tsx +44 -0
- package/template/src/admin/components/UserFormModal.tsx +67 -0
- package/template/src/admin/components/UserTable.tsx +72 -0
- package/template/src/admin/components/__tests__/PageHeader.test.tsx +48 -0
- package/template/src/admin/components/__tests__/PermissionConfigEditor.test.tsx +147 -0
- package/template/src/admin/components/__tests__/PermissionGuard.test.tsx +221 -0
- package/template/src/admin/components/__tests__/PermissionTree.test.tsx +187 -0
- package/template/src/admin/components/__tests__/ProtectedRoute.test.tsx +129 -0
- package/template/src/admin/components/__tests__/StatsCard.test.tsx +44 -0
- package/template/src/admin/components/__tests__/UserFormModal.test.tsx +125 -0
- package/template/src/admin/components/__tests__/UserTable.test.tsx +89 -0
- package/template/src/admin/components/index.ts +7 -0
- package/template/src/admin/hooks/__tests__/useAuditLogs.test.ts +109 -0
- package/template/src/admin/hooks/__tests__/usePermissions.test.tsx +327 -0
- package/template/src/admin/hooks/__tests__/usePermissionsBranches.test.ts +198 -0
- package/template/src/admin/hooks/__tests__/useRoles.test.ts +261 -0
- package/template/src/admin/hooks/useAdminNotifications.ts +156 -0
- package/template/src/admin/hooks/useAuditLogs.ts +44 -0
- package/template/src/admin/hooks/useConfig.ts +168 -0
- package/template/src/admin/hooks/usePermissions.ts +156 -0
- package/template/src/admin/hooks/useRoles.ts +120 -0
- package/template/src/admin/layouts/Header.tsx +93 -0
- package/template/src/admin/layouts/Layout.tsx +23 -0
- package/template/src/admin/layouts/Sidebar.tsx +120 -0
- package/template/src/admin/main.tsx +18 -0
- package/template/src/admin/pages/ContentPage.tsx +252 -0
- package/template/src/admin/pages/DashboardPage.tsx +141 -0
- package/template/src/admin/pages/DisputesPage.tsx +261 -0
- package/template/src/admin/pages/LoginPage.tsx +121 -0
- package/template/src/admin/pages/MediaTestPage.tsx +524 -0
- package/template/src/admin/pages/OrdersPage.tsx +302 -0
- package/template/src/admin/pages/PermissionsPage.tsx +95 -0
- package/template/src/admin/pages/RegisterPage.tsx +103 -0
- package/template/src/admin/pages/RolesPage.tsx +330 -0
- package/template/src/admin/pages/SettingsPage.tsx +73 -0
- package/template/src/admin/pages/SystemLogsPage.tsx +218 -0
- package/template/src/admin/pages/TestCaptchaPage.tsx +120 -0
- package/template/src/admin/pages/TicketsPage.tsx +292 -0
- package/template/src/admin/pages/UsersPage.tsx +282 -0
- package/template/src/admin/pages/__tests__/ContentPage.test.tsx +213 -0
- package/template/src/admin/pages/__tests__/DashboardPage.test.tsx +153 -0
- package/template/src/admin/pages/__tests__/DisputesPage.test.tsx +196 -0
- package/template/src/admin/pages/__tests__/LoginPage.test.tsx +112 -0
- package/template/src/admin/pages/__tests__/OrdersPage.test.tsx +217 -0
- package/template/src/admin/pages/__tests__/PermissionsPage.test.tsx +119 -0
- package/template/src/admin/pages/__tests__/RegisterPage.test.tsx +179 -0
- package/template/src/admin/pages/__tests__/RolesPage.test.tsx +256 -0
- package/template/src/admin/pages/__tests__/SettingsPage.test.tsx +66 -0
- package/template/src/admin/pages/__tests__/SystemLogsPage.test.tsx +125 -0
- package/template/src/admin/pages/__tests__/TicketsPage.test.tsx +202 -0
- package/template/src/admin/pages/__tests__/UsersPage.test.tsx +229 -0
- package/template/src/admin/services/README.md +263 -0
- package/template/src/admin/services/TESTING.md +323 -0
- package/template/src/admin/services/__tests__/skipLoading.test.ts +146 -0
- package/template/src/admin/services/apiClient.ts +66 -0
- package/template/src/admin/services/requestInterceptor.ts +127 -0
- package/template/src/admin/services/types.ts +5 -0
- package/template/src/admin/stores/__tests__/adminStore.test.ts +184 -0
- package/template/src/admin/stores/__tests__/adminStoreBranches.test.ts +148 -0
- package/template/src/admin/stores/__tests__/captchaStore.test.ts +75 -0
- package/template/src/admin/stores/__tests__/captchaStoreBranches.test.ts +37 -0
- package/template/src/admin/stores/__tests__/loadingStore.test.ts +68 -0
- package/template/src/admin/stores/adminStore.ts +88 -0
- package/template/src/admin/stores/captchaStore.ts +47 -0
- package/template/src/admin/stores/loadingStore.ts +27 -0
- package/template/src/cli/index.ts +22 -0
- package/template/src/cli/modules/config/index.ts +132 -0
- package/template/src/cli/modules/index.ts +12 -0
- package/template/src/cli/modules/notification/index.ts +86 -0
- package/template/src/cli/modules/todo/index.ts +60 -0
- package/template/src/cli/rpc/client.ts +23 -0
- package/template/src/cli/rpc/index.ts +1 -0
- package/template/src/cli/utils/api.ts +17 -0
- package/template/src/cli/utils/auto-command.ts +229 -0
- package/template/src/cli/utils/index.ts +8 -0
- package/template/src/cli/utils/logger.ts +79 -0
- package/template/src/client/App.tsx +24 -0
- package/template/src/client/Layout.tsx +27 -0
- package/template/src/client/components/AuthButton.tsx +41 -0
- package/template/src/client/components/ConnectionStatus.tsx +75 -0
- package/template/src/client/components/EmptyState.tsx +26 -0
- package/template/src/client/components/Footer.tsx +17 -0
- package/template/src/client/components/LoadingSpinner.tsx +26 -0
- package/template/src/client/components/MessageCard.tsx +61 -0
- package/template/src/client/components/Navigation.tsx +65 -0
- package/template/src/client/components/StatusBadge.tsx +50 -0
- package/template/src/client/components/__tests__/App.test.tsx +79 -0
- package/template/src/client/components/__tests__/AuthButton.test.tsx +119 -0
- package/template/src/client/components/__tests__/ConnectionStatus.test.tsx +188 -0
- package/template/src/client/components/__tests__/EmptyState.test.tsx +70 -0
- package/template/src/client/components/__tests__/Footer.test.tsx +22 -0
- package/template/src/client/components/__tests__/LoadingSpinner.test.tsx +75 -0
- package/template/src/client/components/__tests__/MessageCard.test.tsx +142 -0
- package/template/src/client/components/__tests__/Navigation.test.tsx +40 -0
- package/template/src/client/components/__tests__/StatusBadge.test.tsx +107 -0
- package/template/src/client/components/index.ts +6 -0
- package/template/src/client/index.css +27 -0
- package/template/src/client/main.tsx +25 -0
- package/template/src/client/pages/ContentDetailPage.tsx +142 -0
- package/template/src/client/pages/ContentListPage.tsx +169 -0
- package/template/src/client/pages/NotificationPage.tsx +288 -0
- package/template/src/client/pages/TodoPage.tsx +389 -0
- package/template/src/client/pages/WebSocketPage.tsx +239 -0
- package/template/src/client/pages/__tests__/ContentDetailPage.test.tsx +176 -0
- package/template/src/client/pages/__tests__/ContentListPage.test.tsx +202 -0
- package/template/src/client/pages/__tests__/NotificationPage.test.tsx +246 -0
- package/template/src/client/pages/__tests__/TodoPage.test.tsx +433 -0
- package/template/src/client/pages/__tests__/WebSocketPage.test.tsx +378 -0
- package/template/src/client/services/apiClient.ts +66 -0
- package/template/src/client/stores/__tests__/authStore.test.ts +139 -0
- package/template/src/client/stores/__tests__/chatWSStore.test.ts +416 -0
- package/template/src/client/stores/__tests__/notificationStore.test.ts +453 -0
- package/template/src/client/stores/__tests__/todoStore.test.ts +509 -0
- package/template/src/client/stores/authStore.ts +51 -0
- package/template/src/client/stores/chatWSStore.ts +122 -0
- package/template/src/client/stores/notificationStore.ts +199 -0
- package/template/src/client/stores/todoStore.ts +207 -0
- package/template/src/server/__tests__/integration/todos-api.test.ts +138 -0
- package/template/src/server/app.ts +105 -0
- package/template/src/server/config.ts +86 -0
- package/template/src/server/core/__tests__/realtime-core.test.ts +329 -0
- package/template/src/server/core/__tests__/realtime-scanner.test.ts +210 -0
- package/template/src/server/core/__tests__/runtime-node.test.ts +330 -0
- package/template/src/server/core/__tests__/runtime.test.ts +219 -0
- package/template/src/server/core/__tests__/typed-runtime.test.ts +178 -0
- package/template/src/server/core/durable-objects/RealtimeDO.ts +206 -0
- package/template/src/server/core/index.ts +83 -0
- package/template/src/server/core/module-loader.ts +281 -0
- package/template/src/server/core/realtime-core.ts +152 -0
- package/template/src/server/core/realtime-scanner.ts +99 -0
- package/template/src/server/core/runtime-cloudflare.ts +207 -0
- package/template/src/server/core/runtime-node.ts +170 -0
- package/template/src/server/core/runtime.ts +129 -0
- package/template/src/server/core/typed-runtime.ts +80 -0
- package/template/src/server/db/__tests__/driver.test.ts +203 -0
- package/template/src/server/db/config.ts +1 -0
- package/template/src/server/db/driver-cloudflare.ts +50 -0
- package/template/src/server/db/driver.ts +116 -0
- package/template/src/server/db/index.ts +3 -0
- package/template/src/server/db/init.ts +412 -0
- package/template/src/server/db/schema/api-endpoints.ts +23 -0
- package/template/src/server/db/schema/contents.ts +31 -0
- package/template/src/server/db/schema/disputes.ts +39 -0
- package/template/src/server/db/schema/index.ts +14 -0
- package/template/src/server/db/schema/notifications.ts +16 -0
- package/template/src/server/db/schema/orders.ts +30 -0
- package/template/src/server/db/schema/permission-audit-logs.ts +17 -0
- package/template/src/server/db/schema/permission-route-mappings.ts +22 -0
- package/template/src/server/db/schema/permissions.ts +17 -0
- package/template/src/server/db/schema/role-permissions.ts +22 -0
- package/template/src/server/db/schema/roles.ts +17 -0
- package/template/src/server/db/schema/tickets.ts +62 -0
- package/template/src/server/db/schema/todo-attachments.ts +22 -0
- package/template/src/server/db/schema/todos.ts +21 -0
- package/template/src/server/db/schema/user-roles.ts +17 -0
- package/template/src/server/db/seeds/index.ts +1 -0
- package/template/src/server/db/seeds/permission-data.ts +354 -0
- package/template/src/server/db/test-setup.ts +647 -0
- package/template/src/server/entries/cloudflare.ts +71 -0
- package/template/src/server/entries/node.ts +190 -0
- package/template/src/server/index.ts +62 -0
- package/template/src/server/middleware/__tests__/auth-simple.test.ts +147 -0
- package/template/src/server/middleware/__tests__/auth.test.ts +276 -0
- package/template/src/server/middleware/__tests__/captcha.test.ts +258 -0
- package/template/src/server/middleware/__tests__/error-handler.test.ts +364 -0
- package/template/src/server/middleware/__tests__/error-response-format.test.ts +80 -0
- package/template/src/server/middleware/__tests__/permission.test.ts +312 -0
- package/template/src/server/middleware/audit-log.ts +101 -0
- package/template/src/server/middleware/auth.ts +235 -0
- package/template/src/server/middleware/captcha.ts +166 -0
- package/template/src/server/middleware/cors.ts +30 -0
- package/template/src/server/middleware/error-handler.ts +135 -0
- package/template/src/server/middleware/index.ts +24 -0
- package/template/src/server/middleware/logger.ts +73 -0
- package/template/src/server/middleware/permission.ts +127 -0
- package/template/src/server/middleware/rate-limit.ts +69 -0
- package/template/src/server/middleware/realtime-env.ts +12 -0
- package/template/src/server/module-admin/__tests__/admin-routes.test.ts +360 -0
- package/template/src/server/module-admin/__tests__/admin-service.test.ts +222 -0
- package/template/src/server/module-admin/__tests__/audit-log-routes.test.ts +261 -0
- package/template/src/server/module-admin/__tests__/export-routes.test.ts +160 -0
- package/template/src/server/module-admin/__tests__/media-routes.test.ts +122 -0
- package/template/src/server/module-admin/module.ts +40 -0
- package/template/src/server/module-admin/routes/admin-notification-routes.ts +197 -0
- package/template/src/server/module-admin/routes/admin-routes.ts +20 -0
- package/template/src/server/module-admin/routes/auth-routes.ts +86 -0
- package/template/src/server/module-admin/routes/export-routes.ts +207 -0
- package/template/src/server/module-admin/routes/media-routes.ts +78 -0
- package/template/src/server/module-admin/routes/system-routes.ts +89 -0
- package/template/src/server/module-admin/routes/user-management-routes.ts +143 -0
- package/template/src/server/module-admin/services/admin-service.ts +268 -0
- package/template/src/server/module-captcha/__tests__/captcha-route.test.ts +35 -0
- package/template/src/server/module-captcha/__tests__/captcha-service.test.ts +53 -0
- package/template/src/server/module-captcha/module.ts +35 -0
- package/template/src/server/module-captcha/routes/captcha-routes.ts +68 -0
- package/template/src/server/module-captcha/services/captcha-service.ts +3 -0
- package/template/src/server/module-chat/__tests__/chat-routes.test.ts +39 -0
- package/template/src/server/module-chat/__tests__/chat-rpc.test.ts +185 -0
- package/template/src/server/module-chat/__tests__/chat-service.test.ts +64 -0
- package/template/src/server/module-chat/module.ts +27 -0
- package/template/src/server/module-chat/routes/chat-routes.ts +46 -0
- package/template/src/server/module-chat/services/chat-service.ts +38 -0
- package/template/src/server/module-content/__tests__/content-route.test.ts +40 -0
- package/template/src/server/module-content/__tests__/content-service.test.ts +107 -0
- package/template/src/server/module-content/module.ts +39 -0
- package/template/src/server/module-content/routes/content-routes.ts +182 -0
- package/template/src/server/module-content/routes/public-content-routes.ts +58 -0
- package/template/src/server/module-content/services/content-service.ts +224 -0
- package/template/src/server/module-dispute/__tests__/dispute-route.test.ts +43 -0
- package/template/src/server/module-dispute/__tests__/dispute-service.test.ts +135 -0
- package/template/src/server/module-dispute/module.ts +30 -0
- package/template/src/server/module-dispute/routes/dispute-routes.ts +153 -0
- package/template/src/server/module-dispute/services/dispute-service.ts +255 -0
- package/template/src/server/module-file/__tests__/file-routes.test.ts +284 -0
- package/template/src/server/module-file/__tests__/file-storage-service.test.ts +323 -0
- package/template/src/server/module-file/module.ts +28 -0
- package/template/src/server/module-file/routes/file-routes.ts +288 -0
- package/template/src/server/module-notifications/__tests__/notification-route-rpc.test.ts +375 -0
- package/template/src/server/module-notifications/__tests__/notification-service.test.ts +241 -0
- package/template/src/server/module-notifications/__tests__/sse-rpc.test.ts +289 -0
- package/template/src/server/module-notifications/module.ts +32 -0
- package/template/src/server/module-notifications/routes/notification-routes.ts +190 -0
- package/template/src/server/module-notifications/services/notification-service.ts +104 -0
- package/template/src/server/module-order/__tests__/order-route.test.ts +258 -0
- package/template/src/server/module-order/__tests__/order-service.test.ts +222 -0
- package/template/src/server/module-order/module.ts +30 -0
- package/template/src/server/module-order/routes/order-routes.ts +202 -0
- package/template/src/server/module-order/services/order-service.ts +268 -0
- package/template/src/server/module-permission/__tests__/permission-middleware.test.ts +90 -0
- package/template/src/server/module-permission/__tests__/permission-routes.test.ts +330 -0
- package/template/src/server/module-permission/__tests__/permission-service-impl.test.ts +388 -0
- package/template/src/server/module-permission/__tests__/permission-service.test.ts +190 -0
- package/template/src/server/module-permission/__tests__/role-routes.test.ts +215 -0
- package/template/src/server/module-permission/module.ts +68 -0
- package/template/src/server/module-permission/routes/audit-log-routes.ts +76 -0
- package/template/src/server/module-permission/routes/permission-routes.ts +184 -0
- package/template/src/server/module-permission/routes/role-routes.ts +263 -0
- package/template/src/server/module-permission/services/audit-log-service.ts +108 -0
- package/template/src/server/module-permission/services/permission-service-impl.ts +233 -0
- package/template/src/server/module-permission/services/permission-service.ts +256 -0
- package/template/src/server/module-permission/services/role-service.ts +122 -0
- package/template/src/server/module-ticket/__tests__/ticket-route.test.ts +173 -0
- package/template/src/server/module-ticket/__tests__/ticket-service.test.ts +201 -0
- package/template/src/server/module-ticket/module.ts +30 -0
- package/template/src/server/module-ticket/routes/ticket-routes.ts +210 -0
- package/template/src/server/module-ticket/services/ticket-service.ts +297 -0
- package/template/src/server/module-todos/__tests__/todo-service.test.ts +196 -0
- package/template/src/server/module-todos/__tests__/todos-file-upload.test.ts +439 -0
- package/template/src/server/module-todos/__tests__/todos-route-rpc.test.ts +575 -0
- package/template/src/server/module-todos/module.ts +30 -0
- package/template/src/server/module-todos/routes/todos-routes.ts +260 -0
- package/template/src/server/module-todos/services/todo-service.ts +202 -0
- package/template/src/server/route-registry.ts +47 -0
- package/template/src/server/test-utils/test-client.ts +66 -0
- package/template/src/server/test-utils/test-server.ts +131 -0
- package/template/src/server/types/bindings.ts +10 -0
- package/template/src/server/utils/__tests__/app-error.test.ts +374 -0
- package/template/src/server/utils/__tests__/auth.test.ts +76 -0
- package/template/src/server/utils/__tests__/captcha.test.ts +80 -0
- package/template/src/server/utils/__tests__/file-storage.test.ts +472 -0
- package/template/src/server/utils/__tests__/logger.test.ts +221 -0
- package/template/src/server/utils/__tests__/route-helpers.test.ts +264 -0
- package/template/src/server/utils/app-error.ts +355 -0
- package/template/src/server/utils/auth.ts +65 -0
- package/template/src/server/utils/captcha.ts +119 -0
- package/template/src/server/utils/date.ts +50 -0
- package/template/src/server/utils/env.ts +4 -0
- package/template/src/server/utils/file-storage.ts +462 -0
- package/template/src/server/utils/generate.ts +26 -0
- package/template/src/server/utils/id-helpers.ts +5 -0
- package/template/src/server/utils/logger.ts +139 -0
- package/template/src/server/utils/permission-utils.ts +6 -0
- package/template/src/server/utils/response.ts +40 -0
- package/template/src/server/utils/route-helpers.ts +200 -0
- package/template/src/server/utils/uuid.ts +8 -0
- package/template/src/server/utils/ws-helper.ts +30 -0
- package/template/src/shared/constants/index.ts +1 -0
- package/template/src/shared/constants/resource-types.ts +72 -0
- package/template/src/shared/core/__tests__/sse-client.test.ts +376 -0
- package/template/src/shared/core/__tests__/ws-client.test.ts +468 -0
- package/template/src/shared/core/api-request.ts +192 -0
- package/template/src/shared/core/api-schemas.ts +41 -0
- package/template/src/shared/core/index.ts +37 -0
- package/template/src/shared/core/module-manifest.ts +120 -0
- package/template/src/shared/core/protocol-types.ts +26 -0
- package/template/src/shared/core/sse-client.ts +185 -0
- package/template/src/shared/core/ws-client.ts +236 -0
- package/template/src/shared/hooks/index.ts +2 -0
- package/template/src/shared/hooks/useSSE.ts +57 -0
- package/template/src/shared/hooks/useWebSocket.ts +66 -0
- package/template/src/shared/index.ts +5 -0
- package/template/src/shared/modules/admin/index.ts +1 -0
- package/template/src/shared/modules/admin/schemas.ts +100 -0
- package/template/src/shared/modules/audit/index.ts +1 -0
- package/template/src/shared/modules/audit/schemas.ts +24 -0
- package/template/src/shared/modules/captcha/index.ts +1 -0
- package/template/src/shared/modules/captcha/schemas.ts +19 -0
- package/template/src/shared/modules/chat/index.ts +38 -0
- package/template/src/shared/modules/content/index.ts +1 -0
- package/template/src/shared/modules/content/schemas.ts +53 -0
- package/template/src/shared/modules/dispute/index.ts +1 -0
- package/template/src/shared/modules/dispute/schemas.ts +62 -0
- package/template/src/shared/modules/files/index.ts +11 -0
- package/template/src/shared/modules/files/schemas.ts +44 -0
- package/template/src/shared/modules/index.ts +70 -0
- package/template/src/shared/modules/notifications/index.ts +26 -0
- package/template/src/shared/modules/notifications/schemas.ts +73 -0
- package/template/src/shared/modules/order/index.ts +1 -0
- package/template/src/shared/modules/order/schemas.ts +63 -0
- package/template/src/shared/modules/permission/index.ts +42 -0
- package/template/src/shared/modules/permission/permission-dependencies.ts +50 -0
- package/template/src/shared/modules/permission/permissions.ts +275 -0
- package/template/src/shared/modules/permission/schemas.ts +92 -0
- package/template/src/shared/modules/permission/types.ts +23 -0
- package/template/src/shared/modules/role/index.ts +1 -0
- package/template/src/shared/modules/role/schemas.ts +46 -0
- package/template/src/shared/modules/ticket/index.ts +1 -0
- package/template/src/shared/modules/ticket/schemas.ts +77 -0
- package/template/src/shared/modules/todos/index.ts +20 -0
- package/template/src/shared/modules/todos/schemas.ts +65 -0
- package/template/src/shared/schemas/index.ts +79 -0
- package/template/src/types/global.d.ts +14 -0
- package/template/src/vite-env.d.ts +21 -0
- package/template/tailwind.config.js +11 -0
- package/template/tests/e2e/admin-crud.spec.ts +81 -0
- package/template/tests/e2e/case-o1.spec.ts +108 -0
- package/template/tests/e2e/global-setup.ts +73 -0
- package/template/tests/e2e/global-teardown.ts +28 -0
- package/template/tests/e2e/notification.spec.ts +458 -0
- package/template/tests/e2e/todo.spec.ts +623 -0
- package/template/tests/e2e/websocket.spec.ts +254 -0
- package/template/tsconfig.json +35 -0
- package/template/tsup.config.ts +95 -0
- package/template/vite-plugins.ts +113 -0
- package/template/vite.config.ts +96 -0
- package/template/vitest.config.ts +53 -0
- package/template/vitest.integration.config.ts +24 -0
- package/template/vitest.integration.setup.ts +22 -0
- package/template/vitest.setup.ts +74 -0
- package/template/wrangler.toml +33 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { create } from 'zustand'
|
|
2
|
+
import { apiClient } from '@client/services/apiClient'
|
|
3
|
+
import type {
|
|
4
|
+
AppNotification,
|
|
5
|
+
CreateNotificationInput,
|
|
6
|
+
SSEClient,
|
|
7
|
+
AppSSEProtocol,
|
|
8
|
+
} from '@shared/schemas'
|
|
9
|
+
|
|
10
|
+
interface NotificationState {
|
|
11
|
+
notifications: AppNotification[]
|
|
12
|
+
unreadCount: number
|
|
13
|
+
loading: boolean
|
|
14
|
+
error: string | null
|
|
15
|
+
sseConnected: boolean
|
|
16
|
+
|
|
17
|
+
fetchNotifications: (unreadOnly?: boolean) => Promise<void>
|
|
18
|
+
createNotification: (input: CreateNotificationInput) => Promise<void>
|
|
19
|
+
markAsRead: (id: string) => Promise<void>
|
|
20
|
+
markAllAsRead: () => Promise<void>
|
|
21
|
+
deleteNotification: (id: string) => Promise<void>
|
|
22
|
+
fetchUnreadCount: () => Promise<void>
|
|
23
|
+
connectSSE: () => Promise<void>
|
|
24
|
+
disconnectSSE: () => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let sseClient: SSEClient<AppSSEProtocol> | null = null
|
|
28
|
+
|
|
29
|
+
export const useNotificationStore = create<NotificationState>(set => ({
|
|
30
|
+
notifications: [],
|
|
31
|
+
unreadCount: 0,
|
|
32
|
+
loading: false,
|
|
33
|
+
error: null,
|
|
34
|
+
sseConnected: false,
|
|
35
|
+
|
|
36
|
+
fetchNotifications: async (unreadOnly = false) => {
|
|
37
|
+
set({ loading: true, error: null })
|
|
38
|
+
try {
|
|
39
|
+
const response = await apiClient.api.notifications.$get({
|
|
40
|
+
query: { unreadOnly: String(unreadOnly) },
|
|
41
|
+
})
|
|
42
|
+
const result = await response.json()
|
|
43
|
+
if (result.success) {
|
|
44
|
+
set({ notifications: result.data.items, loading: false })
|
|
45
|
+
} else {
|
|
46
|
+
set({ error: result.error, loading: false })
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
set({
|
|
50
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
51
|
+
loading: false,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
createNotification: async input => {
|
|
57
|
+
set({ loading: true, error: null })
|
|
58
|
+
try {
|
|
59
|
+
const response = await apiClient.api.notifications.$post({
|
|
60
|
+
json: input,
|
|
61
|
+
})
|
|
62
|
+
const result = await response.json()
|
|
63
|
+
if (result.success) {
|
|
64
|
+
set(state => ({
|
|
65
|
+
notifications: [result.data, ...state.notifications],
|
|
66
|
+
unreadCount: state.unreadCount + 1,
|
|
67
|
+
loading: false,
|
|
68
|
+
}))
|
|
69
|
+
} else {
|
|
70
|
+
set({ error: result.error, loading: false })
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
set({
|
|
74
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
75
|
+
loading: false,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
markAsRead: async (id: string) => {
|
|
81
|
+
try {
|
|
82
|
+
const response = await apiClient.api.notifications[':id'].read.$patch({
|
|
83
|
+
param: { id },
|
|
84
|
+
})
|
|
85
|
+
const result = await response.json()
|
|
86
|
+
if (result.success) {
|
|
87
|
+
set(state => ({
|
|
88
|
+
notifications: state.notifications.map(n => (n.id === id ? { ...n, read: true } : n)),
|
|
89
|
+
unreadCount: Math.max(0, state.unreadCount - 1),
|
|
90
|
+
}))
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('Failed to mark as read:', error)
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
markAllAsRead: async () => {
|
|
98
|
+
try {
|
|
99
|
+
const response = await apiClient.api.notifications['read-all'].$patch()
|
|
100
|
+
const result = await response.json()
|
|
101
|
+
if (result.success) {
|
|
102
|
+
set(state => ({
|
|
103
|
+
notifications: state.notifications.map(n => ({ ...n, read: true })),
|
|
104
|
+
unreadCount: 0,
|
|
105
|
+
}))
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error('Failed to mark all as read:', error)
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
deleteNotification: async (id: string) => {
|
|
113
|
+
try {
|
|
114
|
+
const response = await apiClient.api.notifications[':id'].$delete({
|
|
115
|
+
param: { id },
|
|
116
|
+
})
|
|
117
|
+
const result = await response.json()
|
|
118
|
+
if (result.success) {
|
|
119
|
+
set(state => {
|
|
120
|
+
const notification = state.notifications.find(n => n.id === id)
|
|
121
|
+
return {
|
|
122
|
+
notifications: state.notifications.filter(n => n.id !== id),
|
|
123
|
+
unreadCount:
|
|
124
|
+
notification && !notification.read ? state.unreadCount - 1 : state.unreadCount,
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error('Failed to delete:', error)
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
fetchUnreadCount: async () => {
|
|
134
|
+
try {
|
|
135
|
+
const response = await apiClient.api.notifications['unread-count'].$get()
|
|
136
|
+
const result = await response.json()
|
|
137
|
+
if (result.success) {
|
|
138
|
+
set({ unreadCount: result.data.count })
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error('Failed to fetch unread count:', error)
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
connectSSE: async () => {
|
|
146
|
+
if (sseClient) return
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const conn = apiClient.api.notifications.stream.$sse()
|
|
150
|
+
|
|
151
|
+
conn.onStatusChange(status => {
|
|
152
|
+
if (import.meta.env.DEV) {
|
|
153
|
+
console.log('[SSE] Status changed:', status)
|
|
154
|
+
}
|
|
155
|
+
set({ sseConnected: status === 'open' })
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
conn.on('connected', payload => {
|
|
159
|
+
if (import.meta.env.DEV) {
|
|
160
|
+
console.log('[SSE] Connected:', payload)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
conn.on('notification', notification => {
|
|
165
|
+
if (import.meta.env.DEV) {
|
|
166
|
+
console.log('[SSE] Received notification:', notification)
|
|
167
|
+
}
|
|
168
|
+
set(state => {
|
|
169
|
+
if (state.notifications.some(n => n.id === notification.id)) {
|
|
170
|
+
return state
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
notifications: [notification, ...state.notifications],
|
|
174
|
+
unreadCount: notification.read ? state.unreadCount : state.unreadCount + 1,
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
conn.onError(error => {
|
|
180
|
+
console.error('[SSE] Error:', error)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
sseClient = conn
|
|
184
|
+
if (import.meta.env.DEV) {
|
|
185
|
+
console.log('[SSE] Client initialized')
|
|
186
|
+
}
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error('[SSE] Failed to connect:', error)
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
disconnectSSE: () => {
|
|
193
|
+
if (sseClient) {
|
|
194
|
+
sseClient.abort()
|
|
195
|
+
sseClient = null
|
|
196
|
+
set({ sseConnected: false })
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
}))
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { create } from 'zustand'
|
|
2
|
+
import { apiClient } from '@client/services/apiClient'
|
|
3
|
+
import type { Todo, CreateTodoInput, UpdateTodoInput, TodoAttachment } from '@shared/schemas'
|
|
4
|
+
|
|
5
|
+
interface TodoState {
|
|
6
|
+
todos: Todo[]
|
|
7
|
+
loading: boolean
|
|
8
|
+
error: string | null
|
|
9
|
+
attachments: Map<number, TodoAttachment[]>
|
|
10
|
+
|
|
11
|
+
fetchTodos: () => Promise<void>
|
|
12
|
+
createTodo: (input: CreateTodoInput) => Promise<void>
|
|
13
|
+
updateTodo: (id: number, input: UpdateTodoInput) => Promise<void>
|
|
14
|
+
deleteTodo: (id: number) => Promise<void>
|
|
15
|
+
uploadAttachment: (todoId: number, file: File) => Promise<TodoAttachment | null>
|
|
16
|
+
fetchAttachments: (todoId: number) => Promise<void>
|
|
17
|
+
deleteAttachment: (todoId: number, attachmentId: number) => Promise<void>
|
|
18
|
+
setError: (error: string | null) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useTodoStore = create<TodoState>(set => ({
|
|
22
|
+
todos: [],
|
|
23
|
+
loading: false,
|
|
24
|
+
error: null,
|
|
25
|
+
attachments: new Map(),
|
|
26
|
+
|
|
27
|
+
fetchTodos: async () => {
|
|
28
|
+
set({ loading: true, error: null })
|
|
29
|
+
try {
|
|
30
|
+
const response = await apiClient.api.todos.$get()
|
|
31
|
+
const result = await response.json()
|
|
32
|
+
if (result.success) {
|
|
33
|
+
const data = result.data as Todo[] | { items: Todo[] }
|
|
34
|
+
const items = Array.isArray(data) ? data : data.items || []
|
|
35
|
+
set({ todos: items, loading: false })
|
|
36
|
+
} else {
|
|
37
|
+
set({ error: result.error, loading: false })
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
set({
|
|
41
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
42
|
+
loading: false,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
createTodo: async (input: CreateTodoInput) => {
|
|
48
|
+
set({ loading: true, error: null })
|
|
49
|
+
try {
|
|
50
|
+
const response = await apiClient.api.todos.$post({
|
|
51
|
+
json: input,
|
|
52
|
+
})
|
|
53
|
+
const result = await response.json()
|
|
54
|
+
if (result.success) {
|
|
55
|
+
set(state => ({
|
|
56
|
+
todos: [result.data, ...state.todos],
|
|
57
|
+
loading: false,
|
|
58
|
+
}))
|
|
59
|
+
} else {
|
|
60
|
+
set({ error: result.error, loading: false })
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
set({
|
|
64
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
65
|
+
loading: false,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
updateTodo: async (id: number, input: UpdateTodoInput) => {
|
|
71
|
+
set({ loading: true, error: null })
|
|
72
|
+
try {
|
|
73
|
+
const response = await apiClient.api.todos[':id'].$put({
|
|
74
|
+
param: { id: id.toString() },
|
|
75
|
+
json: input,
|
|
76
|
+
})
|
|
77
|
+
const result = await response.json()
|
|
78
|
+
if (result.success) {
|
|
79
|
+
set(state => ({
|
|
80
|
+
todos: state.todos.map(todo => (todo.id === id ? result.data : todo)),
|
|
81
|
+
loading: false,
|
|
82
|
+
}))
|
|
83
|
+
} else {
|
|
84
|
+
set({ error: result.error, loading: false })
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
set({
|
|
88
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
89
|
+
loading: false,
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
deleteTodo: async (id: number) => {
|
|
95
|
+
set({ loading: true, error: null })
|
|
96
|
+
try {
|
|
97
|
+
const response = await apiClient.api.todos[':id'].$delete({
|
|
98
|
+
param: { id: id.toString() },
|
|
99
|
+
})
|
|
100
|
+
const result = await response.json()
|
|
101
|
+
if (result.success) {
|
|
102
|
+
set(state => {
|
|
103
|
+
const newAttachments = new Map(state.attachments)
|
|
104
|
+
newAttachments.delete(id)
|
|
105
|
+
return {
|
|
106
|
+
todos: state.todos.filter(todo => todo.id !== id),
|
|
107
|
+
attachments: newAttachments,
|
|
108
|
+
loading: false,
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
} else {
|
|
112
|
+
set({ error: result.error, loading: false })
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
set({
|
|
116
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
117
|
+
loading: false,
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
uploadAttachment: async (todoId: number, file: File): Promise<TodoAttachment | null> => {
|
|
123
|
+
set({ loading: true, error: null })
|
|
124
|
+
try {
|
|
125
|
+
const response = await apiClient.api.todos[':id'].attachments.$post({
|
|
126
|
+
param: { id: todoId.toString() },
|
|
127
|
+
form: { file },
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const result = (await response.json()) as {
|
|
131
|
+
success: boolean
|
|
132
|
+
data?: TodoAttachment
|
|
133
|
+
error?: string
|
|
134
|
+
}
|
|
135
|
+
if (result.success && result.data) {
|
|
136
|
+
set(state => {
|
|
137
|
+
const newAttachments = new Map(state.attachments)
|
|
138
|
+
const existing = newAttachments.get(todoId) || []
|
|
139
|
+
newAttachments.set(todoId, [...existing, result.data!])
|
|
140
|
+
return { attachments: newAttachments, loading: false }
|
|
141
|
+
})
|
|
142
|
+
return result.data
|
|
143
|
+
} else {
|
|
144
|
+
set({ error: result.error || 'Upload failed', loading: false })
|
|
145
|
+
return null
|
|
146
|
+
}
|
|
147
|
+
} catch (error) {
|
|
148
|
+
set({
|
|
149
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
150
|
+
loading: false,
|
|
151
|
+
})
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
fetchAttachments: async (todoId: number) => {
|
|
157
|
+
try {
|
|
158
|
+
const response = await apiClient.api.todos[':id'].attachments.$get({
|
|
159
|
+
param: { id: todoId.toString() },
|
|
160
|
+
})
|
|
161
|
+
const result = await response.json()
|
|
162
|
+
if (result.success) {
|
|
163
|
+
set(state => {
|
|
164
|
+
const newAttachments = new Map(state.attachments)
|
|
165
|
+
const data = result.data as TodoAttachment[] | { items: TodoAttachment[] }
|
|
166
|
+
const items = Array.isArray(data) ? data : data.items || []
|
|
167
|
+
newAttachments.set(todoId, items)
|
|
168
|
+
return { attachments: newAttachments }
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error('Failed to fetch attachments:', error)
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
deleteAttachment: async (todoId: number, attachmentId: number) => {
|
|
177
|
+
set({ loading: true, error: null })
|
|
178
|
+
try {
|
|
179
|
+
const response = await apiClient.api.todos[':todoId'].attachments[':attachmentId'].$delete({
|
|
180
|
+
param: { todoId: todoId.toString(), attachmentId: attachmentId.toString() },
|
|
181
|
+
})
|
|
182
|
+
const result = await response.json()
|
|
183
|
+
if (result.success) {
|
|
184
|
+
set(state => {
|
|
185
|
+
const newAttachments = new Map(state.attachments)
|
|
186
|
+
const existing = newAttachments.get(todoId) || []
|
|
187
|
+
newAttachments.set(
|
|
188
|
+
todoId,
|
|
189
|
+
existing.filter(a => a.id !== attachmentId)
|
|
190
|
+
)
|
|
191
|
+
return { attachments: newAttachments, loading: false }
|
|
192
|
+
})
|
|
193
|
+
} else {
|
|
194
|
+
set({ error: result.error, loading: false })
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
set({
|
|
198
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
199
|
+
loading: false,
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
setError: (error: string | null) => {
|
|
205
|
+
set({ error })
|
|
206
|
+
},
|
|
207
|
+
}))
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest'
|
|
2
|
+
import { createTestClient } from '@server/test-utils/test-client'
|
|
3
|
+
import { getDb } from '@server/db'
|
|
4
|
+
import { setupTestDatabase, cleanupTestDatabase } from '@server/db/test-setup'
|
|
5
|
+
|
|
6
|
+
describe('Integration: Todos API (Real Database)', () => {
|
|
7
|
+
const authHeaders = { Authorization: 'Bearer admin-token' }
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
await setupTestDatabase()
|
|
11
|
+
const db = await getDb()
|
|
12
|
+
expect(db).toBeDefined()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
await cleanupTestDatabase()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
await cleanupTestDatabase()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
await cleanupTestDatabase()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('Full CRUD Flow', () => {
|
|
28
|
+
it('should handle complete todo lifecycle', async () => {
|
|
29
|
+
const client = createTestClient(undefined, { headers: authHeaders })
|
|
30
|
+
|
|
31
|
+
const listRes = await client.api.todos.$get({ headers: authHeaders })
|
|
32
|
+
const listData = await listRes.json()
|
|
33
|
+
expect(listData).toMatchObject({ success: true, data: [] })
|
|
34
|
+
|
|
35
|
+
const createRes = await client.api.todos.$post(
|
|
36
|
+
{
|
|
37
|
+
json: { title: 'Integration Todo', description: 'Full test' },
|
|
38
|
+
},
|
|
39
|
+
{ headers: authHeaders }
|
|
40
|
+
)
|
|
41
|
+
expect(createRes.status).toBe(201)
|
|
42
|
+
const created = await createRes.json()
|
|
43
|
+
expect(created.success).toBe(true)
|
|
44
|
+
if (created.success && 'data' in created) {
|
|
45
|
+
expect(created.data.title).toBe('Integration Todo')
|
|
46
|
+
|
|
47
|
+
const readRes = await client.api.todos[':id'].$get(
|
|
48
|
+
{
|
|
49
|
+
param: { id: String(created.data.id) },
|
|
50
|
+
},
|
|
51
|
+
{ headers: authHeaders }
|
|
52
|
+
)
|
|
53
|
+
const readData = await readRes.json()
|
|
54
|
+
expect(readData.success).toBe(true)
|
|
55
|
+
|
|
56
|
+
const updateRes = await client.api.todos[':id'].$put(
|
|
57
|
+
{
|
|
58
|
+
param: { id: String(created.data.id) },
|
|
59
|
+
json: { status: 'completed' },
|
|
60
|
+
},
|
|
61
|
+
{ headers: authHeaders }
|
|
62
|
+
)
|
|
63
|
+
const updated = await updateRes.json()
|
|
64
|
+
expect(updated.success).toBe(true)
|
|
65
|
+
if (updated.success && 'data' in updated) {
|
|
66
|
+
expect(updated.data.status).toBe('completed')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const deleteRes = await client.api.todos[':id'].$delete(
|
|
70
|
+
{
|
|
71
|
+
param: { id: String(created.data.id) },
|
|
72
|
+
},
|
|
73
|
+
{ headers: authHeaders }
|
|
74
|
+
)
|
|
75
|
+
const deleted = await deleteRes.json()
|
|
76
|
+
expect(deleted.success).toBe(true)
|
|
77
|
+
|
|
78
|
+
const verifyRes = await client.api.todos[':id'].$get(
|
|
79
|
+
{
|
|
80
|
+
param: { id: String(created.data.id) },
|
|
81
|
+
},
|
|
82
|
+
{ headers: authHeaders }
|
|
83
|
+
)
|
|
84
|
+
expect(verifyRes.status).toBe(404)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('should handle concurrent requests', async () => {
|
|
89
|
+
const client = createTestClient(undefined, { headers: authHeaders })
|
|
90
|
+
|
|
91
|
+
const promises = Array.from({ length: 10 }, (_, i) =>
|
|
92
|
+
client.api.todos.$post(
|
|
93
|
+
{
|
|
94
|
+
json: { title: `Concurrent Todo ${i}` },
|
|
95
|
+
},
|
|
96
|
+
{ headers: authHeaders }
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
const results = await Promise.all(promises)
|
|
101
|
+
results.forEach((res: { status: number }) => {
|
|
102
|
+
expect(res.status).toBe(201)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const listRes = await client.api.todos.$get({ headers: authHeaders })
|
|
106
|
+
const listData = await listRes.json()
|
|
107
|
+
if (listData.success && 'data' in listData) {
|
|
108
|
+
expect(listData.data).toHaveLength(10)
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
describe('Edge Cases', () => {
|
|
114
|
+
it('should return 404 for non-existent todo', async () => {
|
|
115
|
+
const client = createTestClient(undefined, { headers: authHeaders })
|
|
116
|
+
|
|
117
|
+
const res = await client.api.todos[':id'].$get(
|
|
118
|
+
{
|
|
119
|
+
param: { id: '99999' },
|
|
120
|
+
},
|
|
121
|
+
{ headers: authHeaders }
|
|
122
|
+
)
|
|
123
|
+
expect(res.status).toBe(404)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('should reject invalid todo data', async () => {
|
|
127
|
+
const client = createTestClient(undefined, { headers: authHeaders })
|
|
128
|
+
|
|
129
|
+
const res = await client.api.todos.$post(
|
|
130
|
+
{
|
|
131
|
+
json: { title: '' },
|
|
132
|
+
},
|
|
133
|
+
{ headers: authHeaders }
|
|
134
|
+
)
|
|
135
|
+
expect(res.status).toBe(400)
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { OpenAPIHono } from '@hono/zod-openapi'
|
|
2
|
+
|
|
3
|
+
import { HTTPException } from 'hono/http-exception'
|
|
4
|
+
import type { ContentfulStatusCode } from 'hono/utils/http-status'
|
|
5
|
+
import { ZodError } from 'zod'
|
|
6
|
+
import type { AppBindings, CreateAppOptions } from './types/bindings'
|
|
7
|
+
import { AppError } from './utils/app-error'
|
|
8
|
+
import { autoRegisterRealtime } from './core/realtime-scanner'
|
|
9
|
+
import { corsMiddleware, loggerMiddleware, errorHandlerMiddleware } from './middleware'
|
|
10
|
+
import { realtimeEnvMiddleware } from './middleware/realtime-env'
|
|
11
|
+
import { captchaMiddleware } from './middleware/captcha'
|
|
12
|
+
import { auditLogMiddleware } from './middleware/audit-log'
|
|
13
|
+
import { createModuleLoggerSync } from './utils/logger'
|
|
14
|
+
import { adminApiRoutes, clientApiRoutes } from './route-registry'
|
|
15
|
+
import { fileRoutes } from './module-file/routes/file-routes'
|
|
16
|
+
|
|
17
|
+
export { type AppBindings, type CreateAppOptions } from './types/bindings'
|
|
18
|
+
|
|
19
|
+
export function createApp<T extends AppBindings = AppBindings>(_options: CreateAppOptions = {}) {
|
|
20
|
+
const app = new OpenAPIHono<{ Bindings: T }>()
|
|
21
|
+
.use('*', errorHandlerMiddleware())
|
|
22
|
+
.use('*', loggerMiddleware())
|
|
23
|
+
.use('*', corsMiddleware())
|
|
24
|
+
.use('*', realtimeEnvMiddleware())
|
|
25
|
+
.use('/api/*', auditLogMiddleware())
|
|
26
|
+
.use(
|
|
27
|
+
'/api/admin/*',
|
|
28
|
+
captchaMiddleware({
|
|
29
|
+
maxRequests: 20,
|
|
30
|
+
windowMs: 60000,
|
|
31
|
+
})
|
|
32
|
+
)
|
|
33
|
+
.route('/', clientApiRoutes)
|
|
34
|
+
.route('/', adminApiRoutes)
|
|
35
|
+
.route('/files', fileRoutes)
|
|
36
|
+
.get('/health', async c => {
|
|
37
|
+
try {
|
|
38
|
+
const { getDb } = await import('./db')
|
|
39
|
+
await getDb()
|
|
40
|
+
return c.json({ status: 'ok', timestamp: new Date().toISOString(), db: 'connected' })
|
|
41
|
+
} catch {
|
|
42
|
+
return c.json({ status: 'ok', timestamp: new Date().toISOString(), db: 'not configured' })
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.post('/api/__test__/cleanup', async c => {
|
|
46
|
+
try {
|
|
47
|
+
const { cleanupTestDatabase } = await import('./db/test-setup')
|
|
48
|
+
await cleanupTestDatabase()
|
|
49
|
+
return c.json({ success: true as const, message: 'Database cleaned up' })
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error('Error during database cleanup:', error)
|
|
52
|
+
return c.json({ success: false as const, message: 'Failed to cleanup database' }, 500)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
autoRegisterRealtime(app as unknown as Parameters<typeof autoRegisterRealtime>[0])
|
|
57
|
+
|
|
58
|
+
// Last-resort error handler for framework-level errors (e.g. 404 Not Found).
|
|
59
|
+
// The canonical error handler is errorHandlerMiddleware (middleware/error-handler.ts).
|
|
60
|
+
app.onError((err, c) => {
|
|
61
|
+
const log = createModuleLoggerSync('api')
|
|
62
|
+
c.res.headers.set('Content-Type', 'application/json')
|
|
63
|
+
|
|
64
|
+
if (AppError.isAppError(err)) {
|
|
65
|
+
return c.json(
|
|
66
|
+
{
|
|
67
|
+
success: false as const,
|
|
68
|
+
error: err.message,
|
|
69
|
+
status: err.statusCode,
|
|
70
|
+
details: err.details,
|
|
71
|
+
},
|
|
72
|
+
err.statusCode as ContentfulStatusCode
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (err instanceof HTTPException) {
|
|
77
|
+
return c.json(
|
|
78
|
+
{ success: false as const, error: err.message, status: err.status },
|
|
79
|
+
err.status as ContentfulStatusCode
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (err instanceof ZodError) {
|
|
84
|
+
const details = err.issues.map(issue => ({
|
|
85
|
+
field: issue.path.join('.'),
|
|
86
|
+
message: issue.message,
|
|
87
|
+
}))
|
|
88
|
+
return c.json(
|
|
89
|
+
{ success: false as const, error: 'Validation failed', status: 400, details },
|
|
90
|
+
400
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
log.error({ err, path: c.req.path }, 'Unhandled error')
|
|
95
|
+
return c.json(
|
|
96
|
+
{ success: false as const, error: err.message || 'Internal server error', status: 500 },
|
|
97
|
+
500
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
return app
|
|
102
|
+
}
|
|
103
|
+
export type AdminApiType = typeof adminApiRoutes
|
|
104
|
+
export type ClientApiType = typeof clientApiRoutes
|
|
105
|
+
export type AppType = ReturnType<typeof createApp>
|