Open History to see the last commit
1import {
2 managedNightlyDeniedMessage,
3 managedUpdatesMessage,
4 type ManagedPolicyDocument,
5} from "@t3tools/contracts";
6import type { CliReleaseChannel } from "@t3tools/shared/cliRelease";
7
8/**
9 * Why the managed policy refuses an update a user or maintainer asked for, or `undefined` when it
10 * allows it. The server never updates on its own, so `auto` allows every explicit request.
11 * Pass `targetChannel` when the caller picks the release; the desktop app gates its own channel.
12 */
13export function managedUpdateRefusal(
14 document: ManagedPolicyDocument | undefined,
15 targetChannel?: CliReleaseChannel,
16): string | undefined {
17 const updates = document?.limits?.updates;
18 if (document === undefined || updates === undefined) return undefined;
19 if (updates.mode === "off") return managedUpdatesMessage(document.organization);
20 if (updates.allowNightly === false && targetChannel !== undefined && targetChannel !== "stable") {
21 return managedNightlyDeniedMessage(document.organization);
22 }
23 return undefined;
24}