@streamlayer/feature-gamification 1.4.2 → 1.5.1

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.
@@ -1,11 +1,15 @@
1
1
  import { createMapStore, StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
2
2
  import { PromotionOptions } from '@streamlayer/sdk-web-types';
3
+ import { QuestionNotification } from '@streamlayer/sl-eslib/interactive/interactive.common_pb';
3
4
  import { type GamificationBackground } from '../background';
4
5
  import { getPromotionDetail } from '../queries';
5
6
  type AdvertisementData = {
6
7
  loading?: boolean;
7
8
  error?: unknown;
8
- data?: PromotionOptions;
9
+ data?: {
10
+ promotions: PromotionOptions;
11
+ notification?: QuestionNotification;
12
+ };
9
13
  };
10
14
  export type Advertisement = {
11
15
  autoHideDuration: number;
@@ -2,6 +2,7 @@ import { ApiStore, createMapStore, eventBus } from '@streamlayer/sdk-web-interfa
2
2
  import { QuestionStatus } from '@streamlayer/sdk-web-types';
3
3
  import { createLogger } from '@streamlayer/sdk-web-logger';
4
4
  import { onMount } from 'nanostores';
5
+ import { NotificationEnabled } from '@streamlayer/sl-eslib/interactive/interactive.common_pb';
5
6
  import { $promotionList, getPromotionDetail } from '../queries';
6
7
  import { AdvertisementStorage } from './storage';
7
8
  import { AdvertisementsQueue } from './queue';
@@ -31,7 +32,7 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
31
32
  action: 'received',
32
33
  payload: {
33
34
  advertisementId,
34
- advertisementType: data?.type,
35
+ advertisementType: data?.promotions.type,
35
36
  },
36
37
  });
37
38
  queue.addToQueue({
@@ -43,6 +44,12 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
43
44
  this.data.setKey('loading', true);
44
45
  try {
45
46
  const response = data || (await getPromotionDetail(advertisementId, transport));
47
+ instance.sdk.onAdvertisementActivate({
48
+ stage: 'activate',
49
+ id: advertisementId,
50
+ hasNotification: response?.notification?.enabled === NotificationEnabled.NOTIFICATION_ENABLED,
51
+ isShowed: !!storage.isShowed(advertisementId),
52
+ });
46
53
  if (!response) {
47
54
  this.data.setKey('error', new Error('No promotion found'));
48
55
  }
@@ -89,7 +96,7 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
89
96
  action: 'opened',
90
97
  payload: {
91
98
  advertisementId: advertisement.id,
92
- advertisementType: advertisementData.data?.type,
99
+ advertisementType: advertisementData.data?.promotions.type,
93
100
  },
94
101
  });
95
102
  return advertisement;
@@ -98,11 +105,7 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
98
105
  if (list.data) {
99
106
  const last = list.data[list.data.length - 1];
100
107
  if (last) {
101
- instance.sdk.onAdvertisementActivate({
102
- stage: 'activate',
103
- id: last.id,
104
- isShowed: !!storage.isShowed(last.id),
105
- });
108
+ show(last.id);
106
109
  }
107
110
  }
108
111
  });
@@ -118,20 +121,13 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
118
121
  return;
119
122
  }
120
123
  if (feedItem.status === QuestionStatus.RESOLVED) {
121
- instance.sdk.onAdvertisementActivate({
122
- stage: 'deactivate',
123
- id: feedItem.id,
124
- });
124
+ hide(feedItem.id);
125
125
  logger.debug({ feedItem }, 'resolved: %o');
126
126
  return;
127
127
  }
128
128
  if (feedItem.status === QuestionStatus.ACTIVE) {
129
129
  logger.debug({ feedItem }, 'active: %o');
130
- instance.sdk.onAdvertisementActivate({
131
- stage: 'activate',
132
- id: feedItem.id,
133
- isShowed: !!storage.isShowed(feedItem.id),
134
- });
130
+ show(feedItem.id);
135
131
  return;
136
132
  }
137
133
  logger.debug({ feedItem }, 'skip: %o');
@@ -164,7 +160,10 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
164
160
  }
165
161
  if (feedItem.status === QuestionStatus.ACTIVE) {
166
162
  logger.debug({ feedItem }, 'active: %o');
167
- show(feedItem.id, promotionItem);
163
+ show(feedItem.id, {
164
+ promotions: promotionItem,
165
+ notification: response.data?.attributes?.question?.notification,
166
+ });
168
167
  return;
169
168
  }
170
169
  logger.debug({ feedItem }, 'skip: %o');
@@ -350,7 +350,10 @@ export declare const questionSubscription: (questionId: string, transport: Trans
350
350
  export declare const getQuestionByUser: (questionId: string, transport: Transport) => Promise<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion | undefined>;
351
351
  export declare const getQuestionDetail: (questionId: string, transport: Transport) => Promise<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").Question | undefined>;
352
352
  export declare const $questionByUser: ($questionId: ReadableAtom<string | undefined> | string, transport: Transport) => import("@nanostores/query").FetcherStore<import("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>, any>;
353
- export declare const getPromotionDetail: (promoId: string, transport: Transport) => Promise<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").QuestionOptions_PromotionOptions | undefined>;
353
+ export declare const getPromotionDetail: (promoId: string, transport: Transport) => Promise<{
354
+ promotions: import("@streamlayer/sl-eslib/interactive/interactive.common_pb").QuestionOptions_PromotionOptions;
355
+ notification: import("@streamlayer/sl-eslib/interactive/interactive.common_pb").QuestionNotification | undefined;
356
+ } | undefined>;
354
357
  export declare const $pickHistory: (slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<(import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").PickHistory | undefined)[], any>;
355
358
  export declare const $feedList: ($slStreamId: ReadableAtom<string | undefined>, $interactiveAllowed: ReadableAtom<InteractiveAllowed>, transport: Transport) => import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem[], any>;
356
359
  export declare const $promotionList: ($slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<({
@@ -83,7 +83,7 @@ export const getPromotionDetail = async (promoId, transport) => {
83
83
  const promotions = res.data?.attributes?.options?.options.case === 'promotion'
84
84
  ? res.data?.attributes?.options?.options.value
85
85
  : undefined;
86
- return promotions;
86
+ return promotions ? { promotions, notification: res.data?.attributes?.notification } : undefined;
87
87
  };
88
88
  export const $pickHistory = (slStreamId, transport) => {
89
89
  const { client, queryKey } = transport.createPromiseClient(Feed, { method: 'pickHistory', params: [slStreamId] });
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@streamlayer/feature-gamification",
3
- "version": "1.4.2",
3
+ "version": "1.5.1",
4
4
  "peerDependencies": {
5
5
  "@bufbuild/protobuf": "^1.10.0",
6
6
  "@fastify/deepmerge": "^2.0.0",
7
7
  "@streamlayer/sl-eslib": "^5.122.0",
8
8
  "nanostores": "^0.10.3",
9
- "@streamlayer/sdk-web-api": "^1.3.2",
10
- "@streamlayer/sdk-web-core": "^1.2.2",
11
- "@streamlayer/sdk-web-interfaces": "^1.1.6",
12
- "@streamlayer/sdk-web-logger": "^1.0.11",
13
- "@streamlayer/sdk-web-notifications": "^1.1.6",
14
- "@streamlayer/sdk-web-types": "^1.3.2",
15
- "@streamlayer/sdk-web-storage": "^1.0.11"
9
+ "@streamlayer/sdk-web-core": "^1.2.4",
10
+ "@streamlayer/sdk-web-api": "^1.3.4",
11
+ "@streamlayer/sdk-web-interfaces": "^1.1.8",
12
+ "@streamlayer/sdk-web-logger": "^1.0.13",
13
+ "@streamlayer/sdk-web-notifications": "^1.1.8",
14
+ "@streamlayer/sdk-web-storage": "^1.0.13",
15
+ "@streamlayer/sdk-web-types": "^1.4.1"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tslib": "^2.7.0"