@teamkeel/functions-runtime 0.418.0 → 0.419.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/dist/index.cjs +75 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -22
- package/dist/index.d.ts +30 -22
- package/dist/index.js +75 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2362,6 +2362,7 @@ var textInput = /* @__PURE__ */ __name((name, options) => {
|
|
|
2362
2362
|
minLength: options?.minLength
|
|
2363
2363
|
},
|
|
2364
2364
|
validate: options?.validate,
|
|
2365
|
+
onLeave: options?.onLeave,
|
|
2365
2366
|
getData: /* @__PURE__ */ __name((x) => x, "getData")
|
|
2366
2367
|
};
|
|
2367
2368
|
}, "textInput");
|
|
@@ -2383,6 +2384,7 @@ var numberInput = /* @__PURE__ */ __name((name, options) => {
|
|
|
2383
2384
|
max: options?.max
|
|
2384
2385
|
},
|
|
2385
2386
|
validate: options?.validate,
|
|
2387
|
+
onLeave: options?.onLeave,
|
|
2386
2388
|
getData: /* @__PURE__ */ __name((x) => x, "getData")
|
|
2387
2389
|
};
|
|
2388
2390
|
}, "numberInput");
|
|
@@ -2411,6 +2413,7 @@ var booleanInput = /* @__PURE__ */ __name((name, options) => {
|
|
|
2411
2413
|
mode: options?.mode || "checkbox"
|
|
2412
2414
|
},
|
|
2413
2415
|
validate: options?.validate,
|
|
2416
|
+
onLeave: options?.onLeave,
|
|
2414
2417
|
getData: /* @__PURE__ */ __name((x) => x, "getData")
|
|
2415
2418
|
};
|
|
2416
2419
|
}, "booleanInput");
|
|
@@ -2472,6 +2475,22 @@ var selectOne = /* @__PURE__ */ __name((name, options) => {
|
|
|
2472
2475
|
}, "selectOne");
|
|
2473
2476
|
|
|
2474
2477
|
// src/flows/ui/page.ts
|
|
2478
|
+
async function callbackFn(elements, elementName, callbackName, data) {
|
|
2479
|
+
const element = elements.find(
|
|
2480
|
+
(el) => el.uiConfig && el.uiConfig.name === elementName
|
|
2481
|
+
);
|
|
2482
|
+
if (!element) {
|
|
2483
|
+
throw new Error(`Element with name ${elementName} not found`);
|
|
2484
|
+
}
|
|
2485
|
+
const cb = element[callbackName];
|
|
2486
|
+
if (typeof cb !== "function") {
|
|
2487
|
+
throw new Error(
|
|
2488
|
+
`Callback ${callbackName} not found on element ${elementName}`
|
|
2489
|
+
);
|
|
2490
|
+
}
|
|
2491
|
+
return await cb(data);
|
|
2492
|
+
}
|
|
2493
|
+
__name(callbackFn, "callbackFn");
|
|
2475
2494
|
async function page(options, data, action) {
|
|
2476
2495
|
const content = options.content;
|
|
2477
2496
|
let hasValidationErrors = false;
|
|
@@ -2521,7 +2540,8 @@ async function page(options, data, action) {
|
|
|
2521
2540
|
return a;
|
|
2522
2541
|
}),
|
|
2523
2542
|
hasValidationErrors,
|
|
2524
|
-
validationError
|
|
2543
|
+
validationError,
|
|
2544
|
+
allowBack: options.allowBack
|
|
2525
2545
|
},
|
|
2526
2546
|
hasValidationErrors
|
|
2527
2547
|
};
|
|
@@ -2658,6 +2678,16 @@ var ExhuastedRetriesDisrupt = class extends FlowDisrupt {
|
|
|
2658
2678
|
super();
|
|
2659
2679
|
}
|
|
2660
2680
|
};
|
|
2681
|
+
var CallbackDisrupt = class extends FlowDisrupt {
|
|
2682
|
+
constructor(response, error) {
|
|
2683
|
+
super();
|
|
2684
|
+
this.response = response;
|
|
2685
|
+
this.error = error;
|
|
2686
|
+
}
|
|
2687
|
+
static {
|
|
2688
|
+
__name(this, "CallbackDisrupt");
|
|
2689
|
+
}
|
|
2690
|
+
};
|
|
2661
2691
|
|
|
2662
2692
|
// src/flows/ui/elements/display/banner.ts
|
|
2663
2693
|
var banner = /* @__PURE__ */ __name((options) => {
|
|
@@ -2913,32 +2943,31 @@ var NonRetriableError = class extends Error {
|
|
|
2913
2943
|
}
|
|
2914
2944
|
};
|
|
2915
2945
|
|
|
2916
|
-
// src/flows/ui/elements/
|
|
2917
|
-
var
|
|
2946
|
+
// src/flows/ui/elements/input/scan.ts
|
|
2947
|
+
var isMultiMode = /* @__PURE__ */ __name((opts) => opts && opts.mode === "multi", "isMultiMode");
|
|
2948
|
+
var scan = /* @__PURE__ */ __name((name, options) => {
|
|
2918
2949
|
return {
|
|
2919
2950
|
__type: "input",
|
|
2920
2951
|
uiConfig: {
|
|
2921
|
-
__type: "ui.
|
|
2952
|
+
__type: "ui.input.scan",
|
|
2922
2953
|
name,
|
|
2923
2954
|
title: options?.title ?? void 0,
|
|
2924
2955
|
description: options?.description ?? void 0,
|
|
2925
2956
|
unit: options?.unit ?? void 0,
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2957
|
+
mode: options?.mode ?? "single",
|
|
2958
|
+
duplicateHandling: "none",
|
|
2959
|
+
...isMultiMode(options) ? {
|
|
2960
|
+
max: options.max ?? void 0,
|
|
2961
|
+
min: options.min ?? void 0,
|
|
2962
|
+
duplicateHandling: options.duplicateHandling ?? "none"
|
|
2963
|
+
} : {}
|
|
2929
2964
|
},
|
|
2930
2965
|
validate: /* @__PURE__ */ __name(async (data) => {
|
|
2931
|
-
if (!("scans" in data)) {
|
|
2932
|
-
return "Missing scans in response";
|
|
2933
|
-
}
|
|
2934
|
-
if (!Array.isArray(data.scans)) {
|
|
2935
|
-
return "Scans must be an array";
|
|
2936
|
-
}
|
|
2937
2966
|
return options?.validate?.(data) ?? true;
|
|
2938
2967
|
}, "validate"),
|
|
2939
2968
|
getData: /* @__PURE__ */ __name((x) => x, "getData")
|
|
2940
2969
|
};
|
|
2941
|
-
}, "
|
|
2970
|
+
}, "scan");
|
|
2942
2971
|
|
|
2943
2972
|
// src/flows/index.ts
|
|
2944
2973
|
var STEP_STATUS = /* @__PURE__ */ ((STEP_STATUS2) => {
|
|
@@ -2974,7 +3003,7 @@ var defaultOpts = {
|
|
|
2974
3003
|
retries: 4,
|
|
2975
3004
|
timeout: 6e4
|
|
2976
3005
|
};
|
|
2977
|
-
function createFlowContext(runId, data, action, spanId, ctx) {
|
|
3006
|
+
function createFlowContext(runId, data, action, callback, element, spanId, ctx) {
|
|
2978
3007
|
const usedNames = /* @__PURE__ */ new Set();
|
|
2979
3008
|
return {
|
|
2980
3009
|
identity: ctx.identity,
|
|
@@ -3086,6 +3115,7 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
3086
3115
|
ui: {
|
|
3087
3116
|
page: /* @__PURE__ */ __name(async (name, options) => {
|
|
3088
3117
|
const db = useDatabase();
|
|
3118
|
+
const isCallback = element && callback;
|
|
3089
3119
|
if (usedNames.has(name)) {
|
|
3090
3120
|
await db.insertInto("keel.flow_step").values({
|
|
3091
3121
|
run_id: runId,
|
|
@@ -3121,6 +3151,25 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
3121
3151
|
(await page(options, null, null)).page
|
|
3122
3152
|
);
|
|
3123
3153
|
}
|
|
3154
|
+
if (isCallback) {
|
|
3155
|
+
try {
|
|
3156
|
+
const response = await callbackFn(
|
|
3157
|
+
options.content,
|
|
3158
|
+
element,
|
|
3159
|
+
callback,
|
|
3160
|
+
data
|
|
3161
|
+
);
|
|
3162
|
+
throw new CallbackDisrupt(response, false);
|
|
3163
|
+
} catch (e) {
|
|
3164
|
+
if (e instanceof CallbackDisrupt) {
|
|
3165
|
+
throw e;
|
|
3166
|
+
}
|
|
3167
|
+
throw new CallbackDisrupt(
|
|
3168
|
+
e instanceof Error ? e.message : `An error occurred`,
|
|
3169
|
+
true
|
|
3170
|
+
);
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3124
3173
|
if (!data) {
|
|
3125
3174
|
throw new UIRenderDisrupt(
|
|
3126
3175
|
step?.id,
|
|
@@ -3157,7 +3206,8 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
3157
3206
|
text: textInput,
|
|
3158
3207
|
number: numberInput,
|
|
3159
3208
|
boolean: booleanInput,
|
|
3160
|
-
dataGrid: dataGridInput
|
|
3209
|
+
dataGrid: dataGridInput,
|
|
3210
|
+
scan
|
|
3161
3211
|
},
|
|
3162
3212
|
display: {
|
|
3163
3213
|
divider,
|
|
@@ -3178,8 +3228,7 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
3178
3228
|
iterator,
|
|
3179
3229
|
interactive: {
|
|
3180
3230
|
print,
|
|
3181
|
-
pickList
|
|
3182
|
-
bulkScan
|
|
3231
|
+
pickList
|
|
3183
3232
|
}
|
|
3184
3233
|
}
|
|
3185
3234
|
};
|
|
@@ -3255,6 +3304,8 @@ async function handleFlow(request, config) {
|
|
|
3255
3304
|
request.meta.runId,
|
|
3256
3305
|
request.meta.data,
|
|
3257
3306
|
request.meta.action,
|
|
3307
|
+
request.meta.callback,
|
|
3308
|
+
request.meta.element,
|
|
3258
3309
|
span.spanContext().spanId,
|
|
3259
3310
|
createFlowContextAPI({
|
|
3260
3311
|
meta: request.meta
|
|
@@ -3290,6 +3341,12 @@ async function handleFlow(request, config) {
|
|
|
3290
3341
|
executeAfter: e.executeAfter
|
|
3291
3342
|
});
|
|
3292
3343
|
}
|
|
3344
|
+
if (e instanceof CallbackDisrupt) {
|
|
3345
|
+
if (e.error) {
|
|
3346
|
+
return (0, import_json_rpc_26.createJSONRPCErrorResponse)(request.id, 500, e.response);
|
|
3347
|
+
}
|
|
3348
|
+
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, e.response);
|
|
3349
|
+
}
|
|
3293
3350
|
if (e instanceof UIRenderDisrupt) {
|
|
3294
3351
|
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
3295
3352
|
runId,
|