create-disposabl-app 0.14.18 → 0.16.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 (97) hide show
  1. package/README.md +15 -1
  2. package/dist/disposabl.js +357 -50
  3. package/dist/index.js +8973 -154
  4. package/dist/templates/default/.github/scripts/macos-release.sh +81 -0
  5. package/dist/templates/default/.github/scripts/platforms.sh +1 -1
  6. package/dist/templates/default/.github/scripts/release.sh +1 -1
  7. package/dist/templates/default/.github/workflows/pipeline.yml +14 -3
  8. package/dist/templates/default/apps/desktop/README.md +13 -2
  9. package/dist/templates/default/apps/desktop/forge.config.mts +9 -3
  10. package/dist/templates/default/apps/docs/content/getting-started.mdx +1 -1
  11. package/dist/templates/default/apps/mobile/package.json +1 -0
  12. package/dist/templates/default/apps/web/eslint.config.ts +5 -1
  13. package/dist/templates/default/apps/web/public/disposabl-logo-light.svg +8 -0
  14. package/dist/templates/default/apps/web/public/landing/coast.jpg +0 -0
  15. package/dist/templates/default/apps/web/public/landing/community.jpg +0 -0
  16. package/dist/templates/default/apps/web/public/landing/stores/app-store.svg +46 -0
  17. package/dist/templates/default/apps/web/public/landing/stores/google-play.png +0 -0
  18. package/dist/templates/default/apps/web/public/landing/taste/LICENSE +21 -0
  19. package/dist/templates/default/apps/web/public/landing/taste/init.js +3 -0
  20. package/dist/templates/default/apps/web/public/landing/taste/moments/lib.js +189 -0
  21. package/dist/templates/default/apps/web/public/landing/taste/moments/moments.js +109 -0
  22. package/dist/templates/default/apps/web/public/landing/taste/moments/word-highlight/moment.css +8 -0
  23. package/dist/templates/default/apps/web/public/landing/taste/moments/word-highlight/moment.js +35 -0
  24. package/dist/templates/default/apps/web/public/landing/taste/motion/motion.css +321 -0
  25. package/dist/templates/default/apps/web/public/landing/taste/motion/motion.js +406 -0
  26. package/dist/templates/default/apps/web/routes.config.ts +14 -0
  27. package/dist/templates/default/apps/web/src/router/__root.tsx +8 -2
  28. package/dist/templates/default/apps/web/tsr.config.json +1 -1
  29. package/dist/templates/default/apps/web/vite.config.ts +10 -2
  30. package/dist/templates/default/bun.lock +6 -0
  31. package/dist/templates/default/bunfig.toml +1 -0
  32. package/dist/templates/default/disposabl.json +1 -1
  33. package/dist/templates/default/packages/backend/convex/authSetup.ts +2 -5
  34. package/dist/templates/default/packages/backend/convex/billing.ts +5 -0
  35. package/dist/templates/default/packages/backend/convex/billingHandoff.ts +6 -0
  36. package/dist/templates/default/packages/backend/convex/convex.config.ts +8 -0
  37. package/dist/templates/default/packages/backend/convex/http.ts +6 -0
  38. package/dist/templates/default/packages/backend/convex/revenuecat.ts +13 -0
  39. package/dist/templates/default/packages/backend/convex/schema.ts +44 -0
  40. package/dist/templates/default/packages/backend/convex/telemetry.ts +41 -5
  41. package/dist/templates/default/packages/backend/generate.ts +6 -0
  42. package/dist/templates/default/packages/cli/auth.ts +36 -3
  43. package/dist/templates/default/packages/cli/build.ts +6 -0
  44. package/dist/templates/default/packages/cli/client.ts +189 -19
  45. package/dist/templates/default/packages/cli/errors.ts +18 -0
  46. package/dist/templates/default/packages/cli/telemetry-build.ts +27 -0
  47. package/dist/templates/default/packages/cli/telemetry.ts +266 -0
  48. package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +23 -5
  49. package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry.ts +24 -2
  50. package/dist/templates/default/packages/disposabl-kit/client/lib/theme.ts +1 -0
  51. package/dist/templates/default/packages/disposabl-kit/client/routes/billing-login.tsx +92 -0
  52. package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +113 -43
  53. package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +13 -5
  54. package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +3 -2
  55. package/dist/templates/default/packages/disposabl-kit/lib/telemetry.ts +148 -12
  56. package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +143 -40
  57. package/dist/templates/default/packages/disposabl-kit/mobile/billing/paywall.ts +83 -0
  58. package/dist/templates/default/packages/disposabl-kit/mobile/billing/policy.ts +125 -0
  59. package/dist/templates/default/packages/disposabl-kit/mobile/billing/session.ts +31 -3
  60. package/dist/templates/default/packages/disposabl-kit/mobile/billing/topup.ts +99 -0
  61. package/dist/templates/default/packages/disposabl-kit/mobile/billing/use-topup.ts +116 -0
  62. package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +190 -0
  63. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +9 -2
  64. package/dist/templates/default/packages/disposabl-kit/package.json +10 -1
  65. package/dist/templates/default/packages/disposabl-kit/payments/checkout-attempt.ts +64 -0
  66. package/dist/templates/default/packages/disposabl-kit/payments/config.ts +16 -3
  67. package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +218 -9
  68. package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +126 -0
  69. package/dist/templates/default/packages/disposabl-kit/server/billing-native-capability.ts +12 -0
  70. package/dist/templates/default/packages/disposabl-kit/server/billing-setup.ts +2 -0
  71. package/dist/templates/default/packages/disposabl-kit/server/billing.ts +31 -0
  72. package/dist/templates/default/packages/disposabl-kit/server/browser-session.ts +27 -0
  73. package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +173 -59
  74. package/dist/templates/default/packages/disposabl-kit/server/revenuecat-contract.ts +233 -0
  75. package/dist/templates/default/packages/disposabl-kit/server/revenuecat-functions.ts +554 -0
  76. package/dist/templates/default/packages/disposabl-kit/server/revenuecat-validator.ts +76 -0
  77. package/dist/templates/default/packages/reconfigure-skill/SKILL.md +36 -0
  78. package/dist/templates/default/packages/sdk/README.md +21 -0
  79. package/dist/templates/default/packages/sdk/src/analytics.ts +102 -0
  80. package/dist/templates/default/packages/sdk/src/index.ts +2 -0
  81. package/dist/templates/default/packages/skill/SKILL.md +2 -0
  82. package/dist/templates/default/packages/skill/references/agent.md +2 -0
  83. package/dist/templates/default/packages/tests/billing-attempts.test.ts +156 -0
  84. package/dist/templates/default/packages/tests/billing-handoff.test.ts +116 -0
  85. package/dist/templates/default/packages/tests/billing-setup.test.ts +4 -3
  86. package/dist/templates/default/packages/tests/billing.test.ts +48 -4
  87. package/dist/templates/default/packages/tests/ci-platform-selection.test.ts +54 -0
  88. package/dist/templates/default/packages/tests/desktop-macos-release.test.ts +226 -0
  89. package/dist/templates/default/packages/tests/desktop-packaging.test.ts +12 -0
  90. package/dist/templates/default/packages/tests/flows/seo.e2e.ts +3 -1
  91. package/dist/templates/default/packages/tests/native-billing.test.ts +417 -0
  92. package/dist/templates/default/packages/tests/page-telemetry.test.ts +218 -0
  93. package/dist/templates/default/packages/tests/revenuecat-inbox.test.ts +476 -0
  94. package/dist/templates/default/packages/tests/sdk-analytics.test.ts +158 -0
  95. package/dist/templates/default/packages/tests/telemetry.test.ts +272 -55
  96. package/package.json +1 -1
  97. package/dist/templates/default/apps/web/src/routeTree.gen.ts +0 -578
@@ -0,0 +1,554 @@
1
+ import { httpActionGeneric, makeFunctionReference } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import {
4
+ internalAction,
5
+ internalMutation,
6
+ internalQuery,
7
+ } from "./lib/functions";
8
+ import { paymentsEnabled } from "../features";
9
+ import { billingRequest } from "./billing";
10
+ import {
11
+ balanceId,
12
+ balanceRequest,
13
+ parseRevenueCatEvent,
14
+ parseTransfer,
15
+ revenueCatConfigs,
16
+ selectRevenueCatRoute,
17
+ resolveRevenueCatRoute,
18
+ type PurchaseEvent,
19
+ type RevenueCatConfig,
20
+ } from "./revenuecat-contract";
21
+ import { purchaseEventFields } from "./revenuecat-validator";
22
+
23
+ const receiveRef = makeFunctionReference<
24
+ "mutation",
25
+ { event: PurchaseEvent; balanceId: string },
26
+ string
27
+ >("revenuecat:receive");
28
+ const transferRef = makeFunctionReference<
29
+ "mutation",
30
+ {
31
+ project: string;
32
+ app: string;
33
+ environment: string;
34
+ deliveryId: string;
35
+ from: string[];
36
+ to: string[];
37
+ },
38
+ null
39
+ >("revenuecat:receiveTransfer");
40
+ const dispatchRef = makeFunctionReference<
41
+ "action",
42
+ { balanceId: string },
43
+ null
44
+ >("revenuecat:dispatch");
45
+ const claimRef = makeFunctionReference<
46
+ "mutation",
47
+ {
48
+ balanceId: string;
49
+ project: string;
50
+ app: string;
51
+ environment: string;
52
+ store: string;
53
+ product: string;
54
+ },
55
+ { customer: string; kind: "grant" | "refund" } | null
56
+ >("revenuecat:claim");
57
+ const completeRef = makeFunctionReference<
58
+ "mutation",
59
+ { balanceId: string; kind: "grant" | "refund" },
60
+ null
61
+ >("revenuecat:complete");
62
+
63
+ // Compare digests without early exits. Never expose the configured header in errors.
64
+ async function sameSecret(a: string, b: string) {
65
+ const encoder = new TextEncoder();
66
+ const [x, y] = await Promise.all([
67
+ crypto.subtle.digest("SHA-256", encoder.encode(a)),
68
+ crypto.subtle.digest("SHA-256", encoder.encode(b)),
69
+ ]);
70
+ return (
71
+ new Uint8Array(x).reduce(
72
+ (diff, byte, i) => diff | (byte ^ new Uint8Array(y)[i]!),
73
+ 0,
74
+ ) === 0
75
+ );
76
+ }
77
+
78
+ export async function webhookAuthorized(
79
+ request: Request,
80
+ authorization: string,
81
+ ) {
82
+ const supplied = request.headers.get("authorization");
83
+ return !!supplied && (await sameSecret(supplied, authorization));
84
+ }
85
+
86
+ export const webhook = httpActionGeneric(async (ctx, request) => {
87
+ const configs = revenueCatConfigs(paymentsEnabled, process.env);
88
+ if (!configs) return new Response("Unavailable", { status: 503 });
89
+ if (!(await webhookAuthorized(request, configs[0]!.authorization)))
90
+ return new Response("Unauthorized", { status: 401 });
91
+ let payload: unknown;
92
+ try {
93
+ payload = await request.json();
94
+ } catch {
95
+ return new Response("Invalid event", { status: 400 });
96
+ }
97
+ const config = selectRevenueCatRoute(payload, configs);
98
+ if (!config) return new Response("Invalid event", { status: 400 });
99
+ const transfer = parseTransfer(payload, config);
100
+ if (transfer) {
101
+ await ctx.runMutation(transferRef, transfer);
102
+ return Response.json({ status: "operator_review" }, { status: 202 });
103
+ }
104
+ const event = parseRevenueCatEvent(payload, config);
105
+ if (!event) return new Response("Invalid event", { status: 400 });
106
+ const result = await ctx.runMutation(receiveRef, {
107
+ event,
108
+ balanceId: await balanceId(event),
109
+ });
110
+ // Accepted means persisted, never a claim that the balance has changed.
111
+ return Response.json({ status: result }, { status: 202 });
112
+ });
113
+
114
+ export const receiveTransfer = internalMutation({
115
+ args: {
116
+ project: v.string(),
117
+ app: v.string(),
118
+ environment: v.string(),
119
+ deliveryId: v.string(),
120
+ from: v.array(v.string()),
121
+ to: v.array(v.string()),
122
+ },
123
+ returns: v.null(),
124
+ handler: async (ctx, args) => {
125
+ const delivery = await ctx.db
126
+ .query("revenueCatDeliveries")
127
+ .withIndex("by_delivery", (q) =>
128
+ q
129
+ .eq("project", args.project)
130
+ .eq("app", args.app)
131
+ .eq("environment", args.environment)
132
+ .eq("deliveryId", args.deliveryId),
133
+ )
134
+ .unique();
135
+ if (delivery) throw new Error("Conflicting delivery");
136
+ const prior = await ctx.db
137
+ .query("revenueCatTransfers")
138
+ .withIndex("by_delivery", (q) =>
139
+ q
140
+ .eq("project", args.project)
141
+ .eq("app", args.app)
142
+ .eq("environment", args.environment)
143
+ .eq("deliveryId", args.deliveryId),
144
+ )
145
+ .unique();
146
+ if (prior) {
147
+ if (
148
+ JSON.stringify(prior.from) !== JSON.stringify(args.from) ||
149
+ JSON.stringify(prior.to) !== JSON.stringify(args.to)
150
+ )
151
+ throw new Error("Conflicting delivery");
152
+ } else {
153
+ await ctx.db.insert("revenueCatTransfers", args);
154
+ for (const customer of new Set([...args.from, ...args.to])) {
155
+ await ctx.db.insert("revenueCatTransferHolds", {
156
+ project: args.project,
157
+ app: args.app,
158
+ environment: args.environment,
159
+ deliveryId: args.deliveryId,
160
+ customer,
161
+ active: true,
162
+ });
163
+ }
164
+ }
165
+ return null;
166
+ },
167
+ });
168
+
169
+ export const inspectTransfers = internalQuery({
170
+ args: {},
171
+ returns: v.array(v.any()),
172
+ handler: async (ctx) =>
173
+ ctx.db.query("revenueCatTransfers").order("desc").take(100),
174
+ });
175
+
176
+ export const inspectConflicts = internalQuery({
177
+ args: {},
178
+ returns: v.array(v.any()),
179
+ handler: async (ctx) =>
180
+ ctx.db
181
+ .query("revenueCatDeliveries")
182
+ .withIndex("by_conflict", (q) => q.eq("conflict", true))
183
+ .order("desc")
184
+ .take(100),
185
+ });
186
+
187
+ export const receive = internalMutation({
188
+ args: { event: v.object(purchaseEventFields), balanceId: v.string() },
189
+ returns: v.string(),
190
+ handler: async (ctx, { event, balanceId }) => {
191
+ const userId = ctx.db.normalizeId("users", event.customer);
192
+ if (!userId || !(await ctx.db.get("users", userId)))
193
+ throw new Error("Unknown customer");
194
+ const transfer = await ctx.db
195
+ .query("revenueCatTransfers")
196
+ .withIndex("by_delivery", (q) =>
197
+ q
198
+ .eq("project", event.project)
199
+ .eq("app", event.app)
200
+ .eq("environment", event.environment)
201
+ .eq("deliveryId", event.deliveryId),
202
+ )
203
+ .unique();
204
+ if (transfer) throw new Error("Conflicting delivery");
205
+ const existingDelivery = await ctx.db
206
+ .query("revenueCatDeliveries")
207
+ .withIndex("by_delivery", (q) =>
208
+ q
209
+ .eq("project", event.project)
210
+ .eq("app", event.app)
211
+ .eq("environment", event.environment)
212
+ .eq("deliveryId", event.deliveryId),
213
+ )
214
+ .unique();
215
+ if (existingDelivery) {
216
+ if (
217
+ existingDelivery.balanceId !== balanceId ||
218
+ existingDelivery.customer !== event.customer ||
219
+ existingDelivery.type !== event.type ||
220
+ existingDelivery.product !== event.product
221
+ )
222
+ throw new Error("Conflicting delivery");
223
+ return existingDelivery.conflict ? "operator_review" : "pending";
224
+ }
225
+ const prior = await ctx.db
226
+ .query("revenueCatPurchases")
227
+ .withIndex("by_balanceId", (q) => q.eq("balanceId", balanceId))
228
+ .unique();
229
+ const conflict =
230
+ !!prior &&
231
+ (prior.customer !== event.customer || prior.product !== event.product);
232
+ await ctx.db.insert("revenueCatDeliveries", {
233
+ ...event,
234
+ balanceId,
235
+ conflict,
236
+ });
237
+ if (conflict) return "operator_review";
238
+ if (!prior) {
239
+ const state =
240
+ event.type === "purchase"
241
+ ? "queued"
242
+ : event.type === "cancel"
243
+ ? "tombstone"
244
+ : "review";
245
+ await ctx.db.insert("revenueCatPurchases", {
246
+ balanceId,
247
+ project: event.project,
248
+ app: event.app,
249
+ environment: event.environment,
250
+ store: event.store,
251
+ transaction: event.transaction,
252
+ product: event.product,
253
+ customer: event.customer,
254
+ state,
255
+ refundPending: false,
256
+ reviewPending: false,
257
+ });
258
+ if (state === "queued")
259
+ await ctx.scheduler.runAfter(0, dispatchRef, { balanceId });
260
+ return state === "queued" ? "pending" : "operator_review";
261
+ }
262
+ if (event.type === "cancel") {
263
+ if (prior.state === "queued")
264
+ await ctx.db.patch("revenueCatPurchases", prior._id, {
265
+ state: "tombstone",
266
+ });
267
+ else if (prior.state === "grant_unknown")
268
+ await ctx.db.patch("revenueCatPurchases", prior._id, {
269
+ refundPending: true,
270
+ });
271
+ else if (prior.state === "granted")
272
+ await ctx.db.patch("revenueCatPurchases", prior._id, {
273
+ state: "refund_review",
274
+ });
275
+ } else if (event.type === "review") {
276
+ if (
277
+ ["queued", "granted", "refund_review", "refund_queued"].includes(
278
+ prior.state,
279
+ )
280
+ )
281
+ await ctx.db.patch("revenueCatPurchases", prior._id, {
282
+ state: "review",
283
+ });
284
+ else if (
285
+ prior.state === "grant_unknown" ||
286
+ prior.state === "refund_unknown"
287
+ )
288
+ await ctx.db.patch("revenueCatPurchases", prior._id, {
289
+ reviewPending: true,
290
+ });
291
+ }
292
+ return "pending";
293
+ },
294
+ });
295
+
296
+ export const claim = internalMutation({
297
+ args: {
298
+ balanceId: v.string(),
299
+ project: v.string(),
300
+ app: v.string(),
301
+ environment: v.string(),
302
+ store: v.string(),
303
+ product: v.string(),
304
+ },
305
+ returns: v.union(
306
+ v.null(),
307
+ v.object({
308
+ customer: v.string(),
309
+ kind: v.union(v.literal("grant"), v.literal("refund")),
310
+ }),
311
+ ),
312
+ handler: async (
313
+ ctx,
314
+ { balanceId, project, app, environment, store, product },
315
+ ) => {
316
+ const row = await ctx.db
317
+ .query("revenueCatPurchases")
318
+ .withIndex("by_balanceId", (q) => q.eq("balanceId", balanceId))
319
+ .unique();
320
+ if (
321
+ !row ||
322
+ row.project !== project ||
323
+ row.app !== app ||
324
+ row.environment !== environment ||
325
+ row.store !== store ||
326
+ row.product !== product ||
327
+ (row.state !== "queued" && row.state !== "refund_queued")
328
+ )
329
+ return null;
330
+ const holds = await ctx.db
331
+ .query("revenueCatTransferHolds")
332
+ .withIndex("by_customer_active", (q) =>
333
+ q
334
+ .eq("project", project)
335
+ .eq("environment", environment)
336
+ .eq("customer", row.customer)
337
+ .eq("active", true),
338
+ )
339
+ .take(1);
340
+ if (holds.length) return null;
341
+ const kind: "grant" | "refund" =
342
+ row.state === "queued" ? "grant" : "refund";
343
+ await ctx.db.patch("revenueCatPurchases", row._id, {
344
+ state: kind === "grant" ? "grant_unknown" : "refund_unknown",
345
+ });
346
+ return { customer: row.customer, kind };
347
+ },
348
+ });
349
+
350
+ export const complete = internalMutation({
351
+ args: {
352
+ balanceId: v.string(),
353
+ kind: v.union(v.literal("grant"), v.literal("refund")),
354
+ },
355
+ returns: v.null(),
356
+ handler: async (ctx, { balanceId, kind }) => {
357
+ const row = await ctx.db
358
+ .query("revenueCatPurchases")
359
+ .withIndex("by_balanceId", (q) => q.eq("balanceId", balanceId))
360
+ .unique();
361
+ if (
362
+ row &&
363
+ row.state === (kind === "grant" ? "grant_unknown" : "refund_unknown")
364
+ ) {
365
+ await ctx.db.patch("revenueCatPurchases", row._id, {
366
+ state: row.reviewPending
367
+ ? "review"
368
+ : kind === "refund"
369
+ ? "refunded"
370
+ : row.refundPending
371
+ ? "refund_review"
372
+ : "granted",
373
+ });
374
+ }
375
+ return null;
376
+ },
377
+ });
378
+
379
+ export async function dispatchBalance(
380
+ config: RevenueCatConfig,
381
+ balanceId: string,
382
+ claimOperation: (
383
+ scope: ReturnType<typeof scopedOperation>,
384
+ ) => Promise<{ customer: string; kind: "grant" | "refund" } | null>,
385
+ completeOperation: (kind: "grant" | "refund") => Promise<unknown>,
386
+ fetcher: typeof fetch = fetch,
387
+ ) {
388
+ const operation = await claimOperation(
389
+ scopedOperation({ config, balanceId }),
390
+ );
391
+ if (!operation) return;
392
+ try {
393
+ const result = await billingRequest(
394
+ config.autumnKey,
395
+ operation.kind === "grant" ? "balances.create" : "balances.update",
396
+ balanceRequest(operation.customer, balanceId, operation.kind),
397
+ fetcher,
398
+ );
399
+ if (result.success === true) await completeOperation(operation.kind);
400
+ } catch {
401
+ /* A dispatched write may have committed. Remain unknown. */
402
+ }
403
+ }
404
+
405
+ function scopedOperation({
406
+ config,
407
+ balanceId,
408
+ }: {
409
+ config: RevenueCatConfig;
410
+ balanceId: string;
411
+ }) {
412
+ return {
413
+ balanceId,
414
+ project: config.project,
415
+ app: config.app,
416
+ environment: config.environment,
417
+ store: config.store,
418
+ product: config.product,
419
+ };
420
+ }
421
+
422
+ const routingRef = makeFunctionReference<
423
+ "query",
424
+ { balanceId: string },
425
+ Pick<
426
+ PurchaseEvent,
427
+ "project" | "app" | "environment" | "store" | "product"
428
+ > | null
429
+ >("revenuecat:routing");
430
+
431
+ export const routing = internalQuery({
432
+ args: { balanceId: v.string() },
433
+ returns: v.union(
434
+ v.null(),
435
+ v.object({
436
+ project: v.string(),
437
+ app: v.string(),
438
+ environment: v.string(),
439
+ store: v.string(),
440
+ product: v.string(),
441
+ }),
442
+ ),
443
+ handler: async (ctx, { balanceId }) => {
444
+ const row = await ctx.db
445
+ .query("revenueCatPurchases")
446
+ .withIndex("by_balanceId", (q) => q.eq("balanceId", balanceId))
447
+ .unique();
448
+ return row
449
+ ? {
450
+ project: row.project,
451
+ app: row.app,
452
+ environment: row.environment,
453
+ store: row.store,
454
+ product: row.product,
455
+ }
456
+ : null;
457
+ },
458
+ });
459
+
460
+ export const dispatch = internalAction({
461
+ args: { balanceId: v.string() },
462
+ returns: v.null(),
463
+ handler: async (ctx, { balanceId }) => {
464
+ const configs = revenueCatConfigs(paymentsEnabled, process.env);
465
+ if (!configs) return null;
466
+ const identity = await ctx.runQuery(routingRef, { balanceId });
467
+ const config = identity && resolveRevenueCatRoute(identity, configs);
468
+ if (!config) return null;
469
+ await dispatchBalance(
470
+ config,
471
+ balanceId,
472
+ (scope) => ctx.runMutation(claimRef, scope),
473
+ (kind) => ctx.runMutation(completeRef, { balanceId, kind }),
474
+ );
475
+ return null;
476
+ },
477
+ });
478
+
479
+ /** Private operator tools: inspect states and confirm a full refund after provider review. */
480
+ export const inspect = internalQuery({
481
+ args: {
482
+ state: v.union(
483
+ v.literal("queued"),
484
+ v.literal("grant_unknown"),
485
+ v.literal("granted"),
486
+ v.literal("tombstone"),
487
+ v.literal("refund_review"),
488
+ v.literal("refund_queued"),
489
+ v.literal("refund_unknown"),
490
+ v.literal("refunded"),
491
+ v.literal("review"),
492
+ ),
493
+ },
494
+ returns: v.array(v.any()),
495
+ handler: async (ctx, { state }) =>
496
+ ctx.db
497
+ .query("revenueCatPurchases")
498
+ .withIndex("by_state", (q) => q.eq("state", state))
499
+ .take(100),
500
+ });
501
+ export const confirmFullRefund = internalMutation({
502
+ args: { balanceId: v.string(), evidence: v.string() },
503
+ returns: v.boolean(),
504
+ handler: async (ctx, { balanceId, evidence }) => {
505
+ if (!evidence.trim() || evidence.length > 1000)
506
+ throw new Error("Provider evidence is required");
507
+ const row = await ctx.db
508
+ .query("revenueCatPurchases")
509
+ .withIndex("by_balanceId", (q) => q.eq("balanceId", balanceId))
510
+ .unique();
511
+ if (!row || row.state !== "refund_review") return false;
512
+ await ctx.db.patch("revenueCatPurchases", row._id, {
513
+ state: "refund_queued",
514
+ refundEvidence: evidence.trim(),
515
+ });
516
+ await ctx.scheduler.runAfter(0, dispatchRef, { balanceId });
517
+ return true;
518
+ },
519
+ });
520
+
521
+ // Evidence must identify a provider-confirmed operation; an observed aggregate
522
+ // balance is not sufficient. This never starts another provider request.
523
+ export const confirmUnknown = internalMutation({
524
+ args: {
525
+ balanceId: v.string(),
526
+ kind: v.union(v.literal("grant"), v.literal("refund")),
527
+ evidence: v.string(),
528
+ },
529
+ returns: v.boolean(),
530
+ handler: async (ctx, { balanceId, kind, evidence }) => {
531
+ if (!evidence.trim() || evidence.length > 1000)
532
+ throw new Error("Provider evidence is required");
533
+ const row = await ctx.db
534
+ .query("revenueCatPurchases")
535
+ .withIndex("by_balanceId", (q) => q.eq("balanceId", balanceId))
536
+ .unique();
537
+ if (
538
+ !row ||
539
+ row.state !== (kind === "grant" ? "grant_unknown" : "refund_unknown")
540
+ )
541
+ return false;
542
+ await ctx.db.patch("revenueCatPurchases", row._id, {
543
+ reconciliationEvidence: evidence.trim(),
544
+ state: row.reviewPending
545
+ ? "review"
546
+ : kind === "refund"
547
+ ? "refunded"
548
+ : row.refundPending
549
+ ? "refund_review"
550
+ : "granted",
551
+ });
552
+ return true;
553
+ },
554
+ });
@@ -0,0 +1,76 @@
1
+ import { defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+
4
+ export const purchaseEventFields = {
5
+ deliveryId: v.string(),
6
+ project: v.string(),
7
+ app: v.string(),
8
+ environment: v.string(),
9
+ store: v.string(),
10
+ product: v.string(),
11
+ customer: v.string(),
12
+ transaction: v.string(),
13
+ type: v.union(
14
+ v.literal("purchase"),
15
+ v.literal("cancel"),
16
+ v.literal("review"),
17
+ ),
18
+ };
19
+ export const revenueCatDeliveries = defineTable({
20
+ ...purchaseEventFields,
21
+ balanceId: v.string(),
22
+ conflict: v.boolean(),
23
+ })
24
+ .index("by_delivery", ["project", "app", "environment", "deliveryId"])
25
+ .index("by_conflict", ["conflict"]);
26
+ export const revenueCatPurchases = defineTable({
27
+ balanceId: v.string(),
28
+ project: v.string(),
29
+ app: v.string(),
30
+ environment: v.string(),
31
+ store: v.string(),
32
+ transaction: v.string(),
33
+ product: v.string(),
34
+ customer: v.string(),
35
+ state: v.union(
36
+ v.literal("queued"),
37
+ v.literal("grant_unknown"),
38
+ v.literal("granted"),
39
+ v.literal("tombstone"),
40
+ v.literal("refund_review"),
41
+ v.literal("refund_queued"),
42
+ v.literal("refund_unknown"),
43
+ v.literal("refunded"),
44
+ v.literal("review"),
45
+ ),
46
+ refundPending: v.boolean(),
47
+ reviewPending: v.boolean(),
48
+ refundEvidence: v.optional(v.string()),
49
+ reconciliationEvidence: v.optional(v.string()),
50
+ })
51
+ .index("by_balanceId", ["balanceId"])
52
+ .index("by_state", ["state"]);
53
+ export const revenueCatTransfers = defineTable({
54
+ project: v.string(),
55
+ app: v.string(),
56
+ environment: v.string(),
57
+ deliveryId: v.string(),
58
+ from: v.array(v.string()),
59
+ to: v.array(v.string()),
60
+ }).index("by_delivery", ["project", "app", "environment", "deliveryId"]);
61
+ export const revenueCatTransferHolds = defineTable({
62
+ project: v.string(),
63
+ app: v.string(),
64
+ environment: v.string(),
65
+ customer: v.string(),
66
+ deliveryId: v.string(),
67
+ active: v.boolean(),
68
+ })
69
+ .index("by_customer_active", ["project", "environment", "customer", "active"])
70
+ .index("by_delivery_customer", [
71
+ "project",
72
+ "app",
73
+ "environment",
74
+ "deliveryId",
75
+ "customer",
76
+ ]);
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: disposabl-reconfigure
3
+ description: Update an existing Disposabl app's code when adding or removing features or platforms in disposabl.json, preserving customizations. Does not provision providers or publish the app.
4
+ ---
5
+
6
+ # Change app features and platforms
7
+
8
+ Use this skill in the existing generated app, including an app already published. Keep its app ID, native identities, backend URLs, data, and custom code.
9
+
10
+ Read `disposabl.json`, the Git diff, and the affected workspace instructions. Record the current selections and the user's intended complete selections. `--features` and `--platforms` replace their respective lists; omit a flag to keep that list. Dependencies are resolved by the generator, including Authentication for Payments and Analytics, API for CLI/SDK, and Web for every app.
11
+
12
+ ## Apply code changes
13
+
14
+ Use the generator version recorded in `disposabl.json`, not `latest`. From the parent directory, run the following with the actual version, directory, and complete desired lists:
15
+
16
+ ```sh
17
+ npx create-disposabl-app@<version> <app-directory> --reconfigure-only --platforms web,android --features authentication,payments --skip-install --json
18
+ ```
19
+
20
+ This mode changes local files only. It does not log in, provision services, write secrets, commit, or deploy. Run `bun install` in the app afterward to update dependencies and the lockfile, then review the diff.
21
+
22
+ The generator needs the prior selections in `disposabl.json` to calculate which files to restore. If the lists were already edited, compare with the known working revision. Preserve the desired lists, restore only the prior selection fields, and run the command with the desired lists. If the prior selections cannot be established, explain that missing baseline before changing files. Never reset the whole configuration or discard unrelated edits.
23
+
24
+ Reconfiguration preserves customized files and rejects conflicting starter changes. Resolve each conflict by combining the user's implementation with the necessary feature integration. Do not replace customized files with template copies just to make the command succeed. A version mismatch requires the matching generator; upgrading templates is separate work.
25
+
26
+ Disabling a platform keeps its source so it can be restored later. Feature flags control routes and runtime behavior. Disabling Payments removes unchanged native billing files and SDK dependencies; customized billing files require deliberate reconciliation. Do not delete provider resources, stored data, customer subscriptions, or credentials. Existing subscriptions need a management/cancellation path even when new purchases are disabled.
27
+
28
+ ## Wire and verify
29
+
30
+ Trace the added or removed capability through routes, imports, navigation, feature guards, native config, dependencies, and tests. Preserve the app's design. For mobile styling, use NativeWind classes and existing tokens.
31
+
32
+ For Payments, read `packages/disposabl-kit/PAYMENTS.md` and the editable `payments/config.ts`. Non-mobile checkout uses Autumn. Mobile also requires RevenueCat configuration and native products; adding source cannot configure store accounts or prove purchases work. Keep provider setup as a separate, explicit next step. Never copy another app's keys or invent a credit grant to bypass setup.
33
+
34
+ Read `packages/tests/README.md`. Run the affected typechecks, lint, builds, and behavior flows against the app's development or isolated backend, with telemetry disabled. Check enabled behavior and disabled routes, including direct links. Native dependency changes require rebuilding the client before device verification. Missing credentials or devices are verification limits, not passing checks.
35
+
36
+ Report the changed selections and files, checks that passed or failed, and remaining provider or release steps. Leave publishing to the app's normal delivery workflow.
@@ -22,3 +22,24 @@ const { data: app } = await appsGet({ query: { appId: created!.appId } });
22
22
  Create API keys at `/dashboard/api-keys`. Keep server integration keys on the server. The API also accepts OAuth tokens issued through its MCP authorization server.
23
23
 
24
24
  Run `bun run generate` in `packages/backend`, then `bun run generate` here to update the typed operations. Query parameters use JSON encoding. The backend refuses incompatible contract regeneration without `--accept-breaking`; review that diff before accepting a major contract version.
25
+
26
+ ## Optional SDK analytics
27
+
28
+ The SDK sends no analytics by itself. An application can explicitly wrap calls and forward the approved operation name and outcome to its own analytics project:
29
+
30
+ ```ts
31
+ import { appsList, createSdkAnalytics } from "@disposabl/sdk";
32
+
33
+ const analytics = createSdkAnalytics({
34
+ enabled: true, // defaults to true; set false to opt out
35
+ environment: "production", // use "development" or "test" outside production
36
+ capture: ({ operation, outcome }) => {
37
+ posthog.capture("sdk_operation", { operation, outcome });
38
+ },
39
+ });
40
+ const result = await analytics.track("appsList", () => appsList());
41
+ ```
42
+
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
+
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.