@hasna/microservices 0.0.4 → 0.0.5

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 (38) hide show
  1. package/microservices/microservice-ads/src/cli/index.ts +198 -0
  2. package/microservices/microservice-ads/src/db/campaigns.ts +304 -0
  3. package/microservices/microservice-ads/src/mcp/index.ts +160 -0
  4. package/microservices/microservice-contracts/src/cli/index.ts +410 -23
  5. package/microservices/microservice-contracts/src/db/contracts.ts +430 -1
  6. package/microservices/microservice-contracts/src/db/migrations.ts +83 -0
  7. package/microservices/microservice-contracts/src/mcp/index.ts +312 -3
  8. package/microservices/microservice-domains/src/cli/index.ts +253 -0
  9. package/microservices/microservice-domains/src/db/domains.ts +613 -0
  10. package/microservices/microservice-domains/src/index.ts +21 -0
  11. package/microservices/microservice-domains/src/mcp/index.ts +168 -0
  12. package/microservices/microservice-hiring/src/cli/index.ts +318 -8
  13. package/microservices/microservice-hiring/src/db/hiring.ts +503 -0
  14. package/microservices/microservice-hiring/src/db/migrations.ts +21 -0
  15. package/microservices/microservice-hiring/src/index.ts +29 -0
  16. package/microservices/microservice-hiring/src/lib/scoring.ts +206 -0
  17. package/microservices/microservice-hiring/src/mcp/index.ts +245 -0
  18. package/microservices/microservice-payments/src/cli/index.ts +255 -3
  19. package/microservices/microservice-payments/src/db/migrations.ts +18 -0
  20. package/microservices/microservice-payments/src/db/payments.ts +552 -0
  21. package/microservices/microservice-payments/src/mcp/index.ts +223 -0
  22. package/microservices/microservice-payroll/src/cli/index.ts +269 -0
  23. package/microservices/microservice-payroll/src/db/migrations.ts +26 -0
  24. package/microservices/microservice-payroll/src/db/payroll.ts +636 -0
  25. package/microservices/microservice-payroll/src/mcp/index.ts +246 -0
  26. package/microservices/microservice-shipping/src/cli/index.ts +211 -3
  27. package/microservices/microservice-shipping/src/db/migrations.ts +8 -0
  28. package/microservices/microservice-shipping/src/db/shipping.ts +453 -3
  29. package/microservices/microservice-shipping/src/mcp/index.ts +149 -1
  30. package/microservices/microservice-social/src/cli/index.ts +244 -2
  31. package/microservices/microservice-social/src/db/migrations.ts +33 -0
  32. package/microservices/microservice-social/src/db/social.ts +378 -4
  33. package/microservices/microservice-social/src/mcp/index.ts +221 -1
  34. package/microservices/microservice-subscriptions/src/cli/index.ts +315 -0
  35. package/microservices/microservice-subscriptions/src/db/migrations.ts +68 -0
  36. package/microservices/microservice-subscriptions/src/db/subscriptions.ts +567 -3
  37. package/microservices/microservice-subscriptions/src/mcp/index.ts +267 -1
  38. package/package.json +1 -1
@@ -11,16 +11,33 @@ import {
11
11
  listExpiring,
12
12
  renewContract,
13
13
  getContractStats,
14
+ submitForReview,
15
+ approveContract,
16
+ getContractHistory,
17
+ recordSignature,
18
+ listSignatures,
19
+ compareContracts,
20
+ exportContract,
14
21
  } from "../db/contracts.js";
15
22
  import {
16
23
  createClause,
17
24
  listClauses,
18
25
  deleteClause,
26
+ addClauseFromTemplate,
27
+ saveClauseTemplate,
28
+ listClauseTemplates,
19
29
  } from "../db/contracts.js";
20
30
  import {
21
31
  createReminder,
22
32
  listReminders,
23
33
  deleteReminder,
34
+ setMultiReminders,
35
+ } from "../db/contracts.js";
36
+ import {
37
+ createObligation,
38
+ listObligations,
39
+ completeObligation,
40
+ listOverdueObligations,
24
41
  } from "../db/contracts.js";
25
42
 
26
43
  const program = new Command();
@@ -41,7 +58,7 @@ contractCmd
41
58
  .description("Create a new contract")
42
59
  .requiredOption("--title <title>", "Contract title")
43
60
  .option("--type <type>", "Contract type (nda/service/employment/license/other)", "other")
