@timeax/digital-service-engine 0.0.6 → 0.0.8

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/index.ts"],"sourcesContent":["export * from \"./base\";\r\nexport * from \"./canvas-types\";\r\nexport * from \"./comments\";\r\nexport * from \"./editor\";\r\nexport * from \"./editor.types\";\r\nexport * from \"./graph\";\r\nexport * from \"./order\";\r\nexport * from \"./policies\";\r\nexport * from \"./provider\";\r\nexport * from \"./validation\";\r\nexport * from \"./fallback-editor\""],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/schema/index.ts"],"sourcesContent":["export * from \"./base\";\r\nexport * from \"./canvas-types\";\r\nexport * from \"./comments\";\r\nexport * from \"./editor\";\r\nexport * from \"./editor.types\";\r\nexport * from \"./graph\";\r\nexport * from \"./order\";\r\nexport * from \"./policies\";\r\nexport * from \"./provider\";\r\nexport * from \"./validation\";\r\nexport * from \"./fallback-editor\"\r\nexport * from './catalog'"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,9 +1,9 @@
1
- import { NodeProps } from 'reactflow';
1
+ import { NodeProps, Node } from '@xyflow/react';
2
2
 
3
3
  interface ButtonValue {
4
4
  id: string;
5
5
  value: string | number;
6
- service_id?: number;
6
+ service_id?: ServiceIdRef;
7
7
  pricing_role?: "base" | "utility";
8
8
  meta?: Record<string, unknown> & UtilityMark & WithQuantityDefault;
9
9
  }
@@ -12,16 +12,23 @@ type UtilityMode = "flat" | "per_quantity" | "per_value" | "percent";
12
12
  type QuantityRule = {
13
13
  valueBy: "value" | "length" | "eval";
14
14
  code?: string;
15
+ multiply?: number;
16
+ clamp?: {
17
+ min?: number;
18
+ max?: number;
19
+ };
20
+ fallback?: number;
15
21
  };
16
22
  type UtilityLineItem = {
17
23
  nodeId: string;
18
24
  mode: UtilityMode;
19
25
  rate: number;
26
+ percentBase?: "service_total" | "base_service" | "all";
27
+ label?: string;
20
28
  inputs: {
21
29
  quantity: number;
22
30
  value?: Scalar | Scalar[];
23
- valueBy?: "value" | "length" | "eval";
24
- evalCodeUsed?: boolean;
31
+ valueBy?: "value" | "length";
25
32
  };
26
33
  };
27
34
  type ServiceFallbacks = ServiceFallback;
