@smartico/public-api 0.0.307 → 0.0.308

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.307",
3
+ "version": "0.0.308",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,4 +3,10 @@ export interface AchievementTaskPublicMeta {
3
3
  display_progress_as_count?: boolean;
4
4
  stage_image?: string;
5
5
  priority?: number;
6
+ user_state_operations?: {
7
+ [key: string]: {
8
+ op: string;
9
+ };
10
+ }
11
+
6
12
  }
@@ -1,6 +1,8 @@
1
+ import { IntUtils } from "src/IntUtils";
1
2
  import { AchievementAvailabilityStatus } from "./AchievementAvailabilityStatus";
2
3
  import { AchievementStatus } from "./AchievementStatus";
3
4
  import { UserAchievement } from "./UserAchievement";
5
+ import { UserAchievementTask } from "./UserAchievementTask";
4
6
 
5
7
  export class MissionUtils {
6
8
 
@@ -163,4 +165,49 @@ export class MissionUtils {
163
165
  public static getMs = (ts: number): number => {
164
166
  return new Date(ts).getTime();
165
167
  }
168
+
169
+ public static replaceFavGameNameTag = (task: UserAchievementTask) => {
170
+ if (!task) {
171
+ return task;
172
+ }
173
+
174
+ const userStateParams = (task.user_state_params?.map || {});
175
+ const userStateOperator = task.task_public_meta?.user_state_operations;
176
+ const userStateParamsKeys = Object.keys(userStateParams);
177
+
178
+ if (userStateParamsKeys.length === 0 || !userStateOperator) {
179
+ return task;
180
+ }
181
+
182
+ const operatorsMulti = ['has', '!has'];
183
+ const operatorsPos = ['pos1', 'pos2', 'pos3'];
184
+
185
+ let replacementValue: string = '';
186
+
187
+ userStateParamsKeys.forEach((k: 'core_fav_game_top3' | 'core_fav_game_type_top3') => {
188
+ const operator = userStateOperator[k]?.op;
189
+
190
+ if (operatorsMulti.includes(operator)) {
191
+ const value = userStateParams[k];
192
+ if (value && value.length > 0) {
193
+ replacementValue = value.join(' ,');
194
+ }
195
+ }
196
+
197
+ if (operatorsPos.includes(operator)) {
198
+ const value = userStateParams[k];
199
+ const pos = Number(operator.replace('pos', '')) - 1;
200
+
201
+ if (IntUtils.isNotNull(pos) && value && value[pos]) {
202
+ replacementValue = value[pos];
203
+ }
204
+ }
205
+ });
206
+
207
+ if (replacementValue) {
208
+ task.task_public_meta.name =task.task_public_meta.name.replace('{{suggested_games}}', replacementValue);
209
+ }
210
+
211
+ return task;
212
+ }
166
213
  }
@@ -83,17 +83,21 @@ export const UserAchievementTransform = (items: UserAchievement[]): TMissionOrBa
83
83
  r.ach_public_meta.label_tag === 'custom' ? r.ach_public_meta.custom_label_tag : r.ach_public_meta.label_tag,
84
84
  tasks: (r.achievementTasks || [])
85
85
  .filter((t) => t.task_type_id === AchievementTaskType.CompleteAchievement)
86
- .map((t) => ({
87
- id: t.task_id,
88
- name: t.task_public_meta?.name,
89
- points_reward: t.points_reward,
90
- is_completed: t.isCompleted,
91
- progress: t.userProgress,
92
- execution_count_expected: t.executionCount,
93
- execution_count_actual: t.userExecutedCount,
94
- display_progress_as_count: t.task_public_meta.display_progress_as_count,
95
- stage_image: t.task_public_meta.stage_image,
96
- })),
86
+ .map((t) => {
87
+ MissionUtils.replaceFavGameNameTag(t);
88
+
89
+ return ({
90
+ id: t.task_id,
91
+ name: t.task_public_meta?.name,
92
+ points_reward: t.points_reward,
93
+ is_completed: t.isCompleted,
94
+ progress: t.userProgress,
95
+ execution_count_expected: t.executionCount,
96
+ execution_count_actual: t.userExecutedCount,
97
+ display_progress_as_count: t.task_public_meta.display_progress_as_count,
98
+ stage_image: t.task_public_meta.stage_image,
99
+ })
100
+ }),
97
101
  related_games: (r.related_games || []).map((g) => ({
98
102
  ext_game_id: g.ext_game_id,
99
103
  game_public_meta: {
@@ -13,4 +13,9 @@ export interface UserAchievementTask {
13
13
  lastExecutionDate: string;
14
14
  unlocked_by_mission_id?: number;
15
15
  unlocked_by_level_id?: number;
16
+ user_state_params?: {
17
+ map: {
18
+ [key: string]: any;
19
+ }
20
+ }
16
21
  }
@@ -19,3 +19,4 @@ export * from './AchClaimPrizeRequest';
19
19
  export * from './AchClaimPrizeResponse';
20
20
  export * from './AchievementAvailabilityStatus';
21
21
  export * from './GetRelatedAchTourResponse';
22
+ export * from './MissionsUtils';