react-native-sdk-pianoio 0.3.0 → 0.3.2

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.
Files changed (50) hide show
  1. package/README.md +3 -3
  2. package/SdkPianoio.podspec +4 -16
  3. package/android/build.gradle +12 -19
  4. package/android/gradle.properties +17 -2
  5. package/android/src/main/java/com/sdkpianoio/SdkPianoioModule.kt +543 -7
  6. package/android/src/main/java/com/sdkpianoio/SdkPianoioPackage.kt +3 -3
  7. package/ios/ComposerPianoImpl.swift +247 -0
  8. package/ios/MyComposerDelegate.swift +79 -206
  9. package/ios/SdkPianoio.swift +150 -0
  10. package/ios/SdkPianoioBridge.m +81 -0
  11. package/ios/services/TokenService.swift +10 -7
  12. package/lib/commonjs/NativeSdkPianoio.ts +20 -22
  13. package/lib/commonjs/PianoComposer.js +36 -97
  14. package/lib/commonjs/PianoComposer.js.map +1 -1
  15. package/lib/commonjs/debug.js +23 -0
  16. package/lib/commonjs/debug.js.map +1 -0
  17. package/lib/commonjs/index.js +7 -0
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/module/NativeSdkPianoio.ts +20 -22
  20. package/lib/module/PianoComposer.js +36 -97
  21. package/lib/module/PianoComposer.js.map +1 -1
  22. package/lib/module/debug.js +18 -0
  23. package/lib/module/debug.js.map +1 -0
  24. package/lib/module/index.js +1 -0
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/typescript/commonjs/src/NativeSdkPianoio.d.ts +9 -20
  27. package/lib/typescript/commonjs/src/NativeSdkPianoio.d.ts.map +1 -1
  28. package/lib/typescript/commonjs/src/PianoComposer.d.ts +25 -28
  29. package/lib/typescript/commonjs/src/PianoComposer.d.ts.map +1 -1
  30. package/lib/typescript/commonjs/src/debug.d.ts +2 -0
  31. package/lib/typescript/commonjs/src/debug.d.ts.map +1 -0
  32. package/lib/typescript/commonjs/src/index.d.ts +1 -0
  33. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  34. package/lib/typescript/module/src/NativeSdkPianoio.d.ts +9 -20
  35. package/lib/typescript/module/src/NativeSdkPianoio.d.ts.map +1 -1
  36. package/lib/typescript/module/src/PianoComposer.d.ts +25 -28
  37. package/lib/typescript/module/src/PianoComposer.d.ts.map +1 -1
  38. package/lib/typescript/module/src/debug.d.ts +2 -0
  39. package/lib/typescript/module/src/debug.d.ts.map +1 -0
  40. package/lib/typescript/module/src/index.d.ts +1 -0
  41. package/lib/typescript/module/src/index.d.ts.map +1 -1
  42. package/package.json +30 -15
  43. package/src/NativeSdkPianoio.ts +20 -22
  44. package/src/PianoComposer.tsx +36 -116
  45. package/src/debug.ts +19 -0
  46. package/src/index.tsx +1 -0
  47. package/ios/ComposerPiano.swift +0 -304
  48. package/ios/SdkPianoio.h +0 -4
  49. package/ios/SdkPianoio.mm +0 -283
  50. package/ios/services/ComposerService.swift +0 -49
@@ -1,28 +1,26 @@
1
- import { NativeModules } from 'react-native';
1
+ import { NativeModules, Platform } from 'react-native';
2
2
 
