import type { NavigateFunction } from "@remix-run/react"; import { NotionIcon } from "../components/icons/IntegrationIcons"; import { getChromeExtensionId } from "./util"; export type IntegrationStatus = "idle" | "loading" | "success" | "error"; export interface IntegrationProgress { progress: number; message: string; } export interface IntegrationConfig { id: string; name: string; description: string; icon?: React.ComponentType<{ className?: string }>; buttonClassName?: string; iconClassName?: string; requiresChromeExtension?: { extensionId: string; installUrl?: string; }; getAuthUrl?: (env: Record) => string; handleConnection?: (env: Record, navigate: NavigateFunction) => void; importData?: { url?: string; method?: "GET" | "POST"; withCredentials?: boolean; parseProgress?: (data: any) => IntegrationProgress; onSuccess?: (navigate: NavigateFunction) => void; onError?: (error: Error) => void; }; } export const getIntegrations = ( env: Record, ): Record => ({ notion: { id: "notion", name: "Notion", description: "Import your Notion pages and databases", icon: NotionIcon, buttonClassName: "bg-neutral-800 hover:bg-neutral-700", iconClassName: "w-6 h-6", getAuthUrl: (env) => { const params = new URLSearchParams({ client_id: env.NOTION_CLIENT_ID || "", redirect_uri: env.NODE_ENV === "development" ? "http://localhost:3000/auth/notion/callback" : "https://supermemory.ai/auth/notion/callback", response_type: "code", owner: "user", }); return `https://api.notion.com/v1/oauth/authorize?${params.toString()}`; }, importData: { url: `/backend/v1/integrations/notion/import`, withCredentials: true, parseProgress: (data) => ({ progress: data.progress, message: `Importing from Notion: ${data.progress}%`, }), onSuccess: (navigate) => { setTimeout(() => navigate("/"), 1500); }, }, }, xBookmarks: { id: "xBookmarks", name: "X Bookmarks", description: "Import your saved tweets and threads", iconClassName: "w-6 h-6", buttonClassName: "bg-blue-500 hover:bg-blue-600", requiresChromeExtension: { extensionId: getChromeExtensionId(), installUrl: "https://chrome.google.com/webstore/detail/supermemory/afpgkkipfdpeaflnpoaffkcankadgjfc", }, handleConnection: async (env, navigate) => { console.log("Sending message to extension"); console.log(window.chrome?.runtime); await window.chrome?.runtime.sendMessage( getChromeExtensionId(), { action: "exportBookmarks" }, (response: any) => { // Handle the response and show progress console.log("Response:", response); }, ); await window.postMessage({ action: "exportBookmarks" }, "*"); console.log("Message sent"); }, importData: { parseProgress: (data) => ({ progress: data.progress, message: `Importing from X: ${data.progress}%`, }), onSuccess: (navigate) => { setTimeout(() => navigate("/bookmarks"), 1500); }, }, icon: (props) => ( ), }, chromeBookmarks: { id: "chromeBookmarks", name: "Chrome Bookmarks", description: "Import your Chrome bookmarks", iconClassName: "w-6 h-6", buttonClassName: "bg-yellow-500 hover:bg-yellow-600", requiresChromeExtension: { extensionId: getChromeExtensionId(), installUrl: "https://chrome.google.com/webstore/detail/supermemory/afpgkkipfdpeaflnpoaffkcankadgjfc", }, handleConnection: (env, navigate) => { window.chrome?.runtime.sendMessage( getChromeExtensionId(), { action: "importBookmarks" }, (response: any) => { console.log("Response:", response); }, ); }, importData: { parseProgress: (data) => ({ progress: data.progress, message: `Importing Chrome bookmarks: ${data.progress}%`, }), onSuccess: (navigate) => { setTimeout(() => navigate("/bookmarks"), 1500); }, }, icon: (props) => ( ), }, iosShortcut: { id: "iosShortcut", name: "iOS Shortcut", description: "Import content using the iOS Shortcut", iconClassName: "w-6 h-6", buttonClassName: "bg-gray-500 hover:bg-gray-600", handleConnection: (env, navigate) => { window.location.href = "https://www.icloud.com/shortcuts/55f0695258cd46e4aad1aba8a2a7d14b"; }, icon: (props) => ( iOS Shortcut ), }, });