Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,387 changes: 1,383 additions & 4 deletions app/bun.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion app/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { withSentryConfig } from "@sentry/nextjs";
import type { NextConfig } from "next";
import { withWorkflow } from "workflow/next";

const nextConfig: NextConfig = {
images: {
Expand Down Expand Up @@ -52,7 +53,9 @@ const nextConfig: NextConfig = {
},
};

export default withSentryConfig(nextConfig, {
const workflowConfig = withWorkflow(nextConfig);

export default withSentryConfig(workflowConfig, {
// For all available options, see:
// https://www.npmjs.com/package/@sentry/webpack-plugin#options

Expand Down
3 changes: 3 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"@tanstack/query-db-collection": "^0.2.16",
"@tanstack/react-db": "^0.1.17",
"@types/heic-convert": "^2.1.0",
"@workflow/ai": "^4.0.1-beta.52",
"ai": "^6.0.97",
"better-env": "^0.3.1",
"canvas-confetti": "^1.9.3",
"class-variance-authority": "^0.7.1",
Expand Down Expand Up @@ -84,6 +86,7 @@
"tailwind-merge": "^3.3.1",
"uuid": "^13.0.0",
"vaul": "^1.1.2",
"workflow": "^4.1.0-beta.60",
"zod": "^4.1.8"
},
"devDependencies": {
Expand Down
49 changes: 49 additions & 0 deletions app/src/app/api/cron/luma-sync/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { NextResponse } from "next/server";
import { start } from "workflow/api";
import { syncLumaEventsWorkflow } from "@/workflows/luma-sync";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

const DEFAULT_LIMIT = 10;
const DEFAULT_CALENDAR_HANDLE = "allthingswebcalendar";

function isAuthorized(request: Request): boolean {
const cronSecret = process.env.CRON_SECRET;

if (!cronSecret) {
return true;
}

return request.headers.get("authorization") === `Bearer ${cronSecret}`;
}

export async function GET(request: Request) {
if (!isAuthorized(request)) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

try {
const calendarApiId = process.env.LUMA_CALENDAR_API_ID;
const calendarHandle =
process.env.LUMA_CALENDAR_HANDLE ?? DEFAULT_CALENDAR_HANDLE;

const run = await start(syncLumaEventsWorkflow, [
{
limit: DEFAULT_LIMIT,
calendarApiId,
calendarHandle,
},
]);

return NextResponse.json({
ok: true,
runId: run.runId,
message: "Luma sync workflow started",
});
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown error";

return NextResponse.json({ ok: false, error: message }, { status: 500 });
}
}
100 changes: 77 additions & 23 deletions app/src/lib/luma.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
import { mainConfig } from "@/lib/config";

type LumaGeoAddress = {
city: string;
type: "google" | "string";
country: string;
latitude: number;
longitude: number;
place_id: string;
address: string;
description: string;
city_state: string;
full_address: string;
};

export type LumaEvent = {
app_id: string;
api_id?: string;
app_id?: string;
calendar_api_id?: string;
created_at: string;
cover_url: string;
cover_url?: string | null;
name: string;
description: string;
description_md: string;
description?: string | null;
description_md?: string | null;
series_api_id?: string;
start_at: string;
duration_interval: string;
end_at: string;
geo_address_json: {
city: string;
type: "google" | "string";
country: string;
latitude: number;
longitude: number;
place_id: string;
address: string;
description: string;
city_state: string;
full_address: string;
};
geo_latitude: number;
geo_longitude: number;
geo_address_json?: LumaGeoAddress | null;
geo_latitude?: number | null;
geo_longitude?: number | null;
url: string;
timezone: string;
event_type: "independent" | "series";
user_api_id: string;
visibility: "public" | "private";
zoom_meeting_url: string;
meeting_url: string;
zoom_meeting_url?: string | null;
meeting_url?: string | null;
};

export type LumaHost = {
Expand Down Expand Up @@ -75,6 +79,12 @@ export const createLumaClient = () => {
);
return [];
},
getCalendarEvents: async () => {
console.warn(
"Did not fetch calendar events because LUMA_API_KEY is not set",
);
return [];
},
getEvent: async () => {
console.warn("Did not fetch event because LUMA_API_KEY is not set");
return null;
Expand Down Expand Up @@ -107,8 +117,44 @@ export const createLumaClient = () => {
"x-luma-api-key": apiKey,
};

const getUpcomingEvents = async () => {
const url = `https://api.lu.ma/public/v1/calendar/list-events?pagination_limit=50&after=${new Date().toISOString()}`;
const parseCalendarEventsResponse = (resData: any): LumaEvent[] => {
const entries = resData?.entries ?? resData?.events?.entries ?? [];
if (!Array.isArray(entries)) return [];
return entries
.map((entry: any) => entry?.event ?? entry)
.filter(Boolean) as LumaEvent[];
};

const getCalendarEvents = async ({
limit = 10,
after,
before,
calendarApiId,
calendarHandle,
}: {
limit?: number;
after?: string;
before?: string;
calendarApiId?: string;
calendarHandle?: string;
} = {}) => {
const searchParams = new URLSearchParams({
pagination_limit: String(limit),
});
if (after) {
searchParams.append("after", after);
}
if (before) {
searchParams.append("before", before);
}
if (calendarApiId) {
searchParams.append("calendar_api_id", calendarApiId);
}
if (calendarHandle) {
searchParams.append("calendar_handle", calendarHandle);
}

const url = `https://api.lu.ma/public/v1/calendar/list-events?${searchParams.toString()}`;
const res = await fetch(url, {
method: "GET",
headers,
Expand All @@ -119,7 +165,14 @@ export const createLumaClient = () => {
);
}
const resData = await res.json();
return resData.events.entries.map((e: any) => e.event);
return parseCalendarEventsResponse(resData);
};

const getUpcomingEvents = async () => {
return getCalendarEvents({
limit: 50,
after: new Date().toISOString(),
});
};

const getEvent = async (eventId: string): Promise<LumaEventPayload> => {
Expand Down Expand Up @@ -228,6 +281,7 @@ export const createLumaClient = () => {

return {
getUpcomingEvents,
getCalendarEvents,
getEvent,
getAttendees,
getAllAttendees,
Expand Down
Loading