expo-superwall 1.1.2 → 1.1.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/CHANGELOG.md +13 -0
- package/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt +9 -0
- package/android/src/main/java/expo/modules/superwallexpo/json/PageViewData.kt +17 -0
- package/android/src/main/java/expo/modules/superwallexpo/json/SuperwallEvent.kt +5 -0
- package/build/package.json +1 -1
- package/build/src/SuperwallOptions.d.ts +35 -0
- package/build/src/SuperwallOptions.d.ts.map +1 -1
- package/build/src/SuperwallOptions.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js.map +1 -1
- package/build/src/localResources.d.ts +7 -0
- package/build/src/localResources.d.ts.map +1 -0
- package/build/src/localResources.js +46 -0
- package/build/src/localResources.js.map +1 -0
- package/build/src/useSuperwall.d.ts.map +1 -1
- package/build/src/useSuperwall.js +72 -4
- package/build/src/useSuperwall.js.map +1 -1
- package/ios/Json/SuperwallOptions+Json.swift +9 -0
- package/ios/SuperwallExpo.podspec +31 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b23c170: Ensure that methods await for config finish before triggering
|
|
8
|
+
- 0aa884e: Update podspec to pick proper iOS target
|
|
9
|
+
|
|
10
|
+
## 1.1.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- a8ba5af: Add localResources resolving for expo
|
|
15
|
+
|
|
3
16
|
## 1.1.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -28,6 +28,7 @@ import com.superwall.sdk.paywall.presentation.result.PresentationResult
|
|
|
28
28
|
import com.superwall.sdk.config.models.ConfigurationStatus
|
|
29
29
|
import com.superwall.sdk.paywall.presentation.register
|
|
30
30
|
import com.superwall.sdk.paywall.presentation.dismiss
|
|
31
|
+
import com.superwall.sdk.paywall.view.webview.PaywallResource
|
|
31
32
|
import com.superwall.sdk.paywall.presentation.get_presentation_result.getPresentationResult
|
|
32
33
|
import kotlinx.coroutines.CoroutineScope
|
|
33
34
|
import kotlinx.coroutines.Dispatchers
|
|
@@ -167,6 +168,9 @@ class SuperwallExpoModule : Module() {
|
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
@Suppress("UNCHECKED_CAST")
|
|
172
|
+
val localResourcesMap = options?.get("localResources") as? Map<String, String>
|
|
173
|
+
|
|
170
174
|
Superwall.configure(
|
|
171
175
|
apiKey = apiKey,
|
|
172
176
|
applicationContext = appContext.reactContext?.applicationContext as Application,
|
|
@@ -176,6 +180,11 @@ class SuperwallExpoModule : Module() {
|
|
|
176
180
|
completion = {
|
|
177
181
|
Superwall.instance.setPlatformWrapper("Expo", version = sdkVersion ?: "0.0.0")
|
|
178
182
|
Superwall.instance.delegate = SuperwallDelegateBridge()
|
|
183
|
+
if (localResourcesMap != null) {
|
|
184
|
+
Superwall.instance.localResources = localResourcesMap.mapValues { (_, value) ->
|
|
185
|
+
PaywallResource.FromUri(Uri.parse(value))
|
|
186
|
+
}
|
|
187
|
+
}
|
|
179
188
|
if (promiseSettled.compareAndSet(false, true)) {
|
|
180
189
|
promise.resolve(true)
|
|
181
190
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package expo.modules.superwallexpo.json
|
|
2
|
+
|
|
3
|
+
import com.superwall.sdk.paywall.view.webview.messaging.PageViewData
|
|
4
|
+
|
|
5
|
+
fun PageViewData.toJson(): Map<String, Any> {
|
|
6
|
+
val map = mutableMapOf<String, Any>(
|
|
7
|
+
"pageNodeId" to pageNodeId,
|
|
8
|
+
"flowPosition" to flowPosition,
|
|
9
|
+
"pageName" to pageName,
|
|
10
|
+
"navigationNodeId" to navigationNodeId,
|
|
11
|
+
"navigationType" to navigationType,
|
|
12
|
+
)
|
|
13
|
+
previousPageNodeId?.let { map["previousPageNodeId"] = it }
|
|
14
|
+
previousFlowPosition?.let { map["previousFlowPosition"] = it }
|
|
15
|
+
timeOnPreviousPageMs?.let { map["timeOnPreviousPageMs"] = it }
|
|
16
|
+
return map
|
|
17
|
+
}
|
|
@@ -46,6 +46,11 @@ class SuperwallEvent {
|
|
|
46
46
|
map["event"] = "paywallClose"
|
|
47
47
|
map["paywallInfo"] = superwallPlacement.paywallInfo.toJson()
|
|
48
48
|
}
|
|
49
|
+
is SuperwallEvent.PaywallPageView -> {
|
|
50
|
+
map["event"] = "paywallPageView"
|
|
51
|
+
map["paywallInfo"] = superwallPlacement.paywallInfo.toJson()
|
|
52
|
+
map["data"] = superwallPlacement.data.toJson()
|
|
53
|
+
}
|
|
49
54
|
is SuperwallEvent.PaywallDecline -> {
|
|
50
55
|
map["event"] = "paywallDecline"
|
|
51
56
|
map["paywallInfo"] = superwallPlacement.paywallInfo.toJson()
|
package/build/package.json
CHANGED
|
@@ -29,6 +29,20 @@ export type TransactionBackgroundView = "spinner" | "none";
|
|
|
29
29
|
* Controls when the SDK enters test mode.
|
|
30
30
|
*/
|
|
31
31
|
export type TestModeBehavior = "automatic" | "whenEnabledForUser" | "never" | "always";
|
|
32
|
+
/**
|
|
33
|
+
* @category Types
|
|
34
|
+
* @since 1.2.0
|
|
35
|
+
* A local asset that can be registered with Superwall and served to the paywall webview
|
|
36
|
+
* via the `swlocal://<id>` URL scheme.
|
|
37
|
+
*
|
|
38
|
+
* Accepts:
|
|
39
|
+
* - A Metro `require()` result (e.g. `require("./hero.png")`) — resolved through `expo-asset`.
|
|
40
|
+
* - A string URI: `file://`, `content://`, or an absolute path.
|
|
41
|
+
* - An `{ uri: string }` object (matches `Image` source).
|
|
42
|
+
*/
|
|
43
|
+
export type LocalResource = number | string | {
|
|
44
|
+
uri: string;
|
|
45
|
+
};
|
|
32
46
|
/**
|
|
33
47
|
* @category Models
|
|
34
48
|
* @since 0.0.15
|
|
@@ -152,6 +166,27 @@ export interface PartialSuperwallOptions {
|
|
|
152
166
|
* @platform iOS and Android
|
|
153
167
|
*/
|
|
154
168
|
testModeBehavior?: TestModeBehavior;
|
|
169
|
+
/**
|
|
170
|
+
* A mapping of local resource IDs to local assets. The paywall webview can reference
|
|
171
|
+
* these via the `swlocal://<id>` URL scheme.
|
|
172
|
+
*
|
|
173
|
+
* Resolved at configure time. Pass a Metro `require()`, a file URI string, or `{ uri }`.
|
|
174
|
+
*
|
|
175
|
+
* ```ts
|
|
176
|
+
* <SuperwallProvider
|
|
177
|
+
* apiKeys={...}
|
|
178
|
+
* options={{
|
|
179
|
+
* localResources: {
|
|
180
|
+
* "hero-image": require("./assets/hero.png"),
|
|
181
|
+
* "logo": { uri: FileSystem.documentDirectory + "logo.png" },
|
|
182
|
+
* }
|
|
183
|
+
* }}
|
|
184
|
+
* />
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @platform iOS and Android
|
|
188
|
+
*/
|
|
189
|
+
localResources?: Record<string, LocalResource>;
|
|
155
190
|
}
|
|
156
191
|
/**
|
|
157
192
|
* @category Models
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuperwallOptions.d.ts","sourceRoot":"","sources":["../../src/SuperwallOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAE9D;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAEnE;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAChB,qBAAqB,GACrB,cAAc,GACd,UAAU,GACV,eAAe,GACf,iBAAiB,GACjB,cAAc,GACd,qBAAqB,GACrB,4BAA4B,GAC5B,uBAAuB,GACvB,QAAQ,GACR,SAAS,GACT,eAAe,GACf,iBAAiB,GACjB,iB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ACjC,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC,eAAe,CAAC,EAAE,WAAW,GAAG,WAAW,CAAA;IAC3C,iCAAiC,CAAC,EAAE,OAAO,CAAA;IAC3C,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC;;;OAGG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAA;IACzC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC/C;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBA6BrC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuperwallOptions.js","sourceRoot":"","sources":["../../src/SuperwallOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SuperwallOptions.js","sourceRoot":"","sources":["../../src/SuperwallOptions.ts"],"names":[],"mappings":"AA8NA;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAqB;IACvD,QAAQ,EAAE;QACR,uBAAuB,EAAE,IAAI;QAC7B,aAAa,EAAE;YACb,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,2DAA2D;YACpE,gBAAgB,EAAE,MAAM;SACzB;QACD,8BAA8B,EAAE,IAAI;QACpC,aAAa,EAAE,KAAK;QACpB,oBAAoB,EAAE,IAAI;QAC1B,yBAAyB,EAAE,SAAS;QACpC,sCAAsC,EAAE,KAAK;KAC9C;IACD,kBAAkB,EAAE,SAAS;IAC7B,+BAA+B,EAAE,IAAI;IACrC,uBAAuB,EAAE,KAAK;IAC9B,OAAO,EAAE;QACP,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,CAAC,KAAK,CAAC;KAChB;IACD,0BAA0B,EAAE,KAAK;IACjC,iCAAiC,EAAE,KAAK;IACxC,wBAAwB,EAAE,KAAK;IAC/B,sBAAsB,EAAE,KAAK;IAC7B,+BAA+B,EAAE,KAAK;IACtC,mBAAmB,EAAE,CAAC;IACtB,cAAc,EAAE,KAAK;IACrB,gBAAgB,EAAE,WAAW;CAC9B,CAAA","sourcesContent":["import type { PaywallInfo } from \"./SuperwallExpoModule.types\"\n\n/**\n * @category Types\n * @since 0.0.15\n * Defines the log levels for the SDK.\n */\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\" | \"none\"\n\n/**\n * @category Types\n * @since 0.0.15\n * Defines the scopes for logging within the SDK.\n */\nexport type LogScope =\n | \"localizationManager\"\n | \"bounceButton\"\n | \"coreData\"\n | \"configManager\"\n | \"identityManager\"\n | \"debugManager\"\n | \"debugViewController\"\n | \"localizationViewController\"\n | \"gameControllerManager\"\n | \"device\"\n | \"network\"\n | \"paywallEvents\"\n | \"productsManager\"\n | \"storeKitManager\"\n | \"placements\"\n | \"receipts\"\n | \"superwallCore\"\n | \"paywallPresentation\"\n | \"paywallTransactions\"\n | \"paywallViewController\"\n | \"cache\"\n | \"all\"\n\n/**\n * @category Types\n * @since 0.0.15\n * Defines the network environment for Superwall.\n */\nexport type NetworkEnvironment = \"release\" | \"releaseCandidate\" | \"developer\"\n\n/**\n * @category Types\n * @since 0.0.15\n * Defines the different types of views that can appear behind Apple's payment sheet during a transaction.\n */\nexport type TransactionBackgroundView = \"spinner\" | \"none\"\n\n/**\n * @category Types\n * @since 0.3.0\n * Controls when the SDK enters test mode.\n */\nexport type TestModeBehavior = \"automatic\" | \"whenEnabledForUser\" | \"never\" | \"always\"\n\n/**\n * @category Types\n * @since 1.2.0\n * A local asset that can be registered with Superwall and served to the paywall webview\n * via the `swlocal://<id>` URL scheme.\n *\n * Accepts:\n * - A Metro `require()` result (e.g. `require(\"./hero.png\")`) — resolved through `expo-asset`.\n * - A string URI: `file://`, `content://`, or an absolute path.\n * - An `{ uri: string }` object (matches `Image` source).\n */\nexport type LocalResource = number | string | { uri: string }\n\n/**\n * @category Models\n * @since 0.0.15\n * Defines the messaging of the alert presented to the user when restoring a transaction fails.\n */\nexport interface RestoreFailed {\n title: string\n message: string\n closeButtonTitle: string\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for configuring logging behavior.\n */\nexport interface LoggingOptions {\n level: LogLevel\n scopes: LogScope[]\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for configuring the appearance and behavior of paywalls.\n */\nexport interface PaywallOptions {\n isHapticFeedbackEnabled: boolean\n restoreFailed: RestoreFailed\n shouldShowPurchaseFailureAlert: boolean\n shouldPreload: boolean\n automaticallyDismiss: boolean\n transactionBackgroundView: TransactionBackgroundView\n shouldShowWebPurchaseConfirmationAlert: boolean\n onBackPressed?: (paywallInfo: PaywallInfo) => boolean\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for configuring the Superwall SDK.\n */\nexport interface SuperwallOptions {\n paywalls: PaywallOptions\n networkEnvironment: NetworkEnvironment\n isExternalDataCollectionEnabled: boolean\n localeIdentifier?: string\n isGameControllerEnabled: boolean\n logging: LoggingOptions\n passIdentifiersToPlayStore: boolean\n storeKitVersion?: \"STOREKIT1\" | \"STOREKIT2\"\n enableExperimentalDeviceVariables: boolean\n manualPurchaseManagement: boolean\n /**\n * Observe purchases made outside of Superwall. When true, Superwall will observe\n * StoreKit/Play Store transactions and report them. Defaults to false.\n * @platform iOS and Android\n */\n shouldObservePurchases: boolean\n /**\n * Disables the app transaction check on SDK launch. Defaults to false.\n * @platform iOS only\n */\n shouldBypassAppTransactionCheck: boolean\n /**\n * Number of times the SDK will attempt to get the Superwall configuration after\n * a network failure before it times out. Defaults to 6.\n * @platform iOS only\n */\n maxConfigRetryCount: number\n /**\n * Enable mock review functionality. Defaults to false.\n * @platform Android only\n */\n useMockReviews: boolean\n /**\n * Controls when the SDK enters test mode. Defaults to \"automatic\".\n * @platform iOS and Android\n */\n testModeBehavior: TestModeBehavior\n}\n\n/**\n * @category Types\n * @since 0.2.8\n * Deep partial type for SuperwallOptions, allowing partial configuration at any nesting level.\n */\nexport interface PartialSuperwallOptions {\n paywalls?: Partial<PaywallOptions> & {\n restoreFailed?: Partial<RestoreFailed>\n }\n networkEnvironment?: NetworkEnvironment\n isExternalDataCollectionEnabled?: boolean\n localeIdentifier?: string\n isGameControllerEnabled?: boolean\n logging?: Partial<LoggingOptions>\n passIdentifiersToPlayStore?: boolean\n storeKitVersion?: \"STOREKIT1\" | \"STOREKIT2\"\n enableExperimentalDeviceVariables?: boolean\n manualPurchaseManagement?: boolean\n /**\n * Observe purchases made outside of Superwall. When true, Superwall will observe\n * StoreKit/Play Store transactions and report them. Defaults to false.\n * @platform iOS and Android\n */\n shouldObservePurchases?: boolean\n /**\n * Disables the app transaction check on SDK launch. Defaults to false.\n * @platform iOS only\n */\n shouldBypassAppTransactionCheck?: boolean\n /**\n * Number of times the SDK will attempt to get the Superwall configuration after\n * a network failure before it times out. Defaults to 6.\n * @platform iOS only\n */\n maxConfigRetryCount?: number\n /**\n * Enable mock review functionality. Defaults to false.\n * @platform Android only\n */\n useMockReviews?: boolean\n /**\n * Controls when the SDK enters test mode. Defaults to \"automatic\".\n * @platform iOS and Android\n */\n testModeBehavior?: TestModeBehavior\n /**\n * A mapping of local resource IDs to local assets. The paywall webview can reference\n * these via the `swlocal://<id>` URL scheme.\n *\n * Resolved at configure time. Pass a Metro `require()`, a file URI string, or `{ uri }`.\n *\n * ```ts\n * <SuperwallProvider\n * apiKeys={...}\n * options={{\n * localResources: {\n * \"hero-image\": require(\"./assets/hero.png\"),\n * \"logo\": { uri: FileSystem.documentDirectory + \"logo.png\" },\n * }\n * }}\n * />\n * ```\n *\n * @platform iOS and Android\n */\n localResources?: Record<string, LocalResource>\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Default options for the Superwall SDK.\n */\nexport const DefaultSuperwallOptions: SuperwallOptions = {\n paywalls: {\n isHapticFeedbackEnabled: true,\n restoreFailed: {\n title: \"No Subscription Found\",\n message: \"We couldn't find an active subscription for your account.\",\n closeButtonTitle: \"Okay\",\n },\n shouldShowPurchaseFailureAlert: true,\n shouldPreload: false,\n automaticallyDismiss: true,\n transactionBackgroundView: \"spinner\",\n shouldShowWebPurchaseConfirmationAlert: false,\n },\n networkEnvironment: \"release\",\n isExternalDataCollectionEnabled: true,\n isGameControllerEnabled: false,\n logging: {\n level: \"info\",\n scopes: [\"all\"],\n },\n passIdentifiersToPlayStore: false,\n enableExperimentalDeviceVariables: false,\n manualPurchaseManagement: false,\n shouldObservePurchases: false,\n shouldBypassAppTransactionCheck: false,\n maxConfigRetryCount: 6,\n useMockReviews: false,\n testModeBehavior: \"automatic\",\n}\n"]}
|
package/build/src/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { PresentationResult, PresentationResultHoldout, PresentationResultNoAudi
|
|
|
3
3
|
export * from "./components";
|
|
4
4
|
export { default as SuperwallExpoModule } from "./SuperwallExpoModule";
|
|
5
5
|
export type * from "./SuperwallExpoModule.types";
|
|
6
|
-
export type { LoggingOptions, NetworkEnvironment, PartialSuperwallOptions, PaywallOptions, RestoreFailed, SuperwallOptions, TestModeBehavior, TransactionBackgroundView, } from "./SuperwallOptions";
|
|
6
|
+
export type { LocalResource, LoggingOptions, NetworkEnvironment, PartialSuperwallOptions, PaywallOptions, RestoreFailed, SuperwallOptions, TestModeBehavior, TransactionBackgroundView, } from "./SuperwallOptions";
|
|
7
7
|
export { DefaultSuperwallOptions } from "./SuperwallOptions";
|
|
8
8
|
export * from "./SuperwallProvider";
|
|
9
9
|
export * from "./usePlacement";
|
package/build/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AA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AA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA"}
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,yBAAyB,EACzB,qCAAqC,EACrC,mCAAmC,EACnC,kCAAkC,GACnC,MAAM,iCAAiC,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,yBAAyB,EACzB,qCAAqC,EACrC,mCAAmC,EACnC,kCAAkC,GACnC,MAAM,iCAAiC,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAatE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAE5D,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA","sourcesContent":["export * from \"./CustomPurchaseControllerProvider\"\nexport {\n PresentationResult,\n PresentationResultHoldout,\n PresentationResultNoAudienceMatch,\n PresentationResultPaywall,\n PresentationResultPaywallNotAvailable,\n PresentationResultPlacementNotFound,\n PresentationResultUserIsSubscribed,\n} from \"./compat/lib/PresentationResult\"\nexport * from \"./components\"\nexport { default as SuperwallExpoModule } from \"./SuperwallExpoModule\"\nexport type * from \"./SuperwallExpoModule.types\"\nexport type {\n LocalResource,\n LoggingOptions,\n NetworkEnvironment,\n PartialSuperwallOptions,\n PaywallOptions,\n RestoreFailed,\n SuperwallOptions,\n TestModeBehavior,\n TransactionBackgroundView,\n} from \"./SuperwallOptions\"\nexport { DefaultSuperwallOptions } from \"./SuperwallOptions\"\n\nexport * from \"./SuperwallProvider\"\nexport * from \"./usePlacement\"\nexport * from \"./useSuperwall\"\nexport * from \"./useSuperwallEvents\"\nexport * from \"./useUser\"\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LocalResource } from "./SuperwallOptions";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a map of local resources to plain `{ id: uri }` strings suitable for serializing
|
|
4
|
+
* across the Expo bridge. Entries that fail to resolve are dropped and logged.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveLocalResources(input: Record<string, LocalResource> | undefined): Promise<Record<string, string> | undefined>;
|
|
7
|
+
//# sourceMappingURL=localResources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localResources.d.ts","sourceRoot":"","sources":["../../src/localResources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAwBvD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,SAAS,GAC/C,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAmB7C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Asset } from "expo-asset";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a {@link LocalResource} to a URI string that the native SDK can consume.
|
|
4
|
+
*
|
|
5
|
+
* - `number` (Metro `require()`) is resolved via `expo-asset`, downloading if necessary
|
|
6
|
+
* so the asset has a `file://` `localUri`.
|
|
7
|
+
* - `string` is returned as-is.
|
|
8
|
+
* - `{ uri }` returns the `uri` field.
|
|
9
|
+
*/
|
|
10
|
+
async function resolveLocalResource(resource) {
|
|
11
|
+
if (typeof resource === "number") {
|
|
12
|
+
const asset = Asset.fromModule(resource);
|
|
13
|
+
if (!asset.localUri) {
|
|
14
|
+
await asset.downloadAsync();
|
|
15
|
+
}
|
|
16
|
+
return asset.localUri ?? asset.uri;
|
|
17
|
+
}
|
|
18
|
+
if (typeof resource === "string") {
|
|
19
|
+
return resource;
|
|
20
|
+
}
|
|
21
|
+
return resource.uri;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a map of local resources to plain `{ id: uri }` strings suitable for serializing
|
|
25
|
+
* across the Expo bridge. Entries that fail to resolve are dropped and logged.
|
|
26
|
+
*/
|
|
27
|
+
export async function resolveLocalResources(input) {
|
|
28
|
+
if (!input)
|
|
29
|
+
return undefined;
|
|
30
|
+
const ids = Object.keys(input);
|
|
31
|
+
if (ids.length === 0)
|
|
32
|
+
return undefined;
|
|
33
|
+
const resolved = await Promise.all(ids.map(async (id) => {
|
|
34
|
+
try {
|
|
35
|
+
const uri = await resolveLocalResource(input[id]);
|
|
36
|
+
return [id, uri];
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.warn(`[Superwall] Failed to resolve local resource "${id}"`, error);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
const entries = resolved.filter((entry) => entry !== null);
|
|
44
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=localResources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localResources.js","sourceRoot":"","sources":["../../src/localResources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGlC;;;;;;;GAOG;AACH,KAAK,UAAU,oBAAoB,CAAC,QAAuB;IACzD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,KA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WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACrE,CAAC","sourcesContent":["import { Asset } from \"expo-asset\"\nimport type { LocalResource } from \"./SuperwallOptions\"\n\n/**\n * Resolves a {@link LocalResource} to a URI string that the native SDK can consume.\n *\n * - `number` (Metro `require()`) is resolved via `expo-asset`, downloading if necessary\n * so the asset has a `file://` `localUri`.\n * - `string` is returned as-is.\n * - `{ uri }` returns the `uri` field.\n */\nasync function resolveLocalResource(resource: LocalResource): Promise<string> {\n if (typeof resource === \"number\") {\n const asset = Asset.fromModule(resource)\n if (!asset.localUri) {\n await asset.downloadAsync()\n }\n return asset.localUri ?? asset.uri\n }\n if (typeof resource === \"string\") {\n return resource\n }\n return resource.uri\n}\n\n/**\n * Resolves a map of local resources to plain `{ id: uri }` strings suitable for serializing\n * across the Expo bridge. Entries that fail to resolve are dropped and logged.\n */\nexport async function resolveLocalResources(\n input: Record<string, LocalResource> | undefined,\n): Promise<Record<string, string> | undefined> {\n if (!input) return undefined\n const ids = Object.keys(input)\n if (ids.length === 0) return undefined\n\n const resolved = await Promise.all(\n ids.map(async (id) => {\n try {\n const uri = await resolveLocalResource(input[id]!)\n return [id, uri] as const\n } catch (error) {\n console.warn(`[Superwall] Failed to resolve local resource \"${id}\"`, error)\n return null\n }\n }),\n )\n\n const entries = resolved.filter((entry): entry is readonly [string, string] => entry !== null)\n return entries.length > 0 ? Object.fromEntries(entries) : undefined\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuperwall.d.ts","sourceRoot":"","sources":["../../src/useSuperwall.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"useSuperwall.d.ts","sourceRoot":"","sources":["../../src/useSuperwall.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AAGzE,OAAO,K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,MAAM,CAAC,CAAC,CAAA;IAG/D;;;;;OAKG;IACH,cAAc,EAAE,MAAM,MAAM,IAAI,CAAA;IAEhC,qBAAqB,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpE,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IAEvD;;;;OAIG;IACH,eAAe,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,CAAA;CACjD;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,6EAiN3B,CAAA;AAEH;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,OAAO,GAAG,gBAAgB,CAAC,CAAA;AAEjG,eAAO,MAAM,gBAAgB,kCAAgC,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,oBAAoB,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,GAAG,CAAC,CASjG"}
|
|
@@ -2,9 +2,59 @@ import { createContext, useContext } from "react";
|
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { useShallow } from "zustand/shallow";
|
|
4
4
|
import pkg from "../package.json";
|
|
5
|
+
import { resolveLocalResources } from "./localResources";
|
|
5
6
|
import SuperwallExpoModule from "./SuperwallExpoModule";
|
|
6
7
|
import { DefaultSuperwallOptions } from "./SuperwallOptions";
|
|
7
8
|
import { filterUndefined } from "./utils/filterUndefined";
|
|
9
|
+
const CONFIGURE_WAIT_TIMEOUT_MS = 10_000;
|
|
10
|
+
/**
|
|
11
|
+
* Blocks a native call until Superwall has finished configuring.
|
|
12
|
+
*
|
|
13
|
+
* Resolves as soon as `isConfigured` flips true, rejects if configuration failed
|
|
14
|
+
* (`configurationError`), and otherwise rejects after CONFIGURE_WAIT_TIMEOUT_MS.
|
|
15
|
+
* The timeout clock (re)starts when configure() begins — so a configure() called
|
|
16
|
+
* late still gets the full window — and the error distinguishes "never called"
|
|
17
|
+
* from "called but too slow". Subscribes to the store rather than polling.
|
|
18
|
+
*/
|
|
19
|
+
function awaitConfigured() {
|
|
20
|
+
const { isConfigured, configurationError } = useSuperwallStore.getState();
|
|
21
|
+
if (isConfigured)
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
if (configurationError)
|
|
24
|
+
return Promise.reject(new Error(configurationError));
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
let timer;
|
|
27
|
+
const settle = (fn) => {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
unsubscribe();
|
|
30
|
+
fn();
|
|
31
|
+
};
|
|
32
|
+
// Restart the clock when configure starts so a late configure() gets the full
|
|
33
|
+
// window instead of inheriting time already spent waiting before it ran.
|
|
34
|
+
const arm = () => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
timer = setTimeout(() => {
|
|
37
|
+
const inFlight = useSuperwallStore.getState().isLoading;
|
|
38
|
+
settle(() => reject(new Error(inFlight
|
|
39
|
+
? `Superwall configure did not complete within ${CONFIGURE_WAIT_TIMEOUT_MS}ms.`
|
|
40
|
+
: `Superwall configure was not called within ${CONFIGURE_WAIT_TIMEOUT_MS}ms. Did you forget to call configure()?`)));
|
|
41
|
+
}, CONFIGURE_WAIT_TIMEOUT_MS);
|
|
42
|
+
};
|
|
43
|
+
const unsubscribe = useSuperwallStore.subscribe((state, prev) => {
|
|
44
|
+
if (state.isConfigured) {
|
|
45
|
+
settle(resolve);
|
|
46
|
+
}
|
|
47
|
+
else if (state.configurationError) {
|
|
48
|
+
const error = state.configurationError;
|
|
49
|
+
settle(() => reject(new Error(error)));
|
|
50
|
+
}
|
|
51
|
+
else if (state.isLoading && !prev.isLoading) {
|
|
52
|
+
arm();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
arm();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
8
58
|
/**
|
|
9
59
|
* @category Store
|
|
10
60
|
* @since 0.0.15
|
|
@@ -25,13 +75,15 @@ export const useSuperwallStore = create((set, get) => ({
|
|
|
25
75
|
configure: async (apiKey, options) => {
|
|
26
76
|
set({ isLoading: true, configurationError: null });
|
|
27
77
|
try {
|
|
28
|
-
const { manualPurchaseManagement, manualPurchaseManagment, ...restOptions } = options || {};
|
|
78
|
+
const { manualPurchaseManagement, manualPurchaseManagment, localResources, ...restOptions } = options || {};
|
|
29
79
|
// Support both spellings for backward compatibility
|
|
30
80
|
const isManualPurchaseManagement = manualPurchaseManagement ?? manualPurchaseManagment ?? false;
|
|
81
|
+
const resolvedLocalResources = await resolveLocalResources(localResources);
|
|
31
82
|
// Deep merge partial options with defaults to ensure all required fields are present
|
|
32
83
|
const mergedOptions = {
|
|
33
84
|
...DefaultSuperwallOptions,
|
|
34
85
|
...restOptions,
|
|
86
|
+
...(resolvedLocalResources ? { localResources: resolvedLocalResources } : {}),
|
|
35
87
|
paywalls: {
|
|
36
88
|
...DefaultSuperwallOptions.paywalls,
|
|
37
89
|
...restOptions.paywalls,
|
|
@@ -66,6 +118,7 @@ export const useSuperwallStore = create((set, get) => ({
|
|
|
66
118
|
}
|
|
67
119
|
},
|
|
68
120
|
identify: async (userId, options) => {
|
|
121
|
+
await awaitConfigured();
|
|
69
122
|
await SuperwallExpoModule.identify(userId, options);
|
|
70
123
|
// TODO: Instead of setting users after identify, we should set this based on an event
|
|
71
124
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -76,58 +129,73 @@ export const useSuperwallStore = create((set, get) => ({
|
|
|
76
129
|
set({ user: currentUser, subscriptionStatus });
|
|
77
130
|
},
|
|
78
131
|
reset: async () => {
|
|
132
|
+
await awaitConfigured();
|
|
79
133
|
await SuperwallExpoModule.reset();
|
|
80
134
|
const currentUser = await SuperwallExpoModule.getUserAttributes();
|
|
81
135
|
const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus();
|
|
82
136
|
set({ user: currentUser, subscriptionStatus });
|
|
83
137
|
},
|
|
84
138
|
registerPlacement: async (placement, params, handlerId = "default") => {
|
|
139
|
+
await awaitConfigured();
|
|
85
140
|
await SuperwallExpoModule.registerPlacement(placement, params, handlerId);
|
|
86
141
|
},
|
|
87
142
|
getPresentationResult: async (placement, params) => {
|
|
143
|
+
await awaitConfigured();
|
|
88
144
|
return SuperwallExpoModule.getPresentationResult(placement, params);
|
|
89
145
|
},
|
|
90
146
|
restorePurchases: async () => {
|
|
147
|
+
await awaitConfigured();
|
|
91
148
|
return SuperwallExpoModule.restorePurchases();
|
|
92
149
|
},
|
|
93
150
|
dismiss: async () => {
|
|
151
|
+
await awaitConfigured();
|
|
94
152
|
await SuperwallExpoModule.dismiss();
|
|
95
153
|
},
|
|
96
154
|
preloadAllPaywalls: async () => {
|
|
97
|
-
|
|
155
|
+
await awaitConfigured();
|
|
156
|
+
await SuperwallExpoModule.preloadAllPaywalls();
|
|
98
157
|
},
|
|
99
158
|
preloadPaywalls: async (placements) => {
|
|
100
|
-
|
|
159
|
+
await awaitConfigured();
|
|
160
|
+
await SuperwallExpoModule.preloadPaywalls(placements);
|
|
101
161
|
},
|
|
102
162
|
setUserAttributes: async (attrs) => {
|
|
163
|
+
await awaitConfigured();
|
|
103
164
|
await SuperwallExpoModule.setUserAttributes(filterUndefined(attrs));
|
|
104
165
|
const currentUser = await SuperwallExpoModule.getUserAttributes();
|
|
105
166
|
set({ user: currentUser });
|
|
106
167
|
},
|
|
107
168
|
getUserAttributes: async () => {
|
|
169
|
+
await awaitConfigured();
|
|
108
170
|
const attributes = await SuperwallExpoModule.getUserAttributes();
|
|
109
171
|
set({ user: attributes });
|
|
110
172
|
return attributes;
|
|
111
173
|
},
|
|
112
174
|
setLogLevel: async (level) => {
|
|
113
|
-
|
|
175
|
+
await awaitConfigured();
|
|
176
|
+
await SuperwallExpoModule.setLogLevel(level);
|
|
114
177
|
},
|
|
115
178
|
setIntegrationAttributes: async (attributes) => {
|
|
179
|
+
await awaitConfigured();
|
|
116
180
|
await SuperwallExpoModule.setIntegrationAttributes(attributes);
|
|
117
181
|
const currentUser = await SuperwallExpoModule.getUserAttributes();
|
|
118
182
|
set({ user: currentUser });
|
|
119
183
|
},
|
|
120
184
|
getIntegrationAttributes: async () => {
|
|
185
|
+
await awaitConfigured();
|
|
121
186
|
return SuperwallExpoModule.getIntegrationAttributes();
|
|
122
187
|
},
|
|
123
188
|
setSubscriptionStatus: async (status) => {
|
|
189
|
+
await awaitConfigured();
|
|
124
190
|
await SuperwallExpoModule.setSubscriptionStatus(status);
|
|
125
191
|
},
|
|
126
192
|
getDeviceAttributes: async () => {
|
|
193
|
+
await awaitConfigured();
|
|
127
194
|
const attributes = await SuperwallExpoModule.getDeviceAttributes();
|
|
128
195
|
return attributes;
|
|
129
196
|
},
|
|
130
197
|
getEntitlements: async () => {
|
|
198
|
+
await awaitConfigured();
|
|
131
199
|
const entitlements = await SuperwallExpoModule.getEntitlements();
|
|
132
200
|
return entitlements;
|
|
133
201
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuperwall.js","sourceRoot":"","sources":["../../src/useSuperwall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAA;AAEjC,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AAOvD,OAAO,EAAE,uBAAuB,EAAgC,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAsMzD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACrE,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AAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,KAAqB,EAAE,EAAE,CAAC,KAAqB,CAAA;IACjE,6DAA6D;IAC7D,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AACtE,CAAC","sourcesContent":["import { createContext, useContext } from \"react\"\nimport { create } from \"zustand\"\nimport { useShallow } from \"zustand/shallow\"\nimport pkg from \"../package.json\"\nimport type { PresentationResult } from \"./compat/lib/PresentationResult\"\nimport SuperwallExpoModule from \"./SuperwallExpoModule\"\nimport type {\n EntitlementsInfo,\n IntegrationAttributes,\n RestorationResultResponse,\n SubscriptionStatus,\n} from \"./SuperwallExpoModule.types\"\nimport { DefaultSuperwallOptions, type PartialSuperwallOptions } from \"./SuperwallOptions\"\nimport { filterUndefined } from \"./utils/filterUndefined\"\n\n/**\n * @category Models\n * @since 0.0.15\n * Interface representing the attributes of a user.\n */\nexport interface UserAttributes {\n /** The user's alias ID, if set. */\n aliasId: string\n /** The user's application-specific user ID. */\n appUserId: string\n /** The ISO 8601 date string representation of when the application was installed on the user's device. */\n applicationInstalledAt: string\n /** A seed value associated with the user, used for consistent variant assignments in experiments. */\n seed: number\n /** Allows for custom attributes to be set for the user. These can be of any type. */\n [key: string]: any | null\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for the `identify` method.\n */\nexport interface IdentifyOptions {\n /**\n * Determines whether to restore paywall assignments from a previous session for the identified user.\n * If `true`, the SDK attempts to restore the assignments. Defaults to `false`.\n */\n restorePaywallAssignments?: boolean\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Defines the structure of the Superwall store, including its state and actions.\n * This store is managed by Zustand.\n */\nexport interface SuperwallStore {\n /* -------------------- State -------------------- */\n /** Indicates whether the Superwall SDK has been successfully configured. */\n isConfigured: boolean\n /** Indicates whether the SDK is currently performing a loading operation (e.g., configuring, fetching data). */\n isLoading: boolean\n /** Indicates whether the native event listeners have been initialized. */\n listenersInitialized: boolean\n\n /**\n * Contains error message if SDK configuration failed, `null` otherwise.\n * When this is set, the SDK is not configured and app should show error UI.\n */\n configurationError: string | null\n\n /**\n * The current user's attributes.\n * `null` if no user is identified or after `reset` is called.\n * `undefined` initially before any user data is fetched or set.\n */\n user?: UserAttributes | null\n\n /** The current subscription status of the user. */\n subscriptionStatus: SubscriptionStatus\n\n /* -------------------- Internal -------------------- */\n // Internal listener references for cleanup handled inside Provider effect.\n // Not reactive, so we store outside Zustand state to avoid unnecessary rerenders.\n\n /* -------------------- Actions -------------------- */\n /**\n * Configures the Superwall SDK with the provided API key and options.\n * This must be called before most other SDK functions can be used.\n * @param apiKey - Your Superwall API key.\n * @param options - Optional configuration settings for the SDK.\n * @returns A promise that resolves when configuration is complete.\n * @internal\n */\n configure: (\n apiKey: string,\n options?: PartialSuperwallOptions & {\n /** @deprecated Use manualPurchaseManagement instead */\n manualPurchaseManagment?: boolean\n },\n ) => Promise<void>\n /**\n * Identifies the current user with a unique ID.\n * @param userId - The unique identifier for the user.\n * @param options - Optional parameters for identification.\n * @returns A promise that resolves when identification is complete.\n */\n identify: (userId: string, options?: IdentifyOptions) => Promise<void>\n /**\n * Resets the user's identity and clears all user-specific data, effectively logging them out.\n * @internal\n */\n reset: () => Promise<void>\n\n /**\n * Registers a placement to potentially show a paywall.\n * The decision to show a paywall is determined by campaign rules and user assignments on the Superwall dashboard.\n * @param placement - The ID of the placement to register.\n * @param params - Optional parameters to pass with the placement.\n * @param handlerId - An optional identifier used to associate specific event handlers (e.g., from `usePlacement`). Defaults to \"default\".\n * @returns A promise that resolves when the placement registration is complete.\n */\n registerPlacement: (\n placement: string,\n params?: Record<string, any>,\n handlerId?: string | null,\n ) => Promise<void>\n /**\n * Retrieves the presentation result for a given placement.\n * This can be used to understand what would happen if a placement were to be registered, without actually registering it.\n * @param placement - The ID of the placement.\n * @param params - Optional parameters for the placement.\n * @returns A promise that resolves with the presentation result.\n */\n getPresentationResult: (\n placement: string,\n params?: Record<string, any>,\n ) => Promise<PresentationResult>\n /**\n * Programmatically restores purchases.\n * @returns A promise that resolves with a {@link RestorationResultResponse} indicating success or failure.\n */\n restorePurchases: () => Promise<RestorationResultResponse>\n\n /**\n * Dismisses any currently presented Superwall paywall.\n * @returns A promise that resolves when the dismissal is complete.\n */\n dismiss: () => Promise<void>\n\n /**\n * Preloads all paywalls configured in your Superwall dashboard.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadAllPaywalls: () => Promise<void>\n /**\n * Preloads specific paywalls.\n * @param placements - An array of placement IDs for which to preload paywalls.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadPaywalls: (placements: string[]) => Promise<void>\n\n /**\n * Sets custom attributes for the current user.\n * @param attrs - An object containing the attributes to set.\n * @returns A promise that resolves when attributes are set.\n */\n setUserAttributes: (attrs: Record<string, any | null>) => Promise<void>\n /**\n * Retrieves the current user's attributes.\n * @returns A promise that resolves with the user's attributes.\n */\n getUserAttributes: () => Promise<Record<string, any>>\n\n /**\n * Sets the logging level for the Superwall SDK.\n * @param level - The desired log level (e.g., \"debug\", \"info\", \"warn\", \"error\", \"none\").\n * @returns A promise that resolves when the log level is set.\n */\n setLogLevel: (level: string) => Promise<void>\n\n /**\n * Sets attributes for third-party integrations.\n * @param attributes - Object mapping IntegrationAttribute string values to their IDs\n * @returns A promise that resolves when attributes are set\n */\n setIntegrationAttributes: (attributes: IntegrationAttributes) => Promise<void>\n\n /**\n * Gets the currently set integration attributes.\n * @returns A promise that resolves with the current integration attributes\n */\n getIntegrationAttributes: () => Promise<Record<string, string>>\n\n /* -------------------- Listener helpers -------------------- */\n /**\n * Initializes native event listeners for the SDK.\n * This is typically called internally by the `SuperwallProvider`.\n * @returns A cleanup function to remove the listeners.\n * @internal\n */\n _initListeners: () => () => void\n\n setSubscriptionStatus: (status: SubscriptionStatus) => Promise<void>\n\n getDeviceAttributes: () => Promise<Record<string, any>>\n\n /**\n * Retrieves the user's entitlements from Superwall's servers.\n * This includes both active and inactive entitlements.\n * @returns A promise that resolves with the entitlements information.\n */\n getEntitlements: () => Promise<EntitlementsInfo>\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Zustand store for Superwall SDK state and actions.\n * @internal\n */\nexport const useSuperwallStore = create<SuperwallStore>((set, get) => ({\n /* -------------------- State -------------------- */\n isConfigured: false,\n isLoading: false,\n listenersInitialized: false,\n configurationError: null,\n\n user: null,\n subscriptionStatus: {\n status: \"UNKNOWN\",\n },\n\n /* -------------------- Actions -------------------- */\n configure: async (apiKey, options) => {\n set({ isLoading: true, configurationError: null })\n\n try {\n const { manualPurchaseManagement, manualPurchaseManagment, ...restOptions } = options || {}\n\n // Support both spellings for backward compatibility\n const isManualPurchaseManagement =\n manualPurchaseManagement ?? manualPurchaseManagment ?? false\n\n // Deep merge partial options with defaults to ensure all required fields are present\n const mergedOptions = {\n ...DefaultSuperwallOptions,\n ...restOptions,\n paywalls: {\n ...DefaultSuperwallOptions.paywalls,\n ...restOptions.paywalls,\n restoreFailed: {\n ...DefaultSuperwallOptions.paywalls.restoreFailed,\n ...restOptions.paywalls?.restoreFailed,\n },\n },\n logging: {\n ...DefaultSuperwallOptions.logging,\n ...restOptions.logging,\n },\n }\n\n await SuperwallExpoModule.configure(\n apiKey,\n mergedOptions,\n isManualPurchaseManagement,\n pkg.version,\n )\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n\n set({\n isConfigured: true,\n isLoading: false,\n configurationError: null,\n user: currentUser as UserAttributes,\n subscriptionStatus,\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n set({\n isLoading: false,\n configurationError: errorMessage,\n })\n // Don't throw - let developers handle via state or callback\n }\n },\n identify: async (userId, options) => {\n await SuperwallExpoModule.identify(userId, options)\n\n // TODO: Instead of setting users after identify, we should set this based on an event\n await new Promise((resolve) => setTimeout(resolve, 0))\n\n const [currentUser, subscriptionStatus] = await Promise.all([\n SuperwallExpoModule.getUserAttributes(),\n SuperwallExpoModule.getSubscriptionStatus(),\n ])\n\n set({ user: currentUser as UserAttributes, subscriptionStatus })\n },\n reset: async () => {\n await SuperwallExpoModule.reset()\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n\n set({ user: currentUser as UserAttributes, subscriptionStatus })\n },\n registerPlacement: async (placement, params, handlerId = \"default\") => {\n await SuperwallExpoModule.registerPlacement(placement, params, handlerId)\n },\n getPresentationResult: async (placement, params) => {\n return SuperwallExpoModule.getPresentationResult(placement, params)\n },\n restorePurchases: async () => {\n return SuperwallExpoModule.restorePurchases()\n },\n dismiss: async () => {\n await SuperwallExpoModule.dismiss()\n },\n preloadAllPaywalls: async () => {\n SuperwallExpoModule.preloadAllPaywalls()\n },\n preloadPaywalls: async (placements) => {\n SuperwallExpoModule.preloadPaywalls(placements)\n },\n setUserAttributes: async (attrs) => {\n await SuperwallExpoModule.setUserAttributes(filterUndefined(attrs))\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n set({ user: currentUser as UserAttributes })\n },\n getUserAttributes: async () => {\n const attributes = await SuperwallExpoModule.getUserAttributes()\n set({ user: attributes as UserAttributes })\n return attributes\n },\n setLogLevel: async (level) => {\n SuperwallExpoModule.setLogLevel(level)\n },\n\n setIntegrationAttributes: async (attributes) => {\n await SuperwallExpoModule.setIntegrationAttributes(attributes)\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n set({ user: currentUser as UserAttributes })\n },\n\n getIntegrationAttributes: async () => {\n return SuperwallExpoModule.getIntegrationAttributes()\n },\n\n setSubscriptionStatus: async (status) => {\n await SuperwallExpoModule.setSubscriptionStatus(status)\n },\n getDeviceAttributes: async () => {\n const attributes = await SuperwallExpoModule.getDeviceAttributes()\n return attributes\n },\n getEntitlements: async () => {\n const entitlements = await SuperwallExpoModule.getEntitlements()\n return entitlements as EntitlementsInfo\n },\n\n /* -------------------- Listener helpers -------------------- */\n _initListeners: (): (() => void) => {\n // Use get() to read the state from within the store\n if (get().listenersInitialized) {\n console.warn(\"[Superwall] Listeners already initialized. Skipping.\")\n return () => {} // Return no-op cleanup\n }\n\n const subscriptions: { remove: () => void }[] = []\n\n subscriptions.push(\n SuperwallExpoModule.addListener(\n \"subscriptionStatusDidChange\",\n ({ to }: { to: SubscriptionStatus }) => {\n set({ subscriptionStatus: to })\n },\n ),\n )\n\n // Listen for configuration events\n subscriptions.push(\n SuperwallExpoModule.addListener(\"handleSuperwallEvent\", ({ eventInfo }) => {\n if (eventInfo.event.event === \"configFail\") {\n set({\n configurationError: \"Failed to load Superwall configuration\",\n isLoading: false,\n })\n } else if (eventInfo.event.event === \"configRefresh\") {\n // Clear any previous errors on successful refresh\n set({ configurationError: null })\n }\n }),\n )\n\n set({ listenersInitialized: true })\n console.log(\"[Superwall] Initialized listeners\", subscriptions.length)\n\n return (): void => {\n console.log(\"[Superwall] Cleaning up listeners\", subscriptions.length)\n // biome-ignore lint/suspicious/useIterableCallbackReturn: forEach is used for side effects only\n subscriptions.forEach((s) => s.remove())\n // Reset the state on cleanup\n set({ listenersInitialized: false })\n }\n },\n}))\n\n/**\n * @category Store\n * @since 0.0.15\n * Public interface for the Superwall store, excluding internal methods.\n */\nexport type PublicSuperwallStore = Omit<SuperwallStore, \"configure\" | \"reset\" | \"_initListeners\">\n\nexport const SuperwallContext = createContext<boolean>(false)\n\n/**\n * @category Hooks\n * @since 0.0.15\n * Core React hook for interacting with the Superwall SDK.\n *\n * This hook provides access to the Superwall store, which includes SDK state\n * (like configuration status, user information, subscription status) and actions\n * (like `identify`, `reset`, `registerPlacement`).\n *\n * It must be used within a component that is a descendant of `<SuperwallProvider />`.\n *\n * @template T - Optional type parameter for the selected state. Defaults to the entire `PublicSuperwallStore`.\n * @param selector - An optional function to select a specific slice of the store's state.\n * This is useful for performance optimization, as components will only re-render\n * if the selected part of the state changes. Uses shallow equality checking\n * via `zustand/shallow`. If omitted, the entire store is returned.\n * @returns The selected slice of the Superwall store state, or the entire store if no selector is provided.\n * @throws Error if used outside of a `SuperwallProvider`.\n *\n * @example\n * // Get the entire store\n * const superwall = useSuperwall();\n * console.log(superwall.isConfigured);\n * superwall.identify(\"user_123\");\n *\n * @example\n * // Select specific state properties\n * const { user, subscriptionStatus } = useSuperwall(state => ({\n * user: state.user,\n * subscriptionStatus: state.subscriptionStatus,\n * }));\n * console.log(user?.appUserId, subscriptionStatus?.status);\n */\nexport function useSuperwall<T = PublicSuperwallStore>(selector?: (state: SuperwallStore) => T): T {\n const inProvider = useContext(SuperwallContext)\n if (!inProvider) {\n throw new Error(\"useSuperwall must be used within a SuperwallProvider\")\n }\n\n const identity = (state: SuperwallStore) => state as unknown as T\n // biome-ignore lint/correctness/useHookAtTopLevel: good here\n return useSuperwallStore(selector ? useShallow(selector) : identity)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useSuperwall.js","sourceRoot":"","sources":["../../src/useSuperwall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAA;AAEjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AAOvD,OAAO,EAAE,uBAAuB,EAAgC,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAExC;;;;;;;;GAQG;AACH,SAAS,eAAe;IACtB,MAAM,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAA;IACzE,IAAI,YA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AAC,CAAA;AACtE,CAAC","sourcesContent":["import { createContext, useContext } from \"react\"\nimport { create } from \"zustand\"\nimport { useShallow } from \"zustand/shallow\"\nimport pkg from \"../package.json\"\nimport type { PresentationResult } from \"./compat/lib/PresentationResult\"\nimport { resolveLocalResources } from \"./localResources\"\nimport SuperwallExpoModule from \"./SuperwallExpoModule\"\nimport type {\n EntitlementsInfo,\n IntegrationAttributes,\n RestorationResultResponse,\n SubscriptionStatus,\n} from \"./SuperwallExpoModule.types\"\nimport { DefaultSuperwallOptions, type PartialSuperwallOptions } from \"./SuperwallOptions\"\nimport { filterUndefined } from \"./utils/filterUndefined\"\n\nconst CONFIGURE_WAIT_TIMEOUT_MS = 10_000\n\n/**\n * Blocks a native call until Superwall has finished configuring.\n *\n * Resolves as soon as `isConfigured` flips true, rejects if configuration failed\n * (`configurationError`), and otherwise rejects after CONFIGURE_WAIT_TIMEOUT_MS.\n * The timeout clock (re)starts when configure() begins — so a configure() called\n * late still gets the full window — and the error distinguishes \"never called\"\n * from \"called but too slow\". Subscribes to the store rather than polling.\n */\nfunction awaitConfigured(): Promise<void> {\n const { isConfigured, configurationError } = useSuperwallStore.getState()\n if (isConfigured) return Promise.resolve()\n if (configurationError) return Promise.reject(new Error(configurationError))\n\n return new Promise<void>((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout>\n\n const settle = (fn: () => void) => {\n clearTimeout(timer)\n unsubscribe()\n fn()\n }\n\n // Restart the clock when configure starts so a late configure() gets the full\n // window instead of inheriting time already spent waiting before it ran.\n const arm = () => {\n clearTimeout(timer)\n timer = setTimeout(() => {\n const inFlight = useSuperwallStore.getState().isLoading\n settle(() =>\n reject(\n new Error(\n inFlight\n ? `Superwall configure did not complete within ${CONFIGURE_WAIT_TIMEOUT_MS}ms.`\n : `Superwall configure was not called within ${CONFIGURE_WAIT_TIMEOUT_MS}ms. Did you forget to call configure()?`,\n ),\n ),\n )\n }, CONFIGURE_WAIT_TIMEOUT_MS)\n }\n\n const unsubscribe = useSuperwallStore.subscribe((state, prev) => {\n if (state.isConfigured) {\n settle(resolve)\n } else if (state.configurationError) {\n const error = state.configurationError\n settle(() => reject(new Error(error)))\n } else if (state.isLoading && !prev.isLoading) {\n arm()\n }\n })\n\n arm()\n })\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Interface representing the attributes of a user.\n */\nexport interface UserAttributes {\n /** The user's alias ID, if set. */\n aliasId: string\n /** The user's application-specific user ID. */\n appUserId: string\n /** The ISO 8601 date string representation of when the application was installed on the user's device. */\n applicationInstalledAt: string\n /** A seed value associated with the user, used for consistent variant assignments in experiments. */\n seed: number\n /** Allows for custom attributes to be set for the user. These can be of any type. */\n [key: string]: any | null\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for the `identify` method.\n */\nexport interface IdentifyOptions {\n /**\n * Determines whether to restore paywall assignments from a previous session for the identified user.\n * If `true`, the SDK attempts to restore the assignments. Defaults to `false`.\n */\n restorePaywallAssignments?: boolean\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Defines the structure of the Superwall store, including its state and actions.\n * This store is managed by Zustand.\n */\nexport interface SuperwallStore {\n /* -------------------- State -------------------- */\n /** Indicates whether the Superwall SDK has been successfully configured. */\n isConfigured: boolean\n /** Indicates whether the SDK is currently performing a loading operation (e.g., configuring, fetching data). */\n isLoading: boolean\n /** Indicates whether the native event listeners have been initialized. */\n listenersInitialized: boolean\n\n /**\n * Contains error message if SDK configuration failed, `null` otherwise.\n * When this is set, the SDK is not configured and app should show error UI.\n */\n configurationError: string | null\n\n /**\n * The current user's attributes.\n * `null` if no user is identified or after `reset` is called.\n * `undefined` initially before any user data is fetched or set.\n */\n user?: UserAttributes | null\n\n /** The current subscription status of the user. */\n subscriptionStatus: SubscriptionStatus\n\n /* -------------------- Internal -------------------- */\n // Internal listener references for cleanup handled inside Provider effect.\n // Not reactive, so we store outside Zustand state to avoid unnecessary rerenders.\n\n /* -------------------- Actions -------------------- */\n /**\n * Configures the Superwall SDK with the provided API key and options.\n * This must be called before most other SDK functions can be used.\n * @param apiKey - Your Superwall API key.\n * @param options - Optional configuration settings for the SDK.\n * @returns A promise that resolves when configuration is complete.\n * @internal\n */\n configure: (\n apiKey: string,\n options?: PartialSuperwallOptions & {\n /** @deprecated Use manualPurchaseManagement instead */\n manualPurchaseManagment?: boolean\n },\n ) => Promise<void>\n /**\n * Identifies the current user with a unique ID.\n * @param userId - The unique identifier for the user.\n * @param options - Optional parameters for identification.\n * @returns A promise that resolves when identification is complete.\n */\n identify: (userId: string, options?: IdentifyOptions) => Promise<void>\n /**\n * Resets the user's identity and clears all user-specific data, effectively logging them out.\n * @internal\n */\n reset: () => Promise<void>\n\n /**\n * Registers a placement to potentially show a paywall.\n * The decision to show a paywall is determined by campaign rules and user assignments on the Superwall dashboard.\n * @param placement - The ID of the placement to register.\n * @param params - Optional parameters to pass with the placement.\n * @param handlerId - An optional identifier used to associate specific event handlers (e.g., from `usePlacement`). Defaults to \"default\".\n * @returns A promise that resolves when the placement registration is complete.\n */\n registerPlacement: (\n placement: string,\n params?: Record<string, any>,\n handlerId?: string | null,\n ) => Promise<void>\n /**\n * Retrieves the presentation result for a given placement.\n * This can be used to understand what would happen if a placement were to be registered, without actually registering it.\n * @param placement - The ID of the placement.\n * @param params - Optional parameters for the placement.\n * @returns A promise that resolves with the presentation result.\n */\n getPresentationResult: (\n placement: string,\n params?: Record<string, any>,\n ) => Promise<PresentationResult>\n /**\n * Programmatically restores purchases.\n * @returns A promise that resolves with a {@link RestorationResultResponse} indicating success or failure.\n */\n restorePurchases: () => Promise<RestorationResultResponse>\n\n /**\n * Dismisses any currently presented Superwall paywall.\n * @returns A promise that resolves when the dismissal is complete.\n */\n dismiss: () => Promise<void>\n\n /**\n * Preloads all paywalls configured in your Superwall dashboard.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadAllPaywalls: () => Promise<void>\n /**\n * Preloads specific paywalls.\n * @param placements - An array of placement IDs for which to preload paywalls.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadPaywalls: (placements: string[]) => Promise<void>\n\n /**\n * Sets custom attributes for the current user.\n * @param attrs - An object containing the attributes to set.\n * @returns A promise that resolves when attributes are set.\n */\n setUserAttributes: (attrs: Record<string, any | null>) => Promise<void>\n /**\n * Retrieves the current user's attributes.\n * @returns A promise that resolves with the user's attributes.\n */\n getUserAttributes: () => Promise<Record<string, any>>\n\n /**\n * Sets the logging level for the Superwall SDK.\n * @param level - The desired log level (e.g., \"debug\", \"info\", \"warn\", \"error\", \"none\").\n * @returns A promise that resolves when the log level is set.\n */\n setLogLevel: (level: string) => Promise<void>\n\n /**\n * Sets attributes for third-party integrations.\n * @param attributes - Object mapping IntegrationAttribute string values to their IDs\n * @returns A promise that resolves when attributes are set\n */\n setIntegrationAttributes: (attributes: IntegrationAttributes) => Promise<void>\n\n /**\n * Gets the currently set integration attributes.\n * @returns A promise that resolves with the current integration attributes\n */\n getIntegrationAttributes: () => Promise<Record<string, string>>\n\n /* -------------------- Listener helpers -------------------- */\n /**\n * Initializes native event listeners for the SDK.\n * This is typically called internally by the `SuperwallProvider`.\n * @returns A cleanup function to remove the listeners.\n * @internal\n */\n _initListeners: () => () => void\n\n setSubscriptionStatus: (status: SubscriptionStatus) => Promise<void>\n\n getDeviceAttributes: () => Promise<Record<string, any>>\n\n /**\n * Retrieves the user's entitlements from Superwall's servers.\n * This includes both active and inactive entitlements.\n * @returns A promise that resolves with the entitlements information.\n */\n getEntitlements: () => Promise<EntitlementsInfo>\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Zustand store for Superwall SDK state and actions.\n * @internal\n */\nexport const useSuperwallStore = create<SuperwallStore>((set, get) => ({\n /* -------------------- State -------------------- */\n isConfigured: false,\n isLoading: false,\n listenersInitialized: false,\n configurationError: null,\n\n user: null,\n subscriptionStatus: {\n status: \"UNKNOWN\",\n },\n\n /* -------------------- Actions -------------------- */\n configure: async (apiKey, options) => {\n set({ isLoading: true, configurationError: null })\n\n try {\n const { manualPurchaseManagement, manualPurchaseManagment, localResources, ...restOptions } =\n options || {}\n\n // Support both spellings for backward compatibility\n const isManualPurchaseManagement =\n manualPurchaseManagement ?? manualPurchaseManagment ?? false\n\n const resolvedLocalResources = await resolveLocalResources(localResources)\n\n // Deep merge partial options with defaults to ensure all required fields are present\n const mergedOptions = {\n ...DefaultSuperwallOptions,\n ...restOptions,\n ...(resolvedLocalResources ? { localResources: resolvedLocalResources } : {}),\n paywalls: {\n ...DefaultSuperwallOptions.paywalls,\n ...restOptions.paywalls,\n restoreFailed: {\n ...DefaultSuperwallOptions.paywalls.restoreFailed,\n ...restOptions.paywalls?.restoreFailed,\n },\n },\n logging: {\n ...DefaultSuperwallOptions.logging,\n ...restOptions.logging,\n },\n }\n\n await SuperwallExpoModule.configure(\n apiKey,\n mergedOptions,\n isManualPurchaseManagement,\n pkg.version,\n )\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n\n set({\n isConfigured: true,\n isLoading: false,\n configurationError: null,\n user: currentUser as UserAttributes,\n subscriptionStatus,\n })\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error)\n set({\n isLoading: false,\n configurationError: errorMessage,\n })\n // Don't throw - let developers handle via state or callback\n }\n },\n identify: async (userId, options) => {\n await awaitConfigured()\n await SuperwallExpoModule.identify(userId, options)\n\n // TODO: Instead of setting users after identify, we should set this based on an event\n await new Promise((resolve) => setTimeout(resolve, 0))\n\n const [currentUser, subscriptionStatus] = await Promise.all([\n SuperwallExpoModule.getUserAttributes(),\n SuperwallExpoModule.getSubscriptionStatus(),\n ])\n\n set({ user: currentUser as UserAttributes, subscriptionStatus })\n },\n reset: async () => {\n await awaitConfigured()\n await SuperwallExpoModule.reset()\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n\n set({ user: currentUser as UserAttributes, subscriptionStatus })\n },\n registerPlacement: async (placement, params, handlerId = \"default\") => {\n await awaitConfigured()\n await SuperwallExpoModule.registerPlacement(placement, params, handlerId)\n },\n getPresentationResult: async (placement, params) => {\n await awaitConfigured()\n return SuperwallExpoModule.getPresentationResult(placement, params)\n },\n restorePurchases: async () => {\n await awaitConfigured()\n return SuperwallExpoModule.restorePurchases()\n },\n dismiss: async () => {\n await awaitConfigured()\n await SuperwallExpoModule.dismiss()\n },\n preloadAllPaywalls: async () => {\n await awaitConfigured()\n await SuperwallExpoModule.preloadAllPaywalls()\n },\n preloadPaywalls: async (placements) => {\n await awaitConfigured()\n await SuperwallExpoModule.preloadPaywalls(placements)\n },\n setUserAttributes: async (attrs) => {\n await awaitConfigured()\n await SuperwallExpoModule.setUserAttributes(filterUndefined(attrs))\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n set({ user: currentUser as UserAttributes })\n },\n getUserAttributes: async () => {\n await awaitConfigured()\n const attributes = await SuperwallExpoModule.getUserAttributes()\n set({ user: attributes as UserAttributes })\n return attributes\n },\n setLogLevel: async (level) => {\n await awaitConfigured()\n await SuperwallExpoModule.setLogLevel(level)\n },\n\n setIntegrationAttributes: async (attributes) => {\n await awaitConfigured()\n await SuperwallExpoModule.setIntegrationAttributes(attributes)\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n set({ user: currentUser as UserAttributes })\n },\n\n getIntegrationAttributes: async () => {\n await awaitConfigured()\n return SuperwallExpoModule.getIntegrationAttributes()\n },\n\n setSubscriptionStatus: async (status) => {\n await awaitConfigured()\n await SuperwallExpoModule.setSubscriptionStatus(status)\n },\n getDeviceAttributes: async () => {\n await awaitConfigured()\n const attributes = await SuperwallExpoModule.getDeviceAttributes()\n return attributes\n },\n getEntitlements: async () => {\n await awaitConfigured()\n const entitlements = await SuperwallExpoModule.getEntitlements()\n return entitlements as EntitlementsInfo\n },\n\n /* -------------------- Listener helpers -------------------- */\n _initListeners: (): (() => void) => {\n // Use get() to read the state from within the store\n if (get().listenersInitialized) {\n console.warn(\"[Superwall] Listeners already initialized. Skipping.\")\n return () => {} // Return no-op cleanup\n }\n\n const subscriptions: { remove: () => void }[] = []\n\n subscriptions.push(\n SuperwallExpoModule.addListener(\n \"subscriptionStatusDidChange\",\n ({ to }: { to: SubscriptionStatus }) => {\n set({ subscriptionStatus: to })\n },\n ),\n )\n\n // Listen for configuration events\n subscriptions.push(\n SuperwallExpoModule.addListener(\"handleSuperwallEvent\", ({ eventInfo }) => {\n if (eventInfo.event.event === \"configFail\") {\n set({\n configurationError: \"Failed to load Superwall configuration\",\n isLoading: false,\n })\n } else if (eventInfo.event.event === \"configRefresh\") {\n // Clear any previous errors on successful refresh\n set({ configurationError: null })\n }\n }),\n )\n\n set({ listenersInitialized: true })\n console.log(\"[Superwall] Initialized listeners\", subscriptions.length)\n\n return (): void => {\n console.log(\"[Superwall] Cleaning up listeners\", subscriptions.length)\n // biome-ignore lint/suspicious/useIterableCallbackReturn: forEach is used for side effects only\n subscriptions.forEach((s) => s.remove())\n // Reset the state on cleanup\n set({ listenersInitialized: false })\n }\n },\n}))\n\n/**\n * @category Store\n * @since 0.0.15\n * Public interface for the Superwall store, excluding internal methods.\n */\nexport type PublicSuperwallStore = Omit<SuperwallStore, \"configure\" | \"reset\" | \"_initListeners\">\n\nexport const SuperwallContext = createContext<boolean>(false)\n\n/**\n * @category Hooks\n * @since 0.0.15\n * Core React hook for interacting with the Superwall SDK.\n *\n * This hook provides access to the Superwall store, which includes SDK state\n * (like configuration status, user information, subscription status) and actions\n * (like `identify`, `reset`, `registerPlacement`).\n *\n * It must be used within a component that is a descendant of `<SuperwallProvider />`.\n *\n * @template T - Optional type parameter for the selected state. Defaults to the entire `PublicSuperwallStore`.\n * @param selector - An optional function to select a specific slice of the store's state.\n * This is useful for performance optimization, as components will only re-render\n * if the selected part of the state changes. Uses shallow equality checking\n * via `zustand/shallow`. If omitted, the entire store is returned.\n * @returns The selected slice of the Superwall store state, or the entire store if no selector is provided.\n * @throws Error if used outside of a `SuperwallProvider`.\n *\n * @example\n * // Get the entire store\n * const superwall = useSuperwall();\n * console.log(superwall.isConfigured);\n * superwall.identify(\"user_123\");\n *\n * @example\n * // Select specific state properties\n * const { user, subscriptionStatus } = useSuperwall(state => ({\n * user: state.user,\n * subscriptionStatus: state.subscriptionStatus,\n * }));\n * console.log(user?.appUserId, subscriptionStatus?.status);\n */\nexport function useSuperwall<T = PublicSuperwallStore>(selector?: (state: SuperwallStore) => T): T {\n const inProvider = useContext(SuperwallContext)\n if (!inProvider) {\n throw new Error(\"useSuperwall must be used within a SuperwallProvider\")\n }\n\n const identity = (state: SuperwallStore) => state as unknown as T\n // biome-ignore lint/correctness/useHookAtTopLevel: good here\n return useSuperwallStore(selector ? useShallow(selector) : identity)\n}\n"]}
|
|
@@ -48,6 +48,15 @@ extension SuperwallOptions {
|
|
|
48
48
|
superwallOptions.maxConfigRetryCount = maxConfigRetryCount
|
|
49
49
|
superwallOptions.testModeBehavior = testModeBehavior
|
|
50
50
|
|
|
51
|
+
if let localResourcesValue = dictionary["localResources"] as? [String: String] {
|
|
52
|
+
superwallOptions.localResources = localResourcesValue.compactMapValues { value in
|
|
53
|
+
if let url = URL(string: value), url.scheme != nil {
|
|
54
|
+
return url
|
|
55
|
+
}
|
|
56
|
+
return URL(fileURLWithPath: value)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
51
60
|
return superwallOptions
|
|
52
61
|
}
|
|
53
62
|
}
|
|
@@ -2,6 +2,35 @@ require 'json'
|
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
4
|
|
|
5
|
+
# expo-superwall supports Expo SDK 53+, and ExpoModulesCore's minimum iOS/tvOS
|
|
6
|
+
# deployment target differs per SDK (15.1 on SDK 53, 16.4 on SDK 56+). We have
|
|
7
|
+
# to land between two hard constraints:
|
|
8
|
+
# * Lower than ExpoModulesCore's target → Swift refuses to import it
|
|
9
|
+
# ("module 'ExpoModulesCore' has a minimum deployment target of iOS 16.4").
|
|
10
|
+
# * Higher than the host app's Podfile platform → CocoaPods refuses to
|
|
11
|
+
# install ("required a higher minimum deployment target").
|
|
12
|
+
# So we mirror the ExpoModulesCore that's actually installed, never dropping
|
|
13
|
+
# below our own 15.1 floor. One podspec stays correct across every supported
|
|
14
|
+
# SDK (and any future bump) without forcing a value on anyone.
|
|
15
|
+
expo_modules_core_podspec = begin
|
|
16
|
+
resolved = `node --print "require.resolve('expo-modules-core/package.json')" 2>/dev/null`.strip
|
|
17
|
+
[
|
|
18
|
+
(resolved.empty? ? nil : File.join(File.dirname(resolved), 'ExpoModulesCore.podspec')),
|
|
19
|
+
File.join(__dir__, '..', '..', 'expo-modules-core', 'ExpoModulesCore.podspec'),
|
|
20
|
+
].compact.find { |path| File.exist?(path) }
|
|
21
|
+
rescue StandardError
|
|
22
|
+
# `node` may be unavailable (e.g. resolving from a tarball); fall back to the
|
|
23
|
+
# 15.1 floor below.
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
expo_modules_core_contents = expo_modules_core_podspec ? File.read(expo_modules_core_podspec) : ''
|
|
28
|
+
|
|
29
|
+
deployment_target = lambda do |platform, floor|
|
|
30
|
+
found = expo_modules_core_contents[/:#{platform}\s*=>\s*(['"])([\d.]+)\1/, 2]
|
|
31
|
+
[floor, found].compact.max_by { |version| Gem::Version.new(version) }
|
|
32
|
+
end
|
|
33
|
+
|
|
5
34
|
Pod::Spec.new do |s|
|
|
6
35
|
s.name = 'SuperwallExpo'
|
|
7
36
|
s.version = package['version']
|
|
@@ -11,8 +40,8 @@ Pod::Spec.new do |s|
|
|
|
11
40
|
s.author = package['author']
|
|
12
41
|
s.homepage = package['homepage']
|
|
13
42
|
s.platforms = {
|
|
14
|
-
:ios => '15.1',
|
|
15
|
-
:tvos => '15.1'
|
|
43
|
+
:ios => deployment_target.call(:ios, '15.1'),
|
|
44
|
+
:tvos => deployment_target.call(:tvos, '15.1')
|
|
16
45
|
}
|
|
17
46
|
s.swift_version = '5.4'
|
|
18
47
|
s.source = { git: 'https://github.com/superwall/expo-superwall' }
|