create-disposabl-app 0.17.6 → 0.18.1

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.
Files changed (97) hide show
  1. package/README.md +4 -0
  2. package/dist/disposabl.js +42 -9
  3. package/dist/index.js +64 -18
  4. package/dist/templates/default/apps/mobile/README.md +40 -0
  5. package/dist/templates/default/apps/mobile/app.config.js +46 -2
  6. package/dist/templates/default/apps/mobile/app.json +2 -1
  7. package/dist/templates/default/apps/mobile/package.json +7 -1
  8. package/dist/templates/default/apps/mobile/plugins/with-android-signing.js +23 -1
  9. package/dist/templates/default/apps/mobile/scripts/fresh-android.mjs +24 -0
  10. package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +176 -0
  11. package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +77 -0
  12. package/dist/templates/default/bun.lock +12 -3
  13. package/dist/templates/default/bunfig.toml +1 -0
  14. package/dist/templates/default/package.json +6 -2
  15. package/dist/templates/default/packages/backend/convex/files/guard.ts +2 -0
  16. package/dist/templates/default/packages/backend/convex/http.ts +11 -1
  17. package/dist/templates/default/packages/backend/convex/schema.ts +10 -0
  18. package/dist/templates/default/packages/backend/convex/telemetry.ts +12 -16
  19. package/dist/templates/default/packages/cli/telemetry.ts +40 -3
  20. package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +2 -0
  21. package/dist/templates/default/packages/disposabl-kit/client/components/account-deletion.tsx +111 -0
  22. package/dist/templates/default/packages/disposabl-kit/client/components/consent-identity.tsx +50 -0
  23. package/dist/templates/default/packages/disposabl-kit/client/components/legal-page.tsx +12 -1
  24. package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry-lease.ts +200 -0
  25. package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry.ts +8 -1
  26. package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +23 -1
  27. package/dist/templates/default/packages/disposabl-kit/client/routes/legal/delete-account.tsx +6 -1
  28. package/dist/templates/default/packages/disposabl-kit/client/routes/legal/support.tsx +33 -0
  29. package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +13 -0
  30. package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +19 -2
  31. package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +1 -0
  32. package/dist/templates/default/packages/disposabl-kit/legal/README.md +1 -1
  33. package/dist/templates/default/packages/disposabl-kit/legal/config.ts +32 -4
  34. package/dist/templates/default/packages/disposabl-kit/legal/index.ts +2 -2
  35. package/dist/templates/default/packages/disposabl-kit/legal/publisher.ts +6 -0
  36. package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +13 -9
  37. package/dist/templates/default/packages/disposabl-kit/mobile/billing/paywall.ts +28 -4
  38. package/dist/templates/default/packages/disposabl-kit/mobile/billing/policy.ts +31 -14
  39. package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +45 -34
  40. package/dist/templates/default/packages/disposabl-kit/mobile/components/settings-links.tsx +14 -0
  41. package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +3 -0
  42. package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +4 -0
  43. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +55 -8
  44. package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +147 -124
  45. package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +113 -95
  46. package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +70 -54
  47. package/dist/templates/default/packages/disposabl-kit/server/http.ts +49 -21
  48. package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +25 -1
  49. package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +375 -69
  50. package/dist/templates/default/packages/sdk/README.md +2 -0
  51. package/dist/templates/default/packages/sdk/src/analytics.ts +7 -2
  52. package/dist/templates/default/packages/skill/SKILL.md +4 -2
  53. package/dist/templates/default/packages/skill/references/store-submissions.md +25 -0
  54. package/dist/templates/default/packages/tests/README.md +28 -1
  55. package/dist/templates/default/packages/tests/account-deletion-ui.test.ts +21 -0
  56. package/dist/templates/default/packages/tests/auth-email-setup.test.ts +45 -0
  57. package/dist/templates/default/packages/tests/components/account-deletion.test.mjs +82 -0
  58. package/dist/templates/default/packages/tests/components/consent-identity.test.mjs +175 -0
  59. package/dist/templates/default/packages/tests/components/mobile-deletion-link.test.mjs +40 -0
  60. package/dist/templates/default/packages/tests/components/mobile-theme.test.mjs +56 -3
  61. package/dist/templates/default/packages/tests/components/pricing-identity.test.mjs +113 -0
  62. package/dist/templates/default/packages/tests/components/support-page.test.mjs +36 -0
  63. package/dist/templates/default/packages/tests/consent-identity.test.ts +13 -0
  64. package/dist/templates/default/packages/tests/desktop-macos-release.test.ts +153 -145
  65. package/dist/templates/default/packages/tests/flows/legal.e2e.ts +40 -3
  66. package/dist/templates/default/packages/tests/helpers/auth-email-setup/probe.test.mjs +44 -0
  67. package/dist/templates/default/packages/tests/helpers/mobile-simulator/preflight.py +80 -0
  68. package/dist/templates/default/packages/tests/helpers/mobile-simulator/test_preflight.py +57 -0
  69. package/dist/templates/default/packages/tests/mobile-android-e2e-network.test.ts +81 -1
  70. package/dist/templates/default/packages/tests/mobile-android-signing.test.ts +52 -0
  71. package/dist/templates/default/packages/tests/mobile-deletion-link.test.ts +21 -0
  72. package/dist/templates/default/packages/tests/mobile-ios-reachability-pin.test.ts +84 -0
  73. package/dist/templates/default/packages/tests/mobile-simulator-preflight.test.ts +16 -0
  74. package/dist/templates/default/packages/tests/native-billing.test.ts +288 -0
  75. package/dist/templates/default/packages/tests/pricing-identity.test.ts +13 -0
  76. package/dist/templates/default/packages/tests/sdk-analytics.test.ts +28 -2
  77. package/dist/templates/default/packages/tests/support-page.test.ts +13 -0
  78. package/dist/templates/default/packages/tests/telemetry.test.ts +389 -18
  79. package/dist/templates/default/packages/tests/ui-telemetry-lease.test.ts +346 -0
  80. package/dist/templates/default/patches/convex-mcp-account-erasure-alpha7.patch +466 -0
  81. package/dist/templates/default/vendor/README.md +61 -1
  82. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.patch +890 -0
  83. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.tgz +0 -0
  84. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.patch +1060 -0
  85. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.tgz +0 -0
  86. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.4.tgz +0 -0
  87. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.5.tgz +0 -0
  88. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.6.tgz +0 -0
  89. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.7.tgz +0 -0
  90. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.8.tgz +0 -0
  91. package/dist/templates/default/vendor/convex-auth-core-erasure-disposabl.6.patch +115 -0
  92. package/dist/templates/default/vendor/convex-auth-identity-cutoff-disposabl.7.patch +442 -0
  93. package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.md +11 -0
  94. package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.patch +78 -0
  95. package/dist/templates/default/vendor/convex-auth-marker-disposabl.4.patch +169 -0
  96. package/dist/templates/default/vendor/convex-auth-marker-password-disposabl.5.patch +126 -0
  97. package/package.json +1 -1