44
- .option("--status <status>", "Status (draft/pending_signature/active/expired/terminated)", "draft")
61
+ .option("--status <status>", "Status (draft/pending_review/pending_signature/active/expired/terminated)", "draft")
45
62
  .option("--counterparty <name>", "Counterparty name")
46
63
  .option("--counterparty-email <email>", "Counterparty email")
47
64
  .option("--start-date <date>", "Start date (YYYY-MM-DD)")
@@ -197,6 +214,201 @@ contractCmd
197
214
  }
198
215
  });
199
216
 
217
+ // --- Approval workflow ---
218
+
219
+ contractCmd
220
+ .command("submit")
221
+ .description("Submit a draft contract for review (draft -> pending_review)")
222
+ .argument("<id>", "Contract ID")
223
+ .option("--json", "Output as JSON", false)
224
+ .action((id, opts) => {
225
+ try {
226
+ const contract = submitForReview(id);
227
+ if (!contract) {
228
+ console.error(`Contract '${id}' not found.`);
229
+ process.exit(1);
230
+ }
231
+ if (opts.json) {
232
+ console.log(JSON.stringify(contract, null, 2));
233
+ } else {
234
+ console.log(`Submitted for review: ${contract.title} [${contract.status}]`);
235
+ }
236
+ } catch (err) {
237
+ console.error((err as Error).message);
238
+ process.exit(1);
239
+ }
240
+ });
241
+
242
+ contractCmd
243
+ .command("approve")
244
+ .description("Approve a contract (advances through approval workflow)")
245
+ .argument("<id>", "Contract ID")
246
+ .option("--json", "Output as JSON", false)
247
+ .action((id, opts) => {
248
+ try {
249
+ const contract = approveContract(id);
250
+ if (!contract) {
251
+ console.error(`Contract '${id}' not found.`);
252
+ process.exit(1);
253
+ }
254
+ if (opts.json) {
255
+ console.log(JSON.stringify(contract, null, 2));
256
+ } else {
257
+ console.log(`Approved: ${contract.title} [${contract.status}]`);
258
+ }
259
+ } catch (err) {
260
+ console.error((err as Error).message);
261
+ process.exit(1);
262
+ }
263
+ });
264
+
265
+ // --- Version history ---
266
+
267
+ contractCmd
268
+ .command("history")
269
+ .description("Show version history for a contract")
270
+ .argument("<id>", "Contract ID")
271
+ .option("--json", "Output as JSON", false)
272
+ .action((id, opts) => {
273
+ const history = getContractHistory(id);
274
+ if (opts.json) {
275
+ console.log(JSON.stringify(history, null, 2));
276
+ } else {
277
+ if (history.length === 0) {
278
+ console.log("No version history.");
279
+ return;
280
+ }
281
+ for (const v of history) {
282
+ console.log(` ${v.changed_at} — "${v.title}" [${v.status}] value=${v.value ?? "N/A"}`);
283
+ }
284
+ console.log(`\n${history.length} version(s)`);
285
+ }
286
+ });
287
+
288
+ // --- Signature logging ---
289
+
290
+ contractCmd
291
+ .command("sign")
292
+ .description("Record a signature for a contract")
293
+ .argument("<id>", "Contract ID")
294
+ .requiredOption("--signer <name>", "Signer name")
295
+ .option("--email <email>", "Signer email")
296
+ .option("--method <method>", "Signature method (digital/wet/docusign)", "digital")
297
+ .option("--json", "Output as JSON", false)
298
+ .action((id, opts) => {
299
+ const sig = recordSignature({
300
+ contract_id: id,
301
+ signer_name: opts.signer,
302
+ signer_email: opts.email,
303
+ method: opts.method,
304
+ });
305
+
306
+ if (opts.json) {
307
+ console.log(JSON.stringify(sig, null, 2));
308
+ } else {
309
+ const email = sig.signer_email ? ` (${sig.signer_email})` : "";
310
+ console.log(`Recorded signature: ${sig.signer_name}${email} via ${sig.method} (${sig.id})`);
311
+ }
312
+ });
313
+
314
+ contractCmd
315
+ .command("signatures")
316
+ .description("List signatures for a contract")
317
+ .argument("<id>", "Contract ID")
318
+ .option("--json", "Output as JSON", false)
319
+ .action((id, opts) => {
320
+ const sigs = listSignatures(id);
321
+ if (opts.json) {
322
+ console.log(JSON.stringify(sigs, null, 2));
323
+ } else {
324
+ if (sigs.length === 0) {
325
+ console.log("No signatures found.");
326
+ return;
327
+ }
328
+ for (const s of sigs) {
329
+ const email = s.signer_email ? ` (${s.signer_email})` : "";
330
+ console.log(` ${s.signer_name}${email} — ${s.method} — ${s.signed_at}`);
331
+ }
332
+ }
333
+ });
334
+
335
+ // --- Contract comparison ---
336
+
337
+ contractCmd
338
+ .command("compare")
339
+ .description("Compare two contracts showing clause differences")
340
+ .argument("<id1>", "First contract ID")
341
+ .argument("<id2>", "Second contract ID")
342
+ .option("--json", "Output as JSON", false)
343
+ .action((id1, id2, opts) => {
344
+ try {
345
+ const diff = compareContracts(id1, id2);
346
+ if (opts.json) {
347
+ console.log(JSON.stringify(diff, null, 2));
348
+ } else {
349
+ console.log(`Comparing: "${diff.contract1.title}" vs "${diff.contract2.title}"\n`);
350
+
351
+ if (diff.field_differences.length > 0) {
352
+ console.log("Field differences:");
353
+ for (const d of diff.field_differences) {
354
+ console.log(` ${d.field}: ${JSON.stringify(d.contract1_value)} vs ${JSON.stringify(d.contract2_value)}`);
355
+ }
356
+ console.log("");
357
+ }
358
+
359
+ if (diff.clause_only_in_1.length > 0) {
360
+ console.log(`Clauses only in "${diff.contract1.title}":`);
361
+ for (const c of diff.clause_only_in_1) {
362
+ console.log(` - ${c.name}`);
363
+ }
364
+ console.log("");
365
+ }
366
+
367
+ if (diff.clause_only_in_2.length > 0) {
368
+ console.log(`Clauses only in "${diff.contract2.title}":`);
369
+ for (const c of diff.clause_only_in_2) {
370
+ console.log(` - ${c.name}`);
371
+ }
372
+ console.log("");
373
+ }
374
+
375
+ if (diff.clause_differences.length > 0) {
376
+ console.log("Clause text differences:");
377
+ for (const d of diff.clause_differences) {
378
+ console.log(` ${d.name}:`);
379
+ console.log(` Contract 1: ${d.contract1_text.substring(0, 80)}${d.contract1_text.length > 80 ? "..." : ""}`);
380
+ console.log(` Contract 2: ${d.contract2_text.substring(0, 80)}${d.contract2_text.length > 80 ? "..." : ""}`);
381
+ }
382
+ console.log("");
383
+ }
384
+
385
+ if (diff.field_differences.length === 0 && diff.clause_only_in_1.length === 0 && diff.clause_only_in_2.length === 0 && diff.clause_differences.length === 0) {
386
+ console.log("No differences found.");
387
+ }
388
+ }
389
+ } catch (err) {
390
+ console.error((err as Error).message);
391
+ process.exit(1);
392
+ }
393
+ });
394
+
395
+ // --- Markdown export ---
396
+
397
+ contractCmd
398
+ .command("export")
399
+ .description("Export a contract in markdown or JSON format")
400
+ .argument("<id>", "Contract ID")
401
+ .option("--format <format>", "Export format (md/json)", "md")
402
+ .action((id, opts) => {
403
+ try {
404
+ const output = exportContract(id, opts.format);
405
+ console.log(output);
406
+ } catch (err) {
407
+ console.error((err as Error).message);
408
+ process.exit(1);
409
+ }
410
+ });
411
+
200
412
  // --- Expiring & Renew ---
