@contractspec/example.integration-hub 3.8.8 → 3.8.10
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/dist/connection/connection.enum.js +1 -29
- package/dist/connection/connection.operation.js +1 -124
- package/dist/connection/connection.presentation.js +1 -125
- package/dist/connection/connection.schema.js +1 -71
- package/dist/connection/index.js +1 -127
- package/dist/docs/index.js +5 -49
- package/dist/docs/integration-hub.docblock.js +5 -49
- package/dist/events.js +1 -211
- package/dist/example.js +1 -42
- package/dist/handlers/index.js +5 -292
- package/dist/handlers/integration.handlers.js +5 -292
- package/dist/index.js +8 -2355
- package/dist/integration/index.js +1 -92
- package/dist/integration/integration.enum.js +1 -12
- package/dist/integration/integration.operations.js +1 -89
- package/dist/integration/integration.presentation.js +1 -120
- package/dist/integration/integration.schema.js +1 -42
- package/dist/integration-hub.capability.js +1 -43
- package/dist/integration-hub.feature.js +1 -330
- package/dist/mcp-example.js +1 -154
- package/dist/node/connection/connection.enum.js +1 -29
- package/dist/node/connection/connection.operation.js +1 -124
- package/dist/node/connection/connection.presentation.js +1 -125
- package/dist/node/connection/connection.schema.js +1 -71
- package/dist/node/connection/index.js +1 -127
- package/dist/node/docs/index.js +5 -49
- package/dist/node/docs/integration-hub.docblock.js +5 -49
- package/dist/node/events.js +1 -211
- package/dist/node/example.js +1 -42
- package/dist/node/handlers/index.js +5 -292
- package/dist/node/handlers/integration.handlers.js +5 -292
- package/dist/node/index.js +8 -2355
- package/dist/node/integration/index.js +1 -92
- package/dist/node/integration/integration.enum.js +1 -12
- package/dist/node/integration/integration.operations.js +1 -89
- package/dist/node/integration/integration.presentation.js +1 -120
- package/dist/node/integration/integration.schema.js +1 -42
- package/dist/node/integration-hub.capability.js +1 -43
- package/dist/node/integration-hub.feature.js +1 -330
- package/dist/node/mcp-example.js +1 -154
- package/dist/node/run-mcp.js +1 -159
- package/dist/node/seeders/index.js +6 -60
- package/dist/node/sync/index.js +1 -332
- package/dist/node/sync/sync.enum.js +1 -26
- package/dist/node/sync/sync.operations.js +1 -321
- package/dist/node/sync/sync.presentation.js +1 -301
- package/dist/node/sync/sync.schema.js +1 -154
- package/dist/node/sync-engine/index.js +1 -186
- package/dist/node/tests/operations.test-spec.js +1 -85
- package/dist/node/ui/IntegrationDashboard.js +1 -886
- package/dist/node/ui/IntegrationDashboard.visualizations.js +1 -250
- package/dist/node/ui/IntegrationHubChat.js +1 -34
- package/dist/node/ui/hooks/index.js +1 -57
- package/dist/node/ui/hooks/useIntegrationData.js +1 -54
- package/dist/node/ui/index.js +4 -1173
- package/dist/node/ui/renderers/index.js +4 -484
- package/dist/node/ui/renderers/integration.markdown.js +4 -484
- package/dist/node/ui/tables/ConnectionsTable.js +1 -211
- package/dist/node/ui/tables/IntegrationTables.js +1 -361
- package/dist/node/ui/tables/SyncConfigsTable.js +1 -230
- package/dist/node/ui/tables/integration-table.shared.js +1 -84
- package/dist/node/visualizations/catalog.js +1 -137
- package/dist/node/visualizations/index.js +1 -211
- package/dist/node/visualizations/selectors.js +1 -204
- package/dist/run-mcp.js +1 -159
- package/dist/seeders/index.js +6 -60
- package/dist/sync/index.js +1 -332
- package/dist/sync/sync.enum.js +1 -26
- package/dist/sync/sync.operations.js +1 -321
- package/dist/sync/sync.presentation.js +1 -301
- package/dist/sync/sync.schema.js +1 -154
- package/dist/sync-engine/index.js +1 -186
- package/dist/tests/operations.test-spec.js +1 -85
- package/dist/ui/IntegrationDashboard.js +1 -886
- package/dist/ui/IntegrationDashboard.visualizations.js +1 -250
- package/dist/ui/IntegrationHubChat.js +1 -34
- package/dist/ui/hooks/index.js +1 -57
- package/dist/ui/hooks/useIntegrationData.js +1 -54
- package/dist/ui/index.js +4 -1173
- package/dist/ui/renderers/index.js +4 -484
- package/dist/ui/renderers/integration.markdown.js +4 -484
- package/dist/ui/tables/ConnectionsTable.js +1 -211
- package/dist/ui/tables/IntegrationTables.js +1 -361
- package/dist/ui/tables/SyncConfigsTable.js +1 -230
- package/dist/ui/tables/integration-table.shared.js +1 -84
- package/dist/visualizations/catalog.js +1 -137
- package/dist/visualizations/index.js +1 -211
- package/dist/visualizations/selectors.js +1 -204
- package/package.json +14 -14
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
|
|
4
|
-
var integrationHubDocBlocks = [
|
|
5
|
-
{
|
|
6
|
-
id: "docs.examples.integration-hub",
|
|
7
|
-
title: "Integration Hub",
|
|
8
|
-
summary: "Generic integration center with connectors, connections, sync configs, field mappings, and sync logs.",
|
|
9
|
-
kind: "reference",
|
|
10
|
-
visibility: "public",
|
|
11
|
-
route: "/docs/examples/integration-hub",
|
|
12
|
-
tags: ["integrations", "sync", "etl", "connectors"],
|
|
13
|
-
body: `## Entities
|
|
2
|
+
import{registerDocBlocks as f}from"@contractspec/lib.contracts-spec/docs";var h=[{id:"docs.examples.integration-hub",title:"Integration Hub",summary:"Generic integration center with connectors, connections, sync configs, field mappings, and sync logs.",kind:"reference",visibility:"public",route:"/docs/examples/integration-hub",tags:["integrations","sync","etl","connectors"],body:`## Entities
|
|
14
3
|
|
|
15
4
|
- Integration, Connection, SyncConfig, FieldMapping, SyncLog.
|
|
16
5
|
- Sync engine config lives in \`src/sync-engine\` to map remote <-> local entities.
|
|
@@ -36,17 +25,7 @@ var integrationHubDocBlocks = [
|
|
|
36
25
|
- Seed data includes voice integrations for \`ai-voice.gradium\` and \`ai-voice.fal\`.
|
|
37
26
|
- Feature flags can gate specific providers; metering can track sync volume.
|
|
38
27
|
- The dashboard tables demonstrate client-mode sorting, pagination, visibility, pinning, resizing, and row expansion on the shared table stack.
|
|
39
|
-
`
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: "docs.examples.integration-hub.goal",
|
|
43
|
-
title: "Integration Hub \u2014 Goal",
|
|
44
|
-
summary: "Why this integration hub exists and what success looks like.",
|
|
45
|
-
kind: "goal",
|
|
46
|
-
visibility: "public",
|
|
47
|
-
route: "/docs/examples/integration-hub/goal",
|
|
48
|
-
tags: ["integrations", "goal"],
|
|
49
|
-
body: `## Why it matters
|
|
28
|
+
`},{id:"docs.examples.integration-hub.goal",title:"Integration Hub \u2014 Goal",summary:"Why this integration hub exists and what success looks like.",kind:"goal",visibility:"public",route:"/docs/examples/integration-hub/goal",tags:["integrations","goal"],body:`## Why it matters
|
|
50
29
|
- Gives a regenerable, provider-agnostic integration hub with explicit mappings.
|
|
51
30
|
- Prevents drift between sync configs, mappings, and event/log outputs.
|
|
52
31
|
|
|
@@ -56,17 +35,7 @@ var integrationHubDocBlocks = [
|
|
|
56
35
|
|
|
57
36
|
## Success criteria
|
|
58
37
|
- Connections and mappings regenerate safely after spec edits.
|
|
59
|
-
- Sync events and logs provide auditability; payloads are stored and PII-scoped.`
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: "docs.examples.integration-hub.usage",
|
|
63
|
-
title: "Integration Hub \u2014 Usage",
|
|
64
|
-
summary: "How to configure connectors, mappings, and scheduled syncs.",
|
|
65
|
-
kind: "usage",
|
|
66
|
-
visibility: "public",
|
|
67
|
-
route: "/docs/examples/integration-hub/usage",
|
|
68
|
-
tags: ["integrations", "usage"],
|
|
69
|
-
body: `## Setup
|
|
38
|
+
- Sync events and logs provide auditability; payloads are stored and PII-scoped.`},{id:"docs.examples.integration-hub.usage",title:"Integration Hub \u2014 Usage",summary:"How to configure connectors, mappings, and scheduled syncs.",kind:"usage",visibility:"public",route:"/docs/examples/integration-hub/usage",tags:["integrations","usage"],body:`## Setup
|
|
70
39
|
1) Seed integrations/connections (if available) or create connector definitions.
|
|
71
40
|
2) Configure sync jobs with Jobs module; store payload archives via Files.
|
|
72
41
|
3) Use \`src/run-mcp.ts\` to validate MCP connectivity for provider adapters.
|
|
@@ -79,17 +48,7 @@ var integrationHubDocBlocks = [
|
|
|
79
48
|
## Guardrails
|
|
80
49
|
- Keep mappings declarative; avoid hardcoded transforms.
|
|
81
50
|
- Emit events for sync lifecycle; persist logs for audit.
|
|
82
|
-
- Redact sensitive payload paths in presentations.`
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: "docs.examples.integration-hub.constraints",
|
|
86
|
-
title: "Integration Hub \u2014 Constraints & Safety",
|
|
87
|
-
summary: "Internal guidance for sync lifecycle, mappings, and regeneration safety.",
|
|
88
|
-
kind: "reference",
|
|
89
|
-
visibility: "internal",
|
|
90
|
-
route: "/docs/examples/integration-hub/constraints",
|
|
91
|
-
tags: ["integrations", "constraints", "internal"],
|
|
92
|
-
body: `## Constraints
|
|
51
|
+
- Redact sensitive payload paths in presentations.`},{id:"docs.examples.integration-hub.constraints",title:"Integration Hub \u2014 Constraints & Safety",summary:"Internal guidance for sync lifecycle, mappings, and regeneration safety.",kind:"reference",visibility:"internal",route:"/docs/examples/integration-hub/constraints",tags:["integrations","constraints","internal"],body:`## Constraints
|
|
93
52
|
- Mappings and sync states must remain declarative in spec; no hidden code transforms.
|
|
94
53
|
- Events to emit at minimum: sync.started, sync.completed, sync.failed; connection.connected/disconnected.
|
|
95
54
|
- Regeneration should not alter retry/backoff semantics without explicit spec change.
|
|
@@ -102,7 +61,4 @@ var integrationHubDocBlocks = [
|
|
|
102
61
|
## Verification
|
|
103
62
|
- Include fixtures for mapping changes and sync retries.
|
|
104
63
|
- Validate that scheduled jobs (cron) are spec-driven; Jobs module wiring intact.
|
|
105
|
-
- Ensure Audit/Notifications receive sync lifecycle events.`
|
|
106
|
-
}
|
|
107
|
-
];
|
|
108
|
-
registerDocBlocks(integrationHubDocBlocks);
|
|
64
|
+
- Ensure Audit/Notifications receive sync lifecycle events.`}];f(h);
|
package/dist/events.js
CHANGED
|
@@ -1,212 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
|
-
var IntegrationCreatedPayload = defineSchemaModel({
|
|
6
|
-
name: "IntegrationCreatedPayload",
|
|
7
|
-
description: "Payload when an integration is created",
|
|
8
|
-
fields: {
|
|
9
|
-
integrationId: {
|
|
10
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
11
|
-
isOptional: false
|
|
12
|
-
},
|
|
13
|
-
type: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
14
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
var IntegrationCreatedEvent = defineEvent({
|
|
18
|
-
meta: {
|
|
19
|
-
key: "integration.created",
|
|
20
|
-
version: "1.0.0",
|
|
21
|
-
description: "Fired when a new integration is created",
|
|
22
|
-
stability: "experimental",
|
|
23
|
-
owners: ["@integration-team"],
|
|
24
|
-
tags: ["integration"]
|
|
25
|
-
},
|
|
26
|
-
payload: IntegrationCreatedPayload
|
|
27
|
-
});
|
|
28
|
-
var ConnectionCreatedPayload = defineSchemaModel({
|
|
29
|
-
name: "ConnectionCreatedPayload",
|
|
30
|
-
description: "Payload when a connection is established",
|
|
31
|
-
fields: {
|
|
32
|
-
connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
33
|
-
integrationId: {
|
|
34
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
35
|
-
isOptional: false
|
|
36
|
-
},
|
|
37
|
-
status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
38
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
var ConnectionCreatedEvent = defineEvent({
|
|
42
|
-
meta: {
|
|
43
|
-
key: "integration.connection.created",
|
|
44
|
-
version: "1.0.0",
|
|
45
|
-
description: "Fired when a new connection is established",
|
|
46
|
-
stability: "experimental",
|
|
47
|
-
owners: ["@integration-team"],
|
|
48
|
-
tags: ["integration", "connection"]
|
|
49
|
-
},
|
|
50
|
-
payload: ConnectionCreatedPayload
|
|
51
|
-
});
|
|
52
|
-
var ConnectionStatusChangedPayload = defineSchemaModel({
|
|
53
|
-
name: "ConnectionStatusChangedPayload",
|
|
54
|
-
description: "Payload when a connection status changes",
|
|
55
|
-
fields: {
|
|
56
|
-
connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
57
|
-
previousStatus: {
|
|
58
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
59
|
-
isOptional: false
|
|
60
|
-
},
|
|
61
|
-
newStatus: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
62
|
-
changedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
var ConnectionStatusChangedEvent = defineEvent({
|
|
66
|
-
meta: {
|
|
67
|
-
key: "integration.connection.statusChanged",
|
|
68
|
-
version: "1.0.0",
|
|
69
|
-
description: "Fired when a connection status changes",
|
|
70
|
-
stability: "experimental",
|
|
71
|
-
owners: ["@integration-team"],
|
|
72
|
-
tags: ["integration", "connection"]
|
|
73
|
-
},
|
|
74
|
-
payload: ConnectionStatusChangedPayload
|
|
75
|
-
});
|
|
76
|
-
var SyncConfigCreatedPayload = defineSchemaModel({
|
|
77
|
-
name: "SyncConfigCreatedPayload",
|
|
78
|
-
description: "Payload when a sync configuration is created",
|
|
79
|
-
fields: {
|
|
80
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
81
|
-
connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
82
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
var SyncConfigCreatedEvent = defineEvent({
|
|
86
|
-
meta: {
|
|
87
|
-
key: "integration.syncConfig.created",
|
|
88
|
-
version: "1.0.0",
|
|
89
|
-
description: "Fired when a sync configuration is created",
|
|
90
|
-
stability: "experimental",
|
|
91
|
-
owners: ["@integration-team"],
|
|
92
|
-
tags: ["integration", "sync"]
|
|
93
|
-
},
|
|
94
|
-
payload: SyncConfigCreatedPayload
|
|
95
|
-
});
|
|
96
|
-
var SyncStartedPayload = defineSchemaModel({
|
|
97
|
-
name: "SyncStartedPayload",
|
|
98
|
-
description: "Payload when a sync run starts",
|
|
99
|
-
fields: {
|
|
100
|
-
syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
101
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
102
|
-
startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
var SyncStartedEvent = defineEvent({
|
|
106
|
-
meta: {
|
|
107
|
-
key: "integration.sync.started",
|
|
108
|
-
version: "1.0.0",
|
|
109
|
-
description: "Fired when a sync run starts",
|
|
110
|
-
stability: "experimental",
|
|
111
|
-
owners: ["@integration-team"],
|
|
112
|
-
tags: ["integration", "sync"]
|
|
113
|
-
},
|
|
114
|
-
payload: SyncStartedPayload
|
|
115
|
-
});
|
|
116
|
-
var SyncCompletedPayload = defineSchemaModel({
|
|
117
|
-
name: "SyncCompletedPayload",
|
|
118
|
-
description: "Payload when a sync run completes successfully",
|
|
119
|
-
fields: {
|
|
120
|
-
syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
121
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
122
|
-
recordsProcessed: {
|
|
123
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
124
|
-
isOptional: false
|
|
125
|
-
},
|
|
126
|
-
completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
var SyncCompletedEvent = defineEvent({
|
|
130
|
-
meta: {
|
|
131
|
-
key: "integration.sync.completed",
|
|
132
|
-
version: "1.0.0",
|
|
133
|
-
description: "Fired when a sync run completes successfully",
|
|
134
|
-
stability: "experimental",
|
|
135
|
-
owners: ["@integration-team"],
|
|
136
|
-
tags: ["integration", "sync"]
|
|
137
|
-
},
|
|
138
|
-
payload: SyncCompletedPayload
|
|
139
|
-
});
|
|
140
|
-
var SyncFailedPayload = defineSchemaModel({
|
|
141
|
-
name: "SyncFailedPayload",
|
|
142
|
-
description: "Payload when a sync run fails",
|
|
143
|
-
fields: {
|
|
144
|
-
syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
145
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
146
|
-
error: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
147
|
-
failedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
var SyncFailedEvent = defineEvent({
|
|
151
|
-
meta: {
|
|
152
|
-
key: "integration.sync.failed",
|
|
153
|
-
version: "1.0.0",
|
|
154
|
-
description: "Fired when a sync run fails",
|
|
155
|
-
stability: "experimental",
|
|
156
|
-
owners: ["@integration-team"],
|
|
157
|
-
tags: ["integration", "sync"]
|
|
158
|
-
},
|
|
159
|
-
payload: SyncFailedPayload
|
|
160
|
-
});
|
|
161
|
-
var RecordSyncedPayload = defineSchemaModel({
|
|
162
|
-
name: "RecordSyncedPayload",
|
|
163
|
-
description: "Payload when a single record is synced",
|
|
164
|
-
fields: {
|
|
165
|
-
syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
166
|
-
recordId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
167
|
-
sourceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
168
|
-
targetId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
var RecordSyncedEvent = defineEvent({
|
|
172
|
-
meta: {
|
|
173
|
-
key: "integration.record.synced",
|
|
174
|
-
version: "1.0.0",
|
|
175
|
-
description: "Fired when a single record is synced",
|
|
176
|
-
stability: "experimental",
|
|
177
|
-
owners: ["@integration-team"],
|
|
178
|
-
tags: ["integration", "sync"]
|
|
179
|
-
},
|
|
180
|
-
payload: RecordSyncedPayload
|
|
181
|
-
});
|
|
182
|
-
var FieldMappingAddedPayload = defineSchemaModel({
|
|
183
|
-
name: "FieldMappingAddedPayload",
|
|
184
|
-
description: "Payload when a field mapping is added to a sync config",
|
|
185
|
-
fields: {
|
|
186
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
187
|
-
sourceField: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
188
|
-
targetField: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
var FieldMappingAddedEvent = defineEvent({
|
|
192
|
-
meta: {
|
|
193
|
-
key: "integration.fieldMapping.added",
|
|
194
|
-
version: "1.0.0",
|
|
195
|
-
description: "Fired when a field mapping is added to a sync config",
|
|
196
|
-
stability: "experimental",
|
|
197
|
-
owners: ["@integration-team"],
|
|
198
|
-
tags: ["integration", "sync"]
|
|
199
|
-
},
|
|
200
|
-
payload: FieldMappingAddedPayload
|
|
201
|
-
});
|
|
202
|
-
export {
|
|
203
|
-
SyncStartedEvent,
|
|
204
|
-
SyncFailedEvent,
|
|
205
|
-
SyncConfigCreatedEvent,
|
|
206
|
-
SyncCompletedEvent,
|
|
207
|
-
RecordSyncedEvent,
|
|
208
|
-
IntegrationCreatedEvent,
|
|
209
|
-
FieldMappingAddedEvent,
|
|
210
|
-
ConnectionStatusChangedEvent,
|
|
211
|
-
ConnectionCreatedEvent
|
|
212
|
-
};
|
|
2
|
+
import{defineEvent as k}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as q,ScalarTypeEnum as j}from"@contractspec/lib.schema";var w=q({name:"IntegrationCreatedPayload",description:"Payload when an integration is created",fields:{integrationId:{type:j.String_unsecure(),isOptional:!1},type:{type:j.String_unsecure(),isOptional:!1},createdAt:{type:j.DateTime(),isOptional:!1}}}),O=k({meta:{key:"integration.created",version:"1.0.0",description:"Fired when a new integration is created",stability:"experimental",owners:["@integration-team"],tags:["integration"]},payload:w}),x=q({name:"ConnectionCreatedPayload",description:"Payload when a connection is established",fields:{connectionId:{type:j.String_unsecure(),isOptional:!1},integrationId:{type:j.String_unsecure(),isOptional:!1},status:{type:j.String_unsecure(),isOptional:!1},createdAt:{type:j.DateTime(),isOptional:!1}}}),Q=k({meta:{key:"integration.connection.created",version:"1.0.0",description:"Fired when a new connection is established",stability:"experimental",owners:["@integration-team"],tags:["integration","connection"]},payload:x}),z=q({name:"ConnectionStatusChangedPayload",description:"Payload when a connection status changes",fields:{connectionId:{type:j.String_unsecure(),isOptional:!1},previousStatus:{type:j.String_unsecure(),isOptional:!1},newStatus:{type:j.String_unsecure(),isOptional:!1},changedAt:{type:j.DateTime(),isOptional:!1}}}),U=k({meta:{key:"integration.connection.statusChanged",version:"1.0.0",description:"Fired when a connection status changes",stability:"experimental",owners:["@integration-team"],tags:["integration","connection"]},payload:z}),B=q({name:"SyncConfigCreatedPayload",description:"Payload when a sync configuration is created",fields:{syncConfigId:{type:j.String_unsecure(),isOptional:!1},connectionId:{type:j.String_unsecure(),isOptional:!1},createdAt:{type:j.DateTime(),isOptional:!1}}}),V=k({meta:{key:"integration.syncConfig.created",version:"1.0.0",description:"Fired when a sync configuration is created",stability:"experimental",owners:["@integration-team"],tags:["integration","sync"]},payload:B}),D=q({name:"SyncStartedPayload",description:"Payload when a sync run starts",fields:{syncRunId:{type:j.String_unsecure(),isOptional:!1},syncConfigId:{type:j.String_unsecure(),isOptional:!1},startedAt:{type:j.DateTime(),isOptional:!1}}}),W=k({meta:{key:"integration.sync.started",version:"1.0.0",description:"Fired when a sync run starts",stability:"experimental",owners:["@integration-team"],tags:["integration","sync"]},payload:D}),G=q({name:"SyncCompletedPayload",description:"Payload when a sync run completes successfully",fields:{syncRunId:{type:j.String_unsecure(),isOptional:!1},syncConfigId:{type:j.String_unsecure(),isOptional:!1},recordsProcessed:{type:j.Int_unsecure(),isOptional:!1},completedAt:{type:j.DateTime(),isOptional:!1}}}),X=k({meta:{key:"integration.sync.completed",version:"1.0.0",description:"Fired when a sync run completes successfully",stability:"experimental",owners:["@integration-team"],tags:["integration","sync"]},payload:G}),H=q({name:"SyncFailedPayload",description:"Payload when a sync run fails",fields:{syncRunId:{type:j.String_unsecure(),isOptional:!1},syncConfigId:{type:j.String_unsecure(),isOptional:!1},error:{type:j.String_unsecure(),isOptional:!1},failedAt:{type:j.DateTime(),isOptional:!1}}}),Y=k({meta:{key:"integration.sync.failed",version:"1.0.0",description:"Fired when a sync run fails",stability:"experimental",owners:["@integration-team"],tags:["integration","sync"]},payload:H}),J=q({name:"RecordSyncedPayload",description:"Payload when a single record is synced",fields:{syncRunId:{type:j.String_unsecure(),isOptional:!1},recordId:{type:j.String_unsecure(),isOptional:!1},sourceId:{type:j.String_unsecure(),isOptional:!1},targetId:{type:j.String_unsecure(),isOptional:!1}}}),Z=k({meta:{key:"integration.record.synced",version:"1.0.0",description:"Fired when a single record is synced",stability:"experimental",owners:["@integration-team"],tags:["integration","sync"]},payload:J}),K=q({name:"FieldMappingAddedPayload",description:"Payload when a field mapping is added to a sync config",fields:{syncConfigId:{type:j.String_unsecure(),isOptional:!1},sourceField:{type:j.String_unsecure(),isOptional:!1},targetField:{type:j.String_unsecure(),isOptional:!1}}}),_=k({meta:{key:"integration.fieldMapping.added",version:"1.0.0",description:"Fired when a field mapping is added to a sync config",stability:"experimental",owners:["@integration-team"],tags:["integration","sync"]},payload:K});export{W as SyncStartedEvent,Y as SyncFailedEvent,V as SyncConfigCreatedEvent,X as SyncCompletedEvent,Z as RecordSyncedEvent,O as IntegrationCreatedEvent,_ as FieldMappingAddedEvent,U as ConnectionStatusChangedEvent,Q as ConnectionCreatedEvent};
|
package/dist/example.js
CHANGED
|
@@ -1,43 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineExample } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
var example = defineExample({
|
|
5
|
-
meta: {
|
|
6
|
-
key: "integration-hub",
|
|
7
|
-
version: "1.0.0",
|
|
8
|
-
title: "Integration Hub",
|
|
9
|
-
description: "Provider-agnostic integration center with connectors, connections, field mappings, and sync logs.",
|
|
10
|
-
kind: "template",
|
|
11
|
-
visibility: "public",
|
|
12
|
-
stability: "experimental",
|
|
13
|
-
owners: ["@platform.core"],
|
|
14
|
-
tags: ["integrations", "sync", "etl", "connectors"]
|
|
15
|
-
},
|
|
16
|
-
docs: {
|
|
17
|
-
rootDocId: "docs.examples.integration-hub",
|
|
18
|
-
goalDocId: "docs.examples.integration-hub.goal",
|
|
19
|
-
usageDocId: "docs.examples.integration-hub.usage",
|
|
20
|
-
constraintsDocId: "docs.examples.integration-hub.constraints"
|
|
21
|
-
},
|
|
22
|
-
entrypoints: {
|
|
23
|
-
packageName: "@contractspec/example.integration-hub",
|
|
24
|
-
feature: "./feature",
|
|
25
|
-
contracts: "./contracts",
|
|
26
|
-
presentations: "./presentations",
|
|
27
|
-
handlers: "./handlers",
|
|
28
|
-
docs: "./docs"
|
|
29
|
-
},
|
|
30
|
-
surfaces: {
|
|
31
|
-
templates: true,
|
|
32
|
-
sandbox: {
|
|
33
|
-
enabled: true,
|
|
34
|
-
modes: ["playground", "specs", "builder", "markdown", "evolution"]
|
|
35
|
-
},
|
|
36
|
-
studio: { enabled: true, installable: true },
|
|
37
|
-
mcp: { enabled: true }
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
var example_default = example;
|
|
41
|
-
export {
|
|
42
|
-
example_default as default
|
|
43
|
-
};
|
|
2
|
+
import{defineExample as g}from"@contractspec/lib.contracts-spec";var h=g({meta:{key:"integration-hub",version:"1.0.0",title:"Integration Hub",description:"Provider-agnostic integration center with connectors, connections, field mappings, and sync logs.",kind:"template",visibility:"public",stability:"experimental",owners:["@platform.core"],tags:["integrations","sync","etl","connectors"]},docs:{rootDocId:"docs.examples.integration-hub",goalDocId:"docs.examples.integration-hub.goal",usageDocId:"docs.examples.integration-hub.usage",constraintsDocId:"docs.examples.integration-hub.constraints"},entrypoints:{packageName:"@contractspec/example.integration-hub",feature:"./feature",contracts:"./contracts",presentations:"./presentations",handlers:"./handlers",docs:"./docs"},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs","builder","markdown","evolution"]},studio:{enabled:!0,installable:!0},mcp:{enabled:!0}}}),q=h;export{q as default};
|
package/dist/handlers/index.js
CHANGED
|
@@ -1,293 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
id: row.id,
|
|
8
|
-
projectId: row.projectId,
|
|
9
|
-
organizationId: row.organizationId,
|
|
10
|
-
name: row.name,
|
|
11
|
-
description: row.description ?? undefined,
|
|
12
|
-
type: row.type,
|
|
13
|
-
status: row.status,
|
|
14
|
-
iconUrl: row.iconUrl ?? undefined,
|
|
15
|
-
createdAt: new Date(row.createdAt),
|
|
16
|
-
updatedAt: new Date(row.updatedAt)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function rowToConnection(row) {
|
|
20
|
-
return {
|
|
21
|
-
id: row.id,
|
|
22
|
-
integrationId: row.integrationId,
|
|
23
|
-
name: row.name,
|
|
24
|
-
status: row.status,
|
|
25
|
-
credentials: row.credentials ? JSON.parse(row.credentials) : undefined,
|
|
26
|
-
config: row.config ? JSON.parse(row.config) : undefined,
|
|
27
|
-
lastSyncAt: row.lastSyncAt ? new Date(row.lastSyncAt) : undefined,
|
|
28
|
-
errorMessage: row.errorMessage ?? undefined,
|
|
29
|
-
createdAt: new Date(row.createdAt),
|
|
30
|
-
updatedAt: new Date(row.updatedAt)
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function rowToSyncConfig(row) {
|
|
34
|
-
return {
|
|
35
|
-
id: row.id,
|
|
36
|
-
connectionId: row.connectionId,
|
|
37
|
-
name: row.name,
|
|
38
|
-
sourceEntity: row.sourceEntity,
|
|
39
|
-
targetEntity: row.targetEntity,
|
|
40
|
-
frequency: row.frequency,
|
|
41
|
-
status: row.status,
|
|
42
|
-
lastRunAt: row.lastRunAt ? new Date(row.lastRunAt) : undefined,
|
|
43
|
-
lastRunStatus: row.lastRunStatus ?? undefined,
|
|
44
|
-
recordsSynced: row.recordsSynced,
|
|
45
|
-
createdAt: new Date(row.createdAt),
|
|
46
|
-
updatedAt: new Date(row.updatedAt)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function rowToFieldMapping(row) {
|
|
50
|
-
return {
|
|
51
|
-
id: row.id,
|
|
52
|
-
syncConfigId: row.syncConfigId,
|
|
53
|
-
sourceField: row.sourceField,
|
|
54
|
-
targetField: row.targetField,
|
|
55
|
-
transformType: row.transformType ?? undefined,
|
|
56
|
-
transformConfig: row.transformConfig ? JSON.parse(row.transformConfig) : undefined,
|
|
57
|
-
createdAt: new Date(row.createdAt)
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function createIntegrationHandlers(db) {
|
|
61
|
-
async function listIntegrations(input) {
|
|
62
|
-
const { projectId, type, status, search, limit = 20, offset = 0 } = input;
|
|
63
|
-
let whereClause = "WHERE projectId = ?";
|
|
64
|
-
const params = [projectId];
|
|
65
|
-
if (type && type !== "all") {
|
|
66
|
-
whereClause += " AND type = ?";
|
|
67
|
-
params.push(type);
|
|
68
|
-
}
|
|
69
|
-
if (status && status !== "all") {
|
|
70
|
-
whereClause += " AND status = ?";
|
|
71
|
-
params.push(status);
|
|
72
|
-
}
|
|
73
|
-
if (search) {
|
|
74
|
-
whereClause += " AND name LIKE ?";
|
|
75
|
-
params.push(`%${search}%`);
|
|
76
|
-
}
|
|
77
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration ${whereClause}`, params)).rows;
|
|
78
|
-
const total = countResult[0]?.count ?? 0;
|
|
79
|
-
const rows = (await db.query(`SELECT * FROM integration ${whereClause} ORDER BY name LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
80
|
-
return {
|
|
81
|
-
integrations: rows.map(rowToIntegration),
|
|
82
|
-
total
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
async function createIntegration(input, context) {
|
|
86
|
-
const id = generateId("integ");
|
|
87
|
-
const now = new Date().toISOString();
|
|
88
|
-
await db.execute(`INSERT INTO integration (id, projectId, organizationId, name, description, type, status, iconUrl, createdAt, updatedAt)
|
|
89
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
90
|
-
id,
|
|
91
|
-
context.projectId,
|
|
92
|
-
context.organizationId,
|
|
93
|
-
input.name,
|
|
94
|
-
input.description ?? null,
|
|
95
|
-
input.type,
|
|
96
|
-
"INACTIVE",
|
|
97
|
-
input.iconUrl ?? null,
|
|
98
|
-
now,
|
|
99
|
-
now
|
|
100
|
-
]);
|
|
101
|
-
const rows = (await db.query(`SELECT * FROM integration WHERE id = ?`, [id])).rows;
|
|
102
|
-
return rowToIntegration(rows[0]);
|
|
103
|
-
}
|
|
104
|
-
async function listConnections(input) {
|
|
105
|
-
const { integrationId, status, limit = 20, offset = 0 } = input;
|
|
106
|
-
let whereClause = "WHERE 1=1";
|
|
107
|
-
const params = [];
|
|
108
|
-
if (integrationId) {
|
|
109
|
-
whereClause += " AND integrationId = ?";
|
|
110
|
-
params.push(integrationId);
|
|
111
|
-
}
|
|
112
|
-
if (status && status !== "all") {
|
|
113
|
-
whereClause += " AND status = ?";
|
|
114
|
-
params.push(status);
|
|
115
|
-
}
|
|
116
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration_connection ${whereClause}`, params)).rows;
|
|
117
|
-
const total = countResult[0]?.count ?? 0;
|
|
118
|
-
const rows = (await db.query(`SELECT * FROM integration_connection ${whereClause} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
119
|
-
return {
|
|
120
|
-
connections: rows.map(rowToConnection),
|
|
121
|
-
total
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
async function connectService(input) {
|
|
125
|
-
const id = generateId("conn");
|
|
126
|
-
const now = new Date().toISOString();
|
|
127
|
-
await db.execute(`INSERT INTO integration_connection (id, integrationId, name, status, credentials, config, createdAt, updatedAt)
|
|
128
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
129
|
-
id,
|
|
130
|
-
input.integrationId,
|
|
131
|
-
input.name,
|
|
132
|
-
"PENDING",
|
|
133
|
-
input.credentials ? JSON.stringify(input.credentials) : null,
|
|
134
|
-
input.config ? JSON.stringify(input.config) : null,
|
|
135
|
-
now,
|
|
136
|
-
now
|
|
137
|
-
]);
|
|
138
|
-
await db.execute(`UPDATE integration_connection SET status = 'CONNECTED', updatedAt = ? WHERE id = ?`, [now, id]);
|
|
139
|
-
await db.execute(`UPDATE integration SET status = 'ACTIVE', updatedAt = ? WHERE id = ?`, [now, input.integrationId]);
|
|
140
|
-
const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [id])).rows;
|
|
141
|
-
return rowToConnection(rows[0]);
|
|
142
|
-
}
|
|
143
|
-
async function disconnectService(connectionId) {
|
|
144
|
-
const now = new Date().toISOString();
|
|
145
|
-
await db.execute(`UPDATE integration_connection SET status = 'DISCONNECTED', updatedAt = ? WHERE id = ?`, [now, connectionId]);
|
|
146
|
-
const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [
|
|
147
|
-
connectionId
|
|
148
|
-
])).rows;
|
|
149
|
-
return rowToConnection(rows[0]);
|
|
150
|
-
}
|
|
151
|
-
async function listSyncConfigs(input) {
|
|
152
|
-
const { connectionId, status, limit = 20, offset = 0 } = input;
|
|
153
|
-
let whereClause = "WHERE 1=1";
|
|
154
|
-
const params = [];
|
|
155
|
-
if (connectionId) {
|
|
156
|
-
whereClause += " AND connectionId = ?";
|
|
157
|
-
params.push(connectionId);
|
|
158
|
-
}
|
|
159
|
-
if (status && status !== "all") {
|
|
160
|
-
whereClause += " AND status = ?";
|
|
161
|
-
params.push(status);
|
|
162
|
-
}
|
|
163
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration_sync_config ${whereClause}`, params)).rows;
|
|
164
|
-
const total = countResult[0]?.count ?? 0;
|
|
165
|
-
const rows = (await db.query(`SELECT * FROM integration_sync_config ${whereClause} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
166
|
-
return {
|
|
167
|
-
configs: rows.map(rowToSyncConfig),
|
|
168
|
-
total
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
async function configureSync(input) {
|
|
172
|
-
const id = generateId("sync");
|
|
173
|
-
const now = new Date().toISOString();
|
|
174
|
-
await db.execute(`INSERT INTO integration_sync_config (id, connectionId, name, sourceEntity, targetEntity, frequency, status, recordsSynced, createdAt, updatedAt)
|
|
175
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
176
|
-
id,
|
|
177
|
-
input.connectionId,
|
|
178
|
-
input.name,
|
|
179
|
-
input.sourceEntity,
|
|
180
|
-
input.targetEntity,
|
|
181
|
-
input.frequency ?? "DAILY",
|
|
182
|
-
"ACTIVE",
|
|
183
|
-
0,
|
|
184
|
-
now,
|
|
185
|
-
now
|
|
186
|
-
]);
|
|
187
|
-
const rows = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [id])).rows;
|
|
188
|
-
return rowToSyncConfig(rows[0]);
|
|
189
|
-
}
|
|
190
|
-
async function mapFields(input) {
|
|
191
|
-
const now = new Date().toISOString();
|
|
192
|
-
const mappings = [];
|
|
193
|
-
await db.execute(`DELETE FROM integration_field_mapping WHERE syncConfigId = ?`, [input.syncConfigId]);
|
|
194
|
-
for (const mapping of input.mappings) {
|
|
195
|
-
const id = generateId("fmap");
|
|
196
|
-
await db.execute(`INSERT INTO integration_field_mapping (id, syncConfigId, sourceField, targetField, transformType, transformConfig, createdAt)
|
|
197
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`, [
|
|
198
|
-
id,
|
|
199
|
-
input.syncConfigId,
|
|
200
|
-
mapping.sourceField,
|
|
201
|
-
mapping.targetField,
|
|
202
|
-
mapping.transformType ?? null,
|
|
203
|
-
mapping.transformConfig ? JSON.stringify(mapping.transformConfig) : null,
|
|
204
|
-
now
|
|
205
|
-
]);
|
|
206
|
-
const rows = (await db.query(`SELECT * FROM integration_field_mapping WHERE id = ?`, [
|
|
207
|
-
id
|
|
208
|
-
])).rows;
|
|
209
|
-
mappings.push(rowToFieldMapping(rows[0]));
|
|
210
|
-
}
|
|
211
|
-
return mappings;
|
|
212
|
-
}
|
|
213
|
-
async function getFieldMappings(syncConfigId) {
|
|
214
|
-
const rows = (await db.query(`SELECT * FROM integration_field_mapping WHERE syncConfigId = ?`, [syncConfigId])).rows;
|
|
215
|
-
return rows.map(rowToFieldMapping);
|
|
216
|
-
}
|
|
217
|
-
async function runSync(syncConfigId) {
|
|
218
|
-
const now = new Date().toISOString();
|
|
219
|
-
const recordsSynced = Math.floor(Math.random() * 1000) + 50;
|
|
220
|
-
await db.execute(`UPDATE integration_sync_config SET lastRunAt = ?, lastRunStatus = 'SUCCESS', recordsSynced = recordsSynced + ?, updatedAt = ? WHERE id = ?`, [now, recordsSynced, now, syncConfigId]);
|
|
221
|
-
const config = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [
|
|
222
|
-
syncConfigId
|
|
223
|
-
])).rows;
|
|
224
|
-
if (config[0]) {
|
|
225
|
-
await db.execute(`UPDATE integration_connection SET lastSyncAt = ?, updatedAt = ? WHERE id = ?`, [now, now, config[0].connectionId]);
|
|
226
|
-
}
|
|
227
|
-
const rows = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [
|
|
228
|
-
syncConfigId
|
|
229
|
-
])).rows;
|
|
230
|
-
return rowToSyncConfig(rows[0]);
|
|
231
|
-
}
|
|
232
|
-
async function validateByokKey(input) {
|
|
233
|
-
const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [
|
|
234
|
-
input.connectionId
|
|
235
|
-
])).rows;
|
|
236
|
-
if (!rows[0]) {
|
|
237
|
-
return {
|
|
238
|
-
valid: false,
|
|
239
|
-
provider: "unknown",
|
|
240
|
-
keyPrefix: "",
|
|
241
|
-
error: `Connection ${input.connectionId} not found`
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
const keyPrefix = input.providerKey.slice(0, 8);
|
|
245
|
-
const looksValid = input.providerKey.length >= 16;
|
|
246
|
-
return {
|
|
247
|
-
valid: looksValid,
|
|
248
|
-
provider: rows[0].name,
|
|
249
|
-
keyPrefix: `${keyPrefix}...`,
|
|
250
|
-
expiresAt: looksValid ? new Date(Date.now() + 90 * 24 * 60 * 60 * 1000).toISOString() : undefined,
|
|
251
|
-
error: looksValid ? undefined : "Key must be at least 16 characters"
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async function refreshOAuth2Token(input) {
|
|
255
|
-
const now = new Date().toISOString();
|
|
256
|
-
await db.execute(`UPDATE integration_connection SET updatedAt = ? WHERE id = ?`, [now, input.connectionId]);
|
|
257
|
-
return {
|
|
258
|
-
refreshed: true,
|
|
259
|
-
expiresAt: new Date(Date.now() + 3600 * 1000).toISOString(),
|
|
260
|
-
tokenType: "Bearer",
|
|
261
|
-
scopes: ["read", "write", "sync"]
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
async function getTransportOptions(input) {
|
|
265
|
-
return {
|
|
266
|
-
integrationId: input.integrationId,
|
|
267
|
-
transports: [
|
|
268
|
-
{ transport: "rest", supported: true, defaultVersion: "v2" },
|
|
269
|
-
{ transport: "mcp", supported: true, defaultVersion: "v1" },
|
|
270
|
-
{ transport: "webhook", supported: true },
|
|
271
|
-
{ transport: "sdk", supported: false }
|
|
272
|
-
]
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
listIntegrations,
|
|
277
|
-
createIntegration,
|
|
278
|
-
listConnections,
|
|
279
|
-
connectService,
|
|
280
|
-
disconnectService,
|
|
281
|
-
listSyncConfigs,
|
|
282
|
-
configureSync,
|
|
283
|
-
mapFields,
|
|
284
|
-
getFieldMappings,
|
|
285
|
-
runSync,
|
|
286
|
-
validateByokKey,
|
|
287
|
-
refreshOAuth2Token,
|
|
288
|
-
getTransportOptions
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
export {
|
|
292
|
-
createIntegrationHandlers
|
|
293
|
-
};
|
|
2
|
+
import{web as S}from"@contractspec/lib.runtime-sandbox";var{generateId:R}=S;function Y(q){return{id:q.id,projectId:q.projectId,organizationId:q.organizationId,name:q.name,description:q.description??void 0,type:q.type,status:q.status,iconUrl:q.iconUrl??void 0,createdAt:new Date(q.createdAt),updatedAt:new Date(q.updatedAt)}}function U(q){return{id:q.id,integrationId:q.integrationId,name:q.name,status:q.status,credentials:q.credentials?JSON.parse(q.credentials):void 0,config:q.config?JSON.parse(q.config):void 0,lastSyncAt:q.lastSyncAt?new Date(q.lastSyncAt):void 0,errorMessage:q.errorMessage??void 0,createdAt:new Date(q.createdAt),updatedAt:new Date(q.updatedAt)}}function W(q){return{id:q.id,connectionId:q.connectionId,name:q.name,sourceEntity:q.sourceEntity,targetEntity:q.targetEntity,frequency:q.frequency,status:q.status,lastRunAt:q.lastRunAt?new Date(q.lastRunAt):void 0,lastRunStatus:q.lastRunStatus??void 0,recordsSynced:q.recordsSynced,createdAt:new Date(q.createdAt),updatedAt:new Date(q.updatedAt)}}function Z(q){return{id:q.id,syncConfigId:q.syncConfigId,sourceField:q.sourceField,targetField:q.targetField,transformType:q.transformType??void 0,transformConfig:q.transformConfig?JSON.parse(q.transformConfig):void 0,createdAt:new Date(q.createdAt)}}function y(q){async function _(z){let{projectId:D,type:E,status:G,search:H,limit:J=20,offset:L=0}=z,Q="WHERE projectId = ?",N=[D];if(E&&E!=="all")Q+=" AND type = ?",N.push(E);if(G&&G!=="all")Q+=" AND status = ?",N.push(G);if(H)Q+=" AND name LIKE ?",N.push(`%${H}%`);let k=(await q.query(`SELECT COUNT(*) as count FROM integration ${Q}`,N)).rows[0]?.count??0;return{integrations:(await q.query(`SELECT * FROM integration ${Q} ORDER BY name LIMIT ? OFFSET ?`,[...N,J,L])).rows.map(Y),total:k}}async function $(z,D){let E=R("integ"),G=new Date().toISOString();await q.execute(`INSERT INTO integration (id, projectId, organizationId, name, description, type, status, iconUrl, createdAt, updatedAt)
|
|
3
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[E,D.projectId,D.organizationId,z.name,z.description??null,z.type,"INACTIVE",z.iconUrl??null,G,G]);let H=(await q.query("SELECT * FROM integration WHERE id = ?",[E])).rows;return Y(H[0])}async function j(z){let{integrationId:D,status:E,limit:G=20,offset:H=0}=z,J="WHERE 1=1",L=[];if(D)J+=" AND integrationId = ?",L.push(D);if(E&&E!=="all")J+=" AND status = ?",L.push(E);let N=(await q.query(`SELECT COUNT(*) as count FROM integration_connection ${J}`,L)).rows[0]?.count??0;return{connections:(await q.query(`SELECT * FROM integration_connection ${J} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`,[...L,G,H])).rows.map(U),total:N}}async function A(z){let D=R("conn"),E=new Date().toISOString();await q.execute(`INSERT INTO integration_connection (id, integrationId, name, status, credentials, config, createdAt, updatedAt)
|
|
4
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,[D,z.integrationId,z.name,"PENDING",z.credentials?JSON.stringify(z.credentials):null,z.config?JSON.stringify(z.config):null,E,E]),await q.execute("UPDATE integration_connection SET status = 'CONNECTED', updatedAt = ? WHERE id = ?",[E,D]),await q.execute("UPDATE integration SET status = 'ACTIVE', updatedAt = ? WHERE id = ?",[E,z.integrationId]);let G=(await q.query("SELECT * FROM integration_connection WHERE id = ?",[D])).rows;return U(G[0])}async function B(z){let D=new Date().toISOString();await q.execute("UPDATE integration_connection SET status = 'DISCONNECTED', updatedAt = ? WHERE id = ?",[D,z]);let E=(await q.query("SELECT * FROM integration_connection WHERE id = ?",[z])).rows;return U(E[0])}async function K(z){let{connectionId:D,status:E,limit:G=20,offset:H=0}=z,J="WHERE 1=1",L=[];if(D)J+=" AND connectionId = ?",L.push(D);if(E&&E!=="all")J+=" AND status = ?",L.push(E);let N=(await q.query(`SELECT COUNT(*) as count FROM integration_sync_config ${J}`,L)).rows[0]?.count??0;return{configs:(await q.query(`SELECT * FROM integration_sync_config ${J} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`,[...L,G,H])).rows.map(W),total:N}}async function P(z){let D=R("sync"),E=new Date().toISOString();await q.execute(`INSERT INTO integration_sync_config (id, connectionId, name, sourceEntity, targetEntity, frequency, status, recordsSynced, createdAt, updatedAt)
|
|
5
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[D,z.connectionId,z.name,z.sourceEntity,z.targetEntity,z.frequency??"DAILY","ACTIVE",0,E,E]);let G=(await q.query("SELECT * FROM integration_sync_config WHERE id = ?",[D])).rows;return W(G[0])}async function O(z){let D=new Date().toISOString(),E=[];await q.execute("DELETE FROM integration_field_mapping WHERE syncConfigId = ?",[z.syncConfigId]);for(let G of z.mappings){let H=R("fmap");await q.execute(`INSERT INTO integration_field_mapping (id, syncConfigId, sourceField, targetField, transformType, transformConfig, createdAt)
|
|
6
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,[H,z.syncConfigId,G.sourceField,G.targetField,G.transformType??null,G.transformConfig?JSON.stringify(G.transformConfig):null,D]);let J=(await q.query("SELECT * FROM integration_field_mapping WHERE id = ?",[H])).rows;E.push(Z(J[0]))}return E}async function v(z){return(await q.query("SELECT * FROM integration_field_mapping WHERE syncConfigId = ?",[z])).rows.map(Z)}async function M(z){let D=new Date().toISOString(),E=Math.floor(Math.random()*1000)+50;await q.execute("UPDATE integration_sync_config SET lastRunAt = ?, lastRunStatus = 'SUCCESS', recordsSynced = recordsSynced + ?, updatedAt = ? WHERE id = ?",[D,E,D,z]);let G=(await q.query("SELECT * FROM integration_sync_config WHERE id = ?",[z])).rows;if(G[0])await q.execute("UPDATE integration_connection SET lastSyncAt = ?, updatedAt = ? WHERE id = ?",[D,D,G[0].connectionId]);let H=(await q.query("SELECT * FROM integration_sync_config WHERE id = ?",[z])).rows;return W(H[0])}async function V(z){let D=(await q.query("SELECT * FROM integration_connection WHERE id = ?",[z.connectionId])).rows;if(!D[0])return{valid:!1,provider:"unknown",keyPrefix:"",error:`Connection ${z.connectionId} not found`};let E=z.providerKey.slice(0,8),G=z.providerKey.length>=16;return{valid:G,provider:D[0].name,keyPrefix:`${E}...`,expiresAt:G?new Date(Date.now()+7776000000).toISOString():void 0,error:G?void 0:"Key must be at least 16 characters"}}async function F(z){let D=new Date().toISOString();return await q.execute("UPDATE integration_connection SET updatedAt = ? WHERE id = ?",[D,z.connectionId]),{refreshed:!0,expiresAt:new Date(Date.now()+3600000).toISOString(),tokenType:"Bearer",scopes:["read","write","sync"]}}async function x(z){return{integrationId:z.integrationId,transports:[{transport:"rest",supported:!0,defaultVersion:"v2"},{transport:"mcp",supported:!0,defaultVersion:"v1"},{transport:"webhook",supported:!0},{transport:"sdk",supported:!1}]}}return{listIntegrations:_,createIntegration:$,listConnections:j,connectService:A,disconnectService:B,listSyncConfigs:K,configureSync:P,mapFields:O,getFieldMappings:v,runSync:M,validateByokKey:V,refreshOAuth2Token:F,getTransportOptions:x}}export{y as createIntegrationHandlers};
|