@teamkeel/functions-runtime 0.417.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 +88 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -2
- package/dist/index.d.ts +57 -2
- package/dist/index.js +88 -3
- 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,6 +2943,32 @@ var NonRetriableError = class extends Error {
|
|
|
2913
2943
|
}
|
|
2914
2944
|
};
|
|
2915
2945
|
|
|
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) => {
|
|
2949
|
+
return {
|
|
2950
|
+
__type: "input",
|
|
2951
|
+
uiConfig: {
|
|
2952
|
+
__type: "ui.input.scan",
|
|
2953
|
+
name,
|
|
2954
|
+
title: options?.title ?? void 0,
|
|
2955
|
+
description: options?.description ?? void 0,
|
|
2956
|
+
unit: options?.unit ?? void 0,
|
|
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
|
+
} : {}
|
|
2964
|
+
},
|
|
2965
|
+
validate: /* @__PURE__ */ __name(async (data) => {
|
|
2966
|
+
return options?.validate?.(data) ?? true;
|
|
2967
|
+
}, "validate"),
|
|
2968
|
+
getData: /* @__PURE__ */ __name((x) => x, "getData")
|
|
2969
|
+
};
|
|
2970
|
+
}, "scan");
|
|
2971
|
+
|
|
2916
2972
|
// src/flows/index.ts
|
|
2917
2973
|
var STEP_STATUS = /* @__PURE__ */ ((STEP_STATUS2) => {
|
|
2918
2974
|
STEP_STATUS2["NEW"] = "NEW";
|
|
@@ -2947,7 +3003,7 @@ var defaultOpts = {
|
|
|
2947
3003
|
retries: 4,
|
|
2948
3004
|
timeout: 6e4
|
|
2949
3005
|
};
|
|
2950
|
-
function createFlowContext(runId, data, action, spanId, ctx) {
|
|
3006
|
+
function createFlowContext(runId, data, action, callback, element, spanId, ctx) {
|
|
2951
3007
|
const usedNames = /* @__PURE__ */ new Set();
|
|
2952
3008
|
return {
|
|
2953
3009
|
identity: ctx.identity,
|
|
@@ -3059,6 +3115,7 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
3059
3115
|
ui: {
|
|
3060
3116
|
page: /* @__PURE__ */ __name(async (name, options) => {
|
|
3061
3117
|
const db = useDatabase();
|
|
3118
|
+
const isCallback = element && callback;
|
|
3062
3119
|
if (usedNames.has(name)) {
|
|
3063
3120
|
await db.insertInto("keel.flow_step").values({
|
|
3064
3121
|
run_id: runId,
|
|
@@ -3094,6 +3151,25 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
3094
3151
|
(await page(options, null, null)).page
|
|
3095
3152
|
);
|
|
3096
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
|
+
}
|
|
3097
3173
|
if (!data) {
|
|
3098
3174
|
throw new UIRenderDisrupt(
|
|
3099
3175
|
step?.id,
|
|
@@ -3130,7 +3206,8 @@ function createFlowContext(runId, data, action, spanId, ctx) {
|
|
|
3130
3206
|
text: textInput,
|
|
3131
3207
|
number: numberInput,
|
|
3132
3208
|
boolean: booleanInput,
|
|
3133
|
-
dataGrid: dataGridInput
|
|
3209
|
+
dataGrid: dataGridInput,
|
|
3210
|
+
scan
|
|
3134
3211
|
},
|
|
3135
3212
|
display: {
|
|
3136
3213
|
divider,
|
|
@@ -3227,6 +3304,8 @@ async function handleFlow(request, config) {
|
|
|
3227
3304
|
request.meta.runId,
|
|
3228
3305
|
request.meta.data,
|
|
3229
3306
|
request.meta.action,
|
|
3307
|
+
request.meta.callback,
|
|
3308
|
+
request.meta.element,
|
|
3230
3309
|
span.spanContext().spanId,
|
|
3231
3310
|
createFlowContextAPI({
|
|
3232
3311
|
meta: request.meta
|
|
@@ -3262,6 +3341,12 @@ async function handleFlow(request, config) {
|
|
|
3262
3341
|
executeAfter: e.executeAfter
|
|
3263
3342
|
});
|
|
3264
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
|
+
}
|
|
3265
3350
|
if (e instanceof UIRenderDisrupt) {
|
|
3266
3351
|
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
3267
3352
|
runId,
|