-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
354 lines (304 loc) · 9.56 KB
/
types.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package main
import (
"fmt"
"net/url"
"os"
"time"
)
type Campaign struct {
EmailListID string `json:"emailListId"`
ProviderName ProviderName `json:"providerName"`
OutputIDs []string `json:"outputIds"`
RedirectUrl string `json:"redirectUrl"`
}
func (c Campaign) Link() (string, error) {
var (
protocol = os.Getenv(EnvProtocol)
hostname = os.Getenv(EnvHostname)
)
if protocol == "" || hostname == "" {
return "", missingEnv(EnvProtocol, EnvHostname)
}
oauthID, err := decenc.Encode(c.EmailListID, c.ProviderName, c.OutputIDs, c.RedirectUrl)
if err != nil {
return "", err
}
return fmt.Sprintf("%s//%s/c?c=%s", protocol, hostname, url.QueryEscape(oauthID)), nil
}
type DiscordOAuth2TokenResp struct {
TokenType string `json:"token_type"`
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope"`
}
type DiscordProviderResp struct {
ID string `json:"id"`
Username string `json:"username"`
Avatar string `json:"avatar"`
Discriminator string `json:"discriminator"`
PublicFlags int `json:"public_flags"`
Flags int `json:"flags"`
Banner *string `json:"banner"`
AccentColor *int `json:"accent_color"`
GlobalName *string `json:"global_name"`
AvatarDecorationData *string `json:"avatar_decoration_data"`
BannerColor *string `json:"banner_color"`
Clan *string `json:"clan"`
MfaEnabled bool `json:"mfa_enabled"`
Locale string `json:"locale"`
PremiumType int `json:"premium_type"`
Email string `json:"email"`
Verified bool `json:"verified"`
}
type EmailList struct {
ID string `json:"id"`
UserID string `json:"userId"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func NewEmailList(userID string, name string) *EmailList {
now := time.Now()
return &EmailList{
ID: NewUUID(),
UserID: userID,
Name: name,
CreatedAt: now,
UpdatedAt: now,
}
}
type EmailListCreationReq struct {
UserID string `json:"userId"`
Name string `json:"name"`
}
type EmailListUpdateReq struct {
Name string `json:"name"`
}
type GoogleProviderResp struct {
ID string `json:"id"`
Email string `json:"email"`
VerifiedEmail bool `json:"verified_email"`
Name string `json:"name"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Picture string `json:"picture"`
}
type LoginInfo struct {
Username string `json:"username"`
Password string `json:"password"`
}
type Output interface {
OutputName() OutputName
GetUserID() string
Handle(emailAddr string, name string) error
}
type OutputsData map[OutputName][]Output
type OutputCreationReq struct {
UserID string `json:"userId"`
OutputName OutputName `json:"outputName"`
ListID string `json:"listId"`
Param1 string `json:"param1"`
Param2 string `json:"param2"`
Param3 string `json:"param3"`
}
type OutputUpdateReq struct {
OutputName OutputName `json:"outputName"`
ListID string `json:"listId"`
Param1 string `json:"param1"`
Param2 string `json:"param2"`
Param3 string `json:"param3"`
}
type AWeberOutput struct {
ID string `json:"id"`
UserID string `json:"userId"`
ListID string `json:"listId"`
AdTracking string `json:"adTracking"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type BrevoOutput struct {
ID string `json:"id"`
UserID string `json:"userId"`
ListID string `json:"listId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type ResendOutput struct {
ID string `json:"id"`
UserID string `json:"userId"`
AudienceID string `json:"audienceId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type TelegramOutput struct {
ID string `json:"id"`
UserID string `json:"userId"`
ChatID string `json:"chatId"`
MsgFmt string `json:"msgFmt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type WebhookOutput struct {
ID string `json:"id"`
UserID string `json:"userId"`
UrlFmt string `json:"urlFmt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type ProviderResult struct {
Name string `json:"name"`
EmailAddr string `json:"emailAddr"`
}
type Subscriber struct {
ID string `json:"id"`
EmailListID string `json:"emailListId"`
UserID string `json:"userId"`
SourceProviderName ProviderName `json:"sourceProviderName"`
Name string `json:"name"`
EmailAddr string `json:"emailAddr"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func NewSubscriber(
emailListID string,
userID string,
sourceProviderName ProviderName,
name string,
emailAddr string,
) *Subscriber {
now := time.Now()
return &Subscriber{
ID: NewUUID(),
EmailListID: emailListID,
UserID: userID,
SourceProviderName: sourceProviderName,
Name: name,
EmailAddr: emailAddr,
CreatedAt: now,
UpdatedAt: now,
}
}
type SubscriberCreationReq struct {
EmailListID string `json:"emailListId"`
UserID string `json:"userId"`
SourceProviderName ProviderName `json:"sourceProviderName"`
Name string `json:"name"`
EmailAddr string `json:"emailAddr"`
}
type SubscriberUpdateReq struct {
Name string `json:"name"`
EmailAddr string `json:"emailAddr"`
}
type User struct {
ID string `json:"id"`
Name string `json:"name"`
HashedPassword string `json:"hashedPassword"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type UserCreationReq struct {
Name string `json:"name"`
Password string `json:"password"`
}
type UserUpdateReq struct {
Name string `json:"name"`
Password string `json:"password"`
}
const (
ContentTypeApplicationJson string = "application/json"
ContentTypeApplicationXwwwFormUrlEncoded string = "application/x-www-form-urlencoded"
)
type CookieName string
const (
CookieNameCreatedAt CookieName = "createdAt"
CookieNameEmailListID CookieName = "emailListId"
CookieNameJWT CookieName = "jwt"
CookieNameOutputIDs CookieName = "outputIds"
CookieNameProviderName CookieName = "providerName"
CookieNameRedirectURL CookieName = "redirectUrl"
)
const (
EnvBrevoApiKey string = "BREVO_API_KEY"
EnvCatchAllRedirectUrl string = "CATCH_ALL_REDIRECT_URL"
EnvCookieSecret string = "COOKIE_SECRET"
EnvCryptoSecret string = "CRYPTO_SECRET"
EnvDiscordClientID string = "DISCORD_CLIENT_ID"
EnvDiscordClientSecret string = "DISCORD_CLIENT_SECRET"
EnvGoogleClientID string = "GOOGLE_CLIENT_ID"
EnvGoogleClientSecret string = "GOOGLE_CLIENT_SECRET"
EnvGoogleOAuthStateStr string = "GOOGLE_OAUTH_STATE_STR"
EnvHostname string = "HOST_NAME"
EnvJWTSecret string = "JWT_SECRET"
EnvPort string = "PORT"
EnvProtocol string = "PROTOCOL"
EnvPostgresConnStr string = "POSTGRES_CONN_STR"
EnvResendApiKey string = "RESEND_API_KEY"
EnvRootPassword string = "ROOT_PASSWORD"
EnvRootUsername string = "ROOT_USERNAME"
EnvRunningFromServerless string = "RUNNING_FROM_SERVERLESS"
EnvTelegramBotID string = "TELEGRAM_BOT_ID"
)
const (
FormFieldAdTracking string = "meta_adtracking"
FormFieldClientID string = "client_id"
FormFieldClientSecret string = "client_secret"
FormFieldCode string = "code"
FormFieldEmail string = "email"
FormFieldGrantType string = "grant_type"
FormFieldListName string = "listname"
FormFieldName string = "name"
FormFieldRedirectUri string = "redirect_uri"
FormFieldText string = "text"
FormFieldTelegramChatID string = "chat_id"
)
const FormValueAuthorizationCode string = "authorization_code"
const (
GoogleOauthScopeEmail string = "email"
GoogleOauthScopeProfile string = "profile"
)
const (
HTTPHeaderAcceptEncoding string = "Accept-Encoding"
HTTPHeaderAuthorization string = "Authorization"
HTTPHeaderContentType string = "Content-Type"
)
const (
JwtClaimExpiresAt string = "expiresAt"
JwtClaimData string = "data"
JwtClaimUserID string = "userID"
)
const (
MuxVarUserID string = "userID"
MuxVarOutputID string = "outputID"
)
const JwtHeaderAlg string = "alg"
type OutputName string
const (
OutputNameAWeber OutputName = "aweber"
OutputNameBrevo OutputName = "brevo"
OutputNameResend OutputName = "resend"
OutputNameTelegram OutputName = "telegram"
OutputNameWebhook OutputName = "webhook"
)
type ProviderName string
const (
ProviderNameDiscord ProviderName = "Discord"
ProviderNameGoogle ProviderName = "Google"
)
var providerNames = []ProviderName{
ProviderNameDiscord,
ProviderNameGoogle,
}
const (
QueryParamC string = "c"
QueryParamCode string = "code"
QueryParamState string = "state"
)
const (
StringTrue string = "true"
StringFalse string = "false"
)
const (
StrIpolEmailAddr string = "emailAddr"
StrIpolName string = "name"
)