182 lines
6.2 KiB
JavaScript
182 lines
6.2 KiB
JavaScript
/* This file is generated by scripts/generate-api-client.mjs. */
|
|
export const apiOperations = {
|
|
activateCharacter: { method: "POST", path: "/api/characters/{characterId}/activate", expectsJson: true },
|
|
createCampaign: { method: "POST", path: "/api/campaigns", expectsJson: true },
|
|
createCharacter: { method: "POST", path: "/api/characters", expectsJson: true },
|
|
createSkill: { method: "POST", path: "/api/characters/{characterId}/skills", expectsJson: true },
|
|
getCampaign: { method: "GET", path: "/api/campaigns/{campaignId}", expectsJson: true },
|
|
getCampaignLog: { method: "GET", path: "/api/campaigns/{campaignId}/log", expectsJson: true },
|
|
getCampaigns: { method: "GET", path: "/api/campaigns", expectsJson: true },
|
|
getCurrentCampaignCharacters: { method: "GET", path: "/api/characters/current-campaign", expectsJson: true },
|
|
getHealth: { method: "GET", path: "/api/health", expectsJson: true },
|
|
getMe: { method: "GET", path: "/api/me", expectsJson: true },
|
|
getRulesets: { method: "GET", path: "/api/rulesets", expectsJson: true },
|
|
loginUser: { method: "POST", path: "/api/auth/login", expectsJson: true },
|
|
logoutUser: { method: "POST", path: "/api/auth/logout", expectsJson: false },
|
|
registerUser: { method: "POST", path: "/api/auth/register", expectsJson: true },
|
|
rollSkill: { method: "POST", path: "/api/skills/{skillId}/roll", expectsJson: true },
|
|
updateCharacter: { method: "PUT", path: "/api/characters/{characterId}", expectsJson: true },
|
|
updateSkill: { method: "PUT", path: "/api/skills/{skillId}", expectsJson: true }
|
|
};
|
|
function withPathParams(pathTemplate, pathParams) {
|
|
let pathValue = pathTemplate;
|
|
for (const [key, value] of Object.entries(pathParams)) {
|
|
pathValue = pathValue.replace(`{${key}}`, encodeURIComponent(String(value)));
|
|
}
|
|
return pathValue;
|
|
}
|
|
function withQuery(pathValue, query) {
|
|
const entries = Object.entries(query).filter(([, value]) => value !== undefined);
|
|
if (entries.length === 0) {
|
|
return pathValue;
|
|
}
|
|
const queryString = new URLSearchParams(entries.map(([key, value]) => [key, String(value)])).toString();
|
|
return queryString.length === 0 ? pathValue : `${pathValue}?${queryString}`;
|
|
}
|
|
async function send(operation, options) {
|
|
const resolvedPath = withQuery(withPathParams(operation.path, options.pathParams ?? {}), options.query ?? {});
|
|
const headers = {
|
|
"Accept": "application/json"
|
|
};
|
|
let body;
|
|
if (options.body !== undefined) {
|
|
headers["Content-Type"] = "application/json";
|
|
body = JSON.stringify(options.body);
|
|
}
|
|
const response = await fetch(resolvedPath, {
|
|
method: operation.method,
|
|
headers,
|
|
body
|
|
});
|
|
if (!response.ok) {
|
|
const errorPayload = await response.json().catch(() => ({ error: "Unknown API error." }));
|
|
if (errorPayload && typeof errorPayload === "object" && "error" in errorPayload && typeof errorPayload.error === "string") {
|
|
throw new Error(errorPayload.error);
|
|
}
|
|
throw new Error(`Request failed with status ${response.status}`);
|
|
}
|
|
if (!operation.expectsJson) {
|
|
return undefined;
|
|
}
|
|
return response.json();
|
|
}
|
|
export async function activateCharacter(characterId) {
|
|
return send(apiOperations.activateCharacter, {
|
|
pathParams: { characterId: characterId },
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function createCampaign(body) {
|
|
return send(apiOperations.createCampaign, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|
|
export async function createCharacter(body) {
|
|
return send(apiOperations.createCharacter, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|
|
export async function createSkill(characterId, body) {
|
|
return send(apiOperations.createSkill, {
|
|
pathParams: { characterId: characterId },
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|
|
export async function getCampaign(campaignId) {
|
|
return send(apiOperations.getCampaign, {
|
|
pathParams: { campaignId: campaignId },
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function getCampaignLog(campaignId) {
|
|
return send(apiOperations.getCampaignLog, {
|
|
pathParams: { campaignId: campaignId },
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function getCampaigns() {
|
|
return send(apiOperations.getCampaigns, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function getCurrentCampaignCharacters() {
|
|
return send(apiOperations.getCurrentCampaignCharacters, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function getHealth() {
|
|
return send(apiOperations.getHealth, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function getMe() {
|
|
return send(apiOperations.getMe, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function getRulesets() {
|
|
return send(apiOperations.getRulesets, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function loginUser(body) {
|
|
return send(apiOperations.loginUser, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|
|
export async function logoutUser() {
|
|
return send(apiOperations.logoutUser, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: undefined
|
|
});
|
|
}
|
|
export async function registerUser(body) {
|
|
return send(apiOperations.registerUser, {
|
|
pathParams: {},
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|
|
export async function rollSkill(skillId, body) {
|
|
return send(apiOperations.rollSkill, {
|
|
pathParams: { skillId: skillId },
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|
|
export async function updateCharacter(characterId, body) {
|
|
return send(apiOperations.updateCharacter, {
|
|
pathParams: { characterId: characterId },
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|
|
export async function updateSkill(skillId, body) {
|
|
return send(apiOperations.updateSkill, {
|
|
pathParams: { skillId: skillId },
|
|
query: undefined,
|
|
body: body
|
|
});
|
|
}
|