add new sveltekit frontend

This commit is contained in:
Sam 2023-03-11 16:54:58 +01:00
commit fc4334932a
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
40 changed files with 3802 additions and 0 deletions

View file

@ -0,0 +1,99 @@
export interface User {
id: string;
name: string;
display_name: string | null;
bio: string | null;
avatar_urls: string[] | null;
links: string[] | null;
names: FieldEntry[];
pronouns: Pronoun[];
members: PartialMember[];
fields: Field[];
}
export interface MeUser extends User {
discord: string | null;
discord_username: string | null;
}
export interface Field {
name: string;
entries: FieldEntry[];
}
export interface FieldEntry {
value: string;
status: WordStatus;
}
export interface Pronoun {
pronouns: string;
display_text: string | null;
status: WordStatus;
}
export enum WordStatus {
Unknown = 0,
Favourite = 1,
Okay = 2,
Jokingly = 3,
FriendsOnly = 4,
Avoid = 5,
}
export interface PartialMember {
id: string;
name: string;
display_name: string | null;
avatar_urls: string[] | null;
}
export interface Member extends PartialMember {
bio: string | null;
links: string | null;
names: FieldEntry[];
pronouns: Pronoun[];
fields: Field[];
user: MemberPartialUser;
}
export interface MemberPartialUser {
id: string;
name: string;
display_name: string | null;
avatar_urls: string[] | null;
}
export interface APIError {
code: ErrorCode;
message?: string;
details?: string;
}
export enum ErrorCode {
BadRequest = 400,
Forbidden = 403,
NotFound = 404,
MethodNotAllowed = 405,
TooManyRequests = 429,
InternalServerError = 500,
InvalidState = 1001,
InvalidOAuthCode = 1002,
InvalidToken = 1003,
InviteRequired = 1004,
InvalidTicket = 1005,
InvalidUsername = 1006,
UsernameTaken = 1007,
InvitesDisabled = 1008,
InviteLimitReached = 1009,
InviteAlreadyUsed = 1010,
UserNotFound = 2001,
MemberNotFound = 3001,
MemberLimitReached = 3002,
RequestTooBig = 4001,
}

View file

@ -0,0 +1,24 @@
import type { APIError } from "./entities";
import { PUBLIC_BASE_URL } from "$env/static/public";
export async function apiFetch<T>(
path: string,
{ method, body, token }: { method?: string; body?: any; token?: string },
) {
const resp = await fetch(`${PUBLIC_BASE_URL}/api/v1${path}`, {
method: method || "GET",
headers: {
...(token ? { Authorization: token } : {}),
"Content-Type": "application/json",
},
body: body ? JSON.stringify(body) : null,
});
const data = await resp.json();
if (resp.status < 200 || resp.status >= 300) throw data as APIError;
return data as T;
}
export const apiFetchClient = async <T>(path: string, method: string = "GET", body: any = null) =>
apiFetch<T>(path, { method, body, token: localStorage.getItem("pronouns-token") || undefined });