@hasna/microservices 0.0.15 → 0.0.17

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 (296) hide show
  1. package/README.md +120 -138
  2. package/bin/index.js +703 -12728
  3. package/bin/mcp.js +250 -9726
  4. package/dist/index.js +170 -9407
  5. package/package.json +25 -25
  6. package/microservices/microservice-ads/package.json +0 -27
  7. package/microservices/microservice-ads/src/cli/index.ts +0 -605
  8. package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
  9. package/microservices/microservice-ads/src/db/database.ts +0 -93
  10. package/microservices/microservice-ads/src/db/migrations.ts +0 -60
  11. package/microservices/microservice-ads/src/index.ts +0 -39
  12. package/microservices/microservice-ads/src/mcp/index.ts +0 -480
  13. package/microservices/microservice-analytics/package.json +0 -27
  14. package/microservices/microservice-analytics/src/cli/index.ts +0 -373
  15. package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
  16. package/microservices/microservice-analytics/src/db/database.ts +0 -93
  17. package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
  18. package/microservices/microservice-analytics/src/index.ts +0 -37
  19. package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
  20. package/microservices/microservice-assets/package.json +0 -27
  21. package/microservices/microservice-assets/src/cli/index.ts +0 -375
  22. package/microservices/microservice-assets/src/db/assets.ts +0 -370
  23. package/microservices/microservice-assets/src/db/database.ts +0 -93
  24. package/microservices/microservice-assets/src/db/migrations.ts +0 -51
  25. package/microservices/microservice-assets/src/index.ts +0 -32
  26. package/microservices/microservice-assets/src/mcp/index.ts +0 -346
  27. package/microservices/microservice-bookkeeping/package.json +0 -27
  28. package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
  29. package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
  30. package/microservices/microservice-bookkeeping/src/db/database.ts +0 -93
  31. package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
  32. package/microservices/microservice-bookkeeping/src/index.ts +0 -32
  33. package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
  34. package/microservices/microservice-calendar/package.json +0 -27
  35. package/microservices/microservice-calendar/src/cli/index.ts +0 -287
  36. package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
  37. package/microservices/microservice-calendar/src/db/database.ts +0 -82
  38. package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
  39. package/microservices/microservice-calendar/src/index.ts +0 -24
  40. package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
  41. package/microservices/microservice-company/package.json +0 -27
  42. package/microservices/microservice-company/src/cli/index.ts +0 -1126
  43. package/microservices/microservice-company/src/db/company.ts +0 -854
  44. package/microservices/microservice-company/src/db/database.ts +0 -93
  45. package/microservices/microservice-company/src/db/migrations.ts +0 -214
  46. package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
  47. package/microservices/microservice-company/src/index.ts +0 -60
  48. package/microservices/microservice-company/src/lib/audit.ts +0 -168
  49. package/microservices/microservice-company/src/lib/finance.ts +0 -299
  50. package/microservices/microservice-company/src/lib/settings.ts +0 -85
  51. package/microservices/microservice-company/src/lib/workflows.ts +0 -698
  52. package/microservices/microservice-company/src/mcp/index.ts +0 -991
  53. package/microservices/microservice-compliance/package.json +0 -27
  54. package/microservices/microservice-compliance/src/cli/index.ts +0 -467
  55. package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
  56. package/microservices/microservice-compliance/src/db/database.ts +0 -93
  57. package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
  58. package/microservices/microservice-compliance/src/index.ts +0 -46
  59. package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
  60. package/microservices/microservice-contacts/package.json +0 -27
  61. package/microservices/microservice-contacts/src/cli/index.ts +0 -393
  62. package/microservices/microservice-contacts/src/db/companies.ts +0 -167
  63. package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
  64. package/microservices/microservice-contacts/src/db/database.ts +0 -93
  65. package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
  66. package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
  67. package/microservices/microservice-contacts/src/index.ts +0 -42
  68. package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
  69. package/microservices/microservice-contracts/package.json +0 -27
  70. package/microservices/microservice-contracts/src/cli/index.ts +0 -770
  71. package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
  72. package/microservices/microservice-contracts/src/db/database.ts +0 -93
  73. package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
  74. package/microservices/microservice-contracts/src/index.ts +0 -43
  75. package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
  76. package/microservices/microservice-crm/package.json +0 -27
  77. package/microservices/microservice-crm/src/cli/index.ts +0 -396
  78. package/microservices/microservice-crm/src/db/database.ts +0 -82
  79. package/microservices/microservice-crm/src/db/migrations.ts +0 -66
  80. package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
  81. package/microservices/microservice-crm/src/index.ts +0 -34
  82. package/microservices/microservice-crm/src/mcp/index.ts +0 -294
  83. package/microservices/microservice-documents/package.json +0 -27
  84. package/microservices/microservice-documents/src/cli/index.ts +0 -246
  85. package/microservices/microservice-documents/src/db/database.ts +0 -82
  86. package/microservices/microservice-documents/src/db/documents.ts +0 -316
  87. package/microservices/microservice-documents/src/db/migrations.ts +0 -49
  88. package/microservices/microservice-documents/src/index.ts +0 -24
  89. package/microservices/microservice-documents/src/mcp/index.ts +0 -202
  90. package/microservices/microservice-domains/package.json +0 -27
  91. package/microservices/microservice-domains/src/cli/index.ts +0 -1111
  92. package/microservices/microservice-domains/src/db/database.ts +0 -93
  93. package/microservices/microservice-domains/src/db/domains.ts +0 -1164
  94. package/microservices/microservice-domains/src/db/migrations.ts +0 -60
  95. package/microservices/microservice-domains/src/index.ts +0 -65
  96. package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
  97. package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
  98. package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
  99. package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
  100. package/microservices/microservice-domains/src/mcp/index.ts +0 -781
  101. package/microservices/microservice-expenses/package.json +0 -27
  102. package/microservices/microservice-expenses/src/cli/index.ts +0 -267
  103. package/microservices/microservice-expenses/src/db/database.ts +0 -82
  104. package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
  105. package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
  106. package/microservices/microservice-expenses/src/index.ts +0 -25
  107. package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
  108. package/microservices/microservice-habits/package.json +0 -27
  109. package/microservices/microservice-habits/src/cli/index.ts +0 -315
  110. package/microservices/microservice-habits/src/db/database.ts +0 -93
  111. package/microservices/microservice-habits/src/db/habits.ts +0 -451
  112. package/microservices/microservice-habits/src/db/migrations.ts +0 -46
  113. package/microservices/microservice-habits/src/index.ts +0 -31
  114. package/microservices/microservice-habits/src/mcp/index.ts +0 -313
  115. package/microservices/microservice-health/package.json +0 -27
  116. package/microservices/microservice-health/src/cli/index.ts +0 -484
  117. package/microservices/microservice-health/src/db/database.ts +0 -93
  118. package/microservices/microservice-health/src/db/health.ts +0 -708
  119. package/microservices/microservice-health/src/db/migrations.ts +0 -70
  120. package/microservices/microservice-health/src/index.ts +0 -63
  121. package/microservices/microservice-health/src/mcp/index.ts +0 -437
  122. package/microservices/microservice-hiring/package.json +0 -27
  123. package/microservices/microservice-hiring/src/cli/index.ts +0 -741
  124. package/microservices/microservice-hiring/src/db/database.ts +0 -93
  125. package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
  126. package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
  127. package/microservices/microservice-hiring/src/index.ts +0 -80
  128. package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
  129. package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
  130. package/microservices/microservice-inventory/package.json +0 -27
  131. package/microservices/microservice-inventory/src/cli/index.ts +0 -365
  132. package/microservices/microservice-inventory/src/db/database.ts +0 -82
  133. package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
  134. package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
  135. package/microservices/microservice-inventory/src/index.ts +0 -28
  136. package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
  137. package/microservices/microservice-invoices/dashboard/dist/assets/index-Bngq7FNM.css +0 -1
  138. package/microservices/microservice-invoices/dashboard/dist/assets/index-aHW4ARZR.js +0 -124
  139. package/microservices/microservice-invoices/dashboard/dist/index.html +0 -13
  140. package/microservices/microservice-invoices/dashboard/index.html +0 -12
  141. package/microservices/microservice-invoices/dashboard/package.json +0 -29
  142. package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
  143. package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
  144. package/microservices/microservice-invoices/package.json +0 -30
  145. package/microservices/microservice-invoices/src/cli/index.ts +0 -308
  146. package/microservices/microservice-invoices/src/db/business.ts +0 -241
  147. package/microservices/microservice-invoices/src/db/clients.ts +0 -127
  148. package/microservices/microservice-invoices/src/db/database.ts +0 -82
  149. package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
  150. package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
  151. package/microservices/microservice-invoices/src/index.ts +0 -56
  152. package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
  153. package/microservices/microservice-invoices/src/server/index.ts +0 -162
  154. package/microservices/microservice-leads/package.json +0 -27
  155. package/microservices/microservice-leads/src/cli/index.ts +0 -596
  156. package/microservices/microservice-leads/src/db/database.ts +0 -93
  157. package/microservices/microservice-leads/src/db/leads.ts +0 -520
  158. package/microservices/microservice-leads/src/db/lists.ts +0 -151
  159. package/microservices/microservice-leads/src/db/migrations.ts +0 -93
  160. package/microservices/microservice-leads/src/index.ts +0 -65
  161. package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
  162. package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
  163. package/microservices/microservice-leads/src/mcp/index.ts +0 -533
  164. package/microservices/microservice-notes/package.json +0 -27
  165. package/microservices/microservice-notes/src/cli/index.ts +0 -63
  166. package/microservices/microservice-notes/src/db/database.ts +0 -93
  167. package/microservices/microservice-notes/src/db/migrations.ts +0 -40
  168. package/microservices/microservice-notes/src/db/notes.ts +0 -114
  169. package/microservices/microservice-notes/src/index.ts +0 -2
  170. package/microservices/microservice-notes/src/mcp/index.ts +0 -37
  171. package/microservices/microservice-notifications/package.json +0 -27
  172. package/microservices/microservice-notifications/src/cli/index.ts +0 -349
  173. package/microservices/microservice-notifications/src/db/database.ts +0 -93
  174. package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
  175. package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
  176. package/microservices/microservice-notifications/src/index.ts +0 -41
  177. package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
  178. package/microservices/microservice-payments/package.json +0 -27
  179. package/microservices/microservice-payments/src/cli/index.ts +0 -609
  180. package/microservices/microservice-payments/src/db/database.ts +0 -93
  181. package/microservices/microservice-payments/src/db/migrations.ts +0 -81
  182. package/microservices/microservice-payments/src/db/payments.ts +0 -1204
  183. package/microservices/microservice-payments/src/index.ts +0 -51
  184. package/microservices/microservice-payments/src/mcp/index.ts +0 -683
  185. package/microservices/microservice-payroll/package.json +0 -27
  186. package/microservices/microservice-payroll/src/cli/index.ts +0 -643
  187. package/microservices/microservice-payroll/src/db/database.ts +0 -93
  188. package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
  189. package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
  190. package/microservices/microservice-payroll/src/index.ts +0 -48
  191. package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
  192. package/microservices/microservice-products/package.json +0 -27
  193. package/microservices/microservice-products/src/cli/index.ts +0 -416
  194. package/microservices/microservice-products/src/db/categories.ts +0 -154
  195. package/microservices/microservice-products/src/db/database.ts +0 -93
  196. package/microservices/microservice-products/src/db/migrations.ts +0 -58
  197. package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
  198. package/microservices/microservice-products/src/db/products.ts +0 -452
  199. package/microservices/microservice-products/src/index.ts +0 -53
  200. package/microservices/microservice-products/src/mcp/index.ts +0 -453
  201. package/microservices/microservice-projects/package.json +0 -27
  202. package/microservices/microservice-projects/src/cli/index.ts +0 -480
  203. package/microservices/microservice-projects/src/db/database.ts +0 -93
  204. package/microservices/microservice-projects/src/db/migrations.ts +0 -65
  205. package/microservices/microservice-projects/src/db/projects.ts +0 -715
  206. package/microservices/microservice-projects/src/index.ts +0 -57
  207. package/microservices/microservice-projects/src/mcp/index.ts +0 -501
  208. package/microservices/microservice-proposals/package.json +0 -27
  209. package/microservices/microservice-proposals/src/cli/index.ts +0 -400
  210. package/microservices/microservice-proposals/src/db/database.ts +0 -93
  211. package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
  212. package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
  213. package/microservices/microservice-proposals/src/index.ts +0 -37
  214. package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
  215. package/microservices/microservice-reading/package.json +0 -27
  216. package/microservices/microservice-reading/src/cli/index.ts +0 -464
  217. package/microservices/microservice-reading/src/db/database.ts +0 -93
  218. package/microservices/microservice-reading/src/db/migrations.ts +0 -59
  219. package/microservices/microservice-reading/src/db/reading.ts +0 -524
  220. package/microservices/microservice-reading/src/index.ts +0 -51
  221. package/microservices/microservice-reading/src/mcp/index.ts +0 -368
  222. package/microservices/microservice-shipping/package.json +0 -27
  223. package/microservices/microservice-shipping/src/cli/index.ts +0 -606
  224. package/microservices/microservice-shipping/src/db/database.ts +0 -93
  225. package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
  226. package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
  227. package/microservices/microservice-shipping/src/index.ts +0 -53
  228. package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
  229. package/microservices/microservice-social/package.json +0 -28
  230. package/microservices/microservice-social/src/cli/index.ts +0 -1583
  231. package/microservices/microservice-social/src/db/database.ts +0 -93
  232. package/microservices/microservice-social/src/db/migrations.ts +0 -160
  233. package/microservices/microservice-social/src/db/social.ts +0 -1076
  234. package/microservices/microservice-social/src/index.ts +0 -46
  235. package/microservices/microservice-social/src/lib/audience.ts +0 -353
  236. package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
  237. package/microservices/microservice-social/src/lib/media.ts +0 -311
  238. package/microservices/microservice-social/src/lib/mentions.ts +0 -434
  239. package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
  240. package/microservices/microservice-social/src/lib/publisher.ts +0 -377
  241. package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
  242. package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
  243. package/microservices/microservice-social/src/lib/threads.ts +0 -291
  244. package/microservices/microservice-social/src/mcp/index.ts +0 -1425
  245. package/microservices/microservice-social/src/server/index.ts +0 -441
  246. package/microservices/microservice-subscriptions/package.json +0 -27
  247. package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
  248. package/microservices/microservice-subscriptions/src/db/database.ts +0 -93
  249. package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
  250. package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
  251. package/microservices/microservice-subscriptions/src/index.ts +0 -41
  252. package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
  253. package/microservices/microservice-timesheets/package.json +0 -27
  254. package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
  255. package/microservices/microservice-timesheets/src/db/database.ts +0 -82
  256. package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
  257. package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
  258. package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
  259. package/microservices/microservice-timesheets/src/index.ts +0 -44
  260. package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
  261. package/microservices/microservice-transcriber/package.json +0 -28
  262. package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
  263. package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
  264. package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
  265. package/microservices/microservice-transcriber/src/db/database.ts +0 -82
  266. package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
  267. package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
  268. package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
  269. package/microservices/microservice-transcriber/src/index.ts +0 -43
  270. package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
  271. package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
  272. package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
  273. package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
  274. package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
  275. package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
  276. package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
  277. package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
  278. package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
  279. package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
  280. package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
  281. package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
  282. package/microservices/microservice-transcriber/src/server/index.ts +0 -199
  283. package/microservices/microservice-travel/package.json +0 -27
  284. package/microservices/microservice-travel/src/cli/index.ts +0 -505
  285. package/microservices/microservice-travel/src/db/database.ts +0 -93
  286. package/microservices/microservice-travel/src/db/migrations.ts +0 -77
  287. package/microservices/microservice-travel/src/db/travel.ts +0 -802
  288. package/microservices/microservice-travel/src/index.ts +0 -60
  289. package/microservices/microservice-travel/src/mcp/index.ts +0 -495
  290. package/microservices/microservice-wiki/package.json +0 -27
  291. package/microservices/microservice-wiki/src/cli/index.ts +0 -345
  292. package/microservices/microservice-wiki/src/db/database.ts +0 -93
  293. package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
  294. package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
  295. package/microservices/microservice-wiki/src/index.ts +0 -32
  296. package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
