@oondemand/oon-core-back 0.3.67 → 0.3.68
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/package.json
CHANGED
|
@@ -46,6 +46,11 @@ function normalizeList(definition = {}, index = 0) {
|
|
|
46
46
|
statusCode: 422,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
if (definition.filter !== undefined && typeof definition.filter !== "function") {
|
|
50
|
+
throw new GenericError(`O filtro da lista Omie ${key} deve ser uma função.`, {
|
|
51
|
+
statusCode: 422,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
49
54
|
if (!definition.call) {
|
|
50
55
|
throw new GenericError(`A lista Omie ${key} deve referenciar uma chamada declarada.`, {
|
|
51
56
|
statusCode: 422,
|
|
@@ -180,6 +185,7 @@ function describeOmieDefinitions(definitions = collectOmieDefinitions()) {
|
|
|
180
185
|
direction: list.direction,
|
|
181
186
|
targetModel: list.target.model,
|
|
182
187
|
externalKey: list.target.externalKey,
|
|
188
|
+
filtered: typeof list.filter === "function",
|
|
183
189
|
policies: list.policies,
|
|
184
190
|
schedule: list.schedule || null,
|
|
185
191
|
order: list.order,
|
|
@@ -108,6 +108,21 @@ function effectiveListMode(list, payload = {}) {
|
|
|
108
108
|
return requested || list.mode;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
async function evaluateListFilter(item, filter, scope = {}) {
|
|
112
|
+
if (typeof filter !== "function") return { include: true, reason: "" };
|
|
113
|
+
const result = await filter(item, scope);
|
|
114
|
+
if (result && typeof result === "object" && Object.prototype.hasOwnProperty.call(result, "include")) {
|
|
115
|
+
return {
|
|
116
|
+
include: result.include !== false,
|
|
117
|
+
reason: String(result.reason || "filtered"),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
include: result !== false,
|
|
122
|
+
reason: result === false ? "filtered" : "",
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
111
126
|
async function synchronizeOmieList(definitions, list, event, context = {}) {
|
|
112
127
|
const mode = effectiveListMode(list, event.payload || {});
|
|
113
128
|
if (!["import", "full", "incremental", "individual"].includes(mode)) {
|
|
@@ -177,11 +192,23 @@ async function synchronizeOmieList(definitions, list, event, context = {}) {
|
|
|
177
192
|
for (const [index, item] of items.entries()) {
|
|
178
193
|
let externalValue;
|
|
179
194
|
try {
|
|
180
|
-
const
|
|
195
|
+
const scope = {
|
|
181
196
|
input,
|
|
182
197
|
response: callResult.response || callResult.data,
|
|
183
198
|
instanceId,
|
|
184
|
-
|
|
199
|
+
index,
|
|
200
|
+
};
|
|
201
|
+
const filterResult = await evaluateListFilter(item, list.filter, scope);
|
|
202
|
+
if (!filterResult.include) {
|
|
203
|
+
summary.skipped += 1;
|
|
204
|
+
context.recordItem?.({
|
|
205
|
+
index,
|
|
206
|
+
status: "skipped",
|
|
207
|
+
reason: filterResult.reason || "filtered",
|
|
208
|
+
});
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const mapped = mapRecord(item, list.mapping || {}, scope);
|
|
185
212
|
const externalField = list.target.externalKey;
|
|
186
213
|
externalValue = mapped[externalField]
|
|
187
214
|
?? getPath(item, list.sourceExternalKey || externalField);
|
|
@@ -491,6 +518,7 @@ module.exports = {
|
|
|
491
518
|
clientFor,
|
|
492
519
|
enqueueOmieCall,
|
|
493
520
|
ensureOmieProviderRegistered,
|
|
521
|
+
evaluateListFilter,
|
|
494
522
|
executeConfiguredCall,
|
|
495
523
|
handleOmieWebhook,
|
|
496
524
|
mapRecord,
|