{"version":3,"file":"index.mjs","names":["setPath"],"sources":["../src/providers.ts","../src/api.ts","../src/settings.ts","../src/status.ts","../src/summary.ts","../src/unmapped.ts","../src/walk.ts","../src/index.ts"],"sourcesContent":["/**\n * The back-office platforms Fluid Connect links to Fluid.\n *\n * Only what the API doesn't report lives here: the slug fluid-integrations\n * names each provider by, the droplet name the Fluid marketplace lists it\n * under, and which credential groups its connection needs. Settings,\n * supported mappings, and mapping options are read live from the API.\n */\n/** One credential the connection needs. `key` is the dotted path in\n *  `auth_settings` (the same names `fluid connect credentials --set` takes). */\nexport interface CredentialField {\n  key: string;\n  label: string;\n  /** Typed without echo, and never shown back. */\n  secret?: boolean;\n  /** Fluid has a default for it, so it can be left blank. */\n  optional?: boolean;\n}\n\nconst MSSQL_CREDENTIALS: readonly CredentialField[] = [\n  { key: \"mssql.dataserver\", label: \"SQL Server host (data server)\" },\n  { key: \"mssql.database\", label: \"SQL Server database name\" },\n  { key: \"mssql.username\", label: \"SQL Server login username\" },\n  { key: \"mssql.password\", label: \"SQL Server login password\", secret: true },\n];\n\nexport const PROVIDERS = {\n  exigo: {\n    label: \"Exigo\",\n    slug: \"exigo\",\n    dropletName: \"Exigo\",\n    // Reads changes from Exigo's SQL Server; writes through Exigo's API.\n    credentialGroups: [\"api\", \"mssql\"],\n    credentials: [\n      { key: \"api.company\", label: \"Exigo company login (company code)\" },\n      { key: \"api.username\", label: \"Exigo API service-account username\" },\n      { key: \"api.password\", label: \"Exigo API service-account password\", secret: true },\n      ...MSSQL_CREDENTIALS,\n    ],\n    // Exigo also asks `environment`, and `sandbox_id` outside production.\n    environments: true,\n    // Exigo's own values for the target side of a mapping.\n    targetOptions: true,\n  },\n  bydesign: {\n    label: \"ByDesign\",\n    slug: \"bydesign\",\n    dropletName: \"ByDesign\",\n    credentialGroups: [\"api\"],\n    credentials: [\n      { key: \"api.company\", label: \"ByDesign tenant (company) code\" },\n      { key: \"api.username\", label: \"ByDesign API service-account username\" },\n      { key: \"api.password\", label: \"ByDesign API service-account password\", secret: true },\n      { key: \"api.api_url\", label: \"Freedom API host (blank for Fluid's default)\", optional: true },\n    ],\n    environments: false,\n    targetOptions: false,\n  },\n  infotrax: {\n    label: \"InfoTrax\",\n    slug: \"infotrax\",\n    dropletName: \"Infotrax\",\n    credentialGroups: [\"api\", \"mssql\"],\n    credentials: MSSQL_CREDENTIALS,\n    environments: false,\n    targetOptions: false,\n  },\n  pillars: {\n    label: \"Pillars\",\n    slug: \"pillars\",\n    dropletName: \"Pillars\",\n    credentialGroups: [\"api\"],\n    credentials: [\n      { key: \"api.token\", label: \"Pillars API token\", secret: true },\n      { key: \"api.api_url\", label: \"Pillars API base URL\" },\n    ],\n    environments: false,\n    targetOptions: false,\n  },\n} as const satisfies Record<\n  string,\n  {\n    label: string;\n    slug: string;\n    dropletName: string;\n    credentialGroups: readonly string[];\n    credentials: readonly CredentialField[];\n    environments: boolean;\n    targetOptions: boolean;\n  }\n>;\n\nexport type ProviderId = keyof typeof PROVIDERS;\nexport type Provider = (typeof PROVIDERS)[ProviderId];\n\nexport const PROVIDER_IDS = Object.keys(PROVIDERS) as ProviderId[];\n\n/** Scopes the Connect droplet is installed with (the same set Mist uses). */\nexport const CONNECT_DROPLET_SCOPES = [\n  \"main\",\n  \"members\",\n  \"prospects\",\n  \"products\",\n  \"orders\",\n  \"users\",\n  \"settings\",\n] as const;\n\nexport class ConnectError extends Error {\n  constructor(message: string) {\n    super(message);\n    this.name = \"ConnectError\";\n  }\n}\n\nexport function providerOf(id: string): Provider & { id: ProviderId } {\n  const key = id.trim().toLowerCase();\n  if (!(key in PROVIDERS)) {\n    throw new ConnectError(\n      `Unknown provider \"${id}\". Use one of: ${PROVIDER_IDS.join(\", \")}.`,\n    );\n  }\n  return { id: key as ProviderId, ...PROVIDERS[key as ProviderId] };\n}\n","import {\n  CONNECT_DROPLET_SCOPES,\n  ConnectError,\n  type Provider,\n  type ProviderId,\n} from \"./providers.js\";\n\n/** The slice of the CLI's API client these calls use. */\nexport interface ConnectClient {\n  get<T>(endpoint: string, params?: Record<string, unknown>): Promise<T>;\n  post<T>(endpoint: string, body?: unknown): Promise<T>;\n  put<T>(endpoint: string, body?: unknown): Promise<T>;\n  delete<T>(endpoint: string): Promise<T>;\n}\n\nexport const DEFAULT_INTEGRATIONS_BASE =\n  \"https://integrations-api.fluid.app\";\n\n/** fluid-integrations, where Connect's configuration lives. It accepts the\n *  same Fluid API token the CLI sends to api.fluid.app. */\nexport function integrationsBase(): string {\n  return (process.env[\"FLUID_INTEGRATIONS_BASE\"] ?? DEFAULT_INTEGRATIONS_BASE)\n    .trim()\n    .replace(/\\/$/, \"\");\n}\n\ninterface IntegrationWire {\n  id?: number;\n  name?: string;\n  droplet_uuid?: string | null;\n  company_integration_id?: number | null;\n  is_connected?: boolean | null;\n  supported_entities?: string[];\n  supported_sync_modes?: string[];\n}\n\nexport interface ProviderStatus {\n  provider: ProviderId;\n  label: string;\n  /** False when the company has no connection to the provider yet. */\n  installed: boolean;\n  connected: boolean;\n  companyIntegrationId: number | null;\n  /** The official droplet for the provider, as fluid-integrations names it. */\n  dropletUuid: string | null;\n  /** fluid-integrations' id for the provider, used to create a connection. */\n  integrationId: number | null;\n}\n\n/** The provider's integration as fluid-integrations sees this company. */\n/**\n * fluid-integrations has no record of a company until its first Connect\n * droplet is installed in Fluid, so it answers a new company's token with\n * 409 company_not_installed. Nothing is installed yet, which is what every\n * caller needs to know; installing goes through Fluid, not this service.\n */\nexport function isCompanyNotInstalled(error: unknown): boolean {\n  const e = error as { status?: unknown; body?: { error_code?: unknown } | null };\n  return e.status === 409 && e.body?.error_code === \"company_not_installed\";\n}\n\n/**\n * fluid-integrations answers a token that lacks the Integrations permission a\n * change needs with 403 permission_denied. The message names the permission,\n * so the user knows to grant it to the token's role instead of retrying.\n */\nexport function permissionDeniedMessage(error: unknown): string | null {\n  const e = error as {\n    status?: unknown;\n    body?: { error_code?: unknown; required_permission?: unknown } | null;\n  };\n  if (e.status !== 403 || e.body?.error_code !== \"permission_denied\") return null;\n  const permission =\n    typeof e.body.required_permission === \"string\" ? e.body.required_permission : \"Integrations update\";\n  return `Your Fluid token needs the ${permission} permission to do this. Grant it to the token's role in Fluid, or use a token that has it.`;\n}\n\nexport async function providerStatus(\n  integrations: ConnectClient,\n  provider: Provider & { id: ProviderId },\n): Promise<ProviderStatus> {\n  let wire: IntegrationWire;\n  try {\n    wire = await integrations.get<IntegrationWire>(\n      `/api/v1/integrations/${provider.slug}`,\n    );\n  } catch (error) {\n    if (isCompanyNotInstalled(error)) {\n      return {\n        provider: provider.id,\n        label: provider.label,\n        installed: false,\n        connected: false,\n        companyIntegrationId: null,\n        dropletUuid: null,\n        integrationId: null,\n      };\n    }\n    if ((error as { status?: number }).status === 404) {\n      throw new ConnectError(\n        `${provider.label} isn't available on fluid-integrations for this company.`,\n      );\n    }\n    throw error;\n  }\n  const ciId = wire.company_integration_id ?? null;\n  return {\n    provider: provider.id,\n    label: provider.label,\n    installed: ciId !== null,\n    connected: wire.is_connected === true,\n    companyIntegrationId: ciId,\n    dropletUuid: wire.droplet_uuid ?? null,\n    integrationId: wire.id ?? null,\n  };\n}\n\n/** The company integration id, or a ConnectError saying to install first. */\nexport async function companyIntegrationId(\n  integrations: ConnectClient,\n  provider: Provider & { id: ProviderId },\n): Promise<number> {\n  const status = await providerStatus(integrations, provider);\n  if (status.companyIntegrationId === null) {\n    throw new ConnectError(\n      `${provider.label} isn't installed for this company. Run \\`fluid connect install ${provider.id} --yes\\` first.`,\n    );\n  }\n  return status.companyIntegrationId;\n}\n\nexport interface CompanyIntegrationWire {\n  id: number;\n  name?: string;\n  initialized?: boolean;\n  environment?: string | null;\n  sync_settings?: Record<string, unknown>;\n  settings_schema?: Record<string, Record<string, SchemaSetting>>;\n  supported_mappings?: string[];\n  live_sync_state?: string | null;\n  live_sync_degraded_reason?: string | null;\n}\n\nexport interface SchemaSetting {\n  type?: string;\n  value?: unknown;\n  label?: string;\n  description?: string;\n  options?: Array<{ value: unknown; label?: string }>;\n  multiple?: boolean;\n  depends_on?: string | string[];\n}\n\nexport async function getCompanyIntegration(\n  integrations: ConnectClient,\n  ciId: number,\n): Promise<CompanyIntegrationWire> {\n  return integrations.get<CompanyIntegrationWire>(\n    `/api/v1/company_integrations/${ciId}`,\n  );\n}\n\n/** Save credentials. fluid-integrations tests the connection with them and\n *  answers 422 with the reason when it fails, so nothing broken is saved. */\nexport async function setCredentials(\n  integrations: ConnectClient,\n  ciId: number,\n  authSettings: Record<string, unknown>,\n): Promise<{ saved: true }> {\n  await integrations.put(`/api/v1/company_integrations/${ciId}`, {\n    company_integration: { auth_settings: authSettings },\n  });\n  return { saved: true };\n}\n\n/**\n * Save credentials, creating the connection when the droplet is installed\n * but its install hasn't created the connection yet (the same request\n * Fluid's admin makes). Without an installed droplet nothing is created, so\n * `install` still installs it. Either way fluid-integrations tests the\n * connection first and answers 422 with the reason when it fails, so\n * nothing broken is saved.\n */\nexport async function saveCredentials(\n  integrations: ConnectClient,\n  fluid: ConnectClient,\n  provider: Provider & { id: ProviderId },\n  authSettings: Record<string, unknown>,\n): Promise<{ saved: true; created: boolean; companyIntegrationId: number }> {\n  const status = await providerStatus(integrations, provider);\n  if (status.companyIntegrationId !== null) {\n    await setCredentials(integrations, status.companyIntegrationId, authSettings);\n    return { saved: true, created: false, companyIntegrationId: status.companyIntegrationId };\n  }\n  // The droplet `install` would have installed: the one fluid-integrations\n  // names, else the catalog's unambiguous name match.\n  const dropletUuid =\n    status.dropletUuid ?? (await findDropletUuid(fluid, provider).catch(() => null));\n  if (\n    status.integrationId === null ||\n    dropletUuid === null ||\n    !(await dropletInstalled(fluid, dropletUuid))\n  ) {\n    throw new ConnectError(\n      `${provider.label} isn't installed for this company. Run \\`fluid connect install ${provider.id} --yes\\` first.`,\n    );\n  }\n  const created = await integrations.post<{ id?: number; data?: { id?: number } }>(\n    \"/api/v1/company_integrations\",\n    {\n      company_integration: {\n        integration_id: status.integrationId,\n        name: provider.label,\n        droplet_uuid: dropletUuid,\n        auth_settings: authSettings,\n      },\n    },\n  );\n  const id =\n    created?.id ??\n    created?.data?.id ??\n    (await providerStatus(integrations, provider)).companyIntegrationId;\n  if (typeof id !== \"number\") {\n    throw new ConnectError(`${provider.label} accepted the credentials, but the connection's id didn't come back. Run \\`fluid connect show ${provider.id}\\`.`);\n  }\n  return { saved: true, created: true, companyIntegrationId: id };\n}\n\n/** Merge a sync-settings patch into the saved settings. */\nexport async function updateSyncSettings(\n  integrations: ConnectClient,\n  ciId: number,\n  patch: Record<string, unknown>,\n): Promise<CompanyIntegrationWire> {\n  await integrations.put(`/api/v1/company_integrations/${ciId}`, {\n    company_integration: { sync_settings: patch },\n  });\n  return getCompanyIntegration(integrations, ciId);\n}\n\n/** A mapping type as its route names it, e.g. `customer_type`. */\n/**\n * fluid-integrations names its mapping cards with a `_title` suffix\n * (`customer_type_title`); the routes, and so the commands, use the bare type\n * (`customer_type`). Accept either and use the bare one.\n */\nexport function mappingType(name: string): string {\n  return name.replace(/_title$/, \"\");\n}\n\nexport function mappingPath(ciId: number, name: string): string {\n  const type = mappingType(name);\n  if (!/^[a-z_]+$/.test(type)) {\n    throw new ConnectError(\n      `\"${type}\" isn't a mapping type. Use names like customer_type or warehouse (see \\`fluid connect show\\`).`,\n    );\n  }\n  return `/api/v1/company_integrations/${ciId}/${type}_mappings`;\n}\n\nexport async function listMappings(\n  integrations: ConnectClient,\n  ciId: number,\n  type: string,\n): Promise<unknown> {\n  return integrations.get(mappingPath(ciId, type));\n}\n\n/** Values to choose from: Fluid's for the source side, and for Exigo also\n *  Exigo's own for the target side. */\nexport async function mappingOptions(\n  integrations: ConnectClient,\n  ciId: number,\n  type: string,\n  provider: Provider,\n): Promise<{ fluid: unknown; provider?: unknown }> {\n  // Some types (ship methods) list only Exigo's values, so a missing\n  // source_options leaves `fluid` null rather than failing the command.\n  let fluid: unknown = null;\n  try {\n    fluid = await integrations.get(`${mappingPath(ciId, type)}/source_options`);\n  } catch (error) {\n    if ((error as { status?: number }).status !== 404) throw error;\n    if (!provider.targetOptions) throw error;\n  }\n  if (!provider.targetOptions) return { fluid };\n  return {\n    fluid,\n    provider: await integrations.get(\n      `${mappingPath(ciId, type)}/exigo_options`,\n    ),\n  };\n}\n\n/** Create one mapping row. `fields` are the row's attributes, wrapped in\n *  the singular resource key the API expects (`customer_type_mapping`). */\nexport async function createMapping(\n  integrations: ConnectClient,\n  ciId: number,\n  type: string,\n  fields: Record<string, unknown>,\n): Promise<unknown> {\n  return integrations.post(mappingPath(ciId, type), {\n    [`${mappingType(type)}_mapping`]: fields,\n  });\n}\n\nexport async function deleteMapping(\n  integrations: ConnectClient,\n  ciId: number,\n  type: string,\n  id: number,\n): Promise<{ deleted: true; id: number }> {\n  await integrations.delete(`${mappingPath(ciId, type)}/${id}`);\n  return { deleted: true, id };\n}\n\ninterface InstallationListWire {\n  droplet_installations?: Array<{ droplet_uuid?: string; active?: boolean }>;\n  meta?: { pagination?: { total_pages?: number } };\n}\n\n/** Whether the company has the droplet installed and active in Fluid (one\n *  pending uninstall is listed, but inactive). */\nexport async function dropletInstalled(\n  fluid: ConnectClient,\n  dropletUuid: string,\n): Promise<boolean> {\n  for (let page = 1; page <= CATALOG_PAGES; page += 1) {\n    const data = await fluid.get<InstallationListWire>(\"/api/droplet_installations\", {\n      page,\n      per_page: 100,\n    });\n    const rows = data.droplet_installations ?? [];\n    if (rows.some((row) => row.droplet_uuid === dropletUuid && row.active !== false)) return true;\n    const totalPages = data.meta?.pagination?.total_pages ?? 1;\n    if (page >= totalPages || rows.length < 100) break;\n  }\n  return false;\n}\n\ninterface DropletListWire {\n  droplets?: Array<{ uuid?: string; name?: string }>;\n  meta?: { pagination?: { total_pages?: number } };\n}\n\nconst CATALOG_PAGES = 10;\n\n/** Install the provider's droplet in Fluid, which creates its company\n *  integration on fluid-integrations. */\nexport async function installProvider(\n  fluid: ConnectClient,\n  provider: Provider,\n  /** The official droplet from fluid-integrations, when it names one. */\n  officialUuid: string | null = null,\n): Promise<{ installed: true; dropletUuid: string }> {\n  const dropletUuid = officialUuid ?? (await findDropletUuid(fluid, provider));\n  await fluid.post(\"/api/droplet_installations\", {\n    droplet_uuid: dropletUuid,\n    scopes: CONNECT_DROPLET_SCOPES,\n  });\n  return { installed: true, dropletUuid };\n}\n\nasync function findDropletUuid(\n  fluid: ConnectClient,\n  provider: Provider,\n): Promise<string> {\n  const wanted = provider.dropletName.toLowerCase();\n  const matches = new Set<string>();\n  for (let page = 1; page <= CATALOG_PAGES; page += 1) {\n    const data = await fluid.get<DropletListWire>(\"/api/droplets\", {\n      page,\n      per_page: 100,\n    });\n    for (const droplet of data.droplets ?? []) {\n      if (droplet.uuid && droplet.name?.trim().toLowerCase() === wanted) matches.add(droplet.uuid);\n    }\n    const totalPages = data.meta?.pagination?.total_pages ?? 1;\n    if (page >= totalPages || (data.droplets ?? []).length < 100) break;\n  }\n  // A company's own droplet can share the name, so a name alone must be\n  // unambiguous before it's installed with Connect's scopes.\n  if (matches.size === 1) return [...matches][0]!;\n  if (matches.size > 1) {\n    throw new ConnectError(\n      `More than one droplet is named ${provider.dropletName}, and fluid-integrations didn't say which is ${provider.label}'s. Ask Fluid to check the ${provider.label} integration's droplet.`,\n    );\n  }\n  throw new ConnectError(\n    `The ${provider.label} droplet isn't in this company's droplet catalog. Ask Fluid to make it available.`,\n  );\n}\n","import { ConnectError } from \"./providers.js\";\n\n/**\n * Parse `--set` values into the nested object the API takes.\n *\n * `api.username=alice` → `{ api: { username: \"alice\" } }`. Values that read\n * as JSON (true, 42, [\"a\",\"b\"], {\"x\":1}) are parsed; anything else stays a\n * string, so a password like `abc123` is never mangled.\n */\nexport function parseAssignments(\n  assignments: readonly string[],\n  /** Keep every value a string, as credentials need: a password like\n   *  `123456` or `true` must reach the API exactly as typed. */\n  opts: { strings?: boolean } = {},\n): Record<string, unknown> {\n  const out: Record<string, unknown> = {};\n  for (const assignment of assignments) {\n    const at = assignment.indexOf(\"=\");\n    if (at <= 0) {\n      throw new ConnectError(\n        `\"${assignment}\" isn't key=value. Use dots for nesting, e.g. api.username=alice.`,\n      );\n    }\n    const path = assignment.slice(0, at).split(\".\");\n    if (path.some((part) => part.length === 0)) {\n      throw new ConnectError(`\"${assignment}\" has an empty key segment.`);\n    }\n    if (path.some((part) => UNSAFE_KEYS.has(part))) {\n      throw new ConnectError(`\"${assignment}\" uses a reserved key name.`);\n    }\n    const raw = assignment.slice(at + 1);\n    setPath(out, path, opts.strings ? raw : parseValue(raw));\n  }\n  return out;\n}\n\n// Keys that would reach Object.prototype through a plain object.\nconst UNSAFE_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction parseValue(raw: string): unknown {\n  if (/^(true|false|null|-?\\d+(\\.\\d+)?)$/.test(raw) || /^[[{]/.test(raw)) {\n    try {\n      return JSON.parse(raw);\n    } catch {\n      return raw;\n    }\n  }\n  return raw;\n}\n\nfunction setPath(\n  target: Record<string, unknown>,\n  path: string[],\n  value: unknown,\n): void {\n  let node = target;\n  for (const key of path.slice(0, -1)) {\n    const next = node[key];\n    if (typeof next !== \"object\" || next === null || Array.isArray(next)) {\n      node[key] = {};\n    }\n    node = node[key] as Record<string, unknown>;\n  }\n  node[path[path.length - 1]!] = value;\n}\n\n/**\n * Sync settings are saved per entity as the schema entry itself, with the\n * chosen value under `value`: `entities.<entity>.settings.<key>.value`.\n * `--set` takes the short `<entity>.<key>=value` form `fluid connect\n * settings` prints, and this expands it. Exigo's `sponsor_tree` is the one\n * top-level setting (`sync_settings.sponsor_tree.value`); write it as\n * `sponsor_tree.sponsor_tree=value`.\n */\nexport function syncSettingsPatch(\n  assignments: readonly string[],\n): Record<string, unknown> {\n  const entries: Array<[string, unknown]> = [];\n  for (const assignment of assignments) {\n    const parsed = parseAssignments([assignment]);\n    const [group, values] = Object.entries(parsed)[0]!;\n    if (typeof values !== \"object\" || values === null || Array.isArray(values)) {\n      throw new ConnectError(\n        `\"${assignment}\" needs an entity and a setting, e.g. order.refund_handling=hold.`,\n      );\n    }\n    for (const [key, value] of Object.entries(values)) {\n      entries.push([`${group}.${key}`, value]);\n    }\n  }\n  return patchFromEntries(entries);\n}\n\n/**\n * A patch that puts settings back to their schema defaults: all of them,\n * or only the `<entity>.<key>` names in `only`. Unknown names are refused\n * rather than silently skipped.\n */\nexport function defaultsPatch(\n  schema: Record<string, Record<string, { value?: unknown }>>,\n  only: readonly string[] = [],\n): Record<string, unknown> {\n  const all = Object.entries(schema).flatMap(([entity, settings]) =>\n    Object.entries(settings).map(\n      ([key, setting]) => [`${entity}.${key}`, setting.value] as [string, unknown],\n    ),\n  );\n  // A setting whose schema has no default is left as it is: there's\n  // nothing to restore, and sending null would wipe a saved value.\n  const withDefault = all.filter(([, value]) => value !== undefined);\n  if (only.length === 0) return patchFromEntries(withDefault);\n  const known = new Map(all);\n  const unknown = only.filter((key) => !known.has(key));\n  if (unknown.length > 0) {\n    throw new ConnectError(\n      `Unknown setting(s): ${unknown.join(\", \")}. List them with \\`fluid connect settings <provider>\\`.`,\n    );\n  }\n  const noDefault = only.filter((key) => known.get(key) === undefined);\n  if (noDefault.length > 0) {\n    throw new ConnectError(`No default to restore for: ${noDefault.join(\", \")}.`);\n  }\n  return patchFromEntries(only.map((key) => [key, known.get(key)]));\n}\n\n/** Settings worth deciding before the first sync, in the order the setup\n *  guides list them. A provider without one of them skips it. */\nexport const COMMON_SETTINGS = [\n  \"customer.duplicate_customer_handling\",\n  \"customer.unverified_customer_handling\",\n  \"customer.customer_creation_sync\",\n  \"customer.customer_changelog_sync\",\n  \"order.refund_handling\",\n  \"order.duplicate_order_handling\",\n  \"order.order_creation_sync\",\n  \"order.order_changelog_sync\",\n  \"product.new_inactive\",\n  \"product.warehouseless_product_handling\",\n  \"rank.sync_ranks\",\n  \"rank.pulled_from\",\n  \"sponsor_tree.sponsor_tree\",\n  \"customer.fetch_mode\",\n  \"order_payment.skip_payment_on_export\",\n] as const;\n\n/** A patch setting `<entity>.<key>` names to values exactly as given (no\n *  parsing), in the shape `--set` and `--defaults` send. */\nexport function settingsPatch(\n  values: Record<string, unknown>,\n): Record<string, unknown> {\n  return patchFromEntries(Object.entries(values));\n}\n\nfunction patchFromEntries(\n  entries: ReadonlyArray<[string, unknown]>,\n): Record<string, unknown> {\n  const entities: Record<string, { settings: Record<string, unknown> }> = {};\n  const patch: Record<string, unknown> = {};\n  for (const [name, value] of entries) {\n    const at = name.indexOf(\".\");\n    const group = name.slice(0, at);\n    const key = name.slice(at + 1);\n    if (group === \"sponsor_tree\" && key === \"sponsor_tree\") {\n      patch[\"sponsor_tree\"] = { value };\n      continue;\n    }\n    entities[group] ??= { settings: {} };\n    entities[group].settings[key] = { value };\n  }\n  if (Object.keys(entities).length > 0) patch[\"entities\"] = entities;\n  return patch;\n}\n","import type { ConnectClient, ProviderStatus } from \"./api.js\";\nimport { ConnectError, type Provider, type ProviderId } from \"./providers.js\";\n\n/**\n * `fluid connect status`: a Connect integration's sync status, read from\n * Fluid's own endpoints (`/api/company/v2026-10/connect/integrations`) with\n * the CLI's Fluid token. It never calls fluid-integrations: Fluid's endpoint\n * strips the error text and record ids fluid-integrations would return.\n */\nexport const CONNECT_INTEGRATIONS_PATH =\n  \"/api/company/v2026-10/connect/integrations\";\n\nexport interface ConnectIntegrationRow {\n  uuid: string;\n  name: string;\n  platform: string;\n  installation_status: string;\n  reachable: boolean;\n}\n\ninterface IntegrationListWire {\n  connect_integrations?: ConnectIntegrationRow[];\n}\n\ninterface StatusWire {\n  connect_status?: Record<string, unknown>;\n}\n\n/** A Fluid error answer, carried through to the plugin's `fail()` with the\n *  status and Fluid's error code (`not_connected`, `connect_unconfigured`…). */\nexport class ConnectStatusError extends ConnectError {\n  readonly status: number | undefined;\n  readonly body: { error: string; code?: string };\n\n  constructor(\n    message: string,\n    status: number | undefined,\n    code: string | undefined,\n  ) {\n    super(message);\n    this.name = \"ConnectStatusError\";\n    this.status = status;\n    this.body = { error: message, ...(code ? { code } : {}) };\n  }\n}\n\n/** Fluid's error envelope (`{ error: { message, details: { code } } }`) as\n *  a ConnectStatusError; anything else is rethrown as it is. */\nfunction fluidError(error: unknown): unknown {\n  const e = error as {\n    status?: unknown;\n    body?: {\n      error?: { message?: unknown; details?: { code?: unknown } };\n    } | null;\n  };\n  const envelope = e.body?.error;\n  if (typeof e.status !== \"number\" || !envelope || typeof envelope !== \"object\")\n    return error;\n  const message =\n    typeof envelope.message === \"string\"\n      ? envelope.message\n      : `HTTP ${e.status}`;\n  const code =\n    typeof envelope.details?.code === \"string\"\n      ? envelope.details.code\n      : undefined;\n  return new ConnectStatusError(message, e.status, code);\n}\n\n/** The result `fluid connect list` prints for a provider with nothing\n *  installed. */\nexport function notInstalled(\n  provider: Provider & { id: ProviderId },\n): ProviderStatus {\n  return {\n    provider: provider.id,\n    label: provider.label,\n    installed: false,\n    connected: false,\n    companyIntegrationId: null,\n    dropletUuid: null,\n    integrationId: null,\n  };\n}\n\n/** The company's Connect integration for the provider, matched by the\n *  platform Fluid reports, or null when it isn't installed. */\nexport async function findIntegration(\n  fluid: ConnectClient,\n  provider: Provider & { id: ProviderId },\n): Promise<ConnectIntegrationRow | null> {\n  let list: IntegrationListWire;\n  try {\n    list = await fluid.get<IntegrationListWire>(CONNECT_INTEGRATIONS_PATH);\n  } catch (error) {\n    throw fluidError(error);\n  }\n  return (\n    (list.connect_integrations ?? []).find(\n      (row) => row.platform === provider.id,\n    ) ?? null\n  );\n}\n\n/**\n * The provider's status, or the not-installed result `list` prints. Fluid's\n * 404, 409, 502 and 503 answers are thrown as ConnectStatusError, so the\n * command exits non-zero with a JSON `error`.\n */\nexport async function connectStatus(\n  fluid: ConnectClient,\n  provider: Provider & { id: ProviderId },\n  range?: string,\n): Promise<Record<string, unknown> | ProviderStatus> {\n  const integration = await findIntegration(fluid, provider);\n  if (integration === null) return notInstalled(provider);\n  let answer: StatusWire;\n  try {\n    answer = await fluid.get<StatusWire>(\n      `${CONNECT_INTEGRATIONS_PATH}/${encodeURIComponent(integration.uuid)}/status`,\n      range ? { range } : undefined,\n    );\n  } catch (error) {\n    throw fluidError(error);\n  }\n  if (!answer.connect_status) {\n    throw new ConnectError(\n      `Fluid didn't return a status for ${provider.label}.`,\n    );\n  }\n  return answer.connect_status;\n}\n","import type { CompanyIntegrationWire, SchemaSetting } from \"./api.js\";\n\nexport interface SettingSummary {\n  /** Pass to `fluid connect settings --set <key>=<value>`. */\n  key: string;\n  label: string | null;\n  description: string | null;\n  type: string | null;\n  value: unknown;\n  default: unknown;\n  options?: unknown[];\n  multiple?: boolean;\n  dependsOn?: string | string[];\n}\n\n/**\n * Every sync setting the provider supports, with the value saved for this\n * company next to the default. Saved values live at\n * `entities.<entity>.settings.<key>.value` (Exigo's `sponsor_tree` at\n * `sponsor_tree.value`); a setting never saved reads as its default.\n */\nexport function summarizeSettings(\n  ci: CompanyIntegrationWire,\n): SettingSummary[] {\n  const schema = ci.settings_schema ?? {};\n  const saved = ci.sync_settings ?? {};\n  const out: SettingSummary[] = [];\n  for (const [entity, settings] of Object.entries(schema)) {\n    for (const [name, setting] of Object.entries(settings)) {\n      out.push(summarize(entity, name, setting, savedValue(saved, entity, name)));\n    }\n  }\n  return out;\n}\n\nfunction summarize(\n  entity: string,\n  name: string,\n  setting: SchemaSetting,\n  saved: { found: boolean; value: unknown },\n): SettingSummary {\n  return {\n    key: `${entity}.${name}`,\n    label: setting.label ?? null,\n    description: setting.description ?? null,\n    type: setting.type ?? null,\n    value: saved.found ? saved.value : (setting.value ?? null),\n    default: setting.value ?? null,\n    ...(setting.options ? { options: setting.options.map((o) => o.value) } : {}),\n    ...(setting.multiple !== undefined ? { multiple: setting.multiple } : {}),\n    ...(setting.depends_on ? { dependsOn: setting.depends_on } : {}),\n  };\n}\n\nfunction savedValue(\n  saved: Record<string, unknown>,\n  entity: string,\n  name: string,\n): { found: boolean; value: unknown } {\n  const entry =\n    entity === \"sponsor_tree\" && name === \"sponsor_tree\"\n      ? saved[\"sponsor_tree\"]\n      : dig(saved, [\"entities\", entity, \"settings\", name]);\n  if (entry && typeof entry === \"object\" && \"value\" in entry) {\n    return { found: true, value: (entry as { value: unknown }).value };\n  }\n  return { found: false, value: undefined };\n}\n\nfunction dig(node: unknown, path: string[]): unknown {\n  let current = node;\n  for (const key of path) {\n    if (!current || typeof current !== \"object\") return undefined;\n    current = (current as Record<string, unknown>)[key];\n  }\n  return current;\n}\n","import {\n  mappingType,\n  createMapping,\n  getCompanyIntegration,\n  mappingPath,\n  type ConnectClient,\n} from \"./api.js\";\nimport type { Provider } from \"./providers.js\";\n\n/** The field each mapping type keeps the Fluid (source) value in. A row\n *  whose source is `*` is the fallback for every value without its own row. */\nexport const SOURCE_FIELD: Record<string, string> = {\n  customer_type: \"source_type_slug\",\n  customer_status: \"source_status_slug\",\n  order_status: \"source_status_slug\",\n  order_type: \"source_type_slug\",\n  payable_type: \"source_type_slug\",\n  price_type: \"source_price_type_title\",\n  warehouse: \"source_warehouse_title\",\n  customer_warehouse: \"source_country_code\",\n  payment_type: \"source_payment_method\",\n  wallet_type: \"source_payment_method\",\n  fraud_decision: \"source_decision\",\n  ship_method: \"source_shipping_method_title\",\n  product_type: \"source_title\",\n  country_market: \"source_title\",\n  tree: \"source_title\",\n  rank: \"source_title\",\n};\n\n/** The field each mapping type keeps the provider's (target) value in. */\nexport const TARGET_FIELD: Record<string, string> = {\n  customer_type: \"target_type_id\",\n  customer_status: \"target_status_id\",\n  order_status: \"target_status_id\",\n  order_type: \"target_type_id\",\n  payable_type: \"target_payable_id\",\n  price_type: \"target_price_type_id\",\n  warehouse: \"external_warehouse_id\",\n  customer_warehouse: \"target_warehouse_id\",\n  payment_type: \"target_payment_type\",\n  wallet_type: \"target_wallet_type_id\",\n  fraud_decision: \"target_field_value\",\n  ship_method: \"exigo_ship_method_id\",\n  product_type: \"target_title\",\n  country_market: \"target_title\",\n  tree: \"target_title\",\n  rank: \"target_title\",\n};\n\n/** Types whose Fluid values the API lists (`source_options`), with a\n *  `mapped` flag on each. Ranks and ship methods have no such list. */\nconst LISTS_FLUID_VALUES = new Set([\n  \"customer_type\",\n  \"customer_status\",\n  \"order_status\",\n  \"order_type\",\n  \"payable_type\",\n  \"price_type\",\n  \"warehouse\",\n  \"customer_warehouse\",\n  \"payment_type\",\n  \"wallet_type\",\n  \"fraud_decision\",\n  \"currency_point_account\",\n  \"product_type\",\n  \"country_market\",\n  \"tree\",\n]);\n\ninterface FluidOption {\n  id?: string | number;\n  title?: string;\n  slug?: string;\n  mapped?: boolean;\n}\n\ninterface ProviderOption {\n  id?: string | number;\n  title?: string;\n}\n\n/** How to build a row from a Fluid option and the Exigo option with the\n *  same title. Only types whose target is an Exigo id are listed: a title\n *  match then names exactly one Exigo record. */\nconst AUTO_MAP: Record<\n  string,\n  (fluid: FluidOption, provider: ProviderOption) => Record<string, unknown> | null\n> = {\n  customer_type: (f, p) => f.slug ? { source_type_slug: f.slug, target_type_id: String(p.id) } : null,\n  customer_status: (f, p) => f.slug ? { source_status_slug: f.slug, target_status_id: String(p.id) } : null,\n  order_status: (f, p) => f.slug ? { source_status_slug: f.slug, target_status_id: String(p.id) } : null,\n  order_type: (f, p) => f.slug ? { source_type_slug: f.slug, target_type_id: String(p.id) } : null,\n  payable_type: (f, p) => f.slug ? { source_type_slug: f.slug, target_payable_id: String(p.id) } : null,\n  price_type: (f, p) => f.title ? { source_price_type_title: f.title, target_price_type_id: String(p.id) } : null,\n  warehouse: (f, p) =>\n    f.title && f.id !== undefined\n      ? { fluid_warehouse_id: f.id, source_warehouse_title: f.title, external_warehouse_id: String(p.id) }\n      : null,\n};\n\nexport interface UnmappedValue {\n  /** What to put in the source field when you add the row. */\n  value: string;\n  title: string | null;\n  /** The Fluid record's id, which a warehouse row also needs. */\n  id?: string | number;\n}\n\nexport interface MappingTypeReport {\n  type: string;\n  /** covered: every Fluid value has a row or a `*` fallback covers them.\n   *  needs_mapping: `unmapped` lists the values a person must map.\n   *  check_by_hand: the API doesn't list Fluid's values for this type.\n   *  error: the values couldn't be read; see `error`. */\n  status: \"covered\" | \"needs_mapping\" | \"check_by_hand\" | \"error\";\n  sourceField: string | null;\n  fallback?: boolean;\n  unmapped?: UnmappedValue[];\n  autoMapped?: Array<Record<string, unknown>>;\n  error?: string;\n}\n\nconst norm = (text: string | undefined): string =>\n  (text ?? \"\").trim().toLowerCase();\n\n/** The value a row's source field takes for a Fluid option: the title for\n *  fields keyed by title (`source_price_type_title`), else the slug. */\nexport function sourceValue(option: FluidOption, sourceField?: string | null): string {\n  const value = sourceField?.endsWith(\"_title\")\n    ? (option.title ?? option.slug ?? option.id)\n    : (option.slug ?? option.title ?? option.id);\n  return String(value ?? \"\");\n}\n\n/** Pair unmapped Fluid options with provider options whose title matches\n *  exactly (ignoring case and edge spaces). A title that more than one\n *  provider option shares is ambiguous and left for a person. */\nexport function exactTitleMatches(\n  unmapped: FluidOption[],\n  providerOptions: ProviderOption[],\n): Array<{ fluid: FluidOption; provider: ProviderOption }> {\n  const byTitle = new Map<string, ProviderOption[]>();\n  for (const option of providerOptions) {\n    const key = norm(option.title);\n    if (!key || option.id === undefined || option.id === null) continue;\n    byTitle.set(key, [...(byTitle.get(key) ?? []), option]);\n  }\n  const pairs: Array<{ fluid: FluidOption; provider: ProviderOption }> = [];\n  for (const fluid of unmapped) {\n    const candidates = byTitle.get(norm(fluid.title)) ?? [];\n    if (candidates.length === 1) pairs.push({ fluid, provider: candidates[0]! });\n  }\n  return pairs;\n}\n\nfunction optionsOf(response: unknown): unknown[] {\n  const options = (response as { options?: unknown })?.options;\n  return Array.isArray(options) ? options : [];\n}\n\nfunction rowsOf(response: unknown, type: string): Array<Record<string, unknown>> {\n  const rows = (response as Record<string, unknown> | null)?.[`${type}_mappings`];\n  return Array.isArray(rows) ? (rows as Array<Record<string, unknown>>) : [];\n}\n\nfunction errorText(error: unknown): string {\n  const body = (error as { body?: Record<string, unknown> | null }).body;\n  const detail = body?.[\"error\"] ?? body?.[\"errors\"];\n  if (typeof detail === \"string\") return detail;\n  return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * For every mapping type the provider supports, the Fluid values that still\n * need a row. With `autoMap`, rows are first created for values whose title\n * matches exactly one provider value (Exigo only, and only types whose target\n * is an id), so what's returned is what a person still has to decide.\n */\nexport async function unmappedReport(\n  integrations: ConnectClient,\n  ciId: number,\n  provider: Provider,\n  autoMap: boolean,\n): Promise<MappingTypeReport[]> {\n  const ci = await getCompanyIntegration(integrations, ciId);\n  const types = (ci.supported_mappings ?? [])\n    .map(mappingType)\n    .filter((type) => type in SOURCE_FIELD || LISTS_FLUID_VALUES.has(type));\n\n  const reports: MappingTypeReport[] = [];\n  for (const type of types) {\n    reports.push(await reportFor(integrations, ciId, provider, type, autoMap));\n  }\n  return reports;\n}\n\nasync function reportFor(\n  integrations: ConnectClient,\n  ciId: number,\n  provider: Provider,\n  type: string,\n  autoMap: boolean,\n): Promise<MappingTypeReport> {\n  const sourceField = SOURCE_FIELD[type] ?? null;\n  if (!LISTS_FLUID_VALUES.has(type)) {\n    return { type, status: \"check_by_hand\", sourceField };\n  }\n  // Kept outside the try so a later failure still reports what was saved.\n  const autoMapped: Array<Record<string, unknown>> = [];\n  try {\n    const path = mappingPath(ciId, type);\n    const [optionsResponse, rowsResponse] = await Promise.all([\n      integrations.get(`${path}/source_options`),\n      integrations.get(path),\n    ]);\n    const fallback =\n      sourceField !== null &&\n      rowsOf(rowsResponse, type).some((row) => row[sourceField] === \"*\");\n    if (fallback) return { type, status: \"covered\", sourceField, fallback: true };\n\n    let unmapped = (optionsOf(optionsResponse) as FluidOption[]).filter(\n      (option) => option.mapped === false,\n    );\n    const build = AUTO_MAP[type];\n    if (autoMap && provider.targetOptions && build && unmapped.length > 0) {\n      const providerOptions = optionsOf(\n        await integrations.get(`${path}/exigo_options`),\n      ) as ProviderOption[];\n      for (const { fluid, provider: match } of exactTitleMatches(unmapped, providerOptions)) {\n        const fields = build(fluid, match);\n        if (!fields) continue;\n        await createMapping(integrations, ciId, type, fields);\n        autoMapped.push(fields);\n        unmapped = unmapped.filter((option) => option !== fluid);\n      }\n    }\n    return {\n      type,\n      status: unmapped.length === 0 ? \"covered\" : \"needs_mapping\",\n      sourceField,\n      unmapped: unmapped.map((option) => ({\n        value: sourceValue(option, sourceField),\n        title: option.title ?? null,\n        ...(option.id !== undefined && option.id !== null ? { id: option.id } : {}),\n      })),\n      ...(autoMapped.length > 0 ? { autoMapped } : {}),\n    };\n  } catch (error) {\n    return {\n      type,\n      status: \"error\",\n      sourceField,\n      error: errorText(error),\n      ...(autoMapped.length > 0 ? { autoMapped } : {}),\n    };\n  }\n}\n","// `fluid connect walk <provider>`: the setup guide as a conversation. It\n// installs the provider if needed, asks for the credentials, maps each\n// unmapped value, and goes through the common sync settings. Every answer\n// is saved as it's given, through the same functions the non-interactive\n// commands use, and a person can go back, skip, or open a menu to jump to a\n// part or change an answer.\n\nimport {\n  NAV_HELP,\n  type Choice,\n  type Nav,\n  type Prompter,\n  type Question,\n} from \"@fluid-app/fluid-cli\";\n\nimport {\n  createMapping,\n  deleteMapping,\n  getCompanyIntegration,\n  installProvider,\n  mappingPath,\n  providerStatus,\n  saveCredentials,\n  updateSyncSettings,\n  type CompanyIntegrationWire,\n  type ConnectClient,\n  type SchemaSetting,\n} from \"./api.js\";\nimport {\n  ConnectError,\n  type CredentialField,\n  type Provider,\n  type ProviderId,\n} from \"./providers.js\";\nimport { COMMON_SETTINGS, defaultsPatch, settingsPatch } from \"./settings.js\";\nimport { summarizeSettings } from \"./summary.js\";\nimport {\n  SOURCE_FIELD,\n  TARGET_FIELD,\n  unmappedReport,\n  type MappingTypeReport,\n  type UnmappedValue,\n} from \"./unmapped.js\";\n\nexport interface WalkDeps {\n  /** The Fluid API, for installing the droplet. */\n  fluid: ConnectClient;\n  /** fluid-integrations, where the connection lives. */\n  integrations: ConnectClient;\n  provider: Provider & { id: ProviderId };\n  prompter: Prompter;\n  /** Waits between checks for a just-installed connection. */\n  sleep?: (ms: number) => Promise<void>;\n}\n\nexport interface WalkResult {\n  provider: ProviderId;\n  installed: boolean;\n  connected: boolean;\n  /** True when the walk saved credentials that passed the connection test. */\n  credentialsSaved: boolean;\n  /** Rows added by matching names (Exigo). */\n  autoMapped: number;\n  /** Rows added from answers, including `*` fallbacks. */\n  rowsAdded: number;\n  /** Every mapping type is covered. Null when it couldn't be checked. */\n  mappingsDone: boolean | null;\n  /** Types that still have values without a row, with how many. */\n  stillUnmapped: Array<{ type: string; count: number | null; status: string }>;\n  settingsChanged: string[];\n  settingsRestored: boolean;\n  /** The questions passed over with `>`. */\n  skipped: string[];\n  /** Stopped before the end (Ctrl-C or Stop in the menu). */\n  stopped: boolean;\n}\n\n// ---------------------------------------------------------------- steps\n\ntype Phase = \"credentials\" | \"mappings\" | \"settings\";\n\nconst PHASE_NAMES: Record<Phase, string> = {\n  credentials: \"Credentials\",\n  mappings: \"Mappings\",\n  settings: \"Settings\",\n};\n\n/** What a step did: answered, asked to move, or wants to go elsewhere. */\ntype Outcome =\n  | { done: true; answer?: string }\n  | { nav: Nav }\n  | { retry: true }\n  | { goto: string }\n  | { stop: true };\n\ninterface Step {\n  id: string;\n  phase: Phase;\n  /** Steps generated together (one report, one settings pass) share a group\n   *  so they can be replaced as a whole. */\n  group?: string;\n  /** How the menu names it. */\n  title: string;\n  /** False for steps that only act (save, load), which back passes over. */\n  asks: boolean;\n  when?: () => boolean;\n  run(canGoBack: boolean): Promise<Outcome>;\n}\n\nconst DONE: Outcome = { done: true };\nconst FALLBACK = \"*\";\n\n/** The reason a request failed: the provider's, on a failed connection test. */\nexport function reasonOf(error: unknown): string {\n  const body = (error as { body?: Record<string, unknown> | null }).body;\n  const detail = body?.[\"errors\"] ?? body?.[\"error\"] ?? body?.[\"error_message\"];\n  if (typeof detail === \"string\") return detail;\n  if (Array.isArray(detail)) return detail.map(String).join(\"; \");\n  if (detail && typeof detail === \"object\") {\n    return Object.entries(detail)\n      .map(([key, value]) => `${key}: ${Array.isArray(value) ? value.join(\", \") : String(value)}`)\n      .join(\"; \");\n  }\n  return error instanceof Error ? error.message : String(error);\n}\n\nconst words = (type: string) => type.replace(/_/g, \" \");\n\nfunction display(value: unknown): string {\n  if (value === undefined || value === null || value === \"\") return \"(none)\";\n  if (typeof value === \"boolean\") return value ? \"Yes\" : \"No\";\n  return typeof value === \"string\" ? value : JSON.stringify(value);\n}\n\nfunction setPath(target: Record<string, unknown>, key: string, value: string): void {\n  const path = key.split(\".\");\n  let node = target;\n  for (const part of path.slice(0, -1)) {\n    if (typeof node[part] !== \"object\" || node[part] === null) node[part] = {};\n    node = node[part] as Record<string, unknown>;\n  }\n  node[path[path.length - 1]!] = value;\n}\n\nfunction rowIdOf(response: unknown, type: string): number | undefined {\n  const record = response as Record<string, unknown> | null;\n  const row = (record?.[`${type}_mapping`] ?? record) as { id?: unknown } | null;\n  return typeof row?.id === \"number\" ? row.id : undefined;\n}\n\n// ----------------------------------------------------------------- walk\n\nexport async function walkConnect(deps: WalkDeps): Promise<WalkResult> {\n  const { integrations, provider, prompter } = deps;\n  const sleep = deps.sleep ?? ((ms: number) => new Promise((r) => setTimeout(r, ms)));\n  const label = provider.label;\n\n  const result: WalkResult = {\n    provider: provider.id,\n    installed: false,\n    connected: false,\n    credentialsSaved: false,\n    autoMapped: 0,\n    rowsAdded: 0,\n    mappingsDone: null,\n    stillUnmapped: [],\n    settingsChanged: [],\n    settingsRestored: false,\n    skipped: [],\n    stopped: false,\n  };\n\n  prompter.note(NAV_HELP);\n\n  // ------------------------------------------------------------ install\n  let status = await providerStatus(integrations, provider);\n  if (!status.installed) {\n    const choice = await prompter.menu(\n      `${label} isn't installed for this company. Installing it adds the ${label} droplet in Fluid, which creates the connection (changes live config).`,\n      [\n        { title: `Install ${label}`, value: \"install\" },\n        { title: \"Stop\", value: \"stop\" },\n      ],\n    );\n    if (choice !== \"install\") {\n      result.stopped = true;\n      return result;\n    }\n    await installProvider(deps.fluid, provider, status.dropletUuid);\n    prompter.note(`Installed ${label}. Waiting for the connection…`);\n    for (let attempt = 0; attempt < 10 && !status.installed; attempt += 1) {\n      await sleep(2000);\n      status = await providerStatus(integrations, provider);\n    }\n    if (!status.installed) {\n      prompter.note(`The connection isn't there yet, so saving the credentials will create it.`);\n    }\n  }\n  result.installed = true;\n  result.connected = status.connected;\n  /** Null until the connection exists; saving credentials creates it. */\n  let ciId: number | null = status.companyIntegrationId;\n  let ci: CompanyIntegrationWire =\n    ciId === null ? { id: 0 } : await getCompanyIntegration(integrations, ciId);\n  /** The connection, for the parts that need one (guarded at mappings-start). */\n  const connection = (): number => {\n    if (ciId === null) throw new ConnectError(`${label} has no connection yet. Save its credentials first.`);\n    return ciId;\n  };\n\n  // --------------------------------------------------------- the walk\n  const steps: Step[] = [];\n  const history: string[] = [];\n  const skipped = new Map<string, string>();\n  const answers = new Map<string, string>();\n  let index = 0;\n  /** The step reached by back or the menu: asked even if answered. */\n  let targeted: string | undefined;\n\n  const indexOf = (id: string) => steps.findIndex((s) => s.id === id);\n\n  /** Put `fresh` in place of the group's steps, right after `afterId`. */\n  const replaceGroup = (group: string, afterId: string, fresh: Step[]) => {\n    for (let i = steps.length - 1; i >= 0; i -= 1) {\n      if (steps[i]!.group === group) {\n        answers.delete(steps[i]!.id);\n        skipped.delete(steps[i]!.id);\n        steps.splice(i, 1);\n      }\n    }\n    steps.splice(indexOf(afterId) + 1, 0, ...fresh);\n  };\n\n  const ask = (question: Omit<Question, \"canGoBack\">, canGoBack: boolean) =>\n    prompter.ask({ ...question, canGoBack });\n\n  // ------------------------------------------------------ credentials\n  const draft = new Map<string, string>();\n  const credentialSteps: Step[] = [];\n  const firstCredential = () => credentialSteps.find((s) => s.asks && s.id !== \"credentials-keep\")!.id;\n\n  if (status.connected) {\n    credentialSteps.push({\n      id: \"credentials-keep\",\n      phase: \"credentials\",\n      title: \"Change the credentials?\",\n      asks: true,\n      run: async (canGoBack) => {\n        const reply = await ask(\n          {\n            section: PHASE_NAMES.credentials,\n            message: `${label} is connected. Change its credentials?`,\n            kind: \"select\",\n            choices: [\n              { title: \"Keep the saved credentials\", value: \"keep\" },\n              { title: \"Change them\", value: \"change\" },\n            ],\n          },\n          canGoBack,\n        );\n        if (\"nav\" in reply) return reply;\n        if (reply.value === \"keep\") {\n          answers.set(\"credentials-keep\", \"Keep\");\n          history.push(\"credentials-keep\");\n          return { goto: \"mappings-start\" };\n        }\n        return { done: true, answer: \"Change\" };\n      },\n    });\n  }\n\n  const required = (field: CredentialField) => !field.optional && !result.connected;\n\n  const credentialStep = (field: CredentialField, when?: () => boolean): Step => ({\n    id: `credential:${field.key}`,\n    phase: \"credentials\",\n    title: field.label,\n    asks: true,\n    ...(when ? { when } : {}),\n    run: async (canGoBack) => {\n      const typed = draft.get(field.key);\n      const reply = await ask(\n        {\n          section: `${PHASE_NAMES.credentials} · ${field.key}`,\n          message: field.label,\n          kind: field.secret ? \"secret\" : \"text\",\n          ...(typed !== undefined ? { current: field.secret ? \"••••••\" : typed } : {}),\n          ...(result.connected\n            ? { hint: \"Enter keeps the saved value\" }\n            : field.optional\n              ? { hint: \"optional; Enter leaves it blank\" }\n              : {}),\n        },\n        canGoBack,\n      );\n      if (\"nav\" in reply) return reply;\n      const value = reply.value.trim();\n      if (value === \"\") {\n        if (typed !== undefined || !required(field)) return { done: true, answer: typed !== undefined ? \"(entered)\" : \"(unchanged)\" };\n        prompter.note(`${label} needs this. Type it, or > to skip.`);\n        return { retry: true };\n      }\n      draft.set(field.key, value);\n      return { done: true, answer: field.secret ? \"(entered)\" : value };\n    },\n  });\n\n  if (provider.environments) {\n    credentialSteps.push({\n      id: \"credential:environment\",\n      phase: \"credentials\",\n      title: `${label} environment`,\n      asks: true,\n      run: async (canGoBack) => {\n        const reply = await ask(\n          {\n            section: `${PHASE_NAMES.credentials} · environment`,\n            message: `Which ${label} environment?`,\n            kind: \"select\",\n            choices: [\n              { title: \"Production (your live Exigo)\", value: \"production\" },\n              { title: \"Sandbox\", value: \"sandbox\" },\n            ],\n            ...(draft.get(\"environment\") ?? ci.environment\n              ? { current: draft.get(\"environment\") ?? ci.environment ?? undefined }\n              : {}),\n          },\n          canGoBack,\n        );\n        if (\"nav\" in reply) return reply;\n        const environment = reply.value.trim() || draft.get(\"environment\") || ci.environment;\n        if (!environment) {\n          prompter.note(\"Choose an environment, or > to skip.\");\n          return { retry: true };\n        }\n        draft.set(\"environment\", environment);\n        return { done: true, answer: environment };\n      },\n    });\n    credentialSteps.push(\n      credentialStep(\n        { key: \"sandbox_id\", label: \"Exigo sandbox ID (the number in sandboxapi<ID>.exigo.com)\" },\n        () => (draft.get(\"environment\") ?? ci.environment) !== \"production\",\n      ),\n    );\n  }\n  for (const field of provider.credentials) credentialSteps.push(credentialStep(field));\n\n  credentialSteps.push({\n    id: \"credentials-save\",\n    phase: \"credentials\",\n    title: \"Save the credentials\",\n    asks: false,\n    run: async () => {\n      if (draft.size === 0) return DONE;\n      const authSettings: Record<string, unknown> = {};\n      for (const [key, value] of draft) setPath(authSettings, key, value);\n      prompter.note(`Testing the connection to ${label}…`);\n      try {\n        ciId = (await saveCredentials(integrations, deps.fluid, provider, authSettings)).companyIntegrationId;\n      } catch (error) {\n        prompter.note(`${label} didn't accept the credentials, so nothing was saved: ${reasonOf(error)}`);\n        prompter.note(\"Check the values and answer again. Enter keeps what you typed.\");\n        for (const step of credentialSteps) answers.delete(step.id);\n        return { goto: firstCredential() };\n      }\n      draft.clear();\n      result.credentialsSaved = true;\n      result.connected = true;\n      prompter.note(\"Connected. The credentials are saved.\");\n      return DONE;\n    },\n  });\n  steps.push(...credentialSteps);\n\n  // --------------------------------------------------------- mappings\n  let autoMap = false;\n  const providerChoices = new Map<string, Choice[]>();\n  /** Types a `*` row now covers, so their other values aren't asked. */\n  const fallbackTypes = new Set<string>();\n  /** The row each mapping answer created, replaced when it's changed. */\n  const rowsByStep = new Map<string, { type: string; id?: number; fallback: boolean }>();\n\n  steps.push({\n    id: \"mappings-start\",\n    phase: \"mappings\",\n    title: \"Mappings\",\n    asks: false,\n    run: async () => {\n      if (ciId !== null) return DONE;\n      prompter.note(\n        `Mappings and settings need the connection, which saving ${label}'s credentials creates. Answer the credentials, or run \\`fluid connect credentials ${provider.id}\\`.`,\n      );\n      return { stop: true };\n    },\n  });\n\n  if (provider.targetOptions) {\n    steps.push({\n      id: \"mappings-automap\",\n      phase: \"mappings\",\n      title: \"Map exact name matches\",\n      asks: true,\n      run: async (canGoBack) => {\n        const reply = await ask(\n          {\n            section: PHASE_NAMES.mappings,\n            message: `Add a mapping wherever a Fluid value's name matches exactly one ${label} value? (changes live config)`,\n            kind: \"select\",\n            choices: [\n              { title: \"Yes, map exact name matches first\", value: \"yes\" },\n              { title: \"No, I'll map each one\", value: \"no\" },\n            ],\n            ...(answers.has(\"mappings-automap\") ? { current: autoMap ? \"yes\" : \"no\" } : {}),\n          },\n          canGoBack,\n        );\n        if (\"nav\" in reply) return reply;\n        autoMap = reply.value === \"yes\";\n        return { done: true, answer: autoMap ? \"Yes\" : \"No\" };\n      },\n    });\n  }\n\n  /** The provider's values for a type, as pick-list choices (Exigo). */\n  const choicesFor = async (type: string): Promise<Choice[]> => {\n    if (!provider.targetOptions) return [];\n    const cached = providerChoices.get(type);\n    if (cached) return cached;\n    let choices: Choice[] = [];\n    try {\n      const response = await integrations.get<{ options?: Array<{ id?: unknown; title?: string }> }>(\n        `${mappingPath(connection(), type)}/exigo_options`,\n      );\n      const byTitle = (TARGET_FIELD[type] ?? \"\").endsWith(\"_title\");\n      choices = (response?.options ?? [])\n        .filter((o) => o.id !== undefined && o.id !== null)\n        .map((o) => ({\n          title: o.title ? `${o.title} (${String(o.id)})` : String(o.id),\n          value: byTitle && o.title ? o.title : String(o.id),\n        }));\n    } catch {\n      choices = []; // fall back to typing the value\n    }\n    providerChoices.set(type, choices);\n    return choices;\n  };\n\n  /** Ask for the provider's value: a pick list for Exigo, typed otherwise. */\n  const askTarget = async (\n    type: string,\n    message: string,\n    section: string,\n    canGoBack: boolean,\n    offerFallback: boolean,\n    current?: string,\n  ) => {\n    const choices = await choicesFor(type);\n    const fallback: Choice[] = offerFallback\n      ? [{ title: `* Use one ${label} value for every remaining ${words(type)}`, value: FALLBACK }]\n      : [];\n    if (choices.length > 0) {\n      return ask(\n        {\n          section,\n          message,\n          kind: \"search\",\n          choices: [...choices, ...fallback],\n          hint: \"type to filter\",\n          ...(current ? { current } : {}),\n        },\n        canGoBack,\n      );\n    }\n    const targetIsName = (TARGET_FIELD[type] ?? \"\").endsWith(\"_title\");\n    return ask(\n      {\n        section,\n        message,\n        kind: \"text\",\n        hint: [\n          `${label}'s ${words(type)} ${targetIsName ? \"name\" : \"ID\"}, from your ${label} back office`,\n          offerFallback ? `or * to use one value for every remaining ${words(type)}` : \"\",\n        ]\n          .filter(Boolean)\n          .join(\"; \"),\n        ...(current ? { current } : {}),\n      },\n      canGoBack,\n    );\n  };\n\n  /** Save one row, replacing the row this step saved before. */\n  const saveRow = async (\n    stepId: string,\n    type: string,\n    fields: Record<string, unknown>,\n    fallback: boolean,\n  ): Promise<boolean> => {\n    let response: unknown;\n    try {\n      response = await createMapping(integrations, connection(), type, fields);\n    } catch (error) {\n      prompter.note(`Not saved: ${reasonOf(error)}`);\n      return false;\n    }\n    const previous = rowsByStep.get(stepId);\n    if (previous) {\n      if (previous.fallback) fallbackTypes.delete(previous.type);\n      if (previous.id !== undefined) {\n        try {\n          await deleteMapping(integrations, connection(), previous.type, previous.id);\n        } catch (error) {\n          prompter.note(\n            `The earlier row (${previous.id}) is still there: ${reasonOf(error)}. Remove it with \\`fluid connect unmap ${provider.id} ${previous.type} ${previous.id} --yes\\`.`,\n          );\n        }\n      }\n    } else {\n      result.rowsAdded += 1;\n    }\n    const id = rowIdOf(response, type);\n    rowsByStep.set(stepId, { type, ...(id !== undefined ? { id } : {}), fallback });\n    if (fallback) fallbackTypes.add(type);\n    return true;\n  };\n\n  const valueStep = (\n    report: MappingTypeReport,\n    value: UnmappedValue,\n    position: number,\n  ): Step => {\n    const type = report.type;\n    const id = `map:${type}:${value.value}`;\n    const name = value.title && value.title !== value.value ? `\"${value.title}\" (${value.value})` : `\"${value.value}\"`;\n    const section = `${PHASE_NAMES.mappings} · ${words(type)} · ${position} of ${report.unmapped!.length}`;\n    return {\n      id,\n      phase: \"mappings\",\n      group: \"mapping-values\",\n      title: `${words(type)}: ${value.title ?? value.value}`,\n      asks: true,\n      // A `*` row saved by an earlier answer covers the rest of the type.\n      when: () => !fallbackTypes.has(type) || rowsByStep.get(id)?.fallback === true,\n      run: async (canGoBack) => {\n        const reply = await askTarget(\n          type,\n          `${label} ${words(type)} for Fluid's ${name}`,\n          section,\n          canGoBack,\n          true,\n          answers.get(id),\n        );\n        if (\"nav\" in reply) return reply;\n        let target = reply.value.trim();\n        if (target === \"\") {\n          if (answers.has(id)) return { done: true, answer: answers.get(id)! };\n          prompter.note(\"Choose a value, or > to skip.\");\n          return { retry: true };\n        }\n        if (target === answers.get(id)) return { done: true, answer: target };\n        const fallback = target === FALLBACK;\n        if (fallback) {\n          const second = await askTarget(\n            type,\n            `${label} ${words(type)} for every Fluid ${words(type)} without its own row`,\n            section,\n            canGoBack,\n            false,\n          );\n          if (\"nav\" in second) return second.nav === \"back\" ? { retry: true } : second;\n          target = second.value.trim();\n          if (target === \"\") return { retry: true };\n        }\n        const sourceField = SOURCE_FIELD[type]!;\n        const fields: Record<string, unknown> = {\n          // value.value is already the title for title-keyed fields.\n          [sourceField]: fallback ? FALLBACK : value.value,\n          [TARGET_FIELD[type]!]: target,\n        };\n        if (type === \"warehouse\" && !fallback && value.id !== undefined) {\n          fields[\"fluid_warehouse_id\"] = value.id;\n          fields[\"source_warehouse_title\"] = value.title ?? value.value;\n        }\n        if (!(await saveRow(id, type, fields, fallback))) return { retry: true };\n        const answer = fallback ? `* → ${target}` : target;\n        prompter.note(\n          fallback\n            ? `Saved a * row: every other ${words(type)} maps to ${target}.`\n            : `Saved: ${value.title ?? value.value} → ${target}.`,\n        );\n        return { done: true, answer };\n      },\n    };\n  };\n\n  /** Ranks and ship methods: the API can't list Fluid's values. */\n  const byHandStep = (report: MappingTypeReport): Step => {\n    const type = report.type;\n    const id = `by-hand:${type}`;\n    return {\n      id,\n      phase: \"mappings\",\n      group: \"mapping-values\",\n      title: `${words(type)} (by hand)`,\n      asks: true,\n      run: async (canGoBack) => {\n        const section = `${PHASE_NAMES.mappings} · ${words(type)}`;\n        const reply = await ask(\n          {\n            section,\n            message: `Fluid can't list its ${words(type)}s, so compare \\`fluid connect mappings ${provider.id} ${type}\\` with them yourself. Add a ${words(type)} row now?`,\n            kind: \"select\",\n            choices: [\n              { title: \"Not now\", value: \"no\" },\n              { title: `Add a ${words(type)} row`, value: \"add\" },\n            ],\n          },\n          canGoBack,\n        );\n        if (\"nav\" in reply) return reply;\n        if (reply.value !== \"add\") return { done: true, answer: answers.get(id) ?? \"Not now\" };\n\n        const sourceField = report.sourceField ?? SOURCE_FIELD[type]!;\n        const source = await ask(\n          { section, message: `Fluid ${words(type)} name (or * for every one without its own row)`, kind: \"text\" },\n          true,\n        );\n        if (\"nav\" in source) return source.nav === \"back\" ? { retry: true } : source;\n        if (source.value.trim() === \"\") return { retry: true };\n        const target = await askTarget(type, `${label} ${words(type)} for \"${source.value.trim()}\"`, section, true, false);\n        if (\"nav\" in target) return target.nav === \"back\" ? { retry: true } : target;\n        if (target.value.trim() === \"\") return { retry: true };\n        const fields: Record<string, unknown> = {\n          [sourceField]: source.value.trim(),\n          [TARGET_FIELD[type]!]: target.value.trim(),\n        };\n        if (type === \"ship_method\") {\n          const country = await ask(\n            { section, message: \"Country code for this ship method (Enter for any country)\", kind: \"text\" },\n            true,\n          );\n          if (\"nav\" in country) return country.nav === \"back\" ? { retry: true } : country;\n          if (country.value.trim() !== \"\") fields[\"country_code\"] = country.value.trim().toUpperCase();\n        }\n        try {\n          await createMapping(integrations, connection(), type, fields);\n        } catch (error) {\n          prompter.note(`Not saved: ${reasonOf(error)}`);\n          return { retry: true };\n        }\n        result.rowsAdded += 1;\n        const added = Number(answers.get(`${id}#count`) ?? \"0\") + 1;\n        answers.set(`${id}#count`, String(added));\n        answers.set(id, `${added} row(s) added`);\n        prompter.note(`Saved: ${source.value.trim()} → ${target.value.trim()}.`);\n        return { retry: true }; // ask again: another row, or Not now\n      },\n    };\n  };\n\n  steps.push({\n    id: \"mappings-report\",\n    phase: \"mappings\",\n    title: \"Find what needs mapping\",\n    asks: false,\n    run: async () => {\n      prompter.note(autoMap ? \"Mapping exact name matches, then checking what's left…\" : \"Checking what needs mapping…\");\n      const report = await unmappedReport(integrations, connection(), provider, autoMap);\n      const fresh: Step[] = [];\n      let added = 0;\n      for (const entry of report) {\n        added += entry.autoMapped?.length ?? 0;\n        if (entry.status === \"needs_mapping\" && entry.sourceField && TARGET_FIELD[entry.type]) {\n          entry.unmapped!.forEach((value, i) => fresh.push(valueStep(entry, value, i + 1)));\n        } else if (entry.status === \"needs_mapping\") {\n          prompter.note(\n            `${words(entry.type)}: ${entry.unmapped!.length} value(s) to map. Add them with \\`fluid connect map ${provider.id} ${entry.type} --set field=value --yes\\`.`,\n          );\n        } else if (entry.status === \"check_by_hand\" && TARGET_FIELD[entry.type]) {\n          fresh.push(byHandStep(entry));\n        } else if (entry.status === \"error\") {\n          prompter.note(`${words(entry.type)}: couldn't read its values (${entry.error}). Check it later with \\`fluid connect unmapped ${provider.id}\\`.`);\n        }\n      }\n      if (added > 0) {\n        result.autoMapped += added;\n        prompter.note(`Added ${added} row(s) by matching names.`);\n      }\n      const toMap = fresh.filter((s) => s.id.startsWith(\"map:\")).length;\n      prompter.note(\n        toMap === 0\n          ? \"Every value Fluid lists is mapped.\"\n          : `${toMap} value(s) to map. Pick the ${label} value for each; * covers every remaining value of that type.`,\n      );\n      replaceGroup(\"mapping-values\", \"mappings-report\", fresh);\n      return DONE;\n    },\n  });\n\n  // --------------------------------------------------------- settings\n  const settingStep = (key: string, setting: SchemaSetting, position: number, total: number): Step => {\n    const id = `setting:${key}`;\n    return {\n      id,\n      phase: \"settings\",\n      group: \"settings-values\",\n      title: setting.label ?? key,\n      asks: true,\n      run: async (canGoBack) => {\n        const summary = summarizeSettings(ci).find((s) => s.key === key);\n        const current = summary ? summary.value : setting.value;\n        const fallbackLabel = (value: unknown) =>\n          setting.options?.find((o) => o.value === value)?.label ?? display(value);\n        const question: Omit<Question, \"canGoBack\"> = {\n          section: `${PHASE_NAMES.settings} · ${position} of ${total} · ${key}`,\n          message: `${setting.label ?? key} (default: ${fallbackLabel(setting.value)})`,\n          kind: \"text\",\n          ...(setting.description ? { hint: setting.description } : {}),\n        };\n        let choices: Array<Choice & { raw: unknown }> | undefined;\n        if (setting.options && setting.options.length > 0 && !setting.multiple) {\n          choices = setting.options.map((o, i) => ({\n            title: `${o.label ?? display(o.value)}${o.value === setting.value ? \" (default)\" : \"\"}`,\n            value: String(i),\n            raw: o.value,\n          }));\n        } else if (setting.type === \"boolean\") {\n          choices = [\n            { title: `Yes${setting.value === true ? \" (default)\" : \"\"}`, value: \"yes\", raw: true },\n            { title: `No${setting.value === false ? \" (default)\" : \"\"}`, value: \"no\", raw: false },\n          ];\n        }\n        if (choices) {\n          question.kind = \"select\";\n          question.choices = choices.map(({ raw: _raw, ...c }) => c);\n          const now = choices.find((c) => c.raw === current);\n          if (now) question.current = now.title;\n        } else {\n          // Nothing saved: no pre-fill, so Enter keeps it unset.\n          if (current !== null && current !== undefined && current !== \"\") {\n            question.current = display(current);\n          }\n          question.hint = [setting.description, \"JSON for lists and objects\"].filter(Boolean).join(\" · \");\n        }\n\n        const reply = await ask(question, canGoBack);\n        if (\"nav\" in reply) return reply;\n        let value: unknown;\n        if (choices) {\n          value = choices.find((c) => c.value === reply.value)?.raw;\n        } else {\n          const raw = reply.value.trim();\n          if (raw === \"\") return { done: true, answer: display(current) };\n          try {\n            value = /^(true|false|null|-?\\d+(\\.\\d+)?)$|^[[{]/.test(raw) ? JSON.parse(raw) : raw;\n          } catch {\n            value = raw;\n          }\n        }\n        if (JSON.stringify(value) === JSON.stringify(current)) {\n          return { done: true, answer: fallbackLabel(value) };\n        }\n        try {\n          ci = await updateSyncSettings(integrations, connection(), settingsPatch({ [key]: value }));\n        } catch (error) {\n          prompter.note(`Not saved: ${reasonOf(error)}`);\n          return { retry: true };\n        }\n        if (!result.settingsChanged.includes(key)) result.settingsChanged.push(key);\n        prompter.note(`Saved: ${setting.label ?? key} → ${fallbackLabel(value)}.`);\n        return { done: true, answer: fallbackLabel(value) };\n      },\n    };\n  };\n\n  steps.push({\n    id: \"settings-choice\",\n    phase: \"settings\",\n    title: \"Sync settings\",\n    asks: true,\n    run: async (canGoBack) => {\n      ci = await getCompanyIntegration(integrations, connection());\n      const schema = ci.settings_schema ?? {};\n      const common = COMMON_SETTINGS.flatMap((key) => {\n        const [entity, name] = key.split(\".\") as [string, string];\n        const setting = schema[entity]?.[name];\n        return setting ? [{ key, setting }] : [];\n      });\n      const reply = await ask(\n        {\n          section: PHASE_NAMES.settings,\n          message: `Sync settings. A new connection starts on the defaults, and each default is safe.`,\n          kind: \"select\",\n          choices: [\n            { title: \"Keep every setting as it is\", value: \"keep\" },\n            { title: `Go through the ${common.length} common settings`, value: \"review\" },\n            { title: \"Put every setting back to its default\", value: \"defaults\" },\n          ],\n        },\n        canGoBack,\n      );\n      if (\"nav\" in reply) return reply;\n      if (reply.value === \"review\") {\n        replaceGroup(\n          \"settings-values\",\n          \"settings-choice\",\n          common.map(({ key, setting }, i) => settingStep(key, setting, i + 1, common.length)),\n        );\n        return { done: true, answer: \"Go through the common settings\" };\n      }\n      replaceGroup(\"settings-values\", \"settings-choice\", []);\n      if (reply.value === \"defaults\") {\n        try {\n          ci = await updateSyncSettings(integrations, connection(), defaultsPatch(schema));\n        } catch (error) {\n          prompter.note(`Not saved: ${reasonOf(error)}`);\n          return { retry: true };\n        }\n        result.settingsRestored = true;\n        prompter.note(\"Every setting is back on its default.\");\n        return { done: true, answer: \"Put back to defaults\" };\n      }\n      return { done: true, answer: \"Keep as is\" };\n    },\n  });\n\n  // ------------------------------------------------------------- menu\n  const goBack = (): boolean => {\n    let previous = history.pop();\n    // A regenerated report or settings pass may have removed it.\n    while (previous !== undefined && indexOf(previous) < 0) previous = history.pop();\n    if (previous === undefined) {\n      prompter.note(\"This is the first question.\");\n      return false;\n    }\n    skipped.delete(previous);\n    index = indexOf(previous);\n    targeted = previous;\n    return true;\n  };\n\n  /** True when the walk should stop. */\n  const openMenu = async (): Promise<boolean> => {\n    const phases = (Object.keys(PHASE_NAMES) as Phase[]).filter((phase) =>\n      steps.some((s) => s.phase === phase),\n    );\n    const answered = steps.filter((s) => s.asks && answers.has(s.id));\n    const action = await prompter.menu(\"What next?\", [\n      { title: \"Continue\", value: \"continue\" },\n      { title: \"Back to the previous question\", value: \"back\", disabled: history.length === 0 },\n      ...phases.map((phase) => ({ title: `Go to ${PHASE_NAMES[phase]}`, value: `phase:${phase}` })),\n      { title: \"Change an answer\", value: \"change\", disabled: answered.length === 0 },\n      { title: \"Finish: show the summary\", value: \"finish\" },\n      { title: \"Stop for now (answers are saved)\", value: \"quit\" },\n    ]);\n    if (action === null || action === \"quit\") return true;\n    if (action === \"back\") {\n      goBack();\n    } else if (action === \"finish\") {\n      index = steps.length;\n    } else if (action.startsWith(\"phase:\")) {\n      const phase = action.slice(\"phase:\".length) as Phase;\n      const first = phase === \"mappings\" ? \"mappings-start\" : steps.find((s) => s.phase === phase)!.id;\n      index = indexOf(first);\n      targeted = steps.find((s, i) => i >= index && s.asks)?.id;\n    } else if (action === \"change\") {\n      const id = await prompter.menu(\n        \"Which answer?\",\n        answered.map((s) => ({ title: `${s.title} — ${answers.get(s.id)}`, value: s.id })),\n      );\n      if (id) {\n        index = indexOf(id);\n        targeted = id;\n      }\n    }\n    return false;\n  };\n\n  // ------------------------------------------------------------- loop\n  while (index < steps.length) {\n    const step = steps[index]!;\n    if (step.when && !step.when()) {\n      index += 1;\n      continue;\n    }\n    if (step.asks && answers.has(step.id) && targeted !== step.id) {\n      index += 1; // answered: walking forward passes it over\n      continue;\n    }\n    const outcome = await step.run(history.length > 0);\n\n    if (\"stop\" in outcome) {\n      result.stopped = true;\n      break;\n    }\n    if (\"goto\" in outcome) {\n      index = indexOf(outcome.goto);\n      targeted = steps[index]?.id;\n      continue;\n    }\n    if (\"retry\" in outcome) {\n      targeted = step.id;\n      continue;\n    }\n    if (\"nav\" in outcome) {\n      if (outcome.nav === \"quit\") {\n        result.stopped = true;\n        break;\n      }\n      if (outcome.nav === \"back\") {\n        if (!goBack()) targeted = step.id;\n        continue;\n      }\n      if (outcome.nav === \"skip\") {\n        skipped.set(step.id, step.title);\n        history.push(step.id);\n        index += 1;\n        continue;\n      }\n      targeted = step.id; // menu: come back here unless it moves elsewhere\n      if (await openMenu()) {\n        result.stopped = true;\n        break;\n      }\n      continue;\n    }\n    if (step.asks) {\n      history.push(step.id);\n      skipped.delete(step.id);\n      answers.set(step.id, outcome.answer ?? \"\");\n    }\n    targeted = undefined;\n    index += 1;\n  }\n\n  // ---------------------------------------------------------- summary\n  status = await providerStatus(integrations, provider);\n  result.connected = status.connected;\n  result.skipped = [...skipped.values()];\n  try {\n    if (ciId === null) throw new ConnectError(\"there's no connection yet\");\n    const report = await unmappedReport(integrations, ciId, provider, false);\n    result.mappingsDone = report.every((r) => r.status === \"covered\");\n    result.stillUnmapped = report\n      .filter((r) => r.status !== \"covered\")\n      .map((r) => ({ type: r.type, count: r.unmapped?.length ?? null, status: r.status }));\n  } catch (error) {\n    prompter.note(`Couldn't check the mappings: ${reasonOf(error)}`);\n  }\n\n  const lines = [\n    `${label}: ${result.connected ? \"connected\" : \"not connected yet\"}.`,\n    result.credentialsSaved ? \"Credentials saved and tested.\" : \"\",\n    result.autoMapped + result.rowsAdded > 0\n      ? `Mapping rows added: ${result.rowsAdded}${result.autoMapped > 0 ? `, plus ${result.autoMapped} by name` : \"\"}.`\n      : \"\",\n    result.mappingsDone\n      ? \"Every mapping type is covered.\"\n      : result.stillUnmapped.length > 0\n        ? `Still to map or check: ${result.stillUnmapped\n            .map((r) => `${words(r.type)}${r.count ? ` (${r.count})` : r.status === \"check_by_hand\" ? \" (check by hand)\" : \"\"}`)\n            .join(\", \")}. See \\`fluid connect unmapped ${provider.id}\\`.`\n        : \"\",\n    result.settingsRestored ? \"Every sync setting is on its default.\" : \"\",\n    result.settingsChanged.length > 0 ? `Settings changed: ${result.settingsChanged.join(\", \")}.` : \"\",\n    result.skipped.length > 0 ? `Skipped: ${result.skipped.join(\"; \")}.` : \"\",\n    `Run \\`fluid connect walk ${provider.id}\\` again to pick up where you left off.`,\n  ].filter(Boolean);\n  prompter.note(`\\n${lines.join(\"\\n\")}`);\n  return result;\n}\n","import type { Command } from \"commander\";\nimport prompts from \"prompts\";\nimport type { CommandContext, FluidPlugin } from \"@fluid-app/fluid-cli\";\nimport {\n  assertInteractive,\n  createDomainCommand,\n  terminalPrompter,\n} from \"@fluid-app/fluid-cli\";\n\nimport {\n  companyIntegrationId,\n  createMapping,\n  deleteMapping,\n  getCompanyIntegration,\n  installProvider,\n  integrationsBase,\n  listMappings,\n  mappingType,\n  mappingOptions,\n  permissionDeniedMessage,\n  providerStatus,\n  saveCredentials,\n  updateSyncSettings,\n  type ConnectClient,\n} from \"./api.js\";\nimport { ConnectError, PROVIDER_IDS, providerOf } from \"./providers.js\";\nimport {\n  defaultsPatch,\n  parseAssignments,\n  syncSettingsPatch,\n} from \"./settings.js\";\nimport { connectStatus } from \"./status.js\";\nimport { summarizeSettings } from \"./summary.js\";\nimport { unmappedReport } from \"./unmapped.js\";\nimport { walkConnect } from \"./walk.js\";\n\nasync function fluidClient(ctx: CommandContext): Promise<ConnectClient> {\n  return (await ctx.getClient()) as unknown as ConnectClient;\n}\n\nasync function integrationsClient(ctx: CommandContext): Promise<ConnectClient> {\n  return (await ctx.getClientFor(\n    integrationsBase(),\n  )) as unknown as ConnectClient;\n}\n\n/**\n * Changes to a live connection need an explicit yes. Scripts and agents\n * pass `--yes`; an interactive terminal is asked. With neither, nothing runs.\n */\nexport async function confirmChange(\n  question: string,\n  yes: boolean,\n  interactive: boolean = Boolean(process.stdin.isTTY),\n): Promise<void> {\n  if (yes) return;\n  if (!interactive)\n    throw new ConnectError(`${question} Pass --yes to confirm.`);\n  const answer = await prompts({\n    type: \"confirm\",\n    name: \"ok\",\n    message: question,\n    initial: false,\n  });\n  if (!answer.ok) throw new ConnectError(\"Cancelled.\");\n}\n\n/** Print a failure as JSON on stderr and exit non-zero. A failed connection\n *  test (422) carries the provider's reason in `errors`; a Fluid Connect\n *  error carries its `code` (e.g. `not_connected`). */\nfunction fail(err: unknown): void {\n  const status =\n    typeof (err as { status?: unknown }).status === \"number\"\n      ? (err as { status: number }).status\n      : undefined;\n  const body = (err as { body?: Record<string, unknown> | null }).body;\n  const detail =\n    body && (body[\"errors\"] ?? body[\"error\"] ?? body[\"error_message\"]);\n  const message =\n    permissionDeniedMessage(err) ??\n    (typeof detail === \"string\"\n      ? detail\n      : err instanceof Error\n        ? err.message\n        : String(err));\n  const code =\n    body && typeof body[\"code\"] === \"string\" ? body[\"code\"] : undefined;\n  process.stderr.write(\n    JSON.stringify({\n      error: message,\n      ...(status ? { status } : {}),\n      ...(code ? { code } : {}),\n      ...(detail && typeof detail === \"object\" ? { details: detail } : {}),\n    }) + \"\\n\",\n  );\n  process.exitCode = 1;\n}\n\nfunction run(action: () => Promise<void>): Promise<void> {\n  return action().catch(fail);\n}\n\nconst collect = (value: string, previous: string[] = []): string[] => [\n  ...previous,\n  value,\n];\n\nexport function registerConnectCommands(\n  parent: Command,\n  ctx: CommandContext,\n): void {\n  parent\n    .command(\"list\")\n    .description(\n      `Show ${PROVIDER_IDS.join(\", \")} and whether each is installed`,\n    )\n    .action(() =>\n      run(async () => {\n        const integrations = await integrationsClient(ctx);\n        ctx.output(\n          await Promise.all(\n            PROVIDER_IDS.map((id) =>\n              providerStatus(integrations, providerOf(id)),\n            ),\n          ),\n        );\n      }),\n    );\n\n  parent\n    .command(\"status <provider>\")\n    .description(\n      \"Show the provider's sync status (success rate, tier, failures by category) from Fluid; read-only\",\n    )\n    .option(\"--range <range>\", \"The window: 60m, 24h, 7d or 30d (default 24h)\")\n    .action((providerId: string, opts: { range?: string }) =>\n      run(async () => {\n        const provider = providerOf(providerId);\n        ctx.output(\n          await connectStatus(await fluidClient(ctx), provider, opts.range),\n        );\n      }),\n    );\n\n  parent\n    .command(\"install <provider>\")\n    .description(\n      \"Install the provider's droplet, which creates its connection (changes live config)\",\n    )\n    .option(\"--yes\", \"Confirm without a prompt\", false)\n    .action((providerId: string, opts: { yes: boolean }) =>\n      run(async () => {\n        const provider = providerOf(providerId);\n        const status = await providerStatus(\n          await integrationsClient(ctx),\n          provider,\n        );\n        if (status.installed) {\n          ctx.output({ ...status, alreadyInstalled: true });\n          return;\n        }\n        await confirmChange(\n          `Install ${provider.label} for this company?`,\n          opts.yes,\n        );\n        ctx.output({\n          ...(await installProvider(\n            await fluidClient(ctx),\n            provider,\n            status.dropletUuid,\n          )),\n          // fluid-integrations sets up the connection from Fluid's install\n          // webhook, so it can take a moment to appear.\n          next: `The connection appears within a minute. Check with \\`fluid connect show ${provider.id}\\`, then save the credentials.`,\n        });\n      }),\n    );\n\n  parent\n    .command(\"show <provider>\")\n    .description(\n      \"Show the connection: state, supported mappings, and every sync setting with its current value\",\n    )\n    .action((providerId: string) =>\n      run(async () => {\n        const provider = providerOf(providerId);\n        const integrations = await integrationsClient(ctx);\n        const ciId = await companyIntegrationId(integrations, provider);\n        const ci = await getCompanyIntegration(integrations, ciId);\n        ctx.output({\n          provider: provider.id,\n          companyIntegrationId: ci.id,\n          initialized: ci.initialized ?? null,\n          environment: ci.environment ?? null,\n          liveSyncState: ci.live_sync_state ?? null,\n          liveSyncDegradedReason: ci.live_sync_degraded_reason ?? null,\n          credentialGroups: provider.credentialGroups,\n          // The names the mapping commands take (`customer_type`), not the\n          // API's card names (`customer_type_title`).\n          supportedMappings: (ci.supported_mappings ?? []).map(mappingType),\n          settings: summarizeSettings(ci),\n        });\n      }),\n    );\n\n  parent\n    .command(\"credentials <provider>\")\n    .description(\n      \"Save credentials; the connection is tested before anything is saved, and created if the install has not yet (changes live config). Values here land in shell history; `fluid connect walk` asks for passwords hidden\",\n    )\n    .option(\n      \"--set <key=value>\",\n      \"A credential, e.g. api.username=alice or mssql.dataserver=sql.example.com (repeatable)\",\n      collect,\n      [],\n    )\n    .option(\"--yes\", \"Confirm without a prompt\", false)\n    .action((providerId: string, opts: { set: string[]; yes: boolean }) =>\n      run(async () => {\n        const provider = providerOf(providerId);\n        if (opts.set.length === 0) {\n          throw new ConnectError(\n            `Pass credentials with --set, e.g. --set api.username=alice. ${provider.label} uses: ${provider.credentialGroups.join(\", \")}.`,\n          );\n        }\n        const authSettings = parseAssignments(opts.set, { strings: true });\n        const integrations = await integrationsClient(ctx);\n        await confirmChange(\n          `Save new ${provider.label} credentials?`,\n          opts.yes,\n        );\n        ctx.output(\n          await saveCredentials(\n            integrations,\n            await fluidClient(ctx),\n            provider,\n            authSettings,\n          ),\n        );\n      }),\n    );\n\n  parent\n    .command(\"settings <provider>\")\n    .description(\n      \"List sync settings, change them with --set entity.key=value, or restore defaults with --defaults (changes live config)\",\n    )\n    .option(\n      \"--set <key=value>\",\n      \"A setting from `fluid connect show`, e.g. order.refund_handling=hold (repeatable)\",\n      collect,\n      [],\n    )\n    .option(\n      \"--defaults\",\n      \"Restore settings to their defaults: all of them, or only those named with --only\",\n      false,\n    )\n    .option(\n      \"--only <key>\",\n      \"With --defaults, restore just this setting, e.g. order.refund_handling (repeatable)\",\n      collect,\n      [],\n    )\n    .option(\"--yes\", \"Confirm without a prompt\", false)\n    .action(\n      (\n        providerId: string,\n        opts: {\n          set: string[];\n          defaults: boolean;\n          only: string[];\n          yes: boolean;\n        },\n      ) =>\n        run(async () => {\n          const provider = providerOf(providerId);\n          if (opts.defaults && opts.set.length > 0) {\n            throw new ConnectError(\"Use --set or --defaults, not both.\");\n          }\n          if (opts.only.length > 0 && !opts.defaults) {\n            throw new ConnectError(\"--only goes with --defaults.\");\n          }\n          const integrations = await integrationsClient(ctx);\n          const ciId = await companyIntegrationId(integrations, provider);\n          if (opts.defaults) {\n            const ci = await getCompanyIntegration(integrations, ciId);\n            const patch = defaultsPatch(ci.settings_schema ?? {}, opts.only);\n            const what =\n              opts.only.length > 0\n                ? `${opts.only.length} setting(s)`\n                : \"every sync setting\";\n            await confirmChange(\n              `Restore ${what} to the default for ${provider.label}?`,\n              opts.yes,\n            );\n            ctx.output(\n              summarizeSettings(\n                await updateSyncSettings(integrations, ciId, patch),\n              ),\n            );\n            return;\n          }\n          if (opts.set.length === 0) {\n            ctx.output(\n              summarizeSettings(\n                await getCompanyIntegration(integrations, ciId),\n              ),\n            );\n            return;\n          }\n          const patch = syncSettingsPatch(opts.set);\n          await confirmChange(\n            `Change ${opts.set.length} ${provider.label} sync setting(s)?`,\n            opts.yes,\n          );\n          ctx.output(\n            summarizeSettings(\n              await updateSyncSettings(integrations, ciId, patch),\n            ),\n          );\n        }),\n    );\n\n  parent\n    .command(\"walk <provider>\")\n    .description(\n      \"Set up the connection question by question in the terminal: install, credentials, mappings, and settings. Go back with <, skip with >, open the menu with ?; each answer is saved as you go (changes live config)\",\n    )\n    .action((providerId: string) =>\n      run(async () => {\n        assertInteractive(\n          \"`install`, `credentials`, `unmapped`, `map`, and `settings` with --yes (see `fluid connect --help`)\",\n        );\n        const provider = providerOf(providerId);\n        ctx.output(\n          await walkConnect({\n            fluid: await fluidClient(ctx),\n            integrations: await integrationsClient(ctx),\n            provider,\n            prompter: terminalPrompter(),\n          }),\n        );\n      }),\n    );\n\n  parent\n    .command(\"unmapped <provider>\")\n    .description(\n      \"List only the data mappings a person still has to add; --auto-map first maps exact name matches (Exigo)\",\n    )\n    .option(\n      \"--auto-map\",\n      \"Exigo: add rows where a Fluid value's name matches exactly one Exigo value (changes live config)\",\n      false,\n    )\n    .option(\"--yes\", \"Confirm --auto-map without a prompt\", false)\n    .action((providerId: string, opts: { autoMap: boolean; yes: boolean }) =>\n      run(async () => {\n        const provider = providerOf(providerId);\n        const integrations = await integrationsClient(ctx);\n        const ciId = await companyIntegrationId(integrations, provider);\n        if (opts.autoMap) {\n          if (!provider.targetOptions) {\n            throw new ConnectError(\n              `--auto-map needs ${provider.label}'s own values, which only Exigo lists. Run without it to see what to map.`,\n            );\n          }\n          await confirmChange(\n            `Add ${provider.label} mappings for exact name matches?`,\n            opts.yes,\n          );\n        }\n        const report = await unmappedReport(\n          integrations,\n          ciId,\n          provider,\n          opts.autoMap,\n        );\n        ctx.output({\n          provider: provider.id,\n          done: report.every((r) => r.status === \"covered\"),\n          mappings: report,\n        });\n        // A type that couldn't be checked makes the report incomplete.\n        if (report.some((r) => r.status === \"error\")) process.exitCode = 1;\n      }),\n    );\n\n  parent\n    .command(\"mappings <provider> <type>\")\n    .description(\n      \"List one mapping type's rows (e.g. customer_type, warehouse); --options lists the values to choose from\",\n    )\n    .option(\n      \"--options\",\n      \"List the Fluid values, and for Exigo the Exigo values, instead of the saved rows\",\n      false,\n    )\n    .action((providerId: string, type: string, opts: { options: boolean }) =>\n      run(async () => {\n        const provider = providerOf(providerId);\n        const integrations = await integrationsClient(ctx);\n        const ciId = await companyIntegrationId(integrations, provider);\n        ctx.output(\n          opts.options\n            ? await mappingOptions(integrations, ciId, type, provider)\n            : await listMappings(integrations, ciId, type),\n        );\n      }),\n    );\n\n  parent\n    .command(\"map <provider> <type>\")\n    .description(\n      \"Add a mapping row, e.g. --set source_type_slug=rep --set target_type_id=2 (changes live config)\",\n    )\n    .option(\n      \"--set <field=value>\",\n      \"A field of the mapping row (repeatable)\",\n      collect,\n      [],\n    )\n    .option(\"--yes\", \"Confirm without a prompt\", false)\n    .action(\n      (\n        providerId: string,\n        type: string,\n        opts: { set: string[]; yes: boolean },\n      ) =>\n        run(async () => {\n          const provider = providerOf(providerId);\n          if (opts.set.length === 0) {\n            throw new ConnectError(\n              \"Pass the row's fields with --set field=value.\",\n            );\n          }\n          const integrations = await integrationsClient(ctx);\n          const ciId = await companyIntegrationId(integrations, provider);\n          await confirmChange(\n            `Add a ${type} mapping to ${provider.label}?`,\n            opts.yes,\n          );\n          ctx.output(\n            await createMapping(\n              integrations,\n              ciId,\n              type,\n              parseAssignments(opts.set),\n            ),\n          );\n        }),\n    );\n\n  parent\n    .command(\"unmap <provider> <type> <id>\")\n    .description(\"Remove one mapping row (changes live config)\")\n    .option(\"--yes\", \"Confirm without a prompt\", false)\n    .action(\n      (providerId: string, type: string, id: string, opts: { yes: boolean }) =>\n        run(async () => {\n          const provider = providerOf(providerId);\n          const rowId = Number(id);\n          if (!Number.isInteger(rowId) || rowId <= 0) {\n            throw new ConnectError(`\"${id}\" isn't a mapping row id.`);\n          }\n          const integrations = await integrationsClient(ctx);\n          const ciId = await companyIntegrationId(integrations, provider);\n          await confirmChange(\n            `Remove ${type} mapping ${rowId} from ${provider.label}?`,\n            opts.yes,\n          );\n          ctx.output(await deleteMapping(integrations, ciId, type, rowId));\n        }),\n    );\n}\n\nconst plugin: FluidPlugin = {\n  name: \"@fluid-app/fluid-cli-connect\",\n  version: \"0.1.1\",\n  register(ctx) {\n    ctx.program.addCommand(\n      createDomainCommand(\n        \"connect\",\n        \"Connect Exigo, InfoTrax, ByDesign, or Pillars: credentials, data mappings, and sync settings\",\n        registerConnectCommands,\n      ),\n    );\n  },\n};\n\nexport default plugin;\n"],"mappings":";;;AAmBA,MAAM,oBAAgD;CACpD;EAAE,KAAK;EAAoB,OAAO;EAAiC;CACnE;EAAE,KAAK;EAAkB,OAAO;EAA4B;CAC5D;EAAE,KAAK;EAAkB,OAAO;EAA6B;CAC7D;EAAE,KAAK;EAAkB,OAAO;EAA6B,QAAQ;EAAM;CAC5E;AAED,MAAa,YAAY;CACvB,OAAO;EACL,OAAO;EACP,MAAM;EACN,aAAa;EAEb,kBAAkB,CAAC,OAAO,QAAQ;EAClC,aAAa;GACX;IAAE,KAAK;IAAe,OAAO;IAAsC;GACnE;IAAE,KAAK;IAAgB,OAAO;IAAsC;GACpE;IAAE,KAAK;IAAgB,OAAO;IAAsC,QAAQ;IAAM;GAClF,GAAG;GACJ;EAED,cAAc;EAEd,eAAe;EAChB;CACD,UAAU;EACR,OAAO;EACP,MAAM;EACN,aAAa;EACb,k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