File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " pam-react-native" ,
3- "version" : " 0.1.14 " ,
3+ "version" : " 0.1.15 " ,
44 "description" : " Pam SDK for React Native" ,
55 "source" : " ./src/index.tsx" ,
66 "main" : " ./lib/commonjs/index.js" ,
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { ConsentMessage } from './interface/consent_message';
77import type { IAttentionItem } from './interface/attention' ;
88import type { ICustomerConsentStatus } from './interface/iconsent_status' ;
99import { Utils } from './utils' ;
10- import type { PamPushMessage } from './interface/pam_push_message' ;
10+ import { PamPushMessage } from './interface/pam_push_message' ;
1111
1212export class PamAPI {
1313 private http : HTTPClient ;
@@ -177,7 +177,7 @@ export class PamAPI {
177177 response = await this . http . get ( url , { } ) ;
178178 } catch ( e ) { }
179179 if ( response ) {
180- return response . data as PamPushMessage [ ] ;
180+ return PamPushMessage . parseFromResponse ( response . items ) ;
181181 }
182182 return null ;
183183 }
@@ -194,7 +194,7 @@ export class PamAPI {
194194 } catch ( e ) { }
195195
196196 if ( response ) {
197- return response . data as PamPushMessage [ ] ;
197+ return PamPushMessage . parseFromResponse ( response . items ) ;
198198 }
199199 return null ;
200200 }
@@ -209,8 +209,9 @@ export class PamAPI {
209209 const url = `/api/app-notifications?_database=${ database } &_contact_id=${ contactID } &email=${ email } ` ;
210210 response = await this . http . get ( url , { } ) ;
211211 } catch ( e ) { }
212+
212213 if ( response ) {
213- return response . data as PamPushMessage [ ] ;
214+ return PamPushMessage . parseFromResponse ( response . items ) ;
214215 }
215216 return null ;
216217 }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import PamTracker from './PamTracker';
66import type { ConsentMessage } from './interface/consent_message' ;
77import { type AppAttentionStyle } from './interface/app_attention_style' ;
88import { Linking } from 'react-native' ;
9- import type { PamPushMessage } from './interface/pam_push_message' ;
9+ import { PamPushMessage } from './interface/pam_push_message' ;
1010
1111const LINKING_ERROR =
1212 `The package 'pam-react-native' doesn't seem to be linked. Make sure: \n\n` +
@@ -157,19 +157,19 @@ export class Pam {
157157 const title = message . notification ?. title ?? '' ;
158158 const description = message . notification ?. body ?? '' ;
159159
160- var item = {
161- deliverID : '' ,
162- pixel : pixel ,
163- title : title ,
164- description : description ,
165- thumbnailUrl : banner ,
166- flex : flex ,
167- url : url ,
168- popupType : popupType ,
169- date : new Date ( ) ,
170- isOpen : false ,
171- data : payload ,
172- } ;
160+ let item = new PamPushMessage (
161+ '' ,
162+ pixel ,
163+ title ,
164+ description ,
165+ banner ,
166+ flex ,
167+ url ,
168+ popupType ,
169+ new Date ( ) ,
170+ false ,
171+ payload
172+ ) ;
173173
174174 return item ;
175175 }
Original file line number Diff line number Diff line change 1- export interface PamPushMessage {
1+ export class PamPushMessage {
22 deliverID ?: string ;
33 pixel ?: string ;
44 title ?: string ;
@@ -7,7 +7,78 @@ export interface PamPushMessage {
77 flex ?: string ;
88 url ?: string ;
99 popupType ?: string ;
10- bisOpen ?: boolean ;
10+ isOpen ?: boolean ;
1111 date ?: Date ;
1212 data ?: Record < string , any > ;
13+
14+ constructor (
15+ deliverID : string ,
16+ pixel : string ,
17+ title : string ,
18+ description : string ,
19+ thumbnailUrl : string ,
20+ flex : string ,
21+ url : string ,
22+ popupType : string ,
23+ date : Date ,
24+ isOpen : boolean ,
25+ data : Record < string , any >
26+ ) {
27+ this . deliverID = deliverID ;
28+ this . pixel = pixel ;
29+ this . title = title ;
30+ this . description = description ;
31+ this . thumbnailUrl = thumbnailUrl ;
32+ this . flex = flex ;
33+ this . url = url ;
34+ this . popupType = popupType ;
35+ this . date = date ;
36+ this . isOpen = isOpen ;
37+ this . data = data ;
38+ }
39+
40+ trackOpen ( ) {
41+ if ( this . pixel ) {
42+ fetch ( this . pixel , {
43+ method : 'GET' ,
44+ } )
45+ . then ( ( response ) => {
46+ if ( ! response . ok ) {
47+ throw new Error ( 'Network response was not ok' ) ;
48+ }
49+ } )
50+ . catch ( ( error ) => {
51+ console . error (
52+ 'There has been a problem with your fetch operation:' ,
53+ error
54+ ) ;
55+ } ) ;
56+ }
57+ }
58+
59+ static parseFromResponse ( items : any [ ] ) : PamPushMessage [ ] {
60+ return items . map ( ( data ) => {
61+ return PamPushMessage . fromNotificationData ( data ) ;
62+ } ) ;
63+ }
64+
65+ private static fromNotificationData (
66+ data : Record < string , any >
67+ ) : PamPushMessage {
68+ const payload = data . json_data . pam ;
69+
70+ return new PamPushMessage (
71+ data . deliver_id ,
72+ data . pixel ,
73+ data . title ,
74+ data . description ,
75+ data . thumbnail_url ,
76+ data . flex ,
77+ data . url ,
78+ payload . popupType ,
79+ new Date ( data . created_date + 'Z' ) ,
80+ data . is_open ,
81+ payload
82+ ) ;
83+ }
1384}
You can’t perform that action at this time.
0 commit comments