diff --git a/.stats.yml b/.stats.yml index c49780c..f79fb2f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-0b6874fdff2a5ed63c4e84830811f10a91e10e9c3e300a33f25422ad0afb945b.yml +configured_endpoints: 38 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-e915b33a18d4e6592966587ef174bbfe316edd9bc1fd7c17f86f372089bf80eb.yml diff --git a/api.md b/api.md index b31c293..6e372c9 100644 --- a/api.md +++ b/api.md @@ -331,3 +331,17 @@ Methods: - client.Payroll.PayGroups.Get(ctx context.Context, payGroupID string) (finchgo.PayrollPayGroupGetResponse, error) - client.Payroll.PayGroups.List(ctx context.Context, query finchgo.PayrollPayGroupListParams) (pagination.SinglePage[finchgo.PayrollPayGroupListResponse], error) + +# Connect + +## Sessions + +Response Types: + +- finchgo.ConnectSessionNewResponse +- finchgo.ConnectSessionReauthenticateResponse + +Methods: + +- client.Connect.Sessions.New(ctx context.Context, body finchgo.ConnectSessionNewParams) (finchgo.ConnectSessionNewResponse, error) +- client.Connect.Sessions.Reauthenticate(ctx context.Context, body finchgo.ConnectSessionReauthenticateParams) (finchgo.ConnectSessionReauthenticateResponse, error) diff --git a/client.go b/client.go index b7b1ed9..63a5e67 100644 --- a/client.go +++ b/client.go @@ -30,6 +30,7 @@ type Client struct { Jobs *JobService Sandbox *SandboxService Payroll *PayrollService + Connect *ConnectService } // NewClient generates a new client with the default option read from the @@ -67,6 +68,7 @@ func NewClient(opts ...option.RequestOption) (r *Client) { r.Jobs = NewJobService(opts...) r.Sandbox = NewSandboxService(opts...) r.Payroll = NewPayrollService(opts...) + r.Connect = NewConnectService(opts...) return } diff --git a/connect.go b/connect.go new file mode 100644 index 0000000..3c123f8 --- /dev/null +++ b/connect.go @@ -0,0 +1,28 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package finchgo + +import ( + "github.com/Finch-API/finch-api-go/option" +) + +// ConnectService contains methods and other services that help with interacting +// with the Finch API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewConnectService] method instead. +type ConnectService struct { + Options []option.RequestOption + Sessions *ConnectSessionService +} + +// NewConnectService generates a new service that applies the given options to each +// request. These options are applied after the parent client's options (if there +// is one), and before any request-specific options. +func NewConnectService(opts ...option.RequestOption) (r *ConnectService) { + r = &ConnectService{} + r.Options = opts + r.Sessions = NewConnectSessionService(opts...) + return +} diff --git a/connectsession.go b/connectsession.go new file mode 100644 index 0000000..e67a140 --- /dev/null +++ b/connectsession.go @@ -0,0 +1,217 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package finchgo + +import ( + "context" + "net/http" + + "github.com/Finch-API/finch-api-go/internal/apijson" + "github.com/Finch-API/finch-api-go/internal/param" + "github.com/Finch-API/finch-api-go/internal/requestconfig" + "github.com/Finch-API/finch-api-go/option" +) + +// ConnectSessionService contains methods and other services that help with +// interacting with the Finch API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewConnectSessionService] method instead. +type ConnectSessionService struct { + Options []option.RequestOption +} + +// NewConnectSessionService generates a new service that applies the given options +// to each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewConnectSessionService(opts ...option.RequestOption) (r *ConnectSessionService) { + r = &ConnectSessionService{} + r.Options = opts + return +} + +// Create a new connect session for an employer +func (r *ConnectSessionService) New(ctx context.Context, body ConnectSessionNewParams, opts ...option.RequestOption) (res *ConnectSessionNewResponse, err error) { + opts = append(r.Options[:], opts...) + path := "connect/sessions" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +// Create a new Connect session for reauthenticating an existing connection +func (r *ConnectSessionService) Reauthenticate(ctx context.Context, body ConnectSessionReauthenticateParams, opts ...option.RequestOption) (res *ConnectSessionReauthenticateResponse, err error) { + opts = append(r.Options[:], opts...) + path := "connect/sessions/reauthenticate" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +type ConnectSessionNewResponse struct { + // The Connect URL to redirect the user to for authentication + ConnectURL string `json:"connect_url,required" format:"uri"` + // The unique identifier for the created connect session + SessionID string `json:"session_id,required"` + JSON connectSessionNewResponseJSON `json:"-"` +} + +// connectSessionNewResponseJSON contains the JSON metadata for the struct +// [ConnectSessionNewResponse] +type connectSessionNewResponseJSON struct { + ConnectURL apijson.Field + SessionID apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConnectSessionNewResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r connectSessionNewResponseJSON) RawJSON() string { + return r.raw +} + +type ConnectSessionReauthenticateResponse struct { + // The Connect URL to redirect the user to for reauthentication + ConnectURL string `json:"connect_url,required" format:"uri"` + // The unique identifier for the created connect session + SessionID string `json:"session_id,required"` + JSON connectSessionReauthenticateResponseJSON `json:"-"` +} + +// connectSessionReauthenticateResponseJSON contains the JSON metadata for the +// struct [ConnectSessionReauthenticateResponse] +type connectSessionReauthenticateResponseJSON struct { + ConnectURL apijson.Field + SessionID apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConnectSessionReauthenticateResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r connectSessionReauthenticateResponseJSON) RawJSON() string { + return r.raw +} + +type ConnectSessionNewParams struct { + CustomerID param.Field[string] `json:"customer_id,required"` + CustomerName param.Field[string] `json:"customer_name,required"` + Products param.Field[[]ConnectSessionNewParamsProduct] `json:"products,required"` + CustomerEmail param.Field[string] `json:"customer_email" format:"email"` + Integration param.Field[ConnectSessionNewParamsIntegration] `json:"integration"` + Manual param.Field[bool] `json:"manual"` + // The number of minutes until the session expires (defaults to 10,080, which is 7 + // days) + MinutesToExpire param.Field[float64] `json:"minutes_to_expire"` + RedirectUri param.Field[string] `json:"redirect_uri"` + Sandbox param.Field[ConnectSessionNewParamsSandbox] `json:"sandbox"` +} + +func (r ConnectSessionNewParams) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// The Finch products that can be requested during the Connect flow. +type ConnectSessionNewParamsProduct string + +const ( + ConnectSessionNewParamsProductCompany ConnectSessionNewParamsProduct = "company" + ConnectSessionNewParamsProductDirectory ConnectSessionNewParamsProduct = "directory" + ConnectSessionNewParamsProductIndividual ConnectSessionNewParamsProduct = "individual" + ConnectSessionNewParamsProductEmployment ConnectSessionNewParamsProduct = "employment" + ConnectSessionNewParamsProductPayment ConnectSessionNewParamsProduct = "payment" + ConnectSessionNewParamsProductPayStatement ConnectSessionNewParamsProduct = "pay_statement" + ConnectSessionNewParamsProductBenefits ConnectSessionNewParamsProduct = "benefits" + ConnectSessionNewParamsProductSsn ConnectSessionNewParamsProduct = "ssn" +) + +func (r ConnectSessionNewParamsProduct) IsKnown() bool { + switch r { + case ConnectSessionNewParamsProductCompany, ConnectSessionNewParamsProductDirectory, ConnectSessionNewParamsProductIndividual, ConnectSessionNewParamsProductEmployment, ConnectSessionNewParamsProductPayment, ConnectSessionNewParamsProductPayStatement, ConnectSessionNewParamsProductBenefits, ConnectSessionNewParamsProductSsn: + return true + } + return false +} + +type ConnectSessionNewParamsIntegration struct { + AuthMethod param.Field[ConnectSessionNewParamsIntegrationAuthMethod] `json:"auth_method"` + Provider param.Field[string] `json:"provider"` +} + +func (r ConnectSessionNewParamsIntegration) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +type ConnectSessionNewParamsIntegrationAuthMethod string + +const ( + ConnectSessionNewParamsIntegrationAuthMethodAssisted ConnectSessionNewParamsIntegrationAuthMethod = "assisted" + ConnectSessionNewParamsIntegrationAuthMethodCredential ConnectSessionNewParamsIntegrationAuthMethod = "credential" + ConnectSessionNewParamsIntegrationAuthMethodOAuth ConnectSessionNewParamsIntegrationAuthMethod = "oauth" + ConnectSessionNewParamsIntegrationAuthMethodAPIToken ConnectSessionNewParamsIntegrationAuthMethod = "api_token" +) + +func (r ConnectSessionNewParamsIntegrationAuthMethod) IsKnown() bool { + switch r { + case ConnectSessionNewParamsIntegrationAuthMethodAssisted, ConnectSessionNewParamsIntegrationAuthMethodCredential, ConnectSessionNewParamsIntegrationAuthMethodOAuth, ConnectSessionNewParamsIntegrationAuthMethodAPIToken: + return true + } + return false +} + +type ConnectSessionNewParamsSandbox string + +const ( + ConnectSessionNewParamsSandboxFinch ConnectSessionNewParamsSandbox = "finch" + ConnectSessionNewParamsSandboxProvider ConnectSessionNewParamsSandbox = "provider" +) + +func (r ConnectSessionNewParamsSandbox) IsKnown() bool { + switch r { + case ConnectSessionNewParamsSandboxFinch, ConnectSessionNewParamsSandboxProvider: + return true + } + return false +} + +type ConnectSessionReauthenticateParams struct { + // The ID of the existing connection to reauthenticate + ConnectionID param.Field[string] `json:"connection_id,required"` + // The number of minutes until the session expires (defaults to 10,080, which is 7 + // days) + MinutesToExpire param.Field[int64] `json:"minutes_to_expire"` + // The products to request access to (optional for reauthentication) + Products param.Field[[]ConnectSessionReauthenticateParamsProduct] `json:"products"` + // The URI to redirect to after the Connect flow is completed + RedirectUri param.Field[string] `json:"redirect_uri" format:"uri"` +} + +func (r ConnectSessionReauthenticateParams) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// The Finch products that can be requested during the Connect flow. +type ConnectSessionReauthenticateParamsProduct string + +const ( + ConnectSessionReauthenticateParamsProductCompany ConnectSessionReauthenticateParamsProduct = "company" + ConnectSessionReauthenticateParamsProductDirectory ConnectSessionReauthenticateParamsProduct = "directory" + ConnectSessionReauthenticateParamsProductIndividual ConnectSessionReauthenticateParamsProduct = "individual" + ConnectSessionReauthenticateParamsProductEmployment ConnectSessionReauthenticateParamsProduct = "employment" + ConnectSessionReauthenticateParamsProductPayment ConnectSessionReauthenticateParamsProduct = "payment" + ConnectSessionReauthenticateParamsProductPayStatement ConnectSessionReauthenticateParamsProduct = "pay_statement" + ConnectSessionReauthenticateParamsProductBenefits ConnectSessionReauthenticateParamsProduct = "benefits" + ConnectSessionReauthenticateParamsProductSsn ConnectSessionReauthenticateParamsProduct = "ssn" +) + +func (r ConnectSessionReauthenticateParamsProduct) IsKnown() bool { + switch r { + case ConnectSessionReauthenticateParamsProductCompany, ConnectSessionReauthenticateParamsProductDirectory, ConnectSessionReauthenticateParamsProductIndividual, ConnectSessionReauthenticateParamsProductEmployment, ConnectSessionReauthenticateParamsProductPayment, ConnectSessionReauthenticateParamsProductPayStatement, ConnectSessionReauthenticateParamsProductBenefits, ConnectSessionReauthenticateParamsProductSsn: + return true + } + return false +} diff --git a/connectsession_test.go b/connectsession_test.go new file mode 100644 index 0000000..84b1730 --- /dev/null +++ b/connectsession_test.go @@ -0,0 +1,80 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package finchgo_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/Finch-API/finch-api-go" + "github.com/Finch-API/finch-api-go/internal/testutil" + "github.com/Finch-API/finch-api-go/option" +) + +func TestConnectSessionNewWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := finchgo.NewClient( + option.WithBaseURL(baseURL), + option.WithAccessToken("My Access Token"), + option.WithClientID("4ab15e51-11ad-49f4-acae-f343b7794375"), + option.WithClientSecret("My Client Secret"), + ) + _, err := client.Connect.Sessions.New(context.TODO(), finchgo.ConnectSessionNewParams{ + CustomerID: finchgo.F("x"), + CustomerName: finchgo.F("x"), + Products: finchgo.F([]finchgo.ConnectSessionNewParamsProduct{finchgo.ConnectSessionNewParamsProductCompany, finchgo.ConnectSessionNewParamsProductDirectory, finchgo.ConnectSessionNewParamsProductIndividual}), + CustomerEmail: finchgo.F("dev@stainlessapi.com"), + Integration: finchgo.F(finchgo.ConnectSessionNewParamsIntegration{ + AuthMethod: finchgo.F(finchgo.ConnectSessionNewParamsIntegrationAuthMethodAssisted), + Provider: finchgo.F("provider"), + }), + Manual: finchgo.F(true), + MinutesToExpire: finchgo.F(1.000000), + RedirectUri: finchgo.F("redirect_uri"), + Sandbox: finchgo.F(finchgo.ConnectSessionNewParamsSandboxFinch), + }) + if err != nil { + var apierr *finchgo.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestConnectSessionReauthenticateWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := finchgo.NewClient( + option.WithBaseURL(baseURL), + option.WithAccessToken("My Access Token"), + option.WithClientID("4ab15e51-11ad-49f4-acae-f343b7794375"), + option.WithClientSecret("My Client Secret"), + ) + _, err := client.Connect.Sessions.Reauthenticate(context.TODO(), finchgo.ConnectSessionReauthenticateParams{ + ConnectionID: finchgo.F("connection_id"), + MinutesToExpire: finchgo.F(int64(0)), + Products: finchgo.F([]finchgo.ConnectSessionReauthenticateParamsProduct{finchgo.ConnectSessionReauthenticateParamsProductCompany, finchgo.ConnectSessionReauthenticateParamsProductDirectory, finchgo.ConnectSessionReauthenticateParamsProductIndividual}), + RedirectUri: finchgo.F("https://example.com"), + }) + if err != nil { + var apierr *finchgo.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +}