Files
crosscode-platform/apps/accounts/backend/src/privacy/notice.ts
T
joshuaandClaude Opus 5.5 069b66fd30 Accounts 1.0.0 backend: OIDC provider, sign-in steps, account and admin API
oidc-provider 9.13.3 with PKCE, ES256, crosscode.identity/1 claims and
back-channel logout; clients are the linked products (Connect). Sign-in
steps (password, sign-up, email check, 2FA and its setup, privacy notice,
news question, password reset) survive to the product. Account page and
admin API, church profile, export and deletion fan-out, Hub v2 client,
jobs. End-to-end tests with a test product on openid-client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:33:49 +02:00

46 lines
2.3 KiB
TypeScript

/**
* The privacy notice (ROADMAP-v3 §3, as Cross Events): versions an admin publishes, and who
* accepted which. Version 1 is the built-in notice; published versions are 2, 3, … Someone who
* accepted an older version is asked again before signing in to a product (§5 of the plan).
*/
import type { Ctx } from '../context.js';
import { church } from '../church/profile.js';
export const BUILT_IN_VERSION = 1;
export async function builtInNotice(ctx: Ctx) {
const c = await church(ctx);
const contact = c.contact.email ? ` You can reach us at ${c.contact.email}.` : '';
return {
version: BUILT_IN_VERSION,
title: `How ${c.name} looks after your information`,
body: [
`${c.name} keeps your name, email address and (if you give it) phone number so you can sign in to the church's websites and apps, and so we can contact you about what you've signed up for.`,
'We only send you news if you say yes, and you can change that at any time on your account page.',
'You can download everything we hold about you, or ask us to delete your account, from your account page. We keep a record of sign-ins to protect your account.',
`We don't sell or share your information. The services that store it for us are bound to keep it safe.${contact}`,
].join('\n\n'),
publishedAt: null as Date | null,
};
}
export async function currentNotice(ctx: Ctx) {
const latest = await ctx.db.privacyNotice.findFirst({ orderBy: { version: 'desc' } });
return latest ?? (await builtInNotice(ctx));
}
export async function currentNoticeVersion(ctx: Ctx): Promise<number> {
return (await currentNotice(ctx)).version;
}
export async function accept(ctx: Ctx, accountId: string, version: number) {
await ctx.db.noticeAcceptance.create({ data: { accountId, version, acceptedAt: ctx.now() } });
await ctx.db.account.update({ where: { id: accountId }, data: { noticeVersionAccepted: version } });
}
export async function publish(ctx: Ctx, input: { title: string; body: string }, actorId: string) {
const latest = await ctx.db.privacyNotice.findFirst({ orderBy: { version: 'desc' } });
const version = Math.max(BUILT_IN_VERSION, latest?.version ?? BUILT_IN_VERSION) + 1;
return ctx.db.privacyNotice.create({ data: { version, title: input.title, body: input.body, publishedAt: ctx.now(), publishedById: actorId } });
}