@eventcatalog/sdk 2.20.0 → 2.21.1

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.ts CHANGED
@@ -184,6 +184,7 @@ interface Service extends BaseSchema {
184
184
  repository?: DetailPanelProperty;
185
185
  owners?: DetailPanelProperty;
186
186
  changelog?: DetailPanelProperty;
187
+ flows?: DetailPanelProperty;
187
188
  };
188
189
  }
189
190
 
@@ -321,6 +322,7 @@ interface DataProduct extends BaseSchema {
321
322
  repository?: DetailPanelProperty;
322
323
  owners?: DetailPanelProperty;
323
324
  changelog?: DetailPanelProperty;
325
+ flows?: DetailPanelProperty;
324
326
  };
325
327
  }
326
328
 
@@ -339,6 +341,8 @@ interface FlowStep {
339
341
  message?: ResourcePointer;
340
342
  service?: ResourcePointer;
341
343
  flow?: ResourcePointer;
344
+ container?: ResourcePointer;
345
+ dataProduct?: ResourcePointer;
342
346
  actor?: {
343
347
  name: string;
344
348
  summary?: string;
@@ -496,6 +500,437 @@ type SnapshotDiff = {
496
500
  relationships: RelationshipChange[];
497
501
  };
498
502
 
503
+ type FlowStepId = string | number;
504
+ type FlowStepPointer = FlowStepId | {
505
+ id: FlowStepId;
506
+ label?: string;
507
+ };
508
+ /**
509
+ * Input used to create a flow builder.
510
+ *
511
+ * This is the normal `Flow` resource shape without requiring `steps` up front.
512
+ * You can pass existing steps if you want to append to a partially built flow.
513
+ */
514
+ type FlowBuilderInput = Omit<Flow, 'steps'> & {
515
+ steps?: FlowStep[];
516
+ };
517
+ /**
518
+ * Payload for a generic flow step.
519
+ *
520
+ * Use generic steps for process milestones that are not messages, services,
521
+ * actors, external systems, sub-flows, or custom nodes.
522
+ */
523
+ type FlowStepInput = {
524
+ id: FlowStepId;
525
+ title?: string;
526
+ summary?: string;
527
+ nextSteps?: FlowStepPointer[];
528
+ };
529
+ /**
530
+ * Payload for a flow step that references an event, command, or query.
531
+ */
532
+ type FlowMessageStepInput<TMessageId extends string = string> = FlowStepInput & {
533
+ message?: {
534
+ id: TMessageId;
535
+ version?: string;
536
+ };
537
+ version?: string;
538
+ };
539
+ /**
540
+ * Payload for a flow step that references a service.
541
+ */
542
+ type FlowServiceStepInput = FlowStepInput & {
543
+ service?: {
544
+ id: string;
545
+ version?: string;
546
+ };
547
+ version?: string;
548
+ };
549
+ /**
550
+ * Payload for a flow step that references a data store/container.
551
+ */
552
+ type FlowDataStoreStepInput = FlowStepInput & {
553
+ container?: {
554
+ id: string;
555
+ version?: string;
556
+ };
557
+ version?: string;
558
+ };
559
+ /**
560
+ * Payload for a flow step that references a data product.
561
+ */
562
+ type FlowDataProductStepInput = FlowStepInput & {
563
+ dataProduct?: {
564
+ id: string;
565
+ version?: string;
566
+ };
567
+ version?: string;
568
+ };
569
+ /**
570
+ * Payload for a flow step that represents a user or actor.
571
+ */
572
+ type FlowActorStepInput = FlowStepInput & {
573
+ actor?: {
574
+ name: string;
575
+ summary?: string;
576
+ };
577
+ name?: string;
578
+ };
579
+ /**
580
+ * Payload for a flow step that represents an external system.
581
+ */
582
+ type FlowExternalSystemStepInput = FlowStepInput & {
583
+ externalSystem?: {
584
+ name: string;
585
+ summary?: string;
586
+ url?: string;
587
+ };
588
+ name?: string;
589
+ url?: string;
590
+ };
591
+ /**
592
+ * Payload for a flow step that references another flow.
593
+ */
594
+ type FlowSubFlowStepInput = FlowStepInput & {
595
+ flow?: {
596
+ id: string;
597
+ version?: string;
598
+ };
599
+ version?: string;
600
+ };
601
+ /**
602
+ * Payload for a custom flow step.
603
+ */
604
+ type FlowCustomStepInput = FlowStepInput & {
605
+ custom?: {
606
+ title: string;
607
+ icon?: string;
608
+ type?: string;
609
+ summary?: string;
610
+ url?: string;
611
+ color?: string;
612
+ properties?: Record<string, string | number>;
613
+ height?: number;
614
+ menu?: {
615
+ label: string;
616
+ url?: string;
617
+ }[];
618
+ };
619
+ icon?: string;
620
+ type?: string;
621
+ url?: string;
622
+ color?: string;
623
+ properties?: Record<string, string | number>;
624
+ height?: number;
625
+ menu?: {
626
+ label: string;
627
+ url?: string;
628
+ }[];
629
+ };
630
+ /**
631
+ * Build EventCatalog flow resources using a fluent API.
632
+ *
633
+ * `FlowBuilder` is useful when you want to define flows in code and then write
634
+ * the generated `Flow` resource with `writeFlow`. The builder outputs the normal
635
+ * EventCatalog `Flow` shape, so the persisted catalog remains standard
636
+ * markdown/frontmatter.
637
+ *
638
+ * `nextSteps` is the authoring API. When `build()` is called, a single next step
639
+ * is normalized to `next_step` and multiple next steps are normalized to
640
+ * `next_steps`.
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * import utils, { FlowBuilder } from '@eventcatalog/sdk';
645
+ *
646
+ * const { writeFlow } = utils('/path/to/eventcatalog');
647
+ *
648
+ * const flow = FlowBuilder.create({
649
+ * id: 'PaymentFlow',
650
+ * name: 'Payment Flow',
651
+ * version: '1.0.0',
652
+ * markdown: '# Payment Flow',
653
+ * })
654
+ * .addStep({
655
+ * id: 'Customer places order',
656
+ * nextSteps: [{ id: 'PlaceOrder', label: 'places order' }],
657
+ * })
658
+ * .addMessageStep({
659
+ * id: 'PlaceOrder',
660
+ * message: { id: 'PlaceOrder' },
661
+ * nextSteps: [{ id: 'PaymentService', label: 'process payment' }],
662
+ * })
663
+ * .addServiceStep({
664
+ * id: 'PaymentService',
665
+ * service: { id: 'PaymentService' },
666
+ * })
667
+ * .build();
668
+ *
669
+ * await writeFlow(flow);
670
+ * ```
671
+ *
672
+ * @example
673
+ * ```ts
674
+ * import { FlowBuilder } from '@eventcatalog/sdk';
675
+ *
676
+ * type PaymentMessageId = 'PlaceOrder' | 'PaymentProcessed';
677
+ *
678
+ * const flow = FlowBuilder.create<PaymentMessageId>({
679
+ * id: 'TypedPaymentFlow',
680
+ * name: 'Typed Payment Flow',
681
+ * version: '1.0.0',
682
+ * markdown: '# Typed Payment Flow',
683
+ * })
684
+ * .addMessageStep({
685
+ * id: 'PlaceOrder',
686
+ * nextSteps: [{ id: 'PaymentProcessed' }],
687
+ * })
688
+ * .addMessageStep({
689
+ * id: 'PaymentProcessed',
690
+ * })
691
+ * .build();
692
+ * ```
693
+ */
694
+ declare class FlowBuilder<TMessageId extends string = string> {
695
+ private readonly flowResource;
696
+ private readonly steps;
697
+ private readonly order;
698
+ private constructor();
699
+ /**
700
+ * Create a flow builder.
701
+ *
702
+ * The created builder can add steps and then produce a normal `Flow` resource
703
+ * with `build()`.
704
+ *
705
+ * @example
706
+ * ```ts
707
+ * const flow = FlowBuilder.create({
708
+ * id: 'PaymentFlow',
709
+ * name: 'Payment Flow',
710
+ * version: '1.0.0',
711
+ * markdown: '# Payment Flow',
712
+ * }).build();
713
+ * ```
714
+ */
715
+ static create<TMessageId extends string = string>(flow: FlowBuilderInput): FlowBuilder<TMessageId>;
716
+ /**
717
+ * Add a generic flow step.
718
+ *
719
+ * Generic steps are useful for business process stages that do not map to
720
+ * another catalog resource.
721
+ *
722
+ * @param step - The step payload.
723
+ *
724
+ * @example
725
+ * ```ts
726
+ * FlowBuilder.create({
727
+ * id: 'OrderFlow',
728
+ * name: 'Order Flow',
729
+ * version: '1.0.0',
730
+ * markdown: '',
731
+ * })
732
+ * .addStep({
733
+ * id: 'Calculate',
734
+ * title: 'Calculate totals',
735
+ * nextSteps: [{ id: 'OrderConfirmed' }],
736
+ * });
737
+ * ```
738
+ */
739
+ addStep(step: FlowStepInput): this;
740
+ /**
741
+ * Add a message step.
742
+ *
743
+ * Message steps can reference an event, command, or query id.
744
+ *
745
+ * @param step - The message step payload.
746
+ *
747
+ * @example
748
+ * ```ts
749
+ * FlowBuilder.create({
750
+ * id: 'OrderFlow',
751
+ * name: 'Order Flow',
752
+ * version: '1.0.0',
753
+ * markdown: '',
754
+ * })
755
+ * .addMessageStep({
756
+ * id: 'OrderConfirmed',
757
+ * title: 'Order confirmed',
758
+ * message: { id: 'OrderConfirmed', version: '1.0.0' },
759
+ * });
760
+ * ```
761
+ */
762
+ addMessageStep(step: FlowMessageStepInput<TMessageId>): this;
763
+ /**
764
+ * Add a service step.
765
+ *
766
+ * @param step - The service step payload.
767
+ *
768
+ * @example
769
+ * ```ts
770
+ * FlowBuilder.create({
771
+ * id: 'OrderFlow',
772
+ * name: 'Order Flow',
773
+ * version: '1.0.0',
774
+ * markdown: '',
775
+ * })
776
+ * .addServiceStep({
777
+ * id: 'OrderService',
778
+ * service: { id: 'OrderService', version: '1.0.0' },
779
+ * });
780
+ * ```
781
+ */
782
+ addServiceStep(step: FlowServiceStepInput): this;
783
+ /**
784
+ * Add a data store step.
785
+ *
786
+ * Data store steps reference container resources in EventCatalog. If a
787
+ * version is not provided, EventCatalog resolves the latest matching
788
+ * container version when rendering the flow.
789
+ *
790
+ * @param step - The data store step payload.
791
+ *
792
+ * @example
793
+ * ```ts
794
+ * FlowBuilder.create({
795
+ * id: 'OrderFlow',
796
+ * name: 'Order Flow',
797
+ * version: '1.0.0',
798
+ * markdown: '',
799
+ * })
800
+ * .addDataStoreStep({
801
+ * id: 'OrdersDB',
802
+ * container: { id: 'OrdersDB', version: '1.0.0' },
803
+ * });
804
+ * ```
805
+ */
806
+ addDataStoreStep(step: FlowDataStoreStepInput): this;
807
+ /**
808
+ * Add a container step.
809
+ *
810
+ * Alias for `addDataStoreStep`.
811
+ */
812
+ addContainerStep(step: FlowDataStoreStepInput): this;
813
+ /**
814
+ * Add a data product step.
815
+ *
816
+ * If a version is not provided, EventCatalog resolves the latest matching
817
+ * data product version when rendering the flow.
818
+ *
819
+ * @param step - The data product step payload.
820
+ *
821
+ * @example
822
+ * ```ts
823
+ * FlowBuilder.create({
824
+ * id: 'OrderFlow',
825
+ * name: 'Order Flow',
826
+ * version: '1.0.0',
827
+ * markdown: '',
828
+ * })
829
+ * .addDataProductStep({
830
+ * id: 'OrderAnalytics',
831
+ * dataProduct: { id: 'OrderAnalytics', version: '1.0.0' },
832
+ * });
833
+ * ```
834
+ */
835
+ addDataProductStep(step: FlowDataProductStepInput): this;
836
+ /**
837
+ * Add an actor step.
838
+ *
839
+ * @param step - The actor step payload.
840
+ *
841
+ * @example
842
+ * ```ts
843
+ * FlowBuilder.create({
844
+ * id: 'OrderFlow',
845
+ * name: 'Order Flow',
846
+ * version: '1.0.0',
847
+ * markdown: '',
848
+ * })
849
+ * .addActorStep({
850
+ * id: 'Customer',
851
+ * actor: { name: 'Customer' },
852
+ * });
853
+ * ```
854
+ */
855
+ addActorStep(step: FlowActorStepInput): this;
856
+ /**
857
+ * Add an external system step.
858
+ *
859
+ * @param step - The external system step payload.
860
+ *
861
+ * @example
862
+ * ```ts
863
+ * FlowBuilder.create({
864
+ * id: 'PaymentFlow',
865
+ * name: 'Payment Flow',
866
+ * version: '1.0.0',
867
+ * markdown: '',
868
+ * })
869
+ * .addExternalSystemStep({
870
+ * id: 'Stripe',
871
+ * externalSystem: {
872
+ * name: 'Stripe',
873
+ * summary: 'Payment provider',
874
+ * url: 'https://stripe.com',
875
+ * },
876
+ * });
877
+ * ```
878
+ */
879
+ addExternalSystemStep(step: FlowExternalSystemStepInput): this;
880
+ /**
881
+ * Add a sub-flow step.
882
+ *
883
+ * @param step - The sub-flow step payload.
884
+ *
885
+ * @example
886
+ * ```ts
887
+ * FlowBuilder.create({
888
+ * id: 'OrderFlow',
889
+ * name: 'Order Flow',
890
+ * version: '1.0.0',
891
+ * markdown: '',
892
+ * })
893
+ * .addFlowStep({
894
+ * id: 'PaymentFlow',
895
+ * flow: { id: 'PaymentFlow', version: '1.0.0' },
896
+ * });
897
+ * ```
898
+ */
899
+ addFlowStep(step: FlowSubFlowStepInput): this;
900
+ /**
901
+ * Add a custom flow step.
902
+ *
903
+ * @param step - The custom step payload.
904
+ *
905
+ * @example
906
+ * ```ts
907
+ * FlowBuilder.create({
908
+ * id: 'PaymentFlow',
909
+ * name: 'Payment Flow',
910
+ * version: '1.0.0',
911
+ * markdown: '',
912
+ * })
913
+ * .addCustomStep({
914
+ * id: 'ManualReview',
915
+ * custom: {
916
+ * title: 'Manual review',
917
+ * type: 'manual',
918
+ * },
919
+ * });
920
+ * ```
921
+ */
922
+ addCustomStep(step: FlowCustomStepInput): this;
923
+ /**
924
+ * Build the EventCatalog flow resource.
925
+ *
926
+ * @returns A `Flow` resource that can be written with `writeFlow`.
927
+ */
928
+ build(): Flow;
929
+ private addStepWithNext;
930
+ private appendStep;
931
+ private validateNextSteps;
932
+ }
933
+
499
934
  /**
500
935
  * Init the SDK for EventCatalog
501
936
  *
@@ -981,7 +1416,14 @@ declare const _default: (path: string) => {
981
1416
  path?: string;
982
1417
  override?: boolean;
983
1418
  versionExistingContent?: boolean;
984
- format?: "md" | "mdx";
1419
+ format? /**
1420
+ * Adds an event to a service in EventCatalog
1421
+ *
1422
+ * @param event - The event to write to the service
1423
+ * @param service - The service and it's id to write to the event to
1424
+ * @param options - Optional options to write the event
1425
+ *
1426
+ */: "md" | "mdx";
985
1427
  }) => Promise<void>;
