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,226 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import {
4
+ mkdtempSync,
5
+ mkdirSync,
6
+ readFileSync,
7
+ readdirSync,
8
+ rmSync,
9
+ writeFileSync,
10
+ } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join, resolve } from "node:path";
13
+ import { spawnSync } from "node:child_process";
14
+
15
+ test("macOS signed release verifies before enabling publication and cleans credentials", () => {
16
+ const root = mkdtempSync(join(tmpdir(), "macos-release-test-"));
17
+ try {
18
+ const bin = join(root, "bin");
19
+ mkdirSync(bin);
20
+ mkdirSync(join(root, "dist", "release"), { recursive: true });
21
+ writeFileSync(join(root, "dist", "release", "app.zip"), "fixture");
22
+ writeFileSync(join(root, "dist", "release", "app.dmg"), "fixture");
23
+ const mock = (name: string, body: string) =>
24
+ writeFileSync(join(bin, name), `#!/bin/bash\nset -e\n${body}\n`, {
25
+ mode: 0o755,
26
+ });
27
+ mock("security", 'echo "$1" >> "$CALLS"');
28
+ mock(
29
+ "base64",
30
+ `node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>process.stdout.write(Buffer.from(s.trim(),"base64")))'`,
31
+ );
32
+ mock("bun", 'echo build >> "$CALLS"');
33
+ mock("ditto", 'mkdir -p "$4/Test.app"');
34
+ mock(
35
+ "hdiutil",
36
+ 'if [[ "$1" == attach ]]; then [[ "${FAIL_STAGE:-}" != attach ]] || exit 1; mkdir -p "$5/Test.app"; else [[ "${FAIL_STAGE:-}" != detach ]] || exit 1; rm -rf "$2/Test.app"; echo detach >> "$CALLS"; fi',
37
+ );
38
+ mock(
39
+ "codesign",
40
+ `target="\${@: -1}"
41
+ if [[ "$1" == "-dv" ]]; then
42
+ hash=abc123
43
+ if [[ "$target" == */mount/* && "\${FAIL_STAGE:-}" == mismatch ]]; then hash=def456; fi
44
+ printf "Authority=Developer ID Application: Test (ABCDE12345)\\nTeamIdentifier=ABCDE12345\\nCDHash=%s\\n" "$hash" >&2
45
+ else
46
+ [[ "\${FAIL_VERIFY:-}" != true ]] || exit 1
47
+ [[ "$target" != */mount/* || "\${FAIL_STAGE:-}" != signature ]] || exit 1
48
+ fi`,
49
+ );
50
+ mock(
51
+ "xcrun",
52
+ 'echo staple >> "$CALLS"; [[ "${@: -1}" != */mount/* || "${FAIL_STAGE:-}" != staple ]]',
53
+ );
54
+ mock(
55
+ "spctl",
56
+ 'echo assess >> "$CALLS"; [[ "${@: -1}" != */mount/* || "${FAIL_STAGE:-}" != assess ]]',
57
+ );
58
+ const config = JSON.stringify({
59
+ certificateBase64: "Y2VydA==",
60
+ certificatePassword: "fixture-password",
61
+ identity: "Developer ID Application: Test (ABCDE12345)",
62
+ teamId: "ABCDE12345",
63
+ apiKeyBase64: "a2V5",
64
+ apiKeyId: "KEY",
65
+ apiIssuer: "ISSUER",
66
+ });
67
+ const script = resolve(
68
+ import.meta.dirname,
69
+ "../../.github/scripts/macos-release.sh",
70
+ );
71
+ const run = (fail: boolean, signingConfig = config, stage = "") => {
72
+ rmSync(join(root, "env"), { force: true });
73
+ return spawnSync("bash", [script], {
74
+ cwd: root,
75
+ encoding: "utf8",
76
+ env: {
77
+ ...process.env,
78
+ PATH: `${bin}:${process.env.PATH}`,
79
+ RUNNER_TEMP: root,
80
+ GITHUB_ENV: join(root, "env"),
81
+ CALLS: join(root, "calls"),
82
+ MACOS_SIGNING_CONFIG: signingConfig,
83
+ FAIL_VERIFY: String(fail),
84
+ FAIL_STAGE: stage,
85
+ },
86
+ });
87
+ };
88
+ const success = run(false);
89
+ assert.equal(success.status, 0, success.stderr);
90
+ assert.match(
91
+ readFileSync(join(root, "env"), "utf8"),
92
+ /MACOS_NOTARIZE=true\n$/,
93
+ );
94
+ assert.match(readFileSync(join(root, "calls"), "utf8"), /delete-keychain/);
95
+ rmSync(join(root, "env"));
96
+ const failed = run(true);
97
+ assert.notEqual(failed.status, 0);
98
+ assert.equal(
99
+ (failed.stdout + failed.stderr).includes("fixture-password"),
100
+ false,
101
+ );
102
+ assert.doesNotMatch(
103
+ readFileSync(join(root, "env"), "utf8"),
104
+ /MACOS_NOTARIZE=true/,
105
+ );
106
+ assert.equal(
107
+ readFileSync(join(root, "calls"), "utf8").match(/delete-keychain/g)
108
+ ?.length,
109
+ 2,
110
+ );
111
+ assert.equal(
112
+ readdirSync(root).some((name) => name.startsWith("macos-signing.")),
113
+ false,
114
+ );
115
+ for (const stage of ["signature", "staple", "assess", "mismatch"]) {
116
+ const invalidDmg = run(false, config, stage);
117
+ assert.notEqual(invalidDmg.status, 0, stage);
118
+ assert.doesNotMatch(
119
+ readFileSync(join(root, "env"), "utf8"),
120
+ /MACOS_NOTARIZE=true/,
121
+ );
122
+ assert.equal(
123
+ readdirSync(root).some((name) => name.startsWith("macos-signing.")),
124
+ false,
125
+ );
126
+ }
127
+ assert.equal(
128
+ readFileSync(join(root, "calls"), "utf8").match(/^detach$/gm)?.length,
129
+ 5,
130
+ );
131
+ for (const stage of ["attach", "detach"]) {
132
+ assert.notEqual(run(false, config, stage).status, 0, stage);
133
+ assert.doesNotMatch(
134
+ readFileSync(join(root, "env"), "utf8"),
135
+ /MACOS_NOTARIZE=true/,
136
+ );
137
+ const directories = readdirSync(root).filter((name) =>
138
+ name.startsWith("macos-signing."),
139
+ );
140
+ assert.equal(directories.length, stage === "detach" ? 1 : 0);
141
+ for (const directory of directories) {
142
+ const remaining = join(root, directory);
143
+ assert.equal(
144
+ spawnSync("test", ["-e", join(remaining, "AuthKey.p8")]).status,
145
+ 1,
146
+ );
147
+ assert.equal(
148
+ spawnSync("test", ["-e", join(remaining, "certificate.p12")]).status,
149
+ 1,
150
+ );
151
+ // This is a mock directory, not a real mounted volume.
152
+ rmSync(remaining, { recursive: true });
153
+ }
154
+ }
155
+ const incomplete = run(false, JSON.stringify({ identity: "incomplete" }));
156
+ assert.notEqual(incomplete.status, 0);
157
+ assert.equal(spawnSync("test", ["-e", join(root, "env")]).status, 1);
158
+ const unsigned = run(false, "");
159
+ assert.equal(unsigned.status, 0, unsigned.stderr);
160
+ assert.equal(spawnSync("test", ["-e", join(root, "env")]).status, 1);
161
+ const leftover = join(root, "macos-signing.12345678");
162
+ const otherJob = join(root, "macos-signing.87654321");
163
+ mkdirSync(leftover);
164
+ mkdirSync(otherJob);
165
+ writeFileSync(join(leftover, "AuthKey.p8"), "fixture");
166
+ const cleanup = spawnSync("bash", [script, "cleanup"], {
167
+ cwd: root,
168
+ encoding: "utf8",
169
+ env: {
170
+ ...process.env,
171
+ PATH: `${bin}:${process.env.PATH}`,
172
+ RUNNER_TEMP: root,
173
+ MACOS_SIGNING_DIRECTORY: leftover,
174
+ CALLS: join(root, "calls"),
175
+ },
176
+ });
177
+ assert.equal(cleanup.status, 0, cleanup.stderr);
178
+ assert.equal(spawnSync("test", ["-e", leftover]).status, 1);
179
+ assert.equal(spawnSync("test", ["-d", otherJob]).status, 0);
180
+ } finally {
181
+ rmSync(root, { recursive: true, force: true });
182
+ }
183
+ });
184
+
185
+ test("macOS workflow publishes only verified signed artifacts", () => {
186
+ const parsed = spawnSync(
187
+ process.execPath,
188
+ [
189
+ "-e",
190
+ "console.log(JSON.stringify(Bun.YAML.parse(await Bun.stdin.text())))",
191
+ ],
192
+ {
193
+ input: readFileSync(
194
+ resolve(import.meta.dirname, "../../.github/workflows/pipeline.yml"),
195
+ "utf8",
196
+ ),
197
+ encoding: "utf8",
198
+ },
199
+ );
200
+ assert.equal(parsed.status, 0, parsed.stderr);
201
+ const workflow = JSON.parse(parsed.stdout);
202
+ const steps = workflow.jobs.desktop.steps as Array<Record<string, any>>;
203
+ const find = (name: string) => steps.find((step) => step.name === name);
204
+ assert.equal(
205
+ find("Build macOS")?.run,
206
+ "bash .github/scripts/macos-release.sh",
207
+ );
208
+ assert.match(
209
+ find("Upload desktop release artifacts")?.if,
210
+ /MACOS_NOTARIZE == 'true'/,
211
+ );
212
+ assert.match(
213
+ find("Upload unsigned macOS artifact")?.if,
214
+ /MACOS_NOTARIZE != 'true'/,
215
+ );
216
+ assert.match(
217
+ find("Publish desktop update feed")?.if,
218
+ /MACOS_NOTARIZE == 'true'/,
219
+ );
220
+ assert.match(find("Clean up macOS signing")?.if, /always\(\)/);
221
+ const script = readFileSync(
222
+ resolve(import.meta.dirname, "../../.github/scripts/release.sh"),
223
+ "utf8",
224
+ );
225
+ assert.match(script, /for platform in android linux windows macos/);
226
+ });
@@ -0,0 +1,12 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { MakerDMG } from "@electron-forge/maker-dmg";
4
+ import config from "../../apps/desktop/forge.config.mts";
5
+
6
+ test("macOS disk image uses a bounded title without overriding artifact names", async () => {
7
+ const maker = config.makers?.find((item) => item instanceof MakerDMG);
8
+ assert.ok(maker instanceof MakerDMG);
9
+ await maker.prepareConfig("arm64");
10
+ assert.equal(maker.config.title, "Install");
11
+ assert.equal(maker.config.name, undefined);
12
+ });
@@ -9,7 +9,9 @@ test(
9
9
  const response = await fetch(new URL("/", app.baseUrl));
10
10
  expect(response.status).toBe(200);
11
11
  const head = (await response.text()).split("</head>")[0];
12
- expect(head).toContain(`property="og:title" content="${site.title}"`);
12
+ expect(head).toContain(
13
+ `property="og:title" content="${site.title.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")}"`,
14
+ );
13
15
  if (site.origin)
14
16
  expect(head).toContain(`rel="canonical" href="${site.origin}/"`);
15
17
  if (site.image) {
@@ -3,6 +3,11 @@ import assert from "node:assert/strict";
3
3
  import { BillingSession } from "../disposabl-kit/mobile/billing/session";
4
4
  import { pricing } from "../disposabl-kit/payments/config";
5
5
  import { monthlyPlanFromCustomer } from "../disposabl-kit/server/billing";
6
+ import {
7
+ paymentOptions,
8
+ storeEligibility,
9
+ preflightWebMonthly,
10
+ } from "../disposabl-kit/mobile/billing/policy";
6
11
 
7
12
  function deferred() {
8
13
  let resolve!: () => void;
@@ -14,6 +19,148 @@ function deferred() {
14
19
  };
15
20
  }
16
21
 
22
+ test("retained gate and account keep separate leases across focus and in-flight work", async () => {
23
+ const started = deferred();
24
+ const finish = deferred();
25
+ const session = new BillingSession(async () => ({ configure() {} }) as never);
26
+ const gate = session.acquire("alice");
27
+ const purchase = session.run("alice", gate, "key", async () => {
28
+ started.resolve();
29
+ await finish.promise;
30
+ return "result";
31
+ });
32
+ await started.promise;
33
+ const account = session.acquire("alice");
34
+ assert.equal(session.current("alice", gate), true);
35
+ assert.equal(session.current("alice", account), true);
36
+ assert.equal(session.beginTransaction(), true);
37
+ assert.equal(session.beginTransaction(), false);
38
+ session.endTransaction();
39
+ session.release("alice", account);
40
+ assert.equal(session.current("alice", gate), true);
41
+ finish.resolve();
42
+ assert.equal(await purchase, "result");
43
+ const returnedAccount = session.acquire("alice");
44
+ const pending = session.run("alice", returnedAccount, "key", async () => {
45
+ await finish.promise;
46
+ return true;
47
+ });
48
+ session.release("alice", returnedAccount);
49
+ await assert.rejects(pending, /account changed/);
50
+ assert.equal(session.current("alice", gate), true);
51
+ const bob = session.acquire("bob");
52
+ assert.equal(session.current("alice", gate), false);
53
+ session.release("alice", gate);
54
+ assert.equal(session.current("bob", bob), true);
55
+ });
56
+
57
+ test("web monthly preflight rechecks storefront, account, and both subscription sources", async () => {
58
+ let current = true;
59
+ let country = "USA";
60
+ let active: string[] = [];
61
+ const sdk = {
62
+ canMakePayments: async () => true,
63
+ getStorefront: async () => ({ countryCode: country }),
64
+ getCustomerInfo: async () => ({ activeSubscriptions: active }),
65
+ getOfferings: async () => ({
66
+ current: {
67
+ availablePackages: [
68
+ { product: { identifier: "monthly", subscriptionPeriod: "P1M" } },
69
+ ],
70
+ },
71
+ }),
72
+ };
73
+ const snapshot = async () => ({
74
+ balance: 0,
75
+ hasMonthlyPlan: false,
76
+ nativeSubscriptionsEnabled: true,
77
+ monthlyCheckoutPending: false,
78
+ mobileWebCheckoutEnabled: true,
79
+ customerId: "alice",
80
+ });
81
+ const run = () =>
82
+ preflightWebMonthly(
83
+ sdk as never,
84
+ "ios",
85
+ "monthly",
86
+ "alice",
87
+ snapshot,
88
+ () => current,
89
+ );
90
+ await run();
91
+ country = "CAN";
92
+ await assert.rejects(run(), /unavailable/);
93
+ country = "USA";
94
+ active = ["monthly"];
95
+ await assert.rejects(run(), /existing_subscription/);
96
+ active = [];
97
+ current = false;
98
+ await assert.rejects(run(), /Account changed/);
99
+ });
100
+
101
+ test("account switch invalidates all retained views while work is in flight", async () => {
102
+ const started = deferred();
103
+ const finish = deferred();
104
+ const session = new BillingSession(async () => ({ configure() {} }) as never);
105
+ const gate = session.acquire("alice");
106
+ const account = session.acquire("alice");
107
+ const pending = session.run("alice", gate, "key", async () => {
108
+ started.resolve();
109
+ await finish.promise;
110
+ });
111
+ const rejected = assert.rejects(pending, /account changed/);
112
+ await started.promise;
113
+ const bob = session.acquire("bob");
114
+ assert.equal(session.current("alice", account), false);
115
+ finish.resolve();
116
+ await rejected;
117
+ assert.equal(session.current("bob", bob), true);
118
+ });
119
+
120
+ test("storefront policy fails closed and Android never offers web", async () => {
121
+ const base = {
122
+ platform: "ios",
123
+ storefront: "USA",
124
+ paymentsEnabled: true,
125
+ webCheckoutEnabled: true,
126
+ nativeReady: true,
127
+ canMakePayments: true,
128
+ };
129
+ assert.deepEqual(paymentOptions(base), { native: true, web: true });
130
+ for (const change of [
131
+ { storefront: null },
132
+ { storefront: "CAN" },
133
+ { platform: "android" },
134
+ { webCheckoutEnabled: false },
135
+ { nativeReady: false },
136
+ { canMakePayments: false },
137
+ { paymentsEnabled: false },
138
+ ])
139
+ assert.equal(paymentOptions({ ...base, ...change }).web, false);
140
+ assert.deepEqual(
141
+ await storeEligibility(
142
+ {
143
+ canMakePayments: async () => true,
144
+ getStorefront: async () => ({ countryCode: "USA" }),
145
+ } as never,
146
+ "ios",
147
+ ),
148
+ { canMakePayments: true, storefront: "USA" },
149
+ );
150
+ assert.deepEqual(
151
+ await storeEligibility(
152
+ {
153
+ canMakePayments: async () => true,
154
+ getStorefront: async () => {
155
+ throw new Error("unknown");
156
+ },
157
+ } as never,
158
+ "ios",
159
+ ),
160
+ { canMakePayments: true, storefront: null },
161
+ );
162
+ });
163
+
17
164
  test("monthly state includes scheduled plans and fails closed for unknown responses", () => {
18
165
  assert.equal(monthlyPlanFromCustomer({ subscriptions: [] }), false);
19
166
  for (const status of ["active", "scheduled"])
@@ -139,3 +286,273 @@ test("a failed login cannot leave another user's identity trusted", async () =>
139
286
  await session.run("alice", session.select("alice"), "public", async () => {});
140
287
  assert.deepEqual(logins, ["bob", "alice"]);
141
288
  });
289
+
290
+ test("monthly paywall permits only a verified current offering and fresh customer", async () => {
291
+ const { presentMonthlyPaywall, validMonthlyOffering } =
292
+ await import("../disposabl-kit/mobile/billing/paywall");
293
+ const monthly = {
294
+ product: { identifier: "monthly", subscriptionPeriod: "P1M" },
295
+ };
296
+ const topup = { product: { identifier: "topup", subscriptionPeriod: null } };
297
+ assert.equal(validMonthlyOffering([monthly], "monthly"), true);
298
+ assert.equal(validMonthlyOffering([monthly, topup], "monthly"), false);
299
+ assert.equal(validMonthlyOffering([topup], "monthly"), false);
300
+ assert.equal(validMonthlyOffering([], "monthly"), false);
301
+ const snapshot = async () => ({
302
+ balance: 0,
303
+ hasMonthlyPlan: false,
304
+ nativeSubscriptionsEnabled: true,
305
+ monthlyCheckoutPending: false,
306
+ });
307
+ let shown = 0;
308
+ const sdk = {
309
+ canMakePayments: async () => true,
310
+ getCustomerInfo: async () => ({ activeSubscriptions: [] }),
311
+ getOfferings: async () => ({ current: { availablePackages: [monthly] } }),
312
+ };
313
+ const show = async () => {
314
+ shown++;
315
+ return "cancelled" as const;
316
+ };
317
+ assert.equal(
318
+ await presentMonthlyPaywall(
319
+ sdk as never,
320
+ snapshot,
321
+ () => true,
322
+ "monthly",
323
+ show,
324
+ ),
325
+ "cancelled",
326
+ );
327
+ assert.equal(shown, 1);
328
+ for (const monthlyCheckoutPending of [true, undefined]) {
329
+ await assert.rejects(
330
+ presentMonthlyPaywall(
331
+ sdk as never,
332
+ async () =>
333
+ ({ ...(await snapshot()), monthlyCheckoutPending }) as never,
334
+ () => true,
335
+ "monthly",
336
+ show,
337
+ ),
338
+ /website checkout/,
339
+ );
340
+ }
341
+ await assert.rejects(
342
+ presentMonthlyPaywall(
343
+ { ...sdk, canMakePayments: async () => false } as never,
344
+ snapshot,
345
+ () => true,
346
+ "monthly",
347
+ show,
348
+ ),
349
+ /restricted/,
350
+ );
351
+ await assert.rejects(
352
+ presentMonthlyPaywall(
353
+ sdk as never,
354
+ async () => ({ ...(await snapshot()), hasMonthlyPlan: true }),
355
+ () => true,
356
+ "monthly",
357
+ show,
358
+ ),
359
+ /existing_subscription/,
360
+ );
361
+ await assert.rejects(
362
+ presentMonthlyPaywall(sdk as never, snapshot, () => false, "monthly", show),
363
+ /Account changed/,
364
+ );
365
+ await assert.rejects(
366
+ presentMonthlyPaywall(
367
+ {
368
+ ...sdk,
369
+ getOfferings: async () => ({
370
+ current: { availablePackages: [monthly, topup] },
371
+ }),
372
+ } as never,
373
+ snapshot,
374
+ () => true,
375
+ "monthly",
376
+ show,
377
+ ),
378
+ /unavailable/,
379
+ );
380
+ assert.equal(shown, 1);
381
+ });
382
+
383
+ // Consumable top-ups share the session lease but do not depend on monthly checkout.
384
+ test("native top-up fails closed and checks identity at purchase", async () => {
385
+ const { nativeTopupRoutes } =
386
+ await import("../disposabl-kit/server/billing-native-capability");
387
+ const { loadTopup, matchingTopupRoute, purchaseTopup } =
388
+ await import("../disposabl-kit/mobile/billing/topup");
389
+ const env = {
390
+ REVENUECAT_CONSUMABLE_OWNER: "custom",
391
+ REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED: "true",
392
+ REVENUECAT_WEBHOOK_AUTH: "auth",
393
+ REVENUECAT_PROJECT_ID: "project",
394
+ AUTUMN_SECRET_KEY: "key",
395
+ REVENUECAT_ENVIRONMENT: "SANDBOX",
396
+ REVENUECAT_ROUTES: JSON.stringify([
397
+ { app: "apple", store: "APP_STORE", product: "coins" },
398
+ ]),
399
+ };
400
+ assert.deepEqual(nativeTopupRoutes(false, env), []);
401
+ for (const change of [
402
+ { REVENUECAT_CONSUMABLE_OWNER: "managed" },
403
+ { REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED: "false" },
404
+ { REVENUECAT_ROUTES: "[]" },
405
+ { REVENUECAT_WEBHOOK_AUTH: "" },
406
+ ])
407
+ assert.deepEqual(nativeTopupRoutes(true, { ...env, ...change }), []);
408
+ const snapshot = {
409
+ customerId: "user",
410
+ nativeTopupRoutes: nativeTopupRoutes(true, env),
411
+ };
412
+ assert.equal(matchingTopupRoute(snapshot, "ios", "apple", "coins"), true);
413
+ assert.equal(
414
+ matchingTopupRoute(snapshot, "android", "apple", "coins"),
415
+ false,
416
+ );
417
+ const product = {
418
+ identifier: "coins",
419
+ productCategory: "NON_SUBSCRIPTION",
420
+ productType: "CONSUMABLE",
421
+ priceString: "$5.00",
422
+ };
423
+ let purchases = 0;
424
+ const sdk = {
425
+ PRODUCT_CATEGORY: { NON_SUBSCRIPTION: "NON_SUBSCRIPTION" },
426
+ getProducts: async () => [product],
427
+ getAppUserID: async () => "user",
428
+ canMakePayments: async () => true,
429
+ purchaseStoreProduct: async () => {
430
+ purchases++;
431
+ },
432
+ };
433
+ for (const bad of [
434
+ { ...product, identifier: "other" },
435
+ { ...product, productCategory: "SUBSCRIPTION" },
436
+ { ...product, productType: "UNKNOWN" },
437
+ ])
438
+ assert.equal(
439
+ await loadTopup(
440
+ { ...sdk, getProducts: async () => [bad] } as never,
441
+ "ios",
442
+ "coins",
443
+ ),
444
+ null,
445
+ );
446
+ assert.ok(
447
+ await loadTopup(
448
+ {
449
+ ...sdk,
450
+ getProducts: async () => [{ ...product, productType: "UNKNOWN" }],
451
+ } as never,
452
+ "android",
453
+ "coins",
454
+ ),
455
+ );
456
+ const run = (overrides = {}, state = snapshot, current = () => true) =>
457
+ purchaseTopup(
458
+ { ...sdk, ...overrides } as never,
459
+ async () => state,
460
+ current,
461
+ "user",
462
+ "ios",
463
+ "apple",
464
+ "coins",
465
+ );
466
+ await assert.rejects(run({ getAppUserID: async () => "other" }));
467
+ await assert.rejects(run({ canMakePayments: async () => false }));
468
+ await assert.rejects(run({}, { ...snapshot, nativeTopupRoutes: [] }));
469
+ await assert.rejects(run({}, snapshot, () => false));
470
+ let current = true;
471
+ await assert.rejects(
472
+ run(
473
+ {
474
+ getProducts: async () => {
475
+ current = false;
476
+ return [product];
477
+ },
478
+ },
479
+ snapshot,
480
+ () => current,
481
+ ),
482
+ );
483
+ assert.equal(purchases, 0);
484
+ await run();
485
+ assert.equal(purchases, 1);
486
+ });
487
+
488
+ test("web top-up preflight rechecks storefront, product, route and account independently of monthly plan", async () => {
489
+ const { preflightWebTopup } =
490
+ await import("../disposabl-kit/mobile/billing/policy");
491
+ const product = {
492
+ identifier: "coins",
493
+ productCategory: "NON_SUBSCRIPTION",
494
+ productType: "CONSUMABLE",
495
+ priceString: "$5",
496
+ };
497
+ const sdk = {
498
+ canMakePayments: async () => true,
499
+ getStorefront: async () => ({ countryCode: "USA" }),
500
+ getAppUserID: async () => "user",
501
+ getProducts: async () => [product],
502
+ PRODUCT_CATEGORY: { NON_SUBSCRIPTION: "NON_SUBSCRIPTION" },
503
+ };
504
+ const state = {
505
+ customerId: "user",
506
+ mobileWebCheckoutEnabled: true,
507
+ nativeTopupRoutes: [{ app: "apple", store: "APP_STORE", product: "coins" }],
508
+ hasMonthlyPlan: true,
509
+ monthlyCheckoutPending: true,
510
+ };
511
+ const run = (
512
+ changes = {},
513
+ snapshot = state,
514
+ platform = "ios",
515
+ current = () => true,
516
+ ) =>
517
+ preflightWebTopup(
518
+ { ...sdk, ...changes } as never,
519
+ platform,
520
+ "apple",
521
+ "coins",
522
+ "user",
523
+ async () => snapshot,
524
+ current,
525
+ );
526
+ await run();
527
+ for (const changes of [
528
+ { canMakePayments: async () => false },
529
+ { getStorefront: async () => null },
530
+ { getStorefront: async () => ({ countryCode: "CAN" }) },
531
+ {
532
+ getStorefront: async () => {
533
+ throw Error();
534
+ },
535
+ },
536
+ { getAppUserID: async () => "other" },
537
+ { getProducts: async () => [{ ...product, productType: "UNKNOWN" }] },
538
+ ])
539
+ await assert.rejects(run(changes));
540
+ await assert.rejects(run({}, { ...state, nativeTopupRoutes: [] }));
541
+ await assert.rejects(run({}, { ...state, customerId: "other" }));
542
+ await assert.rejects(run({}, { ...state, mobileWebCheckoutEnabled: false }));
543
+ await assert.rejects(run({}, state, "android"));
544
+ let current = true;
545
+ await assert.rejects(
546
+ run(
547
+ {
548
+ getProducts: async () => {
549
+ current = false;
550
+ return [product];
551
+ },
552
+ },
553
+ state,
554
+ "ios",
555
+ () => current,
556
+ ),
557
+ );
558
+ });