import Zulip from './zulip.js' import Path from 'path' import FS from 'fs/promises' import formatPlaneEvent from './format.js' import Env from './env.js' const API_KEYS = Env.array('API_KEYS') /** @type {import('./zulip.js').Config} */ const zulip = { email: Env.required('ZULIP_EMAIL'), apiKey: Env.required('ZULIP_API_KEY'), baseURI: Env.required('ZULIP_BASE_URI'), } /** @type {import('./plane.js').Config} */ const plane = { workspace: Env.required('PLANE_WORKSPACE'), apiKey: Env.required('PLANE_API_KEY'), baseURI: Env.required('PLANE_BASE_URI'), } const server = Bun.serve({ fetch: async req => { const url = new URL(req.url) const apiKey = url.searchParams.get('apiKey') if (!apiKey) return new Response(null, { status: 401 }) if (!API_KEYS.includes(apiKey.trim())) return new Response(null, { status: 401 }) const body = await req.json() const { topic, content } = await formatPlaneEvent(plane, body) await Zulip.Messages.send(zulip, { type: 'stream', to: 'plane', topic, content, }) return new Response() }, hostname: '0.0.0.0', lowMemoryMode: true, }) console.log(`Zulip <> Plane integration`) console.log(`listening on ${server.hostname}:${server.port}`)