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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Auth router test script
|
|
4
|
+
|
|
5
|
+
# Get the directory where this script is located
|
|
6
|
+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
7
|
+
|
|
8
|
+
# Source the test configuration
|
|
9
|
+
source "$SCRIPT_DIR/../test-config.sh"
|
|
10
|
+
|
|
11
|
+
echo "🧪 Testing auth router..."
|
|
12
|
+
|
|
13
|
+
# Use configuration from test-config.sh
|
|
14
|
+
API_BASE="$TEST_API_BASE"
|
|
15
|
+
AUTH_TOKEN=""
|
|
16
|
+
|
|
17
|
+
# Test function
|
|
18
|
+
# $1: method, $2: endpoint, $3: data, $4: description, $5: extra header
|
|
19
|
+
# If $5 is not empty, it will be added as header
|
|
20
|
+
|
|
21
|
+
test_endpoint() {
|
|
22
|
+
local method=$1
|
|
23
|
+
local endpoint=$2
|
|
24
|
+
local data=$3
|
|
25
|
+
local description=$4
|
|
26
|
+
local extra_header=$5
|
|
27
|
+
|
|
28
|
+
print_info "Test: $description"
|
|
29
|
+
|
|
30
|
+
if [ "$method" = "GET" ]; then
|
|
31
|
+
response=$(curl -s -w "\n%{http_code}" -X GET "$endpoint" \
|
|
32
|
+
-H "Authorization: Bearer $AUTH_TOKEN" \
|
|
33
|
+
-H "Content-Type: application/json" $extra_header)
|
|
34
|
+
elif [ "$method" = "POST" ]; then
|
|
35
|
+
response=$(curl -s -w "\n%{http_code}" -X POST "$endpoint" \
|
|
36
|
+
-H "Content-Type: application/json" $extra_header \
|
|
37
|
+
-d "$data")
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
body=$(echo "$response" | head -n -1)
|
|
41
|
+
status=$(echo "$response" | tail -n 1)
|
|
42
|
+
|
|
43
|
+
if [ "$status" -ge 200 ] && [ "$status" -lt 300 ]; then
|
|
44
|
+
print_success "Success ($status)"
|
|
45
|
+
echo "Response: $body" | head -c 200
|
|
46
|
+
echo ""
|
|
47
|
+
else
|
|
48
|
+
print_fail "Failed ($status)"
|
|
49
|
+
echo "Error: $body"
|
|
50
|
+
fi
|
|
51
|
+
echo ""
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# 1. register new user
|
|
55
|
+
USER_EMAIL="${TEST_USER_EMAIL_PREFIX}$(date +%s)@example.com"
|
|
56
|
+
echo "USER_EMAIL: $USER_EMAIL"
|
|
57
|
+
USER_PASS="testpass123"
|
|
58
|
+
USER_NAME="${TEST_USER_EMAIL_PREFIX}$(date +%s)"
|
|
59
|
+
|
|
60
|
+
# Register user for cleanup
|
|
61
|
+
register_test_user "$USER_EMAIL"
|
|
62
|
+
|
|
63
|
+
echo "📝 Registering new user..."
|
|
64
|
+
register_response=$(curl -s -X POST "$API_BASE/auth/users" \
|
|
65
|
+
-H "Content-Type: application/json" \
|
|
66
|
+
-d '{"email":"'$USER_EMAIL'","password":"'$USER_PASS'","name":"'$USER_NAME'"}')
|
|
67
|
+
|
|
68
|
+
if echo "$register_response" | grep -q '"accessToken"'; then
|
|
69
|
+
print_success "Register success"
|
|
70
|
+
AUTH_TOKEN=$(echo "$register_response" | grep -o '"accessToken":"[^"]*"' | cut -d'"' -f4)
|
|
71
|
+
else
|
|
72
|
+
print_fail "Register failed"
|
|
73
|
+
echo "Response: $register_response"
|
|
74
|
+
track_test_failure
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
echo ""
|
|
78
|
+
|
|
79
|
+
# 2. login with correct password
|
|
80
|
+
echo "🔑 Logging in with correct password..."
|
|
81
|
+
login_response=$(curl -s -X POST "$API_BASE/auth/sessions" \
|
|
82
|
+
-H "Content-Type: application/json" \
|
|
83
|
+
-d '{"email":"'$USER_EMAIL'","password":"'$USER_PASS'"}')
|
|
84
|
+
|
|
85
|
+
if echo "$login_response" | grep -q '"accessToken"'; then
|
|
86
|
+
print_success "Login success"
|
|
87
|
+
AUTH_TOKEN=$(echo "$login_response" | grep -o '"accessToken":"[^"]*"' | cut -d'"' -f4)
|
|
88
|
+
else
|
|
89
|
+
print_fail "Login failed"
|
|
90
|
+
echo "Response: $login_response"
|
|
91
|
+
track_test_failure
|
|
92
|
+
fi
|
|
93
|
+
|
|
94
|
+
echo ""
|
|
95
|
+
|
|
96
|
+
# 3. login with wrong password
|
|
97
|
+
echo "🔒 Logging in with wrong password..."
|
|
98
|
+
wrong_login_response=$(curl -s -X POST "$API_BASE/auth/sessions" \
|
|
99
|
+
-H "Content-Type: application/json" \
|
|
100
|
+
-d '{"email":"'$USER_EMAIL'","password":"wrongpass"}')
|
|
101
|
+
|
|
102
|
+
if echo "$wrong_login_response" | grep -q '"Invalid credentials"'; then
|
|
103
|
+
print_success "Wrong password login failed as expected"
|
|
104
|
+
else
|
|
105
|
+
print_fail "Wrong password login did not fail"
|
|
106
|
+
echo "Response: $wrong_login_response"
|
|
107
|
+
track_test_failure
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
echo ""
|
|
111
|
+
|
|
112
|
+
# 4. register with duplicate email
|
|
113
|
+
echo "📝 Registering with duplicate email..."
|
|
114
|
+
duplicate_register_response=$(curl -s -X POST "$API_BASE/auth/users" \
|
|
115
|
+
-H "Content-Type: application/json" \
|
|
116
|
+
-d '{"email":"'$USER_EMAIL'","password":"'$USER_PASS'","name":"'$USER_NAME' duplicate"}')
|
|
117
|
+
|
|
118
|
+
if echo "$duplicate_register_response" | grep -q '"User already exists"'; then
|
|
119
|
+
print_success "Duplicate register failed as expected"
|
|
120
|
+
else
|
|
121
|
+
print_fail "Duplicate register did not fail"
|
|
122
|
+
echo "Response: $duplicate_register_response"
|
|
123
|
+
track_test_failure
|
|
124
|
+
fi
|
|
125
|
+
|
|
126
|
+
echo ""
|
|
127
|
+
|
|
128
|
+
# 5. get current user info
|
|
129
|
+
echo "👤 Getting current user info..."
|
|
130
|
+
me_response=$(curl -s -X GET "$API_BASE/auth/sessions/current" \
|
|
131
|
+
-H "Authorization: Bearer $AUTH_TOKEN" \
|
|
132
|
+
-H "Content-Type: application/json")
|
|
133
|
+
|
|
134
|
+
if echo "$me_response" | grep -q '"id"' && echo "$me_response" | grep -q '"email"'; then
|
|
135
|
+
print_success "Get current user info success"
|
|
136
|
+
echo "Response: $me_response" | head -c 200
|
|
137
|
+
echo ""
|
|
138
|
+
else
|
|
139
|
+
print_fail "Get current user info failed"
|
|
140
|
+
echo "Response: $me_response"
|
|
141
|
+
track_test_failure
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
print_success "🎉 Auth router test completed!"
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Simple database router test script
|
|
4
|
+
|
|
5
|
+
# Get the directory where this script is located
|
|
6
|
+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
7
|
+
|
|
8
|
+
# Source the test configuration
|
|
9
|
+
source "$SCRIPT_DIR/../test-config.sh"
|
|
10
|
+
|
|
11
|
+
echo "🧪 Testing database router..."
|
|
12
|
+
|
|
13
|
+
# Configuration
|
|
14
|
+
API_BASE="$TEST_API_BASE"
|
|
15
|
+
TEST_EMAIL="$TEST_ADMIN_EMAIL"
|
|
16
|
+
TEST_PASSWORD="$TEST_ADMIN_PASSWORD"
|
|
17
|
+
AUTH_TOKEN=""
|
|
18
|
+
|
|
19
|
+
# Dynamic table name to avoid conflicts
|
|
20
|
+
TEST_TABLE="test_products_$(date +%s)"
|
|
21
|
+
|
|
22
|
+
# Register table for cleanup
|
|
23
|
+
register_test_table "$TEST_TABLE"
|
|
24
|
+
|
|
25
|
+
# Test function
|
|
26
|
+
test_endpoint() {
|
|
27
|
+
local method=$1
|
|
28
|
+
local endpoint=$2
|
|
29
|
+
local data=$3
|
|
30
|
+
local description=$4
|
|
31
|
+
|
|
32
|
+
echo -e "${YELLOW}Test: $description${NC}"
|
|
33
|
+
|
|
34
|
+
if [ "$method" = "GET" ]; then
|
|
35
|
+
response=$(curl -s -w "\n%{http_code}" -X GET "$endpoint" \
|
|
36
|
+
-H "Authorization: Bearer $AUTH_TOKEN" \
|
|
37
|
+
-H "Content-Type: application/json")
|
|
38
|
+
elif [ "$method" = "POST" ]; then
|
|
39
|
+
response=$(curl -s -w "\n%{http_code}" -X POST "$endpoint" \
|
|
40
|
+
-H "Authorization: Bearer $AUTH_TOKEN" \
|
|
41
|
+
-H "Content-Type: application/json" \
|
|
42
|
+
-H "Prefer: return=representation" \
|
|
43
|
+
-d "$data")
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# Separate response body and status code
|
|
47
|
+
body=$(echo "$response" | sed '$d')
|
|
48
|
+
status=$(echo "$response" | tail -n 1)
|
|
49
|
+
|
|
50
|
+
if [ "$status" -ge 200 ] && [ "$status" -lt 300 ]; then
|
|
51
|
+
print_success "Success ($status)"
|
|
52
|
+
echo "Response: $body" | head -c 200
|
|
53
|
+
echo ""
|
|
54
|
+
else
|
|
55
|
+
print_fail "Failed ($status)"
|
|
56
|
+
echo "Error: $body"
|
|
57
|
+
fi
|
|
58
|
+
echo ""
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# 1. Login to get token
|
|
62
|
+
echo "🔑 Logging in to get authentication token..."
|
|
63
|
+
AUTH_TOKEN=$(get_admin_token)
|
|
64
|
+
|
|
65
|
+
if [ -n "$AUTH_TOKEN" ]; then
|
|
66
|
+
print_success "Login successful"
|
|
67
|
+
else
|
|
68
|
+
print_fail "Login failed"
|
|
69
|
+
echo "Please ensure the service is running and admin account exists"
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
# Get API key for database operations
|
|
73
|
+
API_KEY=""
|
|
74
|
+
if [ -n "$AUTH_TOKEN" ]; then
|
|
75
|
+
api_key_response=$(curl -s "$API_BASE/metadata/api-key" \
|
|
76
|
+
-H "Authorization: Bearer $AUTH_TOKEN")
|
|
77
|
+
if echo "$api_key_response" | grep -q '"apiKey"'; then
|
|
78
|
+
API_KEY=$(echo "$api_key_response" | grep -o '"apiKey":"[^"]*"' | cut -d'"' -f4)
|
|
79
|
+
print_success "API key obtained"
|
|
80
|
+
else
|
|
81
|
+
print_fail "Failed to get API key"
|
|
82
|
+
fi
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
# 2. Create test table
|
|
86
|
+
echo "📋 Creating test table($TEST_TABLE)..."
|
|
87
|
+
create_table_response=$(curl -s -X POST "$API_BASE/database/tables" \
|
|
88
|
+
-H "Authorization: Bearer $AUTH_TOKEN" \
|
|
89
|
+
-H "Content-Type: application/json" \
|
|
90
|
+
-d '{
|
|
91
|
+
"tableName": "'$TEST_TABLE'",
|
|
92
|
+
"rlsEnabled": false,
|
|
93
|
+
"columns":[
|
|
94
|
+
{
|
|
95
|
+
"columnName": "name",
|
|
96
|
+
"type": "string",
|
|
97
|
+
"isNullable": true,
|
|
98
|
+
"isUnique": false
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"columnName": "price",
|
|
102
|
+
"type": "float",
|
|
103
|
+
"isNullable": true,
|
|
104
|
+
"isUnique": false
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"columnName": "category",
|
|
108
|
+
"type": "string",
|
|
109
|
+
"isNullable": true,
|
|
110
|
+
"isUnique": false
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}')
|
|
114
|
+
|
|
115
|
+
if ! echo "$create_table_response" | grep -q '"error"'; then
|
|
116
|
+
echo -e "${GREEN}✅ Test table created successfully${NC}"
|
|
117
|
+
else
|
|
118
|
+
echo -e "${RED}❌ Test table creation failed${NC}"
|
|
119
|
+
echo "Response: $create_table_response"
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# 3. Test database router
|
|
123
|
+
print_info "🗄️ Testing database router..."
|
|
124
|
+
|
|
125
|
+
# Wait for the table to be created and synced
|
|
126
|
+
sleep 3
|
|
127
|
+
|
|
128
|
+
# Insert data
|
|
129
|
+
test_endpoint "POST" "$API_BASE/database/records/$TEST_TABLE" \
|
|
130
|
+
'[{"name":"iPhone 15","price":999.99,"category":"Electronics"}]' \
|
|
131
|
+
"Insert product data"
|
|
132
|
+
|
|
133
|
+
# Query data
|
|
134
|
+
test_endpoint "GET" "$API_BASE/database/records/$TEST_TABLE" \
|
|
135
|
+
"" \
|
|
136
|
+
"Query all products"
|
|
137
|
+
|
|
138
|
+
# Conditional query
|
|
139
|
+
test_endpoint "GET" "$API_BASE/database/records/$TEST_TABLE?category=eq.Electronics" \
|
|
140
|
+
"" \
|
|
141
|
+
"Query products by category"
|
|
142
|
+
|
|
143
|
+
# Select fields
|
|
144
|
+
test_endpoint "GET" "$API_BASE/database/records/$TEST_TABLE?select=name,price" \
|
|
145
|
+
"" \
|
|
146
|
+
"Select specific fields"
|
|
147
|
+
|
|
148
|
+
# Pagination query
|
|
149
|
+
test_endpoint "GET" "$API_BASE/database/records/$TEST_TABLE?limit=1&offset=0" \
|
|
150
|
+
"" \
|
|
151
|
+
"Pagination query"
|
|
152
|
+
|
|
153
|
+
# Test update table schema
|
|
154
|
+
echo -e "${YELLOW}🔧 Testing table schema update...${NC}"
|
|
155
|
+
|
|
156
|
+
# Add a new column
|
|
157
|
+
update_schema_response=$(curl -s -w "\n%{http_code}" -X PATCH "$API_BASE/database/tables/$TEST_TABLE/schema" \
|
|
158
|
+
-H "Authorization: Bearer $AUTH_TOKEN" \
|
|
159
|
+
-H "Content-Type: application/json" \
|
|
160
|
+
-d '{
|
|
161
|
+
"addColumns": [
|
|
162
|
+
{
|
|
163
|
+
"columnName": "discount",
|
|
164
|
+
"type": "float",
|
|
165
|
+
"isNullable": true,
|
|
166
|
+
"isUnique": false,
|
|
167
|
+
"defaultValue": "0.0"
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}')
|
|
171
|
+
|
|
172
|
+
body=$(echo "$update_schema_response" | sed '$d')
|
|
173
|
+
status=$(echo "$update_schema_response" | tail -n 1)
|
|
174
|
+
|
|
175
|
+
if [ "$status" -eq 200 ]; then
|
|
176
|
+
print_success "Added column successfully"
|
|
177
|
+
echo "Response: $body" | head -c 200
|
|
178
|
+
else
|
|
179
|
+
print_fail "Failed to add column ($status)"
|
|
180
|
+
echo "Error: $body"
|
|
181
|
+
fi
|
|
182
|
+
echo ""
|
|
183
|
+
|
|
184
|
+
# Test multiple operations
|
|
185
|
+
echo -e "${YELLOW}Test: Multiple schema operations${NC}"
|
|
186
|
+
multi_ops_response=$(curl -s -w "\n%{http_code}" -X PATCH "$API_BASE/database/tables/$TEST_TABLE/schema" \
|
|
187
|
+
-H "Authorization: Bearer $AUTH_TOKEN" \
|
|
188
|
+
-H "Content-Type: application/json" \
|
|
189
|
+
-d '{
|
|
190
|
+
"addColumns": [
|
|
191
|
+
{
|
|
192
|
+
"columnName": "brand",
|
|
193
|
+
"type": "string",
|
|
194
|
+
"isNullable": true,
|
|
195
|
+
"isUnique": false
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
"updateColumns": [
|
|
199
|
+
{
|
|
200
|
+
"columnName": "name",
|
|
201
|
+
"newColumnName": "product_name"
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
}')
|
|
205
|
+
|
|
206
|
+
body=$(echo "$multi_ops_response" | sed '$d')
|
|
207
|
+
status=$(echo "$multi_ops_response" | tail -n 1)
|
|
208
|
+
|
|
209
|
+
if [ "$status" -eq 200 ]; then
|
|
210
|
+
print_success "Multiple operations successful"
|
|
211
|
+
echo "Response: $body" | head -c 300
|
|
212
|
+
else
|
|
213
|
+
print_fail "Multiple operations failed ($status)"
|
|
214
|
+
echo "Error: $body"
|
|
215
|
+
fi
|
|
216
|
+
echo ""
|
|
217
|
+
|
|
218
|
+
echo -e "${GREEN}🎉 Database router test completed!${NC}"
|
|
219
|
+
echo ""
|
|
220
|
+
echo "📚 For more tests, see:"
|
|
221
|
+
echo " - examples/database-router-example.js"
|
|
222
|
+
echo " - docs/database-router.md"
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# End-to-End test script for Insforge Backend
|
|
4
|
+
|
|
5
|
+
# Get the directory where this script is located
|
|
6
|
+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
7
|
+
|
|
8
|
+
# Source the test configuration
|
|
9
|
+
source "$SCRIPT_DIR/../test-config.sh"
|
|
10
|
+
|
|
11
|
+
# Test variables
|
|
12
|
+
TEST_EMAIL="${TEST_USER_EMAIL_PREFIX}e2e_$(date +%s)@example.com"
|
|
13
|
+
TEST_PASSWORD="TestPassword123!"
|
|
14
|
+
USER_TOKEN=""
|
|
15
|
+
API_KEY=""
|
|
16
|
+
USER_ID=""
|
|
17
|
+
TEST_TABLE="test_todos_$(date +%s)"
|
|
18
|
+
TEST_BUCKET="test-bucket-$(date +%s)"
|
|
19
|
+
|
|
20
|
+
# Export API_KEY so cleanup can use it
|
|
21
|
+
export ACCESS_API_KEY=""
|
|
22
|
+
|
|
23
|
+
# Register test resources for cleanup
|
|
24
|
+
register_test_user "$TEST_EMAIL"
|
|
25
|
+
register_test_table "$TEST_TABLE"
|
|
26
|
+
register_test_bucket "$TEST_BUCKET"
|
|
27
|
+
|
|
28
|
+
echo "Starting End-to-End Tests for Insforge Backend"
|
|
29
|
+
echo "=================================="
|
|
30
|
+
|
|
31
|
+
# Function to test endpoint
|
|
32
|
+
test_endpoint() {
|
|
33
|
+
local test_name=$1
|
|
34
|
+
local response=$2
|
|
35
|
+
local expected_status=$3
|
|
36
|
+
local actual_status=$(echo "$response" | tail -n 1)
|
|
37
|
+
|
|
38
|
+
if [ "$actual_status" == "$expected_status" ]; then
|
|
39
|
+
print_success "$test_name"
|
|
40
|
+
return 0
|
|
41
|
+
else
|
|
42
|
+
print_fail "$test_name - Expected $expected_status, got $actual_status"
|
|
43
|
+
echo "Response: $(echo "$response" | sed '$d')"
|
|
44
|
+
return 1
|
|
45
|
+
fi
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# 1. Test Health Check
|
|
49
|
+
print_info "1. Testing Health Check"
|
|
50
|
+
response=$(curl -s -w "\n%{http_code}" "$TEST_API_BASE/health")
|
|
51
|
+
test_endpoint "Health check" "$response" "200"
|
|
52
|
+
|
|
53
|
+
# 2. Test User Registration
|
|
54
|
+
print_info "2. Testing User Registration"
|
|
55
|
+
response_with_code=$(register_user "$TEST_EMAIL" "$TEST_PASSWORD" "Test User" && echo -e "\n201")
|
|
56
|
+
test_endpoint "User registration" "$response_with_code" "201"
|
|
57
|
+
|
|
58
|
+
# Extract token from response
|
|
59
|
+
response=$(echo "$response_with_code" | sed '$d')
|
|
60
|
+
USER_TOKEN=$(echo "$response" | grep -o '"accessToken":"[^"]*' | grep -o '[^"]*$')
|
|
61
|
+
USER_ID=$(echo "$response" | grep -o '"user":{[^}]*' | grep -o '"id":"[^"]*' | grep -o '[^"]*$')
|
|
62
|
+
|
|
63
|
+
if [ -z "$USER_TOKEN" ]; then
|
|
64
|
+
print_fail "Failed to extract user token"
|
|
65
|
+
else
|
|
66
|
+
echo "User ID: $USER_ID"
|
|
67
|
+
echo "Token: ${USER_TOKEN:0:20}..."
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# 3. Test User Login
|
|
71
|
+
print_info "3. Testing User Login"
|
|
72
|
+
response_with_code=$(login_user "$TEST_EMAIL" "$TEST_PASSWORD" && echo -e "\n200")
|
|
73
|
+
test_endpoint "User login" "$response_with_code" "200"
|
|
74
|
+
|
|
75
|
+
# 4. Test Get Profile (with auth)
|
|
76
|
+
print_info "4. Testing Get Profile"
|
|
77
|
+
response_with_code=$(get_user_profile "$USER_TOKEN" && echo -e "\n200")
|
|
78
|
+
test_endpoint "Get profile" "$response_with_code" "200"
|
|
79
|
+
|
|
80
|
+
# Get admin token for table operations and API key
|
|
81
|
+
admin_token=$(get_admin_token)
|
|
82
|
+
if [ -z "$admin_token" ]; then
|
|
83
|
+
print_fail "Could not get admin token for table operations"
|
|
84
|
+
else
|
|
85
|
+
print_success "Got admin token for table operations"
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
# 5. Get API Key
|
|
89
|
+
print_info "5. Getting API Key"
|
|
90
|
+
# First try environment variable or docker logs
|
|
91
|
+
API_KEY=$(get_admin_api_key)
|
|
92
|
+
|
|
93
|
+
# If that fails, try to get it via the API endpoint
|
|
94
|
+
if [ -z "$API_KEY" ] && [ -n "$admin_token" ]; then
|
|
95
|
+
api_key_response=$(curl -s "$TEST_API_BASE/metadata/api-key" \
|
|
96
|
+
-H "Authorization: Bearer $admin_token")
|
|
97
|
+
API_KEY=$(echo "$api_key_response" | grep -o '"apiKey":"[^"]*' | cut -d'"' -f4)
|
|
98
|
+
fi
|
|
99
|
+
|
|
100
|
+
if [ -n "$API_KEY" ]; then
|
|
101
|
+
print_success "Got API key"
|
|
102
|
+
echo "API Key: ${API_KEY:0:20}..."
|
|
103
|
+
# Export for cleanup
|
|
104
|
+
export ACCESS_API_KEY="$API_KEY"
|
|
105
|
+
else
|
|
106
|
+
print_fail "Failed to get API key - remaining tests will be skipped"
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# Continue only if we have an API key
|
|
110
|
+
if [ -z "$API_KEY" ]; then
|
|
111
|
+
print_info "Skipping remaining tests - no API key available"
|
|
112
|
+
exit 0
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
# 6. Test Create Table
|
|
116
|
+
print_info "6. Testing Create Table"
|
|
117
|
+
response=$(curl -s -w "\n%{http_code}" -X POST "$TEST_API_BASE/database/tables" \
|
|
118
|
+
-H "Authorization: Bearer $admin_token" \
|
|
119
|
+
-H "Content-Type: application/json" \
|
|
120
|
+
-d "{
|
|
121
|
+
\"tableName\": \"$TEST_TABLE\",
|
|
122
|
+
\"rlsEnabled\": false,
|
|
123
|
+
\"columns\": [
|
|
124
|
+
{\"columnName\": \"title\", \"type\": \"string\", \"isNullable\": false, \"isUnique\": false},
|
|
125
|
+
{\"columnName\": \"completed\", \"type\": \"boolean\", \"isNullable\": false, \"isUnique\": false, \"defaultValue\": \"false\"},
|
|
126
|
+
{\"columnName\": \"user_id\", \"type\": \"string\", \"isNullable\": false, \"isUnique\": false}
|
|
127
|
+
]
|
|
128
|
+
}")
|
|
129
|
+
test_endpoint "Create table" "$response" "201"
|
|
130
|
+
|
|
131
|
+
# Wait a bit for table creation to propagate
|
|
132
|
+
sleep 1
|
|
133
|
+
|
|
134
|
+
# 7. Test Insert Record
|
|
135
|
+
print_info "7. Testing Insert Record"
|
|
136
|
+
response=$(curl -s -w "\n%{http_code}" -X POST "$TEST_API_BASE/database/records/$TEST_TABLE" \
|
|
137
|
+
-H "Authorization: Bearer $admin_token" \
|
|
138
|
+
-H "Content-Type: application/json" \
|
|
139
|
+
-d "[{
|
|
140
|
+
\"title\": \"Test Todo Item\",
|
|
141
|
+
\"completed\": false,
|
|
142
|
+
\"user_id\": \"$USER_ID\"
|
|
143
|
+
}]")
|
|
144
|
+
test_endpoint "Insert record" "$response" "201"
|
|
145
|
+
|
|
146
|
+
# Extract record ID
|
|
147
|
+
# PostgREST returns an empty array on successful insert, so we need to query the table
|
|
148
|
+
sleep 1 # Give PostgREST time to sync
|
|
149
|
+
query_response=$(curl -s "$TEST_API_BASE/database/records/$TEST_TABLE?limit=1&order=created_at.desc" \
|
|
150
|
+
-H "Authorization: Bearer $admin_token")
|
|
151
|
+
RECORD_ID=$(echo "$query_response" | jq -r '.[0].id' 2>/dev/null || echo "")
|
|
152
|
+
if [ -z "$RECORD_ID" ] || [ "$RECORD_ID" == "null" ]; then
|
|
153
|
+
# Try alternative parsing
|
|
154
|
+
RECORD_ID=$(echo "$query_response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
|
|
155
|
+
fi
|
|
156
|
+
echo "Record ID: $RECORD_ID"
|
|
157
|
+
|
|
158
|
+
# 8. Test Get Records
|
|
159
|
+
print_info "8. Testing Get Records"
|
|
160
|
+
response=$(curl -s -w "\n%{http_code}" "$TEST_API_BASE/database/records/$TEST_TABLE" \
|
|
161
|
+
-H "Authorization: Bearer $admin_token")
|
|
162
|
+
test_endpoint "Get records" "$response" "200"
|
|
163
|
+
|
|
164
|
+
# 9. Test Update Record
|
|
165
|
+
if [ -n "$RECORD_ID" ]; then
|
|
166
|
+
print_info "9. Testing Update Record"
|
|
167
|
+
response=$(curl -s -w "\n%{http_code}" -X PATCH "$TEST_API_BASE/database/records/$TEST_TABLE?id=eq.$RECORD_ID" \
|
|
168
|
+
-H "Authorization: Bearer $admin_token" \
|
|
169
|
+
-H "Content-Type: application/json" \
|
|
170
|
+
-d '{
|
|
171
|
+
"completed": true
|
|
172
|
+
}')
|
|
173
|
+
test_endpoint "Update record" "$response" "204"
|
|
174
|
+
else
|
|
175
|
+
print_info "9. Skipping Update Record test - no record ID"
|
|
176
|
+
fi
|
|
177
|
+
|
|
178
|
+
# 10. Test Storage - Create Bucket
|
|
179
|
+
print_info "10. Testing Create Storage Bucket"
|
|
180
|
+
response=$(curl -s -w "\n%{http_code}" -X POST "$TEST_API_BASE/storage/buckets" \
|
|
181
|
+
-H "Authorization: Bearer $API_KEY" \
|
|
182
|
+
-H "Content-Type: application/json" \
|
|
183
|
+
-d "{
|
|
184
|
+
\"bucketName\": \"$TEST_BUCKET\",
|
|
185
|
+
\"isPublic\": false
|
|
186
|
+
}")
|
|
187
|
+
test_endpoint "Create bucket" "$response" "201"
|
|
188
|
+
|
|
189
|
+
# 11. Test Upload File
|
|
190
|
+
print_info "11. Testing Upload File"
|
|
191
|
+
echo "Test file content" > /tmp/test-upload.txt
|
|
192
|
+
response=$(curl -s -w "\n%{http_code}" -X PUT "$TEST_API_BASE/storage/buckets/$TEST_BUCKET/objects/test-file.txt" \
|
|
193
|
+
-H "Authorization: Bearer $API_KEY" \
|
|
194
|
+
-F "file=@/tmp/test-upload.txt")
|
|
195
|
+
test_endpoint "Upload file" "$response" "201"
|
|
196
|
+
|
|
197
|
+
# 12. Test Download File
|
|
198
|
+
print_info "12. Testing Download File"
|
|
199
|
+
response=$(curl -s -w "\n%{http_code}" "$TEST_API_BASE/storage/buckets/$TEST_BUCKET/objects/test-file.txt" \
|
|
200
|
+
-H "Authorization: Bearer $API_KEY" \
|
|
201
|
+
-o /tmp/test-download.txt)
|
|
202
|
+
test_endpoint "Download file" "$response" "200"
|
|
203
|
+
|
|
204
|
+
# Verify file content
|
|
205
|
+
if [ -f /tmp/test-download.txt ]; then
|
|
206
|
+
downloaded_content=$(cat /tmp/test-download.txt)
|
|
207
|
+
if [ "$downloaded_content" == "Test file content" ]; then
|
|
208
|
+
print_success "File content verified"
|
|
209
|
+
else
|
|
210
|
+
print_fail "File content mismatch"
|
|
211
|
+
fi
|
|
212
|
+
rm -f /tmp/test-download.txt
|
|
213
|
+
else
|
|
214
|
+
print_fail "Downloaded file not found"
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
# 13. Test Delete Record
|
|
218
|
+
if [ -n "$RECORD_ID" ]; then
|
|
219
|
+
print_info "13. Testing Delete Record"
|
|
220
|
+
response=$(curl -s -w "\n%{http_code}" -X DELETE "$TEST_API_BASE/database/records/$TEST_TABLE?id=eq.$RECORD_ID" \
|
|
221
|
+
-H "Authorization: Bearer $admin_token")
|
|
222
|
+
test_endpoint "Delete record" "$response" "204"
|
|
223
|
+
else
|
|
224
|
+
print_info "13. Skipping Delete Record test - no record ID"
|
|
225
|
+
fi
|
|
226
|
+
|
|
227
|
+
# 14. Test Delete File
|
|
228
|
+
print_info "14. Testing Delete File"
|
|
229
|
+
response=$(curl -s -w "\n%{http_code}" -X DELETE "$TEST_API_BASE/storage/buckets/$TEST_BUCKET/objects/test-file.txt" \
|
|
230
|
+
-H "Authorization: Bearer $API_KEY")
|
|
231
|
+
test_endpoint "Delete file" "$response" "200"
|
|
232
|
+
|
|
233
|
+
# Clean up temp files
|
|
234
|
+
rm -f /tmp/test-upload.txt
|
|
235
|
+
|
|
236
|
+
echo ""
|
|
237
|
+
echo "=================================="
|
|
238
|
+
print_success "End-to-End tests completed!"
|
|
239
|
+
echo "=================================="
|
|
240
|
+
|
|
241
|
+
# Note: All test resources will be cleaned up automatically on exit
|