expo-superwall 0.7.0 → 0.7.2
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 +12 -0
- package/README.md +1 -0
- package/build/package.json +1 -1
- package/build/src/compat/lib/PaywallOptions.d.ts.map +1 -1
- package/build/src/compat/lib/PaywallOptions.js +17 -5
- package/build/src/compat/lib/PaywallOptions.js.map +1 -1
- package/build/src/compat/lib/SuperwallOptions.d.ts.map +1 -1
- package/build/src/compat/lib/SuperwallOptions.js +23 -6
- package/build/src/compat/lib/SuperwallOptions.js.map +1 -1
- package/build/src/useSuperwallEvents.d.ts.map +1 -1
- package/build/src/useSuperwallEvents.js +48 -79
- package/build/src/useSuperwallEvents.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/build/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaywallOptions.d.ts","sourceRoot":"","sources":["../../../../src/compat/lib/PaywallOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PaywallOptions.d.ts","sourceRoot":"","sources":["../../../../src/compat/lib/PaywallOptions.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,oBAAY,yBAAyB;IACnC,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAED;;;;GAIG;AACH,qBAAa,aAAa;IACxB,KAAK,SAA0B;IAC/B,OAAO,SAA8D;IACrE,gBAAgB,SAAS;IAEzB,MAAM,IAAI,MAAM;CAOjB;AAED;;;;GAIG;AACH,qBAAa,cAAc;IACzB,uBAAuB,UAAO;IAC9B,aAAa,EAAE,aAAa,CAAsB;IAClD,8BAA8B,UAAO;IACrC,aAAa,UAAQ;IACrB,oBAAoB,UAAO;IAC3B,yBAAyB,EAAE,yBAAyB,CAAoC;gBAE5E,IAAI,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IA2B1C,MAAM,IAAI,MAAM;CAUjB"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to remove undefined values from an object.
|
|
3
|
+
* This is necessary for Android compatibility as the Expo bridge
|
|
4
|
+
* cannot convert undefined to Kotlin types.
|
|
5
|
+
*/
|
|
6
|
+
function filterUndefined(obj) {
|
|
7
|
+
return Object.fromEntries(Object.entries(obj).filter(([_, value]) => value !== undefined));
|
|
8
|
+
}
|
|
1
9
|
/**
|
|
2
10
|
* @category Enums
|
|
3
11
|
* @since 0.0.15
|
|
@@ -18,11 +26,11 @@ export class RestoreFailed {
|
|
|
18
26
|
message = "We couldn't find an active subscription for your account.";
|
|
19
27
|
closeButtonTitle = "Okay";
|
|
20
28
|
toJson() {
|
|
21
|
-
return {
|
|
29
|
+
return filterUndefined({
|
|
22
30
|
title: this.title,
|
|
23
31
|
message: this.message,
|
|
24
32
|
closeButtonTitle: this.closeButtonTitle,
|
|
25
|
-
};
|
|
33
|
+
});
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
/**
|
|
@@ -55,19 +63,23 @@ export class PaywallOptions {
|
|
|
55
63
|
this.transactionBackgroundView = init.transactionBackgroundView;
|
|
56
64
|
}
|
|
57
65
|
if (init.restoreFailed) {
|
|
58
|
-
|
|
66
|
+
// Ensure restoreFailed is always a RestoreFailed instance
|
|
67
|
+
this.restoreFailed =
|
|
68
|
+
init.restoreFailed instanceof RestoreFailed
|
|
69
|
+
? init.restoreFailed
|
|
70
|
+
: Object.assign(new RestoreFailed(), init.restoreFailed);
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
73
|
}
|
|
62
74
|
toJson() {
|
|
63
|
-
return {
|
|
75
|
+
return filterUndefined({
|
|
64
76
|
isHapticFeedbackEnabled: this.isHapticFeedbackEnabled,
|
|
65
77
|
restoreFailed: this.restoreFailed.toJson(),
|
|
66
78
|
shouldShowPurchaseFailureAlert: this.shouldShowPurchaseFailureAlert,
|
|
67
79
|
shouldPreload: this.shouldPreload,
|
|
68
80
|
automaticallyDismiss: this.automaticallyDismiss,
|
|
69
81
|
transactionBackgroundView: this.transactionBackgroundView,
|
|
70
|
-
};
|
|
82
|
+
});
|
|
71
83
|
}
|
|
72
84
|
}
|
|
73
85
|
//# sourceMappingURL=PaywallOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaywallOptions.js","sourceRoot":"","sources":["../../../../src/compat/lib/PaywallOptions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAN,IAAY,yBAGX;AAHD,WAAY,yBAAyB;IACnC,gDAAmB,CAAA;IACnB,0CAAa,CAAA;AACf,CAAC,EAHW,yBAAyB,KAAzB,yBAAyB,QAGpC;AAED;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACxB,KAAK,GAAG,uBAAuB,CAAA;IAC/B,OAAO,GAAG,2DAA2D,CAAA;IACrE,gBAAgB,GAAG,MAAM,CAAA;IAEzB,MAAM;QACJ,OAAO;
|
|
1
|
+
{"version":3,"file":"PaywallOptions.js","sourceRoot":"","sources":["../../../../src/compat/lib/PaywallOptions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,SAAS,eAAe,CAAgC,GAAM;IAC5D,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAClD,CAAA;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,yBAGX;AAHD,WAAY,yBAAyB;IACnC,gDAAmB,CAAA;IACnB,0CAAa,CAAA;AACf,CAAC,EAHW,yBAAyB,KAAzB,yBAAyB,QAGpC;AAED;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACxB,KAAK,GAAG,uBAAuB,CAAA;IAC/B,OAAO,GAAG,2DAA2D,CAAA;IACrE,gBAAgB,GAAG,MAAM,CAAA;IAEzB,MAAM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CAAC,CAAC,IAAI,CAAC,aAAa;wBACpB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,aAAa,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;YAC9D,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO,eAAe,CAAC;YACrB,uBAAuB,EAAE,IAAI,CAAC,uBAAuB;YACrD,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;YAC1C,8BAA8B,EAAE,IAAI,CAAC,8BAA8B;YACnE,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,yBAAyB,EAAE,IAAI,CAAC,yBAAyB;SAC1D,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["/**\n * Helper function to remove undefined values from an object.\n * This is necessary for Android compatibility as the Expo bridge\n * cannot convert undefined to Kotlin types.\n */\nfunction filterUndefined<T extends Record<string, any>>(obj: T): Partial<T> {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, value]) => value !== undefined),\n ) as Partial<T>\n}\n\n/**\n * @category Enums\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 enum TransactionBackgroundView {\n spinner = \"spinner\",\n none = \"none\",\n}\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 class RestoreFailed {\n title = \"No Subscription Found\"\n message = \"We couldn't find an active subscription for your account.\"\n closeButtonTitle = \"Okay\"\n\n toJson(): object {\n return filterUndefined({\n title: this.title,\n message: this.message,\n closeButtonTitle: this.closeButtonTitle,\n })\n }\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for configuring the appearance and behavior of paywalls.\n */\nexport class PaywallOptions {\n isHapticFeedbackEnabled = true\n restoreFailed: RestoreFailed = new RestoreFailed()\n shouldShowPurchaseFailureAlert = true\n shouldPreload = false\n automaticallyDismiss = true\n transactionBackgroundView: TransactionBackgroundView = TransactionBackgroundView.spinner\n\n constructor(init?: Partial<PaywallOptions>) {\n if (init) {\n if (init.isHapticFeedbackEnabled !== undefined) {\n this.isHapticFeedbackEnabled = init.isHapticFeedbackEnabled\n }\n if (init.shouldShowPurchaseFailureAlert !== undefined) {\n this.shouldShowPurchaseFailureAlert = init.shouldShowPurchaseFailureAlert\n }\n if (init.shouldPreload !== undefined) {\n this.shouldPreload = init.shouldPreload\n }\n if (init.automaticallyDismiss !== undefined) {\n this.automaticallyDismiss = init.automaticallyDismiss\n }\n if (init.transactionBackgroundView) {\n this.transactionBackgroundView = init.transactionBackgroundView\n }\n if (init.restoreFailed) {\n // Ensure restoreFailed is always a RestoreFailed instance\n this.restoreFailed =\n init.restoreFailed instanceof RestoreFailed\n ? init.restoreFailed\n : Object.assign(new RestoreFailed(), init.restoreFailed)\n }\n }\n }\n\n toJson(): object {\n return filterUndefined({\n isHapticFeedbackEnabled: this.isHapticFeedbackEnabled,\n restoreFailed: this.restoreFailed.toJson(),\n shouldShowPurchaseFailureAlert: this.shouldShowPurchaseFailureAlert,\n shouldPreload: this.shouldPreload,\n automaticallyDismiss: this.automaticallyDismiss,\n transactionBackgroundView: this.transactionBackgroundView,\n })\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuperwallOptions.d.ts","sourceRoot":"","sources":["../../../../src/compat/lib/SuperwallOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"SuperwallOptions.d.ts","sourceRoot":"","sources":["../../../../src/compat/lib/SuperwallOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAajD;;;;GAIG;AACH,oBAAY,kBAAkB;IAC5B,OAAO,YAAY;IACnB,gBAAgB,qBAAqB;IACrC,SAAS,cAAc;CACxB;AAED;;;;GAIG;AACH,qBAAa,cAAc;IACzB,KAAK,EAAE,QAAQ,CAAgB;IAC/B,MAAM,EAAE,QAAQ,EAAE,CAAiB;IAEnC,MAAM,IAAI,MAAM;CAMjB;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,QAAQ,EAAE,cAAc,CAAuB;IAC/C,kBAAkB,EAAE,kBAAkB,CAA6B;IACnE,+BAA+B,UAAO;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,uBAAuB,UAAQ;IAC/B,OAAO,EAAE,cAAc,CAAuB;IAC9C,4BAA4B,UAAQ;IACpC,0BAA0B,UAAQ;IAClC,eAAe,CAAC,EAAE,WAAW,GAAG,WAAW,CAAA;IAC3C,iCAAiC,UAAQ;gBAE7B,IAAI,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAwB5C,MAAM,IAAI,MAAM;CAgBjB"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { LogLevel } from "./LogLevel";
|
|
2
2
|
import { LogScope } from "./LogScope";
|
|
3
3
|
import { PaywallOptions } from "./PaywallOptions";
|
|
4
|
+
/**
|
|
5
|
+
* Helper function to remove undefined values from an object.
|
|
6
|
+
* This is necessary for Android compatibility as the Expo bridge
|
|
7
|
+
* cannot convert undefined to Kotlin types.
|
|
8
|
+
*/
|
|
9
|
+
function filterUndefined(obj) {
|
|
10
|
+
return Object.fromEntries(Object.entries(obj).filter(([_, value]) => value !== undefined));
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* @category Enums
|
|
6
14
|
* @since 0.0.15
|
|
@@ -21,10 +29,10 @@ export class LoggingOptions {
|
|
|
21
29
|
level = LogLevel.Info;
|
|
22
30
|
scopes = [LogScope.All];
|
|
23
31
|
toJson() {
|
|
24
|
-
return {
|
|
32
|
+
return filterUndefined({
|
|
25
33
|
level: this.level,
|
|
26
34
|
scopes: this.scopes,
|
|
27
|
-
};
|
|
35
|
+
});
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
/**
|
|
@@ -48,8 +56,16 @@ export class SuperwallOptions {
|
|
|
48
56
|
if (init.paywalls) {
|
|
49
57
|
this.paywalls = new PaywallOptions(init.paywalls); // Pass init.paywalls to PaywallOptions constructor
|
|
50
58
|
}
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
if (init.logging) {
|
|
60
|
+
// Ensure logging is always a LoggingOptions instance
|
|
61
|
+
this.logging =
|
|
62
|
+
init.logging instanceof LoggingOptions
|
|
63
|
+
? init.logging
|
|
64
|
+
: Object.assign(new LoggingOptions(), init.logging);
|
|
65
|
+
}
|
|
66
|
+
// Assign other properties, excluding nested objects
|
|
67
|
+
// biome-ignore lint/correctness/noUnusedVariables: Extracted to exclude from spread
|
|
68
|
+
const { paywalls, logging, ...restInit } = init;
|
|
53
69
|
Object.assign(this, restInit);
|
|
54
70
|
if (paywalls && !init.paywalls) {
|
|
55
71
|
// if paywalls was in init but not used for constructor
|
|
@@ -60,7 +76,8 @@ export class SuperwallOptions {
|
|
|
60
76
|
// You can add methods to this class if needed
|
|
61
77
|
toJson() {
|
|
62
78
|
// Method to serialize class instance to a plain object, useful when passing to native code
|
|
63
|
-
|
|
79
|
+
// Filter out undefined values to prevent Android Expo bridge conversion errors
|
|
80
|
+
return filterUndefined({
|
|
64
81
|
paywalls: this.paywalls.toJson(),
|
|
65
82
|
networkEnvironment: this.networkEnvironment,
|
|
66
83
|
isExternalDataCollectionEnabled: this.isExternalDataCollectionEnabled,
|
|
@@ -71,7 +88,7 @@ export class SuperwallOptions {
|
|
|
71
88
|
passIdentifiersToPlayStore: this.passIdentifiersToPlayStore,
|
|
72
89
|
storeKitVersion: this.storeKitVersion,
|
|
73
90
|
enableExperimentalDeviceVariables: this.enableExperimentalDeviceVariables,
|
|
74
|
-
};
|
|
91
|
+
});
|
|
75
92
|
}
|
|
76
93
|
}
|
|
77
94
|
//# sourceMappingURL=SuperwallOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuperwallOptions.js","sourceRoot":"","sources":["../../../../src/compat/lib/SuperwallOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD;;;;GAIG;AACH,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2DAAqC,CAAA;IACrC,6CAAuB,CAAA;AACzB,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B;AAED;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACzB,KAAK,GAAa,QAAQ,CAAC,IAAI,CAAA;IAC/B,MAAM,GAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAEnC,MAAM;QACJ,OAAO;
|
|
1
|
+
{"version":3,"file":"SuperwallOptions.js","sourceRoot":"","sources":["../../../../src/compat/lib/SuperwallOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD;;;;GAIG;AACH,SAAS,eAAe,CAAgC,GAAM;IAC5D,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAClD,CAAA;AACjB,CAAC;AAED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CAAC,IAAI,cAAc,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;YACzD,CAAC;YACD,oDAAoD;YACpD,oFAAoF;YACpF,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAA;YAC/C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAC7B,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAC/B,uDAAuD;gBACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAA;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;IAED,8CAA8C;IAC9C,MAAM;QACJ,2FAA2F;QAC3F,+EAA+E;QAC/E,OAAO,eAAe,CAAC;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAChC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,+BAA+B,EAAE,IAAI,CAAC,+BAA+B;YACrE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,uBAAuB,EAAE,IAAI,CAAC,uBAAuB;YACrD,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC9B,4BAA4B,EAAE,IAAI,CAAC,4BAA4B;YAC/D,0BAA0B,EAAE,IAAI,CAAC,0BAA0B;YAC3D,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,iCAAiC,EAAE,IAAI,CAAC,iCAAiC;SAC1E,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { LogLevel } from \"./LogLevel\"\nimport { LogScope } from \"./LogScope\"\nimport { PaywallOptions } from \"./PaywallOptions\"\n\n/**\n * Helper function to remove undefined values from an object.\n * This is necessary for Android compatibility as the Expo bridge\n * cannot convert undefined to Kotlin types.\n */\nfunction filterUndefined<T extends Record<string, any>>(obj: T): Partial<T> {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, value]) => value !== undefined),\n ) as Partial<T>\n}\n\n/**\n * @category Enums\n * @since 0.0.15\n * Defines the network environment for Superwall.\n */\nexport enum NetworkEnvironment {\n Release = \"release\",\n ReleaseCandidate = \"releaseCandidate\",\n Developer = \"developer\",\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for configuring logging behavior.\n */\nexport class LoggingOptions {\n level: LogLevel = LogLevel.Info\n scopes: LogScope[] = [LogScope.All]\n\n toJson(): object {\n return filterUndefined({\n level: this.level,\n scopes: this.scopes,\n })\n }\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for configuring the Superwall SDK.\n */\nexport class SuperwallOptions {\n paywalls: PaywallOptions = new PaywallOptions()\n networkEnvironment: NetworkEnvironment = NetworkEnvironment.Release\n isExternalDataCollectionEnabled = true\n localeIdentifier?: string\n isGameControllerEnabled = false\n logging: LoggingOptions = new LoggingOptions()\n collectAdServicesAttribution = false\n passIdentifiersToPlayStore = false\n storeKitVersion?: \"STOREKIT1\" | \"STOREKIT2\"\n enableExperimentalDeviceVariables = false\n\n constructor(init?: Partial<SuperwallOptions>) {\n if (init) {\n if (init.paywalls) {\n this.paywalls = new PaywallOptions(init.paywalls) // Pass init.paywalls to PaywallOptions constructor\n }\n if (init.logging) {\n // Ensure logging is always a LoggingOptions instance\n this.logging =\n init.logging instanceof LoggingOptions\n ? init.logging\n : Object.assign(new LoggingOptions(), init.logging)\n }\n // Assign other properties, excluding nested objects\n // biome-ignore lint/correctness/noUnusedVariables: Extracted to exclude from spread\n const { paywalls, logging, ...restInit } = init\n Object.assign(this, restInit)\n if (paywalls && !init.paywalls) {\n // if paywalls was in init but not used for constructor\n this.paywalls = new PaywallOptions(paywalls)\n }\n }\n }\n\n // You can add methods to this class if needed\n toJson(): object {\n // Method to serialize class instance to a plain object, useful when passing to native code\n // Filter out undefined values to prevent Android Expo bridge conversion errors\n return filterUndefined({\n paywalls: this.paywalls.toJson(),\n networkEnvironment: this.networkEnvironment,\n isExternalDataCollectionEnabled: this.isExternalDataCollectionEnabled,\n localeIdentifier: this.localeIdentifier,\n isGameControllerEnabled: this.isGameControllerEnabled,\n logging: this.logging.toJson(),\n collectAdServicesAttribution: this.collectAdServicesAttribution,\n passIdentifiersToPlayStore: this.passIdentifiersToPlayStore,\n storeKitVersion: this.storeKitVersion,\n enableExperimentalDeviceVariables: this.enableExperimentalDeviceVariables,\n })\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuperwallEvents.d.ts","sourceRoot":"","sources":["../../src/useSuperwallEvents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,6BAA6B,CAAA;AAEpC;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAA;IACrD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,KAAK,IAAI,CAAA;IAC5E;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAA;IACtD;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAExC;;;OAGG;IACH,0BAA0B,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAA;IAEjE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,kBAAkB,KAAK,IAAI,CAAA;IAC1D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAE9C;;;OAGG;IACH,kBAAkB,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK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C,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5C;;;OAGG;IACH,yBAAyB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAEjD;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;QACf,KAAK,EAAE,QAAQ,CAAA;QACf,KAAK,EAAE,QAAQ,CAAA;QACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;QACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;QAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KACrB,KAAK,IAAI,CAAA;IAEV;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAElD;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAA;IAClC;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAA;IAE9B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,SAAS,EAAE,gBAAgB,EAC3B,GAAG,SAAS,EACb,GAAE,uBAA4B,GAAG,IAAI,CAkIrC"}
|
|
@@ -39,49 +39,35 @@ export function useSuperwallEvents({ handlerId: trackedHandlerId, ...callbacks }
|
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
const subs = [];
|
|
41
41
|
/* ---------------- Core events ---------------- */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
callbacksRef.current.onPaywallSkip?.(skippedReason);
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
if (callbacksRef.current.onPaywallError) {
|
|
64
|
-
subs.push(SuperwallExpoModule.addListener("onPaywallError", ({ errorString }) => {
|
|
65
|
-
callbacksRef.current.onPaywallError?.(errorString);
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
42
|
+
subs.push(SuperwallExpoModule.addListener("onPaywallPresent", ({ paywallInfoJson, handlerId }) => {
|
|
43
|
+
if (trackedHandlerId && handlerId !== trackedHandlerId)
|
|
44
|
+
return;
|
|
45
|
+
callbacksRef.current.onPaywallPresent?.(paywallInfoJson);
|
|
46
|
+
}));
|
|
47
|
+
subs.push(SuperwallExpoModule.addListener("onPaywallDismiss", ({ paywallInfoJson, result, handlerId }) => {
|
|
48
|
+
if (trackedHandlerId && handlerId !== trackedHandlerId)
|
|
49
|
+
return;
|
|
50
|
+
callbacksRef.current.onPaywallDismiss?.(paywallInfoJson, result);
|
|
51
|
+
}));
|
|
52
|
+
subs.push(SuperwallExpoModule.addListener("onPaywallSkip", ({ skippedReason, handlerId }) => {
|
|
53
|
+
if (trackedHandlerId && handlerId !== trackedHandlerId)
|
|
54
|
+
return;
|
|
55
|
+
callbacksRef.current.onPaywallSkip?.(skippedReason);
|
|
56
|
+
}));
|
|
57
|
+
subs.push(SuperwallExpoModule.addListener("onPaywallError", ({ errorString }) => {
|
|
58
|
+
callbacksRef.current.onPaywallError?.(errorString);
|
|
59
|
+
}));
|
|
68
60
|
/* ---------------- Subscription ---------------- */
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
61
|
+
subs.push(SuperwallExpoModule.addListener("subscriptionStatusDidChange", ({ to }) => {
|
|
62
|
+
callbacksRef.current.onSubscriptionStatusChange?.(to);
|
|
63
|
+
}));
|
|
74
64
|
/* ---------------- Delegate bridge ---------------- */
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
subs.push(SuperwallExpoModule.addListener("handleCustomPaywallAction", ({ name }) => {
|
|
82
|
-
callbacksRef.current.onCustomPaywallAction?.(name);
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
65
|
+
subs.push(SuperwallExpoModule.addListener("handleSuperwallEvent", ({ eventInfo }) => {
|
|
66
|
+
callbacksRef.current.onSuperwallEvent?.(eventInfo);
|
|
67
|
+
}));
|
|
68
|
+
subs.push(SuperwallExpoModule.addListener("handleCustomPaywallAction", ({ name }) => {
|
|
69
|
+
callbacksRef.current.onCustomPaywallAction?.(name);
|
|
70
|
+
}));
|
|
85
71
|
/* ---------------- Paywall lifecycle ---------------- */
|
|
86
72
|
const lifecycleMap = [
|
|
87
73
|
["willDismissPaywall", "willDismissPaywall"],
|
|
@@ -90,53 +76,36 @@ export function useSuperwallEvents({ handlerId: trackedHandlerId, ...callbacks }
|
|
|
90
76
|
["didPresentPaywall", "didPresentPaywall"],
|
|
91
77
|
];
|
|
92
78
|
lifecycleMap.forEach(([key, event]) => {
|
|
93
|
-
const cb = callbacksRef.current[key];
|
|
94
|
-
if (!cb)
|
|
95
|
-
return;
|
|
96
79
|
subs.push(SuperwallExpoModule.addListener(event, ({ info }) => {
|
|
97
80
|
// @ts-expect-error – key narrowed above
|
|
98
81
|
callbacksRef.current[key]?.(info);
|
|
99
82
|
}));
|
|
100
83
|
});
|
|
101
84
|
/* ---------------- Links ---------------- */
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
subs.push(SuperwallExpoModule.addListener("paywallWillOpenDeepLink", ({ url }) => {
|
|
109
|
-
callbacksRef.current.onPaywallWillOpenDeepLink?.(url);
|
|
110
|
-
}));
|
|
111
|
-
}
|
|
85
|
+
subs.push(SuperwallExpoModule.addListener("paywallWillOpenURL", ({ url }) => {
|
|
86
|
+
callbacksRef.current.onPaywallWillOpenURL?.(url);
|
|
87
|
+
}));
|
|
88
|
+
subs.push(SuperwallExpoModule.addListener("paywallWillOpenDeepLink", ({ url }) => {
|
|
89
|
+
callbacksRef.current.onPaywallWillOpenDeepLink?.(url);
|
|
90
|
+
}));
|
|
112
91
|
/* ---------------- Logs ---------------- */
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
92
|
+
subs.push(SuperwallExpoModule.addListener("handleLog", (params) => {
|
|
93
|
+
callbacksRef.current.onLog?.(params);
|
|
94
|
+
}));
|
|
118
95
|
/* ---------------- Promotional links ---------------- */
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
subs.push(SuperwallExpoModule.addListener("didRedeemLink", (result) => {
|
|
126
|
-
callbacksRef.current.didRedeemLink?.(result);
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
96
|
+
subs.push(SuperwallExpoModule.addListener("willRedeemLink", () => {
|
|
97
|
+
callbacksRef.current.willRedeemLink?.();
|
|
98
|
+
}));
|
|
99
|
+
subs.push(SuperwallExpoModule.addListener("didRedeemLink", (result) => {
|
|
100
|
+
callbacksRef.current.didRedeemLink?.(result);
|
|
101
|
+
}));
|
|
129
102
|
/* ---------------- Purchases ---------------- */
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
subs.push(SuperwallExpoModule.addListener("onPurchaseRestore", () => {
|
|
137
|
-
callbacksRef.current.onPurchaseRestore?.();
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
103
|
+
subs.push(SuperwallExpoModule.addListener("onPurchase", (params) => {
|
|
104
|
+
callbacksRef.current.onPurchase?.(params);
|
|
105
|
+
}));
|
|
106
|
+
subs.push(SuperwallExpoModule.addListener("onPurchaseRestore", () => {
|
|
107
|
+
callbacksRef.current.onPurchaseRestore?.();
|
|
108
|
+
}));
|
|
140
109
|
// biome-ignore lint/suspicious/useIterableCallbackReturn: <explanation>
|
|
141
110
|
return () => subs.forEach((s) => s.remove());
|
|
142
111
|
}, [trackedHandlerId]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuperwallEvents.js","sourceRoot":"","sources":["../../src/useSuperwallEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AA2IvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,kBAAkB,CAAC,EACjC,SAAS,EAAE,gBAAgB,EAC3B,GAAG,SAAS,KACe,EAAE;IAC7B,6EAA6E;IAC7E,MAAM,YAAY,GAAG,MAAM,CAA0B,SAAS,CAAC,CAAA;IAC/D,YAAY,CAAC,OAAO,GAAG,SAAS,CAAA;IAEhC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,IAAI,GAA6B,EAAE,CAAA;QAEzC,mDAAmD;QACnD,IAAI,YAAY,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC1C,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,EAAE;gBACrF,IAAI,gBAAgB,IAAI,SAAS,KAAK,gBAAgB;oBAAE,OAAM;gBAE9D,YAAY,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,eAAe,CAAC,CAAA;YAC1D,CAAC,CAAC,CACH,CAAA;QACH,CAAC;QAED,IAAI,YAAY,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC1C,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAC7B,kBAAkB,EAClB,CAAC,EAAE,eAAe,EAAE,MAAM,EAA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CAAC;YACpC,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,MAAW,EAAE,EAAE;gBAC5D,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAA;YAC3C,CAAC,CAAC,CACH,CAAA;QACH,CAAC;QAED,IAAI,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC3C,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,mBAAmB,EAAE,GAAG,EAAE;gBACxD,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAA;YAC5C,CAAC,CAAC,CACH,CAAA;QACH,CAAC;QAED,wEAAwE;QACxE,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;IAC9C,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAA;AACxB,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\"\nimport SuperwallExpoModule from \"./SuperwallExpoModule\"\nimport type {\n LogLevel,\n LogScope,\n PaywallInfo,\n PaywallResult,\n PaywallSkippedReason,\n RedemptionResult,\n SubscriptionStatus,\n SuperwallEventInfo,\n} from \"./SuperwallExpoModule.types\"\n\n/**\n * @category Events\n * @since 0.0.15\n * Defines the available callbacks for subscribing to Superwall native events.\n * Each property is an optional callback function that will be invoked when the corresponding event occurs.\n * If a callback is not provided, no listener will be registered for that event.\n */\nexport interface SuperwallEventCallbacks {\n /**\n * Called when a paywall is presented.\n * @param paywallInfo - Information about the presented paywall. See {@link PaywallInfo}.\n */\n onPaywallPresent?: (paywallInfo: PaywallInfo) => void\n /**\n * Called when a paywall is dismissed.\n * @param paywallInfo - Information about the dismissed paywall. See {@link PaywallInfo}.\n * @param result - The result of the paywall interaction. See {@link PaywallResult}.\n */\n onPaywallDismiss?: (paywallInfo: PaywallInfo, result: PaywallResult) => void\n /**\n * Called when a paywall is skipped.\n * @param reason - The reason why the paywall was skipped. See {@link PaywallSkippedReason}.\n */\n onPaywallSkip?: (reason: PaywallSkippedReason) => void\n /**\n * Called when an error occurs during paywall presentation or other SDK operations.\n * @param error - A string describing the error.\n */\n onPaywallError?: (error: string) => void\n\n /**\n * Called when the user's subscription status changes.\n * @param status - The new subscription status. See {@link SubscriptionStatus}.\n */\n onSubscriptionStatusChange?: (status: SubscriptionStatus) => void\n\n /**\n * Called for all Superwall internal events. This is a general-purpose event handler.\n * @param eventInfo - Information about the Superwall event. See {@link SuperwallEventInfo}.\n */\n onSuperwallEvent?: (eventInfo: SuperwallEventInfo) => void\n /**\n * Called when a custom action is triggered from a paywall (e.g., via `superwall.triggerCustomPaywallAction('myAction')`).\n * @param name - The name of the custom action.\n */\n onCustomPaywallAction?: (name: string) => void\n\n /**\n * Called just before a paywall is dismissed.\n * @param paywallInfo - Information about the paywall that will be dismissed. See {@link PaywallInfo}.\n */\n willDismissPaywall?: (paywallInfo: PaywallInfo) => void\n /**\n * Called just before a paywall is presented.\n * @param paywallInfo - Information about the paywall that will be presented. See {@link PaywallInfo}.\n */\n willPresentPaywall?: (paywallInfo: PaywallInfo) => void\n /**\n * Called after a paywall has been dismissed.\n * @param paywallInfo - Information about the paywall that was dismissed. See {@link PaywallInfo}.\n */\n didDismissPaywall?: (paywallInfo: PaywallInfo) => void\n /**\n * Called after a paywall has been presented.\n * @param paywallInfo - Information about the paywall that was presented. See {@link PaywallInfo}.\n */\n didPresentPaywall?: (paywallInfo: PaywallInfo) => void\n\n /**\n * Called when the paywall attempts to open a URL.\n * @param url - The URL that the paywall will attempt to open.\n */\n onPaywallWillOpenURL?: (url: string) => void\n /**\n * Called when the paywall attempts to open a deep link.\n * @param url - The deep link URL that the paywall will attempt to open.\n */\n onPaywallWillOpenDeepLink?: (url: string) => void\n\n /**\n * Called for logging messages from the SDK.\n * @param params - An object containing log details.\n * @param params.level - The log level. See {@link LogLevel}.\n * @param params.scope - The scope of the log. See {@link LogScope}.\n * @param params.message - The log message.\n * @param params.info - Additional info associated with the log.\n * @param params.error - Error message if applicable.\n */\n onLog?: (params: {\n level: LogLevel\n scope: LogScope\n message: string | null\n info: Record<string, any> | null\n error: string | null\n }) => void\n\n /**\n * Called before the SDK attempts to redeem a promotional link.\n */\n willRedeemLink?: () => void\n /**\n * Called after the SDK has attempted to redeem a promotional link.\n * @param result - The result of the redemption attempt. See {@link RedemptionResult}.\n */\n didRedeemLink?: (result: RedemptionResult) => void\n\n /**\n * Called when a purchase is initiated.\n * @param params - Parameters related to the purchase. For iOS, this includes `productId` and `platform`.\n * For Android, this includes `productId`, `platform`, `basePlanId`, and `offerId`.\n */\n onPurchase?: (params: any) => void // Type any due to platform differences, specific types in SuperwallExpoModule.types.ts\n /**\n * Called when a purchase restoration is initiated.\n */\n onPurchaseRestore?: () => void\n\n /**\n * An optional identifier used to scope certain events (like `onPaywallPresent`, `onPaywallDismiss`, `onPaywallSkip`)\n * to a specific `usePlacement` hook instance. If provided, these events will only be triggered\n * if the event originated from a `registerPlacement` call associated with the same `handlerId`.\n * This is primarily used internally by the `usePlacement` hook.\n * @internal\n */\n handlerId?: string\n}\n\n/**\n * @category Hooks\n * @since 0.0.15\n * React hook for subscribing to a wide range of native Superwall events.\n *\n * This hook allows you to define callback functions for various events emitted by the\n * Superwall SDK, such as paywall presentation, dismissal, subscription status changes,\n * and more. Event listeners are automatically added when the component mounts\n * and removed when it unmounts.\n *\n * It must be used within a component that is a descendant of `<SuperwallProvider />`.\n *\n * @param callbacks - An object where keys are event names (from `SuperwallEventCallbacks`)\n * and values are the corresponding callback functions.\n * If `callbacks.handlerId` is provided, core paywall events (`onPaywallPresent`,\n * `onPaywallDismiss`, `onPaywallSkip`) will be scoped to that handler. This is\n * mainly for internal use by `usePlacement`.\n *\n * @example\n * useSuperwallEvents({\n * onPaywallPresent: (info) => console.log(\"Paywall presented:\", info.name),\n * onSubscriptionStatusChange: (status) => console.log(\"New sub status:\", status),\n * onLog: (logParams) => {\n * if (logParams.level === 'error') {\n * console.error(`[Superwall SDK Error] ${logParams.scope}: ${logParams.message}`);\n * }\n * },\n * });\n *\n * // This component will now log specific Superwall events.\n * // Return null or your component's JSX.\n */\nexport function useSuperwallEvents({\n handlerId: trackedHandlerId,\n ...callbacks\n}: SuperwallEventCallbacks = {}): void {\n // Keep the latest callbacks in a ref so event handlers always use the latest\n const callbacksRef = useRef<SuperwallEventCallbacks>(callbacks)\n callbacksRef.current = callbacks\n\n useEffect(() => {\n const subs: { remove: () => void }[] = []\n\n /* ---------------- Core events ---------------- */\n if (callbacksRef.current.onPaywallPresent) {\n subs.push(\n SuperwallExpoModule.addListener(\"onPaywallPresent\", ({ paywallInfoJson, handlerId }) => {\n if (trackedHandlerId && handlerId !== trackedHandlerId) return\n\n callbacksRef.current.onPaywallPresent?.(paywallInfoJson)\n }),\n )\n }\n\n if (callbacksRef.current.onPaywallDismiss) {\n subs.push(\n SuperwallExpoModule.addListener(\n \"onPaywallDismiss\",\n ({ paywallInfoJson, result, handlerId }) => {\n if (trackedHandlerId && handlerId !== trackedHandlerId) return\n\n callbacksRef.current.onPaywallDismiss?.(paywallInfoJson, result)\n },\n ),\n )\n }\n\n if (callbacksRef.current.onPaywallSkip) {\n subs.push(\n SuperwallExpoModule.addListener(\"onPaywallSkip\", ({ skippedReason, handlerId }) => {\n if (trackedHandlerId && handlerId !== trackedHandlerId) return\n callbacksRef.current.onPaywallSkip?.(skippedReason)\n }),\n )\n }\n\n if (callbacksRef.current.onPaywallError) {\n subs.push(\n SuperwallExpoModule.addListener(\"onPaywallError\", ({ errorString }) => {\n callbacksRef.current.onPaywallError?.(errorString)\n }),\n )\n }\n\n /* ---------------- Subscription ---------------- */\n if (callbacksRef.current.onSubscriptionStatusChange) {\n subs.push(\n SuperwallExpoModule.addListener(\"subscriptionStatusDidChange\", ({ to }) => {\n callbacksRef.current.onSubscriptionStatusChange?.(to)\n }),\n )\n }\n\n /* ---------------- Delegate bridge ---------------- */\n if (callbacksRef.current.onSuperwallEvent) {\n subs.push(\n SuperwallExpoModule.addListener(\"handleSuperwallEvent\", ({ eventInfo }) => {\n callbacksRef.current.onSuperwallEvent?.(eventInfo)\n }),\n )\n }\n\n if (callbacksRef.current.onCustomPaywallAction) {\n subs.push(\n SuperwallExpoModule.addListener(\n \"handleCustomPaywallAction\",\n ({ name }: { name: string }) => {\n callbacksRef.current.onCustomPaywallAction?.(name)\n },\n ),\n )\n }\n\n /* ---------------- Paywall lifecycle ---------------- */\n const lifecycleMap: [keyof SuperwallEventCallbacks, string][] = [\n [\"willDismissPaywall\", \"willDismissPaywall\"],\n [\"willPresentPaywall\", \"willPresentPaywall\"],\n [\"didDismissPaywall\", \"didDismissPaywall\"],\n [\"didPresentPaywall\", \"didPresentPaywall\"],\n ]\n\n lifecycleMap.forEach(([key, event]) => {\n const cb = callbacksRef.current[key]\n if (!cb) return\n subs.push(\n SuperwallExpoModule.addListener(event as any, ({ info }: { info: PaywallInfo }) => {\n // @ts-expect-error – key narrowed above\n callbacksRef.current[key]?.(info)\n }),\n )\n })\n\n /* ---------------- Links ---------------- */\n if (callbacksRef.current.onPaywallWillOpenURL) {\n subs.push(\n SuperwallExpoModule.addListener(\"paywallWillOpenURL\", ({ url }: { url: string }) => {\n callbacksRef.current.onPaywallWillOpenURL?.(url)\n }),\n )\n }\n\n if (callbacksRef.current.onPaywallWillOpenDeepLink) {\n subs.push(\n SuperwallExpoModule.addListener(\"paywallWillOpenDeepLink\", ({ url }: { url: string }) => {\n callbacksRef.current.onPaywallWillOpenDeepLink?.(url)\n }),\n )\n }\n\n /* ---------------- Logs ---------------- */\n if (callbacksRef.current.onLog) {\n subs.push(\n SuperwallExpoModule.addListener(\"handleLog\", (params) => {\n callbacksRef.current.onLog?.(params)\n }),\n )\n }\n\n /* ---------------- Promotional links ---------------- */\n if (callbacksRef.current.willRedeemLink) {\n subs.push(\n SuperwallExpoModule.addListener(\"willRedeemLink\", () => {\n callbacksRef.current.willRedeemLink?.()\n }),\n )\n }\n\n if (callbacksRef.current.didRedeemLink) {\n subs.push(\n SuperwallExpoModule.addListener(\"didRedeemLink\", (result: RedemptionResult) => {\n callbacksRef.current.didRedeemLink?.(result)\n }),\n )\n }\n\n /* ---------------- Purchases ---------------- */\n if (callbacksRef.current.onPurchase) {\n subs.push(\n SuperwallExpoModule.addListener(\"onPurchase\", (params: any) => {\n callbacksRef.current.onPurchase?.(params)\n }),\n )\n }\n\n if (callbacksRef.current.onPurchaseRestore) {\n subs.push(\n SuperwallExpoModule.addListener(\"onPurchaseRestore\", () => {\n callbacksRef.current.onPurchaseRestore?.()\n }),\n )\n }\n\n // biome-ignore lint/suspicious/useIterableCallbackReturn: <explanation>\n return () => subs.forEach((s) => s.remove())\n }, [trackedHandlerId])\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useSuperwallEvents.js","sourceRoot":"","sources":["../../src/useSuperwallEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AA2IvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,kBAAkB,CAAC,EACjC,SAAS,EAAE,gBAAgB,EAC3B,GAAG,SAAS,KACe,EAAE;IAC7B,6EAA6E;IAC7E,MAAM,YAAY,GAAG,MAAM,CAA0B,SAAS,CAAC,CAAA;IAC/D,YAAY,CAAC,OAAO,GAAG,SAAS,CAAA;IAEhC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,IAAI,GAA6B,EAAE,CAAA;QAEzC,mDAAmD;QACnD,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,EAAE;YACrF,IAAI,gBAAgB,IAAI,SAAS,KAAK,gBAAgB;gBAAE,OAAM;YAE9D,YAAY,CAAC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AA4C;QAC5C,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE;YACtD,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,CAAA;QACtC,CAAC,CAAC,CACH,CAAA;QAED,yDAAyD;QACzD,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,gBAAgB,EAAE,GAAG,EAAE;YACrD,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAA;QACzC,CAAC,CAAC,CACH,CAAA;QAED,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,MAAwB,EAAE,EAAE;YAC5E,YAAY,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,CAAA;QAC9C,CAAC,CAAC,CACH,CAAA;QAED,iDAAiD;QACjD,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,MAAW,EAAE,EAAE;YAC5D,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAA;QAC3C,CAAC,CAAC,CACH,CAAA;QAED,IAAI,CAAC,IAAI,CACP,mBAAmB,CAAC,WAAW,CAAC,mBAAmB,EAAE,GAAG,EAAE;YACxD,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAA;QAC5C,CAAC,CAAC,CACH,CAAA;QAED,wEAAwE;QACxE,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;IAC9C,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAA;AACxB,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\"\nimport SuperwallExpoModule from \"./SuperwallExpoModule\"\nimport type {\n LogLevel,\n LogScope,\n PaywallInfo,\n PaywallResult,\n PaywallSkippedReason,\n RedemptionResult,\n SubscriptionStatus,\n SuperwallEventInfo,\n} from \"./SuperwallExpoModule.types\"\n\n/**\n * @category Events\n * @since 0.0.15\n * Defines the available callbacks for subscribing to Superwall native events.\n * Each property is an optional callback function that will be invoked when the corresponding event occurs.\n * If a callback is not provided, no listener will be registered for that event.\n */\nexport interface SuperwallEventCallbacks {\n /**\n * Called when a paywall is presented.\n * @param paywallInfo - Information about the presented paywall. See {@link PaywallInfo}.\n */\n onPaywallPresent?: (paywallInfo: PaywallInfo) => void\n /**\n * Called when a paywall is dismissed.\n * @param paywallInfo - Information about the dismissed paywall. See {@link PaywallInfo}.\n * @param result - The result of the paywall interaction. See {@link PaywallResult}.\n */\n onPaywallDismiss?: (paywallInfo: PaywallInfo, result: PaywallResult) => void\n /**\n * Called when a paywall is skipped.\n * @param reason - The reason why the paywall was skipped. See {@link PaywallSkippedReason}.\n */\n onPaywallSkip?: (reason: PaywallSkippedReason) => void\n /**\n * Called when an error occurs during paywall presentation or other SDK operations.\n * @param error - A string describing the error.\n */\n onPaywallError?: (error: string) => void\n\n /**\n * Called when the user's subscription status changes.\n * @param status - The new subscription status. See {@link SubscriptionStatus}.\n */\n onSubscriptionStatusChange?: (status: SubscriptionStatus) => void\n\n /**\n * Called for all Superwall internal events. This is a general-purpose event handler.\n * @param eventInfo - Information about the Superwall event. See {@link SuperwallEventInfo}.\n */\n onSuperwallEvent?: (eventInfo: SuperwallEventInfo) => void\n /**\n * Called when a custom action is triggered from a paywall (e.g., via `superwall.triggerCustomPaywallAction('myAction')`).\n * @param name - The name of the custom action.\n */\n onCustomPaywallAction?: (name: string) => void\n\n /**\n * Called just before a paywall is dismissed.\n * @param paywallInfo - Information about the paywall that will be dismissed. See {@link PaywallInfo}.\n */\n willDismissPaywall?: (paywallInfo: PaywallInfo) => void\n /**\n * Called just before a paywall is presented.\n * @param paywallInfo - Information about the paywall that will be presented. See {@link PaywallInfo}.\n */\n willPresentPaywall?: (paywallInfo: PaywallInfo) => void\n /**\n * Called after a paywall has been dismissed.\n * @param paywallInfo - Information about the paywall that was dismissed. See {@link PaywallInfo}.\n */\n didDismissPaywall?: (paywallInfo: PaywallInfo) => void\n /**\n * Called after a paywall has been presented.\n * @param paywallInfo - Information about the paywall that was presented. See {@link PaywallInfo}.\n */\n didPresentPaywall?: (paywallInfo: PaywallInfo) => void\n\n /**\n * Called when the paywall attempts to open a URL.\n * @param url - The URL that the paywall will attempt to open.\n */\n onPaywallWillOpenURL?: (url: string) => void\n /**\n * Called when the paywall attempts to open a deep link.\n * @param url - The deep link URL that the paywall will attempt to open.\n */\n onPaywallWillOpenDeepLink?: (url: string) => void\n\n /**\n * Called for logging messages from the SDK.\n * @param params - An object containing log details.\n * @param params.level - The log level. See {@link LogLevel}.\n * @param params.scope - The scope of the log. See {@link LogScope}.\n * @param params.message - The log message.\n * @param params.info - Additional info associated with the log.\n * @param params.error - Error message if applicable.\n */\n onLog?: (params: {\n level: LogLevel\n scope: LogScope\n message: string | null\n info: Record<string, any> | null\n error: string | null\n }) => void\n\n /**\n * Called before the SDK attempts to redeem a promotional link.\n */\n willRedeemLink?: () => void\n /**\n * Called after the SDK has attempted to redeem a promotional link.\n * @param result - The result of the redemption attempt. See {@link RedemptionResult}.\n */\n didRedeemLink?: (result: RedemptionResult) => void\n\n /**\n * Called when a purchase is initiated.\n * @param params - Parameters related to the purchase. For iOS, this includes `productId` and `platform`.\n * For Android, this includes `productId`, `platform`, `basePlanId`, and `offerId`.\n */\n onPurchase?: (params: any) => void // Type any due to platform differences, specific types in SuperwallExpoModule.types.ts\n /**\n * Called when a purchase restoration is initiated.\n */\n onPurchaseRestore?: () => void\n\n /**\n * An optional identifier used to scope certain events (like `onPaywallPresent`, `onPaywallDismiss`, `onPaywallSkip`)\n * to a specific `usePlacement` hook instance. If provided, these events will only be triggered\n * if the event originated from a `registerPlacement` call associated with the same `handlerId`.\n * This is primarily used internally by the `usePlacement` hook.\n * @internal\n */\n handlerId?: string\n}\n\n/**\n * @category Hooks\n * @since 0.0.15\n * React hook for subscribing to a wide range of native Superwall events.\n *\n * This hook allows you to define callback functions for various events emitted by the\n * Superwall SDK, such as paywall presentation, dismissal, subscription status changes,\n * and more. Event listeners are automatically added when the component mounts\n * and removed when it unmounts.\n *\n * It must be used within a component that is a descendant of `<SuperwallProvider />`.\n *\n * @param callbacks - An object where keys are event names (from `SuperwallEventCallbacks`)\n * and values are the corresponding callback functions.\n * If `callbacks.handlerId` is provided, core paywall events (`onPaywallPresent`,\n * `onPaywallDismiss`, `onPaywallSkip`) will be scoped to that handler. This is\n * mainly for internal use by `usePlacement`.\n *\n * @example\n * useSuperwallEvents({\n * onPaywallPresent: (info) => console.log(\"Paywall presented:\", info.name),\n * onSubscriptionStatusChange: (status) => console.log(\"New sub status:\", status),\n * onLog: (logParams) => {\n * if (logParams.level === 'error') {\n * console.error(`[Superwall SDK Error] ${logParams.scope}: ${logParams.message}`);\n * }\n * },\n * });\n *\n * // This component will now log specific Superwall events.\n * // Return null or your component's JSX.\n */\nexport function useSuperwallEvents({\n handlerId: trackedHandlerId,\n ...callbacks\n}: SuperwallEventCallbacks = {}): void {\n // Keep the latest callbacks in a ref so event handlers always use the latest\n const callbacksRef = useRef<SuperwallEventCallbacks>(callbacks)\n callbacksRef.current = callbacks\n\n useEffect(() => {\n const subs: { remove: () => void }[] = []\n\n /* ---------------- Core events ---------------- */\n subs.push(\n SuperwallExpoModule.addListener(\"onPaywallPresent\", ({ paywallInfoJson, handlerId }) => {\n if (trackedHandlerId && handlerId !== trackedHandlerId) return\n\n callbacksRef.current.onPaywallPresent?.(paywallInfoJson)\n }),\n )\n\n subs.push(\n SuperwallExpoModule.addListener(\n \"onPaywallDismiss\",\n ({ paywallInfoJson, result, handlerId }) => {\n if (trackedHandlerId && handlerId !== trackedHandlerId) return\n\n callbacksRef.current.onPaywallDismiss?.(paywallInfoJson, result)\n },\n ),\n )\n\n subs.push(\n SuperwallExpoModule.addListener(\"onPaywallSkip\", ({ skippedReason, handlerId }) => {\n if (trackedHandlerId && handlerId !== trackedHandlerId) return\n callbacksRef.current.onPaywallSkip?.(skippedReason)\n }),\n )\n\n subs.push(\n SuperwallExpoModule.addListener(\"onPaywallError\", ({ errorString }) => {\n callbacksRef.current.onPaywallError?.(errorString)\n }),\n )\n\n /* ---------------- Subscription ---------------- */\n subs.push(\n SuperwallExpoModule.addListener(\"subscriptionStatusDidChange\", ({ to }) => {\n callbacksRef.current.onSubscriptionStatusChange?.(to)\n }),\n )\n\n /* ---------------- Delegate bridge ---------------- */\n subs.push(\n SuperwallExpoModule.addListener(\"handleSuperwallEvent\", ({ eventInfo }) => {\n callbacksRef.current.onSuperwallEvent?.(eventInfo)\n }),\n )\n\n subs.push(\n SuperwallExpoModule.addListener(\n \"handleCustomPaywallAction\",\n ({ name }: { name: string }) => {\n callbacksRef.current.onCustomPaywallAction?.(name)\n },\n ),\n )\n\n /* ---------------- Paywall lifecycle ---------------- */\n const lifecycleMap: [keyof SuperwallEventCallbacks, string][] = [\n [\"willDismissPaywall\", \"willDismissPaywall\"],\n [\"willPresentPaywall\", \"willPresentPaywall\"],\n [\"didDismissPaywall\", \"didDismissPaywall\"],\n [\"didPresentPaywall\", \"didPresentPaywall\"],\n ]\n\n lifecycleMap.forEach(([key, event]) => {\n subs.push(\n SuperwallExpoModule.addListener(event as any, ({ info }: { info: PaywallInfo }) => {\n // @ts-expect-error – key narrowed above\n callbacksRef.current[key]?.(info)\n }),\n )\n })\n\n /* ---------------- Links ---------------- */\n subs.push(\n SuperwallExpoModule.addListener(\"paywallWillOpenURL\", ({ url }: { url: string }) => {\n callbacksRef.current.onPaywallWillOpenURL?.(url)\n }),\n )\n\n subs.push(\n SuperwallExpoModule.addListener(\"paywallWillOpenDeepLink\", ({ url }: { url: string }) => {\n callbacksRef.current.onPaywallWillOpenDeepLink?.(url)\n }),\n )\n\n /* ---------------- Logs ---------------- */\n subs.push(\n SuperwallExpoModule.addListener(\"handleLog\", (params) => {\n callbacksRef.current.onLog?.(params)\n }),\n )\n\n /* ---------------- Promotional links ---------------- */\n subs.push(\n SuperwallExpoModule.addListener(\"willRedeemLink\", () => {\n callbacksRef.current.willRedeemLink?.()\n }),\n )\n\n subs.push(\n SuperwallExpoModule.addListener(\"didRedeemLink\", (result: RedemptionResult) => {\n callbacksRef.current.didRedeemLink?.(result)\n }),\n )\n\n /* ---------------- Purchases ---------------- */\n subs.push(\n SuperwallExpoModule.addListener(\"onPurchase\", (params: any) => {\n callbacksRef.current.onPurchase?.(params)\n }),\n )\n\n subs.push(\n SuperwallExpoModule.addListener(\"onPurchaseRestore\", () => {\n callbacksRef.current.onPurchaseRestore?.()\n }),\n )\n\n // biome-ignore lint/suspicious/useIterableCallbackReturn: <explanation>\n return () => subs.forEach((s) => s.remove())\n }, [trackedHandlerId])\n}\n"]}
|