@@ -47,8 +54,16 @@ type SnapshotContext = {
47
54
  /** Client pruning policy used (so server can mirror/compare). */
48
55
  policy: {
49
56
  ratePolicy: {
50
- kind: "lte_primary" | "none";
51
- thresholdPct?: number;
57
+ kind: "eq_primary";
58
+ } | {
59
+ kind: "lte_primary";
60
+ pct: number;
61
+ } | {
62
+ kind: "within_pct";
63
+ pct: number;
64
+ } | {
65
+ kind: "at_least_pct_lower";
66
+ pct: number;
52
67
  };
53
68
  requireConstraintFit: boolean;
54
69
  };
@@ -156,7 +171,7 @@ type NodeRef = {
156
171
  };
157
172
  type NodeMap = Map<string, NodeRef>;
158
173
 
159
- type ValidationCode = "root_missing" | "cycle_in_tags" | "bad_bind_reference" | "duplicate_id" | "duplicate_tag_label" | "duplicate_field_name" | "label_missing" | "duplicate_visible_label" | "bad_option_key" | "option_include_exclude_conflict" | "service_field_missing_service_id" | "user_input_field_has_service_option" | "rate_mismatch_across_base" | "utility_without_base" | "unsupported_constraint" | "constraint_contradiction" | "custom_component_missing" | "policy_violation" | "field_unbound" | "constraint_overridden" | "unsupported_constraint_option" | "custom_component_unresolvable" | "quantity_multiple_markers" | "utility_with_service_id" | "utility_missing_rate" | "utility_invalid_mode" | "fallback_bad_node" | "fallback_unknown_service" | "fallback_cycle" | "fallback_no_primary" | "fallback_rate_violation" | "fallback_constraint_mismatch" | "fallback_no_tag_context";
174
+ type ValidationCode = "root_missing" | "cycle_in_tags" | "bad_bind_reference" | "duplicate_id" | "duplicate_tag_label" | "duplicate_field_name" | "label_missing" | "duplicate_visible_label" | "bad_option_key" | "option_include_exclude_conflict" | "service_field_missing_service_id" | "user_input_field_has_service_option" | "rate_mismatch_across_base" | "rate_coherence_violation" | "utility_without_base" | "unsupported_constraint" | "constraint_contradiction" | "custom_component_missing" | "policy_violation" | "field_unbound" | "constraint_overridden" | "unsupported_constraint_option" | "custom_component_unresolvable" | "quantity_multiple_markers" | "utility_with_service_id" | "utility_missing_rate" | "utility_invalid_mode" | "fallback_bad_node" | "fallback_unknown_service" | "fallback_cycle" | "fallback_no_primary" | "fallback_rate_violation" | "fallback_constraint_mismatch" | "fallback_no_tag_context" | "field_validation_invalid_rule" | "field_validation_invalid_op" | "field_validation_eval_missing_code" | "field_validation_between_missing_bounds" | "field_validation_match_missing_pattern";
160
175
  type ValidationError = {
161
176
  code: ValidationCode;
162
177
  message: string;
@@ -212,7 +227,10 @@ type ValidatorOptions = {
212
227
  fallbackSettings?: FallbackSettings;
213
228
  };
214
229
  type RatePolicy = {
230
+ kind: "eq_primary";
231
+ } | {
215
232
  kind: "lte_primary";
233
+ pct: number;
216
234
  } | {
217
235
  kind: "within_pct";
218
236
  pct: number;
@@ -223,7 +241,7 @@ type RatePolicy = {
223
241
  type FallbackSettings = {
224
242
  /** Require fallbacks to satisfy tag constraints (dripfeed/refill/cancel) when a tag context is known. Default: true */
225
243
  requireConstraintFit?: boolean;
226
- /** Rate rule policy. Default: { kind: 'lte_primary' } i.e. candidate.rate <= primary.rate */
244
+ /** Rate rule policy. Default: { kind: 'lte_primary', pct: 5 }. */
227
245
  ratePolicy?: RatePolicy;
228
246
  /** When multiple candidates remain, choose first (priority) or cheapest. Default: 'priority' */
229
247
  selectionStrategy?: "priority" | "cheapest";
@@ -231,7 +249,6 @@ type FallbackSettings = {
231
249
  mode?: "strict" | "dev";
232
250
  };
233
251
 
234
- type ServiceIdRef = number | string;
235
252
  type NodeIdRef = string;
236
253
  type ServiceFallback = {
237
254
  /** Node-scoped fallbacks: prefer these when that node’s primary service fails */
@@ -375,6 +392,7 @@ interface FallbackEditor {
375
392
  }
376
393
  declare function createFallbackEditor(options?: FallbackEditorOptions): FallbackEditor;
377
394
 
395
+ type ServiceIdRef = IdType;
378
396
  type PricingRole = "base" | "utility";
379
397
  type FieldType = "custom" | (string & {});
380
398
  /** ── Marker types (live inside meta; non-breaking) ───────────────────── */
@@ -508,6 +526,20 @@ type UiValue<U extends Ui> = U extends {
508
526
  } ? {
509
527
  [K in keyof F]?: UiValue<F[K]>;
510
528
  } : unknown;
529
+ type FieldValidationValueBy = "value" | "length" | "eval";
530
+ type FieldValidationOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "between" | "in" | "nin" | "truthy" | "falsy" | "match";
531
+ type FieldValidationRule = {
532
+ valueBy?: FieldValidationValueBy;
533
+ op: FieldValidationOp;
534
+ value?: unknown;
535
+ min?: number;
536
+ max?: number;
537
+ values?: unknown[];
538
+ pattern?: string;
539
+ flags?: string;
540
+ code?: string;
541
+ message?: string;
542
+ };
511
543
  /**
512
544
  * FieldWithTypedDefaults<T>: same shape as BaseFieldUI, but:
513
545
  * - ui is a concrete map T (propName → Ui node)
@@ -523,7 +555,7 @@ type FieldOption = {
523
555
  id: string;
524
556
  label: string;
525
557
  value?: string | number;
526
- service_id?: number;
558
+ service_id?: ServiceIdRef;
527
559
  pricing_role?: PricingRole;
528
560
  meta?: Record<string, unknown> & UtilityMark & WithQuantityDefault;
529
561
  };
@@ -536,6 +568,7 @@ type Field = BaseFieldUI & {
536
568
  description?: string;
537
569
  component?: string;
538
570
  pricing_role?: PricingRole;
571
+ validation?: FieldValidationRule[];
539
572
  meta?: Record<string, unknown> & QuantityMark & UtilityMark & {
540
573
  multi?: boolean;
541
574
  };
@@ -544,7 +577,7 @@ type Field = BaseFieldUI & {
544
577
  service_id?: undefined;
545
578
  } | ({
546
579
  button: true;
547
- service_id?: number;
580
+ service_id?: ServiceIdRef;
548
581
  } & WithQuantityDefault));
549
582
  type ConstraintKey = string;
550
583
  /**
@@ -556,7 +589,7 @@ type Tag = {
556
589
  id: string;
557
590
  label: string;
558
591
  bind_id?: string;
559
- service_id?: number;
592
+ service_id?: ServiceIdRef;
560
593
  includes?: string[];
561
594
  excludes?: string[];
562
595
  meta?: Record<string, unknown> & WithQuantityDefault;
@@ -635,10 +668,10 @@ type GraphSnapshot = {
635
668
  nodes: GraphNode[];
636
669
  edges: GraphEdge[];
637
670
  };
638
- type FlowNode = NodeProps<{
671
+ type FlowNode = NodeProps<Node<{
639
672
  node: GraphNode;
640
673
  [x: string]: any;
641
- }>;
674
+ }, NodeKind>>;
642
675
 
643
676
  type CommentId = string;
644
677
  type ThreadId = string;
@@ -681,6 +714,119 @@ type CommentThread = {
681
714
  _sync?: "pending" | "synced" | "error";
682
715
  };
683
716
 
717
+ type Env = "client" | "workspace";
718
+ type SelectionOptions = {
719
+ env?: Env;
720
+ rootTagId?: string;
721
+ /** Resolve service capability from an id (used for `services` array) */
722
+ resolveService?: (id: any) => DgpServiceCapability | undefined;
723
+ };
724
+
725
+ type CatalogId = string;
726
+ type CatalogServiceId = string | number;
727
+ type CatalogNodeKind = "group" | "smart-group";
728
+ type CatalogSmartRule = {
729
+ type: "service-field";
730
+ field: string;
731
+ op: "eq" | "neq" | "in" | "contains" | "startsWith" | "endsWith" | "gt" | "gte" | "lt" | "lte" | "between" | "exists";
732
+ value?: unknown;
733
+ min?: number;
734
+ max?: number;
735
+ } | {
736
+ type: "policy-family";
737
+ key: string;
738
+ value?: unknown;
739
+ } | {
740
+ type: "compatibility";
741
+ scope: "tag" | "field" | "option" | "visible-group";
742
+ targetId?: string;
743
+ mode: "safe" | "assignable" | "same-family" | "conflicts";
744
+ };
745
+ type CatalogNodeBase = {
746
+ id: CatalogId;
747
+ label: string;
748
+ parentId?: CatalogId;
749
+ description?: string;
750
+ order?: number;
751
+ color?: string;
752
+ icon?: string;
753
+ collapsed?: boolean;
754
+ meta?: Record<string, unknown>;
755
+ };
756
+ type CatalogGroupNode = CatalogNodeBase & {
757
+ kind: "group";
758
+ serviceIds: CatalogServiceId[];
759
+ };
760
+ type CatalogSmartGroupNode = CatalogNodeBase & {
761
+ kind: "smart-group";
762
+ rules: CatalogSmartRule[];
763
+ match: "all" | "any";
764
+ resolvedServiceIds?: CatalogServiceId[];
765
+ resolvedAt?: number;
766
+ };
767
+ type CatalogNode = CatalogGroupNode | CatalogSmartGroupNode;
768
+ type CatalogViewMode = "all" | "grouped" | "smart" | "assigned";
769
+ interface ServiceCatalogState {
770
+ version: 1;
771
+ nodes: CatalogNode[];
772
+ activeNodeId?: CatalogId;
773
+ expandedIds?: CatalogId[];
774
+ pinnedNodeIds?: CatalogId[];
775
+ selectedServiceId?: CatalogServiceId;
776
+ viewMode?: CatalogViewMode;
777
+ meta?: Record<string, unknown>;
778
+ }
779
+
780
+ type EditorEvents = {
781
+ "editor:command": {
782
+ name: string;
783
+ payload?: any;
784
+ };
785
+ "editor:change": {
786
+ props: ServiceProps;
787
+ reason: string;
788
+ command?: string;
789
+ snapshot: EditorSnapshot;
790
+ };
791
+ "editor:undo": {
792
+ stackSize: number;
793
+ index: number;
794
+ };
795
+ "editor:redo": {
796
+ stackSize: number;
797
+ index: number;
798
+ };
799
+ "editor:error": {
800
+ message: string;
801
+ code?: string;
802
+ meta?: any;
803
+ };
804
+ "catalog:change": {
805
+ catalog?: ServiceCatalogState;
806
+ reason: string;
807
+ };
808
+ "catalog:active-change": {
809
+ activeNodeId?: string;
810
+ };
811
+ };
812
+ type Command = {
813
+ name: string;
814
+ do(): void;
815
+ undo(): void;
816
+ };
817
+ type EditorOptions = {
818
+ historyLimit?: number;
819
+ validateAfterEach?: boolean;
820
+ /** Sync existence check; return true if the service exists. */
821
+ serviceExists?: (id: number) => boolean;
822
+ /** Optional local index; used if serviceExists is not provided. */
823
+ serviceMap?: Record<number, unknown>;
824
+ /** Raw policies JSON; will be compiled on demand by filterServicesForVisibleGroup. */
825
+ policiesRaw?: unknown;
826
+ selectionProps?: SelectionOptions;
827
+ };
828
+ type ConnectKind = "bind" | "include" | "exclude";
829
+
684
830
  type Viewport = {
685
831
  x: number;
686
832
  y: number;
@@ -766,7 +912,7 @@ type CanvasEvents = {
766
912
  nextDelayMs?: number;
767
913
  error?: any;
768
914
  };
769
- };
915
+ } & EditorEvents;
770
916
  type NodeView = GraphNode & {
771
917
  position?: NodePos;
772
918
  };
@@ -811,60 +957,11 @@ type EditorSnapshot = {
811
957
  props: ServiceProps;
812
958
  layout?: LayoutState;
813
959
  comments?: CommentNode[];
960
+ catalog?: ServiceCatalogState;
814
961
  meta?: Record<string, unknown>;
815
962
  };
816
963
 
817
- type Env = "client" | "workspace";
818
- type SelectionOptions = {
819
- env?: Env;
820
- rootTagId?: string;
821
- /** Resolve service capability from an id (used for `services` array) */
822
- resolveService?: (id: any) => DgpServiceCapability | undefined;
823
- };
824
-
825
- type EditorEvents = {
826
- "editor:command": {
827
- name: string;
828
- payload?: any;
829
- };
830
- "editor:change": {
831
- props: ServiceProps;
832
- reason: string;
833
- command?: string;
834
- };
835
- "editor:undo": {
836
- stackSize: number;
837
- index: number;
838
- };
839
- "editor:redo": {
840
- stackSize: number;
841
- index: number;
842
- };
843
- "editor:error": {
844
- message: string;
845
- code?: string;
846
- meta?: any;
847
- };
848
- };
849
- type Command = {
850
- name: string;
851
- do(): void;
852
- undo(): void;
853
- };
854
- type EditorOptions = {
855
- historyLimit?: number;
856
- validateAfterEach?: boolean;
857
- /** Sync existence check; return true if the service exists. */
858
- serviceExists?: (id: number) => boolean;
859
- /** Optional local index; used if serviceExists is not provided. */
860
- serviceMap?: Record<number, unknown>;
861
- /** Raw policies JSON; will be compiled on demand by filterServicesForVisibleGroup. */
862
- policiesRaw?: unknown;
863
- selectionProps?: SelectionOptions;
864
- };
865
- type ConnectKind = "bind" | "include" | "exclude";
866
-
867
964
  /** Exported alias so the schema generator can target an array */
868
965
  type AdminPolicies = DynamicRule[];
869
966
 
870
- export { type AdminPolicies, type BaseFieldUI, type ButtonValue, type CanvasEvents, type CanvasOptions, type CanvasState, type Command, type CommentAnchor, type CommentId, type CommentMessage, type CommentNode, type CommentThread, type ConnectKind, type ConstraintKey, type DgpServiceCapability, type DgpServiceMap, type DraftWire, type DynamicRule, type EdgeKind, type EdgeRoute, type EdgeView, type EditorEvents, type EditorOptions, type EditorSnapshot, type FallbackCandidateCheck, type FallbackCheckReason, type FallbackCheckResult, type FallbackDiagnostics, type FallbackEditor, type FallbackEditorOptions, type FallbackEditorServiceMap, type FallbackEditorServiceRecord, type FallbackEditorState, type FallbackMutationOptions, type FallbackRegistration, type FallbackRegistrationScope, type FallbackScopeRef, type FallbackSettings, type Field, type FieldOption, type FieldType, type FieldWithTypedDefaults, type FlagKey, type FlowNode, type GraphEdge, type GraphNode, type GraphSnapshot, type IdType, type LayoutState, type NodeIdRef, type NodeKind, type NodePos, type NodePositions, type NodeView, type NoticeKind, type NoticeSeverity, type NoticeTarget, type NoticeType, type OrderSnapshot, type PricingRole, type QuantityMark, type QuantityRule, type RatePolicy, type Scalar, type ServiceEstimates, type ServiceFallback, type ServiceFallbacks, type ServiceFlag, type ServiceFlags, type ServiceIdRef, type ServiceProps, type ServicePropsNotice, type ServiceWhereClause, type ServiceWhereOp, type SnapshotContext, type SpeedEstimate, type Tag, type ThreadId, type TimeRangeEstimate, type Ui, type UiAnyOf, type UiArray, type UiBoolean, type UiNumber, type UiObject, type UiString, type UiValue, type UtilityLineItem, type UtilityMark, type UtilityMode, type ValidationCode, type ValidationError, type ValidatorOptions, type Viewport, type WithQuantityDefault, createFallbackEditor };
967
+ export { type AdminPolicies, type BaseFieldUI, type ButtonValue, type CanvasEvents, type CanvasOptions, type CanvasState, type CatalogGroupNode, type CatalogId, type CatalogNode, type CatalogNodeBase, type CatalogNodeKind, type CatalogServiceId, type CatalogSmartGroupNode, type CatalogSmartRule, type CatalogViewMode, type Command, type CommentAnchor, type CommentId, type CommentMessage, type CommentNode, type CommentThread, type ConnectKind, type ConstraintKey, type DgpServiceCapability, type DgpServiceMap, type DraftWire, type DynamicRule, type EdgeKind, type EdgeRoute, type EdgeView, type EditorEvents, type EditorOptions, type EditorSnapshot, type FallbackCandidateCheck, type FallbackCheckReason, type FallbackCheckResult, type FallbackDiagnostics, type FallbackEditor, type FallbackEditorOptions, type FallbackEditorServiceMap, type FallbackEditorServiceRecord, type FallbackEditorState, type FallbackMutationOptions, type FallbackRegistration, type FallbackRegistrationScope, type FallbackScopeRef, type FallbackSettings, type Field, type FieldOption, type FieldType, type FieldValidationOp, type FieldValidationRule, type FieldValidationValueBy, type FieldWithTypedDefaults, type FlagKey, type FlowNode, type GraphEdge, type GraphNode, type GraphSnapshot, type IdType, type LayoutState, type NodeIdRef, type NodeKind, type NodePos, type NodePositions, type NodeView, type NoticeKind, type NoticeSeverity, type NoticeTarget, type NoticeType, type OrderSnapshot, type PricingRole, type QuantityMark, type QuantityRule, type RatePolicy, type Scalar, type ServiceCatalogState, type ServiceEstimates, type ServiceFallback, type ServiceFallbacks, type ServiceFlag, type ServiceFlags, type ServiceIdRef, type ServiceProps, type ServicePropsNotice, type ServiceWhereClause, type ServiceWhereOp, type SnapshotContext, type SpeedEstimate, type Tag, type ThreadId, type TimeRangeEstimate, type Ui, type UiAnyOf, type UiArray, type UiBoolean, type UiNumber, type UiObject, type UiString, type UiValue, type UtilityLineItem, type UtilityMark, type UtilityMode, type ValidationCode, type ValidationError, type ValidatorOptions, type Viewport, type WithQuantityDefault, createFallbackEditor };