@teamkeel/functions-runtime 0.414.6 → 0.415.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.d.cts CHANGED
@@ -353,7 +353,7 @@ type PageOptions<C extends FlowConfig, A extends PageActions[], T extends UIElem
353
353
  title?: string;
354
354
  description?: string;
355
355
  content: T;
356
- validate?: (data: ExtractFormData<T>) => Promise<null | string | void> | string | null | void;
356
+ validate?: ValidateFn<ExtractFormData<T>>;
357
357
  actions?: A;
358
358
  };
359
359
  type UiPage<C extends FlowConfig> = <T extends UIElements, const A extends PageActions[] = []>(name: string, options: PageOptions<C, A, T>) => Promise<A["length"] extends 0 ? ExtractFormData<T> : {
@@ -454,16 +454,17 @@ type ImageConfig = {
454
454
  alt?: string;
455
455
  fit?: "cover" | "contain";
456
456
  };
457
+
457
458
  type ListItem = {
458
459
  title?: string;
459
460
  description?: string;
460
461
  image?: ImageConfig;
461
462
  };
462
- type ListOptions<T> = {
463
+ type ListOptions$1<T> = {
463
464
  data: T[];
464
465
  render: (data: T) => ListItem;
465
466
  };
466
- type UiElementList = <T extends any>(options: ListOptions<T>) => DisplayElementResponse;
467
+ type UiElementList = <T extends any>(options: ListOptions$1<T>) => DisplayElementResponse;
467
468
  interface UiElementListApiResponse extends BaseUiDisplayResponse<"ui.display.list"> {
468
469
  data: ListItem[];
469
470
  }
@@ -544,11 +545,62 @@ type DataGridColumn = {
544
545
  editable: boolean;
545
546
  };
546
547
 
548
+ type UiElementPrint = DisplayElementWithRequiredConfig<{
549
+ jobs: PrintData[] | PrintData;
550
+ title?: string;
551
+ description?: string;
552
+ /** If true, the jobs will be automatically printed. */
553
+ autoPrint?: boolean;
554
+ /** If true, the flow will continue after the jobs are complete. */
555
+ autoContinue?: boolean;
556
+ }>;
557
+ type PrintData = {
558
+ type: "zpl";
559
+ name?: string;
560
+ data: string | string[];
561
+ };
562
+ interface UiElementPrintApiResponse extends BaseUiDisplayResponse<"ui.interactive.print"> {
563
+ title?: string;
564
+ description?: string;
565
+ data: {
566
+ type: "url" | "text" | "html" | "zpl";
567
+ data?: string[];
568
+ url?: string;
569
+ }[];
570
+ autoPrint: boolean;
571
+ }
572
+
573
+ type UiElementPickList = <N extends string, T extends Record<string, any>>(name: N, options: ListOptions<T>) => InputElementResponse<N, {
574
+ items: PickListResponseItem[];
575
+ }>;
576
+ type PickListResponseItem = {
577
+ id: string;
578
+ quantity: number;
579
+ targetQuantity: number;
580
+ };
581
+ type PickListItem = {
582
+ id: string;
583
+ targetQuantity: number;
584
+ title?: string;
585
+ description?: string;
586
+ image?: ImageConfig;
587
+ barcodes?: string[];
588
+ };
589
+ type ListOptions<T> = {
590
+ data: T[];
591
+ render: (data: T) => PickListItem;
592
+ validate?: ValidateFn<PickListResponseItem>;
593
+ };
594
+ interface UiElementPickListApiResponse extends BaseUiMinimalInputResponse<"ui.interactive.pickList"> {
595
+ data: PickListItem[];
596
+ }
597
+
547
598
  interface UI<C extends FlowConfig> {
548
599
  page: UiPage<C>;
549
600
  display: UiDisplayElements;
550
601
  inputs: UiInputsElements;
551
602
  select: UiSelectElements;
603
+ interactive: UiInteractiveElements;
552
604
  }
553
605
  type UiInputsElements = {
554
606
  text: UiElementInputText;
@@ -572,8 +624,13 @@ type UiDisplayElements = {
572
624
  table: UiElementTable;
573
625
  keyValue: UiElementKeyValue;
574
626
  };
627
+ type UiInteractiveElements = {
628
+ print: UiElementPrint;
629
+ pickList: UiElementPickList;
630
+ };
575
631
  type InputElement<TValueType, TConfig extends any = never> = <N extends string>(name: N, options?: BaseInputConfig<TValueType> & TConfig) => InputElementResponse<N, TValueType>;
576
632
  type DisplayElement<TConfig extends any = never> = (options?: TConfig) => DisplayElementResponse;
633
+ type DisplayElementWithRequiredConfig<TConfig extends any = never> = (options: TConfig) => DisplayElementResponse;
577
634
  type UIElements = (InputElementResponse<string, any> | DisplayElementResponse)[];
578
635
  interface UIElementBase {
579
636
  _type: string;
@@ -592,8 +649,9 @@ interface BaseInputConfig<T> {
592
649
  helpText?: string;
593
650
  optional?: boolean;
594
651
  disabled?: boolean;
595
- validate?: (data: T) => Promise<null | string | void> | string | null | void;
652
+ validate?: ValidateFn<T>;
596
653
  }
654
+ type ValidateFn<T> = (data: T) => Promise<boolean | string> | boolean | string;
597
655
  interface BaseUiInputResponse<K, TData> {
598
656
  __type: K;
599
657
  name: string;
@@ -604,6 +662,11 @@ interface BaseUiInputResponse<K, TData> {
604
662
  helpText?: string;
605
663
  validationError?: string;
606
664
  }
665
+ interface BaseUiMinimalInputResponse<K> {
666
+ __type: K;
667
+ name: string;
668
+ validationError?: string;
669
+ }
607
670
  interface BaseUiDisplayResponse<K> {
608
671
  __type: K;
609
672
  }
@@ -630,6 +693,10 @@ type UIApiResponses = {
630
693
  one: UiElementSelectOneApiResponse;
631
694
  table: UiElementSelectTableApiResponse;
632
695
  };
696
+ interactive: {
697
+ print: UiElementPrintApiResponse;
698
+ pickList: UiElementPickListApiResponse;
699
+ };
633
700
  };
634
701
 
635
702
  declare class NonRetriableError extends Error {
package/dist/index.d.ts CHANGED
@@ -353,7 +353,7 @@ type PageOptions<C extends FlowConfig, A extends PageActions[], T extends UIElem
353
353
  title?: string;
354
354
  description?: string;
355
355
  content: T;
356
- validate?: (data: ExtractFormData<T>) => Promise<null | string | void> | string | null | void;
356
+ validate?: ValidateFn<ExtractFormData<T>>;
357
357
  actions?: A;
358
358
  };
359
359
  type UiPage<C extends FlowConfig> = <T extends UIElements, const A extends PageActions[] = []>(name: string, options: PageOptions<C, A, T>) => Promise<A["length"] extends 0 ? ExtractFormData<T> : {
@@ -454,16 +454,17 @@ type ImageConfig = {
454
454
  alt?: string;
455
455
  fit?: "cover" | "contain";
456
456
  };
457
+
457
458
  type ListItem = {
458
459
  title?: string;
459
460
  description?: string;
460
461
  image?: ImageConfig;
461
462
  };
462
- type ListOptions<T> = {
463
+ type ListOptions$1<T> = {
463
464
  data: T[];
464
465
  render: (data: T) => ListItem;
465
466
  };
466
- type UiElementList = <T extends any>(options: ListOptions<T>) => DisplayElementResponse;
467
+ type UiElementList = <T extends any>(options: ListOptions$1<T>) => DisplayElementResponse;
467
468
  interface UiElementListApiResponse extends BaseUiDisplayResponse<"ui.display.list"> {
468
469
  data: ListItem[];
469
470
  }
@@ -544,11 +545,62 @@ type DataGridColumn = {
544
545
  editable: boolean;
545
546
  };
546
547
 
548
+ type UiElementPrint = DisplayElementWithRequiredConfig<{
549
+ jobs: PrintData[] | PrintData;
550
+ title?: string;
551
+ description?: string;
552
+ /** If true, the jobs will be automatically printed. */
553
+ autoPrint?: boolean;
554
+ /** If true, the flow will continue after the jobs are complete. */
555
+ autoContinue?: boolean;
556
+ }>;
557
+ type PrintData = {
558
+ type: "zpl";
559
+ name?: string;
560
+ data: string | string[];
561
+ };
562
+ interface UiElementPrintApiResponse extends BaseUiDisplayResponse<"ui.interactive.print"> {
563
+ title?: string;
564
+ description?: string;
565
+ data: {
566
+ type: "url" | "text" | "html" | "zpl";
567
+ data?: string[];
568
+ url?: string;
569
+ }[];
570
+ autoPrint: boolean;
571
+ }
572
+
573
+ type UiElementPickList = <N extends string, T extends Record<string, any>>(name: N, options: ListOptions<T>) => InputElementResponse<N, {
574
+ items: PickListResponseItem[];
575
+ }>;
576
+ type PickListResponseItem = {
577
+ id: string;
578
+ quantity: number;
579
+ targetQuantity: number;
580
+ };
581
+ type PickListItem = {
582
+ id: string;
583
+ targetQuantity: number;
584
+ title?: string;
585
+ description?: string;
586
+ image?: ImageConfig;
587
+ barcodes?: string[];
588
+ };
589
+ type ListOptions<T> = {
590
+ data: T[];
591
+ render: (data: T) => PickListItem;
592
+ validate?: ValidateFn<PickListResponseItem>;
593
+ };
594
+ interface UiElementPickListApiResponse extends BaseUiMinimalInputResponse<"ui.interactive.pickList"> {
595
+ data: PickListItem[];
596
+ }
597
+
547
598
  interface UI<C extends FlowConfig> {
548
599
  page: UiPage<C>;
549
600
  display: UiDisplayElements;
550
601
  inputs: UiInputsElements;
551
602
  select: UiSelectElements;
603
+ interactive: UiInteractiveElements;
552
604
  }
553
605
  type UiInputsElements = {
554
606
  text: UiElementInputText;
@@ -572,8 +624,13 @@ type UiDisplayElements = {
572
624
  table: UiElementTable;
573
625
  keyValue: UiElementKeyValue;
574
626
  };
627
+ type UiInteractiveElements = {
628
+ print: UiElementPrint;
629
+ pickList: UiElementPickList;
630
+ };
575
631
  type InputElement<TValueType, TConfig extends any = never> = <N extends string>(name: N, options?: BaseInputConfig<TValueType> & TConfig) => InputElementResponse<N, TValueType>;
576
632
  type DisplayElement<TConfig extends any = never> = (options?: TConfig) => DisplayElementResponse;
633
+ type DisplayElementWithRequiredConfig<TConfig extends any = never> = (options: TConfig) => DisplayElementResponse;
577
634
  type UIElements = (InputElementResponse<string, any> | DisplayElementResponse)[];
578
635
  interface UIElementBase {
579
636
  _type: string;
@@ -592,8 +649,9 @@ interface BaseInputConfig<T> {
592
649
  helpText?: string;
593
650
  optional?: boolean;
594
651
  disabled?: boolean;
595
- validate?: (data: T) => Promise<null | string | void> | string | null | void;
652
+ validate?: ValidateFn<T>;
596
653
  }
654
+ type ValidateFn<T> = (data: T) => Promise<boolean | string> | boolean | string;
597
655
  interface BaseUiInputResponse<K, TData> {
598
656
  __type: K;
599
657
  name: string;
@@ -604,6 +662,11 @@ interface BaseUiInputResponse<K, TData> {
604
662
  helpText?: string;
605
663
  validationError?: string;
606
664
  }
665
+ interface BaseUiMinimalInputResponse<K> {
666
+ __type: K;
667
+ name: string;
668
+ validationError?: string;
669
+ }
607
670
  interface BaseUiDisplayResponse<K> {
608
671
  __type: K;
609
672
  }
@@ -630,6 +693,10 @@ type UIApiResponses = {
630
693
  one: UiElementSelectOneApiResponse;
631
694
  table: UiElementSelectTableApiResponse;
632
695
  };
696
+ interactive: {
697
+ print: UiElementPrintApiResponse;
698
+ pickList: UiElementPickListApiResponse;
699
+ };
633
700
  };
634
701
 
635
702
  declare class NonRetriableError extends Error {
package/dist/index.js CHANGED
@@ -2455,10 +2455,11 @@ async function page(options, data, action) {
2455
2455
  }
2456
2456
  }
2457
2457
  const contentUiConfig = await Promise.all(
2458
- content.map(async (c) => {
2458
+ content.map(async (content2) => {
2459
+ let c = await content2;
2459
2460
  const isInput = "__type" in c && c.__type == "input";
2460
2461
  const hasData = data && c.uiConfig.name in data;
2461
- if (isInput && hasData && c.validate) {
2462
+ if (isInput && hasData && "validate" in c && c.validate) {
2462
2463
  const validationError2 = await c.validate(data[c.uiConfig.name]);
2463
2464
  if (typeof validationError2 === "string") {
2464
2465
  hasValidationErrors = true;
@@ -2702,6 +2703,68 @@ var dataGridInput = /* @__PURE__ */ __name((name, options) => {
2702
2703
  };
2703
2704
  }, "dataGridInput");
2704
2705
 
2706
+ // src/flows/ui/elements/interactive/print.ts
2707
+ var print = /* @__PURE__ */ __name(async (options) => {
2708
+ const dataConfig = Array.isArray(options.jobs) ? options.jobs : [options.jobs];
2709
+ const dataPromises = dataConfig.map(async (d) => {
2710
+ if ("type" in d && d.type) {
2711
+ return {
2712
+ type: d.type,
2713
+ name: d.name,
2714
+ data: Array.isArray(d.data) ? d.data : [d.data]
2715
+ };
2716
+ }
2717
+ return null;
2718
+ });
2719
+ const data = (await Promise.all(dataPromises)).filter((x) => x !== null);
2720
+ return {
2721
+ uiConfig: {
2722
+ __type: "ui.interactive.print",
2723
+ title: options.title,
2724
+ description: options.description,
2725
+ data,
2726
+ autoPrint: options.autoPrint ?? false
2727
+ }
2728
+ };
2729
+ }, "print");
2730
+
2731
+ // src/flows/ui/elements/interactive/pickList.ts
2732
+ var pickList = /* @__PURE__ */ __name((name, options) => {
2733
+ return {
2734
+ __type: "input",
2735
+ uiConfig: {
2736
+ __type: "ui.interactive.pickList",
2737
+ name,
2738
+ data: options.data.map((item) => {
2739
+ const rendered = options.render(item);
2740
+ return {
2741
+ id: rendered.id,
2742
+ targetQuantity: rendered.targetQuantity,
2743
+ title: rendered.title,
2744
+ description: rendered.description,
2745
+ image: rendered.image ?? void 0,
2746
+ barcodes: rendered.barcodes ?? void 0
2747
+ };
2748
+ })
2749
+ },
2750
+ validate: /* @__PURE__ */ __name(async (data) => {
2751
+ if (!("items" in data)) {
2752
+ return "Missing items in response";
2753
+ }
2754
+ if (!Array.isArray(data.items)) {
2755
+ return "Items must be an array";
2756
+ }
2757
+ if (data.items.some(
2758
+ (item) => typeof item !== "object" || typeof item.id !== "string" || typeof item.qty !== "number"
2759
+ )) {
2760
+ return "Invalid data";
2761
+ }
2762
+ return options?.validate?.(data) ?? true;
2763
+ }, "validate"),
2764
+ getData: /* @__PURE__ */ __name((x) => x, "getData")
2765
+ };
2766
+ }, "pickList");
2767
+
2705
2768
  // src/flows/errors.ts
2706
2769
  var NonRetriableError = class extends Error {
2707
2770
  static {
@@ -2928,6 +2991,10 @@ function createFlowContext(runId, data, action, spanId, ctx) {
2928
2991
  select: {
2929
2992
  one: selectOne,
2930
2993
  table: selectTable
2994
+ },
2995
+ interactive: {
2996
+ print,
2997
+ pickList
2931
2998
  }
2932
2999
  }
2933
3000
  };
@@ -2952,7 +3019,7 @@ async function complete(options) {
2952
3019
  const content = options.content || [];
2953
3020
  const contentUiConfig = await Promise.all(
2954
3021
  content.map(async (c) => {
2955
- return c.uiConfig;
3022
+ return (await c).uiConfig;
2956
3023
  })
2957
3024
  );
2958
3025
  return {