Edits history of script submission #16205 for ' Update a site customization settings (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Update a site customization settings
     *
     */
    export async function main(
      auth: Gitbook,
      organizationId: string,
      siteId: string,
      body: {
        title?: string;
        styling: {
          theme: "clean" | "muted" | "bold" | "gradient";
          primaryColor: { light: string; dark: string };
          tint?: { color: { light: string; dark: string } };
          infoColor: { light: string; dark: string };
          successColor: { light: string; dark: string };
          warningColor: { light: string; dark: string };
          dangerColor: { light: string; dark: string };
          corners: "straight" | "rounded" | "circular";
          depth: "subtle" | "flat";
          links: "default" | "accent";
          font:
            | "ABCFavorit"
            | "Inter"
            | "Roboto"
            | "RobotoSlab"
            | "OpenSans"
            | "SourceSansPro"
            | "Lato"
            | "Ubuntu"
            | "Raleway"
            | "Merriweather"
            | "Overpass"
            | "NotoSans"
            | "IBMPlexSerif"
            | "Poppins"
            | "FiraSans"
            | {
                id: string;
                custom: false | true;
                fontFamily: string;
                fontFaces: {
                  weight: number;
                  sources: { url: string; format?: "woff2" | "woff" }[];
                }[];
              };
          monospaceFont:
            | "FiraCode"
            | "IBMPlexMono"
            | "JetBrainsMono"
            | "SourceCodePro"
            | "RobotoMono"
            | "SpaceMono"
            | "DMMono"
            | "Inconsolata"
            | {
                id: string;
                custom: false | true;
                fontFamily: string;
                fontFaces: {
                  weight: number;
                  sources: { url: string; format?: "woff2" | "woff" }[];
                }[];
              };
          background: "plain" | "match";
          icons: "regular" | "solid" | "duotone" | "light" | "thin";
          sidebar: {
            background: "default" | "filled";
            list: "default" | "pill" | "line";
          };
          search: "subtle" | "prominent";
        };
        internationalization: {
          locale:
            | "en"
            | "fr"
            | "es"
            | "zh"
            | "ja"
            | "de"
            | "nl"
            | "no"
            | "pt-br"
            | "ru";
        };
        favicon: {} | { icon: { light: string; dark: string } } | { emoji: string };
        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;
        };
        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";
        };
        themes: { default: "light" | "dark"; toggeable: false | true };
        pdf: { enabled: false | true };
        feedback: { enabled: false | true };
        ai: { mode: "none" | "search" | "assistant" };
        advancedCustomization: { enabled: false | true };
        git: { showEditLink: false | true };
        pageActions: { externalAI: false | true; markdown: false | true };
        externalLinks: { target: "self" | "blank" };
        pagination: { enabled: false | true };
        trademark: { enabled: false | true };
        privacyPolicy: { url?: string };
        socialPreview: { url?: string };
        insights: { trackingCookie: false | true };
      },
    ) {
      const url = new URL(
        `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/customization`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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