@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.
Files changed (48) hide show
  1. package/README.md +40 -0
  2. package/dist/docs/index.js +2 -0
  3. package/dist/docs/integration-hub.docblock.js +2 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +149 -0
  6. package/dist/mcp-example.d.ts +16 -0
  7. package/dist/mcp-example.js +151 -0
  8. package/dist/node/docs/index.js +2 -0
  9. package/dist/node/docs/integration-hub.docblock.js +2 -0
  10. package/dist/node/index.js +149 -0
  11. package/dist/node/mcp-example.js +150 -0
  12. package/dist/node/run-mcp.js +155 -0
  13. package/dist/run-mcp.d.ts +1 -0
  14. package/dist/run-mcp.js +156 -0
  15. package/package.json +34 -94
  16. package/dist/browser/connection/connection.enum.js +0 -12
  17. package/dist/browser/connection/connection.operation.js +0 -101
  18. package/dist/browser/connection/connection.presentation.js +0 -102
  19. package/dist/browser/connection/connection.schema.js +0 -48
  20. package/dist/browser/connection/index.js +0 -104
  21. package/dist/browser/docs/index.js +0 -104
  22. package/dist/browser/docs/integration-hub.docblock.js +0 -104
  23. package/dist/browser/events.js +0 -211
  24. package/dist/browser/example.js +0 -42
  25. package/dist/browser/handlers/index.js +0 -246
  26. package/dist/browser/handlers/integration.handlers.js +0 -246
  27. package/dist/browser/index.js +0 -1595
  28. package/dist/browser/integration/index.js +0 -92
  29. package/dist/browser/integration/integration.enum.js +0 -12
  30. package/dist/browser/integration/integration.operations.js +0 -89
  31. package/dist/browser/integration/integration.presentation.js +0 -120
  32. package/dist/browser/integration/integration.schema.js +0 -42
  33. package/dist/browser/integration-hub.capability.js +0 -43
  34. package/dist/browser/integration-hub.feature.js +0 -114
  35. package/dist/browser/seeders/index.js +0 -60
  36. package/dist/browser/sync/index.js +0 -332
  37. package/dist/browser/sync/sync.enum.js +0 -26
  38. package/dist/browser/sync/sync.operations.js +0 -321
  39. package/dist/browser/sync/sync.presentation.js +0 -301
  40. package/dist/browser/sync/sync.schema.js +0 -154
  41. package/dist/browser/sync-engine/index.js +0 -186
  42. package/dist/browser/tests/operations.test-spec.js +0 -85
  43. package/dist/browser/ui/IntegrationDashboard.js +0 -369
  44. package/dist/browser/ui/hooks/index.js +0 -57
  45. package/dist/browser/ui/hooks/useIntegrationData.js +0 -54
  46. package/dist/browser/ui/index.js +0 -644
  47. package/dist/browser/ui/renderers/index.js +0 -273
  48. package/dist/browser/ui/renderers/integration.markdown.js +0 -273
