Skip to content

Commit

Permalink
Added Extras Field and Source SDK on iOS (#8)
Browse files Browse the repository at this point in the history
* Fixes from testing

- Rename package to smile_id
- Update README
- Added Job Type mapping
- Re-ran pigeon
- Simplified usage of SmileID entry
- Removed PlatformInterface
- Downgrade Flutter version requirement
- Add mockito for tests

* Fix test

* Update iOS Pod name

* added permission instructions

* updated CONTRIBUTING.md

* updated CONTRIBUTING.md

* Take default values from native SmileID.config

* Fix iOS

* Create smile_config for ios

* added extras field and source sdk on iOS

* cleaning up flutter pub deps

* run pigeon to generate missing extras field

* added empty map to partner params

* added release pipeline

* bumped up smile ios sdk version

* Fixes

---------

Co-authored-by: Vansh Gandhi <vansh@smileidentity.com>
  • Loading branch information
jumaallan and vanshg authored Aug 16, 2023
1 parent 8f564bf commit a170aa8
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 20 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/release_sdk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release Flutter SDK
on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

jobs:
deployment:
name: Deploy package
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Flutter action
uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Publish package
run: dart pub publish -v -f
13 changes: 10 additions & 3 deletions android/src/main/kotlin/com/smileidentity/flutter/Messages.g.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ enum class FlutterJobType(val raw: Int) {
}
}

/** Generated class from Pigeon that represents data sent in messages. */
/**
* Custom values specific to partners can be placed in [extras]
*
* Generated class from Pigeon that represents data sent in messages.
*/
data class FlutterPartnerParams (
val jobType: FlutterJobType? = null,
val jobId: String,
val userId: String
val userId: String,
val extras: Map<String?, String?>? = null

) {
companion object {
Expand All @@ -67,14 +72,16 @@ data class FlutterPartnerParams (
}
val jobId = list[1] as String
val userId = list[2] as String
return FlutterPartnerParams(jobType, jobId, userId)
val extras = list[3] as Map<String?, String?>?
return FlutterPartnerParams(jobType, jobId, userId, extras)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
jobType?.raw,
jobId,
userId,
extras,
)
}
}
Expand Down
28 changes: 26 additions & 2 deletions android/src/main/kotlin/com/smileidentity/flutter/mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,31 @@ import com.smileidentity.models.EnhancedKycRequest
import com.smileidentity.models.JobType
import com.smileidentity.models.PartnerParams

/**
* Pigeon does not allow non nullable types in this example here
*
* final Map<String, String> extras;
*
* Error: pigeons/messages.dart:18: Generic type arguments must be nullable in field "extras" in
* class "FlutterPartnerParams".
*
* The fix is these two helper functions to convert maps to nullable types, and vice versa
*/
fun convertNullableMapToNonNull(map: Map<String?, String?>?): Map<String, String> =
map?.filterKeys { it != null }
?.filterValues { it != null }
?.mapKeys { it.key!! }
?.mapValues { it.value!! } ?: mapOf()

fun convertNonNullMapToNullable(map: Map<String, String>): Map<String?, String?> =
map.mapKeys { it.key }
.mapValues { it.value }


fun FlutterJobType.toRequest() = when(this) {
FlutterJobType.ENHANCEDKYC -> JobType.EnhancedKyc
}

