react-native-sdk-pianoio 0.3.1 → 0.3.4

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 (37) hide show
  1. package/README.md +176 -186
  2. package/android/build.gradle +29 -42
  3. package/android/gradle.properties +33 -14
  4. package/android/src/main/java/com/sdkpianoio/ComposerPianoImpl.kt +366 -0
  5. package/android/src/main/java/com/sdkpianoio/SdkPianoioModule.kt +281 -507
  6. package/android/src/main/java/com/sdkpianoio/TokenService.kt +139 -0
  7. package/android/test.sh +494 -0
  8. package/ios/ComposerPianoImpl.swift +128 -225
  9. package/ios/MyComposerDelegate.swift +142 -109
  10. package/ios/SdkPianoio.swift +69 -143
  11. package/ios/SdkPianoioBridge.m +18 -46
  12. package/ios/TokenService.swift +219 -0
  13. package/lib/commonjs/NativeSdkPianoio.ts +35 -22
  14. package/lib/commonjs/PianoComposer.js +89 -132
  15. package/lib/commonjs/PianoComposer.js.map +1 -1
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/module/NativeSdkPianoio.ts +35 -22
  18. package/lib/module/PianoComposer.js +90 -132
  19. package/lib/module/PianoComposer.js.map +1 -1
  20. package/lib/module/index.js +0 -14
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/typescript/commonjs/src/NativeSdkPianoio.d.ts +28 -21
  23. package/lib/typescript/commonjs/src/NativeSdkPianoio.d.ts.map +1 -1
  24. package/lib/typescript/commonjs/src/PianoComposer.d.ts +55 -31
  25. package/lib/typescript/commonjs/src/PianoComposer.d.ts.map +1 -1
  26. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  27. package/lib/typescript/module/src/NativeSdkPianoio.d.ts +28 -21
  28. package/lib/typescript/module/src/NativeSdkPianoio.d.ts.map +1 -1
  29. package/lib/typescript/module/src/PianoComposer.d.ts +55 -31
  30. package/lib/typescript/module/src/PianoComposer.d.ts.map +1 -1
  31. package/lib/typescript/module/src/index.d.ts.map +1 -1
  32. package/package.json +5 -2
  33. package/src/NativeSdkPianoio.ts +35 -22
  34. package/src/PianoComposer.tsx +78 -141
  35. package/src/index.tsx +0 -14
  36. package/android/src/main/AndroidManifestNew.xml +0 -2
  37. package/ios/services/TokenService.swift +0 -70
@@ -1,184 +1,121 @@
1
1
  import SdkPianoio from './NativeSdkPianoio';
2
2
 
3
+ /**
4
+ * A wrapper class for the native SdkPianoio module that provides a clean,
5
+ * object-oriented API for interacting with the Piano SDK.
6
+ */
3
7
  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
