devpush 0.0.0-stage → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/agent-release.json +37 -0
- package/dist/package/LICENSE.md +21 -0
- package/dist/package/migrate.mjs +182 -0
- package/dist/package/plugins.mjs +125 -0
- package/dist/package/vite.mjs +439 -0
- package/package.json +170 -4
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon.svg +1 -0
- package/public/logo-email.png +0 -0
- package/public/robots.txt +3 -0
- package/public/social.png +0 -0
- package/src/cloudflare-runtime.d.ts +78 -0
- package/src/components/about-dialog.tsx +70 -0
- package/src/components/copy-button.tsx +74 -0
- package/src/components/logo-mark.tsx +20 -0
- package/src/components/pending-collection.tsx +103 -0
- package/src/components/resource-avatar.tsx +65 -0
- package/src/components/route-error-state.tsx +95 -0
- package/src/components/section-navigation.tsx +39 -0
- package/src/components/settings-layout.tsx +111 -0
- package/src/components/storage-capabilities.tsx +11 -0
- package/src/components/table-pager.tsx +101 -0
- package/src/components/ui/alert-dialog.tsx +180 -0
- package/src/components/ui/alert.tsx +78 -0
- package/src/components/ui/avatar.tsx +58 -0
- package/src/components/ui/badge.tsx +49 -0
- package/src/components/ui/button-group.tsx +38 -0
- package/src/components/ui/button.tsx +67 -0
- package/src/components/ui/card.tsx +82 -0
- package/src/components/ui/chart.tsx +307 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/combobox.tsx +256 -0
- package/src/components/ui/dialog.tsx +163 -0
- package/src/components/ui/dropdown-menu.tsx +110 -0
- package/src/components/ui/empty.tsx +65 -0
- package/src/components/ui/field.tsx +192 -0
- package/src/components/ui/input-group.tsx +118 -0
- package/src/components/ui/input-otp.tsx +70 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/pagination.tsx +34 -0
- package/src/components/ui/popover.tsx +86 -0
- package/src/components/ui/select.tsx +145 -0
- package/src/components/ui/skeleton.tsx +19 -0
- package/src/components/ui/sonner.tsx +47 -0
- package/src/components/ui/switch.tsx +31 -0
- package/src/components/ui/table.tsx +81 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +55 -0
- package/src/features/admin/admin-settings.tsx +1048 -0
- package/src/features/auth/current-user-context-query.ts +11 -0
- package/src/features/auth/login-form.tsx +442 -0
- package/src/features/auth/sign-out-menu-item.tsx +42 -0
- package/src/features/deployments/deployment-actions.tsx +336 -0
- package/src/features/deployments/deployment-alias-badge.tsx +35 -0
- package/src/features/deployments/deployment-detail.tsx +596 -0
- package/src/features/deployments/deployment-filters.ts +66 -0
- package/src/features/deployments/deployment-list.tsx +465 -0
- package/src/features/deployments/deployment-visit-links.tsx +104 -0
- package/src/features/deployments/deployments-page.tsx +376 -0
- package/src/features/logs/log-scroll-area.tsx +69 -0
- package/src/features/notifications/email-preferences.tsx +232 -0
- package/src/features/onboarding/profile-onboarding.tsx +162 -0
- package/src/features/plugins/contributions.tsx +118 -0
- package/src/features/projects/backup-job-logs.tsx +143 -0
- package/src/features/projects/backup-policy-delete-dialog.tsx +82 -0
- package/src/features/projects/backup-restore-actions.tsx +573 -0
- package/src/features/projects/backup-status-icon.tsx +33 -0
- package/src/features/projects/backup-target-list.tsx +222 -0
- package/src/features/projects/backup-timestamp.tsx +32 -0
- package/src/features/projects/backup-volume-picker.tsx +158 -0
- package/src/features/projects/compose-service-input.tsx +64 -0
- package/src/features/projects/deploy-readiness.ts +28 -0
- package/src/features/projects/environment-dot.tsx +91 -0
- package/src/features/projects/log-keyword-filter.tsx +48 -0
- package/src/features/projects/manual-deploy-dialog.tsx +563 -0
- package/src/features/projects/pending-section.ts +26 -0
- package/src/features/projects/project-backup-details-pending.tsx +305 -0
- package/src/features/projects/project-backup-details.tsx +936 -0
- package/src/features/projects/project-backup-policy.tsx +644 -0
- package/src/features/projects/project-backup-utils.ts +190 -0
- package/src/features/projects/project-backups-pending.tsx +136 -0
- package/src/features/projects/project-backups.tsx +876 -0
- package/src/features/projects/project-environment-settings.tsx +1128 -0
- package/src/features/projects/project-heading.tsx +68 -0
- package/src/features/projects/project-layout.tsx +188 -0
- package/src/features/projects/project-logs.tsx +461 -0
- package/src/features/projects/project-overview.tsx +280 -0
- package/src/features/projects/project-route-pending.tsx +1064 -0
- package/src/features/projects/project-routing-settings.tsx +663 -0
- package/src/features/projects/project-settings-section.tsx +64 -0
- package/src/features/projects/project-settings-utils.ts +101 -0
- package/src/features/projects/project-settings.tsx +1472 -0
- package/src/features/projects/repository-picker-dialog.tsx +404 -0
- package/src/features/repositories/new-project-dialog-launcher.tsx +44 -0
- package/src/features/repositories/new-project-dialog.tsx +1204 -0
- package/src/features/repositories/new-project-pending.tsx +28 -0
- package/src/features/repositories/repository-list-pending.tsx +59 -0
- package/src/features/servers/server-availability-alert.tsx +44 -0
- package/src/features/servers/server-availability.ts +29 -0
- package/src/features/servers/server-avatar.tsx +52 -0
- package/src/features/servers/server-detail-pending.tsx +315 -0
- package/src/features/servers/server-detail.tsx +855 -0
- package/src/features/servers/server-metric-chart-pending.tsx +38 -0
- package/src/features/servers/server-metric-chart.tsx +182 -0
- package/src/features/servers/server-metric-format.ts +50 -0
- package/src/features/servers/server-metrics-pending.tsx +75 -0
- package/src/features/servers/server-metrics.tsx +136 -0
- package/src/features/servers/team-servers.tsx +432 -0
- package/src/features/settings/settings-route-pending.tsx +406 -0
- package/src/features/teams/backup-storage-settings.tsx +483 -0
- package/src/features/teams/navigation.ts +51 -0
- package/src/features/teams/new-team-dialog.tsx +132 -0
- package/src/features/teams/pending-section.ts +19 -0
- package/src/features/teams/team-header.tsx +1286 -0
- package/src/features/teams/team-heading.tsx +57 -0
- package/src/features/teams/team-home.tsx +391 -0
- package/src/features/teams/team-invite.tsx +155 -0
- package/src/features/teams/team-route-pending.tsx +505 -0
- package/src/features/teams/team-settings.tsx +1555 -0
- package/src/features/teams/use-workspace-updates.ts +126 -0
- package/src/features/users/api-keys-settings.tsx +544 -0
- package/src/features/users/api-scope-selection.tsx +269 -0
- package/src/features/users/connected-apps-settings.tsx +449 -0
- package/src/features/users/mcp-consent.tsx +220 -0
- package/src/features/users/profile-picture.tsx +171 -0
- package/src/features/users/user-settings.tsx +1064 -0
- package/src/lib/account-settings-schema.ts +78 -0
- package/src/lib/action-feedback.ts +81 -0
- package/src/lib/admin-search-schema.ts +8 -0
- package/src/lib/agent-release.d.mts +21 -0
- package/src/lib/agent-release.mjs +90 -0
- package/src/lib/allowlist-schema.ts +79 -0
- package/src/lib/api-key-schema.ts +176 -0
- package/src/lib/auth/client.ts +20 -0
- package/src/lib/avatar-schema.ts +11 -0
- package/src/lib/backup-cron.ts +118 -0
- package/src/lib/backup-database.ts +41 -0
- package/src/lib/backup-feature.ts +2 -0
- package/src/lib/backup-paths.ts +7 -0
- package/src/lib/backup-policy-schema.ts +85 -0
- package/src/lib/backup-resource-schema.ts +12 -0
- package/src/lib/backup-restore-schema.ts +15 -0
- package/src/lib/backup-storage-schema.ts +55 -0
- package/src/lib/deferred-module.ts +38 -0
- package/src/lib/deployment-logs-query.ts +63 -0
- package/src/lib/display-name.ts +7 -0
- package/src/lib/error-message.ts +119 -0
- package/src/lib/form-errors.ts +10 -0
- package/src/lib/internal-redirect.ts +25 -0
- package/src/lib/manual-deploy-options-query.ts +21 -0
- package/src/lib/notification-preferences.ts +43 -0
- package/src/lib/onboarding.ts +11 -0
- package/src/lib/operation-logs-query.ts +51 -0
- package/src/lib/page-head.ts +14 -0
- package/src/lib/project-context-query.ts +257 -0
- package/src/lib/project-creation-schema.ts +64 -0
- package/src/lib/project-env-schema.ts +23 -0
- package/src/lib/project-environments-schema.ts +56 -0
- package/src/lib/project-routing-schema.ts +94 -0
- package/src/lib/project-runtime-config.ts +131 -0
- package/src/lib/project-settings-schema.ts +75 -0
- package/src/lib/public-api-schema.ts +128 -0
- package/src/lib/public-error.ts +337 -0
- package/src/lib/query.ts +13 -0
- package/src/lib/repository-selection-query.ts +11 -0
- package/src/lib/resource-cache.ts +30 -0
- package/src/lib/runtime-id.ts +19 -0
- package/src/lib/search.ts +14 -0
- package/src/lib/server-context-query.ts +43 -0
- package/src/lib/server-name-schema.ts +11 -0
- package/src/lib/settings-conflict.ts +45 -0
- package/src/lib/settings-version.ts +7 -0
- package/src/lib/team-context-query.ts +126 -0
- package/src/lib/team-context-schema.ts +8 -0
- package/src/lib/team-forms-schema.ts +45 -0
- package/src/lib/team-role.ts +13 -0
- package/src/lib/team-settings-schema.ts +48 -0
- package/src/lib/urls.ts +3 -0
- package/src/lib/use-avatar-input.ts +61 -0
- package/src/lib/use-refresh-error.ts +18 -0
- package/src/lib/use-settings-version.ts +23 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/validation.ts +5 -0
- package/src/lib/workspace-updates.ts +53 -0
- package/src/package/config.ts +10 -0
- package/src/package/env.mjs +54 -0
- package/src/package/migrate-api.d.ts +5 -0
- package/src/package/migrate.ts +56 -0
- package/src/package/plugins.ts +141 -0
- package/src/package/sqlite.mjs +2 -0
- package/src/package/vite-api.d.ts +5 -0
- package/src/package/vite.ts +324 -0
- package/src/package/watch-guard.cjs +26 -0
- package/src/plugins/client.ts +57 -0
- package/src/plugins/contract.ts +188 -0
- package/src/plugins/default.server.ts +4 -0
- package/src/plugins/default.ui.ts +4 -0
- package/src/plugins/operations.ts +45 -0
- package/src/plugins/server.ts +197 -0
- package/src/plugins/version.ts +1 -0
- package/src/routeTree.gen.ts +1275 -0
- package/src/router.tsx +46 -0
- package/src/routes/$teamSlug.index.tsx +53 -0
- package/src/routes/$teamSlug.new-project.tsx +13 -0
- package/src/routes/$teamSlug.projects.$projectName.backups.$backupId.tsx +40 -0
- package/src/routes/$teamSlug.projects.$projectName.backups.tsx +82 -0
- package/src/routes/$teamSlug.projects.$projectName.deployments.$deploymentId.tsx +52 -0
- package/src/routes/$teamSlug.projects.$projectName.deployments.tsx +86 -0
- package/src/routes/$teamSlug.projects.$projectName.logs.tsx +55 -0
- package/src/routes/$teamSlug.projects.$projectName.settings.tsx +51 -0
- package/src/routes/$teamSlug.projects.$projectName.tsx +106 -0
- package/src/routes/$teamSlug.projects.tsx +40 -0
- package/src/routes/$teamSlug.servers.$serverId.tsx +31 -0
- package/src/routes/$teamSlug.servers.index.tsx +59 -0
- package/src/routes/$teamSlug.servers.tsx +7 -0
- package/src/routes/$teamSlug.settings.tsx +56 -0
- package/src/routes/$teamSlug.tsx +86 -0
- package/src/routes/[.]well-known.oauth-authorization-server.api.auth.ts +13 -0
- package/src/routes/[.]well-known.oauth-protected-resource.mcp.ts +6 -0
- package/src/routes/__root.tsx +155 -0
- package/src/routes/admin.tsx +55 -0
- package/src/routes/api/agents/certificates.ts +21 -0
- package/src/routes/api/agents/credentials/rotate.ts +22 -0
- package/src/routes/api/agents/heartbeat.ts +42 -0
- package/src/routes/api/agents/job-logs.ts +22 -0
- package/src/routes/api/agents/jobs/complete.ts +22 -0
- package/src/routes/api/agents/jobs/next.ts +29 -0
- package/src/routes/api/agents/jobs/progress.ts +32 -0
- package/src/routes/api/agents/jobs/status.ts +22 -0
- package/src/routes/api/agents/register.ts +45 -0
- package/src/routes/api/agents/runtime-logs.ts +22 -0
- package/src/routes/api/agents/switch.ts +25 -0
- package/src/routes/api/auth/$.ts +38 -0
- package/src/routes/api/cron/backups.ts +33 -0
- package/src/routes/api/cron/maintenance.ts +30 -0
- package/src/routes/api/github/install.callback.ts +51 -0
- package/src/routes/api/github/install.ts +41 -0
- package/src/routes/api/github/webhook.ts +11 -0
- package/src/routes/api/health.ts +19 -0
- package/src/routes/api/install/agent.$token.ts +50 -0
- package/src/routes/api/install/agent.binary.ts +83 -0
- package/src/routes/api/install/agent.checksum.ts +45 -0
- package/src/routes/api/install/agent.ts +26 -0
- package/src/routes/api/plugins/$.ts +11 -0
- package/src/routes/api/v1/$.ts +15 -0
- package/src/routes/api/workspaces/updates.ts +8 -0
- package/src/routes/auth.login.tsx +50 -0
- package/src/routes/deployments.$deploymentId.unavailable.tsx +21 -0
- package/src/routes/index.tsx +23 -0
- package/src/routes/invites.$token.tsx +35 -0
- package/src/routes/mcp.ts +13 -0
- package/src/routes/oauth.consent.tsx +54 -0
- package/src/routes/onboarding.tsx +37 -0
- package/src/routes/onboarding.workspace.tsx +44 -0
- package/src/routes/settings.tsx +30 -0
- package/src/routes/uploads/avatars/$fileName.ts +44 -0
- package/src/server/admin/access.ts +67 -0
- package/src/server/admin/functions.ts +122 -0
- package/src/server/admin/service.ts +260 -0
- package/src/server/agents/backup-state.ts +210 -0
- package/src/server/agents/certificates.ts +96 -0
- package/src/server/agents/claims.ts +116 -0
- package/src/server/agents/cleanup.ts +52 -0
- package/src/server/agents/compatibility.ts +116 -0
- package/src/server/agents/completion.ts +83 -0
- package/src/server/agents/container-cleanup-state.ts +51 -0
- package/src/server/agents/deployment-state.ts +111 -0
- package/src/server/agents/job-payloads.ts +159 -0
- package/src/server/agents/jobs.ts +1293 -0
- package/src/server/agents/protocol.ts +400 -0
- package/src/server/agents/reconciliation.ts +43 -0
- package/src/server/agents/runtime-logs.ts +337 -0
- package/src/server/agents/runtime-state.ts +125 -0
- package/src/server/api/admission.ts +12 -0
- package/src/server/api/authorization.ts +115 -0
- package/src/server/api/credentials.ts +569 -0
- package/src/server/api/cursors.ts +72 -0
- package/src/server/api/errors.ts +24 -0
- package/src/server/api/functions.ts +60 -0
- package/src/server/api/handler.ts +274 -0
- package/src/server/api/mutation-operations.ts +913 -0
- package/src/server/api/operation-context.ts +139 -0
- package/src/server/api/operation-contract.ts +1099 -0
- package/src/server/api/operations.ts +64 -0
- package/src/server/api/read-operations.ts +891 -0
- package/src/server/api/retention.ts +33 -0
- package/src/server/auth/access.ts +109 -0
- package/src/server/auth/auth-methods.ts +28 -0
- package/src/server/auth/better-auth.ts +518 -0
- package/src/server/auth/context.ts +28 -0
- package/src/server/auth/email-change.ts +47 -0
- package/src/server/auth/email-delivery.ts +51 -0
- package/src/server/auth/provider-identity.ts +19 -0
- package/src/server/auth/provider-tokens.ts +27 -0
- package/src/server/auth/session.server.ts +19 -0
- package/src/server/backups/database-commands.ts +40 -0
- package/src/server/backups/destination.ts +12 -0
- package/src/server/backups/feature.ts +6 -0
- package/src/server/backups/policy-validation.ts +51 -0
- package/src/server/backups/queue-state.ts +137 -0
- package/src/server/backups/service.ts +918 -0
- package/src/server/backups/storage-functions.ts +42 -0
- package/src/server/backups/storage-state.ts +67 -0
- package/src/server/backups/storage.ts +237 -0
- package/src/server/config.ts +274 -0
- package/src/server/db/atomic.ts +16 -0
- package/src/server/db/d1-connection.ts +83 -0
- package/src/server/db/errors.ts +17 -0
- package/src/server/db/index.cloudflare.ts +15 -0
- package/src/server/db/index.ts +35 -0
- package/src/server/db/libsql-connection.ts +72 -0
- package/src/server/db/log-schema.ts +102 -0
- package/src/server/db/migrate-libsql.ts +29 -0
- package/src/server/db/migrate-sqlite.ts +47 -0
- package/src/server/db/migration-history.ts +12 -0
- package/src/server/db/migrations-logs/0000_initial.sql +48 -0
- package/src/server/db/migrations-logs/0001_runtime_log_order.sql +2 -0
- package/src/server/db/migrations-logs/meta/0000_snapshot.json +327 -0
- package/src/server/db/migrations-logs/meta/0001_snapshot.json +329 -0
- package/src/server/db/migrations-logs/meta/_journal.json +20 -0
- package/src/server/db/migrations-sqlite/0000_initial.sql +894 -0
- package/src/server/db/migrations-sqlite/0001_agent_indexes.sql +5 -0
- package/src/server/db/migrations-sqlite/meta/0000_snapshot.json +5816 -0
- package/src/server/db/migrations-sqlite/meta/0001_snapshot.json +5841 -0
- package/src/server/db/migrations-sqlite/meta/_journal.json +20 -0
- package/src/server/db/oauth-schema.ts +216 -0
- package/src/server/db/remote-config.ts +47 -0
- package/src/server/db/schema.ts +1218 -0
- package/src/server/db/sqlite-connection.ts +94 -0
- package/src/server/db/sqlite-files.ts +27 -0
- package/src/server/db/sqlite-params.ts +19 -0
- package/src/server/db/worker-connection.ts +47 -0
- package/src/server/deleted-resources.ts +133 -0
- package/src/server/deletion-recovery.ts +272 -0
- package/src/server/email/layout.tsx +85 -0
- package/src/server/email/notification-template.tsx +62 -0
- package/src/server/email/otp-template.tsx +48 -0
- package/src/server/email/service.ts +251 -0
- package/src/server/email/team-invite-template.tsx +59 -0
- package/src/server/email/theme.ts +10 -0
- package/src/server/github/http.ts +14 -0
- package/src/server/github/install-state.ts +48 -0
- package/src/server/github/service.ts +831 -0
- package/src/server/github/webhook-handler.ts +198 -0
- package/src/server/github/webhooks.ts +205 -0
- package/src/server/http/auth.ts +11 -0
- package/src/server/http/error-diagnostics.ts +66 -0
- package/src/server/http/plugin-request.ts +15 -0
- package/src/server/http/proxy-request.ts +53 -0
- package/src/server/http/public-errors.ts +48 -0
- package/src/server/http/rate-limit.ts +59 -0
- package/src/server/http/request-body.ts +54 -0
- package/src/server/http/request-ip.ts +54 -0
- package/src/server/http/security-headers.ts +36 -0
- package/src/server/install/agent-binary.ts +230 -0
- package/src/server/install/agent-script.ts +565 -0
- package/src/server/install/release-binary.ts +65 -0
- package/src/server/logs/budget.ts +72 -0
- package/src/server/logs/cleanup.ts +64 -0
- package/src/server/logs/deployments.ts +98 -0
- package/src/server/logs/operations.ts +145 -0
- package/src/server/logs/retention.ts +39 -0
- package/src/server/maintenance.ts +61 -0
- package/src/server/mcp/connections.ts +358 -0
- package/src/server/mcp/functions.ts +63 -0
- package/src/server/mcp/handler.ts +295 -0
- package/src/server/mcp/oauth-discovery.cloudflare.ts +6 -0
- package/src/server/mcp/oauth-discovery.ts +8 -0
- package/src/server/mcp/oauth-provider.ts +220 -0
- package/src/server/mcp/urls.ts +20 -0
- package/src/server/notifications/functions.ts +51 -0
- package/src/server/notifications/observe.ts +303 -0
- package/src/server/notifications/outbox.ts +335 -0
- package/src/server/notifications/preferences.ts +131 -0
- package/src/server/notifications/query.ts +16 -0
- package/src/server/plugins/scope.ts +17 -0
- package/src/server/plugins/server-context.ts +157 -0
- package/src/server/plugins/services.server.ts +10 -0
- package/src/server/plugins/workspace-access.ts +74 -0
- package/src/server/projects/backup-policy-state.ts +68 -0
- package/src/server/projects/backups.ts +219 -0
- package/src/server/projects/compose-metadata.ts +174 -0
- package/src/server/projects/configuration-state.ts +90 -0
- package/src/server/projects/context.ts +909 -0
- package/src/server/projects/creation-state.ts +46 -0
- package/src/server/projects/deletion-state.ts +69 -0
- package/src/server/projects/deployment-config.ts +139 -0
- package/src/server/projects/deployment-logs.ts +97 -0
- package/src/server/projects/deployments.ts +1123 -0
- package/src/server/projects/domain-state.ts +71 -0
- package/src/server/projects/environment-branches.ts +75 -0
- package/src/server/projects/environment-state.ts +158 -0
- package/src/server/projects/environments.ts +424 -0
- package/src/server/projects/functions.ts +748 -0
- package/src/server/projects/generated-hostname.ts +77 -0
- package/src/server/projects/hostnames.ts +244 -0
- package/src/server/projects/mappers.ts +457 -0
- package/src/server/projects/names.ts +41 -0
- package/src/server/projects/project-env-vars.ts +28 -0
- package/src/server/projects/queue-state.ts +118 -0
- package/src/server/projects/repository.ts +368 -0
- package/src/server/projects/route-state.ts +37 -0
- package/src/server/projects/runtime-logs.ts +97 -0
- package/src/server/projects/settings-context.ts +58 -0
- package/src/server/projects/settings.ts +738 -0
- package/src/server/projects/types.ts +355 -0
- package/src/server/realtime/agent-events.ts +32 -0
- package/src/server/realtime/node-broadcaster.ts +71 -0
- package/src/server/realtime/node-handler.ts +55 -0
- package/src/server/realtime/service.ts +125 -0
- package/src/server/realtime/workspace-object.cloudflare.ts +62 -0
- package/src/server/realtime/workspace-object.ts +3 -0
- package/src/server/resources/color.ts +13 -0
- package/src/server/runtime/background.ts +21 -0
- package/src/server/runtime/node-asset-cache-plugin.ts +12 -0
- package/src/server/runtime/node-scheduler-plugin.ts +17 -0
- package/src/server/runtime/node-scheduler.ts +51 -0
- package/src/server/runtime/platform-env.cloudflare.ts +17 -0
- package/src/server/runtime/platform-env.ts +19 -0
- package/src/server/runtime/scheduled-task-error.ts +9 -0
- package/src/server/scheduled-tasks.ts +28 -0
- package/src/server/secrets/crypto.ts +56 -0
- package/src/server/servers/functions.ts +233 -0
- package/src/server/servers/lifecycle.ts +122 -0
- package/src/server/servers/metric-history-schema.ts +24 -0
- package/src/server/servers/metric-history.ts +55 -0
- package/src/server/servers/monitoring.ts +592 -0
- package/src/server/servers/service.ts +1211 -0
- package/src/server/servers/status.ts +32 -0
- package/src/server/servers/switch.ts +96 -0
- package/src/server/settings-version.ts +43 -0
- package/src/server/storage/capabilities.ts +6 -0
- package/src/server/storage/local-object-store.cloudflare.ts +7 -0
- package/src/server/storage/local-object-store.ts +50 -0
- package/src/server/storage/object-store.ts +160 -0
- package/src/server/teams/creation.ts +51 -0
- package/src/server/teams/delete-policy.ts +13 -0
- package/src/server/teams/deletion-state.ts +80 -0
- package/src/server/teams/functions.ts +324 -0
- package/src/server/teams/invitations.ts +38 -0
- package/src/server/teams/membership.ts +86 -0
- package/src/server/teams/queries.ts +261 -0
- package/src/server/teams/service.ts +1127 -0
- package/src/server/teams/types.ts +101 -0
- package/src/server/uploads/avatar.ts +133 -0
- package/src/server/users/deletion-state.ts +93 -0
- package/src/server/users/functions.ts +160 -0
- package/src/server/users/onboarding.ts +17 -0
- package/src/server/users/service.ts +644 -0
- package/src/server.ts +55 -0
- package/src/styles/shadcn.css +653 -0
- package/src/styles/theme.css +76 -0
- package/src/styles.css +177 -0
- package/wrangler.template.jsonc +37 -0
|
@@ -0,0 +1,891 @@
|
|
|
1
|
+
import { backupDatabaseSchema } from '#devpush/lib/backup-database'
|
|
2
|
+
import { requireProjectRuntimeConfig } from '#devpush/lib/project-runtime-config'
|
|
3
|
+
import { PublicError } from '#devpush/lib/public-error'
|
|
4
|
+
import { db, logsDb } from '#devpush/server/db'
|
|
5
|
+
import {
|
|
6
|
+
deploymentLogs,
|
|
7
|
+
operationLogs,
|
|
8
|
+
runtimeLogs,
|
|
9
|
+
} from '#devpush/server/db/log-schema'
|
|
10
|
+
import {
|
|
11
|
+
aliases,
|
|
12
|
+
backupArtifacts,
|
|
13
|
+
backupConfigs,
|
|
14
|
+
backupRuns,
|
|
15
|
+
backupStorage,
|
|
16
|
+
deployments,
|
|
17
|
+
domains,
|
|
18
|
+
environments,
|
|
19
|
+
projects,
|
|
20
|
+
serverMetrics,
|
|
21
|
+
servers,
|
|
22
|
+
teams,
|
|
23
|
+
user,
|
|
24
|
+
} from '#devpush/server/db/schema'
|
|
25
|
+
import {
|
|
26
|
+
createInstallationAccessToken,
|
|
27
|
+
getGitHubAccount,
|
|
28
|
+
listBranchCommits,
|
|
29
|
+
listInstallationRepositoriesPage,
|
|
30
|
+
listRepositoryBranchesPage,
|
|
31
|
+
listUserInstallationsPage,
|
|
32
|
+
} from '#devpush/server/github/service'
|
|
33
|
+
import { getEnvironmentForBranch } from '#devpush/server/projects/environment-branches'
|
|
34
|
+
import { normalizeProjectRoutes } from '#devpush/server/projects/mappers'
|
|
35
|
+
import { readProjectEnvVars } from '#devpush/server/projects/project-env-vars'
|
|
36
|
+
import { getEffectiveServerStatus } from '#devpush/server/servers/status'
|
|
37
|
+
import type { SQL } from 'drizzle-orm'
|
|
38
|
+
import { and, asc, desc, eq, gt, gte, lt, ne, or, sql } from 'drizzle-orm'
|
|
39
|
+
import { apiFingerprint, decodeApiCursor, encodeApiCursor } from './cursors'
|
|
40
|
+
import { ApiError } from './errors'
|
|
41
|
+
|
|
42
|
+
import type { OperationContext } from './operation-context'
|
|
43
|
+
import {
|
|
44
|
+
backupRow,
|
|
45
|
+
deploymentRow,
|
|
46
|
+
jobRow,
|
|
47
|
+
projectGuard,
|
|
48
|
+
projectRow,
|
|
49
|
+
requireWholeTeam,
|
|
50
|
+
serialize,
|
|
51
|
+
serverSelection,
|
|
52
|
+
} from './operation-context'
|
|
53
|
+
|
|
54
|
+
const projectSelection = {
|
|
55
|
+
id: projects.id,
|
|
56
|
+
teamId: projects.teamId,
|
|
57
|
+
name: projects.name,
|
|
58
|
+
slug: projects.slug,
|
|
59
|
+
repository: projects.githubRepo,
|
|
60
|
+
repositoryId: projects.githubRepoId,
|
|
61
|
+
defaultServerId: projects.defaultServerId,
|
|
62
|
+
settingsVersion: projects.settingsVersion,
|
|
63
|
+
createdAt: projects.createdAt,
|
|
64
|
+
}
|
|
65
|
+
const deploymentSelection = {
|
|
66
|
+
id: deployments.id,
|
|
67
|
+
projectId: environments.projectId,
|
|
68
|
+
environmentId: deployments.environmentId,
|
|
69
|
+
serverId: deployments.serverId,
|
|
70
|
+
status: deployments.status,
|
|
71
|
+
phase: deployments.phase,
|
|
72
|
+
trigger: deployments.trigger,
|
|
73
|
+
repository: deployments.repoFullName,
|
|
74
|
+
sha: deployments.gitSha,
|
|
75
|
+
branch: deployments.gitBranch,
|
|
76
|
+
createdAt: deployments.createdAt,
|
|
77
|
+
startedAt: deployments.startedAt,
|
|
78
|
+
finishedAt: deployments.finishedAt,
|
|
79
|
+
}
|
|
80
|
+
const backupSelection = {
|
|
81
|
+
id: backupRuns.id,
|
|
82
|
+
projectId: backupRuns.projectId,
|
|
83
|
+
environmentId: backupRuns.environmentId,
|
|
84
|
+
deploymentId: backupRuns.deploymentId,
|
|
85
|
+
serverId: backupRuns.serverId,
|
|
86
|
+
status: backupRuns.status,
|
|
87
|
+
createdAt: backupRuns.createdAt,
|
|
88
|
+
startedAt: backupRuns.startedAt,
|
|
89
|
+
finishedAt: backupRuns.finishedAt,
|
|
90
|
+
}
|
|
91
|
+
function publicEndpoint(value: string | null) {
|
|
92
|
+
if (!value) return null
|
|
93
|
+
try {
|
|
94
|
+
const endpoint = new URL(value)
|
|
95
|
+
endpoint.username = ''
|
|
96
|
+
endpoint.password = ''
|
|
97
|
+
endpoint.search = ''
|
|
98
|
+
endpoint.hash = ''
|
|
99
|
+
return endpoint.toString()
|
|
100
|
+
} catch {
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function cursorContext(context: OperationContext) {
|
|
105
|
+
const { cursor: _cursor, limit: _limit, ...filters } = context.input
|
|
106
|
+
return apiFingerprint({
|
|
107
|
+
operation: context.operation.id,
|
|
108
|
+
membershipId: context.principal.membershipId,
|
|
109
|
+
projects: context.principal.projectIds,
|
|
110
|
+
filters,
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
function pageState(context: OperationContext, date: SQL | any, id: SQL | any) {
|
|
114
|
+
const scope = cursorContext(context)
|
|
115
|
+
const cursor = decodeApiCursor(context.input.cursor, scope)
|
|
116
|
+
return {
|
|
117
|
+
scope,
|
|
118
|
+
condition: cursor
|
|
119
|
+
? or(
|
|
120
|
+
lt(date, new Date(cursor.position)),
|
|
121
|
+
and(eq(date, new Date(cursor.position)), lt(id, cursor.id)),
|
|
122
|
+
)
|
|
123
|
+
: undefined,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function page<T extends { id: string; createdAt: Date }>(
|
|
127
|
+
context: OperationContext,
|
|
128
|
+
rows: T[],
|
|
129
|
+
) {
|
|
130
|
+
const hasMore = rows.length > context.input.limit
|
|
131
|
+
const items = rows.slice(0, context.input.limit)
|
|
132
|
+
const last = items.at(-1)
|
|
133
|
+
return {
|
|
134
|
+
items: serialize(items),
|
|
135
|
+
nextCursor:
|
|
136
|
+
hasMore && last
|
|
137
|
+
? encodeApiCursor(
|
|
138
|
+
cursorContext(context),
|
|
139
|
+
last.createdAt.getTime(),
|
|
140
|
+
last.id,
|
|
141
|
+
)
|
|
142
|
+
: null,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function readOperation(
|
|
147
|
+
context: OperationContext,
|
|
148
|
+
): Promise<unknown> {
|
|
149
|
+
const { principal, input: i, operation } = context
|
|
150
|
+
const limit = Number(i.limit ?? 25)
|
|
151
|
+
if (
|
|
152
|
+
operation.id === 'list_github_installations' ||
|
|
153
|
+
operation.id === 'list_github_repositories'
|
|
154
|
+
) {
|
|
155
|
+
const account = await getGitHubAccount(principal.userId)
|
|
156
|
+
if (!account) throw new PublicError('PROJECT_GITHUB_ACCOUNT_REQUIRED')
|
|
157
|
+
const scope = `${cursorContext(context)}:provider:${limit}`
|
|
158
|
+
const providerPage = decodeApiCursor(i.cursor, scope)?.position ?? 1
|
|
159
|
+
if (providerPage < 1) throw new ApiError('INVALID_CURSOR', 400)
|
|
160
|
+
if (operation.id === 'list_github_installations') {
|
|
161
|
+
const response = await listUserInstallationsPage({
|
|
162
|
+
accessToken: account.accessToken,
|
|
163
|
+
page: providerPage,
|
|
164
|
+
perPage: limit,
|
|
165
|
+
})
|
|
166
|
+
return {
|
|
167
|
+
items: response.items,
|
|
168
|
+
nextCursor: response.hasMore
|
|
169
|
+
? encodeApiCursor(scope, providerPage + 1)
|
|
170
|
+
: null,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const response = await listInstallationRepositoriesPage({
|
|
174
|
+
accessToken: account.accessToken,
|
|
175
|
+
installationId: i.installationId,
|
|
176
|
+
page: providerPage,
|
|
177
|
+
perPage: limit,
|
|
178
|
+
})
|
|
179
|
+
return {
|
|
180
|
+
items: response.items
|
|
181
|
+
.filter((repository) => repository.permissions.push)
|
|
182
|
+
.map((repository) => ({
|
|
183
|
+
id: repository.id,
|
|
184
|
+
installationId: i.installationId,
|
|
185
|
+
fullName: repository.fullName,
|
|
186
|
+
defaultBranch: repository.defaultBranch,
|
|
187
|
+
private: repository.private,
|
|
188
|
+
})),
|
|
189
|
+
nextCursor: response.hasMore
|
|
190
|
+
? encodeApiCursor(scope, providerPage + 1)
|
|
191
|
+
: null,
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (operation.id === 'get_backup_policy') {
|
|
195
|
+
const { project } = await projectRow(context, i.projectId)
|
|
196
|
+
const [policy] = await db
|
|
197
|
+
.select()
|
|
198
|
+
.from(backupConfigs)
|
|
199
|
+
.where(
|
|
200
|
+
and(
|
|
201
|
+
eq(backupConfigs.id, i.policyId),
|
|
202
|
+
eq(backupConfigs.projectId, project.id),
|
|
203
|
+
),
|
|
204
|
+
)
|
|
205
|
+
.limit(1)
|
|
206
|
+
if (!policy) throw new PublicError('BACKUP_POLICY_NOT_FOUND')
|
|
207
|
+
const dumps = Array.isArray(policy.databaseDumps)
|
|
208
|
+
? policy.databaseDumps.map((dump) => backupDatabaseSchema.parse(dump))
|
|
209
|
+
: []
|
|
210
|
+
return {
|
|
211
|
+
id: policy.id,
|
|
212
|
+
projectId: project.id,
|
|
213
|
+
settingsVersion: policy.settingsVersion,
|
|
214
|
+
name: policy.name,
|
|
215
|
+
environmentId: policy.environmentId,
|
|
216
|
+
enabled: policy.enabled,
|
|
217
|
+
schedule: policy.schedule,
|
|
218
|
+
destination: policy.destination,
|
|
219
|
+
retention: policy.retention,
|
|
220
|
+
volumes: policy.volumes,
|
|
221
|
+
databaseDumps: dumps,
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (operation.id === 'get_identity') {
|
|
225
|
+
const [row] = await db
|
|
226
|
+
.select({
|
|
227
|
+
user: { id: user.id, name: user.name, username: user.username },
|
|
228
|
+
team: { id: teams.id, name: teams.name, slug: teams.slug },
|
|
229
|
+
})
|
|
230
|
+
.from(user)
|
|
231
|
+
.innerJoin(teams, eq(teams.id, principal.teamId))
|
|
232
|
+
.where(eq(user.id, principal.userId))
|
|
233
|
+
.limit(1)
|
|
234
|
+
if (!row) throw new ApiError('NOT_FOUND', 404)
|
|
235
|
+
return {
|
|
236
|
+
...row,
|
|
237
|
+
scopes: principal.scopes,
|
|
238
|
+
projectIds: principal.projectIds,
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (operation.id === 'list_projects') {
|
|
242
|
+
const pagination = pageState(context, projects.createdAt, projects.id)
|
|
243
|
+
return page(
|
|
244
|
+
context,
|
|
245
|
+
await db
|
|
246
|
+
.select(projectSelection)
|
|
247
|
+
.from(projects)
|
|
248
|
+
.where(
|
|
249
|
+
and(projectGuard(principal, operation.scope), pagination.condition),
|
|
250
|
+
)
|
|
251
|
+
.orderBy(desc(projects.createdAt), desc(projects.id))
|
|
252
|
+
.limit(limit + 1),
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
if (operation.id === 'get_project') {
|
|
256
|
+
await projectRow(context, i.projectId)
|
|
257
|
+
const [row] = await db
|
|
258
|
+
.select(projectSelection)
|
|
259
|
+
.from(projects)
|
|
260
|
+
.where(eq(projects.id, i.projectId))
|
|
261
|
+
.limit(1)
|
|
262
|
+
return serialize(row)
|
|
263
|
+
}
|
|
264
|
+
if (
|
|
265
|
+
(operation.id.startsWith('list_') && i.projectId) ||
|
|
266
|
+
[
|
|
267
|
+
'get_project_configuration',
|
|
268
|
+
'read_runtime_logs',
|
|
269
|
+
'get_deployment_options',
|
|
270
|
+
].includes(operation.id)
|
|
271
|
+
) {
|
|
272
|
+
const { project } = await projectRow(context, i.projectId)
|
|
273
|
+
if (operation.id === 'list_environments') {
|
|
274
|
+
const pagination = pageState(
|
|
275
|
+
context,
|
|
276
|
+
environments.createdAt,
|
|
277
|
+
environments.id,
|
|
278
|
+
)
|
|
279
|
+
return page(
|
|
280
|
+
context,
|
|
281
|
+
await db
|
|
282
|
+
.select({
|
|
283
|
+
id: environments.id,
|
|
284
|
+
projectId: environments.projectId,
|
|
285
|
+
name: environments.name,
|
|
286
|
+
slug: environments.slug,
|
|
287
|
+
branch: environments.branch,
|
|
288
|
+
isProduction: environments.isProduction,
|
|
289
|
+
position: environments.position,
|
|
290
|
+
color: environments.color,
|
|
291
|
+
serverId: sql<
|
|
292
|
+
string | null
|
|
293
|
+
>`coalesce(${environments.serverId}, ${project.defaultServerId})`,
|
|
294
|
+
createdAt: environments.createdAt,
|
|
295
|
+
})
|
|
296
|
+
.from(environments)
|
|
297
|
+
.where(
|
|
298
|
+
and(
|
|
299
|
+
eq(environments.projectId, project.id),
|
|
300
|
+
eq(environments.status, 'active'),
|
|
301
|
+
pagination.condition,
|
|
302
|
+
),
|
|
303
|
+
)
|
|
304
|
+
.orderBy(desc(environments.createdAt), desc(environments.id))
|
|
305
|
+
.limit(limit + 1),
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
if (operation.id === 'get_project_configuration')
|
|
309
|
+
return {
|
|
310
|
+
settingsVersion: project.settingsVersion,
|
|
311
|
+
runtimeConfig: requireProjectRuntimeConfig(project.runtimeConfig),
|
|
312
|
+
routes: normalizeProjectRoutes(project.routes),
|
|
313
|
+
}
|
|
314
|
+
if (operation.id === 'get_deployment_options') {
|
|
315
|
+
if (!project.githubInstallationId || !project.githubRepoId)
|
|
316
|
+
throw new PublicError('DEPLOYMENT_GITHUB_INSTALLATION_REQUIRED')
|
|
317
|
+
const projectEnvironments = await db
|
|
318
|
+
.select({
|
|
319
|
+
id: environments.id,
|
|
320
|
+
branch: environments.branch,
|
|
321
|
+
slug: environments.slug,
|
|
322
|
+
isProduction: environments.isProduction,
|
|
323
|
+
})
|
|
324
|
+
.from(environments)
|
|
325
|
+
.where(
|
|
326
|
+
and(
|
|
327
|
+
eq(environments.projectId, project.id),
|
|
328
|
+
eq(environments.status, 'active'),
|
|
329
|
+
),
|
|
330
|
+
)
|
|
331
|
+
.orderBy(asc(environments.position), asc(environments.id))
|
|
332
|
+
.limit(1001)
|
|
333
|
+
if (projectEnvironments.length > 1000)
|
|
334
|
+
throw new ApiError('OPERATION_CONFLICT', 409)
|
|
335
|
+
if (
|
|
336
|
+
!projectEnvironments.some(
|
|
337
|
+
(environment) => environment.id === i.environmentId,
|
|
338
|
+
)
|
|
339
|
+
)
|
|
340
|
+
throw new PublicError('DEPLOYMENT_ENVIRONMENT_NOT_FOUND')
|
|
341
|
+
const token = await createInstallationAccessToken({
|
|
342
|
+
installationId: project.githubInstallationId,
|
|
343
|
+
repositoryId: project.githubRepoId,
|
|
344
|
+
repositoryFullName: project.githubRepo,
|
|
345
|
+
})
|
|
346
|
+
if (
|
|
347
|
+
i.branch &&
|
|
348
|
+
getEnvironmentForBranch(i.branch, projectEnvironments)?.id !==
|
|
349
|
+
i.environmentId
|
|
350
|
+
)
|
|
351
|
+
throw new PublicError('DEPLOYMENT_BRANCH_MISMATCH')
|
|
352
|
+
const scope = `${cursorContext(context)}:provider:${i.limit}:${project.settingsVersion}`
|
|
353
|
+
const providerPage = decodeApiCursor(i.cursor, scope)?.position ?? 1
|
|
354
|
+
if (providerPage < 1) throw new ApiError('INVALID_CURSOR', 400)
|
|
355
|
+
const response = await listRepositoryBranchesPage({
|
|
356
|
+
accessToken: token.token,
|
|
357
|
+
repo: project.githubRepo,
|
|
358
|
+
page: providerPage,
|
|
359
|
+
perPage: i.limit,
|
|
360
|
+
})
|
|
361
|
+
const branches = response.items.filter(
|
|
362
|
+
(branch) =>
|
|
363
|
+
getEnvironmentForBranch(branch, projectEnvironments)?.id ===
|
|
364
|
+
i.environmentId,
|
|
365
|
+
)
|
|
366
|
+
const selectedBranch = i.branch ?? branches[0] ?? null
|
|
367
|
+
const commits = selectedBranch
|
|
368
|
+
? await listBranchCommits({
|
|
369
|
+
accessToken: token.token,
|
|
370
|
+
branch: selectedBranch,
|
|
371
|
+
repo: project.githubRepo,
|
|
372
|
+
perPage: 5,
|
|
373
|
+
})
|
|
374
|
+
: []
|
|
375
|
+
return {
|
|
376
|
+
branches,
|
|
377
|
+
nextCursor: response.hasMore
|
|
378
|
+
? encodeApiCursor(scope, providerPage + 1)
|
|
379
|
+
: null,
|
|
380
|
+
selectedBranch,
|
|
381
|
+
commits: commits.map((commit) => ({
|
|
382
|
+
sha: commit.sha,
|
|
383
|
+
message: commit.message,
|
|
384
|
+
url: commit.url,
|
|
385
|
+
authorName: commit.authorName,
|
|
386
|
+
authoredAt: commit.authoredAt,
|
|
387
|
+
})),
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (operation.id === 'list_variables') {
|
|
391
|
+
const values = readProjectEnvVars(project)
|
|
392
|
+
.map(({ key, environment }) => ({
|
|
393
|
+
key,
|
|
394
|
+
environmentId: environment || null,
|
|
395
|
+
}))
|
|
396
|
+
.sort((a, b) =>
|
|
397
|
+
`${a.environmentId ?? ''}\0${a.key}`.localeCompare(
|
|
398
|
+
`${b.environmentId ?? ''}\0${b.key}`,
|
|
399
|
+
),
|
|
400
|
+
)
|
|
401
|
+
const scope = cursorContext(context)
|
|
402
|
+
const cursor = decodeApiCursor(
|
|
403
|
+
i.cursor,
|
|
404
|
+
`${scope}:${project.settingsVersion}`,
|
|
405
|
+
)
|
|
406
|
+
const offset = cursor?.position ?? 0
|
|
407
|
+
return {
|
|
408
|
+
items: values.slice(offset, offset + limit),
|
|
409
|
+
nextCursor:
|
|
410
|
+
offset + limit < values.length
|
|
411
|
+
? encodeApiCursor(
|
|
412
|
+
`${scope}:${project.settingsVersion}`,
|
|
413
|
+
offset + limit,
|
|
414
|
+
)
|
|
415
|
+
: null,
|
|
416
|
+
settingsVersion: project.settingsVersion,
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (operation.id === 'list_domains' || operation.id === 'list_aliases') {
|
|
420
|
+
const table = operation.id === 'list_domains' ? domains : aliases
|
|
421
|
+
const pagination = pageState(context, table.createdAt, table.id)
|
|
422
|
+
if (operation.id === 'list_domains')
|
|
423
|
+
return page(
|
|
424
|
+
context,
|
|
425
|
+
await db
|
|
426
|
+
.select({
|
|
427
|
+
id: domains.id,
|
|
428
|
+
environmentId: domains.environmentId,
|
|
429
|
+
hostname: domains.hostname,
|
|
430
|
+
basePath: domains.basePath,
|
|
431
|
+
https: domains.https,
|
|
432
|
+
status: domains.status,
|
|
433
|
+
createdAt: domains.createdAt,
|
|
434
|
+
})
|
|
435
|
+
.from(domains)
|
|
436
|
+
.where(and(eq(domains.projectId, project.id), pagination.condition))
|
|
437
|
+
.orderBy(desc(domains.createdAt), desc(domains.id))
|
|
438
|
+
.limit(limit + 1),
|
|
439
|
+
)
|
|
440
|
+
return page(
|
|
441
|
+
context,
|
|
442
|
+
await db
|
|
443
|
+
.select({
|
|
444
|
+
id: aliases.id,
|
|
445
|
+
environmentId: aliases.environmentId,
|
|
446
|
+
deploymentId: aliases.deploymentId,
|
|
447
|
+
hostname: aliases.hostname,
|
|
448
|
+
type: aliases.type,
|
|
449
|
+
branch: aliases.branch,
|
|
450
|
+
https: aliases.https,
|
|
451
|
+
createdAt: aliases.createdAt,
|
|
452
|
+
})
|
|
453
|
+
.from(aliases)
|
|
454
|
+
.where(and(eq(aliases.projectId, project.id), pagination.condition))
|
|
455
|
+
.orderBy(desc(aliases.createdAt), desc(aliases.id))
|
|
456
|
+
.limit(limit + 1),
|
|
457
|
+
)
|
|
458
|
+
}
|
|
459
|
+
if (operation.id === 'list_deployments') {
|
|
460
|
+
const pagination = pageState(
|
|
461
|
+
context,
|
|
462
|
+
deployments.createdAt,
|
|
463
|
+
deployments.id,
|
|
464
|
+
)
|
|
465
|
+
return page(
|
|
466
|
+
context,
|
|
467
|
+
await db
|
|
468
|
+
.select(deploymentSelection)
|
|
469
|
+
.from(deployments)
|
|
470
|
+
.innerJoin(
|
|
471
|
+
environments,
|
|
472
|
+
eq(environments.id, deployments.environmentId),
|
|
473
|
+
)
|
|
474
|
+
.where(
|
|
475
|
+
and(
|
|
476
|
+
eq(environments.projectId, project.id),
|
|
477
|
+
i.environmentId
|
|
478
|
+
? eq(environments.id, i.environmentId)
|
|
479
|
+
: undefined,
|
|
480
|
+
pagination.condition,
|
|
481
|
+
),
|
|
482
|
+
)
|
|
483
|
+
.orderBy(desc(deployments.createdAt), desc(deployments.id))
|
|
484
|
+
.limit(limit + 1),
|
|
485
|
+
)
|
|
486
|
+
}
|
|
487
|
+
if (operation.id === 'list_backups') {
|
|
488
|
+
const pagination = pageState(context, backupRuns.createdAt, backupRuns.id)
|
|
489
|
+
return page(
|
|
490
|
+
context,
|
|
491
|
+
await db
|
|
492
|
+
.select(backupSelection)
|
|
493
|
+
.from(backupRuns)
|
|
494
|
+
.where(
|
|
495
|
+
and(
|
|
496
|
+
eq(backupRuns.projectId, project.id),
|
|
497
|
+
i.environmentId
|
|
498
|
+
? eq(backupRuns.environmentId, i.environmentId)
|
|
499
|
+
: undefined,
|
|
500
|
+
pagination.condition,
|
|
501
|
+
),
|
|
502
|
+
)
|
|
503
|
+
.orderBy(desc(backupRuns.createdAt), desc(backupRuns.id))
|
|
504
|
+
.limit(limit + 1),
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
if (operation.id === 'list_backup_policies') {
|
|
508
|
+
const pagination = pageState(
|
|
509
|
+
context,
|
|
510
|
+
backupConfigs.createdAt,
|
|
511
|
+
backupConfigs.id,
|
|
512
|
+
)
|
|
513
|
+
return page(
|
|
514
|
+
context,
|
|
515
|
+
await db
|
|
516
|
+
.select({
|
|
517
|
+
id: backupConfigs.id,
|
|
518
|
+
name: backupConfigs.name,
|
|
519
|
+
environmentId: backupConfigs.environmentId,
|
|
520
|
+
enabled: backupConfigs.enabled,
|
|
521
|
+
createdAt: backupConfigs.createdAt,
|
|
522
|
+
})
|
|
523
|
+
.from(backupConfigs)
|
|
524
|
+
.where(
|
|
525
|
+
and(eq(backupConfigs.projectId, project.id), pagination.condition),
|
|
526
|
+
)
|
|
527
|
+
.orderBy(desc(backupConfigs.createdAt), desc(backupConfigs.id))
|
|
528
|
+
.limit(limit + 1),
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
if (operation.id === 'read_runtime_logs')
|
|
532
|
+
return readRuntimeLogs(context, project)
|
|
533
|
+
}
|
|
534
|
+
if (operation.id === 'get_deployment') {
|
|
535
|
+
await deploymentRow(context, i.deploymentId)
|
|
536
|
+
const [row] = await db
|
|
537
|
+
.select(deploymentSelection)
|
|
538
|
+
.from(deployments)
|
|
539
|
+
.innerJoin(environments, eq(environments.id, deployments.environmentId))
|
|
540
|
+
.where(eq(deployments.id, i.deploymentId))
|
|
541
|
+
.limit(1)
|
|
542
|
+
return serialize(row)
|
|
543
|
+
}
|
|
544
|
+
if (operation.id === 'read_deployment_logs') {
|
|
545
|
+
await deploymentRow(context, i.deploymentId)
|
|
546
|
+
const table = deploymentLogs
|
|
547
|
+
const cursor = decodeApiCursor(i.cursor, cursorContext(context))
|
|
548
|
+
const store = logsDb
|
|
549
|
+
const rows = await store
|
|
550
|
+
.select({
|
|
551
|
+
position: table.seq,
|
|
552
|
+
content: table.content,
|
|
553
|
+
createdAt: table.createdAt,
|
|
554
|
+
})
|
|
555
|
+
.from(table)
|
|
556
|
+
.where(
|
|
557
|
+
and(
|
|
558
|
+
eq(table.deploymentId, i.deploymentId),
|
|
559
|
+
eq(table.stream, 'deploy'),
|
|
560
|
+
gt(table.seq, cursor?.position ?? 0),
|
|
561
|
+
),
|
|
562
|
+
)
|
|
563
|
+
.orderBy(asc(table.seq))
|
|
564
|
+
.limit(limit + 1)
|
|
565
|
+
return logPage(context, rows)
|
|
566
|
+
}
|
|
567
|
+
if (
|
|
568
|
+
operation.id === 'list_servers' ||
|
|
569
|
+
operation.id === 'get_server' ||
|
|
570
|
+
operation.id === 'read_server_metrics' ||
|
|
571
|
+
operation.id === 'get_server_delete_diagnostic'
|
|
572
|
+
) {
|
|
573
|
+
requireWholeTeam(principal)
|
|
574
|
+
const conditions = [
|
|
575
|
+
eq(servers.teamId, principal.teamId),
|
|
576
|
+
ne(servers.status, 'deleted'),
|
|
577
|
+
]
|
|
578
|
+
if (i.serverId) conditions.push(eq(servers.id, i.serverId))
|
|
579
|
+
if (operation.id === 'list_servers') {
|
|
580
|
+
const pagination = pageState(context, servers.createdAt, servers.id)
|
|
581
|
+
const rows = await db
|
|
582
|
+
.select(serverSelection)
|
|
583
|
+
.from(servers)
|
|
584
|
+
.where(and(...conditions, pagination.condition))
|
|
585
|
+
.orderBy(desc(servers.createdAt), desc(servers.id))
|
|
586
|
+
.limit(limit + 1)
|
|
587
|
+
return page(
|
|
588
|
+
context,
|
|
589
|
+
rows.map((row) => ({ ...row, status: getEffectiveServerStatus(row) })),
|
|
590
|
+
)
|
|
591
|
+
}
|
|
592
|
+
const [row] = await db
|
|
593
|
+
.select(serverSelection)
|
|
594
|
+
.from(servers)
|
|
595
|
+
.where(and(...conditions))
|
|
596
|
+
.limit(1)
|
|
597
|
+
if (!row) throw new ApiError('NOT_FOUND', 404)
|
|
598
|
+
if (operation.id === 'get_server_delete_diagnostic') {
|
|
599
|
+
const [counts] = await db
|
|
600
|
+
.select({
|
|
601
|
+
projectCount: sql<number>`count(distinct ${projects.id})`,
|
|
602
|
+
environmentCount: sql<number>`count(*)`,
|
|
603
|
+
})
|
|
604
|
+
.from(environments)
|
|
605
|
+
.innerJoin(projects, eq(projects.id, environments.projectId))
|
|
606
|
+
.where(
|
|
607
|
+
and(
|
|
608
|
+
eq(projects.teamId, principal.teamId),
|
|
609
|
+
eq(projects.status, 'active'),
|
|
610
|
+
eq(environments.status, 'active'),
|
|
611
|
+
sql`coalesce(${environments.serverId},${projects.defaultServerId}) = ${row.id}`,
|
|
612
|
+
),
|
|
613
|
+
)
|
|
614
|
+
return {
|
|
615
|
+
serverId: row.id,
|
|
616
|
+
projectCount: Number(counts?.projectCount ?? 0),
|
|
617
|
+
environmentCount: Number(counts?.environmentCount ?? 0),
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (operation.id === 'get_server')
|
|
621
|
+
return serialize({ ...row, status: getEffectiveServerStatus(row) })
|
|
622
|
+
const scope = cursorContext(context)
|
|
623
|
+
const cursor = decodeApiCursor(i.cursor, scope)
|
|
624
|
+
const metricRows = await db
|
|
625
|
+
.select({
|
|
626
|
+
id: serverMetrics.id,
|
|
627
|
+
observedAt: serverMetrics.observedAt,
|
|
628
|
+
cpuPercent: serverMetrics.cpuPercent,
|
|
629
|
+
memoryUsedBytes: serverMetrics.memoryUsedBytes,
|
|
630
|
+
memoryTotalBytes: serverMetrics.memoryTotalBytes,
|
|
631
|
+
diskUsedBytes: serverMetrics.diskUsedBytes,
|
|
632
|
+
diskTotalBytes: serverMetrics.diskTotalBytes,
|
|
633
|
+
networkReceiveBytesPerSecond:
|
|
634
|
+
serverMetrics.networkReceiveBytesPerSecond,
|
|
635
|
+
networkTransmitBytesPerSecond:
|
|
636
|
+
serverMetrics.networkTransmitBytesPerSecond,
|
|
637
|
+
})
|
|
638
|
+
.from(serverMetrics)
|
|
639
|
+
.where(
|
|
640
|
+
and(
|
|
641
|
+
eq(serverMetrics.serverId, row.id),
|
|
642
|
+
i.since
|
|
643
|
+
? gte(serverMetrics.observedAt, new Date(i.since))
|
|
644
|
+
: undefined,
|
|
645
|
+
cursor
|
|
646
|
+
? or(
|
|
647
|
+
lt(serverMetrics.observedAt, new Date(cursor.position)),
|
|
648
|
+
and(
|
|
649
|
+
eq(serverMetrics.observedAt, new Date(cursor.position)),
|
|
650
|
+
lt(serverMetrics.id, cursor.id),
|
|
651
|
+
),
|
|
652
|
+
)
|
|
653
|
+
: undefined,
|
|
654
|
+
),
|
|
655
|
+
)
|
|
656
|
+
.orderBy(desc(serverMetrics.observedAt), desc(serverMetrics.id))
|
|
657
|
+
.limit(limit + 1)
|
|
658
|
+
const items = metricRows.slice(0, limit)
|
|
659
|
+
const last = items.at(-1)
|
|
660
|
+
return {
|
|
661
|
+
items: serialize(items),
|
|
662
|
+
nextCursor:
|
|
663
|
+
metricRows.length > limit && last
|
|
664
|
+
? encodeApiCursor(scope, last.observedAt.getTime(), last.id)
|
|
665
|
+
: null,
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (
|
|
669
|
+
operation.id === 'get_backup' ||
|
|
670
|
+
operation.id === 'list_backup_artifacts'
|
|
671
|
+
) {
|
|
672
|
+
await backupRow(context, i.backupRunId)
|
|
673
|
+
if (operation.id === 'get_backup') {
|
|
674
|
+
const [row] = await db
|
|
675
|
+
.select(backupSelection)
|
|
676
|
+
.from(backupRuns)
|
|
677
|
+
.where(eq(backupRuns.id, i.backupRunId))
|
|
678
|
+
.limit(1)
|
|
679
|
+
return serialize(row)
|
|
680
|
+
}
|
|
681
|
+
const pagination = pageState(
|
|
682
|
+
context,
|
|
683
|
+
backupArtifacts.createdAt,
|
|
684
|
+
backupArtifacts.id,
|
|
685
|
+
)
|
|
686
|
+
return page(
|
|
687
|
+
context,
|
|
688
|
+
await db
|
|
689
|
+
.select({
|
|
690
|
+
id: backupArtifacts.id,
|
|
691
|
+
type: backupArtifacts.type,
|
|
692
|
+
storage: backupArtifacts.storage,
|
|
693
|
+
sizeBytes: backupArtifacts.sizeBytes,
|
|
694
|
+
checksumSha256: backupArtifacts.checksumSha256,
|
|
695
|
+
createdAt: backupArtifacts.createdAt,
|
|
696
|
+
})
|
|
697
|
+
.from(backupArtifacts)
|
|
698
|
+
.where(
|
|
699
|
+
and(
|
|
700
|
+
eq(backupArtifacts.backupRunId, i.backupRunId),
|
|
701
|
+
pagination.condition,
|
|
702
|
+
),
|
|
703
|
+
)
|
|
704
|
+
.orderBy(desc(backupArtifacts.createdAt), desc(backupArtifacts.id))
|
|
705
|
+
.limit(limit + 1),
|
|
706
|
+
)
|
|
707
|
+
}
|
|
708
|
+
if (operation.id === 'list_backup_storage') {
|
|
709
|
+
requireWholeTeam(principal)
|
|
710
|
+
const pagination = pageState(
|
|
711
|
+
context,
|
|
712
|
+
backupStorage.createdAt,
|
|
713
|
+
backupStorage.id,
|
|
714
|
+
)
|
|
715
|
+
const rows = await db
|
|
716
|
+
.select({
|
|
717
|
+
settingsVersion: backupStorage.settingsVersion,
|
|
718
|
+
id: backupStorage.id,
|
|
719
|
+
name: backupStorage.name,
|
|
720
|
+
bucket: backupStorage.bucket,
|
|
721
|
+
region: backupStorage.region,
|
|
722
|
+
endpoint: backupStorage.endpoint,
|
|
723
|
+
createdAt: backupStorage.createdAt,
|
|
724
|
+
})
|
|
725
|
+
.from(backupStorage)
|
|
726
|
+
.where(
|
|
727
|
+
and(eq(backupStorage.teamId, principal.teamId), pagination.condition),
|
|
728
|
+
)
|
|
729
|
+
.orderBy(desc(backupStorage.createdAt), desc(backupStorage.id))
|
|
730
|
+
.limit(limit + 1)
|
|
731
|
+
return page(
|
|
732
|
+
context,
|
|
733
|
+
rows.map((row) => ({ ...row, endpoint: publicEndpoint(row.endpoint) })),
|
|
734
|
+
)
|
|
735
|
+
}
|
|
736
|
+
if (operation.id === 'get_job' || operation.id === 'read_job_logs') {
|
|
737
|
+
const { job, projectId } = await jobRow(context, i.jobId)
|
|
738
|
+
if (operation.id === 'get_job')
|
|
739
|
+
return serialize({
|
|
740
|
+
id: job.id,
|
|
741
|
+
projectId,
|
|
742
|
+
type: job.type,
|
|
743
|
+
status: job.status,
|
|
744
|
+
createdAt: job.createdAt,
|
|
745
|
+
finishedAt: job.finishedAt,
|
|
746
|
+
})
|
|
747
|
+
const cursor = decodeApiCursor(i.cursor, cursorContext(context))
|
|
748
|
+
const rows = await logsDb
|
|
749
|
+
.select({
|
|
750
|
+
position: operationLogs.offset,
|
|
751
|
+
content: operationLogs.content,
|
|
752
|
+
createdAt: operationLogs.createdAt,
|
|
753
|
+
})
|
|
754
|
+
.from(operationLogs)
|
|
755
|
+
.where(
|
|
756
|
+
and(
|
|
757
|
+
eq(operationLogs.jobId, job.id),
|
|
758
|
+
gt(operationLogs.offset, cursor?.position ?? -1),
|
|
759
|
+
),
|
|
760
|
+
)
|
|
761
|
+
.orderBy(asc(operationLogs.offset))
|
|
762
|
+
.limit(limit + 1)
|
|
763
|
+
return logPage(context, rows)
|
|
764
|
+
}
|
|
765
|
+
throw new ApiError('NOT_FOUND', 404)
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
function boundedLogContent(content: string) {
|
|
769
|
+
const bytes = new TextEncoder().encode(content)
|
|
770
|
+
if (bytes.length <= 64 * 1024) return { content, truncated: false }
|
|
771
|
+
// Streaming decoding omits an incomplete trailing UTF-8 sequence instead of
|
|
772
|
+
// adding a replacement character that could exceed the advertised byte cap.
|
|
773
|
+
return {
|
|
774
|
+
content: new TextDecoder().decode(bytes.subarray(0, 64 * 1024), {
|
|
775
|
+
stream: true,
|
|
776
|
+
}),
|
|
777
|
+
truncated: true,
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
function logPage(
|
|
781
|
+
context: OperationContext,
|
|
782
|
+
rows: Array<{ position: number; content: string; createdAt: Date }>,
|
|
783
|
+
) {
|
|
784
|
+
let bytes = 0
|
|
785
|
+
const items = []
|
|
786
|
+
for (const row of rows.slice(0, context.input.limit)) {
|
|
787
|
+
const bounded = boundedLogContent(row.content)
|
|
788
|
+
const length = new TextEncoder().encode(bounded.content).length
|
|
789
|
+
if (items.length && bytes + length > 256 * 1024) break
|
|
790
|
+
bytes += length
|
|
791
|
+
items.push({
|
|
792
|
+
position: row.position,
|
|
793
|
+
...bounded,
|
|
794
|
+
createdAt: row.createdAt.toISOString(),
|
|
795
|
+
})
|
|
796
|
+
}
|
|
797
|
+
return {
|
|
798
|
+
items,
|
|
799
|
+
nextCursor:
|
|
800
|
+
rows.length > items.length && items.length
|
|
801
|
+
? encodeApiCursor(cursorContext(context), items.at(-1)!.position)
|
|
802
|
+
: null,
|
|
803
|
+
retentionMayHaveRemovedEarlierEntries: true,
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
async function readRuntimeLogs(
|
|
807
|
+
context: OperationContext,
|
|
808
|
+
project: typeof projects.$inferSelect,
|
|
809
|
+
) {
|
|
810
|
+
const i = context.input
|
|
811
|
+
const scopes = await db
|
|
812
|
+
.select({
|
|
813
|
+
id: environments.id,
|
|
814
|
+
runtimeId: environments.runtimeId,
|
|
815
|
+
serverId: sql<
|
|
816
|
+
string | null
|
|
817
|
+
>`coalesce(${environments.serverId}, ${project.defaultServerId})`,
|
|
818
|
+
})
|
|
819
|
+
.from(environments)
|
|
820
|
+
.where(
|
|
821
|
+
and(
|
|
822
|
+
eq(environments.projectId, project.id),
|
|
823
|
+
eq(environments.status, 'active'),
|
|
824
|
+
i.environmentId ? eq(environments.id, i.environmentId) : undefined,
|
|
825
|
+
),
|
|
826
|
+
)
|
|
827
|
+
.limit(1001)
|
|
828
|
+
// A bounded public query never silently scans an unbounded environment set.
|
|
829
|
+
if (scopes.length > 1000) throw new ApiError('OPERATION_CONFLICT', 409)
|
|
830
|
+
const cursor = decodeApiCursor(i.cursor, cursorContext(context))
|
|
831
|
+
const authorizedScopes = scopes.filter((row) => row.serverId)
|
|
832
|
+
if (!authorizedScopes.length)
|
|
833
|
+
return {
|
|
834
|
+
items: [],
|
|
835
|
+
nextCursor: null,
|
|
836
|
+
retentionMayHaveRemovedEarlierEntries: true,
|
|
837
|
+
}
|
|
838
|
+
const rows = await logsDb
|
|
839
|
+
.select({
|
|
840
|
+
id: runtimeLogs.id,
|
|
841
|
+
environmentId: runtimeLogs.environmentId,
|
|
842
|
+
service: runtimeLogs.service,
|
|
843
|
+
content: runtimeLogs.content,
|
|
844
|
+
observedAt: runtimeLogs.observedAt,
|
|
845
|
+
})
|
|
846
|
+
.from(runtimeLogs)
|
|
847
|
+
.where(
|
|
848
|
+
and(
|
|
849
|
+
eq(runtimeLogs.projectId, project.id),
|
|
850
|
+
sql`exists(select 1 from json_each(${JSON.stringify(authorizedScopes)}) as scope where json_extract(scope.value,'$.id') = ${runtimeLogs.environmentId} and json_extract(scope.value,'$.serverId') = ${runtimeLogs.serverId} and json_extract(scope.value,'$.runtimeId') = ${runtimeLogs.runtimeId})`,
|
|
851
|
+
i.service ? eq(runtimeLogs.service, i.service) : undefined,
|
|
852
|
+
i.keyword
|
|
853
|
+
? sql`instr(${runtimeLogs.searchContent},${i.keyword.toLowerCase()}) > 0`
|
|
854
|
+
: undefined,
|
|
855
|
+
i.since ? gte(runtimeLogs.observedAt, new Date(i.since)) : undefined,
|
|
856
|
+
cursor
|
|
857
|
+
? or(
|
|
858
|
+
lt(runtimeLogs.observedAt, new Date(cursor.position)),
|
|
859
|
+
and(
|
|
860
|
+
eq(runtimeLogs.observedAt, new Date(cursor.position)),
|
|
861
|
+
lt(runtimeLogs.id, cursor.id),
|
|
862
|
+
),
|
|
863
|
+
)
|
|
864
|
+
: undefined,
|
|
865
|
+
),
|
|
866
|
+
)
|
|
867
|
+
.orderBy(desc(runtimeLogs.observedAt), desc(runtimeLogs.id))
|
|
868
|
+
.limit(i.limit + 1)
|
|
869
|
+
let bytes = 0
|
|
870
|
+
const items = []
|
|
871
|
+
for (const row of rows.slice(0, i.limit)) {
|
|
872
|
+
const bounded = boundedLogContent(row.content)
|
|
873
|
+
const length = new TextEncoder().encode(bounded.content).length
|
|
874
|
+
if (items.length && bytes + length > 256 * 1024) break
|
|
875
|
+
bytes += length
|
|
876
|
+
items.push({ ...row, ...bounded })
|
|
877
|
+
}
|
|
878
|
+
const last = items.at(-1)
|
|
879
|
+
return {
|
|
880
|
+
items: serialize(items),
|
|
881
|
+
nextCursor:
|
|
882
|
+
rows.length > items.length && last
|
|
883
|
+
? encodeApiCursor(
|
|
884
|
+
cursorContext(context),
|
|
885
|
+
last.observedAt.getTime(),
|
|
886
|
+
last.id,
|
|
887
|
+
)
|
|
888
|
+
: null,
|
|
889
|
+
retentionMayHaveRemovedEarlierEntries: true,
|
|
890
|
+
}
|
|
891
|
+
}
|