@useatlas/create 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +231 -0
- package/index.ts +829 -0
- package/package.json +38 -0
- package/templates/docker/.env.example +67 -0
- package/templates/docker/Dockerfile +52 -0
- package/templates/docker/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/docker/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/docker/bin/__tests__/eval.test.ts +434 -0
- package/templates/docker/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/docker/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/docker/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/docker/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/docker/bin/__tests__/query.test.ts +240 -0
- package/templates/docker/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/docker/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/docker/bin/atlas.ts +5044 -0
- package/templates/docker/bin/benchmark.ts +695 -0
- package/templates/docker/bin/enrich.ts +559 -0
- package/templates/docker/bin/eval.ts +770 -0
- package/templates/docker/bin/smoke.ts +438 -0
- package/templates/docker/data/.gitkeep +0 -0
- package/templates/docker/data/cybersec.sql +1961 -0
- package/templates/docker/data/demo-semantic/catalog.yml +40 -0
- package/templates/docker/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/docker/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/docker/data/demo-semantic/entities/people.yml +145 -0
- package/templates/docker/data/demo-semantic/glossary.yml +22 -0
- package/templates/docker/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/docker/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/docker/data/demo.sql +373 -0
- package/templates/docker/data/ecommerce.sql +1690 -0
- package/templates/docker/data/init-demo-db.sql +8 -0
- package/templates/docker/docker-compose.yml +34 -0
- package/templates/docker/docs/deploy.md +390 -0
- package/templates/docker/eslint.config.mjs +18 -0
- package/templates/docker/gitignore +5 -0
- package/templates/docker/next.config.ts +9 -0
- package/templates/docker/package.json +59 -0
- package/templates/docker/postcss.config.mjs +8 -0
- package/templates/docker/public/.gitkeep +0 -0
- package/templates/docker/public/favicon.svg +4 -0
- package/templates/docker/railway.json +13 -0
- package/templates/docker/render.yaml +34 -0
- package/templates/docker/semantic/catalog.yml +5 -0
- package/templates/docker/semantic/entities/.gitkeep +0 -0
- package/templates/docker/semantic/glossary.yml +6 -0
- package/templates/docker/semantic/metrics/.gitkeep +0 -0
- package/templates/docker/sidecar/Dockerfile +28 -0
- package/templates/docker/sidecar/railway.json +14 -0
- package/templates/docker/sidecar/server.ts +188 -0
- package/templates/docker/src/api/__tests__/actions.test.ts +683 -0
- package/templates/docker/src/api/__tests__/admin.test.ts +820 -0
- package/templates/docker/src/api/__tests__/auth.test.ts +165 -0
- package/templates/docker/src/api/__tests__/chat.test.ts +376 -0
- package/templates/docker/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/docker/src/api/__tests__/cors.test.ts +135 -0
- package/templates/docker/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/docker/src/api/__tests__/health.test.ts +261 -0
- package/templates/docker/src/api/__tests__/query.test.ts +891 -0
- package/templates/docker/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/docker/src/api/__tests__/slack.test.ts +847 -0
- package/templates/docker/src/api/index.ts +117 -0
- package/templates/docker/src/api/routes/actions.ts +274 -0
- package/templates/docker/src/api/routes/admin.ts +757 -0
- package/templates/docker/src/api/routes/auth.ts +48 -0
- package/templates/docker/src/api/routes/chat.ts +465 -0
- package/templates/docker/src/api/routes/conversations.ts +266 -0
- package/templates/docker/src/api/routes/health.ts +287 -0
- package/templates/docker/src/api/routes/openapi.ts +390 -0
- package/templates/docker/src/api/routes/query.ts +318 -0
- package/templates/docker/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/docker/src/api/routes/slack.ts +611 -0
- package/templates/docker/src/api/server.ts +226 -0
- package/templates/docker/src/app/api/[...route]/route.ts +33 -0
- package/templates/docker/src/app/error.tsx +24 -0
- package/templates/docker/src/app/globals.css +126 -0
- package/templates/docker/src/app/layout.tsx +19 -0
- package/templates/docker/src/app/page.tsx +14 -0
- package/templates/docker/src/global.d.ts +1 -0
- package/templates/docker/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/docker/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/docker/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/docker/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/docker/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/docker/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/docker/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/docker/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/docker/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/docker/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/docker/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/docker/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/docker/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/docker/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/docker/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/docker/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/docker/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/docker/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/docker/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/docker/src/lib/action-types.ts +95 -0
- package/templates/docker/src/lib/agent-query.ts +178 -0
- package/templates/docker/src/lib/agent.ts +505 -0
- package/templates/docker/src/lib/api-url.ts +2 -0
- package/templates/docker/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/docker/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/docker/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/docker/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/docker/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/docker/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/docker/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/docker/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/docker/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/docker/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/docker/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/docker/src/lib/auth/audit.ts +89 -0
- package/templates/docker/src/lib/auth/byot.ts +158 -0
- package/templates/docker/src/lib/auth/client.ts +35 -0
- package/templates/docker/src/lib/auth/detect.ts +83 -0
- package/templates/docker/src/lib/auth/managed.ts +73 -0
- package/templates/docker/src/lib/auth/middleware.ts +208 -0
- package/templates/docker/src/lib/auth/migrate.ts +111 -0
- package/templates/docker/src/lib/auth/permissions.ts +156 -0
- package/templates/docker/src/lib/auth/server.ts +142 -0
- package/templates/docker/src/lib/auth/simple-key.ts +92 -0
- package/templates/docker/src/lib/auth/types.ts +49 -0
- package/templates/docker/src/lib/config.ts +704 -0
- package/templates/docker/src/lib/conversation-types.ts +29 -0
- package/templates/docker/src/lib/conversations.ts +270 -0
- package/templates/docker/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/docker/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/docker/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/docker/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/docker/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/docker/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/docker/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/docker/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/docker/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/docker/src/lib/db/connection.ts +753 -0
- package/templates/docker/src/lib/db/duckdb.ts +122 -0
- package/templates/docker/src/lib/db/internal.ts +273 -0
- package/templates/docker/src/lib/db/salesforce.ts +342 -0
- package/templates/docker/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/docker/src/lib/errors.ts +154 -0
- package/templates/docker/src/lib/logger.ts +98 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/docker/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/docker/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/docker/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/docker/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/docker/src/lib/plugins/hooks.ts +162 -0
- package/templates/docker/src/lib/plugins/index.ts +9 -0
- package/templates/docker/src/lib/plugins/migrate.ts +309 -0
- package/templates/docker/src/lib/plugins/registry.ts +231 -0
- package/templates/docker/src/lib/plugins/tools.ts +39 -0
- package/templates/docker/src/lib/plugins/wiring.ts +291 -0
- package/templates/docker/src/lib/providers.ts +102 -0
- package/templates/docker/src/lib/rls.ts +321 -0
- package/templates/docker/src/lib/scheduled-task-types.ts +132 -0
- package/templates/docker/src/lib/scheduled-tasks.ts +475 -0
- package/templates/docker/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/docker/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/delivery.ts +248 -0
- package/templates/docker/src/lib/scheduler/engine.ts +317 -0
- package/templates/docker/src/lib/scheduler/executor.ts +73 -0
- package/templates/docker/src/lib/scheduler/format-email.ts +109 -0
- package/templates/docker/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/docker/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/docker/src/lib/scheduler/index.ts +7 -0
- package/templates/docker/src/lib/security.ts +11 -0
- package/templates/docker/src/lib/semantic-index.ts +503 -0
- package/templates/docker/src/lib/semantic.ts +387 -0
- package/templates/docker/src/lib/sidecar-types.ts +16 -0
- package/templates/docker/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/docker/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/docker/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/docker/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/docker/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/docker/src/lib/slack/api.ts +102 -0
- package/templates/docker/src/lib/slack/format.ts +209 -0
- package/templates/docker/src/lib/slack/store.ts +107 -0
- package/templates/docker/src/lib/slack/threads.ts +64 -0
- package/templates/docker/src/lib/slack/verify.ts +71 -0
- package/templates/docker/src/lib/startup.ts +730 -0
- package/templates/docker/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/docker/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/docker/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/docker/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/docker/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/docker/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/docker/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/docker/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/docker/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/docker/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/docker/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/docker/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/docker/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/docker/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/docker/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/docker/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/docker/src/lib/tools/actions/audit.ts +47 -0
- package/templates/docker/src/lib/tools/actions/email.ts +191 -0
- package/templates/docker/src/lib/tools/actions/handler.ts +591 -0
- package/templates/docker/src/lib/tools/actions/index.ts +23 -0
- package/templates/docker/src/lib/tools/actions/jira.ts +220 -0
- package/templates/docker/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/docker/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/docker/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/docker/src/lib/tools/explore.ts +379 -0
- package/templates/docker/src/lib/tools/registry.ts +221 -0
- package/templates/docker/src/lib/tools/salesforce.ts +138 -0
- package/templates/docker/src/lib/tools/soql-validation.ts +172 -0
- package/templates/docker/src/lib/tools/sql.ts +680 -0
- package/templates/docker/src/lib/tracing.ts +40 -0
- package/templates/docker/src/lib/utils.ts +6 -0
- package/templates/docker/src/test-setup.ts +38 -0
- package/templates/docker/src/types/vercel-sandbox.d.ts +54 -0
- package/templates/docker/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/docker/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/docker/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/docker/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/docker/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/docker/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/docker/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/docker/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/docker/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/docker/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/docker/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/docker/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/docker/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/docker/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/docker/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/docker/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/docker/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/docker/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/docker/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/docker/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/docker/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/docker/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/docker/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/docker/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/docker/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/docker/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/docker/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/docker/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/docker/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/docker/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/docker/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/docker/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/docker/src/ui/context.tsx +78 -0
- package/templates/docker/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/docker/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/docker/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/docker/src/ui/lib/action-types.ts +63 -0
- package/templates/docker/src/ui/lib/helpers.ts +104 -0
- package/templates/docker/src/ui/lib/types.ts +145 -0
- package/templates/docker/tsconfig.json +41 -0
- package/templates/docker/vercel.json +3 -0
- package/templates/nextjs-standalone/.env.example +68 -0
- package/templates/nextjs-standalone/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/nextjs-standalone/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/nextjs-standalone/bin/__tests__/eval.test.ts +434 -0
- package/templates/nextjs-standalone/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/nextjs-standalone/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/nextjs-standalone/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/nextjs-standalone/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/nextjs-standalone/bin/__tests__/query.test.ts +240 -0
- package/templates/nextjs-standalone/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/nextjs-standalone/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/nextjs-standalone/bin/atlas.ts +5044 -0
- package/templates/nextjs-standalone/bin/benchmark.ts +695 -0
- package/templates/nextjs-standalone/bin/enrich.ts +559 -0
- package/templates/nextjs-standalone/bin/eval.ts +770 -0
- package/templates/nextjs-standalone/bin/smoke.ts +438 -0
- package/templates/nextjs-standalone/data/.gitkeep +0 -0
- package/templates/nextjs-standalone/data/cybersec.sql +1961 -0
- package/templates/nextjs-standalone/data/demo-semantic/catalog.yml +40 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/people.yml +145 -0
- package/templates/nextjs-standalone/data/demo-semantic/glossary.yml +22 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/nextjs-standalone/data/demo.sql +373 -0
- package/templates/nextjs-standalone/data/ecommerce.sql +1690 -0
- package/templates/nextjs-standalone/data/init-demo-db.sql +8 -0
- package/templates/nextjs-standalone/docs/deploy.md +390 -0
- package/templates/nextjs-standalone/eslint.config.mjs +18 -0
- package/templates/nextjs-standalone/gitignore +5 -0
- package/templates/nextjs-standalone/next.config.ts +10 -0
- package/templates/nextjs-standalone/package.json +63 -0
- package/templates/nextjs-standalone/postcss.config.mjs +8 -0
- package/templates/nextjs-standalone/semantic/catalog.yml +5 -0
- package/templates/nextjs-standalone/semantic/entities/.gitkeep +0 -0
- package/templates/nextjs-standalone/semantic/glossary.yml +6 -0
- package/templates/nextjs-standalone/semantic/metrics/.gitkeep +0 -0
- package/templates/nextjs-standalone/src/api/__tests__/actions.test.ts +683 -0
- package/templates/nextjs-standalone/src/api/__tests__/admin.test.ts +820 -0
- package/templates/nextjs-standalone/src/api/__tests__/auth.test.ts +165 -0
- package/templates/nextjs-standalone/src/api/__tests__/chat.test.ts +376 -0
- package/templates/nextjs-standalone/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/nextjs-standalone/src/api/__tests__/cors.test.ts +135 -0
- package/templates/nextjs-standalone/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/nextjs-standalone/src/api/__tests__/health.test.ts +261 -0
- package/templates/nextjs-standalone/src/api/__tests__/query.test.ts +891 -0
- package/templates/nextjs-standalone/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/nextjs-standalone/src/api/__tests__/slack.test.ts +847 -0
- package/templates/nextjs-standalone/src/api/index.ts +117 -0
- package/templates/nextjs-standalone/src/api/routes/actions.ts +274 -0
- package/templates/nextjs-standalone/src/api/routes/admin.ts +757 -0
- package/templates/nextjs-standalone/src/api/routes/auth.ts +48 -0
- package/templates/nextjs-standalone/src/api/routes/chat.ts +465 -0
- package/templates/nextjs-standalone/src/api/routes/conversations.ts +266 -0
- package/templates/nextjs-standalone/src/api/routes/health.ts +287 -0
- package/templates/nextjs-standalone/src/api/routes/openapi.ts +390 -0
- package/templates/nextjs-standalone/src/api/routes/query.ts +318 -0
- package/templates/nextjs-standalone/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/nextjs-standalone/src/api/routes/slack.ts +611 -0
- package/templates/nextjs-standalone/src/api/server.ts +226 -0
- package/templates/nextjs-standalone/src/app/api/[...route]/route.ts +33 -0
- package/templates/nextjs-standalone/src/app/error.tsx +24 -0
- package/templates/nextjs-standalone/src/app/global-error.tsx +68 -0
- package/templates/nextjs-standalone/src/app/globals.css +126 -0
- package/templates/nextjs-standalone/src/app/layout.tsx +19 -0
- package/templates/nextjs-standalone/src/app/page.tsx +14 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/nextjs-standalone/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/nextjs-standalone/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/nextjs-standalone/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/nextjs-standalone/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/nextjs-standalone/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/nextjs-standalone/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/nextjs-standalone/src/lib/action-types.ts +95 -0
- package/templates/nextjs-standalone/src/lib/agent-query.ts +178 -0
- package/templates/nextjs-standalone/src/lib/agent.ts +505 -0
- package/templates/nextjs-standalone/src/lib/api-url.ts +3 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/nextjs-standalone/src/lib/auth/audit.ts +89 -0
- package/templates/nextjs-standalone/src/lib/auth/byot.ts +158 -0
- package/templates/nextjs-standalone/src/lib/auth/client.ts +23 -0
- package/templates/nextjs-standalone/src/lib/auth/detect.ts +83 -0
- package/templates/nextjs-standalone/src/lib/auth/managed.ts +73 -0
- package/templates/nextjs-standalone/src/lib/auth/middleware.ts +208 -0
- package/templates/nextjs-standalone/src/lib/auth/migrate.ts +111 -0
- package/templates/nextjs-standalone/src/lib/auth/permissions.ts +156 -0
- package/templates/nextjs-standalone/src/lib/auth/server.ts +142 -0
- package/templates/nextjs-standalone/src/lib/auth/simple-key.ts +92 -0
- package/templates/nextjs-standalone/src/lib/auth/types.ts +49 -0
- package/templates/nextjs-standalone/src/lib/config.ts +704 -0
- package/templates/nextjs-standalone/src/lib/conversation-types.ts +29 -0
- package/templates/nextjs-standalone/src/lib/conversations.ts +270 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/nextjs-standalone/src/lib/db/connection.ts +753 -0
- package/templates/nextjs-standalone/src/lib/db/duckdb.ts +122 -0
- package/templates/nextjs-standalone/src/lib/db/internal.ts +273 -0
- package/templates/nextjs-standalone/src/lib/db/salesforce.ts +342 -0
- package/templates/nextjs-standalone/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/nextjs-standalone/src/lib/errors.ts +154 -0
- package/templates/nextjs-standalone/src/lib/logger.ts +98 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/nextjs-standalone/src/lib/plugins/hooks.ts +162 -0
- package/templates/nextjs-standalone/src/lib/plugins/index.ts +9 -0
- package/templates/nextjs-standalone/src/lib/plugins/migrate.ts +309 -0
- package/templates/nextjs-standalone/src/lib/plugins/registry.ts +231 -0
- package/templates/nextjs-standalone/src/lib/plugins/tools.ts +39 -0
- package/templates/nextjs-standalone/src/lib/plugins/wiring.ts +291 -0
- package/templates/nextjs-standalone/src/lib/providers.ts +102 -0
- package/templates/nextjs-standalone/src/lib/rls.ts +321 -0
- package/templates/nextjs-standalone/src/lib/scheduled-task-types.ts +132 -0
- package/templates/nextjs-standalone/src/lib/scheduled-tasks.ts +475 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/delivery.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/engine.ts +317 -0
- package/templates/nextjs-standalone/src/lib/scheduler/executor.ts +73 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-email.ts +109 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/nextjs-standalone/src/lib/scheduler/index.ts +7 -0
- package/templates/nextjs-standalone/src/lib/security.ts +11 -0
- package/templates/nextjs-standalone/src/lib/semantic-index.ts +503 -0
- package/templates/nextjs-standalone/src/lib/semantic.ts +387 -0
- package/templates/nextjs-standalone/src/lib/sidecar-types.ts +16 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/nextjs-standalone/src/lib/slack/api.ts +102 -0
- package/templates/nextjs-standalone/src/lib/slack/format.ts +209 -0
- package/templates/nextjs-standalone/src/lib/slack/store.ts +107 -0
- package/templates/nextjs-standalone/src/lib/slack/threads.ts +64 -0
- package/templates/nextjs-standalone/src/lib/slack/verify.ts +71 -0
- package/templates/nextjs-standalone/src/lib/startup.ts +730 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/audit.ts +47 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/email.ts +191 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/handler.ts +591 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/index.ts +23 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/jira.ts +220 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/nextjs-standalone/src/lib/tools/explore.ts +379 -0
- package/templates/nextjs-standalone/src/lib/tools/registry.ts +221 -0
- package/templates/nextjs-standalone/src/lib/tools/salesforce.ts +138 -0
- package/templates/nextjs-standalone/src/lib/tools/soql-validation.ts +172 -0
- package/templates/nextjs-standalone/src/lib/tools/sql.ts +680 -0
- package/templates/nextjs-standalone/src/lib/tracing.ts +40 -0
- package/templates/nextjs-standalone/src/lib/utils.ts +6 -0
- package/templates/nextjs-standalone/src/test-setup.ts +38 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/nextjs-standalone/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/nextjs-standalone/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/nextjs-standalone/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/nextjs-standalone/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/nextjs-standalone/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/nextjs-standalone/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/nextjs-standalone/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/nextjs-standalone/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/nextjs-standalone/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/nextjs-standalone/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/nextjs-standalone/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/nextjs-standalone/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/nextjs-standalone/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/nextjs-standalone/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/nextjs-standalone/src/ui/context.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/nextjs-standalone/src/ui/lib/action-types.ts +63 -0
- package/templates/nextjs-standalone/src/ui/lib/helpers.ts +104 -0
- package/templates/nextjs-standalone/src/ui/lib/types.ts +145 -0
- package/templates/nextjs-standalone/tsconfig.json +32 -0
- package/templates/nextjs-standalone/vercel.json +4 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for logActionAudit — structured pino logs for action lifecycle events.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach, mock } from "bun:test";
|
|
6
|
+
import type { ActionAuditEntry } from "../audit";
|
|
7
|
+
|
|
8
|
+
// --- Mock the logger ---
|
|
9
|
+
|
|
10
|
+
const mockInfo = mock(() => {});
|
|
11
|
+
const mockWarn = mock(() => {});
|
|
12
|
+
const mockError = mock(() => {});
|
|
13
|
+
|
|
14
|
+
mock.module("@atlas/api/lib/logger", () => ({
|
|
15
|
+
createLogger: () => ({
|
|
16
|
+
info: mockInfo,
|
|
17
|
+
warn: mockWarn,
|
|
18
|
+
error: mockError,
|
|
19
|
+
debug: mock(() => {}),
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
// Import after mocks
|
|
24
|
+
const { logActionAudit } = await import("../audit");
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
mockInfo.mockReset();
|
|
28
|
+
mockWarn.mockReset();
|
|
29
|
+
mockError.mockReset();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("logActionAudit()", () => {
|
|
33
|
+
// -------------------------------------------------------------------------
|
|
34
|
+
// Log level routing by status
|
|
35
|
+
// -------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
it("calls log.error for status 'failed'", () => {
|
|
38
|
+
logActionAudit({
|
|
39
|
+
actionId: "a1",
|
|
40
|
+
actionType: "test:action",
|
|
41
|
+
status: "failed",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(mockError).toHaveBeenCalledTimes(1);
|
|
45
|
+
expect(mockInfo).not.toHaveBeenCalled();
|
|
46
|
+
expect(mockWarn).not.toHaveBeenCalled();
|
|
47
|
+
|
|
48
|
+
const [fields, message] = mockError.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
49
|
+
expect(message).toBe("action_failed");
|
|
50
|
+
expect(fields.actionId).toBe("a1");
|
|
51
|
+
expect(fields.status).toBe("failed");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("calls log.warn for status 'denied'", () => {
|
|
55
|
+
logActionAudit({
|
|
56
|
+
actionId: "a2",
|
|
57
|
+
actionType: "test:action",
|
|
58
|
+
status: "denied",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(mockWarn).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(mockInfo).not.toHaveBeenCalled();
|
|
63
|
+
expect(mockError).not.toHaveBeenCalled();
|
|
64
|
+
|
|
65
|
+
const [, message] = mockWarn.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
66
|
+
expect(message).toBe("action_denied");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("calls log.info for status 'executed'", () => {
|
|
70
|
+
logActionAudit({
|
|
71
|
+
actionId: "a3",
|
|
72
|
+
actionType: "test:action",
|
|
73
|
+
status: "executed",
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(mockInfo).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(mockWarn).not.toHaveBeenCalled();
|
|
78
|
+
expect(mockError).not.toHaveBeenCalled();
|
|
79
|
+
|
|
80
|
+
const [, message] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
81
|
+
expect(message).toBe("action_executed");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("calls log.info for status 'pending'", () => {
|
|
85
|
+
logActionAudit({
|
|
86
|
+
actionId: "a4",
|
|
87
|
+
actionType: "test:action",
|
|
88
|
+
status: "pending",
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(mockInfo).toHaveBeenCalledTimes(1);
|
|
92
|
+
const [, message] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
93
|
+
expect(message).toBe("action_pending");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("calls log.info for status 'auto_approved'", () => {
|
|
97
|
+
logActionAudit({
|
|
98
|
+
actionId: "a5",
|
|
99
|
+
actionType: "test:action",
|
|
100
|
+
status: "auto_approved",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(mockInfo).toHaveBeenCalledTimes(1);
|
|
104
|
+
const [, message] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
105
|
+
expect(message).toBe("action_auto_approved");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("calls log.info for status 'approved'", () => {
|
|
109
|
+
logActionAudit({
|
|
110
|
+
actionId: "a6",
|
|
111
|
+
actionType: "test:action",
|
|
112
|
+
status: "approved",
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(mockInfo).toHaveBeenCalledTimes(1);
|
|
116
|
+
const [, message] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
117
|
+
expect(message).toBe("action_approved");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// -------------------------------------------------------------------------
|
|
121
|
+
// Optional fields inclusion
|
|
122
|
+
// -------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
it("includes latencyMs when provided", () => {
|
|
125
|
+
logActionAudit({
|
|
126
|
+
actionId: "a7",
|
|
127
|
+
actionType: "test:action",
|
|
128
|
+
status: "executed",
|
|
129
|
+
latencyMs: 150,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const [fields] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
133
|
+
expect(fields.latencyMs).toBe(150);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("includes userId when provided", () => {
|
|
137
|
+
logActionAudit({
|
|
138
|
+
actionId: "a8",
|
|
139
|
+
actionType: "test:action",
|
|
140
|
+
status: "pending",
|
|
141
|
+
userId: "user-123",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const [fields] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
145
|
+
expect(fields.userId).toBe("user-123");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("includes approverId when provided", () => {
|
|
149
|
+
logActionAudit({
|
|
150
|
+
actionId: "a9",
|
|
151
|
+
actionType: "test:action",
|
|
152
|
+
status: "approved",
|
|
153
|
+
approverId: "admin-1",
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const [fields] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
157
|
+
expect(fields.approverId).toBe("admin-1");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("includes error when provided", () => {
|
|
161
|
+
logActionAudit({
|
|
162
|
+
actionId: "a10",
|
|
163
|
+
actionType: "test:action",
|
|
164
|
+
status: "failed",
|
|
165
|
+
error: "Connection refused",
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const [fields] = mockError.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
169
|
+
expect(fields.error).toBe("Connection refused");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("omits optional fields when not provided", () => {
|
|
173
|
+
logActionAudit({
|
|
174
|
+
actionId: "a11",
|
|
175
|
+
actionType: "test:action",
|
|
176
|
+
status: "pending",
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const [fields] = mockInfo.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
180
|
+
expect(fields.actionId).toBe("a11");
|
|
181
|
+
expect(fields.actionType).toBe("test:action");
|
|
182
|
+
expect(fields.status).toBe("pending");
|
|
183
|
+
expect("latencyMs" in fields).toBe(false);
|
|
184
|
+
expect("userId" in fields).toBe(false);
|
|
185
|
+
expect("approverId" in fields).toBe(false);
|
|
186
|
+
expect("error" in fields).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("includes all optional fields when all are provided", () => {
|
|
190
|
+
const entry: ActionAuditEntry = {
|
|
191
|
+
actionId: "a12",
|
|
192
|
+
actionType: "test:action",
|
|
193
|
+
status: "failed",
|
|
194
|
+
latencyMs: 250,
|
|
195
|
+
userId: "user-456",
|
|
196
|
+
approverId: "admin-2",
|
|
197
|
+
error: "Timeout",
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
logActionAudit(entry);
|
|
201
|
+
|
|
202
|
+
const [fields] = mockError.mock.calls[0] as unknown as [Record<string, unknown>, string];
|
|
203
|
+
expect(fields.actionId).toBe("a12");
|
|
204
|
+
expect(fields.actionType).toBe("test:action");
|
|
205
|
+
expect(fields.status).toBe("failed");
|
|
206
|
+
expect(fields.latencyMs).toBe(250);
|
|
207
|
+
expect(fields.userId).toBe("user-456");
|
|
208
|
+
expect(fields.approverId).toBe("admin-2");
|
|
209
|
+
expect(fields.error).toBe("Timeout");
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, mock } from "bun:test";
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Mock handler module so we don't hit real DB / auth
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
let lastHandleActionCall: { request: unknown; executeFn: unknown } | null = null;
|
|
8
|
+
|
|
9
|
+
mock.module("@atlas/api/lib/tools/actions/handler", () => ({
|
|
10
|
+
buildActionRequest: (params: Record<string, unknown>) => ({
|
|
11
|
+
id: "test-action-id",
|
|
12
|
+
...params,
|
|
13
|
+
}),
|
|
14
|
+
handleAction: async (request: unknown, executeFn: unknown) => {
|
|
15
|
+
lastHandleActionCall = { request, executeFn };
|
|
16
|
+
return { status: "pending_approval", actionId: "test-action-id", summary: "test" };
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
mock.module("@atlas/api/lib/logger", () => ({
|
|
21
|
+
createLogger: () => ({
|
|
22
|
+
info: () => {},
|
|
23
|
+
warn: () => {},
|
|
24
|
+
error: () => {},
|
|
25
|
+
debug: () => {},
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const { executeEmailSend, sendEmailReport } = await import(
|
|
30
|
+
"@atlas/api/lib/tools/actions/email"
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Env snapshot + fetch mock
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
const ENV_KEYS = [
|
|
38
|
+
"RESEND_API_KEY",
|
|
39
|
+
"ATLAS_EMAIL_FROM",
|
|
40
|
+
"ATLAS_EMAIL_ALLOWED_DOMAINS",
|
|
41
|
+
] as const;
|
|
42
|
+
|
|
43
|
+
const saved: Record<string, string | undefined> = {};
|
|
44
|
+
const originalFetch = globalThis.fetch;
|
|
45
|
+
|
|
46
|
+
let capturedFetchUrl = "";
|
|
47
|
+
let capturedFetchInit: RequestInit | undefined;
|
|
48
|
+
|
|
49
|
+
function installFetchMock(
|
|
50
|
+
response: { status: number; body: unknown },
|
|
51
|
+
) {
|
|
52
|
+
globalThis.fetch = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
53
|
+
capturedFetchUrl = typeof input === "string" ? input : (input as Request).url;
|
|
54
|
+
capturedFetchInit = init;
|
|
55
|
+
return new Response(JSON.stringify(response.body), {
|
|
56
|
+
status: response.status,
|
|
57
|
+
headers: { "Content-Type": "application/json" },
|
|
58
|
+
});
|
|
59
|
+
}) as typeof globalThis.fetch;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
beforeEach(() => {
|
|
63
|
+
for (const key of ENV_KEYS) saved[key] = process.env[key];
|
|
64
|
+
lastHandleActionCall = null;
|
|
65
|
+
capturedFetchUrl = "";
|
|
66
|
+
capturedFetchInit = undefined;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
globalThis.fetch = originalFetch;
|
|
71
|
+
for (const key of ENV_KEYS) {
|
|
72
|
+
if (saved[key] !== undefined) process.env[key] = saved[key];
|
|
73
|
+
else delete process.env[key];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// AtlasAction metadata
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
describe("sendEmailReport — metadata", () => {
|
|
82
|
+
it("has the correct actionType", () => {
|
|
83
|
+
expect(sendEmailReport.actionType).toBe("email:send");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("is not reversible", () => {
|
|
87
|
+
expect(sendEmailReport.reversible).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("defaults to admin-only approval", () => {
|
|
91
|
+
expect(sendEmailReport.defaultApproval).toBe("admin-only");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("requires RESEND_API_KEY", () => {
|
|
95
|
+
expect(sendEmailReport.requiredCredentials).toEqual(["RESEND_API_KEY"]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("has a name", () => {
|
|
99
|
+
expect(sendEmailReport.name).toBe("sendEmailReport");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("has a description", () => {
|
|
103
|
+
expect(sendEmailReport.description).toBeTruthy();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
// executeEmailSend — raw API call
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
describe("executeEmailSend", () => {
|
|
112
|
+
it("throws when RESEND_API_KEY is missing", async () => {
|
|
113
|
+
delete process.env.RESEND_API_KEY;
|
|
114
|
+
|
|
115
|
+
await expect(
|
|
116
|
+
executeEmailSend({
|
|
117
|
+
to: "user@example.com",
|
|
118
|
+
subject: "Test",
|
|
119
|
+
body: "<p>Hello</p>",
|
|
120
|
+
}),
|
|
121
|
+
).rejects.toThrow("Missing RESEND_API_KEY");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("calls Resend API with correct params", async () => {
|
|
125
|
+
process.env.RESEND_API_KEY = "re_test_123";
|
|
126
|
+
process.env.ATLAS_EMAIL_FROM = "Reports <reports@company.com>";
|
|
127
|
+
|
|
128
|
+
installFetchMock({ status: 200, body: { id: "email-id-123" } });
|
|
129
|
+
|
|
130
|
+
const result = await executeEmailSend({
|
|
131
|
+
to: ["alice@example.com", "bob@example.com"],
|
|
132
|
+
subject: "Weekly Report",
|
|
133
|
+
body: "<h1>Report</h1><p>Data here</p>",
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(capturedFetchUrl).toBe("https://api.resend.com/emails");
|
|
137
|
+
expect(capturedFetchInit?.method).toBe("POST");
|
|
138
|
+
|
|
139
|
+
// Check auth header
|
|
140
|
+
expect(
|
|
141
|
+
(capturedFetchInit?.headers as Record<string, string>)?.Authorization,
|
|
142
|
+
).toBe("Bearer re_test_123");
|
|
143
|
+
|
|
144
|
+
// Check body
|
|
145
|
+
const body = JSON.parse(capturedFetchInit?.body as string);
|
|
146
|
+
expect(body.from).toBe("Reports <reports@company.com>");
|
|
147
|
+
expect(body.to).toEqual(["alice@example.com", "bob@example.com"]);
|
|
148
|
+
expect(body.subject).toBe("Weekly Report");
|
|
149
|
+
expect(body.html).toBe("<h1>Report</h1><p>Data here</p>");
|
|
150
|
+
|
|
151
|
+
expect(result.id).toBe("email-id-123");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("uses default from address when ATLAS_EMAIL_FROM is not set", async () => {
|
|
155
|
+
process.env.RESEND_API_KEY = "re_test_123";
|
|
156
|
+
delete process.env.ATLAS_EMAIL_FROM;
|
|
157
|
+
|
|
158
|
+
installFetchMock({ status: 200, body: { id: "email-id-456" } });
|
|
159
|
+
|
|
160
|
+
await executeEmailSend({
|
|
161
|
+
to: "user@example.com",
|
|
162
|
+
subject: "Test",
|
|
163
|
+
body: "<p>Hello</p>",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const body = JSON.parse(capturedFetchInit?.body as string);
|
|
167
|
+
expect(body.from).toContain("Atlas");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("normalizes string recipient to array", async () => {
|
|
171
|
+
process.env.RESEND_API_KEY = "re_test_123";
|
|
172
|
+
|
|
173
|
+
installFetchMock({ status: 200, body: { id: "email-id-789" } });
|
|
174
|
+
|
|
175
|
+
await executeEmailSend({
|
|
176
|
+
to: "single@example.com",
|
|
177
|
+
subject: "Test",
|
|
178
|
+
body: "<p>Hello</p>",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const body = JSON.parse(capturedFetchInit?.body as string);
|
|
182
|
+
expect(body.to).toEqual(["single@example.com"]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("throws on API error without exposing API key", async () => {
|
|
186
|
+
process.env.RESEND_API_KEY = "re_secret_key_123";
|
|
187
|
+
|
|
188
|
+
installFetchMock({
|
|
189
|
+
status: 422,
|
|
190
|
+
body: { message: "Invalid recipient address" },
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
await executeEmailSend({
|
|
195
|
+
to: "user@example.com",
|
|
196
|
+
subject: "Test",
|
|
197
|
+
body: "<p>Hello</p>",
|
|
198
|
+
});
|
|
199
|
+
expect(true).toBe(false); // should not reach here
|
|
200
|
+
} catch (err) {
|
|
201
|
+
const message = (err as Error).message;
|
|
202
|
+
expect(message).toContain("Resend API error");
|
|
203
|
+
expect(message).toContain("Invalid recipient");
|
|
204
|
+
// Must not contain secrets
|
|
205
|
+
expect(message).not.toContain("re_secret_key_123");
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("handles non-JSON error responses", async () => {
|
|
210
|
+
process.env.RESEND_API_KEY = "re_test_123";
|
|
211
|
+
|
|
212
|
+
globalThis.fetch = (async () => {
|
|
213
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
214
|
+
}) as unknown as typeof globalThis.fetch;
|
|
215
|
+
|
|
216
|
+
await expect(
|
|
217
|
+
executeEmailSend({ to: "user@example.com", subject: "Test", body: "<p>Hi</p>" }),
|
|
218
|
+
).rejects.toThrow("HTTP 500");
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
// Domain allowlist
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
|
|
226
|
+
describe("sendEmailReport — domain allowlist", () => {
|
|
227
|
+
it("blocks email to disallowed domain", async () => {
|
|
228
|
+
process.env.ATLAS_EMAIL_ALLOWED_DOMAINS = "company.com,partner.com";
|
|
229
|
+
|
|
230
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
231
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const result = (await aiTool.execute(
|
|
235
|
+
{ to: "user@blocked.com", subject: "Test", body: "<p>Hi</p>" },
|
|
236
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
237
|
+
)) as { status: string; error?: string };
|
|
238
|
+
|
|
239
|
+
expect(result.status).toBe("error");
|
|
240
|
+
expect(result.error).toContain("not allowed");
|
|
241
|
+
expect(result.error).toContain("blocked.com");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("allows email to permitted domain", async () => {
|
|
245
|
+
process.env.ATLAS_EMAIL_ALLOWED_DOMAINS = "company.com,partner.com";
|
|
246
|
+
|
|
247
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
248
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const result = (await aiTool.execute(
|
|
252
|
+
{ to: "alice@company.com", subject: "Test", body: "<p>Hi</p>" },
|
|
253
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
254
|
+
)) as { status: string };
|
|
255
|
+
|
|
256
|
+
expect(result.status).toBe("pending_approval");
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("allows any domain when ATLAS_EMAIL_ALLOWED_DOMAINS is not set", async () => {
|
|
260
|
+
delete process.env.ATLAS_EMAIL_ALLOWED_DOMAINS;
|
|
261
|
+
|
|
262
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
263
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const result = (await aiTool.execute(
|
|
267
|
+
{ to: "anyone@anywhere.com", subject: "Test", body: "<p>Hi</p>" },
|
|
268
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
269
|
+
)) as { status: string };
|
|
270
|
+
|
|
271
|
+
expect(result.status).toBe("pending_approval");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("blocks malformed email addresses without @ sign", async () => {
|
|
275
|
+
process.env.ATLAS_EMAIL_ALLOWED_DOMAINS = "company.com";
|
|
276
|
+
|
|
277
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
278
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const result = (await aiTool.execute(
|
|
282
|
+
{ to: "notanemail", subject: "Test", body: "<p>Hi</p>" },
|
|
283
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
284
|
+
)) as { status: string; error?: string };
|
|
285
|
+
|
|
286
|
+
expect(result.status).toBe("error");
|
|
287
|
+
expect(result.error).toContain("not allowed");
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("extracts domain from display-name format addresses", async () => {
|
|
291
|
+
process.env.ATLAS_EMAIL_ALLOWED_DOMAINS = "company.com";
|
|
292
|
+
|
|
293
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
294
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const result = (await aiTool.execute(
|
|
298
|
+
{ to: "User <user@company.com>", subject: "Test", body: "<p>Hi</p>" },
|
|
299
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
300
|
+
)) as { status: string };
|
|
301
|
+
|
|
302
|
+
expect(result.status).toBe("pending_approval");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("blocks mixed recipients where some are disallowed", async () => {
|
|
306
|
+
process.env.ATLAS_EMAIL_ALLOWED_DOMAINS = "company.com";
|
|
307
|
+
|
|
308
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
309
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const result = (await aiTool.execute(
|
|
313
|
+
{
|
|
314
|
+
to: ["good@company.com", "bad@external.com"],
|
|
315
|
+
subject: "Test",
|
|
316
|
+
body: "<p>Hi</p>",
|
|
317
|
+
},
|
|
318
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
319
|
+
)) as { status: string; error?: string };
|
|
320
|
+
|
|
321
|
+
expect(result.status).toBe("error");
|
|
322
|
+
expect(result.error).toContain("bad@external.com");
|
|
323
|
+
expect(result.error).not.toContain("good@company.com");
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// ---------------------------------------------------------------------------
|
|
328
|
+
// Tool execute — integration with handleAction
|
|
329
|
+
// ---------------------------------------------------------------------------
|
|
330
|
+
|
|
331
|
+
describe("sendEmailReport — tool execute", () => {
|
|
332
|
+
it("calls handleAction with correct actionType and payload", async () => {
|
|
333
|
+
delete process.env.ATLAS_EMAIL_ALLOWED_DOMAINS;
|
|
334
|
+
|
|
335
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
336
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
await aiTool.execute(
|
|
340
|
+
{
|
|
341
|
+
to: "user@example.com",
|
|
342
|
+
subject: "Report",
|
|
343
|
+
body: "<p>Data</p>",
|
|
344
|
+
},
|
|
345
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
expect(lastHandleActionCall).not.toBeNull();
|
|
349
|
+
const request = lastHandleActionCall!.request as Record<string, unknown>;
|
|
350
|
+
expect(request.actionType).toBe("email:send");
|
|
351
|
+
expect(request.target).toBe("user@example.com");
|
|
352
|
+
expect(request.reversible).toBe(false);
|
|
353
|
+
expect((request.payload as Record<string, unknown>).subject).toBe("Report");
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
// Zod schema — empty recipient array
|
|
359
|
+
// ---------------------------------------------------------------------------
|
|
360
|
+
|
|
361
|
+
describe("sendEmailReport — schema validation", () => {
|
|
362
|
+
it("rejects empty recipient array via Zod min(1)", async () => {
|
|
363
|
+
delete process.env.ATLAS_EMAIL_ALLOWED_DOMAINS;
|
|
364
|
+
|
|
365
|
+
const aiTool = sendEmailReport.tool as unknown as {
|
|
366
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
367
|
+
parameters: { parse: (input: unknown) => unknown };
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
expect(() => {
|
|
371
|
+
aiTool.parameters.parse({
|
|
372
|
+
to: [],
|
|
373
|
+
subject: "Test",
|
|
374
|
+
body: "<p>Hi</p>",
|
|
375
|
+
});
|
|
376
|
+
}).toThrow();
|
|
377
|
+
});
|
|
378
|
+
});
|