@stackedapp/utils 1.17.3 → 1.17.4

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.
Files changed (2) hide show
  1. package/dist/conditions.js +22 -6
  2. package/package.json +1 -1
@@ -16,6 +16,7 @@ const calculatePercent = (amount, goal, isMet) => {
16
16
  }
17
17
  return isMet ? 100 : 0;
18
18
  };
19
+ const formatList = (items) => items.length === 2 ? items.join(' and ') : `${items.slice(0, -1).join(', ')}, and ${items.at(-1)}`;
19
20
  const calculateDynamicConditionPercent = (dynamicObj, cond) => {
20
21
  if (!dynamicObj)
21
22
  return 0;
@@ -451,7 +452,7 @@ additionalData, }) => {
451
452
  }
452
453
  }
453
454
  // Validate link count conditions
454
- if (conditions?.links && 'entityLinks' in playerSnap) {
455
+ if (conditions?.links) {
455
456
  for (const [linkType, constraint] of Object.entries(conditions.links)) {
456
457
  // linkType should always exist. and be default is none was specified
457
458
  const linkCount = playerSnap.entityLinks?.filter((link) => (link.kind || exports.DEFAULT_ENTITY_KIND) === linkType).length || 0;
@@ -553,19 +554,30 @@ additionalData, }) => {
553
554
  return { isValid: false, isComplete: false, percentCompleted: 0 };
554
555
  }
555
556
  }
556
- if (conditions?.identifiers?.platforms?.length && 'identifiers' in playerSnap) {
557
+ if (conditions?.identifiers?.platforms?.length) {
557
558
  const playerPlatforms = new Set(playerSnap.identifiers?.map((i) => i.platform.toLowerCase()) || []);
558
559
  const isAndBehaviour = conditions.identifiers.behaviour === 'AND';
559
560
  const platformsToCheck = conditions.identifiers.platforms;
560
561
  let isMet;
561
562
  let displayText;
563
+ const platformsMap = {
564
+ sms: 'SMS',
565
+ email: 'Email',
566
+ apple: 'Apple',
567
+ google: 'Google',
568
+ tiktok: 'TikTok',
569
+ };
570
+ const metAndPlatforms = platformsToCheck.filter((platform) => playerPlatforms.has(platform.toLowerCase()));
562
571
  if (isAndBehaviour) {
563
- isMet = platformsToCheck.every((platform) => playerPlatforms.has(platform.toLowerCase()));
564
- displayText = `Link all: ${platformsToCheck.join(', ')}`;
572
+ isMet = metAndPlatforms.length === platformsToCheck.length;
573
+ displayText =
574
+ platformsToCheck.length > 1
575
+ ? `Link your ${formatList(platformsToCheck.map((p) => platformsMap[p.toLowerCase()] ?? p))} accounts`
576
+ : `Link your ${platformsMap[platformsToCheck[0].toLowerCase()] ?? platformsToCheck[0]} account`;
565
577
  }
566
578
  else {
567
579
  isMet = platformsToCheck.some((platform) => playerPlatforms.has(platform.toLowerCase()));
568
- displayText = `Link any: ${platformsToCheck.join(', ')}`;
580
+ displayText = `Link any of your ${formatList(platformsToCheck.map((p) => platformsMap[p.toLowerCase()] ?? p))} accounts`;
569
581
  }
570
582
  if (addDetails) {
571
583
  conditionData.push({
@@ -573,7 +585,11 @@ additionalData, }) => {
573
585
  kind: 'identifiers',
574
586
  trackerAmount: isMet ? 1 : 0,
575
587
  trackerGoal: 1,
576
- percentCompleted: isMet ? 100 : 0, // Binary
588
+ percentCompleted: isAndBehaviour
589
+ ? calculatePercent(metAndPlatforms.length, platformsToCheck.length, isMet)
590
+ : isMet
591
+ ? 100
592
+ : 0,
577
593
  text: displayText,
578
594
  });
579
595
  if (!isMet)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackedapp/utils",
3
- "version": "1.17.3",
3
+ "version": "1.17.4",
4
4
  "description": "Public utilities for Stacked platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",