@streamlayer/sdk-web-notifications 0.13.3 → 0.13.5

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.
@@ -11,19 +11,18 @@ export type NotificationData = {
11
11
  predictionResult?: boolean;
12
12
  correct?: boolean;
13
13
  correctAnswerTitle?: string;
14
+ questionTitle?: string;
14
15
  };
15
16
  insight?: InstantView;
16
- onboarding?: GameSettings;
17
+ onboarding?: GameSettings & {
18
+ instantOpen?: boolean;
19
+ };
17
20
  tweet?: {
18
21
  title: string;
19
22
  image: string;
20
23
  body: string;
21
- account: {
22
- image: string;
23
- name: string;
24
- userName: string;
25
- verified: boolean;
26
- };
24
+ account: string;
25
+ accountVerified: boolean;
27
26
  };
28
27
  };
29
28
  export declare enum NotificationType {
@@ -41,6 +40,7 @@ export type Notification<M extends Record<string, Function> = never> = {
41
40
  methods?: M;
42
41
  data: NotificationData;
43
42
  id: string;
43
+ persistent?: boolean;
44
44
  };
45
45
  /**
46
46
  * @description app notifications (inapp)
@@ -50,7 +50,7 @@ export declare class Notifications {
50
50
  private storage;
51
51
  constructor(options?: Partial<NotificationsQueueOptions>);
52
52
  add: (notification: Notification) => void;
53
- close: (notificationId: string) => void;
53
+ close: (notificationId: string, markAsViewed?: boolean) => void;
54
54
  getQueueStore: () => import("nanostores").WritableAtom<Map<string, Notification> | undefined>;
55
55
  markAsViewed: (notificationId: string) => void;
56
56
  }
@@ -22,9 +22,11 @@ export class Notifications {
22
22
  this.queue.addToQueue(notification);
23
23
  }
24
24
  };
25
- close = (notificationId) => {
25
+ close = (notificationId, markAsViewed = true) => {
26
26
  this.queue.closeNotification(notificationId);
27
- this.markAsViewed(notificationId);
27
+ if (markAsViewed) {
28
+ this.markAsViewed(notificationId);
29
+ }
28
30
  };
29
31
  getQueueStore = () => {
30
32
  return this.queue.notificationsList;
@@ -42,8 +42,27 @@ export class NotificationsQueue {
42
42
  },
43
43
  });
44
44
  this.waitingQueue.add(notification.id);
45
- this.logger.debug({ notification }, 'notification added to waiting queue');
46
- this.tickWaitingQueue();
45
+ /**
46
+ * Hide an oldest notification if the active queue is full,
47
+ * and show a new notification on the next tick
48
+ */
49
+ if (this.activeQueue.size === this.options.concurrency) {
50
+ const [job] = this.activeQueue;
51
+ const notification = this.store.get(job);
52
+ if (notification?.persistent !== true) {
53
+ this.closeNotification(job);
54
+ }
55
+ else {
56
+ const [job] = this.waitingQueue;
57
+ if (this.waitingQueue.size > 1) {
58
+ this.closeNotification(job);
59
+ }
60
+ this.tickWaitingQueue();
61
+ }
62
+ }
63
+ else {
64
+ this.tickWaitingQueue();
65
+ }
47
66
  };
48
67
  tickWaitingQueue = () => {
49
68
  if (this.activeQueue.size < this.options.concurrency) {
@@ -89,7 +108,9 @@ export class NotificationsQueue {
89
108
  const prevQueue = new Map(this.notifications.getValue());
90
109
  const notification = prevQueue.get(notificationId);
91
110
  if (notification) {
92
- notification.hiding = true;
111
+ // do not hide notification if we have more than one notification in waiting queue,
112
+ // because we need to show next notification immediately
113
+ notification.hiding = !(this.waitingQueue.size >= this.options.concurrency);
93
114
  this.notifications.setValue(prevQueue);
94
115
  const timeout = setTimeout(() => {
95
116
  const prevQueue = new Map(this.notifications.getValue());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamlayer/sdk-web-notifications",
3
- "version": "0.13.3",
3
+ "version": "0.13.5",
4
4
  "type": "module",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
@@ -9,10 +9,10 @@
9
9
  "package.json"
10
10
  ],
11
11
  "peerDependencies": {
12
- "@streamlayer/sdk-web-interfaces": "^0.0.1",
13
- "@streamlayer/sdk-web-types": "^0.0.1",
14
- "@streamlayer/sdk-web-logger": "^0.0.4",
15
- "@streamlayer/sdk-web-storage": "^0.0.4"
12
+ "@streamlayer/sdk-web-interfaces": "^0.19.0",
13
+ "@streamlayer/sdk-web-logger": "^0.5.11",
14
+ "@streamlayer/sdk-web-storage": "^0.3.11",
15
+ "@streamlayer/sdk-web-types": "^0.21.0"
16
16
  },
17
17
  "exports": {
18
18
  ".": {
@@ -22,10 +22,10 @@
22
22
  }
23
23
  },
24
24
  "devDependencies": {
25
+ "@nx/playwright": "^17.2.8",
26
+ "@nx/webpack": "^17.2.8",
27
+ "@playwright/test": "^1.41.1",
25
28
  "tslib": "^2.6.2",
26
- "@nx/playwright": "17.1.1",
27
- "@playwright/test": "^1.39.0",
28
- "@nx/webpack": "17.0.3",
29
29
  "webpack": "^5.89.0"
30
30
  }
31
31
  }