@skedulo/integration-sdk 0.1.2 → 0.2.0
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/CHANGELOG.md +6 -0
- package/README.md +59 -3
- package/dist/adapters/base.adapter.d.ts +61 -0
- package/dist/adapters/base.adapter.d.ts.map +1 -0
- package/dist/adapters/base.adapter.js +69 -0
- package/dist/adapters/base.adapter.js.map +1 -0
- package/dist/adapters/skedulo.adapter.d.ts +8 -0
- package/dist/adapters/skedulo.adapter.d.ts.map +1 -1
- package/dist/adapters/skedulo.adapter.js +77 -4
- package/dist/adapters/skedulo.adapter.js.map +1 -1
- package/dist/browser.d.ts +3 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +3 -1
- package/dist/browser.js.map +1 -1
- package/dist/clients/dataflow.client.d.ts +1 -1
- package/dist/clients/dataflow.client.d.ts.map +1 -1
- package/dist/clients/dataflow.client.js +6 -4
- package/dist/clients/dataflow.client.js.map +1 -1
- package/dist/clients/proxy.client.d.ts +1 -0
- package/dist/clients/proxy.client.d.ts.map +1 -1
- package/dist/clients/proxy.client.js +5 -1
- package/dist/clients/proxy.client.js.map +1 -1
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +14 -1
- package/dist/constants.js.map +1 -1
- package/dist/context.d.ts +7 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces/adapter.interface.d.ts +53 -19
- package/dist/interfaces/adapter.interface.d.ts.map +1 -1
- package/dist/interfaces/field-mapping.interface.d.ts +10 -5
- package/dist/interfaces/field-mapping.interface.d.ts.map +1 -1
- package/dist/interfaces/integration-capabilities.interface.d.ts +6 -0
- package/dist/interfaces/integration-capabilities.interface.d.ts.map +1 -1
- package/dist/interfaces/sync-flow-strategy.interface.d.ts +15 -0
- package/dist/interfaces/sync-flow-strategy.interface.d.ts.map +1 -0
- package/dist/interfaces/sync-flow-strategy.interface.js +3 -0
- package/dist/interfaces/sync-flow-strategy.interface.js.map +1 -0
- package/dist/interfaces/sync-pipeline.interface.d.ts +108 -0
- package/dist/interfaces/sync-pipeline.interface.d.ts.map +1 -0
- package/dist/interfaces/sync-pipeline.interface.js +12 -0
- package/dist/interfaces/sync-pipeline.interface.js.map +1 -0
- package/dist/services/external-id-sync.strategy.d.ts +13 -0
- package/dist/services/external-id-sync.strategy.d.ts.map +1 -0
- package/dist/services/external-id-sync.strategy.js +139 -0
- package/dist/services/external-id-sync.strategy.js.map +1 -0
- package/dist/services/field-mapping.service.d.ts +31 -0
- package/dist/services/field-mapping.service.d.ts.map +1 -0
- package/dist/services/field-mapping.service.js +131 -0
- package/dist/services/field-mapping.service.js.map +1 -0
- package/dist/services/id-mapping-sync.strategy.d.ts +19 -0
- package/dist/services/id-mapping-sync.strategy.d.ts.map +1 -0
- package/dist/services/id-mapping-sync.strategy.js +389 -0
- package/dist/services/id-mapping-sync.strategy.js.map +1 -0
- package/dist/services/id-mapping.service.d.ts +38 -0
- package/dist/services/id-mapping.service.d.ts.map +1 -0
- package/dist/services/id-mapping.service.js +207 -0
- package/dist/services/id-mapping.service.js.map +1 -0
- package/dist/services/preview.service.js +2 -2
- package/dist/services/preview.service.js.map +1 -1
- package/dist/services/sync-runner.d.ts +3 -0
- package/dist/services/sync-runner.d.ts.map +1 -1
- package/dist/services/sync-runner.js +22 -7
- package/dist/services/sync-runner.js.map +1 -1
- package/dist/services/sync.service.d.ts +3 -2
- package/dist/services/sync.service.d.ts.map +1 -1
- package/dist/services/sync.service.js +55 -109
- package/dist/services/sync.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdMappingService = void 0;
|
|
4
|
+
const pulse_solution_services_1 = require("@skedulo/pulse-solution-services");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const MAPPING_OBJECT_NAME = 'IntegrationIdMapping';
|
|
8
|
+
const MAPPING_FIELDS = [
|
|
9
|
+
{ name: 'SourceSystem', label: 'Source System', maxLength: 64 },
|
|
10
|
+
{ name: 'TargetSystem', label: 'Target System', maxLength: 64 },
|
|
11
|
+
{ name: 'ObjectType', label: 'Object Type', maxLength: 128 },
|
|
12
|
+
{ name: 'SourceId', label: 'Source ID', maxLength: 512 },
|
|
13
|
+
{ name: 'TargetId', label: 'Target ID', maxLength: 512 },
|
|
14
|
+
{ name: 'UniqueKey', label: 'Unique Key', maxLength: 768, unique: true },
|
|
15
|
+
{ name: 'DataFlowId', label: 'Data Flow ID', maxLength: 64 },
|
|
16
|
+
];
|
|
17
|
+
function buildFieldPayload(spec) {
|
|
18
|
+
var _a;
|
|
19
|
+
return {
|
|
20
|
+
metadata: { type: 'CustomField' },
|
|
21
|
+
objectName: MAPPING_OBJECT_NAME,
|
|
22
|
+
name: spec.name,
|
|
23
|
+
field: {
|
|
24
|
+
type: 'String',
|
|
25
|
+
description: spec.label,
|
|
26
|
+
display: {
|
|
27
|
+
label: spec.label,
|
|
28
|
+
order: 0,
|
|
29
|
+
isAlert: false,
|
|
30
|
+
showIf: null,
|
|
31
|
+
showOnDesktop: true,
|
|
32
|
+
showOnMobile: false,
|
|
33
|
+
editableOnMobile: false,
|
|
34
|
+
requiredOnMobile: false,
|
|
35
|
+
},
|
|
36
|
+
constraints: {
|
|
37
|
+
required: false,
|
|
38
|
+
unique: (_a = spec.unique) !== null && _a !== void 0 ? _a : false,
|
|
39
|
+
accessMode: 'ReadWrite',
|
|
40
|
+
maxLength: spec.maxLength,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
class IdMappingService {
|
|
46
|
+
/**
|
|
47
|
+
* Batch query: resolve source IDs to target IDs across multiple object types.
|
|
48
|
+
* Returns a map keyed by 'ObjectType:sourceId'.
|
|
49
|
+
*/
|
|
50
|
+
async resolve(ctx, queries) {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
const result = new Map();
|
|
53
|
+
for (const query of queries) {
|
|
54
|
+
const { sourceSystem, targetSystem, objectType, sourceIds } = query;
|
|
55
|
+
if (sourceIds.length === 0)
|
|
56
|
+
continue;
|
|
57
|
+
for (const chunkIds of chunkArray(sourceIds, constants_1.LOOKUP_CHUNK_SIZE)) {
|
|
58
|
+
const list = chunkIds.map((id) => `'${(0, utils_1.escapeEqlString)(id)}'`).join(', ');
|
|
59
|
+
const filter = [
|
|
60
|
+
`SourceSystem == '${(0, utils_1.escapeEqlString)(sourceSystem)}'`,
|
|
61
|
+
`TargetSystem == '${(0, utils_1.escapeEqlString)(targetSystem)}'`,
|
|
62
|
+
`ObjectType == '${(0, utils_1.escapeEqlString)(objectType)}'`,
|
|
63
|
+
`SourceId IN [${list}]`,
|
|
64
|
+
].join(' AND ');
|
|
65
|
+
const builder = ctx.newQueryBuilder({
|
|
66
|
+
objectName: MAPPING_OBJECT_NAME,
|
|
67
|
+
operationName: constants_1.OperationName.MAPPING_RESOLVE,
|
|
68
|
+
readOnly: true,
|
|
69
|
+
});
|
|
70
|
+
const queryResult = await builder
|
|
71
|
+
.withFields(['SourceId', 'TargetId'])
|
|
72
|
+
.withFilter(filter)
|
|
73
|
+
.withLimit(chunkIds.length)
|
|
74
|
+
.execute();
|
|
75
|
+
for (const record of (_a = queryResult.records) !== null && _a !== void 0 ? _a : []) {
|
|
76
|
+
const r = record;
|
|
77
|
+
const sourceId = String((_b = r['SourceId']) !== null && _b !== void 0 ? _b : '');
|
|
78
|
+
const targetId = String((_c = r['TargetId']) !== null && _c !== void 0 ? _c : '');
|
|
79
|
+
if (sourceId && targetId) {
|
|
80
|
+
result.set(`${objectType}:${sourceId}`, targetId);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** Idempotent write — upserts on UniqueKey. */
|
|
88
|
+
async upsertMappings(ctx, entries) {
|
|
89
|
+
if (entries.length === 0)
|
|
90
|
+
return;
|
|
91
|
+
const records = entries.map((e) => (Object.assign({ SourceSystem: e.sourceSystem, TargetSystem: e.targetSystem, ObjectType: e.objectType, SourceId: e.sourceId, TargetId: e.targetId, UniqueKey: buildUniqueKey(e) }, (e.dataFlowId ? { DataFlowId: e.dataFlowId } : {}))));
|
|
92
|
+
await ctx.graphqlService.upsert({
|
|
93
|
+
objectName: MAPPING_OBJECT_NAME,
|
|
94
|
+
operationName: constants_1.OperationName.MAPPING_UPSERT,
|
|
95
|
+
records,
|
|
96
|
+
keyField: 'UniqueKey',
|
|
97
|
+
bulkOperation: true,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/** Delete mapping entries for a given set of source IDs. Called after a successful target delete. */
|
|
101
|
+
async deleteMappings(ctx, params) {
|
|
102
|
+
var _a;
|
|
103
|
+
const { sourceSystem, targetSystem, objectType, sourceIds } = params;
|
|
104
|
+
if (sourceIds.length === 0)
|
|
105
|
+
return;
|
|
106
|
+
for (const chunkIds of chunkArray(sourceIds, constants_1.LOOKUP_CHUNK_SIZE)) {
|
|
107
|
+
const list = chunkIds.map((id) => `'${(0, utils_1.escapeEqlString)(id)}'`).join(', ');
|
|
108
|
+
const filter = [
|
|
109
|
+
`SourceSystem == '${(0, utils_1.escapeEqlString)(sourceSystem)}'`,
|
|
110
|
+
`TargetSystem == '${(0, utils_1.escapeEqlString)(targetSystem)}'`,
|
|
111
|
+
`ObjectType == '${(0, utils_1.escapeEqlString)(objectType)}'`,
|
|
112
|
+
`SourceId IN [${list}]`,
|
|
113
|
+
].join(' AND ');
|
|
114
|
+
const builder = ctx.newQueryBuilder({
|
|
115
|
+
objectName: MAPPING_OBJECT_NAME,
|
|
116
|
+
operationName: constants_1.OperationName.MAPPING_DELETE_LOOKUP,
|
|
117
|
+
readOnly: true,
|
|
118
|
+
});
|
|
119
|
+
const result = await builder
|
|
120
|
+
.withFields(['UID'])
|
|
121
|
+
.withFilter(filter)
|
|
122
|
+
.withLimit(chunkIds.length)
|
|
123
|
+
.execute();
|
|
124
|
+
const uids = ((_a = result.records) !== null && _a !== void 0 ? _a : []).map((r) => ({ UID: r.UID })).filter((r) => r.UID);
|
|
125
|
+
if (uids.length === 0)
|
|
126
|
+
continue;
|
|
127
|
+
await ctx.graphqlService.delete({
|
|
128
|
+
objectName: MAPPING_OBJECT_NAME,
|
|
129
|
+
operationName: constants_1.OperationName.MAPPING_DELETE,
|
|
130
|
+
records: uids,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Bulk cleanup when a flow is deleted. Paginated so large mapping tables don't OOM. */
|
|
135
|
+
async deleteByDataFlowId(ctx, dataFlowId) {
|
|
136
|
+
var _a, _b;
|
|
137
|
+
let lastUID = null;
|
|
138
|
+
while (true) {
|
|
139
|
+
const clauses = [`DataFlowId == '${(0, utils_1.escapeEqlString)(dataFlowId)}'`];
|
|
140
|
+
if (lastUID)
|
|
141
|
+
clauses.push(`UID > '${(0, utils_1.escapeEqlString)(lastUID)}'`);
|
|
142
|
+
const builder = ctx.newQueryBuilder({
|
|
143
|
+
objectName: MAPPING_OBJECT_NAME,
|
|
144
|
+
operationName: constants_1.OperationName.MAPPING_FLOW_DELETE,
|
|
145
|
+
});
|
|
146
|
+
const result = await builder
|
|
147
|
+
.withFields(['UID'])
|
|
148
|
+
.withFilter(clauses.join(' AND '))
|
|
149
|
+
.withLimit(constants_1.LOOKUP_CHUNK_SIZE)
|
|
150
|
+
.withOrderBy('UID ASC')
|
|
151
|
+
.execute();
|
|
152
|
+
const records = ((_a = result.records) !== null && _a !== void 0 ? _a : []);
|
|
153
|
+
if (records.length === 0)
|
|
154
|
+
break;
|
|
155
|
+
await ctx.graphqlService.delete({
|
|
156
|
+
objectName: MAPPING_OBJECT_NAME,
|
|
157
|
+
operationName: constants_1.OperationName.MAPPING_DELETE,
|
|
158
|
+
records: records.map((r) => ({ UID: r.UID })),
|
|
159
|
+
});
|
|
160
|
+
if (records.length < constants_1.LOOKUP_CHUNK_SIZE)
|
|
161
|
+
break;
|
|
162
|
+
lastUID = String((_b = records[records.length - 1].UID) !== null && _b !== void 0 ? _b : '');
|
|
163
|
+
if (!lastUID)
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Idempotent schema bootstrap. Checks before creating — safe to call on every /setup request.
|
|
169
|
+
* Must be called from the integration's /setup endpoint before any idMapping flows run.
|
|
170
|
+
*/
|
|
171
|
+
static async ensureSchema(ctx) {
|
|
172
|
+
const objectClient = ctx.newArtifactClient(pulse_solution_services_1.ArtifactType.CUSTOM_OBJECT);
|
|
173
|
+
const existing = await objectClient
|
|
174
|
+
.get({ name: MAPPING_OBJECT_NAME })
|
|
175
|
+
.catch(() => null);
|
|
176
|
+
if (!existing) {
|
|
177
|
+
await objectClient.upsert({}, {
|
|
178
|
+
metadata: { type: 'CustomObject' },
|
|
179
|
+
name: MAPPING_OBJECT_NAME,
|
|
180
|
+
label: 'Integration ID Mapping',
|
|
181
|
+
description: 'Cross-system record ID store for integration flows',
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
const fieldClient = ctx.newArtifactClient(pulse_solution_services_1.ArtifactType.CUSTOM_FIELD);
|
|
185
|
+
for (const fieldSpec of MAPPING_FIELDS) {
|
|
186
|
+
const existingField = await fieldClient
|
|
187
|
+
.get({ objectName: MAPPING_OBJECT_NAME, name: fieldSpec.name })
|
|
188
|
+
.catch(() => null);
|
|
189
|
+
if (!existingField) {
|
|
190
|
+
// No path params — the objectName is in the body payload.
|
|
191
|
+
// POST to artifacts/custom-field (not /custom-field/IntegrationIdMapping).
|
|
192
|
+
await fieldClient.upsert({}, buildFieldPayload(fieldSpec));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.IdMappingService = IdMappingService;
|
|
198
|
+
function buildUniqueKey(e) {
|
|
199
|
+
return `${e.sourceSystem}_${e.targetSystem}_${e.objectType}_${e.sourceId}`;
|
|
200
|
+
}
|
|
201
|
+
function chunkArray(arr, size) {
|
|
202
|
+
const out = [];
|
|
203
|
+
for (let i = 0; i < arr.length; i += size)
|
|
204
|
+
out.push(arr.slice(i, i + size));
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=id-mapping.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-mapping.service.js","sourceRoot":"","sources":["../../src/services/id-mapping.service.ts"],"names":[],"mappings":";;;AAAA,8EAAgE;AAEhE,4CAAgE;AAChE,oCAA2C;AAW3C,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AASnD,MAAM,cAAc,GAAgB;IAClC,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,EAAE;IAC/D,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,EAAE;IAC/D,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE;IAC5D,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE;IACxD,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE;IACxD,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IACxE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,EAAE;CAC7D,CAAC;AAEF,SAAS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G,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI;QAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC5E,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PreviewService = void 0;
|
|
4
|
-
const
|
|
4
|
+
const field_mapping_service_1 = require("./field-mapping.service");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
class PreviewService {
|
|
7
7
|
async run(args, ctx) {
|
|
@@ -15,7 +15,7 @@ class PreviewService {
|
|
|
15
15
|
const results = [];
|
|
16
16
|
for (const record of samples) {
|
|
17
17
|
try {
|
|
18
|
-
const result = await (0,
|
|
18
|
+
const result = await (0, field_mapping_service_1.executeMappingDetailed)(flow, record);
|
|
19
19
|
switch (result.status) {
|
|
20
20
|
case 'filtered':
|
|
21
21
|
results.push({ sourceRecord: record, targetRecord: null, status: 'filtered_out' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.service.js","sourceRoot":"","sources":["../../src/services/preview.service.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"preview.service.js","sourceRoot":"","sources":["../../src/services/preview.service.ts"],"names":[],"mappings":";;;AACA,mEAAiE;AAEjE,4CAA6C;AAE7C,MAAa,cAAc;IACzB,KAAK,CAAC,GAAG,CACP,IAKC,EACD,GAAuB;;QAEvB,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,UAAU,YAAY,CAAC,CAAC;QAEpE,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,aAAa,mC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,IAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;wBACxF,MAAM;gBACV,CAAC;YACH,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC;oBACX,YAAY,EAAE,MAAM;oBACpB,YAAY,EAAE,IAAI;oBAClB,MAAM,EAAE,iBAAiB;oBACzB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;iBACzB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAxDD,wCAwDC;AAED,KAAK,UAAU,oBAAoB,CACjC,IAAc,EACd,IAAY,EACZ,GAAuB;IAEvB,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;IAC9F,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,GAAG;SACrB,eAAe,CAAC;QACf,UAAU,EAAE,IAAI,CAAC,YAAY;QAC7B,aAAa,EAAE,yBAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,QAAQ,EAAE,IAAI;KACf,CAAC;SACD,SAAS,CAAC,IAAI,CAAC;SACf,OAAO,EAAE,CAAC;IACb,OAAO,MAAM,CAAC,OAAoC,CAAC;AACrD,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -2,6 +2,7 @@ import type { IntegrationContext } from '../context';
|
|
|
2
2
|
import type { Adapter } from '../interfaces/adapter.interface';
|
|
3
3
|
import type { MappedEvent } from '../interfaces/mapped-event.interface';
|
|
4
4
|
import type { BatchResult, SyncResult } from '../interfaces/sync-result.interface';
|
|
5
|
+
import type { SyncRunOptions } from '../interfaces/sync-flow-strategy.interface';
|
|
5
6
|
export declare class AdapterNotRegisteredError extends Error {
|
|
6
7
|
constructor(systemName: string);
|
|
7
8
|
}
|
|
@@ -13,9 +14,11 @@ export declare class SyncRunner {
|
|
|
13
14
|
since: Date | null;
|
|
14
15
|
sourceSystem?: string;
|
|
15
16
|
targetSystem?: string;
|
|
17
|
+
options?: SyncRunOptions;
|
|
16
18
|
}, ctx: IntegrationContext): Promise<BatchResult>;
|
|
17
19
|
handleEvent(args: {
|
|
18
20
|
event: MappedEvent;
|
|
21
|
+
options?: SyncRunOptions;
|
|
19
22
|
}, ctx: IntegrationContext): Promise<SyncResult[]>;
|
|
20
23
|
private _resolve;
|
|
21
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-runner.d.ts","sourceRoot":"","sources":["../../src/services/sync-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-runner.d.ts","sourceRoot":"","sources":["../../src/services/sync-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,4CAA4C,CAAC;AA+BnG,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,UAAU,EAAE,MAAM;CAI/B;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IAEvD,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAQ9C,GAAG,CACP,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,OAAO,CAAC,EAAE,cAAc,CAAC;KAC1B,EACD,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,WAAW,CAAC;IAyBjB,WAAW,CACf,IAAI,EAAE;QAAE,KAAK,EAAE,WAAW,CAAC;QAAC,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,EACtD,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,UAAU,EAAE,CAAC;IA0CxB,OAAO,CAAC,QAAQ;CAMjB"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SyncRunner = exports.AdapterNotRegisteredError = void 0;
|
|
4
|
+
const external_id_sync_strategy_1 = require("./external-id-sync.strategy");
|
|
5
|
+
const id_mapping_sync_strategy_1 = require("./id-mapping-sync.strategy");
|
|
6
|
+
const id_mapping_service_1 = require("./id-mapping.service");
|
|
4
7
|
const sync_service_1 = require("./sync.service");
|
|
5
8
|
// SyncRunner is the high-level entry point for integration packages.
|
|
6
9
|
//
|
|
@@ -8,6 +11,7 @@ const sync_service_1 = require("./sync.service");
|
|
|
8
11
|
// - Adapter registration (keyed by system name, e.g. 'hubspot', 'skedulo')
|
|
9
12
|
// - Flow fetch by ID or by filter (for event-driven paths)
|
|
10
13
|
// - Adapter resolution from flow.sourceSystem / flow.targetSystem
|
|
14
|
+
// - Strategy creation based on SyncRunOptions.lookupStrategy
|
|
11
15
|
// - Delegation to SyncService for the actual pipeline
|
|
12
16
|
//
|
|
13
17
|
// Integration packages register their adapters at startup, then call
|
|
@@ -17,11 +21,14 @@ const sync_service_1 = require("./sync.service");
|
|
|
17
21
|
// runner.register('hubspot', new HubSpotAdapter())
|
|
18
22
|
// runner.register('skedulo', new SkeduloAdapter())
|
|
19
23
|
//
|
|
20
|
-
// // Scheduled / Run Now:
|
|
24
|
+
// // Scheduled / Run Now (ExternalId strategy — default):
|
|
21
25
|
// await runner.run({ flowId, since }, ctx)
|
|
22
26
|
//
|
|
23
|
-
// //
|
|
24
|
-
// await runner.
|
|
27
|
+
// // Scheduled / Run Now (IdMapping strategy):
|
|
28
|
+
// await runner.run({ flowId, since, options: { lookupStrategy: 'idMapping' } }, ctx)
|
|
29
|
+
//
|
|
30
|
+
// // Event-driven:
|
|
31
|
+
// await runner.handleEvent({ event, options: { lookupStrategy: 'idMapping' } }, ctx)
|
|
25
32
|
class AdapterNotRegisteredError extends Error {
|
|
26
33
|
constructor(systemName) {
|
|
27
34
|
super(`adapter not registered for system: "${systemName}"`);
|
|
@@ -41,7 +48,7 @@ class SyncRunner {
|
|
|
41
48
|
// sourceSystem / targetSystem fallbacks are used when the flow's own values are null
|
|
42
49
|
// (e.g. flows created before these columns were added to the schema).
|
|
43
50
|
async run(args, ctx) {
|
|
44
|
-
var _a, _b, _c, _d;
|
|
51
|
+
var _a, _b, _c, _d, _e;
|
|
45
52
|
try {
|
|
46
53
|
const flow = await ctx.dataFlowService.getFlowById(args.flowId);
|
|
47
54
|
if (!flow) {
|
|
@@ -50,7 +57,8 @@ class SyncRunner {
|
|
|
50
57
|
}
|
|
51
58
|
const source = this._resolve((_b = (_a = flow.sourceSystem) !== null && _a !== void 0 ? _a : args.sourceSystem) !== null && _b !== void 0 ? _b : null);
|
|
52
59
|
const target = this._resolve((_d = (_c = flow.targetSystem) !== null && _c !== void 0 ? _c : args.targetSystem) !== null && _d !== void 0 ? _d : null);
|
|
53
|
-
|
|
60
|
+
const strategy = createSyncStrategy((_e = args.options) !== null && _e !== void 0 ? _e : {}, ctx);
|
|
61
|
+
return new sync_service_1.SyncService(source, target, strategy).run({ flow, since: args.since }, ctx);
|
|
54
62
|
}
|
|
55
63
|
catch (err) {
|
|
56
64
|
if (err instanceof AdapterNotRegisteredError) {
|
|
@@ -65,7 +73,7 @@ class SyncRunner {
|
|
|
65
73
|
// executionOrder (nulls last), and processes each sequentially so that a failure
|
|
66
74
|
// in one flow doesn't prevent the others from running.
|
|
67
75
|
async handleEvent(args, ctx) {
|
|
68
|
-
var _a;
|
|
76
|
+
var _a, _b;
|
|
69
77
|
const { event } = args;
|
|
70
78
|
const flows = await ctx.dataFlowService.getFlowsByFilter({
|
|
71
79
|
integrationType: event.integrationType,
|
|
@@ -80,7 +88,8 @@ class SyncRunner {
|
|
|
80
88
|
for (const flow of sorted) {
|
|
81
89
|
try {
|
|
82
90
|
const target = this._resolve((_a = flow.targetSystem) !== null && _a !== void 0 ? _a : null);
|
|
83
|
-
const
|
|
91
|
+
const strategy = createSyncStrategy((_b = args.options) !== null && _b !== void 0 ? _b : {}, ctx);
|
|
92
|
+
const result = await new sync_service_1.SyncService(null, target, strategy).handleEvent({ event, flow }, ctx);
|
|
84
93
|
results.push(result);
|
|
85
94
|
}
|
|
86
95
|
catch (err) {
|
|
@@ -107,4 +116,10 @@ class SyncRunner {
|
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
exports.SyncRunner = SyncRunner;
|
|
119
|
+
function createSyncStrategy(options, _ctx) {
|
|
120
|
+
if (options.lookupStrategy === 'idMapping') {
|
|
121
|
+
return new id_mapping_sync_strategy_1.IdMappingSyncStrategy(new id_mapping_service_1.IdMappingService());
|
|
122
|
+
}
|
|
123
|
+
return new external_id_sync_strategy_1.ExternalIdSyncStrategy();
|
|
124
|
+
}
|
|
110
125
|
//# sourceMappingURL=sync-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-runner.js","sourceRoot":"","sources":["../../src/services/sync-runner.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"sync-runner.js","sourceRoot":"","sources":["../../src/services/sync-runner.ts"],"names":[],"mappings":";;;AAKA,2EAAqE;AACrE,yEAAmE;AACnE,6DAAwD;AACxD,iDAA6C;AAE7C,qEAAqE;AACrE,EAAE;AACF,WAAW;AACX,6EAA6E;AAC7E,6DAA6D;AAC7D,oEAAoE;AACpE,+DAA+D;AAC/D,wDAAwD;AACxD,EAAE;AACF,qEAAqE;AACrE,oEAAoE;AACpE,EAAE;AACF,8BAA8B;AAC9B,qDAAqD;AACrD,qDAAqD;AACrD,EAAE;AACF,4DAA4D;AAC5D,6CAA6C;AAC7C,EAAE;AACF,iDAAiD;AACjD,uFAAuF;AACvF,EAAE;AACF,qBAAqB;AACrB,uFAAuF;AAEvF,MAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,UAAkB;QAC5B,KAAK,CAAC,uCAAuC,UAAU,GAAG,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AALD,8DAKC;AAED,MAAa,UAAU;IAAvB;QACmB,aAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IA+FzD,CAAC;IA7FC,QAAQ,CAAC,UAAkB,EAAE,OAAgB;QAC3C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,0CAA0C;IAC1C,6EAA6E;IAC7E,qFAAqF;IACrF,sEAAsE;IACtE,KAAK,CAAC,GAAG,CACP,IAMC,EACD,GAAuB;;QAEvB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,IAAI,CAAC,MAAM,YAAY,CAAC,CAAC;gBACl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CAAC;IACD,OAAO,IAAI,kDAAsB,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -3,10 +3,12 @@ import type { Adapter } from '../interfaces/adapter.interface';
|
|
|
3
3
|
import type { DataFlow } from '../interfaces/data-flow-spec.interface';
|
|
4
4
|
import type { MappedEvent } from '../interfaces/mapped-event.interface';
|
|
5
5
|
import type { BatchResult, SyncResult } from '../interfaces/sync-result.interface';
|
|
6
|
+
import type { SyncFlowStrategy } from '../interfaces/sync-flow-strategy.interface';
|
|
6
7
|
export declare class SyncService {
|
|
7
8
|
private readonly source;
|
|
8
9
|
private readonly target;
|
|
9
|
-
|
|
10
|
+
private readonly strategy;
|
|
11
|
+
constructor(source: Adapter | null, target: Adapter, strategy?: SyncFlowStrategy);
|
|
10
12
|
run(args: {
|
|
11
13
|
flow: DataFlow;
|
|
12
14
|
since: Date | null;
|
|
@@ -16,6 +18,5 @@ export declare class SyncService {
|
|
|
16
18
|
flow: DataFlow;
|
|
17
19
|
}, ctx: IntegrationContext): Promise<SyncResult>;
|
|
18
20
|
processBatch(flow: DataFlow, records: Record<string, unknown>[], ctx: IntegrationContext): Promise<BatchResult>;
|
|
19
|
-
private _processBatch;
|
|
20
21
|
}
|
|
21
22
|
//# sourceMappingURL=sync.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.service.d.ts","sourceRoot":"","sources":["../../src/services/sync.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"sync.service.d.ts","sourceRoot":"","sources":["../../src/services/sync.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAuBnF,qBAAa,WAAW;IAIpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;gBAGzB,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,MAAM,EAAE,OAAO,EAChC,QAAQ,CAAC,EAAE,gBAAgB;IAOvB,GAAG,CACP,IAAI,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,EAC5C,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,WAAW,CAAC;IA2CjB,WAAW,CACf,IAAI,EAAE;QAAE,KAAK,EAAE,WAAW,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,EAC5C,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,UAAU,CAAC;IAiBhB,YAAY,CAChB,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClC,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,WAAW,CAAC;CAaxB"}
|
|
@@ -8,32 +8,39 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.SyncService = void 0;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
const constants_1 = require("../constants");
|
|
12
|
+
const base_adapter_1 = require("../adapters/base.adapter");
|
|
13
|
+
const external_id_sync_strategy_1 = require("./external-id-sync.strategy");
|
|
14
|
+
// SyncService runs one DataFlow using a source adapter, target adapter, and an injected strategy.
|
|
14
15
|
//
|
|
15
16
|
// Two entrypoints:
|
|
16
17
|
//
|
|
17
18
|
// run({ flow, since }, ctx)
|
|
18
|
-
// Scheduled/batch: source.fetch →
|
|
19
|
-
// → target.resolveLookups? → source.enrich? → target.upsert
|
|
20
|
-
// source may be null when the caller provides records directly.
|
|
19
|
+
// Scheduled/batch: source.fetch → strategy.processBatch
|
|
21
20
|
//
|
|
22
21
|
// handleEvent({ event, flow }, ctx)
|
|
23
|
-
// Event-driven:
|
|
24
|
-
//
|
|
22
|
+
// Event-driven: strategy.handleDeleteEvent or strategy.handleUpsertEvent
|
|
23
|
+
//
|
|
24
|
+
// The fetch loop lives here (same for all strategies).
|
|
25
|
+
// All batch logic, lookup resolution, and write-back are delegated to the strategy.
|
|
25
26
|
//
|
|
26
27
|
// Constructor:
|
|
27
|
-
// source
|
|
28
|
-
// target
|
|
28
|
+
// source — adapter that fetches from the source system (null for event-driven)
|
|
29
|
+
// target — adapter that writes to the destination system
|
|
30
|
+
// strategy — injected by SyncRunner; selects ExternalId or IdMapping behaviour
|
|
29
31
|
class SyncService {
|
|
30
|
-
constructor(source, target) {
|
|
32
|
+
constructor(source, target, strategy) {
|
|
31
33
|
this.source = source;
|
|
32
34
|
this.target = target;
|
|
35
|
+
this.strategy = strategy !== null && strategy !== void 0 ? strategy : new external_id_sync_strategy_1.ExternalIdSyncStrategy();
|
|
36
|
+
if (source instanceof base_adapter_1.BaseAdapter)
|
|
37
|
+
source._initRole(constants_1.AdapterRole.SOURCE);
|
|
38
|
+
if (target instanceof base_adapter_1.BaseAdapter)
|
|
39
|
+
target._initRole(constants_1.AdapterRole.TARGET);
|
|
33
40
|
}
|
|
34
41
|
async run(args, ctx) {
|
|
35
42
|
var _a, e_1, _b, _c;
|
|
36
|
-
var _d, _e;
|
|
43
|
+
var _d, _e, _f, _g;
|
|
37
44
|
if (!((_d = this.source) === null || _d === void 0 ? void 0 : _d.fetch)) {
|
|
38
45
|
throw new Error('SyncService.run requires a source adapter with fetch()');
|
|
39
46
|
}
|
|
@@ -41,131 +48,70 @@ class SyncService {
|
|
|
41
48
|
const totals = { succeeded: 0, filtered: 0, failed: 0, dlqWrites: 0 };
|
|
42
49
|
const localFilter = (_e = flow.filter) !== null && _e !== void 0 ? _e : null;
|
|
43
50
|
try {
|
|
44
|
-
for (var
|
|
45
|
-
_c =
|
|
46
|
-
|
|
51
|
+
for (var _h = true, _j = __asyncValues(this.source.fetch(ctx, flow, since, localFilter)), _k; _k = await _j.next(), _a = _k.done, !_a; _h = true) {
|
|
52
|
+
_c = _k.value;
|
|
53
|
+
_h = false;
|
|
47
54
|
const batch = _c;
|
|
48
55
|
if (!batch || batch.length === 0)
|
|
49
56
|
continue;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
// Initialize pipeline state for this batch. Strategies and hooks update it in place.
|
|
58
|
+
ctx.pipeline = _initPipeline(flow, localFilter, batch, constants_1.SyncMode.BATCH, since);
|
|
59
|
+
// Step 2: beforeMap — adapter transforms raw records and adds synthetic/computed fields.
|
|
60
|
+
await ((_g = (_f = this.source).beforeMap) === null || _g === void 0 ? void 0 : _g.call(_f, ctx));
|
|
61
|
+
const stats = await this.strategy.processBatch(ctx, flow, this.source, this.target, ctx.pipeline.data.map((p) => p.raw), localFilter);
|
|
54
62
|
totals.succeeded += stats.succeeded;
|
|
55
63
|
totals.filtered += stats.filtered;
|
|
56
64
|
totals.failed += stats.failed;
|
|
57
65
|
totals.dlqWrites += stats.dlqWrites;
|
|
66
|
+
ctx.pipeline = undefined;
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
61
70
|
finally {
|
|
62
71
|
try {
|
|
63
|
-
if (!
|
|
72
|
+
if (!_h && !_a && (_b = _j.return)) await _b.call(_j);
|
|
64
73
|
}
|
|
65
74
|
finally { if (e_1) throw e_1.error; }
|
|
66
75
|
}
|
|
67
76
|
return totals;
|
|
68
77
|
}
|
|
69
78
|
async handleEvent(args, ctx) {
|
|
70
|
-
var _a
|
|
79
|
+
var _a;
|
|
71
80
|
const { event, flow } = args;
|
|
81
|
+
ctx.pipeline = _initPipeline(flow, (_a = flow.filter) !== null && _a !== void 0 ? _a : null, [event.payload], constants_1.SyncMode.EVENT, null);
|
|
82
|
+
let result;
|
|
72
83
|
if (event.operation === 'DELETE') {
|
|
73
|
-
await this.
|
|
74
|
-
return { status: 'synced', recordsProcessed: 1 };
|
|
75
|
-
}
|
|
76
|
-
const mapped = await (0, mapping_service_1.executeMapping)(flow, event.payload);
|
|
77
|
-
if (!mapped) {
|
|
78
|
-
return { status: 'filtered', recordsProcessed: 0 };
|
|
84
|
+
result = await this.strategy.handleDeleteEvent(ctx, flow, this.target, event.recordId);
|
|
79
85
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (outcome.status === 'ok') {
|
|
83
|
-
return { status: 'synced', recordsProcessed: 1 };
|
|
86
|
+
else {
|
|
87
|
+
result = await this.strategy.handleUpsertEvent(ctx, flow, this.source, this.target, event);
|
|
84
88
|
}
|
|
85
|
-
ctx.
|
|
86
|
-
|
|
87
|
-
return { status: 'failed', recordsProcessed: 0, error: (_b = outcome.error) !== null && _b !== void 0 ? _b : outcome.status };
|
|
89
|
+
ctx.pipeline = undefined;
|
|
90
|
+
return result;
|
|
88
91
|
}
|
|
89
92
|
// Exposed for tests / direct batch processing.
|
|
90
93
|
async processBatch(flow, records, ctx) {
|
|
91
|
-
var _a;
|
|
92
|
-
return this._processBatch(flow, records, (_a = flow.filter) !== null && _a !== void 0 ? _a : null, ctx);
|
|
93
|
-
}
|
|
94
|
-
async _processBatch(flow, records, localFilter, ctx) {
|
|
95
94
|
var _a, _b;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (localFilter)
|
|
99
|
-
(0, compileFilter_1.compileFilter)(localFilter);
|
|
100
|
-
const stats = { succeeded: 0, filtered: 0, failed: 0, dlqWrites: 0 };
|
|
101
|
-
const pairs = [];
|
|
102
|
-
for (const record of records) {
|
|
103
|
-
if (localFilter && !(await (0, mapping_service_1.evaluateFilter)(localFilter, record))) {
|
|
104
|
-
stats.filtered++;
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
try {
|
|
108
|
-
const mapped = await (0, mapping_service_1.applyMapping)(flow, record);
|
|
109
|
-
if (!mapped) {
|
|
110
|
-
stats.filtered++;
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
pairs.push({ raw: record, mapped });
|
|
114
|
-
stats.succeeded++;
|
|
115
|
-
}
|
|
116
|
-
catch (err) {
|
|
117
|
-
stats.failed++;
|
|
118
|
-
ctx.logger.error(`dlq_write: dataFlowId=${flow.id} error=${err instanceof Error ? err.message : String(err)}`);
|
|
119
|
-
stats.dlqWrites++;
|
|
120
|
-
}
|
|
95
|
+
if (!ctx.pipeline) {
|
|
96
|
+
ctx.pipeline = _initPipeline(flow, (_a = flow.filter) !== null && _a !== void 0 ? _a : null, records, constants_1.SyncMode.BATCH, null);
|
|
121
97
|
}
|
|
122
|
-
|
|
123
|
-
return stats;
|
|
124
|
-
// Resolve lookups via target adapter (e.g. Skedulo ExternalId → UID)
|
|
125
|
-
if (this.target.resolveLookups) {
|
|
126
|
-
try {
|
|
127
|
-
await this.target.resolveLookups(ctx, flow, pairs);
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
ctx.logger.error(`lookup_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
131
|
-
stats.failed += stats.succeeded;
|
|
132
|
-
stats.succeeded = 0;
|
|
133
|
-
return stats;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// Optional enrich from source adapter after lookups resolved
|
|
137
|
-
let toUpsert;
|
|
138
|
-
if ((_a = this.source) === null || _a === void 0 ? void 0 : _a.enrich) {
|
|
139
|
-
try {
|
|
140
|
-
toUpsert = await this.source.enrich(ctx, flow, pairs);
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
ctx.logger.error(`enrich_failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
144
|
-
stats.failed += stats.succeeded;
|
|
145
|
-
stats.succeeded = 0;
|
|
146
|
-
return stats;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
toUpsert = pairs.map((p) => p.mapped);
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
const outcomes = await this.target.upsert(ctx, flow, toUpsert);
|
|
154
|
-
for (let i = 0; i < outcomes.length; i++) {
|
|
155
|
-
if (outcomes[i].status !== 'ok') {
|
|
156
|
-
ctx.logger.error(`upsert_failed: dataFlowId=${flow.id} class=${outcomes[i].status} error=${(_b = outcomes[i].error) !== null && _b !== void 0 ? _b : 'unknown'}`);
|
|
157
|
-
stats.succeeded--;
|
|
158
|
-
stats.failed++;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
catch (err) {
|
|
163
|
-
ctx.logger.error(`batch_upsert_failed: dataFlowId=${flow.id} error=${err instanceof Error ? err.message : String(err)}`);
|
|
164
|
-
stats.failed += stats.succeeded;
|
|
165
|
-
stats.succeeded = 0;
|
|
166
|
-
}
|
|
167
|
-
return stats;
|
|
98
|
+
return this.strategy.processBatch(ctx, flow, this.source, this.target, records, (_b = flow.filter) !== null && _b !== void 0 ? _b : null);
|
|
168
99
|
}
|
|
169
100
|
}
|
|
170
101
|
exports.SyncService = SyncService;
|
|
102
|
+
function _initPipeline(flow, filter, records, syncMode, since) {
|
|
103
|
+
return {
|
|
104
|
+
flow,
|
|
105
|
+
filter: filter !== null && filter !== void 0 ? filter : null,
|
|
106
|
+
syncMode,
|
|
107
|
+
since,
|
|
108
|
+
data: records.map((raw) => ({ raw, mapped: {} })),
|
|
109
|
+
outcomes: [],
|
|
110
|
+
deleteIds: [],
|
|
111
|
+
stats: { succeeded: 0, filtered: 0, failed: 0, dlqWrites: 0 },
|
|
112
|
+
errors: [],
|
|
113
|
+
failedAtStage: null,
|
|
114
|
+
meta: {},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
171
117
|
//# sourceMappingURL=sync.service.js.map
|