diff --git a/.github/workflows/gitleaks-secrets-validate.yml b/.github/workflows/gitleaks-secrets-validate.yml new file mode 100644 index 0000000..a9a6a62 --- /dev/null +++ b/.github/workflows/gitleaks-secrets-validate.yml @@ -0,0 +1,19 @@ +name: Gitleaks Secrets Validate +on: + pull_request: + workflow_dispatch: +jobs: + scan: + name: gitleaks + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run Gitleaks + uses: gitleaks/gitleaks-action@v2.3.4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITLEAKS_LICENSE: ${{ secrets.MINDBOX_GITLEAKS_LICENSE }} diff --git a/mindbox_ios/example/.gitignore b/example/flutter_example/.gitignore similarity index 72% rename from mindbox_ios/example/.gitignore rename to example/flutter_example/.gitignore index daa55a8..3965723 100644 --- a/mindbox_ios/example/.gitignore +++ b/example/flutter_example/.gitignore @@ -8,17 +8,7 @@ .buildlog/ .history .svn/ -mindbox_ios_example.iml -pubspec.lock -.metadata -.packages -.flutter-plugins-dependencies -.flutter-plugins -ios/Podfile.lock -ios/Pods/ -android/gradlew -android/gradlew.bat -android/local.properties +migrate_working_dir/ # IntelliJ related *.iml @@ -37,14 +27,10 @@ android/local.properties .dart_tool/ .flutter-plugins .flutter-plugins-dependencies -.packages .pub-cache/ .pub/ /build/ -# Web related -lib/generated_plugin_registrant.dart - # Symbolication related app.*.symbols @@ -55,3 +41,6 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +/android/app/google-services.json +/android/app/agconnect-services.json \ No newline at end of file diff --git a/example/flutter_example/.metadata b/example/flutter_example/.metadata new file mode 100644 index 0000000..d2765fc --- /dev/null +++ b/example/flutter_example/.metadata @@ -0,0 +1,45 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "54e66469a933b60ddf175f858f82eaeb97e48c8d" + channel: "stable" + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + - platform: android + create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + - platform: ios + create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + - platform: linux + create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + - platform: macos + create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + - platform: web + create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + - platform: windows + create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/flutter_example/README.md b/example/flutter_example/README.md new file mode 100644 index 0000000..4810d23 --- /dev/null +++ b/example/flutter_example/README.md @@ -0,0 +1,71 @@ +# Example app for Mindbox SDK for flutter + +This is an example of SDK [integration](https://developers.mindbox.ru/docs/flutter-sdk-integration) + +## Getting Started + +### IOS +1. Clone [flutter-sdk repository](https://github.com/mindbox-cloud/flutter-sdk). +2. Go to `flutter-sdk/example/flutter_example`. +3. From the terminal: + ``` + flutter pub get + ``` +4. Make sure you have CocoaPods installed or install it according to the instructions. +5. Go to `ios/Runner`. +6. Install pods: +``` +pod install +``` +7. Launch `Runner.xcworkspace` . +8. Launch app. + +Now you can test the in-app on the simulator. +In our admin panel there are already 3 ready-made in-apps that you can look at. +To run the application on a real device and try push notifications, follow the instructions below. + +9. Change [team](https://developers.mindbox.ru/docs/ios-get-keys) and bundle identifiers and App Group name for next targets: + - Runner + - MindboxNotificationServiceExtension + - MindboxNotificationContentExtension +10. [Configure your endpoints](https://developers.mindbox.ru/docs/add-ios-integration). +11. Change domain and endpoints in the `main.dart` to yours. + +### Android +1. Clone [flutter-sdk repository](https://github.com/mindbox-cloud/flutter-sdk). +2. Go to `flutter-sdk/example/flutter_example`. +3. From the terminal: + ``` + flutter pub get + ``` +4. Open `android` folder in Android Studio. +5. Change `namespace` and `applicationId` in `app/build.gradle` to yours. +6. Add `google-services.json` and `agconnect-services.json` to `android/app`. +- [Get google-services.json](https://developers.mindbox.ru/docs/firebase-get-keys) +- [Get agconnect-services.json](https://developers.mindbox.ru/docs/huawei-get-keys) +7. [Configure your endpoints](https://developers.mindbox.ru/docs/add-ios-integration). +8. Change domain and endpoints in the `main.dart` to yours. +8. Launch app. + +### SDK functionality testing +1. To check innap when opening: + - [Read this](https://help.mindbox.ru/docs/in-app-what-is). + - Open app. +2. To check the inapp anywhere in the application: + - [Read this](https://help.mindbox.ru/docs/in-app-location). + - Replace `operationSystemName` in `syncOperation` and `asyncOperation` in `view_model.dart`. + - Click to the button `Show in-app` opposite the selected operation. +3. To check push notifications: + - Read [iOS](https://developers.mindbox.ru/docs/ios-send-push-notifications-flutter). + - Read [android with Firebase](https://developers.mindbox.ru/docs/firebase-send-push-notifications-flutter). + - Read [android with Huawei](https://developers.mindbox.ru/docs/huawei-send-push-notifications-flutter). + - Send a notification from your account. +4. To check rich-push notifications: + - Read [iOS](https://developers.mindbox.ru/docs/ios-send-rich-push-flutter). + - Read [android with Firebase](https://developers.mindbox.ru/docs/firebase-send-push-notifications-flutter). + - Read [android with Huawei](https://developers.mindbox.ru/docs/huawei-send-push-notifications-flutter). + - Send a notification from your account. + +### Additionally + - Currently the In-App only comes once per session. + - There are comments and links in the flutter example code that can help you. diff --git a/mindbox_ios/example/analysis_options.yaml b/example/flutter_example/analysis_options.yaml similarity index 93% rename from mindbox_ios/example/analysis_options.yaml rename to example/flutter_example/analysis_options.yaml index 61b6c4d..0d29021 100644 --- a/mindbox_ios/example/analysis_options.yaml +++ b/example/flutter_example/analysis_options.yaml @@ -13,8 +13,7 @@ linter: # The lint rules applied to this project can be customized in the # section below to disable rules from the `package:flutter_lints/flutter.yaml` # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. + # and their documentation is published at https://dart.dev/lints. # # Instead of disabling a lint rule for the entire project in the # section below, it can also be suppressed for a single line of code diff --git a/mindbox_android/example/android/.gitignore b/example/flutter_example/android/.gitignore similarity index 100% rename from mindbox_android/example/android/.gitignore rename to example/flutter_example/android/.gitignore diff --git a/example/flutter_example/android/app/build.gradle b/example/flutter_example/android/app/build.gradle new file mode 100644 index 0000000..d0b4198 --- /dev/null +++ b/example/flutter_example/android/app/build.gradle @@ -0,0 +1,78 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" + id 'com.google.gms.google-services' + id 'com.huawei.agconnect' +} + +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +android { + namespace "cloud.mindbox.flutter_example" + compileSdk flutter.compileSdkVersion + ndkVersion flutter.ndkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + applicationId "cloud.mindbox.flutter_example" + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + multiDexEnabled true + } + + buildTypes { + release { + signingConfig signingConfigs.debug + } + } + buildToolsVersion '34.0.0' +} + +flutter { + source '../..' +} + +ext.mindbox_version = "2.9.1" + +dependencies { + implementation 'androidx.multidex:multidex:2.0.1' + //https://developers.mindbox.ru/docs/firebase-send-push-notifications-flutter + implementation "cloud.mindbox:mobile-sdk:$mindbox_version" + implementation "cloud.mindbox:mindbox-firebase:$mindbox_version" + implementation platform('com.google.firebase:firebase-bom:32.8.1') + implementation 'com.google.firebase:firebase-messaging:23.4.1' + //https://developers.mindbox.ru/docs/huawei-send-push-notifications-flutter + implementation "cloud.mindbox:mindbox-huawei:$mindbox_version" + implementation 'com.huawei.hms:push:6.11.0.300' +} \ No newline at end of file diff --git a/mindbox_android/example/android/app/src/debug/AndroidManifest.xml b/example/flutter_example/android/app/src/debug/AndroidManifest.xml similarity index 58% rename from mindbox_android/example/android/app/src/debug/AndroidManifest.xml rename to example/flutter_example/android/app/src/debug/AndroidManifest.xml index f880684..399f698 100644 --- a/mindbox_android/example/android/app/src/debug/AndroidManifest.xml +++ b/example/flutter_example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,6 @@ - diff --git a/mindbox_android/example/android/app/src/main/AndroidManifest.xml b/example/flutter_example/android/app/src/main/AndroidManifest.xml similarity index 64% rename from mindbox_android/example/android/app/src/main/AndroidManifest.xml rename to example/flutter_example/android/app/src/main/AndroidManifest.xml index d5a265f..b4d9445 100644 --- a/mindbox_android/example/android/app/src/main/AndroidManifest.xml +++ b/example/flutter_example/android/app/src/main/AndroidManifest.xml @@ -1,10 +1,28 @@ - + + + + + + + + + + + + + + - - @@ -37,5 +46,11 @@ + + + + + + diff --git a/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MainActivity.kt b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MainActivity.kt new file mode 100644 index 0000000..309e879 --- /dev/null +++ b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MainActivity.kt @@ -0,0 +1,5 @@ +package cloud.mindbox.flutter_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() diff --git a/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MainApplication.kt b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MainApplication.kt new file mode 100644 index 0000000..09d37a9 --- /dev/null +++ b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MainApplication.kt @@ -0,0 +1,13 @@ +package cloud.mindbox.flutter_example + +import android.app.Application +import cloud.mindbox.mobile_sdk.Mindbox +import cloud.mindbox.mindbox_firebase.MindboxFirebase +import cloud.mindbox.mindbox_huawei.MindboxHuawei + +class MainApplication : Application() { + override fun onCreate() { + super.onCreate() + Mindbox.initPushServices(applicationContext, listOf(MindboxFirebase, MindboxHuawei)) + } +} \ No newline at end of file diff --git a/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MindboxFirebaseMessagingService.kt b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MindboxFirebaseMessagingService.kt new file mode 100644 index 0000000..1e5a143 --- /dev/null +++ b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MindboxFirebaseMessagingService.kt @@ -0,0 +1,37 @@ +package cloud.mindbox.flutter_example + +import cloud.mindbox.mobile_sdk.Mindbox +import com.google.firebase.messaging.* +import cloud.mindbox.mindbox_firebase.MindboxFirebase + +class MindboxFirebaseMessagingService: FirebaseMessagingService() { + override fun onNewToken(token: String) { + Mindbox.updatePushToken(applicationContext, token, MindboxFirebase) + super.onNewToken(token) + } + + override fun onMessageReceived(remoteMessage: RemoteMessage) { + super.onMessageReceived(remoteMessage) + val channelId = "default_channel_id" + val channelName = "default_channel_name" + val channelDescription = "default_channel_description" + val pushSmallIcon = android.R.drawable.ic_dialog_info + + + val messageWasHandled = Mindbox.handleRemoteMessage( + context = applicationContext, + message = remoteMessage, + activities = mapOf(), + channelId = channelId, + channelName = channelName, + pushSmallIcon = pushSmallIcon, + defaultActivity = MainActivity::class.java, + channelDescription = channelDescription + ) + + if (!messageWasHandled) { + //If the push notification was not from Mindbox or it contains incorrect data, then you can write a fallback to process it + } + } + +} \ No newline at end of file diff --git a/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MindboxHuaweiMessagingService.kt b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MindboxHuaweiMessagingService.kt new file mode 100644 index 0000000..bf477d5 --- /dev/null +++ b/example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MindboxHuaweiMessagingService.kt @@ -0,0 +1,36 @@ +package cloud.mindbox.flutter_example + +import cloud.mindbox.mobile_sdk.Mindbox +import com.huawei.hms.push.* +import cloud.mindbox.mindbox_huawei.MindboxHuawei + +class MindboxHuaweiMessagingService: HmsMessageService() { + override fun onNewToken(token: String) { + super.onNewToken(token) + Mindbox.updatePushToken(applicationContext, token, MindboxHuawei) + } + + override fun onMessageReceived(remoteMessage: RemoteMessage) { + super.onMessageReceived(remoteMessage) + val channelId = "default_channel_id" + val channelName = "default_channel_name" + val channelDescription = "default_channel_description" + val pushSmallIcon = android.R.drawable.ic_dialog_info + + val messageWasHandled = Mindbox.handleRemoteMessage( + context = applicationContext, + message = remoteMessage, + activities = mapOf(), + channelId = channelId, + channelName = channelName, + pushSmallIcon = pushSmallIcon, + defaultActivity = MainActivity::class.java, + channelDescription = channelDescription + ) + + if (!messageWasHandled) { + //If the push notification was not from Mindbox or it contains incorrect data, then you can write a fallback to process it + } + + } +} \ No newline at end of file diff --git a/mindbox_android/example/android/app/src/main/res/drawable-v21/launch_background.xml b/example/flutter_example/android/app/src/main/res/drawable-v21/launch_background.xml similarity index 100% rename from mindbox_android/example/android/app/src/main/res/drawable-v21/launch_background.xml rename to example/flutter_example/android/app/src/main/res/drawable-v21/launch_background.xml diff --git a/mindbox_android/example/android/app/src/main/res/drawable/launch_background.xml b/example/flutter_example/android/app/src/main/res/drawable/launch_background.xml similarity index 100% rename from mindbox_android/example/android/app/src/main/res/drawable/launch_background.xml rename to example/flutter_example/android/app/src/main/res/drawable/launch_background.xml diff --git a/mindbox_android/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/example/flutter_example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from mindbox_android/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to example/flutter_example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/mindbox_android/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/example/flutter_example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from mindbox_android/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to example/flutter_example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/mindbox_android/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/example/flutter_example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from mindbox_android/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to example/flutter_example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/mindbox_android/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/example/flutter_example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from mindbox_android/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to example/flutter_example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/mindbox_android/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/example/flutter_example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from mindbox_android/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to example/flutter_example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/mindbox_android/example/android/app/src/main/res/values-night/styles.xml b/example/flutter_example/android/app/src/main/res/values-night/styles.xml similarity index 94% rename from mindbox_android/example/android/app/src/main/res/values-night/styles.xml rename to example/flutter_example/android/app/src/main/res/values-night/styles.xml index 449a9f9..06952be 100644 --- a/mindbox_android/example/android/app/src/main/res/values-night/styles.xml +++ b/example/flutter_example/android/app/src/main/res/values-night/styles.xml @@ -3,14 +3,14 @@