@hasna/microservices 0.0.5 → 0.0.7
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.
- package/bin/index.js +9 -1
- package/bin/mcp.js +9 -1
- package/dist/index.js +9 -1
- package/microservices/microservice-company/package.json +27 -0
- package/microservices/microservice-company/src/cli/index.ts +1126 -0
- package/microservices/microservice-company/src/db/company.ts +854 -0
- package/microservices/microservice-company/src/db/database.ts +93 -0
- package/microservices/microservice-company/src/db/migrations.ts +214 -0
- package/microservices/microservice-company/src/db/workflow-migrations.ts +44 -0
- package/microservices/microservice-company/src/index.ts +60 -0
- package/microservices/microservice-company/src/lib/audit.ts +168 -0
- package/microservices/microservice-company/src/lib/finance.ts +299 -0
- package/microservices/microservice-company/src/lib/settings.ts +85 -0
- package/microservices/microservice-company/src/lib/workflows.ts +698 -0
- package/microservices/microservice-company/src/mcp/index.ts +991 -0
- package/microservices/microservice-domains/src/cli/index.ts +420 -0
- package/microservices/microservice-domains/src/lib/brandsight.ts +350 -0
- package/microservices/microservice-domains/src/lib/godaddy.ts +338 -0
- package/microservices/microservice-domains/src/lib/namecheap.ts +262 -0
- package/microservices/microservice-domains/src/lib/registrar.ts +355 -0
- package/microservices/microservice-domains/src/mcp/index.ts +245 -0
- package/package.json +1 -1
|
@@ -30,6 +30,26 @@ import {
|
|
|
30
30
|
checkAllDomains,
|
|
31
31
|
getDomainByName,
|
|
32
32
|
} from "../db/domains.js";
|
|
33
|
+
import {
|
|
34
|
+
syncToLocalDb,
|
|
35
|
+
renewDomain as namecheapRenew,
|
|
36
|
+
checkAvailability as namecheapCheck,
|
|
37
|
+
} from "../lib/namecheap.js";
|
|
38
|
+
import {
|
|
39
|
+
syncToLocalDb as godaddySyncToLocalDb,
|
|
40
|
+
renewDomain as godaddyRenewDomain,
|
|
41
|
+
} from "../lib/godaddy.js";
|
|
42
|
+
import {
|
|
43
|
+
getAvailableProviders,
|
|
44
|
+
syncAll,
|
|
45
|
+
autoDetectRegistrar,
|
|
46
|
+
getProvider,
|
|
47
|
+
} from "../lib/registrar.js";
|
|
48
|
+
import {
|
|
49
|
+
monitorBrand,
|
|
50
|
+
getSimilarDomains,
|
|
51
|
+
getThreatAssessment,
|
|
52
|
+
} from "../lib/brandsight.js";
|
|
33
53
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
34
54
|
|
|
35
55
|
const program = new Command();
|
|
@@ -688,4 +708,404 @@ alertCmd
|
|
|
688
708
|
}
|
|
689
709
|
});
|
|
690
710
|
|
|
711
|
+
// --- Namecheap Integration ---
|
|
712
|
+
|
|
713
|
+
program
|
|
714
|
+
.command("sync")
|
|
715
|
+
.description("Sync domains from a provider to local DB")
|
|
716
|
+
.requiredOption("--provider <provider>", "Provider name (namecheap, godaddy)")
|
|
717
|
+
.option("--json", "Output as JSON", false)
|
|
718
|
+
.action(async (opts) => {
|
|
719
|
+
const provider = opts.provider.toLowerCase();
|
|
720
|
+
|
|
721
|
+
if (provider === "namecheap") {
|
|
722
|
+
try {
|
|
723
|
+
const result = await syncToLocalDb({
|
|
724
|
+
getDomainByName,
|
|
725
|
+
createDomain,
|
|
726
|
+
updateDomain,
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
if (opts.json) {
|
|
730
|
+
console.log(JSON.stringify(result, null, 2));
|
|
731
|
+
} else {
|
|
732
|
+
console.log(`Synced ${result.synced} domain(s) from Namecheap`);
|
|
733
|
+
for (const d of result.domains) {
|
|
734
|
+
console.log(` ${d}`);
|
|
735
|
+
}
|
|
736
|
+
if (result.errors.length > 0) {
|
|
737
|
+
console.log("Errors:");
|
|
738
|
+
for (const e of result.errors) {
|
|
739
|
+
console.log(` - ${e}`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
} catch (error: unknown) {
|
|
744
|
+
console.error(`Sync failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
745
|
+
process.exit(1);
|
|
746
|
+
}
|
|
747
|
+
} else if (provider === "godaddy") {
|
|
748
|
+
try {
|
|
749
|
+
const result = await godaddySyncToLocalDb({
|
|
750
|
+
getDomainByName,
|
|
751
|
+
createDomain,
|
|
752
|
+
updateDomain,
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
if (opts.json) {
|
|
756
|
+
console.log(JSON.stringify(result, null, 2));
|
|
757
|
+
} else {
|
|
758
|
+
console.log(`Synced ${result.synced} domain(s) from GoDaddy (created: ${result.created}, updated: ${result.updated})`);
|
|
759
|
+
if (result.errors.length > 0) {
|
|
760
|
+
console.log("Errors:");
|
|
761
|
+
for (const e of result.errors) {
|
|
762
|
+
console.log(` - ${e}`);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
} catch (error: unknown) {
|
|
767
|
+
console.error(`Sync failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
768
|
+
process.exit(1);
|
|
769
|
+
}
|
|
770
|
+
} else {
|
|
771
|
+
console.error(`Unsupported provider: ${opts.provider}. Supported: namecheap, godaddy`);
|
|
772
|
+
process.exit(1);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
program
|
|
777
|
+
.command("renew")
|
|
778
|
+
.description("Renew a domain via provider")
|
|
779
|
+
.argument("<name>", "Domain name (e.g. example.com)")
|
|
780
|
+
.requiredOption("--provider <provider>", "Provider name (namecheap, godaddy)")
|
|
781
|
+
.option("--years <n>", "Number of years to renew", "1")
|
|
782
|
+
.option("--json", "Output as JSON", false)
|
|
783
|
+
.action(async (name, opts) => {
|
|
784
|
+
const provider = opts.provider.toLowerCase();
|
|
785
|
+
|
|
786
|
+
if (provider === "namecheap") {
|
|
787
|
+
try {
|
|
788
|
+
const result = await namecheapRenew(name, parseInt(opts.years));
|
|
789
|
+
|
|
790
|
+
if (opts.json) {
|
|
791
|
+
console.log(JSON.stringify(result, null, 2));
|
|
792
|
+
} else {
|
|
793
|
+
console.log(`Renewed ${result.domain} successfully`);
|
|
794
|
+
if (result.chargedAmount) console.log(` Charged: $${result.chargedAmount}`);
|
|
795
|
+
if (result.orderId) console.log(` Order ID: ${result.orderId}`);
|
|
796
|
+
if (result.transactionId) console.log(` Transaction ID: ${result.transactionId}`);
|
|
797
|
+
}
|
|
798
|
+
} catch (error: unknown) {
|
|
799
|
+
console.error(`Renewal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
800
|
+
process.exit(1);
|
|
801
|
+
}
|
|
802
|
+
} else if (provider === "godaddy") {
|
|
803
|
+
try {
|
|
804
|
+
const result = await godaddyRenewDomain(name);
|
|
805
|
+
|
|
806
|
+
if (opts.json) {
|
|
807
|
+
console.log(JSON.stringify(result, null, 2));
|
|
808
|
+
} else {
|
|
809
|
+
console.log(`Renewed ${name} successfully via GoDaddy`);
|
|
810
|
+
if (result.orderId) console.log(` Order ID: ${result.orderId}`);
|
|
811
|
+
if (result.total) console.log(` Total: $${(result.total / 100).toFixed(2)}`);
|
|
812
|
+
}
|
|
813
|
+
} catch (error: unknown) {
|
|
814
|
+
console.error(`Renewal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
815
|
+
process.exit(1);
|
|
816
|
+
}
|
|
817
|
+
} else {
|
|
818
|
+
console.error(`Unsupported provider: ${opts.provider}. Supported: namecheap, godaddy`);
|
|
819
|
+
process.exit(1);
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
program
|
|
824
|
+
.command("check")
|
|
825
|
+
.description("Check domain availability")
|
|
826
|
+
.argument("<name>", "Domain name (e.g. example.com)")
|
|
827
|
+
.option("--json", "Output as JSON", false)
|
|
828
|
+
.action(async (name, opts) => {
|
|
829
|
+
try {
|
|
830
|
+
const result = await namecheapCheck(name);
|
|
831
|
+
|
|
832
|
+
if (opts.json) {
|
|
833
|
+
console.log(JSON.stringify(result, null, 2));
|
|
834
|
+
} else {
|
|
835
|
+
if (result.available) {
|
|
836
|
+
console.log(`${result.domain} is AVAILABLE`);
|
|
837
|
+
} else {
|
|
838
|
+
console.log(`${result.domain} is NOT available`);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
} catch (error: unknown) {
|
|
842
|
+
console.error(`Availability check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
843
|
+
process.exit(1);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
// --- Unified Provider Commands ---
|
|
848
|
+
|
|
849
|
+
program
|
|
850
|
+
.command("providers")
|
|
851
|
+
.description("Show which registrar providers are configured")
|
|
852
|
+
.option("--json", "Output as JSON", false)
|
|
853
|
+
.action((opts) => {
|
|
854
|
+
const providers = getAvailableProviders();
|
|
855
|
+
|
|
856
|
+
if (opts.json) {
|
|
857
|
+
console.log(JSON.stringify(providers, null, 2));
|
|
858
|
+
} else {
|
|
859
|
+
console.log("Registrar Providers:");
|
|
860
|
+
for (const p of providers) {
|
|
861
|
+
const status = p.configured ? "CONFIGURED" : "not configured";
|
|
862
|
+
console.log(` ${p.name}: ${status}`);
|
|
863
|
+
if (!p.configured) {
|
|
864
|
+
console.log(` Missing: ${p.envVars.join(", ")}`);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
// Override sync command to support --all flag
|
|
871
|
+
program.commands = program.commands.filter((c) => c.name() !== "sync");
|
|
872
|
+
|
|
873
|
+
program
|
|
874
|
+
.command("sync")
|
|
875
|
+
.description("Sync domains from a provider to local DB")
|
|
876
|
+
.option("--provider <provider>", "Provider name (namecheap, godaddy)")
|
|
877
|
+
.option("--all", "Sync from all configured providers")
|
|
878
|
+
.option("--json", "Output as JSON", false)
|
|
879
|
+
.action(async (opts) => {
|
|
880
|
+
if (opts.all) {
|
|
881
|
+
try {
|
|
882
|
+
const result = await syncAll({
|
|
883
|
+
getDomainByName,
|
|
884
|
+
createDomain,
|
|
885
|
+
updateDomain,
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
if (opts.json) {
|
|
889
|
+
console.log(JSON.stringify(result, null, 2));
|
|
890
|
+
} else {
|
|
891
|
+
console.log(`Synced ${result.totalSynced} domain(s) from ${result.providers.length} provider(s)`);
|
|
892
|
+
for (const p of result.providers) {
|
|
893
|
+
console.log(` ${p.name}: ${p.result.synced} synced`);
|
|
894
|
+
}
|
|
895
|
+
if (result.totalErrors.length > 0) {
|
|
896
|
+
console.log("Errors:");
|
|
897
|
+
for (const e of result.totalErrors) {
|
|
898
|
+
console.log(` - ${e}`);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
} catch (error: unknown) {
|
|
903
|
+
console.error(`Sync failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
904
|
+
process.exit(1);
|
|
905
|
+
}
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
const provider = (opts.provider || "").toLowerCase();
|
|
910
|
+
if (!provider) {
|
|
911
|
+
console.error("Specify --provider <name> or --all");
|
|
912
|
+
process.exit(1);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
if (provider === "namecheap") {
|
|
916
|
+
try {
|
|
917
|
+
const result = await syncToLocalDb({
|
|
918
|
+
getDomainByName,
|
|
919
|
+
createDomain,
|
|
920
|
+
updateDomain,
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
if (opts.json) {
|
|
924
|
+
console.log(JSON.stringify(result, null, 2));
|
|
925
|
+
} else {
|
|
926
|
+
console.log(`Synced ${result.synced} domain(s) from Namecheap`);
|
|
927
|
+
for (const d of result.domains) {
|
|
928
|
+
console.log(` ${d}`);
|
|
929
|
+
}
|
|
930
|
+
if (result.errors.length > 0) {
|
|
931
|
+
console.log("Errors:");
|
|
932
|
+
for (const e of result.errors) {
|
|
933
|
+
console.log(` - ${e}`);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
} catch (error: unknown) {
|
|
938
|
+
console.error(`Sync failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
939
|
+
process.exit(1);
|
|
940
|
+
}
|
|
941
|
+
} else if (provider === "godaddy") {
|
|
942
|
+
try {
|
|
943
|
+
const result = await godaddySyncToLocalDb({
|
|
944
|
+
getDomainByName,
|
|
945
|
+
createDomain,
|
|
946
|
+
updateDomain,
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
if (opts.json) {
|
|
950
|
+
console.log(JSON.stringify(result, null, 2));
|
|
951
|
+
} else {
|
|
952
|
+
console.log(`Synced ${result.synced} domain(s) from GoDaddy (created: ${result.created}, updated: ${result.updated})`);
|
|
953
|
+
if (result.errors.length > 0) {
|
|
954
|
+
console.log("Errors:");
|
|
955
|
+
for (const e of result.errors) {
|
|
956
|
+
console.log(` - ${e}`);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
} catch (error: unknown) {
|
|
961
|
+
console.error(`Sync failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
962
|
+
process.exit(1);
|
|
963
|
+
}
|
|
964
|
+
} else {
|
|
965
|
+
console.error(`Unsupported provider: ${provider}. Supported: namecheap, godaddy`);
|
|
966
|
+
process.exit(1);
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
// Override renew command to support auto-detect
|
|
971
|
+
program.commands = program.commands.filter((c) => c.name() !== "renew");
|
|
972
|
+
|
|
973
|
+
program
|
|
974
|
+
.command("renew")
|
|
975
|
+
.description("Renew a domain via provider (auto-detects registrar from DB if --provider not given)")
|
|
976
|
+
.argument("<name>", "Domain name (e.g. example.com)")
|
|
977
|
+
.option("--provider <provider>", "Provider name (namecheap, godaddy)")
|
|
978
|
+
.option("--years <n>", "Number of years to renew", "1")
|
|
979
|
+
.option("--json", "Output as JSON", false)
|
|
980
|
+
.action(async (name, opts) => {
|
|
981
|
+
let provider = (opts.provider || "").toLowerCase();
|
|
982
|
+
|
|
983
|
+
if (!provider) {
|
|
984
|
+
const detected = autoDetectRegistrar(name, getDomainByName);
|
|
985
|
+
if (!detected) {
|
|
986
|
+
console.error(`Could not auto-detect registrar for '${name}'. Use --provider.`);
|
|
987
|
+
process.exit(1);
|
|
988
|
+
}
|
|
989
|
+
provider = detected;
|
|
990
|
+
console.log(`Auto-detected registrar: ${provider}`);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
if (provider === "namecheap") {
|
|
994
|
+
try {
|
|
995
|
+
const result = await namecheapRenew(name, parseInt(opts.years));
|
|
996
|
+
if (opts.json) {
|
|
997
|
+
console.log(JSON.stringify(result, null, 2));
|
|
998
|
+
} else {
|
|
999
|
+
console.log(`Renewed ${result.domain} successfully via Namecheap`);
|
|
1000
|
+
if (result.chargedAmount) console.log(` Charged: $${result.chargedAmount}`);
|
|
1001
|
+
if (result.orderId) console.log(` Order ID: ${result.orderId}`);
|
|
1002
|
+
}
|
|
1003
|
+
} catch (error: unknown) {
|
|
1004
|
+
console.error(`Renewal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1005
|
+
process.exit(1);
|
|
1006
|
+
}
|
|
1007
|
+
} else if (provider === "godaddy") {
|
|
1008
|
+
try {
|
|
1009
|
+
const result = await godaddyRenewDomain(name);
|
|
1010
|
+
if (opts.json) {
|
|
1011
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1012
|
+
} else {
|
|
1013
|
+
console.log(`Renewed ${name} successfully via GoDaddy`);
|
|
1014
|
+
if (result.orderId) console.log(` Order ID: ${result.orderId}`);
|
|
1015
|
+
if (result.total) console.log(` Total: $${(result.total / 100).toFixed(2)}`);
|
|
1016
|
+
}
|
|
1017
|
+
} catch (error: unknown) {
|
|
1018
|
+
console.error(`Renewal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1019
|
+
process.exit(1);
|
|
1020
|
+
}
|
|
1021
|
+
} else {
|
|
1022
|
+
console.error(`Unsupported provider: ${provider}. Supported: namecheap, godaddy`);
|
|
1023
|
+
process.exit(1);
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
// --- Brandsight Commands ---
|
|
1028
|
+
|
|
1029
|
+
program
|
|
1030
|
+
.command("monitor")
|
|
1031
|
+
.description("Monitor a brand for similar domain registrations (Brandsight)")
|
|
1032
|
+
.argument("<brand>", "Brand name to monitor")
|
|
1033
|
+
.option("--json", "Output as JSON", false)
|
|
1034
|
+
.action(async (brand, opts) => {
|
|
1035
|
+
try {
|
|
1036
|
+
const result = await monitorBrand(brand);
|
|
1037
|
+
if (opts.json) {
|
|
1038
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1039
|
+
} else {
|
|
1040
|
+
if (result.stub) console.log("(stub data — Brandsight API unreachable)");
|
|
1041
|
+
console.log(`Brand monitoring for "${result.brand}":`);
|
|
1042
|
+
if (result.alerts.length === 0) {
|
|
1043
|
+
console.log(" No alerts.");
|
|
1044
|
+
} else {
|
|
1045
|
+
for (const a of result.alerts) {
|
|
1046
|
+
console.log(` [${a.type}] ${a.domain} — registered ${a.registered_at}`);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
console.log(`\n${result.alerts.length} alert(s)`);
|
|
1050
|
+
}
|
|
1051
|
+
} catch (error: unknown) {
|
|
1052
|
+
console.error(`Monitor failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1053
|
+
process.exit(1);
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
program
|
|
1058
|
+
.command("similar")
|
|
1059
|
+
.description("Find typosquat/competing domains similar to a domain (Brandsight)")
|
|
1060
|
+
.argument("<domain>", "Domain to check")
|
|
1061
|
+
.option("--json", "Output as JSON", false)
|
|
1062
|
+
.action(async (domain, opts) => {
|
|
1063
|
+
try {
|
|
1064
|
+
const result = await getSimilarDomains(domain);
|
|
1065
|
+
if (opts.json) {
|
|
1066
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1067
|
+
} else {
|
|
1068
|
+
if (result.stub) console.log("(stub data — Brandsight API unreachable)");
|
|
1069
|
+
console.log(`Similar domains for ${result.domain}:`);
|
|
1070
|
+
for (const d of result.similar) {
|
|
1071
|
+
console.log(` ${d}`);
|
|
1072
|
+
}
|
|
1073
|
+
console.log(`\n${result.similar.length} similar domain(s)`);
|
|
1074
|
+
}
|
|
1075
|
+
} catch (error: unknown) {
|
|
1076
|
+
console.error(`Similar domains check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1077
|
+
process.exit(1);
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
program
|
|
1082
|
+
.command("threats")
|
|
1083
|
+
.description("Get threat assessment for a domain (Brandsight)")
|
|
1084
|
+
.argument("<domain>", "Domain to assess")
|
|
1085
|
+
.option("--json", "Output as JSON", false)
|
|
1086
|
+
.action(async (domain, opts) => {
|
|
1087
|
+
try {
|
|
1088
|
+
const result = await getThreatAssessment(domain);
|
|
1089
|
+
if (opts.json) {
|
|
1090
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1091
|
+
} else {
|
|
1092
|
+
if (result.stub) console.log("(stub data — Brandsight API unreachable)");
|
|
1093
|
+
console.log(`Threat Assessment for ${result.domain}:`);
|
|
1094
|
+
console.log(` Risk Level: ${result.risk_level}`);
|
|
1095
|
+
if (result.threats.length > 0) {
|
|
1096
|
+
console.log(" Threats:");
|
|
1097
|
+
for (const t of result.threats) {
|
|
1098
|
+
console.log(` - ${t}`);
|
|
1099
|
+
}
|
|
1100
|
+
} else {
|
|
1101
|
+
console.log(" Threats: none detected");
|
|
1102
|
+
}
|
|
1103
|
+
console.log(` Recommendation: ${result.recommendation}`);
|
|
1104
|
+
}
|
|
1105
|
+
} catch (error: unknown) {
|
|
1106
|
+
console.error(`Threat assessment failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1107
|
+
process.exit(1);
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
|
|
691
1111
|
program.parse(process.argv);
|