From da05ba1121039d1fe863e16fec25dc6fdac10d3c Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 7 Nov 2026 14:20:33 +0100 Subject: [PATCH] refactor(native): keep the Android bridge additions apart from the iOS ones in trekShell.ts The new methods sit at the end of the interface and the restore's Android answer has a type of its own, so the watch and large-screen branches, which add their methods after storeRestore, merge without a conflict. --- client/src/native/iap.ts | 7 +++++-- client/src/native/trekShell.ts | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/client/src/native/iap.ts b/client/src/native/iap.ts index b1091fb94..a3d29e5e6 100644 --- a/client/src/native/iap.ts +++ b/client/src/native/iap.ts @@ -1,5 +1,5 @@ import { isNativeAndroid, isNativeIos } from './platform'; -import { TrekShell } from './trekShell'; +import { TrekShell, type StoreRestoreResult } from './trekShell'; /** * In-app purchase, from the app's side. A seam, like {@link TrekShell}: the @@ -162,7 +162,10 @@ export const nativeIapClient: IapClient = { }, async restore() { try { - const { jws, purchaseToken, productId, transactionId } = await TrekShell.storeRestore({ prefix: PRODUCT_PREFIX }); + // Google Play answers with a purchase token where the App Store answers with a signed transaction. + const { jws, purchaseToken, productId, transactionId }: StoreRestoreResult = await TrekShell.storeRestore({ + prefix: PRODUCT_PREFIX, + }); if (purchaseToken && transactionId) { return { platform: 'google', productId: productId ?? '', receipt: purchaseToken, transactionId }; } diff --git a/client/src/native/trekShell.ts b/client/src/native/trekShell.ts index 57c2609f6..8b8539a47 100644 --- a/client/src/native/trekShell.ts +++ b/client/src/native/trekShell.ts @@ -96,10 +96,12 @@ export interface TrekShellPlugin { storeFinish(options: { transactionId: string }): Promise; /** iOS, feature wallet: adds a .pkpass (base64) to Apple Wallet, or opens it there when it is already in. */ addToWallet(options: { data: string }): Promise<{ result: 'added' | 'opened' | 'cancelled' }>; - /** The newest active subscription under `prefix` on this Apple ID or Google account, if any. */ - storeRestore(options: { - prefix: string; - }): Promise<{ jws?: string; purchaseToken?: string; productId?: string; transactionId?: string }>; + /** iOS, feature storeKit: the newest active subscription under `prefix` on this Apple ID, if any. */ + storeRestore(options: { prefix: string }): Promise<{ jws?: string; transactionId?: string }>; + addListener( + event: 'pushOpened', + listener: (payload: { url: string }) => void + ): Promise<{ remove: () => Promise }>; /** Android, feature googleWallet: opens a Google Wallet save link (https://pay.google.com/gp/v/save/...). */ addToGoogleWallet(options: { url: string }): Promise<{ result: 'opened' }>; /** Android, feature windowLayout: the window's size classes and a foldable's posture and hinge. */ @@ -108,10 +110,14 @@ export interface TrekShellPlugin { event: 'windowLayout', listener: (payload: NativeWindowLayout) => void ): Promise<{ remove: () => Promise }>; - addListener( - event: 'pushOpened', - listener: (payload: { url: string }) => void - ): Promise<{ remove: () => Promise }>; +} + +/** What Google Play Billing answers a restore with (Android, feature playBilling), beside iOS's `jws`. */ +export interface StoreRestoreResult { + jws?: string; + purchaseToken?: string; + productId?: string; + transactionId?: string; } /** A document shared to TREK, as the native side reads it. */