@patodo/localapp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.localapp-artifact.json +2731 -0
- package/LICENSE +21 -0
- package/README.md +288 -0
- package/bin/localapp.mjs +34182 -0
- package/package.json +21 -0
- package/runtime/bootstrap/localapp-daemon-bootstrap.mjs +150 -0
- package/runtime/native/adapter-manifest.json +85 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Info.plist +21 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Info.plist +21 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
- package/runtime/native/linux-x64/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/linux-x64/localapp-notifications +0 -0
- package/runtime/native/win32-x64/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/win32-x64/localapp-native.exe +0 -0
- package/runtime/server/.localapp-server-runtime.json +133 -0
- package/runtime/server/bin/server-cli.cjs +8343 -0
- package/runtime/server/bin/server.mjs +8 -0
- package/runtime/server/bin/worker.cjs +144339 -0
- package/runtime/server/node_modules/sql.js/dist/sql-wasm.js +185 -0
- package/runtime/server/node_modules/sql.js/dist/sql-wasm.wasm +0 -0
- package/runtime/server/node_modules/sql.js/package.json +58 -0
- package/runtime/server/package.json +11 -0
- package/runtime/server/runner/localapp-runner.mjs +324 -0
- package/runtime/server/web/404.html +1 -0
- package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_buildManifest.js +1 -0
- package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_ssgManifest.js +1 -0
- package/runtime/server/web/_next/static/chunks/184-184da63eba05808f.js +1 -0
- package/runtime/server/web/_next/static/chunks/265-a58973dbf631dc41.js +1 -0
- package/runtime/server/web/_next/static/chunks/308-d74213c6f5179bf0.js +1 -0
- package/runtime/server/web/_next/static/chunks/416-53d48ad9442eb7b2.js +1 -0
- package/runtime/server/web/_next/static/chunks/448-280e06e915001cb5.js +1 -0
- package/runtime/server/web/_next/static/chunks/66-6f6658280a10fbca.js +1 -0
- package/runtime/server/web/_next/static/chunks/740d80ee-6c0a9504f1fd46f8.js +1 -0
- package/runtime/server/web/_next/static/chunks/86-7105ac54171494a1.js +1 -0
- package/runtime/server/web/_next/static/chunks/900-743e38de13217291.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/inbox/page-32b885c019043e48.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/layout-4b3a212263712a5c.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/analytics/page-6af9adc14ccfa925.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/[name]/settings/page-8b6f809eeccdbd22.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/page-7f1ddf07889da248.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/dashboard/page-a25eb621fb18491d.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-actions/page-e6045823829567f7.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-notifications/page-377ed49cf55da81d.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/favorites/page-82f292daebf98a2f.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/groups/page-fe4ed80c7b11920f.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/info/page-d5d5075eec069ce3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/keys/page-35ed01bf39a163b6.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/layout-5481d53aae3a0ce1.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/orgs/page-44c606ff2233f1a8.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/page-f2331bbbe09541aa.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/pages/page-6bf4e160a99411ce.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/peers/page-27041dd149601002.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/recent/page-f321688d374a8ff3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/settings/page-64e724318dc3a584.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/studio/page-a2c0c34538ac62b3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/subscriptions/page-57cdaafe12347e32.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/system/page-96d2e1f8c2fb22b0.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/tasks/page-bf16b78ed6749d78.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/users/page-c47d4524d2a156b8.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-f4641be7b88818a2.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/_not-found/page-f4902e6b69eebd4c.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/layout-5557bc90d966fded.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/platform-shell/[userId]/[name]/page-da0d5e71857f33d1.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/platform-shell-preview/page-52fa7e8c8b480934.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/setup/page-9e29d6f66825a8f8.js +1 -0
- package/runtime/server/web/_next/static/chunks/framework-1c02a2e60068b586.js +1 -0
- package/runtime/server/web/_next/static/chunks/main-21ea4d4d10f4a256.js +1 -0
- package/runtime/server/web/_next/static/chunks/main-app-5b3c67453d8c5b99.js +1 -0
- package/runtime/server/web/_next/static/chunks/pages/_app-649f81c9fedecf29.js +1 -0
- package/runtime/server/web/_next/static/chunks/pages/_error-64e3bd84e2ecae08.js +1 -0
- package/runtime/server/web/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/runtime/server/web/_next/static/chunks/webpack-0bed2fdf6baa566e.js +1 -0
- package/runtime/server/web/_next/static/css/afdc0938fca59693.css +3 -0
- package/runtime/server/web/_next/static/media/013b72fa676f92e0-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/22a5144ee8d83bca-s.p.woff2 +0 -0
- package/runtime/server/web/_next/static/media/2b5b02fc7e511755-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/65f03d54ccadf4a8-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/7d4881bb7e1bf84d-s.p.woff2 +0 -0
- package/runtime/server/web/_next/static/media/9766a7e9e2e0ad5a-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/aa016aab0e6d1295-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/b66cf8e69499582a-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/b9408752a0c24fb9-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/e038a29029a234f2-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/f639721981034f88-s.woff2 +0 -0
- package/runtime/server/web/home/redline-launch-hero.png +0 -0
- package/runtime/server/web/inbox.html +1 -0
- package/runtime/server/web/inbox.txt +27 -0
- package/runtime/server/web/index.html +1 -0
- package/runtime/server/web/index.txt +27 -0
- package/runtime/server/web/my/analytics.html +1 -0
- package/runtime/server/web/my/analytics.txt +27 -0
- package/runtime/server/web/my/apps/placeholder/settings.html +1 -0
- package/runtime/server/web/my/apps/placeholder/settings.txt +24 -0
- package/runtime/server/web/my/apps.html +1 -0
- package/runtime/server/web/my/apps.txt +27 -0
- package/runtime/server/web/my/dashboard.html +1 -0
- package/runtime/server/web/my/dashboard.txt +27 -0
- package/runtime/server/web/my/device-actions.html +1 -0
- package/runtime/server/web/my/device-actions.txt +24 -0
- package/runtime/server/web/my/device-notifications.html +1 -0
- package/runtime/server/web/my/device-notifications.txt +24 -0
- package/runtime/server/web/my/favorites.html +1 -0
- package/runtime/server/web/my/favorites.txt +27 -0
- package/runtime/server/web/my/groups.html +1 -0
- package/runtime/server/web/my/groups.txt +27 -0
- package/runtime/server/web/my/info.html +1 -0
- package/runtime/server/web/my/info.txt +27 -0
- package/runtime/server/web/my/keys.html +1 -0
- package/runtime/server/web/my/keys.txt +27 -0
- package/runtime/server/web/my/orgs.html +1 -0
- package/runtime/server/web/my/orgs.txt +27 -0
- package/runtime/server/web/my/pages.html +1 -0
- package/runtime/server/web/my/pages.txt +27 -0
- package/runtime/server/web/my/peers.html +1 -0
- package/runtime/server/web/my/peers.txt +24 -0
- package/runtime/server/web/my/recent.html +1 -0
- package/runtime/server/web/my/recent.txt +27 -0
- package/runtime/server/web/my/settings.html +1 -0
- package/runtime/server/web/my/settings.txt +27 -0
- package/runtime/server/web/my/studio.html +1 -0
- package/runtime/server/web/my/studio.txt +24 -0
- package/runtime/server/web/my/subscriptions.html +1 -0
- package/runtime/server/web/my/subscriptions.txt +27 -0
- package/runtime/server/web/my/system.html +1 -0
- package/runtime/server/web/my/system.txt +24 -0
- package/runtime/server/web/my/tasks.html +1 -0
- package/runtime/server/web/my/tasks.txt +24 -0
- package/runtime/server/web/my/users.html +1 -0
- package/runtime/server/web/my/users.txt +27 -0
- package/runtime/server/web/my.html +1 -0
- package/runtime/server/web/my.txt +27 -0
- package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -0
- package/runtime/server/web/platform-shell/placeholder/placeholder.txt +23 -0
- package/runtime/server/web/platform-shell-preview.html +1 -0
- package/runtime/server/web/platform-shell-preview.txt +23 -0
- package/runtime/server/web/setup.html +1 -0
- package/runtime/server/web/setup.txt +23 -0
- package/template/.claude/skills/agent-tool-patterns/SKILL.md +195 -0
- package/template/.claude/skills/localapp/SKILL.md +80 -0
- package/template/.claude/skills/localapp-auth/SKILL.md +299 -0
- package/template/.claude/skills/localapp-business/SKILL.md +325 -0
- package/template/.claude/skills/localapp-data/SKILL.md +381 -0
- package/template/.claude/skills/localapp-device-actions/SKILL.md +60 -0
- package/template/.claude/skills/localapp-notify/SKILL.md +118 -0
- package/template/.claude/skills/localapp-transitions/SKILL.md +238 -0
- package/template/.claude/skills/localapp-ui/SKILL.md +67 -0
- package/template/.claude/skills/localapp-upload/SKILL.md +172 -0
- package/template/AGENTS.md +33 -0
- package/template/CLAUDE.md +117 -0
- package/template/ISSUES.md +32 -0
- package/template/backend/resources/work_items/mutations.json +83 -0
- package/template/backend/resources/work_items/queries.json +83 -0
- package/template/backend/resources/work_items/schema.json +31 -0
- package/template/backend/schemas/mutations.schema.json +15 -0
- package/template/backend/schemas/queries.schema.json +36 -0
- package/template/backend/schemas/resource-schema.schema.json +25 -0
- package/template/components.json +25 -0
- package/template/index.html +12 -0
- package/template/migrations/001_work_items.sql +6 -0
- package/template/package.json +70 -0
- package/template/postcss.config.js +5 -0
- package/template/runtime/dev-shell.tsx +6398 -0
- package/template/runtime/hooks/use-mobile.ts +19 -0
- package/template/runtime/issue-reference.ts +44 -0
- package/template/runtime/lib/utils.ts +6 -0
- package/template/runtime/package.json +14 -0
- package/template/runtime/platform-capabilities.json +109 -0
- package/template/runtime/sdk/agent/package.json +51 -0
- package/template/runtime/sdk/agent/src/agent-chat.tsx +188 -0
- package/template/runtime/sdk/agent/src/assistant-ui-adapter.ts +87 -0
- package/template/runtime/sdk/agent/src/context.ts +56 -0
- package/template/runtime/sdk/agent/src/dev-bridge.ts +21 -0
- package/template/runtime/sdk/agent/src/index.ts +19 -0
- package/template/runtime/sdk/agent/src/llm-adapter.ts +263 -0
- package/template/runtime/sdk/agent/src/native-registry.ts +61 -0
- package/template/runtime/sdk/agent/src/platform-runtime.ts +164 -0
- package/template/runtime/sdk/agent/src/postmessage-bridge.ts +60 -0
- package/template/runtime/sdk/agent/src/postmessage-types.ts +150 -0
- package/template/runtime/sdk/agent/src/tools.ts +70 -0
- package/template/runtime/sdk/agent/src/types.ts +27 -0
- package/template/runtime/sdk/agent/src/use-agent.ts +139 -0
- package/template/runtime/sdk/agent/src/use-register-edit-session.ts +54 -0
- package/template/runtime/sdk/agent/src/use-register-tools.ts +92 -0
- package/template/runtime/sdk/agent/tests/platform-runtime.test.ts +154 -0
- package/template/runtime/sdk/agent/tests/postmessage-bridge.test.ts +119 -0
- package/template/runtime/sdk/agent/tests/shell-integration.test.ts +71 -0
- package/template/runtime/sdk/agent/tests/use-register-edit-session.test.tsx +125 -0
- package/template/runtime/sdk/agent/tests/use-register-tools.test.ts +208 -0
- package/template/runtime/sdk/agent/tsconfig.json +18 -0
- package/template/runtime/sdk/agent/vitest.config.ts +8 -0
- package/template/runtime/sdk/backend/package.json +15 -0
- package/template/runtime/sdk/backend/src/index.ts +92 -0
- package/template/runtime/sdk/backend/tsconfig.json +8 -0
- package/template/runtime/sdk/core/package.json +15 -0
- package/template/runtime/sdk/core/src/client.ts +317 -0
- package/template/runtime/sdk/core/src/collaboration.ts +66 -0
- package/template/runtime/sdk/core/src/desktop.ts +469 -0
- package/template/runtime/sdk/core/src/device.ts +112 -0
- package/template/runtime/sdk/core/src/index.ts +6 -0
- package/template/runtime/sdk/core/src/invalidate.ts +40 -0
- package/template/runtime/sdk/core/src/types.ts +108 -0
- package/template/runtime/sdk/core/tests/capabilities.test.ts +64 -0
- package/template/runtime/sdk/core/tests/client.test.ts +424 -0
- package/template/runtime/sdk/core/tests/collaboration.test.ts +92 -0
- package/template/runtime/sdk/core/tests/desktop.test.ts +310 -0
- package/template/runtime/sdk/core/tests/device.test.ts +69 -0
- package/template/runtime/sdk/core/tsconfig.json +17 -0
- package/template/runtime/sdk/react/package.json +34 -0
- package/template/runtime/sdk/react/src/client.ts +7 -0
- package/template/runtime/sdk/react/src/components/can.tsx +24 -0
- package/template/runtime/sdk/react/src/hooks/use-action.ts +34 -0
- package/template/runtime/sdk/react/src/hooks/use-capabilities.ts +35 -0
- package/template/runtime/sdk/react/src/hooks/use-count.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-create.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-delete.ts +36 -0
- package/template/runtime/sdk/react/src/hooks/use-desktop-action.ts +94 -0
- package/template/runtime/sdk/react/src/hooks/use-device-action.ts +62 -0
- package/template/runtime/sdk/react/src/hooks/use-get.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-group-members.ts +31 -0
- package/template/runtime/sdk/react/src/hooks/use-groups.ts +31 -0
- package/template/runtime/sdk/react/src/hooks/use-list.ts +53 -0
- package/template/runtime/sdk/react/src/hooks/use-me.ts +35 -0
- package/template/runtime/sdk/react/src/hooks/use-mutation.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-permissions.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-platform-data.ts +94 -0
- package/template/runtime/sdk/react/src/hooks/use-query.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-time.ts +36 -0
- package/template/runtime/sdk/react/src/hooks/use-transaction.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-transitions.ts +82 -0
- package/template/runtime/sdk/react/src/hooks/use-update.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-upload.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-users.ts +31 -0
- package/template/runtime/sdk/react/src/index.ts +40 -0
- package/template/runtime/sdk/react/src/permissions.ts +94 -0
- package/template/runtime/sdk/react/tests/permissions.test.ts +176 -0
- package/template/runtime/sdk/react/tests/use-action.test.tsx +64 -0
- package/template/runtime/sdk/react/tests/use-capabilities.test.tsx +48 -0
- package/template/runtime/sdk/react/tests/use-desktop-action.test.tsx +144 -0
- package/template/runtime/sdk/react/tests/use-permissions.test.tsx +162 -0
- package/template/runtime/sdk/react/tests/use-platform-data.test.tsx +89 -0
- package/template/runtime/sdk/react/tests/use-transaction.test.tsx +65 -0
- package/template/runtime/sdk/react/tests/use-transitions.test.ts +149 -0
- package/template/runtime/sdk/react/tsconfig.json +18 -0
- package/template/runtime/sdk/react/vitest.config.ts +9 -0
- package/template/runtime/sdk/react/vitest.setup.ts +6 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts +84 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts.map +1 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.js +115 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.js.map +1 -0
- package/template/runtime/server-core/dist/index.d.ts +19 -0
- package/template/runtime/server-core/dist/index.d.ts.map +1 -0
- package/template/runtime/server-core/dist/index.js +35 -0
- package/template/runtime/server-core/dist/index.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js +475 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js +65 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js +103 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js +358 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js +786 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js +82 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js +42 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js +144 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js +75 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js +85 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js +75 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js +78 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js +66 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js +322 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js +49 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js +67 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js +91 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js +69 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js +159 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js +102 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js +65 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js +226 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js +64 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js +101 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js +69 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js +32 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/access-control.d.ts +34 -0
- package/template/runtime/server-core/dist/lib/access-control.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/access-control.js +138 -0
- package/template/runtime/server-core/dist/lib/access-control.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.d.ts +69 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.js +57 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-db.d.ts +486 -0
- package/template/runtime/server-core/dist/lib/app-db.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-db.js +2581 -0
- package/template/runtime/server-core/dist/lib/app-db.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-runtime.d.ts +28 -0
- package/template/runtime/server-core/dist/lib/app-runtime.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-runtime.js +56 -0
- package/template/runtime/server-core/dist/lib/app-runtime.js.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-actions.d.ts +149 -0
- package/template/runtime/server-core/dist/lib/backend-actions.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-actions.js +926 -0
- package/template/runtime/server-core/dist/lib/backend-actions.js.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-contract.d.ts +399 -0
- package/template/runtime/server-core/dist/lib/backend-contract.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-contract.js +1148 -0
- package/template/runtime/server-core/dist/lib/backend-contract.js.map +1 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.d.ts +30 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.js +133 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts +7 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.js +22 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts +43 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.js +201 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts +11 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.js +66 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-templates.d.ts +16 -0
- package/template/runtime/server-core/dist/lib/issue-templates.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-templates.js +89 -0
- package/template/runtime/server-core/dist/lib/issue-templates.js.map +1 -0
- package/template/runtime/server-core/dist/lib/migrations.d.ts +31 -0
- package/template/runtime/server-core/dist/lib/migrations.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/migrations.js +180 -0
- package/template/runtime/server-core/dist/lib/migrations.js.map +1 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts +21 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.js +71 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.js.map +1 -0
- package/template/runtime/server-core/dist/lib/record-access.d.ts +34 -0
- package/template/runtime/server-core/dist/lib/record-access.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/record-access.js +81 -0
- package/template/runtime/server-core/dist/lib/record-access.js.map +1 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts +28 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.js +67 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.js.map +1 -0
- package/template/runtime/server-core/dist/lib/transitions.d.ts +55 -0
- package/template/runtime/server-core/dist/lib/transitions.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/transitions.js +142 -0
- package/template/runtime/server-core/dist/lib/transitions.js.map +1 -0
- package/template/runtime/server-core/dist/types/models.d.ts +163 -0
- package/template/runtime/server-core/dist/types/models.d.ts.map +1 -0
- package/template/runtime/server-core/dist/types/models.js +3 -0
- package/template/runtime/server-core/dist/types/models.js.map +1 -0
- package/template/runtime/server-core/package.json +24 -0
- package/template/runtime/styles/preset.css +282 -0
- package/template/runtime/sync-template-command.cjs +19 -0
- package/template/runtime/sync-template.cjs +71 -0
- package/template/runtime/tsconfig.base.json +20 -0
- package/template/runtime/version.json +3 -0
- package/template/runtime/vite-plugin.mjs +309 -0
- package/template/src/App.tsx +273 -0
- package/template/src/components/ui/accordion.tsx +79 -0
- package/template/src/components/ui/alert-dialog.tsx +197 -0
- package/template/src/components/ui/alert.tsx +76 -0
- package/template/src/components/ui/aspect-ratio.tsx +11 -0
- package/template/src/components/ui/avatar.tsx +110 -0
- package/template/src/components/ui/badge.tsx +49 -0
- package/template/src/components/ui/breadcrumb.tsx +122 -0
- package/template/src/components/ui/button-group.tsx +83 -0
- package/template/src/components/ui/button.tsx +67 -0
- package/template/src/components/ui/calendar.tsx +221 -0
- package/template/src/components/ui/card.tsx +103 -0
- package/template/src/components/ui/carousel.tsx +240 -0
- package/template/src/components/ui/chart.tsx +373 -0
- package/template/src/components/ui/checkbox.tsx +31 -0
- package/template/src/components/ui/collapsible.tsx +33 -0
- package/template/src/components/ui/combobox.tsx +299 -0
- package/template/src/components/ui/command.tsx +193 -0
- package/template/src/components/ui/context-menu.tsx +261 -0
- package/template/src/components/ui/dialog.tsx +168 -0
- package/template/src/components/ui/direction.tsx +22 -0
- package/template/src/components/ui/drawer.tsx +132 -0
- package/template/src/components/ui/dropdown-menu.tsx +269 -0
- package/template/src/components/ui/empty.tsx +104 -0
- package/template/src/components/ui/field.tsx +238 -0
- package/template/src/components/ui/hover-card.tsx +42 -0
- package/template/src/components/ui/input-group.tsx +154 -0
- package/template/src/components/ui/input-otp.tsx +87 -0
- package/template/src/components/ui/input.tsx +19 -0
- package/template/src/components/ui/item.tsx +196 -0
- package/template/src/components/ui/kbd.tsx +26 -0
- package/template/src/components/ui/label.tsx +22 -0
- package/template/src/components/ui/menubar.tsx +280 -0
- package/template/src/components/ui/native-select.tsx +61 -0
- package/template/src/components/ui/navigation-menu.tsx +164 -0
- package/template/src/components/ui/pagination.tsx +129 -0
- package/template/src/components/ui/popover.tsx +87 -0
- package/template/src/components/ui/progress.tsx +31 -0
- package/template/src/components/ui/radio-group.tsx +42 -0
- package/template/src/components/ui/resizable.tsx +50 -0
- package/template/src/components/ui/scroll-area.tsx +53 -0
- package/template/src/components/ui/select.tsx +192 -0
- package/template/src/components/ui/separator.tsx +26 -0
- package/template/src/components/ui/sheet.tsx +145 -0
- package/template/src/components/ui/sidebar.tsx +700 -0
- package/template/src/components/ui/skeleton.tsx +13 -0
- package/template/src/components/ui/slider.tsx +59 -0
- package/template/src/components/ui/sonner.tsx +47 -0
- package/template/src/components/ui/spinner.tsx +10 -0
- package/template/src/components/ui/switch.tsx +33 -0
- package/template/src/components/ui/table.tsx +114 -0
- package/template/src/components/ui/tabs.tsx +90 -0
- package/template/src/components/ui/textarea.tsx +18 -0
- package/template/src/components/ui/toggle-group.tsx +89 -0
- package/template/src/components/ui/toggle.tsx +45 -0
- package/template/src/components/ui/tooltip.tsx +57 -0
- package/template/src/hooks/use-mobile.ts +3 -0
- package/template/src/index.css +4 -0
- package/template/src/lib/utils.ts +3 -0
- package/template/src/main.tsx +10 -0
- package/template/src/vite-env.d.ts +1 -0
- package/template/template.gitignore +10 -0
- package/template/template.npmrc +1 -0
- package/template/tests/agent-context.test.ts +69 -0
- package/template/tests/agent-guidance-template.test.ts +49 -0
- package/template/tests/agent-runtime.test.ts +198 -0
- package/template/tests/agent-tools.test.ts +150 -0
- package/template/tests/agent-use-agent.test.ts +86 -0
- package/template/tests/assistant-ui-adapter.test.ts +211 -0
- package/template/tests/business-modeling-template.test.ts +71 -0
- package/template/tests/client.test.ts +382 -0
- package/template/tests/dev-issue-search-suggestions.test.ts +36 -0
- package/template/tests/dev-shell-context.test.tsx +40 -0
- package/template/tests/dev-shell-template.test.ts +2593 -0
- package/template/tests/invalidation.test.ts +126 -0
- package/template/tests/main-tsx.test.ts +28 -0
- package/template/tests/media-preview-template.test.ts +21 -0
- package/template/tests/mutations.test.ts +224 -0
- package/template/tests/react.test.ts +302 -0
- package/template/tests/redirect.test.ts +51 -0
- package/template/tests/skill-docs.test.ts +76 -0
- package/template/tests/state-transitions-template.test.ts +61 -0
- package/template/tests/template-ui.test.ts +145 -0
- package/template/tests/upload.test.ts +143 -0
- package/template/tests/vite-plugin.test.ts +426 -0
- package/template/tests/vite-proxy-security.test.ts +153 -0
- package/template/tsconfig.json +11 -0
- package/template/vite.config.ts +7 -0
- package/template/vitest.config.ts +16 -0
- package/template/vitest.setup.ts +1 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useState, useCallback, useMemo } from "react";
|
|
2
|
+
import { LocalAppError, invalidate, availableTransitions, type TransitionInfo, type ExecResult } from "@localapp/sdk";
|
|
3
|
+
import { getClient } from "../client.js";
|
|
4
|
+
import type { BusinessMetadata } from "../permissions.js";
|
|
5
|
+
|
|
6
|
+
export interface UseTransitionsOptions<T> {
|
|
7
|
+
onSuccess?: (data: ExecResult) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface UseTransitionsResult {
|
|
11
|
+
transitions: TransitionInfo[];
|
|
12
|
+
transition: (name: string, payload?: Record<string, unknown>) => Promise<ExecResult>;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error: LocalAppError | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 根据 schema 元数据本地计算当前 record 可执行的 transitions,并通过 named mutation
|
|
19
|
+
* 执行状态流转。
|
|
20
|
+
*
|
|
21
|
+
* 平台不再提供 GET/POST /api/<resource>/:id/transitions 端点(restrict-app-api-to-named-sql
|
|
22
|
+
* 变更整体移除了 transition 服务端执行入口)。前端用 availableTransitions 本地计算,
|
|
23
|
+
* 状态流转改由应用在 backend/resources/<resource>/mutations.json 中声明对应的
|
|
24
|
+
* named mutation(如 $<resource>.approve)承担。
|
|
25
|
+
*
|
|
26
|
+
* 用法:
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const schema = { statusField: "status", transitions: [
|
|
29
|
+
* { name: "approve", from: ["pending"], to: "approved", label: "批准" }
|
|
30
|
+
* ]};
|
|
31
|
+
* const { transitions, transition } = useTransitions("leaves", record, schema);
|
|
32
|
+
* transitions.map(t => <button onClick={() => transition(t.name)}>{t.label}</button>)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function useTransitions<TRecord extends { id?: number } = Record<string, unknown>>(
|
|
36
|
+
resource: string,
|
|
37
|
+
record: TRecord | null,
|
|
38
|
+
schema: BusinessMetadata,
|
|
39
|
+
options?: UseTransitionsOptions<TRecord>,
|
|
40
|
+
): UseTransitionsResult {
|
|
41
|
+
const [loading, setLoading] = useState(false);
|
|
42
|
+
const [error, setError] = useState<LocalAppError | null>(null);
|
|
43
|
+
|
|
44
|
+
const transitions = useMemo(() => {
|
|
45
|
+
if (!record) return [];
|
|
46
|
+
return availableTransitions(
|
|
47
|
+
{
|
|
48
|
+
statusField: schema.statusField,
|
|
49
|
+
transitions: schema.transitions as Array<{ name: string; label?: string; to: unknown; from?: unknown[] }> | undefined,
|
|
50
|
+
},
|
|
51
|
+
record as Record<string, unknown>,
|
|
52
|
+
);
|
|
53
|
+
}, [record, schema.statusField, schema.transitions]);
|
|
54
|
+
|
|
55
|
+
const transition = useCallback(
|
|
56
|
+
async (name: string, payload?: Record<string, unknown>) => {
|
|
57
|
+
if (!record?.id) {
|
|
58
|
+
throw new LocalAppError("Cannot execute transition: record.id is missing", 0);
|
|
59
|
+
}
|
|
60
|
+
setLoading(true);
|
|
61
|
+
setError(null);
|
|
62
|
+
try {
|
|
63
|
+
const result = await getClient().mutate<ExecResult>(`$${resource}.${name}`, {
|
|
64
|
+
id: record.id,
|
|
65
|
+
...(payload ?? {}),
|
|
66
|
+
});
|
|
67
|
+
options?.onSuccess?.(result);
|
|
68
|
+
invalidate(resource);
|
|
69
|
+
return result;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
const qe = e instanceof LocalAppError ? e : new LocalAppError(String(e), 0);
|
|
72
|
+
setError(qe);
|
|
73
|
+
throw qe;
|
|
74
|
+
} finally {
|
|
75
|
+
setLoading(false);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[resource, record?.id, options?.onSuccess],
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return { transitions, transition, loading, error };
|
|
82
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import { LocalAppError, invalidate } from "@localapp/sdk";
|
|
3
|
+
import { getClient } from "../client.js";
|
|
4
|
+
|
|
5
|
+
interface UseUpdateOptions<T> {
|
|
6
|
+
onSuccess?: (data: T) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface UseUpdateResult<T> {
|
|
10
|
+
update: (id: number, data: Record<string, unknown>) => Promise<T>;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: LocalAppError | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useUpdate<T = Record<string, unknown>>(resource: string, options?: UseUpdateOptions<T>): UseUpdateResult<T> {
|
|
16
|
+
const [loading, setLoading] = useState(false);
|
|
17
|
+
const [error, setError] = useState<LocalAppError | null>(null);
|
|
18
|
+
|
|
19
|
+
const update = useCallback(async (id: number, data: Record<string, unknown>) => {
|
|
20
|
+
setLoading(true);
|
|
21
|
+
setError(null);
|
|
22
|
+
try {
|
|
23
|
+
const result = await getClient().update<T>(resource, id, data);
|
|
24
|
+
options?.onSuccess?.(result);
|
|
25
|
+
invalidate(resource);
|
|
26
|
+
return result;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
const qe = e instanceof LocalAppError ? e : new LocalAppError(String(e), 0);
|
|
29
|
+
setError(qe);
|
|
30
|
+
throw qe;
|
|
31
|
+
} finally {
|
|
32
|
+
setLoading(false);
|
|
33
|
+
}
|
|
34
|
+
}, [resource, options?.onSuccess]);
|
|
35
|
+
|
|
36
|
+
return { update, loading, error };
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import { LocalAppError, type UploadResult } from "@localapp/sdk";
|
|
3
|
+
import { getClient } from "../client.js";
|
|
4
|
+
|
|
5
|
+
interface UseUploadResult {
|
|
6
|
+
upload: (file: File) => Promise<UploadResult>;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: LocalAppError | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useUpload(): UseUploadResult {
|
|
12
|
+
const [loading, setLoading] = useState(false);
|
|
13
|
+
const [error, setError] = useState<LocalAppError | null>(null);
|
|
14
|
+
|
|
15
|
+
const upload = useCallback(async (file: File): Promise<UploadResult> => {
|
|
16
|
+
setLoading(true);
|
|
17
|
+
setError(null);
|
|
18
|
+
try {
|
|
19
|
+
return await getClient().upload(file);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
const err = e instanceof LocalAppError ? e : new LocalAppError(String(e), 0);
|
|
22
|
+
setError(err);
|
|
23
|
+
throw err;
|
|
24
|
+
} finally {
|
|
25
|
+
setLoading(false);
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
return { upload, loading, error };
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { LocalAppError, type UserBasic } from "@localapp/sdk";
|
|
3
|
+
import { getClient } from "../client.js";
|
|
4
|
+
|
|
5
|
+
interface UseUsersResult {
|
|
6
|
+
users: UserBasic[];
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: LocalAppError | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useUsers(): UseUsersResult {
|
|
12
|
+
const [users, setUsers] = useState<UserBasic[]>([]);
|
|
13
|
+
const [loading, setLoading] = useState(true);
|
|
14
|
+
const [error, setError] = useState<LocalAppError | null>(null);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
let cancelled = false;
|
|
18
|
+
setError(null);
|
|
19
|
+
getClient().users().then((data) => {
|
|
20
|
+
if (!cancelled) { setUsers(data); setLoading(false); }
|
|
21
|
+
}).catch((e) => {
|
|
22
|
+
if (!cancelled) {
|
|
23
|
+
setError(e instanceof LocalAppError ? e : new LocalAppError(String(e), 0));
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return () => { cancelled = true; };
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
return { users, loading, error };
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export { useMe } from "./hooks/use-me.js";
|
|
2
|
+
export { useTime } from "./hooks/use-time.js";
|
|
3
|
+
export { useCapabilities, type UseCapabilitiesResult } from "./hooks/use-capabilities.js";
|
|
4
|
+
export { useUsers } from "./hooks/use-users.js";
|
|
5
|
+
export { useGroups } from "./hooks/use-groups.js";
|
|
6
|
+
export { useGroupMembers } from "./hooks/use-group-members.js";
|
|
7
|
+
export { useList } from "./hooks/use-list.js";
|
|
8
|
+
export { useGet } from "./hooks/use-get.js";
|
|
9
|
+
export { useCount } from "./hooks/use-count.js";
|
|
10
|
+
export { useCreate } from "./hooks/use-create.js";
|
|
11
|
+
export { useUpdate } from "./hooks/use-update.js";
|
|
12
|
+
export { useDelete } from "./hooks/use-delete.js";
|
|
13
|
+
export { useQuery, type UseQueryResult } from "./hooks/use-query.js";
|
|
14
|
+
export { useMutation, type UseMutationResult } from "./hooks/use-mutation.js";
|
|
15
|
+
export { useTransaction, type UseTransactionResult } from "./hooks/use-transaction.js";
|
|
16
|
+
export { useAction, type UseActionResult } from "./hooks/use-action.js";
|
|
17
|
+
export { useDesktopAction, type UseDesktopActionResult } from "./hooks/use-desktop-action.js";
|
|
18
|
+
export { useDeviceAction, type UseDeviceActionResult } from "./hooks/use-device-action.js";
|
|
19
|
+
export { useUpload } from "./hooks/use-upload.js";
|
|
20
|
+
export { useTransitions, type UseTransitionsOptions, type UseTransitionsResult } from "./hooks/use-transitions.js";
|
|
21
|
+
export { usePermissions, type CanFn, type UsePermissionsResult } from "./hooks/use-permissions.js";
|
|
22
|
+
export {
|
|
23
|
+
usePlatformData,
|
|
24
|
+
type PlatformGroup,
|
|
25
|
+
type PlatformRole,
|
|
26
|
+
type PlatformUser,
|
|
27
|
+
type UsePlatformDataResult,
|
|
28
|
+
} from "./hooks/use-platform-data.js";
|
|
29
|
+
export { Can, type CanProps } from "./components/can.js";
|
|
30
|
+
export {
|
|
31
|
+
checkPermission,
|
|
32
|
+
createCan,
|
|
33
|
+
type RecordAction,
|
|
34
|
+
type RecordAccessMode,
|
|
35
|
+
type RecordAccessPolicy,
|
|
36
|
+
type RecordAccess,
|
|
37
|
+
type BusinessMetadata,
|
|
38
|
+
type DataSchemaLike,
|
|
39
|
+
type CurrentUser,
|
|
40
|
+
} from "./permissions.js";
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React SDK 端的权限策略解析。
|
|
3
|
+
*
|
|
4
|
+
* 与服务端 record-access.ts 共享同一策略格式(ownerField / assigneeField / aclField
|
|
5
|
+
* + when 状态条件),用于在前端判断是否展示某个操作按钮。
|
|
6
|
+
*
|
|
7
|
+
* 重要:本模块只用于 UI 展示判断,后端 CRUD API 才是记录级权限的安全边界。
|
|
8
|
+
* 即使前端判断为「可以更新」,后端仍会再次校验。这里只是避免给用户展示无法使用的按钮。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type RecordAction = "read" | "create" | "update" | "delete";
|
|
12
|
+
|
|
13
|
+
export type RecordAccessMode = "ownerField" | "assigneeField" | "aclField" | "authenticated";
|
|
14
|
+
|
|
15
|
+
export interface RecordAccessPolicy {
|
|
16
|
+
mode: RecordAccessMode;
|
|
17
|
+
field?: string;
|
|
18
|
+
when?: Record<string, unknown[]>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RecordAccess {
|
|
22
|
+
read?: RecordAccessPolicy;
|
|
23
|
+
create?: RecordAccessPolicy;
|
|
24
|
+
update?: RecordAccessPolicy;
|
|
25
|
+
delete?: RecordAccessPolicy;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface BusinessMetadata {
|
|
29
|
+
kind?: string;
|
|
30
|
+
ownerField?: string;
|
|
31
|
+
assigneeField?: string;
|
|
32
|
+
aclField?: string;
|
|
33
|
+
statusField?: string;
|
|
34
|
+
statuses?: unknown[];
|
|
35
|
+
transitions?: unknown[];
|
|
36
|
+
recordAccess?: RecordAccess;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DataSchemaLike {
|
|
40
|
+
business?: BusinessMetadata;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CurrentUser {
|
|
44
|
+
id: string;
|
|
45
|
+
name?: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 判断当前用户能否对特定记录执行某操作。
|
|
50
|
+
*
|
|
51
|
+
* - 无策略:返回 true(由后端兜底)
|
|
52
|
+
* - mode=authenticated:登录即可
|
|
53
|
+
* - mode=ownerField/assigneeField/aclField:record[field] 必须等于 user.id
|
|
54
|
+
* - when 中的字段值必须在允许集合内
|
|
55
|
+
*/
|
|
56
|
+
export function checkPermission(
|
|
57
|
+
action: RecordAction,
|
|
58
|
+
record: Record<string, unknown> | null | undefined,
|
|
59
|
+
schema: DataSchemaLike | null | undefined,
|
|
60
|
+
user: CurrentUser | null | undefined,
|
|
61
|
+
): boolean {
|
|
62
|
+
if (!user) return false;
|
|
63
|
+
const policy = schema?.business?.recordAccess?.[action];
|
|
64
|
+
if (!policy) return true;
|
|
65
|
+
|
|
66
|
+
if (policy.mode === "authenticated") return true;
|
|
67
|
+
|
|
68
|
+
const field = policy.field;
|
|
69
|
+
if (!field) return true;
|
|
70
|
+
|
|
71
|
+
if (!record) return false;
|
|
72
|
+
const recordValue = record[field];
|
|
73
|
+
if (recordValue === undefined || recordValue === null) return false;
|
|
74
|
+
if (String(recordValue) !== String(user.id)) return false;
|
|
75
|
+
|
|
76
|
+
if (policy.when) {
|
|
77
|
+
for (const [key, allowed] of Object.entries(policy.when)) {
|
|
78
|
+
if (!Array.isArray(allowed)) continue;
|
|
79
|
+
if (!allowed.includes(record[key])) return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 创建绑定到特定用户的 `can` 函数,便于在 React Hook 中复用。
|
|
87
|
+
*/
|
|
88
|
+
export function createCan(user: CurrentUser | null | undefined) {
|
|
89
|
+
return (
|
|
90
|
+
action: RecordAction,
|
|
91
|
+
record: Record<string, unknown> | null | undefined,
|
|
92
|
+
schema: DataSchemaLike | null | undefined,
|
|
93
|
+
): boolean => checkPermission(action, record, schema, user);
|
|
94
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
checkPermission,
|
|
4
|
+
createCan,
|
|
5
|
+
type RecordAction,
|
|
6
|
+
type RecordAccess,
|
|
7
|
+
type DataSchemaLike,
|
|
8
|
+
type CurrentUser,
|
|
9
|
+
} from "../src/permissions.js";
|
|
10
|
+
|
|
11
|
+
const user: CurrentUser = { id: "u-1", name: "alice" };
|
|
12
|
+
const otherUser: CurrentUser = { id: "u-2", name: "bob" };
|
|
13
|
+
|
|
14
|
+
function schemaWith(recordAccess: RecordAccess): DataSchemaLike {
|
|
15
|
+
return { business: { recordAccess } };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("checkPermission - 无策略", () => {
|
|
19
|
+
it("未登录用户对无策略操作返回 false", () => {
|
|
20
|
+
expect(checkPermission("read", {}, { business: {} }, null)).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("登录用户对无策略操作返回 true(交由后端兜底)", () => {
|
|
24
|
+
expect(checkPermission("read", {}, { business: {} }, user)).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("schema 为 null 时登录用户返回 true", () => {
|
|
28
|
+
expect(checkPermission("read", {}, null, user)).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("checkPermission - authenticated 模式", () => {
|
|
33
|
+
it("登录用户即可执行操作", () => {
|
|
34
|
+
const schema = schemaWith({ read: { mode: "authenticated" } });
|
|
35
|
+
expect(checkPermission("read", {}, schema, user)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("未登录用户不可执行操作", () => {
|
|
39
|
+
const schema = schemaWith({ read: { mode: "authenticated" } });
|
|
40
|
+
expect(checkPermission("read", {}, schema, null)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("checkPermission - ownerField 模式", () => {
|
|
45
|
+
const schema = schemaWith({
|
|
46
|
+
update: { mode: "ownerField", field: "ownerId" },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("记录字段等于当前用户 ID 时允许", () => {
|
|
50
|
+
expect(checkPermission("update", { ownerId: "u-1" }, schema, user)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("记录字段不等于当前用户 ID 时拒绝", () => {
|
|
54
|
+
expect(checkPermission("update", { ownerId: "u-2" }, schema, user)).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("记录字段缺失时拒绝", () => {
|
|
58
|
+
expect(checkPermission("update", {}, schema, user)).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("记录字段为 null 时拒绝", () => {
|
|
62
|
+
expect(checkPermission("update", { ownerId: null }, schema, user)).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("无 record 时拒绝", () => {
|
|
66
|
+
expect(checkPermission("update", null, schema, user)).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("字符串/数字 ID 等价处理", () => {
|
|
70
|
+
const s = schemaWith({ update: { mode: "ownerField", field: "id" } });
|
|
71
|
+
expect(checkPermission("update", { id: 123 }, s, { id: "123", name: null })).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("checkPermission - assigneeField / aclField 模式", () => {
|
|
76
|
+
it("assigneeField 匹配时允许", () => {
|
|
77
|
+
const schema = schemaWith({
|
|
78
|
+
update: { mode: "assigneeField", field: "assigneeId" },
|
|
79
|
+
});
|
|
80
|
+
expect(checkPermission("update", { assigneeId: "u-1" }, schema, user)).toBe(true);
|
|
81
|
+
expect(checkPermission("update", { assigneeId: "u-2" }, schema, user)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("aclField 匹配时允许", () => {
|
|
85
|
+
const schema = schemaWith({
|
|
86
|
+
read: { mode: "aclField", field: "acl" },
|
|
87
|
+
});
|
|
88
|
+
expect(checkPermission("read", { acl: "u-1" }, schema, user)).toBe(true);
|
|
89
|
+
expect(checkPermission("read", { acl: "u-2" }, schema, user)).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("checkPermission - when 状态条件", () => {
|
|
94
|
+
const schema = schemaWith({
|
|
95
|
+
update: {
|
|
96
|
+
mode: "ownerField",
|
|
97
|
+
field: "ownerId",
|
|
98
|
+
when: { status: ["draft"] },
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("记录字段匹配且状态满足条件时允许", () => {
|
|
103
|
+
expect(
|
|
104
|
+
checkPermission("update", { ownerId: "u-1", status: "draft" }, schema, user),
|
|
105
|
+
).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("记录字段匹配但状态不满足时拒绝", () => {
|
|
109
|
+
expect(
|
|
110
|
+
checkPermission("update", { ownerId: "u-1", status: "approved" }, schema, user),
|
|
111
|
+
).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("状态字段缺失时拒绝", () => {
|
|
115
|
+
expect(checkPermission("update", { ownerId: "u-1" }, schema, user)).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("checkPermission - 不同动作独立判断", () => {
|
|
120
|
+
const schema = schemaWith({
|
|
121
|
+
read: { mode: "authenticated" },
|
|
122
|
+
update: { mode: "ownerField", field: "ownerId" },
|
|
123
|
+
delete: { mode: "ownerField", field: "ownerId", when: { status: ["draft"] } },
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("read 用 authenticated 策略", () => {
|
|
127
|
+
expect(checkPermission("read", {}, schema, user)).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("update 用 ownerField 策略", () => {
|
|
131
|
+
expect(checkPermission("update", { ownerId: "u-1" }, schema, user)).toBe(true);
|
|
132
|
+
expect(checkPermission("update", { ownerId: "u-2" }, schema, user)).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("delete 用 ownerField+when 策略", () => {
|
|
136
|
+
expect(
|
|
137
|
+
checkPermission("delete", { ownerId: "u-1", status: "draft" }, schema, user),
|
|
138
|
+
).toBe(true);
|
|
139
|
+
expect(
|
|
140
|
+
checkPermission("delete", { ownerId: "u-1", status: "archived" }, schema, user),
|
|
141
|
+
).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("createCan", () => {
|
|
146
|
+
it("返回绑定到指定用户的 can 函数", () => {
|
|
147
|
+
const can = createCan(user);
|
|
148
|
+
const schema = schemaWith({ update: { mode: "ownerField", field: "ownerId" } });
|
|
149
|
+
expect(can("update", { ownerId: "u-1" }, schema)).toBe(true);
|
|
150
|
+
expect(can("update", { ownerId: "u-2" }, schema)).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("未登录用户对所有者策略一律拒绝", () => {
|
|
154
|
+
const can = createCan(null);
|
|
155
|
+
const schema = schemaWith({ update: { mode: "ownerField", field: "ownerId" } });
|
|
156
|
+
expect(can("update", { ownerId: "u-1" }, schema)).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("未登录用户对 authenticated 策略拒绝", () => {
|
|
160
|
+
const can = createCan(null);
|
|
161
|
+
const schema = schemaWith({ read: { mode: "authenticated" } });
|
|
162
|
+
expect(can("read", {}, schema)).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("undefined 用户视为未登录", () => {
|
|
166
|
+
const can = createCan(undefined);
|
|
167
|
+
expect(can("read", {}, schemaWith({ read: { mode: "authenticated" } }))).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("切换用户后策略判断随之变化", () => {
|
|
171
|
+
const schema = schemaWith({ update: { mode: "ownerField", field: "ownerId" } });
|
|
172
|
+
const record = { ownerId: "u-1" };
|
|
173
|
+
expect(createCan(user)("update", record, schema)).toBe(true);
|
|
174
|
+
expect(createCan(otherUser)("update", record, schema)).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
3
|
+
import { LocalAppError } from "@localapp/sdk";
|
|
4
|
+
|
|
5
|
+
const actionMock = vi.fn();
|
|
6
|
+
|
|
7
|
+
vi.mock("../src/client.js", () => ({
|
|
8
|
+
getClient: () => ({
|
|
9
|
+
action: (...args: unknown[]) => actionMock(...args),
|
|
10
|
+
}),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { useAction } from "../src/index.js";
|
|
14
|
+
|
|
15
|
+
describe("useAction", () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
actionMock.mockReset();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.unstubAllGlobals();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("runs a backend action and exposes loading state", async () => {
|
|
25
|
+
let resolveAction!: (value: { ok: boolean }) => void;
|
|
26
|
+
actionMock.mockReturnValue(new Promise((resolve) => {
|
|
27
|
+
resolveAction = resolve;
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const { result } = renderHook(() => useAction<{ id: number }, { ok: boolean }>("work_items.close"));
|
|
31
|
+
|
|
32
|
+
let promise!: Promise<{ ok: boolean }>;
|
|
33
|
+
act(() => {
|
|
34
|
+
promise = result.current.run({ id: 7 });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result.current.loading).toBe(true);
|
|
38
|
+
expect(actionMock).toHaveBeenCalledWith("work_items.close", { id: 7 });
|
|
39
|
+
|
|
40
|
+
await act(async () => {
|
|
41
|
+
resolveAction({ ok: true });
|
|
42
|
+
await promise;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await waitFor(() => expect(result.current.loading).toBe(false));
|
|
46
|
+
expect(await promise).toEqual({ ok: true });
|
|
47
|
+
expect(result.current.error).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("stores LocalAppError when action fails", async () => {
|
|
51
|
+
const error = new LocalAppError("Access denied", 403);
|
|
52
|
+
actionMock.mockRejectedValue(error);
|
|
53
|
+
|
|
54
|
+
const { result } = renderHook(() => useAction("work_items.close"));
|
|
55
|
+
|
|
56
|
+
await act(async () => {
|
|
57
|
+
await expect(result.current.run({ id: 7 })).rejects.toBe(error);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(result.current.loading).toBe(false);
|
|
61
|
+
expect(result.current.error).toBe(error);
|
|
62
|
+
expect(result.current.error?.status).toBe(403);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { LocalAppError, type PlatformCapabilities } from "@localapp/sdk";
|
|
4
|
+
|
|
5
|
+
const capabilitiesMock = vi.fn();
|
|
6
|
+
|
|
7
|
+
vi.mock("../src/client.js", () => ({
|
|
8
|
+
getClient: () => ({ capabilities: capabilitiesMock }),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
import { useCapabilities } from "../src/index.js";
|
|
12
|
+
|
|
13
|
+
const capabilities = {
|
|
14
|
+
schemaVersion: 1,
|
|
15
|
+
platformVersion: "1.0.0",
|
|
16
|
+
} as PlatformCapabilities;
|
|
17
|
+
|
|
18
|
+
describe("useCapabilities", () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
capabilitiesMock.mockReset();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("loads the platform capability contract", async () => {
|
|
24
|
+
capabilitiesMock.mockResolvedValue(capabilities);
|
|
25
|
+
|
|
26
|
+
const { result } = renderHook(() => useCapabilities());
|
|
27
|
+
|
|
28
|
+
expect(result.current.loading).toBe(true);
|
|
29
|
+
await waitFor(() => expect(result.current.loading).toBe(false));
|
|
30
|
+
expect(result.current.capabilities).toEqual(capabilities);
|
|
31
|
+
expect(result.current.error).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("exposes a retryable error state", async () => {
|
|
35
|
+
capabilitiesMock.mockRejectedValueOnce(new LocalAppError("Unavailable", 503));
|
|
36
|
+
const { result } = renderHook(() => useCapabilities());
|
|
37
|
+
await waitFor(() => expect(result.current.loading).toBe(false));
|
|
38
|
+
|
|
39
|
+
expect(result.current.error).toMatchObject({ message: "Unavailable", status: 503 });
|
|
40
|
+
capabilitiesMock.mockResolvedValueOnce(capabilities);
|
|
41
|
+
await act(async () => {
|
|
42
|
+
await result.current.refresh();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(result.current.capabilities).toEqual(capabilities);
|
|
46
|
+
expect(result.current.error).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
});
|