@@ -8,7 +8,10 @@ import {
8
8
  import { makeFunctionReference, type Auth } from "convex/server";
9
9
  import { getSessionUserId } from "./lib/functions";
10
10
  import type { Id } from "../../backend/convex/_generated/dataModel";
11
- import type { ActionCtx } from "../../backend/convex/_generated/server";
11
+ import type {
12
+ ActionCtx,
13
+ MutationCtx,
14
+ } from "../../backend/convex/_generated/server";
12
15
  import {
13
16
  deleteThenForget,
14
17
  r2Config,
@@ -73,17 +76,27 @@ async function owner(ctx: { auth: Auth }) {
73
76
  if (!userId) throw new Error("Authentication required.");
74
77
  return userId;
75
78
  }
76
- export const register = internalMutation({
77
- args: {
78
- filename: v.string(),
79
- mediaType: v.string(),
80
- size: v.number(),
81
- location,
82
- },
83
- returns: v.id("files"),
84
- handler: async (ctx, args) =>
85
- ctx.db.insert("files", { ...args, owner: await owner(ctx) }),
86
- });
79
+ export type FileWriteGuard = (
80
+ ctx: ActionCtx | MutationCtx,
81
+ userId: string,
82
+ ) => Promise<void>;
83
+
84
+ export const createRegister = (guard?: FileWriteGuard) =>
85
+ internalMutation({
86
+ args: {
87
+ filename: v.string(),
88
+ mediaType: v.string(),
89
+ size: v.number(),
90
+ location,
91
+ },
92
+ returns: v.id("files"),
93
+ handler: async (ctx, args) => {
94
+ const userId = await owner(ctx);
95
+ if (guard) await guard(ctx, userId);
96
+ return ctx.db.insert("files", { ...args, owner: userId });
97
+ },
98
+ });
99
+ export const register = createRegister();
87
100
  export const getOwned = internalQuery({
88
101
  args: { id: v.id("files") },
89
102
  returns: fileValidator,
@@ -100,49 +113,52 @@ export const forget = internalMutation({
100
113
  },
101
114
  });
102
115
 
103
- export const upload = action({
104
- args: { filename: v.string(), mediaType: v.string(), bytes: v.bytes() },
105
- returns: v.id("files"),
106
- handler: async (
107
- ctx,
108
- { filename, mediaType, bytes },
109
- ): Promise<Id<"files">> => {
110
- await owner(ctx);
111
- validateUpload(filename, mediaType, bytes);
112
- const config = r2Config(env);
113
- return (await registerWithRollback(
114
- async (): Promise<FileRecord["location"]> => {
115
- if (config) {
116
- const loc = {
117
- provider: "r2" as const,
118
- key: crypto.randomUUID(),
119
- account: config.account,
120
- bucket: config.bucket,
116
+ export const createUpload = (guard?: FileWriteGuard) =>
117
+ action({
118
+ args: { filename: v.string(), mediaType: v.string(), bytes: v.bytes() },
119
+ returns: v.id("files"),
120
+ handler: async (
121
+ ctx,
122
+ { filename, mediaType, bytes },
123
+ ): Promise<Id<"files">> => {
124
+ const userId = await owner(ctx);
125
+ if (guard) await guard(ctx, userId);
126
+ validateUpload(filename, mediaType, bytes);
127
+ const config = r2Config(env);
128
+ return (await registerWithRollback(
129
+ async (): Promise<FileRecord["location"]> => {
130
+ if (config) {
131
+ const loc = {
132
+ provider: "r2" as const,
133
+ key: crypto.randomUUID(),
134
+ account: config.account,
135
+ bucket: config.bucket,
136
+ };
137
+ await r2Write(loc, env, bytes, mediaType);
138
+ return loc;
139
+ }
140
+ return {
141
+ provider: "convex",
142
+ storageId: await ctx.storage.store(
143
+ new Blob([bytes], { type: mediaType }),
144
+ ),
121
145
  };
122
- await r2Write(loc, env, bytes, mediaType);
123
- return loc;
124
- }
125
- return {
126
- provider: "convex",
127
- storageId: await ctx.storage.store(
128
- new Blob([bytes], { type: mediaType }),
129
- ),
130
- };
131
- },
132
- (loc) =>
133
- ctx.runMutation(registerRef, {
134
- filename: filename.trim(),
135
- mediaType,
136
- size: bytes.byteLength,
137
- location: loc,
138
- }),
139
- (loc) =>
140
- loc.provider === "r2"
141
- ? r2Delete(loc, env)
142
- : ctx.storage.delete(loc.storageId),
143
- )) as Id<"files">;
144
- },
145
- });
146
+ },
147
+ (loc) =>
148
+ ctx.runMutation(registerRef, {
149
+ filename: filename.trim(),
150
+ mediaType,
151
+ size: bytes.byteLength,
152
+ location: loc,
153
+ }),
154
+ (loc) =>
155
+ loc.provider === "r2"
156
+ ? r2Delete(loc, env)
157
+ : ctx.storage.delete(loc.storageId),
158
+ )) as Id<"files">;
159
+ },
160
+ });
161
+ export const upload = createUpload();
146
162
  async function resolve(ctx: ActionCtx, id: Id<"files">) {
147
163
  const file = await ctx.runQuery(getRef, { id });
148
164
  const url =
@@ -15,6 +15,7 @@ import {
15
15
  createOpenApi,
16
16
  createPlatforms,
17
17
  type ApiPolicy,
18
+ type AccountEligibility,
18
19
  } from "./lib/platform-spec";
19
20
  import { registerPageRoutes } from "./lib/static";
20
21
  import { resend } from "../../backend/convex/emails";
@@ -24,7 +25,7 @@ import { desktopAuthPath, desktopAuthRedirect } from "../lib/desktop-auth";
24
25
 
25
26
  export { tool } from "@convex-dev/mcp";
26
27
  export type { McpServerOptions, McpUser, ToolCtx } from "@convex-dev/mcp";
27
- export type { ApiPolicy } from "./lib/platform-spec";
28
+ export type { ApiPolicy, AccountEligibility } from "./lib/platform-spec";
28
29
 
29
30
  const platforms = createPlatforms(modules);
30
31
  if (
@@ -37,33 +38,60 @@ if (
37
38
  export const platformSpec = platforms.spec;
38
39
 
39
40
  const enabled = validatePlatforms(config.platforms);
40
- const mcp: McpServer | undefined = enabled.some(
41
- (platform) => platform === "mcp" || platform === "api",
42
- )
43
- ? new McpServer(components.mcp, {
44
- name: "disposabl",
45
- title: "Disposabl",
46
- version: "1.0.0",
47
- siteUrl: env.CONVEX_SITE_URL,
48
- consentUrl: `${env.CONVEX_SITE_URL}/consent`,
49
- scopes: {},
50
- clientMetadataDocumentHosts: ["claude.ai"],
51
- tools: platforms.tools,
52
- })
53
- : undefined;
41
+ function createMcp(eligibility?: AccountEligibility): McpServer | undefined {
42
+ return enabled.some((platform) => platform === "mcp" || platform === "api")
43
+ ? new McpServer(components.mcp, {
44
+ name: "disposabl",
45
+ title: "Disposabl",
46
+ version: "1.0.0",
47
+ siteUrl: env.CONVEX_SITE_URL,
48
+ consentUrl: `${env.CONVEX_SITE_URL}/consent`,
49
+ scopes: {},
50
+ clientMetadataDocumentHosts: ["claude.ai"],
51
+ tools: eligibility
52
+ ? createPlatforms(modules, eligibility).tools
53
+ : platforms.tools,
54
+ })
55
+ : undefined;
56
+ }
54
57
 
55
- // Keep the enabled API types for consumers; disabled exports are absent at runtime.
58
+ /** Protect issuance while retaining listing and revocation for existing grants. */
59
+ export function createMcpApi(eligibility?: AccountEligibility) {
60
+ const mcp = createMcp(eligibility);
61
+ if (!mcp) return {} as ReturnType<McpServer["api"]>;
62
+ const standard = mcp.api({ getUserId: getSessionUserId });
63
+ if (!eligibility) return standard;
64
+ const guarded = mcp.api({
65
+ getUserId: async (ctx) => {
66
+ const id = await getSessionUserId(ctx);
67
+ return id &&
68
+ (await eligibility(ctx as Parameters<AccountEligibility>[0], id))
69
+ ? id
70
+ : null;
71
+ },
72
+ });
73
+ return {
74
+ ...standard,
75
+ authorize: guarded.authorize,
76
+ createApiKey: guarded.createApiKey,
77
+ };
78
+ }
56
79
  export const {
57
80
  getAuthRequest,
58
81
  authorize,
59
82
  listConnections,
60
83
  revokeConnection,
61
84
  createApiKey,
62
- } =
63
- mcp?.api({ getUserId: getSessionUserId }) ??
64
- ({} as ReturnType<McpServer["api"]>);
85
+ } = createMcpApi();
65
86
 
66
- export default function createHttpRouter(apiPolicy?: ApiPolicy) {
87
+ export default function createHttpRouter(
88
+ apiPolicy?: ApiPolicy,
89
+ eligibility?: AccountEligibility,
90
+ ) {
91
+ const mcp = createMcp(eligibility);
92
+ const requestPlatforms = eligibility
93
+ ? createPlatforms(modules, eligibility)
94
+ : platforms;
67
95
  const http = httpRouter();
68
96
  if (authenticationEnabled) {
69
97
  if (
@@ -157,7 +185,7 @@ export default function createHttpRouter(apiPolicy?: ApiPolicy) {
157
185
  const response =
158
186
  method === "OPTIONS"
159
187
  ? new Response(null, { status: 204 })
160
- : await platforms.handleApi(
188
+ : await requestPlatforms.handleApi(
161
189
  ctx,
162
190
  request,
163
191
  mcp.authenticate.bind(mcp),
@@ -47,9 +47,15 @@ export type ApiPolicy = {
47
47
  ) => boolean;
48
48
  };
49
49
 
50
+ export type AccountEligibility = (
51
+ ctx: ToolCtx,
52
+ userId: string,
53
+ ) => Promise<boolean>;
54
+
50
55
  /** One opt-in produces the shared JSON contract and both transport adapters. */
51
56
  export function createPlatforms(
52
57
  modules: Record<string, Record<string, unknown>>,
58
+ eligibility?: AccountEligibility,
53
59
  ) {
54
60
  const spec: Operation[] = [];
55
61
  const tools: Record<string, ToolDefinition> = Object.create(null);
@@ -98,6 +104,8 @@ export function createPlatforms(
98
104
  args,
99
105
  returns: fn.returns,
100
106
  handler: async (ctx, input, user) => {
107
+ if (eligibility && !(await eligibility(ctx, user.userId)))
108
+ throw new ConvexError("Account is unavailable.");
101
109
  const startedAt = Date.now();
102
110
  try {
103
111
  const result = await runOperation(ctx, input, user);
@@ -186,6 +194,8 @@ export function createPlatforms(
186
194
  )
187
195
  )
188
196
  return Response.json({ error: "forbidden" }, { status: 403 });
197
+ if (eligibility && !(await eligibility(ctx, user.userId)))
198
+ return Response.json({ error: "forbidden" }, { status: 403 });
189
199
  const startedAt = Date.now();
190
200
  const header = request.headers.get("X-Disposabl-Source");
191
201
  const source = header === "cli" || header === "sdk" ? header : "api";
@@ -212,6 +222,13 @@ export function createPlatforms(
212
222
  await record("success");
213
223
  } catch (error) {
214
224
  await record("error");
225
+ if (
226
+ !(error instanceof ConvexError) &&
227
+ !(error instanceof SyntaxError)
228
+ ) {
229
+ console.error("platform_api_internal_error");
230
+ return Response.json({ error: "internal_error" }, { status: 500 });
231
+ }
215
232
  throw error;
216
233
  }
217
234
  return new Response(
@@ -238,7 +255,14 @@ export function createPlatforms(
238
255
  );
239
256
  if (error instanceof SyntaxError)
240
257
  return Response.json({ error: "invalid_request" }, { status: 400 });
241
- console.error(error);
258
+ const operation = spec.find((item) => item.path === url.pathname)!;
259
+ const header = request.headers.get("X-Disposabl-Source");
260
+ await scheduleTelemetry(ctx, "api_operation", {
261
+ source: header === "cli" || header === "sdk" ? header : "api",
262
+ operation: operation.name,
263
+ outcome: "error",
264
+ });
265
+ console.error("platform_api_internal_error");
242
266
  return Response.json({ error: "internal_error" }, { status: 500 });
243
267
  }
244
268
  },