chore(release): remove legacy runtime dependencies

This commit is contained in:
poyrazavsever
2026-07-17 09:13:23 +03:00
parent 5948907e5d
commit 8cd3de8e1f
42 changed files with 910 additions and 6207 deletions
-72
View File
@@ -1,72 +0,0 @@
import { embed } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { createClient } from '@/lib/supabase/server';
export async function generateEmbedding(text: string, provider: string, apiKey: string) {
let embeddingModel;
if (provider === 'google' && apiKey) {
const google = createGoogleGenerativeAI({ apiKey });
embeddingModel = google.textEmbeddingModel('text-embedding-004');
} else if (apiKey) {
const openai = createOpenAI({ apiKey });
embeddingModel = openai.embedding('text-embedding-3-small');
} else {
throw new Error('Geçerli bir API Anahtarı bulunamadı.');
}
const { embedding } = await embed({
model: embeddingModel,
value: text,
});
return embedding;
}
export async function saveDocumentEmbedding(
userId: string,
content: string,
metadata: Record<string, any>,
provider: string,
apiKey: string
) {
const embedding = await generateEmbedding(content, provider, apiKey);
const supabase = await createClient();
const { error } = await supabase.from('document_embeddings').insert({
user_id: userId,
content,
metadata,
embedding,
});
if (error) {
console.error('Embedding kayıt hatası:', error);
throw new Error('Embedding kaydedilemedi.');
}
}
export async function searchSimilarDocuments(
userId: string,
query: string,
provider: string,
apiKey: string,
matchCount: number = 5
) {
const queryEmbedding = await generateEmbedding(query, provider, apiKey);
const supabase = await createClient();
const { data, error } = await supabase.rpc('match_documents', {
query_embedding: queryEmbedding,
match_count: matchCount,
filter_user_id: userId,
});
if (error) {
console.error('Vektör arama hatası:', error);
return [];
}
return data;
}
-111
View File
@@ -1,111 +0,0 @@
import { createClient } from "@/lib/supabase/server";
type FirstAdminSetupState = {
available: boolean;
errorMessage?: string;
};
type FirstAdminSetupOptions = {
timeoutMs?: number;
};
const DEFAULT_SETUP_TIMEOUT_MS = 5_000;
function createTimeoutSignal(timeoutMs: number) {
if (typeof AbortSignal !== "undefined" && "timeout" in AbortSignal) {
return AbortSignal.timeout(timeoutMs);
}
const controller = new AbortController();
setTimeout(() => controller.abort(), timeoutMs).unref?.();
return controller.signal;
}
function isMissingSetupFunctionError(error: {
code?: string;
message?: string;
}) {
return (
error.code === "PGRST202" ||
error.message?.includes("is_first_admin_setup_available")
);
}
async function getSetupStateFromProfiles(
timeoutMs: number,
): Promise<FirstAdminSetupState | null> {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!supabaseUrl || !serviceRoleKey) {
return null;
}
const endpoint = new URL("/rest/v1/profiles", supabaseUrl);
endpoint.searchParams.set("select", "id");
endpoint.searchParams.set("limit", "1");
try {
const response = await fetch(endpoint, {
cache: "no-store",
signal: createTimeoutSignal(timeoutMs),
headers: {
apikey: serviceRoleKey,
authorization: `Bearer ${serviceRoleKey}`,
},
});
if (!response.ok) {
console.error("First admin setup fallback check failed", {
status: response.status,
body: await response.text(),
});
return null;
}
const rows = (await response.json()) as Array<{ id: string }>;
return { available: rows.length === 0 };
} catch (error) {
console.error("First admin setup fallback request failed", error);
return null;
}
}
export async function getFirstAdminSetupState(
options: FirstAdminSetupOptions = {},
): Promise<FirstAdminSetupState> {
const timeoutMs = options.timeoutMs ?? DEFAULT_SETUP_TIMEOUT_MS;
const supabase = await createClient();
const { data, error } = await supabase
.rpc("is_first_admin_setup_available")
.abortSignal(createTimeoutSignal(timeoutMs));
if (error) {
console.error("First admin setup check failed", {
code: error.code,
message: error.message,
details: error.details,
hint: error.hint,
});
const fallbackState = await getSetupStateFromProfiles(timeoutMs);
if (fallbackState) {
if (isMissingSetupFunctionError(error)) {
console.warn(
"First admin setup RPC is not available through PostgREST yet; using service-role profile fallback.",
);
}
return fallbackState;
}
return {
available: false,
errorMessage:
"İlk kurulum kontrolü yapılamadı. Veritabanı hazırlık servisi henüz tamamlanmamış olabilir; birkaç saniye sonra tekrar deneyin.",
};
}
return { available: Boolean(data) };
}
-65
View File
@@ -1,65 +0,0 @@
import { createServiceRoleClient } from "@/lib/supabase/admin";
type InternalAuthUserRole = "freelancer" | "client";
type CreateInternalAuthUserInput = {
email: string;
password: string;
role: InternalAuthUserRole;
reason: string;
};
export async function createInternalAuthUser({
email,
password,
role,
reason,
}: CreateInternalAuthUserInput) {
const admin = createServiceRoleClient();
const normalizedEmail = email.trim().toLowerCase();
if (!normalizedEmail || !password) {
throw new Error("E-posta ve şifre zorunludur.");
}
const { error: guardError } = await admin.rpc(
"request_internal_auth_creation",
{
target_email: normalizedEmail,
target_reason: reason,
},
);
if (guardError) {
throw new Error(
`Kullanıcı oluşturma hazırlığı tamamlanamadı: ${guardError.message}`,
);
}
const { data, error } = await admin.auth.admin.createUser({
email: normalizedEmail,
password,
email_confirm: true,
app_metadata: {
internal_created: true,
role,
},
user_metadata: {
role,
},
});
if (error) {
throw new Error(error.message);
}
if (!data.user?.id) {
throw new Error("Kullanıcı oluşturuldu fakat kullanıcı kimliği alınamadı.");
}
return {
admin,
user: data.user,
userId: data.user.id,
};
}
-52
View File
@@ -1,52 +0,0 @@
import Dexie, { type Table } from "dexie";
// Veritabanı Modelleri
export interface Journal {
id: string;
date: string;
mood: string;
energy: number;
content: string;
ai_tags?: string[];
ai_sentiment_score?: number;
ai_summary?: string;
created_at: string;
updated_at: string;
}
export interface Task {
id: string;
journal_id?: string;
title: string;
status: "todo" | "in_progress" | "completed";
ai_generated: boolean;
date: string;
created_at: string;
}
export interface ChatMessage {
id: string;
role: "user" | "assistant";
content: string;
created_at: string;
}
export class MindSpaceDB extends Dexie {
journals!: Table<Journal>;
tasks!: Table<Task>;
chat_messages!: Table<ChatMessage>;
constructor() {
super("MindSpaceDatabase");
// Schema tanımlamaları.
// IndexedDB'de sadece indekslenecek (üzerinde arama/sıralama yapılacak) alanları belirtiriz.
this.version(2).stores({
journals: "id, date, mood",
tasks: "id, status, date, journal_id",
chat_messages: "id, created_at",
});
}
}
export const db = new MindSpaceDB();
-17
View File
@@ -1,17 +0,0 @@
import { createClient } from "@supabase/supabase-js";
export function createServiceRoleClient() {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!supabaseUrl || !serviceRoleKey) {
throw new Error("Supabase service role yapılandırması eksik.");
}
return createClient(supabaseUrl, serviceRoleKey, {
auth: {
autoRefreshToken: false,
persistSession: false,
},
});
}
-8
View File
@@ -1,8 +0,0 @@
import { createBrowserClient } from '@supabase/ssr'
export function createClient() {
return createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)
}
-62
View File
@@ -1,62 +0,0 @@
import { createServerClient } from '@supabase/ssr'
import { NextResponse, type NextRequest } from 'next/server'
export async function updateSession(request: NextRequest) {
const pathname = request.nextUrl.pathname
if (
pathname.startsWith('/login') ||
pathname.startsWith('/register') ||
pathname.startsWith('/auth') ||
pathname.startsWith('/forgot-password')
) {
return NextResponse.next({ request })
}
let supabaseResponse = NextResponse.next({
request,
})
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return request.cookies.getAll()
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))
supabaseResponse = NextResponse.next({
request,
})
cookiesToSet.forEach(({ name, value, options }) =>
supabaseResponse.cookies.set(name, value, options)
)
},
},
}
)
// IMPORTANT: Avoid writing any logic between createServerClient and
// supabase.auth.getUser(). A simple mistake could make it very hard to debug
// issues with users being randomly logged out.
const {
data: { user },
} = await supabase.auth.getUser()
if (
!user &&
!pathname.startsWith('/login') &&
!pathname.startsWith('/register') &&
!pathname.startsWith('/auth')
) {
// no user, potentially respond by redirecting the user to the login page
const url = request.nextUrl.clone()
url.pathname = '/login'
return NextResponse.redirect(url)
}
return supabaseResponse
}
-29
View File
@@ -1,29 +0,0 @@
import { createServerClient } from '@supabase/ssr'
import { cookies } from 'next/headers'
export async function createClient() {
const cookieStore = await cookies()
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll()
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) => {
cookieStore.set(name, value, options)
})
} catch {
// The `set` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
)
}