diff --git a/functions/metadata.ts b/functions/metadata.ts index 5a5a75e..b698e60 100644 --- a/functions/metadata.ts +++ b/functions/metadata.ts @@ -1,20 +1,18 @@ import { StatusCodes } from 'http-status-codes'; +import { version } from '../package.json'; import { setDB } from '../src/backend/api'; import type { RequestContext } from '../src/backend/context'; import { error, response } from '../src/backend/utils'; -import { version } from '../package.json'; +import type { Metadata } from '../src/generic'; export async function onRequest({ env }: RequestContext) { try { setDB(env.DB); - return response( - StatusCodes.OK, - { - version, - debug: !!env.DEBUG, - }, - false - ); + const metadata: Metadata = { + version, + debug: !!env.DEBUG, + }; + return response(StatusCodes.OK, metadata, false); } catch (e) { console.error(e); return error(StatusCodes.INTERNAL_SERVER_ERROR, env.DEBUG && e?.message); diff --git a/src/frontend/account.ts b/src/frontend/endpoints/account.ts similarity index 95% rename from src/frontend/account.ts rename to src/frontend/endpoints/account.ts index 3d484b7..5afec00 100644 --- a/src/frontend/account.ts +++ b/src/frontend/endpoints/account.ts @@ -1,7 +1,10 @@ -import type { Account, AccountResult, FullAccount, UniqueAccountKey } from '../accounts.js'; -import { accountAttributes, checkAccountAttribute } from '../accounts.js'; -import { Access } from '../generic.js'; -import { request } from './request.js'; +/** + * Account-related endpoints + */ +import type { Account, AccountResult, FullAccount, UniqueAccountKey } from '../../accounts.js'; +import { accountAttributes, checkAccountAttribute } from '../../accounts.js'; +import { Access } from '../../generic.js'; +import { request } from '../request.js'; /** * Parses the account result of a response diff --git a/src/frontend/endpoints/index.ts b/src/frontend/endpoints/index.ts new file mode 100644 index 0000000..261e40c --- /dev/null +++ b/src/frontend/endpoints/index.ts @@ -0,0 +1,10 @@ +import { request, type Metadata } from '../index.js'; + +export * from './account.js'; + +/** + * Get metadata about the API + */ +export function metadata(): Promise { + return request('GET', '/metadata'); +} diff --git a/src/frontend/index.ts b/src/frontend/index.ts index 89b09d8..7005e6c 100644 --- a/src/frontend/index.ts +++ b/src/frontend/index.ts @@ -1,5 +1,5 @@ export * from '../accounts.js'; export * from '../generic.js'; -export * from './account.js'; +export * from './endpoints'; export { auth } from './auth.js'; export * from './request.js'; diff --git a/src/generic.ts b/src/generic.ts index 772253c..3c8e6a5 100644 --- a/src/generic.ts +++ b/src/generic.ts @@ -38,3 +38,15 @@ export interface Response { */ result: Result; } + +export interface Metadata { + /** + * Current API version + */ + version: string; + + /** + * Whether the API has debug features enabled + */ + debug: boolean; +}