react-native-sdk-pianoio 0.3.2 → 0.3.5

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 +111 -212
  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 +34 -10
  14. package/lib/commonjs/PianoComposer.js +69 -51
  15. package/lib/commonjs/PianoComposer.js.map +1 -1
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/module/NativeSdkPianoio.ts +34 -10
  18. package/lib/module/PianoComposer.js +70 -51
  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 +27 -9
  23. package/lib/typescript/commonjs/src/NativeSdkPianoio.d.ts.map +1 -1
  24. package/lib/typescript/commonjs/src/PianoComposer.d.ts +45 -18
  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 +27 -9
  28. package/lib/typescript/module/src/NativeSdkPianoio.d.ts.map +1 -1
  29. package/lib/typescript/module/src/PianoComposer.d.ts +45 -18
  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 +4 -1
  33. package/src/NativeSdkPianoio.ts +34 -10
  34. package/src/PianoComposer.tsx +76 -59
  35. package/src/index.tsx +0 -14
  36. package/android/src/main/AndroidManifestNew.xml +0 -2
  37. package/ios/services/TokenService.swift +0 -70
package/README.md CHANGED
@@ -1,274 +1,173 @@
1
- # react-native-sdk-pianoio
1
+ # React Native SDK for Piano.io
2
2
 
3
- Lo scopo di questo pacchetto npm è quello di avere la possibilità di interagire con i metodi messi a disposizione dalle SDK di Piano sia di iOS che di Android, così da avere un unico pacchetto da installare nel momento in cui si vuole utilizzare Piano.io.
3
+ A React Native SDK for integrating Piano.io's digital monetization platform into your mobile applications. This SDK provides seamless, cross-platform integration with Piano's paywall, subscription, and content monetization features.
4
4
 
5
- Il tutto deve essere compatibile con la version **Expo SDK51** ed è su questa versione che sono stati effettuati i test.
5
+ ## Features
6
6
 
7
- Il progetto è ancora in **work in progress**.
7
+ - **Full Piano Composer Integration**: Execute experiences, manage content access, and handle paywalls
8
+ - **Piano ID Authentication**: Complete user authentication and token management for both platforms
9
+ - **Cross-Platform Parity**: A single, unified API for both iOS and Android
10
+ - **Flexible Configuration**: Manage tags, zone IDs, custom variables, user tokens, and more
8
11
 
9
- ## Indice
12
+ ## 📦 Installation
10
13
 
