react-native-spike-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +184 -0
  3. package/android/build.gradle +82 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +18 -0
  7. package/android/src/main/java/com/spikesdk/SpikeSdkPackage.kt +17 -0
  8. package/ios/SpikeSdk-Bridging-Header.h +2 -0
  9. package/ios/SpikeSdk.m +36 -0
  10. package/ios/SpikeSdk.swift +135 -0
  11. package/ios/SpikeSdk.xcodeproj/project.pbxproj +281 -0
  12. package/ios/SpikeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  13. package/ios/SpikeSdk.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  14. package/ios/SpikeSdk.xcodeproj/project.xcworkspace/xcuserdata/ekroman.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  15. package/ios/SpikeSdk.xcodeproj/xcuserdata/ekroman.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  16. package/lib/commonjs/Spike.js +68 -0
  17. package/lib/commonjs/Spike.js.map +1 -0
  18. package/lib/commonjs/SpikeDataType.js +2 -0
  19. package/lib/commonjs/SpikeDataType.js.map +1 -0
  20. package/lib/commonjs/SpikeInterface.js +6 -0
  21. package/lib/commonjs/SpikeInterface.js.map +1 -0
  22. package/lib/commonjs/SpikeResultData.js +2 -0
  23. package/lib/commonjs/SpikeResultData.js.map +1 -0
  24. package/lib/commonjs/SpikeSdk.js +18 -0
  25. package/lib/commonjs/SpikeSdk.js.map +1 -0
  26. package/lib/commonjs/index.js +19 -0
  27. package/lib/commonjs/index.js.map +1 -0
  28. package/lib/commonjs/useSpikeEvents.js +36 -0
  29. package/lib/commonjs/useSpikeEvents.js.map +1 -0
  30. package/lib/module/Spike.js +61 -0
  31. package/lib/module/Spike.js.map +1 -0
  32. package/lib/module/SpikeDataType.js +2 -0
  33. package/lib/module/SpikeDataType.js.map +1 -0
  34. package/lib/module/SpikeInterface.js +2 -0
  35. package/lib/module/SpikeInterface.js.map +1 -0
  36. package/lib/module/SpikeResultData.js +2 -0
  37. package/lib/module/SpikeResultData.js.map +1 -0
  38. package/lib/module/SpikeSdk.js +11 -0
  39. package/lib/module/SpikeSdk.js.map +1 -0
  40. package/lib/module/index.js +6 -0
  41. package/lib/module/index.js.map +1 -0
  42. package/lib/module/useSpikeEvents.js +29 -0
  43. package/lib/module/useSpikeEvents.js.map +1 -0
  44. package/lib/typescript/Spike.d.ts +14 -0
  45. package/lib/typescript/Spike.d.ts.map +1 -0
  46. package/lib/typescript/SpikeDataType.d.ts +2 -0
  47. package/lib/typescript/SpikeDataType.d.ts.map +1 -0
  48. package/lib/typescript/SpikeInterface.d.ts +13 -0
  49. package/lib/typescript/SpikeInterface.d.ts.map +1 -0
  50. package/lib/typescript/SpikeResultData.d.ts +26 -0
  51. package/lib/typescript/SpikeResultData.d.ts.map +1 -0
  52. package/lib/typescript/SpikeSdk.d.ts +2 -0
  53. package/lib/typescript/SpikeSdk.d.ts.map +1 -0
  54. package/lib/typescript/index.d.ts +9 -0
  55. package/lib/typescript/index.d.ts.map +1 -0
  56. package/lib/typescript/useSpikeEvents.d.ts +10 -0
  57. package/lib/typescript/useSpikeEvents.d.ts.map +1 -0
  58. package/package.json +131 -0
  59. package/react-native-spike-sdk.podspec +44 -0
  60. package/src/Spike.ts +76 -0
  61. package/src/SpikeDataType.ts +8 -0
  62. package/src/SpikeInterface.ts +26 -0
  63. package/src/SpikeResultData.ts +25 -0
  64. package/src/SpikeSdk.ts +18 -0
  65. package/src/index.ts +18 -0
  66. package/src/useSpikeEvents.ts +37 -0
