@streamlayer/feature-gamification 1.16.3 → 1.16.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.
@@ -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
- ...betPackData,
94
- [question.id]: extendedQuestion,
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
- ...betPackData,
134
- [question.id]: extendedQuestion,
136
+ timestamp: Date.now(),
137
+ data: {
138
+ ...betPackData,
139
+ [question.id]: extendedQuestion,
140
+ },
135
141
  });
136
142
  }
137
143
  }
@@ -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) => {
@@ -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<Record<string, import("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>> | null, any>;
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>;
@@ -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 null;
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 null;
192
- }
193
- return res.data?.reduce((acc, item) => {
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
- if (!storage.isBetPackQuestionReceived(flags, question.id)) {
204
- eventBus.emit('poll', {
205
- action: 'received',
206
- payload: {
207
- questionId: question.id,
208
- questionType: question.type,
209
- },
210
- });
211
- storage.saveBetPackQuestionReceived(flags, question.id);
212
- }
213
- return { ...acc, [question.id]: question };
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",
3
+ "version": "1.16.5",
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.3",
11
- "@streamlayer/sdk-web-core": "^1.11.5",
12
- "@streamlayer/sdk-web-logger": "^1.0.50",
13
- "@streamlayer/sdk-web-interfaces": "^1.4.16",
14
- "@streamlayer/sdk-web-notifications": "^1.3.12",
15
- "@streamlayer/sdk-web-storage": "^1.0.50",
16
- "@streamlayer/sdk-web-types": "^1.10.7"
10
+ "@streamlayer/sdk-web-api": "^1.8.5",
11
+ "@streamlayer/sdk-web-core": "^1.11.7",
12
+ "@streamlayer/sdk-web-interfaces": "^1.4.18",
13
+ "@streamlayer/sdk-web-logger": "^1.0.52",
14
+ "@streamlayer/sdk-web-notifications": "^1.3.14",
15
+ "@streamlayer/sdk-web-storage": "^1.0.52",
16
+ "@streamlayer/sdk-web-types": "^1.10.9"
17
17
  },
18
18
  "devDependencies": {
19
19
  "tslib": "^2.7.0"