diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 197613b..e9cb3c5 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -5,6 +5,7 @@ import { cors } from "hono/cors"; import { auth } from "./auth"; import { getHono } from "./hono"; import { zero } from "./zero"; +import { webhook } from "./webhook"; const app = getHono(); @@ -43,6 +44,7 @@ app.use("*", async (c, next) => { app.route("/api/zero", zero); app.get("/api", (c) => c.text("OK")); +app.get("/api/webhook_receiver", webhook); app.get("/", (c) => c.text("OK")); serve( diff --git a/apps/api/src/plaid.ts b/apps/api/src/plaid.ts new file mode 100644 index 0000000..dcf9249 --- /dev/null +++ b/apps/api/src/plaid.ts @@ -0,0 +1,13 @@ +import { Configuration, PlaidApi, PlaidEnvironments } from "plaid"; + +const configuration = new Configuration({ + basePath: process.env.PLAID_ENV == 'production' ? PlaidEnvironments.production : PlaidEnvironments.sandbox, + baseOptions: { + headers: { + 'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID, + 'PLAID-SECRET': process.env.PLAID_SECRET, + } + }, +}); +export const plaidClient = new PlaidApi(configuration); + diff --git a/apps/api/src/webhook.ts b/apps/api/src/webhook.ts new file mode 100644 index 0000000..8d42f70 --- /dev/null +++ b/apps/api/src/webhook.ts @@ -0,0 +1,14 @@ +import type { Context } from "hono"; +import { plaidClient } from "./plaid"; +// import { LinkSessionFinishedWebhook, WebhookType } from "plaid"; + +export const webhook = async (c: Context) => { + + console.log("Got webhook"); + const b = await c.req.text(); + console.log("body:", b); + + + return c.text("Hi"); + +} diff --git a/apps/api/src/zero.ts b/apps/api/src/zero.ts index 7b74aa2..616e06a 100644 --- a/apps/api/src/zero.ts +++ b/apps/api/src/zero.ts @@ -25,19 +25,7 @@ import { randomUUID } from "crypto"; import { db } from "./db"; import { balance, plaidAccessTokens, plaidLink, transaction } from "@money/shared/db"; import { eq, inArray, sql, type InferInsertModel } from "drizzle-orm"; - - -const configuration = new Configuration({ - basePath: process.env.PLAID_ENV == 'production' ? PlaidEnvironments.production : PlaidEnvironments.sandbox, - baseOptions: { - headers: { - 'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID, - 'PLAID-SECRET': process.env.PLAID_SECRET, - } - } -}); -const plaidClient = new PlaidApi(configuration); - +import { plaidClient } from "./plaid"; const processor = new PushProcessor( new ZQLDatabase( @@ -56,7 +44,6 @@ const createMutators = (authData: AuthData | null) => { ...mutators.link, async create() { isLoggedIn(authData); - console.log("Creating Link token"); const r = await plaidClient.linkTokenCreate({ user: { client_user_id: authData.user.id, @@ -65,9 +52,9 @@ const createMutators = (authData: AuthData | null) => { language: "en", products: [Products.Transactions], country_codes: [CountryCode.Us], + webhook: "https://webhooks.koon.us/api/webhook_receiver", hosted_link: {} }); - console.log("Result", r); const { link_token, hosted_link_url } = r.data; if (!hosted_link_url) throw Error("No link in response"); diff --git a/flake.nix b/flake.nix index 61eb94d..9312037 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,7 @@ postgresql process-compose + cloudflared ]; }; }); diff --git a/process-compose.yaml b/process-compose.yaml index 2cf17dd..80529de 100644 --- a/process-compose.yaml +++ b/process-compose.yaml @@ -62,3 +62,6 @@ processes: depends_on: db: condition: process_healthy + + tunnel: + command: cloudflared tunnel --config ~/.cloudflared/config.yml run