@smartico/public-api 0.0.434 → 0.0.435

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.
@@ -1302,7 +1302,8 @@ var BadgesTimeLimitStates;
1302
1302
  })(BadgesTimeLimitStates || (BadgesTimeLimitStates = {}));
1303
1303
 
1304
1304
  var _MissionUtils;
1305
- const USER_STATE_PARAMS_KEYS_GAMES = ['core_fav_game_top3', 'core_fav_game_type_top3', 'core_fav_game_provider_top3'];
1305
+ // tag -> favorites (top 3 arrays) that fill it; a task has at most one condition per tag (enforced in the BO)
1306
+ const FAV_TAGS = [['{{suggested_games}}', ['core_fav_game_top3', 'core_fav_game_type_top3', 'core_fav_game_provider_top3']], ['{{suggested_sport}}', ['core_fav_sport_type_top3', 'core_fav_sport_league_top3']]];
1306
1307
  const USER_STATE_PARAMS_KEYS_BET_AMOUNT = ['core_recommended_deposit_amount', 'core_recommended_casino_bet_amount', 'core_recommended_sport_bet_amount'];
1307
1308
  const MINOR_WORDS = new Set(['of', 'at', 'in', 'on', 'to', 'up', 'as', 'by', 'for', 'from', 'into', 'onto', 'with', 'upon', 'via', 'and', 'but', 'or', 'nor', 'so', 'yet', 'vs', 'v', 'a', 'an', 'the']);
1308
1309
  function toGameTitleCase(raw) {
@@ -1480,52 +1481,37 @@ MissionUtils.replaceTagsFavMissionTask = ({
1480
1481
  }
1481
1482
  const userStateParams = task.user_state_params || {};
1482
1483
  const userStateOperator = (_task$task_public_met = task.task_public_meta) == null ? void 0 : _task$task_public_met.user_state_operations;
1483
- const userStateParamsKeys = Object.keys(userStateParams);
1484
- if (userStateParamsKeys.length === 0 || !userStateOperator) {
1484
+ if (Object.keys(userStateParams).length === 0 || !userStateOperator) {
1485
1485
  return result;
1486
1486
  }
1487
- const operatorsMulti = ['has', '!has'];
1488
- const operatorsPos = ['pos1', 'pos2', 'pos3'];
1489
- let suggestedGames = '';
1490
- let suggestedValue = '';
1491
- userStateParamsKeys.forEach(k => {
1487
+ const formatFav = v => toGameTitleCase(v.replace(/_/g, ' '));
1488
+ // 'has' / '!has' -> all favorites, 'posN' -> the N-th one
1489
+ const favValue = k => {
1492
1490
  var _userStateOperator$k;
1491
+ const values = userStateParams[k];
1493
1492
  const operator = (_userStateOperator$k = userStateOperator[k]) == null ? void 0 : _userStateOperator$k.op;
1494
- if (USER_STATE_PARAMS_KEYS_GAMES.includes(k)) {
1495
- if (operatorsMulti.includes(operator)) {
1496
- var _userStateParams$k;
1497
- const value = (_userStateParams$k = userStateParams[k]) == null ? void 0 : _userStateParams$k.filter(v => Boolean(v));
1498
- if (value && value.length > 0) {
1499
- suggestedGames = value.map(v => {
1500
- const cleaned = v.replace(/_/g, ' ');
1501
- return toGameTitleCase(cleaned);
1502
- }).join(', ');
1503
- }
1504
- }
1505
- if (operatorsPos.includes(operator)) {
1506
- const value = userStateParams[k];
1507
- const pos = Number(operator.replace('pos', '')) - 1;
1508
- if (IntUtils.isNotNull(pos) && value && value[pos]) {
1509
- suggestedGames = value[pos];
1510
- if (suggestedGames) {
1511
- suggestedGames = toGameTitleCase(suggestedGames.replace(/_/g, ' '));
1512
- }
1513
- }
1514
- }
1493
+ if (!Array.isArray(values)) {
1494
+ return '';
1515
1495
  }
1516
- if (USER_STATE_PARAMS_KEYS_BET_AMOUNT.includes(k)) {
1517
- suggestedValue = userStateParams[k];
1518
- if (suggestedValue) {
1519
- const currencyFromTheTask = userStateParams == null ? void 0 : userStateParams.core_wallet_currency;
1520
- suggestedValue = `${suggestedValue} ${currencySymbol || currencyFromTheTask || ''}`;
1521
- }
1496
+ if (operator === 'has' || operator === '!has') {
1497
+ return values.filter(Boolean).map(formatFav).join(', ');
1498
+ }
1499
+ const pos = /^pos[1-3]$/.test(operator) ? values[Number(operator.substring(3)) - 1] : null;
1500
+ return pos ? formatFav(pos) : '';
1501
+ };
1502
+ // split/join replaces every occurrence of the tag, not only the first one
1503
+ const replaceTag = (tag, value) => {
1504
+ if (value && result) {
1505
+ result = result.split(tag).join(value);
1522
1506
  }
1507
+ };
1508
+ FAV_TAGS.forEach(([tag, keys]) => {
1509
+ replaceTag(tag, keys.map(favValue).find(Boolean));
1523
1510
  });
1524
- if (suggestedGames && result) {
1525
- result = result.replace('{{suggested_games}}', suggestedGames);
1526
- }
1527
- if (suggestedValue && result) {
1528
- result = result.replace('{{suggested_value}}', suggestedValue);
1511
+ const amountKey = USER_STATE_PARAMS_KEYS_BET_AMOUNT.find(k => userStateParams[k]);
1512
+ if (amountKey) {
1513
+ const currencyFromTheTask = userStateParams.core_wallet_currency;
1514
+ replaceTag('{{suggested_value}}', `${userStateParams[amountKey]} ${currencySymbol || currencyFromTheTask || ''}`);
1529
1515
  }
1530
1516
  return result;
1531
1517
  };
@@ -1605,19 +1591,19 @@ const UserAchievementTransform = items => {
1605
1591
  if ((_r$ach_public_meta$na = r.ach_public_meta.name) != null && _r$ach_public_meta$na.includes('{{suggested_')) {
1606
1592
  missionName = MissionUtils.replaceTagsFavMissionTask({
1607
1593
  task: t,
1608
- valueToReplace: r.ach_public_meta.name
1594
+ valueToReplace: missionName
1609
1595
  });
1610
1596
  }
1611
1597
  if ((_r$ach_public_meta$su = r.ach_public_meta.sub_header) != null && _r$ach_public_meta$su.includes('{{suggested_')) {
1612
1598
  missionSubHeader = MissionUtils.replaceTagsFavMissionTask({
1613
1599
  task: t,
1614
- valueToReplace: r.ach_public_meta.sub_header
1600
+ valueToReplace: missionSubHeader
1615
1601
  });
1616
1602
  }
1617
1603
  if ((_r$ach_public_meta$de = r.ach_public_meta.description) != null && _r$ach_public_meta$de.includes('{{suggested_')) {
1618
1604
  missionDescription = MissionUtils.replaceTagsFavMissionTask({
1619
1605
  task: t,
1620
- valueToReplace: r.ach_public_meta.description
1606
+ valueToReplace: missionDescription
1621
1607
  });
1622
1608
  }
1623
1609
  });