@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,93 +0,0 @@
1
- /**
2
- * Database connection for microservice-ads
3
- */
4
-
5
- import { Database } from "bun:sqlite";
6
- import { existsSync, mkdirSync } from "node:fs";
7
- import { dirname, join, resolve } from "node:path";
8
- import { MIGRATIONS } from "./migrations.js";
9
-
10
- let _db: Database | null = null;
11
-
12
- function getDbPath(): string {
13
- // Environment variable override
14
- if (process.env["MICROSERVICES_DIR"]) {
15
- return join(process.env["MICROSERVICES_DIR"], "microservice-ads", "data.db");
16
- }
17
-
18
- // Check for .microservices in current or parent directories
19
- let dir = resolve(process.cwd());
20
- while (true) {
21
- const candidate = join(dir, ".microservices", "microservice-ads", "data.db");
22
- const msDir = join(dir, ".microservices");
23
- if (existsSync(msDir)) return candidate;
24
- const parent = dirname(dir);
25
- if (parent === dir) break;
26
- dir = parent;
27
- }
28
-
29
- // Global fallback
30
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
31
- return join(home, ".microservices", "microservice-ads", "data.db");
32
- }
33
-
34
- function ensureDir(filePath: string): void {
35
- const dir = dirname(resolve(filePath));
36
- if (!existsSync(dir)) {
37
- mkdirSync(dir, { recursive: true });
38
- }
39
- }
40
-
41
- export function getDatabase(): Database {
42
- if (_db) return _db;
43
-
44
- const dbPath = getDbPath();
45
- ensureDir(dbPath);
46
-
47
- _db = new Database(dbPath);
48
- _db.exec("PRAGMA journal_mode = WAL");
49
- _db.exec("PRAGMA foreign_keys = ON");
50
-
51
- // Create migrations table
52
- _db.exec(`
53
- CREATE TABLE IF NOT EXISTS _migrations (
54
- id INTEGER PRIMARY KEY,
55
- name TEXT NOT NULL,
56
- applied_at TEXT NOT NULL DEFAULT (datetime('now'))
57
- )
58
- `);
59
-
60
- // Apply pending migrations
61
- const applied = _db
62
- .query("SELECT id FROM _migrations ORDER BY id")
63
- .all() as { id: number }[];
64
- const appliedIds = new Set(applied.map((r) => r.id));
65
-
66
- for (const migration of MIGRATIONS) {
67
- if (appliedIds.has(migration.id)) continue;
68
-
69
- _db.exec("BEGIN");
70
- try {
71
- _db.exec(migration.sql);
72
- _db.prepare("INSERT INTO _migrations (id, name) VALUES (?, ?)").run(
73
- migration.id,
74
- migration.name
75
- );
76
- _db.exec("COMMIT");
77
- } catch (error) {
78
- _db.exec("ROLLBACK");
79
- throw new Error(
80
- `Migration ${migration.id} (${migration.name}) failed: ${error instanceof Error ? error.message : String(error)}`
81
- );
82
- }
83
- }
84
-
85
- return _db;
86
- }
87
-
88
- export function closeDatabase(): void {
89
- if (_db) {
90
- _db.close();
91
- _db = null;
92
- }
93
- }
@@ -1,60 +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 campaigns (
13
- id TEXT PRIMARY KEY,
14
- platform TEXT NOT NULL CHECK (platform IN ('google', 'meta', 'linkedin', 'tiktok')),
15
- name TEXT NOT NULL,
16
- status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'active', 'paused', 'completed')),
17
- budget_daily REAL NOT NULL DEFAULT 0,
18
- budget_total REAL NOT NULL DEFAULT 0,
19
- spend REAL NOT NULL DEFAULT 0,
20
- impressions INTEGER NOT NULL DEFAULT 0,
21
- clicks INTEGER NOT NULL DEFAULT 0,
22
- conversions INTEGER NOT NULL DEFAULT 0,
23
- roas REAL NOT NULL DEFAULT 0,
24
- start_date TEXT,
25
- end_date TEXT,
26
- created_at TEXT NOT NULL DEFAULT (datetime('now')),
27
- updated_at TEXT NOT NULL DEFAULT (datetime('now')),
28
- metadata TEXT NOT NULL DEFAULT '{}'
29
- );
30
-
31
- CREATE TABLE IF NOT EXISTS ad_groups (
32
- id TEXT PRIMARY KEY,
33
- campaign_id TEXT NOT NULL REFERENCES campaigns(id) ON DELETE CASCADE,
34
- name TEXT NOT NULL,
35
- targeting TEXT NOT NULL DEFAULT '{}',
36
- status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'active', 'paused', 'completed')),
37
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
38
- );
39
-
40
- CREATE TABLE IF NOT EXISTS ads (
41
- id TEXT PRIMARY KEY,
42
- ad_group_id TEXT NOT NULL REFERENCES ad_groups(id) ON DELETE CASCADE,
43
- headline TEXT NOT NULL,
44
- description TEXT,
45
- creative_url TEXT,
46
- status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'active', 'paused', 'completed')),
47
- metrics TEXT NOT NULL DEFAULT '{}',
48
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
49
- );
50
-
51
- CREATE INDEX IF NOT EXISTS idx_campaigns_platform ON campaigns(platform);
52
- CREATE INDEX IF NOT EXISTS idx_campaigns_status ON campaigns(status);
53
- CREATE INDEX IF NOT EXISTS idx_campaigns_name ON campaigns(name);
54
- CREATE INDEX IF NOT EXISTS idx_ad_groups_campaign ON ad_groups(campaign_id);
55
- CREATE INDEX IF NOT EXISTS idx_ad_groups_status ON ad_groups(status);
56
- CREATE INDEX IF NOT EXISTS idx_ads_ad_group ON ads(ad_group_id);
57
- CREATE INDEX IF NOT EXISTS idx_ads_status ON ads(status);
58
- `,
59
- },
60
- ];
@@ -1,39 +0,0 @@
1
- /**
2
- * microservice-ads — Ad campaign management microservice
3
- */
4
-
5
- export {
6
- createCampaign,
7
- getCampaign,
8
- listCampaigns,
9
- updateCampaign,
10
- deleteCampaign,
11
- pauseCampaign,
12
- resumeCampaign,
13
- countCampaigns,
14
- getCampaignStats,
15
- getSpendByPlatform,
16
- getPlatforms,
17
- createAdGroup,
18
- getAdGroup,
19
- listAdGroups,
20
- deleteAdGroup,
21
- createAd,
22
- getAd,
23
- listAds,
24
- deleteAd,
25
- type Campaign,
26
- type CreateCampaignInput,
27
- type UpdateCampaignInput,
28
- type ListCampaignsOptions,
29
- type Platform,
30
- type CampaignStatus,
31
- type AdGroup,
32
- type CreateAdGroupInput,
33
- type Ad,
34
- type CreateAdInput,
35
- type CampaignStats,
36
- type SpendByPlatform,
37
- } from "./db/campaigns.js";
38
-
39
- export { getDatabase, closeDatabase } from "./db/database.js";
@@ -1,480 +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
- createCampaign,
8
- getCampaign,
9
- listCampaigns,
10
- updateCampaign,
11
- deleteCampaign,
12
- pauseCampaign,
13
- resumeCampaign,
14
- getCampaignStats,
15
- getSpendByPlatform,
16
- getPlatforms,
17
- createAdGroup,
18
- listAdGroups,
19
- createAd,
20
- listAds,
21
- bulkPause,
22
- bulkResume,
23
- getRankedCampaigns,
24
- checkBudgetStatus,
25
- comparePlatforms,
26
- exportCampaigns,
27
- cloneCampaign,
28
- getBudgetRemaining,
29
- getAdGroupStats,
30
- } from "../db/campaigns.js";
31
-
32
- const server = new McpServer({
33
- name: "microservice-ads",
34
- version: "0.0.1",
35
- });
36
-
37
- const PlatformEnum = z.enum(["google", "meta", "linkedin", "tiktok"]);
38
- const StatusEnum = z.enum(["draft", "active", "paused", "completed"]);
39
-
40
- // --- Campaigns ---
41
-
42
- server.registerTool(
43
- "create_campaign",
44
- {
45
- title: "Create Campaign",
46
- description: "Create a new ad campaign.",
47
- inputSchema: {
48
- platform: PlatformEnum,
49
- name: z.string(),
50
- status: StatusEnum.optional(),
51
- budget_daily: z.number().optional(),
52
- budget_total: z.number().optional(),
53
- start_date: z.string().optional(),
54
- end_date: z.string().optional(),
55
- metadata: z.record(z.unknown()).optional(),
56
- },
57
- },
58
- async (params) => {
59
- const campaign = createCampaign(params);
60
- return { content: [{ type: "text", text: JSON.stringify(campaign, null, 2) }] };
61
- }
62
- );
63
-
64
- server.registerTool(
65
- "get_campaign",
66
- {
67
- title: "Get Campaign",
68
- description: "Get a campaign by ID.",
69
- inputSchema: { id: z.string() },
70
- },
71
- async ({ id }) => {
72
- const campaign = getCampaign(id);
73
- if (!campaign) {
74
- return { content: [{ type: "text", text: `Campaign '${id}' not found.` }], isError: true };
75
- }
76
- return { content: [{ type: "text", text: JSON.stringify(campaign, null, 2) }] };
77
- }
78
- );
79
-
80
- server.registerTool(
81
- "list_campaigns",
82
- {
83
- title: "List Campaigns",
84
- description: "List campaigns with optional filters.",
85
- inputSchema: {
86
- platform: PlatformEnum.optional(),
87
- status: StatusEnum.optional(),
88
- search: z.string().optional(),
89
- limit: z.number().optional(),
90
- },
91
- },
92
- async (params) => {
93
- const campaigns = listCampaigns(params);
94
- return {
95
- content: [
96
- {
97
- type: "text",
98
- text: JSON.stringify({ campaigns, count: campaigns.length }, null, 2),
99
- },
100
- ],
101
- };
102
- }
103
- );
104
-
105
- server.registerTool(
106
- "update_campaign",
107
- {
108
- title: "Update Campaign",
109
- description: "Update an existing campaign.",
110
- inputSchema: {
111
- id: z.string(),
112
- platform: PlatformEnum.optional(),
113
- name: z.string().optional(),
114
- status: StatusEnum.optional(),
115
- budget_daily: z.number().optional(),
116
- budget_total: z.number().optional(),
117
- spend: z.number().optional(),
118
- impressions: z.number().optional(),
119
- clicks: z.number().optional(),
120
- conversions: z.number().optional(),
121
- roas: z.number().optional(),
122
- start_date: z.string().optional(),
123
- end_date: z.string().optional(),
124
- metadata: z.record(z.unknown()).optional(),
125
- },
126
- },
127
- async ({ id, ...input }) => {
128
- const campaign = updateCampaign(id, input);
129
- if (!campaign) {
130
- return { content: [{ type: "text", text: `Campaign '${id}' not found.` }], isError: true };
131
- }
132
- return { content: [{ type: "text", text: JSON.stringify(campaign, null, 2) }] };
133
- }
134
- );
135
-
136
- server.registerTool(
137
- "delete_campaign",
138
- {
139
- title: "Delete Campaign",
140
- description: "Delete a campaign by ID.",
141
- inputSchema: { id: z.string() },
142
- },
143
- async ({ id }) => {
144
- const deleted = deleteCampaign(id);
145
- return { content: [{ type: "text", text: JSON.stringify({ id, deleted }) }] };
146
- }
147
- );
148
-
149
- server.registerTool(
150
- "pause_campaign",
151
- {
152
- title: "Pause Campaign",
153
- description: "Pause an active campaign.",
154
- inputSchema: { id: z.string() },
155
- },
156
- async ({ id }) => {
157
- const campaign = pauseCampaign(id);
158
- if (!campaign) {
159
- return { content: [{ type: "text", text: `Campaign '${id}' not found.` }], isError: true };
160
- }
161
- return { content: [{ type: "text", text: JSON.stringify(campaign, null, 2) }] };
162
- }
163
- );
164
-
165
- server.registerTool(
166
- "resume_campaign",
167
- {
168
- title: "Resume Campaign",
169
- description: "Resume a paused campaign.",
170
- inputSchema: { id: z.string() },
171
- },
172
- async ({ id }) => {
173
- const campaign = resumeCampaign(id);
174
- if (!campaign) {
175
- return { content: [{ type: "text", text: `Campaign '${id}' not found.` }], isError: true };
176
- }
177
- return { content: [{ type: "text", text: JSON.stringify(campaign, null, 2) }] };
178
- }
179
- );
180
-
181
- server.registerTool(
182
- "campaign_stats",
183
- {
184
- title: "Campaign Stats",
185
- description: "Get aggregate campaign statistics.",
186
- inputSchema: {},
187
- },
188
- async () => {
189
- const stats = getCampaignStats();
190
- return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
191
- }
192
- );
193
-
194
- server.registerTool(
195
- "spend_by_platform",
196
- {
197
- title: "Spend by Platform",
198
- description: "Get total spend broken down by platform.",
199
- inputSchema: {},
200
- },
201
- async () => {
202
- const spend = getSpendByPlatform();
203
- return { content: [{ type: "text", text: JSON.stringify(spend, null, 2) }] };
204
- }
205
- );
206
-
207
- server.registerTool(
208
- "list_platforms",
209
- {
210
- title: "List Platforms",
211
- description: "List platforms that have campaigns.",
212
- inputSchema: {},
213
- },
214
- async () => {
215
- const platforms = getPlatforms();
216
- return { content: [{ type: "text", text: JSON.stringify(platforms, null, 2) }] };
217
- }
218
- );
219
-
220
- server.registerTool(
221
- "list_providers",
222
- {
223
- title: "List Providers",
224
- description: "List all supported ad providers.",
225
- inputSchema: {},
226
- },
227
- async () => {
228
- const providers = ["google", "meta", "linkedin", "tiktok"];
229
- return { content: [{ type: "text", text: JSON.stringify(providers, null, 2) }] };
230
- }
231
- );
232
-
233
- // --- Ad Groups ---
234
-
235
- server.registerTool(
236
- "create_ad_group",
237
- {
238
- title: "Create Ad Group",
239
- description: "Create a new ad group within a campaign.",
240
- inputSchema: {
241
- campaign_id: z.string(),
242
- name: z.string(),
243
- targeting: z.record(z.unknown()).optional(),
244
- status: StatusEnum.optional(),
245
- },
246
- },
247
- async (params) => {
248
- const adGroup = createAdGroup(params);
249
- return { content: [{ type: "text", text: JSON.stringify(adGroup, null, 2) }] };
250
- }
251
- );
252
-
253
- server.registerTool(
254
- "list_ad_groups",
255
- {
256
- title: "List Ad Groups",
257
- description: "List ad groups, optionally filtered by campaign.",
258
- inputSchema: {
259
- campaign_id: z.string().optional(),
260
- },
261
- },
262
- async ({ campaign_id }) => {
263
- const adGroups = listAdGroups(campaign_id);
264
- return {
265
- content: [
266
- {
267
- type: "text",
268
- text: JSON.stringify({ ad_groups: adGroups, count: adGroups.length }, null, 2),
269
- },
270
- ],
271
- };
272
- }
273
- );
274
-
275
- // --- Ads ---
276
-
277
- server.registerTool(
278
- "create_ad",
279
- {
280
- title: "Create Ad",
281
- description: "Create a new ad within an ad group.",
282
- inputSchema: {
283
- ad_group_id: z.string(),
284
- headline: z.string(),
285
- description: z.string().optional(),
286
- creative_url: z.string().optional(),
287
- status: StatusEnum.optional(),
288
- metrics: z.record(z.unknown()).optional(),
289
- },
290
- },
291
- async (params) => {
292
- const ad = createAd(params);
293
- return { content: [{ type: "text", text: JSON.stringify(ad, null, 2) }] };
294
- }
295
- );
296
-
297
- server.registerTool(
298
- "list_ads",
299
- {
300
- title: "List Ads",
301
- description: "List ads, optionally filtered by ad group.",
302
- inputSchema: {
303
- ad_group_id: z.string().optional(),
304
- },
305
- },
306
- async ({ ad_group_id }) => {
307
- const ads = listAds(ad_group_id);
308
- return {
309
- content: [
310
- {
311
- type: "text",
312
- text: JSON.stringify({ ads, count: ads.length }, null, 2),
313
- },
314
- ],
315
- };
316
- }
317
- );
318
-
319
- // --- QoL Tools ---
320
-
321
- // 1. Bulk pause/resume
322
- server.registerTool(
323
- "bulk_pause_campaigns",
324
- {
325
- title: "Bulk Pause Campaigns",
326
- description: "Pause all active campaigns on a specific platform.",
327
- inputSchema: {
328
- platform: PlatformEnum,
329
- },
330
- },
331
- async ({ platform }) => {
332
- const result = bulkPause(platform);
333
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
334
- }
335
- );
336
-
337
- server.registerTool(
338
- "bulk_resume_campaigns",
339
- {
340
- title: "Bulk Resume Campaigns",
341
- description: "Resume all paused campaigns on a specific platform.",
342
- inputSchema: {
343
- platform: PlatformEnum,
344
- },
345
- },
346
- async ({ platform }) => {
347
- const result = bulkResume(platform);
348
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
349
- }
350
- );
351
-
352
- // 2. Performance ranking
353
- server.registerTool(
354
- "ranked_campaigns",
355
- {
356
- title: "Ranked Campaigns",
357
- description: "Get campaigns ranked by a performance metric (roas, ctr, or spend).",
358
- inputSchema: {
359
- sort_by: z.enum(["roas", "ctr", "spend"]).optional(),
360
- limit: z.number().optional(),
361
- },
362
- },
363
- async ({ sort_by, limit }) => {
364
- const campaigns = getRankedCampaigns(sort_by || "roas", limit || 10);
365
- return { content: [{ type: "text", text: JSON.stringify(campaigns, null, 2) }] };
366
- }
367
- );
368
-
369
- // 3. Budget alerts
370
- server.registerTool(
371
- "check_budget",
372
- {
373
- title: "Check Budget Status",
374
- description: "Check if a campaign is over budget and get remaining budget details.",
375
- inputSchema: { id: z.string() },
376
- },
377
- async ({ id }) => {
378
- const status = checkBudgetStatus(id);
379
- if (!status) {
380
- return { content: [{ type: "text", text: `Campaign '${id}' not found.` }], isError: true };
381
- }
382
- return { content: [{ type: "text", text: JSON.stringify(status, null, 2) }] };
383
- }
384
- );
385
-
386
- // 4. Cross-platform comparison
387
- server.registerTool(
388
- "compare_platforms",
389
- {
390
- title: "Compare Platforms",
391
- description: "Compare ROAS, CPA, and spend across all platforms side-by-side.",
392
- inputSchema: {},
393
- },
394
- async () => {
395
- const comparison = comparePlatforms();
396
- return { content: [{ type: "text", text: JSON.stringify(comparison, null, 2) }] };
397
- }
398
- );
399
-
400
- // 5. CSV export
401
- server.registerTool(
402
- "export_campaigns",
403
- {
404
- title: "Export Campaigns",
405
- description: "Export all campaigns in CSV or JSON format.",
406
- inputSchema: {
407
- format: z.enum(["csv", "json"]).optional(),
408
- },
409
- },
410
- async ({ format }) => {
411
- const output = exportCampaigns(format || "csv");
412
- return { content: [{ type: "text", text: output }] };
413
- }
414
- );
415
-
416
- // 6. Campaign cloning
417
- server.registerTool(
418
- "clone_campaign",
419
- {
420
- title: "Clone Campaign",
421
- description: "Clone a campaign with all its ad groups and ads.",
422
- inputSchema: {
423
- id: z.string(),
424
- new_name: z.string(),
425
- },
426
- },
427
- async ({ id, new_name }) => {
428
- const cloned = cloneCampaign(id, new_name);
429
- if (!cloned) {
430
- return { content: [{ type: "text", text: `Campaign '${id}' not found.` }], isError: true };
431
- }
432
- return { content: [{ type: "text", text: JSON.stringify(cloned, null, 2) }] };
433
- }
434
- );
435
-
436
- // 7. Budget remaining
437
- server.registerTool(
438
- "budget_remaining",
439
- {
440
- title: "Budget Remaining",
441
- description: "Show daily and total budget remaining for a campaign.",
442
- inputSchema: { id: z.string() },
443
- },
444
- async ({ id }) => {
445
- const remaining = getBudgetRemaining(id);
446
- if (!remaining) {
447
- return { content: [{ type: "text", text: `Campaign '${id}' not found.` }], isError: true };
448
- }
449
- return { content: [{ type: "text", text: JSON.stringify(remaining, null, 2) }] };
450
- }
451
- );
452
-
453
- // 8. Ad group stats
454
- server.registerTool(
455
- "ad_group_stats",
456
- {
457
- title: "Ad Group Stats",
458
- description: "Get aggregated metrics for all ads within an ad group.",
459
- inputSchema: { ad_group_id: z.string() },
460
- },
461
- async ({ ad_group_id }) => {
462
- const stats = getAdGroupStats(ad_group_id);
463
- if (!stats) {
464
- return { content: [{ type: "text", text: `Ad group '${ad_group_id}' not found.` }], isError: true };
465
- }
466
- return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
467
- }
468
- );
469
-
470
- // --- Start ---
471
- async function main() {
472
- const transport = new StdioServerTransport();
473
- await server.connect(transport);
474
- console.error("microservice-ads MCP server running on stdio");
475
- }
476
-
477
- main().catch((error) => {
478
- console.error("Fatal error:", error);
479
- process.exit(1);
480
- });
@@ -1,27 +0,0 @@
1
- {
2
- "name": "@hasna/microservice-analytics",
3
- "version": "0.0.1",
4
- "description": "Business analytics microservice with KPIs, dashboards, reports, and AI-powered executive summaries",
5
- "type": "module",
6
- "bin": {
7
- "microservice-analytics": "./src/cli/index.ts",
8
- "microservice-analytics-mcp": "./src/mcp/index.ts"
9
- },
10
- "exports": {
11
- ".": "./src/index.ts"
12
- },
13
- "scripts": {
14
- "dev": "bun run ./src/cli/index.ts",
15
- "test": "bun test"
16
- },
17
- "dependencies": {
18
- "@modelcontextprotocol/sdk": "^1.26.0",
19
- "commander": "^12.1.0",
20
- "zod": "^3.24.0"
21
- },
22
- "license": "Apache-2.0",
23
- "publishConfig": {
24
- "registry": "https://registry.npmjs.org",
25
- "access": "public"
26
- }
27
- }