mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 15:08:38 +01:00
STRIPE_SECRET_KEY and the seven other STRIPE_* vars appear zero times outside
src/ and zero times in .env.example, so isStripeReady() could only ever return
false. Three API routes, a checkout route, a tier grid and a "Manage
subscription" button were all gated on it and permanently unreachable.
Confirmed empty in production before touching the schema:
select count(*) filter (where stripe_customer_id is not null),
count(*) filter (where stripe_subscription_id is not null),
count(*) from users;
→ 0 | 0 | 7
So this removes no data and, more to the point, changes nothing a user sees:
every code path already fell through to the branch below it.
WHAT STAYS. Plans are real and untouched. They are granted through the
OrangeCat/Bitcoin rail (/api/orangecat/entitlement -> recordOcBillingGrant),
with the expiry cron reverting a lapsed pass to free. The pricing CTA cascade
loses only its unreachable middle step: free -> TBA -> [stripe] -> BTC ->
start-free.
WHAT WAS ACTIVELY WRONG. Because isStripeReady() was false, the one part of
Billing that DID render was a notice telling the reader to "add
STRIPE_SECRET_KEY and price IDs" — an environment variable shown to a person
who does not deploy the app and could not act on it. That is the same mistake
NotificationsPill's comment already calls out. Billing now states the plan and
links to /pricing.
Removed: lib/stripe.ts, api/stripe/{checkout,portal,webhook}, api/checkout/
[plan], getUserByStripeCustomerId, two user columns (migration 0063), two
entries from the user-client-view redaction lists, the api/stripe/webhook entry
in proxy.ts's public matcher, the stripe npm dependency, and the smoke/auth
probes for routes that no longer exist.
BillingSettings drops "use client" — with the handlers gone it holds no state,
no effect and no search-param read.
Two mentions deliberately KEPT because they are not the rail: the placeholder
prose describing what a user might build ("Simple dashboard, automated
reminders, Stripe payments…") and the demo project's stack string.
pnpm run verify green. 28 files, 519 deletions.
Claude-Session: https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
115 lines
4.3 KiB
TypeScript
115 lines
4.3 KiB
TypeScript
// GET /api/me returned the user row verbatim, so every authenticated page load
|
|
// shipped `passwordHash` and `privateZonePinHash` to the browser. These cases
|
|
// pin the projection that stops it (src/lib/user-client-view.ts) — and, more
|
|
// importantly, pin it against the column added TOMORROW: the schema is the SSOT
|
|
// this test reads, so a new field fails the suite until it is classified.
|
|
// Run: npx tsx scripts/test/user-client-view.ts
|
|
import { getTableColumns } from "drizzle-orm";
|
|
import { users, type User } from "@/db/schema/users";
|
|
import { USER_CLIENT_FIELDS, USER_WITHHELD_FIELDS, toClientUser } from "@/lib/user-client-view";
|
|
|
|
let pass = 0;
|
|
let fail = 0;
|
|
function ok(cond: boolean, label: string) {
|
|
if (cond) {
|
|
pass++;
|
|
} else {
|
|
fail++;
|
|
console.error(`✗ ${label}`);
|
|
}
|
|
}
|
|
function eq(actual: unknown, expected: unknown, label: string) {
|
|
ok(
|
|
JSON.stringify(actual) === JSON.stringify(expected),
|
|
`${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`,
|
|
);
|
|
}
|
|
|
|
const schemaColumns = Object.keys(getTableColumns(users)).sort();
|
|
const exposed = new Set<string>(USER_CLIENT_FIELDS);
|
|
const withheld = new Set<string>(Object.keys(USER_WITHHELD_FIELDS));
|
|
|
|
// --- exhaustiveness: every column is classified, exactly once ------------------
|
|
|
|
for (const column of schemaColumns) {
|
|
const inExposed = exposed.has(column);
|
|
const inWithheld = withheld.has(column);
|
|
ok(
|
|
inExposed !== inWithheld,
|
|
inExposed && inWithheld
|
|
? `users.${column} is in BOTH lists — say which one`
|
|
: `users.${column} is in NEITHER list — classify it as exposed or withheld in src/lib/user-client-view.ts`,
|
|
);
|
|
}
|
|
|
|
// ...and neither list names a column that no longer exists.
|
|
const schemaSet = new Set(schemaColumns);
|
|
for (const field of [...exposed, ...withheld]) {
|
|
ok(schemaSet.has(field), `"${field}" is classified but is not a column on users — stale entry`);
|
|
}
|
|
|
|
// Every withheld field carries the reason it can never be sent.
|
|
for (const [field, reason] of Object.entries(USER_WITHHELD_FIELDS)) {
|
|
ok(
|
|
typeof reason === "string" && reason.length > 20,
|
|
`users.${field} is withheld without a stated reason`,
|
|
);
|
|
}
|
|
|
|
// The two that started this. Named explicitly so a future "simplification" that
|
|
// re-exposes them fails here and not in a page response.
|
|
ok(withheld.has("passwordHash"), "passwordHash must never reach the client");
|
|
ok(withheld.has("privateZonePinHash"), "privateZonePinHash must never reach the client");
|
|
|
|
// --- the projection actually drops them ---------------------------------------
|
|
|
|
const row: User = {
|
|
id: "00000000-0000-0000-0000-000000000001",
|
|
name: "Test Person",
|
|
email: "test@example.com",
|
|
emailVerified: new Date("2026-01-01T00:00:00Z"),
|
|
image: null,
|
|
username: "testperson",
|
|
passwordHash: "4f7d37130615776551e8af20f2749a19",
|
|
isDefault: false,
|
|
onboardedAt: null,
|
|
orangecatActorId: null,
|
|
plan: "free",
|
|
planStatus: null,
|
|
planExpiresAt: null,
|
|
privateZonePinHash: "deadbeef.cafe",
|
|
privateZonePinSetAt: new Date("2026-02-01T00:00:00Z"),
|
|
fleetSettings: {},
|
|
createdAt: new Date("2026-01-01T00:00:00Z"),
|
|
updatedAt: new Date("2026-01-01T00:00:00Z"),
|
|
};
|
|
|
|
const view = toClientUser(row);
|
|
const viewKeys = Object.keys(view).sort();
|
|
|
|
eq(viewKeys, [...USER_CLIENT_FIELDS].sort(), "projection returns exactly the exposed fields");
|
|
ok(!("passwordHash" in view), "projection drops passwordHash");
|
|
ok(!("privateZonePinHash" in view), "projection drops privateZonePinHash");
|
|
|
|
// The serialized response is what actually crosses the wire — assert on that,
|
|
// not just on the object, so a stray toJSON or getter cannot smuggle a field.
|
|
const wire = JSON.stringify(view);
|
|
ok(!wire.includes(row.passwordHash!), "serialized response does not contain the password hash");
|
|
ok(!wire.includes(row.privateZonePinHash!), "serialized response does not contain the PIN hash");
|
|
|
|
// What the app needs still survives — the smoke test asserts on id, Settings on
|
|
// name/username/plan, and the private-zone UI on whether a PIN was ever set.
|
|
eq(view.id, row.id, "id survives");
|
|
eq(view.username, row.username, "username survives");
|
|
eq(view.plan, row.plan, "plan survives");
|
|
eq(
|
|
view.privateZonePinSetAt,
|
|
row.privateZonePinSetAt,
|
|
"privateZonePinSetAt survives (the fact, not the secret)",
|
|
);
|
|
|
|
console.log(
|
|
`${pass}/${pass + fail} user-client-view cases passed (${schemaColumns.length} columns classified)`,
|
|
);
|
|
if (fail > 0) process.exit(1);
|