Kapalı-beta public API temeli (rapor: api-widget-analizi-2026-07-03): - better-auth apiKey plugin (defaultPrefix sase_, enableMetadata, anahtar başına 120 istek/dk); enableSessionForAPIKeys KAPALI — anahtar dashboard oturumu yerine geçmez, cookie AuthGuard davranışı değişmez - apikeys tablosu (migration 0023, plugin şemasının birebir karşılığı) - ApiKeyGuard: Authorization Bearer / x-api-key → verifyApiKey → kullanıcı yüklenir (status kontrolü), request.user + request.apiKey doldurulur - /api/v1/vin/decode: mevcut slim kontrat + aday akışı; günlük başarılı-decode kotası (Redis, TR günü, aynı VIN idempotent; limit: key metadata dailyDecodeLimit → PUBLIC_API_DAILY_DECODE_LIMIT → 100) ve X-Decode-Quota-* header'ları - /api/v1/oem/:code: P çapraz-referans (kotasız) - internal/admin/api-keys: x-internal-token ile anahtar üret/listele/kapat (düz metin yalnız create cevabında) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
39 lines
1.5 KiB
SQL
39 lines
1.5 KiB
SQL
-- Public API anahtarları — better-auth `apiKey` plugin'inin tablosu (model
|
||
-- "apikey", usePlural → "apikeys"). Kolon seti plugin şemasının birebir
|
||
-- karşılığı; "key" kolonu secret'ın SHA256 hash'i (düz metin sadece üretim
|
||
-- anında bir kez gösterilir). "metadata" JSON string (dailyDecodeLimit gibi
|
||
-- anahtar-bazlı limitler burada taşınır).
|
||
CREATE TABLE IF NOT EXISTS "apikeys" (
|
||
"id" text PRIMARY KEY NOT NULL,
|
||
"name" text,
|
||
"start" text,
|
||
"prefix" text,
|
||
"key" text NOT NULL,
|
||
"user_id" uuid NOT NULL,
|
||
"refill_interval" integer,
|
||
"refill_amount" integer,
|
||
"last_refill_at" timestamp with time zone,
|
||
"enabled" boolean DEFAULT true NOT NULL,
|
||
"rate_limit_enabled" boolean DEFAULT true NOT NULL,
|
||
"rate_limit_time_window" integer,
|
||
"rate_limit_max" integer,
|
||
"request_count" integer DEFAULT 0 NOT NULL,
|
||
"remaining" integer,
|
||
"last_request" timestamp with time zone,
|
||
"expires_at" timestamp with time zone,
|
||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||
"permissions" text,
|
||
"metadata" text
|
||
);
|
||
--> statement-breakpoint
|
||
DO $$ BEGIN
|
||
ALTER TABLE "apikeys" ADD CONSTRAINT "apikeys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
||
EXCEPTION
|
||
WHEN duplicate_object THEN null;
|
||
END $$;
|
||
--> statement-breakpoint
|
||
CREATE INDEX IF NOT EXISTS "apikeys_key_idx" ON "apikeys" ("key");
|
||
--> statement-breakpoint
|
||
CREATE INDEX IF NOT EXISTS "apikeys_user_id_idx" ON "apikeys" ("user_id");
|