@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,609 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import { Command } from "commander";
4
- import {
5
- createPayment,
6
- getPayment,
7
- listPayments,
8
- updatePayment,
9
- deletePayment,
10
- refundPayment,
11
- searchPayments,
12
- getRevenueReport,
13
- getRevenueByCustomer,
14
- reconcileWithInvoice,
15
- getPaymentStats,
16
- getBalanceByProvider,
17
- autoReconcile,
18
- retryPayment,
19
- listRetries,
20
- getRetryStats,
21
- convertCurrency,
22
- feeAnalysis,
23
- declineReport,
24
- addDisputeEvidence,
25
- splitPayment,
26
- revenueForecast,
27
- findReconciliationGaps,
28
- type PaymentType,
29
- type PaymentStatus,
30
- type PaymentProvider,
31
- } from "../db/payments.js";
32
- import {
33
- listDisputes,
34
- respondDispute,
35
- type DisputeStatus,
36
- } from "../db/payments.js";
37
- import {
38
- createPayout,
39
- listPayouts,
40
- type PayoutStatus,
41
- } from "../db/payments.js";
42
-
43
- const program = new Command();
44
-
45
- program
46
- .name("microservice-payments")
47
- .description("Payment processing and tracking microservice")
48
- .version("0.0.1");
49
-
50
- // --- Payments ---
51
-
52
- const paymentCmd = program
53
- .command("payment")
54
- .description("Payment management");
55
-
56
- paymentCmd
57
- .command("create")
58
- .description("Create a new payment")
59
- .requiredOption("--type <type>", "Payment type (charge/refund/transfer/payout)")
60
- .requiredOption("--amount <amount>", "Amount")
61
- .option("--currency <currency>", "Currency code", "USD")
62
- .option("--status <status>", "Status")
63
- .option("--customer-name <name>", "Customer name")
64
- .option("--customer-email <email>", "Customer email")
65
- .option("--description <desc>", "Description")
66
- .option("--provider <provider>", "Provider (stripe/square/mercury/manual)")
67
- .option("--provider-id <id>", "Provider transaction ID")
68
- .option("--invoice-id <id>", "Invoice ID")
69
- .option("--json", "Output as JSON", false)
70
- .action((opts) => {
71
- const payment = createPayment({
72
- type: opts.type as PaymentType,
73
- amount: parseFloat(opts.amount),
74
- currency: opts.currency,
75
- status: opts.status as PaymentStatus | undefined,
76
- customer_name: opts.customerName,
77
- customer_email: opts.customerEmail,
78
- description: opts.description,
79
- provider: opts.provider as PaymentProvider | undefined,
80
- provider_id: opts.providerId,
81
- invoice_id: opts.invoiceId,
82
- });
83
-
84
- if (opts.json) {
85
- console.log(JSON.stringify(payment, null, 2));
86
- } else {
87
- console.log(`Created payment: ${payment.type} $${payment.amount} ${payment.currency} (${payment.id})`);
88
- }
89
- });
90
-
91
- paymentCmd
92
- .command("list")
93
- .description("List payments")
94
- .option("--status <status>", "Filter by status")
95
- .option("--type <type>", "Filter by type")
96
- .option("--provider <provider>", "Filter by provider")
97
- .option("--limit <n>", "Limit results")
98
- .option("--json", "Output as JSON", false)
99
- .action((opts) => {
100
- const payments = listPayments({
101
- status: opts.status as PaymentStatus | undefined,
102
- type: opts.type as PaymentType | undefined,
103
- provider: opts.provider as PaymentProvider | undefined,
104
- limit: opts.limit ? parseInt(opts.limit) : undefined,
105
- });
106
-
107
- if (opts.json) {
108
- console.log(JSON.stringify(payments, null, 2));
109
- } else {
110
- if (payments.length === 0) {
111
- console.log("No payments found.");
112
- return;
113
- }
114
- for (const p of payments) {
115
- const customer = p.customer_name || p.customer_email || "—";
116
- console.log(` ${p.type} $${p.amount} ${p.currency} [${p.status}] ${customer} (${p.id})`);
117
- }
118
- console.log(`\n${payments.length} payment(s)`);
119
- }
120
- });
121
-
122
- paymentCmd
123
- .command("get")
124
- .description("Get a payment by ID")
125
- .argument("<id>", "Payment ID")
126
- .option("--json", "Output as JSON", false)
127
- .action((id, opts) => {
128
- const payment = getPayment(id);
129
- if (!payment) {
130
- console.error(`Payment '${id}' not found.`);
131
- process.exit(1);
132
- }
133
-
134
- if (opts.json) {
135
- console.log(JSON.stringify(payment, null, 2));
136
- } else {
137
- console.log(`${payment.type} — $${payment.amount} ${payment.currency}`);
138
- console.log(` Status: ${payment.status}`);
139
- if (payment.customer_name) console.log(` Customer: ${payment.customer_name}`);
140
- if (payment.customer_email) console.log(` Email: ${payment.customer_email}`);
141
- if (payment.description) console.log(` Description: ${payment.description}`);
142
- if (payment.provider) console.log(` Provider: ${payment.provider}`);
143
- if (payment.invoice_id) console.log(` Invoice: ${payment.invoice_id}`);
144
- console.log(` Created: ${payment.created_at}`);
145
- }
146
- });
147
-
148
- paymentCmd
149
- .command("refund")
150
- .description("Refund a payment")
151
- .argument("<id>", "Payment ID to refund")
152
- .option("--amount <amount>", "Partial refund amount")
153
- .option("--json", "Output as JSON", false)
154
- .action((id, opts) => {
155
- const refund = refundPayment(id, opts.amount ? parseFloat(opts.amount) : undefined);
156
- if (!refund) {
157
- console.error(`Cannot refund payment '${id}' — not found or not succeeded.`);
158
- process.exit(1);
159
- }
160
-
161
- if (opts.json) {
162
- console.log(JSON.stringify(refund, null, 2));
163
- } else {
164
- console.log(`Refunded $${refund.amount} ${refund.currency} (${refund.id})`);
165
- }
166
- });
167
-
168
- // --- Payment Retry ---
169
-
170
- paymentCmd
171
- .command("retry")
172
- .description("Retry a failed payment")
173
- .argument("<id>", "Payment ID to retry")
174
- .option("--json", "Output as JSON", false)
175
- .action((id, opts) => {
176
- const attempt = retryPayment(id);
177
- if (!attempt) {
178
- console.error(`Cannot retry payment '${id}' — not found or not failed.`);
179
- process.exit(1);
180
- }
181
-
182
- if (opts.json) {
183
- console.log(JSON.stringify(attempt, null, 2));
184
- } else {
185
- console.log(`Retry attempt #${attempt.attempt} for payment ${id}: ${attempt.status}`);
186
- }
187
- });
188
-
189
- paymentCmd
190
- .command("retries")
191
- .description("List retry attempts for a payment")
192
- .argument("<paymentId>", "Payment ID")
193
- .option("--json", "Output as JSON", false)
194
- .action((paymentId, opts) => {
195
- const retries = listRetries(paymentId);
196
-
197
- if (opts.json) {
198
- console.log(JSON.stringify(retries, null, 2));
199
- } else {
200
- if (retries.length === 0) {
201
- console.log("No retry attempts found.");
202
- return;
203
- }
204
- for (const r of retries) {
205
- console.log(` Attempt #${r.attempt} [${r.status}] ${r.attempted_at || ""} ${r.error || ""}`);
206
- }
207
- console.log(`\n${retries.length} retry attempt(s)`);
208
- }
209
- });
210
-
211
- // --- Payment Convert ---
212
-
213
- paymentCmd
214
- .command("convert")
215
- .description("Convert currency amount")
216
- .requiredOption("--from <currency>", "Source currency")
217
- .requiredOption("--to <currency>", "Target currency")
218
- .requiredOption("--amount <amount>", "Amount to convert")
219
- .option("--json", "Output as JSON", false)
220
- .action((opts) => {
221
- const result = convertCurrency(parseFloat(opts.amount), opts.from, opts.to);
222
- if (!result) {
223
- console.error(`Unsupported currency pair: ${opts.from} -> ${opts.to}`);
224
- process.exit(1);
225
- }
226
-
227
- if (opts.json) {
228
- console.log(JSON.stringify(result, null, 2));
229
- } else {
230
- console.log(`${result.original_amount} ${result.from} = ${result.converted_amount} ${result.to} (rate: ${result.rate})`);
231
- }
232
- });
233
-
234
- // --- Decline Report ---
235
-
236
- paymentCmd
237
- .command("decline-report")
238
- .description("Show decline analytics for failed payments")
239
- .option("--provider <provider>", "Filter by provider")
240
- .option("--json", "Output as JSON", false)
241
- .action((opts) => {
242
- const report = declineReport(opts.provider as PaymentProvider | undefined);
243
-
244
- if (opts.json) {
245
- console.log(JSON.stringify(report, null, 2));
246
- } else {
247
- if (report.entries.length === 0) {
248
- console.log("No declined payments found.");
249
- return;
250
- }
251
- console.log("Decline Report:");
252
- for (const e of report.entries) {
253
- console.log(` [${e.provider}] "${e.description || "No description"}" — ${e.count} decline(s), $${e.total_amount.toFixed(2)}`);
254
- }
255
- console.log(`\nTotal: ${report.total_declined} decline(s), $${report.total_amount.toFixed(2)}`);
256
- }
257
- });
258
-
259
- // --- Payment Split ---
260
-
261
- paymentCmd
262
- .command("split")
263
- .description("Split a payment into marketplace commission splits")
264
- .argument("<id>", "Payment ID")
265
- .requiredOption("--splits <json>", "Split percentages as JSON (e.g. '{\"vendor1\":70,\"vendor2\":30}')")
266
- .option("--json", "Output as JSON", false)
267
- .action((id, opts) => {
268
- let splits: Record<string, number>;
269
- try {
270
- splits = JSON.parse(opts.splits);
271
- } catch {
272
- console.error("Invalid JSON for --splits");
273
- process.exit(1);
274
- }
275
-
276
- const payment = splitPayment(id, splits);
277
- if (!payment) {
278
- console.error(`Payment '${id}' not found.`);
279
- process.exit(1);
280
- }
281
-
282
- if (opts.json) {
283
- console.log(JSON.stringify(payment, null, 2));
284
- } else {
285
- console.log(`Payment ${id} split recorded: ${JSON.stringify(splits)}`);
286
- }
287
- });
288
-
289
- // --- Disputes ---
290
-
291
- const disputeCmd = program
292
- .command("dispute")
293
- .description("Dispute management");
294
-
295
- disputeCmd
296
- .command("list")
297
- .description("List disputes")
298
- .option("--status <status>", "Filter by status (open/under_review/won/lost)")
299
- .option("--json", "Output as JSON", false)
300
- .action((opts) => {
301
- const disputes = listDisputes(opts.status as DisputeStatus | undefined);
302
-
303
- if (opts.json) {
304
- console.log(JSON.stringify(disputes, null, 2));
305
- } else {
306
- if (disputes.length === 0) {
307
- console.log("No disputes found.");
308
- return;
309
- }
310
- for (const d of disputes) {
311
- const amount = d.amount != null ? ` $${d.amount}` : "";
312
- console.log(` [${d.status}]${amount} — ${d.reason || "No reason"} (${d.id})`);
313
- }
314
- console.log(`\n${disputes.length} dispute(s)`);
315
- }
316
- });
317
-
318
- disputeCmd
319
- .command("respond")
320
- .description("Respond to a dispute")
321
- .argument("<id>", "Dispute ID")
322
- .requiredOption("--status <status>", "New status (open/under_review/won/lost)")
323
- .option("--json", "Output as JSON", false)
324
- .action((id, opts) => {
325
- const dispute = respondDispute(id, { status: opts.status as DisputeStatus });
326
- if (!dispute) {
327
- console.error(`Dispute '${id}' not found.`);
328
- process.exit(1);
329
- }
330
-
331
- if (opts.json) {
332
- console.log(JSON.stringify(dispute, null, 2));
333
- } else {
334
- console.log(`Dispute ${id} updated to: ${dispute.status}`);
335
- }
336
- });
337
-
338
- disputeCmd
339
- .command("add-evidence")
340
- .description("Add evidence to a dispute")
341
- .argument("<id>", "Dispute ID")
342
- .requiredOption("--description <desc>", "Evidence description")
343
- .option("--file-ref <path>", "File reference path")
344
- .option("--json", "Output as JSON", false)
345
- .action((id, opts) => {
346
- const dispute = addDisputeEvidence(id, opts.description, opts.fileRef);
347
- if (!dispute) {
348
- console.error(`Dispute '${id}' not found.`);
349
- process.exit(1);
350
- }
351
-
352
- if (opts.json) {
353
- console.log(JSON.stringify(dispute, null, 2));
354
- } else {
355
- console.log(`Evidence added to dispute ${id}: "${opts.description}"`);
356
- }
357
- });
358
-
359
- // --- Payouts ---
360
-
361
- const payoutCmd = program
362
- .command("payout")
363
- .description("Payout management");
364
-
365
- payoutCmd
366
- .command("list")
367
- .description("List payouts")
368
- .option("--status <status>", "Filter by status (pending/in_transit/paid/failed)")
369
- .option("--json", "Output as JSON", false)
370
- .action((opts) => {
371
- const payouts = listPayouts(opts.status as PayoutStatus | undefined);
372
-
373
- if (opts.json) {
374
- console.log(JSON.stringify(payouts, null, 2));
375
- } else {
376
- if (payouts.length === 0) {
377
- console.log("No payouts found.");
378
- return;
379
- }
380
- for (const p of payouts) {
381
- const dest = p.destination || "—";
382
- console.log(` $${p.amount} ${p.currency} [${p.status}] -> ${dest} (${p.id})`);
383
- }
384
- console.log(`\n${payouts.length} payout(s)`);
385
- }
386
- });
387
-
388
- payoutCmd
389
- .command("initiate")
390
- .description("Initiate a new payout")
391
- .requiredOption("--amount <amount>", "Amount")
392
- .option("--currency <currency>", "Currency code", "USD")
393
- .option("--destination <dest>", "Destination (bank account, etc.)")
394
- .option("--json", "Output as JSON", false)
395
- .action((opts) => {
396
- const payout = createPayout({
397
- amount: parseFloat(opts.amount),
398
- currency: opts.currency,
399
- destination: opts.destination,
400
- });
401
-
402
- if (opts.json) {
403
- console.log(JSON.stringify(payout, null, 2));
404
- } else {
405
- console.log(`Initiated payout: $${payout.amount} ${payout.currency} (${payout.id})`);
406
- }
407
- });
408
-
409
- // --- Balance ---
410
-
411
- program
412
- .command("balance")
413
- .description("Show balance by provider")
414
- .option("--json", "Output as JSON", false)
415
- .action((opts) => {
416
- const balances = getBalanceByProvider();
417
-
418
- if (opts.json) {
419
- console.log(JSON.stringify(balances, null, 2));
420
- } else {
421
- if (balances.length === 0) {
422
- console.log("No payment data.");
423
- return;
424
- }
425
- for (const b of balances) {
426
- console.log(` ${b.provider}: charges $${b.total_charges}, refunds $${b.total_refunds}, net $${b.net_balance}`);
427
- }
428
- }
429
- });
430
-
431
- // --- Revenue ---
432
-
433
- const revenueCmd = program
434
- .command("revenue")
435
- .description("Revenue reports and forecasting");
436
-
437
- revenueCmd
438
- .command("report")
439
- .description("Revenue report for a period")
440
- .requiredOption("--period <YYYY-MM>", "Month period (e.g. 2024-01)")
441
- .option("--json", "Output as JSON", false)
442
- .action((opts) => {
443
- const [year, month] = opts.period.split("-").map(Number);
444
- const startDate = `${year}-${String(month).padStart(2, "0")}-01`;
445
- const lastDay = new Date(year, month, 0).getDate();
446
- const endDate = `${year}-${String(month).padStart(2, "0")}-${String(lastDay).padStart(2, "0")} 23:59:59`;
447
-
448
- const report = getRevenueReport(startDate, endDate);
449
-
450
- if (opts.json) {
451
- console.log(JSON.stringify(report, null, 2));
452
- } else {
453
- console.log(`Revenue Report: ${opts.period}`);
454
- console.log(` Total Revenue: $${report.total_revenue.toFixed(2)}`);
455
- console.log(` Total Refunds: $${report.total_refunds.toFixed(2)}`);
456
- console.log(` Net Revenue: $${report.net_revenue.toFixed(2)}`);
457
- console.log(` Payments: ${report.payment_count} Refunds: ${report.refund_count}`);
458
- }
459
- });
460
-
461
- revenueCmd
462
- .command("forecast")
463
- .description("Project revenue for upcoming months based on recent trends")
464
- .requiredOption("--months <n>", "Number of months to forecast")
465
- .option("--json", "Output as JSON", false)
466
- .action((opts) => {
467
- const result = revenueForecast(parseInt(opts.months));
468
-
469
- if (opts.json) {
470
- console.log(JSON.stringify(result, null, 2));
471
- } else {
472
- console.log(`Revenue Forecast (${result.months_projected} months, trend: ${result.trend})`);
473
- console.log(" Historical:");
474
- for (const h of result.historical) {
475
- console.log(` ${h.month}: $${h.revenue.toFixed(2)}`);
476
- }
477
- console.log(" Forecast:");
478
- for (const f of result.forecast) {
479
- console.log(` ${f.month}: $${f.projected_revenue.toFixed(2)} (projected)`);
480
- }
481
- console.log(` Average Monthly Revenue: $${result.average_monthly_revenue.toFixed(2)}`);
482
- }
483
- });
484
-
485
- // --- Reconcile ---
486
-
487
- const reconcileCmd = program
488
- .command("reconcile")
489
- .description("Reconciliation commands");
490
-
491
- reconcileCmd
492
- .command("link")
493
- .description("Link a payment to an invoice")
494
- .requiredOption("--payment <id>", "Payment ID")
495
- .requiredOption("--invoice <id>", "Invoice ID")
496
- .option("--json", "Output as JSON", false)
497
- .action((opts) => {
498
- const payment = reconcileWithInvoice(opts.payment, opts.invoice);
499
- if (!payment) {
500
- console.error(`Payment '${opts.payment}' not found.`);
501
- process.exit(1);
502
- }
503
-
504
- if (opts.json) {
505
- console.log(JSON.stringify(payment, null, 2));
506
- } else {
507
- console.log(`Linked payment ${payment.id} to invoice ${payment.invoice_id}`);
508
- }
509
- });
510
-
511
- reconcileCmd
512
- .command("auto")
513
- .description("Auto-reconcile payments to invoices by amount, email, and date")
514
- .option("--from <date>", "Start date (YYYY-MM-DD)")
515
- .option("--to <date>", "End date (YYYY-MM-DD)")
516
- .option("--json", "Output as JSON", false)
517
- .action((opts) => {
518
- const result = autoReconcile(opts.from, opts.to);
519
-
520
- if (opts.json) {
521
- console.log(JSON.stringify(result, null, 2));
522
- } else {
523
- console.log("Auto-Reconciliation Results:");
524
- console.log(` Matched: ${result.matched.length}`);
525
- for (const m of result.matched) {
526
- console.log(` Payment ${m.payment_id} -> Invoice ${m.invoice_id} (${m.confidence})`);
527
- }
528
- console.log(` Unmatched Payments: ${result.unmatched_payments.length}`);
529
- console.log(` Unmatched Invoices: ${result.unmatched_invoices.length}`);
530
- }
531
- });
532
-
533
- reconcileCmd
534
- .command("check-gaps")
535
- .description("Find reconciliation gaps — payments without invoices and vice versa")
536
- .requiredOption("--from <date>", "Start date (YYYY-MM-DD)")
537
- .requiredOption("--to <date>", "End date (YYYY-MM-DD)")
538
- .option("--json", "Output as JSON", false)
539
- .action((opts) => {
540
- const gaps = findReconciliationGaps(opts.from, opts.to);
541
-
542
- if (opts.json) {
543
- console.log(JSON.stringify(gaps, null, 2));
544
- } else {
545
- console.log("Reconciliation Gaps:");
546
- console.log(` Payments without invoice: ${gaps.payments_without_invoice.length}`);
547
- for (const p of gaps.payments_without_invoice) {
548
- console.log(` $${p.amount} ${p.currency} — ${p.customer_email || "no email"} (${p.id})`);
549
- }
550
- console.log(` Invoice IDs without succeeded payment: ${gaps.invoice_ids_without_payment.length}`);
551
- for (const inv of gaps.invoice_ids_without_payment) {
552
- console.log(` ${inv}`);
553
- }
554
- console.log(` Total gaps: ${gaps.gap_count}`);
555
- }
556
- });
557
-
558
- // --- Fees ---
559
-
560
- program
561
- .command("fees")
562
- .description("Fee analysis by provider for a given month")
563
- .requiredOption("--month <YYYY-MM>", "Month period (e.g. 2026-03)")
564
- .option("--json", "Output as JSON", false)
565
- .action((opts) => {
566
- const result = feeAnalysis(opts.month);
567
-
568
- if (opts.json) {
569
- console.log(JSON.stringify(result, null, 2));
570
- } else {
571
- console.log(`Fee Analysis: ${result.month}`);
572
- for (const p of result.providers) {
573
- console.log(` ${p.provider}: gross $${p.gross.toFixed(2)}, fees $${p.fees.toFixed(2)}, net $${p.net.toFixed(2)} (${p.transaction_count} txns)`);
574
- }
575
- console.log(` Total: gross $${result.total_gross.toFixed(2)}, fees $${result.total_fees.toFixed(2)}, net $${result.total_net.toFixed(2)}`);
576
- }
577
- });
578
-
579
- // --- Stats ---
580
-
581
- program
582
- .command("stats")
583
- .description("Payment statistics")
584
- .option("--json", "Output as JSON", false)
585
- .action((opts) => {
586
- const stats = getPaymentStats();
587
-
588
- if (opts.json) {
589
- console.log(JSON.stringify(stats, null, 2));
590
- } else {
591
- console.log("Payment Statistics:");
592
- console.log(` Total Payments: ${stats.total_payments}`);
593
- console.log(` Charges: ${stats.total_charges}`);
594
- console.log(` Refunds: ${stats.total_refunds}`);
595
- console.log(` Transfers: ${stats.total_transfers}`);
596
- console.log(` Payouts: ${stats.total_payouts}`);
597
- console.log(` Total Amount: $${stats.total_amount.toFixed(2)}`);
598
- console.log(" By Status:");
599
- for (const [s, c] of Object.entries(stats.by_status)) {
600
- console.log(` ${s}: ${c}`);
601
- }
602
- console.log(" By Provider:");
603
- for (const [p, c] of Object.entries(stats.by_provider)) {
604
- console.log(` ${p}: ${c}`);
605
- }
606
- }
607
- });
608
-
609
- program.parse(process.argv);
@@ -1,93 +0,0 @@
1
- /**
2
- * Database connection for microservice-payments
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-payments", "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-payments", "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-payments", "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
- }