@@ -0,0 +1,14 @@
1
+ import type { SpikeDataType } from './SpikeDataType';
2
+ import type { SpikeInterface } from './SpikeInterface';
3
+ export declare class Spike implements SpikeInterface {
4
+ isBackgroundUpdateEnabled(): Promise<boolean>;
5
+ enableDebug(): void;
6
+ initialize(): void;
7
+ setup(clientId: string, authToken: string, userId: string, postbackURL?: string): void;
8
+ getCurrentUUID(): Promise<string | undefined>;
9
+ clearData(): void;
10
+ getData(dataTypes: SpikeDataType[]): void;
11
+ enableBackgroundDelivery(dataTypes: SpikeDataType[]): Promise<void>;
12
+ disableAllBackgroundDelivery(): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=Spike.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Spike.d.ts","sourceRoot":"","sources":["../../src/Spike.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,qBAAa,KAAM,YAAW,cAAc;IACpC,yBAAyB,IAAI,OAAO,CAAC,OAAO,CAAC;IAOnD,WAAW,IAAI,IAAI;IAMnB,UAAU,IAAI,IAAI;IAMlB,KAAK,CACH,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI;IAUD,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAYnD,SAAS,IAAI,IAAI;IAMjB,OAAO,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,IAAI;IAMnC,wBAAwB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnE,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC;CAKpD"}
@@ -0,0 +1,2 @@
1
+ export type SpikeDataType = 'DataTypeStep' | 'DataTypeHeartRate' | 'DataTypeRestingHeartRate' | 'DataTypeActiveEnergy' | 'DataTypeBasalEnergy' | 'DataTypeAppleMoveTime' | 'DataTypeAppleExerciseTime';
2
+ //# sourceMappingURL=SpikeDataType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpikeDataType.d.ts","sourceRoot":"","sources":["../../src/SpikeDataType.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACrB,cAAc,GACd,mBAAmB,GACnB,0BAA0B,GAC1B,sBAAsB,GACtB,qBAAqB,GACrB,uBAAuB,GACvB,2BAA2B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { SpikeDataType } from './SpikeDataType';
2
+ export interface SpikeInterface {
3
+ isBackgroundUpdateEnabled(): Promise<boolean>;
4
+ enableDebug(): void;
5
+ initialize(): void;
6
+ setup(clientId: string, authToken: string, userId: string, postbackURL?: string): void;
7
+ getCurrentUUID(): Promise<string | undefined>;
8
+ clearData(): void;
9
+ getData(dataTypes: SpikeDataType[]): void;
10
+ enableBackgroundDelivery(dataTypes: SpikeDataType[]): Promise<void>;
11
+ disableAllBackgroundDelivery(): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=SpikeInterface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpikeInterface.d.ts","sourceRoot":"","sources":["../../src/SpikeInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,cAAc;IAC7B,yBAAyB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9C,WAAW,IAAI,IAAI,CAAC;IAEpB,UAAU,IAAI,IAAI,CAAC;IAEnB,KAAK,CACH,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI,CAAC;IAER,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAE9C,SAAS,IAAI,IAAI,CAAC;IAElB,OAAO,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IAE1C,wBAAwB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C"}
@@ -0,0 +1,26 @@
1
+ export interface SpikeResultData {
2
+ date?: string;
3
+ calories_bmr?: number;
4
+ calories_total?: number;
5
+ calories_active?: number;
6
+ steps?: number;
7
+ daily_movement?: number;
8
+ low?: number;
9
+ medium?: number;
10
+ high?: number;
11
+ elevation?: number;
12
+ resting_hr?: number;
13
+ floors?: number;
14
+ sedentary_minutes?: number;
15
+ min_hr?: number;
16
+ avg_hr?: number;
17
+ max_hr?: number;
18
+ avg_stress_level?: number;
19
+ max_stress_level?: number;
20
+ stress_duration?: number;
21
+ low_stress_duration?: number;
22
+ medium_stress_duration?: number;
23
+ high_stress_duration?: number;
24
+ source?: string;
25
+ }
26
+ //# sourceMappingURL=SpikeResultData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpikeResultData.d.ts","sourceRoot":"","sources":["../../src/SpikeResultData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,2 @@
1
+ export declare const SpikeSdk: any;
2
+ //# sourceMappingURL=SpikeSdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpikeSdk.d.ts","sourceRoot":"","sources":["../../src/SpikeSdk.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,QAAQ,KAShB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Spike } from './Spike';
2
+ import type { SpikeDataType } from './SpikeDataType';
3
+ import type { SpikeResultData } from './SpikeResultData';
4
+ import { useSpikeEvents } from './useSpikeEvents';
5
+ declare const _default: Spike;
6
+ export default _default;
7
+ export { useSpikeEvents, SpikeDataType, SpikeResultData };
8
+ export declare const SpikeDataTypesAll: SpikeDataType[];
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;;AAElD,wBAA2B;AAE3B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAE1D,eAAO,MAAM,iBAAiB,EAAE,aAAa,EAQ5C,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { SpikeResultData } from './SpikeResultData';
2
+ type Props = {
3
+ onInitialize?: (uuid: string) => void;
4
+ onInitializationFailure?: () => void;
5
+ onDataResult?: (result: SpikeResultData) => void;
6
+ onDataFailure?: () => void;
7
+ };
8
+ export declare const useSpikeEvents: ({ onInitialize, onInitializationFailure, onDataResult, onDataFailure, }: Props) => void;
9
+ export {};
10
+ //# sourceMappingURL=useSpikeEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSpikeEvents.d.ts","sourceRoot":"","sources":["../../src/useSpikeEvents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,KAAK,KAAK,GAAG;IACX,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,uBAAuB,CAAC,EAAE,MAAM,IAAI,CAAC;IACrC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;IACjD,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,cAAc,4EAKxB,KAAK,SAoBP,CAAC"}
package/package.json ADDED
@@ -0,0 +1,131 @@
1
+ {
2
+ "name": "react-native-spike-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Spike API for health and productivity data from wearables and IoT devices",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "!lib/typescript/example",
18
+ "!ios/build",
19
+ "!android/build",
20
+ "!android/gradle",
21
+ "!android/gradlew",
22
+ "!android/gradlew.bat",
23
+ "!android/local.properties",
24
+ "!**/__tests__",
25
+ "!**/__fixtures__",
26
+ "!**/__mocks__",
27
+ "!**/.*"
28
+ ],
29
+ "scripts": {
30
+ "test": "jest",
31
+ "typecheck": "tsc --noEmit",
32
+ "prepack": "bob build",
33
+ "release": "release-it",
34
+ "example": "yarn --cwd example",
35
+ "bootstrap": "yarn example && yarn install && yarn example pods",
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
37
+ },
38
+ "keywords": [
39
+ "react-native",
40
+ "ios",
41
+ "android"
42
+ ],
43
+ "repository": "https://gitlab.com/spike_api/spike-react-native-sdk",
44
+ "author": "SpikeAPI <vytenis@spikeapi.com> (https://gitlab.com/spike_api/spike-react-native-sdk)",
45
+ "license": "MIT",
46
+ "bugs": {
47
+ "url": "https://gitlab.com/spike_api/spike-react-native-sdk/issues"
48
+ },
49
+ "homepage": "https://gitlab.com/spike_api/spike-react-native-sdk#readme",
50
+ "publishConfig": {
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "devDependencies": {
54
+ "@commitlint/config-conventional": "^17.0.2",
55
+ "@release-it/conventional-changelog": "^5.0.0",
56
+ "@types/jest": "^28.1.2",
57
+ "@types/react": "~17.0.21",
58
+ "@types/react-native": "0.70.0",
59
+ "commitlint": "^17.0.2",
60
+ "del-cli": "^5.0.0",
61
+ "jest": "^28.1.1",
62
+ "pod-install": "^0.1.0",
63
+ "prettier": "^2.0.5",
64
+ "react": "18.2.0",
65
+ "react-native": "0.71.1",
66
+ "react-native-builder-bob": "^0.20.0",
67
+ "release-it": "^15.0.0",
68
+ "typescript": "^4.5.2"
69
+ },
70
+ "resolutions": {
71
+ "@types/react": "17.0.21"
72
+ },
73
+ "peerDependencies": {
74
+ "react": "*",
75
+ "react-native": "*"
76
+ },
77
+ "engines": {
78
+ "node": ">= 16.0.0"
79
+ },
80
+ "packageManager": "^yarn@1.22.15",
81
+ "jest": {
82
+ "preset": "react-native",
83
+ "modulePathIgnorePatterns": [
84
+ "<rootDir>/example/node_modules",
85
+ "<rootDir>/lib/"
86
+ ]
87
+ },
88
+ "commitlint": {
89
+ "extends": [
90
+ "@commitlint/config-conventional"
91
+ ]
92
+ },
93
+ "release-it": {
94
+ "git": {
95
+ "commitMessage": "chore: release ${version}",
96
+ "tagName": "v${version}"
97
+ },
98
+ "npm": {
99
+ "publish": true
100
+ },
101
+ "github": {
102
+ "release": true
103
+ },
104
+ "plugins": {
105
+ "@release-it/conventional-changelog": {
106
+ "preset": "angular"
107
+ }
108
+ }
109
+ },
110
+ "prettier": {
111
+ "quoteProps": "consistent",
112
+ "singleQuote": true,
113
+ "tabWidth": 2,
114
+ "trailingComma": "es5",
115
+ "useTabs": false
116
+ },
117
+ "react-native-builder-bob": {
118
+ "source": "src",
119
+ "output": "lib",
120
+ "targets": [
121
+ "commonjs",
122
+ "module",
123
+ [
124
+ "typescript",
125
+ {
126
+ "project": "tsconfig.build.json"
127
+ }
128
+ ]
129
+ ]
130
+ }
131
+ }
@@ -0,0 +1,44 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-spike-sdk"
8
+ s.version = "0.1.0"
9
+ s.summary = "Spike API for health and productivity data from wearables and IoT devices"
10
+
11
+ s.description = <<-DESC
12
+ Connect your app to users’ real-time data via a single API and enable new (data-driven) functionality and personalisation
13
+ DESC
14
+
15
+ s.homepage = "https://gitlab.com/spike_api/spike-react-native-sdk.git"
16
+ s.license = { :type => 'MIT', :file => 'LICENSE' }
17
+ s.author = { "SpikeAPI" => "vytenis@spikeapi.com" }
18
+
19
+
20
+ s.source = { :git => "https://gitlab.com/spike_api/spike-react-native-sdk.git", :tag => "#{s.version}" }
21
+
22
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
23
+
24
+ s.platform = :ios, "13.0"
25
+ s.swift_version = "5"
26
+
27
+ s.dependency "React-Core"
28
+ s.dependency "SpikeSDK", "0.1.5"
29
+
30
+ # Don't install the dependencies when we run `pod install` in the old architecture.
31
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
32
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
33
+ s.pod_target_xcconfig = {
34
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
35
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
36
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
37
+ }
38
+ s.dependency "React-Codegen"
39
+ s.dependency "RCT-Folly"
40
+ s.dependency "RCTRequired"
41
+ s.dependency "RCTTypeSafety"
42
+ s.dependency "ReactCommon/turbomodule/core"
43
+ end
44
+ end
package/src/Spike.ts ADDED
@@ -0,0 +1,76 @@
1
+ import { Platform } from 'react-native';
2
+ import type { SpikeDataType } from './SpikeDataType';
3
+ import type { SpikeInterface } from './SpikeInterface';
4
+ import { SpikeSdk } from './SpikeSdk';
5
+
6
+ export class Spike implements SpikeInterface {
7
+ async isBackgroundUpdateEnabled(): Promise<boolean> {
8
+ if (Platform.OS === 'ios') {
9
+ return SpikeSdk.isBackgroundUpdateEnabled();
10
+ }
11
+ return false;
12
+ }
13
+
14
+ enableDebug(): void {
15
+ if (Platform.OS === 'ios') {
16
+ SpikeSdk.enableDebug();
17
+ }
18
+ }
19
+
20
+ initialize(): void {
21
+ if (Platform.OS === 'ios') {
22
+ SpikeSdk.initialize();
23
+ }
24
+ }
25
+
26
+ setup(
27
+ clientId: string,
28
+ authToken: string,
29
+ userId: string,
30
+ postbackURL?: string
31
+ ): void {
32
+ if (Platform.OS === 'ios') {
33
+ if (postbackURL !== undefined) {
34
+ SpikeSdk.setupWithURL(clientId, authToken, userId, postbackURL);
35
+ } else {
36
+ SpikeSdk.setup(clientId, authToken, userId);
37
+ }
38
+ }
39
+ }
40
+
41
+ async getCurrentUUID(): Promise<string | undefined> {
42
+ if (Platform.OS === 'ios') {
43
+ const uuid: string = await SpikeSdk.getCurrentUUID();
44
+ if (uuid) {
45
+ return uuid;
46
+ } else {
47
+ return undefined;
48
+ }
49
+ }
50
+ return undefined;
51
+ }
52
+
53
+ clearData(): void {
54
+ if (Platform.OS === 'ios') {
55
+ SpikeSdk.clearData();
56
+ }
57
+ }
58
+
59
+ getData(dataTypes: SpikeDataType[]): void {
60
+ if (Platform.OS === 'ios') {
61
+ SpikeSdk.getData(dataTypes);
62
+ }
63
+ }
64
+
65
+ async enableBackgroundDelivery(dataTypes: SpikeDataType[]): Promise<void> {
66
+ if (Platform.OS === 'ios') {
67
+ return SpikeSdk.enableBackgroundDelivery(dataTypes);
68
+ }
69
+ }
70
+
71
+ async disableAllBackgroundDelivery(): Promise<void> {
72
+ if (Platform.OS === 'ios') {
73
+ return SpikeSdk.disableAllBackgroundDelivery();
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,8 @@
1
+ export type SpikeDataType =
2
+ | 'DataTypeStep'
3
+ | 'DataTypeHeartRate'
4
+ | 'DataTypeRestingHeartRate'
5
+ | 'DataTypeActiveEnergy'
6
+ | 'DataTypeBasalEnergy'
7
+ | 'DataTypeAppleMoveTime'
8
+ | 'DataTypeAppleExerciseTime';
@@ -0,0 +1,26 @@
1
+ import type { SpikeDataType } from './SpikeDataType';
2
+
3
+ export interface SpikeInterface {
4
+ isBackgroundUpdateEnabled(): Promise<boolean>;
5
+
6
+ enableDebug(): void;
7
+
8
+ initialize(): void;
9
+
10
+ setup(
11
+ clientId: string,
12
+ authToken: string,
13
+ userId: string,
14
+ postbackURL?: string
15
+ ): void;
16
+
17
+ getCurrentUUID(): Promise<string | undefined>;
18
+
19
+ clearData(): void;
20
+
21
+ getData(dataTypes: SpikeDataType[]): void;
22
+
23
+ enableBackgroundDelivery(dataTypes: SpikeDataType[]): Promise<void>;
24
+
25
+ disableAllBackgroundDelivery(): Promise<void>;
26
+ }
@@ -0,0 +1,25 @@
1
+ export interface SpikeResultData {
2
+ date?: string;
3
+ calories_bmr?: number;
4
+ calories_total?: number;
5
+ calories_active?: number;
6
+ steps?: number;
7
+ daily_movement?: number;
8
+ low?: number;
9
+ medium?: number;
10
+ high?: number;
11
+ elevation?: number;
12
+ resting_hr?: number;
13
+ floors?: number;
14
+ sedentary_minutes?: number;
15
+ min_hr?: number;
16
+ avg_hr?: number;
17
+ max_hr?: number;
18
+ avg_stress_level?: number;
19
+ max_stress_level?: number;
20
+ stress_duration?: number;
21
+ low_stress_duration?: number;
22
+ medium_stress_duration?: number;
23
+ high_stress_duration?: number;
24
+ source?: string;
25
+ }
@@ -0,0 +1,18 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package 'react-native-spike-sdk' doesn't seem to be linked. Make sure: \n\n` +
5
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
+ '- You rebuilt the app after installing the package\n' +
7
+ '- You are not using Expo Go\n';
8
+
9
+ export const SpikeSdk = NativeModules.SpikeSdk
10
+ ? NativeModules.SpikeSdk
11
+ : new Proxy(
12
+ {},
13
+ {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ },
17
+ }
18
+ );
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { Spike } from './Spike';
2
+ import type { SpikeDataType } from './SpikeDataType';
3
+ import type { SpikeResultData } from './SpikeResultData';
4
+ import { useSpikeEvents } from './useSpikeEvents';
5
+
6
+ export default new Spike();
7
+
8
+ export { useSpikeEvents, SpikeDataType, SpikeResultData };
9
+
10
+ export const SpikeDataTypesAll: SpikeDataType[] = [
11
+ 'DataTypeStep',
12
+ 'DataTypeHeartRate',
13
+ 'DataTypeRestingHeartRate',
14
+ 'DataTypeActiveEnergy',
15
+ 'DataTypeBasalEnergy',
16
+ 'DataTypeAppleMoveTime',
17
+ 'DataTypeAppleExerciseTime',
18
+ ];
@@ -0,0 +1,37 @@
1
+ import { NativeEventEmitter } from 'react-native';
2
+ import type { SpikeResultData } from './SpikeResultData';
3
+ import { SpikeSdk } from './SpikeSdk';
4
+
5
+ type Props = {
6
+ onInitialize?: (uuid: string) => void;
7
+ onInitializationFailure?: () => void;
8
+ onDataResult?: (result: SpikeResultData) => void;
9
+ onDataFailure?: () => void;
10
+ };
11
+
12
+ export const useSpikeEvents = ({
13
+ onInitialize,
14
+ onInitializationFailure,
15
+ onDataResult,
16
+ onDataFailure,
17
+ }: Props) => {
18
+ const SpikeSdkEvents = new NativeEventEmitter(SpikeSdk);
19
+
20
+ SpikeSdkEvents.addListener('onInitialize', (data: { uuid: string }) => {
21
+ console.log(`SpikeEvent: onInitialize: ${JSON.stringify(data)}`);
22
+ onInitialize?.(data.uuid);
23
+ });
24
+ SpikeSdkEvents.addListener('onInitializationFailure', () => {
25
+ console.log(`SpikeEvent: onInitializationFailure`);
26
+ onInitializationFailure?.();
27
+ });
28
+ SpikeSdkEvents.addListener('onDataResult', (data: { resultJson: string }) => {
29
+ console.log(`SpikeEvent: onDataResult: ${JSON.stringify(data.resultJson)}`);
30
+ const result: SpikeResultData = JSON.parse(data.resultJson);
31
+ onDataResult?.(result);
32
+ });
33
+ SpikeSdkEvents.addListener('onDataFailure', () => {
34
+ console.log('SpikeEvent: onDataFailure');
35
+ onDataFailure?.();
36
+ });
37
+ };