@hasna/microservices 0.0.16 → 0.0.18

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 (293) hide show
  1. package/README.md +143 -23
  2. package/bin/index.js +784 -13987
  3. package/bin/mcp.js +298 -10973
  4. package/dist/index.js +251 -10056
  5. package/package.json +36 -26
  6. package/microservices/microservice-ads/package.json +0 -28
  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 -91
  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 -28
  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 -91
  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 -28
  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 -91
  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 -28
  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 -91
  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 -28
  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 -91
  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 -28
  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 -91
  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 -28
  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 -91
  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 -28
  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 -91
  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 -28
  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 -91
  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 -28
  77. package/microservices/microservice-crm/src/cli/index.ts +0 -396
  78. package/microservices/microservice-crm/src/db/database.ts +0 -91
  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 -28
  84. package/microservices/microservice-documents/src/cli/index.ts +0 -246
  85. package/microservices/microservice-documents/src/db/database.ts +0 -91
  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 -28
  91. package/microservices/microservice-domains/src/cli/index.ts +0 -1111
  92. package/microservices/microservice-domains/src/db/database.ts +0 -91
  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 -28
  102. package/microservices/microservice-expenses/src/cli/index.ts +0 -267
  103. package/microservices/microservice-expenses/src/db/database.ts +0 -91
  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 -28
  109. package/microservices/microservice-habits/src/cli/index.ts +0 -315
  110. package/microservices/microservice-habits/src/db/database.ts +0 -91
  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 -28
  116. package/microservices/microservice-health/src/cli/index.ts +0 -484
  117. package/microservices/microservice-health/src/db/database.ts +0 -91
  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 -28
  123. package/microservices/microservice-hiring/src/cli/index.ts +0 -741
  124. package/microservices/microservice-hiring/src/db/database.ts +0 -91
  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 -28
  131. package/microservices/microservice-inventory/src/cli/index.ts +0 -365
  132. package/microservices/microservice-inventory/src/db/database.ts +0 -91
  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/index.html +0 -12
  138. package/microservices/microservice-invoices/dashboard/package.json +0 -29
  139. package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
  140. package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
  141. package/microservices/microservice-invoices/package.json +0 -31
  142. package/microservices/microservice-invoices/src/cli/index.ts +0 -308
  143. package/microservices/microservice-invoices/src/db/business.ts +0 -241
  144. package/microservices/microservice-invoices/src/db/clients.ts +0 -127
  145. package/microservices/microservice-invoices/src/db/database.ts +0 -91
  146. package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
  147. package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
  148. package/microservices/microservice-invoices/src/index.ts +0 -56
  149. package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
  150. package/microservices/microservice-invoices/src/server/index.ts +0 -162
  151. package/microservices/microservice-leads/package.json +0 -28
  152. package/microservices/microservice-leads/src/cli/index.ts +0 -596
  153. package/microservices/microservice-leads/src/db/database.ts +0 -91
  154. package/microservices/microservice-leads/src/db/leads.ts +0 -520
  155. package/microservices/microservice-leads/src/db/lists.ts +0 -151
  156. package/microservices/microservice-leads/src/db/migrations.ts +0 -93
  157. package/microservices/microservice-leads/src/index.ts +0 -65
  158. package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
  159. package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
  160. package/microservices/microservice-leads/src/mcp/index.ts +0 -533
  161. package/microservices/microservice-notes/package.json +0 -28
  162. package/microservices/microservice-notes/src/cli/index.ts +0 -63
  163. package/microservices/microservice-notes/src/db/database.ts +0 -91
  164. package/microservices/microservice-notes/src/db/migrations.ts +0 -40
  165. package/microservices/microservice-notes/src/db/notes.ts +0 -114
  166. package/microservices/microservice-notes/src/index.ts +0 -2
  167. package/microservices/microservice-notes/src/mcp/index.ts +0 -37
  168. package/microservices/microservice-notifications/package.json +0 -28
  169. package/microservices/microservice-notifications/src/cli/index.ts +0 -349
  170. package/microservices/microservice-notifications/src/db/database.ts +0 -91
  171. package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
  172. package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
  173. package/microservices/microservice-notifications/src/index.ts +0 -41
  174. package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
  175. package/microservices/microservice-payments/package.json +0 -28
  176. package/microservices/microservice-payments/src/cli/index.ts +0 -609
  177. package/microservices/microservice-payments/src/db/database.ts +0 -91
  178. package/microservices/microservice-payments/src/db/migrations.ts +0 -81
  179. package/microservices/microservice-payments/src/db/payments.ts +0 -1204
  180. package/microservices/microservice-payments/src/index.ts +0 -51
  181. package/microservices/microservice-payments/src/mcp/index.ts +0 -683
  182. package/microservices/microservice-payroll/package.json +0 -28
  183. package/microservices/microservice-payroll/src/cli/index.ts +0 -643
  184. package/microservices/microservice-payroll/src/db/database.ts +0 -91
  185. package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
  186. package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
  187. package/microservices/microservice-payroll/src/index.ts +0 -48
  188. package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
  189. package/microservices/microservice-products/package.json +0 -28
  190. package/microservices/microservice-products/src/cli/index.ts +0 -416
  191. package/microservices/microservice-products/src/db/categories.ts +0 -154
  192. package/microservices/microservice-products/src/db/database.ts +0 -91
  193. package/microservices/microservice-products/src/db/migrations.ts +0 -58
  194. package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
  195. package/microservices/microservice-products/src/db/products.ts +0 -452
  196. package/microservices/microservice-products/src/index.ts +0 -53
  197. package/microservices/microservice-products/src/mcp/index.ts +0 -453
  198. package/microservices/microservice-projects/package.json +0 -28
  199. package/microservices/microservice-projects/src/cli/index.ts +0 -480
  200. package/microservices/microservice-projects/src/db/database.ts +0 -91
  201. package/microservices/microservice-projects/src/db/migrations.ts +0 -65
  202. package/microservices/microservice-projects/src/db/projects.ts +0 -715
  203. package/microservices/microservice-projects/src/index.ts +0 -57
  204. package/microservices/microservice-projects/src/mcp/index.ts +0 -501
  205. package/microservices/microservice-proposals/package.json +0 -28
  206. package/microservices/microservice-proposals/src/cli/index.ts +0 -400
  207. package/microservices/microservice-proposals/src/db/database.ts +0 -91
  208. package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
  209. package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
  210. package/microservices/microservice-proposals/src/index.ts +0 -37
  211. package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
  212. package/microservices/microservice-reading/package.json +0 -28
  213. package/microservices/microservice-reading/src/cli/index.ts +0 -464
  214. package/microservices/microservice-reading/src/db/database.ts +0 -91
  215. package/microservices/microservice-reading/src/db/migrations.ts +0 -59
  216. package/microservices/microservice-reading/src/db/reading.ts +0 -524
  217. package/microservices/microservice-reading/src/index.ts +0 -51
  218. package/microservices/microservice-reading/src/mcp/index.ts +0 -368
  219. package/microservices/microservice-shipping/package.json +0 -28
  220. package/microservices/microservice-shipping/src/cli/index.ts +0 -606
  221. package/microservices/microservice-shipping/src/db/database.ts +0 -91
  222. package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
  223. package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
  224. package/microservices/microservice-shipping/src/index.ts +0 -53
  225. package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
  226. package/microservices/microservice-social/package.json +0 -29
  227. package/microservices/microservice-social/src/cli/index.ts +0 -1583
  228. package/microservices/microservice-social/src/db/database.ts +0 -91
  229. package/microservices/microservice-social/src/db/migrations.ts +0 -160
  230. package/microservices/microservice-social/src/db/social.ts +0 -1076
  231. package/microservices/microservice-social/src/index.ts +0 -46
  232. package/microservices/microservice-social/src/lib/audience.ts +0 -353
  233. package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
  234. package/microservices/microservice-social/src/lib/media.ts +0 -311
  235. package/microservices/microservice-social/src/lib/mentions.ts +0 -434
  236. package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
  237. package/microservices/microservice-social/src/lib/publisher.ts +0 -377
  238. package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
  239. package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
  240. package/microservices/microservice-social/src/lib/threads.ts +0 -291
  241. package/microservices/microservice-social/src/mcp/index.ts +0 -1425
  242. package/microservices/microservice-social/src/server/index.ts +0 -441
  243. package/microservices/microservice-subscriptions/package.json +0 -28
  244. package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
  245. package/microservices/microservice-subscriptions/src/db/database.ts +0 -91
  246. package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
  247. package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
  248. package/microservices/microservice-subscriptions/src/index.ts +0 -41
  249. package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
  250. package/microservices/microservice-timesheets/package.json +0 -28
  251. package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
  252. package/microservices/microservice-timesheets/src/db/database.ts +0 -91
  253. package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
  254. package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
  255. package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
  256. package/microservices/microservice-timesheets/src/index.ts +0 -44
  257. package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
  258. package/microservices/microservice-transcriber/package.json +0 -29
  259. package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
  260. package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
  261. package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
  262. package/microservices/microservice-transcriber/src/db/database.ts +0 -91
  263. package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
  264. package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
  265. package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
  266. package/microservices/microservice-transcriber/src/index.ts +0 -43
  267. package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
  268. package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
  269. package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
  270. package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
  271. package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
  272. package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
  273. package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
  274. package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
  275. package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
  276. package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
  277. package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
  278. package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
  279. package/microservices/microservice-transcriber/src/server/index.ts +0 -199
  280. package/microservices/microservice-travel/package.json +0 -28
  281. package/microservices/microservice-travel/src/cli/index.ts +0 -505
  282. package/microservices/microservice-travel/src/db/database.ts +0 -91
  283. package/microservices/microservice-travel/src/db/migrations.ts +0 -77
  284. package/microservices/microservice-travel/src/db/travel.ts +0 -802
  285. package/microservices/microservice-travel/src/index.ts +0 -60
  286. package/microservices/microservice-travel/src/mcp/index.ts +0 -495
  287. package/microservices/microservice-wiki/package.json +0 -28
  288. package/microservices/microservice-wiki/src/cli/index.ts +0 -345
  289. package/microservices/microservice-wiki/src/db/database.ts +0 -91
  290. package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
  291. package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
  292. package/microservices/microservice-wiki/src/index.ts +0 -32
  293. package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
