create-disposabl-app 0.19.0 → 0.19.1

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  // ../cli/auth.ts
4
4
  import { lock } from "proper-lockfile";
5
5
  // ../cli/package.json
6
- var version = "0.19.0";
6
+ var version = "0.19.1";
7
7
  var package_default = {
8
8
  name: "@disposabl/cli",
9
9
  version,
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.19.0";
1566
+ var version = "0.19.1";
1567
1567
 
1568
1568
  // ../cli/telemetry.ts
1569
1569
  var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
@@ -9137,7 +9137,11 @@ import { existsSync } from "node:fs";
9137
9137
  import { readFile as readFile3, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
9138
9138
  import { join as join3, sep } from "node:path";
9139
9139
  var nativeBillingPath = join3("packages", "disposabl-kit", "mobile", "billing") + sep;
9140
- var nativeBillingTest = join3("packages", "tests", "native-billing.test.ts");
9140
+ var nativeBillingTests = [
9141
+ join3("packages", "tests", "native-billing.test.ts"),
9142
+ join3("packages", "tests", "mobile-storefront-observer.test.ts"),
9143
+ join3("packages", "tests", "components", "mobile-storefront-observer.test.mjs")
9144
+ ];
9141
9145
  var purchasesPackage = "react-native-purchases";
9142
9146
  var purchasesPackages = [purchasesPackage, "react-native-purchases-ui"];
9143
9147
  var dependencyFields = [
@@ -9192,7 +9196,8 @@ async function omitMobilePayments(root) {
9192
9196
  const source = await readFile3(path, "utf8");
9193
9197
  await writeFile3(path, source.replace(/^[ \t]*\/\/ payments:start\r?\n[\s\S]*?^[ \t]*\/\/ payments:end\r?\n/gm, "").replace(/^[ \t]*\{\/\* payments:start \*\/\}\r?\n[\s\S]*?^[ \t]*\{\/\* payments:end \*\/\}\r?\n/gm, ""));
9194
9198
  await rm3(join3(root, nativeBillingPath), { recursive: true, force: true });
9195
- await rm3(join3(root, nativeBillingTest), { force: true });
9199
+ for (const path of nativeBillingTests)
9200
+ await rm3(join3(root, path), { force: true });
9196
9201
  }
9197
9202
 
9198
9203
  // ../disposabl-kit/android-architectures.ts
@@ -9287,6 +9292,8 @@ For Disposabl development and delivery, read [.agents/skills/disposabl-app/SKILL
9287
9292
  await rm4(join4(tests, entry));
9288
9293
  }
9289
9294
  if (!folders.includes("apps/mobile")) {
9295
+ for (const path of nativeBillingTests)
9296
+ await rm4(join4(destination, path), { force: true });
9290
9297
  await rm4(join4(tests, "helpers/mobile-simulator"), {
9291
9298
  recursive: true,
9292
9299
  force: true
@@ -9613,7 +9620,7 @@ async function reconfigureApp(template, directory, version, options) {
9613
9620
  }
9614
9621
  }
9615
9622
  for (const path of oldFiles) {
9616
- if (nextFiles.has(path) || !(path.startsWith(nativeBillingPath) || path === nativeBillingTest || disableAuth && authStarterPaths.some((authPath) => path === authPath || path.startsWith(authPath + sep2))))
9623
+ if (nextFiles.has(path) || !(path.startsWith(nativeBillingPath) || nativeBillingTests.includes(path) || disableAuth && authStarterPaths.some((authPath) => path === authPath || path.startsWith(authPath + sep2))))
9617
9624
  continue;
9618
9625
  const current = await safeRead(directory, path);
9619
9626
  if (!current)
@@ -0,0 +1,9 @@
1
+ # Storefront observation
2
+
3
+ This local iOS Expo module invalidates cached website-checkout eligibility when StoreKit reports a storefront change. It registers a retained `SKPaymentTransactionObserver` synchronously before `start()` resolves. Its required transaction callback is intentionally empty; RevenueCat owns purchase processing.
4
+
5
+ Observation is reference-counted on the main dispatch queue. Each successful start needs a stop, and module destruction removes all remaining observation. Missing native support leaves website checkout unavailable.
6
+
7
+ StoreKit callback delivery to JavaScript is asynchronous. The billing hook also rechecks eligibility before browser handoff and cancels when an observed change invalidates that operation. These checks do not make the storefront read and browser opening atomic or monitor a checkout after the browser opens.
8
+
9
+ The queue observer API is deprecated, but provides a documented registration boundary. Do not replace it with an unawaited `Storefront.updates` task and assume observation is already active when the start call returns.
@@ -0,0 +1 @@
1
+ { "platforms": ["ios"], "ios": { "modules": ["StorefrontObserverModule"] } }
@@ -0,0 +1,15 @@
1
+ Pod::Spec.new do |s|
2
+ s.name = 'StorefrontObserver'
3
+ s.version = '1.0.0'
4
+ s.summary = 'StoreKit storefront change signal'
5
+ s.description = 'Observes StoreKit storefront changes.'
6
+ s.license = { :type => 'MIT' }
7
+ s.author = 'Disposabl'
8
+ s.homepage = 'https://expo.dev'
9
+ s.platform = :ios, '16.4'
10
+ s.swift_version = '5.9'
11
+ s.source = { :git => 'https://github.com/expo/expo.git' }
12
+ s.static_framework = true
13
+ s.dependency 'ExpoModulesCore'
14
+ s.source_files = '**/*.{h,m,swift}'
15
+ end
@@ -0,0 +1,59 @@
1
+ import ExpoModulesCore
2
+ import StoreKit
3
+
4
+ // All mutable state is confined to the main dispatch queue, including teardown.
5
+ // Registration is synchronous. RevenueCat remains the transaction owner.
6
+ private final class StorefrontObservation: NSObject, SKPaymentTransactionObserver {
7
+ private var observers = 0
8
+ private var changed: (() -> Void)?
9
+
10
+ func start(changed: @escaping () -> Void) {
11
+ dispatchPrecondition(condition: .onQueue(.main))
12
+ self.changed = changed
13
+ observers += 1
14
+ if observers == 1 { SKPaymentQueue.default().add(self) }
15
+ }
16
+
17
+ func stop(all: Bool = false) {
18
+ dispatchPrecondition(condition: .onQueue(.main))
19
+ guard observers > 0 else { return }
20
+ observers = all ? 0 : observers - 1
21
+ if observers == 0 {
22
+ SKPaymentQueue.default().remove(self)
23
+ changed = nil
24
+ }
25
+ }
26
+
27
+ func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
28
+ // Required protocol callback. Never finish, acknowledge, or modify purchases.
29
+ }
30
+
31
+ func paymentQueueDidChangeStorefront(_ queue: SKPaymentQueue) {
32
+ DispatchQueue.main.async { [weak self] in self?.changed?() }
33
+ }
34
+ }
35
+
36
+ public final class StorefrontObserverModule: Module {
37
+ private let observation = StorefrontObservation()
38
+
39
+ public func definition() -> ModuleDefinition {
40
+ Name("StorefrontObserver")
41
+ Events("onStorefrontChange")
42
+
43
+ AsyncFunction("start") { [weak self] () -> Bool in
44
+ guard let self else { return false }
45
+ self.observation.start { [weak self] in
46
+ self?.sendEvent("onStorefrontChange", [:])
47
+ }
48
+ return true
49
+ }.runOnQueue(.main)
50
+
51
+ AsyncFunction("stop") { [observation] in
52
+ observation.stop()
53
+ }.runOnQueue(.main)
54
+
55
+ OnDestroy { [observation] in
56
+ DispatchQueue.main.async { observation.stop(all: true) }
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "storefront-observer",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "description": "StoreKit storefront change signal",
6
+ "license": "MIT"
7
+ }
@@ -0,0 +1,45 @@
1
+ import { requireOptionalNativeModule } from "expo";
2
+
3
+ type Observer = {
4
+ addListener: (event: string, callback: () => void) => { remove: () => void };
5
+ start: () => Promise<boolean>;
6
+ stop: () => Promise<void>;
7
+ };
8
+
9
+ /** Subscribe before reading eligibility. Missing native support fails closed. */
10
+ export function observeStorefront(onChange: () => void) {
11
+ let removed = false;
12
+ let listener: { remove: () => void } | undefined;
13
+ let native: Observer | null = null;
14
+ try {
15
+ native = requireOptionalNativeModule<Observer>("StorefrontObserver");
16
+ if (native)
17
+ listener = native.addListener("onStorefrontChange", () => {
18
+ if (!removed) onChange();
19
+ });
20
+ } catch {
21
+ native = null;
22
+ }
23
+ const active = native;
24
+ const ready =
25
+ active && listener
26
+ ? Promise.resolve()
27
+ .then(() => active.start())
28
+ .then(async (started) => {
29
+ if (started && removed) await active.stop().catch(() => undefined);
30
+ return started && !removed;
31
+ })
32
+ .catch(() => false)
33
+ : Promise.resolve(false);
34
+ return {
35
+ ready,
36
+ remove() {
37
+ if (removed) return;
38
+ removed = true;
39
+ listener?.remove();
40
+ void ready.then((started) => {
41
+ if (started) void active?.stop().catch(() => undefined);
42
+ });
43
+ },
44
+ };
45
+ }
@@ -4,6 +4,7 @@ import { makeFunctionReference } from "convex/server";
4
4
  import { useCallback, useEffect, useRef, useState } from "react";
5
5
  import { AppState, Linking, Platform } from "react-native";
6
6
  import { billingSession } from "./session";
7
+ import { observeStorefront } from "./storefront-observer";
7
8
  import {
8
9
  guardedWebHandoff,
9
10
  paymentOptions,
@@ -43,13 +44,14 @@ export function useWebCheckout(
43
44
  const [topupAvailable, setTopupAvailable] = useState(false);
44
45
  const [busy, setBusy] = useState(false);
45
46
  const [error, setError] = useState("");
46
- const lifecycle = useRef({ sequence: 0 });
47
+ const lifecycle = useRef({ sequence: 0, observing: false, eligible: false });
47
48
  const refresh = useCallback(
48
49
  async (generation: number) => {
49
50
  const seq = ++lifecycle.current.sequence;
51
+ lifecycle.current.eligible = false;
50
52
  setAvailable(false);
51
53
  setTopupAvailable(false);
52
- if (Platform.OS !== "ios" || !key) return;
54
+ if (Platform.OS !== "ios" || !key || !lifecycle.current.observing) return;
53
55
  try {
54
56
  const latest = await snapshot();
55
57
  if (latest.customerId !== customerId) return;
@@ -96,6 +98,7 @@ export function useWebCheckout(
96
98
  seq === lifecycle.current.sequence &&
97
99
  billingSession.current(customerId, generation)
98
100
  ) {
101
+ lifecycle.current.eligible = true;
99
102
  setAvailable(value.monthly && latest.hasMonthlyPlan === false);
100
103
  setTopupAvailable(value.topup);
101
104
  }
@@ -107,25 +110,54 @@ export function useWebCheckout(
107
110
  );
108
111
  useEffect(() => {
109
112
  const state = lifecycle.current;
113
+ let active = true;
114
+ state.observing = false;
115
+ state.eligible = false;
110
116
  const update = () => void refresh(version.current);
111
- update();
112
- const listener = AppState.addEventListener("change", (state) => {
113
- if (state === "active") update();
117
+ const observer =
118
+ Platform.OS === "ios"
119
+ ? observeStorefront(() => {
120
+ state.sequence++;
121
+ state.eligible = false;
122
+ setAvailable(false);
123
+ setTopupAvailable(false);
124
+ if (state.observing) update();
125
+ })
126
+ : null;
127
+ void observer?.ready.then((ready) => {
128
+ if (!active || !ready) return;
129
+ state.observing = true;
130
+ update();
131
+ });
132
+ const listener = AppState.addEventListener("change", (next) => {
133
+ if (next === "active") update();
114
134
  });
115
135
  return () => {
136
+ active = false;
116
137
  state.sequence++;
138
+ state.observing = false;
139
+ state.eligible = false;
140
+ observer?.remove();
117
141
  listener.remove();
118
142
  };
119
143
  }, [refresh, version]);
120
144
  async function open(purchase: "monthly" | "topup" = "monthly") {
121
145
  if (
146
+ !lifecycle.current.observing ||
147
+ !lifecycle.current.eligible ||
122
148
  !(purchase === "monthly" ? available && productId : topupAvailable) ||
123
149
  !key ||
124
150
  !billingSession.beginTransaction()
125
151
  )
126
152
  return false;
127
153
  const generation = version.current;
128
- const current = () => billingSession.current(customerId, generation);
154
+ const sequence = lifecycle.current.sequence;
155
+ const sameSession = () => billingSession.current(customerId, generation);
156
+ const current = () =>
157
+ sameSession() &&
158
+ lifecycle.current.observing &&
159
+ lifecycle.current.eligible &&
160
+ lifecycle.current.sequence === sequence;
129
161
  setBusy(true);
130
162
  setError("");
131
163
  try {
@@ -193,7 +225,7 @@ export function useWebCheckout(
193
225
  return false;
194
226
  } finally {
195
227
  billingSession.endTransaction();
196
- if (current()) setBusy(false);
228
+ if (sameSession()) setBusy(false);
197
229
  }
198
230
  }
199
231
  return {
@@ -0,0 +1,241 @@
1
+ import { afterEach, expect, mock, test } from "bun:test";
2
+ import { createElement } from "react";
3
+ import { act, create } from "react-test-renderer";
4
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
5
+ const listeners = new Set();
6
+ let starts = 0,
7
+ stops = 0,
8
+ country = "USA",
9
+ current = true,
10
+ failStart = false,
11
+ missing = false,
12
+ pending,
13
+ startPending,
14
+ onStorefrontRead;
15
+ const link = {
16
+ url: `https://fixture.invalid/billing-login#${"A".repeat(43)}`,
17
+ userId: "owner",
18
+ };
19
+ const handoff = mock(async () => link);
20
+ const openURL = mock(async () => {});
21
+ const observer = {
22
+ addListener(_event, callback) {
23
+ listeners.add(callback);
24
+ return { remove: () => listeners.delete(callback) };
25
+ },
26
+ async start() {
27
+ starts++;
28
+ if (failStart) throw Error("unavailable");
29
+ return startPending ? await startPending : true;
30
+ },
31
+ async stop() {
32
+ stops++;
33
+ },
34
+ };
35
+ mock.module("expo", () => ({
36
+ requireOptionalNativeModule: () => (missing ? null : observer),
37
+ }));
38
+ mock.module("expo-constants", () => ({ default: { expoConfig: {} } }));
39
+ mock.module("convex/server", () => ({
40
+ makeFunctionReference: () => "fixture",
41
+ }));
42
+ mock.module("convex/react", () => ({ useMutation: () => handoff }));
43
+ mock.module("react-native", () => ({
44
+ Platform: { OS: "ios" },
45
+ Linking: { openURL },
46
+ AppState: { addEventListener: () => ({ remove() {} }) },
47
+ }));
48
+ mock.module("../../../packages/disposabl-kit/mobile/billing/session", () => ({
49
+ billingSession: {
50
+ current: () => current,
51
+ beginTransaction: () => true,
52
+ endTransaction: () => {},
53
+ run: async (_id, _version, _key, fn) =>
54
+ fn({
55
+ canMakePayments: async () => true,
56
+ getStorefront: async () => {
57
+ const value = pending
58
+ ? await pending
59
+ : country === "error"
60
+ ? await Promise.reject(Error("unknown"))
61
+ : country
62
+ ? { countryCode: country }
63
+ : null;
64
+ onStorefrontRead?.();
65
+ return value;
66
+ },
67
+ getCustomerInfo: async () => ({ activeSubscriptions: [] }),
68
+ getOfferings: async () => ({}),
69
+ getAppUserID: async () => "owner",
70
+ }),
71
+ },
72
+ }));
73
+ mock.module("../../../packages/disposabl-kit/mobile/billing/paywall", () => ({
74
+ monthlyOfferingId: "",
75
+ selectMonthlyOffering: () => ({}),
76
+ }));
77
+ mock.module("../../../packages/disposabl-kit/mobile/billing/topup", () => ({
78
+ matchingTopupRoute: () => false,
79
+ loadTopup: async () => null,
80
+ }));
81
+ const { useWebCheckout } =
82
+ await import("../../../packages/disposabl-kit/mobile/billing/web-checkout");
83
+ let renderer, result;
84
+ const version = { current: 1 };
85
+ const snapshot = async () => ({
86
+ customerId: "owner",
87
+ nativeSubscriptionsEnabled: true,
88
+ hasMonthlyPlan: false,
89
+ mobileWebCheckoutEnabled: true,
90
+ });
91
+ function Harness() {
92
+ result = useWebCheckout("owner", version, "key", "product", snapshot);
93
+ return null;
94
+ }
95
+ async function mount() {
96
+ await act(async () => {
97
+ renderer = create(createElement(Harness));
98
+ });
99
+ }
100
+ async function change() {
101
+ await act(async () => {
102
+ for (const listener of [...listeners]) listener();
103
+ });
104
+ }
105
+ afterEach(async () => {
106
+ await act(async () => renderer?.unmount());
107
+ starts = 0;
108
+ stops = 0;
109
+ country = "USA";
110
+ current = true;
111
+ failStart = false;
112
+ missing = false;
113
+ pending = undefined;
114
+ startPending = undefined;
115
+ onStorefrontRead = undefined;
116
+ handoff.mockReset().mockImplementation(async () => link);
117
+ openURL.mockClear();
118
+ listeners.clear();
119
+ });
120
+ test("active storefront changes and unknown/error fail closed", async () => {
121
+ await mount();
122
+ expect(result.available).toBe(true);
123
+ country = "CAN";
124
+ await change();
125
+ expect(result.available).toBe(false);
126
+ country = null;
127
+ await change();
128
+ expect(result.available).toBe(false);
129
+ country = "error";
130
+ await change();
131
+ expect(result.available).toBe(false);
132
+ country = "USA";
133
+ await change();
134
+ expect(result.available).toBe(true);
135
+ });
136
+ test("event invalidates pending eligibility and stale session results", async () => {
137
+ await mount();
138
+ let finish;
139
+ pending = new Promise((resolve) => {
140
+ finish = resolve;
141
+ });
142
+ await act(async () => {
143
+ void result.refresh();
144
+ });
145
+ expect(result.available).toBe(false);
146
+ country = "CAN";
147
+ pending = undefined;
148
+ await change();
149
+ expect(result.available).toBe(false);
150
+ await act(async () => finish({ countryCode: "USA" }));
151
+ expect(result.available).toBe(false);
152
+ current = false;
153
+ country = "USA";
154
+ await change();
155
+ expect(result.available).toBe(false);
156
+ });
157
+ test("observer start failure and cleanup fail closed", async () => {
158
+ failStart = true;
159
+ await mount();
160
+ expect(result.available).toBe(false);
161
+ expect(starts).toBe(1);
162
+ await act(async () => renderer.unmount());
163
+ expect(listeners.size).toBe(0);
164
+ expect(stops).toBe(0);
165
+ });
166
+ test("multiple mounts retain observation until each is removed", async () => {
167
+ await mount();
168
+ let second;
169
+ await act(async () => {
170
+ second = create(createElement(Harness));
171
+ });
172
+ expect(starts).toBe(2);
173
+ await act(async () => renderer.unmount());
174
+ expect(stops).toBe(1);
175
+ expect(listeners.size).toBe(1);
176
+ await act(async () => second.unmount());
177
+ expect(stops).toBe(2);
178
+ expect(listeners.size).toBe(0);
179
+ });
180
+
181
+ test("missing module and unmount during native start remain closed", async () => {
182
+ missing = true;
183
+ await mount();
184
+ expect(result.available).toBe(false);
185
+ expect(listeners.size).toBe(0);
186
+ await act(async () => renderer.unmount());
187
+ missing = false;
188
+ let finish;
189
+ startPending = new Promise((resolve) => {
190
+ finish = resolve;
191
+ });
192
+ await mount();
193
+ await act(async () => renderer.unmount());
194
+ await act(async () => finish(true));
195
+ expect(stops).toBe(1);
196
+ expect(listeners.size).toBe(0);
197
+ });
198
+
199
+ test("an unchanged US storefront opens the validated handoff", async () => {
200
+ await mount();
201
+ let opened;
202
+ await act(async () => {
203
+ opened = await result.open();
204
+ });
205
+ expect(opened).toBe(true);
206
+ expect(openURL).toHaveBeenCalledWith(link.url);
207
+ expect(result.busy).toBe(false);
208
+ });
209
+
210
+ test("a change during the final storefront read cancels the handoff and clears busy", async () => {
211
+ await mount();
212
+ handoff.mockImplementationOnce(async () => {
213
+ onStorefrontRead = () => {
214
+ onStorefrontRead = undefined;
215
+ country = "CAN";
216
+ for (const listener of [...listeners]) listener();
217
+ };
218
+ return link;
219
+ });
220
+ let opened;
221
+ await act(async () => {
222
+ opened = await result.open();
223
+ });
224
+ expect(handoff).toHaveBeenCalledTimes(1);
225
+ expect(opened).toBe(false);
226
+ expect(openURL).not.toHaveBeenCalled();
227
+ expect(result.busy).toBe(false);
228
+ expect(result.available).toBe(false);
229
+ });
230
+
231
+ test("a queued callback from a removed subscription is ignored", async () => {
232
+ const { observeStorefront } =
233
+ await import("../../../packages/disposabl-kit/mobile/billing/storefront-observer");
234
+ const changed = mock(() => {});
235
+ const subscription = observeStorefront(changed);
236
+ await subscription.ready;
237
+ const queued = [...listeners][0];
238
+ subscription.remove();
239
+ queued();
240
+ expect(changed).not.toHaveBeenCalled();
241
+ });
@@ -0,0 +1,22 @@
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("native storefront observation and eligibility races", () => {
7
+ const result = spawnSync(
8
+ process.execPath,
9
+ [
10
+ "test",
11
+ join(
12
+ import.meta.dirname,
13
+ "components/mobile-storefront-observer.test.mjs",
14
+ ),
15
+ ],
16
+ {
17
+ encoding: "utf8",
18
+ env: { ...process.env, E2E_TELEMETRY_DISABLED: "1", DO_NOT_TRACK: "1" },
19
+ },
20
+ );
21
+ assert.equal(result.status, 0, result.stdout + result.stderr);
22
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "Create a Disposabl app",
5
5
  "type": "module",
6
6
  "license": "MIT",