create-disposabl-app 0.20.17 → 0.20.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/disposabl.js +1 -1
  2. package/dist/index.js +3 -1
  3. package/dist/templates/default/.github/scripts/release.sh +11 -1
  4. package/dist/templates/default/.github/workflows/pipeline.yml +1 -1
  5. package/dist/templates/default/apps/docs/content/mobile.mdx +2 -0
  6. package/dist/templates/default/apps/docs/content/publishing/apple.mdx +12 -0
  7. package/dist/templates/default/apps/docs/content/publishing/google-play.mdx +12 -0
  8. package/dist/templates/default/apps/docs/content/publishing/index.mdx +23 -0
  9. package/dist/templates/default/apps/mobile/package.json +1 -0
  10. package/dist/templates/default/apps/mobile/scripts/android-release-verify.mjs +51 -6
  11. package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +4 -0
  12. package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +48 -0
  13. package/dist/templates/default/bun.lock +8 -0
  14. package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +2 -0
  15. package/dist/templates/default/packages/disposabl-kit/client/components/cookie-consent.tsx +117 -0
  16. package/dist/templates/default/packages/disposabl-kit/client/components/legal-page.tsx +15 -0
  17. package/dist/templates/default/packages/disposabl-kit/client/styles/cookie-consent.css +54 -0
  18. package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +168 -99
  19. package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-ui.tsx +9 -21
  20. package/dist/templates/default/packages/disposabl-kit/mobile/components/settings-page.tsx +52 -20
  21. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +13 -4
  22. package/dist/templates/default/packages/disposabl-kit/package.json +7 -2
  23. package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +15 -3
  24. package/dist/templates/default/packages/disposabl-kit/server/billing-native-capability.ts +33 -6
  25. package/dist/templates/default/packages/disposabl-kit/server/billing.ts +11 -3
  26. package/dist/templates/default/packages/tests/billing.test.ts +22 -0
  27. package/dist/templates/default/packages/tests/components/mobile-account-billing.test.mjs +149 -0
  28. package/dist/templates/default/packages/tests/ios-ota.test.ts +13 -10
  29. package/dist/templates/default/packages/tests/mobile-account-billing.test.ts +19 -0
  30. package/dist/templates/default/packages/tests/native-billing.test.ts +71 -0
  31. package/dist/templates/default/packages/tests/package-release.test.ts +16 -0
  32. package/package.json +1 -1
@@ -1,12 +1,39 @@
1
1
  import { revenueCatConfigs } from "./revenuecat-contract";
2
2
 
