@suprsend/web-sdk 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
# SuprSend Javascript Web SDK
|
|
2
2
|
|
|
3
|
-
This library is used to integrate SuprSend features like WebPush, Preferences in to your javascript client environments.
|
|
3
|
+
This library is used to integrate SuprSend features like WebPush, Preferences and InApp feed in to your javascript client environments.
|
|
4
4
|
|
|
5
|
-
> 📘
|
|
5
|
+
> 📘 Upgrading major version of SDK
|
|
6
6
|
>
|
|
7
|
-
> -
|
|
8
|
-
> - Added support for feed.
|
|
9
|
-
|
|
10
|
-
> 📘 Migrating to v2 from v1
|
|
11
|
-
>
|
|
12
|
-
> We have changed the web SDK authentication from workspace key-secret to public key and JWT based authentication. This is done to improve security in frontend applications.
|
|
13
|
-
>
|
|
14
|
-
> - Refer the v1 SDK [documentation](https://docs.suprsend.com/v1.2.1/docs/javascript-sdk)
|
|
15
|
-
> - For migrating to v2, follow this [guide](https://docs.suprsend.com/docs/js-migration-from-v1)
|
|
7
|
+
> - Please refer [migration](https://docs.suprsend.com/docs/js-migration-from-v1) guide if you are migrating the major version of SDK.
|
|
16
8
|
|
|
17
9
|
## Documentation
|
|
18
10
|
|
|
19
|
-
Checkout detailed [documentation](https://docs.suprsend.com/docs/javascript-sdk) for this library.
|
|
11
|
+
- Checkout detailed [documentation](https://docs.suprsend.com/docs/javascript-sdk) for this library.
|
|
12
|
+
- Refer type definitions for this library [here](https://github.com/suprsend/suprsend-web-sdk/blob/main/src/interface.ts).
|
|
20
13
|
|
|
21
14
|
## Installation
|
|
22
15
|
|
|
@@ -183,11 +176,113 @@ suprSendClient.emitter.on('preferences_error', (errorResp) => void);
|
|
|
183
176
|
|
|
184
177
|
## InApp Feed
|
|
185
178
|
|
|
186
|
-
|
|
179
|
+
### Initialise feed client
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const feedClient: Feed = suprSendClient.feed.initialize(options?: IFeedOptions);
|
|
183
|
+
|
|
184
|
+
interface IFeedOptions {
|
|
185
|
+
tenantId?: string;
|
|
186
|
+
pageSize?: number;
|
|
187
|
+
stores?: IStore[] | null;
|
|
188
|
+
host?: { socketHost?: string; apiHost?: string };
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Feed Client
|
|
193
|
+
|
|
194
|
+
#### Get Feed Data
|
|
195
|
+
|
|
196
|
+
This returns notification store which contains list of notifications and other meta data like page information etc. You can call this anytime to get updated store data.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const feedData: IFeedData = feedClient.data;
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### Initialize socket for realtime update
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
feedClient.initializeSocketConnection();
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Fetching notification data
|
|
209
|
+
|
|
210
|
+
This method will get first page of notifications from SuprSend server and set data in notification store.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
feedClient.fetch();
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### Fetch more notifications
|
|
217
|
+
|
|
218
|
+
This method will get next page of notifications from SuprSend server and set data in notification store.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
feedClient.fetchNextPage();
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### Listening for updates to store
|
|
225
|
+
|
|
226
|
+
Whenever there is update in notification store (ex: on new notification or existing notification state updated) this event is fired by library. You can listen to this event and update your local state so that UI of you application is refreshed.
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
feedClient.emitter.on('feed.store_update', (updatedStoreData: IFeedData) => {
|
|
230
|
+
// update your local state to refresh UI
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Listening for new notification
|
|
235
|
+
|
|
236
|
+
In case you want to show toast notification on receiving new notification you can use this listener
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
feedClient.emitter.on(
|
|
240
|
+
'feed.new_notification',
|
|
241
|
+
(notificationData: IRemoteNotification) => {
|
|
242
|
+
// your logic to trigger toast with new notification data
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
#### Removing Feed
|
|
248
|
+
|
|
249
|
+
This will remove feed client data and abort socket connection. Additionally calling `suprSendClient.reset` method during logout will also remove all feedClient instances attached SuprSend client instance.
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
feedClient.remove();
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
#### Other methods
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
// If stores are used, this method will change active store
|
|
259
|
+
feedClient.changeActiveStore(storeId: string)
|
|
260
|
+
|
|
261
|
+
// mark notification as seen
|
|
262
|
+
await feedClient.markAsSeen(notificationId: string)
|
|
263
|
+
|
|
264
|
+
// mark notification as read
|
|
265
|
+
await feedClient.markAsRead(notificationId: string)
|
|
266
|
+
|
|
267
|
+
// mark notification as unread
|
|
268
|
+
await feedClient.markAsUnread(notificationId: string)
|
|
269
|
+
|
|
270
|
+
// mark notification as archived
|
|
271
|
+
await feedClient.markAsArchived(notificationId: string)
|
|
272
|
+
|
|
273
|
+
// mark notification as interacted
|
|
274
|
+
await feedClient.markAsInteracted(notificationId: string)
|
|
275
|
+
|
|
276
|
+
// bulk mark all notifications as read
|
|
277
|
+
await feedClient.markAllAsRead()
|
|
278
|
+
|
|
279
|
+
// bulk mark given notification id's as seen
|
|
280
|
+
await feedClient.markBulkAsSeen(notificationIds: string[])
|
|
281
|
+
```
|
|
187
282
|
|
|
188
283
|
## Response Structure
|
|
189
284
|
|
|
190
|
-
|
|
285
|
+
Most of the methods in this library return `Promise<ApiResponse>`
|
|
191
286
|
|
|
192
287
|
```typescript
|
|
193
288
|
interface ApiResponse {
|