create-disposabl-app 0.17.5 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/disposabl.js +43 -10
- package/dist/index.js +64 -18
- package/dist/templates/default/apps/mobile/README.md +40 -0
- package/dist/templates/default/apps/mobile/app.config.js +46 -2
- package/dist/templates/default/apps/mobile/package.json +7 -1
- package/dist/templates/default/apps/mobile/plugins/with-android-signing.js +23 -1
- package/dist/templates/default/apps/mobile/scripts/fresh-android.mjs +24 -0
- package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +176 -0
- package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +77 -0
- package/dist/templates/default/bun.lock +12 -3
- package/dist/templates/default/bunfig.toml +1 -0
- package/dist/templates/default/package.json +6 -2
- package/dist/templates/default/packages/backend/convex/files/guard.ts +2 -0
- package/dist/templates/default/packages/backend/convex/http.ts +11 -1
- package/dist/templates/default/packages/backend/convex/schema.ts +10 -0
- package/dist/templates/default/packages/backend/convex/telemetry.ts +12 -16
- package/dist/templates/default/packages/cli/build.ts +4 -0
- package/dist/templates/default/packages/cli/package.json +2 -1
- package/dist/templates/default/packages/cli/telemetry.ts +40 -3
- package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +2 -0
- package/dist/templates/default/packages/disposabl-kit/client/components/account-deletion.tsx +111 -0
- package/dist/templates/default/packages/disposabl-kit/client/components/consent-identity.tsx +50 -0
- package/dist/templates/default/packages/disposabl-kit/client/components/legal-page.tsx +12 -1
- package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry-lease.ts +200 -0
- package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry.ts +8 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +23 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/legal/delete-account.tsx +6 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/legal/support.tsx +33 -0
- package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +13 -0
- package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +19 -2
- package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +1 -0
- package/dist/templates/default/packages/disposabl-kit/legal/README.md +1 -1
- package/dist/templates/default/packages/disposabl-kit/legal/config.ts +32 -4
- package/dist/templates/default/packages/disposabl-kit/legal/index.ts +2 -2
- package/dist/templates/default/packages/disposabl-kit/legal/publisher.ts +6 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +13 -9
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/paywall.ts +28 -4
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/policy.ts +31 -14
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +45 -34
- package/dist/templates/default/packages/disposabl-kit/mobile/components/settings-links.tsx +14 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +3 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +4 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +55 -8
- package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +147 -124
- package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +113 -95
- package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +70 -54
- package/dist/templates/default/packages/disposabl-kit/server/http.ts +49 -21
- package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +25 -1
- package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +375 -69
- package/dist/templates/default/packages/disposabl-kit/server/release/clients.mjs +28 -1
- package/dist/templates/default/packages/disposabl-kit/server/release/verify-metadata.mjs +64 -0
- package/dist/templates/default/packages/sdk/README.md +2 -0
- package/dist/templates/default/packages/sdk/build.ts +8 -0
- package/dist/templates/default/packages/sdk/package.json +3 -2
- package/dist/templates/default/packages/sdk/src/analytics.ts +7 -2
- package/dist/templates/default/packages/skill/SKILL.md +4 -2
- package/dist/templates/default/packages/skill/references/store-submissions.md +25 -0
- package/dist/templates/default/packages/tests/README.md +28 -1
- package/dist/templates/default/packages/tests/account-deletion-ui.test.ts +21 -0
- package/dist/templates/default/packages/tests/auth-email-setup.test.ts +45 -0
- package/dist/templates/default/packages/tests/components/account-deletion.test.mjs +82 -0
- package/dist/templates/default/packages/tests/components/consent-identity.test.mjs +175 -0
- package/dist/templates/default/packages/tests/components/mobile-deletion-link.test.mjs +40 -0
- package/dist/templates/default/packages/tests/components/mobile-theme.test.mjs +56 -3
- package/dist/templates/default/packages/tests/components/pricing-identity.test.mjs +113 -0
- package/dist/templates/default/packages/tests/components/support-page.test.mjs +36 -0
- package/dist/templates/default/packages/tests/consent-identity.test.ts +13 -0
- package/dist/templates/default/packages/tests/desktop-macos-release.test.ts +153 -145
- package/dist/templates/default/packages/tests/flows/legal.e2e.ts +40 -3
- package/dist/templates/default/packages/tests/helpers/auth-email-setup/probe.test.mjs +44 -0
- package/dist/templates/default/packages/tests/helpers/mobile-simulator/preflight.py +80 -0
- package/dist/templates/default/packages/tests/helpers/mobile-simulator/test_preflight.py +57 -0
- package/dist/templates/default/packages/tests/mobile-android-e2e-network.test.ts +81 -1
- package/dist/templates/default/packages/tests/mobile-android-signing.test.ts +52 -0
- package/dist/templates/default/packages/tests/mobile-deletion-link.test.ts +21 -0
- package/dist/templates/default/packages/tests/mobile-ios-reachability-pin.test.ts +84 -0
- package/dist/templates/default/packages/tests/mobile-simulator-preflight.test.ts +16 -0
- package/dist/templates/default/packages/tests/native-billing.test.ts +288 -0
- package/dist/templates/default/packages/tests/pricing-identity.test.ts +13 -0
- package/dist/templates/default/packages/tests/sdk-analytics.test.ts +28 -2
- package/dist/templates/default/packages/tests/support-page.test.ts +13 -0
- package/dist/templates/default/packages/tests/telemetry.test.ts +389 -18
- package/dist/templates/default/packages/tests/ui-telemetry-lease.test.ts +346 -0
- package/dist/templates/default/patches/convex-mcp-account-erasure-alpha7.patch +466 -0
- package/dist/templates/default/vendor/README.md +61 -1
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.patch +890 -0
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.patch +1060 -0
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.4.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.5.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.6.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.7.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.8.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-core-erasure-disposabl.6.patch +115 -0
- package/dist/templates/default/vendor/convex-auth-identity-cutoff-disposabl.7.patch +442 -0
- package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.md +11 -0
- package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.patch +78 -0
- package/dist/templates/default/vendor/convex-auth-marker-disposabl.4.patch +169 -0
- package/dist/templates/default/vendor/convex-auth-marker-password-disposabl.5.patch +126 -0
- package/dist/verify-metadata.mjs +64 -0
- package/package.json +3 -2
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
--- a/src/component/_generated/component.ts
|
|
2
|
+
+++ b/src/component/_generated/component.ts
|
|
3
|
+
@@ -24,6 +24,8 @@
|
|
4
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
5
|
+
{
|
|
6
|
+
public: {
|
|
7
|
+
+ beginUserErasure: FunctionReference<"mutation", "internal", {userId: string}, null, Name>;
|
|
8
|
+
+ purgeUserLinkedAuth: FunctionReference<"mutation", "internal", {userId: string}, {linkedRowsCleared: boolean; deletedAccounts: number; deletedSessions: number; deletedRefreshTokens: number; legacyOrphansUnverified: true}, Name>;
|
|
9
|
+
exchangeSession: FunctionReference<"mutation", "internal", {
|
|
10
|
+
sessionId: string; userId: string; accessTokenTtlSeconds: number;
|
|
11
|
+
refreshInactivityTimeoutSeconds: number; sessionMaxLifetimeSeconds: number;
|
|
12
|
+
--- a/src/component/public.ts
|
|
13
|
+
+++ b/src/component/public.ts
|
|
14
|
+
@@ -49,6 +49,14 @@
|
|
15
|
+
|
|
16
|
+
// --- Internal helpers ------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
+async function erasedUser(ctx: QueryCtx, userId: string) {
|
|
19
|
+
+ return await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique();
|
|
20
|
+
+}
|
|
21
|
+
+async function requireActiveUser(ctx: QueryCtx, userId: string) {
|
|
22
|
+
+ if (await erasedUser(ctx, userId)) throw new Error("Auth account is unavailable.");
|
|
23
|
+
+}
|
|
24
|
+
+
|
|
25
|
+
+
|
|
26
|
+
/** Look up an account by its provider identity. */
|
|
27
|
+
function accountByIdentity(
|
|
28
|
+
ctx: QueryCtx,
|
|
29
|
+
@@ -89,6 +97,7 @@
|
|
30
|
+
userId: string,
|
|
31
|
+
ttl: TtlConfig,
|
|
32
|
+
): Promise<TokenBundle> {
|
|
33
|
+
+ await requireActiveUser(ctx, userId);
|
|
34
|
+
const now = Date.now();
|
|
35
|
+
await evictLeastRecentlyRefreshedSessions(ctx, userId);
|
|
36
|
+
const sessionId = await ctx.db.insert("sessions", {
|
|
37
|
+
@@ -191,6 +200,7 @@
|
|
38
|
+
profile: claims.profile,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
+ await requireActiveUser(ctx, userId);
|
|
42
|
+
const { providerName } = claims;
|
|
43
|
+
const providerAccountId =
|
|
44
|
+
claims.providerAccountId === USE_USER_ID_AS_ACCOUNT_ID
|
|
45
|
+
@@ -318,6 +328,7 @@
|
|
46
|
+
`A first sign-in for an identity must go through signUp.`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
+ await requireActiveUser(ctx, account.userId);
|
|
50
|
+
await notifySignIn(ctx, claims, account.userId, args.onSignInHandle);
|
|
51
|
+
return await issueSession(ctx, account._id, account.userId, ttl);
|
|
52
|
+
},
|
|
53
|
+
@@ -396,7 +407,7 @@
|
|
54
|
+
const id = ctx.db.normalizeId("sessions", sessionId);
|
|
55
|
+
if (id === null) return null;
|
|
56
|
+
const session = await ctx.db.get("sessions", id);
|
|
57
|
+
- return session === null ? null : { userId: session.userId };
|
|
58
|
+
+ return session === null || await erasedUser(ctx, session.userId) ? null : { userId: session.userId };
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
@@ -454,7 +465,7 @@
|
|
63
|
+
// `deleteSession`), so a token can outlive its session for a moment. The
|
|
64
|
+
// session ended already, thus there is nothing to refresh or revoke.
|
|
65
|
+
const session = await ctx.db.get("sessions", token.sessionId);
|
|
66
|
+
- if (session === null) return { kind: "noSession" };
|
|
67
|
+
+ if (session === null || await erasedUser(ctx, session.userId)) return { kind: "noSession" };
|
|
68
|
+
|
|
69
|
+
switch (token.state) {
|
|
70
|
+
case "spent":
|
|
71
|
+
@@ -675,5 +686,34 @@
|
|
72
|
+
if (!account || account.userId !== session.userId)
|
|
73
|
+
throw new Error("Source account is no longer active.");
|
|
74
|
+
return await issueSession(ctx, session.accountId, session.userId, ttl);
|
|
75
|
+
+ },
|
|
76
|
+
+});
|
|
77
|
+
+
|
|
78
|
+
+/** App-server-only fence. Coordinate with provider-component fences in one app mutation. */
|
|
79
|
+
+export const beginUserErasure = mutation({
|
|
80
|
+
+ args: { userId: v.string() }, returns: v.null(),
|
|
81
|
+
+ handler: async (ctx, { userId }) => {
|
|
82
|
+
+ if (!userId) throw new Error("Missing user ID.");
|
|
83
|
+
+ if (!(await erasedUser(ctx, userId))) await ctx.db.insert("erasedUsers", { userId, requestedAt: Date.now() });
|
|
84
|
+
+ return null;
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
+/** Bounded cleanup of linked records only; older orphan refresh tokens lack a user join. */
|
|
88
|
+
+export const purgeUserLinkedAuth = mutation({
|
|
89
|
+
+ args: { userId: v.string() },
|
|
90
|
+
+ returns: v.object({ linkedRowsCleared: v.boolean(), deletedAccounts: v.number(), deletedSessions: v.number(), deletedRefreshTokens: v.number(), legacyOrphansUnverified: v.literal(true) }),
|
|
91
|
+
+ handler: async (ctx, { userId }) => {
|
|
92
|
+
+ if (!(await erasedUser(ctx, userId))) throw new Error("Begin auth erasure first.");
|
|
93
|
+
+ const session = await ctx.db.query("sessions").withIndex("by_user", q => q.eq("userId", userId)).first();
|
|
94
|
+
+ if (session) {
|
|
95
|
+
+ const tokens = await ctx.db.query("refreshTokens").withIndex("by_session_state", q => q.eq("sessionId", session._id)).take(101);
|
|
96
|
+
+ for (const token of tokens.slice(0, 100)) await ctx.db.delete("refreshTokens", token._id);
|
|
97
|
+
+ const deletedSessions = tokens.length <= 100 ? 1 : 0;
|
|
98
|
+
+ if (deletedSessions) await ctx.db.delete("sessions", session._id);
|
|
99
|
+
+ return { linkedRowsCleared: false, deletedAccounts: 0, deletedSessions, deletedRefreshTokens: Math.min(tokens.length,100), legacyOrphansUnverified: true as const };
|
|
100
|
+
+ }
|
|
101
|
+
+ const accounts = await ctx.db.query("accounts").withIndex("by_user", q => q.eq("userId", userId)).take(101);
|
|
102
|
+
+ for (const account of accounts.slice(0, 100)) await ctx.db.delete("accounts", account._id);
|
|
103
|
+
+ return { linkedRowsCleared: accounts.length <= 100, deletedAccounts: Math.min(accounts.length,100), deletedSessions: 0, deletedRefreshTokens: 0, legacyOrphansUnverified: true as const };
|
|
104
|
+
+ },
|
|
105
|
+
+});
|
|
106
|
+
--- a/src/component/schema.ts
|
|
107
|
+
+++ b/src/component/schema.ts
|
|
108
|
+
@@ -2,6 +2,7 @@
|
|
109
|
+
import { v } from "convex/values";
|
|
110
|
+
|
|
111
|
+
export default defineSchema({
|
|
112
|
+
+ erasedUsers: defineTable({ userId: v.string(), requestedAt: v.number() }).index("by_userId", ["userId"]),
|
|
113
|
+
// Maps a provider-scoped identity to an opaque app user id. The app owns the
|
|
114
|
+
// actual users table; we only store the id string it gives us back.
|
|
115
|
+
accounts: defineTable({
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
--- a/src/methods/google/server.ts
|
|
2
|
+
+++ b/src/methods/google/server.ts
|
|
3
|
+
@@ -72,7 +72,11 @@
|
|
4
|
+
*/
|
|
5
|
+
allowedRedirectOrigins: string[];
|
|
6
|
+
/** Server-only pre-sign-in check; undefined is legacy authorization proof. */
|
|
7
|
+
- checkAuthorizationStart?: (ctx: GenericMutationCtx<GenericDataModel>, profile: GoogleProfile, startedAt: number | undefined) => Promise<void>;
|
|
8
|
+
+ checkAuthorizationStart?: (
|
|
9
|
+
+ ctx: GenericMutationCtx<GenericDataModel>,
|
|
10
|
+
+ profile: GoogleProfile,
|
|
11
|
+
+ startedAt: number | undefined,
|
|
12
|
+
+ ) => Promise<void>;
|
|
13
|
+
/** Optional signed state envelope for a shared callback. */
|
|
14
|
+
authorizationState?: (state: string) => Promise<string>;
|
|
15
|
+
};
|
|
16
|
+
@@ -138,6 +142,7 @@
|
|
17
|
+
{ claims?: OidcClaims }
|
|
18
|
+
>({
|
|
19
|
+
providerName: PROVIDER_NAME,
|
|
20
|
+
+ enforceIdentityErasure: true,
|
|
21
|
+
authMutation,
|
|
22
|
+
checkAuthorizationStart: options.checkAuthorizationStart,
|
|
23
|
+
claimTicket: (ctx, args) =>
|
|
24
|
+
--- a/src/component/public.ts
|
|
25
|
+
+++ b/src/component/public.ts
|
|
26
|
+
@@ -50,13 +50,34 @@
|
|
27
|
+
// --- Internal helpers ------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
async function erasedUser(ctx: QueryCtx, userId: string) {
|
|
30
|
+
- return await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique();
|
|
31
|
+
+ return await ctx.db
|
|
32
|
+
+ .query("erasedUsers")
|
|
33
|
+
+ .withIndex("by_userId", (q) => q.eq("userId", userId))
|
|
34
|
+
+ .unique();
|
|
35
|
+
+}
|
|
36
|
+
+// Pseudonymous, stable and potentially guessable; retention policy is required.
|
|
37
|
+
+async function identityDigest(provider: string, account: string) {
|
|
38
|
+
+ return sha256Hex(JSON.stringify([provider, account]));
|
|
39
|
+
+}
|
|
40
|
+
+async function identityCutoff(
|
|
41
|
+
+ ctx: QueryCtx,
|
|
42
|
+
+ provider: string,
|
|
43
|
+
+ account: string,
|
|
44
|
+
+): Promise<number | null> {
|
|
45
|
+
+ const digest = await identityDigest(provider, account);
|
|
46
|
+
+ const tombstone = await ctx.db
|
|
47
|
+
+ .query("identityErasure")
|
|
48
|
+
+ .withIndex("by_digest", (q) => q.eq("digest", digest))
|
|
49
|
+
+ .unique();
|
|
50
|
+
+ const mapped = await accountByIdentity(ctx, provider, account);
|
|
51
|
+
+ const user = mapped ? await erasedUser(ctx, mapped.userId) : null;
|
|
52
|
+
+ return Math.max(tombstone?.cutoff ?? 0, user?.requestedAt ?? 0) || null;
|
|
53
|
+
}
|
|
54
|
+
async function requireActiveUser(ctx: QueryCtx, userId: string) {
|
|
55
|
+
- if (await erasedUser(ctx, userId)) throw new Error("Auth account is unavailable.");
|
|
56
|
+
+ if (await erasedUser(ctx, userId))
|
|
57
|
+
+ throw new Error("Auth account is unavailable.");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
-
|
|
61
|
+
/** Look up an account by its provider identity. */
|
|
62
|
+
function accountByIdentity(
|
|
63
|
+
ctx: QueryCtx,
|
|
64
|
+
@@ -175,6 +196,10 @@
|
|
65
|
+
// identifier), so there is nothing to check yet; the pre-insert check below
|
|
66
|
+
// covers that path once the key is known.
|
|
67
|
+
if (claims.providerAccountId !== USE_USER_ID_AS_ACCOUNT_ID) {
|
|
68
|
+
+ if (
|
|
69
|
+
+ await identityCutoff(ctx, claims.providerName, claims.providerAccountId)
|
|
70
|
+
+ )
|
|
71
|
+
+ throw new Error("Identity registration is unavailable.");
|
|
72
|
+
const account = await accountByIdentity(
|
|
73
|
+
ctx,
|
|
74
|
+
claims.providerName,
|
|
75
|
+
@@ -206,6 +231,8 @@
|
|
76
|
+
claims.providerAccountId === USE_USER_ID_AS_ACCOUNT_ID
|
|
77
|
+
? userId
|
|
78
|
+
: claims.providerAccountId;
|
|
79
|
+
+ if (await identityCutoff(ctx, providerName, providerAccountId))
|
|
80
|
+
+ throw new Error("Identity registration is unavailable.");
|
|
81
|
+
// The last word on uniqueness, for the `USE_USER_ID_AS_ACCOUNT_ID` path,
|
|
82
|
+
// whose key is only known now. Redundant for every other path, and cheap.
|
|
83
|
+
const existingAccount = await ctx.db
|
|
84
|
+
@@ -407,7 +434,9 @@
|
|
85
|
+
const id = ctx.db.normalizeId("sessions", sessionId);
|
|
86
|
+
if (id === null) return null;
|
|
87
|
+
const session = await ctx.db.get("sessions", id);
|
|
88
|
+
- return session === null || await erasedUser(ctx, session.userId) ? null : { userId: session.userId };
|
|
89
|
+
+ return session === null || (await erasedUser(ctx, session.userId))
|
|
90
|
+
+ ? null
|
|
91
|
+
+ : { userId: session.userId };
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
@@ -465,7 +494,8 @@
|
|
96
|
+
// `deleteSession`), so a token can outlive its session for a moment. The
|
|
97
|
+
// session ended already, thus there is nothing to refresh or revoke.
|
|
98
|
+
const session = await ctx.db.get("sessions", token.sessionId);
|
|
99
|
+
- if (session === null || await erasedUser(ctx, session.userId)) return { kind: "noSession" };
|
|
100
|
+
+ if (session === null || (await erasedUser(ctx, session.userId)))
|
|
101
|
+
+ return { kind: "noSession" };
|
|
102
|
+
|
|
103
|
+
switch (token.state) {
|
|
104
|
+
case "spent":
|
|
105
|
+
@@ -678,9 +708,14 @@
|
|
106
|
+
throw new Error("Source session is no longer active.");
|
|
107
|
+
const latest = await newestIssuedToken(ctx, session._id);
|
|
108
|
+
const now = Date.now();
|
|
109
|
+
- if (!latest ||
|
|
110
|
+
- refreshTokenInactivityExpiresAt(latest, ttl.refreshInactivityTimeoutSeconds) <= now ||
|
|
111
|
+
- sessionMaxLifetimeExpiresAt(session, ttl.sessionMaxLifetimeSeconds) <= now)
|
|
112
|
+
+ if (
|
|
113
|
+
+ !latest ||
|
|
114
|
+
+ refreshTokenInactivityExpiresAt(
|
|
115
|
+
+ latest,
|
|
116
|
+
+ ttl.refreshInactivityTimeoutSeconds,
|
|
117
|
+
+ ) <= now ||
|
|
118
|
+
+ sessionMaxLifetimeExpiresAt(session, ttl.sessionMaxLifetimeSeconds) <= now
|
|
119
|
+
+ )
|
|
120
|
+
throw new Error("Source session has expired.");
|
|
121
|
+
const account = await ctx.db.get("accounts", session.accountId);
|
|
122
|
+
if (!account || account.userId !== session.userId)
|
|
123
|
+
@@ -691,29 +726,107 @@
|
|
124
|
+
|
|
125
|
+
/** App-server-only fence. Coordinate with provider-component fences in one app mutation. */
|
|
126
|
+
export const beginUserErasure = mutation({
|
|
127
|
+
- args: { userId: v.string() }, returns: v.null(),
|
|
128
|
+
+ args: { userId: v.string() },
|
|
129
|
+
+ returns: v.null(),
|
|
130
|
+
handler: async (ctx, { userId }) => {
|
|
131
|
+
if (!userId) throw new Error("Missing user ID.");
|
|
132
|
+
- if (!(await erasedUser(ctx, userId))) await ctx.db.insert("erasedUsers", { userId, requestedAt: Date.now() });
|
|
133
|
+
+ if (!(await erasedUser(ctx, userId)))
|
|
134
|
+
+ await ctx.db.insert("erasedUsers", { userId, requestedAt: Date.now() });
|
|
135
|
+
return null;
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
/** Bounded cleanup of linked records only; older orphan refresh tokens lack a user join. */
|
|
139
|
+
export const purgeUserLinkedAuth = mutation({
|
|
140
|
+
args: { userId: v.string() },
|
|
141
|
+
- returns: v.object({ linkedRowsCleared: v.boolean(), deletedAccounts: v.number(), deletedSessions: v.number(), deletedRefreshTokens: v.number(), legacyOrphansUnverified: v.literal(true) }),
|
|
142
|
+
+ returns: v.object({
|
|
143
|
+
+ linkedRowsCleared: v.boolean(),
|
|
144
|
+
+ deletedAccounts: v.number(),
|
|
145
|
+
+ deletedSessions: v.number(),
|
|
146
|
+
+ deletedRefreshTokens: v.number(),
|
|
147
|
+
+ legacyOrphansUnverified: v.literal(true),
|
|
148
|
+
+ }),
|
|
149
|
+
handler: async (ctx, { userId }) => {
|
|
150
|
+
- if (!(await erasedUser(ctx, userId))) throw new Error("Begin auth erasure first.");
|
|
151
|
+
- const session = await ctx.db.query("sessions").withIndex("by_user", q => q.eq("userId", userId)).first();
|
|
152
|
+
+ if (!(await erasedUser(ctx, userId)))
|
|
153
|
+
+ throw new Error("Begin auth erasure first.");
|
|
154
|
+
+ const receipt = await ctx.db
|
|
155
|
+
+ .query("sessionCleanupReceipts")
|
|
156
|
+
+ .withIndex("by_user", (q) => q.eq("userId", userId))
|
|
157
|
+
+ .first();
|
|
158
|
+
+ if (receipt) {
|
|
159
|
+
+ const tokens = await ctx.db
|
|
160
|
+
+ .query("refreshTokens")
|
|
161
|
+
+ .withIndex("by_session_state", (q) =>
|
|
162
|
+
+ q.eq("sessionId", receipt.sessionId),
|
|
163
|
+
+ )
|
|
164
|
+
+ .take(101);
|
|
165
|
+
+ for (const token of tokens.slice(0, 100))
|
|
166
|
+
+ await ctx.db.delete("refreshTokens", token._id);
|
|
167
|
+
+ if (tokens.length <= 100)
|
|
168
|
+
+ await ctx.db.delete("sessionCleanupReceipts", receipt._id);
|
|
169
|
+
+ return {
|
|
170
|
+
+ linkedRowsCleared: false,
|
|
171
|
+
+ deletedAccounts: 0,
|
|
172
|
+
+ deletedSessions: 0,
|
|
173
|
+
+ deletedRefreshTokens: Math.min(tokens.length, 100),
|
|
174
|
+
+ legacyOrphansUnverified: true as const,
|
|
175
|
+
+ };
|
|
176
|
+
+ }
|
|
177
|
+
+ const session = await ctx.db
|
|
178
|
+
+ .query("sessions")
|
|
179
|
+
+ .withIndex("by_user", (q) => q.eq("userId", userId))
|
|
180
|
+
+ .first();
|
|
181
|
+
if (session) {
|
|
182
|
+
- const tokens = await ctx.db.query("refreshTokens").withIndex("by_session_state", q => q.eq("sessionId", session._id)).take(101);
|
|
183
|
+
- for (const token of tokens.slice(0, 100)) await ctx.db.delete("refreshTokens", token._id);
|
|
184
|
+
+ const tokens = await ctx.db
|
|
185
|
+
+ .query("refreshTokens")
|
|
186
|
+
+ .withIndex("by_session_state", (q) => q.eq("sessionId", session._id))
|
|
187
|
+
+ .take(101);
|
|
188
|
+
+ for (const token of tokens.slice(0, 100))
|
|
189
|
+
+ await ctx.db.delete("refreshTokens", token._id);
|
|
190
|
+
const deletedSessions = tokens.length <= 100 ? 1 : 0;
|
|
191
|
+
if (deletedSessions) await ctx.db.delete("sessions", session._id);
|
|
192
|
+
- return { linkedRowsCleared: false, deletedAccounts: 0, deletedSessions, deletedRefreshTokens: Math.min(tokens.length,100), legacyOrphansUnverified: true as const };
|
|
193
|
+
+ return {
|
|
194
|
+
+ linkedRowsCleared: false,
|
|
195
|
+
+ deletedAccounts: 0,
|
|
196
|
+
+ deletedSessions,
|
|
197
|
+
+ deletedRefreshTokens: Math.min(tokens.length, 100),
|
|
198
|
+
+ legacyOrphansUnverified: true as const,
|
|
199
|
+
+ };
|
|
200
|
+
}
|
|
201
|
+
- const accounts = await ctx.db.query("accounts").withIndex("by_user", q => q.eq("userId", userId)).take(101);
|
|
202
|
+
- for (const account of accounts.slice(0, 100)) await ctx.db.delete("accounts", account._id);
|
|
203
|
+
- return { linkedRowsCleared: accounts.length <= 100, deletedAccounts: Math.min(accounts.length,100), deletedSessions: 0, deletedRefreshTokens: 0, legacyOrphansUnverified: true as const };
|
|
204
|
+
+ const accounts = await ctx.db
|
|
205
|
+
+ .query("accounts")
|
|
206
|
+
+ .withIndex("by_user", (q) => q.eq("userId", userId))
|
|
207
|
+
+ .take(101);
|
|
208
|
+
+ const cutoff = (await erasedUser(ctx, userId))!.requestedAt;
|
|
209
|
+
+ for (const account of accounts.slice(0, 100)) {
|
|
210
|
+
+ const digest = await identityDigest(
|
|
211
|
+
+ account.provider,
|
|
212
|
+
+ account.providerAccountId,
|
|
213
|
+
+ );
|
|
214
|
+
+ const prior = await ctx.db
|
|
215
|
+
+ .query("identityErasure")
|
|
216
|
+
+ .withIndex("by_digest", (q) => q.eq("digest", digest))
|
|
217
|
+
+ .unique();
|
|
218
|
+
+ if (prior)
|
|
219
|
+
+ await ctx.db.patch("identityErasure", prior._id, {
|
|
220
|
+
+ cutoff: Math.max(prior.cutoff, cutoff),
|
|
221
|
+
+ });
|
|
222
|
+
+ else await ctx.db.insert("identityErasure", { digest, cutoff });
|
|
223
|
+
+ await ctx.db.delete("accounts", account._id);
|
|
224
|
+
+ }
|
|
225
|
+
+ return {
|
|
226
|
+
+ linkedRowsCleared: accounts.length <= 100,
|
|
227
|
+
+ deletedAccounts: Math.min(accounts.length, 100),
|
|
228
|
+
+ deletedSessions: 0,
|
|
229
|
+
+ deletedRefreshTokens: 0,
|
|
230
|
+
+ legacyOrphansUnverified: true as const,
|
|
231
|
+
+ };
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
+
|
|
235
|
+
+/** App-server query: returns a cutoff while a mapped owner is fenced and after mapping purge. */
|
|
236
|
+
+export const getIdentityErasureCutoff = query({
|
|
237
|
+
+ args: { provider: v.string(), providerAccountId: v.string() },
|
|
238
|
+
+ returns: v.union(v.number(), v.null()),
|
|
239
|
+
+ handler: (ctx, { provider, providerAccountId }) =>
|
|
240
|
+
+ identityCutoff(ctx, provider, providerAccountId),
|
|
241
|
+
+});
|
|
242
|
+
--- a/src/component/schema.ts
|
|
243
|
+
+++ b/src/component/schema.ts
|
|
244
|
+
@@ -2,7 +2,20 @@
|
|
245
|
+
import { v } from "convex/values";
|
|
246
|
+
|
|
247
|
+
export default defineSchema({
|
|
248
|
+
- erasedUsers: defineTable({ userId: v.string(), requestedAt: v.number() }).index("by_userId", ["userId"]),
|
|
249
|
+
+ erasedUsers: defineTable({
|
|
250
|
+
+ userId: v.string(),
|
|
251
|
+
+ requestedAt: v.number(),
|
|
252
|
+
+ }).index("by_userId", ["userId"]),
|
|
253
|
+
+ identityErasure: defineTable({
|
|
254
|
+
+ digest: v.string(),
|
|
255
|
+
+ cutoff: v.number(),
|
|
256
|
+
+ }).index("by_digest", ["digest"]),
|
|
257
|
+
+ sessionCleanupReceipts: defineTable({
|
|
258
|
+
+ userId: v.string(),
|
|
259
|
+
+ sessionId: v.id("sessions"),
|
|
260
|
+
+ })
|
|
261
|
+
+ .index("by_user", ["userId"])
|
|
262
|
+
+ .index("by_session", ["sessionId"]),
|
|
263
|
+
// Maps a provider-scoped identity to an opaque app user id. The app owns the
|
|
264
|
+
// actual users table; we only store the id string it gives us back.
|
|
265
|
+
accounts: defineTable({
|
|
266
|
+
--- a/src/component/sessions.ts
|
|
267
|
+
+++ b/src/component/sessions.ts
|
|
268
|
+
@@ -146,9 +146,17 @@
|
|
269
|
+
): Promise<void> {
|
|
270
|
+
// `delete` throws on an id that is already gone, and the session may have
|
|
271
|
+
// been deleted by whoever we raced, which also scheduled its tokens.
|
|
272
|
+
- if ((await ctx.db.get("sessions", sessionId)) === null) {
|
|
273
|
+
- return;
|
|
274
|
+
- }
|
|
275
|
+
+ const session = await ctx.db.get("sessions", sessionId);
|
|
276
|
+
+ if (session === null) return;
|
|
277
|
+
+ const receipt = await ctx.db
|
|
278
|
+
+ .query("sessionCleanupReceipts")
|
|
279
|
+
+ .withIndex("by_session", (q) => q.eq("sessionId", sessionId))
|
|
280
|
+
+ .unique();
|
|
281
|
+
+ if (!receipt)
|
|
282
|
+
+ await ctx.db.insert("sessionCleanupReceipts", {
|
|
283
|
+
+ userId: session.userId,
|
|
284
|
+
+ sessionId,
|
|
285
|
+
+ });
|
|
286
|
+
await ctx.db.delete("sessions", sessionId);
|
|
287
|
+
await ctx.scheduler.runAfter(0, internal.sessions.deleteSessionTokens, {
|
|
288
|
+
sessionId,
|
|
289
|
+
@@ -176,6 +184,13 @@
|
|
290
|
+
for (const row of tokens) {
|
|
291
|
+
await ctx.db.delete("refreshTokens", row._id);
|
|
292
|
+
}
|
|
293
|
+
+ if (tokens.length < TOKEN_DELETION_BATCH_SIZE) {
|
|
294
|
+
+ const receipt = await ctx.db
|
|
295
|
+
+ .query("sessionCleanupReceipts")
|
|
296
|
+
+ .withIndex("by_session", (q) => q.eq("sessionId", sessionId))
|
|
297
|
+
+ .unique();
|
|
298
|
+
+ if (receipt) await ctx.db.delete("sessionCleanupReceipts", receipt._id);
|
|
299
|
+
+ }
|
|
300
|
+
if (tokens.length === TOKEN_DELETION_BATCH_SIZE) {
|
|
301
|
+
await ctx.scheduler.runAfter(0, internal.sessions.deleteSessionTokens, {
|
|
302
|
+
sessionId,
|
|
303
|
+
--- a/src/component/_generated/component.ts
|
|
304
|
+
+++ b/src/component/_generated/component.ts
|
|
305
|
+
@@ -24,12 +24,51 @@
|
|
306
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
307
|
+
{
|
|
308
|
+
public: {
|
|
309
|
+
- beginUserErasure: FunctionReference<"mutation", "internal", {userId: string}, null, Name>;
|
|
310
|
+
- purgeUserLinkedAuth: FunctionReference<"mutation", "internal", {userId: string}, {linkedRowsCleared: boolean; deletedAccounts: number; deletedSessions: number; deletedRefreshTokens: number; legacyOrphansUnverified: true}, Name>;
|
|
311
|
+
- exchangeSession: FunctionReference<"mutation", "internal", {
|
|
312
|
+
- sessionId: string; userId: string; accessTokenTtlSeconds: number;
|
|
313
|
+
- refreshInactivityTimeoutSeconds: number; sessionMaxLifetimeSeconds: number;
|
|
314
|
+
- }, { accessToken: string; refreshToken: string; refreshTokenExpiresAt: number; userId: string }, Name>;
|
|
315
|
+
+ getIdentityErasureCutoff: FunctionReference<
|
|
316
|
+
+ "query",
|
|
317
|
+
+ "internal",
|
|
318
|
+
+ { provider: string; providerAccountId: string },
|
|
319
|
+
+ number | null,
|
|
320
|
+
+ Name
|
|
321
|
+
+ >;
|
|
322
|
+
+ beginUserErasure: FunctionReference<
|
|
323
|
+
+ "mutation",
|
|
324
|
+
+ "internal",
|
|
325
|
+
+ { userId: string },
|
|
326
|
+
+ null,
|
|
327
|
+
+ Name
|
|
328
|
+
+ >;
|
|
329
|
+
+ purgeUserLinkedAuth: FunctionReference<
|
|
330
|
+
+ "mutation",
|
|
331
|
+
+ "internal",
|
|
332
|
+
+ { userId: string },
|
|
333
|
+
+ {
|
|
334
|
+
+ linkedRowsCleared: boolean;
|
|
335
|
+
+ deletedAccounts: number;
|
|
336
|
+
+ deletedSessions: number;
|
|
337
|
+
+ deletedRefreshTokens: number;
|
|
338
|
+
+ legacyOrphansUnverified: true;
|
|
339
|
+
+ },
|
|
340
|
+
+ Name
|
|
341
|
+
+ >;
|
|
342
|
+
+ exchangeSession: FunctionReference<
|
|
343
|
+
+ "mutation",
|
|
344
|
+
+ "internal",
|
|
345
|
+
+ {
|
|
346
|
+
+ sessionId: string;
|
|
347
|
+
+ userId: string;
|
|
348
|
+
+ accessTokenTtlSeconds: number;
|
|
349
|
+
+ refreshInactivityTimeoutSeconds: number;
|
|
350
|
+
+ sessionMaxLifetimeSeconds: number;
|
|
351
|
+
+ },
|
|
352
|
+
+ {
|
|
353
|
+
+ accessToken: string;
|
|
354
|
+
+ refreshToken: string;
|
|
355
|
+
+ refreshTokenExpiresAt: number;
|
|
356
|
+
+ userId: string;
|
|
357
|
+
+ },
|
|
358
|
+
+ Name
|
|
359
|
+
+ >;
|
|
360
|
+
|
|
361
|
+
getSession: FunctionReference<
|
|
362
|
+
"query",
|
|
363
|
+
--- a/src/server/setup.ts
|
|
364
|
+
+++ b/src/server/setup.ts
|
|
365
|
+
@@ -392,6 +392,24 @@
|
|
366
|
+
},
|
|
367
|
+
createUserHandle: await createFunctionHandle(createUser),
|
|
368
|
+
});
|
|
369
|
+
+ },
|
|
370
|
+
+ assertAuthorizationStart: async (
|
|
371
|
+
+ providerAccountId: string,
|
|
372
|
+
+ startedAt: number | undefined,
|
|
373
|
+
+ ): Promise<void> => {
|
|
374
|
+
+ const cutoff = await ctx.runQuery(
|
|
375
|
+
+ component.public.getIdentityErasureCutoff,
|
|
376
|
+
+ { provider: name, providerAccountId },
|
|
377
|
+
+ );
|
|
378
|
+
+ if (cutoff !== null) {
|
|
379
|
+
+ if (startedAt === undefined || startedAt <= cutoff)
|
|
380
|
+
+ throw new Error(
|
|
381
|
+
+ "Authorization predates account erasure or lacks proof.",
|
|
382
|
+
+ );
|
|
383
|
+
+ throw new Error(
|
|
384
|
+
+ "Registration for this identity is unavailable pending an explicit re-registration ceremony.",
|
|
385
|
+
+ );
|
|
386
|
+
+ }
|
|
387
|
+
},
|
|
388
|
+
resolveUserId: async (
|
|
389
|
+
providerAccountId: string,
|
|
390
|
+
--- a/src/lib/types.ts
|
|
391
|
+
+++ b/src/lib/types.ts
|
|
392
|
+
@@ -367,6 +367,10 @@
|
|
393
|
+
* Returns `null` when no user id is found for the account.
|
|
394
|
+
*/
|
|
395
|
+
resolveUserId(providerAccountId: string): Promise<string | null>;
|
|
396
|
+
+ assertAuthorizationStart(
|
|
397
|
+
+ providerAccountId: string,
|
|
398
|
+
+ startedAt: number | undefined,
|
|
399
|
+
+ ): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* Revokes every session of the signed-in user other than the current one
|
|
402
|
+
* (the JWT's subject). Returns the number of active (non-expired)
|
|
403
|
+
--- a/src/lib/oauth/redemption.ts
|
|
404
|
+
+++ b/src/lib/oauth/redemption.ts
|
|
405
|
+
@@ -144,9 +144,17 @@
|
|
406
|
+
claimTicket: (
|
|
407
|
+
ctx: MutationCtx,
|
|
408
|
+
args: { ticketCodeHash: string; stateHash: string },
|
|
409
|
+
- ) => Promise<{ encryptedPayload: string; authorizationStartedAt?: number } | null>;
|
|
410
|
+
+ ) => Promise<{
|
|
411
|
+
+ encryptedPayload: string;
|
|
412
|
+
+ authorizationStartedAt?: number;
|
|
413
|
+
+ } | null>;
|
|
414
|
+
+ enforceIdentityErasure?: boolean;
|
|
415
|
+
/** Optional server-side consumer; undefined marks legacy tickets. */
|
|
416
|
+
- checkAuthorizationStart?: (ctx: MutationCtx, profile: Profile, startedAt: number | undefined) => Promise<void>;
|
|
417
|
+
+ checkAuthorizationStart?: (
|
|
418
|
+
+ ctx: MutationCtx,
|
|
419
|
+
+ profile: Profile,
|
|
420
|
+
+ startedAt: number | undefined,
|
|
421
|
+
+ ) => Promise<void>;
|
|
422
|
+
/** Map what the provider attested to the account profile. */
|
|
423
|
+
profile: (payload: Payload) => Profile;
|
|
424
|
+
}) {
|
|
425
|
+
@@ -178,7 +186,16 @@
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
- await options.checkAuthorizationStart?.(ctx, profile, ticket.authorizationStartedAt);
|
|
430
|
+
+ if (options.enforceIdentityErasure)
|
|
431
|
+
+ await ctx.convexAuth.assertAuthorizationStart(
|
|
432
|
+
+ profile.id,
|
|
433
|
+
+ ticket.authorizationStartedAt,
|
|
434
|
+
+ );
|
|
435
|
+
+ await options.checkAuthorizationStart?.(
|
|
436
|
+
+ ctx,
|
|
437
|
+
+ profile,
|
|
438
|
+
+ ticket.authorizationStartedAt,
|
|
439
|
+
+ );
|
|
440
|
+
|
|
441
|
+
// The same redemption flow serves a first sign-in and a return visit, so
|
|
442
|
+
// resolve the identity to pick a path. This handler is a mutation, so the
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Auth identity cleanup contract
|
|
2
|
+
|
|
3
|
+
The current catalog selects this extension of `convex-auth-437831bd-disposabl.7.tgz`. Product `users/authDeletion.ts` coordinates the four fences and bounded cleanup. The original vendor-only candidate did not change selection or orchestration; those were integrated separately. The bounded independent email-write and archive-parity reviews described below are complete; selection is not production deployment evidence. Archive SHA-256: `2a84ec66965d64507439ced99899b3fa227b6f79d8437305435cdd074849aa40`. Source patch SHA-256: `979b80c9a942ee450b725f9f306574635bc21166ae9c0393e5755ba69ca12422`. Applying the patch with `patch -p1` to the unpacked `.7` package reproduces its `.8` source. The package includes source, compiled runtime, public and internal declarations; rebuild with the same upstream build instructions in `README.md`, setting version `.8`.
|
|
4
|
+
|
|
5
|
+
The username component exposes app-server-only `public.eraseUser({ userId })`: atomically insert a permanent user-ID tombstone and delete the username. `setUsername` rejects that ID after the tombstone commits. The email component exposes app-server-only `verifiedEmails.eraseUserBatch({ userId })`: atomically establish its permanent fence and delete up to 100 verified-email rows and 100 attributed challenge rows. Continue until `complete` is true; a full 100-row batch intentionally needs another call. The existing unfenced `deleteUsername` and unbounded `deleteUser` are retained for compatibility and must not be treated as these erasure operations. New attributed email challenges reject erased IDs and claims of existing attributed challenges fail after the fence. The tombstones retain opaque user IDs and timestamps indefinitely; neither anonymous data nor a retention policy is established.
|
|
6
|
+
|
|
7
|
+
Integration must establish core/password/username/email fences in one app-server mutation before core mappings can be purged or deletion can be reported complete. Continue the bounded email and existing core/password batches until all report complete; perform independent authorization, retry and orchestration review. The email API purges only rows indexed by `purpose.userId`. Custom challenges started without an attributed user ID are not safely associable here, may remain until existing expiry cleanup, and cannot be counted as erased. The patch does not address other components, old unattributed rows, provider identities, retention policy, or whole-account deletion. Re-registration under the same old user ID is denied; no tombstone removal policy is supplied.
|
|
8
|
+
|
|
9
|
+
Fixture code is product-only. The reset inventories exclude `packages/tests/fixtures/auth-identity-erasure-convex`; preserve that exclusion and its packaging proof. Frozen-install, generator, product integration, and source/compiled local fixture results are recorded in the delivery handoff. They do not replace independent archive review or establish production deployment and complete erasure.
|
|
10
|
+
|
|
11
|
+
The independent 2026-11-09 email-write review enumerated the three production verified-email insertion paths, `addEmail`, `changeEmail`, and `signUp`, and traced their attributed challenge creation and claim checks in source and compiled JavaScript. It found no tombstone bypass in that scope. Custom challenge completion does not insert verified emails; recovery rechecks the current verified owner. Legacy `deleteUser` remains unfenced and must not replace `eraseUserBatch`. This was static inspection, not a fixture rerun. A separate static review completed the `.7`-to-`.8` archive delta, username operations, validators and declaration parity. The inventories match with no added or removed files and 44 changed files. Applying the patch reproduced the full `.8` source tree byte-for-byte; unchanged core and Google files were preserved. Username set and erase use the same indexed tombstone within their mutations, and the new operation signatures agree across runtime validators and declaration outputs. Neither review reran the fixtures or establishes provider behavior, retention approval or whole-account deletion.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
diff --git a/src/components/email/_generated/component.ts b/src/components/email/_generated/component.ts
|
|
2
|
+
index a1e7581..cf44b0b 100644
|
|
3
|
+
--- a/src/components/email/_generated/component.ts
|
|
4
|
+
+++ b/src/components/email/_generated/component.ts
|
|
5
|
+
@@ -269,0 +270 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
6
|
+
+ eraseUserBatch: FunctionReference<"mutation", "internal", { userId: string }, { emailsDeleted: number; challengesDeleted: number; complete: boolean }, Name>;
|
|
7
|
+
diff --git a/src/components/email/challenge/common.ts b/src/components/email/challenge/common.ts
|
|
8
|
+
index e183df6..f6a0570 100644
|
|
9
|
+
--- a/src/components/email/challenge/common.ts
|
|
10
|
+
+++ b/src/components/email/challenge/common.ts
|
|
11
|
+
@@ -394,0 +395,3 @@ export async function createChallengeAndSendEmail(
|
|
12
|
+
+ const challengeUserId = args.purpose.userId;
|
|
13
|
+
+ if (challengeUserId !== undefined && await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", challengeUserId)).unique())
|
|
14
|
+
+ throw new Error("User identity has been erased");
|
|
15
|
+
@@ -498,0 +502,3 @@ export async function findClaimableChallenge<Expected extends ExpectedPurpose>(
|
|
16
|
+
+ const challengeUserId = row.purpose.userId;
|
|
17
|
+
+ if (challengeUserId !== undefined && await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", challengeUserId)).unique())
|
|
18
|
+
+ return claimFailure("INVALID_CHALLENGE");
|
|
19
|
+
diff --git a/src/components/email/schema.ts b/src/components/email/schema.ts
|
|
20
|
+
index f7f7633..17392a9 100644
|
|
21
|
+
--- a/src/components/email/schema.ts
|
|
22
|
+
+++ b/src/components/email/schema.ts
|
|
23
|
+
@@ -4,0 +5 @@ export default defineSchema({
|
|
24
|
+
+ erasedUsers: defineTable({ userId: v.string(), erasedAt: v.number() }).index("by_userId", ["userId"]),
|
|
25
|
+
diff --git a/src/components/email/verifiedEmails.ts b/src/components/email/verifiedEmails.ts
|
|
26
|
+
index 2de2e09..17ea000 100644
|
|
27
|
+
--- a/src/components/email/verifiedEmails.ts
|
|
28
|
+
+++ b/src/components/email/verifiedEmails.ts
|
|
29
|
+
@@ -116,0 +117,15 @@ export const deleteUser = mutation({
|
|
30
|
+
+
|
|
31
|
+
+/** App-server only. Establish a permanent fence and delete bounded attributed rows. */
|
|
32
|
+
+export const eraseUserBatch = mutation({
|
|
33
|
+
+ args: { userId: v.string() },
|
|
34
|
+
+ returns: v.object({ emailsDeleted: v.number(), challengesDeleted: v.number(), complete: v.boolean() }),
|
|
35
|
+
+ handler: async (ctx, { userId }) => {
|
|
36
|
+
+ const tombstone = await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique();
|
|
37
|
+
+ if (!tombstone) await ctx.db.insert("erasedUsers", { userId, erasedAt: Date.now() });
|
|
38
|
+
+ const emails = await ctx.db.query("verifiedEmails").withIndex("by_userId", q => q.eq("userId", userId)).take(100);
|
|
39
|
+
+ const challenges = await ctx.db.query("challenges").withIndex("by_purpose_userId", q => q.eq("purpose.userId", userId)).take(100);
|
|
40
|
+
+ for (const row of emails) await ctx.db.delete("verifiedEmails", row._id);
|
|
41
|
+
+ for (const row of challenges) await ctx.db.delete("challenges", row._id);
|
|
42
|
+
+ return { emailsDeleted: emails.length, challengesDeleted: challenges.length, complete: emails.length < 100 && challenges.length < 100 };
|
|
43
|
+
+ },
|
|
44
|
+
+});
|
|
45
|
+
diff --git a/src/components/username/_generated/component.ts b/src/components/username/_generated/component.ts
|
|
46
|
+
index 116d150..01e0dac 100644
|
|
47
|
+
--- a/src/components/username/_generated/component.ts
|
|
48
|
+
+++ b/src/components/username/_generated/component.ts
|
|
49
|
+
@@ -26,0 +27 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
50
|
+
+ eraseUser: FunctionReference<"mutation", "internal", { userId: string }, { deleted: boolean }, Name>;
|
|
51
|
+
diff --git a/src/components/username/public.ts b/src/components/username/public.ts
|
|
52
|
+
index 20216b4..3bd14e0 100644
|
|
53
|
+
--- a/src/components/username/public.ts
|
|
54
|
+
+++ b/src/components/username/public.ts
|
|
55
|
+
@@ -38,0 +39,2 @@ export const setUsername = mutation({
|
|
56
|
+
+ if (await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique())
|
|
57
|
+
+ throw new Error("User identity has been erased");
|
|
58
|
+
@@ -119,0 +122,14 @@ export const deleteUsername = mutation({
|
|
59
|
+
+/** Permanently fence the old user ID and remove its username. App-server only. */
|
|
60
|
+
+export const eraseUser = mutation({
|
|
61
|
+
+ args: { userId: v.string() },
|
|
62
|
+
+ returns: v.object({ deleted: v.boolean() }),
|
|
63
|
+
+ handler: async (ctx, { userId }) => {
|
|
64
|
+
+ const tombstone = await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique();
|
|
65
|
+
+ if (!tombstone) await ctx.db.insert("erasedUsers", { userId, erasedAt: Date.now() });
|
|
66
|
+
+ const row = await rowByUserId(ctx, userId);
|
|
67
|
+
+ if (!row) return { deleted: false };
|
|
68
|
+
+ await ctx.db.delete("usernames", row._id);
|
|
69
|
+
+ return { deleted: true };
|
|
70
|
+
+ },
|
|
71
|
+
+});
|
|
72
|
+
+
|
|
73
|
+
diff --git a/src/components/username/schema.ts b/src/components/username/schema.ts
|
|
74
|
+
index fcba693..d979bca 100644
|
|
75
|
+
--- a/src/components/username/schema.ts
|
|
76
|
+
+++ b/src/components/username/schema.ts
|
|
77
|
+
@@ -4,0 +5 @@ export default defineSchema({
|
|
78
|
+
+ erasedUsers: defineTable({ userId: v.string(), erasedAt: v.number() }).index("by_userId", ["userId"]),
|