apps-sdk 1.0.146 → 1.0.147

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.146",
3
+ "version": "1.0.147",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -244,7 +244,6 @@ const styles = {
244
244
  backgroundColor: '#000',
245
245
  width: '100%',
246
246
  height: '100%',
247
- paddingTop: 35,
248
247
  },
249
248
  }
250
249
 
@@ -1,248 +0,0 @@
1
- import React, { useState, useRef, useEffect } from 'react';
2
- import { BottomSheet } from 'react-native-btr';
3
- import { WebView } from 'react-native-webview';
4
- import { View, Platform } from "react-native";
5
- import Utils from "../libraries/Utils";
6
- import Networking from "../libraries/Networking";
7
- import PayWallLogic from "../libraries/PayWallLogic";
8
- import Session from "../libraries/Session";
9
- import * as Linking from 'expo-linking';
10
- import * as config from "../../config";
11
-
12
- const PayWall = (props) => {
13
- const { visible, onClose, type, keyword, onSubscribe, onPaymentError, acceptTerms } = props;
14
- const webviewRef = useRef(null);
15
- const [paywallData, setPaywallData] = useState({});
16
- const [paywallJS, setPaywallJS] = useState('');
17
- const [htmlContent, setHtmlContent] = useState('');
18
-
19
- useEffect(() => {
20
- initPayWall();
21
- }, []);
22
-
23
- useEffect(() => {
24
- if (PayWallLogic.paywallJS === '' || Object.keys(paywallData).length === 0) {
25
- getPayWallData(type, keyword);
26
- // config.DEBUG_MODE && console.log('PayWallLogic.paywallJS:', PayWallLogic.paywallJS);
27
- // config.DEBUG_MODE && console.log('PayWallLogic.paywallJS type:', typeof PayWallLogic.paywallJS);
28
- }
29
- }, [type, keyword, paywallData]);
30
-
31
- const initPayWall = async () => {
32
- await PayWallLogic.initializePayWall();
33
- }
34
-
35
- const getURL = (type, keyword) => {
36
- return config.PAYWALL_DATA[type][keyword].url || '';
37
- }
38
-
39
- const getDesignIDFromURL = (url) => {
40
- const urlObject = new URL(url);
41
- return urlObject.searchParams.get('dsn_id') || '';
42
- }
43
-
44
- const getPayWallData = (type, keyword) => {
45
- if (!config.PAYWALL_DATA[type] || !config.PAYWALL_DATA[type][keyword]) {
46
- console.log('No se encontraron datos para el paywall.');
47
- return;
48
- }
49
- setPaywallData(config.PAYWALL_DATA[type][keyword]);
50
- }
51
-
52
- const handleMessage = (message) => {
53
- const data = JSON.parse(message.nativeEvent.data);
54
- const event = "event" + Utils.capitalize(data.query);
55
- config.DEBUG_MODE && console.log('handleMessage event:', event, data);
56
- if (typeof this[event] === 'function') {
57
- this[event](data);
58
- } else {
59
- console.log(`El método ${event} no existe en la clase.`);
60
- }
61
- }
62
-
63
- const fetchAndModifyHTML = async () => {
64
- try {
65
- const response = await fetch(paywallData.url);
66
- let html = await response.text();
67
-
68
- for (let ind in config.PAYWALL_DATA.paywall_info) {
69
- let paywallInfo = config.PAYWALL_DATA.paywall_info[ind];
70
- let os = Platform.OS === 'ios' ? 'i' : 'a';
71
- let product_id = paywallInfo.productIdentifier;
72
- if (paywallInfo.localizedPriceYear) {
73
- html = html.replace(new RegExp(`\\[PRICE_YEAR\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPrice);
74
- }
75
- if (paywallInfo.localizedPriceMonth) {
76
- html = html.replace(new RegExp(`\\[PRICE_MONTH\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceMonth);
77
- }
78
- if (paywallInfo.localizedPriceWeek) {
79
- html = html.replace(new RegExp(`\\[PRICE_WEEK\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceWeek);
80
- }
81
- if (paywallInfo.localizedPriceDay) {
82
- html = html.replace(new RegExp(`\\[PRICE_DAY\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceDay);
83
- }
84
- }
85
-
86
- // let paywallJS = await PayWallLogic.getPayWallJS(props);
87
- // html = html.replace(
88
- // '</body>',
89
- // `<script>${paywallJS}</script></body>`
90
- // );
91
-
92
- let tokens = html.match(/\[PRICE.*\]/g);
93
- if (tokens) {
94
- Networking.sendEvent('other', 'cp_price_token_not_replaced', { tokens: tokens, url: paywallData.url });
95
- }
96
- setHtmlContent(html);
97
- } catch (error) {
98
- console.log('Error al obtener el HTML:', error);
99
- }
100
- }
101
-
102
- useEffect(() => {
103
- if (props.visible && paywallData.url) {
104
- const fetchData = async () => {
105
- await fetchAndModifyHTML();
106
- setTimeout(() => {
107
- Networking.sendEvent('scene', 'payment_card', {
108
- user_id: Session.getUserID(),
109
- scene: 'payment_card'
110
- });
111
- }, 3000);
112
- };
113
- fetchData();
114
- }
115
- }, [props.visible, paywallData.url]);
116
-
117
- const getCardID = () => {
118
- return getDesignIDFromURL(paywallData.url) || '';
119
- }
120
-
121
- // --------------------------------------- Eventos ---------------------------------------
122
- const eventClickClose = (data) => {
123
- Networking.sendEvent('action', 'continue_free');
124
- onClose();
125
- }
126
-
127
- const eventClickSubscribe = (data) => {
128
- Networking.sendEvent('other', 'cta_click_init');
129
-
130
- if (Platform.OS === 'ios' && data.iid) {
131
- data.id = data.iid;
132
- } else {
133
- if (data.aid) {
134
- data.id = data.aid;
135
- }
136
- }
137
-
138
- if (paywallData && data.id && data.id.length > 0) {
139
- Networking.sendEvent('action', 'cta', {product_id: data.id});
140
- let subscribed = PayWallLogic.executePurchase(data.id, hideSpinner, hidePayWall).then((subscribed) => {
141
- console.log('subscription result: ', subscribed);
142
- if (subscribed) {
143
- onSubscribe(false);
144
- } else {
145
- onPaymentError();
146
- }
147
- });
148
- } else {
149
- Networking.sendEvent('other', 'cta_click_error_paywall_data');
150
- onPaymentError();
151
- }
152
- }
153
-
154
- const eventClickFreeSubscription = (data) => {
155
- Networking.sendEvent('action', 'continue_free');
156
- onClose();
157
- }
158
-
159
- const eventClickAcceptTerms = (data) => {
160
- acceptTerms();
161
- }
162
-
163
- const eventClickRestore = (data) => {
164
- Networking.sendEvent('action', 'subscription_restore');
165
- let subscribed = PayWallLogic.restorePurchase(hideSpinner, hidePayWall).then((subscribed) => {
166
- console.log('subscription result: ',subscribed);
167
- if (subscribed) {
168
- onSubscribe(true);
169
- }
170
- });
171
- }
172
-
173
- const eventTrackAction = (data) => {
174
- config.DEBUG_MODE && console.debug('eventTrackAction', data);
175
- Networking.sendEvent('action', data.eventName, data || {});
176
- }
177
-
178
- const eventTrackScene = (data) => {
179
- config.DEBUG_MODE && console.debug('eventTrackScene', data);
180
- Networking.sendEvent('scene', data.eventName, data || {});
181
- }
182
-
183
- const hideSpinner = () => {
184
- const event = {
185
- event: 'hideLoader',
186
- value: {
187
- status: true,
188
- }
189
- }
190
- console.log('SDK setHideLoaderAppquiles',event);
191
- if (paywallData.url) {
192
- const jsHideSpinner = `Appquiles.emitAppEvent(${JSON.stringify(event)});$('.spinner').hide(); true;`;
193
- webviewRef.current.injectJavaScript(jsHideSpinner);
194
- }
195
- }
196
-
197
- const hidePayWall = () => {
198
- onClose();
199
- }
200
-
201
- // --------------------------------------- Eventos ---------------------------------------
202
-
203
- if (!paywallData.url) {
204
- config.DEBUG_MODE && console.log('PayWallLogic: paywallData no tiene url para este type / keyword -> ' + type + ' / ' + keyword);
205
- return null;
206
- }
207
-
208
- return (
209
- <BottomSheet visible={visible}>
210
- <View style={styles.bottomNavigationView}>
211
- {htmlContent ? (
212
- <WebView
213
- style={{ flex: 1 }}
214
- originWhitelist={['*']}
215
- source={{ html: htmlContent }}
216
- javaScriptEnabled
217
- ref={webviewRef}
218
- onMessage={handleMessage}
219
- onError={(err) => { console.log('Error al cargar webview:', err) }}
220
- // injectedJavaScript={PayWallLogic.paywallJS}
221
- allowsInlineMediaPlayback={true}
222
- mediaPlaybackRequiresUserAction={false}
223
- onShouldStartLoadWithRequest={request => {
224
- if (request.url !== 'about:blank' && request.url !== paywallData.url) {
225
- Networking.sendEvent('action', 'click_link', { url: request.url });
226
- Linking.openURL(request.url);
227
- return false;
228
- } else {
229
- return true;
230
- }
231
- }}
232
- />
233
- ) : null}
234
- </View>
235
- </BottomSheet>
236
- );
237
- }
238
-
239
- const styles = {
240
- bottomNavigationView: {
241
- backgroundColor: '#000',
242
- width: '100%',
243
- height: '100%',
244
- paddingTop: 35,
245
- },
246
- }
247
-
248
- export default PayWall;