docs: remove free tier, update rate limits and auth for demo+pro model
- Remove free tier from rate limits, add Demo (5/hour, watermarked) - Update auth section: remove free-tier key mention, link to docfast.dev - Update getting started: demo → upgrade to Pro → use API key - Add deprecated: true to /v1/signup/free swagger annotation - Regenerate openapi.json
This commit is contained in:
parent
c35ff2bc97
commit
45b5be248c
8 changed files with 1118 additions and 11 deletions
44
dist/services/keys.js
vendored
44
dist/services/keys.js
vendored
|
|
@ -60,21 +60,37 @@ export async function createFreeKey(email) {
|
|||
return entry;
|
||||
}
|
||||
export async function createProKey(email, stripeCustomerId) {
|
||||
// Check in-memory cache first (fast path)
|
||||
const existing = keysCache.find((k) => k.stripeCustomerId === stripeCustomerId);
|
||||
if (existing) {
|
||||
existing.tier = "pro";
|
||||
await queryWithRetry("UPDATE api_keys SET tier = 'pro' WHERE key = $1", [existing.key]);
|
||||
return existing;
|
||||
}
|
||||
// UPSERT: handles duplicate webhooks across pods via DB unique index
|
||||
const newKey = generateKey("df_pro");
|
||||
const now = new Date().toISOString();
|
||||
const result = await queryWithRetry(`INSERT INTO api_keys (key, tier, email, created_at, stripe_customer_id)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (stripe_customer_id) WHERE stripe_customer_id IS NOT NULL
|
||||
DO UPDATE SET tier = 'pro'
|
||||
RETURNING key, tier, email, created_at, stripe_customer_id`, [newKey, "pro", email, now, stripeCustomerId]);
|
||||
const row = result.rows[0];
|
||||
const entry = {
|
||||
key: generateKey("df_pro"),
|
||||
tier: "pro",
|
||||
email,
|
||||
createdAt: new Date().toISOString(),
|
||||
stripeCustomerId,
|
||||
key: row.key,
|
||||
tier: row.tier,
|
||||
email: row.email,
|
||||
createdAt: row.created_at instanceof Date ? row.created_at.toISOString() : row.created_at,
|
||||
stripeCustomerId: row.stripe_customer_id || undefined,
|
||||
};
|
||||
await queryWithRetry("INSERT INTO api_keys (key, tier, email, created_at, stripe_customer_id) VALUES ($1, $2, $3, $4, $5)", [entry.key, entry.tier, entry.email, entry.createdAt, entry.stripeCustomerId]);
|
||||
keysCache.push(entry);
|
||||
// Refresh in-memory cache
|
||||
const cacheIdx = keysCache.findIndex((k) => k.stripeCustomerId === stripeCustomerId);
|
||||
if (cacheIdx >= 0) {
|
||||
keysCache[cacheIdx] = entry;
|
||||
}
|
||||
else {
|
||||
keysCache.push(entry);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
export async function downgradeByCustomer(stripeCustomerId) {
|
||||
|
|
@ -86,6 +102,20 @@ export async function downgradeByCustomer(stripeCustomerId) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export async function findKeyByCustomerId(stripeCustomerId) {
|
||||
// Check DB directly — survives pod restarts unlike in-memory cache
|
||||
const result = await queryWithRetry("SELECT key, tier, email, created_at, stripe_customer_id FROM api_keys WHERE stripe_customer_id = $1 LIMIT 1", [stripeCustomerId]);
|
||||
if (result.rows.length === 0)
|
||||
return null;
|
||||
const r = result.rows[0];
|
||||
return {
|
||||
key: r.key,
|
||||
tier: r.tier,
|
||||
email: r.email,
|
||||
createdAt: r.created_at instanceof Date ? r.created_at.toISOString() : r.created_at,
|
||||
stripeCustomerId: r.stripe_customer_id || undefined,
|
||||
};
|
||||
}
|
||||
export function getAllKeys() {
|
||||
return [...keysCache];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue