create-disposabl-app 0.20.16 → 0.20.18

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 (65) hide show
  1. package/dist/disposabl.js +1 -1
  2. package/dist/index.js +3 -1
  3. package/dist/templates/default/.github/scripts/apple.sh +9 -0
  4. package/dist/templates/default/.github/scripts/release.sh +11 -1
  5. package/dist/templates/default/.github/workflows/pipeline.yml +1 -1
  6. package/dist/templates/default/apps/docs/content/mobile.mdx +2 -0
  7. package/dist/templates/default/apps/docs/content/publishing/apple.mdx +12 -0
  8. package/dist/templates/default/apps/docs/content/publishing/google-play.mdx +12 -0
  9. package/dist/templates/default/apps/docs/content/publishing/index.mdx +23 -0
  10. package/dist/templates/default/apps/mobile/eas.json +2 -0
  11. package/dist/templates/default/apps/mobile/package.json +15 -14
  12. package/dist/templates/default/apps/mobile/scripts/android-release-verify.mjs +62 -7
  13. package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +4 -0
  14. package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +48 -0
  15. package/dist/templates/default/bun.lock +111 -169
  16. package/dist/templates/default/disposabl.json +1 -1
  17. package/dist/templates/default/package.json +6 -6
  18. package/dist/templates/default/packages/backend/convex/authEmail.ts +1 -1
  19. package/dist/templates/default/packages/backend/convex/convex.config.ts +1 -0
  20. package/dist/templates/default/packages/backend/convex/users/internal.ts +13 -16
  21. package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +8 -0
  22. package/dist/templates/default/packages/disposabl-kit/client/components/cookie-consent.tsx +117 -0
  23. package/dist/templates/default/packages/disposabl-kit/client/components/google-sign-in.tsx +0 -2
  24. package/dist/templates/default/packages/disposabl-kit/client/components/legal-page.tsx +19 -1
  25. package/dist/templates/default/packages/disposabl-kit/client/routes/_auth-pages/verify-email.tsx +4 -2
  26. package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +18 -4
  27. package/dist/templates/default/packages/disposabl-kit/client/styles/cookie-consent.css +54 -0
  28. package/dist/templates/default/packages/disposabl-kit/legal/config.ts +10 -7
  29. package/dist/templates/default/packages/disposabl-kit/legal/documents/privacy.ts +3 -1
  30. package/dist/templates/default/packages/disposabl-kit/legal/index.ts +2 -1
  31. package/dist/templates/default/packages/disposabl-kit/legal/publisher.ts +5 -1
  32. package/dist/templates/default/packages/disposabl-kit/legal/types.ts +18 -0
  33. package/dist/templates/default/packages/disposabl-kit/lib/auth-errors.ts +2 -0
  34. package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +168 -99
  35. package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-ui.tsx +9 -21
  36. package/dist/templates/default/packages/disposabl-kit/mobile/components/email-verification.tsx +4 -2
  37. package/dist/templates/default/packages/disposabl-kit/mobile/components/settings-page.tsx +52 -20
  38. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +13 -4
  39. package/dist/templates/default/packages/disposabl-kit/mobile/lib/auth-errors.ts +2 -0
  40. package/dist/templates/default/packages/disposabl-kit/package.json +14 -9
  41. package/dist/templates/default/packages/disposabl-kit/payments/catalog.ts +6 -0
  42. package/dist/templates/default/packages/disposabl-kit/payments/config.ts +5 -3
  43. package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +15 -3
  44. package/dist/templates/default/packages/disposabl-kit/server/billing-native-capability.ts +33 -6
  45. package/dist/templates/default/packages/disposabl-kit/server/billing.ts +11 -3
  46. package/dist/templates/default/packages/disposabl-kit/server/revenuecat-contract.ts +87 -8
  47. package/dist/templates/default/packages/disposabl-kit/server/revenuecat-functions.ts +34 -8
  48. package/dist/templates/default/packages/disposabl-kit/server/revenuecat-validator.ts +3 -0
  49. package/dist/templates/default/packages/tests/billing-setup.test.ts +14 -14
  50. package/dist/templates/default/packages/tests/billing.test.ts +22 -0
  51. package/dist/templates/default/packages/tests/components/mobile-account-billing.test.mjs +149 -0
  52. package/dist/templates/default/packages/tests/flows/email-delivery.e2e.ts +1 -1
  53. package/dist/templates/default/packages/tests/flows/legal.e2e.ts +7 -5
  54. package/dist/templates/default/packages/tests/flows/password-backend.e2e.ts +1 -1
  55. package/dist/templates/default/packages/tests/helpers/auth-email-setup/probe.test.mjs +1 -1
  56. package/dist/templates/default/packages/tests/ios-ota.test.ts +32 -10
  57. package/dist/templates/default/packages/tests/mobile-account-billing.test.ts +19 -0
  58. package/dist/templates/default/packages/tests/native-billing.test.ts +71 -0
  59. package/dist/templates/default/packages/tests/package-release.test.ts +16 -0
  60. package/dist/templates/default/packages/tests/revenuecat-inbox.test.ts +91 -3
  61. package/dist/templates/default/patches/expo-modules-core@58.1.0.patch +23 -0
  62. package/dist/templates/default/vendor/README.md +4 -10
  63. package/dist/templates/default/vendor/convex-auth-2.0.0-disposabl.2.patch +2096 -0
  64. package/dist/templates/default/vendor/convex-auth-2.0.0-disposabl.2.tgz +0 -0
  65. package/package.json +1 -1
