-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Add connect sessions endpoints (#249)
- Loading branch information
1 parent
9fa8c1e
commit 77639ad
Showing
6 changed files
with
343 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("[email protected]"), | ||
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()) | ||
} | ||
} |