apps-sdk 2.1.4 → 2.1.6
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/config.js +1 -0
- package/index.js +89 -53
- package/package.json +2 -2
- package/src/libraries/Notifications.js +112 -81
- package/src/libraries/Session.js +31 -0
- package/types/index.d.ts +1 -0
package/config.js
CHANGED
package/index.js
CHANGED
|
@@ -1,69 +1,105 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NotificationsPush,
|
|
3
|
+
Networking,
|
|
4
|
+
Storage,
|
|
5
|
+
Session,
|
|
6
|
+
Utils,
|
|
7
|
+
PayWallLogic,
|
|
8
|
+
Rating,
|
|
9
|
+
AdJust,
|
|
10
|
+
TrackingTransparency,
|
|
11
|
+
Voice,
|
|
12
|
+
MixPanel,
|
|
13
|
+
Adapty,
|
|
14
|
+
HomeActions,
|
|
15
|
+
Facebook,
|
|
16
|
+
Legal,
|
|
17
|
+
Authentication,
|
|
18
|
+
Firebase,
|
|
19
|
+
} from "./src/libraries";
|
|
2
20
|
// import PayWall from "./src/components/PayWall"; // DEPRECATED: Use SDK.adaptyOnboarding or SDK.adapty.showPaywall() instead
|
|
3
21
|
import AdaptyOnboarding from "./src/components/AdaptyOnboarding";
|
|
4
22
|
|
|
5
23
|
class AppsSDK {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
24
|
+
constructor() {
|
|
25
|
+
Storage.setTrackingPermissionFromStorage();
|
|
26
|
+
}
|
|
9
27
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
sobrescribeConsole = () => {
|
|
29
|
+
try {
|
|
30
|
+
console.log("Overwriting console.log and console.debug...");
|
|
31
|
+
const originalConsoleLog = console.log;
|
|
32
|
+
const originalConsoleDebug = console.debug;
|
|
15
33
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
console.log = function () {
|
|
35
|
+
let date = new Date();
|
|
36
|
+
let timestamp =
|
|
37
|
+
date.toLocaleDateString() +
|
|
38
|
+
" " +
|
|
39
|
+
date.toLocaleTimeString() +
|
|
40
|
+
"." +
|
|
41
|
+
date.getMilliseconds();
|
|
42
|
+
originalConsoleLog.apply(
|
|
43
|
+
console,
|
|
44
|
+
["[" + timestamp + "]"].concat(Array.from(arguments)),
|
|
45
|
+
);
|
|
46
|
+
};
|
|
21
47
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
48
|
+
console.debug = function () {
|
|
49
|
+
let date = new Date();
|
|
50
|
+
let timestamp =
|
|
51
|
+
date.toLocaleDateString() +
|
|
52
|
+
" " +
|
|
53
|
+
date.toLocaleTimeString() +
|
|
54
|
+
"." +
|
|
55
|
+
date.getMilliseconds();
|
|
56
|
+
originalConsoleDebug.apply(
|
|
57
|
+
console,
|
|
58
|
+
["[" + timestamp + "]"].concat(Array.from(arguments)),
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("Error al sobreescribir console.log:", error);
|
|
30
63
|
}
|
|
64
|
+
};
|
|
31
65
|
|
|
32
|
-
|
|
33
|
-
|
|
66
|
+
initializePushNotifications = async (onPermissionDenied) => {
|
|
67
|
+
await NotificationsPush.initialize();
|
|
34
68
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
69
|
+
return NotificationsPush.registerForPushNotificationsAsync(
|
|
70
|
+
onPermissionDenied,
|
|
71
|
+
).then(async (expoToken) => {
|
|
72
|
+
return expoToken;
|
|
73
|
+
});
|
|
74
|
+
};
|
|
39
75
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
76
|
+
getNotificationsStatus = async () => {
|
|
77
|
+
return await NotificationsPush.getPushNotificationsStatus();
|
|
78
|
+
};
|
|
43
79
|
}
|
|
44
80
|
|
|
45
81
|
const Core = new AppsSDK();
|
|
46
82
|
Core.sobrescribeConsole();
|
|
47
83
|
export default {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
84
|
+
initializePushNotifications: Core.initializePushNotifications,
|
|
85
|
+
getPushNotificationsStatus: Core.getNotificationsStatus,
|
|
86
|
+
networking: Networking,
|
|
87
|
+
storage: Storage,
|
|
88
|
+
session: Session,
|
|
89
|
+
utils: Utils,
|
|
90
|
+
rating: Rating,
|
|
91
|
+
paywallLogic: PayWallLogic,
|
|
92
|
+
adjust: AdJust,
|
|
93
|
+
mixpanel: MixPanel,
|
|
94
|
+
tracking: TrackingTransparency,
|
|
95
|
+
// paywall: PayWall, // DEPRECATED: Use adaptyOnboarding or adapty.showPaywall() instead
|
|
96
|
+
adaptyOnboarding: AdaptyOnboarding,
|
|
97
|
+
notifications: NotificationsPush,
|
|
98
|
+
voice: Voice,
|
|
99
|
+
adapty: Adapty,
|
|
100
|
+
homeActions: HomeActions,
|
|
101
|
+
facebook: Facebook,
|
|
102
|
+
firebase: Firebase,
|
|
103
|
+
legal: Legal,
|
|
104
|
+
authentication: Authentication,
|
|
105
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apps-sdk",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "Apps SDK - Compatible with Expo SDK 54 + React 19 - add
|
|
3
|
+
"version": "2.1.6",
|
|
4
|
+
"description": "Apps SDK - Compatible with Expo SDK 54 + React 19 - add generic method checksubscription to check if user has active subscription in webapp, and push notifications handler to handle incoming notifications and route to correct screen",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "ASD",
|
|
7
7
|
"license": "ISC",
|
|
@@ -1,100 +1,131 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {Platform } from
|
|
3
|
-
import * as Notifications from
|
|
4
|
-
import * as Device from
|
|
5
|
-
import Constants from
|
|
6
|
-
import { default as Networking } from
|
|
7
|
-
import { default as Storage } from
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import * as Notifications from "expo-notifications";
|
|
4
|
+
import * as Device from "expo-device";
|
|
5
|
+
import Constants from "expo-constants";
|
|
6
|
+
import { default as Networking } from "./Networking";
|
|
7
|
+
import { default as Storage } from "./Storage";
|
|
8
8
|
import MixPanel from "../libraries/MixPanel";
|
|
9
9
|
|
|
10
10
|
class NotificationsPush {
|
|
11
|
-
|
|
11
|
+
initialize = async () => {
|
|
12
|
+
Notifications.setNotificationHandler({
|
|
13
|
+
handleNotification: async () => ({
|
|
14
|
+
shouldShowAlert: true,
|
|
15
|
+
shouldPlaySound: false,
|
|
16
|
+
shouldSetBadge: false,
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
//FirebaseApp.initializeApp();
|
|
21
|
+
Notifications.addNotificationReceivedListener((notification) => {
|
|
22
|
+
console.log(
|
|
23
|
+
"addNotificationReceivedListener",
|
|
24
|
+
JSON.stringify(notification),
|
|
25
|
+
);
|
|
26
|
+
});
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
Notifications.addNotificationResponseReceivedListener((response) => {
|
|
29
|
+
console.log(
|
|
30
|
+
"addNotificationResponseReceivedListener",
|
|
31
|
+
JSON.stringify(response),
|
|
32
|
+
);
|
|
33
|
+
Storage.storeData(
|
|
34
|
+
"PUSH_ACTION",
|
|
35
|
+
response.notification.request.content.data,
|
|
36
|
+
);
|
|
37
|
+
Networking.sendEvent("action", "click_notification", {
|
|
38
|
+
date_notification: response.notification.date,
|
|
39
|
+
content: response.notification.request.content,
|
|
40
|
+
});
|
|
41
|
+
MixPanel.trackEvent("Push Notification CTA", {
|
|
42
|
+
action: response.notification.request.content.data.action || "",
|
|
43
|
+
placement: response.notification.request.content.data.placement || "",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
async registerForPushNotificationsAsync(onPermissionDenied) {
|
|
49
|
+
let token;
|
|
25
50
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
51
|
+
if (Platform.OS === "android") {
|
|
52
|
+
try {
|
|
53
|
+
await Notifications.setNotificationChannelAsync("default", {
|
|
54
|
+
name: "default",
|
|
55
|
+
importance: Notifications.AndroidImportance.MAX,
|
|
56
|
+
vibrationPattern: [0, 250, 250, 250],
|
|
57
|
+
lightColor: "#FF231F7C",
|
|
31
58
|
});
|
|
32
|
-
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.log("Error en setNotificationChannelAsync", error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (Device.isDevice) {
|
|
65
|
+
try {
|
|
66
|
+
const { status: existingStatus } =
|
|
67
|
+
await Notifications.getPermissionsAsync();
|
|
68
|
+
let finalStatus = existingStatus;
|
|
69
|
+
|
|
70
|
+
if (existingStatus !== "granted") {
|
|
71
|
+
Networking.sendEvent("other", "push_banner_shown", {
|
|
72
|
+
platform: Platform.OS,
|
|
73
|
+
});
|
|
74
|
+
MixPanel.trackEvent("push_banner_shown", { platform: Platform.OS });
|
|
33
75
|
|
|
34
|
-
|
|
35
|
-
|
|
76
|
+
const { status } = await Notifications.requestPermissionsAsync();
|
|
77
|
+
finalStatus = status;
|
|
36
78
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
79
|
+
if (finalStatus === "granted") {
|
|
80
|
+
Networking.sendEvent("other", "push_permission_granted", {
|
|
81
|
+
platform: Platform.OS,
|
|
82
|
+
});
|
|
83
|
+
MixPanel.trackEvent("push_permission_granted", {
|
|
84
|
+
platform: Platform.OS,
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
Networking.sendEvent("other", "push_permission_denied", {
|
|
88
|
+
platform: Platform.OS,
|
|
89
|
+
});
|
|
90
|
+
MixPanel.trackEvent("push_permission_denied", {
|
|
91
|
+
platform: Platform.OS,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
48
94
|
}
|
|
49
95
|
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (finalStatus === 'granted') {
|
|
63
|
-
Networking.sendEvent('other', 'push_permission_granted', { platform: Platform.OS });
|
|
64
|
-
MixPanel.trackEvent('push_permission_granted', { platform: Platform.OS });
|
|
65
|
-
} else {
|
|
66
|
-
Networking.sendEvent('other', 'push_permission_denied', { platform: Platform.OS });
|
|
67
|
-
MixPanel.trackEvent('push_permission_denied', { platform: Platform.OS });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (finalStatus === 'granted') {
|
|
72
|
-
token = (await Notifications.getExpoPushTokenAsync({"projectId": Constants.expoConfig.extra.eas.projectId})).data;
|
|
73
|
-
console.log('Notification token', token);
|
|
74
|
-
await Storage.storeData('PUSH_NOTIFICATIONS_ACCEPTED', true);
|
|
75
|
-
await Storage.storeData('PUSH_NOTIFICATIONS_TOKEN', token);
|
|
76
|
-
if (token) {
|
|
77
|
-
await Networking.setToken(token);
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
console.log('Notifications permissions not granted');
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.log('Error en getExpoPushTokenAsync', error);
|
|
84
|
-
}
|
|
96
|
+
if (finalStatus === "granted") {
|
|
97
|
+
token = (
|
|
98
|
+
await Notifications.getExpoPushTokenAsync({
|
|
99
|
+
projectId: Constants.expoConfig.extra.eas.projectId,
|
|
100
|
+
})
|
|
101
|
+
).data;
|
|
102
|
+
console.log("Notification token", token);
|
|
103
|
+
await Storage.storeData("PUSH_NOTIFICATIONS_ACCEPTED", true);
|
|
104
|
+
await Storage.storeData("PUSH_NOTIFICATIONS_TOKEN", token);
|
|
105
|
+
if (token) {
|
|
106
|
+
await Networking.setToken(token);
|
|
107
|
+
}
|
|
85
108
|
} else {
|
|
86
|
-
|
|
109
|
+
console.log("Notifications permissions not granted");
|
|
110
|
+
if (typeof onPermissionDenied === "function") {
|
|
111
|
+
onPermissionDenied();
|
|
112
|
+
}
|
|
87
113
|
}
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.log("Error en getExpoPushTokenAsync", error);
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
console.log("Must use physical device for Push Notifications");
|
|
90
119
|
}
|
|
91
120
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return existingStatus;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
121
|
+
return token;
|
|
122
|
+
}
|
|
98
123
|
|
|
124
|
+
async getPushNotificationsStatus() {
|
|
125
|
+
const { status: existingStatus } =
|
|
126
|
+
await Notifications.getPermissionsAsync();
|
|
127
|
+
return existingStatus;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
99
130
|
|
|
100
131
|
export default new NotificationsPush();
|
package/src/libraries/Session.js
CHANGED
|
@@ -284,6 +284,37 @@ class Session {
|
|
|
284
284
|
return 0;
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
+
|
|
288
|
+
checkSubscriptionWebapp = async (webappUrl, websiteId) => {
|
|
289
|
+
config.DEBUG_MODE && console.debug("checkSubscriptionWebapp");
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
const endpoint = `${webappUrl}${config.WEBAPP_PATHS.CHECK_SUBS}`;
|
|
293
|
+
const payload = this.getWebappBasePayload(websiteId);
|
|
294
|
+
|
|
295
|
+
const response = await fetch(endpoint, {
|
|
296
|
+
method: 'POST',
|
|
297
|
+
headers: { 'Content-Type': 'application/json' },
|
|
298
|
+
body: JSON.stringify(payload),
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const data = await response.json();
|
|
302
|
+
config.DEBUG_MODE && console.debug("checkSubscriptionWebapp - result: ", data);
|
|
303
|
+
|
|
304
|
+
if (data?.success && data?.data?.[0]) {
|
|
305
|
+
const subData = data.data[0];
|
|
306
|
+
await this.setIsSubscribed(subData.subscription_active);
|
|
307
|
+
await this.setSubscriptionData(subData);
|
|
308
|
+
|
|
309
|
+
return subData;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return null;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error('[SDK] checkSubscriptionWebapp error:', error);
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
287
318
|
}
|
|
288
319
|
|
|
289
320
|
export default new Session();
|
package/types/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ declare module 'apps-sdk' {
|
|
|
40
40
|
setUserCreateEndpoint(endpoint: string): void;
|
|
41
41
|
setBaseUrl(baseUrl: string): void;
|
|
42
42
|
getCredits(webappUrl: string, websiteId: string): Promise<number>;
|
|
43
|
+
checkSubscriptionWebapp(webappUrl: string, websiteId: string): Promise<any>;
|
|
43
44
|
getWebappBasePayload(websiteId: string, additionalData?: any): any;
|
|
44
45
|
initSession(): Promise<void>;
|
|
45
46
|
storeSessionStructure(): Promise<void>;
|