create-disposabl-app 0.15.0 → 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.
- package/README.md +15 -1
- package/dist/disposabl.js +357 -50
- package/dist/index.js +8973 -154
- package/dist/templates/default/apps/desktop/forge.config.mts +2 -1
- package/dist/templates/default/apps/docs/content/getting-started.mdx +1 -1
- package/dist/templates/default/apps/mobile/package.json +1 -0
- package/dist/templates/default/apps/web/eslint.config.ts +5 -1
- package/dist/templates/default/apps/web/public/disposabl-logo-light.svg +8 -0
- package/dist/templates/default/apps/web/public/landing/coast.jpg +0 -0
- package/dist/templates/default/apps/web/public/landing/community.jpg +0 -0
- package/dist/templates/default/apps/web/public/landing/stores/app-store.svg +46 -0
- package/dist/templates/default/apps/web/public/landing/stores/google-play.png +0 -0
- package/dist/templates/default/apps/web/public/landing/taste/LICENSE +21 -0
- package/dist/templates/default/apps/web/public/landing/taste/init.js +3 -0
- package/dist/templates/default/apps/web/public/landing/taste/moments/lib.js +189 -0
- package/dist/templates/default/apps/web/public/landing/taste/moments/moments.js +109 -0
- package/dist/templates/default/apps/web/public/landing/taste/moments/word-highlight/moment.css +8 -0
- package/dist/templates/default/apps/web/public/landing/taste/moments/word-highlight/moment.js +35 -0
- package/dist/templates/default/apps/web/public/landing/taste/motion/motion.css +321 -0
- package/dist/templates/default/apps/web/public/landing/taste/motion/motion.js +406 -0
- package/dist/templates/default/apps/web/routes.config.ts +14 -0
- package/dist/templates/default/apps/web/src/router/__root.tsx +8 -2
- package/dist/templates/default/apps/web/tsr.config.json +1 -1
- package/dist/templates/default/apps/web/vite.config.ts +10 -2
- package/dist/templates/default/bun.lock +6 -0
- package/dist/templates/default/bunfig.toml +1 -0
- package/dist/templates/default/disposabl.json +1 -1
- package/dist/templates/default/packages/backend/convex/authSetup.ts +2 -5
- package/dist/templates/default/packages/backend/convex/billing.ts +5 -0
- package/dist/templates/default/packages/backend/convex/billingHandoff.ts +6 -0
- package/dist/templates/default/packages/backend/convex/convex.config.ts +8 -0
- package/dist/templates/default/packages/backend/convex/http.ts +6 -0
- package/dist/templates/default/packages/backend/convex/revenuecat.ts +13 -0
- package/dist/templates/default/packages/backend/convex/schema.ts +44 -0
- package/dist/templates/default/packages/backend/convex/telemetry.ts +41 -5
- package/dist/templates/default/packages/backend/generate.ts +6 -0
- package/dist/templates/default/packages/cli/auth.ts +36 -3
- package/dist/templates/default/packages/cli/build.ts +6 -0
- package/dist/templates/default/packages/cli/client.ts +189 -19
- package/dist/templates/default/packages/cli/errors.ts +18 -0
- package/dist/templates/default/packages/cli/telemetry-build.ts +27 -0
- package/dist/templates/default/packages/cli/telemetry.ts +266 -0
- package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +23 -5
- package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry.ts +24 -2
- package/dist/templates/default/packages/disposabl-kit/client/lib/theme.ts +1 -0
- package/dist/templates/default/packages/disposabl-kit/client/routes/billing-login.tsx +92 -0
- package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +113 -43
- package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +13 -5
- package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +3 -2
- package/dist/templates/default/packages/disposabl-kit/lib/telemetry.ts +148 -12
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +143 -40
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/paywall.ts +83 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/policy.ts +125 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/session.ts +31 -3
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/topup.ts +99 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/use-topup.ts +116 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +190 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +9 -2
- package/dist/templates/default/packages/disposabl-kit/package.json +10 -1
- package/dist/templates/default/packages/disposabl-kit/payments/checkout-attempt.ts +64 -0
- package/dist/templates/default/packages/disposabl-kit/payments/config.ts +16 -3
- package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +218 -9
- package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +126 -0
- package/dist/templates/default/packages/disposabl-kit/server/billing-native-capability.ts +12 -0
- package/dist/templates/default/packages/disposabl-kit/server/billing-setup.ts +2 -0
- package/dist/templates/default/packages/disposabl-kit/server/billing.ts +31 -0
- package/dist/templates/default/packages/disposabl-kit/server/browser-session.ts +27 -0
- package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +173 -59
- package/dist/templates/default/packages/disposabl-kit/server/revenuecat-contract.ts +233 -0
- package/dist/templates/default/packages/disposabl-kit/server/revenuecat-functions.ts +554 -0
- package/dist/templates/default/packages/disposabl-kit/server/revenuecat-validator.ts +76 -0
- package/dist/templates/default/packages/reconfigure-skill/SKILL.md +36 -0
- package/dist/templates/default/packages/sdk/README.md +21 -0
- package/dist/templates/default/packages/sdk/src/analytics.ts +102 -0
- package/dist/templates/default/packages/sdk/src/index.ts +2 -0
- package/dist/templates/default/packages/skill/SKILL.md +2 -0
- package/dist/templates/default/packages/skill/references/agent.md +2 -0
- package/dist/templates/default/packages/tests/billing-attempts.test.ts +156 -0
- package/dist/templates/default/packages/tests/billing-handoff.test.ts +116 -0
- package/dist/templates/default/packages/tests/billing-setup.test.ts +4 -3
- package/dist/templates/default/packages/tests/billing.test.ts +48 -4
- package/dist/templates/default/packages/tests/desktop-packaging.test.ts +12 -0
- package/dist/templates/default/packages/tests/flows/seo.e2e.ts +3 -1
- package/dist/templates/default/packages/tests/native-billing.test.ts +417 -0
- package/dist/templates/default/packages/tests/page-telemetry.test.ts +218 -0
- package/dist/templates/default/packages/tests/revenuecat-inbox.test.ts +476 -0
- package/dist/templates/default/packages/tests/sdk-analytics.test.ts +158 -0
- package/dist/templates/default/packages/tests/telemetry.test.ts +272 -55
- package/package.json +1 -1
- package/dist/templates/default/apps/web/src/routeTree.gen.ts +0 -578
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { lock } from "proper-lockfile";
|
|
7
|
+
import { credentialRevision } from "./auth";
|
|
8
|
+
|
|
9
|
+
type State = {
|
|
10
|
+
anonymousId: string;
|
|
11
|
+
credentialRevision: string;
|
|
12
|
+
userId?: string;
|
|
13
|
+
loginAttempt?: string;
|
|
14
|
+
};
|
|
15
|
+
type Product = "cli" | "generator";
|
|
16
|
+
type Outcome = "started" | "success" | "failure" | "cancelled";
|
|
17
|
+
|
|
18
|
+
// The public project token must be provided by the release configuration. Never
|
|
19
|
+
// use the generated app's PostHog project or a personal API key here.
|
|
20
|
+
export function installedRelease(
|
|
21
|
+
version: string,
|
|
22
|
+
entry = process.argv[1] ?? "",
|
|
23
|
+
) {
|
|
24
|
+
try {
|
|
25
|
+
entry = realpathSync(entry);
|
|
26
|
+
} catch {
|
|
27
|
+
// The production binary can be replaced while it is running.
|
|
28
|
+
}
|
|
29
|
+
return (
|
|
30
|
+
/(?:^|[\\/])node_modules[\\/]/.test(entry) &&
|
|
31
|
+
/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version) &&
|
|
32
|
+
!version.includes("development")
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function telemetryConfig(
|
|
37
|
+
version: string,
|
|
38
|
+
entry = process.argv[1] ?? "",
|
|
39
|
+
) {
|
|
40
|
+
const env = process.env;
|
|
41
|
+
const host = process.env.DISPOSABL_CLI_POSTHOG_HOST;
|
|
42
|
+
const token = process.env.DISPOSABL_CLI_POSTHOG_PROJECT_TOKEN;
|
|
43
|
+
if (
|
|
44
|
+
!installedRelease(version, entry) ||
|
|
45
|
+
env.NODE_ENV === "test" ||
|
|
46
|
+
env.NODE_ENV === "development" ||
|
|
47
|
+
env.BUN_ENV === "test" ||
|
|
48
|
+
env.CI ||
|
|
49
|
+
env.E2E_TELEMETRY_DISABLED ||
|
|
50
|
+
["1", "true"].includes(env.DO_NOT_TRACK?.toLowerCase() ?? "") ||
|
|
51
|
+
env.DISPOSABL_TELEMETRY_DISABLED === "1" ||
|
|
52
|
+
env.DISPOSABL_API_KEY ||
|
|
53
|
+
(env.DISPOSABL_API_ORIGIN &&
|
|
54
|
+
env.DISPOSABL_API_ORIGIN !== "https://www.disposabl.dev") ||
|
|
55
|
+
!token?.startsWith("phc_") ||
|
|
56
|
+
!["https://us.i.posthog.com", "https://eu.i.posthog.com"].includes(
|
|
57
|
+
host ?? "",
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
return null;
|
|
61
|
+
return { token, host: host! };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const directory = () => join(homedir(), ".config", "disposabl");
|
|
65
|
+
export const telemetryStatePath = () => join(directory(), "telemetry.json");
|
|
66
|
+
async function state(path: string): Promise<State> {
|
|
67
|
+
const revision = await credentialRevision();
|
|
68
|
+
try {
|
|
69
|
+
const value = JSON.parse(await readFile(path, "utf8")) as State;
|
|
70
|
+
if (
|
|
71
|
+
/^[0-9a-f-]{36}$/.test(value.anonymousId) &&
|
|
72
|
+
(!value.userId || /^[a-zA-Z0-9_-]{1,128}$/.test(value.userId)) &&
|
|
73
|
+
value.credentialRevision === revision
|
|
74
|
+
)
|
|
75
|
+
return value;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (
|
|
78
|
+
!(error instanceof SyntaxError) &&
|
|
79
|
+
(error as NodeJS.ErrnoException).code !== "ENOENT"
|
|
80
|
+
)
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
await mkdir(join(path, ".."), { recursive: true, mode: 0o700 });
|
|
84
|
+
const fresh = {
|
|
85
|
+
anonymousId: randomUUID(),
|
|
86
|
+
credentialRevision: revision,
|
|
87
|
+
};
|
|
88
|
+
// Every caller holds the telemetry lock. Never migrate an old account binding.
|
|
89
|
+
await writeFile(path, JSON.stringify(fresh), { mode: 0o600 });
|
|
90
|
+
return fresh;
|
|
91
|
+
}
|
|
92
|
+
async function synchronized<T>(
|
|
93
|
+
path: string,
|
|
94
|
+
run: () => Promise<T>,
|
|
95
|
+
): Promise<T> {
|
|
96
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
97
|
+
const release = await lock(path, {
|
|
98
|
+
realpath: false,
|
|
99
|
+
stale: 5000,
|
|
100
|
+
retries: { retries: 20, minTimeout: 50, maxTimeout: 50 },
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
return await run();
|
|
104
|
+
} finally {
|
|
105
|
+
await release();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function send(
|
|
109
|
+
config: NonNullable<ReturnType<typeof telemetryConfig>>,
|
|
110
|
+
event: string,
|
|
111
|
+
distinctId: string,
|
|
112
|
+
properties: Record<string, unknown>,
|
|
113
|
+
) {
|
|
114
|
+
const response = await fetch(`${config.host}/i/v0/e/`, {
|
|
115
|
+
method: "POST",
|
|
116
|
+
redirect: "error",
|
|
117
|
+
signal: AbortSignal.timeout(500),
|
|
118
|
+
headers: { "Content-Type": "application/json" },
|
|
119
|
+
body: JSON.stringify({
|
|
120
|
+
api_key: config.token,
|
|
121
|
+
event,
|
|
122
|
+
distinct_id: distinctId,
|
|
123
|
+
properties: { ...properties, $geoip_disable: true, $ip: "0.0.0.0" },
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
return response.ok;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function capture(
|
|
130
|
+
version: string,
|
|
131
|
+
product: Product,
|
|
132
|
+
command: string,
|
|
133
|
+
outcome: Outcome,
|
|
134
|
+
path: string,
|
|
135
|
+
) {
|
|
136
|
+
const config = telemetryConfig(version);
|
|
137
|
+
if (!config) return;
|
|
138
|
+
try {
|
|
139
|
+
const current = await synchronized(path, () => state(path));
|
|
140
|
+
// A failed rotation must not preserve a prior account after credentials change.
|
|
141
|
+
if (current.credentialRevision !== (await credentialRevision())) return;
|
|
142
|
+
const allowed = [
|
|
143
|
+
"agent",
|
|
144
|
+
"login",
|
|
145
|
+
"logout",
|
|
146
|
+
"apps",
|
|
147
|
+
"previews",
|
|
148
|
+
"connections",
|
|
149
|
+
"users",
|
|
150
|
+
"help",
|
|
151
|
+
"version",
|
|
152
|
+
"other",
|
|
153
|
+
"create",
|
|
154
|
+
];
|
|
155
|
+
await send(config, "cli_command", current.userId ?? current.anonymousId, {
|
|
156
|
+
product,
|
|
157
|
+
command: allowed.includes(command) ? command : "other",
|
|
158
|
+
outcome,
|
|
159
|
+
version,
|
|
160
|
+
invocation:
|
|
161
|
+
process.env.npm_command === "exec"
|
|
162
|
+
? "npx"
|
|
163
|
+
: (/^(npm|pnpm|yarn|bun)\//.exec(
|
|
164
|
+
process.env.npm_config_user_agent ?? "",
|
|
165
|
+
)?.[1] ?? "direct"),
|
|
166
|
+
platform: ["darwin", "linux", "win32"].includes(process.platform)
|
|
167
|
+
? process.platform
|
|
168
|
+
: "other",
|
|
169
|
+
...(!current.userId ? { $process_person_profile: false } : {}),
|
|
170
|
+
});
|
|
171
|
+
} catch {
|
|
172
|
+
/* analytics must not affect the command */
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// A new attempt invalidates any earlier in-flight login. A linked identity
|
|
177
|
+
// gets a new anonymous ID before another account can use it.
|
|
178
|
+
export async function prepareLogin(path: string): Promise<string | undefined> {
|
|
179
|
+
try {
|
|
180
|
+
return await synchronized(path, async () => {
|
|
181
|
+
const current = await state(path);
|
|
182
|
+
const loginAttempt = randomUUID();
|
|
183
|
+
const next = {
|
|
184
|
+
anonymousId:
|
|
185
|
+
current.userId ||
|
|
186
|
+
current.loginAttempt ||
|
|
187
|
+
current.credentialRevision !==
|
|
188
|
+
createHash("sha256").update("anonymous").digest("hex")
|
|
189
|
+
? randomUUID()
|
|
190
|
+
: current.anonymousId,
|
|
191
|
+
loginAttempt,
|
|
192
|
+
credentialRevision: await credentialRevision(),
|
|
193
|
+
};
|
|
194
|
+
await writeFile(path, JSON.stringify(next), { mode: 0o600 });
|
|
195
|
+
return loginAttempt;
|
|
196
|
+
});
|
|
197
|
+
} catch {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export async function identify(
|
|
203
|
+
version: string,
|
|
204
|
+
userId: unknown,
|
|
205
|
+
path: string,
|
|
206
|
+
attempt: string | undefined,
|
|
207
|
+
revision: string | undefined = undefined,
|
|
208
|
+
) {
|
|
209
|
+
const config = telemetryConfig(version);
|
|
210
|
+
if (
|
|
211
|
+
!config ||
|
|
212
|
+
!attempt ||
|
|
213
|
+
typeof userId !== "string" ||
|
|
214
|
+
!/^[a-zA-Z0-9_-]{1,128}$/.test(userId)
|
|
215
|
+
)
|
|
216
|
+
return;
|
|
217
|
+
try {
|
|
218
|
+
// Direct callers also bind to a snapshot taken before waiting for the lock.
|
|
219
|
+
const expectedRevision = revision ?? (await credentialRevision());
|
|
220
|
+
await synchronized(path, async () => {
|
|
221
|
+
// Do not recreate state after logout or a later login.
|
|
222
|
+
const current = JSON.parse(await readFile(path, "utf8")) as State;
|
|
223
|
+
if (
|
|
224
|
+
current.loginAttempt !== attempt ||
|
|
225
|
+
expectedRevision !== (await credentialRevision()) ||
|
|
226
|
+
current.userId ||
|
|
227
|
+
!/^[0-9a-f-]{36}$/.test(current.anonymousId)
|
|
228
|
+
)
|
|
229
|
+
return;
|
|
230
|
+
const opaqueId = createHash("sha256")
|
|
231
|
+
.update(`disposabl:${config.token}:${userId}`)
|
|
232
|
+
.digest("hex");
|
|
233
|
+
if (
|
|
234
|
+
await send(config, "$identify", opaqueId, {
|
|
235
|
+
$anon_distinct_id: current.anonymousId,
|
|
236
|
+
})
|
|
237
|
+
) {
|
|
238
|
+
await writeFile(
|
|
239
|
+
path,
|
|
240
|
+
JSON.stringify({
|
|
241
|
+
anonymousId: current.anonymousId,
|
|
242
|
+
userId: opaqueId,
|
|
243
|
+
credentialRevision: expectedRevision,
|
|
244
|
+
}),
|
|
245
|
+
{ mode: 0o600 },
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
} catch {
|
|
250
|
+
/* analytics must not affect login */
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export async function resetIdentity(path: string, attempt?: string) {
|
|
255
|
+
try {
|
|
256
|
+
await synchronized(path, async () => {
|
|
257
|
+
if (attempt) {
|
|
258
|
+
const current = JSON.parse(await readFile(path, "utf8")) as State;
|
|
259
|
+
if (current.loginAttempt !== attempt) return;
|
|
260
|
+
}
|
|
261
|
+
await rm(path, { force: true });
|
|
262
|
+
});
|
|
263
|
+
} catch {
|
|
264
|
+
/* analytics must not affect authentication */
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Payments setup
|
|
2
2
|
|
|
3
|
+
US iOS website checkout requires a verified monthly store offering, RevenueCat sync, an HTTPS `BILLING_RETURN_URL` ending in `/pricing`, and backend `MOBILE_WEB_CHECKOUT_ENABLED=true`. The app rechecks the StoreKit storefront and payment restrictions before opening a full browser. The browser confirms the account and the customer separately chooses the monthly purchase. Other storefronts and Android retain store purchasing. After checkout, return to the app and refresh; only the Autumn balance is credited. US iOS top-ups require a matching verified native consumable route and product; the app rechecks these before opening the browser.
|
|
4
|
+
|
|
5
|
+
The checkout attempt is recorded before the provider call. A lost or unfamiliar response stays unresolved and blocks another attempt for that customer and purchase type. The operator must check the corresponding Autumn and payment-provider records before invoking the internal `billing:resolveAttempt` with that customer, request ID, resolution outcome and provider evidence. A known checkout URL is retained against its request ID so a lost action response does not start another provider request. Provider URLs may be sensitive and should be protected as billing data.
|
|
6
|
+
|
|
7
|
+
App Review notes, 2026-11-08: the US StoreKit storefront sees equally styled monthly store and website options, the website option opens the external browser after a tap, and other storefronts retain IAP. Provide reviewers with configured test accounts and recheck current review rules before submission. This is source behavior, not evidence of a sandbox purchase, device verification, or App Review acceptance.
|
|
8
|
+
|
|
3
9
|
Payments is optional and includes authentication. Select `payments` in `disposabl.json`; the server checks this selection before reading credentials or calling Autumn. With it off, the pricing page blocks purchases and no billing credentials are needed. The authenticated Convex Auth user ID is the Autumn customer ID. Never use a client-supplied customer ID or price.
|
|
4
10
|
|
|
5
11
|
Before first setup, the **Autumn organization's default currency must match `pricing.currency`** in `payments/config.ts`, USD in the starter. Base price amounts use that organization currency; the create-plan request does not select a currency. Setup neither changes nor verifies the organization currency. Autumn `accounts.get` describes a customer group, not the organization, and cannot verify this prerequisite. Check the organization settings and both prices in Autumn before accepting purchases.
|
|
@@ -8,7 +14,7 @@ Configure `AUTUMN_SECRET_KEY` and `BILLING_RETURN_URL` on this app's Convex depl
|
|
|
8
14
|
|
|
9
15
|
## Catalog initialization
|
|
10
16
|
|
|
11
|
-
`payments/config.ts` is the editable source for plan IDs, prices, credits and currency. The default catalog has a consumable `credits` feature, a $5 monthly plan with
|
|
17
|
+
`payments/config.ts` is the editable source for plan IDs, prices, credits and currency. The default catalog has a consumable `credits` feature, a $5 monthly plan with 750 included credits resetting each month, and a $5 prepaid top-up with `billing_units: 500` and `interval: "one_off"`. The monthly multiplier changes the monthly allowance without changing top-ups. Top-ups have no reset or expiry configuration. Web checkout sends exactly that credit quantity. The web pricing page, mobile allowance text and optional Autumn configuration example use the same source.
|
|
12
18
|
|
|
13
19
|
The internal Convex action `billing:setup` takes `{}` and returns `{ enabled, created, preserved }`. It is re-exported by both the app backend and starter backend. With payments disabled, it returns before reading credentials or calling Autumn. When enabled without `AUTUMN_SECRET_KEY`, it fails with a setup message identifying the missing deployment credential. Customer checkout never initializes the catalog.
|
|
14
20
|
|
|
@@ -30,15 +36,27 @@ The app calls Autumn API 2.6.0 `customers.get_or_create`, `billing.attach`, and
|
|
|
30
36
|
|
|
31
37
|
Generated apps include RevenueCat and the native billing example only when payments is selected. Reconfiguring payments adds or removes that SDK and its unchanged example files; unrelated dependencies are preserved. Customized billing files must be reconciled before disabling payments. Run installation after reconfiguration and build a new native binary when the SDK selection changes.
|
|
32
38
|
|
|
33
|
-
The account screen
|
|
39
|
+
The account screen presents a RevenueCat paywall for the configured monthly subscription and supports restore. Its current offering must contain exactly that one monthly product; mixed or unverified products are unavailable. Use Autumn's managed RevenueCat integration as the sole sync path, with the same authenticated user ID as RevenueCat `appUserID` and Autumn `customer_id`. Request beta access, connect a RevenueCat project and V2 read-only key in Autumn, map store-level subscription products to `credits_monthly`, and configure separate test and live webhooks using Autumn's provided URL and authorization. Block duplicate web/native subscriptions based on the provider customer state. Mobile purchases use RevenueCat, never Autumn attach. Await Autumn webhook synchronization before treating the Autumn balance as available.
|
|
34
40
|
|
|
35
|
-
Set public build-time variables `EXPO_PUBLIC_REVENUECAT_IOS_API_KEY` and `EXPO_PUBLIC_REVENUECAT_ANDROID_API_KEY`, plus `EXPO_PUBLIC_REVENUECAT_IOS_MONTHLY_PRODUCT` and `EXPO_PUBLIC_REVENUECAT_ANDROID_MONTHLY_PRODUCT` to the exact store product identifiers. Configure each
|
|
41
|
+
Set public build-time variables `EXPO_PUBLIC_REVENUECAT_IOS_API_KEY` and `EXPO_PUBLIC_REVENUECAT_ANDROID_API_KEY`, plus `EXPO_PUBLIC_REVENUECAT_IOS_MONTHLY_PRODUCT` and `EXPO_PUBLIC_REVENUECAT_ANDROID_MONTHLY_PRODUCT` to the exact store product identifiers. Configure each monthly product to match `pricing.monthly.price` in `payments/config.ts`, with no unverified offers, and map it to the Autumn monthly plan whose included credits come from `creditQuantity("monthly")`. The defaults are $5 and 750 credits per cycle. The app displays the store's localized price. Build a new native binary after adding the SDK; Expo Go is insufficient. Android uses `singleTop` when payments is selected so external bank verification can return to the purchase.
|
|
36
42
|
|
|
37
43
|
Only set backend `REVENUECAT_SYNC_ENABLED=true` after configuring and verifying the matching Autumn environment's managed integration. Without it, the app still reads shared credits but does not offer native purchases. Payments disabled means no billing component or SDK initialization. The SDK uses custom user IDs only and serializes account switching with purchase operations. Sign-out clears UI ownership without creating a RevenueCat anonymous ID. Configure RevenueCat restore behavior deliberately so a restore does not transfer another account's purchases unexpectedly.
|
|
38
44
|
|
|
39
|
-
Web checkout and native purchasing reject an existing or scheduled monthly plan, and native purchasing also checks RevenueCat's active subscriptions. Unknown provider state blocks a new subscription.
|
|
45
|
+
Web checkout and native purchasing reject an existing or scheduled monthly plan, and native purchasing also checks RevenueCat's active subscriptions. Unknown provider state blocks a new subscription. Web monthly checkout reuses its single outstanding URL across tabs, devices and request IDs. Creating a URL does not release that guard. A pending monthly attempt also blocks the native subscription preflight, including when its provider outcome is unknown. After an operator resolves an attempt, the browser may discard that request ID and start a new checkout only on a new explicit purchase action. Unknown outcomes retain the same ID. An internal operator must verify the checkout completed, expired or was cancelled and record evidence through `billing:resolveAttempt` before allowing a replacement. This deliberately remains manual until provider checkout lifecycle reconciliation is verified. An unpaid but still payable link is not safe to release. These checks do not constitute a distributed transaction across concurrent web and store checkouts. Credits always come from Autumn; a store receipt is shown as awaiting synchronization, never added locally.
|
|
46
|
+
|
|
47
|
+
Native consumable top-ups use a separately fetched store product and the opt-in custom RevenueCat inbox; this is not provider or release proof. The native button remains disabled until the backend route and the public app and product IDs match and the operator explicitly verifies the integration. Its ownership must be exclusive: keep this top-up product out of Autumn's managed RevenueCat mapping, while managed subscriptions remain separate. Never enable custom grants for a product already granted by a managed integration. The inbox accepts an explicit allowlist of store apps and products within one RevenueCat project and environment.
|
|
48
|
+
|
|
49
|
+
With payments selected, custom processing is disabled unless `REVENUECAT_CONSUMABLE_OWNER=custom`, `REVENUECAT_WEBHOOK_AUTH`, `REVENUECAT_PROJECT_ID`, `REVENUECAT_ENVIRONMENT` (`SANDBOX` or `PRODUCTION`), `REVENUECAT_ROUTES`, and `AUTUMN_SECRET_KEY` are present. `REVENUECAT_ROUTES` is a JSON array such as `[{"app":"apple-app-id","store":"APP_STORE","product":"apple-topup"},{"app":"google-app-id","store":"PLAY_STORE","product":"google-topup"}]`. Each app ID must be unique. Invalid or ambiguous configuration disables the inbox. Configure a distinct authorization for each project and environment, sent as the complete Authorization header to `/revenuecat/webhook`. RevenueCat payloads do not normally include a project ID: the project association depends on that credential; authenticated app ID, store, environment and product select the allowlisted route. Transfer events without an environment are rejected for review. Use separate test and live deployments and secrets. Payments-off never processes a webhook or makes an Autumn request.
|
|
50
|
+
|
|
51
|
+
After completing the verification below, an operator may explicitly set `REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED=true` on the matching backend. Set `EXPO_PUBLIC_REVENUECAT_IOS_APP_ID`, `EXPO_PUBLIC_REVENUECAT_ANDROID_APP_ID`, `EXPO_PUBLIC_REVENUECAT_IOS_TOPUP_PRODUCT`, and `EXPO_PUBLIC_REVENUECAT_ANDROID_TOPUP_PRODUCT` to the exact route values for each build. The SDK fetches the localized store price and verifies the product identifier and non-subscription category. On iOS it requires StoreKit 2 to identify the product as consumable; StoreKit 1 cannot prove this. On Android the SDK may report an unknown specific product type, so the operator must independently verify its consumable configuration. Do not enable based on category alone. The monthly RevenueCat offering remains separate and contains only the monthly product.
|
|
52
|
+
|
|
53
|
+
The authenticated webhook checks app, environment, store, product, transaction and a known local user, then durably records delivery and transaction ownership. A stable balance ID excludes the customer, so an account switch cannot create a second grant. A scheduled worker atomically changes `queued` to `grant_unknown` before calling Autumn 2.6 `balances.create` with the configured top-up credit quantity. Only an explicit `{success:true}` response records a grant. A timeout, malformed response, provider error, or worker crash leaves `grant_unknown`: duplicate deliveries and action retries cannot issue another create. A separate paid transaction can proceed independently. The HTTP 202 response means accepted for processing, never credited.
|
|
54
|
+
|
|
55
|
+
A cancellation before dispatch creates a local tombstone; a later purchase cannot grant. Cancellation during a write is held until the result is known. After a grant, cancellation enters `refund_review` because the webhook alone does not prove the refund is full. An operator must establish the scope and spent-credit policy from provider records before calling private `revenuecat:confirmFullRefund` with a nonsecret evidence reference. It targets only that balance ID via `balances.update` with `remaining: 0`. An uncertain update is held as `refund_unknown`. Transfers and refund reversals require review; transfer notifications are stored separately and place affected customers on hold across both apps in the same project and environment. A transfer arriving after dispatch cannot cancel an in-flight provider request. There is no automatic hold release until transfer reconciliation is defined, and incomplete event identities are rejected. No automatic restore, replay of an uncertain operation, or missed-webhook reconciliation is implied.
|
|
56
|
+
|
|
57
|
+
Operators can inspect private `revenuecat:inspect` by state and `revenuecat:inspectTransfers` and `revenuecat:inspectConflicts`. `revenuecat:confirmUnknown` records a provider-confirmed grant or refund with a nonsecret evidence reference, without issuing another write. An aggregate customer balance alone is not proof of an individual operation. There is no automatic reissue of a failed or uncertain dispatch. A queued operation whose worker never started or found configuration missing needs an operator-run `revenuecat:dispatch` after confirming the same deployment and exact route configuration; unknown states cannot be claimed by that action.
|
|
40
58
|
|
|
41
|
-
Autumn
|
|
59
|
+
Autumn documents a caller-supplied `balance_id`, not its atomic uniqueness and retry semantics. This code does not claim exactly-once behavior across providers. Before enabling or offering the consumable, verify stable ID behavior and balance targeting, event ownership, concurrent delivery, response loss, crashes, refunds and partial refunds in isolated Apple and Google sandboxes; establish a documented provider reconciliation contract and a missed-webhook process. A successful local test or a callback does not prove a purchase or provider write. Native product IDs, pricing, RevenueCat offerings and both stores still need verification; do not set the verification flag until those checks pass. A store purchase remains pending until the authoritative Autumn balance updates; the app never grants credits locally.
|
|
42
60
|
|
|
43
61
|
## Platform connection and starter packaging
|
|
44
62
|
|
|
@@ -2,7 +2,29 @@ import { useEffect, useRef } from "react";
|
|
|
2
2
|
import { sessionId } from "../../lib/auth-session";
|
|
3
3
|
import { analyticsEnabled } from "../../features";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { createPageTelemetry } from "../../lib/telemetry";
|
|
6
|
+
|
|
7
|
+
// A shared ID is safe only when its entire read/send/write transition is locked.
|
|
8
|
+
// Without Web Locks, use a document-local identity rather than share stale state.
|
|
9
|
+
let memory: string | null = null;
|
|
10
|
+
const locks = typeof navigator === "undefined" ? undefined : navigator.locks;
|
|
11
|
+
const telemetry = createPageTelemetry(
|
|
12
|
+
locks
|
|
13
|
+
? {
|
|
14
|
+
getItem: (key) => localStorage.getItem(key),
|
|
15
|
+
setItem: (key, value) => localStorage.setItem(key, value),
|
|
16
|
+
}
|
|
17
|
+
: {
|
|
18
|
+
getItem: () => memory,
|
|
19
|
+
setItem: (_key, value) => {
|
|
20
|
+
memory = value;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
fetch,
|
|
24
|
+
locks
|
|
25
|
+
? (work) => locks.request("disposabl.analytics.identity.v1", work)
|
|
26
|
+
: undefined,
|
|
27
|
+
);
|
|
6
28
|
|
|
7
29
|
export function usePageTelemetry(
|
|
8
30
|
pathname: string,
|
|
@@ -22,7 +44,7 @@ export function usePageTelemetry(
|
|
|
22
44
|
const key = JSON.stringify([pathname, sessionId(token)]);
|
|
23
45
|
if (lastView.current === key) return;
|
|
24
46
|
lastView.current = key;
|
|
25
|
-
|
|
47
|
+
telemetry.view(
|
|
26
48
|
import.meta.env.VITE_CONVEX_SITE_URL,
|
|
27
49
|
"web",
|
|
28
50
|
pathname,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ThemeProvider, useTheme } from "next-themes";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
+
import { useAuthActions } from "@convex-dev/auth/react";
|
|
3
|
+
import { makeFunctionReference } from "convex/server";
|
|
4
|
+
import { useMutation, useQuery } from "convex/react";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { PasswordPage } from "../components/password-page";
|
|
7
|
+
import { Button } from "../components/ui/button";
|
|
8
|
+
|
|
9
|
+
export const Route = createFileRoute("/_providers/billing-login")({
|
|
10
|
+
component: BillingLogin,
|
|
11
|
+
});
|
|
12
|
+
const inspect = makeFunctionReference<
|
|
13
|
+
"query",
|
|
14
|
+
{ code: string },
|
|
15
|
+
{ name: string | null } | null
|
|
16
|
+
>("billingHandoff:inspect");
|
|
17
|
+
const redeem = makeFunctionReference<
|
|
18
|
+
"mutation",
|
|
19
|
+
{ code: string },
|
|
20
|
+
{
|
|
21
|
+
accessToken: string;
|
|
22
|
+
refreshToken: string;
|
|
23
|
+
refreshTokenExpiresAt: number;
|
|
24
|
+
userId: string;
|
|
25
|
+
purchase: "monthly" | "topup";
|
|
26
|
+
expiresAt: number;
|
|
27
|
+
}
|
|
28
|
+
>("billingHandoff:redeem");
|
|
29
|
+
function BillingLogin() {
|
|
30
|
+
const [framed] = useState(
|
|
31
|
+
() => typeof window !== "undefined" && window.top !== window.self,
|
|
32
|
+
);
|
|
33
|
+
const [code] = useState(() =>
|
|
34
|
+
typeof window === "undefined" ? "" : window.location.hash.slice(1),
|
|
35
|
+
);
|
|
36
|
+
const account = useQuery(inspect, code && !framed ? { code } : "skip");
|
|
37
|
+
const exchange = useMutation(redeem);
|
|
38
|
+
const { setSession } = useAuthActions();
|
|
39
|
+
const [pending, setPending] = useState(false);
|
|
40
|
+
const [error, setError] = useState("");
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
window.history.replaceState(
|
|
43
|
+
window.history.state,
|
|
44
|
+
"",
|
|
45
|
+
window.location.pathname,
|
|
46
|
+
);
|
|
47
|
+
}, []);
|
|
48
|
+
async function proceed() {
|
|
49
|
+
if (!account?.name || pending) return;
|
|
50
|
+
setPending(true);
|
|
51
|
+
try {
|
|
52
|
+
const { purchase, expiresAt, ...tokens } = await exchange({ code });
|
|
53
|
+
await setSession(tokens);
|
|
54
|
+
window.sessionStorage.setItem(
|
|
55
|
+
"billing-from-ios",
|
|
56
|
+
JSON.stringify({ purchase, expiresAt, userId: tokens.userId }),
|
|
57
|
+
);
|
|
58
|
+
window.location.replace("/pricing?source=ios");
|
|
59
|
+
} catch {
|
|
60
|
+
setError(
|
|
61
|
+
"This link could not sign you in. Open billing again from the app.",
|
|
62
|
+
);
|
|
63
|
+
setPending(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return (
|
|
67
|
+
<PasswordPage
|
|
68
|
+
title="Continue from the app"
|
|
69
|
+
description="Sign in to view website pricing."
|
|
70
|
+
>
|
|
71
|
+
{framed ? (
|
|
72
|
+
<p role="alert">Open this link directly in your browser.</p>
|
|
73
|
+
) : account === undefined && code ? (
|
|
74
|
+
<p>Checking your account…</p>
|
|
75
|
+
) : account?.name ? (
|
|
76
|
+
<>
|
|
77
|
+
<p className="break-words font-medium">{account.name}</p>
|
|
78
|
+
<p>This signs this browser into the account shown above.</p>
|
|
79
|
+
<Button disabled={pending} onClick={() => void proceed()}>
|
|
80
|
+
{pending ? "Signing in…" : `Continue as ${account.name}`}
|
|
81
|
+
</Button>
|
|
82
|
+
</>
|
|
83
|
+
) : (
|
|
84
|
+
<p role="alert">
|
|
85
|
+
This link expired or your account could not be identified. Open
|
|
86
|
+
billing again from the app.
|
|
87
|
+
</p>
|
|
88
|
+
)}
|
|
89
|
+
{error && <p role="alert">{error}</p>}
|
|
90
|
+
</PasswordPage>
|
|
91
|
+
);
|
|
92
|
+
}
|