@@ -28,7 +28,10 @@ import { CacheItemStateType } from "./cache-item-state.model";
28
28
import { CalendarFilterOptions } from "./calendar-filter-options.model" ;
29
29
import { IntegrationErrorType } from "./integration-error.model" ;
30
30
import { PubSubClient } from "./pubsub-client.model" ;
31
- import { PubSubContactsMessage } from "./pubsub-contacts-message.model" ;
31
+ import {
32
+ PubSubContactsMessage ,
33
+ PubSubContactsState ,
34
+ } from "./pubsub-contacts-message.model" ;
32
35
33
36
const CONTACT_FETCH_TIMEOUT = 3000 ;
34
37
@@ -47,19 +50,28 @@ export class Controller {
47
50
private contactCache : ContactCache | null ;
48
51
private ajv : Ajv ;
49
52
private pubSubClient : PubSubClient | null = null ;
53
+ private integrationName : string = "UNKNOWN" ;
50
54
51
55
constructor ( adapter : Adapter , contactCache : ContactCache | null ) {
52
56
this . adapter = adapter ;
53
57
this . contactCache = contactCache ;
54
58
this . ajv = new Ajv ( ) ;
55
59
56
60
if ( this . adapter . streamContacts ) {
57
- const { PUBSUB_TOPIC_NAME : topicName } = process . env ;
61
+ const {
62
+ PUBSUB_TOPIC_NAME : topicName ,
63
+ INTEGRATION_NAME : integrationName ,
64
+ } = process . env ;
58
65
59
66
if ( ! topicName ) {
60
- throw new Error ( "No pubsub topic name provided." ) ;
67
+ throw new Error ( "No PUBSUB_TOPIC_NAME provided." ) ;
68
+ }
69
+
70
+ if ( ! integrationName ) {
71
+ throw new Error ( "No INTEGRATION_NAME provided." ) ;
61
72
}
62
73
74
+ this . integrationName = integrationName ;
63
75
this . pubSubClient = new PubSubClient ( topicName ) ;
64
76
infoLogger (
65
77
"Controller" ,
@@ -209,6 +221,8 @@ export class Controller {
209
221
contacts : contacts . map ( ( contact ) =>
210
222
sanitizeContact ( contact , providerConfig . locale )
211
223
) ,
224
+ state : PubSubContactsState . IN_PROGRESS ,
225
+ integrationName : this . integrationName ,
212
226
} ;
213
227
214
228
await this . pubSubClient ?. publishMessage ( message ) ;
@@ -225,14 +239,24 @@ export class Controller {
225
239
}
226
240
} ;
227
241
228
- streamContacts ( ) . catch ( ( error ) =>
229
- errorLogger (
230
- "streamContacts" ,
231
- "Could not stream contacts" ,
232
- providerConfig . apiKey ,
233
- error
242
+ streamContacts ( )
243
+ . catch ( ( error ) =>
244
+ errorLogger (
245
+ "streamContacts" ,
246
+ "Could not stream contacts" ,
247
+ providerConfig . apiKey ,
248
+ error
249
+ )
234
250
)
235
- ) ;
251
+ . finally ( ( ) =>
252
+ this . pubSubClient ?. publishMessage ( {
253
+ userId : providerConfig . userId ,
254
+ timestamp,
255
+ contacts : [ ] ,
256
+ state : PubSubContactsState . COMPLETE ,
257
+ integrationName : this . integrationName ,
258
+ } )
259
+ ) ;
236
260
237
261
if ( this . adapter . getToken && req . providerConfig ) {
238
262
const { apiKey } = await this . adapter . getToken ( req . providerConfig ) ;
0 commit comments