986
1428
  /**
987
1429
  * Adds a versioned service to EventCatalog
@@ -1003,7 +1445,12 @@ declare const _default: (path: string) => {
1003
1445
  version?: string;
1004
1446
  direction?: string;
1005
1447
  }, options?: {
1006
- path?: string;
1448
+ path? /**
1449
+ * Returns a command from EventCatalog
1450
+ * @param id - The id of the command to retrieve
1451
+ * @param version - Optional id of the version to get (supports semver)
1452
+ * @returns Command|Undefined
1453
+ */: string;
1007
1454
  format?: "md" | "mdx";
1008
1455
  override?: boolean;
1009
1456
  }) => Promise<void>;
@@ -1225,12 +1672,7 @@ declare const _default: (path: string) => {
1225
1672
  */
1226
1673
  writeDomain: (domain: Domain, options?: {
1227
1674
  path?: string;
1228
- override? /**
1229
- * Remove an event by an Event id
1230
- *
1231
- * @param id - The id of the event you want to remove
1232
- *
1233
- */: boolean;
1675
+ override?: boolean;
1234
1676
  versionExistingContent?: boolean;
1235
1677
  format?: "md" | "mdx";
1236
1678
  }) => Promise<void>;
@@ -1725,6 +2167,95 @@ declare const _default: (path: string) => {
1725
2167
  getFlows: (options?: {
1726
2168
  latestOnly?: boolean;
1727
2169
  }) => Promise<Flow[]>;
2170
+ /**
2171
+ * Adds a flow to EventCatalog
2172
+ *
2173
+ * @param flow - The flow to write
2174
+ * @param options - Optional options to write the flow
2175
+ *
2176
+ */
2177
+ writeFlow: (flow: Flow, options?: {
2178
+ path?: string;
2179
+ override?: boolean;
2180
+ versionExistingContent?: boolean;
2181
+ format?: "md" | "mdx";
2182
+ }) => Promise<void>;
2183
+ /**
2184
+ * Adds a versioned flow to EventCatalog
2185
+ *
2186
+ * @param flow - The flow to write
2187
+ *
2188
+ */
2189
+ writeVersionedFlow: (flow: Flow) => Promise<void>;
2190
+ /**
2191
+ * Adds a flow to a domain in EventCatalog
2192
+ *
2193
+ * @param flow - The flow to write to the domain
2194
+ * @param domain - The domain and its id to write the flow to
2195
+ * @param options - Optional options to write the flow
2196
+ *
2197
+ */
2198
+ writeFlowToDomain: (flow: Flow, domain: {
2199
+ id: string;
2200
+ version?: string;
2201
+ }, options?: {
2202
+ path?: string;
2203
+ format?: "md" | "mdx";
2204
+ override?: boolean;
2205
+ }) => Promise<void>;
2206
+ /**
2207
+ * Adds a flow to a service in EventCatalog
2208
+ *
2209
+ * @param flow - The flow to write to the service
2210
+ * @param service - The service and its id to write the flow to
2211
+ * @param options - Optional options to write the flow
2212
+ *
2213
+ */
2214
+ writeFlowToService: (flow: Flow, service: {
2215
+ id: string;
2216
+ version?: string;
2217
+ }, options?: {
2218
+ path?: string;
2219
+ format?: "md" | "mdx";
2220
+ override?: boolean;
2221
+ }) => Promise<void>;
2222
+ /**
2223
+ * Remove a flow from EventCatalog (modeled on the standard POSIX rm utility)
2224
+ *
2225
+ * @param path - The path to your flow, e.g. `/PaymentFlow`
2226
+ *
2227
+ */
2228
+ rmFlow: (path: string) => Promise<void>;
2229
+ /**
2230
+ * Remove a flow by a flow id
2231
+ *
2232
+ * @param id - The id of the flow you want to remove
2233
+ *
2234
+ */
2235
+ rmFlowById: (id: string, version?: string, persistFiles?: boolean) => Promise<void>;
2236
+ /**
2237
+ * Moves a given flow id to the version directory
2238
+ * @param id - The id of the flow to version
2239
+ */
2240
+ versionFlow: (id: string) => Promise<void>;
2241
+ /**
2242
+ * Check to see if a flow version exists
2243
+ * @param id - The id of the flow
2244
+ * @param version - The version of the flow (supports semver)
2245
+ * @returns
2246
+ */
2247
+ flowHasVersion: (id: string, version?: string) => Promise<boolean>;
2248
+ /**
2249
+ * Adds a file to the given flow
2250
+ * @param id - The id of the flow to add the file to
2251
+ * @param file - File contents to add including the content and the file name
2252
+ * @param version - Optional version of the flow to add the file to
2253
+ * @returns
2254
+ */
2255
+ addFileToFlow: (id: string, file: {
2256
+ content: string;
2257
+ fileName: string;
2258
+ }, version?: string) => Promise<void>;
1728
2259
  /**
1729
2260
  * ================================
1730
2261
  * Data Stores
@@ -1990,4 +2521,4 @@ declare const _default: (path: string) => {
1990
2521
  toDSL: (resource: (Event | Command | Query | Service | Domain) | (Event | Command | Query | Service | Domain)[], options: ToDSLOptions) => Promise<string>;
1991
2522
  };
1992
2523
 
1993
- export { type Badge, type BaseSchema, type CatalogSnapshot, type Changelog, type Channel, type ChannelPointer, type Command, type Container, type CustomDoc, type DataProduct, type DataProductOutputPointer, type Diagram, type DiffSummary, type Domain, type Entity, type Event, type EventCatalog, type Flow, type FlowStep, type Message, type Operation, type Query, type ReceivesPointer, type RelationshipChange, type ResourceChange, type ResourceChangeType, type ResourceGroup, type ResourcePointer, type SendsPointer, type Service, type SnapshotDiff, type SnapshotGitInfo, type SnapshotMeta, type SnapshotOptions, type SnapshotResourceType, type SnapshotResources, type SnapshotResult, type Specification, type Specifications, type Team, type UbiquitousLanguage, type UbiquitousLanguageDictionary, type User, _default as default };
2524
+ export { type Badge, type BaseSchema, type CatalogSnapshot, type Changelog, type Channel, type ChannelPointer, type Command, type Container, type CustomDoc, type DataProduct, type DataProductOutputPointer, type Diagram, type DiffSummary, type Domain, type Entity, type Event, type EventCatalog, type Flow, type FlowActorStepInput, FlowBuilder, type FlowBuilderInput, type FlowCustomStepInput, type FlowDataProductStepInput, type FlowDataStoreStepInput, type FlowExternalSystemStepInput, type FlowMessageStepInput, type FlowServiceStepInput, type FlowStep, type FlowStepInput, type FlowSubFlowStepInput, type Message, type Operation, type Query, type ReceivesPointer, type RelationshipChange, type ResourceChange, type ResourceChangeType, type ResourceGroup, type ResourcePointer, type SendsPointer, type Service, type SnapshotDiff, type SnapshotGitInfo, type SnapshotMeta, type SnapshotOptions, type SnapshotResourceType, type SnapshotResources, type SnapshotResult, type Specification, type Specifications, type Team, type UbiquitousLanguage, type UbiquitousLanguageDictionary, type User, _default as default };