{"version":3,"file":"editor-BXtXOryt.mjs","names":[],"sources":["../../editors/connection-editor/connection-usage.ts","../../editors/connection-editor/ConnectionToolbar.tsx","../../editors/connection-editor/UsedBy.tsx","../../editors/connection-editor/editor.tsx"],"sourcesContent":["// Which workflows depend on a connection, and where. Answers the question a\n// connection page has to answer before anyone dares revoke or delete it.\n\nexport interface UsageStep {\n  id: string;\n  key: string;\n  name: string;\n  pieceName: string;\n  pieceVersion: string;\n  actionName: string;\n}\n\nexport interface UsageWorkflow {\n  id: string;\n  name: string;\n  status: string;\n  trigger?: { connectionId?: string | null } | null;\n  steps: readonly UsageStep[];\n}\n\nexport interface ConnectionUsage {\n  workflow: UsageWorkflow;\n  // The trigger binds this connection.\n  trigger: boolean;\n  steps: UsageStep[];\n}\n\nexport function connectionUsage(\n  connectionId: string,\n  workflows: readonly UsageWorkflow[],\n): ConnectionUsage[] {\n  const usage: ConnectionUsage[] = [];\n  for (const workflow of workflows) {\n    const trigger = workflow.trigger?.connectionId === connectionId;\n    const steps = workflow.steps.filter(\n      (step) =>\n        (step as { connectionId?: string | null }).connectionId ===\n        connectionId,\n    );\n    if (trigger || steps.length > 0) usage.push({ workflow, trigger, steps });\n  }\n  return usage.sort((a, b) => a.workflow.name.localeCompare(b.workflow.name));\n}\n\n// An enabled workflow that depends on this connection breaks the moment it is\n// revoked, so the UI warns before that happens.\nexport function enabledDependents(usage: ConnectionUsage[]): number {\n  return usage.filter((entry) => entry.workflow.status === \"ENABLED\").length;\n}\n","// Connection identity and state, in the same shape as the workflow editor's\n// toolbar: name, connector, status, and the one destructive action.\nimport { useState } from \"react\";\nimport type { ConnectionState } from \"document-models/connection\";\nimport type { ConnectionCheckResult } from \"../workflow-editor/runtime-client.js\";\nimport {\n  usePieceCatalog,\n  useRuntimeActions,\n} from \"../workflow-editor/runtime-context.js\";\nimport { packageFromConnectorId } from \"./piece-auth.js\";\nimport { Button } from \"../shared/controls.js\";\nimport { Icon } from \"../shared/icons.js\";\nimport { formatWhen } from \"../workflow-studio/components/run-format.js\";\nimport { CONNECTION_STATUS_LABEL, CONNECTION_STATUS_STYLES } from \"./status.js\";\n\n// Runs the piece's own check server-side; the outcome lands on the document.\nfunction useConnectionTest(connectionId: string) {\n  const [testing, setTesting] = useState(false);\n  const [result, setResult] = useState<ConnectionCheckResult | null>(null);\n  const { checkConnection } = useRuntimeActions();\n  const test = () => {\n    setTesting(true);\n    setResult(null);\n    checkConnection(connectionId)\n      .then(setResult)\n      .catch((error: unknown) =>\n        setResult({\n          ok: false,\n          detail: error instanceof Error ? error.message : String(error),\n          accountLabel: null,\n        }),\n      )\n      .finally(() => setTesting(false));\n  };\n  return { testing, result, test };\n}\n\nexport function ConnectionToolbar(props: {\n  connectionId: string;\n  // Enabled workflows that stop working if this is revoked.\n  enabledDependents: number;\n  state: ConnectionState;\n  onRename: (name: string) => void;\n  onSetStatus: (status: \"OK\" | \"REVOKED\") => void;\n  onDelete: () => void;\n}) {\n  const { state } = props;\n  // Shared with the form below through the editor's query cache.\n  const catalog = usePieceCatalog().data;\n\n  const packageName = packageFromConnectorId(state.connectorId);\n  const piece = catalog?.find((entry) => entry.name === packageName);\n  const revoked = state.status === \"REVOKED\";\n  const { testing, result, test } = useConnectionTest(props.connectionId);\n\n  return (\n    <header className=\"mb-8 flex flex-wrap items-start gap-4\">\n      <div className=\"flex h-14 w-14 shrink-0 items-center justify-center rounded-xl border border-solid border-foreground/10 bg-white\">\n        {piece?.logoUrl ? (\n          <img src={piece.logoUrl} alt=\"\" className=\"h-8 w-8 object-contain\" />\n        ) : (\n          <Icon name=\"link\" className=\"h-6 w-6 text-neutral-500\" />\n        )}\n      </div>\n      <div className=\"min-w-0 flex-1\">\n        <input\n          key={state.name}\n          className=\"-mx-1.5 w-full max-w-md rounded-md border border-solid border-transparent bg-transparent px-1.5 text-xl font-semibold tracking-tight text-foreground hover:border-foreground/15 focus:border-ring focus:outline-none focus:ring-2 focus:ring-ring/25\"\n          defaultValue={state.name}\n          placeholder=\"Untitled connection\"\n          spellCheck={false}\n          aria-label=\"Connection name\"\n          onKeyDown={(event) => {\n            if (event.key === \"Enter\") event.currentTarget.blur();\n          }}\n          onBlur={(event) => {\n            const name = event.target.value.trim();\n            if (name && name !== state.name) props.onRename(name);\n          }}\n        />\n        <p className=\"mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-[13px] text-muted-foreground\">\n          <span\n            className={`rounded-full px-2 py-0.5 text-xs font-medium ${CONNECTION_STATUS_STYLES[state.status]}`}\n          >\n            {CONNECTION_STATUS_LABEL[state.status]}\n          </span>\n          <span>\n            {piece?.displayName ?? (packageName || \"No service picked\")}\n            {state.accountLabel ? (\n              <>\n                {\" \"}\n                as{\" \"}\n                <span className=\"font-medium text-foreground\">\n                  {state.accountLabel}\n                </span>\n              </>\n            ) : null}\n          </span>\n        </p>\n        <p\n          className=\"mt-1 text-xs text-muted-foreground\"\n          title={\n            state.lastCheckedAt\n              ? new Date(state.lastCheckedAt).toLocaleString()\n              : undefined\n          }\n        >\n          {state.lastCheckedAt\n            ? `Last checked ${formatWhen(state.lastCheckedAt)}`\n            : \"Never checked\"}\n        </p>\n      </div>\n      <div className=\"flex items-center gap-2\">\n        <Button size=\"sm\" variant=\"danger\" onClick={props.onDelete}>\n          Delete\n        </Button>\n        <Button\n          size=\"sm\"\n          title={\n            !revoked && props.enabledDependents > 0\n              ? `${props.enabledDependents} enabled ${props.enabledDependents === 1 ? \"workflow stops\" : \"workflows stop\"} working while it's revoked`\n              : undefined\n          }\n          onClick={() => props.onSetStatus(revoked ? \"OK\" : \"REVOKED\")}\n        >\n          {revoked ? \"Reactivate\" : \"Revoke\"}\n        </Button>\n        <Button\n          size=\"sm\"\n          variant=\"primary\"\n          disabled={testing || revoked || !packageName}\n          onClick={test}\n        >\n          <Icon name=\"check\" className=\"h-3.5 w-3.5\" />\n          {testing ? \"Testing…\" : \"Test connection\"}\n        </Button>\n      </div>\n      {result ? (\n        <p\n          role=\"status\"\n          className={`flex w-full items-start gap-2 rounded-md px-3 py-2 text-xs ${\n            result.ok ? \"bg-wf-ok/10 text-wf-ok\" : \"bg-wf-fail/10 text-wf-fail\"\n          }`}\n        >\n          <Icon\n            name={result.ok ? \"check\" : \"alert\"}\n            className=\"mt-px h-3.5 w-3.5\"\n          />\n          <span className=\"min-w-0 break-words\">\n            {result.ok\n              ? `It works${result.accountLabel ? `, signed in as ${result.accountLabel}` : \"\"}.`\n              : result.detail}\n          </span>\n        </p>\n      ) : null}\n    </header>\n  );\n}\n","// The workflows that depend on this connection, and through which steps, so\n// nobody revokes or deletes it blind.\nimport { setSelectedNode } from \"@powerhousedao/reactor-browser\";\nimport { useWorkflowDocumentsInSelectedDrive } from \"document-models/workflow\";\nimport { BlockLogo } from \"../workflow-editor/ui/BlockSelector.js\";\nimport { stepBlock } from \"../workflow-editor/ui/blocks.js\";\nimport {\n  connectionUsage,\n  type ConnectionUsage,\n  type UsageWorkflow,\n} from \"./connection-usage.js\";\n\nexport function useConnectionUsage(connectionId: string) {\n  const workflows = useWorkflowDocumentsInSelectedDrive() ?? [];\n  return connectionUsage(\n    connectionId,\n    workflows.map((workflow): UsageWorkflow => ({\n      id: workflow.header.id,\n      name: workflow.state.global.name || workflow.header.name || \"Untitled\",\n      status: workflow.state.global.status,\n      trigger: workflow.state.global.trigger,\n      steps: workflow.state.global.steps,\n    })),\n  );\n}\n\nexport function UsedBy(props: { usage: ConnectionUsage[] }) {\n  const { usage } = props;\n  return (\n    <section className=\"mt-8 border-t border-solid border-foreground/10 pt-5\">\n      <h3 className=\"text-[13px] font-semibold text-foreground\">Used by</h3>\n      {usage.length === 0 ? (\n        <p className=\"mt-1 text-xs text-muted-foreground\">\n          No workflow uses this connection yet. Pick it on a step in a\n          workflow's editor.\n        </p>\n      ) : (\n        <ul className=\"-mx-2 mt-2 flex flex-col\">\n          {usage.map((entry) => (\n            <li key={entry.workflow.id}>\n              <button\n                type=\"button\"\n                className=\"flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-[13px] hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                onClick={() => setSelectedNode(entry.workflow.id)}\n              >\n                <span className=\"shrink-0 font-medium text-foreground\">\n                  {entry.workflow.name}\n                </span>\n                {entry.workflow.status !== \"ENABLED\" ? (\n                  <span className=\"shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] text-muted-foreground\">\n                    {entry.workflow.status.charAt(0) +\n                      entry.workflow.status.slice(1).toLowerCase()}\n                  </span>\n                ) : null}\n                <span className=\"flex min-w-0 items-center gap-1.5 truncate text-xs text-muted-foreground\">\n                  {entry.steps.map((step) => (\n                    <span\n                      key={step.id}\n                      className=\"inline-flex items-center gap-1\"\n                    >\n                      <BlockLogo block={stepBlock(step)} size={14} bare />\n                      {step.name || step.key}\n                    </span>\n                  ))}\n                  {entry.trigger ? <span>Trigger</span> : null}\n                </span>\n              </button>\n            </li>\n          ))}\n        </ul>\n      )}\n    </section>\n  );\n}\n","import {\n  showDeleteNodeModal,\n  useSelectedDocumentId,\n} from \"@powerhousedao/reactor-browser\";\nimport { useSelectedConnectionDocument } from \"document-models/connection\";\nimport { DocumentErrorBoundary } from \"../shared/DocumentErrorBoundary.js\";\nimport { BackButton, UndoRedo } from \"../shared/editor-chrome.js\";\nimport { WorkflowRuntimeProvider } from \"../workflow-editor/runtime-context.js\";\nimport { connectionCallbacks } from \"./connection-callbacks.js\";\nimport { ConnectionForm } from \"./connection-form.js\";\nimport { enabledDependents } from \"./connection-usage.js\";\nimport { ConnectionToolbar } from \"./ConnectionToolbar.js\";\nimport { UsedBy, useConnectionUsage } from \"./UsedBy.js\";\n\nfunction ConnectionEditor() {\n  const [document, dispatch] = useSelectedConnectionDocument();\n  const state = document.state.global;\n\n  const callbacks = connectionCallbacks(state, dispatch);\n  const usage = useConnectionUsage(document.header.id);\n\n  return (\n    <div className=\"flex h-full min-h-0 flex-col bg-background\">\n      <div className=\"flex items-center justify-between border-b border-solid border-foreground/10 px-4 py-2\">\n        <BackButton />\n        <UndoRedo documentId={document.header.id} />\n      </div>\n      <div className=\"min-h-0 flex-1 overflow-y-auto\">\n        <div className=\"mx-auto w-full max-w-2xl px-6 py-10\">\n          <ConnectionToolbar\n            connectionId={document.header.id}\n            enabledDependents={enabledDependents(usage)}\n            state={state}\n            onRename={callbacks.setName}\n            onSetStatus={callbacks.setStatus}\n            onDelete={() => showDeleteNodeModal(document.header.id)}\n          />\n          <ConnectionForm\n            state={state}\n            callbacks={callbacks}\n            connectionId={document.header.id}\n          />\n          <UsedBy usage={usage} />\n        </div>\n      </div>\n    </div>\n  );\n}\n\n// A drive node can point at a document the reactor cannot serve; the document\n// hooks throw for it. The boundary keeps that failure inside the editor pane.\nexport default function Editor() {\n  const documentId = useSelectedDocumentId();\n  return (\n    <DocumentErrorBoundary documentId={documentId}>\n      <WorkflowRuntimeProvider>\n        <ConnectionEditor />\n      </WorkflowRuntimeProvider>\n    </DocumentErrorBoundary>\n  );\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,gBACd,cACA,WACmB;CACnB,MAAM,QAA2B,CAAC;CAClC,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,UAAU,SAAS,SAAS,iBAAiB;EACnD,MAAM,QAAQ,SAAS,MAAM,QAC1B,SACE,KAA0C,iBAC3C,YACJ;EACA,IAAI,WAAW,MAAM,SAAS,GAAG,MAAM,KAAK;GAAE;GAAU;GAAS;EAAM,CAAC;CAC1E;CACA,OAAO,MAAM,MAAM,GAAG,MAAM,EAAE,SAAS,KAAK,cAAc,EAAE,SAAS,IAAI,CAAC;AAC5E;AAIA,SAAgB,kBAAkB,OAAkC;CAClE,OAAO,MAAM,QAAQ,UAAU,MAAM,SAAS,WAAW,SAAS,CAAC,CAAC;AACtE;;;AChCA,SAAS,kBAAkB,cAAsB;CAC/C,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,QAAQ,aAAa,SAAuC,IAAI;CACvE,MAAM,EAAE,oBAAoB,kBAAkB;CAC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