Skip to content

Commit c229783

Browse files
committed
build: 0.1.15
1 parent 9d931d6 commit c229783

4 files changed

Lines changed: 93 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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",

src/api.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ConsentMessage } from './interface/consent_message';
77
import type { IAttentionItem } from './interface/attention';
88
import type { ICustomerConsentStatus } from './interface/iconsent_status';
99
import { Utils } from './utils';
10-
import type { PamPushMessage } from './interface/pam_push_message';
10+
import { PamPushMessage } from './interface/pam_push_message';
1111

1212
export 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
}

src/index.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PamTracker from './PamTracker';
66
import type { ConsentMessage } from './interface/consent_message';
77
import { type AppAttentionStyle } from './interface/app_attention_style';
88
import { Linking } from 'react-native';
9-
import type { PamPushMessage } from './interface/pam_push_message';
9+
import { PamPushMessage } from './interface/pam_push_message';
1010

1111
const 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
}

src/interface/pam_push_message.ts

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
}

0 commit comments

Comments
 (0)