create-disposabl-app 0.18.1 → 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 +1 -1
- package/dist/index.js +11 -4
- package/dist/templates/default/.github/scripts/release.sh +12 -6
- package/dist/templates/default/.github/workflows/pipeline.yml +1 -538
- package/dist/templates/default/apps/mobile/eas.json +3 -1
- package/dist/templates/default/apps/mobile/modules/storefront-observer/README.md +9 -0
- package/dist/templates/default/apps/mobile/modules/storefront-observer/expo-module.config.json +1 -0
- package/dist/templates/default/apps/mobile/modules/storefront-observer/ios/StorefrontObserver.podspec +15 -0
- package/dist/templates/default/apps/mobile/modules/storefront-observer/ios/StorefrontObserverModule.swift +59 -0
- package/dist/templates/default/apps/mobile/modules/storefront-observer/package.json +7 -0
- package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +61 -15
- package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +1 -1
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.api-keys.tsx +2 -1
- package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry-lease.ts +8 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +53 -7
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/storefront-observer.ts +45 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +39 -7
- package/dist/templates/default/packages/tests/android-failure-workflow.test.ts +10 -4
- package/dist/templates/default/packages/tests/billing-setup-hooks.test.ts +17 -6
- package/dist/templates/default/packages/tests/components/mobile-storefront-observer.test.mjs +241 -0
- package/dist/templates/default/packages/tests/mobile-storefront-observer.test.ts +22 -0
- package/dist/templates/default/packages/tests/package-release.test.ts +121 -0
- package/dist/templates/default/packages/tests/ui-telemetry-lease.test.ts +46 -0
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -23,19 +23,31 @@ function run(command, args, options = {}) {
|
|
|
23
23
|
const packageId = required("PLAY_PACKAGE_ID");
|
|
24
24
|
if (!/^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$/.test(packageId))
|
|
25
25
|
throw new Error("Invalid Play package ID");
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const rawPlayCert = env.PLAY_UPLOAD_CERT_SHA256 || "";
|
|
27
|
+
const playCert = rawPlayCert.replaceAll(":", "").toUpperCase();
|
|
28
|
+
if (
|
|
29
|
+
rawPlayCert &&
|
|
30
|
+
!/^(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){31})$/.test(
|
|
31
|
+
rawPlayCert,
|
|
32
|
+
)
|
|
33
|
+
)
|
|
30
34
|
throw new Error("Invalid upload certificate SHA256");
|
|
31
|
-
const
|
|
32
|
-
const previous = required("PLAY_PREVIOUS_VERSION_CODE");
|
|
35
|
+
const rawPlayCertSha1 = env.PLAY_UPLOAD_CERT_SHA1 || "";
|
|
33
36
|
if (
|
|
34
|
-
|
|
35
|
-
!/^(0|[
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
rawPlayCertSha1 &&
|
|
38
|
+
!/^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){19})$/.test(
|
|
39
|
+
rawPlayCertSha1,
|
|
40
|
+
)
|
|
38
41
|
)
|
|
42
|
+
throw new Error("Invalid upload certificate SHA1");
|
|
43
|
+
const playCertSha1 = rawPlayCertSha1.replaceAll(":", "").toUpperCase();
|
|
44
|
+
const version = required("DISPOSABL_ANDROID_VERSION_CODE");
|
|
45
|
+
const previous = env.PLAY_PREVIOUS_VERSION_CODE || "";
|
|
46
|
+
if (!/^[1-9]\d*$/.test(version) || BigInt(version) > 2100000000n)
|
|
47
|
+
throw new Error("Invalid candidate version code");
|
|
48
|
+
if (previous && !/^(0|[1-9]\d*)$/.test(previous))
|
|
49
|
+
throw new Error("Invalid previous Play version code");
|
|
50
|
+
if (previous && BigInt(version) <= BigInt(previous))
|
|
39
51
|
throw new Error(
|
|
40
52
|
"Version code must be greater than the verified Play version code",
|
|
41
53
|
);
|
|
@@ -80,7 +92,21 @@ const keyInfo = run(
|
|
|
80
92
|
],
|
|
81
93
|
{ env: { ...env, LANG: "C", LC_ALL: "C" } },
|
|
82
94
|
);
|
|
83
|
-
|
|
95
|
+
const signingCert = fingerprint(keyInfo);
|
|
96
|
+
if (playCertSha1) {
|
|
97
|
+
const values = [
|
|
98
|
+
...keyInfo.matchAll(
|
|
99
|
+
/^\s*SHA1:\s*((?:[0-9a-fA-F]{2}:){19}[0-9a-fA-F]{2})\s*$/gm,
|
|
100
|
+
),
|
|
101
|
+
];
|
|
102
|
+
if (values.length !== 1)
|
|
103
|
+
throw new Error("Expected exactly one SHA1 certificate fingerprint");
|
|
104
|
+
if (values[0][1].replaceAll(":", "").toUpperCase() !== playCertSha1)
|
|
105
|
+
throw new Error(
|
|
106
|
+
"Keystore certificate SHA1 does not match supplied Play upload certificate",
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (playCert && signingCert !== playCert)
|
|
84
110
|
throw new Error(
|
|
85
111
|
"Keystore certificate does not match verified Play upload certificate",
|
|
86
112
|
);
|
|
@@ -92,7 +118,7 @@ if (
|
|
|
92
118
|
String(config.android?.versionCode) !== version
|
|
93
119
|
)
|
|
94
120
|
throw new Error(
|
|
95
|
-
"Expo package or version does not match
|
|
121
|
+
"Expo package or candidate version does not match requested inputs",
|
|
96
122
|
);
|
|
97
123
|
const architectures = config.extra?.disposablAndroidArchitectures;
|
|
98
124
|
if (
|
|
@@ -127,7 +153,7 @@ if (
|
|
|
127
153
|
!gradle.includes(`versionCode ${version}\n`)
|
|
128
154
|
)
|
|
129
155
|
throw new Error(
|
|
130
|
-
"Fresh Android project does not match
|
|
156
|
+
"Fresh Android project does not match requested package and candidate version",
|
|
131
157
|
);
|
|
132
158
|
run(
|
|
133
159
|
"./gradlew",
|
|
@@ -169,8 +195,28 @@ const verified = verifyBundle({
|
|
|
169
195
|
packageId,
|
|
170
196
|
version,
|
|
171
197
|
architectures,
|
|
172
|
-
expectedCert,
|
|
198
|
+
expectedCert: signingCert,
|
|
173
199
|
bundletool: required("BUNDLETOOL_JAR"),
|
|
174
200
|
production: true,
|
|
175
201
|
});
|
|
176
|
-
|
|
202
|
+
const { uploadCertificateSha256: _certificate, ...bundleResult } = verified;
|
|
203
|
+
console.log(
|
|
204
|
+
JSON.stringify(
|
|
205
|
+
{
|
|
206
|
+
...bundleResult,
|
|
207
|
+
signingCertificateSha256: signingCert,
|
|
208
|
+
signingCertificateSource: "selected keystore",
|
|
209
|
+
playUploadCertificate: playCert
|
|
210
|
+
? "matched supplied fingerprint"
|
|
211
|
+
: "unchecked",
|
|
212
|
+
playUploadCertificateSha1: playCertSha1
|
|
213
|
+
? "matched supplied fingerprint"
|
|
214
|
+
: "unchecked",
|
|
215
|
+
playPreviousVersion: previous
|
|
216
|
+
? "checked against supplied version"
|
|
217
|
+
: "unchecked",
|
|
218
|
+
},
|
|
219
|
+
null,
|
|
220
|
+
2,
|
|
221
|
+
),
|
|
222
|
+
);
|
|
@@ -39,7 +39,7 @@ function ApiKeys() {
|
|
|
39
39
|
className="flex gap-2"
|
|
40
40
|
onSubmit={async (event) => {
|
|
41
41
|
event.preventDefault();
|
|
42
|
-
if (pending) return;
|
|
42
|
+
if (pending || !name.trim() || key) return;
|
|
43
43
|
setPending(true);
|
|
44
44
|
setError(undefined);
|
|
45
45
|
try {
|
|
@@ -130,6 +130,7 @@ function ApiKeys() {
|
|
|
130
130
|
variant="outline"
|
|
131
131
|
disabled={pending}
|
|
132
132
|
onClick={async () => {
|
|
133
|
+
if (pending) return;
|
|
133
134
|
setPending(true);
|
|
134
135
|
setError(undefined);
|
|
135
136
|
try {
|
|
@@ -113,6 +113,8 @@ export function createTelemetryLeaseController(options: {
|
|
|
113
113
|
signal: controller.signal,
|
|
114
114
|
},
|
|
115
115
|
);
|
|
116
|
+
if (epoch !== generation) return;
|
|
117
|
+
if (response.status === 401) anonymousId = undefined;
|
|
116
118
|
retryable = response.status === 429 || response.status >= 500;
|
|
117
119
|
if (!response.ok || response.status !== 200)
|
|
118
120
|
throw new Error("bootstrap unavailable");
|
|
@@ -147,10 +149,15 @@ export function createTelemetryLeaseController(options: {
|
|
|
147
149
|
if (unchanged && options.adapter.renew) {
|
|
148
150
|
options.adapter.renew(bounded);
|
|
149
151
|
} else {
|
|
150
|
-
if (active)
|
|
152
|
+
if (active) {
|
|
153
|
+
active = false;
|
|
154
|
+
options.adapter.stop();
|
|
155
|
+
if (epoch !== generation) return;
|
|
156
|
+
}
|
|
151
157
|
active = true;
|
|
152
158
|
options.adapter.start(bounded);
|
|
153
159
|
}
|
|
160
|
+
if (epoch !== generation) return;
|
|
154
161
|
failures = 0;
|
|
155
162
|
activeLease = bounded;
|
|
156
163
|
anonymousId = lease.anonymousId;
|
|
@@ -60,7 +60,14 @@ const portal = makeFunctionReference<
|
|
|
60
60
|
{ url: string }
|
|
61
61
|
>("billing:portal");
|
|
62
62
|
|
|
63
|
-
export
|
|
63
|
+
export type BillingAttempt =
|
|
64
|
+
| "billing_monthly_checkout_attempt"
|
|
65
|
+
| "billing_topup_checkout_attempt"
|
|
66
|
+
| "billing_portal_attempt";
|
|
67
|
+
|
|
68
|
+
export function Pricing({
|
|
69
|
+
onAttempt,
|
|
70
|
+
}: { onAttempt?: (attempt: BillingAttempt) => void } = {}) {
|
|
64
71
|
if (!paymentsEnabled)
|
|
65
72
|
return (
|
|
66
73
|
<section className="mx-auto max-w-5xl p-8">
|
|
@@ -68,13 +75,23 @@ export function Pricing() {
|
|
|
68
75
|
<SubscriptionHelp />
|
|
69
76
|
</section>
|
|
70
77
|
);
|
|
71
|
-
return <SessionPricing />;
|
|
78
|
+
return <SessionPricing onAttempt={onAttempt} />;
|
|
72
79
|
}
|
|
73
|
-
function SessionPricing(
|
|
80
|
+
function SessionPricing({
|
|
81
|
+
onAttempt,
|
|
82
|
+
}: {
|
|
83
|
+
onAttempt?: (attempt: BillingAttempt) => void;
|
|
84
|
+
}) {
|
|
74
85
|
const token = useAuthToken();
|
|
75
86
|
const { isAuthenticated, isLoading } = useConvexAuth();
|
|
76
87
|
const session = !isLoading && isAuthenticated ? sessionId(token) : null;
|
|
77
|
-
return
|
|
88
|
+
return (
|
|
89
|
+
<PurchasePage
|
|
90
|
+
key={session ?? "signed-out"}
|
|
91
|
+
session={session}
|
|
92
|
+
onAttempt={onAttempt}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
78
95
|
}
|
|
79
96
|
function SubscriptionHelp() {
|
|
80
97
|
return (
|
|
@@ -99,7 +116,13 @@ function SubscriptionHelp() {
|
|
|
99
116
|
</p>
|
|
100
117
|
);
|
|
101
118
|
}
|
|
102
|
-
function PurchasePage({
|
|
119
|
+
function PurchasePage({
|
|
120
|
+
session,
|
|
121
|
+
onAttempt,
|
|
122
|
+
}: {
|
|
123
|
+
session: string | null;
|
|
124
|
+
onAttempt?: (attempt: BillingAttempt) => void;
|
|
125
|
+
}) {
|
|
103
126
|
const identity = useConsentIdentity();
|
|
104
127
|
const [{ handoff, fromIos }] = useState(() =>
|
|
105
128
|
typeof window === "undefined"
|
|
@@ -130,6 +153,7 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
130
153
|
const [message, setMessage] = useState("");
|
|
131
154
|
const [refreshError, setRefreshError] = useState("");
|
|
132
155
|
const [busy, setBusy] = useState(false);
|
|
156
|
+
const inFlight = useRef(false);
|
|
133
157
|
const generation = useRef(0);
|
|
134
158
|
const refreshSequence = useRef(0);
|
|
135
159
|
useLayoutEffect(() => {
|
|
@@ -172,12 +196,24 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
172
196
|
!session ||
|
|
173
197
|
!customerId ||
|
|
174
198
|
busy ||
|
|
199
|
+
inFlight.current ||
|
|
200
|
+
(kind === "monthly" && hasMonthlyPlan !== false) ||
|
|
175
201
|
!handoffAllows(fromIos, handoff, customerId, kind)
|
|
176
202
|
)
|
|
177
203
|
return;
|
|
178
204
|
const version = generation.current;
|
|
205
|
+
inFlight.current = true;
|
|
179
206
|
setBusy(true);
|
|
180
207
|
setMessage("");
|
|
208
|
+
try {
|
|
209
|
+
onAttempt?.(
|
|
210
|
+
kind === "monthly"
|
|
211
|
+
? "billing_monthly_checkout_attempt"
|
|
212
|
+
: "billing_topup_checkout_attempt",
|
|
213
|
+
);
|
|
214
|
+
} catch {
|
|
215
|
+
/* Reporting must not interrupt checkout. */
|
|
216
|
+
}
|
|
181
217
|
try {
|
|
182
218
|
const result = await requestCheckout(
|
|
183
219
|
localStorage,
|
|
@@ -205,19 +241,29 @@ function PurchasePage({ session }: { session: string | null }) {
|
|
|
205
241
|
);
|
|
206
242
|
await refresh();
|
|
207
243
|
} finally {
|
|
208
|
-
if (version === generation.current)
|
|
244
|
+
if (version === generation.current) {
|
|
245
|
+
inFlight.current = false;
|
|
246
|
+
setBusy(false);
|
|
247
|
+
}
|
|
209
248
|
}
|
|
210
249
|
}
|
|
211
250
|
async function manage() {
|
|
212
|
-
if (!session || busy) return;
|
|
251
|
+
if (!session || busy || inFlight.current) return;
|
|
213
252
|
const version = generation.current;
|
|
253
|
+
inFlight.current = true;
|
|
214
254
|
setBusy(true);
|
|
255
|
+
try {
|
|
256
|
+
onAttempt?.("billing_portal_attempt");
|
|
257
|
+
} catch {
|
|
258
|
+
/* Reporting must not interrupt billing. */
|
|
259
|
+
}
|
|
215
260
|
try {
|
|
216
261
|
const result = await openPortal({});
|
|
217
262
|
if (version === generation.current) window.location.assign(result.url);
|
|
218
263
|
} catch {
|
|
219
264
|
if (version !== generation.current) return;
|
|
220
265
|
setMessage("Unable to open billing settings. Please try again.");
|
|
266
|
+
inFlight.current = false;
|
|
221
267
|
setBusy(false);
|
|
222
268
|
}
|
|
223
269
|
}
|
|
@@ -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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
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 (
|
|
228
|
+
if (sameSession()) setBusy(false);
|
|
197
229
|
}
|
|
198
230
|
}
|
|
199
231
|
return {
|
|
@@ -20,7 +20,7 @@ const workflow = JSON.parse(
|
|
|
20
20
|
),
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
test("Android uses its selected runner while
|
|
23
|
+
test("Android uses its selected runner while allowing native build and cache finalization", () => {
|
|
24
24
|
assert.equal(
|
|
25
25
|
workflow.jobs.changes.outputs.android_runner,
|
|
26
26
|
"${{ steps.platforms.outputs.android_runner }}",
|
|
@@ -29,7 +29,7 @@ test("Android uses its selected runner while retaining the twenty-minute limit",
|
|
|
29
29
|
workflow.jobs.android["runs-on"],
|
|
30
30
|
"${{ needs.changes.outputs.android_runner }}",
|
|
31
31
|
);
|
|
32
|
-
assert.equal(workflow.jobs.android["timeout-minutes"],
|
|
32
|
+
assert.equal(workflow.jobs.android["timeout-minutes"], 30);
|
|
33
33
|
assert.equal(
|
|
34
34
|
workflow.jobs.web["runs-on"],
|
|
35
35
|
"${{ needs.changes.outputs.linux_runner }}",
|
|
@@ -38,10 +38,16 @@ test("Android uses its selected runner while retaining the twenty-minute limit",
|
|
|
38
38
|
|
|
39
39
|
test("Android failure reporting handles failed and cancelled builds independently", () => {
|
|
40
40
|
const job = workflow.jobs["android-failure"];
|
|
41
|
-
|
|
41
|
+
const hasPlayJob = !!workflow.jobs["android-play"];
|
|
42
|
+
assert.deepEqual(
|
|
43
|
+
job.needs,
|
|
44
|
+
hasPlayJob ? ["android", "android-play"] : "android",
|
|
45
|
+
);
|
|
42
46
|
assert.equal(
|
|
43
47
|
job.if,
|
|
44
|
-
|
|
48
|
+
hasPlayJob
|
|
49
|
+
? "always() && (needs.android.result == 'failure' || needs.android.result == 'cancelled' || needs.android-play.result == 'failure' || needs.android-play.result == 'cancelled')"
|
|
50
|
+
: "always() && (needs.android.result == 'failure' || needs.android.result == 'cancelled')",
|
|
45
51
|
);
|
|
46
52
|
assert.deepEqual(job.permissions, { contents: "read", "id-token": "write" });
|
|
47
53
|
assert.equal(job["runs-on"], "ubuntu-24.04");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import { execFile } from "node:child_process";
|
|
3
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
4
4
|
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
@@ -35,11 +35,22 @@ test("CI uses the deployed target, runs setup before upload and stops on setup f
|
|
|
35
35
|
join(root, ".github/workflows/pipeline.yml"),
|
|
36
36
|
"utf8",
|
|
37
37
|
);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const parsed = JSON.parse(
|
|
39
|
+
execFileSync(
|
|
40
|
+
process.execPath,
|
|
41
|
+
[
|
|
42
|
+
"-e",
|
|
43
|
+
"console.log(JSON.stringify(Bun.YAML.parse(await Bun.stdin.text())))",
|
|
44
|
+
],
|
|
45
|
+
{ input: workflow, encoding: "utf8" },
|
|
46
|
+
),
|
|
47
|
+
) as {
|
|
48
|
+
jobs: { web: { steps: Array<{ name?: string; run?: string }> } };
|
|
49
|
+
};
|
|
50
|
+
const deploy = parsed.jobs.web.steps.find(
|
|
51
|
+
(step) => step.name === "Deploy",
|
|
52
|
+
)?.run;
|
|
53
|
+
assert.equal(typeof deploy, "string");
|
|
43
54
|
assert.ok(deploy);
|
|
44
55
|
const temp = await mkdtemp(join(tmpdir(), "billing-deploy-hook-"));
|
|
45
56
|
try {
|