apps-sdk 1.1.55 → 1.1.57

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,5 +1,6 @@
1
1
  import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust, TrackingTransparency, Voice, MixPanel, Adapty, HomeActions, Facebook} from "./src/libraries";
2
2
  import PayWall from "./src/components/PayWall";
3
+ import AdaptyOnboarding from "./src/components/AdaptyOnboarding";
3
4
 
4
5
  class AppsSDK {
5
6
  constructor() {
@@ -56,6 +57,7 @@ export default {
56
57
  mixpanel: MixPanel,
57
58
  tracking: TrackingTransparency,
58
59
  paywall: PayWall,
60
+ adaptyOnboarding: AdaptyOnboarding,
59
61
  notifications: NotificationsPush,
60
62
  voice: Voice,
61
63
  adapty: Adapty,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.1.55",
3
+ "version": "1.1.57",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,203 @@
1
+ import React from 'react';
2
+ import Adapty from '../libraries/Adapty';
3
+ import * as config from '../../config';
4
+
5
+ class AdaptyOnboarding extends React.Component {
6
+ constructor(props) {
7
+ super(props);
8
+ this.onboardingView = null;
9
+ this.isPresenting = false;
10
+ this.remoteConfig = null;
11
+ this.termsAccepted = false;
12
+ this.currentStep = 0;
13
+ this.totalSteps = 0;
14
+ }
15
+
16
+ async componentDidMount() {
17
+ if (this.props.visible) {
18
+ await this.presentOnboarding();
19
+ }
20
+ }
21
+
22
+ async componentDidUpdate(prevProps) {
23
+ if (this.props.visible && !prevProps.visible && !this.isPresenting) {
24
+ await this.presentOnboarding();
25
+ } else if (!this.props.visible && prevProps.visible) {
26
+ await this.dismissOnboarding();
27
+ }
28
+ }
29
+
30
+ componentWillUnmount() {
31
+ this.dismissOnboarding();
32
+ }
33
+
34
+ presentOnboarding = async () => {
35
+ const {
36
+ placementID,
37
+ lang,
38
+ onCustom,
39
+ onClose,
40
+ onError,
41
+ onRemoteConfigLoaded,
42
+ ...handlers
43
+ } = this.props;
44
+
45
+ try {
46
+ this.isPresenting = true;
47
+ const onboarding = await Adapty.getOnboardingForPlacement(placementID, lang);
48
+
49
+ if (onboarding) {
50
+ // Extraer y guardar remote config
51
+ this.remoteConfig = onboarding.remoteConfig || {};
52
+
53
+ // Callback inicial con el config
54
+ if (onRemoteConfigLoaded && this.remoteConfig) {
55
+ config.DEBUG_MODE && console.log('Remote config loaded:', this.remoteConfig);
56
+ onRemoteConfigLoaded(this.remoteConfig);
57
+ }
58
+
59
+ this.onboardingView = await Adapty.createOnboardingView(onboarding);
60
+
61
+ this.onboardingView.registerEventHandlers({
62
+ onCustom: (actionId, meta) => {
63
+ config.DEBUG_MODE && console.log('Onboarding custom action:', actionId, meta);
64
+
65
+ // Marcar términos aceptados solo cuando se dispara este action
66
+ if (actionId === 'accept_terms') {
67
+ this.termsAccepted = true;
68
+ config.DEBUG_MODE && console.log('Terms accepted - can close when reaching last step');
69
+ }
70
+
71
+ // Pasar remoteConfig en el handler
72
+ if (onCustom) {
73
+ onCustom(actionId, meta, this.remoteConfig);
74
+ }
75
+ },
76
+ onClose: async (actionId, meta) => {
77
+ const isLastStep = this.totalSteps > 0 && this.currentStep === this.totalSteps - 1;
78
+ const canClose = this.termsAccepted && isLastStep;
79
+
80
+ config.DEBUG_MODE && console.log('Onboarding close attempt:', {
81
+ actionId,
82
+ meta,
83
+ termsAccepted: this.termsAccepted,
84
+ currentStep: this.currentStep,
85
+ totalSteps: this.totalSteps,
86
+ isLastStep,
87
+ canClose
88
+ });
89
+
90
+ // Solo permitir cerrar si:
91
+ // 1. El usuario aceptó los términos Y
92
+ // 2. Está en el último paso del onboarding
93
+ if (!canClose) {
94
+ config.DEBUG_MODE && console.log('Onboarding close prevented - must accept terms and reach last step');
95
+ return false; // Bloquear cierre
96
+ }
97
+
98
+ // Permitir cerrar
99
+ config.DEBUG_MODE && console.log('Onboarding close allowed - terms accepted and last step reached');
100
+ this.isPresenting = false;
101
+
102
+ // Pasar remoteConfig en el handler
103
+ if (onClose) {
104
+ onClose(actionId, meta, this.remoteConfig);
105
+ }
106
+
107
+ await this.onboardingView.dismiss();
108
+
109
+ // Reset para próxima vez
110
+ this.termsAccepted = false;
111
+ this.currentStep = 0;
112
+ this.totalSteps = 0;
113
+
114
+ return true;
115
+ },
116
+ onError: (error) => {
117
+ console.error('Onboarding error:', error);
118
+ this.isPresenting = false;
119
+ // Pasar remoteConfig en el handler
120
+ if (onError) {
121
+ onError(error, this.remoteConfig);
122
+ }
123
+ return true;
124
+ },
125
+ onAnalytics: (event, data) => {
126
+ config.DEBUG_MODE && console.log('Onboarding analytics:', event, data);
127
+ if (handlers.onAnalytics) {
128
+ handlers.onAnalytics(event, data, this.remoteConfig);
129
+ }
130
+ },
131
+ onPaywall: () => {
132
+ config.DEBUG_MODE && console.log('Onboarding paywall event');
133
+ if (handlers.onPaywall) {
134
+ handlers.onPaywall(this.remoteConfig);
135
+ }
136
+ },
137
+ onStateUpdated: (action, meta) => {
138
+ // Extraer información del paso actual desde meta
139
+ if (meta && typeof meta === 'object') {
140
+ this.currentStep = meta.screen_index ?? this.currentStep;
141
+ this.totalSteps = meta.total_screens ?? this.totalSteps;
142
+
143
+ config.DEBUG_MODE && console.log('Onboarding state updated:', {
144
+ action,
145
+ meta,
146
+ currentStep: this.currentStep,
147
+ totalSteps: this.totalSteps,
148
+ termsAccepted: this.termsAccepted
149
+ });
150
+ }
151
+
152
+ if (handlers.onStateUpdated) {
153
+ handlers.onStateUpdated(action, meta, this.remoteConfig);
154
+ }
155
+ },
156
+ onFinishedLoading: (meta) => {
157
+ config.DEBUG_MODE && console.log('Onboarding finished loading', meta);
158
+ if (handlers.onFinishedLoading) {
159
+ handlers.onFinishedLoading(meta, this.remoteConfig);
160
+ }
161
+ },
162
+ });
163
+
164
+ await this.onboardingView.present();
165
+ } else {
166
+ console.warn('Onboarding not found for placement:', placementID, 'and language:', lang);
167
+ if (this.props.onError) {
168
+ this.props.onError(new Error('Onboarding not found'), this.remoteConfig);
169
+ }
170
+ }
171
+ } catch (error) {
172
+ console.error('Error presenting onboarding:', error);
173
+ this.isPresenting = false;
174
+ if (this.props.onError) {
175
+ this.props.onError(error, this.remoteConfig);
176
+ }
177
+ }
178
+ }
179
+
180
+ dismissOnboarding = async () => {
181
+ if (this.onboardingView && this.isPresenting) {
182
+ try {
183
+ await this.onboardingView.dismiss();
184
+ this.isPresenting = false;
185
+ this.remoteConfig = null;
186
+ } catch (error) {
187
+ console.error('Error dismissing onboarding:', error);
188
+ }
189
+ }
190
+ }
191
+
192
+ // Método público para acceder al config desde el componente padre (opcional)
193
+ getRemoteConfig = () => {
194
+ return this.remoteConfig;
195
+ }
196
+
197
+ render() {
198
+ // Componente invisible, el onboarding se presenta nativamente
199
+ return null;
200
+ }
201
+ }
202
+
203
+ export default AdaptyOnboarding;
package/types/index.d.ts CHANGED
@@ -158,6 +158,22 @@ declare module 'apps-sdk' {
158
158
 
159
159
  export class PayWall extends Component<PayWallProps, {}> {}
160
160
 
161
+ export interface AdaptyOnboardingProps {
162
+ visible: boolean;
163
+ placementID: string;
164
+ lang: string;
165
+ onCustom?: (actionId: string, meta?: Record<string, any>, remoteConfig?: Record<string, any>) => void;
166
+ onClose?: (actionId: string, meta?: Record<string, any>, remoteConfig?: Record<string, any>) => void;
167
+ onError?: (error: Error | string | any, remoteConfig?: Record<string, any>) => void;
168
+ onRemoteConfigLoaded?: (remoteConfig: Record<string, any>) => void;
169
+ onAnalytics?: (event: string | any, data?: Record<string, any>, remoteConfig?: Record<string, any>) => void;
170
+ onPaywall?: (remoteConfig?: Record<string, any>) => void;
171
+ onStateUpdated?: (action: any, meta?: Record<string, any>, remoteConfig?: Record<string, any>) => void;
172
+ onFinishedLoading?: (meta?: Record<string, any>, remoteConfig?: Record<string, any>) => void;
173
+ }
174
+
175
+ export class AdaptyOnboarding extends Component<AdaptyOnboardingProps, {}> {}
176
+
161
177
  export class PayWallLogic {
162
178
  initializePayWall(): Promise<void>;
163
179
  executePurchase(productID: string): Promise<void>;
@@ -278,6 +294,7 @@ declare module 'apps-sdk' {
278
294
  session : Session;
279
295
  utils : Utils;
280
296
  paywall : PayWall;
297
+ adaptyOnboarding : typeof AdaptyOnboarding;
281
298
  rating : Rating;
282
299
  adjust : AdJust;
283
300
  mixpanel : MixPanel;