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.
Files changed (103) hide show
  1. package/README.md +4 -0
  2. package/dist/disposabl.js +43 -10
  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/package.json +7 -1
  7. package/dist/templates/default/apps/mobile/plugins/with-android-signing.js +23 -1
  8. package/dist/templates/default/apps/mobile/scripts/fresh-android.mjs +24 -0
  9. package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +176 -0
  10. package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +77 -0
  11. package/dist/templates/default/bun.lock +12 -3
  12. package/dist/templates/default/bunfig.toml +1 -0
  13. package/dist/templates/default/package.json +6 -2
  14. package/dist/templates/default/packages/backend/convex/files/guard.ts +2 -0
  15. package/dist/templates/default/packages/backend/convex/http.ts +11 -1
  16. package/dist/templates/default/packages/backend/convex/schema.ts +10 -0
  17. package/dist/templates/default/packages/backend/convex/telemetry.ts +12 -16
  18. package/dist/templates/default/packages/cli/build.ts +4 -0
  19. package/dist/templates/default/packages/cli/package.json +2 -1
  20. package/dist/templates/default/packages/cli/telemetry.ts +40 -3
  21. package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +2 -0
  22. package/dist/templates/default/packages/disposabl-kit/client/components/account-deletion.tsx +111 -0
  23. package/dist/templates/default/packages/disposabl-kit/client/components/consent-identity.tsx +50 -0
  24. package/dist/templates/default/packages/disposabl-kit/client/components/legal-page.tsx +12 -1
  25. package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry-lease.ts +200 -0
  26. package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry.ts +8 -1
  27. package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +23 -1
  28. package/dist/templates/default/packages/disposabl-kit/client/routes/legal/delete-account.tsx +6 -1
  29. package/dist/templates/default/packages/disposabl-kit/client/routes/legal/support.tsx +33 -0
  30. package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +13 -0
  31. package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +19 -2
  32. package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +1 -0
  33. package/dist/templates/default/packages/disposabl-kit/legal/README.md +1 -1
  34. package/dist/templates/default/packages/disposabl-kit/legal/config.ts +32 -4
  35. package/dist/templates/default/packages/disposabl-kit/legal/index.ts +2 -2
  36. package/dist/templates/default/packages/disposabl-kit/legal/publisher.ts +6 -0
  37. package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +13 -9
  38. package/dist/templates/default/packages/disposabl-kit/mobile/billing/paywall.ts +28 -4
  39. package/dist/templates/default/packages/disposabl-kit/mobile/billing/policy.ts +31 -14
  40. package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +45 -34
  41. package/dist/templates/default/packages/disposabl-kit/mobile/components/settings-links.tsx +14 -0
  42. package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +3 -0
  43. package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +4 -0
  44. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +55 -8
  45. package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +147 -124
  46. package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +113 -95
  47. package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +70 -54
  48. package/dist/templates/default/packages/disposabl-kit/server/http.ts +49 -21
  49. package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +25 -1
  50. package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +375 -69
  51. package/dist/templates/default/packages/disposabl-kit/server/release/clients.mjs +28 -1
  52. package/dist/templates/default/packages/disposabl-kit/server/release/verify-metadata.mjs +64 -0
  53. package/dist/templates/default/packages/sdk/README.md +2 -0
  54. package/dist/templates/default/packages/sdk/build.ts +8 -0
  55. package/dist/templates/default/packages/sdk/package.json +3 -2
  56. package/dist/templates/default/packages/sdk/src/analytics.ts +7 -2
  57. package/dist/templates/default/packages/skill/SKILL.md +4 -2
  58. package/dist/templates/default/packages/skill/references/store-submissions.md +25 -0
  59. package/dist/templates/default/packages/tests/README.md +28 -1
  60. package/dist/templates/default/packages/tests/account-deletion-ui.test.ts +21 -0
  61. package/dist/templates/default/packages/tests/auth-email-setup.test.ts +45 -0
  62. package/dist/templates/default/packages/tests/components/account-deletion.test.mjs +82 -0
  63. package/dist/templates/default/packages/tests/components/consent-identity.test.mjs +175 -0
  64. package/dist/templates/default/packages/tests/components/mobile-deletion-link.test.mjs +40 -0
  65. package/dist/templates/default/packages/tests/components/mobile-theme.test.mjs +56 -3
  66. package/dist/templates/default/packages/tests/components/pricing-identity.test.mjs +113 -0
  67. package/dist/templates/default/packages/tests/components/support-page.test.mjs +36 -0
  68. package/dist/templates/default/packages/tests/consent-identity.test.ts +13 -0
  69. package/dist/templates/default/packages/tests/desktop-macos-release.test.ts +153 -145
  70. package/dist/templates/default/packages/tests/flows/legal.e2e.ts +40 -3
  71. package/dist/templates/default/packages/tests/helpers/auth-email-setup/probe.test.mjs +44 -0
  72. package/dist/templates/default/packages/tests/helpers/mobile-simulator/preflight.py +80 -0
  73. package/dist/templates/default/packages/tests/helpers/mobile-simulator/test_preflight.py +57 -0
  74. package/dist/templates/default/packages/tests/mobile-android-e2e-network.test.ts +81 -1
  75. package/dist/templates/default/packages/tests/mobile-android-signing.test.ts +52 -0
  76. package/dist/templates/default/packages/tests/mobile-deletion-link.test.ts +21 -0
  77. package/dist/templates/default/packages/tests/mobile-ios-reachability-pin.test.ts +84 -0
  78. package/dist/templates/default/packages/tests/mobile-simulator-preflight.test.ts +16 -0
  79. package/dist/templates/default/packages/tests/native-billing.test.ts +288 -0
  80. package/dist/templates/default/packages/tests/pricing-identity.test.ts +13 -0
  81. package/dist/templates/default/packages/tests/sdk-analytics.test.ts +28 -2
  82. package/dist/templates/default/packages/tests/support-page.test.ts +13 -0
  83. package/dist/templates/default/packages/tests/telemetry.test.ts +389 -18
  84. package/dist/templates/default/packages/tests/ui-telemetry-lease.test.ts +346 -0
  85. package/dist/templates/default/patches/convex-mcp-account-erasure-alpha7.patch +466 -0
  86. package/dist/templates/default/vendor/README.md +61 -1
  87. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.patch +890 -0
  88. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.tgz +0 -0
  89. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.patch +1060 -0
  90. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.tgz +0 -0
  91. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.4.tgz +0 -0
  92. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.5.tgz +0 -0
  93. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.6.tgz +0 -0
  94. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.7.tgz +0 -0
  95. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.8.tgz +0 -0
  96. package/dist/templates/default/vendor/convex-auth-core-erasure-disposabl.6.patch +115 -0
  97. package/dist/templates/default/vendor/convex-auth-identity-cutoff-disposabl.7.patch +442 -0
  98. package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.md +11 -0
  99. package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.patch +78 -0
  100. package/dist/templates/default/vendor/convex-auth-marker-disposabl.4.patch +169 -0
  101. package/dist/templates/default/vendor/convex-auth-marker-password-disposabl.5.patch +126 -0
  102. package/dist/verify-metadata.mjs +64 -0
  103. package/package.json +3 -2
