/** * Shared organization-resolution helper — the org-scoped counterpart to * `resolveEnvironment` in `./environment.ts`. * * `brief`, `campaign`, and `brand` act on a Sitecore **organization**, * not an XM Cloud **environment**: their APIs are org-keyed (one brand * credential per org, one region per org, briefs/campaigns live at org * scope). They must not require `--environment-name` / `defaultEnvProfile` * the way `resolveEnvironment` does — an operator with a single * environment, or none at all, should still be able to run them. * * This consolidates the resolution `brand/credential.ts` already did * inline (`resolveBrandOrgId`) so brief and campaign get the same * behaviour instead of dragging in the env-requiring resolver purely to * read `environment.organizationId`. * * Workspace-policy gating: runs `enforceOrganizationPolicy` once the * orgId is resolved — the org-scoped counterpart of the env-scoped gate * inside `resolveEnvironment`. Closes the prior bypass where brand / * brief / campaign retargeted any orgId without an allowlist check. * `skipPolicy` is the same escape hatch used by `setup` / `policy` * commands and `mcp serve` startup. */ import type { EnvironmentConfiguration, RootConfiguration } from "../config/types.js"; export interface ResolveOrganizationOptions { /** Base directory for resolving `sitecoreai.cli.json`; defaults to cwd. */ config?: string; /** Explicit organization id (e.g. from `--org-id`). Highest priority. */ orgId?: string; /** Explicit env profile name (e.g. from `-n` / `--environment-name`). */ environmentName?: string; /** * Skip the workspace-policy gate (`enforceOrganizationPolicy`). Used * by paths that run *before* an org is enrolled — `scai mcp serve` * startup, the `setup` / `policy` commands. Everything that touches * tenant data leaves this unset, so the gate is on by default. */ skipPolicy?: boolean; } export interface ResolvedOrganization { /** The resolved Sitecore organization id. */ orgId: string; /** The full root configuration. */ root: RootConfiguration; /** * An env profile belonging to `orgId`, when one exists — the env that * was explicitly named, else the first profile carrying this org. * `undefined` when the org was resolved purely from `--org-id` (or the * sole `brand` entry) and no env profile references it. Consumers that * need an env-scoped automation client read this; those that only need * the org id ignore it. */ environment?: EnvironmentConfiguration; /** Name of `environment`, when one was resolved. */ envName?: string; } /** * Resolve the Sitecore organization an org-scoped command should act on. * * Resolution order: * 1. Explicit `orgId` (`--org-id`). * 2. The explicitly named env profile's `organizationId` (`-n` or a * configured `defaultEnvProfile`) — a named env is authoritative. * 3. The first env profile that carries an `organizationId` — so a * single-environment config resolves with no flag and no default. * 4. The sole `brand[orgId]` credential entry, when exactly one exists. * * Throws `INPUT_INVALID` when none yields an org id, and `ENV_NOT_FOUND` * when an explicitly named env profile does not exist. */ export declare const resolveOrganization: (options: ResolveOrganizationOptions) => ResolvedOrganization;