create-disposabl-app 0.17.2 → 0.17.3
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/dist/disposabl.js +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/default/apps/mobile/app.config.js +15 -1
- package/dist/templates/default/apps/mobile/src/app/+native-intent.ts +15 -0
- package/dist/templates/default/packages/backend/convex/billingHandoff.ts +1 -0
- package/dist/templates/default/packages/backend/convex/convex.config.ts +1 -0
- package/dist/templates/default/packages/backend/convex/schema.ts +3 -0
- package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +2 -0
- package/dist/templates/default/packages/disposabl-kit/client/routes/billing-login.tsx +10 -2
- package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +33 -2
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +8 -2
- package/dist/templates/default/packages/disposabl-kit/payments/checkout-attempt.ts +21 -0
- package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +83 -7
- package/dist/templates/default/packages/tests/billing-handoff.test.ts +68 -1
- package/dist/templates/default/packages/tests/mobile-google.test.ts +13 -1
- package/package.json +1 -1
package/dist/disposabl.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1563,7 +1563,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
1563
1563
|
import { Command, CommanderError } from "commander";
|
|
1564
1564
|
import * as p2 from "@clack/prompts";
|
|
1565
1565
|
// package.json
|
|
1566
|
-
var version = "0.17.
|
|
1566
|
+
var version = "0.17.3";
|
|
1567
1567
|
|
|
1568
1568
|
// ../cli/telemetry.ts
|
|
1569
1569
|
var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const { createHash } = require("node:crypto");
|
|
2
|
+
const { readFileSync } = require("node:fs");
|
|
3
|
+
const { join } = require("node:path");
|
|
2
4
|
const project = require("../../package.json");
|
|
3
5
|
|
|
4
6
|
module.exports = ({ config }) => {
|
|
@@ -16,6 +18,10 @@ module.exports = ({ config }) => {
|
|
|
16
18
|
.update(project.name)
|
|
17
19
|
.digest("hex")
|
|
18
20
|
.slice(0, 12);
|
|
21
|
+
const paymentsEnabled = JSON.parse(
|
|
22
|
+
readFileSync(join(__dirname, "../../disposabl.json"), "utf8"),
|
|
23
|
+
).features.includes("payments");
|
|
24
|
+
const billingScheme = `disposabl-billing-${suffix}-${channel}`;
|
|
19
25
|
const basePackage = config.android?.package || `app.disposabl.a${suffix}`;
|
|
20
26
|
const versionCode = Number(process.env.DISPOSABL_ANDROID_VERSION_CODE || 1);
|
|
21
27
|
if (
|
|
@@ -49,8 +55,12 @@ module.exports = ({ config }) => {
|
|
|
49
55
|
...new Set([
|
|
50
56
|
...[config.scheme || []].flat(),
|
|
51
57
|
`disposabl-${project.name.replace(/[^a-z0-9.-]/g, "-")}`,
|
|
58
|
+
...(paymentsEnabled ? [billingScheme] : []),
|
|
52
59
|
]),
|
|
53
60
|
],
|
|
61
|
+
...(paymentsEnabled
|
|
62
|
+
? { extra: { ...config.extra, billingReturnChannel: channel } }
|
|
63
|
+
: {}),
|
|
54
64
|
owner: process.env.EXPO_OWNER || config.owner,
|
|
55
65
|
slug: process.env.EXPO_SLUG || config.slug,
|
|
56
66
|
ios: {
|
|
@@ -96,7 +106,11 @@ module.exports = ({ config }) => {
|
|
|
96
106
|
...(projectId
|
|
97
107
|
? {
|
|
98
108
|
runtimeVersion: { policy: "fingerprint" },
|
|
99
|
-
extra: {
|
|
109
|
+
extra: {
|
|
110
|
+
...config.extra,
|
|
111
|
+
...(paymentsEnabled ? { billingReturnChannel: channel } : {}),
|
|
112
|
+
eas: { ...config.extra?.eas, projectId },
|
|
113
|
+
},
|
|
100
114
|
}
|
|
101
115
|
: {}),
|
|
102
116
|
updates: {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Ignore the billing return link so foreground refresh retains the current screen. */
|
|
2
|
+
export function redirectSystemPath({
|
|
3
|
+
path,
|
|
4
|
+
}: {
|
|
5
|
+
path: string;
|
|
6
|
+
initial: boolean;
|
|
7
|
+
}) {
|
|
8
|
+
if (
|
|
9
|
+
/^disposabl-billing-[a-f0-9]{12}-[a-z][a-z0-9-]{0,62}:\/\/billing-return\/?$/.test(
|
|
10
|
+
path,
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+
return null;
|
|
14
|
+
return path;
|
|
15
|
+
}
|
|
@@ -18,6 +18,7 @@ const app = defineApp({
|
|
|
18
18
|
AUTUMN_SECRET_KEY: v.optional(v.string()),
|
|
19
19
|
BILLING_RETURN_URL: v.optional(v.string()),
|
|
20
20
|
MOBILE_WEB_CHECKOUT_ENABLED: v.optional(v.string()),
|
|
21
|
+
BILLING_IOS_RETURN_CHANNELS: v.optional(v.string()),
|
|
21
22
|
REVENUECAT_CONSUMABLE_OWNER: v.optional(v.string()),
|
|
22
23
|
REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED: v.optional(v.string()),
|
|
23
24
|
REVENUECAT_WEBHOOK_AUTH: v.optional(v.string()),
|
|
@@ -25,6 +25,9 @@ export default defineSchema({
|
|
|
25
25
|
userId: v.string(),
|
|
26
26
|
sessionId: v.string(),
|
|
27
27
|
purchase: v.optional(v.union(v.literal("monthly"), v.literal("topup"))),
|
|
28
|
+
returnChannel: v.optional(v.string()),
|
|
29
|
+
browserSessionId: v.optional(v.string()),
|
|
30
|
+
returnExpiresAt: v.optional(v.number()),
|
|
28
31
|
expiresAt: v.number(),
|
|
29
32
|
}).index("by_hash", ["hash"]),
|
|
30
33
|
billingAttempts: defineTable({
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
+
For the optional Open app action, set the public deployment variable `BILLING_IOS_RETURN_CHANNELS` to a comma-separated allowlist of this deployment's native channels, for example `production` on production or `preview` on a preview backend. Only list channels built for that backend. A fresh iOS binary registers a separate project-and-channel billing scheme; the existing sign-in scheme is unchanged. A one-time browser handoff binds its return claim to the exchanged browser session and allowed channel for 30 minutes. No credentials or purchase data appear in the return URL. Missing or unlisted channels and older binaries retain manual return. Opening the app does not confirm payment or continue setup; the user refreshes the authoritative balance and chooses Continue. Rebuild native binaries: the new URL scheme changes the native runtime fingerprint and cannot be delivered as an OTA-only change.
|
|
6
|
+
|
|
5
7
|
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
8
|
|
|
7
9
|
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.
|
|
@@ -24,6 +24,7 @@ const redeem = makeFunctionReference<
|
|
|
24
24
|
userId: string;
|
|
25
25
|
purchase: "monthly" | "topup";
|
|
26
26
|
expiresAt: number;
|
|
27
|
+
returnClaim: string | null;
|
|
27
28
|
}
|
|
28
29
|
>("billingHandoff:redeem");
|
|
29
30
|
function BillingLogin() {
|
|
@@ -49,11 +50,18 @@ function BillingLogin() {
|
|
|
49
50
|
if (!account?.name || pending) return;
|
|
50
51
|
setPending(true);
|
|
51
52
|
try {
|
|
52
|
-
const { purchase, expiresAt, ...tokens } = await exchange({
|
|
53
|
+
const { purchase, expiresAt, returnClaim, ...tokens } = await exchange({
|
|
54
|
+
code,
|
|
55
|
+
});
|
|
53
56
|
await setSession(tokens);
|
|
54
57
|
window.sessionStorage.setItem(
|
|
55
58
|
"billing-from-ios",
|
|
56
|
-
JSON.stringify({
|
|
59
|
+
JSON.stringify({
|
|
60
|
+
purchase,
|
|
61
|
+
expiresAt,
|
|
62
|
+
userId: tokens.userId,
|
|
63
|
+
returnClaim,
|
|
64
|
+
}),
|
|
57
65
|
);
|
|
58
66
|
window.location.replace("/pricing?source=ios");
|
|
59
67
|
} catch {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createFileRoute } from "@tanstack/react-router";
|
|
2
2
|
import { makeFunctionReference } from "convex/server";
|
|
3
|
-
import { useAction, useConvexAuth } from "convex/react";
|
|
3
|
+
import { useAction, useConvexAuth, useQuery } from "convex/react";
|
|
4
4
|
import {
|
|
5
5
|
useCallback,
|
|
6
6
|
useEffect,
|
|
@@ -14,6 +14,8 @@ import { paymentsEnabled } from "../../features";
|
|
|
14
14
|
import {
|
|
15
15
|
requestCheckout,
|
|
16
16
|
handoffContext,
|
|
17
|
+
handoffReturnClaim,
|
|
18
|
+
safeBillingReturnUrl,
|
|
17
19
|
handoffAllows,
|
|
18
20
|
type CheckoutResult,
|
|
19
21
|
} from "../../payments/checkout-attempt";
|
|
@@ -46,6 +48,11 @@ const checkout = makeFunctionReference<
|
|
|
46
48
|
{ purchase: "monthly" | "topup"; requestId: string },
|
|
47
49
|
CheckoutResult
|
|
48
50
|
>("billing:checkout");
|
|
51
|
+
const returnTarget = makeFunctionReference<
|
|
52
|
+
"query",
|
|
53
|
+
{ code: string },
|
|
54
|
+
{ url: string; expiresAt: number } | null
|
|
55
|
+
>("billingHandoff:returnTarget");
|
|
49
56
|
const portal = makeFunctionReference<
|
|
50
57
|
"action",
|
|
51
58
|
Record<string, never>,
|
|
@@ -100,6 +107,16 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
100
107
|
window.location.search,
|
|
101
108
|
),
|
|
102
109
|
);
|
|
110
|
+
const [returnClaim] = useState(() =>
|
|
111
|
+
typeof window === "undefined"
|
|
112
|
+
? null
|
|
113
|
+
: handoffReturnClaim(window.sessionStorage.getItem("billing-from-ios")),
|
|
114
|
+
);
|
|
115
|
+
const returnLink = useQuery(
|
|
116
|
+
returnTarget,
|
|
117
|
+
session && returnClaim ? { code: returnClaim } : "skip",
|
|
118
|
+
);
|
|
119
|
+
const openApp = safeBillingReturnUrl(returnLink?.url);
|
|
103
120
|
const { isLoading } = useConvexAuth();
|
|
104
121
|
const getSnapshot = useAction(snapshot);
|
|
105
122
|
const start = useAction(checkout);
|
|
@@ -230,7 +247,21 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
230
247
|
the balance has not updated yet.
|
|
231
248
|
</p>
|
|
232
249
|
{fromIos && (
|
|
233
|
-
<p>
|
|
250
|
+
<p>
|
|
251
|
+
After checkout, return to the app and refresh your credits.{" "}
|
|
252
|
+
{openApp && (
|
|
253
|
+
<a
|
|
254
|
+
className="underline"
|
|
255
|
+
href={openApp}
|
|
256
|
+
onClick={(event) => {
|
|
257
|
+
if (!returnLink || Date.now() >= returnLink.expiresAt)
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
}}
|
|
260
|
+
>
|
|
261
|
+
Open app
|
|
262
|
+
</a>
|
|
263
|
+
)}
|
|
264
|
+
</p>
|
|
234
265
|
)}
|
|
235
266
|
{checkoutNeedsReview && (
|
|
236
267
|
<p role="alert">
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Constants from "expo-constants";
|
|
1
2
|
import { useMutation } from "convex/react";
|
|
2
3
|
import { makeFunctionReference } from "convex/server";
|
|
3
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
@@ -17,7 +18,7 @@ const topupProduct = process.env.EXPO_PUBLIC_REVENUECAT_IOS_TOPUP_PRODUCT;
|
|
|
17
18
|
|
|
18
19
|
const create = makeFunctionReference<
|
|
19
20
|
"mutation",
|
|
20
|
-
{ purchase: "monthly" | "topup" },
|
|
21
|
+
{ purchase: "monthly" | "topup"; returnChannel?: string },
|
|
21
22
|
{ url: string; userId: string }
|
|
22
23
|
>("billingHandoff:create");
|
|
23
24
|
type Snapshot = BillingSnapshot &
|
|
@@ -148,7 +149,12 @@ export function useWebCheckout(
|
|
|
148
149
|
current,
|
|
149
150
|
);
|
|
150
151
|
if (!current()) throw new Error("Account changed.");
|
|
151
|
-
|
|
152
|
+
const returnChannel =
|
|
153
|
+
Constants.expoConfig?.extra?.billingReturnChannel;
|
|
154
|
+
return handoff({
|
|
155
|
+
purchase,
|
|
156
|
+
...(typeof returnChannel === "string" ? { returnChannel } : {}),
|
|
157
|
+
});
|
|
152
158
|
},
|
|
153
159
|
);
|
|
154
160
|
const parsed = new URL(handoffResult.url);
|
|
@@ -62,3 +62,24 @@ export function handoffContext(stored: string | null, search: string) {
|
|
|
62
62
|
stored !== null || new URLSearchParams(search).get("source") === "ios",
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
/** A claim is checked against the redeemed browser session by the backend. */
|
|
67
|
+
export function handoffReturnClaim(value: string | null) {
|
|
68
|
+
try {
|
|
69
|
+
const record = JSON.parse(value ?? "null");
|
|
70
|
+
return typeof record?.returnClaim === "string" &&
|
|
71
|
+
/^[A-Za-z0-9_-]{43}$/.test(record.returnClaim)
|
|
72
|
+
? record.returnClaim
|
|
73
|
+
: null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function safeBillingReturnUrl(value: string | undefined) {
|
|
79
|
+
return value &&
|
|
80
|
+
/^disposabl-billing-[a-f0-9]{12}-[a-z][a-z0-9-]{0,62}:\/\/billing-return$/.test(
|
|
81
|
+
value,
|
|
82
|
+
)
|
|
83
|
+
? value
|
|
84
|
+
: null;
|
|
85
|
+
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type QueryCtx,
|
|
10
10
|
} from "../../backend/convex/_generated/server";
|
|
11
11
|
import { paymentsEnabled } from "../features";
|
|
12
|
+
import project from "../../../package.json";
|
|
12
13
|
import { billingConfig, mobileWebCheckoutConfigured } from "./billing";
|
|
13
14
|
import {
|
|
14
15
|
hashBrowserCode as digest,
|
|
@@ -16,6 +17,30 @@ import {
|
|
|
16
17
|
} from "./browser-session";
|
|
17
18
|
|
|
18
19
|
const ttl = 120_000;
|
|
20
|
+
const returnTtl = 30 * 60_000;
|
|
21
|
+
const allowedChannel = (channel: string | undefined) =>
|
|
22
|
+
!!channel &&
|
|
23
|
+
/^[a-z][a-z0-9-]{0,62}$/.test(channel) &&
|
|
24
|
+
(process.env.BILLING_IOS_RETURN_CHANNELS ?? "")
|
|
25
|
+
.split(",")
|
|
26
|
+
.map((s: string) => s.trim())
|
|
27
|
+
.includes(channel);
|
|
28
|
+
async function returnUrl(channel: string) {
|
|
29
|
+
const hash = await digest(project.name);
|
|
30
|
+
return `disposabl-billing-${hash.slice(0, 12)}-${channel}://billing-return`;
|
|
31
|
+
}
|
|
32
|
+
function accessSessionId(token: string) {
|
|
33
|
+
try {
|
|
34
|
+
const payload = token.split(".")[1];
|
|
35
|
+
if (!payload) return null;
|
|
36
|
+
const value = JSON.parse(
|
|
37
|
+
atob(payload.replaceAll("-", "+").replaceAll("_", "/")),
|
|
38
|
+
);
|
|
39
|
+
return typeof value.sub === "string" && value.sub ? value.sub : null;
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
19
44
|
const invalid = () =>
|
|
20
45
|
new ConvexError("This link expired. Open billing again from the app.");
|
|
21
46
|
const cleanupRef = makeFunctionReference<"mutation", { hash: string }, null>(
|
|
@@ -28,13 +53,17 @@ async function lookup(ctx: QueryCtx, code: string) {
|
|
|
28
53
|
.query("billingHandoffs")
|
|
29
54
|
.withIndex("by_hash", (q) => q.eq("hash", hash))
|
|
30
55
|
.unique();
|
|
31
|
-
if (!row || row.expiresAt <= Date.now()
|
|
56
|
+
if (!row || row.expiresAt <= Date.now() || row.browserSessionId)
|
|
57
|
+
throw invalid();
|
|
32
58
|
return row;
|
|
33
59
|
}
|
|
34
60
|
export const create = mutation({
|
|
35
|
-
args: {
|
|
61
|
+
args: {
|
|
62
|
+
purchase: v.union(v.literal("monthly"), v.literal("topup")),
|
|
63
|
+
returnChannel: v.optional(v.string()),
|
|
64
|
+
},
|
|
36
65
|
returns: v.object({ url: v.string(), userId: v.string() }),
|
|
37
|
-
handler: async (ctx, { purchase }) => {
|
|
66
|
+
handler: async (ctx, { purchase, returnChannel }) => {
|
|
38
67
|
const config = billingConfig(paymentsEnabled, process.env);
|
|
39
68
|
if (!config || !mobileWebCheckoutConfigured(paymentsEnabled, process.env))
|
|
40
69
|
throw new ConvexError("Website checkout is unavailable.");
|
|
@@ -48,14 +77,21 @@ export const create = mutation({
|
|
|
48
77
|
.replaceAll("/", "_")
|
|
49
78
|
.replaceAll("=", "");
|
|
50
79
|
const hash = await digest(code);
|
|
80
|
+
const channel = allowedChannel(returnChannel) ? returnChannel : undefined;
|
|
81
|
+
const now = Date.now();
|
|
51
82
|
await ctx.db.insert("billingHandoffs", {
|
|
52
83
|
hash,
|
|
53
84
|
userId,
|
|
54
85
|
sessionId: identity.subject,
|
|
55
86
|
purchase,
|
|
56
|
-
|
|
87
|
+
...(channel
|
|
88
|
+
? { returnChannel: channel, returnExpiresAt: now + returnTtl }
|
|
89
|
+
: {}),
|
|
90
|
+
expiresAt: now + ttl,
|
|
91
|
+
});
|
|
92
|
+
await ctx.scheduler.runAfter(channel ? returnTtl : ttl, cleanupRef, {
|
|
93
|
+
hash,
|
|
57
94
|
});
|
|
58
|
-
await ctx.scheduler.runAfter(ttl, cleanupRef, { hash });
|
|
59
95
|
const url = new URL("/billing-login", config.returnUrl);
|
|
60
96
|
url.hash = code;
|
|
61
97
|
return { url: url.href, userId };
|
|
@@ -99,15 +135,55 @@ export const redeem = mutation({
|
|
|
99
135
|
userId: v.string(),
|
|
100
136
|
purchase: v.union(v.literal("monthly"), v.literal("topup")),
|
|
101
137
|
expiresAt: v.number(),
|
|
138
|
+
returnClaim: v.union(v.string(), v.null()),
|
|
102
139
|
}),
|
|
103
140
|
handler: async (ctx, { code }) => {
|
|
104
141
|
const row = await lookup(ctx, code);
|
|
105
142
|
const tokens = await exchangeBrowserSession(ctx, row.sessionId, row.userId);
|
|
106
|
-
|
|
143
|
+
const browserSessionId = accessSessionId(tokens.accessToken);
|
|
144
|
+
const hasReturn =
|
|
145
|
+
!!row.returnChannel &&
|
|
146
|
+
allowedChannel(row.returnChannel) &&
|
|
147
|
+
!!browserSessionId;
|
|
148
|
+
if (hasReturn)
|
|
149
|
+
await ctx.db.patch("billingHandoffs", row._id, { browserSessionId });
|
|
150
|
+
else await ctx.db.delete("billingHandoffs", row._id);
|
|
107
151
|
return {
|
|
108
152
|
...tokens,
|
|
109
153
|
purchase: row.purchase ?? "monthly",
|
|
110
154
|
expiresAt: row.expiresAt,
|
|
155
|
+
returnClaim: hasReturn ? code : null,
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
export const returnTarget = query({
|
|
160
|
+
args: { code: v.string() },
|
|
161
|
+
returns: v.union(
|
|
162
|
+
v.null(),
|
|
163
|
+
v.object({ url: v.string(), expiresAt: v.number() }),
|
|
164
|
+
),
|
|
165
|
+
handler: async (ctx, { code }) => {
|
|
166
|
+
if (!/^[A-Za-z0-9_-]{43}$/.test(code)) return null;
|
|
167
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
168
|
+
const userId = await getAuthUserId(ctx);
|
|
169
|
+
if (!identity || !userId) return null;
|
|
170
|
+
const hash = await digest(code);
|
|
171
|
+
const row = await ctx.db
|
|
172
|
+
.query("billingHandoffs")
|
|
173
|
+
.withIndex("by_hash", (q) => q.eq("hash", hash))
|
|
174
|
+
.unique();
|
|
175
|
+
if (
|
|
176
|
+
!row ||
|
|
177
|
+
row.userId !== userId ||
|
|
178
|
+
row.browserSessionId !== identity.subject ||
|
|
179
|
+
!row.returnExpiresAt ||
|
|
180
|
+
row.returnExpiresAt <= Date.now() ||
|
|
181
|
+
!allowedChannel(row.returnChannel)
|
|
182
|
+
)
|
|
183
|
+
return null;
|
|
184
|
+
return {
|
|
185
|
+
url: await returnUrl(row.returnChannel!),
|
|
186
|
+
expiresAt: row.returnExpiresAt,
|
|
111
187
|
};
|
|
112
188
|
},
|
|
113
189
|
});
|
|
@@ -119,7 +195,7 @@ export const cleanup = internalMutation({
|
|
|
119
195
|
.query("billingHandoffs")
|
|
120
196
|
.withIndex("by_hash", (q) => q.eq("hash", hash))
|
|
121
197
|
.unique();
|
|
122
|
-
if (row && row.expiresAt <= Date.now())
|
|
198
|
+
if (row && (row.returnExpiresAt ?? row.expiresAt) <= Date.now())
|
|
123
199
|
await ctx.db.delete("billingHandoffs", row._id);
|
|
124
200
|
return null;
|
|
125
201
|
},
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
redeem,
|
|
5
|
+
cleanup,
|
|
6
|
+
returnTarget,
|
|
7
|
+
} from "../disposabl-kit/server/billing-handoff";
|
|
4
8
|
|
|
5
9
|
test("billing handoff expires and a redeemed link cannot be replayed", async () => {
|
|
6
10
|
let row: any = {
|
|
@@ -29,6 +33,7 @@ test("billing handoff expires and a redeemed link cannot be replayed", async ()
|
|
|
29
33
|
userId: "alice",
|
|
30
34
|
purchase: "topup",
|
|
31
35
|
expiresAt,
|
|
36
|
+
returnClaim: null,
|
|
32
37
|
});
|
|
33
38
|
await assert.rejects((redeem as any)._handler(ctx, { code }), /expired/);
|
|
34
39
|
assert.equal(exchanges, 1);
|
|
@@ -114,3 +119,65 @@ test("expired iOS selection stays restricted on a query-free pricing return", as
|
|
|
114
119
|
assert.equal(handoffContext(null, "").fromIos, false);
|
|
115
120
|
assert.equal(handoffContext(null, "?source=ios").fromIos, true);
|
|
116
121
|
});
|
|
122
|
+
|
|
123
|
+
test("return target is bound to a redeemed browser session and an allowlisted channel", async () => {
|
|
124
|
+
const previous = process.env.BILLING_IOS_RETURN_CHANNELS;
|
|
125
|
+
process.env.BILLING_IOS_RETURN_CHANNELS = "production,preview";
|
|
126
|
+
const code = "Q".repeat(43);
|
|
127
|
+
const expiresAt = Date.now() + 120_000;
|
|
128
|
+
let row: any = {
|
|
129
|
+
_id: "one",
|
|
130
|
+
userId: "alice",
|
|
131
|
+
sessionId: "source",
|
|
132
|
+
purchase: "topup",
|
|
133
|
+
expiresAt,
|
|
134
|
+
returnChannel: "preview",
|
|
135
|
+
returnExpiresAt: Date.now() + 300_000,
|
|
136
|
+
};
|
|
137
|
+
let identity: any = { subject: "browser" };
|
|
138
|
+
let owner = "alice";
|
|
139
|
+
const accessToken = `x.${btoa(JSON.stringify({ sub: "browser" }))}.x`;
|
|
140
|
+
const ctx: any = {
|
|
141
|
+
auth: { getUserIdentity: async () => identity },
|
|
142
|
+
db: {
|
|
143
|
+
query: () => ({ withIndex: () => ({ unique: async () => row }) }),
|
|
144
|
+
patch: async (_table: string, _id: string, value: object) =>
|
|
145
|
+
Object.assign(row, value),
|
|
146
|
+
delete: async () => {
|
|
147
|
+
row = null;
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
runQuery: async () => ({ userId: owner }),
|
|
151
|
+
runMutation: async () => ({ userId: "alice", accessToken }),
|
|
152
|
+
};
|
|
153
|
+
try {
|
|
154
|
+
assert.equal(await (returnTarget as any)._handler(ctx, { code }), null);
|
|
155
|
+
const issued = await (redeem as any)._handler(ctx, { code });
|
|
156
|
+
assert.equal(issued.returnClaim, code);
|
|
157
|
+
await assert.rejects((redeem as any)._handler(ctx, { code }), /expired/);
|
|
158
|
+
const result = await (returnTarget as any)._handler(ctx, { code });
|
|
159
|
+
assert.match(
|
|
160
|
+
result.url,
|
|
161
|
+
/^disposabl-billing-[a-f0-9]{12}-preview:\/\/billing-return$/,
|
|
162
|
+
);
|
|
163
|
+
assert.equal(result.expiresAt, row.returnExpiresAt);
|
|
164
|
+
identity = { subject: "other" };
|
|
165
|
+
assert.equal(await (returnTarget as any)._handler(ctx, { code }), null);
|
|
166
|
+
identity = { subject: "browser" };
|
|
167
|
+
owner = "bob";
|
|
168
|
+
assert.equal(await (returnTarget as any)._handler(ctx, { code }), null);
|
|
169
|
+
owner = "alice";
|
|
170
|
+
row.returnChannel = "forged";
|
|
171
|
+
assert.equal(await (returnTarget as any)._handler(ctx, { code }), null);
|
|
172
|
+
row.returnChannel = "preview";
|
|
173
|
+
row.returnExpiresAt = Date.now() - 1;
|
|
174
|
+
assert.equal(await (returnTarget as any)._handler(ctx, { code }), null);
|
|
175
|
+
assert.equal(
|
|
176
|
+
await (returnTarget as any)._handler(ctx, { code: "../../evil" }),
|
|
177
|
+
null,
|
|
178
|
+
);
|
|
179
|
+
} finally {
|
|
180
|
+
if (previous === undefined) delete process.env.BILLING_IOS_RETURN_CHANNELS;
|
|
181
|
+
else process.env.BILLING_IOS_RETURN_CHANNELS = previous;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { authReturnPath } from "../disposabl-kit/mobile/lib/auth-return";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
+
import projectFeatures from "../../disposabl.json";
|
|
3
4
|
import assert from "node:assert/strict";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
import { spawnSync } from "node:child_process";
|
|
@@ -11,6 +12,8 @@ import {
|
|
|
11
12
|
mobileAuthReturnUrl,
|
|
12
13
|
} from "../disposabl-kit/lib/mobile-auth";
|
|
13
14
|
|
|
15
|
+
const selectedFeatures: readonly string[] = projectFeatures.features;
|
|
16
|
+
|
|
14
17
|
test("mobile Google browser lifecycle", () => {
|
|
15
18
|
const result = spawnSync(
|
|
16
19
|
process.execPath,
|
|
@@ -83,11 +86,20 @@ test(
|
|
|
83
86
|
"../../apps/mobile/app.config.js",
|
|
84
87
|
);
|
|
85
88
|
const config = configure({ config: { scheme: ["custom", "another"] } });
|
|
86
|
-
assert.deepEqual(config.scheme, [
|
|
89
|
+
assert.deepEqual(config.scheme.slice(0, 3), [
|
|
87
90
|
"custom",
|
|
88
91
|
"another",
|
|
89
92
|
new URL(mobileAuthReturnUrl).protocol.slice(0, -1),
|
|
90
93
|
]);
|
|
94
|
+
if (config.scheme.length === 4)
|
|
95
|
+
assert.match(
|
|
96
|
+
config.scheme[3],
|
|
97
|
+
/^disposabl-billing-[a-f0-9]{12}-[a-z][a-z0-9-]{0,62}$/,
|
|
98
|
+
);
|
|
99
|
+
assert.equal(
|
|
100
|
+
config.scheme.length,
|
|
101
|
+
selectedFeatures.includes("payments") ? 4 : 3,
|
|
102
|
+
);
|
|
91
103
|
} finally {
|
|
92
104
|
keys.forEach((key, index) => {
|
|
93
105
|
if (saved[index] === undefined) delete process.env[key];
|