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.
- package/README.md +176 -186
- package/android/build.gradle +29 -42
- package/android/gradle.properties +33 -14
- package/android/src/main/java/com/sdkpianoio/ComposerPianoImpl.kt +366 -0
- package/android/src/main/java/com/sdkpianoio/SdkPianoioModule.kt +281 -507
- package/android/src/main/java/com/sdkpianoio/TokenService.kt +139 -0
- package/android/test.sh +494 -0
- package/ios/ComposerPianoImpl.swift +128 -225
- package/ios/MyComposerDelegate.swift +142 -109
- package/ios/SdkPianoio.swift +69 -143
- package/ios/SdkPianoioBridge.m +18 -46
- package/ios/TokenService.swift +219 -0
- package/lib/commonjs/NativeSdkPianoio.ts +35 -22
- package/lib/commonjs/PianoComposer.js +89 -132
- package/lib/commonjs/PianoComposer.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeSdkPianoio.ts +35 -22
- package/lib/module/PianoComposer.js +90 -132
- package/lib/module/PianoComposer.js.map +1 -1
- package/lib/module/index.js +0 -14
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/NativeSdkPianoio.d.ts +28 -21
- package/lib/typescript/commonjs/src/NativeSdkPianoio.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/PianoComposer.d.ts +55 -31
- package/lib/typescript/commonjs/src/PianoComposer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeSdkPianoio.d.ts +28 -21
- package/lib/typescript/module/src/NativeSdkPianoio.d.ts.map +1 -1
- package/lib/typescript/module/src/PianoComposer.d.ts +55 -31
- package/lib/typescript/module/src/PianoComposer.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/NativeSdkPianoio.ts +35 -22
- package/src/PianoComposer.tsx +78 -141
- package/src/index.tsx +0 -14
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/ios/services/TokenService.swift +0 -70
package/src/PianoComposer.tsx
CHANGED
@@ -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
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
18
|
-
|
19
|
+
// Call the corrected native initialize method
|
20
|
+
await SdkPianoio.initialize(aid);
|
21
|
+
return new PianoComposer();
|
19
22
|
}
|
20
23
|
|
21
|
-
|
22
|
-
this.tags.push(tag);
|
23
|
-
return SdkPianoio.addComposerTag(tag);
|
24
|
-
}
|
24
|
+
// --- Configuration Methods ---
|
25
25
|
|
26
|
-
async
|
27
|
-
|
28
|
-
return SdkPianoio.addComposerTags(tags);
|
26
|
+
async addTag(tag: string): Promise<boolean> {
|
27
|
+
return SdkPianoio.addTag(tag);
|
29
28
|
}
|
30
29
|
|
31
|
-
async
|
32
|
-
|
33
|
-
return SdkPianoio.setComposerZoneId(zoneId);
|
30
|
+
async addTags(tags: string[]): Promise<boolean> {
|
31
|
+
return SdkPianoio.addTags(tags);
|
34
32
|
}
|
35
33
|
|
36
|
-
async
|
37
|
-
|
38
|
-
return SdkPianoio.setComposerReferrer(referrer);
|
34
|
+
async setZoneId(zoneId: string): Promise<boolean> {
|
35
|
+
return SdkPianoio.setZoneId(zoneId);
|
39
36
|
}
|
40
37
|
|
41
|
-
async
|
42
|
-
|
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
|
48
|
-
|
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
|
53
|
-
|
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
|
58
|
-
return SdkPianoio.
|
50
|
+
async setUserToken(token: string): Promise<boolean> {
|
51
|
+
return SdkPianoio.setUserToken(token);
|
59
52
|
}
|
60
53
|
|
61
|
-
async
|
62
|
-
|
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
|
-
|
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
|
-
|
82
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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,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
|
-
}
|