Edits history of script submission #15959 for ' Create a space (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Create a space
     *
     */
    export async function main(
      auth: Gitbook,
      organizationId: string,
      body:
        | ({
            title?: string;
            emoji?: string;
            parent?: string;
            language?:
              | "en"
              | "fr"
              | "de"
              | "es"
              | "it"
              | "pt"
              | "pt-br"
              | "ru"
              | "ja"
              | "zh"
              | "ko"
              | "ar"
              | "hi"
              | "nl"
              | "pl"
              | "tr"
              | "sv"
              | "no"
              | "da"
              | "fi"
              | "el"
              | "cs"
              | "hu"
              | "ro"
              | "th"
              | "vi"
              | "id"
              | "ms"
              | "he"
              | "uk"
              | "sk"
              | "bg"
              | "hr"
              | "lt"
              | "lv"
              | "et"
              | "sl";
            editMode?: "live" | "locked";
          } & {})
        | ({
            title?: string;
            emoji?: string;
            parent?: string;
            language?:
              | "en"
              | "fr"
              | "de"
              | "es"
              | "it"
              | "pt"
              | "pt-br"
              | "ru"
              | "ja"
              | "zh"
              | "ko"
              | "ar"
              | "hi"
              | "nl"
              | "pl"
              | "tr"
              | "sv"
              | "no"
              | "da"
              | "fi"
              | "el"
              | "cs"
              | "hu"
              | "ro"
              | "th"
              | "vi"
              | "id"
              | "ms"
              | "he"
              | "uk"
              | "sk"
              | "bg"
              | "hr"
              | "lt"
              | "lv"
              | "et"
              | "sl";
            editMode?: "live" | "locked";
          } & { template: { id: string; params?: { contentRefs?: {} } } })
        | ({
            title?: string;
            emoji?: string;
            parent?: string;
            language?:
              | "en"
              | "fr"
              | "de"
              | "es"
              | "it"
              | "pt"
              | "pt-br"
              | "ru"
              | "ja"
              | "zh"
              | "ko"
              | "ar"
              | "hi"
              | "nl"
              | "pl"
              | "tr"
              | "sv"
              | "no"
              | "da"
              | "fi"
              | "el"
              | "cs"
              | "hu"
              | "ro"
              | "th"
              | "vi"
              | "id"
              | "ms"
              | "he"
              | "uk"
              | "sk"
              | "bg"
              | "hr"
              | "lt"
              | "lv"
              | "et"
              | "sl";
            editMode?: "live" | "locked";
          } & {
            computedSource:
              | ({
                  type: "builtin:openapi";
                  dependencies: {
                    spec:
                      | { ref: { kind: "openapi"; spec: string } }
                      | {
                          ref: { kind: "openapi"; spec: string };
                          value: {
                            object: "openapi-spec";
                            id: string;
                            slug: string;
                            lastVersion?: string;
                          };
                        };
                  };
                } & { props: { models: false | true } })
              | {
                  type: "builtin:translation";
                  props: {};
                  dependencies: {
                    translation:
                      | { ref: { kind: "translation"; translation: string } }
                      | {
                          ref: { kind: "translation"; translation: string };
                          value: { space: string; revision: string };
                        };
                  };
                }
              | { type: string; props: {}; dependencies?: {} };
          }),
    ) {
      const url = new URL(`https://api.gitbook.com/v1/orgs/${organizationId}/spaces`);
    
      const response = await fetch(url, {
        method: "POST",
        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