diff --git a/cmd/auth/clients/create.go b/cmd/auth/clients/create.go index a05ac209..db2782ac 100644 --- a/cmd/auth/clients/create.go +++ b/cmd/auth/clients/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -95,7 +95,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab trusted := fctl.GetBool(cmd, c.trustedFlag) description := fctl.GetString(cmd, c.descriptionFlag) - request := shared.CreateClientRequest{ + request := auth.ClientOptions1{ Public: &public, RedirectUris: fctl.GetStringSlice(cmd, c.redirectUriFlag), Description: &description, @@ -114,13 +114,13 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab } c.store.Client = &CreateClient{ - ID: response.CreateClientResponse.Data.ID, - Name: response.CreateClientResponse.Data.Name, - Description: fctl.StringPointerToString(response.CreateClientResponse.Data.Description), - IsPublic: fctl.BoolPointerToString(response.CreateClientResponse.Data.Public), - RedirectUri: strings.Join(response.CreateClientResponse.Data.RedirectUris, ","), - PostLogoutRedirectUri: strings.Join(response.CreateClientResponse.Data.PostLogoutRedirectUris, ","), - Scopes: response.CreateClientResponse.Data.Scopes, + ID: response.CreateClientResponse.ClientOptions.ID, + Name: response.CreateClientResponse.ClientOptions.Name, + Description: fctl.StringPointerToString(response.CreateClientResponse.ClientOptions.Description), + IsPublic: fctl.BoolPointerToString(response.CreateClientResponse.ClientOptions.Public), + RedirectUri: strings.Join(response.CreateClientResponse.ClientOptions.RedirectUris, ","), + PostLogoutRedirectUri: strings.Join(response.CreateClientResponse.ClientOptions.PostLogoutRedirectUris, ","), + Scopes: response.CreateClientResponse.ClientOptions.Scopes, } return c, nil diff --git a/cmd/auth/clients/delete.go b/cmd/auth/clients/delete.go index 2f944fb0..c202bc04 100644 --- a/cmd/auth/clients/delete.go +++ b/cmd/auth/clients/delete.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/auth/clients/list.go b/cmd/auth/clients/list.go index f51f6125..883e6fb1 100644 --- a/cmd/auth/clients/list.go +++ b/cmd/auth/clients/list.go @@ -6,7 +6,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -73,7 +73,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", clients.StatusCode) } - c.store.Clients = fctl.Map(clients.ListClientsResponse.Data, func(o shared.Client) Client { + c.store.Clients = fctl.Map(clients.ListClientsResponse.Data, func(o auth.ClientOptions) Client { return Client{ ID: o.ID, Name: o.Name, diff --git a/cmd/auth/clients/secrets/create.go b/cmd/auth/clients/secrets/create.go index b22e906f..95a391ee 100644 --- a/cmd/auth/clients/secrets/create.go +++ b/cmd/auth/clients/secrets/create.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -65,7 +65,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab request := operations.CreateSecretRequest{ ClientID: args[0], - CreateSecretRequest: &shared.CreateSecretRequest{ + SecretOptions: &auth.SecretOptions{ Name: args[1], Metadata: nil, }, @@ -79,9 +79,9 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.SecretId = response.CreateSecretResponse.Data.ID - c.store.Name = response.CreateSecretResponse.Data.Name - c.store.Clear = response.CreateSecretResponse.Data.Clear + c.store.SecretId = response.CreateSecretResponse.SecretOptions.ID + c.store.Name = response.CreateSecretResponse.SecretOptions.Name + c.store.Clear = response.CreateSecretResponse.SecretOptions.Clear return c, nil } diff --git a/cmd/auth/clients/secrets/delete.go b/cmd/auth/clients/secrets/delete.go index d128bd03..4d1b5dba 100644 --- a/cmd/auth/clients/secrets/delete.go +++ b/cmd/auth/clients/secrets/delete.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/auth/clients/show.go b/cmd/auth/clients/show.go index a8b47ab6..7ce8f854 100644 --- a/cmd/auth/clients/show.go +++ b/cmd/auth/clients/show.go @@ -6,15 +6,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/auth/clients/views" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Client *shared.Client `json:"client,omitempty"` + Client *auth.ClientOptions `json:"client,omitempty"` } type ShowController struct { store *ShowStore @@ -70,7 +70,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Client = response.ReadClientResponse.Data + c.store.Client = response.ReadClientResponse.ClientOptions return c, nil } diff --git a/cmd/auth/clients/update.go b/cmd/auth/clients/update.go index 015832f9..958a737d 100644 --- a/cmd/auth/clients/update.go +++ b/cmd/auth/clients/update.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -104,7 +104,7 @@ func (c *UpdateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab request := operations.UpdateClientRequest{ ClientID: args[0], - CreateClientRequest: &shared.CreateClientRequest{ + ClientOptions: &auth.ClientOptions1{ Public: &public, RedirectUris: fctl.GetStringSlice(cmd, c.redirectUriFlag), Description: &description, @@ -123,13 +123,13 @@ func (c *UpdateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Client.ID = response.UpdateClientResponse.Data.ID - c.store.Client.Name = response.UpdateClientResponse.Data.Name - c.store.Client.Description = fctl.StringPointerToString(response.UpdateClientResponse.Data.Description) - c.store.Client.IsPublic = fctl.BoolPointerToString(response.UpdateClientResponse.Data.Public) - c.store.Client.RedirectUri = strings.Join(response.UpdateClientResponse.Data.RedirectUris, ",") - c.store.Client.PostLogoutRedirectUri = strings.Join(response.UpdateClientResponse.Data.PostLogoutRedirectUris, ",") - c.store.Client.Scopes = response.UpdateClientResponse.Data.Scopes + c.store.Client.ID = response.CreateClientResponse.ClientOptions.ID + c.store.Client.Name = response.CreateClientResponse.ClientOptions.Name + c.store.Client.Description = fctl.StringPointerToString(response.CreateClientResponse.ClientOptions.Description) + c.store.Client.IsPublic = fctl.BoolPointerToString(response.CreateClientResponse.ClientOptions.Public) + c.store.Client.RedirectUri = strings.Join(response.CreateClientResponse.ClientOptions.RedirectUris, ",") + c.store.Client.PostLogoutRedirectUri = strings.Join(response.CreateClientResponse.ClientOptions.PostLogoutRedirectUris, ",") + c.store.Client.Scopes = response.CreateClientResponse.ClientOptions.Scopes return c, nil } diff --git a/cmd/auth/clients/views/client.go b/cmd/auth/clients/views/client.go index 3e9aa6bd..b8254a71 100644 --- a/cmd/auth/clients/views/client.go +++ b/cmd/auth/clients/views/client.go @@ -7,12 +7,12 @@ import ( "github.com/pterm/pterm" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" fctl "github.com/formancehq/fctl/v3/pkg" ) -func PrintClient(out io.Writer, client *shared.Client) error { +func PrintClient(out io.Writer, client *auth.ClientOptions) error { tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("ID"), client.ID}) tableData = append(tableData, []string{pterm.LightCyan("Name"), client.Name}) diff --git a/cmd/auth/clients/views/secrets.go b/cmd/auth/clients/views/secrets.go index 14b45dde..3c973738 100644 --- a/cmd/auth/clients/views/secrets.go +++ b/cmd/auth/clients/views/secrets.go @@ -5,19 +5,19 @@ import ( "github.com/pterm/pterm" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" fctl "github.com/formancehq/fctl/v3/pkg" ) -func PrintSecrets(out io.Writer, secrets []shared.ClientSecret) error { +func PrintSecrets(out io.Writer, secrets []auth.ClientSecret) error { fctl.Section.WithWriter(out).Println("Secrets :") return pterm.DefaultTable. WithWriter(out). WithHasHeader(true). WithData(fctl.Prepend( - fctl.Map(secrets, func(secret shared.ClientSecret) []string { + fctl.Map(secrets, func(secret auth.ClientSecret) []string { return []string{ secret.ID, secret.Name, secret.LastDigits, } diff --git a/cmd/auth/users/list.go b/cmd/auth/users/list.go index b37b6056..fbbca60b 100644 --- a/cmd/auth/users/list.go +++ b/cmd/auth/users/list.go @@ -6,7 +6,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/auth" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -70,7 +70,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", listUsersResponse.StatusCode) } - c.store.Users = fctl.Map(listUsersResponse.ListUsersResponse.Data, func(o shared.User) User { + c.store.Users = fctl.Map(listUsersResponse.ListUsersResponse.Data, func(o auth.User) User { return User{ ID: *o.ID, Subject: *o.Subject, diff --git a/cmd/auth/users/show.go b/cmd/auth/users/show.go index f3bb9d1d..74616b88 100644 --- a/cmd/auth/users/show.go +++ b/cmd/auth/users/show.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -68,9 +68,9 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable } c.store.User = &User{ - ID: *readUserResponse.ReadUserResponse.Data.ID, - Subject: *readUserResponse.ReadUserResponse.Data.Subject, - Email: *readUserResponse.ReadUserResponse.Data.Email, + ID: *readUserResponse.ReadUserResponse.User.ID, + Subject: *readUserResponse.ReadUserResponse.User.Subject, + Email: *readUserResponse.ReadUserResponse.User.Email, } return c, nil diff --git a/cmd/ledger/accounts/delete_metadata.go b/cmd/ledger/accounts/delete_metadata.go index 8c52a713..8b4c2044 100644 --- a/cmd/ledger/accounts/delete_metadata.go +++ b/cmd/ledger/accounts/delete_metadata.go @@ -4,7 +4,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/ledger/internal" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/ledger/accounts/list.go b/cmd/ledger/accounts/list.go index 673a0f37..fb75ccdc 100644 --- a/cmd/ledger/accounts/list.go +++ b/cmd/ledger/accounts/list.go @@ -4,15 +4,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/ledger/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Accounts []shared.V2Account `json:"accounts"` + Accounts []ledger.V2Account `json:"accounts"` } type ListController struct { store *ListStore @@ -75,7 +75,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable request := operations.V2ListAccountsRequest{ Ledger: fctl.GetString(cmd, internal.LedgerFlag), - Query: map[string]any{ + RequestBody: map[string]any{ "$and": body, }, } @@ -91,7 +91,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Accounts, func(account shared.V2Account) []string { + tableData := fctl.Map(c.store.Accounts, func(account ledger.V2Account) []string { return []string{ account.Address, fctl.MetadataAsShortString(account.Metadata), diff --git a/cmd/ledger/accounts/set_metadata.go b/cmd/ledger/accounts/set_metadata.go index 64509189..b4807443 100644 --- a/cmd/ledger/accounts/set_metadata.go +++ b/cmd/ledger/accounts/set_metadata.go @@ -4,7 +4,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/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/collectionutils" "github.com/formancehq/fctl/v3/cmd/ledger/internal" diff --git a/cmd/ledger/accounts/show.go b/cmd/ledger/accounts/show.go index 07a3fd02..58631249 100644 --- a/cmd/ledger/accounts/show.go +++ b/cmd/ledger/accounts/show.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/collectionutils" internal "github.com/formancehq/fctl/v3/cmd/ledger/internal" @@ -15,7 +15,7 @@ import ( ) type ShowStore struct { - Account *shared.AccountWithVolumesAndBalances `json:"account"` + Account *ledger.AccountWithVolumesAndBalances `json:"account"` } type ShowController struct { store *ShowStore @@ -59,7 +59,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable } ledger := fctl.GetString(cmd, internal.LedgerFlag) - response, err := stackClient.Ledger.V1.GetAccount(cmd.Context(), operations.GetAccountRequest{ + response, err := stackClient.Ledger.V1.GetAccountLedger(cmd.Context(), operations.GetAccountLedgerRequest{ Address: args[0], Ledger: ledger, }) @@ -67,7 +67,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, err } - c.store.Account = &response.AccountResponse.Data + c.store.Account = &response.AccountResponse.AccountWithVolumesAndBalances return c, nil } diff --git a/cmd/ledger/create.go b/cmd/ledger/create.go index 300ce44f..96ea73bc 100644 --- a/cmd/ledger/create.go +++ b/cmd/ledger/create.go @@ -7,8 +7,8 @@ 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" + ledgermodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/pointer" fctl "github.com/formancehq/fctl/v3/pkg" @@ -92,10 +92,10 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab } _, err = stackClient.Ledger.V2.CreateLedger(cmd.Context(), operations.V2CreateLedgerRequest{ - V2CreateLedgerRequest: shared.V2CreateLedgerRequest{ - Bucket: pointer.For(fctl.GetString(cmd, bucketNameFlag)), - Metadata: metadata, - Features: features, + V2CreateLedgerRequest: ledgermodels.V2CreateLedgerRequest{ + Bucket: pointer.For(fctl.GetString(cmd, bucketNameFlag)), + V2Metadata: metadata, + Features: features, }, Ledger: args[0], }) diff --git a/cmd/ledger/delete_metadata.go b/cmd/ledger/delete_metadata.go index 0d2c3566..3e3bfce5 100644 --- a/cmd/ledger/delete_metadata.go +++ b/cmd/ledger/delete_metadata.go @@ -4,7 +4,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/ledger/export.go b/cmd/ledger/export.go index e8e56294..57299a82 100644 --- a/cmd/ledger/export.go +++ b/cmd/ledger/export.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/ledger/internal" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/ledger/import.go b/cmd/ledger/import.go index ceb8c4cc..eeba9cb0 100644 --- a/cmd/ledger/import.go +++ b/cmd/ledger/import.go @@ -14,7 +14,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/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/pointer" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/ledger/internal/print.go b/cmd/ledger/internal/print.go index 34de5bd7..9dff6f8d 100644 --- a/cmd/ledger/internal/print.go +++ b/cmd/ledger/internal/print.go @@ -9,7 +9,7 @@ import ( "github.com/pterm/pterm" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" "github.com/formancehq/go-libs/v4/collectionutils" fctl "github.com/formancehq/fctl/v3/pkg" @@ -19,7 +19,7 @@ func printCommonInformation( out io.Writer, txID *big.Int, reference string, - postings []shared.Posting, + postings []ledger.Posting, timestamp time.Time, ) error { fctl.Section.WithWriter(out).Println("Information") @@ -107,22 +107,22 @@ func PrintExpandedTransaction(out io.Writer, transaction ExpandedTransaction) er type Transaction interface { GetReference() *string GetID() *big.Int - GetPostings() []shared.Posting + GetPostings() []ledger.Posting GetTimestamp() time.Time GetMetadata() map[string]string } type v2Transaction struct { - shared.V2Transaction + ledger.V2Transaction } func (t v2Transaction) GetID() *big.Int { return t.ID } -func (t v2Transaction) GetPostings() []shared.Posting { - return collectionutils.Map(t.V2Transaction.GetPostings(), func(from shared.V2Posting) shared.Posting { - return shared.Posting{ +func (t v2Transaction) GetPostings() []ledger.Posting { + return collectionutils.Map(t.V2Transaction.GetPostings(), func(from ledger.V2Posting) ledger.Posting { + return ledger.Posting{ Amount: from.GetAmount(), Asset: from.GetAsset(), Destination: from.GetDestination(), @@ -131,16 +131,20 @@ func (t v2Transaction) GetPostings() []shared.Posting { }) } +func (t v2Transaction) GetMetadata() map[string]string { + return t.V2Transaction.GetV2Metadata() +} + var _ Transaction = (*v2Transaction)(nil) -func WrapV2Transaction(transaction shared.V2Transaction) *v2Transaction { +func WrapV2Transaction(transaction ledger.V2Transaction) *v2Transaction { return &v2Transaction{ V2Transaction: transaction, } } type v1Transaction struct { - shared.Transaction + ledger.Transaction } func (t v1Transaction) GetID() *big.Int { @@ -151,9 +155,17 @@ func (t v1Transaction) GetMetadata() map[string]string { return collectionutils.ConvertMap(t.Transaction.Metadata, collectionutils.ToFmtString) } +func (t v1Transaction) GetPreCommitVolumes() map[string]map[string]ledger.Volume { + return t.Transaction.GetAggregatedVolumes() +} + +func (t v1Transaction) GetPostCommitVolumes() map[string]map[string]ledger.Volume { + return t.Transaction.GetAggregatedVolumes1() +} + var _ Transaction = (*v1Transaction)(nil) -func WrapV1Transaction(transaction shared.Transaction) *v1Transaction { +func WrapV1Transaction(transaction ledger.Transaction) *v1Transaction { return &v1Transaction{ Transaction: transaction, } @@ -161,8 +173,8 @@ func WrapV1Transaction(transaction shared.Transaction) *v1Transaction { type ExpandedTransaction interface { Transaction - GetPreCommitVolumes() map[string]map[string]shared.Volume - GetPostCommitVolumes() map[string]map[string]shared.Volume + GetPreCommitVolumes() map[string]map[string]ledger.Volume + GetPostCommitVolumes() map[string]map[string]ledger.Volume } func PrintTransaction(out io.Writer, transaction Transaction) error { diff --git a/cmd/ledger/internal/transaction.go b/cmd/ledger/internal/transaction.go index 35aaafb3..38d5dcab 100644 --- a/cmd/ledger/internal/transaction.go +++ b/cmd/ledger/internal/transaction.go @@ -8,8 +8,8 @@ import ( "strconv" "strings" - formance "github.com/formancehq/formance-sdk-go/v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" + formance "github.com/formancehq/formance-sdk-go/v4" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" ) func TransactionIDOrLastN(ctx context.Context, ledgerClient *formance.Formance, ledger, id string) (*big.Int, error) { diff --git a/cmd/ledger/list.go b/cmd/ledger/list.go index 0521063b..b469ae33 100644 --- a/cmd/ledger/list.go +++ b/cmd/ledger/list.go @@ -6,14 +6,14 @@ 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" + ledgermodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Ledgers []shared.V2Ledger `json:"ledgers"` + Ledgers []ledgermodels.V2Ledger `json:"ledgers"` } type ListController struct { store *ListStore @@ -23,7 +23,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewDefaultListStore() *ListStore { return &ListStore{ - Ledgers: []shared.V2Ledger{}, + Ledgers: []ledgermodels.V2Ledger{}, } } @@ -70,9 +70,9 @@ func (c *ListController) Run(cmd *cobra.Command, _ []string) (fctl.Renderable, e } func (c *ListController) Render(cmd *cobra.Command, _ []string) error { - tableData := fctl.Map(c.store.Ledgers, func(ledger shared.V2Ledger) []string { + tableData := fctl.Map(c.store.Ledgers, func(ledger ledgermodels.V2Ledger) []string { return []string{ - ledger.Name, ledger.AddedAt.Format(time.RFC3339Nano), fctl.MetadataAsShortString(ledger.Metadata), + ledger.Name, ledger.AddedAt.Format(time.RFC3339Nano), fctl.MetadataAsShortString(ledger.V2Metadata), } }) tableData = fctl.Prepend(tableData, []string{"Name", "Created at", "Metadata"}) diff --git a/cmd/ledger/send.go b/cmd/ledger/send.go index dc2bebb6..775351d8 100644 --- a/cmd/ledger/send.go +++ b/cmd/ledger/send.go @@ -6,8 +6,8 @@ import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + ledgermodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/collectionutils" "github.com/formancehq/fctl/v3/cmd/ledger/internal" @@ -15,7 +15,7 @@ import ( ) type SendStore struct { - Transaction *shared.Transaction `json:"transaction"` + Transaction *ledgermodels.Transaction `json:"transaction"` } type SendController struct { store *SendStore @@ -96,9 +96,9 @@ func (c *SendController) Run(cmd *cobra.Command, args []string) (fctl.Renderable reference := fctl.GetString(cmd, c.referenceFlag) response, err := stackClient.Ledger.V1.CreateTransaction(cmd.Context(), operations.CreateTransactionRequest{ - PostTransaction: shared.PostTransaction{ + PostTransaction: ledgermodels.PostTransaction{ Metadata: collectionutils.ConvertMap(metadata, collectionutils.ToAny[string]), - Postings: []shared.Posting{ + Postings: []ledgermodels.Posting{ { Amount: amount, Asset: asset, diff --git a/cmd/ledger/serverinfo.go b/cmd/ledger/serverinfo.go index 5fb7b86d..18e29e06 100644 --- a/cmd/ledger/serverinfo.go +++ b/cmd/ledger/serverinfo.go @@ -63,8 +63,8 @@ func (c *ServerInfoController) Run(cmd *cobra.Command, args []string) (fctl.Rend return nil, err } - c.store.Server = response.ConfigInfoResponse.Data.Server - c.store.Version = response.ConfigInfoResponse.Data.Version + c.store.Server = response.ConfigInfoResponse.ConfigInfo.Server + c.store.Version = response.ConfigInfoResponse.ConfigInfo.Version return c, nil } diff --git a/cmd/ledger/set_metadata.go b/cmd/ledger/set_metadata.go index ee1ebb06..43327651 100644 --- a/cmd/ledger/set_metadata.go +++ b/cmd/ledger/set_metadata.go @@ -4,7 +4,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/ledger/stats.go b/cmd/ledger/stats.go index dc4e0805..b58554c7 100644 --- a/cmd/ledger/stats.go +++ b/cmd/ledger/stats.go @@ -6,15 +6,15 @@ 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" + ledgermodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/ledger/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type StatsStore struct { - Stats shared.Stats `json:"stats"` + Stats ledgermodels.Stats `json:"stats"` } type StatsController struct { store *StatsStore @@ -66,7 +66,7 @@ func (c *StatsController) Run(cmd *cobra.Command, args []string) (fctl.Renderabl return nil, err } - c.store.Stats = response.StatsResponse.Data + c.store.Stats = response.StatsResponse.Stats return c, nil } diff --git a/cmd/ledger/transactions/delete_metadata.go b/cmd/ledger/transactions/delete_metadata.go index e2642c98..f4d23212 100644 --- a/cmd/ledger/transactions/delete_metadata.go +++ b/cmd/ledger/transactions/delete_metadata.go @@ -4,7 +4,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/ledger/internal" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/ledger/transactions/list.go b/cmd/ledger/transactions/list.go index 745923a9..0d53f456 100644 --- a/cmd/ledger/transactions/list.go +++ b/cmd/ledger/transactions/list.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/collectionutils" "github.com/formancehq/go-libs/v4/pointer" @@ -17,7 +17,7 @@ import ( ) type ListStore struct { - Transaction shared.TransactionsCursorResponseCursor `json:"transactionCursor"` + Transaction ledger.TransactionsCursorResponseCursor `json:"transactionCursor"` } type ListController struct { store *ListStore @@ -141,7 +141,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error { return nil } - tableData := fctl.Map(c.store.Transaction.Data, func(tx shared.Transaction) []string { + tableData := fctl.Map(c.store.Transaction.Data, func(tx ledger.Transaction) []string { return []string{ fmt.Sprintf("%d", tx.Txid), func() string { diff --git a/cmd/ledger/transactions/num.go b/cmd/ledger/transactions/num.go index f0bf15ca..a792b8f4 100644 --- a/cmd/ledger/transactions/num.go +++ b/cmd/ledger/transactions/num.go @@ -8,8 +8,8 @@ import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/collectionutils" "github.com/formancehq/fctl/v3/cmd/ledger/internal" @@ -17,7 +17,7 @@ import ( ) type NumStore struct { - Transaction *shared.Transaction `json:"transaction"` + Transaction *ledger.Transaction `json:"transaction"` } type NumController struct { store *NumStore @@ -145,13 +145,13 @@ func (c *NumController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, return nil, err } - ledger := fctl.GetString(cmd, internal.LedgerFlag) + ledgerName := fctl.GetString(cmd, internal.LedgerFlag) response, err := stackClient.Ledger.V1.CreateTransaction(cmd.Context(), operations.CreateTransactionRequest{ - PostTransaction: shared.PostTransaction{ + PostTransaction: ledger.PostTransaction{ Metadata: collectionutils.ConvertMap(metadata, collectionutils.ToAny[string]), Reference: &reference, - Script: &shared.PostTransactionScript{ + Script: &ledger.PostTransactionScript{ Plain: script, Vars: vars, }, @@ -162,7 +162,7 @@ func (c *NumController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, return ×tamp }(), }, - Ledger: ledger, + Ledger: ledgerName, }) if err != nil { return nil, err diff --git a/cmd/ledger/transactions/revert.go b/cmd/ledger/transactions/revert.go index e242d44e..b24f5f1f 100644 --- a/cmd/ledger/transactions/revert.go +++ b/cmd/ledger/transactions/revert.go @@ -3,7 +3,7 @@ package transactions import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/pointer" "github.com/formancehq/fctl/v3/cmd/ledger/internal" @@ -82,7 +82,7 @@ func (c *RevertController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, err } - c.store.Transaction = internal.WrapV2Transaction(response.V2RevertTransactionResponse.Data) + c.store.Transaction = internal.WrapV2Transaction(response.V2CreateTransactionResponse.V2Transaction) } else { request := operations.RevertTransactionRequest{ Ledger: ledger, @@ -95,7 +95,7 @@ func (c *RevertController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, err } - c.store.Transaction = internal.WrapV1Transaction(response.TransactionResponse.Data) + c.store.Transaction = internal.WrapV1Transaction(response.TransactionResponse.Transaction) } return c, nil diff --git a/cmd/ledger/transactions/set_metadata.go b/cmd/ledger/transactions/set_metadata.go index ac72b6d1..14e0ad89 100644 --- a/cmd/ledger/transactions/set_metadata.go +++ b/cmd/ledger/transactions/set_metadata.go @@ -4,7 +4,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/v4/pkg/models/operations" "github.com/formancehq/go-libs/v4/collectionutils" "github.com/formancehq/fctl/v3/cmd/ledger/internal" diff --git a/cmd/ledger/transactions/show.go b/cmd/ledger/transactions/show.go index 88e7bcc3..83d4b7be 100644 --- a/cmd/ledger/transactions/show.go +++ b/cmd/ledger/transactions/show.go @@ -3,15 +3,15 @@ package transactions import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/ledger/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Transaction shared.Transaction `json:"transaction"` + Transaction ledger.Transaction `json:"transaction"` } type ShowController struct { store *ShowStore @@ -69,7 +69,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, err } - c.store.Transaction = response.TransactionResponse.Data + c.store.Transaction = response.TransactionResponse.Transaction return c, nil } diff --git a/cmd/ledger/volumes/list.go b/cmd/ledger/volumes/list.go index cfba80a8..3d50890b 100644 --- a/cmd/ledger/volumes/list.go +++ b/cmd/ledger/volumes/list.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/ledger/internal" fctl "github.com/formancehq/fctl/v3/pkg" @@ -15,7 +15,7 @@ import ( ) type ListStore struct { - Cursor shared.V2VolumesWithBalanceCursorResponseCursor + Cursor ledger.V2VolumesWithBalanceCursorResponseCursor } type ListController struct { @@ -88,7 +88,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable } request := operations.V2GetVolumesWithBalancesRequest{ - Query: map[string]any{ + RequestBody: map[string]any{ "$and": body, }, Ledger: fctl.GetString(cmd, internal.LedgerFlag), @@ -114,7 +114,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(volume shared.V2VolumesWithBalance) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(volume ledger.V2VolumesWithBalance) []string { return []string{ volume.Account, volume.Asset, diff --git a/cmd/orchestration/instances/describe.go b/cmd/orchestration/instances/describe.go index 76a772e7..4ad3b239 100644 --- a/cmd/orchestration/instances/describe.go +++ b/cmd/orchestration/instances/describe.go @@ -8,15 +8,15 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - formance "github.com/formancehq/formance-sdk-go/v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + formance "github.com/formancehq/formance-sdk-go/v4" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) type InstancesDescribeStore struct { - WorkflowInstancesHistory []shared.WorkflowInstanceHistory `json:"workflowInstanceHistory"` + WorkflowInstancesHistory []orchestration.WorkflowInstanceHistory `json:"workflowInstanceHistory"` } type InstancesDescribeController struct { store *InstancesDescribeStore @@ -67,7 +67,7 @@ func (c *InstancesDescribeController) Run(cmd *cobra.Command, args []string) (fc return nil, err } - c.store.WorkflowInstancesHistory = response.GetWorkflowInstanceHistoryResponse.Data + c.store.WorkflowInstancesHistory = response.GetWorkflowInstanceHistoryResponse.WorkflowInstanceHistoryList return c, nil } @@ -93,7 +93,7 @@ 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 orchestration.WorkflowInstanceHistory) { 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 { @@ -101,33 +101,33 @@ func printHistoryBaseInfo(out io.Writer, name string, ind int, history shared.Wo } } -func stageSourceName(src *shared.StageSendSource) string { +func stageSourceName(src *orchestration.StageSendSource) string { switch { - case src.Wallet != nil: - return fmt.Sprintf("wallet '%s' (balance: %s)", src.Wallet.ID, *src.Wallet.Balance) - case src.Account != nil: - return fmt.Sprintf("account '%s' (ledger: %s)", src.Account.ID, *src.Account.Ledger) - case src.Payment != nil: - return fmt.Sprintf("payment '%s'", src.Payment.ID) + case src.StageSendSourceWallet != nil: + return fmt.Sprintf("wallet '%s' (balance: %s)", src.StageSendSourceWallet.ID, *src.StageSendSourceWallet.Balance) + case src.StageSendSourceAccount != nil: + return fmt.Sprintf("account '%s' (ledger: %s)", src.StageSendSourceAccount.ID, *src.StageSendSourceAccount.Ledger) + case src.StageSendSourcePayment != nil: + return fmt.Sprintf("payment '%s'", src.StageSendSourcePayment.ID) default: return "unknown_source_type" } } -func stageDestinationName(dst *shared.StageSendDestination) string { +func stageDestinationName(dst *orchestration.StageSendDestination) string { switch { - case dst.Wallet != nil: - return fmt.Sprintf("wallet '%s' (balance: %s)", dst.Wallet.ID, *dst.Wallet.Balance) - case dst.Account != nil: - return fmt.Sprintf("account '%s' (ledger: %s)", dst.Account.ID, *dst.Account.Ledger) - case dst.Payment != nil: - return dst.Payment.Psp + case dst.StageSendSourceWallet != nil: + return fmt.Sprintf("wallet '%s' (balance: %s)", dst.StageSendSourceWallet.ID, *dst.StageSendSourceWallet.Balance) + case dst.StageSendSourceAccount != nil: + return fmt.Sprintf("account '%s' (ledger: %s)", dst.StageSendSourceAccount.ID, *dst.StageSendSourceAccount.Ledger) + case dst.StageSendDestinationPayment != nil: + return dst.StageSendDestinationPayment.Psp default: return "unknown_source_type" } } -func subjectName(src shared.Subject) string { +func subjectName(src orchestration.Subject) string { switch { case src.WalletSubject != nil: return fmt.Sprintf("wallet %s (balance: %s)", src.WalletSubject.Identifier, *src.WalletSubject.Balance) @@ -150,18 +150,18 @@ 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 orchestration.WorkflowInstanceHistory) error { cyanWriter := fctl.BasicTextCyan defaultWriter := fctl.BasicText listItems := make([]pterm.BulletListItem, 0) - switch history.Input.Type { - case shared.StageTypeStageSend: + switch history.Stage.Type { + case orchestration.StageTypeStageSend: 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)) + cyanWriter.Printfln("Send %v %s from %s to %s", history.Stage.StageSend.Monetary.Amount, + history.Stage.StageSend.Monetary.Asset, stageSourceName(history.Stage.StageSend.StageSendSource), + stageDestinationName(history.Stage.StageSend.StageSendDestination)) fctl.Println() stageResponse, err := client.Orchestration.V1.GetInstanceStageHistory(cmd.Context(), operations.GetInstanceStageHistoryRequest{ @@ -172,82 +172,82 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, return err } - for _, historyStage := range stageResponse.GetWorkflowInstanceHistoryStageResponse.Data { + for _, historyStage := range stageResponse.GetWorkflowInstanceHistoryStageResponse.WorkflowInstanceHistoryStageList { switch { - case historyStage.Input.StripeTransfer != nil: + case historyStage.WorkflowInstanceHistoryStageInput.StripeTransferRequest != nil: listItems = append(listItems, historyItemTitle("Send %v %s to Stripe connected account: %s", - *historyStage.Input.StripeTransfer.Amount, - *historyStage.Input.StripeTransfer.Asset, - *historyStage.Input.StripeTransfer.Destination, + *historyStage.WorkflowInstanceHistoryStageInput.StripeTransferRequest.Amount, + *historyStage.WorkflowInstanceHistoryStageInput.StripeTransferRequest.Asset, + *historyStage.WorkflowInstanceHistoryStageInput.StripeTransferRequest.Destination, )) - case historyStage.Input.CreateTransaction != nil: + case historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction != 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, + historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.PostTransaction.Postings[0].Amount, + historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.PostTransaction.Postings[0].Asset, + historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.PostTransaction.Postings[0].Source, + historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.PostTransaction.Postings[0].Destination, + *historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.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)) + listItems = append(listItems, historyItemDetails("Created transaction: %d", historyStage.WorkflowInstanceHistoryStageOutput.CreateTransactionResponse.Transaction.ID)) + if historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.PostTransaction.Reference != nil { + listItems = append(listItems, historyItemDetails("Reference: %s", *historyStage.WorkflowInstanceHistoryStageOutput.CreateTransactionResponse.Transaction.Reference)) } - if len(historyStage.Input.CreateTransaction.Data.Metadata) > 0 { - listItems = append(listItems, printMetadata(historyStage.Input.CreateTransaction.Data.Metadata)...) + if len(historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.PostTransaction.Metadata) > 0 { + listItems = append(listItems, printMetadata(historyStage.WorkflowInstanceHistoryStageInput.ActivityCreateTransaction.PostTransaction.Metadata)...) } } - case historyStage.Input.ConfirmHold != nil: - listItems = append(listItems, historyItemTitle("Confirm debit hold %s", historyStage.Input.ConfirmHold.ID)) - case historyStage.Input.CreditWallet != nil: + case historyStage.WorkflowInstanceHistoryStageInput.ActivityConfirmHold != nil: + listItems = append(listItems, historyItemTitle("Confirm debit hold %s", historyStage.WorkflowInstanceHistoryStageInput.ActivityConfirmHold.ID)) + case historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet != nil: listItems = append(listItems, historyItemTitle("Credit wallet %s (balance: %s) of %v %s from %s", - *historyStage.Input.CreditWallet.ID, - *historyStage.Input.CreditWallet.Data.Balance, - historyStage.Input.CreditWallet.Data.Amount.Amount, - historyStage.Input.CreditWallet.Data.Amount.Asset, - subjectName(historyStage.Input.CreditWallet.Data.Sources[0]), + *historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet.ID, + *historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet.CreditWalletRequest.Balance, + historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet.CreditWalletRequest.Monetary.Amount, + historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet.CreditWalletRequest.Monetary.Asset, + subjectName(historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet.CreditWalletRequest.Sources[0]), )) if historyStage.Error == nil && historyStage.LastFailure == nil && historyStage.Terminated { - if len(historyStage.Input.CreditWallet.Data.Metadata) > 0 { - listItems = append(listItems, printMetadata(historyStage.Input.CreditWallet.Data.Metadata)...) + if len(historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet.CreditWalletRequest.Metadata) > 0 { + listItems = append(listItems, printMetadata(historyStage.WorkflowInstanceHistoryStageInput.ActivityCreditWallet.CreditWalletRequest.Metadata)...) } } - case historyStage.Input.DebitWallet != nil: + case historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet != nil: destination := "@world" - if historyStage.Input.DebitWallet.Data.Destination != nil { - destination = subjectName(*historyStage.Input.DebitWallet.Data.Destination) + if historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.DebitWalletRequest.Subject != nil { + destination = subjectName(*historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.DebitWalletRequest.Subject) } listItems = append(listItems, historyItemTitle("Debit wallet %s (balance: %s) of %v %s to %s", - *historyStage.Input.DebitWallet.ID, - historyStage.Input.DebitWallet.Data.Balances[0], - historyStage.Input.DebitWallet.Data.Amount.Amount, - historyStage.Input.DebitWallet.Data.Amount.Asset, + *historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.ID, + historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.DebitWalletRequest.Balances[0], + historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.DebitWalletRequest.Monetary.Amount, + historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.DebitWalletRequest.Monetary.Asset, destination, )) if historyStage.Error == nil && historyStage.LastFailure == nil && historyStage.Terminated { - if len(historyStage.Input.DebitWallet.Data.Metadata) > 0 { - listItems = append(listItems, printMetadata(historyStage.Input.DebitWallet.Data.Metadata)...) + if len(historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.DebitWalletRequest.Metadata) > 0 { + listItems = append(listItems, printMetadata(historyStage.WorkflowInstanceHistoryStageInput.ActivityDebitWallet.DebitWalletRequest.Metadata)...) } } - case historyStage.Input.GetAccount != nil: + case historyStage.WorkflowInstanceHistoryStageInput.ActivityGetAccount != nil: listItems = append(listItems, historyItemTitle("Read account %s of ledger %s", - historyStage.Input.GetAccount.ID, - historyStage.Input.GetAccount.Ledger, + historyStage.WorkflowInstanceHistoryStageInput.ActivityGetAccount.ID, + historyStage.WorkflowInstanceHistoryStageInput.ActivityGetAccount.Ledger, )) - case historyStage.Input.GetPayment != nil: + case historyStage.WorkflowInstanceHistoryStageInput.ActivityGetPayment != nil: listItems = append(listItems, historyItemTitle("Read payment %s", - 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)) + historyStage.WorkflowInstanceHistoryStageInput.ActivityGetPayment.ID)) + case historyStage.WorkflowInstanceHistoryStageInput.ActivityGetWallet != nil: + listItems = append(listItems, historyItemTitle("Read wallet '%s'", historyStage.WorkflowInstanceHistoryStageInput.ActivityGetWallet.ID)) + case historyStage.WorkflowInstanceHistoryStageInput.ActivityRevertTransaction != nil: + listItems = append(listItems, historyItemTitle("Revert transaction %s", historyStage.WorkflowInstanceHistoryStageInput.ActivityRevertTransaction.ID)) if historyStage.Error == nil { - listItems = append(listItems, historyItemTitle("Created transaction: %d", historyStage.Output.RevertTransaction.Data.ID)) + listItems = append(listItems, historyItemTitle("Created transaction: %d", historyStage.WorkflowInstanceHistoryStageOutput.CreateTransactionResponse1.Transaction.ID)) } - case historyStage.Input.VoidHold != nil: - listItems = append(listItems, historyItemTitle("Cancel debit hold %s", historyStage.Input.VoidHold.ID)) - case historyStage.Input.ListWallets != nil: + case historyStage.WorkflowInstanceHistoryStageInput.ActivityVoidHold != nil: + listItems = append(listItems, historyItemTitle("Cancel debit hold %s", historyStage.WorkflowInstanceHistoryStageInput.ActivityVoidHold.ID)) + case historyStage.WorkflowInstanceHistoryStageInput.ActivityListWallets != nil: listItems = append(listItems, historyItemTitle("List wallets")) } if historyStage.LastFailure != nil { @@ -261,17 +261,17 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, listItems = append(listItems, historyItemError("%s", *historyStage.Error)) } } - case shared.StageTypeStageDelay: + case orchestration.StageTypeStageDelay: 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)) + case history.Stage.StageDelay.Duration != nil: + listItems = append(listItems, historyItemTitle("Pause workflow for a delay of %s", *history.Stage.StageDelay.Duration)) + case history.Stage.StageDelay.Until != nil: + listItems = append(listItems, historyItemTitle("Pause workflow until %s", *history.Stage.StageDelay.Until)) } - case shared.StageTypeStageWaitEvent: + case orchestration.StageTypeStageWaitEvent: printHistoryBaseInfo(cmd.OutOrStdout(), "wait_event", i, history) - listItems = append(listItems, historyItemTitle("Waiting event '%s'", history.Input.StageWaitEvent.Event)) + listItems = append(listItems, historyItemTitle("Waiting event '%s'", history.Stage.StageWaitEvent.Event)) if history.Error == nil { if history.Terminated { listItems = append(listItems, historyItemDetails("Event received!")) @@ -279,11 +279,11 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, listItems = append(listItems, historyItemDetails("Still waiting event...")) } } - case shared.StageTypeUpdate: + case orchestration.StageTypeUpdate: printHistoryBaseInfo(cmd.OutOrStdout(), "update", i, history) switch { - case history.Input.Update.Account != nil: - account := history.Input.Update.Account + case history.Stage.Update.UpdateAccount != nil: + account := history.Stage.Update.UpdateAccount listItems = append(listItems, historyItemTitle("Update account '%s' of ledger '%s'", account.ID, account.Ledger)) listItems = append(listItems, printMetadata(account.Metadata)...) } diff --git a/cmd/orchestration/instances/list.go b/cmd/orchestration/instances/list.go index 18920d94..bc772eaa 100644 --- a/cmd/orchestration/instances/list.go +++ b/cmd/orchestration/instances/list.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -81,7 +81,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.ListRunsResponse.Data, func(src orchestration.WorkflowInstance) 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 0136a5fc..1e5e7d53 100644 --- a/cmd/orchestration/instances/send_event.go +++ b/cmd/orchestration/instances/send_event.go @@ -4,7 +4,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/orchestration/instances/show.go b/cmd/orchestration/instances/show.go index 43a1e202..6a9c7763 100644 --- a/cmd/orchestration/instances/show.go +++ b/cmd/orchestration/instances/show.go @@ -7,16 +7,16 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" "github.com/formancehq/fctl/v3/cmd/orchestration/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type InstancesShowStore struct { - WorkflowInstance shared.WorkflowInstance `json:"workflowInstance"` - Workflow shared.Workflow `json:"workflow"` + WorkflowInstance orchestration.WorkflowInstance `json:"workflowInstance"` + Workflow orchestration.Workflow `json:"workflow"` } type InstancesShowController struct { store *InstancesShowStore @@ -66,15 +66,15 @@ func (c *InstancesShowController) Run(cmd *cobra.Command, args []string) (fctl.R return nil, fmt.Errorf("reading instance: %w", err) } - c.store.WorkflowInstance = res.GetWorkflowInstanceResponse.Data + c.store.WorkflowInstance = res.GetWorkflowInstanceResponse.WorkflowInstance response, err := stackClient.Orchestration.V1.GetWorkflow(cmd.Context(), operations.GetWorkflowRequest{ - FlowID: res.GetWorkflowInstanceResponse.Data.WorkflowID, + FlowID: res.GetWorkflowInstanceResponse.WorkflowInstance.WorkflowID, }) if err != nil { return nil, err } - c.store.Workflow = response.GetWorkflowResponse.Data + c.store.Workflow = response.GetWorkflowResponse.Workflow return c, nil } diff --git a/cmd/orchestration/instances/stop.go b/cmd/orchestration/instances/stop.go index 380b6c6c..dec37ea7 100644 --- a/cmd/orchestration/instances/stop.go +++ b/cmd/orchestration/instances/stop.go @@ -4,7 +4,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/orchestration/internal/print.go b/cmd/orchestration/internal/print.go index 1bab538c..d3e0308c 100644 --- a/cmd/orchestration/internal/print.go +++ b/cmd/orchestration/internal/print.go @@ -7,12 +7,12 @@ import ( "github.com/pterm/pterm" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) -func PrintWorkflowInstance(out io.Writer, w shared.Workflow, instance shared.WorkflowInstance) error { +func PrintWorkflowInstance(out io.Writer, w orchestration.Workflow, instance orchestration.WorkflowInstance) error { fctl.Section.WithWriter(out).Println("Stages") ind := 0 @@ -22,8 +22,8 @@ func PrintWorkflowInstance(out io.Writer, w shared.Workflow, instance shared.Wor WithData( fctl.Prepend( fctl.Map(instance.Status, - func(src shared.StageStatus) []string { - stage := w.Config.Stages[ind] + func(src orchestration.StageStatus) []string { + stage := w.WorkflowConfig.Stages[ind] var name string for name = range stage { } diff --git a/cmd/orchestration/triggers/create.go b/cmd/orchestration/triggers/create.go index 30e9ff46..311a2c9c 100644 --- a/cmd/orchestration/triggers/create.go +++ b/cmd/orchestration/triggers/create.go @@ -8,14 +8,14 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" "github.com/formancehq/go-libs/v4/pointer" fctl "github.com/formancehq/fctl/v3/pkg" ) type TriggersCreateStore struct { - Trigger shared.Trigger `json:"trigger"` + Trigger orchestration.TriggerData `json:"trigger"` } type TriggersCreateController struct { store *TriggersCreateStore @@ -76,7 +76,7 @@ func (c *TriggersCreateController) Run(cmd *cobra.Command, args []string) (fctl. workflow = args[1] ) - data := &shared.TriggerData{ + data := &orchestration.TriggerData1{ Event: event, Name: &name, WorkflowID: workflow, @@ -100,7 +100,7 @@ func (c *TriggersCreateController) Run(cmd *cobra.Command, args []string) (fctl. return nil, fmt.Errorf("reading trigger: %w", err) } - c.store.Trigger = res.CreateTriggerResponse.Data + c.store.Trigger = res.CreateTriggerResponse.TriggerData return c, nil } diff --git a/cmd/orchestration/triggers/delete.go b/cmd/orchestration/triggers/delete.go index 15f72894..deaf2f70 100644 --- a/cmd/orchestration/triggers/delete.go +++ b/cmd/orchestration/triggers/delete.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/orchestration/triggers/list.go b/cmd/orchestration/triggers/list.go index 1d4eabc2..36c46e10 100644 --- a/cmd/orchestration/triggers/list.go +++ b/cmd/orchestration/triggers/list.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) type TriggersListStore struct { - WorkflowTrigger []shared.Trigger `json:"workflowTriggers"` + WorkflowTrigger []orchestration.TriggerData `json:"workflowTriggers"` } type TriggersListController struct { store *TriggersListStore @@ -86,7 +86,7 @@ func (c *TriggersListController) Render(cmd *cobra.Command, args []string) error WithData( fctl.Prepend( fctl.Map(c.store.WorkflowTrigger, - func(src shared.Trigger) []string { + func(src orchestration.TriggerData) []string { return []string{ src.ID, *src.Name, diff --git a/cmd/orchestration/triggers/occurrences/list.go b/cmd/orchestration/triggers/occurrences/list.go index 3c5c7dd9..5f6c3145 100644 --- a/cmd/orchestration/triggers/occurrences/list.go +++ b/cmd/orchestration/triggers/occurrences/list.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) type OccurrencesListStore struct { - WorkflowOccurrence []shared.TriggerOccurrence `json:"occurrences"` + WorkflowOccurrence []orchestration.TriggerOccurrence `json:"occurrences"` } type OccurrencesListController struct { store *OccurrencesListStore @@ -82,7 +82,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 orchestration.TriggerOccurrence) []string { return []string{ func() string { if src.WorkflowInstanceID != nil { diff --git a/cmd/orchestration/triggers/show.go b/cmd/orchestration/triggers/show.go index 32a2dd2d..d548f5ff 100644 --- a/cmd/orchestration/triggers/show.go +++ b/cmd/orchestration/triggers/show.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) type TriggersShowStore struct { - Trigger shared.Trigger `json:"trigger"` + Trigger orchestration.TriggerData `json:"trigger"` } type TriggersShowController struct { store *TriggersShowStore @@ -64,7 +64,7 @@ func (c *TriggersShowController) Run(cmd *cobra.Command, args []string) (fctl.Re return nil, fmt.Errorf("reading trigger: %w", err) } - c.store.Trigger = res.ReadTriggerResponse.Data + c.store.Trigger = res.ReadTriggerResponse.TriggerData return c, nil } diff --git a/cmd/orchestration/triggers/test.go b/cmd/orchestration/triggers/test.go index c5a1013c..e1819620 100644 --- a/cmd/orchestration/triggers/test.go +++ b/cmd/orchestration/triggers/test.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) type TriggersTestStore struct { - Trigger shared.V2TriggerTest `json:"trigger"` + Trigger orchestration.V2TriggerTest `json:"trigger"` } type TriggersTestController struct { store *TriggersTestStore @@ -70,7 +70,7 @@ func (c *TriggersTestController) Run(cmd *cobra.Command, args []string) (fctl.Re return nil, fmt.Errorf("testing trigger: %w", err) } - c.store.Trigger = res.V2TestTriggerResponse.Data + c.store.Trigger = res.V2TestTriggerResponse.V2TriggerTest return c, nil } diff --git a/cmd/orchestration/workflows/create.go b/cmd/orchestration/workflows/create.go index e34b6d0c..14e86180 100644 --- a/cmd/orchestration/workflows/create.go +++ b/cmd/orchestration/workflows/create.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" "gopkg.in/yaml.v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -59,14 +59,14 @@ func (c *WorkflowsCreateController) Run(cmd *cobra.Command, args []string) (fctl return nil, err } - config := shared.CreateWorkflowRequest{} + config := orchestration.WorkflowConfig{} if err := yaml.Unmarshal([]byte(script), &config); err != nil { return nil, err } //nolint:gosimple response, err := stackClient.Orchestration.V1. - CreateWorkflow(cmd.Context(), &shared.CreateWorkflowRequest{ + CreateWorkflow(cmd.Context(), &orchestration.WorkflowConfig{ Name: config.Name, Stages: config.Stages, }) @@ -74,7 +74,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.CreateWorkflowResponse.Workflow.ID return c, nil } diff --git a/cmd/orchestration/workflows/delete.go b/cmd/orchestration/workflows/delete.go index 9f924e33..7f1a5de9 100644 --- a/cmd/orchestration/workflows/delete.go +++ b/cmd/orchestration/workflows/delete.go @@ -4,7 +4,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/orchestration/workflows/list.go b/cmd/orchestration/workflows/list.go index c2b80d2f..22f64692 100644 --- a/cmd/orchestration/workflows/list.go +++ b/cmd/orchestration/workflows/list.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -68,12 +68,12 @@ func (c *WorkflowsListController) Run(cmd *cobra.Command, args []string) (fctl.R return nil, err } - c.store.Workflows = fctl.Map(response.ListWorkflowsResponse.Data, func(src shared.Workflow) Workflow { + c.store.Workflows = fctl.Map(response.ListWorkflowsResponse.Data, func(src orchestration.Workflow) Workflow { return Workflow{ ID: src.ID, Name: func() string { - if src.Config.Name != nil { - return *src.Config.Name + if src.WorkflowConfig.Name != nil { + return *src.WorkflowConfig.Name } return "" }(), diff --git a/cmd/orchestration/workflows/run.go b/cmd/orchestration/workflows/run.go index 0f281279..9f6bb180 100644 --- a/cmd/orchestration/workflows/run.go +++ b/cmd/orchestration/workflows/run.go @@ -7,15 +7,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" "github.com/formancehq/fctl/v3/cmd/orchestration/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type WorkflowsRunStore struct { - WorkflowInstance shared.WorkflowInstance `json:"workflowInstance"` + WorkflowInstance orchestration.WorkflowInstance `json:"workflowInstance"` } type WorkflowsRunController struct { store *WorkflowsRunStore @@ -88,7 +88,7 @@ func (c *WorkflowsRunController) Run(cmd *cobra.Command, args []string) (fctl.Re } c.wait = wait - c.store.WorkflowInstance = response.RunWorkflowResponse.Data + c.store.WorkflowInstance = response.RunWorkflowResponse.WorkflowInstance return c, nil } @@ -112,7 +112,7 @@ func (c *WorkflowsRunController) Render(cmd *cobra.Command, args []string) error panic(err) } - return internal.PrintWorkflowInstance(cmd.OutOrStdout(), w.GetWorkflowResponse.Data, c.store.WorkflowInstance) + return internal.PrintWorkflowInstance(cmd.OutOrStdout(), w.GetWorkflowResponse.Workflow, c.store.WorkflowInstance) } return nil } diff --git a/cmd/orchestration/workflows/show.go b/cmd/orchestration/workflows/show.go index 466240ed..29276774 100644 --- a/cmd/orchestration/workflows/show.go +++ b/cmd/orchestration/workflows/show.go @@ -8,14 +8,14 @@ import ( "github.com/spf13/cobra" "gopkg.in/yaml.v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/orchestration" fctl "github.com/formancehq/fctl/v3/pkg" ) type WorkflowsShowStore struct { - Workflow shared.Workflow `json:"workflow"` + Workflow orchestration.Workflow `json:"workflow"` } type WorkflowsShowController struct { store *WorkflowsShowStore @@ -66,7 +66,7 @@ func (c *WorkflowsShowController) Run(cmd *cobra.Command, args []string) (fctl.R return nil, err } - c.store.Workflow = response.GetWorkflowResponse.Data + c.store.Workflow = response.GetWorkflowResponse.Workflow return c, nil } @@ -76,8 +76,8 @@ func (c *WorkflowsShowController) Render(cmd *cobra.Command, args []string) erro tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("ID"), c.store.Workflow.ID}) tableData = append(tableData, []string{pterm.LightCyan("Name"), func() string { - if c.store.Workflow.Config.Name != nil { - return *c.store.Workflow.Config.Name + if c.store.Workflow.WorkflowConfig.Name != nil { + return *c.store.Workflow.WorkflowConfig.Name } return "" }()}) @@ -94,7 +94,7 @@ func (c *WorkflowsShowController) Render(cmd *cobra.Command, args []string) erro fmt.Fprintln(cmd.OutOrStdout()) fctl.Section.WithWriter(cmd.OutOrStdout()).Println("Configuration") - configAsBytes, err := yaml.Marshal(c.store.Workflow.Config) + configAsBytes, err := yaml.Marshal(c.store.Workflow.WorkflowConfig) if err != nil { panic(err) } diff --git a/cmd/payments/accounts/balances.go b/cmd/payments/accounts/balances.go index 4e191d45..e68650b6 100644 --- a/cmd/payments/accounts/balances.go +++ b/cmd/payments/accounts/balances.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListBalancesStore struct { - Cursor *shared.BalancesCursorCursor `json:"cursor"` + Cursor *payments.BalancesCursorCursorBase `json:"cursor"` } type ListBalancesController struct { @@ -28,7 +28,7 @@ var _ fctl.Controller[*ListBalancesStore] = (*ListBalancesController)(nil) func NewListBalanceStore() *ListBalancesStore { return &ListBalancesStore{ - Cursor: &shared.BalancesCursorCursor{}, + Cursor: &payments.BalancesCursorCursorBase{}, } } @@ -83,13 +83,13 @@ func (c *ListBalancesController) Run(cmd *cobra.Command, args []string) (fctl.Re return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Cursor = &response.BalancesCursor.Cursor + c.store.Cursor = &response.BalancesCursor.CursorBase return c, nil } func (c *ListBalancesController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(balance shared.AccountBalance) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(balance payments.AccountBalance) []string { return []string{ balance.AccountID, balance.Asset, diff --git a/cmd/payments/accounts/create.go b/cmd/payments/accounts/create.go index 5cec3714..03346a8d 100644 --- a/cmd/payments/accounts/create.go +++ b/cmd/payments/accounts/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -81,7 +81,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, err } - request := shared.AccountRequest{} + request := payments.AccountRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -96,7 +96,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.AccountID = response.PaymentsAccountResponse.Data.ID + c.store.AccountID = response.AccountResponse.Account.ID return c, nil } diff --git a/cmd/payments/accounts/list.go b/cmd/payments/accounts/list.go index b10ac23f..c30b0a52 100644 --- a/cmd/payments/accounts/list.go +++ b/cmd/payments/accounts/list.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Cursor *shared.Cursor `json:"cursor"` + Cursor *payments.CursorBase `json:"cursor"` } type ListController struct { @@ -28,7 +28,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewListStore() *ListStore { return &ListStore{ - Cursor: &shared.Cursor{}, + Cursor: &payments.CursorBase{}, } } @@ -66,9 +66,9 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable pageSize = fctl.Ptr(int64(ps)) } - response, err := stackClient.Payments.V1.PaymentslistAccounts( + response, err := stackClient.Payments.V1.ListAccountsPayments( cmd.Context(), - operations.PaymentslistAccountsRequest{ + operations.ListAccountsPaymentsRequest{ Cursor: cursor, PageSize: pageSize, }, @@ -81,13 +81,13 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Cursor = &response.AccountsCursor.Cursor + c.store.Cursor = &response.AccountsCursor.CursorBase return c, nil } func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(acc shared.PaymentsAccount) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(acc payments.Account) []string { return []string{ acc.ID, acc.Reference, @@ -95,7 +95,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error { acc.AccountName, acc.DefaultAsset, acc.DefaultCurrency, - string(acc.Type), + string(acc.AccountType), acc.ConnectorID, } }) diff --git a/cmd/payments/accounts/show.go b/cmd/payments/accounts/show.go index 566a2d28..0b474f42 100644 --- a/cmd/payments/accounts/show.go +++ b/cmd/payments/accounts/show.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Account *shared.PaymentsAccount `json:"account"` + Account *payments.Account `json:"account"` } type ShowController struct { store *ShowStore @@ -58,7 +58,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, err } - response, err := stackClient.Payments.V1.PaymentsgetAccount(cmd.Context(), operations.PaymentsgetAccountRequest{ + response, err := stackClient.Payments.V1.GetAccountPayments(cmd.Context(), operations.GetAccountPaymentsRequest{ AccountID: args[0], }) if err != nil { @@ -69,7 +69,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Account = &response.PaymentsAccountResponse.Data + c.store.Account = &response.AccountResponse.Account return c, nil } @@ -84,7 +84,7 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { tableData = append(tableData, []string{pterm.LightCyan("DefaultAsset"), c.store.Account.DefaultAsset}) tableData = append(tableData, []string{pterm.LightCyan("DefaultCurrency"), c.store.Account.DefaultCurrency}) tableData = append(tableData, []string{pterm.LightCyan("Reference"), c.store.Account.Reference}) - tableData = append(tableData, []string{pterm.LightCyan("Type"), string(c.store.Account.Type)}) + tableData = append(tableData, []string{pterm.LightCyan("Type"), string(c.store.Account.AccountType)}) if err := pterm.DefaultTable. WithWriter(cmd.OutOrStdout()). @@ -93,5 +93,5 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { return err } - return fctl.PrintMetadata(cmd.OutOrStdout(), c.store.Account.Metadata) + return fctl.PrintMetadata(cmd.OutOrStdout(), c.store.Account.AccountMetadata) } diff --git a/cmd/payments/bankaccounts/create.go b/cmd/payments/bankaccounts/create.go index 1fd1a9ea..266225e5 100644 --- a/cmd/payments/bankaccounts/create.go +++ b/cmd/payments/bankaccounts/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -83,7 +83,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab } if c.PaymentsVersion.Major >= versions.V3 { - request := shared.V3CreateBankAccountRequest{} + request := payments.V3CreateBankAccountRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -100,7 +100,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return c, nil } - request := shared.BankAccountRequest{} + request := payments.BankAccountRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -115,7 +115,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.BankAccountID = response.BankAccountResponse.Data.ID + c.store.BankAccountID = response.BankAccountResponse.BankAccount.ID return c, nil } diff --git a/cmd/payments/bankaccounts/forward.go b/cmd/payments/bankaccounts/forward.go index 51785066..75ca01b5 100644 --- a/cmd/payments/bankaccounts/forward.go +++ b/cmd/payments/bankaccounts/forward.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -95,7 +95,7 @@ func (c *ForwardController) Run(cmd *cobra.Command, args []string) (fctl.Rendera if c.PaymentsVersion.Major < versions.V3 { //nolint:gosimple response, err := stackClient.Payments.V1.ForwardBankAccount(cmd.Context(), operations.ForwardBankAccountRequest{ - ForwardBankAccountRequest: shared.ForwardBankAccountRequest{ + ForwardBankAccountRequest: payments.ForwardBankAccountRequest{ ConnectorID: connectorID, }, BankAccountID: bankAccountID, @@ -108,14 +108,14 @@ func (c *ForwardController) Run(cmd *cobra.Command, args []string) (fctl.Rendera return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.BankAccountID = response.BankAccountResponse.Data.ID - c.store.ConnectorID = *response.BankAccountResponse.Data.ConnectorID + c.store.BankAccountID = response.BankAccountResponse.BankAccount.ID + c.store.ConnectorID = *response.BankAccountResponse.BankAccount.ConnectorID return c, nil } response, err := stackClient.Payments.V3.ForwardBankAccount(cmd.Context(), operations.V3ForwardBankAccountRequest{ - V3ForwardBankAccountRequest: &shared.V3ForwardBankAccountRequest{ + V3ForwardBankAccountRequest: &payments.V3ForwardBankAccountRequest{ ConnectorID: connectorID, }, BankAccountID: bankAccountID, diff --git a/cmd/payments/bankaccounts/list.go b/cmd/payments/bankaccounts/list.go index 2c9ad41a..d03b4d5a 100644 --- a/cmd/payments/bankaccounts/list.go +++ b/cmd/payments/bankaccounts/list.go @@ -7,16 +7,16 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - formance "github.com/formancehq/formance-sdk-go/v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + formance "github.com/formancehq/formance-sdk-go/v4" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Cursor *shared.V3BankAccountsCursorResponseCursor `json:"cursor"` + Cursor *payments.V3BankAccountsCursorResponseCursor `json:"cursor"` } type ListController struct { @@ -36,7 +36,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewListStore() *ListStore { return &ListStore{ - Cursor: &shared.V3BankAccountsCursorResponseCursor{}, + Cursor: &payments.V3BankAccountsCursorResponseCursor{}, } } @@ -102,7 +102,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Cursor = ToV3BankAccountCursor(&response.BankAccountsCursor.Cursor) + c.store.Cursor = ToV3BankAccountCursor(&response.BankAccountsCursor.CursorBase) return c, nil } @@ -128,9 +128,9 @@ func (c *ListController) v3list(cmd *cobra.Command, stackClient *formance.Forman return c, nil } -func ToV3BankAccountCursor(c *shared.BankAccountsCursorCursor) *shared.V3BankAccountsCursorResponseCursor { - cursor := &shared.V3BankAccountsCursorResponseCursor{ - Data: make([]shared.V3BankAccount, 0, len(c.Data)), +func ToV3BankAccountCursor(c *payments.BankAccountsCursorCursorBase) *payments.V3BankAccountsCursorResponseCursor { + cursor := &payments.V3BankAccountsCursorResponseCursor{ + Data: make([]payments.V3BankAccount, 0, len(c.Data)), HasMore: c.HasMore, Next: c.Next, Previous: c.Previous, @@ -143,7 +143,7 @@ func ToV3BankAccountCursor(c *shared.BankAccountsCursorCursor) *shared.V3BankAcc } func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(bc shared.V3BankAccount) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(bc payments.V3BankAccount) []string { row := []string{ bc.ID, bc.Name, diff --git a/cmd/payments/bankaccounts/show.go b/cmd/payments/bankaccounts/show.go index b5b5bb55..6812a9d5 100644 --- a/cmd/payments/bankaccounts/show.go +++ b/cmd/payments/bankaccounts/show.go @@ -7,15 +7,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - BankAccount *shared.V3BankAccount `json:"bankAccount"` + BankAccount *payments.V3BankAccount `json:"bankAccount"` } type ShowController struct { PaymentsVersion versions.Version @@ -84,7 +84,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable if response.StatusCode >= 300 { return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.BankAccount = &response.V3GetBankAccountResponse.Data + c.store.BankAccount = &response.V3GetBankAccountResponse.V3BankAccount return c, nil } @@ -100,26 +100,26 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - bankAccount := ToV3BankAccount(&response.BankAccountResponse.Data) + bankAccount := ToV3BankAccount(&response.BankAccountResponse.BankAccount) c.store.BankAccount = &bankAccount return c, nil } -func ToV3BankAccount(account *shared.BankAccount) shared.V3BankAccount { - v3Account := shared.V3BankAccount{ +func ToV3BankAccount(account *payments.BankAccount) payments.V3BankAccount { + v3Account := payments.V3BankAccount{ AccountNumber: account.AccountNumber, Country: &account.Country, CreatedAt: account.CreatedAt, Iban: account.Iban, ID: account.ID, - Metadata: account.Metadata, + V3Metadata: account.BankAccountMetadata, Name: account.Name, - RelatedAccounts: make([]shared.V3BankAccountRelatedAccount, 0, len(account.RelatedAccounts)), + RelatedAccounts: make([]payments.V3BankAccountRelatedAccount, 0, len(account.RelatedAccounts)), SwiftBicCode: account.SwiftBicCode, } for _, acc := range account.RelatedAccounts { - v3Account.RelatedAccounts = append(v3Account.RelatedAccounts, shared.V3BankAccountRelatedAccount{ + v3Account.RelatedAccounts = append(v3Account.RelatedAccounts, payments.V3BankAccountRelatedAccount{ AccountID: acc.AccountID, CreatedAt: acc.CreatedAt, }) @@ -154,7 +154,7 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { } fctl.Section.WithWriter(cmd.OutOrStdout()).Println("RelatedAccounts") - tableData = fctl.Map(c.store.BankAccount.RelatedAccounts, func(ba shared.V3BankAccountRelatedAccount) []string { + tableData = fctl.Map(c.store.BankAccount.RelatedAccounts, func(ba payments.V3BankAccountRelatedAccount) []string { return []string{ ba.AccountID, ba.CreatedAt.Format(time.RFC3339), @@ -169,5 +169,5 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { return err } - return fctl.PrintMetadata(cmd.OutOrStdout(), c.store.BankAccount.Metadata) + return fctl.PrintMetadata(cmd.OutOrStdout(), c.store.BankAccount.V3Metadata) } diff --git a/cmd/payments/bankaccounts/update_metadata.go b/cmd/payments/bankaccounts/update_metadata.go index adb1402c..170c64c1 100644 --- a/cmd/payments/bankaccounts/update_metadata.go +++ b/cmd/payments/bankaccounts/update_metadata.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -85,8 +85,8 @@ func (c *UpdateMetadataController) Run(cmd *cobra.Command, args []string) (fctl. } if c.PaymentsVersion.Major >= versions.V3 { request := operations.V3UpdateBankAccountMetadataRequest{ - V3UpdateBankAccountMetadataRequest: &shared.V3UpdateBankAccountMetadataRequest{ - Metadata: metadata, + V3UpdateBankAccountMetadataRequest: &payments.V3UpdateBankAccountMetadataRequest{ + V3Metadata: metadata, }, BankAccountID: bankAccountID, } @@ -105,8 +105,8 @@ func (c *UpdateMetadataController) Run(cmd *cobra.Command, args []string) (fctl. } request := operations.UpdateBankAccountMetadataRequest{ - UpdateBankAccountMetadataRequest: shared.UpdateBankAccountMetadataRequest{ - Metadata: metadata, + UpdateBankAccountMetadataRequest: payments.UpdateBankAccountMetadataRequest{ + BankAccountMetadata: metadata, }, BankAccountID: bankAccountID, } diff --git a/cmd/payments/connectors/configs.go b/cmd/payments/connectors/configs.go index 804a0ed6..a119cf46 100644 --- a/cmd/payments/connectors/configs.go +++ b/cmd/payments/connectors/configs.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - formance "github.com/formancehq/formance-sdk-go/v3" + formance "github.com/formancehq/formance-sdk-go/v4" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/payments/connectors/configs/getconfig.go b/cmd/payments/connectors/configs/getconfig.go index b81a1223..a6902b59 100644 --- a/cmd/payments/connectors/configs/getconfig.go +++ b/cmd/payments/connectors/configs/getconfig.go @@ -11,8 +11,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/go-libs/v4/collectionutils" "github.com/formancehq/fctl/v3/cmd/payments/connectors/internal" @@ -22,10 +22,10 @@ import ( ) type PaymentsLoadConfigStore struct { - ConnectorConfig *shared.ConnectorConfigResponse `json:"connectorConfig"` - V3ConfigData map[string]interface{} `json:"v3ConnectorConfig,omitempty"` - Provider string `json:"provider"` - ConnectorID string `json:"connectorId"` + ConnectorConfig *payments.ConnectorConfigResponse `json:"connectorConfig"` + V3ConfigData map[string]interface{} `json:"v3ConnectorConfig,omitempty"` + Provider string `json:"provider"` + ConnectorID string `json:"connectorId"` } type PaymentsLoadConfigController struct { @@ -148,7 +148,7 @@ func (c *PaymentsLoadConfigController) Run(cmd *cobra.Command, args []string) (f } response, err := stackClient.Payments.V1.ReadConnectorConfig(cmd.Context(), operations.ReadConnectorConfigRequest{ - Connector: shared.Connector(provider), + Connector: payments.Connector(provider), }) if err != nil { return nil, err @@ -175,13 +175,13 @@ func (c *PaymentsLoadConfigController) Run(cmd *cobra.Command, args []string) (f return nil, fmt.Errorf("unexpected status code: %d", connectorList.StatusCode) } - connectorsFiltered := collectionutils.Filter(connectorList.ConnectorsResponse.Data, func(connector shared.ConnectorsResponseData) bool { + connectorsFiltered := collectionutils.Filter(connectorList.ConnectorsResponse.Data, func(connector payments.ConnectorsResponseData) bool { if connectorID != "" { return connector.ConnectorID == connectorID } if provider != "" { - return connector.Provider == shared.Connector(strings.ToUpper(provider)) + return connector.Connector == payments.Connector(strings.ToUpper(provider)) } return true @@ -191,12 +191,12 @@ func (c *PaymentsLoadConfigController) Run(cmd *cobra.Command, args []string) (f case 0: return nil, fmt.Errorf("no connectors found") case 1: - provider = string(connectorsFiltered[0].Provider) + provider = string(connectorsFiltered[0].Connector) connectorID = connectorsFiltered[0].ConnectorID default: options := make([]string, 0, len(connectorsFiltered)) for _, connector := range connectorsFiltered { - options = append(options, strings.Join([]string{"id:" + connector.ConnectorID, "provider:" + string(connector.Provider), "name:" + connector.Name, "enabled:" + fctl.BoolPointerToString(connector.Enabled)}, " ")) + options = append(options, strings.Join([]string{"id:" + connector.ConnectorID, "provider:" + string(connector.Connector), "name:" + connector.Name, "enabled:" + fctl.BoolPointerToString(connector.Enabled)}, " ")) } printer := pterm.DefaultInteractiveSelect.WithOptions(options) selectedOption, err := printer.Show("Please select a connector") @@ -208,7 +208,7 @@ func (c *PaymentsLoadConfigController) Run(cmd *cobra.Command, args []string) (f } response, err := stackClient.Payments.V1.ReadConnectorConfigV1(cmd.Context(), operations.ReadConnectorConfigV1Request{ - Connector: shared.Connector(provider), + Connector: payments.Connector(provider), ConnectorID: connectorID, }) if err != nil { diff --git a/cmd/payments/connectors/configs/updateconfig.go b/cmd/payments/connectors/configs/updateconfig.go index 1b0a4a10..fef4c1cc 100644 --- a/cmd/payments/connectors/configs/updateconfig.go +++ b/cmd/payments/connectors/configs/updateconfig.go @@ -11,8 +11,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/connectors/internal" "github.com/formancehq/fctl/v3/cmd/payments/versions" @@ -167,13 +167,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( name := strings.ToLower(connectorName) switch name { case internal.AdyenConnector: - config := &shared.AdyenConfig{} + config := &payments.AdyenConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{AdyenConfig: config}, - Connector: shared.ConnectorAdyen, + ConnectorConfig: payments.ConnectorConfig{AdyenConfig: config}, + Connector: payments.ConnectorAdyen, ConnectorID: connectorID, }) if err != nil { @@ -184,13 +184,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.AtlarConnector: - config := &shared.AtlarConfig{} + config := &payments.AtlarConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{AtlarConfig: config}, - Connector: shared.ConnectorAtlar, + ConnectorConfig: payments.ConnectorConfig{AtlarConfig: config}, + Connector: payments.ConnectorAtlar, ConnectorID: connectorID, }) if err != nil { @@ -201,13 +201,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.BankingCircleConnector: - config := &shared.BankingCircleConfig{} + config := &payments.BankingCircleConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{BankingCircleConfig: config}, - Connector: shared.ConnectorBankingCircle, + ConnectorConfig: payments.ConnectorConfig{BankingCircleConfig: config}, + Connector: payments.ConnectorBankingCircle, ConnectorID: connectorID, }) if err != nil { @@ -218,13 +218,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.CurrencyCloudConnector: - config := &shared.CurrencyCloudConfig{} + config := &payments.CurrencyCloudConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{CurrencyCloudConfig: config}, - Connector: shared.ConnectorCurrencyCloud, + ConnectorConfig: payments.ConnectorConfig{CurrencyCloudConfig: config}, + Connector: payments.ConnectorCurrencyCloud, ConnectorID: connectorID, }) if err != nil { @@ -235,13 +235,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.MangoPayConnector: - config := &shared.MangoPayConfig{} + config := &payments.MangoPayConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{MangoPayConfig: config}, - Connector: shared.ConnectorMangopay, + ConnectorConfig: payments.ConnectorConfig{MangoPayConfig: config}, + Connector: payments.ConnectorMangopay, ConnectorID: connectorID, }) if err != nil { @@ -252,13 +252,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.ModulrConnector: - config := &shared.ModulrConfig{} + config := &payments.ModulrConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{ModulrConfig: config}, - Connector: shared.ConnectorModulr, + ConnectorConfig: payments.ConnectorConfig{ModulrConfig: config}, + Connector: payments.ConnectorModulr, ConnectorID: connectorID, }) if err != nil { @@ -269,13 +269,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.MoneycorpConnector: - config := &shared.MoneycorpConfig{} + config := &payments.MoneycorpConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{MoneycorpConfig: config}, - Connector: shared.ConnectorMoneycorp, + ConnectorConfig: payments.ConnectorConfig{MoneycorpConfig: config}, + Connector: payments.ConnectorMoneycorp, ConnectorID: connectorID, }) if err != nil { @@ -286,13 +286,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.StripeConnector: - config := &shared.StripeConfig{} + config := &payments.StripeConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{StripeConfig: config}, - Connector: shared.ConnectorStripe, + ConnectorConfig: payments.ConnectorConfig{StripeConfig: config}, + Connector: payments.ConnectorStripe, ConnectorID: connectorID, }) if err != nil { @@ -303,13 +303,13 @@ func (c *ConnectorUpdateConfigController) runV1Typed( } case internal.WiseConnector: - config := &shared.WiseConfig{} + config := &payments.WiseConfig{} if err := json.Unmarshal([]byte(script), config); err != nil { return nil, err } resp, err := sc.Payments.V1.UpdateConnectorConfigV1(cmd.Context(), operations.UpdateConnectorConfigV1Request{ - ConnectorConfig: shared.ConnectorConfig{WiseConfig: config}, - Connector: shared.ConnectorWise, + ConnectorConfig: payments.ConnectorConfig{WiseConfig: config}, + Connector: payments.ConnectorWise, ConnectorID: connectorID, }) if err != nil { diff --git a/cmd/payments/connectors/install/install.go b/cmd/payments/connectors/install/install.go index bd159d0b..c089dd3b 100644 --- a/cmd/payments/connectors/install/install.go +++ b/cmd/payments/connectors/install/install.go @@ -11,8 +11,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/connectors/internal" "github.com/formancehq/fctl/v3/cmd/payments/versions" @@ -160,13 +160,13 @@ func (c *ConnectorInstallController) runV1Typed( name := strings.ToLower(connectorName) switch name { case internal.AdyenConnector: - var config shared.AdyenConfig + var config payments.AdyenConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{AdyenConfig: &config}, - Connector: shared.ConnectorAdyen, + ConnectorConfig: payments.ConnectorConfig{AdyenConfig: &config}, + Connector: payments.ConnectorAdyen, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -181,13 +181,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.AtlarConnector: - var config shared.AtlarConfig + var config payments.AtlarConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{AtlarConfig: &config}, - Connector: shared.ConnectorAtlar, + ConnectorConfig: payments.ConnectorConfig{AtlarConfig: &config}, + Connector: payments.ConnectorAtlar, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -202,13 +202,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.BankingCircleConnector: - var config shared.BankingCircleConfig + var config payments.BankingCircleConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{BankingCircleConfig: &config}, - Connector: shared.ConnectorBankingCircle, + ConnectorConfig: payments.ConnectorConfig{BankingCircleConfig: &config}, + Connector: payments.ConnectorBankingCircle, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -223,13 +223,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.CurrencyCloudConnector: - var config shared.CurrencyCloudConfig + var config payments.CurrencyCloudConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{CurrencyCloudConfig: &config}, - Connector: shared.ConnectorCurrencyCloud, + ConnectorConfig: payments.ConnectorConfig{CurrencyCloudConfig: &config}, + Connector: payments.ConnectorCurrencyCloud, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -244,13 +244,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.MangoPayConnector: - var config shared.MangoPayConfig + var config payments.MangoPayConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{MangoPayConfig: &config}, - Connector: shared.ConnectorMangopay, + ConnectorConfig: payments.ConnectorConfig{MangoPayConfig: &config}, + Connector: payments.ConnectorMangopay, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -265,13 +265,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.ModulrConnector: - var config shared.ModulrConfig + var config payments.ModulrConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{ModulrConfig: &config}, - Connector: shared.ConnectorModulr, + ConnectorConfig: payments.ConnectorConfig{ModulrConfig: &config}, + Connector: payments.ConnectorModulr, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -286,13 +286,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.MoneycorpConnector: - var config shared.MoneycorpConfig + var config payments.MoneycorpConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{MoneycorpConfig: &config}, - Connector: shared.ConnectorMoneycorp, + ConnectorConfig: payments.ConnectorConfig{MoneycorpConfig: &config}, + Connector: payments.ConnectorMoneycorp, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -307,13 +307,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.StripeConnector: - var config shared.StripeConfig + var config payments.StripeConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{StripeConfig: &config}, - Connector: shared.ConnectorStripe, + ConnectorConfig: payments.ConnectorConfig{StripeConfig: &config}, + Connector: payments.ConnectorStripe, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -328,13 +328,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.WiseConnector: - var config shared.WiseConfig + var config payments.WiseConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{WiseConfig: &config}, - Connector: shared.ConnectorWise, + ConnectorConfig: payments.ConnectorConfig{WiseConfig: &config}, + Connector: payments.ConnectorWise, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) @@ -349,13 +349,13 @@ func (c *ConnectorInstallController) runV1Typed( } case internal.GenericConnector: - var config shared.GenericConfig + var config payments.GenericConfig if err := json.Unmarshal([]byte(script), &config); err != nil { return nil, err } resp, err := stackClient.Payments.V1.InstallConnector(cmd.Context(), operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{GenericConfig: &config}, - Connector: shared.ConnectorGeneric, + ConnectorConfig: payments.ConnectorConfig{GenericConfig: &config}, + Connector: payments.ConnectorGeneric, }) if err != nil { return nil, fmt.Errorf("installing connector: %w", err) diff --git a/cmd/payments/connectors/list.go b/cmd/payments/connectors/list.go index 1b695fc7..5de24c3a 100644 --- a/cmd/payments/connectors/list.go +++ b/cmd/payments/connectors/list.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -156,7 +156,7 @@ func (c *PaymentsConnectorsListController) Render(cmd *cobra.Command, args []str Render() } -func V3toConnectorData(connector shared.V3Connector) ConnectorData { +func V3toConnectorData(connector payments.V3Connector) ConnectorData { return ConnectorData{ ID: connector.ID, Name: connector.Name, @@ -164,10 +164,10 @@ func V3toConnectorData(connector shared.V3Connector) ConnectorData { } } -func V1toConnectorData(connector shared.ConnectorsResponseData) ConnectorData { +func V1toConnectorData(connector payments.ConnectorsResponseData) ConnectorData { return ConnectorData{ ID: connector.ConnectorID, Name: connector.Name, - Provider: string(connector.Provider), + Provider: string(connector.Connector), } } diff --git a/cmd/payments/connectors/uninstall.go b/cmd/payments/connectors/uninstall.go index cd947be2..cdd683e6 100644 --- a/cmd/payments/connectors/uninstall.go +++ b/cmd/payments/connectors/uninstall.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/connectors/internal" "github.com/formancehq/fctl/v3/cmd/payments/versions" @@ -130,7 +130,7 @@ func (c *PaymentsConnectorsUninstallController) Run(cmd *cobra.Command, args []s response, err := stackClient.Payments.V1.UninstallConnectorV1(cmd.Context(), operations.UninstallConnectorV1Request{ ConnectorID: connectorID, - Connector: shared.Connector(provider), + Connector: payments.Connector(provider), }) if err != nil { return nil, err @@ -151,7 +151,7 @@ func (c *PaymentsConnectorsUninstallController) Run(cmd *cobra.Command, args []s } response, err := stackClient.Payments.V1.UninstallConnector(cmd.Context(), operations.UninstallConnectorRequest{ - Connector: shared.Connector(provider), + Connector: payments.Connector(provider), }) if err != nil { return nil, err diff --git a/cmd/payments/connectors/views/adyen.go b/cmd/payments/connectors/views/adyen.go index 76dbe4c0..2fff7c26 100644 --- a/cmd/payments/connectors/views/adyen.go +++ b/cmd/payments/connectors/views/adyen.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayAdyenConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.AdyenConfig +func DisplayAdyenConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.AdyenConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -28,8 +28,8 @@ func DisplayAdyenConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCon return nil } -func DisplayAdyenConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3AdyenConfig +func DisplayAdyenConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3AdyenConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/atlar.go b/cmd/payments/connectors/views/atlar.go index 8e4857dd..426e8291 100644 --- a/cmd/payments/connectors/views/atlar.go +++ b/cmd/payments/connectors/views/atlar.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayAtlarConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.AtlarConfig +func DisplayAtlarConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.AtlarConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -29,8 +29,8 @@ func DisplayAtlarConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCon return nil } -func DisplayAtlarConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3AtlarConfig +func DisplayAtlarConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3AtlarConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/banking_circle.go b/cmd/payments/connectors/views/banking_circle.go index b82612dc..488041d7 100644 --- a/cmd/payments/connectors/views/banking_circle.go +++ b/cmd/payments/connectors/views/banking_circle.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayBankingCircleConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.BankingCircleConfig +func DisplayBankingCircleConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.BankingCircleConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -30,8 +30,8 @@ func DisplayBankingCircleConfig(cmd *cobra.Command, connectorConfig *shared.Conn return nil } -func DisplayBankingCircleConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3BankingcircleConfig +func DisplayBankingCircleConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3BankingcircleConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/coinbaseprime.go b/cmd/payments/connectors/views/coinbaseprime.go index 1a46a29e..f4a8b190 100644 --- a/cmd/payments/connectors/views/coinbaseprime.go +++ b/cmd/payments/connectors/views/coinbaseprime.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayCoinbaseprimeConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3CoinbaseprimeConfig +func DisplayCoinbaseprimeConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3CoinbaseprimeConfig if config == nil { return nil } diff --git a/cmd/payments/connectors/views/column.go b/cmd/payments/connectors/views/column.go index 577ddc21..916dd3ec 100644 --- a/cmd/payments/connectors/views/column.go +++ b/cmd/payments/connectors/views/column.go @@ -4,15 +4,15 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) // Column is a connector implemented in v3, so not compatible with the v1 call. -func DisplayColumnConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3ColumnConfig +func DisplayColumnConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3ColumnConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/currency_cloud.go b/cmd/payments/connectors/views/currency_cloud.go index 619ac2fa..55abfcfd 100644 --- a/cmd/payments/connectors/views/currency_cloud.go +++ b/cmd/payments/connectors/views/currency_cloud.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayCurrencyCloudConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.CurrencyCloudConfig +func DisplayCurrencyCloudConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.CurrencyCloudConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -33,8 +33,8 @@ func DisplayCurrencyCloudConfig(cmd *cobra.Command, connectorConfig *shared.Conn return nil } -func DisplayCurrencyCloudConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3CurrencycloudConfig +func DisplayCurrencyCloudConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3CurrencycloudConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/fireblocks.go b/cmd/payments/connectors/views/fireblocks.go index 18f32975..7ac0dd33 100644 --- a/cmd/payments/connectors/views/fireblocks.go +++ b/cmd/payments/connectors/views/fireblocks.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayFireblocksConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3FireblocksConfig +func DisplayFireblocksConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3FireblocksConfig if config == nil { return nil } diff --git a/cmd/payments/connectors/views/increase.go b/cmd/payments/connectors/views/increase.go index 4765cc72..ac4ea0d2 100644 --- a/cmd/payments/connectors/views/increase.go +++ b/cmd/payments/connectors/views/increase.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayIncreaseConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3IncreaseConfig +func DisplayIncreaseConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3IncreaseConfig if config == nil { return nil } diff --git a/cmd/payments/connectors/views/mangopay.go b/cmd/payments/connectors/views/mangopay.go index 20065f5a..06cba49c 100644 --- a/cmd/payments/connectors/views/mangopay.go +++ b/cmd/payments/connectors/views/mangopay.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayMangopayConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.MangoPayConfig +func DisplayMangopayConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.MangoPayConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -33,8 +33,8 @@ func DisplayMangopayConfig(cmd *cobra.Command, connectorConfig *shared.Connector return nil } -func DisplayMangopayConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3MangopayConfig +func DisplayMangopayConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3MangopayConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/modulr.go b/cmd/payments/connectors/views/modulr.go index 466c6a9c..c7007597 100644 --- a/cmd/payments/connectors/views/modulr.go +++ b/cmd/payments/connectors/views/modulr.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayModulrConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.ModulrConfig +func DisplayModulrConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.ModulrConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -38,8 +38,8 @@ func DisplayModulrConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCo return nil } -func DisplayModulrConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3ModulrConfig +func DisplayModulrConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3ModulrConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/moneycorp.go b/cmd/payments/connectors/views/moneycorp.go index 6d3e694b..17b9b04a 100644 --- a/cmd/payments/connectors/views/moneycorp.go +++ b/cmd/payments/connectors/views/moneycorp.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayMoneycorpConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.MoneycorpConfig +func DisplayMoneycorpConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.MoneycorpConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -33,8 +33,8 @@ func DisplayMoneycorpConfig(cmd *cobra.Command, connectorConfig *shared.Connecto return nil } -func DisplayMoneycorpConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3MoneycorpConfig +func DisplayMoneycorpConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3MoneycorpConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/plaid.go b/cmd/payments/connectors/views/plaid.go index 9174f0ff..cfa66eef 100644 --- a/cmd/payments/connectors/views/plaid.go +++ b/cmd/payments/connectors/views/plaid.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayPlaidConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3PlaidConfig +func DisplayPlaidConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3PlaidConfig if config == nil { return nil } diff --git a/cmd/payments/connectors/views/powens.go b/cmd/payments/connectors/views/powens.go index 9cb8ebf0..4d04ea72 100644 --- a/cmd/payments/connectors/views/powens.go +++ b/cmd/payments/connectors/views/powens.go @@ -6,13 +6,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayPowensConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3PowensConfig +func DisplayPowensConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3PowensConfig if config == nil { return nil } diff --git a/cmd/payments/connectors/views/qonto.go b/cmd/payments/connectors/views/qonto.go index 6bc754f6..4f86a85e 100644 --- a/cmd/payments/connectors/views/qonto.go +++ b/cmd/payments/connectors/views/qonto.go @@ -4,15 +4,15 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) // Qonto is a connector implemented in v3, so not compatible with the v1 call. -func DisplayQontoConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3QontoConfig +func DisplayQontoConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3QontoConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/stripe.go b/cmd/payments/connectors/views/stripe.go index 46b1551f..e85e658e 100644 --- a/cmd/payments/connectors/views/stripe.go +++ b/cmd/payments/connectors/views/stripe.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayStripeConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.StripeConfig +func DisplayStripeConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.StripeConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -31,8 +31,8 @@ func DisplayStripeConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorCo return nil } -func DisplayStripeConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3StripeConfig +func DisplayStripeConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3StripeConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/connectors/views/tink.go b/cmd/payments/connectors/views/tink.go index e12a9dbc..e91b4564 100644 --- a/cmd/payments/connectors/views/tink.go +++ b/cmd/payments/connectors/views/tink.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayTinkConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3TinkConfig +func DisplayTinkConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3TinkConfig if config == nil { return nil } diff --git a/cmd/payments/connectors/views/wise.go b/cmd/payments/connectors/views/wise.go index dc60a4d0..15742602 100644 --- a/cmd/payments/connectors/views/wise.go +++ b/cmd/payments/connectors/views/wise.go @@ -4,13 +4,13 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) -func DisplayWiseConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConfigResponse) error { - config := connectorConfig.Data.WiseConfig +func DisplayWiseConfig(cmd *cobra.Command, connectorConfig *payments.ConnectorConfigResponse) error { + config := connectorConfig.ConnectorConfig.WiseConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) @@ -31,8 +31,8 @@ func DisplayWiseConfig(cmd *cobra.Command, connectorConfig *shared.ConnectorConf return nil } -func DisplayWiseConfigV3(cmd *cobra.Command, v3Config *shared.V3GetConnectorConfigResponse) error { - config := v3Config.Data.V3WiseConfig +func DisplayWiseConfigV3(cmd *cobra.Command, v3Config *payments.V3GetConnectorConfigResponse) error { + config := v3Config.V3ConnectorConfig.V3WiseConfig tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name:"), config.Name}) diff --git a/cmd/payments/payments/create.go b/cmd/payments/payments/create.go index 14e9a088..ac4fc992 100644 --- a/cmd/payments/payments/create.go +++ b/cmd/payments/payments/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + paymentsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -81,7 +81,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, err } - request := shared.PaymentRequest{} + request := paymentsmodels.PaymentRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -96,7 +96,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.PaymentID = response.PaymentResponse.Data.ID + c.store.PaymentID = response.PaymentResponse.Payment.ID return c, nil } diff --git a/cmd/payments/payments/list.go b/cmd/payments/payments/list.go index 0b1d38a3..01d2c4c3 100644 --- a/cmd/payments/payments/list.go +++ b/cmd/payments/payments/list.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + paymentsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Cursor *shared.PaymentsCursorCursor `json:"cursor"` + Cursor *paymentsmodels.PaymentsCursorCursorBase `json:"cursor"` } type ListController struct { store *ListStore @@ -27,7 +27,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewListStore() *ListStore { return &ListStore{ - Cursor: &shared.PaymentsCursorCursor{}, + Cursor: &paymentsmodels.PaymentsCursorCursorBase{}, } } @@ -81,21 +81,21 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Cursor = &response.PaymentsCursor.Cursor + c.store.Cursor = &response.PaymentsCursor.CursorBase return c, nil } func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(payment shared.Payment) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(payment paymentsmodels.Payment) []string { return []string{ payment.ID, - string(payment.Type), + string(payment.PaymentType), fmt.Sprint(payment.Amount), fmt.Sprint(payment.InitialAmount), payment.Asset, - string(payment.Status), - string(payment.Scheme), + string(payment.PaymentStatus), + string(payment.PaymentScheme), payment.Reference, payment.SourceAccountID, payment.DestinationAccountID, diff --git a/cmd/payments/payments/set_metadata.go b/cmd/payments/payments/set_metadata.go index 2e924745..fea8c3e9 100644 --- a/cmd/payments/payments/set_metadata.go +++ b/cmd/payments/payments/set_metadata.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/payments/payments/show.go b/cmd/payments/payments/show.go index 1c219542..20ff0ba8 100644 --- a/cmd/payments/payments/show.go +++ b/cmd/payments/payments/show.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + paymentsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Payment *shared.Payment `json:"payment"` + Payment *paymentsmodels.Payment `json:"payment"` } type ShowController struct { store *ShowStore @@ -69,7 +69,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Payment = &response.PaymentResponse.Data + c.store.Payment = &response.PaymentResponse.Payment return c, nil } @@ -84,16 +84,16 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { tableData = append(tableData, []string{pterm.LightCyan("Asset"), c.store.Payment.Asset}) tableData = append(tableData, []string{pterm.LightCyan("Amount"), c.store.Payment.Amount.String()}) tableData = append(tableData, []string{pterm.LightCyan("InitialAmount"), c.store.Payment.InitialAmount.String()}) - tableData = append(tableData, []string{pterm.LightCyan("Type"), string(c.store.Payment.Type)}) - tableData = append(tableData, []string{pterm.LightCyan("Scheme"), string(c.store.Payment.Scheme)}) - tableData = append(tableData, []string{pterm.LightCyan("Status"), string(c.store.Payment.Status)}) + tableData = append(tableData, []string{pterm.LightCyan("Type"), string(c.store.Payment.PaymentType)}) + tableData = append(tableData, []string{pterm.LightCyan("Scheme"), string(c.store.Payment.PaymentScheme)}) + tableData = append(tableData, []string{pterm.LightCyan("Status"), string(c.store.Payment.PaymentStatus)}) tableData = append(tableData, []string{pterm.LightCyan("DestinationAccountID"), c.store.Payment.DestinationAccountID}) tableData = append(tableData, []string{pterm.LightCyan("SourceAccountID"), c.store.Payment.SourceAccountID}) tableData = append(tableData, []string{pterm.LightCyan("Provider"), func() string { - if c.store.Payment.Provider == nil { + if c.store.Payment.Connector == nil { return "" } - return string(*c.store.Payment.Provider) + return string(*c.store.Payment.Connector) }()}) if err := pterm.DefaultTable. @@ -103,10 +103,10 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { return err } - tableData = fctl.Map(c.store.Payment.Adjustments, func(pa shared.PaymentAdjustment) []string { + tableData = fctl.Map(c.store.Payment.Adjustments, func(pa paymentsmodels.PaymentAdjustment) []string { return []string{ pa.Reference, - string(pa.Status), + string(pa.PaymentStatus), pa.CreatedAt.Format(time.RFC3339), pa.Amount.String(), } @@ -121,5 +121,5 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { return err } - return fctl.PrintMetadata(cmd.OutOrStdout(), c.store.Payment.Metadata) + return fctl.PrintMetadata(cmd.OutOrStdout(), c.store.Payment.PaymentMetadata) } diff --git a/cmd/payments/pools/add_accounts.go b/cmd/payments/pools/add_accounts.go index 9b6b2910..4bb47413 100644 --- a/cmd/payments/pools/add_accounts.go +++ b/cmd/payments/pools/add_accounts.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -77,7 +77,7 @@ func (c *AddAccountController) Run(cmd *cobra.Command, args []string) (fctl.Rend response, err := stackClient.Payments.V1.AddAccountToPool(cmd.Context(), operations.AddAccountToPoolRequest{ PoolID: args[0], - AddAccountToPoolRequest: shared.AddAccountToPoolRequest{ + AddAccountToPoolRequest: payments.AddAccountToPoolRequest{ AccountID: args[1], }, }) diff --git a/cmd/payments/pools/balances.go b/cmd/payments/pools/balances.go index a96090e1..14915ab9 100644 --- a/cmd/payments/pools/balances.go +++ b/cmd/payments/pools/balances.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" fctl "github.com/formancehq/fctl/v3/pkg" ) type BalancesStore struct { - Balances *shared.PoolBalances `json:"balances"` + Balances *payments.PoolBalances `json:"balances"` } type BalancesController struct { @@ -25,7 +25,7 @@ var _ fctl.Controller[*BalancesStore] = (*BalancesController)(nil) func NewBalancesStore() *BalancesStore { return &BalancesStore{ - Balances: &shared.PoolBalances{}, + Balances: &payments.PoolBalances{}, } } @@ -71,13 +71,13 @@ func (c *BalancesController) Run(cmd *cobra.Command, args []string) (fctl.Render return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Balances = &response.PoolBalancesResponse.Data + c.store.Balances = &response.PoolBalancesResponse.PoolBalances return c, nil } func (c *BalancesController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Balances.Balances, func(balance shared.PoolBalance) []string { + tableData := fctl.Map(c.store.Balances.Balances, func(balance payments.PoolBalance) []string { return []string{ balance.Asset, balance.Amount.String(), diff --git a/cmd/payments/pools/create.go b/cmd/payments/pools/create.go index a04cc042..bbe37de4 100644 --- a/cmd/payments/pools/create.go +++ b/cmd/payments/pools/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -85,7 +85,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab switch c.PaymentsVersion.Major { case versions.V3: - request := shared.V3CreatePoolRequest{} + request := payments.V3CreatePoolRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -105,7 +105,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab c.store.PoolID = response.V3CreatePoolResponse.Data default: - request := shared.PoolRequest{} + request := payments.PoolRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -119,7 +119,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.PoolID = response.PoolResponse.Data.ID + c.store.PoolID = response.PoolResponse.Pool.ID } return c, nil diff --git a/cmd/payments/pools/delete.go b/cmd/payments/pools/delete.go index 4fdeb3d3..a06045ad 100644 --- a/cmd/payments/pools/delete.go +++ b/cmd/payments/pools/delete.go @@ -6,7 +6,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/payments/pools/latest_balances.go b/cmd/payments/pools/latest_balances.go index 4de0223c..7abe0fb6 100644 --- a/cmd/payments/pools/latest_balances.go +++ b/cmd/payments/pools/latest_balances.go @@ -7,16 +7,16 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - formance "github.com/formancehq/formance-sdk-go/v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + formance "github.com/formancehq/formance-sdk-go/v4" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type LatestBalancesStore struct { - Balances *shared.PoolBalances `json:"balances"` + Balances *payments.PoolBalances `json:"balances"` } type LatestBalancesController struct { @@ -33,7 +33,7 @@ var _ fctl.Controller[*LatestBalancesStore] = (*LatestBalancesController)(nil) func NewLatestBalancesStore() *LatestBalancesStore { return &LatestBalancesStore{ - Balances: &shared.PoolBalances{}, + Balances: &payments.PoolBalances{}, } } @@ -86,7 +86,7 @@ func (c *LatestBalancesController) CallV1(context context.Context, client *forma if response.StatusCode >= 300 { return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Balances = &shared.PoolBalances{Balances: response.PoolBalancesLatestResponse.Data} + c.store.Balances = &payments.PoolBalances{Balances: response.PoolBalancesLatestResponse.PoolBalancesLatest} return c, nil } @@ -103,22 +103,22 @@ func (c *LatestBalancesController) CallV3(context context.Context, client *forma return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - v3Balances := &response.V3PoolBalancesResponse.Data + v3Balances := &response.V3PoolBalancesResponse.V3PoolBalances - poolBalances := make([]shared.PoolBalance, 0, len(*v3Balances)) + poolBalances := make([]payments.PoolBalance, 0, len(*v3Balances)) for _, v3Balance := range *v3Balances { - poolBalance := shared.PoolBalance{ + poolBalance := payments.PoolBalance{ Asset: v3Balance.Asset, Amount: v3Balance.Amount, } poolBalances = append(poolBalances, poolBalance) } - c.store.Balances = &shared.PoolBalances{Balances: poolBalances} + c.store.Balances = &payments.PoolBalances{Balances: poolBalances} return c, nil } func (c *LatestBalancesController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Balances.Balances, func(balance shared.PoolBalance) []string { + tableData := fctl.Map(c.store.Balances.Balances, func(balance payments.PoolBalance) []string { return []string{ balance.Asset, balance.Amount.String(), diff --git a/cmd/payments/pools/list.go b/cmd/payments/pools/list.go index 5d191820..8a150242 100644 --- a/cmd/payments/pools/list.go +++ b/cmd/payments/pools/list.go @@ -7,15 +7,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Cursor *shared.PoolsCursorCursor `json:"cursor"` + Cursor *payments.PoolsCursorCursorBase `json:"cursor"` } type ListController struct { @@ -35,7 +35,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewListStore() *ListStore { return &ListStore{ - Cursor: &shared.PoolsCursorCursor{}, + Cursor: &payments.PoolsCursorCursorBase{}, } } @@ -97,13 +97,13 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Cursor = &response.PoolsCursor.Cursor + c.store.Cursor = &response.PoolsCursor.CursorBase return c, nil } func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(bc shared.Pool) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(bc payments.Pool) []string { return []string{ bc.ID, bc.Name, diff --git a/cmd/payments/pools/remove_account.go b/cmd/payments/pools/remove_account.go index 7edca67a..d233ac51 100644 --- a/cmd/payments/pools/remove_account.go +++ b/cmd/payments/pools/remove_account.go @@ -6,7 +6,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/payments/pools/show.go b/cmd/payments/pools/show.go index 8bb57a5a..3d596731 100644 --- a/cmd/payments/pools/show.go +++ b/cmd/payments/pools/show.go @@ -7,15 +7,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Pool *shared.Pool `json:"pool"` + Pool *payments.Pool `json:"pool"` } type ShowController struct { PaymentsVersion versions.Version @@ -85,7 +85,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Pool = &response.PoolResponse.Data + c.store.Pool = &response.PoolResponse.Pool return c, nil } diff --git a/cmd/payments/pools/update_query.go b/cmd/payments/pools/update_query.go index 1dc22d4d..93b5d5a7 100644 --- a/cmd/payments/pools/update_query.go +++ b/cmd/payments/pools/update_query.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -84,7 +84,7 @@ func (c *UpdateQueryController) Run(cmd *cobra.Command, args []string) (fctl.Ren return nil, err } - var request shared.V3UpdatePoolQueryRequest + var request payments.V3UpdatePoolQueryRequest if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } diff --git a/cmd/payments/root.go b/cmd/payments/root.go index 470ad521..775b5ced 100644 --- a/cmd/payments/root.go +++ b/cmd/payments/root.go @@ -6,7 +6,7 @@ import ( "github.com/formancehq/fctl/v3/cmd/payments/accounts" "github.com/formancehq/fctl/v3/cmd/payments/bankaccounts" "github.com/formancehq/fctl/v3/cmd/payments/connectors" - "github.com/formancehq/fctl/v3/cmd/payments/payments" + paymentsmodels "github.com/formancehq/fctl/v3/cmd/payments/payments" "github.com/formancehq/fctl/v3/cmd/payments/pools" "github.com/formancehq/fctl/v3/cmd/payments/tasks" "github.com/formancehq/fctl/v3/cmd/payments/transferinitiation" @@ -18,7 +18,7 @@ func NewCommand() *cobra.Command { fctl.WithShortDescription("Manage payments"), fctl.WithChildCommands( connectors.NewConnectorsCommand(), - payments.NewPaymentsCommand(), + paymentsmodels.NewPaymentsCommand(), transferinitiation.NewTransferInitiationCommand(), bankaccounts.NewBankAccountsCommand(), accounts.NewAccountsCommand(), diff --git a/cmd/payments/tasks/show.go b/cmd/payments/tasks/show.go index f0b6ae71..30b5f55e 100644 --- a/cmd/payments/tasks/show.go +++ b/cmd/payments/tasks/show.go @@ -6,15 +6,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Task *shared.V3Task `json:"task"` + Task *payments.V3Task `json:"task"` } type ShowController struct { PaymentsVersion versions.Version @@ -84,7 +84,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Task = &response.V3GetTaskResponse.Data + c.store.Task = &response.V3GetTaskResponse.V3Task return c, nil } @@ -113,7 +113,7 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { tableData = append(tableData, []string{pterm.LightCyan("CreatedObjectID"), createdObjectID}) tableData = append(tableData, []string{pterm.LightCyan("CreatedAt"), c.store.Task.CreatedAt.String()}) tableData = append(tableData, []string{pterm.LightCyan("Error"), errStr}) - tableData = append(tableData, []string{pterm.LightCyan("Status"), string(c.store.Task.Status)}) + tableData = append(tableData, []string{pterm.LightCyan("Status"), string(c.store.Task.V3TaskStatusEnum)}) tableData = append(tableData, []string{pterm.LightCyan("UpdatedAt"), c.store.Task.UpdatedAt.String()}) if err := pterm.DefaultTable. diff --git a/cmd/payments/transferinitiation/approve.go b/cmd/payments/transferinitiation/approve.go index 2c46c120..7d5dafc0 100644 --- a/cmd/payments/transferinitiation/approve.go +++ b/cmd/payments/transferinitiation/approve.go @@ -6,7 +6,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/payments/transferinitiation/create.go b/cmd/payments/transferinitiation/create.go index d30abd1c..34b9c313 100644 --- a/cmd/payments/transferinitiation/create.go +++ b/cmd/payments/transferinitiation/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -81,7 +81,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, err } - request := shared.TransferInitiationRequest{} + request := payments.TransferInitiationRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -96,7 +96,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.TransferInitiationId = response.TransferInitiationResponse.Data.ID + c.store.TransferInitiationId = response.TransferInitiationResponse.TransferInitiation.ID return c, nil } diff --git a/cmd/payments/transferinitiation/delete.go b/cmd/payments/transferinitiation/delete.go index 5eb9077c..4e2d9850 100644 --- a/cmd/payments/transferinitiation/delete.go +++ b/cmd/payments/transferinitiation/delete.go @@ -6,7 +6,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/payments/transferinitiation/list.go b/cmd/payments/transferinitiation/list.go index c82eafb2..499055c0 100644 --- a/cmd/payments/transferinitiation/list.go +++ b/cmd/payments/transferinitiation/list.go @@ -7,15 +7,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Cursor *shared.TransferInitiationsCursorCursor `json:"cursor"` + Cursor *payments.TransferInitiationsCursorCursorBase `json:"cursor"` } type ListController struct { @@ -35,7 +35,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewListStore() *ListStore { return &ListStore{ - Cursor: &shared.TransferInitiationsCursorCursor{}, + Cursor: &payments.TransferInitiationsCursorCursorBase{}, } } @@ -96,13 +96,13 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.Cursor = &response.TransferInitiationsCursor.Cursor + c.store.Cursor = &response.TransferInitiationsCursor.CursorBase return c, nil } func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(tf shared.TransferInitiation) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(tf payments.TransferInitiation) []string { return []string{ tf.ID, tf.Reference, @@ -116,7 +116,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error { fmt.Sprint(tf.Amount), fmt.Sprint(tf.InitialAmount), tf.Asset, - string(tf.Status), + string(tf.TransferInitiationStatus), *tf.Error, } }) diff --git a/cmd/payments/transferinitiation/reject.go b/cmd/payments/transferinitiation/reject.go index 3facc4da..047254ce 100644 --- a/cmd/payments/transferinitiation/reject.go +++ b/cmd/payments/transferinitiation/reject.go @@ -6,7 +6,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/payments/transferinitiation/retry.go b/cmd/payments/transferinitiation/retry.go index 44e08b3e..546e05a0 100644 --- a/cmd/payments/transferinitiation/retry.go +++ b/cmd/payments/transferinitiation/retry.go @@ -6,7 +6,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/v4/pkg/models/operations" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" diff --git a/cmd/payments/transferinitiation/reverse.go b/cmd/payments/transferinitiation/reverse.go index 8e2fceb1..1a5163e9 100644 --- a/cmd/payments/transferinitiation/reverse.go +++ b/cmd/payments/transferinitiation/reverse.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -80,7 +80,7 @@ func (c *ReverseController) Run(cmd *cobra.Command, args []string) (fctl.Rendera return nil, err } - request := shared.ReverseTransferInitiationRequest{} + request := payments.ReverseTransferInitiationRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } diff --git a/cmd/payments/transferinitiation/show.go b/cmd/payments/transferinitiation/show.go index be064500..84b4b428 100644 --- a/cmd/payments/transferinitiation/show.go +++ b/cmd/payments/transferinitiation/show.go @@ -7,15 +7,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - TransferInitiation *shared.TransferInitiation `json:"transferInitiation"` + TransferInitiation *payments.TransferInitiation `json:"transferInitiation"` } type ShowController struct { PaymentsVersion versions.Version @@ -84,7 +84,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.TransferInitiation = &response.TransferInitiationResponse.Data + c.store.TransferInitiation = &response.TransferInitiationResponse.TransferInitiation return c, nil } @@ -104,7 +104,7 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { tableData = append(tableData, []string{pterm.LightCyan("Amount"), fmt.Sprint(c.store.TransferInitiation.Amount)}) tableData = append(tableData, []string{pterm.LightCyan("InitialAmount"), fmt.Sprint(c.store.TransferInitiation.InitialAmount)}) tableData = append(tableData, []string{pterm.LightCyan("Asset"), c.store.TransferInitiation.Asset}) - tableData = append(tableData, []string{pterm.LightCyan("Status"), string(c.store.TransferInitiation.Status)}) + tableData = append(tableData, []string{pterm.LightCyan("Status"), string(c.store.TransferInitiation.TransferInitiationStatus)}) tableData = append(tableData, []string{pterm.LightCyan("Error"), *c.store.TransferInitiation.Error}) if err := pterm.DefaultTable. @@ -114,11 +114,11 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { return err } - tableData = fctl.Map(c.store.TransferInitiation.RelatedPayments, func(tf shared.TransferInitiationPayments) []string { + tableData = fctl.Map(c.store.TransferInitiation.RelatedPayments, func(tf payments.TransferInitiationPayments) []string { return []string{ tf.PaymentID, tf.CreatedAt.Format(time.RFC3339), - string(tf.Status), + string(tf.LegacyPaymentStatus), *tf.Error, } }) @@ -131,11 +131,11 @@ func (c *ShowController) Render(cmd *cobra.Command, args []string) error { return err } - tableData = fctl.Map(c.store.TransferInitiation.RelatedAdjustments, func(tf shared.TransferInitiationAdjustments) []string { + tableData = fctl.Map(c.store.TransferInitiation.RelatedAdjustments, func(tf payments.TransferInitiationAdjustments) []string { return []string{ tf.AdjustmentID, tf.CreatedAt.Format(time.RFC3339), - string(tf.Status), + string(tf.TransferInitiationStatus), *tf.Error, } }) diff --git a/cmd/payments/transferinitiation/update_status.go b/cmd/payments/transferinitiation/update_status.go index a96fcdbb..9d3c3d85 100644 --- a/cmd/payments/transferinitiation/update_status.go +++ b/cmd/payments/transferinitiation/update_status.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/payments" "github.com/formancehq/fctl/v3/cmd/payments/versions" fctl "github.com/formancehq/fctl/v3/pkg" @@ -82,8 +82,8 @@ func (c *UpdateStatusController) Run(cmd *cobra.Command, args []string) (fctl.Re //nolint:gosimple response, err := stackClient.Payments.V1.UpdateTransferInitiationStatus(cmd.Context(), operations.UpdateTransferInitiationStatusRequest{ - UpdateTransferInitiationStatusRequest: shared.UpdateTransferInitiationStatusRequest{ - Status: shared.Status(args[1]), + UpdateTransferInitiationStatusRequest: payments.UpdateTransferInitiationStatusRequest{ + Status: payments.Status(args[1]), }, TransferID: args[0], }) diff --git a/cmd/payments/versions/versions.go b/cmd/payments/versions/versions.go index ede07b33..d50f0524 100644 --- a/cmd/payments/versions/versions.go +++ b/cmd/payments/versions/versions.go @@ -42,7 +42,7 @@ func GetPaymentsVersion(cmd *cobra.Command, _ []string, controller VersionContro if err != nil { return err } - response, err := stackClient.Payments.V1.PaymentsgetServerInfo(cmd.Context()) + response, err := stackClient.Payments.V1.GetServerInfoPayments(cmd.Context()) if err != nil { return err } @@ -51,7 +51,7 @@ func GetPaymentsVersion(cmd *cobra.Command, _ []string, controller VersionContro return fmt.Errorf("unexpected status code: %d", response.StatusCode) } - version := "v" + strings.TrimPrefix(*response.PaymentsServerInfo.Version, "v") + version := "v" + strings.TrimPrefix(*response.ServerInfo.Version, "v") paymentVersion, err := computePaymentVersion(version) if err != nil { diff --git a/cmd/reconciliation/list.go b/cmd/reconciliation/list.go index af06cd64..b69ac42b 100644 --- a/cmd/reconciliation/list.go +++ b/cmd/reconciliation/list.go @@ -7,14 +7,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + reconciliationmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/reconciliation" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Cursor *shared.ReconciliationsCursorResponseCursor `json:"cursor"` + Cursor *reconciliationmodels.ReconciliationsCursorResponseCursor `json:"cursor"` } type ListController struct { @@ -28,7 +28,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewListStore() *ListStore { return &ListStore{ - Cursor: &shared.ReconciliationsCursorResponseCursor{}, + Cursor: &reconciliationmodels.ReconciliationsCursorResponseCursor{}, } } @@ -88,7 +88,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable } func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(p shared.Reconciliation) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(p reconciliationmodels.Reconciliation) []string { return []string{ p.ID, p.PolicyID, diff --git a/cmd/reconciliation/policies/create.go b/cmd/reconciliation/policies/create.go index ab9cfcda..74ec9820 100644 --- a/cmd/reconciliation/policies/create.go +++ b/cmd/reconciliation/policies/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/reconciliation" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -67,7 +67,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, err } - request := shared.PolicyRequest{} + request := reconciliation.PolicyRequest{} if err := json.Unmarshal([]byte(script), &request); err != nil { return nil, err } @@ -82,7 +82,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.PolicyID = response.PolicyResponse.Data.ID + c.store.PolicyID = response.PolicyResponse.Policy.ID return c, nil } diff --git a/cmd/reconciliation/policies/delete.go b/cmd/reconciliation/policies/delete.go index d2e5e368..f636db72 100644 --- a/cmd/reconciliation/policies/delete.go +++ b/cmd/reconciliation/policies/delete.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/reconciliation/policies/list.go b/cmd/reconciliation/policies/list.go index aac90dd5..1f9536d6 100644 --- a/cmd/reconciliation/policies/list.go +++ b/cmd/reconciliation/policies/list.go @@ -8,14 +8,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/reconciliation" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Cursor *shared.PoliciesCursorResponseCursor `json:"cursor"` + Cursor *reconciliation.Cursor `json:"cursor"` } type ListController struct { @@ -29,7 +29,7 @@ var _ fctl.Controller[*ListStore] = (*ListController)(nil) func NewListStore() *ListStore { return &ListStore{ - Cursor: &shared.PoliciesCursorResponseCursor{}, + Cursor: &reconciliation.Cursor{}, } } @@ -89,7 +89,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable } func (c *ListController) Render(cmd *cobra.Command, args []string) error { - tableData := fctl.Map(c.store.Cursor.Data, func(p shared.Policy) []string { + tableData := fctl.Map(c.store.Cursor.Data, func(p reconciliation.Policy) []string { return []string{ p.ID, p.Name, diff --git a/cmd/reconciliation/policies/reconciliation.go b/cmd/reconciliation/policies/reconciliation.go index 5023666a..d0c69ce6 100644 --- a/cmd/reconciliation/policies/reconciliation.go +++ b/cmd/reconciliation/policies/reconciliation.go @@ -8,14 +8,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/reconciliation" fctl "github.com/formancehq/fctl/v3/pkg" ) type ReconciliationStore struct { - Reconciliation shared.Reconciliation `json:"reconciliation"` + Reconciliation reconciliation.Reconciliation `json:"reconciliation"` } type ReconciliationController struct { store *ReconciliationStore @@ -71,7 +71,7 @@ func (c *ReconciliationController) Run(cmd *cobra.Command, args []string) (fctl. response, err := stackClient.Reconciliation.V1.Reconcile(cmd.Context(), operations.ReconcileRequest{ PolicyID: args[0], - ReconciliationRequest: shared.ReconciliationRequest{ + ReconciliationRequest: reconciliation.ReconciliationRequest{ ReconciledAtLedger: atLedger, ReconciledAtPayments: atPayments, }, @@ -88,7 +88,7 @@ func (c *ReconciliationController) Run(cmd *cobra.Command, args []string) (fctl. return nil, fmt.Errorf("policy not found") } - c.store.Reconciliation = response.ReconciliationResponse.Data + c.store.Reconciliation = response.ReconciliationResponse.Reconciliation return c, nil } diff --git a/cmd/reconciliation/policies/show.go b/cmd/reconciliation/policies/show.go index 9a4c6daf..cc3b88d7 100644 --- a/cmd/reconciliation/policies/show.go +++ b/cmd/reconciliation/policies/show.go @@ -8,14 +8,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/reconciliation" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Policy shared.Policy `json:"policy"` + Policy reconciliation.Policy `json:"policy"` } type ShowController struct { store *ShowStore @@ -74,7 +74,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("policy not found") } - c.store.Policy = response.PolicyResponse.Data + c.store.Policy = response.PolicyResponse.Policy return c, nil } diff --git a/cmd/reconciliation/show.go b/cmd/reconciliation/show.go index 54932e99..1f444df7 100644 --- a/cmd/reconciliation/show.go +++ b/cmd/reconciliation/show.go @@ -8,14 +8,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + reconciliationmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/reconciliation" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Reconciliation shared.Reconciliation `json:"policy"` + Reconciliation reconciliationmodels.Reconciliation `json:"policy"` } type ShowController struct { store *ShowStore @@ -74,7 +74,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("policy not found") } - c.store.Reconciliation = response.ReconciliationResponse.Data + c.store.Reconciliation = response.ReconciliationResponse.Reconciliation return c, nil } diff --git a/cmd/root.go b/cmd/root.go index 8ab935eb..48d89984 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,7 +13,7 @@ import ( "github.com/spf13/cobra" "github.com/formancehq/fctl/internal/membershipclient/v3/models/apierrors" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/sdkerrors" + ledgermodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/ledger" "github.com/formancehq/go-libs/v4/api" "github.com/formancehq/go-libs/v4/logging" @@ -25,7 +25,6 @@ import ( "github.com/formancehq/fctl/v3/cmd/payments" "github.com/formancehq/fctl/v3/cmd/profiles" "github.com/formancehq/fctl/v3/cmd/reconciliation" - "github.com/formancehq/fctl/v3/cmd/search" "github.com/formancehq/fctl/v3/cmd/stack" "github.com/formancehq/fctl/v3/cmd/ui" "github.com/formancehq/fctl/v3/cmd/version" @@ -59,7 +58,6 @@ func NewRootCommand() *cobra.Command { stack.NewCommand(), auth.NewCommand(), cloud.NewCommand(), - search.NewCommand(), webhooks.NewCommand(), wallets.NewCommand(), orchestration.NewCommand(), @@ -114,10 +112,10 @@ func Execute() { for unwrapped != nil { //notes(gfyrag): not a clean assertion but following errors does not implements standard Is() helper for errors switch err := unwrapped.(type) { - case *sdkerrors.ErrorResponse: + case *ledgermodels.ErrorResponseError: printErrorResponse(err) return - case *sdkerrors.V2ErrorResponse: + case *ledgermodels.V2ErrorResponseError: printV2ErrorResponse(err) return case *apierrors.APIError: @@ -156,10 +154,10 @@ func printError(code string, message string, details *string) { os.Exit(2) } -func printV2ErrorResponse(target *sdkerrors.V2ErrorResponse) { - printError(string(target.ErrorCode), target.ErrorMessage, target.Details) +func printV2ErrorResponse(target *ledgermodels.V2ErrorResponseError) { + printError(string(target.V2ErrorsEnum), target.ErrorMessage, target.Details) } -func printErrorResponse(target *sdkerrors.ErrorResponse) { - printError(string(target.ErrorCode), target.ErrorMessage, target.Details) +func printErrorResponse(target *ledgermodels.ErrorResponseError) { + printError(string(target.ErrorsEnum), target.ErrorMessage, target.Details) } diff --git a/cmd/search/root.go b/cmd/search/root.go deleted file mode 100644 index 73d8b0ab..00000000 --- a/cmd/search/root.go +++ /dev/null @@ -1,185 +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/v3/cmd/search/views" - fctl "github.com/formancehq/fctl/v3/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) { - - _, profile, profileName, relyingParty, err := fctl.LoadAndAuthenticateCurrentProfile(cmd) - if err != nil { - return nil, err - } - - stackClient, err := fctl.NewStackClientFromFlags(cmd, relyingParty, fctl.NewPTermDialog(), profileName, *profile) - if err != nil { - return nil, err - } - - 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 := stackClient.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()), - ) -} diff --git a/cmd/search/views/accounts.go b/cmd/search/views/accounts.go deleted file mode 100644 index 38506b07..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/v3/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 42fca0c0..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/v3/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 f2d59163..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/v3/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 c93e2618..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/v3/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() -} diff --git a/cmd/stack/create.go b/cmd/stack/create.go index 71dc3ffd..73bf7bd3 100644 --- a/cmd/stack/create.go +++ b/cmd/stack/create.go @@ -10,7 +10,7 @@ import ( "github.com/formancehq/fctl/internal/membershipclient/v3/models/components" "github.com/formancehq/fctl/internal/membershipclient/v3/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/gateway" "github.com/formancehq/go-libs/v4/pointer" "github.com/formancehq/fctl/v3/cmd/stack/internal" @@ -25,7 +25,7 @@ const ( type CreateStore struct { Stack *components.Stack - Versions *shared.GetVersionsResponse + Versions *gateway.GetVersionsResponse } type CreateController struct { @@ -37,7 +37,7 @@ var _ fctl.Controller[*CreateStore] = (*CreateController)(nil) func NewDefaultStackCreateStore() *CreateStore { return &CreateStore{ Stack: &components.Stack{}, - Versions: &shared.GetVersionsResponse{}, + Versions: &gateway.GetVersionsResponse{}, } } func NewStackCreateController() *CreateController { diff --git a/cmd/stack/internal/print.go b/cmd/stack/internal/print.go index 49c8d54f..bf23308a 100644 --- a/cmd/stack/internal/print.go +++ b/cmd/stack/internal/print.go @@ -8,12 +8,12 @@ import ( "github.com/pterm/pterm" "github.com/formancehq/fctl/internal/membershipclient/v3/models/components" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/gateway" fctl "github.com/formancehq/fctl/v3/pkg" ) -func PrintStackInformation(out io.Writer, stack *components.Stack, versions *shared.GetVersionsResponse) error { +func PrintStackInformation(out io.Writer, stack *components.Stack, versions *gateway.GetVersionsResponse) error { err := printInformation(out, stack) if err != nil { @@ -56,7 +56,7 @@ func printInformation(out io.Writer, stack *components.Stack) error { Render() } -func printVersion(out io.Writer, url string, versions *shared.GetVersionsResponse) error { +func printVersion(out io.Writer, url string, versions *gateway.GetVersionsResponse) error { fctl.Println() fctl.Section.WithWriter(out).Println("Versions") diff --git a/cmd/stack/restore.go b/cmd/stack/restore.go index e68ee58e..b6662281 100644 --- a/cmd/stack/restore.go +++ b/cmd/stack/restore.go @@ -10,15 +10,15 @@ import ( "github.com/formancehq/fctl/internal/membershipclient/v3/models/components" "github.com/formancehq/fctl/internal/membershipclient/v3/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/gateway" "github.com/formancehq/fctl/v3/cmd/stack/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type StackRestoreStore struct { - Stack *components.Stack `json:"stack"` - Versions *shared.GetVersionsResponse `json:"versions"` + Stack *components.Stack `json:"stack"` + Versions *gateway.GetVersionsResponse `json:"versions"` } type StackRestoreController struct { store *StackRestoreStore @@ -30,7 +30,7 @@ var _ fctl.Controller[*StackRestoreStore] = (*StackRestoreController)(nil) func NewDefaultVersionStore() *StackRestoreStore { return &StackRestoreStore{ Stack: &components.Stack{}, - Versions: &shared.GetVersionsResponse{}, + Versions: &gateway.GetVersionsResponse{}, } } diff --git a/cmd/stack/show.go b/cmd/stack/show.go index 262f9d4f..d3daa29c 100644 --- a/cmd/stack/show.go +++ b/cmd/stack/show.go @@ -9,7 +9,7 @@ import ( "github.com/formancehq/fctl/internal/membershipclient/v3/models/components" "github.com/formancehq/fctl/internal/membershipclient/v3/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/gateway" "github.com/formancehq/fctl/v3/cmd/stack/internal" fctl "github.com/formancehq/fctl/v3/pkg" @@ -18,8 +18,8 @@ import ( var errStackNotFound = errors.New("stack not found") type StackShowStore struct { - Stack *components.Stack `json:"stack"` - Versions *shared.GetVersionsResponse `json:"versions"` + Stack *components.Stack `json:"stack"` + Versions *gateway.GetVersionsResponse `json:"versions"` } type StackShowController struct { diff --git a/cmd/wallets/balances/create.go b/cmd/wallets/balances/create.go index 424aa51f..dbdb92be 100644 --- a/cmd/wallets/balances/create.go +++ b/cmd/wallets/balances/create.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" fctl "github.com/formancehq/fctl/v3/pkg" @@ -86,7 +86,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab request := operations.CreateBalanceRequest{ ID: walletID, - CreateBalanceRequest: &shared.CreateBalanceRequest{ + Balance: &wallets.Balance{ Name: args[0], ExpiresAt: expiresAt, Priority: priority, @@ -97,7 +97,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("creating balance: %w", err) } - c.store.BalanceName = response.CreateBalanceResponse.Data.Name + c.store.BalanceName = response.CreateBalanceResponse.Balance.Name return c, nil } diff --git a/cmd/wallets/balances/list.go b/cmd/wallets/balances/list.go index a53301ce..f6b5fdf4 100644 --- a/cmd/wallets/balances/list.go +++ b/cmd/wallets/balances/list.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" fctl "github.com/formancehq/fctl/v3/pkg" @@ -77,7 +77,7 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode) } - c.store.BalancesNames = fctl.Map(response.ListBalancesResponse.Cursor.Data, func(balance shared.Balance) []string { + c.store.BalancesNames = fctl.Map(response.ListBalancesResponse.Cursor.Data, func(balance wallets.Balance) []string { return []string{ balance.Name, } diff --git a/cmd/wallets/balances/show.go b/cmd/wallets/balances/show.go index 5a3ee214..5adc3444 100644 --- a/cmd/wallets/balances/show.go +++ b/cmd/wallets/balances/show.go @@ -5,8 +5,8 @@ import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" "github.com/formancehq/fctl/v3/cmd/wallets/internal/views" @@ -14,7 +14,7 @@ import ( ) type ShowStore struct { - Balance shared.BalanceWithAssets `json:"balance"` + Balance wallets.AssetHolder1 `json:"balance"` } type ShowController struct { store *ShowStore @@ -74,7 +74,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("getting balance: %w", err) } - c.store.Balance = response.GetBalanceResponse.Data + c.store.Balance = response.GetBalanceResponse.AssetHolder return c, nil } diff --git a/cmd/wallets/create.go b/cmd/wallets/create.go index 958cdeef..7f920794 100644 --- a/cmd/wallets/create.go +++ b/cmd/wallets/create.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + walletsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -75,7 +75,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab } request := operations.CreateWalletRequest{ - CreateWalletRequest: &shared.CreateWalletRequest{ + CreateWalletRequest: &walletsmodels.CreateWalletRequest{ Name: args[0], Metadata: metadata, }, @@ -86,7 +86,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab return nil, fmt.Errorf("creating wallet: %w", err) } - c.store.WalletID = response.CreateWalletResponse.Data.ID + c.store.WalletID = response.CreateWalletResponse.Wallet.ID return c, nil } diff --git a/cmd/wallets/credit.go b/cmd/wallets/credit.go index 1f9039a8..b2db8436 100644 --- a/cmd/wallets/credit.go +++ b/cmd/wallets/credit.go @@ -8,9 +8,9 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - formance "github.com/formancehq/formance-sdk-go/v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + formance "github.com/formancehq/formance-sdk-go/v4" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + walletsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" fctl "github.com/formancehq/fctl/v3/pkg" @@ -100,7 +100,7 @@ func (c *CreditWalletController) Run(cmd *cobra.Command, args []string) (fctl.Re return nil, err } - sources := make([]shared.Subject, 0) + sources := make([]walletsmodels.Subject, 0) for _, sourceStr := range fctl.GetStringSlice(cmd, c.sourceFlag) { source, err := internal.ParseSubject(sourceStr, cmd, stackClient) if err != nil { @@ -112,8 +112,8 @@ func (c *CreditWalletController) Run(cmd *cobra.Command, args []string) (fctl.Re request := operations.CreditWalletRequest{ IdempotencyKey: fctl.Ptr(fctl.GetString(cmd, c.ikFlag)), ID: walletID, - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ + CreditWalletRequest: &walletsmodels.CreditWalletRequest{ + Monetary: walletsmodels.Monetary{ Asset: asset, Amount: amount, }, diff --git a/cmd/wallets/debit.go b/cmd/wallets/debit.go index 69349911..7091ef5f 100644 --- a/cmd/wallets/debit.go +++ b/cmd/wallets/debit.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + walletsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" fctl "github.com/formancehq/fctl/v3/pkg" @@ -111,7 +111,7 @@ func (c *DebitWalletController) Run(cmd *cobra.Command, args []string) (fctl.Ren return nil, fmt.Errorf("unable to parse '%s' as big int", amountStr) } - var destination *shared.Subject + var destination *walletsmodels.Subject if destinationStr := fctl.GetString(cmd, c.destinationFlag); destinationStr != "" { destination, err = internal.ParseSubject(destinationStr, cmd, stackClient) if err != nil { @@ -120,15 +120,15 @@ func (c *DebitWalletController) Run(cmd *cobra.Command, args []string) (fctl.Ren } response, err := stackClient.Wallets.V1.DebitWallet(cmd.Context(), operations.DebitWalletRequest{ - DebitWalletRequest: &shared.DebitWalletRequest{ - Amount: shared.Monetary{ + DebitWalletRequest: &walletsmodels.DebitWalletRequest{ + Monetary: walletsmodels.Monetary{ Asset: asset, Amount: amount, }, Pending: &pending, Metadata: metadata, Description: &description, - Destination: destination, + Subject: destination, Balances: fctl.GetStringSlice(cmd, c.balanceFlag), }, ID: walletID, @@ -138,7 +138,7 @@ func (c *DebitWalletController) Run(cmd *cobra.Command, args []string) (fctl.Ren } if response.DebitWalletResponse != nil { - c.store.HoldID = &response.DebitWalletResponse.Data.ID + c.store.HoldID = &response.DebitWalletResponse.Hold.ID } c.store.Success = true diff --git a/cmd/wallets/holds/confirm.go b/cmd/wallets/holds/confirm.go index a14618d5..0b077f0f 100644 --- a/cmd/wallets/holds/confirm.go +++ b/cmd/wallets/holds/confirm.go @@ -7,8 +7,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -74,7 +74,7 @@ func (c *ConfirmController) Run(cmd *cobra.Command, args []string) (fctl.Rendera request := operations.ConfirmHoldRequest{ HoldID: args[0], - ConfirmHoldRequest: &shared.ConfirmHoldRequest{ + ConfirmHoldRequest: &wallets.ConfirmHoldRequest{ Amount: big.NewInt(amount), Final: &final, }, diff --git a/cmd/wallets/holds/list.go b/cmd/wallets/holds/list.go index 81628da0..3bfdbb9c 100644 --- a/cmd/wallets/holds/list.go +++ b/cmd/wallets/holds/list.go @@ -6,15 +6,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Holds []shared.Hold `json:"holds"` + Holds []wallets.Hold `json:"holds"` } type ListController struct { store *ListStore @@ -100,7 +100,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error { WithData( fctl.Prepend( fctl.Map(c.store.Holds, - func(src shared.Hold) []string { + func(src wallets.Hold) []string { return []string{ src.ID, src.WalletID, diff --git a/cmd/wallets/holds/show.go b/cmd/wallets/holds/show.go index 7d1d66e1..0d13e1c6 100644 --- a/cmd/wallets/holds/show.go +++ b/cmd/wallets/holds/show.go @@ -5,15 +5,15 @@ import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal/views" fctl "github.com/formancehq/fctl/v3/pkg" ) type ShowStore struct { - Hold shared.ExpandedDebitHold `json:"hold"` + Hold wallets.Hold1 `json:"hold"` } type ShowController struct { store *ShowStore @@ -65,7 +65,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("getting hold: %w", err) } - c.store.Hold = response.GetHoldResponse.Data + c.store.Hold = response.GetHoldResponse.Hold return c, nil } diff --git a/cmd/wallets/holds/void.go b/cmd/wallets/holds/void.go index 472436a2..99b065d0 100644 --- a/cmd/wallets/holds/void.go +++ b/cmd/wallets/holds/void.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/wallets/internal/command.go b/cmd/wallets/internal/command.go index 2d33ee7c..1fe7df3c 100644 --- a/cmd/wallets/internal/command.go +++ b/cmd/wallets/internal/command.go @@ -6,8 +6,8 @@ import ( "github.com/spf13/cobra" - formance "github.com/formancehq/formance-sdk-go/v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" + formance "github.com/formancehq/formance-sdk-go/v4" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/wallets/internal/subject.go b/cmd/wallets/internal/subject.go index 4892b6e2..42c0d9fe 100644 --- a/cmd/wallets/internal/subject.go +++ b/cmd/wallets/internal/subject.go @@ -6,11 +6,11 @@ import ( "github.com/spf13/cobra" - formance "github.com/formancehq/formance-sdk-go/v3" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + formance "github.com/formancehq/formance-sdk-go/v4" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" ) -func ParseSubject(subject string, cmd *cobra.Command, client *formance.Formance) (*shared.Subject, error) { +func ParseSubject(subject string, cmd *cobra.Command, client *formance.Formance) (*wallets.Subject, error) { var err error switch { case strings.HasPrefix(subject, "wallet="): @@ -33,13 +33,13 @@ func ParseSubject(subject string, cmd *cobra.Command, client *formance.Formance) default: return nil, errors.New("malformed wallet source definition") } - subject := shared.CreateSubjectWallet(shared.WalletSubject{ + subject := wallets.CreateSubjectWalletSubject(wallets.WalletSubject{ Identifier: walletID, Balance: &balance, }) return &subject, nil case strings.HasPrefix(subject, "account="): - subject := shared.CreateSubjectAccount(shared.LedgerAccountSubject{ + subject := wallets.CreateSubjectLedgerAccountSubject(wallets.LedgerAccountSubject{ Identifier: strings.TrimPrefix(subject, "account="), }) return &subject, nil diff --git a/cmd/wallets/internal/views/balance.go b/cmd/wallets/internal/views/balance.go index af8f59b3..3c43f32b 100644 --- a/cmd/wallets/internal/views/balance.go +++ b/cmd/wallets/internal/views/balance.go @@ -6,12 +6,12 @@ import ( "github.com/pterm/pterm" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" fctl "github.com/formancehq/fctl/v3/pkg" ) -func PrintBalance(out io.Writer, balance shared.BalanceWithAssets) error { +func PrintBalance(out io.Writer, balance wallets.AssetHolder1) error { fctl.Section.Println("Information") tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("Name"), balance.Name}) diff --git a/cmd/wallets/internal/views/hold.go b/cmd/wallets/internal/views/hold.go index c04cbda5..b3a2cb1f 100644 --- a/cmd/wallets/internal/views/hold.go +++ b/cmd/wallets/internal/views/hold.go @@ -6,12 +6,12 @@ import ( "github.com/pterm/pterm" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" fctl "github.com/formancehq/fctl/v3/pkg" ) -func PrintHold(out io.Writer, hold shared.ExpandedDebitHold) error { +func PrintHold(out io.Writer, hold wallets.Hold1) error { fctl.Section.Println("Information") tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("ID"), fmt.Sprint(hold.ID)}) diff --git a/cmd/wallets/internal/views/wallet.go b/cmd/wallets/internal/views/wallet.go index 33ef063b..c80bee04 100644 --- a/cmd/wallets/internal/views/wallet.go +++ b/cmd/wallets/internal/views/wallet.go @@ -6,12 +6,12 @@ import ( "github.com/pterm/pterm" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" fctl "github.com/formancehq/fctl/v3/pkg" ) -func PrintWallet(out io.Writer, wallet shared.WalletWithBalances) error { +func PrintWallet(out io.Writer, wallet wallets.WalletWithBalances) error { fctl.Section.Println("Information") tableData := pterm.TableData{} tableData = append(tableData, []string{pterm.LightCyan("ID"), fmt.Sprint(wallet.ID)}) @@ -25,13 +25,13 @@ func PrintWallet(out io.Writer, wallet shared.WalletWithBalances) error { } fctl.Section.Println("Balances") - if len(wallet.Balances.Main.Assets) == 0 { + if len(wallet.Balances.AssetHolder.Assets) == 0 { fctl.Println("No balances found.") return nil } tableData = pterm.TableData{} tableData = append(tableData, []string{"Asset", "Amount"}) - for asset, amount := range wallet.Balances.Main.Assets { + for asset, amount := range wallet.Balances.AssetHolder.Assets { tableData = append(tableData, []string{asset, fmt.Sprint(amount)}) } if err := pterm.DefaultTable. @@ -44,7 +44,7 @@ func PrintWallet(out io.Writer, wallet shared.WalletWithBalances) error { return nil } -func PrintWalletWithMetadata(out io.Writer, wallet shared.WalletWithBalances) error { +func PrintWalletWithMetadata(out io.Writer, wallet wallets.WalletWithBalances) error { err := PrintWallet(out, wallet) if err != nil { return err diff --git a/cmd/wallets/list.go b/cmd/wallets/list.go index 3cd5fde9..dedb4e43 100644 --- a/cmd/wallets/list.go +++ b/cmd/wallets/list.go @@ -6,14 +6,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + walletsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Wallets []shared.Wallet `json:"wallets"` + Wallets []walletsmodels.Wallet `json:"wallets"` } type ListController struct { store *ListStore @@ -94,7 +94,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error { WithData( fctl.Prepend( fctl.Map(c.store.Wallets, - func(src shared.Wallet) []string { + func(src walletsmodels.Wallet) []string { return []string{ src.ID, src.Name, diff --git a/cmd/wallets/show.go b/cmd/wallets/show.go index 06f6849d..52aaccfe 100644 --- a/cmd/wallets/show.go +++ b/cmd/wallets/show.go @@ -6,8 +6,8 @@ import ( "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + walletsmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" "github.com/formancehq/fctl/v3/cmd/wallets/internal/views" @@ -15,7 +15,7 @@ import ( ) type ShowStore struct { - Wallet shared.WalletWithBalances `json:"wallet"` + Wallet walletsmodels.WalletWithBalances `json:"wallet"` } type ShowController struct { store *ShowStore @@ -78,7 +78,7 @@ func (c *ShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable return nil, fmt.Errorf("getting wallet: %w", err) } - c.store.Wallet = response.GetWalletResponse.Data + c.store.Wallet = response.GetWalletResponse.WalletWithBalances return c, nil } diff --git a/cmd/wallets/transactions/list.go b/cmd/wallets/transactions/list.go index a9b869da..ae0bb9c4 100644 --- a/cmd/wallets/transactions/list.go +++ b/cmd/wallets/transactions/list.go @@ -7,15 +7,15 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/wallets" "github.com/formancehq/fctl/v3/cmd/wallets/internal" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListStore struct { - Transactions []shared.WalletsTransaction `json:"transactions"` + Transactions []wallets.Transaction `json:"transactions"` } type ListController struct { store *ListStore @@ -85,7 +85,7 @@ func (c *ListController) Render(cmd *cobra.Command, args []string) error { return nil } - tableData := fctl.Map(c.store.Transactions, func(tx shared.WalletsTransaction) []string { + tableData := fctl.Map(c.store.Transactions, func(tx wallets.Transaction) []string { return []string{ fmt.Sprintf("%d", tx.ID), tx.Timestamp.Format(time.RFC3339), diff --git a/cmd/wallets/update.go b/cmd/wallets/update.go index 22c2ea49..d4da41d4 100644 --- a/cmd/wallets/update.go +++ b/cmd/wallets/update.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/webhooks/activate.go b/cmd/webhooks/activate.go index edb9c1b7..5cedf46c 100644 --- a/cmd/webhooks/activate.go +++ b/cmd/webhooks/activate.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) diff --git a/cmd/webhooks/create.go b/cmd/webhooks/create.go index 07e4279f..2fb66a63 100644 --- a/cmd/webhooks/create.go +++ b/cmd/webhooks/create.go @@ -7,7 +7,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" + webhooksmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/webhooks" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -21,14 +21,14 @@ type CreateWebhookController struct { } type CreateWebhookStore struct { - Webhook shared.WebhooksConfig `json:"webhook"` + Webhook webhooksmodels.WebhooksConfig `json:"webhook"` } var _ fctl.Controller[*CreateWebhookStore] = (*CreateWebhookController)(nil) func NewDefaultCreateWebhookStore() *CreateWebhookStore { return &CreateWebhookStore{ - Webhook: shared.WebhooksConfig{}, + Webhook: webhooksmodels.WebhooksConfig{}, } } @@ -63,7 +63,7 @@ func (c *CreateWebhookController) Run(cmd *cobra.Command, args []string) (fctl.R secret := fctl.GetString(cmd, secretFlag) - response, err := stackClient.Webhooks.V1.InsertConfig(cmd.Context(), shared.ConfigUser{ + response, err := stackClient.Webhooks.V1.InsertConfig(cmd.Context(), webhooksmodels.ConfigUser{ Endpoint: args[0], EventTypes: args[1:], Secret: &secret, @@ -73,7 +73,7 @@ func (c *CreateWebhookController) Run(cmd *cobra.Command, args []string) (fctl.R return nil, fmt.Errorf("creating config: %w", err) } - c.store.Webhook = response.ConfigResponse.Data + c.store.Webhook = response.ConfigResponse.WebhooksConfig return c, nil } diff --git a/cmd/webhooks/deactivate.go b/cmd/webhooks/deactivate.go index a5973bb2..95048e29 100644 --- a/cmd/webhooks/deactivate.go +++ b/cmd/webhooks/deactivate.go @@ -6,7 +6,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/v4/pkg/models/operations" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -60,7 +60,7 @@ func (c *DesactivateWebhookController) Run(cmd *cobra.Command, args []string) (f return nil, fmt.Errorf("deactivating config: %w", err) } - c.store.Success = !response.ConfigResponse.Data.Active + c.store.Success = !response.ConfigResponse.WebhooksConfig.Active return c, nil } diff --git a/cmd/webhooks/delete.go b/cmd/webhooks/delete.go index ecb74e76..46c1c2ce 100644 --- a/cmd/webhooks/delete.go +++ b/cmd/webhooks/delete.go @@ -6,15 +6,15 @@ 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/sdkerrors" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + webhooksmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/webhooks" fctl "github.com/formancehq/fctl/v3/pkg" ) type DeleteWebhookStore struct { - ErrorResponse *sdkerrors.WebhooksErrorResponse `json:"error"` - Success bool `json:"success"` + ErrorResponse *webhooksmodels.ErrorResponse `json:"error"` + Success bool `json:"success"` } type DeleteWebhookController struct { diff --git a/cmd/webhooks/list.go b/cmd/webhooks/list.go index 2009d722..8c192d9a 100644 --- a/cmd/webhooks/list.go +++ b/cmd/webhooks/list.go @@ -8,14 +8,14 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + webhooksmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/webhooks" fctl "github.com/formancehq/fctl/v3/pkg" ) type ListWebhookStore struct { - Webhooks []shared.WebhooksConfig `json:"webhooks"` + Webhooks []webhooksmodels.WebhooksConfig `json:"webhooks"` } type ListWebhookController struct { store *ListWebhookStore @@ -25,7 +25,7 @@ var _ fctl.Controller[*ListWebhookStore] = (*ListWebhookController)(nil) func NewDefaultListWebhookStore() *ListWebhookStore { return &ListWebhookStore{ - Webhooks: []shared.WebhooksConfig{}, + Webhooks: []webhooksmodels.WebhooksConfig{}, } } @@ -68,7 +68,7 @@ func (c *ListWebhookController) Render(cmd *cobra.Command, args []string) error WithData( fctl.Prepend( fctl.Map(c.store.Webhooks, - func(src shared.WebhooksConfig) []string { + func(src webhooksmodels.WebhooksConfig) []string { return []string{ src.ID, src.CreatedAt.Format(time.RFC3339), diff --git a/cmd/webhooks/secret.go b/cmd/webhooks/secret.go index 27609ca5..713ef94a 100644 --- a/cmd/webhooks/secret.go +++ b/cmd/webhooks/secret.go @@ -6,8 +6,8 @@ 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" + "github.com/formancehq/formance-sdk-go/v4/pkg/models/operations" + webhooksmodels "github.com/formancehq/formance-sdk-go/v4/pkg/models/webhooks" fctl "github.com/formancehq/fctl/v3/pkg" ) @@ -59,7 +59,7 @@ func (c *ChangeSecretWebhookController) Run(cmd *cobra.Command, args []string) ( response, err := stackClient.Webhooks.V1. ChangeConfigSecret(cmd.Context(), operations.ChangeConfigSecretRequest{ - ConfigChangeSecret: &shared.ConfigChangeSecret{ + ConfigChangeSecret: &webhooksmodels.ConfigChangeSecret{ Secret: secret, }, ID: args[0], @@ -68,8 +68,8 @@ func (c *ChangeSecretWebhookController) Run(cmd *cobra.Command, args []string) ( return nil, fmt.Errorf("changing secret: %w", err) } - c.store.ID = response.ConfigResponse.Data.ID - c.store.Secret = response.ConfigResponse.Data.Secret + c.store.ID = response.ConfigResponse.WebhooksConfig.ID + c.store.Secret = response.ConfigResponse.WebhooksConfig.Secret return c, nil } diff --git a/go.mod b/go.mod index 21de6131..2b0f11bc 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/c-bata/go-prompt v0.2.6 github.com/formancehq/fctl/internal/deployserverclient/v3 v3.1.1 github.com/formancehq/fctl/internal/membershipclient/v3 v3.1.1 - github.com/formancehq/formance-sdk-go/v3 v3.8.1 + github.com/formancehq/formance-sdk-go/v4 v4.0.0 github.com/formancehq/go-libs/v4 v4.1.1 github.com/go-jose/go-jose/v4 v4.1.4 github.com/iancoleman/strcase v0.3.0 diff --git a/go.sum b/go.sum index 9ac2979f..74d003d2 100644 --- a/go.sum +++ b/go.sum @@ -101,8 +101,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/formancehq/cobra v1.10.3-0.20260226173701-7f22399f993b h1:8sPsvBsI0CJEzskLvdRMSBSdQKUlYTRGRdTiuL1HTfI= github.com/formancehq/cobra v1.10.3-0.20260226173701-7f22399f993b/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= -github.com/formancehq/formance-sdk-go/v3 v3.8.1 h1:nKWcpZT70vegEUV+/Xl/wekiI1PsCFVe7mvGgwaA9fk= -github.com/formancehq/formance-sdk-go/v3 v3.8.1/go.mod h1:2Kb2Z4bN8/I4MQQnuSilvThqeaUtuLaTdmMGIb3nMJY= +github.com/formancehq/formance-sdk-go/v4 v4.0.0 h1:VaDHdPdy2oLU80rhWsG7ll4M5fc5zFgr5KgZlZ7Zy74= +github.com/formancehq/formance-sdk-go/v4 v4.0.0/go.mod h1:dkPQPeS133IQcePjTkgfKJEeX3IAbBFYMEwcYBf/WYM= github.com/formancehq/go-libs/v4 v4.1.1 h1:D4LRPyssaq/2rPyNlmvAfypY5CsjLSQLLX2N4I/PsR4= github.com/formancehq/go-libs/v4 v4.1.1/go.mod h1:iVE2pTLa4KNhqXkCpBAGzpGO8TdHTEjdJMAiCkkeb0A= github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= diff --git a/pkg/clients.go b/pkg/clients.go index 58983cfd..ded49c47 100644 --- a/pkg/clients.go +++ b/pkg/clients.go @@ -16,7 +16,7 @@ import ( "github.com/formancehq/fctl/internal/deployserverclient/v3" "github.com/formancehq/fctl/internal/membershipclient/v3" "github.com/formancehq/fctl/internal/membershipclient/v3/models/components" - formance "github.com/formancehq/formance-sdk-go/v3" + formance "github.com/formancehq/formance-sdk-go/v4" "github.com/formancehq/go-libs/v4/collectionutils" "github.com/formancehq/go-libs/v4/oidc" "github.com/formancehq/go-libs/v4/oidc/client" @@ -451,23 +451,30 @@ func NewStackClient( return nil, err } + stackHTTPClient := oauth2.NewClient( + context.WithValue(cmd.Context(), oauth2.HTTPClient, relyingParty.HttpClient()), + NewStackTokenSource( + *stackToken, + stackAccess, + relyingParty, + func(newToken AccessToken) error { + return WriteStackToken(cmd, profileName, stackID, newToken) + }, + cmd, + profileName, + organizationID, + stackID, + ), + ) + stackHTTPTransport, err := newRewriteLocalhostServerURLRoundTripper(stackAccess.URI, stackHTTPClient.Transport) + if err != nil { + return nil, err + } + stackHTTPClient.Transport = stackHTTPTransport + return formance.New( formance.WithServerURL(stackAccess.URI), - formance.WithClient(oauth2.NewClient( - context.WithValue(cmd.Context(), oauth2.HTTPClient, relyingParty.HttpClient()), - NewStackTokenSource( - *stackToken, - stackAccess, - relyingParty, - func(newToken AccessToken) error { - return WriteStackToken(cmd, profileName, stackID, newToken) - }, - cmd, - profileName, - organizationID, - stackID, - ), - )), + formance.WithClient(stackHTTPClient), ), nil } @@ -536,9 +543,16 @@ func NewStackClientsFromFlags( baseCtx := context.WithValue(cmd.Context(), oauth2.HTTPClient, relyingParty.HttpClient()) + sdkHTTPClient := oauth2.NewClient(baseCtx, tokenSource) + sdkHTTPTransport, err := newRewriteLocalhostServerURLRoundTripper(stackAccess.URI, sdkHTTPClient.Transport) + if err != nil { + return nil, err + } + sdkHTTPClient.Transport = sdkHTTPTransport + sdkClient := formance.New( formance.WithServerURL(stackAccess.URI), - formance.WithClient(oauth2.NewClient(baseCtx, tokenSource)), + formance.WithClient(sdkHTTPClient), ) rawHTTPClient := oauth2.NewClient(baseCtx, tokenSource) diff --git a/pkg/http.go b/pkg/http.go index 88338789..d9cf576b 100644 --- a/pkg/http.go +++ b/pkg/http.go @@ -8,6 +8,8 @@ import ( "io" "net/http" "net/http/httputil" + "net/url" + "strings" "github.com/TylerBrock/colorjson" "github.com/spf13/cobra" @@ -151,3 +153,54 @@ func newInjectHTTPHeadersRoundTripper(headers http.Header, next http.RoundTrippe next: next, } } + +var _ http.RoundTripper = (*rewriteLocalhostServerURLRoundTripper)(nil) + +type rewriteLocalhostServerURLRoundTripper struct { + base *url.URL + next http.RoundTripper +} + +func (rt *rewriteLocalhostServerURLRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { + if req.URL.Scheme != "http" || req.URL.Host != "localhost:8080" { + return rt.next.RoundTrip(req) + } + + rewritten := req.Clone(req.Context()) + rewritten.URL = cloneURL(req.URL) + rewritten.URL.Scheme = rt.base.Scheme + rewritten.URL.Host = rt.base.Host + rewritten.URL.Path = joinURLPath(rt.base.Path, req.URL.Path) + rewritten.URL.RawPath = "" + rewritten.Host = rt.base.Host + + return rt.next.RoundTrip(rewritten) +} + +func newRewriteLocalhostServerURLRoundTripper(serverURL string, next http.RoundTripper) (http.RoundTripper, error) { + base, err := url.Parse(serverURL) + if err != nil { + return nil, err + } + return &rewriteLocalhostServerURLRoundTripper{ + base: base, + next: next, + }, nil +} + +func cloneURL(from *url.URL) *url.URL { + to := *from + return &to +} + +func joinURLPath(basePath, requestPath string) string { + basePath = strings.TrimRight(basePath, "/") + requestPath = strings.TrimLeft(requestPath, "/") + if basePath == "" { + return "/" + requestPath + } + if requestPath == "" { + return basePath + } + return basePath + "/" + requestPath +}