@suprsend/web-sdk 3.0.0 → 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.
Files changed (2) hide show
  1. package/README.md +113 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,17 +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
- > 📘 This is v2 version of @suprsend/web-sdk
5
+ > 📘 Upgrading major version of SDK
6
6
  >
7
- > 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.
8
- >
9
- > - Refer the v1 SDK [documentation](https://docs.suprsend.com/v1.2.1/docs/javascript-sdk)
10
- > - 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.
11
8
 
12
9
  ## Documentation
13
10
 
14
- 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).
15
13
 
16
14
  ## Installation
17
15
 
@@ -30,7 +28,7 @@ yarn add @suprsend/web-sdk@latest
30
28
  Create suprSendClient instance and use same instance to access all the methods of SuprSend library.
31
29
 
32
30
  ```typescript
33
- import SuprSend from '@suprsend/web-sdk';
31
+ import {SuprSend} from '@suprsend/web-sdk';
34
32
 
35
33
  export const suprSendClient = new SuprSend(publicApiKey: string);
36
34
  ```
@@ -176,9 +174,115 @@ suprSendClient.emitter.on('preferences_updated', (preferenceDataResp) => void);
176
174
  suprSendClient.emitter.on('preferences_error', (errorResp) => void);
177
175
  ```
178
176
 
177
+ ## InApp Feed
178
+
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
+ ```
282
+
179
283
  ## Response Structure
180
284
 
181
- Almost all methods of this library return `Promise<ApiResponse>`
285
+ Most of the methods in this library return `Promise<ApiResponse>`
182
286
 
183
287
  ```typescript
184
288
  interface ApiResponse {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "The client side javascript library for interacting with SuprSend",
5
5
  "author": "SuprSend Developers",
6
6
  "type": "module",