@streamlayer/sdk-web-notifications 0.14.1 → 0.15.0
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/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/notifications.d.ts +6 -4
- package/lib/notifications.js +29 -0
- package/lib/queue/index.d.ts +1 -1
- package/lib/queue/index.js +1 -0
- package/package.json +7 -7
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -4,8 +4,9 @@ export { NotificationType, Notifications } from './notifications';
|
|
|
4
4
|
* notifications plugin, connect notifications to sdk
|
|
5
5
|
*/
|
|
6
6
|
export const notifications = (instance, opts, done) => {
|
|
7
|
-
instance.notifications = new Notifications();
|
|
7
|
+
instance.notifications = new Notifications(undefined);
|
|
8
8
|
instance.addNotification = instance.notifications.add;
|
|
9
9
|
instance.sdk.getNotificationsStore = () => instance.notifications.getQueueStore();
|
|
10
|
+
instance.sdk.getActiveNotification = () => instance.notifications.getActiveNotification();
|
|
10
11
|
done();
|
|
11
12
|
};
|
package/lib/notifications.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { InstantView, QuestionType, GameSettings, TweetHistory
|
|
1
|
+
import { InstantView, QuestionType, GameSettings, TweetHistory } from '@streamlayer/sdk-web-types';
|
|
2
2
|
import { NotificationsQueue, NotificationsQueueOptions } from './queue';
|
|
3
3
|
export type NotificationData = {
|
|
4
|
+
questionId: string;
|
|
4
5
|
questionType: QuestionType;
|
|
5
6
|
question?: {
|
|
6
7
|
title: string;
|
|
@@ -13,9 +14,7 @@ export type NotificationData = {
|
|
|
13
14
|
correctAnswerTitle?: string;
|
|
14
15
|
questionTitle?: string;
|
|
15
16
|
};
|
|
16
|
-
insight?: InstantView
|
|
17
|
-
imageMode?: QuestionImages;
|
|
18
|
-
};
|
|
17
|
+
insight?: InstantView;
|
|
19
18
|
onboarding?: GameSettings & {
|
|
20
19
|
instantOpen?: boolean;
|
|
21
20
|
};
|
|
@@ -26,6 +25,7 @@ export type NotificationData = {
|
|
|
26
25
|
account: string;
|
|
27
26
|
accountVerified: boolean;
|
|
28
27
|
tweet: TweetHistory['tweet'] | undefined;
|
|
28
|
+
tweetId: string;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
export declare enum NotificationType {
|
|
@@ -41,6 +41,7 @@ export type Notification<M extends Record<string, Function> = never> = {
|
|
|
41
41
|
action?: (...args: unknown[]) => void;
|
|
42
42
|
close?: (...args: unknown[]) => void;
|
|
43
43
|
methods?: M;
|
|
44
|
+
emitEvent?: boolean;
|
|
44
45
|
data: NotificationData;
|
|
45
46
|
id: string;
|
|
46
47
|
persistent?: boolean;
|
|
@@ -54,6 +55,7 @@ export declare class Notifications {
|
|
|
54
55
|
constructor(options?: Partial<NotificationsQueueOptions>);
|
|
55
56
|
add: (notification: Notification) => void;
|
|
56
57
|
close: (notificationId: string, markAsViewed?: boolean) => void;
|
|
58
|
+
getActiveNotification: () => Notification | null;
|
|
57
59
|
getQueueStore: () => import("nanostores").WritableAtom<Map<string, Notification> | undefined>;
|
|
58
60
|
markAsViewed: (notificationId: string) => void;
|
|
59
61
|
}
|
package/lib/notifications.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { eventBus } from '@streamlayer/sdk-web-interfaces';
|
|
1
2
|
import { NotificationsQueue } from './queue';
|
|
2
3
|
import { NotificationStorage } from './storage';
|
|
3
4
|
export var NotificationType;
|
|
@@ -19,6 +20,21 @@ export class Notifications {
|
|
|
19
20
|
add = (notification) => {
|
|
20
21
|
const isViewed = this.storage.isOpened(notification.id);
|
|
21
22
|
if (!isViewed) {
|
|
23
|
+
if (notification.data && notification.emitEvent) {
|
|
24
|
+
const action = notification.action;
|
|
25
|
+
notification.action = (...args) => {
|
|
26
|
+
if (action) {
|
|
27
|
+
action(...args);
|
|
28
|
+
}
|
|
29
|
+
eventBus.emit('notification', {
|
|
30
|
+
action: 'opened',
|
|
31
|
+
payload: {
|
|
32
|
+
questionId: notification.data.questionId,
|
|
33
|
+
questionType: notification.data.questionType,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
22
38
|
this.queue.addToQueue(notification);
|
|
23
39
|
}
|
|
24
40
|
};
|
|
@@ -28,6 +44,19 @@ export class Notifications {
|
|
|
28
44
|
this.markAsViewed(notificationId);
|
|
29
45
|
}
|
|
30
46
|
};
|
|
47
|
+
getActiveNotification = () => {
|
|
48
|
+
const notifications = this.queue.notificationsList.get();
|
|
49
|
+
if (!notifications?.size) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
for (const notification of notifications.values()) {
|
|
53
|
+
if (notification.type === NotificationType.ONBOARDING) {
|
|
54
|
+
return notification;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const notification = notifications.values().next().value;
|
|
58
|
+
return notification;
|
|
59
|
+
};
|
|
31
60
|
getQueueStore = () => {
|
|
32
61
|
return this.queue.notificationsList;
|
|
33
62
|
};
|
package/lib/queue/index.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export declare class NotificationsQueue {
|
|
|
18
18
|
addToQueue: (notification: Notification) => void;
|
|
19
19
|
tickWaitingQueue: () => void;
|
|
20
20
|
tickActiveQueue: (notificationId: string) => void;
|
|
21
|
-
closeNotification: (notificationId: string) =>
|
|
21
|
+
closeNotification: (notificationId: string) => Notification | undefined;
|
|
22
22
|
}
|
package/lib/queue/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/sdk-web-notifications",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
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.
|
|
13
|
-
"@streamlayer/sdk-web-logger": "^0.5.
|
|
14
|
-
"@streamlayer/sdk-web-storage": "^0.4.
|
|
15
|
-
"@streamlayer/sdk-web-types": "^0.
|
|
12
|
+
"@streamlayer/sdk-web-interfaces": "^0.21.0",
|
|
13
|
+
"@streamlayer/sdk-web-logger": "^0.5.18",
|
|
14
|
+
"@streamlayer/sdk-web-storage": "^0.4.5",
|
|
15
|
+
"@streamlayer/sdk-web-types": "^0.23.0"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@nx/playwright": "
|
|
26
|
-
"@nx/webpack": "
|
|
25
|
+
"@nx/playwright": "17.3.0",
|
|
26
|
+
"@nx/webpack": "17.3.0",
|
|
27
27
|
"@playwright/test": "^1.41.1",
|
|
28
28
|
"tslib": "^2.6.2",
|
|
29
29
|
"webpack": "^5.90.0"
|