@streamlayer/feature-gamification 1.16.2 → 1.16.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/advertisement/externalAd/index.js +9 -2
- package/lib/background.js +12 -6
- package/lib/gamification.js +2 -2
- package/lib/queries/index.d.ts +7 -1
- package/lib/queries/index.js +33 -24
- package/package.json +8 -8
|
@@ -64,10 +64,16 @@ export const gam = (adContainer, url) => {
|
|
|
64
64
|
if (!uuidValidate(deviceId)) {
|
|
65
65
|
deviceId = uuid5(`https://${deviceId}`, uuid5.URL);
|
|
66
66
|
}
|
|
67
|
+
if (!parsedUrl.searchParams.get('url')) {
|
|
68
|
+
parsedUrl.searchParams.set('url', 'https://streamlayer.io');
|
|
69
|
+
}
|
|
70
|
+
if (!parsedUrl.searchParams.get('description_url')) {
|
|
71
|
+
parsedUrl.searchParams.set('description_url', 'https://streamlayer.io');
|
|
72
|
+
}
|
|
67
73
|
request.adWillAutoPlay = parsedUrl.searchParams.get('vpa') === 'auto';
|
|
68
74
|
request.adWillPlayMuted = parsedUrl.searchParams.get('vpmute') === '1';
|
|
69
75
|
request.continuousPlayback = true;
|
|
70
|
-
request.descriptionUrl = parsedUrl.searchParams.get('description_url')
|
|
76
|
+
request.descriptionUrl = parsedUrl.searchParams.get('description_url');
|
|
71
77
|
request.iconsSupported = true;
|
|
72
78
|
request.sessionId = deviceId;
|
|
73
79
|
// Player support for VPAID 2.0, OMID 1.0, and SIMID 1.1
|
|
@@ -75,7 +81,6 @@ export const gam = (adContainer, url) => {
|
|
|
75
81
|
request.videoHeight = adContainer.clientHeight;
|
|
76
82
|
request.videoWidth = adContainer.clientWidth;
|
|
77
83
|
const nonceManager = await nonceLoader.loadNonceManager(request);
|
|
78
|
-
parsedUrl.searchParams.set('givn', nonceManager.getNonce());
|
|
79
84
|
if (parsedUrl.searchParams.get('is_lat') === '[placeholder]') {
|
|
80
85
|
parsedUrl.searchParams.set('is_lat', '1');
|
|
81
86
|
}
|
|
@@ -85,6 +90,8 @@ export const gam = (adContainer, url) => {
|
|
|
85
90
|
if (parsedUrl.searchParams.get('correlator') === '[placeholder]') {
|
|
86
91
|
parsedUrl.searchParams.set('correlator', sessionId);
|
|
87
92
|
}
|
|
93
|
+
parsedUrl.searchParams.set('wta', '1');
|
|
94
|
+
parsedUrl.searchParams.set('givn', nonceManager.getNonce());
|
|
88
95
|
return parsedUrl;
|
|
89
96
|
}
|
|
90
97
|
catch (adError) {
|
package/lib/background.js
CHANGED
|
@@ -74,7 +74,7 @@ export class GamificationBackground {
|
|
|
74
74
|
this.openedQuestion.updateExtendedQuestion(question);
|
|
75
75
|
if (question?.type === QuestionType.PREDICTION &&
|
|
76
76
|
(question.status === QuestionStatus.ACTIVE || question.status === QuestionStatus.RESOLVED)) {
|
|
77
|
-
const betPackData = this.betPack.getValues().data || {};
|
|
77
|
+
const betPackData = this.betPack.getValues().data?.data || {};
|
|
78
78
|
const betPackItem = betPackData?.[question.id];
|
|
79
79
|
if (betPackItem || Object.keys(betPackData).length < 5) {
|
|
80
80
|
const data = queries.$questionByUser(question.id, this.transport);
|
|
@@ -90,8 +90,11 @@ export class GamificationBackground {
|
|
|
90
90
|
data.invalidate();
|
|
91
91
|
});
|
|
92
92
|
this.betPack.getStore().mutate({
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
timestamp: Date.now(),
|
|
94
|
+
data: {
|
|
95
|
+
...betPackData,
|
|
96
|
+
[question.id]: extendedQuestion,
|
|
97
|
+
},
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
100
|
}
|
|
@@ -112,7 +115,7 @@ export class GamificationBackground {
|
|
|
112
115
|
const question = response.data?.attributes?.question;
|
|
113
116
|
if (question?.type === QuestionType.PREDICTION &&
|
|
114
117
|
(question.status === QuestionStatus.ACTIVE || question.status === QuestionStatus.RESOLVED)) {
|
|
115
|
-
const betPackData = this.betPack.getValues().data || {};
|
|
118
|
+
const betPackData = this.betPack.getValues().data?.data || {};
|
|
116
119
|
const betPackItem = betPackData?.[question.id];
|
|
117
120
|
if (betPackItem || Object.keys(betPackData).length < 5) {
|
|
118
121
|
const data = queries.$questionByUser(question.id, this.transport);
|
|
@@ -130,8 +133,11 @@ export class GamificationBackground {
|
|
|
130
133
|
});
|
|
131
134
|
// get extended question data and mark as dirty
|
|
132
135
|
this.betPack.getStore().mutate({
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
timestamp: Date.now(),
|
|
137
|
+
data: {
|
|
138
|
+
...betPackData,
|
|
139
|
+
[question.id]: extendedQuestion,
|
|
140
|
+
},
|
|
135
141
|
});
|
|
136
142
|
}
|
|
137
143
|
}
|
package/lib/gamification.js
CHANGED
|
@@ -360,7 +360,7 @@ export class Gamification extends AbstractFeature {
|
|
|
360
360
|
}
|
|
361
361
|
throw error;
|
|
362
362
|
}
|
|
363
|
-
const betPackList = { ...this.betPack.getValues().data };
|
|
363
|
+
const betPackList = { ...this.betPack.getValues().data?.data };
|
|
364
364
|
const question = betPackList?.[questionId];
|
|
365
365
|
if (question) {
|
|
366
366
|
eventBus.emit('poll', {
|
|
@@ -379,7 +379,7 @@ export class Gamification extends AbstractFeature {
|
|
|
379
379
|
}
|
|
380
380
|
return answer;
|
|
381
381
|
});
|
|
382
|
-
this.betPack.getStore().mutate(betPackList);
|
|
382
|
+
this.betPack.getStore().mutate({ data: betPackList, timestamp: Date.now() });
|
|
383
383
|
}
|
|
384
384
|
};
|
|
385
385
|
submitAnswer = async (questionId, answerId) => {
|
package/lib/queries/index.d.ts
CHANGED
|
@@ -434,4 +434,10 @@ export declare const $activePromotionId: ($slStreamId: ReadableAtom<string | und
|
|
|
434
434
|
export { $userSummary, $leaderboardList } from './leaderboard';
|
|
435
435
|
export { $friends } from './friends';
|
|
436
436
|
export { $moderation } from './moderation';
|
|
437
|
-
export declare const $betPack: ($slStreamId: ReadableAtom<string | undefined>, $slUserId: ReadableAtom<string | undefined>, $slOrganizationId: ReadableAtom<string | undefined>, storage: GamificationStorage, transport: Transport) => import("@nanostores/query").FetcherStore<
|
|
437
|
+
export declare const $betPack: ($slStreamId: ReadableAtom<string | undefined>, $slUserId: ReadableAtom<string | undefined>, $slOrganizationId: ReadableAtom<string | undefined>, storage: GamificationStorage, transport: Transport) => import("@nanostores/query").FetcherStore<{
|
|
438
|
+
timestamp: number;
|
|
439
|
+
data: null;
|
|
440
|
+
} | {
|
|
441
|
+
timestamp: number;
|
|
442
|
+
data: Record<string, import("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>>;
|
|
443
|
+
}, any>;
|
package/lib/queries/index.js
CHANGED
|
@@ -175,7 +175,10 @@ export const $betPack = ($slStreamId, $slUserId, $slOrganizationId, storage, tra
|
|
|
175
175
|
return transport.nanoquery.createFetcherStore(queryKey, {
|
|
176
176
|
fetcher: async (_, __, slStreamId, userId, organizationId) => {
|
|
177
177
|
if (!slStreamId || !userId || !organizationId) {
|
|
178
|
-
return
|
|
178
|
+
return {
|
|
179
|
+
timestamp: Date.now(),
|
|
180
|
+
data: null,
|
|
181
|
+
};
|
|
179
182
|
}
|
|
180
183
|
const res = await client.betPack({
|
|
181
184
|
eventId: slStreamId,
|
|
@@ -188,30 +191,36 @@ export const $betPack = ($slStreamId, $slUserId, $slOrganizationId, storage, tra
|
|
|
188
191
|
},
|
|
189
192
|
});
|
|
190
193
|
if (!res.data || !res.data.length) {
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const question = item?.attributes?.question;
|
|
195
|
-
if (!question?.id) {
|
|
196
|
-
return acc;
|
|
197
|
-
}
|
|
198
|
-
const flags = {
|
|
199
|
-
eventId: slStreamId,
|
|
200
|
-
userId: userId,
|
|
201
|
-
organizationId: organizationId,
|
|
194
|
+
return {
|
|
195
|
+
timestamp: Date.now(),
|
|
196
|
+
data: null,
|
|
202
197
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
timestamp: Date.now(),
|
|
201
|
+
data: res.data?.reduce((acc, item) => {
|
|
202
|
+
const question = item?.attributes?.question;
|
|
203
|
+
if (!question?.id) {
|
|
204
|
+
return acc;
|
|
205
|
+
}
|
|
206
|
+
const flags = {
|
|
207
|
+
eventId: slStreamId,
|
|
208
|
+
userId: userId,
|
|
209
|
+
organizationId: organizationId,
|
|
210
|
+
};
|
|
211
|
+
if (!storage.isBetPackQuestionReceived(flags, question.id)) {
|
|
212
|
+
eventBus.emit('poll', {
|
|
213
|
+
action: 'received',
|
|
214
|
+
payload: {
|
|
215
|
+
questionId: question.id,
|
|
216
|
+
questionType: question.type,
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
storage.saveBetPackQuestionReceived(flags, question.id);
|
|
220
|
+
}
|
|
221
|
+
return { ...acc, [question.id]: question };
|
|
222
|
+
}, {}),
|
|
223
|
+
};
|
|
215
224
|
},
|
|
216
225
|
dedupeTime: 0,
|
|
217
226
|
refetchInterval: 0,
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.4",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.10.0",
|
|
6
6
|
"@fastify/deepmerge": "^2.0.0",
|
|
7
7
|
"@streamlayer/sl-eslib": "^5.149.1",
|
|
8
8
|
"uuid": "^11.1.0",
|
|
9
9
|
"nanostores": "^0.11.4",
|
|
10
|
-
"@streamlayer/sdk-web-api": "^1.8.
|
|
11
|
-
"@streamlayer/sdk-web-core": "^1.11.
|
|
12
|
-
"@streamlayer/sdk-web-interfaces": "^1.4.
|
|
13
|
-
"@streamlayer/sdk-web-logger": "^1.0.
|
|
14
|
-
"@streamlayer/sdk-web-notifications": "^1.3.
|
|
15
|
-
"@streamlayer/sdk-web-storage": "^1.0.
|
|
16
|
-
"@streamlayer/sdk-web-types": "^1.10.
|
|
10
|
+
"@streamlayer/sdk-web-api": "^1.8.4",
|
|
11
|
+
"@streamlayer/sdk-web-core": "^1.11.6",
|
|
12
|
+
"@streamlayer/sdk-web-interfaces": "^1.4.17",
|
|
13
|
+
"@streamlayer/sdk-web-logger": "^1.0.51",
|
|
14
|
+
"@streamlayer/sdk-web-notifications": "^1.3.13",
|
|
15
|
+
"@streamlayer/sdk-web-storage": "^1.0.51",
|
|
16
|
+
"@streamlayer/sdk-web-types": "^1.10.8"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tslib": "^2.7.0"
|