3
3
  interface SdkPianoioType {
4
- initializeComposer(aid: string): Promise<any>;
4
+ initializeComposer(aid: string): Promise<boolean>;
5
+ executeExperience(): Promise<any>;
5
6
  getComposer(): Promise<any>;
6
- addComposerTag(tag: string): Promise<any>;
7
- addComposerTags(tags: string[]): Promise<any>;
8
- setComposerZoneId(zoneId: string): Promise<any>;
9
- setComposerReferrer(referrer: string): Promise<any>;
10
- setComposerUrl(url: string): Promise<any>;
11
- setComposerCustomVariable(name: string, value: string): Promise<any>;
12
- setComposerUserToken(token: string): Promise<any>;
13
- executeComposer(): Promise<void>;
14
7
 
15
- experienceExecute(): Promise<boolean>;
16
- showLogin(): Promise<boolean>;
17
- showTemplate(): Promise<boolean>;
18
- showForm(): Promise<boolean>;
19
- showRecommendations(): Promise<boolean>;
20
- nonSite(): Promise<boolean>;
21
- userSegmentTrue(): Promise<boolean>;
22
- userSegmentFalse(): Promise<boolean>;
23
- meterActive(): Promise<boolean>;
24
- meterExpired(): Promise<boolean>;
25
- composerExecutionCompleted(): Promise<boolean>;
8
+ addComposerTag(tag: string): Promise<void>;
9
+ addComposerTags(tags: string[]): Promise<void>;
10
+ setComposerZoneId(zoneId: string): Promise<void>;
11
+ setComposerReferrer(referrer: string): Promise<void>;
12
+ setComposerUrl(url: string): Promise<void>;
13
+ setComposerCustomVariable(name: string, value: string): Promise<void>;
14
+ setComposerUserToken(token: string): Promise<void>;
26
15
  }
27
16
 
28
- export default NativeModules.SdkPianoio as SdkPianoioType;
17
+ const SdkPianoio = NativeModules.SdkPianoio;
18
+
19
+ if (!SdkPianoio) {
20
+ throw new Error(
21
+ `react-native-sdk-pianoio: Native module 'SdkPianoio' is not available on ${Platform.OS}. ` +
22
+ 'Make sure you have properly linked the library and rebuilt your app.'
23
+ );
24
+ }
25
+
26
+ export default SdkPianoio as SdkPianoioType;
@@ -1,158 +1,80 @@
1
1
  import SdkPianoio from './NativeSdkPianoio';
2
2
 
