{"version":3,"sources":["../../src/public-error/locale.ts","../../src/public-error/LocalizedMessageSet.ts","../../src/public-error/LocaleResolver.ts","../../src/utils/error-resolution.ts","../../src/utils/problem-validation.ts","../../src/public-error/PublicErrorCatalog.ts","../../src/public-error/project.ts","../../src/public-error/localize.ts","../../src/utils/json-safe.ts","../../src/public-error/toProblem.ts"],"names":[],"mappings":";;;;;;;;;;;;AAUO,SAAS,mBAAmB,GAAA,EAAiC;AAClE,EAAA,IAAI;AACF,IAAA,OAAO,IAAA,CAAK,mBAAA,CAAoB,GAAG,CAAA,CAAE,CAAC,CAAA;AAAA,EACxC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAeO,SAAS,gBAAgB,YAAA,EAAgC;AAC9D,EAAA,IAAI,KAAA,GAAQ,YAAA,CAAa,KAAA,CAAM,GAAG,CAAA;AAClC,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,OAAO,KAAA,CAAM,SAAS,CAAA,EAAG;AACvB,IAAA,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAG,CAAC,CAAA;AAC1B,IAAA,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AACzB,IAAA,IAAI,KAAA,CAAM,SAAS,CAAA,IAAM,KAAA,CAAM,MAAM,MAAA,GAAS,CAAC,CAAA,CAAa,MAAA,KAAW,CAAA,EAAG;AACxE,MAAA,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;;;AC1CA,IAAA,SAAA;AA6BO,IAAM,sBAAN,MAA0B;AAAA,EAMxB,YAAY,OAAA,EAAqC;AAFxD,IAAA,YAAA,CAAA,IAAA,EAAS,SAAA,CAAA;AAGP,IAAA,MAAM,UAAA,GAAa,mBAAA,CAAoB,OAAA,CAAQ,UAAA,EAAY,YAAY,CAAA;AA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AAA,CAAiB,SAAA,CAAU,MAAM,CAAA,EAAG;AACvC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,4EAAA,EAA+E,MAAA,CAAO,SAAA,CAAU,MAAM,CAAC,CAAA,CAAA;AAAA,KACzG;AAAA,EACF;AACA,EAAA,IAAI,UAAU,IAAA,KAAS,MAAA,IAAa,CAAC,gBAAA,CAAiB,SAAA,CAAU,IAAI,CAAA,EAAG;AACrE,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,SAAA;AACT","file":"index.cjs","sourcesContent":["// Internal BCP 47 locale utilities used by the public-error localization\n// primitives (LocalizedMessageSet, resolveUserMessage). Not part of the public\n// surface.\n\n/**\n * Canonicalizes a single BCP 47 tag with `Intl.getCanonicalLocales`, or returns\n * `undefined` if it is structurally invalid. `Intl.getCanonicalLocales` throws a\n * `RangeError` on invalid input; this wraps that into the read-side \"invalid is\n * a miss\" policy. Write-side callers turn the `undefined` into a throw.\n */\nexport function canonicalizeLocale(tag: string): string | undefined {\n  try {\n    return Intl.getCanonicalLocales(tag)[0];\n  } catch {\n    return undefined;\n  }\n}\n\n/**\n * The RFC 4647 lookup fallback chain for a canonical tag: the tag itself, then\n * progressively truncated from the right one subtag at a time. Whenever\n * truncation would leave a single-character singleton subtag (a `u` extension,\n * an `x` private-use marker, and so on) as the trailing subtag, that singleton\n * is removed as well before the next candidate is yielded.\n *\n * `zh-Hant-TW` -> `zh-Hant` -> `zh`\n * `de-DE-u-co-phonebk` -> `de-DE-u-co` -> `de-DE` -> `de`\n * `en-US-x-private` -> `en-US` -> `en`\n *\n * The input is assumed already canonical, so each truncation stays canonical.\n */\nexport function truncationChain(canonicalTag: string): string[] {\n  let parts = canonicalTag.split(\"-\");\n  const chain: string[] = [];\n  while (parts.length > 0) {\n    chain.push(parts.join(\"-\"));\n    parts = parts.slice(0, -1);\n    if (parts.length > 0 && (parts[parts.length - 1] as string).length === 1) {\n      parts = parts.slice(0, -1);\n    }\n  }\n  return chain;\n}\n","import { canonicalizeLocale } from \"./locale.js\";\n\n/**\n * Options for {@link LocalizedMessageSet}.\n */\nexport type LocalizedMessageSetOptions = {\n  /**\n   * The guaranteed-fallback locale, made explicit (no hidden default). After\n   * canonicalization it must have an entry in `messages`.\n   */\n  readonly baseLocale: string;\n  /**\n   * Locale tag to message text. Keys are canonicalized (BCP 47); message\n   * contents are preserved verbatim and never trimmed or modified.\n   */\n  readonly messages: Readonly<Record<string, string>>;\n};\n\n/**\n * An immutable, canonicalized set of localized messages keyed by BCP 47 locale.\n *\n * Construction enforces the write-side invariants: every key is canonicalized\n * with `Intl.getCanonicalLocales` (invalid tags throw), keys that collide after\n * canonicalization throw, every message must contain at least one non-whitespace\n * character, and an entry for the (canonical) `baseLocale` must exist. Lookups\n * are exact, canonical matches with no parent fallback: walking up a tag\n * (`de-DE` to `de`) and choosing between preferences is the resolver's job, not\n * the set's. On the read side an invalid requested tag is a miss, never a throw.\n */\nexport class LocalizedMessageSet {\n  /** Canonical BCP 47 tag of the guaranteed-fallback locale. */\n  public readonly baseLocale: string;\n\n  readonly #messages: ReadonlyMap<string, string>;\n\n  public constructor(options: LocalizedMessageSetOptions) {\n    const baseLocale = canonicalizeOrThrow(options.baseLocale, \"baseLocale\");\n\n    const canonical = new Map<string, string>();\n    const originalKeyFor = new Map<string, string>();\n    for (const [rawKey, text] of Object.entries(options.messages)) {\n      const key = canonicalizeOrThrow(rawKey, `messages key \"${rawKey}\"`);\n      const prior = originalKeyFor.get(key);\n      if (prior !== undefined) {\n        throw new Error(\n          `LocalizedMessageSet: keys \"${prior}\" and \"${rawKey}\" both canonicalize to \"${key}\".`,\n        );\n      }\n      if (text.trim().length === 0) {\n        throw new Error(\n          `LocalizedMessageSet: message for \"${rawKey}\" is empty or whitespace-only.`,\n        );\n      }\n      originalKeyFor.set(key, rawKey);\n      canonical.set(key, text);\n    }\n\n    if (!canonical.has(baseLocale)) {\n      throw new Error(\n        `LocalizedMessageSet: no message for baseLocale \"${baseLocale}\".`,\n      );\n    }\n\n    this.baseLocale = baseLocale;\n    this.#messages = canonical;\n  }\n\n  /**\n   * Whether an exact (canonical) entry exists for `locale`. No parent fallback.\n   * An invalid tag is a miss.\n   */\n  public has(locale: string): boolean {\n    const key = canonicalizeLocale(locale);\n    return key !== undefined && this.#messages.has(key);\n  }\n\n  /**\n   * The exact (canonical) message for `locale`, or `undefined`. No parent\n   * fallback. An invalid tag yields `undefined`.\n   */\n  public get(locale: string): string | undefined {\n    const key = canonicalizeLocale(locale);\n    return key === undefined ? undefined : this.#messages.get(key);\n  }\n\n  /**\n   * Fast-path lookup for a key that is **already canonical**. Skips\n   * canonicalization, so the caller is responsible for passing a canonical tag\n   * (a non-canonical spelling misses). Used by the resolver, which already\n   * canonicalizes once and walks canonical truncation tags; prefer {@link get}\n   * for untrusted input.\n   */\n  public getCanonical(canonicalLocale: string): string | undefined {\n    return this.#messages.get(canonicalLocale);\n  }\n\n  /** A copy of the entries as `[canonicalLocale, message]` pairs. */\n  public entries(): ReadonlyArray<readonly [string, string]> {\n    return [...this.#messages.entries()];\n  }\n}\n\n/**\n * Canonicalizes a single BCP 47 tag, or throws if it is invalid. Used on the\n * write side, where an invalid tag is a construction error.\n */\nfunction canonicalizeOrThrow(tag: string, label: string): string {\n  const canonical = canonicalizeLocale(tag);\n  if (canonical === undefined) {\n    throw new Error(\n      `LocalizedMessageSet: invalid locale tag for ${label}: \"${tag}\".`,\n    );\n  }\n  return canonical;\n}\n","import type { LocalizedMessageSet } from \"./LocalizedMessageSet.js\";\nimport { canonicalizeLocale, truncationChain } from \"./locale.js\";\n\n/**\n * The outcome of resolving a localized message: the text plus the locale that\n * actually matched and how. `matchedPreferenceIndex` and `match` are diagnostic\n * (tests, finding missing translations) and need not reach a public view.\n */\nexport type ResolvedUserMessage = {\n  /** Canonical BCP 47 tag that actually matched. */\n  locale: string;\n  /** The message for that locale. */\n  message: string;\n  /**\n   * Index into the supplied `locales` whose tag (or one of its parents)\n   * matched. `undefined` only when the match came from the appended baseLocale.\n   */\n  matchedPreferenceIndex?: number;\n  /**\n   * `exact` when the canonical supplied tag matched, `parent` when one of its\n   * truncations matched, `base` only when the appended baseLocale matched.\n   */\n  match: \"exact\" | \"parent\" | \"base\";\n};\n\n/**\n * Resolves a single localized message from `set` against an ordered list of\n * locale preferences (RFC 4647 lookup). For each supplied locale, in order, the\n * canonical tag and its truncation chain are tried; the first present entry\n * wins. Candidates are deduped preserving first-seen order, so a duplicate is\n * attributed to the earlier preference's chain. The baseLocale is consulted only\n * after every supplied preference, and a match against it alone is reported as\n * `base`. An invalid supplied tag is skipped (a miss), never a throw.\n *\n * This never returns `undefined`: a {@link LocalizedMessageSet} always has an\n * entry for its baseLocale, which is the guaranteed floor.\n */\nexport function resolveUserMessage(\n  set: LocalizedMessageSet,\n  options?: { locales?: readonly string[] },\n): ResolvedUserMessage {\n  const locales = options?.locales ?? [];\n  const seen = new Set<string>();\n\n  for (const [index, raw] of locales.entries()) {\n    const canonical = canonicalizeLocale(raw);\n    if (canonical === undefined) continue;\n    for (const [depth, tag] of truncationChain(canonical).entries()) {\n      if (seen.has(tag)) continue;\n      seen.add(tag);\n      // Tags from the truncation chain are already canonical; skip re-canonicalizing.\n      const message = set.getCanonical(tag);\n      if (message !== undefined) {\n        return {\n          locale: tag,\n          message,\n          matchedPreferenceIndex: index,\n          match: depth === 0 ? \"exact\" : \"parent\",\n        };\n      }\n    }\n  }\n\n  // Floor: the baseLocale entry is guaranteed to exist by the set's invariant.\n  const baseMessage = set.getCanonical(set.baseLocale);\n  if (baseMessage !== undefined) {\n    return { locale: set.baseLocale, message: baseMessage, match: \"base\" };\n  }\n\n  // Unreachable for a valid LocalizedMessageSet; guards against a bypassed invariant.\n  throw new Error(\n    `LocaleResolver: LocalizedMessageSet has no entry for its baseLocale \"${set.baseLocale}\".`,\n  );\n}\n","/**\n * Shared error-to-descriptor resolution: exact `code` match, then predicate\n * matchers in registration order. Used by the public-error catalog, keeping the\n * matching semantics (and the throwing-getter and throwing-matcher handling) in\n * a single definition.\n */\n\n/** A predicate matcher paired with the value it resolves to. */\nexport type PredicateEntry<T> = {\n  readonly match: (error: unknown) => boolean;\n  readonly value: T;\n};\n\n/** The outcome of resolving an error by code then predicates. */\nexport type CodeResolution<T> =\n  | {\n      readonly found: true;\n      readonly via: \"code\" | \"predicate\";\n      readonly value: T;\n      readonly matcherThrew: boolean;\n    }\n  | { readonly found: false; readonly matcherThrew: boolean };\n\n/**\n * The string `code` of an error-like object, or `undefined`. A throwing `code`\n * getter is treated as no code, so resolution stays total.\n */\nexport function readErrorCode(error: unknown): string | undefined {\n  if (typeof error === \"object\" && error !== null && \"code\" in error) {\n    try {\n      const code = (error as { code: unknown }).code;\n      if (typeof code === \"string\") return code;\n    } catch {\n      return undefined;\n    }\n  }\n  return undefined;\n}\n\n/**\n * Resolves `error` to a value by exact `code` match first, then predicate\n * matchers in order. A matcher that throws is treated as a miss and sets\n * `matcherThrew`, so a caller can distinguish a genuine miss from a broken\n * matcher.\n */\nexport function resolveByCodeThenPredicate<T>(\n  error: unknown,\n  byCode: ReadonlyMap<string, T>,\n  predicates: readonly PredicateEntry<T>[],\n): CodeResolution<T> {\n  const code = readErrorCode(error);\n  if (code !== undefined) {\n    const value = byCode.get(code);\n    if (value !== undefined) {\n      return { found: true, via: \"code\", value, matcherThrew: false };\n    }\n  }\n\n  let matcherThrew = false;\n  for (const { match, value } of predicates) {\n    try {\n      if (match(error)) {\n        return { found: true, via: \"predicate\", value, matcherThrew };\n      }\n    } catch {\n      matcherThrew = true;\n    }\n  }\n\n  return { found: false, matcherThrew };\n}\n","/**\n * Shared RFC 9457 / HTTP helpers. One definition of \"a valid problem status\", \"a\n * usable type/title string\", and the problem media type, reused across the\n * public-error pipeline (projection, catalog registration, and the transport\n * stage) so the rules cannot drift between them.\n */\n\n/** Media type for RFC 9457 JSON problem details. */\nexport const PROBLEM_DETAILS_JSON = \"application/problem+json\" as const;\n\n/** True for an integer HTTP status in the RFC 9457 range [100, 599]. */\nexport function isHttpStatusCode(value: unknown): value is number {\n  return (\n    typeof value === \"number\" &&\n    Number.isInteger(value) &&\n    value >= 100 &&\n    value <= 599\n  );\n}\n\n/** True for a non-empty string (an RFC 9457 `type` URI reference, or a code). */\nexport function isNonEmptyString(value: unknown): value is string {\n  return typeof value === \"string\" && value.length > 0;\n}\n\n/** True for a non-negative integer, the delay-seconds form of `Retry-After`. */\nexport function isRetryAfterSeconds(value: unknown): value is number {\n  return typeof value === \"number\" && Number.isInteger(value) && value >= 0;\n}\n","import type { LocalizedMessageSet } from \"./LocalizedMessageSet.js\";\nimport { resolveByCodeThenPredicate } from \"../utils/error-resolution.js\";\nimport type { PredicateEntry } from \"../utils/error-resolution.js\";\nimport {\n  isHttpStatusCode,\n  isNonEmptyString,\n} from \"../utils/problem-validation.js\";\nimport type {\n  OnProject,\n  ProjectionOutcome,\n  PublicError,\n  PublicErrorDescriptor,\n} from \"./types.js\";\n\n/** A descriptor with its types erased, as stored and returned by the catalog. */\ntype AnyDescriptor = PublicErrorDescriptor<unknown, unknown>;\n\n/**\n * The static wire metadata of a public code, as read by {@link toProblem}:\n * status, the RFC 9457 type, and the static developer-facing title.\n */\nexport type Transport = {\n  readonly status: number;\n  readonly type?: string;\n  /** Static, developer-facing problem-type summary (RFC 9457 `title`). */\n  readonly title?: string;\n};\n\n/** Transport plus the curated category, kept internal for the conflict check. */\ntype StoredTransport = Transport & { readonly category?: string };\n\n/**\n * The outcome of resolving an error against the catalog. `matcherThrew` lets a\n * caller distinguish a genuine miss from a broken matcher, mirroring the\n * presentation registry.\n */\nexport type CatalogResolution =\n  | {\n      readonly found: true;\n      readonly via: \"code\" | \"predicate\";\n      readonly descriptor: AnyDescriptor;\n      readonly matcherThrew: boolean;\n    }\n  | { readonly found: false; readonly matcherThrew: boolean };\n\n/**\n * The single source of truth: one descriptor per public error code, addressable\n * both by the internal error `code`/predicate (for {@link project}) and by\n * public code (for {@link toProblem}'s transport facet and {@link localize}'s\n * messages). Unifies what used to be a registry (messages/details) plus a\n * separate adapter map (status/type), so the two cannot drift.\n *\n * Resolution order matches the presentation registry: exact internal `code`,\n * then predicate matchers in registration order, then a miss (the `fallback`).\n */\nexport class PublicErrorCatalog<TPublicCode extends string = string> {\n  readonly #byCode = new Map<string, AnyDescriptor>();\n  readonly #predicates: Array<PredicateEntry<AnyDescriptor>> = [];\n  readonly #transportByPublicCode = new Map<string, StoredTransport>();\n  readonly #messagesByPublicCode = new Map<string, LocalizedMessageSet>();\n  readonly #onProject: OnProject | undefined;\n  readonly #categories: ReadonlySet<string> | undefined;\n\n  /** The generic descriptor used for any unmatched error. */\n  public readonly fallback: AnyDescriptor;\n\n  public constructor(options: {\n    fallback: PublicErrorDescriptor<never, never, TPublicCode>;\n    /** Fire-and-forget observer invoked once per {@link project} through this catalog. */\n    onProject?: OnProject;\n    /**\n     * Optional closed vocabulary for the advisory public `category`. When given,\n     * every descriptor's `category` must be a member, validated at registration\n     * to prevent drift. `category` remains advisory: branch on `publicCode`.\n     */\n    categories?: readonly string[];\n  }) {\n    this.fallback = options.fallback as AnyDescriptor;\n    this.#onProject = options.onProject;\n    this.#categories =\n      options.categories !== undefined\n        ? new Set(options.categories)\n        : undefined;\n    this.#index(this.fallback);\n    if (\n      this.#categories !== undefined &&\n      this.fallback.category === undefined\n    ) {\n      throw new Error(\n        \"PublicErrorCatalog: the fallback must declare a category when categories are declared; it is the bucket a client uses for codes it does not recognize.\",\n      );\n    }\n  }\n\n  /**\n   * Invokes the configured {@link OnProject} observer, swallowing any error so\n   * telemetry can never break projection totality. Called by `project`.\n   */\n  public observeProjection(\n    error: unknown,\n    view: PublicError,\n    outcome: ProjectionOutcome,\n  ): void {\n    if (this.#onProject === undefined) return;\n    try {\n      this.#onProject(error, view, outcome);\n    } catch {\n      // Telemetry must never break totality.\n    }\n  }\n\n  /**\n   * Registers a descriptor keyed by an exact internal error `code`. Returns a\n   * catalog widened with the new public code, so a chain of registrations\n   * accumulates the public-code union for end-to-end typing.\n   */\n  public registerByCode<\n    TError = unknown,\n    TDetails = never,\n    const TNewCode extends string = string,\n  >(\n    code: string,\n    descriptor: PublicErrorDescriptor<TError, TDetails, TNewCode>,\n  ): PublicErrorCatalog<TPublicCode | TNewCode> {\n    if (this.#byCode.has(code)) {\n      throw new Error(\n        `PublicErrorCatalog: code \"${code}\" is already registered.`,\n      );\n    }\n    this.#byCode.set(code, descriptor as AnyDescriptor);\n    this.#index(descriptor as AnyDescriptor);\n    return this as unknown as PublicErrorCatalog<TPublicCode | TNewCode>;\n  }\n\n  /** Registers a descriptor guarded by a type-guard matcher, tried after code matches. */\n  public register<\n    TError,\n    TDetails = never,\n    const TNewCode extends string = string,\n  >(entry: {\n    match: (error: unknown) => error is TError;\n    descriptor: PublicErrorDescriptor<TError, TDetails, TNewCode>;\n  }): PublicErrorCatalog<TPublicCode | TNewCode> {\n    this.#predicates.push({\n      match: entry.match as (error: unknown) => boolean,\n      value: entry.descriptor as AnyDescriptor,\n    });\n    this.#index(entry.descriptor as AnyDescriptor);\n    return this as unknown as PublicErrorCatalog<TPublicCode | TNewCode>;\n  }\n\n  /** Resolves the descriptor for `error`, or a miss. */\n  public resolve(error: unknown): CatalogResolution {\n    const resolution = resolveByCodeThenPredicate(\n      error,\n      this.#byCode,\n      this.#predicates,\n    );\n    return resolution.found\n      ? {\n          found: true,\n          via: resolution.via,\n          descriptor: resolution.value,\n          matcherThrew: resolution.matcherThrew,\n        }\n      : { found: false, matcherThrew: resolution.matcherThrew };\n  }\n\n  /**\n   * The static wire metadata (status/type/title) for a registered public code,\n   * or `undefined` if the code is not registered (including the fallback, which\n   * is indexed at construction). An unknown code is a foreign/stale view that\n   * must not be paired with this catalog's fallback status; the caller decides.\n   */\n  public transportFor(publicCode: string): Transport | undefined {\n    return this.#transportByPublicCode.get(publicCode);\n  }\n\n  /** The localized messages registered for a public code, if any. */\n  public messagesFor(publicCode: string): LocalizedMessageSet | undefined {\n    return this.#messagesByPublicCode.get(publicCode);\n  }\n\n  /**\n   * Asserts that every code in `knownCodes` has a `registerByCode` descriptor.\n   * An opt-in completeness check for the consumer's composition root.\n   */\n  public assertCoverage(knownCodes: readonly string[]): void {\n    const missing = knownCodes.filter((code) => !this.#byCode.has(code));\n    if (missing.length > 0) {\n      throw new Error(\n        `PublicErrorCatalog: no descriptor registered for code(s): ${missing.join(\", \")}.`,\n      );\n    }\n  }\n\n  #index(descriptor: AnyDescriptor): void {\n    if (!isNonEmptyString(descriptor.publicCode)) {\n      throw new Error(\n        \"PublicErrorCatalog: descriptor has an empty or invalid publicCode.\",\n      );\n    }\n    if (!isHttpStatusCode(descriptor.status)) {\n      throw new Error(\n        `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" has an invalid status; expected an integer in [100, 599], got ${String(descriptor.status)}.`,\n      );\n    }\n    if (descriptor.type !== undefined && !isNonEmptyString(descriptor.type)) {\n      throw new Error(\n        `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" has an empty type.`,\n      );\n    }\n    if (descriptor.category !== undefined) {\n      if (!isNonEmptyString(descriptor.category)) {\n        throw new Error(\n          `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" has an empty category.`,\n        );\n      }\n      if (\n        this.#categories !== undefined &&\n        !this.#categories.has(descriptor.category)\n      ) {\n        throw new Error(\n          `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" uses category \"${descriptor.category}\" not in the declared categories.`,\n        );\n      }\n    }\n    const transport: StoredTransport = {\n      status: descriptor.status,\n      ...(descriptor.type !== undefined && { type: descriptor.type }),\n      ...(descriptor.title !== undefined && { title: descriptor.title }),\n      ...(descriptor.category !== undefined && {\n        category: descriptor.category,\n      }),\n    };\n    const prior = this.#transportByPublicCode.get(descriptor.publicCode);\n    if (\n      prior !== undefined &&\n      (prior.status !== transport.status ||\n        prior.type !== transport.type ||\n        prior.title !== transport.title ||\n        prior.category !== transport.category)\n    ) {\n      throw new Error(\n        `PublicErrorCatalog: publicCode \"${descriptor.publicCode}\" mapped to conflicting transport (status, type, title, or category).`,\n      );\n    }\n    this.#transportByPublicCode.set(descriptor.publicCode, transport);\n    if (descriptor.userMessages !== undefined) {\n      const priorMessages = this.#messagesByPublicCode.get(\n        descriptor.publicCode,\n      );\n      if (\n        priorMessages !== undefined &&\n        !sameMessages(priorMessages, descriptor.userMessages)\n      ) {\n        throw new Error(\n          `PublicErrorCatalog: publicCode \"${descriptor.publicCode}\" mapped to conflicting userMessages.`,\n        );\n      }\n      this.#messagesByPublicCode.set(\n        descriptor.publicCode,\n        descriptor.userMessages,\n      );\n    }\n  }\n}\n\n/**\n * Content equality for two message sets: same `baseLocale` and the same\n * locale-to-message entries. One public code is one user-facing message, so two\n * internal codes mapping to it must agree (or be different public codes).\n */\nfunction sameMessages(a: LocalizedMessageSet, b: LocalizedMessageSet): boolean {\n  if (a === b) return true;\n  if (a.baseLocale !== b.baseLocale) return false;\n  const aEntries = a.entries();\n  const bEntries = b.entries();\n  if (aEntries.length !== bEntries.length) return false;\n  const bByLocale = new Map(bEntries);\n  for (const [locale, message] of aEntries) {\n    if (bByLocale.get(locale) !== message) return false;\n  }\n  return true;\n}\n\n/** The union of public codes a {@link PublicErrorCatalog} can produce. */\nexport type PublicCodeOf<TCatalog> =\n  TCatalog extends PublicErrorCatalog<infer TPublicCode> ? TPublicCode : never;\n\n/**\n * Builds a catalog whose public-code union is inferred from the fallback (and\n * grows as you chain `registerByCode`/`register`). Prefer this over `new` when\n * you want the UI to switch exhaustively on `code` at compile time; `new`\n * leaves the union as the open `string`.\n */\nexport function definePublicErrors<const TCode extends string>(options: {\n  fallback: PublicErrorDescriptor<never, never, TCode>;\n  onProject?: OnProject;\n  categories?: readonly string[];\n}): PublicErrorCatalog<TCode> {\n  return new PublicErrorCatalog<TCode>(options);\n}\n","import { isRetryAfterSeconds } from \"../utils/problem-validation.js\";\nimport type { PublicErrorCatalog } from \"./PublicErrorCatalog.js\";\nimport type {\n  FieldFault,\n  ProjectionOutcome,\n  ProjectionStatus,\n  PublicError,\n  PublicErrorDescriptor,\n} from \"./types.js\";\n\n/**\n * Stage 1: curation as a security boundary. Turns an unknown technical error\n * into a curated, transport-neutral, message-free {@link PublicError}. Total\n * over `unknown`: an unmatched error degrades to the catalog's fallback rather\n * than leaking or throwing. Nothing of the error reaches the view automatically;\n * only declared (`category`/`retryable`) or explicitly projected\n * (`details`/`fields`) values appear, and a throwing projector is contained.\n *\n * Invokes the catalog's {@link OnProject} observer once, so a single place can\n * log the technical error alongside the emitted code and outcome.\n */\nexport function project<TPublicCode extends string>(\n  catalog: PublicErrorCatalog<TPublicCode>,\n  error: unknown,\n): PublicError<unknown, TPublicCode> {\n  const resolution = catalog.resolve(error);\n  const descriptor = resolution.found\n    ? resolution.descriptor\n    : catalog.fallback;\n  const { view, projection } = projectCore(descriptor, error);\n\n  const outcome: ProjectionOutcome = resolution.found\n    ? { kind: \"matched\", via: resolution.via, projection }\n    : {\n        kind: \"fallback\",\n        reason: resolution.matcherThrew ? \"matcher_failed\" : \"no_match\",\n        projection,\n      };\n  catalog.observeProjection(error, view, outcome);\n\n  return view as PublicError<unknown, TPublicCode>;\n}\n\n/**\n * Catalog-free projection against a single descriptor the caller already chose.\n * The same curation rules as {@link project}, without resolution or the\n * observer: use this when you bring your own matching, or have no catalog.\n */\nexport function projectWithDescriptor<TCode extends string>(\n  descriptor: PublicErrorDescriptor<never, unknown, TCode>,\n  error: unknown,\n): PublicError<unknown, TCode> {\n  return projectCore(descriptor, error).view as PublicError<unknown, TCode>;\n}\n\nfunction projectCore(\n  descriptor: PublicErrorDescriptor<never, unknown, string>,\n  error: unknown,\n): { view: PublicError; projection: ProjectionStatus } {\n  const retryable = resolveRetryable(descriptor, error);\n  const retryAfter = resolveRetryAfter(descriptor, error);\n\n  let failed = false;\n  const onThrow = (): void => {\n    failed = true;\n  };\n  const details =\n    descriptor.projectDetails === undefined\n      ? undefined\n      : safeCall(descriptor.projectDetails, error, onThrow);\n  const fields =\n    descriptor.projectFields === undefined\n      ? undefined\n      : safeFields(descriptor.projectFields, error, onThrow);\n\n  const hasProjector =\n    descriptor.projectDetails !== undefined ||\n    descriptor.projectFields !== undefined;\n  const projection: ProjectionStatus = !hasProjector\n    ? \"none\"\n    : failed\n      ? \"failed\"\n      : \"succeeded\";\n\n  const view: PublicError = Object.freeze({\n    code: descriptor.publicCode,\n    ...(descriptor.category !== undefined && { category: descriptor.category }),\n    ...(retryable !== undefined && { retryable }),\n    ...(retryAfter !== undefined && { retryAfter }),\n    ...(details !== undefined && { details }),\n    ...(fields !== undefined && fields.length > 0 && { fields }),\n  });\n  return { view, projection };\n}\n\nfunction resolveRetryable(\n  descriptor: PublicErrorDescriptor<never, unknown, string>,\n  error: unknown,\n): boolean | undefined {\n  if (descriptor.projectRetryable !== undefined) {\n    try {\n      const projected = descriptor.projectRetryable(error as never);\n      if (typeof projected === \"boolean\") return projected;\n    } catch {\n      // Fall through to the declared default; totality must hold.\n    }\n  }\n  return descriptor.retryable;\n}\n\nfunction resolveRetryAfter(\n  descriptor: PublicErrorDescriptor<never, unknown, string>,\n  error: unknown,\n): number | undefined {\n  if (descriptor.projectRetryAfter === undefined) return undefined;\n  try {\n    const seconds = descriptor.projectRetryAfter(error as never);\n    return isRetryAfterSeconds(seconds) ? seconds : undefined;\n  } catch {\n    // A retry hint must never break projection totality.\n    return undefined;\n  }\n}\n\nfunction safeCall(\n  fn: (error: never) => unknown,\n  error: unknown,\n  onThrow: () => void,\n): unknown {\n  try {\n    return fn(error as never);\n  } catch {\n    onThrow();\n    return undefined;\n  }\n}\n\nfunction safeFields(\n  fn: (error: never) => readonly FieldFault[],\n  error: unknown,\n  onThrow: () => void,\n): readonly FieldFault[] | undefined {\n  try {\n    const fields = fn(error as never);\n    // A non-array or a malformed entry is a projector bug, not \"no faults\":\n    // drop the member and mark the projection failed for telemetry.\n    if (!Array.isArray(fields) || !fields.every(isFieldFault)) {\n      onThrow();\n      return undefined;\n    }\n    // Curated copy: exactly { field, code } per fault, frozen. Strips foreign\n    // extras a projector passed through by reference (a fault is a closed\n    // shape, unlike details) and decouples the view from the projector's\n    // objects, so later mutation of internal state cannot reach it.\n    return Object.freeze(\n      fields.map((fault) =>\n        Object.freeze({ field: fault.field, code: fault.code }),\n      ),\n    );\n  } catch {\n    onThrow();\n    return undefined;\n  }\n}\n\nfunction isFieldFault(value: unknown): value is FieldFault {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    typeof (value as FieldFault).field === \"string\" &&\n    typeof (value as FieldFault).code === \"string\"\n  );\n}\n","import type { LocalizedMessageSet } from \"./LocalizedMessageSet.js\";\nimport { resolveUserMessage } from \"./LocaleResolver.js\";\nimport type { LocalizedPublicError, PublicError } from \"./types.js\";\n\n/**\n * Stage 2: localization, deliberately optional and orthogonal. Attaches human\n * text to a {@link PublicError}, resolving `messages` against ordered locale\n * preferences. The `messages` set is keyed on the public code by the caller: a\n * backend passes `catalog.messagesFor(view.code)`, a client passes its own\n * catalog for the same public code. A client-localizing app simply never calls\n * this stage and renders text from `view.code` itself.\n */\nexport function localize<TDetails, TCode extends string = string>(\n  view: PublicError<TDetails, TCode>,\n  messages: LocalizedMessageSet,\n  options?: { locales?: readonly string[] },\n): LocalizedPublicError<TDetails, TCode> {\n  // `messages` is typed non-optional, but `catalog.messagesFor(code)` returns\n  // `undefined` for a public code with no userMessages. A caller that forces it\n  // through (a `!` assertion) would otherwise hit a cryptic deref inside the\n  // resolver; surface a clear contract violation instead.\n  if (messages == null) {\n    throw new TypeError(\n      \"localize: a LocalizedMessageSet is required. catalog.messagesFor(code) \" +\n        \"returns undefined for a public code with no userMessages; guard it and \" +\n        \"send the message-free view, or pass a fallback set.\",\n    );\n  }\n  const resolved = resolveUserMessage(messages, options);\n  // Frozen to match project()'s view: all three stages give the same guarantee.\n  return Object.freeze({\n    ...view,\n    message: resolved.message,\n    locale: resolved.locale,\n  });\n}\n","/**\n * Shared JSON-safety helper. A value that crosses a wire (an HTTP body, an RPC\n * boundary, `postMessage`) must survive `JSON.stringify` losslessly and must not\n * carry a hostile prototype. This module is the single clone-and-freeze\n * implementation for the public-error transport stage (`toProblem`), so the\n * wire-safety guarantee lives at exactly one place.\n */\n\n/** The subset of values that round-trips through JSON without loss. */\nexport type JsonSafeValue =\n  | null\n  | boolean\n  | number\n  | string\n  | readonly JsonSafeValue[]\n  | { readonly [key: string]: JsonSafeValue };\n\n/** True for a value with `Object.prototype` or a null prototype (a plain record). */\nexport function isPlainObject(\n  value: unknown,\n): value is Record<string, unknown> {\n  if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n    return false;\n  }\n  const prototype = Object.getPrototypeOf(value) as unknown;\n  return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Total-node budget for one {@link cloneJsonSafe} call. Cycles are rejected,\n * but shared (DAG) references are cloned once per reference, so a small input\n * can legally expand exponentially (`{a, b}` doubling per level). The budget\n * turns that CPU-exhaustion shape into the ordinary \"not JSON-safe\" failure\n * the callers already handle, and sits far above any sane wire payload.\n */\nconst MAX_CLONE_NODES = 100_000;\n\n/**\n * Deep-clones `value` into a frozen, JSON-safe structure, or throws if any part\n * is not JSON-safe: a non-finite number (`NaN`/`Infinity`), a function, a\n * symbol, a `Date`/`Map`/`Set` or other exotic object, a symbol-keyed object, a\n * sparse array, a circular reference, or a value expanding past\n * {@link MAX_CLONE_NODES} total nodes (a shared-reference blowup). The returned\n * clone is deeply frozen and decoupled from the source, so it is safe to place\n * on a wire object that may be shared or mutated afterward.\n */\nexport function cloneJsonSafe(value: unknown): JsonSafeValue {\n  return cloneInto(value, new Set(), { nodes: 0 });\n}\n\nfunction cloneInto(\n  value: unknown,\n  seen: Set<object>,\n  state: { nodes: number },\n): JsonSafeValue {\n  if (++state.nodes > MAX_CLONE_NODES) {\n    throw new Error(\"value is not JSON-safe\");\n  }\n  if (\n    value === null ||\n    typeof value === \"string\" ||\n    typeof value === \"boolean\"\n  ) {\n    return value;\n  }\n  if (typeof value === \"number\") {\n    if (Number.isFinite(value)) return value;\n    throw new Error(\"value is not JSON-safe\");\n  }\n  if (typeof value !== \"object\" || seen.has(value)) {\n    throw new Error(\"value is not JSON-safe\");\n  }\n\n  seen.add(value);\n  try {\n    if (Array.isArray(value)) {\n      for (let index = 0; index < value.length; index++) {\n        if (!Object.prototype.hasOwnProperty.call(value, index)) {\n          throw new Error(\"value is not JSON-safe\");\n        }\n      }\n      return Object.freeze(\n        value.map((item) => cloneInto(item, seen, state)),\n      ) as readonly JsonSafeValue[];\n    }\n\n    if (\n      !isPlainObject(value) ||\n      Object.getOwnPropertySymbols(value).length > 0\n    ) {\n      throw new Error(\"value is not JSON-safe\");\n    }\n    const clone = Object.create(null) as Record<string, JsonSafeValue>;\n    for (const [key, item] of Object.entries(value)) {\n      clone[key] = cloneInto(item, seen, state);\n    }\n    return Object.freeze(clone);\n  } finally {\n    seen.delete(value);\n  }\n}\n","import { cloneJsonSafe } from \"../utils/json-safe.js\";\nimport type { JsonSafeValue } from \"../utils/json-safe.js\";\nimport {\n  isHttpStatusCode,\n  isNonEmptyString,\n  isRetryAfterSeconds,\n  PROBLEM_DETAILS_JSON,\n} from \"../utils/problem-validation.js\";\nimport { PublicErrorCatalog } from \"./PublicErrorCatalog.js\";\nimport type { Transport } from \"./PublicErrorCatalog.js\";\nimport type { FieldFault, LocalizedPublicError, PublicError } from \"./types.js\";\n\nexport { PROBLEM_DETAILS_JSON };\n\n/** A dynamic body member dropped because it was not JSON-safe. */\nexport type OmittedMember = \"details\" | \"fields\" | \"extensions\";\n\n/** Body members the adapter owns; an extension may not collide with them. */\nconst RESERVED_BODY_FIELDS = [\n  \"type\",\n  \"title\",\n  \"status\",\n  \"detail\",\n  \"instance\",\n  \"code\",\n  \"category\",\n  \"retryable\",\n  \"retryAfter\",\n  \"fields\",\n  \"details\",\n] as const;\ntype ReservedBodyField = (typeof RESERVED_BODY_FIELDS)[number];\n\n/**\n * Keys an extension may never carry: every reserved body member, plus the\n * pollution-vector names that would otherwise serialize onto the body and revive\n * as `__proto__`/`constructor`/`prototype` own keys on a non-hardened downstream\n * `JSON.parse`. The body is null-prototype, so this is defense in depth.\n */\nconst FORBIDDEN_EXTENSION_KEYS: ReadonlySet<string> = new Set<string>([\n  ...RESERVED_BODY_FIELDS,\n  \"__proto__\",\n  \"constructor\",\n  \"prototype\",\n]);\n\n/** Every extension value must be JSON-safe; a non-JSON-safe field is `never`. */\ntype JsonSafeExtensionShape<TExtensions extends object> = {\n  readonly [K in keyof TExtensions]: Pick<TExtensions, K> extends Required<\n    Pick<TExtensions, K>\n  >\n    ? TExtensions[K] extends JsonSafeValue\n      ? TExtensions[K]\n      : never\n    : Exclude<TExtensions[K], undefined> extends JsonSafeValue\n      ? TExtensions[K]\n      : never;\n};\n\n/** Extensions must be string-keyed (symbol/number keys are rejected). */\ntype StringKeyedExtensionShape<TExtensions extends object> =\n  Exclude<keyof TExtensions, string> extends never ? unknown : never;\n\n/**\n * Per-occurrence members added while mapping one view to a problem. `extensions`\n * are additional top-level body members; they are compile-time constrained to be\n * JSON-safe, string-keyed, and free of reserved field names, and re-validated at\n * runtime (a non-JSON-safe or colliding set drops to `outcome.omitted`).\n */\nexport type ToProblemContext<\n  TExtensions extends object = Record<never, never>,\n> = {\n  /** RFC 9457 occurrence URI. */\n  readonly instance?: string;\n  /** RFC 9457 occurrence-specific explanation (distinct from the per-type title). */\n  readonly detail?: string;\n  /**\n   * Retry delay in whole seconds, overriding the view's `retryAfter`. For a\n   * boundary that knows the value (a rate limiter) rather than the error. A\n   * non-integer/negative value is ignored.\n   */\n  readonly retryAfter?: number;\n  /** Additional JSON-safe top-level body members, keyed by a non-reserved name. */\n  readonly extensions?: TExtensions &\n    JsonSafeExtensionShape<TExtensions> &\n    StringKeyedExtensionShape<TExtensions> & {\n      readonly [K in ReservedBodyField]?: never;\n    };\n};\n\n/**\n * An RFC 9457 problem body. `type`/`title`/`status`/`detail`/`instance` are the\n * reserved members (`title` present only when a message was localized);\n * `code`/`category`/`retryable`/`fields`/`details` are documented extension\n * members the adapter writes by default. The body has a null prototype and is\n * deeply frozen, so it is safe to serialize and cannot carry prototype\n * pollution.\n */\nexport type ProblemDetails<\n  TDetails = unknown,\n  TCode extends string = string,\n  TExtensions extends object = Record<never, never>,\n> = {\n  readonly type?: string;\n  readonly title?: string;\n  readonly status: number;\n  readonly detail?: string;\n  readonly instance?: string;\n  readonly code: TCode;\n  readonly category?: string;\n  readonly retryable?: boolean;\n  readonly retryAfter?: number;\n  readonly fields?: readonly FieldFault[];\n  readonly details?: TDetails;\n} & Readonly<Partial<TExtensions>>;\n\n/** Mapping diagnostics retained outside the serialized body. */\nexport type ProblemDetailsOutcome = {\n  /** Dynamic members dropped because they were not JSON-safe. */\n  readonly omitted: readonly OmittedMember[];\n};\n\n/** Framework-neutral status, headers, body, and diagnostics. */\nexport type ProblemDetailsResult<\n  TDetails = unknown,\n  TCode extends string = string,\n  TExtensions extends object = Record<never, never>,\n> = {\n  readonly status: number;\n  readonly headers: Readonly<{\n    \"content-type\": typeof PROBLEM_DETAILS_JSON;\n    \"content-language\"?: string;\n    \"retry-after\"?: string;\n  }>;\n  readonly body: ProblemDetails<TDetails, TCode, TExtensions>;\n  readonly outcome: ProblemDetailsOutcome;\n};\n\n/**\n * Stage 3: transport. Maps a (possibly localized) {@link PublicError} to an RFC\n * 9457 result. The transport `source` is either a {@link PublicErrorCatalog}\n * (looks up `status`/`type` by public code) or an explicit {@link Transport}\n * `{ status, type? }` for catalog-free use; the machine members ride from the\n * view. A `title` and a `content-language` header appear only when the view was\n * localized, so the structure-only path is a first-class, RFC-valid response.\n *\n * This is the wire boundary: `details` and `fields` are deep-cloned into a\n * frozen, JSON-safe structure (a `Date`, `BigInt`, circular reference, or other\n * non-serializable value drops that member and records it in `outcome.omitted`\n * rather than throwing or leaking a value the next serializer would choke on).\n */\nexport function toProblem<\n  TDetails,\n  TCode extends string = string,\n  const TExtensions extends object = Record<never, never>,\n>(\n  source: PublicErrorCatalog | Transport,\n  view: PublicError<TDetails, TCode> | LocalizedPublicError<TDetails, TCode>,\n  context?: ToProblemContext<TExtensions>,\n): ProblemDetailsResult<TDetails, TCode, TExtensions> {\n  if (!isNonEmptyString(view.code)) {\n    throw new Error(\"toProblem: view.code must be a non-empty string.\");\n  }\n  const transport =\n    source instanceof PublicErrorCatalog\n      ? transportOrThrow(source, view.code)\n      : assertValidTransport(source);\n  const localized = hasMessage(view) ? view : undefined;\n  const omitted: OmittedMember[] = [];\n\n  // A localized end-user message wins; otherwise the static developer-facing\n  // title. RFC 9457 title is optional, so a client-localizing app that sets\n  // neither simply emits no title.\n  const title = localized !== undefined ? localized.message : transport.title;\n\n  // Each candidate is validated independently, so an invalid boundary override\n  // falls back to the view's still-valid hint rather than dropping both.\n  const retryAfter = isRetryAfterSeconds(context?.retryAfter)\n    ? context.retryAfter\n    : isRetryAfterSeconds(view.retryAfter)\n      ? view.retryAfter\n      : undefined;\n\n  const details = jsonSafeOrOmit(view.details, \"details\", omitted);\n  // Match project(): an empty fields array is not a member.\n  const rawFields =\n    view.fields !== undefined && view.fields.length > 0\n      ? view.fields\n      : undefined;\n  const fields = jsonSafeOrOmit(rawFields, \"fields\", omitted);\n  const extensions = safeExtensions(context?.extensions, omitted);\n\n  const body = Object.freeze(\n    Object.assign(Object.create(null) as Record<string, unknown>, {\n      // Extensions first: the reserved members below always win a collision.\n      ...extensions,\n      ...(transport.type !== undefined && { type: transport.type }),\n      // typeof guard, not `!== undefined`: a cast/JSON-revived non-string\n      // descriptor or transport `title` must not reach the wire body, the same\n      // wire-safety the detail/instance guards below enforce.\n      ...(typeof title === \"string\" && { title }),\n      status: transport.status,\n      // The TS type already constrains these to strings; the runtime guard keeps\n      // an untyped caller (an `as` cast, a value from JSON.parse) from writing a\n      // non-string, non-RFC-9457 value straight onto the wire body.\n      ...(typeof context?.detail === \"string\" && { detail: context.detail }),\n      ...(typeof context?.instance === \"string\" && {\n        instance: context.instance,\n      }),\n      code: view.code,\n      ...(typeof view.category === \"string\" && { category: view.category }),\n      ...(typeof view.retryable === \"boolean\" && { retryable: view.retryable }),\n      ...(retryAfter !== undefined && { retryAfter }),\n      ...(fields !== undefined && { fields }),\n      ...(details !== undefined && { details }),\n    }),\n  ) as ProblemDetails<TDetails, TCode, TExtensions>;\n\n  const headers = Object.freeze({\n    \"content-type\": PROBLEM_DETAILS_JSON,\n    ...(localized !== undefined && { \"content-language\": localized.locale }),\n    ...(retryAfter !== undefined && { \"retry-after\": String(retryAfter) }),\n  });\n\n  const outcome: ProblemDetailsOutcome = Object.freeze({\n    omitted: Object.freeze(omitted),\n  });\n\n  return Object.freeze({ status: transport.status, headers, body, outcome });\n}\n\nfunction jsonSafeOrOmit(\n  value: unknown,\n  member: OmittedMember,\n  omitted: OmittedMember[],\n): unknown {\n  if (value === undefined) return undefined;\n  try {\n    return cloneJsonSafe(value);\n  } catch {\n    omitted.push(member);\n    return undefined;\n  }\n}\n\n/**\n * Validates and clones the explicit `extensions`: a plain object whose own keys\n * are all strings, none forbidden ({@link FORBIDDEN_EXTENSION_KEYS}), and whose\n * values are all JSON-safe. The whole set is dropped (recorded in\n * `outcome.omitted`) if any key collides or any value is not JSON-safe, so a bad\n * set never partially leaks onto the body. Keys are screened on the raw input\n * before the clone, so a `__proto__` own key (e.g. from `JSON.parse`) is rejected\n * rather than serialized; `cloneJsonSafe` only carries those screened string keys\n * through, so no second key check is needed.\n */\nfunction safeExtensions(\n  raw: unknown,\n  omitted: OmittedMember[],\n): Record<string, JsonSafeValue> | undefined {\n  if (raw === undefined) return undefined;\n  try {\n    if (\n      typeof raw !== \"object\" ||\n      raw === null ||\n      Array.isArray(raw) ||\n      Reflect.ownKeys(raw).some(\n        (key) => typeof key !== \"string\" || FORBIDDEN_EXTENSION_KEYS.has(key),\n      )\n    ) {\n      throw new Error(\"invalid extensions\");\n    }\n    return cloneJsonSafe(raw) as Record<string, JsonSafeValue>;\n  } catch {\n    omitted.push(\"extensions\");\n    return undefined;\n  }\n}\n\nfunction hasMessage<TDetails, TCode extends string>(\n  view: PublicError<TDetails, TCode> | LocalizedPublicError<TDetails, TCode>,\n): view is LocalizedPublicError<TDetails, TCode> {\n  const partial = view as Partial<LocalizedPublicError<TDetails, TCode>>;\n  // Both are required: a message without a locale would emit\n  // `content-language: undefined`, so a partial view stays unlocalized.\n  return (\n    typeof partial.message === \"string\" && typeof partial.locale === \"string\"\n  );\n}\n\n/**\n * Resolves the transport for a registered public code, or throws. A code the\n * catalog does not know is a foreign/stale view; emitting the fallback status\n * would pair the view's real code with a mismatched status, so the caller must\n * use an explicit transport instead.\n */\nfunction transportOrThrow(\n  catalog: PublicErrorCatalog,\n  publicCode: string,\n): Transport {\n  const transport = catalog.transportFor(publicCode);\n  if (transport === undefined) {\n    throw new Error(\n      `toProblem: public code \"${publicCode}\" is not registered in this catalog; pass an explicit transport for a foreign view.`,\n    );\n  }\n  return transport;\n}\n\n/**\n * Validates an explicit (catalog-free) transport at the boundary, since it\n * bypasses the catalog's registration-time checks. Returns it unchanged on\n * success.\n */\nfunction assertValidTransport(transport: Transport): Transport {\n  if (!isHttpStatusCode(transport.status)) {\n    throw new Error(\n      `toProblem: invalid transport status; expected an integer in [100, 599], got ${String(transport.status)}.`,\n    );\n  }\n  if (transport.type !== undefined && !isNonEmptyString(transport.type)) {\n    throw new Error(\n      \"toProblem: invalid transport type; expected a non-empty string.\",\n    );\n  }\n  return transport;\n}\n"]}