diff --git a/frontend/src/lib/components/DeployWorkspace.svelte b/frontend/src/lib/components/DeployWorkspace.svelte index 4c7fae7ccd..95e02fc3db 100644 --- a/frontend/src/lib/components/DeployWorkspace.svelte +++ b/frontend/src/lib/components/DeployWorkspace.svelte @@ -34,9 +34,12 @@ } from '$lib/utils_deployable' import { checkItemExists, + deployFromWorkspace, deployItem, getItemValue, - getOnBehalfOf + getOnBehalfOf, + serverDeployKind, + type DeployResult } from '$lib/utils_workspace_deploy' import type { App } from './apps/types' import { getAllGridItems } from './apps/editor/appUtils' @@ -382,16 +385,35 @@ const target = workspaceToDeployTo deploymentStatus[statusPath] = { status: 'loading' } - const result = await deployItem({ - kind, - path, - workspaceFrom: $operatingWorkspace!, - workspaceTo: target!, - additionalInformation, - onBehalfOf: getOnBehalfOfForDeploy(statusPath, kind), - onBehalfOfPrincipal: getOnBehalfOfPermissionedAsForDeploy(statusPath, kind), - targetBaseUrl: isRemote ? remoteTarget?.base_url : undefined - }) + const onBehalfOf = getOnBehalfOfForDeploy(statusPath, kind) + const onBehalfOfPrincipal = getOnBehalfOfPermissionedAsForDeploy(statusPath, kind) + const serverKind = serverDeployKind(kind, additionalInformation) + let result: DeployResult + if (isRemote) { + // The server deploy writes only to this instance; another one is reached through the + // remote-deploy proxy, which the client-side deploy calls route by route. + result = await deployItem({ + kind, + path, + workspaceFrom: $operatingWorkspace!, + workspaceTo: target!, + additionalInformation, + onBehalfOf, + onBehalfOfPrincipal, + targetBaseUrl: remoteTarget?.base_url + }) + } else if (serverKind) { + result = await deployFromWorkspace({ + kind: serverKind, + path, + workspaceFrom: $operatingWorkspace!, + workspaceTo: target!, + onBehalfOf, + onBehalfOfPrincipal + }) + } else { + result = { success: false, error: `Cannot deploy ${kind} ${path}` } + } // The statuses on screen are the current destination's; this deploy went to `target`. if (target !== workspaceToDeployTo) return diff --git a/frontend/src/lib/utils_workspace_deploy.ts b/frontend/src/lib/utils_workspace_deploy.ts index 85770d3e43..d1a31e9860 100644 --- a/frontend/src/lib/utils_workspace_deploy.ts +++ b/frontend/src/lib/utils_workspace_deploy.ts @@ -24,6 +24,7 @@ import type { UserDraftItemKind } from '$lib/gen' import { get } from 'svelte/store' import { userWorkspaces } from '$lib/stores' import { apiBaseUrl } from './apiBaseUrl.svelte' +import type { TriggerKind } from './components/triggers' import { capabilitiesIn } from '$lib/roleCapabilities' import { roleCanAuthor } from '$lib/editRights' import type { ProtectionRuleset, RoleCapabilities } from '$lib/gen' @@ -174,6 +175,32 @@ function legacyTriggerKind(kind: TriggerDeployKind) { return map[kind] } +/** The server deploy's kind for each trigger kind `DeployWorkspace.svelte` names. */ +const SERVER_TRIGGER_KIND: Partial> = { + schedules: 'schedule', + routes: 'http_trigger', + websockets: 'websocket_trigger', + kafka: 'kafka_trigger', + nats: 'nats_trigger', + postgres: 'postgres_trigger', + mqtt: 'mqtt_trigger', + amqp: 'amqp_trigger', + sqs: 'sqs_trigger', + gcp: 'gcp_trigger', + azure: 'azure_trigger', + emails: 'email_trigger' +} + +/** + * The kind the server deploy takes, resolving the generic `'trigger'` `DeployWorkspace.svelte` + * uses. Undefined for a trigger whose sub-kind is unknown or not deployable. + */ +export function serverDeployKind(kind: Kind, info?: AdditionalInformation): Kind | undefined { + if (kind !== 'trigger') return kind + const legacy = info?.triggers?.kind + return legacy && SERVER_TRIGGER_KIND[legacy] +} + /** An identity in both formats the app policy stores it in. */ export type AppIdentity = { email: string; permissionedAs: string }