3
- /** Expose only non-secret routing metadata after an operator verifies the integration. */
4
- export function nativeTopupRoutes(
3
+ type Environment = Record<string, string | undefined>;
4
+
5
+ /** Server-derived user IDs only; the route configuration validates the allowlist. */
6
+ export function reviewerNativeSubscriptionsEnabled(
5
7
  enabled: boolean,
6
- env: Record<string, string | undefined>,
8
+ env: Environment,
9
+ userId?: string,
7
10
  ) {
8
- if (env.REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED !== "true") return [];
9
- return (revenueCatConfigs(enabled, env) ?? []).map(
10
- ({ app, store, product }) => ({ app, store, product }),
11
+ return (
12
+ !!userId &&
13
+ (revenueCatConfigs(enabled, env) ?? []).some(
14
+ (route) =>
15
+ route.reviewerMonthly && route.reviewerCustomers?.includes(userId),
16
+ )
11
17
  );
12
18
  }
19
+
20
+ /** Expose non-secret consumable routes after verification or for a qualified test account. */
21
+ export function nativeTopupRoutes(
22
+ enabled: boolean,
23
+ env: Environment,
24
+ userId?: string,
25
+ ) {
26
+ const configs = revenueCatConfigs(enabled, env) ?? [];
27
+ const globallyVerified =
28
+ env.REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED === "true";
29
+ const eligible = reviewerNativeSubscriptionsEnabled(enabled, env, userId);
30
+ return configs
31
+ .filter(
32
+ (route) =>
33
+ !route.reviewerMonthly &&
34
+ (globallyVerified
35
+ ? !route.reviewerCustomers
36
+ : eligible && route.reviewerCustomers?.includes(userId!)),
37
+ )
38
+ .map(({ app, store, product }) => ({ app, store, product }));
39
+ }
@@ -120,9 +120,17 @@ export function balanceFromCustomer(
120
120
  customer: Record<string, unknown>,
121
121
  config: Pricing = pricing,
122
122
  ): number | null {
123
- const balances = customer.balances as
124
- Record<string, { remaining?: unknown }> | undefined;
125
- const remaining = balances?.[config.featureId]?.remaining;
123
+ const plainObject = (value: unknown): value is Record<string, unknown> =>
124
+ value !== null &&
125
+ typeof value === "object" &&
126
+ (Object.getPrototypeOf(value) === Object.prototype ||
127
+ Object.getPrototypeOf(value) === null);
128
+ const balances = customer.balances;
129
+ if (!plainObject(balances) || !Object.values(balances).every(plainObject))
130
+ return null;
131
+ if (!Object.hasOwn(balances, config.featureId)) return 0;
132
+ const remaining = (balances[config.featureId] as Record<string, unknown>)
133
+ .remaining;
126
134
  return typeof remaining === "number" && Number.isFinite(remaining)
127
135
  ? remaining
128
136
  : null;
@@ -172,6 +172,28 @@ describe("billing boundary", () => {
172
172
  }),
173
173
  750,
174
174
  );
175
+ assert.equal(balanceFromCustomer({ balances: {} }), 0);
176
+ assert.equal(
177
+ balanceFromCustomer({
178
+ balances: {
179
+ [`${pricing.featureId}_other`]: { remaining: 900 },
180
+ [`${pricing.featureId}_seats`]: { remaining: 5 },
181
+ },
182
+ }),
183
+ 0,
184
+ );
185
+ for (const balances of [
186
+ undefined,
187
+ null,
188
+ [],
189
+ "invalid",
190
+ { other: null },
191
+ { [pricing.featureId]: null },
192
+ { [pricing.featureId]: {} },
193
+ { [pricing.featureId]: { remaining: "750" } },
194
+ { [pricing.featureId]: { remaining: Infinity } },
195
+ ])
196
+ assert.equal(balanceFromCustomer({ balances }), null);
175
197
  assert.equal(balanceFromCustomer({}), null);
176
198
  const mock = (() =>
177
199
  Promise.resolve(
@@ -0,0 +1,149 @@
1
+ import { afterEach, expect, mock, test } from "bun:test";
2
+ import { createElement } from "react";
3
+ import { act, create } from "react-test-renderer";
4
+
5
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
6
+ process.env.EXPO_PUBLIC_REVENUECAT_IOS_API_KEY = "test-key";
7
+ process.env.EXPO_PUBLIC_REVENUECAT_IOS_MONTHLY_PRODUCT = "test-monthly";
8
+ let snapshotFails = false;
9
+ let offeringFails = false;
10
+ let renderer;
11
+ const snapshot = {
12
+ balance: 1000,
13
+ customerId: "customer",
14
+ hasMonthlyPlan: false,
15
+ monthlyCheckoutPending: false,
16
+ nativeSubscriptionsEnabled: true,
17
+ nativeTopupRoutes: [],
18
+ mobileWebCheckoutEnabled: false,
19
+ };
20
+ const sdk = {
21
+ canMakePayments: async () => true,
22
+ getStorefront: async () => ({ countryCode: "USA" }),
23
+ getOfferings: async () => {
24
+ if (offeringFails) throw new Error("BILLING_UNAVAILABLE");
25
+ return {
26
+ current: {
27
+ availablePackages: [
28
+ {
29
+ product: {
30
+ identifier: "test-monthly",
31
+ subscriptionPeriod: "P1M",
32
+ priceString: "$5.00",
33
+ },
34
+ },
35
+ ],
36
+ },
37
+ all: {},
38
+ };
39
+ },
40
+ };
41
+ mock.module("react-native", () => ({
42
+ AppState: { addEventListener: () => ({ remove() {} }) },
43
+ Linking: { openURL: async () => {} },
44
+ Platform: { OS: "ios" },
45
+ Pressable: "Pressable",
46
+ Text: "Text",
47
+ View: "View",
48
+ }));
49
+ const getSnapshot = async () => {
50
+ if (snapshotFails) throw new Error("backend unavailable");
51
+ return snapshot;
52
+ };
53
+ mock.module("convex/react", () => ({ useAction: () => getSnapshot }));
54
+ mock.module("../../../packages/disposabl-kit/mobile/billing/session", () => ({
55
+ billingSession: {
56
+ acquire: () => 1,
57
+ release() {},
58
+ current: () => true,
59
+ run: async (_id, _version, _key, action) => action(sdk),
60
+ },
61
+ }));
62
+ mock.module(
63
+ "../../../packages/disposabl-kit/mobile/billing/web-checkout",
64
+ () => ({
65
+ useWebCheckout: () => ({
66
+ available: false,
67
+ topupAvailable: false,
68
+ busy: false,
69
+ open: async () => {},
70
+ error: "",
71
+ }),
72
+ }),
73
+ );
74
+ mock.module("../../../packages/disposabl-kit/mobile/billing/use-topup", () => ({
75
+ useTopup: () => ({
76
+ product: null,
77
+ busy: false,
78
+ purchase: async () => {},
79
+ message: "",
80
+ }),
81
+ }));
82
+ const { AccountBilling } =
83
+ await import("../../../packages/disposabl-kit/mobile/billing/account-billing");
84
+ const mount = async () => {
85
+ await act(async () => {
86
+ renderer = create(
87
+ createElement(AccountBilling, { customerId: "customer" }),
88
+ );
89
+ });
90
+ };
91
+ const texts = () =>
92
+ renderer.root
93
+ .findAllByType("Text")
94
+ .flatMap((node) => [
95
+ node.children
96
+ .filter(
97
+ (child) => typeof child === "string" || typeof child === "number",
98
+ )
99
+ .join(""),
100
+ ]);
101
+ const contains = (text) => texts().some((value) => value.includes(text));
102
+ const refresh = async () => {
103
+ const button = renderer.root
104
+ .findAllByType("Pressable")
105
+ .find((node) =>
106
+ node
107
+ .findAllByType("Text")
108
+ .some((text) => text.children.includes("Refresh")),
109
+ );
110
+ expect(button).toBeDefined();
111
+ await act(async () => {
112
+ button.props.onPress();
113
+ });
114
+ };
115
+ afterEach(async () => {
116
+ await act(async () => renderer?.unmount());
117
+ renderer = undefined;
118
+ snapshotFails = false;
119
+ offeringFails = false;
120
+ });
121
+
122
+ test("a store offerings failure preserves a verified balance and does not offer a purchase", async () => {
123
+ offeringFails = true;
124
+ await mount();
125
+ expect(contains("1,000 credits")).toBe(true);
126
+ expect(contains("Store subscriptions unavailable.")).toBe(true);
127
+ expect(contains("750 credits / month")).toBe(false);
128
+ });
129
+
130
+ test("a failed backend refresh clears a previously verified balance and offering", async () => {
131
+ await mount();
132
+ expect(contains("1,000 credits")).toBe(true);
133
+ expect(contains("750 credits / month")).toBe(true);
134
+ snapshotFails = true;
135
+ await refresh();
136
+ expect(contains("1,000 credits")).toBe(false);
137
+ expect(contains("Unavailable")).toBe(true);
138
+ expect(contains("750 credits / month")).toBe(false);
139
+ });
140
+
141
+ test("refresh recovers balance and offering when the store comes back", async () => {
142
+ offeringFails = true;
143
+ await mount();
144
+ offeringFails = false;
145
+ await refresh();
146
+ expect(contains("1,000 credits")).toBe(true);
147
+ expect(contains("750 credits / month")).toBe(true);
148
+ expect(contains("$5.00 / mo")).toBe(true);
149
+ });
@@ -167,21 +167,24 @@ test("iOS reuses only a matching finished production binary", async () => {
167
167
  assert.match(result.trace, /"--build-profile","ios-production"/);
168
168
  assert.match(result.trace, /"--channel","production"/);
169
169
  assert.match(result.trace, /"--app-identifier","app.test"/);
170
- for (const candidate of [
171
- null,
172
- { ...build, runtime: { version: "different" } },
173
- { ...build, isForIosSimulator: true },
174
- { ...build, app: { id: "other" } },
175
- { ...build, updateChannel: { name: "preview" } },
176
- { ...build, artifacts: {} },
177
- ]) {
170
+ });
171
+
172
+ for (const [reason, candidate] of [
173
+ ["no binary", null],
174
+ ["different runtime", { ...build, runtime: { version: "different" } }],
175
+ ["simulator", { ...build, isForIosSimulator: true }],
176
+ ["different project", { ...build, app: { id: "other" } }],
177
+ ["preview channel", { ...build, updateChannel: { name: "preview" } }],
178
+ ["missing archive", { ...build, artifacts: {} }],
179
+ ] as const) {
180
+ test(`iOS requests a build for ${reason}`, async () => {
178
181
  const mismatch = await run("ota-plan", {
179
182
  BUILDS: JSON.stringify(candidate ? [candidate] : []),
180
183
  });
181
184
  assert.equal(mismatch.status, 0, mismatch.stderr);
182
185
  assert.match(mismatch.output, /action=build/);
183
- }
184
- });
186
+ });
187
+ }
185
188
 
186
189
  test("iOS build lookup errors do not trigger a replacement build", async () => {
187
190
  for (const values of [
@@ -0,0 +1,19 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { spawnSync } from "node:child_process";
4
+ import { join } from "node:path";
5
+
6
+ test("mobile billing preserves the balance across store failures", () => {
7
+ const result = spawnSync(
8
+ process.execPath,
9
+ [
10
+ "test",
11
+ join(import.meta.dirname, "components/mobile-account-billing.test.mjs"),
12
+ ],
13
+ {
14
+ encoding: "utf8",
15
+ env: { ...process.env, E2E_TELEMETRY_DISABLED: "1", DO_NOT_TRACK: "1" },
16
+ },
17
+ );
18
+ assert.equal(result.status, 0, result.stdout + result.stderr);
19
+ });
@@ -1,3 +1,4 @@
1
+ import { creditQuantity } from "../disposabl-kit/payments/config";
1
2
  import { test } from "node:test";
2
3
  import assert from "node:assert/strict";
3
4
  import { BillingSession } from "../disposabl-kit/mobile/billing/session";
@@ -845,3 +846,73 @@ test("web handoff rechecks the storefront and account after link creation", asyn
845
846
  );
846
847
  }
847
848
  });
849
+
850
+ test("reviewer qualification exposes only configured top-ups to the authenticated allowlist", async () => {
851
+ const { nativeTopupRoutes, reviewerNativeSubscriptionsEnabled } =
852
+ await import("../disposabl-kit/server/billing-native-capability");
853
+ const reviewer = "a".repeat(32);
854
+ const env = {
855
+ REVENUECAT_CONSUMABLE_OWNER: "custom",
856
+ REVENUECAT_WEBHOOK_AUTH: "fixture",
857
+ REVENUECAT_PROJECT_ID: "project",
858
+ AUTUMN_SECRET_KEY: "am_sk_live_fixture",
859
+ REVENUECAT_ENVIRONMENT: "PRODUCTION",
860
+ REVENUECAT_ROUTES: JSON.stringify([
861
+ { app: "apple", store: "APP_STORE", product: "coins" },
862
+ ]),
863
+ REVENUECAT_MANAGED_MONTHLY_ROUTES: JSON.stringify([
864
+ { app: "apple", store: "APP_STORE", product: "monthly" },
865
+ ]),
866
+ REVENUECAT_REVIEWER_USERS: JSON.stringify([reviewer]),
867
+ };
868
+ const expected = [{ app: "apple", store: "APP_STORE", product: "coins" }];
869
+ assert.equal(reviewerNativeSubscriptionsEnabled(true, env, reviewer), true);
870
+ assert.deepEqual(nativeTopupRoutes(true, env, reviewer), expected);
871
+ for (const userId of [
872
+ undefined,
873
+ "b".repeat(32),
874
+ "",
875
+ "$RCAnonymousID:foreign",
876
+ ]) {
877
+ assert.equal(reviewerNativeSubscriptionsEnabled(true, env, userId), false);
878
+ assert.deepEqual(nativeTopupRoutes(true, env, userId), []);
879
+ }
880
+ for (const changes of [
881
+ { REVENUECAT_ROUTES: "[]" },
882
+ { REVENUECAT_REVIEWER_USERS: "bad" },
883
+ { REVENUECAT_WEBHOOK_AUTH: "" },
884
+ { REVENUECAT_MANAGED_MONTHLY_ROUTES: "[]" },
885
+ ]) {
886
+ assert.equal(
887
+ reviewerNativeSubscriptionsEnabled(
888
+ true,
889
+ { ...env, ...changes },
890
+ reviewer,
891
+ ),
892
+ false,
893
+ );
894
+ assert.deepEqual(
895
+ nativeTopupRoutes(true, { ...env, ...changes }, reviewer),
896
+ [],
897
+ );
898
+ }
899
+ assert.equal(reviewerNativeSubscriptionsEnabled(false, env, reviewer), false);
900
+ assert.deepEqual(
901
+ nativeTopupRoutes(
902
+ true,
903
+ { ...env, REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED: "true" },
904
+ "b".repeat(32),
905
+ ),
906
+ expected,
907
+ );
908
+ assert.deepEqual(
909
+ nativeTopupRoutes(
910
+ true,
911
+ { ...env, REVENUECAT_CONSUMABLE_INTEGRATION_VERIFIED: "true" },
912
+ reviewer,
913
+ ),
914
+ expected,
915
+ );
916
+ assert.equal(creditQuantity("monthly"), 750);
917
+ assert.equal(creditQuantity("topup"), 500);
918
+ });
@@ -17,6 +17,7 @@ function release(options: {
17
17
  prepared?: string;
18
18
  available?: string;
19
19
  failure?: boolean;
20
+ visibleAfter?: number;
20
21
  }) {
21
22
  const directory = mkdtempSync(join(tmpdir(), "package-release-"));
22
23
  try {
@@ -49,9 +50,12 @@ fi`,
49
50
  executable(
50
51
  "npm",
51
52
  `echo "npm $*" >> calls
53
+ count=$(grep -c "^npm " calls)
54
+ (( count > VISIBLE_AFTER )) || exit 1
52
55
  [[ -n "$AVAILABLE" ]] || { echo 'E404 or registry unavailable' >&2; exit 1; }
53
56
  printf '%s\\n' "$AVAILABLE"`,
54
57
  );
58
+ executable("sleep", ":");
55
59
  executable(
56
60
  "node",
57
61
  `if [[ "$1" == -p ]]; then
@@ -73,6 +77,7 @@ fi`,
73
77
  PREPARED: options.prepared ?? "",
74
78
  AVAILABLE: options.available ?? "",
75
79
  FAIL_RELEASE: String(options.failure ?? false),
80
+ VISIBLE_AFTER: String(options.visibleAfter ?? 0),
76
81
  },
77
82
  });
78
83
  const calls = join(directory, "calls");
@@ -126,3 +131,14 @@ test("a mismatched registry version cannot report ready", () => {
126
131
  assert.match(result.calls, /no matching published version/);
127
132
  assert.doesNotMatch(result.calls, / ready /);
128
133
  });
134
+
135
+ test("new publication waits for delayed registry visibility", () => {
136
+ const result = release({
137
+ prepared: "1.0.0",
138
+ available: "1.0.0",
139
+ visibleAfter: 2,
140
+ });
141
+ assert.equal(result.status, 0, result.stderr);
142
+ assert.equal((result.calls.match(/npm view/g) ?? []).length, 3);
143
+ assert.match(result.calls, /report typescript-sdk ready version=1\.0\.0/);
144
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.20.17",
3
+ "version": "0.20.18",
4
4
  "description": "Create a Disposabl app",
5
5
  "type": "module",
6
6
  "license": "MIT",