201
413
 
202
414
  program
@@ -252,21 +464,36 @@ clauseCmd
252
464
  .description("Add a clause to a contract")
253
465
  .requiredOption("--contract <id>", "Contract ID")
254
466
  .requiredOption("--name <name>", "Clause name")
255
- .requiredOption("--text <text>", "Clause text")
467
+ .option("--text <text>", "Clause text")
468
+ .option("--from-template <templateName>", "Add clause from a template by name")
256
469
  .option("--type <type>", "Clause type (standard/custom/negotiated)", "standard")
257
470
  .option("--json", "Output as JSON", false)
258
471
  .action((opts) => {
259
- const clause = createClause({
260
- contract_id: opts.contract,
261
- name: opts.name,
262
- text: opts.text,
263
- type: opts.type,
264
- });
472
+ try {
473
+ let clause;
474
+ if (opts.fromTemplate) {
475
+ clause = addClauseFromTemplate(opts.contract, opts.fromTemplate);
476
+ } else {
477
+ if (!opts.text) {
478
+ console.error("Either --text or --from-template is required.");
479
+ process.exit(1);
480
+ }
481
+ clause = createClause({
482
+ contract_id: opts.contract,
483
+ name: opts.name,
484
+ text: opts.text,
485
+ type: opts.type,
486
+ });
487
+ }
265
488
 
266
- if (opts.json) {
267
- console.log(JSON.stringify(clause, null, 2));
268
- } else {
269
- console.log(`Added clause: ${clause.name} (${clause.id})`);
489
+ if (opts.json) {
490
+ console.log(JSON.stringify(clause, null, 2));
491
+ } else {
492
+ console.log(`Added clause: ${clause.name} (${clause.id})`);
493
+ }
494
+ } catch (err) {
495
+ console.error((err as Error).message);
496
+ process.exit(1);
270
497
  }
271
498
  });
272
499
 
@@ -305,6 +532,143 @@ clauseCmd
305
532
  }
