···11+import { AtpAgent } from "@atproto/api";
22+33+export const agent: AtpAgent = new AtpAgent({
44+ // App View URL
55+ service: "https://api.bsky.app",
66+ // If you were making an authenticated client, you would
77+ // use the PDS URL here instead - the main one is bsky.social
88+ // service: "https://bsky.social",
99+});
+34
lib/sheetsConnector.ts
···11+import Papa from "papaparse";
22+import type { ParseResult } from "papaparse";
33+44+/**Fetch the CSV data from the provided Google Sheets URL. */
55+async function getSheetsCSV(url: URL): Promise<string> {
66+ const response = await fetch(url);
77+88+ if (!response.ok) {
99+ throw new Error(`Failed to fetch data from ${url}`);
1010+ }
1111+1212+ const csv = await response.text();
1313+ return csv;
1414+}
1515+1616+/**Parse the provided CSV data into an array of JSON objects. */
1717+function parseCSV(csvData: string): ParseResult<string> {
1818+ return Papa.parse(csvData, { header: true });
1919+}
2020+2121+/**Convenience function to fetch CSV data from the provided Google Sheets URL
2222+ * and parse it into an array of JSON objects, all in one.
2323+ *
2424+ * Combines getSheetsCSV and parseCSV.
2525+ */
2626+export async function importCSVDataAsJson(
2727+ url: string
2828+): Promise<ParseResult<string>> {
2929+ const urlObj = new URL(url);
3030+3131+ const csv = await getSheetsCSV(urlObj);
3232+ const json = parseCSV(csv);
3333+ return json;
3434+}