insforge 0.3.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/.dockerignore +58 -0
- package/.env.example +49 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +83 -0
- package/.github/ISSUE_TEMPLATE/config.yml +11 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +79 -0
- package/.github/copilot-instructions.md +147 -0
- package/.github/workflows/build-image.yml +65 -0
- package/.github/workflows/ci-premerge-check.yml +24 -0
- package/.github/workflows/deploy-aws.yml +130 -0
- package/.github/workflows/lint-and-format.yml +33 -0
- package/.prettierignore +65 -0
- package/.prettierrc +9 -0
- package/CHANGELOG.md +3 -0
- package/CONTRIBUTING.md +126 -0
- package/Dockerfile +27 -0
- package/GITHUB_OAUTH_SETUP.md +49 -0
- package/GOOGLE_OAUTH_SETUP.md +148 -0
- package/LICENSE +201 -0
- package/README.md +134 -0
- package/assets/Dark.svg +23 -0
- package/assets/archDiagram.png +0 -0
- package/assets/banner.png +0 -0
- package/assets/mcpInstallv2.png +0 -0
- package/assets/sampleResponse.png +0 -0
- package/assets/signin.png +0 -0
- package/assets/userflow.png +0 -0
- package/backend/migrations/000_create-base-tables.sql +142 -0
- package/backend/migrations/001_create-helper-functions.sql +41 -0
- package/backend/migrations/002_rename-auth-tables.sql +30 -0
- package/backend/migrations/003_create-users-table.sql +56 -0
- package/backend/migrations/004_add-reload-postgrest-func.sql +24 -0
- package/backend/migrations/005_enable-project-admin-modify-users.sql +30 -0
- package/backend/migrations/006_modify-ai-usage-table.sql +25 -0
- package/backend/migrations/007_drop-metadata-table.sql +2 -0
- package/backend/migrations/008_add-system-tables.sql +77 -0
- package/backend/migrations/009_add-function-secrets.sql +24 -0
- package/backend/migrations/010_modify-ai-config-modalities.sql +93 -0
- package/backend/migrations/011_refactor-secrets-table.sql +15 -0
- package/backend/migrations/012_add-storage-uploaded-by.sql +8 -0
- package/backend/package.json +75 -0
- package/backend/src/api/middleware/auth.ts +240 -0
- package/backend/src/api/middleware/error.ts +231 -0
- package/backend/src/api/middleware/upload.ts +59 -0
- package/backend/src/api/routes/agent.ts +29 -0
- package/backend/src/api/routes/ai.ts +472 -0
- package/backend/src/api/routes/auth.oauth.ts +482 -0
- package/backend/src/api/routes/auth.ts +386 -0
- package/backend/src/api/routes/database.advance.ts +275 -0
- package/backend/src/api/routes/database.records.ts +246 -0
- package/backend/src/api/routes/database.tables.ts +161 -0
- package/backend/src/api/routes/docs.ts +66 -0
- package/backend/src/api/routes/functions.ts +183 -0
- package/backend/src/api/routes/logs.ts +150 -0
- package/backend/src/api/routes/metadata.ts +160 -0
- package/backend/src/api/routes/openapi.ts +82 -0
- package/backend/src/api/routes/secrets.ts +199 -0
- package/backend/src/api/routes/storage.ts +547 -0
- package/backend/src/api/routes/usage.ts +96 -0
- package/backend/src/core/ai/chat.ts +207 -0
- package/backend/src/core/ai/client.ts +242 -0
- package/backend/src/core/ai/config.ts +187 -0
- package/backend/src/core/ai/image.ts +156 -0
- package/backend/src/core/ai/model.ts +117 -0
- package/backend/src/core/ai/usage.ts +290 -0
- package/backend/src/core/auth/auth.ts +781 -0
- package/backend/src/core/auth/oauth.ts +398 -0
- package/backend/src/core/database/advance.ts +1074 -0
- package/backend/src/core/database/manager.ts +178 -0
- package/backend/src/core/database/table.ts +772 -0
- package/backend/src/core/documentation/agent.ts +689 -0
- package/backend/src/core/documentation/openapi.ts +856 -0
- package/backend/src/core/functions/functions.ts +310 -0
- package/backend/src/core/logs/analytics.ts +76 -0
- package/backend/src/core/logs/audit.ts +255 -0
- package/backend/src/core/logs/providers/base.provider.ts +83 -0
- package/backend/src/core/logs/providers/cloudwatch.provider.ts +510 -0
- package/backend/src/core/logs/providers/localdb.provider.ts +246 -0
- package/backend/src/core/secrets/encryption.ts +58 -0
- package/backend/src/core/secrets/secrets.ts +410 -0
- package/backend/src/core/socket/socket.ts +388 -0
- package/backend/src/core/socket/types.ts +79 -0
- package/backend/src/core/storage/storage.ts +923 -0
- package/backend/src/server.ts +288 -0
- package/backend/src/types/ai.ts +46 -0
- package/backend/src/types/auth.ts +90 -0
- package/backend/src/types/database.ts +136 -0
- package/backend/src/types/error-constants.ts +86 -0
- package/backend/src/types/logs.ts +47 -0
- package/backend/src/types/profile.ts +55 -0
- package/backend/src/types/storage.ts +23 -0
- package/backend/src/utils/cloud-token.ts +39 -0
- package/backend/src/utils/constants.ts +1 -0
- package/backend/src/utils/environment.ts +35 -0
- package/backend/src/utils/helpers.ts +49 -0
- package/backend/src/utils/logger.ts +13 -0
- package/backend/src/utils/response.ts +62 -0
- package/backend/src/utils/seed.ts +205 -0
- package/backend/src/utils/sql-parser.ts +63 -0
- package/backend/src/utils/uuid.ts +9 -0
- package/backend/src/utils/validations.ts +129 -0
- package/backend/tests/README.md +134 -0
- package/backend/tests/cleanup-all-test-data.sh +231 -0
- package/backend/tests/cloud/test-s3-multitenant.sh +132 -0
- package/backend/tests/local/comprehensive-curl-tests.sh +156 -0
- package/backend/tests/local/test-auth-router.sh +144 -0
- package/backend/tests/local/test-database-router.sh +222 -0
- package/backend/tests/local/test-e2e.sh +241 -0
- package/backend/tests/local/test-fk-errors.sh +97 -0
- package/backend/tests/local/test-id-field.sh +201 -0
- package/backend/tests/local/test-public-bucket.sh +265 -0
- package/backend/tests/local/test-secrets.sh +248 -0
- package/backend/tests/local/test-serverless-functions.sh.disabled +325 -0
- package/backend/tests/local/test-traditional-rest.sh +209 -0
- package/backend/tests/manual/README.md +51 -0
- package/backend/tests/manual/create-large-table-simple.sql +11 -0
- package/backend/tests/manual/seed-large-table.sql +101 -0
- package/backend/tests/manual/setup-large-table-extras.sql +34 -0
- package/backend/tests/manual/test-better-auth.sh +303 -0
- package/backend/tests/manual/test-bulk-upsert.sh +410 -0
- package/backend/tests/manual/test-database-advance.sh +297 -0
- package/backend/tests/manual/test-postgrest-stability.sh +192 -0
- package/backend/tests/manual/test-rawsql-export-import.sh +412 -0
- package/backend/tests/manual/test-universal-storage.sh +264 -0
- package/backend/tests/manual/test-users.sql +18 -0
- package/backend/tests/run-all-tests.sh +140 -0
- package/backend/tests/setup.ts +22 -0
- package/backend/tests/test-config.sh +303 -0
- package/backend/tsconfig.json +23 -0
- package/backend/tsup.config.ts +18 -0
- package/backend/vitest.config.ts +22 -0
- package/docker-compose.prod.yml +145 -0
- package/docker-compose.yml +167 -0
- package/docker-init/db/db-init.sql +125 -0
- package/docker-init/db/jwt.sql +5 -0
- package/docker-init/db/logs.sql +9 -0
- package/docker-init/db/postgresql.conf +17 -0
- package/docs/deprecated/insforge-auth-api.md +215 -0
- package/docs/deprecated/insforge-auth-sdk.md +100 -0
- package/docs/deprecated/insforge-db-api.md +359 -0
- package/docs/deprecated/insforge-db-sdk.md +140 -0
- package/docs/deprecated/insforge-debug-sdk.md +157 -0
- package/docs/deprecated/insforge-debug.md +65 -0
- package/docs/deprecated/insforge-instructions.md +124 -0
- package/docs/deprecated/insforge-project.md +118 -0
- package/docs/deprecated/insforge-storage-api.md +279 -0
- package/docs/deprecated/insforge-storage-sdk.md +159 -0
- package/docs/insforge-instructions-sdk.md +407 -0
- package/eslint.config.js +317 -0
- package/examples/oauth/frontend-oauth-example.html +251 -0
- package/examples/response-examples.md +444 -0
- package/frontend/README.md +112 -0
- package/frontend/components.json +17 -0
- package/frontend/index.html +13 -0
- package/frontend/package.json +63 -0
- package/frontend/public/favicon.ico +0 -0
- package/frontend/src/App.tsx +106 -0
- package/frontend/src/assets/icons/checkbox_checked.svg +6 -0
- package/frontend/src/assets/icons/checkbox_undetermined.svg +6 -0
- package/frontend/src/assets/icons/checked.svg +3 -0
- package/frontend/src/assets/icons/error.svg +3 -0
- package/frontend/src/assets/icons/pencil.svg +4 -0
- package/frontend/src/assets/icons/refresh.svg +4 -0
- package/frontend/src/assets/icons/step_active.svg +3 -0
- package/frontend/src/assets/icons/step_inactive.svg +11 -0
- package/frontend/src/assets/icons/warning.svg +3 -0
- package/frontend/src/assets/logos/amazon.svg +1 -0
- package/frontend/src/assets/logos/claude_code.svg +3 -0
- package/frontend/src/assets/logos/cline.svg +6 -0
- package/frontend/src/assets/logos/cursor.svg +20 -0
- package/frontend/src/assets/logos/discord.svg +9 -0
- package/frontend/src/assets/logos/gemini.svg +19 -0
- package/frontend/src/assets/logos/github.svg +5 -0
- package/frontend/src/assets/logos/google.svg +13 -0
- package/frontend/src/assets/logos/grok.svg +10 -0
- package/frontend/src/assets/logos/insforge_dark.svg +15 -0
- package/frontend/src/assets/logos/insforge_light.svg +15 -0
- package/frontend/src/assets/logos/openai.svg +10 -0
- package/frontend/src/assets/logos/roo_code.svg +9 -0
- package/frontend/src/assets/logos/trae.svg +3 -0
- package/frontend/src/assets/logos/windsurf.svg +10 -0
- package/frontend/src/components/ButtonWithLoading.tsx +27 -0
- package/frontend/src/components/Checkbox.tsx +61 -0
- package/frontend/src/components/CodeBlock.tsx +32 -0
- package/frontend/src/components/ConfirmDialog.tsx +96 -0
- package/frontend/src/components/CopyButton.tsx +69 -0
- package/frontend/src/components/DeleteActionButton.tsx +42 -0
- package/frontend/src/components/EmptyState.tsx +41 -0
- package/frontend/src/components/ErrorState.tsx +35 -0
- package/frontend/src/components/FeatureSidebar.tsx +126 -0
- package/frontend/src/components/FeatureSidebarItem.tsx +101 -0
- package/frontend/src/components/JsonHighlight.tsx +61 -0
- package/frontend/src/components/LoadingState.tsx +16 -0
- package/frontend/src/components/PaginationControls.tsx +54 -0
- package/frontend/src/components/PromptDialog.tsx +68 -0
- package/frontend/src/components/SearchInput.tsx +90 -0
- package/frontend/src/components/SelectionClearButton.tsx +26 -0
- package/frontend/src/components/Stepper.tsx +139 -0
- package/frontend/src/components/ThemeToggle.tsx +58 -0
- package/frontend/src/components/TypeBadge.tsx +20 -0
- package/frontend/src/components/datagrid/DataGrid.tsx +264 -0
- package/frontend/src/components/datagrid/DefaultCellRenderer.tsx +114 -0
- package/frontend/src/components/datagrid/IdCell.tsx +44 -0
- package/frontend/src/components/datagrid/SortableHeader.tsx +74 -0
- package/frontend/src/components/datagrid/cell-editors/BooleanCellEditor.tsx +54 -0
- package/frontend/src/components/datagrid/cell-editors/DateCellEditor.tsx +483 -0
- package/frontend/src/components/datagrid/cell-editors/JsonCellEditor.tsx +362 -0
- package/frontend/src/components/datagrid/cell-editors/TextCellEditor.tsx +38 -0
- package/frontend/src/components/datagrid/cell-editors/index.ts +14 -0
- package/frontend/src/components/datagrid/cell-editors/types.ts +43 -0
- package/frontend/src/components/datagrid/datagridTypes.tsx +72 -0
- package/frontend/src/components/datagrid/index.tsx +20 -0
- package/frontend/src/components/index.ts +39 -0
- package/frontend/src/components/layout/AppHeader.tsx +146 -0
- package/frontend/src/components/layout/AppSidebar.tsx +190 -0
- package/frontend/src/components/layout/CloudLayout.tsx +95 -0
- package/frontend/src/components/layout/Layout.tsx +43 -0
- package/frontend/src/components/radix/Alert.tsx +45 -0
- package/frontend/src/components/radix/AlertDialog.tsx +115 -0
- package/frontend/src/components/radix/Avatar.tsx +45 -0
- package/frontend/src/components/radix/Badge.tsx +33 -0
- package/frontend/src/components/radix/Button.tsx +50 -0
- package/frontend/src/components/radix/Card.tsx +58 -0
- package/frontend/src/components/radix/Dialog.tsx +98 -0
- package/frontend/src/components/radix/DropdownMenu.tsx +185 -0
- package/frontend/src/components/radix/Form.tsx +167 -0
- package/frontend/src/components/radix/Input.tsx +22 -0
- package/frontend/src/components/radix/Label.tsx +19 -0
- package/frontend/src/components/radix/Popover.tsx +29 -0
- package/frontend/src/components/radix/ScrollArea.tsx +44 -0
- package/frontend/src/components/radix/Select.tsx +151 -0
- package/frontend/src/components/radix/Separator.tsx +26 -0
- package/frontend/src/components/radix/Sheet.tsx +119 -0
- package/frontend/src/components/radix/Skeleton.tsx +7 -0
- package/frontend/src/components/radix/Switch.tsx +29 -0
- package/frontend/src/components/radix/Tabs.tsx +50 -0
- package/frontend/src/components/radix/Textarea.tsx +21 -0
- package/frontend/src/components/radix/Tooltip.tsx +28 -0
- package/frontend/src/features/ai/components/AIConfigCard.tsx +154 -0
- package/frontend/src/features/ai/components/AIConfigDialog.tsx +76 -0
- package/frontend/src/features/ai/components/AIConfigForm.tsx +222 -0
- package/frontend/src/features/ai/components/AIEmptyState.tsx +18 -0
- package/frontend/src/features/ai/components/fields/ModalityField.tsx +87 -0
- package/frontend/src/features/ai/components/fields/ModelSelectionField.tsx +134 -0
- package/frontend/src/features/ai/components/fields/SystemPromptField.tsx +33 -0
- package/frontend/src/features/ai/helpers.ts +155 -0
- package/frontend/src/features/ai/hooks/useAIConfigs.ts +221 -0
- package/frontend/src/features/ai/hooks/useAIUsage.ts +77 -0
- package/frontend/src/features/ai/page/AIPage.tsx +178 -0
- package/frontend/src/features/ai/services/ai.service.ts +148 -0
- package/frontend/src/features/auth/components/AddOAuthDialog.tsx +106 -0
- package/frontend/src/features/auth/components/AuthMethodTab.tsx +238 -0
- package/frontend/src/features/auth/components/OAuthConfigDialog.tsx +303 -0
- package/frontend/src/features/auth/components/OAuthEmptyState.tsx +15 -0
- package/frontend/src/features/auth/components/UserFormDialog.tsx +248 -0
- package/frontend/src/features/auth/components/UsersDataGrid.tsx +183 -0
- package/frontend/src/features/auth/components/UsersTab.tsx +114 -0
- package/frontend/src/features/auth/hooks/useOAuthConfig.ts +129 -0
- package/frontend/src/features/auth/hooks/useUsers.ts +57 -0
- package/frontend/src/features/auth/index.ts +9 -0
- package/frontend/src/features/auth/page/AuthenticationPage.tsx +169 -0
- package/frontend/src/features/auth/services/auth.service.ts +112 -0
- package/frontend/src/features/auth/services/oauth.service.ts +49 -0
- package/frontend/src/features/dashboard/page/DashboardPage.tsx +194 -0
- package/frontend/src/features/database/components/ColumnTypeSelect.tsx +64 -0
- package/frontend/src/features/database/components/DatabaseDataGrid.tsx +282 -0
- package/frontend/src/features/database/components/ForeignKeyCell.tsx +187 -0
- package/frontend/src/features/database/components/ForeignKeyPopover.tsx +378 -0
- package/frontend/src/features/database/components/LinkRecordModal.tsx +288 -0
- package/frontend/src/features/database/components/RecordFormDialog.tsx +164 -0
- package/frontend/src/features/database/components/RecordFormField.tsx +568 -0
- package/frontend/src/features/database/components/TableEmptyState.tsx +21 -0
- package/frontend/src/features/database/components/TableForm.tsx +656 -0
- package/frontend/src/features/database/components/TableFormColumn.tsx +137 -0
- package/frontend/src/features/database/components/TableListSkeleton.tsx +9 -0
- package/frontend/src/features/database/components/TableSidebar.tsx +47 -0
- package/frontend/src/features/database/constants.ts +26 -0
- package/frontend/src/features/database/helpers.ts +125 -0
- package/frontend/src/features/database/hooks/UseLinkModal.tsx +78 -0
- package/frontend/src/features/database/index.ts +12 -0
- package/frontend/src/features/database/page/DatabasePage.tsx +626 -0
- package/frontend/src/features/database/schema.ts +25 -0
- package/frontend/src/features/database/services/database.service.ts +216 -0
- package/frontend/src/features/functions/components/FunctionEmptyState.tsx +15 -0
- package/frontend/src/features/functions/components/FunctionRow.tsx +71 -0
- package/frontend/src/features/functions/components/FunctionViewer.tsx +46 -0
- package/frontend/src/features/functions/components/FunctionsContent.tsx +88 -0
- package/frontend/src/features/functions/components/FunctionsSidebar.tsx +56 -0
- package/frontend/src/features/functions/components/SecretEmptyState.tsx +23 -0
- package/frontend/src/features/functions/components/SecretRow.tsx +68 -0
- package/frontend/src/features/functions/components/SecretsContent.tsx +120 -0
- package/frontend/src/features/functions/hooks/useFunctions.ts +106 -0
- package/frontend/src/features/functions/page/FunctionsPage.tsx +28 -0
- package/frontend/src/features/functions/services/functions.service.ts +48 -0
- package/frontend/src/features/login/components/AuthErrorBoundary.tsx +87 -0
- package/frontend/src/features/login/components/PrivateRoute.tsx +24 -0
- package/frontend/src/features/login/page/CloudLoginPage.tsx +93 -0
- package/frontend/src/features/login/page/LoginPage.tsx +174 -0
- package/frontend/src/features/logs/components/AnalyticsLogsTable.tsx +313 -0
- package/frontend/src/features/logs/components/LogsTable.tsx +199 -0
- package/frontend/src/features/logs/hooks/useAuditLogs.ts +39 -0
- package/frontend/src/features/logs/index.ts +5 -0
- package/frontend/src/features/logs/page/AnalyticsLogsPage.tsx +530 -0
- package/frontend/src/features/logs/page/AuditsPage.tsx +192 -0
- package/frontend/src/features/logs/services/log.service.ts +171 -0
- package/frontend/src/features/metadata/hooks/useMetadata.ts +53 -0
- package/frontend/src/features/metadata/index.ts +0 -0
- package/frontend/src/features/metadata/page/MetadataPage.tsx +136 -0
- package/frontend/src/features/metadata/services/metadata.service.ts +17 -0
- package/frontend/src/features/onboard/components/CompletionCard.tsx +41 -0
- package/frontend/src/features/onboard/components/OnboardButton.tsx +84 -0
- package/frontend/src/features/onboard/components/StepContent.tsx +91 -0
- package/frontend/src/features/onboard/components/TestConnectionStep.tsx +53 -0
- package/frontend/src/features/onboard/components/mcp/CursorDeeplinkGenerator.tsx +35 -0
- package/frontend/src/features/onboard/components/mcp/McpInstallation.tsx +144 -0
- package/frontend/src/features/onboard/components/mcp/index.ts +4 -0
- package/frontend/src/features/onboard/components/mcp/mcp-helper.tsx +98 -0
- package/frontend/src/features/onboard/index.ts +3 -0
- package/frontend/src/features/onboard/page/OnBoardPage.tsx +104 -0
- package/frontend/src/features/onboard/types.ts +8 -0
- package/frontend/src/features/secrets/hooks/useSecrets.ts +139 -0
- package/frontend/src/features/secrets/services/secrets.service.ts +57 -0
- package/frontend/src/features/storage/components/BucketEmptyState.tsx +19 -0
- package/frontend/src/features/storage/components/BucketFormDialog.tsx +194 -0
- package/frontend/src/features/storage/components/BucketListSkeleton.tsx +17 -0
- package/frontend/src/features/storage/components/FilePreviewDialog.tsx +287 -0
- package/frontend/src/features/storage/components/StorageDataGrid.tsx +239 -0
- package/frontend/src/features/storage/components/StorageManager.tsx +236 -0
- package/frontend/src/features/storage/components/StorageSidebar.tsx +44 -0
- package/frontend/src/features/storage/components/UploadToast.tsx +46 -0
- package/frontend/src/features/storage/index.ts +3 -0
- package/frontend/src/features/storage/page/StoragePage.tsx +553 -0
- package/frontend/src/features/storage/services/storage.service.ts +144 -0
- package/frontend/src/features/visualizer/components/AuthNode.tsx +107 -0
- package/frontend/src/features/visualizer/components/BucketNode.tsx +34 -0
- package/frontend/src/features/visualizer/components/SchemaVisualizer.tsx +359 -0
- package/frontend/src/features/visualizer/components/TableNode.tsx +152 -0
- package/frontend/src/features/visualizer/components/VisualizerSkeleton.tsx +24 -0
- package/frontend/src/features/visualizer/components/index.ts +5 -0
- package/frontend/src/features/visualizer/page/VisualizerPage.tsx +127 -0
- package/frontend/src/index.css +248 -0
- package/frontend/src/lib/api/client.ts +163 -0
- package/frontend/src/lib/contexts/AuthContext.tsx +157 -0
- package/frontend/src/lib/contexts/OnboardStepContext.tsx +68 -0
- package/frontend/src/lib/contexts/SocketContext.tsx +303 -0
- package/frontend/src/lib/contexts/ThemeContext.tsx +125 -0
- package/frontend/src/lib/hooks/useAuth.ts +4 -0
- package/frontend/src/lib/hooks/useConfirm.ts +55 -0
- package/frontend/src/lib/hooks/useInterval.ts +27 -0
- package/frontend/src/lib/hooks/useMediaQuery.ts +59 -0
- package/frontend/src/lib/hooks/useOnboardingCompletion.ts +29 -0
- package/frontend/src/lib/hooks/usePagination.ts +27 -0
- package/frontend/src/lib/hooks/useTimeout.ts +27 -0
- package/frontend/src/lib/hooks/useToast.tsx +229 -0
- package/frontend/src/lib/utils/constants.ts +38 -0
- package/frontend/src/lib/utils/utils.ts +165 -0
- package/frontend/src/lib/utils/validation-schemas.ts +126 -0
- package/frontend/src/main.tsx +16 -0
- package/frontend/src/rdg.css +194 -0
- package/frontend/src/vite-env.d.ts +12 -0
- package/frontend/tailwind.config.js +97 -0
- package/frontend/tsconfig.json +26 -0
- package/frontend/tsconfig.node.json +10 -0
- package/frontend/vite.config.ts +37 -0
- package/frontend/vitest.config.ts +36 -0
- package/functions/deno.json +25 -0
- package/functions/server.ts +290 -0
- package/functions/worker-template.js +126 -0
- package/openapi/ai.yaml +689 -0
- package/openapi/auth.yaml +563 -0
- package/openapi/functions.yaml +476 -0
- package/openapi/health.yaml +30 -0
- package/openapi/logs.yaml +224 -0
- package/openapi/metadata.yaml +178 -0
- package/openapi/records.yaml +382 -0
- package/openapi/secrets.yaml +371 -0
- package/openapi/storage.yaml +876 -0
- package/openapi/tables.yaml +464 -0
- package/package.json +88 -0
- package/shared-schemas/package.json +31 -0
- package/shared-schemas/src/ai-api.schema.ts +167 -0
- package/shared-schemas/src/ai.schema.ts +54 -0
- package/shared-schemas/src/auth-api.schema.ts +193 -0
- package/shared-schemas/src/auth.schema.ts +94 -0
- package/shared-schemas/src/database-api.schema.ts +259 -0
- package/shared-schemas/src/database.schema.ts +69 -0
- package/shared-schemas/src/functions-api.schema.ts +25 -0
- package/shared-schemas/src/functions.schema.ts +16 -0
- package/shared-schemas/src/index.ts +13 -0
- package/shared-schemas/src/logs-api.schema.ts +49 -0
- package/shared-schemas/src/logs.schema.ts +14 -0
- package/shared-schemas/src/metadata.schema.ts +56 -0
- package/shared-schemas/src/storage-api.schema.ts +65 -0
- package/shared-schemas/src/storage.schema.ts +19 -0
- package/shared-schemas/tsconfig.json +21 -0
- package/tsconfig.json +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://insforge.com">
|
|
3
|
+
<img src="assets/banner.png" alt="Insforge Logo">
|
|
4
|
+
</a>
|
|
5
|
+
|
|
6
|
+
</div>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="#quickstart-tldr">Get Started</a> ·
|
|
9
|
+
<a href="https://docs.insforge.dev/introduction">Documentation</a> ·
|
|
10
|
+
<a href="https://discord.gg/MPxwj5xVvW">Discord</a>
|
|
11
|
+
</p>
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License"></a>
|
|
14
|
+
<a href="https://discord.gg/MPxwj5xVvW"><img src="https://img.shields.io/badge/Discord-Join%20Community-7289DA?logo=discord&logoColor=white" alt="Discord"></a>
|
|
15
|
+
<a href="https://github.com/InsForge/insforge/stargazers"><img src="https://img.shields.io/github/stars/InsForge/insforge?style=social" alt="GitHub Stars"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
# InsForge
|
|
19
|
+
|
|
20
|
+
**InsForge is the Agent-Native Supabase Alternative.** We are building the features of Supabase in an AI-native way, enabling AI agents to build and manage full-stack applications autonomously.
|
|
21
|
+
|
|
22
|
+
## Key Features & Use Cases
|
|
23
|
+
|
|
24
|
+
### Core Features:
|
|
25
|
+
- **Authentication** - Complete user management system
|
|
26
|
+
- **Database** - Flexible data storage and retrieval
|
|
27
|
+
- **Storage** - File management and organization
|
|
28
|
+
- **Serverless Functions** - Scalable compute power
|
|
29
|
+
- **Site Deployment** *(coming soon)* - Easy application deployment
|
|
30
|
+
|
|
31
|
+
### Use Cases: Building full-stack applications using natural language
|
|
32
|
+
- **Connect AI agents to InsForge** - Enable Claude, GPT, or other AI agents to manage your backend
|
|
33
|
+
- **Add backend to Lovable or Bolt-style vibe coding project projects** - Instant backend for AI-generated frontends
|
|
34
|
+
|
|
35
|
+
## Prompt Examples:
|
|
36
|
+
|
|
37
|
+
<td align="center">
|
|
38
|
+
<img src="assets/userflow.png" alt="userFlow">
|
|
39
|
+
<br>
|
|
40
|
+
</td>
|
|
41
|
+
|
|
42
|
+
## Quickstart TLDR;
|
|
43
|
+
|
|
44
|
+
### 1. Install and run InsForge
|
|
45
|
+
|
|
46
|
+
**Use Docker (Recommended)**
|
|
47
|
+
Prerequisites: [Docker](https://www.docker.com/) + [Node.js](https://nodejs.org/)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Run with Docker
|
|
51
|
+
git clone https://github.com/insforge/insforge.git
|
|
52
|
+
cd insforge
|
|
53
|
+
cp .env.example .env
|
|
54
|
+
docker compose up
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Connect an AI Agent
|
|
58
|
+
|
|
59
|
+
Visit InsForge Dashboard (default: http://localhost:7131), log in, and follow the "Connect" guide, and set up your MCP.
|
|
60
|
+
|
|
61
|
+
<div align="center">
|
|
62
|
+
<table>
|
|
63
|
+
<tr>
|
|
64
|
+
<td align="center">
|
|
65
|
+
<img src="assets/signin.png" alt="Sign In">
|
|
66
|
+
<br>
|
|
67
|
+
<em>Sign in to InsForge</em>
|
|
68
|
+
</td>
|
|
69
|
+
<td align="center">
|
|
70
|
+
<img src="assets/mcpInstallv2.png" alt="MCP Configuration"">
|
|
71
|
+
<br>
|
|
72
|
+
<em>Configure MCP connection</em>
|
|
73
|
+
</td>
|
|
74
|
+
</tr>
|
|
75
|
+
</table>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
### 3. Test the Connection
|
|
79
|
+
|
|
80
|
+
In your agent, send:
|
|
81
|
+
```
|
|
82
|
+
InsForge is my backend platform, what is my current backend structure?
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
<div align="center">
|
|
86
|
+
<img src="assets/sampleResponse.png" alt="Successful Connection Response" width="600">
|
|
87
|
+
<br>
|
|
88
|
+
<em>Sample successful response calling insforge MCP tools</em>
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
### 4. Start Using InsForge
|
|
92
|
+
|
|
93
|
+
Start building your project in a new directory! Build your next todo app, Instagram clone, or online platform in seconds!
|
|
94
|
+
|
|
95
|
+
**Sample Project Prompts:**
|
|
96
|
+
- "Build a todo app with user authentication"
|
|
97
|
+
- "Create an Instagram with image upload"
|
|
98
|
+
|
|
99
|
+
## Architecture
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
<div align="center">
|
|
103
|
+
<img src="assets/archDiagram.png" alt="Carch">
|
|
104
|
+
<br>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## Contributing
|
|
110
|
+
|
|
111
|
+
**Contributing**: If you're interested in contributing, you can check our guide here [CONTRIBUTING.md](CONTRIBUTING.md). We truly appreciate pull requests, all types of help are appreciated!
|
|
112
|
+
|
|
113
|
+
**Support**: If you need any type of help support, we're responsive on our [Discord channel](https://discord.gg/MPxwj5xVvW), and also feel free to email us [info@insforge.dev](mailto:info@insforge.dev) too!
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## Documentation & Support
|
|
117
|
+
|
|
118
|
+
### Documentation
|
|
119
|
+
- **[Official Docs](https://docs.insforge.dev/introduction)** - Comprehensive guides and API references
|
|
120
|
+
|
|
121
|
+
### Community
|
|
122
|
+
- **[Discord](https://discord.gg/D3Vf8zD2ZS)** - Join our vibrant community
|
|
123
|
+
- **[Twitter](https://x.com/InsForge_dev)** - Follow for updates and tips
|
|
124
|
+
|
|
125
|
+
### Contact
|
|
126
|
+
- **Email**: info@insforge.dev
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
[](https://www.star-history.com/#InsForge/insforge&Date)
|
package/assets/Dark.svg
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<svg width="1080" height="400" viewBox="0 0 1080 400" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<rect width="1080" height="400" fill="black"/>
|
|
3
|
+
<path d="M253 281C253 284 251.664 286.164 249 287.5C247.739 288.132 247 288.5 245.8 288.5C245 288.5 243.54 288.193 242.5 287.5C239.5 285.5 164 209 164 209L192 181L248.607 237.607C251.42 240.42 253 244.222 253 248.201V281Z" fill="url(#paint0_linear_101_25)"/>
|
|
4
|
+
<path d="M136.244 230.934L107.134 201.96C104.302 199.142 104.302 194.559 107.134 191.741L170.07 129.1C171.421 127.755 173.25 127 175.156 127H199.878C201.784 127 203.612 127.755 204.963 129.1L221.694 145.751C225.657 149.697 225.657 156.113 221.694 160.058L150.484 230.934C146.546 234.853 140.182 234.853 136.244 230.934Z" fill="url(#paint1_linear_101_25)"/>
|
|
5
|
+
<path d="M949.564 209.58C949.328 203.246 947.74 198.204 944.797 194.456C941.972 190.578 937.912 188.639 932.616 188.639C927.319 188.639 922.788 190.707 919.022 194.843C915.373 198.851 913.019 204.732 911.96 212.488H949.564V209.58ZM937.029 270.659C922.788 270.659 911.548 266.005 903.309 256.698C895.07 247.391 890.951 235.175 890.951 220.051C890.951 204.797 894.835 192.711 902.603 183.791C910.371 174.872 920.081 170.412 931.733 170.412C943.385 170.412 952.624 174.29 959.45 182.046C966.277 189.802 969.69 201.113 969.69 215.979C969.69 219.598 969.278 224.252 968.454 229.94H912.313C913.843 237.049 917.021 242.479 921.846 246.227C926.79 249.976 933.439 251.85 941.796 251.85C950.152 251.85 957.567 249.265 964.041 244.094V264.26C957.803 268.526 948.799 270.659 937.029 270.659Z" fill="white"/>
|
|
6
|
+
<path d="M832.287 190.19C826.402 190.19 821.694 192.84 818.163 198.14C814.632 203.31 812.867 210.42 812.867 219.469C812.867 228.518 814.691 235.498 818.34 240.41C821.988 245.193 826.637 247.585 832.287 247.585C838.054 247.585 842.88 245.128 846.764 240.216C850.648 235.175 852.59 228.065 852.59 218.887C852.59 209.58 850.706 202.47 846.94 197.558C843.174 192.646 838.289 190.19 832.287 190.19ZM873.775 260.77C873.775 276.282 869.656 287.916 861.417 295.672C853.296 303.557 843.115 307.5 830.875 307.5C818.752 307.5 808.277 305.173 799.45 300.52V276.864C807.453 283.068 817.045 286.171 828.226 286.171C844.468 286.171 852.59 277.639 852.59 260.576V252.044C847.176 261.739 839.054 266.587 828.226 266.587C817.516 266.587 808.571 262.58 801.392 254.565C794.33 246.421 790.799 234.981 790.799 220.244C790.799 205.379 794.153 193.357 800.862 184.179C807.688 174.872 816.633 170.218 827.697 170.218C838.878 170.218 847.176 175.324 852.59 185.536V171.381H873.775V260.77Z" fill="white"/>
|
|
7
|
+
<path d="M753.806 269.689H732.444L732.62 171.381H753.806V188.833C757.925 176.681 765.458 170.606 776.404 170.606C778.875 170.606 780.876 170.8 782.406 171.188V193.68C779.699 192.387 776.698 191.741 773.402 191.741C767.635 191.741 762.927 194.326 759.279 199.497C755.63 204.668 753.806 211.131 753.806 218.887V269.689Z" fill="white"/>
|
|
8
|
+
<path d="M671.46 188.832C664.516 188.832 659.219 191.87 655.571 197.946C652.04 204.021 650.275 211.648 650.275 220.826C650.275 229.875 652.099 237.437 655.747 243.513C659.396 249.588 664.634 252.626 671.46 252.626C678.286 252.626 683.465 249.653 686.996 243.706C690.527 237.76 692.292 230.133 692.292 220.826C692.292 211.519 690.586 203.892 687.172 197.946C683.759 191.87 678.522 188.832 671.46 188.832ZM671.637 169.83C685.054 169.83 695.529 174.613 703.062 184.179C710.594 193.615 714.36 205.702 714.36 220.438C714.36 235.175 710.535 247.326 702.885 256.892C695.352 266.458 684.76 271.24 671.107 271.24C657.572 271.24 646.979 266.587 639.329 257.28C631.796 247.972 628.03 235.95 628.03 221.214C628.03 206.477 631.973 194.262 639.858 184.567C647.744 174.742 658.337 169.83 671.637 169.83Z" fill="white"/>
|
|
9
|
+
<path d="M609.312 217.53H568V269.689H545.579V139H615.314V158.972H568V197.558H609.312V217.53Z" fill="white"/>
|
|
10
|
+
<path d="M527.791 241.38C527.791 250.558 524.79 257.732 518.787 262.903C512.784 268.073 504.487 270.659 493.894 270.659C483.419 270.659 474.768 268.655 467.942 264.648V243.319C475.828 249.136 484.361 252.044 493.541 252.044C497.425 252.044 500.426 251.269 502.545 249.717C504.781 248.037 505.899 246.098 505.899 243.9C505.899 241.574 505.546 239.764 504.84 238.471C504.134 237.049 502.78 235.692 500.779 234.399C498.19 232.719 495.542 231.297 492.835 230.133C490.246 228.841 488.833 228.13 488.598 228C488.48 227.871 488.245 227.742 487.892 227.613C487.539 227.483 487.244 227.354 487.009 227.225C473.945 220.762 467.412 211.454 467.412 199.303C467.412 190.254 470.531 183.145 476.769 177.974C483.007 172.803 490.716 170.218 499.897 170.218C509.195 170.218 516.845 171.64 522.848 174.484V195.037C516.963 191.159 509.607 189.22 500.779 189.22C497.131 189.22 494.247 190.125 492.129 191.935C490.128 193.615 489.127 195.813 489.127 198.528C489.127 200.725 489.657 202.406 490.716 203.569C491.776 204.732 492.658 205.637 493.365 206.284C494.071 206.93 495.071 207.641 496.366 208.416C499.544 210.097 501.956 211.325 503.604 212.101C511.725 215.849 517.787 220.051 521.788 224.704C525.79 229.229 527.791 234.787 527.791 241.38Z" fill="white"/>
|
|
11
|
+
<path d="M447.21 269.689H426.025V209.192C426.025 202.729 424.613 197.881 421.788 194.649C418.963 191.289 414.962 189.608 409.783 189.608C404.604 189.608 400.132 191.999 396.365 196.782C392.599 201.436 390.716 208.158 390.716 216.948V269.689H369.531V171.381H390.716V188.251C395.777 176.229 404.957 170.218 418.257 170.218C427.202 170.218 434.264 173.191 439.442 179.137C444.621 185.084 447.21 193.486 447.21 204.345V269.689Z" fill="white"/>
|
|
12
|
+
<path d="M344.245 269.689H322V139H344.245V269.689Z" fill="white"/>
|
|
13
|
+
<defs>
|
|
14
|
+
<linearGradient id="paint0_linear_101_25" x1="264.639" y1="302.534" x2="192.289" y2="165.357" gradientUnits="userSpaceOnUse">
|
|
15
|
+
<stop stop-color="#009DFF"/>
|
|
16
|
+
<stop offset="1" stop-color="#004E75"/>
|
|
17
|
+
</linearGradient>
|
|
18
|
+
<linearGradient id="paint1_linear_101_25" x1="210.858" y1="136.372" x2="87.5817" y2="259.648" gradientUnits="userSpaceOnUse">
|
|
19
|
+
<stop stop-color="#009DFF"/>
|
|
20
|
+
<stop offset="1" stop-color="#004E75"/>
|
|
21
|
+
</linearGradient>
|
|
22
|
+
</defs>
|
|
23
|
+
</svg>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
-- Migration: 000 - Create base system tables
|
|
2
|
+
-- This migration creates all the initial tables that the application needs
|
|
3
|
+
|
|
4
|
+
-- System configuration
|
|
5
|
+
CREATE TABLE IF NOT EXISTS _config (
|
|
6
|
+
key TEXT PRIMARY KEY,
|
|
7
|
+
value TEXT NOT NULL,
|
|
8
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
9
|
+
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- App metadata
|
|
13
|
+
CREATE TABLE IF NOT EXISTS _metadata (
|
|
14
|
+
key TEXT PRIMARY KEY,
|
|
15
|
+
value TEXT,
|
|
16
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
17
|
+
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- Storage buckets table to track bucket-level settings
|
|
21
|
+
CREATE TABLE IF NOT EXISTS _storage_buckets (
|
|
22
|
+
name TEXT PRIMARY KEY,
|
|
23
|
+
public BOOLEAN DEFAULT TRUE,
|
|
24
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
25
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- Storage files table
|
|
29
|
+
CREATE TABLE IF NOT EXISTS _storage (
|
|
30
|
+
bucket TEXT NOT NULL,
|
|
31
|
+
key TEXT NOT NULL,
|
|
32
|
+
size INTEGER NOT NULL,
|
|
33
|
+
mime_type TEXT,
|
|
34
|
+
uploaded_at TIMESTAMPTZ DEFAULT NOW(),
|
|
35
|
+
PRIMARY KEY (bucket, key),
|
|
36
|
+
FOREIGN KEY (bucket) REFERENCES _storage_buckets(name) ON DELETE CASCADE
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
-- MCP usage tracking table
|
|
40
|
+
CREATE TABLE IF NOT EXISTS _mcp_usage (
|
|
41
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
42
|
+
tool_name VARCHAR(255) NOT NULL,
|
|
43
|
+
success BOOLEAN DEFAULT true,
|
|
44
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
-- AI configurations table
|
|
48
|
+
CREATE TABLE IF NOT EXISTS _ai_configs (
|
|
49
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
50
|
+
modality VARCHAR(255) NOT NULL,
|
|
51
|
+
provider VARCHAR(255) NOT NULL,
|
|
52
|
+
model_id VARCHAR(255) UNIQUE NOT NULL,
|
|
53
|
+
system_prompt TEXT,
|
|
54
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
55
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
CREATE TABLE IF NOT EXISTS _ai_usage (
|
|
59
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
60
|
+
config_id UUID NOT NULL,
|
|
61
|
+
input_tokens INT,
|
|
62
|
+
output_tokens INT,
|
|
63
|
+
image_count INT,
|
|
64
|
+
image_resolution TEXT,
|
|
65
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
66
|
+
FOREIGN KEY (config_id) REFERENCES _ai_configs(id) ON DELETE NO ACTION
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
-- Indexes for AI tables
|
|
70
|
+
CREATE INDEX IF NOT EXISTS idx_ai_usage_config_id ON _ai_usage(config_id);
|
|
71
|
+
CREATE INDEX IF NOT EXISTS idx_ai_usage_created_at ON _ai_usage(created_at DESC);
|
|
72
|
+
|
|
73
|
+
-- Index for efficient date range queries
|
|
74
|
+
CREATE INDEX IF NOT EXISTS idx_mcp_usage_created_at ON _mcp_usage(created_at DESC);
|
|
75
|
+
|
|
76
|
+
-- Edge functions
|
|
77
|
+
CREATE TABLE IF NOT EXISTS _edge_functions (
|
|
78
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
79
|
+
slug VARCHAR(255) UNIQUE NOT NULL,
|
|
80
|
+
name VARCHAR(255) NOT NULL,
|
|
81
|
+
description TEXT,
|
|
82
|
+
code TEXT NOT NULL,
|
|
83
|
+
status VARCHAR(50) DEFAULT 'draft',
|
|
84
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
85
|
+
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
86
|
+
deployed_at TIMESTAMPTZ
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
-- Auth Tables (2-table structure)
|
|
90
|
+
-- User table
|
|
91
|
+
CREATE TABLE IF NOT EXISTS _user (
|
|
92
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
93
|
+
email TEXT UNIQUE NOT NULL,
|
|
94
|
+
password TEXT, -- NULL for OAuth-only users
|
|
95
|
+
name TEXT,
|
|
96
|
+
email_verified BOOLEAN DEFAULT false,
|
|
97
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
98
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
-- Account table (for OAuth connections)
|
|
102
|
+
CREATE TABLE IF NOT EXISTS _account (
|
|
103
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
104
|
+
user_id UUID NOT NULL REFERENCES _user(id) ON DELETE CASCADE,
|
|
105
|
+
provider TEXT NOT NULL, -- OAuth provider name: 'google', 'github', etc.
|
|
106
|
+
provider_account_id TEXT NOT NULL, -- User's unique ID on the provider's system
|
|
107
|
+
access_token TEXT, -- OAuth access token for making API calls to provider
|
|
108
|
+
refresh_token TEXT, -- OAuth refresh token for renewing access
|
|
109
|
+
provider_data JSONB, -- OAuth provider's user profile
|
|
110
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
111
|
+
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
112
|
+
UNIQUE(provider, provider_account_id)
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
-- Create update timestamp function
|
|
116
|
+
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
|
117
|
+
RETURNS TRIGGER AS $$
|
|
118
|
+
BEGIN
|
|
119
|
+
NEW.updated_at = NOW();
|
|
120
|
+
RETURN NEW;
|
|
121
|
+
END;
|
|
122
|
+
$$ language 'plpgsql';
|
|
123
|
+
|
|
124
|
+
-- Create triggers for updated_at
|
|
125
|
+
DROP TRIGGER IF EXISTS update__config_updated_at ON _config;
|
|
126
|
+
CREATE TRIGGER update__config_updated_at BEFORE UPDATE ON _config
|
|
127
|
+
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
128
|
+
|
|
129
|
+
DROP TRIGGER IF EXISTS update__metadata_updated_at ON _metadata;
|
|
130
|
+
CREATE TRIGGER update__metadata_updated_at BEFORE UPDATE ON _metadata
|
|
131
|
+
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
132
|
+
|
|
133
|
+
DROP TRIGGER IF EXISTS update__edge_functions_updated_at ON _edge_functions;
|
|
134
|
+
CREATE TRIGGER update__edge_functions_updated_at BEFORE UPDATE ON _edge_functions
|
|
135
|
+
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
136
|
+
|
|
137
|
+
-- Insert initial metadata
|
|
138
|
+
INSERT INTO _metadata (key, value) VALUES ('version', '1.0.0')
|
|
139
|
+
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
|
|
140
|
+
|
|
141
|
+
INSERT INTO _metadata (key, value) VALUES ('created_at', NOW()::TEXT)
|
|
142
|
+
ON CONFLICT (key) DO NOTHING;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Migration: 001 - Create helper functions for RLS
|
|
2
|
+
-- These functions extract user information from JWT claims
|
|
3
|
+
|
|
4
|
+
-- Function to get current user ID from JWT
|
|
5
|
+
CREATE OR REPLACE FUNCTION public.uid()
|
|
6
|
+
RETURNS uuid
|
|
7
|
+
LANGUAGE sql STABLE
|
|
8
|
+
AS $$
|
|
9
|
+
SELECT
|
|
10
|
+
nullif(
|
|
11
|
+
coalesce(
|
|
12
|
+
current_setting('request.jwt.claim.sub', true),
|
|
13
|
+
(current_setting('request.jwt.claims', true)::jsonb ->> 'sub')
|
|
14
|
+
),
|
|
15
|
+
''
|
|
16
|
+
)::uuid
|
|
17
|
+
$$;
|
|
18
|
+
|
|
19
|
+
-- Function to get current user role from JWT
|
|
20
|
+
CREATE OR REPLACE FUNCTION public.role()
|
|
21
|
+
RETURNS text
|
|
22
|
+
LANGUAGE sql STABLE
|
|
23
|
+
AS $$
|
|
24
|
+
SELECT
|
|
25
|
+
coalesce(
|
|
26
|
+
current_setting('request.jwt.claim.role', true),
|
|
27
|
+
(current_setting('request.jwt.claims', true)::jsonb ->> 'role')
|
|
28
|
+
)::text
|
|
29
|
+
$$;
|
|
30
|
+
|
|
31
|
+
-- Function to get current user email from JWT
|
|
32
|
+
CREATE OR REPLACE FUNCTION public.email()
|
|
33
|
+
RETURNS text
|
|
34
|
+
LANGUAGE sql STABLE
|
|
35
|
+
AS $$
|
|
36
|
+
SELECT
|
|
37
|
+
coalesce(
|
|
38
|
+
current_setting('request.jwt.claim.email', true),
|
|
39
|
+
(current_setting('request.jwt.claims', true)::jsonb ->> 'email')
|
|
40
|
+
)::text
|
|
41
|
+
$$;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Migration: 002 - Rename authentication tables to better auth naming convention
|
|
2
|
+
|
|
3
|
+
DO $$
|
|
4
|
+
BEGIN
|
|
5
|
+
-- Handle _account to _oauth_connections
|
|
6
|
+
IF EXISTS (SELECT FROM information_schema.tables
|
|
7
|
+
WHERE table_name = '_account' AND table_schema = 'public') THEN
|
|
8
|
+
IF EXISTS (SELECT FROM information_schema.tables
|
|
9
|
+
WHERE table_name = '_oauth_connections' AND table_schema = 'public') THEN
|
|
10
|
+
-- Both exist, drop the old one
|
|
11
|
+
DROP TABLE _account CASCADE;
|
|
12
|
+
ELSE
|
|
13
|
+
-- Only old exists, rename it
|
|
14
|
+
ALTER TABLE _account RENAME TO _oauth_connections;
|
|
15
|
+
END IF;
|
|
16
|
+
END IF;
|
|
17
|
+
|
|
18
|
+
-- Handle _user to _accounts
|
|
19
|
+
IF EXISTS (SELECT FROM information_schema.tables
|
|
20
|
+
WHERE table_name = '_user' AND table_schema = 'public') THEN
|
|
21
|
+
IF EXISTS (SELECT FROM information_schema.tables
|
|
22
|
+
WHERE table_name = '_accounts' AND table_schema = 'public') THEN
|
|
23
|
+
-- Both exist, drop the old one
|
|
24
|
+
DROP TABLE _user CASCADE;
|
|
25
|
+
ELSE
|
|
26
|
+
-- Only old exists, rename it
|
|
27
|
+
ALTER TABLE _user RENAME TO _accounts;
|
|
28
|
+
END IF;
|
|
29
|
+
END IF;
|
|
30
|
+
END $$;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
-- Migration: 003 - Create users table for user profiles
|
|
2
|
+
|
|
3
|
+
DO $$
|
|
4
|
+
BEGIN
|
|
5
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
6
|
+
id UUID PRIMARY KEY REFERENCES _accounts(id) ON DELETE CASCADE,
|
|
7
|
+
nickname TEXT,
|
|
8
|
+
avatar_url TEXT,
|
|
9
|
+
bio TEXT,
|
|
10
|
+
birthday DATE,
|
|
11
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
12
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
-- Check and create policies only if they don't exist
|
|
16
|
+
-- Allow everyone to read users table
|
|
17
|
+
IF NOT EXISTS (
|
|
18
|
+
SELECT 1 FROM pg_policies
|
|
19
|
+
WHERE tablename = 'users'
|
|
20
|
+
AND policyname = 'Enable read access for all users'
|
|
21
|
+
) THEN
|
|
22
|
+
CREATE POLICY "Enable read access for all users" ON users
|
|
23
|
+
FOR SELECT
|
|
24
|
+
USING (true); -- Allow all reads
|
|
25
|
+
END IF;
|
|
26
|
+
|
|
27
|
+
IF NOT EXISTS (
|
|
28
|
+
SELECT 1 FROM pg_policies
|
|
29
|
+
WHERE tablename = 'users'
|
|
30
|
+
AND policyname = 'Disable delete for users'
|
|
31
|
+
) THEN
|
|
32
|
+
CREATE POLICY "Disable delete for users" ON users
|
|
33
|
+
FOR DELETE
|
|
34
|
+
TO authenticated
|
|
35
|
+
USING (false);
|
|
36
|
+
END IF;
|
|
37
|
+
|
|
38
|
+
IF NOT EXISTS (
|
|
39
|
+
SELECT 1 FROM pg_policies
|
|
40
|
+
WHERE tablename = 'users'
|
|
41
|
+
AND policyname = 'Enable update for users based on user_id'
|
|
42
|
+
) THEN
|
|
43
|
+
CREATE POLICY "Enable update for users based on user_id" ON users
|
|
44
|
+
FOR UPDATE
|
|
45
|
+
TO authenticated
|
|
46
|
+
USING (uid() = id)
|
|
47
|
+
WITH CHECK (uid() = id); -- make sure only the owner can update
|
|
48
|
+
END IF;
|
|
49
|
+
|
|
50
|
+
-- Enable Row Level Security on the users table
|
|
51
|
+
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
|
|
52
|
+
|
|
53
|
+
-- Grant permissions to anon and authenticated roles
|
|
54
|
+
GRANT SELECT ON users TO anon;
|
|
55
|
+
GRANT SELECT, UPDATE ON users TO authenticated;
|
|
56
|
+
END $$;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- Migration: 004 - add reload_postgrest_schema function.
|
|
2
|
+
|
|
3
|
+
DO $$
|
|
4
|
+
BEGIN
|
|
5
|
+
-- Create a function to reload PostgREST schema
|
|
6
|
+
CREATE OR REPLACE FUNCTION reload_postgrest_schema()
|
|
7
|
+
RETURNS void
|
|
8
|
+
LANGUAGE plpgsql
|
|
9
|
+
AS $reload_function$
|
|
10
|
+
BEGIN
|
|
11
|
+
-- Method 1: Use NOTIFY to signal PostgREST to reload schema
|
|
12
|
+
-- PostgREST listens to 'pgrst' channel for schema changes
|
|
13
|
+
NOTIFY pgrst, 'reload schema';
|
|
14
|
+
|
|
15
|
+
RAISE NOTICE 'PostgREST schema reload notification sent';
|
|
16
|
+
END
|
|
17
|
+
$reload_function$;
|
|
18
|
+
|
|
19
|
+
-- Grant execute permission to project_admin and authenticated users
|
|
20
|
+
GRANT EXECUTE ON FUNCTION reload_postgrest_schema() TO project_admin;
|
|
21
|
+
GRANT EXECUTE ON FUNCTION reload_postgrest_schema() TO authenticated;
|
|
22
|
+
|
|
23
|
+
RAISE NOTICE 'PostgREST schema reload function created successfully';
|
|
24
|
+
END $$;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Migration: 005 - Enable project admin modify any users.
|
|
2
|
+
|
|
3
|
+
DO $$
|
|
4
|
+
BEGIN
|
|
5
|
+
-- Create policy to allow project_admin to update any user
|
|
6
|
+
IF NOT EXISTS (
|
|
7
|
+
SELECT 1 FROM pg_policies
|
|
8
|
+
WHERE tablename = 'users'
|
|
9
|
+
AND policyname = 'Allow project_admin to update any user'
|
|
10
|
+
) THEN
|
|
11
|
+
CREATE POLICY "Allow project_admin to update any user" ON users
|
|
12
|
+
FOR UPDATE
|
|
13
|
+
TO project_admin
|
|
14
|
+
USING (true)
|
|
15
|
+
WITH CHECK (true); -- Ensure project_admin always can update
|
|
16
|
+
END IF;
|
|
17
|
+
|
|
18
|
+
-- Grant necessary permissions
|
|
19
|
+
GRANT SELECT, UPDATE ON users TO project_admin;
|
|
20
|
+
|
|
21
|
+
-- Notify PostgREST to reload schema after policy changes
|
|
22
|
+
IF EXISTS (SELECT 1 FROM pg_proc WHERE proname = 'reload_postgrest_schema') THEN
|
|
23
|
+
PERFORM reload_postgrest_schema();
|
|
24
|
+
RAISE NOTICE 'PostgREST schema reload requested after migration';
|
|
25
|
+
ELSE
|
|
26
|
+
RAISE WARNING 'PostgREST reload function not found - please restart PostgREST manually';
|
|
27
|
+
END IF;
|
|
28
|
+
|
|
29
|
+
RAISE NOTICE 'Migration project-admin-update-users completed successfully';
|
|
30
|
+
END $$;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Migration: 006 - Modify AI usage table
|
|
2
|
+
-- This migration modifies the _ai_usage table to:
|
|
3
|
+
-- 1. Change foreign key constraint on config_id to SET NULL
|
|
4
|
+
-- 2. Make config_id nullable
|
|
5
|
+
-- 3. Add model_id column
|
|
6
|
+
|
|
7
|
+
-- Drop existing foreign key constraint
|
|
8
|
+
ALTER TABLE _ai_usage
|
|
9
|
+
DROP CONSTRAINT IF EXISTS _ai_usage_config_id_fkey;
|
|
10
|
+
|
|
11
|
+
-- Make config_id nullable
|
|
12
|
+
ALTER TABLE _ai_usage
|
|
13
|
+
ALTER COLUMN config_id DROP NOT NULL;
|
|
14
|
+
|
|
15
|
+
-- Add new foreign key constraint with SET NULL on delete
|
|
16
|
+
ALTER TABLE _ai_usage
|
|
17
|
+
ADD CONSTRAINT _ai_usage_config_id_fkey
|
|
18
|
+
FOREIGN KEY (config_id) REFERENCES _ai_configs(id) ON DELETE SET NULL;
|
|
19
|
+
|
|
20
|
+
-- Add new columns for model identification
|
|
21
|
+
ALTER TABLE _ai_usage
|
|
22
|
+
ADD COLUMN IF NOT EXISTS model_id VARCHAR(255);
|
|
23
|
+
|
|
24
|
+
-- Create indexes for the new columns
|
|
25
|
+
CREATE INDEX IF NOT EXISTS idx_ai_usage_model_id ON _ai_usage(model_id);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
-- Migration: 008 - Create new system tables and rename OAuth connections table
|
|
2
|
+
|
|
3
|
+
-- 1. Create _secrets table for storing application secrets
|
|
4
|
+
CREATE TABLE IF NOT EXISTS _secrets (
|
|
5
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
6
|
+
name TEXT UNIQUE NOT NULL,
|
|
7
|
+
value_ciphertext TEXT NOT NULL,
|
|
8
|
+
is_active BOOLEAN DEFAULT TRUE,
|
|
9
|
+
last_used_at TIMESTAMPTZ,
|
|
10
|
+
expires_at TIMESTAMPTZ,
|
|
11
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
12
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
-- 2. Create _oauth_configs table for OAuth provider configurations
|
|
16
|
+
CREATE TABLE IF NOT EXISTS _oauth_configs (
|
|
17
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
18
|
+
provider TEXT UNIQUE NOT NULL,
|
|
19
|
+
client_id TEXT,
|
|
20
|
+
secret_id UUID REFERENCES _secrets(id) ON DELETE RESTRICT,
|
|
21
|
+
scopes TEXT[],
|
|
22
|
+
redirect_uri TEXT,
|
|
23
|
+
use_shared_key BOOLEAN DEFAULT FALSE,
|
|
24
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
25
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- 3. Create _audit_logs table for storing admin operation logs
|
|
29
|
+
CREATE TABLE IF NOT EXISTS _audit_logs (
|
|
30
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
31
|
+
actor TEXT NOT NULL,
|
|
32
|
+
action TEXT NOT NULL,
|
|
33
|
+
module TEXT NOT NULL,
|
|
34
|
+
details JSONB,
|
|
35
|
+
ip_address INET,
|
|
36
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
37
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
-- 4. Rename _oauth_connections to _account_providers
|
|
41
|
+
DO $$
|
|
42
|
+
BEGIN
|
|
43
|
+
IF EXISTS (SELECT FROM information_schema.tables
|
|
44
|
+
WHERE table_name = '_oauth_connections' AND table_schema = 'public') THEN
|
|
45
|
+
IF EXISTS (SELECT FROM information_schema.tables
|
|
46
|
+
WHERE table_name = '_account_providers' AND table_schema = 'public') THEN
|
|
47
|
+
-- _account_providers already exists, just drop _oauth_connections
|
|
48
|
+
DROP TABLE _oauth_connections CASCADE;
|
|
49
|
+
ELSE
|
|
50
|
+
-- _account_providers doesn't exist, rename _oauth_connections to _account_providers
|
|
51
|
+
ALTER TABLE _oauth_connections RENAME TO _account_providers;
|
|
52
|
+
END IF;
|
|
53
|
+
END IF;
|
|
54
|
+
END $$;
|
|
55
|
+
|
|
56
|
+
-- 5. Drop the old _config system table
|
|
57
|
+
DROP TABLE IF EXISTS _config CASCADE;
|
|
58
|
+
|
|
59
|
+
-- Create indexes for better query performance
|
|
60
|
+
CREATE INDEX IF NOT EXISTS idx_secrets_name ON _secrets(name);
|
|
61
|
+
CREATE INDEX IF NOT EXISTS idx_oauth_configs_provider ON _oauth_configs(provider);
|
|
62
|
+
CREATE INDEX IF NOT EXISTS idx_audit_logs_actor ON _audit_logs(actor);
|
|
63
|
+
CREATE INDEX IF NOT EXISTS idx_audit_logs_module ON _audit_logs(module);
|
|
64
|
+
CREATE INDEX IF NOT EXISTS idx_audit_logs_created_at ON _audit_logs(created_at DESC);
|
|
65
|
+
|
|
66
|
+
-- Add triggers for updated_at
|
|
67
|
+
DROP TRIGGER IF EXISTS update__secrets_updated_at ON _secrets;
|
|
68
|
+
CREATE TRIGGER update__secrets_updated_at BEFORE UPDATE ON _secrets
|
|
69
|
+
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
70
|
+
|
|
71
|
+
DROP TRIGGER IF EXISTS update__oauth_configs_updated_at ON _oauth_configs;
|
|
72
|
+
CREATE TRIGGER update__oauth_configs_updated_at BEFORE UPDATE ON _oauth_configs
|
|
73
|
+
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
74
|
+
|
|
75
|
+
DROP TRIGGER IF EXISTS update__audit_logs_updated_at ON _audit_logs;
|
|
76
|
+
CREATE TRIGGER update__audit_logs_updated_at BEFORE UPDATE ON _audit_logs
|
|
77
|
+
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- Migration: 009 - Create function secrets table for edge functions environment variables
|
|
2
|
+
-- This table stores encrypted secrets that are injected into edge functions as Deno.env variables
|
|
3
|
+
|
|
4
|
+
CREATE TABLE IF NOT EXISTS _function_secrets (
|
|
5
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
6
|
+
key VARCHAR(255) UNIQUE NOT NULL,
|
|
7
|
+
value_ciphertext TEXT NOT NULL, -- Encrypted value using AES-256-GCM
|
|
8
|
+
is_reserved BOOLEAN DEFAULT FALSE, -- System-reserved keys that can't be modified/deleted
|
|
9
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
10
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
-- Create index for faster key lookups
|
|
14
|
+
CREATE INDEX IF NOT EXISTS idx_function_secrets_key ON _function_secrets(key);
|
|
15
|
+
|
|
16
|
+
-- Add trigger for updated_at
|
|
17
|
+
DROP TRIGGER IF EXISTS update__function_secrets_updated_at ON _function_secrets;
|
|
18
|
+
CREATE TRIGGER update__function_secrets_updated_at BEFORE UPDATE ON _function_secrets
|
|
19
|
+
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
20
|
+
|
|
21
|
+
-- Note: Reserved system secrets will be initialized by the application on startup
|
|
22
|
+
|
|
23
|
+
-- Rename _edge_functions table to functions
|
|
24
|
+
ALTER TABLE IF EXISTS _edge_functions RENAME TO _functions;
|