306
533
  });
307
534
 
535
+ // --- Clause templates ---
536
+
537
+ clauseCmd
538
+ .command("save-template")
539
+ .description("Save a clause as a reusable template")
540
+ .requiredOption("--name <name>", "Template name")
541
+ .requiredOption("--text <text>", "Template text")
542
+ .option("--type <type>", "Clause type (standard/custom/negotiated)", "standard")
543
+ .option("--json", "Output as JSON", false)
544
+ .action((opts) => {
545
+ const template = saveClauseTemplate({
546
+ name: opts.name,
547
+ text: opts.text,
548
+ type: opts.type,
549
+ });
550
+
551
+ if (opts.json) {
552
+ console.log(JSON.stringify(template, null, 2));
553
+ } else {
554
+ console.log(`Saved template: ${template.name} (${template.id})`);
555
+ }
556
+ });
557
+
558
+ clauseCmd
559
+ .command("list-templates")
560
+ .description("List all clause templates")
561
+ .option("--json", "Output as JSON", false)
562
+ .action((opts) => {
563
+ const templates = listClauseTemplates();
564
+
565
+ if (opts.json) {
566
+ console.log(JSON.stringify(templates, null, 2));
567
+ } else {
568
+ if (templates.length === 0) {
569
+ console.log("No clause templates found.");
570
+ return;
571
+ }
572
+ for (const t of templates) {
573
+ console.log(` ${t.name} [${t.type}]: ${t.text.substring(0, 80)}${t.text.length > 80 ? "..." : ""}`);
574
+ }
575
+ }
576
+ });
577
+
578
+ // --- Obligations ---
579
+
580
+ const obligationCmd = program
581
+ .command("obligation")
582
+ .description("Obligation tracking");
583
+
584
+ obligationCmd
585
+ .command("add")
586
+ .description("Add an obligation to a clause")
587
+ .requiredOption("--clause <id>", "Clause ID")
588
+ .requiredOption("--description <desc>", "Obligation description")
589
+ .option("--due-date <date>", "Due date (YYYY-MM-DD)")
590
+ .option("--assigned-to <name>", "Person assigned to this obligation")
591
+ .option("--json", "Output as JSON", false)
592
+ .action((opts) => {
593
+ const obligation = createObligation({
594
+ clause_id: opts.clause,
595
+ description: opts.description,
596
+ due_date: opts.dueDate,
597
+ assigned_to: opts.assignedTo,
598
+ });
599
+
600
+ if (opts.json) {
601
+ console.log(JSON.stringify(obligation, null, 2));
602
+ } else {
603
+ console.log(`Added obligation: ${obligation.description} (${obligation.id})`);
604
+ }
605
+ });
606
+
607
+ obligationCmd
608
+ .command("list")
609
+ .description("List obligations for a clause")
610
+ .argument("<clause-id>", "Clause ID")
611
+ .option("--json", "Output as JSON", false)
612
+ .action((clauseId, opts) => {
613
+ const obligations = listObligations(clauseId);
614
+
615
+ if (opts.json) {
616
+ console.log(JSON.stringify(obligations, null, 2));
617
+ } else {
618
+ if (obligations.length === 0) {
619
+ console.log("No obligations found.");
620
+ return;
621
+ }
622
+ for (const o of obligations) {
623
+ const due = o.due_date ? ` due ${o.due_date}` : "";
624
+ const assigned = o.assigned_to ? ` (${o.assigned_to})` : "";
625
+ console.log(` [${o.status}] ${o.description}${due}${assigned}`);
626
+ }
627
+ }
628
+ });
629
+
630
+ obligationCmd
631
+ .command("complete")
632
+ .description("Mark an obligation as completed")
633
+ .argument("<id>", "Obligation ID")
634
+ .option("--json", "Output as JSON", false)
635
+ .action((id, opts) => {
636
+ const obligation = completeObligation(id);
637
+ if (!obligation) {
638
+ console.error(`Obligation '${id}' not found.`);
639
+ process.exit(1);
640
+ }
641
+
642
+ if (opts.json) {
643
+ console.log(JSON.stringify(obligation, null, 2));
644
+ } else {
645
+ console.log(`Completed: ${obligation.description}`);
646
+ }
647
+ });
648
+
649
+ obligationCmd
650
+ .command("overdue")
651
+ .description("List all overdue obligations")
652
+ .option("--json", "Output as JSON", false)
653
+ .action((opts) => {
654
+ const obligations = listOverdueObligations();
655
+
656
+ if (opts.json) {
657
+ console.log(JSON.stringify(obligations, null, 2));
658
+ } else {
659
+ if (obligations.length === 0) {
660
+ console.log("No overdue obligations.");
661
+ return;
662
+ }
663
+ for (const o of obligations) {
664
+ const due = o.due_date ? ` due ${o.due_date}` : "";
665
+ const assigned = o.assigned_to ? ` (${o.assigned_to})` : "";
666
+ console.log(` [${o.status}] ${o.description}${due}${assigned}`);
667
+ }
668
+ console.log(`\n${obligations.length} overdue obligation(s)`);
669
+ }
670
+ });
671
+
308
672
  // --- Reminders ---
