@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,435 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { Parser } from "node-sql-parser";
|
|
3
|
+
import {
|
|
4
|
+
resolveClaimPath,
|
|
5
|
+
resolveRLSFilters,
|
|
6
|
+
injectRLSConditions,
|
|
7
|
+
} from "@atlas/api/lib/rls";
|
|
8
|
+
import type { RLSConfig } from "@atlas/api/lib/config";
|
|
9
|
+
import type { AtlasUser } from "@atlas/api/lib/auth/types";
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// resolveClaimPath
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
describe("resolveClaimPath", () => {
|
|
16
|
+
it("resolves a flat claim", () => {
|
|
17
|
+
expect(resolveClaimPath({ tenant_id: "acme" }, "tenant_id")).toBe("acme");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("resolves a nested claim", () => {
|
|
21
|
+
expect(
|
|
22
|
+
resolveClaimPath({ app: { tenant: "acme" } }, "app.tenant"),
|
|
23
|
+
).toBe("acme");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("resolves a deeply nested claim", () => {
|
|
27
|
+
expect(
|
|
28
|
+
resolveClaimPath({ a: { b: { c: "val" } } }, "a.b.c"),
|
|
29
|
+
).toBe("val");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("returns undefined for missing path", () => {
|
|
33
|
+
expect(resolveClaimPath({ x: 1 }, "y")).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("returns undefined for partial path", () => {
|
|
37
|
+
expect(resolveClaimPath({ a: { b: 1 } }, "a.c")).toBeUndefined();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("returns undefined when intermediate is null", () => {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
expect(resolveClaimPath({ a: null } as Record<string, any>, "a.b")).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("returns non-string values", () => {
|
|
46
|
+
expect(resolveClaimPath({ count: 42 }, "count")).toBe(42);
|
|
47
|
+
expect(resolveClaimPath({ flag: true }, "flag")).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// resolveRLSFilters
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
describe("resolveRLSFilters", () => {
|
|
56
|
+
const config: RLSConfig = {
|
|
57
|
+
enabled: true,
|
|
58
|
+
policies: [
|
|
59
|
+
{ tables: ["*"], column: "tenant_id", claim: "tenant_id" },
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const user: AtlasUser = {
|
|
64
|
+
id: "user-1",
|
|
65
|
+
mode: "byot",
|
|
66
|
+
label: "test@example.com",
|
|
67
|
+
claims: { tenant_id: "acme", sub: "user-1" },
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
it("wildcard policy matches all queried tables", () => {
|
|
71
|
+
const result = resolveRLSFilters(
|
|
72
|
+
user,
|
|
73
|
+
new Set(["orders", "customers"]),
|
|
74
|
+
config,
|
|
75
|
+
);
|
|
76
|
+
expect("filters" in result).toBe(true);
|
|
77
|
+
if ("filters" in result) {
|
|
78
|
+
expect(result.filters).toHaveLength(2);
|
|
79
|
+
expect(result.filters.map((f) => f.table).sort()).toEqual(["customers", "orders"]);
|
|
80
|
+
expect(result.filters[0].column).toBe("tenant_id");
|
|
81
|
+
expect(result.filters[0].value).toBe("acme");
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("specific table policy matches only named tables", () => {
|
|
86
|
+
const specificConfig: RLSConfig = {
|
|
87
|
+
enabled: true,
|
|
88
|
+
policies: [
|
|
89
|
+
{ tables: ["orders"], column: "tenant_id", claim: "tenant_id" },
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
const result = resolveRLSFilters(
|
|
93
|
+
user,
|
|
94
|
+
new Set(["orders", "customers"]),
|
|
95
|
+
specificConfig,
|
|
96
|
+
);
|
|
97
|
+
expect("filters" in result).toBe(true);
|
|
98
|
+
if ("filters" in result) {
|
|
99
|
+
expect(result.filters).toHaveLength(1);
|
|
100
|
+
expect(result.filters[0].table).toBe("orders");
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("no match when policy tables not in query", () => {
|
|
105
|
+
const specificConfig: RLSConfig = {
|
|
106
|
+
enabled: true,
|
|
107
|
+
policies: [
|
|
108
|
+
{ tables: ["invoices"], column: "tenant_id", claim: "tenant_id" },
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
const result = resolveRLSFilters(
|
|
112
|
+
user,
|
|
113
|
+
new Set(["orders", "customers"]),
|
|
114
|
+
specificConfig,
|
|
115
|
+
);
|
|
116
|
+
expect("filters" in result).toBe(true);
|
|
117
|
+
if ("filters" in result) {
|
|
118
|
+
expect(result.filters).toHaveLength(0);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("returns error when user is undefined", () => {
|
|
123
|
+
const result = resolveRLSFilters(undefined, new Set(["orders"]), config);
|
|
124
|
+
expect("error" in result).toBe(true);
|
|
125
|
+
if ("error" in result) {
|
|
126
|
+
expect(result.error).toContain("no authenticated user");
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("returns error when user has no claims", () => {
|
|
131
|
+
const noClaimsUser: AtlasUser = {
|
|
132
|
+
id: "user-1",
|
|
133
|
+
mode: "simple-key",
|
|
134
|
+
label: "api-key-test",
|
|
135
|
+
};
|
|
136
|
+
const result = resolveRLSFilters(noClaimsUser, new Set(["orders"]), config);
|
|
137
|
+
expect("error" in result).toBe(true);
|
|
138
|
+
if ("error" in result) {
|
|
139
|
+
expect(result.error).toContain("no claims");
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("returns error when required claim is missing (fail-closed)", () => {
|
|
144
|
+
const missingClaimUser: AtlasUser = {
|
|
145
|
+
id: "user-1",
|
|
146
|
+
mode: "byot",
|
|
147
|
+
label: "test@example.com",
|
|
148
|
+
claims: { sub: "user-1" }, // no tenant_id
|
|
149
|
+
};
|
|
150
|
+
const result = resolveRLSFilters(
|
|
151
|
+
missingClaimUser,
|
|
152
|
+
new Set(["orders"]),
|
|
153
|
+
config,
|
|
154
|
+
);
|
|
155
|
+
expect("error" in result).toBe(true);
|
|
156
|
+
if ("error" in result) {
|
|
157
|
+
expect(result.error).toContain('claim "tenant_id"');
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("supports dot-path claim extraction", () => {
|
|
162
|
+
const nestedConfig: RLSConfig = {
|
|
163
|
+
enabled: true,
|
|
164
|
+
policies: [
|
|
165
|
+
{ tables: ["*"], column: "org_id", claim: "app_metadata.org_id" },
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
const nestedUser: AtlasUser = {
|
|
169
|
+
id: "user-1",
|
|
170
|
+
mode: "byot",
|
|
171
|
+
label: "test",
|
|
172
|
+
claims: { app_metadata: { org_id: "org-42" } },
|
|
173
|
+
};
|
|
174
|
+
const result = resolveRLSFilters(
|
|
175
|
+
nestedUser,
|
|
176
|
+
new Set(["orders"]),
|
|
177
|
+
nestedConfig,
|
|
178
|
+
);
|
|
179
|
+
expect("filters" in result).toBe(true);
|
|
180
|
+
if ("filters" in result) {
|
|
181
|
+
expect(result.filters[0].value).toBe("org-42");
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("deduplicates table/column pairs", () => {
|
|
186
|
+
const dupeConfig: RLSConfig = {
|
|
187
|
+
enabled: true,
|
|
188
|
+
policies: [
|
|
189
|
+
{ tables: ["*"], column: "tenant_id", claim: "tenant_id" },
|
|
190
|
+
{ tables: ["orders"], column: "tenant_id", claim: "tenant_id" },
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
const result = resolveRLSFilters(
|
|
194
|
+
user,
|
|
195
|
+
new Set(["orders"]),
|
|
196
|
+
dupeConfig,
|
|
197
|
+
);
|
|
198
|
+
expect("filters" in result).toBe(true);
|
|
199
|
+
if ("filters" in result) {
|
|
200
|
+
expect(result.filters).toHaveLength(1);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("escapes single quotes in claim values", () => {
|
|
205
|
+
const quoteUser: AtlasUser = {
|
|
206
|
+
id: "user-1",
|
|
207
|
+
mode: "byot",
|
|
208
|
+
label: "test",
|
|
209
|
+
claims: { tenant_id: "O'Brien" },
|
|
210
|
+
};
|
|
211
|
+
const result = resolveRLSFilters(
|
|
212
|
+
quoteUser,
|
|
213
|
+
new Set(["orders"]),
|
|
214
|
+
config,
|
|
215
|
+
);
|
|
216
|
+
expect("filters" in result).toBe(true);
|
|
217
|
+
if ("filters" in result) {
|
|
218
|
+
expect(result.filters[0].value).toBe("O''Brien");
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("multiple policies with different claims", () => {
|
|
223
|
+
const multiConfig: RLSConfig = {
|
|
224
|
+
enabled: true,
|
|
225
|
+
policies: [
|
|
226
|
+
{ tables: ["*"], column: "tenant_id", claim: "tenant_id" },
|
|
227
|
+
{ tables: ["users"], column: "id", claim: "sub" },
|
|
228
|
+
],
|
|
229
|
+
};
|
|
230
|
+
const result = resolveRLSFilters(
|
|
231
|
+
user,
|
|
232
|
+
new Set(["users", "orders"]),
|
|
233
|
+
multiConfig,
|
|
234
|
+
);
|
|
235
|
+
expect("filters" in result).toBe(true);
|
|
236
|
+
if ("filters" in result) {
|
|
237
|
+
// orders gets tenant_id filter, users gets both tenant_id and id filter
|
|
238
|
+
expect(result.filters).toHaveLength(3);
|
|
239
|
+
const usersFilters = result.filters.filter((f) => f.table === "users");
|
|
240
|
+
expect(usersFilters).toHaveLength(2);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("table matching is case-insensitive", () => {
|
|
245
|
+
const upperConfig: RLSConfig = {
|
|
246
|
+
enabled: true,
|
|
247
|
+
policies: [
|
|
248
|
+
{ tables: ["Orders"], column: "tenant_id", claim: "tenant_id" },
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
const result = resolveRLSFilters(
|
|
252
|
+
user,
|
|
253
|
+
new Set(["orders"]),
|
|
254
|
+
upperConfig,
|
|
255
|
+
);
|
|
256
|
+
expect("filters" in result).toBe(true);
|
|
257
|
+
if ("filters" in result) {
|
|
258
|
+
expect(result.filters).toHaveLength(1);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
// injectRLSConditions
|
|
265
|
+
// ---------------------------------------------------------------------------
|
|
266
|
+
|
|
267
|
+
describe("injectRLSConditions", () => {
|
|
268
|
+
const filter = (table: string, column = "tenant_id", value = "acme"): {
|
|
269
|
+
table: string;
|
|
270
|
+
column: string;
|
|
271
|
+
value: string;
|
|
272
|
+
} => ({ table, column, value });
|
|
273
|
+
|
|
274
|
+
it("injects WHERE into a simple SELECT with no existing WHERE", () => {
|
|
275
|
+
const sql = "SELECT * FROM orders";
|
|
276
|
+
const result = injectRLSConditions(sql, [filter("orders")], "postgres");
|
|
277
|
+
expect(result.toLowerCase()).toContain("where");
|
|
278
|
+
expect(result).toContain("tenant_id");
|
|
279
|
+
expect(result).toContain("acme");
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("AND-merges with an existing WHERE clause", () => {
|
|
283
|
+
const sql = "SELECT * FROM orders WHERE status = 'active'";
|
|
284
|
+
const result = injectRLSConditions(sql, [filter("orders")], "postgres");
|
|
285
|
+
expect(result.toLowerCase()).toContain("and");
|
|
286
|
+
expect(result).toContain("tenant_id");
|
|
287
|
+
expect(result).toContain("active");
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("uses table alias in the injected condition", () => {
|
|
291
|
+
const sql = "SELECT o.id FROM orders o WHERE o.status = 'active'";
|
|
292
|
+
const result = injectRLSConditions(sql, [filter("orders")], "postgres");
|
|
293
|
+
// The condition should reference the alias 'o', not the table name 'orders'
|
|
294
|
+
expect(result).toContain("o");
|
|
295
|
+
expect(result).toContain("tenant_id");
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("injects into multiple joined tables", () => {
|
|
299
|
+
const sql = "SELECT o.id, c.name FROM orders o JOIN customers c ON o.customer_id = c.id";
|
|
300
|
+
const result = injectRLSConditions(
|
|
301
|
+
sql,
|
|
302
|
+
[filter("orders"), filter("customers")],
|
|
303
|
+
"postgres",
|
|
304
|
+
);
|
|
305
|
+
expect(result).toContain("tenant_id");
|
|
306
|
+
// Both tables should be filtered
|
|
307
|
+
const lowerResult = result.toLowerCase();
|
|
308
|
+
expect(lowerResult).toContain("where");
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("returns SQL unchanged when no filters match", () => {
|
|
312
|
+
const sql = "SELECT * FROM orders";
|
|
313
|
+
const result = injectRLSConditions(sql, [], "postgres");
|
|
314
|
+
expect(result).toBe(sql);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("handles SQL injection safely — quotes in claim values", () => {
|
|
318
|
+
const sql = "SELECT * FROM orders";
|
|
319
|
+
const result = injectRLSConditions(
|
|
320
|
+
sql,
|
|
321
|
+
[filter("orders", "tenant_id", "O''Brien")],
|
|
322
|
+
"postgres",
|
|
323
|
+
);
|
|
324
|
+
// Should produce valid SQL with escaped quotes
|
|
325
|
+
expect(result).toContain("O''Brien");
|
|
326
|
+
// Should NOT contain unescaped single quote that would break SQL
|
|
327
|
+
expect(result).not.toContain("O'B");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("works with MySQL dialect", () => {
|
|
331
|
+
const sql = "SELECT * FROM orders WHERE status = 'active'";
|
|
332
|
+
const result = injectRLSConditions(sql, [filter("orders")], "mysql");
|
|
333
|
+
expect(result.toLowerCase()).toContain("and");
|
|
334
|
+
expect(result).toContain("tenant_id");
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("produces valid SQL that can be re-parsed", () => {
|
|
338
|
+
const sql = "SELECT * FROM orders WHERE status = 'active'";
|
|
339
|
+
const result = injectRLSConditions(sql, [filter("orders")], "postgres");
|
|
340
|
+
|
|
341
|
+
// The result should be parseable by node-sql-parser
|
|
342
|
+
const parser = new Parser();
|
|
343
|
+
expect(() => {
|
|
344
|
+
parser.astify(result, { database: "PostgresQL" });
|
|
345
|
+
}).not.toThrow();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("handles UNION queries", () => {
|
|
349
|
+
const sql = "SELECT id FROM orders UNION SELECT id FROM returns";
|
|
350
|
+
const result = injectRLSConditions(
|
|
351
|
+
sql,
|
|
352
|
+
[filter("orders"), filter("returns")],
|
|
353
|
+
"postgres",
|
|
354
|
+
);
|
|
355
|
+
// Both sides of the UNION should get filtered
|
|
356
|
+
expect(result).toContain("tenant_id");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("injects into derived tables (subqueries in FROM clause)", () => {
|
|
360
|
+
const sql = "SELECT * FROM (SELECT * FROM orders) sub";
|
|
361
|
+
const result = injectRLSConditions(sql, [filter("orders")], "postgres");
|
|
362
|
+
// The inner subquery should get the WHERE condition
|
|
363
|
+
expect(result).toContain("tenant_id");
|
|
364
|
+
expect(result).toContain("acme");
|
|
365
|
+
// Verify the result is valid SQL
|
|
366
|
+
const p = new Parser();
|
|
367
|
+
expect(() => p.astify(result, { database: "PostgresQL" })).not.toThrow();
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("injects into CTE body", () => {
|
|
371
|
+
const sql = "WITH recent AS (SELECT * FROM orders WHERE created > '2024-01-01') SELECT * FROM recent";
|
|
372
|
+
const result = injectRLSConditions(sql, [filter("orders")], "postgres");
|
|
373
|
+
expect(result).toContain("tenant_id");
|
|
374
|
+
expect(result).toContain("acme");
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("injects into WHERE subqueries", () => {
|
|
378
|
+
const sql = "SELECT * FROM customers WHERE id IN (SELECT customer_id FROM orders)";
|
|
379
|
+
const result = injectRLSConditions(
|
|
380
|
+
sql,
|
|
381
|
+
[filter("orders"), filter("customers")],
|
|
382
|
+
"postgres",
|
|
383
|
+
);
|
|
384
|
+
expect(result).toContain("tenant_id");
|
|
385
|
+
// Both customers (outer) and orders (subquery) should be filtered
|
|
386
|
+
const p = new Parser();
|
|
387
|
+
expect(() => p.astify(result, { database: "PostgresQL" })).not.toThrow();
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it("end-to-end: resolveRLSFilters -> injectRLSConditions with malicious claim", () => {
|
|
391
|
+
// Full pipeline test: raw malicious value through resolve then inject
|
|
392
|
+
const user: AtlasUser = {
|
|
393
|
+
id: "user-1",
|
|
394
|
+
mode: "byot",
|
|
395
|
+
label: "test",
|
|
396
|
+
claims: { tenant_id: "'; DROP TABLE orders; --" },
|
|
397
|
+
};
|
|
398
|
+
const rlsConfig: RLSConfig = {
|
|
399
|
+
enabled: true,
|
|
400
|
+
policies: [{ tables: ["*"], column: "tenant_id", claim: "tenant_id" }],
|
|
401
|
+
};
|
|
402
|
+
const filterResult = resolveRLSFilters(user, new Set(["orders"]), rlsConfig);
|
|
403
|
+
expect("filters" in filterResult).toBe(true);
|
|
404
|
+
if (!("filters" in filterResult)) return;
|
|
405
|
+
|
|
406
|
+
const sql = "SELECT * FROM orders";
|
|
407
|
+
const result = injectRLSConditions(sql, filterResult.filters, "postgres");
|
|
408
|
+
|
|
409
|
+
// The injected SQL should be parseable as a single SELECT (no injection breakout)
|
|
410
|
+
const p = new Parser();
|
|
411
|
+
const ast = p.astify(result, { database: "PostgresQL" });
|
|
412
|
+
const stmts = Array.isArray(ast) ? ast : [ast];
|
|
413
|
+
expect(stmts).toHaveLength(1);
|
|
414
|
+
expect(stmts[0].type).toBe("select");
|
|
415
|
+
// The malicious value is safely contained in a string literal
|
|
416
|
+
expect(result).toContain("''';");
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it("uses qualified alias reference for joined tables", () => {
|
|
420
|
+
const sql = "SELECT o.id, c.name FROM orders o JOIN customers c ON o.cid = c.id";
|
|
421
|
+
const result = injectRLSConditions(
|
|
422
|
+
sql,
|
|
423
|
+
[filter("orders"), filter("customers")],
|
|
424
|
+
"postgres",
|
|
425
|
+
);
|
|
426
|
+
// Verify qualified references: o.tenant_id and c.tenant_id (not orders.tenant_id)
|
|
427
|
+
const p = new Parser();
|
|
428
|
+
const ast = p.astify(result, { database: "PostgresQL" });
|
|
429
|
+
// If parsing succeeds with correct structure, the aliases are used correctly
|
|
430
|
+
expect(ast).toBeDefined();
|
|
431
|
+
// Both aliases should appear in the WHERE clause
|
|
432
|
+
expect(result.toLowerCase()).toContain("where");
|
|
433
|
+
expect(result).toContain("tenant_id");
|
|
434
|
+
});
|
|
435
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for scheduled task type definitions.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
DELIVERY_CHANNELS,
|
|
7
|
+
RUN_STATUSES,
|
|
8
|
+
type EmailRecipient,
|
|
9
|
+
type SlackRecipient,
|
|
10
|
+
type WebhookRecipient,
|
|
11
|
+
type Recipient,
|
|
12
|
+
type ScheduledTask,
|
|
13
|
+
type ScheduledTaskRun,
|
|
14
|
+
} from "../scheduled-task-types";
|
|
15
|
+
|
|
16
|
+
describe("scheduled-task-types", () => {
|
|
17
|
+
describe("DELIVERY_CHANNELS", () => {
|
|
18
|
+
it("contains email, slack, webhook", () => {
|
|
19
|
+
expect(DELIVERY_CHANNELS).toEqual(["email", "slack", "webhook"]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("is a readonly tuple (as const)", () => {
|
|
23
|
+
// TypeScript enforces readonly at compile time; at runtime the array is mutable.
|
|
24
|
+
// Verify it has exactly 3 entries as defined.
|
|
25
|
+
expect(DELIVERY_CHANNELS.length).toBe(3);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("RUN_STATUSES", () => {
|
|
30
|
+
it("contains running, success, failed, skipped", () => {
|
|
31
|
+
expect(RUN_STATUSES).toEqual(["running", "success", "failed", "skipped"]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("is a readonly tuple (as const)", () => {
|
|
35
|
+
expect(RUN_STATUSES.length).toBe(4);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("Recipient types", () => {
|
|
40
|
+
it("EmailRecipient has type email and address", () => {
|
|
41
|
+
const r: EmailRecipient = { type: "email", address: "test@example.com" };
|
|
42
|
+
expect(r.type).toBe("email");
|
|
43
|
+
expect(r.address).toBe("test@example.com");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("SlackRecipient has type slack, channel, and optional teamId", () => {
|
|
47
|
+
const r: SlackRecipient = { type: "slack", channel: "#general" };
|
|
48
|
+
expect(r.type).toBe("slack");
|
|
49
|
+
expect(r.channel).toBe("#general");
|
|
50
|
+
expect(r.teamId).toBeUndefined();
|
|
51
|
+
|
|
52
|
+
const r2: SlackRecipient = { type: "slack", channel: "#general", teamId: "T123" };
|
|
53
|
+
expect(r2.teamId).toBe("T123");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("WebhookRecipient has type webhook, url, and optional headers", () => {
|
|
57
|
+
const r: WebhookRecipient = { type: "webhook", url: "https://example.com/hook" };
|
|
58
|
+
expect(r.type).toBe("webhook");
|
|
59
|
+
expect(r.url).toBe("https://example.com/hook");
|
|
60
|
+
expect(r.headers).toBeUndefined();
|
|
61
|
+
|
|
62
|
+
const r2: WebhookRecipient = { type: "webhook", url: "https://example.com/hook", headers: { "X-Key": "abc" } };
|
|
63
|
+
expect(r2.headers).toEqual({ "X-Key": "abc" });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("Recipient discriminated union narrows correctly", () => {
|
|
67
|
+
const recipients: Recipient[] = [
|
|
68
|
+
{ type: "email", address: "a@b.com" },
|
|
69
|
+
{ type: "slack", channel: "#dev" },
|
|
70
|
+
{ type: "webhook", url: "https://hook.example.com" },
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
const emails = recipients.filter((r): r is EmailRecipient => r.type === "email");
|
|
74
|
+
expect(emails.length).toBe(1);
|
|
75
|
+
expect(emails[0].address).toBe("a@b.com");
|
|
76
|
+
|
|
77
|
+
const slacks = recipients.filter((r): r is SlackRecipient => r.type === "slack");
|
|
78
|
+
expect(slacks.length).toBe(1);
|
|
79
|
+
expect(slacks[0].channel).toBe("#dev");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("ScheduledTask shape", () => {
|
|
84
|
+
it("has all required fields", () => {
|
|
85
|
+
const task: ScheduledTask = {
|
|
86
|
+
id: "uuid",
|
|
87
|
+
ownerId: "u1",
|
|
88
|
+
name: "Daily Revenue",
|
|
89
|
+
question: "What was yesterday's revenue?",
|
|
90
|
+
cronExpression: "0 9 * * 1",
|
|
91
|
+
deliveryChannel: "email",
|
|
92
|
+
recipients: [],
|
|
93
|
+
connectionId: null,
|
|
94
|
+
approvalMode: "auto",
|
|
95
|
+
enabled: true,
|
|
96
|
+
lastRunAt: null,
|
|
97
|
+
nextRunAt: "2024-01-01T09:00:00Z",
|
|
98
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
99
|
+
updatedAt: "2024-01-01T00:00:00Z",
|
|
100
|
+
};
|
|
101
|
+
expect(task.id).toBe("uuid");
|
|
102
|
+
expect(task.enabled).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("ScheduledTaskRun shape", () => {
|
|
107
|
+
it("has all required fields", () => {
|
|
108
|
+
const run: ScheduledTaskRun = {
|
|
109
|
+
id: "run-uuid",
|
|
110
|
+
taskId: "task-uuid",
|
|
111
|
+
startedAt: "2024-01-01T09:00:00Z",
|
|
112
|
+
completedAt: "2024-01-01T09:00:30Z",
|
|
113
|
+
status: "success",
|
|
114
|
+
conversationId: null,
|
|
115
|
+
actionId: null,
|
|
116
|
+
error: null,
|
|
117
|
+
tokensUsed: 1500,
|
|
118
|
+
createdAt: "2024-01-01T09:00:00Z",
|
|
119
|
+
};
|
|
120
|
+
expect(run.status).toBe("success");
|
|
121
|
+
expect(run.tokensUsed).toBe(1500);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|