@tryterra/react-native 2.2.1 → 2.3.1
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 +68 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/BridgeBootstrap.kt +14 -1
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/Conversions.kt +35 -2
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/Rejections.kt +3 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/TerraBridgeOpsImpl.kt +33 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/generated/BridgeErrors.kt +12 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/generated/BridgeOps.kt +47 -0
- package/android/src/bridgeCore/kotlin/co/tryterra/sdk/bridge/generated/BridgeTypes.kt +348 -0
- package/docs/availability.md +111 -1
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Info.plist +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.abi.json +21646 -9224
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.package.swiftinterface +351 -14
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +351 -14
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios.swiftinterface +339 -13
- package/frameworks/TerraSDK.xcframework/ios-arm64/TerraSDK.framework/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/dSYMs/TerraSDK.framework.dSYM/Contents/Info.plist +2 -2
- package/frameworks/TerraSDK.xcframework/ios-arm64/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/DWARF/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/TerraSDK.yml +7449 -6589
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Info.plist +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +21646 -9224
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.package.swiftinterface +351 -14
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +351 -14
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +339 -13
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +21646 -9224
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.package.swiftinterface +351 -14
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +351 -14
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/Modules/TerraSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +339 -13
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/TerraSDK.framework/_CodeSignature/CodeResources +21 -21
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Info.plist +2 -2
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/DWARF/TerraSDK +0 -0
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/TerraSDK.yml +7450 -6590
- package/frameworks/TerraSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/TerraSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/TerraSDK.yml +7359 -6508
- package/ios/TerraBridgeCore/BridgeBootstrap.swift +13 -3
- package/ios/TerraBridgeCore/Conversions.swift +36 -1
- package/ios/TerraBridgeCore/Generated/BridgeErrors.swift +15 -0
- package/ios/TerraBridgeCore/Generated/BridgeOps.swift +82 -0
- package/ios/TerraBridgeCore/Generated/BridgeTypes.swift +252 -3
- package/ios/TerraBridgeCore/Rejections.swift +5 -1
- package/ios/TerraBridgeCore/TerraBridgeOpsImpl.swift +32 -1
- package/lib/Terra.d.ts +47 -1
- package/lib/Terra.js +16 -0
- package/lib/generated/client.d.ts +33 -1
- package/lib/generated/client.js +42 -0
- package/lib/generated/codecs.d.ts +15 -1
- package/lib/generated/codecs.js +119 -5
- package/lib/generated/errors.d.ts +1 -1
- package/lib/generated/errors.js +6 -1
- package/lib/generated/ops.d.ts +1 -1
- package/lib/generated/ops.js +12 -0
- package/lib/generated/types.d.ts +70 -2
- package/lib/generated/types.js +101 -1
- package/lib/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/Terra.ts +64 -0
- package/src/generated/client.ts +49 -2
- package/src/generated/codecs.ts +112 -6
- package/src/generated/errors.ts +11 -1
- package/src/generated/ops.ts +17 -0
- package/src/generated/types.ts +274 -1
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -18,6 +18,32 @@ There is no sync call: once connected, the SDK uploads on its own, in the backgr
|
|
|
18
18
|
rejection is a `TerraError` with a stable `code` (see `docs/availability.md` for the full list and
|
|
19
19
|
what exists on which platform).
|
|
20
20
|
|
|
21
|
+
## Asking for specific types
|
|
22
|
+
|
|
23
|
+
A category asks for everything behind it: `body` is blood glucose, blood pressure and temperature as
|
|
24
|
+
well as weight. An app whose consent screen and `NSHealthShareUsageDescription` name specific data
|
|
25
|
+
asks for exactly that, as Terra Grip does for the 22 types it discloses:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
await terra.permissions.request({
|
|
29
|
+
readTypes: [
|
|
30
|
+
"workouts", "steps", "activeEnergy", "exerciseTime", "distance", "floorsClimbed",
|
|
31
|
+
"heartRate", "restingHeartRate", "heartRateVariability", "vo2Max", "sleepAnalysis",
|
|
32
|
+
"weight", "height", "bmi", "bodyFat",
|
|
33
|
+
"dietaryEnergyConsumed", "dietaryWater", "dietaryProtein", "dietaryCarbohydrates",
|
|
34
|
+
"dietaryFatTotal", "dietarySugar", "menstrualFlow",
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
const status = await terra.permissions.typeStatus("heartRate");
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The sheet names exactly those types, and from then on the SDK reads and uploads nothing else. iOS
|
|
41
|
+
answers `typeStatus` with `notDisclosed`, because HealthKit never reports a read decision; Android
|
|
42
|
+
answers `granted` once any permission behind the type is (`workouts` once exercise is). `exerciseTime` and `bmi` are HealthKit
|
|
43
|
+
only, so on Android pass the list less them: a type a platform has no store type for rejects with
|
|
44
|
+
`bridge.unsupported_on_platform` and nothing is recorded. `docs/sdk-reference.md` lists every type
|
|
45
|
+
with the HealthKit and Health Connect types behind it.
|
|
46
|
+
|
|
21
47
|
## Local reads
|
|
22
48
|
|
|
23
49
|
Every read goes straight to the device's store and never touches the network:
|
|
@@ -69,6 +95,18 @@ needs it then. Both platforms read the dev id from native configuration.
|
|
|
69
95
|
```
|
|
70
96
|
|
|
71
97
|
Without it every call rejects with `bridge.not_bootstrapped`, and `details.line` names the line.
|
|
98
|
+
4. Health Records (opt-in). Only if the app reads them:
|
|
99
|
+
- add `health-records` to the `com.apple.developer.healthkit.access` array;
|
|
100
|
+
- add both `NSHealthShareUsageDescription` and `NSHealthClinicalHealthRecordsShareUsageDescription`
|
|
101
|
+
to `Info.plist`;
|
|
102
|
+
- enable `CLINICAL_RECORD` for the Terra client in Terra's dashboard, or Terra refuses every
|
|
103
|
+
upload with `data_type_not_enabled`;
|
|
104
|
+
- ask on HealthKit's own sheet. The method is absent on Android, and `permissions.request`
|
|
105
|
+
ignores `clinicalRecord`:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
await terra.permissions.requestClinicalRecords?.();
|
|
109
|
+
```
|
|
72
110
|
|
|
73
111
|
### Android
|
|
74
112
|
|
|
@@ -80,6 +118,36 @@ needs it then. Both platforms read the dev id from native configuration.
|
|
|
80
118
|
3. One `<uses-permission android:name="android.permission.health.*">` per Health Connect type your
|
|
81
119
|
`permissions.request` reads, plus the permissions-rationale activity filters. `example/` has a
|
|
82
120
|
complete manifest.
|
|
121
|
+
4. Multi-dev-id mode (connector apps only). Only if several customers link the same person through
|
|
122
|
+
this app with `terra.linkedDevIds`: in `<application>`, beside the dev id,
|
|
123
|
+
|
|
124
|
+
```xml
|
|
125
|
+
<meta-data android:name="co.tryterra.sdk.DEV_ID_MODE" android:value="multiple" />
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Absent, or any other value, is single mode, and `linkedDevIds` rejects with `dev_id_mismatch`.
|
|
129
|
+
`client.attach` reports the mode the native client was built in as `devIdMode`. On iOS the same
|
|
130
|
+
switch is `TerraDevIDMode` set to `multiple` in `Info.plist`.
|
|
131
|
+
|
|
132
|
+
An Expo app, whose manifest is generated, sets both meta-data entries from a config plugin:
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
// plugins/withTerraManifest.js
|
|
136
|
+
const { withAndroidManifest, AndroidConfig } = require("@expo/config-plugins");
|
|
137
|
+
|
|
138
|
+
module.exports = function withTerraManifest(config, { devId, devIdMode = "single" }) {
|
|
139
|
+
return withAndroidManifest(config, (mod) => {
|
|
140
|
+
const app = AndroidConfig.Manifest.getMainApplicationOrThrow(mod.modResults);
|
|
141
|
+
AndroidConfig.Manifest.addMetaDataItemToMainApplication(app, "co.tryterra.sdk.DEV_ID", devId);
|
|
142
|
+
AndroidConfig.Manifest.addMetaDataItemToMainApplication(app, "co.tryterra.sdk.DEV_ID_MODE", devIdMode);
|
|
143
|
+
return mod;
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{ "expo": { "plugins": [["./plugins/withTerraManifest", { "devId": "your-dev-id", "devIdMode": "multiple" }]] } }
|
|
150
|
+
```
|
|
83
151
|
|
|
84
152
|
### Samsung Health (Android, optional)
|
|
85
153
|
|
|
@@ -7,6 +7,7 @@ import android.content.pm.PackageManager
|
|
|
7
7
|
import android.os.Bundle
|
|
8
8
|
import android.util.Log
|
|
9
9
|
import androidx.activity.result.ActivityResultCaller
|
|
10
|
+
import co.tryterra.sdk.DevIdMode
|
|
10
11
|
import co.tryterra.sdk.SDK_VERSION
|
|
11
12
|
import co.tryterra.sdk.Source
|
|
12
13
|
import co.tryterra.sdk.StoreRegistration
|
|
@@ -23,6 +24,13 @@ public object BridgeBootstrap {
|
|
|
23
24
|
/** The manifest meta-data carrying the developer id. */
|
|
24
25
|
public const val DEV_ID_KEY: String = "co.tryterra.sdk.DEV_ID"
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The manifest meta-data choosing `DevIdMode.MULTIPLE`: the string `multiple`. Absent, or
|
|
29
|
+
* anything else, is single mode - every integration but a connector app several customers link
|
|
30
|
+
* through. The twin of Apple's `TerraDevIDMode` Info.plist key.
|
|
31
|
+
*/
|
|
32
|
+
public const val DEV_ID_MODE_KEY: String = "co.tryterra.sdk.DEV_ID_MODE"
|
|
33
|
+
|
|
26
34
|
private const val TAG = "TerraBridge"
|
|
27
35
|
|
|
28
36
|
/** What bootstrap parked: the client, and the broker the client was built with. */
|
|
@@ -49,7 +57,8 @@ public object BridgeBootstrap {
|
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
val tokens = TokenBroker()
|
|
52
|
-
val
|
|
60
|
+
val mode = devIdMode(meta?.getString(DEV_ID_MODE_KEY))
|
|
61
|
+
val terra = Terra(app, devId, tokenProvider = tokens::provide, devIdMode = mode, stores = stores)
|
|
53
62
|
val launchers = Launchers(terra, servedSources(terra))
|
|
54
63
|
app.registerActivityLifecycleCallbacks(launchers)
|
|
55
64
|
val registered = BackgroundSync.register(app, terra)
|
|
@@ -64,6 +73,10 @@ public object BridgeBootstrap {
|
|
|
64
73
|
return TerraBridge(current.terra, current.tokens, current.host, scope, emit = emit)
|
|
65
74
|
}
|
|
66
75
|
|
|
76
|
+
/** The mode a manifest value names: `multiple`, trimmed, is multiple and anything else single. */
|
|
77
|
+
internal fun devIdMode(value: String?): DevIdMode =
|
|
78
|
+
if (value?.trim() == "multiple") DevIdMode.MULTIPLE else DevIdMode.SINGLE
|
|
79
|
+
|
|
67
80
|
private fun metaData(app: Application): Bundle? = try {
|
|
68
81
|
app.packageManager.getApplicationInfo(app.packageName, PackageManager.GET_META_DATA).metaData
|
|
69
82
|
} catch (missing: PackageManager.NameNotFoundException) {
|
|
@@ -33,6 +33,7 @@ import co.tryterra.sdk.diagnostics.DiagnosticsState
|
|
|
33
33
|
import co.tryterra.sdk.diagnostics.DiagnosticsWire
|
|
34
34
|
import co.tryterra.sdk.diagnostics.SupportReport
|
|
35
35
|
import co.tryterra.sdk.diagnostics.TerraEvent
|
|
36
|
+
import co.tryterra.sdk.HealthDataType
|
|
36
37
|
import co.tryterra.sdk.health.HealthAccess
|
|
37
38
|
import co.tryterra.sdk.HealthChange
|
|
38
39
|
import co.tryterra.sdk.store.StoredConnection
|
|
@@ -51,6 +52,7 @@ import co.tryterra.sdk.bridge.generated.Nutrient as WireNutrient
|
|
|
51
52
|
import co.tryterra.sdk.bridge.generated.DiagnosticsState as WireDiagnosticsState
|
|
52
53
|
import co.tryterra.sdk.bridge.generated.EndUser as WireEndUser
|
|
53
54
|
import co.tryterra.sdk.bridge.generated.HealthAccess as WireHealthAccess
|
|
55
|
+
import co.tryterra.sdk.bridge.generated.HealthDataType as WireHealthDataType
|
|
54
56
|
import co.tryterra.sdk.bridge.generated.HealthChange as WireHealthChange
|
|
55
57
|
import co.tryterra.sdk.bridge.generated.HeartRateEntry as WireHeartRateEntry
|
|
56
58
|
import co.tryterra.sdk.bridge.generated.HeartRateSample as WireHeartRateSample
|
|
@@ -87,6 +89,16 @@ internal object Conversions {
|
|
|
87
89
|
|
|
88
90
|
// ---- enums ------------------------------------------------------------------------------
|
|
89
91
|
|
|
92
|
+
/** One customer's binding, as the wrapper reads it: `active` is whether Terra still delivers to it. */
|
|
93
|
+
fun devIdBinding(binding: co.tryterra.sdk.store.DevIdBinding): co.tryterra.sdk.bridge.generated.DevIdBinding =
|
|
94
|
+
co.tryterra.sdk.bridge.generated.DevIdBinding(
|
|
95
|
+
devId = binding.devId,
|
|
96
|
+
userId = binding.userId,
|
|
97
|
+
dataTypes = binding.dataTypes?.map { it.wire },
|
|
98
|
+
linkedAt = BridgeInstant.format(binding.linkedAt),
|
|
99
|
+
active = binding.isActive,
|
|
100
|
+
)
|
|
101
|
+
|
|
90
102
|
fun source(wire: WireSource): Source = when (wire) {
|
|
91
103
|
WireSource.HEALTH -> Source.HEALTH
|
|
92
104
|
WireSource.SAMSUNG_HEALTH -> Source.SAMSUNG_HEALTH
|
|
@@ -98,8 +110,9 @@ internal object Conversions {
|
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
/**
|
|
101
|
-
* `ATHLETE` is HealthKit's characteristics and
|
|
102
|
-
*
|
|
113
|
+
* `ATHLETE` is HealthKit's characteristics and `CLINICAL_RECORD` is Apple Health Records; neither
|
|
114
|
+
* has a Health Connect counterpart, so a request naming one is refused as this platform lacking
|
|
115
|
+
* it rather than quietly dropped from the sheet.
|
|
103
116
|
*/
|
|
104
117
|
fun category(wire: WireCategory): DataCategory = when (wire) {
|
|
105
118
|
WireCategory.ACTIVITY -> DataCategory.ACTIVITY
|
|
@@ -109,6 +122,7 @@ internal object Conversions {
|
|
|
109
122
|
WireCategory.NUTRITION -> DataCategory.NUTRITION
|
|
110
123
|
WireCategory.MENSTRUATION -> DataCategory.MENSTRUATION
|
|
111
124
|
WireCategory.ATHLETE -> throw BridgeError.UnsupportedOnPlatform("athlete")
|
|
125
|
+
WireCategory.CLINICAL_RECORD -> throw BridgeError.UnsupportedOnPlatform("clinicalRecord")
|
|
112
126
|
}
|
|
113
127
|
|
|
114
128
|
fun category(category: DataCategory): WireCategory = when (category) {
|
|
@@ -403,6 +417,10 @@ internal object Conversions {
|
|
|
403
417
|
fun access(access: HealthAccess): WireHealthAccess = WireHealthAccess(
|
|
404
418
|
read = access.read.map(::category).sortedBy { it.name },
|
|
405
419
|
write = access.write.map(::category).sortedBy { it.name },
|
|
420
|
+
// Absent for an install that asked only by category, so its record keeps the shape it had
|
|
421
|
+
// before types existed; sorted by wire name, since the field is not a codec set.
|
|
422
|
+
readTypes = access.readTypes.takeIf { it.isNotEmpty() }
|
|
423
|
+
?.map(::dataType)?.sortedBy { it.wireName() },
|
|
406
424
|
workouts = access.workouts
|
|
407
425
|
.groupBy { WorkoutActivity.reportName(it.activity) }
|
|
408
426
|
.toSortedMap()
|
|
@@ -415,6 +433,21 @@ internal object Conversions {
|
|
|
415
433
|
},
|
|
416
434
|
)
|
|
417
435
|
|
|
436
|
+
/**
|
|
437
|
+
* The SDK type behind a wire one, matched by enum name: both enums name a type after its wire
|
|
438
|
+
* spelling in screaming snake case. An iOS-only type has no Health Connect record and is
|
|
439
|
+
* refused as `unsupported_on_platform`, naming the type, as `athlete` is.
|
|
440
|
+
*/
|
|
441
|
+
fun dataType(wire: WireHealthDataType): HealthDataType =
|
|
442
|
+
HealthDataType.entries.firstOrNull { it.name == wire.name }
|
|
443
|
+
?: throw BridgeError.UnsupportedOnPlatform(wire.wireName())
|
|
444
|
+
|
|
445
|
+
fun dataType(type: HealthDataType): WireHealthDataType = WireHealthDataType.valueOf(type.name)
|
|
446
|
+
|
|
447
|
+
/** The wire spelling, read from the generated codec so it cannot disagree with it. */
|
|
448
|
+
fun WireHealthDataType.wireName(): String =
|
|
449
|
+
WireHealthDataType.serializer().descriptor.getElementName(ordinal)
|
|
450
|
+
|
|
418
451
|
fun scope(scope: WorkoutScope): WireWorkoutScope = WireWorkoutScope(
|
|
419
452
|
activity = activity(scope.activity),
|
|
420
453
|
energy = scope.energy,
|
|
@@ -88,6 +88,8 @@ internal object Rejections {
|
|
|
88
88
|
is TerraError.SyncAlreadyRunning -> obj("dataType" to JsonPrimitive(error.dataType.wire))
|
|
89
89
|
is TerraError.SampleNotFound -> obj("id" to JsonPrimitive(error.id.value))
|
|
90
90
|
is TerraError.DeviceKeyUnavailable -> obj("reason" to JsonPrimitive(error.reason))
|
|
91
|
+
// One of four fixed server codes, so it names nobody.
|
|
92
|
+
is TerraError.LinkRefused -> obj("reason" to JsonPrimitive(error.reason))
|
|
91
93
|
// The cause travels as a code: a nested throwable carries a stack and a message.
|
|
92
94
|
is TerraError.RollbackIncomplete -> obj(
|
|
93
95
|
"remaining" to JsonPrimitive(error.remaining.size),
|
|
@@ -96,6 +98,7 @@ internal object Rejections {
|
|
|
96
98
|
is TerraError.DistanceNotAttributable -> obj(
|
|
97
99
|
"activity" to JsonPrimitive(co.tryterra.sdk.WorkoutActivity.reportName(error.activity)),
|
|
98
100
|
)
|
|
101
|
+
is TerraError.WorkoutsRequired -> obj("type" to JsonPrimitive(error.type.wire))
|
|
99
102
|
// No message. The host's own provider threw, and the text it chose is as likely to contain
|
|
100
103
|
// the token it was minting as it is to describe the failure - `IllegalStateException(
|
|
101
104
|
// "token=...")` is not a hypothetical. The host already knows why its provider failed; what
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package co.tryterra.sdk.bridge
|
|
2
2
|
|
|
3
|
+
import co.tryterra.sdk.DevIdMode
|
|
3
4
|
import co.tryterra.sdk.RecordId
|
|
4
5
|
import co.tryterra.sdk.Source
|
|
5
6
|
import co.tryterra.sdk.Terra
|
|
@@ -8,10 +9,16 @@ import co.tryterra.sdk.bridge.generated.BootstrapState
|
|
|
8
9
|
import co.tryterra.sdk.bridge.generated.BridgeError
|
|
9
10
|
import co.tryterra.sdk.bridge.generated.BridgeInstant
|
|
10
11
|
import co.tryterra.sdk.bridge.generated.CategoryRequest
|
|
12
|
+
import co.tryterra.sdk.bridge.generated.DataTypeRequest
|
|
11
13
|
import co.tryterra.sdk.bridge.generated.Connection
|
|
12
14
|
import co.tryterra.sdk.bridge.generated.ConnectRequest
|
|
13
15
|
import co.tryterra.sdk.bridge.generated.ConnectionList
|
|
16
|
+
import co.tryterra.sdk.bridge.generated.DevIdBinding
|
|
17
|
+
import co.tryterra.sdk.bridge.generated.DevIdBindingList
|
|
18
|
+
import co.tryterra.sdk.bridge.generated.DevIdRequest
|
|
14
19
|
import co.tryterra.sdk.bridge.generated.DiagnosticsState
|
|
20
|
+
import co.tryterra.sdk.bridge.generated.LinkDevIdRequest
|
|
21
|
+
import co.tryterra.sdk.bridge.generated.LinkedDevIdsRequest
|
|
15
22
|
import co.tryterra.sdk.bridge.generated.DietaryQuantityList
|
|
16
23
|
import co.tryterra.sdk.bridge.generated.Empty
|
|
17
24
|
import co.tryterra.sdk.bridge.generated.HealthAccess
|
|
@@ -77,6 +84,7 @@ internal class TerraBridgeOpsImpl(
|
|
|
77
84
|
platform = host.platform,
|
|
78
85
|
sdkVersion = host.sdkVersion,
|
|
79
86
|
backgroundRegistered = host.backgroundRegistered(),
|
|
87
|
+
devIdMode = if (terra.devIdMode == DevIdMode.MULTIPLE) "multiple" else "single",
|
|
80
88
|
)
|
|
81
89
|
|
|
82
90
|
override suspend fun clientConnect(request: ConnectRequest): Connection {
|
|
@@ -97,6 +105,20 @@ internal class TerraBridgeOpsImpl(
|
|
|
97
105
|
return Empty()
|
|
98
106
|
}
|
|
99
107
|
|
|
108
|
+
override suspend fun clientLinkDevId(request: LinkDevIdRequest): DevIdBinding =
|
|
109
|
+
Conversions.devIdBinding(terra.linkedDevIds.link(request.devId, request.token, sourceOf(request.source)))
|
|
110
|
+
|
|
111
|
+
override suspend fun clientUnlinkDevId(request: DevIdRequest): Empty {
|
|
112
|
+
terra.linkedDevIds.unlink(request.devId, sourceOf(request.source))
|
|
113
|
+
return Empty()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override suspend fun clientLinkedDevIds(request: LinkedDevIdsRequest): DevIdBindingList =
|
|
117
|
+
DevIdBindingList(
|
|
118
|
+
terra.linkedDevIds.all(sourceOf(request.source), refresh = request.refresh == true)
|
|
119
|
+
.map(Conversions::devIdBinding),
|
|
120
|
+
)
|
|
121
|
+
|
|
100
122
|
// ---- token ------------------------------------------------------------------------------
|
|
101
123
|
|
|
102
124
|
override suspend fun tokenSetProviderPresent(request: TokenProviderRequest): Empty {
|
|
@@ -124,6 +146,13 @@ internal class TerraBridgeOpsImpl(
|
|
|
124
146
|
*/
|
|
125
147
|
override suspend fun permissionsRequest(request: PermissionRequest): PermissionGrant {
|
|
126
148
|
val source = sourceOf(request.source)
|
|
149
|
+
val readTypes = request.readTypes.orEmpty().map(Conversions::dataType).toSet()
|
|
150
|
+
// Samsung Health is asked by category only. Refused here, before the launcher or the record
|
|
151
|
+
// is touched, as the iOS-only types are: the SDK refuses it too, but with an
|
|
152
|
+
// `IllegalArgumentException` a wrapper could only report as a platform failure.
|
|
153
|
+
if (source == Source.SAMSUNG_HEALTH && readTypes.isNotEmpty()) {
|
|
154
|
+
throw BridgeError.UnsupportedOnPlatform(with(Conversions) { request.readTypes.orEmpty().first().wireName() })
|
|
155
|
+
}
|
|
127
156
|
val permissions = terra.on(source).permissions
|
|
128
157
|
val launcher = host.permissionLauncher(source) ?: throw BridgeError.NoActivity
|
|
129
158
|
val granted = try {
|
|
@@ -132,6 +161,7 @@ internal class TerraBridgeOpsImpl(
|
|
|
132
161
|
write = request.write.map(Conversions::category).toSet(),
|
|
133
162
|
workouts = request.workouts.map(Conversions::scope).toSet(),
|
|
134
163
|
launcher = launcher,
|
|
164
|
+
readTypes = readTypes,
|
|
135
165
|
)
|
|
136
166
|
} catch (cancelled: CancellationException) {
|
|
137
167
|
// CancellationException is an IllegalStateException.
|
|
@@ -147,6 +177,9 @@ internal class TerraBridgeOpsImpl(
|
|
|
147
177
|
override suspend fun permissionsStatus(request: CategoryRequest): StatusResult =
|
|
148
178
|
StatusResult(Conversions.permissionStatus(permissionsOf(request.source).status(Conversions.category(request.category))))
|
|
149
179
|
|
|
180
|
+
override suspend fun permissionsTypeStatus(request: DataTypeRequest): StatusResult =
|
|
181
|
+
StatusResult(Conversions.permissionStatus(permissionsOf(request.source).status(Conversions.dataType(request.type))))
|
|
182
|
+
|
|
150
183
|
override suspend fun permissionsWriteStatus(request: CategoryRequest): StatusResult =
|
|
151
184
|
StatusResult(
|
|
152
185
|
Conversions.permissionStatus(permissionsOf(request.source).writeStatus(Conversions.category(request.category))),
|
|
@@ -84,6 +84,7 @@ public object BridgeErrorCodes {
|
|
|
84
84
|
"health_data_unavailable",
|
|
85
85
|
"not_connected",
|
|
86
86
|
"route_awaiting_converter",
|
|
87
|
+
"data_type_not_enabled",
|
|
87
88
|
"token_unavailable",
|
|
88
89
|
"token_rejected",
|
|
89
90
|
"token_provider_failed",
|
|
@@ -96,6 +97,7 @@ public object BridgeErrorCodes {
|
|
|
96
97
|
"link_revoked",
|
|
97
98
|
"dev_id_mismatch",
|
|
98
99
|
"link_conflict",
|
|
100
|
+
"link_refused",
|
|
99
101
|
"sync_already_running",
|
|
100
102
|
"link_already_running",
|
|
101
103
|
"store_locked",
|
|
@@ -107,8 +109,11 @@ public object BridgeErrorCodes {
|
|
|
107
109
|
"sample_not_found",
|
|
108
110
|
"rollback_incomplete",
|
|
109
111
|
"distance_not_attributable",
|
|
112
|
+
"workouts_required",
|
|
110
113
|
"blood_pressure_incomplete",
|
|
111
114
|
"authorization_unavailable_in_extension",
|
|
115
|
+
"health_records_unavailable",
|
|
116
|
+
"health_records_usage_description_missing",
|
|
112
117
|
"planned_workout_unnamed",
|
|
113
118
|
"network.transport",
|
|
114
119
|
"network.throttled",
|
|
@@ -141,6 +146,7 @@ public object BridgeErrorCodes {
|
|
|
141
146
|
"link_revoked",
|
|
142
147
|
"dev_id_mismatch",
|
|
143
148
|
"link_conflict",
|
|
149
|
+
"link_refused",
|
|
144
150
|
"sync_already_running",
|
|
145
151
|
"link_already_running",
|
|
146
152
|
"store_locked",
|
|
@@ -152,6 +158,7 @@ public object BridgeErrorCodes {
|
|
|
152
158
|
"sample_not_found",
|
|
153
159
|
"rollback_incomplete",
|
|
154
160
|
"distance_not_attributable",
|
|
161
|
+
"workouts_required",
|
|
155
162
|
"blood_pressure_incomplete",
|
|
156
163
|
"authorization_unavailable_in_extension",
|
|
157
164
|
"network.transport",
|
|
@@ -170,6 +177,7 @@ public object BridgeErrorCodes {
|
|
|
170
177
|
"health_data_unavailable" to false,
|
|
171
178
|
"not_connected" to false,
|
|
172
179
|
"route_awaiting_converter" to false,
|
|
180
|
+
"data_type_not_enabled" to false,
|
|
173
181
|
"token_unavailable" to false,
|
|
174
182
|
"token_rejected" to false,
|
|
175
183
|
"token_provider_failed" to false,
|
|
@@ -182,6 +190,7 @@ public object BridgeErrorCodes {
|
|
|
182
190
|
"link_revoked" to false,
|
|
183
191
|
"dev_id_mismatch" to false,
|
|
184
192
|
"link_conflict" to true,
|
|
193
|
+
"link_refused" to false,
|
|
185
194
|
"sync_already_running" to false,
|
|
186
195
|
"link_already_running" to false,
|
|
187
196
|
"store_locked" to true,
|
|
@@ -193,8 +202,11 @@ public object BridgeErrorCodes {
|
|
|
193
202
|
"sample_not_found" to false,
|
|
194
203
|
"rollback_incomplete" to false,
|
|
195
204
|
"distance_not_attributable" to false,
|
|
205
|
+
"workouts_required" to false,
|
|
196
206
|
"blood_pressure_incomplete" to false,
|
|
197
207
|
"authorization_unavailable_in_extension" to false,
|
|
208
|
+
"health_records_unavailable" to false,
|
|
209
|
+
"health_records_usage_description_missing" to false,
|
|
198
210
|
"planned_workout_unnamed" to false,
|
|
199
211
|
"network.transport" to true,
|
|
200
212
|
"network.throttled" to true,
|
|
@@ -27,13 +27,18 @@ public enum class BridgeOp(public val wire: String, public val isSupported: Bool
|
|
|
27
27
|
CLIENT_CONNECTIONS("client.connections", true),
|
|
28
28
|
CLIENT_AVAILABILITY("client.availability", true),
|
|
29
29
|
CLIENT_DISCONNECT("client.disconnect", true),
|
|
30
|
+
CLIENT_LINK_DEV_ID("client.linkDevId", true),
|
|
31
|
+
CLIENT_UNLINK_DEV_ID("client.unlinkDevId", true),
|
|
32
|
+
CLIENT_LINKED_DEV_IDS("client.linkedDevIds", true),
|
|
30
33
|
TOKEN_SET_PROVIDER_PRESENT("token.setProviderPresent", true),
|
|
31
34
|
TOKEN_RESOLVE("token.resolve", true),
|
|
32
35
|
TOKEN_REJECT("token.reject", true),
|
|
33
36
|
PERMISSIONS_REQUEST("permissions.request", true),
|
|
34
37
|
PERMISSIONS_STATUS("permissions.status", true),
|
|
38
|
+
PERMISSIONS_TYPE_STATUS("permissions.typeStatus", true),
|
|
35
39
|
PERMISSIONS_WRITE_STATUS("permissions.writeStatus", true),
|
|
36
40
|
PERMISSIONS_REQUESTED("permissions.requested", true),
|
|
41
|
+
PERMISSIONS_REQUEST_CLINICAL_RECORDS("permissions.requestClinicalRecords", false),
|
|
37
42
|
PERMISSIONS_STATUSES("permissions.statuses", true),
|
|
38
43
|
PERMISSIONS_BACKGROUND_READ_STATUS("permissions.backgroundReadStatus", true),
|
|
39
44
|
PERMISSIONS_HISTORY_READ_STATUS("permissions.historyReadStatus", true),
|
|
@@ -100,6 +105,22 @@ public interface TerraBridgeOps {
|
|
|
100
105
|
/** Whether the device can serve the source at all. Needs no connection and prompts for nothing. */
|
|
101
106
|
public suspend fun clientAvailability(request: SourceRequest): AvailabilityResult
|
|
102
107
|
public suspend fun clientDisconnect(request: SourceRequest): Empty
|
|
108
|
+
/**
|
|
109
|
+
* Multi-dev-id mode only: links one customer's connection to the installation's shared device
|
|
110
|
+
* link. The first customer links the installation; every later one joins it, keeping one read
|
|
111
|
+
* and one upload.
|
|
112
|
+
*/
|
|
113
|
+
public suspend fun clientLinkDevId(request: LinkDevIdRequest): DevIdBinding
|
|
114
|
+
/**
|
|
115
|
+
* Multi-dev-id mode only: stops delivering to one customer's connection and leaves the others
|
|
116
|
+
* linked. The last customer's unlink disconnects the installation.
|
|
117
|
+
*/
|
|
118
|
+
public suspend fun clientUnlinkDevId(request: DevIdRequest): Empty
|
|
119
|
+
/**
|
|
120
|
+
* Multi-dev-id mode only: the customers currently linked, in the order they linked, gone ones
|
|
121
|
+
* included (active false). refresh asks Terra first.
|
|
122
|
+
*/
|
|
123
|
+
public suspend fun clientLinkedDevIds(request: LinkedDevIdsRequest): DevIdBindingList
|
|
103
124
|
/**
|
|
104
125
|
* Tells the broker whether JS can answer at all. Without it a link asks a provider that is not
|
|
105
126
|
* there and waits out the timeout.
|
|
@@ -113,6 +134,13 @@ public interface TerraBridgeOps {
|
|
|
113
134
|
public suspend fun tokenReject(request: TokenRejectRequest): Empty
|
|
114
135
|
public suspend fun permissionsRequest(request: PermissionRequest): PermissionGrant
|
|
115
136
|
public suspend fun permissionsStatus(request: CategoryRequest): StatusResult
|
|
137
|
+
/**
|
|
138
|
+
* One type's read status. iOS answers notDisclosed wherever the OS has the type, because
|
|
139
|
+
* HealthKit never reports a read decision; Android answers granted once any permission behind
|
|
140
|
+
* the type is granted, denied when it was asked for and none is, and notDetermined when it
|
|
141
|
+
* never was.
|
|
142
|
+
*/
|
|
143
|
+
public suspend fun permissionsTypeStatus(request: DataTypeRequest): StatusResult
|
|
116
144
|
public suspend fun permissionsWriteStatus(request: CategoryRequest): StatusResult
|
|
117
145
|
public suspend fun permissionsRequested(request: SourceRequest): HealthAccess
|
|
118
146
|
/** Available on android only. */
|
|
@@ -194,13 +222,18 @@ public object BridgeCodecs {
|
|
|
194
222
|
BridgeOp.CLIENT_CONNECTIONS -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
195
223
|
BridgeOp.CLIENT_AVAILABILITY -> json.encodeToString(json.decodeFromString<SourceRequest>(payload))
|
|
196
224
|
BridgeOp.CLIENT_DISCONNECT -> json.encodeToString(json.decodeFromString<SourceRequest>(payload))
|
|
225
|
+
BridgeOp.CLIENT_LINK_DEV_ID -> json.encodeToString(json.decodeFromString<LinkDevIdRequest>(payload))
|
|
226
|
+
BridgeOp.CLIENT_UNLINK_DEV_ID -> json.encodeToString(json.decodeFromString<DevIdRequest>(payload))
|
|
227
|
+
BridgeOp.CLIENT_LINKED_DEV_IDS -> json.encodeToString(json.decodeFromString<LinkedDevIdsRequest>(payload))
|
|
197
228
|
BridgeOp.TOKEN_SET_PROVIDER_PRESENT -> json.encodeToString(json.decodeFromString<TokenProviderRequest>(payload))
|
|
198
229
|
BridgeOp.TOKEN_RESOLVE -> json.encodeToString(json.decodeFromString<TokenResolveRequest>(payload))
|
|
199
230
|
BridgeOp.TOKEN_REJECT -> json.encodeToString(json.decodeFromString<TokenRejectRequest>(payload))
|
|
200
231
|
BridgeOp.PERMISSIONS_REQUEST -> json.encodeToString(json.decodeFromString<PermissionRequest>(payload))
|
|
201
232
|
BridgeOp.PERMISSIONS_STATUS -> json.encodeToString(json.decodeFromString<CategoryRequest>(payload))
|
|
233
|
+
BridgeOp.PERMISSIONS_TYPE_STATUS -> json.encodeToString(json.decodeFromString<DataTypeRequest>(payload))
|
|
202
234
|
BridgeOp.PERMISSIONS_WRITE_STATUS -> json.encodeToString(json.decodeFromString<CategoryRequest>(payload))
|
|
203
235
|
BridgeOp.PERMISSIONS_REQUESTED -> json.encodeToString(json.decodeFromString<SourceRequest>(payload))
|
|
236
|
+
BridgeOp.PERMISSIONS_REQUEST_CLINICAL_RECORDS -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
204
237
|
BridgeOp.PERMISSIONS_STATUSES -> json.encodeToString(json.decodeFromString<SourceRequest>(payload))
|
|
205
238
|
BridgeOp.PERMISSIONS_BACKGROUND_READ_STATUS -> json.encodeToString(json.decodeFromString<SourceRequest>(payload))
|
|
206
239
|
BridgeOp.PERMISSIONS_HISTORY_READ_STATUS -> json.encodeToString(json.decodeFromString<SourceRequest>(payload))
|
|
@@ -250,13 +283,18 @@ public object BridgeCodecs {
|
|
|
250
283
|
BridgeOp.CLIENT_CONNECTIONS -> json.encodeToString(json.decodeFromString<ConnectionList>(payload))
|
|
251
284
|
BridgeOp.CLIENT_AVAILABILITY -> json.encodeToString(json.decodeFromString<AvailabilityResult>(payload))
|
|
252
285
|
BridgeOp.CLIENT_DISCONNECT -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
286
|
+
BridgeOp.CLIENT_LINK_DEV_ID -> json.encodeToString(json.decodeFromString<DevIdBinding>(payload))
|
|
287
|
+
BridgeOp.CLIENT_UNLINK_DEV_ID -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
288
|
+
BridgeOp.CLIENT_LINKED_DEV_IDS -> json.encodeToString(json.decodeFromString<DevIdBindingList>(payload))
|
|
253
289
|
BridgeOp.TOKEN_SET_PROVIDER_PRESENT -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
254
290
|
BridgeOp.TOKEN_RESOLVE -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
255
291
|
BridgeOp.TOKEN_REJECT -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
256
292
|
BridgeOp.PERMISSIONS_REQUEST -> json.encodeToString(json.decodeFromString<PermissionGrant>(payload))
|
|
257
293
|
BridgeOp.PERMISSIONS_STATUS -> json.encodeToString(json.decodeFromString<StatusResult>(payload))
|
|
294
|
+
BridgeOp.PERMISSIONS_TYPE_STATUS -> json.encodeToString(json.decodeFromString<StatusResult>(payload))
|
|
258
295
|
BridgeOp.PERMISSIONS_WRITE_STATUS -> json.encodeToString(json.decodeFromString<StatusResult>(payload))
|
|
259
296
|
BridgeOp.PERMISSIONS_REQUESTED -> json.encodeToString(json.decodeFromString<HealthAccess>(payload))
|
|
297
|
+
BridgeOp.PERMISSIONS_REQUEST_CLINICAL_RECORDS -> json.encodeToString(json.decodeFromString<Empty>(payload))
|
|
260
298
|
BridgeOp.PERMISSIONS_STATUSES -> json.encodeToString(json.decodeFromString<StatusesResult>(payload))
|
|
261
299
|
BridgeOp.PERMISSIONS_BACKGROUND_READ_STATUS -> json.encodeToString(json.decodeFromString<StatusResult>(payload))
|
|
262
300
|
BridgeOp.PERMISSIONS_HISTORY_READ_STATUS -> json.encodeToString(json.decodeFromString<StatusResult>(payload))
|
|
@@ -375,6 +413,12 @@ public class BridgeDispatch(
|
|
|
375
413
|
json.encodeToString(ops.clientAvailability(json.decodeRequest<SourceRequest>(payload)))
|
|
376
414
|
BridgeOp.CLIENT_DISCONNECT ->
|
|
377
415
|
json.encodeToString(ops.clientDisconnect(json.decodeRequest<SourceRequest>(payload)))
|
|
416
|
+
BridgeOp.CLIENT_LINK_DEV_ID ->
|
|
417
|
+
json.encodeToString(ops.clientLinkDevId(json.decodeRequest<LinkDevIdRequest>(payload)))
|
|
418
|
+
BridgeOp.CLIENT_UNLINK_DEV_ID ->
|
|
419
|
+
json.encodeToString(ops.clientUnlinkDevId(json.decodeRequest<DevIdRequest>(payload)))
|
|
420
|
+
BridgeOp.CLIENT_LINKED_DEV_IDS ->
|
|
421
|
+
json.encodeToString(ops.clientLinkedDevIds(json.decodeRequest<LinkedDevIdsRequest>(payload)))
|
|
378
422
|
BridgeOp.TOKEN_SET_PROVIDER_PRESENT ->
|
|
379
423
|
json.encodeToString(ops.tokenSetProviderPresent(json.decodeRequest<TokenProviderRequest>(payload)))
|
|
380
424
|
BridgeOp.TOKEN_RESOLVE ->
|
|
@@ -385,10 +429,13 @@ public class BridgeDispatch(
|
|
|
385
429
|
json.encodeToString(ops.permissionsRequest(json.decodeRequest<PermissionRequest>(payload)))
|
|
386
430
|
BridgeOp.PERMISSIONS_STATUS ->
|
|
387
431
|
json.encodeToString(ops.permissionsStatus(json.decodeRequest<CategoryRequest>(payload)))
|
|
432
|
+
BridgeOp.PERMISSIONS_TYPE_STATUS ->
|
|
433
|
+
json.encodeToString(ops.permissionsTypeStatus(json.decodeRequest<DataTypeRequest>(payload)))
|
|
388
434
|
BridgeOp.PERMISSIONS_WRITE_STATUS ->
|
|
389
435
|
json.encodeToString(ops.permissionsWriteStatus(json.decodeRequest<CategoryRequest>(payload)))
|
|
390
436
|
BridgeOp.PERMISSIONS_REQUESTED ->
|
|
391
437
|
json.encodeToString(ops.permissionsRequested(json.decodeRequest<SourceRequest>(payload)))
|
|
438
|
+
BridgeOp.PERMISSIONS_REQUEST_CLINICAL_RECORDS -> throw BridgeError.UnsupportedOnPlatform(known.wire)
|
|
392
439
|
BridgeOp.PERMISSIONS_STATUSES ->
|
|
393
440
|
json.encodeToString(ops.permissionsStatuses(json.decodeRequest<SourceRequest>(payload)))
|
|
394
441
|
BridgeOp.PERMISSIONS_BACKGROUND_READ_STATUS ->
|