@contractspec/example.integration-hub 3.8.9 → 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.
Files changed (89) hide show
  1. package/dist/connection/connection.enum.js +1 -29
  2. package/dist/connection/connection.operation.js +1 -124
  3. package/dist/connection/connection.presentation.js +1 -125
  4. package/dist/connection/connection.schema.js +1 -71
  5. package/dist/connection/index.js +1 -127
  6. package/dist/docs/index.js +5 -49
  7. package/dist/docs/integration-hub.docblock.js +5 -49
  8. package/dist/events.js +1 -211
  9. package/dist/example.js +1 -42
  10. package/dist/handlers/index.js +5 -292
  11. package/dist/handlers/integration.handlers.js +5 -292
  12. package/dist/index.js +8 -2355
  13. package/dist/integration/index.js +1 -92
  14. package/dist/integration/integration.enum.js +1 -12
  15. package/dist/integration/integration.operations.js +1 -89
  16. package/dist/integration/integration.presentation.js +1 -120
  17. package/dist/integration/integration.schema.js +1 -42
  18. package/dist/integration-hub.capability.js +1 -43
  19. package/dist/integration-hub.feature.js +1 -330
  20. package/dist/mcp-example.js +1 -154
  21. package/dist/node/connection/connection.enum.js +1 -29
  22. package/dist/node/connection/connection.operation.js +1 -124
  23. package/dist/node/connection/connection.presentation.js +1 -125
  24. package/dist/node/connection/connection.schema.js +1 -71
  25. package/dist/node/connection/index.js +1 -127
  26. package/dist/node/docs/index.js +5 -49
  27. package/dist/node/docs/integration-hub.docblock.js +5 -49
  28. package/dist/node/events.js +1 -211
  29. package/dist/node/example.js +1 -42
  30. package/dist/node/handlers/index.js +5 -292
  31. package/dist/node/handlers/integration.handlers.js +5 -292
  32. package/dist/node/index.js +8 -2355
  33. package/dist/node/integration/index.js +1 -92
  34. package/dist/node/integration/integration.enum.js +1 -12
  35. package/dist/node/integration/integration.operations.js +1 -89
  36. package/dist/node/integration/integration.presentation.js +1 -120
  37. package/dist/node/integration/integration.schema.js +1 -42
  38. package/dist/node/integration-hub.capability.js +1 -43
  39. package/dist/node/integration-hub.feature.js +1 -330
  40. package/dist/node/mcp-example.js +1 -154
  41. package/dist/node/run-mcp.js +1 -159
  42. package/dist/node/seeders/index.js +6 -60
  43. package/dist/node/sync/index.js +1 -332
  44. package/dist/node/sync/sync.enum.js +1 -26
  45. package/dist/node/sync/sync.operations.js +1 -321
  46. package/dist/node/sync/sync.presentation.js +1 -301
  47. package/dist/node/sync/sync.schema.js +1 -154
  48. package/dist/node/sync-engine/index.js +1 -186
  49. package/dist/node/tests/operations.test-spec.js +1 -85
  50. package/dist/node/ui/IntegrationDashboard.js +1 -886
  51. package/dist/node/ui/IntegrationDashboard.visualizations.js +1 -250
  52. package/dist/node/ui/IntegrationHubChat.js +1 -34
  53. package/dist/node/ui/hooks/index.js +1 -57
  54. package/dist/node/ui/hooks/useIntegrationData.js +1 -54
  55. package/dist/node/ui/index.js +4 -1173
  56. package/dist/node/ui/renderers/index.js +4 -484
  57. package/dist/node/ui/renderers/integration.markdown.js +4 -484
  58. package/dist/node/ui/tables/ConnectionsTable.js +1 -211
  59. package/dist/node/ui/tables/IntegrationTables.js +1 -361
  60. package/dist/node/ui/tables/SyncConfigsTable.js +1 -230
  61. package/dist/node/ui/tables/integration-table.shared.js +1 -84
  62. package/dist/node/visualizations/catalog.js +1 -137
  63. package/dist/node/visualizations/index.js +1 -211
  64. package/dist/node/visualizations/selectors.js +1 -204
  65. package/dist/run-mcp.js +1 -159
  66. package/dist/seeders/index.js +6 -60
  67. package/dist/sync/index.js +1 -332
  68. package/dist/sync/sync.enum.js +1 -26
  69. package/dist/sync/sync.operations.js +1 -321
  70. package/dist/sync/sync.presentation.js +1 -301
  71. package/dist/sync/sync.schema.js +1 -154
  72. package/dist/sync-engine/index.js +1 -186
  73. package/dist/tests/operations.test-spec.js +1 -85
  74. package/dist/ui/IntegrationDashboard.js +1 -886
  75. package/dist/ui/IntegrationDashboard.visualizations.js +1 -250
  76. package/dist/ui/IntegrationHubChat.js +1 -34
  77. package/dist/ui/hooks/index.js +1 -57
  78. package/dist/ui/hooks/useIntegrationData.js +1 -54
  79. package/dist/ui/index.js +4 -1173
  80. package/dist/ui/renderers/index.js +4 -484
  81. package/dist/ui/renderers/integration.markdown.js +4 -484
  82. package/dist/ui/tables/ConnectionsTable.js +1 -211
  83. package/dist/ui/tables/IntegrationTables.js +1 -361
  84. package/dist/ui/tables/SyncConfigsTable.js +1 -230
  85. package/dist/ui/tables/integration-table.shared.js +1 -84
  86. package/dist/visualizations/catalog.js +1 -137
  87. package/dist/visualizations/index.js +1 -211
  88. package/dist/visualizations/selectors.js +1 -204
  89. package/package.json +11 -11
