@@ -19,10 +19,10 @@ const SEND_OUTCOME = 'sendOutcome';
1919const SEND_UNIQUE_OUTCOME = 'sendUniqueOutcome' ;
2020
2121export default class OutcomesHelper {
22- private outcomeName : string ;
23- private config : OutcomesConfig ;
24- private appId : string ;
25- private isUnique : boolean ;
22+ private _outcomeName : string ;
23+ private _config : OutcomesConfig ;
24+ private _appId : string ;
25+ private _isUnique : boolean ;
2626
2727 /**
2828 * @param {string } appId
@@ -36,10 +36,10 @@ export default class OutcomesHelper {
3636 outcomeName : string ,
3737 isUnique : boolean ,
3838 ) {
39- this . outcomeName = outcomeName ;
40- this . config = config ;
41- this . appId = appId ;
42- this . isUnique = isUnique ;
39+ this . _outcomeName = outcomeName ;
40+ this . _config = config ;
41+ this . _appId = appId ;
42+ this . _isUnique = isUnique ;
4343 }
4444 /**
4545 * Returns `OutcomeAttribution` object which includes
@@ -50,27 +50,27 @@ export default class OutcomesHelper {
5050 * does not check if they have been previously attributed (used in both sendOutcome & sendUniqueOutcome)
5151 * @returns Promise
5252 */
53- async getAttribution ( ) : Promise < OutcomeAttribution > {
54- return await getConfigAttribution ( this . config ) ;
53+ async _getAttribution ( ) : Promise < OutcomeAttribution > {
54+ return await getConfigAttribution ( this . _config ) ;
5555 }
5656
5757 /**
5858 * Performs logging of method call and returns whether Outcomes are supported
5959 * @param {boolean } isUnique
6060 * @returns Promise
6161 */
62- async beforeOutcomeSend ( ) : Promise < boolean > {
63- const outcomeMethodString = this . isUnique
62+ async _beforeOutcomeSend ( ) : Promise < boolean > {
63+ const outcomeMethodString = this . _isUnique
6464 ? SEND_UNIQUE_OUTCOME
6565 : SEND_OUTCOME ;
66- logMethodCall ( outcomeMethodString , this . outcomeName ) ;
66+ logMethodCall ( outcomeMethodString , this . _outcomeName ) ;
6767
68- if ( ! this . config ) {
68+ if ( ! this . _config ) {
6969 Log . _debug ( 'Outcomes feature not supported by main application yet.' ) ;
7070 return false ;
7171 }
7272
73- if ( ! this . outcomeName ) {
73+ if ( ! this . _outcomeName ) {
7474 Log . _error ( 'Outcome name is required' ) ;
7575 return false ;
7676 }
@@ -91,10 +91,10 @@ export default class OutcomesHelper {
9191 * @param {string } outcomeName
9292 * @returns Promise
9393 */
94- async getAttributedNotifsByUniqueOutcomeName ( ) : Promise < string [ ] > {
94+ async _getAttributedNotifsByUniqueOutcomeName ( ) : Promise < string [ ] > {
9595 const sentOutcomes = await db . getAll ( 'SentUniqueOutcome' ) ;
9696 return sentOutcomes
97- . filter ( ( o ) => o . outcomeName === this . outcomeName )
97+ . filter ( ( o ) => o . outcomeName === this . _outcomeName )
9898 . reduce ( ( acc : string [ ] , curr : SentUniqueOutcome ) => {
9999 const notificationIds = curr . notificationIds || [ ] ;
100100 return [ ...acc , ...notificationIds ] ;
@@ -106,25 +106,28 @@ export default class OutcomesHelper {
106106 * @param {string } outcomeName
107107 * @param {string[] } notificationIds
108108 */
109- async getNotifsToAttributeWithUniqueOutcome ( notificationIds : string [ ] ) {
109+ async _getNotifsToAttributeWithUniqueOutcome ( notificationIds : string [ ] ) {
110110 const previouslyAttributedArr : string [ ] =
111- await this . getAttributedNotifsByUniqueOutcomeName ( ) ;
111+ await this . _getAttributedNotifsByUniqueOutcomeName ( ) ;
112112
113113 return notificationIds . filter (
114114 ( id ) => previouslyAttributedArr . indexOf ( id ) === - 1 ,
115115 ) ;
116116 }
117117
118- shouldSendUnique ( outcomeAttribution : OutcomeAttribution , notifArr : string [ ] ) {
118+ _shouldSendUnique (
119+ outcomeAttribution : OutcomeAttribution ,
120+ notifArr : string [ ] ,
121+ ) {
119122 // we should only send if type is unattributed OR there are notifs to attribute
120123 if ( outcomeAttribution . type === OutcomeAttributionType . Unattributed ) {
121124 return true ;
122125 }
123126 return notifArr . length > 0 ;
124127 }
125128
126- async saveSentUniqueOutcome ( newNotificationIds : string [ ] ) : Promise < void > {
127- const outcomeName = this . outcomeName ;
129+ async _saveSentUniqueOutcome ( newNotificationIds : string [ ] ) : Promise < void > {
130+ const outcomeName = this . _outcomeName ;
128131 const existingSentOutcome = await db . get ( 'SentUniqueOutcome' , outcomeName ) ;
129132 const currentSession = await getCurrentSession ( ) ;
130133
@@ -141,8 +144,8 @@ export default class OutcomesHelper {
141144 } ) ;
142145 }
143146
144- async wasSentDuringSession ( ) {
145- const sentOutcome = await db . get ( 'SentUniqueOutcome' , this . outcomeName ) ;
147+ async _wasSentDuringSession ( ) {
148+ const sentOutcome = await db . get ( 'SentUniqueOutcome' , this . _outcomeName ) ;
146149
147150 if ( ! sentOutcome ) {
148151 return false ;
@@ -160,45 +163,45 @@ export default class OutcomesHelper {
160163 ) ;
161164 }
162165
163- async send ( outcomeProps : OutcomeProps ) : Promise < void > {
166+ async _send ( outcomeProps : OutcomeProps ) : Promise < void > {
164167 const { type, notificationIds, weight } = outcomeProps ;
165168
166169 switch ( type ) {
167170 case OutcomeAttributionType . Direct :
168- if ( this . isUnique ) {
169- await this . saveSentUniqueOutcome ( notificationIds ) ;
171+ if ( this . _isUnique ) {
172+ await this . _saveSentUniqueOutcome ( notificationIds ) ;
170173 }
171174 await OneSignal . _context . _updateManager . _sendOutcomeDirect (
172- this . appId ,
175+ this . _appId ,
173176 notificationIds ,
174- this . outcomeName ,
177+ this . _outcomeName ,
175178 weight ,
176179 ) ;
177180 return ;
178181 case OutcomeAttributionType . Indirect :
179- if ( this . isUnique ) {
180- await this . saveSentUniqueOutcome ( notificationIds ) ;
182+ if ( this . _isUnique ) {
183+ await this . _saveSentUniqueOutcome ( notificationIds ) ;
181184 }
182185 await OneSignal . _context . _updateManager . _sendOutcomeInfluenced (
183- this . appId ,
186+ this . _appId ,
184187 notificationIds ,
185- this . outcomeName ,
188+ this . _outcomeName ,
186189 weight ,
187190 ) ;
188191 return ;
189192 case OutcomeAttributionType . Unattributed :
190- if ( this . isUnique ) {
191- if ( await this . wasSentDuringSession ( ) ) {
193+ if ( this . _isUnique ) {
194+ if ( await this . _wasSentDuringSession ( ) ) {
192195 Log . _warn (
193196 `(Unattributed) unique outcome was already sent during this session` ,
194197 ) ;
195198 return ;
196199 }
197- await this . saveSentUniqueOutcome ( [ ] ) ;
200+ await this . _saveSentUniqueOutcome ( [ ] ) ;
198201 }
199202 await OneSignal . _context . _updateManager . _sendOutcomeUnattributed (
200- this . appId ,
201- this . outcomeName ,
203+ this . _appId ,
204+ this . _outcomeName ,
202205 weight ,
203206 ) ;
204207 return ;
@@ -209,8 +212,6 @@ export default class OutcomesHelper {
209212 return ;
210213 }
211214 }
212-
213- // statics
214215}
215216
216217/**
0 commit comments