@@ -18,8 +18,18 @@ import {
18
18
VerifyTokenVariables ,
19
19
verifyTokenQuery ,
20
20
} from '../../graphql/verifyTokenQuery'
21
+ import {
22
+ EnableChannelNotificationsMutationResult ,
23
+ EnableChannelNotificationsMutationVariables ,
24
+ enableChannelNotificationsMutation ,
25
+ } from '../../graphql/enableChannelNotifications'
26
+ import {
27
+ VerifyEmailMutationResult ,
28
+ VerifyEmailMutationVariables ,
29
+ verifyEmailMutation ,
30
+ } from '../../graphql/verifyEmailMutation'
21
31
22
- type ErrorInfo = {
32
+ export type ErrorInfo = {
23
33
type : string
24
34
message : string
25
35
}
@@ -169,3 +179,68 @@ export const connectToChannel = async ({
169
179
) ,
170
180
) ,
171
181
) ( )
182
+
183
+ export const enableChannelNotifications = ( {
184
+ apollo,
185
+ token,
186
+ email,
187
+ channel,
188
+ } : {
189
+ token : string
190
+ channel : string
191
+ email : string
192
+ apollo : ApolloClient < NormalizedCacheObject >
193
+ } ) =>
194
+ tryCatch < ErrorInfo , { emailVerified : boolean } > (
195
+ async ( ) =>
196
+ apollo
197
+ . mutate <
198
+ EnableChannelNotificationsMutationResult ,
199
+ EnableChannelNotificationsMutationVariables
200
+ > ( {
201
+ mutation : enableChannelNotificationsMutation ,
202
+ variables : { token, channel, email } ,
203
+ } )
204
+ . then ( ( { data } ) => {
205
+ if ( ! data ) {
206
+ throw new Error ( 'No response received!' )
207
+ } else {
208
+ return data . enableChannelNotifications
209
+ }
210
+ } ) ,
211
+ reason => ( {
212
+ type : 'IntegrationError' ,
213
+ message : `Failed to enable channel notifications: ${
214
+ ( reason as Error ) . message
215
+ } `,
216
+ } ) ,
217
+ )
218
+
219
+ export const verifyEmail = ( {
220
+ apollo,
221
+ email,
222
+ code,
223
+ } : {
224
+ code : string
225
+ email : string
226
+ apollo : ApolloClient < NormalizedCacheObject >
227
+ } ) =>
228
+ tryCatch < ErrorInfo , boolean > (
229
+ async ( ) =>
230
+ apollo
231
+ . mutate < VerifyEmailMutationResult , VerifyEmailMutationVariables > ( {
232
+ mutation : verifyEmailMutation ,
233
+ variables : { code, email } ,
234
+ } )
235
+ . then ( ( { data } ) => {
236
+ if ( ! data ) {
237
+ throw new Error ( 'No response received!' )
238
+ } else {
239
+ return data . verifyEmail
240
+ }
241
+ } ) ,
242
+ reason => ( {
243
+ type : 'IntegrationError' ,
244
+ message : `Failed to verify email: ${ ( reason as Error ) . message } ` ,
245
+ } ) ,
246
+ )
0 commit comments