react-native-spike-sdk 4.3.43 → 4.3.53
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.
|
@@ -597,21 +597,16 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
597
597
|
customerEndUserId: String,
|
|
598
598
|
promise: Promise
|
|
599
599
|
) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
)
|
|
608
|
-
|
|
609
|
-
addConnectionV3(connection, uuid)
|
|
610
|
-
promise.resolve(uuid)
|
|
600
|
+
executeV3Method(promise) {
|
|
601
|
+
val connection = SpikeConnectionAPIv3.createConnectionLegacy(
|
|
602
|
+
appId = appId,
|
|
603
|
+
authToken = authToken,
|
|
604
|
+
customerEndUserId = customerEndUserId,
|
|
605
|
+
context = reactApplicationContext
|
|
606
|
+
)
|
|
611
607
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
608
|
+
addConnectionV3(connection, uuid)
|
|
609
|
+
promise.resolve(uuid)
|
|
615
610
|
}
|
|
616
611
|
}
|
|
617
612
|
|
|
@@ -623,21 +618,16 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
623
618
|
endUserId: String,
|
|
624
619
|
promise: Promise
|
|
625
620
|
) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
)
|
|
634
|
-
|
|
635
|
-
addConnectionV3(connection, uuid)
|
|
636
|
-
promise.resolve(uuid)
|
|
621
|
+
executeV3Method(promise) {
|
|
622
|
+
val connection = SpikeConnectionAPIv3.createConnection(
|
|
623
|
+
applicationId = applicationId,
|
|
624
|
+
signature = signature,
|
|
625
|
+
endUserId = endUserId,
|
|
626
|
+
context = reactApplicationContext
|
|
627
|
+
)
|
|
637
628
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
629
|
+
addConnectionV3(connection, uuid)
|
|
630
|
+
promise.resolve(uuid)
|
|
641
631
|
}
|
|
642
632
|
}
|
|
643
633
|
|
|
@@ -648,20 +638,9 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
648
638
|
connectionUUID: String,
|
|
649
639
|
promise: Promise
|
|
650
640
|
) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
655
|
-
"Connection not found (getUserInfo)"
|
|
656
|
-
)
|
|
657
|
-
|
|
658
|
-
val result = connection.getUserInfo()
|
|
659
|
-
|
|
660
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
661
|
-
|
|
662
|
-
} catch (e: SpikeExceptions) {
|
|
663
|
-
promise.reject(e.mapException(), e.message)
|
|
664
|
-
}
|
|
641
|
+
executeV3MethodWithConnection("getUserInfo", connectionUUID, promise) { connection ->
|
|
642
|
+
val result = connection.getUserInfo()
|
|
643
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
665
644
|
}
|
|
666
645
|
}
|
|
667
646
|
|
|
@@ -674,26 +653,15 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
674
653
|
config: String?,
|
|
675
654
|
promise: Promise
|
|
676
655
|
) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
val providerObject = Provider.values().find { it.value == provider } ?: Provider.UNKNOWN
|
|
685
|
-
val configObject = if (config != null) {
|
|
686
|
-
IntegrationInitConfigUtils.fromValue(config)
|
|
687
|
-
} else {
|
|
688
|
-
null
|
|
689
|
-
}
|
|
690
|
-
val result = connection.getIntegrationInitUrl(providerObject, configObject)
|
|
691
|
-
|
|
692
|
-
promise.resolve(result)
|
|
693
|
-
|
|
694
|
-
} catch (e: SpikeExceptions) {
|
|
695
|
-
promise.reject(e.mapException(), e.message)
|
|
656
|
+
executeV3MethodWithConnection("getIntegrationInitUrl", connectionUUID, promise) { connection ->
|
|
657
|
+
val providerObject = Provider.values().find { it.value == provider } ?: Provider.UNKNOWN
|
|
658
|
+
val configObject = if (config != null) {
|
|
659
|
+
IntegrationInitConfigUtils.fromValue(config)
|
|
660
|
+
} else {
|
|
661
|
+
null
|
|
696
662
|
}
|
|
663
|
+
val result = connection.getIntegrationInitUrl(providerObject, configObject)
|
|
664
|
+
promise.resolve(result)
|
|
697
665
|
}
|
|
698
666
|
}
|
|
699
667
|
|
|
@@ -709,33 +677,24 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
709
677
|
filter: String?, // StatisticsFilter?
|
|
710
678
|
promise: Promise
|
|
711
679
|
) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
from = dateFrom,
|
|
729
|
-
to = dateTo,
|
|
730
|
-
interval = statsInterval,
|
|
731
|
-
filter = statsFilter
|
|
732
|
-
)
|
|
733
|
-
|
|
734
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
680
|
+
executeV3MethodWithConnection("getStatistics", connectionUUID, promise) { connection ->
|
|
681
|
+
val statTypes = types.toArrayList().mapNotNull {
|
|
682
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
683
|
+
}.toSet()
|
|
684
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
685
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
686
|
+
val statsInterval = StatisticsIntervalUtils.fromValue(interval)
|
|
687
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
688
|
+
|
|
689
|
+
val result = connection.getStatistics(
|
|
690
|
+
types = statTypes,
|
|
691
|
+
from = dateFrom,
|
|
692
|
+
to = dateTo,
|
|
693
|
+
interval = statsInterval,
|
|
694
|
+
filter = statsFilter
|
|
695
|
+
)
|
|
735
696
|
|
|
736
|
-
|
|
737
|
-
promise.reject(e.mapException(), e.message)
|
|
738
|
-
}
|
|
697
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
739
698
|
}
|
|
740
699
|
}
|
|
741
700
|
|
|
@@ -748,31 +707,22 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
748
707
|
filter: String?, // StatisticsFilter?
|
|
749
708
|
promise: Promise
|
|
750
709
|
) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
types = statTypes,
|
|
766
|
-
from = dateFrom,
|
|
767
|
-
to = dateTo,
|
|
768
|
-
filter = statsFilter
|
|
769
|
-
)
|
|
710
|
+
executeV3MethodWithConnection("getRecords", connectionUUID, promise) { connection ->
|
|
711
|
+
val statTypes = types.toArrayList().mapNotNull {
|
|
712
|
+
MetricTypeUtils.fromValue(it as String)
|
|
713
|
+
}.toSet()
|
|
714
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
715
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
716
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
717
|
+
|
|
718
|
+
val result = connection.getRecords(
|
|
719
|
+
types = statTypes,
|
|
720
|
+
from = dateFrom,
|
|
721
|
+
to = dateTo,
|
|
722
|
+
filter = statsFilter
|
|
723
|
+
)
|
|
770
724
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
} catch (e: SpikeExceptions) {
|
|
774
|
-
promise.reject(e.mapException(), e.message)
|
|
775
|
-
}
|
|
725
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
776
726
|
}
|
|
777
727
|
}
|
|
778
728
|
|
|
@@ -785,29 +735,20 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
785
735
|
filter: String?, // StatisticsFilter?
|
|
786
736
|
promise: Promise
|
|
787
737
|
) {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
config = configObject,
|
|
801
|
-
from = dateFrom,
|
|
802
|
-
to = dateTo,
|
|
803
|
-
filter = statsFilter
|
|
804
|
-
)
|
|
738
|
+
executeV3MethodWithConnection("getActivities", connectionUUID, promise) { connection ->
|
|
739
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
740
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
741
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
742
|
+
val configObject = ActivityConfigUtils.fromValue(configJson) ?: ActivityConfig()
|
|
743
|
+
|
|
744
|
+
val result = connection.getActivities(
|
|
745
|
+
config = configObject,
|
|
746
|
+
from = dateFrom,
|
|
747
|
+
to = dateTo,
|
|
748
|
+
filter = statsFilter
|
|
749
|
+
)
|
|
805
750
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
} catch (e: SpikeExceptions) {
|
|
809
|
-
promise.reject(e.mapException(), e.message)
|
|
810
|
-
}
|
|
751
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
811
752
|
}
|
|
812
753
|
}
|
|
813
754
|
|
|
@@ -820,29 +761,20 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
820
761
|
filter: String?, // StatisticsFilter?
|
|
821
762
|
promise: Promise
|
|
822
763
|
) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
config = configObject,
|
|
836
|
-
from = dateFrom,
|
|
837
|
-
to = dateTo,
|
|
838
|
-
filter = statsFilter
|
|
839
|
-
)
|
|
764
|
+
executeV3MethodWithConnection("getSleep", connectionUUID, promise) { connection ->
|
|
765
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
766
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
767
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
768
|
+
val configObject = SleepConfigUtils.fromValue(configJson) ?: SleepConfig()
|
|
769
|
+
|
|
770
|
+
val result = connection.getSleep(
|
|
771
|
+
config = configObject,
|
|
772
|
+
from = dateFrom,
|
|
773
|
+
to = dateTo,
|
|
774
|
+
filter = statsFilter
|
|
775
|
+
)
|
|
840
776
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
} catch (e: SpikeExceptions) {
|
|
844
|
-
promise.reject(e.mapException(), e.message)
|
|
845
|
-
}
|
|
777
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
846
778
|
}
|
|
847
779
|
}
|
|
848
780
|
|
|
@@ -852,24 +784,13 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
852
784
|
metrics: ReadableArray,
|
|
853
785
|
promise: Promise
|
|
854
786
|
) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
"Connection not found (getUserProperties)"
|
|
860
|
-
)
|
|
861
|
-
|
|
862
|
-
val mTypes = metrics.toArrayList().mapNotNull {
|
|
863
|
-
MetricTypeUtils.fromValue(it as String)
|
|
864
|
-
}.toSet()
|
|
865
|
-
|
|
866
|
-
val result = connection.getUserProperties(types = mTypes)
|
|
867
|
-
|
|
868
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
787
|
+
executeV3MethodWithConnection("getUserProperties", connectionUUID, promise) { connection ->
|
|
788
|
+
val mTypes = metrics.toArrayList().mapNotNull {
|
|
789
|
+
MetricTypeUtils.fromValue(it as String)
|
|
790
|
+
}.toSet()
|
|
869
791
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
}
|
|
792
|
+
val result = connection.getUserProperties(types = mTypes)
|
|
793
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
873
794
|
}
|
|
874
795
|
}
|
|
875
796
|
|
|
@@ -878,126 +799,65 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
878
799
|
|
|
879
800
|
@ReactMethod
|
|
880
801
|
fun checkHealthConnectAvailability(connectionUUID: String, promise: Promise) {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
885
|
-
"Connection not found (checkHealthConnectAvailability)"
|
|
886
|
-
)
|
|
887
|
-
|
|
888
|
-
val result = connection.checkHealthConnectAvailability()
|
|
889
|
-
promise.resolve(result.value)
|
|
890
|
-
|
|
891
|
-
} catch (e: SpikeExceptions) {
|
|
892
|
-
promise.reject(e.mapException(), e.message)
|
|
893
|
-
}
|
|
802
|
+
executeV3MethodWithConnection("checkHealthConnectAvailability", connectionUUID, promise) { connection ->
|
|
803
|
+
val result = connection.checkHealthConnectAvailability()
|
|
804
|
+
promise.resolve(result.value)
|
|
894
805
|
}
|
|
895
806
|
}
|
|
896
807
|
|
|
897
808
|
@ReactMethod
|
|
898
809
|
fun openHealthConnectInstallation(connectionUUID: String, promise: Promise) {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
903
|
-
"Connection not found (openHealthConnectInstallation)"
|
|
904
|
-
)
|
|
905
|
-
|
|
906
|
-
connection.openHealthConnectInstallation()
|
|
907
|
-
promise.resolve(true)
|
|
908
|
-
|
|
909
|
-
} catch (e: SpikeExceptions) {
|
|
910
|
-
promise.reject(e.mapException(), e.message)
|
|
911
|
-
}
|
|
810
|
+
executeV3MethodWithConnection("openHealthConnectInstallation", connectionUUID, promise) { connection ->
|
|
811
|
+
connection.openHealthConnectInstallation()
|
|
812
|
+
promise.resolve(true)
|
|
912
813
|
}
|
|
913
814
|
}
|
|
914
815
|
|
|
915
816
|
@ReactMethod
|
|
916
817
|
fun enableHealthConnectIntegration(connectionUUID: String, promise: Promise) {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
"Connection not found (enableHealthConnectIntegration)"
|
|
922
|
-
)
|
|
923
|
-
|
|
924
|
-
connection.enableHealthConnectIntegration()
|
|
925
|
-
Log.d("SpikeSdkModule", "Health Connect integration enabled")
|
|
926
|
-
promise.resolve(true)
|
|
927
|
-
} catch (e: SpikeExceptions) {
|
|
928
|
-
promise.reject(e.mapException(), e.message)
|
|
929
|
-
}
|
|
818
|
+
executeV3MethodWithConnection("enableHealthConnectIntegration", connectionUUID, promise) { connection ->
|
|
819
|
+
connection.enableHealthConnectIntegration()
|
|
820
|
+
Log.d("SpikeSdkModule", "Health Connect integration enabled")
|
|
821
|
+
promise.resolve(true)
|
|
930
822
|
}
|
|
931
823
|
}
|
|
932
824
|
|
|
933
825
|
@ReactMethod
|
|
934
826
|
fun disableHealthConnectIntegration(connectionUUID: String, promise: Promise) {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
"Connection not found (enableHealthConnectIntegration)"
|
|
940
|
-
)
|
|
941
|
-
|
|
942
|
-
connection.disableHealthConnectIntegration()
|
|
943
|
-
Log.d("SpikeSdkModule", "Health Connect integration disabled")
|
|
944
|
-
promise.resolve(true)
|
|
945
|
-
|
|
946
|
-
} catch (e: SpikeExceptions) {
|
|
947
|
-
promise.reject(e.mapException(), e.message)
|
|
948
|
-
}
|
|
827
|
+
executeV3MethodWithConnection("disableHealthConnectIntegration", connectionUUID, promise) { connection ->
|
|
828
|
+
connection.disableHealthConnectIntegration()
|
|
829
|
+
Log.d("SpikeSdkModule", "Health Connect integration disabled")
|
|
830
|
+
promise.resolve(true)
|
|
949
831
|
}
|
|
950
832
|
}
|
|
951
833
|
|
|
952
834
|
@ReactMethod
|
|
953
835
|
fun isHealthConnectIntegrationEnabled(connectionUUID: String, promise: Promise) {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
"Connection not found (enableHealthConnectIntegration)"
|
|
959
|
-
)
|
|
960
|
-
|
|
961
|
-
val result = connection.isHealthConnectIntegrationEnabled()
|
|
962
|
-
Log.d("SpikeSdkModule", "Health Connect integration is " + if (result) { "enabled" } else ( "disabled" ))
|
|
963
|
-
promise.resolve(result)
|
|
964
|
-
|
|
965
|
-
} catch (e: SpikeExceptions) {
|
|
966
|
-
promise.reject(e.mapException(), e.message)
|
|
967
|
-
}
|
|
836
|
+
executeV3MethodWithConnection("isHealthConnectIntegrationEnabled", connectionUUID, promise) { connection ->
|
|
837
|
+
val result = connection.isHealthConnectIntegrationEnabled()
|
|
838
|
+
Log.d("SpikeSdkModule", "Health Connect integration is " + if (result) { "enabled" } else ( "disabled" ))
|
|
839
|
+
promise.resolve(result)
|
|
968
840
|
}
|
|
969
841
|
}
|
|
970
842
|
|
|
971
843
|
@ReactMethod
|
|
972
844
|
fun getGrantedHealthConnectPermissions(connectionUUID: String, promise: Promise) {
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
"Connection not found (getGrantedHealthConnectPermissions)"
|
|
978
|
-
)
|
|
979
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
980
|
-
return@launch promise.reject(
|
|
981
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
982
|
-
"Health Connect should be enabled before calling getGrantedHealthConnectPermissions"
|
|
983
|
-
)
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
val permissions = connection
|
|
987
|
-
.getHealthConnectPermissionManager()
|
|
988
|
-
.getGrantedPermissions()
|
|
845
|
+
executeV3MethodWithConnection("getGrantedHealthConnectPermissions", connectionUUID, promise) { connection ->
|
|
846
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
847
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling getGrantedHealthConnectPermissions")
|
|
848
|
+
}
|
|
989
849
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
Log.w("SpikeSdkModule", "$permissions")
|
|
996
|
-
promise.resolve(result)
|
|
850
|
+
val permissions = connection
|
|
851
|
+
.getHealthConnectPermissionManager()
|
|
852
|
+
.getGrantedPermissions()
|
|
997
853
|
|
|
998
|
-
|
|
999
|
-
|
|
854
|
+
val result = Arguments.createArray()
|
|
855
|
+
permissions.forEach {
|
|
856
|
+
result.pushString(it)
|
|
1000
857
|
}
|
|
858
|
+
|
|
859
|
+
Log.w("SpikeSdkModule", "$permissions")
|
|
860
|
+
promise.resolve(result)
|
|
1001
861
|
}
|
|
1002
862
|
}
|
|
1003
863
|
|
|
@@ -1012,122 +872,85 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1012
872
|
includeBackgroundDelivery: Boolean,
|
|
1013
873
|
promise: Promise
|
|
1014
874
|
) {
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
875
|
+
executeV3MethodWithConnection("getHealthConnectPermissions", connectionUUID, promise) { connection ->
|
|
876
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
877
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling getHealthConnectPermissionsForStatisticTypes")
|
|
878
|
+
}
|
|
879
|
+
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
880
|
+
|
|
881
|
+
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
882
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
883
|
+
}.toSet()
|
|
884
|
+
|
|
885
|
+
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
886
|
+
MetricTypeUtils.fromValue(it as String)
|
|
887
|
+
}.toSet()
|
|
888
|
+
|
|
889
|
+
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
890
|
+
ActivityConfigUtils.fromValue(it as String)
|
|
891
|
+
}.toSet()
|
|
892
|
+
|
|
893
|
+
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
894
|
+
SleepConfigUtils.fromValue(it as String)
|
|
895
|
+
}.toSet()
|
|
896
|
+
|
|
897
|
+
val permissions = permissionManager
|
|
898
|
+
.getPermissions(
|
|
899
|
+
statisticsTypes = statTypes,
|
|
900
|
+
metricTypes = mTypes,
|
|
901
|
+
activityConfigs = aConfigs,
|
|
902
|
+
sleepConfigs = sConfigs,
|
|
903
|
+
includeEnhancedPermissions = includeEnhancedPermissions,
|
|
904
|
+
includeBackgroundDelivery = includeBackgroundDelivery
|
|
1020
905
|
)
|
|
1021
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1022
|
-
return@launch promise.reject(
|
|
1023
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1024
|
-
"Health Connect should be enabled before calling getHealthConnectPermissionsForStatisticTypes"
|
|
1025
|
-
)
|
|
1026
|
-
}
|
|
1027
|
-
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1028
|
-
|
|
1029
|
-
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1030
|
-
StatisticsTypeUtils.fromValue(it as String)
|
|
1031
|
-
}.toSet()
|
|
1032
|
-
|
|
1033
|
-
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
1034
|
-
MetricTypeUtils.fromValue(it as String)
|
|
1035
|
-
}.toSet()
|
|
1036
|
-
|
|
1037
|
-
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
1038
|
-
ActivityConfigUtils.fromValue(it as String)
|
|
1039
|
-
}.toSet()
|
|
1040
|
-
|
|
1041
|
-
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
1042
|
-
SleepConfigUtils.fromValue(it as String)
|
|
1043
|
-
}.toSet()
|
|
1044
|
-
|
|
1045
|
-
val permissions = permissionManager
|
|
1046
|
-
.getPermissions(
|
|
1047
|
-
statisticsTypes = statTypes,
|
|
1048
|
-
metricTypes = mTypes,
|
|
1049
|
-
activityConfigs = aConfigs,
|
|
1050
|
-
sleepConfigs = sConfigs,
|
|
1051
|
-
includeEnhancedPermissions = includeEnhancedPermissions,
|
|
1052
|
-
includeBackgroundDelivery = includeBackgroundDelivery
|
|
1053
|
-
)
|
|
1054
906
|
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
// Log.w("SpikeSdkModule", "$permissions")
|
|
1061
|
-
promise.resolve(result)
|
|
1062
|
-
|
|
1063
|
-
} catch (e: SpikeExceptions) {
|
|
1064
|
-
promise.reject(e.mapException(), e.message)
|
|
907
|
+
val result = Arguments.createArray()
|
|
908
|
+
permissions.forEach {
|
|
909
|
+
result.pushString(it)
|
|
1065
910
|
}
|
|
911
|
+
|
|
912
|
+
// Log.w("SpikeSdkModule", "$permissions")
|
|
913
|
+
promise.resolve(result)
|
|
1066
914
|
}
|
|
1067
915
|
}
|
|
1068
916
|
|
|
1069
917
|
@ReactMethod
|
|
1070
918
|
fun revokeAllHealthConnectPermissions(connectionUUID: String, promise: Promise) {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
1075
|
-
"Connection not found (revokeAllHealthConnectPermissions)"
|
|
1076
|
-
)
|
|
1077
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1078
|
-
return@launch promise.reject(
|
|
1079
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1080
|
-
"Health Connect should be enabled before calling revokeAllHealthConnectPermissions"
|
|
1081
|
-
)
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
connection
|
|
1085
|
-
.getHealthConnectPermissionManager()
|
|
1086
|
-
.revokeAllPermissions()
|
|
1087
|
-
|
|
1088
|
-
promise.resolve(true)
|
|
1089
|
-
|
|
1090
|
-
} catch (e: SpikeExceptions) {
|
|
1091
|
-
promise.reject(e.mapException(), e.message)
|
|
919
|
+
executeV3MethodWithConnection("revokeAllHealthConnectPermissions", connectionUUID, promise) { connection ->
|
|
920
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
921
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling revokeAllHealthConnectPermissions")
|
|
1092
922
|
}
|
|
923
|
+
|
|
924
|
+
connection
|
|
925
|
+
.getHealthConnectPermissionManager()
|
|
926
|
+
.revokeAllPermissions()
|
|
927
|
+
|
|
928
|
+
promise.resolve(true)
|
|
1093
929
|
}
|
|
1094
930
|
}
|
|
1095
931
|
|
|
1096
932
|
@ReactMethod
|
|
1097
933
|
fun requestPermissionsFromHealthConnect(connectionUUID: String, permissions: ReadableArray, promise: Promise) {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
"Connection not found"
|
|
1103
|
-
).mapException(), "Connection not found"
|
|
1104
|
-
)
|
|
1105
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1106
|
-
return@launch promise.reject(
|
|
1107
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1108
|
-
"Health Connect should be enabled before calling requestPermissionsFromHealthConnect"
|
|
1109
|
-
)
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1113
|
-
val permissionsStrings = permissions.toArrayList().map{ it as String }.toSet()
|
|
934
|
+
executeV3MethodWithConnection("requestPermissionsFromHealthConnect", connectionUUID, promise) { connection ->
|
|
935
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
936
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling requestPermissionsFromHealthConnect")
|
|
937
|
+
}
|
|
1114
938
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
promise.resolve(true)
|
|
1118
|
-
return@launch
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
Log.d("SpikeSdkModule", "Will ask for following Health Connect permissions: $permissions")
|
|
939
|
+
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
940
|
+
val permissionsStrings = permissions.toArrayList().map{ it as String }.toSet()
|
|
1122
941
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
942
|
+
if (checkIfAllPermissionsAreGranted(permissionManager, permissionsStrings)) {
|
|
943
|
+
// All permissions granted, nothing to do here
|
|
944
|
+
promise.resolve(true)
|
|
945
|
+
return@executeV3MethodWithConnection
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
Log.d("SpikeSdkModule", "Will ask for following Health Connect permissions: $permissions")
|
|
1128
949
|
|
|
1129
|
-
|
|
1130
|
-
|
|
950
|
+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) {
|
|
951
|
+
startHealthConnectRequest_oldAndroid(connectionUUID, permissionManager, permissionsStrings, promise)
|
|
952
|
+
} else {
|
|
953
|
+
startHealthConnectRequest(connectionUUID, permissionManager, permissionsStrings, promise)
|
|
1131
954
|
}
|
|
1132
955
|
}
|
|
1133
956
|
}
|
|
@@ -1176,27 +999,14 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1176
999
|
}
|
|
1177
1000
|
|
|
1178
1001
|
fun areAllPermissionsGranted(connectionUUID: String, permissions: Set<String>, promise: Promise) {
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
SpikeExceptions.SpikeException(
|
|
1183
|
-
"Connection not found"
|
|
1184
|
-
).mapException(), "Connection not found"
|
|
1185
|
-
)
|
|
1186
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1187
|
-
return@launch promise.reject(
|
|
1188
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1189
|
-
"Health Connect should be enabled before calling areAllPermissionsGranted"
|
|
1190
|
-
)
|
|
1191
|
-
}
|
|
1192
|
-
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1193
|
-
|
|
1194
|
-
val permissionsGranted: Boolean = checkIfAllPermissionsAreGranted(permissionManager, permissions)
|
|
1195
|
-
promise.resolve(permissionsGranted)
|
|
1196
|
-
|
|
1197
|
-
} catch (e: SpikeExceptions) {
|
|
1198
|
-
promise.reject(e.mapException(), e.message)
|
|
1002
|
+
executeV3MethodWithConnection("areAllPermissionsGranted", connectionUUID, promise) { connection ->
|
|
1003
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1004
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling areAllPermissionsGranted")
|
|
1199
1005
|
}
|
|
1006
|
+
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1007
|
+
|
|
1008
|
+
val permissionsGranted: Boolean = checkIfAllPermissionsAreGranted(permissionManager, permissions)
|
|
1009
|
+
promise.resolve(permissionsGranted)
|
|
1200
1010
|
}
|
|
1201
1011
|
}
|
|
1202
1012
|
|
|
@@ -1215,47 +1025,35 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1215
1025
|
sleepConfigs: ReadableArray,
|
|
1216
1026
|
promise: Promise
|
|
1217
1027
|
) {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
"Connection not found (enableBackgroundDelivery)"
|
|
1223
|
-
)
|
|
1224
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1225
|
-
return@launch promise.reject(
|
|
1226
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1227
|
-
"Health Connect should be enabled before calling enableBackgroundDelivery"
|
|
1228
|
-
)
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1232
|
-
StatisticsTypeUtils.fromValue(it as String)
|
|
1233
|
-
}.toSet()
|
|
1028
|
+
executeV3MethodWithConnection("enableBackgroundDelivery", connectionUUID, promise) { connection ->
|
|
1029
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1030
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling enableBackgroundDelivery")
|
|
1031
|
+
}
|
|
1234
1032
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1033
|
+
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1034
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
1035
|
+
}.toSet()
|
|
1238
1036
|
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1037
|
+
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
1038
|
+
MetricTypeUtils.fromValue(it as String)
|
|
1039
|
+
}.toSet()
|
|
1242
1040
|
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1041
|
+
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
1042
|
+
ActivityConfigUtils.fromValue(it as String)
|
|
1043
|
+
}.toSet()
|
|
1246
1044
|
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
activityConfigs = aConfigs,
|
|
1251
|
-
sleepConfigs = sConfigs
|
|
1252
|
-
)
|
|
1045
|
+
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
1046
|
+
SleepConfigUtils.fromValue(it as String)
|
|
1047
|
+
}.toSet()
|
|
1253
1048
|
|
|
1254
|
-
|
|
1049
|
+
connection.enableBackgroundDelivery(
|
|
1050
|
+
statisticsTypes = statTypes,
|
|
1051
|
+
metricTypes = mTypes,
|
|
1052
|
+
activityConfigs = aConfigs,
|
|
1053
|
+
sleepConfigs = sConfigs
|
|
1054
|
+
)
|
|
1255
1055
|
|
|
1256
|
-
|
|
1257
|
-
promise.reject(e.mapException(), e.message)
|
|
1258
|
-
}
|
|
1056
|
+
promise.resolve(true)
|
|
1259
1057
|
}
|
|
1260
1058
|
}
|
|
1261
1059
|
|
|
@@ -1264,24 +1062,12 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1264
1062
|
connectionUUID: String,
|
|
1265
1063
|
promise: Promise
|
|
1266
1064
|
) {
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
1271
|
-
"Connection not found (disableBackgroundDelivery)"
|
|
1272
|
-
)
|
|
1273
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1274
|
-
return@launch promise.reject(
|
|
1275
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1276
|
-
"Health Connect should be enabled before calling disableBackgroundDelivery"
|
|
1277
|
-
)
|
|
1278
|
-
}
|
|
1279
|
-
connection.disableBackgroundDelivery()
|
|
1280
|
-
promise.resolve(true)
|
|
1281
|
-
|
|
1282
|
-
} catch (e: SpikeExceptions) {
|
|
1283
|
-
promise.reject(e.mapException(), e.message)
|
|
1065
|
+
executeV3MethodWithConnection("disableBackgroundDelivery", connectionUUID, promise) { connection ->
|
|
1066
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1067
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling disableBackgroundDelivery")
|
|
1284
1068
|
}
|
|
1069
|
+
connection.disableBackgroundDelivery()
|
|
1070
|
+
promise.resolve(true)
|
|
1285
1071
|
}
|
|
1286
1072
|
}
|
|
1287
1073
|
|
|
@@ -1290,27 +1076,15 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1290
1076
|
connectionUUID: String,
|
|
1291
1077
|
promise: Promise
|
|
1292
1078
|
) {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
"Health Connect should be enabled before calling getBackgroundDeliveryConfig"
|
|
1303
|
-
)
|
|
1304
|
-
}
|
|
1305
|
-
val result = connection.getBackgroundDeliveryConfig()
|
|
1306
|
-
if (result == null) {
|
|
1307
|
-
promise.resolve(null)
|
|
1308
|
-
} else {
|
|
1309
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
} catch (e: SpikeExceptions) {
|
|
1313
|
-
promise.reject(e.mapException(), e.message)
|
|
1079
|
+
executeV3MethodWithConnection("getBackgroundDeliveryConfig", connectionUUID, promise) { connection ->
|
|
1080
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1081
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling getBackgroundDeliveryConfig")
|
|
1082
|
+
}
|
|
1083
|
+
val result = connection.getBackgroundDeliveryConfig()
|
|
1084
|
+
if (result == null) {
|
|
1085
|
+
promise.resolve(null)
|
|
1086
|
+
} else {
|
|
1087
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
1314
1088
|
}
|
|
1315
1089
|
}
|
|
1316
1090
|
}
|
|
@@ -1336,6 +1110,44 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1336
1110
|
}
|
|
1337
1111
|
}
|
|
1338
1112
|
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Centralized error handling for V3 methods
|
|
1116
|
+
* Executes the provided block in a coroutine scope with comprehensive error handling
|
|
1117
|
+
*/
|
|
1118
|
+
private fun executeV3Method(
|
|
1119
|
+
promise: Promise,
|
|
1120
|
+
block: suspend () -> Unit
|
|
1121
|
+
) {
|
|
1122
|
+
scope.launch {
|
|
1123
|
+
try {
|
|
1124
|
+
block()
|
|
1125
|
+
} catch (e: SpikeExceptions) {
|
|
1126
|
+
promise.reject(e.mapException(), e.message)
|
|
1127
|
+
} catch (e: Exception) {
|
|
1128
|
+
promise.reject(e.toString(), e.message)
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Centralized error handling for V3 methods that need connection validation
|
|
1135
|
+
* Executes the provided block in a coroutine scope with connection validation and comprehensive error handling
|
|
1136
|
+
*/
|
|
1137
|
+
private fun executeV3MethodWithConnection(
|
|
1138
|
+
methodName: String,
|
|
1139
|
+
connectionUUID: String,
|
|
1140
|
+
promise: Promise,
|
|
1141
|
+
block: suspend (SpikeConnectionAPIv3) -> Unit
|
|
1142
|
+
) {
|
|
1143
|
+
executeV3Method(promise) {
|
|
1144
|
+
val connection = getConnectionV3(connectionUUID) ?: throw SpikeExceptions.SpikeException(
|
|
1145
|
+
"Connection not found ($methodName)"
|
|
1146
|
+
)
|
|
1147
|
+
block(connection)
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1339
1151
|
}
|
|
1340
1152
|
|
|
1341
1153
|
private fun convertIsoStringToInstant(isoString: String): Instant {
|
package/lib/commonjs/version.js
CHANGED
|
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.SPIKE_SDK_VERSION = void 0;
|
|
7
7
|
// This file is auto-generated. Do not edit manually.
|
|
8
|
-
const SPIKE_SDK_VERSION = exports.SPIKE_SDK_VERSION = "4.3.
|
|
8
|
+
const SPIKE_SDK_VERSION = exports.SPIKE_SDK_VERSION = "4.3.53";
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
package/lib/module/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SPIKE_SDK_VERSION = "4.3.
|
|
1
|
+
export declare const SPIKE_SDK_VERSION = "4.3.53";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
package/src/version.ts
CHANGED