-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectsession.go
217 lines (184 loc) · 9.63 KB
/
connectsession.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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 20,160, which is 14
// 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 20,160, which is 14
// 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
}