fun JobType.toResponse() = when(this) {
fun JobType.toResponse() = when (this) {
JobType.EnhancedKyc -> FlutterJobType.ENHANCEDKYC
else -> TODO("Not yet implemented")
}
Expand All @@ -42,6 +57,14 @@ fun PartnerParams.toResponse() = FlutterPartnerParams(
jobType = jobType?.toResponse(),
jobId = jobId,
userId = userId,
extras = convertNonNullMapToNullable(extras)
)

fun FlutterPartnerParams.toRequest() = PartnerParams(
jobType = jobType?.toRequest(),
jobId = jobId,
userId = userId,
extras = convertNullableMapToNonNull(extras)
)

fun ConsentInfo.toRequest() = FlutterConsentInfo(
Expand Down Expand Up @@ -73,6 +96,7 @@ fun FlutterEnhancedKycRequest.toRequest() = EnhancedKycRequest(
jobType = partnerParams.jobType?.toRequest(),
jobId = partnerParams.jobId,
userId = partnerParams.userId,
extras = convertNullableMapToNonNull(partnerParams.extras)
),
sourceSdk = "android (flutter)",
timestamp = timestamp,
Expand Down
12 changes: 7 additions & 5 deletions ios/Classes/Mapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ extension FlutterEnhancedKycRequest {
phoneNumber: phoneNumber,
bankCode: bankCode,
callbackUrl: callbackUrl,
partnerParams: partnerParams.toPartnerParams(),
partnerParams: partnerParams.toRequest(),
sourceSdk: "ios (flutter)",
timestamp: timestamp,
signature: signature)
}
Expand All @@ -31,16 +32,16 @@ extension EnhancedKycAsyncResponse {
}

extension FlutterPartnerParams {
func toPartnerParams() -> PartnerParams {
func toRequest() -> PartnerParams {
PartnerParams(jobId: jobId,
userId: userId,
jobType: JobType(rawValue: jobType!.rawValue)!)
jobType: jobType!.toRequest())
}
}

extension FlutterAuthenticationRequest {
func toRequest() -> AuthenticationRequest {
let mappedJobType = JobType(rawValue: jobType.rawValue)!
let mappedJobType = jobType.toRequest()
return AuthenticationRequest(jobType: mappedJobType,
enrollment: mappedJobType == .smartSelfieEnrollment,
updateEnrolledImage: updateEnrolledImage,
Expand All @@ -62,7 +63,8 @@ extension PartnerParams {
func toFlutterPartnerParams() -> FlutterPartnerParams {
FlutterPartnerParams(jobType: FlutterJobType(rawValue: jobType.rawValue),
jobId: jobId,
userId: userId)
userId: userId,
extras: [:])
}
}

Expand Down
8 changes: 7 additions & 1 deletion ios/Classes/Messages.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ enum FlutterJobType: Int {
case enhancedKyc = 0
}

/// Custom values specific to partners can be placed in [extras]
///
/// Generated class from Pigeon that represents data sent in messages.
struct FlutterPartnerParams {
var jobType: FlutterJobType? = nil
var jobId: String
var userId: String
var extras: [String?: String?]? = nil

static func fromList(_ list: [Any?]) -> FlutterPartnerParams? {
var jobType: FlutterJobType? = nil
Expand All @@ -52,18 +55,21 @@ struct FlutterPartnerParams {
}
let jobId = list[1] as! String
let userId = list[2] as! String
let extras: [String?: String?]? = nilOrValue(list[3])

return FlutterPartnerParams(
jobType: jobType,
jobId: jobId,
userId: userId
userId: userId,
extras: extras
)
}
func toList() -> [Any?] {
return [
jobType?.rawValue,
jobId,
userId,
extras,
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions ios/smile_id.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Pod::Spec.new do |s|
s.name = 'smile_id'
# NB! Keep this version in sync with the Native iOS SDK version
s.version = '10.0.0-beta04'
s.version = '10.0.0-beta06'
s.summary = 'Official Smile ID SDK for Flutter'
s.description = <<-DESC
A new Flutter project.
Expand All @@ -15,7 +15,7 @@ A new Flutter project.
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
# NB! Update the s.version above when changing this version
s.dependency 'SmileID' , '10.0.0-beta04'
s.dependency 'SmileID' , '10.0.0-beta06'
s.platform = :ios, '13.0'

# Flutter.framework does not contain a i386 slice.
Expand Down
6 changes: 6 additions & 0 deletions lib/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ enum FlutterJobType {
enhancedKyc,
}

/// Custom values specific to partners can be placed in [extras]
class FlutterPartnerParams {
FlutterPartnerParams({
this.jobType,
required this.jobId,
required this.userId,
this.extras,
});

FlutterJobType? jobType;
Expand All @@ -25,11 +27,14 @@ class FlutterPartnerParams {

String userId;

Map<String?, String?>? extras;

Object encode() {
return <Object?>[
jobType?.index,
jobId,
userId,
extras,
];
}

Expand All @@ -41,6 +46,7 @@ class FlutterPartnerParams {
: null,
jobId: result[1]! as String,
userId: result[2]! as String,
extras: (result[3] as Map<Object?, Object?>?)?.cast<String?, String?>(),
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/smile_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class SmileID {
return platformInterface.authenticate(request);
}

static Future<FlutterEnhancedKycAsyncResponse?> doEnhancedKycAsync(FlutterEnhancedKycRequest request) {
static Future<FlutterEnhancedKycAsyncResponse?> doEnhancedKycAsync(
FlutterEnhancedKycRequest request) {
return platformInterface.doEnhancedKycAsync(request);
}
}
2 changes: 2 additions & 0 deletions pigeon/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import 'package:pigeon/pigeon.dart';
))
enum FlutterJobType { enhancedKyc }

/// Custom values specific to partners can be placed in [extras]
class FlutterPartnerParams {
final FlutterJobType? jobType;
final String jobId;
final String userId;
Map<String?, String?>? extras;

FlutterPartnerParams(this.jobType, this.jobId, this.userId);
}
Expand Down
4 changes: 4 additions & 0 deletions sample/ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Flutter/flutter_export_environment.sh
ServiceDefinitions.json
Runner/GeneratedPluginRegistrant.*

# This .gitignore file is not technically necessary, but it is retained here in order for the assets
# directory to be included in git, as it would otherwise be empty
smile_config.json

# Exceptions to above rules.
!default.mode1v3
!default.mode2v3
Expand Down
10 changes: 5 additions & 5 deletions sample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ PODS:
- Flutter (1.0.0)
- integration_test (0.0.1):
- Flutter
- smile_id (10.0.0-beta04):
- smile_id (10.0.0-beta06):
- Flutter
- SmileID (= 10.0.0-beta04)
- SmileID (10.0.0-beta04):
- SmileID (= 10.0.0-beta06)
- SmileID (10.0.0-beta06):
- Zip (~> 2.1.0)
- Zip (2.1.2)

Expand All @@ -30,8 +30,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
integration_test: 13825b8a9334a850581300559b8839134b124670
smile_id: 60b37c0c644448e8b8f3a39c706c25f09232eb3d
SmileID: c3ebaee55b06009cf1363df98e4dab82d2c3b1a4
smile_id: b8ca41650880b5ab85addb0e485131906df9430e
SmileID: b102f1f2e2ab35601d89ea618ef26c27b4489421
Zip: b3fef584b147b6e582b2256a9815c897d60ddc67

PODFILE CHECKSUM: 929954fb8941cef06249e96bd1516fd2a22ed7a5
Expand Down
2 changes: 1 addition & 1 deletion sample/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _MyAppState extends State<MyApp> {
child: Column(
children: [
ElevatedButton(
child: Text("Enhanced KYC (Async)"),
child: const Text("Enhanced KYC (Async)"),
onPressed: () {
SmileID.initialize();
var userId = "<your user's user ID>";
Expand Down

0 comments on commit a170aa8

Please sign in to comment.