@@ -1,211 +1 @@
1
- // src/events.ts
2
- import { defineEvent } from "@contractspec/lib.contracts-spec";
3
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
4
- var IntegrationCreatedPayload = defineSchemaModel({
5
- name: "IntegrationCreatedPayload",
6
- description: "Payload when an integration is created",
7
- fields: {
8
- integrationId: {
9
- type: ScalarTypeEnum.String_unsecure(),
10
- isOptional: false
11
- },
12
- type: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
13
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
14
- }
15
- });
16
- var IntegrationCreatedEvent = defineEvent({
17
- meta: {
18
- key: "integration.created",
19
- version: "1.0.0",
20
- description: "Fired when a new integration is created",
21
- stability: "experimental",
22
- owners: ["@integration-team"],
23
- tags: ["integration"]
24
- },
25
- payload: IntegrationCreatedPayload
26
- });
27
- var ConnectionCreatedPayload = defineSchemaModel({
28
- name: "ConnectionCreatedPayload",
29
- description: "Payload when a connection is established",
30
- fields: {
31
- connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
32
- integrationId: {
33
- type: ScalarTypeEnum.String_unsecure(),
34
- isOptional: false
35
- },
36
- status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
38
- }
39
- });
40
- var ConnectionCreatedEvent = defineEvent({
41
- meta: {
42
- key: "integration.connection.created",
43
- version: "1.0.0",
44
- description: "Fired when a new connection is established",
45
- stability: "experimental",
46
- owners: ["@integration-team"],
47
- tags: ["integration", "connection"]
48
- },
49
- payload: ConnectionCreatedPayload
50
- });
51
- var ConnectionStatusChangedPayload = defineSchemaModel({
52
- name: "ConnectionStatusChangedPayload",
53
- description: "Payload when a connection status changes",
54
- fields: {
55
- connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
56
- previousStatus: {
57
- type: ScalarTypeEnum.String_unsecure(),
58
- isOptional: false
59
- },
60
- newStatus: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
- changedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
62
- }
63
- });
64
- var ConnectionStatusChangedEvent = defineEvent({
65
- meta: {
66
- key: "integration.connection.statusChanged",
67
- version: "1.0.0",
68
- description: "Fired when a connection status changes",
69
- stability: "experimental",
70
- owners: ["@integration-team"],
71
- tags: ["integration", "connection"]
72
- },
73
- payload: ConnectionStatusChangedPayload
74
- });
75
- var SyncConfigCreatedPayload = defineSchemaModel({
76
- name: "SyncConfigCreatedPayload",
77
- description: "Payload when a sync configuration is created",
78
- fields: {
79
- syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
80
- connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
81
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
82
- }
83
- });
84
- var SyncConfigCreatedEvent = defineEvent({
85
- meta: {
86
- key: "integration.syncConfig.created",
87
- version: "1.0.0",
88
- description: "Fired when a sync configuration is created",
89
- stability: "experimental",
90
- owners: ["@integration-team"],
91
- tags: ["integration", "sync"]
92
- },
93
- payload: SyncConfigCreatedPayload
94
- });
95
- var SyncStartedPayload = defineSchemaModel({
96
- name: "SyncStartedPayload",
97
- description: "Payload when a sync run starts",
98
- fields: {
99
- syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
100
- syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
101
- startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
102
- }
103
- });
104
- var SyncStartedEvent = defineEvent({
105
- meta: {
106
- key: "integration.sync.started",
107
- version: "1.0.0",
108
- description: "Fired when a sync run starts",
109
- stability: "experimental",
110
- owners: ["@integration-team"],
111
- tags: ["integration", "sync"]
112
- },
113
- payload: SyncStartedPayload
114
- });
115
- var SyncCompletedPayload = defineSchemaModel({
116
- name: "SyncCompletedPayload",
117
- description: "Payload when a sync run completes successfully",
118
- fields: {
119
- syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
120
- syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
121
- recordsProcessed: {
122
- type: ScalarTypeEnum.Int_unsecure(),
123
- isOptional: false
124
- },
125
- completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
126
- }
127
- });
128
- var SyncCompletedEvent = defineEvent({
129
- meta: {
130
- key: "integration.sync.completed",
131
- version: "1.0.0",
132
- description: "Fired when a sync run completes successfully",
133
- stability: "experimental",
134
- owners: ["@integration-team"],
135
- tags: ["integration", "sync"]
136
- },
137
- payload: SyncCompletedPayload
138
- });
139
- var SyncFailedPayload = defineSchemaModel({
140
- name: "SyncFailedPayload",
141
- description: "Payload when a sync run fails",
142
- fields: {
143
- syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
144
- syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
145
- error: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
146
- failedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
147
- }
148
- });
149
- var SyncFailedEvent = defineEvent({
150
- meta: {
151
- key: "integration.sync.failed",
152
- version: "1.0.0",
153
- description: "Fired when a sync run fails",
154
- stability: "experimental",
155
- owners: ["@integration-team"],
156
- tags: ["integration", "sync"]
157
- },
158
- payload: SyncFailedPayload
159
- });
160
- var RecordSyncedPayload = defineSchemaModel({
161
- name: "RecordSyncedPayload",
162
- description: "Payload when a single record is synced",
163
- fields: {
164
- syncRunId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
165
- recordId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
166
- sourceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
167
- targetId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
168
- }
169
- });
170
- var RecordSyncedEvent = defineEvent({
171
- meta: {
172
- key: "integration.record.synced",
173
- version: "1.0.0",
174
- description: "Fired when a single record is synced",
175
- stability: "experimental",
176
- owners: ["@integration-team"],
177
- tags: ["integration", "sync"]
178
- },
179
- payload: RecordSyncedPayload
180
- });
181
- var FieldMappingAddedPayload = defineSchemaModel({
182
- name: "FieldMappingAddedPayload",
183
- description: "Payload when a field mapping is added to a sync config",
184
- fields: {
185
- syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
186
- sourceField: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
187
- targetField: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
188
- }
189
- });
190
- var FieldMappingAddedEvent = defineEvent({
191
- meta: {
192
- key: "integration.fieldMapping.added",
193
- version: "1.0.0",
194
- description: "Fired when a field mapping is added to a sync config",
195
- stability: "experimental",
196
- owners: ["@integration-team"],
197
- tags: ["integration", "sync"]
198
- },
199
- payload: FieldMappingAddedPayload
200
- });
201
- export {
202
- SyncStartedEvent,
203
- SyncFailedEvent,
204
- SyncConfigCreatedEvent,
205
- SyncCompletedEvent,
206
- RecordSyncedEvent,
207
- IntegrationCreatedEvent,
208
- FieldMappingAddedEvent,
209
- ConnectionStatusChangedEvent,
210
- ConnectionCreatedEvent
211
- };
1
+ 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};
@@ -1,42 +1 @@
1
- // src/example.ts
2
- import { defineExample } from "@contractspec/lib.contracts-spec";
3
- var example = defineExample({
4
- meta: {
5
- key: "integration-hub",
6
- version: "1.0.0",
7
- title: "Integration Hub",
8
- description: "Provider-agnostic integration center with connectors, connections, field mappings, and sync logs.",
9
- kind: "template",
10
- visibility: "public",
11
- stability: "experimental",
12
- owners: ["@platform.core"],
13
- tags: ["integrations", "sync", "etl", "connectors"]
14
- },
15
- docs: {
16
- rootDocId: "docs.examples.integration-hub",
17
- goalDocId: "docs.examples.integration-hub.goal",
18
- usageDocId: "docs.examples.integration-hub.usage",
19
- constraintsDocId: "docs.examples.integration-hub.constraints"
20
- },
21
- entrypoints: {
22
- packageName: "@contractspec/example.integration-hub",
23
- feature: "./feature",
24
- contracts: "./contracts",
25
- presentations: "./presentations",
26
- handlers: "./handlers",
27
- docs: "./docs"
28
- },
29
- surfaces: {
30
- templates: true,
31
- sandbox: {
32
- enabled: true,
33
- modes: ["playground", "specs", "builder", "markdown", "evolution"]
34
- },
35
- studio: { enabled: true, installable: true },
36
- mcp: { enabled: true }
37
- }
38
- });
39
- var example_default = example;
40
- export {
41
- example_default as default
42
- };
1
+ 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};
@@ -1,292 +1,5 @@
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
- async function validateByokKey(input) {
232
- const rows = (await db.query(`SELECT * FROM integration_connection WHERE id = ?`, [
233
- input.connectionId
234
- ])).rows;
235
- if (!rows[0]) {
236
- return {
237
- valid: false,
238
- provider: "unknown",
239
- keyPrefix: "",
240
- error: `Connection ${input.connectionId} not found`
241
- };
242
- }
243
- const keyPrefix = input.providerKey.slice(0, 8);
244
- const looksValid = input.providerKey.length >= 16;
245
- return {
246
- valid: looksValid,
247
- provider: rows[0].name,
248
- keyPrefix: `${keyPrefix}...`,
249
- expiresAt: looksValid ? new Date(Date.now() + 90 * 24 * 60 * 60 * 1000).toISOString() : undefined,
250
- error: looksValid ? undefined : "Key must be at least 16 characters"
251
- };
252
- }
253
- async function refreshOAuth2Token(input) {
254
- const now = new Date().toISOString();
255
- await db.execute(`UPDATE integration_connection SET updatedAt = ? WHERE id = ?`, [now, input.connectionId]);
256
- return {
257
- refreshed: true,
258
- expiresAt: new Date(Date.now() + 3600 * 1000).toISOString(),
259
- tokenType: "Bearer",
260
- scopes: ["read", "write", "sync"]
261
- };
262
- }
263
- async function getTransportOptions(input) {
264
- return {
265
- integrationId: input.integrationId,
266
- transports: [
267
- { transport: "rest", supported: true, defaultVersion: "v2" },
268
- { transport: "mcp", supported: true, defaultVersion: "v1" },
269
- { transport: "webhook", supported: true },
270
- { transport: "sdk", supported: false }
271
- ]
272
- };
273
- }
274
- return {
275
- listIntegrations,
276
- createIntegration,
277
- listConnections,
278
- connectService,
279
- disconnectService,
280
- listSyncConfigs,
281
- configureSync,
282
- mapFields,
283
- getFieldMappings,
284
- runSync,
285
- validateByokKey,
286
- refreshOAuth2Token,
287
- getTransportOptions
288
- };
289
- }
290
- export {
291
- createIntegrationHandlers
292
- };
1
+ 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)
2
+ 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)
3
+ 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)
4
+ 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)
5
+ 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};