@@ -1,393 +0,0 @@
1
- /**
2
- * Inventory CRUD operations
3
- */
4
-
5
- import { getDatabase } from "./database.js";
6
-
7
- // --- Products ---
8
-
9
- export interface Product {
10
- id: string;
11
- sku: string;
12
- name: string;
13
- description: string | null;
14
- category: string | null;
15
- unit_price: number;
16
- cost_price: number;
17
- unit: string;
18
- quantity_on_hand: number;
19
- reorder_level: number;
20
- metadata: Record<string, unknown>;
21
- created_at: string;
22
- updated_at: string;
23
- }
24
-
25
- interface ProductRow extends Omit<Product, "metadata"> {
26
- metadata: string;
27
- }
28
-
29
- function rowToProduct(row: ProductRow): Product {
30
- return { ...row, metadata: JSON.parse(row.metadata || "{}") } as Product;
31
- }
32
-
33
- export interface CreateProductInput {
34
- sku: string;
35
- name: string;
36
- description?: string;
37
- category?: string;
38
- unit_price?: number;
39
- cost_price?: number;
40
- unit?: string;
41
- quantity_on_hand?: number;
42
- reorder_level?: number;
43
- metadata?: Record<string, unknown>;
44
- }
45
-
46
- export function createProduct(input: CreateProductInput): Product {
47
- const db = getDatabase();
48
- const id = crypto.randomUUID();
49
- const metadata = JSON.stringify(input.metadata || {});
50
-
51
- db.prepare(
52
- `INSERT INTO products (id, sku, name, description, category, unit_price, cost_price, unit, quantity_on_hand, reorder_level, metadata)
53
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
54
- ).run(
55
- id,
56
- input.sku,
57
- input.name,
58
- input.description || null,
59
- input.category || null,
60
- input.unit_price || 0,
61
- input.cost_price || 0,
62
- input.unit || "each",
63
- input.quantity_on_hand || 0,
64
- input.reorder_level || 0,
65
- metadata
66
- );
67
-
68
- return getProduct(id)!;
69
- }
70
-
71
- export function getProduct(id: string): Product | null {
72
- const db = getDatabase();
73
- const row = db.prepare("SELECT * FROM products WHERE id = ? OR sku = ?").get(id, id) as ProductRow | null;
74
- return row ? rowToProduct(row) : null;
75
- }
76
-
77
- export interface ListProductsOptions {
78
- category?: string;
79
- low_stock?: boolean;
80
- search?: string;
81
- limit?: number;
82
- offset?: number;
83
- }
84
-
85
- export function listProducts(options: ListProductsOptions = {}): Product[] {
86
- const db = getDatabase();
87
- const conditions: string[] = [];
88
- const params: unknown[] = [];
89
-
90
- if (options.category) {
91
- conditions.push("category = ?");
92
- params.push(options.category);
93
- }
94
-
95
- if (options.low_stock) {
96
- conditions.push("quantity_on_hand <= reorder_level");
97
- }
98
-
99
- if (options.search) {
100
- conditions.push("(name LIKE ? OR sku LIKE ? OR description LIKE ?)");
101
- const q = `%${options.search}%`;
102
- params.push(q, q, q);
103
- }
104
-
105
- let sql = "SELECT * FROM products";
106
- if (conditions.length > 0) {
107
- sql += " WHERE " + conditions.join(" AND ");
108
- }
109
- sql += " ORDER BY name";
110
-
111
- if (options.limit) {
112
- sql += " LIMIT ?";
113
- params.push(options.limit);
114
- }
115
- if (options.offset) {
116
- sql += " OFFSET ?";
117
- params.push(options.offset);
118
- }
119
-
120
- const rows = db.prepare(sql).all(...params) as ProductRow[];
121
- return rows.map(rowToProduct);
122
- }
123
-
124
- export interface UpdateProductInput {
125
- sku?: string;
126
- name?: string;
127
- description?: string;
128
- category?: string;
129
- unit_price?: number;
130
- cost_price?: number;
131
- unit?: string;
132
- quantity_on_hand?: number;
133
- reorder_level?: number;
134
- metadata?: Record<string, unknown>;
135
- }
136
-
137
- export function updateProduct(
138
- id: string,
139
- input: UpdateProductInput
140
- ): Product | null {
141
- const db = getDatabase();
142
- const existing = getProduct(id);
143
- if (!existing) return null;
144
-
145
- const sets: string[] = [];
146
- const params: unknown[] = [];
147
-
148
- if (input.sku !== undefined) {
149
- sets.push("sku = ?");
150
- params.push(input.sku);
151
- }
152
- if (input.name !== undefined) {
153
- sets.push("name = ?");
154
- params.push(input.name);
155
- }
156
- if (input.description !== undefined) {
157
- sets.push("description = ?");
158
- params.push(input.description);
159
- }
160
- if (input.category !== undefined) {
161
- sets.push("category = ?");
162
- params.push(input.category);
163
- }
164
- if (input.unit_price !== undefined) {
165
- sets.push("unit_price = ?");
166
- params.push(input.unit_price);
167
- }
168
- if (input.cost_price !== undefined) {
169
- sets.push("cost_price = ?");
170
- params.push(input.cost_price);
171
- }
172
- if (input.unit !== undefined) {
173
- sets.push("unit = ?");
174
- params.push(input.unit);
175
- }
176
- if (input.quantity_on_hand !== undefined) {
177
- sets.push("quantity_on_hand = ?");
178
- params.push(input.quantity_on_hand);
179
- }
180
- if (input.reorder_level !== undefined) {
181
- sets.push("reorder_level = ?");
182
- params.push(input.reorder_level);
183
- }
184
- if (input.metadata !== undefined) {
185
- sets.push("metadata = ?");
186
- params.push(JSON.stringify(input.metadata));
187
- }
188
-
189
- if (sets.length === 0) return existing;
190
-
191
- sets.push("updated_at = datetime('now')");
192
- params.push(existing.id);
193
-
194
- db.prepare(
195
- `UPDATE products SET ${sets.join(", ")} WHERE id = ?`
196
- ).run(...params);
197
-
198
- return getProduct(existing.id);
199
- }
200
-
201
- export function deleteProduct(id: string): boolean {
202
- const db = getDatabase();
203
- const existing = getProduct(id);
204
- if (!existing) return false;
205
- return db.prepare("DELETE FROM products WHERE id = ?").run(existing.id).changes > 0;
206
- }
207
-
208
- // --- Stock Movements ---
209
-
210
- export interface StockMovement {
211
- id: string;
212
- product_id: string;
213
- type: "in" | "out" | "adjustment";
214
- quantity: number;
215
- reference: string | null;
216
- notes: string | null;
217
- created_at: string;
218
- }
219
-
220
- export interface RecordMovementInput {
221
- product_id: string;
222
- type: "in" | "out" | "adjustment";
223
- quantity: number;
224
- reference?: string;
225
- notes?: string;
226
- }
227
-
228
- export function recordMovement(input: RecordMovementInput): StockMovement {
229
- const db = getDatabase();
230
- const id = crypto.randomUUID();
231
-
232
- // Resolve product by id or sku
233
- const product = getProduct(input.product_id);
234
- if (!product) {
235
- throw new Error(`Product '${input.product_id}' not found.`);
236
- }
237
-
238
- db.prepare(
239
- `INSERT INTO stock_movements (id, product_id, type, quantity, reference, notes)
240
- VALUES (?, ?, ?, ?, ?, ?)`
241
- ).run(
242
- id,
243
- product.id,
244
- input.type,
245
- input.quantity,
246
- input.reference || null,
247
- input.notes || null
248
- );
249
-
250
- // Adjust quantity_on_hand
251
- let delta: number;
252
- if (input.type === "in") {
253
- delta = input.quantity;
254
- } else if (input.type === "out") {
255
- delta = -input.quantity;
256
- } else {
257
- // adjustment: quantity is the absolute adjustment (can be positive or negative)
258
- delta = input.quantity;
259
- }
260
-
261
- db.prepare(
262
- "UPDATE products SET quantity_on_hand = quantity_on_hand + ?, updated_at = datetime('now') WHERE id = ?"
263
- ).run(delta, product.id);
264
-
265
- return db.prepare("SELECT * FROM stock_movements WHERE id = ?").get(id) as StockMovement;
266
- }
267
-
268
- export interface ListMovementsOptions {
269
- product_id?: string;
270
- type?: "in" | "out" | "adjustment";
271
- from_date?: string;
272
- to_date?: string;
273
- limit?: number;
274
- }
275
-
276
- export function listMovements(options: ListMovementsOptions = {}): StockMovement[] {
277
- const db = getDatabase();
278
- const conditions: string[] = [];
279
- const params: unknown[] = [];
280
-
281
- if (options.product_id) {
282
- // Resolve product by id or sku
283
- const product = getProduct(options.product_id);
284
- if (product) {
285
- conditions.push("product_id = ?");
286
- params.push(product.id);
287
- } else {
288
- conditions.push("product_id = ?");
289
- params.push(options.product_id);
290
- }
291
- }
292
-
293
- if (options.type) {
294
- conditions.push("type = ?");
295
- params.push(options.type);
296
- }
297
-
298
- if (options.from_date) {
299
- conditions.push("created_at >= ?");
300
- params.push(options.from_date);
301
- }
302
-
303
- if (options.to_date) {
304
- conditions.push("created_at <= ?");
305
- params.push(options.to_date);
306
- }
307
-
308
- let sql = "SELECT * FROM stock_movements";
309
- if (conditions.length > 0) {
310
- sql += " WHERE " + conditions.join(" AND ");
311
- }
312
- sql += " ORDER BY created_at DESC";
313
-
314
- if (options.limit) {
315
- sql += " LIMIT ?";
316
- params.push(options.limit);
317
- }
318
-
319
- return db.prepare(sql).all(...params) as StockMovement[];
320
- }
321
-
322
- // --- Low Stock ---
323
-
324
- export function getLowStockProducts(): Product[] {
325
- return listProducts({ low_stock: true });
326
- }
327
-
328
- // --- Inventory Value ---
329
-
330
- export function getInventoryValue(): {
331
- total_products: number;
332
- total_quantity: number;
333
- total_cost_value: number;
334
- total_retail_value: number;
335
- } {
336
- const db = getDatabase();
337
-
338
- const row = db
339
- .prepare(
340
- `SELECT
341
- COUNT(*) as total_products,
342
- COALESCE(SUM(quantity_on_hand), 0) as total_quantity,
343
- COALESCE(SUM(quantity_on_hand * cost_price), 0) as total_cost_value,
344
- COALESCE(SUM(quantity_on_hand * unit_price), 0) as total_retail_value
345
- FROM products`
346
- )
347
- .get() as {
348
- total_products: number;
349
- total_quantity: number;
350
- total_cost_value: number;
351
- total_retail_value: number;
352
- };
353
-
354
- return row;
355
- }
356
-
357
- // --- Locations ---
358
-
359
- export interface Location {
360
- id: string;
361
- name: string;
362
- description: string | null;
363
- created_at: string;
364
- }
365
-
366
- export interface CreateLocationInput {
367
- name: string;
368
- description?: string;
369
- }
370
-
371
- export function createLocation(input: CreateLocationInput): Location {
372
- const db = getDatabase();
373
- const id = crypto.randomUUID();
374
-
375
- db.prepare(
376
- `INSERT INTO locations (id, name, description) VALUES (?, ?, ?)`
377
- ).run(id, input.name, input.description || null);
378
-
379
- return db.prepare("SELECT * FROM locations WHERE id = ?").get(id) as Location;
380
- }
381
-
382
- export function listLocations(search?: string): Location[] {
383
- const db = getDatabase();
384
-
385
- if (search) {
386
- const q = `%${search}%`;
387
- return db
388
- .prepare("SELECT * FROM locations WHERE name LIKE ? OR description LIKE ? ORDER BY name")
389
- .all(q, q) as Location[];
390
- }
391
-
392
- return db.prepare("SELECT * FROM locations ORDER BY name").all() as Location[];
393
- }
@@ -1,54 +0,0 @@
1
- export interface MigrationEntry {
2
- id: number;
3
- name: string;
4
- sql: string;
5
- }
6
-
7
- export const MIGRATIONS: MigrationEntry[] = [
8
- {
9
- id: 1,
10
- name: "initial_schema",
11
- sql: `
12
- CREATE TABLE IF NOT EXISTS products (
13
- id TEXT PRIMARY KEY,
14
- sku TEXT NOT NULL UNIQUE,
15
- name TEXT NOT NULL,
16
- description TEXT,
17
- category TEXT,
18
- unit_price REAL NOT NULL DEFAULT 0,
19
- cost_price REAL NOT NULL DEFAULT 0,
20
- unit TEXT NOT NULL DEFAULT 'each',
21
- quantity_on_hand REAL NOT NULL DEFAULT 0,
22
- reorder_level REAL NOT NULL DEFAULT 0,
23
- metadata TEXT NOT NULL DEFAULT '{}',
24
- created_at TEXT NOT NULL DEFAULT (datetime('now')),
25
- updated_at TEXT NOT NULL DEFAULT (datetime('now'))
26
- );
27
-
28
- CREATE TABLE IF NOT EXISTS stock_movements (
29
- id TEXT PRIMARY KEY,
30
- product_id TEXT NOT NULL REFERENCES products(id) ON DELETE CASCADE,
31
- type TEXT NOT NULL CHECK(type IN ('in', 'out', 'adjustment')),
32
- quantity REAL NOT NULL,
33
- reference TEXT,
34
- notes TEXT,
35
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
36
- );
37
-
38
- CREATE TABLE IF NOT EXISTS locations (
39
- id TEXT PRIMARY KEY,
40
- name TEXT NOT NULL,
41
- description TEXT,
42
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
43
- );
44
-
45
- CREATE INDEX IF NOT EXISTS idx_products_sku ON products(sku);
46
- CREATE INDEX IF NOT EXISTS idx_products_name ON products(name);
47
- CREATE INDEX IF NOT EXISTS idx_products_category ON products(category);
48
- CREATE INDEX IF NOT EXISTS idx_stock_movements_product ON stock_movements(product_id);
49
- CREATE INDEX IF NOT EXISTS idx_stock_movements_type ON stock_movements(type);
50
- CREATE INDEX IF NOT EXISTS idx_stock_movements_created ON stock_movements(created_at);
51
- CREATE INDEX IF NOT EXISTS idx_locations_name ON locations(name);
52
- `,
53
- },
54
- ];
@@ -1,28 +0,0 @@
1
- /**
2
- * microservice-inventory — Inventory management microservice
3
- */
4
-
5
- export {
6
- createProduct,
7
- getProduct,
8
- listProducts,
9
- updateProduct,
10
- deleteProduct,
11
- recordMovement,
12
- listMovements,
13
- getLowStockProducts,
14
- getInventoryValue,
15
- createLocation,
16
- listLocations,
17
- type Product,
18
- type CreateProductInput,
19
- type UpdateProductInput,
20
- type ListProductsOptions,
21
- type StockMovement,
22
- type RecordMovementInput,
23
- type ListMovementsOptions,
24
- type Location,
25
- type CreateLocationInput,
26
- } from "./db/inventory.js";
27
-
28
- export { getDatabase, closeDatabase } from "./db/database.js";
@@ -1,250 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
- import { z } from "zod";
6
- import {
7
- createProduct,
8
- getProduct,
9
- listProducts,
10
- updateProduct,
11
- deleteProduct,
12
- recordMovement,
13
- listMovements,
14
- getLowStockProducts,
15
- getInventoryValue,
16
- createLocation,
17
- listLocations,
18
- } from "../db/inventory.js";
19
-
20
- const server = new McpServer({
21
- name: "microservice-inventory",
22
- version: "0.0.1",
23
- });
24
-
25
- // --- Products ---
26
-
27
- server.registerTool(
28
- "create_product",
29
- {
30
- title: "Create Product",
31
- description: "Create a new product in inventory.",
32
- inputSchema: {
33
- sku: z.string(),
34
- name: z.string(),
35
- description: z.string().optional(),
36
- category: z.string().optional(),
37
- unit_price: z.number().optional(),
38
- cost_price: z.number().optional(),
39
- unit: z.string().optional(),
40
- quantity_on_hand: z.number().optional(),
41
- reorder_level: z.number().optional(),
42
- },
43
- },
44
- async (params) => {
45
- const product = createProduct(params);
46
- return { content: [{ type: "text", text: JSON.stringify(product, null, 2) }] };
47
- }
48
- );
49
-
50
- server.registerTool(
51
- "get_product",
52
- {
53
- title: "Get Product",
54
- description: "Get a product by ID or SKU.",
55
- inputSchema: { id: z.string() },
56
- },
57
- async ({ id }) => {
58
- const product = getProduct(id);
59
- if (!product) {
60
- return { content: [{ type: "text", text: `Product '${id}' not found.` }], isError: true };
61
- }
62
- return { content: [{ type: "text", text: JSON.stringify(product, null, 2) }] };
63
- }
64
- );
65
-
66
- server.registerTool(
67
- "list_products",
68
- {
69
- title: "List Products",
70
- description: "List products with optional filters.",
71
- inputSchema: {
72
- category: z.string().optional(),
73
- low_stock: z.boolean().optional(),
74
- search: z.string().optional(),
75
- limit: z.number().optional(),
76
- },
77
- },
78
- async (params) => {
79
- const products = listProducts(params);
80
- return {
81
- content: [
82
- { type: "text", text: JSON.stringify({ products, count: products.length }, null, 2) },
83
- ],
84
- };
85
- }
86
- );
87
-
88
- server.registerTool(
89
- "update_product",
90
- {
91
- title: "Update Product",
92
- description: "Update an existing product.",
93
- inputSchema: {
94
- id: z.string(),
95
- sku: z.string().optional(),
96
- name: z.string().optional(),
97
- description: z.string().optional(),
98
- category: z.string().optional(),
99
- unit_price: z.number().optional(),
100
- cost_price: z.number().optional(),
101
- unit: z.string().optional(),
102
- reorder_level: z.number().optional(),
103
- },
104
- },
105
- async ({ id, ...input }) => {
106
- const product = updateProduct(id, input);
107
- if (!product) {
108
- return { content: [{ type: "text", text: `Product '${id}' not found.` }], isError: true };
109
- }
110
- return { content: [{ type: "text", text: JSON.stringify(product, null, 2) }] };
111
- }
112
- );
113
-
114
- server.registerTool(
115
- "delete_product",
116
- {
117
- title: "Delete Product",
118
- description: "Delete a product by ID or SKU.",
119
- inputSchema: { id: z.string() },
120
- },
121
- async ({ id }) => {
122
- const deleted = deleteProduct(id);
123
- return { content: [{ type: "text", text: JSON.stringify({ id, deleted }) }] };
124
- }
125
- );
126
-
127
- // --- Stock Movements ---
128
-
129
- server.registerTool(
130
- "record_movement",
131
- {
132
- title: "Record Stock Movement",
133
- description: "Record a stock movement (in, out, or adjustment). Automatically adjusts quantity on hand.",
134
- inputSchema: {
135
- product_id: z.string(),
136
- type: z.enum(["in", "out", "adjustment"]),
137
- quantity: z.number(),
138
- reference: z.string().optional(),
139
- notes: z.string().optional(),
140
- },
141
- },
142
- async (params) => {
143
- const movement = recordMovement(params);
144
- return { content: [{ type: "text", text: JSON.stringify(movement, null, 2) }] };
145
- }
146
- );
147
-
148
- server.registerTool(
149
- "list_movements",
150
- {
151
- title: "List Stock Movements",
152
- description: "List stock movements with optional filters.",
153
- inputSchema: {
154
- product_id: z.string().optional(),
155
- type: z.enum(["in", "out", "adjustment"]).optional(),
156
- from_date: z.string().optional(),
157
- to_date: z.string().optional(),
158
- limit: z.number().optional(),
159
- },
160
- },
161
- async (params) => {
162
- const movements = listMovements(params);
163
- return {
164
- content: [
165
- { type: "text", text: JSON.stringify({ movements, count: movements.length }, null, 2) },
166
- ],
167
- };
168
- }
169
- );
170
-
171
- // --- Low Stock ---
172
-
173
- server.registerTool(
174
- "low_stock_products",
175
- {
176
- title: "Low Stock Products",
177
- description: "Get all products at or below their reorder level.",
178
- inputSchema: {},
179
- },
180
- async () => {
181
- const products = getLowStockProducts();
182
- return {
183
- content: [
184
- { type: "text", text: JSON.stringify({ products, count: products.length }, null, 2) },
185
- ],
186
- };
187
- }
188
- );
189
-
190
- // --- Inventory Value ---
191
-
192
- server.registerTool(
193
- "inventory_value",
194
- {
195
- title: "Inventory Value",
196
- description: "Get total inventory value (cost and retail).",
197
- inputSchema: {},
198
- },
199
- async () => {
200
- const value = getInventoryValue();
201
- return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
202
- }
203
- );
204
-
205
- // --- Locations ---
206
-
207
- server.registerTool(
208
- "create_location",
209
- {
210
- title: "Create Location",
211
- description: "Create a new inventory location.",
212
- inputSchema: {
213
- name: z.string(),
214
- description: z.string().optional(),
215
- },
216
- },
217
- async (params) => {
218
- const location = createLocation(params);
219
- return { content: [{ type: "text", text: JSON.stringify(location, null, 2) }] };
220
- }
221
- );
222
-
223
- server.registerTool(
224
- "list_locations",
225
- {
226
- title: "List Locations",
227
- description: "List all inventory locations.",
228
- inputSchema: { search: z.string().optional() },
229
- },
230
- async ({ search }) => {
231
- const locations = listLocations(search);
232
- return {
233
- content: [
234
- { type: "text", text: JSON.stringify({ locations, count: locations.length }, null, 2) },
235
- ],
236
- };
237
- }
238
- );
239
-
240
- // --- Start ---
241
- async function main() {
242
- const transport = new StdioServerTransport();
243
- await server.connect(transport);
244
- console.error("microservice-inventory MCP server running on stdio");
245
- }
246
-
247
- main().catch((error) => {
248
- console.error("Fatal error:", error);
249
- process.exit(1);
250
- });