309
673
 
310
674
  const remindCmd = program
@@ -315,20 +679,43 @@ remindCmd
315
679
  .command("set")
316
680
  .description("Set a reminder for a contract")
317
681
  .requiredOption("--contract <id>", "Contract ID")
318
- .requiredOption("--at <datetime>", "Reminder datetime (ISO 8601)")
319
- .requiredOption("--message <msg>", "Reminder message")
682
+ .option("--at <datetime>", "Reminder datetime (ISO 8601)")
683
+ .option("--message <msg>", "Reminder message")
684
+ .option("--days-before <days>", "Set multi-stage reminders (comma-separated, e.g. 60,30,7)")
320
685
  .option("--json", "Output as JSON", false)
321
686
  .action((opts) => {
322
- const reminder = createReminder({
323
- contract_id: opts.contract,
324
- remind_at: opts.at,
325
- message: opts.message,
326
- });
327
-
328
- if (opts.json) {
329
- console.log(JSON.stringify(reminder, null, 2));
687
+ if (opts.daysBefore) {
688
+ try {
689
+ const days = opts.daysBefore.split(",").map((d: string) => parseInt(d.trim()));
690
+ const reminders = setMultiReminders(opts.contract, days);
691
+ if (opts.json) {
692
+ console.log(JSON.stringify(reminders, null, 2));
693
+ } else {
694
+ for (const r of reminders) {
695
+ console.log(`Set reminder: ${r.message} at ${r.remind_at} (${r.id})`);
696
+ }
697
+ console.log(`\n${reminders.length} reminder(s) created`);
698
+ }
699
+ } catch (err) {
700
+ console.error((err as Error).message);
701
+ process.exit(1);
702
+ }
330
703
  } else {
331
- console.log(`Set reminder: ${reminder.message} at ${reminder.remind_at} (${reminder.id})`);
704
+ if (!opts.at || !opts.message) {
705
+ console.error("Either --at and --message are required, or use --days-before for multi-stage reminders.");
706
+ process.exit(1);
707
+ }
708
+ const reminder = createReminder({
709
+ contract_id: opts.contract,
710
+ remind_at: opts.at,
711
+ message: opts.message,
712
+ });
713
+
714
+ if (opts.json) {
715
+ console.log(JSON.stringify(reminder, null, 2));
716
+ } else {
717
+ console.log(`Set reminder: ${reminder.message} at ${reminder.remind_at} (${reminder.id})`);
718
+ }
332
719
  }
333
720
  });
334
721