@teamkeel/functions-runtime 0.414.0 → 0.414.2
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 +81 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -8
- package/dist/index.d.ts +34 -8
- package/dist/index.js +79 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
PERMISSION_STATE: () => PERMISSION_STATE,
|
|
41
41
|
Permissions: () => Permissions,
|
|
42
42
|
RequestHeaders: () => RequestHeaders,
|
|
43
|
+
STEP_STATUS: () => STEP_STATUS,
|
|
44
|
+
STEP_TYPE: () => STEP_TYPE,
|
|
43
45
|
checkBuiltInPermissions: () => checkBuiltInPermissions,
|
|
44
46
|
createFlowContext: () => createFlowContext,
|
|
45
47
|
handleFlow: () => handleFlow,
|
|
@@ -1119,11 +1121,11 @@ var TimePeriod = class _TimePeriod {
|
|
|
1119
1121
|
static {
|
|
1120
1122
|
__name(this, "TimePeriod");
|
|
1121
1123
|
}
|
|
1122
|
-
constructor(period = "", value = 0, offset = 0,
|
|
1124
|
+
constructor(period = "", value = 0, offset = 0, complete2 = false) {
|
|
1123
1125
|
this.period = period;
|
|
1124
1126
|
this.value = value;
|
|
1125
1127
|
this.offset = offset;
|
|
1126
|
-
this.complete =
|
|
1128
|
+
this.complete = complete2;
|
|
1127
1129
|
}
|
|
1128
1130
|
static fromExpression(expression) {
|
|
1129
1131
|
const pattern = /^(this|next|last)?\s*(\d+)?\s*(complete)?\s*(second|minute|hour|day|week|month|year|seconds|minutes|hours|days|weeks|months|years)?$/i;
|
|
@@ -1149,15 +1151,15 @@ var TimePeriod = class _TimePeriod {
|
|
|
1149
1151
|
const [, direction, rawValue, isComplete, rawPeriod] = match;
|
|
1150
1152
|
let period = rawPeriod ? rawPeriod.toLowerCase().replace(/s$/, "") : "";
|
|
1151
1153
|
let value = rawValue ? parseInt(rawValue, 10) : 1;
|
|
1152
|
-
let
|
|
1154
|
+
let complete2 = Boolean(isComplete);
|
|
1153
1155
|
let offset = 0;
|
|
1154
1156
|
switch (direction?.toLowerCase()) {
|
|
1155
1157
|
case "this":
|
|
1156
1158
|
offset = 0;
|
|
1157
|
-
|
|
1159
|
+
complete2 = true;
|
|
1158
1160
|
break;
|
|
1159
1161
|
case "next":
|
|
1160
|
-
offset =
|
|
1162
|
+
offset = complete2 ? 1 : 0;
|
|
1161
1163
|
break;
|
|
1162
1164
|
case "last":
|
|
1163
1165
|
offset = -value;
|
|
@@ -1167,7 +1169,7 @@ var TimePeriod = class _TimePeriod {
|
|
|
1167
1169
|
"Time period expression must start with this, next, or last"
|
|
1168
1170
|
);
|
|
1169
1171
|
}
|
|
1170
|
-
return new _TimePeriod(period, value, offset,
|
|
1172
|
+
return new _TimePeriod(period, value, offset, complete2);
|
|
1171
1173
|
}
|
|
1172
1174
|
periodStartSQL() {
|
|
1173
1175
|
let sql4 = "NOW()";
|
|
@@ -2460,7 +2462,7 @@ async function page(options, data, action) {
|
|
|
2460
2462
|
if (options.actions) {
|
|
2461
2463
|
const isValidAction = options.actions.some((a) => {
|
|
2462
2464
|
if (typeof a === "string") return a === action;
|
|
2463
|
-
return a && typeof a === "object" && "
|
|
2465
|
+
return a && typeof a === "object" && "value" in a && a.value === action;
|
|
2464
2466
|
});
|
|
2465
2467
|
hasValidationErrors = !isValidAction;
|
|
2466
2468
|
}
|
|
@@ -2488,7 +2490,14 @@ async function page(options, data, action) {
|
|
|
2488
2490
|
title: options.title,
|
|
2489
2491
|
description: options.description,
|
|
2490
2492
|
content: contentUiConfig,
|
|
2491
|
-
actions: options.actions
|
|
2493
|
+
actions: options.actions?.map((a) => {
|
|
2494
|
+
if (typeof a === "string") {
|
|
2495
|
+
return { label: a, value: a, mode: "primary" };
|
|
2496
|
+
} else if (typeof a === "object") {
|
|
2497
|
+
a.mode = a.mode || "primary";
|
|
2498
|
+
}
|
|
2499
|
+
return a;
|
|
2500
|
+
})
|
|
2492
2501
|
},
|
|
2493
2502
|
hasValidationErrors
|
|
2494
2503
|
};
|
|
@@ -2613,6 +2622,21 @@ var header = /* @__PURE__ */ __name((options) => {
|
|
|
2613
2622
|
}, "header");
|
|
2614
2623
|
|
|
2615
2624
|
// src/flows/index.ts
|
|
2625
|
+
var STEP_STATUS = /* @__PURE__ */ ((STEP_STATUS2) => {
|
|
2626
|
+
STEP_STATUS2["NEW"] = "NEW";
|
|
2627
|
+
STEP_STATUS2["RUNNING"] = "RUNNING";
|
|
2628
|
+
STEP_STATUS2["PENDING"] = "PENDING";
|
|
2629
|
+
STEP_STATUS2["COMPLETED"] = "COMPLETED";
|
|
2630
|
+
STEP_STATUS2["FAILED"] = "FAILED";
|
|
2631
|
+
return STEP_STATUS2;
|
|
2632
|
+
})(STEP_STATUS || {});
|
|
2633
|
+
var STEP_TYPE = /* @__PURE__ */ ((STEP_TYPE2) => {
|
|
2634
|
+
STEP_TYPE2["FUNCTION"] = "FUNCTION";
|
|
2635
|
+
STEP_TYPE2["UI"] = "UI";
|
|
2636
|
+
STEP_TYPE2["DELAY"] = "DELAY";
|
|
2637
|
+
STEP_TYPE2["COMPLETE"] = "COMPLETE";
|
|
2638
|
+
return STEP_TYPE2;
|
|
2639
|
+
})(STEP_TYPE || {});
|
|
2616
2640
|
var defaultOpts = {
|
|
2617
2641
|
retries: 5,
|
|
2618
2642
|
timeout: 6e4
|
|
@@ -2620,9 +2644,11 @@ var defaultOpts = {
|
|
|
2620
2644
|
function createFlowContext(runId, data, action, spanId, ctx) {
|
|
2621
2645
|
const usedNames = /* @__PURE__ */ new Set();
|
|
2622
2646
|
return {
|
|
2647
|
+
identity: ctx.identity,
|
|
2623
2648
|
env: ctx.env,
|
|
2624
2649
|
now: ctx.now,
|
|
2625
2650
|
secrets: ctx.secrets,
|
|
2651
|
+
complete: /* @__PURE__ */ __name((options) => options, "complete"),
|
|
2626
2652
|
step: /* @__PURE__ */ __name(async (name, optionsOrFn, fn) => {
|
|
2627
2653
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
2628
2654
|
const actualFn = typeof optionsOrFn === "function" ? optionsOrFn : fn;
|
|
@@ -2803,6 +2829,26 @@ function withTimeout(promiseFn, timeout) {
|
|
|
2803
2829
|
}
|
|
2804
2830
|
__name(withTimeout, "withTimeout");
|
|
2805
2831
|
|
|
2832
|
+
// src/flows/ui/complete.ts
|
|
2833
|
+
async function complete(options) {
|
|
2834
|
+
const content = options.content;
|
|
2835
|
+
const contentUiConfig = await Promise.all(
|
|
2836
|
+
content.map(async (c) => {
|
|
2837
|
+
return c.uiConfig;
|
|
2838
|
+
})
|
|
2839
|
+
);
|
|
2840
|
+
return {
|
|
2841
|
+
complete: {
|
|
2842
|
+
__type: "ui.complete",
|
|
2843
|
+
stage: options.stage,
|
|
2844
|
+
title: options.title,
|
|
2845
|
+
description: options.description,
|
|
2846
|
+
content: contentUiConfig
|
|
2847
|
+
}
|
|
2848
|
+
};
|
|
2849
|
+
}
|
|
2850
|
+
__name(complete, "complete");
|
|
2851
|
+
|
|
2806
2852
|
// src/handleFlow.ts
|
|
2807
2853
|
var import_change_case2 = require("change-case");
|
|
2808
2854
|
async function handleFlow(request, config) {
|
|
@@ -2860,8 +2906,9 @@ async function handleFlow(request, config) {
|
|
|
2860
2906
|
})
|
|
2861
2907
|
};
|
|
2862
2908
|
const inputs = parseInputs(request.meta?.inputs);
|
|
2909
|
+
let response = void 0;
|
|
2863
2910
|
try {
|
|
2864
|
-
await tryExecuteFlow(db, async () => {
|
|
2911
|
+
response = await tryExecuteFlow(db, async () => {
|
|
2865
2912
|
return flowFunction(ctx, inputs);
|
|
2866
2913
|
});
|
|
2867
2914
|
} catch (e) {
|
|
@@ -2900,10 +2947,32 @@ async function handleFlow(request, config) {
|
|
|
2900
2947
|
config: flowConfig
|
|
2901
2948
|
});
|
|
2902
2949
|
}
|
|
2950
|
+
let ui = null;
|
|
2951
|
+
let data = null;
|
|
2952
|
+
if (response && typeof response == "object" && "content" in response) {
|
|
2953
|
+
const completeStep = await db.selectFrom("keel.flow_step").where("run_id", "=", runId).where("type", "=", "COMPLETE" /* COMPLETE */).selectAll().executeTakeFirst();
|
|
2954
|
+
if (!completeStep) {
|
|
2955
|
+
await db.insertInto("keel.flow_step").values({
|
|
2956
|
+
run_id: runId,
|
|
2957
|
+
name: "",
|
|
2958
|
+
stage: response.stage,
|
|
2959
|
+
status: "COMPLETED" /* COMPLETED */,
|
|
2960
|
+
type: "COMPLETE" /* COMPLETE */,
|
|
2961
|
+
startTime: /* @__PURE__ */ new Date(),
|
|
2962
|
+
endTime: /* @__PURE__ */ new Date()
|
|
2963
|
+
}).returningAll().executeTakeFirst();
|
|
2964
|
+
}
|
|
2965
|
+
ui = (await complete(response)).complete;
|
|
2966
|
+
data = response.data;
|
|
2967
|
+
} else if (response) {
|
|
2968
|
+
data = response;
|
|
2969
|
+
}
|
|
2903
2970
|
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2904
2971
|
runId,
|
|
2905
2972
|
runCompleted: true,
|
|
2906
|
-
|
|
2973
|
+
data,
|
|
2974
|
+
config: flowConfig,
|
|
2975
|
+
ui
|
|
2907
2976
|
});
|
|
2908
2977
|
} catch (e) {
|
|
2909
2978
|
if (e instanceof Error) {
|
|
@@ -2951,6 +3020,8 @@ __name(ksuid, "ksuid");
|
|
|
2951
3020
|
PERMISSION_STATE,
|
|
2952
3021
|
Permissions,
|
|
2953
3022
|
RequestHeaders,
|
|
3023
|
+
STEP_STATUS,
|
|
3024
|
+
STEP_TYPE,
|
|
2954
3025
|
checkBuiltInPermissions,
|
|
2955
3026
|
createFlowContext,
|
|
2956
3027
|
handleFlow,
|