11
- - [Installazione](#installazione)
12
- - [Prerequisiti](#prerequisiti)
13
- - [iOS](#ios)
14
- - [Android](#android)
15
- - [Avviare progetto](#avviare-progetto)
16
- - [Utilizzo](#utilizzo)
17
- - [Importazione](#importazione)
18
- - [Creazione del Composer](#creazione-del-composer)
19
- - [Metodi del Composer](#metodi-del-composer)
20
- - [Metodi statici](#metodi-statici)
21
- - [Esempio completo](#esempio-completo)
22
- <!-- - [Contributing](#contributing)
23
- - [License](#license) -->
24
-
25
- ## Installazione
26
-
27
- ### Prerequisiti
28
-
29
- Seguendo la guida presente al link https://docs.expo.dev/get-started/create-a-project/ è possibile effettuare la creazione di un progetto in expo.
30
-
31
- Una volta effettuato questo è possibile installare questo pacchetto all'interno del progetto.
32
-
33
- Bisogna rendere come prima cosa il progetto in expo predisposto all'utilizzo di moduli nativi, per farlo c'è il seguente comando:
34
-
35
- ```sh
36
- npx expo prebuild
37
- ```
38
- Questo creerà la cartella per iOS e per Android.
39
-
40
- È necessario, all'interno dell'app.js avere questa configurazione con **"useFrameworks": "static"**:
41
-
42
- ```sh
43
- "plugins": [
44
- [
45
- "expo-build-properties",
46
- {
47
- "android": {
48
- "buildToolsVersion": "34.0.0",
49
- "compileSdkVersion": 34,
50
- "minSdkVersion": 24,
51
- "targetSdkVersion": 34
52
- },
53
- "ios": {
54
- "deploymentTarget": "13.4",
55
- "useFrameworks": "static"
56
- }
57
- }
58
- ]
59
- ]
60
- ```
61
-
62
- Dopodiché si può passare all'installazione del pacchetto npm:
63
-
64
- ```sh
14
+ ```bash
65
15
  npm install react-native-sdk-pianoio
16
+ # or
17
+ yarn add react-native-sdk-pianoio
66
18
  ```
67
19
 
68
- ### iOS
69
-
70
- Nel progetto di react native entrare nella cartella per ios ed installare le dipendenze:
71
-
72
- ```sh
73
- pod install
74
- ```
20
+ ## 🚀 Quick Start
75
21
 
76
- ### Android
22
+ ### 1. Initialize the SDK
77
23
 
78
- Nel progetto di react native entrare nella cartella per android e [...]
24
+ ```javascript
25
+ import { PianoComposer } from 'react-native-sdk-pianoio';
79
26
 
80
- ```sh
81
- work in progress
27
+ // Initialize with your Piano Application ID
28
+ const composer = await PianoComposer.create('YOUR_PIANO_AID');
82
29
  ```
83
30
 
84
- #### Avviare progetto
31
+ ### 2. Configure the Experience
85
32
 
86
- In seguito si può far partire il progetto, tramite il comando:
33
+ ```javascript
34
+ // Set the required parameters for the experience
35
+ await composer.setUrl('https://www.your-website.com/premium-article');
36
+ await composer.setZoneId('your_zone_id'); // e.g., 'default'
37
+ await composer.setReferrer('https://www.your-website.com/');
87
38
 
88
- ```sh
89
- npx expo run:ios
39
+ // Add optional parameters
40
+ await composer.addTag('premium-content');
41
+ await composer.setCustomVariable('article_id', '12345');
90
42
  ```
91
43
 
92
- **Importante:** non usare ExpoGo per il progetto, potrebbe causare errori.
93
-
94
-
95
- ## Utilizzo
96
-
97
- ⚠️ Questa libreria al momento è progettata per funzionare con il modulo nativo iOS (NativeSdkPianoio), uno dei prossimi passi sarà renderla compatibile anche per Android.
44
+ ### 3. Execute the Experience
98
45
 
99
- ### Importazione
100
-
101
- ```ts
102
- import PianoComposer from './PianoComposer';
103
- ```
104
-
105
- ### Creazione del Composer
106
-
107
- ```ts
108
- const composer = await PianoComposer.create('your_aid');
109
- ```
110
-
111
- ## Metodi del Composer
112
-
113
- ### `addTag(tag: string)`
114
-
115
- Aggiunge un singolo tag all’istanza del composer.
116
-
117
- ```ts
118
- await composer.addTag('homepage');
119
- ```
120
-
121
- ---
122
-
123
- ### `addTags(tags: string[])`
124
-
125
- Aggiunge più tag in una sola chiamata.
126
-
127
- ```ts
128
- await composer.addTags(['homepage', 'subscriber']);
129
- ```
130
-
131
- ---
132
-
133
- ### `setZoneId(zoneId: string)`
134
-
135
- Imposta la zona del Composer.
136
-
137
- ```ts
138
- await composer.setZoneId('zone-123');
46
+ ```javascript
47
+ try {
48
+ const result = await composer.executeExperience();
49
+ console.log('Experience result:', result);
50
+ // Handle the event data from the Piano backend
51
+ } catch (error) {
52
+ console.error('Failed to execute experience:', error);
53
+ }
139
54
  ```
140
55
 
141
- ---
142
-
143
- ### `setReferrer(referrer: string)`
56
+ ### 4. Handle Authentication
144
57
 
145
- Imposta l’URL del referrer.
58
+ ```javascript
59
+ // Sign in a user
60
+ const user = await composer.signIn();
146
61
 
147
- ```ts
148
- await composer.setReferrer('https://example.com/article');
149
- ```
150
-
151
- ---
152
-
153
- ### `setUrl(url: string)`
62
+ // Check if a user is authenticated
63
+ const isAuthenticated = await composer.isAuthenticated();
154
64
 
155
- Imposta l’URL del contenuto su cui il Composer è eseguito.
65
+ // Get the current user's details
66
+ const currentUser = await composer.getCurrentUser();
156
67
 
157
- ```ts
158
- await composer.setUrl('https://example.com/page');
68
+ // Sign out the user
69
+ await composer.signOut();
159
70
  ```
160
71
 
161
- ---
72
+ ## 📋 API Reference
162
73
 
163
- ### `setCustomVariable(name: string, value: string)`
74
+ ### Core Methods
164
75
 
165
- Imposta una variabile personalizzata.
76
+ - `PianoComposer.create(aid: string)` - Creates and initializes a new PianoComposer instance
77
+ - `composer.executeExperience()` - Executes the Piano experience with the current configuration
78
+ - `composer.signIn()` - Initiates the user sign-in flow
79
+ - `composer.signOut()` - Signs out the current user
166
80
 
167
- ```ts
168
- await composer.setCustomVariable('userType', 'subscriber');
169
- ```
81
+ ### Configuration Methods
170
82
 
171
- ---
83
+ - `addTag(tag: string)`
84
+ - `addTags(tags: string[])`
85
+ - `setZoneId(zoneId: string)`
86
+ - `setReferrer(referrer: string)`
87
+ - `setUrl(url: string)`
88
+ - `setUserToken(token: string)`
89
+ - `addCustomVariable(key: string, value: string)`
90
+ - `setCustomVariables(variables: { [key: string]: string })`
172
91
 
173
- ### `setUserToken(token: string)`
92
+ ### Utility Methods
174
93
 
175
- Imposta il token utente per identificazione e personalizzazione.
94
+ - `getCurrentUser()`
95
+ - `isAuthenticated()`
96
+ - `getStatus()`
97
+ - `clearConfiguration()`
98
+ - `removeTag(tag: string)`
99
+ - `removeCustomVariable(key: string)`
100
+ - `clearTags()`
101
+ - `clearCustomVariables()`
176
102
 
177
- ```ts
178
- await composer.setUserToken('token123');
179
- ```
103
+ ## 📱 Platform Status
180
104
 
181
- ---
105
+ - ✅ **Android**: Fully implemented and aligned with the official Piano Android SDK
106
+ - ✅ **iOS**: Fully implemented and aligned with the official Piano iOS SDK
182
107
 
183
- ### `executeExperience()`
108
+ ## 🔧 Development
184
109
 
185
- Permette di eseguire l'espèerienza in base ai parametri impostati precedentemente, difatti le SDK ufficiali di piano non permettono di inserire in maniera comoda l'id dell'esperienza da eseguire, ma bisogna inserire il resto dei parametri e del resto se ne occupa il backend di piano.io.
110
+ ### Prerequisites
186
111
 
187
- ```ts
188
- await composer.executeExperience();
189
- ```
112
+ - Node.js 18+
113
+ - React Native
114
+ - Android Studio (for Android development)
115
+ - Xcode & CocoaPods (for iOS development)
190
116
 
191
- ---
117
+ ### Setup
192
118
 
193
- ### `toString()`
119
+ ```bash
120
+ # Clone the repository
121
+ git clone https://github.com/HexagonSwiss/hex-react-native-sdk-pianoio.git
194
122
 
195
- Restituisce una rappresentazione leggibile dello stato del Composer.
123
+ # Install dependencies
124
+ npm install
196
125
 
197
- ```ts
198
- console.log(await composer.toString());
126
+ # Build the library
127
+ npm run build
199
128
  ```
200
129
 
201
- Esempio:
130
+ ### Project Structure
202
131
 
203
132
  ```
204
- PianoComposer {
205
- aid: your_aid,
206
- tags: homepage,sports,
207
- zoneId: zone-123,
208
- referrer: https://example.com,
209
- customVariables: {"userType":"subscriber"},
210
- userToken: token123,
211
- url: https://example.com/article
212
- }
133
+ ├── android/ # Android native implementation
134
+ ├── ios/ # iOS native implementation
135
+ ├── src/ # TypeScript source (JS bridge)
136
+ └── ...
213
137
  ```
214
138
 
215
- ---
216
-
217
- ## Metodi statici
218
-
219
- ### `PianoComposer.create(aid: string): Promise<PianoComposer>`
220
-
221
- Crea e inizializza una nuova istanza di `PianoComposer`.
139
+ ## 🎯 Example App
222
140
 
223
- ### `PianoComposer.isInitialized(): Promise<boolean>`
141
+ The repository includes an example app to demonstrate all SDK features.
224
142
 
225
- Verifica se il composer è stato inizializzato correttamente a livello nativo.
143
+ ```bash
144
+ # Navigate to the example directory
145
+ cd example
226
146
 
227
- ```ts
228
- const initialized = await PianoComposer.isInitialized();
229
- ```
230
-
231
- ### `PianoComposer.getComposerFromSdkIOS(): Promise<Object>`
147
+ # Install dependencies
148
+ npm install
232
149
 
233
- Recupera i dati correnti dal modulo nativo iOS. Questo oggetto include:
150
+ # Run on Android
151
+ npx expo run:android
234
152
 
235
- ```ts
236
- {
237
- aid: string,
238
- tags: string[],
239
- zoneId: string,
240
- referrer: string,
241
- url: string,
242
- userToken: string,
243
- customVariables: { [key: string]: string }
244
- }
153
+ # Run on iOS
154
+ npx expo run:ios
245
155
  ```
246
156
 
247
- ## Esempio completo
157
+ ## 🤝 Contributing
248
158
 
249
- ```ts
250
- const composer = await PianoComposer.create('YOUR_AID');
251
-
252
- await composer.addTags(['homepage', 'premium']);
253
- await composer.setZoneId('zone-abc');
254
- await composer.setReferrer('https://my.site');
255
- await composer.setUrl('https://my.site/article');
256
- await composer.setUserToken('jwt-token');
257
- await composer.setCustomVariable('device', 'mobile');
258
-
259
- await composer.executeExperience();
260
-
261
- console.log(await composer.toString());
262
- ```
159
+ We welcome contributions! Please see our Contributing Guide for details.
263
160
 
264
- ## Contributing
161
+ ## 📄 License
265
162
 
266
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
163
+ This project is licensed under the MIT License - see the LICENSE file for details.
267
164
 
268
- ## License
165
+ ## 🆘 Support
269
166
 
270
- MIT
167
+ - 📧 **Email**: sviluppo@hexagonswiss.ch
168
+ - 🐛 **Issues**: [GitHub Issues](https://github.com/HexagonSwiss/hex-react-native-sdk-pianoio/issues)
169
+ - 📖 **Documentation**: [Piano.io Documentation](https://docs.piano.io/)
271
170
 
272
171
  ---
273
172
 
274
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
173
+ Made with ❤️ by HexagonSwiss
@@ -1,52 +1,35 @@
1
1
  buildscript {
2
- ext.getExtOrDefault = { name ->
3
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SdkPianoio_' + name]
2
+ ext {
3
+ buildToolsVersion = "35.0.0"
4
+ minSdkVersion = 24
5
+ compileSdkVersion = 34
6
+ targetSdkVersion = 34
7
+ ndkVersion = "27.1.12297006"
8
+ kotlinVersion = "2.0.21"
4
9
  }
5
-
6
10
  repositories {
7
11
  google()
8
12
  mavenCentral()
9
13
  }
10
-
11
14
  dependencies {
12
- classpath "com.android.tools.build:gradle:8.7.2"
13
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ classpath("com.android.tools.build:gradle:8.7.2")
16
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
14
17
  }
15
18
  }
16
19
 
17
20
  apply plugin: "com.android.library"
18
- apply plugin: "kotlin-android"
19
-
20
- def getExtOrIntegerDefault(name) {
21
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SdkPianoio_" + name]).toInteger()
22
- }
23
-
24
- def supportsNamespace() {
25
- def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
26
- def major = parsed[0].toInteger()
27
- def minor = parsed[1].toInteger()
28
-
29
- // Namespace support was added in 7.3.0
30
- return (major == 7 && minor >= 3) || major >= 8
31
- }
21
+ apply plugin: "org.jetbrains.kotlin.android"
32
22
 
33
23
  android {
34
- if (supportsNamespace()) {
35
- namespace "com.sdkpianoio"
24
+ ndkVersion rootProject.ext.ndkVersion
25
+ buildToolsVersion rootProject.ext.buildToolsVersion
26
+ compileSdk rootProject.ext.compileSdkVersion
36
27
 
37
- sourceSets {
38
- main {
39
- manifest.srcFile "src/main/AndroidManifestNew.xml"
40
- }
41
- }
42
- }
43
-
44
- // ✅ Esplicita i valori direttamente per evitare problemi
45
- compileSdkVersion 34
28
+ namespace "com.sdkpianoio"
46
29
 
47
30
  defaultConfig {
48
- minSdkVersion 21
49
- targetSdkVersion 34
31
+ minSdkVersion rootProject.ext.minSdkVersion
32
+ targetSdkVersion rootProject.ext.targetSdkVersion
50
33
  }
51
34
 
52
35
  buildFeatures {
@@ -64,8 +47,12 @@ android {
64
47
  }
65
48
 
66
49
  compileOptions {
67
- sourceCompatibility JavaVersion.VERSION_1_8
68
- targetCompatibility JavaVersion.VERSION_1_8
50
+ sourceCompatibility JavaVersion.VERSION_17
51
+ targetCompatibility JavaVersion.VERSION_17
52
+ }
53
+
54
+ kotlinOptions {
55
+ jvmTarget = '17'
69
56
  }
70
57
 
71
58
  sourceSets {
@@ -77,17 +64,17 @@ android {
77
64
  }
78
65
  }
79
66
  }
80
-
67
+ kotlin {
68
+ jvmToolchain(17)
69
+ }
81
70
  repositories {
82
71
  google()
83
72
  mavenCentral()
84
- maven { url("$rootDir/../node_modules/react-native/android") }
85
73
  }
86
74
 
87
75
  dependencies {
88
- implementation "org.jetbrains.kotlin:kotlin-stdlib:${getExtOrDefault('kotlinVersion')}"
89
- implementation "com.facebook.react:react-android" // React Native core
90
- implementation "com.facebook.react:react-native"
91
- implementation "io.piano.android:composer:2.11.0"
92
- implementation "io.piano.android:id:2.11.0"
76
+ implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21")
77
+ implementation("com.facebook.react:react-android:0.78.1")
78
+ implementation("io.piano.android:composer:2.11.0")
79
+ implementation("io.piano.android:id:2.11.0")
93
80
  }
@@ -1,20 +1,39 @@
1
- ## For more details on how to configure your build environment visit
1
+ # Project-wide Gradle settings.
2
+
3
+ # IDE (e.g. Android Studio) users:
4
+ # Gradle settings configured through the IDE *will override*
5
+ # any settings specified in this file.
6
+
7
+ # For more details on how to configure your build environment visit
2
8
  # http://www.gradle.org/docs/current/userguide/build_environment.html
3
- #
9
+
4
10
  # Specifies the JVM arguments used for the daemon process.
5
11
  # The setting is particularly useful for tweaking memory settings.
6
- # Default value: -Xmx1024m -XX:MaxPermSize=256m
7
- # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
8
- #
12
+ # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
13
+ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
14
+
9
15
  # When configured, Gradle will run in incubating parallel mode.
10
- # This option should only be used with decoupled projects. For more details, visit
11
- # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
16
+ # This option should only be used with decoupled projects. More details, visit
17
+ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
12
18
  # org.gradle.parallel=true
13
- #Thu Jul 10 13:17:17 CEST 2025
14
- SdkPianoio_compileSdkVersion=35
15
- SdkPianoio_kotlinVersion=2.0.21
16
- SdkPianoio_minSdkVersion=24
17
- SdkPianoio_ndkVersion=27.1.12297006
18
- SdkPianoio_targetSdkVersion=34
19
- android.enableJetifier=true
19
+
20
+ # AndroidX package structure to make it clearer which packages are bundled with the
21
+ # Android operating system, and which are packaged with your app's APK
22
+ # https://developer.android.com/topic/libraries/support-library/androidx-rn
20
23
  android.useAndroidX=true
24
+
25
+ # Use this property to specify which architecture you want to build.
26
+ # You can also override it from the CLI using
27
+ # ./gradlew <task> -PreactNativeArchitectures=x86_64
28
+ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
29
+
30
+ # Use this property to enable support to the new architecture.
31
+ # This will allow you to use TurboModules and the Fabric render in
32
+ # your application. You should enable this flag either if you want
33
+ # to write custom TurboModules/Fabric components OR use libraries that
34
+ # are providing them.
35
+ newArchEnabled=true
36
+
37
+ # Use this property to enable or disable the Hermes JS engine.
38
+ # If set to false, you will be using JSC instead.
39
+ hermesEnabled=true