Edits history of script submission #16157 for ' Override a site space customization settings (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Override a site space customization settings
     *
     */
    export async function main(
      auth: Gitbook,
      organizationId: string,
      siteId: string,
      siteSpaceId: string,
      body: {
        title?: string;
        styling?: {
          theme?: "clean" | "muted" | "bold" | "gradient";
          primaryColor?: { light: string; dark: string };
          infoColor?: { light: string; dark: string };
          successColor?: { light: string; dark: string };
          warningColor?: { light: string; dark: string };
          dangerColor?: { light: string; dark: string };
          tint?: { color: { light: string; dark: string } };
          corners?: "straight" | "rounded" | "circular";
          depth?: "subtle" | "flat";
          links?: "default" | "accent";
          icons?: "regular" | "solid" | "duotone" | "light" | "thin";
          sidebar?: {
            background?: "default" | "filled";
            list?: "default" | "pill" | "line";
          };
          search?: "subtle" | "prominent";
          background?: "plain" | "match";
        };
        internationalization?: {
          locale:
            | "en"
            | "fr"
            | "es"
            | "zh"
            | "ja"
            | "de"
            | "nl"
            | "no"
            | "pt-br"
            | "ru";
        };
        favicon?:
          | {}
          | { icon: { light: string; dark: string } }
          | { emoji: string };
        announcement?: {
          enabled: false | true;
          message: string;
          link?: {
            title: string;
            to:
              | { kind: "file"; file: string }
              | { kind: "url"; url: string }
              | { kind: "page"; page: string; space?: string }
              | { kind: "anchor"; anchor: string; space?: string; page?: string }
              | { kind: "user"; user: string }
              | { kind: "collection"; collection: string }
              | { kind: "space"; space: string }
              | {
                  kind: "reusable-content";
                  reusableContent: string;
                  space?: string;
                }
              | { kind: "openapi"; spec: string };
          };
          style: "info" | "warning" | "danger" | "success";
        };
        header?: {
          preset?: "bold" | "default" | "contrast" | "custom" | "none";
          logo?: { light: string; dark: string };
          backgroundColor?: { light: string; dark: string };
          linkColor?: { light: string; dark: string };
          links?: {
            title: string;
            style?: "link" | "button-primary" | "button-secondary";
            to:
              | { kind: "file"; file: string }
              | { kind: "url"; url: string }
              | { kind: "page"; page: string; space?: string }
              | { kind: "anchor"; anchor: string; space?: string; page?: string }
              | { kind: "user"; user: string }
              | { kind: "collection"; collection: string }
              | { kind: "space"; space: string }
              | {
                  kind: "reusable-content";
                  reusableContent: string;
                  space?: string;
                }
              | { kind: "openapi"; spec: string };
            links: {
              title: string;
              to:
                | { kind: "file"; file: string }
                | { kind: "url"; url: string }
                | { kind: "page"; page: string; space?: string }
                | { kind: "anchor"; anchor: string; space?: string; page?: string }
                | { kind: "user"; user: string }
                | { kind: "collection"; collection: string }
                | { kind: "space"; space: string }
                | {
                    kind: "reusable-content";
                    reusableContent: string;
                    space?: string;
                  }
                | { kind: "openapi"; spec: string };
            }[];
            condition?: string;
          }[];
        };
        footer?: {
          logo?: { light: string; dark: string };
          groups?: {
            title: string;
            links: {
              title: string;
              to:
                | { kind: "file"; file: string }
                | { kind: "url"; url: string }
                | { kind: "page"; page: string; space?: string }
                | { kind: "anchor"; anchor: string; space?: string; page?: string }
                | { kind: "user"; user: string }
                | { kind: "collection"; collection: string }
                | { kind: "space"; space: string }
                | {
                    kind: "reusable-content";
                    reusableContent: string;
                    space?: string;
                  }
                | { kind: "openapi"; spec: string };
            }[];
          }[];
          copyright?: string;
        };
        themes?: { default?: "light" | "dark"; toggeable?: false | true };
        pdf?: { enabled: false | true };
        feedback?: { enabled: false | true };
        git?: { showEditLink: false | true };
        externalLinks?: { target: "self" | "blank" };
        pagination?: { enabled: false | true };
        trademark?: { enabled: false | true };
        privacyPolicy?: { url?: string };
        socialPreview?: { url?: string };
      },
    ) {
      const url = new URL(
        `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/site-spaces/${siteSpaceId}/customization`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago