Files
ncd-fe/packages/pl-api/lib/client/apps.ts
nicole mikołajczyk d5d453e645 pl-api: allow importing parts of the client
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2026-02-23 10:39:26 +01:00

34 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as v from 'valibot';
import { applicationSchema, credentialApplicationSchema } from '../entities';
import type { PlApiBaseClient } from '../client-base';
import type { CreateApplicationParams } from '../params/apps';
/** Register client applications that can be used to obtain OAuth tokens. */
const apps = (client: PlApiBaseClient) => ({
/**
* Create an application
* Create a new application to obtain OAuth2 credentials.
* @see {@link https://docs.joinmastodon.org/methods/apps/#create}
*/
createApplication: async (params: CreateApplicationParams) => {
const response = await client.request('/api/v1/apps', { method: 'POST', body: params });
return v.parse(credentialApplicationSchema, response.json);
},
/**
* Verify your app works
* Confirm that the apps OAuth2 credentials work.
* @see {@link https://docs.joinmastodon.org/methods/apps/#verify_credentials}
*/
verifyApplication: async () => {
const response = await client.request('/api/v1/apps/verify_credentials');
return v.parse(applicationSchema, response.json);
},
});
export { apps };