Files
kittycad.ts/src/api/users/get_user_shortlinks.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

import {
ShortlinkResultsPage_type,
Error_type,
CreatedAtSortMode_type,
} from '../../models.js';
import { Client } from '../../client.js';
interface Get_user_shortlinks_params {
client?: Client;
limit: number;
page_token: string;
sort_by: CreatedAtSortMode_type;
}
type Get_user_shortlinks_return = ShortlinkResultsPage_type | Error_type;
export default async function get_user_shortlinks({
client,
limit,
page_token,
sort_by,
}: Get_user_shortlinks_params): Promise<Get_user_shortlinks_return> {
const url = `/user/shortlinks?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
const urlBase = process?.env?.BASE_URL || 'https://api.zoo.dev';
const fullUrl = urlBase + url;
const kittycadToken = client
? client.token
: process.env.KITTYCAD_TOKEN || '';
const headers = {
Authorization: `Bearer ${kittycadToken}`,
};
const fetchOptions = {
method: 'GET',
headers,
};
const response = await fetch(fullUrl, fetchOptions);
const result = (await response.json()) as Get_user_shortlinks_return;
return result;
}