From f1182d08eb8b4659e582af0992efed2222a4bb17 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Mon, 17 Nov 2025 15:55:27 +0100 Subject: [PATCH] chore: clean stack v1 support --- cmd/orchestration/instances/describe.go | 109 +++++----- cmd/orchestration/instances/list.go | 4 +- cmd/orchestration/instances/send_event.go | 4 +- cmd/orchestration/instances/show.go | 41 +++- cmd/orchestration/instances/stop.go | 2 +- cmd/orchestration/triggers/create.go | 16 +- cmd/orchestration/triggers/delete.go | 2 +- cmd/orchestration/triggers/list.go | 16 +- .../triggers/occurrences/list.go | 8 +- cmd/orchestration/triggers/show.go | 14 +- cmd/orchestration/workflows/create.go | 6 +- cmd/orchestration/workflows/delete.go | 4 +- cmd/orchestration/workflows/list.go | 5 +- cmd/orchestration/workflows/run.go | 28 ++- cmd/orchestration/workflows/show.go | 13 +- cmd/root.go | 2 - cmd/search/root.go | 205 ------------------ cmd/search/views/accounts.go | 27 --- cmd/search/views/assets.go | 30 --- cmd/search/views/payment.go | 34 --- cmd/search/views/transactions.go | 34 --- 21 files changed, 183 insertions(+), 421 deletions(-) delete mode 100644 cmd/search/root.go delete mode 100644 cmd/search/views/accounts.go delete mode 100644 cmd/search/views/assets.go delete mode 100644 cmd/search/views/payment.go delete mode 100644 cmd/search/views/transactions.go diff --git a/cmd/orchestration/instances/describe.go b/cmd/orchestration/instances/describe.go index f6343683..9b47e5bb 100644 --- a/cmd/orchestration/instances/describe.go +++ b/cmd/orchestration/instances/describe.go @@ -16,7 +16,7 @@ import ( ) type InstancesDescribeStore struct { - WorkflowInstancesHistory []shared.WorkflowInstanceHistory `json:"workflowInstanceHistory"` + WorkflowInstancesHistory []shared.V2WorkflowInstanceHistory `json:"workflowInstanceHistory"` } type InstancesDescribeController struct { store *InstancesDescribeStore @@ -51,14 +51,14 @@ func (c *InstancesDescribeController) GetStore() *InstancesDescribeStore { func (c *InstancesDescribeController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - response, err := store.Client().Orchestration.V1.GetInstanceHistory(cmd.Context(), operations.GetInstanceHistoryRequest{ + response, err := store.Client().Orchestration.V2.GetInstanceHistory(cmd.Context(), operations.V2GetInstanceHistoryRequest{ InstanceID: args[0], }) if err != nil { return nil, err } - c.store.WorkflowInstancesHistory = response.GetWorkflowInstanceHistoryResponse.Data + c.store.WorkflowInstancesHistory = response.V2GetWorkflowInstanceHistoryResponse.Data return c, nil } @@ -74,15 +74,15 @@ func (c *InstancesDescribeController) Render(cmd *cobra.Command, args []string) return nil } -func printHistoryBaseInfo(out io.Writer, name string, ind int, history shared.WorkflowInstanceHistory) { +func printHistoryBaseInfo(out io.Writer, name string, ind int, history shared.V2WorkflowInstanceHistory) { fctl.Section.WithWriter(out).Printf("Stage %d : %s\n", ind, name) fctl.BasicText.WithWriter(out).Printfln("Started at: %s", history.StartedAt.Format(time.RFC3339)) if history.Terminated { - fctl.BasicText.WithWriter(out).Printfln("Terminated at: %s", history.StartedAt.Format(time.RFC3339)) + fctl.BasicText.WithWriter(out).Printfln("Terminated at: %s", history.TerminatedAt.Format(time.RFC3339)) } } -func stageSourceName(src *shared.StageSendSource) string { +func stageSourceName(src *shared.V2StageSendSource) string { switch { case src.Wallet != nil: return fmt.Sprintf("wallet '%s' (balance: %s)", src.Wallet.ID, *src.Wallet.Balance) @@ -95,7 +95,7 @@ func stageSourceName(src *shared.StageSendSource) string { } } -func stageDestinationName(dst *shared.StageSendDestination) string { +func stageDestinationName(dst *shared.V2StageSendDestination) string { switch { case dst.Wallet != nil: return fmt.Sprintf("wallet '%s' (balance: %s)", dst.Wallet.ID, *dst.Wallet.Balance) @@ -108,12 +108,12 @@ func stageDestinationName(dst *shared.StageSendDestination) string { } } -func subjectName(src shared.Subject) string { +func subjectName(src shared.V2Subject) string { switch { - case src.WalletSubject != nil: - return fmt.Sprintf("wallet %s (balance: %s)", src.WalletSubject.Identifier, *src.WalletSubject.Balance) - case src.LedgerAccountSubject != nil: - return fmt.Sprintf("account %s", src.LedgerAccountSubject.Identifier) + case src.V2WalletSubject != nil: + return fmt.Sprintf("wallet %s (balance: %s)", src.V2WalletSubject.Identifier, *src.V2WalletSubject.Balance) + case src.V2LedgerAccountSubject != nil: + return fmt.Sprintf("account %s", src.V2LedgerAccountSubject.Identifier) default: return "unknown_subject_type" } @@ -131,21 +131,23 @@ func printMetadata(metadata map[string]string) []pterm.BulletListItem { return ret } -func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, history shared.WorkflowInstanceHistory) error { +func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, history shared.V2WorkflowInstanceHistory) error { cyanWriter := fctl.BasicTextCyan defaultWriter := fctl.BasicText listItems := make([]pterm.BulletListItem, 0) switch history.Input.Type { - case shared.StageTypeStageSend: + case shared.V2StageTypeV2StageSend: printHistoryBaseInfo(cmd.OutOrStdout(), "send", i, history) - cyanWriter.Printfln("Send %v %s from %s to %s", history.Input.StageSend.Amount.Amount, - history.Input.StageSend.Amount.Asset, stageSourceName(history.Input.StageSend.Source), - stageDestinationName(history.Input.StageSend.Destination)) + if history.Input.V2StageSend != nil { + cyanWriter.Printfln("Send %v %s from %s to %s", history.Input.V2StageSend.Amount.Amount, + history.Input.V2StageSend.Amount.Asset, stageSourceName(history.Input.V2StageSend.Source), + stageDestinationName(history.Input.V2StageSend.Destination)) + } fctl.Println() - stageResponse, err := client.Orchestration.V1.GetInstanceStageHistory(cmd.Context(), operations.GetInstanceStageHistoryRequest{ + stageResponse, err := client.Orchestration.V2.GetInstanceStageHistory(cmd.Context(), operations.V2GetInstanceStageHistoryRequest{ InstanceID: id, Number: int64(i), }) @@ -153,7 +155,7 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, return err } - for _, historyStage := range stageResponse.GetWorkflowInstanceHistoryStageResponse.Data { + for _, historyStage := range stageResponse.V2GetWorkflowInstanceHistoryStageResponse.Data { switch { case historyStage.Input.StripeTransfer != nil: listItems = append(listItems, historyItemTitle("Send %v %s to Stripe connected account: %s", @@ -162,19 +164,26 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, *historyStage.Input.StripeTransfer.Destination, )) case historyStage.Input.CreateTransaction != nil: - listItems = append(listItems, historyItemTitle("Send %v %s from account %s to account %s (ledger %s)", - historyStage.Input.CreateTransaction.Data.Postings[0].Amount, - historyStage.Input.CreateTransaction.Data.Postings[0].Asset, - historyStage.Input.CreateTransaction.Data.Postings[0].Source, - historyStage.Input.CreateTransaction.Data.Postings[0].Destination, - *historyStage.Input.CreateTransaction.Ledger, - )) + if historyStage.Input.CreateTransaction.Data != nil && len(historyStage.Input.CreateTransaction.Data.Postings) > 0 { + listItems = append(listItems, historyItemTitle("Send %v %s from account %s to account %s (ledger %s)", + historyStage.Input.CreateTransaction.Data.Postings[0].Amount, + historyStage.Input.CreateTransaction.Data.Postings[0].Asset, + historyStage.Input.CreateTransaction.Data.Postings[0].Source, + historyStage.Input.CreateTransaction.Data.Postings[0].Destination, + *historyStage.Input.CreateTransaction.Ledger, + )) + } if historyStage.Error == nil && historyStage.LastFailure == nil && historyStage.Terminated { - listItems = append(listItems, historyItemDetails("Created transaction: %d", historyStage.Output.CreateTransaction.Data.ID)) - if historyStage.Input.CreateTransaction.Data.Reference != nil { - listItems = append(listItems, historyItemDetails("Reference: %s", *historyStage.Output.CreateTransaction.Data.Reference)) + if historyStage.Output.CreateTransaction != nil && len(historyStage.Output.CreateTransaction.Data) > 0 { + txid := historyStage.Output.CreateTransaction.Data[0].Txid + if txid != nil { + listItems = append(listItems, historyItemDetails("Created transaction: %d", txid.Int64())) + } } - if len(historyStage.Input.CreateTransaction.Data.Metadata) > 0 { + if historyStage.Input.CreateTransaction != nil && historyStage.Input.CreateTransaction.Data != nil && historyStage.Input.CreateTransaction.Data.Reference != nil { + listItems = append(listItems, historyItemDetails("Reference: %s", *historyStage.Input.CreateTransaction.Data.Reference)) + } + if historyStage.Input.CreateTransaction != nil && historyStage.Input.CreateTransaction.Data != nil && len(historyStage.Input.CreateTransaction.Data.Metadata) > 0 { listItems = append(listItems, printMetadata(historyStage.Input.CreateTransaction.Data.Metadata)...) } } @@ -221,11 +230,7 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, historyStage.Input.GetPayment.ID)) case historyStage.Input.GetWallet != nil: listItems = append(listItems, historyItemTitle("Read wallet '%s'", historyStage.Input.GetWallet.ID)) - case historyStage.Input.RevertTransaction != nil: - listItems = append(listItems, historyItemTitle("Revert transaction %s", historyStage.Input.RevertTransaction.ID)) - if historyStage.Error == nil { - listItems = append(listItems, historyItemTitle("Created transaction: %d", historyStage.Output.RevertTransaction.Data.ID)) - } + // V2 doesn't have RevertTransaction, skip it case historyStage.Input.VoidHold != nil: listItems = append(listItems, historyItemTitle("Cancel debit hold %s", historyStage.Input.VoidHold.ID)) case historyStage.Input.ListWallets != nil: @@ -242,17 +247,21 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, listItems = append(listItems, historyItemError(*historyStage.Error)) } } - case shared.StageTypeStageDelay: + case shared.V2StageTypeV2StageDelay: printHistoryBaseInfo(cmd.OutOrStdout(), "delay", i, history) - switch { - case history.Input.StageDelay.Duration != nil: - listItems = append(listItems, historyItemTitle("Pause workflow for a delay of %s", *history.Input.StageDelay.Duration)) - case history.Input.StageDelay.Until != nil: - listItems = append(listItems, historyItemTitle("Pause workflow until %s", *history.Input.StageDelay.Until)) + if history.Input.V2StageDelay != nil { + switch { + case history.Input.V2StageDelay.Duration != nil: + listItems = append(listItems, historyItemTitle("Pause workflow for a delay of %s", *history.Input.V2StageDelay.Duration)) + case history.Input.V2StageDelay.Until != nil: + listItems = append(listItems, historyItemTitle("Pause workflow until %s", *history.Input.V2StageDelay.Until)) + } } - case shared.StageTypeStageWaitEvent: + case shared.V2StageTypeV2StageWaitEvent: printHistoryBaseInfo(cmd.OutOrStdout(), "wait_event", i, history) - listItems = append(listItems, historyItemTitle("Waiting event '%s'", history.Input.StageWaitEvent.Event)) + if history.Input.V2StageWaitEvent != nil { + listItems = append(listItems, historyItemTitle("Waiting event '%s'", history.Input.V2StageWaitEvent.Event)) + } if history.Error == nil { if history.Terminated { listItems = append(listItems, historyItemDetails("Event received!")) @@ -260,13 +269,15 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, listItems = append(listItems, historyItemDetails("Still waiting event...")) } } - case shared.StageTypeUpdate: + case shared.V2StageTypeV2Update: printHistoryBaseInfo(cmd.OutOrStdout(), "update", i, history) - switch { - case history.Input.Update.Account != nil: - account := history.Input.Update.Account - listItems = append(listItems, historyItemTitle("Update account '%s' of ledger '%s'", account.ID, account.Ledger)) - listItems = append(listItems, printMetadata(account.Metadata)...) + if history.Input.V2Update != nil { + switch { + case history.Input.V2Update.Account != nil: + account := history.Input.V2Update.Account + listItems = append(listItems, historyItemTitle("Update account '%s' of ledger '%s'", account.ID, account.Ledger)) + listItems = append(listItems, printMetadata(account.Metadata)...) + } } default: // Display error? diff --git a/cmd/orchestration/instances/list.go b/cmd/orchestration/instances/list.go index 221d84f3..32d8ee8a 100644 --- a/cmd/orchestration/instances/list.go +++ b/cmd/orchestration/instances/list.go @@ -64,7 +64,7 @@ func (c *InstancesListController) GetStore() *InstancesListStore { func (c *InstancesListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - response, err := store.Client().Orchestration.V1.ListInstances(cmd.Context(), operations.ListInstancesRequest{ + response, err := store.Client().Orchestration.V2.ListInstances(cmd.Context(), operations.V2ListInstancesRequest{ Running: fctl.Ptr(fctl.GetBool(cmd, c.runningFlag)), WorkflowID: fctl.Ptr(fctl.GetString(cmd, c.workflowFlag)), }) @@ -72,7 +72,7 @@ func (c *InstancesListController) Run(cmd *cobra.Command, args []string) (fctl.R return nil, err } - c.store.WorkflowInstance = fctl.Map(response.ListRunsResponse.Data, func(src shared.WorkflowInstance) WorkflowInstance { + c.store.WorkflowInstance = fctl.Map(response.V2ListRunsResponse.Cursor.Data, func(src shared.V2WorkflowInstance) WorkflowInstance { return WorkflowInstance{ InstanceID: src.ID, WorkflowID: src.WorkflowID, diff --git a/cmd/orchestration/instances/send_event.go b/cmd/orchestration/instances/send_event.go index fc2f6d1f..de914128 100644 --- a/cmd/orchestration/instances/send_event.go +++ b/cmd/orchestration/instances/send_event.go @@ -49,8 +49,8 @@ func (c *InstancesSendEventController) GetStore() *InstancesSendEventStore { func (c *InstancesSendEventController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - _, err := store.Client().Orchestration.V1.SendEvent(cmd.Context(), operations.SendEventRequest{ - RequestBody: &operations.SendEventRequestBody{ + _, err := store.Client().Orchestration.V2.SendEvent(cmd.Context(), operations.V2SendEventRequest{ + RequestBody: &operations.V2SendEventRequestBody{ Name: args[1], }, InstanceID: args[0], diff --git a/cmd/orchestration/instances/show.go b/cmd/orchestration/instances/show.go index e46da074..9bd47b2a 100644 --- a/cmd/orchestration/instances/show.go +++ b/cmd/orchestration/instances/show.go @@ -15,8 +15,8 @@ import ( ) type InstancesShowStore struct { - WorkflowInstance shared.WorkflowInstance `json:"workflowInstance"` - Workflow shared.Workflow `json:"workflow"` + WorkflowInstance shared.V2WorkflowInstance `json:"workflowInstance"` + Workflow shared.Workflow `json:"workflow"` } type InstancesShowController struct { store *InstancesShowStore @@ -50,22 +50,29 @@ func (c *InstancesShowController) GetStore() *InstancesShowStore { func (c *InstancesShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - res, err := store.Client().Orchestration.V1.GetInstance(cmd.Context(), operations.GetInstanceRequest{ + res, err := store.Client().Orchestration.V2.GetInstance(cmd.Context(), operations.V2GetInstanceRequest{ InstanceID: args[0], }) if err != nil { return nil, errors.Wrap(err, "reading instance") } - c.store.WorkflowInstance = res.GetWorkflowInstanceResponse.Data - response, err := store.Client().Orchestration.V1.GetWorkflow(cmd.Context(), operations.GetWorkflowRequest{ - FlowID: res.GetWorkflowInstanceResponse.Data.WorkflowID, + c.store.WorkflowInstance = res.V2GetWorkflowInstanceResponse.Data + response, err := store.Client().Orchestration.V2.GetWorkflow(cmd.Context(), operations.V2GetWorkflowRequest{ + FlowID: res.V2GetWorkflowInstanceResponse.Data.WorkflowID, }) if err != nil { return nil, err } - c.store.Workflow = response.GetWorkflowResponse.Data + // Convert V2Workflow to Workflow + v2Workflow := response.V2GetWorkflowResponse.Data + c.store.Workflow = shared.Workflow{ + ID: v2Workflow.ID, + CreatedAt: v2Workflow.CreatedAt, + UpdatedAt: v2Workflow.UpdatedAt, + Config: shared.WorkflowConfig(v2Workflow.Config), + } return c, nil } @@ -91,7 +98,25 @@ func (c *InstancesShowController) Render(cmd *cobra.Command, args []string) erro return err } - if err := internal.PrintWorkflowInstance(cmd.OutOrStdout(), c.store.Workflow, c.store.WorkflowInstance); err != nil { + // Convert V2WorkflowInstance to WorkflowInstance + v2Instance := c.store.WorkflowInstance + instance := shared.WorkflowInstance{ + ID: v2Instance.ID, + WorkflowID: v2Instance.WorkflowID, + CreatedAt: v2Instance.CreatedAt, + UpdatedAt: v2Instance.UpdatedAt, + Terminated: v2Instance.Terminated, + TerminatedAt: v2Instance.TerminatedAt, + Error: v2Instance.Error, + Status: fctl.Map(v2Instance.Status, func(src shared.V2StageStatus) shared.StageStatus { + return shared.StageStatus{ + StartedAt: src.StartedAt, + TerminatedAt: src.TerminatedAt, + Error: src.Error, + } + }), + } + if err := internal.PrintWorkflowInstance(cmd.OutOrStdout(), c.store.Workflow, instance); err != nil { return err } diff --git a/cmd/orchestration/instances/stop.go b/cmd/orchestration/instances/stop.go index b27cacc0..b161accb 100644 --- a/cmd/orchestration/instances/stop.go +++ b/cmd/orchestration/instances/stop.go @@ -45,7 +45,7 @@ func (c *InstancesStopController) GetStore() *InstancesStopStore { func (c *InstancesStopController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - _, err := store.Client().Orchestration.V1.CancelEvent(cmd.Context(), operations.CancelEventRequest{ + _, err := store.Client().Orchestration.V2.CancelEvent(cmd.Context(), operations.V2CancelEventRequest{ InstanceID: args[0], }) if err != nil { diff --git a/cmd/orchestration/triggers/create.go b/cmd/orchestration/triggers/create.go index 78d1ac9c..340cd5d7 100644 --- a/cmd/orchestration/triggers/create.go +++ b/cmd/orchestration/triggers/create.go @@ -66,7 +66,7 @@ func (c *TriggersCreateController) Run(cmd *cobra.Command, args []string) (fctl. workflow = args[1] ) - data := &shared.TriggerData{ + data := &shared.V2TriggerData{ Event: event, Name: &name, WorkflowID: workflow, @@ -85,12 +85,22 @@ func (c *TriggersCreateController) Run(cmd *cobra.Command, args []string) (fctl. } } - res, err := store.Client().Orchestration.V1.CreateTrigger(cmd.Context(), data) + res, err := store.Client().Orchestration.V2.CreateTrigger(cmd.Context(), data) if err != nil { return nil, errors.Wrap(err, "reading trigger") } - c.store.Trigger = res.CreateTriggerResponse.Data + // Convert V2Trigger to Trigger + v2Trigger := res.V2CreateTriggerResponse.Data + c.store.Trigger = shared.Trigger{ + ID: v2Trigger.ID, + Name: v2Trigger.Name, + WorkflowID: v2Trigger.WorkflowID, + Event: v2Trigger.Event, + Filter: v2Trigger.Filter, + Vars: v2Trigger.Vars, + CreatedAt: v2Trigger.CreatedAt, + } return c, nil } diff --git a/cmd/orchestration/triggers/delete.go b/cmd/orchestration/triggers/delete.go index a880f605..4f51a830 100644 --- a/cmd/orchestration/triggers/delete.go +++ b/cmd/orchestration/triggers/delete.go @@ -45,7 +45,7 @@ func (c *TriggersDeleteController) GetStore() *TriggersDeleteStore { func (c *TriggersDeleteController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - _, err := store.Client().Orchestration.V1.DeleteTrigger(cmd.Context(), operations.DeleteTriggerRequest{ + _, err := store.Client().Orchestration.V2.DeleteTrigger(cmd.Context(), operations.V2DeleteTriggerRequest{ TriggerID: args[0], }) if err != nil { diff --git a/cmd/orchestration/triggers/list.go b/cmd/orchestration/triggers/list.go index 85d9eacf..6b40525a 100644 --- a/cmd/orchestration/triggers/list.go +++ b/cmd/orchestration/triggers/list.go @@ -52,7 +52,7 @@ func (c *TriggersListController) GetStore() *TriggersListStore { func (c *TriggersListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) var name = fctl.GetString(cmd, c.nameFlag) - response, err := store.Client().Orchestration.V1.ListTriggers(cmd.Context(), operations.ListTriggersRequest{ + response, err := store.Client().Orchestration.V2.ListTriggers(cmd.Context(), operations.V2ListTriggersRequest{ Name: &name, }) @@ -60,7 +60,19 @@ func (c *TriggersListController) Run(cmd *cobra.Command, args []string) (fctl.Re return nil, err } - c.store.WorkflowTrigger = response.ListTriggersResponse.Data + // Convert V2Trigger to Trigger + v2Triggers := response.V2ListTriggersResponse.Cursor.Data + c.store.WorkflowTrigger = fctl.Map(v2Triggers, func(v2Trigger shared.V2Trigger) shared.Trigger { + return shared.Trigger{ + ID: v2Trigger.ID, + Name: v2Trigger.Name, + WorkflowID: v2Trigger.WorkflowID, + Event: v2Trigger.Event, + Filter: v2Trigger.Filter, + Vars: v2Trigger.Vars, + CreatedAt: v2Trigger.CreatedAt, + } + }) return c, nil } diff --git a/cmd/orchestration/triggers/occurrences/list.go b/cmd/orchestration/triggers/occurrences/list.go index 4fdb03e5..e9b3d17c 100644 --- a/cmd/orchestration/triggers/occurrences/list.go +++ b/cmd/orchestration/triggers/occurrences/list.go @@ -14,7 +14,7 @@ import ( ) type OccurrencesListStore struct { - WorkflowOccurrence []shared.TriggerOccurrence `json:"occurrences"` + WorkflowOccurrence []shared.V2TriggerOccurrence `json:"occurrences"` } type OccurrencesListController struct { store *OccurrencesListStore @@ -49,14 +49,14 @@ func (c *OccurrencesListController) GetStore() *OccurrencesListStore { func (c *OccurrencesListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - response, err := store.Client().Orchestration.V1.ListTriggersOccurrences(cmd.Context(), operations.ListTriggersOccurrencesRequest{ + response, err := store.Client().Orchestration.V2.ListTriggersOccurrences(cmd.Context(), operations.V2ListTriggersOccurrencesRequest{ TriggerID: args[0], }) if err != nil { return nil, err } - c.store.WorkflowOccurrence = response.ListTriggersOccurrencesResponse.Data + c.store.WorkflowOccurrence = response.V2ListTriggersOccurrencesResponse.Cursor.Data return c, nil } @@ -73,7 +73,7 @@ func (c *OccurrencesListController) Render(cmd *cobra.Command, args []string) er WithData( fctl.Prepend( fctl.Map(c.store.WorkflowOccurrence, - func(src shared.TriggerOccurrence) []string { + func(src shared.V2TriggerOccurrence) []string { return []string{ func() string { if src.WorkflowInstanceID != nil { diff --git a/cmd/orchestration/triggers/show.go b/cmd/orchestration/triggers/show.go index 75a67993..ea2081e7 100644 --- a/cmd/orchestration/triggers/show.go +++ b/cmd/orchestration/triggers/show.go @@ -48,14 +48,24 @@ func (c *TriggersShowController) GetStore() *TriggersShowStore { func (c *TriggersShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - res, err := store.Client().Orchestration.V1.ReadTrigger(cmd.Context(), operations.ReadTriggerRequest{ + res, err := store.Client().Orchestration.V2.ReadTrigger(cmd.Context(), operations.V2ReadTriggerRequest{ TriggerID: args[0], }) if err != nil { return nil, errors.Wrap(err, "reading trigger") } - c.store.Trigger = res.ReadTriggerResponse.Data + // Convert V2Trigger to Trigger + v2Trigger := res.V2ReadTriggerResponse.Data + c.store.Trigger = shared.Trigger{ + ID: v2Trigger.ID, + Name: v2Trigger.Name, + WorkflowID: v2Trigger.WorkflowID, + Event: v2Trigger.Event, + Filter: v2Trigger.Filter, + Vars: v2Trigger.Vars, + CreatedAt: v2Trigger.CreatedAt, + } return c, nil } diff --git a/cmd/orchestration/workflows/create.go b/cmd/orchestration/workflows/create.go index f54b7cbe..4e6b564e 100644 --- a/cmd/orchestration/workflows/create.go +++ b/cmd/orchestration/workflows/create.go @@ -57,8 +57,8 @@ func (c *WorkflowsCreateController) Run(cmd *cobra.Command, args []string) (fctl } //nolint:gosimple - response, err := store.Client().Orchestration.V1. - CreateWorkflow(cmd.Context(), &shared.WorkflowConfig{ + response, err := store.Client().Orchestration.V2. + CreateWorkflow(cmd.Context(), &shared.V2WorkflowConfig{ Name: config.Name, Stages: config.Stages, }) @@ -66,7 +66,7 @@ func (c *WorkflowsCreateController) Run(cmd *cobra.Command, args []string) (fctl return nil, err } - c.store.WorkflowId = response.CreateWorkflowResponse.Data.ID + c.store.WorkflowId = response.V2CreateWorkflowResponse.Data.ID return c, nil } diff --git a/cmd/orchestration/workflows/delete.go b/cmd/orchestration/workflows/delete.go index 599b4c42..494c5e40 100644 --- a/cmd/orchestration/workflows/delete.go +++ b/cmd/orchestration/workflows/delete.go @@ -44,9 +44,9 @@ func (c *WorkflowsDeleteController) GetStore() *WorkflowsDeleteStore { func (c *WorkflowsDeleteController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { store := fctl.GetStackStore(cmd.Context()) - _, err := store.Client().Orchestration.V1.DeleteWorkflow( + _, err := store.Client().Orchestration.V2.DeleteWorkflow( cmd.Context(), - operations.DeleteWorkflowRequest{ + operations.V2DeleteWorkflowRequest{ FlowID: args[0], }, ) diff --git a/cmd/orchestration/workflows/list.go b/cmd/orchestration/workflows/list.go index f0cb53ef..1636f625 100644 --- a/cmd/orchestration/workflows/list.go +++ b/cmd/orchestration/workflows/list.go @@ -7,6 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" + "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" fctl "github.com/formancehq/fctl/pkg" @@ -55,12 +56,12 @@ func (c *WorkflowsListController) Run(cmd *cobra.Command, args []string) (fctl.R store := fctl.GetStackStore(cmd.Context()) - response, err := store.Client().Orchestration.V1.ListWorkflows(cmd.Context()) + response, err := store.Client().Orchestration.V2.ListWorkflows(cmd.Context(), operations.V2ListWorkflowsRequest{}) if err != nil { return nil, err } - c.store.Workflows = fctl.Map(response.ListWorkflowsResponse.Data, func(src shared.Workflow) Workflow { + c.store.Workflows = fctl.Map(response.V2ListWorkflowsResponse.Cursor.Data, func(src shared.V2Workflow) Workflow { return Workflow{ ID: src.ID, Name: func() string { diff --git a/cmd/orchestration/workflows/run.go b/cmd/orchestration/workflows/run.go index 0fe86097..43345e41 100644 --- a/cmd/orchestration/workflows/run.go +++ b/cmd/orchestration/workflows/run.go @@ -69,8 +69,8 @@ func (c *WorkflowsRunController) Run(cmd *cobra.Command, args []string) (fctl.Re variables[parts[0]] = parts[1] } - response, err := store.Client().Orchestration.V1. - RunWorkflow(cmd.Context(), operations.RunWorkflowRequest{ + response, err := store.Client().Orchestration.V2. + RunWorkflow(cmd.Context(), operations.V2RunWorkflowRequest{ RequestBody: variables, Wait: &wait, WorkflowID: args[0], @@ -80,7 +80,17 @@ func (c *WorkflowsRunController) Run(cmd *cobra.Command, args []string) (fctl.Re } c.wait = wait - c.store.WorkflowInstance = response.RunWorkflowResponse.Data + // Convert V2WorkflowInstance to WorkflowInstance + v2Instance := response.V2RunWorkflowResponse.Data + c.store.WorkflowInstance = shared.WorkflowInstance{ + ID: v2Instance.ID, + WorkflowID: v2Instance.WorkflowID, + CreatedAt: v2Instance.CreatedAt, + UpdatedAt: v2Instance.UpdatedAt, + Terminated: v2Instance.Terminated, + TerminatedAt: v2Instance.TerminatedAt, + Error: v2Instance.Error, + } return c, nil } @@ -88,14 +98,22 @@ func (c *WorkflowsRunController) Render(cmd *cobra.Command, args []string) error store := fctl.GetStackStore(cmd.Context()) pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("Workflow instance created with ID: %s", c.store.WorkflowInstance.ID) if c.wait { - w, err := store.Client().Orchestration.V1.GetWorkflow(cmd.Context(), operations.GetWorkflowRequest{ + w, err := store.Client().Orchestration.V2.GetWorkflow(cmd.Context(), operations.V2GetWorkflowRequest{ FlowID: args[0], }) if err != nil { panic(err) } - return internal.PrintWorkflowInstance(cmd.OutOrStdout(), w.GetWorkflowResponse.Data, c.store.WorkflowInstance) + // Convert V2Workflow to Workflow + v2Workflow := w.V2GetWorkflowResponse.Data + workflow := shared.Workflow{ + ID: v2Workflow.ID, + CreatedAt: v2Workflow.CreatedAt, + UpdatedAt: v2Workflow.UpdatedAt, + Config: shared.WorkflowConfig(v2Workflow.Config), + } + return internal.PrintWorkflowInstance(cmd.OutOrStdout(), workflow, c.store.WorkflowInstance) } return nil } diff --git a/cmd/orchestration/workflows/show.go b/cmd/orchestration/workflows/show.go index 707f3b0d..09c4f042 100644 --- a/cmd/orchestration/workflows/show.go +++ b/cmd/orchestration/workflows/show.go @@ -50,15 +50,22 @@ func (c *WorkflowsShowController) Run(cmd *cobra.Command, args []string) (fctl.R store := fctl.GetStackStore(cmd.Context()) - response, err := store.Client().Orchestration.V1. - GetWorkflow(cmd.Context(), operations.GetWorkflowRequest{ + response, err := store.Client().Orchestration.V2. + GetWorkflow(cmd.Context(), operations.V2GetWorkflowRequest{ FlowID: args[0], }) if err != nil { return nil, err } - c.store.Workflow = response.GetWorkflowResponse.Data + // Convert V2Workflow to Workflow + v2Workflow := response.V2GetWorkflowResponse.Data + c.store.Workflow = shared.Workflow{ + ID: v2Workflow.ID, + CreatedAt: v2Workflow.CreatedAt, + UpdatedAt: v2Workflow.UpdatedAt, + Config: shared.WorkflowConfig(v2Workflow.Config), + } return c, nil } diff --git a/cmd/root.go b/cmd/root.go index 1618f62c..55b06c56 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,7 +24,6 @@ import ( "github.com/formancehq/fctl/cmd/payments" "github.com/formancehq/fctl/cmd/profiles" "github.com/formancehq/fctl/cmd/reconciliation" - "github.com/formancehq/fctl/cmd/search" "github.com/formancehq/fctl/cmd/stack" "github.com/formancehq/fctl/cmd/ui" "github.com/formancehq/fctl/cmd/version" @@ -59,7 +58,6 @@ func NewRootCommand() *cobra.Command { stack.NewCommand(), auth.NewCommand(), cloud.NewCommand(), - search.NewCommand(), webhooks.NewCommand(), wallets.NewCommand(), orchestration.NewCommand(), diff --git a/cmd/search/root.go b/cmd/search/root.go deleted file mode 100644 index a7cfd3b0..00000000 --- a/cmd/search/root.go +++ /dev/null @@ -1,205 +0,0 @@ -package search - -import ( - "encoding/json" - "fmt" - "strings" - - "github.com/pterm/pterm" - "github.com/spf13/cobra" - - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - - "github.com/formancehq/fctl/cmd/search/views" - fctl "github.com/formancehq/fctl/pkg" -) - -const ( - sizeFlag = "size" - defaultTarget = "ANY" -) - -var targets = []string{"TRANSACTION", "ACCOUNT", "ASSET", "PAYMENT"} - -type SearchStore struct { - Response *shared.Response `json:"response"` -} - -type SearchController struct { - store *SearchStore - target string -} - -var _ fctl.Controller[*SearchStore] = (*SearchController)(nil) - -func NewDefaultSearchStore() *SearchStore { - return &SearchStore{ - Response: &shared.Response{ - Data: make(map[string]interface{}, 0), - Cursor: &shared.ResponseCursor{ - Data: make([]map[string]interface{}, 0), - }, - }, - } -} - -func NewSearchController() *SearchController { - return &SearchController{ - store: NewDefaultSearchStore(), - } -} - -func (c *SearchController) GetStore() *SearchStore { - return c.store -} - -func (c *SearchController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { - - store := fctl.GetStackStore(cmd.Context()) - - terms := make([]string, 0) - if len(args) > 1 { - terms = args[1:] - } - size := int64(fctl.GetInt(cmd, sizeFlag)) - - target := strings.ToUpper(args[0]) - - if target == "ANY" { - target = "" - } - c.target = target - request := shared.Query{ - PageSize: &size, - Terms: terms, - Target: &target, - } - response, err := store.Client().Search.V1.Search(cmd.Context(), request) - if err != nil { - return nil, err - } - - if response.StatusCode >= 300 { - return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) - } - - if target == "" { - c.store.Response.Data = response.Response.Data - c.store.Response.Cursor = response.Response.Cursor - } else { - // TRANSACTION, ACCOUNT, ASSET, PAYMENT - c.store.Response.Cursor = response.Response.Cursor - } - - return c, err -} - -func (c *SearchController) Render(cmd *cobra.Command, args []string) error { - var err error - // No Data - if (c.store.Response.Cursor != nil && len(c.store.Response.Cursor.Data) == 0) && len(c.store.Response.Data) == 0 { - fctl.Section.WithWriter(cmd.OutOrStdout()).Println("No data found") - return nil - } - - ok := fctl.ContainValue(targets, c.target) - // Cursor is initialized & target is valid - if ok && c.store.Response.Cursor != nil { - //But no data - if len(c.store.Response.Cursor.Data) == 0 { - fctl.Section.WithWriter(cmd.OutOrStdout()).Println("No data found") - return nil - } - - // Display the data - switch c.target { - case "TRANSACTION": - fctl.Section.WithWriter(cmd.OutOrStdout()).Println("Transactions") - err = views.DisplayTransactions(cmd.OutOrStdout(), c.store.Response.Cursor.Data) - case "ACCOUNT": - fctl.Section.WithWriter(cmd.OutOrStdout()).Println("Accounts") - err = views.DisplayAccounts(cmd.OutOrStdout(), c.store.Response.Cursor.Data) - case "ASSET": - fctl.Section.WithWriter(cmd.OutOrStdout()).Println("Assets") - err = views.DisplayAssets(cmd.OutOrStdout(), c.store.Response.Cursor.Data) - case "PAYMENT": - fctl.Section.WithWriter(cmd.OutOrStdout()).Println("Payments") - err = views.DisplayPayments(cmd.OutOrStdout(), c.store.Response.Cursor.Data) - } - } - - ok = defaultTarget == c.target || c.target == "" - - // Any data - if len(c.store.Response.Data) > 0 && ok { - tableData := make([][]string, 0) - for kind, values := range c.store.Response.Data { - for _, value := range values.([]any) { - dataAsJson, err := json.Marshal(value) - if err != nil { - return err - } - - dataAsJsonString := string(dataAsJson) - if len(dataAsJsonString) > 100 { - dataAsJsonString = dataAsJsonString[:100] + "..." - } - - tableData = append(tableData, []string{ - kind, dataAsJsonString, - }) - } - } - tableData = fctl.Prepend(tableData, []string{"Kind", "Object"}) - return pterm.DefaultTable. - WithHasHeader(). - WithWriter(cmd.OutOrStdout()). - WithData(tableData). - Render() - } - - return err -} - -func NewCommand() *cobra.Command { - - return fctl.NewStackCommand("search ...", - fctl.WithAliases("se"), - fctl.WithArgs(cobra.MinimumNArgs(1)), - fctl.WithIntFlag(sizeFlag, 5, "Number of items to fetch"), - fctl.WithValidArgs(append(targets, defaultTarget)...), - // fctl.WithValidArgsFunction(func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - // return append(targets, defaultTarget), cobra.ShellCompDirectiveNoFileComp - // }), - fctl.WithShortDescription("Search in all services (Default: ANY), or in a specific service (ACCOUNT, TRANSACTION, ASSET, PAYMENT)"), - fctl.WithController(NewSearchController()), - fctl.WithPersistentPreRunE(func(cmd *cobra.Command, args []string) error { - - cfg, err := fctl.GetConfig(cmd) - if err != nil { - return err - } - apiClient, err := fctl.NewMembershipClient(cmd, cfg) - if err != nil { - return err - } - organizationID, err := fctl.ResolveOrganizationID(cmd, cfg, apiClient.DefaultAPI) - if err != nil { - return err - } - - stack, err := fctl.ResolveStack(cmd, cfg, organizationID) - if err != nil { - return err - } - - stackClient, err := fctl.NewStackClient(cmd, cfg, stack) - if err != nil { - return err - } - cmd.SetContext(fctl.ContextWithStackStore(cmd.Context(), fctl.StackNode(cfg, stack, organizationID, stackClient))) - - return nil - }), - ) -} diff --git a/cmd/search/views/accounts.go b/cmd/search/views/accounts.go deleted file mode 100644 index e0e70c4c..00000000 --- a/cmd/search/views/accounts.go +++ /dev/null @@ -1,27 +0,0 @@ -package views - -import ( - "io" - - "github.com/pterm/pterm" - - fctl "github.com/formancehq/fctl/pkg" -) - -func DisplayAccounts(out io.Writer, accounts []map[string]interface{}) error { - tableData := make([][]string, 0) - for _, account := range accounts { - tableData = append(tableData, []string{ - // TODO: Missing property 'ledger' on api response - //account["ledger"].(string), - account["address"].(string), - }) - } - tableData = fctl.Prepend(tableData, []string{ /*"Ledger",*/ "Address"}) - - return pterm.DefaultTable. - WithHasHeader(). - WithWriter(out). - WithData(tableData). - Render() -} diff --git a/cmd/search/views/assets.go b/cmd/search/views/assets.go deleted file mode 100644 index 229549b0..00000000 --- a/cmd/search/views/assets.go +++ /dev/null @@ -1,30 +0,0 @@ -package views - -import ( - "fmt" - "io" - - "github.com/pterm/pterm" - - fctl "github.com/formancehq/fctl/pkg" -) - -func DisplayAssets(out io.Writer, assets []map[string]interface{}) error { - tableData := make([][]string, 0) - for _, asset := range assets { - tableData = append(tableData, []string{ - asset["ledger"].(string), - asset["name"].(string), - asset["account"].(string), - fmt.Sprint(asset["input"].(float64)), - fmt.Sprint(asset["output"].(float64)), - }) - } - tableData = fctl.Prepend(tableData, []string{"Ledger", "Asset", "Account", "Input", "Output"}) - - return pterm.DefaultTable. - WithHasHeader(). - WithWriter(out). - WithData(tableData). - Render() -} diff --git a/cmd/search/views/payment.go b/cmd/search/views/payment.go deleted file mode 100644 index 1f71c458..00000000 --- a/cmd/search/views/payment.go +++ /dev/null @@ -1,34 +0,0 @@ -package views - -import ( - "fmt" - "io" - - "github.com/pterm/pterm" - - fctl "github.com/formancehq/fctl/pkg" -) - -func DisplayPayments(out io.Writer, payments []map[string]interface{}) error { - tableData := make([][]string, 0) - for _, payment := range payments { - tableData = append(tableData, []string{ - payment["provider"].(string), - payment["reference"].(string), - fmt.Sprint(payment["amount"].(float64)), - payment["asset"].(string), - payment["createdAt"].(string), - payment["scheme"].(string), - payment["status"].(string), - payment["type"].(string), - }) - } - tableData = fctl.Prepend(tableData, []string{"Provider", "Reference", "Account", - "Asset", "Created at", "Scheme", "Status", "Type"}) - - return pterm.DefaultTable. - WithHasHeader(). - WithWriter(out). - WithData(tableData). - Render() -} diff --git a/cmd/search/views/transactions.go b/cmd/search/views/transactions.go deleted file mode 100644 index 76988976..00000000 --- a/cmd/search/views/transactions.go +++ /dev/null @@ -1,34 +0,0 @@ -package views - -import ( - "fmt" - "io" - - "github.com/pterm/pterm" - - fctl "github.com/formancehq/fctl/pkg" -) - -func DisplayTransactions(out io.Writer, txs []map[string]interface{}) error { - tableData := make([][]string, 0) - for _, tx := range txs { - referenceValue := tx["reference"] - reference := "" - if referenceValue != nil { - reference = referenceValue.(string) - } - tableData = append(tableData, []string{ - tx["ledger"].(string), - fmt.Sprint(tx["txid"].(float64)), - reference, - tx["timestamp"].(string), - }) - } - tableData = fctl.Prepend(tableData, []string{"Ledger", "ID", "Reference", "Date"}) - - return pterm.DefaultTable. - WithHasHeader(). - WithWriter(out). - WithData(tableData). - Render() -}