@adminide-stack/yantra-mobile 12.0.98 → 12.0.99-alpha.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.
- package/lib/bridge/handlers/SurfaceHostBridgeHandler.js +9 -2
- package/lib/bridge/handlers/SurfaceHostBridgeHandler.js.map +1 -1
- package/lib/compute.js +109 -1
- package/lib/compute.js.map +1 -1
- package/lib/config/env-config.js +11 -1
- package/lib/config/env-config.js.map +1 -1
- package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
- package/lib/features/apps/AppsCatalog.js +10 -0
- package/lib/features/apps/AppsCatalog.js.map +1 -1
- package/lib/features/apps/appArt.js +2 -1
- package/lib/features/apps/appArt.js.map +1 -1
- package/lib/features/apps/mobileAppCatalog.js +10 -0
- package/lib/features/apps/mobileAppCatalog.js.map +1 -1
- package/lib/features/apps/nativeAppHandoff.js +2 -1
- package/lib/features/apps/nativeAppHandoff.js.map +1 -1
- package/lib/features/apps/resolveSurfaceUrl.js +1 -2
- package/lib/features/apps/resolveSurfaceUrl.js.map +1 -1
- package/lib/features/attachments/useImageAttachments.js +8 -5
- package/lib/features/attachments/useImageAttachments.js.map +1 -1
- package/lib/features/chat/AssistantMarkdown.js +7 -6
- package/lib/features/chat/AssistantMarkdown.js.map +1 -1
- package/lib/features/chat/ChatTranscript.js +12 -2
- package/lib/features/chat/ChatTranscript.js.map +1 -1
- package/lib/features/devices/bleTransport.js +141 -0
- package/lib/features/devices/bleTransport.js.map +1 -0
- package/lib/features/devices/catalog.js +59 -0
- package/lib/features/devices/catalog.js.map +1 -0
- package/lib/features/devices/deviceStore.js +292 -0
- package/lib/features/devices/deviceStore.js.map +1 -0
- package/lib/features/devices/devices.js +68 -0
- package/lib/features/devices/devices.js.map +1 -0
- package/lib/features/devices/drivers.js +378 -0
- package/lib/features/devices/drivers.js.map +1 -0
- package/lib/features/devices/gatt/bytes.js +103 -0
- package/lib/features/devices/gatt/bytes.js.map +1 -0
- package/lib/features/devices/gatt/dateTime.js +23 -0
- package/lib/features/devices/gatt/dateTime.js.map +1 -0
- package/lib/features/devices/gatt/measurements.js +210 -0
- package/lib/features/devices/gatt/measurements.js.map +1 -0
- package/lib/features/devices/gatt/userData.js +57 -0
- package/lib/features/devices/gatt/userData.js.map +1 -0
- package/lib/features/devices/gatt/uuids.js +41 -0
- package/lib/features/devices/gatt/uuids.js.map +1 -0
- package/lib/features/devices/link.js +8 -0
- package/lib/features/devices/link.js.map +1 -0
- package/lib/features/devices/readings.js +158 -0
- package/lib/features/devices/readings.js.map +1 -0
- package/lib/features/devices/session.js +334 -0
- package/lib/features/devices/session.js.map +1 -0
- package/lib/features/expenses/ExpensesAgentChatPane.js +50 -0
- package/lib/features/expenses/ExpensesAgentChatPane.js.map +1 -0
- package/lib/features/expenses/ExpensesExperience.js +646 -0
- package/lib/features/expenses/ExpensesExperience.js.map +1 -0
- package/lib/features/expenses/claimFilters.js +94 -0
- package/lib/features/expenses/claimFilters.js.map +1 -0
- package/lib/features/expenses/components/AccountsPanel.js +464 -0
- package/lib/features/expenses/components/AccountsPanel.js.map +1 -0
- package/lib/features/expenses/components/BudgetsPanel.js +320 -0
- package/lib/features/expenses/components/BudgetsPanel.js.map +1 -0
- package/lib/features/expenses/components/CategoriesSheet.js +181 -0
- package/lib/features/expenses/components/CategoriesSheet.js.map +1 -0
- package/lib/features/expenses/components/ClaimDetail.js +309 -0
- package/lib/features/expenses/components/ClaimDetail.js.map +1 -0
- package/lib/features/expenses/components/ClaimForm.js +375 -0
- package/lib/features/expenses/components/ClaimForm.js.map +1 -0
- package/lib/features/expenses/components/ClaimRow.js +77 -0
- package/lib/features/expenses/components/ClaimRow.js.map +1 -0
- package/lib/features/expenses/components/ClaimsPanel.js +388 -0
- package/lib/features/expenses/components/ClaimsPanel.js.map +1 -0
- package/lib/features/expenses/components/DateSheet.js +214 -0
- package/lib/features/expenses/components/DateSheet.js.map +1 -0
- package/lib/features/expenses/components/ExpensesStates.js +274 -0
- package/lib/features/expenses/components/ExpensesStates.js.map +1 -0
- package/lib/features/expenses/components/ExpensesTabBar.js +83 -0
- package/lib/features/expenses/components/ExpensesTabBar.js.map +1 -0
- package/lib/features/expenses/components/FiltersSheet.js +137 -0
- package/lib/features/expenses/components/FiltersSheet.js.map +1 -0
- package/lib/features/expenses/components/InsightsPanel.js +362 -0
- package/lib/features/expenses/components/InsightsPanel.js.map +1 -0
- package/lib/features/expenses/components/RecurringPanel.js +370 -0
- package/lib/features/expenses/components/RecurringPanel.js.map +1 -0
- package/lib/features/expenses/components/Sheets.js +220 -0
- package/lib/features/expenses/components/Sheets.js.map +1 -0
- package/lib/features/expenses/components/ui.js +496 -0
- package/lib/features/expenses/components/ui.js.map +1 -0
- package/lib/features/expenses/expensesClient.js +398 -0
- package/lib/features/expenses/expensesClient.js.map +1 -0
- package/lib/features/expenses/expensesContext.js +30 -0
- package/lib/features/expenses/expensesContext.js.map +1 -0
- package/lib/features/expenses/expensesEndpoint.js +12 -0
- package/lib/features/expenses/expensesEndpoint.js.map +1 -0
- package/lib/features/expenses/expensesFormat.js +360 -0
- package/lib/features/expenses/expensesFormat.js.map +1 -0
- package/lib/features/expenses/expensesOperations.js +136 -0
- package/lib/features/expenses/expensesOperations.js.map +1 -0
- package/lib/features/expenses/expensesPrompts.js +81 -0
- package/lib/features/expenses/expensesPrompts.js.map +1 -0
- package/lib/features/expenses/expensesTheme.js +107 -0
- package/lib/features/expenses/expensesTheme.js.map +1 -0
- package/lib/features/expenses/nativeExpensesRegistry.js +15 -0
- package/lib/features/expenses/nativeExpensesRegistry.js.map +1 -0
- package/lib/features/expenses/receiptScan.js +242 -0
- package/lib/features/expenses/receiptScan.js.map +1 -0
- package/lib/features/expenses/useClaimsList.js +159 -0
- package/lib/features/expenses/useClaimsList.js.map +1 -0
- package/lib/features/expenses/useExpensesResource.js +68 -0
- package/lib/features/expenses/useExpensesResource.js.map +1 -0
- package/lib/features/health/HealthSyncRunner.js +24 -10
- package/lib/features/health/HealthSyncRunner.js.map +1 -1
- package/lib/features/health/buildDays.js +52 -5
- package/lib/features/health/buildDays.js.map +1 -1
- package/lib/features/health/fitnessClient.js +30 -3
- package/lib/features/health/fitnessClient.js.map +1 -1
- package/lib/features/health/healthConnectMapping.js +65 -2
- package/lib/features/health/healthConnectMapping.js.map +1 -1
- package/lib/features/health/healthConnectReader.js +23 -5
- package/lib/features/health/healthConnectReader.js.map +1 -1
- package/lib/features/health/healthConnectWriter.js +49 -0
- package/lib/features/health/healthConnectWriter.js.map +1 -0
- package/lib/features/health/healthkitMapping.js +58 -2
- package/lib/features/health/healthkitMapping.js.map +1 -1
- package/lib/features/health/healthkitReader.js +29 -7
- package/lib/features/health/healthkitReader.js.map +1 -1
- package/lib/features/health/healthkitWriter.js +55 -0
- package/lib/features/health/healthkitWriter.js.map +1 -0
- package/lib/features/health/model.js +8 -1
- package/lib/features/health/model.js.map +1 -1
- package/lib/features/health/ownSource.js +6 -0
- package/lib/features/health/ownSource.js.map +1 -0
- package/lib/features/health/reader.js +21 -0
- package/lib/features/health/reader.js.map +1 -1
- package/lib/features/health/types.js +15 -3
- package/lib/features/health/types.js.map +1 -1
- package/lib/features/health/writeMapping.js +218 -0
- package/lib/features/health/writeMapping.js.map +1 -0
- package/lib/features/links/ChatLinkOpenerProvider.js +56 -0
- package/lib/features/links/ChatLinkOpenerProvider.js.map +1 -0
- package/lib/features/links/chatLinkOpener.js +8 -0
- package/lib/features/links/chatLinkOpener.js.map +1 -0
- package/lib/features/links/openInApp.js +25 -0
- package/lib/features/links/openInApp.js.map +1 -0
- package/lib/features/messaging/ChatComponents.js +25 -6
- package/lib/features/messaging/ChatComponents.js.map +1 -1
- package/lib/features/messaging/LinkPreviewCard.js +103 -0
- package/lib/features/messaging/LinkPreviewCard.js.map +1 -0
- package/lib/features/messaging/NativeChatExperience.js +20 -7
- package/lib/features/messaging/NativeChatExperience.js.map +1 -1
- package/lib/features/messaging/ThreadScreen.js +4 -2
- package/lib/features/messaging/ThreadScreen.js.map +1 -1
- package/lib/features/messaging/chatLinks.js +64 -0
- package/lib/features/messaging/chatLinks.js.map +1 -0
- package/lib/features/messaging/linkPreview.js +64 -0
- package/lib/features/messaging/linkPreview.js.map +1 -0
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/routes.json +54 -0
- package/lib/screens/Account/index.js +39 -14
- package/lib/screens/Account/index.js.map +1 -1
- package/lib/screens/Chat/index.js +4 -3
- package/lib/screens/Chat/index.js.map +1 -1
- package/lib/screens/Devices/index.js +1055 -0
- package/lib/screens/Devices/index.js.map +1 -0
- package/lib/screens/ExpensesNative/index.js +98 -0
- package/lib/screens/ExpensesNative/index.js.map +1 -0
- package/lib/screens/ExpensesNative/useExpensesHostChat.js +63 -0
- package/lib/screens/ExpensesNative/useExpensesHostChat.js.map +1 -0
- package/lib/screens/Health/index.js +40 -7
- package/lib/screens/Health/index.js.map +1 -1
- package/lib/screens/WebBuilder/index.js +20 -0
- package/lib/screens/WebBuilder/index.js.map +1 -1
- package/lib/utils/hasNativeModule.js +9 -0
- package/lib/utils/hasNativeModule.js.map +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {authorizationStatusFor,AuthorizationStatus,requestAuthorization,saveQuantitySample,saveCorrelationSample}from'@kingstinct/react-native-healthkit';import {healthKitWritesFor,HK_WRITE_TYPES}from'./writeMapping.js';const SYSTOLIC = "HKQuantityTypeIdentifierBloodPressureSystolic";
|
|
2
|
+
const DIASTOLIC = "HKQuantityTypeIdentifierBloodPressureDiastolic";
|
|
3
|
+
const typesOf = (w) => w.kind === "quantity" ? [w.type] : [SYSTOLIC, DIASTOLIC];
|
|
4
|
+
async function write(w) {
|
|
5
|
+
if (w.kind === "quantity") {
|
|
6
|
+
await saveQuantitySample(w.type, w.unit, w.value, w.at, w.at, w.metadata);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
await saveCorrelationSample("HKCorrelationTypeIdentifierBloodPressure", [{
|
|
10
|
+
quantityType: SYSTOLIC,
|
|
11
|
+
quantity: w.systolic,
|
|
12
|
+
unit: "mmHg",
|
|
13
|
+
startDate: w.at,
|
|
14
|
+
endDate: w.at
|
|
15
|
+
}, {
|
|
16
|
+
quantityType: DIASTOLIC,
|
|
17
|
+
quantity: w.diastolic,
|
|
18
|
+
unit: "mmHg",
|
|
19
|
+
startDate: w.at,
|
|
20
|
+
endDate: w.at
|
|
21
|
+
}], w.at, w.at, w.metadata);
|
|
22
|
+
}
|
|
23
|
+
function createHealthKitWriter() {
|
|
24
|
+
return {
|
|
25
|
+
storeName: "Apple Health",
|
|
26
|
+
async requestAccess() {
|
|
27
|
+
await requestAuthorization({
|
|
28
|
+
toShare: HK_WRITE_TYPES
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
async asked() {
|
|
32
|
+
return HK_WRITE_TYPES.some((t) => authorizationStatusFor(t) !== AuthorizationStatus.notDetermined);
|
|
33
|
+
},
|
|
34
|
+
async save(reading) {
|
|
35
|
+
const writes = healthKitWritesFor(reading);
|
|
36
|
+
if (!writes.length) return "nothing";
|
|
37
|
+
let saved = 0;
|
|
38
|
+
let denied = 0;
|
|
39
|
+
for (const w of writes) {
|
|
40
|
+
if (typesOf(w).some((t) => authorizationStatusFor(t) !== AuthorizationStatus.sharingAuthorized)) {
|
|
41
|
+
denied++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
await write(w);
|
|
46
|
+
saved++;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
return saved ? "saved" : "failed";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (saved) return "saved";
|
|
52
|
+
return denied ? "not-allowed" : "failed";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}export{createHealthKitWriter};//# sourceMappingURL=healthkitWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"healthkitWriter.js","sources":["../../../src/features/health/healthkitWriter.ts"],"sourcesContent":["/**\n * Apple Health writer, iOS only: saves the readings Yantra took from a paired\n * Bluetooth device (see writeMapping.ts for what each becomes). HealthKit says\n * per type whether saving is allowed, so a type the person turned off is\n * skipped, never retried into an error.\n */\nimport {\n AuthorizationStatus,\n authorizationStatusFor,\n requestAuthorization,\n saveCorrelationSample,\n saveQuantitySample,\n} from '@kingstinct/react-native-healthkit';\nimport { HK_WRITE_TYPES, healthKitWritesFor, type HKWrite, type HKWriteType } from './writeMapping';\nimport type { HealthWriter, SaveOutcome } from './writer';\n\nconst SYSTOLIC: HKWriteType = 'HKQuantityTypeIdentifierBloodPressureSystolic';\nconst DIASTOLIC: HKWriteType = 'HKQuantityTypeIdentifierBloodPressureDiastolic';\n\nconst typesOf = (w: HKWrite): HKWriteType[] => (w.kind === 'quantity' ? [w.type] : [SYSTOLIC, DIASTOLIC]);\n\nasync function write(w: HKWrite): Promise<void> {\n if (w.kind === 'quantity') {\n await saveQuantitySample(w.type, w.unit as never, w.value, w.at, w.at, w.metadata as never);\n return;\n }\n await saveCorrelationSample(\n 'HKCorrelationTypeIdentifierBloodPressure',\n [\n { quantityType: SYSTOLIC, quantity: w.systolic, unit: 'mmHg', startDate: w.at, endDate: w.at },\n { quantityType: DIASTOLIC, quantity: w.diastolic, unit: 'mmHg', startDate: w.at, endDate: w.at },\n ],\n w.at,\n w.at,\n w.metadata as never,\n );\n}\n\nexport function createHealthKitWriter(): HealthWriter {\n return {\n storeName: 'Apple Health',\n\n async requestAccess() {\n await requestAuthorization({ toShare: HK_WRITE_TYPES });\n },\n\n async asked() {\n return HK_WRITE_TYPES.some((t) => authorizationStatusFor(t) !== AuthorizationStatus.notDetermined);\n },\n\n async save(reading): Promise<SaveOutcome> {\n const writes = healthKitWritesFor(reading);\n if (!writes.length) return 'nothing';\n let saved = 0;\n let denied = 0;\n for (const w of writes) {\n if (typesOf(w).some((t) => authorizationStatusFor(t) !== AuthorizationStatus.sharingAuthorized)) {\n denied++;\n continue;\n }\n try {\n await write(w);\n saved++;\n } catch {\n return saved ? 'saved' : 'failed';\n }\n }\n if (saved) return 'saved';\n return denied ? 'not-allowed' : 'failed';\n },\n };\n}\n"],"names":[],"mappings":"4NASA,MAAM,QAAwB,GAAA,+CAAA;AAC9B,MAAM,SAAyB,GAAA,gDAAA;AAC/B,MAAM,OAAU,GAAA,CAAC,CAA8B,KAAA,CAAA,CAAE,IAAS,KAAA,UAAA,GAAa,CAAC,CAAA,CAAE,IAAI,CAAA,GAAI,CAAC,QAAA,EAAU,SAAS,CAAA;AACtG,eAAe,MAAM,CAA2B,EAAA;AAC9C,EAAI,IAAA,CAAA,CAAE,SAAS,UAAY,EAAA;AACzB,IAAA,MAAM,kBAAmB,CAAA,CAAA,CAAE,IAAM,EAAA,CAAA,CAAE,IAAe,EAAA,CAAA,CAAE,KAAO,EAAA,CAAA,CAAE,EAAI,EAAA,CAAA,CAAE,EAAI,EAAA,CAAA,CAAE,QAAiB,CAAA;AAC1F,IAAA;AAAA;AAEF,EAAM,MAAA,qBAAA,CAAsB,4CAA4C,CAAC;AAAA,IACvE,YAAc,EAAA,QAAA;AAAA,IACd,UAAU,CAAE,CAAA,QAAA;AAAA,IACZ,IAAM,EAAA,MAAA;AAAA,IACN,WAAW,CAAE,CAAA,EAAA;AAAA,IACb,SAAS,CAAE,CAAA;AAAA,GACV,EAAA;AAAA,IACD,YAAc,EAAA,SAAA;AAAA,IACd,UAAU,CAAE,CAAA,SAAA;AAAA,IACZ,IAAM,EAAA,MAAA;AAAA,IACN,WAAW,CAAE,CAAA,EAAA;AAAA,IACb,SAAS,CAAE,CAAA;AAAA,GACZ,CAAG,EAAA,CAAA,CAAE,IAAI,CAAE,CAAA,EAAA,EAAI,EAAE,QAAiB,CAAA;AACrC;AACO,SAAS,qBAAsC,GAAA;AACpD,EAAO,OAAA;AAAA,IACL,SAAW,EAAA,cAAA;AAAA,IACX,MAAM,aAAgB,GAAA;AACpB,MAAA,MAAM,oBAAqB,CAAA;AAAA,QACzB,OAAS,EAAA;AAAA,OACV,CAAA;AAAA,KACH;AAAA,IACA,MAAM,KAAQ,GAAA;AACZ,MAAA,OAAO,eAAe,IAAK,CAAA,CAAA,CAAA,KAAK,uBAAuB,CAAC,CAAA,KAAM,oBAAoB,aAAa,CAAA;AAAA,KACjG;AAAA,IACA,MAAM,KAAK,OAA+B,EAAA;AACxC,MAAM,MAAA,MAAA,GAAS,mBAAmB,OAAO,CAAA;AACzC,MAAI,IAAA,CAAC,MAAO,CAAA,MAAA,EAAe,OAAA,SAAA;AAC3B,MAAA,IAAI,KAAQ,GAAA,CAAA;AACZ,MAAA,IAAI,MAAS,GAAA,CAAA;AACb,MAAA,KAAA,MAAW,KAAK,MAAQ,EAAA;AACtB,QAAI,IAAA,OAAA,CAAQ,CAAC,CAAA,CAAE,IAAK,CAAA,CAAA,CAAA,KAAK,uBAAuB,CAAC,CAAA,KAAM,mBAAoB,CAAA,iBAAiB,CAAG,EAAA;AAC7F,UAAA,MAAA,EAAA;AACA,UAAA;AAAA;AAEF,QAAI,IAAA;AACF,UAAA,MAAM,MAAM,CAAC,CAAA;AACb,UAAA,KAAA,EAAA;AAAA,SACM,CAAA,OAAA,CAAA,EAAA;AACN,UAAA,OAAO,QAAQ,OAAU,GAAA,QAAA;AAAA;AAC3B;AAEF,MAAA,IAAI,OAAc,OAAA,OAAA;AAClB,MAAA,OAAO,SAAS,aAAgB,GAAA,QAAA;AAAA;AAClC,GACF;AACF"}
|
|
@@ -10,6 +10,13 @@ function emptyRawHealthData(hrvMethod) {
|
|
|
10
10
|
weightKg: [],
|
|
11
11
|
vo2Max: [],
|
|
12
12
|
spo2: [],
|
|
13
|
-
respiratoryRate: []
|
|
13
|
+
respiratoryRate: [],
|
|
14
|
+
bodyFatPct: [],
|
|
15
|
+
leanMassKg: [],
|
|
16
|
+
bmi: [],
|
|
17
|
+
waistCm: [],
|
|
18
|
+
bodyTempC: [],
|
|
19
|
+
bloodPressure: [],
|
|
20
|
+
glucose: []
|
|
14
21
|
};
|
|
15
22
|
}export{emptyRawHealthData};//# sourceMappingURL=model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sources":["../../../src/features/health/model.ts"],"sourcesContent":["/**\n * What a platform reader hands the day builder: one neutral shape for HealthKit\n * and Health Connect, so the bucketing (days, nights, zones, ranges) is written\n * and tested once. The `fromHealthKit` / `fromHealthConnect` mappers turn each\n * library's records into this; the readers only fetch.\n *\n * Instants are epoch milliseconds.\n */\n\n/** Totals the platform already de-duplicated across sources (phone + watch), per local day. */\nexport interface DailyTotals {\n date: string;\n steps?: number;\n activeCalories?: number;\n distanceMeters?: number;\n activeMinutes?: number;\n}\n\nexport interface TimedValue {\n t: number;\n value: number;\n}\n\nexport type SleepStage = 'inBed' | 'asleep' | 'light' | 'deep' | 'rem' | 'awake' | 'outOfBed';\n\nexport interface SleepSegment {\n start: number;\n end: number;\n stage: SleepStage;\n /**\n * Which writer recorded it (HealthKit bundle id, Health Connect data\n * origin). A night is taken from ONE writer so a watch and a phone\n * tracking the same night are never added together.\n */\n sourceKey: string;\n}\n\nexport interface RawWorkout {\n id: string;\n start: number;\n end: number;\n /** Already normalized (see workoutTypes.ts). */\n type: string;\n /** Active time without pauses, when the source knows it. */\n durationMin?: number;\n calories?: number;\n distanceMeters?: number;\n /** From the source's own workout statistics; else derived from heart-rate samples. */\n avgHr?: number;\n maxHr?: number;\n}\n\nexport interface RawHealthData {\n dailyTotals: DailyTotals[];\n heartRate: TimedValue[];\n restingHr: TimedValue[];\n hrv: TimedValue[];\n hrvMethod: 'rmssd' | 'sdnn';\n sleep: SleepSegment[];\n workouts: RawWorkout[];\n weightKg: TimedValue[];\n vo2Max: TimedValue[];\n /** Percent, 0-100. */\n spo2: TimedValue[];\n respiratoryRate: TimedValue[];\n}\n\nexport function emptyRawHealthData(hrvMethod: 'rmssd' | 'sdnn'): RawHealthData {\n return {\n dailyTotals: [],\n heartRate: [],\n restingHr: [],\n hrv: [],\n hrvMethod,\n sleep: [],\n workouts: [],\n weightKg: [],\n vo2Max: [],\n spo2: [],\n respiratoryRate: [],\n };\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model.js","sources":["../../../src/features/health/model.ts"],"sourcesContent":["/**\n * What a platform reader hands the day builder: one neutral shape for HealthKit\n * and Health Connect, so the bucketing (days, nights, zones, ranges) is written\n * and tested once. The `fromHealthKit` / `fromHealthConnect` mappers turn each\n * library's records into this; the readers only fetch.\n *\n * Instants are epoch milliseconds.\n */\n\nimport type { MealRelation } from './types';\n\n/** Totals the platform already de-duplicated across sources (phone + watch), per local day. */\nexport interface DailyTotals {\n date: string;\n steps?: number;\n activeCalories?: number;\n distanceMeters?: number;\n activeMinutes?: number;\n}\n\nexport interface TimedValue {\n t: number;\n value: number;\n}\n\nexport type SleepStage = 'inBed' | 'asleep' | 'light' | 'deep' | 'rem' | 'awake' | 'outOfBed';\n\nexport interface SleepSegment {\n start: number;\n end: number;\n stage: SleepStage;\n /**\n * Which writer recorded it (HealthKit bundle id, Health Connect data\n * origin). A night is taken from ONE writer so a watch and a phone\n * tracking the same night are never added together.\n */\n sourceKey: string;\n}\n\nexport interface RawWorkout {\n id: string;\n start: number;\n end: number;\n /** Already normalized (see workoutTypes.ts). */\n type: string;\n /** Active time without pauses, when the source knows it. */\n durationMin?: number;\n calories?: number;\n distanceMeters?: number;\n /** From the source's own workout statistics; else derived from heart-rate samples. */\n avgHr?: number;\n maxHr?: number;\n}\n\n/** A blood-pressure reading another app wrote (Omron, Withings ...), with the store's id. */\nexport interface RawBloodPressure {\n id: string;\n t: number;\n systolic: number;\n diastolic: number;\n}\n\nexport interface RawGlucose {\n id: string;\n t: number;\n mgdl: number;\n meal?: MealRelation;\n}\n\nexport interface RawHealthData {\n dailyTotals: DailyTotals[];\n heartRate: TimedValue[];\n restingHr: TimedValue[];\n hrv: TimedValue[];\n hrvMethod: 'rmssd' | 'sdnn';\n sleep: SleepSegment[];\n workouts: RawWorkout[];\n weightKg: TimedValue[];\n vo2Max: TimedValue[];\n /** Percent, 0-100. */\n spo2: TimedValue[];\n respiratoryRate: TimedValue[];\n /** Body measurements another app (a brand scale's own app) wrote. Percent 0-100 for body fat. */\n bodyFatPct: TimedValue[];\n leanMassKg: TimedValue[];\n bmi: TimedValue[];\n waistCm: TimedValue[];\n bodyTempC: TimedValue[];\n bloodPressure: RawBloodPressure[];\n glucose: RawGlucose[];\n}\n\nexport function emptyRawHealthData(hrvMethod: 'rmssd' | 'sdnn'): RawHealthData {\n return {\n dailyTotals: [],\n heartRate: [],\n restingHr: [],\n hrv: [],\n hrvMethod,\n sleep: [],\n workouts: [],\n weightKg: [],\n vo2Max: [],\n spo2: [],\n respiratoryRate: [],\n bodyFatPct: [],\n leanMassKg: [],\n bmi: [],\n waistCm: [],\n bodyTempC: [],\n bloodPressure: [],\n glucose: [],\n };\n}\n"],"names":[],"mappings":"AAqFO,SAAS,mBAAmB,SAA4C,EAAA;AAC7E,EAAO,OAAA;AAAA,IACL,aAAa,EAAC;AAAA,IACd,WAAW,EAAC;AAAA,IACZ,WAAW,EAAC;AAAA,IACZ,KAAK,EAAC;AAAA,IACN,SAAA;AAAA,IACA,OAAO,EAAC;AAAA,IACR,UAAU,EAAC;AAAA,IACX,UAAU,EAAC;AAAA,IACX,QAAQ,EAAC;AAAA,IACT,MAAM,EAAC;AAAA,IACP,iBAAiB,EAAC;AAAA,IAClB,YAAY,EAAC;AAAA,IACb,YAAY,EAAC;AAAA,IACb,KAAK,EAAC;AAAA,IACN,SAAS,EAAC;AAAA,IACV,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,SAAS;AAAC,GACZ;AACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import Constants from'expo-constants';function ownAppId(platform) {
|
|
2
|
+
var _a, _b;
|
|
3
|
+
const config = Constants.expoConfig;
|
|
4
|
+
const id = platform === "ios" ? (_a = config == null ? void 0 : config.ios) == null ? void 0 : _a.bundleIdentifier : (_b = config == null ? void 0 : config.android) == null ? void 0 : _b.package;
|
|
5
|
+
return id || void 0;
|
|
6
|
+
}export{ownAppId};//# sourceMappingURL=ownSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownSource.js","sources":["../../../src/features/health/ownSource.ts"],"sourcesContent":["/**\n * How HealthKit and Health Connect name this app as a writer: its bundle id\n * (iOS) or package name (Android). The readers skip samples written under it,\n * because those are readings Yantra took from a paired Bluetooth device and\n * already sent to the Fitness backend as source `device` (writer.ts).\n */\nimport Constants from 'expo-constants';\n\nexport function ownAppId(platform: 'ios' | 'android'): string | undefined {\n const config = Constants.expoConfig;\n const id = platform === 'ios' ? config?.ios?.bundleIdentifier : config?.android?.package;\n return id || undefined;\n}\n"],"names":[],"mappings":"sCAOO,SAAS,SAAS,QAAiD,EAAA;AAP1E,EAAA,IAAA,EAAA,EAAA,EAAA;AAQE,EAAA,MAAM,SAAS,SAAU,CAAA,UAAA;AACzB,EAAM,MAAA,EAAA,GAAK,aAAa,KAAQ,GAAA,CAAA,EAAA,GAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,QAAR,IAAa,GAAA,MAAA,GAAA,EAAA,CAAA,gBAAA,GAAA,CAAmB,EAAQ,GAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAA,OAAA,KAAR,IAAiB,GAAA,MAAA,GAAA,EAAA,CAAA,OAAA;AACjF,EAAA,OAAO,EAAM,IAAA,MAAA;AACf"}
|
|
@@ -37,6 +37,27 @@ const HEALTH_DATA_TYPES = [{
|
|
|
37
37
|
}, {
|
|
38
38
|
id: "respiratoryRate",
|
|
39
39
|
label: "Respiratory rate"
|
|
40
|
+
}, {
|
|
41
|
+
id: "bodyFat",
|
|
42
|
+
label: "Body fat"
|
|
43
|
+
}, {
|
|
44
|
+
id: "leanMass",
|
|
45
|
+
label: "Lean body mass"
|
|
46
|
+
}, {
|
|
47
|
+
id: "bmi",
|
|
48
|
+
label: "BMI"
|
|
49
|
+
}, {
|
|
50
|
+
id: "waist",
|
|
51
|
+
label: "Waist"
|
|
52
|
+
}, {
|
|
53
|
+
id: "bodyTemp",
|
|
54
|
+
label: "Body temperature"
|
|
55
|
+
}, {
|
|
56
|
+
id: "bloodPressure",
|
|
57
|
+
label: "Blood pressure"
|
|
58
|
+
}, {
|
|
59
|
+
id: "bloodGlucose",
|
|
60
|
+
label: "Blood glucose"
|
|
40
61
|
}];
|
|
41
62
|
function labelOf(type) {
|
|
42
63
|
var _a, _b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reader.js","sources":["../../../src/features/health/reader.ts"],"sourcesContent":["/**\n * What the sync engine needs from a platform. healthkitReader.ts (iOS) and\n * healthConnectReader.ts (Android) implement it; tests use fakes.\n */\nimport type { RawHealthData } from './model';\nimport type { ZoneClock } from './time';\nimport type { DeviceHealthSource } from './types';\n\nexport type HealthDataType =\n | 'steps'\n | 'distance'\n | 'activeCalories'\n | 'exercise'\n | 'heartRate'\n | 'restingHr'\n | 'hrv'\n | 'sleep'\n | 'workouts'\n | 'weight'\n | 'vo2Max'\n | 'spo2'\n | 'respiratoryRate';\n\n/** What the screen lists under \"Shared with Yantra\", in this order. */\nexport const HEALTH_DATA_TYPES: ReadonlyArray<{ id: HealthDataType; label: string }> = [\n { id: 'sleep', label: 'Sleep' },\n { id: 'heartRate', label: 'Heart rate' },\n { id: 'restingHr', label: 'Resting heart rate' },\n { id: 'hrv', label: 'Heart rate variability' },\n { id: 'steps', label: 'Steps' },\n { id: 'distance', label: 'Distance' },\n { id: 'activeCalories', label: 'Active energy' },\n { id: 'exercise', label: 'Exercise minutes' },\n { id: 'workouts', label: 'Workouts' },\n { id: 'weight', label: 'Weight' },\n { id: 'vo2Max', label: 'VO2 max' },\n { id: 'spo2', label: 'Blood oxygen' },\n { id: 'respiratoryRate', label: 'Respiratory rate' },\n];\n\nexport function labelOf(type: HealthDataType): string {\n return HEALTH_DATA_TYPES.find((t) => t.id === type)?.label ?? type;\n}\n\nexport type HealthAvailability =\n | { status: 'available' }\n /** Android: the Health Connect app is not installed (Android 13 and older). */\n | { status: 'not-installed' }\n /** Android: Health Connect is installed but needs an update. */\n | { status: 'needs-update' }\n | { status: 'unsupported'; reason: string };\n\nexport interface ReadResult {\n raw: RawHealthData;\n /** Types that could not be read (permission off, provider error). The rest still syncs. */\n unreadable: HealthDataType[];\n}\n\nexport interface HealthReader {\n readonly source: DeviceHealthSource;\n /** What the platform calls its health store, for the screen. */\n readonly storeName: string;\n availability(): Promise<HealthAvailability>;\n /**\n * Shows the system permission sheet. Resolves with the types granted, or\n * null when the platform does not tell apps (HealthKit hides read access).\n */\n requestAccess(): Promise<HealthDataType[] | null>;\n /** Granted read types, or null when the platform does not tell apps. */\n grantedTypes(): Promise<HealthDataType[] | null>;\n /** Everything recorded between two instants. */\n read(range: { start: number; end: number }, clock: ZoneClock): Promise<ReadResult>;\n /** Give the permissions back where the platform allows it (Health Connect); a no-op on iOS. */\n revoke(): Promise<void>;\n /** The platform's own screen for this app's permissions, when it has one. */\n openSettings?(): Promise<void>;\n}\n"],"names":[],"mappings":"AAUO,MAAM,oBAGR,CAAC;AAAA,EACJ,EAAI,EAAA,OAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,WAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,WAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,KAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,OAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,UAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,gBAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,UAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,UAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,QAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,QAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,MAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,iBAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAC;AACM,SAAS,QAAQ,IAA8B,EAAA;
|
|
1
|
+
{"version":3,"file":"reader.js","sources":["../../../src/features/health/reader.ts"],"sourcesContent":["/**\n * What the sync engine needs from a platform. healthkitReader.ts (iOS) and\n * healthConnectReader.ts (Android) implement it; tests use fakes.\n */\nimport type { RawHealthData } from './model';\nimport type { ZoneClock } from './time';\nimport type { DeviceHealthSource } from './types';\n\nexport type HealthDataType =\n | 'steps'\n | 'distance'\n | 'activeCalories'\n | 'exercise'\n | 'heartRate'\n | 'restingHr'\n | 'hrv'\n | 'sleep'\n | 'workouts'\n | 'weight'\n | 'vo2Max'\n | 'spo2'\n | 'respiratoryRate'\n | 'bodyFat'\n | 'leanMass'\n | 'bmi'\n | 'waist'\n | 'bodyTemp'\n | 'bloodPressure'\n | 'bloodGlucose';\n\n/** What the screen lists under \"Shared with Yantra\", in this order. */\nexport const HEALTH_DATA_TYPES: ReadonlyArray<{ id: HealthDataType; label: string }> = [\n { id: 'sleep', label: 'Sleep' },\n { id: 'heartRate', label: 'Heart rate' },\n { id: 'restingHr', label: 'Resting heart rate' },\n { id: 'hrv', label: 'Heart rate variability' },\n { id: 'steps', label: 'Steps' },\n { id: 'distance', label: 'Distance' },\n { id: 'activeCalories', label: 'Active energy' },\n { id: 'exercise', label: 'Exercise minutes' },\n { id: 'workouts', label: 'Workouts' },\n { id: 'weight', label: 'Weight' },\n { id: 'vo2Max', label: 'VO2 max' },\n { id: 'spo2', label: 'Blood oxygen' },\n { id: 'respiratoryRate', label: 'Respiratory rate' },\n { id: 'bodyFat', label: 'Body fat' },\n { id: 'leanMass', label: 'Lean body mass' },\n { id: 'bmi', label: 'BMI' },\n { id: 'waist', label: 'Waist' },\n { id: 'bodyTemp', label: 'Body temperature' },\n { id: 'bloodPressure', label: 'Blood pressure' },\n { id: 'bloodGlucose', label: 'Blood glucose' },\n];\n\nexport function labelOf(type: HealthDataType): string {\n return HEALTH_DATA_TYPES.find((t) => t.id === type)?.label ?? type;\n}\n\nexport type HealthAvailability =\n | { status: 'available' }\n /** Android: the Health Connect app is not installed (Android 13 and older). */\n | { status: 'not-installed' }\n /** Android: Health Connect is installed but needs an update. */\n | { status: 'needs-update' }\n | { status: 'unsupported'; reason: string };\n\nexport interface ReadResult {\n raw: RawHealthData;\n /** Types that could not be read (permission off, provider error). The rest still syncs. */\n unreadable: HealthDataType[];\n}\n\nexport interface HealthReader {\n readonly source: DeviceHealthSource;\n /** What the platform calls its health store, for the screen. */\n readonly storeName: string;\n availability(): Promise<HealthAvailability>;\n /**\n * Shows the system permission sheet. Resolves with the types granted, or\n * null when the platform does not tell apps (HealthKit hides read access).\n */\n requestAccess(): Promise<HealthDataType[] | null>;\n /** Granted read types, or null when the platform does not tell apps. */\n grantedTypes(): Promise<HealthDataType[] | null>;\n /** Everything recorded between two instants. */\n read(range: { start: number; end: number }, clock: ZoneClock): Promise<ReadResult>;\n /** Give the permissions back where the platform allows it (Health Connect); a no-op on iOS. */\n revoke(): Promise<void>;\n /** The platform's own screen for this app's permissions, when it has one. */\n openSettings?(): Promise<void>;\n}\n"],"names":[],"mappings":"AAUO,MAAM,oBAGR,CAAC;AAAA,EACJ,EAAI,EAAA,OAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA;AAAA,EACD,EAAI,EAAA,WAAA;AAAA,EACJ,KAAO,EAAA;AACT,CAAG,EAAA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AAO,EAAA;AACT,CAAC;AACM,SAAS,QAAQ,IAA8B,EAAA;AA1EtD,EAAA,IAAA,EAAA,EAAA,EAAA;AA2EE,EAAO,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,iBAAA,CAAkB,KAAK,CAAK,CAAA,KAAA,CAAA,CAAE,OAAO,IAAI,CAAA,KAAzC,IAA4C,GAAA,MAAA,GAAA,EAAA,CAAA,KAAA,KAA5C,IAAqD,GAAA,EAAA,GAAA,IAAA;AAC9D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const HEALTH_NUMERIC_FIELDS = ["sleepMinutes", "inBedMinutes", "deepMinutes", "remMinutes", "lightMinutes", "awakeMinutes", "restingHr", "hrvMs", "avgHr", "maxHr", "steps", "activeCalories", "activeMinutes", "distanceMeters", "vo2Max", "weightKg", "spo2", "respiratoryRate"];
|
|
1
|
+
const HEALTH_NUMERIC_FIELDS = ["sleepMinutes", "inBedMinutes", "deepMinutes", "remMinutes", "lightMinutes", "awakeMinutes", "restingHr", "hrvMs", "avgHr", "maxHr", "steps", "activeCalories", "activeMinutes", "distanceMeters", "vo2Max", "weightKg", "spo2", "respiratoryRate", "bodyFatPct", "leanMassKg", "bmi", "waistCm", "bodyTempC"];
|
|
2
2
|
const HEALTH_RANGES = {
|
|
3
3
|
sleepMinutes: [0, 1080],
|
|
4
4
|
inBedMinutes: [0, 1200],
|
|
@@ -17,8 +17,20 @@ const HEALTH_RANGES = {
|
|
|
17
17
|
vo2Max: [10, 95],
|
|
18
18
|
weightKg: [25, 350],
|
|
19
19
|
spo2: [70, 100],
|
|
20
|
-
respiratoryRate: [4, 40]
|
|
20
|
+
respiratoryRate: [4, 40],
|
|
21
|
+
bodyFatPct: [2, 75],
|
|
22
|
+
leanMassKg: [10, 200],
|
|
23
|
+
bmi: [10, 90],
|
|
24
|
+
waistCm: [40, 250],
|
|
25
|
+
bodyTempC: [33, 43]
|
|
21
26
|
};
|
|
27
|
+
const READING_RANGES = {
|
|
28
|
+
systolic: [60, 260],
|
|
29
|
+
diastolic: [30, 160],
|
|
30
|
+
pulse: [25, 220],
|
|
31
|
+
glucoseMgDl: [20, 600]
|
|
32
|
+
};
|
|
33
|
+
const MAX_READINGS_PER_DAY = 50;
|
|
22
34
|
const WORKOUT_RANGES = {
|
|
23
35
|
durationMin: [0, 1440],
|
|
24
36
|
calories: [0, 1e4],
|
|
@@ -27,4 +39,4 @@ const WORKOUT_RANGES = {
|
|
|
27
39
|
maxHr: [25, 240]
|
|
28
40
|
};
|
|
29
41
|
const MAX_INGEST_DAYS = 120;
|
|
30
|
-
const MAX_WORKOUTS_PER_DAY = 40;export{HEALTH_NUMERIC_FIELDS,HEALTH_RANGES,MAX_INGEST_DAYS,MAX_WORKOUTS_PER_DAY,WORKOUT_RANGES};//# sourceMappingURL=types.js.map
|
|
42
|
+
const MAX_WORKOUTS_PER_DAY = 40;export{HEALTH_NUMERIC_FIELDS,HEALTH_RANGES,MAX_INGEST_DAYS,MAX_READINGS_PER_DAY,MAX_WORKOUTS_PER_DAY,READING_RANGES,WORKOUT_RANGES};//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../src/features/health/types.ts"],"sourcesContent":["/**\n * The wire contract the Fitness backend ingests (`ingestFitnessHealth`).\n *\n * PORTED, not imported: the source of truth is yantra-surface\n * `packages/fitness/src/domain/health.ts` (HealthDay, HealthWorkout,\n * HEALTH_RANGES, MAX_INGEST_DAYS). That package builds for the web toolchain,\n * so the app keeps a copy of the types and the ranges and pins the wire shape\n * in tests. Keep the two in step when the contract changes.\n */\n\nexport type HealthSource = 'apple-health' | 'health-connect' | 'google-health' | 'manual';\n\n/** The
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/features/health/types.ts"],"sourcesContent":["/**\n * The wire contract the Fitness backend ingests (`ingestFitnessHealth`).\n *\n * PORTED, not imported: the source of truth is yantra-surface\n * `packages/fitness/src/domain/health.ts` (HealthDay, HealthWorkout,\n * HEALTH_RANGES, MAX_INGEST_DAYS). That package builds for the web toolchain,\n * so the app keeps a copy of the types and the ranges and pins the wire shape\n * in tests. Keep the two in step when the contract changes.\n */\n\n/** `device`: a Bluetooth device paired in this app (features/devices). */\nexport type HealthSource = 'device' | 'apple-health' | 'health-connect' | 'google-health' | 'manual';\n\n/** The phone's own health store this app syncs from (Apple Health or Health Connect). */\nexport type DeviceHealthSource = Extract<HealthSource, 'apple-health' | 'health-connect'>;\n\nexport type HealthReadingKind = 'blood-pressure' | 'glucose';\nexport type MealRelation = 'fasting' | 'before-meal' | 'after-meal' | 'bedtime' | 'other';\n\n/** Something measured several times a day: a blood-pressure or glucose reading. */\nexport interface HealthReading {\n /** Stable id from the source (device record, HealthKit UUID, Health Connect id). */\n id: string;\n /** ISO timestamp of the measurement. */\n at: string;\n kind: HealthReadingKind;\n /** mmHg. */\n systolic?: number;\n diastolic?: number;\n pulse?: number;\n glucoseMgDl?: number;\n meal?: MealRelation;\n /** The device's name as it advertised itself. */\n device?: string;\n}\n\nexport interface HealthWorkout {\n /** Stable id from the source (HealthKit UUID, Health Connect record id). */\n id: string;\n /** ISO timestamps. */\n start: string;\n end: string;\n /** run | walk | cycle | strength | swim | hiit | yoga | other ... free text, lowercased. */\n type: string;\n durationMin?: number;\n calories?: number;\n distanceMeters?: number;\n avgHr?: number;\n maxHr?: number;\n /** Minutes in heart-rate zones 1..5 (50-60, 60-70, 70-80, 80-90, 90-100% of max HR). */\n zoneMinutes?: number[];\n}\n\n/** One calendar day (the person's timezone) from one source. All fields optional. */\nexport interface HealthDay {\n date: string;\n source: HealthSource;\n /** The night that ENDED on `date`. */\n sleepMinutes?: number;\n inBedMinutes?: number;\n deepMinutes?: number;\n remMinutes?: number;\n lightMinutes?: number;\n awakeMinutes?: number;\n /** ISO timestamps of that night. */\n sleepStart?: string;\n sleepEnd?: string;\n restingHr?: number;\n /**\n * Overnight HRV in ms, as the source measures it: Health Connect reports\n * RMSSD, HealthKit reports SDNN. The two are not convertible, so\n * `hrvMethod` says which.\n */\n hrvMs?: number;\n hrvMethod?: 'rmssd' | 'sdnn';\n avgHr?: number;\n maxHr?: number;\n steps?: number;\n activeCalories?: number;\n activeMinutes?: number;\n distanceMeters?: number;\n /** Whole-day minutes in heart-rate zones 1..5, when the source has them. */\n zoneMinutes?: number[];\n vo2Max?: number;\n weightKg?: number;\n spo2?: number;\n respiratoryRate?: number;\n /** Body measurements, the latest of the day. */\n bodyFatPct?: number;\n leanMassKg?: number;\n bmi?: number;\n waistCm?: number;\n bodyTempC?: number;\n readings?: HealthReading[];\n workouts?: HealthWorkout[];\n /** When the source wrote it (ISO). */\n syncedAt?: string;\n}\n\nexport const HEALTH_NUMERIC_FIELDS = [\n 'sleepMinutes',\n 'inBedMinutes',\n 'deepMinutes',\n 'remMinutes',\n 'lightMinutes',\n 'awakeMinutes',\n 'restingHr',\n 'hrvMs',\n 'avgHr',\n 'maxHr',\n 'steps',\n 'activeCalories',\n 'activeMinutes',\n 'distanceMeters',\n 'vo2Max',\n 'weightKg',\n 'spo2',\n 'respiratoryRate',\n 'bodyFatPct',\n 'leanMassKg',\n 'bmi',\n 'waistCm',\n 'bodyTempC',\n] as const;\n\nexport type HealthNumericField = (typeof HEALTH_NUMERIC_FIELDS)[number];\n\n/** Physically plausible ranges; the backend drops anything outside, so the app does too. */\nexport const HEALTH_RANGES: Record<HealthNumericField, [number, number]> = {\n sleepMinutes: [0, 1080],\n inBedMinutes: [0, 1200],\n deepMinutes: [0, 600],\n remMinutes: [0, 600],\n lightMinutes: [0, 900],\n awakeMinutes: [0, 600],\n restingHr: [25, 140],\n hrvMs: [3, 300],\n avgHr: [25, 220],\n maxHr: [40, 230],\n steps: [0, 150000],\n activeCalories: [0, 10000],\n activeMinutes: [0, 1440],\n distanceMeters: [0, 300000],\n vo2Max: [10, 95],\n weightKg: [25, 350],\n spo2: [70, 100],\n respiratoryRate: [4, 40],\n bodyFatPct: [2, 75],\n leanMassKg: [10, 200],\n bmi: [10, 90],\n waistCm: [40, 250],\n bodyTempC: [33, 43],\n};\n\n/** Reading field ranges, same as the backend's coerceHealthDays. */\nexport const READING_RANGES = {\n systolic: [60, 260],\n diastolic: [30, 160],\n pulse: [25, 220],\n glucoseMgDl: [20, 600],\n} as const satisfies Record<string, [number, number]>;\n\n/** The backend keeps at most this many readings per day. */\nexport const MAX_READINGS_PER_DAY = 50;\n\n/** Workout field ranges, same as the backend's coerceHealthDays. */\nexport const WORKOUT_RANGES = {\n durationMin: [0, 1440],\n calories: [0, 10000],\n distanceMeters: [0, 300000],\n avgHr: [25, 230],\n maxHr: [25, 240],\n} as const satisfies Record<string, [number, number]>;\n\n/** The backend takes at most this many days per `ingestFitnessHealth` call. */\nexport const MAX_INGEST_DAYS = 120;\n/** The backend keeps at most this many workouts per day. */\nexport const MAX_WORKOUTS_PER_DAY = 40;\n"],"names":[],"mappings":"AAgGa,MAAA,qBAAA,GAAwB,CAAC,cAAA,EAAgB,cAAgB,EAAA,aAAA,EAAe,cAAc,cAAgB,EAAA,cAAA,EAAgB,WAAa,EAAA,OAAA,EAAS,OAAS,EAAA,OAAA,EAAS,SAAS,gBAAkB,EAAA,eAAA,EAAiB,gBAAkB,EAAA,QAAA,EAAU,UAAY,EAAA,MAAA,EAAQ,mBAAmB,YAAc,EAAA,YAAA,EAAc,KAAO,EAAA,SAAA,EAAW,WAAW;AAI5U,MAAM,aAA8D,GAAA;AAAA,EACzE,YAAA,EAAc,CAAC,CAAA,EAAG,IAAI,CAAA;AAAA,EACtB,YAAA,EAAc,CAAC,CAAA,EAAG,IAAI,CAAA;AAAA,EACtB,WAAA,EAAa,CAAC,CAAA,EAAG,GAAG,CAAA;AAAA,EACpB,UAAA,EAAY,CAAC,CAAA,EAAG,GAAG,CAAA;AAAA,EACnB,YAAA,EAAc,CAAC,CAAA,EAAG,GAAG,CAAA;AAAA,EACrB,YAAA,EAAc,CAAC,CAAA,EAAG,GAAG,CAAA;AAAA,EACrB,SAAA,EAAW,CA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IAAI,CAAA;AAAA,EACrB,QAAA,EAAU,CAAC,CAAA,EAAG,GAAK,CAAA;AAAA,EACnB,cAAA,EAAgB,CAAC,CAAA,EAAG,GAAM,CAAA;AAAA,EAC1B,KAAA,EAAO,CAAC,EAAA,EAAI,GAAG,CAAA;AAAA,EACf,KAAA,EAAO,CAAC,EAAA,EAAI,GAAG;AACjB;AAGO,MAAM,eAAkB,GAAA;AAExB,MAAM,oBAAuB,GAAA"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
const HK_WRITE_TYPES = ["HKQuantityTypeIdentifierBodyMass", "HKQuantityTypeIdentifierBodyFatPercentage", "HKQuantityTypeIdentifierLeanBodyMass", "HKQuantityTypeIdentifierBodyMassIndex", "HKQuantityTypeIdentifierBloodPressureSystolic", "HKQuantityTypeIdentifierBloodPressureDiastolic", "HKQuantityTypeIdentifierHeartRate", "HKQuantityTypeIdentifierOxygenSaturation", "HKQuantityTypeIdentifierBodyTemperature", "HKQuantityTypeIdentifierBloodGlucose"];
|
|
18
|
+
function hkMeta(syncId) {
|
|
19
|
+
return {
|
|
20
|
+
HKMetadataKeySyncIdentifier: syncId,
|
|
21
|
+
HKMetadataKeySyncVersion: 1,
|
|
22
|
+
HKMetadataKeyExternalUUID: syncId
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const HK_MEAL_TIME = {
|
|
26
|
+
"before-meal": 1,
|
|
27
|
+
fasting: 1,
|
|
28
|
+
"after-meal": 2
|
|
29
|
+
};
|
|
30
|
+
function healthKitWritesFor(r) {
|
|
31
|
+
const at = new Date(r.at);
|
|
32
|
+
const q = (type, unit, value, suffix, extra = {}) => ({
|
|
33
|
+
kind: "quantity",
|
|
34
|
+
type,
|
|
35
|
+
unit,
|
|
36
|
+
value,
|
|
37
|
+
at,
|
|
38
|
+
metadata: __spreadValues(__spreadValues({}, hkMeta(`${r.id}:${suffix}`)), extra)
|
|
39
|
+
});
|
|
40
|
+
switch (r.kind) {
|
|
41
|
+
case "body": {
|
|
42
|
+
const out = [];
|
|
43
|
+
if (r.weightKg !== void 0) out.push(q("HKQuantityTypeIdentifierBodyMass", "kg", r.weightKg, "weight"));
|
|
44
|
+
if (r.bodyFatPct !== void 0) out.push(q("HKQuantityTypeIdentifierBodyFatPercentage", "%", r.bodyFatPct / 100, "fat"));
|
|
45
|
+
if (r.leanMassKg !== void 0) out.push(q("HKQuantityTypeIdentifierLeanBodyMass", "kg", r.leanMassKg, "lean"));
|
|
46
|
+
if (r.bmi !== void 0) out.push(q("HKQuantityTypeIdentifierBodyMassIndex", "count", r.bmi, "bmi"));
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
case "blood-pressure": {
|
|
50
|
+
const out = [{
|
|
51
|
+
kind: "blood-pressure",
|
|
52
|
+
systolic: r.systolic,
|
|
53
|
+
diastolic: r.diastolic,
|
|
54
|
+
at,
|
|
55
|
+
metadata: hkMeta(`${r.id}:bp`)
|
|
56
|
+
}];
|
|
57
|
+
if (r.pulse !== void 0) out.push(q("HKQuantityTypeIdentifierHeartRate", "count/min", r.pulse, "pulse"));
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
case "temperature":
|
|
61
|
+
return [q("HKQuantityTypeIdentifierBodyTemperature", "degC", r.celsius, "temp")];
|
|
62
|
+
case "spo2": {
|
|
63
|
+
const out = [q("HKQuantityTypeIdentifierOxygenSaturation", "%", r.spo2 / 100, "spo2")];
|
|
64
|
+
if (r.pulse !== void 0) out.push(q("HKQuantityTypeIdentifierHeartRate", "count/min", r.pulse, "pulse"));
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
case "glucose": {
|
|
68
|
+
const meal = r.meal ? HK_MEAL_TIME[r.meal] : void 0;
|
|
69
|
+
return [q("HKQuantityTypeIdentifierBloodGlucose", "mg/dL", r.mgdl, "glucose", meal ? {
|
|
70
|
+
HKMetadataKeyBloodGlucoseMealTime: meal
|
|
71
|
+
} : {})];
|
|
72
|
+
}
|
|
73
|
+
case "heart-rate":
|
|
74
|
+
return r.samples.map((s) => ({
|
|
75
|
+
kind: "quantity",
|
|
76
|
+
type: "HKQuantityTypeIdentifierHeartRate",
|
|
77
|
+
unit: "count/min",
|
|
78
|
+
value: s.value,
|
|
79
|
+
at: new Date(s.t),
|
|
80
|
+
metadata: hkMeta(`${r.id}:hr:${Math.round(s.t / 1e3)}`)
|
|
81
|
+
}));
|
|
82
|
+
default:
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const HC_WRITE_TYPES = ["Weight", "BodyFat", "LeanBodyMass", "BloodPressure", "HeartRate", "OxygenSaturation", "BodyTemperature", "BloodGlucose"];
|
|
87
|
+
const HC_DEVICE_TYPE = {
|
|
88
|
+
body: 3,
|
|
89
|
+
"heart-rate": 7
|
|
90
|
+
};
|
|
91
|
+
const AUTOMATICALLY_RECORDED = 2;
|
|
92
|
+
const HC_RELATION_TO_MEAL = {
|
|
93
|
+
fasting: 2,
|
|
94
|
+
"before-meal": 3,
|
|
95
|
+
"after-meal": 4,
|
|
96
|
+
bedtime: 1,
|
|
97
|
+
other: 1
|
|
98
|
+
};
|
|
99
|
+
const CAPILLARY_BLOOD = 2;
|
|
100
|
+
function healthConnectRecordsFor(r) {
|
|
101
|
+
const time = new Date(r.at).toISOString();
|
|
102
|
+
const metadata = (suffix) => {
|
|
103
|
+
var _a;
|
|
104
|
+
return {
|
|
105
|
+
clientRecordId: `${r.id}:${suffix}`,
|
|
106
|
+
clientRecordVersion: 1,
|
|
107
|
+
recordingMethod: AUTOMATICALLY_RECORDED,
|
|
108
|
+
device: {
|
|
109
|
+
model: r.deviceName,
|
|
110
|
+
type: (_a = HC_DEVICE_TYPE[r.kind]) != null ? _a : 0
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
switch (r.kind) {
|
|
115
|
+
case "body": {
|
|
116
|
+
const out = [];
|
|
117
|
+
if (r.weightKg !== void 0) out.push({
|
|
118
|
+
recordType: "Weight",
|
|
119
|
+
time,
|
|
120
|
+
weight: {
|
|
121
|
+
value: r.weightKg,
|
|
122
|
+
unit: "kilograms"
|
|
123
|
+
},
|
|
124
|
+
metadata: metadata("weight")
|
|
125
|
+
});
|
|
126
|
+
if (r.bodyFatPct !== void 0) out.push({
|
|
127
|
+
recordType: "BodyFat",
|
|
128
|
+
time,
|
|
129
|
+
percentage: r.bodyFatPct,
|
|
130
|
+
metadata: metadata("fat")
|
|
131
|
+
});
|
|
132
|
+
if (r.leanMassKg !== void 0) out.push({
|
|
133
|
+
recordType: "LeanBodyMass",
|
|
134
|
+
time,
|
|
135
|
+
mass: {
|
|
136
|
+
value: r.leanMassKg,
|
|
137
|
+
unit: "kilograms"
|
|
138
|
+
},
|
|
139
|
+
metadata: metadata("lean")
|
|
140
|
+
});
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
case "blood-pressure": {
|
|
144
|
+
const out = [{
|
|
145
|
+
recordType: "BloodPressure",
|
|
146
|
+
time,
|
|
147
|
+
systolic: {
|
|
148
|
+
value: r.systolic,
|
|
149
|
+
unit: "millimetersOfMercury"
|
|
150
|
+
},
|
|
151
|
+
diastolic: {
|
|
152
|
+
value: r.diastolic,
|
|
153
|
+
unit: "millimetersOfMercury"
|
|
154
|
+
},
|
|
155
|
+
bodyPosition: 0,
|
|
156
|
+
measurementLocation: 0,
|
|
157
|
+
metadata: metadata("bp")
|
|
158
|
+
}];
|
|
159
|
+
if (r.pulse !== void 0) out.push(heartRateRecord(r.at, r.at + 1e3, [{
|
|
160
|
+
t: r.at,
|
|
161
|
+
value: r.pulse
|
|
162
|
+
}], metadata("pulse")));
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
case "temperature":
|
|
166
|
+
return [{
|
|
167
|
+
recordType: "BodyTemperature",
|
|
168
|
+
time,
|
|
169
|
+
temperature: {
|
|
170
|
+
value: r.celsius,
|
|
171
|
+
unit: "celsius"
|
|
172
|
+
},
|
|
173
|
+
metadata: metadata("temp")
|
|
174
|
+
}];
|
|
175
|
+
case "spo2": {
|
|
176
|
+
const out = [{
|
|
177
|
+
recordType: "OxygenSaturation",
|
|
178
|
+
time,
|
|
179
|
+
percentage: r.spo2,
|
|
180
|
+
metadata: metadata("spo2")
|
|
181
|
+
}];
|
|
182
|
+
if (r.pulse !== void 0) out.push(heartRateRecord(r.at, r.at + 1e3, [{
|
|
183
|
+
t: r.at,
|
|
184
|
+
value: r.pulse
|
|
185
|
+
}], metadata("pulse")));
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
case "glucose":
|
|
189
|
+
return [{
|
|
190
|
+
recordType: "BloodGlucose",
|
|
191
|
+
time,
|
|
192
|
+
level: {
|
|
193
|
+
value: r.mgdl,
|
|
194
|
+
unit: "milligramsPerDeciliter"
|
|
195
|
+
},
|
|
196
|
+
specimenSource: CAPILLARY_BLOOD,
|
|
197
|
+
mealType: 0,
|
|
198
|
+
relationToMeal: r.meal ? HC_RELATION_TO_MEAL[r.meal] : 0,
|
|
199
|
+
metadata: metadata("glucose")
|
|
200
|
+
}];
|
|
201
|
+
case "heart-rate":
|
|
202
|
+
return r.samples.length ? [heartRateRecord(r.at, r.end, r.samples, metadata("hr"))] : [];
|
|
203
|
+
default:
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function heartRateRecord(start, end, samples, metadata) {
|
|
208
|
+
return {
|
|
209
|
+
recordType: "HeartRate",
|
|
210
|
+
startTime: new Date(start).toISOString(),
|
|
211
|
+
endTime: new Date(Math.max(end, start + 1e3)).toISOString(),
|
|
212
|
+
samples: samples.map((s) => ({
|
|
213
|
+
time: new Date(s.t).toISOString(),
|
|
214
|
+
beatsPerMinute: Math.round(s.value)
|
|
215
|
+
})),
|
|
216
|
+
metadata
|
|
217
|
+
};
|
|
218
|
+
}export{HC_WRITE_TYPES,HK_WRITE_TYPES,healthConnectRecordsFor,healthKitWritesFor};//# sourceMappingURL=writeMapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeMapping.js","sources":["../../../src/features/health/writeMapping.ts"],"sourcesContent":["/**\n * A reading Yantra took from a paired Bluetooth device -> what Apple Health or\n * Health Connect stores, so the person's other apps see it too. Only what\n * Yantra itself measured is ever written (never a copy of something it read),\n * and workouts stay with the watch that recorded them.\n *\n * Every sample carries the reading's id as the store's own de-duplication key\n * (HealthKit HKMetadataKeySyncIdentifier, Health Connect clientRecordId), so\n * saving the same reading twice replaces it instead of adding a second one.\n *\n * Pure: the writers (healthkitWriter.ts, healthConnectWriter.ts) only hand\n * these to the native libraries.\n */\n\nimport type { DeviceReading } from '../devices/readings';\n\n// ---------------------------------------------------------------- HealthKit\n\nexport type HKWriteType =\n | 'HKQuantityTypeIdentifierBodyMass'\n | 'HKQuantityTypeIdentifierBodyFatPercentage'\n | 'HKQuantityTypeIdentifierLeanBodyMass'\n | 'HKQuantityTypeIdentifierBodyMassIndex'\n | 'HKQuantityTypeIdentifierBloodPressureSystolic'\n | 'HKQuantityTypeIdentifierBloodPressureDiastolic'\n | 'HKQuantityTypeIdentifierHeartRate'\n | 'HKQuantityTypeIdentifierOxygenSaturation'\n | 'HKQuantityTypeIdentifierBodyTemperature'\n | 'HKQuantityTypeIdentifierBloodGlucose';\n\n/** Everything Yantra may ask to save, in one permission sheet with the reads. */\nexport const HK_WRITE_TYPES: readonly HKWriteType[] = [\n 'HKQuantityTypeIdentifierBodyMass',\n 'HKQuantityTypeIdentifierBodyFatPercentage',\n 'HKQuantityTypeIdentifierLeanBodyMass',\n 'HKQuantityTypeIdentifierBodyMassIndex',\n 'HKQuantityTypeIdentifierBloodPressureSystolic',\n 'HKQuantityTypeIdentifierBloodPressureDiastolic',\n 'HKQuantityTypeIdentifierHeartRate',\n 'HKQuantityTypeIdentifierOxygenSaturation',\n 'HKQuantityTypeIdentifierBodyTemperature',\n 'HKQuantityTypeIdentifierBloodGlucose',\n];\n\nexport interface HKQuantityWrite {\n kind: 'quantity';\n type: HKWriteType;\n unit: string;\n value: number;\n at: Date;\n metadata: Record<string, string | number>;\n}\n\nexport interface HKBloodPressureWrite {\n kind: 'blood-pressure';\n systolic: number;\n diastolic: number;\n at: Date;\n metadata: Record<string, string | number>;\n}\n\nexport type HKWrite = HKQuantityWrite | HKBloodPressureWrite;\n\n/** HealthKit's own de-duplication: a second save with the same identifier replaces the first. */\nfunction hkMeta(syncId: string): Record<string, string | number> {\n return { HKMetadataKeySyncIdentifier: syncId, HKMetadataKeySyncVersion: 1, HKMetadataKeyExternalUUID: syncId };\n}\n\n/** HKMetadataKeyBloodGlucoseMealTime: 1 before a meal, 2 after one. */\nconst HK_MEAL_TIME: Partial<Record<string, number>> = { 'before-meal': 1, fasting: 1, 'after-meal': 2 };\n\nexport function healthKitWritesFor(r: DeviceReading): HKWrite[] {\n const at = new Date(r.at);\n const q = (type: HKWriteType, unit: string, value: number, suffix: string, extra = {}): HKQuantityWrite => ({\n kind: 'quantity',\n type,\n unit,\n value,\n at,\n metadata: { ...hkMeta(`${r.id}:${suffix}`), ...extra },\n });\n switch (r.kind) {\n case 'body': {\n const out: HKWrite[] = [];\n if (r.weightKg !== undefined) out.push(q('HKQuantityTypeIdentifierBodyMass', 'kg', r.weightKg, 'weight'));\n // HealthKit's percent unit is a fraction: 23.1 % is 0.231.\n if (r.bodyFatPct !== undefined)\n out.push(q('HKQuantityTypeIdentifierBodyFatPercentage', '%', r.bodyFatPct / 100, 'fat'));\n if (r.leanMassKg !== undefined)\n out.push(q('HKQuantityTypeIdentifierLeanBodyMass', 'kg', r.leanMassKg, 'lean'));\n if (r.bmi !== undefined) out.push(q('HKQuantityTypeIdentifierBodyMassIndex', 'count', r.bmi, 'bmi'));\n return out;\n }\n case 'blood-pressure': {\n const out: HKWrite[] = [\n {\n kind: 'blood-pressure',\n systolic: r.systolic,\n diastolic: r.diastolic,\n at,\n metadata: hkMeta(`${r.id}:bp`),\n },\n ];\n if (r.pulse !== undefined) out.push(q('HKQuantityTypeIdentifierHeartRate', 'count/min', r.pulse, 'pulse'));\n return out;\n }\n case 'temperature':\n return [q('HKQuantityTypeIdentifierBodyTemperature', 'degC', r.celsius, 'temp')];\n case 'spo2': {\n const out: HKWrite[] = [q('HKQuantityTypeIdentifierOxygenSaturation', '%', r.spo2 / 100, 'spo2')];\n if (r.pulse !== undefined) out.push(q('HKQuantityTypeIdentifierHeartRate', 'count/min', r.pulse, 'pulse'));\n return out;\n }\n case 'glucose': {\n const meal = r.meal ? HK_MEAL_TIME[r.meal] : undefined;\n return [\n q(\n 'HKQuantityTypeIdentifierBloodGlucose',\n 'mg/dL',\n r.mgdl,\n 'glucose',\n meal ? { HKMetadataKeyBloodGlucoseMealTime: meal } : {},\n ),\n ];\n }\n case 'heart-rate':\n // The samples, not a workout: the person's watch or the strap's own app owns workouts.\n return r.samples.map((s) => ({\n kind: 'quantity' as const,\n type: 'HKQuantityTypeIdentifierHeartRate' as const,\n unit: 'count/min',\n value: s.value,\n at: new Date(s.t),\n metadata: hkMeta(`${r.id}:hr:${Math.round(s.t / 1000)}`),\n }));\n default:\n return [];\n }\n}\n\n// ----------------------------------------------------------- Health Connect\n\nexport type HCWriteRecordType =\n | 'Weight'\n | 'BodyFat'\n | 'LeanBodyMass'\n | 'BloodPressure'\n | 'HeartRate'\n | 'OxygenSaturation'\n | 'BodyTemperature'\n | 'BloodGlucose';\n\nexport const HC_WRITE_TYPES: readonly HCWriteRecordType[] = [\n 'Weight',\n 'BodyFat',\n 'LeanBodyMass',\n 'BloodPressure',\n 'HeartRate',\n 'OxygenSaturation',\n 'BodyTemperature',\n 'BloodGlucose',\n];\n\n/** Health Connect metadata.device.type: 3 scale, 7 chest strap, 0 unknown. */\nconst HC_DEVICE_TYPE: Partial<Record<DeviceReading['kind'], number>> = { body: 3, 'heart-rate': 7 };\n/** RecordingMethod.RECORDING_METHOD_AUTOMATICALLY_RECORDED: a device measured it. */\nconst AUTOMATICALLY_RECORDED = 2;\n/** RelationToMeal: 2 fasting, 3 before a meal, 4 after one, 1 general. */\nconst HC_RELATION_TO_MEAL: Record<string, number> = {\n fasting: 2,\n 'before-meal': 3,\n 'after-meal': 4,\n bedtime: 1,\n other: 1,\n};\n/** SpecimenSource.CAPILLARY_BLOOD: a finger-prick meter. */\nconst CAPILLARY_BLOOD = 2;\n\nexport type HCRecord = { recordType: HCWriteRecordType } & Record<string, unknown>;\n\nexport function healthConnectRecordsFor(r: DeviceReading): HCRecord[] {\n const time = new Date(r.at).toISOString();\n const metadata = (suffix: string) => ({\n clientRecordId: `${r.id}:${suffix}`,\n clientRecordVersion: 1,\n recordingMethod: AUTOMATICALLY_RECORDED,\n device: { model: r.deviceName, type: HC_DEVICE_TYPE[r.kind] ?? 0 },\n });\n switch (r.kind) {\n case 'body': {\n const out: HCRecord[] = [];\n if (r.weightKg !== undefined)\n out.push({\n recordType: 'Weight',\n time,\n weight: { value: r.weightKg, unit: 'kilograms' },\n metadata: metadata('weight'),\n });\n if (r.bodyFatPct !== undefined)\n out.push({ recordType: 'BodyFat', time, percentage: r.bodyFatPct, metadata: metadata('fat') });\n if (r.leanMassKg !== undefined)\n out.push({\n recordType: 'LeanBodyMass',\n time,\n mass: { value: r.leanMassKg, unit: 'kilograms' },\n metadata: metadata('lean'),\n });\n return out;\n }\n case 'blood-pressure': {\n const out: HCRecord[] = [\n {\n recordType: 'BloodPressure',\n time,\n systolic: { value: r.systolic, unit: 'millimetersOfMercury' },\n diastolic: { value: r.diastolic, unit: 'millimetersOfMercury' },\n bodyPosition: 0,\n measurementLocation: 0,\n metadata: metadata('bp'),\n },\n ];\n if (r.pulse !== undefined)\n out.push(heartRateRecord(r.at, r.at + 1000, [{ t: r.at, value: r.pulse }], metadata('pulse')));\n return out;\n }\n case 'temperature':\n return [\n {\n recordType: 'BodyTemperature',\n time,\n temperature: { value: r.celsius, unit: 'celsius' },\n metadata: metadata('temp'),\n },\n ];\n case 'spo2': {\n const out: HCRecord[] = [\n { recordType: 'OxygenSaturation', time, percentage: r.spo2, metadata: metadata('spo2') },\n ];\n if (r.pulse !== undefined)\n out.push(heartRateRecord(r.at, r.at + 1000, [{ t: r.at, value: r.pulse }], metadata('pulse')));\n return out;\n }\n case 'glucose':\n return [\n {\n recordType: 'BloodGlucose',\n time,\n level: { value: r.mgdl, unit: 'milligramsPerDeciliter' },\n specimenSource: CAPILLARY_BLOOD,\n mealType: 0,\n relationToMeal: r.meal ? HC_RELATION_TO_MEAL[r.meal] : 0,\n metadata: metadata('glucose'),\n },\n ];\n case 'heart-rate':\n return r.samples.length ? [heartRateRecord(r.at, r.end, r.samples, metadata('hr'))] : [];\n default:\n return [];\n }\n}\n\nfunction heartRateRecord(\n start: number,\n end: number,\n samples: ReadonlyArray<{ t: number; value: number }>,\n metadata: Record<string, unknown>,\n): HCRecord {\n return {\n recordType: 'HeartRate',\n startTime: new Date(start).toISOString(),\n endTime: new Date(Math.max(end, start + 1000)).toISOString(),\n samples: samples.map((s) => ({ time: new Date(s.t).toISOString(), beatsPerMinute: Math.round(s.value) })),\n metadata,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;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,eAAgB,CAAA,KAAA,EAAe,GAAa,EAAA,OAAA,EAGjD,QAA6C,EAAA;AAC/C,EAAO,OAAA;AAAA,IACL,UAAY,EAAA,WAAA;AAAA,IACZ,SAAW,EAAA,IAAI,IAAK,CAAA,KAAK,EAAE,WAAY,EAAA;AAAA,IACvC,OAAA,EAAS,IAAI,IAAA,CAAK,IAAK,CAAA,GAAA,CAAI,KAAK,KAAQ,GAAA,GAAI,CAAC,CAAA,CAAE,WAAY,EAAA;AAAA,IAC3D,OAAA,EAAS,OAAQ,CAAA,GAAA,CAAI,CAAM,CAAA,MAAA;AAAA,MACzB,MAAM,IAAI,IAAA,CAAK,CAAE,CAAA,CAAC,EAAE,WAAY,EAAA;AAAA,MAChC,cAAgB,EAAA,IAAA,CAAK,KAAM,CAAA,CAAA,CAAE,KAAK;AAAA,KAClC,CAAA,CAAA;AAAA,IACF;AAAA,GACF;AACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {jsx}from'react/jsx-runtime';import*as React from'react';import {getApolloContext,gql}from'@apollo/client/index.js';import {navigationRef}from'@common-stack/client-react';import {Linking}from'react-native';import {openChatLink,createLinkPreviewLoader}from'../messaging/linkPreview.js';import {ChatLinkOpenerContext}from'./chatLinkOpener.js';import {openWebPageInApp,openSurfaceInApp}from'./openInApp.js';const documents = /* @__PURE__ */ new Map();
|
|
2
|
+
const loaders = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function linkPreviewLoaderFor(client) {
|
|
4
|
+
let loader = loaders.get(client);
|
|
5
|
+
if (!loader) {
|
|
6
|
+
loader = createLinkPreviewLoader({
|
|
7
|
+
async query(document, variables, opts) {
|
|
8
|
+
var _a;
|
|
9
|
+
let parsed = documents.get(document);
|
|
10
|
+
if (!parsed) {
|
|
11
|
+
parsed = gql(document);
|
|
12
|
+
documents.set(document, parsed);
|
|
13
|
+
}
|
|
14
|
+
const res = await client.query({
|
|
15
|
+
query: parsed,
|
|
16
|
+
variables,
|
|
17
|
+
fetchPolicy: (_a = opts == null ? void 0 : opts.fetchPolicy) != null ? _a : "cache-first"
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
data: res.data,
|
|
21
|
+
errors: res.errors
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
loaders.set(client, loader);
|
|
26
|
+
}
|
|
27
|
+
return loader;
|
|
28
|
+
}
|
|
29
|
+
const NO_PREVIEWS = {
|
|
30
|
+
load: async () => ({
|
|
31
|
+
preview: null,
|
|
32
|
+
open: null
|
|
33
|
+
}),
|
|
34
|
+
peek: () => void 0
|
|
35
|
+
};
|
|
36
|
+
function ChatLinkOpenerProvider({
|
|
37
|
+
children
|
|
38
|
+
}) {
|
|
39
|
+
const client = React.useContext(getApolloContext()).client;
|
|
40
|
+
const open = React.useCallback((url) => {
|
|
41
|
+
void openChatLink(url, {
|
|
42
|
+
loader: client ? linkPreviewLoaderFor(client) : NO_PREVIEWS,
|
|
43
|
+
link: {
|
|
44
|
+
openUrl: async (target) => {
|
|
45
|
+
await Linking.openURL(target).catch(() => void 0);
|
|
46
|
+
},
|
|
47
|
+
openWebPage: openWebPageInApp,
|
|
48
|
+
openSurface: async (target) => {
|
|
49
|
+
if (navigationRef.isReady()) openSurfaceInApp(navigationRef, target);
|
|
50
|
+
else await openWebPageInApp(target.url);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}, [client]);
|
|
55
|
+
return /* @__PURE__ */ jsx(ChatLinkOpenerContext.Provider, { value: open, children });
|
|
56
|
+
}export{ChatLinkOpenerProvider};//# sourceMappingURL=ChatLinkOpenerProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatLinkOpenerProvider.js","sources":["../../../src/features/links/ChatLinkOpenerProvider.tsx"],"sourcesContent":["/**\n * Opens links tapped in a chat's markdown the way the messenger does: in the\n * app on their surface when the gateway says they belong there, else in an\n * in-app browser sheet (openInApp.ts, messaging/linkPreview.ts).\n *\n * Mounted by the chat screens. It navigates through the app's root\n * `navigationRef`, so it works wherever the transcript sits in the tree.\n */\nimport * as React from 'react';\nimport { getApolloContext, gql, type ApolloClient, type DocumentNode } from '@apollo/client';\nimport { navigationRef } from '@common-stack/client-react';\nimport { Linking } from 'react-native';\nimport { createLinkPreviewLoader, openChatLink, type LinkPreviewLoader } from '../messaging/linkPreview';\nimport { ChatLinkOpenerContext } from './chatLinkOpener';\nimport { openSurfaceInApp, openWebPageInApp } from './openInApp';\n\nconst documents = new Map<string, DocumentNode>();\nconst loaders = new WeakMap<ApolloClient<unknown>, LinkPreviewLoader>();\n\n/** One loader per Apollo client, so every chat shares what the others already read. */\nfunction linkPreviewLoaderFor(client: ApolloClient<unknown>): LinkPreviewLoader {\n let loader = loaders.get(client);\n if (!loader) {\n loader = createLinkPreviewLoader({\n async query(document, variables, opts) {\n let parsed = documents.get(document);\n if (!parsed) {\n parsed = gql(document);\n documents.set(document, parsed);\n }\n const res = await client.query({\n query: parsed,\n variables,\n fetchPolicy: opts?.fetchPolicy ?? 'cache-first',\n });\n return { data: res.data as never, errors: res.errors as never };\n },\n });\n loaders.set(client, loader);\n }\n return loader;\n}\n\nconst NO_PREVIEWS: LinkPreviewLoader = {\n load: async () => ({ preview: null, open: null }),\n peek: () => undefined,\n};\n\nexport function ChatLinkOpenerProvider({ children }: { children: React.ReactNode }) {\n const client = React.useContext(getApolloContext()).client as ApolloClient<unknown> | undefined;\n const open = React.useCallback(\n (url: string) => {\n void openChatLink(url, {\n loader: client ? linkPreviewLoaderFor(client) : NO_PREVIEWS,\n link: {\n openUrl: async (target) => {\n await Linking.openURL(target).catch(() => undefined);\n },\n openWebPage: openWebPageInApp,\n openSurface: async (target) => {\n // Not ready only while the app is still mounting its navigator.\n if (navigationRef.isReady()) openSurfaceInApp(navigationRef, target);\n else await openWebPageInApp(target.url);\n },\n },\n });\n },\n [client],\n );\n return <ChatLinkOpenerContext.Provider value={open}>{children}</ChatLinkOpenerContext.Provider>;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;AACF,CAEG,EAAA;AACD,EAAA,MAAM,MAAS,GAAA,KAAA,CAAM,UAAW,CAAA,gBAAA,EAAkB,CAAE,CAAA,MAAA;AACpD,EAAA,MAAM,IAAO,GAAA,KAAA,CAAM,WAAY,CAAA,CAAC,GAAgB,KAAA;AAC9C,IAAA,KAAK,aAAa,GAAK,EAAA;AAAA,MACrB,MAAQ,EAAA,MAAA,GAAS,oBAAqB,CAAA,MAAM,CAAI,GAAA,WAAA;AAAA,MAChD,IAAM,EAAA;AAAA,QACJ,OAAA,EAAS,OAAM,MAAU,KAAA;AACvB,UAAA,MAAM,QAAQ,OAAQ,CAAA,MAAM,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA,SACrD;AAAA,QACA,WAAa,EAAA,gBAAA;AAAA,QACb,WAAA,EAAa,OAAM,MAAU,KAAA;AAE3B,UAAA,IAAI,aAAc,CAAA,OAAA,EAAW,EAAA,gBAAA,CAAiB,eAAe,MAAM,CAAA;AAAA,eAAO,MAAM,gBAAiB,CAAA,MAAA,CAAO,GAAG,CAAA;AAAA;AAC7G;AACF,KACD,CAAA;AAAA,GACH,EAAG,CAAC,MAAM,CAAC,CAAA;AACX,EAAA,2BAAQ,qBAAsB,CAAA,QAAA,EAAtB,EAA+B,KAAA,EAAO,MAAO,QAAS,EAAA,CAAA;AAChE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import*as React from'react';import {Linking}from'react-native';const ChatLinkOpenerContext = React.createContext(null);
|
|
2
|
+
const openWithOs = (url) => {
|
|
3
|
+
void Linking.openURL(url).catch(() => void 0);
|
|
4
|
+
};
|
|
5
|
+
function useChatLinkOpener() {
|
|
6
|
+
var _a;
|
|
7
|
+
return (_a = React.useContext(ChatLinkOpenerContext)) != null ? _a : openWithOs;
|
|
8
|
+
}export{ChatLinkOpenerContext,useChatLinkOpener};//# sourceMappingURL=chatLinkOpener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatLinkOpener.js","sources":["../../../src/features/links/chatLinkOpener.ts"],"sourcesContent":["/**\n * How a chat's markdown opens a tapped link - injected, so the markdown stays\n * a presentational component with no navigation, Apollo or browser imports.\n *\n * The chat screens mount ChatLinkOpenerProvider, which opens a link in the app\n * on its surface or in a browser sheet (the gateway decides which). Anywhere\n * without it - a test, a preview - a link still opens, through the OS.\n */\nimport * as React from 'react';\nimport { Linking } from 'react-native';\n\nexport type OpenChatLink = (url: string) => void;\n\nexport const ChatLinkOpenerContext = React.createContext<OpenChatLink | null>(null);\n\nconst openWithOs: OpenChatLink = (url) => {\n void Linking.openURL(url).catch(() => undefined);\n};\n\nexport function useChatLinkOpener(): OpenChatLink {\n return React.useContext(ChatLinkOpenerContext) ?? openWithOs;\n}\n"],"names":[],"mappings":"+DAWa,MAAA,qBAAA,GAAwB,KAAM,CAAA,aAAA,CAAmC,IAAI;AAClF,MAAM,aAA2B,CAAO,GAAA,KAAA;AACtC,EAAA,KAAK,QAAQ,OAAQ,CAAA,GAAG,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AACjD,CAAA;AACO,SAAS,iBAAkC,GAAA;AAflD,EAAA,IAAA,EAAA;AAgBE,EAAA,OAAA,CAAO,EAAM,GAAA,KAAA,CAAA,UAAA,CAAW,qBAAqB,CAAA,KAAtC,IAA2C,GAAA,EAAA,GAAA,UAAA;AACpD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {CommonActions}from'@react-navigation/native';import*as WebBrowser from'expo-web-browser';import {Linking}from'react-native';function surfaceTitle(slug) {
|
|
2
|
+
return slug.split(/[-_]+/).filter(Boolean).map((word) => word[0].toUpperCase() + word.slice(1)).join(" ");
|
|
3
|
+
}
|
|
4
|
+
function openSurfaceInApp(navigation, target) {
|
|
5
|
+
navigation.dispatch(CommonActions.navigate({
|
|
6
|
+
name: "MainStack.WebBuilder",
|
|
7
|
+
params: {
|
|
8
|
+
url: target.url,
|
|
9
|
+
appTitle: surfaceTitle(target.surface)
|
|
10
|
+
}
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
async function openWebPageInApp(url) {
|
|
14
|
+
try {
|
|
15
|
+
if (/^https?:\/\//i.test(url)) {
|
|
16
|
+
await WebBrowser.openBrowserAsync(url, {
|
|
17
|
+
presentationStyle: WebBrowser.WebBrowserPresentationStyle.PAGE_SHEET,
|
|
18
|
+
dismissButtonStyle: "close"
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
await Linking.openURL(url);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
}
|
|
25
|
+
}export{openSurfaceInApp,openWebPageInApp,surfaceTitle};//# sourceMappingURL=openInApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openInApp.js","sources":["../../../src/features/links/openInApp.ts"],"sourcesContent":["/**\n * Where a tapped link opens on the phone.\n *\n * A Yantra surface page opens in the app's own surface screen (WebBuilder),\n * which hands the page this device's sign-in - so a bounty link opens the\n * bounty in Freelance, signed in, ready to apply. Any other web page opens in\n * an in-app browser sheet, so reading a link never drops the person out of\n * Yantra. WHICH links are surface pages is the messenger gateway's call\n * (`Query.gatewayLinkPreview` -> `open`), not decided here.\n *\n * Shared by the messenger's host seam (portable-devices `useChatLinkSeam`) and\n * the assistant chat, so a link behaves the same wherever it was tapped.\n */\nimport { CommonActions, type NavigationProp, type ParamListBase } from '@react-navigation/native';\nimport * as WebBrowser from 'expo-web-browser';\nimport { Linking } from 'react-native';\n\nexport interface InAppSurfaceTarget {\n surface: string;\n url: string;\n}\n\n/** `freelance` -> `Freelance`, `job-search` -> `Job Search`: the surface screen's header. */\nexport function surfaceTitle(slug: string): string {\n return slug\n .split(/[-_]+/)\n .filter(Boolean)\n .map((word) => word[0].toUpperCase() + word.slice(1))\n .join(' ');\n}\n\n/**\n * Open a surface page in the app's surface screen - the same navigation the\n * Apps catalog uses to open a surface tile, with the link's page as its URL.\n */\nexport function openSurfaceInApp(\n navigation: Pick<NavigationProp<ParamListBase>, 'dispatch'>,\n target: InAppSurfaceTarget,\n): void {\n navigation.dispatch(\n CommonActions.navigate({\n name: 'MainStack.WebBuilder',\n params: { url: target.url, appTitle: surfaceTitle(target.surface) },\n }),\n );\n}\n\n/** Open a web page in an in-app browser sheet; anything that is not a web page goes to the OS. */\nexport async function openWebPageInApp(url: string): Promise<void> {\n try {\n if (/^https?:\\/\\//i.test(url)) {\n await WebBrowser.openBrowserAsync(url, {\n presentationStyle: WebBrowser.WebBrowserPresentationStyle.PAGE_SHEET,\n dismissButtonStyle: 'close',\n });\n return;\n }\n await Linking.openURL(url);\n } catch {\n // A link that cannot be opened must not take the screen down with it.\n }\n}\n"],"names":[],"mappings":"oIAsBO,SAAS,aAAa,IAAsB,EAAA;AACjD,EAAO,OAAA,IAAA,CAAK,MAAM,OAAO,CAAA,CAAE,OAAO,OAAO,CAAA,CAAE,IAAI,CAAQ,IAAA,KAAA,IAAA,CAAK,CAAC,CAAE,CAAA,WAAA,KAAgB,IAAK,CAAA,KAAA,CAAM,CAAC,CAAC,CAAA,CAAE,KAAK,GAAG,CAAA;AACxG;AAMgB,SAAA,gBAAA,CAAiB,YAA6D,MAAkC,EAAA;AAC9H,EAAW,UAAA,CAAA,QAAA,CAAS,cAAc,QAAS,CAAA;AAAA,IACzC,IAAM,EAAA,sBAAA;AAAA,IACN,MAAQ,EAAA;AAAA,MACN,KAAK,MAAO,CAAA,GAAA;AAAA,MACZ,QAAA,EAAU,YAAa,CAAA,MAAA,CAAO,OAAO;AAAA;AACvC,GACD,CAAC,CAAA;AACJ;AAGA,eAAsB,iBAAiB,GAA4B,EAAA;AACjE,EAAI,IAAA;AACF,IAAI,IAAA,eAAA,CAAgB,IAAK,CAAA,GAAG,CAAG,EAAA;AAC7B,MAAM,MAAA,UAAA,CAAW,iBAAiB,GAAK,EAAA;AAAA,QACrC,iBAAA,EAAmB,WAAW,2BAA4B,CAAA,UAAA;AAAA,QAC1D,kBAAoB,EAAA;AAAA,OACrB,CAAA;AACD,MAAA;AAAA;AAEF,IAAM,MAAA,OAAA,CAAQ,QAAQ,GAAG,CAAA;AAAA,GACnB,CAAA,OAAA,CAAA,EAAA;AAAA;AAGV"}
|