create-disposabl-app 0.13.3 → 0.13.4
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/.github/scripts/android-runner.sh +26 -0
- package/dist/templates/default/.github/scripts/mobile.sh +1 -0
- package/dist/templates/default/.github/scripts/platforms.sh +1 -1
- package/dist/templates/default/.github/workflows/pipeline.yml +2 -0
- package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +3 -3
- package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +8 -5
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +4 -1
- package/dist/templates/default/packages/disposabl-kit/payments/autumn.config.example +31 -6
- package/dist/templates/default/packages/disposabl-kit/payments/config.ts +32 -0
- package/dist/templates/default/packages/disposabl-kit/server/billing.ts +16 -11
- package/dist/templates/default/packages/tests/android-runner.test.ts +78 -0
- package/dist/templates/default/packages/tests/billing.test.ts +69 -5
- package/dist/templates/default/packages/tests/ci-platform-selection.test.ts +12 -0
- package/dist/templates/default/packages/tests/native-billing.test.ts +6 -3
- package/package.json +1 -1
package/dist/disposabl.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
8
8
|
import { Command, CommanderError } from "commander";
|
|
9
9
|
import * as p2 from "@clack/prompts";
|
|
10
10
|
// package.json
|
|
11
|
-
var version = "0.13.
|
|
11
|
+
var version = "0.13.4";
|
|
12
12
|
|
|
13
13
|
// ../disposabl-kit/platforms.ts
|
|
14
14
|
var platforms = [
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
case "${1:?operation required}" in
|
|
5
|
+
prepare)
|
|
6
|
+
df -h .
|
|
7
|
+
# Only disposable GitHub-hosted Linux runners. Keep Android, Java, Node,
|
|
8
|
+
# the checkout and dependency caches intact; these toolchains are unused.
|
|
9
|
+
if [[ "${GITHUB_ACTIONS:-}" == true && "${RUNNER_ENVIRONMENT:-}" == github-hosted && "${RUNNER_OS:-}" == Linux ]]; then
|
|
10
|
+
unused=(/usr/share/dotnet /usr/local/.ghcup /opt/ghc /opt/hostedtoolcache/CodeQL
|
|
11
|
+
/usr/share/swift /usr/share/miniconda /opt/microsoft/powershell /usr/local/share/powershell)
|
|
12
|
+
du -sh -- "${unused[@]}" 2>/dev/null || true
|
|
13
|
+
sudo rm -rf -- "${unused[@]}"
|
|
14
|
+
fi
|
|
15
|
+
df -h .
|
|
16
|
+
;;
|
|
17
|
+
check)
|
|
18
|
+
df -h .
|
|
19
|
+
available=$(df -Pk . | awk 'END {print $4}')
|
|
20
|
+
if [[ ! "$available" =~ ^[0-9]+$ ]] || (( available < 25 * 1024 * 1024 )); then
|
|
21
|
+
echo '::error::Android native builds require at least 25 GiB free before prebuild. Use a runner with more disk capacity.' >&2
|
|
22
|
+
exit 1
|
|
23
|
+
fi
|
|
24
|
+
;;
|
|
25
|
+
*) echo "Unknown operation: $1" >&2; exit 1 ;;
|
|
26
|
+
esac
|
|
@@ -105,6 +105,7 @@ bun x "$EAS_CLI" update --platform android --channel "$CHANNEL" --environment "$
|
|
|
105
105
|
jq --arg sha "$SHA" '. + {sha256: $sha, action: "update"}' <<< "$MANIFEST" > ../../dist/release/android.json
|
|
106
106
|
;;
|
|
107
107
|
android-build)
|
|
108
|
+
bash ../../.github/scripts/android-runner.sh check
|
|
108
109
|
MANIFEST=$(manifest)
|
|
109
110
|
test "$(gh api "repos/$GH_REPO/$SOURCE_PATH" --jq 'if has("head") then (if .state == "open" then .head.sha else "closed" end) else .object.sha end')" = "$SOURCE"
|
|
110
111
|
if [[ "$CHANNEL" == production ]]; then
|
|
@@ -38,7 +38,7 @@ node --input-type=module -e '
|
|
|
38
38
|
};
|
|
39
39
|
const shared = p => /^(bun.lock$|package.json$|disposabl.json$|turbo.json$|bunfig.toml$|patches\/|vendor\/|\.github\/(workflows\/pipeline.yml$|scripts\/(platforms.sh|disposabl.mjs|release.sh)$))/.test(p);
|
|
40
40
|
const affected = (platform, dependency) => enabled.includes(platform) && changes(platform).some(p => shared(p) || dependency.test(p));
|
|
41
|
-
const mobile = /^(apps\/mobile\/|packages\/disposabl-kit\/|\.github\/scripts\/(mobile|apple)\.sh$)/;
|
|
41
|
+
const mobile = /^(apps\/mobile\/|packages\/disposabl-kit\/|\.github\/scripts\/(mobile|apple|android-runner)\.sh$)/;
|
|
42
42
|
for (const platform of ["android", "ios"]) console.log(`${platform}=${(platform === "ios" ? process.env.IOS_BUILDS_ENABLED !== "false" : process.env.EXPO_CONNECTED === "true") && affected(platform, mobile)}`);
|
|
43
43
|
const production = process.env.GITHUB_EVENT_NAME === "push" && process.env.GITHUB_REF === "refs/heads/main";
|
|
44
44
|
const desktop = (production ? ["linux", "windows", "macos"] : []).filter(platform => affected(platform, /^apps\/desktop\//))
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
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
4
|
|
|
5
|
-
Set the Autumn environment default currency to USD and verify both prices in the provider preview. For a separate Autumn test environment, configure `AUTUMN_SECRET_KEY` and `BILLING_RETURN_URL` on that app's Convex deployment. The latter must be the absolute HTTPS URL of its `/pricing` page (HTTP localhost is allowed for development), without query or fragment. Do not store the secret in the frontend or `disposabl.json`. Set the corresponding live values separately only when ready to launch.
|
|
5
|
+
Set the Autumn environment default currency to match `payments/config.ts` (USD by default) and verify both prices in the provider preview. For a separate Autumn test environment, configure `AUTUMN_SECRET_KEY` and `BILLING_RETURN_URL` on that app's Convex deployment. The latter must be the absolute HTTPS URL of its `/pricing` page (HTTP localhost is allowed for development), without query or fragment. Do not store the secret in the frontend or `disposabl.json`. Set the corresponding live values separately only when ready to launch.
|
|
6
6
|
|
|
7
|
-
`payments/autumn.config.example` defines the `credits` consumable feature, $5 monthly plan with 500 credits per cycle, and $5 one-off prepaid top-up for 500 credits.
|
|
7
|
+
`payments/autumn.config.example` defines the `credits` consumable feature, $5 monthly plan with 500 credits per cycle, and $5 one-off prepaid top-up for 500 credits. The editable defaults live in `payments/config.ts`; checkout quantities, the web pricing page, mobile allowance text, and the Autumn example use this same configuration. Copy both files into a separate configuration project with `atmn@2.0.218` installed, naming the example `autumn.config.ts` and keeping `config.ts` alongside it. After editing prices or credits, apply the matching Autumn and store configuration before deploying the app. Changing the local file alone does not update provider prices. Preview with `atmn push` before applying to a dedicated Autumn environment. Its lists are complete: a push can delete unlisted plans and features. Review the diff and test repeated top-ups, renewals and cancellation in sandbox before taking payment. The one-off prepaid credits are documented to last forever; subscription credits reset each cycle. Autumn's docs do not establish that subscription credits survive cancellation. Do not promise that they do. The provider balance is authoritative; a redirect alone does not grant credits. This foundation does not implement usage charging.
|
|
8
8
|
|
|
9
|
-
The app calls Autumn API 2.6.0 `customers.get_or_create`, `billing.attach`, and `billing.open_customer_portal` server-side. Checkout uses
|
|
9
|
+
The app calls Autumn API 2.6.0 `customers.get_or_create`, `billing.attach`, and `billing.open_customer_portal` server-side. Checkout uses server-owned plan IDs and the top-up quantity from `payments/config.ts`. Return to pricing may precede provider synchronization; use Refresh to read Autumn again. Setup and test Stripe checkout and portal in Autumn before enabling live use.
|
|
10
10
|
|
|
11
11
|
## Native subscriptions and synchronization
|
|
12
12
|
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { useAuthToken } from "@convex-dev/auth/react";
|
|
12
12
|
import { sessionId } from "../../lib/auth-session";
|
|
13
13
|
import { paymentsEnabled } from "../../features";
|
|
14
|
+
import { pricing, creditQuantity, formatPrice } from "../../payments/config";
|
|
14
15
|
|
|
15
16
|
export const Route = createFileRoute("/_providers/pricing")({
|
|
16
17
|
component: Pricing,
|
|
@@ -154,7 +155,9 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
154
155
|
<main className="mx-auto max-w-5xl space-y-8 p-8">
|
|
155
156
|
<div>
|
|
156
157
|
<h1 className="text-3xl font-semibold">Pricing</h1>
|
|
157
|
-
<p>
|
|
158
|
+
<p>
|
|
159
|
+
{pricing.creditsPerDollar} credits per {formatPrice(1)}.
|
|
160
|
+
</p>
|
|
158
161
|
</div>
|
|
159
162
|
{isLoading ? (
|
|
160
163
|
<p>Checking your account...</p>
|
|
@@ -190,8 +193,8 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
190
193
|
<div className="grid gap-5 md:grid-cols-2">
|
|
191
194
|
<section className="rounded-lg border p-6">
|
|
192
195
|
<h2 className="text-xl font-semibold">Monthly</h2>
|
|
193
|
-
<p
|
|
194
|
-
<p>
|
|
196
|
+
<p>{formatPrice(pricing.monthly.price)} / month</p>
|
|
197
|
+
<p>{creditQuantity("monthly")} credits each billing cycle.</p>
|
|
195
198
|
<button
|
|
196
199
|
className="mt-4 rounded bg-black px-4 py-2 text-white disabled:opacity-50"
|
|
197
200
|
disabled={!session || busy || hasMonthlyPlan !== false}
|
|
@@ -204,8 +207,8 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
204
207
|
</section>
|
|
205
208
|
<section className="rounded-lg border p-6">
|
|
206
209
|
<h2 className="text-xl font-semibold">Top-up</h2>
|
|
207
|
-
<p
|
|
208
|
-
<p>
|
|
210
|
+
<p>{formatPrice(pricing.topup.price)} once</p>
|
|
211
|
+
<p>{creditQuantity("topup")} credits that do not expire.</p>
|
|
209
212
|
<button
|
|
210
213
|
className="mt-4 rounded bg-black px-4 py-2 text-white disabled:opacity-50"
|
|
211
214
|
disabled={!session || busy}
|
|
@@ -5,6 +5,7 @@ import { AppState, Linking, Platform, Text, View } from "react-native";
|
|
|
5
5
|
import type { PurchasesPackage } from "react-native-purchases";
|
|
6
6
|
import { AuthButton, styles } from "../components/auth-ui";
|
|
7
7
|
import { billingSession } from "./session";
|
|
8
|
+
import { creditQuantity } from "../../payments/config";
|
|
8
9
|
|
|
9
10
|
type Snapshot = {
|
|
10
11
|
balance: number | null;
|
|
@@ -148,7 +149,9 @@ export function AccountBilling({ customerId }: { customerId: string }) {
|
|
|
148
149
|
<Text style={styles.body}>
|
|
149
150
|
Available: {data?.balance ?? "unavailable"}
|
|
150
151
|
</Text>
|
|
151
|
-
<Text style={styles.body}>
|
|
152
|
+
<Text style={styles.body}>
|
|
153
|
+
{creditQuantity("monthly")} credits each monthly billing cycle.
|
|
154
|
+
</Text>
|
|
152
155
|
{data?.hasMonthlyPlan && (
|
|
153
156
|
<Text style={styles.body}>
|
|
154
157
|
Your monthly plan is active or scheduled.
|
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
import { atmn, feature, plan } from "atmn";
|
|
2
|
+
import { pricing, creditQuantity } from "./config";
|
|
2
3
|
|
|
3
|
-
export const credits = feature({
|
|
4
|
+
export const credits = feature({
|
|
5
|
+
featureId: pricing.featureId,
|
|
6
|
+
name: "Credits",
|
|
7
|
+
type: "metered",
|
|
8
|
+
consumable: true,
|
|
9
|
+
});
|
|
4
10
|
export const monthly = plan({
|
|
5
|
-
planId:
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
planId: pricing.monthly.planId,
|
|
12
|
+
versionSlug: "v1",
|
|
13
|
+
active: true,
|
|
14
|
+
name: "Monthly credits",
|
|
15
|
+
price: { amount: pricing.monthly.price, interval: "month" },
|
|
16
|
+
items: [{
|
|
17
|
+
featureId: credits.featureId,
|
|
18
|
+
included: creditQuantity("monthly"),
|
|
19
|
+
reset: { interval: "month" },
|
|
20
|
+
}],
|
|
8
21
|
});
|
|
9
22
|
export const topup = plan({
|
|
10
|
-
planId:
|
|
11
|
-
|
|
23
|
+
planId: pricing.topup.planId,
|
|
24
|
+
versionSlug: "v1",
|
|
25
|
+
active: true,
|
|
26
|
+
name: "Credits top-up",
|
|
27
|
+
addOn: true,
|
|
28
|
+
items: [{
|
|
29
|
+
featureId: credits.featureId,
|
|
30
|
+
price: {
|
|
31
|
+
amount: pricing.topup.price,
|
|
32
|
+
billingUnits: creditQuantity("topup"),
|
|
33
|
+
interval: "one_off",
|
|
34
|
+
billingMethod: "prepaid",
|
|
35
|
+
},
|
|
36
|
+
}],
|
|
12
37
|
});
|
|
13
38
|
export default atmn({ features: [credits], plans: [monthly, topup] });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type Pricing = {
|
|
2
|
+
currency: string;
|
|
3
|
+
creditsPerDollar: number;
|
|
4
|
+
featureId: string;
|
|
5
|
+
monthly: { planId: string; price: number };
|
|
6
|
+
topup: { planId: string; price: number };
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Editable starter example. Apply matching changes to Autumn before accepting purchases. */
|
|
10
|
+
export const pricing: Pricing = {
|
|
11
|
+
currency: "USD",
|
|
12
|
+
creditsPerDollar: 100,
|
|
13
|
+
featureId: "credits",
|
|
14
|
+
monthly: { planId: "credits_monthly", price: 5 },
|
|
15
|
+
topup: { planId: "credits_topup", price: 5 },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Purchase = "monthly" | "topup";
|
|
19
|
+
|
|
20
|
+
export function creditQuantity(purchase: Purchase, config: Pricing = pricing) {
|
|
21
|
+
// Credits are whole units; decimal prices must not leak floating-point noise.
|
|
22
|
+
return Math.round(config[purchase].price * config.creditsPerDollar);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function formatPrice(amount: number, config: Pricing = pricing) {
|
|
26
|
+
return new Intl.NumberFormat("en-US", {
|
|
27
|
+
style: "currency",
|
|
28
|
+
currency: config.currency,
|
|
29
|
+
minimumFractionDigits: 0,
|
|
30
|
+
maximumFractionDigits: 2,
|
|
31
|
+
}).format(amount);
|
|
32
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} as const;
|
|
5
|
-
export type Purchase = keyof typeof billingPlans;
|
|
1
|
+
import { pricing, creditQuantity, type Pricing } from "../payments/config";
|
|
2
|
+
|
|
3
|
+
export type { Purchase } from "../payments/config";
|
|
6
4
|
|
|
7
5
|
export function billingConfig(
|
|
8
6
|
enabled: boolean,
|
|
@@ -57,18 +55,23 @@ export async function billingRequest(
|
|
|
57
55
|
|
|
58
56
|
export function purchaseRequest(
|
|
59
57
|
customerId: string,
|
|
60
|
-
purchase:
|
|
58
|
+
purchase: string,
|
|
61
59
|
returnUrl: string,
|
|
60
|
+
config: Pricing = pricing,
|
|
62
61
|
) {
|
|
63
|
-
if (
|
|
62
|
+
if (purchase !== "monthly" && purchase !== "topup")
|
|
64
63
|
throw new Error("Invalid purchase.");
|
|
65
64
|
return {
|
|
66
65
|
customer_id: customerId,
|
|
67
|
-
plan_id:
|
|
66
|
+
plan_id: config[purchase].planId,
|
|
68
67
|
...(purchase === "topup"
|
|
69
68
|
? {
|
|
70
69
|
feature_quantities: [
|
|
71
|
-
{
|
|
70
|
+
{
|
|
71
|
+
feature_id: config.featureId,
|
|
72
|
+
quantity: creditQuantity(purchase, config),
|
|
73
|
+
adjustable: false,
|
|
74
|
+
},
|
|
72
75
|
],
|
|
73
76
|
}
|
|
74
77
|
: {}),
|
|
@@ -79,10 +82,11 @@ export function purchaseRequest(
|
|
|
79
82
|
|
|
80
83
|
export function balanceFromCustomer(
|
|
81
84
|
customer: Record<string, unknown>,
|
|
85
|
+
config: Pricing = pricing,
|
|
82
86
|
): number | null {
|
|
83
87
|
const balances = customer.balances as
|
|
84
88
|
Record<string, { remaining?: unknown }> | undefined;
|
|
85
|
-
const remaining = balances?.
|
|
89
|
+
const remaining = balances?.[config.featureId]?.remaining;
|
|
86
90
|
return typeof remaining === "number" && Number.isFinite(remaining)
|
|
87
91
|
? remaining
|
|
88
92
|
: null;
|
|
@@ -91,6 +95,7 @@ export function balanceFromCustomer(
|
|
|
91
95
|
/** Missing or unfamiliar provider data must not authorize another subscription. */
|
|
92
96
|
export function monthlyPlanFromCustomer(
|
|
93
97
|
customer: Record<string, unknown>,
|
|
98
|
+
config: Pricing = pricing,
|
|
94
99
|
): boolean | null {
|
|
95
100
|
if (!Array.isArray(customer.subscriptions)) return null;
|
|
96
101
|
let present = false;
|
|
@@ -101,7 +106,7 @@ export function monthlyPlanFromCustomer(
|
|
|
101
106
|
!["active", "scheduled"].includes(subscription.status)
|
|
102
107
|
)
|
|
103
108
|
return null;
|
|
104
|
-
if (subscription.plan_id ===
|
|
109
|
+
if (subscription.plan_id === config.monthly.planId) present = true;
|
|
105
110
|
}
|
|
106
111
|
return present;
|
|
107
112
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { mkdtempSync, writeFileSync, readFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
test("Android disk preparation only removes unused hosted-runner toolchains", () => {
|
|
9
|
+
const dir = mkdtempSync(join(tmpdir(), "android-runner-"));
|
|
10
|
+
try {
|
|
11
|
+
writeFileSync(
|
|
12
|
+
join(dir, "sudo"),
|
|
13
|
+
'#!/bin/sh\nprintf "%s\\n" "$*" >> "$CALLS"\n',
|
|
14
|
+
{ mode: 0o755 },
|
|
15
|
+
);
|
|
16
|
+
writeFileSync(join(dir, "du"), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
|
|
17
|
+
writeFileSync(
|
|
18
|
+
join(dir, "df"),
|
|
19
|
+
'#!/bin/sh\nprintf "Filesystem 1024-blocks Used Available Capacity Mounted\\n/dev/test 99999999 1 %s 1%% /\\n" "$AVAILABLE"\n',
|
|
20
|
+
{ mode: 0o755 },
|
|
21
|
+
);
|
|
22
|
+
const calls = join(dir, "calls");
|
|
23
|
+
writeFileSync(calls, "");
|
|
24
|
+
const run = (operation: string, overrides: Record<string, string> = {}) =>
|
|
25
|
+
spawnSync(
|
|
26
|
+
"bash",
|
|
27
|
+
[
|
|
28
|
+
resolve(
|
|
29
|
+
import.meta.dirname,
|
|
30
|
+
"../../.github/scripts/android-runner.sh",
|
|
31
|
+
),
|
|
32
|
+
operation,
|
|
33
|
+
],
|
|
34
|
+
{
|
|
35
|
+
encoding: "utf8",
|
|
36
|
+
env: {
|
|
37
|
+
...process.env,
|
|
38
|
+
PATH: `${dir}:${process.env.PATH}`,
|
|
39
|
+
CALLS: calls,
|
|
40
|
+
AVAILABLE: "31457280",
|
|
41
|
+
GITHUB_ACTIONS: "true",
|
|
42
|
+
RUNNER_ENVIRONMENT: "github-hosted",
|
|
43
|
+
RUNNER_OS: "Linux",
|
|
44
|
+
...overrides,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
const otherRunners: Record<string, string>[] = [
|
|
49
|
+
{ RUNNER_ENVIRONMENT: "self-hosted" },
|
|
50
|
+
{ GITHUB_ACTIONS: "false" },
|
|
51
|
+
{ RUNNER_OS: "macOS" },
|
|
52
|
+
{ RUNNER_ENVIRONMENT: "" },
|
|
53
|
+
{ GITHUB_ACTIONS: "" },
|
|
54
|
+
{ RUNNER_OS: "" },
|
|
55
|
+
];
|
|
56
|
+
for (const overrides of otherRunners) {
|
|
57
|
+
assert.equal(run("prepare", overrides).status, 0);
|
|
58
|
+
assert.equal(readFileSync(calls, "utf8"), "");
|
|
59
|
+
}
|
|
60
|
+
assert.equal(run("prepare").status, 0);
|
|
61
|
+
assert.equal(
|
|
62
|
+
readFileSync(calls, "utf8"),
|
|
63
|
+
"rm -rf -- /usr/share/dotnet /usr/local/.ghcup /opt/ghc /opt/hostedtoolcache/CodeQL /usr/share/swift /usr/share/miniconda /opt/microsoft/powershell /usr/local/share/powershell\n",
|
|
64
|
+
);
|
|
65
|
+
assert.equal(run("check").status, 0);
|
|
66
|
+
assert.equal(run("check", { AVAILABLE: "26214400" }).status, 0);
|
|
67
|
+
assert.equal(run("check", { AVAILABLE: "26214399" }).status, 1);
|
|
68
|
+
const low = run("check", { AVAILABLE: "1024" });
|
|
69
|
+
assert.equal(low.status, 1);
|
|
70
|
+
assert.match(low.stderr, /25 GiB free/);
|
|
71
|
+
assert.equal(run("check", { AVAILABLE: "invalid" }).status, 1);
|
|
72
|
+
assert.equal(run("unsupported").status, 1);
|
|
73
|
+
writeFileSync(join(dir, "sudo"), "#!/bin/sh\nexit 42\n", { mode: 0o755 });
|
|
74
|
+
assert.equal(run("prepare").status, 42);
|
|
75
|
+
} finally {
|
|
76
|
+
rmSync(dir, { recursive: true, force: true });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
@@ -4,13 +4,71 @@ import {
|
|
|
4
4
|
balanceFromCustomer,
|
|
5
5
|
billingConfig,
|
|
6
6
|
billingContext,
|
|
7
|
-
billingPlans,
|
|
8
7
|
billingRequest,
|
|
9
8
|
purchaseRequest,
|
|
9
|
+
monthlyPlanFromCustomer,
|
|
10
10
|
} from "../disposabl-kit/server/billing";
|
|
11
|
+
import {
|
|
12
|
+
pricing,
|
|
13
|
+
creditQuantity,
|
|
14
|
+
formatPrice,
|
|
15
|
+
type Pricing,
|
|
16
|
+
} from "../disposabl-kit/payments/config";
|
|
11
17
|
import { resolveFeatures } from "../disposabl-kit/feature-options";
|
|
12
18
|
|
|
13
19
|
describe("billing boundary", () => {
|
|
20
|
+
test("editable starter prices drive server quantities and displayed allowances", () => {
|
|
21
|
+
const example: Pricing = {
|
|
22
|
+
currency: "USD",
|
|
23
|
+
creditsPerDollar: 100,
|
|
24
|
+
featureId: "credits",
|
|
25
|
+
monthly: { planId: "credits_monthly", price: 5 },
|
|
26
|
+
topup: { planId: "credits_topup", price: 5 },
|
|
27
|
+
};
|
|
28
|
+
assert.equal(formatPrice(example.monthly.price, example), "$5");
|
|
29
|
+
assert.equal(creditQuantity("monthly", example), 500);
|
|
30
|
+
assert.equal(creditQuantity("topup", example), 500);
|
|
31
|
+
assert.equal(
|
|
32
|
+
creditQuantity("topup", {
|
|
33
|
+
...example,
|
|
34
|
+
topup: { ...example.topup, price: 1.1 },
|
|
35
|
+
}),
|
|
36
|
+
110,
|
|
37
|
+
);
|
|
38
|
+
const custom: Pricing = {
|
|
39
|
+
...example,
|
|
40
|
+
featureId: "workspace_credits",
|
|
41
|
+
creditsPerDollar: 80,
|
|
42
|
+
monthly: { planId: "workspace_monthly", price: 12 },
|
|
43
|
+
topup: { planId: "workspace_topup", price: 3 },
|
|
44
|
+
};
|
|
45
|
+
const request = purchaseRequest(
|
|
46
|
+
"owner",
|
|
47
|
+
"topup",
|
|
48
|
+
"https://example.com/pricing",
|
|
49
|
+
custom,
|
|
50
|
+
);
|
|
51
|
+
assert.equal(request.plan_id, "workspace_topup");
|
|
52
|
+
assert.deepEqual(request.feature_quantities, [
|
|
53
|
+
{ feature_id: "workspace_credits", quantity: 240, adjustable: false },
|
|
54
|
+
]);
|
|
55
|
+
assert.equal(creditQuantity("monthly", custom), 960);
|
|
56
|
+
assert.equal(formatPrice(custom.monthly.price, custom), "$12");
|
|
57
|
+
assert.equal(
|
|
58
|
+
balanceFromCustomer(
|
|
59
|
+
{ balances: { workspace_credits: { remaining: 37 } } },
|
|
60
|
+
custom,
|
|
61
|
+
),
|
|
62
|
+
37,
|
|
63
|
+
);
|
|
64
|
+
assert.equal(
|
|
65
|
+
monthlyPlanFromCustomer(
|
|
66
|
+
{ subscriptions: [{ plan_id: "workspace_monthly", status: "active" }] },
|
|
67
|
+
custom,
|
|
68
|
+
),
|
|
69
|
+
true,
|
|
70
|
+
);
|
|
71
|
+
});
|
|
14
72
|
test("payments requires authentication and disabled ignores credentials", () => {
|
|
15
73
|
assert.deepEqual(resolveFeatures(["payments"]), [
|
|
16
74
|
"authentication",
|
|
@@ -45,15 +103,19 @@ describe("billing boundary", () => {
|
|
|
45
103
|
"https://app.example/pricing",
|
|
46
104
|
);
|
|
47
105
|
assert.equal(monthly.customer_id, "user");
|
|
48
|
-
assert.equal(monthly.plan_id,
|
|
106
|
+
assert.equal(monthly.plan_id, pricing.monthly.planId);
|
|
49
107
|
const topup = purchaseRequest(
|
|
50
108
|
"user",
|
|
51
109
|
"topup",
|
|
52
110
|
"https://app.example/pricing",
|
|
53
111
|
);
|
|
54
|
-
assert.equal(topup.plan_id,
|
|
112
|
+
assert.equal(topup.plan_id, pricing.topup.planId);
|
|
55
113
|
assert.deepEqual(topup.feature_quantities, [
|
|
56
|
-
{
|
|
114
|
+
{
|
|
115
|
+
feature_id: pricing.featureId,
|
|
116
|
+
quantity: creditQuantity("topup"),
|
|
117
|
+
adjustable: false,
|
|
118
|
+
},
|
|
57
119
|
]);
|
|
58
120
|
assert.throws(() =>
|
|
59
121
|
purchaseRequest("user", "other" as never, "https://app.example/pricing"),
|
|
@@ -61,7 +123,9 @@ describe("billing boundary", () => {
|
|
|
61
123
|
});
|
|
62
124
|
test("reads provider balances and hides provider errors", async () => {
|
|
63
125
|
assert.equal(
|
|
64
|
-
balanceFromCustomer({
|
|
126
|
+
balanceFromCustomer({
|
|
127
|
+
balances: { [pricing.featureId]: { remaining: 750 } },
|
|
128
|
+
}),
|
|
65
129
|
750,
|
|
66
130
|
);
|
|
67
131
|
assert.equal(balanceFromCustomer({}), null);
|
|
@@ -47,6 +47,18 @@ test("iOS builds can be paused independently of Android", () => {
|
|
|
47
47
|
{ cwd: dir, env: { ...env, IOS_BUILDS_ENABLED: "true" } },
|
|
48
48
|
);
|
|
49
49
|
assert.match(readFileSync(out, "utf8"), /^ios=true$/m);
|
|
50
|
+
writeFileSync(
|
|
51
|
+
join(dir, "bin/gh"),
|
|
52
|
+
'#!/bin/sh\ncase "$*" in *pulls/1/files*) echo .github/scripts/android-runner.sh;; *) exit 1;; esac\n',
|
|
53
|
+
{ mode: 0o755 },
|
|
54
|
+
);
|
|
55
|
+
writeFileSync(out, "");
|
|
56
|
+
execFileSync(
|
|
57
|
+
"bash",
|
|
58
|
+
[resolve(import.meta.dirname, "../../.github/scripts/platforms.sh")],
|
|
59
|
+
{ cwd: dir, env },
|
|
60
|
+
);
|
|
61
|
+
assert.match(readFileSync(out, "utf8"), /^android=true$/m);
|
|
50
62
|
} finally {
|
|
51
63
|
rmSync(dir, { recursive: true, force: true });
|
|
52
64
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
3
|
import { BillingSession } from "../disposabl-kit/mobile/billing/session";
|
|
4
|
+
import { pricing } from "../disposabl-kit/payments/config";
|
|
4
5
|
import { monthlyPlanFromCustomer } from "../disposabl-kit/server/billing";
|
|
5
6
|
|
|
6
7
|
function deferred() {
|
|
@@ -18,18 +19,20 @@ test("monthly state includes scheduled plans and fails closed for unknown respon
|
|
|
18
19
|
for (const status of ["active", "scheduled"])
|
|
19
20
|
assert.equal(
|
|
20
21
|
monthlyPlanFromCustomer({
|
|
21
|
-
subscriptions: [{ plan_id:
|
|
22
|
+
subscriptions: [{ plan_id: pricing.monthly.planId, status }],
|
|
22
23
|
}),
|
|
23
24
|
true,
|
|
24
25
|
);
|
|
25
26
|
assert.equal(monthlyPlanFromCustomer({}), null);
|
|
26
27
|
assert.equal(
|
|
27
|
-
monthlyPlanFromCustomer({
|
|
28
|
+
monthlyPlanFromCustomer({
|
|
29
|
+
subscriptions: [{ planId: pricing.monthly.planId }],
|
|
30
|
+
}),
|
|
28
31
|
null,
|
|
29
32
|
);
|
|
30
33
|
assert.equal(
|
|
31
34
|
monthlyPlanFromCustomer({
|
|
32
|
-
subscriptions: [{ plan_id:
|
|
35
|
+
subscriptions: [{ plan_id: pricing.monthly.planId, status: "unknown" }],
|
|
33
36
|
}),
|
|
34
37
|
null,
|
|
35
38
|
);
|