@stackedapp/utils 1.17.12 → 1.18.0

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 +26 -0
  2. package/package.json +1 -1
@@ -722,6 +722,30 @@ additionalData, }) => {
722
722
  }
723
723
  }
724
724
  }
725
+ // Evaluate userSettings conditions
726
+ if (conditions?.userSettings) {
727
+ const { emailNewsletter } = conditions.userSettings;
728
+ if (emailNewsletter !== undefined) {
729
+ const playerHasNewsletter = additionalData?.emailNewsletter ?? false;
730
+ const isDisqualify = emailNewsletter !== playerHasNewsletter;
731
+ if (addDetails) {
732
+ conditionData.push({
733
+ isMet: !isDisqualify,
734
+ kind: 'userSettings.emailNewsletter',
735
+ trackerAmount: playerHasNewsletter ? 1 : 0,
736
+ trackerGoal: 1,
737
+ percentCompleted: !isDisqualify ? 100 : 0,
738
+ text: emailNewsletter ? 'Subscribe to email newsletter' : 'Must not be subscribed to email newsletter',
739
+ });
740
+ if (isDisqualify)
741
+ isValid = false;
742
+ }
743
+ else {
744
+ if (isDisqualify)
745
+ return { isValid: false, isComplete: false, percentCompleted: 0 };
746
+ }
747
+ }
748
+ }
725
749
  // Calculate top-level percentCompleted as average of all condition percentages
726
750
  const percentCompleted = conditionData.length > 0
727
751
  ? conditionData.reduce((sum, c) => sum + c.percentCompleted, 0) / conditionData.length
@@ -787,6 +811,8 @@ const hasCompletionConditions = (conditions) => {
787
811
  return true;
788
812
  if (conditions.stackedAccount)
789
813
  return true;
814
+ if (conditions.userSettings)
815
+ return true;
790
816
  return false;
791
817
  };
792
818
  exports.hasCompletionConditions = hasCompletionConditions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackedapp/utils",
3
- "version": "1.17.12",
3
+ "version": "1.18.0",
4
4
  "description": "Public utilities for Stacked platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",