@@ -5,28 +5,29 @@ import { AnalyticsConfigProto, AnalyticsProto } from 'juno-proto';
55import { lastValueFrom } from 'rxjs' ;
66import { ANALYTICS_CONFIG_DB_SERVICE_NAME } from 'juno-proto/dist/gen/analytics_config' ;
77
8- type EventEnvironment = any ;
9-
108@Injectable ( )
119export class AnalyticsService implements OnModuleInit {
1210 private analyticsService : AnalyticsConfigProto . AnalyticsConfigDbServiceClient ;
1311
14- private AnalyticsLogger : any ;
12+ private AnalyticsLogger : any ;
1513 private AnalyticsViewer : any ;
1614 private EventEnvironment : any ;
1715
18- constructor ( @Inject ( ANALYTICS_CONFIG_DB_SERVICE_NAME ) private analyticsClient : ClientGrpc
16+ constructor (
17+ @Inject ( ANALYTICS_CONFIG_DB_SERVICE_NAME )
18+ private analyticsClient : ClientGrpc ,
1919 ) { }
2020
2121 async onModuleInit ( ) {
22- this . analyticsService = this . analyticsClient . getService < AnalyticsConfigProto . AnalyticsConfigDbServiceClient > (
23- ANALYTICS_CONFIG_DB_SERVICE_NAME
24- ) ;
22+ this . analyticsService =
23+ this . analyticsClient . getService < AnalyticsConfigProto . AnalyticsConfigDbServiceClient > (
24+ ANALYTICS_CONFIG_DB_SERVICE_NAME ,
25+ ) ;
2526
2627 // bog-analytics is absolutely cursed and outdated, have to do some shenanigans
2728 // to get around ESM import
2829 const loadModule = eval ( '(specifier) => import(specifier)' ) ;
29- const bogAnalytics = await loadModule ( 'bog-analytics' ) ;
30+ const bogAnalytics = await loadModule ( 'bog-analytics' ) ;
3031
3132 this . AnalyticsLogger = bogAnalytics . AnalyticsLogger ;
3233 this . AnalyticsViewer = bogAnalytics . AnalyticsViewer ;
@@ -35,7 +36,11 @@ export class AnalyticsService implements OnModuleInit {
3536
3637 // bog-analytics currently doesn't allow stateless requests with passing in a key,
3738 // so we have to compromise by re-instantiating the object each time
38- async getAnalyticsViewer ( analyticsEnvironment : any , configId : number , junoEnvironment : string ) {
39+ async getAnalyticsViewer (
40+ analyticsEnvironment : any ,
41+ configId : number ,
42+ junoEnvironment : string ,
43+ ) {
3944 const config = await lastValueFrom (
4045 this . analyticsService . readAnalyticsConfig ( {
4146 id : configId ,
@@ -49,7 +54,7 @@ export class AnalyticsService implements OnModuleInit {
4954 } ) ;
5055
5156 try {
52- viewer . authenticate ( config . analyticsKey ) ;
57+ viewer . authenticate ( config . serverAnalyticsKey ) ;
5358 } catch ( e ) {
5459 throw new RpcException ( {
5560 code : status . UNAUTHENTICATED ,
@@ -60,7 +65,11 @@ export class AnalyticsService implements OnModuleInit {
6065 return viewer ;
6166 }
6267
63- async getAnalyticsLogger ( analyticsEnvironment : any , configId : number , junoEnvironment : string ) {
68+ async getAnalyticsLogger (
69+ analyticsEnvironment : any ,
70+ configId : number ,
71+ junoEnvironment : string ,
72+ ) {
6473 const config = await lastValueFrom (
6574 this . analyticsService . readAnalyticsConfig ( {
6675 id : configId ,
@@ -70,11 +79,11 @@ export class AnalyticsService implements OnModuleInit {
7079
7180 const viewer = new this . AnalyticsLogger ( {
7281 apiBaseUrl : process . env . BOG_ANALYTICS_BASE_URL ,
73- environment : analyticsEnvironment
82+ environment : analyticsEnvironment ,
7483 } ) ;
7584
7685 try {
77- viewer . authenticate ( config . analyticsKey ) ;
86+ viewer . authenticate ( config . clientAnalyticsKey ) ;
7887 } catch ( e ) {
7988 throw new RpcException ( {
8089 code : status . UNAUTHENTICATED ,
@@ -88,7 +97,11 @@ export class AnalyticsService implements OnModuleInit {
8897 async logClickEvent (
8998 event : AnalyticsProto . ClickEventRequest ,
9099 ) : Promise < AnalyticsProto . ClickEventResponse > {
91- const logger = await this . getAnalyticsLogger ( this . EventEnvironment . DEVELOPMENT , event . configId , event . configEnvironment ) ;
100+ const logger = await this . getAnalyticsLogger (
101+ this . EventEnvironment . DEVELOPMENT ,
102+ event . configId ,
103+ event . configEnvironment ,
104+ ) ;
92105
93106 if (
94107 ! event ||
@@ -128,8 +141,12 @@ export class AnalyticsService implements OnModuleInit {
128141 async logInputEvent (
129142 event : AnalyticsProto . InputEventRequest ,
130143 ) : Promise < AnalyticsProto . InputEventResponse > {
131- // TODO: we need to allow bog-analytics specific environments
132- const logger = await this . getAnalyticsLogger ( this . EventEnvironment . DEVELOPMENT , event . configId , event . environment ) ;
144+ // TODO: we need to allow bog-analytics specific environments
145+ const logger = await this . getAnalyticsLogger (
146+ this . EventEnvironment . DEVELOPMENT ,
147+ event . configId ,
148+ event . environment ,
149+ ) ;
133150
134151 if (
135152 ! event ||
@@ -173,8 +190,12 @@ export class AnalyticsService implements OnModuleInit {
173190 async logVisitEvent (
174191 event : AnalyticsProto . VisitEventRequest ,
175192 ) : Promise < AnalyticsProto . VisitEventResponse > {
176- // TODO: we need to allow environments
177- const logger = await this . getAnalyticsLogger ( this . EventEnvironment . DEVELOPMENT , event . configId , event . environment ) ;
193+ // TODO: we need to allow environments
194+ const logger = await this . getAnalyticsLogger (
195+ this . EventEnvironment . DEVELOPMENT ,
196+ event . configId ,
197+ event . environment ,
198+ ) ;
178199
179200 if (
180201 ! event ||
@@ -214,8 +235,12 @@ export class AnalyticsService implements OnModuleInit {
214235 async logCustomEvent (
215236 event : AnalyticsProto . CustomEventRequest ,
216237 ) : Promise < AnalyticsProto . CustomEventResponse > {
217- // TODO: we need to allow environments
218- const logger = await this . getAnalyticsLogger ( this . EventEnvironment . DEVELOPMENT , event . configId , event . environment ) ;
238+ // TODO: we need to allow environments
239+ const logger = await this . getAnalyticsLogger (
240+ this . EventEnvironment . DEVELOPMENT ,
241+ event . configId ,
242+ event . environment ,
243+ ) ;
219244
220245 if (
221246 ! event ||
@@ -261,7 +286,11 @@ export class AnalyticsService implements OnModuleInit {
261286 request : AnalyticsProto . CustomEventTypeRequest ,
262287 ) : Promise < AnalyticsProto . CustomEventTypeResponse > {
263288 // TODO: environments
264- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
289+ const viewer = await this . getAnalyticsViewer (
290+ this . EventEnvironment . DEVELOPMENT ,
291+ request . configId ,
292+ request . configEnvironment ,
293+ ) ;
265294
266295 if ( ! request . projectName || request . projectName . length === 0 ) {
267296 throw new RpcException ( {
@@ -270,9 +299,7 @@ export class AnalyticsService implements OnModuleInit {
270299 } ) ;
271300 }
272301
273- const response = await viewer . getCustomEventTypes (
274- request . projectName ,
275- ) ;
302+ const response = await viewer . getCustomEventTypes ( request . projectName ) ;
276303
277304 if ( ! response || response . length === 0 ) {
278305 return {
@@ -299,7 +326,11 @@ export class AnalyticsService implements OnModuleInit {
299326 request : AnalyticsProto . CustomGraphTypeRequest ,
300327 ) : Promise < AnalyticsProto . CustomGraphTypeResponse > {
301328 // TODO: environments
302- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
329+ const viewer = await this . getAnalyticsViewer (
330+ this . EventEnvironment . DEVELOPMENT ,
331+ request . configId ,
332+ request . configEnvironment ,
333+ ) ;
303334
304335 if ( ! request . projectName || request . projectName . length === 0 ) {
305336 throw new RpcException ( {
@@ -341,7 +372,11 @@ export class AnalyticsService implements OnModuleInit {
341372 async getClickEventsPaginated (
342373 request : AnalyticsProto . GetClickEventsRequest ,
343374 ) : Promise < AnalyticsProto . GetClickEventsResponse > {
344- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . environment ) ;
375+ const viewer = await this . getAnalyticsViewer (
376+ this . EventEnvironment . DEVELOPMENT ,
377+ request . configId ,
378+ request . environment ,
379+ ) ;
345380
346381 if ( ! request . projectName || request . projectName . length === 0 ) {
347382 throw new RpcException ( {
@@ -358,8 +393,7 @@ export class AnalyticsService implements OnModuleInit {
358393 afterTime : request . afterTime || undefined ,
359394 } ;
360395
361- const response =
362- await viewer . getClickEventsPaginated ( queryParams ) ;
396+ const response = await viewer . getClickEventsPaginated ( queryParams ) ;
363397
364398 if ( ! response ) {
365399 return { events : [ ] , afterId : '' } ;
@@ -392,7 +426,12 @@ export class AnalyticsService implements OnModuleInit {
392426 async getAllClickEvents (
393427 request : AnalyticsProto . GetAllClickEventsRequest ,
394428 ) : Promise < AnalyticsProto . GetAllClickEventsResponse > {
395- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
429+ console . log ( 'requesting new viewer ' ) ;
430+ const viewer = await this . getAnalyticsViewer (
431+ this . EventEnvironment . DEVELOPMENT ,
432+ request . configId ,
433+ request . configEnvironment ,
434+ ) ;
396435
397436 if ( ! request . projectName || request . projectName . length === 0 ) {
398437 throw new RpcException ( {
@@ -412,7 +451,10 @@ export class AnalyticsService implements OnModuleInit {
412451 limit ,
413452 ) ;
414453
454+ console . log ( response ) ;
455+
415456 if ( ! response ) {
457+ console . log ( 'null,' ) ;
416458 return { events : [ ] } ;
417459 }
418460
@@ -442,7 +484,11 @@ export class AnalyticsService implements OnModuleInit {
442484 async getVisitEventsPaginated (
443485 request : AnalyticsProto . GetVisitEventsRequest ,
444486 ) : Promise < AnalyticsProto . GetVisitEventsResponse > {
445- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
487+ const viewer = await this . getAnalyticsViewer (
488+ this . EventEnvironment . DEVELOPMENT ,
489+ request . configId ,
490+ request . configEnvironment ,
491+ ) ;
446492
447493 if ( ! request . projectName || request . projectName . length === 0 ) {
448494 throw new RpcException ( {
@@ -459,8 +505,7 @@ export class AnalyticsService implements OnModuleInit {
459505 afterTime : request . afterTime || undefined ,
460506 } ;
461507
462- const response =
463- await viewer . getVisitEventsPaginated ( queryParams ) ;
508+ const response = await viewer . getVisitEventsPaginated ( queryParams ) ;
464509
465510 if ( ! response ) {
466511 return { events : [ ] , afterId : '' } ;
@@ -493,7 +538,11 @@ export class AnalyticsService implements OnModuleInit {
493538 async getAllVisitEvents (
494539 request : AnalyticsProto . GetAllVisitEventsRequest ,
495540 ) : Promise < AnalyticsProto . GetAllVisitEventsResponse > {
496- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
541+ const viewer = await this . getAnalyticsViewer (
542+ this . EventEnvironment . DEVELOPMENT ,
543+ request . configId ,
544+ request . configEnvironment ,
545+ ) ;
497546
498547 if ( ! request . projectName || request . projectName . length === 0 ) {
499548 throw new RpcException ( {
@@ -543,7 +592,11 @@ export class AnalyticsService implements OnModuleInit {
543592 async getInputEventsPaginated (
544593 request : AnalyticsProto . GetInputEventsRequest ,
545594 ) : Promise < AnalyticsProto . GetInputEventsResponse > {
546- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
595+ const viewer = await this . getAnalyticsViewer (
596+ this . EventEnvironment . DEVELOPMENT ,
597+ request . configId ,
598+ request . configEnvironment ,
599+ ) ;
547600
548601 if ( ! request . projectName || request . projectName . length === 0 ) {
549602 throw new RpcException ( {
@@ -560,8 +613,7 @@ export class AnalyticsService implements OnModuleInit {
560613 afterTime : request . afterTime || undefined ,
561614 } ;
562615
563- const response =
564- await viewer . getInputEventsPaginated ( queryParams ) ;
616+ const response = await viewer . getInputEventsPaginated ( queryParams ) ;
565617
566618 if ( ! response ) {
567619 return { events : [ ] , afterId : '' } ;
@@ -595,7 +647,11 @@ export class AnalyticsService implements OnModuleInit {
595647 async getAllInputEvents (
596648 request : AnalyticsProto . GetAllInputEventsRequest ,
597649 ) : Promise < AnalyticsProto . GetAllInputEventsResponse > {
598- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
650+ const viewer = await this . getAnalyticsViewer (
651+ this . EventEnvironment . DEVELOPMENT ,
652+ request . configId ,
653+ request . configEnvironment ,
654+ ) ;
599655
600656 if ( ! request . projectName || request . projectName . length === 0 ) {
601657 throw new RpcException ( {
@@ -646,7 +702,11 @@ export class AnalyticsService implements OnModuleInit {
646702 async getCustomEventsPaginated (
647703 request : AnalyticsProto . GetCustomEventsRequest ,
648704 ) : Promise < AnalyticsProto . GetCustomEventsResponse > {
649- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
705+ const viewer = await this . getAnalyticsViewer (
706+ this . EventEnvironment . DEVELOPMENT ,
707+ request . configId ,
708+ request . configEnvironment ,
709+ ) ;
650710
651711 if ( ! request . projectName || request . projectName . length === 0 ) {
652712 throw new RpcException ( {
@@ -679,8 +739,7 @@ export class AnalyticsService implements OnModuleInit {
679739 subcategory : request . subcategory ,
680740 } ;
681741
682- const response =
683- await viewer . getCustomEventsPaginated ( queryParams ) ;
742+ const response = await viewer . getCustomEventsPaginated ( queryParams ) ;
684743
685744 if ( ! response ) {
686745 return { events : [ ] , afterId : '' } ;
@@ -711,7 +770,11 @@ export class AnalyticsService implements OnModuleInit {
711770 async getAllCustomEvents (
712771 request : AnalyticsProto . GetAllCustomEventsRequest ,
713772 ) : Promise < AnalyticsProto . GetAllCustomEventsResponse > {
714- const viewer = await this . getAnalyticsViewer ( this . EventEnvironment . DEVELOPMENT , request . configId , request . configEnvironment ) ;
773+ const viewer = await this . getAnalyticsViewer (
774+ this . EventEnvironment . DEVELOPMENT ,
775+ request . configId ,
776+ request . configEnvironment ,
777+ ) ;
715778
716779 if ( ! request . projectName || request . projectName . length === 0 ) {
717780 throw new RpcException ( {
0 commit comments