@@ -1,12 +1,39 @@
1
1
  import { revenueCatConfigs } from "./revenuecat-contract";
2
2
 
3
- /** Expose only non-secret routing metadata after an operator verifies the integration. */
4
- export function nativeTopupRoutes(
3
+ type Environment = Record<string, string | undefined>;
4
+
5
+ /** Server-derived user IDs only; the route configuration validates the allowlist. */
6
+ export function reviewerNativeSubscriptionsEnabled(
5
7
  enabled: boolean,
6
- env: Record<string, string | undefined>,
8
+ env: Environment,
9
+ userId?: string,
7
10
  ) {
8
- if (env.REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED !== "true") return [];
9
- return (revenueCatConfigs(enabled, env) ?? []).map(
10
- ({ app, store, product }) => ({ app, store, product }),
11
+ return (
12
+ !!userId &&
13
+ (revenueCatConfigs(enabled, env) ?? []).some(
14
+ (route) =>
15
+ route.reviewerMonthly && route.reviewerCustomers?.includes(userId),
16
+ )
11
17
  );
12
18
  }
19
+
20
+ /** Expose non-secret consumable routes after verification or for a qualified test account. */
21
+ export function nativeTopupRoutes(
22
+ enabled: boolean,
23
+ env: Environment,
24
+ userId?: string,
25
+ ) {
26
+ const configs = revenueCatConfigs(enabled, env) ?? [];
27
+ const globallyVerified =
28
+ env.REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED === "true";
29
+ const eligible = reviewerNativeSubscriptionsEnabled(enabled, env, userId);
30
+ return configs
31
+ .filter(
32
+ (route) =>
33
+ !route.reviewerMonthly &&
34
+ (globallyVerified
35
+ ? !route.reviewerCustomers
36
+ : eligible && route.reviewerCustomers?.includes(userId!)),
37
+ )
38
+ .map(({ app, store, product }) => ({ app, store, product }));
39
+ }
@@ -120,9 +120,17 @@ export function balanceFromCustomer(
120
120
  customer: Record<string, unknown>,
121
121
  config: Pricing = pricing,
122
122
  ): number | null {
123
- const balances = customer.balances as
124
- Record<string, { remaining?: unknown }> | undefined;
125
- const remaining = balances?.[config.featureId]?.remaining;
123
+ const plainObject = (value: unknown): value is Record<string, unknown> =>
124
+ value !== null &&
125
+ typeof value === "object" &&
126
+ (Object.getPrototypeOf(value) === Object.prototype ||
127
+ Object.getPrototypeOf(value) === null);
128
+ const balances = customer.balances;
129
+ if (!plainObject(balances) || !Object.values(balances).every(plainObject))
130
+ return null;
131
+ if (!Object.hasOwn(balances, config.featureId)) return 0;
132
+ const remaining = (balances[config.featureId] as Record<string, unknown>)
133
+ .remaining;
126
134
  return typeof remaining === "number" && Number.isFinite(remaining)
127
135
  ? remaining
128
136
  : null;
@@ -9,6 +9,8 @@ export type RevenueCatConfig = {
9
9
  store: "APP_STORE" | "PLAY_STORE";
10
10
  autumnKey: string;
11
11
  managedMonthlyProducts?: string[];
12
+ reviewerCustomers?: string[];
13
+ reviewerMonthly?: boolean;
12
14
  };
13
15
 
14
16
  export type PurchaseEvent = {
@@ -20,7 +22,8 @@ export type PurchaseEvent = {
20
22
  product: string;
21
23
  customer: string;
22
24
  transaction: string;
23
- type: "purchase" | "cancel" | "review";
25
+ type: "purchase" | "cancel" | "review" | "ignore";
26
+ expiresAt?: number;
24
27
  };
25
28
 
26
29
  export function parseTransfer(payload: unknown, config: RevenueCatConfig) {
@@ -43,6 +46,7 @@ export function parseTransfer(payload: unknown, config: RevenueCatConfig) {
43
46
  (id) => typeof id === "string" && id.length > 0 && id.length <= 256,
44
47
  );
45
48
  if (
49
+ config.reviewerCustomers !== undefined ||
46
50
  e.type !== "TRANSFER" ||
47
51
  e.app_id !== config.app ||
48
52
  e.environment !== config.environment ||
@@ -149,6 +153,42 @@ export function revenueCatConfigs(
149
153
  (config.managedMonthlyProducts ??= []).push(route.product);
150
154
  }
151
155
  }
156
+ if (environment === "PRODUCTION" && env.REVENUECAT_REVIEWER_USERS) {
157
+ let users: unknown;
158
+ try {
159
+ users = JSON.parse(env.REVENUECAT_REVIEWER_USERS);
160
+ } catch {
161
+ return null;
162
+ }
163
+ if (
164
+ !Array.isArray(users) ||
165
+ !users.length ||
166
+ users.length > 20 ||
167
+ !users.every(
168
+ (id) => typeof id === "string" && /^[a-z0-9]{20,64}$/.test(id),
169
+ ) ||
170
+ new Set(users).size !== users.length
171
+ )
172
+ return null;
173
+ const reviewers = users as string[];
174
+ const sandbox = result.flatMap((route) => [
175
+ {
176
+ ...route,
177
+ environment: "SANDBOX" as const,
178
+ managedMonthlyProducts: undefined,
179
+ reviewerCustomers: reviewers,
180
+ },
181
+ ...(route.managedMonthlyProducts ?? []).map((product) => ({
182
+ ...route,
183
+ product,
184
+ environment: "SANDBOX" as const,
185
+ managedMonthlyProducts: undefined,
186
+ reviewerCustomers: reviewers,
187
+ reviewerMonthly: true,
188
+ })),
189
+ ]);
190
+ result.push(...sandbox);
191
+ }
152
192
  return result;
153
193
  }
154
194
 
@@ -235,16 +275,48 @@ export function parseRevenueCatEvent(
235
275
  const customer = e.app_user_id as string;
236
276
  if (
237
277
  customer.startsWith("$RCAnonymousID:") ||
278
+ (config.reviewerCustomers &&
279
+ !config.reviewerCustomers.includes(customer)) ||
238
280
  (e.original_app_user_id !== undefined &&
239
281
  e.original_app_user_id !== customer)
240
282
  )
241
283
  return null;
242
- const type =
243
- e.type === "NON_RENEWING_PURCHASE"
244
- ? "purchase"
245
- : e.type === "CANCELLATION"
246
- ? "cancel"
247
- : "review";
284
+ let type: PurchaseEvent["type"];
285
+ let expiresAt: number | undefined;
286
+ if (config.reviewerMonthly) {
287
+ if (e.type === "INITIAL_PURCHASE" || e.type === "RENEWAL") {
288
+ if (
289
+ !Number.isSafeInteger(e.expiration_at_ms) ||
290
+ (e.expiration_at_ms as number) <= 0
291
+ )
292
+ return null;
293
+ expiresAt = e.expiration_at_ms as number;
294
+ type = "purchase";
295
+ } else if (
296
+ e.type === "CANCELLATION" &&
297
+ e.cancel_reason === "CUSTOMER_SUPPORT"
298
+ )
299
+ type = "cancel";
300
+ else if (
301
+ (e.type === "CANCELLATION" &&
302
+ [
303
+ "UNSUBSCRIBE",
304
+ "BILLING_ERROR",
305
+ "DEVELOPER_INITIATED",
306
+ "PRICE_INCREASE",
307
+ ].includes(e.cancel_reason as string)) ||
308
+ e.type === "EXPIRATION"
309
+ )
310
+ type = "ignore";
311
+ else type = "review";
312
+ } else {
313
+ type =
314
+ e.type === "NON_RENEWING_PURCHASE"
315
+ ? "purchase"
316
+ : e.type === "CANCELLATION"
317
+ ? "cancel"
318
+ : "review";
319
+ }
248
320
  return {
249
321
  deliveryId: e.id as string,
250
322
  project: config.project,
@@ -255,6 +327,7 @@ export function parseRevenueCatEvent(
255
327
  customer,
256
328
  transaction: e.transaction_id as string,
257
329
  type,
330
+ ...(expiresAt === undefined ? {} : { expiresAt }),
258
331
  };
259
332
  }
260
333
 
@@ -282,13 +355,19 @@ export function balanceRequest(
282
355
  customer: string,
283
356
  balance: string,
284
357
  kind: "grant" | "refund",
358
+ expiresAt?: number,
285
359
  ) {
286
360
  return {
287
361
  customer_id: customer,
288
362
  feature_id: pricing.featureId,
289
363
  balance_id: balance,
290
364
  ...(kind === "grant"
291
- ? { included_grant: creditQuantity("topup") }
365
+ ? {
366
+ included_grant: creditQuantity(
367
+ expiresAt === undefined ? "topup" : "monthly",
368
+ ),
369
+ ...(expiresAt === undefined ? {} : { expires_at: expiresAt }),
370
+ }
292
371
  : { remaining: 0 }),
293
372
  };
294
373
  }
@@ -62,7 +62,7 @@ const claimRef = makeFunctionReference<
62
62
  store: string;
63
63
  product: string;
64
64
  },
65
- { customer: string; kind: "grant" | "refund" } | null
65
+ { customer: string; kind: "grant" | "refund"; expiresAt?: number } | null
66
66
  >("revenuecat:claim");
67
67
  const completeRef = makeFunctionReference<
68
68
  "mutation",
@@ -119,6 +119,7 @@ export const createWebhook = (
119
119
  }
120
120
  const event = parseRevenueCatEvent(payload, config);
121
121
  if (!event) return new Response("Invalid event", { status: 400 });
122
+ if (event.type === "ignore") return Response.json({ status: "ignored" });
122
123
  const result = await ctx.runMutation(receiveRef, {
123
124
  event,
124
125
  balanceId: await balanceId(event),
@@ -303,7 +304,8 @@ export const receive = internalMutation({
303
304
  existingDelivery.balanceId !== balanceId ||
304
305
  existingDelivery.customer !== event.customer ||
305
306
  existingDelivery.type !== event.type ||
306
- existingDelivery.product !== event.product
307
+ existingDelivery.product !== event.product ||
308
+ existingDelivery.expiresAt !== event.expiresAt
307
309
  )
308
310
  throw new Error("Conflicting delivery");
309
311
  return existingDelivery.conflict ? "operator_review" : "pending";
@@ -314,7 +316,9 @@ export const receive = internalMutation({
314
316
  .unique();
315
317
  const conflict =
316
318
  !!prior &&
317
- (prior.customer !== event.customer || prior.product !== event.product);
319
+ (prior.customer !== event.customer ||
320
+ prior.product !== event.product ||
321
+ (event.type === "purchase" && prior.expiresAt !== event.expiresAt));
318
322
  await ctx.db.insert("revenueCatDeliveries", {
319
323
  ...event,
320
324
  balanceId,
@@ -337,6 +341,9 @@ export const receive = internalMutation({
337
341
  transaction: event.transaction,
338
342
  product: event.product,
339
343
  customer: event.customer,
344
+ ...(event.expiresAt === undefined
345
+ ? {}
346
+ : { expiresAt: event.expiresAt }),
340
347
  state,
341
348
  refundPending: false,
342
349
  reviewPending: false,
@@ -393,6 +400,7 @@ export const claim = internalMutation({
393
400
  v.object({
394
401
  customer: v.string(),
395
402
  kind: v.union(v.literal("grant"), v.literal("refund")),
403
+ expiresAt: v.optional(v.number()),
396
404
  }),
397
405
  ),
398
406
  handler: async (
@@ -425,6 +433,8 @@ export const claim = internalMutation({
425
433
  .take(1);
426
434
  if (holds.length) return null;
427
435
  if (row.state === "queued") {
436
+ if (row.expiresAt !== undefined && row.expiresAt <= Date.now())
437
+ return null;
428
438
  const customerId = ctx.db.normalizeId("users", row.customer);
429
439
  if (!customerId || !(await ctx.db.get("users", customerId))) return null;
430
440
  }
@@ -433,7 +443,11 @@ export const claim = internalMutation({
433
443
  await ctx.db.patch("revenueCatPurchases", row._id, {
434
444
  state: kind === "grant" ? "grant_unknown" : "refund_unknown",
435
445
  });
436
- return { customer: row.customer, kind };
446
+ return {
447
+ customer: row.customer,
448
+ kind,
449
+ ...(row.expiresAt === undefined ? {} : { expiresAt: row.expiresAt }),
450
+ };
437
451
  },
438
452
  });
439
453
 
@@ -517,9 +531,11 @@ export const complete = internalMutation({
517
531
  export async function dispatchBalance(
518
532
  config: RevenueCatConfig,
519
533
  balanceId: string,
520
- claimOperation: (
521
- scope: ReturnType<typeof scopedOperation>,
522
- ) => Promise<{ customer: string; kind: "grant" | "refund" } | null>,
534
+ claimOperation: (scope: ReturnType<typeof scopedOperation>) => Promise<{
535
+ customer: string;
536
+ kind: "grant" | "refund";
537
+ expiresAt?: number;
538
+ } | null>,
523
539
  completeOperation: (kind: "grant" | "refund") => Promise<unknown>,
524
540
  fetcher: typeof fetch = fetch,
525
541
  ) {
@@ -527,11 +543,21 @@ export async function dispatchBalance(
527
543
  scopedOperation({ config, balanceId }),
528
544
  );
529
545
  if (!operation) return;
546
+ if (
547
+ config.reviewerCustomers &&
548
+ !config.reviewerCustomers.includes(operation.customer)
549
+ )
550
+ return;
530
551
  try {
531
552
  const result = await billingRequest(
532
553
  config.autumnKey,
533
554
  operation.kind === "grant" ? "balances.create" : "balances.update",
534
- balanceRequest(operation.customer, balanceId, operation.kind),
555
+ balanceRequest(
556
+ operation.customer,
557
+ balanceId,
558
+ operation.kind,
559
+ operation.expiresAt,
560
+ ),
535
561
  fetcher,
536
562
  );
537
563
  if (result.success === true) await completeOperation(operation.kind);
@@ -10,10 +10,12 @@ export const purchaseEventFields = {
10
10
  product: v.string(),
11
11
  customer: v.string(),
12
12
  transaction: v.string(),
13
+ expiresAt: v.optional(v.number()),
13
14
  type: v.union(
14
15
  v.literal("purchase"),
15
16
  v.literal("cancel"),
16
17
  v.literal("review"),
18
+ v.literal("ignore"),
17
19
  ),
18
20
  };
19
21
  export const revenueCatDeliveries = defineTable({
@@ -44,6 +46,7 @@ export const revenueCatPurchases = defineTable({
44
46
  v.literal("refunded"),
45
47
  v.literal("review"),
46
48
  ),
49
+ expiresAt: v.optional(v.number()),
47
50
  refundPending: v.boolean(),
48
51
  reviewPending: v.boolean(),
49
52
  refundEvidence: v.optional(v.string()),
@@ -91,7 +91,7 @@ test("defaults create monthly included credits and nonexpiring prepaid top-ups o
91
91
  {
92
92
  method: "features.create",
93
93
  body: {
94
- feature_id: "credits",
94
+ feature_id: pricing.featureId,
95
95
  name: "Credits",
96
96
  type: "metered",
97
97
  consumable: true,
@@ -100,13 +100,13 @@ test("defaults create monthly included credits and nonexpiring prepaid top-ups o
100
100
  {
101
101
  method: "plans.create",
102
102
  body: {
103
- plan_id: "credits_monthly",
103
+ plan_id: pricing.monthly.planId,
104
104
  name: "Monthly credits",
105
105
  auto_enable: false,
106
106
  price: { amount: 5, interval: "month" },
107
107
  items: [
108
108
  {
109
- feature_id: "credits",
109
+ feature_id: pricing.featureId,
110
110
  included: 750,
111
111
  reset: { interval: "month" },
112
112
  },
@@ -116,13 +116,13 @@ test("defaults create monthly included credits and nonexpiring prepaid top-ups o
116
116
  {
117
117
  method: "plans.create",
118
118
  body: {
119
- plan_id: "credits_topup",
119
+ plan_id: pricing.topup.planId,
120
120
  name: "Credits top-up",
121
121
  add_on: true,
122
122
  auto_enable: false,
123
123
  items: [
124
124
  {
125
- feature_id: "credits",
125
+ feature_id: pricing.featureId,
126
126
  price: {
127
127
  amount: 5,
128
128
  billing_units: 500,
@@ -177,14 +177,14 @@ test("edited config drives new IDs, prices and quantities without assuming USD",
177
177
 
178
178
  test("custom, archived and unrelated catalog entries remain byte-for-byte unchanged", async () => {
179
179
  const p = provider();
180
- p.features.set("credits", {
181
- id: "credits",
180
+ p.features.set(pricing.featureId, {
181
+ id: pricing.featureId,
182
182
  type: "credit_system",
183
183
  archived: true,
184
184
  creditSchema: ["custom"],
185
185
  });
186
- p.plans.set("credits_monthly", {
187
- id: "credits_monthly",
186
+ p.plans.set(pricing.monthly.planId, {
187
+ id: pricing.monthly.planId,
188
188
  price: { amount: 37 },
189
189
  version: 8,
190
190
  archived: true,
@@ -192,8 +192,8 @@ test("custom, archived and unrelated catalog entries remain byte-for-byte unchan
192
192
  p.plans.set("enterprise", { id: "enterprise", name: "Custom deal" });
193
193
  const before = JSON.stringify([...p.features, ...p.plans]);
194
194
  const result = await setupBilling(true, env, pricing, p.fetcher);
195
- assert.deepEqual(result.created, ["plans:credits_topup"]);
196
- p.plans.delete("credits_topup");
195
+ assert.deepEqual(result.created, [`plans:${pricing.topup.planId}`]);
196
+ p.plans.delete(pricing.topup.planId);
197
197
  assert.equal(JSON.stringify([...p.features, ...p.plans]), before);
198
198
  });
199
199
 
@@ -203,7 +203,7 @@ test("partial failure stops writes and a later run resumes from provider state",
203
203
  const body = JSON.parse(String(init?.body));
204
204
  if (
205
205
  String(url).endsWith("plans.create") &&
206
- body.plan_id === "credits_topup"
206
+ body.plan_id === pricing.topup.planId
207
207
  )
208
208
  return new Response("private error", { status: 500 });
209
209
  return p.fetcher(url, init);
@@ -215,7 +215,7 @@ test("partial failure stops writes and a later run resumes from provider state",
215
215
  assert.equal(p.features.size, 1);
216
216
  assert.equal(p.plans.size, 1);
217
217
  const resumed = await setupBilling(true, env, pricing, p.fetcher);
218
- assert.deepEqual(resumed.created, ["plans:credits_topup"]);
218
+ assert.deepEqual(resumed.created, [`plans:${pricing.topup.planId}`]);
219
219
  assert.equal(
220
220
  p.calls.filter((call) => call.method.endsWith(".create")).length,
221
221
  3,
@@ -265,7 +265,7 @@ test("uncertain create is not retried in place; next run discovers committed ent
265
265
  assert.equal(p.calls.length, 3);
266
266
  assert.equal(p.plans.size, 0);
267
267
  const resumed = await setupBilling(true, env, pricing, p.fetcher);
268
- assert.deepEqual(resumed.preserved, ["features:credits"]);
268
+ assert.deepEqual(resumed.preserved, [`features:${pricing.featureId}`]);
269
269
  assert.equal(resumed.created.length, 2);
270
270
  }
271
271
  });
@@ -172,6 +172,28 @@ describe("billing boundary", () => {
172
172
  }),
173
173
  750,
174
174
  );
175
+ assert.equal(balanceFromCustomer({ balances: {} }), 0);
176
+ assert.equal(
177
+ balanceFromCustomer({
178
+ balances: {
179
+ [`${pricing.featureId}_other`]: { remaining: 900 },
180
+ [`${pricing.featureId}_seats`]: { remaining: 5 },
181
+ },
182
+ }),
183
+ 0,
184
+ );
185
+ for (const balances of [
186
+ undefined,
187
+ null,
188
+ [],
189
+ "invalid",
190
+ { other: null },
191
+ { [pricing.featureId]: null },
192
+ { [pricing.featureId]: {} },
193
+ { [pricing.featureId]: { remaining: "750" } },
194
+ { [pricing.featureId]: { remaining: Infinity } },
195
+ ])
196
+ assert.equal(balanceFromCustomer({ balances }), null);
175
197
  assert.equal(balanceFromCustomer({}), null);
176
198
  const mock = (() =>
177
199
  Promise.resolve(
@@ -0,0 +1,149 @@
1
+ import { afterEach, expect, mock, test } from "bun:test";
2
+ import { createElement } from "react";
3
+ import { act, create } from "react-test-renderer";
4
+
5
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
6
+ process.env.EXPO_PUBLIC_REVENUECAT_IOS_API_KEY = "test-key";
7
+ process.env.EXPO_PUBLIC_REVENUECAT_IOS_MONTHLY_PRODUCT = "test-monthly";
8
+ let snapshotFails = false;
9
+ let offeringFails = false;
10
+ let renderer;
11
+ const snapshot = {
12
+ balance: 1000,
13
+ customerId: "customer",
14
+ hasMonthlyPlan: false,
15
+ monthlyCheckoutPending: false,
16
+ nativeSubscriptionsEnabled: true,
17
+ nativeTopupRoutes: [],
18
+ mobileWebCheckoutEnabled: false,
19
+ };
20
+ const sdk = {
21
+ canMakePayments: async () => true,
22
+ getStorefront: async () => ({ countryCode: "USA" }),
23
+ getOfferings: async () => {
24
+ if (offeringFails) throw new Error("BILLING_UNAVAILABLE");
25
+ return {
26
+ current: {
27
+ availablePackages: [
28
+ {
29
+ product: {
30
+ identifier: "test-monthly",
31
+ subscriptionPeriod: "P1M",
32
+ priceString: "$5.00",
33
+ },
34
+ },
35
+ ],
36
+ },
37
+ all: {},
38
+ };
39
+ },
40
+ };
41
+ mock.module("react-native", () => ({
42
+ AppState: { addEventListener: () => ({ remove() {} }) },
43
+ Linking: { openURL: async () => {} },
44
+ Platform: { OS: "ios" },
45
+ Pressable: "Pressable",
46
+ Text: "Text",
47
+ View: "View",
48
+ }));
49
+ const getSnapshot = async () => {
50
+ if (snapshotFails) throw new Error("backend unavailable");
51
+ return snapshot;
52
+ };
53
+ mock.module("convex/react", () => ({ useAction: () => getSnapshot }));
54
+ mock.module("../../../packages/disposabl-kit/mobile/billing/session", () => ({
55
+ billingSession: {
56
+ acquire: () => 1,
57
+ release() {},
58
+ current: () => true,
59
+ run: async (_id, _version, _key, action) => action(sdk),
60
+ },
61
+ }));
62
+ mock.module(
63
+ "../../../packages/disposabl-kit/mobile/billing/web-checkout",
64
+ () => ({
65
+ useWebCheckout: () => ({
66
+ available: false,
67
+ topupAvailable: false,
68
+ busy: false,
69
+ open: async () => {},
70
+ error: "",
71
+ }),
72
+ }),
73
+ );
74
+ mock.module("../../../packages/disposabl-kit/mobile/billing/use-topup", () => ({
75
+ useTopup: () => ({
76
+ product: null,
77
+ busy: false,
78
+ purchase: async () => {},
79
+ message: "",
80
+ }),
81
+ }));
82
+ const { AccountBilling } =
83
+ await import("../../../packages/disposabl-kit/mobile/billing/account-billing");
84
+ const mount = async () => {
85
+ await act(async () => {
86
+ renderer = create(
87
+ createElement(AccountBilling, { customerId: "customer" }),
88
+ );
89
+ });
90
+ };
91
+ const texts = () =>
92
+ renderer.root
93
+ .findAllByType("Text")
94
+ .flatMap((node) => [
95
+ node.children
96
+ .filter(
97
+ (child) => typeof child === "string" || typeof child === "number",
98
+ )
99
+ .join(""),
100
+ ]);
101
+ const contains = (text) => texts().some((value) => value.includes(text));
102
+ const refresh = async () => {
103
+ const button = renderer.root
104
+ .findAllByType("Pressable")
105
+ .find((node) =>
106
+ node
107
+ .findAllByType("Text")
108
+ .some((text) => text.children.includes("Refresh")),
109
+ );
110
+ expect(button).toBeDefined();
111
+ await act(async () => {
112
+ button.props.onPress();
113
+ });
114
+ };
115
+ afterEach(async () => {
116
+ await act(async () => renderer?.unmount());
117
+ renderer = undefined;
118
+ snapshotFails = false;
119
+ offeringFails = false;
120
+ });
121
+
122
+ test("a store offerings failure preserves a verified balance and does not offer a purchase", async () => {
123
+ offeringFails = true;
124
+ await mount();
125
+ expect(contains("1,000 credits")).toBe(true);
126
+ expect(contains("Store subscriptions unavailable.")).toBe(true);
127
+ expect(contains("750 credits / month")).toBe(false);
128
+ });
129
+
130
+ test("a failed backend refresh clears a previously verified balance and offering", async () => {
131
+ await mount();
132
+ expect(contains("1,000 credits")).toBe(true);
133
+ expect(contains("750 credits / month")).toBe(true);
134
+ snapshotFails = true;
135
+ await refresh();
136
+ expect(contains("1,000 credits")).toBe(false);
137
+ expect(contains("Unavailable")).toBe(true);
138
+ expect(contains("750 credits / month")).toBe(false);
139
+ });
140
+
141
+ test("refresh recovers balance and offering when the store comes back", async () => {
142
+ offeringFails = true;
143
+ await mount();
144
+ offeringFails = false;
145
+ await refresh();
146
+ expect(contains("1,000 credits")).toBe(true);
147
+ expect(contains("750 credits / month")).toBe(true);
148
+ expect(contains("$5.00 / mo")).toBe(true);
149
+ });
@@ -72,7 +72,7 @@ test(
72
72
  .map((link: string) => new URL(link).searchParams.get("code"))
73
73
  .find(Boolean);
74
74
  if (!code) throw new Error("Verification email has no code link");
75
- const verified = await call("authEmail:completeSignUp", {
75
+ const verified = await call("authEmail:completeSignUpWithEmailPassword", {
76
76
  emailCode: code,
77
77
  browserSecret: signup.browserSecret,
78
78
  });
@@ -1,21 +1,23 @@
1
1
  import { test } from "@e2e-dev/web";
2
2
  import { expect } from "e2e";
3
3
  import { authenticationEnabled } from "../../disposabl-kit/features";
4
- import { legalConfig } from "../../disposabl-kit/legal";
4
+ import { legalConfig, legalIsDraft } from "../../disposabl-kit/legal";
5
5
 
6
6
  for (const [path, title] of [
7
7
  ["/legal/privacy", "Privacy policy"],
8
8
  ["/legal/terms", "Terms of service"],
9
9
  ] as const) {
10
10
  test(
11
- `${title} is public and identified as a draft`,
11
+ `${title} is public with its publication status`,
12
12
  { platforms: ["web"] },
13
13
  async ({ app, screen, browser }) => {
14
14
  await app.open(path);
15
15
  await expect(screen.getByRole("heading", title)).toBeVisible();
16
- await expect(browser.locator('[role="note"]')).toHaveText(
17
- "Draft documents. Publisher details and data practices are still being reviewed. These documents are not yet final.",
18
- );
16
+ if (legalIsDraft())
17
+ await expect(browser.locator('[role="note"]')).toHaveText(
18
+ "Draft documents. Publisher details and data practices are still being reviewed. These documents are not yet final.",
19
+ );
20
+ else await expect(browser.locator('[role="note"]')).toHaveCount(0);
19
21
  await expect(
20
22
  screen.getByRole("link", "All legal documents"),
21
23
  ).toBeVisible();
@@ -28,7 +28,7 @@ test(
28
28
  newPassword: "Not-a-real-password-2",
29
29
  });
30
30
  expect(denied.value?.success).toBe(false);
31
- expect(denied.value?.userError?.error).toBe("NOT_SIGNED_IN");
31
+ expect(denied.value?.userError?.error).toBe("NOT_LOGGED_IN");
32
32
  const emailDenied = await call("mutation", "authEmail:changePassword", {
33
33
  currentPassword: "Not-a-real-password-1",
34
34
  newPassword: "Not-a-real-password-2",