@contractspec/example.integration-hub 3.7.5 → 3.7.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/README.md +70 -183
- package/dist/connection/index.d.ts +1 -1
- package/dist/events.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +596 -594
- package/dist/integration/index.d.ts +1 -1
- package/dist/node/events.js +1 -1
- package/dist/node/index.js +596 -594
- package/dist/node/ui/IntegrationDashboard.js +27 -27
- package/dist/node/ui/hooks/index.js +1 -1
- package/dist/node/ui/hooks/useIntegrationData.js +1 -1
- package/dist/node/ui/index.js +545 -544
- package/dist/sync/index.d.ts +3 -3
- package/dist/ui/IntegrationDashboard.js +27 -27
- package/dist/ui/hooks/index.d.ts +1 -1
- package/dist/ui/hooks/index.js +1 -1
- package/dist/ui/hooks/useIntegrationData.js +1 -1
- package/dist/ui/index.d.ts +2 -2
- package/dist/ui/index.js +545 -544
- package/dist/ui/renderers/index.d.ts +1 -1
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -496,6 +496,158 @@ var CreateIntegrationContract = defineCommand2({
|
|
|
496
496
|
]
|
|
497
497
|
}
|
|
498
498
|
});
|
|
499
|
+
// src/mcp-example.ts
|
|
500
|
+
import { randomUUID } from "crypto";
|
|
501
|
+
import {
|
|
502
|
+
createMcpToolsets
|
|
503
|
+
} from "@contractspec/lib.ai-agent/tools/mcp-client";
|
|
504
|
+
var DEFAULT_STDIO_ARGS = [
|
|
505
|
+
"-y",
|
|
506
|
+
"@modelcontextprotocol/server-filesystem",
|
|
507
|
+
"."
|
|
508
|
+
];
|
|
509
|
+
async function runIntegrationHubMcpExampleFromEnv() {
|
|
510
|
+
const mode = resolveMode();
|
|
511
|
+
const transport = resolveTransport();
|
|
512
|
+
const config = buildMcpConfigFromEnv();
|
|
513
|
+
const toolset = await createMcpToolsets([config], {
|
|
514
|
+
onNameCollision: "error"
|
|
515
|
+
});
|
|
516
|
+
try {
|
|
517
|
+
const toolNames = Object.keys(toolset.tools).sort();
|
|
518
|
+
const output = {
|
|
519
|
+
mode,
|
|
520
|
+
server: {
|
|
521
|
+
name: config.name,
|
|
522
|
+
transport
|
|
523
|
+
},
|
|
524
|
+
authMethod: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_AUTH_METHOD,
|
|
525
|
+
apiVersion: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_API_VERSION,
|
|
526
|
+
tools: toolNames
|
|
527
|
+
};
|
|
528
|
+
if (mode === "call") {
|
|
529
|
+
const toolName = requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_NAME");
|
|
530
|
+
const toolArgs = parseRecordEnvOrDefault("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_ARGS_JSON", {});
|
|
531
|
+
const tool = toolset.tools[toolName];
|
|
532
|
+
if (!tool?.execute) {
|
|
533
|
+
throw new Error(`Tool "${toolName}" was not found. Available tools: ${toolNames.join(", ")}`);
|
|
534
|
+
}
|
|
535
|
+
const toolOutput = await tool.execute(toolArgs, {
|
|
536
|
+
toolCallId: `integration-hub-${randomUUID()}`,
|
|
537
|
+
messages: []
|
|
538
|
+
});
|
|
539
|
+
output.toolCall = {
|
|
540
|
+
name: toolName,
|
|
541
|
+
args: toolArgs,
|
|
542
|
+
output: toolOutput
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
return output;
|
|
546
|
+
} finally {
|
|
547
|
+
await toolset.cleanup().catch(() => {
|
|
548
|
+
return;
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function buildMcpConfigFromEnv() {
|
|
553
|
+
const name = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_NAME ?? "filesystem";
|
|
554
|
+
const transport = resolveTransport();
|
|
555
|
+
const toolPrefix = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_PREFIX;
|
|
556
|
+
if (transport === "stdio") {
|
|
557
|
+
return {
|
|
558
|
+
name,
|
|
559
|
+
transport,
|
|
560
|
+
command: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_COMMAND ?? "npx",
|
|
561
|
+
args: parseStringArrayEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_ARGS_JSON", DEFAULT_STDIO_ARGS),
|
|
562
|
+
toolPrefix
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
const accessToken = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN;
|
|
566
|
+
const accessTokenEnvVar = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN_ENV;
|
|
567
|
+
const mcpTransport = transport === "webhook" || transport === "http" ? "http" : "sse";
|
|
568
|
+
return {
|
|
569
|
+
name,
|
|
570
|
+
transport: mcpTransport,
|
|
571
|
+
url: requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_URL"),
|
|
572
|
+
headers: parseStringRecordEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_HEADERS_JSON"),
|
|
573
|
+
accessToken,
|
|
574
|
+
accessTokenEnvVar,
|
|
575
|
+
toolPrefix
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function resolveMode() {
|
|
579
|
+
const rawMode = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE?.toLowerCase() ?? "list";
|
|
580
|
+
if (rawMode === "list" || rawMode === "call") {
|
|
581
|
+
return rawMode;
|
|
582
|
+
}
|
|
583
|
+
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE: ${rawMode}. Use "list" or "call".`);
|
|
584
|
+
}
|
|
585
|
+
function resolveTransport() {
|
|
586
|
+
const rawTransport = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT?.toLowerCase() ?? "stdio";
|
|
587
|
+
if (rawTransport === "stdio" || rawTransport === "http" || rawTransport === "sse" || rawTransport === "webhook") {
|
|
588
|
+
return rawTransport;
|
|
589
|
+
}
|
|
590
|
+
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT: ${rawTransport}. Use "stdio", "http", "sse", or "webhook".`);
|
|
591
|
+
}
|
|
592
|
+
function parseStringArrayEnv(key, fallback) {
|
|
593
|
+
const raw = process.env[key];
|
|
594
|
+
if (!raw) {
|
|
595
|
+
return fallback;
|
|
596
|
+
}
|
|
597
|
+
const parsed = parseJsonEnv(key);
|
|
598
|
+
if (!Array.isArray(parsed) || parsed.some((value) => typeof value !== "string")) {
|
|
599
|
+
throw new Error(`${key} must be a JSON string array.`);
|
|
600
|
+
}
|
|
601
|
+
return parsed;
|
|
602
|
+
}
|
|
603
|
+
function parseRecordEnv(key) {
|
|
604
|
+
const raw = process.env[key];
|
|
605
|
+
if (!raw) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const parsed = parseJsonEnv(key);
|
|
609
|
+
if (!isRecord(parsed)) {
|
|
610
|
+
throw new Error(`${key} must be a JSON object.`);
|
|
611
|
+
}
|
|
612
|
+
return parsed;
|
|
613
|
+
}
|
|
614
|
+
function parseRecordEnvOrDefault(key, fallback) {
|
|
615
|
+
return parseRecordEnv(key) ?? fallback;
|
|
616
|
+
}
|
|
617
|
+
function parseStringRecordEnv(key) {
|
|
618
|
+
const parsed = parseRecordEnv(key);
|
|
619
|
+
if (!parsed) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const entries = Object.entries(parsed);
|
|
623
|
+
const invalidEntry = entries.find(([, value]) => typeof value !== "string");
|
|
624
|
+
if (invalidEntry) {
|
|
625
|
+
throw new Error(`${key} must contain only string values.`);
|
|
626
|
+
}
|
|
627
|
+
return Object.fromEntries(entries);
|
|
628
|
+
}
|
|
629
|
+
function parseJsonEnv(key) {
|
|
630
|
+
const raw = process.env[key];
|
|
631
|
+
if (!raw) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
try {
|
|
635
|
+
return JSON.parse(raw);
|
|
636
|
+
} catch {
|
|
637
|
+
throw new Error(`${key} contains invalid JSON.`);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function requireEnv(key) {
|
|
641
|
+
const value = process.env[key];
|
|
642
|
+
if (!value) {
|
|
643
|
+
throw new Error(`Missing required env var: ${key}`);
|
|
644
|
+
}
|
|
645
|
+
return value;
|
|
646
|
+
}
|
|
647
|
+
function isRecord(value) {
|
|
648
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
649
|
+
}
|
|
650
|
+
|
|
499
651
|
// src/sync/sync.enum.ts
|
|
500
652
|
import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
|
|
501
653
|
var SyncDirectionEnum = defineEnum3("SyncDirection", [
|
|
@@ -811,277 +963,189 @@ var ListSyncRunsContract = defineQuery({
|
|
|
811
963
|
]
|
|
812
964
|
}
|
|
813
965
|
});
|
|
814
|
-
// src/
|
|
815
|
-
|
|
816
|
-
{
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
966
|
+
// src/sync-engine/index.ts
|
|
967
|
+
class BasicFieldTransformer {
|
|
968
|
+
transform(value, expression) {
|
|
969
|
+
try {
|
|
970
|
+
if (expression.startsWith("uppercase")) {
|
|
971
|
+
return typeof value === "string" ? value.toUpperCase() : value;
|
|
972
|
+
}
|
|
973
|
+
if (expression.startsWith("lowercase")) {
|
|
974
|
+
return typeof value === "string" ? value.toLowerCase() : value;
|
|
975
|
+
}
|
|
976
|
+
if (expression.startsWith("trim")) {
|
|
977
|
+
return typeof value === "string" ? value.trim() : value;
|
|
978
|
+
}
|
|
979
|
+
if (expression.startsWith("default:")) {
|
|
980
|
+
const defaultVal = expression.replace("default:", "");
|
|
981
|
+
return value ?? JSON.parse(defaultVal);
|
|
982
|
+
}
|
|
983
|
+
if (expression.startsWith("concat:")) {
|
|
984
|
+
const separator = expression.replace("concat:", "") || " ";
|
|
985
|
+
if (Array.isArray(value)) {
|
|
986
|
+
return value.join(separator);
|
|
987
|
+
}
|
|
988
|
+
return value;
|
|
989
|
+
}
|
|
990
|
+
if (expression.startsWith("split:")) {
|
|
991
|
+
const separator = expression.replace("split:", "") || ",";
|
|
992
|
+
if (typeof value === "string") {
|
|
993
|
+
return value.split(separator);
|
|
994
|
+
}
|
|
995
|
+
return value;
|
|
996
|
+
}
|
|
997
|
+
if (expression.startsWith("number")) {
|
|
998
|
+
return Number(value);
|
|
999
|
+
}
|
|
1000
|
+
if (expression.startsWith("boolean")) {
|
|
1001
|
+
return Boolean(value);
|
|
1002
|
+
}
|
|
1003
|
+
if (expression.startsWith("string")) {
|
|
1004
|
+
return String(value);
|
|
1005
|
+
}
|
|
1006
|
+
return value;
|
|
1007
|
+
} catch {
|
|
1008
|
+
return value;
|
|
1009
|
+
}
|
|
857
1010
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
status: "CONNECTED",
|
|
865
|
-
lastSyncAt: "2024-01-16T10:00:00Z"
|
|
866
|
-
},
|
|
867
|
-
{
|
|
868
|
-
id: "conn-2",
|
|
869
|
-
integrationId: "int-1",
|
|
870
|
-
name: "Sandbox Salesforce",
|
|
871
|
-
status: "CONNECTED",
|
|
872
|
-
lastSyncAt: "2024-01-15T14:00:00Z"
|
|
873
|
-
},
|
|
874
|
-
{
|
|
875
|
-
id: "conn-3",
|
|
876
|
-
integrationId: "int-2",
|
|
877
|
-
name: "Marketing HubSpot",
|
|
878
|
-
status: "CONNECTED",
|
|
879
|
-
lastSyncAt: "2024-01-16T08:00:00Z"
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
id: "conn-4",
|
|
883
|
-
integrationId: "int-3",
|
|
884
|
-
name: "Stripe Live",
|
|
885
|
-
status: "CONNECTED",
|
|
886
|
-
lastSyncAt: "2024-01-16T12:00:00Z"
|
|
887
|
-
},
|
|
888
|
-
{
|
|
889
|
-
id: "conn-5",
|
|
890
|
-
integrationId: "int-5",
|
|
891
|
-
name: "Analytics Sheet",
|
|
892
|
-
status: "ERROR",
|
|
893
|
-
lastSyncAt: "2024-01-14T09:00:00Z",
|
|
894
|
-
error: "Authentication expired"
|
|
895
|
-
},
|
|
896
|
-
{
|
|
897
|
-
id: "conn-6",
|
|
898
|
-
integrationId: "int-6",
|
|
899
|
-
name: "PostHog Workspace",
|
|
900
|
-
status: "CONNECTED",
|
|
901
|
-
lastSyncAt: "2024-01-16T11:45:00Z"
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
class BasicSyncEngine {
|
|
1014
|
+
transformer;
|
|
1015
|
+
constructor(transformer) {
|
|
1016
|
+
this.transformer = transformer ?? new BasicFieldTransformer;
|
|
902
1017
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
id: "sync-2",
|
|
916
|
-
connectionId: "conn-1",
|
|
917
|
-
name: "Opportunities Sync",
|
|
918
|
-
frequency: "DAILY",
|
|
919
|
-
lastRunAt: "2024-01-16T00:00:00Z",
|
|
920
|
-
status: "SUCCESS",
|
|
921
|
-
recordsSynced: 340
|
|
922
|
-
},
|
|
923
|
-
{
|
|
924
|
-
id: "sync-3",
|
|
925
|
-
connectionId: "conn-3",
|
|
926
|
-
name: "Orders Sync",
|
|
927
|
-
frequency: "REALTIME",
|
|
928
|
-
lastRunAt: "2024-01-16T12:30:00Z",
|
|
929
|
-
status: "SUCCESS",
|
|
930
|
-
recordsSynced: 89
|
|
931
|
-
},
|
|
932
|
-
{
|
|
933
|
-
id: "sync-4",
|
|
934
|
-
connectionId: "conn-5",
|
|
935
|
-
name: "Metrics Export",
|
|
936
|
-
frequency: "DAILY",
|
|
937
|
-
lastRunAt: "2024-01-14T09:00:00Z",
|
|
938
|
-
status: "FAILED",
|
|
939
|
-
recordsSynced: 0
|
|
1018
|
+
async sync(_context) {
|
|
1019
|
+
const result = {
|
|
1020
|
+
success: true,
|
|
1021
|
+
recordsProcessed: 0,
|
|
1022
|
+
recordsCreated: 0,
|
|
1023
|
+
recordsUpdated: 0,
|
|
1024
|
+
recordsDeleted: 0,
|
|
1025
|
+
recordsFailed: 0,
|
|
1026
|
+
recordsSkipped: 0,
|
|
1027
|
+
errors: []
|
|
1028
|
+
};
|
|
1029
|
+
return result;
|
|
940
1030
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
`| Sync Configs | ${syncs.length} |`,
|
|
969
|
-
`| Records Synced (24h) | ${totalRecordsSynced.toLocaleString()} |`,
|
|
970
|
-
"",
|
|
971
|
-
"## Integrations",
|
|
972
|
-
"",
|
|
973
|
-
"| Name | Type | Connections | Status |",
|
|
974
|
-
"|------|------|-------------|--------|"
|
|
975
|
-
];
|
|
976
|
-
for (const integration of integrations) {
|
|
977
|
-
const statusIcon = integration.status === "ACTIVE" ? "\uD83D\uDFE2" : "\u26AB";
|
|
978
|
-
lines.push(`| ${integration.name} | ${integration.type} | ${integration.connectionCount} | ${statusIcon} ${integration.status} |`);
|
|
979
|
-
}
|
|
980
|
-
lines.push("");
|
|
981
|
-
lines.push("## Recent Sync Activity");
|
|
982
|
-
lines.push("");
|
|
983
|
-
lines.push("| Sync | Frequency | Last Run | Records | Status |");
|
|
984
|
-
lines.push("|------|-----------|----------|---------|--------|");
|
|
985
|
-
for (const sync of syncs) {
|
|
986
|
-
const lastRun = new Date(sync.lastRunAt).toLocaleString();
|
|
987
|
-
const statusIcon = sync.status === "SUCCESS" ? "\u2705" : "\u274C";
|
|
988
|
-
lines.push(`| ${sync.name} | ${sync.frequency} | ${lastRun} | ${sync.recordsSynced} | ${statusIcon} ${sync.status} |`);
|
|
989
|
-
}
|
|
990
|
-
if (errorConnections.length > 0) {
|
|
991
|
-
lines.push("");
|
|
992
|
-
lines.push("## \u26A0\uFE0F Connections with Errors");
|
|
993
|
-
lines.push("");
|
|
994
|
-
for (const conn of errorConnections) {
|
|
995
|
-
const integration = integrations.find((i) => i.id === conn.integrationId);
|
|
996
|
-
lines.push(`- **${conn.name}** (${integration?.name ?? "Unknown"}): ${conn.error ?? "Unknown error"}`);
|
|
1031
|
+
transformRecord(sourceRecord, mappings, _context) {
|
|
1032
|
+
const targetData = {};
|
|
1033
|
+
for (const mapping of mappings) {
|
|
1034
|
+
let value;
|
|
1035
|
+
let sourceValue;
|
|
1036
|
+
switch (mapping.mappingType) {
|
|
1037
|
+
case "DIRECT":
|
|
1038
|
+
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1039
|
+
break;
|
|
1040
|
+
case "TRANSFORM":
|
|
1041
|
+
sourceValue = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1042
|
+
value = mapping.transformExpression ? this.transformer.transform(sourceValue, mapping.transformExpression) : sourceValue;
|
|
1043
|
+
break;
|
|
1044
|
+
case "CONSTANT":
|
|
1045
|
+
value = mapping.constantValue;
|
|
1046
|
+
break;
|
|
1047
|
+
case "LOOKUP":
|
|
1048
|
+
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1049
|
+
break;
|
|
1050
|
+
case "COMPUTED":
|
|
1051
|
+
value = mapping.transformExpression ? this.evaluateComputed(sourceRecord.data, mapping.transformExpression) : null;
|
|
1052
|
+
break;
|
|
1053
|
+
default:
|
|
1054
|
+
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1055
|
+
}
|
|
1056
|
+
if (value === undefined || value === null) {
|
|
1057
|
+
value = mapping.defaultValue;
|
|
997
1058
|
}
|
|
1059
|
+
this.setNestedValue(targetData, mapping.targetField, value);
|
|
998
1060
|
}
|
|
999
1061
|
return {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
`)
|
|
1062
|
+
id: sourceRecord.id,
|
|
1063
|
+
data: targetData
|
|
1003
1064
|
};
|
|
1004
1065
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
""
|
|
1019
|
-
];
|
|
1020
|
-
for (const integration of integrations) {
|
|
1021
|
-
const intConnections = connections.filter((c) => c.integrationId === integration.id);
|
|
1022
|
-
if (intConnections.length === 0)
|
|
1023
|
-
continue;
|
|
1024
|
-
lines.push(`## ${integration.name}`);
|
|
1025
|
-
lines.push("");
|
|
1026
|
-
lines.push("| Connection | Status | Last Sync |");
|
|
1027
|
-
lines.push("|------------|--------|-----------|");
|
|
1028
|
-
for (const conn of intConnections) {
|
|
1029
|
-
const lastSync = new Date(conn.lastSyncAt).toLocaleString();
|
|
1030
|
-
const statusIcon = conn.status === "CONNECTED" ? "\uD83D\uDFE2" : conn.status === "ERROR" ? "\uD83D\uDD34" : "\u26AB";
|
|
1031
|
-
lines.push(`| ${conn.name} | ${statusIcon} ${conn.status} | ${lastSync} |`);
|
|
1066
|
+
validateRecord(record, mappings) {
|
|
1067
|
+
const errors = [];
|
|
1068
|
+
for (const mapping of mappings) {
|
|
1069
|
+
if (mapping.isRequired) {
|
|
1070
|
+
const value = this.getNestedValue(record.data, mapping.targetField);
|
|
1071
|
+
if (value === undefined || value === null) {
|
|
1072
|
+
errors.push({
|
|
1073
|
+
recordId: record.id,
|
|
1074
|
+
field: mapping.targetField,
|
|
1075
|
+
message: `Required field ${mapping.targetField} is missing`,
|
|
1076
|
+
code: "REQUIRED_FIELD_MISSING"
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1032
1079
|
}
|
|
1033
|
-
lines.push("");
|
|
1034
1080
|
}
|
|
1035
1081
|
return {
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
`)
|
|
1082
|
+
valid: errors.length === 0,
|
|
1083
|
+
errors
|
|
1039
1084
|
};
|
|
1040
1085
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
const connections = mockConnections;
|
|
1050
|
-
const lines = [
|
|
1051
|
-
"# Sync Configurations",
|
|
1052
|
-
"",
|
|
1053
|
-
"> Configure automated data synchronization",
|
|
1054
|
-
""
|
|
1055
|
-
];
|
|
1056
|
-
for (const sync of syncs) {
|
|
1057
|
-
const connection = connections.find((c) => c.id === sync.connectionId);
|
|
1058
|
-
const statusIcon = sync.status === "SUCCESS" ? "\u2705" : "\u274C";
|
|
1059
|
-
lines.push(`## ${sync.name}`);
|
|
1060
|
-
lines.push("");
|
|
1061
|
-
lines.push(`**Connection:** ${connection?.name ?? "Unknown"}`);
|
|
1062
|
-
lines.push(`**Frequency:** ${sync.frequency}`);
|
|
1063
|
-
lines.push(`**Status:** ${statusIcon} ${sync.status}`);
|
|
1064
|
-
lines.push(`**Last Run:** ${new Date(sync.lastRunAt).toLocaleString()}`);
|
|
1065
|
-
lines.push(`**Records Synced:** ${sync.recordsSynced.toLocaleString()}`);
|
|
1066
|
-
lines.push("");
|
|
1086
|
+
getNestedValue(obj, path) {
|
|
1087
|
+
const parts = path.split(".");
|
|
1088
|
+
let current = obj;
|
|
1089
|
+
for (const part of parts) {
|
|
1090
|
+
if (current === null || current === undefined) {
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
current = current[part];
|
|
1067
1094
|
}
|
|
1068
|
-
|
|
1069
|
-
lines.push("");
|
|
1070
|
-
lines.push("- **REALTIME**: Sync on every change");
|
|
1071
|
-
lines.push("- **HOURLY**: Sync every hour");
|
|
1072
|
-
lines.push("- **DAILY**: Sync once per day");
|
|
1073
|
-
lines.push("- **WEEKLY**: Sync once per week");
|
|
1074
|
-
lines.push("- **MANUAL**: Sync only when triggered");
|
|
1075
|
-
return {
|
|
1076
|
-
mimeType: "text/markdown",
|
|
1077
|
-
body: lines.join(`
|
|
1078
|
-
`)
|
|
1079
|
-
};
|
|
1095
|
+
return current;
|
|
1080
1096
|
}
|
|
1081
|
-
|
|
1097
|
+
setNestedValue(obj, path, value) {
|
|
1098
|
+
const parts = path.split(".");
|
|
1099
|
+
let current = obj;
|
|
1100
|
+
for (let i = 0;i < parts.length - 1; i++) {
|
|
1101
|
+
const part = parts[i];
|
|
1102
|
+
if (part === undefined)
|
|
1103
|
+
continue;
|
|
1104
|
+
if (!(part in current)) {
|
|
1105
|
+
current[part] = {};
|
|
1106
|
+
}
|
|
1107
|
+
current = current[part];
|
|
1108
|
+
}
|
|
1109
|
+
const lastPart = parts[parts.length - 1];
|
|
1110
|
+
if (lastPart !== undefined) {
|
|
1111
|
+
current[lastPart] = value;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
evaluateComputed(data, expression) {
|
|
1115
|
+
try {
|
|
1116
|
+
const result = expression.replace(/\$\{([^}]+)\}/g, (_, path) => {
|
|
1117
|
+
const value = this.getNestedValue(data, path);
|
|
1118
|
+
return String(value ?? "");
|
|
1119
|
+
});
|
|
1120
|
+
return result;
|
|
1121
|
+
} catch {
|
|
1122
|
+
return null;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
function createSyncEngine(transformer) {
|
|
1127
|
+
return new BasicSyncEngine(transformer);
|
|
1128
|
+
}
|
|
1129
|
+
function computeChecksum(data) {
|
|
1130
|
+
const str = JSON.stringify(data, Object.keys(data).sort());
|
|
1131
|
+
let hash = 0;
|
|
1132
|
+
for (let i = 0;i < str.length; i++) {
|
|
1133
|
+
const char = str.charCodeAt(i);
|
|
1134
|
+
hash = (hash << 5) - hash + char;
|
|
1135
|
+
hash = hash & hash;
|
|
1136
|
+
}
|
|
1137
|
+
return hash.toString(16);
|
|
1138
|
+
}
|
|
1139
|
+
function hasChanges(sourceChecksum, targetChecksum) {
|
|
1140
|
+
if (!sourceChecksum || !targetChecksum) {
|
|
1141
|
+
return true;
|
|
1142
|
+
}
|
|
1143
|
+
return sourceChecksum !== targetChecksum;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1082
1146
|
// src/ui/hooks/useIntegrationData.ts
|
|
1083
|
-
import { useCallback, useEffect, useState } from "react";
|
|
1084
1147
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
1148
|
+
import { useCallback, useEffect, useState } from "react";
|
|
1085
1149
|
"use client";
|
|
1086
1150
|
function useIntegrationData(projectId = "local-project") {
|
|
1087
1151
|
const { handlers } = useTemplateRuntime();
|
|
@@ -1131,6 +1195,9 @@ function useIntegrationData(projectId = "local-project") {
|
|
|
1131
1195
|
};
|
|
1132
1196
|
}
|
|
1133
1197
|
|
|
1198
|
+
// src/ui/hooks/index.ts
|
|
1199
|
+
"use client";
|
|
1200
|
+
|
|
1134
1201
|
// src/ui/IntegrationHubChat.tsx
|
|
1135
1202
|
import { ChatWithSidebar } from "@contractspec/module.ai-chat";
|
|
1136
1203
|
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
@@ -1164,7 +1231,6 @@ function IntegrationHubChat({
|
|
|
1164
1231
|
}
|
|
1165
1232
|
|
|
1166
1233
|
// src/ui/IntegrationDashboard.tsx
|
|
1167
|
-
import { useState as useState2 } from "react";
|
|
1168
1234
|
import {
|
|
1169
1235
|
Button,
|
|
1170
1236
|
ErrorState,
|
|
@@ -1172,6 +1238,7 @@ import {
|
|
|
1172
1238
|
StatCard,
|
|
1173
1239
|
StatCardGroup
|
|
1174
1240
|
} from "@contractspec/lib.design-system";
|
|
1241
|
+
import { useState as useState2 } from "react";
|
|
1175
1242
|
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
1176
1243
|
"use client";
|
|
1177
1244
|
var STATUS_COLORS = {
|
|
@@ -1228,7 +1295,7 @@ function IntegrationDashboard() {
|
|
|
1228
1295
|
className: "flex items-center justify-between",
|
|
1229
1296
|
children: [
|
|
1230
1297
|
/* @__PURE__ */ jsxDEV2("h2", {
|
|
1231
|
-
className: "text-2xl
|
|
1298
|
+
className: "font-bold text-2xl",
|
|
1232
1299
|
children: "Integration Hub"
|
|
1233
1300
|
}, undefined, false, undefined, this),
|
|
1234
1301
|
/* @__PURE__ */ jsxDEV2(Button, {
|
|
@@ -1263,14 +1330,14 @@ function IntegrationDashboard() {
|
|
|
1263
1330
|
]
|
|
1264
1331
|
}, undefined, true, undefined, this),
|
|
1265
1332
|
/* @__PURE__ */ jsxDEV2("nav", {
|
|
1266
|
-
className: "
|
|
1333
|
+
className: "flex gap-1 rounded-lg bg-muted p-1",
|
|
1267
1334
|
role: "tablist",
|
|
1268
1335
|
children: tabs.map((tab) => /* @__PURE__ */ jsxDEV2(Button, {
|
|
1269
1336
|
type: "button",
|
|
1270
1337
|
role: "tab",
|
|
1271
1338
|
"aria-selected": activeTab === tab.id,
|
|
1272
1339
|
onClick: () => setActiveTab(tab.id),
|
|
1273
|
-
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm
|
|
1340
|
+
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 font-medium text-sm transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
|
|
1274
1341
|
children: [
|
|
1275
1342
|
/* @__PURE__ */ jsxDEV2("span", {
|
|
1276
1343
|
children: tab.icon
|
|
@@ -1287,7 +1354,7 @@ function IntegrationDashboard() {
|
|
|
1287
1354
|
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
1288
1355
|
children: [
|
|
1289
1356
|
integrations.map((integration) => /* @__PURE__ */ jsxDEV2("div", {
|
|
1290
|
-
className: "
|
|
1357
|
+
className: "cursor-pointer rounded-lg border border-border bg-card p-4 transition-colors hover:bg-muted/50",
|
|
1291
1358
|
children: [
|
|
1292
1359
|
/* @__PURE__ */ jsxDEV2("div", {
|
|
1293
1360
|
className: "mb-3 flex items-center gap-3",
|
|
@@ -1314,7 +1381,7 @@ function IntegrationDashboard() {
|
|
|
1314
1381
|
className: "flex items-center justify-between",
|
|
1315
1382
|
children: [
|
|
1316
1383
|
/* @__PURE__ */ jsxDEV2("span", {
|
|
1317
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs
|
|
1384
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[integration.status] ?? ""}`,
|
|
1318
1385
|
children: integration.status
|
|
1319
1386
|
}, undefined, false, undefined, this),
|
|
1320
1387
|
/* @__PURE__ */ jsxDEV2("span", {
|
|
@@ -1326,37 +1393,37 @@ function IntegrationDashboard() {
|
|
|
1326
1393
|
]
|
|
1327
1394
|
}, integration.id, true, undefined, this)),
|
|
1328
1395
|
integrations.length === 0 && /* @__PURE__ */ jsxDEV2("div", {
|
|
1329
|
-
className: "
|
|
1396
|
+
className: "col-span-full flex h-64 items-center justify-center text-muted-foreground",
|
|
1330
1397
|
children: "No integrations configured"
|
|
1331
1398
|
}, undefined, false, undefined, this)
|
|
1332
1399
|
]
|
|
1333
1400
|
}, undefined, true, undefined, this),
|
|
1334
1401
|
activeTab === "connections" && /* @__PURE__ */ jsxDEV2("div", {
|
|
1335
|
-
className: "
|
|
1402
|
+
className: "rounded-lg border border-border",
|
|
1336
1403
|
children: /* @__PURE__ */ jsxDEV2("table", {
|
|
1337
1404
|
className: "w-full",
|
|
1338
1405
|
children: [
|
|
1339
1406
|
/* @__PURE__ */ jsxDEV2("thead", {
|
|
1340
|
-
className: "border-border bg-muted/30
|
|
1407
|
+
className: "border-border border-b bg-muted/30",
|
|
1341
1408
|
children: /* @__PURE__ */ jsxDEV2("tr", {
|
|
1342
1409
|
children: [
|
|
1343
1410
|
/* @__PURE__ */ jsxDEV2("th", {
|
|
1344
|
-
className: "px-4 py-3 text-left text-sm
|
|
1411
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
1345
1412
|
children: "Connection"
|
|
1346
1413
|
}, undefined, false, undefined, this),
|
|
1347
1414
|
/* @__PURE__ */ jsxDEV2("th", {
|
|
1348
|
-
className: "px-4 py-3 text-left text-sm
|
|
1415
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
1349
1416
|
children: "Status"
|
|
1350
1417
|
}, undefined, false, undefined, this),
|
|
1351
1418
|
/* @__PURE__ */ jsxDEV2("th", {
|
|
1352
|
-
className: "px-4 py-3 text-left text-sm
|
|
1419
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
1353
1420
|
children: "Last Sync"
|
|
1354
1421
|
}, undefined, false, undefined, this)
|
|
1355
1422
|
]
|
|
1356
1423
|
}, undefined, true, undefined, this)
|
|
1357
1424
|
}, undefined, false, undefined, this),
|
|
1358
1425
|
/* @__PURE__ */ jsxDEV2("tbody", {
|
|
1359
|
-
className: "divide-
|
|
1426
|
+
className: "divide-y divide-border",
|
|
1360
1427
|
children: [
|
|
1361
1428
|
connections.map((conn) => /* @__PURE__ */ jsxDEV2("tr", {
|
|
1362
1429
|
className: "hover:bg-muted/50",
|
|
@@ -1371,12 +1438,12 @@ function IntegrationDashboard() {
|
|
|
1371
1438
|
/* @__PURE__ */ jsxDEV2("td", {
|
|
1372
1439
|
className: "px-4 py-3",
|
|
1373
1440
|
children: /* @__PURE__ */ jsxDEV2("span", {
|
|
1374
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs
|
|
1441
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[conn.status] ?? ""}`,
|
|
1375
1442
|
children: conn.status
|
|
1376
1443
|
}, undefined, false, undefined, this)
|
|
1377
1444
|
}, undefined, false, undefined, this),
|
|
1378
1445
|
/* @__PURE__ */ jsxDEV2("td", {
|
|
1379
|
-
className: "
|
|
1446
|
+
className: "px-4 py-3 text-muted-foreground text-sm",
|
|
1380
1447
|
children: conn.lastSyncAt?.toLocaleString() ?? "Never"
|
|
1381
1448
|
}, undefined, false, undefined, this)
|
|
1382
1449
|
]
|
|
@@ -1384,7 +1451,7 @@ function IntegrationDashboard() {
|
|
|
1384
1451
|
connections.length === 0 && /* @__PURE__ */ jsxDEV2("tr", {
|
|
1385
1452
|
children: /* @__PURE__ */ jsxDEV2("td", {
|
|
1386
1453
|
colSpan: 3,
|
|
1387
|
-
className: "
|
|
1454
|
+
className: "px-4 py-8 text-center text-muted-foreground",
|
|
1388
1455
|
children: "No connections found"
|
|
1389
1456
|
}, undefined, false, undefined, this)
|
|
1390
1457
|
}, undefined, false, undefined, this)
|
|
@@ -1404,35 +1471,35 @@ function IntegrationDashboard() {
|
|
|
1404
1471
|
className: "min-h-[400px]"
|
|
1405
1472
|
}, undefined, false, undefined, this),
|
|
1406
1473
|
activeTab === "syncs" && /* @__PURE__ */ jsxDEV2("div", {
|
|
1407
|
-
className: "
|
|
1474
|
+
className: "rounded-lg border border-border",
|
|
1408
1475
|
children: /* @__PURE__ */ jsxDEV2("table", {
|
|
1409
1476
|
className: "w-full",
|
|
1410
1477
|
children: [
|
|
1411
1478
|
/* @__PURE__ */ jsxDEV2("thead", {
|
|
1412
|
-
className: "border-border bg-muted/30
|
|
1479
|
+
className: "border-border border-b bg-muted/30",
|
|
1413
1480
|
children: /* @__PURE__ */ jsxDEV2("tr", {
|
|
1414
1481
|
children: [
|
|
1415
1482
|
/* @__PURE__ */ jsxDEV2("th", {
|
|
1416
|
-
className: "px-4 py-3 text-left text-sm
|
|
1483
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
1417
1484
|
children: "Sync Config"
|
|
1418
1485
|
}, undefined, false, undefined, this),
|
|
1419
1486
|
/* @__PURE__ */ jsxDEV2("th", {
|
|
1420
|
-
className: "px-4 py-3 text-left text-sm
|
|
1487
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
1421
1488
|
children: "Frequency"
|
|
1422
1489
|
}, undefined, false, undefined, this),
|
|
1423
1490
|
/* @__PURE__ */ jsxDEV2("th", {
|
|
1424
|
-
className: "px-4 py-3 text-left text-sm
|
|
1491
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
1425
1492
|
children: "Status"
|
|
1426
1493
|
}, undefined, false, undefined, this),
|
|
1427
1494
|
/* @__PURE__ */ jsxDEV2("th", {
|
|
1428
|
-
className: "px-4 py-3 text-left text-sm
|
|
1495
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
1429
1496
|
children: "Records"
|
|
1430
1497
|
}, undefined, false, undefined, this)
|
|
1431
1498
|
]
|
|
1432
1499
|
}, undefined, true, undefined, this)
|
|
1433
1500
|
}, undefined, false, undefined, this),
|
|
1434
1501
|
/* @__PURE__ */ jsxDEV2("tbody", {
|
|
1435
|
-
className: "divide-
|
|
1502
|
+
className: "divide-y divide-border",
|
|
1436
1503
|
children: [
|
|
1437
1504
|
syncConfigs.map((sync) => /* @__PURE__ */ jsxDEV2("tr", {
|
|
1438
1505
|
className: "hover:bg-muted/50",
|
|
@@ -1461,12 +1528,12 @@ function IntegrationDashboard() {
|
|
|
1461
1528
|
/* @__PURE__ */ jsxDEV2("td", {
|
|
1462
1529
|
className: "px-4 py-3",
|
|
1463
1530
|
children: /* @__PURE__ */ jsxDEV2("span", {
|
|
1464
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs
|
|
1531
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[sync.status] ?? ""}`,
|
|
1465
1532
|
children: sync.status
|
|
1466
1533
|
}, undefined, false, undefined, this)
|
|
1467
1534
|
}, undefined, false, undefined, this),
|
|
1468
1535
|
/* @__PURE__ */ jsxDEV2("td", {
|
|
1469
|
-
className: "
|
|
1536
|
+
className: "px-4 py-3 text-muted-foreground text-sm",
|
|
1470
1537
|
children: sync.recordsSynced.toLocaleString()
|
|
1471
1538
|
}, undefined, false, undefined, this)
|
|
1472
1539
|
]
|
|
@@ -1474,7 +1541,7 @@ function IntegrationDashboard() {
|
|
|
1474
1541
|
syncConfigs.length === 0 && /* @__PURE__ */ jsxDEV2("tr", {
|
|
1475
1542
|
children: /* @__PURE__ */ jsxDEV2("td", {
|
|
1476
1543
|
colSpan: 4,
|
|
1477
|
-
className: "
|
|
1544
|
+
className: "px-4 py-8 text-center text-muted-foreground",
|
|
1478
1545
|
children: "No sync configurations found"
|
|
1479
1546
|
}, undefined, false, undefined, this)
|
|
1480
1547
|
}, undefined, false, undefined, this)
|
|
@@ -1489,339 +1556,274 @@ function IntegrationDashboard() {
|
|
|
1489
1556
|
}, undefined, true, undefined, this);
|
|
1490
1557
|
}
|
|
1491
1558
|
|
|
1492
|
-
// src/ui/
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
} catch {
|
|
1536
|
-
return value;
|
|
1537
|
-
}
|
|
1559
|
+
// src/ui/renderers/integration.markdown.ts
|
|
1560
|
+
var mockIntegrations = [
|
|
1561
|
+
{
|
|
1562
|
+
id: "int-1",
|
|
1563
|
+
name: "Salesforce",
|
|
1564
|
+
type: "CRM",
|
|
1565
|
+
status: "ACTIVE",
|
|
1566
|
+
connectionCount: 3
|
|
1567
|
+
},
|
|
1568
|
+
{
|
|
1569
|
+
id: "int-2",
|
|
1570
|
+
name: "HubSpot",
|
|
1571
|
+
type: "MARKETING",
|
|
1572
|
+
status: "ACTIVE",
|
|
1573
|
+
connectionCount: 2
|
|
1574
|
+
},
|
|
1575
|
+
{
|
|
1576
|
+
id: "int-3",
|
|
1577
|
+
name: "Stripe",
|
|
1578
|
+
type: "PAYMENT",
|
|
1579
|
+
status: "ACTIVE",
|
|
1580
|
+
connectionCount: 1
|
|
1581
|
+
},
|
|
1582
|
+
{
|
|
1583
|
+
id: "int-4",
|
|
1584
|
+
name: "Slack",
|
|
1585
|
+
type: "COMMUNICATION",
|
|
1586
|
+
status: "INACTIVE",
|
|
1587
|
+
connectionCount: 0
|
|
1588
|
+
},
|
|
1589
|
+
{
|
|
1590
|
+
id: "int-5",
|
|
1591
|
+
name: "Google Sheets",
|
|
1592
|
+
type: "DATA",
|
|
1593
|
+
status: "ACTIVE",
|
|
1594
|
+
connectionCount: 5
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
id: "int-6",
|
|
1598
|
+
name: "PostHog",
|
|
1599
|
+
type: "ANALYTICS",
|
|
1600
|
+
status: "ACTIVE",
|
|
1601
|
+
connectionCount: 1
|
|
1538
1602
|
}
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1603
|
+
];
|
|
1604
|
+
var mockConnections = [
|
|
1605
|
+
{
|
|
1606
|
+
id: "conn-1",
|
|
1607
|
+
integrationId: "int-1",
|
|
1608
|
+
name: "Production Salesforce",
|
|
1609
|
+
status: "CONNECTED",
|
|
1610
|
+
lastSyncAt: "2024-01-16T10:00:00Z"
|
|
1611
|
+
},
|
|
1612
|
+
{
|
|
1613
|
+
id: "conn-2",
|
|
1614
|
+
integrationId: "int-1",
|
|
1615
|
+
name: "Sandbox Salesforce",
|
|
1616
|
+
status: "CONNECTED",
|
|
1617
|
+
lastSyncAt: "2024-01-15T14:00:00Z"
|
|
1618
|
+
},
|
|
1619
|
+
{
|
|
1620
|
+
id: "conn-3",
|
|
1621
|
+
integrationId: "int-2",
|
|
1622
|
+
name: "Marketing HubSpot",
|
|
1623
|
+
status: "CONNECTED",
|
|
1624
|
+
lastSyncAt: "2024-01-16T08:00:00Z"
|
|
1625
|
+
},
|
|
1626
|
+
{
|
|
1627
|
+
id: "conn-4",
|
|
1628
|
+
integrationId: "int-3",
|
|
1629
|
+
name: "Stripe Live",
|
|
1630
|
+
status: "CONNECTED",
|
|
1631
|
+
lastSyncAt: "2024-01-16T12:00:00Z"
|
|
1632
|
+
},
|
|
1633
|
+
{
|
|
1634
|
+
id: "conn-5",
|
|
1635
|
+
integrationId: "int-5",
|
|
1636
|
+
name: "Analytics Sheet",
|
|
1637
|
+
status: "ERROR",
|
|
1638
|
+
lastSyncAt: "2024-01-14T09:00:00Z",
|
|
1639
|
+
error: "Authentication expired"
|
|
1640
|
+
},
|
|
1641
|
+
{
|
|
1642
|
+
id: "conn-6",
|
|
1643
|
+
integrationId: "int-6",
|
|
1644
|
+
name: "PostHog Workspace",
|
|
1645
|
+
status: "CONNECTED",
|
|
1646
|
+
lastSyncAt: "2024-01-16T11:45:00Z"
|
|
1545
1647
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1648
|
+
];
|
|
1649
|
+
var mockSyncConfigs = [
|
|
1650
|
+
{
|
|
1651
|
+
id: "sync-1",
|
|
1652
|
+
connectionId: "conn-1",
|
|
1653
|
+
name: "Contacts Sync",
|
|
1654
|
+
frequency: "HOURLY",
|
|
1655
|
+
lastRunAt: "2024-01-16T10:00:00Z",
|
|
1656
|
+
status: "SUCCESS",
|
|
1657
|
+
recordsSynced: 1250
|
|
1658
|
+
},
|
|
1659
|
+
{
|
|
1660
|
+
id: "sync-2",
|
|
1661
|
+
connectionId: "conn-1",
|
|
1662
|
+
name: "Opportunities Sync",
|
|
1663
|
+
frequency: "DAILY",
|
|
1664
|
+
lastRunAt: "2024-01-16T00:00:00Z",
|
|
1665
|
+
status: "SUCCESS",
|
|
1666
|
+
recordsSynced: 340
|
|
1667
|
+
},
|
|
1668
|
+
{
|
|
1669
|
+
id: "sync-3",
|
|
1670
|
+
connectionId: "conn-3",
|
|
1671
|
+
name: "Orders Sync",
|
|
1672
|
+
frequency: "REALTIME",
|
|
1673
|
+
lastRunAt: "2024-01-16T12:30:00Z",
|
|
1674
|
+
status: "SUCCESS",
|
|
1675
|
+
recordsSynced: 89
|
|
1676
|
+
},
|
|
1677
|
+
{
|
|
1678
|
+
id: "sync-4",
|
|
1679
|
+
connectionId: "conn-5",
|
|
1680
|
+
name: "Metrics Export",
|
|
1681
|
+
frequency: "DAILY",
|
|
1682
|
+
lastRunAt: "2024-01-14T09:00:00Z",
|
|
1683
|
+
status: "FAILED",
|
|
1684
|
+
recordsSynced: 0
|
|
1558
1685
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
case "DIRECT":
|
|
1566
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1567
|
-
break;
|
|
1568
|
-
case "TRANSFORM":
|
|
1569
|
-
sourceValue = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1570
|
-
value = mapping.transformExpression ? this.transformer.transform(sourceValue, mapping.transformExpression) : sourceValue;
|
|
1571
|
-
break;
|
|
1572
|
-
case "CONSTANT":
|
|
1573
|
-
value = mapping.constantValue;
|
|
1574
|
-
break;
|
|
1575
|
-
case "LOOKUP":
|
|
1576
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1577
|
-
break;
|
|
1578
|
-
case "COMPUTED":
|
|
1579
|
-
value = mapping.transformExpression ? this.evaluateComputed(sourceRecord.data, mapping.transformExpression) : null;
|
|
1580
|
-
break;
|
|
1581
|
-
default:
|
|
1582
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1583
|
-
}
|
|
1584
|
-
if (value === undefined || value === null) {
|
|
1585
|
-
value = mapping.defaultValue;
|
|
1586
|
-
}
|
|
1587
|
-
this.setNestedValue(targetData, mapping.targetField, value);
|
|
1686
|
+
];
|
|
1687
|
+
var integrationDashboardMarkdownRenderer = {
|
|
1688
|
+
target: "markdown",
|
|
1689
|
+
render: async (desc) => {
|
|
1690
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "IntegrationDashboard") {
|
|
1691
|
+
throw new Error("integrationDashboardMarkdownRenderer: not IntegrationDashboard");
|
|
1588
1692
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1693
|
+
const integrations = mockIntegrations;
|
|
1694
|
+
const connections = mockConnections;
|
|
1695
|
+
const syncs = mockSyncConfigs;
|
|
1696
|
+
const activeIntegrations = integrations.filter((i) => i.status === "ACTIVE");
|
|
1697
|
+
const connectedConnections = connections.filter((c) => c.status === "CONNECTED");
|
|
1698
|
+
const errorConnections = connections.filter((c) => c.status === "ERROR");
|
|
1699
|
+
const successfulSyncs = syncs.filter((s) => s.status === "SUCCESS");
|
|
1700
|
+
const totalRecordsSynced = successfulSyncs.reduce((sum, s) => sum + s.recordsSynced, 0);
|
|
1701
|
+
const lines = [
|
|
1702
|
+
"# Integration Hub",
|
|
1703
|
+
"",
|
|
1704
|
+
"> Connect and sync data with external services",
|
|
1705
|
+
"",
|
|
1706
|
+
"## Overview",
|
|
1707
|
+
"",
|
|
1708
|
+
"| Metric | Value |",
|
|
1709
|
+
"|--------|-------|",
|
|
1710
|
+
`| Active Integrations | ${activeIntegrations.length} |`,
|
|
1711
|
+
`| Connected Services | ${connectedConnections.length} |`,
|
|
1712
|
+
`| Error Connections | ${errorConnections.length} |`,
|
|
1713
|
+
`| Sync Configs | ${syncs.length} |`,
|
|
1714
|
+
`| Records Synced (24h) | ${totalRecordsSynced.toLocaleString()} |`,
|
|
1715
|
+
"",
|
|
1716
|
+
"## Integrations",
|
|
1717
|
+
"",
|
|
1718
|
+
"| Name | Type | Connections | Status |",
|
|
1719
|
+
"|------|------|-------------|--------|"
|
|
1720
|
+
];
|
|
1721
|
+
for (const integration of integrations) {
|
|
1722
|
+
const statusIcon = integration.status === "ACTIVE" ? "\uD83D\uDFE2" : "\u26AB";
|
|
1723
|
+
lines.push(`| ${integration.name} | ${integration.type} | ${integration.connectionCount} | ${statusIcon} ${integration.status} |`);
|
|
1724
|
+
}
|
|
1725
|
+
lines.push("");
|
|
1726
|
+
lines.push("## Recent Sync Activity");
|
|
1727
|
+
lines.push("");
|
|
1728
|
+
lines.push("| Sync | Frequency | Last Run | Records | Status |");
|
|
1729
|
+
lines.push("|------|-----------|----------|---------|--------|");
|
|
1730
|
+
for (const sync of syncs) {
|
|
1731
|
+
const lastRun = new Date(sync.lastRunAt).toLocaleString();
|
|
1732
|
+
const statusIcon = sync.status === "SUCCESS" ? "\u2705" : "\u274C";
|
|
1733
|
+
lines.push(`| ${sync.name} | ${sync.frequency} | ${lastRun} | ${sync.recordsSynced} | ${statusIcon} ${sync.status} |`);
|
|
1734
|
+
}
|
|
1735
|
+
if (errorConnections.length > 0) {
|
|
1736
|
+
lines.push("");
|
|
1737
|
+
lines.push("## \u26A0\uFE0F Connections with Errors");
|
|
1738
|
+
lines.push("");
|
|
1739
|
+
for (const conn of errorConnections) {
|
|
1740
|
+
const integration = integrations.find((i) => i.id === conn.integrationId);
|
|
1741
|
+
lines.push(`- **${conn.name}** (${integration?.name ?? "Unknown"}): ${conn.error ?? "Unknown error"}`);
|
|
1607
1742
|
}
|
|
1608
1743
|
}
|
|
1609
1744
|
return {
|
|
1610
|
-
|
|
1611
|
-
|
|
1745
|
+
mimeType: "text/markdown",
|
|
1746
|
+
body: lines.join(`
|
|
1747
|
+
`)
|
|
1612
1748
|
};
|
|
1613
1749
|
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
}
|
|
1621
|
-
current = current[part];
|
|
1750
|
+
};
|
|
1751
|
+
var connectionListMarkdownRenderer = {
|
|
1752
|
+
target: "markdown",
|
|
1753
|
+
render: async (desc) => {
|
|
1754
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "ConnectionList") {
|
|
1755
|
+
throw new Error("connectionListMarkdownRenderer: not ConnectionList");
|
|
1622
1756
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1757
|
+
const connections = mockConnections;
|
|
1758
|
+
const integrations = mockIntegrations;
|
|
1759
|
+
const lines = [
|
|
1760
|
+
"# Connections",
|
|
1761
|
+
"",
|
|
1762
|
+
"> Manage connections to external services",
|
|
1763
|
+
""
|
|
1764
|
+
];
|
|
1765
|
+
for (const integration of integrations) {
|
|
1766
|
+
const intConnections = connections.filter((c) => c.integrationId === integration.id);
|
|
1767
|
+
if (intConnections.length === 0)
|
|
1631
1768
|
continue;
|
|
1632
|
-
|
|
1633
|
-
|
|
1769
|
+
lines.push(`## ${integration.name}`);
|
|
1770
|
+
lines.push("");
|
|
1771
|
+
lines.push("| Connection | Status | Last Sync |");
|
|
1772
|
+
lines.push("|------------|--------|-----------|");
|
|
1773
|
+
for (const conn of intConnections) {
|
|
1774
|
+
const lastSync = new Date(conn.lastSyncAt).toLocaleString();
|
|
1775
|
+
const statusIcon = conn.status === "CONNECTED" ? "\uD83D\uDFE2" : conn.status === "ERROR" ? "\uD83D\uDD34" : "\u26AB";
|
|
1776
|
+
lines.push(`| ${conn.name} | ${statusIcon} ${conn.status} | ${lastSync} |`);
|
|
1634
1777
|
}
|
|
1635
|
-
|
|
1636
|
-
}
|
|
1637
|
-
const lastPart = parts[parts.length - 1];
|
|
1638
|
-
if (lastPart !== undefined) {
|
|
1639
|
-
current[lastPart] = value;
|
|
1778
|
+
lines.push("");
|
|
1640
1779
|
}
|
|
1780
|
+
return {
|
|
1781
|
+
mimeType: "text/markdown",
|
|
1782
|
+
body: lines.join(`
|
|
1783
|
+
`)
|
|
1784
|
+
};
|
|
1641
1785
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
return result;
|
|
1649
|
-
} catch {
|
|
1650
|
-
return null;
|
|
1786
|
+
};
|
|
1787
|
+
var syncConfigMarkdownRenderer = {
|
|
1788
|
+
target: "markdown",
|
|
1789
|
+
render: async (desc) => {
|
|
1790
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "SyncConfigEditor") {
|
|
1791
|
+
throw new Error("syncConfigMarkdownRenderer: not SyncConfigEditor");
|
|
1651
1792
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
return sourceChecksum !== targetChecksum;
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
// src/mcp-example.ts
|
|
1675
|
-
import { randomUUID } from "crypto";
|
|
1676
|
-
import {
|
|
1677
|
-
createMcpToolsets
|
|
1678
|
-
} from "@contractspec/lib.ai-agent/tools/mcp-client";
|
|
1679
|
-
var DEFAULT_STDIO_ARGS = [
|
|
1680
|
-
"-y",
|
|
1681
|
-
"@modelcontextprotocol/server-filesystem",
|
|
1682
|
-
"."
|
|
1683
|
-
];
|
|
1684
|
-
async function runIntegrationHubMcpExampleFromEnv() {
|
|
1685
|
-
const mode = resolveMode();
|
|
1686
|
-
const transport = resolveTransport();
|
|
1687
|
-
const config = buildMcpConfigFromEnv();
|
|
1688
|
-
const toolset = await createMcpToolsets([config], {
|
|
1689
|
-
onNameCollision: "error"
|
|
1690
|
-
});
|
|
1691
|
-
try {
|
|
1692
|
-
const toolNames = Object.keys(toolset.tools).sort();
|
|
1693
|
-
const output = {
|
|
1694
|
-
mode,
|
|
1695
|
-
server: {
|
|
1696
|
-
name: config.name,
|
|
1697
|
-
transport
|
|
1698
|
-
},
|
|
1699
|
-
authMethod: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_AUTH_METHOD,
|
|
1700
|
-
apiVersion: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_API_VERSION,
|
|
1701
|
-
tools: toolNames
|
|
1702
|
-
};
|
|
1703
|
-
if (mode === "call") {
|
|
1704
|
-
const toolName = requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_NAME");
|
|
1705
|
-
const toolArgs = parseRecordEnvOrDefault("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_ARGS_JSON", {});
|
|
1706
|
-
const tool = toolset.tools[toolName];
|
|
1707
|
-
if (!tool?.execute) {
|
|
1708
|
-
throw new Error(`Tool "${toolName}" was not found. Available tools: ${toolNames.join(", ")}`);
|
|
1709
|
-
}
|
|
1710
|
-
const toolOutput = await tool.execute(toolArgs, {
|
|
1711
|
-
toolCallId: `integration-hub-${randomUUID()}`,
|
|
1712
|
-
messages: []
|
|
1713
|
-
});
|
|
1714
|
-
output.toolCall = {
|
|
1715
|
-
name: toolName,
|
|
1716
|
-
args: toolArgs,
|
|
1717
|
-
output: toolOutput
|
|
1718
|
-
};
|
|
1793
|
+
const syncs = mockSyncConfigs;
|
|
1794
|
+
const connections = mockConnections;
|
|
1795
|
+
const lines = [
|
|
1796
|
+
"# Sync Configurations",
|
|
1797
|
+
"",
|
|
1798
|
+
"> Configure automated data synchronization",
|
|
1799
|
+
""
|
|
1800
|
+
];
|
|
1801
|
+
for (const sync of syncs) {
|
|
1802
|
+
const connection = connections.find((c) => c.id === sync.connectionId);
|
|
1803
|
+
const statusIcon = sync.status === "SUCCESS" ? "\u2705" : "\u274C";
|
|
1804
|
+
lines.push(`## ${sync.name}`);
|
|
1805
|
+
lines.push("");
|
|
1806
|
+
lines.push(`**Connection:** ${connection?.name ?? "Unknown"}`);
|
|
1807
|
+
lines.push(`**Frequency:** ${sync.frequency}`);
|
|
1808
|
+
lines.push(`**Status:** ${statusIcon} ${sync.status}`);
|
|
1809
|
+
lines.push(`**Last Run:** ${new Date(sync.lastRunAt).toLocaleString()}`);
|
|
1810
|
+
lines.push(`**Records Synced:** ${sync.recordsSynced.toLocaleString()}`);
|
|
1811
|
+
lines.push("");
|
|
1719
1812
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
function buildMcpConfigFromEnv() {
|
|
1728
|
-
const name = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_NAME ?? "filesystem";
|
|
1729
|
-
const transport = resolveTransport();
|
|
1730
|
-
const toolPrefix = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_PREFIX;
|
|
1731
|
-
if (transport === "stdio") {
|
|
1813
|
+
lines.push("## Frequency Options");
|
|
1814
|
+
lines.push("");
|
|
1815
|
+
lines.push("- **REALTIME**: Sync on every change");
|
|
1816
|
+
lines.push("- **HOURLY**: Sync every hour");
|
|
1817
|
+
lines.push("- **DAILY**: Sync once per day");
|
|
1818
|
+
lines.push("- **WEEKLY**: Sync once per week");
|
|
1819
|
+
lines.push("- **MANUAL**: Sync only when triggered");
|
|
1732
1820
|
return {
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
args: parseStringArrayEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_ARGS_JSON", DEFAULT_STDIO_ARGS),
|
|
1737
|
-
toolPrefix
|
|
1821
|
+
mimeType: "text/markdown",
|
|
1822
|
+
body: lines.join(`
|
|
1823
|
+
`)
|
|
1738
1824
|
};
|
|
1739
1825
|
}
|
|
1740
|
-
|
|
1741
|
-
const accessTokenEnvVar = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN_ENV;
|
|
1742
|
-
const mcpTransport = transport === "webhook" || transport === "http" ? "http" : "sse";
|
|
1743
|
-
return {
|
|
1744
|
-
name,
|
|
1745
|
-
transport: mcpTransport,
|
|
1746
|
-
url: requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_URL"),
|
|
1747
|
-
headers: parseStringRecordEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_HEADERS_JSON"),
|
|
1748
|
-
accessToken,
|
|
1749
|
-
accessTokenEnvVar,
|
|
1750
|
-
toolPrefix
|
|
1751
|
-
};
|
|
1752
|
-
}
|
|
1753
|
-
function resolveMode() {
|
|
1754
|
-
const rawMode = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE?.toLowerCase() ?? "list";
|
|
1755
|
-
if (rawMode === "list" || rawMode === "call") {
|
|
1756
|
-
return rawMode;
|
|
1757
|
-
}
|
|
1758
|
-
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE: ${rawMode}. Use "list" or "call".`);
|
|
1759
|
-
}
|
|
1760
|
-
function resolveTransport() {
|
|
1761
|
-
const rawTransport = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT?.toLowerCase() ?? "stdio";
|
|
1762
|
-
if (rawTransport === "stdio" || rawTransport === "http" || rawTransport === "sse" || rawTransport === "webhook") {
|
|
1763
|
-
return rawTransport;
|
|
1764
|
-
}
|
|
1765
|
-
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT: ${rawTransport}. Use "stdio", "http", "sse", or "webhook".`);
|
|
1766
|
-
}
|
|
1767
|
-
function parseStringArrayEnv(key, fallback) {
|
|
1768
|
-
const raw = process.env[key];
|
|
1769
|
-
if (!raw) {
|
|
1770
|
-
return fallback;
|
|
1771
|
-
}
|
|
1772
|
-
const parsed = parseJsonEnv(key);
|
|
1773
|
-
if (!Array.isArray(parsed) || parsed.some((value) => typeof value !== "string")) {
|
|
1774
|
-
throw new Error(`${key} must be a JSON string array.`);
|
|
1775
|
-
}
|
|
1776
|
-
return parsed;
|
|
1777
|
-
}
|
|
1778
|
-
function parseRecordEnv(key) {
|
|
1779
|
-
const raw = process.env[key];
|
|
1780
|
-
if (!raw) {
|
|
1781
|
-
return;
|
|
1782
|
-
}
|
|
1783
|
-
const parsed = parseJsonEnv(key);
|
|
1784
|
-
if (!isRecord(parsed)) {
|
|
1785
|
-
throw new Error(`${key} must be a JSON object.`);
|
|
1786
|
-
}
|
|
1787
|
-
return parsed;
|
|
1788
|
-
}
|
|
1789
|
-
function parseRecordEnvOrDefault(key, fallback) {
|
|
1790
|
-
return parseRecordEnv(key) ?? fallback;
|
|
1791
|
-
}
|
|
1792
|
-
function parseStringRecordEnv(key) {
|
|
1793
|
-
const parsed = parseRecordEnv(key);
|
|
1794
|
-
if (!parsed) {
|
|
1795
|
-
return;
|
|
1796
|
-
}
|
|
1797
|
-
const entries = Object.entries(parsed);
|
|
1798
|
-
const invalidEntry = entries.find(([, value]) => typeof value !== "string");
|
|
1799
|
-
if (invalidEntry) {
|
|
1800
|
-
throw new Error(`${key} must contain only string values.`);
|
|
1801
|
-
}
|
|
1802
|
-
return Object.fromEntries(entries);
|
|
1803
|
-
}
|
|
1804
|
-
function parseJsonEnv(key) {
|
|
1805
|
-
const raw = process.env[key];
|
|
1806
|
-
if (!raw) {
|
|
1807
|
-
return;
|
|
1808
|
-
}
|
|
1809
|
-
try {
|
|
1810
|
-
return JSON.parse(raw);
|
|
1811
|
-
} catch {
|
|
1812
|
-
throw new Error(`${key} contains invalid JSON.`);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
function requireEnv(key) {
|
|
1816
|
-
const value = process.env[key];
|
|
1817
|
-
if (!value) {
|
|
1818
|
-
throw new Error(`Missing required env var: ${key}`);
|
|
1819
|
-
}
|
|
1820
|
-
return value;
|
|
1821
|
-
}
|
|
1822
|
-
function isRecord(value) {
|
|
1823
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1824
|
-
}
|
|
1826
|
+
};
|
|
1825
1827
|
export {
|
|
1826
1828
|
useIntegrationData,
|
|
1827
1829
|
syncConfigMarkdownRenderer,
|