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.
- package/README.md +15 -1
- package/dist/disposabl.js +357 -50
- package/dist/index.js +8973 -154
- package/dist/templates/default/.github/scripts/macos-release.sh +81 -0
- package/dist/templates/default/.github/scripts/platforms.sh +1 -1
- package/dist/templates/default/.github/scripts/release.sh +1 -1
- package/dist/templates/default/.github/workflows/pipeline.yml +14 -3
- package/dist/templates/default/apps/desktop/README.md +13 -2
- package/dist/templates/default/apps/desktop/forge.config.mts +9 -3
- 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/ci-platform-selection.test.ts +54 -0
- package/dist/templates/default/packages/tests/desktop-macos-release.test.ts +226 -0
- 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,102 @@
|
|
|
1
|
+
/** Metadata sent to an application owner's analytics sink, never request data. */
|
|
2
|
+
export type SdkOperation =
|
|
3
|
+
| "agentAbortMessage"
|
|
4
|
+
| "agentGetMessages"
|
|
5
|
+
| "agentSendMessage"
|
|
6
|
+
| "appsCreate"
|
|
7
|
+
| "appsDelete"
|
|
8
|
+
| "appsGet"
|
|
9
|
+
| "appsList"
|
|
10
|
+
| "appsRepositoryToken"
|
|
11
|
+
| "appsRequestConfiguration"
|
|
12
|
+
| "appsUpdate"
|
|
13
|
+
| "connectionsStatus"
|
|
14
|
+
| "previewsGet"
|
|
15
|
+
| "previewsList"
|
|
16
|
+
| "previewsTokenCreate"
|
|
17
|
+
| "releasesGet"
|
|
18
|
+
| "usersCurrent";
|
|
19
|
+
|
|
20
|
+
const operations = new Set<SdkOperation>([
|
|
21
|
+
"agentAbortMessage",
|
|
22
|
+
"agentGetMessages",
|
|
23
|
+
"agentSendMessage",
|
|
24
|
+
"appsCreate",
|
|
25
|
+
"appsDelete",
|
|
26
|
+
"appsGet",
|
|
27
|
+
"appsList",
|
|
28
|
+
"appsRepositoryToken",
|
|
29
|
+
"appsRequestConfiguration",
|
|
30
|
+
"appsUpdate",
|
|
31
|
+
"connectionsStatus",
|
|
32
|
+
"previewsGet",
|
|
33
|
+
"previewsList",
|
|
34
|
+
"previewsTokenCreate",
|
|
35
|
+
"releasesGet",
|
|
36
|
+
"usersCurrent",
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
export type SdkAnalyticsEvent<Operation extends string = SdkOperation> = {
|
|
40
|
+
operation: Operation;
|
|
41
|
+
outcome: "success" | "error";
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Opt in explicitly; capture should send to the application owner's project. */
|
|
45
|
+
export function createSdkAnalytics<
|
|
46
|
+
const Operation extends string = SdkOperation,
|
|
47
|
+
>(config: {
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
environment: "production" | "development" | "test";
|
|
50
|
+
e2e?: boolean;
|
|
51
|
+
/** Fixed SDK operation IDs, for APIs generated from the owner's contract. */
|
|
52
|
+
operations?: readonly Operation[];
|
|
53
|
+
capture: (event: SdkAnalyticsEvent<Operation>) => void | Promise<void>;
|
|
54
|
+
}) {
|
|
55
|
+
const allowed: ReadonlySet<string> = config.operations
|
|
56
|
+
? new Set(
|
|
57
|
+
config.operations.filter((name) =>
|
|
58
|
+
/^[A-Za-z][A-Za-z0-9_]{0,79}$/.test(name),
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
: operations;
|
|
62
|
+
function capture(operation: Operation, outcome: "success" | "error") {
|
|
63
|
+
const env = (
|
|
64
|
+
globalThis as { process?: { env?: Record<string, string | undefined> } }
|
|
65
|
+
).process?.env;
|
|
66
|
+
if (
|
|
67
|
+
config.enabled === false ||
|
|
68
|
+
config.environment !== "production" ||
|
|
69
|
+
config.e2e ||
|
|
70
|
+
env?.E2E_TELEMETRY_DISABLED === "1" ||
|
|
71
|
+
env?.DO_NOT_TRACK === "1" ||
|
|
72
|
+
(typeof navigator !== "undefined" && navigator.doNotTrack === "1") ||
|
|
73
|
+
!allowed.has(operation)
|
|
74
|
+
)
|
|
75
|
+
return;
|
|
76
|
+
try {
|
|
77
|
+
void Promise.resolve(config.capture({ operation, outcome })).catch(
|
|
78
|
+
() => {},
|
|
79
|
+
);
|
|
80
|
+
} catch {
|
|
81
|
+
// Analytics must not affect an SDK call.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
/** Wrap a generated SDK call; handles both thrown and returned errors. */
|
|
86
|
+
async track<T>(operation: Operation, call: () => Promise<T>): Promise<T> {
|
|
87
|
+
try {
|
|
88
|
+
const result = await call();
|
|
89
|
+
const failed =
|
|
90
|
+
result !== null &&
|
|
91
|
+
typeof result === "object" &&
|
|
92
|
+
"error" in result &&
|
|
93
|
+
result.error != null;
|
|
94
|
+
capture(operation, failed ? "error" : "success");
|
|
95
|
+
return result;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
capture(operation, "error");
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -31,6 +31,8 @@ Use command help and the current API contract for other operations. If login is
|
|
|
31
31
|
|
|
32
32
|
## Implement and deliver
|
|
33
33
|
|
|
34
|
+
For an existing app's platform or feature changes, use the separately installed `disposabl-reconfigure` skill. It applies local code changes without repeating account setup or publishing.
|
|
35
|
+
|
|
34
36
|
Choose a visual direction suited to the product. Read the `frontend-design` skill when available and read [app branding and visual design](references/design.md). If that skill is unavailable, proceed with the user's brief and report the limitation without blocking development.
|
|
35
37
|
|
|
36
38
|
Read [delivery checks](references/delivery.md) before native builds or delivery repairs. Aim to show a usable web preview early; first native builds can take longer. Do not promise a build deadline.
|
|
@@ -6,6 +6,8 @@ Each user has one persistent sandbox for all their apps. Each app has its own co
|
|
|
6
6
|
|
|
7
7
|
Use the connected Disposabl API/MCP tools, or `bunx --package create-disposabl-app@latest disposabl`. Remote work needs a Disposabl login but no local app directory, `disposabl.json`, or generator installation.
|
|
8
8
|
|
|
9
|
+
When payments are enabled, each agent request needs at least 10 credits. Compute costs 10 credits per 10-minute window for the shared sandbox, not per app; AI is currently included. If a request returns `credits_required`, tell the user to add credits using the server-provided payment URL. Do not open it or start checkout automatically, or include credentials in the link. If no URL is returned, report that billing setup is unavailable rather than inventing one. If `credits_unavailable` is returned, ask the user to retry. A payment before the current window ends can keep active work running; after expiry, send a new message only when the user explicitly requests it.
|
|
10
|
+
|
|
9
11
|
Before sending work, inspect the user's existing apps with `apps list` and their conversations with `agent getMessages`. Match the request to an existing app using its name, repository, and recent messages. Read that app's messages before continuing. Reuse its `appId` across chats. If two apps fit equally well, ask which one; do not guess. If this is a new app, omit `appId`.
|
|
10
12
|
|
|
11
13
|
```sh
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
beginAttempt,
|
|
5
|
+
finishAttempt,
|
|
6
|
+
hasUnknownAttempt,
|
|
7
|
+
hasPendingMonthlyAttempt,
|
|
8
|
+
resolveAttempt,
|
|
9
|
+
} from "../disposabl-kit/server/billing-functions";
|
|
10
|
+
|
|
11
|
+
test("uncertain checkout persists and prevents replay without blocking a different purchase", async () => {
|
|
12
|
+
const rows: {
|
|
13
|
+
_id: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
purchase: string;
|
|
16
|
+
requestId: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
resolvedAt?: number;
|
|
19
|
+
}[] = [];
|
|
20
|
+
const ctx = {
|
|
21
|
+
db: {
|
|
22
|
+
query: () => ({
|
|
23
|
+
withIndex: (_: string, filter: (q: any) => any) => {
|
|
24
|
+
const fields: Record<string, string | undefined> = {};
|
|
25
|
+
const q = {
|
|
26
|
+
eq: (key: string, value: string | undefined) => {
|
|
27
|
+
fields[key] = value;
|
|
28
|
+
return q;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
filter(q);
|
|
32
|
+
const matches = () =>
|
|
33
|
+
rows.filter((row) =>
|
|
34
|
+
Object.entries(fields).every(
|
|
35
|
+
([key, value]) => (row as any)[key] === value,
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
return {
|
|
39
|
+
unique: async () => matches()[0] ?? null,
|
|
40
|
+
first: async () => matches()[0] ?? null,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
insert: async (_: string, row: any) => {
|
|
45
|
+
rows.push({ ...row, _id: String(rows.length + 1) });
|
|
46
|
+
},
|
|
47
|
+
patch: async (_: string, id: string, value: { url: string }) => {
|
|
48
|
+
Object.assign(
|
|
49
|
+
rows.find((row) => row._id === id)!,
|
|
50
|
+
value,
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const begin = (purchase: string, requestId: string) =>
|
|
56
|
+
(beginAttempt as any)._handler(ctx, {
|
|
57
|
+
userId: "alice",
|
|
58
|
+
purchase,
|
|
59
|
+
requestId,
|
|
60
|
+
});
|
|
61
|
+
const pending = () =>
|
|
62
|
+
(hasUnknownAttempt as any)._handler(ctx, { userId: "alice" });
|
|
63
|
+
const monthlyPending = (userId = "alice") =>
|
|
64
|
+
(hasPendingMonthlyAttempt as any)._handler(ctx, { userId });
|
|
65
|
+
assert.equal(await monthlyPending(), false);
|
|
66
|
+
assert.equal(await begin("monthly", "one"), null);
|
|
67
|
+
assert.equal(await monthlyPending(), true);
|
|
68
|
+
assert.equal(await monthlyPending("bob"), false);
|
|
69
|
+
await assert.rejects(begin("monthly", "one"), /review/);
|
|
70
|
+
await assert.rejects(begin("monthly", "two"), /review/);
|
|
71
|
+
assert.equal(await begin("topup", "three"), null);
|
|
72
|
+
assert.equal(await pending(), true);
|
|
73
|
+
await (finishAttempt as any)._handler(ctx, {
|
|
74
|
+
userId: "alice",
|
|
75
|
+
purchase: "topup",
|
|
76
|
+
requestId: "three",
|
|
77
|
+
url: "https://checkout.example/three",
|
|
78
|
+
});
|
|
79
|
+
assert.equal(await pending(), true);
|
|
80
|
+
await (finishAttempt as any)._handler(ctx, {
|
|
81
|
+
userId: "alice",
|
|
82
|
+
purchase: "monthly",
|
|
83
|
+
requestId: "one",
|
|
84
|
+
url: "https://checkout.example/one",
|
|
85
|
+
});
|
|
86
|
+
assert.equal(await pending(), false);
|
|
87
|
+
assert.equal(await monthlyPending(), true);
|
|
88
|
+
assert.equal(await begin("monthly", "one"), "https://checkout.example/one");
|
|
89
|
+
assert.equal(await begin("monthly", "two"), "https://checkout.example/one");
|
|
90
|
+
assert.equal(
|
|
91
|
+
await begin("monthly", "another-device"),
|
|
92
|
+
"https://checkout.example/one",
|
|
93
|
+
);
|
|
94
|
+
assert.equal(rows.filter((row) => row.purchase === "monthly").length, 1);
|
|
95
|
+
await assert.rejects(
|
|
96
|
+
(resolveAttempt as any)._handler(ctx, {
|
|
97
|
+
userId: "alice",
|
|
98
|
+
requestId: "one",
|
|
99
|
+
outcome: "not_charged",
|
|
100
|
+
evidence: "Still a payable checkout link",
|
|
101
|
+
}),
|
|
102
|
+
/completed, cancelled or expired/,
|
|
103
|
+
);
|
|
104
|
+
await (resolveAttempt as any)._handler(ctx, {
|
|
105
|
+
userId: "alice",
|
|
106
|
+
requestId: "one",
|
|
107
|
+
outcome: "cancelled",
|
|
108
|
+
evidence: "Provider fixture confirms checkout cancellation",
|
|
109
|
+
});
|
|
110
|
+
assert.ok(rows[0].resolvedAt);
|
|
111
|
+
assert.equal(await monthlyPending(), false);
|
|
112
|
+
assert.deepEqual(await begin("monthly", "one"), { retryAllowed: true });
|
|
113
|
+
assert.equal(rows.length, 2);
|
|
114
|
+
assert.equal(await begin("monthly", "two"), null);
|
|
115
|
+
await assert.rejects(begin("topup", "one"), /review/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("browser retains unknown checkout identity and releases only a confirmed closed attempt", async () => {
|
|
119
|
+
const { requestCheckout } =
|
|
120
|
+
await import("../disposabl-kit/payments/checkout-attempt");
|
|
121
|
+
const values = new Map<string, string>();
|
|
122
|
+
const storage = {
|
|
123
|
+
getItem: (key: string) => values.get(key) ?? null,
|
|
124
|
+
setItem: (key: string, value: string) => {
|
|
125
|
+
values.set(key, value);
|
|
126
|
+
},
|
|
127
|
+
removeItem: (key: string) => {
|
|
128
|
+
values.delete(key);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
const ids: string[] = [];
|
|
132
|
+
let serial = 0;
|
|
133
|
+
const run = (result: "unknown" | "closed" | "url" | "pending") =>
|
|
134
|
+
requestCheckout(
|
|
135
|
+
storage,
|
|
136
|
+
"alice",
|
|
137
|
+
"monthly",
|
|
138
|
+
async ({ requestId }) => {
|
|
139
|
+
ids.push(requestId);
|
|
140
|
+
if (result === "unknown") throw new Error("Response lost");
|
|
141
|
+
if (result === "closed") return { url: null, retryAllowed: true };
|
|
142
|
+
return {
|
|
143
|
+
url: result === "url" ? "https://checkout.example/new" : null,
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
() => String(++serial),
|
|
147
|
+
);
|
|
148
|
+
await assert.rejects(run("unknown"), /Response lost/);
|
|
149
|
+
await run("pending");
|
|
150
|
+
await run("closed");
|
|
151
|
+
assert.deepEqual(ids, ["1", "1", "1"]);
|
|
152
|
+
assert.equal(values.size, 0);
|
|
153
|
+
await run("url");
|
|
154
|
+
assert.deepEqual(ids, ["1", "1", "1", "2"]);
|
|
155
|
+
assert.equal(values.size, 0);
|
|
156
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { redeem, cleanup } from "../disposabl-kit/server/billing-handoff";
|
|
4
|
+
|
|
5
|
+
test("billing handoff expires and a redeemed link cannot be replayed", async () => {
|
|
6
|
+
let row: any = {
|
|
7
|
+
_id: "one",
|
|
8
|
+
userId: "alice",
|
|
9
|
+
sessionId: "session",
|
|
10
|
+
purchase: "topup",
|
|
11
|
+
expiresAt: Date.now() + 120_000,
|
|
12
|
+
};
|
|
13
|
+
let exchanges = 0;
|
|
14
|
+
const ctx = {
|
|
15
|
+
db: {
|
|
16
|
+
query: () => ({ withIndex: () => ({ unique: async () => row }) }),
|
|
17
|
+
delete: async () => {
|
|
18
|
+
row = null;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
runMutation: async () => {
|
|
22
|
+
exchanges++;
|
|
23
|
+
return { userId: "alice" };
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const code = "Q".repeat(43);
|
|
27
|
+
const expiresAt = row.expiresAt;
|
|
28
|
+
assert.deepEqual(await (redeem as any)._handler(ctx, { code }), {
|
|
29
|
+
userId: "alice",
|
|
30
|
+
purchase: "topup",
|
|
31
|
+
expiresAt,
|
|
32
|
+
});
|
|
33
|
+
await assert.rejects((redeem as any)._handler(ctx, { code }), /expired/);
|
|
34
|
+
assert.equal(exchanges, 1);
|
|
35
|
+
row = {
|
|
36
|
+
_id: "two",
|
|
37
|
+
userId: "alice",
|
|
38
|
+
sessionId: "session",
|
|
39
|
+
expiresAt: Date.now() - 1,
|
|
40
|
+
};
|
|
41
|
+
await assert.rejects((redeem as any)._handler(ctx, { code }), /expired/);
|
|
42
|
+
await (cleanup as any)._handler(ctx, { hash: "hash" });
|
|
43
|
+
assert.equal(row, null);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("pricing requires the redeemed selection and matching account for iOS", async () => {
|
|
47
|
+
const { handoffSelection, handoffAllows } =
|
|
48
|
+
await import("../disposabl-kit/payments/checkout-attempt");
|
|
49
|
+
assert.equal(
|
|
50
|
+
handoffAllows(true, handoffSelection(null), "alice", "topup"),
|
|
51
|
+
false,
|
|
52
|
+
);
|
|
53
|
+
assert.equal(
|
|
54
|
+
handoffAllows(true, handoffSelection("1"), "alice", "topup"),
|
|
55
|
+
false,
|
|
56
|
+
);
|
|
57
|
+
const selection = handoffSelection(
|
|
58
|
+
JSON.stringify({
|
|
59
|
+
userId: "alice",
|
|
60
|
+
purchase: "topup",
|
|
61
|
+
expiresAt: Date.now() + 120000,
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
assert.equal(handoffAllows(true, selection, "alice", "topup"), true);
|
|
65
|
+
assert.equal(handoffAllows(true, selection, "bob", "topup"), false);
|
|
66
|
+
assert.equal(handoffAllows(true, selection, "alice", "monthly"), false);
|
|
67
|
+
assert.equal(handoffAllows(false, null, "alice", "topup"), true);
|
|
68
|
+
assert.equal(
|
|
69
|
+
handoffSelection(
|
|
70
|
+
JSON.stringify({
|
|
71
|
+
userId: "alice",
|
|
72
|
+
purchase: "topup",
|
|
73
|
+
expiresAt: Date.now() - 1,
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
null,
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("expired iOS selection stays restricted on a query-free pricing return", async () => {
|
|
81
|
+
const { handoffContext, handoffAllows } =
|
|
82
|
+
await import("../disposabl-kit/payments/checkout-attempt");
|
|
83
|
+
const stored = JSON.stringify({
|
|
84
|
+
userId: "alice",
|
|
85
|
+
purchase: "topup",
|
|
86
|
+
expiresAt: Date.now() - 1,
|
|
87
|
+
});
|
|
88
|
+
for (const value of [stored, "broken json", "1", "", "null"]) {
|
|
89
|
+
const returned = handoffContext(value, "");
|
|
90
|
+
assert.equal(returned.fromIos, true);
|
|
91
|
+
assert.equal(returned.handoff, null);
|
|
92
|
+
for (const purchase of ["monthly", "topup"] as const)
|
|
93
|
+
assert.equal(
|
|
94
|
+
handoffAllows(returned.fromIos, returned.handoff, "alice", purchase),
|
|
95
|
+
false,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const renewed = handoffContext(
|
|
99
|
+
JSON.stringify({
|
|
100
|
+
userId: "alice",
|
|
101
|
+
purchase: "topup",
|
|
102
|
+
expiresAt: Date.now() + 120000,
|
|
103
|
+
}),
|
|
104
|
+
"",
|
|
105
|
+
);
|
|
106
|
+
assert.equal(
|
|
107
|
+
handoffAllows(renewed.fromIos, renewed.handoff, "alice", "topup"),
|
|
108
|
+
true,
|
|
109
|
+
);
|
|
110
|
+
assert.equal(
|
|
111
|
+
handoffAllows(renewed.fromIos, renewed.handoff, "alice", "monthly"),
|
|
112
|
+
false,
|
|
113
|
+
);
|
|
114
|
+
assert.equal(handoffContext(null, "").fromIos, false);
|
|
115
|
+
assert.equal(handoffContext(null, "?source=ios").fromIos, true);
|
|
116
|
+
});
|
|
@@ -71,6 +71,7 @@ test("enabled setup needs this deployment's key and valid pricing before request
|
|
|
71
71
|
);
|
|
72
72
|
for (const config of [
|
|
73
73
|
{ ...pricing, creditsPerDollar: 0 },
|
|
74
|
+
{ ...pricing, monthly: { ...pricing.monthly, creditMultiplier: 0 } },
|
|
74
75
|
{ ...pricing, monthly: { ...pricing.monthly, price: NaN } },
|
|
75
76
|
{ ...pricing, topup: { ...pricing.topup, planId: pricing.monthly.planId } },
|
|
76
77
|
])
|
|
@@ -106,7 +107,7 @@ test("defaults create monthly included credits and nonexpiring prepaid top-ups o
|
|
|
106
107
|
items: [
|
|
107
108
|
{
|
|
108
109
|
feature_id: "credits",
|
|
109
|
-
included:
|
|
110
|
+
included: 750,
|
|
110
111
|
reset: { interval: "month" },
|
|
111
112
|
},
|
|
112
113
|
],
|
|
@@ -150,7 +151,7 @@ test("edited config drives new IDs, prices and quantities without assuming USD",
|
|
|
150
151
|
currency: "EUR",
|
|
151
152
|
featureId: "tokens",
|
|
152
153
|
creditsPerDollar: 80,
|
|
153
|
-
monthly: { planId: "custom_monthly", price: 12 },
|
|
154
|
+
monthly: { planId: "custom_monthly", price: 12, creditMultiplier: 1.25 },
|
|
154
155
|
topup: { planId: "custom_topup", price: 3 },
|
|
155
156
|
};
|
|
156
157
|
await setupBilling(true, env, config, p.fetcher);
|
|
@@ -159,7 +160,7 @@ test("edited config drives new IDs, prices and quantities without assuming USD",
|
|
|
159
160
|
interval: "month",
|
|
160
161
|
});
|
|
161
162
|
assert.deepEqual(p.plans.get("custom_monthly")?.items, [
|
|
162
|
-
{ feature_id: "tokens", included:
|
|
163
|
+
{ feature_id: "tokens", included: 1200, reset: { interval: "month" } },
|
|
163
164
|
]);
|
|
164
165
|
assert.deepEqual(p.plans.get("custom_topup")?.items, [
|
|
165
166
|
{
|
|
@@ -7,27 +7,66 @@ import {
|
|
|
7
7
|
billingRequest,
|
|
8
8
|
purchaseRequest,
|
|
9
9
|
monthlyPlanFromCustomer,
|
|
10
|
+
mobileWebCheckoutConfigured,
|
|
11
|
+
checkoutUrl,
|
|
10
12
|
} from "../disposabl-kit/server/billing";
|
|
11
13
|
import {
|
|
12
14
|
pricing,
|
|
13
15
|
creditQuantity,
|
|
14
16
|
formatPrice,
|
|
17
|
+
monthlyLabel,
|
|
15
18
|
type Pricing,
|
|
16
19
|
} from "../disposabl-kit/payments/config";
|
|
17
20
|
import { resolveFeatures } from "../disposabl-kit/feature-options";
|
|
18
21
|
|
|
19
22
|
describe("billing boundary", () => {
|
|
23
|
+
test("unusable checkout responses are treated as unknown", () => {
|
|
24
|
+
assert.equal(
|
|
25
|
+
checkoutUrl({ payment_url: "https://checkout.example/pay" }),
|
|
26
|
+
"https://checkout.example/pay",
|
|
27
|
+
);
|
|
28
|
+
for (const result of [
|
|
29
|
+
{},
|
|
30
|
+
{ payment_url: null },
|
|
31
|
+
{ payment_url: "http://example.com" },
|
|
32
|
+
{ payment_url: "https://user:pass@example.com" },
|
|
33
|
+
{ payment_url: "invalid" },
|
|
34
|
+
])
|
|
35
|
+
assert.equal(checkoutUrl(result), null);
|
|
36
|
+
});
|
|
37
|
+
test("mobile checkout capability requires a configured secure pricing origin and native sync", () => {
|
|
38
|
+
const env = {
|
|
39
|
+
AUTUMN_SECRET_KEY: "key",
|
|
40
|
+
BILLING_RETURN_URL: "https://example.com/pricing",
|
|
41
|
+
MOBILE_WEB_CHECKOUT_ENABLED: "true",
|
|
42
|
+
REVENUECAT_SYNC_ENABLED: "true",
|
|
43
|
+
};
|
|
44
|
+
assert.equal(mobileWebCheckoutConfigured(true, env), true);
|
|
45
|
+
assert.equal(mobileWebCheckoutConfigured(false, env), false);
|
|
46
|
+
for (const changes of [
|
|
47
|
+
{ MOBILE_WEB_CHECKOUT_ENABLED: "false" },
|
|
48
|
+
{ REVENUECAT_SYNC_ENABLED: "false" },
|
|
49
|
+
{ BILLING_RETURN_URL: "http://localhost/pricing" },
|
|
50
|
+
{ BILLING_RETURN_URL: "https://example.com/other" },
|
|
51
|
+
{ AUTUMN_SECRET_KEY: "" },
|
|
52
|
+
])
|
|
53
|
+
assert.equal(
|
|
54
|
+
mobileWebCheckoutConfigured(true, { ...env, ...changes }),
|
|
55
|
+
false,
|
|
56
|
+
);
|
|
57
|
+
});
|
|
20
58
|
test("editable starter prices drive server quantities and displayed allowances", () => {
|
|
21
59
|
const example: Pricing = {
|
|
22
60
|
currency: "USD",
|
|
23
61
|
creditsPerDollar: 100,
|
|
24
62
|
featureId: "credits",
|
|
25
|
-
monthly: { planId: "credits_monthly", price: 5 },
|
|
63
|
+
monthly: { planId: "credits_monthly", price: 5, creditMultiplier: 1.5 },
|
|
26
64
|
topup: { planId: "credits_topup", price: 5 },
|
|
27
65
|
};
|
|
28
66
|
assert.equal(formatPrice(example.monthly.price, example), "$5");
|
|
29
|
-
assert.equal(creditQuantity("monthly", example),
|
|
67
|
+
assert.equal(creditQuantity("monthly", example), 750);
|
|
30
68
|
assert.equal(creditQuantity("topup", example), 500);
|
|
69
|
+
assert.equal(monthlyLabel(example), "Monthly · 50% more");
|
|
31
70
|
assert.equal(
|
|
32
71
|
creditQuantity("topup", {
|
|
33
72
|
...example,
|
|
@@ -39,7 +78,11 @@ describe("billing boundary", () => {
|
|
|
39
78
|
...example,
|
|
40
79
|
featureId: "workspace_credits",
|
|
41
80
|
creditsPerDollar: 80,
|
|
42
|
-
monthly: {
|
|
81
|
+
monthly: {
|
|
82
|
+
planId: "workspace_monthly",
|
|
83
|
+
price: 12,
|
|
84
|
+
creditMultiplier: 1.25,
|
|
85
|
+
},
|
|
43
86
|
topup: { planId: "workspace_topup", price: 3 },
|
|
44
87
|
};
|
|
45
88
|
const request = purchaseRequest(
|
|
@@ -52,7 +95,8 @@ describe("billing boundary", () => {
|
|
|
52
95
|
assert.deepEqual(request.feature_quantities, [
|
|
53
96
|
{ feature_id: "workspace_credits", quantity: 240, adjustable: false },
|
|
54
97
|
]);
|
|
55
|
-
assert.equal(creditQuantity("monthly", custom),
|
|
98
|
+
assert.equal(creditQuantity("monthly", custom), 1200);
|
|
99
|
+
assert.equal(monthlyLabel(custom), "Monthly · 25% more");
|
|
56
100
|
assert.equal(formatPrice(custom.monthly.price, custom), "$12");
|
|
57
101
|
assert.equal(
|
|
58
102
|
balanceFromCustomer(
|
|
@@ -91,3 +91,57 @@ test("platform selection keeps iOS optional and sizes Android independently", ()
|
|
|
91
91
|
rmSync(dir, { recursive: true, force: true });
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
test("a macOS signing-script change selects only the enabled macOS build", () => {
|
|
96
|
+
const dir = mkdtempSync(join(tmpdir(), "disposabl-macos-selection-"));
|
|
97
|
+
try {
|
|
98
|
+
mkdirSync(join(dir, "bin"));
|
|
99
|
+
writeFileSync(join(dir, "bin/gh"), "#!/bin/sh\necho baseline\n", {
|
|
100
|
+
mode: 0o755,
|
|
101
|
+
});
|
|
102
|
+
writeFileSync(
|
|
103
|
+
join(dir, "bin/git"),
|
|
104
|
+
'#!/bin/sh\nif [ "$1" = diff ]; then echo .github/scripts/macos-release.sh; fi\n',
|
|
105
|
+
{ mode: 0o755 },
|
|
106
|
+
);
|
|
107
|
+
writeFileSync(
|
|
108
|
+
join(dir, "disposabl.json"),
|
|
109
|
+
JSON.stringify({
|
|
110
|
+
platforms: ["macos", "windows", "linux", "android", "ios"],
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
const out = join(dir, "output");
|
|
114
|
+
execFileSync(
|
|
115
|
+
"bash",
|
|
116
|
+
[resolve(import.meta.dirname, "../../.github/scripts/platforms.sh")],
|
|
117
|
+
{
|
|
118
|
+
cwd: dir,
|
|
119
|
+
env: {
|
|
120
|
+
...process.env,
|
|
121
|
+
PATH: `${join(dir, "bin")}:${process.env.PATH}`,
|
|
122
|
+
PR: "",
|
|
123
|
+
SOURCE: "current",
|
|
124
|
+
GH_REPO: "fixture/app",
|
|
125
|
+
RUNNER_TEMP: dir,
|
|
126
|
+
GITHUB_OUTPUT: out,
|
|
127
|
+
GITHUB_EVENT_NAME: "push",
|
|
128
|
+
GITHUB_REF: "refs/heads/main",
|
|
129
|
+
EXPO_CONNECTED: "true",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
const selected = Object.fromEntries(
|
|
134
|
+
readFileSync(out, "utf8")
|
|
135
|
+
.trim()
|
|
136
|
+
.split("\n")
|
|
137
|
+
.map((line) => line.split("=")),
|
|
138
|
+
);
|
|
139
|
+
assert.deepEqual(JSON.parse(selected.desktop), [
|
|
140
|
+
{ platform: "macos", runner: "macos-26" },
|
|
141
|
+
]);
|
|
142
|
+
assert.equal(selected.android, "false");
|
|
143
|
+
assert.equal(selected.ios, "false");
|
|
144
|
+
} finally {
|
|
145
|
+
rmSync(dir, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
});
|