@ateam-ai-mobile/expo 0.1.4 → 0.1.7

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 (158) hide show
  1. package/android/build.gradle +16 -0
  2. package/android/src/main/java/expo/modules/adavision/AdaVisionModule.kt +75 -0
  3. package/dist/attachmentCache-DhQTqi2E.d.mts +18 -0
  4. package/dist/attachmentCache-DhQTqi2E.d.ts +18 -0
  5. package/dist/bootstrap.d.mts +95 -0
  6. package/dist/bootstrap.d.ts +95 -0
  7. package/dist/bootstrap.js +2473 -0
  8. package/dist/bootstrap.js.map +1 -0
  9. package/dist/bootstrap.mjs +64 -0
  10. package/dist/bootstrap.mjs.map +1 -0
  11. package/dist/chunk-4BMWVN25.mjs +91 -0
  12. package/dist/chunk-4BMWVN25.mjs.map +1 -0
  13. package/dist/chunk-4XYXJYN5.mjs +1513 -0
  14. package/dist/chunk-4XYXJYN5.mjs.map +1 -0
  15. package/dist/chunk-5HM6UA2K.mjs +571 -0
  16. package/dist/chunk-5HM6UA2K.mjs.map +1 -0
  17. package/dist/chunk-6LXF3JVX.mjs +96 -0
  18. package/dist/chunk-6LXF3JVX.mjs.map +1 -0
  19. package/dist/chunk-FF6ZZZXH.mjs +71 -0
  20. package/dist/chunk-FF6ZZZXH.mjs.map +1 -0
  21. package/dist/chunk-KOXF2FZM.mjs +92 -0
  22. package/dist/chunk-KOXF2FZM.mjs.map +1 -0
  23. package/dist/chunk-L4V7OCJ3.mjs +71 -0
  24. package/dist/chunk-L4V7OCJ3.mjs.map +1 -0
  25. package/dist/chunk-TZXWVYYR.mjs +67 -0
  26. package/dist/chunk-TZXWVYYR.mjs.map +1 -0
  27. package/dist/chunk-VQJPSLHP.mjs +1801 -0
  28. package/dist/chunk-VQJPSLHP.mjs.map +1 -0
  29. package/dist/chunk-WMJKH4XE.mjs +34 -0
  30. package/dist/chunk-WMJKH4XE.mjs.map +1 -0
  31. package/dist/chunk-XQSY6MHP.mjs +213 -0
  32. package/dist/chunk-XQSY6MHP.mjs.map +1 -0
  33. package/dist/createBridge.mjs +2 -0
  34. package/dist/createBridge.mjs.map +1 -1
  35. package/dist/device/createDeviceProvider.d.mts +23 -0
  36. package/dist/device/createDeviceProvider.d.ts +23 -0
  37. package/dist/device/createDeviceProvider.js +967 -0
  38. package/dist/device/createDeviceProvider.js.map +1 -0
  39. package/dist/device/createDeviceProvider.mjs +17 -0
  40. package/dist/device/createDeviceProvider.mjs.map +1 -0
  41. package/dist/device-bridge/collectors/appEngagement.d.mts +10 -0
  42. package/dist/device-bridge/collectors/appEngagement.d.ts +10 -0
  43. package/dist/device-bridge/collectors/appEngagement.js +128 -0
  44. package/dist/device-bridge/collectors/appEngagement.js.map +1 -0
  45. package/dist/device-bridge/collectors/appEngagement.mjs +12 -0
  46. package/dist/device-bridge/collectors/appEngagement.mjs.map +1 -0
  47. package/dist/device-bridge/collectors/health.d.mts +24 -0
  48. package/dist/device-bridge/collectors/health.d.ts +24 -0
  49. package/dist/device-bridge/collectors/health.js +238 -0
  50. package/dist/device-bridge/collectors/health.js.map +1 -0
  51. package/dist/device-bridge/collectors/health.mjs +18 -0
  52. package/dist/device-bridge/collectors/health.mjs.map +1 -0
  53. package/dist/device-bridge/cookies.d.mts +49 -0
  54. package/dist/device-bridge/cookies.d.ts +49 -0
  55. package/dist/device-bridge/cookies.js +90 -0
  56. package/dist/device-bridge/cookies.js.map +1 -0
  57. package/dist/device-bridge/cookies.mjs +14 -0
  58. package/dist/device-bridge/cookies.mjs.map +1 -0
  59. package/dist/device-bridge/index.d.mts +483 -0
  60. package/dist/device-bridge/index.d.ts +483 -0
  61. package/dist/device-bridge/index.js +2084 -0
  62. package/dist/device-bridge/index.js.map +1 -0
  63. package/dist/device-bridge/index.mjs +32 -0
  64. package/dist/device-bridge/index.mjs.map +1 -0
  65. package/dist/device-bridge/nfc.d.mts +30 -0
  66. package/dist/device-bridge/nfc.d.ts +30 -0
  67. package/dist/device-bridge/nfc.js +109 -0
  68. package/dist/device-bridge/nfc.js.map +1 -0
  69. package/dist/device-bridge/nfc.mjs +14 -0
  70. package/dist/device-bridge/nfc.mjs.map +1 -0
  71. package/dist/index.d.mts +493 -18
  72. package/dist/index.d.ts +493 -18
  73. package/dist/index.js +1409 -6
  74. package/dist/index.js.map +1 -1
  75. package/dist/index.mjs +23 -194
  76. package/dist/index.mjs.map +1 -1
  77. package/dist/oauth/expoOAuth.d.mts +18 -0
  78. package/dist/oauth/expoOAuth.d.ts +18 -0
  79. package/dist/oauth/expoOAuth.js +102 -0
  80. package/dist/oauth/expoOAuth.js.map +1 -0
  81. package/dist/oauth/expoOAuth.mjs +8 -0
  82. package/dist/oauth/expoOAuth.mjs.map +1 -0
  83. package/dist/types-BRanJYTn.d.mts +138 -0
  84. package/dist/types-BRanJYTn.d.ts +138 -0
  85. package/dist/vision/index.d.mts +81 -0
  86. package/dist/vision/index.d.ts +81 -0
  87. package/dist/vision/index.js +101 -0
  88. package/dist/vision/index.js.map +1 -0
  89. package/dist/vision/index.mjs +28 -0
  90. package/dist/vision/index.mjs.map +1 -0
  91. package/expo-module.config.json +9 -0
  92. package/ios/AdaVision.podspec +28 -0
  93. package/ios/AdaVisionModule.swift +432 -0
  94. package/ios/Resources/yolov8n-oiv7.mlmodelc/analytics/coremldata.bin +0 -0
  95. package/ios/Resources/yolov8n-oiv7.mlmodelc/coremldata.bin +0 -0
  96. package/ios/Resources/yolov8n-oiv7.mlmodelc/metadata.json +773 -0
  97. package/ios/Resources/yolov8n-oiv7.mlmodelc/model0/analytics/coremldata.bin +0 -0
  98. package/ios/Resources/yolov8n-oiv7.mlmodelc/model0/coremldata.bin +0 -0
  99. package/ios/Resources/yolov8n-oiv7.mlmodelc/model0/model.mil +720 -0
  100. package/ios/Resources/yolov8n-oiv7.mlmodelc/model0/weights/weight.bin +0 -0
  101. package/ios/Resources/yolov8n-oiv7.mlmodelc/model1/coremldata.bin +0 -0
  102. package/package.json +107 -7
  103. package/src/bootstrap.ts +159 -0
  104. package/src/camera/CameraTaskHost.tsx +175 -0
  105. package/src/camera/cameraTasks.ts +129 -0
  106. package/src/device/createDeviceProvider.ts +832 -0
  107. package/src/device-bridge/actions/calendar-actions.ts +217 -0
  108. package/src/device-bridge/actions/dnd.ts +74 -0
  109. package/src/device-bridge/actions/health-actions.ts +58 -0
  110. package/src/device-bridge/actions/index.ts +12 -0
  111. package/src/device-bridge/actions/messaging.ts +74 -0
  112. package/src/device-bridge/actions/navigation.ts +88 -0
  113. package/src/device-bridge/actions/queue-poller.ts +151 -0
  114. package/src/device-bridge/background.ts +137 -0
  115. package/src/device-bridge/biometrics.ts +64 -0
  116. package/src/device-bridge/capabilities.ts +218 -0
  117. package/src/device-bridge/collectors/appEngagement.ts +120 -0
  118. package/src/device-bridge/collectors/battery.ts +83 -0
  119. package/src/device-bridge/collectors/calendar.ts +162 -0
  120. package/src/device-bridge/collectors/camera.ts +27 -0
  121. package/src/device-bridge/collectors/connectivity.ts +60 -0
  122. package/src/device-bridge/collectors/contacts.ts +200 -0
  123. package/src/device-bridge/collectors/health.ts +299 -0
  124. package/src/device-bridge/collectors/index.ts +12 -0
  125. package/src/device-bridge/collectors/location.ts +224 -0
  126. package/src/device-bridge/collectors/mood.ts +141 -0
  127. package/src/device-bridge/collectors/notifications.ts +70 -0
  128. package/src/device-bridge/cookies.ts +89 -0
  129. package/src/device-bridge/dynamic-connector.ts +422 -0
  130. package/src/device-bridge/index.ts +467 -0
  131. package/src/device-bridge/nfc.ts +85 -0
  132. package/src/device-bridge/plugin.ts +71 -0
  133. package/src/device-bridge/relay-client.ts +237 -0
  134. package/src/device-bridge/scanner.ts +42 -0
  135. package/src/device-bridge/sharing.ts +35 -0
  136. package/src/device-bridge/types.ts +326 -0
  137. package/src/device-state/activityClassifier.ts +151 -0
  138. package/src/device-state/activityEngine.ts +252 -0
  139. package/src/device-state/collectors.ts +31 -0
  140. package/src/device-state/domains/activity.ts +93 -0
  141. package/src/device-state/domains/capability.ts +60 -0
  142. package/src/device-state/domains/connectivity.ts +60 -0
  143. package/src/device-state/domains/deviceContext.ts +55 -0
  144. package/src/device-state/domains/interaction.ts +59 -0
  145. package/src/device-state/domains/spatial.ts +283 -0
  146. package/src/device-state/domains/visual.ts +100 -0
  147. package/src/device-state/headingSource.ts +84 -0
  148. package/src/device-state/index.ts +77 -0
  149. package/src/device-state/quality.ts +60 -0
  150. package/src/device-state/replay.ts +220 -0
  151. package/src/device-state/turnDetector.ts +121 -0
  152. package/src/device-state/visualEngine.ts +341 -0
  153. package/src/haptics.ts +4 -0
  154. package/src/index.ts +37 -0
  155. package/src/oauth/expoOAuth.tsx +113 -0
  156. package/src/vision/analysis.js +80 -0
  157. package/src/vision/index.ts +144 -0
  158. package/src/vision/ring.js +35 -0
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/device-bridge/collectors/health.ts
21
+ var health_exports = {};
22
+ __export(health_exports, {
23
+ collectHistory: () => collectHistory,
24
+ collectMoodExtras: () => collectMoodExtras,
25
+ collectToday: () => collectToday,
26
+ hasPermission: () => hasPermission,
27
+ lastHealthInitError: () => lastHealthInitError,
28
+ requestPermission: () => requestPermission
29
+ });
30
+ module.exports = __toCommonJS(health_exports);
31
+ var import_react_native = require("react-native");
32
+ var _HK = null;
33
+ var _hkProbed = false;
34
+ function getHK() {
35
+ if (import_react_native.Platform.OS !== "ios") return null;
36
+ if (_hkProbed) return _HK;
37
+ _hkProbed = true;
38
+ try {
39
+ const mod = require("@kingstinct/react-native-healthkit");
40
+ if (mod && typeof mod.requestAuthorization === "function") {
41
+ _HK = mod;
42
+ } else {
43
+ console.warn("[health] @kingstinct/react-native-healthkit native bridge unavailable \u2014 HealthKit disabled (Expo Go?)");
44
+ }
45
+ } catch (e) {
46
+ console.warn("[health] @kingstinct/react-native-healthkit require failed:", e);
47
+ }
48
+ return _HK;
49
+ }
50
+ var lastHealthInitError = null;
51
+ var READ_TYPES = [
52
+ "HKQuantityTypeIdentifierStepCount",
53
+ "HKQuantityTypeIdentifierFlightsClimbed",
54
+ "HKQuantityTypeIdentifierActiveEnergyBurned",
55
+ "HKQuantityTypeIdentifierDistanceWalkingRunning",
56
+ // Added for mood signals — all read-only, covered by the same auth sheet.
57
+ "HKQuantityTypeIdentifierRestingHeartRate",
58
+ "HKQuantityTypeIdentifierAppleExerciseTime",
59
+ "HKCategoryTypeIdentifierSleepAnalysis"
60
+ ];
61
+ var _initPromise = null;
62
+ async function ensureInit() {
63
+ const HK = getHK();
64
+ if (!HK) {
65
+ lastHealthInitError = "@kingstinct/react-native-healthkit native module not loaded";
66
+ return false;
67
+ }
68
+ if (_initPromise) return _initPromise;
69
+ _initPromise = (async () => {
70
+ try {
71
+ await HK.requestAuthorization({ toRead: READ_TYPES, toWrite: [] });
72
+ lastHealthInitError = null;
73
+ return true;
74
+ } catch (e) {
75
+ lastHealthInitError = `requestAuthorization threw: ${e?.message || String(e)}`;
76
+ console.warn("[health]", lastHealthInitError);
77
+ _initPromise = null;
78
+ return false;
79
+ }
80
+ })();
81
+ return _initPromise;
82
+ }
83
+ async function hasPermission() {
84
+ return ensureInit();
85
+ }
86
+ async function requestPermission() {
87
+ return ensureInit();
88
+ }
89
+ function startOfDay(d) {
90
+ const out = new Date(d);
91
+ out.setHours(0, 0, 0, 0);
92
+ return out;
93
+ }
94
+ function dateKey(d) {
95
+ const y = d.getFullYear();
96
+ const m = String(d.getMonth() + 1).padStart(2, "0");
97
+ const day = String(d.getDate()).padStart(2, "0");
98
+ return `${y}-${m}-${day}`;
99
+ }
100
+ async function readDailySum(identifier, unit, start, end) {
101
+ const HK = getHK();
102
+ if (!HK?.queryStatisticsForQuantity) return 0;
103
+ try {
104
+ const result = await HK.queryStatisticsForQuantity(
105
+ identifier,
106
+ ["cumulativeSum"],
107
+ {
108
+ unit,
109
+ filter: { date: { startDate: start, endDate: end } }
110
+ }
111
+ );
112
+ const q = result?.sumQuantity?.quantity;
113
+ return typeof q === "number" ? q : 0;
114
+ } catch {
115
+ return 0;
116
+ }
117
+ }
118
+ async function readDailyAverage(identifier, unit, start, end) {
119
+ const HK = getHK();
120
+ if (!HK?.queryStatisticsForQuantity) return null;
121
+ try {
122
+ const result = await HK.queryStatisticsForQuantity(
123
+ identifier,
124
+ ["discreteAverage"],
125
+ { unit, filter: { date: { startDate: start, endDate: end } } }
126
+ );
127
+ const q = result?.averageQuantity?.quantity;
128
+ return typeof q === "number" ? q : null;
129
+ } catch {
130
+ return null;
131
+ }
132
+ }
133
+ async function readSleepMinutes(start, end) {
134
+ const HK = getHK();
135
+ const query = HK?.queryCategorySamples || HK?.queryCategorySamplesAsync || HK?.querySamples;
136
+ if (!query) return null;
137
+ try {
138
+ const samples = await query.call(
139
+ HK,
140
+ "HKCategoryTypeIdentifierSleepAnalysis",
141
+ { filter: { date: { startDate: start, endDate: end } } }
142
+ );
143
+ if (!Array.isArray(samples) || samples.length === 0) return null;
144
+ let ms = 0;
145
+ for (const s of samples) {
146
+ const v = s?.value;
147
+ const isAsleep = v !== 0 && v !== 2;
148
+ if (!isAsleep) continue;
149
+ const a = new Date(s?.startDate).getTime();
150
+ const b = new Date(s?.endDate).getTime();
151
+ if (Number.isFinite(a) && Number.isFinite(b) && b > a) ms += b - a;
152
+ }
153
+ return ms > 0 ? Math.round(ms / 6e4) : null;
154
+ } catch {
155
+ return null;
156
+ }
157
+ }
158
+ async function collectMoodExtras() {
159
+ const ok = await ensureInit();
160
+ if (!ok) return { sleep_min: null, resting_hr: null, active_energy_kcal: null, exercise_min: null };
161
+ const start = startOfDay(/* @__PURE__ */ new Date());
162
+ const end = new Date(start);
163
+ end.setDate(end.getDate() + 1);
164
+ const sleepStart = new Date(start);
165
+ sleepStart.setHours(sleepStart.getHours() - 6);
166
+ const [sleep_min, resting_hr, energy, exercise] = await Promise.all([
167
+ readSleepMinutes(sleepStart, end),
168
+ readDailyAverage("HKQuantityTypeIdentifierRestingHeartRate", "count/min", start, end),
169
+ readDailySum("HKQuantityTypeIdentifierActiveEnergyBurned", "kcal", start, end),
170
+ readDailySum("HKQuantityTypeIdentifierAppleExerciseTime", "min", start, end)
171
+ ]);
172
+ return {
173
+ sleep_min,
174
+ resting_hr: resting_hr != null ? Math.round(resting_hr) : null,
175
+ active_energy_kcal: energy ? Math.round(energy) : null,
176
+ exercise_min: exercise ? Math.round(exercise) : null
177
+ };
178
+ }
179
+ async function readDay(date) {
180
+ const start = startOfDay(date);
181
+ const end = new Date(start);
182
+ end.setDate(end.getDate() + 1);
183
+ const [steps, floors, energy, distance] = await Promise.all([
184
+ readDailySum("HKQuantityTypeIdentifierStepCount", "count", start, end),
185
+ readDailySum("HKQuantityTypeIdentifierFlightsClimbed", "count", start, end),
186
+ readDailySum("HKQuantityTypeIdentifierActiveEnergyBurned", "kcal", start, end),
187
+ // Ask for kilometers directly so we don't have to convert from meters.
188
+ readDailySum("HKQuantityTypeIdentifierDistanceWalkingRunning", "km", start, end)
189
+ ]);
190
+ return {
191
+ date: dateKey(start),
192
+ available: true,
193
+ steps: Math.round(steps),
194
+ floors: Math.round(floors),
195
+ active_energy_kcal: Math.round(energy),
196
+ distance_km: Math.round(distance * 100) / 100
197
+ };
198
+ }
199
+ function unavailableDay(date) {
200
+ return {
201
+ date: dateKey(date),
202
+ available: false,
203
+ steps: null,
204
+ floors: null,
205
+ active_energy_kcal: null,
206
+ distance_km: null
207
+ };
208
+ }
209
+ async function collectToday() {
210
+ const ok = await ensureInit();
211
+ if (!ok) {
212
+ return unavailableDay(/* @__PURE__ */ new Date());
213
+ }
214
+ return readDay(/* @__PURE__ */ new Date());
215
+ }
216
+ async function collectHistory(days) {
217
+ const n = Math.max(1, Math.min(30, Math.floor(days)));
218
+ const ok = await ensureInit();
219
+ if (!ok) return [];
220
+ const today = startOfDay(/* @__PURE__ */ new Date());
221
+ const out = [];
222
+ for (let i = 0; i < n; i++) {
223
+ const d = new Date(today);
224
+ d.setDate(d.getDate() - i);
225
+ out.push(await readDay(d));
226
+ }
227
+ return out;
228
+ }
229
+ // Annotate the CommonJS export names for ESM import in node:
230
+ 0 && (module.exports = {
231
+ collectHistory,
232
+ collectMoodExtras,
233
+ collectToday,
234
+ hasPermission,
235
+ lastHealthInitError,
236
+ requestPermission
237
+ });
238
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/device-bridge/collectors/health.ts"],"sourcesContent":["/**\n * Health Collector — reads HealthKit aggregates via @kingstinct/react-native-healthkit\n * (TurboModule / Nitro-Modules based; works in React Native's New Architecture).\n *\n * iOS only. On Android the functions resolve with zeros so the caller doesn't\n * need to platform-check.\n *\n * Public:\n * - hasPermission() — returns true once authorization has been requested.\n * - requestPermission() — triggers the iOS HealthKit permission sheet (red heart).\n * - collectToday() — one HealthDayMetrics for today.\n * - collectHistory(days) — array of HealthDayMetrics, newest-first.\n */\nimport { Platform } from 'react-native';\nimport type { HealthDayMetrics } from '../types';\n\n// Lazy-loaded so the module is harmless on Android / Expo Go / non-iOS.\n// In Expo Go the JS module resolves but the native bridge is missing —\n// resulting object exists yet methods like requestAuthorization are undefined.\nlet _HK: any = null;\nlet _hkProbed = false;\nfunction getHK(): any | null {\n if (Platform.OS !== 'ios') return null;\n if (_hkProbed) return _HK;\n _hkProbed = true;\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const mod = require('@kingstinct/react-native-healthkit');\n if (mod && typeof mod.requestAuthorization === 'function') {\n _HK = mod;\n } else {\n console.warn('[health] @kingstinct/react-native-healthkit native bridge unavailable — HealthKit disabled (Expo Go?)');\n }\n } catch (e) {\n console.warn('[health] @kingstinct/react-native-healthkit require failed:', e);\n }\n return _HK;\n}\n\n// Last error from requestAuthorization — surfaced to UI so we don't fail silently.\nexport let lastHealthInitError: string | null = null;\n\nconst READ_TYPES = [\n 'HKQuantityTypeIdentifierStepCount',\n 'HKQuantityTypeIdentifierFlightsClimbed',\n 'HKQuantityTypeIdentifierActiveEnergyBurned',\n 'HKQuantityTypeIdentifierDistanceWalkingRunning',\n // Added for mood signals — all read-only, covered by the same auth sheet.\n 'HKQuantityTypeIdentifierRestingHeartRate',\n 'HKQuantityTypeIdentifierAppleExerciseTime',\n 'HKCategoryTypeIdentifierSleepAnalysis',\n] as const;\n\nlet _initPromise: Promise<boolean> | null = null;\n\n/** Request HealthKit authorization once; subsequent calls reuse the result. */\nasync function ensureInit(): Promise<boolean> {\n const HK = getHK();\n if (!HK) {\n lastHealthInitError = '@kingstinct/react-native-healthkit native module not loaded';\n return false;\n }\n if (_initPromise) return _initPromise;\n _initPromise = (async () => {\n try {\n // requestAuthorization triggers the iOS HealthKit permission sheet.\n // Resolves once the user dismisses it (regardless of allow/deny).\n // Returns the authorization status — but iOS deliberately does not\n // disclose per-type read permission state for privacy, so we just\n // treat \"we asked\" as \"ready to read\" and let reads return 0 if denied.\n await HK.requestAuthorization({ toRead: READ_TYPES, toWrite: [] });\n lastHealthInitError = null;\n return true;\n } catch (e: any) {\n lastHealthInitError = `requestAuthorization threw: ${e?.message || String(e)}`;\n console.warn('[health]', lastHealthInitError);\n _initPromise = null;\n return false;\n }\n })();\n return _initPromise;\n}\n\nexport async function hasPermission(): Promise<boolean> {\n return ensureInit();\n}\n\nexport async function requestPermission(): Promise<boolean> {\n return ensureInit();\n}\n\n// ─── Helpers ────────────────────────────────────────────────\n\nfunction startOfDay(d: Date): Date {\n const out = new Date(d);\n out.setHours(0, 0, 0, 0);\n return out;\n}\n\nfunction dateKey(d: Date): string {\n // Local-date YYYY-MM-DD\n const y = d.getFullYear();\n const m = String(d.getMonth() + 1).padStart(2, '0');\n const day = String(d.getDate()).padStart(2, '0');\n return `${y}-${m}-${day}`;\n}\n\n/**\n * Read a single daily-aggregate sum for [start, end) in the given unit.\n * Returns 0 when no data, HealthKit unavailable, or the call throws.\n *\n * `queryStatisticsForQuantity` is the modern statistics API; we ask only for\n * the cumulative sum since that's what we need for these data types.\n */\nasync function readDailySum(identifier: string, unit: string, start: Date, end: Date): Promise<number> {\n const HK = getHK();\n if (!HK?.queryStatisticsForQuantity) return 0;\n try {\n // The kingstinct API takes the date range nested under filter.date — not\n // top-level from/to. Without filter.date the call returns the cumulative\n // sum across ALL historical data, which is what we hit before this fix\n // (millions of steps, thousands of km, hundreds of thousands of kcal).\n const result: any = await HK.queryStatisticsForQuantity(\n identifier,\n ['cumulativeSum'],\n {\n unit,\n filter: { date: { startDate: start, endDate: end } },\n },\n );\n const q = result?.sumQuantity?.quantity;\n return typeof q === 'number' ? q : 0;\n } catch {\n return 0;\n }\n}\n\n/**\n * Daily discrete-average for a quantity (e.g. resting heart rate). Returns\n * null when no sample exists for the day so the backend can tell \"no data\"\n * apart from a real zero.\n */\nasync function readDailyAverage(identifier: string, unit: string, start: Date, end: Date): Promise<number | null> {\n const HK = getHK();\n if (!HK?.queryStatisticsForQuantity) return null;\n try {\n const result: any = await HK.queryStatisticsForQuantity(\n identifier,\n ['discreteAverage'],\n { unit, filter: { date: { startDate: start, endDate: end } } },\n );\n const q = result?.averageQuantity?.quantity;\n return typeof q === 'number' ? q : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Total minutes asleep for [start, end) from HKCategoryTypeIdentifierSleepAnalysis.\n * Sums sample durations that represent actual sleep (any \"asleep*\" value),\n * excluding inBed/awake. Heavily guarded — sleep-stage enums differ across iOS\n * versions and the kingstinct API surface, so any failure returns null.\n */\nasync function readSleepMinutes(start: Date, end: Date): Promise<number | null> {\n const HK = getHK();\n const query = HK?.queryCategorySamples || HK?.queryCategorySamplesAsync || HK?.querySamples;\n if (!query) return null;\n try {\n const samples: any[] = await query.call(\n HK,\n 'HKCategoryTypeIdentifierSleepAnalysis',\n { filter: { date: { startDate: start, endDate: end } } },\n );\n if (!Array.isArray(samples) || samples.length === 0) return null;\n // value semantics: 0 = inBed, 2 = awake; everything else = a sleep stage.\n // Treat anything that isn't explicitly inBed/awake as asleep.\n let ms = 0;\n for (const s of samples) {\n const v = s?.value;\n const isAsleep = v !== 0 && v !== 2; // exclude inBed + awake\n if (!isAsleep) continue;\n const a = new Date(s?.startDate).getTime();\n const b = new Date(s?.endDate).getTime();\n if (Number.isFinite(a) && Number.isFinite(b) && b > a) ms += b - a;\n }\n return ms > 0 ? Math.round(ms / 60000) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Mood-relevant HealthKit extras for today: sleep minutes, resting heart rate,\n * active energy (kcal), exercise minutes. Each is null when unavailable so the\n * backend weights only present fields.\n */\nexport async function collectMoodExtras(): Promise<{\n sleep_min: number | null;\n resting_hr: number | null;\n active_energy_kcal: number | null;\n exercise_min: number | null;\n}> {\n const ok = await ensureInit();\n if (!ok) return { sleep_min: null, resting_hr: null, active_energy_kcal: null, exercise_min: null };\n const start = startOfDay(new Date());\n const end = new Date(start);\n end.setDate(end.getDate() + 1);\n // Sleep window: look back from this morning over the past night (~last 18h)\n // so an evening collection still captures the prior night.\n const sleepStart = new Date(start);\n sleepStart.setHours(sleepStart.getHours() - 6); // include after-midnight + prev evening within today's window\n const [sleep_min, resting_hr, energy, exercise] = await Promise.all([\n readSleepMinutes(sleepStart, end),\n readDailyAverage('HKQuantityTypeIdentifierRestingHeartRate', 'count/min', start, end),\n readDailySum('HKQuantityTypeIdentifierActiveEnergyBurned', 'kcal', start, end),\n readDailySum('HKQuantityTypeIdentifierAppleExerciseTime', 'min', start, end),\n ]);\n return {\n sleep_min,\n resting_hr: resting_hr != null ? Math.round(resting_hr) : null,\n active_energy_kcal: energy ? Math.round(energy) : null,\n exercise_min: exercise ? Math.round(exercise) : null,\n };\n}\n\nasync function readDay(date: Date): Promise<HealthDayMetrics> {\n const start = startOfDay(date);\n const end = new Date(start);\n end.setDate(end.getDate() + 1);\n\n const [steps, floors, energy, distance] = await Promise.all([\n readDailySum('HKQuantityTypeIdentifierStepCount', 'count', start, end),\n readDailySum('HKQuantityTypeIdentifierFlightsClimbed', 'count', start, end),\n readDailySum('HKQuantityTypeIdentifierActiveEnergyBurned', 'kcal', start, end),\n // Ask for kilometers directly so we don't have to convert from meters.\n readDailySum('HKQuantityTypeIdentifierDistanceWalkingRunning', 'km', start, end),\n ]);\n\n return {\n date: dateKey(start),\n available: true,\n steps: Math.round(steps),\n floors: Math.round(floors),\n active_energy_kcal: Math.round(energy),\n distance_km: Math.round(distance * 100) / 100,\n };\n}\n\n// ─── Public API ─────────────────────────────────────────────\n\n/**\n * A day we could not read: metrics null, availability stated.\n *\n * The distinction this preserves is the whole point — \"no data\" and \"a day\n * with no activity\" look identical once you write a zero, and only one of\n * them is something to tell the user about.\n */\nfunction unavailableDay(date: Date): HealthDayMetrics {\n return {\n date: dateKey(date),\n available: false,\n steps: null,\n floors: null,\n active_energy_kcal: null,\n distance_km: null,\n };\n}\n\nexport async function collectToday(): Promise<HealthDayMetrics> {\n const ok = await ensureInit();\n if (!ok) {\n // HealthKit unavailable or access denied. NOT a day with no activity —\n // reporting zeros here is how \"you have taken 0 steps today\" reached the\n // user as a fact, with a coaching skill ready to act on it.\n return unavailableDay(new Date());\n }\n return readDay(new Date());\n}\n\n/**\n * Last `days` days, newest-first. Index 0 is today.\n * Caller passes 1..30 — we clamp defensively.\n */\nexport async function collectHistory(days: number): Promise<HealthDayMetrics[]> {\n const n = Math.max(1, Math.min(30, Math.floor(days)));\n const ok = await ensureInit();\n if (!ok) return [];\n\n const today = startOfDay(new Date());\n const out: HealthDayMetrics[] = [];\n // Sequential to avoid hammering HealthKit with 30 parallel queries.\n for (let i = 0; i < n; i++) {\n const d = new Date(today);\n d.setDate(d.getDate() - i);\n out.push(await readDay(d));\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,0BAAyB;AAMzB,IAAI,MAAW;AACf,IAAI,YAAY;AAChB,SAAS,QAAoB;AAC3B,MAAI,6BAAS,OAAO,MAAO,QAAO;AAClC,MAAI,UAAW,QAAO;AACtB,cAAY;AACZ,MAAI;AAEF,UAAM,MAAM,QAAQ,oCAAoC;AACxD,QAAI,OAAO,OAAO,IAAI,yBAAyB,YAAY;AACzD,YAAM;AAAA,IACR,OAAO;AACL,cAAQ,KAAK,4GAAuG;AAAA,IACtH;AAAA,EACF,SAAS,GAAG;AACV,YAAQ,KAAK,+DAA+D,CAAC;AAAA,EAC/E;AACA,SAAO;AACT;AAGO,IAAI,sBAAqC;AAEhD,IAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAI,eAAwC;AAG5C,eAAe,aAA+B;AAC5C,QAAM,KAAK,MAAM;AACjB,MAAI,CAAC,IAAI;AACP,0BAAsB;AACtB,WAAO;AAAA,EACT;AACA,MAAI,aAAc,QAAO;AACzB,kBAAgB,YAAY;AAC1B,QAAI;AAMF,YAAM,GAAG,qBAAqB,EAAE,QAAQ,YAAY,SAAS,CAAC,EAAE,CAAC;AACjE,4BAAsB;AACtB,aAAO;AAAA,IACT,SAAS,GAAQ;AACf,4BAAsB,+BAA+B,GAAG,WAAW,OAAO,CAAC,CAAC;AAC5E,cAAQ,KAAK,YAAY,mBAAmB;AAC5C,qBAAe;AACf,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AACH,SAAO;AACT;AAEA,eAA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EA,eAAsB,eAA0C;AAC9D,QAAM,KAAK,MAAM,WAAW;AAC5B,MAAI,CAAC,IAAI;AAIP,WAAO,eAAe,oBAAI,KAAK,CAAC;AAAA,EAClC;AACA,SAAO,QAAQ,oBAAI,KAAK,CAAC;AAC3B;AAMA,eAAsB,eAAe,MAA2C;AAC9E,QAAM,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC;AACpD,QAAM,KAAK,MAAM,WAAW;AAC5B,MAAI,CAAC,GAAI,QAAO,CAAC;AAEjB,QAAM,QAAQ,WAAW,oBAAI,KAAK,CAAC;AACnC,QAAM,MAA0B,CAAC;AAEjC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,UAAM,IAAI,IAAI,KAAK,KAAK;AACxB,MAAE,QAAQ,EAAE,QAAQ,IAAI,CAAC;AACzB,QAAI,KAAK,MAAM,QAAQ,CAAC,CAAC;AAAA,EAC3B;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,18 @@
1
+ import {
2
+ collectHistory,
3
+ collectMoodExtras,
4
+ collectToday,
5
+ hasPermission,
6
+ lastHealthInitError,
7
+ requestPermission
8
+ } from "../../chunk-XQSY6MHP.mjs";
9
+ import "../../chunk-WMJKH4XE.mjs";
10
+ export {
11
+ collectHistory,
12
+ collectMoodExtras,
13
+ collectToday,
14
+ hasPermission,
15
+ lastHealthInitError,
16
+ requestPermission
17
+ };
18
+ //# sourceMappingURL=health.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Device-bridge: Cookies API
3
+ *
4
+ * Reads the platform's shared cookie jar (NSHTTPCookieStorage on iOS,
5
+ * CookieManager on Android) so upper layers (plugin-sdk → RN plugins) can
6
+ * extract session cookies captured during a native WebView login flow.
7
+ *
8
+ * Wraps `@react-native-cookies/cookies` so upper layers never import the
9
+ * native module directly. If we swap implementations, only this file changes.
10
+ *
11
+ * Why device-bridge owns this: cookies are a device-level capability (tied
12
+ * to the platform's shared HTTP stack). Plugins should consume a clean
13
+ * abstraction; the native wiring lives here.
14
+ */
15
+ interface DeviceCookie {
16
+ name: string;
17
+ value: string;
18
+ domain?: string;
19
+ path?: string;
20
+ /** Unix seconds. Omitted for session cookies. */
21
+ expires?: number;
22
+ httpOnly?: boolean;
23
+ secure?: boolean;
24
+ sameSite?: 'Lax' | 'Strict' | 'None';
25
+ }
26
+ /**
27
+ * Get every cookie attached to the URL's effective domain.
28
+ * Set `includeHttpOnly` true to include HttpOnly cookies (required for
29
+ * LinkedIn/Google session tokens).
30
+ */
31
+ declare function get(url: string, includeHttpOnly?: boolean): Promise<DeviceCookie[]>;
32
+ /**
33
+ * Wipe the shared cookie jar. Cross-platform scoped clear isn't supported
34
+ * uniformly; `clearAll` is the safe operation on both iOS and Android.
35
+ */
36
+ declare function clearAll(): Promise<{
37
+ ok: boolean;
38
+ error?: string;
39
+ }>;
40
+ /**
41
+ * Set a cookie programmatically. Useful when replaying a saved session on
42
+ * the device's shared jar before opening a WebView.
43
+ */
44
+ declare function set(url: string, cookie: DeviceCookie): Promise<{
45
+ ok: boolean;
46
+ error?: string;
47
+ }>;
48
+
49
+ export { type DeviceCookie, clearAll, get, set };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Device-bridge: Cookies API
3
+ *
4
+ * Reads the platform's shared cookie jar (NSHTTPCookieStorage on iOS,
5
+ * CookieManager on Android) so upper layers (plugin-sdk → RN plugins) can
6
+ * extract session cookies captured during a native WebView login flow.
7
+ *
8
+ * Wraps `@react-native-cookies/cookies` so upper layers never import the
9
+ * native module directly. If we swap implementations, only this file changes.
10
+ *
11
+ * Why device-bridge owns this: cookies are a device-level capability (tied
12
+ * to the platform's shared HTTP stack). Plugins should consume a clean
13
+ * abstraction; the native wiring lives here.
14
+ */
15
+ interface DeviceCookie {
16
+ name: string;
17
+ value: string;
18
+ domain?: string;
19
+ path?: string;
20
+ /** Unix seconds. Omitted for session cookies. */
21
+ expires?: number;
22
+ httpOnly?: boolean;
23
+ secure?: boolean;
24
+ sameSite?: 'Lax' | 'Strict' | 'None';
25
+ }
26
+ /**
27
+ * Get every cookie attached to the URL's effective domain.
28
+ * Set `includeHttpOnly` true to include HttpOnly cookies (required for
29
+ * LinkedIn/Google session tokens).
30
+ */
31
+ declare function get(url: string, includeHttpOnly?: boolean): Promise<DeviceCookie[]>;
32
+ /**
33
+ * Wipe the shared cookie jar. Cross-platform scoped clear isn't supported
34
+ * uniformly; `clearAll` is the safe operation on both iOS and Android.
35
+ */
36
+ declare function clearAll(): Promise<{
37
+ ok: boolean;
38
+ error?: string;
39
+ }>;
40
+ /**
41
+ * Set a cookie programmatically. Useful when replaying a saved session on
42
+ * the device's shared jar before opening a WebView.
43
+ */
44
+ declare function set(url: string, cookie: DeviceCookie): Promise<{
45
+ ok: boolean;
46
+ error?: string;
47
+ }>;
48
+
49
+ export { type DeviceCookie, clearAll, get, set };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/device-bridge/cookies.ts
31
+ var cookies_exports = {};
32
+ __export(cookies_exports, {
33
+ clearAll: () => clearAll,
34
+ get: () => get,
35
+ set: () => set
36
+ });
37
+ module.exports = __toCommonJS(cookies_exports);
38
+ var import_cookies = __toESM(require("@react-native-cookies/cookies"));
39
+ async function get(url, includeHttpOnly = true) {
40
+ const raw = await import_cookies.default.get(url, includeHttpOnly);
41
+ const out = [];
42
+ for (const [name, c] of Object.entries(raw || {})) {
43
+ if (!c || typeof c !== "object") continue;
44
+ const value = typeof c.value === "string" ? c.value : String(c.value ?? "");
45
+ const cookie = { name, value };
46
+ if (c.domain) cookie.domain = String(c.domain);
47
+ if (c.path) cookie.path = String(c.path);
48
+ if (c.expires) {
49
+ const t = Date.parse(c.expires);
50
+ if (!Number.isNaN(t)) cookie.expires = Math.floor(t / 1e3);
51
+ }
52
+ if (typeof c.httpOnly === "boolean") cookie.httpOnly = c.httpOnly;
53
+ if (typeof c.secure === "boolean") cookie.secure = c.secure;
54
+ if (c.sameSite === "Lax" || c.sameSite === "Strict" || c.sameSite === "None") {
55
+ cookie.sameSite = c.sameSite;
56
+ }
57
+ out.push(cookie);
58
+ }
59
+ return out;
60
+ }
61
+ async function clearAll() {
62
+ try {
63
+ await import_cookies.default.clearAll(true);
64
+ return { ok: true };
65
+ } catch (e) {
66
+ return { ok: false, error: String(e?.message || e) };
67
+ }
68
+ }
69
+ async function set(url, cookie) {
70
+ try {
71
+ await import_cookies.default.set(url, {
72
+ name: cookie.name,
73
+ value: cookie.value,
74
+ domain: cookie.domain,
75
+ path: cookie.path || "/",
76
+ httpOnly: cookie.httpOnly,
77
+ secure: cookie.secure
78
+ }, true);
79
+ return { ok: true };
80
+ } catch (e) {
81
+ return { ok: false, error: String(e?.message || e) };
82
+ }
83
+ }
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ clearAll,
87
+ get,
88
+ set
89
+ });
90
+ //# sourceMappingURL=cookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/device-bridge/cookies.ts"],"sourcesContent":["/**\n * Device-bridge: Cookies API\n *\n * Reads the platform's shared cookie jar (NSHTTPCookieStorage on iOS,\n * CookieManager on Android) so upper layers (plugin-sdk → RN plugins) can\n * extract session cookies captured during a native WebView login flow.\n *\n * Wraps `@react-native-cookies/cookies` so upper layers never import the\n * native module directly. If we swap implementations, only this file changes.\n *\n * Why device-bridge owns this: cookies are a device-level capability (tied\n * to the platform's shared HTTP stack). Plugins should consume a clean\n * abstraction; the native wiring lives here.\n */\n\nimport CookieManager from '@react-native-cookies/cookies';\n\nexport interface DeviceCookie {\n name: string;\n value: string;\n domain?: string;\n path?: string;\n /** Unix seconds. Omitted for session cookies. */\n expires?: number;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: 'Lax' | 'Strict' | 'None';\n}\n\n/**\n * Get every cookie attached to the URL's effective domain.\n * Set `includeHttpOnly` true to include HttpOnly cookies (required for\n * LinkedIn/Google session tokens).\n */\nexport async function get(url: string, includeHttpOnly: boolean = true): Promise<DeviceCookie[]> {\n const raw = (await CookieManager.get(url, includeHttpOnly)) as Record<string, any>;\n const out: DeviceCookie[] = [];\n for (const [name, c] of Object.entries(raw || {})) {\n if (!c || typeof c !== 'object') continue;\n const value = typeof c.value === 'string' ? c.value : String(c.value ?? '');\n const cookie: DeviceCookie = { name, value };\n if (c.domain) cookie.domain = String(c.domain);\n if (c.path) cookie.path = String(c.path);\n if (c.expires) {\n const t = Date.parse(c.expires);\n if (!Number.isNaN(t)) cookie.expires = Math.floor(t / 1000);\n }\n if (typeof c.httpOnly === 'boolean') cookie.httpOnly = c.httpOnly;\n if (typeof c.secure === 'boolean') cookie.secure = c.secure;\n if (c.sameSite === 'Lax' || c.sameSite === 'Strict' || c.sameSite === 'None') {\n cookie.sameSite = c.sameSite;\n }\n out.push(cookie);\n }\n return out;\n}\n\n/**\n * Wipe the shared cookie jar. Cross-platform scoped clear isn't supported\n * uniformly; `clearAll` is the safe operation on both iOS and Android.\n */\nexport async function clearAll(): Promise<{ ok: boolean; error?: string }> {\n try {\n await CookieManager.clearAll(true);\n return { ok: true };\n } catch (e: any) {\n return { ok: false, error: String(e?.message || e) };\n }\n}\n\n/**\n * Set a cookie programmatically. Useful when replaying a saved session on\n * the device's shared jar before opening a WebView.\n */\nexport async function set(url: string, cookie: DeviceCookie): Promise<{ ok: boolean; error?: string }> {\n try {\n await CookieManager.set(url, {\n name: cookie.name,\n value: cookie.value,\n domain: cookie.domain,\n path: cookie.path || '/',\n httpOnly: cookie.httpOnly,\n secure: cookie.secure,\n } as any, true);\n return { ok: true };\n } catch (e: any) {\n return { ok: false, error: String(e?.message || e) };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,qBAA0B;AAmB1B,eAAsB,IAAI,KAAa,kBAA2B,MAA+B;AAC/F,QAAM,MAAO,MAAM,eAAAA,QAAc,IAAI,KAAK,eAAe;AACzD,QAAM,MAAsB,CAAC;AAC7B,aAAW,CAAC,MAAM,CAAC,KAAK,OAAO,QAAQ,OAAO,CAAC,CAAC,GAAG;AACjD,QAAI,CAAC,KAAK,OAAO,MAAM,SAAU;AACjC,UAAM,QAAQ,OAAO,EAAE,UAAU,WAAW,EAAE,QAAQ,OAAO,EAAE,SAAS,EAAE;AAC1E,UAAM,SAAuB,EAAE,MAAM,MAAM;AAC3C,QAAI,EAAE,OAAQ,QAAO,SAAS,OAAO,EAAE,MAAM;AAC7C,QAAI,EAAE,KAAM,QAAO,OAAO,OAAO,EAAE,IAAI;AACvC,QAAI,EAAE,SAAS;AACb,YAAM,IAAI,KAAK,MAAM,EAAE,OAAO;AAC9B,UAAI,CAAC,OAAO,MAAM,CAAC,EAAG,QAAO,UAAU,KAAK,MAAM,IAAI,GAAI;AAAA,IAC5D;AACA,QAAI,OAAO,EAAE,aAAa,UAAW,QAAO,WAAW,EAAE;AACzD,QAAI,OAAO,EAAE,WAAW,UAAW,QAAO,SAAS,EAAE;AACrD,QAAI,EAAE,aAAa,SAAS,EAAE,aAAa,YAAY,EAAE,aAAa,QAAQ;AAC5E,aAAO,WAAW,EAAE;AAAA,IACtB;AACA,QAAI,KAAK,MAAM;AAAA,EACjB;AACA,SAAO;AACT;AAMA,eAAsB,WAAqD;AACzE,MAAI;AACF,UAAM,eAAAA,QAAc,SAAS,IAAI;AACjC,WAAO,EAAE,IAAI,KAAK;AAAA,EACpB,SAAS,GAAQ;AACf,WAAO,EAAE,IAAI,OAAO,OAAO,OAAO,GAAG,WAAW,CAAC,EAAE;AAAA,EACrD;AACF;AAMA,eAAsB,IAAI,KAAa,QAAgE;AACrG,MAAI;AACF,UAAM,eAAAA,QAAc,IAAI,KAAK;AAAA,MAC3B,MAAM,OAAO;AAAA,MACb,OAAO,OAAO;AAAA,MACd,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO,QAAQ;AAAA,MACrB,UAAU,OAAO;AAAA,MACjB,QAAQ,OAAO;AAAA,IACjB,GAAU,IAAI;AACd,WAAO,EAAE,IAAI,KAAK;AAAA,EACpB,SAAS,GAAQ;AACf,WAAO,EAAE,IAAI,OAAO,OAAO,OAAO,GAAG,WAAW,CAAC,EAAE;AAAA,EACrD;AACF;","names":["CookieManager"]}
@@ -0,0 +1,14 @@
1
+ import {
2
+ clearAll,
3
+ get,
4
+ init_cookies,
5
+ set
6
+ } from "../chunk-FF6ZZZXH.mjs";
7
+ import "../chunk-WMJKH4XE.mjs";
8
+ init_cookies();
9
+ export {
10
+ clearAll,
11
+ get,
12
+ set
13
+ };
14
+ //# sourceMappingURL=cookies.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}