@@ -1,246 +0,0 @@
1
- // src/handlers/integration.handlers.ts
2
- import { web } from "@contractspec/lib.runtime-sandbox";
3
- var { generateId } = web;
4
- function rowToIntegration(row) {
5
- return {
6
- id: row.id,
7
- projectId: row.projectId,
8
- organizationId: row.organizationId,
9
- name: row.name,
10
- description: row.description ?? undefined,
11
- type: row.type,
12
- status: row.status,
13
- iconUrl: row.iconUrl ?? undefined,
14
- createdAt: new Date(row.createdAt),
15
- updatedAt: new Date(row.updatedAt)
16
- };
17
- }
18
- function rowToConnection(row) {
19
- return {
20
- id: row.id,
21
- integrationId: row.integrationId,
22
- name: row.name,
23
- status: row.status,
24
- credentials: row.credentials ? JSON.parse(row.credentials) : undefined,
25
- config: row.config ? JSON.parse(row.config) : undefined,
26
- lastSyncAt: row.lastSyncAt ? new Date(row.lastSyncAt) : undefined,
27
- errorMessage: row.errorMessage ?? undefined,
28
- createdAt: new Date(row.createdAt),
29
- updatedAt: new Date(row.updatedAt)
30
- };
31
- }
32
- function rowToSyncConfig(row) {
33
- return {
34
- id: row.id,
35
- connectionId: row.connectionId,
36
- name: row.name,
37
- sourceEntity: row.sourceEntity,
38
- targetEntity: row.targetEntity,
39
- frequency: row.frequency,
40
- status: row.status,
41
- lastRunAt: row.lastRunAt ? new Date(row.lastRunAt) : undefined,
42
- lastRunStatus: row.lastRunStatus ?? undefined,
43
- recordsSynced: row.recordsSynced,
44
- createdAt: new Date(row.createdAt),
45
- updatedAt: new Date(row.updatedAt)
46
- };
47
- }
48
- function rowToFieldMapping(row) {
49
- return {
50
- id: row.id,
51
- syncConfigId: row.syncConfigId,
52
- sourceField: row.sourceField,
53
- targetField: row.targetField,
54
- transformType: row.transformType ?? undefined,
55
- transformConfig: row.transformConfig ? JSON.parse(row.transformConfig) : undefined,
56
- createdAt: new Date(row.createdAt)
57
- };
58
- }
59
- function createIntegrationHandlers(db) {
60
- async function listIntegrations(input) {
61
- const { projectId, type, status, search, limit = 20, offset = 0 } = input;
62
- let whereClause = "WHERE projectId = ?";
63
- const params = [projectId];
64
- if (type && type !== "all") {
65
- whereClause += " AND type = ?";
66
- params.push(type);
67
- }
68
- if (status && status !== "all") {
69
- whereClause += " AND status = ?";
70
- params.push(status);
71
- }
72
- if (search) {
73
- whereClause += " AND name LIKE ?";
74
- params.push(`%${search}%`);
75
- }
76
- const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration ${whereClause}`, params)).rows;
77
- const total = countResult[0]?.count ?? 0;
78
- const rows = (await db.query(`SELECT * FROM integration ${whereClause} ORDER BY name LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
79
- return {
80
- integrations: rows.map(rowToIntegration),
81
- total
82
- };
83
- }
84
- async function createIntegration(input, context) {
85
- const id = generateId("integ");
86
- const now = new Date().toISOString();
87
- await db.execute(`INSERT INTO integration (id, projectId, organizationId, name, description, type, status, iconUrl, createdAt, updatedAt)
88
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
89
- id,
90
- context.projectId,
91
- context.organizationId,
92
- input.name,
93
- input.description ?? null,
94
- input.type,
95
- "INACTIVE",
96
- input.iconUrl ?? null,
97
- now,
98
- now
99
- ]);
100
- const rows = (await db.query(`SELECT * FROM integration WHERE id = ?`, [id])).rows;
101
- return rowToIntegration(rows[0]);
102
- }
103
- async function listConnections(input) {
104
- const { integrationId, status, limit = 20, offset = 0 } = input;
105
- let whereClause = "WHERE 1=1";
106
- const params = [];
107
- if (integrationId) {
108
- whereClause += " AND integrationId = ?";
109
- params.push(integrationId);
110
- }
111
- if (status && status !== "all") {
112
- whereClause += " AND status = ?";
113
- params.push(status);
114
- }
115
- const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration_connection ${whereClause}`, params)).rows;
116
- const total = countResult[0]?.count ?? 0;
117
- const rows = (await db.query(`SELECT * FROM integration_connection ${whereClause} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
118
- return {
119
- connections: rows.map(rowToConnection),
120
- total
121
- };
122
- }
123
- async function connectService(input) {
124
- const id = generateId("conn");
125
- const now = new Date().toISOString();
126
- await db.execute(`INSERT INTO integration_connection (id, integrationId, name, status, credentials, config, createdAt, updatedAt)
127
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [
128
- id,
129
- input.integrationId,
130
- input.name,
131
- "PENDING",
132
- input.credentials ? JSON.stringify(input.credentials) : null,
133
- input.config ? JSON.stringify(input.config) : null,
134
- now,
135
- now
136
- ]);
137
- await db.execute(`UPDATE integration_connection SET status = 'CONNECTED', updatedAt = ? WHERE id = ?`, [now, id]);
138
- await db.execute(`UPDATE integration SET status = 'ACTIVE', updatedAt = ? WHERE id = ?`, [now, input.integrationId]);
139
- const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [id])).rows;
140
- return rowToConnection(rows[0]);
141
- }
142
- async function disconnectService(connectionId) {
143
- const now = new Date().toISOString();
144
- await db.execute(`UPDATE integration_connection SET status = 'DISCONNECTED', updatedAt = ? WHERE id = ?`, [now, connectionId]);
145
- const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [
146
- connectionId
147
- ])).rows;
148
- return rowToConnection(rows[0]);
149
- }
150
- async function listSyncConfigs(input) {
151
- const { connectionId, status, limit = 20, offset = 0 } = input;
152
- let whereClause = "WHERE 1=1";
153
- const params = [];
154
- if (connectionId) {
155
- whereClause += " AND connectionId = ?";
156
- params.push(connectionId);
157
- }
158
- if (status && status !== "all") {
159
- whereClause += " AND status = ?";
160
- params.push(status);
161
- }
162
- const countResult = (await db.query(`SELECT COUNT(*) as count FROM integration_sync_config ${whereClause}`, params)).rows;
163
- const total = countResult[0]?.count ?? 0;
164
- const rows = (await db.query(`SELECT * FROM integration_sync_config ${whereClause} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
165
- return {
166
- configs: rows.map(rowToSyncConfig),
167
- total
168
- };
169
- }
170
- async function configureSync(input) {
171
- const id = generateId("sync");
172
- const now = new Date().toISOString();
173
- await db.execute(`INSERT INTO integration_sync_config (id, connectionId, name, sourceEntity, targetEntity, frequency, status, recordsSynced, createdAt, updatedAt)
174
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
175
- id,
176
- input.connectionId,
177
- input.name,
178
- input.sourceEntity,
179
- input.targetEntity,
180
- input.frequency ?? "DAILY",
181
- "ACTIVE",
182
- 0,
183
- now,
184
- now
185
- ]);
186
- const rows = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [id])).rows;
187
- return rowToSyncConfig(rows[0]);
188
- }
189
- async function mapFields(input) {
190
- const now = new Date().toISOString();
191
- const mappings = [];
192
- await db.execute(`DELETE FROM integration_field_mapping WHERE syncConfigId = ?`, [input.syncConfigId]);
193
- for (const mapping of input.mappings) {
194
- const id = generateId("fmap");
195
- await db.execute(`INSERT INTO integration_field_mapping (id, syncConfigId, sourceField, targetField, transformType, transformConfig, createdAt)
196
- VALUES (?, ?, ?, ?, ?, ?, ?)`, [
197
- id,
198
- input.syncConfigId,
199
- mapping.sourceField,
200
- mapping.targetField,
201
- mapping.transformType ?? null,
202
- mapping.transformConfig ? JSON.stringify(mapping.transformConfig) : null,
203
- now
204
- ]);
205
- const rows = (await db.query(`SELECT * FROM integration_field_mapping WHERE id = ?`, [
206
- id
207
- ])).rows;
208
- mappings.push(rowToFieldMapping(rows[0]));
209
- }
210
- return mappings;
211
- }
212
- async function getFieldMappings(syncConfigId) {
213
- const rows = (await db.query(`SELECT * FROM integration_field_mapping WHERE syncConfigId = ?`, [syncConfigId])).rows;
214
- return rows.map(rowToFieldMapping);
215
- }
216
- async function runSync(syncConfigId) {
217
- const now = new Date().toISOString();
218
- const recordsSynced = Math.floor(Math.random() * 1000) + 50;
219
- await db.execute(`UPDATE integration_sync_config SET lastRunAt = ?, lastRunStatus = 'SUCCESS', recordsSynced = recordsSynced + ?, updatedAt = ? WHERE id = ?`, [now, recordsSynced, now, syncConfigId]);
220
- const config = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [
221
- syncConfigId
222
- ])).rows;
223
- if (config[0]) {
224
- await db.execute(`UPDATE integration_connection SET lastSyncAt = ?, updatedAt = ? WHERE id = ?`, [now, now, config[0].connectionId]);
225
- }
226
- const rows = (await db.query(`SELECT * FROM integration_sync_config WHERE id = ?`, [
227
- syncConfigId
228
- ])).rows;
229
- return rowToSyncConfig(rows[0]);
230
- }
231
- return {
232
- listIntegrations,
233
- createIntegration,
234
- listConnections,
235
- connectService,
236
- disconnectService,
237
- listSyncConfigs,
238
- configureSync,
239
- mapFields,
240
- getFieldMappings,
241
- runSync
242
- };
243
- }
244
- export {
245
- createIntegrationHandlers
246
- };