@@ -1,7 +1,14 @@
1
1
  import config from "../../../../disposabl.json";
2
2
  import { makeFunctionReference } from "convex/server";
3
3
  import { v } from "convex/values";
4
- import { internalMutation } from "../../../backend/convex/_generated/server";
4
+ import {
5
+ internalMutation,
6
+ internalAction,
7
+ internalQuery,
8
+ type ActionCtx,
9
+ type MutationCtx,
10
+ type QueryCtx,
11
+ } from "../../../backend/convex/_generated/server";
5
12
 
6
13
  export type TelemetryEvent =
7
14
  | "api_operation"
@@ -81,62 +88,257 @@ const expireIdentityRef = makeFunctionReference<
81
88
  { id: string },
82
89
  null
83
90
  >("telemetry:expireIdentity");
91
+ const deliverLinkRef = makeFunctionReference<"action", { id: string }, null>(
92
+ "telemetry:deliverLink",
93
+ );
84
94
 
85
- export const claimIdentity = internalMutation({
95
+ export const createClaimIdentity = (
96
+ checkUser?: (ctx: MutationCtx, userId: string) => Promise<void>,
97
+ ) =>
98
+ internalMutation({
99
+ args: {
100
+ hash: v.optional(v.string()),
101
+ newHash: v.string(),
102
+ userId: v.optional(v.string()),
103
+ link: v.optional(
104
+ v.object({
105
+ anonymous: v.string(),
106
+ distinct: v.string(),
107
+ eventId: v.string(),
108
+ }),
109
+ ),
110
+ },
111
+ returns: v.union(v.boolean(), v.null(), v.literal("linked")),
112
+ handler: async (ctx, { hash, newHash, userId, link }) => {
113
+ if (userId !== undefined) await checkUser?.(ctx, userId);
114
+ const row = hash
115
+ ? await ctx.db
116
+ .query("telemetryIdentities")
117
+ .withIndex("by_hash", (q) => q.eq("hash", hash))
118
+ .unique()
119
+ : null;
120
+ if (
121
+ row &&
122
+ row.expiresAt > Date.now() &&
123
+ (!row.userId || row.userId === userId)
124
+ ) {
125
+ if (userId && !row.userId) {
126
+ await ctx.db.patch("telemetryIdentities", row._id, {
127
+ userId,
128
+ ...(link
129
+ ? {
130
+ link: {
131
+ ...link,
132
+ createdAt: Date.now(),
133
+ attempts: 0,
134
+ retryAfter: Date.now(),
135
+ },
136
+ }
137
+ : {}),
138
+ });
139
+ if (link) {
140
+ await ctx.scheduler.runAfter(0, deliverLinkRef, { id: row._id });
141
+ // A scheduled action can fail before it reserves its own retry.
142
+ await ctx.scheduler.runAfter(30_000, deliverLinkRef, {
143
+ id: row._id,
144
+ });
145
+ return "linked";
146
+ }
147
+ }
148
+ if (
149
+ row.link &&
150
+ row.link.attempts >= 5 &&
151
+ Date.now() >= row.link.retryAfter
152
+ ) {
153
+ await ctx.db.patch("telemetryIdentities", row._id, {
154
+ link: { ...row.link, attempts: 0, retryAfter: Date.now() },
155
+ });
156
+ await ctx.scheduler.runAfter(0, deliverLinkRef, { id: row._id });
157
+ await ctx.scheduler.runAfter(30_000, deliverLinkRef, { id: row._id });
158
+ }
159
+ return true;
160
+ }
161
+ const now = Date.now();
162
+ const bucket = await ctx.db
163
+ .query("telemetryIssuance")
164
+ .withIndex("by_key", (q) => q.eq("key", "global"))
165
+ .unique();
166
+ const tokens = bucket
167
+ ? Math.min(
168
+ issuanceBurst,
169
+ bucket.tokens +
170
+ Math.max(0, now - bucket.updatedAt) / issuanceRefillMs,
171
+ )
172
+ : issuanceBurst;
173
+ if (tokens < 1) return null;
174
+ if (bucket) {
175
+ await ctx.db.patch("telemetryIssuance", bucket._id, {
176
+ tokens: tokens - 1,
177
+ updatedAt: now,
178
+ });
179
+ } else {
180
+ await ctx.db.insert("telemetryIssuance", {
181
+ key: "global",
182
+ tokens: tokens - 1,
183
+ updatedAt: now,
184
+ });
185
+ }
186
+ const id = await ctx.db.insert("telemetryIdentities", {
187
+ hash: newHash,
188
+ expiresAt: Date.now() + identityTtl,
189
+ ...(userId ? { userId } : {}),
190
+ });
191
+ await ctx.scheduler.runAfter(identityTtl, expireIdentityRef, { id });
192
+ return false;
193
+ },
194
+ });
195
+
196
+ export const claimIdentity = createClaimIdentity();
197
+
198
+ const linkValue = v.object({
199
+ anonymous: v.string(),
200
+ distinct: v.string(),
201
+ eventId: v.string(),
202
+ createdAt: v.number(),
203
+ attempts: v.number(),
204
+ retryAfter: v.number(),
205
+ });
206
+ export const createLinkLookup = (
207
+ checkUser?: (ctx: QueryCtx, userId: string) => Promise<void>,
208
+ ) =>
209
+ internalQuery({
210
+ args: { id: v.id("telemetryIdentities") },
211
+ returns: v.union(linkValue, v.null()),
212
+ handler: async (ctx, { id }) => {
213
+ const row = await ctx.db.get("telemetryIdentities", id);
214
+ if (!row?.link || !row.userId) return null;
215
+ try {
216
+ await checkUser?.(ctx, row.userId);
217
+ } catch {
218
+ return null;
219
+ }
220
+ return row.link;
221
+ },
222
+ });
223
+ export const getLink = createLinkLookup();
224
+ export const finishLink = internalMutation({
86
225
  args: {
87
- hash: v.optional(v.string()),
88
- newHash: v.string(),
89
- userId: v.optional(v.string()),
226
+ id: v.id("telemetryIdentities"),
227
+ eventId: v.string(),
228
+ success: v.boolean(),
90
229
  },
91
- returns: v.union(v.boolean(), v.null()),
92
- handler: async (ctx, { hash, newHash, userId }) => {
93
- const row = hash
94
- ? await ctx.db
95
- .query("telemetryIdentities")
96
- .withIndex("by_hash", (q) => q.eq("hash", hash))
97
- .unique()
98
- : null;
230
+ returns: v.null(),
231
+ handler: async (ctx, { id, eventId, success }) => {
232
+ const row = await ctx.db.get("telemetryIdentities", id);
233
+ if (!row?.link || row.link.eventId !== eventId) return null;
234
+ if (success)
235
+ await ctx.db.patch("telemetryIdentities", id, { link: undefined });
236
+ return null;
237
+ },
238
+ });
239
+ export const beginLink = internalMutation({
240
+ args: {
241
+ id: v.id("telemetryIdentities"),
242
+ eventId: v.string(),
243
+ attempts: v.number(),
244
+ },
245
+ returns: v.boolean(),
246
+ handler: async (ctx, { id, eventId, attempts }) => {
247
+ const row = await ctx.db.get("telemetryIdentities", id);
99
248
  if (
100
- row &&
101
- row.expiresAt > Date.now() &&
102
- (!row.userId || row.userId === userId)
103
- ) {
104
- if (userId && !row.userId)
105
- await ctx.db.patch("telemetryIdentities", row._id, { userId });
106
- return true;
107
- }
108
- const now = Date.now();
109
- const bucket = await ctx.db
110
- .query("telemetryIssuance")
111
- .withIndex("by_key", (q) => q.eq("key", "global"))
112
- .unique();
113
- const tokens = bucket
114
- ? Math.min(
115
- issuanceBurst,
116
- bucket.tokens +
117
- Math.max(0, now - bucket.updatedAt) / issuanceRefillMs,
118
- )
119
- : issuanceBurst;
120
- if (tokens < 1) return null;
121
- if (bucket) {
122
- await ctx.db.patch("telemetryIssuance", bucket._id, {
123
- tokens: tokens - 1,
124
- updatedAt: now,
125
- });
126
- } else {
127
- await ctx.db.insert("telemetryIssuance", {
128
- key: "global",
129
- tokens: tokens - 1,
130
- updatedAt: now,
249
+ !row?.link ||
250
+ row.link.eventId !== eventId ||
251
+ row.link.attempts !== attempts ||
252
+ attempts >= 5
253
+ )
254
+ return false;
255
+ await ctx.db.patch("telemetryIdentities", id, {
256
+ link: {
257
+ ...row.link,
258
+ attempts: attempts + 1,
259
+ retryAfter: Date.now() + 5 * 60_000,
260
+ },
261
+ });
262
+ if (attempts + 1 < 5)
263
+ await ctx.scheduler.runAfter(2 ** (attempts + 1) * 1000, deliverLinkRef, {
264
+ id,
131
265
  });
266
+ return true;
267
+ },
268
+ });
269
+ const getLinkRef = makeFunctionReference<
270
+ "query",
271
+ { id: string },
272
+ {
273
+ anonymous: string;
274
+ distinct: string;
275
+ eventId: string;
276
+ createdAt: number;
277
+ attempts: number;
278
+ retryAfter: number;
279
+ } | null
280
+ >("telemetry:getLink");
281
+ const finishLinkRef = makeFunctionReference<
282
+ "mutation",
283
+ { id: string; eventId: string; success: boolean },
284
+ null
285
+ >("telemetry:finishLink");
286
+ const beginLinkRef = makeFunctionReference<
287
+ "mutation",
288
+ { id: string; eventId: string; attempts: number },
289
+ boolean
290
+ >("telemetry:beginLink");
291
+ export const deliverLink = internalAction({
292
+ args: { id: v.id("telemetryIdentities") },
293
+ returns: v.null(),
294
+ handler: async (ctx, { id }) => {
295
+ const link = await ctx.runQuery(getLinkRef, { id });
296
+ if (!link || link.attempts >= 5) return null;
297
+ if (
298
+ !(await ctx.runMutation(beginLinkRef, {
299
+ id,
300
+ eventId: link.eventId,
301
+ attempts: link.attempts,
302
+ }))
303
+ )
304
+ return null;
305
+ if (!(await ctx.runQuery(getLinkRef, { id }))) return null;
306
+ let success = false;
307
+ if (telemetryEnabled()) {
308
+ const token =
309
+ settings.analytics?.projectToken ?? process.env.POSTHOG_PROJECT_TOKEN!;
310
+ const host = settings.analytics?.host ?? process.env.POSTHOG_HOST!;
311
+ if (/^phc_[A-Za-z0-9_-]+$/.test(token)) {
312
+ try {
313
+ const response = await fetch(`${host}/capture/`, {
314
+ method: "POST",
315
+ redirect: "error",
316
+ signal: AbortSignal.timeout(2000),
317
+ headers: { "Content-Type": "application/json" },
318
+ body: JSON.stringify({
319
+ api_key: token,
320
+ event: "$identify",
321
+ uuid: link.eventId,
322
+ timestamp: new Date(link.createdAt).toISOString(),
323
+ properties: {
324
+ distinct_id: link.distinct,
325
+ $anon_distinct_id: link.anonymous,
326
+ $ip: "0.0.0.0",
327
+ },
328
+ }),
329
+ });
330
+ success = response.ok;
331
+ } catch {
332
+ /* Retry only this idempotent event. */
333
+ }
334
+ }
132
335
  }
133
- const id = await ctx.db.insert("telemetryIdentities", {
134
- hash: newHash,
135
- expiresAt: Date.now() + identityTtl,
136
- ...(userId ? { userId } : {}),
336
+ await ctx.runMutation(finishLinkRef, {
337
+ id,
338
+ eventId: link.eventId,
339
+ success,
137
340
  });
138
- await ctx.scheduler.runAfter(identityTtl, expireIdentityRef, { id });
139
- return false;
341
+ return null;
140
342
  },
141
343
  });
142
344
 
@@ -165,6 +367,129 @@ async function opaqueId(value: string) {
165
367
  ).join("");
166
368
  }
167
369
 
370
+ const bootstrapClaim = makeFunctionReference<
371
+ "mutation",
372
+ {
373
+ hash?: string;
374
+ newHash: string;
375
+ userId?: string;
376
+ link?: { anonymous: string; distinct: string; eventId: string };
377
+ },
378
+ boolean | null | "linked"
379
+ >("telemetry:claimIdentity");
380
+ const uuidPattern =
381
+ /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
382
+ const bootstrapHeaders = {
383
+ "Access-Control-Allow-Origin": "*",
384
+ "Access-Control-Allow-Headers": "Authorization, Content-Type",
385
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
386
+ "Cache-Control": "no-store",
387
+ };
388
+
389
+ /** Shared by SDK bootstrap and categorized page capture; linking is transactional. */
390
+ export async function claimTelemetryClient(
391
+ ctx: ActionCtx,
392
+ existing: string | undefined,
393
+ userId: string | null,
394
+ ) {
395
+ const projectToken =
396
+ settings.analytics?.projectToken ?? process.env.POSTHOG_PROJECT_TOKEN!;
397
+ const issued = crypto.randomUUID();
398
+ const anonymousDistinct = existing
399
+ ? await opaqueId(`disposabl:${projectToken}:anonymous:${existing}`)
400
+ : undefined;
401
+ const userDistinct = userId
402
+ ? await opaqueId(`disposabl:${projectToken}:${userId}`)
403
+ : undefined;
404
+ const claim = await ctx.runMutation(bootstrapClaim, {
405
+ ...(existing ? { hash: await hashTelemetryIdentity(existing) } : {}),
406
+ newHash: await hashTelemetryIdentity(issued),
407
+ ...(userId ? { userId } : {}),
408
+ ...(anonymousDistinct && userDistinct
409
+ ? {
410
+ link: {
411
+ anonymous: anonymousDistinct,
412
+ distinct: userDistinct,
413
+ eventId: crypto.randomUUID(),
414
+ },
415
+ }
416
+ : {}),
417
+ });
418
+ if (claim === null) return null;
419
+ const anonymousId = claim && existing ? existing : issued;
420
+ const chosenAnonymousDistinct = await opaqueId(
421
+ `disposabl:${projectToken}:anonymous:${anonymousId}`,
422
+ );
423
+ const distinctId = userId
424
+ ? await opaqueId(`disposabl:${projectToken}:${userId}`)
425
+ : chosenAnonymousDistinct;
426
+ return { anonymousId, distinctId };
427
+ }
428
+
429
+ /** The expiry governs client refresh; it cannot revoke the public project token. */
430
+ export async function bootstrapTelemetry(
431
+ ctx: ActionCtx,
432
+ request: Request,
433
+ getUser: (ctx: ActionCtx) => Promise<string | null>,
434
+ enabled: () => boolean = telemetryEnabled,
435
+ ) {
436
+ let body: unknown;
437
+ try {
438
+ body = await request.json();
439
+ } catch {
440
+ return new Response(null, { status: 400, headers: bootstrapHeaders });
441
+ }
442
+ if (
443
+ !body ||
444
+ typeof body !== "object" ||
445
+ Array.isArray(body) ||
446
+ Object.keys(body).some((key) => key !== "anonymousId") ||
447
+ ("anonymousId" in body &&
448
+ (typeof body.anonymousId !== "string" ||
449
+ !uuidPattern.test(body.anonymousId)))
450
+ )
451
+ return new Response(null, { status: 400, headers: bootstrapHeaders });
452
+ if (!enabled())
453
+ return new Response(null, { status: 204, headers: bootstrapHeaders });
454
+ const projectToken =
455
+ settings.analytics?.projectToken ?? process.env.POSTHOG_PROJECT_TOKEN!;
456
+ const host = settings.analytics?.host ?? process.env.POSTHOG_HOST!;
457
+ if (!/^phc_[A-Za-z0-9_-]+$/.test(projectToken))
458
+ return new Response(null, { status: 204, headers: bootstrapHeaders });
459
+ let userId: string | null;
460
+ try {
461
+ userId = await getUser(ctx);
462
+ } catch {
463
+ return new Response(null, { status: 401, headers: bootstrapHeaders });
464
+ }
465
+ if (request.headers.has("Authorization") && !userId)
466
+ return new Response(null, { status: 401, headers: bootstrapHeaders });
467
+ const existing =
468
+ "anonymousId" in body ? (body.anonymousId as string) : undefined;
469
+ let identity: Awaited<ReturnType<typeof claimTelemetryClient>>;
470
+ try {
471
+ identity = await claimTelemetryClient(ctx, existing, userId);
472
+ } catch {
473
+ return new Response(null, {
474
+ status: userId ? 401 : 503,
475
+ headers: bootstrapHeaders,
476
+ });
477
+ }
478
+ if (!identity)
479
+ return new Response(null, { status: 429, headers: bootstrapHeaders });
480
+ return Response.json(
481
+ {
482
+ enabled: true,
483
+ projectToken,
484
+ host,
485
+ ...identity,
486
+ identified: !!userId,
487
+ expiresAt: Date.now() + 30_000,
488
+ },
489
+ { headers: bootstrapHeaders },
490
+ );
491
+ }
492
+
168
493
  /** Only trusted server callers can supply a user or app ID. */
169
494
  export async function captureTelemetry(
170
495
  event: TelemetryEvent,
@@ -238,25 +563,6 @@ export async function captureTelemetry(
238
563
  .map((key) => [key, properties[key]]),
239
564
  ),
240
565
  };
241
- if (userId && anonymousId) {
242
- const response = await fetch(`${host}/capture/`, {
243
- method: "POST",
244
- signal: AbortSignal.timeout(2000),
245
- headers: { "Content-Type": "application/json" },
246
- body: JSON.stringify({
247
- api_key: token,
248
- event: "$identify",
249
- properties: {
250
- distinct_id: identity,
251
- $anon_distinct_id: await opaqueId(
252
- `disposabl:${token}:anonymous:${anonymousId}`,
253
- ),
254
- $ip: "0.0.0.0",
255
- },
256
- }),
257
- });
258
- if (!response.ok) return;
259
- }
260
566
  await fetch(`${host}/capture/`, {
261
567
  method: "POST",
262
568
  signal: AbortSignal.timeout(2000),
@@ -3,6 +3,7 @@ import { readFileSync, writeFileSync, realpathSync } from "node:fs";
3
3
  import { basename, relative, resolve } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { analyzeCommits as conventional } from "@semantic-release/commit-analyzer";
6
+ import { verifyMetadata } from "./verify-metadata.mjs";
6
7
 
7
8
  const contract = "packages/backend/generated/openapi.json";
8
9
  const git = (cwd, ...args) =>
@@ -86,14 +87,40 @@ export async function analyzeCommits(_, context) {
86
87
  return release;
87
88
  }
88
89
 
90
+ // Use semantic-release's original repository URL, before it injects Git credentials.
91
+ export function publicRepositoryUrl(original) {
92
+ if (typeof original !== "string")
93
+ throw new Error("Missing original repository URL");
94
+ const scp = /^(?:[^@/]+@)?([^:/]+):(.+)$/.exec(original);
95
+ const input =
96
+ scp && !original.includes("://")
97
+ ? `https://${scp[1]}/${scp[2]}`
98
+ : original.replace(/^git\+/, "");
99
+ let url;
100
+ try {
101
+ url = new URL(input);
102
+ } catch {
103
+ throw new Error("Invalid repository URL");
104
+ }
105
+ if (!["http:", "https:", "ssh:"].includes(url.protocol))
106
+ throw new Error("Unsupported repository URL");
107
+ if (url.protocol === "ssh:") return `git+https://${url.host}${url.pathname}`;
108
+ url.username = "";
109
+ url.password = "";
110
+ url.search = "";
111
+ url.hash = "";
112
+ return `git+${url.href}`;
113
+ }
114
+
89
115
  // Generated apps acquire their own repository metadata at release time.
90
116
  export function verifyConditions(_, { cwd, options }) {
91
117
  const path = resolve(cwd, "package.json");
92
118
  const manifest = JSON.parse(readFileSync(path, "utf8"));
93
119
  manifest.repository = {
94
120
  type: "git",
95
- url: options.repositoryUrl,
121
+ url: publicRepositoryUrl(options.originalRepositoryURL),
96
122
  directory: `packages/${basename(cwd)}`,
97
123
  };
124
+ verifyMetadata(manifest);
98
125
  writeFileSync(path, JSON.stringify(manifest, null, 2) + "\n");
99
126
  }
@@ -0,0 +1,64 @@
1
+ import { readFileSync, realpathSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+
5
+ // Package metadata must never publish authenticated or signed URLs.
6
+ export function verifyMetadata(manifest) {
7
+ function inspect(value, field) {
8
+ if (typeof value === "string") {
9
+ const candidate = value
10
+ .trim()
11
+ .replace(/[\u0000-\u0020]/g, "")
12
+ .replace(/^git\+/i, "");
13
+ if (
14
+ /^[a-z][a-z\d+.-]*:/i.test(candidate) ||
15
+ /^[\\/]{2}/.test(candidate)
16
+ ) {
17
+ let url;
18
+ try {
19
+ url = new URL(
20
+ candidate,
21
+ /^[\\/]{2}/.test(candidate)
22
+ ? "https://metadata.invalid"
23
+ : undefined,
24
+ );
25
+ } catch {
26
+ throw new Error(`Invalid URL in package metadata: ${field}`);
27
+ }
28
+ if (url.username || url.password || url.search || url.hash)
29
+ throw new Error(`Unsafe URL in package metadata: ${field}`);
30
+ } else if (/^[^/]+@[^/]+:/.test(candidate)) {
31
+ throw new Error(`Unsafe URL in package metadata: ${field}`);
32
+ }
33
+ } else if (Array.isArray(value)) {
34
+ value.forEach((item) => inspect(item, field));
35
+ } else if (value && typeof value === "object") {
36
+ for (const item of Object.values(value)) inspect(item, field);
37
+ }
38
+ }
39
+ for (const field of [
40
+ "repository",
41
+ "homepage",
42
+ "bugs",
43
+ "funding",
44
+ "author",
45
+ "contributors",
46
+ "maintainers",
47
+ "publishConfig",
48
+ ])
49
+ inspect(manifest[field], field);
50
+ }
51
+
52
+ if (
53
+ process.argv[1] &&
54
+ import.meta.url === pathToFileURL(realpathSync(resolve(process.argv[1]))).href
55
+ )
56
+ try {
57
+ verifyMetadata(
58
+ JSON.parse(readFileSync(process.argv[2] ?? "package.json", "utf8")),
59
+ );
60
+ } catch (error) {
61
+ if (error instanceof SyntaxError)
62
+ throw new Error("Invalid package metadata JSON");
63
+ throw error;
64
+ }
@@ -43,3 +43,5 @@ const result = await analytics.track("appsList", () => appsList());
43
43
  Supply your own initialized `posthog` (or another sink); the SDK includes no project key or transport. Set `e2e: true` for E2E builds; `E2E_TELEMETRY_DISABLED=1` also disables capture in Node. Capture failures are ignored. Use field-style responses (the default) or `throwOnError: true` so the wrapper can detect failures. The wrapper cannot detect errors hidden by `responseStyle: "data"`. Only wrapped calls emit events. These owner-configured events are separate from any Disposabl platform usage telemetry; avoid enabling PostHog autocapture or sending request content in the sink.
44
44
 
45
45
  `DO_NOT_TRACK=1` and the browser's `navigator.doNotTrack` setting disable capture. For an SDK generated from your own API, provide `operations: ["notesList", "notesCreate"] as const` with the fixed operation IDs from your generated contract. This replaces the default Disposabl platform operation list. Only identifiers containing letters, numbers, and underscores are accepted; never put user input into this allowlist. Server-side platform operation telemetry, when configured, is separate from this optional owner hook.
46
+
47
+ The hook also suppresses capture in Node development, test and CI environments, when `E2E_TELEMETRY_DISABLED` is set, or when `DISPOSABL_TELEMETRY_DISABLED=1`.
@@ -0,0 +1,8 @@
1
+ await Bun.$`bun run generate`;
2
+ await Bun.$`tsc -p tsconfig.build.json`;
3
+ await Bun.write(
4
+ "dist/verify-metadata.mjs",
5
+ Bun.file("../disposabl-kit/server/release/verify-metadata.mjs"),
6
+ );
7
+
8
+ export {};
@@ -19,10 +19,11 @@
19
19
  },
20
20
  "scripts": {
21
21
  "generate": "openapi-ts && bun fmt src/generated",
22
- "build": "bun run generate && tsc -p tsconfig.build.json",
22
+ "build": "bun build.ts",
23
23
  "typecheck": "bun run generate && tsc --noEmit",
24
24
  "lint": "bun check",
25
- "release": "semantic-release"
25
+ "release": "semantic-release",
26
+ "prepack": "node dist/verify-metadata.mjs"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@hey-api/openapi-ts": "0.99.0",
@@ -67,8 +67,13 @@ export function createSdkAnalytics<
67
67
  config.enabled === false ||
68
68
  config.environment !== "production" ||
69
69
  config.e2e ||
70
- env?.E2E_TELEMETRY_DISABLED === "1" ||
71
- env?.DO_NOT_TRACK === "1" ||
70
+ env?.NODE_ENV === "test" ||
71
+ env?.NODE_ENV === "development" ||
72
+ env?.BUN_ENV === "test" ||
73
+ !!env?.CI ||
74
+ !!env?.E2E_TELEMETRY_DISABLED ||
75
+ env?.DISPOSABL_TELEMETRY_DISABLED === "1" ||
76
+ ["1", "true"].includes(env?.DO_NOT_TRACK?.toLowerCase() ?? "") ||
72
77
  (typeof navigator !== "undefined" && navigator.doNotTrack === "1") ||
73
78
  !allowed.has(operation)
74
79
  )
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: disposabl-app
3
- description: Create, develop, and deliver Disposabl apps, with preview status updates and verification on the requested platforms.
3
+ description: Create, develop, deliver, and submit Disposabl apps, with preview status updates and verification on the requested platforms.
4
4
  ---
5
5
 
6
6
  # Build a Disposabl app
@@ -20,7 +20,7 @@ bun create disposabl-app@latest my-app --platforms web,android,mcp --features au
20
20
 
21
21
  Use the requested platforms and features. Creation handles Disposabl login, required GitHub and Convex setup, and the app's scoped development environment. Resume interrupted setup in the same directory. Do not create a replacement Convex project or delete an app unless requested. Never print credentials.
22
22
 
23
- The CLI is bundled with `create-disposabl-app`; do not use the retired `@disposabl/cli` package. Commands below use the published CLI and work without a global install:
23
+ The CLI is bundled with `create-disposabl-app`. Commands below use that bundled CLI and work without a global install:
24
24
 
25
25
  ```sh
26
26
  bunx --package create-disposabl-app@latest disposabl login status
@@ -37,6 +37,8 @@ Choose a visual direction suited to the product. Read the `frontend-design` skil
37
37
 
38
38
  Read [delivery checks](references/delivery.md) before native builds or delivery repairs. Aim to show a usable web preview early; first native builds can take longer. Do not promise a build deadline.
39
39
 
40
+ For requested App Store or Google Play submission, read [store submissions](references/store-submissions.md). Build and verify the matching store artifacts and reviewer access, then follow the requested submission and release scope.
41
+
40
42
  Prefer local development, builds, and verification whenever the toolchain is available. Do not push or start GitHub Actions merely to test changes. Use the existing release workflows for authorized publication.
41
43
 
42
44
  ## Testing