Skip to content
← Public packages

@kody/github

Call GitHub REST, GraphQL, and pull requests with a GitHub OAuth App or a personal access token.

FollowFork

Files

auth-options.ts

24 lines · 1.4 KB · TypeScript
/** Auth options removed in @kody/github 1.0.0. Passing any of them throws. */
export const REMOVED_AUTH_OPTIONS = ["secretName", "integrationName", "account"] as const

/**
 * Throw a clear error when a caller passes an auth option removed in 1.0.0.
 * Every helper now reads one credential slot named `github`; the caller picks
 * which credential fills it with the execute credentials map.
 */
export function rejectRemovedAuthOptions(input: unknown): void {
  if (!input || typeof input !== "object") return
  const record = input as Record<string, unknown>
  const passed = REMOVED_AUTH_OPTIONS.filter((key) => record[key] !== undefined && record[key] !== null)
  if (passed.length === 0) return
  const named =
    passed.map((key) => record[key]).find((value): value is string => typeof value === "string" && value.trim().length > 0)?.trim() ??
    "<credential name>"
  throw new Error(
    `@kody/github 1.0.0 removed the ${passed.map((key) => `"${key}"`).join(", ")} option${passed.length > 1 ? "s" : ""}. ` +
      `Every helper now reads one credential slot named "github", which a personal access token or a GitHub OAuth connection can fill. ` +
      `Pick the credential with the execute credentials map instead: { credentials: { github: "${named}" } } on execute, ` +
      `or --credential github=${named} with the CLI. ` +
      `A package that imports @kody/github can set a default mapping for its "github" need on the package's Credentials tab.`,
  )
}