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,909 @@
|
|
|
1
|
+
import { PublicError } from '#devpush/lib/public-error'
|
|
2
|
+
import { listBackupStorage } from '#devpush/server/backups/storage'
|
|
3
|
+
import {
|
|
4
|
+
and,
|
|
5
|
+
asc,
|
|
6
|
+
desc,
|
|
7
|
+
eq,
|
|
8
|
+
getTableColumns,
|
|
9
|
+
inArray,
|
|
10
|
+
ne,
|
|
11
|
+
sql,
|
|
12
|
+
} from 'drizzle-orm'
|
|
13
|
+
|
|
14
|
+
import { db } from '#devpush/server/db'
|
|
15
|
+
import {
|
|
16
|
+
agentRuntimeObservations,
|
|
17
|
+
agentJobs,
|
|
18
|
+
aliases,
|
|
19
|
+
backupArtifacts,
|
|
20
|
+
backupConfigs,
|
|
21
|
+
backupRuns,
|
|
22
|
+
deployments,
|
|
23
|
+
domains,
|
|
24
|
+
environments,
|
|
25
|
+
projects,
|
|
26
|
+
servers,
|
|
27
|
+
teamMembers,
|
|
28
|
+
teams,
|
|
29
|
+
} from '#devpush/server/db/schema'
|
|
30
|
+
import { readProjectRuntimeLogs, projectHasRuntimeLogs } from './runtime-logs'
|
|
31
|
+
import {
|
|
32
|
+
readProjectDeploymentLogs,
|
|
33
|
+
projectHasDeploymentLogs,
|
|
34
|
+
} from './deployment-logs'
|
|
35
|
+
import { getResourceColor } from '#devpush/server/resources/color'
|
|
36
|
+
import { getUserContext } from '#devpush/server/teams/service'
|
|
37
|
+
import {
|
|
38
|
+
listTeamProjects,
|
|
39
|
+
listTeamServers,
|
|
40
|
+
} from '#devpush/server/teams/queries'
|
|
41
|
+
import { requireProjectRuntimeConfig } from '#devpush/lib/project-runtime-config'
|
|
42
|
+
import type { ProjectComposeMetadata } from './compose-metadata'
|
|
43
|
+
import {
|
|
44
|
+
expandPublicRoutesFromHostnames,
|
|
45
|
+
getEffectiveProjectRoutes,
|
|
46
|
+
getEnvVarsForEnvironment,
|
|
47
|
+
getProductionEnvironment,
|
|
48
|
+
mapBackupConfig,
|
|
49
|
+
mapBackupRun,
|
|
50
|
+
mapDeployment,
|
|
51
|
+
mapEnvironment,
|
|
52
|
+
mapEnvironmentConfig,
|
|
53
|
+
mapProjectDomains,
|
|
54
|
+
mapRuntimeObservation,
|
|
55
|
+
normalizeProjectRoutes,
|
|
56
|
+
toRouteHostnames,
|
|
57
|
+
} from './mappers'
|
|
58
|
+
import { readProjectEnvVars } from './project-env-vars'
|
|
59
|
+
import type {
|
|
60
|
+
DeploymentSectionContext,
|
|
61
|
+
DeploymentSummary,
|
|
62
|
+
ProjectContext,
|
|
63
|
+
ProjectContextScope,
|
|
64
|
+
ProjectLogEntry,
|
|
65
|
+
ProjectLogsSectionContext,
|
|
66
|
+
ProjectSectionContext,
|
|
67
|
+
} from './types'
|
|
68
|
+
|
|
69
|
+
async function requireProjectIdentity({
|
|
70
|
+
userId,
|
|
71
|
+
teamSlug,
|
|
72
|
+
projectName,
|
|
73
|
+
includeEnvVars = false,
|
|
74
|
+
includeComposeMetadata = false,
|
|
75
|
+
}: {
|
|
76
|
+
userId: string
|
|
77
|
+
teamSlug: string
|
|
78
|
+
projectName: string
|
|
79
|
+
includeEnvVars?: boolean
|
|
80
|
+
includeComposeMetadata?: boolean
|
|
81
|
+
}) {
|
|
82
|
+
const { envVarsEncrypted, composeMetadata, ...projectColumns } =
|
|
83
|
+
getTableColumns(projects)
|
|
84
|
+
const rows = await db
|
|
85
|
+
.select({
|
|
86
|
+
team: {
|
|
87
|
+
id: teams.id,
|
|
88
|
+
slug: teams.slug,
|
|
89
|
+
name: teams.name,
|
|
90
|
+
settingsVersion: teams.settingsVersion,
|
|
91
|
+
image: teams.avatarPath,
|
|
92
|
+
role: teamMembers.role,
|
|
93
|
+
},
|
|
94
|
+
project: {
|
|
95
|
+
...projectColumns,
|
|
96
|
+
envVarsEncrypted: includeEnvVars
|
|
97
|
+
? envVarsEncrypted
|
|
98
|
+
: sql<string | null>`null`,
|
|
99
|
+
composeMetadata: includeComposeMetadata
|
|
100
|
+
? composeMetadata
|
|
101
|
+
: sql<typeof projects.$inferSelect.composeMetadata>`null`,
|
|
102
|
+
},
|
|
103
|
+
environment: environments,
|
|
104
|
+
server: {
|
|
105
|
+
id: servers.id,
|
|
106
|
+
name: servers.name,
|
|
107
|
+
status: servers.status,
|
|
108
|
+
lastSeenAt: servers.lastSeenAt,
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
.from(teamMembers)
|
|
112
|
+
.innerJoin(teams, eq(teams.id, teamMembers.teamId))
|
|
113
|
+
.innerJoin(
|
|
114
|
+
projects,
|
|
115
|
+
and(
|
|
116
|
+
eq(projects.teamId, teams.id),
|
|
117
|
+
eq(projects.slug, projectName),
|
|
118
|
+
eq(projects.status, 'active'),
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
.innerJoin(
|
|
122
|
+
environments,
|
|
123
|
+
and(
|
|
124
|
+
eq(environments.projectId, projects.id),
|
|
125
|
+
eq(environments.isProduction, true),
|
|
126
|
+
),
|
|
127
|
+
)
|
|
128
|
+
.leftJoin(
|
|
129
|
+
servers,
|
|
130
|
+
eq(
|
|
131
|
+
servers.id,
|
|
132
|
+
sql`coalesce(${environments.serverId}, ${projects.defaultServerId})`,
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
.where(
|
|
136
|
+
and(
|
|
137
|
+
eq(teamMembers.userId, userId),
|
|
138
|
+
eq(teams.slug, teamSlug),
|
|
139
|
+
eq(teams.status, 'active'),
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
.limit(1)
|
|
143
|
+
const row = rows.at(0)
|
|
144
|
+
|
|
145
|
+
if (!row) {
|
|
146
|
+
throw new PublicError('PROJECT_NOT_FOUND')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return row
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function getProjectContext({
|
|
153
|
+
userId,
|
|
154
|
+
teamSlug,
|
|
155
|
+
projectName,
|
|
156
|
+
scope = 'full',
|
|
157
|
+
}: {
|
|
158
|
+
userId: string
|
|
159
|
+
teamSlug: string
|
|
160
|
+
projectName: string
|
|
161
|
+
scope?: ProjectContextScope
|
|
162
|
+
}): Promise<ProjectContext> {
|
|
163
|
+
const [row, userContext] = await Promise.all([
|
|
164
|
+
requireProjectIdentity({
|
|
165
|
+
userId,
|
|
166
|
+
teamSlug,
|
|
167
|
+
projectName,
|
|
168
|
+
includeEnvVars: scope === 'settings' || scope === 'full',
|
|
169
|
+
includeComposeMetadata: ['settings', 'backups', 'full'].includes(scope),
|
|
170
|
+
}),
|
|
171
|
+
getUserContext(userId),
|
|
172
|
+
])
|
|
173
|
+
const team = {
|
|
174
|
+
...row.team,
|
|
175
|
+
color: getResourceColor(row.team.id),
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const deploymentsRequested = ['deployments', 'full', 'overview'].includes(
|
|
179
|
+
scope,
|
|
180
|
+
)
|
|
181
|
+
const settingsRequested = ['full', 'settings'].includes(scope)
|
|
182
|
+
const backupsRequested = ['backups', 'full'].includes(scope)
|
|
183
|
+
const runtimeRequested = ['full', 'overview'].includes(scope)
|
|
184
|
+
const projectEnvVars = settingsRequested
|
|
185
|
+
? readProjectEnvVars(row.project)
|
|
186
|
+
: []
|
|
187
|
+
const [
|
|
188
|
+
projectDeployments,
|
|
189
|
+
teamProjects,
|
|
190
|
+
teamServers,
|
|
191
|
+
environmentRows,
|
|
192
|
+
aliasRows,
|
|
193
|
+
domainRows,
|
|
194
|
+
backupRows,
|
|
195
|
+
runtimeObservationRows,
|
|
196
|
+
] = await Promise.all([
|
|
197
|
+
deploymentsRequested
|
|
198
|
+
? listProjectDeployments(row.project.id)
|
|
199
|
+
: Promise.resolve([]),
|
|
200
|
+
listTeamProjects(team.id),
|
|
201
|
+
listTeamServers(team.id, { includeMonitoring: false }),
|
|
202
|
+
db
|
|
203
|
+
.select()
|
|
204
|
+
.from(environments)
|
|
205
|
+
.where(
|
|
206
|
+
and(
|
|
207
|
+
eq(environments.projectId, row.project.id),
|
|
208
|
+
eq(environments.status, 'active'),
|
|
209
|
+
),
|
|
210
|
+
)
|
|
211
|
+
.orderBy(asc(environments.position), asc(environments.createdAt)),
|
|
212
|
+
db
|
|
213
|
+
.select()
|
|
214
|
+
.from(aliases)
|
|
215
|
+
.where(
|
|
216
|
+
and(
|
|
217
|
+
eq(aliases.projectId, row.project.id),
|
|
218
|
+
ne(aliases.type, 'deployment'),
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
settingsRequested
|
|
222
|
+
? db.select().from(domains).where(eq(domains.projectId, row.project.id))
|
|
223
|
+
: Promise.resolve([]),
|
|
224
|
+
backupsRequested
|
|
225
|
+
? listProjectBackupRows(row.project.id)
|
|
226
|
+
: Promise.resolve(null),
|
|
227
|
+
runtimeRequested && row.server
|
|
228
|
+
? db
|
|
229
|
+
.select({
|
|
230
|
+
lastSeenAt: agentRuntimeObservations.lastSeenAt,
|
|
231
|
+
services: agentRuntimeObservations.services,
|
|
232
|
+
})
|
|
233
|
+
.from(agentRuntimeObservations)
|
|
234
|
+
.where(
|
|
235
|
+
and(
|
|
236
|
+
eq(agentRuntimeObservations.serverId, row.server.id),
|
|
237
|
+
eq(agentRuntimeObservations.runtimeId, row.environment.runtimeId),
|
|
238
|
+
),
|
|
239
|
+
)
|
|
240
|
+
.limit(1)
|
|
241
|
+
: Promise.resolve([]),
|
|
242
|
+
])
|
|
243
|
+
const projectEnvironments = environmentRows.map((environment) => ({
|
|
244
|
+
...mapEnvironmentConfig(environment, row.project.defaultServerId),
|
|
245
|
+
defaultHost:
|
|
246
|
+
aliasRows.find(
|
|
247
|
+
(alias) =>
|
|
248
|
+
alias.environmentId === environment.id &&
|
|
249
|
+
alias.type === 'environment',
|
|
250
|
+
)?.hostname ?? null,
|
|
251
|
+
defaultRouteHttps:
|
|
252
|
+
aliasRows.find(
|
|
253
|
+
(alias) =>
|
|
254
|
+
alias.environmentId === environment.id &&
|
|
255
|
+
alias.type === 'environment',
|
|
256
|
+
)?.https ?? true,
|
|
257
|
+
}))
|
|
258
|
+
const backupData = backupRows
|
|
259
|
+
? mapProjectBackupRows(backupRows, projectEnvironments)
|
|
260
|
+
: { backupConfigs: [], backupRuns: [], backupRestores: [] }
|
|
261
|
+
const productionEnvironment = getProductionEnvironment(projectEnvironments)
|
|
262
|
+
if (!productionEnvironment) throw new Error('Project has no environments.')
|
|
263
|
+
const productionEnvironmentRow =
|
|
264
|
+
environmentRows.find(
|
|
265
|
+
(environment) => environment.id === productionEnvironment.id,
|
|
266
|
+
) ?? row.environment
|
|
267
|
+
const productionServerId =
|
|
268
|
+
productionEnvironmentRow.serverId ?? row.project.defaultServerId
|
|
269
|
+
const productionServer =
|
|
270
|
+
teamServers.find((server) => server.id === productionServerId) ?? null
|
|
271
|
+
const projectRoutes = normalizeProjectRoutes(row.project.routes)
|
|
272
|
+
const productionRoutes = getEffectiveProjectRoutes(
|
|
273
|
+
projectRoutes,
|
|
274
|
+
productionEnvironment.id,
|
|
275
|
+
)
|
|
276
|
+
const productionAliases = aliasRows.filter(
|
|
277
|
+
(alias) =>
|
|
278
|
+
alias.environmentId === productionEnvironment.id &&
|
|
279
|
+
alias.type !== 'deployment',
|
|
280
|
+
)
|
|
281
|
+
const productionDomains = domainRows.filter(
|
|
282
|
+
(domain) =>
|
|
283
|
+
domain.environmentId === productionEnvironment.id &&
|
|
284
|
+
domain.status === 'active',
|
|
285
|
+
)
|
|
286
|
+
const productionPublicRoutes = expandPublicRoutesFromHostnames(
|
|
287
|
+
productionRoutes,
|
|
288
|
+
toRouteHostnames(productionAliases, productionDomains),
|
|
289
|
+
)
|
|
290
|
+
const composeMetadata =
|
|
291
|
+
settingsRequested || backupsRequested
|
|
292
|
+
? parseStoredComposeMetadata(row.project.composeMetadata)
|
|
293
|
+
: null
|
|
294
|
+
const productionDefaultHost =
|
|
295
|
+
productionAliases.find((alias) => alias.type === 'environment')?.hostname ??
|
|
296
|
+
null
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
userContext,
|
|
300
|
+
team,
|
|
301
|
+
project: mapProject(row.project),
|
|
302
|
+
teamProjects,
|
|
303
|
+
routes: projectRoutes,
|
|
304
|
+
composeMetadata,
|
|
305
|
+
domains: mapProjectDomains(domainRows),
|
|
306
|
+
envVars: projectEnvVars,
|
|
307
|
+
backupStorage: backupsRequested ? await listBackupStorage(team.id) : [],
|
|
308
|
+
...backupData,
|
|
309
|
+
environment: {
|
|
310
|
+
...mapEnvironment(row.environment, row.server),
|
|
311
|
+
defaultHost: productionDefaultHost,
|
|
312
|
+
color: productionEnvironment.color,
|
|
313
|
+
serverId: productionServer?.id ?? null,
|
|
314
|
+
serverName: productionServer?.name ?? null,
|
|
315
|
+
serverStatus: productionServer?.status ?? null,
|
|
316
|
+
serverAgentUpdate: productionServer?.agentUpdate ?? null,
|
|
317
|
+
envVars: getEnvVarsForEnvironment(
|
|
318
|
+
projectEnvVars,
|
|
319
|
+
productionEnvironment.id,
|
|
320
|
+
),
|
|
321
|
+
publicRoutes: productionPublicRoutes,
|
|
322
|
+
runtime: mapRuntimeObservation(runtimeObservationRows.at(0) ?? null),
|
|
323
|
+
},
|
|
324
|
+
environments: projectEnvironments,
|
|
325
|
+
deployments: projectDeployments,
|
|
326
|
+
servers: teamServers,
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export async function getProjectSectionContext({
|
|
331
|
+
userId,
|
|
332
|
+
teamSlug,
|
|
333
|
+
projectName,
|
|
334
|
+
scope,
|
|
335
|
+
}: {
|
|
336
|
+
userId: string
|
|
337
|
+
teamSlug: string
|
|
338
|
+
projectName: string
|
|
339
|
+
scope: ProjectSectionContext['scope']
|
|
340
|
+
}): Promise<ProjectSectionContext> {
|
|
341
|
+
if (scope === 'settings') {
|
|
342
|
+
const context = await getProjectContext({
|
|
343
|
+
userId,
|
|
344
|
+
teamSlug,
|
|
345
|
+
projectName,
|
|
346
|
+
scope: 'settings',
|
|
347
|
+
})
|
|
348
|
+
return {
|
|
349
|
+
scope,
|
|
350
|
+
projectId: context.project.id,
|
|
351
|
+
context,
|
|
352
|
+
composeMetadata: context.composeMetadata,
|
|
353
|
+
domains: context.domains,
|
|
354
|
+
envVars: context.envVars,
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const row = await requireProjectIdentity({
|
|
359
|
+
userId,
|
|
360
|
+
teamSlug,
|
|
361
|
+
projectName,
|
|
362
|
+
includeComposeMetadata: scope === 'backups',
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
if (scope === 'overview') {
|
|
366
|
+
const [projectDeployments, runtimeRows] = await Promise.all([
|
|
367
|
+
listProjectDeployments(row.project.id),
|
|
368
|
+
row.server
|
|
369
|
+
? db
|
|
370
|
+
.select({
|
|
371
|
+
lastSeenAt: agentRuntimeObservations.lastSeenAt,
|
|
372
|
+
services: agentRuntimeObservations.services,
|
|
373
|
+
})
|
|
374
|
+
.from(agentRuntimeObservations)
|
|
375
|
+
.where(
|
|
376
|
+
and(
|
|
377
|
+
eq(agentRuntimeObservations.serverId, row.server.id),
|
|
378
|
+
eq(
|
|
379
|
+
agentRuntimeObservations.runtimeId,
|
|
380
|
+
row.environment.runtimeId,
|
|
381
|
+
),
|
|
382
|
+
),
|
|
383
|
+
)
|
|
384
|
+
.limit(1)
|
|
385
|
+
: Promise.resolve([]),
|
|
386
|
+
])
|
|
387
|
+
|
|
388
|
+
return {
|
|
389
|
+
scope,
|
|
390
|
+
projectId: row.project.id,
|
|
391
|
+
deployments: projectDeployments,
|
|
392
|
+
runtime: mapRuntimeObservation(runtimeRows.at(0) ?? null),
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (scope === 'deployments') {
|
|
397
|
+
return {
|
|
398
|
+
scope,
|
|
399
|
+
projectId: row.project.id,
|
|
400
|
+
deployments: await listProjectDeployments(row.project.id),
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const [backupRows, environmentRows] = await Promise.all([
|
|
405
|
+
listProjectBackupRows(row.project.id),
|
|
406
|
+
db
|
|
407
|
+
.select()
|
|
408
|
+
.from(environments)
|
|
409
|
+
.where(
|
|
410
|
+
and(
|
|
411
|
+
eq(environments.projectId, row.project.id),
|
|
412
|
+
eq(environments.status, 'active'),
|
|
413
|
+
),
|
|
414
|
+
)
|
|
415
|
+
.orderBy(asc(environments.position), asc(environments.createdAt)),
|
|
416
|
+
])
|
|
417
|
+
const projectEnvironments = environmentRows.map((environment) =>
|
|
418
|
+
mapEnvironmentConfig(environment, row.project.defaultServerId),
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
return {
|
|
422
|
+
scope,
|
|
423
|
+
projectId: row.project.id,
|
|
424
|
+
backupStorage: await listBackupStorage(row.project.teamId),
|
|
425
|
+
...mapProjectBackupRows(backupRows, projectEnvironments),
|
|
426
|
+
composeMetadata: parseStoredComposeMetadata(row.project.composeMetadata),
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
async function listProjectBackupRows(projectId: string) {
|
|
431
|
+
const [configs, runs, restores] = await Promise.all([
|
|
432
|
+
db
|
|
433
|
+
.select()
|
|
434
|
+
.from(backupConfigs)
|
|
435
|
+
.where(eq(backupConfigs.projectId, projectId)),
|
|
436
|
+
db
|
|
437
|
+
.select({
|
|
438
|
+
backupRun: backupRuns,
|
|
439
|
+
environment: environments,
|
|
440
|
+
server: servers,
|
|
441
|
+
})
|
|
442
|
+
.from(backupRuns)
|
|
443
|
+
.innerJoin(environments, eq(environments.id, backupRuns.environmentId))
|
|
444
|
+
.leftJoin(servers, eq(servers.id, backupRuns.serverId))
|
|
445
|
+
.where(eq(backupRuns.projectId, projectId))
|
|
446
|
+
.orderBy(desc(backupRuns.createdAt))
|
|
447
|
+
.limit(50),
|
|
448
|
+
db
|
|
449
|
+
.select({
|
|
450
|
+
id: agentJobs.id,
|
|
451
|
+
serverId: agentJobs.serverId,
|
|
452
|
+
serverName: servers.name,
|
|
453
|
+
artifacts: sql<unknown>`json_extract(${agentJobs.payload}, '$.artifacts')`,
|
|
454
|
+
backupRunId: sql<string>`json_extract(${agentJobs.payload}, '$.backupRunId')`,
|
|
455
|
+
environmentId: sql<string>`json_extract(${agentJobs.payload}, '$.environmentId')`,
|
|
456
|
+
status: agentJobs.status,
|
|
457
|
+
errorMessage: agentJobs.errorMessage,
|
|
458
|
+
createdAt: agentJobs.createdAt,
|
|
459
|
+
startedAt: agentJobs.claimedAt,
|
|
460
|
+
finishedAt: agentJobs.finishedAt,
|
|
461
|
+
})
|
|
462
|
+
.from(agentJobs)
|
|
463
|
+
.leftJoin(servers, eq(servers.id, agentJobs.serverId))
|
|
464
|
+
.where(
|
|
465
|
+
and(eq(agentJobs.projectId, projectId), eq(agentJobs.type, 'restore')),
|
|
466
|
+
)
|
|
467
|
+
.orderBy(desc(agentJobs.createdAt))
|
|
468
|
+
.limit(50),
|
|
469
|
+
])
|
|
470
|
+
const runIds = runs.map(({ backupRun }) => backupRun.id)
|
|
471
|
+
const artifacts = runIds.length
|
|
472
|
+
? await db
|
|
473
|
+
.select()
|
|
474
|
+
.from(backupArtifacts)
|
|
475
|
+
.where(inArray(backupArtifacts.backupRunId, runIds))
|
|
476
|
+
: []
|
|
477
|
+
|
|
478
|
+
return { artifacts, configs, runs, restores }
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function mapProjectBackupRows(
|
|
482
|
+
rows: Awaited<ReturnType<typeof listProjectBackupRows>>,
|
|
483
|
+
projectEnvironments: ProjectContext['environments'],
|
|
484
|
+
) {
|
|
485
|
+
const artifactsByRunId = new Map<
|
|
486
|
+
string,
|
|
487
|
+
Array<typeof backupArtifacts.$inferSelect>
|
|
488
|
+
>()
|
|
489
|
+
for (const artifact of rows.artifacts) {
|
|
490
|
+
const artifacts = artifactsByRunId.get(artifact.backupRunId) ?? []
|
|
491
|
+
artifacts.push(artifact)
|
|
492
|
+
artifactsByRunId.set(artifact.backupRunId, artifacts)
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return {
|
|
496
|
+
backupRestores: rows.restores.map((restore) => ({
|
|
497
|
+
...restore,
|
|
498
|
+
artifacts: parseRestoreContents(restore.artifacts),
|
|
499
|
+
status:
|
|
500
|
+
restore.status === 'abandoned' ? ('failed' as const) : restore.status,
|
|
501
|
+
createdAt: restore.createdAt.toISOString(),
|
|
502
|
+
startedAt: restore.startedAt?.toISOString() ?? null,
|
|
503
|
+
finishedAt: restore.finishedAt?.toISOString() ?? null,
|
|
504
|
+
})),
|
|
505
|
+
backupConfigs: rows.configs.map(mapBackupConfig),
|
|
506
|
+
backupRuns: rows.runs.map((run) =>
|
|
507
|
+
mapBackupRun(
|
|
508
|
+
run,
|
|
509
|
+
projectEnvironments,
|
|
510
|
+
artifactsByRunId.get(run.backupRun.id) ?? [],
|
|
511
|
+
),
|
|
512
|
+
),
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const deploymentSummarySelection = {
|
|
517
|
+
deployment: {
|
|
518
|
+
id: deployments.id,
|
|
519
|
+
serverId: deployments.serverId,
|
|
520
|
+
status: deployments.status,
|
|
521
|
+
phase: deployments.phase,
|
|
522
|
+
trigger: deployments.trigger,
|
|
523
|
+
gitSha: deployments.gitSha,
|
|
524
|
+
gitBranch: deployments.gitBranch,
|
|
525
|
+
repoFullName: deployments.repoFullName,
|
|
526
|
+
commitMeta: deployments.commitMeta,
|
|
527
|
+
errorMessage: deployments.errorMessage,
|
|
528
|
+
createdAt: deployments.createdAt,
|
|
529
|
+
startedAt: deployments.startedAt,
|
|
530
|
+
finishedAt: deployments.finishedAt,
|
|
531
|
+
},
|
|
532
|
+
environment: {
|
|
533
|
+
name: environments.name,
|
|
534
|
+
slug: environments.slug,
|
|
535
|
+
color: environments.color,
|
|
536
|
+
},
|
|
537
|
+
project: { id: projects.id, name: projects.name },
|
|
538
|
+
server: {
|
|
539
|
+
id: servers.id,
|
|
540
|
+
name: servers.name,
|
|
541
|
+
status: servers.status,
|
|
542
|
+
lastSeenAt: servers.lastSeenAt,
|
|
543
|
+
},
|
|
544
|
+
deploymentAlias: { hostname: aliases.hostname, https: aliases.https },
|
|
545
|
+
serving:
|
|
546
|
+
sql<boolean>`exists(select 1 from aliases as live_alias where live_alias.environment_id = ${deployments.environmentId} and live_alias.type = 'environment' and live_alias.deployment_id = ${deployments.id})`.mapWith(
|
|
547
|
+
Boolean,
|
|
548
|
+
),
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
async function listProjectDeployments(projectId: string) {
|
|
552
|
+
const rows = await db
|
|
553
|
+
.select(deploymentSummarySelection)
|
|
554
|
+
.from(deployments)
|
|
555
|
+
.innerJoin(environments, eq(environments.id, deployments.environmentId))
|
|
556
|
+
.innerJoin(projects, eq(projects.id, environments.projectId))
|
|
557
|
+
.leftJoin(servers, eq(servers.id, deployments.serverId))
|
|
558
|
+
.leftJoin(
|
|
559
|
+
aliases,
|
|
560
|
+
and(
|
|
561
|
+
eq(aliases.deploymentId, deployments.id),
|
|
562
|
+
eq(aliases.type, 'deployment'),
|
|
563
|
+
),
|
|
564
|
+
)
|
|
565
|
+
.where(eq(environments.projectId, projectId))
|
|
566
|
+
.orderBy(desc(deployments.createdAt))
|
|
567
|
+
.limit(20)
|
|
568
|
+
|
|
569
|
+
return rows.map(mapDeployment)
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export async function listTeamDeployments({
|
|
573
|
+
teamId,
|
|
574
|
+
limit = 20,
|
|
575
|
+
}: {
|
|
576
|
+
teamId: string
|
|
577
|
+
limit?: number
|
|
578
|
+
}): Promise<Array<DeploymentSummary>> {
|
|
579
|
+
const deploymentRows = await db
|
|
580
|
+
.select(deploymentSummarySelection)
|
|
581
|
+
.from(deployments)
|
|
582
|
+
.innerJoin(environments, eq(environments.id, deployments.environmentId))
|
|
583
|
+
.innerJoin(projects, eq(projects.id, environments.projectId))
|
|
584
|
+
.leftJoin(servers, eq(servers.id, deployments.serverId))
|
|
585
|
+
.leftJoin(
|
|
586
|
+
aliases,
|
|
587
|
+
and(
|
|
588
|
+
eq(aliases.deploymentId, deployments.id),
|
|
589
|
+
eq(aliases.type, 'deployment'),
|
|
590
|
+
),
|
|
591
|
+
)
|
|
592
|
+
.where(and(eq(projects.teamId, teamId), eq(projects.status, 'active')))
|
|
593
|
+
.orderBy(desc(deployments.createdAt))
|
|
594
|
+
.limit(limit)
|
|
595
|
+
|
|
596
|
+
return deploymentRows.map((deploymentRow) => mapDeployment(deploymentRow))
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export async function getDeploymentSectionContext({
|
|
600
|
+
userId,
|
|
601
|
+
teamSlug,
|
|
602
|
+
projectName,
|
|
603
|
+
deploymentId,
|
|
604
|
+
}: {
|
|
605
|
+
userId: string
|
|
606
|
+
teamSlug: string
|
|
607
|
+
projectName: string
|
|
608
|
+
deploymentId: string
|
|
609
|
+
}): Promise<DeploymentSectionContext> {
|
|
610
|
+
const row = await requireProjectIdentity({ userId, teamSlug, projectName })
|
|
611
|
+
const [deploymentRows, latestDeployments, visitAliases] = await Promise.all([
|
|
612
|
+
db
|
|
613
|
+
.select(deploymentSummarySelection)
|
|
614
|
+
.from(deployments)
|
|
615
|
+
.innerJoin(environments, eq(environments.id, deployments.environmentId))
|
|
616
|
+
.innerJoin(projects, eq(projects.id, environments.projectId))
|
|
617
|
+
.leftJoin(servers, eq(servers.id, deployments.serverId))
|
|
618
|
+
.leftJoin(
|
|
619
|
+
aliases,
|
|
620
|
+
and(
|
|
621
|
+
eq(aliases.deploymentId, deployments.id),
|
|
622
|
+
eq(aliases.type, 'deployment'),
|
|
623
|
+
),
|
|
624
|
+
)
|
|
625
|
+
.where(
|
|
626
|
+
and(eq(deployments.id, deploymentId), eq(projects.id, row.project.id)),
|
|
627
|
+
)
|
|
628
|
+
.limit(1),
|
|
629
|
+
listProjectDeployments(row.project.id),
|
|
630
|
+
db
|
|
631
|
+
.select({
|
|
632
|
+
type: aliases.type,
|
|
633
|
+
hostname: aliases.hostname,
|
|
634
|
+
https: aliases.https,
|
|
635
|
+
})
|
|
636
|
+
.from(aliases)
|
|
637
|
+
.where(
|
|
638
|
+
and(
|
|
639
|
+
eq(aliases.projectId, row.project.id),
|
|
640
|
+
eq(aliases.deploymentId, deploymentId),
|
|
641
|
+
),
|
|
642
|
+
),
|
|
643
|
+
])
|
|
644
|
+
const deploymentRow = deploymentRows.at(0)
|
|
645
|
+
|
|
646
|
+
if (!deploymentRow) {
|
|
647
|
+
throw new PublicError('DEPLOYMENT_NOT_FOUND')
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return {
|
|
651
|
+
projectId: row.project.id,
|
|
652
|
+
latestDeployments,
|
|
653
|
+
deployment: mapDeployment(deploymentRow),
|
|
654
|
+
visitAliases,
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export async function getDeploymentLogsContext({
|
|
659
|
+
deploymentId,
|
|
660
|
+
projectName,
|
|
661
|
+
teamSlug,
|
|
662
|
+
userId,
|
|
663
|
+
}: {
|
|
664
|
+
deploymentId: string
|
|
665
|
+
projectName: string
|
|
666
|
+
teamSlug: string
|
|
667
|
+
userId: string
|
|
668
|
+
}) {
|
|
669
|
+
const rows = await db
|
|
670
|
+
.select({ id: deployments.id, projectId: environments.projectId })
|
|
671
|
+
.from(deployments)
|
|
672
|
+
.innerJoin(environments, eq(environments.id, deployments.environmentId))
|
|
673
|
+
.innerJoin(projects, eq(projects.id, environments.projectId))
|
|
674
|
+
.innerJoin(teams, eq(teams.id, projects.teamId))
|
|
675
|
+
.innerJoin(
|
|
676
|
+
teamMembers,
|
|
677
|
+
and(eq(teamMembers.teamId, teams.id), eq(teamMembers.userId, userId)),
|
|
678
|
+
)
|
|
679
|
+
.where(
|
|
680
|
+
and(
|
|
681
|
+
eq(deployments.id, deploymentId),
|
|
682
|
+
eq(projects.slug, projectName),
|
|
683
|
+
eq(projects.status, 'active'),
|
|
684
|
+
eq(teams.slug, teamSlug),
|
|
685
|
+
eq(teams.status, 'active'),
|
|
686
|
+
),
|
|
687
|
+
)
|
|
688
|
+
.limit(1)
|
|
689
|
+
|
|
690
|
+
const deployment = rows[0]
|
|
691
|
+
if (!deployment) throw new PublicError('DEPLOYMENT_NOT_FOUND')
|
|
692
|
+
const logs = await readProjectDeploymentLogs(
|
|
693
|
+
{ projectId: deployment.projectId, deploymentId },
|
|
694
|
+
1_000,
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
return logs.reverse().map((log) => ({
|
|
698
|
+
...log,
|
|
699
|
+
createdAt: log.createdAt.toISOString(),
|
|
700
|
+
}))
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export async function getProjectLogsSectionContext({
|
|
704
|
+
userId,
|
|
705
|
+
teamSlug,
|
|
706
|
+
projectName,
|
|
707
|
+
branch,
|
|
708
|
+
date,
|
|
709
|
+
deploymentId,
|
|
710
|
+
environmentId,
|
|
711
|
+
keyword,
|
|
712
|
+
}: {
|
|
713
|
+
userId: string
|
|
714
|
+
teamSlug: string
|
|
715
|
+
projectName: string
|
|
716
|
+
branch?: string | null
|
|
717
|
+
date?: string | null
|
|
718
|
+
deploymentId?: string | null
|
|
719
|
+
environmentId?: string | null
|
|
720
|
+
keyword?: string | null
|
|
721
|
+
}): Promise<ProjectLogsSectionContext> {
|
|
722
|
+
const row = await requireProjectIdentity({ userId, teamSlug, projectName })
|
|
723
|
+
const normalizedBranch = branch?.trim() || null
|
|
724
|
+
const normalizedDate = date?.trim() || null
|
|
725
|
+
const normalizedDeploymentId = deploymentId?.trim() || null
|
|
726
|
+
const normalizedEnvironmentId = environmentId?.trim() || null
|
|
727
|
+
const normalizedKeyword = keyword?.trim() || null
|
|
728
|
+
|
|
729
|
+
const since = getDatePresetStart(normalizedDate)
|
|
730
|
+
const deploymentLogsQuery = readProjectDeploymentLogs({
|
|
731
|
+
projectId: row.project.id,
|
|
732
|
+
branch: normalizedBranch,
|
|
733
|
+
deploymentId: normalizedDeploymentId,
|
|
734
|
+
environmentId: normalizedEnvironmentId,
|
|
735
|
+
keyword: normalizedKeyword,
|
|
736
|
+
since,
|
|
737
|
+
})
|
|
738
|
+
const runtimeLogsQuery = normalizedDeploymentId
|
|
739
|
+
? Promise.resolve([])
|
|
740
|
+
: readProjectRuntimeLogs({
|
|
741
|
+
projectId: row.project.id,
|
|
742
|
+
branch: normalizedBranch,
|
|
743
|
+
environmentId: normalizedEnvironmentId,
|
|
744
|
+
keyword: normalizedKeyword,
|
|
745
|
+
since,
|
|
746
|
+
})
|
|
747
|
+
const [
|
|
748
|
+
projectDeployments,
|
|
749
|
+
deploymentLogRows,
|
|
750
|
+
runtimeLogRows,
|
|
751
|
+
deploymentLogExists,
|
|
752
|
+
runtimeLogExists,
|
|
753
|
+
] = await Promise.all([
|
|
754
|
+
listProjectDeployments(row.project.id),
|
|
755
|
+
deploymentLogsQuery,
|
|
756
|
+
runtimeLogsQuery,
|
|
757
|
+
projectHasDeploymentLogs(row.project.id),
|
|
758
|
+
projectHasRuntimeLogs(row.project.id),
|
|
759
|
+
])
|
|
760
|
+
const logs: Array<ProjectLogEntry> = [
|
|
761
|
+
...deploymentLogRows.map((log) => ({
|
|
762
|
+
source: 'deployment' as const,
|
|
763
|
+
deploymentId: log.deploymentId,
|
|
764
|
+
runtimeId: null,
|
|
765
|
+
service: null,
|
|
766
|
+
stream: log.stream,
|
|
767
|
+
seq: log.seq,
|
|
768
|
+
content: log.content,
|
|
769
|
+
createdAt: log.createdAt.toISOString(),
|
|
770
|
+
})),
|
|
771
|
+
...runtimeLogRows.map((log, index) => ({
|
|
772
|
+
source: 'runtime' as const,
|
|
773
|
+
deploymentId: null,
|
|
774
|
+
runtimeId: log.runtimeId,
|
|
775
|
+
service: log.service,
|
|
776
|
+
stream: 'runtime',
|
|
777
|
+
seq: index + 1,
|
|
778
|
+
content: log.content,
|
|
779
|
+
createdAt: log.createdAt.toISOString(),
|
|
780
|
+
})),
|
|
781
|
+
]
|
|
782
|
+
.sort(
|
|
783
|
+
(left, right) =>
|
|
784
|
+
new Date(right.createdAt).getTime() -
|
|
785
|
+
new Date(left.createdAt).getTime(),
|
|
786
|
+
)
|
|
787
|
+
.slice(0, 200)
|
|
788
|
+
|
|
789
|
+
return {
|
|
790
|
+
projectId: row.project.id,
|
|
791
|
+
deployments: projectDeployments,
|
|
792
|
+
logs,
|
|
793
|
+
hasAnyLogs: deploymentLogExists || runtimeLogExists,
|
|
794
|
+
filters: {
|
|
795
|
+
branch: normalizedBranch,
|
|
796
|
+
date: normalizedDate,
|
|
797
|
+
deploymentId: normalizedDeploymentId,
|
|
798
|
+
environmentId: normalizedEnvironmentId,
|
|
799
|
+
keyword: normalizedKeyword,
|
|
800
|
+
},
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function getDatePresetStart(preset: string | null) {
|
|
805
|
+
if (!preset) {
|
|
806
|
+
return null
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const now = new Date()
|
|
810
|
+
|
|
811
|
+
if (preset === 'today') {
|
|
812
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate())
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
const hours =
|
|
816
|
+
preset === '24h'
|
|
817
|
+
? 24
|
|
818
|
+
: preset === '7d'
|
|
819
|
+
? 24 * 7
|
|
820
|
+
: preset === '30d'
|
|
821
|
+
? 24 * 30
|
|
822
|
+
: null
|
|
823
|
+
|
|
824
|
+
if (hours == null) {
|
|
825
|
+
return null
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return new Date(now.getTime() - hours * 60 * 60 * 1000)
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function mapProject(
|
|
832
|
+
project: typeof projects.$inferSelect,
|
|
833
|
+
): ProjectContext['project'] {
|
|
834
|
+
const runtimeConfig = requireProjectRuntimeConfig(project.runtimeConfig)
|
|
835
|
+
return {
|
|
836
|
+
settingsVersion: project.settingsVersion,
|
|
837
|
+
id: project.id,
|
|
838
|
+
name: project.name,
|
|
839
|
+
githubInstallationId: project.githubInstallationId,
|
|
840
|
+
githubRepoId: project.githubRepoId,
|
|
841
|
+
githubRepo: project.githubRepo,
|
|
842
|
+
defaultServerId: project.defaultServerId,
|
|
843
|
+
avatarUrl: project.avatarPath,
|
|
844
|
+
runtimeConfig,
|
|
845
|
+
color: getResourceColor(project.id),
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function parseStoredComposeMetadata(value: unknown) {
|
|
850
|
+
if (!value || typeof value !== 'object') return null
|
|
851
|
+
|
|
852
|
+
const metadata = value as Partial<ProjectComposeMetadata>
|
|
853
|
+
if (
|
|
854
|
+
!Array.isArray(metadata.services) ||
|
|
855
|
+
!Array.isArray(metadata.volumes) ||
|
|
856
|
+
!Array.isArray(metadata.warnings)
|
|
857
|
+
) {
|
|
858
|
+
return null
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
return value as ProjectComposeMetadata
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function parseRestoreContents(value: unknown) {
|
|
865
|
+
const rows = typeof value === 'string' ? JSON.parse(value) : value
|
|
866
|
+
if (!Array.isArray(rows)) return []
|
|
867
|
+
return rows
|
|
868
|
+
.filter(
|
|
869
|
+
(item) =>
|
|
870
|
+
item &&
|
|
871
|
+
typeof item.id === 'string' &&
|
|
872
|
+
['volume', 'database'].includes(item.type),
|
|
873
|
+
)
|
|
874
|
+
.map((item) => ({
|
|
875
|
+
artifactId: item.id as string,
|
|
876
|
+
type: item.type as 'volume' | 'database',
|
|
877
|
+
targetVolume:
|
|
878
|
+
typeof item.targetVolume === 'string' ? item.targetVolume : undefined,
|
|
879
|
+
targetService:
|
|
880
|
+
typeof item.targetService === 'string' ? item.targetService : undefined,
|
|
881
|
+
}))
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// Resolve only after joining current membership; the public opaque ID grants no access.
|
|
885
|
+
export async function resolveUnavailableDeployment(
|
|
886
|
+
userId: string,
|
|
887
|
+
deploymentId: string,
|
|
888
|
+
) {
|
|
889
|
+
const [row] = await db
|
|
890
|
+
.select({ teamSlug: teams.slug, projectName: projects.slug })
|
|
891
|
+
.from(deployments)
|
|
892
|
+
.innerJoin(environments, eq(environments.id, deployments.environmentId))
|
|
893
|
+
.innerJoin(
|
|
894
|
+
projects,
|
|
895
|
+
and(
|
|
896
|
+
eq(projects.id, environments.projectId),
|
|
897
|
+
eq(projects.status, 'active'),
|
|
898
|
+
),
|
|
899
|
+
)
|
|
900
|
+
.innerJoin(teams, eq(teams.id, projects.teamId))
|
|
901
|
+
.innerJoin(
|
|
902
|
+
teamMembers,
|
|
903
|
+
and(eq(teamMembers.teamId, teams.id), eq(teamMembers.userId, userId)),
|
|
904
|
+
)
|
|
905
|
+
.where(eq(deployments.id, deploymentId))
|
|
906
|
+
.limit(1)
|
|
907
|
+
if (!row) throw new PublicError('DEPLOYMENT_NOT_FOUND')
|
|
908
|
+
return row
|
|
909
|
+
}
|