//native
type Gitbook = {
token: string;
};
/**
* Get a space computed document
*
*/
export async function main(
auth: Gitbook,
spaceId: string,
schema: "current" | "next" | undefined,
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:
| { doc: "models" }
| { doc: "operations" | "info"; page: string };
})
| {
type: "builtin:translation";
props: { space: string; document: string };
}
| { type: string; props: {}; dependencies?: {} };
seed: string;
},
) {
const url = new URL(`https://api.gitbook.com/v1/spaces/${spaceId}/content/computed/document`);
for (const [k, v] of [["schema", schema]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
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