├── .husky ├── .npmignore ├── pre-commit └── commit-msg ├── src ├── __tests__ │ ├── index.test.tsx │ └── index.test.js ├── models │ ├── samples │ │ ├── METSample.ts │ │ ├── HeartRateDataSample.ts │ │ ├── Vo2MaxSample.ts │ │ ├── OxygenSaturationSample.ts │ │ ├── PowerSample.ts │ │ ├── StepSample.ts │ │ ├── CadenceSample.ts │ │ ├── ElevationSample.ts │ │ ├── HeartRateVariabilityDataSampleRMSSD.ts │ │ ├── HeartRateVariabilityDataSampleSDNN.ts │ │ ├── DistanceSample.ts │ │ ├── SpeedSample.ts │ │ ├── PositionSample.ts │ │ ├── ActivityLevelSample.ts │ │ ├── CalorieSample.ts │ │ ├── FloorsClimbedSample.ts │ │ ├── OtherDeviceData.ts │ │ ├── TSSSample.ts │ │ ├── HeartRateZoneData.ts │ │ └── LapSample.ts │ └── Activity.ts ├── enums │ ├── Permissions.ts │ ├── Connections.ts │ ├── UploadType.ts │ ├── ActivityLevel.ts │ ├── HeartRateZone.ts │ ├── StrokeType.ts │ ├── CustomPermissions.ts │ └── ActivityTypes.ts ├── helpers.ts └── index.ts ├── app.plugin.js ├── .gitattributes ├── example ├── src │ ├── config.ts │ ├── samplePlannedWorkout.ts │ └── App.tsx ├── ios │ ├── File.swift │ ├── TerraReactExample │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── main.m │ │ ├── AppDelegate.h │ │ ├── TerraReactExample.entitlements │ │ ├── AppDelegate.m │ │ ├── Info.plist │ │ └── LaunchScreen.storyboard │ ├── TerraReactExample-Bridging-Header.h │ ├── TerraReactExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── Podfile │ ├── TerraReactExample.xcodeproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── TerraReactExample.xcscheme │ └── Podfile.lock ├── android │ ├── app │ │ ├── debug.keystore │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── layout │ │ │ │ │ │ └── example.xml │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── terrareact │ │ │ │ │ │ ├── Example.java │ │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ │ └── MainApplication.java │ │ │ │ └── AndroidManifest.xml │ │ │ └── debug │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── terrareact │ │ │ │ └── ReactNativeFlipper.java │ │ ├── proguard-rules.pro │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── gradle.properties │ ├── build.gradle │ ├── gradlew.bat │ └── gradlew ├── app.json ├── index.js ├── index.tsx ├── babel.config.js ├── package.json ├── patches │ └── react-native+0.69.2.patch └── metro.config.js ├── tsconfig.build.json ├── babel.config.js ├── .prettierrc ├── .yarnrc ├── android ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── terrareact │ │ ├── TerraReactPackage.java │ │ └── TerraReactModule.java ├── build.gradle ├── gradlew.bat └── gradlew ├── README.md ├── ios ├── TerraReact-Bridging-Header.h ├── TerraActivityData.swift ├── TerraReact.m └── TerraReact.xcodeproj │ └── project.pbxproj ├── plugin ├── tsconfig.json └── src │ ├── index.js │ └── index.ts ├── .editorconfig ├── terra-react.podspec ├── tsconfig.json ├── scripts └── bootstrap.js ├── .gitignore ├── LICENSE ├── .circleci └── config.yml ├── .github └── workflows │ └── release_package.yml ├── package.json ├── CONTRIBUTING.md └── CHANGELOG.md /.husky/.npmignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /app.plugin.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./plugin/build'); 2 | -------------------------------------------------------------------------------- /src/__tests__/index.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | it.todo('write a test'); 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /example/src/config.ts: -------------------------------------------------------------------------------- 1 | export const config = { 2 | devId: '', 3 | apiKey: '', 4 | }; 5 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint && yarn typescript 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // TerraReactExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn commitlint -E HUSKY_GIT_PARAMS 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "trailingComma": "all", 4 | "singleQuote": true 5 | } 6 | -------------------------------------------------------------------------------- /src/models/samples/METSample.ts: -------------------------------------------------------------------------------- 1 | export interface METSample { 2 | timestamp: string; 3 | level: number; 4 | } 5 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/debug.keystore -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/models/samples/HeartRateDataSample.ts: -------------------------------------------------------------------------------- 1 | export interface HeartRateDataSample { 2 | timestamp: string; 3 | bpm: number; 4 | } 5 | -------------------------------------------------------------------------------- /src/enums/Permissions.ts: -------------------------------------------------------------------------------- 1 | export enum Permissions { 2 | 'ACTIVITY', 3 | 'BODY', 4 | 'DAILY', 5 | 'NUTRITION', 6 | 'SLEEP', 7 | } 8 | -------------------------------------------------------------------------------- /src/models/samples/Vo2MaxSample.ts: -------------------------------------------------------------------------------- 1 | export interface Vo2MaxSample { 2 | timestamp: string; 3 | vo2max_ml_per_min_per_kg: number; 4 | } 5 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TerraReact Example 3 | 4 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/models/samples/OxygenSaturationSample.ts: -------------------------------------------------------------------------------- 1 | export interface OxygenSaturationSample { 2 | timestamp: string; 3 | percentage: number; 4 | } 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docs 2 | 3 | Docs for setting up Terra in your React Native project can be found [here](https://docs.tryterra.co/docs/react-native-project). -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/models/samples/PowerSample.ts: -------------------------------------------------------------------------------- 1 | export interface PowerSample { 2 | timestamp: string; 3 | watts: number; 4 | timer_duration_seconds: number; 5 | } 6 | -------------------------------------------------------------------------------- /src/models/samples/StepSample.ts: -------------------------------------------------------------------------------- 1 | export interface StepSample { 2 | timestamp: string; 3 | steps: number; 4 | timer_duration_seconds: number; 5 | } 6 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /src/enums/Connections.ts: -------------------------------------------------------------------------------- 1 | export enum Connections { 2 | 'APPLE_HEALTH', 3 | 'FREESTYLE_LIBRE', 4 | 'GOOGLE', 5 | 'SAMSUNG', 6 | 'HEALTH_CONNECT', 7 | } 8 | -------------------------------------------------------------------------------- /src/models/samples/CadenceSample.ts: -------------------------------------------------------------------------------- 1 | export interface CadenceSample { 2 | timestamp: string; 3 | cadence_rpm: number; 4 | timer_duration_seconds: number; 5 | } 6 | -------------------------------------------------------------------------------- /src/enums/UploadType.ts: -------------------------------------------------------------------------------- 1 | export enum UploadType { 2 | UNKNOWN = 0, 3 | AUTOMATIC = 1, 4 | MANUAL = 2, 5 | UPDATE = 3, 6 | DELETE = 4, 7 | PENDING = 5, 8 | } 9 | -------------------------------------------------------------------------------- /src/models/samples/ElevationSample.ts: -------------------------------------------------------------------------------- 1 | export interface ElevationSample { 2 | timestamp: string; 3 | elev_meters: number; 4 | timer_duration_seconds: number; 5 | } 6 | -------------------------------------------------------------------------------- /src/models/samples/HeartRateVariabilityDataSampleRMSSD.ts: -------------------------------------------------------------------------------- 1 | export interface HeartRateVariabilityDataSampleRMSSD { 2 | timestamp: string; 3 | hrv_sdnn: number; 4 | } 5 | -------------------------------------------------------------------------------- /src/models/samples/HeartRateVariabilityDataSampleSDNN.ts: -------------------------------------------------------------------------------- 1 | export interface HeartRateVariabilityDataSampleSDNN { 2 | timestamp: string; 3 | hrv_sdnn: number; 4 | } 5 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ios/TerraReact-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jaafar Rammal on 06/06/2022. 3 | // 4 | 5 | #import 6 | #import 7 | -------------------------------------------------------------------------------- /src/models/samples/DistanceSample.ts: -------------------------------------------------------------------------------- 1 | export interface DistanceSample { 2 | timestamp: string; 3 | distance_meters: number; 4 | timer_duration_seconds: number; 5 | } 6 | -------------------------------------------------------------------------------- /src/models/samples/SpeedSample.ts: -------------------------------------------------------------------------------- 1 | export interface SpeedSample { 2 | timestamp: string; 3 | speed_meters_per_second: number; 4 | timer_duration_seconds: number; 5 | } 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /src/models/samples/PositionSample.ts: -------------------------------------------------------------------------------- 1 | export interface PositionSample { 2 | timestamp: string; 3 | coords_lat_lng_deg: [number, number]; 4 | timer_duration_seconds: number; 5 | } 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tryterra/terra-react/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TerraReactExample", 3 | "displayName": "TerraReact Example", 4 | "expo": { 5 | "plugins": [ 6 | "terra-react" 7 | ] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/enums/ActivityLevel.ts: -------------------------------------------------------------------------------- 1 | export enum ActivityLevel { 2 | UNKNOWN = 0, 3 | REST = 1, 4 | INACTIVE = 2, 5 | LOW_INTENSITY = 3, 6 | MEDIUM_INTENSITY = 4, 7 | HIGH_INTENSITY = 5, 8 | } 9 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | AppRegistry.registerComponent(appName, () => App); 5 | -------------------------------------------------------------------------------- /src/enums/HeartRateZone.ts: -------------------------------------------------------------------------------- 1 | export enum HeartRateZone { 2 | ZONE_0 = 0, 3 | ZONE_1 = 1, 4 | ZONE_2 = 2, 5 | ZONE_3 = 3, 6 | ZONE_4 = 4, 7 | ZONE_5 = 5, 8 | OTHER = 6, 9 | } 10 | -------------------------------------------------------------------------------- /example/index.tsx: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /src/enums/StrokeType.ts: -------------------------------------------------------------------------------- 1 | export enum StrokeType { 2 | OTHER = 'other', 3 | FREESTYLE = 'freestyle', 4 | BACKSTROKE = 'backstroke', 5 | BREASTSTROKE = 'breaststroke', 6 | BUTTERFLY = 'butterfly', 7 | } 8 | -------------------------------------------------------------------------------- /src/helpers.ts: -------------------------------------------------------------------------------- 1 | type Some = T; 2 | type None = null; 3 | export type Option = Some | None; 4 | 5 | export function convertToProperIsoFormat(date: Date): string { 6 | return date.toISOString(); 7 | } 8 | -------------------------------------------------------------------------------- /src/models/samples/ActivityLevelSample.ts: -------------------------------------------------------------------------------- 1 | import { ActivityLevel } from '../../enums/ActivityLevel'; 2 | 3 | export interface ActivityLevelSample { 4 | timestamp: string; 5 | level: ActivityLevel; 6 | } 7 | -------------------------------------------------------------------------------- /plugin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "build", 4 | "rootDir": "src", 5 | "declaration": true, 6 | "skipLibCheck": true, 7 | }, 8 | "include": ["./src"] 9 | } 10 | -------------------------------------------------------------------------------- /src/models/samples/CalorieSample.ts: -------------------------------------------------------------------------------- 1 | import { Option } from '../../helpers'; 2 | 3 | export interface CalorieSample { 4 | timestamp: string; 5 | calories: number; 6 | timer_duration_seconds: Option; 7 | } 8 | -------------------------------------------------------------------------------- /src/models/samples/FloorsClimbedSample.ts: -------------------------------------------------------------------------------- 1 | import { Option } from '../../helpers'; 2 | 3 | export interface FloorsClimbedSample { 4 | timestamp: string; 5 | floors_climbed: number; 6 | timer_duration_seconds: Option; 7 | } 8 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Aug 11 13:01:06 BST 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /src/models/samples/OtherDeviceData.ts: -------------------------------------------------------------------------------- 1 | import { Option } from '../../helpers'; 2 | 3 | export interface OtherDeviceData { 4 | name: Option; 5 | manufacturer: Option; 6 | serial_number: Option; 7 | software_version: Option; 8 | hardware_version: Option; 9 | } 10 | -------------------------------------------------------------------------------- /src/models/samples/TSSSample.ts: -------------------------------------------------------------------------------- 1 | import { Option } from '../../helpers'; 2 | 3 | export interface TSSSample { 4 | planned: number; 5 | actual: number; 6 | method: string; 7 | intensity_factor_planned: Option; 8 | intensity_factor_actual: Option; 9 | normalized_power_watts: Option; 10 | } 11 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'TerraReactExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | 5 | include ':terrareact' 6 | project(':terrareact').projectDir = new File(rootProject.projectDir, '../../android') 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /src/models/samples/HeartRateZoneData.ts: -------------------------------------------------------------------------------- 1 | import { HeartRateZone } from '../../enums/HeartRateZone'; 2 | import { Option } from '../../helpers'; 3 | 4 | export interface HeartRateZoneData { 5 | zone: HeartRateZone; 6 | start_percentage: Option; 7 | end_percentage: Option; 8 | name: Option; 9 | duration_seconds: Option; 10 | } 11 | -------------------------------------------------------------------------------- /src/models/samples/LapSample.ts: -------------------------------------------------------------------------------- 1 | import { StrokeType } from '../../enums/StrokeType'; 2 | import { Option } from '../../helpers'; 3 | 4 | export interface LapSample { 5 | start_time: string; 6 | distance_meters: Option; 7 | calories: Option; 8 | total_strokes: Option; 9 | stroke_type: Option; 10 | avg_speed_meters_per_second: Option; 11 | } 12 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/terrareact/Example.java: -------------------------------------------------------------------------------- 1 | package com.example.terrareact; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | public class Example extends Activity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState){ 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.example); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:metro-react-native-babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', 9 | { 10 | extensions: ['.tsx', '.ts', '.js', '.json'], 11 | alias: { 12 | [pak.name]: path.join(__dirname, '..', pak.source), 13 | }, 14 | }, 15 | ], 16 | ], 17 | }; 18 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | #import 10 | 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/terrareact/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.terrareact; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. This is used to schedule 9 | * rendering of the component. 10 | */ 11 | 12 | @Override 13 | protected String getMainComponentName() { 14 | return "TerraReactExample"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/layout/example.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | -keep class co.tryterra.** { *; } 13 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/TerraReactExample.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.developer.healthkit 6 | 7 | com.apple.developer.healthkit.access 8 | 9 | com.apple.developer.healthkit.background-delivery 10 | 11 | com.apple.developer.nfc.readersession.formats 12 | 13 | NDEF 14 | TAG 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "terra-react-example", 3 | "description": "Example app for terra-react", 4 | "version": "0.0.1", 5 | "private": true, 6 | "scripts": { 7 | "android": "react-native run-android", 8 | "ios": "react-native run-ios", 9 | "start": "react-native start" 10 | }, 11 | "dependencies": { 12 | "react": "18.1.0", 13 | "react-native": "0.70.0", 14 | "terra-react": "file:.." 15 | }, 16 | "devDependencies": { 17 | "@babel/core": "^7.12.10", 18 | "@babel/runtime": "^7.12.5", 19 | "babel-plugin-module-resolver": "^4.0.0", 20 | "metro-react-native-babel-preset": "^0.64.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /terra-react.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = "terra-react" 7 | s.version = package["version"] 8 | s.summary = package["description"] 9 | s.homepage = package["homepage"] 10 | s.license = package["license"] 11 | s.authors = package["author"] 12 | 13 | s.platforms = { :ios => "13.0" } 14 | s.source = { :git => "https://github.com/tryterra/terra-react.git", :tag => "#{s.version}" } 15 | 16 | s.source_files = "ios/**/*.{h,m,mm,swift}" 17 | 18 | s.frameworks = ['HealthKit'] 19 | s.dependency "TerraiOS", "1.6.31" 20 | s.dependency "React-Core" 21 | end 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "terra-react": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "jsx": "react", 12 | "lib": ["esnext"], 13 | "module": "esnext", 14 | "moduleResolution": "node", 15 | "noFallthroughCasesInSwitch": true, 16 | "noImplicitReturns": true, 17 | "noImplicitUseStrict": false, 18 | "noStrictGenericChecks": false, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "resolveJsonModule": true, 22 | "skipLibCheck": true, 23 | "strict": true, 24 | "target": "esnext" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true; 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # node.js 48 | # 49 | node_modules/ 50 | npm-debug.log 51 | yarn-debug.log 52 | yarn-error.log 53 | 54 | # BUCK 55 | buck-out/ 56 | \.buckd/ 57 | android/app/libs 58 | android/keystores/debug.keystore 59 | 60 | # Expo 61 | .expo/* 62 | 63 | # generated by bob 64 | lib/ 65 | 66 | /android/bin 67 | 68 | *.tgz -------------------------------------------------------------------------------- /example/patches/react-native+0.69.2.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env 2 | new file mode 100644 3 | index 0000000..361f5fb 4 | --- /dev/null 5 | +++ b/node_modules/react-native/scripts/.packager.env 6 | @@ -0,0 +1 @@ 7 | +export RCT_METRO_PORT=8081 8 | diff --git a/node_modules/react-native/scripts/react_native_pods.rb b/node_modules/react-native/scripts/react_native_pods.rb 9 | index 265fff1..5237089 100644 10 | --- a/node_modules/react-native/scripts/react_native_pods.rb 11 | +++ b/node_modules/react-native/scripts/react_native_pods.rb 12 | @@ -407,7 +407,7 @@ def get_react_codegen_spec(options={}) 13 | 'source' => { :git => '' }, 14 | 'header_mappings_dir' => './', 15 | 'platforms' => { 16 | - 'ios' => '11.0', 17 | + 'ios' => '12.0', 18 | }, 19 | 'source_files' => "**/*.{h,mm,cpp}", 20 | 'pod_target_xcconfig' => { "HEADER_SEARCH_PATHS" => 21 | -------------------------------------------------------------------------------- /android/src/main/java/com/terrareact/TerraReactPackage.java: -------------------------------------------------------------------------------- 1 | package com.terrareact; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import com.facebook.react.ReactPackage; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.uimanager.ViewManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public class TerraReactPackage implements ReactPackage { 15 | @NonNull 16 | @Override 17 | public List createNativeModules(@NonNull ReactApplicationContext reactContext) { 18 | List modules = new ArrayList<>(); 19 | modules.add(new TerraReactModule(reactContext)); 20 | return modules; 21 | } 22 | 23 | @NonNull 24 | @Override 25 | public List createViewManagers(@NonNull ReactApplicationContext reactContext) { 26 | return Collections.emptyList(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | require_relative '../node_modules/react-native/scripts/react_native_pods' 2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' 3 | 4 | platform :ios, '13.0' 5 | 6 | target 'TerraReactExample' do 7 | config = use_native_modules! 8 | 9 | use_react_native!( 10 | :path => config[:reactNativePath], 11 | # to enable hermes on iOS, change `false` to `true` and then install pods 12 | :hermes_enabled => false 13 | ) 14 | 15 | target 'TerraReactExampleTests' do 16 | inherit! :complete 17 | # Pods for testing 18 | end 19 | 20 | # Enables Flipper. 21 | # 22 | # Note that if you have use_frameworks! enabled, Flipper will not work and 23 | # you should disable the next line. 24 | # use_flipper!() 25 | 26 | post_install do |installer| 27 | react_native_post_install(installer) 28 | installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useAndroidX=true 21 | android.enableJetifier=true 22 | FLIPPER_VERSION=0.99.0 23 | org.gradle.jvmargs=-Xmx4608m 24 | 25 | -------------------------------------------------------------------------------- /src/enums/CustomPermissions.ts: -------------------------------------------------------------------------------- 1 | export enum CustomPermissions { 2 | 'WORKOUT_TYPES', 3 | 'ACTIVITY_SUMMARY', 4 | 'LOCATION', 5 | 'CALORIES', 6 | 'STEPS', 7 | 'HEART_RATE', 8 | 'HEART_RATE_VARIABILITY', 9 | 'VO2MAX', 10 | 'HEIGHT', 11 | 'ACTIVE_DURATIONS', 12 | 'WEIGHT', 13 | 'FLIGHTS_CLIMBED', 14 | 'BMI', 15 | 'BODY_FAT', 16 | 'EXERCISE_DISTANCE', 17 | 'GENDER', 18 | 'DATE_OF_BIRTH', 19 | 'BASAL_ENERGY_BURNED', 20 | 'SWIMMING_SUMMARY', 21 | 'RESTING_HEART_RATE', 22 | 'BLOOD_PRESSURE', 23 | 'BLOOD_GLUCOSE', 24 | 'BODY_TEMPERATURE', 25 | 'MINDFULNESS', 26 | 'LEAN_BODY_MASS', 27 | 'OXYGEN_SATURATION', 28 | 'SLEEP_ANALYSIS', 29 | 'RESPIRATORY_RATE', 30 | 'NUTRITION_SODIUM', 31 | 'NUTRITION_PROTEIN', 32 | 'NUTRITION_CARBOHYDRATES', 33 | 'NUTRITION_FIBRE', 34 | 'NUTRITION_FAT_TOTAL', 35 | 'NUTRITION_SUGAR', 36 | 'NUTRITION_VITAMIN_C', 37 | 'NUTRITION_VITAMIN_A', 38 | 'NUTRITION_CALORIES', 39 | 'NUTRITION_WATER', 40 | 'NUTRITION_CHOLESTEROL', 41 | 'MENSTRUATION', 42 | 'INTERBEAT', 43 | 'SPEED', 44 | 'POWER', 45 | } 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 TerraDev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | ext { 4 | minSdkVersion = 28 5 | compileSdkVersion = 34 6 | targetSdkVersion = 31 7 | } 8 | repositories { 9 | google() 10 | mavenCentral() 11 | jcenter() 12 | maven { url 'https://maven.pkg.github.com/facebook/react-native' } 13 | } 14 | dependencies { 15 | classpath 'com.android.tools.build:gradle:7.4.2' 16 | 17 | 18 | // NOTE: Do not place your application dependencies here; they belong 19 | // in the individual module build.gradle files 20 | } 21 | } 22 | 23 | allprojects { 24 | repositories { 25 | mavenLocal() 26 | maven { 27 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 28 | url("$rootDir/../node_modules/react-native/android") 29 | } 30 | maven { 31 | // Android JSC is installed from npm 32 | url("$rootDir/../node_modules/jsc-android/dist") 33 | } 34 | 35 | google() 36 | mavenCentral() 37 | jcenter() 38 | maven { url 'https://www.jitpack.io' } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const blacklist = require('metro-config/src/defaults/exclusionList'); 3 | const escape = require('escape-string-regexp'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: blacklist( 20 | modules.map( 21 | (m) => 22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 23 | ) 24 | ), 25 | 26 | extraNodeModules: modules.reduce((acc, name) => { 27 | acc[name] = path.join(__dirname, 'node_modules', name); 28 | return acc; 29 | }, {}), 30 | }, 31 | 32 | transformer: { 33 | getTransformOptions: async () => ({ 34 | transform: { 35 | experimentalImportSupport: false, 36 | inlineRequires: true, 37 | }, 38 | }), 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /ios/TerraActivityData.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import TerraiOS 3 | 4 | 5 | // At the moment we will only write rudimentary fields to HealthKit 6 | // Namely: distance, calories, start time, end time, workout type and device 7 | func convertToTerraActivityPayload(_ data: NSDictionary) -> TerraActivityData? { 8 | guard let metadata = data["metadata"] as? NSDictionary else { 9 | return nil 10 | } 11 | 12 | guard let deviceData = data["device_data"] as? NSDictionary else { 13 | return nil 14 | } 15 | 16 | guard let distanceData = data["distance_data"] as? NSDictionary else { 17 | return nil 18 | } 19 | 20 | guard let caloriesData = data["calories_data"] as? NSDictionary else { 21 | return nil 22 | } 23 | 24 | var distanceMeters: Double? = nil 25 | if let summary = distanceData["summary"] as? NSDictionary { 26 | distanceMeters = summary["distance_meters"] as? Double 27 | } 28 | 29 | return TerraActivityData( 30 | metadata: .init( 31 | type: metadata["type"] as? Int, 32 | end_time: metadata["end_time"] as? String, 33 | start_time: metadata["start_time"] as? String), 34 | device_data: .init( 35 | software_version: deviceData["software_version"] as? String, 36 | manufacturer: deviceData["manufacturer"] as? String, 37 | serial_number: deviceData["serial_number"] as? String, 38 | name: deviceData["name"] as? String, 39 | hardware_version: deviceData["hardware_version"] as? String 40 | ), 41 | distance_data: .init(summary: .init(distance_meters: distanceMeters)), 42 | calories_data: .init(TerraCaloriesData(net_activity_calories: caloriesData["net_activity_calories"] as? Double)) 43 | ) 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | if (project == rootProject) { 3 | repositories { 4 | google() 5 | mavenCentral() 6 | jcenter() 7 | } 8 | 9 | dependencies { 10 | classpath('com.android.tools.build:gradle:7.2.2') 11 | } 12 | } 13 | } 14 | 15 | apply plugin: 'com.android.library' 16 | 17 | def safeExtGet(prop, fallback) { 18 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 19 | } 20 | 21 | android { 22 | compileSdkVersion safeExtGet('TerraReact_compileSdkVersion', 34) 23 | defaultConfig { 24 | minSdkVersion safeExtGet('TerraReact_minSdkVersion', 28) 25 | targetSdkVersion safeExtGet('TerraReact_targetSdkVersion', 29) 26 | versionCode 1 27 | versionName "1.0" 28 | multiDexEnabled true 29 | } 30 | 31 | buildTypes { 32 | release { 33 | minifyEnabled false 34 | } 35 | } 36 | lintOptions { 37 | disable 'GradleCompatible' 38 | } 39 | compileOptions { 40 | sourceCompatibility JavaVersion.VERSION_1_8 41 | targetCompatibility JavaVersion.VERSION_1_8 42 | } 43 | namespace "com.terrareact" 44 | } 45 | 46 | repositories { 47 | mavenLocal() 48 | maven { 49 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 50 | url("$rootDir/../node_modules/react-native/android") 51 | } 52 | google() 53 | mavenCentral() 54 | } 55 | 56 | dependencies { 57 | //noinspection GradleDynamicVersion 58 | implementation "com.facebook.react:react-native:+" // From node_modules 59 | implementation 'co.tryterra:terra-android:1.6.2' 60 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1' 61 | implementation 'com.google.code.gson:gson:2.9.1' 62 | } 63 | -------------------------------------------------------------------------------- /plugin/src/index.js: -------------------------------------------------------------------------------- 1 | import { withAppDelegate, createRunOncePlugin } from '@expo/config-plugins'; 2 | const withTerraBackgroundDelivery = (config) => { 3 | config = withAppDelegate(config, (delegateConfig) => { 4 | const { contents } = delegateConfig.modResults; 5 | if (delegateConfig.modResults.language === 'swift') { 6 | if (!delegateConfig.modResults.contents.includes('import TerraiOS')) { 7 | delegateConfig.modResults.contents = 8 | `import TerraiOS\n` + delegateConfig.modResults.contents; 9 | } 10 | if ( 11 | !delegateConfig.modResults.contents.includes( 12 | 'Terra.setUpBackgroundDelivery()' 13 | ) 14 | ) { 15 | const regex = 16 | /return super.application\(application, didFinishLaunchingWithOptions: launchOptions\)/; 17 | delegateConfig.modResults.contents = 18 | delegateConfig.modResults.contents.replace( 19 | regex, 20 | (match) => `Terra.setUpBackgroundDelivery()\n ${match}` 21 | ); 22 | } 23 | } else { 24 | if (!contents.includes('#import ')) { 25 | delegateConfig.modResults.contents = contents.replace( 26 | '#import "AppDelegate.h"', 27 | '#import "AppDelegate.h"\n#import ' 28 | ); 29 | } 30 | if (!contents.includes('[Terra setUpBackgroundDelivery];')) { 31 | const regex = 32 | /- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions\s*\{\n/; 33 | delegateConfig.modResults.contents = 34 | delegateConfig.modResults.contents.replace( 35 | regex, 36 | (match) => `${match} [Terra setUpBackgroundDelivery];\n` 37 | ); 38 | } 39 | } 40 | return delegateConfig; 41 | }); 42 | return config; 43 | }; 44 | const pkg = require('terra-react/package.json'); 45 | export default createRunOncePlugin( 46 | withTerraBackgroundDelivery, 47 | pkg.name, 48 | pkg.version 49 | ); 50 | -------------------------------------------------------------------------------- /plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ConfigPlugin, 3 | withAppDelegate, 4 | createRunOncePlugin, 5 | } from '@expo/config-plugins'; 6 | 7 | const withTerraBackgroundDelivery: ConfigPlugin = (config) => { 8 | config = withAppDelegate(config, (delegateConfig) => { 9 | const { contents } = delegateConfig.modResults; 10 | 11 | if (delegateConfig.modResults.language === 'swift') { 12 | if (!delegateConfig.modResults.contents.includes('import TerraiOS')) { 13 | delegateConfig.modResults.contents = 14 | `import TerraiOS\n` + delegateConfig.modResults.contents; 15 | } 16 | 17 | if ( 18 | !delegateConfig.modResults.contents.includes( 19 | 'Terra.setUpBackgroundDelivery()' 20 | ) 21 | ) { 22 | const regex = 23 | /return super.application\(application, didFinishLaunchingWithOptions: launchOptions\)/; 24 | delegateConfig.modResults.contents = 25 | delegateConfig.modResults.contents.replace( 26 | regex, 27 | (match) => `Terra.setUpBackgroundDelivery()\n ${match}` 28 | ); 29 | } 30 | } else { 31 | if (!contents.includes('#import ')) { 32 | delegateConfig.modResults.contents = contents.replace( 33 | '#import "AppDelegate.h"', 34 | '#import "AppDelegate.h"\n#import ' 35 | ); 36 | } 37 | 38 | if (!contents.includes('[Terra setUpBackgroundDelivery];')) { 39 | const regex = 40 | /- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions\s*\{\n/; 41 | delegateConfig.modResults.contents = 42 | delegateConfig.modResults.contents.replace( 43 | regex, 44 | (match) => `${match} [Terra setUpBackgroundDelivery];\n` 45 | ); 46 | } 47 | } 48 | 49 | return delegateConfig; 50 | }); 51 | 52 | return config; 53 | }; 54 | 55 | const pkg = require('terra-react/package.json'); 56 | export default createRunOncePlugin( 57 | withTerraBackgroundDelivery, 58 | pkg.name, 59 | pkg.version 60 | ); 61 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /example/src/samplePlannedWorkout.ts: -------------------------------------------------------------------------------- 1 | import { 2 | TerraPlannedWorkout, 3 | PlannedWorkoutMetaData, 4 | PlannedWorkoutStep, 5 | PlannedWorkoutRepeatStep, 6 | PlannedWorkoutStepsUnion, 7 | PlannedWorkoutStepDurationUnion, 8 | RepsPlannedWorkoutStepDuration, 9 | HRPlannedWorkoutStepTarget, 10 | PlannedWorkoutStepDurationType, 11 | PlannedWorkoutStepTargetType, 12 | } from 'terra-react'; 13 | 14 | // If your TerraActivityType enum is defined, import and use it. 15 | // For this sample, we assume RUNNING = 1. Adjust to your actual values. 16 | const RUNNING = 1; 17 | 18 | export function generateSamplePlannedWorkout(): TerraPlannedWorkout { 19 | const metadata = new PlannedWorkoutMetaData({ 20 | id: 'ceef601a-23e4-4393-8483-a9f6d37b0407', 21 | name: 'My Workout', 22 | description: 'This is a sample workout', 23 | type: RUNNING, // TerraActivityType.RUNNING 24 | planned_date: '2024-01-31T15:00:00+00:00', 25 | created_date: '2024-01-31T15:00:00+00:00', 26 | }); 27 | 28 | return new TerraPlannedWorkout({ 29 | steps: generatePlannedWorkoutSteps(), 30 | metadata, 31 | }); 32 | } 33 | 34 | export function generatePlannedWorkoutStepDurations(): PlannedWorkoutStepDurationUnion[] { 35 | const durations: PlannedWorkoutStepDurationUnion[] = []; 36 | // mimic Dart's Random().nextInt(10) + 1 37 | const reps = Math.floor(Math.random() * 10) + 1; 38 | durations.push( 39 | new RepsPlannedWorkoutStepDuration({ 40 | durationType: PlannedWorkoutStepDurationType.REPS, 41 | reps, 42 | }) 43 | ); 44 | return durations; 45 | } 46 | 47 | export function generatePlannedWorkoutStep(order: number): PlannedWorkoutStep { 48 | return new PlannedWorkoutStep({ 49 | type: 0, // simple step 50 | order, 51 | durations: generatePlannedWorkoutStepDurations(), 52 | targets: [ 53 | new HRPlannedWorkoutStepTarget({ 54 | targetType: PlannedWorkoutStepTargetType.HEARTRATE, 55 | hrBpmHigh: 170, 56 | }), 57 | ], 58 | }); 59 | } 60 | 61 | export function generatePlannedWorkoutRepeatStep(): PlannedWorkoutRepeatStep { 62 | return new PlannedWorkoutRepeatStep({ 63 | type: 1, // repeat step 64 | order: 0, 65 | durations: generatePlannedWorkoutStepDurations(), 66 | targets: [ 67 | new HRPlannedWorkoutStepTarget({ 68 | targetType: PlannedWorkoutStepTargetType.HEARTRATE, 69 | hrBpmHigh: 170, 70 | }), 71 | ], 72 | steps: [generatePlannedWorkoutStep(1)], 73 | }); 74 | } 75 | 76 | export function generatePlannedWorkoutSteps(): PlannedWorkoutStepsUnion[] { 77 | const steps: PlannedWorkoutStepsUnion[] = []; 78 | for (let i = 0; i < 1; i++) { 79 | steps.push(generatePlannedWorkoutStep(i)); 80 | } 81 | steps.push(generatePlannedWorkoutRepeatStep()); 82 | return steps; 83 | } 84 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | #import "AppDelegate.h" 8 | #import 9 | #import 10 | #import 11 | #import 12 | 13 | #ifdef FB_SONARKIT_ENABLED 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | 21 | static void InitializeFlipper(UIApplication *application) { 22 | FlipperClient *client = [FlipperClient sharedClient]; 23 | SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; 24 | [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; 25 | [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; 26 | [client addPlugin:[FlipperKitReactPlugin new]]; 27 | [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; 28 | [client start]; 29 | } 30 | #endif 31 | 32 | @implementation AppDelegate 33 | 34 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 35 | { 36 | #ifdef FB_SONARKIT_ENABLED 37 | InitializeFlipper(application); 38 | #endif 39 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 40 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge 41 | moduleName:@"TerraReactExample" 42 | initialProperties:nil]; 43 | 44 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 45 | 46 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 47 | UIViewController *rootViewController = [UIViewController new]; 48 | rootViewController.view = rootView; 49 | self.window.rootViewController = rootViewController; 50 | [self.window makeKeyAndVisible]; 51 | [Terra setUpBackgroundDelivery]; 52 | [Terra overwriteLogLevel:@"debug"]; 53 | return YES; 54 | } 55 | 56 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 57 | { 58 | #if DEBUG 59 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 60 | #else 61 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 62 | #endif 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BGTaskSchedulerPermittedIdentifiers 6 | 7 | co.tryterra.data.post.request 8 | 9 | NSHealthClinicalHealthRecordsShareUsageDescription 10 | Using TerraiOS to gather health data 11 | NSHealthShareUsageDescription 12 | Using TerraiOS as a mean of getting Health Data 13 | NSHealthUpdateUsageDescription 14 | Allow writing data to health kit 15 | CFBundleDevelopmentRegion 16 | en 17 | CFBundleDisplayName 18 | TerraReact Example 19 | CFBundleExecutable 20 | $(EXECUTABLE_NAME) 21 | CFBundleIdentifier 22 | $(PRODUCT_BUNDLE_IDENTIFIER) 23 | CFBundleInfoDictionaryVersion 24 | 6.0 25 | CFBundleName 26 | $(PRODUCT_NAME) 27 | CFBundlePackageType 28 | APPL 29 | CFBundleShortVersionString 30 | 1.0 31 | CFBundleSignature 32 | ???? 33 | CFBundleVersion 34 | 1 35 | LSRequiresIPhoneOS 36 | 37 | NFCReaderUsageDescription 38 | Scanning FSL Sensors for Glucose Data 39 | NSAppTransportSecurity 40 | 41 | NSAllowsArbitraryLoads 42 | 43 | NSAllowsArbitraryLoadsInWebContent 44 | 45 | NSAllowsLocalNetworking 46 | 47 | NSExceptionDomains 48 | 49 | localhost 50 | 51 | NSExceptionAllowsInsecureHTTPLoads 52 | 53 | 54 | 55 | 56 | NSHealthClinicalHealthRecordsShareUsageDescription 57 | Using TerraiOS to gather health data 58 | NSHealthShareUsageDescription 59 | Using TerraiOS as a mean of getting Health Data 60 | NSHealthUpdateUsageDescription 61 | Allow writing data to health kit 62 | NSLocationWhenInUseUsageDescription 63 | 64 | UILaunchStoryboardName 65 | LaunchScreen 66 | UIRequiredDeviceCapabilities 67 | 68 | armv7 69 | 70 | UISupportedInterfaceOrientations 71 | 72 | UIInterfaceOrientationPortrait 73 | UIInterfaceOrientationLandscapeLeft 74 | UIInterfaceOrientationLandscapeRight 75 | 76 | UIViewControllerBasedStatusBarAppearance 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/terrareact/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.terrareact; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import com.facebook.react.ReactPackage; 6 | import com.facebook.react.PackageList; 7 | import com.facebook.react.ReactApplication; 8 | import com.facebook.react.ReactNativeHost; 9 | import com.facebook.react.ReactInstanceManager; 10 | import com.facebook.soloader.SoLoader; 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.util.List; 13 | import java.util.ArrayList; 14 | 15 | import com.terrareact.BuildConfig; 16 | import com.terrareact.TerraReactPackage; 17 | 18 | public class MainApplication extends Application implements ReactApplication { 19 | private final ReactNativeHost mReactNativeHost = 20 | new ReactNativeHost(this) { 21 | @Override 22 | public boolean getUseDeveloperSupport() { 23 | return BuildConfig.DEBUG; 24 | } 25 | 26 | @Override 27 | protected List getPackages() { 28 | @SuppressWarnings("UnnecessaryLocalVariable") 29 | List packages = new PackageList(this).getPackages(); 30 | // Packages that cannot be autolinked yet can be added manually here, for TerraReactExample: 31 | // packages.add(new MyReactNativePackage()); 32 | // List packages = new ArrayList(); 33 | // packages.add(new TerraReactPackage()); 34 | return packages; 35 | } 36 | 37 | @Override 38 | protected String getJSMainModuleName() { 39 | return "index"; 40 | } 41 | 42 | }; 43 | 44 | @Override 45 | public ReactNativeHost getReactNativeHost() { 46 | return mReactNativeHost; 47 | } 48 | 49 | @Override 50 | public void onCreate() { 51 | super.onCreate(); 52 | SoLoader.init(this, /* native exopackage */ false); 53 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled 54 | } 55 | 56 | /** 57 | * Loads Flipper in React Native templates. 58 | * 59 | * @param context 60 | */ 61 | private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 62 | if (BuildConfig.DEBUG) { 63 | try { 64 | /* 65 | We use reflection here to pick up the class that initializes Flipper, 66 | since Flipper library is not available in release mode 67 | */ 68 | Class aClass = Class.forName("com.example.terrareact.ReactNativeFlipper"); 69 | aClass 70 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 71 | .invoke(null, context, reactInstanceManager); 72 | } catch (ClassNotFoundException e) { 73 | e.printStackTrace(); 74 | } catch (NoSuchMethodException e) { 75 | e.printStackTrace(); 76 | } catch (IllegalAccessException e) { 77 | e.printStackTrace(); 78 | } catch (InvocationTargetException e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/enums/ActivityTypes.ts: -------------------------------------------------------------------------------- 1 | export enum ActivityType { 2 | IN_VEHICLE = 0, 3 | BIKING = 1, 4 | STILL = 3, 5 | UNKNOWN = 4, 6 | TILTING = 5, 7 | WALKING = 7, 8 | RUNNING = 8, 9 | AEROBICS = 9, 10 | BADMINTON = 10, 11 | BASEBALL = 11, 12 | BASKETBALL = 12, 13 | BIATHLON = 13, 14 | HANDBIKING = 14, 15 | MOUNTAIN_BIKING = 15, 16 | ROAD_BIKING = 16, 17 | SPINNING = 17, 18 | STATIONARY_BIKING = 18, 19 | UTILITY_BIKING = 19, 20 | BOXING = 20, 21 | CALISTHENICS = 21, 22 | CIRCUIT_TRAINING = 22, 23 | CRICKET = 23, 24 | DANCING = 24, 25 | ELLIPTICAL = 25, 26 | FENCING = 26, 27 | AMERICAN_FOOTBALL = 27, 28 | AUSTRALIAN_FOOTBALL = 28, 29 | ENGLISH_FOOTBALL = 29, 30 | FRISBEE = 30, 31 | GARDENING = 31, 32 | GOLF = 32, 33 | GYMNASTICS = 33, 34 | HANDBALL = 34, 35 | HIKING = 35, 36 | HOCKEY = 36, 37 | HORSEBACK_RIDING = 37, 38 | HOUSEWORK = 38, 39 | JUMPING_ROPE = 39, 40 | KAYAKING = 40, 41 | KETTLEBELL_TRAINING = 41, 42 | KICKBOXING = 42, 43 | KITESURFING = 43, 44 | MARTIAL_ARTS = 44, 45 | MEDITATION = 45, 46 | MIXED_MARTIAL_ARTS = 46, 47 | P90X_EXERCISES = 47, 48 | PARAGLIDING = 48, 49 | PILATES = 49, 50 | POLO = 50, 51 | RACQUETBALL = 51, 52 | ROCK_CLIMBING = 52, 53 | ROWING = 53, 54 | ROWING_MACHINE = 54, 55 | RUGBY = 55, 56 | JOGGING = 56, 57 | RUNNING_ON_SAND = 57, 58 | TREADMILL_RUNNING = 58, 59 | SAILING = 59, 60 | SCUBA_DIVING = 60, 61 | SKATEBOARDING = 61, 62 | SKATING = 62, 63 | CROSS_SKATING = 63, 64 | INDOOR_ROLLERBLADING = 64, 65 | SKIING = 65, 66 | BACK_COUNTRY_SKIING = 66, 67 | CROSS_COUNTRY_SKIING = 67, 68 | DOWNHILL_SKIING = 68, 69 | KITE_SKIING = 69, 70 | ROLLER_SKIING = 70, 71 | SLEDDING = 71, 72 | SNOWBOARDING = 73, 73 | SNOWMOBILE = 74, 74 | SNOWSHOEING = 75, 75 | SQUASH = 76, 76 | STAIR_CLIMBING = 77, 77 | STAIR_CLIMBING_MACHINE = 78, 78 | STAND_UP_PADDLEBOARDING = 79, 79 | STRENGTH_TRAINING = 80, 80 | SURFING = 81, 81 | SWIMMING = 82, 82 | SWIMMING_SWIMMING_POOL = 83, 83 | SWIMMING_OPEN_WATER = 84, 84 | TABLE_TENNIS = 85, 85 | TEAM_SPORTS = 86, 86 | TENNIS = 87, 87 | TREADMILL = 88, 88 | VOLLEYBALL = 89, 89 | VOLLEYBALL_BEACH = 90, 90 | VOLLEYBALL_INDOOR = 91, 91 | WAKEBOARDING = 92, 92 | WALKING_FITNESS = 93, 93 | NORDIC_WALKING = 94, 94 | WALKING_TREADMILL = 95, 95 | WATERPOLO = 96, 96 | WEIGHTLIFTING = 97, 97 | WHEELCHAIR = 98, 98 | WINDSURFING = 99, 99 | YOGA = 100, 100 | ZUMBA = 101, 101 | DIVING = 102, 102 | ERGOMETER = 103, 103 | ICE_SKATING = 104, 104 | INDOOR_SKATING = 105, 105 | CURLING = 106, 106 | OTHER = 108, 107 | CROSSFIT = 113, 108 | HIIT = 114, 109 | INTERVAL_TRAINING = 115, 110 | WALKING_STROLLER = 116, 111 | ELEVATOR = 117, 112 | ESCALATOR = 118, 113 | ARCHERY = 119, 114 | SOFTBALL = 120, 115 | GUIDED_BREATHING = 122, 116 | CARDIO_TRAINING = 123, 117 | LACROSSE = 124, 118 | STRETCHING = 125, 119 | TRIATHLON = 126, 120 | INLINE_SKATING = 127, 121 | SKY_DIVING = 128, 122 | PADDLING = 129, 123 | MOUNTAINEERING = 130, 124 | FISHING = 131, 125 | WATER_SKIING = 132, 126 | } 127 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/example/terrareact/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example.terrareact; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin; 21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | public class ReactNativeFlipper { 28 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 29 | if (FlipperUtils.shouldEnableFlipper(context)) { 30 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 31 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 32 | client.addPlugin(new ReactFlipperPlugin()); 33 | client.addPlugin(new DatabasesFlipperPlugin(context)); 34 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 35 | client.addPlugin(CrashReporterPlugin.getInstance()); 36 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 37 | NetworkingModule.setCustomClientBuilder( 38 | new NetworkingModule.CustomClientBuilder() { 39 | @Override 40 | public void apply(OkHttpClient.Builder builder) { 41 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 42 | } 43 | }); 44 | client.addPlugin(networkFlipperPlugin); 45 | client.start(); 46 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 47 | // Hence we run if after all native modules have been initialized 48 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 49 | if (reactContext == null) { 50 | reactInstanceManager.addReactInstanceEventListener( 51 | new ReactInstanceManager.ReactInstanceEventListener() { 52 | @Override 53 | public void onReactContextInitialized(ReactContext reactContext) { 54 | reactInstanceManager.removeReactInstanceEventListener(this); 55 | reactContext.runOnNativeModulesQueueThread( 56 | new Runnable() { 57 | @Override 58 | public void run() { 59 | client.addPlugin(new FrescoFlipperPlugin()); 60 | } 61 | }); 62 | } 63 | }); 64 | } else { 65 | client.addPlugin(new FrescoFlipperPlugin()); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /.github/workflows/release_package.yml: -------------------------------------------------------------------------------- 1 | # author: https://superface.ai/blog/npm-publish-gh-actions-changelog 2 | 3 | name: Release package 4 | on: 5 | workflow_dispatch: 6 | inputs: 7 | release-type: 8 | description: 'Release type (one of): patch, minor, major, prepatch, preminor, premajor, prerelease' 9 | required: true 10 | jobs: 11 | release: 12 | runs-on: ubuntu-latest 13 | steps: 14 | # Checkout project repository 15 | - name: Checkout 16 | uses: actions/checkout@v2.3.4 17 | 18 | # Setup Node.js environment 19 | - name: Setup Node.js 20 | uses: actions/setup-node@v2 21 | with: 22 | registry-url: https://registry.npmjs.org/ 23 | node-version: '14' 24 | 25 | # Configure Git 26 | - name: Git configuration 27 | run: | 28 | git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" 29 | git config --global user.name "GitHub Actions" 30 | 31 | # Bump package version 32 | # Use tag latest 33 | - name: Bump release version 34 | if: startsWith(github.event.inputs.release-type, 'pre') != true 35 | run: | 36 | echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV 37 | echo "RELEASE_TAG=latest" >> $GITHUB_ENV 38 | env: 39 | RELEASE_TYPE: ${{ github.event.inputs.release-type }} 40 | 41 | # Bump package pre-release version 42 | # Use tag beta for pre-release versions 43 | - name: Bump pre-release version 44 | if: startsWith(github.event.inputs.release-type, 'pre') 45 | run: | 46 | echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE 47 | echo "RELEASE_TAG=beta" >> $GITHUB_ENV 48 | env: 49 | RELEASE_TYPE: ${{ github.event.inputs.release-type }} 50 | 51 | # Update changelog unreleased section with new version 52 | - name: Update changelog 53 | uses: superfaceai/release-changelog-action@v1 54 | with: 55 | path-to-changelog: CHANGELOG.md 56 | version: ${{ env.NEW_VERSION }} 57 | operation: release 58 | 59 | # Commit changes 60 | - name: Commit CHANGELOG.md and package.json changes and create tag 61 | run: | 62 | git add "package.json" 63 | git add "CHANGELOG.md" 64 | git commit -m "chore: release ${{ env.NEW_VERSION }}" 65 | git tag ${{ env.NEW_VERSION }} 66 | 67 | # Push repository changes 68 | - name: Push changes to repository 69 | env: 70 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 71 | run: | 72 | git push origin && git push --tags 73 | 74 | # Read version changelog 75 | - id: get-changelog 76 | name: Get version changelog 77 | uses: superfaceai/release-changelog-action@v1 78 | with: 79 | path-to-changelog: CHANGELOG.md 80 | version: ${{ env.NEW_VERSION }} 81 | operation: read 82 | 83 | # Update GitHub release with changelog 84 | - name: Update GitHub release documentation 85 | uses: softprops/action-gh-release@v1 86 | with: 87 | tag_name: ${{ env.NEW_VERSION }} 88 | body: ${{ steps.get-changelog.outputs.changelog }} 89 | prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }} 90 | env: 91 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 92 | 93 | # Publish version to public repository 94 | - name: Publish 95 | run: npm publish --verbose --access public --tag ${{ env.RELEASE_TAG }} 96 | env: 97 | NODE_AUTH_TOKEN: ${{ secrets.NPMJS_ACCESS_TOKEN }} 98 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample.xcodeproj/xcshareddata/xcschemes/TerraReactExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 51 | 52 | 53 | 54 | 64 | 66 | 72 | 73 | 74 | 75 | 81 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "terra-react", 3 | "version": "1.8.11", 4 | "description": "React Native SDK mapping for Terra API", 5 | "main": "lib/commonjs/index.js", 6 | "module": "lib/module/index.js", 7 | "types": "lib/typescript/src/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "exports": { 11 | ".": { 12 | "types": "./lib/typescript/src/index.d.ts", 13 | "import": "./lib/commonjs/index.js", 14 | "require": "./lib/commonjs/index.js", 15 | "default": "./lib/commonjs/index.js" 16 | }, 17 | "./package.json": "./package.json", 18 | "./app.plugin.js" : "./app.plugin.js" 19 | }, 20 | "files": [ 21 | "src", 22 | "plugin/build", 23 | "lib", 24 | "android/src", 25 | "android/build.gradle", 26 | "android/gradlew*", 27 | "android/gradle/wrapper/**", 28 | "app.plugin.js", 29 | "ios", 30 | "cpp", 31 | "terra-react.podspec", 32 | "!lib/typescript/example", 33 | "!android/build", 34 | "!android/bin", 35 | "!ios/build", 36 | "!**/__tests__", 37 | "!**/__fixtures__", 38 | "!**/__mocks__" 39 | ], 40 | "scripts": { 41 | "test": "jest", 42 | "typescript": "tsc --noEmit", 43 | "lint": "eslint \"**/*.{js,ts}\"", 44 | "prepare": "bob build && npm run build:plugin", 45 | "release": "release-it", 46 | "example": "yarn --cwd example", 47 | "pods": "cd example && pod-install --quiet", 48 | "bootstrap": "yarn example && yarn && yarn pods", 49 | "build": "tsc", 50 | "format": "prettier --write \"**/*.{js,ts}\"", 51 | "prepublishOnly": "npm test && npm run lint", 52 | "preversion": "npm run lint", 53 | "version": "npm run format && git add -A src", 54 | "postversion": "git push && git push --tags", 55 | "build:plugin": "rimraf plugin/build && tsc --build plugin" 56 | }, 57 | "keywords": [ 58 | "react-native", 59 | "ios", 60 | "android" 61 | ], 62 | "repository": "https://github.com/tryterra/terra-react", 63 | "author": "TerraDev (https://tryterra.co)", 64 | "license": "MIT", 65 | "bugs": { 66 | "url": "https://github.com/tryterra/terra-react/issues" 67 | }, 68 | "homepage": "https://github.com/tryterra/terra-react#readme", 69 | "publishConfig": { 70 | "registry": "https://registry.npmjs.org/" 71 | }, 72 | "devDependencies": { 73 | "@commitlint/config-conventional": "^11.0.0", 74 | "@expo/config-plugins": "^10.0.2", 75 | "@react-native-community/eslint-config": "^2.0.0", 76 | "@release-it/conventional-changelog": "^2.0.0", 77 | "@types/jest": "^26.0.0", 78 | "@types/react": "^16.9.19", 79 | "@types/react-native": "0.62.13", 80 | "commitlint": "^11.0.0", 81 | "eslint": "^7.2.0", 82 | "eslint-config-prettier": "^7.0.0", 83 | "eslint-plugin-prettier": "^3.1.3", 84 | "husky": "^6.0.0", 85 | "jest": "^26.6.3", 86 | "pod-install": "^0.1.0", 87 | "prettier": "^2.7.1", 88 | "react": "18.0.0", 89 | "react-native": "0.69", 90 | "react-native-builder-bob": "^0.18.2", 91 | "release-it": "^14.2.2", 92 | "typescript": "^4.1.3" 93 | }, 94 | "peerDependencies": { 95 | "react": "*", 96 | "react-native": "*" 97 | }, 98 | "jest": { 99 | "preset": "react-native", 100 | "modulePathIgnorePatterns": [ 101 | "/example/node_modules", 102 | "/lib/" 103 | ] 104 | }, 105 | "commitlint": { 106 | "extends": [ 107 | "@commitlint/config-conventional" 108 | ] 109 | }, 110 | "release-it": { 111 | "git": { 112 | "commitMessage": "chore: release ${version}", 113 | "tagName": "v${version}" 114 | }, 115 | "npm": { 116 | "publish": true 117 | }, 118 | "github": { 119 | "release": true 120 | }, 121 | "plugins": { 122 | "@release-it/conventional-changelog": { 123 | "preset": "angular" 124 | } 125 | } 126 | }, 127 | "eslintConfig": { 128 | "root": true, 129 | "extends": [ 130 | "@react-native-community", 131 | "prettier" 132 | ], 133 | "rules": { 134 | "prettier/prettier": [ 135 | "error", 136 | { 137 | "quoteProps": "consistent", 138 | "singleQuote": true, 139 | "tabWidth": 2, 140 | "trailingComma": "es5", 141 | "useTabs": false 142 | } 143 | ] 144 | } 145 | }, 146 | "eslintIgnore": [ 147 | "node_modules/", 148 | "lib/" 149 | ], 150 | "prettier": { 151 | "quoteProps": "consistent", 152 | "singleQuote": true, 153 | "tabWidth": 2, 154 | "trailingComma": "es5", 155 | "useTabs": false 156 | }, 157 | "react-native-builder-bob": { 158 | "source": "src", 159 | "output": "lib", 160 | "targets": [ 161 | "commonjs", 162 | "module", 163 | [ 164 | "typescript", 165 | { 166 | "project": "tsconfig.build.json" 167 | } 168 | ] 169 | ] 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /ios/TerraReact.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jaafar Rammal on 06/06/2022. 3 | // 4 | 5 | #import 6 | 7 | @interface RCT_EXTERN_MODULE(TerraReact, NSObject) 8 | 9 | // init 10 | RCT_EXTERN_METHOD( 11 | initTerra: (NSString *)devID 12 | referenceId: (NSString *)referenceId 13 | resolve: (RCTPromiseResolveBlock)resolve 14 | rejecter: (RCTPromiseRejectBlock)reject 15 | ) 16 | 17 | // initConnection 18 | RCT_EXTERN_METHOD( 19 | initConnection: (NSString *)connection 20 | token: (NSString *)token 21 | schedulerOn: (BOOL)schedulerOn 22 | customPermissions: (NSArray *)customPermissions 23 | startIntent: (NSString *)startIntent 24 | resolve: (RCTPromiseResolveBlock)resolve 25 | rejecter: (RCTPromiseRejectBlock)reject 26 | ) 27 | 28 | // check connection 29 | RCT_EXTERN_METHOD( 30 | checkAuth: (NSString *)connection 31 | devID: (NSString *)devID 32 | resolve: (RCTPromiseResolveBlock)resolve 33 | rejecter: (RCTPromiseRejectBlock)reject 34 | ) 35 | 36 | RCT_EXTERN_METHOD( 37 | getUserId: (NSString *)connection 38 | resolve: (RCTPromiseResolveBlock)resolve 39 | rejecter: (RCTPromiseRejectBlock)reject 40 | ) 41 | 42 | // getters 43 | RCT_EXTERN_METHOD( 44 | getAthlete: (NSString *)connection 45 | toWebhook: (BOOL)toWebhook 46 | resolve: (RCTPromiseResolveBlock)resolve 47 | rejecter: (RCTPromiseRejectBlock)reject 48 | ) 49 | RCT_EXTERN_METHOD( 50 | getBody: (NSString *)connection 51 | startDate: (NSDate *)startDate 52 | endDate: (NSDate *)endDate 53 | latestReading: (BOOL) latestReading 54 | toWebhook: (BOOL)toWebhook 55 | resolve: (RCTPromiseResolveBlock)resolve 56 | rejecter: (RCTPromiseRejectBlock)reject 57 | ) 58 | RCT_EXTERN_METHOD( 59 | getDaily: (NSString *)connection 60 | startDate: (NSDate *)startDate 61 | endDate:(NSDate *)endDate 62 | toWebhook: (BOOL)toWebhook 63 | resolve: (RCTPromiseResolveBlock)resolve 64 | rejecter: (RCTPromiseRejectBlock)reject 65 | ) 66 | RCT_EXTERN_METHOD( 67 | getSleep: (NSString *)connection 68 | startDate: (NSDate *)startDate 69 | endDate:(NSDate *)endDate 70 | toWebhook: (BOOL)toWebhook 71 | resolve: (RCTPromiseResolveBlock)resolve 72 | rejecter: (RCTPromiseRejectBlock)reject 73 | ) 74 | RCT_EXTERN_METHOD( 75 | getActivity: (NSString *)connection 76 | startDate: (NSDate *)startDate 77 | endDate:(NSDate *)endDate 78 | toWebhook: (BOOL)toWebhook 79 | resolve: (RCTPromiseResolveBlock)resolve 80 | rejecter: (RCTPromiseRejectBlock)reject 81 | ) 82 | RCT_EXTERN_METHOD( 83 | getMenstruation: (NSString *)connection 84 | startDate: (NSDate *)startDate 85 | endDate:(NSDate *)endDate 86 | toWebhook: (BOOL)toWebhook 87 | resolve: (RCTPromiseResolveBlock)resolve 88 | rejecter: (RCTPromiseRejectBlock)reject 89 | ) 90 | RCT_EXTERN_METHOD( 91 | getNutrition: (NSString *)connection 92 | startDate: (NSDate *)startDate 93 | endDate:(NSDate *)endDate 94 | toWebhook: (BOOL)toWebhook 95 | resolve: (RCTPromiseResolveBlock)resolve 96 | rejecter: (RCTPromiseRejectBlock)reject 97 | ) 98 | 99 | RCT_EXTERN_METHOD( 100 | postActivity: (NSString *)connection 101 | payload: (NSDictionary *)payload 102 | resolve: (RCTPromiseResolveBlock)resolve 103 | rejecter: (RCTPromiseRejectBlock)reject 104 | ) 105 | 106 | // Freestyle glucose init 107 | RCT_EXTERN_METHOD( 108 | readGlucoseData:(RCTPromiseResolveBlock)resolve 109 | rejecter: (RCTPromiseRejectBlock)reject 110 | ) 111 | 112 | RCT_EXTERN_METHOD( 113 | activateSensor:(RCTPromiseResolveBlock)resolve 114 | rejecter: (RCTPromiseRejectBlock)reject 115 | ) 116 | 117 | RCT_EXTERN_METHOD( 118 | isHealthConnectAvailable:(RCTPromiseResolveBlock)resolve 119 | rejecter: (RCTPromiseRejectBlock)reject 120 | ) 121 | 122 | RCT_EXTERN_METHOD( 123 | openHealthConnect:(RCTPromiseResolveBlock)resolve 124 | rejecter: (RCTPromiseRejectBlock)reject 125 | ) 126 | 127 | RCT_EXTERN_METHOD( 128 | grantedPermissions:(RCTPromiseResolveBlock)resolve 129 | rejecter: (RCTPromiseRejectBlock)reject 130 | ) 131 | 132 | RCT_EXTERN_METHOD( 133 | setIgnoredSources:(NSArray *)ignoredSources 134 | resolve: (RCTPromiseResolveBlock)resolve 135 | rejecter: (RCTPromiseRejectBlock)reject 136 | ) 137 | 138 | RCT_EXTERN_METHOD( 139 | getPlannedWorkouts: (NSString *)connection 140 | resolve: (RCTPromiseResolveBlock)resolve 141 | rejecter: (RCTPromiseRejectBlock)reject 142 | ) 143 | 144 | RCT_EXTERN_METHOD( 145 | deletePlannedWorkout: (NSString *)connection 146 | workoutId: (NSString *)workoutId 147 | resolve: (RCTPromiseResolveBlock)resolve 148 | rejecter: (RCTPromiseRejectBlock)reject 149 | ) 150 | 151 | RCT_EXTERN_METHOD( 152 | completePlannedWorkout: (NSString *)connection 153 | workoutId: (NSString *)workoutId 154 | at: (NSString *)atIso 155 | resolve: (RCTPromiseResolveBlock)resolve 156 | rejecter: (RCTPromiseRejectBlock)reject 157 | ) 158 | 159 | RCT_EXTERN_METHOD( 160 | postPlannedWorkout: (NSString *)connection 161 | payload: (NSString *)payload 162 | resolve: (RCTPromiseResolveBlock)resolve 163 | rejecter: (RCTPromiseRejectBlock)reject 164 | ) 165 | 166 | 167 | @end 168 | -------------------------------------------------------------------------------- /example/ios/TerraReactExample/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import { StyleSheet, View, Text } from 'react-native'; 4 | import { 5 | Connections, 6 | getDaily, 7 | getUserId, 8 | getActivity, 9 | initTerra, 10 | initConnection, 11 | getMenstruation, 12 | getBody, 13 | getNutrition, 14 | getSleep, 15 | checkAuth, 16 | setIgnoredSources, 17 | postPlannedWorkout, 18 | getPlannedWorkouts, 19 | deletePlannedWorkout, 20 | } from 'terra-react'; 21 | import { config } from './config'; 22 | import { generateSamplePlannedWorkout } from './samplePlannedWorkout'; 23 | 24 | export default function App() { 25 | // after showing the widget to the users 26 | // initialise accordingle which connection / reference_id 27 | // example if user wants connect Google using SDK 28 | // you can have multiple connections in the array 29 | 30 | const [results, setResults] = React.useState({}); 31 | 32 | function initThings(devId: string, token: string, connection: Connections) { 33 | setIgnoredSources(['com.apple.Health']); 34 | initTerra(devId, 'reid').then((aa) => { 35 | setResults((r) => ({ ...r, initTerra: aa.success })); 36 | initConnection(connection, token, true).then((a) => { 37 | setResults((r) => ({ ...r, initConnection: a.success })); 38 | let startDate = new Date(); 39 | startDate.setMonth(8); 40 | startDate.setDate(10); 41 | startDate.setHours(0); 42 | startDate.setMinutes(0); 43 | startDate.setSeconds(0); 44 | let endDate = new Date(); 45 | getActivity(connection, startDate, new Date()) 46 | .then((d: any) => console.log(d)) 47 | .catch((e: any) => console.log(e)); 48 | getBody(connection, startDate, new Date(), true, false) 49 | .then((d: any) => { 50 | setResults((r) => ({ ...r, getBody: d.success })); 51 | }) 52 | .catch((e: any) => console.log(e)); 53 | getDaily(connection, startDate, endDate, false) 54 | .then((d: any) => { 55 | setResults((r) => ({ ...r, getDaily: d.success })); 56 | console.log(JSON.stringify(d.data)); 57 | }) 58 | .catch((e: any) => console.log(e)); 59 | getMenstruation(connection, startDate, new Date()) 60 | .then((d: any) => 61 | setResults((r) => ({ ...r, getMenstruation: d.success })) 62 | ) 63 | .catch((e: any) => console.log(e)); 64 | getNutrition(connection, startDate, new Date()) 65 | .then((d: any) => 66 | setResults((r) => ({ ...r, getNutrition: d.success })) 67 | ) 68 | .catch((e: any) => console.log(e)); 69 | getSleep(connection, startDate, new Date()) 70 | .then((d: any) => setResults((r) => ({ ...r, getSleep: d.success }))) 71 | .catch((e: any) => console.log(e)); 72 | // readGlucoseData().then((d) => {console.log(d.data.blood_glucose_samples);}); 73 | // postActivity(connection, {metadata: {start_time: "2024-11-01T04:00:00+01:00", end_time: "2024-11-01T05:00:00+01:00", type: 8, upload_type: 1}, device_data: {name: "Equinox"}, distance_data: {summary: {distance_meters: 1000}}, calories_data: {net_activity_calories: 200}}).then((d) => { 74 | // console.log(d) 75 | // }) 76 | getUserId(connection) 77 | .then((de) => { 78 | console.log(de.userId); 79 | setResults((r) => ({ ...r, getUserId: de.userId })); 80 | }) 81 | .catch((ee) => console.log(ee)); 82 | checkAuth(connection, devId).then((d) => { 83 | console.log(d); 84 | }); 85 | postPlannedWorkoutFlow() 86 | }); 87 | }); 88 | } 89 | 90 | async function postPlannedWorkoutFlow() { 91 | try { 92 | const workout = generateSamplePlannedWorkout(); 93 | const resp = await postPlannedWorkout(Connections.APPLE_HEALTH, workout); 94 | console.log('post success:', resp?.success ?? false); 95 | 96 | const postedPlannedWorkouts = await getPlannedWorkouts(Connections.APPLE_HEALTH); 97 | console.log('getPlannedWorkouts data:', postedPlannedWorkouts?.data ?? 'No data'); 98 | 99 | // 3. Optionally mark as complete 100 | // const markComplete = await completePlannedWorkout( 101 | // connection, 102 | // 'ceef601a-23e4-4393-8483-a9f6d37b0407', 103 | // new Date() 104 | // ); 105 | // console.log('complete success:', markComplete?.success ?? false); 106 | 107 | // 4. Delete workout 108 | // const deleteWorkout = await deletePlannedWorkout( 109 | // Connections.APPLE_HEALTH, 110 | // 'ceef601a-23e4-4393-8483-a9f6d37b0407' 111 | // ); 112 | // console.log('delete success:', deleteWorkout?.success ?? false); 113 | } catch (e) { 114 | console.error('error in planned workout flow', e); 115 | } 116 | } 117 | 118 | React.useEffect(() => { 119 | const devId = config.devId; 120 | const apiKey = config.apiKey; 121 | const connection = Connections.APPLE_HEALTH; 122 | fetch('https://api.tryterra.co/v2/auth/generateAuthToken', { 123 | method: 'POST', 124 | headers: { 125 | 'dev-id': devId, 126 | 'x-api-key': apiKey, 127 | }, 128 | }) 129 | .then((response) => response.json()) 130 | .then((result) => initThings(devId, result.token, connection)) 131 | .catch((error) => console.log('error', error)); 132 | }, []); 133 | 134 | return ( 135 | 136 | Hello from Terra 137 | {Object.entries(results).map(([k, v], i) => ( 138 | 139 | {k}: {v !== undefined || v !== null ? v!.toString() : 'undefined'} 140 | 141 | ))} 142 | 143 | ); 144 | } 145 | 146 | const styles = StyleSheet.create({ 147 | container: { 148 | flex: 1, 149 | alignItems: 'center', 150 | justifyContent: 'center', 151 | }, 152 | box: { 153 | width: 60, 154 | height: 60, 155 | marginVertical: 20, 156 | }, 157 | }); 158 | -------------------------------------------------------------------------------- /src/models/Activity.ts: -------------------------------------------------------------------------------- 1 | import { ActivityType } from '../enums/ActivityTypes'; 2 | import { UploadType } from '../enums/UploadType'; 3 | import { Option } from '../helpers'; 4 | import { ActivityLevelSample } from './samples/ActivityLevelSample'; 5 | import { CadenceSample } from './samples/CadenceSample'; 6 | import { DistanceSample } from './samples/DistanceSample'; 7 | import { ElevationSample } from './samples/ElevationSample'; 8 | import { FloorsClimbedSample } from './samples/FloorsClimbedSample'; 9 | import { HeartRateDataSample } from './samples/HeartRateDataSample'; 10 | import { HeartRateVariabilityDataSampleRMSSD } from './samples/HeartRateVariabilityDataSampleRMSSD'; 11 | import { HeartRateVariabilityDataSampleSDNN } from './samples/HeartRateVariabilityDataSampleSDNN'; 12 | import { HeartRateZoneData } from './samples/HeartRateZoneData'; 13 | import { LapSample } from './samples/LapSample'; 14 | import { METSample } from './samples/METSample'; 15 | import { OtherDeviceData } from './samples/OtherDeviceData'; 16 | import { OxygenSaturationSample } from './samples/OxygenSaturationSample'; 17 | import { PositionSample } from './samples/PositionSample'; 18 | import { PowerSample } from './samples/PowerSample'; 19 | import { StepSample } from './samples/StepSample'; 20 | import { SpeedSample } from './samples/SpeedSample'; 21 | import { TSSSample } from './samples/TSSSample'; 22 | import { Vo2MaxSample } from './samples/Vo2MaxSample'; 23 | 24 | export interface Activity { 25 | movement_data?: { 26 | normalized_speed_meters_per_second?: Option; 27 | max_cadence_rpm?: Option; 28 | avg_speed_meters_per_second?: Option; 29 | avg_pace_minutes_per_kilometer?: Option; 30 | max_velocity_meters_per_second?: Option; 31 | max_pace_minutes_per_kilometer?: Option; 32 | max_torque_newton_meters?: Option; 33 | avg_cadence_rpm?: Option; 34 | avg_velocity_meters_per_second?: Option; 35 | avg_torque_newton_meters?: Option; 36 | cadence_samples?: Array; 37 | speed_samples?: Array; 38 | max_speed_meters_per_second?: Option; 39 | }; 40 | power_data?: { 41 | max_watts?: Option; 42 | avg_watts?: Option; 43 | power_samples?: Array; 44 | }; 45 | position_data?: { 46 | position_samples?: Array; 47 | center_pos_lat_lng_deg?: [number, number]; 48 | start_pos_lat_lng_deg?: [number, number]; 49 | end_pos_lat_lng_deg?: [number, number]; 50 | }; 51 | oxygen_data?: { 52 | saturation_samples?: Array; 53 | avg_saturation_percentage?: Option; 54 | vo2_samples?: Array; 55 | vo2max_ml_per_min_per_kg?: Option; 56 | }; 57 | metadata: { 58 | name?: Option; 59 | summary_id?: Option; 60 | country?: Option; 61 | state?: Option; 62 | upload_type?: UploadType; 63 | end_time: string; 64 | city?: Option; 65 | type: Option; 66 | start_time: string; 67 | }; 68 | TSS_data?: { 69 | TSS_samples?: Array; 70 | }; 71 | device_data: { 72 | name?: Option; 73 | other_devices?: Array; 74 | hardware_version?: Option; 75 | manufacturer?: Option; 76 | software_version?: Option; 77 | activation_timestamp?: Option; 78 | serial_number?: Option; 79 | }; 80 | distance_data?: { 81 | summary?: { 82 | swimming?: { 83 | num_strokes?: Option; 84 | num_laps?: Option; 85 | pool_length_meters?: Option; 86 | }; 87 | floors_climbed?: number; 88 | elevation?: { 89 | loss_actual_meters?: Option; 90 | min_meters?: Option; 91 | avg_meters?: Option; 92 | gain_actual_meters?: Option; 93 | max_meters?: Option; 94 | gain_planned_meters?: Option; 95 | }; 96 | steps?: Option; 97 | distance_meters?: Option; 98 | }; 99 | detailed?: { 100 | step_samples?: Array; 101 | distance_samples?: Array; 102 | elevation_samples?: Array; 103 | floors_climbed_samples?: Array; 104 | }; 105 | }; 106 | calories_data?: { 107 | net_intake_calories?: Option; 108 | BMR_calories?: Option; 109 | total_burned_calories?: Option; 110 | net_activity_calories?: Option; 111 | }; 112 | lap_data?: { 113 | laps?: Array; 114 | }; 115 | MET_data?: { 116 | MET_samples?: Array; 117 | num_low_intensity_minutes?: Option; 118 | num_high_intensity_minutes?: Option; 119 | num_inactive_minutes?: Option; 120 | num_moderate_intensity_minutes?: Option; 121 | avg_level?: Option; 122 | }; 123 | heart_rate_data?: { 124 | summary?: { 125 | max_hr_bpm?: Option; 126 | resting_hr_bpm?: Option; 127 | avg_hrv_rmssd?: Option; 128 | min_hr_bpm?: Option; 129 | user_max_hr_bpm?: Option; 130 | avg_hrv_sdnn?: Option; 131 | avg_hr_bpm?: Option; 132 | hr_zone_data?: Array; 133 | }; 134 | detailed?: { 135 | hr_samples?: Array; 136 | hrv_samples_sdnn?: Array; 137 | hrv_samples_rmssd?: Array; 138 | }; 139 | }; 140 | active_durations_data?: { 141 | activity_seconds?: Option; 142 | rest_seconds?: Option; 143 | low_intensity_seconds?: Option; 144 | activity_levels_samples?: Array; 145 | vigorous_intensity_seconds?: Option; 146 | num_continuous_inactive_periods?: Option; 147 | inactivity_seconds?: Option; 148 | moderate_intensity_seconds?: Option; 149 | }; 150 | polyline_map_data?: { 151 | summary_polyline?: Option; 152 | }; 153 | strain_data?: { 154 | strain_level?: Option; 155 | }; 156 | work_data?: { 157 | work_kilojoules?: Option; 158 | }; 159 | energy_data?: { 160 | energy_kilojoules?: Option; 161 | energy_planned_kilojoules?: Option; 162 | }; 163 | } 164 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn 11 | ``` 12 | 13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 14 | 15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 16 | 17 | To start the packager: 18 | 19 | ```sh 20 | yarn example start 21 | ``` 22 | 23 | To run the example app on Android: 24 | 25 | ```sh 26 | yarn example android 27 | ``` 28 | 29 | To run the example app on iOS: 30 | 31 | ```sh 32 | yarn example ios 33 | ``` 34 | 35 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 36 | 37 | ```sh 38 | yarn typescript 39 | yarn lint 40 | ``` 41 | 42 | To fix formatting errors, run the following: 43 | 44 | ```sh 45 | yarn lint --fix 46 | ``` 47 | 48 | Remember to add tests for your change if possible. Run the unit tests by: 49 | 50 | ```sh 51 | yarn test 52 | ``` 53 | 54 | To edit the Objective-C files, open `example/ios/TerraReactExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > terra-react`. 55 | 56 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `terrareact` under `Android`. 57 | 58 | ### Commit message convention 59 | 60 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 61 | 62 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 63 | - `feat`: new features, e.g. add new method to the module. 64 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 65 | - `docs`: changes into documentation, e.g. add usage example for the module.. 66 | - `test`: adding or updating tests, e.g. add integration tests using detox. 67 | - `chore`: tooling changes, e.g. change CI config. 68 | 69 | Our pre-commit hooks verify that your commit message matches this format when committing. 70 | 71 | ### Linting and tests 72 | 73 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 74 | 75 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 76 | 77 | Our pre-commit hooks verify that the linter and tests pass when committing. 78 | 79 | ### Publishing to npm 80 | 81 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 82 | 83 | To publish new versions, run the following: 84 | 85 | ```sh 86 | yarn release 87 | ``` 88 | 89 | ### Scripts 90 | 91 | The `package.json` file contains various scripts for common tasks: 92 | 93 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 94 | - `yarn typescript`: type-check files with TypeScript. 95 | - `yarn lint`: lint files with ESLint. 96 | - `yarn test`: run unit tests with Jest. 97 | - `yarn example start`: start the Metro server for the example app. 98 | - `yarn example android`: run the example app on Android. 99 | - `yarn example ios`: run the example app on iOS. 100 | 101 | ### Sending a pull request 102 | 103 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 104 | 105 | When you're sending a pull request: 106 | 107 | - Prefer small pull requests focused on one change. 108 | - Verify that linters and tests are passing. 109 | - Review the documentation to make sure it looks good. 110 | - Follow the pull request template when opening a pull request. 111 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 112 | 113 | ## Code of Conduct 114 | 115 | ### Our Pledge 116 | 117 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 118 | 119 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 120 | 121 | ### Our Standards 122 | 123 | Examples of behavior that contributes to a positive environment for our community include: 124 | 125 | - Demonstrating empathy and kindness toward other people 126 | - Being respectful of differing opinions, viewpoints, and experiences 127 | - Giving and gracefully accepting constructive feedback 128 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 129 | - Focusing on what is best not just for us as individuals, but for the overall community 130 | 131 | Examples of unacceptable behavior include: 132 | 133 | - The use of sexualized language or imagery, and sexual attention or 134 | advances of any kind 135 | - Trolling, insulting or derogatory comments, and personal or political attacks 136 | - Public or private harassment 137 | - Publishing others' private information, such as a physical or email 138 | address, without their explicit permission 139 | - Other conduct which could reasonably be considered inappropriate in a 140 | professional setting 141 | 142 | ### Enforcement Responsibilities 143 | 144 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 145 | 146 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 147 | 148 | ### Scope 149 | 150 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 151 | 152 | ### Enforcement 153 | 154 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 155 | 156 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 157 | 158 | ### Enforcement Guidelines 159 | 160 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 161 | 162 | #### 1. Correction 163 | 164 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 165 | 166 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 167 | 168 | #### 2. Warning 169 | 170 | **Community Impact**: A violation through a single incident or series of actions. 171 | 172 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 173 | 174 | #### 3. Temporary Ban 175 | 176 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 177 | 178 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 179 | 180 | #### 4. Permanent Ban 181 | 182 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 183 | 184 | **Consequence**: A permanent ban from any sort of public interaction within the community. 185 | 186 | ### Attribution 187 | 188 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 189 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 190 | 191 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 192 | 193 | [homepage]: https://www.contributor-covenant.org 194 | 195 | For answers to common questions about this code of conduct, see the FAQ at 196 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 197 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // https://reactnative.dev/docs/performance#enable-the-ram-format 22 | * bundleCommand: "ram-bundle", 23 | * 24 | * // whether to bundle JS and assets in debug mode 25 | * bundleInDebug: false, 26 | * 27 | * // whether to bundle JS and assets in release mode 28 | * bundleInRelease: true, 29 | * 30 | * // whether to bundle JS and assets in another build variant (if configured). 31 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 32 | * // The configuration property can be in the following formats 33 | * // 'bundleIn${productFlavor}${buildType}' 34 | * // 'bundleIn${buildType}' 35 | * // bundleInFreeDebug: true, 36 | * // bundleInPaidRelease: true, 37 | * // bundleInBeta: true, 38 | * 39 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 40 | * // for TerraReactExample: to disable dev mode in the staging build type (if configured) 41 | * devDisabledInStaging: true, 42 | * // The configuration property can be in the following formats 43 | * // 'devDisabledIn${productFlavor}${buildType}' 44 | * // 'devDisabledIn${buildType}' 45 | * 46 | * // the root of your project, i.e. where "package.json" lives 47 | * root: "../../", 48 | * 49 | * // where to put the JS bundle asset in debug mode 50 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 51 | * 52 | * // where to put the JS bundle asset in release mode 53 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 54 | * 55 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 56 | * // require('./image.png')), in debug mode 57 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 58 | * 59 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 60 | * // require('./image.png')), in release mode 61 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 62 | * 63 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 64 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 65 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 66 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 67 | * // for TerraReactExample, you might want to remove it from here. 68 | * inputExcludes: ["android/**", "ios/**"], 69 | * 70 | * // override which node gets called and with what additional arguments 71 | * nodeExecutableAndArgs: ["node"], 72 | * 73 | * // supply additional arguments to the packager 74 | * extraPackagerArgs: [] 75 | * ] 76 | */ 77 | 78 | project.ext.react = [ 79 | enableHermes: false, // clean and rebuild if changing 80 | entryFile: "index.tsx", 81 | ] 82 | 83 | apply from: "../../node_modules/react-native/react.gradle" 84 | 85 | /** 86 | * Set this to true to create two separate APKs instead of one: 87 | * - An APK that only works on ARM devices 88 | * - An APK that only works on x86 devices 89 | * The advantage is the size of the APK is reduced by about 4MB. 90 | * Upload all the APKs to the Play Store and people will download 91 | * the correct one based on the CPU architecture of their device. 92 | */ 93 | def enableSeparateBuildPerCPUArchitecture = false 94 | 95 | /** 96 | * Run Proguard to shrink the Java bytecode in release builds. 97 | */ 98 | def enableProguardInReleaseBuilds = false 99 | 100 | /** 101 | * The preferred build flavor of JavaScriptCore. 102 | * 103 | * For TerraReactExample, to use the international variant, you can use: 104 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 105 | * 106 | * The international variant includes ICU i18n library and necessary data 107 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 108 | * give correct results when using with locales other than en-US. Note that 109 | * this variant is about 6MiB larger per architecture than default. 110 | */ 111 | def jscFlavor = 'org.webkit:android-jsc:+' 112 | 113 | /** 114 | * Whether to enable the Hermes VM. 115 | * 116 | * This should be set on project.ext.react and mirrored here. If it is not set 117 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 118 | * and the benefits of using Hermes will therefore be sharply reduced. 119 | */ 120 | def enableHermes = project.ext.react.get("enableHermes", false); 121 | 122 | android { 123 | compileSdkVersion rootProject.ext.compileSdkVersion 124 | 125 | compileOptions { 126 | sourceCompatibility JavaVersion.VERSION_1_8 127 | targetCompatibility JavaVersion.VERSION_1_8 128 | } 129 | 130 | defaultConfig { 131 | applicationId "com.example.terrareact" 132 | minSdkVersion rootProject.ext.minSdkVersion 133 | targetSdkVersion rootProject.ext.targetSdkVersion 134 | versionCode 1 135 | versionName "1.0" 136 | multiDexEnabled true 137 | 138 | } 139 | 140 | splits { 141 | abi { 142 | reset() 143 | enable enableSeparateBuildPerCPUArchitecture 144 | universalApk false // If true, also generate a universal APK 145 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 146 | } 147 | } 148 | signingConfigs { 149 | debug { 150 | storeFile file('debug.keystore') 151 | storePassword 'android' 152 | keyAlias 'androiddebugkey' 153 | keyPassword 'android' 154 | } 155 | } 156 | buildTypes { 157 | debug { 158 | signingConfig signingConfigs.debug 159 | } 160 | release { 161 | // Caution! In production, you need to generate your own keystore file. 162 | // see https://reactnative.dev/docs/signed-apk-android. 163 | signingConfig signingConfigs.debug 164 | minifyEnabled enableProguardInReleaseBuilds 165 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 166 | } 167 | } 168 | // applicationVariants are e.g. debug, release 169 | applicationVariants.all { variant -> 170 | variant.outputs.each { output -> 171 | // For each separate APK per architecture, set a unique version code as described here: 172 | // https://developer.android.com/studio/build/configure-apk-splits.html 173 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 174 | def abi = output.getFilter(OutputFile.ABI) 175 | if (abi != null) { // null for the universal-debug, universal-release variants 176 | output.versionCodeOverride = 177 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 178 | } 179 | 180 | } 181 | } 182 | 183 | packagingOptions { 184 | pickFirst 'lib/x86/libc++_shared.so' 185 | pickFirst 'lib/x86_64/libc++_shared.so' 186 | pickFirst 'lib/armeabi-v7a/libc++_shared.so' 187 | pickFirst 'lib/arm64-v8a/libc++_shared.so' 188 | pickFirst 'lib/arm64-v8a/libfbjni.so' 189 | pickFirst 'lib/armeabi-v7a/libfbjni.so' 190 | pickFirst 'lib/x86_64/libfbjni.so' 191 | pickFirst 'lib/x86/libfbjni.so' 192 | } 193 | rootProject.ext.ffmpegKitPackage = "video" 194 | namespace "com.example.terrareact" 195 | 196 | } 197 | 198 | dependencies { 199 | implementation fileTree(dir: "libs", include: ["*.jar"]) 200 | //noinspection GradleDynamicVersion 201 | implementation "com.facebook.react:react-native:+" // From node_modules 202 | implementation 'androidx.core:core-ktx:1.8.0' 203 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 204 | 205 | implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' 206 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { 207 | exclude group:'com.facebook.fbjni' 208 | } 209 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 210 | exclude group:'com.facebook.flipper' 211 | exclude group:'com.squareup.okhttp3', module:'okhttp' 212 | } 213 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { 214 | exclude group:'com.facebook.flipper' 215 | } 216 | 217 | if (enableHermes) { 218 | def hermesPath = "../../node_modules/hermes-engine/android/"; 219 | debugImplementation files(hermesPath + "hermes-debug.aar") 220 | releaseImplementation files(hermesPath + "hermes-release.aar") 221 | } else { 222 | implementation jscFlavor 223 | } 224 | 225 | // implementation project(':terrareact') 226 | } 227 | 228 | // // Run this once to be able to run the application with BUCK 229 | // puts all compile dependencies into folder libs for BUCK to use 230 | task copyDownloadableDepsToLibs(type: Copy) { 231 | from configurations.implementation 232 | into 'libs' 233 | } 234 | 235 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 236 | -------------------------------------------------------------------------------- /ios/TerraReact.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F4FF95D7245B92E800C19C63 /* TerraReact.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* TerraReact.swift */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 134814201AA4EA6300B7C361 /* libTerraReact.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTerraReact.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 9B4A77942CD523B5000941A0 /* TerraActivityData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerraActivityData.swift; sourceTree = ""; }; 28 | B3E7B5891CC2AC0600A0062D /* TerraReact.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TerraReact.m; sourceTree = ""; }; 29 | F4FF95D5245B92E700C19C63 /* TerraReact-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TerraReact-Bridging-Header.h"; sourceTree = ""; }; 30 | F4FF95D6245B92E800C19C63 /* TerraReact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerraReact.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 134814211AA4EA7D00B7C361 /* Products */ = { 45 | isa = PBXGroup; 46 | children = ( 47 | 134814201AA4EA6300B7C361 /* libTerraReact.a */, 48 | ); 49 | name = Products; 50 | sourceTree = ""; 51 | }; 52 | 58B511D21A9E6C8500147676 = { 53 | isa = PBXGroup; 54 | children = ( 55 | 9B4A77942CD523B5000941A0 /* TerraActivityData.swift */, 56 | F4FF95D6245B92E800C19C63 /* TerraReact.swift */, 57 | B3E7B5891CC2AC0600A0062D /* TerraReact.m */, 58 | F4FF95D5245B92E700C19C63 /* TerraReact-Bridging-Header.h */, 59 | 134814211AA4EA7D00B7C361 /* Products */, 60 | ); 61 | sourceTree = ""; 62 | }; 63 | /* End PBXGroup section */ 64 | 65 | /* Begin PBXNativeTarget section */ 66 | 58B511DA1A9E6C8500147676 /* TerraReact */ = { 67 | isa = PBXNativeTarget; 68 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "TerraReact" */; 69 | buildPhases = ( 70 | 58B511D71A9E6C8500147676 /* Sources */, 71 | 58B511D81A9E6C8500147676 /* Frameworks */, 72 | 58B511D91A9E6C8500147676 /* CopyFiles */, 73 | ); 74 | buildRules = ( 75 | ); 76 | dependencies = ( 77 | ); 78 | name = TerraReact; 79 | productName = RCTDataManager; 80 | productReference = 134814201AA4EA6300B7C361 /* libTerraReact.a */; 81 | productType = "com.apple.product-type.library.static"; 82 | }; 83 | /* End PBXNativeTarget section */ 84 | 85 | /* Begin PBXProject section */ 86 | 58B511D31A9E6C8500147676 /* Project object */ = { 87 | isa = PBXProject; 88 | attributes = { 89 | LastUpgradeCheck = 0920; 90 | ORGANIZATIONNAME = Facebook; 91 | TargetAttributes = { 92 | 58B511DA1A9E6C8500147676 = { 93 | CreatedOnToolsVersion = 6.1.1; 94 | }; 95 | }; 96 | }; 97 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "TerraReact" */; 98 | compatibilityVersion = "Xcode 3.2"; 99 | developmentRegion = English; 100 | hasScannedForEncodings = 0; 101 | knownRegions = ( 102 | English, 103 | en, 104 | ); 105 | mainGroup = 58B511D21A9E6C8500147676; 106 | productRefGroup = 58B511D21A9E6C8500147676; 107 | projectDirPath = ""; 108 | projectRoot = ""; 109 | targets = ( 110 | 58B511DA1A9E6C8500147676 /* TerraReact */, 111 | ); 112 | }; 113 | /* End PBXProject section */ 114 | 115 | /* Begin PBXSourcesBuildPhase section */ 116 | 58B511D71A9E6C8500147676 /* Sources */ = { 117 | isa = PBXSourcesBuildPhase; 118 | buildActionMask = 2147483647; 119 | files = ( 120 | F4FF95D7245B92E800C19C63 /* TerraReact.swift in Sources */, 121 | ); 122 | runOnlyForDeploymentPostprocessing = 0; 123 | }; 124 | /* End PBXSourcesBuildPhase section */ 125 | 126 | /* Begin XCBuildConfiguration section */ 127 | 58B511ED1A9E6C8500147676 /* Debug */ = { 128 | isa = XCBuildConfiguration; 129 | buildSettings = { 130 | ALWAYS_SEARCH_USER_PATHS = NO; 131 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 132 | CLANG_CXX_LIBRARY = "libc++"; 133 | CLANG_ENABLE_MODULES = YES; 134 | CLANG_ENABLE_OBJC_ARC = YES; 135 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 136 | CLANG_WARN_BOOL_CONVERSION = YES; 137 | CLANG_WARN_COMMA = YES; 138 | CLANG_WARN_CONSTANT_CONVERSION = YES; 139 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 140 | CLANG_WARN_EMPTY_BODY = YES; 141 | CLANG_WARN_ENUM_CONVERSION = YES; 142 | CLANG_WARN_INFINITE_RECURSION = YES; 143 | CLANG_WARN_INT_CONVERSION = YES; 144 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 145 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 146 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 147 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 148 | CLANG_WARN_STRICT_PROTOTYPES = YES; 149 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 150 | CLANG_WARN_UNREACHABLE_CODE = YES; 151 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 152 | COPY_PHASE_STRIP = NO; 153 | ENABLE_STRICT_OBJC_MSGSEND = YES; 154 | ENABLE_TESTABILITY = YES; 155 | GCC_C_LANGUAGE_STANDARD = gnu99; 156 | GCC_DYNAMIC_NO_PIC = NO; 157 | GCC_NO_COMMON_BLOCKS = YES; 158 | GCC_OPTIMIZATION_LEVEL = 0; 159 | GCC_PREPROCESSOR_DEFINITIONS = ( 160 | "DEBUG=1", 161 | "$(inherited)", 162 | ); 163 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 164 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 165 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 166 | GCC_WARN_UNDECLARED_SELECTOR = YES; 167 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 168 | GCC_WARN_UNUSED_FUNCTION = YES; 169 | GCC_WARN_UNUSED_VARIABLE = YES; 170 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 171 | MTL_ENABLE_DEBUG_INFO = YES; 172 | ONLY_ACTIVE_ARCH = YES; 173 | SDKROOT = iphoneos; 174 | }; 175 | name = Debug; 176 | }; 177 | 58B511EE1A9E6C8500147676 /* Release */ = { 178 | isa = XCBuildConfiguration; 179 | buildSettings = { 180 | ALWAYS_SEARCH_USER_PATHS = NO; 181 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 182 | CLANG_CXX_LIBRARY = "libc++"; 183 | CLANG_ENABLE_MODULES = YES; 184 | CLANG_ENABLE_OBJC_ARC = YES; 185 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 186 | CLANG_WARN_BOOL_CONVERSION = YES; 187 | CLANG_WARN_COMMA = YES; 188 | CLANG_WARN_CONSTANT_CONVERSION = YES; 189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 190 | CLANG_WARN_EMPTY_BODY = YES; 191 | CLANG_WARN_ENUM_CONVERSION = YES; 192 | CLANG_WARN_INFINITE_RECURSION = YES; 193 | CLANG_WARN_INT_CONVERSION = YES; 194 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 195 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 197 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 198 | CLANG_WARN_STRICT_PROTOTYPES = YES; 199 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 200 | CLANG_WARN_UNREACHABLE_CODE = YES; 201 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 202 | COPY_PHASE_STRIP = YES; 203 | ENABLE_NS_ASSERTIONS = NO; 204 | ENABLE_STRICT_OBJC_MSGSEND = YES; 205 | GCC_C_LANGUAGE_STANDARD = gnu99; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 208 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 209 | GCC_WARN_UNDECLARED_SELECTOR = YES; 210 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 211 | GCC_WARN_UNUSED_FUNCTION = YES; 212 | GCC_WARN_UNUSED_VARIABLE = YES; 213 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 214 | MTL_ENABLE_DEBUG_INFO = NO; 215 | SDKROOT = iphoneos; 216 | VALIDATE_PRODUCT = YES; 217 | }; 218 | name = Release; 219 | }; 220 | 58B511F01A9E6C8500147676 /* Debug */ = { 221 | isa = XCBuildConfiguration; 222 | buildSettings = { 223 | HEADER_SEARCH_PATHS = ( 224 | "$(inherited)", 225 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 226 | "$(SRCROOT)/../../../React/**", 227 | "$(SRCROOT)/../../react-native/React/**", 228 | ); 229 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 230 | OTHER_LDFLAGS = "-ObjC"; 231 | PRODUCT_NAME = TerraReact; 232 | SKIP_INSTALL = YES; 233 | SWIFT_OBJC_BRIDGING_HEADER = "TerraReact-Bridging-Header.h"; 234 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 235 | SWIFT_VERSION = 5.0; 236 | }; 237 | name = Debug; 238 | }; 239 | 58B511F11A9E6C8500147676 /* Release */ = { 240 | isa = XCBuildConfiguration; 241 | buildSettings = { 242 | HEADER_SEARCH_PATHS = ( 243 | "$(inherited)", 244 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 245 | "$(SRCROOT)/../../../React/**", 246 | "$(SRCROOT)/../../react-native/React/**", 247 | ); 248 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 249 | OTHER_LDFLAGS = "-ObjC"; 250 | PRODUCT_NAME = TerraReact; 251 | SKIP_INSTALL = YES; 252 | SWIFT_OBJC_BRIDGING_HEADER = "TerraReact-Bridging-Header.h"; 253 | SWIFT_VERSION = 5.0; 254 | }; 255 | name = Release; 256 | }; 257 | /* End XCBuildConfiguration section */ 258 | 259 | /* Begin XCConfigurationList section */ 260 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "TerraReact" */ = { 261 | isa = XCConfigurationList; 262 | buildConfigurations = ( 263 | 58B511ED1A9E6C8500147676 /* Debug */, 264 | 58B511EE1A9E6C8500147676 /* Release */, 265 | ); 266 | defaultConfigurationIsVisible = 0; 267 | defaultConfigurationName = Release; 268 | }; 269 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "TerraReact" */ = { 270 | isa = XCConfigurationList; 271 | buildConfigurations = ( 272 | 58B511F01A9E6C8500147676 /* Debug */, 273 | 58B511F11A9E6C8500147676 /* Release */, 274 | ); 275 | defaultConfigurationIsVisible = 0; 276 | defaultConfigurationName = Release; 277 | }; 278 | /* End XCConfigurationList section */ 279 | }; 280 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 281 | } 282 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 1.8.11 9 | - Bump TerraiOS SDK to 1.6.31 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 10 | 11 | ## 1.8.10 12 | - Bump TerraAndroid SDK to 1.6.2 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 13 | 14 | ## 1.8.9 15 | - Bump Tag latest version 16 | 17 | ## 1.8.8 18 | - Bump TerraiOS SDK to 1.6.29 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 19 | 20 | ## 1.8.7 21 | - Update react native config package 22 | 23 | ## 1.8.6 24 | - Add Plannedworkouts for iOS 25 | 26 | ## 1.8.5 27 | 28 | ### Changed 29 | - Bump TerraAndroidSDK to 1.6.1 30 | - This improves memory management for the Health Connect based integration 31 | 32 | 33 | ## 1.8.4 34 | 35 | ### Changed 36 | - Remove Info.plist fields from iOS Config on expo 37 | - Remove intent filters from android manifest expo config 38 | Users may now directly add these under their expo app config 39 | 40 | 41 | ## 1.8.3 42 | 43 | ### Changed 44 | - Bump TerraAndroid SDK to 1.6.0 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 45 | 46 | ## 1.8.2 47 | 48 | ### Changed 49 | - Bump TerraiOS SDK to 1.6.28 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 50 | - Bump TerraAndroid SDK to 1.5.10 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 51 | 52 | 53 | ## 1.8.1 54 | 55 | ### Changed 56 | - Added Expo Plugin Support for Expo v53+ 57 | 58 | ## 1.8.0 59 | 60 | ### Changed 61 | - Add Expo Plugin Support 62 | 63 | ## 1.7.8 64 | 65 | ### Changed 66 | - Bump TerraiOS SDK to 1.6.27 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 67 | 68 | ## 1.7.7 69 | 70 | ### Changed 71 | - Bump TerraAndroid SDK to 1.5.7 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 72 | 73 | 74 | ## 1.7.6 75 | 76 | ### Changed 77 | - Bump TerraiOS SDK to 1.6.26 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 78 | 79 | 80 | ## 1.7.5 81 | 82 | ### Changed 83 | - Bump TerraAndroid SDK to 1.5.6 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 84 | 85 | ## 1.7.4 86 | 87 | ### Changed 88 | - Bump TerraAndroid SDK to 1.5.5 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 89 | - Bump TerraiOS SDK to 1.6.25 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 90 | 91 | ## 1.7.3 92 | 93 | ### Changed 94 | - Bump TerraAndroid SDK to 1.5.3 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 95 | 96 | ## 1.7.2 97 | 98 | ### Changed 99 | - Bump TerraiOS SDK to 1.6.24 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 100 | 101 | ## 1.7.1 102 | 103 | ### Changed 104 | - Bump TerraiOS SDK to 1.6.23 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 105 | 106 | ## 1.7.0 107 | 108 | ### Changed 109 | - Bump TerraiOS SDK to 1.6.22 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 110 | - Bump TerraAndroid SDK to 1.5.2 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 111 | 112 | ## 1.6.21 113 | 114 | ### Changed 115 | - Bump TerraiOS SDK to 1.6.21 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 116 | - Added postActivity (only available on iOS 14.0 and above) 117 | 118 | ## 1.6.20 119 | 120 | ### Changed 121 | - Bump TerraiOS SDK to 1.6.19 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 122 | 123 | ## 1.6.19 124 | 125 | ### Changed 126 | - Bump TerraiOS SDK to 1.6.18 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 127 | 128 | ## 1.6.18 129 | 130 | ### Changed 131 | - Bump TerraiOS SDK to 1.6.17 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 132 | 133 | ## 1.6.17 134 | 135 | ### Changed 136 | - Bump TerraiOS SDK to 1.6.16 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 137 | 138 | ## 1.6.16 139 | 140 | ### Changed 141 | - Bump TerraiOS SDK to 1.6.14 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 142 | - Remove specific null checks to getter functions 143 | - Change typings to use primitive types when possible 144 | 145 | ## 1.6.15 146 | 147 | ### Changed 148 | - Bump TerraAndroid SDK to 1.4.24 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 149 | 150 | ## 1.6.14 151 | 152 | ### Changed 153 | - Bump TerraiOS SDK to 1.6.13 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 154 | 155 | ## 1.6.13 156 | 157 | ### Changed 158 | - Bump TerraiOS SDK to 1.6.12 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 159 | 160 | ## 1.6.12 161 | 162 | ### Changed 163 | - Bump TerraiOS SDK to 1.6.10 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 164 | 165 | ## 1.6.11 166 | 167 | ### Changed 168 | - Bump TerraiOS SDK to 1.6.9 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 169 | 170 | ## 1.6.10 171 | 172 | ### Changed 173 | - Fixing sytax error in `TerraReactModule.java` 174 | 175 | ## 1.6.9 176 | 177 | ### Changed 178 | - Bump TerraiOS SDK to 1.6.7 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 179 | - This allows you to set ignoredSources via Terra.setIgnoredSources 180 | 181 | ## 1.6.8 182 | 183 | ### Changed 184 | - Bump TerraiOS SDK to 1.6.6 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 185 | 186 | ## 1.6.7 187 | 188 | ### Changed 189 | - Bump TerraiOS SDK to 1.6.5 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 190 | 191 | ## 1.6.6 192 | 193 | ### Changed 194 | - Bump TerraiOS SDK to 1.6.4 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 195 | 196 | ## 1.6.5 197 | 198 | ### Changed 199 | - Bump TerraiOS SDK to 1.6.3 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 200 | - Fixed a bug where if INTERBEAT CustomPermissions is used in Samsung, it causes a crash 201 | 202 | ## 1.6.4 203 | 204 | ### Changed 205 | - Bump TerraiOS SDK to 1.6.2 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 206 | - Bump TerraAndroid SDK to 1.4.23 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 207 | 208 | ## 1.6.3-noperm 209 | 210 | ### Changed 211 | - Bump TerraiOS SDK to 1.5.3 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 212 | 213 | ## 1.6.3 214 | 215 | ### Changed 216 | - Bump TerraiOS SDK to 1.5.3 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 217 | 218 | ## 1.6.2 219 | 220 | ### Changed 221 | - Bump TerraAndroid SDK to 1.4.21 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 222 | - Allow Health Connect to work correctly for Android 14. 223 | 224 | ## 1.6.1 225 | 226 | ### Changed 227 | - Bump TerraiOS SDK to 1.5.2 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 228 | - Bump TerraAndroid SDK to 1.4.19 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 229 | 230 | ## 1.6.0 231 | 232 | ### Changed 233 | - Bumped TerraiOS SDK to 1.5.1 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 234 | - Update uses new iOS 17 features and requires an Xcode update! 235 | 236 | ## 1.5.2 237 | 238 | ### Changed 239 | - Bumped TerraiOS SDK to 1.4.9 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 240 | 241 | ## 1.5.1 242 | 243 | ### Changed 244 | - Bumped TerraiOS SDK to 1.4.8 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 245 | - Bump TerraAndroid SDK to 1.4.18 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 246 | - Needs compileSdk 34 247 | - Improve local normalisation 248 | - Propagate Libre sensor state on activation of sensor 249 | 250 | ## 1.5.0 251 | 252 | ### Changed 253 | - Bumped TerraiOS SDK to 1.4.5 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 254 | - Improved iOS background delivery 255 | - Updated Terra data models to latest 256 | 257 | ## 1.4.19 258 | 259 | ### Changed 260 | - Bump TerraiOS SDK to 1.3.23 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 261 | 262 | ## 1.4.18 263 | 264 | ### Changed 265 | - Bump TerraiOS SDK to 1.3.21 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 266 | 267 | ## 1.4.17 268 | 269 | ### Changed 270 | - Bump TerraiOS SDK to 1.3.20 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 271 | 272 | ## 1.4.16 273 | 274 | ### Changed 275 | - Bump TerraiOS SDK to 1.3.19 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 276 | - Bump TerraAndroid SDK to 1.4.14 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 277 | 278 | ## 1.4.15 279 | 280 | ### Changed 281 | - Bump TerraAndroid SDK to 1.4.13 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 282 | 283 | ### Bug Fixes 284 | - Fix bug where checkAuth function was not executing correctly for iOS 285 | 286 | ### Added 287 | - Added checkAuth functionality for Android 288 | 289 | ## 1.4.14 290 | 291 | ### Changed 292 | - Bump TerraiOS SDK to 1.3.16 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 293 | 294 | ## 1.4.13 295 | 296 | ### Changed 297 | - Bump TerraiOS SDK to 1.3.15 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 298 | - Bump TerraAndroid SDK to 1.4.12 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 299 | 300 | 301 | ## 1.4.12 302 | 303 | ### Changed 304 | - Bump TerraiOS SDK to 1.3.14 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 305 | - Bump TerraAndroid SDK to 1.4.11 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 306 | 307 | ## 1.4.11 308 | 309 | ### Changed 310 | - Bump TerraiOS SDK to 1.3.13 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 311 | 312 | ## 1.4.10 313 | 314 | ### Changed 315 | - Bump TerraiOS SDK to 1.3.12 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 316 | - Bump TerraAndroid SDK to 1.4.10 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 317 | 318 | ## 1.4.9 319 | 320 | ### Changed 321 | - Bump TerraiOS SDK to 1.3.11 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 322 | - Bump TerraAndroid SDK to 1.4.9 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 323 | 324 | ## 1.4.8 325 | 326 | ### Changed 327 | - Bump TerraiOS SDK to 1.3.10 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 328 | - Bump TerraAndroid SDK to 1.4.8 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 329 | 330 | ## 1.4.7 331 | 332 | ### Changed 333 | - Bump TerraiOS SDK to 1.3.8 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 334 | - Bump TerraAndroid SDK to 1.4.8 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 335 | 336 | ### Added 337 | - Null checks for Android 338 | 339 | ## 1.4.6 340 | 341 | ### Changed 342 | - Bump TerraiOS SDK to 1.3.7 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 343 | 344 | ### Fixed 345 | - Fixed a bug where initTerra callbacks with true even with incorrect developer ID. 346 | 347 | ## 1.4.5 348 | 349 | ### Changed 350 | - Bump TerraiOS SDK to 1.3.6 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 351 | - Bump TerraAndroid SDK to 1.4.6 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 352 | 353 | ## 1.4.4 354 | 355 | ### Changed 356 | - Added a default "toWebhook" parameter for getAthlete function 357 | 358 | ## 1.4.3 359 | 360 | ### Added 361 | - Bridged functions to check if Health Connect is available, get granted permissions from Health Connect and Open Health Connect 362 | 363 | ## 1.4.2 364 | 365 | ### Changed 366 | - Bump TerraiOS SDK to 1.3.5 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 367 | - Bump TerraAndroid SDK to 1.4.5 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 368 | 369 | ## 1.4.1 370 | 371 | ### Changed 372 | - Bump TerraiOS SDK to 1.3.3 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 373 | - Bump TerraAndroid SDK to 1.4.3 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 374 | 375 | ## 1.4.0 376 | 377 | ### Changed 378 | - Bump TerraiOS SDK to 1.3.2 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 379 | - Bump TerraAndroid SDK to 1.4.0 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 380 | 381 | ### Added 382 | - Includes Singleton update 383 | - Can now receive data within getter functions (getActivity, getDaily etc.) 384 | 385 | ## 1.3.2 386 | 387 | ### Changed 388 | 389 | - Bump TerraiOS SDK to 1.2.25 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 390 | - Bump TerraAndroid SDK to 1.3.8 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 391 | 392 | ## 1.3.1 393 | 394 | ### Changed 395 | 396 | - Bump TerraiOS SDK to 1.2.24 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 397 | - Bump TerraAndroid SDK to 1.3.8 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 398 | 399 | ## 1.3.0 400 | 401 | ### Changes 402 | 403 | - Bump TerraiOS SDK to 1.2.21 (https://github.com/tryterra/TerraiOS/wiki/Change-Log) 404 | - Bump TerraAndroid SDK to 1.3.5 (https://github.com/tryterra/TerraAndroid/wiki/Change-Log) 405 | - This version onwards uses Health Connect to connect to Android data 406 | 407 | 408 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { NativeModules, Platform } from 'react-native'; 2 | import { CustomPermissions as CustomPermissions_ } from './enums/CustomPermissions'; 3 | import { Connections as Connections_ } from './enums/Connections'; 4 | import { Activity as TerraActivityPayload } from './models/Activity'; 5 | import { TerraPlannedWorkout } from './models/PlannedWorkouts'; 6 | 7 | const LINKING_ERROR = 8 | `The package 'terra-react' doesn't seem to be linked. Make sure: \n\n` + 9 | Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + 10 | '- You rebuilt the app after installing the package\n' + 11 | '- You are not using Expo managed workflow\n'; 12 | 13 | const TerraReact = NativeModules.TerraReact 14 | ? NativeModules.TerraReact 15 | : new Proxy( 16 | {}, 17 | { 18 | get() { 19 | throw new Error(LINKING_ERROR); 20 | }, 21 | } 22 | ); 23 | 24 | export type GetUserId = { 25 | success: boolean; 26 | userId: string | null; 27 | }; 28 | 29 | export type SuccessMessage = { 30 | success: boolean; 31 | error: string | null; 32 | }; 33 | 34 | export type DataMessage = { 35 | success: boolean; 36 | data: Object; 37 | error: string | null; 38 | }; 39 | 40 | export interface ListDataMessage { 41 | success?: boolean | null; 42 | data?: T[] | null; 43 | error?: string | null; 44 | } 45 | 46 | function ConnectionToString(connection: Connections_) { 47 | switch (connection) { 48 | case Connections_.APPLE_HEALTH: 49 | return 'APPLE_HEALTH'; 50 | case Connections_.FREESTYLE_LIBRE: 51 | return 'FREESTYLE_LIBRE'; 52 | case Connections_.GOOGLE: 53 | return 'GOOGLE'; 54 | case Connections_.SAMSUNG: 55 | return 'SAMSUNG'; 56 | case Connections_.HEALTH_CONNECT: 57 | return 'HEALTH_CONNECT'; 58 | default: 59 | return undefined; 60 | } 61 | } 62 | 63 | function CustomPermissions_ToString(cPermission: CustomPermissions_) { 64 | switch (cPermission) { 65 | case CustomPermissions_.WORKOUT_TYPES: 66 | return 'WORKOUT_TYPES'; 67 | case CustomPermissions_.ACTIVITY_SUMMARY: 68 | return 'ACTIVITY_SUMMARY'; 69 | case CustomPermissions_.LOCATION: 70 | return 'LOCATION'; 71 | case CustomPermissions_.CALORIES: 72 | return 'CALORIES'; 73 | case CustomPermissions_.STEPS: 74 | return 'STEPS'; 75 | case CustomPermissions_.HEART_RATE: 76 | return 'HEART_RATE'; 77 | case CustomPermissions_.HEART_RATE_VARIABILITY: 78 | return 'HEART_RATE_VARIABILITY'; 79 | case CustomPermissions_.VO2MAX: 80 | return 'VO2MAX'; 81 | case CustomPermissions_.HEIGHT: 82 | return 'HEIGHT'; 83 | case CustomPermissions_.ACTIVE_DURATIONS: 84 | return 'ACTIVE_DURATIONS'; 85 | case CustomPermissions_.WEIGHT: 86 | return 'WEIGHT'; 87 | case CustomPermissions_.FLIGHTS_CLIMBED: 88 | return 'FLIGHTS_CLIMBED'; 89 | case CustomPermissions_.BMI: 90 | return 'BMI'; 91 | case CustomPermissions_.BODY_FAT: 92 | return 'BODY_FAT'; 93 | case CustomPermissions_.EXERCISE_DISTANCE: 94 | return 'EXERCISE_DISTANCE'; 95 | case CustomPermissions_.GENDER: 96 | return 'GENDER'; 97 | case CustomPermissions_.DATE_OF_BIRTH: 98 | return 'DATE_OF_BIRTH'; 99 | case CustomPermissions_.BASAL_ENERGY_BURNED: 100 | return 'BASAL_ENERGY_BURNED'; 101 | case CustomPermissions_.SWIMMING_SUMMARY: 102 | return 'SWIMMING_SUMMARY'; 103 | case CustomPermissions_.RESTING_HEART_RATE: 104 | return 'RESTING_HEART_RATE'; 105 | case CustomPermissions_.BLOOD_PRESSURE: 106 | return 'BLOOD_PRESSURE'; 107 | case CustomPermissions_.BLOOD_GLUCOSE: 108 | return 'BLOOD_GLUCOSE'; 109 | case CustomPermissions_.BODY_TEMPERATURE: 110 | return 'BODY_TEMPERATURE'; 111 | case CustomPermissions_.MINDFULNESS: 112 | return 'MINDFULNESS'; 113 | case CustomPermissions_.LEAN_BODY_MASS: 114 | return 'LEAN_BODY_MASS'; 115 | case CustomPermissions_.OXYGEN_SATURATION: 116 | return 'OXYGEN_SATURATION'; 117 | case CustomPermissions_.SLEEP_ANALYSIS: 118 | return 'SLEEP_ANALYSIS'; 119 | case CustomPermissions_.RESPIRATORY_RATE: 120 | return 'RESPIRATORY_RATE'; 121 | case CustomPermissions_.NUTRITION_SODIUM: 122 | return 'NUTRITION_SODIUM'; 123 | case CustomPermissions_.NUTRITION_PROTEIN: 124 | return 'NUTRITION_PROTEIN'; 125 | case CustomPermissions_.NUTRITION_CARBOHYDRATES: 126 | return 'NUTRITION_CARBOHYDRATES'; 127 | case CustomPermissions_.NUTRITION_FIBRE: 128 | return 'NUTRITION_FIBRE'; 129 | case CustomPermissions_.NUTRITION_FAT_TOTAL: 130 | return 'NUTRITION_FAT_TOTAL'; 131 | case CustomPermissions_.NUTRITION_SUGAR: 132 | return 'NUTRITION_SUGAR'; 133 | case CustomPermissions_.NUTRITION_VITAMIN_C: 134 | return 'NUTRITION_VITAMIN_C'; 135 | case CustomPermissions_.NUTRITION_VITAMIN_A: 136 | return 'NUTRITION_VITAMIN_A'; 137 | case CustomPermissions_.NUTRITION_CALORIES: 138 | return 'NUTRITION_CALORIES'; 139 | case CustomPermissions_.NUTRITION_WATER: 140 | return 'NUTRITION_WATER'; 141 | case CustomPermissions_.NUTRITION_CHOLESTEROL: 142 | return 'NUTRITION_CHOLESTEROL'; 143 | case CustomPermissions_.MENSTRUATION: 144 | return 'MENSTRUATION'; 145 | case CustomPermissions_.INTERBEAT: 146 | return 'INTERBEAT'; 147 | case CustomPermissions_.SPEED: 148 | return 'SPEED'; 149 | case CustomPermissions_.POWER: 150 | return 'POWER'; 151 | } 152 | } 153 | 154 | export function initTerra( 155 | devID: string, 156 | referenceId: string | null 157 | ): Promise { 158 | return TerraReact.initTerra(devID, referenceId); 159 | } 160 | 161 | export function initConnection( 162 | connection: Connections_, 163 | token: string, 164 | schedulerOn: boolean, 165 | customPermissions_: CustomPermissions_[] = [], 166 | startIntent: string | null = null 167 | ): Promise { 168 | return TerraReact.initConnection( 169 | ConnectionToString(connection), 170 | token, 171 | schedulerOn, 172 | customPermissions_.map((p) => CustomPermissions_ToString(p)), 173 | startIntent 174 | ); 175 | } 176 | 177 | export function checkAuth( 178 | connection: Connections_, 179 | devID: string 180 | ): Promise> { 181 | return TerraReact.checkAuth(ConnectionToString(connection), devID); 182 | } 183 | 184 | export function getUserId(connection: Connections_): Promise { 185 | return TerraReact.getUserId(ConnectionToString(connection)); 186 | } 187 | 188 | export function getBody( 189 | connection: Connections_, 190 | startDate: Date, 191 | endDate: Date, 192 | latestReading: boolean = false, 193 | toWebhook: boolean = true 194 | ): Promise { 195 | return new Promise((resolve, reject) => { 196 | TerraReact.getBody( 197 | ConnectionToString(connection), 198 | startDate.toISOString(), 199 | endDate.toISOString(), 200 | latestReading, 201 | toWebhook 202 | ) 203 | .then((d: any) => { 204 | const data: DataMessage = { 205 | success: d.success, 206 | data: d.data !== undefined ? JSON.parse(d.data) : null, 207 | error: d.error, 208 | }; 209 | resolve(data); 210 | }) 211 | .catch((e: Error) => { 212 | reject(e); 213 | }); 214 | }); 215 | } 216 | 217 | export function getActivity( 218 | connection: Connections_, 219 | startDate: Date, 220 | endDate: Date, 221 | toWebhook: boolean = true 222 | ): Promise { 223 | return new Promise((resolve, reject) => { 224 | TerraReact.getActivity( 225 | ConnectionToString(connection), 226 | startDate.toISOString(), 227 | endDate.toISOString(), 228 | toWebhook 229 | ) 230 | .then((d: any) => { 231 | const data: DataMessage = { 232 | success: d.success, 233 | data: d.data !== undefined ? JSON.parse(d.data) : null, 234 | error: d.error, 235 | }; 236 | resolve(data); 237 | }) 238 | .catch((e: Error) => { 239 | reject(e); 240 | }); 241 | }); 242 | } 243 | 244 | export function getMenstruation( 245 | connection: Connections_, 246 | startDate: Date, 247 | endDate: Date, 248 | toWebhook: boolean = true 249 | ): Promise { 250 | return new Promise((resolve, reject) => { 251 | TerraReact.getMenstruation( 252 | ConnectionToString(connection), 253 | startDate.toISOString(), 254 | endDate.toISOString(), 255 | toWebhook 256 | ) 257 | .then((d: any) => { 258 | const data: DataMessage = { 259 | success: d.success, 260 | data: d.data !== undefined ? JSON.parse(d.data) : null, 261 | error: d.error, 262 | }; 263 | resolve(data); 264 | }) 265 | .catch((e: Error) => { 266 | reject(e); 267 | }); 268 | }); 269 | } 270 | 271 | export function getDaily( 272 | connection: Connections_, 273 | startDate: Date, 274 | endDate: Date, 275 | toWebhook: boolean = true 276 | ): Promise { 277 | return new Promise((resolve, reject) => { 278 | TerraReact.getDaily( 279 | ConnectionToString(connection), 280 | startDate.toISOString(), 281 | endDate.toISOString(), 282 | toWebhook 283 | ) 284 | .then((d: any) => { 285 | const data: DataMessage = { 286 | success: d.success, 287 | data: d.data !== undefined ? JSON.parse(d.data) : null, 288 | error: d.error, 289 | }; 290 | resolve(data); 291 | }) 292 | .catch((e: Error) => { 293 | reject(e); 294 | }); 295 | }); 296 | } 297 | 298 | export function getNutrition( 299 | connection: Connections_, 300 | startDate: Date, 301 | endDate: Date, 302 | toWebhook: boolean = true 303 | ): Promise { 304 | return new Promise((resolve, reject) => { 305 | TerraReact.getNutrition( 306 | ConnectionToString(connection), 307 | startDate.toISOString(), 308 | endDate.toISOString(), 309 | toWebhook 310 | ) 311 | .then((d: any) => { 312 | const data: DataMessage = { 313 | success: d.success, 314 | data: d.data !== undefined ? JSON.parse(d.data) : null, 315 | error: d.error, 316 | }; 317 | resolve(data); 318 | }) 319 | .catch((e: Error) => { 320 | reject(e); 321 | }); 322 | }); 323 | } 324 | 325 | export function getSleep( 326 | connection: Connections_, 327 | startDate: Date, 328 | endDate: Date, 329 | toWebhook: boolean = true 330 | ): Promise { 331 | return new Promise((resolve, reject) => { 332 | TerraReact.getSleep( 333 | ConnectionToString(connection), 334 | startDate.toISOString(), 335 | endDate.toISOString(), 336 | toWebhook 337 | ) 338 | .then((d: any) => { 339 | const data: DataMessage = { 340 | success: d.success, 341 | data: d.data !== undefined ? JSON.parse(d.data) : null, 342 | error: d.error, 343 | }; 344 | resolve(data); 345 | }) 346 | .catch((e: Error) => { 347 | reject(e); 348 | }); 349 | }); 350 | } 351 | 352 | export function getAthlete( 353 | connection: Connections_, 354 | toWebhook: boolean = true 355 | ) { 356 | return TerraReact.getAthlete(ConnectionToString(connection), toWebhook); 357 | } 358 | 359 | /* 360 | @Only availble on iOS 361 | */ 362 | export function postActivity( 363 | connection: Connections_, 364 | payload: TerraActivityPayload 365 | ): Promise { 366 | return new Promise((resolve, reject) => { 367 | TerraReact.postActivity(ConnectionToString(connection), payload) 368 | .then((d: any) => { 369 | resolve({ success: d.success, error: d.error } as SuccessMessage); 370 | }) 371 | .catch((e: Error) => { 372 | reject(e); 373 | }); 374 | }); 375 | } 376 | export function getPlannedWorkouts( 377 | connection: Connections_ 378 | ): Promise> { 379 | return new Promise>((resolve, reject) => { 380 | TerraReact.getPlannedWorkouts(ConnectionToString(connection)) 381 | .then((d: any) => { 382 | const data: ListDataMessage = { 383 | success: d.success, 384 | data: d.data !== undefined ? JSON.parse(d.data) : null, 385 | error: d.error, 386 | }; 387 | resolve(data); 388 | }) 389 | .catch((e: Error) => reject(e)); 390 | }); 391 | } 392 | export function deletePlannedWorkout( 393 | connection: Connections_, 394 | id: string 395 | ): Promise { 396 | return new Promise((resolve, reject) => { 397 | TerraReact.deletePlannedWorkout(ConnectionToString(connection), id) 398 | .then((d: any) => { 399 | const res: SuccessMessage = { 400 | success: d.success, 401 | error: d.error, 402 | }; 403 | resolve(res); 404 | }) 405 | .catch((e: Error) => reject(e)); 406 | }); 407 | } 408 | 409 | export function completePlannedWorkout( 410 | connection: Connections_, 411 | id: string, 412 | at?: Date 413 | ): Promise { 414 | return new Promise((resolve, reject) => { 415 | TerraReact.completePlannedWorkout( 416 | ConnectionToString(connection), 417 | id, 418 | (at ?? new Date()).toISOString() 419 | ) 420 | .then((d: any) => { 421 | const res: SuccessMessage = { 422 | success: d.success, 423 | error: d.error, 424 | }; 425 | resolve(res); 426 | }) 427 | .catch((e: Error) => reject(e)); 428 | }); 429 | } 430 | 431 | export function postPlannedWorkout( 432 | connection: Connections_, 433 | payload: TerraPlannedWorkout 434 | ): Promise { 435 | return new Promise((resolve, reject) => { 436 | TerraReact.postPlannedWorkout( 437 | ConnectionToString(connection), 438 | JSON.stringify(payload.toJson()) 439 | ) 440 | .then((d: any) => { 441 | const res: SuccessMessage = { 442 | success: d.success, 443 | error: d.error, 444 | }; 445 | resolve(res); 446 | }) 447 | .catch((e: Error) => reject(e)); 448 | }); 449 | } 450 | 451 | export function readGlucoseData(): Promise { 452 | return new Promise((resolve, reject) => { 453 | TerraReact.readGlucoseData() 454 | .then((d: any) => { 455 | resolve(JSON.parse(d)); 456 | }) 457 | .catch((e: Error) => { 458 | reject(e); 459 | }); 460 | }); 461 | } 462 | 463 | export function activateSensor(): Promise { 464 | return new Promise((resolve, reject) => { 465 | TerraReact.activateSensor() 466 | .then((d: any) => { 467 | resolve(JSON.parse(d)); 468 | }) 469 | .catch((e: Error) => { 470 | reject(e); 471 | }); 472 | }); 473 | } 474 | 475 | export function openHealthConnect(): void { 476 | TerraReact.openHealthConnect().catch((e: any) => { 477 | console.log(e); 478 | return; 479 | }); 480 | } 481 | 482 | export function isHealthConnectAvailable(): Promise { 483 | return TerraReact.isHealthConnectAvailable(); 484 | } 485 | 486 | export function grantedPermissions(): Promise> { 487 | return TerraReact.grantedPermissions(); 488 | } 489 | 490 | export function setIgnoredSources(ignoredSources: Array): void { 491 | TerraReact.setIgnoredSources(ignoredSources).then(); 492 | } 493 | 494 | export type Activity = TerraActivityPayload; 495 | export { Connections } from './enums/Connections'; 496 | export { CustomPermissions } from './enums/CustomPermissions'; 497 | export * from './models/PlannedWorkouts'; 498 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - boost (1.76.0) 3 | - DoubleConversion (1.1.6) 4 | - FBLazyVector (0.70.0) 5 | - FBReactNativeSpec (0.70.0): 6 | - RCT-Folly (= 2021.07.22.00) 7 | - RCTRequired (= 0.70.0) 8 | - RCTTypeSafety (= 0.70.0) 9 | - React-Core (= 0.70.0) 10 | - React-jsi (= 0.70.0) 11 | - ReactCommon/turbomodule/core (= 0.70.0) 12 | - fmt (6.2.1) 13 | - glog (0.3.5) 14 | - RCT-Folly (2021.07.22.00): 15 | - boost 16 | - DoubleConversion 17 | - fmt (~> 6.2.1) 18 | - glog 19 | - RCT-Folly/Default (= 2021.07.22.00) 20 | - RCT-Folly/Default (2021.07.22.00): 21 | - boost 22 | - DoubleConversion 23 | - fmt (~> 6.2.1) 24 | - glog 25 | - RCTRequired (0.70.0) 26 | - RCTTypeSafety (0.70.0): 27 | - FBLazyVector (= 0.70.0) 28 | - RCTRequired (= 0.70.0) 29 | - React-Core (= 0.70.0) 30 | - React (0.70.0): 31 | - React-Core (= 0.70.0) 32 | - React-Core/DevSupport (= 0.70.0) 33 | - React-Core/RCTWebSocket (= 0.70.0) 34 | - React-RCTActionSheet (= 0.70.0) 35 | - React-RCTAnimation (= 0.70.0) 36 | - React-RCTBlob (= 0.70.0) 37 | - React-RCTImage (= 0.70.0) 38 | - React-RCTLinking (= 0.70.0) 39 | - React-RCTNetwork (= 0.70.0) 40 | - React-RCTSettings (= 0.70.0) 41 | - React-RCTText (= 0.70.0) 42 | - React-RCTVibration (= 0.70.0) 43 | - React-bridging (0.70.0): 44 | - RCT-Folly (= 2021.07.22.00) 45 | - React-jsi (= 0.70.0) 46 | - React-callinvoker (0.70.0) 47 | - React-Codegen (0.70.0): 48 | - FBReactNativeSpec (= 0.70.0) 49 | - RCT-Folly (= 2021.07.22.00) 50 | - RCTRequired (= 0.70.0) 51 | - RCTTypeSafety (= 0.70.0) 52 | - React-Core (= 0.70.0) 53 | - React-jsi (= 0.70.0) 54 | - React-jsiexecutor (= 0.70.0) 55 | - ReactCommon/turbomodule/core (= 0.70.0) 56 | - React-Core (0.70.0): 57 | - glog 58 | - RCT-Folly (= 2021.07.22.00) 59 | - React-Core/Default (= 0.70.0) 60 | - React-cxxreact (= 0.70.0) 61 | - React-jsi (= 0.70.0) 62 | - React-jsiexecutor (= 0.70.0) 63 | - React-perflogger (= 0.70.0) 64 | - Yoga 65 | - React-Core/CoreModulesHeaders (0.70.0): 66 | - glog 67 | - RCT-Folly (= 2021.07.22.00) 68 | - React-Core/Default 69 | - React-cxxreact (= 0.70.0) 70 | - React-jsi (= 0.70.0) 71 | - React-jsiexecutor (= 0.70.0) 72 | - React-perflogger (= 0.70.0) 73 | - Yoga 74 | - React-Core/Default (0.70.0): 75 | - glog 76 | - RCT-Folly (= 2021.07.22.00) 77 | - React-cxxreact (= 0.70.0) 78 | - React-jsi (= 0.70.0) 79 | - React-jsiexecutor (= 0.70.0) 80 | - React-perflogger (= 0.70.0) 81 | - Yoga 82 | - React-Core/DevSupport (0.70.0): 83 | - glog 84 | - RCT-Folly (= 2021.07.22.00) 85 | - React-Core/Default (= 0.70.0) 86 | - React-Core/RCTWebSocket (= 0.70.0) 87 | - React-cxxreact (= 0.70.0) 88 | - React-jsi (= 0.70.0) 89 | - React-jsiexecutor (= 0.70.0) 90 | - React-jsinspector (= 0.70.0) 91 | - React-perflogger (= 0.70.0) 92 | - Yoga 93 | - React-Core/RCTActionSheetHeaders (0.70.0): 94 | - glog 95 | - RCT-Folly (= 2021.07.22.00) 96 | - React-Core/Default 97 | - React-cxxreact (= 0.70.0) 98 | - React-jsi (= 0.70.0) 99 | - React-jsiexecutor (= 0.70.0) 100 | - React-perflogger (= 0.70.0) 101 | - Yoga 102 | - React-Core/RCTAnimationHeaders (0.70.0): 103 | - glog 104 | - RCT-Folly (= 2021.07.22.00) 105 | - React-Core/Default 106 | - React-cxxreact (= 0.70.0) 107 | - React-jsi (= 0.70.0) 108 | - React-jsiexecutor (= 0.70.0) 109 | - React-perflogger (= 0.70.0) 110 | - Yoga 111 | - React-Core/RCTBlobHeaders (0.70.0): 112 | - glog 113 | - RCT-Folly (= 2021.07.22.00) 114 | - React-Core/Default 115 | - React-cxxreact (= 0.70.0) 116 | - React-jsi (= 0.70.0) 117 | - React-jsiexecutor (= 0.70.0) 118 | - React-perflogger (= 0.70.0) 119 | - Yoga 120 | - React-Core/RCTImageHeaders (0.70.0): 121 | - glog 122 | - RCT-Folly (= 2021.07.22.00) 123 | - React-Core/Default 124 | - React-cxxreact (= 0.70.0) 125 | - React-jsi (= 0.70.0) 126 | - React-jsiexecutor (= 0.70.0) 127 | - React-perflogger (= 0.70.0) 128 | - Yoga 129 | - React-Core/RCTLinkingHeaders (0.70.0): 130 | - glog 131 | - RCT-Folly (= 2021.07.22.00) 132 | - React-Core/Default 133 | - React-cxxreact (= 0.70.0) 134 | - React-jsi (= 0.70.0) 135 | - React-jsiexecutor (= 0.70.0) 136 | - React-perflogger (= 0.70.0) 137 | - Yoga 138 | - React-Core/RCTNetworkHeaders (0.70.0): 139 | - glog 140 | - RCT-Folly (= 2021.07.22.00) 141 | - React-Core/Default 142 | - React-cxxreact (= 0.70.0) 143 | - React-jsi (= 0.70.0) 144 | - React-jsiexecutor (= 0.70.0) 145 | - React-perflogger (= 0.70.0) 146 | - Yoga 147 | - React-Core/RCTSettingsHeaders (0.70.0): 148 | - glog 149 | - RCT-Folly (= 2021.07.22.00) 150 | - React-Core/Default 151 | - React-cxxreact (= 0.70.0) 152 | - React-jsi (= 0.70.0) 153 | - React-jsiexecutor (= 0.70.0) 154 | - React-perflogger (= 0.70.0) 155 | - Yoga 156 | - React-Core/RCTTextHeaders (0.70.0): 157 | - glog 158 | - RCT-Folly (= 2021.07.22.00) 159 | - React-Core/Default 160 | - React-cxxreact (= 0.70.0) 161 | - React-jsi (= 0.70.0) 162 | - React-jsiexecutor (= 0.70.0) 163 | - React-perflogger (= 0.70.0) 164 | - Yoga 165 | - React-Core/RCTVibrationHeaders (0.70.0): 166 | - glog 167 | - RCT-Folly (= 2021.07.22.00) 168 | - React-Core/Default 169 | - React-cxxreact (= 0.70.0) 170 | - React-jsi (= 0.70.0) 171 | - React-jsiexecutor (= 0.70.0) 172 | - React-perflogger (= 0.70.0) 173 | - Yoga 174 | - React-Core/RCTWebSocket (0.70.0): 175 | - glog 176 | - RCT-Folly (= 2021.07.22.00) 177 | - React-Core/Default (= 0.70.0) 178 | - React-cxxreact (= 0.70.0) 179 | - React-jsi (= 0.70.0) 180 | - React-jsiexecutor (= 0.70.0) 181 | - React-perflogger (= 0.70.0) 182 | - Yoga 183 | - React-CoreModules (0.70.0): 184 | - RCT-Folly (= 2021.07.22.00) 185 | - RCTTypeSafety (= 0.70.0) 186 | - React-Codegen (= 0.70.0) 187 | - React-Core/CoreModulesHeaders (= 0.70.0) 188 | - React-jsi (= 0.70.0) 189 | - React-RCTImage (= 0.70.0) 190 | - ReactCommon/turbomodule/core (= 0.70.0) 191 | - React-cxxreact (0.70.0): 192 | - boost (= 1.76.0) 193 | - DoubleConversion 194 | - glog 195 | - RCT-Folly (= 2021.07.22.00) 196 | - React-callinvoker (= 0.70.0) 197 | - React-jsi (= 0.70.0) 198 | - React-jsinspector (= 0.70.0) 199 | - React-logger (= 0.70.0) 200 | - React-perflogger (= 0.70.0) 201 | - React-runtimeexecutor (= 0.70.0) 202 | - React-jsi (0.70.0): 203 | - boost (= 1.76.0) 204 | - DoubleConversion 205 | - glog 206 | - RCT-Folly (= 2021.07.22.00) 207 | - React-jsi/Default (= 0.70.0) 208 | - React-jsi/Default (0.70.0): 209 | - boost (= 1.76.0) 210 | - DoubleConversion 211 | - glog 212 | - RCT-Folly (= 2021.07.22.00) 213 | - React-jsiexecutor (0.70.0): 214 | - DoubleConversion 215 | - glog 216 | - RCT-Folly (= 2021.07.22.00) 217 | - React-cxxreact (= 0.70.0) 218 | - React-jsi (= 0.70.0) 219 | - React-perflogger (= 0.70.0) 220 | - React-jsinspector (0.70.0) 221 | - React-logger (0.70.0): 222 | - glog 223 | - React-perflogger (0.70.0) 224 | - React-RCTActionSheet (0.70.0): 225 | - React-Core/RCTActionSheetHeaders (= 0.70.0) 226 | - React-RCTAnimation (0.70.0): 227 | - RCT-Folly (= 2021.07.22.00) 228 | - RCTTypeSafety (= 0.70.0) 229 | - React-Codegen (= 0.70.0) 230 | - React-Core/RCTAnimationHeaders (= 0.70.0) 231 | - React-jsi (= 0.70.0) 232 | - ReactCommon/turbomodule/core (= 0.70.0) 233 | - React-RCTBlob (0.70.0): 234 | - RCT-Folly (= 2021.07.22.00) 235 | - React-Codegen (= 0.70.0) 236 | - React-Core/RCTBlobHeaders (= 0.70.0) 237 | - React-Core/RCTWebSocket (= 0.70.0) 238 | - React-jsi (= 0.70.0) 239 | - React-RCTNetwork (= 0.70.0) 240 | - ReactCommon/turbomodule/core (= 0.70.0) 241 | - React-RCTImage (0.70.0): 242 | - RCT-Folly (= 2021.07.22.00) 243 | - RCTTypeSafety (= 0.70.0) 244 | - React-Codegen (= 0.70.0) 245 | - React-Core/RCTImageHeaders (= 0.70.0) 246 | - React-jsi (= 0.70.0) 247 | - React-RCTNetwork (= 0.70.0) 248 | - ReactCommon/turbomodule/core (= 0.70.0) 249 | - React-RCTLinking (0.70.0): 250 | - React-Codegen (= 0.70.0) 251 | - React-Core/RCTLinkingHeaders (= 0.70.0) 252 | - React-jsi (= 0.70.0) 253 | - ReactCommon/turbomodule/core (= 0.70.0) 254 | - React-RCTNetwork (0.70.0): 255 | - RCT-Folly (= 2021.07.22.00) 256 | - RCTTypeSafety (= 0.70.0) 257 | - React-Codegen (= 0.70.0) 258 | - React-Core/RCTNetworkHeaders (= 0.70.0) 259 | - React-jsi (= 0.70.0) 260 | - ReactCommon/turbomodule/core (= 0.70.0) 261 | - React-RCTSettings (0.70.0): 262 | - RCT-Folly (= 2021.07.22.00) 263 | - RCTTypeSafety (= 0.70.0) 264 | - React-Codegen (= 0.70.0) 265 | - React-Core/RCTSettingsHeaders (= 0.70.0) 266 | - React-jsi (= 0.70.0) 267 | - ReactCommon/turbomodule/core (= 0.70.0) 268 | - React-RCTText (0.70.0): 269 | - React-Core/RCTTextHeaders (= 0.70.0) 270 | - React-RCTVibration (0.70.0): 271 | - RCT-Folly (= 2021.07.22.00) 272 | - React-Codegen (= 0.70.0) 273 | - React-Core/RCTVibrationHeaders (= 0.70.0) 274 | - React-jsi (= 0.70.0) 275 | - ReactCommon/turbomodule/core (= 0.70.0) 276 | - React-runtimeexecutor (0.70.0): 277 | - React-jsi (= 0.70.0) 278 | - ReactCommon/turbomodule/core (0.70.0): 279 | - DoubleConversion 280 | - glog 281 | - RCT-Folly (= 2021.07.22.00) 282 | - React-bridging (= 0.70.0) 283 | - React-callinvoker (= 0.70.0) 284 | - React-Core (= 0.70.0) 285 | - React-cxxreact (= 0.70.0) 286 | - React-jsi (= 0.70.0) 287 | - React-logger (= 0.70.0) 288 | - React-perflogger (= 0.70.0) 289 | - terra-react (1.8.6): 290 | - React-Core 291 | - TerraiOS (= 1.6.28) 292 | - TerraiOS (1.6.28) 293 | - Yoga (1.14.0) 294 | 295 | DEPENDENCIES: 296 | - boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`) 297 | - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) 298 | - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) 299 | - FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`) 300 | - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) 301 | - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) 302 | - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) 303 | - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`) 304 | - React (from `../node_modules/react-native/`) 305 | - React-bridging (from `../node_modules/react-native/ReactCommon`) 306 | - React-callinvoker (from `../node_modules/react-native/ReactCommon/callinvoker`) 307 | - React-Codegen (from `build/generated/ios`) 308 | - React-Core (from `../node_modules/react-native/`) 309 | - React-Core/RCTWebSocket (from `../node_modules/react-native/`) 310 | - React-CoreModules (from `../node_modules/react-native/React/CoreModules`) 311 | - React-cxxreact (from `../node_modules/react-native/ReactCommon/cxxreact`) 312 | - React-jsi (from `../node_modules/react-native/ReactCommon/jsi`) 313 | - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) 314 | - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) 315 | - React-logger (from `../node_modules/react-native/ReactCommon/logger`) 316 | - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) 317 | - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) 318 | - React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`) 319 | - React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`) 320 | - React-RCTImage (from `../node_modules/react-native/Libraries/Image`) 321 | - React-RCTLinking (from `../node_modules/react-native/Libraries/LinkingIOS`) 322 | - React-RCTNetwork (from `../node_modules/react-native/Libraries/Network`) 323 | - React-RCTSettings (from `../node_modules/react-native/Libraries/Settings`) 324 | - React-RCTText (from `../node_modules/react-native/Libraries/Text`) 325 | - React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`) 326 | - React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`) 327 | - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) 328 | - terra-react (from `../node_modules/terra-react`) 329 | - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) 330 | 331 | SPEC REPOS: 332 | trunk: 333 | - fmt 334 | - TerraiOS 335 | 336 | EXTERNAL SOURCES: 337 | boost: 338 | :podspec: "../node_modules/react-native/third-party-podspecs/boost.podspec" 339 | DoubleConversion: 340 | :podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec" 341 | FBLazyVector: 342 | :path: "../node_modules/react-native/Libraries/FBLazyVector" 343 | FBReactNativeSpec: 344 | :path: "../node_modules/react-native/React/FBReactNativeSpec" 345 | glog: 346 | :podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec" 347 | RCT-Folly: 348 | :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" 349 | RCTRequired: 350 | :path: "../node_modules/react-native/Libraries/RCTRequired" 351 | RCTTypeSafety: 352 | :path: "../node_modules/react-native/Libraries/TypeSafety" 353 | React: 354 | :path: "../node_modules/react-native/" 355 | React-bridging: 356 | :path: "../node_modules/react-native/ReactCommon" 357 | React-callinvoker: 358 | :path: "../node_modules/react-native/ReactCommon/callinvoker" 359 | React-Codegen: 360 | :path: build/generated/ios 361 | React-Core: 362 | :path: "../node_modules/react-native/" 363 | React-CoreModules: 364 | :path: "../node_modules/react-native/React/CoreModules" 365 | React-cxxreact: 366 | :path: "../node_modules/react-native/ReactCommon/cxxreact" 367 | React-jsi: 368 | :path: "../node_modules/react-native/ReactCommon/jsi" 369 | React-jsiexecutor: 370 | :path: "../node_modules/react-native/ReactCommon/jsiexecutor" 371 | React-jsinspector: 372 | :path: "../node_modules/react-native/ReactCommon/jsinspector" 373 | React-logger: 374 | :path: "../node_modules/react-native/ReactCommon/logger" 375 | React-perflogger: 376 | :path: "../node_modules/react-native/ReactCommon/reactperflogger" 377 | React-RCTActionSheet: 378 | :path: "../node_modules/react-native/Libraries/ActionSheetIOS" 379 | React-RCTAnimation: 380 | :path: "../node_modules/react-native/Libraries/NativeAnimation" 381 | React-RCTBlob: 382 | :path: "../node_modules/react-native/Libraries/Blob" 383 | React-RCTImage: 384 | :path: "../node_modules/react-native/Libraries/Image" 385 | React-RCTLinking: 386 | :path: "../node_modules/react-native/Libraries/LinkingIOS" 387 | React-RCTNetwork: 388 | :path: "../node_modules/react-native/Libraries/Network" 389 | React-RCTSettings: 390 | :path: "../node_modules/react-native/Libraries/Settings" 391 | React-RCTText: 392 | :path: "../node_modules/react-native/Libraries/Text" 393 | React-RCTVibration: 394 | :path: "../node_modules/react-native/Libraries/Vibration" 395 | React-runtimeexecutor: 396 | :path: "../node_modules/react-native/ReactCommon/runtimeexecutor" 397 | ReactCommon: 398 | :path: "../node_modules/react-native/ReactCommon" 399 | terra-react: 400 | :path: "../node_modules/terra-react" 401 | Yoga: 402 | :path: "../node_modules/react-native/ReactCommon/yoga" 403 | 404 | SPEC CHECKSUMS: 405 | boost: 9fa78656d705f55b1220151d997e57e2a3f2cde0 406 | DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 407 | FBLazyVector: 6c76fe46345039d5cf0549e9ddaf5aa169630a4a 408 | FBReactNativeSpec: 1a270246542f5c52248cb26a96db119cfe3cb760 409 | fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 410 | glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b 411 | RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda 412 | RCTRequired: d0e501e8024056451424aa341daa078c0c620b0d 413 | RCTTypeSafety: 14a3928ef69eeb4e5bb4f36fefb5ed6a392643ac 414 | React: a76fa5a8f540c9625fc16cfb3a7bbae9877716d5 415 | React-bridging: 3b8c4365cf22dc668cb4f29eafd83ace49a87835 416 | React-callinvoker: 0b108cf2d78be04f46f5e5fff53acfd019f8b9ab 417 | React-Codegen: 2f3419b3a3c825ccb6a399bcf0db53b9761235ed 418 | React-Core: 0a760f00a2cf3f44324266c227b01594f95ef7a0 419 | React-CoreModules: 4c5bc80e046efcb695d826ba276567051f91321e 420 | React-cxxreact: b07535295fd2c773a681f09d87dcba342e46dc7d 421 | React-jsi: baa181d7aa5867d5438f7969a257846cd7a97559 422 | React-jsiexecutor: be588b7abbea4f1d03840bc675d68d99380e5bf3 423 | React-jsinspector: bd839d6c2c28e49fe1373f055735d2abecbd6cf3 424 | React-logger: 48d82b9be8e44d86668de4453fdb60255516388b 425 | React-perflogger: 77947e49d84e31eb87d454d4ef327542dcfeaebc 426 | React-RCTActionSheet: 9f5fd6c1666c1a834ab7f45a452ed08b1de44eb8 427 | React-RCTAnimation: 6fd3db6ca387c8432fd6a26428e940a081bcb476 428 | React-RCTBlob: 43ff9a00ea606c911c14da74a5bd0a07b54d0c34 429 | React-RCTImage: 10ef13883116c1fd67ec3229d96556893771f747 430 | React-RCTLinking: ff75f970da9e1b0491cfe642f34d8a1ab5338715 431 | React-RCTNetwork: 0528cb19329a0764061ec053c4e3ab8a52ad8741 432 | React-RCTSettings: 26ef15ef3a9019fc09f4f8264f5ca79bf4dfc6de 433 | React-RCTText: 4eeb0a8afd28d691f0bd4c104bf3234d79c78b0c 434 | React-RCTVibration: 5499b77c0fd57f346a5f0b36bb79fdb020d17d3e 435 | React-runtimeexecutor: 80c195ffcafb190f531fdc849dc2d19cb4bb2b34 436 | ReactCommon: de55f940495d7bf87b5d7bf55b5b15cdd50d7d7b 437 | terra-react: 7d27afc1bbd9976c1079fa7fd71a8fea0292e7db 438 | TerraiOS: 131a86c453923b98c47e84dc79db2ea6bab7e3cc 439 | Yoga: 82c9e8f652789f67d98bed5aef9d6653f71b04a9 440 | 441 | PODFILE CHECKSUM: 90aedc9257970232a9c84672d116813708898eaf 442 | 443 | COCOAPODS: 1.16.2 444 | -------------------------------------------------------------------------------- /android/src/main/java/com/terrareact/TerraReactModule.java: -------------------------------------------------------------------------------- 1 | package com.terrareact; 2 | 3 | import android.os.Build; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.annotation.RequiresApi; 7 | 8 | import com.facebook.react.bridge.Promise; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 11 | import com.facebook.react.bridge.ReactMethod; 12 | import com.facebook.react.bridge.ReadableMap; 13 | import com.facebook.react.bridge.WritableMap; 14 | import com.facebook.react.bridge.WritableArray; 15 | import com.facebook.react.bridge.WritableNativeArray; 16 | import com.facebook.react.bridge.WritableNativeMap; 17 | import com.facebook.react.module.annotations.ReactModule; 18 | import com.facebook.react.bridge.ReadableArray; 19 | 20 | 21 | import java.util.Date; 22 | import java.util.HashMap; 23 | import java.util.Objects; 24 | import java.time.Instant; 25 | import java.util.HashSet; 26 | import java.util.Map; 27 | 28 | import com.google.gson.Gson; 29 | 30 | import co.tryterra.terra.Terra; 31 | import co.tryterra.terra.TerraManager; 32 | import co.tryterra.terra.enums.Connections; 33 | import co.tryterra.terra.enums.CustomPermissions; 34 | import kotlin.Unit; 35 | 36 | @RequiresApi(api = Build.VERSION_CODES.O) 37 | @ReactModule(name = TerraReactModule.NAME) 38 | public class TerraReactModule extends ReactContextBaseJavaModule { 39 | public static final String NAME = "TerraReact"; 40 | 41 | private Gson gson = new Gson(); 42 | 43 | public TerraReactModule(ReactApplicationContext reactContext) { 44 | super(reactContext); 45 | } 46 | public TerraManager terra; 47 | 48 | @Override 49 | @NonNull 50 | public String getName() { 51 | return NAME; 52 | } 53 | 54 | private Connections parseConnection(String connection){ 55 | switch (connection){ 56 | case "SAMSUNG": 57 | return Connections.SAMSUNG; 58 | case "GOOGLE": 59 | return Connections.GOOGLE_FIT; 60 | case "FREESTYLE_LIBRE": 61 | return Connections.FREESTYLE_LIBRE; 62 | case "HEALTH_CONNECT": 63 | return Connections.HEALTH_CONNECT; 64 | } 65 | return null; 66 | } 67 | 68 | private CustomPermissions parseCustomPermission(String customPermission){ 69 | switch (customPermission){ 70 | case "WORKOUT_TYPES": 71 | return CustomPermissions.WORKOUT_TYPE; 72 | case "ACTIVITY_SUMMARY": 73 | return CustomPermissions.ACTIVITY_SUMMARY; 74 | case "LOCATION": 75 | return CustomPermissions.LOCATION; 76 | case "CALORIES": 77 | return CustomPermissions.CALORIES; 78 | case "STEPS": 79 | return CustomPermissions.STEPS; 80 | case "HEART_RATE": 81 | return CustomPermissions.HEART_RATE; 82 | case "HEART_RATE_VARIABILITY": 83 | return CustomPermissions.HEART_RATE_VARIABILITY; 84 | case "VO2MAX": 85 | return CustomPermissions.VO2MAX; 86 | case "HEIGHT": 87 | return CustomPermissions.HEIGHT; 88 | case "ACTIVE_DURATIONS": 89 | return CustomPermissions.ACTIVE_DURATIONS; 90 | case "WEIGHT": 91 | return CustomPermissions.WEIGHT; 92 | case "FLIGHTS_CLIMBED": 93 | return CustomPermissions.FLIGHTS_CLIMBED; 94 | case "BMI": 95 | return CustomPermissions.BMI; 96 | case "BODY_FAT": 97 | return CustomPermissions.BODY_FAT; 98 | case "EXERCISE_DISTANCE": 99 | return CustomPermissions.EXERCISE_DISTANCE; 100 | case "GENDER": 101 | return CustomPermissions.GENDER; 102 | case "DATE_OF_BIRTH": 103 | return CustomPermissions.DATE_OF_BIRTH; 104 | case "BASAL_ENERGY_BURNED": 105 | return CustomPermissions.BASAL_ENERGY_BURNED; 106 | case "SWIMMING_SUMMARY": 107 | return CustomPermissions.SWIMMING_SUMMARY; 108 | case "RESTING_HEART_RATE": 109 | return CustomPermissions.RESTING_HEART_RATE; 110 | case "BLOOD_PRESSURE": 111 | return CustomPermissions.BLOOD_PRESSURE; 112 | case "BLOOD_GLUCOSE": 113 | return CustomPermissions.BLOOD_GLUCOSE; 114 | case "BODY_TEMPERATURE": 115 | return CustomPermissions.BODY_TEMPERATURE; 116 | case "MINDFULNESS": 117 | return CustomPermissions.MINDFULNESS; 118 | case "LEAN_BODY_MASS": 119 | return CustomPermissions.LEAN_BODY_MASS; 120 | case "OXYGEN_SATURATION": 121 | return CustomPermissions.OXYGEN_SATURATION; 122 | case "SLEEP_ANALYSIS": 123 | return CustomPermissions.SLEEP_ANALYSIS; 124 | case "RESPIRATORY_RATE": 125 | return CustomPermissions.RESPIRATORY_RATE; 126 | case "NUTRITION_SODIUM": 127 | return CustomPermissions.NUTRITION_SODIUM; 128 | case "NUTRITION_PROTEIN": 129 | return CustomPermissions.NUTRITION_PROTEIN; 130 | case "NUTRITION_CARBOHYDRATES": 131 | return CustomPermissions.NUTRITION_CARBOHYDRATES; 132 | case "NUTRITION_FIBRE": 133 | return CustomPermissions.NUTRITION_FIBRE; 134 | case "NUTRITION_FAT_TOTAL": 135 | return CustomPermissions.NUTRITION_FAT_TOTAL; 136 | case "NUTRITION_SUGAR": 137 | return CustomPermissions.NUTRITION_SUGAR; 138 | case "NUTRITION_VITAMIN_C": 139 | return CustomPermissions.NUTRITION_VITAMIN_C; 140 | case "NUTRITION_VITAMIN_A": 141 | return CustomPermissions.NUTRITION_VITAMIN_A; 142 | case "NUTRITION_CALORIES": 143 | return CustomPermissions.NUTRITION_CALORIES; 144 | case "NUTRITION_WATER": 145 | return CustomPermissions.NUTRITION_WATER; 146 | case "NUTRITION_CHOLESTEROL": 147 | return CustomPermissions.NUTRITION_CHOLESTEROL; 148 | case "POWER": 149 | return CustomPermissions.POWER; 150 | case "SPEED": 151 | return CustomPermissions.SPEED; 152 | default: 153 | return null; 154 | } 155 | } 156 | 157 | @ReactMethod 158 | public void initTerra(String devID, String referenceId, Promise promise) { 159 | if (this.getCurrentActivity() == null){ 160 | WritableMap map = new WritableNativeMap(); 161 | map.putBoolean("success", false); 162 | map.putString("error", "Unable to resolve current activity"); 163 | promise.resolve(map); 164 | return; 165 | } 166 | 167 | Terra.Companion.instance( 168 | devID, 169 | referenceId, 170 | Objects.requireNonNull(this.getCurrentActivity()), 171 | (terraManager, error) ->{ 172 | this.terra = terraManager; 173 | WritableMap map = new WritableNativeMap(); 174 | map.putBoolean("success", terraManager != null); 175 | if (error != null){ 176 | map.putString("error", error.getMessage()); 177 | } 178 | promise.resolve(map); 179 | return Unit.INSTANCE; 180 | }); 181 | } 182 | 183 | @ReactMethod 184 | public void initConnection(String connection, String token, Boolean schedulerOn, ReadableArray customPermissions, String startIntent, Promise promise){ 185 | WritableMap map = new WritableNativeMap(); 186 | if (token == null){ 187 | map.putBoolean("success", false); 188 | map.putString("error", "Please make sure you pass a valid token"); 189 | return; 190 | } 191 | 192 | if (this.terra == null){ 193 | map.putBoolean("success", false); 194 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 195 | return; 196 | } 197 | 198 | if (parseConnection(connection) == null){ 199 | map.putBoolean("success", false); 200 | map.putString("error", "Invalid Connection type passed"); 201 | promise.resolve(map); 202 | return; 203 | } 204 | 205 | HashSet cPermissions = new HashSet<>(); 206 | for (Object customPermission: customPermissions.toArrayList()){ 207 | if (customPermission == null && parseCustomPermission((String) customPermission) == null){ 208 | continue; 209 | } 210 | cPermissions.add(parseCustomPermission((String) customPermission)); 211 | } 212 | 213 | this.terra.initConnection(Objects.requireNonNull(parseConnection(connection)), token, Objects.requireNonNull(this.getCurrentActivity()), cPermissions, schedulerOn, startIntent, 214 | (success, error)-> { 215 | map.putBoolean("success", success); 216 | if (error != null){ 217 | map.putString("error", error.getMessage()); 218 | } 219 | promise.resolve(map); 220 | return Unit.INSTANCE; 221 | }); 222 | } 223 | 224 | @ReactMethod 225 | public void getUserId(String connection, Promise promise){ 226 | WritableMap map = new WritableNativeMap(); 227 | if (this.terra == null){ 228 | map.putBoolean("success", false); 229 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 230 | return; 231 | } 232 | 233 | if (parseConnection(connection) == null){ 234 | map.putBoolean("success", false); 235 | map.putString("error", "Invalid Connection type passed"); 236 | promise.resolve(map); 237 | return; 238 | } 239 | 240 | map.putBoolean("success", true); 241 | map.putString("userId", this.terra.getUserId(Objects.requireNonNull(parseConnection(connection)))); 242 | promise.resolve(map); 243 | } 244 | 245 | @ReactMethod 246 | public void getAthlete(String connection, Boolean toWebhook, Promise promise){ 247 | promise.reject("Unimplemented function for Android"); 248 | } 249 | 250 | @ReactMethod 251 | public void getBody(String connection, String startDate, String endDate, Boolean latestReading, Boolean toWebhook, Promise promise){ 252 | WritableMap map = new WritableNativeMap(); 253 | if (this.terra == null){ 254 | map.putBoolean("success", false); 255 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 256 | return; 257 | } 258 | 259 | if (parseConnection(connection) == null){ 260 | map.putBoolean("success", false); 261 | map.putString("error", "Invalid Connection type passed"); 262 | promise.resolve(map); 263 | return; 264 | } 265 | 266 | this.terra.getBody( 267 | Objects.requireNonNull(parseConnection(connection)), 268 | Date.from(Instant.parse(startDate)), 269 | Date.from(Instant.parse(endDate)), 270 | toWebhook, 271 | (success, data, error) ->{ 272 | map.putBoolean("success", success); 273 | if (data != null){ 274 | map.putString("data", gson.toJson(data)); 275 | } 276 | if (error != null){ 277 | map.putString("error", error.getMessage()); 278 | } 279 | promise.resolve(map); 280 | return Unit.INSTANCE; 281 | }); 282 | } 283 | 284 | @ReactMethod 285 | public void getActivity(String connection, String startDate, String endDate, Boolean toWebhook, Promise promise){ 286 | WritableMap map = new WritableNativeMap(); 287 | if (this.terra == null){ 288 | map.putBoolean("success", false); 289 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 290 | return; 291 | } 292 | 293 | if (parseConnection(connection) == null){ 294 | map.putBoolean("success", false); 295 | map.putString("error", "Invalid Connection type passed"); 296 | promise.resolve(map); 297 | return; 298 | } 299 | 300 | this.terra.getActivity( 301 | Objects.requireNonNull(parseConnection(connection)), 302 | Date.from(Instant.parse(startDate)), 303 | Date.from(Instant.parse(endDate)), 304 | toWebhook, 305 | (success, data, error) ->{ 306 | map.putBoolean("success", success); 307 | if (data != null){ 308 | map.putString("data", gson.toJson(data)); 309 | } 310 | if (error != null){ 311 | map.putString("error", error.getMessage()); 312 | } 313 | promise.resolve(map); 314 | return Unit.INSTANCE; 315 | }); 316 | } 317 | 318 | @ReactMethod 319 | public void getDaily(String connection, String startDate, String endDate, Boolean toWebhook, Promise promise){ 320 | WritableMap map = new WritableNativeMap(); 321 | if (this.terra == null){ 322 | map.putBoolean("success", false); 323 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 324 | return; 325 | } 326 | 327 | if (parseConnection(connection) == null){ 328 | map.putBoolean("success", false); 329 | map.putString("error", "Invalid Connection type passed"); 330 | promise.resolve(map); 331 | return; 332 | } 333 | 334 | this.terra.getDaily( 335 | Objects.requireNonNull(parseConnection(connection)), 336 | Date.from(Instant.parse(startDate)), 337 | Date.from(Instant.parse(endDate)), 338 | toWebhook, 339 | (success, data, error) ->{ 340 | map.putBoolean("success", success); 341 | if (data != null){ 342 | map.putString("data", gson.toJson(data)); 343 | } 344 | if (error != null){ 345 | map.putString("error", error.getMessage()); 346 | } 347 | promise.resolve(map); 348 | return Unit.INSTANCE; 349 | }); 350 | } 351 | 352 | @ReactMethod 353 | public void getNutrition(String connection, String startDate, String endDate, Boolean toWebhook, Promise promise){ 354 | WritableMap map = new WritableNativeMap(); 355 | if (this.terra == null){ 356 | map.putBoolean("success", false); 357 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 358 | return; 359 | } 360 | 361 | if (parseConnection(connection) == null){ 362 | map.putBoolean("success", false); 363 | map.putString("error", "Invalid Connection type passed"); 364 | promise.resolve(map); 365 | return; 366 | } 367 | 368 | this.terra.getNutrition( 369 | Objects.requireNonNull(parseConnection(connection)), 370 | Date.from(Instant.parse(startDate)), 371 | Date.from(Instant.parse(endDate)), 372 | toWebhook, 373 | (success, data, error) ->{ 374 | map.putBoolean("success", success); 375 | if (data != null){ 376 | map.putString("data", gson.toJson(data)); 377 | } 378 | if (error != null){ 379 | map.putString("error", error.getMessage()); 380 | } 381 | promise.resolve(map); 382 | return Unit.INSTANCE; 383 | }); 384 | } 385 | 386 | @ReactMethod 387 | public void getSleep(String connection, String startDate, String endDate, Boolean toWebhook, Promise promise){ 388 | WritableMap map = new WritableNativeMap(); 389 | if (this.terra == null){ 390 | map.putBoolean("success", false); 391 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 392 | return; 393 | } 394 | 395 | if (parseConnection(connection) == null){ 396 | map.putBoolean("success", false); 397 | map.putString("error", "Invalid Connection type passed"); 398 | promise.resolve(map); 399 | return; 400 | } 401 | 402 | this.terra.getSleep( 403 | Objects.requireNonNull(parseConnection(connection)), 404 | Date.from(Instant.parse(startDate)), 405 | Date.from(Instant.parse(endDate)), 406 | toWebhook, 407 | (success, data, error) ->{ 408 | map.putBoolean("success", success); 409 | if (data != null){ 410 | map.putString("data", gson.toJson(data)); 411 | } 412 | if (error != null){ 413 | map.putString("error", error.getMessage()); 414 | } 415 | promise.resolve(map); 416 | return Unit.INSTANCE; 417 | }); 418 | } 419 | 420 | @ReactMethod 421 | public void getMenstruation(String connection, String startDate, String endDate, Boolean toWebhook, Promise promise){ 422 | promise.reject("Unimplemented function for Android"); 423 | } 424 | 425 | @ReactMethod 426 | public void readGlucoseData(Promise promise){ 427 | if (this.terra == null){ 428 | WritableMap map = new WritableNativeMap(); 429 | map.putBoolean("success", false); 430 | map.putString("error", "Please make sure Terra is instantiated with initTerra"); 431 | return; 432 | } 433 | 434 | this.terra.readGlucoseData((details) -> { 435 | promise.resolve(gson.toJson(details)); 436 | return Unit.INSTANCE; 437 | }); 438 | } 439 | 440 | @ReactMethod 441 | public void activateSensor(Promise promise){ 442 | WritableMap map = new WritableNativeMap(); 443 | map.putBoolean("success", true); 444 | promise.resolve(map); 445 | } 446 | 447 | @ReactMethod 448 | public void grantedPermissions(Promise promise){ 449 | if (this.terra == null){ 450 | WritableArray perms = new WritableNativeArray(); 451 | promise.resolve(perms); 452 | return; 453 | } 454 | 455 | terra.allGivenPermissions((permissions) -> { 456 | WritableArray perms = new WritableNativeArray(); 457 | permissions.forEach((perm) -> { 458 | perms.pushString(perm); 459 | }); 460 | promise.resolve(perms); 461 | return Unit.INSTANCE; 462 | }); 463 | } 464 | 465 | @ReactMethod 466 | public void openHealthConnect(Promise promise){ 467 | if (this.getCurrentActivity() == null){ 468 | return; 469 | } 470 | Terra.Companion.openHealthConnect(Objects.requireNonNull(this.getCurrentActivity())); 471 | } 472 | 473 | @ReactMethod 474 | public void isHealthConnectAvailable(Promise promise){ 475 | if (this.getCurrentActivity() == null){ 476 | promise.resolve(false); 477 | return; 478 | } 479 | promise.resolve(Terra.Companion.isHealthConnectAvailable(Objects.requireNonNull(this.getCurrentActivity()))); 480 | } 481 | 482 | @ReactMethod 483 | public void checkAuth(String connection, String devID, Promise promise){ 484 | WritableMap map = new WritableNativeMap(); 485 | if (this.terra == null){ 486 | map.putBoolean("success", false); 487 | return; 488 | } 489 | 490 | 491 | if (parseConnection(connection) == null){ 492 | map.putBoolean("success", false); 493 | promise.resolve(map); 494 | return; 495 | } 496 | 497 | this.terra.checkAuth(parseConnection(connection), (success) -> { 498 | map.putBoolean("success", success); 499 | promise.resolve(map); 500 | return Unit.INSTANCE; 501 | }); 502 | } 503 | 504 | @ReactMethod 505 | public void setIgnoredSources(ReadableArray sources, Promise promise){ 506 | // Functionality not implemented for Android yet 507 | } 508 | 509 | @ReactMethod 510 | public void postActivity(String connection, ReadableMap payload, Promise promise) { 511 | promise.reject("Unimplemented function for Android"); 512 | } 513 | 514 | @ReactMethod 515 | public void getPlannedWorkouts(String connection, Promise promise) { 516 | promise.reject("Unimplemented function for Android"); 517 | } 518 | 519 | @ReactMethod 520 | public void deletePlannedWorkout(String connection, String id, Promise promise) { 521 | promise.reject("Unimplemented function for Android"); 522 | } 523 | 524 | @ReactMethod 525 | public void completePlannedWorkout(String connection, String id, String date, Promise promise) { 526 | promise.reject("Unimplemented function for Android"); 527 | } 528 | 529 | @ReactMethod 530 | public void postPlannedWorkout(String connection, String payload, Promise promise) { 531 | promise.reject("Unimplemented function for Android"); 532 | } 533 | } 534 | --------------------------------------------------------------------------------