Edits history of script submission #16173 for ' Render an integration UI with POST method (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Render an integration UI with POST method
     *
     */
    export async function main(
      auth: Gitbook,
      integrationName: string,
      body: {
        componentId: string;
        props: {};
        state?: {};
        context:
          | ({ theme: "dark" | "light" } & {
              type: "configuration_account";
              organizationId: string;
            })
          | ({ theme: "dark" | "light" } & {
              type: "configuration_space";
              spaceId: string;
            })
          | ({ theme: "dark" | "light" } & {
              type: "configuration_site";
              siteId: string;
            })
          | ({ theme: "dark" | "light" } & {
              type: "configuration_contentsource";
              organizationId: string;
              spaceId?: string;
            })
          | ({ theme: "dark" | "light" } & {
              type: "document";
              spaceId: string;
              editable: false | true;
            });
        action?:
          | { action: string }
          | { action: "@ui.modal.open"; componentId: string; props: {} }
          | { action: "@ui.modal.close"; returnValue: {} }
          | { action: "@ui.url.open"; url: string }
          | { action: "@link.unfurl"; url: string }
          | { action: "@editor.node.updateProps"; props: {} };
      },
    ) {
      const url = new URL(`https://api.gitbook.com/v1/integrations/${integrationName}/render`);
    
      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