Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { paginateAPI } from "https://esm.town/v/andreterron/paginateAPI";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import process from "node:process";
export const reachingFreeTierLimit = async (interval: Interval) => {
const threshold = 90;
// If the interval never ran, there's no time range to check for updates
if (!interval.lastRunAt) {
return;
}
const opts = {
headers: {
Authorization: `Bearer ${process.env.vt_token}`,
},
};
const me = await fetchJSON(
"https://api.val.town/v1/me",
opts,
);
const vals = await paginateAPI(
`https://api.val.town/v1/users/${me.id}/vals?limit=100`,
opts,
);
const privateVals = vals.filter((val) => !val.public);
const newPrivateVals = privateVals.filter((val) =>
new Date(val.createdAt) > interval.lastRunAt
);
// Just send a notification when crossing the threshold
if (
privateVals.length >= threshold &&
privateVals.length - newPrivateVals.length < threshold
) {
console.email("Reaching free trial limit!");
}
};
October 23, 2023