@@ -1,708 +0,0 @@
1
- /**
2
- * Health CRUD operations for metrics, medications, appointments, and fitness logs
3
- */
4
-
5
- import { getDatabase } from "./database.js";
6
-
7
- // ============================================================
8
- // Metrics
9
- // ============================================================
10
-
11
- export interface Metric {
12
- id: string;
13
- type: string;
14
- value: number;
15
- unit: string | null;
16
- notes: string | null;
17
- recorded_at: string;
18
- metadata: Record<string, unknown>;
19
- created_at: string;
20
- }
21
-
22
- interface MetricRow {
23
- id: string;
24
- type: string;
25
- value: number;
26
- unit: string | null;
27
- notes: string | null;
28
- recorded_at: string;
29
- metadata: string;
30
- created_at: string;
31
- }
32
-
33
- function rowToMetric(row: MetricRow): Metric {
34
- return {
35
- ...row,
36
- metadata: JSON.parse(row.metadata || "{}"),
37
- };
38
- }
39
-
40
- export interface CreateMetricInput {
41
- type: string;
42
- value: number;
43
- unit?: string;
44
- notes?: string;
45
- recorded_at?: string;
46
- metadata?: Record<string, unknown>;
47
- }
48
-
49
- export function createMetric(input: CreateMetricInput): Metric {
50
- const db = getDatabase();
51
- const id = crypto.randomUUID();
52
- const metadata = JSON.stringify(input.metadata || {});
53
- const recorded_at = input.recorded_at || new Date().toISOString();
54
-
55
- db.prepare(
56
- `INSERT INTO metrics (id, type, value, unit, notes, recorded_at, metadata)
57
- VALUES (?, ?, ?, ?, ?, ?, ?)`
58
- ).run(id, input.type, input.value, input.unit || null, input.notes || null, recorded_at, metadata);
59
-
60
- return getMetric(id)!;
61
- }
62
-
63
- export function getMetric(id: string): Metric | null {
64
- const db = getDatabase();
65
- const row = db.prepare("SELECT * FROM metrics WHERE id = ?").get(id) as MetricRow | null;
66
- return row ? rowToMetric(row) : null;
67
- }
68
-
69
- export interface ListMetricsOptions {
70
- type?: string;
71
- limit?: number;
72
- offset?: number;
73
- }
74
-
75
- export function listMetrics(options: ListMetricsOptions = {}): Metric[] {
76
- const db = getDatabase();
77
- const conditions: string[] = [];
78
- const params: unknown[] = [];
79
-
80
- if (options.type) {
81
- conditions.push("type = ?");
82
- params.push(options.type);
83
- }
84
-
85
- let sql = "SELECT * FROM metrics";
86
- if (conditions.length > 0) {
87
- sql += " WHERE " + conditions.join(" AND ");
88
- }
89
- sql += " ORDER BY recorded_at DESC";
90
-
91
- if (options.limit) {
92
- sql += " LIMIT ?";
93
- params.push(options.limit);
94
- }
95
- if (options.offset) {
96
- sql += " OFFSET ?";
97
- params.push(options.offset);
98
- }
99
-
100
- const rows = db.prepare(sql).all(...params) as MetricRow[];
101
- return rows.map(rowToMetric);
102
- }
103
-
104
- export function deleteMetric(id: string): boolean {
105
- const db = getDatabase();
106
- const result = db.prepare("DELETE FROM metrics WHERE id = ?").run(id);
107
- return result.changes > 0;
108
- }
109
-
110
- export interface MetricTrendPoint {
111
- date: string;
112
- value: number;
113
- }
114
-
115
- export function getMetricTrend(type: string, days: number): MetricTrendPoint[] {
116
- const db = getDatabase();
117
- const rows = db
118
- .prepare(
119
- `SELECT date(recorded_at) as date, AVG(value) as value
120
- FROM metrics
121
- WHERE type = ? AND recorded_at >= datetime('now', '-' || ? || ' days')
122
- GROUP BY date(recorded_at)
123
- ORDER BY date(recorded_at) ASC`
124
- )
125
- .all(type, days) as MetricTrendPoint[];
126
- return rows;
127
- }
128
-
129
- // ============================================================
130
- // Medications
131
- // ============================================================
132
-
133
- export interface Medication {
134
- id: string;
135
- name: string;
136
- dosage: string | null;
137
- frequency: string | null;
138
- start_date: string | null;
139
- end_date: string | null;
140
- refill_date: string | null;
141
- notes: string | null;
142
- active: boolean;
143
- created_at: string;
144
- }
145
-
146
- interface MedicationRow {
147
- id: string;
148
- name: string;
149
- dosage: string | null;
150
- frequency: string | null;
151
- start_date: string | null;
152
- end_date: string | null;
153
- refill_date: string | null;
154
- notes: string | null;
155
- active: number;
156
- created_at: string;
157
- }
158
-
159
- function rowToMedication(row: MedicationRow): Medication {
160
- return {
161
- ...row,
162
- active: row.active === 1,
163
- };
164
- }
165
-
166
- export interface CreateMedicationInput {
167
- name: string;
168
- dosage?: string;
169
- frequency?: string;
170
- start_date?: string;
171
- end_date?: string;
172
- refill_date?: string;
173
- notes?: string;
174
- active?: boolean;
175
- }
176
-
177
- export function createMedication(input: CreateMedicationInput): Medication {
178
- const db = getDatabase();
179
- const id = crypto.randomUUID();
180
- const active = input.active !== undefined ? (input.active ? 1 : 0) : 1;
181
-
182
- db.prepare(
183
- `INSERT INTO medications (id, name, dosage, frequency, start_date, end_date, refill_date, notes, active)
184
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
185
- ).run(
186
- id,
187
- input.name,
188
- input.dosage || null,
189
- input.frequency || null,
190
- input.start_date || null,
191
- input.end_date || null,
192
- input.refill_date || null,
193
- input.notes || null,
194
- active
195
- );
196
-
197
- return getMedication(id)!;
198
- }
199
-
200
- export function getMedication(id: string): Medication | null {
201
- const db = getDatabase();
202
- const row = db.prepare("SELECT * FROM medications WHERE id = ?").get(id) as MedicationRow | null;
203
- return row ? rowToMedication(row) : null;
204
- }
205
-
206
- export interface ListMedicationsOptions {
207
- active?: boolean;
208
- search?: string;
209
- limit?: number;
210
- offset?: number;
211
- }
212
-
213
- export function listMedications(options: ListMedicationsOptions = {}): Medication[] {
214
- const db = getDatabase();
215
- const conditions: string[] = [];
216
- const params: unknown[] = [];
217
-
218
- if (options.active !== undefined) {
219
- conditions.push("active = ?");
220
- params.push(options.active ? 1 : 0);
221
- }
222
-
223
- if (options.search) {
224
- conditions.push("(name LIKE ? OR dosage LIKE ? OR notes LIKE ?)");
225
- const q = `%${options.search}%`;
226
- params.push(q, q, q);
227
- }
228
-
229
- let sql = "SELECT * FROM medications";
230
- if (conditions.length > 0) {
231
- sql += " WHERE " + conditions.join(" AND ");
232
- }
233
- sql += " ORDER BY name ASC";
234
-
235
- if (options.limit) {
236
- sql += " LIMIT ?";
237
- params.push(options.limit);
238
- }
239
- if (options.offset) {
240
- sql += " OFFSET ?";
241
- params.push(options.offset);
242
- }
243
-
244
- const rows = db.prepare(sql).all(...params) as MedicationRow[];
245
- return rows.map(rowToMedication);
246
- }
247
-
248
- export interface UpdateMedicationInput {
249
- name?: string;
250
- dosage?: string;
251
- frequency?: string;
252
- start_date?: string;
253
- end_date?: string;
254
- refill_date?: string;
255
- notes?: string;
256
- active?: boolean;
257
- }
258
-
259
- export function updateMedication(id: string, input: UpdateMedicationInput): Medication | null {
260
- const db = getDatabase();
261
- const existing = getMedication(id);
262
- if (!existing) return null;
263
-
264
- const sets: string[] = [];
265
- const params: unknown[] = [];
266
-
267
- if (input.name !== undefined) {
268
- sets.push("name = ?");
269
- params.push(input.name);
270
- }
271
- if (input.dosage !== undefined) {
272
- sets.push("dosage = ?");
273
- params.push(input.dosage);
274
- }
275
- if (input.frequency !== undefined) {
276
- sets.push("frequency = ?");
277
- params.push(input.frequency);
278
- }
279
- if (input.start_date !== undefined) {
280
- sets.push("start_date = ?");
281
- params.push(input.start_date);
282
- }
283
- if (input.end_date !== undefined) {
284
- sets.push("end_date = ?");
285
- params.push(input.end_date);
286
- }
287
- if (input.refill_date !== undefined) {
288
- sets.push("refill_date = ?");
289
- params.push(input.refill_date);
290
- }
291
- if (input.notes !== undefined) {
292
- sets.push("notes = ?");
293
- params.push(input.notes);
294
- }
295
- if (input.active !== undefined) {
296
- sets.push("active = ?");
297
- params.push(input.active ? 1 : 0);
298
- }
299
-
300
- if (sets.length === 0) return existing;
301
-
302
- params.push(id);
303
- db.prepare(`UPDATE medications SET ${sets.join(", ")} WHERE id = ?`).run(...params);
304
-
305
- return getMedication(id);
306
- }
307
-
308
- export function deactivateMedication(id: string): Medication | null {
309
- return updateMedication(id, { active: false });
310
- }
311
-
312
- export function deleteMedication(id: string): boolean {
313
- const db = getDatabase();
314
- const result = db.prepare("DELETE FROM medications WHERE id = ?").run(id);
315
- return result.changes > 0;
316
- }
317
-
318
- export function getMedicationSchedule(): Medication[] {
319
- return listMedications({ active: true });
320
- }
321
-
322
- // ============================================================
323
- // Appointments
324
- // ============================================================
325
-
326
- export interface Appointment {
327
- id: string;
328
- provider: string;
329
- specialty: string | null;
330
- location: string | null;
331
- scheduled_at: string;
332
- status: "scheduled" | "completed" | "cancelled" | "rescheduled";
333
- notes: string | null;
334
- follow_up_date: string | null;
335
- metadata: Record<string, unknown>;
336
- created_at: string;
337
- }
338
-
339
- interface AppointmentRow {
340
- id: string;
341
- provider: string;
342
- specialty: string | null;
343
- location: string | null;
344
- scheduled_at: string;
345
- status: string;
346
- notes: string | null;
347
- follow_up_date: string | null;
348
- metadata: string;
349
- created_at: string;
350
- }
351
-
352
- function rowToAppointment(row: AppointmentRow): Appointment {
353
- return {
354
- ...row,
355
- status: row.status as Appointment["status"],
356
- metadata: JSON.parse(row.metadata || "{}"),
357
- };
358
- }
359
-
360
- export interface CreateAppointmentInput {
361
- provider: string;
362
- specialty?: string;
363
- location?: string;
364
- scheduled_at: string;
365
- status?: Appointment["status"];
366
- notes?: string;
367
- follow_up_date?: string;
368
- metadata?: Record<string, unknown>;
369
- }
370
-
371
- export function createAppointment(input: CreateAppointmentInput): Appointment {
372
- const db = getDatabase();
373
- const id = crypto.randomUUID();
374
- const metadata = JSON.stringify(input.metadata || {});
375
- const status = input.status || "scheduled";
376
-
377
- db.prepare(
378
- `INSERT INTO appointments (id, provider, specialty, location, scheduled_at, status, notes, follow_up_date, metadata)
379
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
380
- ).run(
381
- id,
382
- input.provider,
383
- input.specialty || null,
384
- input.location || null,
385
- input.scheduled_at,
386
- status,
387
- input.notes || null,
388
- input.follow_up_date || null,
389
- metadata
390
- );
391
-
392
- return getAppointment(id)!;
393
- }
394
-
395
- export function getAppointment(id: string): Appointment | null {
396
- const db = getDatabase();
397
- const row = db.prepare("SELECT * FROM appointments WHERE id = ?").get(id) as AppointmentRow | null;
398
- return row ? rowToAppointment(row) : null;
399
- }
400
-
401
- export interface ListAppointmentsOptions {
402
- status?: string;
403
- provider?: string;
404
- limit?: number;
405
- offset?: number;
406
- }
407
-
408
- export function listAppointments(options: ListAppointmentsOptions = {}): Appointment[] {
409
- const db = getDatabase();
410
- const conditions: string[] = [];
411
- const params: unknown[] = [];
412
-
413
- if (options.status) {
414
- conditions.push("status = ?");
415
- params.push(options.status);
416
- }
417
- if (options.provider) {
418
- conditions.push("provider LIKE ?");
419
- params.push(`%${options.provider}%`);
420
- }
421
-
422
- let sql = "SELECT * FROM appointments";
423
- if (conditions.length > 0) {
424
- sql += " WHERE " + conditions.join(" AND ");
425
- }
426
- sql += " ORDER BY scheduled_at DESC";
427
-
428
- if (options.limit) {
429
- sql += " LIMIT ?";
430
- params.push(options.limit);
431
- }
432
- if (options.offset) {
433
- sql += " OFFSET ?";
434
- params.push(options.offset);
435
- }
436
-
437
- const rows = db.prepare(sql).all(...params) as AppointmentRow[];
438
- return rows.map(rowToAppointment);
439
- }
440
-
441
- export interface UpdateAppointmentInput {
442
- provider?: string;
443
- specialty?: string;
444
- location?: string;
445
- scheduled_at?: string;
446
- status?: Appointment["status"];
447
- notes?: string;
448
- follow_up_date?: string;
449
- metadata?: Record<string, unknown>;
450
- }
451
-
452
- export function updateAppointment(id: string, input: UpdateAppointmentInput): Appointment | null {
453
- const db = getDatabase();
454
- const existing = getAppointment(id);
455
- if (!existing) return null;
456
-
457
- const sets: string[] = [];
458
- const params: unknown[] = [];
459
-
460
- if (input.provider !== undefined) {
461
- sets.push("provider = ?");
462
- params.push(input.provider);
463
- }
464
- if (input.specialty !== undefined) {
465
- sets.push("specialty = ?");
466
- params.push(input.specialty);
467
- }
468
- if (input.location !== undefined) {
469
- sets.push("location = ?");
470
- params.push(input.location);
471
- }
472
- if (input.scheduled_at !== undefined) {
473
- sets.push("scheduled_at = ?");
474
- params.push(input.scheduled_at);
475
- }
476
- if (input.status !== undefined) {
477
- sets.push("status = ?");
478
- params.push(input.status);
479
- }
480
- if (input.notes !== undefined) {
481
- sets.push("notes = ?");
482
- params.push(input.notes);
483
- }
484
- if (input.follow_up_date !== undefined) {
485
- sets.push("follow_up_date = ?");
486
- params.push(input.follow_up_date);
487
- }
488
- if (input.metadata !== undefined) {
489
- sets.push("metadata = ?");
490
- params.push(JSON.stringify(input.metadata));
491
- }
492
-
493
- if (sets.length === 0) return existing;
494
-
495
- params.push(id);
496
- db.prepare(`UPDATE appointments SET ${sets.join(", ")} WHERE id = ?`).run(...params);
497
-
498
- return getAppointment(id);
499
- }
500
-
501
- export function completeAppointment(id: string): Appointment | null {
502
- return updateAppointment(id, { status: "completed" });
503
- }
504
-
505
- export function cancelAppointment(id: string): Appointment | null {
506
- return updateAppointment(id, { status: "cancelled" });
507
- }
508
-
509
- export function deleteAppointment(id: string): boolean {
510
- const db = getDatabase();
511
- const result = db.prepare("DELETE FROM appointments WHERE id = ?").run(id);
512
- return result.changes > 0;
513
- }
514
-
515
- export function getUpcomingAppointments(days: number): Appointment[] {
516
- const db = getDatabase();
517
- const rows = db
518
- .prepare(
519
- `SELECT * FROM appointments
520
- WHERE status = 'scheduled'
521
- AND scheduled_at >= datetime('now')
522
- AND scheduled_at <= datetime('now', '+' || ? || ' days')
523
- ORDER BY scheduled_at ASC`
524
- )
525
- .all(days) as AppointmentRow[];
526
- return rows.map(rowToAppointment);
527
- }
528
-
529
- // ============================================================
530
- // Fitness Logs
531
- // ============================================================
532
-
533
- export interface FitnessLog {
534
- id: string;
535
- activity: string;
536
- duration_min: number | null;
537
- calories_burned: number | null;
538
- distance: number | null;
539
- notes: string | null;
540
- logged_at: string;
541
- created_at: string;
542
- }
543
-
544
- export interface CreateFitnessLogInput {
545
- activity: string;
546
- duration_min?: number;
547
- calories_burned?: number;
548
- distance?: number;
549
- notes?: string;
550
- logged_at?: string;
551
- }
552
-
553
- export function createFitnessLog(input: CreateFitnessLogInput): FitnessLog {
554
- const db = getDatabase();
555
- const id = crypto.randomUUID();
556
- const logged_at = input.logged_at || new Date().toISOString();
557
-
558
- db.prepare(
559
- `INSERT INTO fitness_logs (id, activity, duration_min, calories_burned, distance, notes, logged_at)
560
- VALUES (?, ?, ?, ?, ?, ?, ?)`
561
- ).run(
562
- id,
563
- input.activity,
564
- input.duration_min ?? null,
565
- input.calories_burned ?? null,
566
- input.distance ?? null,
567
- input.notes || null,
568
- logged_at
569
- );
570
-
571
- return getFitnessLog(id)!;
572
- }
573
-
574
- export function getFitnessLog(id: string): FitnessLog | null {
575
- const db = getDatabase();
576
- const row = db.prepare("SELECT * FROM fitness_logs WHERE id = ?").get(id) as FitnessLog | null;
577
- return row;
578
- }
579
-
580
- export interface ListFitnessLogsOptions {
581
- activity?: string;
582
- limit?: number;
583
- offset?: number;
584
- }
585
-
586
- export function listFitnessLogs(options: ListFitnessLogsOptions = {}): FitnessLog[] {
587
- const db = getDatabase();
588
- const conditions: string[] = [];
589
- const params: unknown[] = [];
590
-
591
- if (options.activity) {
592
- conditions.push("activity LIKE ?");
593
- params.push(`%${options.activity}%`);
594
- }
595
-
596
- let sql = "SELECT * FROM fitness_logs";
597
- if (conditions.length > 0) {
598
- sql += " WHERE " + conditions.join(" AND ");
599
- }
600
- sql += " ORDER BY logged_at DESC";
601
-
602
- if (options.limit) {
603
- sql += " LIMIT ?";
604
- params.push(options.limit);
605
- }
606
- if (options.offset) {
607
- sql += " OFFSET ?";
608
- params.push(options.offset);
609
- }
610
-
611
- const rows = db.prepare(sql).all(...params) as FitnessLog[];
612
- return rows;
613
- }
614
-
615
- export function deleteFitnessLog(id: string): boolean {
616
- const db = getDatabase();
617
- const result = db.prepare("DELETE FROM fitness_logs WHERE id = ?").run(id);
618
- return result.changes > 0;
619
- }
620
-
621
- export interface FitnessStats {
622
- total_sessions: number;
623
- total_minutes: number;
624
- total_calories: number;
625
- avg_duration: number;
626
- }
627
-
628
- export function getFitnessStats(days: number): FitnessStats {
629
- const db = getDatabase();
630
- const row = db
631
- .prepare(
632
- `SELECT
633
- COUNT(*) as total_sessions,
634
- COALESCE(SUM(duration_min), 0) as total_minutes,
635
- COALESCE(SUM(calories_burned), 0) as total_calories,
636
- COALESCE(AVG(duration_min), 0) as avg_duration
637
- FROM fitness_logs
638
- WHERE logged_at >= datetime('now', '-' || ? || ' days')`
639
- )
640
- .get(days) as FitnessStats;
641
- return {
642
- total_sessions: row.total_sessions,
643
- total_minutes: row.total_minutes,
644
- total_calories: row.total_calories,
645
- avg_duration: Math.round(row.avg_duration * 100) / 100,
646
- };
647
- }
648
-
649
- // ============================================================
650
- // Health Summary
651
- // ============================================================
652
-
653
- export interface HealthSummary {
654
- metrics: { total: number; types: string[] };
655
- medications: { total: number; active: number };
656
- appointments: { total: number; upcoming: number; completed: number };
657
- fitness: { total_sessions: number; recent_stats: FitnessStats };
658
- }
659
-
660
- export function getHealthSummary(): HealthSummary {
661
- const db = getDatabase();
662
-
663
- // Metrics summary
664
- const metricTotal = (
665
- db.prepare("SELECT COUNT(*) as count FROM metrics").get() as { count: number }
666
- ).count;
667
- const metricTypes = (
668
- db.prepare("SELECT DISTINCT type FROM metrics ORDER BY type").all() as { type: string }[]
669
- ).map((r) => r.type);
670
-
671
- // Medications summary
672
- const medTotal = (
673
- db.prepare("SELECT COUNT(*) as count FROM medications").get() as { count: number }
674
- ).count;
675
- const medActive = (
676
- db.prepare("SELECT COUNT(*) as count FROM medications WHERE active = 1").get() as {
677
- count: number;
678
- }
679
- ).count;
680
-
681
- // Appointments summary
682
- const apptTotal = (
683
- db.prepare("SELECT COUNT(*) as count FROM appointments").get() as { count: number }
684
- ).count;
685
- const apptUpcoming = (
686
- db.prepare(
687
- "SELECT COUNT(*) as count FROM appointments WHERE status = 'scheduled' AND scheduled_at >= datetime('now')"
688
- ).get() as { count: number }
689
- ).count;
690
- const apptCompleted = (
691
- db.prepare(
692
- "SELECT COUNT(*) as count FROM appointments WHERE status = 'completed'"
693
- ).get() as { count: number }
694
- ).count;
695
-
696
- // Fitness summary
697
- const fitnessTotal = (
698
- db.prepare("SELECT COUNT(*) as count FROM fitness_logs").get() as { count: number }
699
- ).count;
700
- const recentStats = getFitnessStats(30);
701
-
702
- return {
703
- metrics: { total: metricTotal, types: metricTypes },
704
- medications: { total: medTotal, active: medActive },
705
- appointments: { total: apptTotal, upcoming: apptUpcoming, completed: apptCompleted },
706
- fitness: { total_sessions: fitnessTotal, recent_stats: recentStats },
707
- };
708
- }