@smartico/public-api 0.0.433 → 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.
@@ -943,7 +943,9 @@ const InboxMessageBodyTransform = item => {
943
943
  icon: item.image,
944
944
  title: item.title,
945
945
  preview_body: item.body,
946
- custom_data: IntUtils.JsonOrText(item == null ? void 0 : item.custom_data)
946
+ custom_data: IntUtils.JsonOrText(item == null ? void 0 : item.custom_data),
947
+ show_preview: item.show_preview,
948
+ show_duration_sec: item.show_duration_sec
947
949
  };
948
950
  if (item.action === 'dp:inbox') {
949
951
  if (item.additional_buttons && item.additional_buttons.length) {
@@ -1300,7 +1302,8 @@ var BadgesTimeLimitStates;
1300
1302
  })(BadgesTimeLimitStates || (BadgesTimeLimitStates = {}));
1301
1303
 
1302
1304
  var _MissionUtils;
1303
- 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']]];
1304
1307
  const USER_STATE_PARAMS_KEYS_BET_AMOUNT = ['core_recommended_deposit_amount', 'core_recommended_casino_bet_amount', 'core_recommended_sport_bet_amount'];
1305
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']);
1306
1309
  function toGameTitleCase(raw) {
@@ -1478,52 +1481,37 @@ MissionUtils.replaceTagsFavMissionTask = ({
1478
1481
  }
1479
1482
  const userStateParams = task.user_state_params || {};
1480
1483
  const userStateOperator = (_task$task_public_met = task.task_public_meta) == null ? void 0 : _task$task_public_met.user_state_operations;
1481
- const userStateParamsKeys = Object.keys(userStateParams);
1482
- if (userStateParamsKeys.length === 0 || !userStateOperator) {
1484
+ if (Object.keys(userStateParams).length === 0 || !userStateOperator) {
1483
1485
  return result;
1484
1486
  }
1485
- const operatorsMulti = ['has', '!has'];
1486
- const operatorsPos = ['pos1', 'pos2', 'pos3'];
1487
- let suggestedGames = '';
1488
- let suggestedValue = '';
1489
- 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 => {
1490
1490
  var _userStateOperator$k;
1491
+ const values = userStateParams[k];
1491
1492
  const operator = (_userStateOperator$k = userStateOperator[k]) == null ? void 0 : _userStateOperator$k.op;
1492
- if (USER_STATE_PARAMS_KEYS_GAMES.includes(k)) {
1493
- if (operatorsMulti.includes(operator)) {
1494
- var _userStateParams$k;
1495
- const value = (_userStateParams$k = userStateParams[k]) == null ? void 0 : _userStateParams$k.filter(v => Boolean(v));
1496
- if (value && value.length > 0) {
1497
- suggestedGames = value.map(v => {
1498
- const cleaned = v.replace(/_/g, ' ');
1499
- return toGameTitleCase(cleaned);
1500
- }).join(', ');
1501
- }
1502
- }
1503
- if (operatorsPos.includes(operator)) {
1504
- const value = userStateParams[k];
1505
- const pos = Number(operator.replace('pos', '')) - 1;
1506
- if (IntUtils.isNotNull(pos) && value && value[pos]) {
1507
- suggestedGames = value[pos];
1508
- if (suggestedGames) {
1509
- suggestedGames = toGameTitleCase(suggestedGames.replace(/_/g, ' '));
1510
- }
1511
- }
1512
- }
1493
+ if (!Array.isArray(values)) {
1494
+ return '';
1513
1495
  }
1514
- if (USER_STATE_PARAMS_KEYS_BET_AMOUNT.includes(k)) {
1515
- suggestedValue = userStateParams[k];
1516
- if (suggestedValue) {
1517
- const currencyFromTheTask = userStateParams == null ? void 0 : userStateParams.core_wallet_currency;
1518
- suggestedValue = `${suggestedValue} ${currencySymbol || currencyFromTheTask || ''}`;
1519
- }
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);
1520
1506
  }
1507
+ };
1508
+ FAV_TAGS.forEach(([tag, keys]) => {
1509
+ replaceTag(tag, keys.map(favValue).find(Boolean));
1521
1510
  });
1522
- if (suggestedGames && result) {
1523
- result = result.replace('{{suggested_games}}', suggestedGames);
1524
- }
1525
- if (suggestedValue && result) {
1526
- 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 || ''}`);
1527
1515
  }
1528
1516
  return result;
1529
1517
  };
@@ -1603,19 +1591,19 @@ const UserAchievementTransform = items => {
1603
1591
  if ((_r$ach_public_meta$na = r.ach_public_meta.name) != null && _r$ach_public_meta$na.includes('{{suggested_')) {
1604
1592
  missionName = MissionUtils.replaceTagsFavMissionTask({
1605
1593
  task: t,
1606
- valueToReplace: r.ach_public_meta.name
1594
+ valueToReplace: missionName
1607
1595
  });
1608
1596
  }
1609
1597
  if ((_r$ach_public_meta$su = r.ach_public_meta.sub_header) != null && _r$ach_public_meta$su.includes('{{suggested_')) {
1610
1598
  missionSubHeader = MissionUtils.replaceTagsFavMissionTask({
1611
1599
  task: t,
1612
- valueToReplace: r.ach_public_meta.sub_header
1600
+ valueToReplace: missionSubHeader
1613
1601
  });
1614
1602
  }
1615
1603
  if ((_r$ach_public_meta$de = r.ach_public_meta.description) != null && _r$ach_public_meta$de.includes('{{suggested_')) {
1616
1604
  missionDescription = MissionUtils.replaceTagsFavMissionTask({
1617
1605
  task: t,
1618
- valueToReplace: r.ach_public_meta.description
1606
+ valueToReplace: missionDescription
1619
1607
  });
1620
1608
  }
1621
1609
  });
@@ -9225,6 +9213,16 @@ class WSAPIInbox extends WSAPILeaderBoard {
9225
9213
  * for safe execution — that helper handles URL vs deep-link
9226
9214
  * routing.
9227
9215
  *
9216
+ * **Preview vs silent delivery**
9217
+ * Every message belongs in your inbox list. `show_preview` decides
9218
+ * whether it should also pop up briefly when it arrives:
9219
+ * - `show_preview !== false` → show a preview popup for
9220
+ * `show_duration_sec ?? 7` seconds.
9221
+ * - `show_preview === false` → store it silently, with no popup.
9222
+ * These fields are returned exactly as the operator configured them;
9223
+ * a missing value means the default above, the same as the default
9224
+ * Smartico UI.
9225
+ *
9228
9226
  * **Idempotency / Side effects**: safe. Read-only HTTP fetch.
9229
9227
  *
9230
9228
  * **UI guidance**: see [UI Guide — `getInboxMessageBody`](../../docs/ui/inbox/UIGuide_getInboxMessageBody.md).
@@ -9250,6 +9248,12 @@ class WSAPIInbox extends WSAPILeaderBoard {
9250
9248
  * console.log('[smartico] simple message — show preview_body + single CTA wired to:', body.action,
9251
9249
  * '— execute via _smartico.dp(body.action)');
9252
9250
  * }
9251
+ *
9252
+ * if (body.show_preview !== false) {
9253
+ * console.log('[smartico] new message — show a preview popup for', body.show_duration_sec ?? 7, 'seconds');
9254
+ * } else {
9255
+ * console.log('[smartico] new message — store it in the inbox silently, no popup');
9256
+ * }
9253
9257
  * ```
9254
9258
  */
9255
9259
  async getInboxMessageBody(messageGuid) {