style(13-03): apply Prettier formatting across repo
Mechanical reformat — no logic changes. 398 files changed, 19125 insertions(+), 16457 deletions(-). Prettier 3.8.4 with .prettierrc (singleQuote:true, semi:true, tabWidth:2, trailingComma:all, printWidth:100). Isolated per D-13-08 for reviewability.
This commit is contained in:
+38
-38
@@ -12,19 +12,19 @@
|
||||
* Mounted under /api/push in index.ts.
|
||||
*/
|
||||
|
||||
import { Hono } from 'hono'
|
||||
import type { Context } from 'hono'
|
||||
import { zValidator } from '@hono/zod-validator'
|
||||
import { z } from 'zod'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import { db } from '../db/client.js'
|
||||
import { pushSubscriptions } from '../db/schema.js'
|
||||
import { getAuth } from '../auth/middleware.js'
|
||||
import { upsertUser, deriveDisplayName } from '../auth/user.js'
|
||||
import { Hono } from 'hono';
|
||||
import type { Context } from 'hono';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
import { z } from 'zod';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { db } from '../db/client.js';
|
||||
import { pushSubscriptions } from '../db/schema.js';
|
||||
import { getAuth } from '../auth/middleware.js';
|
||||
import { upsertUser, deriveDisplayName } from '../auth/user.js';
|
||||
// Side-effect import: brings in the ContextVariableMap augmentation for c.get('user')
|
||||
import '../auth/devBypass.js'
|
||||
import '../auth/devBypass.js';
|
||||
|
||||
export const pushRouter = new Hono()
|
||||
export const pushRouter = new Hono();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Auth helper — Duplicated per router (not extracted to shared module).
|
||||
@@ -35,17 +35,17 @@ export const pushRouter = new Hono()
|
||||
// 2. OIDC path: call getAuth(c). If null → unauthenticated, return null.
|
||||
// ---------------------------------------------------------------------------
|
||||
async function resolveUserId(c: Context): Promise<number | null> {
|
||||
const devUser = c.get('user') as { id: number } | undefined
|
||||
if (devUser) return devUser.id
|
||||
const devUser = c.get('user') as { id: number } | undefined;
|
||||
if (devUser) return devUser.id;
|
||||
|
||||
const auth = await getAuth(c)
|
||||
if (!auth) return null
|
||||
const auth = await getAuth(c);
|
||||
if (!auth) return null;
|
||||
|
||||
const iss = (auth.iss as string | undefined) ?? ''
|
||||
const sub = auth.sub ?? ''
|
||||
const displayName = deriveDisplayName(auth)
|
||||
const user = await upsertUser(iss, sub, displayName)
|
||||
return user?.id ?? null
|
||||
const iss = (auth.iss as string | undefined) ?? '';
|
||||
const sub = auth.sub ?? '';
|
||||
const displayName = deriveDisplayName(auth);
|
||||
const user = await upsertUser(iss, sub, displayName);
|
||||
return user?.id ?? null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -63,7 +63,7 @@ const subscribeSchema = z.object({
|
||||
p256dh: z.string().min(1).max(512),
|
||||
auth: z.string().min(1).max(256),
|
||||
}),
|
||||
})
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GET /api/push/vapid-public-key
|
||||
@@ -76,8 +76,8 @@ const subscribeSchema = z.object({
|
||||
// subscribe to push anyway).
|
||||
// ---------------------------------------------------------------------------
|
||||
pushRouter.get('/vapid-public-key', (c) => {
|
||||
return c.json({ publicKey: process.env.VAPID_PUBLIC_KEY ?? '' })
|
||||
})
|
||||
return c.json({ publicKey: process.env.VAPID_PUBLIC_KEY ?? '' });
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// POST /api/push/subscription
|
||||
@@ -90,10 +90,10 @@ pushRouter.get('/vapid-public-key', (c) => {
|
||||
// T-05-10 — zod subscribeSchema validates all fields before DB write.
|
||||
// ---------------------------------------------------------------------------
|
||||
pushRouter.post('/subscription', zValidator('json', subscribeSchema), async (c) => {
|
||||
const userId = await resolveUserId(c)
|
||||
if (!userId) return c.json({ error: 'Unauthorized' }, 401)
|
||||
const userId = await resolveUserId(c);
|
||||
if (!userId) return c.json({ error: 'Unauthorized' }, 401);
|
||||
|
||||
const body = c.req.valid('json')
|
||||
const body = c.req.valid('json');
|
||||
|
||||
try {
|
||||
await db
|
||||
@@ -110,17 +110,17 @@ pushRouter.post('/subscription', zValidator('json', subscribeSchema), async (c)
|
||||
p256dh: body.keys.p256dh,
|
||||
auth: body.keys.auth,
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
return c.json({ ok: true }, 201)
|
||||
return c.json({ ok: true }, 201);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
'[push/POST /subscription] DB operation failed:',
|
||||
err instanceof Error ? err.message : String(err),
|
||||
)
|
||||
return c.json({ error: 'Service unavailable' }, 503)
|
||||
);
|
||||
return c.json({ error: 'Service unavailable' }, 503);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DELETE /api/push/subscription
|
||||
@@ -129,17 +129,17 @@ pushRouter.post('/subscription', zValidator('json', subscribeSchema), async (c)
|
||||
// Scoped to caller only — cannot delete another member's subscriptions (T-05-13).
|
||||
// ---------------------------------------------------------------------------
|
||||
pushRouter.delete('/subscription', async (c) => {
|
||||
const userId = await resolveUserId(c)
|
||||
if (!userId) return c.json({ error: 'Unauthorized' }, 401)
|
||||
const userId = await resolveUserId(c);
|
||||
if (!userId) return c.json({ error: 'Unauthorized' }, 401);
|
||||
|
||||
try {
|
||||
await db.delete(pushSubscriptions).where(eq(pushSubscriptions.userId, userId))
|
||||
return c.json({ ok: true })
|
||||
await db.delete(pushSubscriptions).where(eq(pushSubscriptions.userId, userId));
|
||||
return c.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error(
|
||||
'[push/DELETE /subscription] DB operation failed:',
|
||||
err instanceof Error ? err.message : String(err),
|
||||
)
|
||||
return c.json({ error: 'Service unavailable' }, 503)
|
||||
);
|
||||
return c.json({ error: 'Service unavailable' }, 503);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user