@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,41 @@
|
|
|
1
|
+
import type { CoreConfig } from '@h-ai/core'
|
|
2
|
+
import type { ServConfig } from '@h-ai/serv'
|
|
3
|
+
import process from 'node:process'
|
|
4
|
+
import { core } from '@h-ai/core'
|
|
5
|
+
import { serv } from '@h-ai/serv'
|
|
6
|
+
import { {{api.serviceAppFactoryName}} } from './app.js'
|
|
7
|
+
import { closeApp, initApp } from './lib/server/init.js'
|
|
8
|
+
|
|
9
|
+
async function main(): Promise<void> {
|
|
10
|
+
await initApp()
|
|
11
|
+
const config = core.config.getOrThrow<CoreConfig>('core')
|
|
12
|
+
const logger = core.logger.child({ app: config.name, scope: 'entrypoint' })
|
|
13
|
+
|
|
14
|
+
// host/port 来自 config/_serv.yml 的 server(HOST/PORT 环境变量高于配置文件)。
|
|
15
|
+
const { server } = core.config.getOrThrow<ServConfig>('serv')
|
|
16
|
+
await new Promise<void>((resolve, reject) => {
|
|
17
|
+
const listener = serv.listen({{api.serviceAppFactoryName}}(), {
|
|
18
|
+
host: server.host,
|
|
19
|
+
port: server.port,
|
|
20
|
+
onListening: (info) => {
|
|
21
|
+
logger.info('API service listening', { address: info.address, port: info.port })
|
|
22
|
+
resolve()
|
|
23
|
+
},
|
|
24
|
+
onClose: closeApp,
|
|
25
|
+
})
|
|
26
|
+
listener.server.once('error', reject)
|
|
27
|
+
listener.server.once('listening', () => listener.server.off('error', reject))
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
main().catch(async (error: unknown) => {
|
|
32
|
+
core.logger.error('API service failed to start', { error })
|
|
33
|
+
process.exitCode = 1
|
|
34
|
+
try {
|
|
35
|
+
// 包括初始化后的 app/transport 创建失败,均须释放已建立的连接。
|
|
36
|
+
await closeApp()
|
|
37
|
+
}
|
|
38
|
+
catch (cleanupError) {
|
|
39
|
+
core.logger.error('API service startup cleanup failed', { error: cleanupError })
|
|
40
|
+
}
|
|
41
|
+
})
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/** 应用声明真实模块顺序;并发、失败回滚与关闭重试由 core 处理。 */
|
|
2
|
+
{{#if features.ai}}
|
|
3
|
+
import { ai, AIConfigSchema } from '@h-ai/ai'
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if features.audit}}
|
|
6
|
+
import { audit, AuditInitConfigSchema } from '@h-ai/audit'
|
|
7
|
+
{{/if}}
|
|
8
|
+
{{#if features.cache}}
|
|
9
|
+
import { cache, CacheConfigSchema } from '@h-ai/cache'
|
|
10
|
+
{{/if}}
|
|
11
|
+
import { core } from '@h-ai/core'
|
|
12
|
+
{{#if features.crypto}}
|
|
13
|
+
import { crypto } from '@h-ai/crypto'
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{#if features.feedback}}
|
|
16
|
+
import { feedback } from '@h-ai/feedback'
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{#if features.iam}}
|
|
19
|
+
import { iam, IamConfigSchema } from '@h-ai/iam'
|
|
20
|
+
{{/if}}
|
|
21
|
+
{{#if features.reach}}
|
|
22
|
+
import { reach, ReachConfigSchema } from '@h-ai/reach'
|
|
23
|
+
{{/if}}
|
|
24
|
+
{{#if features.db}}
|
|
25
|
+
import { reldb, ReldbConfigSchema } from '@h-ai/reldb'
|
|
26
|
+
{{/if}}
|
|
27
|
+
import { ServConfigSchema } from '@h-ai/serv'
|
|
28
|
+
{{#if features.audit}}
|
|
29
|
+
{{#if features.scheduler}}
|
|
30
|
+
import { scheduler, SchedulerConfigSchema } from '@h-ai/scheduler'
|
|
31
|
+
{{/if}}
|
|
32
|
+
{{/if}}
|
|
33
|
+
{{#if features.storage}}
|
|
34
|
+
import { storage, StorageConfigSchema } from '@h-ai/storage'
|
|
35
|
+
{{/if}}
|
|
36
|
+
{{#if features.vecdb}}
|
|
37
|
+
import { vecdb, VecdbConfigSchema } from '@h-ai/vecdb'
|
|
38
|
+
{{/if}}
|
|
39
|
+
{{#if features.feedback}}
|
|
40
|
+
import { buildMetadata } from '../../build-metadata.js'
|
|
41
|
+
{{/if}}
|
|
42
|
+
|
|
43
|
+
{{#if features.feedback}}
|
|
44
|
+
let feedbackRetry: ReturnType<typeof setTimeout> | undefined
|
|
45
|
+
let feedbackStarting: Promise<void> | undefined
|
|
46
|
+
let feedbackClosing = false
|
|
47
|
+
let feedbackFailure: string | number | undefined
|
|
48
|
+
|
|
49
|
+
/** 可选辅助能力独立重试;不能回滚已经就绪的 IAM 与业务模块。 */
|
|
50
|
+
function startFeedback(): Promise<void> {
|
|
51
|
+
if (feedbackStarting)
|
|
52
|
+
return feedbackStarting
|
|
53
|
+
feedbackClosing = false
|
|
54
|
+
feedbackStarting = (async () => {
|
|
55
|
+
try {
|
|
56
|
+
const result = await feedback.init({ ...core.config.getOrThrow<import('@h-ai/feedback').FeedbackConfigInput>('feedback'), ...buildMetadata })
|
|
57
|
+
if (!result.success) {
|
|
58
|
+
if (feedbackFailure !== result.error.code)
|
|
59
|
+
core.logger.warn('Optional feedback unavailable; business runtime remains ready', { module: 'feedback', code: result.error.code })
|
|
60
|
+
feedbackFailure = result.error.code
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
feedbackFailure = undefined
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
if (feedbackFailure !== 'configuration')
|
|
68
|
+
core.logger.warn('Optional feedback configuration unavailable; business runtime remains ready', { module: 'feedback' })
|
|
69
|
+
feedbackFailure = 'configuration'
|
|
70
|
+
}
|
|
71
|
+
if (feedbackFailure && !feedbackClosing) {
|
|
72
|
+
feedbackRetry = setTimeout(() => {
|
|
73
|
+
feedbackRetry = undefined
|
|
74
|
+
void startFeedback()
|
|
75
|
+
}, 30000)
|
|
76
|
+
feedbackRetry.unref()
|
|
77
|
+
}
|
|
78
|
+
})().finally(() => { feedbackStarting = undefined })
|
|
79
|
+
return feedbackStarting
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function closeFeedback() {
|
|
83
|
+
feedbackClosing = true
|
|
84
|
+
if (feedbackRetry)
|
|
85
|
+
clearTimeout(feedbackRetry)
|
|
86
|
+
feedbackRetry = undefined
|
|
87
|
+
await feedbackStarting
|
|
88
|
+
return feedback.close()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
{{/if}}
|
|
92
|
+
|
|
93
|
+
const runtime = core.module.createRuntime([
|
|
94
|
+
{ name: 'configuration', start: () => { core.init({ configDir: './config' }) }, close: () => {} },
|
|
95
|
+
{ name: 'serv-config', start: () => core.config.validate('serv', ServConfigSchema), close: () => {} },
|
|
96
|
+
{{#if features.db}}
|
|
97
|
+
{ name: 'reldb', start: async () => {
|
|
98
|
+
const config = ReldbConfigSchema.parse(core.config.getOrThrow('db'))
|
|
99
|
+
if (config.type === 'sqlite' && config.database !== ':memory:') {
|
|
100
|
+
const { mkdir } = await import('node:fs/promises')
|
|
101
|
+
const { dirname } = await import('node:path')
|
|
102
|
+
await mkdir(dirname(config.database), { recursive: true })
|
|
103
|
+
}
|
|
104
|
+
return reldb.init(config)
|
|
105
|
+
}, close: () => reldb.close() },
|
|
106
|
+
{{/if}}
|
|
107
|
+
{{#if features.cache}}
|
|
108
|
+
{ name: 'cache', start: () => cache.init(CacheConfigSchema.parse(core.config.getOrThrow('cache'))), close: () => cache.close() },
|
|
109
|
+
{{/if}}
|
|
110
|
+
{{#if features.vecdb}}
|
|
111
|
+
{ name: 'vecdb', start: () => vecdb.init(VecdbConfigSchema.parse(core.config.getOrThrow('vecdb'))), close: () => vecdb.close() },
|
|
112
|
+
{{/if}}
|
|
113
|
+
{{#if features.crypto}}
|
|
114
|
+
{ name: 'crypto', start: () => crypto.init(), close: () => crypto.close() },
|
|
115
|
+
{{/if}}
|
|
116
|
+
{{#if features.storage}}
|
|
117
|
+
{ name: 'storage', start: () => storage.init(StorageConfigSchema.parse(core.config.getOrThrow('storage'))), close: () => storage.close() },
|
|
118
|
+
{{/if}}
|
|
119
|
+
{{#if features.reach}}
|
|
120
|
+
{ name: 'reach', enabled: () => Boolean(core.config.get('reach')), start: () => reach.init(ReachConfigSchema.parse(core.config.getOrThrow('reach'))), close: () => reach.close() },
|
|
121
|
+
{{/if}}
|
|
122
|
+
{{#if features.audit}}
|
|
123
|
+
{ name: 'audit', start: () => audit.init({ ...AuditInitConfigSchema.parse(core.config.get('audit') ?? {}){{#if features.storage}}, storage{{/if}}{{#if features.reach}}, reach{{/if}} }), close: () => audit.close() },
|
|
124
|
+
{{/if}}
|
|
125
|
+
{{#if features.iam}}
|
|
126
|
+
{ name: 'iam', start: () => iam.init({ ...IamConfigSchema.parse(core.config.getOrThrow('iam')){{#if features.reach}}, reach{{/if}} }), close: () => iam.close() },
|
|
127
|
+
{{/if}}
|
|
128
|
+
{{#if features.audit}}
|
|
129
|
+
{{#if features.scheduler}}
|
|
130
|
+
{ name: 'audit-jobs', enabled: () => Boolean(audit.schedulerPlan), start: async () => {
|
|
131
|
+
const schedule = audit.schedulerPlan
|
|
132
|
+
if (!schedule)
|
|
133
|
+
return
|
|
134
|
+
const initialized = await scheduler.init({ ...SchedulerConfigSchema.parse(core.config.get('scheduler') ?? {}), ...schedule })
|
|
135
|
+
if (!initialized.success)
|
|
136
|
+
return initialized
|
|
137
|
+
const started = scheduler.start()
|
|
138
|
+
if (!started.success)
|
|
139
|
+
await scheduler.close()
|
|
140
|
+
return started
|
|
141
|
+
}, close: () => scheduler.close() },
|
|
142
|
+
{{/if}}
|
|
143
|
+
{{/if}}
|
|
144
|
+
{{#if features.feedback}}
|
|
145
|
+
{ name: 'feedback', enabled: () => Boolean(core.config.get('feedback')), start: startFeedback, close: closeFeedback },
|
|
146
|
+
{{/if}}
|
|
147
|
+
{{#if features.ai}}
|
|
148
|
+
{ name: 'ai', start: () => ai.init(AIConfigSchema.parse(core.config.getOrThrow('ai'))), close: () => ai.close() },
|
|
149
|
+
{{/if}}
|
|
150
|
+
{ name: 'bootstrap', start: () => { core.logger.info('API service initialized') }, close: () => {} },
|
|
151
|
+
])
|
|
152
|
+
|
|
153
|
+
/** 启动失败只报告模块、错误码和配置路径,私密值不进入错误上下文。 */
|
|
154
|
+
export async function initApp(): Promise<void> {
|
|
155
|
+
const result = await runtime.start()
|
|
156
|
+
if (!result.success)
|
|
157
|
+
throw new Error(result.error.message, { cause: result.error })
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 清理失败时保留依赖和清理义务,可再次调用。 */
|
|
161
|
+
export async function closeApp(): Promise<void> {
|
|
162
|
+
const result = await runtime.close()
|
|
163
|
+
if (!result.success)
|
|
164
|
+
throw new Error(result.error.message, { cause: result.error })
|
|
165
|
+
}
|
package/templates/apps/api/apps/{{projectName}}-serv/src/server/procedures/app-procedures.ts.hbs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ServContext } from '@h-ai/serv'
|
|
2
|
+
import type { AppEchoOutputData, AppInfoOutputData } from '{{api.contractPackageName}}'
|
|
3
|
+
import { ok } from '@h-ai/core'
|
|
4
|
+
import { serv } from '@h-ai/serv'
|
|
5
|
+
import { appContract } from '{{api.contractPackageName}}'
|
|
6
|
+
|
|
7
|
+
export interface AppProcedureDeps {
|
|
8
|
+
readonly info: {
|
|
9
|
+
readonly name: string
|
|
10
|
+
readonly version: string
|
|
11
|
+
readonly env: AppInfoOutputData['env']
|
|
12
|
+
readonly defaultLocale: string
|
|
13
|
+
readonly transportEnabled: boolean
|
|
14
|
+
}
|
|
15
|
+
readonly startedAt: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 创建应用自有 procedures。 */
|
|
19
|
+
export function createAppProcedures(deps: AppProcedureDeps) {
|
|
20
|
+
return serv
|
|
21
|
+
.implement(appContract)
|
|
22
|
+
.context<ServContext>()
|
|
23
|
+
.route('info', () => {
|
|
24
|
+
const data: AppInfoOutputData = {
|
|
25
|
+
name: deps.info.name,
|
|
26
|
+
version: deps.info.version,
|
|
27
|
+
env: deps.info.env,
|
|
28
|
+
defaultLocale: deps.info.defaultLocale,
|
|
29
|
+
transportEnabled: deps.info.transportEnabled,
|
|
30
|
+
uptimeMs: Math.max(0, Date.now() - deps.startedAt),
|
|
31
|
+
}
|
|
32
|
+
return ok(data)
|
|
33
|
+
})
|
|
34
|
+
{{#if features.iam}}
|
|
35
|
+
.route('echo')
|
|
36
|
+
.auth()
|
|
37
|
+
.handle(({ input, context }) => {
|
|
38
|
+
const data: AppEchoOutputData = {
|
|
39
|
+
message: input.message,
|
|
40
|
+
userId: context.session.userId,
|
|
41
|
+
requestId: context.requestId,
|
|
42
|
+
timestamp: new Date().toISOString(),
|
|
43
|
+
}
|
|
44
|
+
return ok(data)
|
|
45
|
+
})
|
|
46
|
+
{{else}}
|
|
47
|
+
.route('echo', ({ input, context }) => {
|
|
48
|
+
const data: AppEchoOutputData = {
|
|
49
|
+
message: input.message,
|
|
50
|
+
requestId: context.requestId,
|
|
51
|
+
timestamp: new Date().toISOString(),
|
|
52
|
+
}
|
|
53
|
+
return ok(data)
|
|
54
|
+
})
|
|
55
|
+
{{/if}}
|
|
56
|
+
.build()
|
|
57
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AppProcedureDeps } from './app-procedures.js'
|
|
2
|
+
{{#if features.ai}}import { ai } from '@h-ai/ai'
|
|
3
|
+
{{/if}}{{#if features.feedback}}import { feedback } from '@h-ai/feedback'
|
|
4
|
+
{{/if}}{{#if features.iam}}import { iam } from '@h-ai/iam'
|
|
5
|
+
{{/if}}{{#if features.ai}}import { createAiProcedures } from '@h-ai/serv/features/ai'
|
|
6
|
+
{{/if}}{{#if features.feedback}}import { createFeedbackProcedures } from '@h-ai/serv/features/feedback'
|
|
7
|
+
{{/if}}{{#if features.iam}}import { createIamProcedures } from '@h-ai/serv/features/iam'
|
|
8
|
+
{{/if}}{{#if features.storage}}import { createStorageProcedures } from '@h-ai/serv/features/storage'
|
|
9
|
+
import { storage } from '@h-ai/storage'
|
|
10
|
+
{{/if}}import { createAppProcedures } from './app-procedures.js'
|
|
11
|
+
|
|
12
|
+
// @hai-generator:procedures:imports
|
|
13
|
+
|
|
14
|
+
/** 创建应用级 procedures 聚合。 */
|
|
15
|
+
export function {{api.serviceProceduresFactoryName}}(deps: { app: AppProcedureDeps }) {
|
|
16
|
+
return {
|
|
17
|
+
// @hai-generator:procedures:entries
|
|
18
|
+
{{#if features.iam}} iam: createIamProcedures({ iam }),
|
|
19
|
+
{{/if}}{{#if features.storage}} storage: createStorageProcedures({
|
|
20
|
+
storage,
|
|
21
|
+
authorize: ({ context, keys }) => keys.every(key =>
|
|
22
|
+
key.startsWith(`users/${encodeURIComponent(context.session.userId)}/`)),
|
|
23
|
+
}),
|
|
24
|
+
{{/if}}{{#if features.ai}} // AI 默认绑定可信 session.userId,跨主体访问需另行提供 authorizeObject 策略。
|
|
25
|
+
ai: createAiProcedures({ ai }),
|
|
26
|
+
{{/if}}{{#if features.feedback}}
|
|
27
|
+
feedback: createFeedbackProcedures({
|
|
28
|
+
feedback,
|
|
29
|
+
resolveContext: ({ session }) => ({
|
|
30
|
+
scopeId: '{{projectName}}',
|
|
31
|
+
userId: session.userId,
|
|
32
|
+
// 示例角色映射;实际产品应从可信租户与资源权限确定范围。
|
|
33
|
+
permissions: session.roles.includes('admin')
|
|
34
|
+
? ['feedback:create', 'feedback:read', 'feedback:process', 'feedback:reopen', 'feedback:export']
|
|
35
|
+
: ['feedback:create'],
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
{{/if}}
|
|
39
|
+
app: createAppProcedures(deps.app),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { CoreConfig } from '@h-ai/core'
|
|
2
|
+
import type { ServConfig } from '@h-ai/serv'
|
|
3
|
+
import type { AddressInfo } from 'node:net'
|
|
4
|
+
import { mkdtempSync, rmSync } from 'node:fs'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
{{#if features.ai}}import { ai } from '@h-ai/ai'
|
|
8
|
+
{{/if}}import { apiClient } from '@h-ai/api-client'
|
|
9
|
+
{{#if features.cache}}import { cache } from '@h-ai/cache'
|
|
10
|
+
{{/if}}import { core } from '@h-ai/core'
|
|
11
|
+
{{#if features.iam}}import { iam } from '@h-ai/iam'
|
|
12
|
+
{{/if}}{{#if features.db}}import { reldb } from '@h-ai/reldb'
|
|
13
|
+
{{/if}}import { serv } from '@h-ai/serv'
|
|
14
|
+
{{#if features.storage}}import { storage } from '@h-ai/storage'
|
|
15
|
+
{{/if}}{{#if features.vecdb}}import { vecdb } from '@h-ai/vecdb'
|
|
16
|
+
{{/if}}import { {{api.contractExportName}} } from '{{api.contractPackageName}}'
|
|
17
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
18
|
+
|
|
19
|
+
import { {{api.serviceAppFactoryName}} } from '../src/app.js'
|
|
20
|
+
|
|
21
|
+
let tempRoot = ''
|
|
22
|
+
let baseUrl = ''
|
|
23
|
+
let client: ReturnType<typeof apiClient.create<typeof {{api.contractExportName}}>>
|
|
24
|
+
let server: ReturnType<typeof serv.listen>
|
|
25
|
+
let servConfig: ServConfig
|
|
26
|
+
{{#if features.storage}}let storageRoot = ''
|
|
27
|
+
{{/if}}{{#if features.vecdb}}let vecdbRoot = ''
|
|
28
|
+
{{/if}}
|
|
29
|
+
|
|
30
|
+
{{#if features.iam}}
|
|
31
|
+
function uniqueUser(prefix = 'api') {
|
|
32
|
+
const suffix = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`.slice(-8)
|
|
33
|
+
return {
|
|
34
|
+
username: `${prefix}_${suffix}`,
|
|
35
|
+
password: 'TestPass123',
|
|
36
|
+
email: `${prefix}_${suffix}@test.local`,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
{{/if}}
|
|
40
|
+
|
|
41
|
+
beforeAll(async () => {
|
|
42
|
+
tempRoot = mkdtempSync(join(tmpdir(), '{{projectName}}-service-test-'))
|
|
43
|
+
{{#if features.storage}} storageRoot = join(tempRoot, 'storage')
|
|
44
|
+
{{/if}}{{#if features.vecdb}} vecdbRoot = join(tempRoot, 'vecdb')
|
|
45
|
+
{{/if}}
|
|
46
|
+
|
|
47
|
+
core.init({
|
|
48
|
+
configDir: './config',
|
|
49
|
+
logging: { level: 'warn' },
|
|
50
|
+
})
|
|
51
|
+
servConfig = core.config.getOrThrow<ServConfig>('serv')
|
|
52
|
+
{{#if features.db}}
|
|
53
|
+
|
|
54
|
+
const dbResult = await reldb.init({ type: 'sqlite', database: ':memory:' })
|
|
55
|
+
if (!dbResult.success)
|
|
56
|
+
throw new Error(`reldb: ${dbResult.error.message}`)
|
|
57
|
+
{{/if}}{{#if features.cache}}
|
|
58
|
+
|
|
59
|
+
const cacheResult = await cache.init({ type: 'memory' })
|
|
60
|
+
if (!cacheResult.success)
|
|
61
|
+
throw new Error(`cache: ${cacheResult.error.message}`)
|
|
62
|
+
{{/if}}{{#if features.vecdb}}
|
|
63
|
+
|
|
64
|
+
const vecdbResult = await vecdb.init({ type: 'lancedb', path: vecdbRoot })
|
|
65
|
+
if (!vecdbResult.success)
|
|
66
|
+
throw new Error(`vecdb: ${vecdbResult.error.message}`)
|
|
67
|
+
{{/if}}{{#if features.iam}}
|
|
68
|
+
|
|
69
|
+
const iamResult = await iam.init({})
|
|
70
|
+
if (!iamResult.success)
|
|
71
|
+
throw new Error(`iam: ${iamResult.error.message}`)
|
|
72
|
+
{{/if}}{{#if features.storage}}
|
|
73
|
+
|
|
74
|
+
const storageResult = await storage.init({ type: 'local', root: storageRoot })
|
|
75
|
+
if (!storageResult.success)
|
|
76
|
+
throw new Error(`storage: ${storageResult.error.message}`)
|
|
77
|
+
{{/if}}{{#if features.ai}}
|
|
78
|
+
|
|
79
|
+
const aiResult = await ai.init({})
|
|
80
|
+
if (!aiResult.success)
|
|
81
|
+
throw new Error(`ai: ${aiResult.error.message}`)
|
|
82
|
+
{{/if}}
|
|
83
|
+
|
|
84
|
+
const app = {{api.serviceAppFactoryName}}({
|
|
85
|
+
transport: 'disabled',{{#if features.iam}}
|
|
86
|
+
refreshCookie: 'disabled',{{/if}}
|
|
87
|
+
})
|
|
88
|
+
const listening = new Promise<AddressInfo>((resolve) => {
|
|
89
|
+
server = serv.listen(app, {
|
|
90
|
+
host: '127.0.0.1',
|
|
91
|
+
port: 0,
|
|
92
|
+
onListening: info => resolve(info as AddressInfo),
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
const address = await listening
|
|
96
|
+
baseUrl = `http://127.0.0.1:${address.port}`
|
|
97
|
+
|
|
98
|
+
client = apiClient.create({{api.contractExportName}})
|
|
99
|
+
const initResult = await client.init({
|
|
100
|
+
baseUrl: `${baseUrl}${servConfig.http.apiPrefix}`,
|
|
101
|
+
auth: { storage: apiClient.tokenStorage.memory() },
|
|
102
|
+
})
|
|
103
|
+
if (!initResult.success)
|
|
104
|
+
throw new Error(`client.init: ${initResult.error.message}`)
|
|
105
|
+
}, 30_000)
|
|
106
|
+
|
|
107
|
+
afterAll(async () => {
|
|
108
|
+
await client?.close()
|
|
109
|
+
await server?.close()
|
|
110
|
+
{{#if features.ai}} await ai.close()
|
|
111
|
+
{{/if}}{{#if features.storage}} await storage.close()
|
|
112
|
+
{{/if}}{{#if features.iam}} await iam.close()
|
|
113
|
+
{{/if}}{{#if features.vecdb}} await vecdb.close()
|
|
114
|
+
{{/if}}{{#if features.cache}} await cache.close()
|
|
115
|
+
{{/if}}{{#if features.db}} await reldb.close()
|
|
116
|
+
{{/if}} rmSync(tempRoot, { recursive: true, force: true })
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('{{api.servPackageName}}', () => {
|
|
120
|
+
it('returns health status', async () => {
|
|
121
|
+
if (servConfig.http.health === false)
|
|
122
|
+
throw new Error('service test requires health endpoint')
|
|
123
|
+
const response = await fetch(`${baseUrl}${servConfig.http.health.path}`)
|
|
124
|
+
|
|
125
|
+
expect(response.status).toBe(200)
|
|
126
|
+
await expect(response.json()).resolves.toEqual({ status: 'ok' })
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('returns app info as HaiResult', async () => {
|
|
130
|
+
const result = await client.app.info()
|
|
131
|
+
|
|
132
|
+
expect(result.success).toBe(true)
|
|
133
|
+
if (result.success) {
|
|
134
|
+
const config = core.config.getOrThrow<CoreConfig>('core')
|
|
135
|
+
expect(result.data).toMatchObject({ name: config.name, version: config.version, env: config.env, defaultLocale: config.defaultLocale })
|
|
136
|
+
expect(typeof result.data.transportEnabled).toBe('boolean')
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('validates echo input', async () => {
|
|
141
|
+
const result = await client.app.echo({ message: '' })
|
|
142
|
+
|
|
143
|
+
expect(result.success).toBe(false)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
{{#if features.iam}}
|
|
147
|
+
it('registers a user and returns authenticated echo context', async () => {
|
|
148
|
+
const user = uniqueUser('svc')
|
|
149
|
+
const authActions = apiClient.createAuthActions(client)
|
|
150
|
+
const register = await authActions.register({
|
|
151
|
+
username: user.username,
|
|
152
|
+
password: user.password,
|
|
153
|
+
email: user.email,
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
expect(register.success).toBe(true)
|
|
157
|
+
|
|
158
|
+
const result = await client.app.echo({ message: 'hello unit' })
|
|
159
|
+
expect(result.success).toBe(true)
|
|
160
|
+
if (result.success) {
|
|
161
|
+
expect(result.data.message).toBe('hello unit')
|
|
162
|
+
expect(result.data.userId).toBeTruthy()
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
{{else}}
|
|
166
|
+
it('returns echo result as HaiResult', async () => {
|
|
167
|
+
const result = await client.app.echo({ message: 'hello unit' })
|
|
168
|
+
|
|
169
|
+
expect(result.success).toBe(true)
|
|
170
|
+
if (result.success) {
|
|
171
|
+
expect(result.data.message).toBe('hello unit')
|
|
172
|
+
expect(result.data.userId).toBeUndefined()
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
{{/if}}
|
|
176
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"moduleResolution": "bundler",
|
|
5
|
+
"types": ["node"],
|
|
6
|
+
"verbatimModuleSyntax": true,
|
|
7
|
+
"skipLibCheck": true
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"src/**/*.ts"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"node_modules",
|
|
14
|
+
"dist"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { defineConfig } from 'tsup'
|
|
4
|
+
import { resolveBuildMetadata } from '../../scripts/build-metadata.js'
|
|
5
|
+
|
|
6
|
+
const buildMetadata = resolveBuildMetadata(fileURLToPath(new URL('.', import.meta.url)))
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
define: { __HAI_BUILD_METADATA__: JSON.stringify(buildMetadata) },
|
|
10
|
+
async onSuccess() {
|
|
11
|
+
await writeFile(new URL('./dist/build-metadata.json', import.meta.url), JSON.stringify(buildMetadata))
|
|
12
|
+
},
|
|
13
|
+
entry: ['src/index.ts'],
|
|
14
|
+
format: ['esm'],
|
|
15
|
+
target: 'node22',
|
|
16
|
+
sourcemap: true,
|
|
17
|
+
clean: true,
|
|
18
|
+
dts: false,
|
|
19
|
+
external: ['@lancedb/lancedb'],
|
|
20
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import { defineConfig } from 'vitest/config'
|
|
3
|
+
import { resolveBuildMetadata } from '../../scripts/build-metadata.js'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
define: { __HAI_BUILD_METADATA__: JSON.stringify(resolveBuildMetadata(fileURLToPath(new URL('.', import.meta.url)))) },
|
|
7
|
+
test: {
|
|
8
|
+
globals: true,
|
|
9
|
+
environment: 'node',
|
|
10
|
+
include: ['tests/**/*.test.ts'],
|
|
11
|
+
},
|
|
12
|
+
})
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { apiClient } from '@h-ai/api-client'
|
|
3
|
+
{{#if features.crypto}}
|
|
4
|
+
import { crypto } from '@h-ai/crypto'
|
|
5
|
+
{{/if}}
|
|
6
|
+
import { expect, test } from '@playwright/test'
|
|
7
|
+
import { {{api.contractExportName}} } from '{{api.contractPackageName}}'
|
|
8
|
+
|
|
9
|
+
const API_PREFIX = '/api/v1'
|
|
10
|
+
const client = apiClient.create({{api.contractExportName}})
|
|
11
|
+
|
|
12
|
+
test.beforeAll(async () => {
|
|
13
|
+
{{#if features.crypto}}
|
|
14
|
+
expect((await crypto.init()).success).toBe(true)
|
|
15
|
+
{{/if}}
|
|
16
|
+
const result = await client.init({
|
|
17
|
+
baseUrl: `${process.env.BASE_URL || 'http://127.0.0.1:3000'}${API_PREFIX}`,
|
|
18
|
+
{{#if features.iam}}
|
|
19
|
+
auth: { storage: apiClient.tokenStorage.memory() },
|
|
20
|
+
{{/if}}
|
|
21
|
+
{{#if features.crypto}}
|
|
22
|
+
transport: { crypto },
|
|
23
|
+
{{/if}}
|
|
24
|
+
})
|
|
25
|
+
expect(result.success).toBe(true)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test.afterAll(async () => {
|
|
29
|
+
await client.close()
|
|
30
|
+
{{#if features.crypto}}
|
|
31
|
+
await crypto.close()
|
|
32
|
+
{{/if}}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('service health endpoint returns ok', async ({ request }) => {
|
|
36
|
+
const response = await request.get('/health')
|
|
37
|
+
|
|
38
|
+
expect(response.status()).toBe(200)
|
|
39
|
+
await expect(response.json()).resolves.toEqual({ status: 'ok' })
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('service app.info endpoint returns HaiResult', async () => {
|
|
43
|
+
const body = await client.app.info()
|
|
44
|
+
expect(body.success).toBe(true)
|
|
45
|
+
if (!body.success)
|
|
46
|
+
return
|
|
47
|
+
expect(body.data.name).toBe(process.env.HAI_CORE_NAME ?? '{{projectName}} API Service')
|
|
48
|
+
expect(body.data.version).toBe(process.env.HAI_CORE_VERSION ?? '0.1.0')
|
|
49
|
+
expect(body.data.env).toBe('test')
|
|
50
|
+
expect(typeof body.data.transportEnabled).toBe('boolean')
|
|
51
|
+
})
|
|
52
|
+
{{#if features.iam}}
|
|
53
|
+
|
|
54
|
+
/** 通过真实 API 验证 IAM 开关、登录、通知和重置,不需要页面适配。 */
|
|
55
|
+
test('configured IAM supports registration, OTP and reset', async ({ request }) => {
|
|
56
|
+
test.setTimeout(60_000)
|
|
57
|
+
const actions = apiClient.createAuthActions(client)
|
|
58
|
+
const publicConfig = await actions.publicConfig()
|
|
59
|
+
expect(publicConfig.success).toBe(true)
|
|
60
|
+
if (!publicConfig.success)
|
|
61
|
+
return
|
|
62
|
+
expect(publicConfig.data?.register.enabled).toBe(true)
|
|
63
|
+
const username = `api${Date.now()}`
|
|
64
|
+
const email = `${username}@example.com`
|
|
65
|
+
const password = 'ApiPassword123'
|
|
66
|
+
expect((await actions.register({ username, email, password })).success).toBe(true)
|
|
67
|
+
expect((await actions.login({ identifier: username, password })).success).toBe(true)
|
|
68
|
+
if (!publicConfig.data?.login.email) {
|
|
69
|
+
// 无 Reach/发送回调时,基础认证仍可用,未就绪的通知入口保持关闭。
|
|
70
|
+
expect((await actions.sendOtp(email)).success).toBe(false)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
if (!process.env.IAM_NOTIFICATION_URL)
|
|
74
|
+
return
|
|
75
|
+
async function received(template: string) {
|
|
76
|
+
const response = await request.get(`${process.env.IAM_NOTIFICATION_URL}/messages?to=${encodeURIComponent(email)}`)
|
|
77
|
+
const messages = await response.json() as { template: string, vars: Record<string, string> }[]
|
|
78
|
+
return messages.findLast(item => item.template === template)?.vars
|
|
79
|
+
}
|
|
80
|
+
expect((await actions.sendOtp(email)).success).toBe(true)
|
|
81
|
+
const otp = await received('otp_email')
|
|
82
|
+
expect(Boolean(otp?.code)).toBe(true)
|
|
83
|
+
expect((await actions.login({ identifier: email, method: 'email', code: otp?.code })).success).toBe(true)
|
|
84
|
+
expect((await actions.requestPasswordReset(email)).success).toBe(true)
|
|
85
|
+
const reset = await received('password_reset')
|
|
86
|
+
expect(Boolean(reset?.token)).toBe(true)
|
|
87
|
+
expect((await actions.confirmPasswordReset(reset?.token ?? '', 'ApiResetPassword456')).success).toBe(true)
|
|
88
|
+
expect((await actions.login({ identifier: username, password: 'ApiResetPassword456' })).success).toBe(true)
|
|
89
|
+
})
|
|
90
|
+
{{/if}}
|
|
91
|
+
{{#if features.feedback}}
|
|
92
|
+
|
|
93
|
+
test('feedback intake is idempotent and creator can append evidence without administrator access', async () => {
|
|
94
|
+
const actions = apiClient.createAuthActions(client)
|
|
95
|
+
const username = `feedback${Date.now()}`
|
|
96
|
+
const password = 'Feedback-test-Password123!'
|
|
97
|
+
expect((await actions.register({ username, password, email: `${username}@example.test` })).success).toBe(true)
|
|
98
|
+
expect((await actions.login({ identifier: username, password })).success).toBe(true)
|
|
99
|
+
const submissionId = `submission-${Date.now()}`
|
|
100
|
+
const created = await client.feedback.reports.submit({ appId: '{{projectName}}', submissionId })
|
|
101
|
+
expect(created.success).toBe(true)
|
|
102
|
+
if (!created.success)
|
|
103
|
+
return
|
|
104
|
+
const duplicate = await client.feedback.reports.submit({ appId: '{{projectName}}', submissionId })
|
|
105
|
+
expect(duplicate.success).toBe(true)
|
|
106
|
+
if (duplicate.success)
|
|
107
|
+
expect(duplicate.data.id).toBe(created.data.id)
|
|
108
|
+
const evidence = await client.feedback.reports.appendEvidence({ id: created.data.id, evidence: [{ id: 'event-1', source: 'api-test', sequence: 1, kind: 'business', timestamp: Date.now(), data: { action: 'api-feedback' } }] })
|
|
109
|
+
expect(evidence.success).toBe(true)
|
|
110
|
+
expect((await client.feedback.reports.completeCollection({ id: created.data.id, missing: ['browser-not-applicable'] })).success).toBe(true)
|
|
111
|
+
expect((await client.feedback.reports.list({})).success).toBe(false)
|
|
112
|
+
})
|
|
113
|
+
{{/if}}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import process from 'node:process'
|
|
4
|
+
import { chromium, expect } from '@playwright/test'
|
|
5
|
+
|
|
6
|
+
/** 仅在指定证据目录时采集健康端点截图,常规 API 测试通过 HTTP 请求完成。 */
|
|
7
|
+
export default async function captureEvidence() {
|
|
8
|
+
const evidence = process.env.HAI_AUTH_EVIDENCE_DIR
|
|
9
|
+
if (!evidence)
|
|
10
|
+
return
|
|
11
|
+
const browser = await chromium.launch({ channel: 'chrome' })
|
|
12
|
+
try {
|
|
13
|
+
const page = await browser.newPage()
|
|
14
|
+
const response = await page.goto(new URL('/health', process.env.BASE_URL || 'http://127.0.0.1:3000').href)
|
|
15
|
+
expect(response?.status()).toBe(200)
|
|
16
|
+
await expect(page.locator('body')).toContainText('ok')
|
|
17
|
+
await mkdir(evidence, { recursive: true })
|
|
18
|
+
await page.screenshot({ path: path.join(evidence, '{{projectName}}-health.png'), fullPage: true })
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
await browser.close()
|
|
22
|
+
}
|
|
23
|
+
}
|