@tryheliumai/paywall-sdk-react-native 0.1.26 → 0.1.27
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/lib/commonjs/handlers/revenuecat.js +146 -0
- package/lib/commonjs/handlers/revenuecat.js.map +1 -0
- package/lib/commonjs/index.js +14 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native-interface.js +34 -14
- package/lib/commonjs/native-interface.js.map +1 -1
- package/lib/commonjs/types.js +27 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/handlers/revenuecat.js +138 -0
- package/lib/module/handlers/revenuecat.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/native-interface.js +34 -14
- package/lib/module/native-interface.js.map +1 -1
- package/lib/module/types.js +23 -0
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/src/handlers/revenuecat.d.ts +16 -0
- package/lib/typescript/commonjs/src/handlers/revenuecat.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +3 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/native-interface.d.ts +2 -2
- package/lib/typescript/commonjs/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +22 -3
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/handlers/revenuecat.d.ts +16 -0
- package/lib/typescript/module/src/handlers/revenuecat.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +3 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/native-interface.d.ts +2 -2
- package/lib/typescript/module/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +22 -3
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/handlers/revenuecat.ts +132 -0
- package/src/index.ts +3 -1
- package/src/native-interface.tsx +42 -19
- package/src/types.ts +42 -4
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RevenueCatConfig = RevenueCatConfig;
|
|
7
|
+
exports.RevenueCatHeliumHandler = void 0;
|
|
8
|
+
var _reactNativePurchases = _interopRequireWildcard(require("react-native-purchases"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
// Rename the factory function
|
|
12
|
+
function RevenueCatConfig(config) {
|
|
13
|
+
return {
|
|
14
|
+
type: 'revenuecat',
|
|
15
|
+
apiKey: config?.apiKey
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
class RevenueCatHeliumHandler {
|
|
19
|
+
productIdToPackageMapping = {};
|
|
20
|
+
isMappingInitialized = false;
|
|
21
|
+
initializationPromise = null;
|
|
22
|
+
constructor(apiKey) {
|
|
23
|
+
if (apiKey) {
|
|
24
|
+
_reactNativePurchases.default.configure({
|
|
25
|
+
apiKey
|
|
26
|
+
});
|
|
27
|
+
} else {}
|
|
28
|
+
this.initializePackageMapping();
|
|
29
|
+
}
|
|
30
|
+
async initializePackageMapping() {
|
|
31
|
+
if (this.initializationPromise) {
|
|
32
|
+
return this.initializationPromise;
|
|
33
|
+
}
|
|
34
|
+
this.initializationPromise = (async () => {
|
|
35
|
+
try {
|
|
36
|
+
const offerings = await _reactNativePurchases.default.getOfferings();
|
|
37
|
+
if (offerings.current?.availablePackages) {
|
|
38
|
+
offerings.current.availablePackages.forEach(pkg => {
|
|
39
|
+
if (pkg.product?.identifier) {
|
|
40
|
+
this.productIdToPackageMapping[pkg.product.identifier] = pkg;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
} else {}
|
|
44
|
+
this.isMappingInitialized = true;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
this.isMappingInitialized = false;
|
|
47
|
+
} finally {
|
|
48
|
+
this.initializationPromise = null;
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
return this.initializationPromise;
|
|
52
|
+
}
|
|
53
|
+
async ensureMappingInitialized() {
|
|
54
|
+
if (!this.isMappingInitialized && !this.initializationPromise) {
|
|
55
|
+
await this.initializePackageMapping();
|
|
56
|
+
} else if (this.initializationPromise) {
|
|
57
|
+
await this.initializationPromise;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async makePurchase(productId) {
|
|
61
|
+
await this.ensureMappingInitialized();
|
|
62
|
+
const pkg = this.productIdToPackageMapping[productId];
|
|
63
|
+
if (!pkg) {
|
|
64
|
+
return {
|
|
65
|
+
status: 'failed',
|
|
66
|
+
error: `RevenueCat Package not found for ID: ${productId}`
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const {
|
|
71
|
+
customerInfo
|
|
72
|
+
} = await _reactNativePurchases.default.purchasePackage(pkg);
|
|
73
|
+
const isActive = this.isProductActive(customerInfo, productId);
|
|
74
|
+
if (isActive) {
|
|
75
|
+
return {
|
|
76
|
+
status: 'purchased'
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
// This case might occur if the purchase succeeded but the entitlement wasn't immediately active
|
|
80
|
+
// or if a different product became active.
|
|
81
|
+
// Consider if polling/listening might be needed here too, similar to pending.
|
|
82
|
+
// For now, returning failed as the specific product isn't confirmed active.
|
|
83
|
+
return {
|
|
84
|
+
status: 'failed',
|
|
85
|
+
error: 'Purchase possibly complete but entitlement/subscription not active for this product.'
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const purchasesError = error;
|
|
90
|
+
if (purchasesError?.code === _reactNativePurchases.PURCHASES_ERROR_CODE.PAYMENT_PENDING_ERROR) {
|
|
91
|
+
// Wait for a terminal state for up to 5 seconds
|
|
92
|
+
return new Promise(resolve => {
|
|
93
|
+
// Define the listener function separately to remove it later
|
|
94
|
+
const updateListener = updatedCustomerInfo => {
|
|
95
|
+
const isActive = this.isProductActive(updatedCustomerInfo, productId);
|
|
96
|
+
if (isActive) {
|
|
97
|
+
clearTimeout(timeoutId);
|
|
98
|
+
// Remove listener using the function reference
|
|
99
|
+
_reactNativePurchases.default.removeCustomerInfoUpdateListener(updateListener);
|
|
100
|
+
resolve({
|
|
101
|
+
status: 'purchased'
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const timeoutId = setTimeout(() => {
|
|
106
|
+
// Remove listener using the function reference on timeout
|
|
107
|
+
_reactNativePurchases.default.removeCustomerInfoUpdateListener(updateListener);
|
|
108
|
+
resolve({
|
|
109
|
+
status: 'pending'
|
|
110
|
+
});
|
|
111
|
+
}, 5000);
|
|
112
|
+
|
|
113
|
+
// Add the listener
|
|
114
|
+
_reactNativePurchases.default.addCustomerInfoUpdateListener(updateListener);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (purchasesError?.code === _reactNativePurchases.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR) {
|
|
118
|
+
return {
|
|
119
|
+
status: 'cancelled'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Handle other errors
|
|
124
|
+
return {
|
|
125
|
+
status: 'failed',
|
|
126
|
+
error: purchasesError?.message || 'RevenueCat purchase failed.'
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Helper function to check if a product is active in CustomerInfo
|
|
132
|
+
isProductActive(customerInfo, productId) {
|
|
133
|
+
return Object.values(customerInfo.entitlements.active).some(entitlement => entitlement.productIdentifier === productId) || customerInfo.activeSubscriptions.includes(productId) || customerInfo.allPurchasedProductIdentifiers.includes(productId);
|
|
134
|
+
}
|
|
135
|
+
async restorePurchases() {
|
|
136
|
+
try {
|
|
137
|
+
const customerInfo = await _reactNativePurchases.default.restorePurchases();
|
|
138
|
+
const isActive = Object.keys(customerInfo.entitlements.active).length > 0;
|
|
139
|
+
return isActive;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.RevenueCatHeliumHandler = RevenueCatHeliumHandler;
|
|
146
|
+
//# sourceMappingURL=revenuecat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNativePurchases","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RevenueCatConfig","config","type","apiKey","RevenueCatHeliumHandler","productIdToPackageMapping","isMappingInitialized","initializationPromise","constructor","Purchases","configure","initializePackageMapping","offerings","getOfferings","current","availablePackages","forEach","pkg","product","identifier","error","ensureMappingInitialized","makePurchase","productId","status","customerInfo","purchasePackage","isActive","isProductActive","purchasesError","code","PURCHASES_ERROR_CODE","PAYMENT_PENDING_ERROR","Promise","resolve","updateListener","updatedCustomerInfo","clearTimeout","timeoutId","removeCustomerInfoUpdateListener","setTimeout","addCustomerInfoUpdateListener","PURCHASE_CANCELLED_ERROR","message","values","entitlements","active","some","entitlement","productIdentifier","activeSubscriptions","includes","allPurchasedProductIdentifiers","restorePurchases","keys","length","exports"],"sourceRoot":"../../../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EACJ;AACJ;AAACoC,OAAA,CAAApD,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "CustomPurchaseConfig", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _types.CustomPurchaseConfig;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "HELIUM_CTA_NAMES", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -21,6 +27,12 @@ Object.defineProperty(exports, "NativeHeliumUpsellView", {
|
|
|
21
27
|
return _nativeInterface.NativeHeliumUpsellView;
|
|
22
28
|
}
|
|
23
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "RevenueCatConfig", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _revenuecat.RevenueCatConfig;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
24
36
|
Object.defineProperty(exports, "UpsellView", {
|
|
25
37
|
enumerable: true,
|
|
26
38
|
get: function () {
|
|
@@ -51,5 +63,7 @@ Object.defineProperty(exports, "useHelium", {
|
|
|
51
63
|
return _nativeInterface.useHelium;
|
|
52
64
|
}
|
|
53
65
|
});
|
|
66
|
+
var _revenuecat = require("./handlers/revenuecat.js");
|
|
54
67
|
var _nativeInterface = require("./native-interface.js");
|
|
68
|
+
var _types = require("./types.js");
|
|
55
69
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_revenuecat","require","_nativeInterface","_types"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useHelium = exports.presentUpsell = exports.initialize = exports.hideUpsell = exports.getDownloadStatus = exports.UpsellView = exports.NativeHeliumUpsellView = exports.HeliumProvider = exports.HELIUM_CTA_NAMES = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _revenuecat = require("./handlers/revenuecat.js");
|
|
9
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -92,16 +93,16 @@ const HeliumProvider = ({
|
|
|
92
93
|
ref: fallbackRef,
|
|
93
94
|
collapsable: false,
|
|
94
95
|
style: {
|
|
95
|
-
display: 'none'
|
|
96
|
+
display: 'none'
|
|
96
97
|
},
|
|
97
98
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(FallbackView, {})
|
|
98
99
|
}), children]
|
|
99
100
|
});
|
|
100
101
|
};
|
|
101
102
|
|
|
102
|
-
// Update initialize to accept config
|
|
103
|
+
// Update initialize to accept full config
|
|
103
104
|
exports.HeliumProvider = HeliumProvider;
|
|
104
|
-
const initialize = async
|
|
105
|
+
const initialize = async config => {
|
|
105
106
|
// Wait for the provider to be mounted if it's not already
|
|
106
107
|
if (!isProviderMounted) {
|
|
107
108
|
await providerMountedPromise;
|
|
@@ -111,6 +112,26 @@ const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
111
112
|
throw new Error('Failed to get fallback view reference. Make sure HeliumProvider is mounted with a fallback view.');
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
// Determine purchase handlers based on config
|
|
116
|
+
let purchaseHandler;
|
|
117
|
+
if (config.purchaseConfig.type === 'revenuecat') {
|
|
118
|
+
// Instantiate RevenueCat handler
|
|
119
|
+
const rcHandler = new _revenuecat.RevenueCatHeliumHandler(config.purchaseConfig.apiKey);
|
|
120
|
+
purchaseHandler = {
|
|
121
|
+
makePurchase: rcHandler.makePurchase.bind(rcHandler),
|
|
122
|
+
restorePurchases: rcHandler.restorePurchases.bind(rcHandler)
|
|
123
|
+
};
|
|
124
|
+
} else if (config.purchaseConfig.type === 'custom') {
|
|
125
|
+
// Use custom callbacks
|
|
126
|
+
purchaseHandler = {
|
|
127
|
+
makePurchase: config.purchaseConfig.makePurchase,
|
|
128
|
+
restorePurchases: config.purchaseConfig.restorePurchases
|
|
129
|
+
};
|
|
130
|
+
} else {
|
|
131
|
+
// Handle potential future types or throw error
|
|
132
|
+
throw new Error('Invalid purchaseConfig type provided.');
|
|
133
|
+
}
|
|
134
|
+
|
|
114
135
|
// Update download status to inProgress
|
|
115
136
|
updateDownloadStatus('inProgress');
|
|
116
137
|
|
|
@@ -141,22 +162,23 @@ const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
141
162
|
}
|
|
142
163
|
}
|
|
143
164
|
|
|
144
|
-
// Forward all events to the callback
|
|
145
|
-
|
|
165
|
+
// Forward all events to the callback provided in config
|
|
166
|
+
config.onHeliumPaywallEvent(event);
|
|
146
167
|
});
|
|
147
168
|
|
|
148
|
-
// Set up purchase event listener
|
|
169
|
+
// Set up purchase event listener using the determined handler
|
|
149
170
|
heliumEventEmitter.addListener('helium_make_purchase', async event => {
|
|
150
|
-
const
|
|
171
|
+
const result = await purchaseHandler.makePurchase(event.productId);
|
|
151
172
|
HeliumBridge.handlePurchaseResponse({
|
|
152
173
|
transactionId: event.transactionId,
|
|
153
|
-
status: status
|
|
174
|
+
status: result.status,
|
|
175
|
+
error: result.error
|
|
154
176
|
});
|
|
155
177
|
});
|
|
156
178
|
|
|
157
|
-
// Set up restore purchases event listener
|
|
179
|
+
// Set up restore purchases event listener using the determined handler
|
|
158
180
|
heliumEventEmitter.addListener('helium_restore_purchases', async event => {
|
|
159
|
-
const success = await
|
|
181
|
+
const success = await purchaseHandler.restorePurchases();
|
|
160
182
|
HeliumBridge.handleRestoreResponse({
|
|
161
183
|
transactionId: event.transactionId,
|
|
162
184
|
status: success ? 'restored' : 'failed'
|
|
@@ -170,10 +192,8 @@ const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
170
192
|
triggers: config.triggers || [],
|
|
171
193
|
customUserId: config.customUserId || null,
|
|
172
194
|
customAPIEndpoint: config.customAPIEndpoint || null,
|
|
173
|
-
customUserTraits: config.customUserTraits == null ? {
|
|
174
|
-
|
|
175
|
-
} : config.customUserTraits
|
|
176
|
-
}, {});
|
|
195
|
+
customUserTraits: config.customUserTraits == null ? {} : config.customUserTraits
|
|
196
|
+
});
|
|
177
197
|
};
|
|
178
198
|
|
|
179
199
|
// Update the other methods to be synchronous
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_react","_interopRequireWildcard","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","HeliumBridge","NativeModules","heliumEventEmitter","NativeEventEmitter","NativeHeliumUpsellView","exports","requireNativeComponent","isProviderMounted","providerMountedPromise","resolveProviderMounted","Promise","resolve","globalDownloadStatus","getDownloadStatus","HeliumContext","createContext","undefined","setDownloadStatusRef","updateDownloadStatus","status","useHelium","context","useContext","Error","fallbackRef","createRef","FallbackViewComponent","HeliumProvider","children","fallbackView","FallbackView","downloadStatus","setDownloadStatus","useState","useEffect","jsxs","Provider","value","jsx","View","ref","collapsable","style","display","initialize","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","_interopRequireWildcard","_revenuecat","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","HeliumBridge","NativeModules","heliumEventEmitter","NativeEventEmitter","NativeHeliumUpsellView","exports","requireNativeComponent","isProviderMounted","providerMountedPromise","resolveProviderMounted","Promise","resolve","globalDownloadStatus","getDownloadStatus","HeliumContext","createContext","undefined","setDownloadStatusRef","updateDownloadStatus","status","useHelium","context","useContext","Error","fallbackRef","createRef","FallbackViewComponent","HeliumProvider","children","fallbackView","FallbackView","downloadStatus","setDownloadStatus","useState","useEffect","jsxs","Provider","value","jsx","View","ref","collapsable","style","display","initialize","config","viewTag","findNodeHandle","current","purchaseHandler","purchaseConfig","type","rcHandler","RevenueCatHeliumHandler","apiKey","makePurchase","bind","restorePurchases","addListener","event","paywallTemplateName","setNativeProps","onHeliumPaywallEvent","result","productId","handlePurchaseResponse","transactionId","error","success","handleRestoreResponse","fallbackPaywall","triggers","customUserId","customAPIEndpoint","customUserTraits","presentUpsell","triggerName","onFallback","getFetchedTriggerNames","triggerNames","includes","hideUpsell","UpsellView","trigger","fallbackViewProps","fallbackViewWrapperStyles","HELIUM_CTA_NAMES","SCHEDULE_CALL","SUBSCRIBE_BUTTON"],"sourceRoot":"../../src","sources":["native-interface.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAAgE,IAAAI,WAAA,GAAA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AA,EAAClC,sBAAsB;IAAC+E,OAAO,EAAEA;EAAQ,CAAE,CAAC;AACrD,CAAC;AAAC9E,OAAA,CAAA6E,UAAA,GAAAA,UAAA;AAEK,MAAMI,gBAAgB,GAAAjF,OAAA,CAAAiF,gBAAA,GAAG;EAC9BC,aAAa,EAAE,eAAe;EAC9BC,gBAAgB,EAAE;AACpB,CAAC","ignoreList":[]}
|
package/lib/commonjs/types.js
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CustomPurchaseConfig = CustomPurchaseConfig;
|
|
7
|
+
// --- Purchase Configuration Types ---
|
|
8
|
+
|
|
9
|
+
/** Interface for providing custom purchase handling logic. */
|
|
10
|
+
|
|
11
|
+
/** Configuration for using the built-in RevenueCat handler. */
|
|
12
|
+
|
|
13
|
+
// Union type for the purchase configuration
|
|
14
|
+
|
|
15
|
+
// Add other config types here in the future, e.g. | StripePurchaseConfig
|
|
16
|
+
|
|
17
|
+
// Helper function for creating Custom Purchase Config
|
|
18
|
+
function CustomPurchaseConfig(callbacks) {
|
|
19
|
+
return {
|
|
20
|
+
type: 'custom',
|
|
21
|
+
makePurchase: callbacks.makePurchase,
|
|
22
|
+
restorePurchases: callbacks.restorePurchases
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// --- Main Helium Configuration ---
|
|
27
|
+
|
|
28
|
+
// --- Other Existing Types ---
|
|
2
29
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["CustomPurchaseConfig","callbacks","type","makePurchase","restorePurchases"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAOA;;AAEA;;AAQA;;AAQA;;AAEA;;AAEA;AACO,SAASA,oBAAoBA,CAACC,SAGpC,EAA2B;EAC1B,OAAO;IACLC,IAAI,EAAE,QAAQ;IACdC,YAAY,EAAEF,SAAS,CAACE,YAAY;IACpCC,gBAAgB,EAAEH,SAAS,CAACG;EAC9B,CAAC;AACH;;AAEA;;AAiBA","ignoreList":[]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Purchases, { PURCHASES_ERROR_CODE } from 'react-native-purchases';
|
|
4
|
+
// Rename the factory function
|
|
5
|
+
export function RevenueCatConfig(config) {
|
|
6
|
+
return {
|
|
7
|
+
type: 'revenuecat',
|
|
8
|
+
apiKey: config?.apiKey
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export class RevenueCatHeliumHandler {
|
|
12
|
+
productIdToPackageMapping = {};
|
|
13
|
+
isMappingInitialized = false;
|
|
14
|
+
initializationPromise = null;
|
|
15
|
+
constructor(apiKey) {
|
|
16
|
+
if (apiKey) {
|
|
17
|
+
Purchases.configure({
|
|
18
|
+
apiKey
|
|
19
|
+
});
|
|
20
|
+
} else {}
|
|
21
|
+
this.initializePackageMapping();
|
|
22
|
+
}
|
|
23
|
+
async initializePackageMapping() {
|
|
24
|
+
if (this.initializationPromise) {
|
|
25
|
+
return this.initializationPromise;
|
|
26
|
+
}
|
|
27
|
+
this.initializationPromise = (async () => {
|
|
28
|
+
try {
|
|
29
|
+
const offerings = await Purchases.getOfferings();
|
|
30
|
+
if (offerings.current?.availablePackages) {
|
|
31
|
+
offerings.current.availablePackages.forEach(pkg => {
|
|
32
|
+
if (pkg.product?.identifier) {
|
|
33
|
+
this.productIdToPackageMapping[pkg.product.identifier] = pkg;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
} else {}
|
|
37
|
+
this.isMappingInitialized = true;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
this.isMappingInitialized = false;
|
|
40
|
+
} finally {
|
|
41
|
+
this.initializationPromise = null;
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
return this.initializationPromise;
|
|
45
|
+
}
|
|
46
|
+
async ensureMappingInitialized() {
|
|
47
|
+
if (!this.isMappingInitialized && !this.initializationPromise) {
|
|
48
|
+
await this.initializePackageMapping();
|
|
49
|
+
} else if (this.initializationPromise) {
|
|
50
|
+
await this.initializationPromise;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async makePurchase(productId) {
|
|
54
|
+
await this.ensureMappingInitialized();
|
|
55
|
+
const pkg = this.productIdToPackageMapping[productId];
|
|
56
|
+
if (!pkg) {
|
|
57
|
+
return {
|
|
58
|
+
status: 'failed',
|
|
59
|
+
error: `RevenueCat Package not found for ID: ${productId}`
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const {
|
|
64
|
+
customerInfo
|
|
65
|
+
} = await Purchases.purchasePackage(pkg);
|
|
66
|
+
const isActive = this.isProductActive(customerInfo, productId);
|
|
67
|
+
if (isActive) {
|
|
68
|
+
return {
|
|
69
|
+
status: 'purchased'
|
|
70
|
+
};
|
|
71
|
+
} else {
|
|
72
|
+
// This case might occur if the purchase succeeded but the entitlement wasn't immediately active
|
|
73
|
+
// or if a different product became active.
|
|
74
|
+
// Consider if polling/listening might be needed here too, similar to pending.
|
|
75
|
+
// For now, returning failed as the specific product isn't confirmed active.
|
|
76
|
+
return {
|
|
77
|
+
status: 'failed',
|
|
78
|
+
error: 'Purchase possibly complete but entitlement/subscription not active for this product.'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const purchasesError = error;
|
|
83
|
+
if (purchasesError?.code === PURCHASES_ERROR_CODE.PAYMENT_PENDING_ERROR) {
|
|
84
|
+
// Wait for a terminal state for up to 5 seconds
|
|
85
|
+
return new Promise(resolve => {
|
|
86
|
+
// Define the listener function separately to remove it later
|
|
87
|
+
const updateListener = updatedCustomerInfo => {
|
|
88
|
+
const isActive = this.isProductActive(updatedCustomerInfo, productId);
|
|
89
|
+
if (isActive) {
|
|
90
|
+
clearTimeout(timeoutId);
|
|
91
|
+
// Remove listener using the function reference
|
|
92
|
+
Purchases.removeCustomerInfoUpdateListener(updateListener);
|
|
93
|
+
resolve({
|
|
94
|
+
status: 'purchased'
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const timeoutId = setTimeout(() => {
|
|
99
|
+
// Remove listener using the function reference on timeout
|
|
100
|
+
Purchases.removeCustomerInfoUpdateListener(updateListener);
|
|
101
|
+
resolve({
|
|
102
|
+
status: 'pending'
|
|
103
|
+
});
|
|
104
|
+
}, 5000);
|
|
105
|
+
|
|
106
|
+
// Add the listener
|
|
107
|
+
Purchases.addCustomerInfoUpdateListener(updateListener);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (purchasesError?.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR) {
|
|
111
|
+
return {
|
|
112
|
+
status: 'cancelled'
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Handle other errors
|
|
117
|
+
return {
|
|
118
|
+
status: 'failed',
|
|
119
|
+
error: purchasesError?.message || 'RevenueCat purchase failed.'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Helper function to check if a product is active in CustomerInfo
|
|
125
|
+
isProductActive(customerInfo, productId) {
|
|
126
|
+
return Object.values(customerInfo.entitlements.active).some(entitlement => entitlement.productIdentifier === productId) || customerInfo.activeSubscriptions.includes(productId) || customerInfo.allPurchasedProductIdentifiers.includes(productId);
|
|
127
|
+
}
|
|
128
|
+
async restorePurchases() {
|
|
129
|
+
try {
|
|
130
|
+
const customerInfo = await Purchases.restorePurchases();
|
|
131
|
+
const isActive = Object.keys(customerInfo.entitlements.active).length > 0;
|
|
132
|
+
return isActive;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=revenuecat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Purchases","PURCHASES_ERROR_CODE","RevenueCatConfig","config","type","apiKey","RevenueCatHeliumHandler","productIdToPackageMapping","isMappingInitialized","initializationPromise","constructor","configure","initializePackageMapping","offerings","getOfferings","current","availablePackages","forEach","pkg","product","identifier","error","ensureMappingInitialized","makePurchase","productId","status","customerInfo","purchasePackage","isActive","isProductActive","purchasesError","code","PAYMENT_PENDING_ERROR","Promise","resolve","updateListener","updatedCustomerInfo","clearTimeout","timeoutId","removeCustomerInfoUpdateListener","setTimeout","addCustomerInfoUpdateListener","PURCHASE_CANCELLED_ERROR","message","Object","values","entitlements","active","some","entitlement","productIdentifier","activeSubscriptions","includes","allPurchasedProductIdentifiers","restorePurchases","keys","length"],"sourceRoot":"../../../src","sources":["handlers/revenuecat.ts"],"mappings":";;AAAA,OAAOA,SAAS,IAAIC,oBAAoB,QAAQ,wBAAwB;AAIxE;AACA,OAAO,SAASC,gBAAgBA,CAACC,MAA4B,EAA4B;EACrF,OAAO;IACHC,IAAI,EAAE,YAAY;IAClBC,MAAM,EAAEF,MAAM,EAAEE;EACpB,CAAC;AACL;AAEA,OAAO,MAAMC,uBAAuB,CAAC;EACzBC,yBAAyB,GAAqC,CAAC,CAAC;EAChEC,oBAAoB,GAAY,KAAK;EACrCC,qBAAqB,GAAyB,IAAI;EAE1DC,WAAWA,CAACL,MAAe,EAAE;IACzB,IAAIA,MAAM,EAAE;MACRL,SAAS,CAACW,SAAS,CAAC;QAAEN;MAAO,CAAC,CAAC;IACnC,CAAC,MAAM,CACP;IACA,IAAI,CAACO,wBAAwB,CAAC,CAAC;EACnC;EAEA,MAAcA,wBAAwBA,CAAA,EAAkB;IACpD,IAAI,IAAI,CAACH,qBAAqB,EAAE;MAC5B,OAAO,IAAI,CAACA,qBAAqB;IACrC;IACA,IAAI,CAACA,qBAAqB,GA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ES,cAAc,EAAEa,OAAO,IAAI;MAA8B,CAAC;IAChG;EACJ;;EAEA;EACQd,eAAeA,CAACH,YAA0B,EAAEF,SAAiB,EAAW;IAC5E,OAAOoB,MAAM,CAACC,MAAM,CAACnB,YAAY,CAACoB,YAAY,CAACC,MAAM,CAAC,CAACC,IAAI,CAAEC,WAAqC,IAAKA,WAAW,CAACC,iBAAiB,KAAK1B,SAAS,CAAC,IACzIE,YAAY,CAACyB,mBAAmB,CAACC,QAAQ,CAAC5B,SAAS,CAAC,IACpDE,YAAY,CAAC2B,8BAA8B,CAACD,QAAQ,CAAC5B,SAAS,CAAC;EAC7E;EAEA,MAAM8B,gBAAgBA,CAAA,EAAqB;IACvC,IAAI;MACA,MAAM5B,YAAY,GAAG,MAAM1B,SAAS,CAACsD,gBAAgB,CAAC,CAAC;MACvD,MAAM1B,QAAQ,GAAGgB,MAAM,CAACW,IAAI,CAAC7B,YAAY,CAACoB,YAAY,CAACC,MAAM,CAAC,CAACS,MAAM,GAAG,CAAC;MACzE,OAAO5B,QAAQ;IACnB,CAAC,CAAC,OAAOP,KAAK,EAAE;MACZ,OAAO,KAAK;IAChB;EACJ;AACJ","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
export { RevenueCatConfig } from "./handlers/revenuecat.js";
|
|
3
4
|
export { HeliumProvider, initialize, presentUpsell, hideUpsell, UpsellView, HELIUM_CTA_NAMES, useHelium, NativeHeliumUpsellView } from "./native-interface.js";
|
|
5
|
+
export { CustomPurchaseConfig } from "./types.js";
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HeliumProvider","initialize","presentUpsell","hideUpsell","UpsellView","HELIUM_CTA_NAMES","useHelium","NativeHeliumUpsellView"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,UAAU,EAAEC,aAAa,EAAEC,UAAU,EAAEC,UAAU,EAAEC,gBAAgB,EAAEC,SAAS,EAAEC,sBAAsB,QAAQ,uBAAoB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["RevenueCatConfig","HeliumProvider","initialize","presentUpsell","hideUpsell","UpsellView","HELIUM_CTA_NAMES","useHelium","NativeHeliumUpsellView","CustomPurchaseConfig"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,gBAAgB,QAAQ,0BAAuB;AACxD,SAASC,cAAc,EAAEC,UAAU,EAAEC,aAAa,EAAEC,UAAU,EAAEC,UAAU,EAAEC,gBAAgB,EAAEC,SAAS,EAAEC,sBAAsB,QAAQ,uBAAoB;AAE3J,SAASC,oBAAoB,QAAQ,YAAS","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { findNodeHandle, NativeModules, View, NativeEventEmitter, requireNativeComponent } from 'react-native';
|
|
4
4
|
import React, { createRef, useEffect, useState, createContext, useContext } from 'react';
|
|
5
|
+
import { RevenueCatHeliumHandler } from "./handlers/revenuecat.js";
|
|
5
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
7
|
const {
|
|
7
8
|
HeliumBridge
|
|
@@ -85,15 +86,15 @@ export const HeliumProvider = ({
|
|
|
85
86
|
ref: fallbackRef,
|
|
86
87
|
collapsable: false,
|
|
87
88
|
style: {
|
|
88
|
-
display: 'none'
|
|
89
|
+
display: 'none'
|
|
89
90
|
},
|
|
90
91
|
children: /*#__PURE__*/_jsx(FallbackView, {})
|
|
91
92
|
}), children]
|
|
92
93
|
});
|
|
93
94
|
};
|
|
94
95
|
|
|
95
|
-
// Update initialize to accept config
|
|
96
|
-
export const initialize = async
|
|
96
|
+
// Update initialize to accept full config
|
|
97
|
+
export const initialize = async config => {
|
|
97
98
|
// Wait for the provider to be mounted if it's not already
|
|
98
99
|
if (!isProviderMounted) {
|
|
99
100
|
await providerMountedPromise;
|
|
@@ -103,6 +104,26 @@ export const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
103
104
|
throw new Error('Failed to get fallback view reference. Make sure HeliumProvider is mounted with a fallback view.');
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
// Determine purchase handlers based on config
|
|
108
|
+
let purchaseHandler;
|
|
109
|
+
if (config.purchaseConfig.type === 'revenuecat') {
|
|
110
|
+
// Instantiate RevenueCat handler
|
|
111
|
+
const rcHandler = new RevenueCatHeliumHandler(config.purchaseConfig.apiKey);
|
|
112
|
+
purchaseHandler = {
|
|
113
|
+
makePurchase: rcHandler.makePurchase.bind(rcHandler),
|
|
114
|
+
restorePurchases: rcHandler.restorePurchases.bind(rcHandler)
|
|
115
|
+
};
|
|
116
|
+
} else if (config.purchaseConfig.type === 'custom') {
|
|
117
|
+
// Use custom callbacks
|
|
118
|
+
purchaseHandler = {
|
|
119
|
+
makePurchase: config.purchaseConfig.makePurchase,
|
|
120
|
+
restorePurchases: config.purchaseConfig.restorePurchases
|
|
121
|
+
};
|
|
122
|
+
} else {
|
|
123
|
+
// Handle potential future types or throw error
|
|
124
|
+
throw new Error('Invalid purchaseConfig type provided.');
|
|
125
|
+
}
|
|
126
|
+
|
|
106
127
|
// Update download status to inProgress
|
|
107
128
|
updateDownloadStatus('inProgress');
|
|
108
129
|
|
|
@@ -133,22 +154,23 @@ export const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
133
154
|
}
|
|
134
155
|
}
|
|
135
156
|
|
|
136
|
-
// Forward all events to the callback
|
|
137
|
-
|
|
157
|
+
// Forward all events to the callback provided in config
|
|
158
|
+
config.onHeliumPaywallEvent(event);
|
|
138
159
|
});
|
|
139
160
|
|
|
140
|
-
// Set up purchase event listener
|
|
161
|
+
// Set up purchase event listener using the determined handler
|
|
141
162
|
heliumEventEmitter.addListener('helium_make_purchase', async event => {
|
|
142
|
-
const
|
|
163
|
+
const result = await purchaseHandler.makePurchase(event.productId);
|
|
143
164
|
HeliumBridge.handlePurchaseResponse({
|
|
144
165
|
transactionId: event.transactionId,
|
|
145
|
-
status: status
|
|
166
|
+
status: result.status,
|
|
167
|
+
error: result.error
|
|
146
168
|
});
|
|
147
169
|
});
|
|
148
170
|
|
|
149
|
-
// Set up restore purchases event listener
|
|
171
|
+
// Set up restore purchases event listener using the determined handler
|
|
150
172
|
heliumEventEmitter.addListener('helium_restore_purchases', async event => {
|
|
151
|
-
const success = await
|
|
173
|
+
const success = await purchaseHandler.restorePurchases();
|
|
152
174
|
HeliumBridge.handleRestoreResponse({
|
|
153
175
|
transactionId: event.transactionId,
|
|
154
176
|
status: success ? 'restored' : 'failed'
|
|
@@ -162,10 +184,8 @@ export const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
162
184
|
triggers: config.triggers || [],
|
|
163
185
|
customUserId: config.customUserId || null,
|
|
164
186
|
customAPIEndpoint: config.customAPIEndpoint || null,
|
|
165
|
-
customUserTraits: config.customUserTraits == null ? {
|
|
166
|
-
|
|
167
|
-
} : config.customUserTraits
|
|
168
|
-
}, {});
|
|
187
|
+
customUserTraits: config.customUserTraits == null ? {} : config.customUserTraits
|
|
188
|
+
});
|
|
169
189
|
};
|
|
170
190
|
|
|
171
191
|
// Update the other methods to be synchronous
|