@suprsend/web-sdk 3.0.1 → 3.0.3

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 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
- > 📘 Migrating to v3 from v2
5
+ > 📘 Upgrading major version of SDK
6
6
  >
7
- > - SuprSend class export has been changed from default export to named export.
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
 
@@ -137,7 +130,7 @@ Create `serviceworker.js` file such that it should be publicly accessible from `
137
130
 
138
131
  ```javascript
139
132
  importScripts(
140
- 'https://cdn.jsdelivr.net/npm/@suprsend/web-sdk@2.0.0/public/serviceworker.min.js'
133
+ 'https://cdn.jsdelivr.net/npm/@suprsend/web-sdk@3.0.3/public/serviceworker.min.js'
141
134
  );
142
135
 
143
136
  initSuprSend(publicApiKey);
@@ -183,11 +176,117 @@ suprSendClient.emitter.on('preferences_error', (errorResp) => void);
183
176
 
184
177
  ## InApp Feed
185
178
 
186
- Documentation is yet to be added.
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
+ // Used to reset badge count which is shown on bell icon. This count is latest notifications that user received from the last he opened inbox popup.
262
+ // call this on click of bell icon
263
+ feedClient.resetBadgeCount()
264
+
265
+ // mark notification as seen
266
+ await feedClient.markAsSeen(notificationId: string)
267
+
268
+ // mark notification as read
269
+ await feedClient.markAsRead(notificationId: string)
270
+
271
+ // mark notification as unread
272
+ await feedClient.markAsUnread(notificationId: string)
273
+
274
+ // mark notification as archived
275
+ await feedClient.markAsArchived(notificationId: string)
276
+
277
+ // mark notification as interacted
278
+ await feedClient.markAsInteracted(notificationId: string)
279
+
280
+ // bulk mark all notifications as read
281
+ await feedClient.markAllAsRead()
282
+
283
+ // bulk mark given notification id's as seen
284
+ await feedClient.markBulkAsSeen(notificationIds: string[])
285
+ ```
187
286
 
188
287
  ## Response Structure
189
288
 
190
- Almost all methods of this library return `Promise<ApiResponse>`
289
+ Most of the methods in this library return `Promise<ApiResponse>`
191
290
 
192
291
  ```typescript
193
292
  interface ApiResponse {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "The client side javascript library for interacting with SuprSend",
5
5
  "author": "SuprSend Developers",
6
6
  "type": "module",
@@ -74,7 +74,7 @@ function callSSApi(body, method = 'post') {
74
74
  function initSuprSend(key, options) {
75
75
  suprsendConfig.publicApiKey = key;
76
76
 
77
- if (options.host) {
77
+ if (options && options.host) {
78
78
  suprsendConfig.host = options.host;
79
79
  }
80
80
  }