diff options
| author | 2023-04-28 00:28:05 +0800 | |
|---|---|---|
| committer | 2023-04-28 00:28:05 +0800 | |
| commit | b992e50faf69e6f9e2d17385c0b05191e29bd49c (patch) | |
| tree | 11e77cc771fc4afd83108ffcabac97fd4f937ea2 | |
| parent | 871ea962c722bb74758e2ea801e3f3ca99af4907 (diff) | |
| download | HydroRoll-b992e50faf69e6f9e2d17385c0b05191e29bd49c.tar.gz HydroRoll-b992e50faf69e6f9e2d17385c0b05191e29bd49c.zip | |
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | docs/lib/ConvertKitApi.ts | 59 | ||||
| -rw-r--r-- | docs/lib/useTurborepoMinutesSaved.ts | 38 | ||||
| -rw-r--r-- | docs/package.json | 1 |
4 files changed, 98 insertions, 1 deletions
@@ -14,7 +14,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ diff --git a/docs/lib/ConvertKitApi.ts b/docs/lib/ConvertKitApi.ts new file mode 100644 index 0000000..3e35ec9 --- /dev/null +++ b/docs/lib/ConvertKitApi.ts @@ -0,0 +1,59 @@ +import axios from "axios";
+
+const API_KEY = process.env.CONVERTKIT_API_KEY;
+const API_SECRET = process.env.CONVERTKIT_API_SECRET;
+
+const Http = axios.create({
+ baseURL: "https://api.convertkit.com/v3",
+ headers: {
+ "Content-Type": "application/json; charset=utf-8",
+ },
+});
+
+export function subscribeToForm({
+ formId,
+ email,
+ firstName,
+ fields,
+}: {
+ formId: string;
+ email: string;
+ firstName: string;
+ fields?: Record<string, any>;
+}): Promise<Subscriber> {
+ return Http(`/forms/${formId}/subscribe`, {
+ method: "POST",
+ data: { api_key: API_KEY, email, first_name: firstName, fields },
+ }).then((res) => res.data.subscription?.subscriber);
+}
+
+export function updateSubscriber(
+ id: string,
+ update: Subscriber
+): Promise<unknown> {
+ return Http(`/subscribers/${id}`, {
+ method: "PUT",
+ data: {
+ api_secret: API_SECRET,
+ ...update,
+ },
+ }).then((res) => res.data);
+}
+
+export interface Subscriber {
+ id: number;
+ first_name: string;
+ email_address: string;
+ state: string; // maybe 'active' | 'inactive'
+ created_at: string;
+ fields: Record<string, any>;
+}
+
+export function getSubscriber(id: string): Promise<Subscriber> {
+ return Http(`/subscribers/${id}`, {
+ method: "GET",
+ data: {
+ api_secret: API_SECRET,
+ },
+ }).then((res) => res.data.subscriber);
+}
\ No newline at end of file diff --git a/docs/lib/useTurborepoMinutesSaved.ts b/docs/lib/useTurborepoMinutesSaved.ts new file mode 100644 index 0000000..5a94a91 --- /dev/null +++ b/docs/lib/useTurborepoMinutesSaved.ts @@ -0,0 +1,38 @@ +import useSWR from "swr";
+import axios from "axios";
+
+const fetcher = (url) => axios.get(url).then((res) => res.data);
+
+const path =
+ "https://api.us-east.tinybird.co/v0/pipes/turborepo_time_saved_ticker.json?token=p.eyJ1IjogIjAzYzA0Y2MyLTM1YTAtNDhhNC05ZTZjLThhMWE0NGNhNjhkZiIsICJpZCI6ICJmOWIzMTU5Yi0wOTVjLTQyM2UtOWIwNS04ZDZlNzIyNjEwNzIifQ.A3TOPdm3Lhmn-1x5m6jNvulCQbbgUeQfAIO3IaaAt5k";
+
+const REFRESH_INTERVAL_IN_MS = 3500;
+
+interface QueryResponse {
+ meta: { name: string; type: string }[];
+ data: {
+ last_update_time: string;
+ remote_cache_minutes_saved: number;
+ local_cache_minutes_saved: number;
+ }[];
+ rows: number;
+ statistics: {
+ elapsed: number;
+ rows_read: number;
+ bytes_read: number;
+ };
+}
+
+export default function useTurborepoMinutesSaved():
+ | {
+ last_update_time: string;
+ remote_cache_minutes_saved: number;
+ local_cache_minutes_saved: number;
+ }
+ | undefined {
+ const swr = useSWR<QueryResponse, unknown>(path, fetcher, {
+ refreshInterval: REFRESH_INTERVAL_IN_MS,
+ });
+
+ return swr.data?.data[0];
+}
\ No newline at end of file diff --git a/docs/package.json b/docs/package.json index 0c4758a..ea5a17c 100644 --- a/docs/package.json +++ b/docs/package.json @@ -36,6 +36,7 @@ }, "devDependencies": { "@babel/core": "7.20.12", + "@turbo/types": "workspace:*", "@types/node": "^16.11.12", "@types/react": "18.0.21", "autoprefixer": "10.4.14", |
