@h-ai/cli 0.1.0-alpha9 → 1.0.0-beta.2
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.en.md +229 -0
- package/README.ja.md +229 -0
- package/README.md +175 -113
- package/dist/chunk-AKV2CQZV.js +1497 -0
- package/dist/chunk-AKV2CQZV.js.map +1 -0
- package/dist/chunk-EF7WOFWZ.js +7557 -0
- package/dist/chunk-EF7WOFWZ.js.map +1 -0
- package/dist/chunk-MUHRBJSW.js +29272 -0
- package/dist/chunk-MUHRBJSW.js.map +1 -0
- package/dist/chunk-ZSDEVXZ7.js +38 -0
- package/dist/{chunk-2H7UOFLK.js.map → chunk-ZSDEVXZ7.js.map} +1 -1
- package/dist/cli-config-templates-HHFHNXBN.js +5 -0
- package/dist/cli-config-templates-HHFHNXBN.js.map +1 -0
- package/dist/cli-skill-templates-PN4FLGBC.js +5 -0
- package/dist/cli-skill-templates-PN4FLGBC.js.map +1 -0
- package/dist/index.js +4444 -554
- package/dist/index.js.map +1 -1
- package/dist/metafile-esm.json +1 -0
- package/dist/src-TEBHR5I5.js +5 -0
- package/dist/src-TEBHR5I5.js.map +1 -0
- package/package.json +35 -15
- package/templates/README.md +56 -114
- package/templates/apps/admin/messages/en-US.json +7 -0
- package/templates/apps/admin/messages/ja-JP.json +40 -0
- package/templates/apps/admin/messages/zh-CN.json +7 -0
- package/templates/apps/admin/src/routes/+layout.svelte.hbs +65 -8
- package/templates/apps/admin/src/routes/+page.svelte.hbs +35 -14
- package/templates/apps/admin/src/routes/admin/+layout.svelte.hbs +54 -22
- package/templates/apps/admin/src/routes/admin/+page.svelte.hbs +33 -24
- package/templates/apps/admin/src/routes/admin/settings/+page.svelte.hbs +16 -13
- package/templates/apps/api/.dockerignore.hbs +25 -0
- package/templates/apps/api/.gitignore.hbs +22 -0
- package/templates/apps/api/.npmrc.hbs +1 -0
- package/templates/apps/api/apps/{{projectName}}-contract/README.md.hbs +39 -0
- package/templates/apps/api/apps/{{projectName}}-contract/package.json.hbs +41 -0
- package/templates/apps/api/apps/{{projectName}}-contract/src/app-contract.ts.hbs +27 -0
- package/templates/apps/api/apps/{{projectName}}-contract/src/app-schemas.ts.hbs +28 -0
- package/templates/apps/api/apps/{{projectName}}-contract/src/index.ts.hbs +5 -0
- package/templates/apps/api/apps/{{projectName}}-contract/src/{{projectName}}-contract.ts.hbs +16 -0
- package/templates/apps/api/apps/{{projectName}}-contract/tests/contract.test.ts.hbs +18 -0
- package/templates/apps/api/apps/{{projectName}}-contract/tsconfig.json.hbs +12 -0
- package/templates/apps/api/apps/{{projectName}}-contract/tsup.config.ts.hbs +11 -0
- package/templates/apps/api/apps/{{projectName}}-contract/vitest.config.ts.hbs +9 -0
- package/templates/apps/api/apps/{{projectName}}-serv/README.md.hbs +60 -0
- package/templates/apps/api/apps/{{projectName}}-serv/config/_core.yml.hbs +17 -0
- package/templates/apps/api/apps/{{projectName}}-serv/config/_serv.yml.hbs +54 -0
- package/templates/apps/api/apps/{{projectName}}-serv/data/.gitkeep.hbs +1 -0
- package/templates/apps/api/apps/{{projectName}}-serv/package.json.hbs +66 -0
- package/templates/apps/api/apps/{{projectName}}-serv/src/app.ts.hbs +119 -0
- package/templates/apps/api/apps/{{projectName}}-serv/src/build-metadata.ts.hbs +7 -0
- package/templates/apps/api/apps/{{projectName}}-serv/src/index.ts.hbs +41 -0
- package/templates/apps/api/apps/{{projectName}}-serv/src/lib/server/init.ts.hbs +165 -0
- package/templates/apps/api/apps/{{projectName}}-serv/src/server/procedures/app-procedures.ts.hbs +57 -0
- package/templates/apps/api/apps/{{projectName}}-serv/src/server/procedures/index.ts.hbs +41 -0
- package/templates/apps/api/apps/{{projectName}}-serv/tests/service.test.ts.hbs +176 -0
- package/templates/apps/api/apps/{{projectName}}-serv/tsconfig.json.hbs +16 -0
- package/templates/apps/api/apps/{{projectName}}-serv/tsup.config.ts.hbs +20 -0
- package/templates/apps/api/apps/{{projectName}}-serv/vitest.config.ts.hbs +12 -0
- package/templates/apps/api/e2e/api-serv.spec.ts.hbs +113 -0
- package/templates/apps/api/e2e/capture-evidence.ts.hbs +23 -0
- package/templates/apps/api/eslint.config.js.hbs +30 -0
- package/templates/apps/api/hai.json.hbs +4 -0
- package/templates/apps/api/images/serv.Dockerfile.hbs +37 -0
- package/templates/apps/api/package.json.hbs +53 -0
- package/templates/apps/api/playwright.config.ts.hbs +67 -0
- package/templates/apps/api/pnpm-workspace.yaml.hbs +40 -0
- package/templates/apps/api/tsconfig.base.json +14 -0
- package/templates/apps/fullstack/.dockerignore.hbs +25 -0
- package/templates/apps/fullstack/.gitignore.hbs +38 -0
- package/templates/apps/fullstack/.npmrc.hbs +1 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/.env.example.hbs +10 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/README.md.hbs +67 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/capacitor.config.ts.hbs +20 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/eslint.config.js.hbs +20 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/index.html.hbs +22 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/messages/en-US.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/messages/ja-JP.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/messages/zh-CN.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/package.json.hbs +86 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/project.inlang/settings.json.hbs +17 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/public/runtime-config.js.hbs +4 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/src/App.svelte.hbs +59 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/src/app.css.hbs +20 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/src/app.d.ts.hbs +8 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/src/build-metadata.ts.hbs +9 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/src/lib/capacitor.ts.hbs +19 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/src/main.ts.hbs +21 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/svelte.config.js.hbs +16 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/tsconfig.json.hbs +23 -0
- package/templates/apps/fullstack/apps/{{projectName}}-app/vite.config.ts.hbs +74 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/.env.example.hbs +6 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/README.md.hbs +64 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/eslint.config.js.hbs +20 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/index.html.hbs +20 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/messages/en-US.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/messages/ja-JP.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/messages/zh-CN.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/package.json.hbs +66 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/project.inlang/settings.json.hbs +17 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/App.svelte.hbs +25 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/app.css.hbs +18 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/app.d.ts.hbs +8 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/build-metadata.ts.hbs +9 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src/main.ts.hbs +20 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/Cargo.toml.hbs +33 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/build.rs.hbs +6 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/capabilities/default.json.hbs +16 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/128x128.png +0 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/128x128@2x.png +0 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/32x32.png +0 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/icon.icns +0 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/icons/icon.ico +0 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/src/lib.rs.hbs +91 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/src/main.rs.hbs +8 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/src-tauri/tauri.conf.json.hbs +46 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/svelte.config.js.hbs +14 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/tsconfig.json.hbs +22 -0
- package/templates/apps/fullstack/apps/{{projectName}}-desktop/vite.config.ts.hbs +89 -0
- package/templates/apps/fullstack/apps/{{projectName}}-miniapp/README.md.hbs +25 -0
- package/templates/apps/fullstack/apps/{{projectName}}-miniapp/messages/en-US.json.hbs +12 -0
- package/templates/apps/fullstack/apps/{{projectName}}-miniapp/messages/ja-JP.json.hbs +12 -0
- package/templates/apps/fullstack/apps/{{projectName}}-miniapp/messages/zh-CN.json.hbs +12 -0
- package/templates/apps/fullstack/apps/{{projectName}}-miniapp/project.inlang/settings.json.hbs +17 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/README.md.hbs +54 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/eslint.config.js.hbs +20 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/index.html.hbs +21 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/messages/en-US.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/messages/ja-JP.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/messages/zh-CN.json.hbs +7 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/package.json.hbs +53 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/project.inlang/settings.json.hbs +17 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/public/runtime-config.js.hbs +1 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/src/App.svelte.hbs +18 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/src/app.css.hbs +18 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/src/app.d.ts.hbs +8 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/src/build-metadata.ts.hbs +9 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/src/main.ts.hbs +14 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/svelte.config.js.hbs +16 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/tsconfig.json.hbs +23 -0
- package/templates/apps/fullstack/apps/{{projectName}}-web/vite.config.ts.hbs +76 -0
- package/templates/apps/fullstack/docs/security-configuration.md.hbs +349 -0
- package/templates/apps/fullstack/e2e/fullstack.spec.ts.hbs +988 -0
- package/templates/apps/fullstack/e2e/session-close.spec.ts.hbs +119 -0
- package/templates/apps/fullstack/eslint.config.js.hbs +41 -0
- package/templates/apps/fullstack/hai.json.hbs +11 -0
- package/templates/apps/fullstack/images/serv.Dockerfile.hbs +38 -0
- package/templates/apps/fullstack/images/web/19-runtime-config.envsh.hbs +5 -0
- package/templates/apps/fullstack/images/web/nginx.conf.hbs +24 -0
- package/templates/apps/fullstack/images/web/runtime-config.js.template.hbs +3 -0
- package/templates/apps/fullstack/images/web.Dockerfile.hbs +37 -0
- package/templates/apps/fullstack/package.json.hbs +61 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/README.md.hbs +40 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/package.json.hbs +30 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/src/admin-contract.ts.hbs +78 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/src/admin-schemas.ts.hbs +134 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/src/app-contract.ts.hbs +20 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/src/app-schemas.ts.hbs +35 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/src/index.ts.hbs +7 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/src/{{projectName}}-contract.ts.hbs +23 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/tests/contract.test.ts.hbs +31 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/tsconfig.json.hbs +9 -0
- package/templates/apps/fullstack/packages/{{projectName}}-contract/tsup.config.ts.hbs +9 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/README.md.hbs +84 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_ai.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_audit.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_cache.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_core.yml.hbs +22 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_db.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_feedback.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_iam.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_payment.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_reach.yml.hbs +60 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_scheduler.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_serv.yml.hbs +64 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_storage.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/config/_vecdb.yml.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/data/.gitkeep.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/package.json.hbs +62 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/app-server.ts.hbs +115 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/build-metadata.ts.hbs +7 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/index.ts.hbs +40 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/admin-service.ts.hbs +294 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/audit-jobs.ts.hbs +28 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/business-settings.ts.hbs +50 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/messages.ts.hbs +50 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/procedures/admin-procedures.ts.hbs +106 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/procedures/app-procedures.ts.hbs +49 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/procedures/index.ts.hbs +34 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/runtime.ts.hbs +159 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/src/server/security-roles.ts.hbs +73 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/tests/app-server.test.ts.hbs +505 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/tests/runtime.test.ts.hbs +72 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/tests/security.test.ts.hbs +183 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/tsconfig.json.hbs +10 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/tsup.config.ts.hbs +18 -0
- package/templates/apps/fullstack/packages/{{projectName}}-serv/vitest.config.ts.hbs +12 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/.gitignore.hbs +10 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/README.md.hbs +97 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/messages/en-US.json.hbs +164 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/messages/ja-JP.json.hbs +164 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/messages/zh-CN.json.hbs +164 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/package.json.hbs +55 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/project.inlang/settings.json.hbs +11 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/index.ts.hbs +7 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/api-client.ts.hbs +94 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/feedback-client.ts.hbs +36 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/sensitive-actions.svelte.ts.hbs +16 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/api/session-recovery.svelte.ts.hbs +4 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/components/AdminWorkspace.svelte.hbs +122 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/components/AppShell.svelte.hbs +90 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/components/FeedbackEntry.svelte.hbs +86 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/audit.svelte.hbs +94 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/configuration.svelte.hbs +25 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/feedback.svelte.hbs +157 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/roles.svelte.hbs +77 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/settings.svelte.hbs +44 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/pages/users.svelte.hbs +216 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/security/role-label.ts.hbs +12 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/stores/guide-store.ts.hbs +55 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/stores/management-store.svelte.ts.hbs +614 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/src/lib/stores/theme-store.svelte.ts.hbs +23 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/svelte.config.js.hbs +1 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/tests/api-client.test.ts.hbs +150 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/tests/management-store.test.ts.hbs +253 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/tsconfig.json.hbs +17 -0
- package/templates/apps/fullstack/packages/{{projectName}}-shared/vitest.config.ts.hbs +7 -0
- package/templates/apps/fullstack/playwright.config.ts.hbs +114 -0
- package/templates/apps/fullstack/playwright.session-close.config.ts.hbs +18 -0
- package/templates/apps/fullstack/pnpm-workspace.yaml.hbs +38 -0
- package/templates/apps/fullstack/tsconfig.base.json +14 -0
- package/templates/apps/h5/messages/en-US.json +3 -0
- package/templates/apps/h5/messages/ja-JP.json +40 -0
- package/templates/apps/h5/messages/zh-CN.json +3 -0
- package/templates/apps/h5/src/routes/+layout.svelte.hbs +85 -30
- package/templates/apps/h5/src/routes/+page.svelte.hbs +20 -8
- package/templates/apps/h5/src/routes/discover/+page.svelte.hbs +17 -6
- package/templates/apps/h5/src/routes/profile/+page.svelte.hbs +17 -6
- package/templates/apps/mobile-app/.env.hbs +3 -0
- package/templates/apps/{android-app → mobile-app}/capacitor.config.ts.hbs +2 -2
- package/templates/apps/mobile-app/index.html.hbs +14 -0
- package/templates/apps/mobile-app/messages/en-US.json +36 -0
- package/templates/apps/mobile-app/messages/ja-JP.json +36 -0
- package/templates/apps/mobile-app/messages/zh-CN.json +36 -0
- package/templates/apps/mobile-app/public/runtime-config.js +1 -0
- package/templates/apps/mobile-app/src/App.svelte.hbs +153 -0
- package/templates/apps/mobile-app/src/lib/api.ts.hbs +213 -0
- package/templates/apps/mobile-app/src/lib/app-config.ts.hbs +14 -0
- package/templates/apps/{android-app → mobile-app}/src/lib/capacitor.ts +6 -7
- package/templates/apps/mobile-app/src/lib/pages/home.svelte.hbs +58 -0
- package/templates/apps/mobile-app/src/lib/pages/profile.svelte.hbs +13 -0
- package/templates/apps/mobile-app/src/lib/pages/tasks.svelte.hbs +16 -0
- package/templates/apps/mobile-app/src/main.ts.hbs +11 -0
- package/templates/apps/website/messages/en-US.json +4 -2
- package/templates/apps/website/messages/ja-JP.json +34 -0
- package/templates/apps/website/messages/zh-CN.json +4 -2
- package/templates/apps/website/scripts/static-website.mjs.hbs +67 -0
- package/templates/apps/website/src/routes/+layout.svelte.hbs +77 -26
- package/templates/apps/website/src/routes/+layout.ts +3 -0
- package/templates/apps/website/src/routes/+page.svelte.hbs +31 -12
- package/templates/apps/website/src/routes/about/+page.svelte.hbs +11 -6
- package/templates/apps/website/src/routes/api/health/+server.ts +3 -0
- package/templates/apps/website/src/routes/contact/+page.svelte.hbs +44 -34
- package/templates/apps/website/src/routes/services/+page.svelte.hbs +27 -40
- package/templates/base/.dockerignore.hbs +27 -0
- package/templates/base/.gitignore.hbs +41 -0
- package/templates/base/.npmrc.hbs +1 -0
- package/templates/base/e2e/app.spec.ts.hbs +213 -0
- package/templates/base/e2e/helpers.ts +1 -1
- package/templates/base/eslint-rules.js +45 -0
- package/templates/base/eslint.config.js.hbs +34 -0
- package/templates/base/hai.json.hbs +4 -0
- package/templates/base/images/web/nginx.conf.hbs +24 -0
- package/templates/base/images/web.Dockerfile.hbs +72 -0
- package/templates/base/package.json.hbs +125 -49
- package/templates/base/playwright.config.ts +44 -6
- package/templates/base/pnpm-workspace.yaml.hbs +40 -0
- package/templates/base/src/app.css.hbs +40 -0
- package/templates/base/src/app.d.ts.hbs +14 -1
- package/templates/base/src/app.html.hbs +13 -0
- package/templates/base/src/hooks.server.ts.hbs +115 -43
- package/templates/base/src/lib/build-metadata.ts.hbs +7 -0
- package/templates/base/src/lib/server/init.ts.hbs +125 -152
- package/templates/base/src/lib/server/kit-config.ts.hbs +40 -0
- package/templates/base/src/routes/+layout.server.ts.hbs +35 -0
- package/templates/base/static/favicon.png +0 -0
- package/templates/base/svelte.config.js.hbs +84 -5
- package/templates/base/tests/scaffold.test.ts.hbs +102 -0
- package/templates/base/tsconfig.json.hbs +50 -0
- package/templates/base/vite.config.ts.hbs +117 -12
- package/templates/base/vitest.config.ts.hbs +19 -0
- package/templates/features/ai/routes/api/chat/+server.ts +6 -7
- package/templates/features/iam/routes-admin/(auth)/+layout.svelte.hbs +3 -17
- package/templates/features/iam/routes-admin/(auth)/auth/forgot-password/+page.svelte.hbs +10 -0
- package/templates/features/iam/routes-admin/(auth)/auth/login/+page.svelte.hbs +9 -96
- package/templates/features/iam/routes-admin/(auth)/auth/register/+page.svelte.hbs +9 -122
- package/templates/features/iam/routes-admin/(auth)/auth/reset-password/+page.svelte.hbs +10 -0
- package/templates/features/iam/routes-h5/auth/forgot-password/+page.svelte.hbs +10 -0
- package/templates/features/iam/routes-h5/auth/login/+page.svelte.hbs +9 -96
- package/templates/features/iam/routes-h5/auth/register/+page.svelte.hbs +9 -112
- package/templates/features/iam/routes-h5/auth/reset-password/+page.svelte.hbs +10 -0
- package/templates/features/iam/routes-shared/api/auth/captcha/+server.ts.hbs +4 -0
- package/templates/features/iam/routes-shared/api/auth/config/+server.ts +4 -0
- package/templates/features/iam/routes-shared/api/auth/login/+server.ts +1 -29
- package/templates/features/iam/routes-shared/api/auth/login/ldap/+server.ts +4 -0
- package/templates/features/iam/routes-shared/api/auth/login/otp/+server.ts +4 -0
- package/templates/features/iam/routes-shared/api/auth/logout/+server.ts +13 -6
- package/templates/features/iam/routes-shared/api/auth/otp/send/+server.ts +4 -0
- package/templates/features/iam/routes-shared/api/auth/password/renew/+server.ts +5 -0
- package/templates/features/iam/routes-shared/api/auth/password-reset/confirm/+server.ts +4 -0
- package/templates/features/iam/routes-shared/api/auth/password-reset/request/+server.ts +4 -0
- package/templates/features/iam/routes-shared/api/auth/reauthenticate/+server.ts +5 -0
- package/templates/features/iam/routes-shared/api/auth/register/+server.ts +1 -23
- package/templates/features/iam/routes-shared/api/auth/session/close/+server.ts.hbs +4 -0
- package/templates/features/iam/routes-website/auth/forgot-password/+page.svelte.hbs +10 -0
- package/templates/features/iam/routes-website/auth/login/+page.svelte.hbs +11 -0
- package/templates/features/iam/routes-website/auth/register/+page.svelte.hbs +11 -0
- package/templates/features/iam/routes-website/auth/reset-password/+page.svelte.hbs +10 -0
- package/templates/features/payment/routes/api/v1/payment/create/+server.ts +25 -23
- package/templates/features/payment/routes/api/v1/payment/notify/[provider]/+server.ts +5 -2
- package/templates/features/storage/routes/api/upload/+server.ts +10 -8
- package/templates/i18n/project.inlang/settings.json +2 -2
- package/templates/shared/.gitattributes +11 -0
- package/templates/shared/build-metadata.ts +42 -0
- package/templates/shared/container-runtime-config.sh +30 -0
- package/templates/shared/e2e-env.ts +98 -0
- package/templates/shared/hash-router.svelte.ts +83 -0
- package/templates/shared/public-base-path.mjs +19 -0
- package/templates/shared/run-e2e.mjs +104 -0
- package/templates/shared/vite-runtime-config.ts +56 -0
- package/templates/skills/AGENTS.md +75 -16
- package/templates/skills/CLAUDE.md +0 -11
- package/templates/skills/bridges/admin/AGENTS.md +89 -0
- package/templates/skills/bridges/api/AGENTS.md +83 -0
- package/templates/skills/bridges/fullstack/AGENTS.md.hbs +102 -0
- package/templates/skills/bridges/h5/AGENTS.md +88 -0
- package/templates/skills/bridges/mobile-app/AGENTS.md +100 -0
- package/templates/skills/bridges/website/AGENTS.md +88 -0
- package/templates/skills/copilot-instructions.md +3 -59
- package/templates/skills/hai-ai/SKILL.md +44 -715
- package/templates/skills/hai-ai/guide.md +457 -0
- package/templates/skills/hai-ai/reference.md +292 -0
- package/templates/skills/hai-api-client/SKILL.md +26 -339
- package/templates/skills/hai-api-client/reference.md +180 -0
- package/templates/skills/hai-api-contract/SKILL.md +36 -0
- package/templates/skills/hai-api-contract/reference.md +280 -0
- package/templates/skills/hai-app-create/SKILL.md +38 -351
- package/templates/skills/hai-app-create/collaboration.md +52 -0
- package/templates/skills/hai-app-create/development.md +243 -0
- package/templates/skills/hai-app-create/reference.md +376 -0
- package/templates/skills/hai-app-review/SKILL.md +57 -126
- package/templates/skills/hai-app-review/differential.md +34 -0
- package/templates/skills/hai-app-tests/SKILL.md +34 -454
- package/templates/skills/hai-app-tests/reference.md +462 -0
- package/templates/skills/hai-app-tests/validation.md +42 -0
- package/templates/skills/hai-audit/SKILL.md +37 -122
- package/templates/skills/hai-audit/reference.md +184 -0
- package/templates/skills/hai-build/SKILL.md +62 -315
- package/templates/skills/hai-build/paths.md +30 -0
- package/templates/skills/hai-build/reference.md +353 -0
- package/templates/skills/hai-cache/SKILL.md +26 -175
- package/templates/skills/hai-cache/reference.md +229 -0
- package/templates/skills/hai-capacitor/SKILL.md +24 -364
- package/templates/skills/hai-capacitor/reference.md +358 -0
- package/templates/skills/hai-change-plan/SKILL.md +46 -0
- package/templates/skills/hai-ci/SKILL.md +114 -0
- package/templates/skills/hai-core/SKILL.md +31 -469
- package/templates/skills/hai-core/reference.md +557 -0
- package/templates/skills/hai-core/request-access.md +65 -0
- package/templates/skills/hai-crypto/SKILL.md +29 -180
- package/templates/skills/hai-crypto/reference.md +317 -0
- package/templates/skills/hai-datapipe/SKILL.md +24 -207
- package/templates/skills/hai-datapipe/reference.md +204 -0
- package/templates/skills/hai-deploy/SKILL.md +53 -178
- package/templates/skills/hai-deploy/credentials.md +19 -0
- package/templates/skills/hai-deploy/middleware.md +129 -0
- package/templates/skills/hai-feedback/SKILL.md +85 -0
- package/templates/skills/hai-framework-sync/SKILL.md +105 -0
- package/templates/skills/hai-framework-sync/sync.md +49 -0
- package/templates/skills/hai-iam/SKILL.md +53 -325
- package/templates/skills/hai-iam/reference.md +535 -0
- package/templates/skills/hai-kit/SKILL.md +33 -329
- package/templates/skills/hai-kit/reference.md +202 -0
- package/templates/skills/hai-payment/SKILL.md +28 -262
- package/templates/skills/hai-payment/reference.md +295 -0
- package/templates/skills/hai-pr-review/SKILL.md +41 -0
- package/templates/skills/hai-reach/SKILL.md +28 -300
- package/templates/skills/hai-reach/reference.md +363 -0
- package/templates/skills/hai-reldb/SKILL.md +28 -449
- package/templates/skills/hai-reldb/reference.md +500 -0
- package/templates/skills/hai-scheduler/SKILL.md +26 -174
- package/templates/skills/hai-scheduler/reference.md +216 -0
- package/templates/skills/hai-serv/SKILL.md +60 -0
- package/templates/skills/hai-serv/reference.md +792 -0
- package/templates/skills/hai-spec-implement/SKILL.md +50 -0
- package/templates/skills/hai-spec-implement/changes.md +67 -0
- package/templates/skills/hai-spec-implement/evaluation.md +18 -0
- package/templates/skills/hai-spec-implement/handoff.md +47 -0
- package/templates/skills/hai-spec-implement/templates.md +117 -0
- package/templates/skills/hai-spec-implement/workflow.md +56 -0
- package/templates/skills/hai-spec-review/SKILL.md +57 -0
- package/templates/skills/hai-spec-review/checklist.md +71 -0
- package/templates/skills/hai-storage/SKILL.md +31 -262
- package/templates/skills/hai-storage/reference.md +284 -0
- package/templates/skills/hai-ui/SKILL.md +62 -238
- package/templates/skills/hai-ui/guide.md +81 -0
- package/templates/skills/hai-ui/reference.md +705 -0
- package/templates/skills/hai-ui-design/SKILL.md +31 -0
- package/templates/skills/hai-ui-design/patterns.md +31 -0
- package/templates/skills/hai-ui-review/SKILL.md +32 -0
- package/templates/skills/hai-ui-review/checklist.md +29 -0
- package/templates/skills/hai-vecdb/SKILL.md +25 -267
- package/templates/skills/hai-vecdb/reference.md +325 -0
- package/templates/skills/opencode.json +0 -5
- package/dist/chunk-2H7UOFLK.js +0 -10
- package/dist/chunk-LANIDJC7.js +0 -659
- package/dist/chunk-LANIDJC7.js.map +0 -1
- package/dist/chunk-YV7WPUI6.js +0 -206
- package/dist/chunk-YV7WPUI6.js.map +0 -1
- package/dist/config-templates-S5RI2MC6.js +0 -5
- package/dist/config-templates-S5RI2MC6.js.map +0 -1
- package/dist/skill-templates-N5DU5FNX.js +0 -5
- package/dist/skill-templates-N5DU5FNX.js.map +0 -1
- package/dist/src-XJ6YXNAF.js +0 -15030
- package/dist/src-XJ6YXNAF.js.map +0 -1
- package/templates/apps/android-app/.env.hbs +0 -3
- package/templates/apps/android-app/messages/en-US.json +0 -24
- package/templates/apps/android-app/messages/zh-CN.json +0 -24
- package/templates/apps/android-app/src/lib/api.ts.hbs +0 -30
- package/templates/apps/android-app/src/routes/+layout.svelte.hbs +0 -42
- package/templates/apps/android-app/src/routes/+layout.ts +0 -7
- package/templates/apps/android-app/src/routes/+page.svelte.hbs +0 -27
- package/templates/apps/api/src/routes/+layout.svelte +0 -14
- package/templates/apps/api/src/routes/+page.svelte +0 -11
- package/templates/apps/api/src/routes/api/v1/health/+server.ts +0 -14
- package/templates/apps/api/src/routes/api/v1/items/+server.ts +0 -37
- package/templates/apps/api/src/routes/api/v1/items/[id]/+server.ts +0 -30
- package/templates/base/src/app.css +0 -2
- package/templates/base/tsconfig.json +0 -8
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import type { CoreConfig, HaiResult } from '@h-ai/core'
|
|
2
|
+
import type { TransportClient } from '@h-ai/crypto'
|
|
3
|
+
import type { AdminUser } from '{{fullstack.contractPackageName}}'
|
|
4
|
+
import { Buffer } from 'node:buffer'
|
|
5
|
+
import { mkdtemp, rm } from 'node:fs/promises'
|
|
6
|
+
import os from 'node:os'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
import { audit } from '@h-ai/audit'
|
|
9
|
+
import { cache } from '@h-ai/cache'
|
|
10
|
+
import { core, err, HaiCommonError } from '@h-ai/core'
|
|
11
|
+
import { crypto } from '@h-ai/crypto'
|
|
12
|
+
import { iam } from '@h-ai/iam'
|
|
13
|
+
import { ServConfigSchema } from '@h-ai/serv'
|
|
14
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
15
|
+
import { createServerApp } from '../src/app-server.js'
|
|
16
|
+
import { closeModules, initializeModules } from '../src/server/runtime.js'
|
|
17
|
+
|
|
18
|
+
const PREFIX = '/api/v1'
|
|
19
|
+
const TEST_PASSWORD = 'TemplateTest123!'
|
|
20
|
+
const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aSxkAAAAASUVORK5CYII='
|
|
21
|
+
let app: ReturnType<typeof createServerApp>
|
|
22
|
+
let transport: TransportClient
|
|
23
|
+
let storageRoot: string
|
|
24
|
+
let cookie = ''
|
|
25
|
+
let adminToken = ''
|
|
26
|
+
let adminId = ''
|
|
27
|
+
let userToken = ''
|
|
28
|
+
let user: AdminUser
|
|
29
|
+
let encryptedRequests = 0
|
|
30
|
+
let encryptedResponses = 0
|
|
31
|
+
interface LoginData { user: { id: string }, tokens: { accessToken: string, refreshToken?: string }, roles: string[] }
|
|
32
|
+
|
|
33
|
+
/** 使用真实加密协议与 HTTP 服务,同时保留浏览器 refresh cookie。 */
|
|
34
|
+
async function call<T>(route: string, input?: object, token?: string, method = 'POST'): Promise<HaiResult<T>> {
|
|
35
|
+
const response = await transport.encryptedFetch(`http://localhost${PREFIX}${route}`, {
|
|
36
|
+
method,
|
|
37
|
+
headers: { 'content-type': 'application/json', ...(token ? { authorization: `Bearer ${token}` } : {}) },
|
|
38
|
+
...(input ? { body: JSON.stringify(input) } : {}),
|
|
39
|
+
})
|
|
40
|
+
return response.json() as Promise<HaiResult<T>>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
beforeAll(async () => {
|
|
44
|
+
storageRoot = await mkdtemp(path.join(os.tmpdir(), '{{projectName}}-avatars-'))
|
|
45
|
+
vi.stubEnv('HAI_DB_DATABASE', '":memory:"')
|
|
46
|
+
vi.stubEnv('HAI_STORAGE_ROOT', storageRoot)
|
|
47
|
+
vi.stubEnv('HAI_ADMIN_DEFAULT_PASSWORD', TEST_PASSWORD)
|
|
48
|
+
core.init({ configDir: './config' })
|
|
49
|
+
await initializeModules()
|
|
50
|
+
const key = crypto.asymmetric.generateKeyPair()
|
|
51
|
+
if (!key.success)
|
|
52
|
+
throw new Error(key.error.message)
|
|
53
|
+
vi.stubEnv('HAI_CRYPTO_TRANSPORT_SERVERKEYRING', JSON.stringify({ activeKeyId: 'test-v1', keys: { 'test-v1': key.data } }))
|
|
54
|
+
app = createServerApp()
|
|
55
|
+
transport = crypto.transport.createClient({
|
|
56
|
+
keyExchangeUrl: `http://localhost${PREFIX}/_hai/key-exchange`,
|
|
57
|
+
fetch: async (input, init) => {
|
|
58
|
+
const request = new Request(input, init)
|
|
59
|
+
if (cookie && request.url.endsWith('/auth/refresh'))
|
|
60
|
+
request.headers.set('cookie', cookie)
|
|
61
|
+
if (request.headers.get('x-encrypted') === 'true')
|
|
62
|
+
encryptedRequests++
|
|
63
|
+
const response = await app.fetch(request)
|
|
64
|
+
if (response.headers.get('x-encrypted') === 'true') {
|
|
65
|
+
encryptedResponses++
|
|
66
|
+
const wire = await response.clone().text()
|
|
67
|
+
expect(wire).not.toContain(TEST_PASSWORD)
|
|
68
|
+
expect(wire).not.toContain('"username"')
|
|
69
|
+
}
|
|
70
|
+
const nextCookie = response.headers.get('set-cookie')
|
|
71
|
+
if (nextCookie)
|
|
72
|
+
cookie = nextCookie.split(';')[0] ?? ''
|
|
73
|
+
return response
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
}, 30_000)
|
|
77
|
+
|
|
78
|
+
afterAll(async () => {
|
|
79
|
+
transport?.destroy()
|
|
80
|
+
await closeModules()
|
|
81
|
+
vi.unstubAllEnvs()
|
|
82
|
+
await rm(storageRoot, { recursive: true, force: true })
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('{{fullstack.servPackageName}} mini administration', () => {
|
|
86
|
+
it('reports disabled management transport instead of silently ignoring the configuration', () => {
|
|
87
|
+
const configured = ServConfigSchema.parse(core.config.getOrThrow('serv'))
|
|
88
|
+
const parse = vi.spyOn(ServConfigSchema, 'parse').mockReturnValueOnce({ ...configured, transport: false })
|
|
89
|
+
try {
|
|
90
|
+
expect(() => createServerApp()).toThrow(/Fullstack management requires transport encryption/)
|
|
91
|
+
}
|
|
92
|
+
finally { parse.mockRestore() }
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('keeps health public, requires encryption and reads runtime identity from core', async () => {
|
|
96
|
+
expect((await app.request('/health')).status).toBe(200)
|
|
97
|
+
expect((await app.request(`${PREFIX}/app/info`, { method: 'POST' })).status).toBe(400)
|
|
98
|
+
const result = await call<{ name: string, version: string, env: string, defaultLocale: string }>('/app/info')
|
|
99
|
+
expect(result.success).toBe(true)
|
|
100
|
+
if (!result.success)
|
|
101
|
+
return
|
|
102
|
+
const config = core.config.getOrThrow<CoreConfig>('core')
|
|
103
|
+
expect(result.data).toMatchObject({ name: config.name, version: config.version, env: config.env, defaultLocale: config.defaultLocale })
|
|
104
|
+
const invalid = await transport.encryptedFetch(`http://localhost${PREFIX}/app/echo`, {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
headers: { 'content-type': 'application/json' },
|
|
107
|
+
body: JSON.stringify({ message: '' }),
|
|
108
|
+
})
|
|
109
|
+
expect(invalid.status).toBe(400)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('logs in and refreshes with a browser cookie without exposing its refresh token', async () => {
|
|
113
|
+
const result = await call<LoginData>('/auth/login', { identifier: 'admin', password: TEST_PASSWORD })
|
|
114
|
+
expect(result.success).toBe(true)
|
|
115
|
+
if (!result.success)
|
|
116
|
+
return
|
|
117
|
+
adminToken = result.data.tokens.accessToken
|
|
118
|
+
adminId = result.data.user.id
|
|
119
|
+
expect(result.data.roles).toEqual(['admin'])
|
|
120
|
+
expect(result.data.tokens.refreshToken).toBeUndefined()
|
|
121
|
+
expect(cookie).toContain('hai_refresh_token=')
|
|
122
|
+
const refreshed = await call<{ tokens: { accessToken: string, refreshToken?: string } }>('/auth/refresh', {})
|
|
123
|
+
expect(refreshed.success).toBe(true)
|
|
124
|
+
if (refreshed.success) {
|
|
125
|
+
expect(refreshed.data.tokens.refreshToken).toBeUndefined()
|
|
126
|
+
adminToken = refreshed.data.tokens.accessToken
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('mounts public auth routes while keeping default IAM administration routes private', async () => {
|
|
131
|
+
const config = await transport.encryptedFetch(`http://localhost${PREFIX}/auth/config`)
|
|
132
|
+
expect(config.status).toBe(200)
|
|
133
|
+
for (const route of ['/auth/register', '/auth/login/ldap', '/auth/login/otp', '/auth/otp/send', '/auth/password-reset/request', '/auth/password-reset/confirm']) {
|
|
134
|
+
const response = await transport.encryptedFetch(`http://localhost${PREFIX}${route}`, {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
headers: { 'content-type': 'application/json' },
|
|
137
|
+
body: '{}',
|
|
138
|
+
})
|
|
139
|
+
expect(response.status).toBe(400)
|
|
140
|
+
}
|
|
141
|
+
for (const [route, method] of [
|
|
142
|
+
['/iam/users', 'GET'],
|
|
143
|
+
['/iam/roles', 'POST'],
|
|
144
|
+
] as const) {
|
|
145
|
+
const response = await transport.encryptedFetch(`http://localhost${PREFIX}${route}`, {
|
|
146
|
+
method,
|
|
147
|
+
headers: { 'content-type': 'application/json', 'authorization': `Bearer ${adminToken}` },
|
|
148
|
+
...(method === 'POST' ? { body: '{}' } : {}),
|
|
149
|
+
})
|
|
150
|
+
expect(response.status).toBe(404)
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('creates a normal user and enforces guards on every administration API', async () => {
|
|
155
|
+
const created = await call<AdminUser>('/admin/users/create', { username: 'normal-user', password: TEST_PASSWORD, role: 'user', accountStatus: 'active' }, adminToken)
|
|
156
|
+
expect(created.success).toBe(true)
|
|
157
|
+
if (!created.success)
|
|
158
|
+
return
|
|
159
|
+
user = created.data
|
|
160
|
+
const loggedIn = await call<LoginData>('/auth/login', { identifier: user.username, password: TEST_PASSWORD })
|
|
161
|
+
expect(loggedIn.success).toBe(true)
|
|
162
|
+
if (!loggedIn.success)
|
|
163
|
+
return
|
|
164
|
+
userToken = loggedIn.data.tokens.accessToken
|
|
165
|
+
for (const [route, input] of [
|
|
166
|
+
['/admin/users/list', { page: 1, pageSize: 20 }],
|
|
167
|
+
['/admin/users/create', { username: 'forbidden', password: TEST_PASSWORD }],
|
|
168
|
+
['/admin/users/update', { id: adminId, accountStatus: 'dormant' }],
|
|
169
|
+
['/admin/users/delete', { id: adminId }],
|
|
170
|
+
['/admin/users/avatar', { id: adminId, contentType: 'image/png', base64: PNG }],
|
|
171
|
+
['/admin/roles/list', undefined],
|
|
172
|
+
['/admin/roles/update', { id: 'missing', description: 'x' }],
|
|
173
|
+
['/admin/audit/list', { page: 1, pageSize: 20 }],
|
|
174
|
+
] as const) {
|
|
175
|
+
const denied = await call(route, input, userToken)
|
|
176
|
+
expect(denied.success).toBe(false)
|
|
177
|
+
if (!denied.success)
|
|
178
|
+
expect(denied.error.httpStatus).toBe(403)
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('allows refresh-token body transport only for an identified trusted native origin', async () => {
|
|
183
|
+
for (const [clientName, origin] of [['{{projectName}}-app', 'capacitor://localhost'], ['{{projectName}}-desktop', 'http://tauri.localhost']] as const) {
|
|
184
|
+
const headers = { 'content-type': 'application/json', 'x-request-client': clientName, 'x-hai-token-transport': 'body', origin }
|
|
185
|
+
const login = await transport.encryptedFetch(`http://localhost${PREFIX}/auth/login`, {
|
|
186
|
+
method: 'POST',
|
|
187
|
+
headers,
|
|
188
|
+
body: JSON.stringify({ identifier: 'admin', password: TEST_PASSWORD }),
|
|
189
|
+
})
|
|
190
|
+
const result = await login.json() as HaiResult<LoginData>
|
|
191
|
+
expect(result.success).toBe(true)
|
|
192
|
+
if (!result.success)
|
|
193
|
+
continue
|
|
194
|
+
expect(result.data.tokens.refreshToken).toBeTruthy()
|
|
195
|
+
expect(login.headers.get('set-cookie')).toBeNull()
|
|
196
|
+
const refresh = await transport.encryptedFetch(`http://localhost${PREFIX}/auth/refresh`, {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers,
|
|
199
|
+
body: JSON.stringify({ refreshToken: result.data.tokens.refreshToken }),
|
|
200
|
+
})
|
|
201
|
+
const refreshed = await refresh.json() as HaiResult<{ tokens: { refreshToken: string } }>
|
|
202
|
+
expect(refreshed.success).toBe(true)
|
|
203
|
+
if (refreshed.success)
|
|
204
|
+
expect(refreshed.data.tokens.refreshToken).not.toBe(result.data.tokens.refreshToken)
|
|
205
|
+
}
|
|
206
|
+
for (const [clientName, origin] of [['{{projectName}}-app', 'http://untrusted.example'], ['unrecognized-client', 'capacitor://localhost']] as const) {
|
|
207
|
+
const response = await transport.encryptedFetch(`http://localhost${PREFIX}/auth/login`, {
|
|
208
|
+
method: 'POST',
|
|
209
|
+
headers: { 'content-type': 'application/json', 'x-request-client': clientName, 'x-hai-token-transport': 'body', origin },
|
|
210
|
+
body: JSON.stringify({ identifier: 'admin', password: TEST_PASSWORD }),
|
|
211
|
+
})
|
|
212
|
+
const result = await response.json() as HaiResult<LoginData>
|
|
213
|
+
expect(result.success).toBe(true)
|
|
214
|
+
if (result.success)
|
|
215
|
+
expect(result.data.tokens.refreshToken).toBeUndefined()
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('paginates users and protects administrators from self deletion, lifecycle changes and reassignment', async () => {
|
|
220
|
+
const listed = await call<{ items: AdminUser[], total: number }>('/admin/users/list', { page: 1, pageSize: 1 }, adminToken)
|
|
221
|
+
expect(listed.success).toBe(true)
|
|
222
|
+
if (listed.success) {
|
|
223
|
+
expect(listed.data.items).toHaveLength(1)
|
|
224
|
+
expect(listed.data.total).toBe(2)
|
|
225
|
+
}
|
|
226
|
+
for (const [route, input] of [['/admin/users/delete', { id: adminId }], ['/admin/users/update', { id: adminId, accountStatus: 'dormant' }], ['/admin/users/update', { id: adminId, role: 'user' }]] as const) {
|
|
227
|
+
const denied = await call(route, input, adminToken)
|
|
228
|
+
expect(denied.success).toBe(false)
|
|
229
|
+
if (!denied.success)
|
|
230
|
+
expect(denied.error.httpStatus).toBe(403)
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('updates personal preferences, validates images and serves only allowed avatar resources', async () => {
|
|
235
|
+
expect((await call('/profile/update', { displayName: 'Updated', locale: 'en-US', theme: '{{fullstack.theme.defaultTheme}}' }, userToken)).success).toBe(true)
|
|
236
|
+
const current = await call<{ metadata: { locale: string, theme: string } }>('/auth/me', undefined, userToken, 'GET')
|
|
237
|
+
expect(current.success).toBe(true)
|
|
238
|
+
if (current.success)
|
|
239
|
+
expect(current.data.metadata).toMatchObject({ locale: 'en-US', theme: '{{fullstack.theme.defaultTheme}}' })
|
|
240
|
+
expect((await call('/profile/update', { email: 'temporary@example.com' }, userToken)).success).toBe(true)
|
|
241
|
+
const cleared = await call<AdminUser>('/profile/update', { email: '' }, userToken)
|
|
242
|
+
expect(cleared.success).toBe(true)
|
|
243
|
+
if (cleared.success)
|
|
244
|
+
expect(cleared.data.email).toBe('')
|
|
245
|
+
const invalid = await call('/profile/avatar', { contentType: 'image/png', base64: 'PHN2Zz48L3N2Zz4=' }, userToken)
|
|
246
|
+
expect(invalid.success).toBe(false)
|
|
247
|
+
if (!invalid.success)
|
|
248
|
+
expect(invalid.error.httpStatus).toBe(400)
|
|
249
|
+
const oversized = await call('/profile/avatar', { contentType: 'image/png', base64: Buffer.alloc(512 * 1024 + 1).toString('base64') }, userToken)
|
|
250
|
+
expect(oversized.success).toBe(false)
|
|
251
|
+
const anonymous = await call('/profile/avatar', { contentType: 'image/png', base64: PNG })
|
|
252
|
+
expect(anonymous.success).toBe(false)
|
|
253
|
+
if (!anonymous.success)
|
|
254
|
+
expect(anonymous.error.httpStatus).toBe(401)
|
|
255
|
+
const injected = await transport.encryptedFetch(`http://localhost${PREFIX}/profile/update`, {
|
|
256
|
+
method: 'POST',
|
|
257
|
+
headers: { 'content-type': 'application/json', 'authorization': `Bearer ${userToken}` },
|
|
258
|
+
body: JSON.stringify({ id: adminId, accountStatus: 'dormant', displayName: 'Intruder' }),
|
|
259
|
+
})
|
|
260
|
+
expect(injected.status).toBe(400)
|
|
261
|
+
const uploaded = await call<{ avatarUrl: string }>('/profile/avatar', { contentType: 'image/png', base64: PNG }, userToken)
|
|
262
|
+
expect(uploaded.success).toBe(true)
|
|
263
|
+
if (!uploaded.success)
|
|
264
|
+
return
|
|
265
|
+
expect(uploaded.data.avatarUrl).toMatch(/^\/api\/v1\/assets\/avatars\/[\w-]+\/[\w-]+\.png$/)
|
|
266
|
+
const asset = await app.request(uploaded.data.avatarUrl)
|
|
267
|
+
expect(asset.status).toBe(200)
|
|
268
|
+
expect(asset.headers.get('content-type')).toBe('image/png')
|
|
269
|
+
expect((await asset.arrayBuffer()).byteLength).toBeGreaterThan(0)
|
|
270
|
+
expect((await app.request(`${PREFIX}/assets/avatars/%2e%2e/config/_core.yml`)).status).toBe(404)
|
|
271
|
+
expect((await call('/admin/users/avatar', { id: user.id, contentType: 'image/png', base64: PNG }, adminToken)).success).toBe(true)
|
|
272
|
+
expect((await app.request(uploaded.data.avatarUrl)).status).toBe(404)
|
|
273
|
+
const hostile = await transport.encryptedFetch(`http://attacker.example${PREFIX}/profile/avatar`, {
|
|
274
|
+
method: 'POST',
|
|
275
|
+
headers: { 'content-type': 'application/json', 'authorization': `Bearer ${userToken}` },
|
|
276
|
+
body: JSON.stringify({ contentType: 'image/png', base64: PNG }),
|
|
277
|
+
})
|
|
278
|
+
const hostileResult = await hostile.json() as HaiResult<{ avatarUrl: string }>
|
|
279
|
+
expect(hostileResult.success).toBe(true)
|
|
280
|
+
if (hostileResult.success) {
|
|
281
|
+
expect(hostileResult.data.avatarUrl).toMatch(/^\/api\/v1\/assets\//)
|
|
282
|
+
expect(hostileResult.data.avatarUrl).not.toContain('attacker.example')
|
|
283
|
+
const stored = await iam.user.getUser(user.id)
|
|
284
|
+
expect(stored.success).toBe(true)
|
|
285
|
+
if (stored.success)
|
|
286
|
+
expect(stored.data?.avatarUrl).toBe(hostileResult.data.avatarUrl)
|
|
287
|
+
}
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
it('lists separate duty roles, updates descriptions and lets only the auditor query redacted records', async () => {
|
|
291
|
+
const roles = await call<{ items: { id: string, code: string, userCount: number }[] }>('/admin/roles/list', undefined, adminToken)
|
|
292
|
+
expect(roles.success).toBe(true)
|
|
293
|
+
if (roles.success) {
|
|
294
|
+
expect(roles.data.items.map(item => item.code).sort()).toEqual(['admin', 'audit_admin', 'business_operator', 'config_admin', 'user'])
|
|
295
|
+
const role = roles.data.items.find(item => item.code === 'user')!
|
|
296
|
+
expect(role.userCount).toBe(1)
|
|
297
|
+
expect((await call('/admin/roles/update', { id: role.id, description: 'Updated description' }, adminToken)).success).toBe(true)
|
|
298
|
+
}
|
|
299
|
+
const denied = await call('/admin/audit/list', { page: 1, pageSize: 100 }, adminToken)
|
|
300
|
+
expect(denied.success).toBe(false)
|
|
301
|
+
const auditor = await iam.user.createUser({ username: 'independent-auditor', password: TEST_PASSWORD })
|
|
302
|
+
const auditRole = await iam.authz.getRoleByCode('audit_admin')
|
|
303
|
+
if (!auditor.success || !auditRole.success || !auditRole.data)
|
|
304
|
+
throw new Error('Auditor fixture failed')
|
|
305
|
+
expect((await iam.authz.syncRoles(auditor.data.user.id, [auditRole.data.id])).success).toBe(true)
|
|
306
|
+
const login = await iam.auth.login({ identifier: 'independent-auditor', password: TEST_PASSWORD })
|
|
307
|
+
if (!login.success)
|
|
308
|
+
throw new Error(login.error.message)
|
|
309
|
+
const logs = await call<{ items: { action: string, details: string | null }[], total: number }>('/admin/audit/list', { page: 1, pageSize: 100 }, login.data.tokens.accessToken)
|
|
310
|
+
expect(logs.success).toBe(true)
|
|
311
|
+
if (logs.success) {
|
|
312
|
+
expect(logs.data.total).toBeGreaterThan(0)
|
|
313
|
+
expect(JSON.stringify(logs.data)).not.toContain(TEST_PASSWORD)
|
|
314
|
+
expect(JSON.stringify(logs.data)).not.toContain(PNG)
|
|
315
|
+
}
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
it('does not write profile fields when role synchronization fails', async () => {
|
|
319
|
+
const before = await iam.user.getUser(user.id)
|
|
320
|
+
expect(before.success).toBe(true)
|
|
321
|
+
const sync = vi.spyOn(iam.authz, 'syncRoles').mockResolvedValueOnce(err(HaiCommonError.API_ERROR, 'Injected role persistence failure'))
|
|
322
|
+
const failed = await call('/admin/users/update', { id: user.id, role: 'admin', email: 'changed@example.com', displayName: 'Should not change' }, adminToken)
|
|
323
|
+
sync.mockRestore()
|
|
324
|
+
expect(failed.success).toBe(false)
|
|
325
|
+
const after = await iam.user.getUser(user.id)
|
|
326
|
+
expect(after.success).toBe(true)
|
|
327
|
+
if (before.success && after.success)
|
|
328
|
+
expect(after.data).toMatchObject({ email: before.data?.email, displayName: before.data?.displayName })
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
it('keeps an already committed profile update successful when best-effort audit fails', async () => {
|
|
332
|
+
const originalLog = audit.log.bind(audit)
|
|
333
|
+
const log = vi.spyOn(audit, 'log').mockImplementation((input, tx) => input.action === 'update' && input.resource === 'profile'
|
|
334
|
+
? Promise.resolve(err(HaiCommonError.API_ERROR, 'Injected audit persistence failure'))
|
|
335
|
+
: originalLog(input, tx))
|
|
336
|
+
const logger = vi.spyOn(core.logger, 'error').mockImplementation(() => {})
|
|
337
|
+
try {
|
|
338
|
+
const result = await call<AdminUser>('/profile/update', { displayName: 'Committed profile' }, userToken)
|
|
339
|
+
expect(result.success).toBe(true)
|
|
340
|
+
if (result.success)
|
|
341
|
+
expect(result.data.displayName).toBe('Committed profile')
|
|
342
|
+
expect(logger).toHaveBeenCalledWith('Failed to record audit event', expect.objectContaining({ action: 'update', resource: 'profile' }))
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
log.mockRestore()
|
|
346
|
+
logger.mockRestore()
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it('rolls back roles when profile persistence fails and keeps role changes effective in active sessions', async () => {
|
|
351
|
+
const update = vi.spyOn(iam.user, 'updateUser').mockResolvedValueOnce(err(HaiCommonError.API_ERROR, 'Injected user persistence failure'))
|
|
352
|
+
const failed = await call('/admin/users/update', { id: user.id, role: 'admin', email: 'changed@example.com' }, adminToken)
|
|
353
|
+
update.mockRestore()
|
|
354
|
+
expect(failed.success).toBe(false)
|
|
355
|
+
const roles = await iam.authz.getUserRoles(user.id)
|
|
356
|
+
expect(roles.success).toBe(true)
|
|
357
|
+
if (roles.success)
|
|
358
|
+
expect(roles.data.map(role => role.code)).toEqual(['user'])
|
|
359
|
+
expect((await call('/admin/users/update', { id: user.id, role: 'admin' }, adminToken)).success).toBe(true)
|
|
360
|
+
expect((await call('/admin/users/list', { page: 1, pageSize: 20 }, userToken)).success).toBe(true)
|
|
361
|
+
expect((await call('/admin/users/update', { id: user.id, role: 'user' }, adminToken)).success).toBe(true)
|
|
362
|
+
const denied = await call('/admin/users/list', { page: 1, pageSize: 20 }, userToken)
|
|
363
|
+
expect(denied.success).toBe(false)
|
|
364
|
+
if (!denied.success)
|
|
365
|
+
expect(denied.error.httpStatus).toBe(403)
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
it('rejects stale administrator snapshots and reports fresh user roles', async () => {
|
|
369
|
+
const snapshot = await iam.session.get(userToken)
|
|
370
|
+
if (!snapshot.success || !snapshot.data)
|
|
371
|
+
throw new Error('Session unavailable')
|
|
372
|
+
const stale = await iam.session.update(userToken, { roles: ['admin'], permissions: ['*'] }, snapshot.data.version)
|
|
373
|
+
expect(stale.success).toBe(true)
|
|
374
|
+
for (const [route, input] of [['/admin/users/list', { page: 1, pageSize: 20 }], ['/admin/roles/list', undefined], ['/admin/audit/list', { page: 1, pageSize: 20 }]] as const) {
|
|
375
|
+
const denied = await call(route, input, userToken)
|
|
376
|
+
expect(denied.success).toBe(false)
|
|
377
|
+
if (!denied.success)
|
|
378
|
+
expect(denied.error.httpStatus).toBe(403)
|
|
379
|
+
}
|
|
380
|
+
const current = await call<{ roles: string[] }>('/auth/me', undefined, userToken, 'GET')
|
|
381
|
+
expect(current.success).toBe(true)
|
|
382
|
+
if (current.success)
|
|
383
|
+
expect(current.data.roles).toEqual(['user'])
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
it('returns a conflict when another administrator holds the mutation lock and resumes after release', async () => {
|
|
387
|
+
const locked = await cache.lock.acquire('hai:app:admin-mutation', { ttl: 10 })
|
|
388
|
+
expect(locked.success).toBe(true)
|
|
389
|
+
if (!locked.success || !locked.data)
|
|
390
|
+
throw new Error('Mutation lock unavailable')
|
|
391
|
+
const owner = locked.data
|
|
392
|
+
try {
|
|
393
|
+
const result = await call('/admin/users/update', { id: user.id, displayName: 'Locked' }, adminToken)
|
|
394
|
+
expect(result.success).toBe(false)
|
|
395
|
+
if (!result.success)
|
|
396
|
+
expect(result.error.httpStatus).toBe(409)
|
|
397
|
+
}
|
|
398
|
+
finally {
|
|
399
|
+
expect((await cache.lock.release('hai:app:admin-mutation', owner)).success).toBe(true)
|
|
400
|
+
}
|
|
401
|
+
expect((await call('/admin/users/update', { id: user.id, displayName: 'Unlocked' }, adminToken)).success).toBe(true)
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
it('keeps single-writer protection after an expired lease and resumes after a slow mutation', async () => {
|
|
405
|
+
const other = await call<AdminUser>('/admin/users/create', { username: 'lease-admin', password: TEST_PASSWORD, role: 'admin' }, adminToken)
|
|
406
|
+
expect(other.success).toBe(true)
|
|
407
|
+
if (!other.success)
|
|
408
|
+
return
|
|
409
|
+
const otherLogin = await call<LoginData>('/auth/login', { identifier: 'lease-admin', password: TEST_PASSWORD })
|
|
410
|
+
expect(otherLogin.success).toBe(true)
|
|
411
|
+
if (!otherLogin.success)
|
|
412
|
+
return
|
|
413
|
+
let resume: () => void = () => {}
|
|
414
|
+
let entered: () => void = () => {}
|
|
415
|
+
const paused = new Promise<void>((resolve) => {
|
|
416
|
+
resume = resolve
|
|
417
|
+
})
|
|
418
|
+
const entry = new Promise<void>((resolve) => {
|
|
419
|
+
entered = resolve
|
|
420
|
+
})
|
|
421
|
+
const original = iam.user.updateUser
|
|
422
|
+
const update = vi.spyOn(iam.user, 'updateUser').mockImplementationOnce(async (id, data) => {
|
|
423
|
+
entered()
|
|
424
|
+
await paused
|
|
425
|
+
return original(id, data)
|
|
426
|
+
})
|
|
427
|
+
const first = call('/admin/users/update', { id: other.data.id, accountStatus: 'dormant' }, adminToken)
|
|
428
|
+
await entry
|
|
429
|
+
const now = vi.spyOn(Date, 'now').mockReturnValue(Date.now() + 301_000)
|
|
430
|
+
try {
|
|
431
|
+
const conflicting = await call('/admin/users/update', { id: adminId, accountStatus: 'dormant' }, otherLogin.data.tokens.accessToken)
|
|
432
|
+
expect(conflicting.success).toBe(false)
|
|
433
|
+
if (!conflicting.success)
|
|
434
|
+
expect(conflicting.error.httpStatus).toBe(409)
|
|
435
|
+
resume()
|
|
436
|
+
expect((await first).success).toBe(true)
|
|
437
|
+
const admin = await iam.user.getUser(adminId)
|
|
438
|
+
expect(admin.success).toBe(true)
|
|
439
|
+
if (admin.success)
|
|
440
|
+
expect(admin.data?.accountStatus).toBe('active')
|
|
441
|
+
}
|
|
442
|
+
finally {
|
|
443
|
+
resume()
|
|
444
|
+
now.mockRestore()
|
|
445
|
+
update.mockRestore()
|
|
446
|
+
}
|
|
447
|
+
expect((await call('/admin/users/delete', { id: other.data.id }, adminToken)).success).toBe(true)
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
it('serializes mutually destructive admin requests and preserves an active administrator', async () => {
|
|
451
|
+
const created = await call<AdminUser>('/admin/users/create', { username: 'second-admin', password: TEST_PASSWORD, role: 'admin' }, adminToken)
|
|
452
|
+
expect(created.success).toBe(true)
|
|
453
|
+
if (!created.success)
|
|
454
|
+
return
|
|
455
|
+
const loggedIn = await call<LoginData>('/auth/login', { identifier: 'second-admin', password: TEST_PASSWORD })
|
|
456
|
+
expect(loggedIn.success).toBe(true)
|
|
457
|
+
if (!loggedIn.success)
|
|
458
|
+
return
|
|
459
|
+
// 对手同时请求禁用原管理员;锁内重新鉴权阻止两个请求全部成功。
|
|
460
|
+
const results = await Promise.all([
|
|
461
|
+
call('/admin/users/update', { id: created.data.id, accountStatus: 'dormant' }, adminToken),
|
|
462
|
+
call('/admin/users/update', { id: adminId, accountStatus: 'dormant' }, loggedIn.data.tokens.accessToken),
|
|
463
|
+
])
|
|
464
|
+
expect(results.filter(result => result.success)).toHaveLength(1)
|
|
465
|
+
const admins = await iam.user.listUsers({ accountStatus: 'active', include: ['roles'] })
|
|
466
|
+
expect(admins.success).toBe(true)
|
|
467
|
+
if (admins.success) {
|
|
468
|
+
const surviving = admins.data.items.filter(item => item.roles?.some(role => role.code === 'admin'))
|
|
469
|
+
expect(surviving).toHaveLength(1)
|
|
470
|
+
// 后续用仍有效的管理员会话验证其他操作。
|
|
471
|
+
if (surviving[0]?.id !== adminId) {
|
|
472
|
+
adminToken = loggedIn.data.tokens.accessToken
|
|
473
|
+
adminId = created.data.id
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
it('invalidates sessions on disable and password change and proves encrypted traffic', async () => {
|
|
479
|
+
expect((await call('/admin/users/update', { id: user.id, accountStatus: 'dormant' }, adminToken)).success).toBe(true)
|
|
480
|
+
const denied = await call('/auth/me', undefined, userToken, 'GET')
|
|
481
|
+
expect(denied.success).toBe(false)
|
|
482
|
+
if (!denied.success)
|
|
483
|
+
expect(denied.error.httpStatus).toBe(401)
|
|
484
|
+
expect((await call('/admin/users/update', { id: user.id, accountStatus: 'active' }, adminToken)).success).toBe(true)
|
|
485
|
+
const loggedIn = await call<LoginData>('/auth/login', { identifier: user.username, password: TEST_PASSWORD })
|
|
486
|
+
expect(loggedIn.success).toBe(true)
|
|
487
|
+
if (!loggedIn.success)
|
|
488
|
+
return
|
|
489
|
+
expect((await call('/auth/change-password', { oldPassword: TEST_PASSWORD, newPassword: 'ChangedTest123!' }, loggedIn.data.tokens.accessToken)).success).toBe(true)
|
|
490
|
+
expect((await call('/auth/me', undefined, loggedIn.data.tokens.accessToken, 'GET')).success).toBe(false)
|
|
491
|
+
const changedLogin = await call<LoginData>('/auth/login', { identifier: user.username, password: 'ChangedTest123!' })
|
|
492
|
+
expect(changedLogin.success).toBe(true)
|
|
493
|
+
if (changedLogin.success) {
|
|
494
|
+
expect((await call('/auth/logout', {}, changedLogin.data.tokens.accessToken)).success).toBe(true)
|
|
495
|
+
expect((await call('/auth/me', undefined, changedLogin.data.tokens.accessToken, 'GET')).success).toBe(false)
|
|
496
|
+
}
|
|
497
|
+
expect((await call('/admin/users/delete', { id: user.id }, adminToken)).success).toBe(true)
|
|
498
|
+
const removed = await iam.user.getUser(user.id)
|
|
499
|
+
expect(removed.success).toBe(true)
|
|
500
|
+
if (removed.success)
|
|
501
|
+
expect(removed.data).toBeNull()
|
|
502
|
+
expect(encryptedRequests).toBeGreaterThan(10)
|
|
503
|
+
expect(encryptedResponses).toBeGreaterThan(10)
|
|
504
|
+
})
|
|
505
|
+
})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { mkdtemp, rm } from 'node:fs/promises'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { audit } from '@h-ai/audit'
|
|
5
|
+
import { cache } from '@h-ai/cache'
|
|
6
|
+
import { core{{#if features.feedback}}, err{{/if}}, HaiConfigError } from '@h-ai/core'
|
|
7
|
+
import { crypto } from '@h-ai/crypto'
|
|
8
|
+
{{#if features.feedback}}
|
|
9
|
+
import { feedback, HaiFeedbackError } from '@h-ai/feedback'
|
|
10
|
+
{{/if}}
|
|
11
|
+
import { iam } from '@h-ai/iam'
|
|
12
|
+
import { reldb } from '@h-ai/reldb'
|
|
13
|
+
import { storage } from '@h-ai/storage'
|
|
14
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
15
|
+
import { closeModules, initializeModules } from '../src/server/runtime.js'
|
|
16
|
+
|
|
17
|
+
let storageRoot: string
|
|
18
|
+
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
storageRoot = await mkdtemp(path.join(os.tmpdir(), '{{projectName}}-bootstrap-'))
|
|
21
|
+
vi.stubEnv('HAI_DB_DATABASE', '":memory:"')
|
|
22
|
+
vi.stubEnv('HAI_STORAGE_ROOT', storageRoot)
|
|
23
|
+
vi.stubEnv('HAI_IAM_PASSWORD_REQUIREUPPERCASE', 'true')
|
|
24
|
+
core.init({ configDir: './config' })
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
afterEach(async () => {
|
|
28
|
+
await closeModules()
|
|
29
|
+
vi.unstubAllEnvs()
|
|
30
|
+
await rm(storageRoot, { recursive: true, force: true })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it.each([
|
|
34
|
+
{ password: 'abc' },
|
|
35
|
+
{ password: 'lowercase123!' },
|
|
36
|
+
])('startup explains the failed password policy and permits a clean retry: $password', async ({ password }) => {
|
|
37
|
+
vi.stubEnv('HAI_ADMIN_DEFAULT_PASSWORD', password)
|
|
38
|
+
await expect(initializeModules()).rejects.toMatchObject({ cause: { ext: { module: 'bootstrap', fields: ['HAI_ADMIN_DEFAULT_PASSWORD'] } } })
|
|
39
|
+
for (const module of [audit, iam, storage, crypto, cache, reldb])
|
|
40
|
+
expect(module.isInitialized).toBe(false)
|
|
41
|
+
|
|
42
|
+
// 失败后再次初始化,确认未保留半成品管理员或未释放的模块。
|
|
43
|
+
vi.stubEnv('HAI_ADMIN_DEFAULT_PASSWORD', 'Bootstrap-retry-Admin123!')
|
|
44
|
+
await initializeModules()
|
|
45
|
+
const users = await iam.user.listUsers({ page: 1, pageSize: 10 })
|
|
46
|
+
expect(users.success).toBe(true)
|
|
47
|
+
if (users.success) {
|
|
48
|
+
expect(users.data.total).toBe(1)
|
|
49
|
+
expect(users.data.items[0]?.username).toBe('admin')
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it.each(['', ' '])('startup identifies an unset administrator password without exposing its value', async (password) => {
|
|
54
|
+
vi.stubEnv('HAI_ADMIN_DEFAULT_PASSWORD', password)
|
|
55
|
+
await expect(initializeModules()).rejects.toMatchObject({ cause: { ext: { module: 'bootstrap', code: HaiConfigError.CONFIG_ENV_VAR_MISSING.code, fields: ['HAI_ADMIN_DEFAULT_PASSWORD'] } } })
|
|
56
|
+
for (const module of [audit, iam, storage, crypto, cache, reldb])
|
|
57
|
+
expect(module.isInitialized).toBe(false)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
{{#if features.feedback}}
|
|
61
|
+
it('optional feedback failure does not roll back authentication and business modules', async () => {
|
|
62
|
+
vi.stubEnv('HAI_ADMIN_DEFAULT_PASSWORD', 'Bootstrap-retry-Admin123!')
|
|
63
|
+
const unavailable = vi.spyOn(feedback, 'init').mockResolvedValue(err(HaiFeedbackError.CONFIG_ERROR, 'Feedback fixture unavailable'))
|
|
64
|
+
try {
|
|
65
|
+
await initializeModules()
|
|
66
|
+
expect(iam.isInitialized && reldb.isInitialized && cache.isInitialized).toBe(true)
|
|
67
|
+
expect((await iam.auth.login({ identifier: 'admin', password: 'Bootstrap-retry-Admin123!' })).success).toBe(true)
|
|
68
|
+
expect(feedback.isInitialized).toBe(false)
|
|
69
|
+
}
|
|
70
|
+
finally { unavailable.mockRestore() }
|
|
71
|
+
})
|
|
72
|
+
{{/if}}
|