1Migrated from folder: api/crux_add
1import { callGoogleSheetsAPI } from "https://esm.town/v/clayway/callGoogleSheetsAPI";
2import { extractReceiptInfo } from "https://esm.town/v/clayway/extractReceiptInfo";
3import process from "node:process";
37 } = result;
38 try {
39 await callGoogleSheetsAPI({
40 sheetId: process.env.BUDGET_SHEET_ID,
41 serviceAccount: process.env.GOOGLE_SERVICE_ACCOUNT,
13 `${process.env.reddit_client_id}:${process.env.reddit_client_secret}`,
14 ).toString("base64");
15 const response = await fetch("https://www.reddit.com/api/v1/access_token", {
16 method: "POST",
17 body: formData,
24
25 try {
26 response = await fetch("https://www.reddit.com/api/v1/access_token", {
27 headers: headers,
28 method: "POST",
11}) {
12 const topUser = whoami().at(-1).slice(1).split(".")[0];
13 const verifyPublicKey = await __utils__.api(topUser + ".vsPublicKey");
14 if (verifyPublicKey !== keys.publicKey)
15 throw new Error("keypair doesn't match @" + topUser + ".vsPublicKey()");
7 const [handle, encodedSignedMessage] = matches.slice(1);
8 const publicKey = Buffer.from(
9 await __utils__.api(handle + ".vsPublicKey"),
10 "base64",
11 );
51 Accept: "application/vnd.github+json",
52 Authorization: req.get("Authorization"),
53 "X-GitHub-Api-Version": "2022-11-28",
54 };
55 const path = `https://api.github.com/repos/${shortlink_repo}/contents/public/_redirects`;
56 const getRes = await fetch(path, {
57 method: "GET",
84 headers,
85 body: JSON.stringify({
86 message: `Adding '${shortlink}' shortlink via API`,
87 content: Buffer.from(redirects).toString("base64"),
88 sha,
2Gets information about a specific val.
3
4To access private vals, pass your API token as a secret to the function. Read more about [authentication](https://docs.val.town/api/authentication) to understand how to generate a token and save it as a secret.
5
6Migrated from folder: Archive/getVal
1// https://developer.mozilla.org/en-US/docs/Web/API/btoa
2import { Buffer } from "node:buffer";
3
7 data: object;
8};
9export async function callGoogleSheetsAPI(
10 { serviceAccount, sheetId, action, data }: Args,
11) {
14 );
15 const googleAuthOptions = {
16 scope: ["https://www.googleapis.com/auth/spreadsheets"],
17 };
18 const { access_token } = await getToken(serviceAccount, googleAuthOptions);
19 const result = fetchJSON(
20 `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/${action}`,
21 {
22 method: "POST",