expo-superwall 1.1.1 → 1.1.3
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/build.gradle +1 -1
- package/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt +9 -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/usePlacement.d.ts.map +1 -1
- package/build/src/usePlacement.js +10 -9
- package/build/src/usePlacement.js.map +1 -1
- package/build/src/useSuperwall.d.ts.map +1 -1
- package/build/src/useSuperwall.js +4 -1
- package/build/src/useSuperwall.js.map +1 -1
- package/ios/Json/SuperwallOptions+Json.swift +9 -0
- package/ios/SuperwallExpo.podspec +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a8ba5af: Add localResources resolving for expo
|
|
8
|
+
|
|
9
|
+
## 1.1.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- a03889a: Ensure register callbacks resolve properly in all cases
|
|
14
|
+
- 09f7538: Bump Android & iOS versions
|
|
15
|
+
|
|
3
16
|
## 1.1.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/android/build.gradle
CHANGED
|
@@ -43,7 +43,7 @@ android {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
dependencies {
|
|
46
|
-
implementation "com.superwall.sdk:superwall-android:2.7.
|
|
46
|
+
implementation "com.superwall.sdk:superwall-android:2.7.15"
|
|
47
47
|
implementation 'com.android.billingclient:billing:8.0.0'
|
|
48
48
|
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2'
|
|
49
49
|
}
|
|
@@ -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
|
}
|
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,iBAAiB,GACjB,YAAY,GACZ,UAAU,GACV,eAAe,GACf,qBAAqB,GACrB,qBAAqB,GACrB,uBAAuB,GACvB,OAAO,GACP,KAAK,CAAA;AAET;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,kBAAkB,GAAG,WAAW,CAAA;AAE7E;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,MAAM,CAAA;AAE1D;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,oBAAoB,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEtF;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,QAAQ,CAAA;IACf,MAAM,EAAE,QAAQ,EAAE,CAAA;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,uBAAuB,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":["../../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;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;AACtE,mBAAmB,6BAA6B,CAAA;AAChD,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAA;AAC3B,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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","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;AACtE,mBAAmB,6BAA6B,CAAA;AAChD,YAAY,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAA;AAC3B,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"}
|
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,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,MAAM,KAAK,CAAC,aAAa,EAAE,CAAA;QAC7B,CAAC;QACD,OAAO,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAA;IACpC,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAA;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAAgD;IAEhD,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC9B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAEtC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAE,CAAC,CAAA;YAClD,OAAO,CAAC,EAAE,EAAE,GAAG,CAAU,CAAA;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YAC3E,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC,CAAC,CACH,CAAA;IAED,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,EAAsC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAA;IAC9F,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,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":"usePlacement.d.ts","sourceRoot":"","sources":["../../src/usePlacement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,oBAAoB,EACrB,MAAM,6BAA6B,CAAA;AAKpC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAE,GACjD;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GAC9C;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAA;CAAE,GACnD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtC;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAA;IAC9C,0CAA0C;IAC1C,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,KAAK,IAAI,CAAA;IACrE,wCAAwC;IACxC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAA;IAC/C,0EAA0E;IAC1E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC;;;OA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,MAAM,EAAE,aAAa,KAAK,IAAI,CAAA;IACrE,wCAAwC;IACxC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAA;IAC/C,0EAA0E;IAC1E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,OAAO,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAAA;CACtG;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAA;IACjB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,YAAY,CAAC,SAAS,GAAE,qBAA0B;iEAmDvB,qBAAqB;;EAiB/D"}
|
|
@@ -63,21 +63,16 @@ export function usePlacement(callbacks = {}) {
|
|
|
63
63
|
handlerId: id,
|
|
64
64
|
onPaywallDismiss(info, result) {
|
|
65
65
|
setState({ status: "dismissed", result });
|
|
66
|
-
if (result.type === "purchased" || result.type === "restored") {
|
|
67
|
-
runPendingFeature();
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
clearPendingFeature();
|
|
71
|
-
}
|
|
72
66
|
callbacks.onDismiss?.(info, result);
|
|
73
67
|
},
|
|
74
68
|
onPaywallSkip(reason) {
|
|
75
69
|
setState({ status: "skipped", reason });
|
|
76
|
-
runPendingFeature();
|
|
77
70
|
callbacks.onSkip?.(reason);
|
|
78
71
|
},
|
|
79
72
|
onPaywallError(error) {
|
|
80
73
|
setState({ status: "error", error });
|
|
74
|
+
// Native won't resolve the register promise on error, so drop the pending
|
|
75
|
+
// feature here to avoid firing it on a later unrelated registerPlacement.
|
|
81
76
|
clearPendingFeature();
|
|
82
77
|
callbacks.onError?.(error);
|
|
83
78
|
},
|
|
@@ -91,16 +86,22 @@ export function usePlacement(callbacks = {}) {
|
|
|
91
86
|
registerPlacement: state.registerPlacement,
|
|
92
87
|
}));
|
|
93
88
|
/* -------------------- Helpers -------------------- */
|
|
89
|
+
// The native module passes a feature closure to Superwall.register; that closure
|
|
90
|
+
// resolves this promise. The native SDK only invokes it when access is granted —
|
|
91
|
+
// including Non-Gated dismissals, skips, and successful purchases — so awaiting
|
|
92
|
+
// the promise is the correct gate for running `feature`. Letting JS infer this
|
|
93
|
+
// from dismiss `result.type` is wrong: it can't distinguish Gated from Non-Gated.
|
|
94
94
|
const registerPlacement = useCallback(async ({ placement, params, feature }) => {
|
|
95
95
|
pendingFeatureRef.current = feature;
|
|
96
96
|
try {
|
|
97
97
|
await storeRegisterPlacement(placement, params, id);
|
|
98
|
+
runPendingFeature();
|
|
98
99
|
}
|
|
99
100
|
catch (error) {
|
|
100
|
-
|
|
101
|
+
clearPendingFeature();
|
|
101
102
|
throw error;
|
|
102
103
|
}
|
|
103
|
-
}, [storeRegisterPlacement, id]);
|
|
104
|
+
}, [storeRegisterPlacement, id, runPendingFeature, clearPendingFeature]);
|
|
104
105
|
return {
|
|
105
106
|
registerPlacement,
|
|
106
107
|
state,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePlacement.js","sourceRoot":"","sources":["../../src/usePlacement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAS5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAmDzD,iDAAiD;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,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,CAAC,CAAA;QAC7B,CAAC;QACD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;KAC7C,CAAC,CAAA;IAEF,MAAM,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,GAAG,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7E,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;KAC3C,CAAC,CAAC,CAAA;IAEH,uDAAuD;IACvD,iFAAiF;IACjF,iFAAiF;IACjF,gFAAgF;IAChF,+EAA+E;IAC/E,kFAAkF;IAClF,MAAM,iBAAiB,GAAG,WAAW,CACnC,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAyB,EAAE,EAAE;QAC9D,iBAAiB,CAAC,OAAO,GAAG,OAAO,CAAA;QACnC,IAAI,CAAC;YACH,MAAM,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;YACnD,iBAAiB,EAAE,CAAA;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,mBAAmB,EAAE,CAAA;YACrB,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,EACD,CAAC,sBAAsB,EAAE,EAAE,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CACrE,CAAA;IAED,OAAO;QACL,iBAAiB;QACjB,KAAK;KACG,CAAA;AACZ,CAAC","sourcesContent":["import { useCallback, useId, useRef, useState } from \"react\"\n\nimport type {\n CustomCallback,\n CustomCallbackResult,\n PaywallInfo,\n PaywallResult,\n PaywallSkippedReason,\n} from \"./SuperwallExpoModule.types\"\nimport { useSuperwall } from \"./useSuperwall\"\nimport { useSuperwallEvents } from \"./useSuperwallEvents\"\n\n// -------------------- Types --------------------\n/**\n * @category Hooks\n * @since 0.0.15\n * Possible states returned by `usePlacement`.\n */\nexport type PaywallState =\n | { status: \"idle\" }\n | { status: \"presented\"; paywallInfo: PaywallInfo }\n | { status: \"dismissed\"; result: PaywallResult }\n | { status: \"skipped\"; reason: PaywallSkippedReason }\n | { status: \"error\"; error: string }\n\n/**\n * @category Hooks\n * @since 0.0.15\n */\nexport interface usePlacementCallbacks {\n /** Called when a paywall is presented. */\n onPresent?: (paywallInfo: PaywallInfo) => void\n /** Called when a paywall is dismissed. */\n onDismiss?: (paywallInfo: PaywallInfo, result: PaywallResult) => void\n /** Called when a paywall is skipped. */\n onSkip?: (reason: PaywallSkippedReason) => void\n /** Called when a paywall fails to present or another SDK error occurs. */\n onError?: (error: string) => void\n /**\n * Called when a custom callback is invoked from a paywall.\n * Return a result to send back to the paywall.\n */\n onCustomCallback?: (callback: CustomCallback) => Promise<CustomCallbackResult> | CustomCallbackResult\n}\n\n/**\n * @category Hooks\n * @since 0.0.15\n */\nexport interface RegisterPlacementArgs {\n /** The placement name defined on the Superwall dashboard. */\n placement: string\n /** Optional parameters passed to the placement. */\n params?: Record<string, any>\n /**\n * An optional feature/function to execute if the placement does **not** result\n * in a paywall presentation – i.e. the user is allowed through.\n */\n feature?: () => void\n}\n\n// -------------------- Hook --------------------\n/**\n * @category Hooks\n * @since 0.0.15\n * React hook for managing paywall presentation based on placements.\n *\n * This hook provides a way to register placements configured on the Superwall dashboard.\n * It handles the state of paywall presentation (`PaywallState`) and allows you\n * to define callbacks for various paywall lifecycle events (`usePlacementCallbacks`).\n *\n * It must be used within a component that is a descendant of `<SuperwallProvider />`.\n *\n * @param callbacks - An optional object containing callback functions for paywall events\n * like `onPresent`, `onDismiss`, `onSkip`, and `onError`.\n * @returns An object containing:\n * - `registerPlacement: (args: RegisterPlacementArgs) => Promise<void>`:\n * A function to register a placement and potentially trigger a paywall.\n * - `args.placement`: The placement name defined on the Superwall dashboard.\n * - `args.params`: Optional parameters to pass to the placement.\n * - `args.feature`: An optional function to execute if the placement does not result\n * in a paywall presentation (e.g., user is already subscribed or part of a holdout).\n * - `state: PaywallState`: The current state of the paywall interaction for this hook instance.\n * This includes states like \"idle\", \"presented\", \"dismissed\", \"skipped\", or \"error\".\n *\n * @example\n * const { registerPlacement, state } = usePlacement({\n * onPresent: (paywallInfo) => console.log(\"Paywall presented:\", paywallInfo.name),\n * onDismiss: (paywallInfo, result) => console.log(\"Paywall dismissed:\", result.type),\n * onSkip: (reason) => console.log(\"Paywall skipped:\", reason.type),\n * onError: (error) => console.error(\"Paywall error:\", error),\n * });\n *\n * const showMyFeaturePaywall = async () => {\n * await registerPlacement({\n * placement: \"MyFeaturePlacement\",\n * feature: () => {\n * // Logic to execute if paywall is not shown (e.g., navigate to feature)\n * console.log(\"Accessing feature directly.\");\n * }\n * });\n * };\n *\n * // In your component:\n * // <Button title=\"Unlock Feature\" onPress={showMyFeaturePaywall} />\n * // <Text>Current paywall state: {state.status}</Text>\n */\nexport function usePlacement(callbacks: usePlacementCallbacks = {}) {\n const id = useId()\n\n const [state, setState] = useState<PaywallState>({ status: \"idle\" })\n const pendingFeatureRef = useRef<RegisterPlacementArgs[\"feature\"]>(undefined)\n\n const clearPendingFeature = useCallback(() => {\n pendingFeatureRef.current = undefined\n }, [])\n\n const runPendingFeature = useCallback(() => {\n const feature = pendingFeatureRef.current\n pendingFeatureRef.current = undefined\n feature?.()\n }, [])\n\n useSuperwallEvents({\n handlerId: id,\n onPaywallDismiss(info, result) {\n setState({ status: \"dismissed\", result })\n callbacks.onDismiss?.(info, result)\n },\n onPaywallSkip(reason) {\n setState({ status: \"skipped\", reason })\n callbacks.onSkip?.(reason)\n },\n onPaywallError(error) {\n setState({ status: \"error\", error })\n // Native won't resolve the register promise on error, so drop the pending\n // feature here to avoid firing it on a later unrelated registerPlacement.\n clearPendingFeature()\n callbacks.onError?.(error)\n },\n onPaywallPresent(info) {\n setState({ status: \"presented\", paywallInfo: info })\n callbacks.onPresent?.(info)\n },\n onCustomCallback: callbacks.onCustomCallback,\n })\n\n const { registerPlacement: storeRegisterPlacement } = useSuperwall((state) => ({\n registerPlacement: state.registerPlacement,\n }))\n\n /* -------------------- Helpers -------------------- */\n // The native module passes a feature closure to Superwall.register; that closure\n // resolves this promise. The native SDK only invokes it when access is granted —\n // including Non-Gated dismissals, skips, and successful purchases — so awaiting\n // the promise is the correct gate for running `feature`. Letting JS infer this\n // from dismiss `result.type` is wrong: it can't distinguish Gated from Non-Gated.\n const registerPlacement = useCallback(\n async ({ placement, params, feature }: RegisterPlacementArgs) => {\n pendingFeatureRef.current = feature\n try {\n await storeRegisterPlacement(placement, params, id)\n runPendingFeature()\n } catch (error) {\n clearPendingFeature()\n throw error\n }\n },\n [storeRegisterPlacement, id, runPendingFeature, clearPendingFeature],\n )\n\n return {\n registerPlacement,\n state,\n } as const\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,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAA2B,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAG1F;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAA;IACjB,0GAA0G;IAC1G,sBAAsB,EAAE,MAAM,CAAA;IAC9B,qGAAqG;IACrG,IAAI,EAAE,MAAM,CAAA;IACZ,qFAAqF;IACrF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAAA;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OA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CAAgC,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,oBAAoB,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,GAAG,CAAC,CASjG"}
|
|
@@ -2,6 +2,7 @@ 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";
|
|
@@ -25,13 +26,15 @@ export const useSuperwallStore = create((set, get) => ({
|
|
|
25
26
|
configure: async (apiKey, options) => {
|
|
26
27
|
set({ isLoading: true, configurationError: null });
|
|
27
28
|
try {
|
|
28
|
-
const { manualPurchaseManagement, manualPurchaseManagment, ...restOptions } = options || {};
|
|
29
|
+
const { manualPurchaseManagement, manualPurchaseManagment, localResources, ...restOptions } = options || {};
|
|
29
30
|
// Support both spellings for backward compatibility
|
|
30
31
|
const isManualPurchaseManagement = manualPurchaseManagement ?? manualPurchaseManagment ?? false;
|
|
32
|
+
const resolvedLocalResources = await resolveLocalResources(localResources);
|
|
31
33
|
// Deep merge partial options with defaults to ensure all required fields are present
|
|
32
34
|
const mergedOptions = {
|
|
33
35
|
...DefaultSuperwallOptions,
|
|
34
36
|
...restOptions,
|
|
37
|
+
...(resolvedLocalResources ? { localResources: resolvedLocalResources } : {}),
|
|
35
38
|
paywalls: {
|
|
36
39
|
...DefaultSuperwallOptions.paywalls,
|
|
37
40
|
...restOptions.paywalls,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuperwall.js","sourceRoot":"","sources":["../../src/useSuperwall.ts"],"names":[],"mappings":"AAAA,O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AC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;YACxC,6BAA6B;YAC7B,GAAG,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAA;QACtC,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAC,CAAA;AASH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAU,KAAK,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,YAAY,CAA2B,QAAuC;IAC5F,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,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;AACh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,OAAO,GAAS,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,mCAAmC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;YACtE,gGAAgG;YAChG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;YACxC,6BAA6B;YAC7B,GAAG,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAA;QACtC,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAC,CAAA;AASH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAU,KAAK,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,YAAY,CAA2B,QAAuC;IAC5F,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,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 { 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\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 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"]}
|
|
@@ -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
|
}
|