@teamkeel/functions-runtime 0.414.7 → 0.415.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +188 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -5
- package/dist/index.d.ts +101 -5
- package/dist/index.js +188 -15
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -2483,20 +2483,15 @@ async function page(options, data, action) {
|
|
|
2483
2483
|
}
|
|
2484
2484
|
const contentUiConfig = await Promise.all(
|
|
2485
2485
|
content.map(async (c) => {
|
|
2486
|
-
const
|
|
2487
|
-
const
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
};
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
return c.uiConfig;
|
|
2499
|
-
}).filter(Boolean)
|
|
2486
|
+
const resolvedC = await c;
|
|
2487
|
+
const elementData = data && typeof data === "object" && resolvedC.uiConfig.name in data ? data[resolvedC.uiConfig.name] : void 0;
|
|
2488
|
+
const { uiConfig, validationErrors } = await recursivelyProcessElement(
|
|
2489
|
+
c,
|
|
2490
|
+
elementData
|
|
2491
|
+
);
|
|
2492
|
+
if (validationErrors) hasValidationErrors = true;
|
|
2493
|
+
return uiConfig;
|
|
2494
|
+
})
|
|
2500
2495
|
);
|
|
2501
2496
|
if (data && options.validate) {
|
|
2502
2497
|
const validationResult = await options.validate(data);
|
|
@@ -2527,6 +2522,101 @@ async function page(options, data, action) {
|
|
|
2527
2522
|
};
|
|
2528
2523
|
}
|
|
2529
2524
|
__name(page, "page");
|
|
2525
|
+
var recursivelyProcessElement = /* @__PURE__ */ __name(async (c, data) => {
|
|
2526
|
+
const resolvedC = await c;
|
|
2527
|
+
const elementType = "__type" in resolvedC ? resolvedC.__type : null;
|
|
2528
|
+
switch (elementType) {
|
|
2529
|
+
case "input":
|
|
2530
|
+
return processInputElement(
|
|
2531
|
+
resolvedC,
|
|
2532
|
+
data
|
|
2533
|
+
);
|
|
2534
|
+
case "iterator":
|
|
2535
|
+
return processIteratorElement(
|
|
2536
|
+
resolvedC,
|
|
2537
|
+
data
|
|
2538
|
+
);
|
|
2539
|
+
default:
|
|
2540
|
+
return {
|
|
2541
|
+
uiConfig: { ...resolvedC.uiConfig },
|
|
2542
|
+
validationErrors: false
|
|
2543
|
+
};
|
|
2544
|
+
}
|
|
2545
|
+
}, "recursivelyProcessElement");
|
|
2546
|
+
var processInputElement = /* @__PURE__ */ __name(async (element, data) => {
|
|
2547
|
+
const hasData = data !== void 0 && data !== null;
|
|
2548
|
+
if (!hasData || !element.validate) {
|
|
2549
|
+
return {
|
|
2550
|
+
uiConfig: { ...element.uiConfig },
|
|
2551
|
+
validationErrors: false
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
const validationError = await element.validate(data);
|
|
2555
|
+
const hasValidationErrors = typeof validationError === "string";
|
|
2556
|
+
return {
|
|
2557
|
+
uiConfig: {
|
|
2558
|
+
...element.uiConfig,
|
|
2559
|
+
validationError: hasValidationErrors ? validationError : void 0
|
|
2560
|
+
},
|
|
2561
|
+
validationErrors: hasValidationErrors
|
|
2562
|
+
};
|
|
2563
|
+
}, "processInputElement");
|
|
2564
|
+
var processIteratorElement = /* @__PURE__ */ __name(async (element, data) => {
|
|
2565
|
+
const elements = element.uiConfig.content;
|
|
2566
|
+
const dataArr = data;
|
|
2567
|
+
const ui = [];
|
|
2568
|
+
for (const el of elements) {
|
|
2569
|
+
const result = await recursivelyProcessElement(el, void 0);
|
|
2570
|
+
ui.push(result.uiConfig);
|
|
2571
|
+
}
|
|
2572
|
+
const validationErrors = await validateIteratorData(elements, dataArr);
|
|
2573
|
+
let hasValidationErrors = validationErrors.length > 0;
|
|
2574
|
+
let validationError = void 0;
|
|
2575
|
+
if (dataArr && element.validate) {
|
|
2576
|
+
const v = await element.validate(dataArr);
|
|
2577
|
+
if (typeof v === "string") {
|
|
2578
|
+
hasValidationErrors = true;
|
|
2579
|
+
validationError = v;
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
return {
|
|
2583
|
+
uiConfig: {
|
|
2584
|
+
...element.uiConfig,
|
|
2585
|
+
content: ui,
|
|
2586
|
+
validationError,
|
|
2587
|
+
contentValidationErrors: hasValidationErrors ? validationErrors : void 0
|
|
2588
|
+
},
|
|
2589
|
+
validationErrors: hasValidationErrors
|
|
2590
|
+
};
|
|
2591
|
+
}, "processIteratorElement");
|
|
2592
|
+
var validateIteratorData = /* @__PURE__ */ __name(async (elements, dataArr) => {
|
|
2593
|
+
const validationErrors = [];
|
|
2594
|
+
if (!dataArr || dataArr.length === 0) {
|
|
2595
|
+
return validationErrors;
|
|
2596
|
+
}
|
|
2597
|
+
for (let i = 0; i < dataArr.length; i++) {
|
|
2598
|
+
const rowData = dataArr[i];
|
|
2599
|
+
for (const el of elements) {
|
|
2600
|
+
const resolvedEl = await el;
|
|
2601
|
+
if ("__type" in resolvedEl && resolvedEl.__type === "input" && "validate" in resolvedEl && resolvedEl.validate && typeof resolvedEl.validate === "function") {
|
|
2602
|
+
const fieldName = resolvedEl.uiConfig.name;
|
|
2603
|
+
if (rowData && typeof rowData === "object" && fieldName in rowData) {
|
|
2604
|
+
const validationError = await resolvedEl.validate(
|
|
2605
|
+
rowData[fieldName]
|
|
2606
|
+
);
|
|
2607
|
+
if (typeof validationError === "string") {
|
|
2608
|
+
validationErrors.push({
|
|
2609
|
+
index: i,
|
|
2610
|
+
name: fieldName,
|
|
2611
|
+
validationError
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
return validationErrors;
|
|
2619
|
+
}, "validateIteratorData");
|
|
2530
2620
|
|
|
2531
2621
|
// src/flows/disrupts.ts
|
|
2532
2622
|
var FlowDisrupt = class {
|
|
@@ -2729,6 +2819,84 @@ var dataGridInput = /* @__PURE__ */ __name((name, options) => {
|
|
|
2729
2819
|
};
|
|
2730
2820
|
}, "dataGridInput");
|
|
2731
2821
|
|
|
2822
|
+
// src/flows/ui/elements/iterator.ts
|
|
2823
|
+
var iterator = /* @__PURE__ */ __name((name, options) => {
|
|
2824
|
+
return {
|
|
2825
|
+
__type: "iterator",
|
|
2826
|
+
uiConfig: {
|
|
2827
|
+
__type: "ui.iterator",
|
|
2828
|
+
name,
|
|
2829
|
+
content: options.content,
|
|
2830
|
+
max: options.max,
|
|
2831
|
+
min: options.min
|
|
2832
|
+
},
|
|
2833
|
+
validate: options?.validate,
|
|
2834
|
+
getData: /* @__PURE__ */ __name((x) => x, "getData")
|
|
2835
|
+
};
|
|
2836
|
+
}, "iterator");
|
|
2837
|
+
|
|
2838
|
+
// src/flows/ui/elements/interactive/print.ts
|
|
2839
|
+
var print = /* @__PURE__ */ __name(async (options) => {
|
|
2840
|
+
const dataConfig = Array.isArray(options.jobs) ? options.jobs : [options.jobs];
|
|
2841
|
+
const dataPromises = dataConfig.map(async (d) => {
|
|
2842
|
+
if ("type" in d && d.type) {
|
|
2843
|
+
return {
|
|
2844
|
+
type: d.type,
|
|
2845
|
+
name: d.name,
|
|
2846
|
+
data: Array.isArray(d.data) ? d.data : [d.data]
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
return null;
|
|
2850
|
+
});
|
|
2851
|
+
const data = (await Promise.all(dataPromises)).filter((x) => x !== null);
|
|
2852
|
+
return {
|
|
2853
|
+
uiConfig: {
|
|
2854
|
+
__type: "ui.interactive.print",
|
|
2855
|
+
title: options.title,
|
|
2856
|
+
description: options.description,
|
|
2857
|
+
data,
|
|
2858
|
+
autoPrint: options.autoPrint ?? false
|
|
2859
|
+
}
|
|
2860
|
+
};
|
|
2861
|
+
}, "print");
|
|
2862
|
+
|
|
2863
|
+
// src/flows/ui/elements/interactive/pickList.ts
|
|
2864
|
+
var pickList = /* @__PURE__ */ __name((name, options) => {
|
|
2865
|
+
return {
|
|
2866
|
+
__type: "input",
|
|
2867
|
+
uiConfig: {
|
|
2868
|
+
__type: "ui.interactive.pickList",
|
|
2869
|
+
name,
|
|
2870
|
+
data: options.data.map((item) => {
|
|
2871
|
+
const rendered = options.render(item);
|
|
2872
|
+
return {
|
|
2873
|
+
id: rendered.id,
|
|
2874
|
+
targetQuantity: rendered.targetQuantity,
|
|
2875
|
+
title: rendered.title,
|
|
2876
|
+
description: rendered.description,
|
|
2877
|
+
image: rendered.image ?? void 0,
|
|
2878
|
+
barcodes: rendered.barcodes ?? void 0
|
|
2879
|
+
};
|
|
2880
|
+
})
|
|
2881
|
+
},
|
|
2882
|
+
validate: /* @__PURE__ */ __name(async (data) => {
|
|
2883
|
+
if (!("items" in data)) {
|
|
2884
|
+
return "Missing items in response";
|
|
2885
|
+
}
|
|
2886
|
+
if (!Array.isArray(data.items)) {
|
|
2887
|
+
return "Items must be an array";
|
|
2888
|
+
}
|
|
2889
|
+
if (data.items.some(
|
|
2890
|
+
(item) => typeof item !== "object" || typeof item.id !== "string" || typeof item.qty !== "number"
|
|
2891
|
+
)) {
|
|
2892
|
+
return "Invalid data";
|
|
2893
|
+
}
|
|
2894
|
+
return options?.validate?.(data) ?? true;
|
|
2895
|
+
}, "validate"),
|
|
2896
|
+
getData: /* @__PURE__ */ __name((x) => x, "getData")
|
|
2897
|
+
};
|
|
2898
|
+
}, "pickList");
|
|
2899
|
+
|
|
2732
2900
|
// src/flows/errors.ts
|
|
2733
2901
|
var NonRetriableError = class extends Error {
|
|
2734
2902
|
static {
|
|
@@ -2955,6 +3123,11 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
2955
3123
|
select: {
|
|
2956
3124
|
one: selectOne,
|
|
2957
3125
|
table: selectTable
|
|
3126
|
+
},
|
|
3127
|
+
iterator,
|
|
3128
|
+
interactive: {
|
|
3129
|
+
print,
|
|
3130
|
+
pickList
|
|
2958
3131
|
}
|
|
2959
3132
|
}
|
|
2960
3133
|
};
|
|
@@ -2979,7 +3152,7 @@ async function complete(options) {
|
|
|
2979
3152
|
const content = options.content || [];
|
|
2980
3153
|
const contentUiConfig = await Promise.all(
|
|
2981
3154
|
content.map(async (c) => {
|
|
2982
|
-
return c.uiConfig;
|
|
3155
|
+
return (await c).uiConfig;
|
|
2983
3156
|
})
|
|
2984
3157
|
);
|
|
2985
3158
|
return {
|