@solutionforest/android-health-connect 0.0.0-stage → 0.3.13

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 (59) hide show
  1. package/AndroidHealthConnect.podspec +20 -0
  2. package/CHANGELOG.md +202 -0
  3. package/LICENSE +20 -0
  4. package/README.md +847 -2
  5. package/SECURITY.md +99 -0
  6. package/android/build.gradle +104 -0
  7. package/android/src/main/AndroidManifest.xml +4 -0
  8. package/android/src/main/java/com/androidhealthconnect/AggregateMapper.kt +521 -0
  9. package/android/src/main/java/com/androidhealthconnect/AndroidHealthConnectModule.kt +637 -0
  10. package/android/src/main/java/com/androidhealthconnect/AndroidHealthConnectPackage.kt +31 -0
  11. package/android/src/main/java/com/androidhealthconnect/AvailabilitySupport.kt +149 -0
  12. package/android/src/main/java/com/androidhealthconnect/ChangesMapper.kt +105 -0
  13. package/android/src/main/java/com/androidhealthconnect/ExtendedRecordMapper.kt +665 -0
  14. package/android/src/main/java/com/androidhealthconnect/FeatureSupport.kt +88 -0
  15. package/android/src/main/java/com/androidhealthconnect/PhrMapper.kt +187 -0
  16. package/android/src/main/java/com/androidhealthconnect/PlannedExerciseMapper.kt +242 -0
  17. package/android/src/main/java/com/androidhealthconnect/RecordMapper.kt +1222 -0
  18. package/app.plugin.js +1 -0
  19. package/docs/assets/logo.jpg +0 -0
  20. package/ios/AndroidHealthConnect.h +5 -0
  21. package/ios/AndroidHealthConnect.mm +21 -0
  22. package/lib/module/NativeAndroidHealthConnect.js +5 -0
  23. package/lib/module/NativeAndroidHealthConnect.js.map +1 -0
  24. package/lib/module/foreground.js +117 -0
  25. package/lib/module/foreground.js.map +1 -0
  26. package/lib/module/helpers.js +280 -0
  27. package/lib/module/helpers.js.map +1 -0
  28. package/lib/module/index.js +354 -0
  29. package/lib/module/index.js.map +1 -0
  30. package/lib/module/package.json +1 -0
  31. package/lib/module/types.js +392 -0
  32. package/lib/module/types.js.map +1 -0
  33. package/lib/module/upgrade.js +101 -0
  34. package/lib/module/upgrade.js.map +1 -0
  35. package/lib/typescript/package.json +1 -0
  36. package/lib/typescript/plugin/src/index.d.ts +14 -0
  37. package/lib/typescript/plugin/src/index.d.ts.map +1 -0
  38. package/lib/typescript/src/NativeAndroidHealthConnect.d.ts +95 -0
  39. package/lib/typescript/src/NativeAndroidHealthConnect.d.ts.map +1 -0
  40. package/lib/typescript/src/foreground.d.ts +43 -0
  41. package/lib/typescript/src/foreground.d.ts.map +1 -0
  42. package/lib/typescript/src/helpers.d.ts +108 -0
  43. package/lib/typescript/src/helpers.d.ts.map +1 -0
  44. package/lib/typescript/src/index.d.ts +208 -0
  45. package/lib/typescript/src/index.d.ts.map +1 -0
  46. package/lib/typescript/src/types.d.ts +1209 -0
  47. package/lib/typescript/src/types.d.ts.map +1 -0
  48. package/lib/typescript/src/upgrade.d.ts +26 -0
  49. package/lib/typescript/src/upgrade.d.ts.map +1 -0
  50. package/package.json +255 -4
  51. package/plugin/build/index.d.ts +13 -0
  52. package/plugin/build/index.js +57 -0
  53. package/plugin/src/index.ts +105 -0
  54. package/src/NativeAndroidHealthConnect.ts +133 -0
  55. package/src/foreground.ts +167 -0
  56. package/src/helpers.ts +373 -0
  57. package/src/index.tsx +623 -0
  58. package/src/types.ts +1525 -0
  59. package/src/upgrade.ts +155 -0
