feat: prepare for webhooks
This commit is contained in:
@@ -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(
|
||||
|
||||
13
apps/api/src/plaid.ts
Normal file
13
apps/api/src/plaid.ts
Normal file
@@ -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);
|
||||
|
||||
14
apps/api/src/webhook.ts
Normal file
14
apps/api/src/webhook.ts
Normal file
@@ -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");
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -62,3 +62,6 @@ processes:
|
||||
depends_on:
|
||||
db:
|
||||
condition: process_healthy
|
||||
|
||||
tunnel:
|
||||
command: cloudflared tunnel --config ~/.cloudflared/config.yml run
|
||||
|
||||
Reference in New Issue
Block a user