import "@johnlindquist/kit"
const fetch = await npm("node-fetch");
interface RecentDoc {
id: string;
title: string;
}
interface QueryResult {
data: RecentDoc[];
}
const apiKey = await env("STASHPAD_DOCS_API_KEY", {
hint: `Login to your account on <a href="https://docs.stashpad.com">Stashpad Docs</a> and generate an API key from the settings menu (top right corner).`,
});
async function getRecentDocs(apiKey: string) {
const response = await fetch(`https://api.stashpad.live/v1/docs/recent?api_key=${apiKey}`);
if (response.status !== 200) {
throw new Error("Please make sure your API key is valid.");
}
return ((await response.json()) as QueryResult).data;
}
const recentDocList = await getRecentDocs(apiKey)
const doc = await arg({
placeholder: "Select a doc to go to",
},
recentDocList.map((d) => {
return {
name: d.title,
value: `https://docs.stashpad.com/document/${d.id}`,
};
})
);
open(doc)