@contractspec/example.integration-hub 2.5.0 → 2.6.1
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 +40 -0
- package/dist/docs/index.js +2 -0
- package/dist/docs/integration-hub.docblock.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +149 -0
- package/dist/mcp-example.d.ts +16 -0
- package/dist/mcp-example.js +151 -0
- package/dist/node/docs/index.js +2 -0
- package/dist/node/docs/integration-hub.docblock.js +2 -0
- package/dist/node/index.js +149 -0
- package/dist/node/mcp-example.js +150 -0
- package/dist/node/run-mcp.js +155 -0
- package/dist/run-mcp.d.ts +1 -0
- package/dist/run-mcp.js +156 -0
- package/package.json +34 -94
- package/dist/browser/connection/connection.enum.js +0 -12
- package/dist/browser/connection/connection.operation.js +0 -101
- package/dist/browser/connection/connection.presentation.js +0 -102
- package/dist/browser/connection/connection.schema.js +0 -48
- package/dist/browser/connection/index.js +0 -104
- package/dist/browser/docs/index.js +0 -104
- package/dist/browser/docs/integration-hub.docblock.js +0 -104
- package/dist/browser/events.js +0 -211
- package/dist/browser/example.js +0 -42
- package/dist/browser/handlers/index.js +0 -246
- package/dist/browser/handlers/integration.handlers.js +0 -246
- package/dist/browser/index.js +0 -1595
- package/dist/browser/integration/index.js +0 -92
- package/dist/browser/integration/integration.enum.js +0 -12
- package/dist/browser/integration/integration.operations.js +0 -89
- package/dist/browser/integration/integration.presentation.js +0 -120
- package/dist/browser/integration/integration.schema.js +0 -42
- package/dist/browser/integration-hub.capability.js +0 -43
- package/dist/browser/integration-hub.feature.js +0 -114
- package/dist/browser/seeders/index.js +0 -60
- package/dist/browser/sync/index.js +0 -332
- package/dist/browser/sync/sync.enum.js +0 -26
- package/dist/browser/sync/sync.operations.js +0 -321
- package/dist/browser/sync/sync.presentation.js +0 -301
- package/dist/browser/sync/sync.schema.js +0 -154
- package/dist/browser/sync-engine/index.js +0 -186
- package/dist/browser/tests/operations.test-spec.js +0 -85
- package/dist/browser/ui/IntegrationDashboard.js +0 -369
- package/dist/browser/ui/hooks/index.js +0 -57
- package/dist/browser/ui/hooks/useIntegrationData.js +0 -54
- package/dist/browser/ui/index.js +0 -644
- package/dist/browser/ui/renderers/index.js +0 -273
- package/dist/browser/ui/renderers/integration.markdown.js +0 -273
package/dist/browser/index.js
DELETED
|
@@ -1,1595 +0,0 @@
|
|
|
1
|
-
// src/connection/connection.enum.ts
|
|
2
|
-
import { defineEnum } from "@contractspec/lib.schema";
|
|
3
|
-
var ConnectionStatusEnum = defineEnum("ConnectionStatus", [
|
|
4
|
-
"PENDING",
|
|
5
|
-
"CONNECTED",
|
|
6
|
-
"DISCONNECTED",
|
|
7
|
-
"ERROR",
|
|
8
|
-
"EXPIRED"
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
// src/connection/connection.schema.ts
|
|
12
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
13
|
-
var ConnectionModel = defineSchemaModel({
|
|
14
|
-
name: "ConnectionModel",
|
|
15
|
-
fields: {
|
|
16
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
17
|
-
integrationId: {
|
|
18
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
19
|
-
isOptional: false
|
|
20
|
-
},
|
|
21
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
22
|
-
status: { type: ConnectionStatusEnum, isOptional: false },
|
|
23
|
-
authType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
24
|
-
externalAccountName: {
|
|
25
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
26
|
-
isOptional: true
|
|
27
|
-
},
|
|
28
|
-
connectedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
29
|
-
lastHealthCheck: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
30
|
-
healthStatus: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
var CreateConnectionInputModel = defineSchemaModel({
|
|
34
|
-
name: "CreateConnectionInput",
|
|
35
|
-
fields: {
|
|
36
|
-
integrationId: {
|
|
37
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
38
|
-
isOptional: false
|
|
39
|
-
},
|
|
40
|
-
name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
41
|
-
authType: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
42
|
-
credentials: { type: ScalarTypeEnum.JSON(), isOptional: true }
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// src/connection/connection.operation.ts
|
|
47
|
-
import { defineCommand } from "@contractspec/lib.contracts-spec/operations";
|
|
48
|
-
var OWNERS = ["@example.integration-hub"];
|
|
49
|
-
var CreateConnectionContract = defineCommand({
|
|
50
|
-
meta: {
|
|
51
|
-
key: "integration.connection.create",
|
|
52
|
-
version: "1.0.0",
|
|
53
|
-
stability: "stable",
|
|
54
|
-
owners: [...OWNERS],
|
|
55
|
-
tags: ["integration", "connection", "create"],
|
|
56
|
-
description: "Create a connection to an external system.",
|
|
57
|
-
goal: "Authenticate with external systems.",
|
|
58
|
-
context: "Connection setup."
|
|
59
|
-
},
|
|
60
|
-
io: { input: CreateConnectionInputModel, output: ConnectionModel },
|
|
61
|
-
policy: { auth: "user" },
|
|
62
|
-
sideEffects: {
|
|
63
|
-
emits: [
|
|
64
|
-
{
|
|
65
|
-
key: "integration.connection.created",
|
|
66
|
-
version: "1.0.0",
|
|
67
|
-
when: "Connection created",
|
|
68
|
-
payload: ConnectionModel
|
|
69
|
-
}
|
|
70
|
-
],
|
|
71
|
-
audit: ["integration.connection.created"]
|
|
72
|
-
},
|
|
73
|
-
acceptance: {
|
|
74
|
-
scenarios: [
|
|
75
|
-
{
|
|
76
|
-
key: "create-connection-happy-path",
|
|
77
|
-
given: ["User is authenticated"],
|
|
78
|
-
when: ["User creates connection with valid credentials"],
|
|
79
|
-
then: ["Connection is created", "ConnectionCreated event is emitted"]
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
examples: [
|
|
83
|
-
{
|
|
84
|
-
key: "connect-crm",
|
|
85
|
-
input: {
|
|
86
|
-
name: "Salesforce Prod",
|
|
87
|
-
integrationId: "salesforce",
|
|
88
|
-
credentials: { clientId: "xxx" }
|
|
89
|
-
},
|
|
90
|
-
output: {
|
|
91
|
-
id: "conn-123",
|
|
92
|
-
status: "connected",
|
|
93
|
-
connectedAt: "2025-01-01T12:00:00Z"
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
// src/handlers/integration.handlers.ts
|
|
100
|
-
import { web } from "@contractspec/lib.runtime-sandbox";
|
|
101
|
-
var { generateId } = web;
|
|
102
|
-
function rowToIntegration(row) {
|
|
103
|
-
return {
|
|
104
|
-
id: row.id,
|
|
105
|
-
projectId: row.projectId,
|
|
106
|
-
organizationId: row.organizationId,
|
|
107
|
-
name: row.name,
|
|
108
|
-
description: row.description ?? undefined,
|
|
109
|
-
type: row.type,
|
|
110
|
-
status: row.status,
|
|
111
|
-
iconUrl: row.iconUrl ?? undefined,
|
|
112
|
-
createdAt: new Date(row.createdAt),
|
|
113
|
-
updatedAt: new Date(row.updatedAt)
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function rowToConnection(row) {
|
|
117
|
-
return {
|
|
118
|
-
id: row.id,
|
|
119
|
-
integrationId: row.integrationId,
|
|
120
|
-
name: row.name,
|
|
121
|
-
status: row.status,
|
|
122
|
-
credentials: row.credentials ? JSON.parse(row.credentials) : undefined,
|
|
123
|
-
config: row.config ? JSON.parse(row.config) : undefined,
|
|
124
|
-
lastSyncAt: row.lastSyncAt ? new Date(row.lastSyncAt) : undefined,
|
|
125
|
-
errorMessage: row.errorMessage ?? undefined,
|
|
126
|
-
createdAt: new Date(row.createdAt),
|
|
127
|
-
updatedAt: new Date(row.updatedAt)
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function rowToSyncConfig(row) {
|
|
131
|
-
return {
|
|
132
|
-
id: row.id,
|
|
133
|
-
connectionId: row.connectionId,
|
|
134
|
-
name: row.name,
|
|
135
|
-
sourceEntity: row.sourceEntity,
|
|
136
|
-
targetEntity: row.targetEntity,
|
|
137
|
-
frequency: row.frequency,
|
|
138
|
-
status: row.status,
|
|
139
|
-
lastRunAt: row.lastRunAt ? new Date(row.lastRunAt) : undefined,
|
|
140
|
-
lastRunStatus: row.lastRunStatus ?? undefined,
|
|
141
|
-
recordsSynced: row.recordsSynced,
|
|
142
|
-
createdAt: new Date(row.createdAt),
|
|
143
|
-
updatedAt: new Date(row.updatedAt)
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function rowToFieldMapping(row) {
|
|
147
|
-
return {
|
|
148
|
-
id: row.id,
|
|
149
|
-
syncConfigId: row.syncConfigId,
|
|
150
|
-
sourceField: row.sourceField,
|
|
151
|
-
targetField: row.targetField,
|
|
152
|
-
transformType: row.transformType ?? undefined,
|
|
153
|
-
transformConfig: row.transformConfig ? JSON.parse(row.transformConfig) : undefined,
|
|
154
|
-
createdAt: new Date(row.createdAt)
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function createIntegrationHandlers(db) {
|
|
158
|
-
async function listIntegrations(input) {
|
|
159
|
-
const { projectId, type, status, search, limit = 20, offset = 0 } = input;
|
|
160
|
-
let whereClause = "WHERE projectId = ?";
|
|
161
|
-
const params = [projectId];
|
|
162
|
-
if (type && type !== "all") {
|
|
163
|
-
whereClause += " AND type = ?";
|
|
164
|
-
params.push(type);
|
|
165
|
-
}
|
|
166
|
-
if (status && status !== "all") {
|
|
167
|
-
whereClause += " AND status = ?";
|
|
168
|
-
params.push(status);
|
|
169
|
-
}
|
|
170
|
-
if (search) {
|
|
171
|
-
whereClause += " AND name LIKE ?";
|
|
172
|
-
params.push(`%${search}%`);
|
|
173
|
-
}
|
|
174
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration ${whereClause}`, params)).rows;
|
|
175
|
-
const total = countResult[0]?.count ?? 0;
|
|
176
|
-
const rows = (await db.query(`SELECT * FROM integration ${whereClause} ORDER BY name LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
177
|
-
return {
|
|
178
|
-
integrations: rows.map(rowToIntegration),
|
|
179
|
-
total
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
async function createIntegration(input, context) {
|
|
183
|
-
const id = generateId("integ");
|
|
184
|
-
const now = new Date().toISOString();
|
|
185
|
-
await db.execute(`INSERT INTO integration (id, projectId, organizationId, name, description, type, status, iconUrl, createdAt, updatedAt)
|
|
186
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
187
|
-
id,
|
|
188
|
-
context.projectId,
|
|
189
|
-
context.organizationId,
|
|
190
|
-
input.name,
|
|
191
|
-
input.description ?? null,
|
|
192
|
-
input.type,
|
|
193
|
-
"INACTIVE",
|
|
194
|
-
input.iconUrl ?? null,
|
|
195
|
-
now,
|
|
196
|
-
now
|
|
197
|
-
]);
|
|
198
|
-
const rows = (await db.query(`SELECT * FROM integration WHERE id = ?`, [id])).rows;
|
|
199
|
-
return rowToIntegration(rows[0]);
|
|
200
|
-
}
|
|
201
|
-
async function listConnections(input) {
|
|
202
|
-
const { integrationId, status, limit = 20, offset = 0 } = input;
|
|
203
|
-
let whereClause = "WHERE 1=1";
|
|
204
|
-
const params = [];
|
|
205
|
-
if (integrationId) {
|
|
206
|
-
whereClause += " AND integrationId = ?";
|
|
207
|
-
params.push(integrationId);
|
|
208
|
-
}
|
|
209
|
-
if (status && status !== "all") {
|
|
210
|
-
whereClause += " AND status = ?";
|
|
211
|
-
params.push(status);
|
|
212
|
-
}
|
|
213
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration_connection ${whereClause}`, params)).rows;
|
|
214
|
-
const total = countResult[0]?.count ?? 0;
|
|
215
|
-
const rows = (await db.query(`SELECT * FROM integration_connection ${whereClause} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
216
|
-
return {
|
|
217
|
-
connections: rows.map(rowToConnection),
|
|
218
|
-
total
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
async function connectService(input) {
|
|
222
|
-
const id = generateId("conn");
|
|
223
|
-
const now = new Date().toISOString();
|
|
224
|
-
await db.execute(`INSERT INTO integration_connection (id, integrationId, name, status, credentials, config, createdAt, updatedAt)
|
|
225
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
226
|
-
id,
|
|
227
|
-
input.integrationId,
|
|
228
|
-
input.name,
|
|
229
|
-
"PENDING",
|
|
230
|
-
input.credentials ? JSON.stringify(input.credentials) : null,
|
|
231
|
-
input.config ? JSON.stringify(input.config) : null,
|
|
232
|
-
now,
|
|
233
|
-
now
|
|
234
|
-
]);
|
|
235
|
-
await db.execute(`UPDATE integration_connection SET status = 'CONNECTED', updatedAt = ? WHERE id = ?`, [now, id]);
|
|
236
|
-
await db.execute(`UPDATE integration SET status = 'ACTIVE', updatedAt = ? WHERE id = ?`, [now, input.integrationId]);
|
|
237
|
-
const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [id])).rows;
|
|
238
|
-
return rowToConnection(rows[0]);
|
|
239
|
-
}
|
|
240
|
-
async function disconnectService(connectionId) {
|
|
241
|
-
const now = new Date().toISOString();
|
|
242
|
-
await db.execute(`UPDATE integration_connection SET status = 'DISCONNECTED', updatedAt = ? WHERE id = ?`, [now, connectionId]);
|
|
243
|
-
const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [
|
|
244
|
-
connectionId
|
|
245
|
-
])).rows;
|
|
246
|
-
return rowToConnection(rows[0]);
|
|
247
|
-
}
|
|
248
|
-
async function listSyncConfigs(input) {
|
|
249
|
-
const { connectionId, status, limit = 20, offset = 0 } = input;
|
|
250
|
-
let whereClause = "WHERE 1=1";
|
|
251
|
-
const params = [];
|
|
252
|
-
if (connectionId) {
|
|
253
|
-
whereClause += " AND connectionId = ?";
|
|
254
|
-
params.push(connectionId);
|
|
255
|
-
}
|
|
256
|
-
if (status && status !== "all") {
|
|
257
|
-
whereClause += " AND status = ?";
|
|
258
|
-
params.push(status);
|
|
259
|
-
}
|
|
260
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration_sync_config ${whereClause}`, params)).rows;
|
|
261
|
-
const total = countResult[0]?.count ?? 0;
|
|
262
|
-
const rows = (await db.query(`SELECT * FROM integration_sync_config ${whereClause} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
263
|
-
return {
|
|
264
|
-
configs: rows.map(rowToSyncConfig),
|
|
265
|
-
total
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
async function configureSync(input) {
|
|
269
|
-
const id = generateId("sync");
|
|
270
|
-
const now = new Date().toISOString();
|
|
271
|
-
await db.execute(`INSERT INTO integration_sync_config (id, connectionId, name, sourceEntity, targetEntity, frequency, status, recordsSynced, createdAt, updatedAt)
|
|
272
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
273
|
-
id,
|
|
274
|
-
input.connectionId,
|
|
275
|
-
input.name,
|
|
276
|
-
input.sourceEntity,
|
|
277
|
-
input.targetEntity,
|
|
278
|
-
input.frequency ?? "DAILY",
|
|
279
|
-
"ACTIVE",
|
|
280
|
-
0,
|
|
281
|
-
now,
|
|
282
|
-
now
|
|
283
|
-
]);
|
|
284
|
-
const rows = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [id])).rows;
|
|
285
|
-
return rowToSyncConfig(rows[0]);
|
|
286
|
-
}
|
|
287
|
-
async function mapFields(input) {
|
|
288
|
-
const now = new Date().toISOString();
|
|
289
|
-
const mappings = [];
|
|
290
|
-
await db.execute(`DELETE FROM integration_field_mapping WHERE syncConfigId = ?`, [input.syncConfigId]);
|
|
291
|
-
for (const mapping of input.mappings) {
|
|
292
|
-
const id = generateId("fmap");
|
|
293
|
-
await db.execute(`INSERT INTO integration_field_mapping (id, syncConfigId, sourceField, targetField, transformType, transformConfig, createdAt)
|
|
294
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`, [
|
|
295
|
-
id,
|
|
296
|
-
input.syncConfigId,
|
|
297
|
-
mapping.sourceField,
|
|
298
|
-
mapping.targetField,
|
|
299
|
-
mapping.transformType ?? null,
|
|
300
|
-
mapping.transformConfig ? JSON.stringify(mapping.transformConfig) : null,
|
|
301
|
-
now
|
|
302
|
-
]);
|
|
303
|
-
const rows = (await db.query(`SELECT * FROM integration_field_mapping WHERE id = ?`, [
|
|
304
|
-
id
|
|
305
|
-
])).rows;
|
|
306
|
-
mappings.push(rowToFieldMapping(rows[0]));
|
|
307
|
-
}
|
|
308
|
-
return mappings;
|
|
309
|
-
}
|
|
310
|
-
async function getFieldMappings(syncConfigId) {
|
|
311
|
-
const rows = (await db.query(`SELECT * FROM integration_field_mapping WHERE syncConfigId = ?`, [syncConfigId])).rows;
|
|
312
|
-
return rows.map(rowToFieldMapping);
|
|
313
|
-
}
|
|
314
|
-
async function runSync(syncConfigId) {
|
|
315
|
-
const now = new Date().toISOString();
|
|
316
|
-
const recordsSynced = Math.floor(Math.random() * 1000) + 50;
|
|
317
|
-
await db.execute(`UPDATE integration_sync_config SET lastRunAt = ?, lastRunStatus = 'SUCCESS', recordsSynced = recordsSynced + ?, updatedAt = ? WHERE id = ?`, [now, recordsSynced, now, syncConfigId]);
|
|
318
|
-
const config = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [
|
|
319
|
-
syncConfigId
|
|
320
|
-
])).rows;
|
|
321
|
-
if (config[0]) {
|
|
322
|
-
await db.execute(`UPDATE integration_connection SET lastSyncAt = ?, updatedAt = ? WHERE id = ?`, [now, now, config[0].connectionId]);
|
|
323
|
-
}
|
|
324
|
-
const rows = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [
|
|
325
|
-
syncConfigId
|
|
326
|
-
])).rows;
|
|
327
|
-
return rowToSyncConfig(rows[0]);
|
|
328
|
-
}
|
|
329
|
-
return {
|
|
330
|
-
listIntegrations,
|
|
331
|
-
createIntegration,
|
|
332
|
-
listConnections,
|
|
333
|
-
connectService,
|
|
334
|
-
disconnectService,
|
|
335
|
-
listSyncConfigs,
|
|
336
|
-
configureSync,
|
|
337
|
-
mapFields,
|
|
338
|
-
getFieldMappings,
|
|
339
|
-
runSync
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// src/integration/integration.enum.ts
|
|
344
|
-
import { defineEnum as defineEnum2 } from "@contractspec/lib.schema";
|
|
345
|
-
var IntegrationStatusEnum = defineEnum2("IntegrationStatus", [
|
|
346
|
-
"DRAFT",
|
|
347
|
-
"ACTIVE",
|
|
348
|
-
"PAUSED",
|
|
349
|
-
"ERROR",
|
|
350
|
-
"ARCHIVED"
|
|
351
|
-
]);
|
|
352
|
-
|
|
353
|
-
// src/integration/integration.schema.ts
|
|
354
|
-
import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
|
|
355
|
-
var IntegrationModel = defineSchemaModel2({
|
|
356
|
-
name: "IntegrationModel",
|
|
357
|
-
fields: {
|
|
358
|
-
id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
359
|
-
name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
360
|
-
slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
361
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
362
|
-
provider: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
363
|
-
status: { type: IntegrationStatusEnum, isOptional: false },
|
|
364
|
-
createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
var CreateIntegrationInputModel = defineSchemaModel2({
|
|
368
|
-
name: "CreateIntegrationInput",
|
|
369
|
-
fields: {
|
|
370
|
-
name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
371
|
-
slug: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
372
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
373
|
-
provider: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
374
|
-
config: { type: ScalarTypeEnum2.JSON(), isOptional: true },
|
|
375
|
-
featureFlagKey: {
|
|
376
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
377
|
-
isOptional: true
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// src/integration/integration.operations.ts
|
|
383
|
-
import { defineCommand as defineCommand2 } from "@contractspec/lib.contracts-spec/operations";
|
|
384
|
-
var CreateIntegrationContract = defineCommand2({
|
|
385
|
-
meta: {
|
|
386
|
-
key: "integration.create",
|
|
387
|
-
version: "1.0.0",
|
|
388
|
-
stability: "stable",
|
|
389
|
-
owners: ["@example.integration-hub"],
|
|
390
|
-
tags: ["integration", "create"],
|
|
391
|
-
description: "Create a new integration.",
|
|
392
|
-
goal: "Allow users to set up integrations with external systems.",
|
|
393
|
-
context: "Integration setup."
|
|
394
|
-
},
|
|
395
|
-
io: { input: CreateIntegrationInputModel, output: IntegrationModel },
|
|
396
|
-
policy: { auth: "user" },
|
|
397
|
-
sideEffects: {
|
|
398
|
-
emits: [
|
|
399
|
-
{
|
|
400
|
-
key: "integration.created",
|
|
401
|
-
version: "1.0.0",
|
|
402
|
-
when: "Integration created",
|
|
403
|
-
payload: IntegrationModel
|
|
404
|
-
}
|
|
405
|
-
],
|
|
406
|
-
audit: ["integration.created"]
|
|
407
|
-
},
|
|
408
|
-
acceptance: {
|
|
409
|
-
scenarios: [
|
|
410
|
-
{
|
|
411
|
-
key: "create-integration-happy-path",
|
|
412
|
-
given: ["User is admin"],
|
|
413
|
-
when: ["User defines new integration type"],
|
|
414
|
-
then: [
|
|
415
|
-
"Integration definition is created",
|
|
416
|
-
"IntegrationCreated event is emitted"
|
|
417
|
-
]
|
|
418
|
-
}
|
|
419
|
-
],
|
|
420
|
-
examples: [
|
|
421
|
-
{
|
|
422
|
-
key: "create-slack",
|
|
423
|
-
input: { name: "Slack", category: "communication", authType: "oauth2" },
|
|
424
|
-
output: { id: "slack", status: "active" }
|
|
425
|
-
}
|
|
426
|
-
]
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
// src/sync/sync.enum.ts
|
|
430
|
-
import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
|
|
431
|
-
var SyncDirectionEnum = defineEnum3("SyncDirection", [
|
|
432
|
-
"INBOUND",
|
|
433
|
-
"OUTBOUND",
|
|
434
|
-
"BIDIRECTIONAL"
|
|
435
|
-
]);
|
|
436
|
-
var SyncStatusEnum = defineEnum3("SyncStatus", [
|
|
437
|
-
"PENDING",
|
|
438
|
-
"RUNNING",
|
|
439
|
-
"COMPLETED",
|
|
440
|
-
"FAILED",
|
|
441
|
-
"CANCELLED"
|
|
442
|
-
]);
|
|
443
|
-
var MappingTypeEnum = defineEnum3("MappingType", [
|
|
444
|
-
"DIRECT",
|
|
445
|
-
"TRANSFORM",
|
|
446
|
-
"LOOKUP",
|
|
447
|
-
"CONSTANT",
|
|
448
|
-
"COMPUTED"
|
|
449
|
-
]);
|
|
450
|
-
|
|
451
|
-
// src/sync/sync.schema.ts
|
|
452
|
-
import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
|
|
453
|
-
var FieldMappingModel = defineSchemaModel3({
|
|
454
|
-
name: "FieldMappingModel",
|
|
455
|
-
fields: {
|
|
456
|
-
id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
457
|
-
sourceField: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
458
|
-
targetField: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
459
|
-
mappingType: { type: MappingTypeEnum, isOptional: false },
|
|
460
|
-
transformExpression: {
|
|
461
|
-
type: ScalarTypeEnum3.String_unsecure(),
|
|
462
|
-
isOptional: true
|
|
463
|
-
},
|
|
464
|
-
isRequired: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
var SyncConfigModel = defineSchemaModel3({
|
|
468
|
-
name: "SyncConfigModel",
|
|
469
|
-
fields: {
|
|
470
|
-
id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
471
|
-
integrationId: {
|
|
472
|
-
type: ScalarTypeEnum3.String_unsecure(),
|
|
473
|
-
isOptional: false
|
|
474
|
-
},
|
|
475
|
-
connectionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
476
|
-
name: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
477
|
-
direction: { type: SyncDirectionEnum, isOptional: false },
|
|
478
|
-
sourceObject: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
479
|
-
targetObject: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
480
|
-
scheduleEnabled: { type: ScalarTypeEnum3.Boolean(), isOptional: false },
|
|
481
|
-
scheduleCron: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
|
|
482
|
-
isActive: { type: ScalarTypeEnum3.Boolean(), isOptional: false },
|
|
483
|
-
lastSyncAt: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
|
|
484
|
-
fieldMappings: { type: FieldMappingModel, isArray: true, isOptional: true }
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
var SyncRunModel = defineSchemaModel3({
|
|
488
|
-
name: "SyncRunModel",
|
|
489
|
-
fields: {
|
|
490
|
-
id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
491
|
-
syncConfigId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
492
|
-
status: { type: SyncStatusEnum, isOptional: false },
|
|
493
|
-
direction: { type: SyncDirectionEnum, isOptional: false },
|
|
494
|
-
trigger: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
495
|
-
recordsProcessed: {
|
|
496
|
-
type: ScalarTypeEnum3.Int_unsecure(),
|
|
497
|
-
isOptional: false
|
|
498
|
-
},
|
|
499
|
-
recordsCreated: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
|
|
500
|
-
recordsUpdated: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
|
|
501
|
-
recordsFailed: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
|
|
502
|
-
errorMessage: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
|
|
503
|
-
startedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
|
|
504
|
-
completedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
|
|
505
|
-
createdAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
var CreateSyncConfigInputModel = defineSchemaModel3({
|
|
509
|
-
name: "CreateSyncConfigInput",
|
|
510
|
-
fields: {
|
|
511
|
-
integrationId: {
|
|
512
|
-
type: ScalarTypeEnum3.String_unsecure(),
|
|
513
|
-
isOptional: false
|
|
514
|
-
},
|
|
515
|
-
connectionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
516
|
-
name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
|
|
517
|
-
direction: { type: SyncDirectionEnum, isOptional: false },
|
|
518
|
-
sourceObject: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
|
|
519
|
-
targetObject: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
|
|
520
|
-
scheduleEnabled: { type: ScalarTypeEnum3.Boolean(), isOptional: true },
|
|
521
|
-
scheduleCron: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
var AddFieldMappingInputModel = defineSchemaModel3({
|
|
525
|
-
name: "AddFieldMappingInput",
|
|
526
|
-
fields: {
|
|
527
|
-
syncConfigId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
528
|
-
sourceField: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
|
|
529
|
-
targetField: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
|
|
530
|
-
mappingType: { type: MappingTypeEnum, isOptional: false },
|
|
531
|
-
transformExpression: {
|
|
532
|
-
type: ScalarTypeEnum3.String_unsecure(),
|
|
533
|
-
isOptional: true
|
|
534
|
-
},
|
|
535
|
-
lookupConfig: { type: ScalarTypeEnum3.JSON(), isOptional: true },
|
|
536
|
-
constantValue: { type: ScalarTypeEnum3.JSON(), isOptional: true },
|
|
537
|
-
isRequired: { type: ScalarTypeEnum3.Boolean(), isOptional: true },
|
|
538
|
-
defaultValue: { type: ScalarTypeEnum3.JSON(), isOptional: true }
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
var TriggerSyncInputModel = defineSchemaModel3({
|
|
542
|
-
name: "TriggerSyncInput",
|
|
543
|
-
fields: {
|
|
544
|
-
syncConfigId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
545
|
-
direction: { type: SyncDirectionEnum, isOptional: true },
|
|
546
|
-
fullSync: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
var ListSyncRunsInputModel = defineSchemaModel3({
|
|
550
|
-
name: "ListSyncRunsInput",
|
|
551
|
-
fields: {
|
|
552
|
-
syncConfigId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
553
|
-
status: { type: SyncStatusEnum, isOptional: true },
|
|
554
|
-
limit: {
|
|
555
|
-
type: ScalarTypeEnum3.Int_unsecure(),
|
|
556
|
-
isOptional: true,
|
|
557
|
-
defaultValue: 20
|
|
558
|
-
},
|
|
559
|
-
offset: {
|
|
560
|
-
type: ScalarTypeEnum3.Int_unsecure(),
|
|
561
|
-
isOptional: true,
|
|
562
|
-
defaultValue: 0
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
var ListSyncRunsOutputModel = defineSchemaModel3({
|
|
567
|
-
name: "ListSyncRunsOutput",
|
|
568
|
-
fields: {
|
|
569
|
-
runs: { type: SyncRunModel, isArray: true, isOptional: false },
|
|
570
|
-
total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false }
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
// src/sync/sync.operations.ts
|
|
575
|
-
import {
|
|
576
|
-
defineCommand as defineCommand3,
|
|
577
|
-
defineQuery
|
|
578
|
-
} from "@contractspec/lib.contracts-spec/operations";
|
|
579
|
-
var OWNERS2 = ["@example.integration-hub"];
|
|
580
|
-
var CreateSyncConfigContract = defineCommand3({
|
|
581
|
-
meta: {
|
|
582
|
-
key: "integration.syncConfig.create",
|
|
583
|
-
version: "1.0.0",
|
|
584
|
-
stability: "stable",
|
|
585
|
-
owners: [...OWNERS2],
|
|
586
|
-
tags: ["integration", "sync", "config", "create"],
|
|
587
|
-
description: "Create a sync configuration.",
|
|
588
|
-
goal: "Define how data should be synchronized.",
|
|
589
|
-
context: "Sync setup."
|
|
590
|
-
},
|
|
591
|
-
io: { input: CreateSyncConfigInputModel, output: SyncConfigModel },
|
|
592
|
-
policy: { auth: "user" },
|
|
593
|
-
sideEffects: {
|
|
594
|
-
emits: [
|
|
595
|
-
{
|
|
596
|
-
key: "integration.syncConfig.created",
|
|
597
|
-
version: "1.0.0",
|
|
598
|
-
when: "Sync config created",
|
|
599
|
-
payload: SyncConfigModel
|
|
600
|
-
}
|
|
601
|
-
],
|
|
602
|
-
audit: ["integration.syncConfig.created"]
|
|
603
|
-
},
|
|
604
|
-
acceptance: {
|
|
605
|
-
scenarios: [
|
|
606
|
-
{
|
|
607
|
-
key: "create-sync-happy-path",
|
|
608
|
-
given: ["User is authenticated"],
|
|
609
|
-
when: ["User creates sync config"],
|
|
610
|
-
then: ["Sync config is created", "SyncConfigCreated event is emitted"]
|
|
611
|
-
}
|
|
612
|
-
],
|
|
613
|
-
examples: [
|
|
614
|
-
{
|
|
615
|
-
key: "create-contact-sync",
|
|
616
|
-
input: {
|
|
617
|
-
name: "Contacts Sync",
|
|
618
|
-
sourceConnectionId: "conn-1",
|
|
619
|
-
targetConnectionId: "conn-2"
|
|
620
|
-
},
|
|
621
|
-
output: { id: "sync-123", status: "active" }
|
|
622
|
-
}
|
|
623
|
-
]
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
var AddFieldMappingContract = defineCommand3({
|
|
627
|
-
meta: {
|
|
628
|
-
key: "integration.fieldMapping.add",
|
|
629
|
-
version: "1.0.0",
|
|
630
|
-
stability: "stable",
|
|
631
|
-
owners: [...OWNERS2],
|
|
632
|
-
tags: ["integration", "mapping", "field"],
|
|
633
|
-
description: "Add a field mapping to a sync config.",
|
|
634
|
-
goal: "Map fields between systems.",
|
|
635
|
-
context: "Mapping configuration."
|
|
636
|
-
},
|
|
637
|
-
io: { input: AddFieldMappingInputModel, output: FieldMappingModel },
|
|
638
|
-
policy: { auth: "user" },
|
|
639
|
-
sideEffects: {
|
|
640
|
-
emits: [
|
|
641
|
-
{
|
|
642
|
-
key: "integration.fieldMapping.added",
|
|
643
|
-
version: "1.0.0",
|
|
644
|
-
when: "Mapping added",
|
|
645
|
-
payload: FieldMappingModel
|
|
646
|
-
}
|
|
647
|
-
]
|
|
648
|
-
},
|
|
649
|
-
acceptance: {
|
|
650
|
-
scenarios: [
|
|
651
|
-
{
|
|
652
|
-
key: "add-mapping-happy-path",
|
|
653
|
-
given: ["Sync config exists"],
|
|
654
|
-
when: ["User adds field mapping"],
|
|
655
|
-
then: ["Mapping is added", "FieldMappingAdded event is emitted"]
|
|
656
|
-
}
|
|
657
|
-
],
|
|
658
|
-
examples: [
|
|
659
|
-
{
|
|
660
|
-
key: "map-email",
|
|
661
|
-
input: {
|
|
662
|
-
syncConfigId: "sync-123",
|
|
663
|
-
sourceField: "email",
|
|
664
|
-
targetField: "user_email"
|
|
665
|
-
},
|
|
666
|
-
output: { id: "map-456", type: "string" }
|
|
667
|
-
}
|
|
668
|
-
]
|
|
669
|
-
}
|
|
670
|
-
});
|
|
671
|
-
var TriggerSyncContract = defineCommand3({
|
|
672
|
-
meta: {
|
|
673
|
-
key: "integration.sync.trigger",
|
|
674
|
-
version: "1.0.0",
|
|
675
|
-
stability: "stable",
|
|
676
|
-
owners: [...OWNERS2],
|
|
677
|
-
tags: ["integration", "sync", "trigger"],
|
|
678
|
-
description: "Trigger a manual sync.",
|
|
679
|
-
goal: "Start data synchronization.",
|
|
680
|
-
context: "Manual sync or webhook trigger."
|
|
681
|
-
},
|
|
682
|
-
io: { input: TriggerSyncInputModel, output: SyncRunModel },
|
|
683
|
-
policy: { auth: "user" },
|
|
684
|
-
sideEffects: {
|
|
685
|
-
emits: [
|
|
686
|
-
{
|
|
687
|
-
key: "integration.sync.started",
|
|
688
|
-
version: "1.0.0",
|
|
689
|
-
when: "Sync starts",
|
|
690
|
-
payload: SyncRunModel
|
|
691
|
-
}
|
|
692
|
-
],
|
|
693
|
-
audit: ["integration.sync.triggered"]
|
|
694
|
-
},
|
|
695
|
-
acceptance: {
|
|
696
|
-
scenarios: [
|
|
697
|
-
{
|
|
698
|
-
key: "trigger-sync-happy-path",
|
|
699
|
-
given: ["Sync config exists"],
|
|
700
|
-
when: ["User triggers sync"],
|
|
701
|
-
then: ["Sync run starts", "SyncStarted event is emitted"]
|
|
702
|
-
}
|
|
703
|
-
],
|
|
704
|
-
examples: [
|
|
705
|
-
{
|
|
706
|
-
key: "manual-trigger",
|
|
707
|
-
input: { syncConfigId: "sync-123" },
|
|
708
|
-
output: { id: "run-789", status: "pending" }
|
|
709
|
-
}
|
|
710
|
-
]
|
|
711
|
-
}
|
|
712
|
-
});
|
|
713
|
-
var ListSyncRunsContract = defineQuery({
|
|
714
|
-
meta: {
|
|
715
|
-
key: "integration.syncRun.list",
|
|
716
|
-
version: "1.0.0",
|
|
717
|
-
stability: "stable",
|
|
718
|
-
owners: [...OWNERS2],
|
|
719
|
-
tags: ["integration", "sync", "run", "list"],
|
|
720
|
-
description: "List sync run history.",
|
|
721
|
-
goal: "View sync history and status.",
|
|
722
|
-
context: "Sync monitoring."
|
|
723
|
-
},
|
|
724
|
-
io: { input: ListSyncRunsInputModel, output: ListSyncRunsOutputModel },
|
|
725
|
-
policy: { auth: "user" },
|
|
726
|
-
acceptance: {
|
|
727
|
-
scenarios: [
|
|
728
|
-
{
|
|
729
|
-
key: "list-runs-happy-path",
|
|
730
|
-
given: ["User has access to syncs"],
|
|
731
|
-
when: ["User lists sync runs"],
|
|
732
|
-
then: ["List of runs is returned"]
|
|
733
|
-
}
|
|
734
|
-
],
|
|
735
|
-
examples: [
|
|
736
|
-
{
|
|
737
|
-
key: "list-recent",
|
|
738
|
-
input: { limit: 10 },
|
|
739
|
-
output: { items: [], total: 50 }
|
|
740
|
-
}
|
|
741
|
-
]
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
// src/ui/renderers/integration.markdown.ts
|
|
745
|
-
var mockIntegrations = [
|
|
746
|
-
{
|
|
747
|
-
id: "int-1",
|
|
748
|
-
name: "Salesforce",
|
|
749
|
-
type: "CRM",
|
|
750
|
-
status: "ACTIVE",
|
|
751
|
-
connectionCount: 3
|
|
752
|
-
},
|
|
753
|
-
{
|
|
754
|
-
id: "int-2",
|
|
755
|
-
name: "HubSpot",
|
|
756
|
-
type: "MARKETING",
|
|
757
|
-
status: "ACTIVE",
|
|
758
|
-
connectionCount: 2
|
|
759
|
-
},
|
|
760
|
-
{
|
|
761
|
-
id: "int-3",
|
|
762
|
-
name: "Stripe",
|
|
763
|
-
type: "PAYMENT",
|
|
764
|
-
status: "ACTIVE",
|
|
765
|
-
connectionCount: 1
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
id: "int-4",
|
|
769
|
-
name: "Slack",
|
|
770
|
-
type: "COMMUNICATION",
|
|
771
|
-
status: "INACTIVE",
|
|
772
|
-
connectionCount: 0
|
|
773
|
-
},
|
|
774
|
-
{
|
|
775
|
-
id: "int-5",
|
|
776
|
-
name: "Google Sheets",
|
|
777
|
-
type: "DATA",
|
|
778
|
-
status: "ACTIVE",
|
|
779
|
-
connectionCount: 5
|
|
780
|
-
},
|
|
781
|
-
{
|
|
782
|
-
id: "int-6",
|
|
783
|
-
name: "PostHog",
|
|
784
|
-
type: "ANALYTICS",
|
|
785
|
-
status: "ACTIVE",
|
|
786
|
-
connectionCount: 1
|
|
787
|
-
}
|
|
788
|
-
];
|
|
789
|
-
var mockConnections = [
|
|
790
|
-
{
|
|
791
|
-
id: "conn-1",
|
|
792
|
-
integrationId: "int-1",
|
|
793
|
-
name: "Production Salesforce",
|
|
794
|
-
status: "CONNECTED",
|
|
795
|
-
lastSyncAt: "2024-01-16T10:00:00Z"
|
|
796
|
-
},
|
|
797
|
-
{
|
|
798
|
-
id: "conn-2",
|
|
799
|
-
integrationId: "int-1",
|
|
800
|
-
name: "Sandbox Salesforce",
|
|
801
|
-
status: "CONNECTED",
|
|
802
|
-
lastSyncAt: "2024-01-15T14:00:00Z"
|
|
803
|
-
},
|
|
804
|
-
{
|
|
805
|
-
id: "conn-3",
|
|
806
|
-
integrationId: "int-2",
|
|
807
|
-
name: "Marketing HubSpot",
|
|
808
|
-
status: "CONNECTED",
|
|
809
|
-
lastSyncAt: "2024-01-16T08:00:00Z"
|
|
810
|
-
},
|
|
811
|
-
{
|
|
812
|
-
id: "conn-4",
|
|
813
|
-
integrationId: "int-3",
|
|
814
|
-
name: "Stripe Live",
|
|
815
|
-
status: "CONNECTED",
|
|
816
|
-
lastSyncAt: "2024-01-16T12:00:00Z"
|
|
817
|
-
},
|
|
818
|
-
{
|
|
819
|
-
id: "conn-5",
|
|
820
|
-
integrationId: "int-5",
|
|
821
|
-
name: "Analytics Sheet",
|
|
822
|
-
status: "ERROR",
|
|
823
|
-
lastSyncAt: "2024-01-14T09:00:00Z",
|
|
824
|
-
error: "Authentication expired"
|
|
825
|
-
},
|
|
826
|
-
{
|
|
827
|
-
id: "conn-6",
|
|
828
|
-
integrationId: "int-6",
|
|
829
|
-
name: "PostHog Workspace",
|
|
830
|
-
status: "CONNECTED",
|
|
831
|
-
lastSyncAt: "2024-01-16T11:45:00Z"
|
|
832
|
-
}
|
|
833
|
-
];
|
|
834
|
-
var mockSyncConfigs = [
|
|
835
|
-
{
|
|
836
|
-
id: "sync-1",
|
|
837
|
-
connectionId: "conn-1",
|
|
838
|
-
name: "Contacts Sync",
|
|
839
|
-
frequency: "HOURLY",
|
|
840
|
-
lastRunAt: "2024-01-16T10:00:00Z",
|
|
841
|
-
status: "SUCCESS",
|
|
842
|
-
recordsSynced: 1250
|
|
843
|
-
},
|
|
844
|
-
{
|
|
845
|
-
id: "sync-2",
|
|
846
|
-
connectionId: "conn-1",
|
|
847
|
-
name: "Opportunities Sync",
|
|
848
|
-
frequency: "DAILY",
|
|
849
|
-
lastRunAt: "2024-01-16T00:00:00Z",
|
|
850
|
-
status: "SUCCESS",
|
|
851
|
-
recordsSynced: 340
|
|
852
|
-
},
|
|
853
|
-
{
|
|
854
|
-
id: "sync-3",
|
|
855
|
-
connectionId: "conn-3",
|
|
856
|
-
name: "Orders Sync",
|
|
857
|
-
frequency: "REALTIME",
|
|
858
|
-
lastRunAt: "2024-01-16T12:30:00Z",
|
|
859
|
-
status: "SUCCESS",
|
|
860
|
-
recordsSynced: 89
|
|
861
|
-
},
|
|
862
|
-
{
|
|
863
|
-
id: "sync-4",
|
|
864
|
-
connectionId: "conn-5",
|
|
865
|
-
name: "Metrics Export",
|
|
866
|
-
frequency: "DAILY",
|
|
867
|
-
lastRunAt: "2024-01-14T09:00:00Z",
|
|
868
|
-
status: "FAILED",
|
|
869
|
-
recordsSynced: 0
|
|
870
|
-
}
|
|
871
|
-
];
|
|
872
|
-
var integrationDashboardMarkdownRenderer = {
|
|
873
|
-
target: "markdown",
|
|
874
|
-
render: async (desc) => {
|
|
875
|
-
if (desc.source.type !== "component" || desc.source.componentKey !== "IntegrationDashboard") {
|
|
876
|
-
throw new Error("integrationDashboardMarkdownRenderer: not IntegrationDashboard");
|
|
877
|
-
}
|
|
878
|
-
const integrations = mockIntegrations;
|
|
879
|
-
const connections = mockConnections;
|
|
880
|
-
const syncs = mockSyncConfigs;
|
|
881
|
-
const activeIntegrations = integrations.filter((i) => i.status === "ACTIVE");
|
|
882
|
-
const connectedConnections = connections.filter((c) => c.status === "CONNECTED");
|
|
883
|
-
const errorConnections = connections.filter((c) => c.status === "ERROR");
|
|
884
|
-
const successfulSyncs = syncs.filter((s) => s.status === "SUCCESS");
|
|
885
|
-
const totalRecordsSynced = successfulSyncs.reduce((sum, s) => sum + s.recordsSynced, 0);
|
|
886
|
-
const lines = [
|
|
887
|
-
"# Integration Hub",
|
|
888
|
-
"",
|
|
889
|
-
"> Connect and sync data with external services",
|
|
890
|
-
"",
|
|
891
|
-
"## Overview",
|
|
892
|
-
"",
|
|
893
|
-
"| Metric | Value |",
|
|
894
|
-
"|--------|-------|",
|
|
895
|
-
`| Active Integrations | ${activeIntegrations.length} |`,
|
|
896
|
-
`| Connected Services | ${connectedConnections.length} |`,
|
|
897
|
-
`| Error Connections | ${errorConnections.length} |`,
|
|
898
|
-
`| Sync Configs | ${syncs.length} |`,
|
|
899
|
-
`| Records Synced (24h) | ${totalRecordsSynced.toLocaleString()} |`,
|
|
900
|
-
"",
|
|
901
|
-
"## Integrations",
|
|
902
|
-
"",
|
|
903
|
-
"| Name | Type | Connections | Status |",
|
|
904
|
-
"|------|------|-------------|--------|"
|
|
905
|
-
];
|
|
906
|
-
for (const integration of integrations) {
|
|
907
|
-
const statusIcon = integration.status === "ACTIVE" ? "\uD83D\uDFE2" : "⚫";
|
|
908
|
-
lines.push(`| ${integration.name} | ${integration.type} | ${integration.connectionCount} | ${statusIcon} ${integration.status} |`);
|
|
909
|
-
}
|
|
910
|
-
lines.push("");
|
|
911
|
-
lines.push("## Recent Sync Activity");
|
|
912
|
-
lines.push("");
|
|
913
|
-
lines.push("| Sync | Frequency | Last Run | Records | Status |");
|
|
914
|
-
lines.push("|------|-----------|----------|---------|--------|");
|
|
915
|
-
for (const sync of syncs) {
|
|
916
|
-
const lastRun = new Date(sync.lastRunAt).toLocaleString();
|
|
917
|
-
const statusIcon = sync.status === "SUCCESS" ? "✅" : "❌";
|
|
918
|
-
lines.push(`| ${sync.name} | ${sync.frequency} | ${lastRun} | ${sync.recordsSynced} | ${statusIcon} ${sync.status} |`);
|
|
919
|
-
}
|
|
920
|
-
if (errorConnections.length > 0) {
|
|
921
|
-
lines.push("");
|
|
922
|
-
lines.push("## ⚠️ Connections with Errors");
|
|
923
|
-
lines.push("");
|
|
924
|
-
for (const conn of errorConnections) {
|
|
925
|
-
const integration = integrations.find((i) => i.id === conn.integrationId);
|
|
926
|
-
lines.push(`- **${conn.name}** (${integration?.name ?? "Unknown"}): ${conn.error ?? "Unknown error"}`);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
return {
|
|
930
|
-
mimeType: "text/markdown",
|
|
931
|
-
body: lines.join(`
|
|
932
|
-
`)
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
};
|
|
936
|
-
var connectionListMarkdownRenderer = {
|
|
937
|
-
target: "markdown",
|
|
938
|
-
render: async (desc) => {
|
|
939
|
-
if (desc.source.type !== "component" || desc.source.componentKey !== "ConnectionList") {
|
|
940
|
-
throw new Error("connectionListMarkdownRenderer: not ConnectionList");
|
|
941
|
-
}
|
|
942
|
-
const connections = mockConnections;
|
|
943
|
-
const integrations = mockIntegrations;
|
|
944
|
-
const lines = [
|
|
945
|
-
"# Connections",
|
|
946
|
-
"",
|
|
947
|
-
"> Manage connections to external services",
|
|
948
|
-
""
|
|
949
|
-
];
|
|
950
|
-
for (const integration of integrations) {
|
|
951
|
-
const intConnections = connections.filter((c) => c.integrationId === integration.id);
|
|
952
|
-
if (intConnections.length === 0)
|
|
953
|
-
continue;
|
|
954
|
-
lines.push(`## ${integration.name}`);
|
|
955
|
-
lines.push("");
|
|
956
|
-
lines.push("| Connection | Status | Last Sync |");
|
|
957
|
-
lines.push("|------------|--------|-----------|");
|
|
958
|
-
for (const conn of intConnections) {
|
|
959
|
-
const lastSync = new Date(conn.lastSyncAt).toLocaleString();
|
|
960
|
-
const statusIcon = conn.status === "CONNECTED" ? "\uD83D\uDFE2" : conn.status === "ERROR" ? "\uD83D\uDD34" : "⚫";
|
|
961
|
-
lines.push(`| ${conn.name} | ${statusIcon} ${conn.status} | ${lastSync} |`);
|
|
962
|
-
}
|
|
963
|
-
lines.push("");
|
|
964
|
-
}
|
|
965
|
-
return {
|
|
966
|
-
mimeType: "text/markdown",
|
|
967
|
-
body: lines.join(`
|
|
968
|
-
`)
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
var syncConfigMarkdownRenderer = {
|
|
973
|
-
target: "markdown",
|
|
974
|
-
render: async (desc) => {
|
|
975
|
-
if (desc.source.type !== "component" || desc.source.componentKey !== "SyncConfigEditor") {
|
|
976
|
-
throw new Error("syncConfigMarkdownRenderer: not SyncConfigEditor");
|
|
977
|
-
}
|
|
978
|
-
const syncs = mockSyncConfigs;
|
|
979
|
-
const connections = mockConnections;
|
|
980
|
-
const lines = [
|
|
981
|
-
"# Sync Configurations",
|
|
982
|
-
"",
|
|
983
|
-
"> Configure automated data synchronization",
|
|
984
|
-
""
|
|
985
|
-
];
|
|
986
|
-
for (const sync of syncs) {
|
|
987
|
-
const connection = connections.find((c) => c.id === sync.connectionId);
|
|
988
|
-
const statusIcon = sync.status === "SUCCESS" ? "✅" : "❌";
|
|
989
|
-
lines.push(`## ${sync.name}`);
|
|
990
|
-
lines.push("");
|
|
991
|
-
lines.push(`**Connection:** ${connection?.name ?? "Unknown"}`);
|
|
992
|
-
lines.push(`**Frequency:** ${sync.frequency}`);
|
|
993
|
-
lines.push(`**Status:** ${statusIcon} ${sync.status}`);
|
|
994
|
-
lines.push(`**Last Run:** ${new Date(sync.lastRunAt).toLocaleString()}`);
|
|
995
|
-
lines.push(`**Records Synced:** ${sync.recordsSynced.toLocaleString()}`);
|
|
996
|
-
lines.push("");
|
|
997
|
-
}
|
|
998
|
-
lines.push("## Frequency Options");
|
|
999
|
-
lines.push("");
|
|
1000
|
-
lines.push("- **REALTIME**: Sync on every change");
|
|
1001
|
-
lines.push("- **HOURLY**: Sync every hour");
|
|
1002
|
-
lines.push("- **DAILY**: Sync once per day");
|
|
1003
|
-
lines.push("- **WEEKLY**: Sync once per week");
|
|
1004
|
-
lines.push("- **MANUAL**: Sync only when triggered");
|
|
1005
|
-
return {
|
|
1006
|
-
mimeType: "text/markdown",
|
|
1007
|
-
body: lines.join(`
|
|
1008
|
-
`)
|
|
1009
|
-
};
|
|
1010
|
-
}
|
|
1011
|
-
};
|
|
1012
|
-
// src/ui/hooks/useIntegrationData.ts
|
|
1013
|
-
import { useCallback, useEffect, useState } from "react";
|
|
1014
|
-
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
1015
|
-
"use client";
|
|
1016
|
-
function useIntegrationData(projectId = "local-project") {
|
|
1017
|
-
const { handlers } = useTemplateRuntime();
|
|
1018
|
-
const integration = handlers.integration;
|
|
1019
|
-
const [integrations, setIntegrations] = useState([]);
|
|
1020
|
-
const [connections, setConnections] = useState([]);
|
|
1021
|
-
const [syncConfigs, setSyncConfigs] = useState([]);
|
|
1022
|
-
const [loading, setLoading] = useState(true);
|
|
1023
|
-
const [error, setError] = useState(null);
|
|
1024
|
-
const fetchData = useCallback(async () => {
|
|
1025
|
-
try {
|
|
1026
|
-
setLoading(true);
|
|
1027
|
-
setError(null);
|
|
1028
|
-
const [integResult, connResult, syncResult] = await Promise.all([
|
|
1029
|
-
integration.listIntegrations({ projectId, limit: 100 }),
|
|
1030
|
-
integration.listConnections({ limit: 100 }),
|
|
1031
|
-
integration.listSyncConfigs({ limit: 100 })
|
|
1032
|
-
]);
|
|
1033
|
-
setIntegrations(integResult.integrations);
|
|
1034
|
-
setConnections(connResult.connections);
|
|
1035
|
-
setSyncConfigs(syncResult.configs);
|
|
1036
|
-
} catch (err) {
|
|
1037
|
-
setError(err instanceof Error ? err : new Error("Failed to load integrations"));
|
|
1038
|
-
} finally {
|
|
1039
|
-
setLoading(false);
|
|
1040
|
-
}
|
|
1041
|
-
}, [integration, projectId]);
|
|
1042
|
-
useEffect(() => {
|
|
1043
|
-
fetchData();
|
|
1044
|
-
}, [fetchData]);
|
|
1045
|
-
const stats = {
|
|
1046
|
-
totalIntegrations: integrations.length,
|
|
1047
|
-
activeIntegrations: integrations.filter((i) => i.status === "ACTIVE").length,
|
|
1048
|
-
totalConnections: connections.length,
|
|
1049
|
-
connectedCount: connections.filter((c) => c.status === "CONNECTED").length,
|
|
1050
|
-
totalSyncs: syncConfigs.length,
|
|
1051
|
-
activeSyncs: syncConfigs.filter((s) => s.status === "ACTIVE").length
|
|
1052
|
-
};
|
|
1053
|
-
return {
|
|
1054
|
-
integrations,
|
|
1055
|
-
connections,
|
|
1056
|
-
syncConfigs,
|
|
1057
|
-
loading,
|
|
1058
|
-
error,
|
|
1059
|
-
stats,
|
|
1060
|
-
refetch: fetchData
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
// src/ui/IntegrationDashboard.tsx
|
|
1065
|
-
import { useState as useState2 } from "react";
|
|
1066
|
-
import {
|
|
1067
|
-
Button,
|
|
1068
|
-
ErrorState,
|
|
1069
|
-
LoaderBlock,
|
|
1070
|
-
StatCard,
|
|
1071
|
-
StatCardGroup
|
|
1072
|
-
} from "@contractspec/lib.design-system";
|
|
1073
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
1074
|
-
"use client";
|
|
1075
|
-
var STATUS_COLORS = {
|
|
1076
|
-
ACTIVE: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
1077
|
-
INACTIVE: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
|
|
1078
|
-
CONNECTED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
1079
|
-
DISCONNECTED: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
|
|
1080
|
-
PENDING: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",
|
|
1081
|
-
ERROR: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
|
|
1082
|
-
PAUSED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
|
|
1083
|
-
};
|
|
1084
|
-
var TYPE_ICONS = {
|
|
1085
|
-
CRM: "\uD83D\uDCCA",
|
|
1086
|
-
MARKETING: "\uD83D\uDCE3",
|
|
1087
|
-
PAYMENT: "\uD83D\uDCB3",
|
|
1088
|
-
COMMUNICATION: "\uD83D\uDCAC",
|
|
1089
|
-
DATA: "\uD83D\uDDC4️",
|
|
1090
|
-
CUSTOM: "⚙️"
|
|
1091
|
-
};
|
|
1092
|
-
function IntegrationDashboard() {
|
|
1093
|
-
const [activeTab, setActiveTab] = useState2("integrations");
|
|
1094
|
-
const {
|
|
1095
|
-
integrations,
|
|
1096
|
-
connections,
|
|
1097
|
-
syncConfigs,
|
|
1098
|
-
loading,
|
|
1099
|
-
error,
|
|
1100
|
-
stats,
|
|
1101
|
-
refetch
|
|
1102
|
-
} = useIntegrationData();
|
|
1103
|
-
const tabs = [
|
|
1104
|
-
{ id: "integrations", label: "Integrations", icon: "\uD83D\uDD0C" },
|
|
1105
|
-
{ id: "connections", label: "Connections", icon: "\uD83D\uDD17" },
|
|
1106
|
-
{ id: "syncs", label: "Sync Configs", icon: "\uD83D\uDD04" }
|
|
1107
|
-
];
|
|
1108
|
-
if (loading) {
|
|
1109
|
-
return /* @__PURE__ */ jsxDEV(LoaderBlock, {
|
|
1110
|
-
label: "Loading Integrations..."
|
|
1111
|
-
}, undefined, false, undefined, this);
|
|
1112
|
-
}
|
|
1113
|
-
if (error) {
|
|
1114
|
-
return /* @__PURE__ */ jsxDEV(ErrorState, {
|
|
1115
|
-
title: "Failed to load Integrations",
|
|
1116
|
-
description: error.message,
|
|
1117
|
-
onRetry: refetch,
|
|
1118
|
-
retryLabel: "Retry"
|
|
1119
|
-
}, undefined, false, undefined, this);
|
|
1120
|
-
}
|
|
1121
|
-
return /* @__PURE__ */ jsxDEV("div", {
|
|
1122
|
-
className: "space-y-6",
|
|
1123
|
-
children: [
|
|
1124
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1125
|
-
className: "flex items-center justify-between",
|
|
1126
|
-
children: [
|
|
1127
|
-
/* @__PURE__ */ jsxDEV("h2", {
|
|
1128
|
-
className: "text-2xl font-bold",
|
|
1129
|
-
children: "Integration Hub"
|
|
1130
|
-
}, undefined, false, undefined, this),
|
|
1131
|
-
/* @__PURE__ */ jsxDEV(Button, {
|
|
1132
|
-
onClick: () => alert("Add integration modal"),
|
|
1133
|
-
children: [
|
|
1134
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
1135
|
-
className: "mr-2",
|
|
1136
|
-
children: "+"
|
|
1137
|
-
}, undefined, false, undefined, this),
|
|
1138
|
-
" Add Integration"
|
|
1139
|
-
]
|
|
1140
|
-
}, undefined, true, undefined, this)
|
|
1141
|
-
]
|
|
1142
|
-
}, undefined, true, undefined, this),
|
|
1143
|
-
/* @__PURE__ */ jsxDEV(StatCardGroup, {
|
|
1144
|
-
children: [
|
|
1145
|
-
/* @__PURE__ */ jsxDEV(StatCard, {
|
|
1146
|
-
label: "Integrations",
|
|
1147
|
-
value: stats.totalIntegrations,
|
|
1148
|
-
hint: `${stats.activeIntegrations} active`
|
|
1149
|
-
}, undefined, false, undefined, this),
|
|
1150
|
-
/* @__PURE__ */ jsxDEV(StatCard, {
|
|
1151
|
-
label: "Connections",
|
|
1152
|
-
value: stats.totalConnections,
|
|
1153
|
-
hint: `${stats.connectedCount} connected`
|
|
1154
|
-
}, undefined, false, undefined, this),
|
|
1155
|
-
/* @__PURE__ */ jsxDEV(StatCard, {
|
|
1156
|
-
label: "Syncs",
|
|
1157
|
-
value: stats.totalSyncs,
|
|
1158
|
-
hint: `${stats.activeSyncs} active`
|
|
1159
|
-
}, undefined, false, undefined, this)
|
|
1160
|
-
]
|
|
1161
|
-
}, undefined, true, undefined, this),
|
|
1162
|
-
/* @__PURE__ */ jsxDEV("nav", {
|
|
1163
|
-
className: "bg-muted flex gap-1 rounded-lg p-1",
|
|
1164
|
-
role: "tablist",
|
|
1165
|
-
children: tabs.map((tab) => /* @__PURE__ */ jsxDEV(Button, {
|
|
1166
|
-
type: "button",
|
|
1167
|
-
role: "tab",
|
|
1168
|
-
"aria-selected": activeTab === tab.id,
|
|
1169
|
-
onClick: () => setActiveTab(tab.id),
|
|
1170
|
-
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-medium transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
|
|
1171
|
-
children: [
|
|
1172
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
1173
|
-
children: tab.icon
|
|
1174
|
-
}, undefined, false, undefined, this),
|
|
1175
|
-
tab.label
|
|
1176
|
-
]
|
|
1177
|
-
}, tab.id, true, undefined, this))
|
|
1178
|
-
}, undefined, false, undefined, this),
|
|
1179
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1180
|
-
className: "min-h-[400px]",
|
|
1181
|
-
role: "tabpanel",
|
|
1182
|
-
children: [
|
|
1183
|
-
activeTab === "integrations" && /* @__PURE__ */ jsxDEV("div", {
|
|
1184
|
-
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
1185
|
-
children: [
|
|
1186
|
-
integrations.map((integration) => /* @__PURE__ */ jsxDEV("div", {
|
|
1187
|
-
className: "border-border bg-card hover:bg-muted/50 cursor-pointer rounded-lg border p-4 transition-colors",
|
|
1188
|
-
children: [
|
|
1189
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1190
|
-
className: "mb-3 flex items-center gap-3",
|
|
1191
|
-
children: [
|
|
1192
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
1193
|
-
className: "text-2xl",
|
|
1194
|
-
children: TYPE_ICONS[integration.type] ?? "⚙️"
|
|
1195
|
-
}, undefined, false, undefined, this),
|
|
1196
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1197
|
-
children: [
|
|
1198
|
-
/* @__PURE__ */ jsxDEV("h3", {
|
|
1199
|
-
className: "font-medium",
|
|
1200
|
-
children: integration.name
|
|
1201
|
-
}, undefined, false, undefined, this),
|
|
1202
|
-
/* @__PURE__ */ jsxDEV("p", {
|
|
1203
|
-
className: "text-muted-foreground text-sm",
|
|
1204
|
-
children: integration.type
|
|
1205
|
-
}, undefined, false, undefined, this)
|
|
1206
|
-
]
|
|
1207
|
-
}, undefined, true, undefined, this)
|
|
1208
|
-
]
|
|
1209
|
-
}, undefined, true, undefined, this),
|
|
1210
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1211
|
-
className: "flex items-center justify-between",
|
|
1212
|
-
children: [
|
|
1213
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
1214
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[integration.status] ?? ""}`,
|
|
1215
|
-
children: integration.status
|
|
1216
|
-
}, undefined, false, undefined, this),
|
|
1217
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
1218
|
-
className: "text-muted-foreground text-xs",
|
|
1219
|
-
children: integration.createdAt.toLocaleDateString()
|
|
1220
|
-
}, undefined, false, undefined, this)
|
|
1221
|
-
]
|
|
1222
|
-
}, undefined, true, undefined, this)
|
|
1223
|
-
]
|
|
1224
|
-
}, integration.id, true, undefined, this)),
|
|
1225
|
-
integrations.length === 0 && /* @__PURE__ */ jsxDEV("div", {
|
|
1226
|
-
className: "text-muted-foreground col-span-full flex h-64 items-center justify-center",
|
|
1227
|
-
children: "No integrations configured"
|
|
1228
|
-
}, undefined, false, undefined, this)
|
|
1229
|
-
]
|
|
1230
|
-
}, undefined, true, undefined, this),
|
|
1231
|
-
activeTab === "connections" && /* @__PURE__ */ jsxDEV("div", {
|
|
1232
|
-
className: "border-border rounded-lg border",
|
|
1233
|
-
children: /* @__PURE__ */ jsxDEV("table", {
|
|
1234
|
-
className: "w-full",
|
|
1235
|
-
children: [
|
|
1236
|
-
/* @__PURE__ */ jsxDEV("thead", {
|
|
1237
|
-
className: "border-border bg-muted/30 border-b",
|
|
1238
|
-
children: /* @__PURE__ */ jsxDEV("tr", {
|
|
1239
|
-
children: [
|
|
1240
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1241
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1242
|
-
children: "Connection"
|
|
1243
|
-
}, undefined, false, undefined, this),
|
|
1244
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1245
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1246
|
-
children: "Status"
|
|
1247
|
-
}, undefined, false, undefined, this),
|
|
1248
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1249
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1250
|
-
children: "Last Sync"
|
|
1251
|
-
}, undefined, false, undefined, this)
|
|
1252
|
-
]
|
|
1253
|
-
}, undefined, true, undefined, this)
|
|
1254
|
-
}, undefined, false, undefined, this),
|
|
1255
|
-
/* @__PURE__ */ jsxDEV("tbody", {
|
|
1256
|
-
className: "divide-border divide-y",
|
|
1257
|
-
children: [
|
|
1258
|
-
connections.map((conn) => /* @__PURE__ */ jsxDEV("tr", {
|
|
1259
|
-
className: "hover:bg-muted/50",
|
|
1260
|
-
children: [
|
|
1261
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1262
|
-
className: "px-4 py-3",
|
|
1263
|
-
children: /* @__PURE__ */ jsxDEV("div", {
|
|
1264
|
-
className: "font-medium",
|
|
1265
|
-
children: conn.name
|
|
1266
|
-
}, undefined, false, undefined, this)
|
|
1267
|
-
}, undefined, false, undefined, this),
|
|
1268
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1269
|
-
className: "px-4 py-3",
|
|
1270
|
-
children: /* @__PURE__ */ jsxDEV("span", {
|
|
1271
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[conn.status] ?? ""}`,
|
|
1272
|
-
children: conn.status
|
|
1273
|
-
}, undefined, false, undefined, this)
|
|
1274
|
-
}, undefined, false, undefined, this),
|
|
1275
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1276
|
-
className: "text-muted-foreground px-4 py-3 text-sm",
|
|
1277
|
-
children: conn.lastSyncAt?.toLocaleString() ?? "Never"
|
|
1278
|
-
}, undefined, false, undefined, this)
|
|
1279
|
-
]
|
|
1280
|
-
}, conn.id, true, undefined, this)),
|
|
1281
|
-
connections.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
|
|
1282
|
-
children: /* @__PURE__ */ jsxDEV("td", {
|
|
1283
|
-
colSpan: 3,
|
|
1284
|
-
className: "text-muted-foreground px-4 py-8 text-center",
|
|
1285
|
-
children: "No connections found"
|
|
1286
|
-
}, undefined, false, undefined, this)
|
|
1287
|
-
}, undefined, false, undefined, this)
|
|
1288
|
-
]
|
|
1289
|
-
}, undefined, true, undefined, this)
|
|
1290
|
-
]
|
|
1291
|
-
}, undefined, true, undefined, this)
|
|
1292
|
-
}, undefined, false, undefined, this),
|
|
1293
|
-
activeTab === "syncs" && /* @__PURE__ */ jsxDEV("div", {
|
|
1294
|
-
className: "border-border rounded-lg border",
|
|
1295
|
-
children: /* @__PURE__ */ jsxDEV("table", {
|
|
1296
|
-
className: "w-full",
|
|
1297
|
-
children: [
|
|
1298
|
-
/* @__PURE__ */ jsxDEV("thead", {
|
|
1299
|
-
className: "border-border bg-muted/30 border-b",
|
|
1300
|
-
children: /* @__PURE__ */ jsxDEV("tr", {
|
|
1301
|
-
children: [
|
|
1302
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1303
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1304
|
-
children: "Sync Config"
|
|
1305
|
-
}, undefined, false, undefined, this),
|
|
1306
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1307
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1308
|
-
children: "Frequency"
|
|
1309
|
-
}, undefined, false, undefined, this),
|
|
1310
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1311
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1312
|
-
children: "Status"
|
|
1313
|
-
}, undefined, false, undefined, this),
|
|
1314
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1315
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1316
|
-
children: "Records"
|
|
1317
|
-
}, undefined, false, undefined, this)
|
|
1318
|
-
]
|
|
1319
|
-
}, undefined, true, undefined, this)
|
|
1320
|
-
}, undefined, false, undefined, this),
|
|
1321
|
-
/* @__PURE__ */ jsxDEV("tbody", {
|
|
1322
|
-
className: "divide-border divide-y",
|
|
1323
|
-
children: [
|
|
1324
|
-
syncConfigs.map((sync) => /* @__PURE__ */ jsxDEV("tr", {
|
|
1325
|
-
className: "hover:bg-muted/50",
|
|
1326
|
-
children: [
|
|
1327
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1328
|
-
className: "px-4 py-3",
|
|
1329
|
-
children: [
|
|
1330
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1331
|
-
className: "font-medium",
|
|
1332
|
-
children: sync.name
|
|
1333
|
-
}, undefined, false, undefined, this),
|
|
1334
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1335
|
-
className: "text-muted-foreground text-sm",
|
|
1336
|
-
children: [
|
|
1337
|
-
sync.sourceEntity,
|
|
1338
|
-
" → ",
|
|
1339
|
-
sync.targetEntity
|
|
1340
|
-
]
|
|
1341
|
-
}, undefined, true, undefined, this)
|
|
1342
|
-
]
|
|
1343
|
-
}, undefined, true, undefined, this),
|
|
1344
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1345
|
-
className: "px-4 py-3 text-sm",
|
|
1346
|
-
children: sync.frequency
|
|
1347
|
-
}, undefined, false, undefined, this),
|
|
1348
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1349
|
-
className: "px-4 py-3",
|
|
1350
|
-
children: /* @__PURE__ */ jsxDEV("span", {
|
|
1351
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[sync.status] ?? ""}`,
|
|
1352
|
-
children: sync.status
|
|
1353
|
-
}, undefined, false, undefined, this)
|
|
1354
|
-
}, undefined, false, undefined, this),
|
|
1355
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1356
|
-
className: "text-muted-foreground px-4 py-3 text-sm",
|
|
1357
|
-
children: sync.recordsSynced.toLocaleString()
|
|
1358
|
-
}, undefined, false, undefined, this)
|
|
1359
|
-
]
|
|
1360
|
-
}, sync.id, true, undefined, this)),
|
|
1361
|
-
syncConfigs.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
|
|
1362
|
-
children: /* @__PURE__ */ jsxDEV("td", {
|
|
1363
|
-
colSpan: 4,
|
|
1364
|
-
className: "text-muted-foreground px-4 py-8 text-center",
|
|
1365
|
-
children: "No sync configurations found"
|
|
1366
|
-
}, undefined, false, undefined, this)
|
|
1367
|
-
}, undefined, false, undefined, this)
|
|
1368
|
-
]
|
|
1369
|
-
}, undefined, true, undefined, this)
|
|
1370
|
-
]
|
|
1371
|
-
}, undefined, true, undefined, this)
|
|
1372
|
-
}, undefined, false, undefined, this)
|
|
1373
|
-
]
|
|
1374
|
-
}, undefined, true, undefined, this)
|
|
1375
|
-
]
|
|
1376
|
-
}, undefined, true, undefined, this);
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
// src/ui/hooks/index.ts
|
|
1380
|
-
"use client";
|
|
1381
|
-
// src/sync-engine/index.ts
|
|
1382
|
-
class BasicFieldTransformer {
|
|
1383
|
-
transform(value, expression) {
|
|
1384
|
-
try {
|
|
1385
|
-
if (expression.startsWith("uppercase")) {
|
|
1386
|
-
return typeof value === "string" ? value.toUpperCase() : value;
|
|
1387
|
-
}
|
|
1388
|
-
if (expression.startsWith("lowercase")) {
|
|
1389
|
-
return typeof value === "string" ? value.toLowerCase() : value;
|
|
1390
|
-
}
|
|
1391
|
-
if (expression.startsWith("trim")) {
|
|
1392
|
-
return typeof value === "string" ? value.trim() : value;
|
|
1393
|
-
}
|
|
1394
|
-
if (expression.startsWith("default:")) {
|
|
1395
|
-
const defaultVal = expression.replace("default:", "");
|
|
1396
|
-
return value ?? JSON.parse(defaultVal);
|
|
1397
|
-
}
|
|
1398
|
-
if (expression.startsWith("concat:")) {
|
|
1399
|
-
const separator = expression.replace("concat:", "") || " ";
|
|
1400
|
-
if (Array.isArray(value)) {
|
|
1401
|
-
return value.join(separator);
|
|
1402
|
-
}
|
|
1403
|
-
return value;
|
|
1404
|
-
}
|
|
1405
|
-
if (expression.startsWith("split:")) {
|
|
1406
|
-
const separator = expression.replace("split:", "") || ",";
|
|
1407
|
-
if (typeof value === "string") {
|
|
1408
|
-
return value.split(separator);
|
|
1409
|
-
}
|
|
1410
|
-
return value;
|
|
1411
|
-
}
|
|
1412
|
-
if (expression.startsWith("number")) {
|
|
1413
|
-
return Number(value);
|
|
1414
|
-
}
|
|
1415
|
-
if (expression.startsWith("boolean")) {
|
|
1416
|
-
return Boolean(value);
|
|
1417
|
-
}
|
|
1418
|
-
if (expression.startsWith("string")) {
|
|
1419
|
-
return String(value);
|
|
1420
|
-
}
|
|
1421
|
-
return value;
|
|
1422
|
-
} catch {
|
|
1423
|
-
return value;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
class BasicSyncEngine {
|
|
1429
|
-
transformer;
|
|
1430
|
-
constructor(transformer) {
|
|
1431
|
-
this.transformer = transformer ?? new BasicFieldTransformer;
|
|
1432
|
-
}
|
|
1433
|
-
async sync(_context) {
|
|
1434
|
-
const result = {
|
|
1435
|
-
success: true,
|
|
1436
|
-
recordsProcessed: 0,
|
|
1437
|
-
recordsCreated: 0,
|
|
1438
|
-
recordsUpdated: 0,
|
|
1439
|
-
recordsDeleted: 0,
|
|
1440
|
-
recordsFailed: 0,
|
|
1441
|
-
recordsSkipped: 0,
|
|
1442
|
-
errors: []
|
|
1443
|
-
};
|
|
1444
|
-
return result;
|
|
1445
|
-
}
|
|
1446
|
-
transformRecord(sourceRecord, mappings, _context) {
|
|
1447
|
-
const targetData = {};
|
|
1448
|
-
for (const mapping of mappings) {
|
|
1449
|
-
let value;
|
|
1450
|
-
let sourceValue;
|
|
1451
|
-
switch (mapping.mappingType) {
|
|
1452
|
-
case "DIRECT":
|
|
1453
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1454
|
-
break;
|
|
1455
|
-
case "TRANSFORM":
|
|
1456
|
-
sourceValue = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1457
|
-
value = mapping.transformExpression ? this.transformer.transform(sourceValue, mapping.transformExpression) : sourceValue;
|
|
1458
|
-
break;
|
|
1459
|
-
case "CONSTANT":
|
|
1460
|
-
value = mapping.constantValue;
|
|
1461
|
-
break;
|
|
1462
|
-
case "LOOKUP":
|
|
1463
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1464
|
-
break;
|
|
1465
|
-
case "COMPUTED":
|
|
1466
|
-
value = mapping.transformExpression ? this.evaluateComputed(sourceRecord.data, mapping.transformExpression) : null;
|
|
1467
|
-
break;
|
|
1468
|
-
default:
|
|
1469
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
1470
|
-
}
|
|
1471
|
-
if (value === undefined || value === null) {
|
|
1472
|
-
value = mapping.defaultValue;
|
|
1473
|
-
}
|
|
1474
|
-
this.setNestedValue(targetData, mapping.targetField, value);
|
|
1475
|
-
}
|
|
1476
|
-
return {
|
|
1477
|
-
id: sourceRecord.id,
|
|
1478
|
-
data: targetData
|
|
1479
|
-
};
|
|
1480
|
-
}
|
|
1481
|
-
validateRecord(record, mappings) {
|
|
1482
|
-
const errors = [];
|
|
1483
|
-
for (const mapping of mappings) {
|
|
1484
|
-
if (mapping.isRequired) {
|
|
1485
|
-
const value = this.getNestedValue(record.data, mapping.targetField);
|
|
1486
|
-
if (value === undefined || value === null) {
|
|
1487
|
-
errors.push({
|
|
1488
|
-
recordId: record.id,
|
|
1489
|
-
field: mapping.targetField,
|
|
1490
|
-
message: `Required field ${mapping.targetField} is missing`,
|
|
1491
|
-
code: "REQUIRED_FIELD_MISSING"
|
|
1492
|
-
});
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
return {
|
|
1497
|
-
valid: errors.length === 0,
|
|
1498
|
-
errors
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
getNestedValue(obj, path) {
|
|
1502
|
-
const parts = path.split(".");
|
|
1503
|
-
let current = obj;
|
|
1504
|
-
for (const part of parts) {
|
|
1505
|
-
if (current === null || current === undefined) {
|
|
1506
|
-
return;
|
|
1507
|
-
}
|
|
1508
|
-
current = current[part];
|
|
1509
|
-
}
|
|
1510
|
-
return current;
|
|
1511
|
-
}
|
|
1512
|
-
setNestedValue(obj, path, value) {
|
|
1513
|
-
const parts = path.split(".");
|
|
1514
|
-
let current = obj;
|
|
1515
|
-
for (let i = 0;i < parts.length - 1; i++) {
|
|
1516
|
-
const part = parts[i];
|
|
1517
|
-
if (part === undefined)
|
|
1518
|
-
continue;
|
|
1519
|
-
if (!(part in current)) {
|
|
1520
|
-
current[part] = {};
|
|
1521
|
-
}
|
|
1522
|
-
current = current[part];
|
|
1523
|
-
}
|
|
1524
|
-
const lastPart = parts[parts.length - 1];
|
|
1525
|
-
if (lastPart !== undefined) {
|
|
1526
|
-
current[lastPart] = value;
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
evaluateComputed(data, expression) {
|
|
1530
|
-
try {
|
|
1531
|
-
const result = expression.replace(/\$\{([^}]+)\}/g, (_, path) => {
|
|
1532
|
-
const value = this.getNestedValue(data, path);
|
|
1533
|
-
return String(value ?? "");
|
|
1534
|
-
});
|
|
1535
|
-
return result;
|
|
1536
|
-
} catch {
|
|
1537
|
-
return null;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
function createSyncEngine(transformer) {
|
|
1542
|
-
return new BasicSyncEngine(transformer);
|
|
1543
|
-
}
|
|
1544
|
-
function computeChecksum(data) {
|
|
1545
|
-
const str = JSON.stringify(data, Object.keys(data).sort());
|
|
1546
|
-
let hash = 0;
|
|
1547
|
-
for (let i = 0;i < str.length; i++) {
|
|
1548
|
-
const char = str.charCodeAt(i);
|
|
1549
|
-
hash = (hash << 5) - hash + char;
|
|
1550
|
-
hash = hash & hash;
|
|
1551
|
-
}
|
|
1552
|
-
return hash.toString(16);
|
|
1553
|
-
}
|
|
1554
|
-
function hasChanges(sourceChecksum, targetChecksum) {
|
|
1555
|
-
if (!sourceChecksum || !targetChecksum) {
|
|
1556
|
-
return true;
|
|
1557
|
-
}
|
|
1558
|
-
return sourceChecksum !== targetChecksum;
|
|
1559
|
-
}
|
|
1560
|
-
export {
|
|
1561
|
-
useIntegrationData,
|
|
1562
|
-
syncConfigMarkdownRenderer,
|
|
1563
|
-
integrationDashboardMarkdownRenderer,
|
|
1564
|
-
hasChanges,
|
|
1565
|
-
createSyncEngine,
|
|
1566
|
-
createIntegrationHandlers,
|
|
1567
|
-
connectionListMarkdownRenderer,
|
|
1568
|
-
computeChecksum,
|
|
1569
|
-
TriggerSyncInputModel,
|
|
1570
|
-
TriggerSyncContract,
|
|
1571
|
-
SyncStatusEnum,
|
|
1572
|
-
SyncRunModel,
|
|
1573
|
-
SyncDirectionEnum,
|
|
1574
|
-
SyncConfigModel,
|
|
1575
|
-
MappingTypeEnum,
|
|
1576
|
-
ListSyncRunsOutputModel,
|
|
1577
|
-
ListSyncRunsInputModel,
|
|
1578
|
-
ListSyncRunsContract,
|
|
1579
|
-
IntegrationStatusEnum,
|
|
1580
|
-
IntegrationModel,
|
|
1581
|
-
IntegrationDashboard,
|
|
1582
|
-
FieldMappingModel,
|
|
1583
|
-
CreateSyncConfigInputModel,
|
|
1584
|
-
CreateSyncConfigContract,
|
|
1585
|
-
CreateIntegrationInputModel,
|
|
1586
|
-
CreateIntegrationContract,
|
|
1587
|
-
CreateConnectionInputModel,
|
|
1588
|
-
CreateConnectionContract,
|
|
1589
|
-
ConnectionStatusEnum,
|
|
1590
|
-
ConnectionModel,
|
|
1591
|
-
BasicSyncEngine,
|
|
1592
|
-
BasicFieldTransformer,
|
|
1593
|
-
AddFieldMappingInputModel,
|
|
1594
|
-
AddFieldMappingContract
|
|
1595
|
-
};
|