@streamlayer/feature-gamification 0.33.0 → 0.33.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.
- package/lib/deepLink.js +6 -3
- package/lib/onboarding.js +62 -41
- package/lib/storage.d.ts +2 -0
- package/lib/storage.js +9 -0
- package/package.json +2 -2
package/lib/deepLink.js
CHANGED
|
@@ -5,9 +5,9 @@ export const deepLink = (transport, $eventId, $userId) => {
|
|
|
5
5
|
const $store = createMapStore({});
|
|
6
6
|
onMount($store, () => {
|
|
7
7
|
const $branchLink = $deepLink(transport, [$eventId]);
|
|
8
|
-
const cancel = $branchLink.subscribe(async ({ data }) => {
|
|
9
|
-
const mobileDeepLink = data?.url;
|
|
10
|
-
if (mobileDeepLink) {
|
|
8
|
+
const cancel = $branchLink.subscribe(async ({ data, error, loading }) => {
|
|
9
|
+
const mobileDeepLink = error ? 'https://masters.com' : data?.url;
|
|
10
|
+
if (!loading && mobileDeepLink) {
|
|
11
11
|
$store.setKey('loading', true);
|
|
12
12
|
const desktopLink = `${window.location.host + window.location.pathname}%23sl_eid=${$eventId.get()}&sl_uid=${$userId.get()}`;
|
|
13
13
|
const shortLink = await generateShortLink(transport, { web: desktopLink, mobile: mobileDeepLink });
|
|
@@ -16,6 +16,9 @@ export const deepLink = (transport, $eventId, $userId) => {
|
|
|
16
16
|
loading: false,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
else {
|
|
20
|
+
$store.setKey('loading', true);
|
|
21
|
+
}
|
|
19
22
|
});
|
|
20
23
|
return cancel;
|
|
21
24
|
});
|
package/lib/onboarding.js
CHANGED
|
@@ -39,70 +39,91 @@ export const onboarding = (service, background, transport, notifications) => {
|
|
|
39
39
|
questionType: QuestionType.UNSET,
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
41
|
// @ts-ignore
|
|
42
|
-
onboarding: {
|
|
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
|
+
},
|
|
43
50
|
},
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
53
|
};
|
|
47
54
|
$store.subscribe((onboardingStatus) => {
|
|
48
|
-
if (onboardingStatus === OnboardingStatus.
|
|
55
|
+
if (onboardingStatus === OnboardingStatus.Unset) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (onboardingStatus === OnboardingStatus.Optional || onboardingStatus === OnboardingStatus.Required) {
|
|
49
59
|
showOnboardingInApp();
|
|
50
60
|
}
|
|
51
61
|
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
52
62
|
background.activeQuestionId.invalidate();
|
|
53
63
|
}
|
|
64
|
+
storage.setOnboardingInstantOpen({
|
|
65
|
+
userId: background.userId.get() || '',
|
|
66
|
+
organizationId: background.organizationId.get() || '',
|
|
67
|
+
eventId: background.slStreamId.get() || '',
|
|
68
|
+
});
|
|
54
69
|
});
|
|
55
70
|
/**
|
|
56
71
|
* check onboarding status, sync with browser cache
|
|
57
72
|
* retrieve onboarding settings from api
|
|
58
73
|
*/
|
|
59
74
|
const onboardingProcess = async () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const onboardingStatus = storage.getOnboardingStatus({
|
|
66
|
-
userId,
|
|
67
|
-
organizationId: background.organizationId.get() || '',
|
|
68
|
-
eventId: background.slStreamId.get() || '',
|
|
69
|
-
});
|
|
70
|
-
if (onboardingStatus === OnboardingStatus.Completed) {
|
|
71
|
-
$store.set(OnboardingStatus.Completed);
|
|
72
|
-
}
|
|
73
|
-
const moderation = await background.moderation.getValue();
|
|
74
|
-
if ($store.get() === OnboardingStatus.Completed) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const onboardingEnabled = !!(moderation?.options?.onboardingEnabled && service.featureSettings.get().inplayGame?.onboarding?.completed);
|
|
78
|
-
const optIn = !!service.featureSettings.get().inplayGame?.titleCard?.optIn;
|
|
79
|
-
if (onboardingEnabled) {
|
|
80
|
-
if (optIn) {
|
|
81
|
-
$store.set(OnboardingStatus.Required);
|
|
75
|
+
try {
|
|
76
|
+
const userId = background.userId.get();
|
|
77
|
+
if (!userId) {
|
|
78
|
+
$store.set(OnboardingStatus.Unset);
|
|
79
|
+
return;
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
|
|
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);
|
|
85
88
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
const moderation = await background.moderation.getValue();
|
|
90
|
+
if ($store.get() === OnboardingStatus.Completed) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const onboardingEnabled = !!(moderation?.options?.onboardingEnabled && service.featureSettings.get().inplayGame?.onboarding?.completed);
|
|
94
|
+
const optIn = !!service.featureSettings.get().inplayGame?.titleCard?.optIn;
|
|
95
|
+
if (onboardingEnabled) {
|
|
96
|
+
if (optIn) {
|
|
97
|
+
$store.set(OnboardingStatus.Required);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
$store.set(OnboardingStatus.Optional);
|
|
101
|
+
}
|
|
90
102
|
}
|
|
91
103
|
else {
|
|
92
|
-
|
|
104
|
+
if (optIn) {
|
|
105
|
+
$store.set(OnboardingStatus.Unavailable);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
$store.set(OnboardingStatus.Disabled);
|
|
109
|
+
}
|
|
93
110
|
}
|
|
94
111
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
background.userId.subscribe((userId) => {
|
|
98
|
-
if (userId) {
|
|
99
|
-
void onboardingProcess();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
background.moderation.subscribe((value) => {
|
|
103
|
-
if (value.data) {
|
|
104
|
-
void onboardingProcess();
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error(error);
|
|
105
114
|
}
|
|
115
|
+
};
|
|
116
|
+
void onboardingProcess().then(() => {
|
|
117
|
+
background.userId.listen((userId) => {
|
|
118
|
+
if (userId) {
|
|
119
|
+
void onboardingProcess();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
background.moderation.listen((value) => {
|
|
123
|
+
if (value.data) {
|
|
124
|
+
void onboardingProcess();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
106
127
|
});
|
|
107
128
|
const submitInplay = async () => {
|
|
108
129
|
const eventId = background.slStreamId.get();
|
package/lib/storage.d.ts
CHANGED
|
@@ -9,5 +9,7 @@ export declare class GamificationStorage extends Storage {
|
|
|
9
9
|
constructor();
|
|
10
10
|
saveOnboardingStatus: ({ userId, eventId, organizationId }: UserProps, status: OnboardingStatus) => void;
|
|
11
11
|
getOnboardingStatus: ({ userId, eventId, organizationId }: UserProps) => string | undefined;
|
|
12
|
+
setOnboardingInstantOpen: ({ userId, eventId, organizationId }: UserProps) => void;
|
|
13
|
+
getOnboardingInstantOpen: ({ userId, eventId, organizationId }: UserProps) => string | null;
|
|
12
14
|
}
|
|
13
15
|
export {};
|
package/lib/storage.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Storage } from '@streamlayer/sdk-web-storage';
|
|
|
2
2
|
var KEY_PREFIX;
|
|
3
3
|
(function (KEY_PREFIX) {
|
|
4
4
|
KEY_PREFIX["ONBOARDING"] = "onboarding";
|
|
5
|
+
KEY_PREFIX["ONBOARDING_IO"] = "onboarding_io";
|
|
5
6
|
})(KEY_PREFIX || (KEY_PREFIX = {}));
|
|
6
7
|
export class GamificationStorage extends Storage {
|
|
7
8
|
constructor() {
|
|
@@ -13,4 +14,12 @@ export class GamificationStorage extends Storage {
|
|
|
13
14
|
getOnboardingStatus = ({ userId, eventId, organizationId }) => {
|
|
14
15
|
return this.read(KEY_PREFIX.ONBOARDING, organizationId, userId, eventId);
|
|
15
16
|
};
|
|
17
|
+
setOnboardingInstantOpen = ({ userId, eventId, organizationId }) => {
|
|
18
|
+
const key = this.generateKey([KEY_PREFIX.ONBOARDING_IO, organizationId, userId, eventId]);
|
|
19
|
+
window.sessionStorage.setItem(key, 'true');
|
|
20
|
+
};
|
|
21
|
+
getOnboardingInstantOpen = ({ userId, eventId, organizationId }) => {
|
|
22
|
+
const key = this.generateKey([KEY_PREFIX.ONBOARDING_IO, organizationId, userId, eventId]);
|
|
23
|
+
return window.sessionStorage.getItem(key);
|
|
24
|
+
};
|
|
16
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
6
|
"@streamlayer/sl-eslib": "^5.61.1",
|
|
@@ -10,7 +10,7 @@
|
|
|
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.
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.0.6",
|
|
14
14
|
"@streamlayer/sdk-web-storage": "^0.0.4",
|
|
15
15
|
"@streamlayer/sdk-web-types": "^0.1.0"
|
|
16
16
|
},
|