feat: sase.tr v2 full application implementation
Complete rewrite of sase.tr VIN lookup platform with modern stack: Backend (NestJS 10 + Drizzle ORM + PostgreSQL + Redis + BullMQ): - 34 DB models (core + PL24 + EMEX schemas) - Auth via Better Auth (email/password + social) - Brands, Plans, Subscriptions, Payments (iyzico + EFT) - VIN decode orchestration (Corgi + PL24 + EMEX + NHTSA) - Interactive schema viewer backend (MinIO storage) - EMEX scraping integration (Puppeteer + BullMQ workers) - Translation module (EN→TR automotive dictionary) - Admin dashboard API (stats, user mgmt, payment approval) - Rate limiting, Helmet security, file upload validation Frontend (Next.js 15 + Tailwind v4 + shadcn/ui + TanStack Query + Zustand): - 20 routes: auth, dashboard, VIN search, schema viewer, admin - Interactive schema viewer with zoom/pan/hotspot highlighting - Subscription management with brand selector - Payment flow (iyzico 3D Secure + EFT with receipt upload) - i18n support (TR/EN) - Error boundaries, loading skeletons, 404 page Infrastructure: - 85 tests (52 backend + 33 frontend, Vitest) - CI/CD (GitHub Actions: lint, typecheck, test, build, deploy) - Zero-downtime deploy script (PM2) - Env validation script Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
61
apps/api/src/integrations/pl24/pl24-auth.service.ts
Normal file
61
apps/api/src/integrations/pl24/pl24-auth.service.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { RedisService } from "../../redis/redis.service";
|
||||
import { PL24_DEFAULTS } from "./pl24.constants";
|
||||
|
||||
@Injectable()
|
||||
export class PL24AuthService {
|
||||
private readonly logger = new Logger(PL24AuthService.name);
|
||||
private readonly cacheKey = `${PL24_DEFAULTS.CACHE_PREFIX}auth_token`;
|
||||
|
||||
constructor(
|
||||
private configService: ConfigService,
|
||||
private redis: RedisService,
|
||||
) {}
|
||||
|
||||
async getToken(): Promise<string> {
|
||||
// Check Redis cache
|
||||
const cached = await this.redis.get(this.cacheKey);
|
||||
if (cached) return cached;
|
||||
|
||||
// Authenticate with PL24
|
||||
const token = await this.authenticate();
|
||||
await this.redis.set(this.cacheKey, token, PL24_DEFAULTS.AUTH_TOKEN_TTL);
|
||||
return token;
|
||||
}
|
||||
|
||||
private async authenticate(): Promise<string> {
|
||||
const apiUrl = this.configService.get<string>("pl24.apiUrl");
|
||||
const username = this.configService.get<string>("pl24.username");
|
||||
const password = this.configService.get<string>("pl24.password");
|
||||
|
||||
if (!apiUrl || !username || !password) {
|
||||
this.logger.warn("PL24 credentials not configured");
|
||||
throw new Error("PL24 credentials not configured");
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiUrl}/auth/login`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password }),
|
||||
signal: AbortSignal.timeout(PL24_DEFAULTS.REQUEST_TIMEOUT),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`PL24 auth failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as { token: string };
|
||||
this.logger.log("PL24 authenticated successfully");
|
||||
return data.token;
|
||||
} catch (error) {
|
||||
this.logger.error("PL24 authentication failed", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async invalidateToken(): Promise<void> {
|
||||
await this.redis.del(this.cacheKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user