apps-sdk 2.1.5 → 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/index.js CHANGED
@@ -1,69 +1,105 @@
1
- import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust, TrackingTransparency, Voice, MixPanel, Adapty, HomeActions, Facebook, Legal, Authentication,Firebase} from "./src/libraries";
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
- constructor() {
7
- Storage.setTrackingPermissionFromStorage();
8
- }
24
+ constructor() {
25
+ Storage.setTrackingPermissionFromStorage();
26
+ }
9
27
 
10
- sobrescribeConsole = () => {
11
- try {
12
- console.log('Overwriting console.log and console.debug...');
13
- const originalConsoleLog = console.log;
14
- const originalConsoleDebug = console.debug;
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
- console.log = function() {
17
- let date = new Date();
18
- let timestamp = date.toLocaleDateString() + ' ' + date.toLocaleTimeString() + '.' + date.getMilliseconds();
19
- originalConsoleLog.apply(console, ['[' + timestamp + ']'].concat(Array.from(arguments)));
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
- console.debug = function() {
23
- let date = new Date();
24
- let timestamp = date.toLocaleDateString() + ' ' + date.toLocaleTimeString() + '.' + date.getMilliseconds();
25
- originalConsoleDebug.apply(console, ['[' + timestamp + ']'].concat(Array.from(arguments)));
26
- };
27
- } catch (error) {
28
- console.error('Error al sobreescribir console.log:', error);
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
- initializePushNotifications = async() => {
33
- await NotificationsPush.initialize();
66
+ initializePushNotifications = async (onPermissionDenied) => {
67
+ await NotificationsPush.initialize();
34
68
 
35
- return NotificationsPush.registerForPushNotificationsAsync().then(async (expoToken) => {
36
- return expoToken
37
- })
38
- }
69
+ return NotificationsPush.registerForPushNotificationsAsync(
70
+ onPermissionDenied,
71
+ ).then(async (expoToken) => {
72
+ return expoToken;
73
+ });
74
+ };
39
75
 
40
- getNotificationsStatus = async () => {
41
- return await NotificationsPush.getPushNotificationsStatus();
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
- initializePushNotifications: Core.initializePushNotifications,
49
- getPushNotificationsStatus: Core.getNotificationsStatus,
50
- networking: Networking,
51
- storage: Storage,
52
- session: Session,
53
- utils: Utils,
54
- rating: Rating,
55
- paywallLogic: PayWallLogic,
56
- adjust: AdJust,
57
- mixpanel: MixPanel,
58
- tracking: TrackingTransparency,
59
- // paywall: PayWall, // DEPRECATED: Use adaptyOnboarding or adapty.showPaywall() instead
60
- adaptyOnboarding: AdaptyOnboarding,
61
- notifications: NotificationsPush,
62
- voice: Voice,
63
- adapty: Adapty,
64
- homeActions: HomeActions,
65
- facebook: Facebook,
66
- firebase: Firebase,
67
- legal: Legal,
68
- authentication: Authentication,
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.5",
4
- "description": "Apps SDK - Compatible with Expo SDK 54 + React 19 - add generic method checksubscription to check if user has active subscription in webapp",
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 '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';
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
- initialize = async () => {
11
+ initialize = async () => {
12
+ Notifications.setNotificationHandler({
13
+ handleNotification: async () => ({
14
+ shouldShowAlert: true,
15
+ shouldPlaySound: false,
16
+ shouldSetBadge: false,
17
+ }),
18
+ });
12
19
 
13
- Notifications.setNotificationHandler({
14
- handleNotification: async () => ({
15
- shouldShowAlert: true,
16
- shouldPlaySound: false,
17
- shouldSetBadge: false,
18
- }),
19
- });
20
+ //FirebaseApp.initializeApp();
21
+ Notifications.addNotificationReceivedListener((notification) => {
22
+ console.log(
23
+ "addNotificationReceivedListener",
24
+ JSON.stringify(notification),
25
+ );
26
+ });
20
27
 
21
- //FirebaseApp.initializeApp();
22
- Notifications.addNotificationReceivedListener(notification => {
23
- console.log('addNotificationReceivedListener',JSON.stringify(notification));
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
- Notifications.addNotificationResponseReceivedListener(response => {
27
- console.log('addNotificationResponseReceivedListener',JSON.stringify(response));
28
- Storage.storeData('PUSH_ACTION', response.notification.request.content.data);
29
- Networking.sendEvent('action', 'click_notification', {"date_notification": response.notification.date, "content": response.notification.request.content});
30
- MixPanel.trackEvent('Push Notification CTA' ,{ "action": response.notification.request.content.data.action || "", "placement": response.notification.request.content.data.placement || "" });
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
- async registerForPushNotificationsAsync() {
35
- let token;
76
+ const { status } = await Notifications.requestPermissionsAsync();
77
+ finalStatus = status;
36
78
 
37
- if (Platform.OS === 'android') {
38
- try {
39
- await Notifications.setNotificationChannelAsync('default', {
40
- name: 'default',
41
- importance: Notifications.AndroidImportance.MAX,
42
- vibrationPattern: [0, 250, 250, 250],
43
- lightColor: '#FF231F7C',
44
- });
45
- } catch (error) {
46
- console.log('Error en setNotificationChannelAsync', error);
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 (Device.isDevice) {
51
- try {
52
- const {status: existingStatus} = await Notifications.getPermissionsAsync();
53
- let finalStatus = existingStatus;
54
-
55
- if (existingStatus !== 'granted') {
56
- Networking.sendEvent('other', 'push_banner_shown', { platform: Platform.OS });
57
- MixPanel.trackEvent('push_banner_shown', { platform: Platform.OS });
58
-
59
- const {status} = await Notifications.requestPermissionsAsync();
60
- finalStatus = status;
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
- console.log('Must use physical device for Push Notifications');
109
+ console.log("Notifications permissions not granted");
110
+ if (typeof onPermissionDenied === "function") {
111
+ onPermissionDenied();
112
+ }
87
113
  }
88
-
89
- return token;
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
- async getPushNotificationsStatus() {
93
- const { status: existingStatus } = await Notifications.getPermissionsAsync();
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();