@@ -67,20 +67,22 @@ export class Controller {
67
67
infoLogger ( `Fetching contacts…` , providerConfig ) ;
68
68
69
69
const fetchedContacts : Contact [ ] = await this . adapter . getContacts (
70
- providerConfig
70
+ providerConfig ,
71
+ req ,
72
+ res
71
73
) ;
72
74
73
75
if ( ! validate ( this . ajv , contactsSchema , fetchedContacts ) ) {
74
76
throw new ServerError ( 500 , "Invalid contacts received" ) ;
75
77
}
76
78
77
79
return fetchedContacts . map ( ( contact ) =>
78
- sanitizeContact ( contact , providerConfig . locale )
80
+ sanitizeContact ( contact , locale )
79
81
) ;
80
82
} ;
81
83
82
84
const fetcherPromise = this . contactCache
83
- ? this . contactCache . get ( providerConfig . apiKey , fetchContacts )
85
+ ? this . contactCache . get ( apiKey , fetchContacts )
84
86
: fetchContacts ( ) ;
85
87
86
88
const timeoutPromise : Promise < "TIMEOUT" > = new Promise ( ( resolve ) =>
@@ -89,7 +91,7 @@ export class Controller {
89
91
90
92
const raceResult = await Promise . race ( [ fetcherPromise , timeoutPromise ] ) ;
91
93
if ( raceResult === "TIMEOUT" ) {
92
- infoLogger ( `Fetching too slow, returning empty array.` , providerConfig ) ;
94
+ console . log ( `[ ${ anonKey } ] fetching too slow, returning empty array` ) ;
93
95
}
94
96
95
97
const responseContacts : Contact [ ] = Array . isArray ( raceResult )
@@ -98,7 +100,7 @@ export class Controller {
98
100
99
101
const contactsCount = responseContacts . length ;
100
102
101
- infoLogger ( ` Found ${ contactsCount } cached contacts.` , providerConfig ) ;
103
+ console . log ( `[ ${ anonKey } ] Found ${ contactsCount } cached contacts` ) ;
102
104
103
105
if (
104
106
! Array . isArray ( raceResult ) &&
@@ -115,11 +117,7 @@ export class Controller {
115
117
116
118
res . status ( 200 ) . send ( responseContacts ) ;
117
119
} catch ( error ) {
118
- errorLogger (
119
- "Could not get contacts:" ,
120
- providerConfig ,
121
- error || "Unknown"
122
- ) ;
120
+ console . error ( "Could not get contacts:" , error || "Unknown" ) ;
123
121
next ( error ) ;
124
122
}
125
123
}
@@ -143,7 +141,9 @@ export class Controller {
143
141
144
142
const contact : Contact = await this . adapter . createContact (
145
143
req . providerConfig ,
146
- req . body as ContactTemplate
144
+ req . body as ContactTemplate ,
145
+ req ,
146
+ res
147
147
) ;
148
148
149
149
const valid = validate ( this . ajv , contactsSchema , [ contact ] ) ;
@@ -199,7 +199,9 @@ export class Controller {
199
199
const contact : Contact = await this . adapter . updateContact (
200
200
req . providerConfig ,
201
201
req . params . id ,
202
- req . body as ContactUpdate
202
+ req . body as ContactUpdate ,
203
+ req ,
204
+ res
203
205
) ;
204
206
205
207
const valid = validate ( this . ajv , contactsSchema , [ contact ] ) ;
@@ -252,7 +254,7 @@ export class Controller {
252
254
console . log ( `Deleting contact for key "${ anonymizeKey ( apiKey ) } "` ) ;
253
255
254
256
const contactId : string = req . params . id ;
255
- await this . adapter . deleteContact ( req . providerConfig , contactId ) ;
257
+ await this . adapter . deleteContact ( req . providerConfig , contactId , req , res ) ;
256
258
257
259
if ( this . adapter . getToken && req . providerConfig ) {
258
260
const { apiKey } = await this . adapter . getToken ( req . providerConfig ) ;
@@ -456,40 +458,36 @@ export class Controller {
456
458
res : Response ,
457
459
next : NextFunction
458
460
) : Promise < void > {
459
- const { providerConfig } = req ;
460
-
461
+ const { providerConfig : { apiKey = "" } = { } } = req ;
461
462
try {
462
- if ( ! providerConfig ) {
463
- throw new ServerError ( 400 , "Missing config parameters" ) ;
464
- }
465
-
466
463
if ( ! this . adapter . handleCallEvent ) {
467
464
throw new ServerError ( 501 , "Handling call event is not implemented" ) ;
468
465
}
469
466
467
+ if ( ! req . providerConfig ) {
468
+ throw new ServerError ( 400 , "Missing config parameters" ) ;
469
+ }
470
+
470
471
if ( shouldSkipCallEvent ( req . body as CallEvent ) ) {
471
- infoLogger (
472
- `Skipping call event for call id ${ req . body . id } ` ,
473
- providerConfig
472
+ console . log (
473
+ `[${ anonymizeKey ( apiKey ) } ] skipping call event for call id ${
474
+ req . body . id
475
+ } `
474
476
) ;
475
477
res . status ( 200 ) . send ( "Skipping call event" ) ;
476
478
return ;
477
479
}
478
480
479
- infoLogger ( ` Handling call event` , providerConfig ) ;
481
+ console . log ( `[ ${ anonymizeKey ( apiKey ) } ] Handling call event for key` ) ;
480
482
481
483
const integrationCallEventRef = await this . adapter . handleCallEvent (
482
- providerConfig ,
484
+ req . providerConfig ,
483
485
req . body as CallEvent
484
486
) ;
485
487
486
488
res . status ( 200 ) . send ( integrationCallEventRef ) ;
487
489
} catch ( error ) {
488
- errorLogger (
489
- "Could not handle call event:" ,
490
- providerConfig ,
491
- error || "Unknown"
492
- ) ;
490
+ console . error ( "Could not handle call event:" , error || "Unknown" ) ;
493
491
next ( error ) ;
494
492
}
495
493
}
@@ -524,11 +522,11 @@ export class Controller {
524
522
}
525
523
526
524
public async updateCallEvent (
527
- req : UpdateCallEventBridgeRequest ,
525
+ req : BridgeRequest ,
528
526
res : Response ,
529
527
next : NextFunction
530
528
) : Promise < void > {
531
- const { providerConfig : { apiKey = "" } = { } , body , params } = req ;
529
+ const { providerConfig : { apiKey = "" } = { } } = req ;
532
530
533
531
try {
534
532
if ( ! this . adapter . updateCallEvent ) {
@@ -539,9 +537,24 @@ export class Controller {
539
537
throw new ServerError ( 400 , "Missing config parameters" ) ;
540
538
}
541
539
540
+ if ( shouldSkipCallEvent ( req . body as CallEvent ) ) {
541
+ console . log (
542
+ `[${ anonymizeKey ( apiKey ) } ] skipping call event for call id ${
543
+ req . body . id
544
+ } `
545
+ ) ;
546
+ res . status ( 200 ) . send ( "Skipping call event" ) ;
547
+ return ;
548
+ }
549
+
542
550
console . log ( `[${ anonymizeKey ( apiKey ) } ] Updating call event` ) ;
543
551
544
- await this . adapter . updateCallEvent ( req . providerConfig , params . id , body ) ;
552
+ //maybe return updated state obj
553
+ await this . adapter . updateCallEvent (
554
+ req . providerConfig ,
555
+ req . params . id ,
556
+ req . body as CallEvent
557
+ ) ;
545
558
res . status ( 200 ) . send ( ) ;
546
559
} catch ( error ) {
547
560
console . error ( "Could not update call event:" , error || "Unknown" ) ;
0 commit comments