-
12
- private constructor(aid: string) {
13
- this.aid = aid;
8
+ // The constructor is private to force users to use the async `create` method.
9
+ private constructor() {
10
+ // This constructor is intentionally empty.
14
11
  }
15
12
 
13
+ /**
14
+ * Creates and initializes a new PianoComposer instance.
15
+ * This is the main entry point for using the library.
16
+ * @param aid Your Application ID from Piano.io
17
+ */
16
18
  static async create(aid: string): Promise<PianoComposer> {
17
- await SdkPianoio.initializeComposer(aid);
18
- return new PianoComposer(aid);
19
+ // Call the corrected native initialize method
20
+ await SdkPianoio.initialize(aid);
21
+ return new PianoComposer();
19
22
  }
20
23
 
21
- async addTag(tag: string) {
22
- this.tags.push(tag);
23
- return SdkPianoio.addComposerTag(tag);
24
- }
24
+ // --- Configuration Methods ---
25
25
 
26
- async addTags(tags: string[]) {
27
- this.tags.push(...tags);
28
- return SdkPianoio.addComposerTags(tags);
26
+ async addTag(tag: string): Promise<boolean> {
27
+ return SdkPianoio.addTag(tag);
29
28
  }
30
29
 
31
- async setZoneId(zoneId: string) {
32
- this.zoneId = zoneId;
33
- return SdkPianoio.setComposerZoneId(zoneId);
30
+ async addTags(tags: string[]): Promise<boolean> {
31
+ return SdkPianoio.addTags(tags);
34
32
  }
35
33
 
36
- async setReferrer(referrer: string) {
37
- this.referrer = referrer;
38
- return SdkPianoio.setComposerReferrer(referrer);
34
+ async setZoneId(zoneId: string): Promise<boolean> {
35
+ return SdkPianoio.setZoneId(zoneId);
39
36
  }
40
37
 
41
- async setCustomVariable(name: string, value: string) {
42
- this.customVariables[name] = value;
43
-
44
- return SdkPianoio.setComposerCustomVariable(name, value);
38
+ async setReferrer(referrer: string): Promise<boolean> {
39
+ return SdkPianoio.setReferrer(referrer);
45
40
  }
46
41
 
47
- async setUserToken(token: string) {
48
- this.userToken = token;
49
- return SdkPianoio.setComposerUserToken(token);
42
+ async setCustomVariable(name: string, value: string): Promise<boolean> {
43
+ return SdkPianoio.addCustomVariable(name, value);
50
44
  }
51
45
 
52
- async setUrl(url: string) {
53
- this.url = url;
54
- return SdkPianoio.setComposerUrl(url);
46
+ async setCustomVariables(variables: { [key: string]: string }): Promise<boolean> {
47
+ return SdkPianoio.setCustomVariables(variables);
55
48
  }
56
49
 
57
- async execute() {
58
- return SdkPianoio.executeComposer();
50
+ async setUserToken(token: string): Promise<boolean> {
51
+ return SdkPianoio.setUserToken(token);
59
52
  }
60
53
 
61
- async executeExperience() {
62
- try {
63
- let r = await SdkPianoio.executeExperience();
64
- console.log('executeExperience triggered');
65
- console.log('Experience executed:', r);
66
- } catch (e) {
67
- console.error('Errore nel executeExperience:', e);
68
- }
54
+ async setUrl(url: string): Promise<boolean> {
55
+ return SdkPianoio.setUrl(url);
69
56
  }
70
57
 
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
- }
58
+ // --- Authentication Methods ---
80
59
 
81
- async showForm() {
82
- return SdkPianoio.showForm();
60
+ /**
61
+ * Signs in the user with Piano.
62
+ * @returns A promise that resolves with user information.
63
+ */
64
+ async signIn(): Promise<any> {
65
+ return SdkPianoio.signIn();
83
66
  }
84
67
 
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
- }
68
+ /**
69
+ * Signs out the current user.
70
+ * @returns A promise that resolves when sign out is complete.
71
+ */
72
+ async signOut(): Promise<any> {
73
+ return SdkPianoio.signOut();
92
74
  }
93
75
 
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
- }
76
+ /**
77
+ * Gets information about the current authenticated user.
78
+ * @returns A promise that resolves with user information.
79
+ */
80
+ async getCurrentUser(): Promise<any> {
81
+ return SdkPianoio.getCurrentUser();
101
82
  }
102
83
 
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
- }
84
+ /**
85
+ * Checks if a user is currently authenticated.
86
+ * @returns A promise that resolves with the authentication status.
87
+ */
88
+ async isAuthenticated(): Promise<any> {
89
+ return SdkPianoio.isAuthenticated();
110
90
  }
111
91
 
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
- }
119
- }
92
+ // --- Core Execution Method ---
120
93
 
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
- }
94
+ /**
95
+ * Executes the Piano experience with the current configuration.
96
+ * This is the primary method to get a decision from the Piano backend.
97
+ * @returns A promise that resolves with the event data object from the native SDK.
98
+ */
99
+ async executeExperience(): Promise<any> {
100
+ return SdkPianoio.executeExperience();
128
101
  }
129
102
 
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
- }
103
+ // --- Utility and Cleanup Methods ---
138
104
 
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
- }
105
+ /**
106
+ * Gets the current status of the SDK.
107
+ * @returns A promise that resolves with status information.
108
+ */
109
+ async getStatus(): Promise<any> {
110
+ return SdkPianoio.getStatus();
146
111
  }
147
112
 
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
- }
156
-
157
- static async isInitialized(): Promise<boolean> {
158
- try {
159
- const result = await SdkPianoio.getComposer();
160
- return result !== null;
161
- } catch (e) {
162
- return false;
163
- }
164
- }
165
-
166
- static async getComposerFromSdkIOS() {
167
- const result = await SdkPianoio.getComposer();
168
-
169
- return result;
170
- }
171
-
172
- async toString() {
173
- return `PianoComposer {
174
- aid: ${this.aid},
175
- tags: ${this.tags},
176
- zoneId: ${this.zoneId},
177
- referrer: ${this.referrer},
178
- customVariables: ${JSON.stringify(this.customVariables)},
179
- userToken: ${this.userToken},
180
- url: ${this.url}
181
- }`;
113
+ /**
114
+ * Clears all configured tags and custom variables.
115
+ * @returns A promise that resolves when the configuration is cleared.
116
+ */
117
+ async clearConfiguration(): Promise<boolean> {
118
+ return SdkPianoio.clearConfiguration();
182
119
  }
183
120
  }