3
3
  class PianoComposer {
4
- aid: string;
5
- tags: string[] = [];
6
- zoneId: string | null = null;
7
- referrer: string | null = null;
8
- customVariables: { [key: string]: string } = {};
9
- userToken: string | null = null;
10
- url: string | null = null;
11
-
4
+ // --- Properties to hold configuration state ---
5
+ private aid: string;
6
+ private tags: string[] = [];
7
+ private zoneId: string | null = null;
8
+ private referrer: string | null = null;
9
+ private customVariables: { [key: string]: string } = {};
10
+ private userToken: string | null = null;
11
+ private url: string | null = null;
12
+
13
+ // The constructor is private to force users to use the async `create` method.
12
14
  private constructor(aid: string) {
13
15
  this.aid = aid;
14
16
  }
15
17
 
18
+ /**
19
+ * Creates and initializes a new PianoComposer instance.
20
+ * This is the entry point for using the library.
21
+ * @param aid Your Application ID from Piano.io
22
+ */
16
23
  static async create(aid: string): Promise<PianoComposer> {
17
24
  await SdkPianoio.initializeComposer(aid);
18
25
  return new PianoComposer(aid);
19
26
  }
20
27
 
28
+ // --- Configuration Methods ---
29
+
21
30
  async addTag(tag: string) {
22
- this.tags.push(tag);
31
+ this.tags.push(tag); // Store state locally
23
32
  return SdkPianoio.addComposerTag(tag);
24
33
  }
25
34
 
26
35
  async addTags(tags: string[]) {
27
- this.tags.push(...tags);
36
+ this.tags.push(...tags); // Store state locally
28
37
  return SdkPianoio.addComposerTags(tags);
29
38
  }
30
39
 
31
40
  async setZoneId(zoneId: string) {
32
- this.zoneId = zoneId;
41
+ this.zoneId = zoneId; // Store state locally
33
42
  return SdkPianoio.setComposerZoneId(zoneId);
34
43
  }
35
44
 
36
45
  async setReferrer(referrer: string) {
37
- this.referrer = referrer;
46
+ this.referrer = referrer; // Store state locally
38
47
  return SdkPianoio.setComposerReferrer(referrer);
39
48
  }
40
49
 
41
50
  async setCustomVariable(name: string, value: string) {
42
- this.customVariables[name] = value;
43
-
51
+ this.customVariables[name] = value; // Store state locally
44
52
  return SdkPianoio.setComposerCustomVariable(name, value);
45
53
  }
46
54
 
47
55
  async setUserToken(token: string) {
48
- this.userToken = token;
56
+ this.userToken = token; // Store state locally
49
57
  return SdkPianoio.setComposerUserToken(token);
50
58
  }
51
59
 
52
60
  async setUrl(url: string) {
53
- this.url = url;
61
+ this.url = url; // Store state locally
54
62
  return SdkPianoio.setComposerUrl(url);
55
63
  }
56
64
 
57
- async execute() {
58
- return SdkPianoio.executeComposer();
59
- }
60
-
61
- async experienceExecute() {
62
- try {
63
- let r = await SdkPianoio.experienceExecute();
64
- console.log('experienceExecute triggered');
65
- console.log('Experience executed:', r);
66
- } catch (e) {
67
- console.error('Errore nel experienceExecute:', e);
68
- }
69
- }
70
-
71
- async composerExecutionCompleted() {
72
- try {
73
- let r = await SdkPianoio.composerExecutionCompleted();
74
- console.log('composerExecutionCompleted triggered');
75
- console.log('Composer execution completed:', r);
76
- } catch (e) {
77
- console.error('Errore nel composerExecutionCompleted:', e);
78
- }
79
- }
80
-
81
- async showForm() {
82
- return SdkPianoio.showForm();
83
- }
84
-
85
- async showLogin() {
86
- try {
87
- await SdkPianoio.showLogin();
88
- console.log('Login triggered');
89
- } catch (e) {
90
- console.error('Errore nel login:', e);
91
- }
92
- }
93
-
94
- async showTemplate() {
95
- try {
96
- await SdkPianoio.showTemplate();
97
- console.log('Template triggered');
98
- } catch (e) {
99
- console.error('Errore nel Template:', e);
100
- }
101
- }
102
-
103
- async showRecommendations() {
104
- try {
105
- await SdkPianoio.showRecommendations();
106
- console.log('showRecommendations triggered');
107
- } catch (e) {
108
- console.error('Errore nel Template:', e);
109
- }
110
- }
65
+ // --- Core Execution Method ---
111
66
 
112
- async nonSite() {
113
- try {
114
- await SdkPianoio.nonSite();
115
- console.log('nonSite triggered');
116
- } catch (e) {
117
- console.error('Errore nel Template:', e);
118
- }
67
+ /**
68
+ * Executes the Piano experience with the current configuration.
69
+ * This is the primary method to get a decision from the Piano backend.
70
+ * @returns A promise that resolves with the event data object from the native SDK.
71
+ */
72
+ async executeExperience() {
73
+ // This now correctly calls the native method AND returns the result.
74
+ return SdkPianoio.executeExperience();
119
75
  }
120
76
 
121
- async userSegmentTrue() {
122
- try {
123
- await SdkPianoio.userSegmentTrue();
124
- console.log('userSegmentTrue triggered');
125
- } catch (e) {
126
- console.error('Errore nel userSegmentTrue:', e);
127
- }
128
- }
129
-
130
- async userSegmentFalse() {
131
- try {
132
- await SdkPianoio.userSegmentFalse();
133
- console.log('userSegmentFalse triggered');
134
- } catch (e) {
135
- console.error('Errore nel userSegmentFalse:', e);
136
- }
137
- }
138
-
139
- async meterActive() {
140
- try {
141
- await SdkPianoio.meterActive();
142
- console.log('Template meterActive');
143
- } catch (e) {
144
- console.error('Errore nel meterActive:', e);
145
- }
146
- }
147
-
148
- async meterExpired() {
149
- try {
150
- await SdkPianoio.meterExpired();
151
- console.log('meterExpired triggered');
152
- } catch (e) {
153
- console.error('Errore nel meterExpired:', e);
154
- }
155
- }
77
+ // --- Static Helper Methods ---
156
78
 
157
79
  static async isInitialized(): Promise<boolean> {
158
80
  try {
@@ -164,15 +86,13 @@ class PianoComposer {
164
86
  }
165
87
 
166
88
  static async getComposerFromSdkIOS() {
167
- const result = await SdkPianoio.getComposer();
168
-
169
- return result;
89
+ return SdkPianoio.getComposer();
170
90
  }
171
91
 
172
92
  async toString() {
173
93
  return `PianoComposer {
174
94
  aid: ${this.aid},
175
- tags: ${this.tags},
95
+ tags: ${this.tags.join(',')},
176
96
  zoneId: ${this.zoneId},
177
97
  referrer: ${this.referrer},
178
98
  customVariables: ${JSON.stringify(this.customVariables)},
package/src/debug.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ export const debugNativeModule = () => {
4
+ console.log('🔍 Debugging Native Module...');
5
+ console.log('Platform:', Platform.OS);
6
+ console.log('Available Native Modules:', Object.keys(NativeModules));
7
+
8
+ const SdkPianoio = NativeModules.SdkPianoio;
9
+ console.log('SdkPianoio module:', SdkPianoio);
10
+
11
+ if (SdkPianoio) {
12
+ console.log('✅ SdkPianoio module found!');
13
+ console.log('Available methods:', Object.keys(SdkPianoio));
14
+ } else {
15
+ console.log('❌ SdkPianoio module NOT found!');
16
+ }
17
+
18
+ return SdkPianoio;
19
+ };
package/src/index.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  // import SdkPianoio from './NativeSdkPianoio';
2
2
  export { default as PianoComposer } from './PianoComposer';
3
+ export { debugNativeModule } from './debug';
3
4
 
4
5
  // export const {
5
6
  // initializeComposer,
@@ -1,304 +0,0 @@
1
- //
2
- // ComposerPiano.swift
3
- // SdkPianoio
4
- //
5
- //
6
- import Foundation
7
- import PianoComposer
8
- import PianoOAuth
9
- import PianoConsents
10
- import PianoTemplate
11
- import React
12
-
13
- import SwiftUI
14
-
15
-
16
- @objcMembers public class ComposerPianoImpl: NSObject {
17
- private var composer: PianoComposer?;
18
- private var delegateHelper : MyComposerDelegate?;
19
- public static var aid = "";
20
-
21
- @objc public func initializeComposer(_ aid: String) -> PianoComposer? {
22
- ComposerPianoImpl.aid = aid;
23
- let tokenService = TokenService();
24
- delegateHelper = MyComposerDelegate(tokenService: tokenService);
25
- composer = PianoComposer(aid: ComposerPianoImpl.aid, endpoint: PianoEndpoint.productionEurope);
26
- composer = delegateHelper?.setComposerAndDelegate(composer!);
27
- return composer;
28
- }
29
-
30
- @objc public func addTag(_ tag: String) -> PianoComposer? {
31
- return composer?.tag(tag);
32
- }
33
- @objc public func addTagToComposer(_ composer: PianoComposer, tag: String) {
34
- composer.tag(tag);
35
- }
36
-
37
- @objc public func addTags(_ tags: [String]) -> PianoComposer? {
38
- return composer?.tags(tags);
39
- }
40
-
41
- @objc public func setZoneId(_ zoneId: String) -> PianoComposer? {
42
- return composer?.zoneId(zoneId);
43
- }
44
-
45
- @objc public func setReferrer(_ referrer: String) -> PianoComposer? {
46
- return composer?.referrer(referrer);
47
- }
48
-
49
- @objc public func setUrl(_ url: String) -> PianoComposer? {
50
- return composer?.url(url);
51
- }
52
-
53
- @objc public func setCustomVariable(_ name: String, value: String) -> PianoComposer? {
54
- return composer?.customVariable(name: name, value: value);
55
- }
56
-
57
- @objc public func setUserToken(_ token: String) -> PianoComposer? {
58
- return composer?.userToken(token);
59
- }
60
-
61
- @objc public func executeComposer() {
62
- print("Esecuzione composer")
63
- DispatchQueue.main.async( group: nil, qos: .unspecified, flags: [], execute: {
64
- guard let rootVC = UIApplication.shared.connectedScenes
65
- .compactMap({ $0 as? UIWindowScene })
66
- .first(where: { $0.activationState == .foregroundActive })?.windows
67
- .first(where: { $0.isKeyWindow })?.rootViewController else {
68
-
69
- return
70
- }
71
- if let composer = self.composer {
72
- print("Va nell'esecuzione yaay")
73
-
74
- composer.execute()
75
- } else {
76
- print("⚠️ Composer è nil")
77
- }
78
- })
79
- }
80
-
81
- // Delegate handler
82
- @objc public func executeExperience(_ completion: @escaping (NSNumber) -> Void) {
83
- let eventDict: [String: Any] = [
84
- "eventType": "login"
85
- ]
86
- let xpEvent = XpEvent(dict: eventDict)
87
-
88
- guard let composer = composer, let _ = composer.delegate else {
89
- completion(NSNumber(value: false))
90
- return
91
- }
92
-
93
- delegateHelper?.executeExperience(composer: composer, event: xpEvent, params: nil)
94
- }
95
-
96
- @objc public func composerExecutionCompleted() {
97
- let eventDict: [String: Any] = [
98
- "eventType": "login"
99
- ]
100
- let xpEvent = XpEvent(dict: eventDict)
101
-
102
- if(composer != nil && composer!.delegate != nil ) {
103
- delegateHelper?.composerExecutionCompleted(composer: composer!);
104
- }
105
- }
106
-
107
- @objc public func showLogin() {
108
- let eventDict: [String: Any] = [
109
- "eventType": "login"
110
- ];
111
-
112
- let xpEvent = XpEvent(dict: eventDict);
113
-
114
- if(composer != nil && composer!.delegate != nil ) {
115
- delegateHelper?.myShowLogin(composer: composer!, event: xpEvent, params: nil);
116
- }
117
- }
118
-
119
- @objc public func showTemplate() {
120
- DispatchQueue.main.async {
121
- guard let rootVC = UIApplication.shared
122
- .connectedScenes
123
- .compactMap({ $0 as? UIWindowScene })
124
- .flatMap({ $0.windows })
125
- .first(where: { $0.isKeyWindow })?
126
- .rootViewController else {
127
- print("⚠️ rootViewController non trovato")
128
- return
129
- }
130
-
131
- let tokenService = self.delegateHelper!.tokenService
132
- let view = ShowTemplateView(tokenService: tokenService)
133
- let hostingController = UIHostingController(rootView: view)
134
- hostingController.modalPresentationStyle = .fullScreen
135
-
136
- rootVC.present(hostingController, animated: true, completion: nil)
137
- }
138
- }
139
-
140
- @objc public func showForm() {
141
- let eventDict: [String: Any] = [
142
- "eventType": "form"
143
- ];
144
-
145
- let xpEvent = XpEvent(dict: eventDict);
146
-
147
- if(composer != nil && composer!.delegate != nil ) {
148
- delegateHelper?.myShowForm(composer: composer!, event: xpEvent, params: nil);
149
- }
150
- }
151
-
152
- @objc public func showRecommendations() {
153
- let eventDict: [String: Any] = [
154
- "eventType": "recommendations"
155
- ];
156
-
157
- let xpEvent = XpEvent(dict: eventDict);
158
-
159
- if(composer != nil && composer!.delegate != nil ) {
160
- delegateHelper?.showRecommendations(composer: composer!, event: xpEvent, params: nil)
161
- }
162
- }
163
-
164
- @objc public func nonSite() {
165
- let eventDict: [String: Any] = [
166
- "eventType": "nonSite"
167
- ]
168
-
169
- let xpEvent = XpEvent(dict: eventDict)
170
-
171
- if(composer != nil && composer!.delegate != nil ) {
172
- delegateHelper?.nonSite(composer: composer!, event: xpEvent)
173
- }
174
- }
175
-
176
- @objc public func userSegmentTrue() {
177
- let eventDict: [String: Any] = [
178
- "eventType": "userSegmentTrue"
179
- ]
180
-
181
- let xpEvent = XpEvent(dict: eventDict)
182
-
183
- if(composer != nil && composer!.delegate != nil ) {
184
- delegateHelper?.userSegmentTrue(composer: composer!, event: xpEvent)
185
- }
186
- }
187
-
188
- @objc public func userSegmentFalse() {
189
- let eventDict: [String: Any] = [
190
- "eventType": "userSegmentFalse"
191
- ]
192
-
193
- let xpEvent = XpEvent(dict: eventDict)
194
-
195
- if(composer != nil && composer!.delegate != nil ) {
196
- delegateHelper?.userSegmentFalse(composer: composer!, event: xpEvent)
197
- }
198
- }
199
-
200
- @objc public func meterActive() {
201
- let eventDict: [String: Any] = [
202
- "eventType": "meterActive"
203
- ]
204
-
205
- let xpEvent = XpEvent(dict: eventDict)
206
-
207
- if(composer != nil && composer!.delegate != nil ) {
208
- delegateHelper?.meterActive(composer: composer!, event: xpEvent, params: nil)
209
- }
210
- }
211
-
212
- @objc public func meterExpired() {
213
- let eventDict: [String: Any] = [
214
- "eventType": "meterExpired"
215
- ]
216
-
217
- let xpEvent = XpEvent(dict: eventDict)
218
-
219
- if(composer != nil && composer!.delegate != nil ) {
220
- delegateHelper?.meterExpired(composer: composer!, event: xpEvent, params: nil)
221
- }
222
- }
223
-
224
- @objc public func experienceExecute() {
225
- let eventDict: [String: Any] = [
226
- "eventType": "experienceExecute"
227
- ]
228
-
229
- let xpEvent = XpEvent(dict: eventDict)
230
-
231
- if(composer != nil && composer!.delegate != nil ) {
232
- delegateHelper?.experienceExecute(composer: composer!, event: xpEvent, params: nil)
233
- }
234
- }
235
-
236
-
237
-
238
- public func findViewBySelector(selector: String) -> UIView? {
239
- return nil;
240
- }
241
-
242
-
243
- // method to get values and helpers
244
- @objc public func getAid() -> String {
245
- if(composer != nil){
246
- return composer?.aid ?? "";
247
- } else {
248
- return "";
249
- }
250
- }
251
-
252
- @objc public func getTags() -> [String] {
253
- if let tags = composer?.tags, !tags.isEmpty {
254
- return Array(tags) // Restituisce l'array dei tag se presenti e non vuoti
255
- } else {
256
- return [] // Restituisce un array vuoto se non ci sono tag
257
- }
258
- }
259
-
260
- @objc public func getComposer() -> PianoComposer? {
261
- return composer;
262
- }
263
-
264
- @objc public func getZoneId() -> String {
265
- return composer?.zoneId ?? ""
266
- }
267
-
268
- @objc public func getReferrer() -> String {
269
- return composer?.referrer ?? ""
270
- }
271
-
272
- @objc public func getUrl() -> String {
273
- return composer?.url ?? ""
274
- }
275
-
276
- @objc public func getUserToken() -> String {
277
- return composer?.userToken ?? ""
278
- }
279
-
280
- @objc public func addTagsToComposer(_ composer: PianoComposer, tags: [String]) {
281
- composer.tags(tags)
282
- }
283
-
284
- @objc public func setCustomVariable(_ composer: PianoComposer, name: String, value: String) {
285
- composer.customVariable(name: name, value: value)
286
- }
287
-
288
- @objc public func setReferrer(_ composer: PianoComposer, referrer: String) {
289
- composer.referrer(referrer)
290
- }
291
-
292
- @objc public func setUrl(_ composer: PianoComposer, url: String) {
293
- composer.url(url)
294
- }
295
-
296
- @objc public func setUserToken(_ composer: PianoComposer, token: String) {
297
- composer.userToken(token)
298
- }
299
-
300
- @objc public func setZoneId(_ composer: PianoComposer, zoneId: String) {
301
- composer.zoneId(zoneId)
302
- }
303
-
304
- }
package/ios/SdkPianoio.h DELETED
@@ -1,4 +0,0 @@
1
- #import <React/RCTBridgeModule.h>
2
-
3
- @interface SdkPianoio : NSObject <RCTBridgeModule>
4
- @end