Edits history of script submission #16021 for ' Get a space computed revision (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Get a space computed revision
     *
     */
    export async function main(
      auth: Gitbook,
      spaceId: string,
      body: {
        source:
          | ({
              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?: {} };
        seed: string;
      },
    ) {
      const url = new URL(`https://api.gitbook.com/v1/spaces/${spaceId}/content/computed/revision`);
    
      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