184
121
 
package/src/index.tsx CHANGED
@@ -1,16 +1,2 @@
1
- // import SdkPianoio from './NativeSdkPianoio';
2
1
  export { default as PianoComposer } from './PianoComposer';
3
2
  export { debugNativeModule } from './debug';
4
-
5
- // export const {
6
- // initializeComposer,
7
- // getComposer,
8
- // addComposerTag,
9
- // addComposerTags,
10
- // setComposerZoneId,
11
- // setComposerReferrer,
12
- // setComposerUrl,
13
- // setComposerCustomVariable,
14
- // setComposerUserToken,
15
- // executeComposer
16
- // } = SdkPianoio;
@@ -1,2 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
@@ -1,70 +0,0 @@
1
- //
2
- // TokenService.swift
3
- // Pods
4
- //
5
- // Created by Alessia Sarak on 24.04.2025.
6
- //
7
-
8
- import PianoOAuth
9
-
10
- public class TokenService: NSObject, PianoIDDelegate {
11
-
12
- @Published private(set) var initialized = false
13
- @Published private(set) var token: PianoIDToken?
14
-
15
- public override init() {
16
- /// Set Piano ID settings
17
- PianoID.shared.endpoint = PianoEndpoint.sandbox
18
- PianoID.shared.aid = ComposerPianoImpl.aid
19
-
20
- super.init()
21
-
22
- PianoID.shared.delegate = self
23
-
24
- token = PianoID.shared.currentToken
25
- request { [weak self] _ in
26
- DispatchQueue.main.async {
27
- self?.initialized = true
28
- }
29
- }
30
- }
31
-
32
- func request(completion: @escaping (PianoIDToken?) -> Void) {
33
- if let t = token {
34
- if t.isExpired {
35
- /// Refresh token if expired
36
- PianoID.shared.refreshToken(t.refreshToken) { token, error in
37
- if let t = token {
38
- self.token = t
39
- completion(t)
40
- return
41
- }
42
- completion(nil)
43
- }
44
- } else {
45
- completion(t)
46
- }
47
- return
48
- }
49
-
50
- completion(nil)
51
- }
52
-
53
- /// Sign In callback
54
- public func signIn(result: PianoIDSignInResult!, withError error: Error!) {
55
- if let r = result {
56
- token = r.token
57
- } else {
58
-
59
- }
60
- }
61
-
62
- /// Sign Out callback
63
- public func signOut(withError error: Error!) {
64
- token = nil
65
- }
66
-
67
- /// Cancel callback
68
- public func cancel() {
69
- }
70
- }