@streamlayer/feature-gamification 0.33.3 → 0.33.4
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/onboarding.js +93 -90
- package/lib/storage.js +1 -1
- package/package.json +2 -2
package/lib/onboarding.js
CHANGED
|
@@ -19,44 +19,94 @@ export var OnboardingStatus;
|
|
|
19
19
|
OnboardingStatus["Disabled"] = "disabled";
|
|
20
20
|
OnboardingStatus["Unavailable"] = "unavailable";
|
|
21
21
|
})(OnboardingStatus || (OnboardingStatus = {}));
|
|
22
|
+
const showOnboardingInApp = (service, background, notifications, storage) => {
|
|
23
|
+
const { inplayGame } = service.featureSettings.get();
|
|
24
|
+
const notificationId = background.getCurrentSessionId({ prefix: 'onboarding' });
|
|
25
|
+
if (inplayGame) {
|
|
26
|
+
notifications.add({
|
|
27
|
+
type: NotificationType.ONBOARDING,
|
|
28
|
+
id: notificationId,
|
|
29
|
+
action: service.openFeature,
|
|
30
|
+
close: () => {
|
|
31
|
+
notifications.markAsViewed(notificationId);
|
|
32
|
+
},
|
|
33
|
+
delay: 1000,
|
|
34
|
+
autoHideDuration: 1000000,
|
|
35
|
+
data: {
|
|
36
|
+
questionType: QuestionType.UNSET,
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
onboarding: {
|
|
40
|
+
...inplayGame,
|
|
41
|
+
instantOpen: !storage.getOnboardingInstantOpen({
|
|
42
|
+
userId: background.userId.get() || '',
|
|
43
|
+
organizationId: background.organizationId.get() || '',
|
|
44
|
+
eventId: background.slStreamId.get() || '',
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* check onboarding status, sync with browser cache
|
|
53
|
+
* retrieve onboarding settings from api
|
|
54
|
+
*/
|
|
55
|
+
const onboardingProcess = ($store, background, service, storage, listeners) => {
|
|
56
|
+
try {
|
|
57
|
+
const userId = background.userId.get();
|
|
58
|
+
if (!userId) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const onboardingStatus = storage.getOnboardingStatus({
|
|
62
|
+
userId,
|
|
63
|
+
organizationId: background.organizationId.get() || '',
|
|
64
|
+
eventId: background.slStreamId.get() || '',
|
|
65
|
+
});
|
|
66
|
+
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
67
|
+
$store.set(OnboardingStatus.Completed);
|
|
68
|
+
for (const cancel of listeners) {
|
|
69
|
+
cancel();
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const moderation = background.moderation.getStore().value?.data;
|
|
74
|
+
const inplayGame = service.featureSettings.get().inplayGame;
|
|
75
|
+
if (moderation === undefined || inplayGame === undefined) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const onboardingEnabled = !!moderation?.options?.onboardingEnabled && inplayGame?.enable;
|
|
79
|
+
const optIn = !!inplayGame?.titleCard?.optIn;
|
|
80
|
+
if (onboardingEnabled) {
|
|
81
|
+
if (optIn) {
|
|
82
|
+
$store.set(OnboardingStatus.Required);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
$store.set(OnboardingStatus.Optional);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (optIn) {
|
|
90
|
+
$store.set(OnboardingStatus.Unavailable);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
$store.set(OnboardingStatus.Disabled);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error(error);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
22
101
|
export const onboarding = (service, background, transport, notifications) => {
|
|
23
102
|
const storage = new GamificationStorage();
|
|
24
103
|
const $store = createSingleStore(OnboardingStatus.Unset);
|
|
25
|
-
const showOnboardingInApp = () => {
|
|
26
|
-
const { inplayGame } = service.featureSettings.get();
|
|
27
|
-
const notificationId = background.getCurrentSessionId({ prefix: 'onboarding' });
|
|
28
|
-
if (inplayGame) {
|
|
29
|
-
notifications.add({
|
|
30
|
-
type: NotificationType.ONBOARDING,
|
|
31
|
-
id: notificationId,
|
|
32
|
-
action: service.openFeature,
|
|
33
|
-
close: () => {
|
|
34
|
-
notifications.markAsViewed(notificationId);
|
|
35
|
-
},
|
|
36
|
-
delay: 1000,
|
|
37
|
-
autoHideDuration: 1000000,
|
|
38
|
-
data: {
|
|
39
|
-
questionType: QuestionType.UNSET,
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
onboarding: {
|
|
43
|
-
...inplayGame,
|
|
44
|
-
instantOpen: !storage.getOnboardingInstantOpen({
|
|
45
|
-
userId: background.userId.get() || '',
|
|
46
|
-
organizationId: background.organizationId.get() || '',
|
|
47
|
-
eventId: background.slStreamId.get() || '',
|
|
48
|
-
}),
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
104
|
$store.subscribe((onboardingStatus) => {
|
|
55
105
|
if (onboardingStatus === OnboardingStatus.Unset) {
|
|
56
106
|
return;
|
|
57
107
|
}
|
|
58
108
|
if (onboardingStatus === OnboardingStatus.Optional || onboardingStatus === OnboardingStatus.Required) {
|
|
59
|
-
showOnboardingInApp();
|
|
109
|
+
showOnboardingInApp(service, background, notifications, storage);
|
|
60
110
|
}
|
|
61
111
|
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
62
112
|
background.activeQuestionId.invalidate();
|
|
@@ -67,72 +117,25 @@ export const onboarding = (service, background, transport, notifications) => {
|
|
|
67
117
|
eventId: background.slStreamId.get() || '',
|
|
68
118
|
});
|
|
69
119
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const onboardingProcess = async () => {
|
|
75
|
-
try {
|
|
76
|
-
const userId = background.userId.get();
|
|
77
|
-
if (!userId) {
|
|
78
|
-
$store.set(OnboardingStatus.Unset);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const onboardingStatus = storage.getOnboardingStatus({
|
|
82
|
-
userId,
|
|
83
|
-
organizationId: background.organizationId.get() || '',
|
|
84
|
-
eventId: background.slStreamId.get() || '',
|
|
85
|
-
});
|
|
86
|
-
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
87
|
-
$store.set(OnboardingStatus.Completed);
|
|
88
|
-
}
|
|
89
|
-
const moderation = await background.moderation.getValue();
|
|
90
|
-
if ($store.get() === OnboardingStatus.Completed) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const onboardingEnabled = !!moderation?.options?.onboardingEnabled;
|
|
94
|
-
const optIn = !!service.featureSettings.get().inplayGame?.titleCard?.optIn;
|
|
95
|
-
if (moderation === undefined || service.featureSettings.get() === undefined) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (onboardingEnabled) {
|
|
99
|
-
if (optIn) {
|
|
100
|
-
$store.set(OnboardingStatus.Required);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
$store.set(OnboardingStatus.Optional);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
if (optIn) {
|
|
108
|
-
$store.set(OnboardingStatus.Unavailable);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
$store.set(OnboardingStatus.Disabled);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
console.error(error);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
void onboardingProcess().then(() => {
|
|
120
|
-
background.userId.listen((userId) => {
|
|
120
|
+
const listeners = [];
|
|
121
|
+
onboardingProcess($store, background, service, storage, listeners);
|
|
122
|
+
if ($store.get() !== OnboardingStatus.Completed) {
|
|
123
|
+
listeners.push(background.userId.listen((userId) => {
|
|
121
124
|
if (userId) {
|
|
122
|
-
void onboardingProcess();
|
|
125
|
+
void onboardingProcess($store, background, service, storage, listeners);
|
|
123
126
|
}
|
|
124
|
-
});
|
|
125
|
-
background.moderation.listen((value) => {
|
|
127
|
+
}));
|
|
128
|
+
listeners.push(background.moderation.listen((value) => {
|
|
126
129
|
if (value.data) {
|
|
127
|
-
void onboardingProcess();
|
|
130
|
+
void onboardingProcess($store, background, service, storage, listeners);
|
|
128
131
|
}
|
|
129
|
-
});
|
|
130
|
-
service.featureSettings.listen((value) => {
|
|
132
|
+
}));
|
|
133
|
+
listeners.push(service.featureSettings.listen((value) => {
|
|
131
134
|
if (value) {
|
|
132
|
-
void onboardingProcess();
|
|
135
|
+
void onboardingProcess($store, background, service, storage, listeners);
|
|
133
136
|
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
136
139
|
const submitInplay = async () => {
|
|
137
140
|
const eventId = background.slStreamId.get();
|
|
138
141
|
if (eventId) {
|
package/lib/storage.js
CHANGED
|
@@ -16,7 +16,7 @@ export class GamificationStorage extends Storage {
|
|
|
16
16
|
};
|
|
17
17
|
setOnboardingInstantOpen = ({ userId, eventId, organizationId }) => {
|
|
18
18
|
const key = this.generateKey([KEY_PREFIX.ONBOARDING_IO, organizationId, userId, eventId]);
|
|
19
|
-
window.sessionStorage.setItem(key, '
|
|
19
|
+
window.sessionStorage.setItem(key, '1');
|
|
20
20
|
};
|
|
21
21
|
getOnboardingInstantOpen = ({ userId, eventId, organizationId }) => {
|
|
22
22
|
const key = this.generateKey([KEY_PREFIX.ONBOARDING_IO, organizationId, userId, eventId]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.4",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
6
|
"@streamlayer/sl-eslib": "^5.61.1",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"@streamlayer/sdk-web-core": "^0.0.1",
|
|
11
11
|
"@streamlayer/sdk-web-interfaces": "^0.18.21",
|
|
12
12
|
"@streamlayer/sdk-web-logger": "^0.0.1",
|
|
13
|
-
"@streamlayer/sdk-web-notifications": "^0.0.6",
|
|
14
13
|
"@streamlayer/sdk-web-storage": "^0.0.4",
|
|
14
|
+
"@streamlayer/sdk-web-notifications": "^0.0.6",
|
|
15
15
|
"@streamlayer/sdk-web-types": "^0.1.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|