@contractspec/example.integration-hub 3.8.8 → 3.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connection/connection.enum.js +1 -29
- package/dist/connection/connection.operation.js +1 -124
- package/dist/connection/connection.presentation.js +1 -125
- package/dist/connection/connection.schema.js +1 -71
- package/dist/connection/index.js +1 -127
- package/dist/docs/index.js +5 -49
- package/dist/docs/integration-hub.docblock.js +5 -49
- package/dist/events.js +1 -211
- package/dist/example.js +1 -42
- package/dist/handlers/index.js +5 -292
- package/dist/handlers/integration.handlers.js +5 -292
- package/dist/index.js +8 -2355
- package/dist/integration/index.js +1 -92
- package/dist/integration/integration.enum.js +1 -12
- package/dist/integration/integration.operations.js +1 -89
- package/dist/integration/integration.presentation.js +1 -120
- package/dist/integration/integration.schema.js +1 -42
- package/dist/integration-hub.capability.js +1 -43
- package/dist/integration-hub.feature.js +1 -330
- package/dist/mcp-example.js +1 -154
- package/dist/node/connection/connection.enum.js +1 -29
- package/dist/node/connection/connection.operation.js +1 -124
- package/dist/node/connection/connection.presentation.js +1 -125
- package/dist/node/connection/connection.schema.js +1 -71
- package/dist/node/connection/index.js +1 -127
- package/dist/node/docs/index.js +5 -49
- package/dist/node/docs/integration-hub.docblock.js +5 -49
- package/dist/node/events.js +1 -211
- package/dist/node/example.js +1 -42
- package/dist/node/handlers/index.js +5 -292
- package/dist/node/handlers/integration.handlers.js +5 -292
- package/dist/node/index.js +8 -2355
- package/dist/node/integration/index.js +1 -92
- package/dist/node/integration/integration.enum.js +1 -12
- package/dist/node/integration/integration.operations.js +1 -89
- package/dist/node/integration/integration.presentation.js +1 -120
- package/dist/node/integration/integration.schema.js +1 -42
- package/dist/node/integration-hub.capability.js +1 -43
- package/dist/node/integration-hub.feature.js +1 -330
- package/dist/node/mcp-example.js +1 -154
- package/dist/node/run-mcp.js +1 -159
- package/dist/node/seeders/index.js +6 -60
- package/dist/node/sync/index.js +1 -332
- package/dist/node/sync/sync.enum.js +1 -26
- package/dist/node/sync/sync.operations.js +1 -321
- package/dist/node/sync/sync.presentation.js +1 -301
- package/dist/node/sync/sync.schema.js +1 -154
- package/dist/node/sync-engine/index.js +1 -186
- package/dist/node/tests/operations.test-spec.js +1 -85
- package/dist/node/ui/IntegrationDashboard.js +1 -886
- package/dist/node/ui/IntegrationDashboard.visualizations.js +1 -250
- package/dist/node/ui/IntegrationHubChat.js +1 -34
- package/dist/node/ui/hooks/index.js +1 -57
- package/dist/node/ui/hooks/useIntegrationData.js +1 -54
- package/dist/node/ui/index.js +4 -1173
- package/dist/node/ui/renderers/index.js +4 -484
- package/dist/node/ui/renderers/integration.markdown.js +4 -484
- package/dist/node/ui/tables/ConnectionsTable.js +1 -211
- package/dist/node/ui/tables/IntegrationTables.js +1 -361
- package/dist/node/ui/tables/SyncConfigsTable.js +1 -230
- package/dist/node/ui/tables/integration-table.shared.js +1 -84
- package/dist/node/visualizations/catalog.js +1 -137
- package/dist/node/visualizations/index.js +1 -211
- package/dist/node/visualizations/selectors.js +1 -204
- package/dist/run-mcp.js +1 -159
- package/dist/seeders/index.js +6 -60
- package/dist/sync/index.js +1 -332
- package/dist/sync/sync.enum.js +1 -26
- package/dist/sync/sync.operations.js +1 -321
- package/dist/sync/sync.presentation.js +1 -301
- package/dist/sync/sync.schema.js +1 -154
- package/dist/sync-engine/index.js +1 -186
- package/dist/tests/operations.test-spec.js +1 -85
- package/dist/ui/IntegrationDashboard.js +1 -886
- package/dist/ui/IntegrationDashboard.visualizations.js +1 -250
- package/dist/ui/IntegrationHubChat.js +1 -34
- package/dist/ui/hooks/index.js +1 -57
- package/dist/ui/hooks/useIntegrationData.js +1 -54
- package/dist/ui/index.js +4 -1173
- package/dist/ui/renderers/index.js +4 -484
- package/dist/ui/renderers/integration.markdown.js +4 -484
- package/dist/ui/tables/ConnectionsTable.js +1 -211
- package/dist/ui/tables/IntegrationTables.js +1 -361
- package/dist/ui/tables/SyncConfigsTable.js +1 -230
- package/dist/ui/tables/integration-table.shared.js +1 -84
- package/dist/visualizations/catalog.js +1 -137
- package/dist/visualizations/index.js +1 -211
- package/dist/visualizations/selectors.js +1 -204
- package/package.json +14 -14
package/dist/sync/sync.schema.js
CHANGED
|
@@ -1,155 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEnum } from "@contractspec/lib.schema";
|
|
4
|
-
var SyncDirectionEnum = defineEnum("SyncDirection", [
|
|
5
|
-
"INBOUND",
|
|
6
|
-
"OUTBOUND",
|
|
7
|
-
"BIDIRECTIONAL"
|
|
8
|
-
]);
|
|
9
|
-
var SyncStatusEnum = defineEnum("SyncStatus", [
|
|
10
|
-
"PENDING",
|
|
11
|
-
"RUNNING",
|
|
12
|
-
"COMPLETED",
|
|
13
|
-
"FAILED",
|
|
14
|
-
"CANCELLED"
|
|
15
|
-
]);
|
|
16
|
-
var MappingTypeEnum = defineEnum("MappingType", [
|
|
17
|
-
"DIRECT",
|
|
18
|
-
"TRANSFORM",
|
|
19
|
-
"LOOKUP",
|
|
20
|
-
"CONSTANT",
|
|
21
|
-
"COMPUTED"
|
|
22
|
-
]);
|
|
23
|
-
|
|
24
|
-
// src/sync/sync.schema.ts
|
|
25
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
26
|
-
var FieldMappingModel = defineSchemaModel({
|
|
27
|
-
name: "FieldMappingModel",
|
|
28
|
-
fields: {
|
|
29
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
30
|
-
sourceField: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
31
|
-
targetField: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
32
|
-
mappingType: { type: MappingTypeEnum, isOptional: false },
|
|
33
|
-
transformExpression: {
|
|
34
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
35
|
-
isOptional: true
|
|
36
|
-
},
|
|
37
|
-
isRequired: { type: ScalarTypeEnum.Boolean(), isOptional: false }
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
var SyncConfigModel = defineSchemaModel({
|
|
41
|
-
name: "SyncConfigModel",
|
|
42
|
-
fields: {
|
|
43
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
44
|
-
integrationId: {
|
|
45
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
46
|
-
isOptional: false
|
|
47
|
-
},
|
|
48
|
-
connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
49
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
50
|
-
direction: { type: SyncDirectionEnum, isOptional: false },
|
|
51
|
-
sourceObject: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
52
|
-
targetObject: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
53
|
-
scheduleEnabled: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
54
|
-
scheduleCron: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
55
|
-
isActive: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
56
|
-
lastSyncAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
57
|
-
fieldMappings: { type: FieldMappingModel, isArray: true, isOptional: true }
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
var SyncRunModel = defineSchemaModel({
|
|
61
|
-
name: "SyncRunModel",
|
|
62
|
-
fields: {
|
|
63
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
64
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
65
|
-
status: { type: SyncStatusEnum, isOptional: false },
|
|
66
|
-
direction: { type: SyncDirectionEnum, isOptional: false },
|
|
67
|
-
trigger: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
68
|
-
recordsProcessed: {
|
|
69
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
70
|
-
isOptional: false
|
|
71
|
-
},
|
|
72
|
-
recordsCreated: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
73
|
-
recordsUpdated: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
74
|
-
recordsFailed: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
75
|
-
errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
76
|
-
startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
77
|
-
completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
78
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
var CreateSyncConfigInputModel = defineSchemaModel({
|
|
82
|
-
name: "CreateSyncConfigInput",
|
|
83
|
-
fields: {
|
|
84
|
-
integrationId: {
|
|
85
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
86
|
-
isOptional: false
|
|
87
|
-
},
|
|
88
|
-
connectionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
89
|
-
name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
90
|
-
direction: { type: SyncDirectionEnum, isOptional: false },
|
|
91
|
-
sourceObject: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
92
|
-
targetObject: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
93
|
-
scheduleEnabled: { type: ScalarTypeEnum.Boolean(), isOptional: true },
|
|
94
|
-
scheduleCron: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
var AddFieldMappingInputModel = defineSchemaModel({
|
|
98
|
-
name: "AddFieldMappingInput",
|
|
99
|
-
fields: {
|
|
100
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
101
|
-
sourceField: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
102
|
-
targetField: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
103
|
-
mappingType: { type: MappingTypeEnum, isOptional: false },
|
|
104
|
-
transformExpression: {
|
|
105
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
106
|
-
isOptional: true
|
|
107
|
-
},
|
|
108
|
-
lookupConfig: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
109
|
-
constantValue: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
110
|
-
isRequired: { type: ScalarTypeEnum.Boolean(), isOptional: true },
|
|
111
|
-
defaultValue: { type: ScalarTypeEnum.JSON(), isOptional: true }
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
var TriggerSyncInputModel = defineSchemaModel({
|
|
115
|
-
name: "TriggerSyncInput",
|
|
116
|
-
fields: {
|
|
117
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
118
|
-
direction: { type: SyncDirectionEnum, isOptional: true },
|
|
119
|
-
fullSync: { type: ScalarTypeEnum.Boolean(), isOptional: true }
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
var ListSyncRunsInputModel = defineSchemaModel({
|
|
123
|
-
name: "ListSyncRunsInput",
|
|
124
|
-
fields: {
|
|
125
|
-
syncConfigId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
126
|
-
status: { type: SyncStatusEnum, isOptional: true },
|
|
127
|
-
limit: {
|
|
128
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
129
|
-
isOptional: true,
|
|
130
|
-
defaultValue: 20
|
|
131
|
-
},
|
|
132
|
-
offset: {
|
|
133
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
134
|
-
isOptional: true,
|
|
135
|
-
defaultValue: 0
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
var ListSyncRunsOutputModel = defineSchemaModel({
|
|
140
|
-
name: "ListSyncRunsOutput",
|
|
141
|
-
fields: {
|
|
142
|
-
runs: { type: SyncRunModel, isArray: true, isOptional: false },
|
|
143
|
-
total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
export {
|
|
147
|
-
TriggerSyncInputModel,
|
|
148
|
-
SyncRunModel,
|
|
149
|
-
SyncConfigModel,
|
|
150
|
-
ListSyncRunsOutputModel,
|
|
151
|
-
ListSyncRunsInputModel,
|
|
152
|
-
FieldMappingModel,
|
|
153
|
-
CreateSyncConfigInputModel,
|
|
154
|
-
AddFieldMappingInputModel
|
|
155
|
-
};
|
|
2
|
+
import{defineEnum as C}from"@contractspec/lib.schema";var I=C("SyncDirection",["INBOUND","OUTBOUND","BIDIRECTIONAL"]),D=C("SyncStatus",["PENDING","RUNNING","COMPLETED","FAILED","CANCELLED"]),L=C("MappingType",["DIRECT","TRANSFORM","LOOKUP","CONSTANT","COMPUTED"]);import{defineSchemaModel as O,ScalarTypeEnum as N}from"@contractspec/lib.schema";var U=O({name:"FieldMappingModel",fields:{id:{type:N.String_unsecure(),isOptional:!1},sourceField:{type:N.String_unsecure(),isOptional:!1},targetField:{type:N.String_unsecure(),isOptional:!1},mappingType:{type:L,isOptional:!1},transformExpression:{type:N.String_unsecure(),isOptional:!0},isRequired:{type:N.Boolean(),isOptional:!1}}}),G=O({name:"SyncConfigModel",fields:{id:{type:N.String_unsecure(),isOptional:!1},integrationId:{type:N.String_unsecure(),isOptional:!1},connectionId:{type:N.String_unsecure(),isOptional:!1},name:{type:N.String_unsecure(),isOptional:!1},direction:{type:I,isOptional:!1},sourceObject:{type:N.String_unsecure(),isOptional:!1},targetObject:{type:N.String_unsecure(),isOptional:!1},scheduleEnabled:{type:N.Boolean(),isOptional:!1},scheduleCron:{type:N.String_unsecure(),isOptional:!0},isActive:{type:N.Boolean(),isOptional:!1},lastSyncAt:{type:N.DateTime(),isOptional:!0},fieldMappings:{type:U,isArray:!0,isOptional:!0}}}),A=O({name:"SyncRunModel",fields:{id:{type:N.String_unsecure(),isOptional:!1},syncConfigId:{type:N.String_unsecure(),isOptional:!1},status:{type:D,isOptional:!1},direction:{type:I,isOptional:!1},trigger:{type:N.String_unsecure(),isOptional:!1},recordsProcessed:{type:N.Int_unsecure(),isOptional:!1},recordsCreated:{type:N.Int_unsecure(),isOptional:!1},recordsUpdated:{type:N.Int_unsecure(),isOptional:!1},recordsFailed:{type:N.Int_unsecure(),isOptional:!1},errorMessage:{type:N.String_unsecure(),isOptional:!0},startedAt:{type:N.DateTime(),isOptional:!0},completedAt:{type:N.DateTime(),isOptional:!0},createdAt:{type:N.DateTime(),isOptional:!1}}}),F=O({name:"CreateSyncConfigInput",fields:{integrationId:{type:N.String_unsecure(),isOptional:!1},connectionId:{type:N.String_unsecure(),isOptional:!1},name:{type:N.NonEmptyString(),isOptional:!1},direction:{type:I,isOptional:!1},sourceObject:{type:N.NonEmptyString(),isOptional:!1},targetObject:{type:N.NonEmptyString(),isOptional:!1},scheduleEnabled:{type:N.Boolean(),isOptional:!0},scheduleCron:{type:N.String_unsecure(),isOptional:!0}}}),K=O({name:"AddFieldMappingInput",fields:{syncConfigId:{type:N.String_unsecure(),isOptional:!1},sourceField:{type:N.NonEmptyString(),isOptional:!1},targetField:{type:N.NonEmptyString(),isOptional:!1},mappingType:{type:L,isOptional:!1},transformExpression:{type:N.String_unsecure(),isOptional:!0},lookupConfig:{type:N.JSON(),isOptional:!0},constantValue:{type:N.JSON(),isOptional:!0},isRequired:{type:N.Boolean(),isOptional:!0},defaultValue:{type:N.JSON(),isOptional:!0}}}),j=O({name:"TriggerSyncInput",fields:{syncConfigId:{type:N.String_unsecure(),isOptional:!1},direction:{type:I,isOptional:!0},fullSync:{type:N.Boolean(),isOptional:!0}}}),k=O({name:"ListSyncRunsInput",fields:{syncConfigId:{type:N.String_unsecure(),isOptional:!1},status:{type:D,isOptional:!0},limit:{type:N.Int_unsecure(),isOptional:!0,defaultValue:20},offset:{type:N.Int_unsecure(),isOptional:!0,defaultValue:0}}}),q=O({name:"ListSyncRunsOutput",fields:{runs:{type:A,isArray:!0,isOptional:!1},total:{type:N.Int_unsecure(),isOptional:!1}}});export{j as TriggerSyncInputModel,A as SyncRunModel,G as SyncConfigModel,q as ListSyncRunsOutputModel,k as ListSyncRunsInputModel,U as FieldMappingModel,F as CreateSyncConfigInputModel,K as AddFieldMappingInputModel};
|
|
@@ -1,187 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
class BasicFieldTransformer {
|
|
4
|
-
transform(value, expression) {
|
|
5
|
-
try {
|
|
6
|
-
if (expression.startsWith("uppercase")) {
|
|
7
|
-
return typeof value === "string" ? value.toUpperCase() : value;
|
|
8
|
-
}
|
|
9
|
-
if (expression.startsWith("lowercase")) {
|
|
10
|
-
return typeof value === "string" ? value.toLowerCase() : value;
|
|
11
|
-
}
|
|
12
|
-
if (expression.startsWith("trim")) {
|
|
13
|
-
return typeof value === "string" ? value.trim() : value;
|
|
14
|
-
}
|
|
15
|
-
if (expression.startsWith("default:")) {
|
|
16
|
-
const defaultVal = expression.replace("default:", "");
|
|
17
|
-
return value ?? JSON.parse(defaultVal);
|
|
18
|
-
}
|
|
19
|
-
if (expression.startsWith("concat:")) {
|
|
20
|
-
const separator = expression.replace("concat:", "") || " ";
|
|
21
|
-
if (Array.isArray(value)) {
|
|
22
|
-
return value.join(separator);
|
|
23
|
-
}
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
if (expression.startsWith("split:")) {
|
|
27
|
-
const separator = expression.replace("split:", "") || ",";
|
|
28
|
-
if (typeof value === "string") {
|
|
29
|
-
return value.split(separator);
|
|
30
|
-
}
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
if (expression.startsWith("number")) {
|
|
34
|
-
return Number(value);
|
|
35
|
-
}
|
|
36
|
-
if (expression.startsWith("boolean")) {
|
|
37
|
-
return Boolean(value);
|
|
38
|
-
}
|
|
39
|
-
if (expression.startsWith("string")) {
|
|
40
|
-
return String(value);
|
|
41
|
-
}
|
|
42
|
-
return value;
|
|
43
|
-
} catch {
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class BasicSyncEngine {
|
|
50
|
-
transformer;
|
|
51
|
-
constructor(transformer) {
|
|
52
|
-
this.transformer = transformer ?? new BasicFieldTransformer;
|
|
53
|
-
}
|
|
54
|
-
async sync(_context) {
|
|
55
|
-
const result = {
|
|
56
|
-
success: true,
|
|
57
|
-
recordsProcessed: 0,
|
|
58
|
-
recordsCreated: 0,
|
|
59
|
-
recordsUpdated: 0,
|
|
60
|
-
recordsDeleted: 0,
|
|
61
|
-
recordsFailed: 0,
|
|
62
|
-
recordsSkipped: 0,
|
|
63
|
-
errors: []
|
|
64
|
-
};
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
transformRecord(sourceRecord, mappings, _context) {
|
|
68
|
-
const targetData = {};
|
|
69
|
-
for (const mapping of mappings) {
|
|
70
|
-
let value;
|
|
71
|
-
let sourceValue;
|
|
72
|
-
switch (mapping.mappingType) {
|
|
73
|
-
case "DIRECT":
|
|
74
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
75
|
-
break;
|
|
76
|
-
case "TRANSFORM":
|
|
77
|
-
sourceValue = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
78
|
-
value = mapping.transformExpression ? this.transformer.transform(sourceValue, mapping.transformExpression) : sourceValue;
|
|
79
|
-
break;
|
|
80
|
-
case "CONSTANT":
|
|
81
|
-
value = mapping.constantValue;
|
|
82
|
-
break;
|
|
83
|
-
case "LOOKUP":
|
|
84
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
85
|
-
break;
|
|
86
|
-
case "COMPUTED":
|
|
87
|
-
value = mapping.transformExpression ? this.evaluateComputed(sourceRecord.data, mapping.transformExpression) : null;
|
|
88
|
-
break;
|
|
89
|
-
default:
|
|
90
|
-
value = this.getNestedValue(sourceRecord.data, mapping.sourceField);
|
|
91
|
-
}
|
|
92
|
-
if (value === undefined || value === null) {
|
|
93
|
-
value = mapping.defaultValue;
|
|
94
|
-
}
|
|
95
|
-
this.setNestedValue(targetData, mapping.targetField, value);
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
id: sourceRecord.id,
|
|
99
|
-
data: targetData
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
validateRecord(record, mappings) {
|
|
103
|
-
const errors = [];
|
|
104
|
-
for (const mapping of mappings) {
|
|
105
|
-
if (mapping.isRequired) {
|
|
106
|
-
const value = this.getNestedValue(record.data, mapping.targetField);
|
|
107
|
-
if (value === undefined || value === null) {
|
|
108
|
-
errors.push({
|
|
109
|
-
recordId: record.id,
|
|
110
|
-
field: mapping.targetField,
|
|
111
|
-
message: `Required field ${mapping.targetField} is missing`,
|
|
112
|
-
code: "REQUIRED_FIELD_MISSING"
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
valid: errors.length === 0,
|
|
119
|
-
errors
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
getNestedValue(obj, path) {
|
|
123
|
-
const parts = path.split(".");
|
|
124
|
-
let current = obj;
|
|
125
|
-
for (const part of parts) {
|
|
126
|
-
if (current === null || current === undefined) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
current = current[part];
|
|
130
|
-
}
|
|
131
|
-
return current;
|
|
132
|
-
}
|
|
133
|
-
setNestedValue(obj, path, value) {
|
|
134
|
-
const parts = path.split(".");
|
|
135
|
-
let current = obj;
|
|
136
|
-
for (let i = 0;i < parts.length - 1; i++) {
|
|
137
|
-
const part = parts[i];
|
|
138
|
-
if (part === undefined)
|
|
139
|
-
continue;
|
|
140
|
-
if (!(part in current)) {
|
|
141
|
-
current[part] = {};
|
|
142
|
-
}
|
|
143
|
-
current = current[part];
|
|
144
|
-
}
|
|
145
|
-
const lastPart = parts[parts.length - 1];
|
|
146
|
-
if (lastPart !== undefined) {
|
|
147
|
-
current[lastPart] = value;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
evaluateComputed(data, expression) {
|
|
151
|
-
try {
|
|
152
|
-
const result = expression.replace(/\$\{([^}]+)\}/g, (_, path) => {
|
|
153
|
-
const value = this.getNestedValue(data, path);
|
|
154
|
-
return String(value ?? "");
|
|
155
|
-
});
|
|
156
|
-
return result;
|
|
157
|
-
} catch {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function createSyncEngine(transformer) {
|
|
163
|
-
return new BasicSyncEngine(transformer);
|
|
164
|
-
}
|
|
165
|
-
function computeChecksum(data) {
|
|
166
|
-
const str = JSON.stringify(data, Object.keys(data).sort());
|
|
167
|
-
let hash = 0;
|
|
168
|
-
for (let i = 0;i < str.length; i++) {
|
|
169
|
-
const char = str.charCodeAt(i);
|
|
170
|
-
hash = (hash << 5) - hash + char;
|
|
171
|
-
hash = hash & hash;
|
|
172
|
-
}
|
|
173
|
-
return hash.toString(16);
|
|
174
|
-
}
|
|
175
|
-
function hasChanges(sourceChecksum, targetChecksum) {
|
|
176
|
-
if (!sourceChecksum || !targetChecksum) {
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
return sourceChecksum !== targetChecksum;
|
|
180
|
-
}
|
|
181
|
-
export {
|
|
182
|
-
hasChanges,
|
|
183
|
-
createSyncEngine,
|
|
184
|
-
computeChecksum,
|
|
185
|
-
BasicSyncEngine,
|
|
186
|
-
BasicFieldTransformer
|
|
187
|
-
};
|
|
2
|
+
class L{transform(q,w){try{if(w.startsWith("uppercase"))return typeof q==="string"?q.toUpperCase():q;if(w.startsWith("lowercase"))return typeof q==="string"?q.toLowerCase():q;if(w.startsWith("trim"))return typeof q==="string"?q.trim():q;if(w.startsWith("default:")){let A=w.replace("default:","");return q??JSON.parse(A)}if(w.startsWith("concat:")){let A=w.replace("concat:","")||" ";if(Array.isArray(q))return q.join(A);return q}if(w.startsWith("split:")){let A=w.replace("split:","")||",";if(typeof q==="string")return q.split(A);return q}if(w.startsWith("number"))return Number(q);if(w.startsWith("boolean"))return Boolean(q);if(w.startsWith("string"))return String(q);return q}catch{return q}}}class M{transformer;constructor(q){this.transformer=q??new L}async sync(q){return{success:!0,recordsProcessed:0,recordsCreated:0,recordsUpdated:0,recordsDeleted:0,recordsFailed:0,recordsSkipped:0,errors:[]}}transformRecord(q,w,A){let G={};for(let z of w){let H,J;switch(z.mappingType){case"DIRECT":H=this.getNestedValue(q.data,z.sourceField);break;case"TRANSFORM":J=this.getNestedValue(q.data,z.sourceField),H=z.transformExpression?this.transformer.transform(J,z.transformExpression):J;break;case"CONSTANT":H=z.constantValue;break;case"LOOKUP":H=this.getNestedValue(q.data,z.sourceField);break;case"COMPUTED":H=z.transformExpression?this.evaluateComputed(q.data,z.transformExpression):null;break;default:H=this.getNestedValue(q.data,z.sourceField)}if(H===void 0||H===null)H=z.defaultValue;this.setNestedValue(G,z.targetField,H)}return{id:q.id,data:G}}validateRecord(q,w){let A=[];for(let G of w)if(G.isRequired){let z=this.getNestedValue(q.data,G.targetField);if(z===void 0||z===null)A.push({recordId:q.id,field:G.targetField,message:`Required field ${G.targetField} is missing`,code:"REQUIRED_FIELD_MISSING"})}return{valid:A.length===0,errors:A}}getNestedValue(q,w){let A=w.split("."),G=q;for(let z of A){if(G===null||G===void 0)return;G=G[z]}return G}setNestedValue(q,w,A){let G=w.split("."),z=q;for(let J=0;J<G.length-1;J++){let K=G[J];if(K===void 0)continue;if(!(K in z))z[K]={};z=z[K]}let H=G[G.length-1];if(H!==void 0)z[H]=A}evaluateComputed(q,w){try{return w.replace(/\$\{([^}]+)\}/g,(G,z)=>{let H=this.getNestedValue(q,z);return String(H??"")})}catch{return null}}}function N(q){return new M(q)}function O(q){let w=JSON.stringify(q,Object.keys(q).sort()),A=0;for(let G=0;G<w.length;G++){let z=w.charCodeAt(G);A=(A<<5)-A+z,A=A&A}return A.toString(16)}function Q(q,w){if(!q||!w)return!0;return q!==w}export{Q as hasChanges,N as createSyncEngine,O as computeChecksum,M as BasicSyncEngine,L as BasicFieldTransformer};
|
|
@@ -1,86 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineTestSpec } from "@contractspec/lib.contracts-spec/tests";
|
|
4
|
-
var SyncConfigCreateTest = defineTestSpec({
|
|
5
|
-
meta: {
|
|
6
|
-
key: "integration.syncConfig.create.test",
|
|
7
|
-
version: "1.0.0",
|
|
8
|
-
stability: "experimental",
|
|
9
|
-
owners: ["@example.integration-hub"],
|
|
10
|
-
description: "Test for creating sync config",
|
|
11
|
-
tags: ["test"]
|
|
12
|
-
},
|
|
13
|
-
target: {
|
|
14
|
-
type: "operation",
|
|
15
|
-
operation: { key: "integration.syncConfig.create", version: "1.0.0" }
|
|
16
|
-
},
|
|
17
|
-
scenarios: [
|
|
18
|
-
{
|
|
19
|
-
key: "success",
|
|
20
|
-
when: { operation: { key: "integration.syncConfig.create" } },
|
|
21
|
-
then: [{ type: "expectOutput", match: {} }]
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
key: "error",
|
|
25
|
-
when: { operation: { key: "integration.syncConfig.create" } },
|
|
26
|
-
then: [{ type: "expectError" }]
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
});
|
|
30
|
-
var FieldMappingAddTest = defineTestSpec({
|
|
31
|
-
meta: {
|
|
32
|
-
key: "integration.fieldMapping.add.test",
|
|
33
|
-
version: "1.0.0",
|
|
34
|
-
stability: "experimental",
|
|
35
|
-
owners: ["@example.integration-hub"],
|
|
36
|
-
description: "Test for adding field mapping",
|
|
37
|
-
tags: ["test"]
|
|
38
|
-
},
|
|
39
|
-
target: {
|
|
40
|
-
type: "operation",
|
|
41
|
-
operation: { key: "integration.fieldMapping.add", version: "1.0.0" }
|
|
42
|
-
},
|
|
43
|
-
scenarios: [
|
|
44
|
-
{
|
|
45
|
-
key: "success",
|
|
46
|
-
when: { operation: { key: "integration.fieldMapping.add" } },
|
|
47
|
-
then: [{ type: "expectOutput", match: {} }]
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
key: "error",
|
|
51
|
-
when: { operation: { key: "integration.fieldMapping.add" } },
|
|
52
|
-
then: [{ type: "expectError" }]
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
});
|
|
56
|
-
var SyncRunListTest = defineTestSpec({
|
|
57
|
-
meta: {
|
|
58
|
-
key: "integration.syncRun.list.test",
|
|
59
|
-
version: "1.0.0",
|
|
60
|
-
stability: "experimental",
|
|
61
|
-
owners: ["@example.integration-hub"],
|
|
62
|
-
description: "Test for listing sync runs",
|
|
63
|
-
tags: ["test"]
|
|
64
|
-
},
|
|
65
|
-
target: {
|
|
66
|
-
type: "operation",
|
|
67
|
-
operation: { key: "integration.syncRun.list", version: "1.0.0" }
|
|
68
|
-
},
|
|
69
|
-
scenarios: [
|
|
70
|
-
{
|
|
71
|
-
key: "success",
|
|
72
|
-
when: { operation: { key: "integration.syncRun.list" } },
|
|
73
|
-
then: [{ type: "expectOutput", match: {} }]
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
key: "error",
|
|
77
|
-
when: { operation: { key: "integration.syncRun.list" } },
|
|
78
|
-
then: [{ type: "expectError" }]
|
|
79
|
-
}
|
|
80
|
-
]
|
|
81
|
-
});
|
|
82
|
-
export {
|
|
83
|
-
SyncRunListTest,
|
|
84
|
-
SyncConfigCreateTest,
|
|
85
|
-
FieldMappingAddTest
|
|
86
|
-
};
|
|
2
|
+
import{defineTestSpec as g}from"@contractspec/lib.contracts-spec/tests";var j=g({meta:{key:"integration.syncConfig.create.test",version:"1.0.0",stability:"experimental",owners:["@example.integration-hub"],description:"Test for creating sync config",tags:["test"]},target:{type:"operation",operation:{key:"integration.syncConfig.create",version:"1.0.0"}},scenarios:[{key:"success",when:{operation:{key:"integration.syncConfig.create"}},then:[{type:"expectOutput",match:{}}]},{key:"error",when:{operation:{key:"integration.syncConfig.create"}},then:[{type:"expectError"}]}]}),k=g({meta:{key:"integration.fieldMapping.add.test",version:"1.0.0",stability:"experimental",owners:["@example.integration-hub"],description:"Test for adding field mapping",tags:["test"]},target:{type:"operation",operation:{key:"integration.fieldMapping.add",version:"1.0.0"}},scenarios:[{key:"success",when:{operation:{key:"integration.fieldMapping.add"}},then:[{type:"expectOutput",match:{}}]},{key:"error",when:{operation:{key:"integration.fieldMapping.add"}},then:[{type:"expectError"}]}]}),m=g({meta:{key:"integration.syncRun.list.test",version:"1.0.0",stability:"experimental",owners:["@example.integration-hub"],description:"Test for listing sync runs",tags:["test"]},target:{type:"operation",operation:{key:"integration.syncRun.list",version:"1.0.0"}},scenarios:[{key:"success",when:{operation:{key:"integration.syncRun.list"}},then:[{type:"expectOutput",match:{}}]},{key:"error",when:{operation:{key:"integration.syncRun.list"}},then:[{type:"expectError"}]}]});export{m as SyncRunListTest,j as SyncConfigCreateTest,k as FieldMappingAddTest};
|