@eventcatalog/sdk 2.19.0 → 2.21.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.mts CHANGED
@@ -173,6 +173,7 @@ interface Service extends BaseSchema {
173
173
  writesTo?: ResourcePointer[];
174
174
  readsFrom?: ResourcePointer[];
175
175
  flows?: ResourcePointer[];
176
+ externalSystem?: boolean;
176
177
  specifications?: Specifications | Specification[];
177
178
  detailsPanel?: {
178
179
  domains?: DetailPanelProperty;
@@ -495,6 +496,364 @@ type SnapshotDiff = {
495
496
  relationships: RelationshipChange[];
496
497
  };
497
498
 
499
+ type FlowStepId = string | number;
500
+ type FlowStepPointer = FlowStepId | {
501
+ id: FlowStepId;
502
+ label?: string;
503
+ };
504
+ /**
505
+ * Input used to create a flow builder.
506
+ *
507
+ * This is the normal `Flow` resource shape without requiring `steps` up front.
508
+ * You can pass existing steps if you want to append to a partially built flow.
509
+ */
510
+ type FlowBuilderInput = Omit<Flow, 'steps'> & {
511
+ steps?: FlowStep[];
512
+ };
513
+ /**
514
+ * Payload for a generic flow step.
515
+ *
516
+ * Use generic steps for process milestones that are not messages, services,
517
+ * actors, external systems, sub-flows, or custom nodes.
518
+ */
519
+ type FlowStepInput = {
520
+ id: FlowStepId;
521
+ title?: string;
522
+ summary?: string;
523
+ nextSteps?: FlowStepPointer[];
524
+ };
525
+ /**
526
+ * Payload for a flow step that references an event, command, or query.
527
+ */
528
+ type FlowMessageStepInput<TMessageId extends string = string> = FlowStepInput & {
529
+ message?: {
530
+ id: TMessageId;
531
+ version?: string;
532
+ };
533
+ version?: string;
534
+ };
535
+ /**
536
+ * Payload for a flow step that references a service.
537
+ */
538
+ type FlowServiceStepInput = FlowStepInput & {
539
+ service?: {
540
+ id: string;
541
+ version?: string;
542
+ };
543
+ version?: string;
544
+ };
545
+ /**
546
+ * Payload for a flow step that represents a user or actor.
547
+ */
548
+ type FlowActorStepInput = FlowStepInput & {
549
+ actor?: {
550
+ name: string;
551
+ summary?: string;
552
+ };
553
+ name?: string;
554
+ };
555
+ /**
556
+ * Payload for a flow step that represents an external system.
557
+ */
558
+ type FlowExternalSystemStepInput = FlowStepInput & {
559
+ externalSystem?: {
560
+ name: string;
561
+ summary?: string;
562
+ url?: string;
563
+ };
564
+ name?: string;
565
+ url?: string;
566
+ };
567
+ /**
568
+ * Payload for a flow step that references another flow.
569
+ */
570
+ type FlowSubFlowStepInput = FlowStepInput & {
571
+ flow?: {
572
+ id: string;
573
+ version?: string;
574
+ };
575
+ version?: string;
576
+ };
577
+ /**
578
+ * Payload for a custom flow step.
579
+ */
580
+ type FlowCustomStepInput = FlowStepInput & {
581
+ custom?: {
582
+ title: string;
583
+ icon?: string;
584
+ type?: string;
585
+ summary?: string;
586
+ url?: string;
587
+ color?: string;
588
+ properties?: Record<string, string | number>;
589
+ height?: number;
590
+ menu?: {
591
+ label: string;
592
+ url?: string;
593
+ }[];
594
+ };
595
+ icon?: string;
596
+ type?: string;
597
+ url?: string;
598
+ color?: string;
599
+ properties?: Record<string, string | number>;
600
+ height?: number;
601
+ menu?: {
602
+ label: string;
603
+ url?: string;
604
+ }[];
605
+ };
606
+ /**
607
+ * Build EventCatalog flow resources using a fluent API.
608
+ *
609
+ * `FlowBuilder` is useful when you want to define flows in code and then write
610
+ * the generated `Flow` resource with `writeFlow`. The builder outputs the normal
611
+ * EventCatalog `Flow` shape, so the persisted catalog remains standard
612
+ * markdown/frontmatter.
613
+ *
614
+ * `nextSteps` is the authoring API. When `build()` is called, a single next step
615
+ * is normalized to `next_step` and multiple next steps are normalized to
616
+ * `next_steps`.
617
+ *
618
+ * @example
619
+ * ```ts
620
+ * import utils, { FlowBuilder } from '@eventcatalog/sdk';
621
+ *
622
+ * const { writeFlow } = utils('/path/to/eventcatalog');
623
+ *
624
+ * const flow = FlowBuilder.create({
625
+ * id: 'PaymentFlow',
626
+ * name: 'Payment Flow',
627
+ * version: '1.0.0',
628
+ * markdown: '# Payment Flow',
629
+ * })
630
+ * .addStep({
631
+ * id: 'Customer places order',
632
+ * nextSteps: [{ id: 'PlaceOrder', label: 'places order' }],
633
+ * })
634
+ * .addMessageStep({
635
+ * id: 'PlaceOrder',
636
+ * message: { id: 'PlaceOrder' },
637
+ * nextSteps: [{ id: 'PaymentService', label: 'process payment' }],
638
+ * })
639
+ * .addServiceStep({
640
+ * id: 'PaymentService',
641
+ * service: { id: 'PaymentService' },
642
+ * })
643
+ * .build();
644
+ *
645
+ * await writeFlow(flow);
646
+ * ```
647
+ *
648
+ * @example
649
+ * ```ts
650
+ * import { FlowBuilder } from '@eventcatalog/sdk';
651
+ *
652
+ * type PaymentMessageId = 'PlaceOrder' | 'PaymentProcessed';
653
+ *
654
+ * const flow = FlowBuilder.create<PaymentMessageId>({
655
+ * id: 'TypedPaymentFlow',
656
+ * name: 'Typed Payment Flow',
657
+ * version: '1.0.0',
658
+ * markdown: '# Typed Payment Flow',
659
+ * })
660
+ * .addMessageStep({
661
+ * id: 'PlaceOrder',
662
+ * nextSteps: [{ id: 'PaymentProcessed' }],
663
+ * })
664
+ * .addMessageStep({
665
+ * id: 'PaymentProcessed',
666
+ * })
667
+ * .build();
668
+ * ```
669
+ */
670
+ declare class FlowBuilder<TMessageId extends string = string> {
671
+ private readonly flowResource;
672
+ private readonly steps;
673
+ private readonly order;
674
+ private constructor();
675
+ /**
676
+ * Create a flow builder.
677
+ *
678
+ * The created builder can add steps and then produce a normal `Flow` resource
679
+ * with `build()`.
680
+ *
681
+ * @example
682
+ * ```ts
683
+ * const flow = FlowBuilder.create({
684
+ * id: 'PaymentFlow',
685
+ * name: 'Payment Flow',
686
+ * version: '1.0.0',
687
+ * markdown: '# Payment Flow',
688
+ * }).build();
689
+ * ```
690
+ */
691
+ static create<TMessageId extends string = string>(flow: FlowBuilderInput): FlowBuilder<TMessageId>;
692
+ /**
693
+ * Add a generic flow step.
694
+ *
695
+ * Generic steps are useful for business process stages that do not map to
696
+ * another catalog resource.
697
+ *
698
+ * @param step - The step payload.
699
+ *
700
+ * @example
701
+ * ```ts
702
+ * FlowBuilder.create({
703
+ * id: 'OrderFlow',
704
+ * name: 'Order Flow',
705
+ * version: '1.0.0',
706
+ * markdown: '',
707
+ * })
708
+ * .addStep({
709
+ * id: 'Calculate',
710
+ * title: 'Calculate totals',
711
+ * nextSteps: [{ id: 'OrderConfirmed' }],
712
+ * });
713
+ * ```
714
+ */
715
+ addStep(step: FlowStepInput): this;
716
+ /**
717
+ * Add a message step.
718
+ *
719
+ * Message steps can reference an event, command, or query id.
720
+ *
721
+ * @param step - The message step payload.
722
+ *
723
+ * @example
724
+ * ```ts
725
+ * FlowBuilder.create({
726
+ * id: 'OrderFlow',
727
+ * name: 'Order Flow',
728
+ * version: '1.0.0',
729
+ * markdown: '',
730
+ * })
731
+ * .addMessageStep({
732
+ * id: 'OrderConfirmed',
733
+ * title: 'Order confirmed',
734
+ * message: { id: 'OrderConfirmed', version: '1.0.0' },
735
+ * });
736
+ * ```
737
+ */
738
+ addMessageStep(step: FlowMessageStepInput<TMessageId>): this;
739
+ /**
740
+ * Add a service step.
741
+ *
742
+ * @param step - The service step payload.
743
+ *
744
+ * @example
745
+ * ```ts
746
+ * FlowBuilder.create({
747
+ * id: 'OrderFlow',
748
+ * name: 'Order Flow',
749
+ * version: '1.0.0',
750
+ * markdown: '',
751
+ * })
752
+ * .addServiceStep({
753
+ * id: 'OrderService',
754
+ * service: { id: 'OrderService', version: '1.0.0' },
755
+ * });
756
+ * ```
757
+ */
758
+ addServiceStep(step: FlowServiceStepInput): this;
759
+ /**
760
+ * Add an actor step.
761
+ *
762
+ * @param step - The actor step payload.
763
+ *
764
+ * @example
765
+ * ```ts
766
+ * FlowBuilder.create({
767
+ * id: 'OrderFlow',
768
+ * name: 'Order Flow',
769
+ * version: '1.0.0',
770
+ * markdown: '',
771
+ * })
772
+ * .addActorStep({
773
+ * id: 'Customer',
774
+ * actor: { name: 'Customer' },
775
+ * });
776
+ * ```
777
+ */
778
+ addActorStep(step: FlowActorStepInput): this;
779
+ /**
780
+ * Add an external system step.
781
+ *
782
+ * @param step - The external system step payload.
783
+ *
784
+ * @example
785
+ * ```ts
786
+ * FlowBuilder.create({
787
+ * id: 'PaymentFlow',
788
+ * name: 'Payment Flow',
789
+ * version: '1.0.0',
790
+ * markdown: '',
791
+ * })
792
+ * .addExternalSystemStep({
793
+ * id: 'Stripe',
794
+ * externalSystem: {
795
+ * name: 'Stripe',
796
+ * summary: 'Payment provider',
797
+ * url: 'https://stripe.com',
798
+ * },
799
+ * });
800
+ * ```
801
+ */
802
+ addExternalSystemStep(step: FlowExternalSystemStepInput): this;
803
+ /**
804
+ * Add a sub-flow step.
805
+ *
806
+ * @param step - The sub-flow step payload.
807
+ *
808
+ * @example
809
+ * ```ts
810
+ * FlowBuilder.create({
811
+ * id: 'OrderFlow',
812
+ * name: 'Order Flow',
813
+ * version: '1.0.0',
814
+ * markdown: '',
815
+ * })
816
+ * .addFlowStep({
817
+ * id: 'PaymentFlow',
818
+ * flow: { id: 'PaymentFlow', version: '1.0.0' },
819
+ * });
820
+ * ```
821
+ */
822
+ addFlowStep(step: FlowSubFlowStepInput): this;
823
+ /**
824
+ * Add a custom flow step.
825
+ *
826
+ * @param step - The custom step payload.
827
+ *
828
+ * @example
829
+ * ```ts
830
+ * FlowBuilder.create({
831
+ * id: 'PaymentFlow',
832
+ * name: 'Payment Flow',
833
+ * version: '1.0.0',
834
+ * markdown: '',
835
+ * })
836
+ * .addCustomStep({
837
+ * id: 'ManualReview',
838
+ * custom: {
839
+ * title: 'Manual review',
840
+ * type: 'manual',
841
+ * },
842
+ * });
843
+ * ```
844
+ */
845
+ addCustomStep(step: FlowCustomStepInput): this;
846
+ /**
847
+ * Build the EventCatalog flow resource.
848
+ *
849
+ * @returns A `Flow` resource that can be written with `writeFlow`.
850
+ */
851
+ build(): Flow;
852
+ private addStepWithNext;
853
+ private appendStep;
854
+ private validateNextSteps;
855
+ }
856
+
498
857
  /**
499
858
  * Init the SDK for EventCatalog
500
859
  *
@@ -1224,10 +1583,17 @@ declare const _default: (path: string) => {
1224
1583
  */
1225
1584
  writeDomain: (domain: Domain, options?: {
1226
1585
  path?: string;
1227
- override? /**
1228
- * Remove an event by an Event id
1586
+ override
1587
+ /**
1588
+ * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
1229
1589
  *
1230
- * @param id - The id of the event you want to remove
1590
+ * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
1591
+ *
1592
+ */
1593
+ ? /**
1594
+ * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
1595
+ *
1596
+ * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
1231
1597
  *
1232
1598
  */: boolean;
1233
1599
  versionExistingContent?: boolean;
@@ -1724,6 +2090,95 @@ declare const _default: (path: string) => {
1724
2090
  getFlows: (options?: {
1725
2091
  latestOnly?: boolean;
1726
2092
  }) => Promise<Flow[]>;
2093
+ /**
2094
+ * Adds a flow to EventCatalog
2095
+ *
2096
+ * @param flow - The flow to write
2097
+ * @param options - Optional options to write the flow
2098
+ *
2099
+ */
2100
+ writeFlow: (flow: Flow, options?: {
2101
+ path?: string;
2102
+ override?: boolean;
2103
+ versionExistingContent?: boolean;
2104
+ format?: "md" | "mdx";
2105
+ }) => Promise<void>;
2106
+ /**
2107
+ * Adds a versioned flow to EventCatalog
2108
+ *
2109
+ * @param flow - The flow to write
2110
+ *
2111
+ */
2112
+ writeVersionedFlow: (flow: Flow) => Promise<void>;
2113
+ /**
2114
+ * Adds a flow to a domain in EventCatalog
2115
+ *
2116
+ * @param flow - The flow to write to the domain
2117
+ * @param domain - The domain and its id to write the flow to
2118
+ * @param options - Optional options to write the flow
2119
+ *
2120
+ */
2121
+ writeFlowToDomain: (flow: Flow, domain: {
2122
+ id: string;
2123
+ version?: string;
2124
+ }, options?: {
2125
+ path?: string;
2126
+ format?: "md" | "mdx";
2127
+ override?: boolean;
2128
+ }) => Promise<void>;
2129
+ /**
2130
+ * Adds a flow to a service in EventCatalog
2131
+ *
2132
+ * @param flow - The flow to write to the service
2133
+ * @param service - The service and its id to write the flow to
2134
+ * @param options - Optional options to write the flow
2135
+ *
2136
+ */
2137
+ writeFlowToService: (flow: Flow, service: {
2138
+ id: string;
2139
+ version?: string;
2140
+ }, options?: {
2141
+ path?: string;
2142
+ format?: "md" | "mdx";
2143
+ override?: boolean;
2144
+ }) => Promise<void>;
2145
+ /**
2146
+ * Remove a flow from EventCatalog (modeled on the standard POSIX rm utility)
2147
+ *
2148
+ * @param path - The path to your flow, e.g. `/PaymentFlow`
2149
+ *
2150
+ */
2151
+ rmFlow: (path: string) => Promise<void>;
2152
+ /**
2153
+ * Remove a flow by a flow id
2154
+ *
2155
+ * @param id - The id of the flow you want to remove
2156
+ *
2157
+ */
2158
+ rmFlowById: (id: string, version?: string, persistFiles?: boolean) => Promise<void>;
2159
+ /**
2160
+ * Moves a given flow id to the version directory
2161
+ * @param id - The id of the flow to version
2162
+ */
2163
+ versionFlow: (id: string) => Promise<void>;
2164
+ /**
2165
+ * Check to see if a flow version exists
2166
+ * @param id - The id of the flow
2167
+ * @param version - The version of the flow (supports semver)
2168
+ * @returns
2169
+ */
2170
+ flowHasVersion: (id: string, version?: string) => Promise<boolean>;
2171
+ /**
2172
+ * Adds a file to the given flow
2173
+ * @param id - The id of the flow to add the file to
2174
+ * @param file - File contents to add including the content and the file name
2175
+ * @param version - Optional version of the flow to add the file to
2176
+ * @returns
2177
+ */
2178
+ addFileToFlow: (id: string, file: {
2179
+ content: string;
2180
+ fileName: string;
2181
+ }, version?: string) => Promise<void>;
1727
2182
  /**
1728
2183
  * ================================
1729
2184
  * Data Stores
@@ -1801,7 +2256,12 @@ declare const _default: (path: string) => {
1801
2256
  }, options?: {
1802
2257
  path?: string;
1803
2258
  format?: "md" | "mdx";
1804
- override?: boolean;
2259
+ override? /**
2260
+ * Returns a command from EventCatalog
2261
+ * @param id - The id of the command to retrieve
2262
+ * @param version - Optional id of the version to get (supports semver)
2263
+ * @returns Command|Undefined
2264
+ */: boolean;
1805
2265
  }) => Promise<void>;
1806
2266
  /**
1807
2267
  * ================================
@@ -1989,4 +2449,4 @@ declare const _default: (path: string) => {
1989
2449
  toDSL: (resource: (Event | Command | Query | Service | Domain) | (Event | Command | Query | Service | Domain)[], options: ToDSLOptions) => Promise<string>;
1990
2450
  };
1991
2451
 
1992
- 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 };
2452
+ 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 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 };