package/src/upgrade.ts ADDED
@@ -0,0 +1,155 @@
1
+ import { version as packageVersion } from '../package.json';
2
+
3
+ export const LIBRARY_VERSION: string = packageVersion;
4
+
5
+ export type LibraryUpdateInfo = {
6
+ currentVersion: string;
7
+ latestVersion: string | null;
8
+ updateAvailable: boolean;
9
+ releaseUrl: string | null;
10
+ releaseName: string | null;
11
+ /** Human-readable upgrade reminder (升级提醒) for UI / logs. */
12
+ advice: string;
13
+ };
14
+
15
+ export type CheckLibraryUpdateOptions = {
16
+ /** GitHub owner/repo. Defaults to solutionforest/AndroidHealthConnect. */
17
+ repository?: string;
18
+ /** Override current version (defaults to package.json version). */
19
+ currentVersion?: string;
20
+ /** Injected fetch for tests. */
21
+ fetchImpl?: typeof fetch;
22
+ };
23
+
24
+ const DEFAULT_REPOSITORY = 'solutionforest/AndroidHealthConnect';
25
+
26
+ function normalizeVersion(version: string): string {
27
+ return version.trim().replace(/^v/i, '');
28
+ }
29
+
30
+ /** Compare core semver (ignores pre-release suffix). Returns -1 / 0 / 1. */
31
+ export function compareSemver(a: string, b: string): number {
32
+ const parse = (v: string): number[] =>
33
+ normalizeVersion(v)
34
+ .split('-')[0]!
35
+ .split('.')
36
+ .map((part) => {
37
+ const n = Number.parseInt(part, 10);
38
+ return Number.isFinite(n) ? n : 0;
39
+ });
40
+
41
+ const left = parse(a);
42
+ const right = parse(b);
43
+ const len = Math.max(left.length, right.length);
44
+
45
+ for (let i = 0; i < len; i++) {
46
+ const av = left[i] ?? 0;
47
+ const bv = right[i] ?? 0;
48
+ if (av > bv) {
49
+ return 1;
50
+ }
51
+ if (av < bv) {
52
+ return -1;
53
+ }
54
+ }
55
+ return 0;
56
+ }
57
+
58
+ type GithubRelease = {
59
+ tag_name?: string;
60
+ name?: string | null;
61
+ html_url?: string;
62
+ draft?: boolean;
63
+ prerelease?: boolean;
64
+ };
65
+
66
+ /**
67
+ * Checks GitHub Releases for a newer library version and returns upgrade advice.
68
+ * Does not auto-upgrade — apps should show the reminder to users / maintainers.
69
+ */
70
+ export async function checkLibraryUpdate(
71
+ options: CheckLibraryUpdateOptions = {}
72
+ ): Promise<LibraryUpdateInfo> {
73
+ const repository = options.repository ?? DEFAULT_REPOSITORY;
74
+ const currentVersion = normalizeVersion(
75
+ options.currentVersion ?? LIBRARY_VERSION
76
+ );
77
+ // Use `in` so callers can inject a non-function (null) for the no-fetch path.
78
+ // `??` would replace null with globalThis.fetch and hide that branch.
79
+ const fetchImpl =
80
+ 'fetchImpl' in options ? options.fetchImpl : globalThis.fetch;
81
+
82
+ if (typeof fetchImpl !== 'function') {
83
+ return {
84
+ currentVersion,
85
+ latestVersion: null,
86
+ updateAvailable: false,
87
+ releaseUrl: null,
88
+ releaseName: null,
89
+ advice: `Unable to check for updates (no fetch). Current version is ${currentVersion}.`,
90
+ };
91
+ }
92
+
93
+ const response = await fetchImpl(
94
+ `https://api.github.com/repos/${repository}/releases/latest`,
95
+ {
96
+ headers: {
97
+ 'Accept': 'application/vnd.github+json',
98
+ 'User-Agent': `android-health-connect/${currentVersion}`,
99
+ },
100
+ }
101
+ );
102
+
103
+ if (!response.ok) {
104
+ return {
105
+ currentVersion,
106
+ latestVersion: null,
107
+ updateAvailable: false,
108
+ releaseUrl: null,
109
+ releaseName: null,
110
+ advice: `Unable to check for updates (GitHub HTTP ${response.status}). Current version is ${currentVersion}.`,
111
+ };
112
+ }
113
+
114
+ const release = (await response.json()) as GithubRelease;
115
+ const latestVersion = release.tag_name
116
+ ? normalizeVersion(release.tag_name)
117
+ : null;
118
+ const releaseUrl = release.html_url ?? null;
119
+ const releaseName = release.name ?? null;
120
+
121
+ if (!latestVersion) {
122
+ return {
123
+ currentVersion,
124
+ latestVersion: null,
125
+ updateAvailable: false,
126
+ releaseUrl,
127
+ releaseName,
128
+ advice: `No GitHub release found. Current version is ${currentVersion}.`,
129
+ };
130
+ }
131
+
132
+ const updateAvailable = compareSemver(currentVersion, latestVersion) < 0;
133
+
134
+ if (updateAvailable) {
135
+ return {
136
+ currentVersion,
137
+ latestVersion,
138
+ updateAvailable: true,
139
+ releaseUrl,
140
+ releaseName,
141
+ advice: `Upgrade recommended / 建议升级: ${currentVersion} → ${latestVersion}. See ${
142
+ releaseUrl ?? `https://github.com/${repository}/releases`
143
+ }`,
144
+ };
145
+ }
146
+
147
+ return {
148
+ currentVersion,
149
+ latestVersion,
150
+ updateAvailable: false,
151
+ releaseUrl,
152
+ releaseName,
153
+ advice: `You are on the latest version (${currentVersion}).`,
154
+ };
155
+ }