feat(api): complete phase 9 mobile contracts
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { getNetaDiscoveryDocument } from "@/server/api/v1/runtime";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export function GET() {
|
||||
try {
|
||||
return Response.json(getNetaDiscoveryDocument(), {
|
||||
headers: {
|
||||
"Cache-Control": "public, max-age=60, stale-while-revalidate=300",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Neta discovery failed", error);
|
||||
return Response.json(
|
||||
{
|
||||
protocol: "neta",
|
||||
discoveryVersion: 1,
|
||||
error: {
|
||||
code: "SERVICE_UNAVAILABLE",
|
||||
message: "Instance keşif bilgisi geçici olarak kullanılamıyor.",
|
||||
},
|
||||
},
|
||||
{
|
||||
status: 503,
|
||||
headers: {
|
||||
"Cache-Control": "no-store",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { apiV1Error, apiV1Success } from "@/server/api/v1/responses";
|
||||
import { checkReadiness } from "@/server/db/health";
|
||||
import { DomainError } from "@/server/domain/errors";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export function GET() {
|
||||
const readiness = checkReadiness();
|
||||
const checkedAt = new Date().toISOString();
|
||||
|
||||
if (!readiness.ok) {
|
||||
return apiV1Error(
|
||||
new DomainError(
|
||||
"SERVICE_UNAVAILABLE",
|
||||
"Instance henüz isteklere hazır değil.",
|
||||
{ checks: readiness.checks, checkedAt },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return apiV1Success({
|
||||
status: "ok",
|
||||
checks: readiness.checks,
|
||||
checkedAt,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { apiV1Error, apiV1Success } from "@/server/api/v1/responses";
|
||||
import { getSessionContextFromHeaders } from "@/server/auth/session";
|
||||
import { getServerConfig } from "@/server/config";
|
||||
import { DomainError } from "@/server/domain/errors";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const context = await getSessionContextFromHeaders(new Headers(request.headers));
|
||||
if (!context) {
|
||||
throw new DomainError("UNAUTHENTICATED", "Geçerli bir oturum gerekli.");
|
||||
}
|
||||
|
||||
return apiV1Success({
|
||||
user: {
|
||||
id: context.user.id,
|
||||
email: context.profile.email,
|
||||
displayName: context.profile.displayName,
|
||||
role: context.profile.role,
|
||||
clientId: context.profile.clientId,
|
||||
imageUrl: absoluteOptionalUrl(context.user.image),
|
||||
},
|
||||
session: {
|
||||
expiresAt: context.session.expiresAt.toISOString(),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return apiV1Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
function absoluteOptionalUrl(value: string | null | undefined): string | null {
|
||||
return value ? new URL(value, `${getServerConfig().appUrl}/`).toString() : null;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { apiV1Error, apiV1Success } from "@/server/api/v1/responses";
|
||||
import { getNetaInstanceMetadata } from "@/server/api/v1/runtime";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export function GET() {
|
||||
try {
|
||||
return apiV1Success(getNetaInstanceMetadata(), {
|
||||
headers: {
|
||||
"Cache-Control": "public, max-age=60, stale-while-revalidate=300",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return apiV1Error(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user