saltfish 0.3.40 → 0.3.41
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/dist/managers/TriggerManager.d.ts +18 -0
- package/dist/managers/TriggerManager.d.ts.map +1 -1
- package/dist/player.js +2 -2
- package/dist/player.min.js +2 -2
- package/dist/saltfish-playlist-player.es.js +96 -1
- package/dist/saltfish-playlist-player.umd.js +1 -1
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -9723,6 +9723,9 @@ class TriggerManager {
|
|
|
9723
9723
|
const elementVisibleCondition = this.evaluateElementVisibleCondition(triggers.elementVisible);
|
|
9724
9724
|
conditions.push(elementVisibleCondition);
|
|
9725
9725
|
log(`TriggerManager: ElementVisible condition for playlist ${playlistId}: ${elementVisibleCondition} (selector: ${triggers.elementVisible})`);
|
|
9726
|
+
const userAttributesCondition = this.evaluateUserAttributesCondition(triggers.userAttributes);
|
|
9727
|
+
conditions.push(userAttributesCondition);
|
|
9728
|
+
log(`TriggerManager: UserAttributes condition for playlist ${playlistId}: ${userAttributesCondition} (conditions: ${JSON.stringify(triggers.userAttributes)})`);
|
|
9726
9729
|
const shouldTrigger = this.applyOperators(conditions, triggers.operators);
|
|
9727
9730
|
log(`TriggerManager: Final evaluation for playlist ${playlistId}: ${shouldTrigger} (operator: ${triggers.operators.join(", ")})`);
|
|
9728
9731
|
if (shouldTrigger) {
|
|
@@ -9856,6 +9859,98 @@ class TriggerManager {
|
|
|
9856
9859
|
const isVisible = this.visibleElements.has(selector);
|
|
9857
9860
|
return isVisible;
|
|
9858
9861
|
}
|
|
9862
|
+
/**
|
|
9863
|
+
* Evaluates user attribute conditions for a playlist
|
|
9864
|
+
* All conditions must be met (AND logic)
|
|
9865
|
+
* @param conditions - Array of user attribute conditions to evaluate
|
|
9866
|
+
*/
|
|
9867
|
+
evaluateUserAttributesCondition(conditions) {
|
|
9868
|
+
if (!conditions || conditions.length === 0) {
|
|
9869
|
+
return true;
|
|
9870
|
+
}
|
|
9871
|
+
const store = getSaltfishStore();
|
|
9872
|
+
const user = store.user;
|
|
9873
|
+
if (!user) {
|
|
9874
|
+
return false;
|
|
9875
|
+
}
|
|
9876
|
+
for (const condition of conditions) {
|
|
9877
|
+
const { attributeKey, attributeType, operator, value: expectedValue } = condition;
|
|
9878
|
+
const userValue = user[attributeKey];
|
|
9879
|
+
if (userValue === void 0 || userValue === null) {
|
|
9880
|
+
return false;
|
|
9881
|
+
}
|
|
9882
|
+
const result = this.compareValues(userValue, expectedValue, attributeType, operator);
|
|
9883
|
+
if (!result) {
|
|
9884
|
+
return false;
|
|
9885
|
+
}
|
|
9886
|
+
}
|
|
9887
|
+
return true;
|
|
9888
|
+
}
|
|
9889
|
+
/**
|
|
9890
|
+
* Compares two values based on attribute type and operator
|
|
9891
|
+
* @param userValue - The user's actual value
|
|
9892
|
+
* @param expectedValue - The expected value from trigger condition (always a string)
|
|
9893
|
+
* @param attributeType - The data type for comparison
|
|
9894
|
+
* @param operator - The comparison operator
|
|
9895
|
+
*/
|
|
9896
|
+
compareValues(userValue, expectedValue, attributeType, operator) {
|
|
9897
|
+
try {
|
|
9898
|
+
switch (attributeType) {
|
|
9899
|
+
case "string": {
|
|
9900
|
+
const userStr = String(userValue);
|
|
9901
|
+
const expectedStr = expectedValue;
|
|
9902
|
+
return this.applyOperator(userStr, expectedStr, operator);
|
|
9903
|
+
}
|
|
9904
|
+
case "boolean": {
|
|
9905
|
+
const userBool = typeof userValue === "boolean" ? userValue : String(userValue).toLowerCase() === "true";
|
|
9906
|
+
const expectedBool = expectedValue.toLowerCase() === "true";
|
|
9907
|
+
if (operator === "equals") return userBool === expectedBool;
|
|
9908
|
+
if (operator === "notEquals") return userBool !== expectedBool;
|
|
9909
|
+
return false;
|
|
9910
|
+
}
|
|
9911
|
+
case "int": {
|
|
9912
|
+
const userNum = typeof userValue === "number" ? userValue : parseFloat(String(userValue));
|
|
9913
|
+
const expectedNum = parseFloat(expectedValue);
|
|
9914
|
+
if (isNaN(userNum) || isNaN(expectedNum)) {
|
|
9915
|
+
log(`TriggerManager: Invalid number comparison - userValue: ${userValue}, expected: ${expectedValue}`);
|
|
9916
|
+
return false;
|
|
9917
|
+
}
|
|
9918
|
+
return this.applyOperator(userNum, expectedNum, operator);
|
|
9919
|
+
}
|
|
9920
|
+
case "date": {
|
|
9921
|
+
const userDate = userValue instanceof Date ? userValue : new Date(String(userValue));
|
|
9922
|
+
const expectedDate = new Date(expectedValue);
|
|
9923
|
+
if (isNaN(userDate.getTime()) || isNaN(expectedDate.getTime())) {
|
|
9924
|
+
log(`TriggerManager: Invalid date comparison - userValue: ${userValue}, expected: ${expectedValue}`);
|
|
9925
|
+
return false;
|
|
9926
|
+
}
|
|
9927
|
+
return this.applyOperator(userDate.getTime(), expectedDate.getTime(), operator);
|
|
9928
|
+
}
|
|
9929
|
+
default:
|
|
9930
|
+
log(`TriggerManager: Unknown attribute type: ${attributeType}`);
|
|
9931
|
+
return false;
|
|
9932
|
+
}
|
|
9933
|
+
} catch (error2) {
|
|
9934
|
+
return false;
|
|
9935
|
+
}
|
|
9936
|
+
}
|
|
9937
|
+
/**
|
|
9938
|
+
* Applies the comparison operator to two values
|
|
9939
|
+
*/
|
|
9940
|
+
applyOperator(userValue, expectedValue, operator) {
|
|
9941
|
+
switch (operator) {
|
|
9942
|
+
case "equals":
|
|
9943
|
+
return userValue === expectedValue;
|
|
9944
|
+
case "notEquals":
|
|
9945
|
+
return userValue !== expectedValue;
|
|
9946
|
+
case "greaterThan":
|
|
9947
|
+
return userValue > expectedValue;
|
|
9948
|
+
case "lessThan":
|
|
9949
|
+
return userValue < expectedValue;
|
|
9950
|
+
default:
|
|
9951
|
+
return false;
|
|
9952
|
+
}
|
|
9953
|
+
}
|
|
9859
9954
|
/**
|
|
9860
9955
|
* Sets up click event listeners for all playlists with elementClicked triggers
|
|
9861
9956
|
*/
|
|
@@ -11896,7 +11991,7 @@ const SaltfishPlayer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.de
|
|
|
11896
11991
|
__proto__: null,
|
|
11897
11992
|
SaltfishPlayer
|
|
11898
11993
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
11899
|
-
const version = "0.3.
|
|
11994
|
+
const version = "0.3.41";
|
|
11900
11995
|
const packageJson = {
|
|
11901
11996
|
version
|
|
11902
11997
|
};
|